From b738e349be490c24d3604c224f44fc54e16d3d7b Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Sat, 23 Jun 2012 11:59:48 -0400 Subject: Support for sparse/dense vectors in the python extension - SparseVector, DenseVector - improved Lattice - Lattice translation - Hypergraph reweighting, pruning --- python/src/_cdec.cpp | 7825 ++++++++++++++++++++++++++++++++------------- python/src/_cdec.pyx | 135 +- python/src/decoder.pxd | 12 +- python/src/hypergraph.pxd | 68 +- python/src/hypergraph.pxi | 92 + python/src/kbest.pxd | 6 +- python/src/lattice.pxd | 9 +- python/src/lattice.pxi | 56 + python/src/utils.pxd | 55 +- python/src/vectors.pxi | 101 + 10 files changed, 5947 insertions(+), 2412 deletions(-) create mode 100644 python/src/hypergraph.pxi create mode 100644 python/src/lattice.pxi create mode 100644 python/src/vectors.pxi (limited to 'python/src') diff --git a/python/src/_cdec.cpp b/python/src/_cdec.cpp index 55470c89..0b9b9911 100644 --- a/python/src/_cdec.cpp +++ b/python/src/_cdec.cpp @@ -1,4 +1,4 @@ -/* Generated by Cython 0.16 on Thu Jun 14 09:24:35 2012 */ +/* Generated by Cython 0.16 on Sat Jun 23 11:57:21 2012 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -272,11 +272,12 @@ #define __PYX_HAVE_API___cdec #include #include +#include #include #include "utils/weights.h" #include "utils/logval.h" -#include "utils/prob.h" #include "utils/wordid.h" +#include "utils/small_vector.h" #include "utils/sparse_vector.h" #include "utils/tdict.cc" #include "utils/verbose.h" @@ -289,6 +290,7 @@ #include "decoder/hg_io.h" #include "decoder/hg_intersect.h" #include "decoder/hg_sampler.h" +#include "decoder/csplit.h" #include "decoder/ff_register.h" #include "decoder/decoder.h" #include "observer.h" @@ -376,46 +378,32 @@ static const char *__pyx_filename; static const char *__pyx_f[] = { "_cdec.pyx", + "vectors.pxi", + "hypergraph.pxi", + "lattice.pxi", }; /*--- Type declarations ---*/ -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___pyx_scope_struct_4_sample; +struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__; +struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree; struct __pyx_obj_5_cdec_Decoder; +struct __pyx_obj_5_cdec_SparseVector; struct __pyx_obj_5_cdec_Hypergraph; struct __pyx_obj_5_cdec_Lattice; +struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__; struct __pyx_obj_5_cdec___pyx_scope_struct____iter__; -struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest; +struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest; +struct __pyx_obj_5_cdec_DenseVector; -/* "_cdec.pyx":105 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 * 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 { - PyObject_HEAD - KBest::KBestDerivations,ETreeTraversal>::Derivation *__pyx_v_derivation; - KBest::KBestDerivations,ETreeTraversal> *__pyx_v_derivations; - unsigned int __pyx_v_k; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; - PyObject *__pyx_v_sentence; - PyObject *__pyx_v_size; - unsigned int __pyx_t_0; - long __pyx_t_1; -}; - - -/* "_cdec.pyx":122 - * 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: */ -struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample { +struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample { PyObject_HEAD std::vector *__pyx_v_hypos; unsigned int __pyx_v_k; @@ -427,35 +415,73 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample { }; -/* "_cdec.pyx":15 - * pass +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":43 + * self.vector.set_value(fid, value) * - * cdef class Weights: # <<<<<<<<<<<<<< - * cdef vector[weight_t]* weights + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) + * cdef str fname + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ { + PyObject_HEAD + PyObject *__pyx_v_fname; + size_t __pyx_v_i; + FastSparseVector::const_iterator *__pyx_v_it; + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self; + size_t __pyx_t_0; + size_t __pyx_t_1; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":44 + * del derivations * + * def kbest_tree(self, size): # <<<<<<<<<<<<<< + * 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 */ -struct __pyx_obj_5_cdec_Weights { +struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree { PyObject_HEAD - std::vector *weights; + KBest::KBestDerivations,ETreeTraversal>::Derivation *__pyx_v_derivation; + KBest::KBestDerivations,ETreeTraversal> *__pyx_v_derivations; + unsigned int __pyx_v_k; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; + PyObject *__pyx_v_size; + PyObject *__pyx_v_tree; + unsigned int __pyx_t_0; + long __pyx_t_1; }; -/* "_cdec.pyx":38 - * yield FDConvert(fid).c_str(), self.weights[0][fid] +/* "_cdec.pyx":15 + * pass * * cdef class Decoder: # <<<<<<<<<<<<<< * cdef decoder.Decoder* dec - * cdef public Weights weights + * cdef public DenseVector weights */ struct __pyx_obj_5_cdec_Decoder { PyObject_HEAD Decoder *dec; - struct __pyx_obj_5_cdec_Weights *weights; + struct __pyx_obj_5_cdec_DenseVector *weights; }; -/* "_cdec.pyx":71 - * return hg +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":32 + * return sparse + * + * cdef class SparseVector: # <<<<<<<<<<<<<< + * cdef FastSparseVector[weight_t]* vector + * + */ +struct __pyx_obj_5_cdec_SparseVector { + PyObject_HEAD + FastSparseVector *vector; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":4 + * cimport kbest as kb * * cdef class Hypergraph: # <<<<<<<<<<<<<< * cdef hypergraph.Hypergraph* hg @@ -468,8 +494,8 @@ struct __pyx_obj_5_cdec_Hypergraph { }; -/* "_cdec.pyx":139 - * # TODO: inside-outside pruning +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":3 + * cimport lattice * * cdef class Lattice: # <<<<<<<<<<<<<< * cdef lattice.Lattice* lattice @@ -481,41 +507,70 @@ struct __pyx_obj_5_cdec_Lattice { }; -/* "_cdec.pyx":33 - * self.weights[0][fid] = value +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":50 + * return hypergraph.AsPLF(self.lattice[0], True).c_str() + * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(len(self)): + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ { + PyObject_HEAD + unsigned int __pyx_v_i; + struct __pyx_obj_5_cdec_Lattice *__pyx_v_self; + Py_ssize_t __pyx_t_0; + unsigned int __pyx_t_1; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":18 + * self.vector[0][fid] = value * * def __iter__(self): # <<<<<<<<<<<<<< * cdef unsigned fid - * for fid in range(1, self.weights.size()): + * for fid in range(1, self.vector.size()): */ struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ { PyObject_HEAD unsigned int __pyx_v_fid; - struct __pyx_obj_5_cdec_Weights *__pyx_v_self; + struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self; size_t __pyx_t_0; unsigned int __pyx_t_1; }; -/* "_cdec.pyx":92 - * return tree.decode('utf8') +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":32 + * return fmap * * 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 */ -struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest { +struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest { PyObject_HEAD KBest::KBestDerivations,ESentenceTraversal>::Derivation *__pyx_v_derivation; KBest::KBestDerivations,ESentenceTraversal> *__pyx_v_derivations; unsigned int __pyx_v_k; struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; + PyObject *__pyx_v_sentence; PyObject *__pyx_v_size; - PyObject *__pyx_v_tree; unsigned int __pyx_t_0; long __pyx_t_1; }; + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":3 + * from cython.operator cimport preincrement as pinc + * + * cdef class DenseVector: # <<<<<<<<<<<<<< + * cdef vector[weight_t]* vector + * + */ +struct __pyx_obj_5_cdec_DenseVector { + PyObject_HEAD + std::vector *vector; +}; + #ifndef CYTHON_REFNANNY #define CYTHON_REFNANNY 0 #endif @@ -572,6 +627,14 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest { static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ +static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ +static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ + +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/ + +static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, + const char *name, int exact); /*proto*/ + static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ @@ -581,13 +644,12 @@ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ -static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, - const char *name, int exact); /*proto*/ - -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ - -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/ +static CYTHON_INLINE int __Pyx_NegateNonNeg(int b) { + return unlikely(b < 0) ? b : !b; +} +static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) { + return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b); +} static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); @@ -595,6 +657,78 @@ static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/ +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { + PyObject *r; + if (!j) return NULL; + r = PyObject_GetItem(o, j); + Py_DECREF(j); + return r; +} +#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ + __Pyx_GetItemInt_List_Fast(o, i) : \ + __Pyx_GetItemInt_Generic(o, to_py_func(i))) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) { + if (likely(o != Py_None)) { + if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { + PyObject *r = PyList_GET_ITEM(o, i); + Py_INCREF(r); + return r; + } + else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) { + PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i); + Py_INCREF(r); + return r; + } + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} +#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ + __Pyx_GetItemInt_Tuple_Fast(o, i) : \ + __Pyx_GetItemInt_Generic(o, to_py_func(i))) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) { + if (likely(o != Py_None)) { + if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, i); + Py_INCREF(r); + return r; + } + else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) { + PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i); + Py_INCREF(r); + return r; + } + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} +#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ + __Pyx_GetItemInt_Fast(o, i) : \ + __Pyx_GetItemInt_Generic(o, to_py_func(i))) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) { + if (PyList_CheckExact(o)) { + Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); + if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) { + PyObject *r = PyList_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } + else if (PyTuple_CheckExact(o)) { + Py_ssize_t n = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); + if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } + else if (likely(i >= 0)) { + PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; + if (likely(m && m->sq_item)) { + return m->sq_item(o, i); + } + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} + static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */ #define __Pyx_PyObject_AsDouble(obj) \ ((likely(PyFloat_CheckExact(obj))) ? \ @@ -693,6 +827,10 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* Module declarations from 'libcpp.vector' */ +/* Module declarations from 'libcpp.utility' */ + +/* Module declarations from 'libcpp.pair' */ + /* Module declarations from 'utils' */ /* Module declarations from 'lattice' */ @@ -704,14 +842,17 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* 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_DenseVector = 0; +static PyTypeObject *__pyx_ptype_5_cdec_SparseVector = 0; static PyTypeObject *__pyx_ptype_5_cdec_Hypergraph = 0; static PyTypeObject *__pyx_ptype_5_cdec_Lattice = 0; +static PyTypeObject *__pyx_ptype_5_cdec_Decoder = 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; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_1___iter__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_2_kbest = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_tree = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_4_sample = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_5___iter__ = 0; #define __Pyx_MODULE_NAME "_cdec" int __pyx_module_is_main__cdec = 0; @@ -719,12 +860,53 @@ int __pyx_module_is_main__cdec = 0; static PyObject *__pyx_builtin_Exception; static PyObject *__pyx_builtin_KeyError; static PyObject *__pyx_builtin_range; -static PyObject *__pyx_builtin_open; +static PyObject *__pyx_builtin_ValueError; +static PyObject *__pyx_builtin_NotImplemented; static PyObject *__pyx_builtin_eval; -static int __pyx_pf_5_cdec_7Weights___cinit__(struct __pyx_obj_5_cdec_Weights *__pyx_v_self, struct __pyx_obj_5_cdec_Decoder *__pyx_v_decoder); /* proto */ -static PyObject *__pyx_pf_5_cdec_7Weights_2__getitem__(struct __pyx_obj_5_cdec_Weights *__pyx_v_self, char *__pyx_v_fname); /* proto */ -static int __pyx_pf_5_cdec_7Weights_4__setitem__(struct __pyx_obj_5_cdec_Weights *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value); /* proto */ -static PyObject *__pyx_pf_5_cdec_7Weights_6__iter__(struct __pyx_obj_5_cdec_Weights *__pyx_v_self); /* proto */ +static PyObject *__pyx_builtin_enumerate; +static PyObject *__pyx_builtin_TypeError; +static PyObject *__pyx_builtin_IndexError; +static PyObject *__pyx_builtin_open; +static PyObject *__pyx_pf_5_cdec_11DenseVector___getitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ +static int __pyx_pf_5_cdec_11DenseVector_2__setitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value); /* proto */ +static PyObject *__pyx_pf_5_cdec_11DenseVector_4__iter__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_11DenseVector_7dot(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_11DenseVector_9tosparse(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector___getitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ +static int __pyx_pf_5_cdec_12SparseVector_2__setitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_4__iter__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, PyObject *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_9todense(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other, int __pyx_v_op); /* proto */ +static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_13__len__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_12SparseVector_15__contains__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_17__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_19__isub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_21__imul__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ +#if PY_MAJOR_VERSION < 3 +static PyObject *__pyx_pf_5_cdec_12SparseVector_23__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ +#endif +static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ +static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_4viterbi_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_6viterbi_source_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_8viterbi_features(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_10kbest(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_13kbest_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_16sample(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, unsigned int __pyx_v_n); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_19intersect(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, struct __pyx_obj_5_cdec_Lattice *__pyx_v_lat); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_21prune(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_beam_alpha, PyObject *__pyx_v_density, PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_23lattice(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_25reweight(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_weights); /* proto */ +static int __pyx_pf_5_cdec_7Lattice___init__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, PyObject *__pyx_v_inp); /* proto */ +static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index); /* proto */ +static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index, PyObject *__pyx_v_arcs); /* proto */ +static Py_ssize_t __pyx_pf_5_cdec_7Lattice_6__len__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_7Lattice_8__str__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ +static void __pyx_pf_5_cdec_7Lattice_13__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, char *__pyx_v_config); /* proto */ static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Decoder *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_cfg); /* proto */ @@ -732,17 +914,16 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self); /* proto */ static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ static int __pyx_pf_5_cdec_7Decoder_7weights_4__del__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self); /* proto */ -static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_4viterbi_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_6kbest(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_9kbest_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_12intersect(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, struct __pyx_obj_5_cdec_Lattice *__pyx_v_lat); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_14sample(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, unsigned int __pyx_v_n); /* proto */ -static int __pyx_pf_5_cdec_7Lattice___init__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, PyObject *__pyx_v_plf_tuple); /* proto */ -static PyObject *__pyx_pf_5_cdec_7Lattice_2__str__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_7Lattice_4__iter__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ -static void __pyx_pf_5_cdec_7Lattice_6__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ +static char __pyx_k_1[] = "cannot take the dot product of %s and SparseVector"; +static char __pyx_k_2[] = "comparison not implemented for SparseVector"; +static char __pyx_k_10[] = "csplit_preserve_full_word"; +static char __pyx_k_11[] = "cannot reweight hypergraph with %s"; +static char __pyx_k_13[] = "Cannot create lattice from %s"; +static char __pyx_k_14[] = "lattice index out of range"; +static char __pyx_k_21[] = "Cannot translate input type %s"; +static char __pyx_k__dot[] = "dot"; +static char __pyx_k__inp[] = "inp"; +static char __pyx_k__plf[] = "plf"; static char __pyx_k__eval[] = "eval"; static char __pyx_k__open[] = "open"; static char __pyx_k__self[] = "self"; @@ -754,7 +935,7 @@ static char __pyx_k__strip[] = "strip"; static char __pyx_k__config[] = "config"; static char __pyx_k__decode[] = "decode"; static char __pyx_k__encode[] = "encode"; -static char __pyx_k__decoder[] = "decoder"; +static char __pyx_k__density[] = "density"; static char __pyx_k__grammar[] = "grammar"; static char __pyx_k__KeyError[] = "KeyError"; static char __pyx_k____exit__[] = "__exit__"; @@ -762,149 +943,98 @@ static char __pyx_k____main__[] = "__main__"; static char __pyx_k____test__[] = "__test__"; static char __pyx_k__sentence[] = "sentence"; static char __pyx_k__Exception[] = "Exception"; +static char __pyx_k__TypeError[] = "TypeError"; static char __pyx_k____enter__[] = "__enter__"; -static char __pyx_k__plf_tuple[] = "plf_tuple"; +static char __pyx_k__enumerate[] = "enumerate"; +static char __pyx_k__IndexError[] = "IndexError"; +static char __pyx_k__ValueError[] = "ValueError"; +static char __pyx_k__beam_alpha[] = "beam_alpha"; static char __pyx_k__ParseFailed[] = "ParseFailed"; +static char __pyx_k__NotImplemented[] = "NotImplemented"; +static PyObject *__pyx_kp_s_1; +static PyObject *__pyx_n_s_10; +static PyObject *__pyx_kp_s_11; +static PyObject *__pyx_kp_s_13; +static PyObject *__pyx_kp_s_14; +static PyObject *__pyx_kp_s_2; +static PyObject *__pyx_kp_s_21; static PyObject *__pyx_n_s__Exception; +static PyObject *__pyx_n_s__IndexError; static PyObject *__pyx_n_s__KeyError; +static PyObject *__pyx_n_s__NotImplemented; static PyObject *__pyx_n_s__ParseFailed; +static PyObject *__pyx_n_s__TypeError; +static PyObject *__pyx_n_s__ValueError; static PyObject *__pyx_n_s____enter__; static PyObject *__pyx_n_s____exit__; static PyObject *__pyx_n_s____main__; static PyObject *__pyx_n_s____test__; static PyObject *__pyx_n_s___cdec; +static PyObject *__pyx_n_s__beam_alpha; static PyObject *__pyx_n_s__config; static PyObject *__pyx_n_s__decode; -static PyObject *__pyx_n_s__decoder; +static PyObject *__pyx_n_s__density; +static PyObject *__pyx_n_s__dot; static PyObject *__pyx_n_s__encode; +static PyObject *__pyx_n_s__enumerate; static PyObject *__pyx_n_s__eval; static PyObject *__pyx_n_s__grammar; +static PyObject *__pyx_n_s__inp; static PyObject *__pyx_n_s__open; -static PyObject *__pyx_n_s__plf_tuple; +static PyObject *__pyx_n_s__plf; static PyObject *__pyx_n_s__range; static PyObject *__pyx_n_s__self; static PyObject *__pyx_n_s__sentence; static PyObject *__pyx_n_s__split; static PyObject *__pyx_n_s__strip; static PyObject *__pyx_n_s__utf8; -static PyObject *__pyx_k_tuple_1; -static PyObject *__pyx_k_tuple_2; +static PyObject *__pyx_int_0; +static PyObject *__pyx_int_1; static PyObject *__pyx_k_tuple_3; static PyObject *__pyx_k_tuple_4; 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_12; +static PyObject *__pyx_k_tuple_15; +static PyObject *__pyx_k_tuple_16; +static PyObject *__pyx_k_tuple_17; +static PyObject *__pyx_k_tuple_18; +static PyObject *__pyx_k_tuple_19; +static PyObject *__pyx_k_tuple_20; /* Python wrapper */ -static int __pyx_pw_5_cdec_7Weights_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5_cdec_7Weights_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - struct __pyx_obj_5_cdec_Decoder *__pyx_v_decoder = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__decoder,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[1] = {0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__decoder); - 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, pos_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; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - } - __pyx_v_decoder = ((struct __pyx_obj_5_cdec_Decoder *)values[0]); - } - 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 = 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 = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_7Weights___cinit__(((struct __pyx_obj_5_cdec_Weights *)__pyx_v_self), __pyx_v_decoder); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "_cdec.pyx":18 - * cdef vector[weight_t]* weights - * - * def __cinit__(self, Decoder decoder): # <<<<<<<<<<<<<< - * self.weights = &decoder.dec.CurrentWeightVector() - * - */ - -static int __pyx_pf_5_cdec_7Weights___cinit__(struct __pyx_obj_5_cdec_Weights *__pyx_v_self, struct __pyx_obj_5_cdec_Decoder *__pyx_v_decoder) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "_cdec.pyx":19 - * - * def __cinit__(self, Decoder decoder): - * self.weights = &decoder.dec.CurrentWeightVector() # <<<<<<<<<<<<<< - * - * def __getitem__(self, char* fname): - */ - __pyx_v_self->weights = (&__pyx_v_decoder->dec->CurrentWeightVector()); - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Weights_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Weights_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { +static PyObject *__pyx_pw_5_cdec_11DenseVector_1__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ +static PyObject *__pyx_pw_5_cdec_11DenseVector_1__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { char *__pyx_v_fname; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); 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 = 21; __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[1]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.Weights.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.DenseVector.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_7Weights_2__getitem__(((struct __pyx_obj_5_cdec_Weights *)__pyx_v_self), ((char *)__pyx_v_fname)); + __pyx_r = __pyx_pf_5_cdec_11DenseVector___getitem__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":21 - * self.weights = &decoder.dec.CurrentWeightVector() +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":6 + * cdef vector[weight_t]* vector * * def __getitem__(self, char* fname): # <<<<<<<<<<<<<< * cdef unsigned fid = FDConvert(fname) - * if fid <= self.weights.size(): + * if fid <= self.vector.size(): */ -static PyObject *__pyx_pf_5_cdec_7Weights_2__getitem__(struct __pyx_obj_5_cdec_Weights *__pyx_v_self, char *__pyx_v_fname) { +static PyObject *__pyx_pf_5_cdec_11DenseVector___getitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname) { unsigned int __pyx_v_fid; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -916,34 +1046,34 @@ static PyObject *__pyx_pf_5_cdec_7Weights_2__getitem__(struct __pyx_obj_5_cdec_W int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__getitem__", 0); - /* "_cdec.pyx":22 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":7 * * def __getitem__(self, char* fname): * cdef unsigned fid = FDConvert(fname) # <<<<<<<<<<<<<< - * if fid <= self.weights.size(): - * return self.weights[0][fid] + * if fid <= self.vector.size(): + * return self.vector[0][fid] */ __pyx_v_fid = FD::Convert(__pyx_v_fname); - /* "_cdec.pyx":23 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":8 * def __getitem__(self, char* fname): * cdef unsigned fid = FDConvert(fname) - * if fid <= self.weights.size(): # <<<<<<<<<<<<<< - * return self.weights[0][fid] + * if fid <= self.vector.size(): # <<<<<<<<<<<<<< + * return self.vector[0][fid] * raise KeyError(fname) */ - __pyx_t_1 = (__pyx_v_fid <= __pyx_v_self->weights->size()); + __pyx_t_1 = (__pyx_v_fid <= __pyx_v_self->vector->size()); if (__pyx_t_1) { - /* "_cdec.pyx":24 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":9 * cdef unsigned fid = FDConvert(fname) - * if fid <= self.weights.size(): - * return self.weights[0][fid] # <<<<<<<<<<<<<< + * if fid <= self.vector.size(): + * return self.vector[0][fid] # <<<<<<<<<<<<<< * raise KeyError(fname) * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyFloat_FromDouble(((__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_t_2 = PyFloat_FromDouble(((__pyx_v_self->vector[0])[__pyx_v_fid])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; @@ -952,33 +1082,33 @@ static PyObject *__pyx_pf_5_cdec_7Weights_2__getitem__(struct __pyx_obj_5_cdec_W } __pyx_L3:; - /* "_cdec.pyx":25 - * if fid <= self.weights.size(): - * return self.weights[0][fid] + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":10 + * if fid <= self.vector.size(): + * return self.vector[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 = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 10; __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 = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__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 = 25; __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[1]; __pyx_lineno = 10; __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 = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec.Weights.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.DenseVector.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -987,111 +1117,111 @@ static PyObject *__pyx_pf_5_cdec_7Weights_2__getitem__(struct __pyx_obj_5_cdec_W } /* Python wrapper */ -static int __pyx_pw_5_cdec_7Weights_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value); /*proto*/ -static int __pyx_pw_5_cdec_7Weights_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value) { +static int __pyx_pw_5_cdec_11DenseVector_3__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value); /*proto*/ +static int __pyx_pw_5_cdec_11DenseVector_3__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value) { char *__pyx_v_fname; float __pyx_v_value; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); 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 = 27; __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[1]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } assert(__pyx_arg_value); { - __pyx_v_value = __pyx_PyFloat_AsFloat(__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;} + __pyx_v_value = __pyx_PyFloat_AsFloat(__pyx_arg_value); if (unlikely((__pyx_v_value == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.Weights.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.DenseVector.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_7Weights_4__setitem__(((struct __pyx_obj_5_cdec_Weights *)__pyx_v_self), ((char *)__pyx_v_fname), ((float)__pyx_v_value)); + __pyx_r = __pyx_pf_5_cdec_11DenseVector_2__setitem__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((char *)__pyx_v_fname), ((float)__pyx_v_value)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":27 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":12 * raise KeyError(fname) * * def __setitem__(self, char* fname, float value): # <<<<<<<<<<<<<< * cdef unsigned fid = FDConvert(fname) - * if self.weights.size() <= fid: + * if self.vector.size() <= fid: */ -static int __pyx_pf_5_cdec_7Weights_4__setitem__(struct __pyx_obj_5_cdec_Weights *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value) { +static int __pyx_pf_5_cdec_11DenseVector_2__setitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value) { unsigned int __pyx_v_fid; int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; __Pyx_RefNannySetupContext("__setitem__", 0); - /* "_cdec.pyx":28 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":13 * * def __setitem__(self, char* fname, float value): * cdef unsigned fid = FDConvert(fname) # <<<<<<<<<<<<<< - * if self.weights.size() <= fid: - * self.weights.resize(fid + 1) + * if self.vector.size() <= fid: + * self.vector.resize(fid + 1) */ __pyx_v_fid = FD::Convert(((char *)__pyx_v_fname)); - /* "_cdec.pyx":29 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":14 * def __setitem__(self, char* fname, float value): * cdef unsigned fid = FDConvert(fname) - * if self.weights.size() <= fid: # <<<<<<<<<<<<<< - * self.weights.resize(fid + 1) - * self.weights[0][fid] = value + * if self.vector.size() <= fid: # <<<<<<<<<<<<<< + * self.vector.resize(fid + 1) + * self.vector[0][fid] = value */ - __pyx_t_1 = (__pyx_v_self->weights->size() <= __pyx_v_fid); + __pyx_t_1 = (__pyx_v_self->vector->size() <= __pyx_v_fid); if (__pyx_t_1) { - /* "_cdec.pyx":30 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":15 * cdef unsigned fid = FDConvert(fname) - * if self.weights.size() <= fid: - * self.weights.resize(fid + 1) # <<<<<<<<<<<<<< - * self.weights[0][fid] = value + * if self.vector.size() <= fid: + * self.vector.resize(fid + 1) # <<<<<<<<<<<<<< + * self.vector[0][fid] = value * */ - __pyx_v_self->weights->resize((__pyx_v_fid + 1)); + __pyx_v_self->vector->resize((__pyx_v_fid + 1)); goto __pyx_L3; } __pyx_L3:; - /* "_cdec.pyx":31 - * if self.weights.size() <= fid: - * self.weights.resize(fid + 1) - * self.weights[0][fid] = value # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":16 + * if self.vector.size() <= fid: + * self.vector.resize(fid + 1) + * self.vector[0][fid] = value # <<<<<<<<<<<<<< * * def __iter__(self): */ - ((__pyx_v_self->weights[0])[__pyx_v_fid]) = __pyx_v_value; + ((__pyx_v_self->vector[0])[__pyx_v_fid]) = __pyx_v_value; __pyx_r = 0; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_7Weights_8generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5_cdec_11DenseVector_6generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Weights_7__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Weights_7__iter__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_11DenseVector_5__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_11DenseVector_5__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Weights_6__iter__(((struct __pyx_obj_5_cdec_Weights *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_11DenseVector_4__iter__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":33 - * self.weights[0][fid] = value +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":18 + * self.vector[0][fid] = value * * def __iter__(self): # <<<<<<<<<<<<<< * cdef unsigned fid - * for fid in range(1, self.weights.size()): + * for fid in range(1, self.vector.size()): */ -static PyObject *__pyx_pf_5_cdec_7Weights_6__iter__(struct __pyx_obj_5_cdec_Weights *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_11DenseVector_4__iter__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -1109,7 +1239,7 @@ static PyObject *__pyx_pf_5_cdec_7Weights_6__iter__(struct __pyx_obj_5_cdec_Weig __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Weights_8generator, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_11DenseVector_6generator, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -1118,7 +1248,7 @@ static PyObject *__pyx_pf_5_cdec_7Weights_6__iter__(struct __pyx_obj_5_cdec_Weig __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Weights.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.DenseVector.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); @@ -1127,7 +1257,7 @@ static PyObject *__pyx_pf_5_cdec_7Weights_6__iter__(struct __pyx_obj_5_cdec_Weig return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_7Weights_8generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_11DenseVector_6generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; @@ -1146,31 +1276,31 @@ static PyObject *__pyx_gb_5_cdec_7Weights_8generator(__pyx_GeneratorObject *__py return NULL; } __pyx_L3_first_run:; - 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[1]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "_cdec.pyx":35 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":20 * def __iter__(self): * cdef unsigned fid - * for fid in range(1, self.weights.size()): # <<<<<<<<<<<<<< - * yield FDConvert(fid).c_str(), self.weights[0][fid] + * for fid in range(1, self.vector.size()): # <<<<<<<<<<<<<< + * yield FDConvert(fid).c_str(), self.vector[0][fid] * */ - __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->weights->size(); + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->vector->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":36 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":21 * cdef unsigned fid - * for fid in range(1, self.weights.size()): - * yield FDConvert(fid).c_str(), self.weights[0][fid] # <<<<<<<<<<<<<< + * for fid in range(1, self.vector.size()): + * yield FDConvert(fid).c_str(), self.vector[0][fid] # <<<<<<<<<<<<<< * - * cdef class Decoder: + * def dot(self, SparseVector other): */ - __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_t_3 = PyBytes_FromString(FD::Convert(__pyx_cur_scope->__pyx_v_fid).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_4 = PyFloat_FromDouble(((__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_t_4 = PyFloat_FromDouble(((__pyx_cur_scope->__pyx_v_self->vector[0])[__pyx_cur_scope->__pyx_v_fid])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 21; __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 = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); @@ -1190,7 +1320,7 @@ static PyObject *__pyx_gb_5_cdec_7Weights_8generator(__pyx_GeneratorObject *__py __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 = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; @@ -1207,1563 +1337,1674 @@ static PyObject *__pyx_gb_5_cdec_7Weights_8generator(__pyx_GeneratorObject *__py } /* Python wrapper */ -static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - char *__pyx_v_config; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__config,0}; - int __pyx_r; +static PyObject *__pyx_pw_5_cdec_11DenseVector_8dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_11DenseVector_8dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[1] = {0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__config); - 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, pos_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 = 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 = 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:; - __pyx_r = __pyx_pf_5_cdec_7Decoder___cinit__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_config); + __Pyx_RefNannySetupContext("dot (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_11DenseVector_7dot(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":42 - * cdef public Weights weights +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":23 + * yield FDConvert(fid).c_str(), self.vector[0][fid] + * + * def dot(self, SparseVector other): # <<<<<<<<<<<<<< + * return other.dot(self) * - * def __cinit__(self, char* config): # <<<<<<<<<<<<<< - * decoder.register_feature_functions() - * cdef istringstream* config_stream = new istringstream(config) */ -static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, char *__pyx_v_config) { - std::istringstream *__pyx_v_config_stream; - int __pyx_r; +static PyObject *__pyx_pf_5_cdec_11DenseVector_7dot(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); + __Pyx_RefNannySetupContext("dot", 0); - /* "_cdec.pyx":43 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":24 * - * def __cinit__(self, char* config): - * decoder.register_feature_functions() # <<<<<<<<<<<<<< - * cdef istringstream* config_stream = new istringstream(config) - * self.dec = new decoder.Decoder(config_stream) + * def dot(self, SparseVector other): + * return other.dot(self) # <<<<<<<<<<<<<< + * + * def tosparse(self): */ - register_feature_functions(); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_other), __pyx_n_s__dot); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; - /* "_cdec.pyx":44 - * def __cinit__(self, char* config): - * decoder.register_feature_functions() - * cdef istringstream* config_stream = new istringstream(config) # <<<<<<<<<<<<<< - * self.dec = new decoder.Decoder(config_stream) - * del config_stream + __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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec.DenseVector.dot", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_11DenseVector_10tosparse(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_11DenseVector_10tosparse(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("tosparse (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_11DenseVector_9tosparse(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":26 + * return other.dot(self) + * + * def tosparse(self): # <<<<<<<<<<<<<< + * cdef SparseVector sparse = SparseVector() + * sparse.vector = new FastSparseVector[weight_t]() */ - __pyx_v_config_stream = new std::istringstream(__pyx_v_config); - /* "_cdec.pyx":45 - * decoder.register_feature_functions() - * cdef istringstream* config_stream = new istringstream(config) - * self.dec = new decoder.Decoder(config_stream) # <<<<<<<<<<<<<< - * del config_stream - * self.weights = Weights(self) +static PyObject *__pyx_pf_5_cdec_11DenseVector_9tosparse(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_sparse = 0; + 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("tosparse", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":27 + * + * def tosparse(self): + * cdef SparseVector sparse = SparseVector() # <<<<<<<<<<<<<< + * sparse.vector = new FastSparseVector[weight_t]() + * InitSparseVector(self.vector[0], sparse.vector) */ - __pyx_v_self->dec = new Decoder(__pyx_v_config_stream); + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sparse = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; - /* "_cdec.pyx":46 - * cdef istringstream* config_stream = new istringstream(config) - * self.dec = new decoder.Decoder(config_stream) - * del config_stream # <<<<<<<<<<<<<< - * self.weights = Weights(self) + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":28 + * def tosparse(self): + * cdef SparseVector sparse = SparseVector() + * sparse.vector = new FastSparseVector[weight_t]() # <<<<<<<<<<<<<< + * InitSparseVector(self.vector[0], sparse.vector) + * return sparse + */ + __pyx_v_sparse->vector = new FastSparseVector(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":29 + * cdef SparseVector sparse = SparseVector() + * sparse.vector = new FastSparseVector[weight_t]() + * InitSparseVector(self.vector[0], sparse.vector) # <<<<<<<<<<<<<< + * return sparse * */ - delete __pyx_v_config_stream; + Weights::InitSparseVector((__pyx_v_self->vector[0]), __pyx_v_sparse->vector); - /* "_cdec.pyx":47 - * self.dec = new decoder.Decoder(config_stream) - * del config_stream - * self.weights = Weights(self) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":30 + * sparse.vector = new FastSparseVector[weight_t]() + * InitSparseVector(self.vector[0], sparse.vector) + * return sparse # <<<<<<<<<<<<<< * - * def __dealloc__(self): + * cdef class SparseVector: */ - __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_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__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_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_GOTREF(__pyx_v_self->weights); - __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); - __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_Weights *)__pyx_t_2); - __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_sparse)); + __pyx_r = ((PyObject *)__pyx_v_sparse); + goto __pyx_L0; - __pyx_r = 0; + __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.Decoder.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_AddTraceback("_cdec.DenseVector.tosparse", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_sparse); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_1__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_1__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { + char *__pyx_v_fname; + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_7Decoder_2__dealloc__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + assert(__pyx_arg_fname); { + __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.SparseVector.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_12SparseVector___getitem__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* "_cdec.pyx":49 - * self.weights = Weights(self) +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":35 + * cdef FastSparseVector[weight_t]* vector * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.dec + * def __getitem__(self, char* fname): # <<<<<<<<<<<<<< + * cdef unsigned fid = FDConvert(fname) + * return self.vector.value(fid) + */ + +static PyObject *__pyx_pf_5_cdec_12SparseVector___getitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname) { + unsigned int __pyx_v_fid; + 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("__getitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":36 + * + * def __getitem__(self, char* fname): + * cdef unsigned fid = FDConvert(fname) # <<<<<<<<<<<<<< + * return self.vector.value(fid) * */ + __pyx_v_fid = FD::Convert(__pyx_v_fname); -static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":37 + * def __getitem__(self, char* fname): + * cdef unsigned fid = FDConvert(fname) + * return self.vector.value(fid) # <<<<<<<<<<<<<< + * + * def __setitem__(self, char* fname, float value): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->value(__pyx_v_fid)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_cdec.SparseVector.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_12SparseVector_3__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value); /*proto*/ +static int __pyx_pw_5_cdec_12SparseVector_3__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value) { + char *__pyx_v_fname; + float __pyx_v_value; + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); + __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); + assert(__pyx_arg_fname); { + __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + assert(__pyx_arg_value); { + __pyx_v_value = __pyx_PyFloat_AsFloat(__pyx_arg_value); if (unlikely((__pyx_v_value == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.SparseVector.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_12SparseVector_2__setitem__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname), ((float)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":50 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":39 + * return self.vector.value(fid) * - * def __dealloc__(self): - * del self.dec # <<<<<<<<<<<<<< + * def __setitem__(self, char* fname, float value): # <<<<<<<<<<<<<< + * cdef unsigned fid = FDConvert(fname) + * self.vector.set_value(fid, value) + */ + +static int __pyx_pf_5_cdec_12SparseVector_2__setitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value) { + unsigned int __pyx_v_fid; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":40 + * + * def __setitem__(self, char* fname, float value): + * cdef unsigned fid = FDConvert(fname) # <<<<<<<<<<<<<< + * self.vector.set_value(fid, value) * - * def read_weights(self, cfg): */ - delete __pyx_v_self->dec; + __pyx_v_fid = FD::Convert(((char *)__pyx_v_fname)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":41 + * def __setitem__(self, char* fname, float value): + * cdef unsigned fid = FDConvert(fname) + * self.vector.set_value(fid, value) # <<<<<<<<<<<<<< + * + * def __iter__(self): + */ + __pyx_v_self->vector->set_value(__pyx_v_fid, __pyx_v_value); + __pyx_r = 0; __Pyx_RefNannyFinishContext(); + return __pyx_r; } +static PyObject *__pyx_gb_5_cdec_12SparseVector_6generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_cfg); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_cfg) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_5__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_5__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_weights (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_4read_weights(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_cfg)); + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_4__iter__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":52 - * del self.dec +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":43 + * self.vector.set_value(fid, value) * - * def read_weights(self, cfg): # <<<<<<<<<<<<<< - * with open(cfg) as fp: - * for line in fp: + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) + * cdef str fname */ -static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_cfg) { - PyObject *__pyx_v_fp = NULL; - PyObject *__pyx_v_line = NULL; - PyObject *__pyx_v_fname = NULL; - PyObject *__pyx_v_value = NULL; +static PyObject *__pyx_pf_5_cdec_12SparseVector_4__iter__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - Py_ssize_t __pyx_t_8; - PyObject *(*__pyx_t_9)(PyObject *); - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *(*__pyx_t_12)(PyObject *); - double __pyx_t_13; - int __pyx_t_14; - PyObject *__pyx_t_15 = NULL; - int __pyx_t_16; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("read_weights", 0); + __Pyx_RefNannySetupContext("__iter__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_1___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_1___iter__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12SparseVector_6generator1, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } - /* "_cdec.pyx":53 + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.SparseVector.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5_cdec_12SparseVector_6generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + size_t __pyx_t_1; + size_t __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[1]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":44 * - * def read_weights(self, cfg): - * with open(cfg) as fp: # <<<<<<<<<<<<<< - * for line in fp: - * fname, value = line.split() + * def __iter__(self): + * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) # <<<<<<<<<<<<<< + * cdef str fname + * for i in range(self.vector.size()): */ - /*with:*/ { - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__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 = 53; __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 = 53; __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 = 53; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /*try:*/ { - { - __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - /*try:*/ { - __Pyx_INCREF(__pyx_t_4); - __pyx_v_fp = __pyx_t_4; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "_cdec.pyx":54 - * def read_weights(self, cfg): - * with open(cfg) as fp: - * for line in fp: # <<<<<<<<<<<<<< - * fname, value = line.split() - * self.weights[fname.strip()] = float(value) + __pyx_cur_scope->__pyx_v_it = new FastSparseVector::const_iterator((__pyx_cur_scope->__pyx_v_self->vector[0]), 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":46 + * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) + * cdef str fname + * for i in range(self.vector.size()): # <<<<<<<<<<<<<< + * fname = FDConvert(it[0].ptr().first).c_str() + * yield (fname, it[0].ptr().second) */ - if (PyList_CheckExact(__pyx_v_fp) || PyTuple_CheckExact(__pyx_v_fp)) { - __pyx_t_4 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; - } else { - __pyx_t_2 = __pyx_t_9(__pyx_t_4); - if (unlikely(!__pyx_t_2)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF(__pyx_v_line); - __pyx_v_line = __pyx_t_2; - __pyx_t_2 = 0; - - /* "_cdec.pyx":55 - * with open(cfg) as fp: - * for line in fp: - * fname, value = line.split() # <<<<<<<<<<<<<< - * self.weights[fname.strip()] = float(value) - * + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->vector->size(); + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":47 + * cdef str fname + * for i in range(self.vector.size()): + * fname = FDConvert(it[0].ptr().first).c_str() # <<<<<<<<<<<<<< + * yield (fname, it[0].ptr().second) + * pinc(it[0]) */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { - PyObject* sequence = __pyx_t_1; - if (likely(PyTuple_CheckExact(sequence))) { - 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 = 55; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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 = 55; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_10 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_11 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; - index = 0; __pyx_t_2 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_2)) goto __pyx_L18_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L18_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 = 55; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - goto __pyx_L19_unpacking_done; - __pyx_L18_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 = 55; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_L19_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_fname); - __pyx_v_fname = __pyx_t_2; - __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_v_value); - __pyx_v_value = __pyx_t_10; - __pyx_t_10 = 0; + __pyx_t_3 = PyBytes_FromString(FD::Convert((__pyx_cur_scope->__pyx_v_it[0]).operator->()->first).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_3)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_3))->tp_name), 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fname)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fname)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_cur_scope->__pyx_v_fname = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; - /* "_cdec.pyx":56 - * for line in fp: - * fname, value = line.split() - * self.weights[fname.strip()] = float(value) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":48 + * for i in range(self.vector.size()): + * fname = FDConvert(it[0].ptr().first).c_str() + * yield (fname, it[0].ptr().second) # <<<<<<<<<<<<<< + * pinc(it[0]) * - * # 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 = 56; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_1 = PyFloat_FromDouble(__pyx_t_13); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = PyObject_GetAttr(__pyx_v_fname, __pyx_n_s__strip); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_t_2, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L14_try_end; - __pyx_L7_error:; - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_3 = PyFloat_FromDouble((__pyx_cur_scope->__pyx_v_it[0]).operator->()->second); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_fname)); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_cur_scope->__pyx_v_fname)); + __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_fname)); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_r = ((PyObject *)__pyx_t_4); + __pyx_t_4 = 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_generator->resume_label = 1; + return __pyx_r; + __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[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "_cdec.pyx":53 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":49 + * fname = FDConvert(it[0].ptr().first).c_str() + * yield (fname, it[0].ptr().second) + * pinc(it[0]) # <<<<<<<<<<<<<< * - * def read_weights(self, cfg): - * with open(cfg) as fp: # <<<<<<<<<<<<<< - * for line in fp: - * fname, value = line.split() + * def dot(self, other): */ - /*except:*/ { - __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_1, &__pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __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 = 53; __pyx_clineno = __LINE__; goto __pyx_L9_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 = 53; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __pyx_t_16 = (!__pyx_t_14); - if (__pyx_t_16) { - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_ErrRestore(__pyx_t_4, __pyx_t_1, __pyx_t_2); - __pyx_t_4 = 0; __pyx_t_1 = 0; __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - goto __pyx_L22; - } - __pyx_L22:; - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L8_exception_handled; - } - __pyx_L9_except_error:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - goto __pyx_L1_error; - __pyx_L8_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - __pyx_L14_try_end:; - } - } - /*finally:*/ { - if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_1, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - goto __pyx_L23; - __pyx_L3_error:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L1_error; - __pyx_L23:; + (++(__pyx_cur_scope->__pyx_v_it[0])); } - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XDECREF(__pyx_v_fp); - __Pyx_XDECREF(__pyx_v_line); - __Pyx_XDECREF(__pyx_v_fname); - __Pyx_XDECREF(__pyx_v_value); - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return __pyx_r; + return NULL; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_sentence = 0; - PyObject *__pyx_v_grammar = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sentence,&__pyx_n_s__grammar,0}; +static PyObject *__pyx_pw_5_cdec_12SparseVector_8dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_8dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("translate (wrapper)", 0); - { - PyObject* values[2] = {0,0}; + __Pyx_RefNannySetupContext("dot (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_7dot(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((PyObject *)__pyx_v_other)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":59 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":51 + * pinc(it[0]) * - * # TODO: list, lattice translation - * def translate(self, unicode sentence, grammar=None): # <<<<<<<<<<<<<< - * if grammar: - * self.dec.SetSentenceGrammarFromString(string( grammar)) + * def dot(self, other): # <<<<<<<<<<<<<< + * if isinstance(other, DenseVector): + * return self.vector.dot(( other).vector[0]) */ - values[1] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sentence); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grammar); - if (value) { values[1] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "translate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_sentence = ((PyObject*)values[0]); - __pyx_v_grammar = values[1]; - } - 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 = 59; __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 = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_7Decoder_6translate(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_sentence, __pyx_v_grammar); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_sentence, PyObject *__pyx_v_grammar) { - PyObject *__pyx_v_inp = NULL; - BasicObserver __pyx_v_observer; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hg = 0; +static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - int __pyx_t_1; - char *__pyx_t_2; + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("translate", 0); + __Pyx_RefNannySetupContext("dot", 0); - /* "_cdec.pyx":60 - * # TODO: list, lattice translation - * def translate(self, unicode sentence, grammar=None): - * if grammar: # <<<<<<<<<<<<<< - * self.dec.SetSentenceGrammarFromString(string( grammar)) - * inp = sentence.strip().encode('utf8') + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":52 + * + * def dot(self, other): + * if isinstance(other, DenseVector): # <<<<<<<<<<<<<< + * return self.vector.dot(( other).vector[0]) + * elif isinstance(other, SparseVector): */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_grammar); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_1) { - - /* "_cdec.pyx":61 - * def translate(self, unicode sentence, grammar=None): - * if grammar: - * self.dec.SetSentenceGrammarFromString(string( grammar)) # <<<<<<<<<<<<<< - * inp = sentence.strip().encode('utf8') - * cdef decoder.BasicObserver observer = decoder.BasicObserver() + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_other, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":53 + * def dot(self, other): + * if isinstance(other, DenseVector): + * return self.vector.dot(( other).vector[0]) # <<<<<<<<<<<<<< + * elif isinstance(other, SparseVector): + * return self.vector.dot(( other).vector[0]) */ - __pyx_t_2 = PyBytes_AsString(__pyx_v_grammar); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->dec->SetSentenceGrammarFromString(std::string(((char *)__pyx_t_2))); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->dot((((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_other)->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; goto __pyx_L3; } - __pyx_L3:; - - /* "_cdec.pyx":62 - * if grammar: - * self.dec.SetSentenceGrammarFromString(string( grammar)) - * inp = sentence.strip().encode('utf8') # <<<<<<<<<<<<<< - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - * self.dec.Decode(string(inp), &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 = 62; __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 = 62; __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 = 62; __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_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_inp = __pyx_t_4; - __pyx_t_4 = 0; - - /* "_cdec.pyx":63 - * self.dec.SetSentenceGrammarFromString(string( grammar)) - * inp = sentence.strip().encode('utf8') - * cdef decoder.BasicObserver observer = decoder.BasicObserver() # <<<<<<<<<<<<<< - * self.dec.Decode(string(inp), &observer) - * if observer.hypergraph == NULL: - */ - __pyx_v_observer = BasicObserver(); - - /* "_cdec.pyx":64 - * inp = sentence.strip().encode('utf8') - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - * self.dec.Decode(string(inp), &observer) # <<<<<<<<<<<<<< - * if observer.hypergraph == NULL: - * raise ParseFailed() - */ - __pyx_t_2 = PyBytes_AsString(__pyx_v_inp); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->dec->Decode(std::string(((char *)__pyx_t_2)), (&__pyx_v_observer)); - - /* "_cdec.pyx":65 - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - * self.dec.Decode(string(inp), &observer) - * if observer.hypergraph == NULL: # <<<<<<<<<<<<<< - * raise ParseFailed() - * cdef Hypergraph hg = Hypergraph() - */ - __pyx_t_1 = (__pyx_v_observer.hypergraph == NULL); - if (__pyx_t_1) { - - /* "_cdec.pyx":66 - * self.dec.Decode(string(inp), &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 = 66; __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 = 66; __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 = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L4; - } - __pyx_L4:; - /* "_cdec.pyx":67 - * if observer.hypergraph == NULL: - * raise ParseFailed() - * cdef Hypergraph hg = Hypergraph() # <<<<<<<<<<<<<< - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) - * return hg + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":54 + * if isinstance(other, DenseVector): + * return self.vector.dot(( other).vector[0]) + * elif isinstance(other, SparseVector): # <<<<<<<<<<<<<< + * return self.vector.dot(( other).vector[0]) + * raise ValueError('cannot take the dot product of %s and SparseVector' % type(other)) */ - __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 = 67; __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; + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_other, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { - /* "_cdec.pyx":68 - * raise ParseFailed() - * cdef Hypergraph hg = Hypergraph() - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) # <<<<<<<<<<<<<< - * return hg + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":55 + * return self.vector.dot(( other).vector[0]) + * elif isinstance(other, SparseVector): + * return self.vector.dot(( other).vector[0]) # <<<<<<<<<<<<<< + * raise ValueError('cannot take the dot product of %s and SparseVector' % type(other)) * */ - __pyx_v_hg->hg = new Hypergraph((__pyx_v_observer.hypergraph[0])); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->dot((((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; - /* "_cdec.pyx":69 - * cdef Hypergraph hg = Hypergraph() - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) - * return hg # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":56 + * elif isinstance(other, SparseVector): + * return self.vector.dot(( other).vector[0]) + * raise ValueError('cannot take the dot product of %s and SparseVector' % type(other)) # <<<<<<<<<<<<<< * - * cdef class Hypergraph: + * def todense(self): */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_hg)); - __pyx_r = ((PyObject *)__pyx_v_hg); - goto __pyx_L0; + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), ((PyObject *)Py_TYPE(__pyx_v_other))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.SparseVector.dot", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_inp); - __Pyx_XDECREF((PyObject *)__pyx_v_hg); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_10todense(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_10todense(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights___get__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannySetupContext("todense (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_9todense(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":40 - * cdef class Decoder: - * cdef decoder.Decoder* dec - * cdef public Weights weights # <<<<<<<<<<<<<< +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":58 + * raise ValueError('cannot take the dot product of %s and SparseVector' % type(other)) * - * def __cinit__(self, char* config): + * def todense(self): # <<<<<<<<<<<<<< + * cdef DenseVector dense = DenseVector() + * dense.vector = new vector[weight_t]() */ -static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_9todense(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { + struct __pyx_obj_5_cdec_DenseVector *__pyx_v_dense = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__", 0); + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("todense", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":59 + * + * def todense(self): + * cdef DenseVector dense = DenseVector() # <<<<<<<<<<<<<< + * dense.vector = new vector[weight_t]() + * self.vector.init_vector(dense.vector) + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_dense = ((struct __pyx_obj_5_cdec_DenseVector *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":60 + * def todense(self): + * cdef DenseVector dense = DenseVector() + * dense.vector = new vector[weight_t]() # <<<<<<<<<<<<<< + * self.vector.init_vector(dense.vector) + * return dense + */ + __pyx_v_dense->vector = new std::vector(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":61 + * cdef DenseVector dense = DenseVector() + * dense.vector = new vector[weight_t]() + * self.vector.init_vector(dense.vector) # <<<<<<<<<<<<<< + * return dense + * + */ + __pyx_v_self->vector->init_vector(__pyx_v_dense->vector); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":62 + * dense.vector = new vector[weight_t]() + * self.vector.init_vector(dense.vector) + * return dense # <<<<<<<<<<<<<< + * + * def __richcmp__(SparseVector self, SparseVector other, int op): + */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self->weights)); - __pyx_r = ((PyObject *)__pyx_v_self->weights); + __Pyx_INCREF(((PyObject *)__pyx_v_dense)); + __pyx_r = ((PyObject *)__pyx_v_dense); 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.SparseVector.todense", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_dense); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +static PyObject *__pyx_pw_5_cdec_12SparseVector_12__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_12__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_2__set__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_self), __pyx_ptype_5_cdec_SparseVector, 1, "self", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_11__richcmp__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other), ((int)__pyx_v_op)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":64 + * return dense + * + * def __richcmp__(SparseVector self, SparseVector other, int op): # <<<<<<<<<<<<<< + * if op == 2: # == + * return self.vector[0] == other.vector[0] + */ + +static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other, int __pyx_v_op) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__set__", 0); - 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(__pyx_v_self->weights); - __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); - __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_Weights *)__pyx_v_value); + __Pyx_RefNannySetupContext("__richcmp__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":67 + * if op == 2: # == + * return self.vector[0] == other.vector[0] + * elif op == 3: # != # <<<<<<<<<<<<<< + * return not (self == other) + * raise NotImplemented('comparison not implemented for SparseVector') + */ + switch (__pyx_v_op) { - __pyx_r = 0; + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":65 + * + * def __richcmp__(SparseVector self, SparseVector other, int op): + * if op == 2: # == # <<<<<<<<<<<<<< + * return self.vector[0] == other.vector[0] + * elif op == 3: # != + */ + case 2: + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":66 + * def __richcmp__(SparseVector self, SparseVector other, int op): + * if op == 2: # == + * return self.vector[0] == other.vector[0] # <<<<<<<<<<<<<< + * elif op == 3: # != + * return not (self == other) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_self->vector[0]) == (__pyx_v_other->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":67 + * if op == 2: # == + * return self.vector[0] == other.vector[0] + * elif op == 3: # != # <<<<<<<<<<<<<< + * return not (self == other) + * raise NotImplemented('comparison not implemented for SparseVector') + */ + case 3: + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":68 + * return self.vector[0] == other.vector[0] + * elif op == 3: # != + * return not (self == other) # <<<<<<<<<<<<<< + * raise NotImplemented('comparison not implemented for SparseVector') + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_self), ((PyObject *)__pyx_v_other), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + break; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":69 + * elif op == 3: # != + * return not (self == other) + * raise NotImplemented('comparison not implemented for SparseVector') # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + __pyx_t_1 = PyObject_Call(__pyx_builtin_NotImplemented, ((PyObject *)__pyx_k_tuple_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Decoder.weights.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.SparseVector.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static int __pyx_pw_5_cdec_7Decoder_7weights_5__del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pw_5_cdec_7Decoder_7weights_5__del__(PyObject *__pyx_v_self) { - int __pyx_r; +static Py_ssize_t __pyx_pw_5_cdec_12SparseVector_14__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_12SparseVector_14__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_4__del__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_13__len__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5_cdec_7Decoder_7weights_4__del__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { - int __pyx_r; +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":71 + * raise NotImplemented('comparison not implemented for SparseVector') + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.vector.size() + * + */ + +static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_13__len__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { + Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__", 0); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->weights); - __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); - __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_Weights *)Py_None); + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":72 + * + * def __len__(self): + * return self.vector.size() # <<<<<<<<<<<<<< + * + * def __contains__(self, char* fname): + */ + __pyx_r = __pyx_v_self->vector->size(); + goto __pyx_L0; __pyx_r = 0; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static void __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(PyObject *__pyx_v_self) { +static int __pyx_pw_5_cdec_12SparseVector_16__contains__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ +static int __pyx_pw_5_cdec_12SparseVector_16__contains__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { + char *__pyx_v_fname; + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_10Hypergraph___dealloc__(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0); + assert(__pyx_arg_fname); { + __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.SparseVector.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); -} - -/* "_cdec.pyx":75 - * cdef MT19937* rng + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_12SparseVector_15__contains__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":74 + * return self.vector.size() + * + * def __contains__(self, char* fname): # <<<<<<<<<<<<<< + * return self.vector.nonzero(FDConvert(fname)) * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.hg - * if self.rng != NULL: */ -static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { +static int __pyx_pf_5_cdec_12SparseVector_15__contains__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname) { + int __pyx_r; __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("__dealloc__", 0); + __Pyx_RefNannySetupContext("__contains__", 0); - /* "_cdec.pyx":76 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":75 * - * def __dealloc__(self): - * del self.hg # <<<<<<<<<<<<<< - * if self.rng != NULL: - * del self.rng + * def __contains__(self, char* fname): + * return self.vector.nonzero(FDConvert(fname)) # <<<<<<<<<<<<<< + * + * def __iadd__(SparseVector self, SparseVector other): */ - delete __pyx_v_self->hg; + __pyx_r = __pyx_v_self->vector->nonzero(FD::Convert(__pyx_v_fname)); + goto __pyx_L0; - /* "_cdec.pyx":77 - * def __dealloc__(self): - * del self.hg - * if self.rng != NULL: # <<<<<<<<<<<<<< - * del self.rng + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_12SparseVector_18__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_18__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iadd__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_17__iadd__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":77 + * return self.vector.nonzero(FDConvert(fname)) * + * def __iadd__(SparseVector self, SparseVector other): # <<<<<<<<<<<<<< + * self.vector[0] += other.vector[0] + * return self */ - __pyx_t_1 = (__pyx_v_self->rng != NULL); - if (__pyx_t_1) { - /* "_cdec.pyx":78 - * del self.hg - * if self.rng != NULL: - * del self.rng # <<<<<<<<<<<<<< +static PyObject *__pyx_pf_5_cdec_12SparseVector_17__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iadd__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":78 + * + * def __iadd__(SparseVector self, SparseVector other): + * self.vector[0] += other.vector[0] # <<<<<<<<<<<<<< + * return self * - * def viterbi(self): */ - delete __pyx_v_self->rng; - goto __pyx_L3; - } - __pyx_L3:; + (__pyx_v_self->vector[0]) += (__pyx_v_other->vector[0]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":79 + * def __iadd__(SparseVector self, SparseVector other): + * self.vector[0] += other.vector[0] + * return self # <<<<<<<<<<<<<< + * + * def __isub__(SparseVector self, SparseVector other): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); + goto __pyx_L0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); + return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_3viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_3viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_20__isub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_20__isub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("viterbi (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_2viterbi(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__isub__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_19__isub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":80 - * del self.rng +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":81 + * return self * - * def viterbi(self): # <<<<<<<<<<<<<< - * assert (self.hg != NULL) - * cdef vector[WordID] trans + * def __isub__(SparseVector self, SparseVector other): # <<<<<<<<<<<<<< + * self.vector[0] -= other.vector[0] + * return self */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { - std::vector __pyx_v_trans; - PyObject *__pyx_v_sentence = 0; +static PyObject *__pyx_pf_5_cdec_12SparseVector_19__isub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { 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", 0); + __Pyx_RefNannySetupContext("__isub__", 0); - /* "_cdec.pyx":81 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":82 * - * def viterbi(self): - * assert (self.hg != NULL) # <<<<<<<<<<<<<< - * cdef vector[WordID] trans - * hypergraph.ViterbiESentence(self.hg[0], &trans) + * def __isub__(SparseVector self, SparseVector other): + * self.vector[0] -= other.vector[0] # <<<<<<<<<<<<<< + * return self + * + */ + (__pyx_v_self->vector[0]) -= (__pyx_v_other->vector[0]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":83 + * def __isub__(SparseVector self, SparseVector other): + * self.vector[0] -= other.vector[0] + * return self # <<<<<<<<<<<<<< + * + * def __imul__(SparseVector self, float scalar): */ - #ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!(__pyx_v_self->hg != NULL))) { - PyErr_SetNone(PyExc_AssertionError); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_12SparseVector_22__imul__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_22__imul__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar) { + float __pyx_v_scalar; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__imul__ (wrapper)", 0); + assert(__pyx_arg_scalar); { + __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } - #endif + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.SparseVector.__imul__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_12SparseVector_21__imul__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((float)__pyx_v_scalar)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":83 - * assert (self.hg != NULL) - * cdef vector[WordID] trans - * hypergraph.ViterbiESentence(self.hg[0], &trans) # <<<<<<<<<<<<<< - * cdef str sentence = GetString(trans).c_str() - * return sentence.decode('utf8') +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":85 + * return self + * + * def __imul__(SparseVector self, float scalar): # <<<<<<<<<<<<<< + * self.vector[0] *= scalar + * return self */ - ViterbiESentence((__pyx_v_self->hg[0]), (&__pyx_v_trans)); - /* "_cdec.pyx":84 - * cdef vector[WordID] trans - * hypergraph.ViterbiESentence(self.hg[0], &trans) - * cdef str sentence = GetString(trans).c_str() # <<<<<<<<<<<<<< - * return sentence.decode('utf8') +static PyObject *__pyx_pf_5_cdec_12SparseVector_21__imul__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__imul__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":86 + * + * def __imul__(SparseVector self, float scalar): + * self.vector[0] *= scalar # <<<<<<<<<<<<<< + * return self * */ - __pyx_t_1 = PyBytes_FromString(TD::GetString(__pyx_v_trans).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __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 = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_sentence = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; + (__pyx_v_self->vector[0]) *= __pyx_v_scalar; - /* "_cdec.pyx":85 - * hypergraph.ViterbiESentence(self.hg[0], &trans) - * cdef str sentence = GetString(trans).c_str() - * return sentence.decode('utf8') # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":87 + * def __imul__(SparseVector self, float scalar): + * self.vector[0] *= scalar + * return self # <<<<<<<<<<<<<< * - * def viterbi_tree(self): + * def __idiv__(SparseVector self, float scalar): */ __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 = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __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; + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); 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", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_sentence); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_5viterbi_tree(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_5viterbi_tree(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +#if PY_MAJOR_VERSION < 3 +static PyObject *__pyx_pw_5_cdec_12SparseVector_24__idiv__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_24__idiv__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar) { + float __pyx_v_scalar; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("viterbi_tree (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_4viterbi_tree(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__idiv__ (wrapper)", 0); + assert(__pyx_arg_scalar); { + __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.SparseVector.__idiv__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_12SparseVector_23__idiv__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((float)__pyx_v_scalar)); __Pyx_RefNannyFinishContext(); return __pyx_r; } +#endif /*!(#if PY_MAJOR_VERSION < 3)*/ -/* "_cdec.pyx":87 - * return sentence.decode('utf8') +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":89 + * return self * - * def viterbi_tree(self): # <<<<<<<<<<<<<< - * assert (self.hg != NULL) - * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str() + * def __idiv__(SparseVector self, float scalar): # <<<<<<<<<<<<<< + * self.vector[0] /= scalar + * return self */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_4viterbi_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { - PyObject *__pyx_v_tree = 0; +#if PY_MAJOR_VERSION < 3 +static PyObject *__pyx_pf_5_cdec_12SparseVector_23__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar) { 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", 0); + __Pyx_RefNannySetupContext("__idiv__", 0); - /* "_cdec.pyx":88 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":90 * - * 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(!(__pyx_v_self->hg != NULL))) { - PyErr_SetNone(PyExc_AssertionError); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - #endif - - /* "_cdec.pyx":89 - * def viterbi_tree(self): - * assert (self.hg != NULL) - * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str() # <<<<<<<<<<<<<< - * return tree.decode('utf8') + * def __idiv__(SparseVector self, float scalar): + * self.vector[0] /= scalar # <<<<<<<<<<<<<< + * return self * */ - __pyx_t_1 = PyBytes_FromString(ViterbiETree((__pyx_v_self->hg[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __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;} - __pyx_v_tree = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; + (__pyx_v_self->vector[0]) /= __pyx_v_scalar; - /* "_cdec.pyx":90 - * assert (self.hg != NULL) - * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str() - * return tree.decode('utf8') # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":91 + * def __idiv__(SparseVector self, float scalar): + * self.vector[0] /= scalar + * return self # <<<<<<<<<<<<<< * - * def kbest(self, size): + * def __add__(SparseVector self, SparseVector other): */ __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 = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __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; + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); 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_8generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +#endif /*!(#if PY_MAJOR_VERSION < 3)*/ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_7kbest(PyObject *__pyx_v_self, PyObject *__pyx_v_size); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_7kbest(PyObject *__pyx_v_self, PyObject *__pyx_v_size) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("kbest (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_6kbest(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_size)); + __Pyx_RefNannySetupContext("__add__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_self), __pyx_ptype_5_cdec_SparseVector, 1, "self", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_25__add__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":92 - * return tree.decode('utf8') +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":93 + * return self * - * 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) + * def __add__(SparseVector self, SparseVector other): # <<<<<<<<<<<<<< + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](self.vector[0] + other.vector[0]) */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_6kbest(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size) { - struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; 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("kbest", 0); - __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_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __pyx_cur_scope->__pyx_v_size = __pyx_v_size; - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_8generator1, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } + __Pyx_RefNannySetupContext("__add__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":94 + * + * def __add__(SparseVector self, SparseVector other): + * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< + * result.vector = new FastSparseVector[weight_t](self.vector[0] + other.vector[0]) + * return result + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":95 + * def __add__(SparseVector self, SparseVector other): + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](self.vector[0] + other.vector[0]) # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_v_result->vector = new FastSparseVector(((__pyx_v_self->vector[0]) + (__pyx_v_other->vector[0]))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":96 + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](self.vector[0] + other.vector[0]) + * return result # <<<<<<<<<<<<<< + * + * def __sub__(SparseVector self, SparseVector other): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Hypergraph.kbest", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.SparseVector.__add__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_10Hypergraph_8generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *)__pyx_generator->closure); - 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; +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("None", 0); - switch (__pyx_generator->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 = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_RefNannySetupContext("__sub__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_self), __pyx_ptype_5_cdec_SparseVector, 1, "self", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_27__sub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":93 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":98 + * return result * - * 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 + * def __sub__(SparseVector self, SparseVector other): # <<<<<<<<<<<<<< + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](self.vector[0] - other.vector[0]) */ - #ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!(__pyx_cur_scope->__pyx_v_self->hg != NULL))) { - PyErr_SetNone(PyExc_AssertionError); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - #endif - /* "_cdec.pyx":94 - * 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 +static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; + 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("__sub__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":99 + * + * def __sub__(SparseVector self, SparseVector other): + * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< + * result.vector = new FastSparseVector[weight_t](self.vector[0] - other.vector[0]) + * return result */ - __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 = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,ESentenceTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; - /* "_cdec.pyx":98 - * cdef str tree - * cdef unsigned k - * for k in range(size): # <<<<<<<<<<<<<< - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":100 + * def __sub__(SparseVector self, SparseVector other): + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](self.vector[0] - other.vector[0]) # <<<<<<<<<<<<<< + * return result */ - __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 = 98; __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; + __pyx_v_result->vector = new FastSparseVector(((__pyx_v_self->vector[0]) - (__pyx_v_other->vector[0]))); - /* "_cdec.pyx":99 - * 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() + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":101 + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](self.vector[0] - other.vector[0]) + * return result # <<<<<<<<<<<<<< */ - __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + goto __pyx_L0; - /* "_cdec.pyx":100 - * 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_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.SparseVector.__sub__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_10Hypergraph___dealloc__(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":8 + * cdef MT19937* rng + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.hg + * if self.rng != NULL: */ - __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":101 - * 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 +static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":9 + * + * def __dealloc__(self): + * del self.hg # <<<<<<<<<<<<<< + * if self.rng != NULL: + * del self.rng */ - __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 = 101; __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 = 101; __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; + delete __pyx_v_self->hg; - /* "_cdec.pyx":102 - * if not derivation: break - * tree = GetString(derivation._yield).c_str() - * yield tree.decode('utf8') # <<<<<<<<<<<<<< - * del derivations + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":10 + * def __dealloc__(self): + * del self.hg + * if self.rng != NULL: # <<<<<<<<<<<<<< + * del self.rng * */ - __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 = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __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_generator->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 = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L5_break:; + __pyx_t_1 = (__pyx_v_self->rng != NULL); + if (__pyx_t_1) { - /* "_cdec.pyx":103 - * tree = GetString(derivation._yield).c_str() - * yield tree.decode('utf8') - * del derivations # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":11 + * del self.hg + * if self.rng != NULL: + * del self.rng # <<<<<<<<<<<<<< * - * def kbest_tree(self, size): + * def viterbi(self): */ - delete __pyx_cur_scope->__pyx_v_derivations; - PyErr_SetNone(PyExc_StopIteration); - 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_generator->resume_label = -1; + delete __pyx_v_self->rng; + goto __pyx_L3; + } + __pyx_L3:; + __Pyx_RefNannyFinishContext(); - return NULL; } -static PyObject *__pyx_gb_5_cdec_10Hypergraph_11generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_10kbest_tree(PyObject *__pyx_v_self, PyObject *__pyx_v_size); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_10kbest_tree(PyObject *__pyx_v_self, PyObject *__pyx_v_size) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_3viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_3viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("kbest_tree (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_9kbest_tree(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_size)); + __Pyx_RefNannySetupContext("viterbi (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_2viterbi(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":105 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":13 + * del self.rng * - * 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) + * def viterbi(self): # <<<<<<<<<<<<<< + * cdef vector[WordID] trans + * hypergraph.ViterbiESentence(self.hg[0], &trans) */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_9kbest_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size) { - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + std::vector __pyx_v_trans; + PyObject *__pyx_v_sentence = 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("kbest_tree", 0); - __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_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __pyx_cur_scope->__pyx_v_size = __pyx_v_size; - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_11generator2, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } + __Pyx_RefNannySetupContext("viterbi", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":15 + * def viterbi(self): + * cdef vector[WordID] trans + * hypergraph.ViterbiESentence(self.hg[0], &trans) # <<<<<<<<<<<<<< + * cdef str sentence = GetString(trans).c_str() + * return sentence.decode('utf8') + */ + ViterbiESentence((__pyx_v_self->hg[0]), (&__pyx_v_trans)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":16 + * 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[2]; __pyx_lineno = 16; __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[2]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_sentence = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":17 + * 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[2]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 17; __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_AddTraceback("_cdec.Hypergraph.kbest_tree", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec.Hypergraph.viterbi", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XDECREF(__pyx_v_sentence); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_10Hypergraph_11generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *)__pyx_generator->closure); - 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; +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_5viterbi_tree(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_5viterbi_tree(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("None", 0); - switch (__pyx_generator->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 = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_RefNannySetupContext("viterbi_tree (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_4viterbi_tree(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":106 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":19 + * return sentence.decode('utf8') * - * 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 + * def viterbi_tree(self): # <<<<<<<<<<<<<< + * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str() + * return tree.decode('utf8') */ - #ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!(__pyx_cur_scope->__pyx_v_self->hg != NULL))) { - PyErr_SetNone(PyExc_AssertionError); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - #endif - /* "_cdec.pyx":107 - * 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 = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,ETreeTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); +static PyObject *__pyx_pf_5_cdec_10Hypergraph_4viterbi_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + 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", 0); - /* "_cdec.pyx":111 - * cdef str sentence - * cdef unsigned k - * for k in range(size): # <<<<<<<<<<<<<< - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":20 + * + * def viterbi_tree(self): + * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str() # <<<<<<<<<<<<<< + * return tree.decode('utf8') + * */ - __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 = 111; __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; + __pyx_t_1 = PyBytes_FromString(ViterbiETree((__pyx_v_self->hg[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 20; __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[2]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_tree = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; - /* "_cdec.pyx":112 - * 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() + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":21 + * def viterbi_tree(self): + * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str() + * return tree.decode('utf8') # <<<<<<<<<<<<<< + * + * def viterbi_source_tree(self): */ - __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); + __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[2]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 21; __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; - /* "_cdec.pyx":113 - * 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:; + __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; +} - /* "_cdec.pyx":114 - * 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 +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_7viterbi_source_tree(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_7viterbi_source_tree(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("viterbi_source_tree (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_6viterbi_source_tree(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":23 + * return tree.decode('utf8') + * + * def viterbi_source_tree(self): # <<<<<<<<<<<<<< + * cdef str tree = hypergraph.ViterbiFTree(self.hg[0]).c_str() + * return tree.decode('utf8') */ - __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 = 114; __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 = 114; __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":115 - * if not derivation: break - * sentence = GetString(derivation._yield).c_str() - * yield sentence.decode('utf8') # <<<<<<<<<<<<<< - * del derivations +static PyObject *__pyx_pf_5_cdec_10Hypergraph_6viterbi_source_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + 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_source_tree", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":24 + * + * def viterbi_source_tree(self): + * cdef str tree = hypergraph.ViterbiFTree(self.hg[0]).c_str() # <<<<<<<<<<<<<< + * return tree.decode('utf8') * */ - __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 = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __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_generator->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 = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L5_break:; + __pyx_t_1 = PyBytes_FromString(ViterbiFTree((__pyx_v_self->hg[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 24; __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[2]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_tree = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; - /* "_cdec.pyx":116 - * sentence = GetString(derivation._yield).c_str() - * yield sentence.decode('utf8') - * del derivations # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":25 + * def viterbi_source_tree(self): + * cdef str tree = hypergraph.ViterbiFTree(self.hg[0]).c_str() + * return tree.decode('utf8') # <<<<<<<<<<<<<< * - * def intersect(self, Lattice lat): + * def viterbi_features(self): */ - delete __pyx_cur_scope->__pyx_v_derivations; - PyErr_SetNone(PyExc_StopIteration); + __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[2]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_6), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 25; __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_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("kbest_tree", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec.Hypergraph.viterbi_source_tree", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; + __Pyx_XDECREF(__pyx_v_tree); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); - return NULL; + return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_13intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_13intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_9viterbi_features(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_9viterbi_features(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("intersect (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lat), __pyx_ptype_5_cdec_Lattice, 1, "lat", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_12intersect(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_lat)); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; + __Pyx_RefNannySetupContext("viterbi_features (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_8viterbi_features(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":118 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":27 + * return tree.decode('utf8') * - * def intersect(self, Lattice lat): # <<<<<<<<<<<<<< - * assert (self.hg != NULL) - * hypergraph.Intersect(lat.lattice[0], self.hg) + * def viterbi_features(self): # <<<<<<<<<<<<<< + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_12intersect(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, struct __pyx_obj_5_cdec_Lattice *__pyx_v_lat) { +static PyObject *__pyx_pf_5_cdec_10Hypergraph_8viterbi_features(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap = 0; 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("intersect", 0); + __Pyx_RefNannySetupContext("viterbi_features", 0); - /* "_cdec.pyx":119 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":28 * - * def intersect(self, Lattice lat): - * assert (self.hg != NULL) # <<<<<<<<<<<<<< - * hypergraph.Intersect(lat.lattice[0], self.hg) + * def viterbi_features(self): + * cdef SparseVector fmap = SparseVector() # <<<<<<<<<<<<<< + * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) + * return fmap + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":29 + * def viterbi_features(self): + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) # <<<<<<<<<<<<<< + * return fmap * */ - #ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!(__pyx_v_self->hg != NULL))) { - PyErr_SetNone(PyExc_AssertionError); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - #endif + __pyx_v_fmap->vector = new FastSparseVector(ViterbiFeatures((__pyx_v_self->hg[0]))); - /* "_cdec.pyx":120 - * def intersect(self, Lattice lat): - * assert (self.hg != NULL) - * hypergraph.Intersect(lat.lattice[0], self.hg) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":30 + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) + * return fmap # <<<<<<<<<<<<<< * - * def sample(self, unsigned n): + * def kbest(self, size): */ - HG::Intersect((__pyx_v_lat->lattice[0]), __pyx_v_self->hg); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_fmap)); + __pyx_r = ((PyObject *)__pyx_v_fmap); + goto __pyx_L0; __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_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.Hypergraph.viterbi_features", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_fmap); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_10Hypergraph_16generator3(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5_cdec_10Hypergraph_12generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_15sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_15sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n) { - unsigned int __pyx_v_n; +static PyObject *__pyx_pw_5_cdec_10Hypergraph_11kbest(PyObject *__pyx_v_self, PyObject *__pyx_v_size); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_11kbest(PyObject *__pyx_v_self, PyObject *__pyx_v_size) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("sample (wrapper)", 0); - assert(__pyx_arg_n); { - __pyx_v_n = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_n); if (unlikely((__pyx_v_n == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __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_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_14sample(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((unsigned int)__pyx_v_n)); + __Pyx_RefNannySetupContext("kbest (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_10kbest(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_size)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":122 - * hypergraph.Intersect(lat.lattice[0], self.hg) +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":32 + * return fmap * - * def sample(self, unsigned n): # <<<<<<<<<<<<<< - * assert (self.hg != NULL) - * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() + * def kbest(self, size): # <<<<<<<<<<<<<< + * 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 */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_14sample(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, unsigned int __pyx_v_n) { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_10kbest(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *__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", 0); - __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); + __Pyx_RefNannySetupContext("kbest", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)__pyx_ptype_5_cdec___pyx_scope_struct_2_kbest->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_2_kbest, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -2772,9 +3013,11 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_14sample(struct __pyx_obj_5_cdec_H __pyx_cur_scope->__pyx_v_self = __pyx_v_self; __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __pyx_cur_scope->__pyx_v_n = __pyx_v_n; + __pyx_cur_scope->__pyx_v_size = __pyx_v_size; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_16generator3, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_12generator2, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -2783,7 +3026,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_14sample(struct __pyx_obj_5_cdec_H __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Hypergraph.sample", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Hypergraph.kbest", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); @@ -2792,13 +3035,13 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_14sample(struct __pyx_obj_5_cdec_H return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_10Hypergraph_16generator3(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_10Hypergraph_12generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *)__pyx_generator->closure); + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)__pyx_generator->closure); PyObject *__pyx_r = NULL; - int __pyx_t_1; - size_t __pyx_t_2; - unsigned int __pyx_t_3; + 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 @@ -2811,451 +3054,3374 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_16generator3(__pyx_GeneratorObject return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "_cdec.pyx":123 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":33 * - * def sample(self, unsigned n): - * assert (self.hg != NULL) # <<<<<<<<<<<<<< - * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() - * if self.rng == NULL: + * def kbest(self, size): + * 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 sentence */ - #ifndef CYTHON_WITHOUT_ASSERTIONS - if (unlikely(!(__pyx_cur_scope->__pyx_v_self->hg != NULL))) { - PyErr_SetNone(PyExc_AssertionError); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - #endif + __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[2]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,ESentenceTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); - /* "_cdec.pyx":124 - * 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() + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":37 + * 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_cur_scope->__pyx_v_hypos = new std::vector(); + __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[2]; __pyx_lineno = 37; __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":125 - * 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) + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":38 + * 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_t_1 = (__pyx_cur_scope->__pyx_v_self->rng == NULL); - if (__pyx_t_1) { + __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); - /* "_cdec.pyx":126 - * 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 - */ - __pyx_cur_scope->__pyx_v_self->rng = new MT19937(); - goto __pyx_L4; - } - __pyx_L4:; - - /* "_cdec.pyx":127 - * 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((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_cur_scope->__pyx_v_n, __pyx_cur_scope->__pyx_v_self->rng, __pyx_cur_scope->__pyx_v_hypos); - - /* "_cdec.pyx":130 - * cdef str sentence - * cdef unsigned k - * for k in range(hypos.size()): # <<<<<<<<<<<<<< - * sentence = GetString(hypos[0][k].words).c_str() + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":39 + * 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_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; + __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":131 - * cdef unsigned k - * for k in range(hypos.size()): - * sentence = GetString(hypos[0][k].words).c_str() # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":40 + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break + * sentence = GetString(derivation._yield).c_str() # <<<<<<<<<<<<<< * yield sentence.decode('utf8') - * del hypos + * del derivations */ - __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 = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __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[2]; __pyx_lineno = 40; __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 = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + 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[2]; __pyx_lineno = 40; __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":132 - * for k in range(hypos.size()): - * sentence = GetString(hypos[0][k].words).c_str() + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":41 + * if not derivation: break + * sentence = GetString(derivation._yield).c_str() * yield sentence.decode('utf8') # <<<<<<<<<<<<<< - * del hypos + * 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 = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __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[2]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 41; __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_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_generator->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 = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __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[2]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } + __pyx_L5_break:; - /* "_cdec.pyx":133 - * sentence = GetString(hypos[0][k].words).c_str() + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":42 + * sentence = GetString(derivation._yield).c_str() * yield sentence.decode('utf8') - * del hypos # <<<<<<<<<<<<<< + * del derivations # <<<<<<<<<<<<<< * - * # TODO: get feature expectations, get partition function ("inside" score) + * def kbest_tree(self, size): */ - delete __pyx_cur_scope->__pyx_v_hypos; + delete __pyx_cur_scope->__pyx_v_derivations; PyErr_SetNone(PyExc_StopIteration); 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_AddTraceback("kbest", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); return NULL; } +static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator3(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static int __pyx_pw_5_cdec_7Lattice_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5_cdec_7Lattice_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_plf_tuple = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__plf_tuple,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); - { - PyObject* values[1] = {0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_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, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __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 = 142; __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 = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_7Lattice___init__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), __pyx_v_plf_tuple); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "_cdec.pyx":142 - * 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__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, PyObject *__pyx_v_plf_tuple) { - 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; - __Pyx_RefNannySetupContext("__init__", 0); - - /* "_cdec.pyx":143 - * - * def __init__(self, tuple plf_tuple): - * self.lattice = new lattice.Lattice() # <<<<<<<<<<<<<< - * cdef bytes plf = str(plf_tuple) - * hypergraph.PLFtoLattice(string(plf), self.lattice) - */ - __pyx_v_self->lattice = new Lattice(); - - /* "_cdec.pyx":144 - * def __init__(self, tuple plf_tuple): - * self.lattice = new lattice.Lattice() - * cdef bytes plf = str(plf_tuple) # <<<<<<<<<<<<<< - * hypergraph.PLFtoLattice(string(plf), self.lattice) - * - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__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 = 144; __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 = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_plf = ((PyObject*)__pyx_t_2); - __pyx_t_2 = 0; - - /* "_cdec.pyx":145 - * self.lattice = new lattice.Lattice() - * cdef bytes plf = str(plf_tuple) - * hypergraph.PLFtoLattice(string(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 = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - HypergraphIO::PLFtoLattice(std::string(((char *)__pyx_t_3)), __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; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Lattice_3__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Lattice_3__str__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_14kbest_tree(PyObject *__pyx_v_self, PyObject *__pyx_v_size); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_14kbest_tree(PyObject *__pyx_v_self, PyObject *__pyx_v_size) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Lattice_2__str__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __Pyx_RefNannySetupContext("kbest_tree (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_13kbest_tree(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_size)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":147 - * hypergraph.PLFtoLattice(string(plf), self.lattice) - * - * def __str__(self): # <<<<<<<<<<<<<< - * return hypergraph.AsPLF(self.lattice[0]).c_str() +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":44 + * del derivations * + * def kbest_tree(self, size): # <<<<<<<<<<<<<< + * 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 */ -static PyObject *__pyx_pf_5_cdec_7Lattice_2__str__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_10Hypergraph_13kbest_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *__pyx_cur_scope; 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__", 0); - - /* "_cdec.pyx":148 - * - * 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((__pyx_v_self->lattice[0]), NULL).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __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_RefNannySetupContext("kbest_tree", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)__pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_tree->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_tree, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __pyx_cur_scope->__pyx_v_size = __pyx_v_size; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_15generator3, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } __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_AddTraceback("_cdec.Hypergraph.kbest_tree", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Lattice_5__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Lattice_5__iter__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator3(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)__pyx_generator->closure); + 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("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Lattice_4__iter__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->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[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} -/* "_cdec.pyx":150 - * return hypergraph.AsPLF(self.lattice[0]).c_str() - * - * def __iter__(self): # <<<<<<<<<<<<<< - * return iter(eval(str(self))) + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":45 * + * def kbest_tree(self, size): + * 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 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[2]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,ETreeTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); -static PyObject *__pyx_pf_5_cdec_7Lattice_4__iter__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__iter__", 0); + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":49 + * 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[2]; __pyx_lineno = 49; __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":151 - * - * def __iter__(self): - * return iter(eval(str(self))) # <<<<<<<<<<<<<< - * - * def __dealloc__(self): + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":50 + * 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_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__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 = 151; __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 = __Pyx_Globals(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - if (((PyObject *)__pyx_v_self)) { - if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_v_self)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":51 + * 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:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":52 + * 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[2]; __pyx_lineno = 52; __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[2]; __pyx_lineno = 52; __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; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":53 + * 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[2]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 53; __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_generator->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[2]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - PyTuple_SET_ITEM(__pyx_t_4, 2, ((PyObject *)__pyx_t_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); - __pyx_t_2 = 0; - __pyx_t_1 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_eval, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; + __pyx_L5_break:; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":54 + * tree = GetString(derivation._yield).c_str() + * yield tree.decode('utf8') + * del derivations # <<<<<<<<<<<<<< + * + * def sample(self, unsigned n): + */ + delete __pyx_cur_scope->__pyx_v_derivations; + PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec.Lattice.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("kbest_tree", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return __pyx_r; + return NULL; } +static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static void __pyx_pw_5_cdec_7Lattice_7__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_7Lattice_7__dealloc__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_17sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_17sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n) { + unsigned int __pyx_v_n; + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_7Lattice_6__dealloc__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __Pyx_RefNannySetupContext("sample (wrapper)", 0); + assert(__pyx_arg_n); { + __pyx_v_n = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_n); if (unlikely((__pyx_v_n == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __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_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_16sample(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((unsigned int)__pyx_v_n)); __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* "_cdec.pyx":153 - * return iter(eval(str(self))) - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.lattice +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 + * del derivations * + * def sample(self, unsigned n): # <<<<<<<<<<<<<< + * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() + * if self.rng == NULL: */ -static void __pyx_pf_5_cdec_7Lattice_6__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_10Hypergraph_16sample(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, unsigned int __pyx_v_n) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *__pyx_cur_scope; + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("sample", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *)__pyx_ptype_5_cdec___pyx_scope_struct_4_sample->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_4_sample, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __pyx_cur_scope->__pyx_v_n = __pyx_v_n; + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_18generator4, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Hypergraph.sample", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *)__pyx_generator->closure); + 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", 0); + switch (__pyx_generator->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[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "_cdec.pyx":154 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":57 * - * def __dealloc__(self): - * del self.lattice # <<<<<<<<<<<<<< + * def sample(self, unsigned n): + * 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(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":58 + * def sample(self, unsigned n): + * 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 = (__pyx_cur_scope->__pyx_v_self->rng == NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":59 + * 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 + */ + __pyx_cur_scope->__pyx_v_self->rng = new MT19937(); + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":60 + * 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((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_cur_scope->__pyx_v_n, __pyx_cur_scope->__pyx_v_self->rng, __pyx_cur_scope->__pyx_v_hypos); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":63 + * 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; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":64 + * 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[2]; __pyx_lineno = 64; __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[2]; __pyx_lineno = 64; __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; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":65 + * for k in range(hypos.size()): + * sentence = GetString(hypos[0][k].words).c_str() + * yield sentence.decode('utf8') # <<<<<<<<<<<<<< + * del hypos * - * # TODO: wrap SparseVector */ - delete __pyx_v_self->lattice; + __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[2]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 65; __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_generator->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[2]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":66 + * sentence = GetString(hypos[0][k].words).c_str() + * yield sentence.decode('utf8') + * del hypos # <<<<<<<<<<<<<< + * + * # TODO richer k-best/sample output (feature vectors, trees?) + */ + delete __pyx_cur_scope->__pyx_v_hypos; + PyErr_SetNone(PyExc_StopIteration); + 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_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); + return NULL; } -static PyObject *__pyx_tp_new_5_cdec_Weights(PyTypeObject *t, PyObject *a, PyObject *k) { +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_20intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_20intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("intersect (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lat), __pyx_ptype_5_cdec_Lattice, 1, "lat", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_19intersect(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_lat)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":70 + * # TODO richer k-best/sample output (feature vectors, trees?) + * + * def intersect(self, Lattice lat): # <<<<<<<<<<<<<< + * return hypergraph.Intersect(lat.lattice[0], self.hg) + * + */ + +static PyObject *__pyx_pf_5_cdec_10Hypergraph_19intersect(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, struct __pyx_obj_5_cdec_Lattice *__pyx_v_lat) { + 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("intersect", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":71 + * + * def intersect(self, Lattice lat): + * return hypergraph.Intersect(lat.lattice[0], self.hg) # <<<<<<<<<<<<<< + * + * def prune(self, beam_alpha=0, density=0, **kwargs): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong(HG::Intersect((__pyx_v_lat->lattice[0]), __pyx_v_self->hg)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_cdec.Hypergraph.intersect", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_22prune(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_22prune(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_beam_alpha = 0; + PyObject *__pyx_v_density = 0; + PyObject *__pyx_v_kwargs = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__beam_alpha,&__pyx_n_s__density,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("prune (wrapper)", 0); + __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL; + __Pyx_GOTREF(__pyx_v_kwargs); + { + PyObject* values[2] = {0,0}; + values[0] = ((PyObject *)__pyx_int_0); + values[1] = ((PyObject *)__pyx_int_0); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__beam_alpha); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__density); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "prune") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_beam_alpha = values[0]; + __pyx_v_density = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("prune", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; + __Pyx_AddTraceback("_cdec.Hypergraph.prune", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_21prune(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), __pyx_v_beam_alpha, __pyx_v_density, __pyx_v_kwargs); + __Pyx_XDECREF(__pyx_v_kwargs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":73 + * return hypergraph.Intersect(lat.lattice[0], self.hg) + * + * def prune(self, beam_alpha=0, density=0, **kwargs): # <<<<<<<<<<<<<< + * cdef hypergraph.EdgeMask* preserve_mask = NULL + * if 'csplit_preserve_full_word' in kwargs: + */ + +static PyObject *__pyx_pf_5_cdec_10Hypergraph_21prune(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_beam_alpha, PyObject *__pyx_v_density, PyObject *__pyx_v_kwargs) { + std::vector *__pyx_v_preserve_mask; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + double __pyx_t_2; + double __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("prune", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":74 + * + * def prune(self, beam_alpha=0, density=0, **kwargs): + * cdef hypergraph.EdgeMask* preserve_mask = NULL # <<<<<<<<<<<<<< + * if 'csplit_preserve_full_word' in kwargs: + * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) + */ + __pyx_v_preserve_mask = NULL; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":75 + * def prune(self, beam_alpha=0, density=0, **kwargs): + * cdef hypergraph.EdgeMask* preserve_mask = NULL + * if 'csplit_preserve_full_word' in kwargs: # <<<<<<<<<<<<<< + * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) + * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True + */ + __pyx_t_1 = ((PyDict_Contains(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s_10)))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":76 + * cdef hypergraph.EdgeMask* preserve_mask = NULL + * if 'csplit_preserve_full_word' in kwargs: + * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) # <<<<<<<<<<<<<< + * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True + * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) + */ + __pyx_v_preserve_mask = new std::vector(__pyx_v_self->hg->edges_.size()); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":77 + * if 'csplit_preserve_full_word' in kwargs: + * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) + * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True # <<<<<<<<<<<<<< + * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) + * + */ + ((__pyx_v_preserve_mask[0])[CompoundSplit::GetFullWordEdgeIndex((__pyx_v_self->hg[0]))]) = 1; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":78 + * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) + * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True + * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) # <<<<<<<<<<<<<< + * + * def lattice(self): # TODO direct hg -> lattice conversion in cdec + */ + __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_beam_alpha); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_density); if (unlikely((__pyx_t_3 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->hg->PruneInsideOutside(__pyx_t_2, __pyx_t_3, __pyx_v_preserve_mask, 0, 1.0, 0); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Hypergraph.prune", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_24lattice(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_24lattice(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("lattice (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_23lattice(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":80 + * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) + * + * def lattice(self): # TODO direct hg -> lattice conversion in cdec # <<<<<<<<<<<<<< + * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() + * return Lattice(eval(plf)) + */ + +static PyObject *__pyx_pf_5_cdec_10Hypergraph_23lattice(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + PyObject *__pyx_v_plf = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("lattice", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":81 + * + * def lattice(self): # TODO direct hg -> lattice conversion in cdec + * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() # <<<<<<<<<<<<<< + * return Lattice(eval(plf)) + * + */ + __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->hg[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 81; __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[2]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_plf = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":82 + * def lattice(self): # TODO direct hg -> lattice conversion in cdec + * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() + * return Lattice(eval(plf)) # <<<<<<<<<<<<<< + * + * def reweight(self, weights): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_Globals(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + if (((PyObject *)__pyx_v_plf)) { + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__plf), ((PyObject *)__pyx_v_plf)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + if (((PyObject *)__pyx_v_self)) { + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_v_self)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(((PyObject *)__pyx_v_plf)); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_plf)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_plf)); + PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_builtin_eval, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec.Hypergraph.lattice", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_plf); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_26reweight(PyObject *__pyx_v_self, PyObject *__pyx_v_weights); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_26reweight(PyObject *__pyx_v_self, PyObject *__pyx_v_weights) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("reweight (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_25reweight(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_weights)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":84 + * return Lattice(eval(plf)) + * + * def reweight(self, weights): # <<<<<<<<<<<<<< + * if isinstance(weights, SparseVector): + * self.hg.Reweight(( weights).vector[0]) + */ + +static PyObject *__pyx_pf_5_cdec_10Hypergraph_25reweight(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_weights) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("reweight", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":85 + * + * def reweight(self, weights): + * if isinstance(weights, SparseVector): # <<<<<<<<<<<<<< + * self.hg.Reweight(( weights).vector[0]) + * elif isinstance(weights, DenseVector): + */ + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":86 + * def reweight(self, weights): + * if isinstance(weights, SparseVector): + * self.hg.Reweight(( weights).vector[0]) # <<<<<<<<<<<<<< + * elif isinstance(weights, DenseVector): + * self.hg.Reweight(( weights).vector[0]) + */ + __pyx_v_self->hg->Reweight((((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_weights)->vector[0])); + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":87 + * if isinstance(weights, SparseVector): + * self.hg.Reweight(( weights).vector[0]) + * elif isinstance(weights, DenseVector): # <<<<<<<<<<<<<< + * self.hg.Reweight(( weights).vector[0]) + * else: + */ + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":88 + * self.hg.Reweight(( weights).vector[0]) + * elif isinstance(weights, DenseVector): + * self.hg.Reweight(( weights).vector[0]) # <<<<<<<<<<<<<< + * else: + * raise ValueError('cannot reweight hypergraph with %s' % type(weights)) + */ + __pyx_v_self->hg->Reweight((((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_weights)->vector[0])); + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":90 + * self.hg.Reweight(( weights).vector[0]) + * else: + * raise ValueError('cannot reweight hypergraph with %s' % type(weights)) # <<<<<<<<<<<<<< + * + * # TODO get feature expectations, get partition function ("inside" score) + */ + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec.Hypergraph.reweight", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_7Lattice_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_7Lattice_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_inp = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__inp,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__inp); + 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, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 6; __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_inp = 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[3]; __pyx_lineno = 6; __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:; + __pyx_r = __pyx_pf_5_cdec_7Lattice___init__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), __pyx_v_inp); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":6 + * cdef lattice.Lattice* lattice + * + * def __init__(self, inp): # <<<<<<<<<<<<<< + * if isinstance(inp, tuple): + * self.lattice = new lattice.Lattice(len(inp)) + */ + +static int __pyx_pf_5_cdec_7Lattice___init__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, PyObject *__pyx_v_inp) { + PyObject *__pyx_v_i = NULL; + PyObject *__pyx_v_arcs = NULL; + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + Py_ssize_t __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *(*__pyx_t_5)(PyObject *); + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + char *__pyx_t_8; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__init__", 0); + __Pyx_INCREF(__pyx_v_inp); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":7 + * + * def __init__(self, inp): + * if isinstance(inp, tuple): # <<<<<<<<<<<<<< + * self.lattice = new lattice.Lattice(len(inp)) + * for i, arcs in enumerate(inp): + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyTuple_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_inp, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":8 + * def __init__(self, inp): + * if isinstance(inp, tuple): + * self.lattice = new lattice.Lattice(len(inp)) # <<<<<<<<<<<<<< + * for i, arcs in enumerate(inp): + * self[i] = arcs + */ + __pyx_t_3 = PyObject_Length(__pyx_v_inp); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->lattice = new Lattice(__pyx_t_3); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":9 + * if isinstance(inp, tuple): + * self.lattice = new lattice.Lattice(len(inp)) + * for i, arcs in enumerate(inp): # <<<<<<<<<<<<<< + * self[i] = arcs + * else: + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_1 = __pyx_int_0; + if (PyList_CheckExact(__pyx_v_inp) || PyTuple_CheckExact(__pyx_v_inp)) { + __pyx_t_4 = __pyx_v_inp; __Pyx_INCREF(__pyx_t_4); __pyx_t_3 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_inp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_4)) break; + __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; + } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; + } else { + __pyx_t_6 = __pyx_t_5(__pyx_t_4); + if (unlikely(!__pyx_t_6)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_6); + } + __Pyx_XDECREF(__pyx_v_arcs); + __pyx_v_arcs = __pyx_t_6; + __pyx_t_6 = 0; + __Pyx_INCREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_1; + __pyx_t_6 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); + __pyx_t_1 = __pyx_t_6; + __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":10 + * self.lattice = new lattice.Lattice(len(inp)) + * for i, arcs in enumerate(inp): + * self[i] = arcs # <<<<<<<<<<<<<< + * else: + * if isinstance(inp, unicode): + */ + if (PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_v_i, __pyx_v_arcs) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":12 + * self[i] = arcs + * else: + * if isinstance(inp, unicode): # <<<<<<<<<<<<<< + * inp = inp.encode('utf8') + * if not isinstance(inp, str): + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_inp, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":13 + * else: + * if isinstance(inp, unicode): + * inp = inp.encode('utf8') # <<<<<<<<<<<<<< + * if not isinstance(inp, str): + * raise TypeError('Cannot create lattice from %s' % type(inp)) + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_inp, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_12), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_v_inp); + __pyx_v_inp = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":14 + * if isinstance(inp, unicode): + * inp = inp.encode('utf8') + * if not isinstance(inp, str): # <<<<<<<<<<<<<< + * raise TypeError('Cannot create lattice from %s' % type(inp)) + * self.lattice = new lattice.Lattice() + */ + __pyx_t_4 = ((PyObject *)((PyObject*)(&PyString_Type))); + __Pyx_INCREF(__pyx_t_4); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_inp, __pyx_t_4); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_7 = (!__pyx_t_2); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":15 + * inp = inp.encode('utf8') + * if not isinstance(inp, str): + * raise TypeError('Cannot create lattice from %s' % type(inp)) # <<<<<<<<<<<<<< + * self.lattice = new lattice.Lattice() + * lattice.ConvertTextToLattice(string(inp), self.lattice) + */ + __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_13), ((PyObject *)Py_TYPE(__pyx_v_inp))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L7; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":16 + * if not isinstance(inp, str): + * raise TypeError('Cannot create lattice from %s' % type(inp)) + * self.lattice = new lattice.Lattice() # <<<<<<<<<<<<<< + * lattice.ConvertTextToLattice(string(inp), self.lattice) + * + */ + __pyx_v_self->lattice = new Lattice(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":17 + * raise TypeError('Cannot create lattice from %s' % type(inp)) + * self.lattice = new lattice.Lattice() + * lattice.ConvertTextToLattice(string(inp), self.lattice) # <<<<<<<<<<<<<< + * + * def __getitem__(self, int index): + */ + __pyx_t_8 = PyBytes_AsString(__pyx_v_inp); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + LatticeTools::ConvertTextToLattice(std::string(((char *)__pyx_t_8)), __pyx_v_self->lattice); + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_cdec.Lattice.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_arcs); + __Pyx_XDECREF(__pyx_v_inp); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Lattice_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Lattice_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index) { + int __pyx_v_index; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + assert(__pyx_arg_index); { + __pyx_v_index = __Pyx_PyInt_AsInt(__pyx_arg_index); if (unlikely((__pyx_v_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.Lattice.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_7Lattice_2__getitem__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), ((int)__pyx_v_index)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":19 + * lattice.ConvertTextToLattice(string(inp), self.lattice) + * + * def __getitem__(self, int index): # <<<<<<<<<<<<<< + * if not 0 <= index < len(self): + * raise IndexError('lattice index out of range') + */ + +static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index) { + PyObject *__pyx_v_arcs = NULL; + std::vector __pyx_v_arc_vector; + LatticeArc *__pyx_v_arc; + PyObject *__pyx_v_label = 0; + unsigned int __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + Py_ssize_t __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + size_t __pyx_t_5; + unsigned int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + int __pyx_t_10; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__getitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":20 + * + * def __getitem__(self, int index): + * if not 0 <= index < len(self): # <<<<<<<<<<<<<< + * raise IndexError('lattice index out of range') + * arcs = [] + */ + __pyx_t_1 = (0 <= __pyx_v_index); + if (__pyx_t_1) { + __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = (__pyx_v_index < __pyx_t_2); + } + __pyx_t_3 = (!__pyx_t_1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":21 + * def __getitem__(self, int index): + * if not 0 <= index < len(self): + * raise IndexError('lattice index out of range') # <<<<<<<<<<<<<< + * arcs = [] + * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] + */ + __pyx_t_4 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_15), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":22 + * if not 0 <= index < len(self): + * raise IndexError('lattice index out of range') + * arcs = [] # <<<<<<<<<<<<<< + * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] + * cdef lattice.LatticeArc* arc + */ + __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_arcs = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":23 + * raise IndexError('lattice index out of range') + * arcs = [] + * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] # <<<<<<<<<<<<<< + * cdef lattice.LatticeArc* arc + * cdef str label + */ + __pyx_v_arc_vector = ((__pyx_v_self->lattice[0])[__pyx_v_index]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":27 + * cdef str label + * cdef unsigned i + * for i in range(arc_vector.size()): # <<<<<<<<<<<<<< + * arc = &arc_vector[i] + * label = TDConvert(arc.label) + */ + __pyx_t_5 = __pyx_v_arc_vector.size(); + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_v_i = __pyx_t_6; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":28 + * cdef unsigned i + * for i in range(arc_vector.size()): + * arc = &arc_vector[i] # <<<<<<<<<<<<<< + * label = TDConvert(arc.label) + * arcs.append((label.decode('utf8'), arc.cost, arc.dist2next)) + */ + __pyx_v_arc = (&(__pyx_v_arc_vector[__pyx_v_i])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":29 + * for i in range(arc_vector.size()): + * arc = &arc_vector[i] + * label = TDConvert(arc.label) # <<<<<<<<<<<<<< + * arcs.append((label.decode('utf8'), arc.cost, arc.dist2next)) + * return tuple(arcs) + */ + __pyx_t_4 = PyBytes_FromString(TD::Convert(__pyx_v_arc->label)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 29; __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[3]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XDECREF(((PyObject *)__pyx_v_label)); + __pyx_v_label = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":30 + * arc = &arc_vector[i] + * label = TDConvert(arc.label) + * arcs.append((label.decode('utf8'), arc.cost, arc.dist2next)) # <<<<<<<<<<<<<< + * return tuple(arcs) + * + */ + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_label), __pyx_n_s__decode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_16), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyFloat_FromDouble(__pyx_v_arc->cost); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = PyInt_FromLong(__pyx_v_arc->dist2next); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_7 = 0; + __pyx_t_4 = 0; + __pyx_t_8 = 0; + __pyx_t_10 = PyList_Append(__pyx_v_arcs, ((PyObject *)__pyx_t_9)); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":31 + * label = TDConvert(arc.label) + * arcs.append((label.decode('utf8'), arc.cost, arc.dist2next)) + * return tuple(arcs) # <<<<<<<<<<<<<< + * + * def __setitem__(self, int index, tuple arcs): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_9 = ((PyObject *)PyList_AsTuple(__pyx_v_arcs)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __pyx_r = ((PyObject *)__pyx_t_9); + __pyx_t_9 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("_cdec.Lattice.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_arcs); + __Pyx_XDECREF(__pyx_v_label); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_7Lattice_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index, PyObject *__pyx_v_arcs); /*proto*/ +static int __pyx_pw_5_cdec_7Lattice_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index, PyObject *__pyx_v_arcs) { + int __pyx_v_index; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); + assert(__pyx_arg_index); { + __pyx_v_index = __Pyx_PyInt_AsInt(__pyx_arg_index); if (unlikely((__pyx_v_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.Lattice.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_arcs), (&PyTuple_Type), 1, "arcs", 1))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_7Lattice_4__setitem__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), ((int)__pyx_v_index), ((PyObject*)__pyx_v_arcs)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":33 + * return tuple(arcs) + * + * def __setitem__(self, int index, tuple arcs): # <<<<<<<<<<<<<< + * if not 0 <= index < len(self): + * raise IndexError('lattice index out of range') + */ + +static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index, PyObject *__pyx_v_arcs) { + LatticeArc *__pyx_v_arc; + PyObject *__pyx_v_label = NULL; + PyObject *__pyx_v_cost = NULL; + PyObject *__pyx_v_dist2next = NULL; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + Py_ssize_t __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *(*__pyx_t_10)(PyObject *); + char *__pyx_t_11; + double __pyx_t_12; + int __pyx_t_13; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__setitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":34 + * + * def __setitem__(self, int index, tuple arcs): + * if not 0 <= index < len(self): # <<<<<<<<<<<<<< + * raise IndexError('lattice index out of range') + * cdef lattice.LatticeArc* arc + */ + __pyx_t_1 = (0 <= __pyx_v_index); + if (__pyx_t_1) { + __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = (__pyx_v_index < __pyx_t_2); + } + __pyx_t_3 = (!__pyx_t_1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":35 + * def __setitem__(self, int index, tuple arcs): + * if not 0 <= index < len(self): + * raise IndexError('lattice index out of range') # <<<<<<<<<<<<<< + * cdef lattice.LatticeArc* arc + * for (label, cost, dist2next) in arcs: + */ + __pyx_t_4 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_17), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":37 + * raise IndexError('lattice index out of range') + * cdef lattice.LatticeArc* arc + * for (label, cost, dist2next) in arcs: # <<<<<<<<<<<<<< + * if isinstance(label, unicode): + * label = label.encode('utf8') + */ + if (unlikely(((PyObject *)__pyx_v_arcs) == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_4 = ((PyObject *)__pyx_v_arcs); __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0; + for (;;) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) { + PyObject* sequence = __pyx_t_5; + if (likely(PyTuple_CheckExact(sequence))) { + if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { + if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 2); + } else { + if (unlikely(PyList_GET_SIZE(sequence) != 3)) { + if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_6 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + __pyx_t_8 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_9 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; + index = 0; __pyx_t_6 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + index = 1; __pyx_t_7 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + index = 2; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L7_unpacking_done; + __pyx_L6_unpacking_failed:; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L7_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_label); + __pyx_v_label = __pyx_t_6; + __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_v_cost); + __pyx_v_cost = __pyx_t_7; + __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_v_dist2next); + __pyx_v_dist2next = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":38 + * cdef lattice.LatticeArc* arc + * for (label, cost, dist2next) in arcs: + * if isinstance(label, unicode): # <<<<<<<<<<<<<< + * label = label.encode('utf8') + * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) + */ + __pyx_t_5 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_5); + __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_label, __pyx_t_5); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":39 + * for (label, cost, dist2next) in arcs: + * if isinstance(label, unicode): + * label = label.encode('utf8') # <<<<<<<<<<<<<< + * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) + * self.lattice[0][index].push_back(arc[0]) + */ + __pyx_t_5 = PyObject_GetAttr(__pyx_v_label, __pyx_n_s__encode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_18), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_v_label); + __pyx_v_label = __pyx_t_8; + __pyx_t_8 = 0; + goto __pyx_L8; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":40 + * if isinstance(label, unicode): + * label = label.encode('utf8') + * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) # <<<<<<<<<<<<<< + * self.lattice[0][index].push_back(arc[0]) + * del arc + */ + __pyx_t_11 = PyBytes_AsString(__pyx_v_label); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_v_cost); if (unlikely((__pyx_t_12 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_v_dist2next); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_arc = new LatticeArc(TD::Convert(((char *)__pyx_t_11)), __pyx_t_12, __pyx_t_13); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":41 + * label = label.encode('utf8') + * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) + * self.lattice[0][index].push_back(arc[0]) # <<<<<<<<<<<<<< + * del arc + * + */ + ((__pyx_v_self->lattice[0])[__pyx_v_index]).push_back((__pyx_v_arc[0])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":42 + * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) + * self.lattice[0][index].push_back(arc[0]) + * del arc # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + delete __pyx_v_arc; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("_cdec.Lattice.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_label); + __Pyx_XDECREF(__pyx_v_cost); + __Pyx_XDECREF(__pyx_v_dist2next); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_5_cdec_7Lattice_7__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_7Lattice_7__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Lattice_6__len__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":44 + * del arc + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.lattice.size() + * + */ + +static Py_ssize_t __pyx_pf_5_cdec_7Lattice_6__len__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":45 + * + * def __len__(self): + * return self.lattice.size() # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + __pyx_r = __pyx_v_self->lattice->size(); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Lattice_9__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Lattice_9__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Lattice_8__str__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":47 + * return self.lattice.size() + * + * def __str__(self): # <<<<<<<<<<<<<< + * return hypergraph.AsPLF(self.lattice[0], True).c_str() + * + */ + +static PyObject *__pyx_pf_5_cdec_7Lattice_8__str__(struct __pyx_obj_5_cdec_Lattice *__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__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":48 + * + * def __str__(self): + * return hypergraph.AsPLF(self.lattice[0], True).c_str() # <<<<<<<<<<<<<< + * + * def __iter__(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->lattice[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __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; +} +static PyObject *__pyx_gb_5_cdec_7Lattice_12generator5(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Lattice_11__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Lattice_11__iter__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Lattice_10__iter__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":50 + * return hypergraph.AsPLF(self.lattice[0], True).c_str() + * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(len(self)): + */ + +static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__iter__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_5___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_5___iter__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Lattice_12generator5, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Lattice.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5_cdec_7Lattice_12generator5(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + Py_ssize_t __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":52 + * def __iter__(self): + * cdef unsigned i + * for i in range(len(self)): # <<<<<<<<<<<<<< + * yield self[i] + * + */ + __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":53 + * cdef unsigned i + * for i in range(len(self)): + * yield self[i] # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 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_generator->resume_label = 1; + return __pyx_r; + __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[3]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_7Lattice_14__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_7Lattice_14__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_7Lattice_13__dealloc__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":55 + * yield self[i] + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.lattice + */ + +static void __pyx_pf_5_cdec_7Lattice_13__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":56 + * + * def __dealloc__(self): + * del self.lattice # <<<<<<<<<<<<<< + */ + delete __pyx_v_self->lattice; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + char *__pyx_v_config; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__config,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__config); + 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __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 = 19; __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 = 19; __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:; + __pyx_r = __pyx_pf_5_cdec_7Decoder___cinit__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_config); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":19 + * cdef public DenseVector weights + * + * def __cinit__(self, char* config): # <<<<<<<<<<<<<< + * decoder.register_feature_functions() + * cdef istringstream* config_stream = new istringstream(config) + */ + +static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, char *__pyx_v_config) { + std::istringstream *__pyx_v_config_stream; + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "_cdec.pyx":20 + * + * def __cinit__(self, char* config): + * decoder.register_feature_functions() # <<<<<<<<<<<<<< + * cdef istringstream* config_stream = new istringstream(config) + * self.dec = new decoder.Decoder(config_stream) + */ + register_feature_functions(); + + /* "_cdec.pyx":21 + * def __cinit__(self, char* config): + * decoder.register_feature_functions() + * cdef istringstream* config_stream = new istringstream(config) # <<<<<<<<<<<<<< + * self.dec = new decoder.Decoder(config_stream) + * del config_stream + */ + __pyx_v_config_stream = new std::istringstream(__pyx_v_config); + + /* "_cdec.pyx":22 + * decoder.register_feature_functions() + * cdef istringstream* config_stream = new istringstream(config) + * self.dec = new decoder.Decoder(config_stream) # <<<<<<<<<<<<<< + * del config_stream + * self.weights = DenseVector() + */ + __pyx_v_self->dec = new Decoder(__pyx_v_config_stream); + + /* "_cdec.pyx":23 + * cdef istringstream* config_stream = new istringstream(config) + * self.dec = new decoder.Decoder(config_stream) + * del config_stream # <<<<<<<<<<<<<< + * self.weights = DenseVector() + * self.weights.vector = &self.dec.CurrentWeightVector() + */ + delete __pyx_v_config_stream; + + /* "_cdec.pyx":24 + * self.dec = new decoder.Decoder(config_stream) + * del config_stream + * self.weights = DenseVector() # <<<<<<<<<<<<<< + * self.weights.vector = &self.dec.CurrentWeightVector() + * + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->weights); + __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); + __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "_cdec.pyx":25 + * del config_stream + * self.weights = DenseVector() + * self.weights.vector = &self.dec.CurrentWeightVector() # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->weights->vector = (&__pyx_v_self->dec->CurrentWeightVector()); + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.Decoder.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_7Decoder_2__dealloc__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "_cdec.pyx":27 + * self.weights.vector = &self.dec.CurrentWeightVector() + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.dec + * + */ + +static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "_cdec.pyx":28 + * + * def __dealloc__(self): + * del self.dec # <<<<<<<<<<<<<< + * + * def read_weights(self, cfg): + */ + delete __pyx_v_self->dec; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_cfg); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_cfg) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_weights (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_4read_weights(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_cfg)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":30 + * del self.dec + * + * def read_weights(self, cfg): # <<<<<<<<<<<<<< + * with open(cfg) as fp: + * for line in fp: + */ + +static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_cfg) { + PyObject *__pyx_v_fp = NULL; + PyObject *__pyx_v_line = NULL; + PyObject *__pyx_v_fname = NULL; + PyObject *__pyx_v_value = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *(*__pyx_t_12)(PyObject *); + double __pyx_t_13; + int __pyx_t_14; + PyObject *__pyx_t_15 = NULL; + int __pyx_t_16; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_weights", 0); + + /* "_cdec.pyx":31 + * + * def read_weights(self, cfg): + * with open(cfg) as fp: # <<<<<<<<<<<<<< + * for line in fp: + * fname, value = line.split() + */ + /*with:*/ { + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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 = 31; __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 = 31; __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 = 31; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_fp = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_cdec.pyx":32 + * def read_weights(self, cfg): + * with open(cfg) as fp: + * for line in fp: # <<<<<<<<<<<<<< + * fname, value = line.split() + * self.weights[fname.strip()] = float(value) + */ + if (PyList_CheckExact(__pyx_v_fp) || PyTuple_CheckExact(__pyx_v_fp)) { + __pyx_t_4 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else { + __pyx_t_2 = __pyx_t_9(__pyx_t_4); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF(__pyx_v_line); + __pyx_v_line = __pyx_t_2; + __pyx_t_2 = 0; + + /* "_cdec.pyx":33 + * with open(cfg) as fp: + * for line in fp: + * fname, value = line.split() # <<<<<<<<<<<<<< + * self.weights[fname.strip()] = float(value) + * + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { + PyObject* sequence = __pyx_t_1; + if (likely(PyTuple_CheckExact(sequence))) { + 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 = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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 = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + __pyx_t_2 = PyList_GET_ITEM(sequence, 0); + __pyx_t_10 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_11 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; + index = 0; __pyx_t_2 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_2)) goto __pyx_L18_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L18_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 = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L19_unpacking_done; + __pyx_L18_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 = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_L19_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_fname); + __pyx_v_fname = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_v_value); + __pyx_v_value = __pyx_t_10; + __pyx_t_10 = 0; + + /* "_cdec.pyx":34 + * for line in fp: + * fname, value = line.split() + * self.weights[fname.strip()] = float(value) # <<<<<<<<<<<<<< + * + * def translate(self, sentence, grammar=None): + */ + __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 = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyFloat_FromDouble(__pyx_t_13); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = PyObject_GetAttr(__pyx_v_fname, __pyx_n_s__strip); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_t_2, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_cdec.pyx":31 + * + * def read_weights(self, cfg): + * with open(cfg) as fp: # <<<<<<<<<<<<<< + * for line in fp: + * fname, value = line.split() + */ + /*except:*/ { + __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_1, &__pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __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 = 31; __pyx_clineno = __LINE__; goto __pyx_L9_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 = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_16 = (!__pyx_t_14); + if (__pyx_t_16) { + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_ErrRestore(__pyx_t_4, __pyx_t_1, __pyx_t_2); + __pyx_t_4 = 0; __pyx_t_1 = 0; __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L22; + } + __pyx_L22:; + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_19, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L23; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L23:; + } + + __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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_fp); + __Pyx_XDECREF(__pyx_v_line); + __Pyx_XDECREF(__pyx_v_fname); + __Pyx_XDECREF(__pyx_v_value); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_sentence = 0; + PyObject *__pyx_v_grammar = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sentence,&__pyx_n_s__grammar,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("translate (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + + /* "_cdec.pyx":36 + * self.weights[fname.strip()] = float(value) + * + * def translate(self, sentence, grammar=None): # <<<<<<<<<<<<<< + * if isinstance(sentence, unicode): + * inp = sentence.strip().encode('utf8') + */ + values[1] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sentence); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grammar); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "translate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_sentence = values[0]; + __pyx_v_grammar = values[1]; + } + 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 = 36; __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:; + __pyx_r = __pyx_pf_5_cdec_7Decoder_6translate(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_sentence, __pyx_v_grammar); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_sentence, PyObject *__pyx_v_grammar) { + PyObject *__pyx_v_inp = NULL; + BasicObserver __pyx_v_observer; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hg = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + char *__pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("translate", 0); + + /* "_cdec.pyx":37 + * + * def translate(self, sentence, grammar=None): + * if isinstance(sentence, unicode): # <<<<<<<<<<<<<< + * inp = sentence.strip().encode('utf8') + * elif isinstance(sentence, str): + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":38 + * def translate(self, sentence, grammar=None): + * if isinstance(sentence, unicode): + * inp = sentence.strip().encode('utf8') # <<<<<<<<<<<<<< + * elif isinstance(sentence, str): + * inp = sentence.strip() + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_inp = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3; + } + + /* "_cdec.pyx":39 + * if isinstance(sentence, unicode): + * inp = sentence.strip().encode('utf8') + * elif isinstance(sentence, str): # <<<<<<<<<<<<<< + * inp = sentence.strip() + * elif isinstance(sentence, Lattice): + */ + __pyx_t_3 = ((PyObject *)((PyObject*)(&PyString_Type))); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":40 + * inp = sentence.strip().encode('utf8') + * elif isinstance(sentence, str): + * inp = sentence.strip() # <<<<<<<<<<<<<< + * elif isinstance(sentence, Lattice): + * inp = str(sentence) # PLF format + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_inp = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L3; + } + + /* "_cdec.pyx":41 + * elif isinstance(sentence, str): + * inp = sentence.strip() + * elif isinstance(sentence, Lattice): # <<<<<<<<<<<<<< + * inp = str(sentence) # PLF format + * else: + */ + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":42 + * inp = sentence.strip() + * elif isinstance(sentence, Lattice): + * inp = str(sentence) # PLF format # <<<<<<<<<<<<<< + * else: + * raise TypeError('Cannot translate input type %s' % type(sentence)) + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_sentence); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_sentence); + __Pyx_GIVEREF(__pyx_v_sentence); + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_v_inp = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "_cdec.pyx":44 + * inp = str(sentence) # PLF format + * else: + * raise TypeError('Cannot translate input type %s' % type(sentence)) # <<<<<<<<<<<<<< + * if grammar: + * self.dec.SetSentenceGrammarFromString(string( grammar)) + */ + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_21), ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 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 = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; + + /* "_cdec.pyx":45 + * else: + * raise TypeError('Cannot translate input type %s' % type(sentence)) + * if grammar: # <<<<<<<<<<<<<< + * self.dec.SetSentenceGrammarFromString(string( grammar)) + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_grammar); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "_cdec.pyx":46 + * raise TypeError('Cannot translate input type %s' % type(sentence)) + * if grammar: + * self.dec.SetSentenceGrammarFromString(string( grammar)) # <<<<<<<<<<<<<< + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + * self.dec.Decode(string(inp), &observer) + */ + __pyx_t_4 = PyBytes_AsString(__pyx_v_grammar); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->dec->SetSentenceGrammarFromString(std::string(((char *)__pyx_t_4))); + goto __pyx_L4; + } + __pyx_L4:; + + /* "_cdec.pyx":47 + * if grammar: + * self.dec.SetSentenceGrammarFromString(string( grammar)) + * cdef decoder.BasicObserver observer = decoder.BasicObserver() # <<<<<<<<<<<<<< + * self.dec.Decode(string(inp), &observer) + * if observer.hypergraph == NULL: + */ + __pyx_v_observer = BasicObserver(); + + /* "_cdec.pyx":48 + * self.dec.SetSentenceGrammarFromString(string( grammar)) + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + * self.dec.Decode(string(inp), &observer) # <<<<<<<<<<<<<< + * if observer.hypergraph == NULL: + * raise ParseFailed() + */ + __pyx_t_4 = PyBytes_AsString(__pyx_v_inp); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->dec->Decode(std::string(((char *)__pyx_t_4)), (&__pyx_v_observer)); + + /* "_cdec.pyx":49 + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + * self.dec.Decode(string(inp), &observer) + * if observer.hypergraph == NULL: # <<<<<<<<<<<<<< + * raise ParseFailed() + * cdef Hypergraph hg = Hypergraph() + */ + __pyx_t_2 = (__pyx_v_observer.hypergraph == NULL); + if (__pyx_t_2) { + + /* "_cdec.pyx":50 + * self.dec.Decode(string(inp), &observer) + * if observer.hypergraph == NULL: + * raise ParseFailed() # <<<<<<<<<<<<<< + * cdef Hypergraph hg = Hypergraph() + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__ParseFailed); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L5; + } + __pyx_L5:; + + /* "_cdec.pyx":51 + * if observer.hypergraph == NULL: + * raise ParseFailed() + * cdef Hypergraph hg = Hypergraph() # <<<<<<<<<<<<<< + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) + * return hg + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Hypergraph)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_hg = ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "_cdec.pyx":52 + * raise ParseFailed() + * cdef Hypergraph hg = Hypergraph() + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) # <<<<<<<<<<<<<< + * return hg + */ + __pyx_v_hg->hg = new Hypergraph((__pyx_v_observer.hypergraph[0])); + + /* "_cdec.pyx":53 + * cdef Hypergraph hg = Hypergraph() + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) + * return hg # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_hg)); + __pyx_r = ((PyObject *)__pyx_v_hg); + 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_3); + __Pyx_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_inp); + __Pyx_XDECREF((PyObject *)__pyx_v_hg); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights___get__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":17 + * cdef class Decoder: + * cdef decoder.Decoder* dec + * cdef public DenseVector weights # <<<<<<<<<<<<<< + * + * def __cinit__(self, char* config): + */ + +static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->weights)); + __pyx_r = ((PyObject *)__pyx_v_self->weights); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_2__set__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); + if (!(likely(((__pyx_v_value) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_value, __pyx_ptype_5_cdec_DenseVector))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->weights); + __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); + __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_value); + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Decoder.weights.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_7Decoder_7weights_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_5_cdec_7Decoder_7weights_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_4__del__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5_cdec_7Decoder_7weights_4__del__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->weights); + __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); + __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_tp_new_5_cdec_DenseVector(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_DenseVector(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_5_cdec_DenseVector(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_5_cdec_DenseVector(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_5_cdec_11DenseVector_3__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_DenseVector[] = { + {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_8dot, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("tosparse"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_10tosparse, METH_NOARGS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_DenseVector = { + 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_DenseVector = { + 0, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5_cdec_DenseVector, /*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_DenseVector = { + 0, /*mp_length*/ + __pyx_pw_5_cdec_11DenseVector_1__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5_cdec_DenseVector, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_DenseVector = { + #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_DenseVector = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.DenseVector"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_DenseVector), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_DenseVector, /*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_DenseVector, /*tp_as_number*/ + &__pyx_tp_as_sequence_DenseVector, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_DenseVector, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_DenseVector, /*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_pw_5_cdec_11DenseVector_5__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_DenseVector, /*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_DenseVector, /*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_SparseVector(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_SparseVector(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_5_cdec_SparseVector(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_5_cdec_SparseVector(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_5_cdec_12SparseVector_3__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_SparseVector[] = { + {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_8dot, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("todense"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_10todense, METH_NOARGS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_SparseVector = { + __pyx_pw_5_cdec_12SparseVector_26__add__, /*nb_add*/ + __pyx_pw_5_cdec_12SparseVector_28__sub__, /*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 + __pyx_pw_5_cdec_12SparseVector_18__iadd__, /*nb_inplace_add*/ + __pyx_pw_5_cdec_12SparseVector_20__isub__, /*nb_inplace_subtract*/ + __pyx_pw_5_cdec_12SparseVector_22__imul__, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + __pyx_pw_5_cdec_12SparseVector_24__idiv__, /*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_SparseVector = { + __pyx_pw_5_cdec_12SparseVector_14__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5_cdec_SparseVector, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + __pyx_pw_5_cdec_12SparseVector_16__contains__, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_SparseVector = { + __pyx_pw_5_cdec_12SparseVector_14__len__, /*mp_length*/ + __pyx_pw_5_cdec_12SparseVector_1__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5_cdec_SparseVector, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_SparseVector = { + #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_SparseVector = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.SparseVector"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_SparseVector), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_SparseVector, /*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_SparseVector, /*tp_as_number*/ + &__pyx_tp_as_sequence_SparseVector, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_SparseVector, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_SparseVector, /*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*/ + __pyx_pw_5_cdec_12SparseVector_12__richcmp__, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + __pyx_pw_5_cdec_12SparseVector_5__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_SparseVector, /*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_SparseVector, /*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_Hypergraph(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_Hypergraph(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_10Hypergraph_1__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_pw_5_cdec_10Hypergraph_3viterbi, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("viterbi_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_5viterbi_tree, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("viterbi_source_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_7viterbi_source_tree, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("viterbi_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_9viterbi_features, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("kbest"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_11kbest, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("kbest_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_14kbest_tree, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("sample"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_17sample, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("intersect"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_20intersect, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("prune"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_22prune, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("lattice"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_24lattice, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("reweight"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_26reweight, METH_O, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Hypergraph = { + 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_Hypergraph = { + 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_Hypergraph = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = { + #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_Hypergraph = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.Hypergraph"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Hypergraph), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_Hypergraph, /*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_Hypergraph, /*tp_as_number*/ + &__pyx_tp_as_sequence_Hypergraph, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Hypergraph, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Hypergraph, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_Hypergraph, /*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_Hypergraph, /*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_Lattice(PyTypeObject *t, PyObject *a, PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - if (__pyx_pw_5_cdec_7Weights_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } return o; } -static void __pyx_tp_dealloc_5_cdec_Weights(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec_Lattice(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_7Lattice_14__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_sq_item_5_cdec_Weights(PyObject *o, Py_ssize_t i) { +static PyObject *__pyx_sq_item_5_cdec_Lattice(PyObject *o, Py_ssize_t i) { PyObject *r; PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); @@ -3263,9 +6429,9 @@ static PyObject *__pyx_sq_item_5_cdec_Weights(PyObject *o, Py_ssize_t i) { return r; } -static int __pyx_mp_ass_subscript_5_cdec_Weights(PyObject *o, PyObject *i, PyObject *v) { +static int __pyx_mp_ass_subscript_5_cdec_Lattice(PyObject *o, PyObject *i, PyObject *v) { if (v) { - return __pyx_pw_5_cdec_7Weights_5__setitem__(o, i, v); + return __pyx_pw_5_cdec_7Lattice_5__setitem__(o, i, v); } else { PyErr_Format(PyExc_NotImplementedError, @@ -3274,11 +6440,11 @@ static int __pyx_mp_ass_subscript_5_cdec_Weights(PyObject *o, PyObject *i, PyObj } } -static PyMethodDef __pyx_methods_5_cdec_Weights[] = { +static PyMethodDef __pyx_methods_5_cdec_Lattice[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_Weights = { +static PyNumberMethods __pyx_tp_as_number_Lattice = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -3336,11 +6502,11 @@ static PyNumberMethods __pyx_tp_as_number_Weights = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Weights = { - 0, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence_Lattice = { + __pyx_pw_5_cdec_7Lattice_7__len__, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_Weights, /*sq_item*/ + __pyx_sq_item_5_cdec_Lattice, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -3349,13 +6515,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Weights = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Weights = { - 0, /*mp_length*/ - __pyx_pw_5_cdec_7Weights_3__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_5_cdec_Weights, /*mp_ass_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping_Lattice = { + __pyx_pw_5_cdec_7Lattice_7__len__, /*mp_length*/ + __pyx_pw_5_cdec_7Lattice_3__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5_cdec_Lattice, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Weights = { +static PyBufferProcs __pyx_tp_as_buffer_Lattice = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -3376,12 +6542,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Weights = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Weights = { +static PyTypeObject __pyx_type_5_cdec_Lattice = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Weights"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Weights), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.Lattice"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Lattice), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Weights, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_Lattice, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -3391,24 +6557,24 @@ static PyTypeObject __pyx_type_5_cdec_Weights = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Weights, /*tp_as_number*/ - &__pyx_tp_as_sequence_Weights, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Weights, /*tp_as_mapping*/ + &__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*/ - 0, /*tp_str*/ + __pyx_pw_5_cdec_7Lattice_9__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Weights, /*tp_as_buffer*/ + &__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_pw_5_cdec_7Weights_7__iter__, /*tp_iter*/ + __pyx_pw_5_cdec_7Lattice_11__iter__, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Weights, /*tp_methods*/ + __pyx_methods_5_cdec_Lattice, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -3416,9 +6582,9 @@ static PyTypeObject __pyx_type_5_cdec_Weights = { 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ - 0, /*tp_init*/ + __pyx_pw_5_cdec_7Lattice_1__init__, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Weights, /*tp_new*/ + __pyx_tp_new_5_cdec_Lattice, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -3437,7 +6603,7 @@ static PyObject *__pyx_tp_new_5_cdec_Decoder(PyTypeObject *t, PyObject *a, PyObj PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; p = ((struct __pyx_obj_5_cdec_Decoder *)o); - p->weights = ((struct __pyx_obj_5_cdec_Weights *)Py_None); Py_INCREF(Py_None); + p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); if (__pyx_pw_5_cdec_7Decoder_1__cinit__(o, a, k) < 0) { Py_DECREF(o); o = 0; } @@ -3472,7 +6638,7 @@ static int __pyx_tp_clear_5_cdec_Decoder(PyObject *o) { struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; PyObject* tmp; tmp = ((PyObject*)p->weights); - p->weights = ((struct __pyx_obj_5_cdec_Weights *)Py_None); Py_INCREF(Py_None); + p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } @@ -3655,36 +6821,44 @@ static PyTypeObject __pyx_type_5_cdec_Decoder = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Hypergraph(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct____iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o); + p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec_Hypergraph(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static PyMethodDef __pyx_methods_5_cdec_Hypergraph[] = { - {__Pyx_NAMESTR("viterbi"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_3viterbi, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("viterbi_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_5viterbi_tree, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("kbest"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_7kbest, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("kbest_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_10kbest_tree, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("intersect"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_13intersect, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("sample"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_15sample, METH_O, __Pyx_DOCSTR(0)}, +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct____iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_Hypergraph = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -3742,7 +6916,7 @@ static PyNumberMethods __pyx_tp_as_number_Hypergraph = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Hypergraph = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct____iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -3755,13 +6929,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Hypergraph = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Hypergraph = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct____iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -3782,12 +6956,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Hypergraph = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Hypergraph"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Hypergraph), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct____iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct____iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Hypergraph, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -3797,24 +6971,24 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Hypergraph, /*tp_as_number*/ - &__pyx_tp_as_sequence_Hypergraph, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Hypergraph, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct____iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct____iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct____iter__, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Hypergraph, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct____iter__, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Hypergraph, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct____iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -3824,7 +6998,7 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Hypergraph, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct____iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -3838,30 +7012,52 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Lattice(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o); + p->__pyx_v_fname = 0; + p->__pyx_v_self = 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_pw_5_cdec_7Lattice_7__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_fname)); + Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static PyMethodDef __pyx_methods_5_cdec_Lattice[] = { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; + if (p->__pyx_v_fname) { + e = (*v)(p->__pyx_v_fname, a); if (e) return e; + } + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_fname); + p->__pyx_v_fname = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_1___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_Lattice = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -3919,7 +7115,7 @@ static PyNumberMethods __pyx_tp_as_number_Lattice = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Lattice = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -3932,13 +7128,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Lattice = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Lattice = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Lattice = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -3959,12 +7155,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Lattice = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Lattice = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Lattice"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Lattice), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_1___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Lattice, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -3974,24 +7170,24 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { 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*/ + &__pyx_tp_as_number___pyx_scope_struct_1___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_1___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_1___iter__, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ - __pyx_pw_5_cdec_7Lattice_3__str__, /*tp_str*/ + 0, /*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*/ + &__pyx_tp_as_buffer___pyx_scope_struct_1___iter__, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_7Lattice_5__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Lattice, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_1___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -3999,9 +7195,9 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ - __pyx_pw_5_cdec_7Lattice_1__init__, /*tp_init*/ + 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Lattice, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -4015,44 +7211,60 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct____iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)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____iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(((PyObject *)p->__pyx_v_sentence)); + Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } + if (p->__pyx_v_sentence) { + e = (*v)(p->__pyx_v_sentence, a); if (e) return e; + } + if (p->__pyx_v_size) { + e = (*v)(p->__pyx_v_size, a); if (e) return e; + } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Weights *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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____iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_2_kbest[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -4110,7 +7322,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct____iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -4123,13 +7335,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct____iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct____iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_2_kbest = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -4150,12 +7362,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct____iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct____iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_2_kbest"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -4165,24 +7377,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct____iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct____iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct____iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_2_kbest, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_2_kbest, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_2_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____iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_2_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____iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct____iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_2_kbest, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -4192,7 +7404,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct____iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -4206,28 +7418,28 @@ 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; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_tree(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1_kbest *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)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; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_kbest_tree(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); Py_XDECREF(p->__pyx_v_size); Py_XDECREF(((PyObject *)p->__pyx_v_tree)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1_kbest(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_kbest_tree(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; + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } @@ -4240,8 +7452,8 @@ static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1_kbest(PyObject *o, visi 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; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_3_kbest_tree(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); @@ -4255,11 +7467,11 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_1_kbest(PyObject *o) { return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_1_kbest[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_3_kbest_tree[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1_kbest = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_kbest_tree = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -4317,7 +7529,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1_kbest = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1_kbest = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -4330,13 +7542,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1_kbest = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1_kbest = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_3_kbest_tree = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1_kbest = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_kbest_tree = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -4357,12 +7569,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1_kbest = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1_kbest = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { 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*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_3_kbest_tree"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1_kbest, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -4372,24 +7584,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1_kbest = { 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*/ + &__pyx_tp_as_number___pyx_scope_struct_3_kbest_tree, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_3_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_1_kbest, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_3_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_1_kbest, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_1_kbest, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_3_kbest_tree, /*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*/ + __pyx_methods_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -4399,7 +7611,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1_kbest = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_1_kbest, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -4413,42 +7625,37 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1_kbest = { #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; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_4_sample(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest_tree *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *)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; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_sample(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); Py_XDECREF(((PyObject *)p->__pyx_v_sentence)); - Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest_tree(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_4_sample(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; + struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } if (p->__pyx_v_sentence) { e = (*v)(p->__pyx_v_sentence, a); if (e) return e; } - if (p->__pyx_v_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; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_4_sample(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); @@ -4456,17 +7663,14 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest_tree(PyObject *o) { 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[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_4_sample[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest_tree = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4_sample = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -4524,7 +7728,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest_tree = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest_tree = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4_sample = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -4537,13 +7741,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest_tree = 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_2_kbest_tree = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_4_sample = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest_tree = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4_sample = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -4564,12 +7768,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest_tree = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest_tree = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_sample = { 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*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_4_sample"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest_tree, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_sample, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -4579,24 +7783,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest_tree = { 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*/ + &__pyx_tp_as_number___pyx_scope_struct_4_sample, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_4_sample, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_4_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_2_kbest_tree, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_4_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_2_kbest_tree, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest_tree, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_4_sample, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_4_sample, /*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*/ + __pyx_methods_5_cdec___pyx_scope_struct_4_sample, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -4606,7 +7810,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest_tree = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest_tree, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_4_sample, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -4620,52 +7824,44 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest_tree = { #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; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_5___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_sample *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *)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; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(((PyObject *)p->__pyx_v_sentence)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_sample(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_5___iter__(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; + struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } - if (p->__pyx_v_sentence) { - e = (*v)(p->__pyx_v_sentence, a); if (e) return e; - } 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; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_5___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Lattice *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_3_sample[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_5___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_sample = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_5___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -4723,7 +7919,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_sample = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_sample = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_5___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -4736,13 +7932,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_sample = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_3_sample = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_5___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_sample = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_5___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -4763,12 +7959,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_sample = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_sample = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5___iter__ = { 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*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_5___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_sample, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -4778,24 +7974,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_sample = { 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*/ + &__pyx_tp_as_number___pyx_scope_struct_5___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_5___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_5___iter__, /*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*/ + &__pyx_tp_as_buffer___pyx_scope_struct_5___iter__, /*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*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_5___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_5___iter__, /*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*/ + __pyx_methods_5_cdec___pyx_scope_struct_5___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -4805,7 +8001,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_sample = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_3_sample, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_5___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -4838,22 +8034,37 @@ static struct PyModuleDef __pyx_moduledef = { #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0}, + {&__pyx_n_s_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 1, 1}, + {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0}, + {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0}, + {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0}, + {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0}, + {&__pyx_kp_s_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 1, 0}, {&__pyx_n_s__Exception, __pyx_k__Exception, sizeof(__pyx_k__Exception), 0, 0, 1, 1}, + {&__pyx_n_s__IndexError, __pyx_k__IndexError, sizeof(__pyx_k__IndexError), 0, 0, 1, 1}, {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1}, + {&__pyx_n_s__NotImplemented, __pyx_k__NotImplemented, sizeof(__pyx_k__NotImplemented), 0, 0, 1, 1}, {&__pyx_n_s__ParseFailed, __pyx_k__ParseFailed, sizeof(__pyx_k__ParseFailed), 0, 0, 1, 1}, + {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1}, + {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, {&__pyx_n_s____enter__, __pyx_k____enter__, sizeof(__pyx_k____enter__), 0, 0, 1, 1}, {&__pyx_n_s____exit__, __pyx_k____exit__, sizeof(__pyx_k____exit__), 0, 0, 1, 1}, {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, {&__pyx_n_s___cdec, __pyx_k___cdec, sizeof(__pyx_k___cdec), 0, 0, 1, 1}, + {&__pyx_n_s__beam_alpha, __pyx_k__beam_alpha, sizeof(__pyx_k__beam_alpha), 0, 0, 1, 1}, {&__pyx_n_s__config, __pyx_k__config, sizeof(__pyx_k__config), 0, 0, 1, 1}, {&__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__density, __pyx_k__density, sizeof(__pyx_k__density), 0, 0, 1, 1}, + {&__pyx_n_s__dot, __pyx_k__dot, sizeof(__pyx_k__dot), 0, 0, 1, 1}, {&__pyx_n_s__encode, __pyx_k__encode, sizeof(__pyx_k__encode), 0, 0, 1, 1}, + {&__pyx_n_s__enumerate, __pyx_k__enumerate, sizeof(__pyx_k__enumerate), 0, 0, 1, 1}, {&__pyx_n_s__eval, __pyx_k__eval, sizeof(__pyx_k__eval), 0, 0, 1, 1}, {&__pyx_n_s__grammar, __pyx_k__grammar, sizeof(__pyx_k__grammar), 0, 0, 1, 1}, + {&__pyx_n_s__inp, __pyx_k__inp, sizeof(__pyx_k__inp), 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__plf, __pyx_k__plf, sizeof(__pyx_k__plf), 0, 0, 1, 1}, {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1}, {&__pyx_n_s__self, __pyx_k__self, sizeof(__pyx_k__self), 0, 0, 1, 1}, {&__pyx_n_s__sentence, __pyx_k__sentence, sizeof(__pyx_k__sentence), 0, 0, 1, 1}, @@ -4864,122 +8075,225 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { }; 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 = 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 = 53; __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 = 151; __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[1]; __pyx_lineno = 10; __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[1]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_NotImplemented = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplemented); if (!__pyx_builtin_NotImplemented) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __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[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __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 = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; return -1; } static int __Pyx_InitCachedConstants(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - - /* "_cdec.pyx":53 - * - * def read_weights(self, cfg): - * with open(cfg) as fp: # <<<<<<<<<<<<<< - * for line in fp: - * fname, value = line.split() - */ - __pyx_k_tuple_1 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_1); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_1, 0, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_1, 1, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_1, 2, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_1)); - - /* "_cdec.pyx":62 - * if grammar: - * self.dec.SetSentenceGrammarFromString(string( grammar)) - * inp = sentence.strip().encode('utf8') # <<<<<<<<<<<<<< - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - * self.dec.Decode(string(inp), &observer) + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":69 + * elif op == 3: # != + * return not (self == other) + * raise NotImplemented('comparison not implemented for SparseVector') # <<<<<<<<<<<<<< + * + * def __len__(self): */ - __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_2); - __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2)); + __pyx_k_tuple_3 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_3); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_2)); + PyTuple_SET_ITEM(__pyx_k_tuple_3, 0, ((PyObject *)__pyx_kp_s_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_3)); - /* "_cdec.pyx":85 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":17 * hypergraph.ViterbiESentence(self.hg[0], &trans) * cdef str sentence = GetString(trans).c_str() * return sentence.decode('utf8') # <<<<<<<<<<<<<< * * def viterbi_tree(self): */ - __pyx_k_tuple_3 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_3); + __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_4); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_3, 0, ((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_3)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4)); - /* "_cdec.pyx":90 - * assert (self.hg != NULL) + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":21 + * def viterbi_tree(self): * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str() * return tree.decode('utf8') # <<<<<<<<<<<<<< * - * def kbest(self, size): + * def viterbi_source_tree(self): */ - __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_4); + __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_5); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5)); - /* "_cdec.pyx":102 - * if not derivation: break - * tree = GetString(derivation._yield).c_str() - * yield tree.decode('utf8') # <<<<<<<<<<<<<< - * del derivations + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":25 + * def viterbi_source_tree(self): + * cdef str tree = hypergraph.ViterbiFTree(self.hg[0]).c_str() + * return tree.decode('utf8') # <<<<<<<<<<<<<< * + * def viterbi_features(self): */ - __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_5); + __pyx_k_tuple_6 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_6); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_6, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_6)); - /* "_cdec.pyx":115 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":41 * if not derivation: break * sentence = GetString(derivation._yield).c_str() * yield sentence.decode('utf8') # <<<<<<<<<<<<<< * del derivations * */ - __pyx_k_tuple_6 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_6); + __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_7); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_6, 0, ((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_6)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_7)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":53 + * if not derivation: break + * tree = GetString(derivation._yield).c_str() + * yield tree.decode('utf8') # <<<<<<<<<<<<<< + * del derivations + * + */ + __pyx_k_tuple_8 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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":132 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":65 * for k in range(hypos.size()): * sentence = GetString(hypos[0][k].words).c_str() * yield sentence.decode('utf8') # <<<<<<<<<<<<<< * del hypos * */ - __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_7); + __pyx_k_tuple_9 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_9); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_7, 0, ((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_7)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_9)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":13 + * else: + * if isinstance(inp, unicode): + * inp = inp.encode('utf8') # <<<<<<<<<<<<<< + * if not isinstance(inp, str): + * raise TypeError('Cannot create lattice from %s' % type(inp)) + */ + __pyx_k_tuple_12 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":21 + * def __getitem__(self, int index): + * if not 0 <= index < len(self): + * raise IndexError('lattice index out of range') # <<<<<<<<<<<<<< + * arcs = [] + * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] + */ + __pyx_k_tuple_15 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_15)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_15); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_15, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_15)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":30 + * arc = &arc_vector[i] + * label = TDConvert(arc.label) + * arcs.append((label.decode('utf8'), arc.cost, arc.dist2next)) # <<<<<<<<<<<<<< + * return tuple(arcs) + * + */ + __pyx_k_tuple_16 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_16)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_16); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_16, 0, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_16)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":35 + * def __setitem__(self, int index, tuple arcs): + * if not 0 <= index < len(self): + * raise IndexError('lattice index out of range') # <<<<<<<<<<<<<< + * cdef lattice.LatticeArc* arc + * for (label, cost, dist2next) in arcs: + */ + __pyx_k_tuple_17 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_17)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_17); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_17, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_17)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":39 + * for (label, cost, dist2next) in arcs: + * if isinstance(label, unicode): + * label = label.encode('utf8') # <<<<<<<<<<<<<< + * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) + * self.lattice[0][index].push_back(arc[0]) + */ + __pyx_k_tuple_18 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_18)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_18); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_18, 0, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_18)); + + /* "_cdec.pyx":31 + * + * def read_weights(self, cfg): + * with open(cfg) as fp: # <<<<<<<<<<<<<< + * for line in fp: + * fname, value = line.split() + */ + __pyx_k_tuple_19 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_19); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_19, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_19, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_19, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_19)); + + /* "_cdec.pyx":38 + * def translate(self, sentence, grammar=None): + * if isinstance(sentence, unicode): + * inp = sentence.strip().encode('utf8') # <<<<<<<<<<<<<< + * elif isinstance(sentence, str): + * inp = sentence.strip() + */ + __pyx_k_tuple_20 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_20); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_20, 0, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20)); __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -4989,6 +8303,8 @@ static int __Pyx_InitCachedConstants(void) { static int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; return 0; __pyx_L1_error:; return -1; @@ -5061,255 +8377,127 @@ 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 = 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 = 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 = 71; __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 = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_DenseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "DenseVector", (PyObject *)&__pyx_type_5_cdec_DenseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_DenseVector = &__pyx_type_5_cdec_DenseVector; + if (PyType_Ready(&__pyx_type_5_cdec_SparseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "SparseVector", (PyObject *)&__pyx_type_5_cdec_SparseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_SparseVector = &__pyx_type_5_cdec_SparseVector; + if (PyType_Ready(&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Hypergraph", (PyObject *)&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Hypergraph = &__pyx_type_5_cdec_Hypergraph; - if (PyType_Ready(&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __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 = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Lattice", (PyObject *)&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Lattice = &__pyx_type_5_cdec_Lattice; - 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;} + if (PyType_Ready(&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __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 = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_Decoder = &__pyx_type_5_cdec_Decoder; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct____iter__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct____iter__ = &__pyx_type_5_cdec___pyx_scope_struct____iter__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_1_kbest) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __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; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_2_kbest_tree) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __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; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_3_sample) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __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; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_1___iter__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_1___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_1___iter__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_2_kbest) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_2_kbest = &__pyx_type_5_cdec___pyx_scope_struct_2_kbest; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_tree = &__pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_4_sample) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_4_sample = &__pyx_type_5_cdec___pyx_scope_struct_4_sample; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_5___iter__) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_5___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_5___iter__; /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ /*--- Execution code ---*/ /* "_cdec.pyx":10 - * cimport kbest as kb + * include "lattice.pxi" * * SetSilent(True) # <<<<<<<<<<<<<< - * - * class ParseFailed(Exception): - */ - SetSilent(1); - - /* "_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 = 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 = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__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 = 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 = 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":1 - * from libcpp.string cimport string # <<<<<<<<<<<<<< - * from libcpp.vector cimport vector - * from cython.operator cimport dereference as deref - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - if (__pyx_m) { - __Pyx_AddTraceback("init _cdec", __pyx_clineno, __pyx_lineno, __pyx_filename); - Py_DECREF(__pyx_m); __pyx_m = 0; - } else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_ImportError, "init _cdec"); - } - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - #if PY_MAJOR_VERSION < 3 - return; - #else - return __pyx_m; - #endif -} - -/* Runtime support code */ -#if CYTHON_REFNANNY -static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { - PyObject *m = NULL, *p = NULL; - void *r = NULL; - m = PyImport_ImportModule((char *)modname); - if (!m) goto end; - p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); - if (!p) goto end; - r = PyLong_AsVoidPtr(p); -end: - Py_XDECREF(p); - Py_XDECREF(m); - return (__Pyx_RefNannyAPIStruct *)r; -} -#endif /* CYTHON_REFNANNY */ - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { - PyObject *result; - result = PyObject_GetAttr(dict, name); - if (!result) { - if (dict != __pyx_b) { - PyErr_Clear(); - result = PyObject_GetAttr(__pyx_b, name); - } - if (!result) { - PyErr_SetObject(PyExc_NameError, name); - } - } - return result; -} - -static void __Pyx_RaiseDoubleKeywordsError( - const char* func_name, - PyObject* kw_name) -{ - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION >= 3 - "%s() got multiple values for keyword argument '%U'", func_name, kw_name); - #else - "%s() got multiple values for keyword argument '%s'", func_name, - PyString_AS_STRING(kw_name)); - #endif -} - -static int __Pyx_ParseOptionalKeywords( - PyObject *kwds, - PyObject **argnames[], - PyObject *kwds2, - PyObject *values[], - Py_ssize_t num_pos_args, - const char* function_name) -{ - PyObject *key = 0, *value = 0; - Py_ssize_t pos = 0; - PyObject*** name; - PyObject*** first_kw_arg = argnames + num_pos_args; - while (PyDict_Next(kwds, &pos, &key, &value)) { - name = first_kw_arg; - while (*name && (**name != key)) name++; - if (*name) { - values[name-argnames] = value; - } else { - #if PY_MAJOR_VERSION < 3 - if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) { - #else - if (unlikely(!PyUnicode_Check(key))) { - #endif - goto invalid_keyword_type; - } else { - for (name = first_kw_arg; *name; name++) { - #if PY_MAJOR_VERSION >= 3 - if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && - PyUnicode_Compare(**name, key) == 0) break; - #else - if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && - _PyString_Eq(**name, key)) break; - #endif - } - if (*name) { - values[name-argnames] = value; - } else { - for (name=argnames; name != first_kw_arg; name++) { - if (**name == key) goto arg_passed_twice; - #if PY_MAJOR_VERSION >= 3 - if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && - PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice; - #else - if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && - _PyString_Eq(**name, key)) goto arg_passed_twice; - #endif - } - if (kwds2) { - if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; - } else { - goto invalid_keyword; - } - } - } - } - } - return 0; -arg_passed_twice: - __Pyx_RaiseDoubleKeywordsError(function_name, **name); - goto bad; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%s() keywords must be strings", function_name); - goto bad; -invalid_keyword: - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION < 3 - "%s() got an unexpected keyword argument '%s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); - #endif -bad: - return -1; + * + * class ParseFailed(Exception): + */ + SetSilent(1); + + /* "_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 = 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 = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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 = 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 = 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":1 + * from libcpp.string cimport string # <<<<<<<<<<<<<< + * from libcpp.vector cimport vector + * from utils cimport * + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + if (__pyx_m) { + __Pyx_AddTraceback("init _cdec", __pyx_clineno, __pyx_lineno, __pyx_filename); + Py_DECREF(__pyx_m); __pyx_m = 0; + } else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "init _cdec"); + } + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + #if PY_MAJOR_VERSION < 3 + return; + #else + return __pyx_m; + #endif } -static void __Pyx_RaiseArgtupleInvalid( - const char* func_name, - int exact, - Py_ssize_t num_min, - Py_ssize_t num_max, - Py_ssize_t num_found) -{ - Py_ssize_t num_expected; - const char *more_or_less; - if (num_found < num_min) { - num_expected = num_min; - more_or_less = "at least"; - } else { - num_expected = num_max; - more_or_less = "at most"; - } - if (exact) { - more_or_less = "exactly"; - } - PyErr_Format(PyExc_TypeError, - "%s() takes %s %"PY_FORMAT_SIZE_T"d positional argument%s (%"PY_FORMAT_SIZE_T"d given)", - func_name, more_or_less, num_expected, - (num_expected == 1) ? "" : "s", num_found); +/* Runtime support code */ +#if CYTHON_REFNANNY +static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { + PyObject *m = NULL, *p = NULL; + void *r = NULL; + m = PyImport_ImportModule((char *)modname); + if (!m) goto end; + p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); + if (!p) goto end; + r = PyLong_AsVoidPtr(p); +end: + Py_XDECREF(p); + Py_XDECREF(m); + return (__Pyx_RefNannyAPIStruct *)r; } +#endif /* CYTHON_REFNANNY */ -static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, - const char *name, int exact) -{ - if (!type) { - PyErr_Format(PyExc_SystemError, "Missing type object"); - return 0; - } - if (none_allowed && obj == Py_None) return 1; - else if (exact) { - if (Py_TYPE(obj) == type) return 1; - } - else { - if (PyObject_TypeCheck(obj, type)) return 1; +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { + PyObject *result; + result = PyObject_GetAttr(dict, name); + if (!result) { + if (dict != __pyx_b) { + PyErr_Clear(); + result = PyObject_GetAttr(__pyx_b, name); + } + if (!result) { + PyErr_SetObject(PyExc_NameError, name); + } } - PyErr_Format(PyExc_TypeError, - "Argument '%s' has incorrect type (expected %s, got %s)", - name, type->tp_name, Py_TYPE(obj)->tp_name); - return 0; + return result; } static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { @@ -5465,6 +8653,141 @@ bad: } #endif +static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, + const char *name, int exact) +{ + if (!type) { + PyErr_Format(PyExc_SystemError, "Missing type object"); + return 0; + } + if (none_allowed && obj == Py_None) return 1; + else if (exact) { + if (Py_TYPE(obj) == type) return 1; + } + else { + if (PyObject_TypeCheck(obj, type)) return 1; + } + PyErr_Format(PyExc_TypeError, + "Argument '%s' has incorrect type (expected %s, got %s)", + name, type->tp_name, Py_TYPE(obj)->tp_name); + return 0; +} + +static void __Pyx_RaiseDoubleKeywordsError( + const char* func_name, + PyObject* kw_name) +{ + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION >= 3 + "%s() got multiple values for keyword argument '%U'", func_name, kw_name); + #else + "%s() got multiple values for keyword argument '%s'", func_name, + PyString_AS_STRING(kw_name)); + #endif +} + +static int __Pyx_ParseOptionalKeywords( + PyObject *kwds, + PyObject **argnames[], + PyObject *kwds2, + PyObject *values[], + Py_ssize_t num_pos_args, + const char* function_name) +{ + PyObject *key = 0, *value = 0; + Py_ssize_t pos = 0; + PyObject*** name; + PyObject*** first_kw_arg = argnames + num_pos_args; + while (PyDict_Next(kwds, &pos, &key, &value)) { + name = first_kw_arg; + while (*name && (**name != key)) name++; + if (*name) { + values[name-argnames] = value; + } else { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) { + #else + if (unlikely(!PyUnicode_Check(key))) { + #endif + goto invalid_keyword_type; + } else { + for (name = first_kw_arg; *name; name++) { + #if PY_MAJOR_VERSION >= 3 + if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && + PyUnicode_Compare(**name, key) == 0) break; + #else + if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && + _PyString_Eq(**name, key)) break; + #endif + } + if (*name) { + values[name-argnames] = value; + } else { + for (name=argnames; name != first_kw_arg; name++) { + if (**name == key) goto arg_passed_twice; + #if PY_MAJOR_VERSION >= 3 + if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && + PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice; + #else + if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && + _PyString_Eq(**name, key)) goto arg_passed_twice; + #endif + } + if (kwds2) { + if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; + } else { + goto invalid_keyword; + } + } + } + } + } + return 0; +arg_passed_twice: + __Pyx_RaiseDoubleKeywordsError(function_name, **name); + goto bad; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%s() keywords must be strings", function_name); + goto bad; +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%s() got an unexpected keyword argument '%s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif +bad: + return -1; +} + +static void __Pyx_RaiseArgtupleInvalid( + const char* func_name, + int exact, + Py_ssize_t num_min, + Py_ssize_t num_max, + Py_ssize_t num_found) +{ + Py_ssize_t num_expected; + const char *more_or_less; + if (num_found < num_min) { + num_expected = num_min; + more_or_less = "at least"; + } else { + num_expected = num_max; + more_or_less = "at most"; + } + if (exact) { + more_or_less = "exactly"; + } + PyErr_Format(PyExc_TypeError, + "%s() takes %s %"PY_FORMAT_SIZE_T"d positional argument%s (%"PY_FORMAT_SIZE_T"d given)", + func_name, more_or_less, num_expected, + (num_expected == 1) ? "" : "s", num_found); +} + static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { PyErr_Format(PyExc_ValueError, "need more than %"PY_FORMAT_SIZE_T"d value%s to unpack", @@ -5492,6 +8815,8 @@ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { return 0; } + + static double __Pyx__PyObject_AsDouble(PyObject* obj) { PyObject* float_value; if (Py_TYPE(obj)->tp_as_number && Py_TYPE(obj)->tp_as_number->nb_float) { diff --git a/python/src/_cdec.pyx b/python/src/_cdec.pyx index 664724dd..698a66f6 100644 --- a/python/src/_cdec.pyx +++ b/python/src/_cdec.pyx @@ -1,50 +1,28 @@ 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 + +include "vectors.pxi" +include "hypergraph.pxi" +include "lattice.pxi" SetSilent(True) class ParseFailed(Exception): pass -cdef class Weights: - cdef vector[weight_t]* weights - - def __cinit__(self, Decoder decoder): - self.weights = &decoder.dec.CurrentWeightVector() - - def __getitem__(self, char* 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 = FDConvert(fname) - if self.weights.size() <= fid: - self.weights.resize(fid + 1) - self.weights[0][fid] = value - - def __iter__(self): - cdef unsigned fid - for fid in range(1, self.weights.size()): - yield FDConvert(fid).c_str(), self.weights[0][fid] - cdef class Decoder: cdef decoder.Decoder* dec - cdef public Weights weights + cdef public DenseVector weights def __cinit__(self, char* config): decoder.register_feature_functions() cdef istringstream* config_stream = new istringstream(config) self.dec = new decoder.Decoder(config_stream) del config_stream - self.weights = Weights(self) + self.weights = DenseVector() + self.weights.vector = &self.dec.CurrentWeightVector() def __dealloc__(self): del self.dec @@ -55,11 +33,17 @@ cdef class Decoder: fname, value = line.split() self.weights[fname.strip()] = float(value) - # TODO: list, lattice translation - def translate(self, unicode sentence, grammar=None): + def translate(self, sentence, grammar=None): + if isinstance(sentence, unicode): + inp = sentence.strip().encode('utf8') + elif isinstance(sentence, str): + inp = sentence.strip() + elif isinstance(sentence, Lattice): + inp = str(sentence) # PLF format + else: + raise TypeError('Cannot translate input type %s' % type(sentence)) if grammar: self.dec.SetSentenceGrammarFromString(string( grammar)) - inp = sentence.strip().encode('utf8') cdef decoder.BasicObserver observer = decoder.BasicObserver() self.dec.Decode(string(inp), &observer) if observer.hypergraph == NULL: @@ -67,90 +51,3 @@ cdef class Decoder: cdef Hypergraph hg = Hypergraph() hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) return hg - -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) - cdef vector[WordID] trans - hypergraph.ViterbiESentence(self.hg[0], &trans) - 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(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 diff --git a/python/src/decoder.pxd b/python/src/decoder.pxd index ab858841..e2678151 100644 --- a/python/src/decoder.pxd +++ b/python/src/decoder.pxd @@ -4,7 +4,7 @@ from hypergraph cimport Hypergraph from utils cimport istream, weight_t cdef extern from "decoder/ff_register.h": - cdef void register_feature_functions() + void register_feature_functions() cdef extern from "decoder/decoder.h": cdef cppclass SentenceMetadata: @@ -16,20 +16,20 @@ cdef extern from "decoder/decoder.h": cdef cppclass Decoder: Decoder(int argc, char** argv) Decoder(istream* config_file) - bint Decode(string input, DecoderObserver* observer) + bint Decode(string& inp, DecoderObserver* observer) # access this to either *read* or *write* to the decoder's last # weight vector (i.e., the weights of the finest past) vector[weight_t]& CurrentWeightVector() - void SetId(int id) - #const boost::program_options::variables_map& GetConf() const { return conf } + # void SetId(int id) + # const boost::program_options::variables_map& GetConf() const { return conf } # add grammar rules (currently only supported by SCFG decoders) # that will be used on subsequent calls to Decode. rules should be in standard # text format. This function does NOT read from a file. - void SetSupplementalGrammar(string grammar) - void SetSentenceGrammarFromString(string grammar_str) + void SetSupplementalGrammar(string& grammar) + void SetSentenceGrammarFromString(string& grammar_str) cdef extern from "observer.h": cdef cppclass BasicObserver(DecoderObserver): diff --git a/python/src/hypergraph.pxd b/python/src/hypergraph.pxd index 4aef6955..656b1d47 100644 --- a/python/src/hypergraph.pxd +++ b/python/src/hypergraph.pxd @@ -1,41 +1,73 @@ from libcpp.string cimport string from libcpp.vector cimport vector from utils cimport * -cimport lattice +from lattice cimport Lattice cdef extern from "decoder/hg.h": + cdef cppclass EdgeMask "std::vector": + EdgeMask(int size) + bint& operator[](int) + cdef cppclass Hypergraph: + cppclass Edge: + int id_ + int head_node_ # position in hg.nodes_ + SmallVector[unsigned] tail_nodes_ # positions in hg.nodes_ + #TRulePtr rule_ + FastSparseVector[weight_t] feature_values_ + LogVal[double] edge_prob_ + short int i_ + short int j_ + short int prev_i_ + short int prev_j_ cppclass Node: int id_ WordID cat_ WordID NT() - #EdgesVector in_edges_ - #EdgesVector out_edges_ + vector[Edge] in_edges_ + vector[Edge] out_edges_ Hypergraph(Hypergraph) vector[Node] nodes_ + vector[Edge] edges_ + void Reweight(vector[weight_t]& weights) + void Reweight(FastSparseVector& weights) + bint PruneInsideOutside(double beam_alpha, + double density, + EdgeMask* preserve_mask, + bint use_sum_prod_semiring, + double scale, + bint safe_inside) cdef extern from "decoder/viterbi.h": - cdef prob_t ViterbiESentence(Hypergraph hg, vector[WordID]* trans) - cdef string ViterbiETree(Hypergraph hg) + LogVal[double] ViterbiESentence(Hypergraph& hg, vector[WordID]* trans) + string ViterbiETree(Hypergraph& hg) + LogVal[double] ViterbiFSentence(Hypergraph& hg, vector[WordID]* trans) + string ViterbiFTree(Hypergraph& hg) + FastSparseVector[weight_t] ViterbiFeatures(Hypergraph& hg) + FastSparseVector[weight_t] ViterbiFeatures(Hypergraph& hg, + FastSparseVector[weight_t]* weights, + bint fatal_dotprod_disagreement) 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) + bint WriteToJSON(Hypergraph& hg, bint remove_rules, ostream* out) + void ReadFromPLF(string& inp, Hypergraph* out, int line) + string AsPLF(Hypergraph& hg, bint include_global_parentheses) + void PLFtoLattice(string& plf, Lattice* pl) + string AsPLF(Lattice& lat, bint include_global_parentheses) cdef extern from "decoder/hg_intersect.h" namespace "HG": - bint Intersect(lattice.Lattice target, Hypergraph* hg) + bint Intersect(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) + FastSparseVector[double] fmap + LogVal[double] model_score + void sample_hypotheses(Hypergraph& hg, + unsigned n, + MT19937* rng, + vector[Hypothesis]* hypos) + +cdef extern from "decoder/csplit.h" namespace "CompoundSplit": + int GetFullWordEdgeIndex(Hypergraph& forest) diff --git a/python/src/hypergraph.pxi b/python/src/hypergraph.pxi new file mode 100644 index 00000000..c226d105 --- /dev/null +++ b/python/src/hypergraph.pxi @@ -0,0 +1,92 @@ +cimport hypergraph +cimport kbest as kb + +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): + cdef vector[WordID] trans + hypergraph.ViterbiESentence(self.hg[0], &trans) + cdef str sentence = GetString(trans).c_str() + return sentence.decode('utf8') + + def viterbi_tree(self): + cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str() + return tree.decode('utf8') + + def viterbi_source_tree(self): + cdef str tree = hypergraph.ViterbiFTree(self.hg[0]).c_str() + return tree.decode('utf8') + + def viterbi_features(self): + cdef SparseVector fmap = SparseVector() + fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) + return fmap + + def kbest(self, size): + 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 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 kbest_tree(self, size): + 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 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 sample(self, unsigned n): + 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 richer k-best/sample output (feature vectors, trees?) + + def intersect(self, Lattice lat): + return hypergraph.Intersect(lat.lattice[0], self.hg) + + def prune(self, beam_alpha=0, density=0, **kwargs): + cdef hypergraph.EdgeMask* preserve_mask = NULL + if 'csplit_preserve_full_word' in kwargs: + preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) + preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True + self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) + + def lattice(self): # TODO direct hg -> lattice conversion in cdec + cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() + return Lattice(eval(plf)) + + def reweight(self, weights): + if isinstance(weights, SparseVector): + self.hg.Reweight(( weights).vector[0]) + elif isinstance(weights, DenseVector): + self.hg.Reweight(( weights).vector[0]) + else: + raise ValueError('cannot reweight hypergraph with %s' % type(weights)) + + # TODO get feature expectations, get partition function ("inside" score) diff --git a/python/src/kbest.pxd b/python/src/kbest.pxd index e339714a..f34ac5ed 100644 --- a/python/src/kbest.pxd +++ b/python/src/kbest.pxd @@ -1,16 +1,18 @@ from libcpp.vector cimport vector from utils cimport WordID -cimport hypergraph +from hypergraph cimport Hypergraph cdef extern from "decoder/viterbi.h": cdef cppclass ESentenceTraversal: pass cdef cppclass ETreeTraversal: pass + cdef cppclass FTreeTraversal: + 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) + KBestDerivations(Hypergraph& hg, unsigned k) Derivation* LazyKthBest(unsigned v, unsigned k) diff --git a/python/src/lattice.pxd b/python/src/lattice.pxd index bdfaba80..3a4bc22f 100644 --- a/python/src/lattice.pxd +++ b/python/src/lattice.pxd @@ -1,4 +1,5 @@ from libcpp.vector cimport vector +from libcpp.string cimport string from utils cimport WordID cdef extern from "decoder/lattice.h": @@ -9,8 +10,12 @@ cdef extern from "decoder/lattice.h": LatticeArc() LatticeArc(WordID w, double c, int i) - cdef cppclass Lattice: # (vector[vector[LatticeArc]]) + cdef cppclass Lattice(vector): # (vector[vector[LatticeArc]]) Lattice() Lattice(unsigned t) - Lattice(unsigned t, vector[LatticeArc] v) + Lattice(unsigned t, vector[LatticeArc]& v) bint IsSentence() + vector[LatticeArc]& operator[](unsigned) + +cdef extern from "decoder/lattice.h" namespace "LatticeTools": + void ConvertTextToLattice(string& text, Lattice* pl) diff --git a/python/src/lattice.pxi b/python/src/lattice.pxi new file mode 100644 index 00000000..493c6dcd --- /dev/null +++ b/python/src/lattice.pxi @@ -0,0 +1,56 @@ +cimport lattice + +cdef class Lattice: + cdef lattice.Lattice* lattice + + def __init__(self, inp): + if isinstance(inp, tuple): + self.lattice = new lattice.Lattice(len(inp)) + for i, arcs in enumerate(inp): + self[i] = arcs + else: + if isinstance(inp, unicode): + inp = inp.encode('utf8') + if not isinstance(inp, str): + raise TypeError('Cannot create lattice from %s' % type(inp)) + self.lattice = new lattice.Lattice() + lattice.ConvertTextToLattice(string(inp), self.lattice) + + def __getitem__(self, int index): + if not 0 <= index < len(self): + raise IndexError('lattice index out of range') + arcs = [] + cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] + cdef lattice.LatticeArc* arc + cdef str label + cdef unsigned i + for i in range(arc_vector.size()): + arc = &arc_vector[i] + label = TDConvert(arc.label) + arcs.append((label.decode('utf8'), arc.cost, arc.dist2next)) + return tuple(arcs) + + def __setitem__(self, int index, tuple arcs): + if not 0 <= index < len(self): + raise IndexError('lattice index out of range') + cdef lattice.LatticeArc* arc + for (label, cost, dist2next) in arcs: + if isinstance(label, unicode): + label = label.encode('utf8') + arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) + self.lattice[0][index].push_back(arc[0]) + del arc + + def __len__(self): + return self.lattice.size() + + def __str__(self): + return hypergraph.AsPLF(self.lattice[0], True).c_str() + + def __iter__(self): + cdef unsigned i + for i in range(len(self)): + yield self[i] + + def __dealloc__(self): + del self.lattice diff --git a/python/src/utils.pxd b/python/src/utils.pxd index 786cd265..3d518524 100644 --- a/python/src/utils.pxd +++ b/python/src/utils.pxd @@ -1,5 +1,6 @@ from libcpp.string cimport string from libcpp.vector cimport vector +from libcpp.pair cimport pair cdef extern from "" namespace "std": cdef cppclass istream: @@ -8,30 +9,60 @@ cdef extern from "" namespace "std": pass cdef cppclass istringstream(istream): istringstream(char*) + ostream cout cdef extern from "utils/weights.h": ctypedef double weight_t cdef extern from "utils/logval.h": cdef cppclass LogVal[T]: - pass + double as_float() -cdef extern from "utils/prob.h": - cdef cppclass prob_t: - pass + double log(LogVal[double]&) cdef extern from "utils/wordid.h": ctypedef int WordID -cdef extern from "utils/sparse_vector.h": - cdef cppclass SparseVector[T]: +cdef extern from "utils/small_vector.h": + cdef cppclass SmallVector[T]: pass +cdef extern from "utils/sparse_vector.h": + cdef cppclass FastSparseVector[T]: + cppclass const_iterator: + const_iterator(FastSparseVector[T]&, bint is_end) + pair[unsigned, T]* ptr "operator->" () + const_iterator& operator++() + bint operator==(const_iterator&) + bint operator!=(const_iterator&) + FastSparseVector() + FastSparseVector(FastSparseVector[T]&) + const_iterator begin() + const_iterator end() + void init_vector(vector[T]* vp) + T value(unsigned k) + void set_value(unsigned k, T& v) + size_t size() + bint nonzero(unsigned k) + bint operator==(FastSparseVector[T]&) + T dot(vector[weight_t]&) # cython bug when [T] + T dot(FastSparseVector[T]&) + + FastSparseVector[weight_t] operator+(FastSparseVector[weight_t]&, FastSparseVector[weight_t]&) + FastSparseVector[weight_t] operator-(FastSparseVector[weight_t]&, FastSparseVector[weight_t]&) + ostream operator<<(ostream& out, FastSparseVector[weight_t]& v) + +cdef extern from "utils/weights.h" namespace "Weights": + void InitSparseVector(vector[weight_t]& dv, FastSparseVector[weight_t]* sv) + cdef extern from "utils/tdict.cc" namespace "TD": - cdef string GetString(vector[WordID] st) + string GetString(vector[WordID]& st) + unsigned NumWords() + WordID TDConvert "TD::Convert" (char*) + char* TDConvert "TD::Convert" (WordID) cdef extern from "utils/verbose.h": - cdef void SetSilent(bint) + void SetSilent(bint) cdef extern from "utils/fdict.h" namespace "FD": WordID FDConvert "FD::Convert" (char*) @@ -39,15 +70,9 @@ cdef extern from "utils/fdict.h" namespace "FD": cdef extern from "utils/filelib.h": cdef cppclass ReadFile: - ReadFile(string) + ReadFile(string&) istream* stream() cdef extern from "utils/sampler.h": cdef cppclass MT19937: pass - -""" -cdef extern from "" namespace "boost": - cdef cppclass shared_ptr[T]: - void reset(T*) -""" diff --git a/python/src/vectors.pxi b/python/src/vectors.pxi new file mode 100644 index 00000000..74d3a0bd --- /dev/null +++ b/python/src/vectors.pxi @@ -0,0 +1,101 @@ +from cython.operator cimport preincrement as pinc + +cdef class DenseVector: + cdef vector[weight_t]* vector + + def __getitem__(self, char* fname): + cdef unsigned fid = FDConvert(fname) + if fid <= self.vector.size(): + return self.vector[0][fid] + raise KeyError(fname) + + def __setitem__(self, char* fname, float value): + cdef unsigned fid = FDConvert(fname) + if self.vector.size() <= fid: + self.vector.resize(fid + 1) + self.vector[0][fid] = value + + def __iter__(self): + cdef unsigned fid + for fid in range(1, self.vector.size()): + yield FDConvert(fid).c_str(), self.vector[0][fid] + + def dot(self, SparseVector other): + return other.dot(self) + + def tosparse(self): + cdef SparseVector sparse = SparseVector() + sparse.vector = new FastSparseVector[weight_t]() + InitSparseVector(self.vector[0], sparse.vector) + return sparse + +cdef class SparseVector: + cdef FastSparseVector[weight_t]* vector + + def __getitem__(self, char* fname): + cdef unsigned fid = FDConvert(fname) + return self.vector.value(fid) + + def __setitem__(self, char* fname, float value): + cdef unsigned fid = FDConvert(fname) + self.vector.set_value(fid, value) + + def __iter__(self): + cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) + cdef str fname + for i in range(self.vector.size()): + fname = FDConvert(it[0].ptr().first).c_str() + yield (fname, it[0].ptr().second) + pinc(it[0]) + + def dot(self, other): + if isinstance(other, DenseVector): + return self.vector.dot(( other).vector[0]) + elif isinstance(other, SparseVector): + return self.vector.dot(( other).vector[0]) + raise ValueError('cannot take the dot product of %s and SparseVector' % type(other)) + + def todense(self): + cdef DenseVector dense = DenseVector() + dense.vector = new vector[weight_t]() + self.vector.init_vector(dense.vector) + return dense + + def __richcmp__(SparseVector self, SparseVector other, int op): + if op == 2: # == + return self.vector[0] == other.vector[0] + elif op == 3: # != + return not (self == other) + raise NotImplemented('comparison not implemented for SparseVector') + + def __len__(self): + return self.vector.size() + + def __contains__(self, char* fname): + return self.vector.nonzero(FDConvert(fname)) + + def __iadd__(SparseVector self, SparseVector other): + self.vector[0] += other.vector[0] + return self + + def __isub__(SparseVector self, SparseVector other): + self.vector[0] -= other.vector[0] + return self + + def __imul__(SparseVector self, float scalar): + self.vector[0] *= scalar + return self + + def __idiv__(SparseVector self, float scalar): + self.vector[0] /= scalar + return self + + def __add__(SparseVector self, SparseVector other): + cdef SparseVector result = SparseVector() + result.vector = new FastSparseVector[weight_t](self.vector[0] + other.vector[0]) + return result + + def __sub__(SparseVector self, SparseVector other): + cdef SparseVector result = SparseVector() + result.vector = new FastSparseVector[weight_t](self.vector[0] - other.vector[0]) + return result -- cgit v1.2.3 From dc9e428224d95adf63da6460a2031348de295ca1 Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Sun, 1 Jul 2012 00:38:30 -0400 Subject: [python] MT evaluation --- python/cdec/__init__.py | 1 + python/cdec/score.py | 1 + python/setup.py | 7 +- python/src/_cdec.cpp | 6817 +++++++++++++++++++++++++++++++++++---------- python/src/_cdec.pyx | 4 +- python/src/hypergraph.pxi | 15 +- python/src/kbest.pxd | 2 + python/src/mteval.pxd | 47 + python/src/mteval.pxi | 116 + python/src/utils.pxd | 10 +- python/src/vectors.pxi | 34 +- python/test.py | 4 +- 12 files changed, 5501 insertions(+), 1557 deletions(-) create mode 100644 python/cdec/score.py create mode 100644 python/src/mteval.pxd create mode 100644 python/src/mteval.pxi (limited to 'python/src') diff --git a/python/cdec/__init__.py b/python/cdec/__init__.py index eda81194..0d7b8782 100644 --- a/python/cdec/__init__.py +++ b/python/cdec/__init__.py @@ -1 +1,2 @@ from _cdec import Decoder, Lattice +import score diff --git a/python/cdec/score.py b/python/cdec/score.py new file mode 100644 index 00000000..c107446f --- /dev/null +++ b/python/cdec/score.py @@ -0,0 +1 @@ +from _cdec import BLEU, TER diff --git a/python/setup.py b/python/setup.py index 49a1ec8f..cc8b289d 100644 --- a/python/setup.py +++ b/python/setup.py @@ -3,8 +3,8 @@ from distutils.extension import Extension from Cython.Distutils import build_ext import os -INC = ['..', 'src/', '../decoder', '../utils'] -LIB = ['../decoder', '../utils', '../mteval', '../klm/lm', '../klm/util'] +INC = ['..', 'src/', '../decoder', '../utils', '../mteval'] +LIB = ['../decoder', '../utils', '../mteval', '../training', '../klm/lm', '../klm/util'] BOOST_ROOT = os.getenv('BOOST_ROOT') if BOOST_ROOT: @@ -18,7 +18,8 @@ ext_modules = [ include_dirs=INC, library_dirs=LIB, libraries=['boost_program_options-mt', 'z', - 'cdec', 'utils', 'mteval', 'klm', 'klm_util']) + 'cdec', 'utils', 'mteval', 'training', 'klm', 'klm_util'], + extra_compile_args=['-DHAVE_CONFIG_H']), ] setup( diff --git a/python/src/_cdec.cpp b/python/src/_cdec.cpp index 0b9b9911..7d45e27f 100644 --- a/python/src/_cdec.cpp +++ b/python/src/_cdec.cpp @@ -1,4 +1,4 @@ -/* Generated by Cython 0.16 on Sat Jun 23 11:57:21 2012 */ +/* Generated by Cython 0.16 on Sun Jul 1 00:36:19 2012 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -279,11 +279,12 @@ #include "utils/wordid.h" #include "utils/small_vector.h" #include "utils/sparse_vector.h" -#include "utils/tdict.cc" +#include "utils/tdict.h" #include "utils/verbose.h" #include "utils/fdict.h" #include "utils/filelib.h" #include "utils/sampler.h" +#include #include "decoder/lattice.h" #include "decoder/hg.h" #include "decoder/viterbi.h" @@ -295,6 +296,8 @@ #include "decoder/decoder.h" #include "observer.h" #include "decoder/kbest.h" +#include "mteval/ns.h" +#include "training/candidate_set.h" #ifdef _OPENMP #include #endif /* _OPENMP */ @@ -381,37 +384,66 @@ static const char *__pyx_f[] = { "vectors.pxi", "hypergraph.pxi", "lattice.pxi", + "mteval.pxi", }; /*--- Type declarations ---*/ -struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample; +struct __pyx_obj_5_cdec_Scorer; +struct __pyx_obj_5_cdec_SufficientStats; struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__; +struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features; struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree; struct __pyx_obj_5_cdec_Decoder; +struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set; +struct __pyx_obj_5_cdec_SegmentEvaluator; struct __pyx_obj_5_cdec_SparseVector; struct __pyx_obj_5_cdec_Hypergraph; struct __pyx_obj_5_cdec_Lattice; -struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__; struct __pyx_obj_5_cdec___pyx_scope_struct____iter__; struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest; +struct __pyx_obj_5_cdec_Candidate; +struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample; struct __pyx_obj_5_cdec_DenseVector; +struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__; +struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__; +struct __pyx_opt_args_5_cdec_as_str; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":3 + * cimport mteval + * + * cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): # <<<<<<<<<<<<<< + * cdef bytes ret + * if isinstance(sentence, unicode): + */ +struct __pyx_opt_args_5_cdec_as_str { + int __pyx_n; + PyObject *error_msg; +}; + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":87 + * del cs + * + * cdef class Scorer: # <<<<<<<<<<<<<< + * cdef string* name * - * def sample(self, unsigned n): # <<<<<<<<<<<<<< - * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() - * if self.rng == NULL: */ -struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample { +struct __pyx_obj_5_cdec_Scorer { PyObject_HEAD - std::vector *__pyx_v_hypos; - unsigned int __pyx_v_k; - unsigned int __pyx_v_n; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; - PyObject *__pyx_v_sentence; - size_t __pyx_t_0; - unsigned int __pyx_t_1; + std::string *name; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":27 + * return fmap + * + * cdef class SufficientStats: # <<<<<<<<<<<<<< + * cdef mteval.SufficientStats* stats + * cdef mteval.EvaluationMetric* metric + */ +struct __pyx_obj_5_cdec_SufficientStats { + PyObject_HEAD + SufficientStats *stats; + EvaluationMetric *metric; }; @@ -433,6 +465,26 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ { }; +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 + * del derivations + * + * def kbest_features(self, size): # <<<<<<<<<<<<<< + * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) + * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal].Derivation* derivation + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features { + PyObject_HEAD + KBest::KBestDerivations,FeatureVectorTraversal>::Derivation *__pyx_v_derivation; + KBest::KBestDerivations,FeatureVectorTraversal> *__pyx_v_derivations; + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap; + unsigned int __pyx_v_k; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; + PyObject *__pyx_v_size; + unsigned int __pyx_t_0; + long __pyx_t_1; +}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":44 * del derivations * @@ -454,7 +506,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree { /* "_cdec.pyx":15 - * pass + * class ParseFailed(Exception): pass * * cdef class Decoder: # <<<<<<<<<<<<<< * cdef decoder.Decoder* dec @@ -467,6 +519,40 @@ struct __pyx_obj_5_cdec_Decoder { }; +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":75 + * return sf + * + * def candidate_set(self, Hypergraph hypergraph, unsigned k): # <<<<<<<<<<<<<< + * cdef mteval.CandidateSet* cs = new mteval.CandidateSet() + * cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set { + PyObject_HEAD + struct __pyx_obj_5_cdec_Candidate *__pyx_v_candidate; + training::CandidateSet *__pyx_v_cs; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph; + unsigned int __pyx_v_i; + unsigned int __pyx_v_k; + struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self; + unsigned int __pyx_t_0; + unsigned int __pyx_t_1; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":59 + * return result + * + * cdef class SegmentEvaluator: # <<<<<<<<<<<<<< + * cdef shared_ptr[mteval.SegmentEvaluator]* scorer + * cdef mteval.EvaluationMetric* metric + */ +struct __pyx_obj_5_cdec_SegmentEvaluator { + PyObject_HEAD + boost::shared_ptr *scorer; + EvaluationMetric *metric; +}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":32 * return sparse * @@ -507,22 +593,6 @@ struct __pyx_obj_5_cdec_Lattice { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":50 - * return hypergraph.AsPLF(self.lattice[0], True).c_str() - * - * def __iter__(self): # <<<<<<<<<<<<<< - * cdef unsigned i - * for i in range(len(self)): - */ -struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ { - PyObject_HEAD - unsigned int __pyx_v_i; - struct __pyx_obj_5_cdec_Lattice *__pyx_v_self; - Py_ssize_t __pyx_t_0; - unsigned int __pyx_t_1; -}; - - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":18 * self.vector[0][fid] = value * @@ -559,6 +629,39 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest { }; +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":13 + * return ret + * + * cdef class Candidate: # <<<<<<<<<<<<<< + * cdef mteval.Candidate* candidate + * cdef public float score + */ +struct __pyx_obj_5_cdec_Candidate { + PyObject_HEAD + const training::Candidate *candidate; + float score; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":69 + * del derivations + * + * def sample(self, unsigned n): # <<<<<<<<<<<<<< + * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() + * if self.rng == NULL: + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample { + PyObject_HEAD + std::vector *__pyx_v_hypos; + unsigned int __pyx_v_k; + unsigned int __pyx_v_n; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; + PyObject *__pyx_v_sentence; + size_t __pyx_t_0; + unsigned int __pyx_t_1; +}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":3 * from cython.operator cimport preincrement as pinc * @@ -571,6 +674,39 @@ struct __pyx_obj_5_cdec_DenseVector { std::vector *vector; }; + +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":50 + * return hypergraph.AsPLF(self.lattice[0], True).c_str() + * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(len(self)): + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ { + PyObject_HEAD + unsigned int __pyx_v_i; + struct __pyx_obj_5_cdec_Lattice *__pyx_v_self; + Py_ssize_t __pyx_t_0; + unsigned int __pyx_t_1; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":45 + * return self.stats.size() + * + * def __iter__(self): # <<<<<<<<<<<<<< + * for i in range(len(self)): + * yield self.stats[0][i] + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ { + PyObject_HEAD + PyObject *__pyx_v_i; + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self; + Py_ssize_t __pyx_t_0; + PyObject *__pyx_t_1; + PyObject *(*__pyx_t_2)(PyObject *); +}; + #ifndef CYTHON_REFNANNY #define CYTHON_REFNANNY 0 #endif @@ -635,6 +771,8 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, const char *name, int exact); /*proto*/ +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ + static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ @@ -736,8 +874,6 @@ static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ -static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ - static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ @@ -801,6 +937,9 @@ static __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body, PyObject *closure); static int __pyx_Generator_init(void); +static void __Pyx_WriteUnraisable(const char *name, int clineno, + int lineno, const char *filename); /*proto*/ + static int __Pyx_check_binary_version(void); typedef struct { @@ -841,18 +980,28 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* Module declarations from 'kbest' */ +/* Module declarations from 'mteval' */ + /* Module declarations from '_cdec' */ static PyTypeObject *__pyx_ptype_5_cdec_DenseVector = 0; static PyTypeObject *__pyx_ptype_5_cdec_SparseVector = 0; static PyTypeObject *__pyx_ptype_5_cdec_Hypergraph = 0; static PyTypeObject *__pyx_ptype_5_cdec_Lattice = 0; +static PyTypeObject *__pyx_ptype_5_cdec_Candidate = 0; +static PyTypeObject *__pyx_ptype_5_cdec_SufficientStats = 0; +static PyTypeObject *__pyx_ptype_5_cdec_SegmentEvaluator = 0; +static PyTypeObject *__pyx_ptype_5_cdec_Scorer = 0; static PyTypeObject *__pyx_ptype_5_cdec_Decoder = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct____iter__ = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_1___iter__ = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_2_kbest = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_tree = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_4_sample = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_5___iter__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_5_sample = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_6___iter__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_7___iter__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_8_candidate_set = 0; +static char *__pyx_f_5_cdec_as_str(PyObject *, struct __pyx_opt_args_5_cdec_as_str *__pyx_optional_args); /*proto*/ #define __Pyx_MODULE_NAME "_cdec" int __pyx_module_is_main__cdec = 0; @@ -860,11 +1009,10 @@ int __pyx_module_is_main__cdec = 0; static PyObject *__pyx_builtin_Exception; static PyObject *__pyx_builtin_KeyError; static PyObject *__pyx_builtin_range; -static PyObject *__pyx_builtin_ValueError; +static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_NotImplemented; static PyObject *__pyx_builtin_eval; static PyObject *__pyx_builtin_enumerate; -static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_IndexError; static PyObject *__pyx_builtin_open; static PyObject *__pyx_pf_5_cdec_11DenseVector___getitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ @@ -877,7 +1025,7 @@ static int __pyx_pf_5_cdec_12SparseVector_2__setitem__(struct __pyx_obj_5_cdec_S static PyObject *__pyx_pf_5_cdec_12SparseVector_4__iter__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, PyObject *__pyx_v_other); /* proto */ static PyObject *__pyx_pf_5_cdec_12SparseVector_9todense(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other, int __pyx_v_op); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y, int __pyx_v_op); /* proto */ static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_13__len__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ static int __pyx_pf_5_cdec_12SparseVector_15__contains__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ static PyObject *__pyx_pf_5_cdec_12SparseVector_17__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ @@ -886,8 +1034,12 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_21__imul__(struct __pyx_obj_5_cd #if PY_MAJOR_VERSION < 3 static PyObject *__pyx_pf_5_cdec_12SparseVector_23__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ #endif -static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_29__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ +#if PY_MAJOR_VERSION < 3 +static PyObject *__pyx_pf_5_cdec_12SparseVector_31__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ +#endif static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_4viterbi_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ @@ -895,11 +1047,12 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_6viterbi_source_tree(struct __pyx_ static PyObject *__pyx_pf_5_cdec_10Hypergraph_8viterbi_features(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_10kbest(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_13kbest_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_16sample(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, unsigned int __pyx_v_n); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_19intersect(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, struct __pyx_obj_5_cdec_Lattice *__pyx_v_lat); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_21prune(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_beam_alpha, PyObject *__pyx_v_density, PyObject *__pyx_v_kwargs); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_23lattice(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_25reweight(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_weights); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_16kbest_features(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_19sample(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, unsigned int __pyx_v_n); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_22intersect(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, struct __pyx_obj_5_cdec_Lattice *__pyx_v_lat); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_24prune(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_beam_alpha, PyObject *__pyx_v_density, PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_26lattice(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_weights); /* proto */ static int __pyx_pf_5_cdec_7Lattice___init__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, PyObject *__pyx_v_inp); /* proto */ static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index); /* proto */ static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index, PyObject *__pyx_v_arcs); /* proto */ @@ -907,6 +1060,23 @@ static Py_ssize_t __pyx_pf_5_cdec_7Lattice_6__len__(struct __pyx_obj_5_cdec_Latt static PyObject *__pyx_pf_5_cdec_7Lattice_8__str__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ static void __pyx_pf_5_cdec_7Lattice_13__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_9Candidate_4fmap___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_9Candidate_5score___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_9Candidate_5score_2__set__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static void __pyx_pf_5_cdec_15SufficientStats___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_15SufficientStats_5score___get__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_15SufficientStats_6detail___get__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self); /* proto */ +static Py_ssize_t __pyx_pf_5_cdec_15SufficientStats_2__len__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__iadd__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_x, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_y); /* proto */ +static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, PyObject *__pyx_v_sentence); /* proto */ +static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph, unsigned int __pyx_v_k); /* proto */ +static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, char *__pyx_v_name); /* proto */ +static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs); /* proto */ +static PyObject *__pyx_pf_5_cdec_6Scorer_4__str__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self); /* proto */ static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, char *__pyx_v_config); /* proto */ static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Decoder *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_cfg); /* proto */ @@ -920,12 +1090,18 @@ static char __pyx_k_10[] = "csplit_preserve_full_word"; static char __pyx_k_11[] = "cannot reweight hypergraph with %s"; static char __pyx_k_13[] = "Cannot create lattice from %s"; static char __pyx_k_14[] = "lattice index out of range"; -static char __pyx_k_21[] = "Cannot translate input type %s"; +static char __pyx_k_19[] = "Cannot convert type %s to str"; +static char __pyx_k_23[] = "Cannot translate input type %s"; +static char __pyx_k__k[] = "k"; +static char __pyx_k__TER[] = "TER"; static char __pyx_k__dot[] = "dot"; static char __pyx_k__inp[] = "inp"; static char __pyx_k__plf[] = "plf"; +static char __pyx_k__BLEU[] = "BLEU"; static char __pyx_k__eval[] = "eval"; +static char __pyx_k__name[] = "name"; static char __pyx_k__open[] = "open"; +static char __pyx_k__refs[] = "refs"; static char __pyx_k__self[] = "self"; static char __pyx_k__utf8[] = "utf8"; static char __pyx_k___cdec[] = "_cdec"; @@ -937,18 +1113,20 @@ static char __pyx_k__decode[] = "decode"; static char __pyx_k__encode[] = "encode"; static char __pyx_k__density[] = "density"; static char __pyx_k__grammar[] = "grammar"; +static char __pyx_k__IBM_BLEU[] = "IBM_BLEU"; static char __pyx_k__KeyError[] = "KeyError"; static char __pyx_k____exit__[] = "__exit__"; static char __pyx_k____main__[] = "__main__"; static char __pyx_k____test__[] = "__test__"; +static char __pyx_k__encoding[] = "encoding"; static char __pyx_k__sentence[] = "sentence"; static char __pyx_k__Exception[] = "Exception"; static char __pyx_k__TypeError[] = "TypeError"; static char __pyx_k____enter__[] = "__enter__"; static char __pyx_k__enumerate[] = "enumerate"; static char __pyx_k__IndexError[] = "IndexError"; -static char __pyx_k__ValueError[] = "ValueError"; static char __pyx_k__beam_alpha[] = "beam_alpha"; +static char __pyx_k__hypergraph[] = "hypergraph"; static char __pyx_k__ParseFailed[] = "ParseFailed"; static char __pyx_k__NotImplemented[] = "NotImplemented"; static PyObject *__pyx_kp_s_1; @@ -956,15 +1134,18 @@ static PyObject *__pyx_n_s_10; static PyObject *__pyx_kp_s_11; static PyObject *__pyx_kp_s_13; static PyObject *__pyx_kp_s_14; +static PyObject *__pyx_kp_s_19; static PyObject *__pyx_kp_s_2; -static PyObject *__pyx_kp_s_21; +static PyObject *__pyx_kp_s_23; +static PyObject *__pyx_n_s__BLEU; static PyObject *__pyx_n_s__Exception; +static PyObject *__pyx_n_s__IBM_BLEU; static PyObject *__pyx_n_s__IndexError; static PyObject *__pyx_n_s__KeyError; static PyObject *__pyx_n_s__NotImplemented; static PyObject *__pyx_n_s__ParseFailed; +static PyObject *__pyx_n_s__TER; static PyObject *__pyx_n_s__TypeError; -static PyObject *__pyx_n_s__ValueError; static PyObject *__pyx_n_s____enter__; static PyObject *__pyx_n_s____exit__; static PyObject *__pyx_n_s____main__; @@ -976,13 +1157,18 @@ static PyObject *__pyx_n_s__decode; static PyObject *__pyx_n_s__density; static PyObject *__pyx_n_s__dot; static PyObject *__pyx_n_s__encode; +static PyObject *__pyx_n_s__encoding; static PyObject *__pyx_n_s__enumerate; static PyObject *__pyx_n_s__eval; static PyObject *__pyx_n_s__grammar; +static PyObject *__pyx_n_s__hypergraph; static PyObject *__pyx_n_s__inp; +static PyObject *__pyx_n_s__k; +static PyObject *__pyx_n_s__name; static PyObject *__pyx_n_s__open; static PyObject *__pyx_n_s__plf; static PyObject *__pyx_n_s__range; +static PyObject *__pyx_n_s__refs; static PyObject *__pyx_n_s__self; static PyObject *__pyx_n_s__sentence; static PyObject *__pyx_n_s__split; @@ -1002,8 +1188,11 @@ static PyObject *__pyx_k_tuple_15; static PyObject *__pyx_k_tuple_16; static PyObject *__pyx_k_tuple_17; static PyObject *__pyx_k_tuple_18; -static PyObject *__pyx_k_tuple_19; static PyObject *__pyx_k_tuple_20; +static PyObject *__pyx_k_tuple_21; +static PyObject *__pyx_k_tuple_22; +static PyObject *__pyx_k_tuple_24; +static PyObject *__pyx_k_tuple_25; /* Python wrapper */ static PyObject *__pyx_pw_5_cdec_11DenseVector_1__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ @@ -1857,7 +2046,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa * return self.vector.dot(( other).vector[0]) * elif isinstance(other, SparseVector): # <<<<<<<<<<<<<< * return self.vector.dot(( other).vector[0]) - * raise ValueError('cannot take the dot product of %s and SparseVector' % type(other)) + * raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) */ __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)); __Pyx_INCREF(__pyx_t_1); @@ -1869,7 +2058,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa * return self.vector.dot(( other).vector[0]) * elif isinstance(other, SparseVector): * return self.vector.dot(( other).vector[0]) # <<<<<<<<<<<<<< - * raise ValueError('cannot take the dot product of %s and SparseVector' % type(other)) + * raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) * */ __Pyx_XDECREF(__pyx_r); @@ -1885,7 +2074,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":56 * elif isinstance(other, SparseVector): * return self.vector.dot(( other).vector[0]) - * raise ValueError('cannot take the dot product of %s and SparseVector' % type(other)) # <<<<<<<<<<<<<< + * raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) # <<<<<<<<<<<<<< * * def todense(self): */ @@ -1896,7 +2085,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); @@ -1928,7 +2117,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_10todense(PyObject *__pyx_v_self } /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":58 - * raise ValueError('cannot take the dot product of %s and SparseVector' % type(other)) + * raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) * * def todense(self): # <<<<<<<<<<<<<< * cdef DenseVector dense = DenseVector() @@ -1980,7 +2169,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_9todense(struct __pyx_obj_5_cdec * self.vector.init_vector(dense.vector) * return dense # <<<<<<<<<<<<<< * - * def __richcmp__(SparseVector self, SparseVector other, int op): + * def __richcmp__(SparseVector x, SparseVector y, int op): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_dense)); @@ -2001,14 +2190,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_9todense(struct __pyx_obj_5_cdec } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_12__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_12__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_12__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_12__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_self), __pyx_ptype_5_cdec_SparseVector, 1, "self", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_11__richcmp__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other), ((int)__pyx_v_op)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_11__richcmp__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y), ((int)__pyx_v_op)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2020,12 +2209,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_12__richcmp__(PyObject *__pyx_v_ /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":64 * return dense * - * def __richcmp__(SparseVector self, SparseVector other, int op): # <<<<<<<<<<<<<< + * def __richcmp__(SparseVector x, SparseVector y, int op): # <<<<<<<<<<<<<< * if op == 2: # == - * return self.vector[0] == other.vector[0] + * return x.vector[0] == y.vector[0] */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other, int __pyx_v_op) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y, int __pyx_v_op) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -2037,31 +2226,31 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":67 * if op == 2: # == - * return self.vector[0] == other.vector[0] + * return x.vector[0] == y.vector[0] * elif op == 3: # != # <<<<<<<<<<<<<< - * return not (self == other) + * return not (x == y) * raise NotImplemented('comparison not implemented for SparseVector') */ switch (__pyx_v_op) { /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":65 * - * def __richcmp__(SparseVector self, SparseVector other, int op): + * def __richcmp__(SparseVector x, SparseVector y, int op): * if op == 2: # == # <<<<<<<<<<<<<< - * return self.vector[0] == other.vector[0] + * return x.vector[0] == y.vector[0] * elif op == 3: # != */ case 2: /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":66 - * def __richcmp__(SparseVector self, SparseVector other, int op): + * def __richcmp__(SparseVector x, SparseVector y, int op): * if op == 2: # == - * return self.vector[0] == other.vector[0] # <<<<<<<<<<<<<< + * return x.vector[0] == y.vector[0] # <<<<<<<<<<<<<< * elif op == 3: # != - * return not (self == other) + * return not (x == y) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_self->vector[0]) == (__pyx_v_other->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_x->vector[0]) == (__pyx_v_y->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2070,22 +2259,22 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":67 * if op == 2: # == - * return self.vector[0] == other.vector[0] + * return x.vector[0] == y.vector[0] * elif op == 3: # != # <<<<<<<<<<<<<< - * return not (self == other) + * return not (x == y) * raise NotImplemented('comparison not implemented for SparseVector') */ case 3: /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":68 - * return self.vector[0] == other.vector[0] + * return x.vector[0] == y.vector[0] * elif op == 3: # != - * return not (self == other) # <<<<<<<<<<<<<< + * return not (x == y) # <<<<<<<<<<<<<< * raise NotImplemented('comparison not implemented for SparseVector') * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_self), ((PyObject *)__pyx_v_other), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -2099,7 +2288,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":69 * elif op == 3: # != - * return not (self == other) + * return not (x == y) * raise NotImplemented('comparison not implemented for SparseVector') # <<<<<<<<<<<<<< * * def __len__(self): @@ -2439,7 +2628,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_23__idiv__(struct __pyx_obj_5_cd * self.vector[0] /= scalar * return self # <<<<<<<<<<<<<< * - * def __add__(SparseVector self, SparseVector other): + * def __add__(SparseVector x, SparseVector y): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_self)); @@ -2455,14 +2644,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_23__idiv__(struct __pyx_obj_5_cd #endif /*!(#if PY_MAJOR_VERSION < 3)*/ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__add__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_self), __pyx_ptype_5_cdec_SparseVector, 1, "self", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_25__add__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_25__add__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2474,12 +2663,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_self /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":93 * return self * - * def __add__(SparseVector self, SparseVector other): # <<<<<<<<<<<<<< + * def __add__(SparseVector x, SparseVector y): # <<<<<<<<<<<<<< * cdef SparseVector result = SparseVector() - * result.vector = new FastSparseVector[weight_t](self.vector[0] + other.vector[0]) + * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -2491,9 +2680,9 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cde /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":94 * - * def __add__(SparseVector self, SparseVector other): + * def __add__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< - * result.vector = new FastSparseVector[weight_t](self.vector[0] + other.vector[0]) + * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) * return result */ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -2502,20 +2691,20 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cde __pyx_t_1 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":95 - * def __add__(SparseVector self, SparseVector other): + * def __add__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() - * result.vector = new FastSparseVector[weight_t](self.vector[0] + other.vector[0]) # <<<<<<<<<<<<<< + * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) # <<<<<<<<<<<<<< * return result * */ - __pyx_v_result->vector = new FastSparseVector(((__pyx_v_self->vector[0]) + (__pyx_v_other->vector[0]))); + __pyx_v_result->vector = new FastSparseVector(((__pyx_v_x->vector[0]) + (__pyx_v_y->vector[0]))); /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":96 * cdef SparseVector result = SparseVector() - * result.vector = new FastSparseVector[weight_t](self.vector[0] + other.vector[0]) + * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) * return result # <<<<<<<<<<<<<< * - * def __sub__(SparseVector self, SparseVector other): + * def __sub__(SparseVector x, SparseVector y): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); @@ -2536,14 +2725,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cde } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__sub__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_self), __pyx_ptype_5_cdec_SparseVector, 1, "self", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_27__sub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_27__sub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2555,12 +2744,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_self /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":98 * return result * - * def __sub__(SparseVector self, SparseVector other): # <<<<<<<<<<<<<< + * def __sub__(SparseVector x, SparseVector y): # <<<<<<<<<<<<<< * cdef SparseVector result = SparseVector() - * result.vector = new FastSparseVector[weight_t](self.vector[0] - other.vector[0]) + * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -2572,9 +2761,9 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cde /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":99 * - * def __sub__(SparseVector self, SparseVector other): + * def __sub__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< - * result.vector = new FastSparseVector[weight_t](self.vector[0] - other.vector[0]) + * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) * return result */ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -2583,17 +2772,20 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cde __pyx_t_1 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":100 - * def __sub__(SparseVector self, SparseVector other): + * def __sub__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() - * result.vector = new FastSparseVector[weight_t](self.vector[0] - other.vector[0]) # <<<<<<<<<<<<<< + * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) # <<<<<<<<<<<<<< * return result + * */ - __pyx_v_result->vector = new FastSparseVector(((__pyx_v_self->vector[0]) - (__pyx_v_other->vector[0]))); + __pyx_v_result->vector = new FastSparseVector(((__pyx_v_x->vector[0]) - (__pyx_v_y->vector[0]))); /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":101 * cdef SparseVector result = SparseVector() - * result.vector = new FastSparseVector[weight_t](self.vector[0] - other.vector[0]) + * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) * return result # <<<<<<<<<<<<<< + * + * def __mul__(x, y): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); @@ -2614,105 +2806,346 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cde } /* Python wrapper */ -static void __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_30__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_30__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_10Hypergraph___dealloc__(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__mul__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_29__mul__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":8 - * cdef MT19937* rng +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":103 + * return result * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.hg - * if self.rng != NULL: + * def __mul__(x, y): # <<<<<<<<<<<<<< + * cdef SparseVector vector + * cdef float scalar */ -static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_29__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_vector = 0; + float __pyx_v_scalar; + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("__dealloc__", 0); + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + float __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__mul__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":9 - * - * def __dealloc__(self): - * del self.hg # <<<<<<<<<<<<<< - * if self.rng != NULL: - * del self.rng + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":106 + * cdef SparseVector vector + * cdef float scalar + * if isinstance(x, SparseVector): vector, scalar = x, y # <<<<<<<<<<<<<< + * else: vector, scalar = y, x + * cdef SparseVector result = SparseVector() */ - delete __pyx_v_self->hg; + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_v_x; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + __pyx_v_scalar = __pyx_t_3; + goto __pyx_L3; + } + /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":10 - * def __dealloc__(self): - * del self.hg - * if self.rng != NULL: # <<<<<<<<<<<<<< - * del self.rng + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":107 + * cdef float scalar + * if isinstance(x, SparseVector): vector, scalar = x, y + * else: vector, scalar = y, x # <<<<<<<<<<<<<< + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) + */ + if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_v_y; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + __pyx_v_scalar = __pyx_t_3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":108 + * if isinstance(x, SparseVector): vector, scalar = x, y + * else: vector, scalar = y, x + * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< + * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) + * return result + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":109 + * else: vector, scalar = y, x + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) # <<<<<<<<<<<<<< + * return result * */ - __pyx_t_1 = (__pyx_v_self->rng != NULL); - if (__pyx_t_1) { + __pyx_v_result->vector = new FastSparseVector(((__pyx_v_vector->vector[0]) * __pyx_v_scalar)); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":11 - * del self.hg - * if self.rng != NULL: - * del self.rng # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":110 + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) + * return result # <<<<<<<<<<<<<< * - * def viterbi(self): + * def __div__(x, y): */ - delete __pyx_v_self->rng; - goto __pyx_L3; - } - __pyx_L3:; + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + 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.SparseVector.__mul__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_vector); + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); + return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_3viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_3viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +#if PY_MAJOR_VERSION < 3 +static PyObject *__pyx_pw_5_cdec_12SparseVector_32__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_32__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("viterbi (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_2viterbi(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__div__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_31__div__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); __Pyx_RefNannyFinishContext(); return __pyx_r; } +#endif /*!(#if PY_MAJOR_VERSION < 3)*/ -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":13 - * del self.rng +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":112 + * return result * - * def viterbi(self): # <<<<<<<<<<<<<< - * cdef vector[WordID] trans - * hypergraph.ViterbiESentence(self.hg[0], &trans) + * def __div__(x, y): # <<<<<<<<<<<<<< + * cdef SparseVector vector + * cdef float scalar */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { - std::vector __pyx_v_trans; - PyObject *__pyx_v_sentence = 0; +#if PY_MAJOR_VERSION < 3 +static PyObject *__pyx_pf_5_cdec_12SparseVector_31__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_vector = 0; + float __pyx_v_scalar; + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; + int __pyx_t_2; + float __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("viterbi", 0); + __Pyx_RefNannySetupContext("__div__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":15 - * def viterbi(self): - * cdef vector[WordID] trans - * hypergraph.ViterbiESentence(self.hg[0], &trans) # <<<<<<<<<<<<<< - * cdef str sentence = GetString(trans).c_str() - * return sentence.decode('utf8') + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":115 + * cdef SparseVector vector + * cdef float scalar + * if isinstance(x, SparseVector): vector, scalar = x, y # <<<<<<<<<<<<<< + * else: vector, scalar = y, x + * cdef SparseVector result = SparseVector() */ - ViterbiESentence((__pyx_v_self->hg[0]), (&__pyx_v_trans)); + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_v_x; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + __pyx_v_scalar = __pyx_t_3; + goto __pyx_L3; + } + /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":16 - * cdef vector[WordID] trans - * hypergraph.ViterbiESentence(self.hg[0], &trans) - * cdef str sentence = GetString(trans).c_str() # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":116 + * cdef float scalar + * if isinstance(x, SparseVector): vector, scalar = x, y + * else: vector, scalar = y, x # <<<<<<<<<<<<<< + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) + */ + if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_v_y; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + __pyx_v_scalar = __pyx_t_3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":117 + * if isinstance(x, SparseVector): vector, scalar = x, y + * else: vector, scalar = y, x + * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< + * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) + * return result + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":118 + * else: vector, scalar = y, x + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) # <<<<<<<<<<<<<< + * return result + */ + __pyx_v_result->vector = new FastSparseVector(((__pyx_v_vector->vector[0]) / __pyx_v_scalar)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":119 + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) + * return result # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + 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.SparseVector.__div__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_vector); + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +#endif /*!(#if PY_MAJOR_VERSION < 3)*/ + +/* Python wrapper */ +static void __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_10Hypergraph___dealloc__(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":8 + * cdef MT19937* rng + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.hg + * if self.rng != NULL: + */ + +static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":9 + * + * def __dealloc__(self): + * del self.hg # <<<<<<<<<<<<<< + * if self.rng != NULL: + * del self.rng + */ + delete __pyx_v_self->hg; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":10 + * def __dealloc__(self): + * del self.hg + * if self.rng != NULL: # <<<<<<<<<<<<<< + * del self.rng + * + */ + __pyx_t_1 = (__pyx_v_self->rng != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":11 + * del self.hg + * if self.rng != NULL: + * del self.rng # <<<<<<<<<<<<<< + * + * def viterbi(self): + */ + delete __pyx_v_self->rng; + goto __pyx_L3; + } + __pyx_L3:; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_3viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_3viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("viterbi (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_2viterbi(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":13 + * del self.rng + * + * def viterbi(self): # <<<<<<<<<<<<<< + * cdef vector[WordID] trans + * hypergraph.ViterbiESentence(self.hg[0], &trans) + */ + +static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + std::vector __pyx_v_trans; + PyObject *__pyx_v_sentence = 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", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":15 + * def viterbi(self): + * cdef vector[WordID] trans + * hypergraph.ViterbiESentence(self.hg[0], &trans) # <<<<<<<<<<<<<< + * cdef str sentence = GetString(trans).c_str() + * return sentence.decode('utf8') + */ + ViterbiESentence((__pyx_v_self->hg[0]), (&__pyx_v_trans)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":16 + * cdef vector[WordID] trans + * hypergraph.ViterbiESentence(self.hg[0], &trans) + * cdef str sentence = GetString(trans).c_str() # <<<<<<<<<<<<<< * return sentence.decode('utf8') * */ @@ -3338,7 +3771,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator3(__pyx_GeneratorObject * yield tree.decode('utf8') * del derivations # <<<<<<<<<<<<<< * - * def sample(self, unsigned n): + * def kbest_features(self, size): */ delete __pyx_cur_scope->__pyx_v_derivations; PyErr_SetNone(PyExc_StopIteration); @@ -3356,22 +3789,12 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator3(__pyx_GeneratorObject static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_17sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_17sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n) { - unsigned int __pyx_v_n; +static PyObject *__pyx_pw_5_cdec_10Hypergraph_17kbest_features(PyObject *__pyx_v_self, PyObject *__pyx_v_size); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_17kbest_features(PyObject *__pyx_v_self, PyObject *__pyx_v_size) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("sample (wrapper)", 0); - assert(__pyx_arg_n); { - __pyx_v_n = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_n); if (unlikely((__pyx_v_n == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __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_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_16sample(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((unsigned int)__pyx_v_n)); + __Pyx_RefNannySetupContext("kbest_features (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_16kbest_features(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_size)); __Pyx_RefNannyFinishContext(); return __pyx_r; } @@ -3379,20 +3802,20 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_17sample(PyObject *__pyx_v_self, P /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 * del derivations * - * def sample(self, unsigned n): # <<<<<<<<<<<<<< - * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() - * if self.rng == NULL: + * def kbest_features(self, size): # <<<<<<<<<<<<<< + * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) + * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal].Derivation* derivation */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_16sample(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, unsigned int __pyx_v_n) { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_16kbest_features(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *__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", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *)__pyx_ptype_5_cdec___pyx_scope_struct_4_sample->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_4_sample, __pyx_empty_tuple, NULL); + __Pyx_RefNannySetupContext("kbest_features", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)__pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -3401,7 +3824,9 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_16sample(struct __pyx_obj_5_cdec_H __pyx_cur_scope->__pyx_v_self = __pyx_v_self; __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __pyx_cur_scope->__pyx_v_n = __pyx_v_n; + __pyx_cur_scope->__pyx_v_size = __pyx_v_size; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); { __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_18generator4, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); @@ -3412,7 +3837,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_16sample(struct __pyx_obj_5_cdec_H __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Hypergraph.sample", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Hypergraph.kbest_features", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); @@ -3423,13 +3848,12 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_16sample(struct __pyx_obj_5_cdec_H static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *)__pyx_generator->closure); + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)__pyx_generator->closure); PyObject *__pyx_r = NULL; - int __pyx_t_1; - size_t __pyx_t_2; - unsigned int __pyx_t_3; + 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", 0); switch (__pyx_generator->resume_label) { @@ -3444,99 +3868,298 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":57 * - * def sample(self, unsigned n): - * 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(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":58 - * def sample(self, unsigned n): - * 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) + * def kbest_features(self, size): + * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) # <<<<<<<<<<<<<< + * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal].Derivation* derivation + * cdef SparseVector fmap */ - __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->rng == NULL); - if (__pyx_t_1) { + __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[2]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,FeatureVectorTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":59 - * 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 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":61 + * cdef SparseVector fmap + * cdef unsigned k + * for k in range(size): # <<<<<<<<<<<<<< + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break */ - __pyx_cur_scope->__pyx_v_self->rng = new MT19937(); - goto __pyx_L4; - } - __pyx_L4:; + __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[2]; __pyx_lineno = 61; __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; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":60 - * if self.rng == NULL: - * self.rng = new MT19937() - * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) # <<<<<<<<<<<<<< - * cdef str sentence + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":62 * cdef unsigned k + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< + * if not derivation: break + * fmap = SparseVector() */ - HypergraphSampler::sample_hypotheses((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_cur_scope->__pyx_v_n, __pyx_cur_scope->__pyx_v_self->rng, __pyx_cur_scope->__pyx_v_hypos); + __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":63 - * cdef str sentence - * cdef unsigned k - * for k in range(hypos.size()): # <<<<<<<<<<<<<< - * sentence = GetString(hypos[0][k].words).c_str() - * yield sentence.decode('utf8') + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":63 + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break # <<<<<<<<<<<<<< + * fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) */ - __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; + __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0)); + if (__pyx_t_3) { + goto __pyx_L5_break; + goto __pyx_L6; + } + __pyx_L6:; /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":64 - * cdef unsigned k - * for k in range(hypos.size()): - * sentence = GetString(hypos[0][k].words).c_str() # <<<<<<<<<<<<<< - * yield sentence.decode('utf8') - * del hypos + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break + * fmap = SparseVector() # <<<<<<<<<<<<<< + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) + * yield fmap */ - __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[2]; __pyx_lineno = 64; __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[2]; __pyx_lineno = 64; __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 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_cur_scope->__pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_4); __pyx_t_4 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":65 - * for k in range(hypos.size()): - * sentence = GetString(hypos[0][k].words).c_str() - * yield sentence.decode('utf8') # <<<<<<<<<<<<<< - * del hypos + * if not derivation: break + * fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) # <<<<<<<<<<<<<< + * yield fmap + * del derivations + */ + __pyx_cur_scope->__pyx_v_fmap->vector = new FastSparseVector(__pyx_cur_scope->__pyx_v_derivation->yield); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":66 + * fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) + * yield fmap # <<<<<<<<<<<<<< + * 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[2]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 65; __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_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); + __pyx_r = ((PyObject *)__pyx_cur_scope->__pyx_v_fmap); + __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_generator->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[2]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } + __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[2]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L5_break:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":67 + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) + * yield fmap + * del derivations # <<<<<<<<<<<<<< + * + * def sample(self, unsigned n): + */ + delete __pyx_cur_scope->__pyx_v_derivations; + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("kbest_features", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} +static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_20sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_20sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n) { + unsigned int __pyx_v_n; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("sample (wrapper)", 0); + assert(__pyx_arg_n); { + __pyx_v_n = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_n); if (unlikely((__pyx_v_n == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __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_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_19sample(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((unsigned int)__pyx_v_n)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":69 + * del derivations + * + * def sample(self, unsigned n): # <<<<<<<<<<<<<< + * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() + * if self.rng == NULL: + */ + +static PyObject *__pyx_pf_5_cdec_10Hypergraph_19sample(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, unsigned int __pyx_v_n) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5_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", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)__pyx_ptype_5_cdec___pyx_scope_struct_5_sample->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_5_sample, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __pyx_cur_scope->__pyx_v_n = __pyx_v_n; + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_21generator5, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Hypergraph.sample", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)__pyx_generator->closure); + 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", 0); + switch (__pyx_generator->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[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":70 + * + * def sample(self, unsigned n): + * 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(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":71 + * def sample(self, unsigned n): + * 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 = (__pyx_cur_scope->__pyx_v_self->rng == NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":72 + * 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 + */ + __pyx_cur_scope->__pyx_v_self->rng = new MT19937(); + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":73 + * 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((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_cur_scope->__pyx_v_n, __pyx_cur_scope->__pyx_v_self->rng, __pyx_cur_scope->__pyx_v_hypos); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":76 + * 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; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":77 + * 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[2]; __pyx_lineno = 77; __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[2]; __pyx_lineno = 77; __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; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":78 + * 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[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 78; __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_generator->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[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":66 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":79 * sentence = GetString(hypos[0][k].words).c_str() * yield sentence.decode('utf8') * del hypos # <<<<<<<<<<<<<< @@ -3558,13 +4181,13 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_20intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_20intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_23intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_23intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("intersect (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lat), __pyx_ptype_5_cdec_Lattice, 1, "lat", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_19intersect(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_lat)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lat), __pyx_ptype_5_cdec_Lattice, 1, "lat", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_22intersect(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_lat)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -3573,7 +4196,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_20intersect(PyObject *__pyx_v_self return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":70 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":83 * # TODO richer k-best/sample output (feature vectors, trees?) * * def intersect(self, Lattice lat): # <<<<<<<<<<<<<< @@ -3581,7 +4204,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_20intersect(PyObject *__pyx_v_self * */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_19intersect(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, struct __pyx_obj_5_cdec_Lattice *__pyx_v_lat) { +static PyObject *__pyx_pf_5_cdec_10Hypergraph_22intersect(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, struct __pyx_obj_5_cdec_Lattice *__pyx_v_lat) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -3590,7 +4213,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_19intersect(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("intersect", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":71 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":84 * * def intersect(self, Lattice lat): * return hypergraph.Intersect(lat.lattice[0], self.hg) # <<<<<<<<<<<<<< @@ -3598,7 +4221,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_19intersect(struct __pyx_obj_5_cde * def prune(self, beam_alpha=0, density=0, **kwargs): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(HG::Intersect((__pyx_v_lat->lattice[0]), __pyx_v_self->hg)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyBool_FromLong(HG::Intersect((__pyx_v_lat->lattice[0]), __pyx_v_self->hg)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -3617,8 +4240,8 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_19intersect(struct __pyx_obj_5_cde } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_22prune(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_22prune(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_25prune(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_25prune(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_beam_alpha = 0; PyObject *__pyx_v_density = 0; PyObject *__pyx_v_kwargs = 0; @@ -3655,7 +4278,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_22prune(PyObject *__pyx_v_self, Py } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "prune") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "prune") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -3670,20 +4293,20 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_22prune(PyObject *__pyx_v_self, Py } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("prune", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("prune", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; __Pyx_AddTraceback("_cdec.Hypergraph.prune", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_21prune(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), __pyx_v_beam_alpha, __pyx_v_density, __pyx_v_kwargs); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_24prune(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), __pyx_v_beam_alpha, __pyx_v_density, __pyx_v_kwargs); __Pyx_XDECREF(__pyx_v_kwargs); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":73 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":86 * return hypergraph.Intersect(lat.lattice[0], self.hg) * * def prune(self, beam_alpha=0, density=0, **kwargs): # <<<<<<<<<<<<<< @@ -3691,7 +4314,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_22prune(PyObject *__pyx_v_self, Py * if 'csplit_preserve_full_word' in kwargs: */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_21prune(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_beam_alpha, PyObject *__pyx_v_density, PyObject *__pyx_v_kwargs) { +static PyObject *__pyx_pf_5_cdec_10Hypergraph_24prune(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_beam_alpha, PyObject *__pyx_v_density, PyObject *__pyx_v_kwargs) { std::vector *__pyx_v_preserve_mask; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -3703,7 +4326,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_21prune(struct __pyx_obj_5_cdec_Hy int __pyx_clineno = 0; __Pyx_RefNannySetupContext("prune", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":74 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":87 * * def prune(self, beam_alpha=0, density=0, **kwargs): * cdef hypergraph.EdgeMask* preserve_mask = NULL # <<<<<<<<<<<<<< @@ -3712,17 +4335,17 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_21prune(struct __pyx_obj_5_cdec_Hy */ __pyx_v_preserve_mask = NULL; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":75 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":88 * def prune(self, beam_alpha=0, density=0, **kwargs): * cdef hypergraph.EdgeMask* preserve_mask = NULL * if 'csplit_preserve_full_word' in kwargs: # <<<<<<<<<<<<<< * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True */ - __pyx_t_1 = ((PyDict_Contains(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s_10)))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = ((PyDict_Contains(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s_10)))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":76 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":89 * cdef hypergraph.EdgeMask* preserve_mask = NULL * if 'csplit_preserve_full_word' in kwargs: * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) # <<<<<<<<<<<<<< @@ -3731,7 +4354,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_21prune(struct __pyx_obj_5_cdec_Hy */ __pyx_v_preserve_mask = new std::vector(__pyx_v_self->hg->edges_.size()); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":77 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":90 * if 'csplit_preserve_full_word' in kwargs: * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True # <<<<<<<<<<<<<< @@ -3743,15 +4366,15 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_21prune(struct __pyx_obj_5_cdec_Hy } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":78 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":91 * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) # <<<<<<<<<<<<<< * * def lattice(self): # TODO direct hg -> lattice conversion in cdec */ - __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_beam_alpha); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_density); if (unlikely((__pyx_t_3 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_beam_alpha); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_density); if (unlikely((__pyx_t_3 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->hg->PruneInsideOutside(__pyx_t_2, __pyx_t_3, __pyx_v_preserve_mask, 0, 1.0, 0); __pyx_r = Py_None; __Pyx_INCREF(Py_None); @@ -3766,17 +4389,17 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_21prune(struct __pyx_obj_5_cdec_Hy } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_24lattice(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_24lattice(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_27lattice(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_27lattice(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("lattice (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_23lattice(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_26lattice(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":80 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":93 * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) * * def lattice(self): # TODO direct hg -> lattice conversion in cdec # <<<<<<<<<<<<<< @@ -3784,7 +4407,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_24lattice(PyObject *__pyx_v_self, * return Lattice(eval(plf)) */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_23lattice(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_10Hypergraph_26lattice(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { PyObject *__pyx_v_plf = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -3796,20 +4419,20 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_23lattice(struct __pyx_obj_5_cdec_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("lattice", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":81 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":94 * * def lattice(self): # TODO direct hg -> lattice conversion in cdec * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() # <<<<<<<<<<<<<< * return Lattice(eval(plf)) * */ - __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->hg[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->hg[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 94; __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[2]; __pyx_lineno = 81; __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[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_plf = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":82 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":95 * def lattice(self): # TODO direct hg -> lattice conversion in cdec * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() * return Lattice(eval(plf)) # <<<<<<<<<<<<<< @@ -3817,17 +4440,17 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_23lattice(struct __pyx_obj_5_cdec_ * def reweight(self, weights): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_Globals(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_Globals(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); if (((PyObject *)__pyx_v_plf)) { - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__plf), ((PyObject *)__pyx_v_plf)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__plf), ((PyObject *)__pyx_v_plf)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } if (((PyObject *)__pyx_v_self)) { - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_v_self)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_v_self)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)__pyx_v_plf)); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_plf)); @@ -3838,15 +4461,15 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_23lattice(struct __pyx_obj_5_cdec_ __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); __pyx_t_1 = 0; __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_eval, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_builtin_eval, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; @@ -3869,17 +4492,17 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_23lattice(struct __pyx_obj_5_cdec_ } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_26reweight(PyObject *__pyx_v_self, PyObject *__pyx_v_weights); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_26reweight(PyObject *__pyx_v_self, PyObject *__pyx_v_weights) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_29reweight(PyObject *__pyx_v_self, PyObject *__pyx_v_weights); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_29reweight(PyObject *__pyx_v_self, PyObject *__pyx_v_weights) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("reweight (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_25reweight(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_weights)); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_28reweight(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_weights)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":84 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":97 * return Lattice(eval(plf)) * * def reweight(self, weights): # <<<<<<<<<<<<<< @@ -3887,7 +4510,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_26reweight(PyObject *__pyx_v_self, * self.hg.Reweight(( weights).vector[0]) */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_25reweight(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_weights) { +static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_weights) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -3898,7 +4521,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_25reweight(struct __pyx_obj_5_cdec int __pyx_clineno = 0; __Pyx_RefNannySetupContext("reweight", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":85 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":98 * * def reweight(self, weights): * if isinstance(weights, SparseVector): # <<<<<<<<<<<<<< @@ -3911,7 +4534,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_25reweight(struct __pyx_obj_5_cdec __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":86 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":99 * def reweight(self, weights): * if isinstance(weights, SparseVector): * self.hg.Reweight(( weights).vector[0]) # <<<<<<<<<<<<<< @@ -3922,7 +4545,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_25reweight(struct __pyx_obj_5_cdec goto __pyx_L3; } - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":87 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":100 * if isinstance(weights, SparseVector): * self.hg.Reweight(( weights).vector[0]) * elif isinstance(weights, DenseVector): # <<<<<<<<<<<<<< @@ -3935,38 +4558,38 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_25reweight(struct __pyx_obj_5_cdec __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":88 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":101 * self.hg.Reweight(( weights).vector[0]) * elif isinstance(weights, DenseVector): * self.hg.Reweight(( weights).vector[0]) # <<<<<<<<<<<<<< * else: - * raise ValueError('cannot reweight hypergraph with %s' % type(weights)) + * raise TypeError('cannot reweight hypergraph with %s' % type(weights)) */ __pyx_v_self->hg->Reweight((((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_weights)->vector[0])); goto __pyx_L3; } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":90 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":103 * self.hg.Reweight(( weights).vector[0]) * else: - * raise ValueError('cannot reweight hypergraph with %s' % type(weights)) # <<<<<<<<<<<<<< + * raise TypeError('cannot reweight hypergraph with %s' % type(weights)) # <<<<<<<<<<<<<< * * # TODO get feature expectations, get partition function ("inside" score) */ - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L3:; @@ -4787,7 +5410,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_8__str__(struct __pyx_obj_5_cdec_Latti __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_7Lattice_12generator5(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5_cdec_7Lattice_12generator6(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ static PyObject *__pyx_pw_5_cdec_7Lattice_11__iter__(PyObject *__pyx_v_self); /*proto*/ @@ -4809,14 +5432,14 @@ static PyObject *__pyx_pw_5_cdec_7Lattice_11__iter__(PyObject *__pyx_v_self) { */ static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *__pyx_cur_scope; + struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__iter__", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_5___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_5___iter__, __pyx_empty_tuple, NULL); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_6___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_6___iter__, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -4826,7 +5449,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lat __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Lattice_12generator5, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Lattice_12generator6, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -4844,9 +5467,9 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lat return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_7Lattice_12generator5(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_7Lattice_12generator6(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *)__pyx_generator->closure); + struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; Py_ssize_t __pyx_t_1; unsigned int __pyx_t_2; @@ -4939,839 +5562,496 @@ static void __pyx_pf_5_cdec_7Lattice_13__dealloc__(CYTHON_UNUSED struct __pyx_ob __Pyx_RefNannyFinishContext(); } -/* Python wrapper */ -static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - char *__pyx_v_config; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__config,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[1] = {0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__config); - 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __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 = 19; __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 = 19; __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:; - __pyx_r = __pyx_pf_5_cdec_7Decoder___cinit__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_config); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "_cdec.pyx":19 - * cdef public DenseVector weights +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":3 + * cimport mteval * - * def __cinit__(self, char* config): # <<<<<<<<<<<<<< - * decoder.register_feature_functions() - * cdef istringstream* config_stream = new istringstream(config) + * cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): # <<<<<<<<<<<<<< + * cdef bytes ret + * if isinstance(sentence, unicode): */ -static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, char *__pyx_v_config) { - std::istringstream *__pyx_v_config_stream; - int __pyx_r; +static char *__pyx_f_5_cdec_as_str(PyObject *__pyx_v_sentence, struct __pyx_opt_args_5_cdec_as_str *__pyx_optional_args) { + PyObject *__pyx_v_error_msg = ((PyObject *)__pyx_kp_s_19); + PyObject *__pyx_v_ret = 0; + char *__pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + char *__pyx_t_4; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); + __Pyx_RefNannySetupContext("as_str", 0); + if (__pyx_optional_args) { + if (__pyx_optional_args->__pyx_n > 0) { + __pyx_v_error_msg = __pyx_optional_args->error_msg; + } + } - /* "_cdec.pyx":20 - * - * def __cinit__(self, char* config): - * decoder.register_feature_functions() # <<<<<<<<<<<<<< - * cdef istringstream* config_stream = new istringstream(config) - * self.dec = new decoder.Decoder(config_stream) + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":5 + * cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): + * cdef bytes ret + * if isinstance(sentence, unicode): # <<<<<<<<<<<<<< + * ret = sentence.encode('utf8') + * elif isinstance(sentence, str): */ - register_feature_functions(); - - /* "_cdec.pyx":21 - * def __cinit__(self, char* config): - * decoder.register_feature_functions() - * cdef istringstream* config_stream = new istringstream(config) # <<<<<<<<<<<<<< - * self.dec = new decoder.Decoder(config_stream) - * del config_stream + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":6 + * cdef bytes ret + * if isinstance(sentence, unicode): + * ret = sentence.encode('utf8') # <<<<<<<<<<<<<< + * elif isinstance(sentence, str): + * ret = sentence */ - __pyx_v_config_stream = new std::istringstream(__pyx_v_config); + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_ret = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + goto __pyx_L3; + } - /* "_cdec.pyx":22 - * decoder.register_feature_functions() - * cdef istringstream* config_stream = new istringstream(config) - * self.dec = new decoder.Decoder(config_stream) # <<<<<<<<<<<<<< - * del config_stream - * self.weights = DenseVector() + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":7 + * if isinstance(sentence, unicode): + * ret = sentence.encode('utf8') + * elif isinstance(sentence, str): # <<<<<<<<<<<<<< + * ret = sentence + * else: */ - __pyx_v_self->dec = new Decoder(__pyx_v_config_stream); + __pyx_t_3 = ((PyObject *)((PyObject*)(&PyString_Type))); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_2) { - /* "_cdec.pyx":23 - * cdef istringstream* config_stream = new istringstream(config) - * self.dec = new decoder.Decoder(config_stream) - * del config_stream # <<<<<<<<<<<<<< - * self.weights = DenseVector() - * self.weights.vector = &self.dec.CurrentWeightVector() + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":8 + * ret = sentence.encode('utf8') + * elif isinstance(sentence, str): + * ret = sentence # <<<<<<<<<<<<<< + * else: + * raise TypeError(error_msg % type(sentence)) */ - delete __pyx_v_config_stream; + if (!(likely(PyBytes_CheckExact(__pyx_v_sentence))||((__pyx_v_sentence) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_sentence)->tp_name), 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_sentence); + __pyx_v_ret = ((PyObject*)__pyx_v_sentence); + goto __pyx_L3; + } + /*else*/ { - /* "_cdec.pyx":24 - * self.dec = new decoder.Decoder(config_stream) - * del config_stream - * self.weights = DenseVector() # <<<<<<<<<<<<<< - * self.weights.vector = &self.dec.CurrentWeightVector() + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":10 + * ret = sentence + * else: + * raise TypeError(error_msg % type(sentence)) # <<<<<<<<<<<<<< + * return ret * */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->weights); - __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); - __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_3 = PyNumber_Remainder(__pyx_v_error_msg, ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; - /* "_cdec.pyx":25 - * del config_stream - * self.weights = DenseVector() - * self.weights.vector = &self.dec.CurrentWeightVector() # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":11 + * else: + * raise TypeError(error_msg % type(sentence)) + * return ret # <<<<<<<<<<<<<< * - * def __dealloc__(self): + * cdef class Candidate: */ - __pyx_v_self->weights->vector = (&__pyx_v_self->dec->CurrentWeightVector()); + __pyx_t_4 = PyBytes_AsString(((PyObject *)__pyx_v_ret)); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_t_4; + goto __pyx_L0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.Decoder.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_WriteUnraisable("_cdec.as_str", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_ret); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_9Candidate_5words_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9Candidate_5words_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_7Decoder_2__dealloc__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9Candidate_5words___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* "_cdec.pyx":27 - * self.weights.vector = &self.dec.CurrentWeightVector() +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":18 * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.dec + * property words: + * def __get__(self): # <<<<<<<<<<<<<< + * return unicode(GetString(self.candidate.ewords).c_str(), encoding='utf8') * */ -static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); - /* "_cdec.pyx":28 - * - * def __dealloc__(self): - * del self.dec # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":19 + * property words: + * def __get__(self): + * return unicode(GetString(self.candidate.ewords).c_str(), encoding='utf8') # <<<<<<<<<<<<<< * - * def read_weights(self, cfg): + * property fmap: */ - delete __pyx_v_self->dec; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(TD::GetString(__pyx_v_self->candidate->ewords).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 19; __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[4]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__encoding), ((PyObject *)__pyx_n_s__utf8)) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec.Candidate.words.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); + return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_cfg); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_cfg) { +static PyObject *__pyx_pw_5_cdec_9Candidate_4fmap_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9Candidate_4fmap_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_weights (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_4read_weights(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_cfg)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9Candidate_4fmap___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":30 - * del self.dec +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":22 * - * def read_weights(self, cfg): # <<<<<<<<<<<<<< - * with open(cfg) as fp: - * for line in fp: + * property fmap: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) */ -static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_cfg) { - PyObject *__pyx_v_fp = NULL; - PyObject *__pyx_v_line = NULL; - PyObject *__pyx_v_fname = NULL; - PyObject *__pyx_v_value = NULL; +static PyObject *__pyx_pf_5_cdec_9Candidate_4fmap___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - Py_ssize_t __pyx_t_8; - PyObject *(*__pyx_t_9)(PyObject *); - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *(*__pyx_t_12)(PyObject *); - double __pyx_t_13; - int __pyx_t_14; - PyObject *__pyx_t_15 = NULL; - int __pyx_t_16; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("read_weights", 0); + __Pyx_RefNannySetupContext("__get__", 0); - /* "_cdec.pyx":31 - * - * def read_weights(self, cfg): - * with open(cfg) as fp: # <<<<<<<<<<<<<< - * for line in fp: - * fname, value = line.split() + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":23 + * property fmap: + * def __get__(self): + * cdef SparseVector fmap = SparseVector() # <<<<<<<<<<<<<< + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) + * return fmap */ - /*with:*/ { - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__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 = 31; __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 = 31; __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 = 31; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /*try:*/ { - { - __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - /*try:*/ { - __Pyx_INCREF(__pyx_t_4); - __pyx_v_fp = __pyx_t_4; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; - /* "_cdec.pyx":32 - * def read_weights(self, cfg): - * with open(cfg) as fp: - * for line in fp: # <<<<<<<<<<<<<< - * fname, value = line.split() - * self.weights[fname.strip()] = float(value) + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":24 + * def __get__(self): + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) # <<<<<<<<<<<<<< + * return fmap + * */ - if (PyList_CheckExact(__pyx_v_fp) || PyTuple_CheckExact(__pyx_v_fp)) { - __pyx_t_4 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; - } else { - __pyx_t_2 = __pyx_t_9(__pyx_t_4); - if (unlikely(!__pyx_t_2)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF(__pyx_v_line); - __pyx_v_line = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_v_fmap->vector = new FastSparseVector(__pyx_v_self->candidate->fmap); - /* "_cdec.pyx":33 - * with open(cfg) as fp: - * for line in fp: - * fname, value = line.split() # <<<<<<<<<<<<<< - * self.weights[fname.strip()] = float(value) + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":25 + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) + * return fmap # <<<<<<<<<<<<<< * + * cdef class SufficientStats: */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { - PyObject* sequence = __pyx_t_1; - if (likely(PyTuple_CheckExact(sequence))) { - 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 = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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 = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_10 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_11 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; - index = 0; __pyx_t_2 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_2)) goto __pyx_L18_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L18_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 = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - goto __pyx_L19_unpacking_done; - __pyx_L18_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 = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_L19_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_fname); - __pyx_v_fname = __pyx_t_2; - __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_v_value); - __pyx_v_value = __pyx_t_10; - __pyx_t_10 = 0; - - /* "_cdec.pyx":34 - * for line in fp: - * fname, value = line.split() - * self.weights[fname.strip()] = float(value) # <<<<<<<<<<<<<< - * - * def translate(self, sentence, grammar=None): - */ - __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 = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_1 = PyFloat_FromDouble(__pyx_t_13); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = PyObject_GetAttr(__pyx_v_fname, __pyx_n_s__strip); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_t_2, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L14_try_end; - __pyx_L7_error:; - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "_cdec.pyx":31 - * - * def read_weights(self, cfg): - * with open(cfg) as fp: # <<<<<<<<<<<<<< - * for line in fp: - * fname, value = line.split() - */ - /*except:*/ { - __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_1, &__pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __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 = 31; __pyx_clineno = __LINE__; goto __pyx_L9_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 = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __pyx_t_16 = (!__pyx_t_14); - if (__pyx_t_16) { - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_ErrRestore(__pyx_t_4, __pyx_t_1, __pyx_t_2); - __pyx_t_4 = 0; __pyx_t_1 = 0; __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - goto __pyx_L22; - } - __pyx_L22:; - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L8_exception_handled; - } - __pyx_L9_except_error:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - goto __pyx_L1_error; - __pyx_L8_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - __pyx_L14_try_end:; - } - } - /*finally:*/ { - if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_19, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - goto __pyx_L23; - __pyx_L3_error:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L1_error; - __pyx_L23:; - } + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_fmap)); + __pyx_r = ((PyObject *)__pyx_v_fmap); + 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_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Candidate.fmap.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_fp); - __Pyx_XDECREF(__pyx_v_line); - __Pyx_XDECREF(__pyx_v_fname); - __Pyx_XDECREF(__pyx_v_value); + __Pyx_XDECREF((PyObject *)__pyx_v_fmap); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_sentence = 0; - PyObject *__pyx_v_grammar = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sentence,&__pyx_n_s__grammar,0}; +static PyObject *__pyx_pw_5_cdec_9Candidate_5score_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9Candidate_5score_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("translate (wrapper)", 0); - { - PyObject* values[2] = {0,0}; + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9Candidate_5score___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":36 - * self.weights[fname.strip()] = float(value) +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":15 + * cdef class Candidate: + * cdef mteval.Candidate* candidate + * cdef public float score # <<<<<<<<<<<<<< * - * def translate(self, sentence, grammar=None): # <<<<<<<<<<<<<< - * if isinstance(sentence, unicode): - * inp = sentence.strip().encode('utf8') + * property words: */ - values[1] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sentence); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grammar); - if (value) { values[1] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "translate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_sentence = values[0]; - __pyx_v_grammar = values[1]; - } - 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 = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename); + +static PyObject *__pyx_pf_5_cdec_9Candidate_5score___get__(struct __pyx_obj_5_cdec_Candidate *__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("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->score); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_cdec.Candidate.score.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_7Decoder_6translate(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_sentence, __pyx_v_grammar); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_9Candidate_5score_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_5_cdec_9Candidate_5score_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9Candidate_5score_2__set__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self), ((PyObject *)__pyx_v_value)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_sentence, PyObject *__pyx_v_grammar) { - PyObject *__pyx_v_inp = NULL; - BasicObserver __pyx_v_observer; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hg = 0; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5_cdec_9Candidate_5score_2__set__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - char *__pyx_t_4; + float __pyx_t_1; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("translate", 0); - - /* "_cdec.pyx":37 - * - * def translate(self, sentence, grammar=None): - * if isinstance(sentence, unicode): # <<<<<<<<<<<<<< - * inp = sentence.strip().encode('utf8') - * elif isinstance(sentence, str): - */ - __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "_cdec.pyx":38 - * def translate(self, sentence, grammar=None): - * if isinstance(sentence, unicode): - * inp = sentence.strip().encode('utf8') # <<<<<<<<<<<<<< - * elif isinstance(sentence, str): - * inp = sentence.strip() - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_inp = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3; - } - - /* "_cdec.pyx":39 - * if isinstance(sentence, unicode): - * inp = sentence.strip().encode('utf8') - * elif isinstance(sentence, str): # <<<<<<<<<<<<<< - * inp = sentence.strip() - * elif isinstance(sentence, Lattice): - */ - __pyx_t_3 = ((PyObject *)((PyObject*)(&PyString_Type))); - __Pyx_INCREF(__pyx_t_3); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_2) { - - /* "_cdec.pyx":40 - * inp = sentence.strip().encode('utf8') - * elif isinstance(sentence, str): - * inp = sentence.strip() # <<<<<<<<<<<<<< - * elif isinstance(sentence, Lattice): - * inp = str(sentence) # PLF format - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_inp = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L3; - } + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __pyx_PyFloat_AsFloat(__pyx_v_value); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->score = __pyx_t_1; - /* "_cdec.pyx":41 - * elif isinstance(sentence, str): - * inp = sentence.strip() - * elif isinstance(sentence, Lattice): # <<<<<<<<<<<<<< - * inp = str(sentence) # PLF format - * else: - */ - __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Candidate.score.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":42 - * inp = sentence.strip() - * elif isinstance(sentence, Lattice): - * inp = str(sentence) # PLF format # <<<<<<<<<<<<<< - * else: - * raise TypeError('Cannot translate input type %s' % type(sentence)) - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_sentence); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_sentence); - __Pyx_GIVEREF(__pyx_v_sentence); - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_v_inp = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3; - } - /*else*/ { +/* Python wrapper */ +static void __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_15SufficientStats___dealloc__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} - /* "_cdec.pyx":44 - * inp = str(sentence) # PLF format - * else: - * raise TypeError('Cannot translate input type %s' % type(sentence)) # <<<<<<<<<<<<<< - * if grammar: - * self.dec.SetSentenceGrammarFromString(string( grammar)) +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":31 + * cdef mteval.EvaluationMetric* metric + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.stats + * */ - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_21), ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 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 = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L3:; - /* "_cdec.pyx":45 - * else: - * raise TypeError('Cannot translate input type %s' % type(sentence)) - * if grammar: # <<<<<<<<<<<<<< - * self.dec.SetSentenceGrammarFromString(string( grammar)) - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_grammar); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_2) { +static void __pyx_pf_5_cdec_15SufficientStats___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "_cdec.pyx":46 - * raise TypeError('Cannot translate input type %s' % type(sentence)) - * if grammar: - * self.dec.SetSentenceGrammarFromString(string( grammar)) # <<<<<<<<<<<<<< - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - * self.dec.Decode(string(inp), &observer) + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":32 + * + * def __dealloc__(self): + * del self.stats # <<<<<<<<<<<<<< + * + * property score: */ - __pyx_t_4 = PyBytes_AsString(__pyx_v_grammar); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->dec->SetSentenceGrammarFromString(std::string(((char *)__pyx_t_4))); - goto __pyx_L4; - } - __pyx_L4:; + delete __pyx_v_self->stats; - /* "_cdec.pyx":47 - * if grammar: - * self.dec.SetSentenceGrammarFromString(string( grammar)) - * cdef decoder.BasicObserver observer = decoder.BasicObserver() # <<<<<<<<<<<<<< - * self.dec.Decode(string(inp), &observer) - * if observer.hypergraph == NULL: - */ - __pyx_v_observer = BasicObserver(); + __Pyx_RefNannyFinishContext(); +} - /* "_cdec.pyx":48 - * self.dec.SetSentenceGrammarFromString(string( grammar)) - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - * self.dec.Decode(string(inp), &observer) # <<<<<<<<<<<<<< - * if observer.hypergraph == NULL: - * raise ParseFailed() - */ - __pyx_t_4 = PyBytes_AsString(__pyx_v_inp); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->dec->Decode(std::string(((char *)__pyx_t_4)), (&__pyx_v_observer)); +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_5score_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_5score_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_5score___get__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":49 - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - * self.dec.Decode(string(inp), &observer) - * if observer.hypergraph == NULL: # <<<<<<<<<<<<<< - * raise ParseFailed() - * cdef Hypergraph hg = Hypergraph() +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":35 + * + * property score: + * def __get__(self): # <<<<<<<<<<<<<< + * return self.metric.ComputeScore(self.stats[0]) + * */ - __pyx_t_2 = (__pyx_v_observer.hypergraph == NULL); - if (__pyx_t_2) { - /* "_cdec.pyx":50 - * self.dec.Decode(string(inp), &observer) - * if observer.hypergraph == NULL: - * raise ParseFailed() # <<<<<<<<<<<<<< - * cdef Hypergraph hg = Hypergraph() - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) - */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__ParseFailed); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L5; - } - __pyx_L5:; +static PyObject *__pyx_pf_5_cdec_15SufficientStats_5score___get__(struct __pyx_obj_5_cdec_SufficientStats *__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("__get__", 0); - /* "_cdec.pyx":51 - * if observer.hypergraph == NULL: - * raise ParseFailed() - * cdef Hypergraph hg = Hypergraph() # <<<<<<<<<<<<<< - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) - * return hg + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":36 + * property score: + * def __get__(self): + * return self.metric.ComputeScore(self.stats[0]) # <<<<<<<<<<<<<< + * + * property detail: */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Hypergraph)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->metric->ComputeScore((__pyx_v_self->stats[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_v_hg = ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_t_1); + __pyx_r = __pyx_t_1; __pyx_t_1 = 0; - - /* "_cdec.pyx":52 - * raise ParseFailed() - * cdef Hypergraph hg = Hypergraph() - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) # <<<<<<<<<<<<<< - * return hg - */ - __pyx_v_hg->hg = new Hypergraph((__pyx_v_observer.hypergraph[0])); - - /* "_cdec.pyx":53 - * cdef Hypergraph hg = Hypergraph() - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) - * return hg # <<<<<<<<<<<<<< - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_hg)); - __pyx_r = ((PyObject *)__pyx_v_hg); 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_3); - __Pyx_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.SufficientStats.score.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_inp); - __Pyx_XDECREF((PyObject *)__pyx_v_hg); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights___get__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_6detail___get__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":17 - * cdef class Decoder: - * cdef decoder.Decoder* dec - * cdef public DenseVector weights # <<<<<<<<<<<<<< +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":39 + * + * property detail: + * def __get__(self): # <<<<<<<<<<<<<< + * return self.metric.DetailedScore(self.stats[0]).c_str() * - * def __cinit__(self, char* config): */ -static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_15SufficientStats_6detail___get__(struct __pyx_obj_5_cdec_SufficientStats *__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("__get__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":40 + * property detail: + * def __get__(self): + * return self.metric.DetailedScore(self.stats[0]).c_str() # <<<<<<<<<<<<<< + * + * def __len__(self): + */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self->weights)); - __pyx_r = ((PyObject *)__pyx_v_self->weights); + __pyx_t_1 = PyBytes_FromString(__pyx_v_self->metric->DetailedScore((__pyx_v_self->stats[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __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.SufficientStats.detail.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); @@ -5779,101 +6059,3402 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cd } /* Python wrapper */ -static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +static Py_ssize_t __pyx_pw_5_cdec_15SufficientStats_3__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_15SufficientStats_3__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_2__set__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_2__len__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":42 + * return self.metric.DetailedScore(self.stats[0]).c_str() + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.stats.size() + * + */ + +static Py_ssize_t __pyx_pf_5_cdec_15SufficientStats_2__len__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":43 + * + * def __len__(self): + * return self.stats.size() # <<<<<<<<<<<<<< + * + * def __iter__(self): + */ + __pyx_r = __pyx_v_self->stats->size(); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator7(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_5__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_5__iter__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_4__iter__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":45 + * return self.stats.size() + * + * def __iter__(self): # <<<<<<<<<<<<<< + * for i in range(len(self)): + * yield self.stats[0][i] + */ + +static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *__pyx_cur_scope; + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__set__", 0); - if (!(likely(((__pyx_v_value) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_value, __pyx_ptype_5_cdec_DenseVector))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(__pyx_v_self->weights); - __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); - __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_value); + __Pyx_RefNannySetupContext("__iter__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_7___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_7___iter__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_15SufficientStats_6generator7, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } - __pyx_r = 0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Decoder.weights.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_AddTraceback("_cdec.SufficientStats.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator7(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *(*__pyx_t_4)(PyObject *); + unsigned int __pyx_t_5; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":46 + * + * def __iter__(self): + * for i in range(len(self)): # <<<<<<<<<<<<<< + * yield self.stats[0][i] + * + */ + __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_1 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { + if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_3)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { + if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; + } else { + __pyx_t_2 = __pyx_t_4(__pyx_t_3); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_i); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_i); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":47 + * def __iter__(self): + * for i in range(len(self)): + * yield self.stats[0][i] # <<<<<<<<<<<<<< + * + * def __iadd__(SufficientStats self, SufficientStats other): + */ + __pyx_t_5 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_i); if (unlikely((__pyx_t_5 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyFloat_FromDouble(((__pyx_cur_scope->__pyx_v_self->stats[0])[__pyx_t_5])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __Pyx_XGIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_t_3); + __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} + /* Python wrapper */ -static int __pyx_pw_5_cdec_7Decoder_7weights_5__del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pw_5_cdec_7Decoder_7weights_5__del__(PyObject *__pyx_v_self) { - int __pyx_r; +static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_4__del__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__iadd__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SufficientStats, 1, "other", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_7__iadd__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_other)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5_cdec_7Decoder_7weights_4__del__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { - int __pyx_r; +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":49 + * yield self.stats[0][i] + * + * def __iadd__(SufficientStats self, SufficientStats other): # <<<<<<<<<<<<<< + * self.stats[0] += other.stats[0] + * return self + */ + +static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__iadd__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_other) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__", 0); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->weights); - __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); - __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); + __Pyx_RefNannySetupContext("__iadd__", 0); - __pyx_r = 0; + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":50 + * + * def __iadd__(SufficientStats self, SufficientStats other): + * self.stats[0] += other.stats[0] # <<<<<<<<<<<<<< + * return self + * + */ + (__pyx_v_self->stats[0]) += (__pyx_v_other->stats[0]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":51 + * def __iadd__(SufficientStats self, SufficientStats other): + * self.stats[0] += other.stats[0] + * return self # <<<<<<<<<<<<<< + * + * def __add__(SufficientStats x, SufficientStats y): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_10__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_10__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__add__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SufficientStats, 1, "x", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SufficientStats, 1, "y", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_9__add__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_y)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_tp_new_5_cdec_DenseVector(PyTypeObject *t, PyObject *a, PyObject *k) { +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":53 + * return self + * + * def __add__(SufficientStats x, SufficientStats y): # <<<<<<<<<<<<<< + * cdef SufficientStats result = SufficientStats() + * result.stats = new mteval.SufficientStats(mteval.add(x.stats[0], y.stats[0])) + */ + +static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_x, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_y) { + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_result = 0; + 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("__add__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":54 + * + * def __add__(SufficientStats x, SufficientStats y): + * cdef SufficientStats result = SufficientStats() # <<<<<<<<<<<<<< + * result.stats = new mteval.SufficientStats(mteval.add(x.stats[0], y.stats[0])) + * result.metric = x.metric + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":55 + * def __add__(SufficientStats x, SufficientStats y): + * cdef SufficientStats result = SufficientStats() + * result.stats = new mteval.SufficientStats(mteval.add(x.stats[0], y.stats[0])) # <<<<<<<<<<<<<< + * result.metric = x.metric + * return result + */ + __pyx_v_result->stats = new SufficientStats(operator+((__pyx_v_x->stats[0]), (__pyx_v_y->stats[0]))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":56 + * cdef SufficientStats result = SufficientStats() + * result.stats = new mteval.SufficientStats(mteval.add(x.stats[0], y.stats[0])) + * result.metric = x.metric # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_v_result->metric = __pyx_v_x->metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":57 + * result.stats = new mteval.SufficientStats(mteval.add(x.stats[0], y.stats[0])) + * result.metric = x.metric + * return result # <<<<<<<<<<<<<< + * + * cdef class SegmentEvaluator: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + 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.SufficientStats.__add__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":63 + * cdef mteval.EvaluationMetric* metric + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.scorer + * + */ + +static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":64 + * + * def __dealloc__(self): + * del self.scorer # <<<<<<<<<<<<<< + * + * def evaluate(self, sentence): + */ + delete __pyx_v_self->scorer; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence); /*proto*/ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("evaluate (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self), ((PyObject *)__pyx_v_sentence)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":66 + * del self.scorer + * + * def evaluate(self, sentence): # <<<<<<<<<<<<<< + * cdef vector[WordID] hyp + * cdef SufficientStats sf = SufficientStats() + */ + +static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, PyObject *__pyx_v_sentence) { + std::vector __pyx_v_hyp; + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sf = 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("evaluate", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":68 + * def evaluate(self, sentence): + * cdef vector[WordID] hyp + * cdef SufficientStats sf = SufficientStats() # <<<<<<<<<<<<<< + * sf.metric = self.metric + * sf.stats = new mteval.SufficientStats() + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sf = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":69 + * cdef vector[WordID] hyp + * cdef SufficientStats sf = SufficientStats() + * sf.metric = self.metric # <<<<<<<<<<<<<< + * sf.stats = new mteval.SufficientStats() + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + */ + __pyx_v_sf->metric = __pyx_v_self->metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":70 + * cdef SufficientStats sf = SufficientStats() + * sf.metric = self.metric + * sf.stats = new mteval.SufficientStats() # <<<<<<<<<<<<<< + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + * self.scorer.get().Evaluate(hyp, sf.stats) + */ + __pyx_v_sf->stats = new SufficientStats(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":71 + * sf.metric = self.metric + * sf.stats = new mteval.SufficientStats() + * ConvertSentence(string(as_str(sentence.strip())), &hyp) # <<<<<<<<<<<<<< + * self.scorer.get().Evaluate(hyp, sf.stats) + * return sf + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_2, NULL)), (&__pyx_v_hyp)); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":72 + * sf.stats = new mteval.SufficientStats() + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + * self.scorer.get().Evaluate(hyp, sf.stats) # <<<<<<<<<<<<<< + * return sf + * + */ + __pyx_v_self->scorer->get()->Evaluate(__pyx_v_hyp, __pyx_v_sf->stats); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":73 + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + * self.scorer.get().Evaluate(hyp, sf.stats) + * return sf # <<<<<<<<<<<<<< + * + * def candidate_set(self, Hypergraph hypergraph, unsigned k): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_sf)); + __pyx_r = ((PyObject *)__pyx_v_sf); + 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.SegmentEvaluator.evaluate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_sf); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_5_cdec_16SegmentEvaluator_6generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph = 0; + unsigned int __pyx_v_k; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__hypergraph,&__pyx_n_s__k,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("candidate_set (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__hypergraph); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("candidate_set", 1, 2, 2, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "candidate_set") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_hypergraph = ((struct __pyx_obj_5_cdec_Hypergraph *)values[0]); + __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("candidate_set", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.SegmentEvaluator.candidate_set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_hypergraph), __pyx_ptype_5_cdec_Hypergraph, 1, "hypergraph", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self), __pyx_v_hypergraph, __pyx_v_k); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":75 + * return sf + * + * def candidate_set(self, Hypergraph hypergraph, unsigned k): # <<<<<<<<<<<<<< + * cdef mteval.CandidateSet* cs = new mteval.CandidateSet() + * cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) + */ + +static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph, unsigned int __pyx_v_k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("candidate_set", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)__pyx_ptype_5_cdec___pyx_scope_struct_8_candidate_set->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_8_candidate_set, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __pyx_cur_scope->__pyx_v_hypergraph = __pyx_v_hypergraph; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_hypergraph); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_hypergraph); + __pyx_cur_scope->__pyx_v_k = __pyx_v_k; + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_16SegmentEvaluator_6generator8, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.SegmentEvaluator.candidate_set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5_cdec_16SegmentEvaluator_6generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + unsigned int __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":76 + * + * def candidate_set(self, Hypergraph hypergraph, unsigned k): + * cdef mteval.CandidateSet* cs = new mteval.CandidateSet() # <<<<<<<<<<<<<< + * cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) + * cdef Candidate candidate + */ + __pyx_cur_scope->__pyx_v_cs = new training::CandidateSet(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":77 + * def candidate_set(self, Hypergraph hypergraph, unsigned k): + * cdef mteval.CandidateSet* cs = new mteval.CandidateSet() + * cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) # <<<<<<<<<<<<<< + * cdef Candidate candidate + * cdef unsigned i + */ + __pyx_cur_scope->__pyx_v_cs->AddKBestCandidates((__pyx_cur_scope->__pyx_v_hypergraph->hg[0]), __pyx_cur_scope->__pyx_v_k, __pyx_cur_scope->__pyx_v_self->scorer->get()); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":80 + * cdef Candidate candidate + * cdef unsigned i + * for i in range(cs.size()): # <<<<<<<<<<<<<< + * candidate = Candidate() + * candidate.candidate = &cs[0][i] + */ + __pyx_t_1 = __pyx_cur_scope->__pyx_v_cs->size(); + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":81 + * cdef unsigned i + * for i in range(cs.size()): + * candidate = Candidate() # <<<<<<<<<<<<<< + * candidate.candidate = &cs[0][i] + * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) + */ + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Candidate)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_candidate)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_candidate)); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_candidate = ((struct __pyx_obj_5_cdec_Candidate *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 + * for i in range(cs.size()): + * candidate = Candidate() + * candidate.candidate = &cs[0][i] # <<<<<<<<<<<<<< + * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) + * yield candidate + */ + __pyx_cur_scope->__pyx_v_candidate->candidate = (&((__pyx_cur_scope->__pyx_v_cs[0])[__pyx_cur_scope->__pyx_v_i])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":83 + * candidate = Candidate() + * candidate.candidate = &cs[0][i] + * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) # <<<<<<<<<<<<<< + * yield candidate + * del cs + */ + __pyx_cur_scope->__pyx_v_candidate->score = __pyx_cur_scope->__pyx_v_self->metric->ComputeScore(((__pyx_cur_scope->__pyx_v_cs[0])[__pyx_cur_scope->__pyx_v_i]).eval_feats); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":84 + * candidate.candidate = &cs[0][i] + * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) + * yield candidate # <<<<<<<<<<<<<< + * del cs + * + */ + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_candidate)); + __pyx_r = ((PyObject *)__pyx_cur_scope->__pyx_v_candidate); + __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_generator->resume_label = 1; + return __pyx_r; + __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[4]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":85 + * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) + * yield candidate + * del cs # <<<<<<<<<<<<<< + * + * cdef class Scorer: + */ + delete __pyx_cur_scope->__pyx_v_cs; + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("candidate_set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + char *__pyx_v_name; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__name,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__name); + 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __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_name = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __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[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.Scorer.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_6Scorer___cinit__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self), __pyx_v_name); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":90 + * cdef string* name + * + * def __cinit__(self, char* name): # <<<<<<<<<<<<<< + * self.name = new string(name) + * + */ + +static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, char *__pyx_v_name) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":91 + * + * def __cinit__(self, char* name): + * self.name = new string(name) # <<<<<<<<<<<<<< + * + * def __call__(self, refs): + */ + __pyx_v_self->name = new std::string(__pyx_v_name); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_6Scorer_3__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_6Scorer_3__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_refs = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__refs,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__call__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__refs); + 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, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 93; __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_refs = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.Scorer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_6Scorer_2__call__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self), __pyx_v_refs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":93 + * self.name = new string(name) + * + * def __call__(self, refs): # <<<<<<<<<<<<<< + * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) + * if isinstance(refs, unicode) or isinstance(refs, str): + */ + +static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs) { + EvaluationMetric *__pyx_v_metric; + std::vector > *__pyx_v_refsv; + std::vector *__pyx_v_refv; + PyObject *__pyx_v_ref = NULL; + struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + Py_ssize_t __pyx_t_5; + PyObject *(*__pyx_t_6)(PyObject *); + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__call__", 0); + __Pyx_INCREF(__pyx_v_refs); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":94 + * + * def __call__(self, refs): + * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) # <<<<<<<<<<<<<< + * if isinstance(refs, unicode) or isinstance(refs, str): + * refs = [refs] + */ + __pyx_v_metric = EvaluationMetric::Instance((__pyx_v_self->name[0])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":95 + * def __call__(self, refs): + * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) + * if isinstance(refs, unicode) or isinstance(refs, str): # <<<<<<<<<<<<<< + * refs = [refs] + * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_refs, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!__pyx_t_2) { + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyString_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_refs, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_2; + } + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":96 + * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) + * if isinstance(refs, unicode) or isinstance(refs, str): + * refs = [refs] # <<<<<<<<<<<<<< + * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() + * cdef vector[WordID]* refv + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_refs); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_refs); + __Pyx_GIVEREF(__pyx_v_refs); + __Pyx_DECREF(__pyx_v_refs); + __pyx_v_refs = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":97 + * if isinstance(refs, unicode) or isinstance(refs, str): + * refs = [refs] + * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() # <<<<<<<<<<<<<< + * cdef vector[WordID]* refv + * cdef bytes ref_str + */ + __pyx_v_refsv = new std::vector >(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":100 + * cdef vector[WordID]* refv + * cdef bytes ref_str + * for ref in refs: # <<<<<<<<<<<<<< + * refv = new vector[WordID]() + * ConvertSentence(string(as_str(ref.strip())), refv) + */ + if (PyList_CheckExact(__pyx_v_refs) || PyTuple_CheckExact(__pyx_v_refs)) { + __pyx_t_1 = __pyx_v_refs; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0; + __pyx_t_6 = NULL; + } else { + __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_refs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; + } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; + } else { + __pyx_t_7 = __pyx_t_6(__pyx_t_1); + if (unlikely(!__pyx_t_7)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_7); + } + __Pyx_XDECREF(__pyx_v_ref); + __pyx_v_ref = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":101 + * cdef bytes ref_str + * for ref in refs: + * refv = new vector[WordID]() # <<<<<<<<<<<<<< + * ConvertSentence(string(as_str(ref.strip())), refv) + * refsv.push_back(refv[0]) + */ + __pyx_v_refv = new std::vector(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":102 + * for ref in refs: + * refv = new vector[WordID]() + * ConvertSentence(string(as_str(ref.strip())), refv) # <<<<<<<<<<<<<< + * refsv.push_back(refv[0]) + * del refv + */ + __pyx_t_7 = PyObject_GetAttr(__pyx_v_ref, __pyx_n_s__strip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_8, NULL)), __pyx_v_refv); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":103 + * refv = new vector[WordID]() + * ConvertSentence(string(as_str(ref.strip())), refv) + * refsv.push_back(refv[0]) # <<<<<<<<<<<<<< + * del refv + * cdef unsigned i + */ + __pyx_v_refsv->push_back((__pyx_v_refv[0])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":104 + * ConvertSentence(string(as_str(ref.strip())), refv) + * refsv.push_back(refv[0]) + * del refv # <<<<<<<<<<<<<< + * cdef unsigned i + * cdef SegmentEvaluator evaluator = SegmentEvaluator() + */ + delete __pyx_v_refv; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":106 + * del refv + * cdef unsigned i + * cdef SegmentEvaluator evaluator = SegmentEvaluator() # <<<<<<<<<<<<<< + * evaluator.metric = metric + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SegmentEvaluator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_evaluator = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":107 + * cdef unsigned i + * cdef SegmentEvaluator evaluator = SegmentEvaluator() + * evaluator.metric = metric # <<<<<<<<<<<<<< + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + * del refsv # in theory should not delete but store in SegmentEvaluator + */ + __pyx_v_evaluator->metric = __pyx_v_metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":108 + * cdef SegmentEvaluator evaluator = SegmentEvaluator() + * evaluator.metric = metric + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) # <<<<<<<<<<<<<< + * del refsv # in theory should not delete but store in SegmentEvaluator + * return evaluator + */ + __pyx_v_evaluator->scorer = new boost::shared_ptr(__pyx_v_metric->CreateSegmentEvaluator((__pyx_v_refsv[0]))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":109 + * evaluator.metric = metric + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + * del refsv # in theory should not delete but store in SegmentEvaluator # <<<<<<<<<<<<<< + * return evaluator + * + */ + delete __pyx_v_refsv; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":110 + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + * del refsv # in theory should not delete but store in SegmentEvaluator + * return evaluator # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_evaluator)); + __pyx_r = ((PyObject *)__pyx_v_evaluator); + 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_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_cdec.Scorer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_ref); + __Pyx_XDECREF((PyObject *)__pyx_v_evaluator); + __Pyx_XDECREF(__pyx_v_refs); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_6Scorer_5__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_6Scorer_5__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_6Scorer_4__str__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":112 + * return evaluator + * + * def __str__(self): # <<<<<<<<<<<<<< + * return self.name.c_str() + * + */ + +static PyObject *__pyx_pf_5_cdec_6Scorer_4__str__(struct __pyx_obj_5_cdec_Scorer *__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__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":113 + * + * def __str__(self): + * return self.name.c_str() # <<<<<<<<<<<<<< + * + * BLEU = Scorer('IBM_BLEU') + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(__pyx_v_self->name->c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 113; __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.Scorer.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + char *__pyx_v_config; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__config,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__config); + 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __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 = 19; __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 = 19; __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:; + __pyx_r = __pyx_pf_5_cdec_7Decoder___cinit__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_config); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":19 + * cdef public DenseVector weights + * + * def __cinit__(self, char* config): # <<<<<<<<<<<<<< + * decoder.register_feature_functions() + * cdef istringstream* config_stream = new istringstream(config) + */ + +static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, char *__pyx_v_config) { + std::istringstream *__pyx_v_config_stream; + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "_cdec.pyx":20 + * + * def __cinit__(self, char* config): + * decoder.register_feature_functions() # <<<<<<<<<<<<<< + * cdef istringstream* config_stream = new istringstream(config) + * self.dec = new decoder.Decoder(config_stream) + */ + register_feature_functions(); + + /* "_cdec.pyx":21 + * def __cinit__(self, char* config): + * decoder.register_feature_functions() + * cdef istringstream* config_stream = new istringstream(config) # <<<<<<<<<<<<<< + * self.dec = new decoder.Decoder(config_stream) + * del config_stream + */ + __pyx_v_config_stream = new std::istringstream(__pyx_v_config); + + /* "_cdec.pyx":22 + * decoder.register_feature_functions() + * cdef istringstream* config_stream = new istringstream(config) + * self.dec = new decoder.Decoder(config_stream) # <<<<<<<<<<<<<< + * del config_stream + * self.weights = DenseVector() + */ + __pyx_v_self->dec = new Decoder(__pyx_v_config_stream); + + /* "_cdec.pyx":23 + * cdef istringstream* config_stream = new istringstream(config) + * self.dec = new decoder.Decoder(config_stream) + * del config_stream # <<<<<<<<<<<<<< + * self.weights = DenseVector() + * self.weights.vector = &self.dec.CurrentWeightVector() + */ + delete __pyx_v_config_stream; + + /* "_cdec.pyx":24 + * self.dec = new decoder.Decoder(config_stream) + * del config_stream + * self.weights = DenseVector() # <<<<<<<<<<<<<< + * self.weights.vector = &self.dec.CurrentWeightVector() + * + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->weights); + __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); + __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "_cdec.pyx":25 + * del config_stream + * self.weights = DenseVector() + * self.weights.vector = &self.dec.CurrentWeightVector() # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->weights->vector = (&__pyx_v_self->dec->CurrentWeightVector()); + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.Decoder.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_7Decoder_2__dealloc__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "_cdec.pyx":27 + * self.weights.vector = &self.dec.CurrentWeightVector() + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.dec + * + */ + +static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "_cdec.pyx":28 + * + * def __dealloc__(self): + * del self.dec # <<<<<<<<<<<<<< + * + * def read_weights(self, cfg): + */ + delete __pyx_v_self->dec; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_cfg); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_cfg) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_weights (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_4read_weights(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_cfg)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":30 + * del self.dec + * + * def read_weights(self, cfg): # <<<<<<<<<<<<<< + * with open(cfg) as fp: + * for line in fp: + */ + +static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_cfg) { + PyObject *__pyx_v_fp = NULL; + PyObject *__pyx_v_line = NULL; + PyObject *__pyx_v_fname = NULL; + PyObject *__pyx_v_value = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *(*__pyx_t_12)(PyObject *); + double __pyx_t_13; + int __pyx_t_14; + PyObject *__pyx_t_15 = NULL; + int __pyx_t_16; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_weights", 0); + + /* "_cdec.pyx":31 + * + * def read_weights(self, cfg): + * with open(cfg) as fp: # <<<<<<<<<<<<<< + * for line in fp: + * fname, value = line.split() + */ + /*with:*/ { + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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 = 31; __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 = 31; __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 = 31; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_fp = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_cdec.pyx":32 + * def read_weights(self, cfg): + * with open(cfg) as fp: + * for line in fp: # <<<<<<<<<<<<<< + * fname, value = line.split() + * self.weights[fname.strip()] = float(value) + */ + if (PyList_CheckExact(__pyx_v_fp) || PyTuple_CheckExact(__pyx_v_fp)) { + __pyx_t_4 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else { + __pyx_t_2 = __pyx_t_9(__pyx_t_4); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF(__pyx_v_line); + __pyx_v_line = __pyx_t_2; + __pyx_t_2 = 0; + + /* "_cdec.pyx":33 + * with open(cfg) as fp: + * for line in fp: + * fname, value = line.split() # <<<<<<<<<<<<<< + * self.weights[fname.strip()] = float(value) + * + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { + PyObject* sequence = __pyx_t_1; + if (likely(PyTuple_CheckExact(sequence))) { + 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 = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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 = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + __pyx_t_2 = PyList_GET_ITEM(sequence, 0); + __pyx_t_10 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_11 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; + index = 0; __pyx_t_2 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_2)) goto __pyx_L18_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L18_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 = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L19_unpacking_done; + __pyx_L18_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 = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_L19_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_fname); + __pyx_v_fname = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_v_value); + __pyx_v_value = __pyx_t_10; + __pyx_t_10 = 0; + + /* "_cdec.pyx":34 + * for line in fp: + * fname, value = line.split() + * self.weights[fname.strip()] = float(value) # <<<<<<<<<<<<<< + * + * def translate(self, sentence, grammar=None): + */ + __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 = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyFloat_FromDouble(__pyx_t_13); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = PyObject_GetAttr(__pyx_v_fname, __pyx_n_s__strip); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_t_2, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_cdec.pyx":31 + * + * def read_weights(self, cfg): + * with open(cfg) as fp: # <<<<<<<<<<<<<< + * for line in fp: + * fname, value = line.split() + */ + /*except:*/ { + __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_1, &__pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __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 = 31; __pyx_clineno = __LINE__; goto __pyx_L9_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 = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_16 = (!__pyx_t_14); + if (__pyx_t_16) { + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_ErrRestore(__pyx_t_4, __pyx_t_1, __pyx_t_2); + __pyx_t_4 = 0; __pyx_t_1 = 0; __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L22; + } + __pyx_L22:; + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_21, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L23; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L23:; + } + + __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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_fp); + __Pyx_XDECREF(__pyx_v_line); + __Pyx_XDECREF(__pyx_v_fname); + __Pyx_XDECREF(__pyx_v_value); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_sentence = 0; + PyObject *__pyx_v_grammar = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sentence,&__pyx_n_s__grammar,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("translate (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + + /* "_cdec.pyx":36 + * self.weights[fname.strip()] = float(value) + * + * def translate(self, sentence, grammar=None): # <<<<<<<<<<<<<< + * if isinstance(sentence, unicode): + * inp = sentence.strip().encode('utf8') + */ + values[1] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sentence); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grammar); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "translate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_sentence = values[0]; + __pyx_v_grammar = values[1]; + } + 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 = 36; __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:; + __pyx_r = __pyx_pf_5_cdec_7Decoder_6translate(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_sentence, __pyx_v_grammar); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_sentence, PyObject *__pyx_v_grammar) { + PyObject *__pyx_v_inp = NULL; + BasicObserver __pyx_v_observer; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hg = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + char *__pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("translate", 0); + + /* "_cdec.pyx":37 + * + * def translate(self, sentence, grammar=None): + * if isinstance(sentence, unicode): # <<<<<<<<<<<<<< + * inp = sentence.strip().encode('utf8') + * elif isinstance(sentence, str): + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":38 + * def translate(self, sentence, grammar=None): + * if isinstance(sentence, unicode): + * inp = sentence.strip().encode('utf8') # <<<<<<<<<<<<<< + * elif isinstance(sentence, str): + * inp = sentence.strip() + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_22), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_inp = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3; + } + + /* "_cdec.pyx":39 + * if isinstance(sentence, unicode): + * inp = sentence.strip().encode('utf8') + * elif isinstance(sentence, str): # <<<<<<<<<<<<<< + * inp = sentence.strip() + * elif isinstance(sentence, Lattice): + */ + __pyx_t_3 = ((PyObject *)((PyObject*)(&PyString_Type))); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":40 + * inp = sentence.strip().encode('utf8') + * elif isinstance(sentence, str): + * inp = sentence.strip() # <<<<<<<<<<<<<< + * elif isinstance(sentence, Lattice): + * inp = str(sentence) # PLF format + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_inp = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L3; + } + + /* "_cdec.pyx":41 + * elif isinstance(sentence, str): + * inp = sentence.strip() + * elif isinstance(sentence, Lattice): # <<<<<<<<<<<<<< + * inp = str(sentence) # PLF format + * else: + */ + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":42 + * inp = sentence.strip() + * elif isinstance(sentence, Lattice): + * inp = str(sentence) # PLF format # <<<<<<<<<<<<<< + * else: + * raise TypeError('Cannot translate input type %s' % type(sentence)) + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_sentence); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_sentence); + __Pyx_GIVEREF(__pyx_v_sentence); + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_v_inp = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "_cdec.pyx":44 + * inp = str(sentence) # PLF format + * else: + * raise TypeError('Cannot translate input type %s' % type(sentence)) # <<<<<<<<<<<<<< + * if grammar: + * self.dec.SetSentenceGrammarFromString(string( grammar)) + */ + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_23), ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 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 = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; + + /* "_cdec.pyx":45 + * else: + * raise TypeError('Cannot translate input type %s' % type(sentence)) + * if grammar: # <<<<<<<<<<<<<< + * self.dec.SetSentenceGrammarFromString(string( grammar)) + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_grammar); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "_cdec.pyx":46 + * raise TypeError('Cannot translate input type %s' % type(sentence)) + * if grammar: + * self.dec.SetSentenceGrammarFromString(string( grammar)) # <<<<<<<<<<<<<< + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + * self.dec.Decode(string(inp), &observer) + */ + __pyx_t_4 = PyBytes_AsString(__pyx_v_grammar); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->dec->SetSentenceGrammarFromString(std::string(((char *)__pyx_t_4))); + goto __pyx_L4; + } + __pyx_L4:; + + /* "_cdec.pyx":47 + * if grammar: + * self.dec.SetSentenceGrammarFromString(string( grammar)) + * cdef decoder.BasicObserver observer = decoder.BasicObserver() # <<<<<<<<<<<<<< + * self.dec.Decode(string(inp), &observer) + * if observer.hypergraph == NULL: + */ + __pyx_v_observer = BasicObserver(); + + /* "_cdec.pyx":48 + * self.dec.SetSentenceGrammarFromString(string( grammar)) + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + * self.dec.Decode(string(inp), &observer) # <<<<<<<<<<<<<< + * if observer.hypergraph == NULL: + * raise ParseFailed() + */ + __pyx_t_4 = PyBytes_AsString(__pyx_v_inp); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->dec->Decode(std::string(((char *)__pyx_t_4)), (&__pyx_v_observer)); + + /* "_cdec.pyx":49 + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + * self.dec.Decode(string(inp), &observer) + * if observer.hypergraph == NULL: # <<<<<<<<<<<<<< + * raise ParseFailed() + * cdef Hypergraph hg = Hypergraph() + */ + __pyx_t_2 = (__pyx_v_observer.hypergraph == NULL); + if (__pyx_t_2) { + + /* "_cdec.pyx":50 + * self.dec.Decode(string(inp), &observer) + * if observer.hypergraph == NULL: + * raise ParseFailed() # <<<<<<<<<<<<<< + * cdef Hypergraph hg = Hypergraph() + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__ParseFailed); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L5; + } + __pyx_L5:; + + /* "_cdec.pyx":51 + * if observer.hypergraph == NULL: + * raise ParseFailed() + * cdef Hypergraph hg = Hypergraph() # <<<<<<<<<<<<<< + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) + * return hg + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Hypergraph)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_hg = ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "_cdec.pyx":52 + * raise ParseFailed() + * cdef Hypergraph hg = Hypergraph() + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) # <<<<<<<<<<<<<< + * return hg + */ + __pyx_v_hg->hg = new Hypergraph((__pyx_v_observer.hypergraph[0])); + + /* "_cdec.pyx":53 + * cdef Hypergraph hg = Hypergraph() + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) + * return hg # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_hg)); + __pyx_r = ((PyObject *)__pyx_v_hg); + 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_3); + __Pyx_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_inp); + __Pyx_XDECREF((PyObject *)__pyx_v_hg); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights___get__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":17 + * cdef class Decoder: + * cdef decoder.Decoder* dec + * cdef public DenseVector weights # <<<<<<<<<<<<<< + * + * def __cinit__(self, char* config): + */ + +static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->weights)); + __pyx_r = ((PyObject *)__pyx_v_self->weights); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_2__set__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); + if (!(likely(((__pyx_v_value) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_value, __pyx_ptype_5_cdec_DenseVector))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->weights); + __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); + __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_value); + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Decoder.weights.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_7Decoder_7weights_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_5_cdec_7Decoder_7weights_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_4__del__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5_cdec_7Decoder_7weights_4__del__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->weights); + __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); + __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_tp_new_5_cdec_DenseVector(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_DenseVector(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_5_cdec_DenseVector(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_5_cdec_DenseVector(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_5_cdec_11DenseVector_3__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_DenseVector[] = { + {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_8dot, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("tosparse"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_10tosparse, METH_NOARGS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_DenseVector = { + 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_DenseVector = { + 0, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5_cdec_DenseVector, /*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_DenseVector = { + 0, /*mp_length*/ + __pyx_pw_5_cdec_11DenseVector_1__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5_cdec_DenseVector, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_DenseVector = { + #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_DenseVector = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.DenseVector"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_DenseVector), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_DenseVector, /*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_DenseVector, /*tp_as_number*/ + &__pyx_tp_as_sequence_DenseVector, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_DenseVector, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_DenseVector, /*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_pw_5_cdec_11DenseVector_5__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_DenseVector, /*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_DenseVector, /*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_SparseVector(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_SparseVector(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_5_cdec_SparseVector(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_5_cdec_SparseVector(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_5_cdec_12SparseVector_3__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_SparseVector[] = { + {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_8dot, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("todense"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_10todense, METH_NOARGS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_SparseVector = { + __pyx_pw_5_cdec_12SparseVector_26__add__, /*nb_add*/ + __pyx_pw_5_cdec_12SparseVector_28__sub__, /*nb_subtract*/ + __pyx_pw_5_cdec_12SparseVector_30__mul__, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 + __pyx_pw_5_cdec_12SparseVector_32__div__, /*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 + __pyx_pw_5_cdec_12SparseVector_18__iadd__, /*nb_inplace_add*/ + __pyx_pw_5_cdec_12SparseVector_20__isub__, /*nb_inplace_subtract*/ + __pyx_pw_5_cdec_12SparseVector_22__imul__, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + __pyx_pw_5_cdec_12SparseVector_24__idiv__, /*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_SparseVector = { + __pyx_pw_5_cdec_12SparseVector_14__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5_cdec_SparseVector, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + __pyx_pw_5_cdec_12SparseVector_16__contains__, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_SparseVector = { + __pyx_pw_5_cdec_12SparseVector_14__len__, /*mp_length*/ + __pyx_pw_5_cdec_12SparseVector_1__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5_cdec_SparseVector, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_SparseVector = { + #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_SparseVector = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.SparseVector"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_SparseVector), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_SparseVector, /*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_SparseVector, /*tp_as_number*/ + &__pyx_tp_as_sequence_SparseVector, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_SparseVector, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_SparseVector, /*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*/ + __pyx_pw_5_cdec_12SparseVector_12__richcmp__, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + __pyx_pw_5_cdec_12SparseVector_5__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_SparseVector, /*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_SparseVector, /*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_Hypergraph(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_Hypergraph(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_10Hypergraph_1__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_pw_5_cdec_10Hypergraph_3viterbi, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("viterbi_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_5viterbi_tree, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("viterbi_source_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_7viterbi_source_tree, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("viterbi_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_9viterbi_features, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("kbest"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_11kbest, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("kbest_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_14kbest_tree, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("kbest_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_17kbest_features, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("sample"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_20sample, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("intersect"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_23intersect, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("prune"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_25prune, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("lattice"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_27lattice, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("reweight"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_29reweight, METH_O, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Hypergraph = { + 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_Hypergraph = { + 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_Hypergraph = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = { + #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_Hypergraph = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.Hypergraph"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Hypergraph), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_Hypergraph, /*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_Hypergraph, /*tp_as_number*/ + &__pyx_tp_as_sequence_Hypergraph, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Hypergraph, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Hypergraph, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_Hypergraph, /*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_Hypergraph, /*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_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_pw_5_cdec_7Lattice_14__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_5_cdec_Lattice(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_5_cdec_Lattice(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_5_cdec_7Lattice_5__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +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 = { + __pyx_pw_5_cdec_7Lattice_7__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5_cdec_Lattice, /*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 = { + __pyx_pw_5_cdec_7Lattice_7__len__, /*mp_length*/ + __pyx_pw_5_cdec_7Lattice_3__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5_cdec_Lattice, /*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_pw_5_cdec_7Lattice_9__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_pw_5_cdec_7Lattice_11__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_pw_5_cdec_7Lattice_1__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_Candidate(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_Candidate(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} + +static PyObject *__pyx_getprop_5_cdec_9Candidate_words(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9Candidate_5words_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_9Candidate_fmap(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9Candidate_4fmap_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_9Candidate_score(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9Candidate_5score_1__get__(o); +} + +static int __pyx_setprop_5_cdec_9Candidate_score(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_9Candidate_5score_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_Candidate[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5_cdec_Candidate[] = { + {(char *)"words", __pyx_getprop_5_cdec_9Candidate_words, 0, 0, 0}, + {(char *)"fmap", __pyx_getprop_5_cdec_9Candidate_fmap, 0, 0, 0}, + {(char *)"score", __pyx_getprop_5_cdec_9Candidate_score, __pyx_setprop_5_cdec_9Candidate_score, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Candidate = { + 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_Candidate = { + 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_Candidate = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Candidate = { + #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_Candidate = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.Candidate"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Candidate), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_Candidate, /*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_Candidate, /*tp_as_number*/ + &__pyx_tp_as_sequence_Candidate, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Candidate, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Candidate, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_Candidate, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5_cdec_Candidate, /*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_Candidate, /*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_SufficientStats(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_SufficientStats(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} + +static PyObject *__pyx_getprop_5_cdec_15SufficientStats_score(PyObject *o, void *x) { + return __pyx_pw_5_cdec_15SufficientStats_5score_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_15SufficientStats_detail(PyObject *o, void *x) { + return __pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(o); +} + +static PyMethodDef __pyx_methods_5_cdec_SufficientStats[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5_cdec_SufficientStats[] = { + {(char *)"score", __pyx_getprop_5_cdec_15SufficientStats_score, 0, 0, 0}, + {(char *)"detail", __pyx_getprop_5_cdec_15SufficientStats_detail, 0, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_SufficientStats = { + __pyx_pw_5_cdec_15SufficientStats_10__add__, /*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 + __pyx_pw_5_cdec_15SufficientStats_8__iadd__, /*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_SufficientStats = { + __pyx_pw_5_cdec_15SufficientStats_3__len__, /*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_SufficientStats = { + __pyx_pw_5_cdec_15SufficientStats_3__len__, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_SufficientStats = { + #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_SufficientStats = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.SufficientStats"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_SufficientStats), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_SufficientStats, /*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_SufficientStats, /*tp_as_number*/ + &__pyx_tp_as_sequence_SufficientStats, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_SufficientStats, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_SufficientStats, /*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_pw_5_cdec_15SufficientStats_5__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_SufficientStats, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5_cdec_SufficientStats, /*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_SufficientStats, /*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_SegmentEvaluator(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_SegmentEvaluator(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_16SegmentEvaluator_1__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_SegmentEvaluator[] = { + {__Pyx_NAMESTR("evaluate"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("candidate_set"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_SegmentEvaluator = { + 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_SegmentEvaluator = { + 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_SegmentEvaluator = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_SegmentEvaluator = { + #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_SegmentEvaluator = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.SegmentEvaluator"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_SegmentEvaluator), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_SegmentEvaluator, /*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_SegmentEvaluator, /*tp_as_number*/ + &__pyx_tp_as_sequence_SegmentEvaluator, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_SegmentEvaluator, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_SegmentEvaluator, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_SegmentEvaluator, /*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_SegmentEvaluator, /*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_Scorer(PyTypeObject *t, PyObject *a, PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + if (__pyx_pw_5_cdec_6Scorer_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } return o; } -static void __pyx_tp_dealloc_5_cdec_DenseVector(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec_Scorer(PyObject *o) { (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_sq_item_5_cdec_DenseVector(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} - -static int __pyx_mp_ass_subscript_5_cdec_DenseVector(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_pw_5_cdec_11DenseVector_3__setitem__(o, i, v); - } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); - return -1; - } -} -static PyMethodDef __pyx_methods_5_cdec_DenseVector[] = { - {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_8dot, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("tosparse"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_10tosparse, METH_NOARGS, __Pyx_DOCSTR(0)}, +static PyMethodDef __pyx_methods_5_cdec_Scorer[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_DenseVector = { +static PyNumberMethods __pyx_tp_as_number_Scorer = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -5931,11 +9512,11 @@ static PyNumberMethods __pyx_tp_as_number_DenseVector = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_DenseVector = { +static PySequenceMethods __pyx_tp_as_sequence_Scorer = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_DenseVector, /*sq_item*/ + 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -5944,13 +9525,13 @@ static PySequenceMethods __pyx_tp_as_sequence_DenseVector = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_DenseVector = { +static PyMappingMethods __pyx_tp_as_mapping_Scorer = { 0, /*mp_length*/ - __pyx_pw_5_cdec_11DenseVector_1__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_5_cdec_DenseVector, /*mp_ass_subscript*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_DenseVector = { +static PyBufferProcs __pyx_tp_as_buffer_Scorer = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -5971,12 +9552,12 @@ static PyBufferProcs __pyx_tp_as_buffer_DenseVector = { #endif }; -static PyTypeObject __pyx_type_5_cdec_DenseVector = { +static PyTypeObject __pyx_type_5_cdec_Scorer = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.DenseVector"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_DenseVector), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.Scorer"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Scorer), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_DenseVector, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_Scorer, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -5986,24 +9567,24 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_DenseVector, /*tp_as_number*/ - &__pyx_tp_as_sequence_DenseVector, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_DenseVector, /*tp_as_mapping*/ + &__pyx_tp_as_number_Scorer, /*tp_as_number*/ + &__pyx_tp_as_sequence_Scorer, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Scorer, /*tp_as_mapping*/ 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ + __pyx_pw_5_cdec_6Scorer_3__call__, /*tp_call*/ + __pyx_pw_5_cdec_6Scorer_5__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_DenseVector, /*tp_as_buffer*/ + &__pyx_tp_as_buffer_Scorer, /*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_pw_5_cdec_11DenseVector_5__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_DenseVector, /*tp_methods*/ + __pyx_methods_5_cdec_Scorer, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -6013,7 +9594,7 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_DenseVector, /*tp_new*/ + __pyx_tp_new_5_cdec_Scorer, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -6027,43 +9608,78 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_SparseVector(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_Decoder(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec_Decoder *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + p = ((struct __pyx_obj_5_cdec_Decoder *)o); + p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_5_cdec_7Decoder_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } return o; } -static void __pyx_tp_dealloc_5_cdec_SparseVector(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec_Decoder(PyObject *o) { + struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_7Decoder_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + Py_XDECREF(((PyObject *)p->weights)); (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_sq_item_5_cdec_SparseVector(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; + +static int __pyx_tp_traverse_5_cdec_Decoder(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; + if (p->weights) { + e = (*v)(((PyObject*)p->weights), a); if (e) return e; + } + return 0; } -static int __pyx_mp_ass_subscript_5_cdec_SparseVector(PyObject *o, PyObject *i, PyObject *v) { +static int __pyx_tp_clear_5_cdec_Decoder(PyObject *o) { + struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; + PyObject* tmp; + tmp = ((PyObject*)p->weights); + p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_5_cdec_7Decoder_weights(PyObject *o, void *x) { + return __pyx_pw_5_cdec_7Decoder_7weights_1__get__(o); +} + +static int __pyx_setprop_5_cdec_7Decoder_weights(PyObject *o, PyObject *v, void *x) { if (v) { - return __pyx_pw_5_cdec_12SparseVector_3__setitem__(o, i, v); + return __pyx_pw_5_cdec_7Decoder_7weights_3__set__(o, v); } else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); - return -1; + return __pyx_pw_5_cdec_7Decoder_7weights_5__del__(o); } } -static PyMethodDef __pyx_methods_5_cdec_SparseVector[] = { - {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_8dot, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("todense"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_10todense, METH_NOARGS, __Pyx_DOCSTR(0)}, +static PyMethodDef __pyx_methods_5_cdec_Decoder[] = { + {__Pyx_NAMESTR("read_weights"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_5read_weights, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("translate"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_7translate, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_26__add__, /*nb_add*/ - __pyx_pw_5_cdec_12SparseVector_28__sub__, /*nb_subtract*/ +static struct PyGetSetDef __pyx_getsets_5_cdec_Decoder[] = { + {(char *)"weights", __pyx_getprop_5_cdec_7Decoder_weights, __pyx_setprop_5_cdec_7Decoder_weights, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Decoder = { + 0, /*nb_add*/ + 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ @@ -6097,11 +9713,11 @@ static PyNumberMethods __pyx_tp_as_number_SparseVector = { #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif - __pyx_pw_5_cdec_12SparseVector_18__iadd__, /*nb_inplace_add*/ - __pyx_pw_5_cdec_12SparseVector_20__isub__, /*nb_inplace_subtract*/ - __pyx_pw_5_cdec_12SparseVector_22__imul__, /*nb_inplace_multiply*/ + 0, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 - __pyx_pw_5_cdec_12SparseVector_24__idiv__, /*nb_inplace_divide*/ + 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ @@ -6119,26 +9735,26 @@ static PyNumberMethods __pyx_tp_as_number_SparseVector = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_14__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence_Decoder = { + 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_SparseVector, /*sq_item*/ + 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ - __pyx_pw_5_cdec_12SparseVector_16__contains__, /*sq_contains*/ + 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_14__len__, /*mp_length*/ - __pyx_pw_5_cdec_12SparseVector_1__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_5_cdec_SparseVector, /*mp_ass_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping_Decoder = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_SparseVector = { +static PyBufferProcs __pyx_tp_as_buffer_Decoder = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -6159,12 +9775,12 @@ static PyBufferProcs __pyx_tp_as_buffer_SparseVector = { #endif }; -static PyTypeObject __pyx_type_5_cdec_SparseVector = { +static PyTypeObject __pyx_type_5_cdec_Decoder = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.SparseVector"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_SparseVector), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.Decoder"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Decoder), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_SparseVector, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_Decoder, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -6174,26 +9790,26 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_SparseVector, /*tp_as_number*/ - &__pyx_tp_as_sequence_SparseVector, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_SparseVector, /*tp_as_mapping*/ + &__pyx_tp_as_number_Decoder, /*tp_as_number*/ + &__pyx_tp_as_sequence_Decoder, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Decoder, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_SparseVector, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer_Decoder, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - __pyx_pw_5_cdec_12SparseVector_12__richcmp__, /*tp_richcompare*/ + __pyx_tp_traverse_5_cdec_Decoder, /*tp_traverse*/ + __pyx_tp_clear_5_cdec_Decoder, /*tp_clear*/ + 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_12SparseVector_5__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_SparseVector, /*tp_methods*/ + __pyx_methods_5_cdec_Decoder, /*tp_methods*/ 0, /*tp_members*/ - 0, /*tp_getset*/ + __pyx_getsets_5_cdec_Decoder, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -6201,7 +9817,7 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_SparseVector, /*tp_new*/ + __pyx_tp_new_5_cdec_Decoder, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -6215,41 +9831,44 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Hypergraph(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct____iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o); + p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec_Hypergraph(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static PyMethodDef __pyx_methods_5_cdec_Hypergraph[] = { - {__Pyx_NAMESTR("viterbi"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_3viterbi, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("viterbi_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_5viterbi_tree, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("viterbi_source_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_7viterbi_source_tree, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("viterbi_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_9viterbi_features, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("kbest"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_11kbest, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("kbest_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_14kbest_tree, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("sample"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_17sample, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("intersect"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_20intersect, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("prune"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_22prune, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("lattice"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_24lattice, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("reweight"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_26reweight, METH_O, __Pyx_DOCSTR(0)}, +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct____iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_Hypergraph = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -6307,7 +9926,7 @@ static PyNumberMethods __pyx_tp_as_number_Hypergraph = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Hypergraph = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct____iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -6320,13 +9939,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Hypergraph = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Hypergraph = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct____iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -6347,12 +9966,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Hypergraph = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Hypergraph"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Hypergraph), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct____iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct____iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Hypergraph, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -6362,24 +9981,24 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Hypergraph, /*tp_as_number*/ - &__pyx_tp_as_sequence_Hypergraph, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Hypergraph, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct____iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct____iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct____iter__, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Hypergraph, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct____iter__, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Hypergraph, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct____iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -6389,7 +10008,7 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Hypergraph, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct____iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -6403,48 +10022,52 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Lattice(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o); + p->__pyx_v_fname = 0; + p->__pyx_v_self = 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_pw_5_cdec_7Lattice_14__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_fname)); + Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_sq_item_5_cdec_Lattice(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} -static int __pyx_mp_ass_subscript_5_cdec_Lattice(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_pw_5_cdec_7Lattice_5__setitem__(o, i, v); +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; + if (p->__pyx_v_fname) { + e = (*v)(p->__pyx_v_fname, a); if (e) return e; } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); - return -1; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } + return 0; } -static PyMethodDef __pyx_methods_5_cdec_Lattice[] = { +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_fname); + p->__pyx_v_fname = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_1___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_Lattice = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -6502,11 +10125,11 @@ static PyNumberMethods __pyx_tp_as_number_Lattice = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Lattice = { - __pyx_pw_5_cdec_7Lattice_7__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1___iter__ = { + 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_Lattice, /*sq_item*/ + 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -6515,13 +10138,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Lattice = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Lattice = { - __pyx_pw_5_cdec_7Lattice_7__len__, /*mp_length*/ - __pyx_pw_5_cdec_7Lattice_3__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_5_cdec_Lattice, /*mp_ass_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1___iter__ = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Lattice = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -6542,12 +10165,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Lattice = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Lattice = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Lattice"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Lattice), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_1___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Lattice, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -6557,24 +10180,24 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { 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*/ + &__pyx_tp_as_number___pyx_scope_struct_1___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_1___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_1___iter__, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ - __pyx_pw_5_cdec_7Lattice_9__str__, /*tp_str*/ + 0, /*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*/ + &__pyx_tp_as_buffer___pyx_scope_struct_1___iter__, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_7Lattice_11__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Lattice, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_1___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -6582,9 +10205,9 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ - __pyx_pw_5_cdec_7Lattice_1__init__, /*tp_init*/ + 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Lattice, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -6598,76 +10221,60 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Decoder(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec_Decoder *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec_Decoder *)o); - p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); - if (__pyx_pw_5_cdec_7Decoder_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)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_Decoder(PyObject *o) { - struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_7Decoder_3__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - Py_XDECREF(((PyObject *)p->weights)); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(((PyObject *)p->__pyx_v_sentence)); + Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec_Decoder(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; - if (p->weights) { - e = (*v)(((PyObject*)p->weights), a); if (e) return e; + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + } + if (p->__pyx_v_sentence) { + e = (*v)(p->__pyx_v_sentence, a); if (e) return e; + } + if (p->__pyx_v_size) { + e = (*v)(p->__pyx_v_size, a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec_Decoder(PyObject *o) { - struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; PyObject* tmp; - tmp = ((PyObject*)p->weights); - p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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 PyObject *__pyx_getprop_5_cdec_7Decoder_weights(PyObject *o, void *x) { - return __pyx_pw_5_cdec_7Decoder_7weights_1__get__(o); -} - -static int __pyx_setprop_5_cdec_7Decoder_weights(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_5_cdec_7Decoder_7weights_3__set__(o, v); - } - else { - return __pyx_pw_5_cdec_7Decoder_7weights_5__del__(o); - } -} - -static PyMethodDef __pyx_methods_5_cdec_Decoder[] = { - {__Pyx_NAMESTR("read_weights"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_5read_weights, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("translate"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_7translate, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_2_kbest[] = { {0, 0, 0, 0} }; -static struct PyGetSetDef __pyx_getsets_5_cdec_Decoder[] = { - {(char *)"weights", __pyx_getprop_5_cdec_7Decoder_weights, __pyx_setprop_5_cdec_7Decoder_weights, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_Decoder = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -6725,7 +10332,7 @@ static PyNumberMethods __pyx_tp_as_number_Decoder = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Decoder = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -6738,13 +10345,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Decoder = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Decoder = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_2_kbest = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Decoder = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -6765,12 +10372,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Decoder = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Decoder = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Decoder"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Decoder), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_2_kbest"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Decoder, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -6780,26 +10387,26 @@ static PyTypeObject __pyx_type_5_cdec_Decoder = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Decoder, /*tp_as_number*/ - &__pyx_tp_as_sequence_Decoder, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Decoder, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_2_kbest, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_2_kbest, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_2_kbest, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Decoder, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct_2_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_Decoder, /*tp_traverse*/ - __pyx_tp_clear_5_cdec_Decoder, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Decoder, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_2_kbest, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_5_cdec_Decoder, /*tp_getset*/ + 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -6807,7 +10414,7 @@ static PyTypeObject __pyx_type_5_cdec_Decoder = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Decoder, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -6821,44 +10428,60 @@ static PyTypeObject __pyx_type_5_cdec_Decoder = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct____iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_tree(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)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____iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_kbest_tree(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(p->__pyx_v_size); + Py_XDECREF(((PyObject *)p->__pyx_v_tree)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_kbest_tree(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; 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____iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_3_kbest_tree(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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____iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_3_kbest_tree[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_kbest_tree = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -6916,7 +10539,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct____iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -6929,13 +10552,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct____iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct____iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_3_kbest_tree = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_kbest_tree = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -6956,12 +10579,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct____iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct____iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_3_kbest_tree"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -6971,24 +10594,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct____iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct____iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct____iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_3_kbest_tree, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_3_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____iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_3_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____iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct____iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -6998,7 +10621,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct____iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -7012,52 +10635,60 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_4_kbest_features(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o); - p->__pyx_v_fname = 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o); + p->__pyx_v_fmap = 0; p->__pyx_v_self = 0; + p->__pyx_v_size = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; - Py_XDECREF(((PyObject *)p->__pyx_v_fname)); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_fmap)); Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; - if (p->__pyx_v_fname) { - e = (*v)(p->__pyx_v_fname, a); if (e) return e; + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; + if (p->__pyx_v_fmap) { + e = (*v)(((PyObject*)p->__pyx_v_fmap), 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; + } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_fname); - p->__pyx_v_fname = ((PyObject*)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_fmap); + p->__pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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_1___iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_4_kbest_features[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4_kbest_features = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -7115,7 +10746,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1___iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4_kbest_features = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -7128,13 +10759,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1___iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1___iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_4_kbest_features = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4_kbest_features = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -7155,12 +10786,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_kbest_features = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_1___iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_4_kbest_features"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -7170,24 +10801,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_1___iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_1___iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_1___iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_4_kbest_features, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_4_kbest_features, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_4_kbest_features, /*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___iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_4_kbest_features, /*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___iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_1___iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -7197,7 +10828,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -7211,42 +10842,37 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_5_sample(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)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(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5_sample(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); Py_XDECREF(((PyObject *)p->__pyx_v_sentence)); - Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_5_sample(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } if (p->__pyx_v_sentence) { e = (*v)(p->__pyx_v_sentence, a); if (e) return e; } - if (p->__pyx_v_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(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_5_sample(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); @@ -7254,17 +10880,14 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest(PyObject *o) { 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[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_5_sample[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_5_sample = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -7322,7 +10945,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_5_sample = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -7335,13 +10958,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_2_kbest = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_5_sample = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_5_sample = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -7362,12 +10985,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5_sample = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_2_kbest"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_5_sample"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5_sample, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -7377,24 +11000,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_2_kbest, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_2_kbest, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_2_kbest, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_5_sample, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_5_sample, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_5_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_2_kbest, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_5_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_2_kbest, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_5_sample, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_5_sample, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_2_kbest, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_5_sample, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -7404,7 +11027,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_5_sample, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -7418,60 +11041,44 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_tree(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_6___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)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_3_kbest_tree(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_6___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(p->__pyx_v_size); - Py_XDECREF(((PyObject *)p->__pyx_v_tree)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_kbest_tree(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_6___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o; 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_3_kbest_tree(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_6___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Lattice *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_3_kbest_tree[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_6___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_kbest_tree = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_6___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -7529,7 +11136,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_kbest_tree = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_6___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -7542,13 +11149,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree = 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_3_kbest_tree = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_6___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_kbest_tree = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_6___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -7569,12 +11176,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_kbest_tree = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_6___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_3_kbest_tree"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_6___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_6___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -7584,24 +11191,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_3_kbest_tree, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_3_kbest_tree, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_6___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_6___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_6___iter__, /*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_kbest_tree, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_6___iter__, /*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_kbest_tree, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_6___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_6___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_6___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -7611,7 +11218,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_6___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -7625,52 +11232,60 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_4_sample(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_7___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)o); + p->__pyx_v_i = 0; p->__pyx_v_self = 0; - p->__pyx_v_sentence = 0; + p->__pyx_t_1 = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_sample(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_7___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)o; + Py_XDECREF(p->__pyx_v_i); Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(((PyObject *)p->__pyx_v_sentence)); + Py_XDECREF(p->__pyx_t_1); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_4_sample(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_7___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)o; + if (p->__pyx_v_i) { + e = (*v)(p->__pyx_v_i, 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_t_1) { + e = (*v)(p->__pyx_t_1, a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_4_sample(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_7___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)o; PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_i); + p->__pyx_v_i = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SufficientStats *)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); + tmp = ((PyObject*)p->__pyx_t_1); + p->__pyx_t_1 = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_4_sample[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_7___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4_sample = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_7___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -7728,7 +11343,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4_sample = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4_sample = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_7___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -7741,13 +11356,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4_sample = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_4_sample = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_7___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4_sample = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_7___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -7768,12 +11383,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4_sample = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_sample = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_4_sample"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_7___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_sample, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_7___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -7783,24 +11398,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_sample = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_4_sample, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_4_sample, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_4_sample, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_7___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_7___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_7___iter__, /*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_4_sample, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_7___iter__, /*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_4_sample, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_4_sample, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_7___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_7___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_4_sample, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_7___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -7810,7 +11425,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_sample = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_4_sample, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_7___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -7824,44 +11439,60 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_sample = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_5___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_8_candidate_set(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)o); + p->__pyx_v_candidate = 0; + p->__pyx_v_hypergraph = 0; p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8_candidate_set(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_candidate)); + Py_XDECREF(((PyObject *)p->__pyx_v_hypergraph)); Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_5___iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_8_candidate_set(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)o; + if (p->__pyx_v_candidate) { + e = (*v)(((PyObject*)p->__pyx_v_candidate), a); if (e) return e; + } + if (p->__pyx_v_hypergraph) { + e = (*v)(((PyObject*)p->__pyx_v_hypergraph), a); if (e) return e; + } if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_5___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_8_candidate_set(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)o; PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_candidate); + p->__pyx_v_candidate = ((struct __pyx_obj_5_cdec_Candidate *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_hypergraph); + p->__pyx_v_hypergraph = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Lattice *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_5___iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_8_candidate_set[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_5___iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_8_candidate_set = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -7919,7 +11550,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_5___iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_5___iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_8_candidate_set = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -7932,13 +11563,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_5___iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_5___iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_8_candidate_set = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_5___iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_8_candidate_set = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -7959,12 +11590,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_5___iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5___iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8_candidate_set = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_5___iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_8_candidate_set"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5___iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -7974,24 +11605,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5___iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_5___iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_5___iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_5___iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_8_candidate_set, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_8_candidate_set, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_8_candidate_set, /*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_5___iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_8_candidate_set, /*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_5___iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_5___iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_5___iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -8001,7 +11632,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5___iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_5___iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -8039,15 +11670,18 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0}, {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0}, {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0}, + {&__pyx_kp_s_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 1, 0}, {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0}, - {&__pyx_kp_s_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 1, 0}, + {&__pyx_kp_s_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 0, 1, 0}, + {&__pyx_n_s__BLEU, __pyx_k__BLEU, sizeof(__pyx_k__BLEU), 0, 0, 1, 1}, {&__pyx_n_s__Exception, __pyx_k__Exception, sizeof(__pyx_k__Exception), 0, 0, 1, 1}, + {&__pyx_n_s__IBM_BLEU, __pyx_k__IBM_BLEU, sizeof(__pyx_k__IBM_BLEU), 0, 0, 1, 1}, {&__pyx_n_s__IndexError, __pyx_k__IndexError, sizeof(__pyx_k__IndexError), 0, 0, 1, 1}, {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1}, {&__pyx_n_s__NotImplemented, __pyx_k__NotImplemented, sizeof(__pyx_k__NotImplemented), 0, 0, 1, 1}, {&__pyx_n_s__ParseFailed, __pyx_k__ParseFailed, sizeof(__pyx_k__ParseFailed), 0, 0, 1, 1}, + {&__pyx_n_s__TER, __pyx_k__TER, sizeof(__pyx_k__TER), 0, 0, 1, 1}, {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1}, - {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, {&__pyx_n_s____enter__, __pyx_k____enter__, sizeof(__pyx_k____enter__), 0, 0, 1, 1}, {&__pyx_n_s____exit__, __pyx_k____exit__, sizeof(__pyx_k____exit__), 0, 0, 1, 1}, {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, @@ -8059,13 +11693,18 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__density, __pyx_k__density, sizeof(__pyx_k__density), 0, 0, 1, 1}, {&__pyx_n_s__dot, __pyx_k__dot, sizeof(__pyx_k__dot), 0, 0, 1, 1}, {&__pyx_n_s__encode, __pyx_k__encode, sizeof(__pyx_k__encode), 0, 0, 1, 1}, + {&__pyx_n_s__encoding, __pyx_k__encoding, sizeof(__pyx_k__encoding), 0, 0, 1, 1}, {&__pyx_n_s__enumerate, __pyx_k__enumerate, sizeof(__pyx_k__enumerate), 0, 0, 1, 1}, {&__pyx_n_s__eval, __pyx_k__eval, sizeof(__pyx_k__eval), 0, 0, 1, 1}, {&__pyx_n_s__grammar, __pyx_k__grammar, sizeof(__pyx_k__grammar), 0, 0, 1, 1}, + {&__pyx_n_s__hypergraph, __pyx_k__hypergraph, sizeof(__pyx_k__hypergraph), 0, 0, 1, 1}, {&__pyx_n_s__inp, __pyx_k__inp, sizeof(__pyx_k__inp), 0, 0, 1, 1}, + {&__pyx_n_s__k, __pyx_k__k, sizeof(__pyx_k__k), 0, 0, 1, 1}, + {&__pyx_n_s__name, __pyx_k__name, sizeof(__pyx_k__name), 0, 0, 1, 1}, {&__pyx_n_s__open, __pyx_k__open, sizeof(__pyx_k__open), 0, 0, 1, 1}, {&__pyx_n_s__plf, __pyx_k__plf, sizeof(__pyx_k__plf), 0, 0, 1, 1}, {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1}, + {&__pyx_n_s__refs, __pyx_k__refs, sizeof(__pyx_k__refs), 0, 0, 1, 1}, {&__pyx_n_s__self, __pyx_k__self, sizeof(__pyx_k__self), 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}, @@ -8074,14 +11713,13 @@ 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 = 12; __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 = 13; __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[1]; __pyx_lineno = 10; __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[1]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_NotImplemented = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplemented); if (!__pyx_builtin_NotImplemented) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __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[2]; __pyx_lineno = 82; __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[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __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 = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; @@ -8095,7 +11733,7 @@ static int __Pyx_InitCachedConstants(void) { /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":69 * elif op == 3: # != - * return not (self == other) + * return not (x == y) * raise NotImplemented('comparison not implemented for SparseVector') # <<<<<<<<<<<<<< * * def __len__(self): @@ -8177,14 +11815,14 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_8)); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":65 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":78 * for k in range(hypos.size()): * sentence = GetString(hypos[0][k].words).c_str() * yield sentence.decode('utf8') # <<<<<<<<<<<<<< * del hypos * */ - __pyx_k_tuple_9 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_9 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_9); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); PyTuple_SET_ITEM(__pyx_k_tuple_9, 0, ((PyObject *)__pyx_n_s__utf8)); @@ -8261,6 +11899,20 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_18)); + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":6 + * cdef bytes ret + * if isinstance(sentence, unicode): + * ret = sentence.encode('utf8') # <<<<<<<<<<<<<< + * elif isinstance(sentence, str): + * ret = sentence + */ + __pyx_k_tuple_20 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_20); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_20, 0, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20)); + /* "_cdec.pyx":31 * * def read_weights(self, cfg): @@ -8268,18 +11920,18 @@ static int __Pyx_InitCachedConstants(void) { * for line in fp: * fname, value = line.split() */ - __pyx_k_tuple_19 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_19); + __pyx_k_tuple_21 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_21); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_19, 0, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_21, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_19, 1, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_21, 1, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_19, 2, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_21, 2, Py_None); __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_19)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21)); /* "_cdec.pyx":38 * def translate(self, sentence, grammar=None): @@ -8288,12 +11940,37 @@ static int __Pyx_InitCachedConstants(void) { * elif isinstance(sentence, str): * inp = sentence.strip() */ - __pyx_k_tuple_20 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_20); + __pyx_k_tuple_22 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_22); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_20, 0, ((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_22, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 + * return self.name.c_str() + * + * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< + * TER = Scorer('TER') + */ + __pyx_k_tuple_24 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_24); + __Pyx_INCREF(((PyObject *)__pyx_n_s__IBM_BLEU)); + PyTuple_SET_ITEM(__pyx_k_tuple_24, 0, ((PyObject *)__pyx_n_s__IBM_BLEU)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IBM_BLEU)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_24)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":116 + * + * BLEU = Scorer('IBM_BLEU') + * TER = Scorer('TER') # <<<<<<<<<<<<<< + */ + __pyx_k_tuple_25 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_25); + __Pyx_INCREF(((PyObject *)__pyx_n_s__TER)); + PyTuple_SET_ITEM(__pyx_k_tuple_25, 0, ((PyObject *)__pyx_n_s__TER)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__TER)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_25)); __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -8389,6 +12066,18 @@ PyMODINIT_FUNC PyInit__cdec(void) if (PyType_Ready(&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Lattice", (PyObject *)&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Lattice = &__pyx_type_5_cdec_Lattice; + if (PyType_Ready(&__pyx_type_5_cdec_Candidate) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Candidate", (PyObject *)&__pyx_type_5_cdec_Candidate) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_Candidate = &__pyx_type_5_cdec_Candidate; + if (PyType_Ready(&__pyx_type_5_cdec_SufficientStats) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "SufficientStats", (PyObject *)&__pyx_type_5_cdec_SufficientStats) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_SufficientStats = &__pyx_type_5_cdec_SufficientStats; + if (PyType_Ready(&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "SegmentEvaluator", (PyObject *)&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_SegmentEvaluator = &__pyx_type_5_cdec_SegmentEvaluator; + if (PyType_Ready(&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Scorer", (PyObject *)&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_Scorer = &__pyx_type_5_cdec_Scorer; if (PyType_Ready(&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __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 = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Decoder = &__pyx_type_5_cdec_Decoder; @@ -8400,42 +12089,69 @@ PyMODINIT_FUNC PyInit__cdec(void) __pyx_ptype_5_cdec___pyx_scope_struct_2_kbest = &__pyx_type_5_cdec___pyx_scope_struct_2_kbest; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_tree = &__pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_4_sample) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_4_sample = &__pyx_type_5_cdec___pyx_scope_struct_4_sample; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_5___iter__) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_5___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_5___iter__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_4_kbest_features) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features = &__pyx_type_5_cdec___pyx_scope_struct_4_kbest_features; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_5_sample) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_5_sample = &__pyx_type_5_cdec___pyx_scope_struct_5_sample; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_6___iter__) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_6___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_6___iter__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_7___iter__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_7___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_7___iter__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_8_candidate_set) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_8_candidate_set = &__pyx_type_5_cdec___pyx_scope_struct_8_candidate_set; /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ /*--- Execution code ---*/ - /* "_cdec.pyx":10 - * include "lattice.pxi" + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 + * return self.name.c_str() + * + * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< + * TER = Scorer('TER') + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":116 + * + * BLEU = Scorer('IBM_BLEU') + * TER = Scorer('TER') # <<<<<<<<<<<<<< + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_cdec.pyx":11 + * include "mteval.pxi" * * SetSilent(True) # <<<<<<<<<<<<<< * - * class ParseFailed(Exception): + * class ParseFailed(Exception): pass */ SetSilent(1); - /* "_cdec.pyx":12 + /* "_cdec.pyx":13 * SetSilent(True) * - * class ParseFailed(Exception): # <<<<<<<<<<<<<< - * pass + * class ParseFailed(Exception): pass # <<<<<<<<<<<<<< * + * cdef class Decoder: */ - __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_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __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 = 12; __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 = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__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 = 12; __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 = 13; __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 = 12; __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 = 13; __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; @@ -8673,6 +12389,18 @@ static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed return 0; } +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { + if (unlikely(!type)) { + PyErr_Format(PyExc_SystemError, "Missing type object"); + return 0; + } + if (likely(PyObject_TypeCheck(obj, type))) + return 1; + PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", + Py_TYPE(obj)->tp_name, type->tp_name); + return 0; +} + static void __Pyx_RaiseDoubleKeywordsError( const char* func_name, PyObject* kw_name) @@ -8889,18 +12617,6 @@ bad: return -1; } -static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { - if (unlikely(!type)) { - PyErr_Format(PyExc_SystemError, "Missing type object"); - return 0; - } - if (likely(PyObject_TypeCheck(obj, type))) - return 1; - PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", - Py_TYPE(obj)->tp_name, type->tp_name); - return 0; -} - static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) { PyThreadState *tstate = PyThreadState_GET(); *type = tstate->exc_type; @@ -9693,6 +13409,25 @@ static int __pyx_Generator_init(void) return PyType_Ready(&__pyx_GeneratorType); } +static void __Pyx_WriteUnraisable(const char *name, int clineno, + int lineno, const char *filename) { + PyObject *old_exc, *old_val, *old_tb; + PyObject *ctx; + __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); + #if PY_MAJOR_VERSION < 3 + ctx = PyString_FromString(name); + #else + ctx = PyUnicode_FromString(name); + #endif + __Pyx_ErrRestore(old_exc, old_val, old_tb); + if (!ctx) { + PyErr_WriteUnraisable(Py_None); + } else { + PyErr_WriteUnraisable(ctx); + Py_DECREF(ctx); + } +} + static int __Pyx_check_binary_version(void) { char ctversion[4], rtversion[4]; PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); diff --git a/python/src/_cdec.pyx b/python/src/_cdec.pyx index 698a66f6..6fafbbc0 100644 --- a/python/src/_cdec.pyx +++ b/python/src/_cdec.pyx @@ -6,11 +6,11 @@ cimport decoder include "vectors.pxi" include "hypergraph.pxi" include "lattice.pxi" +include "mteval.pxi" SetSilent(True) -class ParseFailed(Exception): - pass +class ParseFailed(Exception): pass cdef class Decoder: cdef decoder.Decoder* dec diff --git a/python/src/hypergraph.pxi b/python/src/hypergraph.pxi index c226d105..ce78b729 100644 --- a/python/src/hypergraph.pxi +++ b/python/src/hypergraph.pxi @@ -53,6 +53,19 @@ cdef class Hypergraph: yield tree.decode('utf8') del derivations + def kbest_features(self, size): + cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) + cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal].Derivation* derivation + cdef SparseVector fmap + cdef unsigned k + for k in range(size): + derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + if not derivation: break + fmap = SparseVector() + fmap.vector = new FastSparseVector[weight_t](derivation._yield) + yield fmap + del derivations + def sample(self, unsigned n): cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() if self.rng == NULL: @@ -87,6 +100,6 @@ cdef class Hypergraph: elif isinstance(weights, DenseVector): self.hg.Reweight(( weights).vector[0]) else: - raise ValueError('cannot reweight hypergraph with %s' % type(weights)) + raise TypeError('cannot reweight hypergraph with %s' % type(weights)) # TODO get feature expectations, get partition function ("inside" score) diff --git a/python/src/kbest.pxd b/python/src/kbest.pxd index f34ac5ed..cef42bd3 100644 --- a/python/src/kbest.pxd +++ b/python/src/kbest.pxd @@ -9,6 +9,8 @@ cdef extern from "decoder/viterbi.h": pass cdef cppclass FTreeTraversal: pass + cdef cppclass FeatureVectorTraversal: + pass cdef extern from "decoder/kbest.h" namespace "KBest": cdef cppclass KBestDerivations[T, Traversal]: diff --git a/python/src/mteval.pxd b/python/src/mteval.pxd new file mode 100644 index 00000000..52af6297 --- /dev/null +++ b/python/src/mteval.pxd @@ -0,0 +1,47 @@ +from libcpp.vector cimport vector +from libcpp.string cimport string +from utils cimport * +from hypergraph cimport Hypergraph + +cdef extern from "mteval/ns.h": + cdef cppclass SufficientStats: + SufficientStats() + SufficientStats(SufficientStats&) + unsigned size() + float operator[](unsigned i) + void swap(SufficientStats& other) + + SufficientStats add "operator+" (SufficientStats&, SufficientStats&) + + cdef cppclass SegmentEvaluator: + void Evaluate(vector[WordID]& hyp, SufficientStats* out) + + cdef cppclass EvaluationMetric: + string& MetricId() + bint IsErrorMetric() + float ComputeScore(SufficientStats& stats) + string DetailedScore(SufficientStats& stats) + shared_ptr[SegmentEvaluator] CreateSegmentEvaluator(vector[vector[WordID]]& refs) + ComputeSufficientStatistics(vector[WordID]& hyp, + vector[WordID]& refs, + SufficientStats* out) + +cdef extern from "mteval/ns.h" namespace "EvaluationMetric": + EvaluationMetric* Instance(string& metric_id) + EvaluationMetric* Instance() # IBM_BLEU + +cdef extern from "training/candidate_set.h" namespace "training": + cdef cppclass Candidate "const training::Candidate": + vector[WordID] ewords + FastSparseVector[weight_t] fmap + SufficientStats eval_feats + + cdef cppclass CandidateSet: + CandidateSet() + unsigned size() + Candidate& operator[](unsigned i) + void ReadFromFile(string& file) + void WriteToFile(string& file) + void AddKBestCandidates(Hypergraph& hg, + unsigned kbest_size, + SegmentEvaluator* scorer) diff --git a/python/src/mteval.pxi b/python/src/mteval.pxi new file mode 100644 index 00000000..dabdf927 --- /dev/null +++ b/python/src/mteval.pxi @@ -0,0 +1,116 @@ +cimport mteval + +cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): + cdef bytes ret + if isinstance(sentence, unicode): + ret = sentence.encode('utf8') + elif isinstance(sentence, str): + ret = sentence + else: + raise TypeError(error_msg % type(sentence)) + return ret + +cdef class Candidate: + cdef mteval.Candidate* candidate + cdef public float score + + property words: + def __get__(self): + return unicode(GetString(self.candidate.ewords).c_str(), encoding='utf8') + + property fmap: + def __get__(self): + cdef SparseVector fmap = SparseVector() + fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) + return fmap + +cdef class SufficientStats: + cdef mteval.SufficientStats* stats + cdef mteval.EvaluationMetric* metric + + def __dealloc__(self): + del self.stats + + property score: + def __get__(self): + return self.metric.ComputeScore(self.stats[0]) + + property detail: + def __get__(self): + return self.metric.DetailedScore(self.stats[0]).c_str() + + def __len__(self): + return self.stats.size() + + def __iter__(self): + for i in range(len(self)): + yield self.stats[0][i] + + def __iadd__(SufficientStats self, SufficientStats other): + self.stats[0] += other.stats[0] + return self + + def __add__(SufficientStats x, SufficientStats y): + cdef SufficientStats result = SufficientStats() + result.stats = new mteval.SufficientStats(mteval.add(x.stats[0], y.stats[0])) + result.metric = x.metric + return result + +cdef class SegmentEvaluator: + cdef shared_ptr[mteval.SegmentEvaluator]* scorer + cdef mteval.EvaluationMetric* metric + + def __dealloc__(self): + del self.scorer + + def evaluate(self, sentence): + cdef vector[WordID] hyp + cdef SufficientStats sf = SufficientStats() + sf.metric = self.metric + sf.stats = new mteval.SufficientStats() + ConvertSentence(string(as_str(sentence.strip())), &hyp) + self.scorer.get().Evaluate(hyp, sf.stats) + return sf + + def candidate_set(self, Hypergraph hypergraph, unsigned k): + cdef mteval.CandidateSet* cs = new mteval.CandidateSet() + cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) + cdef Candidate candidate + cdef unsigned i + for i in range(cs.size()): + candidate = Candidate() + candidate.candidate = &cs[0][i] + candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) + yield candidate + del cs + +cdef class Scorer: + cdef string* name + + def __cinit__(self, char* name): + self.name = new string(name) + + def __call__(self, refs): + cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) + if isinstance(refs, unicode) or isinstance(refs, str): + refs = [refs] + cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() + cdef vector[WordID]* refv + cdef bytes ref_str + for ref in refs: + refv = new vector[WordID]() + ConvertSentence(string(as_str(ref.strip())), refv) + refsv.push_back(refv[0]) + del refv + cdef unsigned i + cdef SegmentEvaluator evaluator = SegmentEvaluator() + evaluator.metric = metric + evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + del refsv # in theory should not delete but store in SegmentEvaluator + return evaluator + + def __str__(self): + return self.name.c_str() + +BLEU = Scorer('IBM_BLEU') +TER = Scorer('TER') diff --git a/python/src/utils.pxd b/python/src/utils.pxd index 3d518524..94fab5ef 100644 --- a/python/src/utils.pxd +++ b/python/src/utils.pxd @@ -50,16 +50,19 @@ cdef extern from "utils/sparse_vector.h": FastSparseVector[weight_t] operator+(FastSparseVector[weight_t]&, FastSparseVector[weight_t]&) FastSparseVector[weight_t] operator-(FastSparseVector[weight_t]&, FastSparseVector[weight_t]&) + FastSparseVector[weight_t] operator*(FastSparseVector[weight_t]&, double&) + FastSparseVector[weight_t] operator/(FastSparseVector[weight_t]&, double&) ostream operator<<(ostream& out, FastSparseVector[weight_t]& v) cdef extern from "utils/weights.h" namespace "Weights": void InitSparseVector(vector[weight_t]& dv, FastSparseVector[weight_t]* sv) -cdef extern from "utils/tdict.cc" namespace "TD": +cdef extern from "utils/tdict.h" namespace "TD": string GetString(vector[WordID]& st) unsigned NumWords() WordID TDConvert "TD::Convert" (char*) char* TDConvert "TD::Convert" (WordID) + void ConvertSentence(string& sent, vector[WordID]* ids) cdef extern from "utils/verbose.h": void SetSilent(bint) @@ -76,3 +79,8 @@ cdef extern from "utils/filelib.h": cdef extern from "utils/sampler.h": cdef cppclass MT19937: pass + +cdef extern from "" namespace "boost": + cdef cppclass shared_ptr[T]: + shared_ptr(shared_ptr& r) + T* get() diff --git a/python/src/vectors.pxi b/python/src/vectors.pxi index 74d3a0bd..233c9530 100644 --- a/python/src/vectors.pxi +++ b/python/src/vectors.pxi @@ -53,7 +53,7 @@ cdef class SparseVector: return self.vector.dot(( other).vector[0]) elif isinstance(other, SparseVector): return self.vector.dot(( other).vector[0]) - raise ValueError('cannot take the dot product of %s and SparseVector' % type(other)) + raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) def todense(self): cdef DenseVector dense = DenseVector() @@ -61,11 +61,11 @@ cdef class SparseVector: self.vector.init_vector(dense.vector) return dense - def __richcmp__(SparseVector self, SparseVector other, int op): + def __richcmp__(SparseVector x, SparseVector y, int op): if op == 2: # == - return self.vector[0] == other.vector[0] + return x.vector[0] == y.vector[0] elif op == 3: # != - return not (self == other) + return not (x == y) raise NotImplemented('comparison not implemented for SparseVector') def __len__(self): @@ -90,12 +90,30 @@ cdef class SparseVector: self.vector[0] /= scalar return self - def __add__(SparseVector self, SparseVector other): + def __add__(SparseVector x, SparseVector y): cdef SparseVector result = SparseVector() - result.vector = new FastSparseVector[weight_t](self.vector[0] + other.vector[0]) + result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) return result - def __sub__(SparseVector self, SparseVector other): + def __sub__(SparseVector x, SparseVector y): cdef SparseVector result = SparseVector() - result.vector = new FastSparseVector[weight_t](self.vector[0] - other.vector[0]) + result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) + return result + + def __mul__(x, y): + cdef SparseVector vector + cdef float scalar + if isinstance(x, SparseVector): vector, scalar = x, y + else: vector, scalar = y, x + cdef SparseVector result = SparseVector() + result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) + return result + + def __div__(x, y): + cdef SparseVector vector + cdef float scalar + if isinstance(x, SparseVector): vector, scalar = x, y + else: vector, scalar = y, x + cdef SparseVector result = SparseVector() + result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) return result diff --git a/python/test.py b/python/test.py index 92403298..b3900eef 100644 --- a/python/test.py +++ b/python/test.py @@ -31,9 +31,11 @@ print ' FTree[0]:', forest.viterbi_source_tree().encode('utf8') print 'LgProb[0]:', forest.viterbi_features().dot(decoder.weights) # Get k-best translations -for i, (sentence, tree) in enumerate(zip(forest.kbest(5), forest.kbest_tree(5)), 1): +kbest = zip(forest.kbest(5), forest.kbest_tree(5), forest.kbest_features(5)) +for i, (sentence, tree, features) in enumerate(kbest, 1): print 'Output[%d]:' % i, sentence.encode('utf8') print ' Tree[%d]:' % i, tree.encode('utf8') + print ' FVect[%d]:' % i, dict(features) # Sample translations from the forest for sentence in forest.sample(5): -- cgit v1.2.3 From 7937972d2478a3b377930a30b77b07d2e6e902ba Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Mon, 2 Jul 2012 17:05:08 -0400 Subject: [python] Explicit candidate set; memory leak fixes --- python/src/_cdec.cpp | 3321 ++++++++++++++++++++++++++++----------------- python/src/hypergraph.pxi | 58 +- python/src/mteval.pxi | 47 +- python/src/vectors.pxi | 41 +- python/test.py | 3 + training/candidate_set.cc | 9 +- 6 files changed, 2215 insertions(+), 1264 deletions(-) (limited to 'python/src') diff --git a/python/src/_cdec.cpp b/python/src/_cdec.cpp index 7d45e27f..bc522b32 100644 --- a/python/src/_cdec.cpp +++ b/python/src/_cdec.cpp @@ -1,4 +1,4 @@ -/* Generated by Cython 0.16 on Sun Jul 1 00:36:19 2012 */ +/* Generated by Cython 0.16 on Mon Jul 2 17:01:11 2012 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -389,12 +389,12 @@ static const char *__pyx_f[] = { /*--- Type declarations ---*/ struct __pyx_obj_5_cdec_Scorer; +struct __pyx_obj_5_cdec_CandidateSet; struct __pyx_obj_5_cdec_SufficientStats; struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__; struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features; struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree; struct __pyx_obj_5_cdec_Decoder; -struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set; struct __pyx_obj_5_cdec_SegmentEvaluator; struct __pyx_obj_5_cdec_SparseVector; struct __pyx_obj_5_cdec_Hypergraph; @@ -405,6 +405,7 @@ struct __pyx_obj_5_cdec_Candidate; struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample; struct __pyx_obj_5_cdec_DenseVector; struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__; +struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__; struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__; struct __pyx_opt_args_5_cdec_as_str; @@ -420,8 +421,8 @@ struct __pyx_opt_args_5_cdec_as_str { PyObject *error_msg; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":87 - * del cs +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":109 + * return CandidateSet(self) * * cdef class Scorer: # <<<<<<<<<<<<<< * cdef string* name @@ -433,6 +434,21 @@ struct __pyx_obj_5_cdec_Scorer { }; +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":59 + * return result + * + * cdef class CandidateSet: # <<<<<<<<<<<<<< + * cdef shared_ptr[mteval.SegmentEvaluator]* scorer + * cdef mteval.EvaluationMetric* metric + */ +struct __pyx_obj_5_cdec_CandidateSet { + PyObject_HEAD + boost::shared_ptr *scorer; + EvaluationMetric *metric; + training::CandidateSet *cs; +}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":27 * return fmap * @@ -447,16 +463,15 @@ struct __pyx_obj_5_cdec_SufficientStats { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":43 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":55 * self.vector.set_value(fid, value) * * def __iter__(self): # <<<<<<<<<<<<<< * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) - * cdef str fname + * try: */ struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ { PyObject_HEAD - PyObject *__pyx_v_fname; size_t __pyx_v_i; FastSparseVector::const_iterator *__pyx_v_it; struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self; @@ -465,8 +480,8 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":60 + * del derivations * * def kbest_features(self, size): # <<<<<<<<<<<<<< * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) @@ -485,8 +500,8 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":44 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":46 + * del derivations * * def kbest_tree(self, size): # <<<<<<<<<<<<<< * cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ETreeTraversal](self.hg[0], size) @@ -519,28 +534,8 @@ struct __pyx_obj_5_cdec_Decoder { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":75 - * return sf - * - * def candidate_set(self, Hypergraph hypergraph, unsigned k): # <<<<<<<<<<<<<< - * cdef mteval.CandidateSet* cs = new mteval.CandidateSet() - * cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) - */ -struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set { - PyObject_HEAD - struct __pyx_obj_5_cdec_Candidate *__pyx_v_candidate; - training::CandidateSet *__pyx_v_cs; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph; - unsigned int __pyx_v_i; - unsigned int __pyx_v_k; - struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self; - unsigned int __pyx_t_0; - unsigned int __pyx_t_1; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":59 - * return result +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":90 + * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) * * cdef class SegmentEvaluator: # <<<<<<<<<<<<<< * cdef shared_ptr[mteval.SegmentEvaluator]* scorer @@ -553,7 +548,7 @@ struct __pyx_obj_5_cdec_SegmentEvaluator { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":32 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":36 * return sparse * * cdef class SparseVector: # <<<<<<<<<<<<<< @@ -593,7 +588,7 @@ struct __pyx_obj_5_cdec_Lattice { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":18 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":22 * self.vector[0][fid] = value * * def __iter__(self): # <<<<<<<<<<<<<< @@ -643,8 +638,8 @@ struct __pyx_obj_5_cdec_Candidate { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":69 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":75 + * del derivations * * def sample(self, unsigned n): # <<<<<<<<<<<<<< * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() @@ -666,7 +661,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample { * from cython.operator cimport preincrement as pinc * * cdef class DenseVector: # <<<<<<<<<<<<<< - * cdef vector[weight_t]* vector + * cdef vector[weight_t]* vector # Not owned by DenseVector * */ struct __pyx_obj_5_cdec_DenseVector { @@ -691,6 +686,22 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ { }; +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 + * return candidate + * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(len(self)): + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ { + PyObject_HEAD + unsigned int __pyx_v_i; + struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self; + Py_ssize_t __pyx_t_0; + unsigned int __pyx_t_1; +}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":45 * return self.stats.size() * @@ -989,6 +1000,7 @@ static PyTypeObject *__pyx_ptype_5_cdec_Hypergraph = 0; static PyTypeObject *__pyx_ptype_5_cdec_Lattice = 0; static PyTypeObject *__pyx_ptype_5_cdec_Candidate = 0; static PyTypeObject *__pyx_ptype_5_cdec_SufficientStats = 0; +static PyTypeObject *__pyx_ptype_5_cdec_CandidateSet = 0; static PyTypeObject *__pyx_ptype_5_cdec_SegmentEvaluator = 0; static PyTypeObject *__pyx_ptype_5_cdec_Scorer = 0; static PyTypeObject *__pyx_ptype_5_cdec_Decoder = 0; @@ -1000,7 +1012,7 @@ static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_5_sample = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_6___iter__ = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_7___iter__ = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_8_candidate_set = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_8___iter__ = 0; static char *__pyx_f_5_cdec_as_str(PyObject *, struct __pyx_opt_args_5_cdec_as_str *__pyx_optional_args); /*proto*/ #define __Pyx_MODULE_NAME "_cdec" int __pyx_module_is_main__cdec = 0; @@ -1015,30 +1027,32 @@ static PyObject *__pyx_builtin_eval; static PyObject *__pyx_builtin_enumerate; static PyObject *__pyx_builtin_IndexError; static PyObject *__pyx_builtin_open; -static PyObject *__pyx_pf_5_cdec_11DenseVector___getitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ -static int __pyx_pf_5_cdec_11DenseVector_2__setitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value); /* proto */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_4__iter__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_7dot(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_9tosparse(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector___getitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ -static int __pyx_pf_5_cdec_12SparseVector_2__setitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_4__iter__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, PyObject *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_9todense(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y, int __pyx_v_op); /* proto */ -static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_13__len__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ -static int __pyx_pf_5_cdec_12SparseVector_15__contains__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_17__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_19__isub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_21__imul__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ +static Py_ssize_t __pyx_pf_5_cdec_11DenseVector___len__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_11DenseVector_2__getitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ +static int __pyx_pf_5_cdec_11DenseVector_4__setitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value); /* proto */ +static PyObject *__pyx_pf_5_cdec_11DenseVector_6__iter__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_11DenseVector_9dot(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_11DenseVector_11tosparse(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ +static void __pyx_pf_5_cdec_12SparseVector___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_2copy(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_4__getitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ +static int __pyx_pf_5_cdec_12SparseVector_6__setitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_8__iter__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, PyObject *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y, int __pyx_v_op); /* proto */ +static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_15__len__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_12SparseVector_17__contains__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_19__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_21__isub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_23__imul__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pf_5_cdec_12SparseVector_23__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_25__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ #endif -static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_29__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_27__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_29__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_31__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pf_5_cdec_12SparseVector_31__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_33__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ #endif static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ @@ -1071,12 +1085,19 @@ static Py_ssize_t __pyx_pf_5_cdec_15SufficientStats_2__len__(struct __pyx_obj_5_ static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__iadd__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_other); /* proto */ static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_x, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_y); /* proto */ +static int __pyx_pf_5_cdec_12CandidateSet___cinit__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator); /* proto */ +static void __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self); /* proto */ +static Py_ssize_t __pyx_pf_5_cdec_12CandidateSet_4__len__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, unsigned int __pyx_v_k); /* proto */ +static PyObject *__pyx_pf_5_cdec_12CandidateSet_8__iter__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_12CandidateSet_11add_kbest(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph, unsigned int __pyx_v_k); /* proto */ static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, PyObject *__pyx_v_sentence); /* proto */ -static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph, unsigned int __pyx_v_k); /* proto */ +static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self); /* proto */ static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, char *__pyx_v_name); /* proto */ -static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs); /* proto */ -static PyObject *__pyx_pf_5_cdec_6Scorer_4__str__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self); /* proto */ +static void __pyx_pf_5_cdec_6Scorer_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Scorer *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs); /* proto */ +static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self); /* proto */ static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, char *__pyx_v_config); /* proto */ static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Decoder *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_cfg); /* proto */ @@ -1124,6 +1145,7 @@ static char __pyx_k__Exception[] = "Exception"; static char __pyx_k__TypeError[] = "TypeError"; static char __pyx_k____enter__[] = "__enter__"; static char __pyx_k__enumerate[] = "enumerate"; +static char __pyx_k__evaluator[] = "evaluator"; static char __pyx_k__IndexError[] = "IndexError"; static char __pyx_k__beam_alpha[] = "beam_alpha"; static char __pyx_k__hypergraph[] = "hypergraph"; @@ -1160,6 +1182,7 @@ static PyObject *__pyx_n_s__encode; static PyObject *__pyx_n_s__encoding; static PyObject *__pyx_n_s__enumerate; static PyObject *__pyx_n_s__eval; +static PyObject *__pyx_n_s__evaluator; static PyObject *__pyx_n_s__grammar; static PyObject *__pyx_n_s__hypergraph; static PyObject *__pyx_n_s__inp; @@ -1195,14 +1218,54 @@ static PyObject *__pyx_k_tuple_24; static PyObject *__pyx_k_tuple_25; /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_11DenseVector_1__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ -static PyObject *__pyx_pw_5_cdec_11DenseVector_1__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { +static Py_ssize_t __pyx_pw_5_cdec_11DenseVector_1__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_11DenseVector_1__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_11DenseVector___len__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":6 + * cdef vector[weight_t]* vector # Not owned by DenseVector + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.vector.size() + * + */ + +static Py_ssize_t __pyx_pf_5_cdec_11DenseVector___len__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":7 + * + * def __len__(self): + * return self.vector.size() # <<<<<<<<<<<<<< + * + * def __getitem__(self, char* fname): + */ + __pyx_r = __pyx_v_self->vector->size(); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_11DenseVector_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ +static PyObject *__pyx_pw_5_cdec_11DenseVector_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { char *__pyx_v_fname; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); assert(__pyx_arg_fname); { - __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 6; __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[1]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -1210,21 +1273,21 @@ static PyObject *__pyx_pw_5_cdec_11DenseVector_1__getitem__(PyObject *__pyx_v_se __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_11DenseVector___getitem__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); + __pyx_r = __pyx_pf_5_cdec_11DenseVector_2__getitem__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":6 - * cdef vector[weight_t]* vector +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":9 + * return self.vector.size() * * def __getitem__(self, char* fname): # <<<<<<<<<<<<<< - * cdef unsigned fid = FDConvert(fname) - * if fid <= self.vector.size(): + * cdef int fid = FDConvert(fname) + * if 0 <= fid < self.vector.size(): */ -static PyObject *__pyx_pf_5_cdec_11DenseVector___getitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname) { - unsigned int __pyx_v_fid; +static PyObject *__pyx_pf_5_cdec_11DenseVector_2__getitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname) { + int __pyx_v_fid; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; @@ -1235,34 +1298,37 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector___getitem__(struct __pyx_obj_5_cd int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__getitem__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":7 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":10 * * def __getitem__(self, char* fname): - * cdef unsigned fid = FDConvert(fname) # <<<<<<<<<<<<<< - * if fid <= self.vector.size(): + * cdef int fid = FDConvert(fname) # <<<<<<<<<<<<<< + * if 0 <= fid < self.vector.size(): * return self.vector[0][fid] */ __pyx_v_fid = FD::Convert(__pyx_v_fname); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":8 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":11 * def __getitem__(self, char* fname): - * cdef unsigned fid = FDConvert(fname) - * if fid <= self.vector.size(): # <<<<<<<<<<<<<< + * cdef int fid = FDConvert(fname) + * if 0 <= fid < self.vector.size(): # <<<<<<<<<<<<<< * return self.vector[0][fid] * raise KeyError(fname) */ - __pyx_t_1 = (__pyx_v_fid <= __pyx_v_self->vector->size()); + __pyx_t_1 = (0 <= __pyx_v_fid); + if (__pyx_t_1) { + __pyx_t_1 = (__pyx_v_fid < __pyx_v_self->vector->size()); + } if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":9 - * cdef unsigned fid = FDConvert(fname) - * if fid <= self.vector.size(): + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":12 + * cdef int fid = FDConvert(fname) + * if 0 <= fid < self.vector.size(): * return self.vector[0][fid] # <<<<<<<<<<<<<< * raise KeyError(fname) * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyFloat_FromDouble(((__pyx_v_self->vector[0])[__pyx_v_fid])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyFloat_FromDouble(((__pyx_v_self->vector[0])[__pyx_v_fid])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; @@ -1271,26 +1337,26 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector___getitem__(struct __pyx_obj_5_cd } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":10 - * if fid <= self.vector.size(): + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":13 + * if 0 <= fid < self.vector.size(): * return self.vector[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[1]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 13; __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[1]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__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[1]; __pyx_lineno = 10; __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[1]; __pyx_lineno = 13; __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[1]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; @@ -1306,18 +1372,18 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector___getitem__(struct __pyx_obj_5_cd } /* Python wrapper */ -static int __pyx_pw_5_cdec_11DenseVector_3__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value); /*proto*/ -static int __pyx_pw_5_cdec_11DenseVector_3__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value) { +static int __pyx_pw_5_cdec_11DenseVector_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value); /*proto*/ +static int __pyx_pw_5_cdec_11DenseVector_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value) { char *__pyx_v_fname; float __pyx_v_value; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); assert(__pyx_arg_fname); { - __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 12; __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[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } assert(__pyx_arg_value); { - __pyx_v_value = __pyx_PyFloat_AsFloat(__pyx_arg_value); if (unlikely((__pyx_v_value == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_value = __pyx_PyFloat_AsFloat(__pyx_arg_value); if (unlikely((__pyx_v_value == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -1325,38 +1391,69 @@ static int __pyx_pw_5_cdec_11DenseVector_3__setitem__(PyObject *__pyx_v_self, Py __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_11DenseVector_2__setitem__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((char *)__pyx_v_fname), ((float)__pyx_v_value)); + __pyx_r = __pyx_pf_5_cdec_11DenseVector_4__setitem__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((char *)__pyx_v_fname), ((float)__pyx_v_value)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":12 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":15 * raise KeyError(fname) * * def __setitem__(self, char* fname, float value): # <<<<<<<<<<<<<< - * cdef unsigned fid = FDConvert(fname) - * if self.vector.size() <= fid: + * cdef int fid = FDConvert(fname) + * if fid < 0: raise KeyError(fname) */ -static int __pyx_pf_5_cdec_11DenseVector_2__setitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value) { - unsigned int __pyx_v_fid; +static int __pyx_pf_5_cdec_11DenseVector_4__setitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value) { + int __pyx_v_fid; int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setitem__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":13 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":16 * * def __setitem__(self, char* fname, float value): - * cdef unsigned fid = FDConvert(fname) # <<<<<<<<<<<<<< + * cdef int fid = FDConvert(fname) # <<<<<<<<<<<<<< + * if fid < 0: raise KeyError(fname) * if self.vector.size() <= fid: - * self.vector.resize(fid + 1) */ __pyx_v_fid = FD::Convert(((char *)__pyx_v_fname)); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":14 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":17 * def __setitem__(self, char* fname, float value): - * cdef unsigned fid = FDConvert(fname) + * cdef int fid = FDConvert(fname) + * if fid < 0: raise KeyError(fname) # <<<<<<<<<<<<<< + * if self.vector.size() <= fid: + * self.vector.resize(fid + 1) + */ + __pyx_t_1 = (__pyx_v_fid < 0); + if (__pyx_t_1) { + __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 17; __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[1]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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[1]; __pyx_lineno = 17; __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[1]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":18 + * cdef int fid = FDConvert(fname) + * if fid < 0: raise KeyError(fname) * if self.vector.size() <= fid: # <<<<<<<<<<<<<< * self.vector.resize(fid + 1) * self.vector[0][fid] = value @@ -1364,19 +1461,19 @@ static int __pyx_pf_5_cdec_11DenseVector_2__setitem__(struct __pyx_obj_5_cdec_De __pyx_t_1 = (__pyx_v_self->vector->size() <= __pyx_v_fid); if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":15 - * cdef unsigned fid = FDConvert(fname) + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":19 + * if fid < 0: raise KeyError(fname) * if self.vector.size() <= fid: * self.vector.resize(fid + 1) # <<<<<<<<<<<<<< * self.vector[0][fid] = value * */ __pyx_v_self->vector->resize((__pyx_v_fid + 1)); - goto __pyx_L3; + goto __pyx_L4; } - __pyx_L3:; + __pyx_L4:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":16 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":20 * if self.vector.size() <= fid: * self.vector.resize(fid + 1) * self.vector[0][fid] = value # <<<<<<<<<<<<<< @@ -1386,23 +1483,30 @@ static int __pyx_pf_5_cdec_11DenseVector_2__setitem__(struct __pyx_obj_5_cdec_De ((__pyx_v_self->vector[0])[__pyx_v_fid]) = __pyx_v_value; __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec.DenseVector.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_11DenseVector_6generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5_cdec_11DenseVector_8generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_11DenseVector_5__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_11DenseVector_5__iter__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_11DenseVector_7__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_11DenseVector_7__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_11DenseVector_4__iter__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_11DenseVector_6__iter__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":18 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":22 * self.vector[0][fid] = value * * def __iter__(self): # <<<<<<<<<<<<<< @@ -1410,7 +1514,7 @@ static PyObject *__pyx_pw_5_cdec_11DenseVector_5__iter__(PyObject *__pyx_v_self) * for fid in range(1, self.vector.size()): */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_4__iter__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_11DenseVector_6__iter__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -1428,7 +1532,7 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_4__iter__(struct __pyx_obj_5_cdec __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_11DenseVector_6generator, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_11DenseVector_8generator, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -1446,7 +1550,7 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_4__iter__(struct __pyx_obj_5_cdec return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_11DenseVector_6generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_11DenseVector_8generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; @@ -1465,9 +1569,9 @@ static PyObject *__pyx_gb_5_cdec_11DenseVector_6generator(__pyx_GeneratorObject return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":20 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":24 * def __iter__(self): * cdef unsigned fid * for fid in range(1, self.vector.size()): # <<<<<<<<<<<<<< @@ -1478,18 +1582,18 @@ static PyObject *__pyx_gb_5_cdec_11DenseVector_6generator(__pyx_GeneratorObject for (__pyx_t_2 = 1; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_cur_scope->__pyx_v_fid = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":21 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":25 * cdef unsigned fid * for fid in range(1, self.vector.size()): * yield FDConvert(fid).c_str(), self.vector[0][fid] # <<<<<<<<<<<<<< * * def dot(self, SparseVector other): */ - __pyx_t_3 = PyBytes_FromString(FD::Convert(__pyx_cur_scope->__pyx_v_fid).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 21; __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[1]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_4 = PyFloat_FromDouble(((__pyx_cur_scope->__pyx_v_self->vector[0])[__pyx_cur_scope->__pyx_v_fid])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyFloat_FromDouble(((__pyx_cur_scope->__pyx_v_self->vector[0])[__pyx_cur_scope->__pyx_v_fid])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 25; __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[1]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); @@ -1509,7 +1613,7 @@ static PyObject *__pyx_gb_5_cdec_11DenseVector_6generator(__pyx_GeneratorObject __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[1]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; @@ -1526,13 +1630,13 @@ static PyObject *__pyx_gb_5_cdec_11DenseVector_6generator(__pyx_GeneratorObject } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_11DenseVector_8dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_11DenseVector_8dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_11DenseVector_10dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_11DenseVector_10dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("dot (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_11DenseVector_7dot(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_11DenseVector_9dot(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -1541,7 +1645,7 @@ static PyObject *__pyx_pw_5_cdec_11DenseVector_8dot(PyObject *__pyx_v_self, PyOb return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":23 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":27 * yield FDConvert(fid).c_str(), self.vector[0][fid] * * def dot(self, SparseVector other): # <<<<<<<<<<<<<< @@ -1549,7 +1653,7 @@ static PyObject *__pyx_pw_5_cdec_11DenseVector_8dot(PyObject *__pyx_v_self, PyOb * */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_7dot(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_11DenseVector_9dot(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -1560,7 +1664,7 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_7dot(struct __pyx_obj_5_cdec_Dens int __pyx_clineno = 0; __Pyx_RefNannySetupContext("dot", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":24 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":28 * * def dot(self, SparseVector other): * return other.dot(self) # <<<<<<<<<<<<<< @@ -1568,14 +1672,14 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_7dot(struct __pyx_obj_5_cdec_Dens * def tosparse(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_other), __pyx_n_s__dot); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_other), __pyx_n_s__dot); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; @@ -1598,17 +1702,17 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_7dot(struct __pyx_obj_5_cdec_Dens } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_11DenseVector_10tosparse(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_11DenseVector_10tosparse(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5_cdec_11DenseVector_12tosparse(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_11DenseVector_12tosparse(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("tosparse (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_11DenseVector_9tosparse(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_11DenseVector_11tosparse(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":26 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":30 * return other.dot(self) * * def tosparse(self): # <<<<<<<<<<<<<< @@ -1616,7 +1720,7 @@ static PyObject *__pyx_pw_5_cdec_11DenseVector_10tosparse(PyObject *__pyx_v_self * sparse.vector = new FastSparseVector[weight_t]() */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_9tosparse(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_11DenseVector_11tosparse(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_sparse = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -1626,19 +1730,19 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_9tosparse(struct __pyx_obj_5_cdec int __pyx_clineno = 0; __Pyx_RefNannySetupContext("tosparse", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":27 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":31 * * def tosparse(self): * cdef SparseVector sparse = SparseVector() # <<<<<<<<<<<<<< * sparse.vector = new FastSparseVector[weight_t]() * InitSparseVector(self.vector[0], sparse.vector) */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_sparse = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":28 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":32 * def tosparse(self): * cdef SparseVector sparse = SparseVector() * sparse.vector = new FastSparseVector[weight_t]() # <<<<<<<<<<<<<< @@ -1647,7 +1751,7 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_9tosparse(struct __pyx_obj_5_cdec */ __pyx_v_sparse->vector = new FastSparseVector(); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":29 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":33 * cdef SparseVector sparse = SparseVector() * sparse.vector = new FastSparseVector[weight_t]() * InitSparseVector(self.vector[0], sparse.vector) # <<<<<<<<<<<<<< @@ -1656,7 +1760,7 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_9tosparse(struct __pyx_obj_5_cdec */ Weights::InitSparseVector((__pyx_v_self->vector[0]), __pyx_v_sparse->vector); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":30 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":34 * sparse.vector = new FastSparseVector[weight_t]() * InitSparseVector(self.vector[0], sparse.vector) * return sparse # <<<<<<<<<<<<<< @@ -1682,14 +1786,101 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_9tosparse(struct __pyx_obj_5_cdec } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_1__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_1__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { +static void __pyx_pw_5_cdec_12SparseVector_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_12SparseVector_1__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_12SparseVector___dealloc__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":39 + * cdef FastSparseVector[weight_t]* vector + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.vector + * + */ + +static void __pyx_pf_5_cdec_12SparseVector___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":40 + * + * def __dealloc__(self): + * del self.vector # <<<<<<<<<<<<<< + * + * def copy(self): + */ + delete __pyx_v_self->vector; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_12SparseVector_3copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_3copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("copy (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_2copy(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":42 + * del self.vector + * + * def copy(self): # <<<<<<<<<<<<<< + * return self * 1 + * + */ + +static PyObject *__pyx_pf_5_cdec_12SparseVector_2copy(struct __pyx_obj_5_cdec_SparseVector *__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("copy", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":43 + * + * def copy(self): + * return self * 1 # <<<<<<<<<<<<<< + * + * def __getitem__(self, char* fname): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyNumber_Multiply(((PyObject *)__pyx_v_self), __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_cdec.SparseVector.copy", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_12SparseVector_5__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_5__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { char *__pyx_v_fname; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); assert(__pyx_arg_fname); { - __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __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[1]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -1697,56 +1888,85 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_1__getitem__(PyObject *__pyx_v_s __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12SparseVector___getitem__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_4__getitem__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":35 - * cdef FastSparseVector[weight_t]* vector +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":45 + * return self * 1 * * def __getitem__(self, char* fname): # <<<<<<<<<<<<<< - * cdef unsigned fid = FDConvert(fname) - * return self.vector.value(fid) + * cdef int fid = FDConvert(fname) + * if fid < 0: raise KeyError(fname) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector___getitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname) { - unsigned int __pyx_v_fid; +static PyObject *__pyx_pf_5_cdec_12SparseVector_4__getitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname) { + int __pyx_v_fid; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__getitem__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":36 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":46 * * def __getitem__(self, char* fname): - * cdef unsigned fid = FDConvert(fname) # <<<<<<<<<<<<<< + * cdef int fid = FDConvert(fname) # <<<<<<<<<<<<<< + * if fid < 0: raise KeyError(fname) * return self.vector.value(fid) - * */ __pyx_v_fid = FD::Convert(__pyx_v_fname); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":37 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":47 * def __getitem__(self, char* fname): - * cdef unsigned fid = FDConvert(fname) + * cdef int fid = FDConvert(fname) + * if fid < 0: raise KeyError(fname) # <<<<<<<<<<<<<< + * return self.vector.value(fid) + * + */ + __pyx_t_1 = (__pyx_v_fid < 0); + if (__pyx_t_1) { + __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 47; __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[1]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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[1]; __pyx_lineno = 47; __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[1]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":48 + * cdef int fid = FDConvert(fname) + * if fid < 0: raise KeyError(fname) * return self.vector.value(fid) # <<<<<<<<<<<<<< * * def __setitem__(self, char* fname, float value): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->value(__pyx_v_fid)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_self->vector->value(__pyx_v_fid)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_XDECREF(__pyx_t_3); __Pyx_AddTraceback("_cdec.SparseVector.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -1756,18 +1976,18 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector___getitem__(struct __pyx_obj_5_c } /* Python wrapper */ -static int __pyx_pw_5_cdec_12SparseVector_3__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value); /*proto*/ -static int __pyx_pw_5_cdec_12SparseVector_3__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value) { +static int __pyx_pw_5_cdec_12SparseVector_7__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value); /*proto*/ +static int __pyx_pw_5_cdec_12SparseVector_7__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value) { char *__pyx_v_fname; float __pyx_v_value; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); assert(__pyx_arg_fname); { - __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 39; __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[1]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } assert(__pyx_arg_value); { - __pyx_v_value = __pyx_PyFloat_AsFloat(__pyx_arg_value); if (unlikely((__pyx_v_value == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_value = __pyx_PyFloat_AsFloat(__pyx_arg_value); if (unlikely((__pyx_v_value == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -1775,37 +1995,69 @@ static int __pyx_pw_5_cdec_12SparseVector_3__setitem__(PyObject *__pyx_v_self, P __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12SparseVector_2__setitem__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname), ((float)__pyx_v_value)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_6__setitem__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname), ((float)__pyx_v_value)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":39 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":50 * return self.vector.value(fid) * * def __setitem__(self, char* fname, float value): # <<<<<<<<<<<<<< - * cdef unsigned fid = FDConvert(fname) - * self.vector.set_value(fid, value) + * cdef int fid = FDConvert(fname) + * if fid < 0: raise KeyError(fname) */ -static int __pyx_pf_5_cdec_12SparseVector_2__setitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value) { - unsigned int __pyx_v_fid; +static int __pyx_pf_5_cdec_12SparseVector_6__setitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value) { + int __pyx_v_fid; int __pyx_r; __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setitem__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":40 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":51 * * def __setitem__(self, char* fname, float value): - * cdef unsigned fid = FDConvert(fname) # <<<<<<<<<<<<<< + * cdef int fid = FDConvert(fname) # <<<<<<<<<<<<<< + * if fid < 0: raise KeyError(fname) * self.vector.set_value(fid, value) - * */ __pyx_v_fid = FD::Convert(((char *)__pyx_v_fname)); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":41 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":52 * def __setitem__(self, char* fname, float value): - * cdef unsigned fid = FDConvert(fname) + * cdef int fid = FDConvert(fname) + * if fid < 0: raise KeyError(fname) # <<<<<<<<<<<<<< + * self.vector.set_value(fid, value) + * + */ + __pyx_t_1 = (__pyx_v_fid < 0); + if (__pyx_t_1) { + __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 52; __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[1]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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[1]; __pyx_lineno = 52; __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[1]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":53 + * cdef int fid = FDConvert(fname) + * if fid < 0: raise KeyError(fname) * self.vector.set_value(fid, value) # <<<<<<<<<<<<<< * * def __iter__(self): @@ -1813,31 +2065,38 @@ static int __pyx_pf_5_cdec_12SparseVector_2__setitem__(struct __pyx_obj_5_cdec_S __pyx_v_self->vector->set_value(__pyx_v_fid, __pyx_v_value); __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec.SparseVector.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_12SparseVector_6generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5_cdec_12SparseVector_10generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_5__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_5__iter__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_9__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_9__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_4__iter__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_8__iter__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":43 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":55 * self.vector.set_value(fid, value) * * def __iter__(self): # <<<<<<<<<<<<<< * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) - * cdef str fname + * try: */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_4__iter__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_8__iter__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -1855,7 +2114,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_4__iter__(struct __pyx_obj_5_cde __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12SparseVector_6generator1, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12SparseVector_10generator1, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -1873,7 +2132,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_4__iter__(struct __pyx_obj_5_cde return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_12SparseVector_6generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_12SparseVector_10generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; @@ -1881,99 +2140,133 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_6generator1(__pyx_GeneratorObjec size_t __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_resume_from_yield; + case 1: goto __pyx_L9_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[1]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":44 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":56 * * def __iter__(self): * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) # <<<<<<<<<<<<<< - * cdef str fname - * for i in range(self.vector.size()): + * try: + * for i in range(self.vector.size()): */ __pyx_cur_scope->__pyx_v_it = new FastSparseVector::const_iterator((__pyx_cur_scope->__pyx_v_self->vector[0]), 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":46 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":57 + * def __iter__(self): * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) - * cdef str fname - * for i in range(self.vector.size()): # <<<<<<<<<<<<<< - * fname = FDConvert(it[0].ptr().first).c_str() - * yield (fname, it[0].ptr().second) + * try: # <<<<<<<<<<<<<< + * for i in range(self.vector.size()): + * yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second) */ - __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->vector->size(); - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":47 - * cdef str fname - * for i in range(self.vector.size()): - * fname = FDConvert(it[0].ptr().first).c_str() # <<<<<<<<<<<<<< - * yield (fname, it[0].ptr().second) - * pinc(it[0]) - */ - __pyx_t_3 = PyBytes_FromString(FD::Convert((__pyx_cur_scope->__pyx_v_it[0]).operator->()->first).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_3)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_3))->tp_name), 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fname)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fname)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); - __pyx_cur_scope->__pyx_v_fname = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; + /*try:*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":48 - * for i in range(self.vector.size()): - * fname = FDConvert(it[0].ptr().first).c_str() - * yield (fname, it[0].ptr().second) # <<<<<<<<<<<<<< - * pinc(it[0]) - * - */ - __pyx_t_3 = PyFloat_FromDouble((__pyx_cur_scope->__pyx_v_it[0]).operator->()->second); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_fname)); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_cur_scope->__pyx_v_fname)); - __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_fname)); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_r = ((PyObject *)__pyx_t_4); - __pyx_t_4 = 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_generator->resume_label = 1; - return __pyx_r; - __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[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":58 + * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) + * try: + * for i in range(self.vector.size()): # <<<<<<<<<<<<<< + * yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second) + * pinc(it[0]) # ++it + */ + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->vector->size(); + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":59 + * try: + * for i in range(self.vector.size()): + * yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second) # <<<<<<<<<<<<<< + * pinc(it[0]) # ++it + * finally: + */ + __pyx_t_3 = PyBytes_FromString(FD::Convert((__pyx_cur_scope->__pyx_v_it[0]).operator->()->first).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_t_4 = PyFloat_FromDouble((__pyx_cur_scope->__pyx_v_it[0]).operator->()->second); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_3)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_3 = 0; + __pyx_t_4 = 0; + __pyx_r = ((PyObject *)__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_generator->resume_label = 1; + return __pyx_r; + __pyx_L9_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[1]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L5;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":60 + * for i in range(self.vector.size()): + * yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second) + * pinc(it[0]) # ++it # <<<<<<<<<<<<<< + * finally: + * del it + */ + (++(__pyx_cur_scope->__pyx_v_it[0])); + } + } - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":49 - * fname = FDConvert(it[0].ptr().first).c_str() - * yield (fname, it[0].ptr().second) - * pinc(it[0]) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":62 + * pinc(it[0]) # ++it + * finally: + * del it # <<<<<<<<<<<<<< * * def dot(self, other): */ - (++(__pyx_cur_scope->__pyx_v_it[0])); + /*finally:*/ { + int __pyx_why; + PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; + int __pyx_exc_lineno; + __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; + __pyx_why = 0; goto __pyx_L6; + __pyx_L5: { + __pyx_why = 4; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); + __pyx_exc_lineno = __pyx_lineno; + goto __pyx_L6; + } + __pyx_L6:; + delete __pyx_cur_scope->__pyx_v_it; + switch (__pyx_why) { + case 4: { + __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); + __pyx_lineno = __pyx_exc_lineno; + __pyx_exc_type = 0; + __pyx_exc_value = 0; + __pyx_exc_tb = 0; + goto __pyx_L1_error; + } + } } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; __Pyx_XDECREF(__pyx_r); @@ -1983,25 +2276,25 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_6generator1(__pyx_GeneratorObjec } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_8dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_8dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_12dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_12dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("dot (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_7dot(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((PyObject *)__pyx_v_other)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_11dot(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((PyObject *)__pyx_v_other)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":51 - * pinc(it[0]) +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":64 + * del it * * def dot(self, other): # <<<<<<<<<<<<<< * if isinstance(other, DenseVector): * return self.vector.dot(( other).vector[0]) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -2012,7 +2305,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa int __pyx_clineno = 0; __Pyx_RefNannySetupContext("dot", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":52 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":65 * * def dot(self, other): * if isinstance(other, DenseVector): # <<<<<<<<<<<<<< @@ -2025,7 +2318,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":53 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":66 * def dot(self, other): * if isinstance(other, DenseVector): * return self.vector.dot(( other).vector[0]) # <<<<<<<<<<<<<< @@ -2033,7 +2326,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa * return self.vector.dot(( other).vector[0]) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->dot((((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_other)->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->dot((((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_other)->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2041,7 +2334,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa goto __pyx_L3; } - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":54 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":67 * if isinstance(other, DenseVector): * return self.vector.dot(( other).vector[0]) * elif isinstance(other, SparseVector): # <<<<<<<<<<<<<< @@ -2054,7 +2347,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":55 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":68 * return self.vector.dot(( other).vector[0]) * elif isinstance(other, SparseVector): * return self.vector.dot(( other).vector[0]) # <<<<<<<<<<<<<< @@ -2062,7 +2355,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->dot((((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->dot((((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2071,26 +2364,26 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":56 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":69 * elif isinstance(other, SparseVector): * return self.vector.dot(( other).vector[0]) * raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) # <<<<<<<<<<<<<< * - * def todense(self): + * def __richcmp__(SparseVector x, SparseVector y, int op): */ - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), ((PyObject *)Py_TYPE(__pyx_v_other))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), ((PyObject *)Py_TYPE(__pyx_v_other))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; @@ -2106,98 +2399,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_10todense(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_10todense(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("todense (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_9todense(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":58 - * raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) - * - * def todense(self): # <<<<<<<<<<<<<< - * cdef DenseVector dense = DenseVector() - * dense.vector = new vector[weight_t]() - */ - -static PyObject *__pyx_pf_5_cdec_12SparseVector_9todense(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { - struct __pyx_obj_5_cdec_DenseVector *__pyx_v_dense = 0; - 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("todense", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":59 - * - * def todense(self): - * cdef DenseVector dense = DenseVector() # <<<<<<<<<<<<<< - * dense.vector = new vector[weight_t]() - * self.vector.init_vector(dense.vector) - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_dense = ((struct __pyx_obj_5_cdec_DenseVector *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":60 - * def todense(self): - * cdef DenseVector dense = DenseVector() - * dense.vector = new vector[weight_t]() # <<<<<<<<<<<<<< - * self.vector.init_vector(dense.vector) - * return dense - */ - __pyx_v_dense->vector = new std::vector(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":61 - * cdef DenseVector dense = DenseVector() - * dense.vector = new vector[weight_t]() - * self.vector.init_vector(dense.vector) # <<<<<<<<<<<<<< - * return dense - * - */ - __pyx_v_self->vector->init_vector(__pyx_v_dense->vector); - - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":62 - * dense.vector = new vector[weight_t]() - * self.vector.init_vector(dense.vector) - * return dense # <<<<<<<<<<<<<< - * - * def __richcmp__(SparseVector x, SparseVector y, int op): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_dense)); - __pyx_r = ((PyObject *)__pyx_v_dense); - 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.SparseVector.todense", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_dense); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_12__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_12__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_14__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_14__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_11__richcmp__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y), ((int)__pyx_v_op)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_13__richcmp__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y), ((int)__pyx_v_op)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2206,15 +2415,15 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_12__richcmp__(PyObject *__pyx_v_ return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":64 - * return dense +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":71 + * raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) * * def __richcmp__(SparseVector x, SparseVector y, int op): # <<<<<<<<<<<<<< * if op == 2: # == * return x.vector[0] == y.vector[0] */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y, int __pyx_v_op) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y, int __pyx_v_op) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -2224,7 +2433,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__richcmp__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":67 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":74 * if op == 2: # == * return x.vector[0] == y.vector[0] * elif op == 3: # != # <<<<<<<<<<<<<< @@ -2233,7 +2442,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 */ switch (__pyx_v_op) { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":65 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":72 * * def __richcmp__(SparseVector x, SparseVector y, int op): * if op == 2: # == # <<<<<<<<<<<<<< @@ -2242,7 +2451,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 */ case 2: - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":66 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":73 * def __richcmp__(SparseVector x, SparseVector y, int op): * if op == 2: # == * return x.vector[0] == y.vector[0] # <<<<<<<<<<<<<< @@ -2250,14 +2459,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 * return not (x == y) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_x->vector[0]) == (__pyx_v_y->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_x->vector[0]) == (__pyx_v_y->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; break; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":67 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":74 * if op == 2: # == * return x.vector[0] == y.vector[0] * elif op == 3: # != # <<<<<<<<<<<<<< @@ -2266,7 +2475,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 */ case 3: - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":68 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":75 * return x.vector[0] == y.vector[0] * elif op == 3: # != * return not (x == y) # <<<<<<<<<<<<<< @@ -2274,11 +2483,11 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2286,18 +2495,18 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 break; } - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":69 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":76 * elif op == 3: # != * return not (x == y) * raise NotImplemented('comparison not implemented for SparseVector') # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_t_1 = PyObject_Call(__pyx_builtin_NotImplemented, ((PyObject *)__pyx_k_tuple_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_NotImplemented, ((PyObject *)__pyx_k_tuple_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; @@ -2312,17 +2521,17 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 } /* Python wrapper */ -static Py_ssize_t __pyx_pw_5_cdec_12SparseVector_14__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_5_cdec_12SparseVector_14__len__(PyObject *__pyx_v_self) { +static Py_ssize_t __pyx_pw_5_cdec_12SparseVector_16__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_12SparseVector_16__len__(PyObject *__pyx_v_self) { Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_13__len__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_15__len__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":71 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":78 * raise NotImplemented('comparison not implemented for SparseVector') * * def __len__(self): # <<<<<<<<<<<<<< @@ -2330,12 +2539,12 @@ static Py_ssize_t __pyx_pw_5_cdec_12SparseVector_14__len__(PyObject *__pyx_v_sel * */ -static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_13__len__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { +static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_15__len__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__len__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":72 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":79 * * def __len__(self): * return self.vector.size() # <<<<<<<<<<<<<< @@ -2352,14 +2561,14 @@ static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_13__len__(struct __pyx_obj_5_cd } /* Python wrapper */ -static int __pyx_pw_5_cdec_12SparseVector_16__contains__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ -static int __pyx_pw_5_cdec_12SparseVector_16__contains__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { +static int __pyx_pw_5_cdec_12SparseVector_18__contains__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ +static int __pyx_pw_5_cdec_12SparseVector_18__contains__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { char *__pyx_v_fname; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0); assert(__pyx_arg_fname); { - __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 74; __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[1]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -2367,12 +2576,12 @@ static int __pyx_pw_5_cdec_12SparseVector_16__contains__(PyObject *__pyx_v_self, __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12SparseVector_15__contains__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_17__contains__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":74 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":81 * return self.vector.size() * * def __contains__(self, char* fname): # <<<<<<<<<<<<<< @@ -2380,12 +2589,12 @@ static int __pyx_pw_5_cdec_12SparseVector_16__contains__(PyObject *__pyx_v_self, * */ -static int __pyx_pf_5_cdec_12SparseVector_15__contains__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname) { +static int __pyx_pf_5_cdec_12SparseVector_17__contains__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__contains__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":75 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":82 * * def __contains__(self, char* fname): * return self.vector.nonzero(FDConvert(fname)) # <<<<<<<<<<<<<< @@ -2402,13 +2611,13 @@ static int __pyx_pf_5_cdec_12SparseVector_15__contains__(struct __pyx_obj_5_cdec } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_18__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_18__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_20__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_20__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iadd__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_17__iadd__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_19__iadd__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2417,7 +2626,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_18__iadd__(PyObject *__pyx_v_sel return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":77 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":84 * return self.vector.nonzero(FDConvert(fname)) * * def __iadd__(SparseVector self, SparseVector other): # <<<<<<<<<<<<<< @@ -2425,12 +2634,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_18__iadd__(PyObject *__pyx_v_sel * return self */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_17__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_19__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iadd__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":78 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":85 * * def __iadd__(SparseVector self, SparseVector other): * self.vector[0] += other.vector[0] # <<<<<<<<<<<<<< @@ -2439,7 +2648,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_17__iadd__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) += (__pyx_v_other->vector[0]); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":79 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":86 * def __iadd__(SparseVector self, SparseVector other): * self.vector[0] += other.vector[0] * return self # <<<<<<<<<<<<<< @@ -2459,13 +2668,13 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_17__iadd__(struct __pyx_obj_5_cd } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_20__isub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_20__isub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_22__isub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_22__isub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__isub__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_19__isub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_21__isub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2474,7 +2683,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_20__isub__(PyObject *__pyx_v_sel return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":81 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":88 * return self * * def __isub__(SparseVector self, SparseVector other): # <<<<<<<<<<<<<< @@ -2482,12 +2691,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_20__isub__(PyObject *__pyx_v_sel * return self */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_19__isub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_21__isub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__isub__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":82 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":89 * * def __isub__(SparseVector self, SparseVector other): * self.vector[0] -= other.vector[0] # <<<<<<<<<<<<<< @@ -2496,7 +2705,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_19__isub__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) -= (__pyx_v_other->vector[0]); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":83 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":90 * def __isub__(SparseVector self, SparseVector other): * self.vector[0] -= other.vector[0] * return self # <<<<<<<<<<<<<< @@ -2516,14 +2725,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_19__isub__(struct __pyx_obj_5_cd } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_22__imul__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_22__imul__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_24__imul__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_24__imul__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar) { float __pyx_v_scalar; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__imul__ (wrapper)", 0); assert(__pyx_arg_scalar); { - __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -2531,12 +2740,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_22__imul__(PyObject *__pyx_v_sel __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12SparseVector_21__imul__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((float)__pyx_v_scalar)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_23__imul__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((float)__pyx_v_scalar)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":85 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":92 * return self * * def __imul__(SparseVector self, float scalar): # <<<<<<<<<<<<<< @@ -2544,12 +2753,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_22__imul__(PyObject *__pyx_v_sel * return self */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_21__imul__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_23__imul__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__imul__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":86 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":93 * * def __imul__(SparseVector self, float scalar): * self.vector[0] *= scalar # <<<<<<<<<<<<<< @@ -2558,7 +2767,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_21__imul__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) *= __pyx_v_scalar; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":87 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":94 * def __imul__(SparseVector self, float scalar): * self.vector[0] *= scalar * return self # <<<<<<<<<<<<<< @@ -2579,14 +2788,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_21__imul__(struct __pyx_obj_5_cd /* Python wrapper */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pw_5_cdec_12SparseVector_24__idiv__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_24__idiv__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_26__idiv__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_26__idiv__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar) { float __pyx_v_scalar; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__idiv__ (wrapper)", 0); assert(__pyx_arg_scalar); { - __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -2594,13 +2803,13 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_24__idiv__(PyObject *__pyx_v_sel __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12SparseVector_23__idiv__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((float)__pyx_v_scalar)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_25__idiv__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((float)__pyx_v_scalar)); __Pyx_RefNannyFinishContext(); return __pyx_r; } #endif /*!(#if PY_MAJOR_VERSION < 3)*/ -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":89 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":96 * return self * * def __idiv__(SparseVector self, float scalar): # <<<<<<<<<<<<<< @@ -2609,12 +2818,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_24__idiv__(PyObject *__pyx_v_sel */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pf_5_cdec_12SparseVector_23__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_25__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__idiv__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":90 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":97 * * def __idiv__(SparseVector self, float scalar): * self.vector[0] /= scalar # <<<<<<<<<<<<<< @@ -2623,7 +2832,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_23__idiv__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) /= __pyx_v_scalar; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":91 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":98 * def __idiv__(SparseVector self, float scalar): * self.vector[0] /= scalar * return self # <<<<<<<<<<<<<< @@ -2644,14 +2853,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_23__idiv__(struct __pyx_obj_5_cd #endif /*!(#if PY_MAJOR_VERSION < 3)*/ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_28__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_28__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__add__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_25__add__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_27__add__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2660,7 +2869,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_x, P return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":93 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":100 * return self * * def __add__(SparseVector x, SparseVector y): # <<<<<<<<<<<<<< @@ -2668,7 +2877,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_x, P * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_27__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -2678,19 +2887,19 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__add__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":94 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":101 * * def __add__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":95 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":102 * def __add__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) # <<<<<<<<<<<<<< @@ -2699,7 +2908,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cde */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_x->vector[0]) + (__pyx_v_y->vector[0]))); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":96 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":103 * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) * return result # <<<<<<<<<<<<<< @@ -2725,14 +2934,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cde } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_30__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_30__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__sub__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_27__sub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_29__sub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2741,7 +2950,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_x, P return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":98 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":105 * return result * * def __sub__(SparseVector x, SparseVector y): # <<<<<<<<<<<<<< @@ -2749,7 +2958,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_x, P * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_29__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -2759,19 +2968,19 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__sub__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":99 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":106 * * def __sub__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":100 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":107 * def __sub__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) # <<<<<<<<<<<<<< @@ -2780,7 +2989,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cde */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_x->vector[0]) - (__pyx_v_y->vector[0]))); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":101 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":108 * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) * return result # <<<<<<<<<<<<<< @@ -2806,17 +3015,17 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cde } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_30__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_30__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_32__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_32__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__mul__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_29__mul__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_31__mul__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":103 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":110 * return result * * def __mul__(x, y): # <<<<<<<<<<<<<< @@ -2824,7 +3033,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_30__mul__(PyObject *__pyx_v_x, P * cdef float scalar */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_29__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_31__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_vector = 0; float __pyx_v_scalar; struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; @@ -2838,7 +3047,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_29__mul__(PyObject *__pyx_v_x, P int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__mul__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":106 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":113 * cdef SparseVector vector * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y # <<<<<<<<<<<<<< @@ -2850,10 +3059,10 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_29__mul__(PyObject *__pyx_v_x, P __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_x; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; @@ -2861,36 +3070,36 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_29__mul__(PyObject *__pyx_v_x, P } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":107 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":114 * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x # <<<<<<<<<<<<<< * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) */ - if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_y; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":108 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":115 * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":109 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":116 * else: vector, scalar = y, x * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) # <<<<<<<<<<<<<< @@ -2899,7 +3108,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_29__mul__(PyObject *__pyx_v_x, P */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_vector->vector[0]) * __pyx_v_scalar)); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":110 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":117 * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) * return result # <<<<<<<<<<<<<< @@ -2927,18 +3136,18 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_29__mul__(PyObject *__pyx_v_x, P /* Python wrapper */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pw_5_cdec_12SparseVector_32__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_32__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_34__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_34__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__div__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_31__div__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_33__div__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); __Pyx_RefNannyFinishContext(); return __pyx_r; } #endif /*!(#if PY_MAJOR_VERSION < 3)*/ -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":112 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":119 * return result * * def __div__(x, y): # <<<<<<<<<<<<<< @@ -2947,7 +3156,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_32__div__(PyObject *__pyx_v_x, P */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pf_5_cdec_12SparseVector_31__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_33__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_vector = 0; float __pyx_v_scalar; struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; @@ -2961,7 +3170,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_31__div__(PyObject *__pyx_v_x, P int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__div__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":115 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":122 * cdef SparseVector vector * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y # <<<<<<<<<<<<<< @@ -2973,10 +3182,10 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_31__div__(PyObject *__pyx_v_x, P __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_x; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; @@ -2984,36 +3193,36 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_31__div__(PyObject *__pyx_v_x, P } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":116 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":123 * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x # <<<<<<<<<<<<<< * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) */ - if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_y; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":117 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":124 * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":118 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":125 * else: vector, scalar = y, x * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) # <<<<<<<<<<<<<< @@ -3021,7 +3230,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_31__div__(PyObject *__pyx_v_x, P */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_vector->vector[0]) / __pyx_v_scalar)); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":119 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":126 * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) * return result # <<<<<<<<<<<<<< @@ -3481,7 +3690,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_12generator2(__pyx_GeneratorObject __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L7_resume_from_yield; + case 1: goto __pyx_L10_resume_from_yield; default: /* CPython raises the right error here */ __Pyx_RefNannyFinishContext(); return NULL; @@ -3494,97 +3703,132 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_12generator2(__pyx_GeneratorObject * def kbest(self, size): * 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 sentence + * cdef bytes 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[2]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,ESentenceTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":37 - * cdef str sentence + * cdef bytes sentence * cdef unsigned k - * for k in range(size): # <<<<<<<<<<<<<< - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break + * try: # <<<<<<<<<<<<<< + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) */ - __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[2]; __pyx_lineno = 37; __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; + /*try:*/ { /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":38 * 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((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":39 - * 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:; + * try: + * 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[2]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L5;} + for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { + __pyx_cur_scope->__pyx_v_k = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":39 + * try: + * 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((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":40 + * 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_L8_break; + goto __pyx_L9; + } + __pyx_L9:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":40 - * 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 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":41 + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break + * sentence = GetString(derivation._yield).c_str() # <<<<<<<<<<<<<< + * yield sentence.decode('utf8') + * finally: */ - __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[2]; __pyx_lineno = 40; __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[2]; __pyx_lineno = 40; __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; + __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[2]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __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 = __pyx_t_4; + __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":41 - * if not derivation: break - * sentence = GetString(derivation._yield).c_str() - * yield sentence.decode('utf8') # <<<<<<<<<<<<<< - * del derivations - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":42 + * if not derivation: break + * sentence = GetString(derivation._yield).c_str() + * yield sentence.decode('utf8') # <<<<<<<<<<<<<< + * finally: + * 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[2]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 41; __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_generator->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[2]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __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[2]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L5;} + __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_generator->resume_label = 1; + return __pyx_r; + __pyx_L10_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[2]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L5;} + } + __pyx_L8_break:; } - __pyx_L5_break:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":42 - * sentence = GetString(derivation._yield).c_str() - * yield sentence.decode('utf8') - * del derivations # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":44 + * yield sentence.decode('utf8') + * finally: + * del derivations # <<<<<<<<<<<<<< * * def kbest_tree(self, size): */ - delete __pyx_cur_scope->__pyx_v_derivations; + /*finally:*/ { + int __pyx_why; + PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; + int __pyx_exc_lineno; + __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; + __pyx_why = 0; goto __pyx_L6; + __pyx_L5: { + __pyx_why = 4; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); + __pyx_exc_lineno = __pyx_lineno; + goto __pyx_L6; + } + __pyx_L6:; + delete __pyx_cur_scope->__pyx_v_derivations; + switch (__pyx_why) { + case 4: { + __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); + __pyx_lineno = __pyx_exc_lineno; + __pyx_exc_type = 0; + __pyx_exc_value = 0; + __pyx_exc_tb = 0; + goto __pyx_L1_error; + } + } + } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; @@ -3610,8 +3854,8 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_14kbest_tree(PyObject *__pyx_v_sel return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":44 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":46 + * del derivations * * def kbest_tree(self, size): # <<<<<<<<<<<<<< * cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ETreeTraversal](self.hg[0], size) @@ -3639,7 +3883,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_13kbest_tree(struct __pyx_obj_5_cd __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_15generator3, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_15generator3, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -3670,110 +3914,146 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator3(__pyx_GeneratorObject __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L7_resume_from_yield; + case 1: goto __pyx_L10_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[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":45 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":47 * * def kbest_tree(self, size): * 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 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[2]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __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[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,ETreeTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":49 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":51 * cdef str tree * cdef unsigned k - * for k in range(size): # <<<<<<<<<<<<<< - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break + * try: # <<<<<<<<<<<<<< + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) */ - __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[2]; __pyx_lineno = 49; __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; + /*try:*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":50 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":52 * 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((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":51 - * 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:; + * try: + * 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[2]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L5;} + for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { + __pyx_cur_scope->__pyx_v_k = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":53 + * try: + * 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((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":54 + * 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_L8_break; + goto __pyx_L9; + } + __pyx_L9:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":52 - * 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 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":55 + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break + * tree = GetString(derivation._yield).c_str() # <<<<<<<<<<<<<< + * yield tree.decode('utf8') + * finally: */ - __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[2]; __pyx_lineno = 52; __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[2]; __pyx_lineno = 52; __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; + __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[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L5;} + __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[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L5;} + __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; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":53 - * if not derivation: break - * tree = GetString(derivation._yield).c_str() - * yield tree.decode('utf8') # <<<<<<<<<<<<<< - * del derivations - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 + * if not derivation: break + * tree = GetString(derivation._yield).c_str() + * yield tree.decode('utf8') # <<<<<<<<<<<<<< + * finally: + * 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[2]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 53; __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_generator->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[2]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __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[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L5;} + __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_generator->resume_label = 1; + return __pyx_r; + __pyx_L10_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[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L5;} + } + __pyx_L8_break:; } - __pyx_L5_break:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":54 - * tree = GetString(derivation._yield).c_str() - * yield tree.decode('utf8') - * del derivations # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":58 + * yield tree.decode('utf8') + * finally: + * del derivations # <<<<<<<<<<<<<< * * def kbest_features(self, size): */ - delete __pyx_cur_scope->__pyx_v_derivations; + /*finally:*/ { + int __pyx_why; + PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; + int __pyx_exc_lineno; + __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; + __pyx_why = 0; goto __pyx_L6; + __pyx_L5: { + __pyx_why = 4; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); + __pyx_exc_lineno = __pyx_lineno; + goto __pyx_L6; + } + __pyx_L6:; + delete __pyx_cur_scope->__pyx_v_derivations; + switch (__pyx_why) { + case 4: { + __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); + __pyx_lineno = __pyx_exc_lineno; + __pyx_exc_type = 0; + __pyx_exc_value = 0; + __pyx_exc_tb = 0; + goto __pyx_L1_error; + } + } + } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; @@ -3799,8 +4079,8 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_17kbest_features(PyObject *__pyx_v return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":60 + * del derivations * * def kbest_features(self, size): # <<<<<<<<<<<<<< * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) @@ -3828,7 +4108,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_16kbest_features(struct __pyx_obj_ __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_18generator4, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_18generator4, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -3858,113 +4138,148 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L7_resume_from_yield; + case 1: goto __pyx_L10_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[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":57 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":61 * * def kbest_features(self, size): * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) # <<<<<<<<<<<<<< * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal].Derivation* derivation * cdef SparseVector fmap */ - __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[2]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __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[2]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,FeatureVectorTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":61 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":65 * cdef SparseVector fmap * cdef unsigned k - * for k in range(size): # <<<<<<<<<<<<<< - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break + * try: # <<<<<<<<<<<<<< + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) */ - __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[2]; __pyx_lineno = 61; __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; + /*try:*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":62 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":66 * cdef unsigned k - * for k in range(size): - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< - * if not derivation: break - * fmap = SparseVector() - */ - __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":63 - * for k in range(size): - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break # <<<<<<<<<<<<<< - * fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](derivation._yield) - */ - __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0)); - if (__pyx_t_3) { - goto __pyx_L5_break; - goto __pyx_L6; - } - __pyx_L6:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":64 - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break - * fmap = SparseVector() # <<<<<<<<<<<<<< - * fmap.vector = new FastSparseVector[weight_t](derivation._yield) - * yield fmap - */ - __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_cur_scope->__pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_4); - __pyx_t_4 = 0; + * try: + * 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[2]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L5;} + for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { + __pyx_cur_scope->__pyx_v_k = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":67 + * try: + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< + * if not derivation: break + * fmap = SparseVector() + */ + __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":68 + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break # <<<<<<<<<<<<<< + * fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) + */ + __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0)); + if (__pyx_t_3) { + goto __pyx_L8_break; + goto __pyx_L9; + } + __pyx_L9:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":65 - * if not derivation: break - * fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](derivation._yield) # <<<<<<<<<<<<<< - * yield fmap - * del derivations + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":69 + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break + * fmap = SparseVector() # <<<<<<<<<<<<<< + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) + * yield fmap */ - __pyx_cur_scope->__pyx_v_fmap->vector = new FastSparseVector(__pyx_cur_scope->__pyx_v_derivation->yield); + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_cur_scope->__pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_4); + __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":66 - * fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](derivation._yield) - * yield fmap # <<<<<<<<<<<<<< - * del derivations - * - */ - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); - __pyx_r = ((PyObject *)__pyx_cur_scope->__pyx_v_fmap); - __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_generator->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[2]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":70 + * if not derivation: break + * fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) # <<<<<<<<<<<<<< + * yield fmap + * finally: + */ + __pyx_cur_scope->__pyx_v_fmap->vector = new FastSparseVector(__pyx_cur_scope->__pyx_v_derivation->yield); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":71 + * fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) + * yield fmap # <<<<<<<<<<<<<< + * finally: + * del derivations + */ + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); + __pyx_r = ((PyObject *)__pyx_cur_scope->__pyx_v_fmap); + __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_generator->resume_label = 1; + return __pyx_r; + __pyx_L10_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[2]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L5;} + } + __pyx_L8_break:; } - __pyx_L5_break:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":67 - * fmap.vector = new FastSparseVector[weight_t](derivation._yield) - * yield fmap - * del derivations # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":73 + * yield fmap + * finally: + * del derivations # <<<<<<<<<<<<<< * * def sample(self, unsigned n): */ - delete __pyx_cur_scope->__pyx_v_derivations; + /*finally:*/ { + int __pyx_why; + PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; + int __pyx_exc_lineno; + __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; + __pyx_why = 0; goto __pyx_L6; + __pyx_L5: { + __pyx_why = 4; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); + __pyx_exc_lineno = __pyx_lineno; + goto __pyx_L6; + } + __pyx_L6:; + delete __pyx_cur_scope->__pyx_v_derivations; + switch (__pyx_why) { + case 4: { + __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); + __pyx_lineno = __pyx_exc_lineno; + __pyx_exc_type = 0; + __pyx_exc_value = 0; + __pyx_exc_tb = 0; + goto __pyx_L1_error; + } + } + } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; @@ -3986,7 +4301,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_20sample(PyObject *__pyx_v_self, P __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("sample (wrapper)", 0); assert(__pyx_arg_n); { - __pyx_v_n = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_n); if (unlikely((__pyx_v_n == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_n = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_n); if (unlikely((__pyx_v_n == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -3999,8 +4314,8 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_20sample(PyObject *__pyx_v_self, P return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":69 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":75 + * del derivations * * def sample(self, unsigned n): # <<<<<<<<<<<<<< * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() @@ -4026,7 +4341,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_19sample(struct __pyx_obj_5_cdec_H __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __pyx_cur_scope->__pyx_v_n = __pyx_v_n; { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_21generator5, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_21generator5, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -4057,15 +4372,15 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L7_resume_from_yield; + case 1: goto __pyx_L10_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[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":70 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":76 * * def sample(self, unsigned n): * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() # <<<<<<<<<<<<<< @@ -4074,7 +4389,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject */ __pyx_cur_scope->__pyx_v_hypos = new std::vector(); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":71 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":77 * def sample(self, unsigned n): * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() * if self.rng == NULL: # <<<<<<<<<<<<<< @@ -4084,7 +4399,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->rng == NULL); if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":72 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":78 * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() * if self.rng == NULL: * self.rng = new MT19937() # <<<<<<<<<<<<<< @@ -4096,7 +4411,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject } __pyx_L4:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":73 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":79 * if self.rng == NULL: * self.rng = new MT19937() * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) # <<<<<<<<<<<<<< @@ -4105,68 +4420,104 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject */ HypergraphSampler::sample_hypotheses((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_cur_scope->__pyx_v_n, __pyx_cur_scope->__pyx_v_self->rng, __pyx_cur_scope->__pyx_v_hypos); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":76 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":82 * cdef str sentence * cdef unsigned k - * for k in range(hypos.size()): # <<<<<<<<<<<<<< - * sentence = GetString(hypos[0][k].words).c_str() - * yield sentence.decode('utf8') + * try: # <<<<<<<<<<<<<< + * for k in range(hypos.size()): + * sentence = GetString(hypos[0][k].words).c_str() */ - __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; + /*try:*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":77 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":83 * 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[2]; __pyx_lineno = 77; __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[2]; __pyx_lineno = 77; __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; + * try: + * 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; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":84 + * try: + * for k in range(hypos.size()): + * sentence = GetString(hypos[0][k].words).c_str() # <<<<<<<<<<<<<< + * yield sentence.decode('utf8') + * finally: + */ + __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[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} + __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[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} + __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; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":78 - * for k in range(hypos.size()): - * sentence = GetString(hypos[0][k].words).c_str() - * yield sentence.decode('utf8') # <<<<<<<<<<<<<< - * del hypos - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":85 + * for k in range(hypos.size()): + * sentence = GetString(hypos[0][k].words).c_str() + * yield sentence.decode('utf8') # <<<<<<<<<<<<<< + * finally: + * 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[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 78; __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_generator->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[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __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[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L6;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L6;} + __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_generator->resume_label = 1; + return __pyx_r; + __pyx_L10_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[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L6;} + } } - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":79 - * sentence = GetString(hypos[0][k].words).c_str() - * yield sentence.decode('utf8') - * del hypos # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":87 + * yield sentence.decode('utf8') + * finally: + * del hypos # <<<<<<<<<<<<<< * * # TODO richer k-best/sample output (feature vectors, trees?) */ - delete __pyx_cur_scope->__pyx_v_hypos; + /*finally:*/ { + int __pyx_why; + PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; + int __pyx_exc_lineno; + __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; + __pyx_why = 0; goto __pyx_L7; + __pyx_L6: { + __pyx_why = 4; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); + __pyx_exc_lineno = __pyx_lineno; + goto __pyx_L7; + } + __pyx_L7:; + delete __pyx_cur_scope->__pyx_v_hypos; + switch (__pyx_why) { + case 4: { + __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); + __pyx_lineno = __pyx_exc_lineno; + __pyx_exc_type = 0; + __pyx_exc_value = 0; + __pyx_exc_tb = 0; + goto __pyx_L1_error; + } + } + } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; @@ -4186,7 +4537,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_23intersect(PyObject *__pyx_v_self PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("intersect (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lat), __pyx_ptype_5_cdec_Lattice, 1, "lat", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lat), __pyx_ptype_5_cdec_Lattice, 1, "lat", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = __pyx_pf_5_cdec_10Hypergraph_22intersect(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_lat)); goto __pyx_L0; __pyx_L1_error:; @@ -4196,7 +4547,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_23intersect(PyObject *__pyx_v_self return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":83 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":91 * # TODO richer k-best/sample output (feature vectors, trees?) * * def intersect(self, Lattice lat): # <<<<<<<<<<<<<< @@ -4213,7 +4564,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_22intersect(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("intersect", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":84 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":92 * * def intersect(self, Lattice lat): * return hypergraph.Intersect(lat.lattice[0], self.hg) # <<<<<<<<<<<<<< @@ -4221,7 +4572,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_22intersect(struct __pyx_obj_5_cde * def prune(self, beam_alpha=0, density=0, **kwargs): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(HG::Intersect((__pyx_v_lat->lattice[0]), __pyx_v_self->hg)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyBool_FromLong(HG::Intersect((__pyx_v_lat->lattice[0]), __pyx_v_self->hg)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -4278,7 +4629,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_25prune(PyObject *__pyx_v_self, Py } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "prune") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "prune") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -4293,7 +4644,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_25prune(PyObject *__pyx_v_self, Py } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("prune", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("prune", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; __Pyx_AddTraceback("_cdec.Hypergraph.prune", __pyx_clineno, __pyx_lineno, __pyx_filename); @@ -4306,7 +4657,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_25prune(PyObject *__pyx_v_self, Py return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":86 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":94 * return hypergraph.Intersect(lat.lattice[0], self.hg) * * def prune(self, beam_alpha=0, density=0, **kwargs): # <<<<<<<<<<<<<< @@ -4326,7 +4677,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_24prune(struct __pyx_obj_5_cdec_Hy int __pyx_clineno = 0; __Pyx_RefNannySetupContext("prune", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":87 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":95 * * def prune(self, beam_alpha=0, density=0, **kwargs): * cdef hypergraph.EdgeMask* preserve_mask = NULL # <<<<<<<<<<<<<< @@ -4335,17 +4686,17 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_24prune(struct __pyx_obj_5_cdec_Hy */ __pyx_v_preserve_mask = NULL; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":88 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":96 * def prune(self, beam_alpha=0, density=0, **kwargs): * cdef hypergraph.EdgeMask* preserve_mask = NULL * if 'csplit_preserve_full_word' in kwargs: # <<<<<<<<<<<<<< * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True */ - __pyx_t_1 = ((PyDict_Contains(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s_10)))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = ((PyDict_Contains(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s_10)))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":89 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":97 * cdef hypergraph.EdgeMask* preserve_mask = NULL * if 'csplit_preserve_full_word' in kwargs: * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) # <<<<<<<<<<<<<< @@ -4354,28 +4705,50 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_24prune(struct __pyx_obj_5_cdec_Hy */ __pyx_v_preserve_mask = new std::vector(__pyx_v_self->hg->edges_.size()); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":90 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":98 * if 'csplit_preserve_full_word' in kwargs: * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True # <<<<<<<<<<<<<< * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) - * + * if preserve_mask: */ ((__pyx_v_preserve_mask[0])[CompoundSplit::GetFullWordEdgeIndex((__pyx_v_self->hg[0]))]) = 1; goto __pyx_L3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":91 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":99 * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) # <<<<<<<<<<<<<< + * if preserve_mask: + * del preserve_mask + */ + __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_beam_alpha); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_density); if (unlikely((__pyx_t_3 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->hg->PruneInsideOutside(__pyx_t_2, __pyx_t_3, __pyx_v_preserve_mask, 0, 1.0, 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":100 + * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True + * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) + * if preserve_mask: # <<<<<<<<<<<<<< + * del preserve_mask + * + */ + __pyx_t_1 = (__pyx_v_preserve_mask != 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":101 + * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) + * if preserve_mask: + * del preserve_mask # <<<<<<<<<<<<<< * * def lattice(self): # TODO direct hg -> lattice conversion in cdec */ - __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_beam_alpha); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_density); if (unlikely((__pyx_t_3 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->hg->PruneInsideOutside(__pyx_t_2, __pyx_t_3, __pyx_v_preserve_mask, 0, 1.0, 0); + delete __pyx_v_preserve_mask; + goto __pyx_L4; + } + __pyx_L4:; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; @@ -4399,8 +4772,8 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_27lattice(PyObject *__pyx_v_self, return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":93 - * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":103 + * del preserve_mask * * def lattice(self): # TODO direct hg -> lattice conversion in cdec # <<<<<<<<<<<<<< * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() @@ -4419,20 +4792,20 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_26lattice(struct __pyx_obj_5_cdec_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("lattice", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":94 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":104 * * def lattice(self): # TODO direct hg -> lattice conversion in cdec * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() # <<<<<<<<<<<<<< * return Lattice(eval(plf)) * */ - __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->hg[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->hg[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __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[2]; __pyx_lineno = 94; __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[2]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_plf = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":95 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":105 * def lattice(self): # TODO direct hg -> lattice conversion in cdec * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() * return Lattice(eval(plf)) # <<<<<<<<<<<<<< @@ -4440,17 +4813,17 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_26lattice(struct __pyx_obj_5_cdec_ * def reweight(self, weights): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_Globals(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_Globals(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); if (((PyObject *)__pyx_v_plf)) { - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__plf), ((PyObject *)__pyx_v_plf)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__plf), ((PyObject *)__pyx_v_plf)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } if (((PyObject *)__pyx_v_self)) { - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_v_self)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_v_self)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)__pyx_v_plf)); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_plf)); @@ -4461,15 +4834,15 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_26lattice(struct __pyx_obj_5_cdec_ __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); __pyx_t_1 = 0; __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_eval, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_builtin_eval, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; @@ -4502,7 +4875,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_29reweight(PyObject *__pyx_v_self, return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":97 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":107 * return Lattice(eval(plf)) * * def reweight(self, weights): # <<<<<<<<<<<<<< @@ -4521,7 +4894,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec int __pyx_clineno = 0; __Pyx_RefNannySetupContext("reweight", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":98 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":108 * * def reweight(self, weights): * if isinstance(weights, SparseVector): # <<<<<<<<<<<<<< @@ -4534,7 +4907,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":99 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":109 * def reweight(self, weights): * if isinstance(weights, SparseVector): * self.hg.Reweight(( weights).vector[0]) # <<<<<<<<<<<<<< @@ -4545,7 +4918,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec goto __pyx_L3; } - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":100 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":110 * if isinstance(weights, SparseVector): * self.hg.Reweight(( weights).vector[0]) * elif isinstance(weights, DenseVector): # <<<<<<<<<<<<<< @@ -4558,7 +4931,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":101 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":111 * self.hg.Reweight(( weights).vector[0]) * elif isinstance(weights, DenseVector): * self.hg.Reweight(( weights).vector[0]) # <<<<<<<<<<<<<< @@ -4570,26 +4943,26 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":103 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":113 * self.hg.Reweight(( weights).vector[0]) * else: * raise TypeError('cannot reweight hypergraph with %s' % type(weights)) # <<<<<<<<<<<<<< * * # TODO get feature expectations, get partition function ("inside" score) */ - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L3:; @@ -6396,7 +6769,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(struct __pyx_obj_5_c * result.metric = x.metric * return result # <<<<<<<<<<<<<< * - * cdef class SegmentEvaluator: + * cdef class CandidateSet: */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); @@ -6417,230 +6790,308 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(struct __pyx_obj_5_c } /* Python wrapper */ -static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self) { +static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__evaluator,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__evaluator); + 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 64; __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_evaluator = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)values[0]); + } + 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[4]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.CandidateSet.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_evaluator), __pyx_ptype_5_cdec_SegmentEvaluator, 1, "evaluator", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12CandidateSet___cinit__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), __pyx_v_evaluator); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":64 + * cdef mteval.CandidateSet* cs + * + * def __cinit__(self, SegmentEvaluator evaluator): # <<<<<<<<<<<<<< + * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) + * self.metric = evaluator.metric + */ + +static int __pyx_pf_5_cdec_12CandidateSet___cinit__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":65 + * + * def __cinit__(self, SegmentEvaluator evaluator): + * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) # <<<<<<<<<<<<<< + * self.metric = evaluator.metric + * self.cs = new mteval.CandidateSet() + */ + __pyx_v_self->scorer = new boost::shared_ptr((__pyx_v_evaluator->scorer[0])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":66 + * def __cinit__(self, SegmentEvaluator evaluator): + * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) + * self.metric = evaluator.metric # <<<<<<<<<<<<<< + * self.cs = new mteval.CandidateSet() + * + */ + __pyx_v_self->metric = __pyx_v_evaluator->metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":67 + * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) + * self.metric = evaluator.metric + * self.cs = new mteval.CandidateSet() # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->cs = new training::CandidateSet(); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self)); + __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":63 - * cdef mteval.EvaluationMetric* metric +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":69 + * self.cs = new mteval.CandidateSet() * * def __dealloc__(self): # <<<<<<<<<<<<<< * del self.scorer - * + * del self.cs */ -static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self) { +static void __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":64 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":70 * * def __dealloc__(self): * del self.scorer # <<<<<<<<<<<<<< + * del self.cs * - * def evaluate(self, sentence): */ delete __pyx_v_self->scorer; + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":71 + * def __dealloc__(self): + * del self.scorer + * del self.cs # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + delete __pyx_v_self->cs; + __Pyx_RefNannyFinishContext(); } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence); /*proto*/ -static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence) { +static Py_ssize_t __pyx_pw_5_cdec_12CandidateSet_5__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_12CandidateSet_5__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12CandidateSet_4__len__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":73 + * del self.cs + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.cs.size() + * + */ + +static Py_ssize_t __pyx_pf_5_cdec_12CandidateSet_4__len__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":74 + * + * def __len__(self): + * return self.cs.size() # <<<<<<<<<<<<<< + * + * def __getitem__(self, unsigned k): + */ + __pyx_r = __pyx_v_self->cs->size(); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_k); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_k) { + unsigned int __pyx_v_k; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("evaluate (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self), ((PyObject *)__pyx_v_sentence)); + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + assert(__pyx_arg_k); { + __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_k); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.CandidateSet.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_12CandidateSet_6__getitem__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), ((unsigned int)__pyx_v_k)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":66 - * del self.scorer +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":76 + * return self.cs.size() * - * def evaluate(self, sentence): # <<<<<<<<<<<<<< - * cdef vector[WordID] hyp - * cdef SufficientStats sf = SufficientStats() + * def __getitem__(self, unsigned k): # <<<<<<<<<<<<<< + * cdef Candidate candidate = Candidate() + * candidate.candidate = &self.cs[0][k] */ -static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, PyObject *__pyx_v_sentence) { - std::vector __pyx_v_hyp; - struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sf = 0; +static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, unsigned int __pyx_v_k) { + struct __pyx_obj_5_cdec_Candidate *__pyx_v_candidate = 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("evaluate", 0); + __Pyx_RefNannySetupContext("__getitem__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":68 - * def evaluate(self, sentence): - * cdef vector[WordID] hyp - * cdef SufficientStats sf = SufficientStats() # <<<<<<<<<<<<<< - * sf.metric = self.metric - * sf.stats = new mteval.SufficientStats() + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":77 + * + * def __getitem__(self, unsigned k): + * cdef Candidate candidate = Candidate() # <<<<<<<<<<<<<< + * candidate.candidate = &self.cs[0][k] + * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Candidate)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_v_sf = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_v_candidate = ((struct __pyx_obj_5_cdec_Candidate *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":69 - * cdef vector[WordID] hyp - * cdef SufficientStats sf = SufficientStats() - * sf.metric = self.metric # <<<<<<<<<<<<<< - * sf.stats = new mteval.SufficientStats() - * ConvertSentence(string(as_str(sentence.strip())), &hyp) - */ - __pyx_v_sf->metric = __pyx_v_self->metric; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":70 - * cdef SufficientStats sf = SufficientStats() - * sf.metric = self.metric - * sf.stats = new mteval.SufficientStats() # <<<<<<<<<<<<<< - * ConvertSentence(string(as_str(sentence.strip())), &hyp) - * self.scorer.get().Evaluate(hyp, sf.stats) - */ - __pyx_v_sf->stats = new SufficientStats(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":71 - * sf.metric = self.metric - * sf.stats = new mteval.SufficientStats() - * ConvertSentence(string(as_str(sentence.strip())), &hyp) # <<<<<<<<<<<<<< - * self.scorer.get().Evaluate(hyp, sf.stats) - * return sf + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":78 + * def __getitem__(self, unsigned k): + * cdef Candidate candidate = Candidate() + * candidate.candidate = &self.cs[0][k] # <<<<<<<<<<<<<< + * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) + * return candidate */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_2, NULL)), (&__pyx_v_hyp)); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_candidate->candidate = (&((__pyx_v_self->cs[0])[__pyx_v_k])); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":72 - * sf.stats = new mteval.SufficientStats() - * ConvertSentence(string(as_str(sentence.strip())), &hyp) - * self.scorer.get().Evaluate(hyp, sf.stats) # <<<<<<<<<<<<<< - * return sf + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":79 + * cdef Candidate candidate = Candidate() + * candidate.candidate = &self.cs[0][k] + * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) # <<<<<<<<<<<<<< + * return candidate * */ - __pyx_v_self->scorer->get()->Evaluate(__pyx_v_hyp, __pyx_v_sf->stats); + __pyx_v_candidate->score = __pyx_v_self->metric->ComputeScore(((__pyx_v_self->cs[0])[__pyx_v_k]).eval_feats); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":73 - * ConvertSentence(string(as_str(sentence.strip())), &hyp) - * self.scorer.get().Evaluate(hyp, sf.stats) - * return sf # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":80 + * candidate.candidate = &self.cs[0][k] + * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) + * return candidate # <<<<<<<<<<<<<< * - * def candidate_set(self, Hypergraph hypergraph, unsigned k): + * def __iter__(self): */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_sf)); - __pyx_r = ((PyObject *)__pyx_v_sf); + __Pyx_INCREF(((PyObject *)__pyx_v_candidate)); + __pyx_r = ((PyObject *)__pyx_v_candidate); 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.SegmentEvaluator.evaluate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.CandidateSet.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_sf); + __Pyx_XDECREF((PyObject *)__pyx_v_candidate); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_16SegmentEvaluator_6generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph = 0; - unsigned int __pyx_v_k; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__hypergraph,&__pyx_n_s__k,0}; +static PyObject *__pyx_pw_5_cdec_12CandidateSet_9__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_9__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("candidate_set (wrapper)", 0); - { - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__hypergraph); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("candidate_set", 1, 2, 2, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "candidate_set") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_hypergraph = ((struct __pyx_obj_5_cdec_Hypergraph *)values[0]); - __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("candidate_set", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.SegmentEvaluator.candidate_set", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_hypergraph), __pyx_ptype_5_cdec_Hypergraph, 1, "hypergraph", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self), __pyx_v_hypergraph, __pyx_v_k); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12CandidateSet_8__iter__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":75 - * return sf +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 + * return candidate * - * def candidate_set(self, Hypergraph hypergraph, unsigned k): # <<<<<<<<<<<<<< - * cdef mteval.CandidateSet* cs = new mteval.CandidateSet() - * cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(len(self)): */ -static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph, unsigned int __pyx_v_k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_12CandidateSet_8__iter__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("candidate_set", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)__pyx_ptype_5_cdec___pyx_scope_struct_8_candidate_set->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_8_candidate_set, __pyx_empty_tuple, NULL); + __Pyx_RefNannySetupContext("__iter__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_8___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_8___iter__, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -6649,12 +7100,8 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_ __pyx_cur_scope->__pyx_v_self = __pyx_v_self; __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __pyx_cur_scope->__pyx_v_hypergraph = __pyx_v_hypergraph; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_hypergraph); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_hypergraph); - __pyx_cur_scope->__pyx_v_k = __pyx_v_k; { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_16SegmentEvaluator_6generator8, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12CandidateSet_10generator8, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -6663,7 +7110,7 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.SegmentEvaluator.candidate_set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.CandidateSet.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); @@ -6672,11 +7119,11 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_ return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_16SegmentEvaluator_6generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)__pyx_generator->closure); + struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; - unsigned int __pyx_t_1; + Py_ssize_t __pyx_t_1; unsigned int __pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannyDeclarations @@ -6689,79 +7136,30 @@ static PyObject *__pyx_gb_5_cdec_16SegmentEvaluator_6generator8(__pyx_GeneratorO return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":76 - * - * def candidate_set(self, Hypergraph hypergraph, unsigned k): - * cdef mteval.CandidateSet* cs = new mteval.CandidateSet() # <<<<<<<<<<<<<< - * cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) - * cdef Candidate candidate - */ - __pyx_cur_scope->__pyx_v_cs = new training::CandidateSet(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":77 - * def candidate_set(self, Hypergraph hypergraph, unsigned k): - * cdef mteval.CandidateSet* cs = new mteval.CandidateSet() - * cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) # <<<<<<<<<<<<<< - * cdef Candidate candidate - * cdef unsigned i - */ - __pyx_cur_scope->__pyx_v_cs->AddKBestCandidates((__pyx_cur_scope->__pyx_v_hypergraph->hg[0]), __pyx_cur_scope->__pyx_v_k, __pyx_cur_scope->__pyx_v_self->scorer->get()); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":80 - * cdef Candidate candidate + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":84 + * def __iter__(self): * cdef unsigned i - * for i in range(cs.size()): # <<<<<<<<<<<<<< - * candidate = Candidate() - * candidate.candidate = &cs[0][i] + * for i in range(len(self)): # <<<<<<<<<<<<<< + * yield self[i] + * */ - __pyx_t_1 = __pyx_cur_scope->__pyx_v_cs->size(); + __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":81 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":85 * cdef unsigned i - * for i in range(cs.size()): - * candidate = Candidate() # <<<<<<<<<<<<<< - * candidate.candidate = &cs[0][i] - * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) + * for i in range(len(self)): + * yield self[i] # <<<<<<<<<<<<<< + * + * def add_kbest(self, Hypergraph hypergraph, unsigned k): */ - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Candidate)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_candidate)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_candidate)); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_v_candidate = ((struct __pyx_obj_5_cdec_Candidate *)__pyx_t_3); + __pyx_r = __pyx_t_3; __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 - * for i in range(cs.size()): - * candidate = Candidate() - * candidate.candidate = &cs[0][i] # <<<<<<<<<<<<<< - * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) - * yield candidate - */ - __pyx_cur_scope->__pyx_v_candidate->candidate = (&((__pyx_cur_scope->__pyx_v_cs[0])[__pyx_cur_scope->__pyx_v_i])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":83 - * candidate = Candidate() - * candidate.candidate = &cs[0][i] - * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) # <<<<<<<<<<<<<< - * yield candidate - * del cs - */ - __pyx_cur_scope->__pyx_v_candidate->score = __pyx_cur_scope->__pyx_v_self->metric->ComputeScore(((__pyx_cur_scope->__pyx_v_cs[0])[__pyx_cur_scope->__pyx_v_i]).eval_feats); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":84 - * candidate.candidate = &cs[0][i] - * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) - * yield candidate # <<<<<<<<<<<<<< - * del cs - * - */ - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_candidate)); - __pyx_r = ((PyObject *)__pyx_cur_scope->__pyx_v_candidate); __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; __Pyx_XGIVEREF(__pyx_r); @@ -6772,27 +7170,315 @@ static PyObject *__pyx_gb_5_cdec_16SegmentEvaluator_6generator8(__pyx_GeneratorO __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[4]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph = 0; + unsigned int __pyx_v_k; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__hypergraph,&__pyx_n_s__k,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("add_kbest (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__hypergraph); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_kbest") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_hypergraph = ((struct __pyx_obj_5_cdec_Hypergraph *)values[0]); + __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.CandidateSet.add_kbest", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_hypergraph), __pyx_ptype_5_cdec_Hypergraph, 1, "hypergraph", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12CandidateSet_11add_kbest(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), __pyx_v_hypergraph, __pyx_v_k); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":87 + * yield self[i] + * + * def add_kbest(self, Hypergraph hypergraph, unsigned k): # <<<<<<<<<<<<<< + * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) + * + */ + +static PyObject *__pyx_pf_5_cdec_12CandidateSet_11add_kbest(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph, unsigned int __pyx_v_k) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("add_kbest", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":88 + * + * def add_kbest(self, Hypergraph hypergraph, unsigned k): + * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) # <<<<<<<<<<<<<< + * + * cdef class SegmentEvaluator: + */ + __pyx_v_self->cs->AddKBestCandidates((__pyx_v_hypergraph->hg[0]), __pyx_v_k, __pyx_v_self->scorer->get()); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":94 + * cdef mteval.EvaluationMetric* metric + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.scorer + * + */ + +static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":95 + * + * def __dealloc__(self): + * del self.scorer # <<<<<<<<<<<<<< + * + * def evaluate(self, sentence): + */ + delete __pyx_v_self->scorer; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence); /*proto*/ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("evaluate (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self), ((PyObject *)__pyx_v_sentence)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":97 + * del self.scorer + * + * def evaluate(self, sentence): # <<<<<<<<<<<<<< + * cdef vector[WordID] hyp + * cdef SufficientStats sf = SufficientStats() + */ + +static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, PyObject *__pyx_v_sentence) { + std::vector __pyx_v_hyp; + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sf = 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("evaluate", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":99 + * def evaluate(self, sentence): + * cdef vector[WordID] hyp + * cdef SufficientStats sf = SufficientStats() # <<<<<<<<<<<<<< + * sf.metric = self.metric + * sf.stats = new mteval.SufficientStats() + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sf = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":100 + * cdef vector[WordID] hyp + * cdef SufficientStats sf = SufficientStats() + * sf.metric = self.metric # <<<<<<<<<<<<<< + * sf.stats = new mteval.SufficientStats() + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + */ + __pyx_v_sf->metric = __pyx_v_self->metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":101 + * cdef SufficientStats sf = SufficientStats() + * sf.metric = self.metric + * sf.stats = new mteval.SufficientStats() # <<<<<<<<<<<<<< + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + * self.scorer.get().Evaluate(hyp, sf.stats) + */ + __pyx_v_sf->stats = new SufficientStats(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":102 + * sf.metric = self.metric + * sf.stats = new mteval.SufficientStats() + * ConvertSentence(string(as_str(sentence.strip())), &hyp) # <<<<<<<<<<<<<< + * self.scorer.get().Evaluate(hyp, sf.stats) + * return sf + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_2, NULL)), (&__pyx_v_hyp)); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":103 + * sf.stats = new mteval.SufficientStats() + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + * self.scorer.get().Evaluate(hyp, sf.stats) # <<<<<<<<<<<<<< + * return sf + * + */ + __pyx_v_self->scorer->get()->Evaluate(__pyx_v_hyp, __pyx_v_sf->stats); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":104 + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + * self.scorer.get().Evaluate(hyp, sf.stats) + * return sf # <<<<<<<<<<<<<< + * + * def candidate_set(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_sf)); + __pyx_r = ((PyObject *)__pyx_v_sf); + 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.SegmentEvaluator.evaluate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_sf); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("candidate_set (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":106 + * return sf + * + * def candidate_set(self): # <<<<<<<<<<<<<< + * return CandidateSet(self) + * + */ + +static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_obj_5_cdec_SegmentEvaluator *__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("candidate_set", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":85 - * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) - * yield candidate - * del cs # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":107 + * + * def candidate_set(self): + * return CandidateSet(self) # <<<<<<<<<<<<<< * * cdef class Scorer: */ - delete __pyx_cur_scope->__pyx_v_cs; - PyErr_SetNone(PyExc_StopIteration); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_CandidateSet)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__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_3); - __Pyx_AddTraceback("candidate_set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec.SegmentEvaluator.candidate_set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); - return NULL; + return __pyx_r; } /* Python wrapper */ @@ -6821,18 +7507,18 @@ static int __pyx_pw_5_cdec_6Scorer_1__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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 112; __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_name = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_name = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 112; __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[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.Scorer.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -6843,7 +7529,7 @@ static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject * return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":90 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":112 * cdef string* name * * def __cinit__(self, char* name): # <<<<<<<<<<<<<< @@ -6856,12 +7542,12 @@ static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__p __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":91 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":113 * * def __cinit__(self, char* name): * self.name = new string(name) # <<<<<<<<<<<<<< * - * def __call__(self, refs): + * def __dealloc__(self): */ __pyx_v_self->name = new std::string(__pyx_v_name); @@ -6871,8 +7557,41 @@ static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__p } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_6Scorer_3__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_5_cdec_6Scorer_3__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static void __pyx_pw_5_cdec_6Scorer_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_6Scorer_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_6Scorer_2__dealloc__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 + * self.name = new string(name) + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.name + * + */ + +static void __pyx_pf_5_cdec_6Scorer_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Scorer *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":116 + * + * def __dealloc__(self): + * del self.name # <<<<<<<<<<<<<< + * + * def __call__(self, refs): + */ + delete __pyx_v_self->name; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_refs = 0; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__refs,0}; PyObject *__pyx_r = 0; @@ -6896,7 +7615,7 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_3__call__(PyObject *__pyx_v_self, PyObj else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; @@ -6907,26 +7626,26 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_3__call__(PyObject *__pyx_v_self, PyObj } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.Scorer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_6Scorer_2__call__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self), __pyx_v_refs); + __pyx_r = __pyx_pf_5_cdec_6Scorer_4__call__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self), __pyx_v_refs); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":93 - * self.name = new string(name) +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":118 + * del self.name * * def __call__(self, refs): # <<<<<<<<<<<<<< * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) * if isinstance(refs, unicode) or isinstance(refs, str): */ -static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs) { +static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs) { EvaluationMetric *__pyx_v_metric; std::vector > *__pyx_v_refsv; std::vector *__pyx_v_refv; @@ -6948,7 +7667,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score __Pyx_RefNannySetupContext("__call__", 0); __Pyx_INCREF(__pyx_v_refs); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":94 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":119 * * def __call__(self, refs): * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) # <<<<<<<<<<<<<< @@ -6957,7 +7676,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_metric = EvaluationMetric::Instance((__pyx_v_self->name[0])); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":95 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":120 * def __call__(self, refs): * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) * if isinstance(refs, unicode) or isinstance(refs, str): # <<<<<<<<<<<<<< @@ -6979,14 +7698,14 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score } if (__pyx_t_4) { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":96 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":121 * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) * if isinstance(refs, unicode) or isinstance(refs, str): * refs = [refs] # <<<<<<<<<<<<<< * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() * cdef vector[WordID]* refv */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_refs); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_refs); @@ -6998,7 +7717,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":97 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":122 * if isinstance(refs, unicode) or isinstance(refs, str): * refs = [refs] * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() # <<<<<<<<<<<<<< @@ -7007,7 +7726,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_refsv = new std::vector >(); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":100 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":125 * cdef vector[WordID]* refv * cdef bytes ref_str * for ref in refs: # <<<<<<<<<<<<<< @@ -7018,7 +7737,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score __pyx_t_1 = __pyx_v_refs; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0; __pyx_t_6 = NULL; } else { - __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_refs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_refs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; } @@ -7034,7 +7753,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score if (unlikely(!__pyx_t_7)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } @@ -7044,7 +7763,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score __pyx_v_ref = __pyx_t_7; __pyx_t_7 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":101 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":126 * cdef bytes ref_str * for ref in refs: * refv = new vector[WordID]() # <<<<<<<<<<<<<< @@ -7053,22 +7772,22 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_refv = new std::vector(); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":102 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":127 * for ref in refs: * refv = new vector[WordID]() * ConvertSentence(string(as_str(ref.strip())), refv) # <<<<<<<<<<<<<< * refsv.push_back(refv[0]) * del refv */ - __pyx_t_7 = PyObject_GetAttr(__pyx_v_ref, __pyx_n_s__strip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PyObject_GetAttr(__pyx_v_ref, __pyx_n_s__strip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_8, NULL)), __pyx_v_refv); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":103 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":128 * refv = new vector[WordID]() * ConvertSentence(string(as_str(ref.strip())), refv) * refsv.push_back(refv[0]) # <<<<<<<<<<<<<< @@ -7077,7 +7796,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_refsv->push_back((__pyx_v_refv[0])); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":104 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":129 * ConvertSentence(string(as_str(ref.strip())), refv) * refsv.push_back(refv[0]) * del refv # <<<<<<<<<<<<<< @@ -7088,19 +7807,19 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":106 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":131 * del refv * cdef unsigned i * cdef SegmentEvaluator evaluator = SegmentEvaluator() # <<<<<<<<<<<<<< * evaluator.metric = metric * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SegmentEvaluator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SegmentEvaluator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_evaluator = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":107 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":132 * cdef unsigned i * cdef SegmentEvaluator evaluator = SegmentEvaluator() * evaluator.metric = metric # <<<<<<<<<<<<<< @@ -7109,7 +7828,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_evaluator->metric = __pyx_v_metric; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":108 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":133 * cdef SegmentEvaluator evaluator = SegmentEvaluator() * evaluator.metric = metric * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) # <<<<<<<<<<<<<< @@ -7118,7 +7837,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_evaluator->scorer = new boost::shared_ptr(__pyx_v_metric->CreateSegmentEvaluator((__pyx_v_refsv[0]))); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":109 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":134 * evaluator.metric = metric * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) * del refsv # in theory should not delete but store in SegmentEvaluator # <<<<<<<<<<<<<< @@ -7127,7 +7846,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score */ delete __pyx_v_refsv; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":110 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":135 * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) * del refsv # in theory should not delete but store in SegmentEvaluator * return evaluator # <<<<<<<<<<<<<< @@ -7157,17 +7876,17 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_6Scorer_5__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_6Scorer_5__str__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_6Scorer_7__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_6Scorer_7__str__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_6Scorer_4__str__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_6Scorer_6__str__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":112 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":137 * return evaluator * * def __str__(self): # <<<<<<<<<<<<<< @@ -7175,7 +7894,7 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_5__str__(PyObject *__pyx_v_self) { * */ -static PyObject *__pyx_pf_5_cdec_6Scorer_4__str__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -7184,7 +7903,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__str__(struct __pyx_obj_5_cdec_Scorer int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__str__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":113 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":138 * * def __str__(self): * return self.name.c_str() # <<<<<<<<<<<<<< @@ -7192,7 +7911,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__str__(struct __pyx_obj_5_cdec_Scorer * BLEU = Scorer('IBM_BLEU') */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(__pyx_v_self->name->c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(__pyx_v_self->name->c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; @@ -8129,7 +8848,7 @@ static PyObject *__pyx_sq_item_5_cdec_DenseVector(PyObject *o, Py_ssize_t i) { static int __pyx_mp_ass_subscript_5_cdec_DenseVector(PyObject *o, PyObject *i, PyObject *v) { if (v) { - return __pyx_pw_5_cdec_11DenseVector_3__setitem__(o, i, v); + return __pyx_pw_5_cdec_11DenseVector_5__setitem__(o, i, v); } else { PyErr_Format(PyExc_NotImplementedError, @@ -8139,8 +8858,8 @@ static int __pyx_mp_ass_subscript_5_cdec_DenseVector(PyObject *o, PyObject *i, P } static PyMethodDef __pyx_methods_5_cdec_DenseVector[] = { - {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_8dot, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("tosparse"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_10tosparse, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_10dot, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("tosparse"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_12tosparse, METH_NOARGS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; @@ -8203,7 +8922,7 @@ static PyNumberMethods __pyx_tp_as_number_DenseVector = { }; static PySequenceMethods __pyx_tp_as_sequence_DenseVector = { - 0, /*sq_length*/ + __pyx_pw_5_cdec_11DenseVector_1__len__, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ __pyx_sq_item_5_cdec_DenseVector, /*sq_item*/ @@ -8216,8 +8935,8 @@ static PySequenceMethods __pyx_tp_as_sequence_DenseVector = { }; static PyMappingMethods __pyx_tp_as_mapping_DenseVector = { - 0, /*mp_length*/ - __pyx_pw_5_cdec_11DenseVector_1__getitem__, /*mp_subscript*/ + __pyx_pw_5_cdec_11DenseVector_1__len__, /*mp_length*/ + __pyx_pw_5_cdec_11DenseVector_3__getitem__, /*mp_subscript*/ __pyx_mp_ass_subscript_5_cdec_DenseVector, /*mp_ass_subscript*/ }; @@ -8272,7 +8991,7 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_11DenseVector_5__iter__, /*tp_iter*/ + __pyx_pw_5_cdec_11DenseVector_7__iter__, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_5_cdec_DenseVector, /*tp_methods*/ 0, /*tp_members*/ @@ -8305,6 +9024,15 @@ static PyObject *__pyx_tp_new_5_cdec_SparseVector(PyTypeObject *t, PyObject *a, } static void __pyx_tp_dealloc_5_cdec_SparseVector(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_12SparseVector_1__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } (*Py_TYPE(o)->tp_free)(o); } static PyObject *__pyx_sq_item_5_cdec_SparseVector(PyObject *o, Py_ssize_t i) { @@ -8317,7 +9045,7 @@ static PyObject *__pyx_sq_item_5_cdec_SparseVector(PyObject *o, Py_ssize_t i) { static int __pyx_mp_ass_subscript_5_cdec_SparseVector(PyObject *o, PyObject *i, PyObject *v) { if (v) { - return __pyx_pw_5_cdec_12SparseVector_3__setitem__(o, i, v); + return __pyx_pw_5_cdec_12SparseVector_7__setitem__(o, i, v); } else { PyErr_Format(PyExc_NotImplementedError, @@ -8327,17 +9055,17 @@ static int __pyx_mp_ass_subscript_5_cdec_SparseVector(PyObject *o, PyObject *i, } static PyMethodDef __pyx_methods_5_cdec_SparseVector[] = { - {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_8dot, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("todense"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_10todense, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("copy"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_3copy, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_12dot, METH_O, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_26__add__, /*nb_add*/ - __pyx_pw_5_cdec_12SparseVector_28__sub__, /*nb_subtract*/ - __pyx_pw_5_cdec_12SparseVector_30__mul__, /*nb_multiply*/ + __pyx_pw_5_cdec_12SparseVector_28__add__, /*nb_add*/ + __pyx_pw_5_cdec_12SparseVector_30__sub__, /*nb_subtract*/ + __pyx_pw_5_cdec_12SparseVector_32__mul__, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 - __pyx_pw_5_cdec_12SparseVector_32__div__, /*nb_divide*/ + __pyx_pw_5_cdec_12SparseVector_34__div__, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ @@ -8368,11 +9096,11 @@ static PyNumberMethods __pyx_tp_as_number_SparseVector = { #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif - __pyx_pw_5_cdec_12SparseVector_18__iadd__, /*nb_inplace_add*/ - __pyx_pw_5_cdec_12SparseVector_20__isub__, /*nb_inplace_subtract*/ - __pyx_pw_5_cdec_12SparseVector_22__imul__, /*nb_inplace_multiply*/ + __pyx_pw_5_cdec_12SparseVector_20__iadd__, /*nb_inplace_add*/ + __pyx_pw_5_cdec_12SparseVector_22__isub__, /*nb_inplace_subtract*/ + __pyx_pw_5_cdec_12SparseVector_24__imul__, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 - __pyx_pw_5_cdec_12SparseVector_24__idiv__, /*nb_inplace_divide*/ + __pyx_pw_5_cdec_12SparseVector_26__idiv__, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ @@ -8391,21 +9119,21 @@ static PyNumberMethods __pyx_tp_as_number_SparseVector = { }; static PySequenceMethods __pyx_tp_as_sequence_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_14__len__, /*sq_length*/ + __pyx_pw_5_cdec_12SparseVector_16__len__, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ __pyx_sq_item_5_cdec_SparseVector, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ - __pyx_pw_5_cdec_12SparseVector_16__contains__, /*sq_contains*/ + __pyx_pw_5_cdec_12SparseVector_18__contains__, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_14__len__, /*mp_length*/ - __pyx_pw_5_cdec_12SparseVector_1__getitem__, /*mp_subscript*/ + __pyx_pw_5_cdec_12SparseVector_16__len__, /*mp_length*/ + __pyx_pw_5_cdec_12SparseVector_5__getitem__, /*mp_subscript*/ __pyx_mp_ass_subscript_5_cdec_SparseVector, /*mp_ass_subscript*/ }; @@ -8458,9 +9186,9 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { 0, /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ - __pyx_pw_5_cdec_12SparseVector_12__richcmp__, /*tp_richcompare*/ + __pyx_pw_5_cdec_12SparseVector_14__richcmp__, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_12SparseVector_5__iter__, /*tp_iter*/ + __pyx_pw_5_cdec_12SparseVector_9__iter__, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_5_cdec_SparseVector, /*tp_methods*/ 0, /*tp_members*/ @@ -9258,6 +9986,194 @@ static PyTypeObject __pyx_type_5_cdec_SufficientStats = { #endif }; +static PyObject *__pyx_tp_new_5_cdec_CandidateSet(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + if (__pyx_pw_5_cdec_12CandidateSet_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_5_cdec_CandidateSet(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_5_cdec_CandidateSet(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static PyMethodDef __pyx_methods_5_cdec_CandidateSet[] = { + {__Pyx_NAMESTR("add_kbest"), (PyCFunction)__pyx_pw_5_cdec_12CandidateSet_12add_kbest, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_CandidateSet = { + 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_CandidateSet = { + __pyx_pw_5_cdec_12CandidateSet_5__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5_cdec_CandidateSet, /*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_CandidateSet = { + __pyx_pw_5_cdec_12CandidateSet_5__len__, /*mp_length*/ + __pyx_pw_5_cdec_12CandidateSet_7__getitem__, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_CandidateSet = { + #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_CandidateSet = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.CandidateSet"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_CandidateSet), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_CandidateSet, /*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_CandidateSet, /*tp_as_number*/ + &__pyx_tp_as_sequence_CandidateSet, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_CandidateSet, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_CandidateSet, /*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_pw_5_cdec_12CandidateSet_9__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_CandidateSet, /*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_CandidateSet, /*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_SegmentEvaluator(PyTypeObject *t, PyObject *a, PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -9279,7 +10195,7 @@ static void __pyx_tp_dealloc_5_cdec_SegmentEvaluator(PyObject *o) { static PyMethodDef __pyx_methods_5_cdec_SegmentEvaluator[] = { {__Pyx_NAMESTR("evaluate"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("candidate_set"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("candidate_set"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set, METH_NOARGS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; @@ -9447,6 +10363,15 @@ static PyObject *__pyx_tp_new_5_cdec_Scorer(PyTypeObject *t, PyObject *a, PyObje } static void __pyx_tp_dealloc_5_cdec_Scorer(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_6Scorer_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } (*Py_TYPE(o)->tp_free)(o); } @@ -9571,8 +10496,8 @@ static PyTypeObject __pyx_type_5_cdec_Scorer = { &__pyx_tp_as_sequence_Scorer, /*tp_as_sequence*/ &__pyx_tp_as_mapping_Scorer, /*tp_as_mapping*/ 0, /*tp_hash*/ - __pyx_pw_5_cdec_6Scorer_3__call__, /*tp_call*/ - __pyx_pw_5_cdec_6Scorer_5__str__, /*tp_str*/ + __pyx_pw_5_cdec_6Scorer_5__call__, /*tp_call*/ + __pyx_pw_5_cdec_6Scorer_7__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_Scorer, /*tp_as_buffer*/ @@ -10027,14 +10952,12 @@ static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__(PyTypeObject PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o); - p->__pyx_v_fname = 0; p->__pyx_v_self = 0; return o; } static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; - Py_XDECREF(((PyObject *)p->__pyx_v_fname)); Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } @@ -10042,9 +10965,6 @@ static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__(PyObject *o, visitproc v, void *a) { int e; struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; - if (p->__pyx_v_fname) { - e = (*v)(p->__pyx_v_fname, a); if (e) return e; - } if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } @@ -10054,9 +10974,6 @@ static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__(PyObject *o, v static int __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_fname); - p->__pyx_v_fname = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_self); p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); @@ -11439,60 +12356,44 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7___iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_8_candidate_set(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_8___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)o); - p->__pyx_v_candidate = 0; - p->__pyx_v_hypergraph = 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *)o); p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8_candidate_set(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)o; - Py_XDECREF(((PyObject *)p->__pyx_v_candidate)); - Py_XDECREF(((PyObject *)p->__pyx_v_hypergraph)); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_8_candidate_set(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_8___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)o; - if (p->__pyx_v_candidate) { - e = (*v)(((PyObject*)p->__pyx_v_candidate), a); if (e) return e; - } - if (p->__pyx_v_hypergraph) { - e = (*v)(((PyObject*)p->__pyx_v_hypergraph), a); if (e) return e; - } + struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_8_candidate_set(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_8___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_candidate); - p->__pyx_v_candidate = ((struct __pyx_obj_5_cdec_Candidate *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_hypergraph); - p->__pyx_v_hypergraph = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_CandidateSet *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_8_candidate_set[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_8___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_8_candidate_set = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_8___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -11550,7 +12451,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_8_candidate_set = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_8_candidate_set = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_8___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -11563,13 +12464,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_8_candidate_set 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_8_candidate_set = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_8___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_8_candidate_set = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_8___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -11590,12 +12491,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_8_candidate_set = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8_candidate_set = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_8_candidate_set"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_8___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -11605,24 +12506,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8_candidate_set = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_8_candidate_set, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_8_candidate_set, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_8_candidate_set, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_8___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_8___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_8___iter__, /*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_8_candidate_set, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_8___iter__, /*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_8_candidate_set, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_8___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_8___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_8___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -11632,7 +12533,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8_candidate_set = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_8___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -11696,6 +12597,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__encoding, __pyx_k__encoding, sizeof(__pyx_k__encoding), 0, 0, 1, 1}, {&__pyx_n_s__enumerate, __pyx_k__enumerate, sizeof(__pyx_k__enumerate), 0, 0, 1, 1}, {&__pyx_n_s__eval, __pyx_k__eval, sizeof(__pyx_k__eval), 0, 0, 1, 1}, + {&__pyx_n_s__evaluator, __pyx_k__evaluator, sizeof(__pyx_k__evaluator), 0, 0, 1, 1}, {&__pyx_n_s__grammar, __pyx_k__grammar, sizeof(__pyx_k__grammar), 0, 0, 1, 1}, {&__pyx_n_s__hypergraph, __pyx_k__hypergraph, sizeof(__pyx_k__hypergraph), 0, 0, 1, 1}, {&__pyx_n_s__inp, __pyx_k__inp, sizeof(__pyx_k__inp), 0, 0, 1, 1}, @@ -11714,11 +12616,11 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { }; 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 = 13; __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[1]; __pyx_lineno = 10; __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[1]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_NotImplemented = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplemented); if (!__pyx_builtin_NotImplemented) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __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[2]; __pyx_lineno = 95; __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[1]; __pyx_lineno = 13; __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[1]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_NotImplemented = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplemented); if (!__pyx_builtin_NotImplemented) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __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[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __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 = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -11731,14 +12633,14 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":69 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":76 * elif op == 3: # != * return not (x == y) * raise NotImplemented('comparison not implemented for SparseVector') # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_k_tuple_3 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_3 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_3); __Pyx_INCREF(((PyObject *)__pyx_kp_s_2)); PyTuple_SET_ITEM(__pyx_k_tuple_3, 0, ((PyObject *)__pyx_kp_s_2)); @@ -11787,42 +12689,42 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_6)); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":41 - * if not derivation: break - * sentence = GetString(derivation._yield).c_str() - * yield sentence.decode('utf8') # <<<<<<<<<<<<<< - * del derivations - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":42 + * if not derivation: break + * sentence = GetString(derivation._yield).c_str() + * yield sentence.decode('utf8') # <<<<<<<<<<<<<< + * finally: + * del derivations */ - __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__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)); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":53 - * if not derivation: break - * tree = GetString(derivation._yield).c_str() - * yield tree.decode('utf8') # <<<<<<<<<<<<<< - * del derivations - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 + * if not derivation: break + * tree = GetString(derivation._yield).c_str() + * yield tree.decode('utf8') # <<<<<<<<<<<<<< + * finally: + * del derivations */ - __pyx_k_tuple_8 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_8 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__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)); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":78 - * for k in range(hypos.size()): - * sentence = GetString(hypos[0][k].words).c_str() - * yield sentence.decode('utf8') # <<<<<<<<<<<<<< - * del hypos - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":85 + * for k in range(hypos.size()): + * sentence = GetString(hypos[0][k].words).c_str() + * yield sentence.decode('utf8') # <<<<<<<<<<<<<< + * finally: + * del hypos */ - __pyx_k_tuple_9 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_9 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_9); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); PyTuple_SET_ITEM(__pyx_k_tuple_9, 0, ((PyObject *)__pyx_n_s__utf8)); @@ -11947,25 +12849,25 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22)); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":140 * return self.name.c_str() * * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< * TER = Scorer('TER') */ - __pyx_k_tuple_24 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_24 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_24); __Pyx_INCREF(((PyObject *)__pyx_n_s__IBM_BLEU)); PyTuple_SET_ITEM(__pyx_k_tuple_24, 0, ((PyObject *)__pyx_n_s__IBM_BLEU)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IBM_BLEU)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_24)); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":116 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":141 * * BLEU = Scorer('IBM_BLEU') * TER = Scorer('TER') # <<<<<<<<<<<<<< */ - __pyx_k_tuple_25 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_25 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_25); __Pyx_INCREF(((PyObject *)__pyx_n_s__TER)); PyTuple_SET_ITEM(__pyx_k_tuple_25, 0, ((PyObject *)__pyx_n_s__TER)); @@ -12057,8 +12959,8 @@ PyMODINIT_FUNC PyInit__cdec(void) if (PyType_Ready(&__pyx_type_5_cdec_DenseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "DenseVector", (PyObject *)&__pyx_type_5_cdec_DenseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_DenseVector = &__pyx_type_5_cdec_DenseVector; - if (PyType_Ready(&__pyx_type_5_cdec_SparseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "SparseVector", (PyObject *)&__pyx_type_5_cdec_SparseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_SparseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "SparseVector", (PyObject *)&__pyx_type_5_cdec_SparseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_SparseVector = &__pyx_type_5_cdec_SparseVector; if (PyType_Ready(&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Hypergraph", (PyObject *)&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -12072,57 +12974,60 @@ PyMODINIT_FUNC PyInit__cdec(void) if (PyType_Ready(&__pyx_type_5_cdec_SufficientStats) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "SufficientStats", (PyObject *)&__pyx_type_5_cdec_SufficientStats) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_SufficientStats = &__pyx_type_5_cdec_SufficientStats; - if (PyType_Ready(&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "SegmentEvaluator", (PyObject *)&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_CandidateSet) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "CandidateSet", (PyObject *)&__pyx_type_5_cdec_CandidateSet) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_CandidateSet = &__pyx_type_5_cdec_CandidateSet; + if (PyType_Ready(&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "SegmentEvaluator", (PyObject *)&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_SegmentEvaluator = &__pyx_type_5_cdec_SegmentEvaluator; - if (PyType_Ready(&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Scorer", (PyObject *)&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Scorer", (PyObject *)&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Scorer = &__pyx_type_5_cdec_Scorer; if (PyType_Ready(&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __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 = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Decoder = &__pyx_type_5_cdec_Decoder; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct____iter__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct____iter__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct____iter__ = &__pyx_type_5_cdec___pyx_scope_struct____iter__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_1___iter__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_1___iter__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_1___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_1___iter__; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_2_kbest) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_2_kbest = &__pyx_type_5_cdec___pyx_scope_struct_2_kbest; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_tree = &__pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_4_kbest_features) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_4_kbest_features) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features = &__pyx_type_5_cdec___pyx_scope_struct_4_kbest_features; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_5_sample) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_5_sample) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_5_sample = &__pyx_type_5_cdec___pyx_scope_struct_5_sample; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_6___iter__) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_6___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_6___iter__; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_7___iter__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_7___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_7___iter__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_8_candidate_set) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_8_candidate_set = &__pyx_type_5_cdec___pyx_scope_struct_8_candidate_set; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_8___iter__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_8___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_8___iter__; /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ /*--- Execution code ---*/ - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":140 * return self.name.c_str() * * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< * TER = Scorer('TER') */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":116 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":141 * * BLEU = Scorer('IBM_BLEU') * TER = Scorer('TER') # <<<<<<<<<<<<<< */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "_cdec.pyx":11 diff --git a/python/src/hypergraph.pxi b/python/src/hypergraph.pxi index ce78b729..9d09722e 100644 --- a/python/src/hypergraph.pxi +++ b/python/src/hypergraph.pxi @@ -32,39 +32,45 @@ cdef class Hypergraph: def kbest(self, size): 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 sentence + cdef bytes 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 + try: + 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') + finally: + del derivations def kbest_tree(self, size): 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 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 + try: + 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') + finally: + del derivations def kbest_features(self, size): cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal].Derivation* derivation cdef SparseVector fmap cdef unsigned k - for k in range(size): - derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - if not derivation: break - fmap = SparseVector() - fmap.vector = new FastSparseVector[weight_t](derivation._yield) - yield fmap - del derivations + try: + for k in range(size): + derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + if not derivation: break + fmap = SparseVector() + fmap.vector = new FastSparseVector[weight_t](derivation._yield) + yield fmap + finally: + del derivations def sample(self, unsigned n): cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() @@ -73,10 +79,12 @@ cdef class Hypergraph: 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 + try: + for k in range(hypos.size()): + sentence = GetString(hypos[0][k].words).c_str() + yield sentence.decode('utf8') + finally: + del hypos # TODO richer k-best/sample output (feature vectors, trees?) @@ -89,6 +97,8 @@ cdef class Hypergraph: preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) + if preserve_mask: + del preserve_mask def lattice(self): # TODO direct hg -> lattice conversion in cdec cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() diff --git a/python/src/mteval.pxi b/python/src/mteval.pxi index dabdf927..9afb6fe1 100644 --- a/python/src/mteval.pxi +++ b/python/src/mteval.pxi @@ -56,6 +56,37 @@ cdef class SufficientStats: result.metric = x.metric return result +cdef class CandidateSet: + cdef shared_ptr[mteval.SegmentEvaluator]* scorer + cdef mteval.EvaluationMetric* metric + cdef mteval.CandidateSet* cs + + def __cinit__(self, SegmentEvaluator evaluator): + self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) + self.metric = evaluator.metric + self.cs = new mteval.CandidateSet() + + def __dealloc__(self): + del self.scorer + del self.cs + + def __len__(self): + return self.cs.size() + + def __getitem__(self, unsigned k): + cdef Candidate candidate = Candidate() + candidate.candidate = &self.cs[0][k] + candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) + return candidate + + def __iter__(self): + cdef unsigned i + for i in range(len(self)): + yield self[i] + + def add_kbest(self, Hypergraph hypergraph, unsigned k): + self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) + cdef class SegmentEvaluator: cdef shared_ptr[mteval.SegmentEvaluator]* scorer cdef mteval.EvaluationMetric* metric @@ -72,23 +103,17 @@ cdef class SegmentEvaluator: self.scorer.get().Evaluate(hyp, sf.stats) return sf - def candidate_set(self, Hypergraph hypergraph, unsigned k): - cdef mteval.CandidateSet* cs = new mteval.CandidateSet() - cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) - cdef Candidate candidate - cdef unsigned i - for i in range(cs.size()): - candidate = Candidate() - candidate.candidate = &cs[0][i] - candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) - yield candidate - del cs + def candidate_set(self): + return CandidateSet(self) cdef class Scorer: cdef string* name def __cinit__(self, char* name): self.name = new string(name) + + def __dealloc__(self): + del self.name def __call__(self, refs): cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) diff --git a/python/src/vectors.pxi b/python/src/vectors.pxi index 233c9530..fc0c365f 100644 --- a/python/src/vectors.pxi +++ b/python/src/vectors.pxi @@ -1,16 +1,20 @@ from cython.operator cimport preincrement as pinc cdef class DenseVector: - cdef vector[weight_t]* vector + cdef vector[weight_t]* vector # Not owned by DenseVector + + def __len__(self): + return self.vector.size() def __getitem__(self, char* fname): - cdef unsigned fid = FDConvert(fname) - if fid <= self.vector.size(): + cdef int fid = FDConvert(fname) + if 0 <= fid < self.vector.size(): return self.vector[0][fid] raise KeyError(fname) def __setitem__(self, char* fname, float value): - cdef unsigned fid = FDConvert(fname) + cdef int fid = FDConvert(fname) + if fid < 0: raise KeyError(fname) if self.vector.size() <= fid: self.vector.resize(fid + 1) self.vector[0][fid] = value @@ -32,21 +36,30 @@ cdef class DenseVector: cdef class SparseVector: cdef FastSparseVector[weight_t]* vector + def __dealloc__(self): + del self.vector + + def copy(self): + return self * 1 + def __getitem__(self, char* fname): - cdef unsigned fid = FDConvert(fname) + cdef int fid = FDConvert(fname) + if fid < 0: raise KeyError(fname) return self.vector.value(fid) def __setitem__(self, char* fname, float value): - cdef unsigned fid = FDConvert(fname) + cdef int fid = FDConvert(fname) + if fid < 0: raise KeyError(fname) self.vector.set_value(fid, value) def __iter__(self): cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) - cdef str fname - for i in range(self.vector.size()): - fname = FDConvert(it[0].ptr().first).c_str() - yield (fname, it[0].ptr().second) - pinc(it[0]) + try: + for i in range(self.vector.size()): + yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second) + pinc(it[0]) # ++it + finally: + del it def dot(self, other): if isinstance(other, DenseVector): @@ -54,12 +67,6 @@ cdef class SparseVector: elif isinstance(other, SparseVector): return self.vector.dot(( other).vector[0]) raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) - - def todense(self): - cdef DenseVector dense = DenseVector() - dense.vector = new vector[weight_t]() - self.vector.init_vector(dense.vector) - return dense def __richcmp__(SparseVector x, SparseVector y, int op): if op == 2: # == diff --git a/python/test.py b/python/test.py index b3900eef..8069aa0a 100644 --- a/python/test.py +++ b/python/test.py @@ -60,3 +60,6 @@ print forest.viterbi_source_tree() # Compare 1best and reference feature vectors fref = forest.viterbi_features() print dict(fsrc - fref) + +# Prune hypergraph +forest.prune(density=100) diff --git a/training/candidate_set.cc b/training/candidate_set.cc index 8c086ece..087efec3 100644 --- a/training/candidate_set.cc +++ b/training/candidate_set.cc @@ -4,6 +4,7 @@ #include +#include "verbose.h" #include "ns.h" #include "filelib.h" #include "wordid.h" @@ -118,7 +119,7 @@ void CandidateSet::WriteToFile(const string& file) const { } void CandidateSet::ReadFromFile(const string& file) { - cerr << "Reading candidates from " << file << endl; + if(!SILENT) cerr << "Reading candidates from " << file << endl; ReadFile rf(file); istream& in = *rf.stream(); string cand; @@ -133,11 +134,11 @@ void CandidateSet::ReadFromFile(const string& file) { ParseSparseVector(feats, 0, &cs.back().fmap); cs.back().eval_feats = SufficientStats(ss); } - cerr << " read " << cs.size() << " candidates\n"; + if(!SILENT) cerr << " read " << cs.size() << " candidates\n"; } void CandidateSet::Dedup() { - cerr << "Dedup in=" << cs.size(); + if(!SILENT) cerr << "Dedup in=" << cs.size(); tr1::unordered_set u; while(cs.size() > 0) { u.insert(cs.back()); @@ -148,7 +149,7 @@ void CandidateSet::Dedup() { cs.push_back(*it); it = u.erase(it); } - cerr << " out=" << cs.size() << endl; + if(!SILENT) cerr << " out=" << cs.size() << endl; } void CandidateSet::AddKBestCandidates(const Hypergraph& hg, size_t kbest_size, const SegmentEvaluator* scorer) { -- cgit v1.2.3 From 32a8d92affae91094f2348b73dd26be800e10abd Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Thu, 5 Jul 2012 14:33:14 -0400 Subject: Fix for pow(double, double) + [python] check bounds for candidate set --- dtrain/score.cc | 8 +- python/src/_cdec.cpp | 304 +++++++++++++++++++++++++++++--------------------- python/src/mteval.pxi | 4 +- 3 files changed, 184 insertions(+), 132 deletions(-) (limited to 'python/src') diff --git a/dtrain/score.cc b/dtrain/score.cc index 4a7cac6e..34fc86a9 100644 --- a/dtrain/score.cc +++ b/dtrain/score.cc @@ -103,7 +103,7 @@ SmoothBleuScorer::Score(vector& hyp, vector& ref, i_bleu[j] += (1/((score_t)j+1)) * i_ng; } } - sum += exp(i_bleu[i])/(pow(2.0, N_-i)); + sum += exp(i_bleu[i])/pow(2.0, (double)(N_-i)); } return brevity_penalty(hyp_len, ref_len) * sum; } @@ -126,7 +126,7 @@ SumBleuScorer::Score(vector& hyp, vector& ref, unsigned j = 1; for (unsigned i = 0; i < M; i++) { if (counts.sum_[i] == 0 || counts.clipped_[i] == 0) break; - sum += ((score_t)counts.clipped_[i]/counts.sum_[i])/pow(2., N_-j+1); + sum += ((score_t)counts.clipped_[i]/counts.sum_[i])/pow(2.0, (double) (N_-j+1)); j++; } return brevity_penalty(hyp_len, ref_len) * sum; @@ -150,7 +150,7 @@ SumExpBleuScorer::Score(vector& hyp, vector& ref, unsigned j = 1; for (unsigned i = 0; i < M; i++) { if (counts.sum_[i] == 0 || counts.clipped_[i] == 0) break; - sum += exp(((score_t)counts.clipped_[i]/counts.sum_[i]))/pow(2., N_-j+1); + sum += exp(((score_t)counts.clipped_[i]/counts.sum_[i]))/pow(2.0, (double) (N_-j+1)); j++; } return brevity_penalty(hyp_len, ref_len) * sum; @@ -178,7 +178,7 @@ SumWhateverBleuScorer::Score(vector& hyp, vector& ref, unsigned j = 1; for (unsigned i = 0; i < M; i++) { if (counts.sum_[i] == 0 || counts.clipped_[i] == 0) break; - sum += exp(v[i] * log(((score_t)counts.clipped_[i]/counts.sum_[i])))/pow(2., N_-j+1); + sum += exp(v[i] * log(((score_t)counts.clipped_[i]/counts.sum_[i])))/pow(2.0, (double) (N_-j+1)); j++; } return brevity_penalty(hyp_len, ref_len) * sum; diff --git a/python/src/_cdec.cpp b/python/src/_cdec.cpp index bc522b32..948d99b6 100644 --- a/python/src/_cdec.cpp +++ b/python/src/_cdec.cpp @@ -1,4 +1,4 @@ -/* Generated by Cython 0.16 on Mon Jul 2 17:01:11 2012 */ +/* Generated by Cython 0.16 on Thu Jul 5 13:43:06 2012 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -421,7 +421,7 @@ struct __pyx_opt_args_5_cdec_as_str { PyObject *error_msg; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":109 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":111 * return CandidateSet(self) * * cdef class Scorer: # <<<<<<<<<<<<<< @@ -534,7 +534,7 @@ struct __pyx_obj_5_cdec_Decoder { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":90 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":92 * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) * * cdef class SegmentEvaluator: # <<<<<<<<<<<<<< @@ -686,7 +686,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":84 * return candidate * * def __iter__(self): # <<<<<<<<<<<<<< @@ -1088,7 +1088,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(struct __pyx_obj_5_c static int __pyx_pf_5_cdec_12CandidateSet___cinit__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator); /* proto */ static void __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self); /* proto */ static Py_ssize_t __pyx_pf_5_cdec_12CandidateSet_4__len__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, unsigned int __pyx_v_k); /* proto */ +static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, int __pyx_v_k); /* proto */ static PyObject *__pyx_pf_5_cdec_12CandidateSet_8__iter__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_12CandidateSet_11add_kbest(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph, unsigned int __pyx_v_k); /* proto */ static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self); /* proto */ @@ -1112,7 +1112,8 @@ static char __pyx_k_11[] = "cannot reweight hypergraph with %s"; static char __pyx_k_13[] = "Cannot create lattice from %s"; static char __pyx_k_14[] = "lattice index out of range"; static char __pyx_k_19[] = "Cannot convert type %s to str"; -static char __pyx_k_23[] = "Cannot translate input type %s"; +static char __pyx_k_21[] = "candidate set index out of range"; +static char __pyx_k_25[] = "Cannot translate input type %s"; static char __pyx_k__k[] = "k"; static char __pyx_k__TER[] = "TER"; static char __pyx_k__dot[] = "dot"; @@ -1158,7 +1159,8 @@ static PyObject *__pyx_kp_s_13; static PyObject *__pyx_kp_s_14; static PyObject *__pyx_kp_s_19; static PyObject *__pyx_kp_s_2; -static PyObject *__pyx_kp_s_23; +static PyObject *__pyx_kp_s_21; +static PyObject *__pyx_kp_s_25; static PyObject *__pyx_n_s__BLEU; static PyObject *__pyx_n_s__Exception; static PyObject *__pyx_n_s__IBM_BLEU; @@ -1212,10 +1214,11 @@ static PyObject *__pyx_k_tuple_16; static PyObject *__pyx_k_tuple_17; static PyObject *__pyx_k_tuple_18; static PyObject *__pyx_k_tuple_20; -static PyObject *__pyx_k_tuple_21; static PyObject *__pyx_k_tuple_22; +static PyObject *__pyx_k_tuple_23; static PyObject *__pyx_k_tuple_24; -static PyObject *__pyx_k_tuple_25; +static PyObject *__pyx_k_tuple_26; +static PyObject *__pyx_k_tuple_27; /* Python wrapper */ static Py_ssize_t __pyx_pw_5_cdec_11DenseVector_1__len__(PyObject *__pyx_v_self); /*proto*/ @@ -6958,7 +6961,7 @@ static Py_ssize_t __pyx_pf_5_cdec_12CandidateSet_4__len__(struct __pyx_obj_5_cde * def __len__(self): * return self.cs.size() # <<<<<<<<<<<<<< * - * def __getitem__(self, unsigned k): + * def __getitem__(self,int k): */ __pyx_r = __pyx_v_self->cs->size(); goto __pyx_L0; @@ -6972,12 +6975,12 @@ static Py_ssize_t __pyx_pf_5_cdec_12CandidateSet_4__len__(struct __pyx_obj_5_cde /* Python wrapper */ static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_k); /*proto*/ static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_k) { - unsigned int __pyx_v_k; + int __pyx_v_k; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); assert(__pyx_arg_k); { - __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_k); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_k = __Pyx_PyInt_AsInt(__pyx_arg_k); if (unlikely((__pyx_v_k == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -6985,7 +6988,7 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_s __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12CandidateSet_6__getitem__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), ((unsigned int)__pyx_v_k)); + __pyx_r = __pyx_pf_5_cdec_12CandidateSet_6__getitem__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), ((int)__pyx_v_k)); __Pyx_RefNannyFinishContext(); return __pyx_r; } @@ -6993,16 +6996,18 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_s /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":76 * return self.cs.size() * - * def __getitem__(self, unsigned k): # <<<<<<<<<<<<<< - * cdef Candidate candidate = Candidate() - * candidate.candidate = &self.cs[0][k] + * def __getitem__(self,int k): # <<<<<<<<<<<<<< + * if not 0 <= k < self.cs.size(): + * raise IndexError('candidate set index out of range') */ -static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, unsigned int __pyx_v_k) { +static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, int __pyx_v_k) { struct __pyx_obj_5_cdec_Candidate *__pyx_v_candidate = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -7010,18 +7015,48 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_ /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":77 * - * def __getitem__(self, unsigned k): + * def __getitem__(self,int k): + * if not 0 <= k < self.cs.size(): # <<<<<<<<<<<<<< + * raise IndexError('candidate set index out of range') + * cdef Candidate candidate = Candidate() + */ + __pyx_t_1 = (0 <= __pyx_v_k); + if (__pyx_t_1) { + __pyx_t_1 = (__pyx_v_k < __pyx_v_self->cs->size()); + } + __pyx_t_2 = (!__pyx_t_1); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":78 + * def __getitem__(self,int k): + * if not 0 <= k < self.cs.size(): + * raise IndexError('candidate set index out of range') # <<<<<<<<<<<<<< + * cdef Candidate candidate = Candidate() + * candidate.candidate = &self.cs[0][k] + */ + __pyx_t_3 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_22), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":79 + * if not 0 <= k < self.cs.size(): + * raise IndexError('candidate set index out of range') * cdef Candidate candidate = Candidate() # <<<<<<<<<<<<<< * candidate.candidate = &self.cs[0][k] * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Candidate)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_candidate = ((struct __pyx_obj_5_cdec_Candidate *)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Candidate)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_candidate = ((struct __pyx_obj_5_cdec_Candidate *)__pyx_t_3); + __pyx_t_3 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":78 - * def __getitem__(self, unsigned k): + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":80 + * raise IndexError('candidate set index out of range') * cdef Candidate candidate = Candidate() * candidate.candidate = &self.cs[0][k] # <<<<<<<<<<<<<< * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) @@ -7029,7 +7064,7 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_ */ __pyx_v_candidate->candidate = (&((__pyx_v_self->cs[0])[__pyx_v_k])); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":79 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":81 * cdef Candidate candidate = Candidate() * candidate.candidate = &self.cs[0][k] * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) # <<<<<<<<<<<<<< @@ -7038,7 +7073,7 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_ */ __pyx_v_candidate->score = __pyx_v_self->metric->ComputeScore(((__pyx_v_self->cs[0])[__pyx_v_k]).eval_feats); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":80 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 * candidate.candidate = &self.cs[0][k] * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) * return candidate # <<<<<<<<<<<<<< @@ -7053,7 +7088,7 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("_cdec.CandidateSet.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -7075,7 +7110,7 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_9__iter__(PyObject *__pyx_v_self return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":84 * return candidate * * def __iter__(self): # <<<<<<<<<<<<<< @@ -7101,7 +7136,7 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_8__iter__(struct __pyx_obj_5_cde __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12CandidateSet_10generator8, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12CandidateSet_10generator8, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -7136,27 +7171,27 @@ static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator8(__pyx_GeneratorObje return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":84 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":86 * def __iter__(self): * cdef unsigned i * for i in range(len(self)): # <<<<<<<<<<<<<< * yield self[i] * */ - __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":85 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":87 * cdef unsigned i * for i in range(len(self)): * yield self[i] # <<<<<<<<<<<<<< * * def add_kbest(self, Hypergraph hypergraph, unsigned k): */ - __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; @@ -7170,7 +7205,7 @@ static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator8(__pyx_GeneratorObje __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[4]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; @@ -7214,11 +7249,11 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_se values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k); if (likely(values[1])) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_kbest") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_kbest") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; @@ -7227,17 +7262,17 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_se values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_hypergraph = ((struct __pyx_obj_5_cdec_Hypergraph *)values[0]); - __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.CandidateSet.add_kbest", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_hypergraph), __pyx_ptype_5_cdec_Hypergraph, 1, "hypergraph", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_hypergraph), __pyx_ptype_5_cdec_Hypergraph, 1, "hypergraph", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = __pyx_pf_5_cdec_12CandidateSet_11add_kbest(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), __pyx_v_hypergraph, __pyx_v_k); goto __pyx_L0; __pyx_L1_error:; @@ -7247,7 +7282,7 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_se return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":87 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":89 * yield self[i] * * def add_kbest(self, Hypergraph hypergraph, unsigned k): # <<<<<<<<<<<<<< @@ -7260,7 +7295,7 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_11add_kbest(struct __pyx_obj_5_c __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("add_kbest", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":88 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":90 * * def add_kbest(self, Hypergraph hypergraph, unsigned k): * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) # <<<<<<<<<<<<<< @@ -7284,7 +7319,7 @@ static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_se __Pyx_RefNannyFinishContext(); } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":94 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":96 * cdef mteval.EvaluationMetric* metric * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -7296,7 +7331,7 @@ static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":95 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":97 * * def __dealloc__(self): * del self.scorer # <<<<<<<<<<<<<< @@ -7319,7 +7354,7 @@ static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_ return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":97 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":99 * del self.scorer * * def evaluate(self, sentence): # <<<<<<<<<<<<<< @@ -7339,19 +7374,19 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5 int __pyx_clineno = 0; __Pyx_RefNannySetupContext("evaluate", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":99 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":101 * def evaluate(self, sentence): * cdef vector[WordID] hyp * cdef SufficientStats sf = SufficientStats() # <<<<<<<<<<<<<< * sf.metric = self.metric * sf.stats = new mteval.SufficientStats() */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_sf = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":100 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":102 * cdef vector[WordID] hyp * cdef SufficientStats sf = SufficientStats() * sf.metric = self.metric # <<<<<<<<<<<<<< @@ -7360,7 +7395,7 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5 */ __pyx_v_sf->metric = __pyx_v_self->metric; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":101 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":103 * cdef SufficientStats sf = SufficientStats() * sf.metric = self.metric * sf.stats = new mteval.SufficientStats() # <<<<<<<<<<<<<< @@ -7369,22 +7404,22 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5 */ __pyx_v_sf->stats = new SufficientStats(); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":102 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":104 * sf.metric = self.metric * sf.stats = new mteval.SufficientStats() * ConvertSentence(string(as_str(sentence.strip())), &hyp) # <<<<<<<<<<<<<< * self.scorer.get().Evaluate(hyp, sf.stats) * return sf */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_2, NULL)), (&__pyx_v_hyp)); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":103 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":105 * sf.stats = new mteval.SufficientStats() * ConvertSentence(string(as_str(sentence.strip())), &hyp) * self.scorer.get().Evaluate(hyp, sf.stats) # <<<<<<<<<<<<<< @@ -7393,7 +7428,7 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5 */ __pyx_v_self->scorer->get()->Evaluate(__pyx_v_hyp, __pyx_v_sf->stats); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":104 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":106 * ConvertSentence(string(as_str(sentence.strip())), &hyp) * self.scorer.get().Evaluate(hyp, sf.stats) * return sf # <<<<<<<<<<<<<< @@ -7430,7 +7465,7 @@ static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__p return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":106 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":108 * return sf * * def candidate_set(self): # <<<<<<<<<<<<<< @@ -7448,7 +7483,7 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("candidate_set", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":107 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":109 * * def candidate_set(self): * return CandidateSet(self) # <<<<<<<<<<<<<< @@ -7456,12 +7491,12 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_ * cdef class Scorer: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_CandidateSet)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_CandidateSet)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; @@ -7507,18 +7542,18 @@ static int __pyx_pw_5_cdec_6Scorer_1__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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __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_name = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_name = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __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[4]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.Scorer.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -7529,7 +7564,7 @@ static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject * return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":112 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":114 * cdef string* name * * def __cinit__(self, char* name): # <<<<<<<<<<<<<< @@ -7542,7 +7577,7 @@ static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__p __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":113 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 * * def __cinit__(self, char* name): * self.name = new string(name) # <<<<<<<<<<<<<< @@ -7565,7 +7600,7 @@ static void __pyx_pw_5_cdec_6Scorer_3__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyFinishContext(); } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":117 * self.name = new string(name) * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -7577,7 +7612,7 @@ static void __pyx_pf_5_cdec_6Scorer_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_ __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":116 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":118 * * def __dealloc__(self): * del self.name # <<<<<<<<<<<<<< @@ -7615,7 +7650,7 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObj else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; @@ -7626,7 +7661,7 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObj } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.Scorer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -7637,7 +7672,7 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObj return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":118 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":120 * del self.name * * def __call__(self, refs): # <<<<<<<<<<<<<< @@ -7667,7 +7702,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score __Pyx_RefNannySetupContext("__call__", 0); __Pyx_INCREF(__pyx_v_refs); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":119 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":121 * * def __call__(self, refs): * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) # <<<<<<<<<<<<<< @@ -7676,7 +7711,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_metric = EvaluationMetric::Instance((__pyx_v_self->name[0])); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":120 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":122 * def __call__(self, refs): * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) * if isinstance(refs, unicode) or isinstance(refs, str): # <<<<<<<<<<<<<< @@ -7698,14 +7733,14 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score } if (__pyx_t_4) { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":121 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":123 * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) * if isinstance(refs, unicode) or isinstance(refs, str): * refs = [refs] # <<<<<<<<<<<<<< * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() * cdef vector[WordID]* refv */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_refs); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_refs); @@ -7717,7 +7752,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":122 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":124 * if isinstance(refs, unicode) or isinstance(refs, str): * refs = [refs] * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() # <<<<<<<<<<<<<< @@ -7726,7 +7761,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_refsv = new std::vector >(); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":125 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":127 * cdef vector[WordID]* refv * cdef bytes ref_str * for ref in refs: # <<<<<<<<<<<<<< @@ -7737,7 +7772,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score __pyx_t_1 = __pyx_v_refs; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0; __pyx_t_6 = NULL; } else { - __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_refs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_refs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; } @@ -7753,7 +7788,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score if (unlikely(!__pyx_t_7)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } @@ -7763,7 +7798,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score __pyx_v_ref = __pyx_t_7; __pyx_t_7 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":126 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":128 * cdef bytes ref_str * for ref in refs: * refv = new vector[WordID]() # <<<<<<<<<<<<<< @@ -7772,22 +7807,22 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_refv = new std::vector(); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":127 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":129 * for ref in refs: * refv = new vector[WordID]() * ConvertSentence(string(as_str(ref.strip())), refv) # <<<<<<<<<<<<<< * refsv.push_back(refv[0]) * del refv */ - __pyx_t_7 = PyObject_GetAttr(__pyx_v_ref, __pyx_n_s__strip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PyObject_GetAttr(__pyx_v_ref, __pyx_n_s__strip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_8, NULL)), __pyx_v_refv); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":128 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":130 * refv = new vector[WordID]() * ConvertSentence(string(as_str(ref.strip())), refv) * refsv.push_back(refv[0]) # <<<<<<<<<<<<<< @@ -7796,7 +7831,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_refsv->push_back((__pyx_v_refv[0])); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":129 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":131 * ConvertSentence(string(as_str(ref.strip())), refv) * refsv.push_back(refv[0]) * del refv # <<<<<<<<<<<<<< @@ -7807,19 +7842,19 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":131 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":133 * del refv * cdef unsigned i * cdef SegmentEvaluator evaluator = SegmentEvaluator() # <<<<<<<<<<<<<< * evaluator.metric = metric * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SegmentEvaluator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SegmentEvaluator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_evaluator = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":132 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":134 * cdef unsigned i * cdef SegmentEvaluator evaluator = SegmentEvaluator() * evaluator.metric = metric # <<<<<<<<<<<<<< @@ -7828,7 +7863,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_evaluator->metric = __pyx_v_metric; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":133 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":135 * cdef SegmentEvaluator evaluator = SegmentEvaluator() * evaluator.metric = metric * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) # <<<<<<<<<<<<<< @@ -7837,7 +7872,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_evaluator->scorer = new boost::shared_ptr(__pyx_v_metric->CreateSegmentEvaluator((__pyx_v_refsv[0]))); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":134 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":136 * evaluator.metric = metric * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) * del refsv # in theory should not delete but store in SegmentEvaluator # <<<<<<<<<<<<<< @@ -7846,7 +7881,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score */ delete __pyx_v_refsv; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":135 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":137 * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) * del refsv # in theory should not delete but store in SegmentEvaluator * return evaluator # <<<<<<<<<<<<<< @@ -7886,7 +7921,7 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_7__str__(PyObject *__pyx_v_self) { return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":137 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":139 * return evaluator * * def __str__(self): # <<<<<<<<<<<<<< @@ -7903,7 +7938,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__str__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":138 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":140 * * def __str__(self): * return self.name.c_str() # <<<<<<<<<<<<<< @@ -7911,7 +7946,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer * BLEU = Scorer('IBM_BLEU') */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(__pyx_v_self->name->c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(__pyx_v_self->name->c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; @@ -8375,7 +8410,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ } /*finally:*/ { if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_21, NULL); + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_23, NULL); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); @@ -8522,7 +8557,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_22), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_inp = __pyx_t_3; @@ -8601,7 +8636,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec * if grammar: * self.dec.SetSentenceGrammarFromString(string( grammar)) */ - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_23), ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_25), ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); @@ -12573,7 +12608,8 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0}, {&__pyx_kp_s_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 1, 0}, {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0}, - {&__pyx_kp_s_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 0, 1, 0}, + {&__pyx_kp_s_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 1, 0}, + {&__pyx_kp_s_25, __pyx_k_25, sizeof(__pyx_k_25), 0, 0, 1, 0}, {&__pyx_n_s__BLEU, __pyx_k__BLEU, sizeof(__pyx_k__BLEU), 0, 0, 1, 1}, {&__pyx_n_s__Exception, __pyx_k__Exception, sizeof(__pyx_k__Exception), 0, 0, 1, 1}, {&__pyx_n_s__IBM_BLEU, __pyx_k__IBM_BLEU, sizeof(__pyx_k__IBM_BLEU), 0, 0, 1, 1}, @@ -12815,6 +12851,20 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20)); + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":78 + * def __getitem__(self,int k): + * if not 0 <= k < self.cs.size(): + * raise IndexError('candidate set index out of range') # <<<<<<<<<<<<<< + * cdef Candidate candidate = Candidate() + * candidate.candidate = &self.cs[0][k] + */ + __pyx_k_tuple_22 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_22)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_22); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_21)); + PyTuple_SET_ITEM(__pyx_k_tuple_22, 0, ((PyObject *)__pyx_kp_s_21)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_21)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22)); + /* "_cdec.pyx":31 * * def read_weights(self, cfg): @@ -12822,18 +12872,18 @@ static int __Pyx_InitCachedConstants(void) { * for line in fp: * fname, value = line.split() */ - __pyx_k_tuple_21 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_21); + __pyx_k_tuple_23 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_23); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_21, 0, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_23, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_21, 1, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_23, 1, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_21, 2, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_23, 2, Py_None); __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_23)); /* "_cdec.pyx":38 * def translate(self, sentence, grammar=None): @@ -12842,37 +12892,37 @@ static int __Pyx_InitCachedConstants(void) { * elif isinstance(sentence, str): * inp = sentence.strip() */ - __pyx_k_tuple_22 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_22); + __pyx_k_tuple_24 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_24); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_22, 0, ((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_24, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_24)); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":140 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":142 * return self.name.c_str() * * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< * TER = Scorer('TER') */ - __pyx_k_tuple_24 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_24); + __pyx_k_tuple_26 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_26)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_26); __Pyx_INCREF(((PyObject *)__pyx_n_s__IBM_BLEU)); - PyTuple_SET_ITEM(__pyx_k_tuple_24, 0, ((PyObject *)__pyx_n_s__IBM_BLEU)); + PyTuple_SET_ITEM(__pyx_k_tuple_26, 0, ((PyObject *)__pyx_n_s__IBM_BLEU)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IBM_BLEU)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_24)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_26)); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":141 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":143 * * BLEU = Scorer('IBM_BLEU') * TER = Scorer('TER') # <<<<<<<<<<<<<< */ - __pyx_k_tuple_25 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_25); + __pyx_k_tuple_27 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_27)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_27); __Pyx_INCREF(((PyObject *)__pyx_n_s__TER)); - PyTuple_SET_ITEM(__pyx_k_tuple_25, 0, ((PyObject *)__pyx_n_s__TER)); + PyTuple_SET_ITEM(__pyx_k_tuple_27, 0, ((PyObject *)__pyx_n_s__TER)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__TER)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_25)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_27)); __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -12977,11 +13027,11 @@ PyMODINIT_FUNC PyInit__cdec(void) if (PyType_Ready(&__pyx_type_5_cdec_CandidateSet) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "CandidateSet", (PyObject *)&__pyx_type_5_cdec_CandidateSet) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_CandidateSet = &__pyx_type_5_cdec_CandidateSet; - if (PyType_Ready(&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "SegmentEvaluator", (PyObject *)&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "SegmentEvaluator", (PyObject *)&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_SegmentEvaluator = &__pyx_type_5_cdec_SegmentEvaluator; - if (PyType_Ready(&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Scorer", (PyObject *)&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Scorer", (PyObject *)&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Scorer = &__pyx_type_5_cdec_Scorer; if (PyType_Ready(&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __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 = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -13002,32 +13052,32 @@ PyMODINIT_FUNC PyInit__cdec(void) __pyx_ptype_5_cdec___pyx_scope_struct_6___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_6___iter__; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_7___iter__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_7___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_7___iter__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_8___iter__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_8___iter__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_8___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_8___iter__; /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ /*--- Execution code ---*/ - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":140 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":142 * return self.name.c_str() * * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< * TER = Scorer('TER') */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_26), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":141 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":143 * * BLEU = Scorer('IBM_BLEU') * TER = Scorer('TER') # <<<<<<<<<<<<<< */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_27), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "_cdec.pyx":11 diff --git a/python/src/mteval.pxi b/python/src/mteval.pxi index 9afb6fe1..67a29f6f 100644 --- a/python/src/mteval.pxi +++ b/python/src/mteval.pxi @@ -73,7 +73,9 @@ cdef class CandidateSet: def __len__(self): return self.cs.size() - def __getitem__(self, unsigned k): + def __getitem__(self,int k): + if not 0 <= k < self.cs.size(): + raise IndexError('candidate set index out of range') cdef Candidate candidate = Candidate() candidate.candidate = &self.cs[0][k] candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) -- cgit v1.2.3 From 757f56e391bd2e1d7442ab38fc98aff00d064d38 Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Thu, 5 Jul 2012 16:53:26 -0400 Subject: [python] Add convenience methods --- python/src/_cdec.cpp | 4730 ++++++++++++++++++++++++++++++++++-------------- python/src/_cdec.pyx | 18 +- python/src/lattice.pxi | 12 + python/src/mteval.pxi | 17 +- python/src/vectors.pxi | 6 + 5 files changed, 3388 insertions(+), 1395 deletions(-) (limited to 'python/src') diff --git a/python/src/_cdec.cpp b/python/src/_cdec.cpp index 948d99b6..3a127ba9 100644 --- a/python/src/_cdec.cpp +++ b/python/src/_cdec.cpp @@ -1,4 +1,4 @@ -/* Generated by Cython 0.16 on Thu Jul 5 13:43:06 2012 */ +/* Generated by Cython 0.16 on Thu Jul 5 16:20:15 2012 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -402,11 +402,13 @@ struct __pyx_obj_5_cdec_Lattice; struct __pyx_obj_5_cdec___pyx_scope_struct____iter__; struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest; struct __pyx_obj_5_cdec_Candidate; +struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines; struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample; struct __pyx_obj_5_cdec_DenseVector; struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__; -struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__; -struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__; +struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__; +struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__; +struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot; struct __pyx_opt_args_5_cdec_as_str; /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":3 @@ -421,7 +423,7 @@ struct __pyx_opt_args_5_cdec_as_str { PyObject *error_msg; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":111 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":122 * return CandidateSet(self) * * cdef class Scorer: # <<<<<<<<<<<<<< @@ -434,7 +436,7 @@ struct __pyx_obj_5_cdec_Scorer { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":59 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":70 * return result * * cdef class CandidateSet: # <<<<<<<<<<<<<< @@ -449,7 +451,7 @@ struct __pyx_obj_5_cdec_CandidateSet { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":27 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":36 * return fmap * * cdef class SufficientStats: # <<<<<<<<<<<<<< @@ -525,7 +527,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree { * * cdef class Decoder: # <<<<<<<<<<<<<< * cdef decoder.Decoder* dec - * cdef public DenseVector weights + * cdef DenseVector weights */ struct __pyx_obj_5_cdec_Decoder { PyObject_HEAD @@ -534,7 +536,7 @@ struct __pyx_obj_5_cdec_Decoder { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":92 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":103 * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) * * cdef class SegmentEvaluator: # <<<<<<<<<<<<<< @@ -624,8 +626,8 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":13 - * return ret +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":22 + * return stats * * cdef class Candidate: # <<<<<<<<<<<<<< * cdef mteval.Candidate* candidate @@ -638,6 +640,29 @@ struct __pyx_obj_5_cdec_Candidate { }; +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":59 + * + * def todot(self): + * def lines(): # <<<<<<<<<<<<<< + * yield 'digraph lattice {' + * yield 'rankdir = LR;' + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines { + PyObject_HEAD + struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *__pyx_outer_scope; + PyObject *__pyx_v_delta; + PyObject *__pyx_v_i; + PyObject *__pyx_v_label; + PyObject *__pyx_v_weight; + Py_ssize_t __pyx_t_0; + PyObject *__pyx_t_1; + PyObject *(*__pyx_t_2)(PyObject *); + PyObject *__pyx_t_3; + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); +}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":75 * del derivations * @@ -686,14 +711,31 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":84 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":54 + * return self.stats.size() + * + * def __iter__(self): # <<<<<<<<<<<<<< + * for i in range(len(self)): + * yield self.stats[0][i] + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ { + PyObject_HEAD + PyObject *__pyx_v_i; + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self; + Py_ssize_t __pyx_t_0; + PyObject *__pyx_t_1; + PyObject *(*__pyx_t_2)(PyObject *); +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":95 * return candidate * * def __iter__(self): # <<<<<<<<<<<<<< * cdef unsigned i * for i in range(len(self)): */ -struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ { +struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ { PyObject_HEAD unsigned int __pyx_v_i; struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self; @@ -702,20 +744,16 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":45 - * return self.stats.size() +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":58 + * del self.lattice * - * def __iter__(self): # <<<<<<<<<<<<<< - * for i in range(len(self)): - * yield self.stats[0][i] + * def todot(self): # <<<<<<<<<<<<<< + * def lines(): + * yield 'digraph lattice {' */ -struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ { +struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot { PyObject_HEAD - PyObject *__pyx_v_i; - struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self; - Py_ssize_t __pyx_t_0; - PyObject *__pyx_t_1; - PyObject *(*__pyx_t_2)(PyObject *); + struct __pyx_obj_5_cdec_Lattice *__pyx_v_self; }; #ifndef CYTHON_REFNANNY @@ -878,6 +916,8 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); } +static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname); + static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */ #define __Pyx_PyObject_AsDouble(obj) \ ((likely(PyFloat_CheckExact(obj))) ? \ @@ -895,6 +935,48 @@ static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *na static PyObject* __Pyx_Globals(void); /*proto*/ +#define __Pyx_CyFunction_USED 1 +#include +#define __Pyx_CYFUNCTION_STATICMETHOD 0x01 +#define __Pyx_CYFUNCTION_CLASSMETHOD 0x02 +#define __Pyx_CYFUNCTION_CCLASS 0x04 +#define __Pyx_CyFunction_GetClosure(f) \ + (((__pyx_CyFunctionObject *) (f))->func_closure) +#define __Pyx_CyFunction_GetClassObj(f) \ + (((__pyx_CyFunctionObject *) (f))->func_classobj) +#define __Pyx_CyFunction_Defaults(type, f) \ + ((type *)(((__pyx_CyFunctionObject *) (f))->defaults)) +#define __Pyx_CyFunction_SetDefaultsGetter(f, g) \ + ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g) +typedef struct { + PyCFunctionObject func; + int flags; + PyObject *func_dict; + PyObject *func_weakreflist; + PyObject *func_name; + PyObject *func_doc; + PyObject *func_code; + PyObject *func_closure; + PyObject *func_classobj; /* No-args super() class cell */ + void *defaults; + int defaults_pyobjects; + PyObject *defaults_tuple; /* Const defaults tuple */ + PyObject *(*defaults_getter)(PyObject *); +} __pyx_CyFunctionObject; +static PyTypeObject *__pyx_CyFunctionType = 0; +#define __Pyx_CyFunction_NewEx(ml, flags, self, module, code) \ + __Pyx_CyFunction_New(__pyx_CyFunctionType, ml, flags, self, module, code) +static PyObject *__Pyx_CyFunction_New(PyTypeObject *, + PyMethodDef *ml, int flags, + PyObject *self, PyObject *module, + PyObject* code); +static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m, + size_t size, + int pyobjects); +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m, + PyObject *tuple); +static int __Pyx_CyFunction_init(void); + static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); @@ -1011,9 +1093,12 @@ static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_tree = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_5_sample = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_6___iter__ = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_7___iter__ = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_8___iter__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_7_todot = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_8_lines = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_9___iter__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_10___iter__ = 0; static char *__pyx_f_5_cdec_as_str(PyObject *, struct __pyx_opt_args_5_cdec_as_str *__pyx_optional_args); /*proto*/ +static struct __pyx_obj_5_cdec_SufficientStats *__pyx_f_5_cdec_as_stats(PyObject *, PyObject *); /*proto*/ #define __Pyx_MODULE_NAME "_cdec" int __pyx_module_is_main__cdec = 0; @@ -1042,17 +1127,18 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_Sp static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y, int __pyx_v_op); /* proto */ static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_15__len__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ static int __pyx_pf_5_cdec_12SparseVector_17__contains__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_19__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_21__isub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_23__imul__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_19__neg__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_21__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_23__isub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_25__imul__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pf_5_cdec_12SparseVector_25__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_27__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ #endif -static PyObject *__pyx_pf_5_cdec_12SparseVector_27__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_29__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_31__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_29__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_31__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_33__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pf_5_cdec_12SparseVector_33__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_35__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ #endif static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ @@ -1074,6 +1160,8 @@ static Py_ssize_t __pyx_pf_5_cdec_7Lattice_6__len__(struct __pyx_obj_5_cdec_Latt static PyObject *__pyx_pf_5_cdec_7Lattice_8__str__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ static void __pyx_pf_5_cdec_7Lattice_13__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_7Lattice_5todot_lines(PyObject *__pyx_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_7Lattice_15todot(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_9Candidate_4fmap___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_9Candidate_5score___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self); /* proto */ @@ -1084,7 +1172,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_6detail___get__(struct __pyx_ static Py_ssize_t __pyx_pf_5_cdec_15SufficientStats_2__len__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__iadd__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_x, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ static int __pyx_pf_5_cdec_12CandidateSet___cinit__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator); /* proto */ static void __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self); /* proto */ static Py_ssize_t __pyx_pf_5_cdec_12CandidateSet_4__len__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self); /* proto */ @@ -1100,20 +1188,31 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self); /* proto */ static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, char *__pyx_v_config); /* proto */ static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Decoder *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_weights); /* proto */ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_cfg); /* proto */ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_sentence, PyObject *__pyx_v_grammar); /* proto */ -static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self); /* proto */ -static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static int __pyx_pf_5_cdec_7Decoder_7weights_4__del__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self); /* proto */ static char __pyx_k_1[] = "cannot take the dot product of %s and SparseVector"; static char __pyx_k_2[] = "comparison not implemented for SparseVector"; static char __pyx_k_10[] = "csplit_preserve_full_word"; static char __pyx_k_11[] = "cannot reweight hypergraph with %s"; static char __pyx_k_13[] = "Cannot create lattice from %s"; static char __pyx_k_14[] = "lattice index out of range"; -static char __pyx_k_19[] = "Cannot convert type %s to str"; -static char __pyx_k_21[] = "candidate set index out of range"; -static char __pyx_k_25[] = "Cannot translate input type %s"; +static char __pyx_k_19[] = "digraph lattice {"; + static char __pyx_k_20[] = "rankdir = LR;"; + static char __pyx_k_21[] = "node [shape=circle];"; + static char __pyx_k_22[] = "%d -> %d [label=\"%s\"];"; + static char __pyx_k_23[] = "\""; + static char __pyx_k_24[] = "\\\""; + static char __pyx_k_26[] = "%d [shape=doublecircle]"; +static char __pyx_k_27[] = "}"; +static char __pyx_k_30[] = "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi"; +static char __pyx_k_31[] = "\n"; +static char __pyx_k_33[] = "Cannot convert type %s to str"; +static char __pyx_k_35[] = "candidate set index out of range"; +static char __pyx_k_37[] = "cannot initialize weights with %s"; +static char __pyx_k_40[] = "Cannot translate input type %s"; +static char __pyx_k__i[] = "i"; static char __pyx_k__k[] = "k"; static char __pyx_k__TER[] = "TER"; static char __pyx_k__dot[] = "dot"; @@ -1121,20 +1220,27 @@ static char __pyx_k__inp[] = "inp"; static char __pyx_k__plf[] = "plf"; static char __pyx_k__BLEU[] = "BLEU"; static char __pyx_k__eval[] = "eval"; +static char __pyx_k__join[] = "join"; static char __pyx_k__name[] = "name"; static char __pyx_k__open[] = "open"; static char __pyx_k__refs[] = "refs"; static char __pyx_k__self[] = "self"; static char __pyx_k__utf8[] = "utf8"; static char __pyx_k___cdec[] = "_cdec"; +static char __pyx_k__delta[] = "delta"; +static char __pyx_k__items[] = "items"; +static char __pyx_k__label[] = "label"; +static char __pyx_k__lines[] = "lines"; static char __pyx_k__range[] = "range"; static char __pyx_k__split[] = "split"; static char __pyx_k__strip[] = "strip"; static char __pyx_k__config[] = "config"; static char __pyx_k__decode[] = "decode"; static char __pyx_k__encode[] = "encode"; +static char __pyx_k__weight[] = "weight"; static char __pyx_k__density[] = "density"; static char __pyx_k__grammar[] = "grammar"; +static char __pyx_k__replace[] = "replace"; static char __pyx_k__IBM_BLEU[] = "IBM_BLEU"; static char __pyx_k__KeyError[] = "KeyError"; static char __pyx_k____exit__[] = "__exit__"; @@ -1159,8 +1265,19 @@ static PyObject *__pyx_kp_s_13; static PyObject *__pyx_kp_s_14; static PyObject *__pyx_kp_s_19; static PyObject *__pyx_kp_s_2; +static PyObject *__pyx_kp_s_20; static PyObject *__pyx_kp_s_21; -static PyObject *__pyx_kp_s_25; +static PyObject *__pyx_kp_s_22; +static PyObject *__pyx_kp_s_23; +static PyObject *__pyx_kp_s_24; +static PyObject *__pyx_kp_s_26; +static PyObject *__pyx_kp_s_27; +static PyObject *__pyx_kp_s_30; +static PyObject *__pyx_kp_s_31; +static PyObject *__pyx_kp_s_33; +static PyObject *__pyx_kp_s_35; +static PyObject *__pyx_kp_s_37; +static PyObject *__pyx_kp_s_40; static PyObject *__pyx_n_s__BLEU; static PyObject *__pyx_n_s__Exception; static PyObject *__pyx_n_s__IBM_BLEU; @@ -1178,6 +1295,7 @@ static PyObject *__pyx_n_s___cdec; static PyObject *__pyx_n_s__beam_alpha; static PyObject *__pyx_n_s__config; static PyObject *__pyx_n_s__decode; +static PyObject *__pyx_n_s__delta; static PyObject *__pyx_n_s__density; static PyObject *__pyx_n_s__dot; static PyObject *__pyx_n_s__encode; @@ -1187,18 +1305,25 @@ static PyObject *__pyx_n_s__eval; static PyObject *__pyx_n_s__evaluator; static PyObject *__pyx_n_s__grammar; static PyObject *__pyx_n_s__hypergraph; +static PyObject *__pyx_n_s__i; static PyObject *__pyx_n_s__inp; +static PyObject *__pyx_n_s__items; +static PyObject *__pyx_n_s__join; static PyObject *__pyx_n_s__k; +static PyObject *__pyx_n_s__label; +static PyObject *__pyx_n_s__lines; static PyObject *__pyx_n_s__name; static PyObject *__pyx_n_s__open; static PyObject *__pyx_n_s__plf; static PyObject *__pyx_n_s__range; static PyObject *__pyx_n_s__refs; +static PyObject *__pyx_n_s__replace; static PyObject *__pyx_n_s__self; static PyObject *__pyx_n_s__sentence; static PyObject *__pyx_n_s__split; static PyObject *__pyx_n_s__strip; static PyObject *__pyx_n_s__utf8; +static PyObject *__pyx_n_s__weight; static PyObject *__pyx_int_0; static PyObject *__pyx_int_1; static PyObject *__pyx_k_tuple_3; @@ -1213,12 +1338,16 @@ static PyObject *__pyx_k_tuple_15; static PyObject *__pyx_k_tuple_16; static PyObject *__pyx_k_tuple_17; static PyObject *__pyx_k_tuple_18; -static PyObject *__pyx_k_tuple_20; -static PyObject *__pyx_k_tuple_22; -static PyObject *__pyx_k_tuple_23; -static PyObject *__pyx_k_tuple_24; -static PyObject *__pyx_k_tuple_26; -static PyObject *__pyx_k_tuple_27; +static PyObject *__pyx_k_tuple_25; +static PyObject *__pyx_k_tuple_28; +static PyObject *__pyx_k_tuple_32; +static PyObject *__pyx_k_tuple_34; +static PyObject *__pyx_k_tuple_36; +static PyObject *__pyx_k_tuple_38; +static PyObject *__pyx_k_tuple_39; +static PyObject *__pyx_k_tuple_41; +static PyObject *__pyx_k_tuple_42; +static PyObject *__pyx_k_codeobj_29; /* Python wrapper */ static Py_ssize_t __pyx_pw_5_cdec_11DenseVector_1__len__(PyObject *__pyx_v_self); /*proto*/ @@ -2602,7 +2731,7 @@ static int __pyx_pf_5_cdec_12SparseVector_17__contains__(struct __pyx_obj_5_cdec * def __contains__(self, char* fname): * return self.vector.nonzero(FDConvert(fname)) # <<<<<<<<<<<<<< * - * def __iadd__(SparseVector self, SparseVector other): + * def __neg__(self): */ __pyx_r = __pyx_v_self->vector->nonzero(FD::Convert(__pyx_v_fname)); goto __pyx_L0; @@ -2614,13 +2743,97 @@ static int __pyx_pf_5_cdec_12SparseVector_17__contains__(struct __pyx_obj_5_cdec } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_20__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_20__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_20__neg__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_20__neg__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__neg__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_19__neg__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":84 + * return self.vector.nonzero(FDConvert(fname)) + * + * def __neg__(self): # <<<<<<<<<<<<<< + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](self.vector[0]) + */ + +static PyObject *__pyx_pf_5_cdec_12SparseVector_19__neg__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; + 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("__neg__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":85 + * + * def __neg__(self): + * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< + * result.vector = new FastSparseVector[weight_t](self.vector[0]) + * result.vector[0] *= -1.0 + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":86 + * def __neg__(self): + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](self.vector[0]) # <<<<<<<<<<<<<< + * result.vector[0] *= -1.0 + * return result + */ + __pyx_v_result->vector = new FastSparseVector((__pyx_v_self->vector[0])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":87 + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](self.vector[0]) + * result.vector[0] *= -1.0 # <<<<<<<<<<<<<< + * return result + * + */ + (__pyx_v_result->vector[0]) *= -1.0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":88 + * result.vector = new FastSparseVector[weight_t](self.vector[0]) + * result.vector[0] *= -1.0 + * return result # <<<<<<<<<<<<<< + * + * def __iadd__(SparseVector self, SparseVector other): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + 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.SparseVector.__neg__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_12SparseVector_22__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_22__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iadd__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_19__iadd__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_21__iadd__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2629,20 +2842,20 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_20__iadd__(PyObject *__pyx_v_sel return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":84 - * return self.vector.nonzero(FDConvert(fname)) +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":90 + * return result * * def __iadd__(SparseVector self, SparseVector other): # <<<<<<<<<<<<<< * self.vector[0] += other.vector[0] * return self */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_19__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_21__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iadd__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":85 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":91 * * def __iadd__(SparseVector self, SparseVector other): * self.vector[0] += other.vector[0] # <<<<<<<<<<<<<< @@ -2651,7 +2864,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_19__iadd__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) += (__pyx_v_other->vector[0]); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":86 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":92 * def __iadd__(SparseVector self, SparseVector other): * self.vector[0] += other.vector[0] * return self # <<<<<<<<<<<<<< @@ -2671,13 +2884,13 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_19__iadd__(struct __pyx_obj_5_cd } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_22__isub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_22__isub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_24__isub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_24__isub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__isub__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_21__isub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_23__isub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2686,7 +2899,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_22__isub__(PyObject *__pyx_v_sel return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":88 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":94 * return self * * def __isub__(SparseVector self, SparseVector other): # <<<<<<<<<<<<<< @@ -2694,12 +2907,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_22__isub__(PyObject *__pyx_v_sel * return self */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_21__isub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_23__isub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__isub__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":89 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":95 * * def __isub__(SparseVector self, SparseVector other): * self.vector[0] -= other.vector[0] # <<<<<<<<<<<<<< @@ -2708,7 +2921,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_21__isub__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) -= (__pyx_v_other->vector[0]); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":90 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":96 * def __isub__(SparseVector self, SparseVector other): * self.vector[0] -= other.vector[0] * return self # <<<<<<<<<<<<<< @@ -2728,14 +2941,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_21__isub__(struct __pyx_obj_5_cd } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_24__imul__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_24__imul__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_26__imul__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_26__imul__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar) { float __pyx_v_scalar; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__imul__ (wrapper)", 0); assert(__pyx_arg_scalar); { - __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -2743,12 +2956,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_24__imul__(PyObject *__pyx_v_sel __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12SparseVector_23__imul__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((float)__pyx_v_scalar)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_25__imul__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((float)__pyx_v_scalar)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":92 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":98 * return self * * def __imul__(SparseVector self, float scalar): # <<<<<<<<<<<<<< @@ -2756,12 +2969,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_24__imul__(PyObject *__pyx_v_sel * return self */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_23__imul__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_25__imul__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__imul__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":93 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":99 * * def __imul__(SparseVector self, float scalar): * self.vector[0] *= scalar # <<<<<<<<<<<<<< @@ -2770,7 +2983,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_23__imul__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) *= __pyx_v_scalar; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":94 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":100 * def __imul__(SparseVector self, float scalar): * self.vector[0] *= scalar * return self # <<<<<<<<<<<<<< @@ -2791,14 +3004,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_23__imul__(struct __pyx_obj_5_cd /* Python wrapper */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pw_5_cdec_12SparseVector_26__idiv__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_26__idiv__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_28__idiv__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_28__idiv__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar) { float __pyx_v_scalar; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__idiv__ (wrapper)", 0); assert(__pyx_arg_scalar); { - __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -2806,13 +3019,13 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_26__idiv__(PyObject *__pyx_v_sel __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12SparseVector_25__idiv__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((float)__pyx_v_scalar)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_27__idiv__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((float)__pyx_v_scalar)); __Pyx_RefNannyFinishContext(); return __pyx_r; } #endif /*!(#if PY_MAJOR_VERSION < 3)*/ -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":96 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":102 * return self * * def __idiv__(SparseVector self, float scalar): # <<<<<<<<<<<<<< @@ -2821,12 +3034,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_26__idiv__(PyObject *__pyx_v_sel */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pf_5_cdec_12SparseVector_25__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_27__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__idiv__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":97 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":103 * * def __idiv__(SparseVector self, float scalar): * self.vector[0] /= scalar # <<<<<<<<<<<<<< @@ -2835,7 +3048,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_25__idiv__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) /= __pyx_v_scalar; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":98 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":104 * def __idiv__(SparseVector self, float scalar): * self.vector[0] /= scalar * return self # <<<<<<<<<<<<<< @@ -2856,14 +3069,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_25__idiv__(struct __pyx_obj_5_cd #endif /*!(#if PY_MAJOR_VERSION < 3)*/ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_28__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_28__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_30__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_30__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__add__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_27__add__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_29__add__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2872,7 +3085,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_28__add__(PyObject *__pyx_v_x, P return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":100 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":106 * return self * * def __add__(SparseVector x, SparseVector y): # <<<<<<<<<<<<<< @@ -2880,7 +3093,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_28__add__(PyObject *__pyx_v_x, P * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_27__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_29__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -2890,19 +3103,19 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__add__(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__add__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":101 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":107 * * def __add__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":102 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":108 * def __add__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) # <<<<<<<<<<<<<< @@ -2911,7 +3124,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__add__(struct __pyx_obj_5_cde */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_x->vector[0]) + (__pyx_v_y->vector[0]))); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":103 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":109 * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) * return result # <<<<<<<<<<<<<< @@ -2937,14 +3150,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__add__(struct __pyx_obj_5_cde } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_30__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_30__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_32__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_32__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__sub__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_29__sub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_31__sub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2953,7 +3166,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_30__sub__(PyObject *__pyx_v_x, P return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":105 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":111 * return result * * def __sub__(SparseVector x, SparseVector y): # <<<<<<<<<<<<<< @@ -2961,7 +3174,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_30__sub__(PyObject *__pyx_v_x, P * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_29__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_31__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -2971,19 +3184,19 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_29__sub__(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__sub__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":106 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":112 * * def __sub__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":107 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":113 * def __sub__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) # <<<<<<<<<<<<<< @@ -2992,7 +3205,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_29__sub__(struct __pyx_obj_5_cde */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_x->vector[0]) - (__pyx_v_y->vector[0]))); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":108 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":114 * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) * return result # <<<<<<<<<<<<<< @@ -3018,17 +3231,17 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_29__sub__(struct __pyx_obj_5_cde } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_32__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_32__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_34__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_34__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__mul__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_31__mul__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_33__mul__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":110 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":116 * return result * * def __mul__(x, y): # <<<<<<<<<<<<<< @@ -3036,7 +3249,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_32__mul__(PyObject *__pyx_v_x, P * cdef float scalar */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_31__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_33__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_vector = 0; float __pyx_v_scalar; struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; @@ -3050,7 +3263,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_31__mul__(PyObject *__pyx_v_x, P int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__mul__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":113 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":119 * cdef SparseVector vector * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y # <<<<<<<<<<<<<< @@ -3062,10 +3275,10 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_31__mul__(PyObject *__pyx_v_x, P __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_x; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; @@ -3073,36 +3286,36 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_31__mul__(PyObject *__pyx_v_x, P } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":114 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":120 * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x # <<<<<<<<<<<<<< * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) */ - if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_y; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":115 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":121 * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":116 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":122 * else: vector, scalar = y, x * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) # <<<<<<<<<<<<<< @@ -3111,7 +3324,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_31__mul__(PyObject *__pyx_v_x, P */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_vector->vector[0]) * __pyx_v_scalar)); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":117 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":123 * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) * return result # <<<<<<<<<<<<<< @@ -3139,18 +3352,18 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_31__mul__(PyObject *__pyx_v_x, P /* Python wrapper */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pw_5_cdec_12SparseVector_34__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_34__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_36__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_36__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__div__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_33__div__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_35__div__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); __Pyx_RefNannyFinishContext(); return __pyx_r; } #endif /*!(#if PY_MAJOR_VERSION < 3)*/ -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":119 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":125 * return result * * def __div__(x, y): # <<<<<<<<<<<<<< @@ -3159,7 +3372,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_34__div__(PyObject *__pyx_v_x, P */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pf_5_cdec_12SparseVector_33__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_35__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_vector = 0; float __pyx_v_scalar; struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; @@ -3173,7 +3386,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_33__div__(PyObject *__pyx_v_x, P int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__div__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":122 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":128 * cdef SparseVector vector * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y # <<<<<<<<<<<<<< @@ -3185,10 +3398,10 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_33__div__(PyObject *__pyx_v_x, P __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_x; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; @@ -3196,36 +3409,36 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_33__div__(PyObject *__pyx_v_x, P } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":123 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":129 * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x # <<<<<<<<<<<<<< * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) */ - if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_y; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":124 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":130 * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":125 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":131 * else: vector, scalar = y, x * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) # <<<<<<<<<<<<<< @@ -3233,7 +3446,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_33__div__(PyObject *__pyx_v_x, P */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_vector->vector[0]) / __pyx_v_scalar)); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":126 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":132 * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) * return result # <<<<<<<<<<<<<< @@ -5922,6 +6135,7 @@ static void __pyx_pw_5_cdec_7Lattice_14__dealloc__(PyObject *__pyx_v_self) { * * def __dealloc__(self): # <<<<<<<<<<<<<< * del self.lattice + * */ static void __pyx_pf_5_cdec_7Lattice_13__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { @@ -5932,164 +6146,451 @@ static void __pyx_pf_5_cdec_7Lattice_13__dealloc__(CYTHON_UNUSED struct __pyx_ob * * def __dealloc__(self): * del self.lattice # <<<<<<<<<<<<<< + * + * def todot(self): */ delete __pyx_v_self->lattice; __Pyx_RefNannyFinishContext(); } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":3 - * cimport mteval +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Lattice_16todot(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Lattice_16todot(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("todot (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Lattice_15todot(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_5_cdec_7Lattice_5todot_2generator9(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Lattice_5todot_1lines(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyMethodDef __pyx_mdef_5_cdec_7Lattice_5todot_1lines = {__Pyx_NAMESTR("lines"), (PyCFunction)__pyx_pw_5_cdec_7Lattice_5todot_1lines, METH_NOARGS, __Pyx_DOCSTR(0)}; +static PyObject *__pyx_pw_5_cdec_7Lattice_5todot_1lines(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("lines (wrapper)", 0); + __pyx_self = __pyx_self; + __pyx_r = __pyx_pf_5_cdec_7Lattice_5todot_lines(__pyx_self); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":59 * - * cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): # <<<<<<<<<<<<<< - * cdef bytes ret - * if isinstance(sentence, unicode): + * def todot(self): + * def lines(): # <<<<<<<<<<<<<< + * yield 'digraph lattice {' + * yield 'rankdir = LR;' */ -static char *__pyx_f_5_cdec_as_str(PyObject *__pyx_v_sentence, struct __pyx_opt_args_5_cdec_as_str *__pyx_optional_args) { - PyObject *__pyx_v_error_msg = ((PyObject *)__pyx_kp_s_19); - PyObject *__pyx_v_ret = 0; - char *__pyx_r; +static PyObject *__pyx_pf_5_cdec_7Lattice_5todot_lines(PyObject *__pyx_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *__pyx_cur_scope; + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - char *__pyx_t_4; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("as_str", 0); - if (__pyx_optional_args) { - if (__pyx_optional_args->__pyx_n > 0) { - __pyx_v_error_msg = __pyx_optional_args->error_msg; - } + __Pyx_RefNannySetupContext("lines", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *)__pyx_ptype_5_cdec___pyx_scope_struct_8_lines->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_8_lines, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *) __Pyx_CyFunction_GetClosure(__pyx_self); + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Lattice_5todot_2generator9, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; } - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":5 - * cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): - * cdef bytes ret - * if isinstance(sentence, unicode): # <<<<<<<<<<<<<< - * ret = sentence.encode('utf8') - * elif isinstance(sentence, str): - */ - __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Lattice.todot.lines", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":6 - * cdef bytes ret - * if isinstance(sentence, unicode): - * ret = sentence.encode('utf8') # <<<<<<<<<<<<<< - * elif isinstance(sentence, str): - * ret = sentence - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_ret = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; - goto __pyx_L3; +static PyObject *__pyx_gb_5_cdec_7Lattice_5todot_2generator9(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *(*__pyx_t_4)(PyObject *); + PyObject *__pyx_t_5 = NULL; + Py_ssize_t __pyx_t_6; + PyObject *(*__pyx_t_7)(PyObject *); + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *(*__pyx_t_12)(PyObject *); + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L4_resume_from_yield; + case 2: goto __pyx_L5_resume_from_yield; + case 3: goto __pyx_L6_resume_from_yield; + case 4: goto __pyx_L13_resume_from_yield; + case 5: goto __pyx_L14_resume_from_yield; + case 6: goto __pyx_L15_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[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":7 - * if isinstance(sentence, unicode): - * ret = sentence.encode('utf8') - * elif isinstance(sentence, str): # <<<<<<<<<<<<<< - * ret = sentence - * else: + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":60 + * def todot(self): + * def lines(): + * yield 'digraph lattice {' # <<<<<<<<<<<<<< + * yield 'rankdir = LR;' + * yield 'node [shape=circle];' */ - __pyx_t_3 = ((PyObject *)((PyObject*)(&PyString_Type))); - __Pyx_INCREF(__pyx_t_3); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_2) { + __Pyx_INCREF(((PyObject *)__pyx_kp_s_19)); + __pyx_r = ((PyObject *)__pyx_kp_s_19); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L4_resume_from_yield:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":61 + * def lines(): + * yield 'digraph lattice {' + * yield 'rankdir = LR;' # <<<<<<<<<<<<<< + * yield 'node [shape=circle];' + * for i in range(len(self)): + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_20)); + __pyx_r = ((PyObject *)__pyx_kp_s_20); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 2; + return __pyx_r; + __pyx_L5_resume_from_yield:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":8 - * ret = sentence.encode('utf8') - * elif isinstance(sentence, str): - * ret = sentence # <<<<<<<<<<<<<< - * else: - * raise TypeError(error_msg % type(sentence)) + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":62 + * yield 'digraph lattice {' + * yield 'rankdir = LR;' + * yield 'node [shape=circle];' # <<<<<<<<<<<<<< + * for i in range(len(self)): + * for label, weight, delta in self[i]: */ - if (!(likely(PyBytes_CheckExact(__pyx_v_sentence))||((__pyx_v_sentence) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_sentence)->tp_name), 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_INCREF(__pyx_v_sentence); - __pyx_v_ret = ((PyObject*)__pyx_v_sentence); - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":10 - * ret = sentence - * else: - * raise TypeError(error_msg % type(sentence)) # <<<<<<<<<<<<<< - * return ret - * - */ - __pyx_t_3 = PyNumber_Remainder(__pyx_v_error_msg, ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(((PyObject *)__pyx_kp_s_21)); + __pyx_r = ((PyObject *)__pyx_kp_s_21); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 3; + return __pyx_r; + __pyx_L6_resume_from_yield:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":63 + * yield 'rankdir = LR;' + * yield 'node [shape=circle];' + * for i in range(len(self)): # <<<<<<<<<<<<<< + * for label, weight, delta in self[i]: + * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) + */ + if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } + __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_3)) break; + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; + } else { + __pyx_t_1 = __pyx_t_4(__pyx_t_3); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_i); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_i); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_i = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":64 + * yield 'node [shape=circle];' + * for i in range(len(self)): + * for label, weight, delta in self[i]: # <<<<<<<<<<<<<< + * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) + * yield '%d [shape=doublecircle]' % len(self) + */ + __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_5 = __pyx_t_1; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; + __pyx_t_7 = NULL; + } else { + __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_5)) { + if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break; + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; + } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_5)) { + if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break; + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; + } else { + __pyx_t_1 = __pyx_t_7(__pyx_t_5); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { + PyObject* sequence = __pyx_t_1; + if (likely(PyTuple_CheckExact(sequence))) { + if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { + if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); + } else { + if (unlikely(PyList_GET_SIZE(sequence) != 3)) { + if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_8 = PyList_GET_ITEM(sequence, 0); + __pyx_t_9 = PyList_GET_ITEM(sequence, 1); + __pyx_t_10 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_11 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; + index = 0; __pyx_t_8 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_8)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + index = 1; __pyx_t_9 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_9)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_9); + index = 2; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L12_unpacking_done; + __pyx_L11_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[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L12_unpacking_done:; + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_label); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_label); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_cur_scope->__pyx_v_label = __pyx_t_8; + __pyx_t_8 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_weight); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_weight); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_v_weight = __pyx_t_9; + __pyx_t_9 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_delta); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_delta); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_delta = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":65 + * for i in range(len(self)): + * for label, weight, delta in self[i]: + * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) # <<<<<<<<<<<<<< + * yield '%d [shape=doublecircle]' % len(self) + * yield '}' + */ + __pyx_t_1 = PyNumber_Add(__pyx_cur_scope->__pyx_v_i, __pyx_cur_scope->__pyx_v_delta); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_label, __pyx_n_s__replace); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_cur_scope->__pyx_v_i); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_t_1 = 0; + __pyx_t_9 = 0; + __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_22), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __pyx_r = ((PyObject *)__pyx_t_9); + __pyx_t_9 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; + __Pyx_XGIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; + __Pyx_XGIVEREF(__pyx_t_5); + __pyx_cur_scope->__pyx_t_3 = __pyx_t_5; + __pyx_cur_scope->__pyx_t_4 = __pyx_t_6; + __pyx_cur_scope->__pyx_t_5 = __pyx_t_7; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 4; + return __pyx_r; + __pyx_L13_resume_from_yield:; + __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_t_3); + __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; + __pyx_t_5 = __pyx_cur_scope->__pyx_t_3; + __pyx_cur_scope->__pyx_t_3 = 0; + __Pyx_XGOTREF(__pyx_t_5); + __pyx_t_6 = __pyx_cur_scope->__pyx_t_4; + __pyx_t_7 = __pyx_cur_scope->__pyx_t_5; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } - __pyx_L3:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":11 - * else: - * raise TypeError(error_msg % type(sentence)) - * return ret # <<<<<<<<<<<<<< - * - * cdef class Candidate: + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":66 + * for label, weight, delta in self[i]: + * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) + * yield '%d [shape=doublecircle]' % len(self) # <<<<<<<<<<<<<< + * yield '}' + * return '\n'.join(lines()).encode('utf8') */ - __pyx_t_4 = PyBytes_AsString(((PyObject *)__pyx_v_ret)); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_t_4; - goto __pyx_L0; + __pyx_t_3 = ((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_2 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_26), __pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = ((PyObject *)__pyx_t_5); + __pyx_t_5 = 0; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 5; + return __pyx_r; + __pyx_L14_resume_from_yield:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = 0; + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":67 + * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) + * yield '%d [shape=doublecircle]' % len(self) + * yield '}' # <<<<<<<<<<<<<< + * return '\n'.join(lines()).encode('utf8') + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_27)); + __pyx_r = ((PyObject *)__pyx_kp_s_27); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 6; + return __pyx_r; + __pyx_L15_resume_from_yield:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); - __Pyx_WriteUnraisable("_cdec.as_str", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("lines", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XDECREF(__pyx_v_ret); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_9Candidate_5words_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_9Candidate_5words_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9Candidate_5words___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return __pyx_r; + return NULL; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":18 - * - * property words: - * def __get__(self): # <<<<<<<<<<<<<< - * return unicode(GetString(self.candidate.ewords).c_str(), encoding='utf8') +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":58 + * del self.lattice * + * def todot(self): # <<<<<<<<<<<<<< + * def lines(): + * yield 'digraph lattice {' */ -static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_7Lattice_15todot(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *__pyx_cur_scope; + PyObject *__pyx_v_lines = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -6098,32 +6599,56 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cd int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_RefNannySetupContext("todot", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *)__pyx_ptype_5_cdec___pyx_scope_struct_7_todot->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_7_todot, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":19 - * property words: - * def __get__(self): - * return unicode(GetString(self.candidate.ewords).c_str(), encoding='utf8') # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":59 * - * property fmap: + * def todot(self): + * def lines(): # <<<<<<<<<<<<<< + * yield 'digraph lattice {' + * yield 'rankdir = LR;' + */ + __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5_cdec_7Lattice_5todot_1lines, 0, ((PyObject*)__pyx_cur_scope), __pyx_n_s___cdec, ((PyObject *)__pyx_k_codeobj_29)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_lines = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":68 + * yield '%d [shape=doublecircle]' % len(self) + * yield '}' + * return '\n'.join(lines()).encode('utf8') # <<<<<<<<<<<<<< */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(TD::GetString(__pyx_v_self->candidate->ewords).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 19; __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[4]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_31), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_v_lines, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __pyx_t_1 = 0; - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__encoding), ((PyObject *)__pyx_n_s__utf8)) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_32), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); @@ -6132,70 +6657,403 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cd __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec.Candidate.words.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Lattice.todot", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_lines); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_9Candidate_4fmap_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_9Candidate_4fmap_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9Candidate_4fmap___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":22 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":3 + * cimport mteval * - * property fmap: - * def __get__(self): # <<<<<<<<<<<<<< - * cdef SparseVector fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) + * cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): # <<<<<<<<<<<<<< + * cdef bytes ret + * if isinstance(sentence, unicode): */ -static PyObject *__pyx_pf_5_cdec_9Candidate_4fmap___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { - struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap = 0; - PyObject *__pyx_r = NULL; +static char *__pyx_f_5_cdec_as_str(PyObject *__pyx_v_sentence, struct __pyx_opt_args_5_cdec_as_str *__pyx_optional_args) { + PyObject *__pyx_v_error_msg = ((PyObject *)__pyx_kp_s_33); + PyObject *__pyx_v_ret = 0; + char *__pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + char *__pyx_t_4; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_RefNannySetupContext("as_str", 0); + if (__pyx_optional_args) { + if (__pyx_optional_args->__pyx_n > 0) { + __pyx_v_error_msg = __pyx_optional_args->error_msg; + } + } - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":23 - * property fmap: - * def __get__(self): - * cdef SparseVector fmap = SparseVector() # <<<<<<<<<<<<<< - * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) - * return fmap + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":5 + * cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): + * cdef bytes ret + * if isinstance(sentence, unicode): # <<<<<<<<<<<<<< + * ret = sentence.encode('utf8') + * elif isinstance(sentence, str): */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":24 - * def __get__(self): - * cdef SparseVector fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) # <<<<<<<<<<<<<< - * return fmap - * + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":6 + * cdef bytes ret + * if isinstance(sentence, unicode): + * ret = sentence.encode('utf8') # <<<<<<<<<<<<<< + * elif isinstance(sentence, str): + * ret = sentence */ - __pyx_v_fmap->vector = new FastSparseVector(__pyx_v_self->candidate->fmap); + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_34), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_ret = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + goto __pyx_L3; + } - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":25 - * cdef SparseVector fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) - * return fmap # <<<<<<<<<<<<<< - * - * cdef class SufficientStats: + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":7 + * if isinstance(sentence, unicode): + * ret = sentence.encode('utf8') + * elif isinstance(sentence, str): # <<<<<<<<<<<<<< + * ret = sentence + * else: + */ + __pyx_t_3 = ((PyObject *)((PyObject*)(&PyString_Type))); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":8 + * ret = sentence.encode('utf8') + * elif isinstance(sentence, str): + * ret = sentence # <<<<<<<<<<<<<< + * else: + * raise TypeError(error_msg % type(sentence)) + */ + if (!(likely(PyBytes_CheckExact(__pyx_v_sentence))||((__pyx_v_sentence) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_sentence)->tp_name), 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_sentence); + __pyx_v_ret = ((PyObject*)__pyx_v_sentence); + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":10 + * ret = sentence + * else: + * raise TypeError(error_msg % type(sentence)) # <<<<<<<<<<<<<< + * return ret + * + */ + __pyx_t_3 = PyNumber_Remainder(__pyx_v_error_msg, ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":11 + * else: + * raise TypeError(error_msg % type(sentence)) + * return ret # <<<<<<<<<<<<<< + * + * cdef SufficientStats as_stats(x, y): + */ + __pyx_t_4 = PyBytes_AsString(((PyObject *)__pyx_v_ret)); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_t_4; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_WriteUnraisable("_cdec.as_str", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_ret); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":13 + * return ret + * + * cdef SufficientStats as_stats(x, y): # <<<<<<<<<<<<<< + * if isinstance(x, SufficientStats): + * return x + */ + +static struct __pyx_obj_5_cdec_SufficientStats *__pyx_f_5_cdec_as_stats(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_stats = NULL; + struct __pyx_obj_5_cdec_SufficientStats *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("as_stats", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":14 + * + * cdef SufficientStats as_stats(x, y): + * if isinstance(x, SufficientStats): # <<<<<<<<<<<<<< + * return x + * elif x == 0 and isinstance(y, SufficientStats): + */ + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":15 + * cdef SufficientStats as_stats(x, y): + * if isinstance(x, SufficientStats): + * return x # <<<<<<<<<<<<<< + * elif x == 0 and isinstance(y, SufficientStats): + * stats = SufficientStats() + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SufficientStats))))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_x); + __pyx_r = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_x); + goto __pyx_L0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":16 + * if isinstance(x, SufficientStats): + * return x + * elif x == 0 and isinstance(y, SufficientStats): # <<<<<<<<<<<<<< + * stats = SufficientStats() + * stats.stats = new mteval.SufficientStats() + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_v_x, __pyx_int_0, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_y, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_2; + } + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":17 + * return x + * elif x == 0 and isinstance(y, SufficientStats): + * stats = SufficientStats() # <<<<<<<<<<<<<< + * stats.stats = new mteval.SufficientStats() + * stats.metric = ( y).metric + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_stats = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":18 + * elif x == 0 and isinstance(y, SufficientStats): + * stats = SufficientStats() + * stats.stats = new mteval.SufficientStats() # <<<<<<<<<<<<<< + * stats.metric = ( y).metric + * return stats + */ + __pyx_v_stats->stats = new SufficientStats(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":19 + * stats = SufficientStats() + * stats.stats = new mteval.SufficientStats() + * stats.metric = ( y).metric # <<<<<<<<<<<<<< + * return stats + * + */ + __pyx_v_stats->metric = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_y)->metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":20 + * stats.stats = new mteval.SufficientStats() + * stats.metric = ( y).metric + * return stats # <<<<<<<<<<<<<< + * + * cdef class Candidate: + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_stats)); + __pyx_r = __pyx_v_stats; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = ((struct __pyx_obj_5_cdec_SufficientStats *)Py_None); __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.as_stats", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_stats); + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_9Candidate_5words_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9Candidate_5words_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9Candidate_5words___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":27 + * + * property words: + * def __get__(self): # <<<<<<<<<<<<<< + * return unicode(GetString(self.candidate.ewords).c_str(), encoding='utf8') + * + */ + +static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":28 + * property words: + * def __get__(self): + * return unicode(GetString(self.candidate.ewords).c_str(), encoding='utf8') # <<<<<<<<<<<<<< + * + * property fmap: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(TD::GetString(__pyx_v_self->candidate->ewords).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 28; __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[4]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__encoding), ((PyObject *)__pyx_n_s__utf8)) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec.Candidate.words.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_9Candidate_4fmap_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9Candidate_4fmap_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9Candidate_4fmap___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":31 + * + * property fmap: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) + */ + +static PyObject *__pyx_pf_5_cdec_9Candidate_4fmap___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap = 0; + 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("__get__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":32 + * property fmap: + * def __get__(self): + * cdef SparseVector fmap = SparseVector() # <<<<<<<<<<<<<< + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) + * return fmap + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":33 + * def __get__(self): + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) # <<<<<<<<<<<<<< + * return fmap + * + */ + __pyx_v_fmap->vector = new FastSparseVector(__pyx_v_self->candidate->fmap); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":34 + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) + * return fmap # <<<<<<<<<<<<<< + * + * cdef class SufficientStats: */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_fmap)); @@ -6226,7 +7084,7 @@ static PyObject *__pyx_pw_5_cdec_9Candidate_5score_1__get__(PyObject *__pyx_v_se return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":15 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":24 * cdef class Candidate: * cdef mteval.Candidate* candidate * cdef public float score # <<<<<<<<<<<<<< @@ -6243,7 +7101,7 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_5score___get__(struct __pyx_obj_5_cd int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->score); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->score); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -6280,7 +7138,7 @@ static int __pyx_pf_5_cdec_9Candidate_5score_2__set__(struct __pyx_obj_5_cdec_Ca const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - __pyx_t_1 = __pyx_PyFloat_AsFloat(__pyx_v_value); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_PyFloat_AsFloat(__pyx_v_value); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->score = __pyx_t_1; __pyx_r = 0; @@ -6302,7 +7160,7 @@ static void __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(PyObject *__pyx_v_sel __Pyx_RefNannyFinishContext(); } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":31 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":40 * cdef mteval.EvaluationMetric* metric * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -6314,7 +7172,7 @@ static void __pyx_pf_5_cdec_15SufficientStats___dealloc__(CYTHON_UNUSED struct _ __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":32 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":41 * * def __dealloc__(self): * del self.stats # <<<<<<<<<<<<<< @@ -6337,7 +7195,7 @@ static PyObject *__pyx_pw_5_cdec_15SufficientStats_5score_1__get__(PyObject *__p return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":35 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":44 * * property score: * def __get__(self): # <<<<<<<<<<<<<< @@ -6354,7 +7212,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_5score___get__(struct __pyx_o int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":36 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":45 * property score: * def __get__(self): * return self.metric.ComputeScore(self.stats[0]) # <<<<<<<<<<<<<< @@ -6362,7 +7220,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_5score___get__(struct __pyx_o * property detail: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->metric->ComputeScore((__pyx_v_self->stats[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->metric->ComputeScore((__pyx_v_self->stats[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -6391,7 +7249,7 @@ static PyObject *__pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(PyObject *__ return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":39 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":48 * * property detail: * def __get__(self): # <<<<<<<<<<<<<< @@ -6408,7 +7266,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_6detail___get__(struct __pyx_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":40 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":49 * property detail: * def __get__(self): * return self.metric.DetailedScore(self.stats[0]).c_str() # <<<<<<<<<<<<<< @@ -6416,7 +7274,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_6detail___get__(struct __pyx_ * def __len__(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(__pyx_v_self->metric->DetailedScore((__pyx_v_self->stats[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(__pyx_v_self->metric->DetailedScore((__pyx_v_self->stats[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; @@ -6445,7 +7303,7 @@ static Py_ssize_t __pyx_pw_5_cdec_15SufficientStats_3__len__(PyObject *__pyx_v_s return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":42 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":51 * return self.metric.DetailedScore(self.stats[0]).c_str() * * def __len__(self): # <<<<<<<<<<<<<< @@ -6458,7 +7316,7 @@ static Py_ssize_t __pyx_pf_5_cdec_15SufficientStats_2__len__(struct __pyx_obj_5_ __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__len__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":43 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":52 * * def __len__(self): * return self.stats.size() # <<<<<<<<<<<<<< @@ -6486,7 +7344,7 @@ static PyObject *__pyx_pw_5_cdec_15SufficientStats_5__iter__(PyObject *__pyx_v_s return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":45 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":54 * return self.stats.size() * * def __iter__(self): # <<<<<<<<<<<<<< @@ -6495,14 +7353,14 @@ static PyObject *__pyx_pw_5_cdec_15SufficientStats_5__iter__(PyObject *__pyx_v_s */ static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *__pyx_cur_scope; + struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__iter__", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_7___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_7___iter__, __pyx_empty_tuple, NULL); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_9___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_9___iter__, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -6512,7 +7370,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_ __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_15SufficientStats_6generator7, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_15SufficientStats_6generator7, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -6532,7 +7390,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_ static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator7(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)__pyx_generator->closure); + struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; Py_ssize_t __pyx_t_1; PyObject *__pyx_t_2 = NULL; @@ -6549,31 +7407,31 @@ static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator7(__pyx_GeneratorOb return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":46 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":55 * * def __iter__(self): * for i in range(len(self)): # <<<<<<<<<<<<<< * yield self.stats[0][i] * */ - __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) { __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0; __pyx_t_4 = NULL; } else { - __pyx_t_1 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; } @@ -6590,7 +7448,7 @@ static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator7(__pyx_GeneratorOb if (unlikely(!__pyx_t_2)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } @@ -6602,15 +7460,15 @@ static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator7(__pyx_GeneratorOb __pyx_cur_scope->__pyx_v_i = __pyx_t_2; __pyx_t_2 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":47 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":56 * def __iter__(self): * for i in range(len(self)): * yield self.stats[0][i] # <<<<<<<<<<<<<< * * def __iadd__(SufficientStats self, SufficientStats other): */ - __pyx_t_5 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_i); if (unlikely((__pyx_t_5 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyFloat_FromDouble(((__pyx_cur_scope->__pyx_v_self->stats[0])[__pyx_t_5])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_i); if (unlikely((__pyx_t_5 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyFloat_FromDouble(((__pyx_cur_scope->__pyx_v_self->stats[0])[__pyx_t_5])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; @@ -6629,7 +7487,7 @@ static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator7(__pyx_GeneratorOb __pyx_cur_scope->__pyx_t_1 = 0; __Pyx_XGOTREF(__pyx_t_3); __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyErr_SetNone(PyExc_StopIteration); @@ -6651,7 +7509,7 @@ static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__iadd__(PyObject *__pyx_v_s PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iadd__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SufficientStats, 1, "other", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SufficientStats, 1, "other", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = __pyx_pf_5_cdec_15SufficientStats_7__iadd__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_other)); goto __pyx_L0; __pyx_L1_error:; @@ -6661,7 +7519,7 @@ static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__iadd__(PyObject *__pyx_v_s return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":49 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":58 * yield self.stats[0][i] * * def __iadd__(SufficientStats self, SufficientStats other): # <<<<<<<<<<<<<< @@ -6674,7 +7532,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__iadd__(struct __pyx_obj_5_ __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iadd__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":50 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":59 * * def __iadd__(SufficientStats self, SufficientStats other): * self.stats[0] += other.stats[0] # <<<<<<<<<<<<<< @@ -6683,12 +7541,12 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__iadd__(struct __pyx_obj_5_ */ (__pyx_v_self->stats[0]) += (__pyx_v_other->stats[0]); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":51 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":60 * def __iadd__(SufficientStats self, SufficientStats other): * self.stats[0] += other.stats[0] * return self # <<<<<<<<<<<<<< * - * def __add__(SufficientStats x, SufficientStats y): + * def __add__(x, y): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_self)); @@ -6708,26 +7566,22 @@ static PyObject *__pyx_pw_5_cdec_15SufficientStats_10__add__(PyObject *__pyx_v_x PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__add__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SufficientStats, 1, "x", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SufficientStats, 1, "y", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_15SufficientStats_9__add__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_y)); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_9__add__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":53 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":62 * return self * - * def __add__(SufficientStats x, SufficientStats y): # <<<<<<<<<<<<<< - * cdef SufficientStats result = SufficientStats() - * result.stats = new mteval.SufficientStats(mteval.add(x.stats[0], y.stats[0])) + * def __add__(x, y): # <<<<<<<<<<<<<< + * cdef SufficientStats sx = as_stats(x, y) + * cdef SufficientStats sy = as_stats(y, x) */ -static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_x, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_y) { +static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sx = 0; + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sy = 0; struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -6737,39 +7591,63 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(struct __pyx_obj_5_c int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__add__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":54 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":63 * - * def __add__(SufficientStats x, SufficientStats y): + * def __add__(x, y): + * cdef SufficientStats sx = as_stats(x, y) # <<<<<<<<<<<<<< + * cdef SufficientStats sy = as_stats(y, x) + * cdef SufficientStats result = SufficientStats() + */ + __pyx_t_1 = ((PyObject *)__pyx_f_5_cdec_as_stats(__pyx_v_x, __pyx_v_y)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sx = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":64 + * def __add__(x, y): + * cdef SufficientStats sx = as_stats(x, y) + * cdef SufficientStats sy = as_stats(y, x) # <<<<<<<<<<<<<< + * cdef SufficientStats result = SufficientStats() + * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) + */ + __pyx_t_1 = ((PyObject *)__pyx_f_5_cdec_as_stats(__pyx_v_y, __pyx_v_x)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sy = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":65 + * cdef SufficientStats sx = as_stats(x, y) + * cdef SufficientStats sy = as_stats(y, x) * cdef SufficientStats result = SufficientStats() # <<<<<<<<<<<<<< - * result.stats = new mteval.SufficientStats(mteval.add(x.stats[0], y.stats[0])) - * result.metric = x.metric + * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) + * result.metric = sx.metric */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":55 - * def __add__(SufficientStats x, SufficientStats y): + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":66 + * cdef SufficientStats sy = as_stats(y, x) * cdef SufficientStats result = SufficientStats() - * result.stats = new mteval.SufficientStats(mteval.add(x.stats[0], y.stats[0])) # <<<<<<<<<<<<<< - * result.metric = x.metric + * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) # <<<<<<<<<<<<<< + * result.metric = sx.metric * return result */ - __pyx_v_result->stats = new SufficientStats(operator+((__pyx_v_x->stats[0]), (__pyx_v_y->stats[0]))); + __pyx_v_result->stats = new SufficientStats(operator+((__pyx_v_sx->stats[0]), (__pyx_v_sy->stats[0]))); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":56 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":67 * cdef SufficientStats result = SufficientStats() - * result.stats = new mteval.SufficientStats(mteval.add(x.stats[0], y.stats[0])) - * result.metric = x.metric # <<<<<<<<<<<<<< + * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) + * result.metric = sx.metric # <<<<<<<<<<<<<< * return result * */ - __pyx_v_result->metric = __pyx_v_x->metric; + __pyx_v_result->metric = __pyx_v_sx->metric; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":57 - * result.stats = new mteval.SufficientStats(mteval.add(x.stats[0], y.stats[0])) - * result.metric = x.metric + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":68 + * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) + * result.metric = sx.metric * return result # <<<<<<<<<<<<<< * * cdef class CandidateSet: @@ -6786,6 +7664,8 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(struct __pyx_obj_5_c __Pyx_AddTraceback("_cdec.SufficientStats.__add__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_sx); + __Pyx_XDECREF((PyObject *)__pyx_v_sy); __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); @@ -6818,7 +7698,7 @@ static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyO else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; @@ -6829,13 +7709,13 @@ static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyO } 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[4]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.CandidateSet.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_evaluator), __pyx_ptype_5_cdec_SegmentEvaluator, 1, "evaluator", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_evaluator), __pyx_ptype_5_cdec_SegmentEvaluator, 1, "evaluator", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = __pyx_pf_5_cdec_12CandidateSet___cinit__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), __pyx_v_evaluator); goto __pyx_L0; __pyx_L1_error:; @@ -6845,7 +7725,7 @@ static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyO return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":64 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":75 * cdef mteval.CandidateSet* cs * * def __cinit__(self, SegmentEvaluator evaluator): # <<<<<<<<<<<<<< @@ -6858,7 +7738,7 @@ static int __pyx_pf_5_cdec_12CandidateSet___cinit__(struct __pyx_obj_5_cdec_Cand __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":65 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":76 * * def __cinit__(self, SegmentEvaluator evaluator): * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) # <<<<<<<<<<<<<< @@ -6867,7 +7747,7 @@ static int __pyx_pf_5_cdec_12CandidateSet___cinit__(struct __pyx_obj_5_cdec_Cand */ __pyx_v_self->scorer = new boost::shared_ptr((__pyx_v_evaluator->scorer[0])); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":66 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":77 * def __cinit__(self, SegmentEvaluator evaluator): * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) * self.metric = evaluator.metric # <<<<<<<<<<<<<< @@ -6876,7 +7756,7 @@ static int __pyx_pf_5_cdec_12CandidateSet___cinit__(struct __pyx_obj_5_cdec_Cand */ __pyx_v_self->metric = __pyx_v_evaluator->metric; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":67 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":78 * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) * self.metric = evaluator.metric * self.cs = new mteval.CandidateSet() # <<<<<<<<<<<<<< @@ -6899,7 +7779,7 @@ static void __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(PyObject *__pyx_v_self) __Pyx_RefNannyFinishContext(); } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":69 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":80 * self.cs = new mteval.CandidateSet() * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -6911,7 +7791,7 @@ static void __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(CYTHON_UNUSED struct __p __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":70 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":81 * * def __dealloc__(self): * del self.scorer # <<<<<<<<<<<<<< @@ -6920,7 +7800,7 @@ static void __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(CYTHON_UNUSED struct __p */ delete __pyx_v_self->scorer; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":71 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 * def __dealloc__(self): * del self.scorer * del self.cs # <<<<<<<<<<<<<< @@ -6943,7 +7823,7 @@ static Py_ssize_t __pyx_pw_5_cdec_12CandidateSet_5__len__(PyObject *__pyx_v_self return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":73 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":84 * del self.cs * * def __len__(self): # <<<<<<<<<<<<<< @@ -6956,7 +7836,7 @@ static Py_ssize_t __pyx_pf_5_cdec_12CandidateSet_4__len__(struct __pyx_obj_5_cde __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__len__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":74 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":85 * * def __len__(self): * return self.cs.size() # <<<<<<<<<<<<<< @@ -6980,7 +7860,7 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_s __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); assert(__pyx_arg_k); { - __pyx_v_k = __Pyx_PyInt_AsInt(__pyx_arg_k); if (unlikely((__pyx_v_k == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_k = __Pyx_PyInt_AsInt(__pyx_arg_k); if (unlikely((__pyx_v_k == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -6993,7 +7873,7 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_s return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":76 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":87 * return self.cs.size() * * def __getitem__(self,int k): # <<<<<<<<<<<<<< @@ -7013,7 +7893,7 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__getitem__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":77 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":88 * * def __getitem__(self,int k): * if not 0 <= k < self.cs.size(): # <<<<<<<<<<<<<< @@ -7027,35 +7907,35 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_ __pyx_t_2 = (!__pyx_t_1); if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":78 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":89 * def __getitem__(self,int k): * if not 0 <= k < self.cs.size(): * raise IndexError('candidate set index out of range') # <<<<<<<<<<<<<< * cdef Candidate candidate = Candidate() * candidate.candidate = &self.cs[0][k] */ - __pyx_t_3 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_22), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_36), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":79 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":90 * if not 0 <= k < self.cs.size(): * raise IndexError('candidate set index out of range') * cdef Candidate candidate = Candidate() # <<<<<<<<<<<<<< * candidate.candidate = &self.cs[0][k] * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) */ - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Candidate)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Candidate)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_v_candidate = ((struct __pyx_obj_5_cdec_Candidate *)__pyx_t_3); __pyx_t_3 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":80 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":91 * raise IndexError('candidate set index out of range') * cdef Candidate candidate = Candidate() * candidate.candidate = &self.cs[0][k] # <<<<<<<<<<<<<< @@ -7064,7 +7944,7 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_ */ __pyx_v_candidate->candidate = (&((__pyx_v_self->cs[0])[__pyx_v_k])); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":81 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":92 * cdef Candidate candidate = Candidate() * candidate.candidate = &self.cs[0][k] * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) # <<<<<<<<<<<<<< @@ -7073,7 +7953,7 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_ */ __pyx_v_candidate->score = __pyx_v_self->metric->ComputeScore(((__pyx_v_self->cs[0])[__pyx_v_k]).eval_feats); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":93 * candidate.candidate = &self.cs[0][k] * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) * return candidate # <<<<<<<<<<<<<< @@ -7110,7 +7990,7 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_9__iter__(PyObject *__pyx_v_self return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":84 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":95 * return candidate * * def __iter__(self): # <<<<<<<<<<<<<< @@ -7119,14 +7999,14 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_9__iter__(PyObject *__pyx_v_self */ static PyObject *__pyx_pf_5_cdec_12CandidateSet_8__iter__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *__pyx_cur_scope; + struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__iter__", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_8___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_8___iter__, __pyx_empty_tuple, NULL); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_10___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_10___iter__, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -7136,7 +8016,7 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_8__iter__(struct __pyx_obj_5_cde __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12CandidateSet_10generator8, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12CandidateSet_10generator8, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -7156,7 +8036,7 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_8__iter__(struct __pyx_obj_5_cde static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *)__pyx_generator->closure); + struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; Py_ssize_t __pyx_t_1; unsigned int __pyx_t_2; @@ -7171,27 +8051,27 @@ static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator8(__pyx_GeneratorObje return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":86 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":97 * def __iter__(self): * cdef unsigned i * for i in range(len(self)): # <<<<<<<<<<<<<< * yield self[i] * */ - __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":87 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":98 * cdef unsigned i * for i in range(len(self)): * yield self[i] # <<<<<<<<<<<<<< * * def add_kbest(self, Hypergraph hypergraph, unsigned k): */ - __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; @@ -7205,7 +8085,7 @@ static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator8(__pyx_GeneratorObje __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[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; @@ -7249,11 +8129,11 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_se values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k); if (likely(values[1])) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_kbest") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_kbest") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; @@ -7262,17 +8142,17 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_se values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_hypergraph = ((struct __pyx_obj_5_cdec_Hypergraph *)values[0]); - __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.CandidateSet.add_kbest", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_hypergraph), __pyx_ptype_5_cdec_Hypergraph, 1, "hypergraph", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_hypergraph), __pyx_ptype_5_cdec_Hypergraph, 1, "hypergraph", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = __pyx_pf_5_cdec_12CandidateSet_11add_kbest(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), __pyx_v_hypergraph, __pyx_v_k); goto __pyx_L0; __pyx_L1_error:; @@ -7282,7 +8162,7 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_se return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":89 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":100 * yield self[i] * * def add_kbest(self, Hypergraph hypergraph, unsigned k): # <<<<<<<<<<<<<< @@ -7295,7 +8175,7 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_11add_kbest(struct __pyx_obj_5_c __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("add_kbest", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":90 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":101 * * def add_kbest(self, Hypergraph hypergraph, unsigned k): * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) # <<<<<<<<<<<<<< @@ -7319,7 +8199,7 @@ static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_se __Pyx_RefNannyFinishContext(); } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":96 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":107 * cdef mteval.EvaluationMetric* metric * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -7331,7 +8211,7 @@ static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":97 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":108 * * def __dealloc__(self): * del self.scorer # <<<<<<<<<<<<<< @@ -7354,7 +8234,7 @@ static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_ return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":99 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":110 * del self.scorer * * def evaluate(self, sentence): # <<<<<<<<<<<<<< @@ -7374,19 +8254,19 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5 int __pyx_clineno = 0; __Pyx_RefNannySetupContext("evaluate", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":101 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":112 * def evaluate(self, sentence): * cdef vector[WordID] hyp * cdef SufficientStats sf = SufficientStats() # <<<<<<<<<<<<<< * sf.metric = self.metric * sf.stats = new mteval.SufficientStats() */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_sf = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":102 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":113 * cdef vector[WordID] hyp * cdef SufficientStats sf = SufficientStats() * sf.metric = self.metric # <<<<<<<<<<<<<< @@ -7395,7 +8275,7 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5 */ __pyx_v_sf->metric = __pyx_v_self->metric; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":103 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":114 * cdef SufficientStats sf = SufficientStats() * sf.metric = self.metric * sf.stats = new mteval.SufficientStats() # <<<<<<<<<<<<<< @@ -7404,22 +8284,22 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5 */ __pyx_v_sf->stats = new SufficientStats(); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":104 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 * sf.metric = self.metric * sf.stats = new mteval.SufficientStats() * ConvertSentence(string(as_str(sentence.strip())), &hyp) # <<<<<<<<<<<<<< * self.scorer.get().Evaluate(hyp, sf.stats) * return sf */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_2, NULL)), (&__pyx_v_hyp)); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":105 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":116 * sf.stats = new mteval.SufficientStats() * ConvertSentence(string(as_str(sentence.strip())), &hyp) * self.scorer.get().Evaluate(hyp, sf.stats) # <<<<<<<<<<<<<< @@ -7428,7 +8308,7 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5 */ __pyx_v_self->scorer->get()->Evaluate(__pyx_v_hyp, __pyx_v_sf->stats); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":106 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":117 * ConvertSentence(string(as_str(sentence.strip())), &hyp) * self.scorer.get().Evaluate(hyp, sf.stats) * return sf # <<<<<<<<<<<<<< @@ -7465,7 +8345,7 @@ static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__p return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":108 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":119 * return sf * * def candidate_set(self): # <<<<<<<<<<<<<< @@ -7483,7 +8363,7 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("candidate_set", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":109 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":120 * * def candidate_set(self): * return CandidateSet(self) # <<<<<<<<<<<<<< @@ -7491,12 +8371,12 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_ * cdef class Scorer: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_CandidateSet)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_CandidateSet)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; @@ -7542,18 +8422,18 @@ static int __pyx_pw_5_cdec_6Scorer_1__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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 125; __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_name = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_name = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 125; __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[4]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.Scorer.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -7564,7 +8444,7 @@ static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject * return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":114 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":125 * cdef string* name * * def __cinit__(self, char* name): # <<<<<<<<<<<<<< @@ -7577,7 +8457,7 @@ static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__p __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":126 * * def __cinit__(self, char* name): * self.name = new string(name) # <<<<<<<<<<<<<< @@ -7600,7 +8480,7 @@ static void __pyx_pw_5_cdec_6Scorer_3__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyFinishContext(); } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":117 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":128 * self.name = new string(name) * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -7612,7 +8492,7 @@ static void __pyx_pf_5_cdec_6Scorer_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_ __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":118 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":129 * * def __dealloc__(self): * del self.name # <<<<<<<<<<<<<< @@ -7650,7 +8530,7 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObj else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; @@ -7661,7 +8541,7 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObj } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.Scorer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -7672,7 +8552,7 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObj return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":120 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":131 * del self.name * * def __call__(self, refs): # <<<<<<<<<<<<<< @@ -7702,7 +8582,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score __Pyx_RefNannySetupContext("__call__", 0); __Pyx_INCREF(__pyx_v_refs); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":121 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":132 * * def __call__(self, refs): * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) # <<<<<<<<<<<<<< @@ -7711,7 +8591,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_metric = EvaluationMetric::Instance((__pyx_v_self->name[0])); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":122 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":133 * def __call__(self, refs): * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) * if isinstance(refs, unicode) or isinstance(refs, str): # <<<<<<<<<<<<<< @@ -7733,14 +8613,14 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score } if (__pyx_t_4) { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":123 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":134 * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) * if isinstance(refs, unicode) or isinstance(refs, str): * refs = [refs] # <<<<<<<<<<<<<< * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() * cdef vector[WordID]* refv */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_refs); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_refs); @@ -7752,7 +8632,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":124 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":135 * if isinstance(refs, unicode) or isinstance(refs, str): * refs = [refs] * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() # <<<<<<<<<<<<<< @@ -7761,7 +8641,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_refsv = new std::vector >(); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":127 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":138 * cdef vector[WordID]* refv * cdef bytes ref_str * for ref in refs: # <<<<<<<<<<<<<< @@ -7772,7 +8652,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score __pyx_t_1 = __pyx_v_refs; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0; __pyx_t_6 = NULL; } else { - __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_refs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_refs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; } @@ -7788,7 +8668,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score if (unlikely(!__pyx_t_7)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } @@ -7798,7 +8678,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score __pyx_v_ref = __pyx_t_7; __pyx_t_7 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":128 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":139 * cdef bytes ref_str * for ref in refs: * refv = new vector[WordID]() # <<<<<<<<<<<<<< @@ -7807,22 +8687,22 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_refv = new std::vector(); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":129 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":140 * for ref in refs: * refv = new vector[WordID]() * ConvertSentence(string(as_str(ref.strip())), refv) # <<<<<<<<<<<<<< * refsv.push_back(refv[0]) * del refv */ - __pyx_t_7 = PyObject_GetAttr(__pyx_v_ref, __pyx_n_s__strip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PyObject_GetAttr(__pyx_v_ref, __pyx_n_s__strip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_8, NULL)), __pyx_v_refv); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":130 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":141 * refv = new vector[WordID]() * ConvertSentence(string(as_str(ref.strip())), refv) * refsv.push_back(refv[0]) # <<<<<<<<<<<<<< @@ -7831,7 +8711,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_refsv->push_back((__pyx_v_refv[0])); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":131 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":142 * ConvertSentence(string(as_str(ref.strip())), refv) * refsv.push_back(refv[0]) * del refv # <<<<<<<<<<<<<< @@ -7842,19 +8722,19 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":133 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":144 * del refv * cdef unsigned i * cdef SegmentEvaluator evaluator = SegmentEvaluator() # <<<<<<<<<<<<<< * evaluator.metric = metric * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SegmentEvaluator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SegmentEvaluator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_evaluator = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":134 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":145 * cdef unsigned i * cdef SegmentEvaluator evaluator = SegmentEvaluator() * evaluator.metric = metric # <<<<<<<<<<<<<< @@ -7863,7 +8743,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_evaluator->metric = __pyx_v_metric; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":135 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":146 * cdef SegmentEvaluator evaluator = SegmentEvaluator() * evaluator.metric = metric * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) # <<<<<<<<<<<<<< @@ -7872,7 +8752,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_evaluator->scorer = new boost::shared_ptr(__pyx_v_metric->CreateSegmentEvaluator((__pyx_v_refsv[0]))); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":136 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":147 * evaluator.metric = metric * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) * del refsv # in theory should not delete but store in SegmentEvaluator # <<<<<<<<<<<<<< @@ -7881,7 +8761,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score */ delete __pyx_v_refsv; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":137 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":148 * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) * del refsv # in theory should not delete but store in SegmentEvaluator * return evaluator # <<<<<<<<<<<<<< @@ -7921,7 +8801,7 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_7__str__(PyObject *__pyx_v_self) { return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":139 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":150 * return evaluator * * def __str__(self): # <<<<<<<<<<<<<< @@ -7938,7 +8818,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__str__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":140 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":151 * * def __str__(self): * return self.name.c_str() # <<<<<<<<<<<<<< @@ -7946,7 +8826,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer * BLEU = Scorer('IBM_BLEU') */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(__pyx_v_self->name->c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(__pyx_v_self->name->c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; @@ -8013,7 +8893,7 @@ static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject } /* "_cdec.pyx":19 - * cdef public DenseVector weights + * cdef DenseVector weights * * def __cinit__(self, char* config): # <<<<<<<<<<<<<< * decoder.register_feature_functions() @@ -8127,13 +9007,306 @@ static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj * def __dealloc__(self): * del self.dec # <<<<<<<<<<<<<< * - * def read_weights(self, cfg): + * property weights: */ delete __pyx_v_self->dec; __Pyx_RefNannyFinishContext(); } +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights___get__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":31 + * + * property weights: + * def __get__(self): # <<<<<<<<<<<<<< + * return self.weights + * + */ + +static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + + /* "_cdec.pyx":32 + * property weights: + * def __get__(self): + * return self.weights # <<<<<<<<<<<<<< + * + * def __set__(self, weights): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->weights)); + __pyx_r = ((PyObject *)__pyx_v_self->weights); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_weights); /*proto*/ +static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_weights) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_2__set__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_weights)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":34 + * return self.weights + * + * def __set__(self, weights): # <<<<<<<<<<<<<< + * if isinstance(weights, DenseVector): + * self.weights.vector[0] = ( weights).vector[0] + */ + +static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_weights) { + PyObject *__pyx_v_fname = NULL; + PyObject *__pyx_v_fval = NULL; + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *(*__pyx_t_9)(PyObject *); + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); + + /* "_cdec.pyx":35 + * + * def __set__(self, weights): + * if isinstance(weights, DenseVector): # <<<<<<<<<<<<<< + * self.weights.vector[0] = ( weights).vector[0] + * elif isinstance(weights, SparseVector): + */ + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":36 + * def __set__(self, weights): + * if isinstance(weights, DenseVector): + * self.weights.vector[0] = ( weights).vector[0] # <<<<<<<<<<<<<< + * elif isinstance(weights, SparseVector): + * self.weights.vector.clear() + */ + (__pyx_v_self->weights->vector[0]) = (((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_weights)->vector[0]); + goto __pyx_L3; + } + + /* "_cdec.pyx":37 + * if isinstance(weights, DenseVector): + * self.weights.vector[0] = ( weights).vector[0] + * elif isinstance(weights, SparseVector): # <<<<<<<<<<<<<< + * self.weights.vector.clear() + * (( weights).vector[0]).init_vector(self.weights.vector) + */ + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":38 + * self.weights.vector[0] = ( weights).vector[0] + * elif isinstance(weights, SparseVector): + * self.weights.vector.clear() # <<<<<<<<<<<<<< + * (( weights).vector[0]).init_vector(self.weights.vector) + * elif isinstance(weights, dict): + */ + __pyx_v_self->weights->vector->clear(); + + /* "_cdec.pyx":39 + * elif isinstance(weights, SparseVector): + * self.weights.vector.clear() + * (( weights).vector[0]).init_vector(self.weights.vector) # <<<<<<<<<<<<<< + * elif isinstance(weights, dict): + * for fname, fval in weights.items(): + */ + (((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_weights)->vector[0]).init_vector(__pyx_v_self->weights->vector); + goto __pyx_L3; + } + + /* "_cdec.pyx":40 + * self.weights.vector.clear() + * (( weights).vector[0]).init_vector(self.weights.vector) + * elif isinstance(weights, dict): # <<<<<<<<<<<<<< + * for fname, fval in weights.items(): + * self.weights[fname] = fval + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyDict_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":41 + * (( weights).vector[0]).init_vector(self.weights.vector) + * elif isinstance(weights, dict): + * for fname, fval in weights.items(): # <<<<<<<<<<<<<< + * self.weights[fname] = fval + * else: + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_weights, __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; + } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; + } else { + __pyx_t_3 = __pyx_t_5(__pyx_t_1); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { + PyObject* sequence = __pyx_t_3; + if (likely(PyTuple_CheckExact(sequence))) { + 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 = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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 = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_6 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_8 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; + index = 0; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L7_unpacking_done; + __pyx_L6_unpacking_failed:; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L7_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_fname); + __pyx_v_fname = __pyx_t_6; + __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_v_fval); + __pyx_v_fval = __pyx_t_7; + __pyx_t_7 = 0; + + /* "_cdec.pyx":42 + * elif isinstance(weights, dict): + * for fname, fval in weights.items(): + * self.weights[fname] = fval # <<<<<<<<<<<<<< + * else: + * raise TypeError('cannot initialize weights with %s' % type(weights)) + */ + if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_v_fname, __pyx_v_fval) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "_cdec.pyx":44 + * self.weights[fname] = fval + * else: + * raise TypeError('cannot initialize weights with %s' % type(weights)) # <<<<<<<<<<<<<< + * + * def read_weights(self, cfg): + */ + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_37), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_cdec.Decoder.weights.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_fname); + __Pyx_XDECREF(__pyx_v_fval); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + /* Python wrapper */ static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_cfg); /*proto*/ static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_cfg) { @@ -8145,8 +9318,8 @@ static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, return __pyx_r; } -/* "_cdec.pyx":30 - * del self.dec +/* "_cdec.pyx":46 + * raise TypeError('cannot initialize weights with %s' % type(weights)) * * def read_weights(self, cfg): # <<<<<<<<<<<<<< * with open(cfg) as fp: @@ -8181,7 +9354,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_weights", 0); - /* "_cdec.pyx":31 + /* "_cdec.pyx":47 * * def read_weights(self, cfg): * with open(cfg) as fp: # <<<<<<<<<<<<<< @@ -8189,19 +9362,19 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ * fname, value = line.split() */ /*with:*/ { - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __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 = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__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 = 31; __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 = 47; __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 = 31; __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 = 47; __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 = 31; __pyx_clineno = __LINE__; goto __pyx_L3_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 = 47; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; @@ -8216,7 +9389,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ __pyx_v_fp = __pyx_t_4; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "_cdec.pyx":32 + /* "_cdec.pyx":48 * def read_weights(self, cfg): * with open(cfg) as fp: * for line in fp: # <<<<<<<<<<<<<< @@ -8227,7 +9400,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ __pyx_t_4 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; __pyx_t_9 = NULL; } else { - __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; } @@ -8243,7 +9416,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ if (unlikely(!__pyx_t_2)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L7_error;} } break; } @@ -8253,16 +9426,16 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ __pyx_v_line = __pyx_t_2; __pyx_t_2 = 0; - /* "_cdec.pyx":33 + /* "_cdec.pyx":49 * with open(cfg) as fp: * for line in fp: * fname, value = line.split() # <<<<<<<<<<<<<< * self.weights[fname.strip()] = float(value) * */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { @@ -8271,7 +9444,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ 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 = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L7_error;} } __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); @@ -8279,7 +9452,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ 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 = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L7_error;} } __pyx_t_2 = PyList_GET_ITEM(sequence, 0); __pyx_t_10 = PyList_GET_ITEM(sequence, 1); @@ -8289,7 +9462,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { Py_ssize_t index = -1; - __pyx_t_11 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_11 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_11); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; @@ -8297,14 +9470,14 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ __Pyx_GOTREF(__pyx_t_2); index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L18_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 = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; goto __pyx_L19_unpacking_done; __pyx_L18_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 = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __pyx_L19_unpacking_done:; } __Pyx_XDECREF(__pyx_v_fname); @@ -8314,22 +9487,22 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ __pyx_v_value = __pyx_t_10; __pyx_t_10 = 0; - /* "_cdec.pyx":34 + /* "_cdec.pyx":50 * for line in fp: * fname, value = line.split() * self.weights[fname.strip()] = float(value) # <<<<<<<<<<<<<< * * def translate(self, sentence, grammar=None): */ - __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 = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_1 = PyFloat_FromDouble(__pyx_t_13); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_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 = 50; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyFloat_FromDouble(__pyx_t_13); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = PyObject_GetAttr(__pyx_v_fname, __pyx_n_s__strip); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_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 = 50; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_t_2, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_t_2, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } @@ -8346,7 +9519,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "_cdec.pyx":31 + /* "_cdec.pyx":47 * * def read_weights(self, cfg): * with open(cfg) as fp: # <<<<<<<<<<<<<< @@ -8355,11 +9528,11 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ */ /*except:*/ { __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_1, &__pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_1, &__pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_GOTREF(__pyx_t_1); __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_INCREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_4); @@ -8372,11 +9545,11 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ __Pyx_GIVEREF(__pyx_t_2); __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 = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L9_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 = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} __pyx_t_16 = (!__pyx_t_14); if (__pyx_t_16) { __Pyx_GIVEREF(__pyx_t_4); @@ -8384,7 +9557,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ __Pyx_GIVEREF(__pyx_t_2); __Pyx_ErrRestore(__pyx_t_4, __pyx_t_1, __pyx_t_2); __pyx_t_4 = 0; __pyx_t_1 = 0; __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} goto __pyx_L22; } __pyx_L22:; @@ -8410,13 +9583,13 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ } /*finally:*/ { if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_23, NULL); + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_38, NULL); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_7); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } } goto __pyx_L23; @@ -8458,7 +9631,7 @@ static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyO { PyObject* values[2] = {0,0}; - /* "_cdec.pyx":36 + /* "_cdec.pyx":52 * self.weights[fname.strip()] = float(value) * * def translate(self, sentence, grammar=None): # <<<<<<<<<<<<<< @@ -8488,7 +9661,7 @@ static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyO } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "translate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "translate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -8503,7 +9676,7 @@ static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(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 = 36; __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 = 52; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -8529,7 +9702,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec int __pyx_clineno = 0; __Pyx_RefNannySetupContext("translate", 0); - /* "_cdec.pyx":37 + /* "_cdec.pyx":53 * * def translate(self, sentence, grammar=None): * if isinstance(sentence, unicode): # <<<<<<<<<<<<<< @@ -8542,22 +9715,22 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "_cdec.pyx":38 + /* "_cdec.pyx":54 * def translate(self, sentence, grammar=None): * if isinstance(sentence, unicode): * inp = sentence.strip().encode('utf8') # <<<<<<<<<<<<<< * elif isinstance(sentence, str): * inp = sentence.strip() */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_39), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_inp = __pyx_t_3; @@ -8565,7 +9738,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec goto __pyx_L3; } - /* "_cdec.pyx":39 + /* "_cdec.pyx":55 * if isinstance(sentence, unicode): * inp = sentence.strip().encode('utf8') * elif isinstance(sentence, str): # <<<<<<<<<<<<<< @@ -8578,16 +9751,16 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_2) { - /* "_cdec.pyx":40 + /* "_cdec.pyx":56 * inp = sentence.strip().encode('utf8') * elif isinstance(sentence, str): * inp = sentence.strip() # <<<<<<<<<<<<<< * elif isinstance(sentence, Lattice): * inp = str(sentence) # PLF format */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); 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_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_inp = __pyx_t_1; @@ -8595,7 +9768,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec goto __pyx_L3; } - /* "_cdec.pyx":41 + /* "_cdec.pyx":57 * elif isinstance(sentence, str): * inp = sentence.strip() * elif isinstance(sentence, Lattice): # <<<<<<<<<<<<<< @@ -8608,19 +9781,19 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "_cdec.pyx":42 + /* "_cdec.pyx":58 * inp = sentence.strip() * elif isinstance(sentence, Lattice): * inp = str(sentence) # PLF format # <<<<<<<<<<<<<< * else: * raise TypeError('Cannot translate input type %s' % type(sentence)) */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __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(__pyx_t_1); __Pyx_INCREF(__pyx_v_sentence); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_sentence); __Pyx_GIVEREF(__pyx_v_sentence); - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); 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_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __pyx_v_inp = __pyx_t_3; @@ -8629,53 +9802,53 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec } /*else*/ { - /* "_cdec.pyx":44 + /* "_cdec.pyx":60 * inp = str(sentence) # PLF format * else: * raise TypeError('Cannot translate input type %s' % type(sentence)) # <<<<<<<<<<<<<< * if grammar: * self.dec.SetSentenceGrammarFromString(string( grammar)) */ - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_25), ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_40), ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __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 = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 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 = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L3:; - /* "_cdec.pyx":45 + /* "_cdec.pyx":61 * else: * raise TypeError('Cannot translate input type %s' % type(sentence)) * if grammar: # <<<<<<<<<<<<<< * self.dec.SetSentenceGrammarFromString(string( grammar)) * cdef decoder.BasicObserver observer = decoder.BasicObserver() */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_grammar); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_grammar); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_2) { - /* "_cdec.pyx":46 + /* "_cdec.pyx":62 * raise TypeError('Cannot translate input type %s' % type(sentence)) * if grammar: * self.dec.SetSentenceGrammarFromString(string( grammar)) # <<<<<<<<<<<<<< * cdef decoder.BasicObserver observer = decoder.BasicObserver() * self.dec.Decode(string(inp), &observer) */ - __pyx_t_4 = PyBytes_AsString(__pyx_v_grammar); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyBytes_AsString(__pyx_v_grammar); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->dec->SetSentenceGrammarFromString(std::string(((char *)__pyx_t_4))); goto __pyx_L4; } __pyx_L4:; - /* "_cdec.pyx":47 + /* "_cdec.pyx":63 * if grammar: * self.dec.SetSentenceGrammarFromString(string( grammar)) * cdef decoder.BasicObserver observer = decoder.BasicObserver() # <<<<<<<<<<<<<< @@ -8684,17 +9857,17 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec */ __pyx_v_observer = BasicObserver(); - /* "_cdec.pyx":48 + /* "_cdec.pyx":64 * self.dec.SetSentenceGrammarFromString(string( grammar)) * cdef decoder.BasicObserver observer = decoder.BasicObserver() * self.dec.Decode(string(inp), &observer) # <<<<<<<<<<<<<< * if observer.hypergraph == NULL: * raise ParseFailed() */ - __pyx_t_4 = PyBytes_AsString(__pyx_v_inp); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyBytes_AsString(__pyx_v_inp); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->dec->Decode(std::string(((char *)__pyx_t_4)), (&__pyx_v_observer)); - /* "_cdec.pyx":49 + /* "_cdec.pyx":65 * cdef decoder.BasicObserver observer = decoder.BasicObserver() * self.dec.Decode(string(inp), &observer) * if observer.hypergraph == NULL: # <<<<<<<<<<<<<< @@ -8704,38 +9877,38 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec __pyx_t_2 = (__pyx_v_observer.hypergraph == NULL); if (__pyx_t_2) { - /* "_cdec.pyx":50 + /* "_cdec.pyx":66 * self.dec.Decode(string(inp), &observer) * if observer.hypergraph == NULL: * raise ParseFailed() # <<<<<<<<<<<<<< * cdef Hypergraph hg = Hypergraph() * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__ParseFailed); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__ParseFailed); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L5; } __pyx_L5:; - /* "_cdec.pyx":51 + /* "_cdec.pyx":67 * if observer.hypergraph == NULL: * raise ParseFailed() * cdef Hypergraph hg = Hypergraph() # <<<<<<<<<<<<<< * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) * return hg */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Hypergraph)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Hypergraph)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_hg = ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_t_1); __pyx_t_1 = 0; - /* "_cdec.pyx":52 + /* "_cdec.pyx":68 * raise ParseFailed() * cdef Hypergraph hg = Hypergraph() * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) # <<<<<<<<<<<<<< @@ -8743,7 +9916,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec */ __pyx_v_hg->hg = new Hypergraph((__pyx_v_observer.hypergraph[0])); - /* "_cdec.pyx":53 + /* "_cdec.pyx":69 * cdef Hypergraph hg = Hypergraph() * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) * return hg # <<<<<<<<<<<<<< @@ -8768,137 +9941,427 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec return __pyx_r; } -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights___get__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; +static PyObject *__pyx_tp_new_5_cdec_DenseVector(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + return o; } -/* "_cdec.pyx":17 - * cdef class Decoder: - * cdef decoder.Decoder* dec - * cdef public DenseVector weights # <<<<<<<<<<<<<< - * - * def __cinit__(self, char* config): - */ - -static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self->weights)); - __pyx_r = ((PyObject *)__pyx_v_self->weights); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; +static void __pyx_tp_dealloc_5_cdec_DenseVector(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); } - -/* Python wrapper */ -static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_2__set__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_value)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; +static PyObject *__pyx_sq_item_5_cdec_DenseVector(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; } -static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__set__", 0); - if (!(likely(((__pyx_v_value) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_value, __pyx_ptype_5_cdec_DenseVector))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(__pyx_v_self->weights); - __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); - __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_value); +static int __pyx_mp_ass_subscript_5_cdec_DenseVector(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_5_cdec_11DenseVector_5__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_DenseVector[] = { + {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_10dot, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("tosparse"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_12tosparse, METH_NOARGS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_DenseVector = { + 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_DenseVector = { + __pyx_pw_5_cdec_11DenseVector_1__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5_cdec_DenseVector, /*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_DenseVector = { + __pyx_pw_5_cdec_11DenseVector_1__len__, /*mp_length*/ + __pyx_pw_5_cdec_11DenseVector_3__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5_cdec_DenseVector, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_DenseVector = { + #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_DenseVector = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.DenseVector"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_DenseVector), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_DenseVector, /*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_DenseVector, /*tp_as_number*/ + &__pyx_tp_as_sequence_DenseVector, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_DenseVector, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_DenseVector, /*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_pw_5_cdec_11DenseVector_7__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_DenseVector, /*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_DenseVector, /*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_SparseVector(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_SparseVector(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_12SparseVector_1__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_5_cdec_SparseVector(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_5_cdec_SparseVector(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_5_cdec_12SparseVector_7__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_SparseVector[] = { + {__Pyx_NAMESTR("copy"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_3copy, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_12dot, METH_O, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_SparseVector = { + __pyx_pw_5_cdec_12SparseVector_30__add__, /*nb_add*/ + __pyx_pw_5_cdec_12SparseVector_32__sub__, /*nb_subtract*/ + __pyx_pw_5_cdec_12SparseVector_34__mul__, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 + __pyx_pw_5_cdec_12SparseVector_36__div__, /*nb_divide*/ + #endif + 0, /*nb_remainder*/ + 0, /*nb_divmod*/ + 0, /*nb_power*/ + __pyx_pw_5_cdec_12SparseVector_20__neg__, /*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 + __pyx_pw_5_cdec_12SparseVector_22__iadd__, /*nb_inplace_add*/ + __pyx_pw_5_cdec_12SparseVector_24__isub__, /*nb_inplace_subtract*/ + __pyx_pw_5_cdec_12SparseVector_26__imul__, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + __pyx_pw_5_cdec_12SparseVector_28__idiv__, /*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 +}; - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Decoder.weights.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} +static PySequenceMethods __pyx_tp_as_sequence_SparseVector = { + __pyx_pw_5_cdec_12SparseVector_16__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5_cdec_SparseVector, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + __pyx_pw_5_cdec_12SparseVector_18__contains__, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; -/* Python wrapper */ -static int __pyx_pw_5_cdec_7Decoder_7weights_5__del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pw_5_cdec_7Decoder_7weights_5__del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_4__del__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} +static PyMappingMethods __pyx_tp_as_mapping_SparseVector = { + __pyx_pw_5_cdec_12SparseVector_16__len__, /*mp_length*/ + __pyx_pw_5_cdec_12SparseVector_5__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5_cdec_SparseVector, /*mp_ass_subscript*/ +}; -static int __pyx_pf_5_cdec_7Decoder_7weights_4__del__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__", 0); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->weights); - __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); - __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); +static PyBufferProcs __pyx_tp_as_buffer_SparseVector = { + #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 +}; - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} +static PyTypeObject __pyx_type_5_cdec_SparseVector = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.SparseVector"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_SparseVector), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_SparseVector, /*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_SparseVector, /*tp_as_number*/ + &__pyx_tp_as_sequence_SparseVector, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_SparseVector, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_SparseVector, /*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*/ + __pyx_pw_5_cdec_12SparseVector_14__richcmp__, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + __pyx_pw_5_cdec_12SparseVector_9__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_SparseVector, /*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_SparseVector, /*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_DenseVector(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_Hypergraph(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_DenseVector(PyObject *o) { - (*Py_TYPE(o)->tp_free)(o); -} -static PyObject *__pyx_sq_item_5_cdec_DenseVector(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} - -static int __pyx_mp_ass_subscript_5_cdec_DenseVector(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_pw_5_cdec_11DenseVector_5__setitem__(o, i, v); - } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); - return -1; +static void __pyx_tp_dealloc_5_cdec_Hypergraph(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_10Hypergraph_1__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_DenseVector[] = { - {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_10dot, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("tosparse"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_12tosparse, METH_NOARGS, __Pyx_DOCSTR(0)}, +static PyMethodDef __pyx_methods_5_cdec_Hypergraph[] = { + {__Pyx_NAMESTR("viterbi"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_3viterbi, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("viterbi_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_5viterbi_tree, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("viterbi_source_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_7viterbi_source_tree, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("viterbi_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_9viterbi_features, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("kbest"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_11kbest, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("kbest_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_14kbest_tree, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("kbest_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_17kbest_features, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("sample"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_20sample, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("intersect"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_23intersect, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("prune"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_25prune, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("lattice"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_27lattice, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("reweight"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_29reweight, METH_O, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_DenseVector = { +static PyNumberMethods __pyx_tp_as_number_Hypergraph = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -8956,11 +10419,11 @@ static PyNumberMethods __pyx_tp_as_number_DenseVector = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_DenseVector = { - __pyx_pw_5_cdec_11DenseVector_1__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence_Hypergraph = { + 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_DenseVector, /*sq_item*/ + 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -8969,13 +10432,13 @@ static PySequenceMethods __pyx_tp_as_sequence_DenseVector = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_DenseVector = { - __pyx_pw_5_cdec_11DenseVector_1__len__, /*mp_length*/ - __pyx_pw_5_cdec_11DenseVector_3__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_5_cdec_DenseVector, /*mp_ass_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping_Hypergraph = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_DenseVector = { +static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -8996,12 +10459,12 @@ static PyBufferProcs __pyx_tp_as_buffer_DenseVector = { #endif }; -static PyTypeObject __pyx_type_5_cdec_DenseVector = { +static PyTypeObject __pyx_type_5_cdec_Hypergraph = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.DenseVector"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_DenseVector), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.Hypergraph"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Hypergraph), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_DenseVector, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_Hypergraph, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -9011,24 +10474,24 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_DenseVector, /*tp_as_number*/ - &__pyx_tp_as_sequence_DenseVector, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_DenseVector, /*tp_as_mapping*/ + &__pyx_tp_as_number_Hypergraph, /*tp_as_number*/ + &__pyx_tp_as_sequence_Hypergraph, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Hypergraph, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_DenseVector, /*tp_as_buffer*/ + &__pyx_tp_as_buffer_Hypergraph, /*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_pw_5_cdec_11DenseVector_7__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_DenseVector, /*tp_methods*/ + __pyx_methods_5_cdec_Hypergraph, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -9038,7 +10501,7 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_DenseVector, /*tp_new*/ + __pyx_tp_new_5_cdec_Hypergraph, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -9052,25 +10515,25 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_SparseVector(PyTypeObject *t, PyObject *a, PyObject *k) { +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_SparseVector(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec_Lattice(PyObject *o) { { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); - __pyx_pw_5_cdec_12SparseVector_1__dealloc__(o); + __pyx_pw_5_cdec_7Lattice_14__dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); } (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_sq_item_5_cdec_SparseVector(PyObject *o, Py_ssize_t i) { +static PyObject *__pyx_sq_item_5_cdec_Lattice(PyObject *o, Py_ssize_t i) { PyObject *r; PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); @@ -9078,9 +10541,9 @@ static PyObject *__pyx_sq_item_5_cdec_SparseVector(PyObject *o, Py_ssize_t i) { return r; } -static int __pyx_mp_ass_subscript_5_cdec_SparseVector(PyObject *o, PyObject *i, PyObject *v) { +static int __pyx_mp_ass_subscript_5_cdec_Lattice(PyObject *o, PyObject *i, PyObject *v) { if (v) { - return __pyx_pw_5_cdec_12SparseVector_7__setitem__(o, i, v); + return __pyx_pw_5_cdec_7Lattice_5__setitem__(o, i, v); } else { PyErr_Format(PyExc_NotImplementedError, @@ -9089,18 +10552,17 @@ static int __pyx_mp_ass_subscript_5_cdec_SparseVector(PyObject *o, PyObject *i, } } -static PyMethodDef __pyx_methods_5_cdec_SparseVector[] = { - {__Pyx_NAMESTR("copy"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_3copy, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_12dot, METH_O, __Pyx_DOCSTR(0)}, +static PyMethodDef __pyx_methods_5_cdec_Lattice[] = { + {__Pyx_NAMESTR("todot"), (PyCFunction)__pyx_pw_5_cdec_7Lattice_16todot, METH_NOARGS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_28__add__, /*nb_add*/ - __pyx_pw_5_cdec_12SparseVector_30__sub__, /*nb_subtract*/ - __pyx_pw_5_cdec_12SparseVector_32__mul__, /*nb_multiply*/ +static PyNumberMethods __pyx_tp_as_number_Lattice = { + 0, /*nb_add*/ + 0, /*nb_subtract*/ + 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 - __pyx_pw_5_cdec_12SparseVector_34__div__, /*nb_divide*/ + 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ @@ -9131,11 +10593,11 @@ static PyNumberMethods __pyx_tp_as_number_SparseVector = { #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif - __pyx_pw_5_cdec_12SparseVector_20__iadd__, /*nb_inplace_add*/ - __pyx_pw_5_cdec_12SparseVector_22__isub__, /*nb_inplace_subtract*/ - __pyx_pw_5_cdec_12SparseVector_24__imul__, /*nb_inplace_multiply*/ + 0, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 - __pyx_pw_5_cdec_12SparseVector_26__idiv__, /*nb_inplace_divide*/ + 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ @@ -9153,26 +10615,26 @@ static PyNumberMethods __pyx_tp_as_number_SparseVector = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_16__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence_Lattice = { + __pyx_pw_5_cdec_7Lattice_7__len__, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_SparseVector, /*sq_item*/ + __pyx_sq_item_5_cdec_Lattice, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ - __pyx_pw_5_cdec_12SparseVector_18__contains__, /*sq_contains*/ + 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_16__len__, /*mp_length*/ - __pyx_pw_5_cdec_12SparseVector_5__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_5_cdec_SparseVector, /*mp_ass_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping_Lattice = { + __pyx_pw_5_cdec_7Lattice_7__len__, /*mp_length*/ + __pyx_pw_5_cdec_7Lattice_3__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5_cdec_Lattice, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_SparseVector = { +static PyBufferProcs __pyx_tp_as_buffer_Lattice = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -9193,12 +10655,12 @@ static PyBufferProcs __pyx_tp_as_buffer_SparseVector = { #endif }; -static PyTypeObject __pyx_type_5_cdec_SparseVector = { +static PyTypeObject __pyx_type_5_cdec_Lattice = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.SparseVector"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_SparseVector), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.Lattice"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Lattice), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_SparseVector, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_Lattice, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -9208,24 +10670,24 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_SparseVector, /*tp_as_number*/ - &__pyx_tp_as_sequence_SparseVector, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_SparseVector, /*tp_as_mapping*/ + &__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*/ - 0, /*tp_str*/ + __pyx_pw_5_cdec_7Lattice_9__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_SparseVector, /*tp_as_buffer*/ + &__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*/ - __pyx_pw_5_cdec_12SparseVector_14__richcmp__, /*tp_richcompare*/ + 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_12SparseVector_9__iter__, /*tp_iter*/ + __pyx_pw_5_cdec_7Lattice_11__iter__, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_SparseVector, /*tp_methods*/ + __pyx_methods_5_cdec_Lattice, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -9233,9 +10695,9 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ - 0, /*tp_init*/ + __pyx_pw_5_cdec_7Lattice_1__init__, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_SparseVector, /*tp_new*/ + __pyx_tp_new_5_cdec_Lattice, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -9249,42 +10711,50 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Hypergraph(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_Candidate(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_Hypergraph(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } +static void __pyx_tp_dealloc_5_cdec_Candidate(PyObject *o) { (*Py_TYPE(o)->tp_free)(o); } -static PyMethodDef __pyx_methods_5_cdec_Hypergraph[] = { - {__Pyx_NAMESTR("viterbi"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_3viterbi, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("viterbi_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_5viterbi_tree, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("viterbi_source_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_7viterbi_source_tree, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("viterbi_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_9viterbi_features, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("kbest"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_11kbest, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("kbest_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_14kbest_tree, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("kbest_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_17kbest_features, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("sample"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_20sample, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("intersect"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_23intersect, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("prune"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_25prune, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("lattice"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_27lattice, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("reweight"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_29reweight, METH_O, __Pyx_DOCSTR(0)}, +static PyObject *__pyx_getprop_5_cdec_9Candidate_words(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9Candidate_5words_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_9Candidate_fmap(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9Candidate_4fmap_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_9Candidate_score(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9Candidate_5score_1__get__(o); +} + +static int __pyx_setprop_5_cdec_9Candidate_score(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_9Candidate_5score_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_Candidate[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_Hypergraph = { +static struct PyGetSetDef __pyx_getsets_5_cdec_Candidate[] = { + {(char *)"words", __pyx_getprop_5_cdec_9Candidate_words, 0, 0, 0}, + {(char *)"fmap", __pyx_getprop_5_cdec_9Candidate_fmap, 0, 0, 0}, + {(char *)"score", __pyx_getprop_5_cdec_9Candidate_score, __pyx_setprop_5_cdec_9Candidate_score, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Candidate = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -9342,7 +10812,7 @@ static PyNumberMethods __pyx_tp_as_number_Hypergraph = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Hypergraph = { +static PySequenceMethods __pyx_tp_as_sequence_Candidate = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -9355,13 +10825,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Hypergraph = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Hypergraph = { +static PyMappingMethods __pyx_tp_as_mapping_Candidate = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = { +static PyBufferProcs __pyx_tp_as_buffer_Candidate = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -9382,12 +10852,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Hypergraph = { +static PyTypeObject __pyx_type_5_cdec_Candidate = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Hypergraph"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Hypergraph), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.Candidate"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Candidate), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Hypergraph, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_Candidate, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -9397,15 +10867,15 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Hypergraph, /*tp_as_number*/ - &__pyx_tp_as_sequence_Hypergraph, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Hypergraph, /*tp_as_mapping*/ + &__pyx_tp_as_number_Candidate, /*tp_as_number*/ + &__pyx_tp_as_sequence_Candidate, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Candidate, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Hypergraph, /*tp_as_buffer*/ + &__pyx_tp_as_buffer_Candidate, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ 0, /*tp_doc*/ 0, /*tp_traverse*/ @@ -9414,9 +10884,9 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Hypergraph, /*tp_methods*/ + __pyx_methods_5_cdec_Candidate, /*tp_methods*/ 0, /*tp_members*/ - 0, /*tp_getset*/ + __pyx_getsets_5_cdec_Candidate, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -9424,7 +10894,7 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Hypergraph, /*tp_new*/ + __pyx_tp_new_5_cdec_Candidate, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -9438,49 +10908,45 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Lattice(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_SufficientStats(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) { +static void __pyx_tp_dealloc_5_cdec_SufficientStats(PyObject *o) { { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); - __pyx_pw_5_cdec_7Lattice_14__dealloc__(o); + __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); } (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_sq_item_5_cdec_Lattice(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; + +static PyObject *__pyx_getprop_5_cdec_15SufficientStats_score(PyObject *o, void *x) { + return __pyx_pw_5_cdec_15SufficientStats_5score_1__get__(o); } -static int __pyx_mp_ass_subscript_5_cdec_Lattice(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_pw_5_cdec_7Lattice_5__setitem__(o, i, v); - } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); - return -1; - } +static PyObject *__pyx_getprop_5_cdec_15SufficientStats_detail(PyObject *o, void *x) { + return __pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(o); } -static PyMethodDef __pyx_methods_5_cdec_Lattice[] = { +static PyMethodDef __pyx_methods_5_cdec_SufficientStats[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_Lattice = { - 0, /*nb_add*/ +static struct PyGetSetDef __pyx_getsets_5_cdec_SufficientStats[] = { + {(char *)"score", __pyx_getprop_5_cdec_15SufficientStats_score, 0, 0, 0}, + {(char *)"detail", __pyx_getprop_5_cdec_15SufficientStats_detail, 0, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_SufficientStats = { + __pyx_pw_5_cdec_15SufficientStats_10__add__, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 @@ -9515,7 +10981,7 @@ static PyNumberMethods __pyx_tp_as_number_Lattice = { #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif - 0, /*nb_inplace_add*/ + __pyx_pw_5_cdec_15SufficientStats_8__iadd__, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 @@ -9537,11 +11003,11 @@ static PyNumberMethods __pyx_tp_as_number_Lattice = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Lattice = { - __pyx_pw_5_cdec_7Lattice_7__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence_SufficientStats = { + __pyx_pw_5_cdec_15SufficientStats_3__len__, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_Lattice, /*sq_item*/ + 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -9550,13 +11016,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Lattice = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Lattice = { - __pyx_pw_5_cdec_7Lattice_7__len__, /*mp_length*/ - __pyx_pw_5_cdec_7Lattice_3__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_5_cdec_Lattice, /*mp_ass_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping_SufficientStats = { + __pyx_pw_5_cdec_15SufficientStats_3__len__, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Lattice = { +static PyBufferProcs __pyx_tp_as_buffer_SufficientStats = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -9577,12 +11043,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Lattice = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Lattice = { +static PyTypeObject __pyx_type_5_cdec_SufficientStats = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Lattice"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Lattice), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.SufficientStats"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_SufficientStats), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Lattice, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_SufficientStats, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -9592,34 +11058,34 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { 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*/ + &__pyx_tp_as_number_SufficientStats, /*tp_as_number*/ + &__pyx_tp_as_sequence_SufficientStats, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_SufficientStats, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ - __pyx_pw_5_cdec_7Lattice_9__str__, /*tp_str*/ + 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Lattice, /*tp_as_buffer*/ + &__pyx_tp_as_buffer_SufficientStats, /*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_pw_5_cdec_7Lattice_11__iter__, /*tp_iter*/ + __pyx_pw_5_cdec_15SufficientStats_5__iter__, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Lattice, /*tp_methods*/ + __pyx_methods_5_cdec_SufficientStats, /*tp_methods*/ 0, /*tp_members*/ - 0, /*tp_getset*/ + __pyx_getsets_5_cdec_SufficientStats, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ - __pyx_pw_5_cdec_7Lattice_1__init__, /*tp_init*/ + 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Lattice, /*tp_new*/ + __pyx_tp_new_5_cdec_SufficientStats, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -9633,50 +11099,41 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Candidate(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_CandidateSet(PyTypeObject *t, PyObject *a, PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + if (__pyx_pw_5_cdec_12CandidateSet_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } return o; } -static void __pyx_tp_dealloc_5_cdec_Candidate(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec_CandidateSet(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } (*Py_TYPE(o)->tp_free)(o); } - -static PyObject *__pyx_getprop_5_cdec_9Candidate_words(PyObject *o, void *x) { - return __pyx_pw_5_cdec_9Candidate_5words_1__get__(o); -} - -static PyObject *__pyx_getprop_5_cdec_9Candidate_fmap(PyObject *o, void *x) { - return __pyx_pw_5_cdec_9Candidate_4fmap_1__get__(o); -} - -static PyObject *__pyx_getprop_5_cdec_9Candidate_score(PyObject *o, void *x) { - return __pyx_pw_5_cdec_9Candidate_5score_1__get__(o); -} - -static int __pyx_setprop_5_cdec_9Candidate_score(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_5_cdec_9Candidate_5score_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } +static PyObject *__pyx_sq_item_5_cdec_CandidateSet(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; } -static PyMethodDef __pyx_methods_5_cdec_Candidate[] = { - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_5_cdec_Candidate[] = { - {(char *)"words", __pyx_getprop_5_cdec_9Candidate_words, 0, 0, 0}, - {(char *)"fmap", __pyx_getprop_5_cdec_9Candidate_fmap, 0, 0, 0}, - {(char *)"score", __pyx_getprop_5_cdec_9Candidate_score, __pyx_setprop_5_cdec_9Candidate_score, 0, 0}, - {0, 0, 0, 0, 0} +static PyMethodDef __pyx_methods_5_cdec_CandidateSet[] = { + {__Pyx_NAMESTR("add_kbest"), (PyCFunction)__pyx_pw_5_cdec_12CandidateSet_12add_kbest, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_Candidate = { +static PyNumberMethods __pyx_tp_as_number_CandidateSet = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -9734,11 +11191,11 @@ static PyNumberMethods __pyx_tp_as_number_Candidate = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Candidate = { - 0, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence_CandidateSet = { + __pyx_pw_5_cdec_12CandidateSet_5__len__, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - 0, /*sq_item*/ + __pyx_sq_item_5_cdec_CandidateSet, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -9747,13 +11204,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Candidate = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Candidate = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping_CandidateSet = { + __pyx_pw_5_cdec_12CandidateSet_5__len__, /*mp_length*/ + __pyx_pw_5_cdec_12CandidateSet_7__getitem__, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Candidate = { +static PyBufferProcs __pyx_tp_as_buffer_CandidateSet = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -9774,12 +11231,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Candidate = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Candidate = { +static PyTypeObject __pyx_type_5_cdec_CandidateSet = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Candidate"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Candidate), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.CandidateSet"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_CandidateSet), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Candidate, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_CandidateSet, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -9789,26 +11246,26 @@ static PyTypeObject __pyx_type_5_cdec_Candidate = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Candidate, /*tp_as_number*/ - &__pyx_tp_as_sequence_Candidate, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Candidate, /*tp_as_mapping*/ + &__pyx_tp_as_number_CandidateSet, /*tp_as_number*/ + &__pyx_tp_as_sequence_CandidateSet, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_CandidateSet, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Candidate, /*tp_as_buffer*/ + &__pyx_tp_as_buffer_CandidateSet, /*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*/ - 0, /*tp_iter*/ + __pyx_pw_5_cdec_12CandidateSet_9__iter__, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Candidate, /*tp_methods*/ + __pyx_methods_5_cdec_CandidateSet, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_5_cdec_Candidate, /*tp_getset*/ + 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -9816,7 +11273,7 @@ static PyTypeObject __pyx_type_5_cdec_Candidate = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Candidate, /*tp_new*/ + __pyx_tp_new_5_cdec_CandidateSet, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -9830,18 +11287,18 @@ static PyTypeObject __pyx_type_5_cdec_Candidate = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_SufficientStats(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_SegmentEvaluator(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_SufficientStats(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec_SegmentEvaluator(PyObject *o) { { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); - __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(o); + __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); @@ -9849,26 +11306,14 @@ static void __pyx_tp_dealloc_5_cdec_SufficientStats(PyObject *o) { (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_getprop_5_cdec_15SufficientStats_score(PyObject *o, void *x) { - return __pyx_pw_5_cdec_15SufficientStats_5score_1__get__(o); -} - -static PyObject *__pyx_getprop_5_cdec_15SufficientStats_detail(PyObject *o, void *x) { - return __pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(o); -} - -static PyMethodDef __pyx_methods_5_cdec_SufficientStats[] = { +static PyMethodDef __pyx_methods_5_cdec_SegmentEvaluator[] = { + {__Pyx_NAMESTR("evaluate"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("candidate_set"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set, METH_NOARGS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; -static struct PyGetSetDef __pyx_getsets_5_cdec_SufficientStats[] = { - {(char *)"score", __pyx_getprop_5_cdec_15SufficientStats_score, 0, 0, 0}, - {(char *)"detail", __pyx_getprop_5_cdec_15SufficientStats_detail, 0, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_SufficientStats = { - __pyx_pw_5_cdec_15SufficientStats_10__add__, /*nb_add*/ +static PyNumberMethods __pyx_tp_as_number_SegmentEvaluator = { + 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 @@ -9903,7 +11348,7 @@ static PyNumberMethods __pyx_tp_as_number_SufficientStats = { #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif - __pyx_pw_5_cdec_15SufficientStats_8__iadd__, /*nb_inplace_add*/ + 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 @@ -9925,8 +11370,8 @@ static PyNumberMethods __pyx_tp_as_number_SufficientStats = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_SufficientStats = { - __pyx_pw_5_cdec_15SufficientStats_3__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence_SegmentEvaluator = { + 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ @@ -9938,13 +11383,13 @@ static PySequenceMethods __pyx_tp_as_sequence_SufficientStats = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_SufficientStats = { - __pyx_pw_5_cdec_15SufficientStats_3__len__, /*mp_length*/ +static PyMappingMethods __pyx_tp_as_mapping_SegmentEvaluator = { + 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_SufficientStats = { +static PyBufferProcs __pyx_tp_as_buffer_SegmentEvaluator = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -9965,12 +11410,12 @@ static PyBufferProcs __pyx_tp_as_buffer_SufficientStats = { #endif }; -static PyTypeObject __pyx_type_5_cdec_SufficientStats = { +static PyTypeObject __pyx_type_5_cdec_SegmentEvaluator = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.SufficientStats"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_SufficientStats), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.SegmentEvaluator"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_SegmentEvaluator), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_SufficientStats, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_SegmentEvaluator, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -9980,26 +11425,26 @@ static PyTypeObject __pyx_type_5_cdec_SufficientStats = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_SufficientStats, /*tp_as_number*/ - &__pyx_tp_as_sequence_SufficientStats, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_SufficientStats, /*tp_as_mapping*/ + &__pyx_tp_as_number_SegmentEvaluator, /*tp_as_number*/ + &__pyx_tp_as_sequence_SegmentEvaluator, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_SegmentEvaluator, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_SufficientStats, /*tp_as_buffer*/ + &__pyx_tp_as_buffer_SegmentEvaluator, /*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_pw_5_cdec_15SufficientStats_5__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_SufficientStats, /*tp_methods*/ + __pyx_methods_5_cdec_SegmentEvaluator, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_5_cdec_SufficientStats, /*tp_getset*/ + 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -10007,7 +11452,7 @@ static PyTypeObject __pyx_type_5_cdec_SufficientStats = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_SufficientStats, /*tp_new*/ + __pyx_tp_new_5_cdec_SegmentEvaluator, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -10021,41 +11466,33 @@ static PyTypeObject __pyx_type_5_cdec_SufficientStats = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_CandidateSet(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_Scorer(PyTypeObject *t, PyObject *a, PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - if (__pyx_pw_5_cdec_12CandidateSet_1__cinit__(o, a, k) < 0) { + if (__pyx_pw_5_cdec_6Scorer_1__cinit__(o, a, k) < 0) { Py_DECREF(o); o = 0; } return o; } -static void __pyx_tp_dealloc_5_cdec_CandidateSet(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec_Scorer(PyObject *o) { { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); - __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(o); + __pyx_pw_5_cdec_6Scorer_3__dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); } (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_sq_item_5_cdec_CandidateSet(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} -static PyMethodDef __pyx_methods_5_cdec_CandidateSet[] = { - {__Pyx_NAMESTR("add_kbest"), (PyCFunction)__pyx_pw_5_cdec_12CandidateSet_12add_kbest, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, +static PyMethodDef __pyx_methods_5_cdec_Scorer[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_CandidateSet = { +static PyNumberMethods __pyx_tp_as_number_Scorer = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -10113,11 +11550,11 @@ static PyNumberMethods __pyx_tp_as_number_CandidateSet = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_CandidateSet = { - __pyx_pw_5_cdec_12CandidateSet_5__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence_Scorer = { + 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_CandidateSet, /*sq_item*/ + 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -10126,13 +11563,13 @@ static PySequenceMethods __pyx_tp_as_sequence_CandidateSet = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_CandidateSet = { - __pyx_pw_5_cdec_12CandidateSet_5__len__, /*mp_length*/ - __pyx_pw_5_cdec_12CandidateSet_7__getitem__, /*mp_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping_Scorer = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_CandidateSet = { +static PyBufferProcs __pyx_tp_as_buffer_Scorer = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -10153,12 +11590,12 @@ static PyBufferProcs __pyx_tp_as_buffer_CandidateSet = { #endif }; -static PyTypeObject __pyx_type_5_cdec_CandidateSet = { +static PyTypeObject __pyx_type_5_cdec_Scorer = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.CandidateSet"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_CandidateSet), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.Scorer"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Scorer), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_CandidateSet, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_Scorer, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -10168,24 +11605,24 @@ static PyTypeObject __pyx_type_5_cdec_CandidateSet = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_CandidateSet, /*tp_as_number*/ - &__pyx_tp_as_sequence_CandidateSet, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_CandidateSet, /*tp_as_mapping*/ + &__pyx_tp_as_number_Scorer, /*tp_as_number*/ + &__pyx_tp_as_sequence_Scorer, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Scorer, /*tp_as_mapping*/ 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ + __pyx_pw_5_cdec_6Scorer_5__call__, /*tp_call*/ + __pyx_pw_5_cdec_6Scorer_7__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_CandidateSet, /*tp_as_buffer*/ + &__pyx_tp_as_buffer_Scorer, /*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_pw_5_cdec_12CandidateSet_9__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_CandidateSet, /*tp_methods*/ + __pyx_methods_5_cdec_Scorer, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -10195,7 +11632,7 @@ static PyTypeObject __pyx_type_5_cdec_CandidateSet = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_CandidateSet, /*tp_new*/ + __pyx_tp_new_5_cdec_Scorer, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -10209,32 +11646,77 @@ static PyTypeObject __pyx_type_5_cdec_CandidateSet = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_SegmentEvaluator(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_Decoder(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec_Decoder *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + p = ((struct __pyx_obj_5_cdec_Decoder *)o); + p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_5_cdec_7Decoder_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } return o; } -static void __pyx_tp_dealloc_5_cdec_SegmentEvaluator(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec_Decoder(PyObject *o) { + struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); - __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(o); + __pyx_pw_5_cdec_7Decoder_3__dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); } + Py_XDECREF(((PyObject *)p->weights)); (*Py_TYPE(o)->tp_free)(o); } -static PyMethodDef __pyx_methods_5_cdec_SegmentEvaluator[] = { - {__Pyx_NAMESTR("evaluate"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("candidate_set"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set, METH_NOARGS, __Pyx_DOCSTR(0)}, +static int __pyx_tp_traverse_5_cdec_Decoder(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; + if (p->weights) { + e = (*v)(((PyObject*)p->weights), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5_cdec_Decoder(PyObject *o) { + struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; + PyObject* tmp; + tmp = ((PyObject*)p->weights); + p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_5_cdec_7Decoder_weights(PyObject *o, void *x) { + return __pyx_pw_5_cdec_7Decoder_7weights_1__get__(o); +} + +static int __pyx_setprop_5_cdec_7Decoder_weights(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_7Decoder_7weights_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_Decoder[] = { + {__Pyx_NAMESTR("read_weights"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_5read_weights, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("translate"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_7translate, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_SegmentEvaluator = { +static struct PyGetSetDef __pyx_getsets_5_cdec_Decoder[] = { + {(char *)"weights", __pyx_getprop_5_cdec_7Decoder_weights, __pyx_setprop_5_cdec_7Decoder_weights, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Decoder = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -10292,7 +11774,7 @@ static PyNumberMethods __pyx_tp_as_number_SegmentEvaluator = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_SegmentEvaluator = { +static PySequenceMethods __pyx_tp_as_sequence_Decoder = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -10305,13 +11787,13 @@ static PySequenceMethods __pyx_tp_as_sequence_SegmentEvaluator = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_SegmentEvaluator = { +static PyMappingMethods __pyx_tp_as_mapping_Decoder = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_SegmentEvaluator = { +static PyBufferProcs __pyx_tp_as_buffer_Decoder = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -10332,12 +11814,12 @@ static PyBufferProcs __pyx_tp_as_buffer_SegmentEvaluator = { #endif }; -static PyTypeObject __pyx_type_5_cdec_SegmentEvaluator = { +static PyTypeObject __pyx_type_5_cdec_Decoder = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.SegmentEvaluator"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_SegmentEvaluator), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.Decoder"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Decoder), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_SegmentEvaluator, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_Decoder, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -10347,26 +11829,26 @@ static PyTypeObject __pyx_type_5_cdec_SegmentEvaluator = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_SegmentEvaluator, /*tp_as_number*/ - &__pyx_tp_as_sequence_SegmentEvaluator, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_SegmentEvaluator, /*tp_as_mapping*/ + &__pyx_tp_as_number_Decoder, /*tp_as_number*/ + &__pyx_tp_as_sequence_Decoder, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Decoder, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_SegmentEvaluator, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer_Decoder, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec_Decoder, /*tp_traverse*/ + __pyx_tp_clear_5_cdec_Decoder, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_SegmentEvaluator, /*tp_methods*/ + __pyx_methods_5_cdec_Decoder, /*tp_methods*/ 0, /*tp_members*/ - 0, /*tp_getset*/ + __pyx_getsets_5_cdec_Decoder, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -10374,7 +11856,7 @@ static PyTypeObject __pyx_type_5_cdec_SegmentEvaluator = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_SegmentEvaluator, /*tp_new*/ + __pyx_tp_new_5_cdec_Decoder, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -10388,33 +11870,44 @@ static PyTypeObject __pyx_type_5_cdec_SegmentEvaluator = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Scorer(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct____iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - if (__pyx_pw_5_cdec_6Scorer_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o); + p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec_Scorer(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_6Scorer_3__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static PyMethodDef __pyx_methods_5_cdec_Scorer[] = { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct____iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_Scorer = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -10472,7 +11965,7 @@ static PyNumberMethods __pyx_tp_as_number_Scorer = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Scorer = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct____iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -10485,13 +11978,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Scorer = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Scorer = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct____iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Scorer = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -10512,12 +12005,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Scorer = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Scorer = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Scorer"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Scorer), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct____iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct____iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Scorer, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -10527,24 +12020,24 @@ static PyTypeObject __pyx_type_5_cdec_Scorer = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Scorer, /*tp_as_number*/ - &__pyx_tp_as_sequence_Scorer, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Scorer, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct____iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct____iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct____iter__, /*tp_as_mapping*/ 0, /*tp_hash*/ - __pyx_pw_5_cdec_6Scorer_5__call__, /*tp_call*/ - __pyx_pw_5_cdec_6Scorer_7__str__, /*tp_str*/ + 0, /*tp_call*/ + 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Scorer, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct____iter__, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Scorer, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct____iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -10554,7 +12047,7 @@ static PyTypeObject __pyx_type_5_cdec_Scorer = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Scorer, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct____iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -10568,76 +12061,44 @@ static PyTypeObject __pyx_type_5_cdec_Scorer = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Decoder(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec_Decoder *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec_Decoder *)o); - p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); - if (__pyx_pw_5_cdec_7Decoder_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o); + p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec_Decoder(PyObject *o) { - struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_7Decoder_3__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - Py_XDECREF(((PyObject *)p->weights)); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec_Decoder(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; - if (p->weights) { - e = (*v)(((PyObject*)p->weights), a); if (e) return e; + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec_Decoder(PyObject *o) { - struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; PyObject* tmp; - tmp = ((PyObject*)p->weights); - p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyObject *__pyx_getprop_5_cdec_7Decoder_weights(PyObject *o, void *x) { - return __pyx_pw_5_cdec_7Decoder_7weights_1__get__(o); -} - -static int __pyx_setprop_5_cdec_7Decoder_weights(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_5_cdec_7Decoder_7weights_3__set__(o, v); - } - else { - return __pyx_pw_5_cdec_7Decoder_7weights_5__del__(o); - } -} - -static PyMethodDef __pyx_methods_5_cdec_Decoder[] = { - {__Pyx_NAMESTR("read_weights"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_5read_weights, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("translate"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_7translate, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_1___iter__[] = { {0, 0, 0, 0} }; -static struct PyGetSetDef __pyx_getsets_5_cdec_Decoder[] = { - {(char *)"weights", __pyx_getprop_5_cdec_7Decoder_weights, __pyx_setprop_5_cdec_7Decoder_weights, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_Decoder = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -10695,7 +12156,7 @@ static PyNumberMethods __pyx_tp_as_number_Decoder = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Decoder = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -10708,13 +12169,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Decoder = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Decoder = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Decoder = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -10735,12 +12196,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Decoder = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Decoder = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Decoder"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Decoder), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_1___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Decoder, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -10750,26 +12211,26 @@ static PyTypeObject __pyx_type_5_cdec_Decoder = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Decoder, /*tp_as_number*/ - &__pyx_tp_as_sequence_Decoder, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Decoder, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_1___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_1___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_1___iter__, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Decoder, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct_1___iter__, /*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_Decoder, /*tp_traverse*/ - __pyx_tp_clear_5_cdec_Decoder, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Decoder, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_1___iter__, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_5_cdec_Decoder, /*tp_getset*/ + 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -10777,7 +12238,7 @@ static PyTypeObject __pyx_type_5_cdec_Decoder = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Decoder, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -10791,44 +12252,60 @@ static PyTypeObject __pyx_type_5_cdec_Decoder = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct____iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)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____iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(((PyObject *)p->__pyx_v_sentence)); + Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } + if (p->__pyx_v_sentence) { + e = (*v)(p->__pyx_v_sentence, a); if (e) return e; + } + if (p->__pyx_v_size) { + e = (*v)(p->__pyx_v_size, a); if (e) return e; + } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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____iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_2_kbest[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -10886,7 +12363,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct____iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -10899,13 +12376,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct____iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct____iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_2_kbest = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -10926,12 +12403,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct____iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct____iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_2_kbest"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -10941,24 +12418,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct____iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct____iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct____iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_2_kbest, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_2_kbest, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_2_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____iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_2_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____iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct____iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_2_kbest, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -10968,7 +12445,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct____iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -10982,44 +12459,60 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_tree(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)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___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_kbest_tree(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(p->__pyx_v_size); + Py_XDECREF(((PyObject *)p->__pyx_v_tree)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_kbest_tree(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; 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___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_3_kbest_tree(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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___iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_3_kbest_tree[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_kbest_tree = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -11077,7 +12570,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1___iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -11090,13 +12583,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1___iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1___iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_3_kbest_tree = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_kbest_tree = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -11117,12 +12610,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_1___iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_3_kbest_tree"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -11132,24 +12625,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_1___iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_1___iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_1___iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_3_kbest_tree, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_3_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_1___iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_3_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_1___iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_1___iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -11159,7 +12652,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -11173,60 +12666,60 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_4_kbest_features(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o); + p->__pyx_v_fmap = 0; 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(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_fmap)); Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(((PyObject *)p->__pyx_v_sentence)); Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; + if (p->__pyx_v_fmap) { + e = (*v)(((PyObject*)p->__pyx_v_fmap), 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(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_fmap); + p->__pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_self); p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_4_kbest_features[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4_kbest_features = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -11284,7 +12777,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4_kbest_features = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -11297,13 +12790,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_2_kbest = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_4_kbest_features = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4_kbest_features = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -11324,12 +12817,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_kbest_features = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_2_kbest"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_4_kbest_features"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -11339,24 +12832,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_2_kbest, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_2_kbest, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_2_kbest, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_4_kbest_features, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_4_kbest_features, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_4_kbest_features, /*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, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_4_kbest_features, /*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, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_2_kbest, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -11366,7 +12859,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -11380,60 +12873,52 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_tree(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_5_sample(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o); p->__pyx_v_self = 0; - p->__pyx_v_size = 0; - p->__pyx_v_tree = 0; + p->__pyx_v_sentence = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_kbest_tree(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5_sample(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(p->__pyx_v_size); - Py_XDECREF(((PyObject *)p->__pyx_v_tree)); + Py_XDECREF(((PyObject *)p->__pyx_v_sentence)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_kbest_tree(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_5_sample(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; 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; + 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_kbest_tree(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_5_sample(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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); + 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_kbest_tree[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_5_sample[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_kbest_tree = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_5_sample = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -11491,7 +12976,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_kbest_tree = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_5_sample = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -11504,13 +12989,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree = 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_3_kbest_tree = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_5_sample = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_kbest_tree = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_5_sample = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -11531,12 +13016,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_kbest_tree = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5_sample = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_3_kbest_tree"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_5_sample"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5_sample, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -11546,24 +13031,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_3_kbest_tree, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_3_kbest_tree, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_5_sample, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_5_sample, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_5_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_kbest_tree, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_5_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_kbest_tree, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_5_sample, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_5_sample, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_5_sample, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -11573,7 +13058,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_5_sample, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -11587,60 +13072,44 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_4_kbest_features(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_6___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o); - p->__pyx_v_fmap = 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o); p->__pyx_v_self = 0; - p->__pyx_v_size = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; - Py_XDECREF(((PyObject *)p->__pyx_v_fmap)); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_6___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_6___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; - if (p->__pyx_v_fmap) { - e = (*v)(((PyObject*)p->__pyx_v_fmap), a); if (e) return e; - } + struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o; 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; - } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_6___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_fmap); - p->__pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Lattice *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_4_kbest_features[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_6___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4_kbest_features = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_6___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -11698,7 +13167,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4_kbest_features = #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4_kbest_features = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_6___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -11711,13 +13180,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4_kbest_feature 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_4_kbest_features = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_6___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4_kbest_features = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_6___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -11738,12 +13207,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4_kbest_features = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_kbest_features = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_6___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_4_kbest_features"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_6___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_6___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -11753,24 +13222,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_kbest_features = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_4_kbest_features, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_4_kbest_features, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_4_kbest_features, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_6___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_6___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_6___iter__, /*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_4_kbest_features, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_6___iter__, /*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_4_kbest_features, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_6___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_6___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_6___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -11780,7 +13249,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_kbest_features = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_6___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -11794,52 +13263,44 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_kbest_features = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_5_sample(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_7_todot(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *)o); p->__pyx_v_self = 0; - p->__pyx_v_sentence = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5_sample(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_7_todot(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(((PyObject *)p->__pyx_v_sentence)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_5_sample(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_7_todot(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } - if (p->__pyx_v_sentence) { - e = (*v)(p->__pyx_v_sentence, a); if (e) return e; - } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_5_sample(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_7_todot(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Lattice *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_5_sample[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_7_todot[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_5_sample = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_7_todot = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -11897,7 +13358,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_5_sample = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_5_sample = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_7_todot = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -11910,13 +13371,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_5_sample = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_5_sample = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_7_todot = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_5_sample = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_7_todot = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -11937,12 +13398,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_5_sample = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5_sample = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7_todot = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_5_sample"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_7_todot"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5_sample, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_7_todot, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -11952,24 +13413,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5_sample = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_5_sample, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_5_sample, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_5_sample, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_7_todot, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_7_todot, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_7_todot, /*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_5_sample, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_7_todot, /*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_5_sample, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_5_sample, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_7_todot, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_7_todot, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_5_sample, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_7_todot, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -11979,7 +13440,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5_sample = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_5_sample, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_7_todot, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -11993,44 +13454,92 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5_sample = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_6___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_8_lines(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o); - p->__pyx_v_self = 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *)o); + p->__pyx_outer_scope = 0; + p->__pyx_v_delta = 0; + p->__pyx_v_i = 0; + p->__pyx_v_label = 0; + p->__pyx_v_weight = 0; + p->__pyx_t_1 = 0; + p->__pyx_t_3 = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_6___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o; - Py_XDECREF(((PyObject *)p->__pyx_v_self)); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8_lines(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *)o; + Py_XDECREF(((PyObject *)p->__pyx_outer_scope)); + Py_XDECREF(p->__pyx_v_delta); + Py_XDECREF(p->__pyx_v_i); + Py_XDECREF(p->__pyx_v_label); + Py_XDECREF(p->__pyx_v_weight); + Py_XDECREF(p->__pyx_t_1); + Py_XDECREF(p->__pyx_t_3); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_6___iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_8_lines(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o; - if (p->__pyx_v_self) { - e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *)o; + if (p->__pyx_outer_scope) { + e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e; + } + if (p->__pyx_v_delta) { + e = (*v)(p->__pyx_v_delta, a); if (e) return e; + } + if (p->__pyx_v_i) { + e = (*v)(p->__pyx_v_i, a); if (e) return e; + } + if (p->__pyx_v_label) { + e = (*v)(p->__pyx_v_label, a); if (e) return e; + } + if (p->__pyx_v_weight) { + e = (*v)(p->__pyx_v_weight, a); if (e) return e; + } + if (p->__pyx_t_1) { + e = (*v)(p->__pyx_t_1, a); if (e) return e; + } + if (p->__pyx_t_3) { + e = (*v)(p->__pyx_t_3, a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_6___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_8_lines(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Lattice *)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_outer_scope); + p->__pyx_outer_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_delta); + p->__pyx_v_delta = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_i); + p->__pyx_v_i = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_label); + p->__pyx_v_label = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_weight); + p->__pyx_v_weight = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_1); + p->__pyx_t_1 = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_3); + p->__pyx_t_3 = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_6___iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_8_lines[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_6___iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_8_lines = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -12088,7 +13597,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_6___iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_6___iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_8_lines = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -12101,13 +13610,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_6___iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_6___iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_8_lines = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_6___iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_8_lines = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -12128,12 +13637,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_6___iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_6___iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8_lines = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_6___iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_8_lines"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_6___iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8_lines, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -12143,24 +13652,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_6___iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_6___iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_6___iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_6___iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_8_lines, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_8_lines, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_8_lines, /*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_6___iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_8_lines, /*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_6___iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_6___iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_8_lines, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_8_lines, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_6___iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_8_lines, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -12170,7 +13679,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_6___iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_6___iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_8_lines, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -12184,28 +13693,28 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_6___iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_7___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_9___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *)o); p->__pyx_v_i = 0; p->__pyx_v_self = 0; p->__pyx_t_1 = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_7___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_9___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *)o; Py_XDECREF(p->__pyx_v_i); Py_XDECREF(((PyObject *)p->__pyx_v_self)); Py_XDECREF(p->__pyx_t_1); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_7___iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_9___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *)o; if (p->__pyx_v_i) { e = (*v)(p->__pyx_v_i, a); if (e) return e; } @@ -12218,8 +13727,8 @@ static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_7___iter__(PyObject *o, v return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_7___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_9___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_i); p->__pyx_v_i = Py_None; Py_INCREF(Py_None); @@ -12233,11 +13742,11 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_7___iter__(PyObject *o) { return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_7___iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_9___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_7___iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_9___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -12295,7 +13804,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_7___iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_7___iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_9___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -12308,13 +13817,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_7___iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_7___iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_9___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_7___iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_9___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -12335,12 +13844,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_7___iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7___iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_9___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_7___iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_9___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_7___iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_9___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -12350,24 +13859,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7___iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_7___iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_7___iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_7___iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_9___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_9___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_9___iter__, /*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_7___iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_9___iter__, /*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_7___iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_7___iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_9___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_9___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_7___iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_9___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -12377,7 +13886,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7___iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_7___iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_9___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -12391,32 +13900,32 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7___iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_8___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_10___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *)o); p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_10___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_8___iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_10___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_8___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_10___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); p->__pyx_v_self = ((struct __pyx_obj_5_cdec_CandidateSet *)Py_None); Py_INCREF(Py_None); @@ -12424,11 +13933,11 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_8___iter__(PyObject *o) { return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_8___iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_10___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_8___iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_10___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -12486,7 +13995,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_8___iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_8___iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_10___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -12499,13 +14008,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_8___iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_8___iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_10___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_8___iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_10___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -12526,12 +14035,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_8___iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8___iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_10___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_8___iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_10___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8___iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_10___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -12541,24 +14050,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8___iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_8___iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_8___iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_8___iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_10___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_10___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_10___iter__, /*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_8___iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_10___iter__, /*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_8___iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_8___iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_10___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_10___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_8___iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_10___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -12568,7 +14077,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8___iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_8___iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_10___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -12608,8 +14117,19 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0}, {&__pyx_kp_s_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 1, 0}, {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0}, + {&__pyx_kp_s_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 0, 1, 0}, {&__pyx_kp_s_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 1, 0}, - {&__pyx_kp_s_25, __pyx_k_25, sizeof(__pyx_k_25), 0, 0, 1, 0}, + {&__pyx_kp_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 0}, + {&__pyx_kp_s_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 0, 1, 0}, + {&__pyx_kp_s_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 1, 0}, + {&__pyx_kp_s_26, __pyx_k_26, sizeof(__pyx_k_26), 0, 0, 1, 0}, + {&__pyx_kp_s_27, __pyx_k_27, sizeof(__pyx_k_27), 0, 0, 1, 0}, + {&__pyx_kp_s_30, __pyx_k_30, sizeof(__pyx_k_30), 0, 0, 1, 0}, + {&__pyx_kp_s_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 0, 1, 0}, + {&__pyx_kp_s_33, __pyx_k_33, sizeof(__pyx_k_33), 0, 0, 1, 0}, + {&__pyx_kp_s_35, __pyx_k_35, sizeof(__pyx_k_35), 0, 0, 1, 0}, + {&__pyx_kp_s_37, __pyx_k_37, sizeof(__pyx_k_37), 0, 0, 1, 0}, + {&__pyx_kp_s_40, __pyx_k_40, sizeof(__pyx_k_40), 0, 0, 1, 0}, {&__pyx_n_s__BLEU, __pyx_k__BLEU, sizeof(__pyx_k__BLEU), 0, 0, 1, 1}, {&__pyx_n_s__Exception, __pyx_k__Exception, sizeof(__pyx_k__Exception), 0, 0, 1, 1}, {&__pyx_n_s__IBM_BLEU, __pyx_k__IBM_BLEU, sizeof(__pyx_k__IBM_BLEU), 0, 0, 1, 1}, @@ -12627,6 +14147,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__beam_alpha, __pyx_k__beam_alpha, sizeof(__pyx_k__beam_alpha), 0, 0, 1, 1}, {&__pyx_n_s__config, __pyx_k__config, sizeof(__pyx_k__config), 0, 0, 1, 1}, {&__pyx_n_s__decode, __pyx_k__decode, sizeof(__pyx_k__decode), 0, 0, 1, 1}, + {&__pyx_n_s__delta, __pyx_k__delta, sizeof(__pyx_k__delta), 0, 0, 1, 1}, {&__pyx_n_s__density, __pyx_k__density, sizeof(__pyx_k__density), 0, 0, 1, 1}, {&__pyx_n_s__dot, __pyx_k__dot, sizeof(__pyx_k__dot), 0, 0, 1, 1}, {&__pyx_n_s__encode, __pyx_k__encode, sizeof(__pyx_k__encode), 0, 0, 1, 1}, @@ -12636,18 +14157,25 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__evaluator, __pyx_k__evaluator, sizeof(__pyx_k__evaluator), 0, 0, 1, 1}, {&__pyx_n_s__grammar, __pyx_k__grammar, sizeof(__pyx_k__grammar), 0, 0, 1, 1}, {&__pyx_n_s__hypergraph, __pyx_k__hypergraph, sizeof(__pyx_k__hypergraph), 0, 0, 1, 1}, + {&__pyx_n_s__i, __pyx_k__i, sizeof(__pyx_k__i), 0, 0, 1, 1}, {&__pyx_n_s__inp, __pyx_k__inp, sizeof(__pyx_k__inp), 0, 0, 1, 1}, + {&__pyx_n_s__items, __pyx_k__items, sizeof(__pyx_k__items), 0, 0, 1, 1}, + {&__pyx_n_s__join, __pyx_k__join, sizeof(__pyx_k__join), 0, 0, 1, 1}, {&__pyx_n_s__k, __pyx_k__k, sizeof(__pyx_k__k), 0, 0, 1, 1}, + {&__pyx_n_s__label, __pyx_k__label, sizeof(__pyx_k__label), 0, 0, 1, 1}, + {&__pyx_n_s__lines, __pyx_k__lines, sizeof(__pyx_k__lines), 0, 0, 1, 1}, {&__pyx_n_s__name, __pyx_k__name, sizeof(__pyx_k__name), 0, 0, 1, 1}, {&__pyx_n_s__open, __pyx_k__open, sizeof(__pyx_k__open), 0, 0, 1, 1}, {&__pyx_n_s__plf, __pyx_k__plf, sizeof(__pyx_k__plf), 0, 0, 1, 1}, {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1}, {&__pyx_n_s__refs, __pyx_k__refs, sizeof(__pyx_k__refs), 0, 0, 1, 1}, + {&__pyx_n_s__replace, __pyx_k__replace, sizeof(__pyx_k__replace), 0, 0, 1, 1}, {&__pyx_n_s__self, __pyx_k__self, sizeof(__pyx_k__self), 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}, {&__pyx_n_s__strip, __pyx_k__strip, sizeof(__pyx_k__strip), 0, 0, 1, 1}, {&__pyx_n_s__utf8, __pyx_k__utf8, sizeof(__pyx_k__utf8), 0, 0, 1, 1}, + {&__pyx_n_s__weight, __pyx_k__weight, sizeof(__pyx_k__weight), 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { @@ -12659,7 +14187,7 @@ static int __Pyx_InitCachedBuiltins(void) { __pyx_builtin_eval = __Pyx_GetName(__pyx_b, __pyx_n_s__eval); if (!__pyx_builtin_eval) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __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 = 31; __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 = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; return -1; @@ -12837,6 +14365,59 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_18)); + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":65 + * for i in range(len(self)): + * for label, weight, delta in self[i]: + * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) # <<<<<<<<<<<<<< + * yield '%d [shape=doublecircle]' % len(self) + * yield '}' + */ + __pyx_k_tuple_25 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_25); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_23)); + PyTuple_SET_ITEM(__pyx_k_tuple_25, 0, ((PyObject *)__pyx_kp_s_23)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_23)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_24)); + PyTuple_SET_ITEM(__pyx_k_tuple_25, 1, ((PyObject *)__pyx_kp_s_24)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_24)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_25)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":59 + * + * def todot(self): + * def lines(): # <<<<<<<<<<<<<< + * yield 'digraph lattice {' + * yield 'rankdir = LR;' + */ + __pyx_k_tuple_28 = PyTuple_New(4); if (unlikely(!__pyx_k_tuple_28)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_28); + __Pyx_INCREF(((PyObject *)__pyx_n_s__i)); + PyTuple_SET_ITEM(__pyx_k_tuple_28, 0, ((PyObject *)__pyx_n_s__i)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__label)); + PyTuple_SET_ITEM(__pyx_k_tuple_28, 1, ((PyObject *)__pyx_n_s__label)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__label)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__weight)); + PyTuple_SET_ITEM(__pyx_k_tuple_28, 2, ((PyObject *)__pyx_n_s__weight)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__weight)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__delta)); + PyTuple_SET_ITEM(__pyx_k_tuple_28, 3, ((PyObject *)__pyx_n_s__delta)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__delta)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_28)); + __pyx_k_codeobj_29 = (PyObject*)__Pyx_PyCode_New(0, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_30, __pyx_n_s__lines, 59, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_29)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":68 + * yield '%d [shape=doublecircle]' % len(self) + * yield '}' + * return '\n'.join(lines()).encode('utf8') # <<<<<<<<<<<<<< + */ + __pyx_k_tuple_32 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_32)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_32); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_32, 0, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_32)); + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":6 * cdef bytes ret * if isinstance(sentence, unicode): @@ -12844,85 +14425,85 @@ static int __Pyx_InitCachedConstants(void) { * elif isinstance(sentence, str): * ret = sentence */ - __pyx_k_tuple_20 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_20); + __pyx_k_tuple_34 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_34)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_34); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_20, 0, ((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_34, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_34)); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":78 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":89 * def __getitem__(self,int k): * if not 0 <= k < self.cs.size(): * raise IndexError('candidate set index out of range') # <<<<<<<<<<<<<< * cdef Candidate candidate = Candidate() * candidate.candidate = &self.cs[0][k] */ - __pyx_k_tuple_22 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_22)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_22); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_21)); - PyTuple_SET_ITEM(__pyx_k_tuple_22, 0, ((PyObject *)__pyx_kp_s_21)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_21)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22)); + __pyx_k_tuple_36 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_36)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_36); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_35)); + PyTuple_SET_ITEM(__pyx_k_tuple_36, 0, ((PyObject *)__pyx_kp_s_35)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_35)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_36)); - /* "_cdec.pyx":31 + /* "_cdec.pyx":47 * * def read_weights(self, cfg): * with open(cfg) as fp: # <<<<<<<<<<<<<< * for line in fp: * fname, value = line.split() */ - __pyx_k_tuple_23 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_23); + __pyx_k_tuple_38 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_38)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_38); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_23, 0, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_38, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_23, 1, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_38, 1, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_23, 2, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_38, 2, Py_None); __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_23)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_38)); - /* "_cdec.pyx":38 + /* "_cdec.pyx":54 * def translate(self, sentence, grammar=None): * if isinstance(sentence, unicode): * inp = sentence.strip().encode('utf8') # <<<<<<<<<<<<<< * elif isinstance(sentence, str): * inp = sentence.strip() */ - __pyx_k_tuple_24 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_24); + __pyx_k_tuple_39 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_39)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_39); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_24, 0, ((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_39, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_24)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_39)); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":142 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":153 * return self.name.c_str() * * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< * TER = Scorer('TER') */ - __pyx_k_tuple_26 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_26)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_26); + __pyx_k_tuple_41 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_41)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_41); __Pyx_INCREF(((PyObject *)__pyx_n_s__IBM_BLEU)); - PyTuple_SET_ITEM(__pyx_k_tuple_26, 0, ((PyObject *)__pyx_n_s__IBM_BLEU)); + PyTuple_SET_ITEM(__pyx_k_tuple_41, 0, ((PyObject *)__pyx_n_s__IBM_BLEU)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IBM_BLEU)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_26)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_41)); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":143 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":154 * * BLEU = Scorer('IBM_BLEU') * TER = Scorer('TER') # <<<<<<<<<<<<<< */ - __pyx_k_tuple_27 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_27)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_27); + __pyx_k_tuple_42 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_42)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_42); __Pyx_INCREF(((PyObject *)__pyx_n_s__TER)); - PyTuple_SET_ITEM(__pyx_k_tuple_27, 0, ((PyObject *)__pyx_n_s__TER)); + PyTuple_SET_ITEM(__pyx_k_tuple_42, 0, ((PyObject *)__pyx_n_s__TER)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__TER)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_27)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_42)); __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -13018,20 +14599,20 @@ PyMODINIT_FUNC PyInit__cdec(void) if (PyType_Ready(&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Lattice", (PyObject *)&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Lattice = &__pyx_type_5_cdec_Lattice; - if (PyType_Ready(&__pyx_type_5_cdec_Candidate) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Candidate", (PyObject *)&__pyx_type_5_cdec_Candidate) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_Candidate) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Candidate", (PyObject *)&__pyx_type_5_cdec_Candidate) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Candidate = &__pyx_type_5_cdec_Candidate; - if (PyType_Ready(&__pyx_type_5_cdec_SufficientStats) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "SufficientStats", (PyObject *)&__pyx_type_5_cdec_SufficientStats) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_SufficientStats) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "SufficientStats", (PyObject *)&__pyx_type_5_cdec_SufficientStats) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_SufficientStats = &__pyx_type_5_cdec_SufficientStats; - if (PyType_Ready(&__pyx_type_5_cdec_CandidateSet) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "CandidateSet", (PyObject *)&__pyx_type_5_cdec_CandidateSet) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_CandidateSet) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "CandidateSet", (PyObject *)&__pyx_type_5_cdec_CandidateSet) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_CandidateSet = &__pyx_type_5_cdec_CandidateSet; - if (PyType_Ready(&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "SegmentEvaluator", (PyObject *)&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "SegmentEvaluator", (PyObject *)&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_SegmentEvaluator = &__pyx_type_5_cdec_SegmentEvaluator; - if (PyType_Ready(&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Scorer", (PyObject *)&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Scorer", (PyObject *)&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Scorer = &__pyx_type_5_cdec_Scorer; if (PyType_Ready(&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __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 = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -13050,34 +14631,38 @@ PyMODINIT_FUNC PyInit__cdec(void) __pyx_ptype_5_cdec___pyx_scope_struct_5_sample = &__pyx_type_5_cdec___pyx_scope_struct_5_sample; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_6___iter__) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_6___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_6___iter__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_7___iter__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_7___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_7___iter__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_8___iter__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_8___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_8___iter__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_7_todot) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_7_todot = &__pyx_type_5_cdec___pyx_scope_struct_7_todot; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_8_lines) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_8_lines = &__pyx_type_5_cdec___pyx_scope_struct_8_lines; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_9___iter__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_9___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_9___iter__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_10___iter__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_10___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_10___iter__; /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ /*--- Execution code ---*/ - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":142 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":153 * return self.name.c_str() * * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< * TER = Scorer('TER') */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_26), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_41), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":143 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":154 * * BLEU = Scorer('IBM_BLEU') * TER = Scorer('TER') # <<<<<<<<<<<<<< */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_27), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_42), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "_cdec.pyx":11 @@ -13500,6 +15085,10 @@ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { +static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) { + PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname); +} + static double __Pyx__PyObject_AsDouble(PyObject* obj) { PyObject* float_value; if (Py_TYPE(obj)->tp_as_number && Py_TYPE(obj)->tp_as_number->nb_float) { @@ -13677,6 +15266,365 @@ bad: return NULL; } +static PyObject * +__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *closure) +{ + if (op->func_doc == NULL && op->func.m_ml->ml_doc) { +#if PY_MAJOR_VERSION >= 3 + op->func_doc = PyUnicode_FromString(op->func.m_ml->ml_doc); +#else + op->func_doc = PyString_FromString(op->func.m_ml->ml_doc); +#endif + } + if (op->func_doc == 0) { + Py_INCREF(Py_None); + return Py_None; + } + Py_INCREF(op->func_doc); + return op->func_doc; +} +static int +__Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value) +{ + PyObject *tmp = op->func_doc; + if (value == NULL) + op->func_doc = Py_None; /* Mark as deleted */ + else + op->func_doc = value; + Py_INCREF(op->func_doc); + Py_XDECREF(tmp); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op) +{ + if (op->func_name == NULL) { +#if PY_MAJOR_VERSION >= 3 + op->func_name = PyUnicode_InternFromString(op->func.m_ml->ml_name); +#else + op->func_name = PyString_InternFromString(op->func.m_ml->ml_name); +#endif + } + Py_INCREF(op->func_name); + return op->func_name; +} +static int +__Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value) +{ + PyObject *tmp; +#if PY_MAJOR_VERSION >= 3 + if (value == NULL || !PyUnicode_Check(value)) { +#else + if (value == NULL || !PyString_Check(value)) { +#endif + PyErr_SetString(PyExc_TypeError, + "__name__ must be set to a string object"); + return -1; + } + tmp = op->func_name; + Py_INCREF(value); + op->func_name = value; + Py_XDECREF(tmp); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_self(__pyx_CyFunctionObject *m, CYTHON_UNUSED void *closure) +{ + PyObject *self; + self = m->func_closure; + if (self == NULL) + self = Py_None; + Py_INCREF(self); + return self; +} +static PyObject * +__Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op) +{ + if (op->func_dict == NULL) { + op->func_dict = PyDict_New(); + if (op->func_dict == NULL) + return NULL; + } + Py_INCREF(op->func_dict); + return op->func_dict; +} +static int +__Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value) +{ + PyObject *tmp; + if (value == NULL) { + PyErr_SetString(PyExc_TypeError, + "function's dictionary may not be deleted"); + return -1; + } + if (!PyDict_Check(value)) { + PyErr_SetString(PyExc_TypeError, + "setting function's dictionary to a non-dict"); + return -1; + } + tmp = op->func_dict; + Py_INCREF(value); + op->func_dict = value; + Py_XDECREF(tmp); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_globals(CYTHON_UNUSED __pyx_CyFunctionObject *op) +{ + PyObject* dict = PyModule_GetDict(__pyx_m); + Py_XINCREF(dict); + return dict; +} +static PyObject * +__Pyx_CyFunction_get_closure(CYTHON_UNUSED __pyx_CyFunctionObject *op) +{ + Py_INCREF(Py_None); + return Py_None; +} +static PyObject * +__Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op) +{ + PyObject* result = (op->func_code) ? op->func_code : Py_None; + Py_INCREF(result); + return result; +} +static PyObject * +__Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op) +{ + if (op->defaults_tuple) { + Py_INCREF(op->defaults_tuple); + return op->defaults_tuple; + } + if (op->defaults_getter) { + PyObject *res = op->defaults_getter((PyObject *) op); + if (res) { + Py_INCREF(res); + op->defaults_tuple = res; + } + return res; + } + Py_INCREF(Py_None); + return Py_None; +} +static PyGetSetDef __pyx_CyFunction_getsets[] = { + {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, + {(char *) "__doc__", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, + {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, + {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, + {(char *) "__self__", (getter)__Pyx_CyFunction_get_self, 0, 0, 0}, + {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, + {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, + {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, + {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, + {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, + {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, + {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, + {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, + {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, 0, 0, 0}, + {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, 0, 0, 0}, + {0, 0, 0, 0, 0} +}; +#ifndef PY_WRITE_RESTRICTED /* < Py2.5 */ +#define PY_WRITE_RESTRICTED WRITE_RESTRICTED +#endif +static PyMemberDef __pyx_CyFunction_members[] = { + {(char *) "__module__", T_OBJECT, offsetof(__pyx_CyFunctionObject, func.m_module), PY_WRITE_RESTRICTED, 0}, + {0, 0, 0, 0, 0} +}; +static PyObject * +__Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, CYTHON_UNUSED PyObject *args) +{ +#if PY_MAJOR_VERSION >= 3 + return PyUnicode_FromString(m->func.m_ml->ml_name); +#else + return PyString_FromString(m->func.m_ml->ml_name); +#endif +} +static PyMethodDef __pyx_CyFunction_methods[] = { + {__Pyx_NAMESTR("__reduce__"), (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0}, + {0, 0, 0, 0} +}; +static PyObject *__Pyx_CyFunction_New(PyTypeObject *type, PyMethodDef *ml, int flags, + PyObject *closure, PyObject *module, PyObject* code) { + __pyx_CyFunctionObject *op = PyObject_GC_New(__pyx_CyFunctionObject, type); + if (op == NULL) + return NULL; + op->flags = flags; + op->func_weakreflist = NULL; + op->func.m_ml = ml; + op->func.m_self = (PyObject *) op; + Py_XINCREF(closure); + op->func_closure = closure; + Py_XINCREF(module); + op->func.m_module = module; + op->func_dict = NULL; + op->func_name = NULL; + op->func_doc = NULL; + op->func_classobj = NULL; + Py_XINCREF(code); + op->func_code = code; + op->defaults_pyobjects = 0; + op->defaults = NULL; + op->defaults_tuple = NULL; + op->defaults_getter = NULL; + PyObject_GC_Track(op); + return (PyObject *) op; +} +static int +__Pyx_CyFunction_clear(__pyx_CyFunctionObject *m) +{ + Py_CLEAR(m->func_closure); + Py_CLEAR(m->func.m_module); + Py_CLEAR(m->func_dict); + Py_CLEAR(m->func_name); + Py_CLEAR(m->func_doc); + Py_CLEAR(m->func_code); + Py_CLEAR(m->func_classobj); + Py_CLEAR(m->defaults_tuple); + if (m->defaults) { + PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m); + int i; + for (i = 0; i < m->defaults_pyobjects; i++) + Py_XDECREF(pydefaults[i]); + PyMem_Free(m->defaults); + m->defaults = NULL; + } + return 0; +} +static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m) +{ + PyObject_GC_UnTrack(m); + if (m->func_weakreflist != NULL) + PyObject_ClearWeakRefs((PyObject *) m); + __Pyx_CyFunction_clear(m); + PyObject_GC_Del(m); +} +static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg) +{ + Py_VISIT(m->func_closure); + Py_VISIT(m->func.m_module); + Py_VISIT(m->func_dict); + Py_VISIT(m->func_name); + Py_VISIT(m->func_doc); + Py_VISIT(m->func_code); + Py_VISIT(m->func_classobj); + Py_VISIT(m->defaults_tuple); + if (m->defaults) { + PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m); + int i; + for (i = 0; i < m->defaults_pyobjects; i++) + Py_VISIT(pydefaults[i]); + } + return 0; +} +static PyObject *__Pyx_CyFunction_descr_get(PyObject *func, PyObject *obj, PyObject *type) +{ + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + if (m->flags & __Pyx_CYFUNCTION_STATICMETHOD) { + Py_INCREF(func); + return func; + } + if (m->flags & __Pyx_CYFUNCTION_CLASSMETHOD) { + if (type == NULL) + type = (PyObject *)(Py_TYPE(obj)); + return PyMethod_New(func, + type, (PyObject *)(Py_TYPE(type))); + } + if (obj == Py_None) + obj = NULL; + return PyMethod_New(func, obj, type); +} +static PyObject* +__Pyx_CyFunction_repr(__pyx_CyFunctionObject *op) +{ + PyObject *func_name = __Pyx_CyFunction_get_name(op); +#if PY_MAJOR_VERSION >= 3 + return PyUnicode_FromFormat("", + func_name, (void *)op); +#else + return PyString_FromFormat("", + PyString_AsString(func_name), (void *)op); +#endif +} +static PyTypeObject __pyx_CyFunctionType_type = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("cython_function_or_method"), /*tp_name*/ + sizeof(__pyx_CyFunctionObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + (destructor) __Pyx_CyFunction_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ +#if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ +#else + 0, /*reserved*/ +#endif + (reprfunc) __Pyx_CyFunction_repr, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + __Pyx_PyCFunction_Call, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags*/ + 0, /*tp_doc*/ + (traverseproc) __Pyx_CyFunction_traverse, /*tp_traverse*/ + (inquiry) __Pyx_CyFunction_clear, /*tp_clear*/ + 0, /*tp_richcompare*/ + offsetof(__pyx_CyFunctionObject, func_weakreflist), /* tp_weaklistoffse */ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_CyFunction_methods, /*tp_methods*/ + __pyx_CyFunction_members, /*tp_members*/ + __pyx_CyFunction_getsets, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + __Pyx_CyFunction_descr_get, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + offsetof(__pyx_CyFunctionObject, func_dict),/*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + 0, /*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 int __Pyx_CyFunction_init(void) +{ + if (PyType_Ready(&__pyx_CyFunctionType_type) < 0) + return -1; + __pyx_CyFunctionType = &__pyx_CyFunctionType_type; + return 0; +} +void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) +{ + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults = PyMem_Malloc(size); + if (!m->defaults) + return PyErr_NoMemory(); + memset(m->defaults, 0, sizeof(size)); + m->defaults_pyobjects = pyobjects; + return m->defaults; +} +static void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) +{ + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults_tuple = tuple; + Py_INCREF(tuple); +} + static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { const unsigned char neg_one = (unsigned char)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; diff --git a/python/src/_cdec.pyx b/python/src/_cdec.pyx index 6fafbbc0..cccfec0b 100644 --- a/python/src/_cdec.pyx +++ b/python/src/_cdec.pyx @@ -14,7 +14,7 @@ class ParseFailed(Exception): pass cdef class Decoder: cdef decoder.Decoder* dec - cdef public DenseVector weights + cdef DenseVector weights def __cinit__(self, char* config): decoder.register_feature_functions() @@ -27,6 +27,22 @@ cdef class Decoder: def __dealloc__(self): del self.dec + property weights: + def __get__(self): + return self.weights + + def __set__(self, weights): + if isinstance(weights, DenseVector): + self.weights.vector[0] = ( weights).vector[0] + elif isinstance(weights, SparseVector): + self.weights.vector.clear() + (( weights).vector[0]).init_vector(self.weights.vector) + elif isinstance(weights, dict): + for fname, fval in weights.items(): + self.weights[fname] = fval + else: + raise TypeError('cannot initialize weights with %s' % type(weights)) + def read_weights(self, cfg): with open(cfg) as fp: for line in fp: diff --git a/python/src/lattice.pxi b/python/src/lattice.pxi index 493c6dcd..f8341e29 100644 --- a/python/src/lattice.pxi +++ b/python/src/lattice.pxi @@ -54,3 +54,15 @@ cdef class Lattice: def __dealloc__(self): del self.lattice + + def todot(self): + def lines(): + yield 'digraph lattice {' + yield 'rankdir = LR;' + yield 'node [shape=circle];' + for i in range(len(self)): + for label, weight, delta in self[i]: + yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) + yield '%d [shape=doublecircle]' % len(self) + yield '}' + return '\n'.join(lines()).encode('utf8') diff --git a/python/src/mteval.pxi b/python/src/mteval.pxi index 67a29f6f..d90eb9a6 100644 --- a/python/src/mteval.pxi +++ b/python/src/mteval.pxi @@ -10,6 +10,15 @@ cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): raise TypeError(error_msg % type(sentence)) return ret +cdef SufficientStats as_stats(x, y): + if isinstance(x, SufficientStats): + return x + elif x == 0 and isinstance(y, SufficientStats): + stats = SufficientStats() + stats.stats = new mteval.SufficientStats() + stats.metric = ( y).metric + return stats + cdef class Candidate: cdef mteval.Candidate* candidate cdef public float score @@ -50,10 +59,12 @@ cdef class SufficientStats: self.stats[0] += other.stats[0] return self - def __add__(SufficientStats x, SufficientStats y): + def __add__(x, y): + cdef SufficientStats sx = as_stats(x, y) + cdef SufficientStats sy = as_stats(y, x) cdef SufficientStats result = SufficientStats() - result.stats = new mteval.SufficientStats(mteval.add(x.stats[0], y.stats[0])) - result.metric = x.metric + result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) + result.metric = sx.metric return result cdef class CandidateSet: diff --git a/python/src/vectors.pxi b/python/src/vectors.pxi index fc0c365f..ce95968c 100644 --- a/python/src/vectors.pxi +++ b/python/src/vectors.pxi @@ -80,6 +80,12 @@ cdef class SparseVector: def __contains__(self, char* fname): return self.vector.nonzero(FDConvert(fname)) + + def __neg__(self): + cdef SparseVector result = SparseVector() + result.vector = new FastSparseVector[weight_t](self.vector[0]) + result.vector[0] *= -1.0 + return result def __iadd__(SparseVector self, SparseVector other): self.vector[0] += other.vector[0] -- cgit v1.2.3 From 42532406b1246e6f17766b804b8bd5cce828f0fa Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Wed, 11 Jul 2012 16:08:43 +0900 Subject: [python] Direct hypergraph access - small API changes (*_trees methods) - decoder config can now passed as arguments --- python/src/_cdec.cpp | 17915 +++++++++++++++++++++++++++++++------------- python/src/_cdec.pyx | 49 +- python/src/decoder.pxd | 4 +- python/src/hypergraph.pxd | 52 +- python/src/hypergraph.pxi | 161 +- python/src/lattice.pxi | 5 +- python/src/mteval.pxi | 10 - python/src/trule.pxi | 55 + python/src/utils.pxd | 12 +- python/test.py | 20 +- 10 files changed, 12924 insertions(+), 5359 deletions(-) create mode 100644 python/src/trule.pxi (limited to 'python/src') diff --git a/python/src/_cdec.cpp b/python/src/_cdec.cpp index 3a127ba9..e86dcf7b 100644 --- a/python/src/_cdec.cpp +++ b/python/src/_cdec.cpp @@ -1,4 +1,4 @@ -/* Generated by Cython 0.16 on Thu Jul 5 16:20:15 2012 */ +/* Generated by Cython 0.16 on Wed Jul 11 16:05:22 2012 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -285,7 +285,9 @@ #include "utils/filelib.h" #include "utils/sampler.h" #include +#include #include "decoder/lattice.h" +#include "decoder/trule.h" #include "decoder/hg.h" #include "decoder/viterbi.h" #include "decoder/hg_io.h" @@ -384,35 +386,51 @@ static const char *__pyx_f[] = { "vectors.pxi", "hypergraph.pxi", "lattice.pxi", + "trule.pxi", "mteval.pxi", }; /*--- Type declarations ---*/ struct __pyx_obj_5_cdec_Scorer; +struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config; +struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr; +struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr; +struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__; +struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__; +struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__; +struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__; struct __pyx_obj_5_cdec_CandidateSet; -struct __pyx_obj_5_cdec_SufficientStats; -struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__; +struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__; +struct __pyx_obj_5_cdec_TRule; +struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees; +struct __pyx_obj_5_cdec_SegmentEvaluator; struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features; -struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree; +struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample; +struct __pyx_obj_5_cdec_Candidate; +struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__; +struct __pyx_obj_5_cdec_HypergraphEdge; +struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__; +struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__; struct __pyx_obj_5_cdec_Decoder; -struct __pyx_obj_5_cdec_SegmentEvaluator; +struct __pyx_obj_5_cdec_HypergraphNode; struct __pyx_obj_5_cdec_SparseVector; -struct __pyx_obj_5_cdec_Hypergraph; -struct __pyx_obj_5_cdec_Lattice; +struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr; +struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__; struct __pyx_obj_5_cdec___pyx_scope_struct____iter__; struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest; -struct __pyx_obj_5_cdec_Candidate; -struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines; -struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample; struct __pyx_obj_5_cdec_DenseVector; -struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__; -struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__; -struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__; -struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot; +struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines; +struct __pyx_obj_5_cdec_SufficientStats; +struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot; +struct __pyx_obj_5_cdec_Hypergraph; +struct __pyx_obj_5_cdec_Lattice; +struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase; +struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__; +struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__; struct __pyx_opt_args_5_cdec_as_str; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":3 - * cimport mteval +/* "_cdec.pyx":6 + * cimport decoder * * cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): # <<<<<<<<<<<<<< * cdef bytes ret @@ -423,7 +441,7 @@ struct __pyx_opt_args_5_cdec_as_str { PyObject *error_msg; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":122 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":112 * return CandidateSet(self) * * cdef class Scorer: # <<<<<<<<<<<<<< @@ -436,197 +454,243 @@ struct __pyx_obj_5_cdec_Scorer { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":70 - * return result +/* "_cdec.pyx":27 + * class ParseFailed(Exception): pass * - * cdef class CandidateSet: # <<<<<<<<<<<<<< - * cdef shared_ptr[mteval.SegmentEvaluator]* scorer - * cdef mteval.EvaluationMetric* metric + * def _make_config(config): # <<<<<<<<<<<<<< + * for key, value in config.items(): + * if isinstance(value, dict): */ -struct __pyx_obj_5_cdec_CandidateSet { +struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config { PyObject_HEAD - boost::shared_ptr *scorer; - EvaluationMetric *metric; - training::CandidateSet *cs; + PyObject *__pyx_v_config; + PyObject *__pyx_v_info; + PyObject *__pyx_v_key; + PyObject *__pyx_v_name; + PyObject *__pyx_v_value; + PyObject *__pyx_t_0; + PyObject *__pyx_t_1; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":36 - * return fmap +/* "_cdec.pyx":53 + * 'csplit', 'tagger', 'lexalign'): + * raise InvalidConfig('formalism "%s" unknown' % formalism) + * config_str = '\n'.join('%s = %s' % kv for kv in _make_config(config)) # <<<<<<<<<<<<<< + * cdef istringstream* config_stream = new istringstream(config_str) + * self.dec = new decoder.Decoder(config_stream) + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr { + PyObject_HEAD + struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *__pyx_outer_scope; + PyObject *__pyx_v_kv; + PyObject *__pyx_t_0; + Py_ssize_t __pyx_t_1; + PyObject *(*__pyx_t_2)(PyObject *); +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":2 + * def _phrase(phrase): + * return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) # <<<<<<<<<<<<<< * - * cdef class SufficientStats: # <<<<<<<<<<<<<< - * cdef mteval.SufficientStats* stats - * cdef mteval.EvaluationMetric* metric + * cdef class TRule: */ -struct __pyx_obj_5_cdec_SufficientStats { +struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr { PyObject_HEAD - SufficientStats *stats; - EvaluationMetric *metric; + struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *__pyx_outer_scope; + PyObject *__pyx_v_w; + PyObject *__pyx_t_0; + Py_ssize_t __pyx_t_1; + PyObject *(*__pyx_t_2)(PyObject *); }; -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":55 - * self.vector.set_value(fid, value) +/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":53 + * return TDConvert(-self.rule.lhs_) * - * def __iter__(self): # <<<<<<<<<<<<<< - * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) - * try: + * def __str__(self): # <<<<<<<<<<<<<< + * scores = ' '.join('%s=%s' % feat for feat in self.scores) + * return '[%s] ||| %s ||| %s ||| %s' % (self.lhs, _phrase(self.f), _phrase(self.e), scores) */ -struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ { +struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ { PyObject_HEAD - size_t __pyx_v_i; - FastSparseVector::const_iterator *__pyx_v_it; - struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self; - size_t __pyx_t_0; - size_t __pyx_t_1; + struct __pyx_obj_5_cdec_TRule *__pyx_v_self; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":60 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":189 * - * def kbest_features(self, size): # <<<<<<<<<<<<<< - * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) - * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal].Derivation* derivation + * property in_edges: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.node.in_edges_.size()): */ -struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features { +struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ { PyObject_HEAD - KBest::KBestDerivations,FeatureVectorTraversal>::Derivation *__pyx_v_derivation; - KBest::KBestDerivations,FeatureVectorTraversal> *__pyx_v_derivations; - struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap; - unsigned int __pyx_v_k; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; - PyObject *__pyx_v_size; - unsigned int __pyx_t_0; - long __pyx_t_1; + unsigned int __pyx_v_i; + struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self; + size_t __pyx_t_0; + unsigned int __pyx_t_1; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":46 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":49 + * return hypergraph.AsPLF(self.lattice[0], True).c_str() * - * def kbest_tree(self, size): # <<<<<<<<<<<<<< - * 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 + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(len(self)): */ -struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree { +struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ { PyObject_HEAD - KBest::KBestDerivations,ETreeTraversal>::Derivation *__pyx_v_derivation; - KBest::KBestDerivations,ETreeTraversal> *__pyx_v_derivations; - unsigned int __pyx_v_k; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; - PyObject *__pyx_v_size; - PyObject *__pyx_v_tree; - unsigned int __pyx_t_0; - long __pyx_t_1; + unsigned int __pyx_v_i; + struct __pyx_obj_5_cdec_Lattice *__pyx_v_self; + Py_ssize_t __pyx_t_0; + unsigned int __pyx_t_1; }; -/* "_cdec.pyx":15 - * class ParseFailed(Exception): pass +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":121 * - * cdef class Decoder: # <<<<<<<<<<<<<< - * cdef decoder.Decoder* dec - * cdef DenseVector weights + * property nodes: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.hg.nodes_.size()): */ -struct __pyx_obj_5_cdec_Decoder { +struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ { PyObject_HEAD - Decoder *dec; - struct __pyx_obj_5_cdec_DenseVector *weights; + unsigned int __pyx_v_i; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; + size_t __pyx_t_0; + unsigned int __pyx_t_1; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":103 - * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":60 + * return result * - * cdef class SegmentEvaluator: # <<<<<<<<<<<<<< + * cdef class CandidateSet: # <<<<<<<<<<<<<< * cdef shared_ptr[mteval.SegmentEvaluator]* scorer * cdef mteval.EvaluationMetric* metric */ -struct __pyx_obj_5_cdec_SegmentEvaluator { +struct __pyx_obj_5_cdec_CandidateSet { PyObject_HEAD boost::shared_ptr *scorer; EvaluationMetric *metric; + training::CandidateSet *cs; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":36 - * return sparse - * - * cdef class SparseVector: # <<<<<<<<<<<<<< - * cdef FastSparseVector[weight_t]* vector +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":195 * + * property out_edges: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.node.out_edges_.size()): */ -struct __pyx_obj_5_cdec_SparseVector { +struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ { PyObject_HEAD - FastSparseVector *vector; + unsigned int __pyx_v_i; + struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self; + size_t __pyx_t_0; + unsigned int __pyx_t_1; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":4 - * cimport kbest as kb +/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":4 + * return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) + * + * cdef class TRule: # <<<<<<<<<<<<<< + * cdef hypergraph.TRule* rule * - * cdef class Hypergraph: # <<<<<<<<<<<<<< - * cdef hypergraph.Hypergraph* hg - * cdef MT19937* rng */ -struct __pyx_obj_5_cdec_Hypergraph { +struct __pyx_obj_5_cdec_TRule { PyObject_HEAD - Hypergraph *hg; - MT19937 *rng; + TRule *rule; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":3 - * cimport lattice - * - * cdef class Lattice: # <<<<<<<<<<<<<< - * cdef lattice.Lattice* lattice +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":43 + * del derivations * + * def kbest_trees(self, size): # <<<<<<<<<<<<<< + * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal]* f_derivations = new kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal](self.hg[0], size) + * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal].Derivation* f_derivation */ -struct __pyx_obj_5_cdec_Lattice { +struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees { PyObject_HEAD - Lattice *lattice; + KBest::KBestDerivations,ETreeTraversal>::Derivation *__pyx_v_e_derivation; + KBest::KBestDerivations,ETreeTraversal> *__pyx_v_e_derivations; + PyObject *__pyx_v_e_tree; + KBest::KBestDerivations,FTreeTraversal>::Derivation *__pyx_v_f_derivation; + KBest::KBestDerivations,FTreeTraversal> *__pyx_v_f_derivations; + PyObject *__pyx_v_f_tree; + unsigned int __pyx_v_k; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; + PyObject *__pyx_v_size; + unsigned int __pyx_t_0; + long __pyx_t_1; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":22 - * self.vector[0][fid] = value +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":93 + * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) * - * def __iter__(self): # <<<<<<<<<<<<<< - * cdef unsigned fid - * for fid in range(1, self.vector.size()): + * cdef class SegmentEvaluator: # <<<<<<<<<<<<<< + * cdef shared_ptr[mteval.SegmentEvaluator]* scorer + * cdef mteval.EvaluationMetric* metric */ -struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ { +struct __pyx_obj_5_cdec_SegmentEvaluator { PyObject_HEAD - unsigned int __pyx_v_fid; - struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self; - size_t __pyx_t_0; - unsigned int __pyx_t_1; + boost::shared_ptr *scorer; + EvaluationMetric *metric; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":32 - * return fmap +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":61 + * del e_derivations * - * def kbest(self, size): # <<<<<<<<<<<<<< - * 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 + * def kbest_features(self, size): # <<<<<<<<<<<<<< + * cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal]* derivations = new kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal](self.hg[0], size) + * cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal].Derivation* derivation */ -struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest { +struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features { PyObject_HEAD - KBest::KBestDerivations,ESentenceTraversal>::Derivation *__pyx_v_derivation; - KBest::KBestDerivations,ESentenceTraversal> *__pyx_v_derivations; + KBest::KBestDerivations,FeatureVectorTraversal>::Derivation *__pyx_v_derivation; + KBest::KBestDerivations,FeatureVectorTraversal> *__pyx_v_derivations; + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap; unsigned int __pyx_v_k; struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; - PyObject *__pyx_v_sentence; PyObject *__pyx_v_size; unsigned int __pyx_t_0; long __pyx_t_1; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":22 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":76 + * del derivations + * + * def sample(self, unsigned n): # <<<<<<<<<<<<<< + * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() + * if self.rng == NULL: + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample { + PyObject_HEAD + std::vector *__pyx_v_hypos; + unsigned int __pyx_v_k; + unsigned int __pyx_v_n; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; + size_t __pyx_t_0; + unsigned int __pyx_t_1; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":12 * return stats * * cdef class Candidate: # <<<<<<<<<<<<<< @@ -640,85 +704,63 @@ struct __pyx_obj_5_cdec_Candidate { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":59 - * - * def todot(self): - * def lines(): # <<<<<<<<<<<<<< - * yield 'digraph lattice {' - * yield 'rankdir = LR;' - */ -struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines { - PyObject_HEAD - struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *__pyx_outer_scope; - PyObject *__pyx_v_delta; - PyObject *__pyx_v_i; - PyObject *__pyx_v_label; - PyObject *__pyx_v_weight; - Py_ssize_t __pyx_t_0; - PyObject *__pyx_t_1; - PyObject *(*__pyx_t_2)(PyObject *); - PyObject *__pyx_t_3; - Py_ssize_t __pyx_t_4; - PyObject *(*__pyx_t_5)(PyObject *); -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":75 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":115 * - * def sample(self, unsigned n): # <<<<<<<<<<<<<< - * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() - * if self.rng == NULL: + * property edges: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.hg.edges_.size()): */ -struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample { +struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ { PyObject_HEAD - std::vector *__pyx_v_hypos; - unsigned int __pyx_v_k; - unsigned int __pyx_v_n; + unsigned int __pyx_v_i; struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; - PyObject *__pyx_v_sentence; size_t __pyx_t_0; unsigned int __pyx_t_1; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":3 - * from cython.operator cimport preincrement as pinc - * - * cdef class DenseVector: # <<<<<<<<<<<<<< - * cdef vector[weight_t]* vector # Not owned by DenseVector +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":133 + * include "trule.pxi" * + * cdef class HypergraphEdge: # <<<<<<<<<<<<<< + * cdef hypergraph.Hypergraph* hg + * cdef hypergraph.HypergraphEdge* edge */ -struct __pyx_obj_5_cdec_DenseVector { +struct __pyx_obj_5_cdec_HypergraphEdge { PyObject_HEAD - std::vector *vector; + struct __pyx_vtabstruct_5_cdec_HypergraphEdge *__pyx_vtab; + Hypergraph *hg; + const Hypergraph::Edge *edge; + struct __pyx_obj_5_cdec_TRule *trule; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":50 - * return hypergraph.AsPLF(self.lattice[0], True).c_str() +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":55 + * self.vector.set_value(fid, value) * * def __iter__(self): # <<<<<<<<<<<<<< - * cdef unsigned i - * for i in range(len(self)): + * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) + * try: */ -struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ { +struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ { PyObject_HEAD - unsigned int __pyx_v_i; - struct __pyx_obj_5_cdec_Lattice *__pyx_v_self; - Py_ssize_t __pyx_t_0; - unsigned int __pyx_t_1; + size_t __pyx_v_i; + FastSparseVector::const_iterator *__pyx_v_it; + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self; + size_t __pyx_t_0; + size_t __pyx_t_1; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":54 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":44 * return self.stats.size() * * def __iter__(self): # <<<<<<<<<<<<<< * for i in range(len(self)): * yield self.stats[0][i] */ -struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ { +struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ { PyObject_HEAD PyObject *__pyx_v_i; struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self; @@ -728,34 +770,272 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":95 - * return candidate +/* "_cdec.pyx":38 + * yield key, bytes(value) * - * def __iter__(self): # <<<<<<<<<<<<<< - * cdef unsigned i - * for i in range(len(self)): + * cdef class Decoder: # <<<<<<<<<<<<<< + * cdef decoder.Decoder* dec + * cdef DenseVector weights */ -struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ { +struct __pyx_obj_5_cdec_Decoder { PyObject_HEAD - unsigned int __pyx_v_i; - struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self; - Py_ssize_t __pyx_t_0; - unsigned int __pyx_t_1; + Decoder *dec; + struct __pyx_obj_5_cdec_DenseVector *weights; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":58 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":179 + * raise NotImplemented('comparison not implemented for HypergraphEdge') + * + * cdef class HypergraphNode: # <<<<<<<<<<<<<< + * cdef hypergraph.Hypergraph* hg + * cdef hypergraph.HypergraphNode* node + */ +struct __pyx_obj_5_cdec_HypergraphNode { + PyObject_HEAD + struct __pyx_vtabstruct_5_cdec_HypergraphNode *__pyx_vtab; + Hypergraph *hg; + const Hypergraph::Node *node; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":36 + * return sparse + * + * cdef class SparseVector: # <<<<<<<<<<<<<< + * cdef FastSparseVector[weight_t]* vector + * + */ +struct __pyx_obj_5_cdec_SparseVector { + PyObject_HEAD + FastSparseVector *vector; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":54 + * + * def __str__(self): + * scores = ' '.join('%s=%s' % feat for feat in self.scores) # <<<<<<<<<<<<<< + * return '[%s] ||| %s ||| %s ||| %s' % (self.lhs, _phrase(self.f), _phrase(self.e), scores) + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr { + PyObject_HEAD + struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *__pyx_outer_scope; + PyObject *__pyx_v_feat; + PyObject *__pyx_t_0; + Py_ssize_t __pyx_t_1; + PyObject *(*__pyx_t_2)(PyObject *); +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":153 + * + * property tail_nodes: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.edge.tail_nodes_.size()): + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ { + PyObject_HEAD + unsigned int __pyx_v_i; + struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self; + unsigned int __pyx_t_0; + unsigned int __pyx_t_1; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":22 + * self.vector[0][fid] = value + * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef unsigned fid + * for fid in range(1, self.vector.size()): + */ +struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ { + PyObject_HEAD + unsigned int __pyx_v_fid; + struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self; + size_t __pyx_t_0; + unsigned int __pyx_t_1; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":31 + * return unicode(hypergraph.JoshuaVisualizationString(self.hg[0]).c_str(), 'utf8') + * + * def kbest(self, size): # <<<<<<<<<<<<<< + * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal]* derivations = new kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal](self.hg[0], size) + * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal].Derivation* derivation + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest { + PyObject_HEAD + KBest::KBestDerivations,ESentenceTraversal>::Derivation *__pyx_v_derivation; + KBest::KBestDerivations,ESentenceTraversal> *__pyx_v_derivations; + unsigned int __pyx_v_k; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; + PyObject *__pyx_v_size; + unsigned int __pyx_t_0; + long __pyx_t_1; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":3 + * from cython.operator cimport preincrement as pinc + * + * cdef class DenseVector: # <<<<<<<<<<<<<< + * cdef vector[weight_t]* vector # Not owned by DenseVector + * + */ +struct __pyx_obj_5_cdec_DenseVector { + PyObject_HEAD + std::vector *vector; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":58 + * + * def todot(self): + * def lines(): # <<<<<<<<<<<<<< + * yield 'digraph lattice {' + * yield 'rankdir = LR;' + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines { + PyObject_HEAD + struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *__pyx_outer_scope; + PyObject *__pyx_v_delta; + PyObject *__pyx_v_i; + PyObject *__pyx_v_label; + PyObject *__pyx_v_weight; + Py_ssize_t __pyx_t_0; + PyObject *__pyx_t_1; + PyObject *(*__pyx_t_2)(PyObject *); + PyObject *__pyx_t_3; + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":26 + * return fmap + * + * cdef class SufficientStats: # <<<<<<<<<<<<<< + * cdef mteval.SufficientStats* stats + * cdef mteval.EvaluationMetric* metric + */ +struct __pyx_obj_5_cdec_SufficientStats { + PyObject_HEAD + SufficientStats *stats; + EvaluationMetric *metric; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":57 * del self.lattice * * def todot(self): # <<<<<<<<<<<<<< * def lines(): * yield 'digraph lattice {' */ -struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot { +struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot { PyObject_HEAD struct __pyx_obj_5_cdec_Lattice *__pyx_v_self; }; + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":4 + * cimport kbest + * + * cdef class Hypergraph: # <<<<<<<<<<<<<< + * cdef hypergraph.Hypergraph* hg + * cdef MT19937* rng + */ +struct __pyx_obj_5_cdec_Hypergraph { + PyObject_HEAD + Hypergraph *hg; + MT19937 *rng; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":3 + * cimport lattice + * + * cdef class Lattice: # <<<<<<<<<<<<<< + * cdef lattice.Lattice* lattice + * + */ +struct __pyx_obj_5_cdec_Lattice { + PyObject_HEAD + Lattice *lattice; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":1 + * def _phrase(phrase): # <<<<<<<<<<<<<< + * return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) + * + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase { + PyObject_HEAD + PyObject *__pyx_v_phrase; +}; + + +/* "_cdec.pyx":42 + * cdef DenseVector weights + * + * def __cinit__(self, config_str=None, **config): # <<<<<<<<<<<<<< + * """ Configuration can be given as a string: + * Decoder('formalism = scfg') + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ { + PyObject_HEAD + PyObject *__pyx_v_config; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":85 + * return candidate + * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(len(self)): + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ { + PyObject_HEAD + unsigned int __pyx_v_i; + struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self; + Py_ssize_t __pyx_t_0; + unsigned int __pyx_t_1; +}; + + + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":179 + * raise NotImplemented('comparison not implemented for HypergraphEdge') + * + * cdef class HypergraphNode: # <<<<<<<<<<<<<< + * cdef hypergraph.Hypergraph* hg + * cdef hypergraph.HypergraphNode* node + */ + +struct __pyx_vtabstruct_5_cdec_HypergraphNode { + PyObject *(*init)(struct __pyx_obj_5_cdec_HypergraphNode *, Hypergraph *, unsigned int); +}; +static struct __pyx_vtabstruct_5_cdec_HypergraphNode *__pyx_vtabptr_5_cdec_HypergraphNode; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":133 + * include "trule.pxi" + * + * cdef class HypergraphEdge: # <<<<<<<<<<<<<< + * cdef hypergraph.Hypergraph* hg + * cdef hypergraph.HypergraphEdge* edge + */ + +struct __pyx_vtabstruct_5_cdec_HypergraphEdge { + PyObject *(*init)(struct __pyx_obj_5_cdec_HypergraphEdge *, Hypergraph *, unsigned int); +}; +static struct __pyx_vtabstruct_5_cdec_HypergraphEdge *__pyx_vtabptr_5_cdec_HypergraphEdge; #ifndef CYTHON_REFNANNY #define CYTHON_REFNANNY 0 #endif @@ -838,6 +1118,27 @@ static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) { return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b); } +static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname); + +static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) { + if (likely(PyList_CheckExact(L))) { + if (PyList_Append(L, x) < 0) return NULL; + Py_INCREF(Py_None); + return Py_None; /* this is just to have an accurate signature */ + } + else { + PyObject *r, *m; + m = __Pyx_GetAttrString(L, "append"); + if (!m) return NULL; + r = PyObject_CallFunctionObjArgs(m, x, NULL); + Py_DECREF(m); + return r; + } +} + +#define __Pyx_PyIter_Next(obj) __Pyx_PyIter_Next2(obj, NULL); +static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject *, PyObject *); /*proto*/ + static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); @@ -916,8 +1217,6 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); } -static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname); - static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */ #define __Pyx_PyObject_AsDouble(obj) \ ((likely(PyFloat_CheckExact(obj))) ? \ @@ -977,6 +1276,18 @@ static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m, PyObject *tuple); static int __Pyx_CyFunction_init(void); +#include + +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); /*proto*/ + +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); /*proto*/ + +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals +#else +#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals +#endif + static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); @@ -1009,6 +1320,9 @@ static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); +static void __Pyx_WriteUnraisable(const char *name, int clineno, + int lineno, const char *filename); /*proto*/ + static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ #define __Pyx_Generator_USED @@ -1030,11 +1344,10 @@ static __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body, PyObject *closure); static int __pyx_Generator_init(void); -static void __Pyx_WriteUnraisable(const char *name, int clineno, - int lineno, const char *filename); /*proto*/ - static int __Pyx_check_binary_version(void); +static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ + typedef struct { int code_line; PyCodeObject* code_object; @@ -1079,6 +1392,9 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ static PyTypeObject *__pyx_ptype_5_cdec_DenseVector = 0; static PyTypeObject *__pyx_ptype_5_cdec_SparseVector = 0; static PyTypeObject *__pyx_ptype_5_cdec_Hypergraph = 0; +static PyTypeObject *__pyx_ptype_5_cdec_TRule = 0; +static PyTypeObject *__pyx_ptype_5_cdec_HypergraphEdge = 0; +static PyTypeObject *__pyx_ptype_5_cdec_HypergraphNode = 0; static PyTypeObject *__pyx_ptype_5_cdec_Lattice = 0; static PyTypeObject *__pyx_ptype_5_cdec_Candidate = 0; static PyTypeObject *__pyx_ptype_5_cdec_SufficientStats = 0; @@ -1089,14 +1405,26 @@ static PyTypeObject *__pyx_ptype_5_cdec_Decoder = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct____iter__ = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_1___iter__ = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_2_kbest = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_tree = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_trees = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_5_sample = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_6___iter__ = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_7_todot = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_8_lines = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_9___iter__ = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_10___iter__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_6___get__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_7___get__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_8__phrase = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_9_genexpr = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_10___str__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_11_genexpr = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_12___get__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_13___get__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_14___get__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_15___iter__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_16_todot = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_17_lines = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_18___iter__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_19___iter__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_20__make_config = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_21___cinit__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_22_genexpr = 0; static char *__pyx_f_5_cdec_as_str(PyObject *, struct __pyx_opt_args_5_cdec_as_str *__pyx_optional_args); /*proto*/ static struct __pyx_obj_5_cdec_SufficientStats *__pyx_f_5_cdec_as_stats(PyObject *, PyObject *); /*proto*/ #define __Pyx_MODULE_NAME "_cdec" @@ -1104,9 +1432,9 @@ int __pyx_module_is_main__cdec = 0; /* Implementation of '_cdec' */ static PyObject *__pyx_builtin_Exception; +static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_KeyError; static PyObject *__pyx_builtin_range; -static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_NotImplemented; static PyObject *__pyx_builtin_eval; static PyObject *__pyx_builtin_enumerate; @@ -1142,17 +1470,44 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_35__div__(PyObject *__pyx_v_x, P #endif static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_4viterbi_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_6viterbi_source_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_8viterbi_features(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_4viterbi_trees(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_6viterbi_features(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_8viterbi_joshua(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_10kbest(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_13kbest_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_13kbest_trees(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_16kbest_features(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_19sample(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, unsigned int __pyx_v_n); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_22intersect(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, struct __pyx_obj_5_cdec_Lattice *__pyx_v_lat); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_24prune(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_beam_alpha, PyObject *__pyx_v_density, PyObject *__pyx_v_kwargs); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_26lattice(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_weights); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_5edges___get__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_5nodes___get__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_4goal___get__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_7_phrase_genexpr(PyObject *__pyx_self); /* proto */ +static PyObject *__pyx_pf_5_cdec__phrase(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_phrase); /* proto */ +static PyObject *__pyx_pf_5_cdec_5TRule_5arity___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_5TRule_1f___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_5TRule_1e___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_5TRule_6scores___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_5TRule_3lhs___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_5TRule_7__str___genexpr(PyObject *__pyx_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_5TRule___str__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ +static Py_ssize_t __pyx_pf_5_cdec_14HypergraphEdge___len__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_9head_node___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_10tail_nodes___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_4span___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_14feature_values___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_4prob___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_2__richcmp__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_x, struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_y, int __pyx_v_op); /* proto */ +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_5trule___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_14HypergraphEdge_5trule_2__set__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_5_cdec_14HypergraphEdge_5trule_4__del__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_14HypergraphNode_8in_edges___get__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_14HypergraphNode_9out_edges___get__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_14HypergraphNode_4span___get__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_14HypergraphNode_3cat___get__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_14HypergraphNode___richcmp__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_x, struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_y, int __pyx_v_op); /* proto */ static int __pyx_pf_5_cdec_7Lattice___init__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, PyObject *__pyx_v_inp); /* proto */ static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index); /* proto */ static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index, PyObject *__pyx_v_arcs); /* proto */ @@ -1186,45 +1541,70 @@ static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__p static void __pyx_pf_5_cdec_6Scorer_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Scorer *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs); /* proto */ static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self); /* proto */ -static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, char *__pyx_v_config); /* proto */ +static PyObject *__pyx_pf_5_cdec_2_make_config(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_config); /* proto */ +static PyObject *__pyx_pf_5_cdec_7Decoder_9__cinit___genexpr(PyObject *__pyx_self); /* proto */ +static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_config_str, PyObject *__pyx_v_config); /* proto */ static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Decoder *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self); /* proto */ static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_weights); /* proto */ -static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_cfg); /* proto */ +static PyObject *__pyx_pf_5_cdec_7Decoder_9formalism___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_weights); /* proto */ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_sentence, PyObject *__pyx_v_grammar); /* proto */ -static char __pyx_k_1[] = "cannot take the dot product of %s and SparseVector"; -static char __pyx_k_2[] = "comparison not implemented for SparseVector"; -static char __pyx_k_10[] = "csplit_preserve_full_word"; -static char __pyx_k_11[] = "cannot reweight hypergraph with %s"; -static char __pyx_k_13[] = "Cannot create lattice from %s"; -static char __pyx_k_14[] = "lattice index out of range"; -static char __pyx_k_19[] = "digraph lattice {"; - static char __pyx_k_20[] = "rankdir = LR;"; - static char __pyx_k_21[] = "node [shape=circle];"; - static char __pyx_k_22[] = "%d -> %d [label=\"%s\"];"; - static char __pyx_k_23[] = "\""; - static char __pyx_k_24[] = "\\\""; - static char __pyx_k_26[] = "%d [shape=doublecircle]"; -static char __pyx_k_27[] = "}"; -static char __pyx_k_30[] = "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi"; -static char __pyx_k_31[] = "\n"; -static char __pyx_k_33[] = "Cannot convert type %s to str"; -static char __pyx_k_35[] = "candidate set index out of range"; -static char __pyx_k_37[] = "cannot initialize weights with %s"; -static char __pyx_k_40[] = "Cannot translate input type %s"; +static char __pyx_k_1[] = "Cannot convert type %s to str"; +static char __pyx_k_3[] = "cannot take the dot product of %s and SparseVector"; +static char __pyx_k_4[] = "comparison not implemented for SparseVector"; +static char __pyx_k_6[] = "csplit_preserve_full_word"; +static char __pyx_k_7[] = "cannot reweight hypergraph with %s"; +static char __pyx_k_8[] = "[%s,%d]"; +static char __pyx_k_10[] = " "; +static char __pyx_k_11[] = "%s=%s"; +static char __pyx_k_12[] = "[%s] ||| %s ||| %s ||| %s"; +static char __pyx_k_13[] = "comparison not implemented for HypergraphEdge"; +static char __pyx_k_15[] = "comparison not implemented for HypergraphNode"; +static char __pyx_k_18[] = "Cannot create lattice from %s"; +static char __pyx_k_19[] = "lattice index out of range"; +static char __pyx_k_23[] = "digraph lattice {"; + static char __pyx_k_24[] = "rankdir = LR;"; + static char __pyx_k_25[] = "node [shape=circle];"; + static char __pyx_k_26[] = "%d -> %d [label=\"%s\"];"; + static char __pyx_k_27[] = "\""; + static char __pyx_k_28[] = "\\\""; + static char __pyx_k_30[] = "%d [shape=doublecircle]"; +static char __pyx_k_31[] = "}"; +static char __pyx_k_34[] = "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi"; +static char __pyx_k_35[] = "\n"; +static char __pyx_k_37[] = "candidate set index out of range"; +static char __pyx_k_39[] = "%s %s"; +static char __pyx_k_40[] = "%s = %s"; +static char __pyx_k_42[] = "formalism \"%s\" unknown"; +static char __pyx_k_43[] = "cannot initialize weights with %s"; +static char __pyx_k_44[] = "#"; +static char __pyx_k_48[] = "Cannot translate input type %s"; +static char __pyx_k_51[] = "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi"; +static char __pyx_k_56[] = "/Users/vchahun/Sandbox/cdec/python/src/_cdec.pyx"; +static char __pyx_k__e[] = "e"; +static char __pyx_k__f[] = "f"; static char __pyx_k__i[] = "i"; static char __pyx_k__k[] = "k"; +static char __pyx_k__pb[] = "pb"; static char __pyx_k__TER[] = "TER"; static char __pyx_k__dot[] = "dot"; +static char __pyx_k__fst[] = "fst"; +static char __pyx_k__get[] = "get"; static char __pyx_k__inp[] = "inp"; +static char __pyx_k__key[] = "key"; +static char __pyx_k__lhs[] = "lhs"; static char __pyx_k__plf[] = "plf"; static char __pyx_k__BLEU[] = "BLEU"; static char __pyx_k__eval[] = "eval"; +static char __pyx_k__info[] = "info"; static char __pyx_k__join[] = "join"; static char __pyx_k__name[] = "name"; static char __pyx_k__open[] = "open"; static char __pyx_k__refs[] = "refs"; +static char __pyx_k__scfg[] = "scfg"; static char __pyx_k__self[] = "self"; +static char __pyx_k__span[] = "span"; static char __pyx_k__utf8[] = "utf8"; static char __pyx_k___cdec[] = "_cdec"; static char __pyx_k__delta[] = "delta"; @@ -1234,11 +1614,17 @@ static char __pyx_k__lines[] = "lines"; static char __pyx_k__range[] = "range"; static char __pyx_k__split[] = "split"; static char __pyx_k__strip[] = "strip"; +static char __pyx_k__value[] = "value"; static char __pyx_k__config[] = "config"; -static char __pyx_k__decode[] = "decode"; +static char __pyx_k__csplit[] = "csplit"; static char __pyx_k__encode[] = "encode"; +static char __pyx_k__phrase[] = "phrase"; +static char __pyx_k__scores[] = "scores"; +static char __pyx_k__tagger[] = "tagger"; static char __pyx_k__weight[] = "weight"; +static char __pyx_k___phrase[] = "_phrase"; static char __pyx_k__density[] = "density"; +static char __pyx_k__genexpr[] = "genexpr"; static char __pyx_k__grammar[] = "grammar"; static char __pyx_k__replace[] = "replace"; static char __pyx_k__IBM_BLEU[] = "IBM_BLEU"; @@ -1247,41 +1633,62 @@ static char __pyx_k____exit__[] = "__exit__"; static char __pyx_k____main__[] = "__main__"; static char __pyx_k____test__[] = "__test__"; static char __pyx_k__encoding[] = "encoding"; +static char __pyx_k__in_edges[] = "in_edges"; +static char __pyx_k__lexalign[] = "lexalign"; +static char __pyx_k__lextrans[] = "lextrans"; static char __pyx_k__sentence[] = "sentence"; static char __pyx_k__Exception[] = "Exception"; static char __pyx_k__TypeError[] = "TypeError"; static char __pyx_k____enter__[] = "__enter__"; static char __pyx_k__enumerate[] = "enumerate"; static char __pyx_k__evaluator[] = "evaluator"; +static char __pyx_k__formalism[] = "formalism"; static char __pyx_k__IndexError[] = "IndexError"; static char __pyx_k__beam_alpha[] = "beam_alpha"; +static char __pyx_k__config_str[] = "config_str"; static char __pyx_k__hypergraph[] = "hypergraph"; +static char __pyx_k__startswith[] = "startswith"; static char __pyx_k__ParseFailed[] = "ParseFailed"; +static char __pyx_k___make_config[] = "_make_config"; +static char __pyx_k__InvalidConfig[] = "InvalidConfig"; static char __pyx_k__NotImplemented[] = "NotImplemented"; static PyObject *__pyx_kp_s_1; -static PyObject *__pyx_n_s_10; +static PyObject *__pyx_kp_s_10; static PyObject *__pyx_kp_s_11; +static PyObject *__pyx_kp_s_12; static PyObject *__pyx_kp_s_13; -static PyObject *__pyx_kp_s_14; +static PyObject *__pyx_kp_s_15; +static PyObject *__pyx_kp_s_18; static PyObject *__pyx_kp_s_19; -static PyObject *__pyx_kp_s_2; -static PyObject *__pyx_kp_s_20; -static PyObject *__pyx_kp_s_21; -static PyObject *__pyx_kp_s_22; static PyObject *__pyx_kp_s_23; static PyObject *__pyx_kp_s_24; +static PyObject *__pyx_kp_s_25; static PyObject *__pyx_kp_s_26; static PyObject *__pyx_kp_s_27; +static PyObject *__pyx_kp_s_28; +static PyObject *__pyx_kp_s_3; static PyObject *__pyx_kp_s_30; static PyObject *__pyx_kp_s_31; -static PyObject *__pyx_kp_s_33; +static PyObject *__pyx_kp_s_34; static PyObject *__pyx_kp_s_35; static PyObject *__pyx_kp_s_37; +static PyObject *__pyx_kp_s_39; +static PyObject *__pyx_kp_s_4; static PyObject *__pyx_kp_s_40; +static PyObject *__pyx_kp_s_42; +static PyObject *__pyx_kp_s_43; +static PyObject *__pyx_kp_s_44; +static PyObject *__pyx_kp_s_48; +static PyObject *__pyx_kp_s_51; +static PyObject *__pyx_kp_s_56; +static PyObject *__pyx_n_s_6; +static PyObject *__pyx_kp_s_7; +static PyObject *__pyx_kp_s_8; static PyObject *__pyx_n_s__BLEU; static PyObject *__pyx_n_s__Exception; static PyObject *__pyx_n_s__IBM_BLEU; static PyObject *__pyx_n_s__IndexError; +static PyObject *__pyx_n_s__InvalidConfig; static PyObject *__pyx_n_s__KeyError; static PyObject *__pyx_n_s__NotImplemented; static PyObject *__pyx_n_s__ParseFailed; @@ -1292,92 +1699,249 @@ static PyObject *__pyx_n_s____exit__; static PyObject *__pyx_n_s____main__; static PyObject *__pyx_n_s____test__; static PyObject *__pyx_n_s___cdec; +static PyObject *__pyx_n_s___make_config; +static PyObject *__pyx_n_s___phrase; static PyObject *__pyx_n_s__beam_alpha; static PyObject *__pyx_n_s__config; -static PyObject *__pyx_n_s__decode; +static PyObject *__pyx_n_s__config_str; +static PyObject *__pyx_n_s__csplit; static PyObject *__pyx_n_s__delta; static PyObject *__pyx_n_s__density; static PyObject *__pyx_n_s__dot; +static PyObject *__pyx_n_s__e; static PyObject *__pyx_n_s__encode; static PyObject *__pyx_n_s__encoding; static PyObject *__pyx_n_s__enumerate; static PyObject *__pyx_n_s__eval; static PyObject *__pyx_n_s__evaluator; +static PyObject *__pyx_n_s__f; +static PyObject *__pyx_n_s__formalism; +static PyObject *__pyx_n_s__fst; +static PyObject *__pyx_n_s__genexpr; +static PyObject *__pyx_n_s__get; static PyObject *__pyx_n_s__grammar; static PyObject *__pyx_n_s__hypergraph; static PyObject *__pyx_n_s__i; +static PyObject *__pyx_n_s__in_edges; +static PyObject *__pyx_n_s__info; static PyObject *__pyx_n_s__inp; static PyObject *__pyx_n_s__items; static PyObject *__pyx_n_s__join; static PyObject *__pyx_n_s__k; +static PyObject *__pyx_n_s__key; static PyObject *__pyx_n_s__label; +static PyObject *__pyx_n_s__lexalign; +static PyObject *__pyx_n_s__lextrans; +static PyObject *__pyx_n_s__lhs; static PyObject *__pyx_n_s__lines; static PyObject *__pyx_n_s__name; static PyObject *__pyx_n_s__open; +static PyObject *__pyx_n_s__pb; +static PyObject *__pyx_n_s__phrase; static PyObject *__pyx_n_s__plf; static PyObject *__pyx_n_s__range; static PyObject *__pyx_n_s__refs; static PyObject *__pyx_n_s__replace; +static PyObject *__pyx_n_s__scfg; +static PyObject *__pyx_n_s__scores; static PyObject *__pyx_n_s__self; static PyObject *__pyx_n_s__sentence; +static PyObject *__pyx_n_s__span; static PyObject *__pyx_n_s__split; +static PyObject *__pyx_n_s__startswith; static PyObject *__pyx_n_s__strip; +static PyObject *__pyx_n_s__tagger; static PyObject *__pyx_n_s__utf8; +static PyObject *__pyx_n_s__value; static PyObject *__pyx_n_s__weight; static PyObject *__pyx_int_0; static PyObject *__pyx_int_1; -static PyObject *__pyx_k_tuple_3; -static PyObject *__pyx_k_tuple_4; +static PyObject *__pyx_k_tuple_2; 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_12; -static PyObject *__pyx_k_tuple_15; +static PyObject *__pyx_k_tuple_14; static PyObject *__pyx_k_tuple_16; static PyObject *__pyx_k_tuple_17; -static PyObject *__pyx_k_tuple_18; -static PyObject *__pyx_k_tuple_25; -static PyObject *__pyx_k_tuple_28; +static PyObject *__pyx_k_tuple_20; +static PyObject *__pyx_k_tuple_21; +static PyObject *__pyx_k_tuple_22; +static PyObject *__pyx_k_tuple_29; static PyObject *__pyx_k_tuple_32; -static PyObject *__pyx_k_tuple_34; static PyObject *__pyx_k_tuple_36; static PyObject *__pyx_k_tuple_38; -static PyObject *__pyx_k_tuple_39; static PyObject *__pyx_k_tuple_41; -static PyObject *__pyx_k_tuple_42; -static PyObject *__pyx_k_codeobj_29; - -/* Python wrapper */ -static Py_ssize_t __pyx_pw_5_cdec_11DenseVector_1__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_5_cdec_11DenseVector_1__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_11DenseVector___len__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":6 - * cdef vector[weight_t]* vector # Not owned by DenseVector - * - * def __len__(self): # <<<<<<<<<<<<<< - * return self.vector.size() +static PyObject *__pyx_k_tuple_45; +static PyObject *__pyx_k_tuple_46; +static PyObject *__pyx_k_tuple_47; +static PyObject *__pyx_k_tuple_49; +static PyObject *__pyx_k_tuple_52; +static PyObject *__pyx_k_tuple_53; +static PyObject *__pyx_k_tuple_54; +static PyObject *__pyx_k_codeobj_33; +static PyObject *__pyx_k_codeobj_50; +static PyObject *__pyx_k_codeobj_55; + +/* "_cdec.pyx":6 + * cimport decoder * + * cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): # <<<<<<<<<<<<<< + * cdef bytes ret + * if isinstance(sentence, unicode): */ -static Py_ssize_t __pyx_pf_5_cdec_11DenseVector___len__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { - Py_ssize_t __pyx_r; +static char *__pyx_f_5_cdec_as_str(PyObject *__pyx_v_sentence, struct __pyx_opt_args_5_cdec_as_str *__pyx_optional_args) { + PyObject *__pyx_v_error_msg = ((PyObject *)__pyx_kp_s_1); + PyObject *__pyx_v_ret = 0; + char *__pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__", 0); + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + char *__pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("as_str", 0); + if (__pyx_optional_args) { + if (__pyx_optional_args->__pyx_n > 0) { + __pyx_v_error_msg = __pyx_optional_args->error_msg; + } + } - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":7 - * - * def __len__(self): - * return self.vector.size() # <<<<<<<<<<<<<< - * + /* "_cdec.pyx":8 + * cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): + * cdef bytes ret + * if isinstance(sentence, unicode): # <<<<<<<<<<<<<< + * ret = sentence.encode('utf8') + * elif isinstance(sentence, str): + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":9 + * cdef bytes ret + * if isinstance(sentence, unicode): + * ret = sentence.encode('utf8') # <<<<<<<<<<<<<< + * elif isinstance(sentence, str): + * ret = sentence + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_ret = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + goto __pyx_L3; + } + + /* "_cdec.pyx":10 + * if isinstance(sentence, unicode): + * ret = sentence.encode('utf8') + * elif isinstance(sentence, str): # <<<<<<<<<<<<<< + * ret = sentence + * else: + */ + __pyx_t_3 = ((PyObject *)((PyObject*)(&PyString_Type))); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":11 + * ret = sentence.encode('utf8') + * elif isinstance(sentence, str): + * ret = sentence # <<<<<<<<<<<<<< + * else: + * raise TypeError(error_msg % type(sentence)) + */ + if (!(likely(PyBytes_CheckExact(__pyx_v_sentence))||((__pyx_v_sentence) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_sentence)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_sentence); + __pyx_v_ret = ((PyObject*)__pyx_v_sentence); + goto __pyx_L3; + } + /*else*/ { + + /* "_cdec.pyx":13 + * ret = sentence + * else: + * raise TypeError(error_msg % type(sentence)) # <<<<<<<<<<<<<< + * return ret + * + */ + __pyx_t_3 = PyNumber_Remainder(__pyx_v_error_msg, ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 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 = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; + + /* "_cdec.pyx":14 + * else: + * raise TypeError(error_msg % type(sentence)) + * return ret # <<<<<<<<<<<<<< + * + * include "vectors.pxi" + */ + __pyx_t_4 = PyBytes_AsString(((PyObject *)__pyx_v_ret)); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_t_4; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_WriteUnraisable("_cdec.as_str", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_ret); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_5_cdec_11DenseVector_1__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_11DenseVector_1__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_11DenseVector___len__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":6 + * cdef vector[weight_t]* vector # Not owned by DenseVector + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.vector.size() + * + */ + +static Py_ssize_t __pyx_pf_5_cdec_11DenseVector___len__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":7 + * + * def __len__(self): + * return self.vector.size() # <<<<<<<<<<<<<< + * * def __getitem__(self, char* fname): */ __pyx_r = __pyx_v_self->vector->size(); @@ -2503,7 +3067,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_Sp * * def __richcmp__(SparseVector x, SparseVector y, int op): */ - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), ((PyObject *)Py_TYPE(__pyx_v_other))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_3), ((PyObject *)Py_TYPE(__pyx_v_other))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); @@ -2634,7 +3198,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5 * * def __len__(self): */ - __pyx_t_1 = PyObject_Call(__pyx_builtin_NotImplemented, ((PyObject *)__pyx_k_tuple_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_NotImplemented, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -3548,7 +4112,6 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_3viterbi(PyObject *__pyx_v_self, C static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { std::vector __pyx_v_trans; - PyObject *__pyx_v_sentence = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -3562,39 +4125,34 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_H * def viterbi(self): * cdef vector[WordID] trans * hypergraph.ViterbiESentence(self.hg[0], &trans) # <<<<<<<<<<<<<< - * cdef str sentence = GetString(trans).c_str() - * return sentence.decode('utf8') + * return unicode(GetString(trans).c_str(), 'utf8') + * */ ViterbiESentence((__pyx_v_self->hg[0]), (&__pyx_v_trans)); /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":16 * cdef vector[WordID] trans * hypergraph.ViterbiESentence(self.hg[0], &trans) - * cdef str sentence = GetString(trans).c_str() # <<<<<<<<<<<<<< - * return sentence.decode('utf8') + * return unicode(GetString(trans).c_str(), 'utf8') # <<<<<<<<<<<<<< * + * def viterbi_trees(self): */ + __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyBytes_FromString(TD::GetString(__pyx_v_trans).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 16; __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[2]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_sentence = ((PyObject*)__pyx_t_1); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":17 - * 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[2]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 17; __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; + __Pyx_DECREF(((PyObject *)__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); @@ -3605,33 +4163,33 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_H __Pyx_AddTraceback("_cdec.Hypergraph.viterbi", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_sentence); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_5viterbi_tree(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_5viterbi_tree(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_5viterbi_trees(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_5viterbi_trees(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("viterbi_tree (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_4viterbi_tree(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannySetupContext("viterbi_trees (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_4viterbi_trees(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":19 - * return sentence.decode('utf8') +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":18 + * return unicode(GetString(trans).c_str(), 'utf8') * - * def viterbi_tree(self): # <<<<<<<<<<<<<< - * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str() - * return tree.decode('utf8') + * def viterbi_trees(self): # <<<<<<<<<<<<<< + * f_tree = unicode(hypergraph.ViterbiFTree(self.hg[0]).c_str(), 'utf8') + * e_tree = unicode(hypergraph.ViterbiETree(self.hg[0]).c_str(), 'utf8') */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_4viterbi_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { - PyObject *__pyx_v_tree = 0; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_4viterbi_trees(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + PyObject *__pyx_v_f_tree = NULL; + PyObject *__pyx_v_e_tree = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -3639,36 +4197,72 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_4viterbi_tree(struct __pyx_obj_5_c int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("viterbi_tree", 0); + __Pyx_RefNannySetupContext("viterbi_trees", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":20 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":19 * - * def viterbi_tree(self): - * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str() # <<<<<<<<<<<<<< - * return tree.decode('utf8') + * def viterbi_trees(self): + * f_tree = unicode(hypergraph.ViterbiFTree(self.hg[0]).c_str(), 'utf8') # <<<<<<<<<<<<<< + * e_tree = unicode(hypergraph.ViterbiETree(self.hg[0]).c_str(), 'utf8') + * return (f_tree, e_tree) + */ + __pyx_t_1 = PyBytes_FromString(ViterbiFTree((__pyx_v_self->hg[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_v_f_tree = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":20 + * def viterbi_trees(self): + * f_tree = unicode(hypergraph.ViterbiFTree(self.hg[0]).c_str(), 'utf8') + * e_tree = unicode(hypergraph.ViterbiETree(self.hg[0]).c_str(), 'utf8') # <<<<<<<<<<<<<< + * return (f_tree, e_tree) * */ __pyx_t_1 = PyBytes_FromString(ViterbiETree((__pyx_v_self->hg[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 20; __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[2]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_tree = ((PyObject*)__pyx_t_1); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_v_e_tree = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":21 - * def viterbi_tree(self): - * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str() - * return tree.decode('utf8') # <<<<<<<<<<<<<< + * f_tree = unicode(hypergraph.ViterbiFTree(self.hg[0]).c_str(), 'utf8') + * e_tree = unicode(hypergraph.ViterbiETree(self.hg[0]).c_str(), 'utf8') + * return (f_tree, e_tree) # <<<<<<<<<<<<<< * - * def viterbi_source_tree(self): + * def viterbi_features(self): */ __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[2]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 21; __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; + __Pyx_INCREF(((PyObject *)__pyx_v_f_tree)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_f_tree)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_f_tree)); + __Pyx_INCREF(((PyObject *)__pyx_v_e_tree)); + PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_e_tree)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_e_tree)); + __pyx_r = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); @@ -3676,159 +4270,153 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_4viterbi_tree(struct __pyx_obj_5_c __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_AddTraceback("_cdec.Hypergraph.viterbi_trees", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_tree); + __Pyx_XDECREF(__pyx_v_f_tree); + __Pyx_XDECREF(__pyx_v_e_tree); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_7viterbi_source_tree(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_7viterbi_source_tree(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_7viterbi_features(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_7viterbi_features(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("viterbi_source_tree (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_6viterbi_source_tree(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannySetupContext("viterbi_features (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_6viterbi_features(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":23 - * return tree.decode('utf8') + * return (f_tree, e_tree) * - * def viterbi_source_tree(self): # <<<<<<<<<<<<<< - * cdef str tree = hypergraph.ViterbiFTree(self.hg[0]).c_str() - * return tree.decode('utf8') + * def viterbi_features(self): # <<<<<<<<<<<<<< + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_6viterbi_source_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { - PyObject *__pyx_v_tree = 0; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_6viterbi_features(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap = 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_source_tree", 0); + __Pyx_RefNannySetupContext("viterbi_features", 0); /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":24 * - * def viterbi_source_tree(self): - * cdef str tree = hypergraph.ViterbiFTree(self.hg[0]).c_str() # <<<<<<<<<<<<<< - * return tree.decode('utf8') - * + * def viterbi_features(self): + * cdef SparseVector fmap = SparseVector() # <<<<<<<<<<<<<< + * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) + * return fmap */ - __pyx_t_1 = PyBytes_FromString(ViterbiFTree((__pyx_v_self->hg[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 24; __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[2]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_tree = ((PyObject*)__pyx_t_1); + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":25 - * def viterbi_source_tree(self): - * cdef str tree = hypergraph.ViterbiFTree(self.hg[0]).c_str() - * return tree.decode('utf8') # <<<<<<<<<<<<<< - * * def viterbi_features(self): + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) # <<<<<<<<<<<<<< + * return fmap + * + */ + __pyx_v_fmap->vector = new FastSparseVector(ViterbiFeatures((__pyx_v_self->hg[0]))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":26 + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) + * return fmap # <<<<<<<<<<<<<< + * + * def viterbi_joshua(self): */ __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[2]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_6), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 25; __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; + __Pyx_INCREF(((PyObject *)__pyx_v_fmap)); + __pyx_r = ((PyObject *)__pyx_v_fmap); 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_source_tree", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Hypergraph.viterbi_features", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_tree); + __Pyx_XDECREF((PyObject *)__pyx_v_fmap); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_9viterbi_features(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_9viterbi_features(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_9viterbi_joshua(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_9viterbi_joshua(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("viterbi_features (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_8viterbi_features(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannySetupContext("viterbi_joshua (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_8viterbi_joshua(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":27 - * return tree.decode('utf8') +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":28 + * return fmap + * + * def viterbi_joshua(self): # <<<<<<<<<<<<<< + * return unicode(hypergraph.JoshuaVisualizationString(self.hg[0]).c_str(), 'utf8') * - * def viterbi_features(self): # <<<<<<<<<<<<<< - * cdef SparseVector fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_8viterbi_features(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { - struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap = 0; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_8viterbi_joshua(struct __pyx_obj_5_cdec_Hypergraph *__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("viterbi_features", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":28 - * - * def viterbi_features(self): - * cdef SparseVector fmap = SparseVector() # <<<<<<<<<<<<<< - * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) - * return fmap - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); - __pyx_t_1 = 0; + __Pyx_RefNannySetupContext("viterbi_joshua", 0); /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":29 - * def viterbi_features(self): - * cdef SparseVector fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) # <<<<<<<<<<<<<< - * return fmap * - */ - __pyx_v_fmap->vector = new FastSparseVector(ViterbiFeatures((__pyx_v_self->hg[0]))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":30 - * cdef SparseVector fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) - * return fmap # <<<<<<<<<<<<<< + * def viterbi_joshua(self): + * return unicode(hypergraph.JoshuaVisualizationString(self.hg[0]).c_str(), 'utf8') # <<<<<<<<<<<<<< * * def kbest(self, size): */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_fmap)); - __pyx_r = ((PyObject *)__pyx_v_fmap); + __pyx_t_1 = PyBytes_FromString(JoshuaVisualizationString((__pyx_v_self->hg[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__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_AddTraceback("_cdec.Hypergraph.viterbi_features", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec.Hypergraph.viterbi_joshua", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_fmap); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; @@ -3846,12 +4434,12 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_11kbest(PyObject *__pyx_v_self, Py return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":32 - * return fmap +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":31 + * return unicode(hypergraph.JoshuaVisualizationString(self.hg[0]).c_str(), 'utf8') * * def kbest(self, size): # <<<<<<<<<<<<<< - * 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 kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal]* derivations = new kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal](self.hg[0], size) + * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal].Derivation* derivation */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_10kbest(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size) { @@ -3875,7 +4463,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_10kbest(struct __pyx_obj_5_cdec_Hy __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_12generator2, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_12generator2, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -3912,20 +4500,20 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_12generator2(__pyx_GeneratorObject return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":33 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":32 * * def kbest(self, size): - * 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 bytes sentence + * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal]* derivations = new kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal](self.hg[0], size) # <<<<<<<<<<<<<< + * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal].Derivation* derivation + * cdef unsigned k */ - __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[2]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __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[2]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,ESentenceTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":37 - * cdef bytes sentence + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":35 + * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal].Derivation* derivation * cdef unsigned k * try: # <<<<<<<<<<<<<< * for k in range(size): @@ -3933,32 +4521,32 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_12generator2(__pyx_GeneratorObject */ /*try:*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":38 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":36 * cdef unsigned k * try: * 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[2]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L5;} + __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[2]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L5;} for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { __pyx_cur_scope->__pyx_v_k = __pyx_t_1; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":39 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":37 * try: * 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 unicode(GetString(derivation._yield).c_str(), 'utf8') */ __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":40 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":38 * 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') + * yield unicode(GetString(derivation._yield).c_str(), 'utf8') + * finally: */ __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0)); if (__pyx_t_3) { @@ -3967,35 +4555,28 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_12generator2(__pyx_GeneratorObject } __pyx_L9:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":41 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":39 * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) * if not derivation: break - * sentence = GetString(derivation._yield).c_str() # <<<<<<<<<<<<<< - * yield sentence.decode('utf8') + * yield unicode(GetString(derivation._yield).c_str(), 'utf8') # <<<<<<<<<<<<<< * finally: + * 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[2]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L5;} + __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[2]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L5;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence)); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_4)); __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); - __pyx_cur_scope->__pyx_v_sentence = __pyx_t_4; + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":42 - * if not derivation: break - * sentence = GetString(derivation._yield).c_str() - * yield sentence.decode('utf8') # <<<<<<<<<<<<<< - * finally: - * 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[2]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L5;} + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L5;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L5;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; __Pyx_XGIVEREF(__pyx_r); @@ -4006,17 +4587,17 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_12generator2(__pyx_GeneratorObject __pyx_L10_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[2]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L5;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L5;} } __pyx_L8_break:; } - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":44 - * yield sentence.decode('utf8') + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":41 + * yield unicode(GetString(derivation._yield).c_str(), 'utf8') * finally: * del derivations # <<<<<<<<<<<<<< * - * def kbest_tree(self, size): + * def kbest_trees(self, size): */ /*finally:*/ { int __pyx_why; @@ -4026,8 +4607,8 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_12generator2(__pyx_GeneratorObject __pyx_why = 0; goto __pyx_L6; __pyx_L5: { __pyx_why = 4; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); __pyx_exc_lineno = __pyx_lineno; goto __pyx_L6; @@ -4060,33 +4641,33 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_12generator2(__pyx_GeneratorObject static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator3(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_14kbest_tree(PyObject *__pyx_v_self, PyObject *__pyx_v_size); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_14kbest_tree(PyObject *__pyx_v_self, PyObject *__pyx_v_size) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_14kbest_trees(PyObject *__pyx_v_self, PyObject *__pyx_v_size); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_14kbest_trees(PyObject *__pyx_v_self, PyObject *__pyx_v_size) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("kbest_tree (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_13kbest_tree(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_size)); + __Pyx_RefNannySetupContext("kbest_trees (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_13kbest_trees(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_size)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":46 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":43 * del derivations * - * def kbest_tree(self, size): # <<<<<<<<<<<<<< - * 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 + * def kbest_trees(self, size): # <<<<<<<<<<<<<< + * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal]* f_derivations = new kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal](self.hg[0], size) + * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal].Derivation* f_derivation */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_13kbest_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size) { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_13kbest_trees(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("kbest_tree", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)__pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_tree->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_tree, __pyx_empty_tuple, NULL); + __Pyx_RefNannySetupContext("kbest_trees", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *)__pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_trees->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_trees, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -4099,7 +4680,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_13kbest_tree(struct __pyx_obj_5_cd __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_15generator3, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_15generator3, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -4108,7 +4689,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_13kbest_tree(struct __pyx_obj_5_cd __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Hypergraph.kbest_tree", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Hypergraph.kbest_trees", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); @@ -4119,13 +4700,15 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_13kbest_tree(struct __pyx_obj_5_cd static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator3(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)__pyx_generator->closure); + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *)__pyx_generator->closure); 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; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { @@ -4136,91 +4719,155 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator3(__pyx_GeneratorObject return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":47 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":44 * - * def kbest_tree(self, size): - * 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 tree + * def kbest_trees(self, size): + * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal]* f_derivations = new kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal](self.hg[0], size) # <<<<<<<<<<<<<< + * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal].Derivation* f_derivation + * cdef kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal]* e_derivations = new kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal](self.hg[0], size) + */ + __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[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_f_derivations = new KBest::KBestDerivations,FTreeTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":46 + * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal]* f_derivations = new kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal](self.hg[0], size) + * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal].Derivation* f_derivation + * cdef kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal]* e_derivations = new kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal](self.hg[0], size) # <<<<<<<<<<<<<< + * cdef kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal].Derivation* e_derivation + * cdef unsigned k */ - __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[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,ETreeTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); + __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[2]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_e_derivations = new KBest::KBestDerivations,ETreeTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":51 - * cdef str tree + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":49 + * cdef kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal].Derivation* e_derivation * cdef unsigned k * try: # <<<<<<<<<<<<<< * for k in range(size): - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * f_derivation = f_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) */ /*try:*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":52 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":50 * cdef unsigned k * try: * for k in range(size): # <<<<<<<<<<<<<< - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break + * f_derivation = f_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * e_derivation = e_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) */ - __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[2]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L5;} + __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[2]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L5;} for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { __pyx_cur_scope->__pyx_v_k = __pyx_t_1; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":53 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":51 * try: * for k in range(size): - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< - * if not derivation: break - * tree = GetString(derivation._yield).c_str() + * f_derivation = f_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< + * e_derivation = e_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not f_derivation or not e_derivation: break */ - __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); + __pyx_cur_scope->__pyx_v_f_derivation = __pyx_cur_scope->__pyx_v_f_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":54 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":52 * 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') + * f_derivation = f_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * e_derivation = e_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< + * if not f_derivation or not e_derivation: break + * f_tree = unicode(GetString(f_derivation._yield).c_str(), 'utf8') */ - __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0)); - if (__pyx_t_3) { + __pyx_cur_scope->__pyx_v_e_derivation = __pyx_cur_scope->__pyx_v_e_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":53 + * f_derivation = f_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * e_derivation = e_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not f_derivation or not e_derivation: break # <<<<<<<<<<<<<< + * f_tree = unicode(GetString(f_derivation._yield).c_str(), 'utf8') + * e_tree = unicode(GetString(e_derivation._yield).c_str(), 'utf8') + */ + __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_f_derivation != 0)); + if (!__pyx_t_3) { + __pyx_t_4 = (!(__pyx_cur_scope->__pyx_v_e_derivation != 0)); + __pyx_t_5 = __pyx_t_4; + } else { + __pyx_t_5 = __pyx_t_3; + } + if (__pyx_t_5) { goto __pyx_L8_break; goto __pyx_L9; } __pyx_L9:; + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":54 + * e_derivation = e_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not f_derivation or not e_derivation: break + * f_tree = unicode(GetString(f_derivation._yield).c_str(), 'utf8') # <<<<<<<<<<<<<< + * e_tree = unicode(GetString(e_derivation._yield).c_str(), 'utf8') + * yield (f_tree, e_tree) + */ + __pyx_t_6 = PyBytes_FromString(TD::GetString(__pyx_cur_scope->__pyx_v_f_derivation->yield).c_str()); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_6)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_6)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_7, 1, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __pyx_t_6 = 0; + __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_f_tree)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_f_tree)); + __Pyx_GIVEREF(__pyx_t_6); + __pyx_cur_scope->__pyx_v_f_tree = ((PyObject*)__pyx_t_6); + __pyx_t_6 = 0; + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":55 - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break - * tree = GetString(derivation._yield).c_str() # <<<<<<<<<<<<<< - * yield tree.decode('utf8') + * if not f_derivation or not e_derivation: break + * f_tree = unicode(GetString(f_derivation._yield).c_str(), 'utf8') + * e_tree = unicode(GetString(e_derivation._yield).c_str(), 'utf8') # <<<<<<<<<<<<<< + * yield (f_tree, e_tree) * finally: */ - __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[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L5;} - __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[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L5;} - __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; + __pyx_t_6 = PyBytes_FromString(TD::GetString(__pyx_cur_scope->__pyx_v_e_derivation->yield).c_str()); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_6)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_6)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_7, 1, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __pyx_t_6 = 0; + __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_e_tree)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_e_tree)); + __Pyx_GIVEREF(__pyx_t_6); + __pyx_cur_scope->__pyx_v_e_tree = ((PyObject*)__pyx_t_6); + __pyx_t_6 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 - * if not derivation: break - * tree = GetString(derivation._yield).c_str() - * yield tree.decode('utf8') # <<<<<<<<<<<<<< + * f_tree = unicode(GetString(f_derivation._yield).c_str(), 'utf8') + * e_tree = unicode(GetString(e_derivation._yield).c_str(), 'utf8') + * yield (f_tree, e_tree) # <<<<<<<<<<<<<< * finally: - * del derivations + * del f_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[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L5;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L5;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_f_tree)); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_cur_scope->__pyx_v_f_tree)); + __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_f_tree)); + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_e_tree)); + PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_cur_scope->__pyx_v_e_tree)); + __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_e_tree)); + __pyx_r = ((PyObject *)__pyx_t_6); + __pyx_t_6 = 0; __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; __Pyx_XGIVEREF(__pyx_r); @@ -4237,11 +4884,11 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator3(__pyx_GeneratorObject } /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":58 - * yield tree.decode('utf8') + * yield (f_tree, e_tree) * finally: - * del derivations # <<<<<<<<<<<<<< + * del f_derivations # <<<<<<<<<<<<<< + * del e_derivations * - * def kbest_features(self, size): */ /*finally:*/ { int __pyx_why; @@ -4251,14 +4898,23 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator3(__pyx_GeneratorObject __pyx_why = 0; goto __pyx_L6; __pyx_L5: { __pyx_why = 4; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); __pyx_exc_lineno = __pyx_lineno; goto __pyx_L6; } __pyx_L6:; - delete __pyx_cur_scope->__pyx_v_derivations; + delete __pyx_cur_scope->__pyx_v_f_derivations; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":59 + * finally: + * del f_derivations + * del e_derivations # <<<<<<<<<<<<<< + * + * def kbest_features(self, size): + */ + delete __pyx_cur_scope->__pyx_v_e_derivations; switch (__pyx_why) { case 4: { __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); @@ -4273,9 +4929,9 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator3(__pyx_GeneratorObject PyErr_SetNone(PyExc_StopIteration); 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_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("kbest_trees", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; @@ -4295,12 +4951,12 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_17kbest_features(PyObject *__pyx_v return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":60 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":61 + * del e_derivations * * def kbest_features(self, size): # <<<<<<<<<<<<<< - * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) - * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal].Derivation* derivation + * cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal]* derivations = new kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal](self.hg[0], size) + * cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal].Derivation* derivation */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_16kbest_features(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size) { @@ -4324,7 +4980,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_16kbest_features(struct __pyx_obj_ __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_18generator4, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_18generator4, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -4360,19 +5016,19 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":61 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":62 * * def kbest_features(self, size): - * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) # <<<<<<<<<<<<<< - * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal].Derivation* derivation + * cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal]* derivations = new kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal](self.hg[0], size) # <<<<<<<<<<<<<< + * cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal].Derivation* derivation * cdef SparseVector fmap */ - __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[2]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __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[2]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,FeatureVectorTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":65 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":66 * cdef SparseVector fmap * cdef unsigned k * try: # <<<<<<<<<<<<<< @@ -4381,18 +5037,18 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject */ /*try:*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":66 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":67 * cdef unsigned k * try: * 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[2]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L5;} + __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[2]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L5;} for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { __pyx_cur_scope->__pyx_v_k = __pyx_t_1; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":67 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":68 * try: * for k in range(size): * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< @@ -4401,7 +5057,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject */ __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":68 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":69 * for k in range(size): * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) * if not derivation: break # <<<<<<<<<<<<<< @@ -4415,14 +5071,14 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject } __pyx_L9:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":69 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":70 * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) * if not derivation: break * fmap = SparseVector() # <<<<<<<<<<<<<< * fmap.vector = new FastSparseVector[weight_t](derivation._yield) * yield fmap */ - __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L5;} + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L5;} __Pyx_GOTREF(__pyx_t_4); __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); @@ -4430,7 +5086,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject __pyx_cur_scope->__pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_4); __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":70 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":71 * if not derivation: break * fmap = SparseVector() * fmap.vector = new FastSparseVector[weight_t](derivation._yield) # <<<<<<<<<<<<<< @@ -4439,7 +5095,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject */ __pyx_cur_scope->__pyx_v_fmap->vector = new FastSparseVector(__pyx_cur_scope->__pyx_v_derivation->yield); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":71 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":72 * fmap = SparseVector() * fmap.vector = new FastSparseVector[weight_t](derivation._yield) * yield fmap # <<<<<<<<<<<<<< @@ -4458,12 +5114,12 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject __pyx_L10_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[2]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L5;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L5;} } __pyx_L8_break:; } - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":73 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":74 * yield fmap * finally: * del derivations # <<<<<<<<<<<<<< @@ -4517,7 +5173,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_20sample(PyObject *__pyx_v_self, P __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("sample (wrapper)", 0); assert(__pyx_arg_n); { - __pyx_v_n = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_n); if (unlikely((__pyx_v_n == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_n = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_n); if (unlikely((__pyx_v_n == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -4530,7 +5186,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_20sample(PyObject *__pyx_v_self, P return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":75 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":76 * del derivations * * def sample(self, unsigned n): # <<<<<<<<<<<<<< @@ -4557,7 +5213,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_19sample(struct __pyx_obj_5_cdec_H __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __pyx_cur_scope->__pyx_v_n = __pyx_v_n; { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_21generator5, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_21generator5, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -4594,9 +5250,9 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":76 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":77 * * def sample(self, unsigned n): * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() # <<<<<<<<<<<<<< @@ -4605,7 +5261,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject */ __pyx_cur_scope->__pyx_v_hypos = new std::vector(); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":77 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":78 * def sample(self, unsigned n): * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() * if self.rng == NULL: # <<<<<<<<<<<<<< @@ -4615,33 +5271,33 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->rng == NULL); if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":78 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":79 * 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 */ __pyx_cur_scope->__pyx_v_self->rng = new MT19937(); goto __pyx_L4; } __pyx_L4:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":79 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":80 * if self.rng == NULL: * self.rng = new MT19937() * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) # <<<<<<<<<<<<<< - * cdef str sentence * cdef unsigned k + * try: */ HypergraphSampler::sample_hypotheses((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_cur_scope->__pyx_v_n, __pyx_cur_scope->__pyx_v_self->rng, __pyx_cur_scope->__pyx_v_hypos); /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":82 - * cdef str sentence + * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) * cdef unsigned k * try: # <<<<<<<<<<<<<< * for k in range(hypos.size()): - * sentence = GetString(hypos[0][k].words).c_str() + * yield unicode(GetString(hypos[0][k].words).c_str(), 'utf8') */ /*try:*/ { @@ -4649,8 +5305,8 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject * cdef unsigned k * try: * for k in range(hypos.size()): # <<<<<<<<<<<<<< - * sentence = GetString(hypos[0][k].words).c_str() - * yield sentence.decode('utf8') + * yield unicode(GetString(hypos[0][k].words).c_str(), 'utf8') + * finally: */ __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) { @@ -4659,33 +5315,25 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":84 * try: * for k in range(hypos.size()): - * sentence = GetString(hypos[0][k].words).c_str() # <<<<<<<<<<<<<< - * yield sentence.decode('utf8') + * yield unicode(GetString(hypos[0][k].words).c_str(), 'utf8') # <<<<<<<<<<<<<< * finally: + * 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[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} __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[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence)); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_4)); __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); - __pyx_cur_scope->__pyx_v_sentence = ((PyObject*)__pyx_t_4); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":85 - * for k in range(hypos.size()): - * sentence = GetString(hypos[0][k].words).c_str() - * yield sentence.decode('utf8') # <<<<<<<<<<<<<< - * finally: - * 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[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L6;} + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L6;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; __Pyx_XGIVEREF(__pyx_r); @@ -4696,16 +5344,16 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject __pyx_L10_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[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L6;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} } } - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":87 - * yield sentence.decode('utf8') + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":86 + * yield unicode(GetString(hypos[0][k].words).c_str(), 'utf8') * finally: * del hypos # <<<<<<<<<<<<<< * - * # TODO richer k-best/sample output (feature vectors, trees?) + * def intersect(self, Lattice lat): */ /*finally:*/ { int __pyx_why; @@ -4715,8 +5363,8 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject __pyx_why = 0; goto __pyx_L7; __pyx_L6: { __pyx_why = 4; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); __pyx_exc_lineno = __pyx_lineno; goto __pyx_L7; @@ -4753,7 +5401,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_23intersect(PyObject *__pyx_v_self PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("intersect (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lat), __pyx_ptype_5_cdec_Lattice, 1, "lat", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lat), __pyx_ptype_5_cdec_Lattice, 1, "lat", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = __pyx_pf_5_cdec_10Hypergraph_22intersect(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_lat)); goto __pyx_L0; __pyx_L1_error:; @@ -4763,8 +5411,8 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_23intersect(PyObject *__pyx_v_self return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":91 - * # TODO richer k-best/sample output (feature vectors, trees?) +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":88 + * del hypos * * def intersect(self, Lattice lat): # <<<<<<<<<<<<<< * return hypergraph.Intersect(lat.lattice[0], self.hg) @@ -4780,7 +5428,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_22intersect(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("intersect", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":92 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":89 * * def intersect(self, Lattice lat): * return hypergraph.Intersect(lat.lattice[0], self.hg) # <<<<<<<<<<<<<< @@ -4788,7 +5436,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_22intersect(struct __pyx_obj_5_cde * def prune(self, beam_alpha=0, density=0, **kwargs): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(HG::Intersect((__pyx_v_lat->lattice[0]), __pyx_v_self->hg)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyBool_FromLong(HG::Intersect((__pyx_v_lat->lattice[0]), __pyx_v_self->hg)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -4845,7 +5493,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_25prune(PyObject *__pyx_v_self, Py } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "prune") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "prune") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -4860,7 +5508,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_25prune(PyObject *__pyx_v_self, Py } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("prune", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("prune", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; __Pyx_AddTraceback("_cdec.Hypergraph.prune", __pyx_clineno, __pyx_lineno, __pyx_filename); @@ -4873,7 +5521,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_25prune(PyObject *__pyx_v_self, Py return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":94 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":91 * return hypergraph.Intersect(lat.lattice[0], self.hg) * * def prune(self, beam_alpha=0, density=0, **kwargs): # <<<<<<<<<<<<<< @@ -4893,7 +5541,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_24prune(struct __pyx_obj_5_cdec_Hy int __pyx_clineno = 0; __Pyx_RefNannySetupContext("prune", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":95 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":92 * * def prune(self, beam_alpha=0, density=0, **kwargs): * cdef hypergraph.EdgeMask* preserve_mask = NULL # <<<<<<<<<<<<<< @@ -4902,17 +5550,17 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_24prune(struct __pyx_obj_5_cdec_Hy */ __pyx_v_preserve_mask = NULL; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":96 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":93 * def prune(self, beam_alpha=0, density=0, **kwargs): * cdef hypergraph.EdgeMask* preserve_mask = NULL * if 'csplit_preserve_full_word' in kwargs: # <<<<<<<<<<<<<< * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True */ - __pyx_t_1 = ((PyDict_Contains(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s_10)))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = ((PyDict_Contains(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s_6)))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":97 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":94 * cdef hypergraph.EdgeMask* preserve_mask = NULL * if 'csplit_preserve_full_word' in kwargs: * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) # <<<<<<<<<<<<<< @@ -4921,7 +5569,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_24prune(struct __pyx_obj_5_cdec_Hy */ __pyx_v_preserve_mask = new std::vector(__pyx_v_self->hg->edges_.size()); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":98 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":95 * if 'csplit_preserve_full_word' in kwargs: * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True # <<<<<<<<<<<<<< @@ -4933,18 +5581,18 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_24prune(struct __pyx_obj_5_cdec_Hy } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":99 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":96 * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) # <<<<<<<<<<<<<< * if preserve_mask: * del preserve_mask */ - __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_beam_alpha); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_density); if (unlikely((__pyx_t_3 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_beam_alpha); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_density); if (unlikely((__pyx_t_3 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->hg->PruneInsideOutside(__pyx_t_2, __pyx_t_3, __pyx_v_preserve_mask, 0, 1.0, 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":100 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":97 * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) * if preserve_mask: # <<<<<<<<<<<<<< @@ -4954,7 +5602,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_24prune(struct __pyx_obj_5_cdec_Hy __pyx_t_1 = (__pyx_v_preserve_mask != 0); if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":101 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":98 * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) * if preserve_mask: * del preserve_mask # <<<<<<<<<<<<<< @@ -4988,7 +5636,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_27lattice(PyObject *__pyx_v_self, return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":103 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":100 * del preserve_mask * * def lattice(self): # TODO direct hg -> lattice conversion in cdec # <<<<<<<<<<<<<< @@ -5008,20 +5656,20 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_26lattice(struct __pyx_obj_5_cdec_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("lattice", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":104 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":101 * * def lattice(self): # TODO direct hg -> lattice conversion in cdec * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() # <<<<<<<<<<<<<< * return Lattice(eval(plf)) * */ - __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->hg[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->hg[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 101; __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[2]; __pyx_lineno = 104; __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[2]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_plf = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":105 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":102 * def lattice(self): # TODO direct hg -> lattice conversion in cdec * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() * return Lattice(eval(plf)) # <<<<<<<<<<<<<< @@ -5029,17 +5677,17 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_26lattice(struct __pyx_obj_5_cdec_ * def reweight(self, weights): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_Globals(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_Globals(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); if (((PyObject *)__pyx_v_plf)) { - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__plf), ((PyObject *)__pyx_v_plf)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__plf), ((PyObject *)__pyx_v_plf)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } if (((PyObject *)__pyx_v_self)) { - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_v_self)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_v_self)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)__pyx_v_plf)); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_plf)); @@ -5050,15 +5698,15 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_26lattice(struct __pyx_obj_5_cdec_ __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); __pyx_t_1 = 0; __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_eval, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_builtin_eval, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; @@ -5091,7 +5739,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_29reweight(PyObject *__pyx_v_self, return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":107 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":104 * return Lattice(eval(plf)) * * def reweight(self, weights): # <<<<<<<<<<<<<< @@ -5110,7 +5758,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec int __pyx_clineno = 0; __Pyx_RefNannySetupContext("reweight", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":108 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":105 * * def reweight(self, weights): * if isinstance(weights, SparseVector): # <<<<<<<<<<<<<< @@ -5123,7 +5771,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":109 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":106 * def reweight(self, weights): * if isinstance(weights, SparseVector): * self.hg.Reweight(( weights).vector[0]) # <<<<<<<<<<<<<< @@ -5134,7 +5782,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec goto __pyx_L3; } - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":110 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":107 * if isinstance(weights, SparseVector): * self.hg.Reweight(( weights).vector[0]) * elif isinstance(weights, DenseVector): # <<<<<<<<<<<<<< @@ -5147,7 +5795,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":111 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":108 * self.hg.Reweight(( weights).vector[0]) * elif isinstance(weights, DenseVector): * self.hg.Reweight(( weights).vector[0]) # <<<<<<<<<<<<<< @@ -5159,26 +5807,26 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":113 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":110 * self.hg.Reweight(( weights).vector[0]) * else: * raise TypeError('cannot reweight hypergraph with %s' % type(weights)) # <<<<<<<<<<<<<< * * # TODO get feature expectations, get partition function ("inside" score) */ - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_7), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L3:; @@ -5194,797 +5842,587 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5_cdec_10Hypergraph_5edges_2generator6(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static int __pyx_pw_5_cdec_7Lattice_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5_cdec_7Lattice_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_inp = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__inp,0}; - int __pyx_r; +static PyObject *__pyx_pw_5_cdec_10Hypergraph_5edges_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_5edges_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); - { - PyObject* values[1] = {0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__inp); - 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, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 6; __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_inp = 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[3]; __pyx_lineno = 6; __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:; - __pyx_r = __pyx_pf_5_cdec_7Lattice___init__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), __pyx_v_inp); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_5edges___get__(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":6 - * cdef lattice.Lattice* lattice +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":115 * - * def __init__(self, inp): # <<<<<<<<<<<<<< - * if isinstance(inp, tuple): - * self.lattice = new lattice.Lattice(len(inp)) + * property edges: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.hg.edges_.size()): */ -static int __pyx_pf_5_cdec_7Lattice___init__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, PyObject *__pyx_v_inp) { - PyObject *__pyx_v_i = NULL; - PyObject *__pyx_v_arcs = NULL; - int __pyx_r; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_5edges___get__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *__pyx_cur_scope; + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - Py_ssize_t __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *(*__pyx_t_5)(PyObject *); - PyObject *__pyx_t_6 = NULL; - int __pyx_t_7; - char *__pyx_t_8; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_INCREF(__pyx_v_inp); + __Pyx_RefNannySetupContext("__get__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *)__pyx_ptype_5_cdec___pyx_scope_struct_6___get__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_6___get__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_5edges_2generator6, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":7 - * - * def __init__(self, inp): - * if isinstance(inp, tuple): # <<<<<<<<<<<<<< - * self.lattice = new lattice.Lattice(len(inp)) - * for i, arcs in enumerate(inp): - */ - __pyx_t_1 = ((PyObject *)((PyObject*)(&PyTuple_Type))); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_inp, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Hypergraph.edges.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":8 - * def __init__(self, inp): - * if isinstance(inp, tuple): - * self.lattice = new lattice.Lattice(len(inp)) # <<<<<<<<<<<<<< - * for i, arcs in enumerate(inp): - * self[i] = arcs +static PyObject *__pyx_gb_5_cdec_10Hypergraph_5edges_2generator6(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + size_t __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":117 + * def __get__(self): + * cdef unsigned i + * for i in range(self.hg.edges_.size()): # <<<<<<<<<<<<<< + * yield HypergraphEdge().init(self.hg, i) + * */ - __pyx_t_3 = PyObject_Length(__pyx_v_inp); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->lattice = new Lattice(__pyx_t_3); + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->hg->edges_.size(); + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":9 - * if isinstance(inp, tuple): - * self.lattice = new lattice.Lattice(len(inp)) - * for i, arcs in enumerate(inp): # <<<<<<<<<<<<<< - * self[i] = arcs - * else: + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":118 + * cdef unsigned i + * for i in range(self.hg.edges_.size()): + * yield HypergraphEdge().init(self.hg, i) # <<<<<<<<<<<<<< + * + * property nodes: */ - __Pyx_INCREF(__pyx_int_0); - __pyx_t_1 = __pyx_int_0; - if (PyList_CheckExact(__pyx_v_inp) || PyTuple_CheckExact(__pyx_v_inp)) { - __pyx_t_4 = __pyx_v_inp; __Pyx_INCREF(__pyx_t_4); __pyx_t_3 = 0; - __pyx_t_5 = NULL; - } else { - __pyx_t_3 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_inp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; - } - for (;;) { - if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_4)) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_4)) break; - __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; - } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_4)) { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; - } else { - __pyx_t_6 = __pyx_t_5(__pyx_t_4); - if (unlikely(!__pyx_t_6)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_6); - } - __Pyx_XDECREF(__pyx_v_arcs); - __pyx_v_arcs = __pyx_t_6; - __pyx_t_6 = 0; - __Pyx_INCREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_1; - __pyx_t_6 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); - __pyx_t_1 = __pyx_t_6; - __pyx_t_6 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":10 - * self.lattice = new lattice.Lattice(len(inp)) - * for i, arcs in enumerate(inp): - * self[i] = arcs # <<<<<<<<<<<<<< - * else: - * if isinstance(inp, unicode): - */ - if (PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_v_i, __pyx_v_arcs) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L3; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphEdge)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = ((struct __pyx_vtabstruct_5_cdec_HypergraphEdge *)((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_t_3)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_t_3), __pyx_cur_scope->__pyx_v_self->hg, __pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 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_generator->resume_label = 1; + return __pyx_r; + __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[2]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - /*else*/ { + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} +static PyObject *__pyx_gb_5_cdec_10Hypergraph_5nodes_2generator7(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":12 - * self[i] = arcs - * else: - * if isinstance(inp, unicode): # <<<<<<<<<<<<<< - * inp = inp.encode('utf8') - * if not isinstance(inp, str): - */ - __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_inp, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_5nodes_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_5nodes_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_5nodes___get__(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":13 - * else: - * if isinstance(inp, unicode): - * inp = inp.encode('utf8') # <<<<<<<<<<<<<< - * if not isinstance(inp, str): - * raise TypeError('Cannot create lattice from %s' % type(inp)) +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":121 + * + * property nodes: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.hg.nodes_.size()): */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_inp, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_12), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_v_inp); - __pyx_v_inp = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L6; - } - __pyx_L6:; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":14 - * if isinstance(inp, unicode): - * inp = inp.encode('utf8') - * if not isinstance(inp, str): # <<<<<<<<<<<<<< - * raise TypeError('Cannot create lattice from %s' % type(inp)) - * self.lattice = new lattice.Lattice() - */ - __pyx_t_4 = ((PyObject *)((PyObject*)(&PyString_Type))); - __Pyx_INCREF(__pyx_t_4); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_inp, __pyx_t_4); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_7 = (!__pyx_t_2); - if (__pyx_t_7) { +static PyObject *__pyx_pf_5_cdec_10Hypergraph_5nodes___get__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *)__pyx_ptype_5_cdec___pyx_scope_struct_7___get__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_7___get__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_5nodes_2generator7, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":15 - * inp = inp.encode('utf8') - * if not isinstance(inp, str): - * raise TypeError('Cannot create lattice from %s' % type(inp)) # <<<<<<<<<<<<<< - * self.lattice = new lattice.Lattice() - * lattice.ConvertTextToLattice(string(inp), self.lattice) - */ - __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_13), ((PyObject *)Py_TYPE(__pyx_v_inp))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); - __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L7; - } - __pyx_L7:; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Hypergraph.nodes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":16 - * if not isinstance(inp, str): - * raise TypeError('Cannot create lattice from %s' % type(inp)) - * self.lattice = new lattice.Lattice() # <<<<<<<<<<<<<< - * lattice.ConvertTextToLattice(string(inp), self.lattice) +static PyObject *__pyx_gb_5_cdec_10Hypergraph_5nodes_2generator7(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + size_t __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[2]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":123 + * def __get__(self): + * cdef unsigned i + * for i in range(self.hg.nodes_.size()): # <<<<<<<<<<<<<< + * yield HypergraphNode().init(self.hg, i) * */ - __pyx_v_self->lattice = new Lattice(); + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->hg->nodes_.size(); + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":17 - * raise TypeError('Cannot create lattice from %s' % type(inp)) - * self.lattice = new lattice.Lattice() - * lattice.ConvertTextToLattice(string(inp), self.lattice) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":124 + * cdef unsigned i + * for i in range(self.hg.nodes_.size()): + * yield HypergraphNode().init(self.hg, i) # <<<<<<<<<<<<<< * - * def __getitem__(self, int index): + * property goal: */ - __pyx_t_8 = PyBytes_AsString(__pyx_v_inp); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - LatticeTools::ConvertTextToLattice(std::string(((char *)__pyx_t_8)), __pyx_v_self->lattice); + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = ((struct __pyx_vtabstruct_5_cdec_HypergraphNode *)((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_3)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_3), __pyx_cur_scope->__pyx_v_self->hg, __pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 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_generator->resume_label = 1; + return __pyx_r; + __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[2]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_L3:; - - __pyx_r = 0; + PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("_cdec.Lattice.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_AddTraceback("__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XDECREF(__pyx_v_i); - __Pyx_XDECREF(__pyx_v_arcs); - __Pyx_XDECREF(__pyx_v_inp); + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return __pyx_r; + return NULL; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Lattice_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Lattice_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index) { - int __pyx_v_index; +static PyObject *__pyx_pw_5_cdec_10Hypergraph_4goal_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_4goal_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); - assert(__pyx_arg_index); { - __pyx_v_index = __Pyx_PyInt_AsInt(__pyx_arg_index); if (unlikely((__pyx_v_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.Lattice.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_7Lattice_2__getitem__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), ((int)__pyx_v_index)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_4goal___get__(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":19 - * lattice.ConvertTextToLattice(string(inp), self.lattice) +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":127 + * + * property goal: + * def __get__(self): # <<<<<<<<<<<<<< + * return HypergraphNode().init(self.hg, self.hg.GoalNode()) * - * def __getitem__(self, int index): # <<<<<<<<<<<<<< - * if not 0 <= index < len(self): - * raise IndexError('lattice index out of range') */ -static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index) { - PyObject *__pyx_v_arcs = NULL; - std::vector __pyx_v_arc_vector; - LatticeArc *__pyx_v_arc; - PyObject *__pyx_v_label = 0; - unsigned int __pyx_v_i; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_4goal___get__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - int __pyx_t_1; - Py_ssize_t __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - size_t __pyx_t_5; - unsigned int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - int __pyx_t_10; + 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("__getitem__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":20 - * - * def __getitem__(self, int index): - * if not 0 <= index < len(self): # <<<<<<<<<<<<<< - * raise IndexError('lattice index out of range') - * arcs = [] - */ - __pyx_t_1 = (0 <= __pyx_v_index); - if (__pyx_t_1) { - __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = (__pyx_v_index < __pyx_t_2); - } - __pyx_t_3 = (!__pyx_t_1); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":21 - * def __getitem__(self, int index): - * if not 0 <= index < len(self): - * raise IndexError('lattice index out of range') # <<<<<<<<<<<<<< - * arcs = [] - * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] - */ - __pyx_t_4 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_15), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":22 - * if not 0 <= index < len(self): - * raise IndexError('lattice index out of range') - * arcs = [] # <<<<<<<<<<<<<< - * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] - * cdef lattice.LatticeArc* arc - */ - __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_v_arcs = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":23 - * raise IndexError('lattice index out of range') - * arcs = [] - * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] # <<<<<<<<<<<<<< - * cdef lattice.LatticeArc* arc - * cdef str label - */ - __pyx_v_arc_vector = ((__pyx_v_self->lattice[0])[__pyx_v_index]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":27 - * cdef str label - * cdef unsigned i - * for i in range(arc_vector.size()): # <<<<<<<<<<<<<< - * arc = &arc_vector[i] - * label = TDConvert(arc.label) - */ - __pyx_t_5 = __pyx_v_arc_vector.size(); - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_v_i = __pyx_t_6; - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":28 - * cdef unsigned i - * for i in range(arc_vector.size()): - * arc = &arc_vector[i] # <<<<<<<<<<<<<< - * label = TDConvert(arc.label) - * arcs.append((label.decode('utf8'), arc.cost, arc.dist2next)) - */ - __pyx_v_arc = (&(__pyx_v_arc_vector[__pyx_v_i])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":29 - * for i in range(arc_vector.size()): - * arc = &arc_vector[i] - * label = TDConvert(arc.label) # <<<<<<<<<<<<<< - * arcs.append((label.decode('utf8'), arc.cost, arc.dist2next)) - * return tuple(arcs) - */ - __pyx_t_4 = PyBytes_FromString(TD::Convert(__pyx_v_arc->label)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 29; __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[3]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XDECREF(((PyObject *)__pyx_v_label)); - __pyx_v_label = ((PyObject*)__pyx_t_4); - __pyx_t_4 = 0; + __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":30 - * arc = &arc_vector[i] - * label = TDConvert(arc.label) - * arcs.append((label.decode('utf8'), arc.cost, arc.dist2next)) # <<<<<<<<<<<<<< - * return tuple(arcs) + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":128 + * property goal: + * def __get__(self): + * return HypergraphNode().init(self.hg, self.hg.GoalNode()) # <<<<<<<<<<<<<< * - */ - __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_label), __pyx_n_s__decode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_16), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyFloat_FromDouble(__pyx_v_arc->cost); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = PyInt_FromLong(__pyx_v_arc->dist2next); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - __pyx_t_7 = 0; - __pyx_t_4 = 0; - __pyx_t_8 = 0; - __pyx_t_10 = PyList_Append(__pyx_v_arcs, ((PyObject *)__pyx_t_9)); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":31 - * label = TDConvert(arc.label) - * arcs.append((label.decode('utf8'), arc.cost, arc.dist2next)) - * return tuple(arcs) # <<<<<<<<<<<<<< * - * def __setitem__(self, int index, tuple arcs): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_9 = ((PyObject *)PyList_AsTuple(__pyx_v_arcs)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_9)); - __pyx_r = ((PyObject *)__pyx_t_9); - __pyx_t_9 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = ((struct __pyx_vtabstruct_5_cdec_HypergraphNode *)((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_1)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_1), __pyx_v_self->hg, __pyx_v_self->hg->GoalNode()); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 128; __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_4); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("_cdec.Lattice.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec.Hypergraph.goal.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_arcs); - __Pyx_XDECREF(__pyx_v_label); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static int __pyx_pw_5_cdec_7Lattice_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index, PyObject *__pyx_v_arcs); /*proto*/ -static int __pyx_pw_5_cdec_7Lattice_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index, PyObject *__pyx_v_arcs) { - int __pyx_v_index; - int __pyx_r; +static PyObject *__pyx_pw_5_cdec_1_phrase(PyObject *__pyx_self, PyObject *__pyx_v_phrase); /*proto*/ +static PyMethodDef __pyx_mdef_5_cdec_1_phrase = {__Pyx_NAMESTR("_phrase"), (PyCFunction)__pyx_pw_5_cdec_1_phrase, METH_O, __Pyx_DOCSTR(0)}; +static PyObject *__pyx_pw_5_cdec_1_phrase(PyObject *__pyx_self, PyObject *__pyx_v_phrase) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); - assert(__pyx_arg_index); { - __pyx_v_index = __Pyx_PyInt_AsInt(__pyx_arg_index); if (unlikely((__pyx_v_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.Lattice.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_arcs), (&PyTuple_Type), 1, "arcs", 1))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_7Lattice_4__setitem__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), ((int)__pyx_v_index), ((PyObject*)__pyx_v_arcs)); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = -1; - __pyx_L0:; + __Pyx_RefNannySetupContext("_phrase (wrapper)", 0); + __pyx_self = __pyx_self; + __pyx_r = __pyx_pf_5_cdec__phrase(__pyx_self, ((PyObject *)__pyx_v_phrase)); __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5_cdec_7_phrase_2generator15(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":33 - * return tuple(arcs) +/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":2 + * def _phrase(phrase): + * return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) # <<<<<<<<<<<<<< * - * def __setitem__(self, int index, tuple arcs): # <<<<<<<<<<<<<< - * if not 0 <= index < len(self): - * raise IndexError('lattice index out of range') + * cdef class TRule: */ -static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index, PyObject *__pyx_v_arcs) { - LatticeArc *__pyx_v_arc; - PyObject *__pyx_v_label = NULL; - PyObject *__pyx_v_cost = NULL; - PyObject *__pyx_v_dist2next = NULL; - int __pyx_r; +static PyObject *__pyx_pf_5_cdec_7_phrase_genexpr(PyObject *__pyx_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *__pyx_cur_scope; + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - int __pyx_t_1; - Py_ssize_t __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *(*__pyx_t_10)(PyObject *); - char *__pyx_t_11; - double __pyx_t_12; - int __pyx_t_13; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__setitem__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":34 - * - * def __setitem__(self, int index, tuple arcs): - * if not 0 <= index < len(self): # <<<<<<<<<<<<<< - * raise IndexError('lattice index out of range') - * cdef lattice.LatticeArc* arc - */ - __pyx_t_1 = (0 <= __pyx_v_index); - if (__pyx_t_1) { - __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = (__pyx_v_index < __pyx_t_2); + __Pyx_RefNannySetupContext("genexpr", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *)__pyx_ptype_5_cdec___pyx_scope_struct_9_genexpr->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_9_genexpr, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; } - __pyx_t_3 = (!__pyx_t_1); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":35 - * def __setitem__(self, int index, tuple arcs): - * if not 0 <= index < len(self): - * raise IndexError('lattice index out of range') # <<<<<<<<<<<<<< - * cdef lattice.LatticeArc* arc - * for (label, cost, dist2next) in arcs: - */ - __pyx_t_4 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_17), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *) __pyx_self; + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7_phrase_2generator15, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; } - __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":37 - * raise IndexError('lattice index out of range') - * cdef lattice.LatticeArc* arc - * for (label, cost, dist2next) in arcs: # <<<<<<<<<<<<<< - * if isinstance(label, unicode): - * label = label.encode('utf8') - */ - if (unlikely(((PyObject *)__pyx_v_arcs) == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec._phrase.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5_cdec_7_phrase_2generator15(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase)) { __Pyx_RaiseClosureNameError("phrase"); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } + if (PyList_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase)) { + __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; } - __pyx_t_4 = ((PyObject *)__pyx_v_arcs); __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0; for (;;) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; - if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) { - PyObject* sequence = __pyx_t_5; - if (likely(PyTuple_CheckExact(sequence))) { - if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { - if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 2); - } else { - if (unlikely(PyList_GET_SIZE(sequence) != 3)) { - if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_6 = PyList_GET_ITEM(sequence, 0); - __pyx_t_7 = PyList_GET_ITEM(sequence, 1); - __pyx_t_8 = PyList_GET_ITEM(sequence, 2); + break; } - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_9 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; - index = 0; __pyx_t_6 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_6); - index = 1; __pyx_t_7 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - index = 2; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_8); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L7_unpacking_done; - __pyx_L6_unpacking_failed:; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L7_unpacking_done:; + __Pyx_GOTREF(__pyx_t_4); } - __Pyx_XDECREF(__pyx_v_label); - __pyx_v_label = __pyx_t_6; - __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_v_cost); - __pyx_v_cost = __pyx_t_7; - __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_v_dist2next); - __pyx_v_dist2next = __pyx_t_8; - __pyx_t_8 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":38 - * cdef lattice.LatticeArc* arc - * for (label, cost, dist2next) in arcs: - * if isinstance(label, unicode): # <<<<<<<<<<<<<< - * label = label.encode('utf8') - * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) - */ - __pyx_t_5 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_w); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_w); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_cur_scope->__pyx_v_w = __pyx_t_4; + __pyx_t_4 = 0; + __pyx_t_5 = ((PyObject *)((PyObject*)(&PyTuple_Type))); __Pyx_INCREF(__pyx_t_5); - __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_label, __pyx_t_5); + __pyx_t_6 = __Pyx_TypeCheck(__pyx_cur_scope->__pyx_v_w, __pyx_t_5); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":39 - * for (label, cost, dist2next) in arcs: - * if isinstance(label, unicode): - * label = label.encode('utf8') # <<<<<<<<<<<<<< - * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) - * self.lattice[0][index].push_back(arc[0]) - */ - __pyx_t_5 = PyObject_GetAttr(__pyx_v_label, __pyx_n_s__encode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_6) { + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_8), __pyx_cur_scope->__pyx_v_w); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __pyx_t_4 = ((PyObject *)__pyx_t_5); + __pyx_t_5 = 0; + } else { + __pyx_t_5 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_w, __pyx_n_s__encode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_18), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_v_label); - __pyx_v_label = __pyx_t_8; - __pyx_t_8 = 0; - goto __pyx_L8; + __pyx_t_4 = __pyx_t_7; + __pyx_t_7 = 0; } - __pyx_L8:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":40 - * if isinstance(label, unicode): - * label = label.encode('utf8') - * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) # <<<<<<<<<<<<<< - * self.lattice[0][index].push_back(arc[0]) - * del arc - */ - __pyx_t_11 = PyBytes_AsString(__pyx_v_label); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_v_cost); if (unlikely((__pyx_t_12 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_v_dist2next); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_arc = new LatticeArc(TD::Convert(((char *)__pyx_t_11)), __pyx_t_12, __pyx_t_13); - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":41 - * label = label.encode('utf8') - * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) - * self.lattice[0][index].push_back(arc[0]) # <<<<<<<<<<<<<< - * del arc - * - */ - ((__pyx_v_self->lattice[0])[__pyx_v_index]).push_back((__pyx_v_arc[0])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":42 - * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) - * self.lattice[0][index].push_back(arc[0]) - * del arc # <<<<<<<<<<<<<< - * - * def __len__(self): - */ - delete __pyx_v_arc; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - __pyx_r = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("_cdec.Lattice.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XDECREF(__pyx_v_label); - __Pyx_XDECREF(__pyx_v_cost); - __Pyx_XDECREF(__pyx_v_dist2next); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static Py_ssize_t __pyx_pw_5_cdec_7Lattice_7__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_5_cdec_7Lattice_7__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Lattice_6__len__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return __pyx_r; + return NULL; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":44 - * del arc - * - * def __len__(self): # <<<<<<<<<<<<<< - * return self.lattice.size() +/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":1 + * def _phrase(phrase): # <<<<<<<<<<<<<< + * return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) * */ -static Py_ssize_t __pyx_pf_5_cdec_7Lattice_6__len__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { - Py_ssize_t __pyx_r; +static PyObject *__pyx_pf_5_cdec__phrase(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_phrase) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *__pyx_cur_scope; + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__", 0); + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_phrase", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *)__pyx_ptype_5_cdec___pyx_scope_struct_8__phrase->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_8__phrase, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_phrase = __pyx_v_phrase; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_phrase); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_phrase); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":45 + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":2 + * def _phrase(phrase): + * return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) # <<<<<<<<<<<<<< * - * def __len__(self): - * return self.lattice.size() # <<<<<<<<<<<<<< - * - * def __str__(self): + * cdef class TRule: */ - __pyx_r = __pyx_v_self->lattice->size(); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_10), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_pf_5_cdec_7_phrase_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; - __pyx_r = 0; + __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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec._phrase", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Lattice_9__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Lattice_9__str__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_5TRule_5arity_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_5TRule_5arity_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Lattice_8__str__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_5TRule_5arity___get__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":47 - * return self.lattice.size() +/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":8 * - * def __str__(self): # <<<<<<<<<<<<<< - * return hypergraph.AsPLF(self.lattice[0], True).c_str() + * property arity: + * def __get__(self): # <<<<<<<<<<<<<< + * return self.rule.arity_ * */ -static PyObject *__pyx_pf_5_cdec_7Lattice_8__str__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_5TRule_5arity___get__(struct __pyx_obj_5_cdec_TRule *__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__", 0); + __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":48 - * - * def __str__(self): - * return hypergraph.AsPLF(self.lattice[0], True).c_str() # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":9 + * property arity: + * def __get__(self): + * return self.rule.arity_ # <<<<<<<<<<<<<< * - * def __iter__(self): + * property f: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->lattice[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_r = ((PyObject *)__pyx_t_1); + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->rule->arity_); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; @@ -5992,220 +6430,561 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_8__str__(struct __pyx_obj_5_cdec_Latti goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.Lattice.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.TRule.arity.__get__", __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_7Lattice_12generator6(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Lattice_11__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Lattice_11__iter__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_5TRule_1f_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_5TRule_1f_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Lattice_10__iter__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_5TRule_1f___get__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":50 - * return hypergraph.AsPLF(self.lattice[0], True).c_str() +/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":12 * - * def __iter__(self): # <<<<<<<<<<<<<< - * cdef unsigned i - * for i in range(len(self)): + * property f: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef vector[WordID]* f = &self.rule.f_ + * cdef WordID w */ -static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_5TRule_1f___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self) { + std::vector *__pyx_v_f; + WordID __pyx_v_w; + PyObject *__pyx_v_words = 0; + unsigned int __pyx_v_i; + int __pyx_v_idx; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + size_t __pyx_t_2; + unsigned int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__iter__", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_6___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_6___iter__, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Lattice_12generator6, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } + __Pyx_RefNannySetupContext("__get__", 0); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Lattice.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":13 + * property f: + * def __get__(self): + * cdef vector[WordID]* f = &self.rule.f_ # <<<<<<<<<<<<<< + * cdef WordID w + * cdef words = [] + */ + __pyx_v_f = (&__pyx_v_self->rule->f_); -static PyObject *__pyx_gb_5_cdec_7Lattice_12generator6(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - Py_ssize_t __pyx_t_1; - unsigned int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("None", 0); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_resume_from_yield; - default: /* CPython raises the right error here */ - __Pyx_RefNannyFinishContext(); - return NULL; + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":15 + * cdef vector[WordID]* f = &self.rule.f_ + * cdef WordID w + * cdef words = [] # <<<<<<<<<<<<<< + * cdef unsigned i + * cdef int idx = 0 + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_words = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":17 + * cdef words = [] + * cdef unsigned i + * cdef int idx = 0 # <<<<<<<<<<<<<< + * for i in range(f.size()): + * w = f[0][i] + */ + __pyx_v_idx = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":18 + * cdef unsigned i + * cdef int idx = 0 + * for i in range(f.size()): # <<<<<<<<<<<<<< + * w = f[0][i] + * if w < 0: + */ + __pyx_t_2 = __pyx_v_f->size(); + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":19 + * cdef int idx = 0 + * for i in range(f.size()): + * w = f[0][i] # <<<<<<<<<<<<<< + * if w < 0: + * idx += 1 + */ + __pyx_v_w = ((__pyx_v_f[0])[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":20 + * for i in range(f.size()): + * w = f[0][i] + * if w < 0: # <<<<<<<<<<<<<< + * idx += 1 + * words.append((TDConvert(-w), idx)) + */ + __pyx_t_4 = (__pyx_v_w < 0); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":21 + * w = f[0][i] + * if w < 0: + * idx += 1 # <<<<<<<<<<<<<< + * words.append((TDConvert(-w), idx)) + * else: + */ + __pyx_v_idx = (__pyx_v_idx + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":22 + * if w < 0: + * idx += 1 + * words.append((TDConvert(-w), idx)) # <<<<<<<<<<<<<< + * else: + * words.append(unicode(TDConvert(w), encoding='utf8')) + */ + __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_w))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_5 = PyInt_FromLong(__pyx_v_idx); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_1 = 0; + __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_words, ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":24 + * words.append((TDConvert(-w), idx)) + * else: + * words.append(unicode(TDConvert(w), encoding='utf8')) # <<<<<<<<<<<<<< + * return words + * + */ + __pyx_t_5 = PyBytes_FromString(TD::Convert(__pyx_v_w)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); + __pyx_t_5 = 0; + __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__encoding), ((PyObject *)__pyx_n_s__utf8)) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_6), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_words, __pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __pyx_L5:; } - __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":52 - * def __iter__(self): - * cdef unsigned i - * for i in range(len(self)): # <<<<<<<<<<<<<< - * yield self[i] + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":25 + * else: + * words.append(unicode(TDConvert(w), encoding='utf8')) + * return words # <<<<<<<<<<<<<< * + * property e: */ - __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_words); + __pyx_r = __pyx_v_words; + goto __pyx_L0; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":53 - * cdef unsigned i - * for i in range(len(self)): - * yield self[i] # <<<<<<<<<<<<<< + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_cdec.TRule.f.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_words); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_5TRule_1e_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_5TRule_1e_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_5TRule_1e___get__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":28 * - * def __dealloc__(self): + * property e: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef vector[WordID]* e = &self.rule.e_ + * cdef WordID w */ - __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 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_generator->resume_label = 1; - return __pyx_r; - __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[3]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + +static PyObject *__pyx_pf_5_cdec_5TRule_1e___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self) { + std::vector *__pyx_v_e; + WordID __pyx_v_w; + PyObject *__pyx_v_words = 0; + unsigned int __pyx_v_i; + int __pyx_v_idx; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + size_t __pyx_t_2; + unsigned int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":29 + * property e: + * def __get__(self): + * cdef vector[WordID]* e = &self.rule.e_ # <<<<<<<<<<<<<< + * cdef WordID w + * cdef words = [] + */ + __pyx_v_e = (&__pyx_v_self->rule->e_); + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":31 + * cdef vector[WordID]* e = &self.rule.e_ + * cdef WordID w + * cdef words = [] # <<<<<<<<<<<<<< + * cdef unsigned i + * cdef int idx = 0 + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_words = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":33 + * cdef words = [] + * cdef unsigned i + * cdef int idx = 0 # <<<<<<<<<<<<<< + * for i in range(e.size()): + * w = e[0][i] + */ + __pyx_v_idx = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":34 + * cdef unsigned i + * cdef int idx = 0 + * for i in range(e.size()): # <<<<<<<<<<<<<< + * w = e[0][i] + * if w < 1: + */ + __pyx_t_2 = __pyx_v_e->size(); + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":35 + * cdef int idx = 0 + * for i in range(e.size()): + * w = e[0][i] # <<<<<<<<<<<<<< + * if w < 1: + * idx += 1 + */ + __pyx_v_w = ((__pyx_v_e[0])[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":36 + * for i in range(e.size()): + * w = e[0][i] + * if w < 1: # <<<<<<<<<<<<<< + * idx += 1 + * words.append((TDConvert(1-w), idx)) + */ + __pyx_t_4 = (__pyx_v_w < 1); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":37 + * w = e[0][i] + * if w < 1: + * idx += 1 # <<<<<<<<<<<<<< + * words.append((TDConvert(1-w), idx)) + * else: + */ + __pyx_v_idx = (__pyx_v_idx + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":38 + * if w < 1: + * idx += 1 + * words.append((TDConvert(1-w), idx)) # <<<<<<<<<<<<<< + * else: + * words.append(unicode(TDConvert(w), encoding='utf8')) + */ + __pyx_t_1 = PyBytes_FromString(TD::Convert((1 - __pyx_v_w))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_5 = PyInt_FromLong(__pyx_v_idx); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_1 = 0; + __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_words, ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":40 + * words.append((TDConvert(1-w), idx)) + * else: + * words.append(unicode(TDConvert(w), encoding='utf8')) # <<<<<<<<<<<<<< + * return words + * + */ + __pyx_t_5 = PyBytes_FromString(TD::Convert(__pyx_v_w)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); + __pyx_t_5 = 0; + __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__encoding), ((PyObject *)__pyx_n_s__utf8)) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_6), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_words, __pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __pyx_L5:; } - PyErr_SetNone(PyExc_StopIteration); + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":41 + * else: + * words.append(unicode(TDConvert(w), encoding='utf8')) + * return words # <<<<<<<<<<<<<< + * + * property scores: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_words); + __pyx_r = __pyx_v_words; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_cdec.TRule.e.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; + __Pyx_XDECREF(__pyx_v_words); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); - return NULL; + return __pyx_r; } /* Python wrapper */ -static void __pyx_pw_5_cdec_7Lattice_14__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_7Lattice_14__dealloc__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_5TRule_6scores_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_5TRule_6scores_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_7Lattice_13__dealloc__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_5TRule_6scores___get__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":55 - * yield self[i] - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.lattice +/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":44 * + * property scores: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef SparseVector scores = SparseVector() + * scores.vector = new FastSparseVector[double](self.rule.scores_) */ -static void __pyx_pf_5_cdec_7Lattice_13__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_5TRule_6scores___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_scores = 0; + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":45 + * property scores: + * def __get__(self): + * cdef SparseVector scores = SparseVector() # <<<<<<<<<<<<<< + * scores.vector = new FastSparseVector[double](self.rule.scores_) + * return scores + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_scores = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":56 + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":46 + * def __get__(self): + * cdef SparseVector scores = SparseVector() + * scores.vector = new FastSparseVector[double](self.rule.scores_) # <<<<<<<<<<<<<< + * return scores * - * def __dealloc__(self): - * del self.lattice # <<<<<<<<<<<<<< + */ + __pyx_v_scores->vector = new FastSparseVector(__pyx_v_self->rule->scores_); + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":47 + * cdef SparseVector scores = SparseVector() + * scores.vector = new FastSparseVector[double](self.rule.scores_) + * return scores # <<<<<<<<<<<<<< * - * def todot(self): + * property lhs: */ - delete __pyx_v_self->lattice; + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_scores)); + __pyx_r = ((PyObject *)__pyx_v_scores); + 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.TRule.scores.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_scores); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); + return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Lattice_16todot(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Lattice_16todot(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5_cdec_5TRule_3lhs_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_5TRule_3lhs_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("todot (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Lattice_15todot(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_5TRule_3lhs___get__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":50 + * + * property lhs: + * def __get__(self): # <<<<<<<<<<<<<< + * return TDConvert(-self.rule.lhs_) + * + */ + +static PyObject *__pyx_pf_5_cdec_5TRule_3lhs___get__(struct __pyx_obj_5_cdec_TRule *__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("__get__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":51 + * property lhs: + * def __get__(self): + * return TDConvert(-self.rule.lhs_) # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_self->rule->lhs_))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 51; __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.TRule.lhs.__get__", __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_7Lattice_5todot_2generator9(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Lattice_5todot_1lines(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyMethodDef __pyx_mdef_5_cdec_7Lattice_5todot_1lines = {__Pyx_NAMESTR("lines"), (PyCFunction)__pyx_pw_5_cdec_7Lattice_5todot_1lines, METH_NOARGS, __Pyx_DOCSTR(0)}; -static PyObject *__pyx_pw_5_cdec_7Lattice_5todot_1lines(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5_cdec_5TRule_1__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_5TRule_1__str__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("lines (wrapper)", 0); - __pyx_self = __pyx_self; - __pyx_r = __pyx_pf_5_cdec_7Lattice_5todot_lines(__pyx_self); + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_5TRule___str__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5_cdec_5TRule_7__str___2generator16(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":59 +/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":54 * - * def todot(self): - * def lines(): # <<<<<<<<<<<<<< - * yield 'digraph lattice {' - * yield 'rankdir = LR;' + * def __str__(self): + * scores = ' '.join('%s=%s' % feat for feat in self.scores) # <<<<<<<<<<<<<< + * return '[%s] ||| %s ||| %s ||| %s' % (self.lhs, _phrase(self.f), _phrase(self.e), scores) */ -static PyObject *__pyx_pf_5_cdec_7Lattice_5todot_lines(PyObject *__pyx_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_5TRule_7__str___genexpr(PyObject *__pyx_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("lines", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *)__pyx_ptype_5_cdec___pyx_scope_struct_8_lines->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_8_lines, __pyx_empty_tuple, NULL); + __Pyx_RefNannySetupContext("genexpr", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *)__pyx_ptype_5_cdec___pyx_scope_struct_11_genexpr->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_11_genexpr, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; } __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *) __Pyx_CyFunction_GetClosure(__pyx_self); + __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *) __pyx_self; __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Lattice_5todot_2generator9, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_5TRule_7__str___2generator16, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -6214,7 +6993,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_5todot_lines(PyObject *__pyx_self) { __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Lattice.todot.lines", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.TRule.__str__.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); @@ -6223,432 +7002,202 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_5todot_lines(PyObject *__pyx_self) { return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_7Lattice_5todot_2generator9(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_5TRule_7__str___2generator16(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *)__pyx_generator->closure); + struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *)__pyx_generator->closure); PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; PyObject *(*__pyx_t_4)(PyObject *); - PyObject *__pyx_t_5 = NULL; - Py_ssize_t __pyx_t_6; - PyObject *(*__pyx_t_7)(PyObject *); - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *(*__pyx_t_12)(PyObject *); __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L4_resume_from_yield; - case 2: goto __pyx_L5_resume_from_yield; - case 3: goto __pyx_L6_resume_from_yield; - case 4: goto __pyx_L13_resume_from_yield; - case 5: goto __pyx_L14_resume_from_yield; - case 6: goto __pyx_L15_resume_from_yield; + case 1: goto __pyx_L6_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[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":60 - * def todot(self): - * def lines(): - * yield 'digraph lattice {' # <<<<<<<<<<<<<< - * yield 'rankdir = LR;' - * yield 'node [shape=circle];' - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_19)); - __pyx_r = ((PyObject *)__pyx_kp_s_19); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L4_resume_from_yield:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":61 - * def lines(): - * yield 'digraph lattice {' - * yield 'rankdir = LR;' # <<<<<<<<<<<<<< - * yield 'node [shape=circle];' - * for i in range(len(self)): - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_20)); - __pyx_r = ((PyObject *)__pyx_kp_s_20); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 2; - return __pyx_r; - __pyx_L5_resume_from_yield:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":62 - * yield 'digraph lattice {' - * yield 'rankdir = LR;' - * yield 'node [shape=circle];' # <<<<<<<<<<<<<< - * for i in range(len(self)): - * for label, weight, delta in self[i]: - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_21)); - __pyx_r = ((PyObject *)__pyx_kp_s_21); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 3; - return __pyx_r; - __pyx_L6_resume_from_yield:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":63 - * yield 'rankdir = LR;' - * yield 'node [shape=circle];' - * for i in range(len(self)): # <<<<<<<<<<<<<< - * for label, weight, delta in self[i]: - * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) - */ - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self), __pyx_n_s__scores); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = 0; + __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; __pyx_t_4 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; + __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; for (;;) { - if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_3)) break; - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; - } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; } else { - __pyx_t_1 = __pyx_t_4(__pyx_t_3); + __pyx_t_1 = __pyx_t_4(__pyx_t_2); if (unlikely(!__pyx_t_1)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } __Pyx_GOTREF(__pyx_t_1); } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_i); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_i); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_feat); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_feat); __Pyx_GIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_v_i = __pyx_t_1; + __pyx_cur_scope->__pyx_v_feat = __pyx_t_1; + __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), __pyx_cur_scope->__pyx_v_feat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XGIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_2); + __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":64 - * yield 'node [shape=circle];' - * for i in range(len(self)): - * for label, weight, delta in self[i]: # <<<<<<<<<<<<<< - * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) - * yield '%d [shape=doublecircle]' % len(self) +/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":53 + * return TDConvert(-self.rule.lhs_) + * + * def __str__(self): # <<<<<<<<<<<<<< + * scores = ' '.join('%s=%s' % feat for feat in self.scores) + * return '[%s] ||| %s ||| %s ||| %s' % (self.lhs, _phrase(self.f), _phrase(self.e), scores) */ - __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_5 = __pyx_t_1; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; - __pyx_t_7 = NULL; - } else { - __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_5)) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break; - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; - } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_5)) { - if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break; - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; - } else { - __pyx_t_1 = __pyx_t_7(__pyx_t_5); - if (unlikely(!__pyx_t_1)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { - PyObject* sequence = __pyx_t_1; - if (likely(PyTuple_CheckExact(sequence))) { - if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { - if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); - } else { - if (unlikely(PyList_GET_SIZE(sequence) != 3)) { - if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_8 = PyList_GET_ITEM(sequence, 0); - __pyx_t_9 = PyList_GET_ITEM(sequence, 1); - __pyx_t_10 = PyList_GET_ITEM(sequence, 2); - } - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_11 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; - index = 0; __pyx_t_8 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_8)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_8); - index = 1; __pyx_t_9 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_9)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_9); - index = 2; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_10); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - goto __pyx_L12_unpacking_done; - __pyx_L11_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[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L12_unpacking_done:; - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_label); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_label); - __Pyx_GIVEREF(__pyx_t_8); - __pyx_cur_scope->__pyx_v_label = __pyx_t_8; - __pyx_t_8 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_weight); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_weight); - __Pyx_GIVEREF(__pyx_t_9); - __pyx_cur_scope->__pyx_v_weight = __pyx_t_9; - __pyx_t_9 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_delta); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_delta); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_cur_scope->__pyx_v_delta = __pyx_t_10; - __pyx_t_10 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":65 - * for i in range(len(self)): - * for label, weight, delta in self[i]: - * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) # <<<<<<<<<<<<<< - * yield '%d [shape=doublecircle]' % len(self) - * yield '}' - */ - __pyx_t_1 = PyNumber_Add(__pyx_cur_scope->__pyx_v_i, __pyx_cur_scope->__pyx_v_delta); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_label, __pyx_n_s__replace); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_9 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_i); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_cur_scope->__pyx_v_i); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_i); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - __pyx_t_1 = 0; - __pyx_t_9 = 0; - __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_22), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_9)); - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __pyx_r = ((PyObject *)__pyx_t_9); - __pyx_t_9 = 0; - __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; - __Pyx_XGIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; - __Pyx_XGIVEREF(__pyx_t_5); - __pyx_cur_scope->__pyx_t_3 = __pyx_t_5; - __pyx_cur_scope->__pyx_t_4 = __pyx_t_6; - __pyx_cur_scope->__pyx_t_5 = __pyx_t_7; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 4; - return __pyx_r; - __pyx_L13_resume_from_yield:; - __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; - __pyx_cur_scope->__pyx_t_1 = 0; - __Pyx_XGOTREF(__pyx_t_3); - __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; - __pyx_t_5 = __pyx_cur_scope->__pyx_t_3; - __pyx_cur_scope->__pyx_t_3 = 0; - __Pyx_XGOTREF(__pyx_t_5); - __pyx_t_6 = __pyx_cur_scope->__pyx_t_4; - __pyx_t_7 = __pyx_cur_scope->__pyx_t_5; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":66 - * for label, weight, delta in self[i]: - * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) - * yield '%d [shape=doublecircle]' % len(self) # <<<<<<<<<<<<<< - * yield '}' - * return '\n'.join(lines()).encode('utf8') - */ - __pyx_t_3 = ((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self); - __Pyx_INCREF(__pyx_t_3); - __pyx_t_2 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_26), __pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = ((PyObject *)__pyx_t_5); - __pyx_t_5 = 0; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 5; - return __pyx_r; - __pyx_L14_resume_from_yield:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":67 - * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) - * yield '%d [shape=doublecircle]' % len(self) - * yield '}' # <<<<<<<<<<<<<< - * return '\n'.join(lines()).encode('utf8') - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_27)); - __pyx_r = ((PyObject *)__pyx_kp_s_27); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 6; - return __pyx_r; - __pyx_L15_resume_from_yield:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_AddTraceback("lines", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; - __Pyx_RefNannyFinishContext(); - return NULL; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":58 - * del self.lattice - * - * def todot(self): # <<<<<<<<<<<<<< - * def lines(): - * yield 'digraph lattice {' - */ - -static PyObject *__pyx_pf_5_cdec_7Lattice_15todot(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *__pyx_cur_scope; - PyObject *__pyx_v_lines = 0; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("todot", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *)__pyx_ptype_5_cdec___pyx_scope_struct_7_todot->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_7_todot, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; +static PyObject *__pyx_pf_5_cdec_5TRule___str__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *__pyx_cur_scope; + PyObject *__pyx_v_scores = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__str__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *)__pyx_ptype_5_cdec___pyx_scope_struct_10___str__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_10___str__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; } __Pyx_GOTREF(__pyx_cur_scope); __pyx_cur_scope->__pyx_v_self = __pyx_v_self; __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":59 + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":54 * - * def todot(self): - * def lines(): # <<<<<<<<<<<<<< - * yield 'digraph lattice {' - * yield 'rankdir = LR;' - */ - __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5_cdec_7Lattice_5todot_1lines, 0, ((PyObject*)__pyx_cur_scope), __pyx_n_s___cdec, ((PyObject *)__pyx_k_codeobj_29)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_lines = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":68 - * yield '%d [shape=doublecircle]' % len(self) - * yield '}' - * return '\n'.join(lines()).encode('utf8') # <<<<<<<<<<<<<< + * def __str__(self): + * scores = ' '.join('%s=%s' % feat for feat in self.scores) # <<<<<<<<<<<<<< + * return '[%s] ||| %s ||| %s ||| %s' % (self.lhs, _phrase(self.f), _phrase(self.e), scores) */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_31), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_10), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_v_lines, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __pyx_pf_5_cdec_5TRule_7__str___genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_32), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_scores = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":55 + * def __str__(self): + * scores = ' '.join('%s=%s' % feat for feat in self.scores) + * return '[%s] ||| %s ||| %s ||| %s' % (self.lhs, _phrase(self.f), _phrase(self.e), scores) # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s__lhs); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s___phrase); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s__f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___phrase); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s__e); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_scores); + PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_v_scores); + __Pyx_GIVEREF(__pyx_v_scores); __pyx_t_2 = 0; + __pyx_t_1 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_12), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_r = ((PyObject *)__pyx_t_3); + __pyx_t_3 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); @@ -6657,297 +7206,346 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_15todot(struct __pyx_obj_5_cdec_Lattic __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec.Lattice.todot", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_cdec.TRule.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_lines); + __Pyx_XDECREF(__pyx_v_scores); __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":3 - * cimport mteval +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":138 + * cdef public TRule trule * - * cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): # <<<<<<<<<<<<<< - * cdef bytes ret - * if isinstance(sentence, unicode): + * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): # <<<<<<<<<<<<<< + * self.hg = hg + * self.edge = &hg.edges_[i] */ -static char *__pyx_f_5_cdec_as_str(PyObject *__pyx_v_sentence, struct __pyx_opt_args_5_cdec_as_str *__pyx_optional_args) { - PyObject *__pyx_v_error_msg = ((PyObject *)__pyx_kp_s_33); - PyObject *__pyx_v_ret = 0; - char *__pyx_r; +static PyObject *__pyx_f_5_cdec_14HypergraphEdge_init(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self, Hypergraph *__pyx_v_hg, unsigned int __pyx_v_i) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - char *__pyx_t_4; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("as_str", 0); - if (__pyx_optional_args) { - if (__pyx_optional_args->__pyx_n > 0) { - __pyx_v_error_msg = __pyx_optional_args->error_msg; - } - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":5 - * cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): - * cdef bytes ret - * if isinstance(sentence, unicode): # <<<<<<<<<<<<<< - * ret = sentence.encode('utf8') - * elif isinstance(sentence, str): - */ - __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { + __Pyx_RefNannySetupContext("init", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":6 - * cdef bytes ret - * if isinstance(sentence, unicode): - * ret = sentence.encode('utf8') # <<<<<<<<<<<<<< - * elif isinstance(sentence, str): - * ret = sentence + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":139 + * + * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): + * self.hg = hg # <<<<<<<<<<<<<< + * self.edge = &hg.edges_[i] + * self.trule = TRule() */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_34), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_ret = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; - goto __pyx_L3; - } + __pyx_v_self->hg = __pyx_v_hg; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":7 - * if isinstance(sentence, unicode): - * ret = sentence.encode('utf8') - * elif isinstance(sentence, str): # <<<<<<<<<<<<<< - * ret = sentence - * else: + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":140 + * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): + * self.hg = hg + * self.edge = &hg.edges_[i] # <<<<<<<<<<<<<< + * self.trule = TRule() + * self.trule.rule = self.edge.rule_.get() */ - __pyx_t_3 = ((PyObject *)((PyObject*)(&PyString_Type))); - __Pyx_INCREF(__pyx_t_3); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_2) { + __pyx_v_self->edge = (&(__pyx_v_hg->edges_[__pyx_v_i])); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":8 - * ret = sentence.encode('utf8') - * elif isinstance(sentence, str): - * ret = sentence # <<<<<<<<<<<<<< - * else: - * raise TypeError(error_msg % type(sentence)) + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":141 + * self.hg = hg + * self.edge = &hg.edges_[i] + * self.trule = TRule() # <<<<<<<<<<<<<< + * self.trule.rule = self.edge.rule_.get() + * return self */ - if (!(likely(PyBytes_CheckExact(__pyx_v_sentence))||((__pyx_v_sentence) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_sentence)->tp_name), 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_INCREF(__pyx_v_sentence); - __pyx_v_ret = ((PyObject*)__pyx_v_sentence); - goto __pyx_L3; - } - /*else*/ { + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_TRule)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->trule); + __Pyx_DECREF(((PyObject *)__pyx_v_self->trule)); + __pyx_v_self->trule = ((struct __pyx_obj_5_cdec_TRule *)__pyx_t_1); + __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":10 - * ret = sentence - * else: - * raise TypeError(error_msg % type(sentence)) # <<<<<<<<<<<<<< - * return ret + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":142 + * self.edge = &hg.edges_[i] + * self.trule = TRule() + * self.trule.rule = self.edge.rule_.get() # <<<<<<<<<<<<<< + * return self * */ - __pyx_t_3 = PyNumber_Remainder(__pyx_v_error_msg, ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L3:; + __pyx_v_self->trule->rule = __pyx_v_self->edge->rule_.get(); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":11 - * else: - * raise TypeError(error_msg % type(sentence)) - * return ret # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":143 + * self.trule = TRule() + * self.trule.rule = self.edge.rule_.get() + * return self # <<<<<<<<<<<<<< * - * cdef SufficientStats as_stats(x, y): + * def __len__(self): */ - __pyx_t_4 = PyBytes_AsString(((PyObject *)__pyx_v_ret)); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_t_4; + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - __pyx_r = 0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_WriteUnraisable("_cdec.as_str", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.HypergraphEdge.init", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_ret); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":13 - * return ret +/* Python wrapper */ +static Py_ssize_t __pyx_pw_5_cdec_14HypergraphEdge_1__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_14HypergraphEdge_1__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge___len__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":145 + * return self + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.edge.tail_nodes_.size() * - * cdef SufficientStats as_stats(x, y): # <<<<<<<<<<<<<< - * if isinstance(x, SufficientStats): - * return x */ -static struct __pyx_obj_5_cdec_SufficientStats *__pyx_f_5_cdec_as_stats(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { - struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_stats = NULL; - struct __pyx_obj_5_cdec_SufficientStats *__pyx_r = NULL; +static Py_ssize_t __pyx_pf_5_cdec_14HypergraphEdge___len__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { + Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("as_stats", 0); + __Pyx_RefNannySetupContext("__len__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":14 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":146 * - * cdef SufficientStats as_stats(x, y): - * if isinstance(x, SufficientStats): # <<<<<<<<<<<<<< - * return x - * elif x == 0 and isinstance(y, SufficientStats): + * def __len__(self): + * return self.edge.tail_nodes_.size() # <<<<<<<<<<<<<< + * + * property head_node: */ - __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { + __pyx_r = __pyx_v_self->edge->tail_nodes_.size(); + goto __pyx_L0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":15 - * cdef SufficientStats as_stats(x, y): - * if isinstance(x, SufficientStats): - * return x # <<<<<<<<<<<<<< - * elif x == 0 and isinstance(y, SufficientStats): - * stats = SufficientStats() + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_9head_node_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_9head_node_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_9head_node___get__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":149 + * + * property head_node: + * def __get__(self): # <<<<<<<<<<<<<< + * return HypergraphNode().init(self.hg, self.edge.head_node_) + * */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SufficientStats))))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_INCREF(__pyx_v_x); - __pyx_r = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_x); - goto __pyx_L0; - goto __pyx_L3; - } - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":16 - * if isinstance(x, SufficientStats): - * return x - * elif x == 0 and isinstance(y, SufficientStats): # <<<<<<<<<<<<<< - * stats = SufficientStats() - * stats.stats = new mteval.SufficientStats() +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_9head_node___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__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("__get__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":150 + * property head_node: + * def __get__(self): + * return HypergraphNode().init(self.hg, self.edge.head_node_) # <<<<<<<<<<<<<< + * + * property tail_nodes: */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_x, __pyx_int_0, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = ((struct __pyx_vtabstruct_5_cdec_HypergraphNode *)((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_1)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_1), __pyx_v_self->hg, __pyx_v_self->edge->head_node_); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_y, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = __pyx_t_3; - } else { - __pyx_t_4 = __pyx_t_2; - } - if (__pyx_t_4) { + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":17 - * return x - * elif x == 0 and isinstance(y, SufficientStats): - * stats = SufficientStats() # <<<<<<<<<<<<<< - * stats.stats = new mteval.SufficientStats() - * stats.metric = ( y).metric - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_stats = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); - __pyx_t_1 = 0; + __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.HypergraphEdge.head_node.__get__", __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_14HypergraphEdge_10tail_nodes_2generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":18 - * elif x == 0 and isinstance(y, SufficientStats): - * stats = SufficientStats() - * stats.stats = new mteval.SufficientStats() # <<<<<<<<<<<<<< - * stats.metric = ( y).metric - * return stats +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_10tail_nodes_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_10tail_nodes_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_10tail_nodes___get__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":153 + * + * property tail_nodes: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.edge.tail_nodes_.size()): */ - __pyx_v_stats->stats = new SufficientStats(); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":19 - * stats = SufficientStats() - * stats.stats = new mteval.SufficientStats() - * stats.metric = ( y).metric # <<<<<<<<<<<<<< - * return stats +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_10tail_nodes___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *)__pyx_ptype_5_cdec___pyx_scope_struct_12___get__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_12___get__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_14HypergraphEdge_10tail_nodes_2generator8, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.HypergraphEdge.tail_nodes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5_cdec_14HypergraphEdge_10tail_nodes_2generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + unsigned int __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[2]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":155 + * def __get__(self): + * cdef unsigned i + * for i in range(self.edge.tail_nodes_.size()): # <<<<<<<<<<<<<< + * yield HypergraphNode().init(self.hg, self.edge.tail_nodes_[i]) * */ - __pyx_v_stats->metric = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_y)->metric; + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->edge->tail_nodes_.size(); + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":20 - * stats.stats = new mteval.SufficientStats() - * stats.metric = ( y).metric - * return stats # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":156 + * cdef unsigned i + * for i in range(self.edge.tail_nodes_.size()): + * yield HypergraphNode().init(self.hg, self.edge.tail_nodes_[i]) # <<<<<<<<<<<<<< * - * cdef class Candidate: + * property span: */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __Pyx_INCREF(((PyObject *)__pyx_v_stats)); - __pyx_r = __pyx_v_stats; - goto __pyx_L0; - goto __pyx_L3; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = ((struct __pyx_vtabstruct_5_cdec_HypergraphNode *)((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_3)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_3), __pyx_cur_scope->__pyx_v_self->hg, (__pyx_cur_scope->__pyx_v_self->edge->tail_nodes_[__pyx_cur_scope->__pyx_v_i])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 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_generator->resume_label = 1; + return __pyx_r; + __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[2]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_L3:; - - __pyx_r = ((struct __pyx_obj_5_cdec_SufficientStats *)Py_None); __Pyx_INCREF(Py_None); + PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.as_stats", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_stats); - __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return __pyx_r; + return NULL; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_9Candidate_5words_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_9Candidate_5words_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_4span_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_4span_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9Candidate_5words___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_4span___get__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":27 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":159 * - * property words: + * property span: * def __get__(self): # <<<<<<<<<<<<<< - * return unicode(GetString(self.candidate.ewords).c_str(), encoding='utf8') + * return (self.edge.i_, self.edge.j_) * */ -static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_4span___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -6958,29 +7556,27 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cd int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":28 - * property words: + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":160 + * property span: * def __get__(self): - * return unicode(GetString(self.candidate.ewords).c_str(), encoding='utf8') # <<<<<<<<<<<<<< + * return (self.edge.i_, self.edge.j_) # <<<<<<<<<<<<<< * - * property fmap: + * property feature_values: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(TD::GetString(__pyx_v_self->candidate->ewords).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 28; __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[4]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->edge->i_); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyInt_FromLong(__pyx_v_self->edge->j_); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __pyx_t_1 = 0; - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__encoding), ((PyObject *)__pyx_n_s__utf8)) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_r = __pyx_t_3; + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_r = ((PyObject *)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0; @@ -6990,7 +7586,7 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cd __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec.Candidate.words.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.HypergraphEdge.span.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -6999,26 +7595,26 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cd } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_9Candidate_4fmap_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_9Candidate_4fmap_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_14feature_values_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_14feature_values_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9Candidate_4fmap___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_14feature_values___get__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":31 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":163 * - * property fmap: + * property feature_values: * def __get__(self): # <<<<<<<<<<<<<< - * cdef SparseVector fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) + * cdef SparseVector vector = SparseVector() + * vector.vector = new FastSparseVector[double](self.edge.feature_values_) */ -static PyObject *__pyx_pf_5_cdec_9Candidate_4fmap___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { - struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap = 0; +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_14feature_values___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_vector = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -7027,72 +7623,72 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_4fmap___get__(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":32 - * property fmap: + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":164 + * property feature_values: * def __get__(self): - * cdef SparseVector fmap = SparseVector() # <<<<<<<<<<<<<< - * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) - * return fmap + * cdef SparseVector vector = SparseVector() # <<<<<<<<<<<<<< + * vector.vector = new FastSparseVector[double](self.edge.feature_values_) + * return vector */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":33 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":165 * def __get__(self): - * cdef SparseVector fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) # <<<<<<<<<<<<<< - * return fmap + * cdef SparseVector vector = SparseVector() + * vector.vector = new FastSparseVector[double](self.edge.feature_values_) # <<<<<<<<<<<<<< + * return vector * */ - __pyx_v_fmap->vector = new FastSparseVector(__pyx_v_self->candidate->fmap); + __pyx_v_vector->vector = new FastSparseVector(__pyx_v_self->edge->feature_values_); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":34 - * cdef SparseVector fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) - * return fmap # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":166 + * cdef SparseVector vector = SparseVector() + * vector.vector = new FastSparseVector[double](self.edge.feature_values_) + * return vector # <<<<<<<<<<<<<< * - * cdef class SufficientStats: + * property prob: */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_fmap)); - __pyx_r = ((PyObject *)__pyx_v_fmap); + __Pyx_INCREF(((PyObject *)__pyx_v_vector)); + __pyx_r = ((PyObject *)__pyx_v_vector); 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.Candidate.fmap.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.HypergraphEdge.feature_values.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_fmap); + __Pyx_XDECREF((PyObject *)__pyx_v_vector); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_9Candidate_5score_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_9Candidate_5score_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_4prob_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_4prob_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9Candidate_5score___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_4prob___get__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":24 - * cdef class Candidate: - * cdef mteval.Candidate* candidate - * cdef public float score # <<<<<<<<<<<<<< +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":169 + * + * property prob: + * def __get__(self): # <<<<<<<<<<<<<< + * return self.edge.edge_prob_.as_float() * - * property words: */ -static PyObject *__pyx_pf_5_cdec_9Candidate_5score___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_4prob___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -7100,8 +7696,16 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_5score___get__(struct __pyx_obj_5_cd const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->score); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":170 + * property prob: + * def __get__(self): + * return self.edge.edge_prob_.as_float() # <<<<<<<<<<<<<< + * + * def __richcmp__(HypergraphEdge x, HypergraphEdge y, int op): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->edge->edge_prob_.as_float()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -7111,7 +7715,7 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_5score___get__(struct __pyx_obj_5_cd goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.Candidate.score.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.HypergraphEdge.prob.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -7120,118 +7724,156 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_5score___get__(struct __pyx_obj_5_cd } /* Python wrapper */ -static int __pyx_pw_5_cdec_9Candidate_5score_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5_cdec_9Candidate_5score_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_3__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_3__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9Candidate_5score_2__set__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_HypergraphEdge, 1, "x", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_HypergraphEdge, 1, "y", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_2__richcmp__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_x), ((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_y), ((int)__pyx_v_op)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5_cdec_9Candidate_5score_2__set__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":172 + * return self.edge.edge_prob_.as_float() + * + * def __richcmp__(HypergraphEdge x, HypergraphEdge y, int op): # <<<<<<<<<<<<<< + * if op == 2: # == + * return x.edge == y.edge + */ + +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_2__richcmp__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_x, struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_y, int __pyx_v_op) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - float __pyx_t_1; + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__set__", 0); - __pyx_t_1 = __pyx_PyFloat_AsFloat(__pyx_v_value); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->score = __pyx_t_1; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Candidate.score.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + __Pyx_RefNannySetupContext("__richcmp__", 0); -/* Python wrapper */ -static void __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_15SufficientStats___dealloc__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":175 + * if op == 2: # == + * return x.edge == y.edge + * elif op == 3: # != # <<<<<<<<<<<<<< + * return not (x == y) + * raise NotImplemented('comparison not implemented for HypergraphEdge') + */ + switch (__pyx_v_op) { -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":40 - * cdef mteval.EvaluationMetric* metric - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.stats + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":173 * + * def __richcmp__(HypergraphEdge x, HypergraphEdge y, int op): + * if op == 2: # == # <<<<<<<<<<<<<< + * return x.edge == y.edge + * elif op == 3: # != */ + case 2: -static void __pyx_pf_5_cdec_15SufficientStats___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":174 + * def __richcmp__(HypergraphEdge x, HypergraphEdge y, int op): + * if op == 2: # == + * return x.edge == y.edge # <<<<<<<<<<<<<< + * elif op == 3: # != + * return not (x == y) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_x->edge == __pyx_v_y->edge)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":175 + * if op == 2: # == + * return x.edge == y.edge + * elif op == 3: # != # <<<<<<<<<<<<<< + * return not (x == y) + * raise NotImplemented('comparison not implemented for HypergraphEdge') + */ + case 3: - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":41 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":176 + * return x.edge == y.edge + * elif op == 3: # != + * return not (x == y) # <<<<<<<<<<<<<< + * raise NotImplemented('comparison not implemented for HypergraphEdge') * - * def __dealloc__(self): - * del self.stats # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + break; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":177 + * elif op == 3: # != + * return not (x == y) + * raise NotImplemented('comparison not implemented for HypergraphEdge') # <<<<<<<<<<<<<< * - * property score: + * cdef class HypergraphNode: */ - delete __pyx_v_self->stats; + __pyx_t_1 = PyObject_Call(__pyx_builtin_NotImplemented, ((PyObject *)__pyx_k_tuple_14), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.HypergraphEdge.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); + return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_5score_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_5score_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_5trule_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_5trule_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_15SufficientStats_5score___get__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_5trule___get__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":44 - * - * property score: - * def __get__(self): # <<<<<<<<<<<<<< - * return self.metric.ComputeScore(self.stats[0]) +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":136 + * cdef hypergraph.Hypergraph* hg + * cdef hypergraph.HypergraphEdge* edge + * cdef public TRule trule # <<<<<<<<<<<<<< * + * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): */ -static PyObject *__pyx_pf_5_cdec_15SufficientStats_5score___get__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_5trule___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__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("__get__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":45 - * property score: - * def __get__(self): - * return self.metric.ComputeScore(self.stats[0]) # <<<<<<<<<<<<<< - * - * property detail: - */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->metric->ComputeScore((__pyx_v_self->stats[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __Pyx_INCREF(((PyObject *)__pyx_v_self->trule)); + __pyx_r = ((PyObject *)__pyx_v_self->trule); 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.SufficientStats.score.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); @@ -7239,128 +7881,145 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_5score___get__(struct __pyx_o } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5_cdec_14HypergraphEdge_5trule_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_5_cdec_14HypergraphEdge_5trule_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_15SufficientStats_6detail___get__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_5trule_2__set__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self), ((PyObject *)__pyx_v_value)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":48 - * - * property detail: - * def __get__(self): # <<<<<<<<<<<<<< - * return self.metric.DetailedScore(self.stats[0]).c_str() - * - */ - -static PyObject *__pyx_pf_5_cdec_15SufficientStats_6detail___get__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { - PyObject *__pyx_r = NULL; +static int __pyx_pf_5_cdec_14HypergraphEdge_5trule_2__set__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":49 - * property detail: - * def __get__(self): - * return self.metric.DetailedScore(self.stats[0]).c_str() # <<<<<<<<<<<<<< - * - * def __len__(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(__pyx_v_self->metric->DetailedScore((__pyx_v_self->stats[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __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_RefNannySetupContext("__set__", 0); + if (!(likely(((__pyx_v_value) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_value, __pyx_ptype_5_cdec_TRule))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->trule); + __Pyx_DECREF(((PyObject *)__pyx_v_self->trule)); + __pyx_v_self->trule = ((struct __pyx_obj_5_cdec_TRule *)__pyx_v_value); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.SufficientStats.detail.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("_cdec.HypergraphEdge.trule.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static Py_ssize_t __pyx_pw_5_cdec_15SufficientStats_3__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_5_cdec_15SufficientStats_3__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; +static int __pyx_pw_5_cdec_14HypergraphEdge_5trule_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_5_cdec_14HypergraphEdge_5trule_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_15SufficientStats_2__len__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_5trule_4__del__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":51 - * return self.metric.DetailedScore(self.stats[0]).c_str() - * - * def __len__(self): # <<<<<<<<<<<<<< - * return self.stats.size() +static int __pyx_pf_5_cdec_14HypergraphEdge_5trule_4__del__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->trule); + __Pyx_DECREF(((PyObject *)__pyx_v_self->trule)); + __pyx_v_self->trule = ((struct __pyx_obj_5_cdec_TRule *)Py_None); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":183 + * cdef hypergraph.HypergraphNode* node * + * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): # <<<<<<<<<<<<<< + * self.hg = hg + * self.node = &hg.nodes_[i] */ -static Py_ssize_t __pyx_pf_5_cdec_15SufficientStats_2__len__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { - Py_ssize_t __pyx_r; +static PyObject *__pyx_f_5_cdec_14HypergraphNode_init(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self, Hypergraph *__pyx_v_hg, unsigned int __pyx_v_i) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__", 0); + __Pyx_RefNannySetupContext("init", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":52 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":184 * - * def __len__(self): - * return self.stats.size() # <<<<<<<<<<<<<< + * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): + * self.hg = hg # <<<<<<<<<<<<<< + * self.node = &hg.nodes_[i] + * return self + */ + __pyx_v_self->hg = __pyx_v_hg; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":185 + * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): + * self.hg = hg + * self.node = &hg.nodes_[i] # <<<<<<<<<<<<<< + * return self * - * def __iter__(self): */ - __pyx_r = __pyx_v_self->stats->size(); + __pyx_v_self->node = (&(__pyx_v_hg->nodes_[__pyx_v_i])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":186 + * self.hg = hg + * self.node = &hg.nodes_[i] + * return self # <<<<<<<<<<<<<< + * + * property in_edges: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - __pyx_r = 0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator7(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5_cdec_14HypergraphNode_8in_edges_2generator9(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_5__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_5__iter__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_8in_edges_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_8in_edges_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_15SufficientStats_4__iter__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_14HypergraphNode_8in_edges___get__(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":54 - * return self.stats.size() +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":189 * - * def __iter__(self): # <<<<<<<<<<<<<< - * for i in range(len(self)): - * yield self.stats[0][i] + * property in_edges: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.node.in_edges_.size()): */ -static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_14HypergraphNode_8in_edges___get__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__iter__", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_9___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_9___iter__, __pyx_empty_tuple, NULL); + __Pyx_RefNannySetupContext("__get__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *)__pyx_ptype_5_cdec___pyx_scope_struct_13___get__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_13___get__, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -7370,7 +8029,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_ __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_15SufficientStats_6generator7, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_14HypergraphNode_8in_edges_2generator9, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -7379,7 +8038,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.SufficientStats.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.HypergraphNode.in_edges.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); @@ -7388,15 +8047,14 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_ return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator7(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_14HypergraphNode_8in_edges_2generator9(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *)__pyx_generator->closure); + struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; - Py_ssize_t __pyx_t_1; - PyObject *__pyx_t_2 = NULL; + size_t __pyx_t_1; + unsigned int __pyx_t_2; PyObject *__pyx_t_3 = NULL; - PyObject *(*__pyx_t_4)(PyObject *); - unsigned int __pyx_t_5; + PyObject *__pyx_t_4 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { @@ -7407,75 +8065,35 @@ static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator7(__pyx_GeneratorOb return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":55 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":191 + * def __get__(self): + * cdef unsigned i + * for i in range(self.node.in_edges_.size()): # <<<<<<<<<<<<<< + * yield HypergraphEdge().init(self.hg, self.node.in_edges_[i]) * - * def __iter__(self): - * for i in range(len(self)): # <<<<<<<<<<<<<< - * yield self.stats[0][i] + */ + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->node->in_edges_.size(); + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":192 + * cdef unsigned i + * for i in range(self.node.in_edges_.size()): + * yield HypergraphEdge().init(self.hg, self.node.in_edges_[i]) # <<<<<<<<<<<<<< * + * property out_edges: */ - __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_1 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphEdge)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { - if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_3)) break; - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; - } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { - if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; - } else { - __pyx_t_2 = __pyx_t_4(__pyx_t_3); - if (unlikely(!__pyx_t_2)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_i); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_i); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":56 - * def __iter__(self): - * for i in range(len(self)): - * yield self.stats[0][i] # <<<<<<<<<<<<<< - * - * def __iadd__(SufficientStats self, SufficientStats other): - */ - __pyx_t_5 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_i); if (unlikely((__pyx_t_5 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyFloat_FromDouble(((__pyx_cur_scope->__pyx_v_self->stats[0])[__pyx_t_5])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_t_4 = ((struct __pyx_vtabstruct_5_cdec_HypergraphEdge *)((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_t_3)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_t_3), __pyx_cur_scope->__pyx_v_self->hg, (__pyx_cur_scope->__pyx_v_self->node->in_edges_[__pyx_cur_scope->__pyx_v_i])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; - __Pyx_XGIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); /* return from generator, yielding value */ @@ -7483,2499 +8101,8924 @@ static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator7(__pyx_GeneratorOb return __pyx_r; __pyx_L6_resume_from_yield:; __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; - __pyx_cur_scope->__pyx_t_1 = 0; - __Pyx_XGOTREF(__pyx_t_3); - __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); return NULL; } +static PyObject *__pyx_gb_5_cdec_14HypergraphNode_9out_edges_2generator10(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_9out_edges_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_9out_edges_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iadd__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SufficientStats, 1, "other", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_15SufficientStats_7__iadd__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_other)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_14HypergraphNode_9out_edges___get__(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":195 + * + * property out_edges: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.node.out_edges_.size()): + */ + +static PyObject *__pyx_pf_5_cdec_14HypergraphNode_9out_edges___get__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *)__pyx_ptype_5_cdec___pyx_scope_struct_14___get__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_14___get__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_14HypergraphNode_9out_edges_2generator10, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.HypergraphNode.out_edges.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":58 - * yield self.stats[0][i] - * - * def __iadd__(SufficientStats self, SufficientStats other): # <<<<<<<<<<<<<< - * self.stats[0] += other.stats[0] - * return self - */ - -static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__iadd__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_other) { +static PyObject *__pyx_gb_5_cdec_14HypergraphNode_9out_edges_2generator10(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; + size_t __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iadd__", 0); + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[2]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":59 - * - * def __iadd__(SufficientStats self, SufficientStats other): - * self.stats[0] += other.stats[0] # <<<<<<<<<<<<<< - * return self + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":197 + * def __get__(self): + * cdef unsigned i + * for i in range(self.node.out_edges_.size()): # <<<<<<<<<<<<<< + * yield HypergraphEdge().init(self.hg, self.node.out_edges_[i]) * */ - (__pyx_v_self->stats[0]) += (__pyx_v_other->stats[0]); + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->node->out_edges_.size(); + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":60 - * def __iadd__(SufficientStats self, SufficientStats other): - * self.stats[0] += other.stats[0] - * return self # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":198 + * cdef unsigned i + * for i in range(self.node.out_edges_.size()): + * yield HypergraphEdge().init(self.hg, self.node.out_edges_[i]) # <<<<<<<<<<<<<< * - * def __add__(x, y): + * property span: */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __pyx_r = ((PyObject *)__pyx_v_self); + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphEdge)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = ((struct __pyx_vtabstruct_5_cdec_HypergraphEdge *)((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_t_3)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_t_3), __pyx_cur_scope->__pyx_v_self->hg, (__pyx_cur_scope->__pyx_v_self->node->out_edges_[__pyx_cur_scope->__pyx_v_i])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 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_generator->resume_label = 1; + return __pyx_r; + __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[2]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return __pyx_r; + return NULL; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_10__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_10__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_4span_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_4span_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__add__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_15SufficientStats_9__add__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_14HypergraphNode_4span___get__(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":62 - * return self +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":201 + * + * property span: + * def __get__(self): # <<<<<<<<<<<<<< + * return next(self.in_edges).span * - * def __add__(x, y): # <<<<<<<<<<<<<< - * cdef SufficientStats sx = as_stats(x, y) - * cdef SufficientStats sy = as_stats(y, x) */ -static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { - struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sx = 0; - struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sy = 0; - struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_result = 0; +static PyObject *__pyx_pf_5_cdec_14HypergraphNode_4span___get__(struct __pyx_obj_5_cdec_HypergraphNode *__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("__add__", 0); + __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":63 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":202 + * property span: + * def __get__(self): + * return next(self.in_edges).span # <<<<<<<<<<<<<< * - * def __add__(x, y): - * cdef SufficientStats sx = as_stats(x, y) # <<<<<<<<<<<<<< - * cdef SufficientStats sy = as_stats(y, x) - * cdef SufficientStats result = SufficientStats() - */ - __pyx_t_1 = ((PyObject *)__pyx_f_5_cdec_as_stats(__pyx_v_x, __pyx_v_y)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_sx = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":64 - * def __add__(x, y): - * cdef SufficientStats sx = as_stats(x, y) - * cdef SufficientStats sy = as_stats(y, x) # <<<<<<<<<<<<<< - * cdef SufficientStats result = SufficientStats() - * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) + * property cat: */ - __pyx_t_1 = ((PyObject *)__pyx_f_5_cdec_as_stats(__pyx_v_y, __pyx_v_x)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__in_edges); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_v_sy = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":65 - * cdef SufficientStats sx = as_stats(x, y) - * cdef SufficientStats sy = as_stats(y, x) - * cdef SufficientStats result = SufficientStats() # <<<<<<<<<<<<<< - * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) - * result.metric = sx.metric - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyIter_Next(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__span); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_v_result = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":66 - * cdef SufficientStats sy = as_stats(y, x) - * cdef SufficientStats result = SufficientStats() - * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) # <<<<<<<<<<<<<< - * result.metric = sx.metric - * return result - */ - __pyx_v_result->stats = new SufficientStats(operator+((__pyx_v_sx->stats[0]), (__pyx_v_sy->stats[0]))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":67 - * cdef SufficientStats result = SufficientStats() - * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) - * result.metric = sx.metric # <<<<<<<<<<<<<< - * return result - * - */ - __pyx_v_result->metric = __pyx_v_sx->metric; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":68 - * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) - * result.metric = sx.metric - * return result # <<<<<<<<<<<<<< - * - * cdef class CandidateSet: - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - __pyx_r = ((PyObject *)__pyx_v_result); 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.SufficientStats.__add__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec.HypergraphNode.span.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_sx); - __Pyx_XDECREF((PyObject *)__pyx_v_sy); - __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__evaluator,0}; - int __pyx_r; +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_3cat_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_3cat_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[1] = {0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__evaluator); - 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __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_evaluator = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)values[0]); - } - 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[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.CandidateSet.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_evaluator), __pyx_ptype_5_cdec_SegmentEvaluator, 1, "evaluator", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12CandidateSet___cinit__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), __pyx_v_evaluator); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = -1; - __pyx_L0:; + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_14HypergraphNode_3cat___get__(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":75 - * cdef mteval.CandidateSet* cs +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":205 * - * def __cinit__(self, SegmentEvaluator evaluator): # <<<<<<<<<<<<<< - * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) - * self.metric = evaluator.metric + * property cat: + * def __get__(self): # <<<<<<<<<<<<<< + * if self.node.cat_: + * return TDConvert(-self.node.cat_) */ -static int __pyx_pf_5_cdec_12CandidateSet___cinit__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator) { - int __pyx_r; +static PyObject *__pyx_pf_5_cdec_14HypergraphNode_3cat___get__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":76 - * - * def __cinit__(self, SegmentEvaluator evaluator): - * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) # <<<<<<<<<<<<<< - * self.metric = evaluator.metric - * self.cs = new mteval.CandidateSet() - */ - __pyx_v_self->scorer = new boost::shared_ptr((__pyx_v_evaluator->scorer[0])); + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":77 - * def __cinit__(self, SegmentEvaluator evaluator): - * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) - * self.metric = evaluator.metric # <<<<<<<<<<<<<< - * self.cs = new mteval.CandidateSet() + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":206 + * property cat: + * def __get__(self): + * if self.node.cat_: # <<<<<<<<<<<<<< + * return TDConvert(-self.node.cat_) * */ - __pyx_v_self->metric = __pyx_v_evaluator->metric; + if (__pyx_v_self->node->cat_) { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":78 - * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) - * self.metric = evaluator.metric - * self.cs = new mteval.CandidateSet() # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":207 + * def __get__(self): + * if self.node.cat_: + * return TDConvert(-self.node.cat_) # <<<<<<<<<<<<<< * - * def __dealloc__(self): + * def __richcmp__(HypergraphNode x, HypergraphNode y, int op): */ - __pyx_v_self->cs = new training::CandidateSet(); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_self->node->cat_))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 207; __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; + goto __pyx_L3; + } + __pyx_L3:; - __pyx_r = 0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.HypergraphNode.cat.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static void __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_1__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_1__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_HypergraphNode, 1, "x", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_HypergraphNode, 1, "y", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_14HypergraphNode___richcmp__(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_v_x), ((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_v_y), ((int)__pyx_v_op)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":80 - * self.cs = new mteval.CandidateSet() +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":209 + * return TDConvert(-self.node.cat_) * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.scorer - * del self.cs + * def __richcmp__(HypergraphNode x, HypergraphNode y, int op): # <<<<<<<<<<<<<< + * if op == 2: # == + * return x.node == y.node */ -static void __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_14HypergraphNode___richcmp__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_x, struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_y, int __pyx_v_op) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__richcmp__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":81 - * - * def __dealloc__(self): - * del self.scorer # <<<<<<<<<<<<<< - * del self.cs - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":212 + * if op == 2: # == + * return x.node == y.node + * elif op == 3: # != # <<<<<<<<<<<<<< + * return not (x == y) + * raise NotImplemented('comparison not implemented for HypergraphNode') */ - delete __pyx_v_self->scorer; + switch (__pyx_v_op) { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 - * def __dealloc__(self): - * del self.scorer - * del self.cs # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":210 * - * def __len__(self): + * def __richcmp__(HypergraphNode x, HypergraphNode y, int op): + * if op == 2: # == # <<<<<<<<<<<<<< + * return x.node == y.node + * elif op == 3: # != */ - delete __pyx_v_self->cs; - - __Pyx_RefNannyFinishContext(); -} + case 2: -/* Python wrapper */ -static Py_ssize_t __pyx_pw_5_cdec_12CandidateSet_5__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_5_cdec_12CandidateSet_5__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12CandidateSet_4__len__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":211 + * def __richcmp__(HypergraphNode x, HypergraphNode y, int op): + * if op == 2: # == + * return x.node == y.node # <<<<<<<<<<<<<< + * elif op == 3: # != + * return not (x == y) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_x->node == __pyx_v_y->node)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + break; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":84 - * del self.cs - * - * def __len__(self): # <<<<<<<<<<<<<< - * return self.cs.size() - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":212 + * if op == 2: # == + * return x.node == y.node + * elif op == 3: # != # <<<<<<<<<<<<<< + * return not (x == y) + * raise NotImplemented('comparison not implemented for HypergraphNode') */ + case 3: -static Py_ssize_t __pyx_pf_5_cdec_12CandidateSet_4__len__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__", 0); + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":213 + * return x.node == y.node + * elif op == 3: # != + * return not (x == y) # <<<<<<<<<<<<<< + * raise NotImplemented('comparison not implemented for HypergraphNode') + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + break; + } - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":85 - * - * def __len__(self): - * return self.cs.size() # <<<<<<<<<<<<<< - * - * def __getitem__(self,int k): + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":214 + * elif op == 3: # != + * return not (x == y) + * raise NotImplemented('comparison not implemented for HypergraphNode') # <<<<<<<<<<<<<< */ - __pyx_r = __pyx_v_self->cs->size(); - goto __pyx_L0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_NotImplemented, ((PyObject *)__pyx_k_tuple_16), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = 0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.HypergraphNode.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_k); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_k) { - int __pyx_v_k; - PyObject *__pyx_r = 0; +static int __pyx_pw_5_cdec_7Lattice_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_7Lattice_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_inp = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__inp,0}; + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); - assert(__pyx_arg_k); { - __pyx_v_k = __Pyx_PyInt_AsInt(__pyx_arg_k); if (unlikely((__pyx_v_k == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__inp); + 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, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 6; __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_inp = 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[3]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.CandidateSet.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Lattice.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); - return NULL; + return -1; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12CandidateSet_6__getitem__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), ((int)__pyx_v_k)); + __pyx_r = __pyx_pf_5_cdec_7Lattice___init__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), __pyx_v_inp); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":87 - * return self.cs.size() +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":6 + * cdef lattice.Lattice* lattice * - * def __getitem__(self,int k): # <<<<<<<<<<<<<< - * if not 0 <= k < self.cs.size(): - * raise IndexError('candidate set index out of range') + * def __init__(self, inp): # <<<<<<<<<<<<<< + * if isinstance(inp, tuple): + * self.lattice = new lattice.Lattice(len(inp)) */ -static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, int __pyx_v_k) { - struct __pyx_obj_5_cdec_Candidate *__pyx_v_candidate = 0; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5_cdec_7Lattice___init__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, PyObject *__pyx_v_inp) { + PyObject *__pyx_v_i = NULL; + PyObject *__pyx_v_arcs = NULL; + int __pyx_r; __Pyx_RefNannyDeclarations - int __pyx_t_1; + PyObject *__pyx_t_1 = NULL; int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *(*__pyx_t_5)(PyObject *); + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + char *__pyx_t_8; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__getitem__", 0); + __Pyx_RefNannySetupContext("__init__", 0); + __Pyx_INCREF(__pyx_v_inp); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":88 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":7 * - * def __getitem__(self,int k): - * if not 0 <= k < self.cs.size(): # <<<<<<<<<<<<<< - * raise IndexError('candidate set index out of range') - * cdef Candidate candidate = Candidate() + * def __init__(self, inp): + * if isinstance(inp, tuple): # <<<<<<<<<<<<<< + * self.lattice = new lattice.Lattice(len(inp)) + * for i, arcs in enumerate(inp): */ - __pyx_t_1 = (0 <= __pyx_v_k); - if (__pyx_t_1) { - __pyx_t_1 = (__pyx_v_k < __pyx_v_self->cs->size()); - } - __pyx_t_2 = (!__pyx_t_1); + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyTuple_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_inp, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":89 - * def __getitem__(self,int k): - * if not 0 <= k < self.cs.size(): - * raise IndexError('candidate set index out of range') # <<<<<<<<<<<<<< - * cdef Candidate candidate = Candidate() - * candidate.candidate = &self.cs[0][k] + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":8 + * def __init__(self, inp): + * if isinstance(inp, tuple): + * self.lattice = new lattice.Lattice(len(inp)) # <<<<<<<<<<<<<< + * for i, arcs in enumerate(inp): + * self[i] = arcs */ - __pyx_t_3 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_36), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Length(__pyx_v_inp); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->lattice = new Lattice(__pyx_t_3); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":9 + * if isinstance(inp, tuple): + * self.lattice = new lattice.Lattice(len(inp)) + * for i, arcs in enumerate(inp): # <<<<<<<<<<<<<< + * self[i] = arcs + * else: + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_1 = __pyx_int_0; + if (PyList_CheckExact(__pyx_v_inp) || PyTuple_CheckExact(__pyx_v_inp)) { + __pyx_t_4 = __pyx_v_inp; __Pyx_INCREF(__pyx_t_4); __pyx_t_3 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_inp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_4)) break; + __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; + } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; + } else { + __pyx_t_6 = __pyx_t_5(__pyx_t_4); + if (unlikely(!__pyx_t_6)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_6); + } + __Pyx_XDECREF(__pyx_v_arcs); + __pyx_v_arcs = __pyx_t_6; + __pyx_t_6 = 0; + __Pyx_INCREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_1; + __pyx_t_6 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); + __pyx_t_1 = __pyx_t_6; + __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":10 + * self.lattice = new lattice.Lattice(len(inp)) + * for i, arcs in enumerate(inp): + * self[i] = arcs # <<<<<<<<<<<<<< + * else: + * if isinstance(inp, unicode): + */ + if (PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_v_i, __pyx_v_arcs) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L3; } - __pyx_L3:; + /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":90 - * if not 0 <= k < self.cs.size(): - * raise IndexError('candidate set index out of range') - * cdef Candidate candidate = Candidate() # <<<<<<<<<<<<<< - * candidate.candidate = &self.cs[0][k] - * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":12 + * self[i] = arcs + * else: + * if isinstance(inp, unicode): # <<<<<<<<<<<<<< + * inp = inp.encode('utf8') + * if not isinstance(inp, str): */ - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Candidate)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_candidate = ((struct __pyx_obj_5_cdec_Candidate *)__pyx_t_3); - __pyx_t_3 = 0; + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_inp, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":91 - * raise IndexError('candidate set index out of range') - * cdef Candidate candidate = Candidate() - * candidate.candidate = &self.cs[0][k] # <<<<<<<<<<<<<< - * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) - * return candidate + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":13 + * else: + * if isinstance(inp, unicode): + * inp = inp.encode('utf8') # <<<<<<<<<<<<<< + * if not isinstance(inp, str): + * raise TypeError('Cannot create lattice from %s' % type(inp)) */ - __pyx_v_candidate->candidate = (&((__pyx_v_self->cs[0])[__pyx_v_k])); + __pyx_t_1 = PyObject_GetAttr(__pyx_v_inp, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_17), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_v_inp); + __pyx_v_inp = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L6; + } + __pyx_L6:; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":92 - * cdef Candidate candidate = Candidate() - * candidate.candidate = &self.cs[0][k] - * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) # <<<<<<<<<<<<<< - * return candidate + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":14 + * if isinstance(inp, unicode): + * inp = inp.encode('utf8') + * if not isinstance(inp, str): # <<<<<<<<<<<<<< + * raise TypeError('Cannot create lattice from %s' % type(inp)) + * self.lattice = new lattice.Lattice() + */ + __pyx_t_4 = ((PyObject *)((PyObject*)(&PyString_Type))); + __Pyx_INCREF(__pyx_t_4); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_inp, __pyx_t_4); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_7 = (!__pyx_t_2); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":15 + * inp = inp.encode('utf8') + * if not isinstance(inp, str): + * raise TypeError('Cannot create lattice from %s' % type(inp)) # <<<<<<<<<<<<<< + * self.lattice = new lattice.Lattice() + * lattice.ConvertTextToLattice(string(inp), self.lattice) + */ + __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), ((PyObject *)Py_TYPE(__pyx_v_inp))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L7; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":16 + * if not isinstance(inp, str): + * raise TypeError('Cannot create lattice from %s' % type(inp)) + * self.lattice = new lattice.Lattice() # <<<<<<<<<<<<<< + * lattice.ConvertTextToLattice(string(inp), self.lattice) * */ - __pyx_v_candidate->score = __pyx_v_self->metric->ComputeScore(((__pyx_v_self->cs[0])[__pyx_v_k]).eval_feats); + __pyx_v_self->lattice = new Lattice(); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":93 - * candidate.candidate = &self.cs[0][k] - * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) - * return candidate # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":17 + * raise TypeError('Cannot create lattice from %s' % type(inp)) + * self.lattice = new lattice.Lattice() + * lattice.ConvertTextToLattice(string(inp), self.lattice) # <<<<<<<<<<<<<< * - * def __iter__(self): + * def __getitem__(self, int index): */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_candidate)); - __pyx_r = ((PyObject *)__pyx_v_candidate); - goto __pyx_L0; + __pyx_t_8 = PyBytes_AsString(__pyx_v_inp); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + LatticeTools::ConvertTextToLattice(std::string(((char *)__pyx_t_8)), __pyx_v_self->lattice); + } + __pyx_L3:; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec.CandidateSet.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_cdec.Lattice.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_candidate); - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_arcs); + __Pyx_XDECREF(__pyx_v_inp); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12CandidateSet_9__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12CandidateSet_9__iter__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_7Lattice_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Lattice_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index) { + int __pyx_v_index; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12CandidateSet_8__iter__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + assert(__pyx_arg_index); { + __pyx_v_index = __Pyx_PyInt_AsInt(__pyx_arg_index); if (unlikely((__pyx_v_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.Lattice.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_7Lattice_2__getitem__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), ((int)__pyx_v_index)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":95 - * return candidate +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":19 + * lattice.ConvertTextToLattice(string(inp), self.lattice) * - * def __iter__(self): # <<<<<<<<<<<<<< - * cdef unsigned i - * for i in range(len(self)): + * def __getitem__(self, int index): # <<<<<<<<<<<<<< + * if not 0 <= index < len(self): + * raise IndexError('lattice index out of range') */ -static PyObject *__pyx_pf_5_cdec_12CandidateSet_8__iter__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index) { + PyObject *__pyx_v_arcs = NULL; + std::vector __pyx_v_arc_vector; + LatticeArc *__pyx_v_arc; + unsigned int __pyx_v_i; + PyObject *__pyx_v_label = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations + int __pyx_t_1; + Py_ssize_t __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + size_t __pyx_t_5; + unsigned int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__iter__", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_10___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_10___iter__, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; + __Pyx_RefNannySetupContext("__getitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":20 + * + * def __getitem__(self, int index): + * if not 0 <= index < len(self): # <<<<<<<<<<<<<< + * raise IndexError('lattice index out of range') + * arcs = [] + */ + __pyx_t_1 = (0 <= __pyx_v_index); + if (__pyx_t_1) { + __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = (__pyx_v_index < __pyx_t_2); } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12CandidateSet_10generator8, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; + __pyx_t_3 = (!__pyx_t_1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":21 + * def __getitem__(self, int index): + * if not 0 <= index < len(self): + * raise IndexError('lattice index out of range') # <<<<<<<<<<<<<< + * arcs = [] + * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] + */ + __pyx_t_4 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; } + __pyx_L3:; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.CandidateSet.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":22 + * if not 0 <= index < len(self): + * raise IndexError('lattice index out of range') + * arcs = [] # <<<<<<<<<<<<<< + * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] + * cdef lattice.LatticeArc* arc + */ + __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_arcs = __pyx_t_4; + __pyx_t_4 = 0; -static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - Py_ssize_t __pyx_t_1; - unsigned int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("None", 0); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_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[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":23 + * raise IndexError('lattice index out of range') + * arcs = [] + * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] # <<<<<<<<<<<<<< + * cdef lattice.LatticeArc* arc + * cdef unsigned i + */ + __pyx_v_arc_vector = ((__pyx_v_self->lattice[0])[__pyx_v_index]); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":97 - * def __iter__(self): + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":26 + * cdef lattice.LatticeArc* arc * cdef unsigned i - * for i in range(len(self)): # <<<<<<<<<<<<<< - * yield self[i] - * + * for i in range(arc_vector.size()): # <<<<<<<<<<<<<< + * arc = &arc_vector[i] + * label = unicode(TDConvert(arc.label), 'utf8') */ - __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + __pyx_t_5 = __pyx_v_arc_vector.size(); + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_v_i = __pyx_t_6; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":98 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":27 * cdef unsigned i - * for i in range(len(self)): - * yield self[i] # <<<<<<<<<<<<<< + * for i in range(arc_vector.size()): + * arc = &arc_vector[i] # <<<<<<<<<<<<<< + * label = unicode(TDConvert(arc.label), 'utf8') + * arcs.append((label, arc.cost, arc.dist2next)) + */ + __pyx_v_arc = (&(__pyx_v_arc_vector[__pyx_v_i])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":28 + * for i in range(arc_vector.size()): + * arc = &arc_vector[i] + * label = unicode(TDConvert(arc.label), 'utf8') # <<<<<<<<<<<<<< + * arcs.append((label, arc.cost, arc.dist2next)) + * return tuple(arcs) + */ + __pyx_t_4 = PyBytes_FromString(TD::Convert(__pyx_v_arc->label)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_7, 1, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __Pyx_XDECREF(((PyObject *)__pyx_v_label)); + __pyx_v_label = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":29 + * arc = &arc_vector[i] + * label = unicode(TDConvert(arc.label), 'utf8') + * arcs.append((label, arc.cost, arc.dist2next)) # <<<<<<<<<<<<<< + * return tuple(arcs) * - * def add_kbest(self, Hypergraph hypergraph, unsigned k): */ - __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 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_generator->resume_label = 1; - return __pyx_r; - __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[4]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyFloat_FromDouble(__pyx_v_arc->cost); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = PyInt_FromLong(__pyx_v_arc->dist2next); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(((PyObject *)__pyx_v_label)); + PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_v_label)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_label)); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + __pyx_t_4 = 0; + __pyx_t_7 = 0; + __pyx_t_9 = PyList_Append(__pyx_v_arcs, ((PyObject *)__pyx_t_8)); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; } - PyErr_SetNone(PyExc_StopIteration); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":30 + * label = unicode(TDConvert(arc.label), 'utf8') + * arcs.append((label, arc.cost, arc.dist2next)) + * return tuple(arcs) # <<<<<<<<<<<<<< + * + * def __setitem__(self, int index, tuple arcs): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_8 = ((PyObject *)PyList_AsTuple(__pyx_v_arcs)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_8)); + __pyx_r = ((PyObject *)__pyx_t_8); + __pyx_t_8 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_cdec.Lattice.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; + __Pyx_XDECREF(__pyx_v_arcs); + __Pyx_XDECREF(__pyx_v_label); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); - return NULL; + return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph = 0; - unsigned int __pyx_v_k; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__hypergraph,&__pyx_n_s__k,0}; - PyObject *__pyx_r = 0; +static int __pyx_pw_5_cdec_7Lattice_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index, PyObject *__pyx_v_arcs); /*proto*/ +static int __pyx_pw_5_cdec_7Lattice_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index, PyObject *__pyx_v_arcs) { + int __pyx_v_index; + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("add_kbest (wrapper)", 0); - { - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__hypergraph); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_kbest") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_hypergraph = ((struct __pyx_obj_5_cdec_Hypergraph *)values[0]); - __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); + assert(__pyx_arg_index); { + __pyx_v_index = __Pyx_PyInt_AsInt(__pyx_arg_index); if (unlikely((__pyx_v_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.CandidateSet.add_kbest", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Lattice.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); - return NULL; + return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_hypergraph), __pyx_ptype_5_cdec_Hypergraph, 1, "hypergraph", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12CandidateSet_11add_kbest(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), __pyx_v_hypergraph, __pyx_v_k); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_arcs), (&PyTuple_Type), 1, "arcs", 1))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_7Lattice_4__setitem__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), ((int)__pyx_v_index), ((PyObject*)__pyx_v_arcs)); goto __pyx_L0; __pyx_L1_error:; - __pyx_r = NULL; + __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":100 - * yield self[i] - * - * def add_kbest(self, Hypergraph hypergraph, unsigned k): # <<<<<<<<<<<<<< - * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":32 + * return tuple(arcs) * + * def __setitem__(self, int index, tuple arcs): # <<<<<<<<<<<<<< + * if not 0 <= index < len(self): + * raise IndexError('lattice index out of range') */ -static PyObject *__pyx_pf_5_cdec_12CandidateSet_11add_kbest(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph, unsigned int __pyx_v_k) { - PyObject *__pyx_r = NULL; +static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index, PyObject *__pyx_v_arcs) { + LatticeArc *__pyx_v_arc; + PyObject *__pyx_v_label = NULL; + PyObject *__pyx_v_cost = NULL; + PyObject *__pyx_v_dist2next = NULL; + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("add_kbest", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":101 - * - * def add_kbest(self, Hypergraph hypergraph, unsigned k): - * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) # <<<<<<<<<<<<<< + int __pyx_t_1; + Py_ssize_t __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *(*__pyx_t_10)(PyObject *); + char *__pyx_t_11; + double __pyx_t_12; + int __pyx_t_13; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__setitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":33 * - * cdef class SegmentEvaluator: + * def __setitem__(self, int index, tuple arcs): + * if not 0 <= index < len(self): # <<<<<<<<<<<<<< + * raise IndexError('lattice index out of range') + * cdef lattice.LatticeArc* arc */ - __pyx_v_self->cs->AddKBestCandidates((__pyx_v_hypergraph->hg[0]), __pyx_v_k, __pyx_v_self->scorer->get()); + __pyx_t_1 = (0 <= __pyx_v_index); + if (__pyx_t_1) { + __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = (__pyx_v_index < __pyx_t_2); + } + __pyx_t_3 = (!__pyx_t_1); + if (__pyx_t_3) { - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":34 + * def __setitem__(self, int index, tuple arcs): + * if not 0 <= index < len(self): + * raise IndexError('lattice index out of range') # <<<<<<<<<<<<<< + * cdef lattice.LatticeArc* arc + * for (label, cost, dist2next) in arcs: + */ + __pyx_t_4 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_21), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":36 + * raise IndexError('lattice index out of range') + * cdef lattice.LatticeArc* arc + * for (label, cost, dist2next) in arcs: # <<<<<<<<<<<<<< + * if isinstance(label, unicode): + * label = label.encode('utf8') + */ + if (unlikely(((PyObject *)__pyx_v_arcs) == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_4 = ((PyObject *)__pyx_v_arcs); __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0; + for (;;) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) { + PyObject* sequence = __pyx_t_5; + if (likely(PyTuple_CheckExact(sequence))) { + if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { + if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 2); + } else { + if (unlikely(PyList_GET_SIZE(sequence) != 3)) { + if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_6 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + __pyx_t_8 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_9 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; + index = 0; __pyx_t_6 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + index = 1; __pyx_t_7 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + index = 2; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L7_unpacking_done; + __pyx_L6_unpacking_failed:; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L7_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_label); + __pyx_v_label = __pyx_t_6; + __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_v_cost); + __pyx_v_cost = __pyx_t_7; + __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_v_dist2next); + __pyx_v_dist2next = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":37 + * cdef lattice.LatticeArc* arc + * for (label, cost, dist2next) in arcs: + * if isinstance(label, unicode): # <<<<<<<<<<<<<< + * label = label.encode('utf8') + * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) + */ + __pyx_t_5 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_5); + __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_label, __pyx_t_5); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":38 + * for (label, cost, dist2next) in arcs: + * if isinstance(label, unicode): + * label = label.encode('utf8') # <<<<<<<<<<<<<< + * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) + * self.lattice[0][index].push_back(arc[0]) + */ + __pyx_t_5 = PyObject_GetAttr(__pyx_v_label, __pyx_n_s__encode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_22), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_v_label); + __pyx_v_label = __pyx_t_8; + __pyx_t_8 = 0; + goto __pyx_L8; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":39 + * if isinstance(label, unicode): + * label = label.encode('utf8') + * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) # <<<<<<<<<<<<<< + * self.lattice[0][index].push_back(arc[0]) + * del arc + */ + __pyx_t_11 = PyBytes_AsString(__pyx_v_label); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_v_cost); if (unlikely((__pyx_t_12 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_v_dist2next); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_arc = new LatticeArc(TD::Convert(((char *)__pyx_t_11)), __pyx_t_12, __pyx_t_13); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":40 + * label = label.encode('utf8') + * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) + * self.lattice[0][index].push_back(arc[0]) # <<<<<<<<<<<<<< + * del arc + * + */ + ((__pyx_v_self->lattice[0])[__pyx_v_index]).push_back((__pyx_v_arc[0])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":41 + * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) + * self.lattice[0][index].push_back(arc[0]) + * del arc # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + delete __pyx_v_arc; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("_cdec.Lattice.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_label); + __Pyx_XDECREF(__pyx_v_cost); + __Pyx_XDECREF(__pyx_v_dist2next); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self) { +static Py_ssize_t __pyx_pw_5_cdec_7Lattice_7__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_7Lattice_7__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Lattice_6__len__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":107 - * cdef mteval.EvaluationMetric* metric +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":43 + * del arc * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.scorer + * def __len__(self): # <<<<<<<<<<<<<< + * return self.lattice.size() * */ -static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self) { +static Py_ssize_t __pyx_pf_5_cdec_7Lattice_6__len__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { + Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); + __Pyx_RefNannySetupContext("__len__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":108 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":44 * - * def __dealloc__(self): - * del self.scorer # <<<<<<<<<<<<<< + * def __len__(self): + * return self.lattice.size() # <<<<<<<<<<<<<< * - * def evaluate(self, sentence): + * def __str__(self): */ - delete __pyx_v_self->scorer; + __pyx_r = __pyx_v_self->lattice->size(); + goto __pyx_L0; + __pyx_r = 0; + __pyx_L0:; __Pyx_RefNannyFinishContext(); + return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence); /*proto*/ -static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence) { +static PyObject *__pyx_pw_5_cdec_7Lattice_9__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Lattice_9__str__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("evaluate (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self), ((PyObject *)__pyx_v_sentence)); + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Lattice_8__str__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":110 - * del self.scorer +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":46 + * return self.lattice.size() + * + * def __str__(self): # <<<<<<<<<<<<<< + * return hypergraph.AsPLF(self.lattice[0], True).c_str() * - * def evaluate(self, sentence): # <<<<<<<<<<<<<< - * cdef vector[WordID] hyp - * cdef SufficientStats sf = SufficientStats() */ -static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, PyObject *__pyx_v_sentence) { - std::vector __pyx_v_hyp; - struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sf = 0; +static PyObject *__pyx_pf_5_cdec_7Lattice_8__str__(struct __pyx_obj_5_cdec_Lattice *__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("evaluate", 0); + __Pyx_RefNannySetupContext("__str__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":112 - * def evaluate(self, sentence): - * cdef vector[WordID] hyp - * cdef SufficientStats sf = SufficientStats() # <<<<<<<<<<<<<< - * sf.metric = self.metric - * sf.stats = new mteval.SufficientStats() + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":47 + * + * def __str__(self): + * return hypergraph.AsPLF(self.lattice[0], True).c_str() # <<<<<<<<<<<<<< + * + * def __iter__(self): */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_sf = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->lattice[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":113 - * cdef vector[WordID] hyp - * cdef SufficientStats sf = SufficientStats() - * sf.metric = self.metric # <<<<<<<<<<<<<< - * sf.stats = new mteval.SufficientStats() - * ConvertSentence(string(as_str(sentence.strip())), &hyp) - */ - __pyx_v_sf->metric = __pyx_v_self->metric; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":114 - * cdef SufficientStats sf = SufficientStats() - * sf.metric = self.metric - * sf.stats = new mteval.SufficientStats() # <<<<<<<<<<<<<< - * ConvertSentence(string(as_str(sentence.strip())), &hyp) - * self.scorer.get().Evaluate(hyp, sf.stats) - */ - __pyx_v_sf->stats = new SufficientStats(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 - * sf.metric = self.metric - * sf.stats = new mteval.SufficientStats() - * ConvertSentence(string(as_str(sentence.strip())), &hyp) # <<<<<<<<<<<<<< - * self.scorer.get().Evaluate(hyp, sf.stats) - * return sf - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_2, NULL)), (&__pyx_v_hyp)); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":116 - * sf.stats = new mteval.SufficientStats() - * ConvertSentence(string(as_str(sentence.strip())), &hyp) - * self.scorer.get().Evaluate(hyp, sf.stats) # <<<<<<<<<<<<<< - * return sf - * - */ - __pyx_v_self->scorer->get()->Evaluate(__pyx_v_hyp, __pyx_v_sf->stats); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":117 - * ConvertSentence(string(as_str(sentence.strip())), &hyp) - * self.scorer.get().Evaluate(hyp, sf.stats) - * return sf # <<<<<<<<<<<<<< - * - * def candidate_set(self): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_sf)); - __pyx_r = ((PyObject *)__pyx_v_sf); - goto __pyx_L0; + 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.SegmentEvaluator.evaluate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Lattice.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_sf); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5_cdec_7Lattice_12generator11(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5_cdec_7Lattice_11__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Lattice_11__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("candidate_set (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Lattice_10__iter__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":119 - * return sf - * - * def candidate_set(self): # <<<<<<<<<<<<<< - * return CandidateSet(self) +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":49 + * return hypergraph.AsPLF(self.lattice[0], True).c_str() * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(len(self)): */ -static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *__pyx_cur_scope; 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("candidate_set", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":120 - * - * def candidate_set(self): - * return CandidateSet(self) # <<<<<<<<<<<<<< - * - * cdef class Scorer: - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_CandidateSet)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + __Pyx_RefNannySetupContext("__iter__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_15___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_15___iter__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Lattice_12generator11, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } __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.SegmentEvaluator.candidate_set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Lattice.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* Python wrapper */ -static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - char *__pyx_v_name; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__name,0}; - int __pyx_r; +static PyObject *__pyx_gb_5_cdec_7Lattice_12generator11(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + Py_ssize_t __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[1] = {0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__name); - 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 125; __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_name = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_RefNannyFinishContext(); + return NULL; } - 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[4]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.Scorer.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_6Scorer___cinit__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self), __pyx_v_name); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":125 - * cdef string* name - * - * def __cinit__(self, char* name): # <<<<<<<<<<<<<< - * self.name = new string(name) + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":51 + * def __iter__(self): + * cdef unsigned i + * for i in range(len(self)): # <<<<<<<<<<<<<< + * yield self[i] * */ + __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; -static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, char *__pyx_v_name) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":126 - * - * def __cinit__(self, char* name): - * self.name = new string(name) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":52 + * cdef unsigned i + * for i in range(len(self)): + * yield self[i] # <<<<<<<<<<<<<< * * def __dealloc__(self): */ - __pyx_v_self->name = new std::string(__pyx_v_name); - - __pyx_r = 0; + __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 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_generator->resume_label = 1; + return __pyx_r; + __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[3]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return __pyx_r; + return NULL; } /* Python wrapper */ -static void __pyx_pw_5_cdec_6Scorer_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_6Scorer_3__dealloc__(PyObject *__pyx_v_self) { +static void __pyx_pw_5_cdec_7Lattice_14__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_7Lattice_14__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_6Scorer_2__dealloc__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self)); + __pyx_pf_5_cdec_7Lattice_13__dealloc__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":128 - * self.name = new string(name) +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":54 + * yield self[i] * * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.name + * del self.lattice * */ -static void __pyx_pf_5_cdec_6Scorer_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Scorer *__pyx_v_self) { +static void __pyx_pf_5_cdec_7Lattice_13__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":129 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":55 * * def __dealloc__(self): - * del self.name # <<<<<<<<<<<<<< + * del self.lattice # <<<<<<<<<<<<<< * - * def __call__(self, refs): + * def todot(self): */ - delete __pyx_v_self->name; + delete __pyx_v_self->lattice; __Pyx_RefNannyFinishContext(); } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_refs = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__refs,0}; +static PyObject *__pyx_pw_5_cdec_7Lattice_16todot(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Lattice_16todot(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__call__ (wrapper)", 0); - { - PyObject* values[1] = {0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__refs); - 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, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 131; __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_refs = values[0]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.Scorer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannySetupContext("todot (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Lattice_15todot(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_6Scorer_4__call__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self), __pyx_v_refs); + return __pyx_r; +} +static PyObject *__pyx_gb_5_cdec_7Lattice_5todot_2generator17(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Lattice_5todot_1lines(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyMethodDef __pyx_mdef_5_cdec_7Lattice_5todot_1lines = {__Pyx_NAMESTR("lines"), (PyCFunction)__pyx_pw_5_cdec_7Lattice_5todot_1lines, METH_NOARGS, __Pyx_DOCSTR(0)}; +static PyObject *__pyx_pw_5_cdec_7Lattice_5todot_1lines(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("lines (wrapper)", 0); + __pyx_self = __pyx_self; + __pyx_r = __pyx_pf_5_cdec_7Lattice_5todot_lines(__pyx_self); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":131 - * del self.name +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":58 * - * def __call__(self, refs): # <<<<<<<<<<<<<< - * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) - * if isinstance(refs, unicode) or isinstance(refs, str): + * def todot(self): + * def lines(): # <<<<<<<<<<<<<< + * yield 'digraph lattice {' + * yield 'rankdir = LR;' */ -static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs) { - EvaluationMetric *__pyx_v_metric; - std::vector > *__pyx_v_refsv; - std::vector *__pyx_v_refv; - PyObject *__pyx_v_ref = NULL; - struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator = 0; +static PyObject *__pyx_pf_5_cdec_7Lattice_5todot_lines(PyObject *__pyx_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - Py_ssize_t __pyx_t_5; - PyObject *(*__pyx_t_6)(PyObject *); - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__call__", 0); - __Pyx_INCREF(__pyx_v_refs); + __Pyx_RefNannySetupContext("lines", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *)__pyx_ptype_5_cdec___pyx_scope_struct_17_lines->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_17_lines, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *) __Pyx_CyFunction_GetClosure(__pyx_self); + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Lattice_5todot_2generator17, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":132 - * - * def __call__(self, refs): - * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) # <<<<<<<<<<<<<< - * if isinstance(refs, unicode) or isinstance(refs, str): - * refs = [refs] - */ - __pyx_v_metric = EvaluationMetric::Instance((__pyx_v_self->name[0])); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Lattice.todot.lines", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":133 - * def __call__(self, refs): - * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) - * if isinstance(refs, unicode) or isinstance(refs, str): # <<<<<<<<<<<<<< - * refs = [refs] - * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() - */ - __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_refs, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!__pyx_t_2) { - __pyx_t_1 = ((PyObject *)((PyObject*)(&PyString_Type))); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_refs, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = __pyx_t_3; - } else { - __pyx_t_4 = __pyx_t_2; +static PyObject *__pyx_gb_5_cdec_7Lattice_5todot_2generator17(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *(*__pyx_t_4)(PyObject *); + PyObject *__pyx_t_5 = NULL; + Py_ssize_t __pyx_t_6; + PyObject *(*__pyx_t_7)(PyObject *); + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *(*__pyx_t_12)(PyObject *); + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L4_resume_from_yield; + case 2: goto __pyx_L5_resume_from_yield; + case 3: goto __pyx_L6_resume_from_yield; + case 4: goto __pyx_L13_resume_from_yield; + case 5: goto __pyx_L14_resume_from_yield; + case 6: goto __pyx_L15_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_RefNannyFinishContext(); + return NULL; } - if (__pyx_t_4) { + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":134 - * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) - * if isinstance(refs, unicode) or isinstance(refs, str): - * refs = [refs] # <<<<<<<<<<<<<< - * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() - * cdef vector[WordID]* refv + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":59 + * def todot(self): + * def lines(): + * yield 'digraph lattice {' # <<<<<<<<<<<<<< + * yield 'rankdir = LR;' + * yield 'node [shape=circle];' */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_refs); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_refs); - __Pyx_GIVEREF(__pyx_v_refs); - __Pyx_DECREF(__pyx_v_refs); - __pyx_v_refs = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - goto __pyx_L3; - } - __pyx_L3:; + __Pyx_INCREF(((PyObject *)__pyx_kp_s_23)); + __pyx_r = ((PyObject *)__pyx_kp_s_23); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L4_resume_from_yield:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":135 - * if isinstance(refs, unicode) or isinstance(refs, str): - * refs = [refs] - * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() # <<<<<<<<<<<<<< - * cdef vector[WordID]* refv - * cdef bytes ref_str + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":60 + * def lines(): + * yield 'digraph lattice {' + * yield 'rankdir = LR;' # <<<<<<<<<<<<<< + * yield 'node [shape=circle];' + * for i in range(len(self)): */ - __pyx_v_refsv = new std::vector >(); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_24)); + __pyx_r = ((PyObject *)__pyx_kp_s_24); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 2; + return __pyx_r; + __pyx_L5_resume_from_yield:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":138 - * cdef vector[WordID]* refv - * cdef bytes ref_str - * for ref in refs: # <<<<<<<<<<<<<< - * refv = new vector[WordID]() - * ConvertSentence(string(as_str(ref.strip())), refv) + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":61 + * yield 'digraph lattice {' + * yield 'rankdir = LR;' + * yield 'node [shape=circle];' # <<<<<<<<<<<<<< + * for i in range(len(self)): + * for label, weight, delta in self[i]: */ - if (PyList_CheckExact(__pyx_v_refs) || PyTuple_CheckExact(__pyx_v_refs)) { - __pyx_t_1 = __pyx_v_refs; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0; - __pyx_t_6 = NULL; + __Pyx_INCREF(((PyObject *)__pyx_kp_s_25)); + __pyx_r = ((PyObject *)__pyx_kp_s_25); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 3; + return __pyx_r; + __pyx_L6_resume_from_yield:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":62 + * yield 'rankdir = LR;' + * yield 'node [shape=circle];' + * for i in range(len(self)): # <<<<<<<<<<<<<< + * for label, weight, delta in self[i]: + * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) + */ + if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } + __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = 0; + __pyx_t_4 = NULL; } else { - __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_refs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; + __pyx_t_2 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; for (;;) { - if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; - } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_3)) break; + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; } else { - __pyx_t_7 = __pyx_t_6(__pyx_t_1); - if (unlikely(!__pyx_t_7)) { + __pyx_t_1 = __pyx_t_4(__pyx_t_3); + if (unlikely(!__pyx_t_1)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } - __Pyx_GOTREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_t_1); } - __Pyx_XDECREF(__pyx_v_ref); - __pyx_v_ref = __pyx_t_7; - __pyx_t_7 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_i); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_i); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_i = __pyx_t_1; + __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":139 - * cdef bytes ref_str - * for ref in refs: - * refv = new vector[WordID]() # <<<<<<<<<<<<<< - * ConvertSentence(string(as_str(ref.strip())), refv) - * refsv.push_back(refv[0]) - */ - __pyx_v_refv = new std::vector(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":140 - * for ref in refs: - * refv = new vector[WordID]() - * ConvertSentence(string(as_str(ref.strip())), refv) # <<<<<<<<<<<<<< - * refsv.push_back(refv[0]) - * del refv - */ - __pyx_t_7 = PyObject_GetAttr(__pyx_v_ref, __pyx_n_s__strip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_8, NULL)), __pyx_v_refv); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":141 - * refv = new vector[WordID]() - * ConvertSentence(string(as_str(ref.strip())), refv) - * refsv.push_back(refv[0]) # <<<<<<<<<<<<<< - * del refv - * cdef unsigned i + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":63 + * yield 'node [shape=circle];' + * for i in range(len(self)): + * for label, weight, delta in self[i]: # <<<<<<<<<<<<<< + * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) + * yield '%d [shape=doublecircle]' % len(self) */ - __pyx_v_refsv->push_back((__pyx_v_refv[0])); + __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_5 = __pyx_t_1; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; + __pyx_t_7 = NULL; + } else { + __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_5)) { + if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break; + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; + } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_5)) { + if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break; + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; + } else { + __pyx_t_1 = __pyx_t_7(__pyx_t_5); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { + PyObject* sequence = __pyx_t_1; + if (likely(PyTuple_CheckExact(sequence))) { + if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { + if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); + } else { + if (unlikely(PyList_GET_SIZE(sequence) != 3)) { + if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_8 = PyList_GET_ITEM(sequence, 0); + __pyx_t_9 = PyList_GET_ITEM(sequence, 1); + __pyx_t_10 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_11 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; + index = 0; __pyx_t_8 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_8)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + index = 1; __pyx_t_9 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_9)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_9); + index = 2; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L12_unpacking_done; + __pyx_L11_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[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L12_unpacking_done:; + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_label); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_label); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_cur_scope->__pyx_v_label = __pyx_t_8; + __pyx_t_8 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_weight); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_weight); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_v_weight = __pyx_t_9; + __pyx_t_9 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_delta); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_delta); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_delta = __pyx_t_10; + __pyx_t_10 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":142 - * ConvertSentence(string(as_str(ref.strip())), refv) - * refsv.push_back(refv[0]) - * del refv # <<<<<<<<<<<<<< - * cdef unsigned i - * cdef SegmentEvaluator evaluator = SegmentEvaluator() + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":64 + * for i in range(len(self)): + * for label, weight, delta in self[i]: + * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) # <<<<<<<<<<<<<< + * yield '%d [shape=doublecircle]' % len(self) + * yield '}' */ - delete __pyx_v_refv; + __pyx_t_1 = PyNumber_Add(__pyx_cur_scope->__pyx_v_i, __pyx_cur_scope->__pyx_v_delta); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_label, __pyx_n_s__replace); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_k_tuple_29), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_cur_scope->__pyx_v_i); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_t_1 = 0; + __pyx_t_9 = 0; + __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_26), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __pyx_r = ((PyObject *)__pyx_t_9); + __pyx_t_9 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; + __Pyx_XGIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; + __Pyx_XGIVEREF(__pyx_t_5); + __pyx_cur_scope->__pyx_t_3 = __pyx_t_5; + __pyx_cur_scope->__pyx_t_4 = __pyx_t_6; + __pyx_cur_scope->__pyx_t_5 = __pyx_t_7; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 4; + return __pyx_r; + __pyx_L13_resume_from_yield:; + __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_t_3); + __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; + __pyx_t_5 = __pyx_cur_scope->__pyx_t_3; + __pyx_cur_scope->__pyx_t_3 = 0; + __Pyx_XGOTREF(__pyx_t_5); + __pyx_t_6 = __pyx_cur_scope->__pyx_t_4; + __pyx_t_7 = __pyx_cur_scope->__pyx_t_5; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":144 - * del refv - * cdef unsigned i - * cdef SegmentEvaluator evaluator = SegmentEvaluator() # <<<<<<<<<<<<<< - * evaluator.metric = metric - * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SegmentEvaluator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_evaluator = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":145 - * cdef unsigned i - * cdef SegmentEvaluator evaluator = SegmentEvaluator() - * evaluator.metric = metric # <<<<<<<<<<<<<< - * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) - * del refsv # in theory should not delete but store in SegmentEvaluator - */ - __pyx_v_evaluator->metric = __pyx_v_metric; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":146 - * cdef SegmentEvaluator evaluator = SegmentEvaluator() - * evaluator.metric = metric - * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) # <<<<<<<<<<<<<< - * del refsv # in theory should not delete but store in SegmentEvaluator - * return evaluator - */ - __pyx_v_evaluator->scorer = new boost::shared_ptr(__pyx_v_metric->CreateSegmentEvaluator((__pyx_v_refsv[0]))); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":147 - * evaluator.metric = metric - * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) - * del refsv # in theory should not delete but store in SegmentEvaluator # <<<<<<<<<<<<<< - * return evaluator - * + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":65 + * for label, weight, delta in self[i]: + * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) + * yield '%d [shape=doublecircle]' % len(self) # <<<<<<<<<<<<<< + * yield '}' + * return '\n'.join(lines()).encode('utf8') */ - delete __pyx_v_refsv; + __pyx_t_3 = ((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_2 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_30), __pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = ((PyObject *)__pyx_t_5); + __pyx_t_5 = 0; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 5; + return __pyx_r; + __pyx_L14_resume_from_yield:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":148 - * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) - * del refsv # in theory should not delete but store in SegmentEvaluator - * return evaluator # <<<<<<<<<<<<<< - * - * def __str__(self): + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":66 + * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) + * yield '%d [shape=doublecircle]' % len(self) + * yield '}' # <<<<<<<<<<<<<< + * return '\n'.join(lines()).encode('utf8') */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_evaluator)); - __pyx_r = ((PyObject *)__pyx_v_evaluator); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_31)); + __pyx_r = ((PyObject *)__pyx_kp_s_31); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 6; + return __pyx_r; + __pyx_L15_resume_from_yield:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("_cdec.Scorer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("lines", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XDECREF(__pyx_v_ref); - __Pyx_XDECREF((PyObject *)__pyx_v_evaluator); - __Pyx_XDECREF(__pyx_v_refs); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_6Scorer_7__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_6Scorer_7__str__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_6Scorer_6__str__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self)); + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return __pyx_r; + return NULL; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":150 - * return evaluator - * - * def __str__(self): # <<<<<<<<<<<<<< - * return self.name.c_str() +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":57 + * del self.lattice * + * def todot(self): # <<<<<<<<<<<<<< + * def lines(): + * yield 'digraph lattice {' */ -static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_7Lattice_15todot(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *__pyx_cur_scope; + PyObject *__pyx_v_lines = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__str__", 0); + __Pyx_RefNannySetupContext("todot", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *)__pyx_ptype_5_cdec___pyx_scope_struct_16_todot->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_16_todot, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":151 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":58 * - * def __str__(self): - * return self.name.c_str() # <<<<<<<<<<<<<< - * - * BLEU = Scorer('IBM_BLEU') + * def todot(self): + * def lines(): # <<<<<<<<<<<<<< + * yield 'digraph lattice {' + * yield 'rankdir = LR;' */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(__pyx_v_self->name->c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_r = ((PyObject *)__pyx_t_1); + __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5_cdec_7Lattice_5todot_1lines, 0, ((PyObject*)__pyx_cur_scope), __pyx_n_s___cdec, ((PyObject *)__pyx_k_codeobj_33)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_lines = __pyx_t_1; __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":67 + * yield '%d [shape=doublecircle]' % len(self) + * yield '}' + * return '\n'.join(lines()).encode('utf8') # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_35), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_v_lines, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_36), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_AddTraceback("_cdec.Scorer.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec.Lattice.todot", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_lines); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* Python wrapper */ -static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - char *__pyx_v_config; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__config,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[1] = {0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__config); - 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __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 = 19; __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 = 19; __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:; - __pyx_r = __pyx_pf_5_cdec_7Decoder___cinit__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_config); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "_cdec.pyx":19 - * cdef DenseVector weights +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":3 + * cimport mteval * - * def __cinit__(self, char* config): # <<<<<<<<<<<<<< - * decoder.register_feature_functions() - * cdef istringstream* config_stream = new istringstream(config) + * cdef SufficientStats as_stats(x, y): # <<<<<<<<<<<<<< + * if isinstance(x, SufficientStats): + * return x */ -static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, char *__pyx_v_config) { - std::istringstream *__pyx_v_config_stream; - int __pyx_r; +static struct __pyx_obj_5_cdec_SufficientStats *__pyx_f_5_cdec_as_stats(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_stats = NULL; + struct __pyx_obj_5_cdec_SufficientStats *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); + __Pyx_RefNannySetupContext("as_stats", 0); - /* "_cdec.pyx":20 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":4 * - * def __cinit__(self, char* config): - * decoder.register_feature_functions() # <<<<<<<<<<<<<< - * cdef istringstream* config_stream = new istringstream(config) - * self.dec = new decoder.Decoder(config_stream) + * cdef SufficientStats as_stats(x, y): + * if isinstance(x, SufficientStats): # <<<<<<<<<<<<<< + * return x + * elif x == 0 and isinstance(y, SufficientStats): */ - register_feature_functions(); + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { - /* "_cdec.pyx":21 - * def __cinit__(self, char* config): - * decoder.register_feature_functions() - * cdef istringstream* config_stream = new istringstream(config) # <<<<<<<<<<<<<< - * self.dec = new decoder.Decoder(config_stream) - * del config_stream + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":5 + * cdef SufficientStats as_stats(x, y): + * if isinstance(x, SufficientStats): + * return x # <<<<<<<<<<<<<< + * elif x == 0 and isinstance(y, SufficientStats): + * stats = SufficientStats() */ - __pyx_v_config_stream = new std::istringstream(__pyx_v_config); + __Pyx_XDECREF(((PyObject *)__pyx_r)); + if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SufficientStats))))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_x); + __pyx_r = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_x); + goto __pyx_L0; + goto __pyx_L3; + } - /* "_cdec.pyx":22 - * decoder.register_feature_functions() - * cdef istringstream* config_stream = new istringstream(config) - * self.dec = new decoder.Decoder(config_stream) # <<<<<<<<<<<<<< - * del config_stream - * self.weights = DenseVector() + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":6 + * if isinstance(x, SufficientStats): + * return x + * elif x == 0 and isinstance(y, SufficientStats): # <<<<<<<<<<<<<< + * stats = SufficientStats() + * stats.stats = new mteval.SufficientStats() */ - __pyx_v_self->dec = new Decoder(__pyx_v_config_stream); + __pyx_t_1 = PyObject_RichCompare(__pyx_v_x, __pyx_int_0, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_y, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_2; + } + if (__pyx_t_4) { - /* "_cdec.pyx":23 - * cdef istringstream* config_stream = new istringstream(config) - * self.dec = new decoder.Decoder(config_stream) - * del config_stream # <<<<<<<<<<<<<< - * self.weights = DenseVector() - * self.weights.vector = &self.dec.CurrentWeightVector() + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":7 + * return x + * elif x == 0 and isinstance(y, SufficientStats): + * stats = SufficientStats() # <<<<<<<<<<<<<< + * stats.stats = new mteval.SufficientStats() + * stats.metric = ( y).metric */ - delete __pyx_v_config_stream; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_stats = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; - /* "_cdec.pyx":24 - * self.dec = new decoder.Decoder(config_stream) - * del config_stream - * self.weights = DenseVector() # <<<<<<<<<<<<<< - * self.weights.vector = &self.dec.CurrentWeightVector() + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":8 + * elif x == 0 and isinstance(y, SufficientStats): + * stats = SufficientStats() + * stats.stats = new mteval.SufficientStats() # <<<<<<<<<<<<<< + * stats.metric = ( y).metric + * return stats + */ + __pyx_v_stats->stats = new SufficientStats(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":9 + * stats = SufficientStats() + * stats.stats = new mteval.SufficientStats() + * stats.metric = ( y).metric # <<<<<<<<<<<<<< + * return stats * */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->weights); - __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); - __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_v_stats->metric = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_y)->metric; - /* "_cdec.pyx":25 - * del config_stream - * self.weights = DenseVector() - * self.weights.vector = &self.dec.CurrentWeightVector() # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":10 + * stats.stats = new mteval.SufficientStats() + * stats.metric = ( y).metric + * return stats # <<<<<<<<<<<<<< * - * def __dealloc__(self): + * cdef class Candidate: */ - __pyx_v_self->weights->vector = (&__pyx_v_self->dec->CurrentWeightVector()); + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_stats)); + __pyx_r = __pyx_v_stats; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; - __pyx_r = 0; + __pyx_r = ((struct __pyx_obj_5_cdec_SufficientStats *)Py_None); __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.Decoder.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_AddTraceback("_cdec.as_stats", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_stats); + __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_9Candidate_5words_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9Candidate_5words_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_7Decoder_2__dealloc__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9Candidate_5words___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* "_cdec.pyx":27 - * self.weights.vector = &self.dec.CurrentWeightVector() +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":17 * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.dec + * property words: + * def __get__(self): # <<<<<<<<<<<<<< + * return unicode(GetString(self.candidate.ewords).c_str(), encoding='utf8') * */ -static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); - /* "_cdec.pyx":28 - * - * def __dealloc__(self): - * del self.dec # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":18 + * property words: + * def __get__(self): + * return unicode(GetString(self.candidate.ewords).c_str(), encoding='utf8') # <<<<<<<<<<<<<< * - * property weights: + * property fmap: */ - delete __pyx_v_self->dec; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(TD::GetString(__pyx_v_self->candidate->ewords).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 18; __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[5]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__encoding), ((PyObject *)__pyx_n_s__utf8)) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec.Candidate.words.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); + return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_9Candidate_4fmap_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9Candidate_4fmap_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights___get__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_9Candidate_4fmap___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":31 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":21 * - * property weights: + * property fmap: * def __get__(self): # <<<<<<<<<<<<<< - * return self.weights - * + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) */ -static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_9Candidate_4fmap___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap = 0; 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("__get__", 0); - /* "_cdec.pyx":32 - * property weights: + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":22 + * property fmap: * def __get__(self): - * return self.weights # <<<<<<<<<<<<<< + * cdef SparseVector fmap = SparseVector() # <<<<<<<<<<<<<< + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) + * return fmap + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":23 + * def __get__(self): + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) # <<<<<<<<<<<<<< + * return fmap * - * def __set__(self, weights): + */ + __pyx_v_fmap->vector = new FastSparseVector(__pyx_v_self->candidate->fmap); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":24 + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) + * return fmap # <<<<<<<<<<<<<< + * + * cdef class SufficientStats: */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self->weights)); - __pyx_r = ((PyObject *)__pyx_v_self->weights); + __Pyx_INCREF(((PyObject *)__pyx_v_fmap)); + __pyx_r = ((PyObject *)__pyx_v_fmap); 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.Candidate.fmap.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_fmap); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_weights); /*proto*/ -static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_weights) { - int __pyx_r; +static PyObject *__pyx_pw_5_cdec_9Candidate_5score_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9Candidate_5score_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_2__set__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_weights)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9Candidate_5score___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":34 - * return self.weights +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":14 + * cdef class Candidate: + * cdef mteval.Candidate* candidate + * cdef public float score # <<<<<<<<<<<<<< * - * def __set__(self, weights): # <<<<<<<<<<<<<< - * if isinstance(weights, DenseVector): - * self.weights.vector[0] = ( weights).vector[0] + * property words: */ -static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_weights) { - PyObject *__pyx_v_fname = NULL; - PyObject *__pyx_v_fval = NULL; - int __pyx_r; +static PyObject *__pyx_pf_5_cdec_9Candidate_5score___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - Py_ssize_t __pyx_t_4; - PyObject *(*__pyx_t_5)(PyObject *); - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *(*__pyx_t_9)(PyObject *); + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->score); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_cdec.Candidate.score.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_9Candidate_5score_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_5_cdec_9Candidate_5score_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9Candidate_5score_2__set__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5_cdec_9Candidate_5score_2__set__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + float __pyx_t_1; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __pyx_PyFloat_AsFloat(__pyx_v_value); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->score = __pyx_t_1; - /* "_cdec.pyx":35 - * - * def __set__(self, weights): - * if isinstance(weights, DenseVector): # <<<<<<<<<<<<<< - * self.weights.vector[0] = ( weights).vector[0] - * elif isinstance(weights, SparseVector): - */ - __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Candidate.score.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":36 - * def __set__(self, weights): - * if isinstance(weights, DenseVector): - * self.weights.vector[0] = ( weights).vector[0] # <<<<<<<<<<<<<< - * elif isinstance(weights, SparseVector): - * self.weights.vector.clear() - */ - (__pyx_v_self->weights->vector[0]) = (((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_weights)->vector[0]); - goto __pyx_L3; - } +/* Python wrapper */ +static void __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_15SufficientStats___dealloc__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} - /* "_cdec.pyx":37 - * if isinstance(weights, DenseVector): - * self.weights.vector[0] = ( weights).vector[0] - * elif isinstance(weights, SparseVector): # <<<<<<<<<<<<<< - * self.weights.vector.clear() - * (( weights).vector[0]).init_vector(self.weights.vector) +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":30 + * cdef mteval.EvaluationMetric* metric + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.stats + * */ - __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - /* "_cdec.pyx":38 - * self.weights.vector[0] = ( weights).vector[0] - * elif isinstance(weights, SparseVector): - * self.weights.vector.clear() # <<<<<<<<<<<<<< - * (( weights).vector[0]).init_vector(self.weights.vector) - * elif isinstance(weights, dict): - */ - __pyx_v_self->weights->vector->clear(); +static void __pyx_pf_5_cdec_15SufficientStats___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "_cdec.pyx":39 - * elif isinstance(weights, SparseVector): - * self.weights.vector.clear() - * (( weights).vector[0]).init_vector(self.weights.vector) # <<<<<<<<<<<<<< - * elif isinstance(weights, dict): - * for fname, fval in weights.items(): + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":31 + * + * def __dealloc__(self): + * del self.stats # <<<<<<<<<<<<<< + * + * property score: */ - (((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_weights)->vector[0]).init_vector(__pyx_v_self->weights->vector); - goto __pyx_L3; - } + delete __pyx_v_self->stats; - /* "_cdec.pyx":40 - * self.weights.vector.clear() - * (( weights).vector[0]).init_vector(self.weights.vector) - * elif isinstance(weights, dict): # <<<<<<<<<<<<<< - * for fname, fval in weights.items(): - * self.weights[fname] = fval - */ - __pyx_t_1 = ((PyObject *)((PyObject*)(&PyDict_Type))); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { + __Pyx_RefNannyFinishContext(); +} - /* "_cdec.pyx":41 - * (( weights).vector[0]).init_vector(self.weights.vector) - * elif isinstance(weights, dict): - * for fname, fval in weights.items(): # <<<<<<<<<<<<<< - * self.weights[fname] = fval - * else: - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_weights, __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0; - __pyx_t_5 = NULL; - } else { - __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; - } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; - } else { - __pyx_t_3 = __pyx_t_5(__pyx_t_1); - if (unlikely(!__pyx_t_3)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { - PyObject* sequence = __pyx_t_3; - if (likely(PyTuple_CheckExact(sequence))) { - 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 = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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 = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_6 = PyList_GET_ITEM(sequence, 0); - __pyx_t_7 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_8 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; - index = 0; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_6); - index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - goto __pyx_L7_unpacking_done; - __pyx_L6_unpacking_failed:; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L7_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_fname); - __pyx_v_fname = __pyx_t_6; - __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_v_fval); - __pyx_v_fval = __pyx_t_7; - __pyx_t_7 = 0; +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_5score_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_5score_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_5score___get__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":42 - * elif isinstance(weights, dict): - * for fname, fval in weights.items(): - * self.weights[fname] = fval # <<<<<<<<<<<<<< - * else: - * raise TypeError('cannot initialize weights with %s' % type(weights)) +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":34 + * + * property score: + * def __get__(self): # <<<<<<<<<<<<<< + * return self.metric.ComputeScore(self.stats[0]) + * */ - if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_v_fname, __pyx_v_fval) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L3; - } - /*else*/ { - /* "_cdec.pyx":44 - * self.weights[fname] = fval - * else: - * raise TypeError('cannot initialize weights with %s' % type(weights)) # <<<<<<<<<<<<<< +static PyObject *__pyx_pf_5_cdec_15SufficientStats_5score___get__(struct __pyx_obj_5_cdec_SufficientStats *__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("__get__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":35 + * property score: + * def __get__(self): + * return self.metric.ComputeScore(self.stats[0]) # <<<<<<<<<<<<<< * - * def read_weights(self, cfg): + * property detail: */ - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_37), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L3:; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->metric->ComputeScore((__pyx_v_self->stats[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - __pyx_r = 0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("_cdec.Decoder.weights.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_AddTraceback("_cdec.SufficientStats.score.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_fname); - __Pyx_XDECREF(__pyx_v_fval); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_cfg); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_cfg) { +static PyObject *__pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_weights (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_4read_weights(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_cfg)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_6detail___get__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":46 - * raise TypeError('cannot initialize weights with %s' % type(weights)) +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":38 + * + * property detail: + * def __get__(self): # <<<<<<<<<<<<<< + * return self.metric.DetailedScore(self.stats[0]).c_str() * - * def read_weights(self, cfg): # <<<<<<<<<<<<<< - * with open(cfg) as fp: - * for line in fp: */ -static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_cfg) { - PyObject *__pyx_v_fp = NULL; - PyObject *__pyx_v_line = NULL; - PyObject *__pyx_v_fname = NULL; - PyObject *__pyx_v_value = NULL; +static PyObject *__pyx_pf_5_cdec_15SufficientStats_6detail___get__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - Py_ssize_t __pyx_t_8; - PyObject *(*__pyx_t_9)(PyObject *); - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *(*__pyx_t_12)(PyObject *); - double __pyx_t_13; - int __pyx_t_14; - PyObject *__pyx_t_15 = NULL; - int __pyx_t_16; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("read_weights", 0); + __Pyx_RefNannySetupContext("__get__", 0); - /* "_cdec.pyx":47 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":39 + * property detail: + * def __get__(self): + * return self.metric.DetailedScore(self.stats[0]).c_str() # <<<<<<<<<<<<<< * - * def read_weights(self, cfg): - * with open(cfg) as fp: # <<<<<<<<<<<<<< - * for line in fp: - * fname, value = line.split() + * def __len__(self): */ - /*with:*/ { - __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_GOTREF(__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 = 47; __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 = 47; __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 = 47; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /*try:*/ { - { - __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - /*try:*/ { - __Pyx_INCREF(__pyx_t_4); - __pyx_v_fp = __pyx_t_4; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(__pyx_v_self->metric->DetailedScore((__pyx_v_self->stats[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 39; __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; - /* "_cdec.pyx":48 - * def read_weights(self, cfg): - * with open(cfg) as fp: - * for line in fp: # <<<<<<<<<<<<<< - * fname, value = line.split() - * self.weights[fname.strip()] = float(value) + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.SufficientStats.detail.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_5_cdec_15SufficientStats_3__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_15SufficientStats_3__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_2__len__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":41 + * return self.metric.DetailedScore(self.stats[0]).c_str() + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.stats.size() + * */ - if (PyList_CheckExact(__pyx_v_fp) || PyTuple_CheckExact(__pyx_v_fp)) { - __pyx_t_4 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; - } else { - __pyx_t_2 = __pyx_t_9(__pyx_t_4); - if (unlikely(!__pyx_t_2)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF(__pyx_v_line); - __pyx_v_line = __pyx_t_2; - __pyx_t_2 = 0; - /* "_cdec.pyx":49 - * with open(cfg) as fp: - * for line in fp: - * fname, value = line.split() # <<<<<<<<<<<<<< - * self.weights[fname.strip()] = float(value) - * - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { - PyObject* sequence = __pyx_t_1; - if (likely(PyTuple_CheckExact(sequence))) { - 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 = 49; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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 = 49; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_10 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_11 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; - index = 0; __pyx_t_2 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_2)) goto __pyx_L18_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L18_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 = 49; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - goto __pyx_L19_unpacking_done; - __pyx_L18_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 = 49; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_L19_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_fname); - __pyx_v_fname = __pyx_t_2; - __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_v_value); - __pyx_v_value = __pyx_t_10; - __pyx_t_10 = 0; +static Py_ssize_t __pyx_pf_5_cdec_15SufficientStats_2__len__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); - /* "_cdec.pyx":50 - * for line in fp: - * fname, value = line.split() - * self.weights[fname.strip()] = float(value) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":42 * - * def translate(self, sentence, grammar=None): - */ - __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 = 50; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_1 = PyFloat_FromDouble(__pyx_t_13); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = PyObject_GetAttr(__pyx_v_fname, __pyx_n_s__strip); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_t_2, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L14_try_end; - __pyx_L7_error:; - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "_cdec.pyx":47 + * def __len__(self): + * return self.stats.size() # <<<<<<<<<<<<<< * - * def read_weights(self, cfg): - * with open(cfg) as fp: # <<<<<<<<<<<<<< - * for line in fp: - * fname, value = line.split() + * def __iter__(self): */ - /*except:*/ { - __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_1, &__pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __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 = 47; __pyx_clineno = __LINE__; goto __pyx_L9_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 = 47; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __pyx_t_16 = (!__pyx_t_14); - if (__pyx_t_16) { - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_ErrRestore(__pyx_t_4, __pyx_t_1, __pyx_t_2); - __pyx_t_4 = 0; __pyx_t_1 = 0; __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - goto __pyx_L22; - } - __pyx_L22:; - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L8_exception_handled; - } - __pyx_L9_except_error:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - goto __pyx_L1_error; - __pyx_L8_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - __pyx_L14_try_end:; - } - } - /*finally:*/ { - if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_38, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - goto __pyx_L23; - __pyx_L3_error:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L1_error; - __pyx_L23:; - } - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_r = __pyx_v_self->stats->size(); goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + + __pyx_r = 0; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_fp); - __Pyx_XDECREF(__pyx_v_line); - __Pyx_XDECREF(__pyx_v_fname); - __Pyx_XDECREF(__pyx_v_value); - __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator12(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_sentence = 0; - PyObject *__pyx_v_grammar = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sentence,&__pyx_n_s__grammar,0}; +static PyObject *__pyx_pw_5_cdec_15SufficientStats_5__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_5__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("translate (wrapper)", 0); - { - PyObject* values[2] = {0,0}; - - /* "_cdec.pyx":52 - * self.weights[fname.strip()] = float(value) - * - * def translate(self, sentence, grammar=None): # <<<<<<<<<<<<<< - * if isinstance(sentence, unicode): - * inp = sentence.strip().encode('utf8') - */ - values[1] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sentence); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grammar); - if (value) { values[1] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "translate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_sentence = values[0]; - __pyx_v_grammar = values[1]; - } - 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 = 52; __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:; - __pyx_r = __pyx_pf_5_cdec_7Decoder_6translate(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_sentence, __pyx_v_grammar); + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_4__iter__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_sentence, PyObject *__pyx_v_grammar) { - PyObject *__pyx_v_inp = NULL; - BasicObserver __pyx_v_observer; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hg = 0; +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":44 + * return self.stats.size() + * + * def __iter__(self): # <<<<<<<<<<<<<< + * for i in range(len(self)): + * yield self.stats[0][i] + */ + +static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - char *__pyx_t_4; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("translate", 0); - - /* "_cdec.pyx":53 - * - * def translate(self, sentence, grammar=None): - * if isinstance(sentence, unicode): # <<<<<<<<<<<<<< - * inp = sentence.strip().encode('utf8') - * elif isinstance(sentence, str): - */ - __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { + __Pyx_RefNannySetupContext("__iter__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_18___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_18___iter__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_15SufficientStats_6generator12, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } - /* "_cdec.pyx":54 - * def translate(self, sentence, grammar=None): - * if isinstance(sentence, unicode): - * inp = sentence.strip().encode('utf8') # <<<<<<<<<<<<<< - * elif isinstance(sentence, str): - * inp = sentence.strip() - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_39), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_inp = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3; - } - - /* "_cdec.pyx":55 - * if isinstance(sentence, unicode): - * inp = sentence.strip().encode('utf8') - * elif isinstance(sentence, str): # <<<<<<<<<<<<<< - * inp = sentence.strip() - * elif isinstance(sentence, Lattice): - */ - __pyx_t_3 = ((PyObject *)((PyObject*)(&PyString_Type))); - __Pyx_INCREF(__pyx_t_3); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_2) { + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.SufficientStats.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":56 - * inp = sentence.strip().encode('utf8') - * elif isinstance(sentence, str): - * inp = sentence.strip() # <<<<<<<<<<<<<< - * elif isinstance(sentence, Lattice): - * inp = str(sentence) # PLF format - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); 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_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_inp = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L3; +static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator12(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *(*__pyx_t_4)(PyObject *); + unsigned int __pyx_t_5; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[5]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "_cdec.pyx":57 - * elif isinstance(sentence, str): - * inp = sentence.strip() - * elif isinstance(sentence, Lattice): # <<<<<<<<<<<<<< - * inp = str(sentence) # PLF format - * else: - */ - __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "_cdec.pyx":58 - * inp = sentence.strip() - * elif isinstance(sentence, Lattice): - * inp = str(sentence) # PLF format # <<<<<<<<<<<<<< - * else: - * raise TypeError('Cannot translate input type %s' % type(sentence)) + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":45 + * + * def __iter__(self): + * for i in range(len(self)): # <<<<<<<<<<<<<< + * yield self.stats[0][i] + * */ - __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(__pyx_t_1); - __Pyx_INCREF(__pyx_v_sentence); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_sentence); - __Pyx_GIVEREF(__pyx_v_sentence); - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_1 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_v_inp = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3; + __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; } - /*else*/ { + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { + if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_3)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { + if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; + } else { + __pyx_t_2 = __pyx_t_4(__pyx_t_3); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_i); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_i); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + __pyx_t_2 = 0; - /* "_cdec.pyx":60 - * inp = str(sentence) # PLF format - * else: - * raise TypeError('Cannot translate input type %s' % type(sentence)) # <<<<<<<<<<<<<< - * if grammar: - * self.dec.SetSentenceGrammarFromString(string( grammar)) + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":46 + * def __iter__(self): + * for i in range(len(self)): + * yield self.stats[0][i] # <<<<<<<<<<<<<< + * + * def __iadd__(SufficientStats self, SufficientStats other): */ - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_40), ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 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 = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_i); if (unlikely((__pyx_t_5 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyFloat_FromDouble(((__pyx_cur_scope->__pyx_v_self->stats[0])[__pyx_t_5])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __Pyx_XGIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_t_3); + __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_L3:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} - /* "_cdec.pyx":61 - * else: - * raise TypeError('Cannot translate input type %s' % type(sentence)) - * if grammar: # <<<<<<<<<<<<<< - * self.dec.SetSentenceGrammarFromString(string( grammar)) - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_grammar); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_2) { +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iadd__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SufficientStats, 1, "other", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_7__iadd__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_other)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":62 - * raise TypeError('Cannot translate input type %s' % type(sentence)) - * if grammar: - * self.dec.SetSentenceGrammarFromString(string( grammar)) # <<<<<<<<<<<<<< - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - * self.dec.Decode(string(inp), &observer) +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":48 + * yield self.stats[0][i] + * + * def __iadd__(SufficientStats self, SufficientStats other): # <<<<<<<<<<<<<< + * self.stats[0] += other.stats[0] + * return self */ - __pyx_t_4 = PyBytes_AsString(__pyx_v_grammar); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->dec->SetSentenceGrammarFromString(std::string(((char *)__pyx_t_4))); - goto __pyx_L4; - } - __pyx_L4:; - /* "_cdec.pyx":63 - * if grammar: - * self.dec.SetSentenceGrammarFromString(string( grammar)) - * cdef decoder.BasicObserver observer = decoder.BasicObserver() # <<<<<<<<<<<<<< - * self.dec.Decode(string(inp), &observer) - * if observer.hypergraph == NULL: - */ - __pyx_v_observer = BasicObserver(); +static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__iadd__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_other) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iadd__", 0); - /* "_cdec.pyx":64 - * self.dec.SetSentenceGrammarFromString(string( grammar)) - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - * self.dec.Decode(string(inp), &observer) # <<<<<<<<<<<<<< - * if observer.hypergraph == NULL: - * raise ParseFailed() + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":49 + * + * def __iadd__(SufficientStats self, SufficientStats other): + * self.stats[0] += other.stats[0] # <<<<<<<<<<<<<< + * return self + * */ - __pyx_t_4 = PyBytes_AsString(__pyx_v_inp); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->dec->Decode(std::string(((char *)__pyx_t_4)), (&__pyx_v_observer)); + (__pyx_v_self->stats[0]) += (__pyx_v_other->stats[0]); - /* "_cdec.pyx":65 - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - * self.dec.Decode(string(inp), &observer) - * if observer.hypergraph == NULL: # <<<<<<<<<<<<<< - * raise ParseFailed() - * cdef Hypergraph hg = Hypergraph() - */ - __pyx_t_2 = (__pyx_v_observer.hypergraph == NULL); - if (__pyx_t_2) { + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":50 + * def __iadd__(SufficientStats self, SufficientStats other): + * self.stats[0] += other.stats[0] + * return self # <<<<<<<<<<<<<< + * + * def __add__(x, y): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); + goto __pyx_L0; - /* "_cdec.pyx":66 - * self.dec.Decode(string(inp), &observer) - * if observer.hypergraph == NULL: - * raise ParseFailed() # <<<<<<<<<<<<<< - * cdef Hypergraph hg = Hypergraph() - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_10__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_10__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__add__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_9__add__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":52 + * return self + * + * def __add__(x, y): # <<<<<<<<<<<<<< + * cdef SufficientStats sx = as_stats(x, y) + * cdef SufficientStats sy = as_stats(y, x) */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__ParseFailed); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L5; + +static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sx = 0; + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sy = 0; + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_result = 0; + 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("__add__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":53 + * + * def __add__(x, y): + * cdef SufficientStats sx = as_stats(x, y) # <<<<<<<<<<<<<< + * cdef SufficientStats sy = as_stats(y, x) + * cdef SufficientStats result = SufficientStats() + */ + __pyx_t_1 = ((PyObject *)__pyx_f_5_cdec_as_stats(__pyx_v_x, __pyx_v_y)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sx = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":54 + * def __add__(x, y): + * cdef SufficientStats sx = as_stats(x, y) + * cdef SufficientStats sy = as_stats(y, x) # <<<<<<<<<<<<<< + * cdef SufficientStats result = SufficientStats() + * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) + */ + __pyx_t_1 = ((PyObject *)__pyx_f_5_cdec_as_stats(__pyx_v_y, __pyx_v_x)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sy = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":55 + * cdef SufficientStats sx = as_stats(x, y) + * cdef SufficientStats sy = as_stats(y, x) + * cdef SufficientStats result = SufficientStats() # <<<<<<<<<<<<<< + * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) + * result.metric = sx.metric + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":56 + * cdef SufficientStats sy = as_stats(y, x) + * cdef SufficientStats result = SufficientStats() + * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) # <<<<<<<<<<<<<< + * result.metric = sx.metric + * return result + */ + __pyx_v_result->stats = new SufficientStats(operator+((__pyx_v_sx->stats[0]), (__pyx_v_sy->stats[0]))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":57 + * cdef SufficientStats result = SufficientStats() + * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) + * result.metric = sx.metric # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_v_result->metric = __pyx_v_sx->metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":58 + * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) + * result.metric = sx.metric + * return result # <<<<<<<<<<<<<< + * + * cdef class CandidateSet: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + 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.SufficientStats.__add__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_sx); + __Pyx_XDECREF((PyObject *)__pyx_v_sy); + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__evaluator,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__evaluator); + 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __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_evaluator = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)values[0]); } - __pyx_L5:; + 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[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.CandidateSet.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_evaluator), __pyx_ptype_5_cdec_SegmentEvaluator, 1, "evaluator", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12CandidateSet___cinit__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), __pyx_v_evaluator); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":65 + * cdef mteval.CandidateSet* cs + * + * def __cinit__(self, SegmentEvaluator evaluator): # <<<<<<<<<<<<<< + * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) + * self.metric = evaluator.metric + */ + +static int __pyx_pf_5_cdec_12CandidateSet___cinit__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":66 + * + * def __cinit__(self, SegmentEvaluator evaluator): + * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) # <<<<<<<<<<<<<< + * self.metric = evaluator.metric + * self.cs = new mteval.CandidateSet() + */ + __pyx_v_self->scorer = new boost::shared_ptr((__pyx_v_evaluator->scorer[0])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":67 + * def __cinit__(self, SegmentEvaluator evaluator): + * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) + * self.metric = evaluator.metric # <<<<<<<<<<<<<< + * self.cs = new mteval.CandidateSet() + * + */ + __pyx_v_self->metric = __pyx_v_evaluator->metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":68 + * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) + * self.metric = evaluator.metric + * self.cs = new mteval.CandidateSet() # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->cs = new training::CandidateSet(); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":70 + * self.cs = new mteval.CandidateSet() + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.scorer + * del self.cs + */ + +static void __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":71 + * + * def __dealloc__(self): + * del self.scorer # <<<<<<<<<<<<<< + * del self.cs + * + */ + delete __pyx_v_self->scorer; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":72 + * def __dealloc__(self): + * del self.scorer + * del self.cs # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + delete __pyx_v_self->cs; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_5_cdec_12CandidateSet_5__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_12CandidateSet_5__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12CandidateSet_4__len__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":74 + * del self.cs + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.cs.size() + * + */ + +static Py_ssize_t __pyx_pf_5_cdec_12CandidateSet_4__len__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":75 + * + * def __len__(self): + * return self.cs.size() # <<<<<<<<<<<<<< + * + * def __getitem__(self,int k): + */ + __pyx_r = __pyx_v_self->cs->size(); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_k); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_k) { + int __pyx_v_k; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + assert(__pyx_arg_k); { + __pyx_v_k = __Pyx_PyInt_AsInt(__pyx_arg_k); if (unlikely((__pyx_v_k == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.CandidateSet.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_12CandidateSet_6__getitem__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), ((int)__pyx_v_k)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":77 + * return self.cs.size() + * + * def __getitem__(self,int k): # <<<<<<<<<<<<<< + * if not 0 <= k < self.cs.size(): + * raise IndexError('candidate set index out of range') + */ + +static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, int __pyx_v_k) { + struct __pyx_obj_5_cdec_Candidate *__pyx_v_candidate = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__getitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":78 + * + * def __getitem__(self,int k): + * if not 0 <= k < self.cs.size(): # <<<<<<<<<<<<<< + * raise IndexError('candidate set index out of range') + * cdef Candidate candidate = Candidate() + */ + __pyx_t_1 = (0 <= __pyx_v_k); + if (__pyx_t_1) { + __pyx_t_1 = (__pyx_v_k < __pyx_v_self->cs->size()); + } + __pyx_t_2 = (!__pyx_t_1); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":79 + * def __getitem__(self,int k): + * if not 0 <= k < self.cs.size(): + * raise IndexError('candidate set index out of range') # <<<<<<<<<<<<<< + * cdef Candidate candidate = Candidate() + * candidate.candidate = &self.cs[0][k] + */ + __pyx_t_3 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_38), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":80 + * if not 0 <= k < self.cs.size(): + * raise IndexError('candidate set index out of range') + * cdef Candidate candidate = Candidate() # <<<<<<<<<<<<<< + * candidate.candidate = &self.cs[0][k] + * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) + */ + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Candidate)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_candidate = ((struct __pyx_obj_5_cdec_Candidate *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":81 + * raise IndexError('candidate set index out of range') + * cdef Candidate candidate = Candidate() + * candidate.candidate = &self.cs[0][k] # <<<<<<<<<<<<<< + * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) + * return candidate + */ + __pyx_v_candidate->candidate = (&((__pyx_v_self->cs[0])[__pyx_v_k])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 + * cdef Candidate candidate = Candidate() + * candidate.candidate = &self.cs[0][k] + * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) # <<<<<<<<<<<<<< + * return candidate + * + */ + __pyx_v_candidate->score = __pyx_v_self->metric->ComputeScore(((__pyx_v_self->cs[0])[__pyx_v_k]).eval_feats); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":83 + * candidate.candidate = &self.cs[0][k] + * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) + * return candidate # <<<<<<<<<<<<<< + * + * def __iter__(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_candidate)); + __pyx_r = ((PyObject *)__pyx_v_candidate); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec.CandidateSet.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_candidate); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator13(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_9__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_9__iter__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12CandidateSet_8__iter__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":85 + * return candidate + * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(len(self)): + */ + +static PyObject *__pyx_pf_5_cdec_12CandidateSet_8__iter__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__iter__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_19___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_19___iter__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12CandidateSet_10generator13, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.CandidateSet.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator13(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + Py_ssize_t __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[5]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":87 + * def __iter__(self): + * cdef unsigned i + * for i in range(len(self)): # <<<<<<<<<<<<<< + * yield self[i] + * + */ + __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":88 + * cdef unsigned i + * for i in range(len(self)): + * yield self[i] # <<<<<<<<<<<<<< + * + * def add_kbest(self, Hypergraph hypergraph, unsigned k): + */ + __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 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_generator->resume_label = 1; + return __pyx_r; + __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[5]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph = 0; + unsigned int __pyx_v_k; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__hypergraph,&__pyx_n_s__k,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("add_kbest (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__hypergraph); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, 1); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_kbest") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_hypergraph = ((struct __pyx_obj_5_cdec_Hypergraph *)values[0]); + __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.CandidateSet.add_kbest", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_hypergraph), __pyx_ptype_5_cdec_Hypergraph, 1, "hypergraph", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12CandidateSet_11add_kbest(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), __pyx_v_hypergraph, __pyx_v_k); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":90 + * yield self[i] + * + * def add_kbest(self, Hypergraph hypergraph, unsigned k): # <<<<<<<<<<<<<< + * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) + * + */ + +static PyObject *__pyx_pf_5_cdec_12CandidateSet_11add_kbest(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph, unsigned int __pyx_v_k) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("add_kbest", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":91 + * + * def add_kbest(self, Hypergraph hypergraph, unsigned k): + * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) # <<<<<<<<<<<<<< + * + * cdef class SegmentEvaluator: + */ + __pyx_v_self->cs->AddKBestCandidates((__pyx_v_hypergraph->hg[0]), __pyx_v_k, __pyx_v_self->scorer->get()); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":97 + * cdef mteval.EvaluationMetric* metric + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.scorer + * + */ + +static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":98 + * + * def __dealloc__(self): + * del self.scorer # <<<<<<<<<<<<<< + * + * def evaluate(self, sentence): + */ + delete __pyx_v_self->scorer; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence); /*proto*/ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("evaluate (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self), ((PyObject *)__pyx_v_sentence)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":100 + * del self.scorer + * + * def evaluate(self, sentence): # <<<<<<<<<<<<<< + * cdef vector[WordID] hyp + * cdef SufficientStats sf = SufficientStats() + */ + +static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, PyObject *__pyx_v_sentence) { + std::vector __pyx_v_hyp; + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sf = 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("evaluate", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":102 + * def evaluate(self, sentence): + * cdef vector[WordID] hyp + * cdef SufficientStats sf = SufficientStats() # <<<<<<<<<<<<<< + * sf.metric = self.metric + * sf.stats = new mteval.SufficientStats() + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sf = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":103 + * cdef vector[WordID] hyp + * cdef SufficientStats sf = SufficientStats() + * sf.metric = self.metric # <<<<<<<<<<<<<< + * sf.stats = new mteval.SufficientStats() + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + */ + __pyx_v_sf->metric = __pyx_v_self->metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":104 + * cdef SufficientStats sf = SufficientStats() + * sf.metric = self.metric + * sf.stats = new mteval.SufficientStats() # <<<<<<<<<<<<<< + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + * self.scorer.get().Evaluate(hyp, sf.stats) + */ + __pyx_v_sf->stats = new SufficientStats(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":105 + * sf.metric = self.metric + * sf.stats = new mteval.SufficientStats() + * ConvertSentence(string(as_str(sentence.strip())), &hyp) # <<<<<<<<<<<<<< + * self.scorer.get().Evaluate(hyp, sf.stats) + * return sf + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __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_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_2, NULL)), (&__pyx_v_hyp)); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":106 + * sf.stats = new mteval.SufficientStats() + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + * self.scorer.get().Evaluate(hyp, sf.stats) # <<<<<<<<<<<<<< + * return sf + * + */ + __pyx_v_self->scorer->get()->Evaluate(__pyx_v_hyp, __pyx_v_sf->stats); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":107 + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + * self.scorer.get().Evaluate(hyp, sf.stats) + * return sf # <<<<<<<<<<<<<< + * + * def candidate_set(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_sf)); + __pyx_r = ((PyObject *)__pyx_v_sf); + 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.SegmentEvaluator.evaluate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_sf); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("candidate_set (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":109 + * return sf + * + * def candidate_set(self): # <<<<<<<<<<<<<< + * return CandidateSet(self) + * + */ + +static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_obj_5_cdec_SegmentEvaluator *__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("candidate_set", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":110 + * + * def candidate_set(self): + * return CandidateSet(self) # <<<<<<<<<<<<<< + * + * cdef class Scorer: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_CandidateSet)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__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.SegmentEvaluator.candidate_set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + char *__pyx_v_name; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__name,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__name); + 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 115; __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_name = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 115; __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[5]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.Scorer.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_6Scorer___cinit__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self), __pyx_v_name); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 + * cdef string* name + * + * def __cinit__(self, char* name): # <<<<<<<<<<<<<< + * self.name = new string(name) + * + */ + +static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, char *__pyx_v_name) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":116 + * + * def __cinit__(self, char* name): + * self.name = new string(name) # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->name = new std::string(__pyx_v_name); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_6Scorer_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_6Scorer_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_6Scorer_2__dealloc__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":118 + * self.name = new string(name) + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.name + * + */ + +static void __pyx_pf_5_cdec_6Scorer_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Scorer *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":119 + * + * def __dealloc__(self): + * del self.name # <<<<<<<<<<<<<< + * + * def __call__(self, refs): + */ + delete __pyx_v_self->name; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_refs = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__refs,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__call__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__refs); + 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, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 121; __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_refs = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.Scorer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_6Scorer_4__call__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self), __pyx_v_refs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":121 + * del self.name + * + * def __call__(self, refs): # <<<<<<<<<<<<<< + * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) + * if isinstance(refs, unicode) or isinstance(refs, str): + */ + +static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs) { + EvaluationMetric *__pyx_v_metric; + std::vector > *__pyx_v_refsv; + std::vector *__pyx_v_refv; + PyObject *__pyx_v_ref = NULL; + struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + Py_ssize_t __pyx_t_5; + PyObject *(*__pyx_t_6)(PyObject *); + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__call__", 0); + __Pyx_INCREF(__pyx_v_refs); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":122 + * + * def __call__(self, refs): + * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) # <<<<<<<<<<<<<< + * if isinstance(refs, unicode) or isinstance(refs, str): + * refs = [refs] + */ + __pyx_v_metric = EvaluationMetric::Instance((__pyx_v_self->name[0])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":123 + * def __call__(self, refs): + * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) + * if isinstance(refs, unicode) or isinstance(refs, str): # <<<<<<<<<<<<<< + * refs = [refs] + * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_refs, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!__pyx_t_2) { + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyString_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_refs, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_2; + } + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":124 + * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) + * if isinstance(refs, unicode) or isinstance(refs, str): + * refs = [refs] # <<<<<<<<<<<<<< + * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() + * cdef vector[WordID]* refv + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_refs); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_refs); + __Pyx_GIVEREF(__pyx_v_refs); + __Pyx_DECREF(__pyx_v_refs); + __pyx_v_refs = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":125 + * if isinstance(refs, unicode) or isinstance(refs, str): + * refs = [refs] + * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() # <<<<<<<<<<<<<< + * cdef vector[WordID]* refv + * cdef bytes ref_str + */ + __pyx_v_refsv = new std::vector >(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":128 + * cdef vector[WordID]* refv + * cdef bytes ref_str + * for ref in refs: # <<<<<<<<<<<<<< + * refv = new vector[WordID]() + * ConvertSentence(string(as_str(ref.strip())), refv) + */ + if (PyList_CheckExact(__pyx_v_refs) || PyTuple_CheckExact(__pyx_v_refs)) { + __pyx_t_1 = __pyx_v_refs; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0; + __pyx_t_6 = NULL; + } else { + __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_refs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; + } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; + } else { + __pyx_t_7 = __pyx_t_6(__pyx_t_1); + if (unlikely(!__pyx_t_7)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_7); + } + __Pyx_XDECREF(__pyx_v_ref); + __pyx_v_ref = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":129 + * cdef bytes ref_str + * for ref in refs: + * refv = new vector[WordID]() # <<<<<<<<<<<<<< + * ConvertSentence(string(as_str(ref.strip())), refv) + * refsv.push_back(refv[0]) + */ + __pyx_v_refv = new std::vector(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":130 + * for ref in refs: + * refv = new vector[WordID]() + * ConvertSentence(string(as_str(ref.strip())), refv) # <<<<<<<<<<<<<< + * refsv.push_back(refv[0]) + * del refv + */ + __pyx_t_7 = PyObject_GetAttr(__pyx_v_ref, __pyx_n_s__strip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_8, NULL)), __pyx_v_refv); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":131 + * refv = new vector[WordID]() + * ConvertSentence(string(as_str(ref.strip())), refv) + * refsv.push_back(refv[0]) # <<<<<<<<<<<<<< + * del refv + * cdef unsigned i + */ + __pyx_v_refsv->push_back((__pyx_v_refv[0])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":132 + * ConvertSentence(string(as_str(ref.strip())), refv) + * refsv.push_back(refv[0]) + * del refv # <<<<<<<<<<<<<< + * cdef unsigned i + * cdef SegmentEvaluator evaluator = SegmentEvaluator() + */ + delete __pyx_v_refv; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":134 + * del refv + * cdef unsigned i + * cdef SegmentEvaluator evaluator = SegmentEvaluator() # <<<<<<<<<<<<<< + * evaluator.metric = metric + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SegmentEvaluator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_evaluator = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":135 + * cdef unsigned i + * cdef SegmentEvaluator evaluator = SegmentEvaluator() + * evaluator.metric = metric # <<<<<<<<<<<<<< + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + * del refsv # in theory should not delete but store in SegmentEvaluator + */ + __pyx_v_evaluator->metric = __pyx_v_metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":136 + * cdef SegmentEvaluator evaluator = SegmentEvaluator() + * evaluator.metric = metric + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) # <<<<<<<<<<<<<< + * del refsv # in theory should not delete but store in SegmentEvaluator + * return evaluator + */ + __pyx_v_evaluator->scorer = new boost::shared_ptr(__pyx_v_metric->CreateSegmentEvaluator((__pyx_v_refsv[0]))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":137 + * evaluator.metric = metric + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + * del refsv # in theory should not delete but store in SegmentEvaluator # <<<<<<<<<<<<<< + * return evaluator + * + */ + delete __pyx_v_refsv; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":138 + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + * del refsv # in theory should not delete but store in SegmentEvaluator + * return evaluator # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_evaluator)); + __pyx_r = ((PyObject *)__pyx_v_evaluator); + 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_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_cdec.Scorer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_ref); + __Pyx_XDECREF((PyObject *)__pyx_v_evaluator); + __Pyx_XDECREF(__pyx_v_refs); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_6Scorer_7__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_6Scorer_7__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_6Scorer_6__str__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":140 + * return evaluator + * + * def __str__(self): # <<<<<<<<<<<<<< + * return self.name.c_str() + * + */ + +static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer *__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__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":141 + * + * def __str__(self): + * return self.name.c_str() # <<<<<<<<<<<<<< + * + * BLEU = Scorer('IBM_BLEU') + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(__pyx_v_self->name->c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 141; __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.Scorer.__str__", __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_4generator14(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_3_make_config(PyObject *__pyx_self, PyObject *__pyx_v_config); /*proto*/ +static PyMethodDef __pyx_mdef_5_cdec_3_make_config = {__Pyx_NAMESTR("_make_config"), (PyCFunction)__pyx_pw_5_cdec_3_make_config, METH_O, __Pyx_DOCSTR(0)}; +static PyObject *__pyx_pw_5_cdec_3_make_config(PyObject *__pyx_self, PyObject *__pyx_v_config) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_make_config (wrapper)", 0); + __pyx_self = __pyx_self; + __pyx_r = __pyx_pf_5_cdec_2_make_config(__pyx_self, ((PyObject *)__pyx_v_config)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":27 + * class ParseFailed(Exception): pass + * + * def _make_config(config): # <<<<<<<<<<<<<< + * for key, value in config.items(): + * if isinstance(value, dict): + */ + +static PyObject *__pyx_pf_5_cdec_2_make_config(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_config) { + struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_make_config", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *)__pyx_ptype_5_cdec___pyx_scope_struct_20__make_config->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_20__make_config, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_config = __pyx_v_config; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_config); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_config); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_4generator14, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec._make_config", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5_cdec_4generator14(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *(*__pyx_t_4)(PyObject *); + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *(*__pyx_t_8)(PyObject *); + int __pyx_t_9; + Py_ssize_t __pyx_t_10; + PyObject *(*__pyx_t_11)(PyObject *); + PyObject *__pyx_t_12 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L13_resume_from_yield; + case 2: goto __pyx_L16_resume_from_yield; + case 3: goto __pyx_L17_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 = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "_cdec.pyx":28 + * + * def _make_config(config): + * for key, value in config.items(): # <<<<<<<<<<<<<< + * if isinstance(value, dict): + * for name, info in value.items(): + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_config, __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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 = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; + } else { + __pyx_t_2 = __pyx_t_4(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + if (likely(PyTuple_CheckExact(sequence))) { + 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 = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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 = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_5 = PyList_GET_ITEM(sequence, 0); + __pyx_t_6 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_5 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L7_unpacking_done; + __pyx_L6_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L7_unpacking_done:; + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_key); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_key); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_cur_scope->__pyx_v_key = __pyx_t_5; + __pyx_t_5 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_value); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_value); + __Pyx_GIVEREF(__pyx_t_6); + __pyx_cur_scope->__pyx_v_value = __pyx_t_6; + __pyx_t_6 = 0; + + /* "_cdec.pyx":29 + * def _make_config(config): + * for key, value in config.items(): + * if isinstance(value, dict): # <<<<<<<<<<<<<< + * for name, info in value.items(): + * yield key, '%s %s' % (name, info) + */ + __pyx_t_2 = ((PyObject *)((PyObject*)(&PyDict_Type))); + __Pyx_INCREF(__pyx_t_2); + __pyx_t_9 = __Pyx_TypeCheck(__pyx_cur_scope->__pyx_v_value, __pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_9) { + + /* "_cdec.pyx":30 + * for key, value in config.items(): + * if isinstance(value, dict): + * for name, info in value.items(): # <<<<<<<<<<<<<< + * yield key, '%s %s' % (name, info) + * elif isinstance(value, list): + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_value, __pyx_n_s__items); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyList_CheckExact(__pyx_t_6) || PyTuple_CheckExact(__pyx_t_6)) { + __pyx_t_2 = __pyx_t_6; __Pyx_INCREF(__pyx_t_2); __pyx_t_10 = 0; + __pyx_t_11 = NULL; + } else { + __pyx_t_10 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_11 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + for (;;) { + if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; + } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; + } else { + __pyx_t_6 = __pyx_t_11(__pyx_t_2); + if (unlikely(!__pyx_t_6)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_6); + } + if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) { + PyObject* sequence = __pyx_t_6; + if (likely(PyTuple_CheckExact(sequence))) { + 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 = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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 = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_5 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_12 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_12)->tp_iternext; + index = 0; __pyx_t_5 = __pyx_t_8(__pyx_t_12); if (unlikely(!__pyx_t_5)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + index = 1; __pyx_t_7 = __pyx_t_8(__pyx_t_12); if (unlikely(!__pyx_t_7)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_12), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L12_unpacking_done; + __pyx_L11_unpacking_failed:; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L12_unpacking_done:; + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_name); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_name); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_cur_scope->__pyx_v_name = __pyx_t_5; + __pyx_t_5 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_info); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_info); + __Pyx_GIVEREF(__pyx_t_7); + __pyx_cur_scope->__pyx_v_info = __pyx_t_7; + __pyx_t_7 = 0; + + /* "_cdec.pyx":31 + * if isinstance(value, dict): + * for name, info in value.items(): + * yield key, '%s %s' % (name, info) # <<<<<<<<<<<<<< + * elif isinstance(value, list): + * for name in value: + */ + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_name); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_cur_scope->__pyx_v_name); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_name); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_info); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_cur_scope->__pyx_v_info); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_info); + __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_39), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_7)); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_cur_scope->__pyx_v_key); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_t_7)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_7)); + __pyx_t_7 = 0; + __pyx_r = ((PyObject *)__pyx_t_6); + __pyx_t_6 = 0; + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __Pyx_XGIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_3 = __pyx_t_4; + __pyx_cur_scope->__pyx_t_4 = __pyx_t_10; + __pyx_cur_scope->__pyx_t_5 = __pyx_t_11; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L13_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_t_2); + __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_3; + __pyx_t_10 = __pyx_cur_scope->__pyx_t_4; + __pyx_t_11 = __pyx_cur_scope->__pyx_t_5; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L8; + } + + /* "_cdec.pyx":32 + * for name, info in value.items(): + * yield key, '%s %s' % (name, info) + * elif isinstance(value, list): # <<<<<<<<<<<<<< + * for name in value: + * yield key, name + */ + __pyx_t_2 = ((PyObject *)((PyObject*)(&PyList_Type))); + __Pyx_INCREF(__pyx_t_2); + __pyx_t_9 = __Pyx_TypeCheck(__pyx_cur_scope->__pyx_v_value, __pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_9) { + + /* "_cdec.pyx":33 + * yield key, '%s %s' % (name, info) + * elif isinstance(value, list): + * for name in value: # <<<<<<<<<<<<<< + * yield key, name + * else: + */ + if (PyList_CheckExact(__pyx_cur_scope->__pyx_v_value) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_value)) { + __pyx_t_2 = __pyx_cur_scope->__pyx_v_value; __Pyx_INCREF(__pyx_t_2); __pyx_t_10 = 0; + __pyx_t_11 = NULL; + } else { + __pyx_t_10 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_value); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_11 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; + } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; + } else { + __pyx_t_6 = __pyx_t_11(__pyx_t_2); + if (unlikely(!__pyx_t_6)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_6); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_name); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_name); + __Pyx_GIVEREF(__pyx_t_6); + __pyx_cur_scope->__pyx_v_name = __pyx_t_6; + __pyx_t_6 = 0; + + /* "_cdec.pyx":34 + * elif isinstance(value, list): + * for name in value: + * yield key, name # <<<<<<<<<<<<<< + * else: + * yield key, bytes(value) + */ + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_cur_scope->__pyx_v_key); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_name); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_cur_scope->__pyx_v_name); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_name); + __pyx_r = ((PyObject *)__pyx_t_6); + __pyx_t_6 = 0; + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __Pyx_XGIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_3 = __pyx_t_4; + __pyx_cur_scope->__pyx_t_4 = __pyx_t_10; + __pyx_cur_scope->__pyx_t_5 = __pyx_t_11; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 2; + return __pyx_r; + __pyx_L16_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_t_2); + __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_3; + __pyx_t_10 = __pyx_cur_scope->__pyx_t_4; + __pyx_t_11 = __pyx_cur_scope->__pyx_t_5; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L8; + } + /*else*/ { + + /* "_cdec.pyx":36 + * yield key, name + * else: + * yield key, bytes(value) # <<<<<<<<<<<<<< + * + * cdef class Decoder: + */ + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_value); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_value); + __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyBytes_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_key); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + __pyx_t_6 = 0; + __pyx_r = ((PyObject *)__pyx_t_2); + __pyx_t_2 = 0; + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_3 = __pyx_t_4; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 3; + return __pyx_r; + __pyx_L17_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_3; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L8:; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("_make_config", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_config_str = 0; + PyObject *__pyx_v_config = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__config_str,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + __pyx_v_config = PyDict_New(); if (unlikely(!__pyx_v_config)) return -1; + __Pyx_GOTREF(__pyx_v_config); + { + PyObject* values[1] = {0}; + + /* "_cdec.pyx":42 + * cdef DenseVector weights + * + * def __cinit__(self, config_str=None, **config): # <<<<<<<<<<<<<< + * """ Configuration can be given as a string: + * Decoder('formalism = scfg') + */ + values[0] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__config_str); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_config, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + 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; + } + } + __pyx_v_config_str = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 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_CLEAR(__pyx_v_config); + __Pyx_AddTraceback("_cdec.Decoder.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_7Decoder___cinit__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_config_str, __pyx_v_config); + __Pyx_XDECREF(__pyx_v_config); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_5_cdec_7Decoder_9__cinit___2generator18(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* "_cdec.pyx":53 + * 'csplit', 'tagger', 'lexalign'): + * raise InvalidConfig('formalism "%s" unknown' % formalism) + * config_str = '\n'.join('%s = %s' % kv for kv in _make_config(config)) # <<<<<<<<<<<<<< + * cdef istringstream* config_stream = new istringstream(config_str) + * self.dec = new decoder.Decoder(config_stream) + */ + +static PyObject *__pyx_pf_5_cdec_7Decoder_9__cinit___genexpr(PyObject *__pyx_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("genexpr", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *)__pyx_ptype_5_cdec___pyx_scope_struct_22_genexpr->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_22_genexpr, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *) __pyx_self; + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Decoder_9__cinit___2generator18, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Decoder.__cinit__.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5_cdec_7Decoder_9__cinit___2generator18(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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 = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___make_config); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_config)) { __Pyx_RaiseClosureNameError("config"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __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 = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_config); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_config); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_config); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; + } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; + } else { + __pyx_t_3 = __pyx_t_5(__pyx_t_2); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_kv); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_kv); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_kv = __pyx_t_3; + __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_40), __pyx_cur_scope->__pyx_v_kv); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_r = ((PyObject *)__pyx_t_3); + __pyx_t_3 = 0; + __Pyx_XGIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_4; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_5; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_2); + __pyx_t_4 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_5 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* "_cdec.pyx":42 + * cdef DenseVector weights + * + * def __cinit__(self, config_str=None, **config): # <<<<<<<<<<<<<< + * """ Configuration can be given as a string: + * Decoder('formalism = scfg') + */ + +static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_config_str, PyObject *__pyx_v_config) { + struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *__pyx_cur_scope; + PyObject *__pyx_v_formalism = NULL; + std::istringstream *__pyx_v_config_stream; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + char *__pyx_t_7; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *)__pyx_ptype_5_cdec___pyx_scope_struct_21___cinit__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_21___cinit__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return -1; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_config = __pyx_v_config; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_config); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_config); + __Pyx_INCREF(__pyx_v_config_str); + + /* "_cdec.pyx":48 + * Decoder(formalism='scfg') + * """ + * if config_str is None: # <<<<<<<<<<<<<< + * formalism = config.get('formalism', None) + * if formalism not in ('scfg', 'fst', 'lextrans', 'pb', + */ + __pyx_t_1 = (__pyx_v_config_str == Py_None); + if (__pyx_t_1) { + + /* "_cdec.pyx":49 + * """ + * if config_str is None: + * formalism = config.get('formalism', None) # <<<<<<<<<<<<<< + * if formalism not in ('scfg', 'fst', 'lextrans', 'pb', + * 'csplit', 'tagger', 'lexalign'): + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_config, __pyx_n_s__get); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_41), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_formalism = __pyx_t_3; + __pyx_t_3 = 0; + + /* "_cdec.pyx":50 + * if config_str is None: + * formalism = config.get('formalism', None) + * if formalism not in ('scfg', 'fst', 'lextrans', 'pb', # <<<<<<<<<<<<<< + * 'csplit', 'tagger', 'lexalign'): + * raise InvalidConfig('formalism "%s" unknown' % formalism) + */ + __Pyx_INCREF(__pyx_v_formalism); + __pyx_t_3 = __pyx_v_formalism; + __pyx_t_1 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__scfg), Py_NE); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (((int)__pyx_t_1)) { + __pyx_t_4 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__fst), Py_NE); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = ((int)__pyx_t_4); + } else { + __pyx_t_5 = ((int)__pyx_t_1); + } + if (__pyx_t_5) { + __pyx_t_1 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__lextrans), Py_NE); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = ((int)__pyx_t_1); + } else { + __pyx_t_4 = __pyx_t_5; + } + if (__pyx_t_4) { + __pyx_t_5 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__pb), Py_NE); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = ((int)__pyx_t_5); + } else { + __pyx_t_1 = __pyx_t_4; + } + if (__pyx_t_1) { + __pyx_t_4 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__csplit), Py_NE); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = ((int)__pyx_t_4); + } else { + __pyx_t_5 = __pyx_t_1; + } + if (__pyx_t_5) { + __pyx_t_1 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__tagger), Py_NE); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = ((int)__pyx_t_1); + } else { + __pyx_t_4 = __pyx_t_5; + } + if (__pyx_t_4) { + __pyx_t_5 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__lexalign), Py_NE); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = ((int)__pyx_t_5); + } else { + __pyx_t_1 = __pyx_t_4; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_4 = __pyx_t_1; + if (__pyx_t_4) { + + /* "_cdec.pyx":52 + * if formalism not in ('scfg', 'fst', 'lextrans', 'pb', + * 'csplit', 'tagger', 'lexalign'): + * raise InvalidConfig('formalism "%s" unknown' % formalism) # <<<<<<<<<<<<<< + * config_str = '\n'.join('%s = %s' % kv for kv in _make_config(config)) + * cdef istringstream* config_stream = new istringstream(config_str) + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__InvalidConfig); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_42), __pyx_v_formalism); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 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 = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L4; + } + __pyx_L4:; + + /* "_cdec.pyx":53 + * 'csplit', 'tagger', 'lexalign'): + * raise InvalidConfig('formalism "%s" unknown' % formalism) + * config_str = '\n'.join('%s = %s' % kv for kv in _make_config(config)) # <<<<<<<<<<<<<< + * cdef istringstream* config_stream = new istringstream(config_str) + * self.dec = new decoder.Decoder(config_stream) + */ + __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_35), __pyx_n_s__join); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = __pyx_pf_5_cdec_7Decoder_9__cinit___genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + __pyx_t_6 = 0; + __pyx_t_6 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_v_config_str); + __pyx_v_config_str = __pyx_t_6; + __pyx_t_6 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "_cdec.pyx":54 + * raise InvalidConfig('formalism "%s" unknown' % formalism) + * config_str = '\n'.join('%s = %s' % kv for kv in _make_config(config)) + * cdef istringstream* config_stream = new istringstream(config_str) # <<<<<<<<<<<<<< + * self.dec = new decoder.Decoder(config_stream) + * del config_stream + */ + __pyx_t_7 = PyBytes_AsString(__pyx_v_config_str); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_config_stream = new std::istringstream(__pyx_t_7); + + /* "_cdec.pyx":55 + * config_str = '\n'.join('%s = %s' % kv for kv in _make_config(config)) + * cdef istringstream* config_stream = new istringstream(config_str) + * self.dec = new decoder.Decoder(config_stream) # <<<<<<<<<<<<<< + * del config_stream + * self.weights = DenseVector() + */ + __pyx_v_self->dec = new Decoder(__pyx_v_config_stream); + + /* "_cdec.pyx":56 + * cdef istringstream* config_stream = new istringstream(config_str) + * self.dec = new decoder.Decoder(config_stream) + * del config_stream # <<<<<<<<<<<<<< + * self.weights = DenseVector() + * self.weights.vector = &self.dec.CurrentWeightVector() + */ + delete __pyx_v_config_stream; + + /* "_cdec.pyx":57 + * self.dec = new decoder.Decoder(config_stream) + * del config_stream + * self.weights = DenseVector() # <<<<<<<<<<<<<< + * self.weights.vector = &self.dec.CurrentWeightVector() + * + */ + __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_v_self->weights); + __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); + __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)__pyx_t_6); + __pyx_t_6 = 0; + + /* "_cdec.pyx":58 + * del config_stream + * self.weights = DenseVector() + * self.weights.vector = &self.dec.CurrentWeightVector() # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->weights->vector = (&__pyx_v_self->dec->CurrentWeightVector()); + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_cdec.Decoder.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_formalism); + __Pyx_XDECREF(__pyx_v_config_str); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_7Decoder_2__dealloc__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "_cdec.pyx":60 + * self.weights.vector = &self.dec.CurrentWeightVector() + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.dec + * + */ + +static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "_cdec.pyx":61 + * + * def __dealloc__(self): + * del self.dec # <<<<<<<<<<<<<< + * + * property weights: + */ + delete __pyx_v_self->dec; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights___get__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":64 + * + * property weights: + * def __get__(self): # <<<<<<<<<<<<<< + * return self.weights + * + */ + +static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + + /* "_cdec.pyx":65 + * property weights: + * def __get__(self): + * return self.weights # <<<<<<<<<<<<<< + * + * def __set__(self, weights): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->weights)); + __pyx_r = ((PyObject *)__pyx_v_self->weights); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_weights); /*proto*/ +static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_weights) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_2__set__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_weights)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":67 + * return self.weights + * + * def __set__(self, weights): # <<<<<<<<<<<<<< + * if isinstance(weights, DenseVector): + * self.weights.vector[0] = ( weights).vector[0] + */ + +static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_weights) { + PyObject *__pyx_v_fname = NULL; + PyObject *__pyx_v_fval = NULL; + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *(*__pyx_t_9)(PyObject *); + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); + + /* "_cdec.pyx":68 + * + * def __set__(self, weights): + * if isinstance(weights, DenseVector): # <<<<<<<<<<<<<< + * self.weights.vector[0] = ( weights).vector[0] + * elif isinstance(weights, SparseVector): + */ + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":69 + * def __set__(self, weights): + * if isinstance(weights, DenseVector): + * self.weights.vector[0] = ( weights).vector[0] # <<<<<<<<<<<<<< + * elif isinstance(weights, SparseVector): + * self.weights.vector.clear() + */ + (__pyx_v_self->weights->vector[0]) = (((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_weights)->vector[0]); + goto __pyx_L3; + } + + /* "_cdec.pyx":70 + * if isinstance(weights, DenseVector): + * self.weights.vector[0] = ( weights).vector[0] + * elif isinstance(weights, SparseVector): # <<<<<<<<<<<<<< + * self.weights.vector.clear() + * (( weights).vector[0]).init_vector(self.weights.vector) + */ + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":71 + * self.weights.vector[0] = ( weights).vector[0] + * elif isinstance(weights, SparseVector): + * self.weights.vector.clear() # <<<<<<<<<<<<<< + * (( weights).vector[0]).init_vector(self.weights.vector) + * elif isinstance(weights, dict): + */ + __pyx_v_self->weights->vector->clear(); + + /* "_cdec.pyx":72 + * elif isinstance(weights, SparseVector): + * self.weights.vector.clear() + * (( weights).vector[0]).init_vector(self.weights.vector) # <<<<<<<<<<<<<< + * elif isinstance(weights, dict): + * for fname, fval in weights.items(): + */ + (((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_weights)->vector[0]).init_vector(__pyx_v_self->weights->vector); + goto __pyx_L3; + } + + /* "_cdec.pyx":73 + * self.weights.vector.clear() + * (( weights).vector[0]).init_vector(self.weights.vector) + * elif isinstance(weights, dict): # <<<<<<<<<<<<<< + * for fname, fval in weights.items(): + * self.weights[fname] = fval + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyDict_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":74 + * (( weights).vector[0]).init_vector(self.weights.vector) + * elif isinstance(weights, dict): + * for fname, fval in weights.items(): # <<<<<<<<<<<<<< + * self.weights[fname] = fval + * else: + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_weights, __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; + } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; + } else { + __pyx_t_3 = __pyx_t_5(__pyx_t_1); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { + PyObject* sequence = __pyx_t_3; + if (likely(PyTuple_CheckExact(sequence))) { + 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 = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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 = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_6 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_8 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; + index = 0; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L7_unpacking_done; + __pyx_L6_unpacking_failed:; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L7_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_fname); + __pyx_v_fname = __pyx_t_6; + __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_v_fval); + __pyx_v_fval = __pyx_t_7; + __pyx_t_7 = 0; + + /* "_cdec.pyx":75 + * elif isinstance(weights, dict): + * for fname, fval in weights.items(): + * self.weights[fname] = fval # <<<<<<<<<<<<<< + * else: + * raise TypeError('cannot initialize weights with %s' % type(weights)) + */ + if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_v_fname, __pyx_v_fval) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "_cdec.pyx":77 + * self.weights[fname] = fval + * else: + * raise TypeError('cannot initialize weights with %s' % type(weights)) # <<<<<<<<<<<<<< + * + * property formalism: + */ + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_43), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_3 = PyTuple_New(1); 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); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_cdec.Decoder.weights.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_fname); + __Pyx_XDECREF(__pyx_v_fval); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Decoder_9formalism_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Decoder_9formalism_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_9formalism___get__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":80 + * + * property formalism: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef variables_map* conf = &self.dec.GetConf() + * return conf[0]['formalism'].as_str().c_str() + */ + +static PyObject *__pyx_pf_5_cdec_7Decoder_9formalism___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { + const boost::program_options::variables_map *__pyx_v_conf; + 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("__get__", 0); + + /* "_cdec.pyx":81 + * property formalism: + * def __get__(self): + * cdef variables_map* conf = &self.dec.GetConf() # <<<<<<<<<<<<<< + * return conf[0]['formalism'].as_str().c_str() + * + */ + __pyx_v_conf = (&__pyx_v_self->dec->GetConf()); + + /* "_cdec.pyx":82 + * def __get__(self): + * cdef variables_map* conf = &self.dec.GetConf() + * return conf[0]['formalism'].as_str().c_str() # <<<<<<<<<<<<<< + * + * def read_weights(self, weights): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(((__pyx_v_conf[0])[__pyx_k__formalism]).as().c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __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.Decoder.formalism.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_weights); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_weights) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_weights (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_4read_weights(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_weights)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":84 + * return conf[0]['formalism'].as_str().c_str() + * + * def read_weights(self, weights): # <<<<<<<<<<<<<< + * with open(weights) as fp: + * for line in fp: + */ + +static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_weights) { + PyObject *__pyx_v_fp = NULL; + PyObject *__pyx_v_line = NULL; + PyObject *__pyx_v_fname = NULL; + PyObject *__pyx_v_value = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *(*__pyx_t_13)(PyObject *); + double __pyx_t_14; + PyObject *__pyx_t_15 = NULL; + int __pyx_t_16; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_weights", 0); + + /* "_cdec.pyx":85 + * + * def read_weights(self, weights): + * with open(weights) as fp: # <<<<<<<<<<<<<< + * for line in fp: + * if line.strip().startswith('#'): continue + */ + /*with:*/ { + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_weights); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_weights); + __Pyx_GIVEREF(__pyx_v_weights); + __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 = 85; __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 = 85; __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 = 85; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_fp = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_cdec.pyx":86 + * def read_weights(self, weights): + * with open(weights) as fp: + * for line in fp: # <<<<<<<<<<<<<< + * if line.strip().startswith('#'): continue + * fname, value = line.split() + */ + if (PyList_CheckExact(__pyx_v_fp) || PyTuple_CheckExact(__pyx_v_fp)) { + __pyx_t_4 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else { + __pyx_t_2 = __pyx_t_9(__pyx_t_4); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF(__pyx_v_line); + __pyx_v_line = __pyx_t_2; + __pyx_t_2 = 0; + + /* "_cdec.pyx":87 + * with open(weights) as fp: + * for line in fp: + * if line.strip().startswith('#'): continue # <<<<<<<<<<<<<< + * fname, value = line.split() + * self.weights[fname.strip()] = float(value) + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__strip); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__startswith); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_45), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_10) { + goto __pyx_L16_continue; + goto __pyx_L18; + } + __pyx_L18:; + + /* "_cdec.pyx":88 + * for line in fp: + * if line.strip().startswith('#'): continue + * 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 = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __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 = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + if (likely(PyTuple_CheckExact(sequence))) { + 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 = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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 = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_11 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_12 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_13 = Py_TYPE(__pyx_t_12)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_1)) goto __pyx_L19_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_11 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_11)) goto __pyx_L19_unpacking_failed; + __Pyx_GOTREF(__pyx_t_11); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L20_unpacking_done; + __pyx_L19_unpacking_failed:; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_L20_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_fname); + __pyx_v_fname = __pyx_t_1; + __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_v_value); + __pyx_v_value = __pyx_t_11; + __pyx_t_11 = 0; + + /* "_cdec.pyx":89 + * if line.strip().startswith('#'): continue + * fname, value = line.split() + * self.weights[fname.strip()] = float(value) # <<<<<<<<<<<<<< + * + * def translate(self, sentence, grammar=None): + */ + __pyx_t_14 = __Pyx_PyObject_AsDouble(__pyx_v_value); if (unlikely(__pyx_t_14 == ((double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyFloat_FromDouble(__pyx_t_14); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_11 = PyObject_GetAttr(__pyx_v_fname, __pyx_n_s__strip); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_1 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_t_1, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_L16_continue:; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_cdec.pyx":85 + * + * def read_weights(self, weights): + * with open(weights) as fp: # <<<<<<<<<<<<<< + * for line in fp: + * if line.strip().startswith('#'): continue + */ + /*except:*/ { + __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_2, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_INCREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_15 = PyObject_Call(__pyx_t_3, __pyx_t_11, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_15); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_16 = (!__pyx_t_10); + if (__pyx_t_16) { + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_ErrRestore(__pyx_t_4, __pyx_t_2, __pyx_t_1); + __pyx_t_4 = 0; __pyx_t_2 = 0; __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L23; + } + __pyx_L23:; + __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_46, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L24; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L24:; + } + + __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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_fp); + __Pyx_XDECREF(__pyx_v_line); + __Pyx_XDECREF(__pyx_v_fname); + __Pyx_XDECREF(__pyx_v_value); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_sentence = 0; + PyObject *__pyx_v_grammar = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sentence,&__pyx_n_s__grammar,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("translate (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + + /* "_cdec.pyx":91 + * self.weights[fname.strip()] = float(value) + * + * def translate(self, sentence, grammar=None): # <<<<<<<<<<<<<< + * if isinstance(sentence, unicode): + * inp = sentence.strip().encode('utf8') + */ + values[1] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sentence); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grammar); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "translate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_sentence = values[0]; + __pyx_v_grammar = values[1]; + } + 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 = 91; __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:; + __pyx_r = __pyx_pf_5_cdec_7Decoder_6translate(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_sentence, __pyx_v_grammar); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_sentence, PyObject *__pyx_v_grammar) { + PyObject *__pyx_v_inp = NULL; + BasicObserver __pyx_v_observer; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hg = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + char *__pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("translate", 0); + + /* "_cdec.pyx":92 + * + * def translate(self, sentence, grammar=None): + * if isinstance(sentence, unicode): # <<<<<<<<<<<<<< + * inp = sentence.strip().encode('utf8') + * elif isinstance(sentence, str): + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":93 + * def translate(self, sentence, grammar=None): + * if isinstance(sentence, unicode): + * inp = sentence.strip().encode('utf8') # <<<<<<<<<<<<<< + * elif isinstance(sentence, str): + * inp = sentence.strip() + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_47), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_inp = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3; + } + + /* "_cdec.pyx":94 + * if isinstance(sentence, unicode): + * inp = sentence.strip().encode('utf8') + * elif isinstance(sentence, str): # <<<<<<<<<<<<<< + * inp = sentence.strip() + * elif isinstance(sentence, Lattice): + */ + __pyx_t_3 = ((PyObject *)((PyObject*)(&PyString_Type))); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":95 + * inp = sentence.strip().encode('utf8') + * elif isinstance(sentence, str): + * inp = sentence.strip() # <<<<<<<<<<<<<< + * elif isinstance(sentence, Lattice): + * inp = str(sentence) # PLF format + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_inp = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L3; + } + + /* "_cdec.pyx":96 + * elif isinstance(sentence, str): + * inp = sentence.strip() + * elif isinstance(sentence, Lattice): # <<<<<<<<<<<<<< + * inp = str(sentence) # PLF format + * else: + */ + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":97 + * inp = sentence.strip() + * elif isinstance(sentence, Lattice): + * inp = str(sentence) # PLF format # <<<<<<<<<<<<<< + * else: + * raise TypeError('Cannot translate input type %s' % type(sentence)) + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_sentence); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_sentence); + __Pyx_GIVEREF(__pyx_v_sentence); + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_v_inp = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "_cdec.pyx":99 + * inp = str(sentence) # PLF format + * else: + * raise TypeError('Cannot translate input type %s' % type(sentence)) # <<<<<<<<<<<<<< + * if grammar: + * self.dec.SetSentenceGrammarFromString(string( grammar)) + */ + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_48), ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 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 = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; + + /* "_cdec.pyx":100 + * else: + * raise TypeError('Cannot translate input type %s' % type(sentence)) + * if grammar: # <<<<<<<<<<<<<< + * self.dec.SetSentenceGrammarFromString(string( grammar)) + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_grammar); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "_cdec.pyx":101 + * raise TypeError('Cannot translate input type %s' % type(sentence)) + * if grammar: + * self.dec.SetSentenceGrammarFromString(string( grammar)) # <<<<<<<<<<<<<< + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + * self.dec.Decode(string(inp), &observer) + */ + __pyx_t_4 = PyBytes_AsString(__pyx_v_grammar); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->dec->SetSentenceGrammarFromString(std::string(((char *)__pyx_t_4))); + goto __pyx_L4; + } + __pyx_L4:; + + /* "_cdec.pyx":102 + * if grammar: + * self.dec.SetSentenceGrammarFromString(string( grammar)) + * cdef decoder.BasicObserver observer = decoder.BasicObserver() # <<<<<<<<<<<<<< + * self.dec.Decode(string(inp), &observer) + * if observer.hypergraph == NULL: + */ + __pyx_v_observer = BasicObserver(); + + /* "_cdec.pyx":103 + * self.dec.SetSentenceGrammarFromString(string( grammar)) + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + * self.dec.Decode(string(inp), &observer) # <<<<<<<<<<<<<< + * if observer.hypergraph == NULL: + * raise ParseFailed() + */ + __pyx_t_4 = PyBytes_AsString(__pyx_v_inp); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->dec->Decode(std::string(((char *)__pyx_t_4)), (&__pyx_v_observer)); + + /* "_cdec.pyx":104 + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + * self.dec.Decode(string(inp), &observer) + * if observer.hypergraph == NULL: # <<<<<<<<<<<<<< + * raise ParseFailed() + * cdef Hypergraph hg = Hypergraph() + */ + __pyx_t_2 = (__pyx_v_observer.hypergraph == NULL); + if (__pyx_t_2) { + + /* "_cdec.pyx":105 + * self.dec.Decode(string(inp), &observer) + * if observer.hypergraph == NULL: + * raise ParseFailed() # <<<<<<<<<<<<<< + * cdef Hypergraph hg = Hypergraph() + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__ParseFailed); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); 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_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L5; + } + __pyx_L5:; + + /* "_cdec.pyx":106 + * if observer.hypergraph == NULL: + * raise ParseFailed() + * cdef Hypergraph hg = Hypergraph() # <<<<<<<<<<<<<< + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) + * return hg + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Hypergraph)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_hg = ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "_cdec.pyx":107 + * raise ParseFailed() + * cdef Hypergraph hg = Hypergraph() + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) # <<<<<<<<<<<<<< + * return hg + */ + __pyx_v_hg->hg = new Hypergraph((__pyx_v_observer.hypergraph[0])); + + /* "_cdec.pyx":108 + * cdef Hypergraph hg = Hypergraph() + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) + * return hg # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_hg)); + __pyx_r = ((PyObject *)__pyx_v_hg); + 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_3); + __Pyx_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_inp); + __Pyx_XDECREF((PyObject *)__pyx_v_hg); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_tp_new_5_cdec_DenseVector(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_DenseVector(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_5_cdec_DenseVector(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_5_cdec_DenseVector(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_5_cdec_11DenseVector_5__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_DenseVector[] = { + {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_10dot, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("tosparse"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_12tosparse, METH_NOARGS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_DenseVector = { + 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_DenseVector = { + __pyx_pw_5_cdec_11DenseVector_1__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5_cdec_DenseVector, /*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_DenseVector = { + __pyx_pw_5_cdec_11DenseVector_1__len__, /*mp_length*/ + __pyx_pw_5_cdec_11DenseVector_3__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5_cdec_DenseVector, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_DenseVector = { + #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_DenseVector = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.DenseVector"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_DenseVector), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_DenseVector, /*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_DenseVector, /*tp_as_number*/ + &__pyx_tp_as_sequence_DenseVector, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_DenseVector, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_DenseVector, /*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_pw_5_cdec_11DenseVector_7__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_DenseVector, /*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_DenseVector, /*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_SparseVector(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_SparseVector(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_12SparseVector_1__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_5_cdec_SparseVector(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_5_cdec_SparseVector(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_5_cdec_12SparseVector_7__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_SparseVector[] = { + {__Pyx_NAMESTR("copy"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_3copy, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_12dot, METH_O, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_SparseVector = { + __pyx_pw_5_cdec_12SparseVector_30__add__, /*nb_add*/ + __pyx_pw_5_cdec_12SparseVector_32__sub__, /*nb_subtract*/ + __pyx_pw_5_cdec_12SparseVector_34__mul__, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 + __pyx_pw_5_cdec_12SparseVector_36__div__, /*nb_divide*/ + #endif + 0, /*nb_remainder*/ + 0, /*nb_divmod*/ + 0, /*nb_power*/ + __pyx_pw_5_cdec_12SparseVector_20__neg__, /*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 + __pyx_pw_5_cdec_12SparseVector_22__iadd__, /*nb_inplace_add*/ + __pyx_pw_5_cdec_12SparseVector_24__isub__, /*nb_inplace_subtract*/ + __pyx_pw_5_cdec_12SparseVector_26__imul__, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + __pyx_pw_5_cdec_12SparseVector_28__idiv__, /*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_SparseVector = { + __pyx_pw_5_cdec_12SparseVector_16__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5_cdec_SparseVector, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + __pyx_pw_5_cdec_12SparseVector_18__contains__, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_SparseVector = { + __pyx_pw_5_cdec_12SparseVector_16__len__, /*mp_length*/ + __pyx_pw_5_cdec_12SparseVector_5__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5_cdec_SparseVector, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_SparseVector = { + #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_SparseVector = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.SparseVector"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_SparseVector), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_SparseVector, /*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_SparseVector, /*tp_as_number*/ + &__pyx_tp_as_sequence_SparseVector, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_SparseVector, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_SparseVector, /*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*/ + __pyx_pw_5_cdec_12SparseVector_14__richcmp__, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + __pyx_pw_5_cdec_12SparseVector_9__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_SparseVector, /*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_SparseVector, /*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_Hypergraph(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_Hypergraph(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} + +static PyObject *__pyx_getprop_5_cdec_10Hypergraph_edges(PyObject *o, void *x) { + return __pyx_pw_5_cdec_10Hypergraph_5edges_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_10Hypergraph_nodes(PyObject *o, void *x) { + return __pyx_pw_5_cdec_10Hypergraph_5nodes_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_10Hypergraph_goal(PyObject *o, void *x) { + return __pyx_pw_5_cdec_10Hypergraph_4goal_1__get__(o); +} + +static PyMethodDef __pyx_methods_5_cdec_Hypergraph[] = { + {__Pyx_NAMESTR("viterbi"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_3viterbi, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("viterbi_trees"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_5viterbi_trees, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("viterbi_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_7viterbi_features, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("viterbi_joshua"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_9viterbi_joshua, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("kbest"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_11kbest, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("kbest_trees"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_14kbest_trees, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("kbest_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_17kbest_features, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("sample"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_20sample, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("intersect"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_23intersect, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("prune"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_25prune, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("lattice"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_27lattice, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("reweight"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_29reweight, METH_O, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5_cdec_Hypergraph[] = { + {(char *)"edges", __pyx_getprop_5_cdec_10Hypergraph_edges, 0, 0, 0}, + {(char *)"nodes", __pyx_getprop_5_cdec_10Hypergraph_nodes, 0, 0, 0}, + {(char *)"goal", __pyx_getprop_5_cdec_10Hypergraph_goal, 0, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Hypergraph = { + 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_Hypergraph = { + 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_Hypergraph = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = { + #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_Hypergraph = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.Hypergraph"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Hypergraph), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_Hypergraph, /*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_Hypergraph, /*tp_as_number*/ + &__pyx_tp_as_sequence_Hypergraph, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Hypergraph, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Hypergraph, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_Hypergraph, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5_cdec_Hypergraph, /*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_Hypergraph, /*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_TRule(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_TRule(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} + +static PyObject *__pyx_getprop_5_cdec_5TRule_arity(PyObject *o, void *x) { + return __pyx_pw_5_cdec_5TRule_5arity_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_5TRule_f(PyObject *o, void *x) { + return __pyx_pw_5_cdec_5TRule_1f_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_5TRule_e(PyObject *o, void *x) { + return __pyx_pw_5_cdec_5TRule_1e_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_5TRule_scores(PyObject *o, void *x) { + return __pyx_pw_5_cdec_5TRule_6scores_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_5TRule_lhs(PyObject *o, void *x) { + return __pyx_pw_5_cdec_5TRule_3lhs_1__get__(o); +} + +static PyMethodDef __pyx_methods_5_cdec_TRule[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5_cdec_TRule[] = { + {(char *)"arity", __pyx_getprop_5_cdec_5TRule_arity, 0, 0, 0}, + {(char *)"f", __pyx_getprop_5_cdec_5TRule_f, 0, 0, 0}, + {(char *)"e", __pyx_getprop_5_cdec_5TRule_e, 0, 0, 0}, + {(char *)"scores", __pyx_getprop_5_cdec_5TRule_scores, 0, 0, 0}, + {(char *)"lhs", __pyx_getprop_5_cdec_5TRule_lhs, 0, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_TRule = { + 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_TRule = { + 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_TRule = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_TRule = { + #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_TRule = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.TRule"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_TRule), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_TRule, /*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_TRule, /*tp_as_number*/ + &__pyx_tp_as_sequence_TRule, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_TRule, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_5_cdec_5TRule_1__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_TRule, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_TRule, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5_cdec_TRule, /*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_TRule, /*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 struct __pyx_vtabstruct_5_cdec_HypergraphEdge __pyx_vtable_5_cdec_HypergraphEdge; + +static PyObject *__pyx_tp_new_5_cdec_HypergraphEdge(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec_HypergraphEdge *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_5_cdec_HypergraphEdge *)o); + p->__pyx_vtab = __pyx_vtabptr_5_cdec_HypergraphEdge; + p->trule = ((struct __pyx_obj_5_cdec_TRule *)Py_None); Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_5_cdec_HypergraphEdge(PyObject *o) { + struct __pyx_obj_5_cdec_HypergraphEdge *p = (struct __pyx_obj_5_cdec_HypergraphEdge *)o; + Py_XDECREF(((PyObject *)p->trule)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_5_cdec_HypergraphEdge(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec_HypergraphEdge *p = (struct __pyx_obj_5_cdec_HypergraphEdge *)o; + if (p->trule) { + e = (*v)(((PyObject*)p->trule), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5_cdec_HypergraphEdge(PyObject *o) { + struct __pyx_obj_5_cdec_HypergraphEdge *p = (struct __pyx_obj_5_cdec_HypergraphEdge *)o; + PyObject* tmp; + tmp = ((PyObject*)p->trule); + p->trule = ((struct __pyx_obj_5_cdec_TRule *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_head_node(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphEdge_9head_node_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_tail_nodes(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphEdge_10tail_nodes_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_span(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphEdge_4span_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_feature_values(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphEdge_14feature_values_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_prob(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphEdge_4prob_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_trule(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphEdge_5trule_1__get__(o); +} + +static int __pyx_setprop_5_cdec_14HypergraphEdge_trule(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_14HypergraphEdge_5trule_3__set__(o, v); + } + else { + return __pyx_pw_5_cdec_14HypergraphEdge_5trule_5__del__(o); + } +} + +static PyMethodDef __pyx_methods_5_cdec_HypergraphEdge[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5_cdec_HypergraphEdge[] = { + {(char *)"head_node", __pyx_getprop_5_cdec_14HypergraphEdge_head_node, 0, 0, 0}, + {(char *)"tail_nodes", __pyx_getprop_5_cdec_14HypergraphEdge_tail_nodes, 0, 0, 0}, + {(char *)"span", __pyx_getprop_5_cdec_14HypergraphEdge_span, 0, 0, 0}, + {(char *)"feature_values", __pyx_getprop_5_cdec_14HypergraphEdge_feature_values, 0, 0, 0}, + {(char *)"prob", __pyx_getprop_5_cdec_14HypergraphEdge_prob, 0, 0, 0}, + {(char *)"trule", __pyx_getprop_5_cdec_14HypergraphEdge_trule, __pyx_setprop_5_cdec_14HypergraphEdge_trule, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_HypergraphEdge = { + 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_HypergraphEdge = { + __pyx_pw_5_cdec_14HypergraphEdge_1__len__, /*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_HypergraphEdge = { + __pyx_pw_5_cdec_14HypergraphEdge_1__len__, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_HypergraphEdge = { + #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_HypergraphEdge = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.HypergraphEdge"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_HypergraphEdge), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_HypergraphEdge, /*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_HypergraphEdge, /*tp_as_number*/ + &__pyx_tp_as_sequence_HypergraphEdge, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_HypergraphEdge, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_HypergraphEdge, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_5_cdec_HypergraphEdge, /*tp_traverse*/ + __pyx_tp_clear_5_cdec_HypergraphEdge, /*tp_clear*/ + __pyx_pw_5_cdec_14HypergraphEdge_3__richcmp__, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_HypergraphEdge, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5_cdec_HypergraphEdge, /*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_HypergraphEdge, /*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 struct __pyx_vtabstruct_5_cdec_HypergraphNode __pyx_vtable_5_cdec_HypergraphNode; + +static PyObject *__pyx_tp_new_5_cdec_HypergraphNode(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec_HypergraphNode *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_5_cdec_HypergraphNode *)o); + p->__pyx_vtab = __pyx_vtabptr_5_cdec_HypergraphNode; + return o; +} + +static void __pyx_tp_dealloc_5_cdec_HypergraphNode(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} + +static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_in_edges(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphNode_8in_edges_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_out_edges(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphNode_9out_edges_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_span(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphNode_4span_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_cat(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphNode_3cat_1__get__(o); +} + +static PyMethodDef __pyx_methods_5_cdec_HypergraphNode[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5_cdec_HypergraphNode[] = { + {(char *)"in_edges", __pyx_getprop_5_cdec_14HypergraphNode_in_edges, 0, 0, 0}, + {(char *)"out_edges", __pyx_getprop_5_cdec_14HypergraphNode_out_edges, 0, 0, 0}, + {(char *)"span", __pyx_getprop_5_cdec_14HypergraphNode_span, 0, 0, 0}, + {(char *)"cat", __pyx_getprop_5_cdec_14HypergraphNode_cat, 0, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_HypergraphNode = { + 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_HypergraphNode = { + 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_HypergraphNode = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_HypergraphNode = { + #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_HypergraphNode = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.HypergraphNode"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_HypergraphNode), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_HypergraphNode, /*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_HypergraphNode, /*tp_as_number*/ + &__pyx_tp_as_sequence_HypergraphNode, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_HypergraphNode, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_HypergraphNode, /*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*/ + __pyx_pw_5_cdec_14HypergraphNode_1__richcmp__, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_HypergraphNode, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5_cdec_HypergraphNode, /*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_HypergraphNode, /*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_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_pw_5_cdec_7Lattice_14__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_5_cdec_Lattice(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_5_cdec_Lattice(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_5_cdec_7Lattice_5__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_Lattice[] = { + {__Pyx_NAMESTR("todot"), (PyCFunction)__pyx_pw_5_cdec_7Lattice_16todot, METH_NOARGS, __Pyx_DOCSTR(0)}, + {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 = { + __pyx_pw_5_cdec_7Lattice_7__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5_cdec_Lattice, /*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 = { + __pyx_pw_5_cdec_7Lattice_7__len__, /*mp_length*/ + __pyx_pw_5_cdec_7Lattice_3__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5_cdec_Lattice, /*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_pw_5_cdec_7Lattice_9__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_pw_5_cdec_7Lattice_11__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_pw_5_cdec_7Lattice_1__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_Candidate(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_Candidate(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} + +static PyObject *__pyx_getprop_5_cdec_9Candidate_words(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9Candidate_5words_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_9Candidate_fmap(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9Candidate_4fmap_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_9Candidate_score(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9Candidate_5score_1__get__(o); +} + +static int __pyx_setprop_5_cdec_9Candidate_score(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_9Candidate_5score_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_Candidate[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5_cdec_Candidate[] = { + {(char *)"words", __pyx_getprop_5_cdec_9Candidate_words, 0, 0, 0}, + {(char *)"fmap", __pyx_getprop_5_cdec_9Candidate_fmap, 0, 0, 0}, + {(char *)"score", __pyx_getprop_5_cdec_9Candidate_score, __pyx_setprop_5_cdec_9Candidate_score, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Candidate = { + 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_Candidate = { + 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_Candidate = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Candidate = { + #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_Candidate = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.Candidate"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Candidate), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_Candidate, /*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_Candidate, /*tp_as_number*/ + &__pyx_tp_as_sequence_Candidate, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Candidate, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Candidate, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_Candidate, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5_cdec_Candidate, /*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_Candidate, /*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_SufficientStats(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_SufficientStats(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} + +static PyObject *__pyx_getprop_5_cdec_15SufficientStats_score(PyObject *o, void *x) { + return __pyx_pw_5_cdec_15SufficientStats_5score_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_15SufficientStats_detail(PyObject *o, void *x) { + return __pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(o); +} + +static PyMethodDef __pyx_methods_5_cdec_SufficientStats[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5_cdec_SufficientStats[] = { + {(char *)"score", __pyx_getprop_5_cdec_15SufficientStats_score, 0, 0, 0}, + {(char *)"detail", __pyx_getprop_5_cdec_15SufficientStats_detail, 0, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_SufficientStats = { + __pyx_pw_5_cdec_15SufficientStats_10__add__, /*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 + __pyx_pw_5_cdec_15SufficientStats_8__iadd__, /*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_SufficientStats = { + __pyx_pw_5_cdec_15SufficientStats_3__len__, /*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_SufficientStats = { + __pyx_pw_5_cdec_15SufficientStats_3__len__, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_SufficientStats = { + #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_SufficientStats = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.SufficientStats"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_SufficientStats), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_SufficientStats, /*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_SufficientStats, /*tp_as_number*/ + &__pyx_tp_as_sequence_SufficientStats, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_SufficientStats, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_SufficientStats, /*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_pw_5_cdec_15SufficientStats_5__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_SufficientStats, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5_cdec_SufficientStats, /*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_SufficientStats, /*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_CandidateSet(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + if (__pyx_pw_5_cdec_12CandidateSet_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_5_cdec_CandidateSet(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_5_cdec_CandidateSet(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static PyMethodDef __pyx_methods_5_cdec_CandidateSet[] = { + {__Pyx_NAMESTR("add_kbest"), (PyCFunction)__pyx_pw_5_cdec_12CandidateSet_12add_kbest, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_CandidateSet = { + 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_CandidateSet = { + __pyx_pw_5_cdec_12CandidateSet_5__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5_cdec_CandidateSet, /*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_CandidateSet = { + __pyx_pw_5_cdec_12CandidateSet_5__len__, /*mp_length*/ + __pyx_pw_5_cdec_12CandidateSet_7__getitem__, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_CandidateSet = { + #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_CandidateSet = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.CandidateSet"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_CandidateSet), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_CandidateSet, /*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_CandidateSet, /*tp_as_number*/ + &__pyx_tp_as_sequence_CandidateSet, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_CandidateSet, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_CandidateSet, /*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_pw_5_cdec_12CandidateSet_9__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_CandidateSet, /*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_CandidateSet, /*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_SegmentEvaluator(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_SegmentEvaluator(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_16SegmentEvaluator_1__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_SegmentEvaluator[] = { + {__Pyx_NAMESTR("evaluate"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("candidate_set"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set, METH_NOARGS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_SegmentEvaluator = { + 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_SegmentEvaluator = { + 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_SegmentEvaluator = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_SegmentEvaluator = { + #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_SegmentEvaluator = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.SegmentEvaluator"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_SegmentEvaluator), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_SegmentEvaluator, /*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_SegmentEvaluator, /*tp_as_number*/ + &__pyx_tp_as_sequence_SegmentEvaluator, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_SegmentEvaluator, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_SegmentEvaluator, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_SegmentEvaluator, /*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_SegmentEvaluator, /*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_Scorer(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + if (__pyx_pw_5_cdec_6Scorer_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_5_cdec_Scorer(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_6Scorer_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_Scorer[] = { + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Scorer = { + 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_Scorer = { + 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_Scorer = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Scorer = { + #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_Scorer = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.Scorer"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Scorer), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_Scorer, /*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_Scorer, /*tp_as_number*/ + &__pyx_tp_as_sequence_Scorer, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Scorer, /*tp_as_mapping*/ + 0, /*tp_hash*/ + __pyx_pw_5_cdec_6Scorer_5__call__, /*tp_call*/ + __pyx_pw_5_cdec_6Scorer_7__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Scorer, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_Scorer, /*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_Scorer, /*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_Decoder(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec_Decoder *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_5_cdec_Decoder *)o); + p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_5_cdec_7Decoder_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_5_cdec_Decoder(PyObject *o) { + struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_7Decoder_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + Py_XDECREF(((PyObject *)p->weights)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_5_cdec_Decoder(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; + if (p->weights) { + e = (*v)(((PyObject*)p->weights), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5_cdec_Decoder(PyObject *o) { + struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; + PyObject* tmp; + tmp = ((PyObject*)p->weights); + p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_5_cdec_7Decoder_weights(PyObject *o, void *x) { + return __pyx_pw_5_cdec_7Decoder_7weights_1__get__(o); +} + +static int __pyx_setprop_5_cdec_7Decoder_weights(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_7Decoder_7weights_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5_cdec_7Decoder_formalism(PyObject *o, void *x) { + return __pyx_pw_5_cdec_7Decoder_9formalism_1__get__(o); +} + +static PyMethodDef __pyx_methods_5_cdec_Decoder[] = { + {__Pyx_NAMESTR("read_weights"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_5read_weights, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("translate"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_7translate, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5_cdec_Decoder[] = { + {(char *)"weights", __pyx_getprop_5_cdec_7Decoder_weights, __pyx_setprop_5_cdec_7Decoder_weights, 0, 0}, + {(char *)"formalism", __pyx_getprop_5_cdec_7Decoder_formalism, 0, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Decoder = { + 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_Decoder = { + 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_Decoder = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Decoder = { + #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_Decoder = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.Decoder"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Decoder), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_Decoder, /*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_Decoder, /*tp_as_number*/ + &__pyx_tp_as_sequence_Decoder, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Decoder, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Decoder, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_5_cdec_Decoder, /*tp_traverse*/ + __pyx_tp_clear_5_cdec_Decoder, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_Decoder, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5_cdec_Decoder, /*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_Decoder, /*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____iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o); + p->__pyx_v_self = 0; + return o; +} + +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct____iter__[] = { + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = { + 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____iter__ = { + 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____iter__ = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = { + #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____iter__ = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.__pyx_scope_struct____iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct____iter__), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__, /*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____iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct____iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct____iter__, /*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____iter__, /*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____iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec___pyx_scope_struct____iter__, /*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____iter__, /*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_1___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o); + p->__pyx_v_self = 0; + return o; +} + +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} - /* "_cdec.pyx":67 - * if observer.hypergraph == NULL: - * raise ParseFailed() - * cdef Hypergraph hg = Hypergraph() # <<<<<<<<<<<<<< - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) - * return hg - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Hypergraph)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_hg = ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_t_1); - __pyx_t_1 = 0; +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_1___iter__[] = { + {0, 0, 0, 0} +}; - /* "_cdec.pyx":68 - * raise ParseFailed() - * cdef Hypergraph hg = Hypergraph() - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) # <<<<<<<<<<<<<< - * return hg - */ - __pyx_v_hg->hg = new Hypergraph((__pyx_v_observer.hypergraph[0])); +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { + 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 +}; - /* "_cdec.pyx":69 - * cdef Hypergraph hg = Hypergraph() - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) - * return hg # <<<<<<<<<<<<<< - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_hg)); - __pyx_r = ((PyObject *)__pyx_v_hg); - goto __pyx_L0; +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1___iter__ = { + 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*/ +}; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_inp); - __Pyx_XDECREF((PyObject *)__pyx_v_hg); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1___iter__ = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; -static PyObject *__pyx_tp_new_5_cdec_DenseVector(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { + #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___iter__ = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_1___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__, /*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___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_1___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_1___iter__, /*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___iter__, /*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___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec___pyx_scope_struct_1___iter__, /*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___iter__, /*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(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o); + p->__pyx_v_self = 0; + p->__pyx_v_size = 0; return o; } -static void __pyx_tp_dealloc_5_cdec_DenseVector(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_sq_item_5_cdec_DenseVector(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} -static int __pyx_mp_ass_subscript_5_cdec_DenseVector(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_pw_5_cdec_11DenseVector_5__setitem__(o, i, v); +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); - return -1; + if (p->__pyx_v_size) { + e = (*v)(p->__pyx_v_size, a); if (e) return e; } + return 0; } -static PyMethodDef __pyx_methods_5_cdec_DenseVector[] = { - {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_10dot, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("tosparse"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_12tosparse, METH_NOARGS, __Pyx_DOCSTR(0)}, +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_DenseVector = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -10033,11 +17076,11 @@ static PyNumberMethods __pyx_tp_as_number_DenseVector = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_DenseVector = { - __pyx_pw_5_cdec_11DenseVector_1__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest = { + 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_DenseVector, /*sq_item*/ + 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -10046,13 +17089,13 @@ static PySequenceMethods __pyx_tp_as_sequence_DenseVector = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_DenseVector = { - __pyx_pw_5_cdec_11DenseVector_1__len__, /*mp_length*/ - __pyx_pw_5_cdec_11DenseVector_3__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_5_cdec_DenseVector, /*mp_ass_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_2_kbest = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_DenseVector = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -10073,12 +17116,12 @@ static PyBufferProcs __pyx_tp_as_buffer_DenseVector = { #endif }; -static PyTypeObject __pyx_type_5_cdec_DenseVector = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.DenseVector"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_DenseVector), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_2_kbest"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_DenseVector, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -10088,24 +17131,24 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_DenseVector, /*tp_as_number*/ - &__pyx_tp_as_sequence_DenseVector, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_DenseVector, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_2_kbest, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_2_kbest, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_2_kbest, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_DenseVector, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct_2_kbest, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_11DenseVector_7__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_DenseVector, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_2_kbest, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -10115,7 +17158,7 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_DenseVector, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -10129,60 +17172,78 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_SparseVector(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_trees(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *)o); + p->__pyx_v_e_tree = 0; + p->__pyx_v_f_tree = 0; + p->__pyx_v_self = 0; + p->__pyx_v_size = 0; return o; } -static void __pyx_tp_dealloc_5_cdec_SparseVector(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_12SparseVector_1__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_kbest_trees(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_e_tree)); + Py_XDECREF(((PyObject *)p->__pyx_v_f_tree)); + Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_sq_item_5_cdec_SparseVector(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} -static int __pyx_mp_ass_subscript_5_cdec_SparseVector(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_pw_5_cdec_12SparseVector_7__setitem__(o, i, v); +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_kbest_trees(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *)o; + if (p->__pyx_v_e_tree) { + e = (*v)(p->__pyx_v_e_tree, a); if (e) return e; } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); - return -1; + if (p->__pyx_v_f_tree) { + e = (*v)(p->__pyx_v_f_tree, 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; } + return 0; } -static PyMethodDef __pyx_methods_5_cdec_SparseVector[] = { - {__Pyx_NAMESTR("copy"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_3copy, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_12dot, METH_O, __Pyx_DOCSTR(0)}, +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_3_kbest_trees(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_e_tree); + p->__pyx_v_e_tree = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_f_tree); + p->__pyx_v_f_tree = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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_3_kbest_trees[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_30__add__, /*nb_add*/ - __pyx_pw_5_cdec_12SparseVector_32__sub__, /*nb_subtract*/ - __pyx_pw_5_cdec_12SparseVector_34__mul__, /*nb_multiply*/ +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_kbest_trees = { + 0, /*nb_add*/ + 0, /*nb_subtract*/ + 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 - __pyx_pw_5_cdec_12SparseVector_36__div__, /*nb_divide*/ + 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ - __pyx_pw_5_cdec_12SparseVector_20__neg__, /*nb_negative*/ + 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ @@ -10208,11 +17269,11 @@ static PyNumberMethods __pyx_tp_as_number_SparseVector = { #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif - __pyx_pw_5_cdec_12SparseVector_22__iadd__, /*nb_inplace_add*/ - __pyx_pw_5_cdec_12SparseVector_24__isub__, /*nb_inplace_subtract*/ - __pyx_pw_5_cdec_12SparseVector_26__imul__, /*nb_inplace_multiply*/ + 0, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 - __pyx_pw_5_cdec_12SparseVector_28__idiv__, /*nb_inplace_divide*/ + 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ @@ -10230,26 +17291,26 @@ static PyNumberMethods __pyx_tp_as_number_SparseVector = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_16__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_kbest_trees = { + 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_SparseVector, /*sq_item*/ + 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ - __pyx_pw_5_cdec_12SparseVector_18__contains__, /*sq_contains*/ + 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_16__len__, /*mp_length*/ - __pyx_pw_5_cdec_12SparseVector_5__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_5_cdec_SparseVector, /*mp_ass_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_3_kbest_trees = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_SparseVector = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_kbest_trees = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -10270,12 +17331,12 @@ static PyBufferProcs __pyx_tp_as_buffer_SparseVector = { #endif }; -static PyTypeObject __pyx_type_5_cdec_SparseVector = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_trees = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.SparseVector"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_SparseVector), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_3_kbest_trees"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_SparseVector, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_kbest_trees, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -10285,24 +17346,24 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_SparseVector, /*tp_as_number*/ - &__pyx_tp_as_sequence_SparseVector, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_SparseVector, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_3_kbest_trees, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_3_kbest_trees, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_3_kbest_trees, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_SparseVector, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct_3_kbest_trees, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - __pyx_pw_5_cdec_12SparseVector_14__richcmp__, /*tp_richcompare*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_kbest_trees, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_3_kbest_trees, /*tp_clear*/ + 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_12SparseVector_9__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_SparseVector, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_3_kbest_trees, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -10312,7 +17373,7 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_SparseVector, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_trees, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -10326,42 +17387,60 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Hypergraph(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_4_kbest_features(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o); + p->__pyx_v_fmap = 0; + p->__pyx_v_self = 0; + p->__pyx_v_size = 0; return o; } -static void __pyx_tp_dealloc_5_cdec_Hypergraph(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_fmap)); + Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static PyMethodDef __pyx_methods_5_cdec_Hypergraph[] = { - {__Pyx_NAMESTR("viterbi"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_3viterbi, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("viterbi_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_5viterbi_tree, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("viterbi_source_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_7viterbi_source_tree, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("viterbi_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_9viterbi_features, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("kbest"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_11kbest, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("kbest_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_14kbest_tree, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("kbest_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_17kbest_features, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("sample"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_20sample, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("intersect"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_23intersect, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("prune"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_25prune, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("lattice"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_27lattice, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("reweight"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_29reweight, METH_O, __Pyx_DOCSTR(0)}, +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; + if (p->__pyx_v_fmap) { + e = (*v)(((PyObject*)p->__pyx_v_fmap), 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; + } + return 0; +} + +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_fmap); + p->__pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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_4_kbest_features[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_Hypergraph = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4_kbest_features = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -10419,7 +17498,7 @@ static PyNumberMethods __pyx_tp_as_number_Hypergraph = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Hypergraph = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4_kbest_features = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -10432,13 +17511,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Hypergraph = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Hypergraph = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_4_kbest_features = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4_kbest_features = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -10459,12 +17538,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Hypergraph = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_kbest_features = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Hypergraph"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Hypergraph), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_4_kbest_features"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Hypergraph, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -10474,24 +17553,24 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Hypergraph, /*tp_as_number*/ - &__pyx_tp_as_sequence_Hypergraph, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Hypergraph, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_4_kbest_features, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_4_kbest_features, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_4_kbest_features, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Hypergraph, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct_4_kbest_features, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Hypergraph, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -10501,7 +17580,7 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Hypergraph, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -10515,49 +17594,44 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Lattice(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_5_sample(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p; 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_pw_5_cdec_7Lattice_14__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - (*Py_TYPE(o)->tp_free)(o); + if (!o) return 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o); + p->__pyx_v_self = 0; + return o; } -static PyObject *__pyx_sq_item_5_cdec_Lattice(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; + +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5_sample(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); + (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_mp_ass_subscript_5_cdec_Lattice(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_pw_5_cdec_7Lattice_5__setitem__(o, i, v); - } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); - return -1; +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_5_sample(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } + return 0; } -static PyMethodDef __pyx_methods_5_cdec_Lattice[] = { - {__Pyx_NAMESTR("todot"), (PyCFunction)__pyx_pw_5_cdec_7Lattice_16todot, METH_NOARGS, __Pyx_DOCSTR(0)}, +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_5_sample(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_5_sample[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_Lattice = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_5_sample = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -10615,11 +17689,11 @@ static PyNumberMethods __pyx_tp_as_number_Lattice = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Lattice = { - __pyx_pw_5_cdec_7Lattice_7__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_5_sample = { + 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_Lattice, /*sq_item*/ + 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -10628,13 +17702,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Lattice = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Lattice = { - __pyx_pw_5_cdec_7Lattice_7__len__, /*mp_length*/ - __pyx_pw_5_cdec_7Lattice_3__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_5_cdec_Lattice, /*mp_ass_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_5_sample = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Lattice = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_5_sample = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -10655,12 +17729,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Lattice = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Lattice = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5_sample = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Lattice"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Lattice), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_5_sample"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Lattice, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5_sample, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -10670,24 +17744,24 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { 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*/ + &__pyx_tp_as_number___pyx_scope_struct_5_sample, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_5_sample, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_5_sample, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ - __pyx_pw_5_cdec_7Lattice_9__str__, /*tp_str*/ + 0, /*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*/ + &__pyx_tp_as_buffer___pyx_scope_struct_5_sample, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_5_sample, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_5_sample, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_7Lattice_11__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Lattice, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_5_sample, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -10695,9 +17769,9 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ - __pyx_pw_5_cdec_7Lattice_1__init__, /*tp_init*/ + 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Lattice, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_5_sample, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -10711,50 +17785,44 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Candidate(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_6___get__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *)o); + p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec_Candidate(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_6___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_getprop_5_cdec_9Candidate_words(PyObject *o, void *x) { - return __pyx_pw_5_cdec_9Candidate_5words_1__get__(o); -} - -static PyObject *__pyx_getprop_5_cdec_9Candidate_fmap(PyObject *o, void *x) { - return __pyx_pw_5_cdec_9Candidate_4fmap_1__get__(o); -} - -static PyObject *__pyx_getprop_5_cdec_9Candidate_score(PyObject *o, void *x) { - return __pyx_pw_5_cdec_9Candidate_5score_1__get__(o); +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_6___get__(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + } + return 0; } -static int __pyx_setprop_5_cdec_9Candidate_score(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_5_cdec_9Candidate_5score_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_6___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; } -static PyMethodDef __pyx_methods_5_cdec_Candidate[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_6___get__[] = { {0, 0, 0, 0} }; -static struct PyGetSetDef __pyx_getsets_5_cdec_Candidate[] = { - {(char *)"words", __pyx_getprop_5_cdec_9Candidate_words, 0, 0, 0}, - {(char *)"fmap", __pyx_getprop_5_cdec_9Candidate_fmap, 0, 0, 0}, - {(char *)"score", __pyx_getprop_5_cdec_9Candidate_score, __pyx_setprop_5_cdec_9Candidate_score, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_Candidate = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_6___get__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -10812,7 +17880,7 @@ static PyNumberMethods __pyx_tp_as_number_Candidate = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Candidate = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_6___get__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -10825,13 +17893,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Candidate = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Candidate = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_6___get__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Candidate = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_6___get__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -10852,12 +17920,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Candidate = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Candidate = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_6___get__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Candidate"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Candidate), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_6___get__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Candidate, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_6___get__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -10867,26 +17935,26 @@ static PyTypeObject __pyx_type_5_cdec_Candidate = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Candidate, /*tp_as_number*/ - &__pyx_tp_as_sequence_Candidate, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Candidate, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_6___get__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_6___get__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_6___get__, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Candidate, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct_6___get__, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_6___get__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_6___get__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Candidate, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_6___get__, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_5_cdec_Candidate, /*tp_getset*/ + 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -10894,7 +17962,7 @@ static PyTypeObject __pyx_type_5_cdec_Candidate = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Candidate, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_6___get__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -10908,45 +17976,45 @@ static PyTypeObject __pyx_type_5_cdec_Candidate = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_SufficientStats(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_7___get__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *)o); + p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec_SufficientStats(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_7___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_getprop_5_cdec_15SufficientStats_score(PyObject *o, void *x) { - return __pyx_pw_5_cdec_15SufficientStats_5score_1__get__(o); +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_7___get__(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + } + return 0; } -static PyObject *__pyx_getprop_5_cdec_15SufficientStats_detail(PyObject *o, void *x) { - return __pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(o); +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_7___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; } -static PyMethodDef __pyx_methods_5_cdec_SufficientStats[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_7___get__[] = { {0, 0, 0, 0} }; -static struct PyGetSetDef __pyx_getsets_5_cdec_SufficientStats[] = { - {(char *)"score", __pyx_getprop_5_cdec_15SufficientStats_score, 0, 0, 0}, - {(char *)"detail", __pyx_getprop_5_cdec_15SufficientStats_detail, 0, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_SufficientStats = { - __pyx_pw_5_cdec_15SufficientStats_10__add__, /*nb_add*/ +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_7___get__ = { + 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 @@ -10981,7 +18049,7 @@ static PyNumberMethods __pyx_tp_as_number_SufficientStats = { #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif - __pyx_pw_5_cdec_15SufficientStats_8__iadd__, /*nb_inplace_add*/ + 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 @@ -11003,8 +18071,8 @@ static PyNumberMethods __pyx_tp_as_number_SufficientStats = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_SufficientStats = { - __pyx_pw_5_cdec_15SufficientStats_3__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_7___get__ = { + 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ @@ -11016,13 +18084,13 @@ static PySequenceMethods __pyx_tp_as_sequence_SufficientStats = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_SufficientStats = { - __pyx_pw_5_cdec_15SufficientStats_3__len__, /*mp_length*/ +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_7___get__ = { + 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_SufficientStats = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_7___get__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -11043,12 +18111,12 @@ static PyBufferProcs __pyx_tp_as_buffer_SufficientStats = { #endif }; -static PyTypeObject __pyx_type_5_cdec_SufficientStats = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7___get__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.SufficientStats"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_SufficientStats), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_7___get__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_SufficientStats, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_7___get__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -11058,26 +18126,26 @@ static PyTypeObject __pyx_type_5_cdec_SufficientStats = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_SufficientStats, /*tp_as_number*/ - &__pyx_tp_as_sequence_SufficientStats, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_SufficientStats, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_7___get__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_7___get__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_7___get__, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_SufficientStats, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct_7___get__, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_7___get__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_7___get__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_15SufficientStats_5__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_SufficientStats, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_7___get__, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_5_cdec_SufficientStats, /*tp_getset*/ + 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -11085,7 +18153,7 @@ static PyTypeObject __pyx_type_5_cdec_SufficientStats = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_SufficientStats, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_7___get__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -11099,41 +18167,44 @@ static PyTypeObject __pyx_type_5_cdec_SufficientStats = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_CandidateSet(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_8__phrase(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - if (__pyx_pw_5_cdec_12CandidateSet_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *)o); + p->__pyx_v_phrase = 0; return o; } -static void __pyx_tp_dealloc_5_cdec_CandidateSet(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8__phrase(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *)o; + Py_XDECREF(p->__pyx_v_phrase); (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_sq_item_5_cdec_CandidateSet(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; + +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_8__phrase(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *)o; + if (p->__pyx_v_phrase) { + e = (*v)(p->__pyx_v_phrase, a); if (e) return e; + } + return 0; } -static PyMethodDef __pyx_methods_5_cdec_CandidateSet[] = { - {__Pyx_NAMESTR("add_kbest"), (PyCFunction)__pyx_pw_5_cdec_12CandidateSet_12add_kbest, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_8__phrase(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_phrase); + p->__pyx_v_phrase = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_8__phrase[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_CandidateSet = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_8__phrase = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -11191,11 +18262,11 @@ static PyNumberMethods __pyx_tp_as_number_CandidateSet = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_CandidateSet = { - __pyx_pw_5_cdec_12CandidateSet_5__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_8__phrase = { + 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_CandidateSet, /*sq_item*/ + 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -11204,13 +18275,13 @@ static PySequenceMethods __pyx_tp_as_sequence_CandidateSet = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_CandidateSet = { - __pyx_pw_5_cdec_12CandidateSet_5__len__, /*mp_length*/ - __pyx_pw_5_cdec_12CandidateSet_7__getitem__, /*mp_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_8__phrase = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_CandidateSet = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_8__phrase = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -11231,12 +18302,12 @@ static PyBufferProcs __pyx_tp_as_buffer_CandidateSet = { #endif }; -static PyTypeObject __pyx_type_5_cdec_CandidateSet = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8__phrase = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.CandidateSet"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_CandidateSet), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_8__phrase"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_CandidateSet, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8__phrase, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -11246,24 +18317,24 @@ static PyTypeObject __pyx_type_5_cdec_CandidateSet = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_CandidateSet, /*tp_as_number*/ - &__pyx_tp_as_sequence_CandidateSet, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_CandidateSet, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_8__phrase, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_8__phrase, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_8__phrase, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_CandidateSet, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct_8__phrase, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_8__phrase, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_8__phrase, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_12CandidateSet_9__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_CandidateSet, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_8__phrase, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -11273,7 +18344,7 @@ static PyTypeObject __pyx_type_5_cdec_CandidateSet = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_CandidateSet, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_8__phrase, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -11287,32 +18358,60 @@ static PyTypeObject __pyx_type_5_cdec_CandidateSet = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_SegmentEvaluator(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_9_genexpr(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *)o); + p->__pyx_outer_scope = 0; + p->__pyx_v_w = 0; + p->__pyx_t_0 = 0; return o; } -static void __pyx_tp_dealloc_5_cdec_SegmentEvaluator(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_9_genexpr(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *)o; + Py_XDECREF(((PyObject *)p->__pyx_outer_scope)); + Py_XDECREF(p->__pyx_v_w); + Py_XDECREF(p->__pyx_t_0); (*Py_TYPE(o)->tp_free)(o); } -static PyMethodDef __pyx_methods_5_cdec_SegmentEvaluator[] = { - {__Pyx_NAMESTR("evaluate"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("candidate_set"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set, METH_NOARGS, __Pyx_DOCSTR(0)}, +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_9_genexpr(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *)o; + if (p->__pyx_outer_scope) { + e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e; + } + if (p->__pyx_v_w) { + e = (*v)(p->__pyx_v_w, a); if (e) return e; + } + if (p->__pyx_t_0) { + e = (*v)(p->__pyx_t_0, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_9_genexpr(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_outer_scope); + p->__pyx_outer_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_w); + p->__pyx_v_w = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_0); + p->__pyx_t_0 = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_9_genexpr[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_SegmentEvaluator = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_9_genexpr = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -11370,7 +18469,7 @@ static PyNumberMethods __pyx_tp_as_number_SegmentEvaluator = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_SegmentEvaluator = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_9_genexpr = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -11383,13 +18482,13 @@ static PySequenceMethods __pyx_tp_as_sequence_SegmentEvaluator = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_SegmentEvaluator = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_9_genexpr = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_SegmentEvaluator = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_9_genexpr = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -11410,12 +18509,12 @@ static PyBufferProcs __pyx_tp_as_buffer_SegmentEvaluator = { #endif }; -static PyTypeObject __pyx_type_5_cdec_SegmentEvaluator = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_9_genexpr = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.SegmentEvaluator"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_SegmentEvaluator), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_9_genexpr"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_SegmentEvaluator, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_9_genexpr, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -11425,24 +18524,24 @@ static PyTypeObject __pyx_type_5_cdec_SegmentEvaluator = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_SegmentEvaluator, /*tp_as_number*/ - &__pyx_tp_as_sequence_SegmentEvaluator, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_SegmentEvaluator, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_9_genexpr, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_9_genexpr, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_9_genexpr, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_SegmentEvaluator, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct_9_genexpr, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_9_genexpr, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_9_genexpr, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_SegmentEvaluator, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_9_genexpr, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -11452,7 +18551,7 @@ static PyTypeObject __pyx_type_5_cdec_SegmentEvaluator = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_SegmentEvaluator, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_9_genexpr, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -11466,33 +18565,44 @@ static PyTypeObject __pyx_type_5_cdec_SegmentEvaluator = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Scorer(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_10___str__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - if (__pyx_pw_5_cdec_6Scorer_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *)o); + p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec_Scorer(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_6Scorer_3__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_10___str__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static PyMethodDef __pyx_methods_5_cdec_Scorer[] = { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_10___str__(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_10___str__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_TRule *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_10___str__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_Scorer = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_10___str__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -11550,7 +18660,7 @@ static PyNumberMethods __pyx_tp_as_number_Scorer = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Scorer = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_10___str__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -11563,13 +18673,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Scorer = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Scorer = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_10___str__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Scorer = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_10___str__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -11590,12 +18700,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Scorer = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Scorer = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_10___str__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Scorer"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Scorer), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_10___str__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Scorer, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_10___str__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -11605,24 +18715,24 @@ static PyTypeObject __pyx_type_5_cdec_Scorer = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Scorer, /*tp_as_number*/ - &__pyx_tp_as_sequence_Scorer, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Scorer, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_10___str__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_10___str__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_10___str__, /*tp_as_mapping*/ 0, /*tp_hash*/ - __pyx_pw_5_cdec_6Scorer_5__call__, /*tp_call*/ - __pyx_pw_5_cdec_6Scorer_7__str__, /*tp_str*/ + 0, /*tp_call*/ + 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Scorer, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct_10___str__, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_10___str__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_10___str__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Scorer, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_10___str__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -11632,7 +18742,7 @@ static PyTypeObject __pyx_type_5_cdec_Scorer = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Scorer, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_10___str__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -11646,77 +18756,60 @@ static PyTypeObject __pyx_type_5_cdec_Scorer = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Decoder(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec_Decoder *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_11_genexpr(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec_Decoder *)o); - p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); - if (__pyx_pw_5_cdec_7Decoder_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *)o); + p->__pyx_outer_scope = 0; + p->__pyx_v_feat = 0; + p->__pyx_t_0 = 0; return o; } -static void __pyx_tp_dealloc_5_cdec_Decoder(PyObject *o) { - struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_7Decoder_3__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - Py_XDECREF(((PyObject *)p->weights)); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_11_genexpr(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *)o; + Py_XDECREF(((PyObject *)p->__pyx_outer_scope)); + Py_XDECREF(p->__pyx_v_feat); + Py_XDECREF(p->__pyx_t_0); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec_Decoder(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_11_genexpr(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; - if (p->weights) { - e = (*v)(((PyObject*)p->weights), a); if (e) return e; + struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *)o; + if (p->__pyx_outer_scope) { + e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e; + } + if (p->__pyx_v_feat) { + e = (*v)(p->__pyx_v_feat, a); if (e) return e; + } + if (p->__pyx_t_0) { + e = (*v)(p->__pyx_t_0, a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec_Decoder(PyObject *o) { - struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_11_genexpr(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *)o; PyObject* tmp; - tmp = ((PyObject*)p->weights); - p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_outer_scope); + p->__pyx_outer_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_feat); + p->__pyx_v_feat = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_0); + p->__pyx_t_0 = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyObject *__pyx_getprop_5_cdec_7Decoder_weights(PyObject *o, void *x) { - return __pyx_pw_5_cdec_7Decoder_7weights_1__get__(o); -} - -static int __pyx_setprop_5_cdec_7Decoder_weights(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_5_cdec_7Decoder_7weights_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} - -static PyMethodDef __pyx_methods_5_cdec_Decoder[] = { - {__Pyx_NAMESTR("read_weights"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_5read_weights, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("translate"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_7translate, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_11_genexpr[] = { {0, 0, 0, 0} }; -static struct PyGetSetDef __pyx_getsets_5_cdec_Decoder[] = { - {(char *)"weights", __pyx_getprop_5_cdec_7Decoder_weights, __pyx_setprop_5_cdec_7Decoder_weights, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_Decoder = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_11_genexpr = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -11774,7 +18867,7 @@ static PyNumberMethods __pyx_tp_as_number_Decoder = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Decoder = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_11_genexpr = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -11787,13 +18880,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Decoder = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Decoder = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_11_genexpr = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Decoder = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_11_genexpr = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -11814,12 +18907,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Decoder = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Decoder = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_11_genexpr = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Decoder"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Decoder), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_11_genexpr"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Decoder, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_11_genexpr, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -11829,26 +18922,26 @@ static PyTypeObject __pyx_type_5_cdec_Decoder = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Decoder, /*tp_as_number*/ - &__pyx_tp_as_sequence_Decoder, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Decoder, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_11_genexpr, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_11_genexpr, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_11_genexpr, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Decoder, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct_11_genexpr, /*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_Decoder, /*tp_traverse*/ - __pyx_tp_clear_5_cdec_Decoder, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_11_genexpr, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_11_genexpr, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Decoder, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_11_genexpr, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_5_cdec_Decoder, /*tp_getset*/ + 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -11856,7 +18949,7 @@ static PyTypeObject __pyx_type_5_cdec_Decoder = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Decoder, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_11_genexpr, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -11870,44 +18963,44 @@ static PyTypeObject __pyx_type_5_cdec_Decoder = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct____iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_12___get__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *)o); p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_12___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_12___get__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_12___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_HypergraphEdge *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct____iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_12___get__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_12___get__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -11965,7 +19058,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct____iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_12___get__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -11978,13 +19071,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct____iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct____iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_12___get__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_12___get__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -12005,12 +19098,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_12___get__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct____iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct____iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_12___get__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_12___get__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -12020,24 +19113,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct____iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct____iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct____iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_12___get__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_12___get__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_12___get__, /*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____iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_12___get__, /*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____iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_12___get__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_12___get__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct____iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_12___get__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -12047,7 +19140,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct____iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_12___get__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -12061,44 +19154,44 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_13___get__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *)o); p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_13___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_13___get__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_13___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_HypergraphNode *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_1___iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_13___get__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_13___get__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -12156,7 +19249,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1___iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_13___get__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -12169,13 +19262,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1___iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1___iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_13___get__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_13___get__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -12196,12 +19289,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_13___get__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_1___iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_13___get__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_13___get__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -12211,24 +19304,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_1___iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_1___iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_1___iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_13___get__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_13___get__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_13___get__, /*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___iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_13___get__, /*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___iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_13___get__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_13___get__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_1___iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_13___get__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -12238,7 +19331,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_13___get__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -12251,61 +19344,45 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { 0, /*tp_version_tag*/ #endif }; - -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p; + +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_14___get__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *)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(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_14___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(((PyObject *)p->__pyx_v_sentence)); - Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_14___get__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } - if (p->__pyx_v_sentence) { - e = (*v)(p->__pyx_v_sentence, a); if (e) return e; - } - if (p->__pyx_v_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(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_14___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_HypergraphNode *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_2_kbest[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_14___get__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_14___get__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -12363,7 +19440,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_14___get__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -12376,13 +19453,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_2_kbest = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_14___get__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_14___get__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -12403,12 +19480,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_14___get__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_2_kbest"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_14___get__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_14___get__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -12418,24 +19495,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_2_kbest, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_2_kbest, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_2_kbest, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_14___get__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_14___get__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_14___get__, /*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, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_14___get__, /*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, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_14___get__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_14___get__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_2_kbest, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_14___get__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -12445,7 +19522,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_14___get__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -12459,60 +19536,44 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_tree(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_15___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *)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_3_kbest_tree(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_15___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(p->__pyx_v_size); - Py_XDECREF(((PyObject *)p->__pyx_v_tree)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_kbest_tree(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_15___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *)o; 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_3_kbest_tree(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_15___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Lattice *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_3_kbest_tree[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_15___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_kbest_tree = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_15___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -12570,7 +19631,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_kbest_tree = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_15___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -12583,13 +19644,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree = 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_3_kbest_tree = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_15___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_kbest_tree = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_15___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -12610,12 +19671,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_kbest_tree = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_15___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_3_kbest_tree"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_15___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_15___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -12625,24 +19686,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_3_kbest_tree, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_3_kbest_tree, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_15___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_15___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_15___iter__, /*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_kbest_tree, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_15___iter__, /*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_kbest_tree, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_15___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_15___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_15___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -12652,7 +19713,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_15___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -12666,60 +19727,44 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_4_kbest_features(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_16_todot(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o); - p->__pyx_v_fmap = 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *)o); p->__pyx_v_self = 0; - p->__pyx_v_size = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; - Py_XDECREF(((PyObject *)p->__pyx_v_fmap)); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_16_todot(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_16_todot(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; - if (p->__pyx_v_fmap) { - e = (*v)(((PyObject*)p->__pyx_v_fmap), a); if (e) return e; - } + struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *)o; 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; - } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_16_todot(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_fmap); - p->__pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Lattice *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_4_kbest_features[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_16_todot[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4_kbest_features = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_16_todot = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -12777,7 +19822,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4_kbest_features = #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4_kbest_features = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_16_todot = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -12790,13 +19835,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4_kbest_feature 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_4_kbest_features = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_16_todot = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4_kbest_features = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_16_todot = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -12817,12 +19862,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4_kbest_features = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_kbest_features = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_16_todot = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_4_kbest_features"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_16_todot"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_16_todot, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -12832,24 +19877,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_kbest_features = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_4_kbest_features, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_4_kbest_features, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_4_kbest_features, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_16_todot, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_16_todot, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_16_todot, /*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_4_kbest_features, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_16_todot, /*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_4_kbest_features, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_16_todot, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_16_todot, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_16_todot, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -12859,7 +19904,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_kbest_features = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_16_todot, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -12873,52 +19918,92 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_kbest_features = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_5_sample(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_17_lines(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o); - p->__pyx_v_self = 0; - p->__pyx_v_sentence = 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *)o); + p->__pyx_outer_scope = 0; + p->__pyx_v_delta = 0; + p->__pyx_v_i = 0; + p->__pyx_v_label = 0; + p->__pyx_v_weight = 0; + p->__pyx_t_1 = 0; + p->__pyx_t_3 = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5_sample(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; - Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(((PyObject *)p->__pyx_v_sentence)); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_17_lines(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *)o; + Py_XDECREF(((PyObject *)p->__pyx_outer_scope)); + Py_XDECREF(p->__pyx_v_delta); + Py_XDECREF(p->__pyx_v_i); + Py_XDECREF(p->__pyx_v_label); + Py_XDECREF(p->__pyx_v_weight); + Py_XDECREF(p->__pyx_t_1); + Py_XDECREF(p->__pyx_t_3); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_5_sample(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_17_lines(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; - if (p->__pyx_v_self) { - e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *)o; + if (p->__pyx_outer_scope) { + e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e; + } + if (p->__pyx_v_delta) { + e = (*v)(p->__pyx_v_delta, a); if (e) return e; + } + if (p->__pyx_v_i) { + e = (*v)(p->__pyx_v_i, a); if (e) return e; + } + if (p->__pyx_v_label) { + e = (*v)(p->__pyx_v_label, 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_weight) { + e = (*v)(p->__pyx_v_weight, a); if (e) return e; + } + if (p->__pyx_t_1) { + e = (*v)(p->__pyx_t_1, a); if (e) return e; + } + if (p->__pyx_t_3) { + e = (*v)(p->__pyx_t_3, a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_5_sample(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_17_lines(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_outer_scope); + p->__pyx_outer_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_delta); + p->__pyx_v_delta = 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); + tmp = ((PyObject*)p->__pyx_v_i); + p->__pyx_v_i = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_label); + p->__pyx_v_label = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_weight); + p->__pyx_v_weight = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_1); + p->__pyx_t_1 = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_3); + p->__pyx_t_3 = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_5_sample[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_17_lines[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_5_sample = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_17_lines = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -12976,7 +20061,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_5_sample = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_5_sample = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_17_lines = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -12989,13 +20074,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_5_sample = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_5_sample = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_17_lines = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_5_sample = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_17_lines = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -13016,12 +20101,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_5_sample = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5_sample = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_17_lines = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_5_sample"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_17_lines"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5_sample, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_17_lines, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -13031,24 +20116,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5_sample = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_5_sample, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_5_sample, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_5_sample, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_17_lines, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_17_lines, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_17_lines, /*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_5_sample, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_17_lines, /*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_5_sample, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_5_sample, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_17_lines, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_17_lines, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_5_sample, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_17_lines, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -13058,7 +20143,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5_sample = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_5_sample, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_17_lines, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -13072,44 +20157,60 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5_sample = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_6___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_18___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *)o); + p->__pyx_v_i = 0; p->__pyx_v_self = 0; + p->__pyx_t_1 = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_6___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_18___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *)o; + Py_XDECREF(p->__pyx_v_i); Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(p->__pyx_t_1); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_6___iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_18___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *)o; + if (p->__pyx_v_i) { + e = (*v)(p->__pyx_v_i, 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_t_1) { + e = (*v)(p->__pyx_t_1, a); if (e) return e; + } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_6___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_18___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *)o; PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_i); + p->__pyx_v_i = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Lattice *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SufficientStats *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_1); + p->__pyx_t_1 = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_6___iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_18___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_6___iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_18___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -13167,7 +20268,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_6___iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_6___iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_18___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -13180,13 +20281,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_6___iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_6___iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_18___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_6___iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_18___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -13207,12 +20308,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_6___iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_6___iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_18___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_6___iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_18___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_6___iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_18___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -13222,24 +20323,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_6___iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_6___iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_6___iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_6___iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_18___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_18___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_18___iter__, /*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_6___iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_18___iter__, /*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_6___iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_6___iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_18___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_18___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_6___iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_18___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -13249,7 +20350,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_6___iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_6___iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_18___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -13263,44 +20364,44 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_6___iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_7_todot(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_19___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *)o); p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_7_todot(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_19___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_7_todot(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_19___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_7_todot(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_19___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Lattice *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_CandidateSet *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_7_todot[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_19___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_7_todot = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_19___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -13358,7 +20459,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_7_todot = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_7_todot = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_19___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -13371,13 +20472,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_7_todot = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_7_todot = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_19___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_7_todot = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_19___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -13398,12 +20499,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_7_todot = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7_todot = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_19___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_7_todot"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_19___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_7_todot, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_19___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -13413,24 +20514,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7_todot = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_7_todot, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_7_todot, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_7_todot, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_19___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_19___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_19___iter__, /*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_7_todot, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_19___iter__, /*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_7_todot, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_7_todot, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_19___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_19___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_7_todot, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_19___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -13440,7 +20541,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7_todot = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_7_todot, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_19___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -13454,92 +20555,92 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7_todot = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_8_lines(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_20__make_config(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *)o); - p->__pyx_outer_scope = 0; - p->__pyx_v_delta = 0; - p->__pyx_v_i = 0; - p->__pyx_v_label = 0; - p->__pyx_v_weight = 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *)o); + p->__pyx_v_config = 0; + p->__pyx_v_info = 0; + p->__pyx_v_key = 0; + p->__pyx_v_name = 0; + p->__pyx_v_value = 0; + p->__pyx_t_0 = 0; p->__pyx_t_1 = 0; - p->__pyx_t_3 = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8_lines(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *)o; - Py_XDECREF(((PyObject *)p->__pyx_outer_scope)); - Py_XDECREF(p->__pyx_v_delta); - Py_XDECREF(p->__pyx_v_i); - Py_XDECREF(p->__pyx_v_label); - Py_XDECREF(p->__pyx_v_weight); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_20__make_config(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *)o; + Py_XDECREF(p->__pyx_v_config); + Py_XDECREF(p->__pyx_v_info); + Py_XDECREF(p->__pyx_v_key); + Py_XDECREF(p->__pyx_v_name); + Py_XDECREF(p->__pyx_v_value); + Py_XDECREF(p->__pyx_t_0); Py_XDECREF(p->__pyx_t_1); - Py_XDECREF(p->__pyx_t_3); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_8_lines(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_20__make_config(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *)o; - if (p->__pyx_outer_scope) { - e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e; + struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *)o; + if (p->__pyx_v_config) { + e = (*v)(p->__pyx_v_config, a); if (e) return e; } - if (p->__pyx_v_delta) { - e = (*v)(p->__pyx_v_delta, a); if (e) return e; + if (p->__pyx_v_info) { + e = (*v)(p->__pyx_v_info, a); if (e) return e; } - if (p->__pyx_v_i) { - e = (*v)(p->__pyx_v_i, a); if (e) return e; + if (p->__pyx_v_key) { + e = (*v)(p->__pyx_v_key, a); if (e) return e; } - if (p->__pyx_v_label) { - e = (*v)(p->__pyx_v_label, a); if (e) return e; + if (p->__pyx_v_name) { + e = (*v)(p->__pyx_v_name, a); if (e) return e; } - if (p->__pyx_v_weight) { - e = (*v)(p->__pyx_v_weight, a); if (e) return e; + if (p->__pyx_v_value) { + e = (*v)(p->__pyx_v_value, a); if (e) return e; + } + if (p->__pyx_t_0) { + e = (*v)(p->__pyx_t_0, a); if (e) return e; } if (p->__pyx_t_1) { e = (*v)(p->__pyx_t_1, a); if (e) return e; } - if (p->__pyx_t_3) { - e = (*v)(p->__pyx_t_3, a); if (e) return e; - } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_8_lines(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_20__make_config(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_outer_scope); - p->__pyx_outer_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_7_todot *)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_config); + p->__pyx_v_config = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_delta); - p->__pyx_v_delta = Py_None; Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_info); + p->__pyx_v_info = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_i); - p->__pyx_v_i = Py_None; Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_key); + p->__pyx_v_key = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_label); - p->__pyx_v_label = Py_None; Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_name); + p->__pyx_v_name = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_weight); - p->__pyx_v_weight = Py_None; Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_value); + p->__pyx_v_value = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_0); + p->__pyx_t_0 = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_t_1); p->__pyx_t_1 = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_t_3); - p->__pyx_t_3 = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_8_lines[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_20__make_config[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_8_lines = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_20__make_config = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -13597,7 +20698,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_8_lines = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_8_lines = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_20__make_config = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -13610,13 +20711,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_8_lines = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_8_lines = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_20__make_config = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_8_lines = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_20__make_config = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -13637,12 +20738,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_8_lines = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8_lines = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_20__make_config = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_8_lines"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_8_lines), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_20__make_config"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8_lines, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_20__make_config, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -13652,24 +20753,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8_lines = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_8_lines, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_8_lines, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_8_lines, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_20__make_config, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_20__make_config, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_20__make_config, /*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_8_lines, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_20__make_config, /*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_8_lines, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_8_lines, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_20__make_config, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_20__make_config, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_8_lines, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_20__make_config, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -13679,7 +20780,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8_lines = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_8_lines, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_20__make_config, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -13693,60 +20794,44 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8_lines = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_9___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_21___cinit__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *)o); - p->__pyx_v_i = 0; - p->__pyx_v_self = 0; - p->__pyx_t_1 = 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *)o); + p->__pyx_v_config = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_9___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *)o; - Py_XDECREF(p->__pyx_v_i); - Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(p->__pyx_t_1); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_21___cinit__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *)o; + Py_XDECREF(p->__pyx_v_config); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_9___iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_21___cinit__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *)o; - if (p->__pyx_v_i) { - e = (*v)(p->__pyx_v_i, 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_t_1) { - e = (*v)(p->__pyx_t_1, a); if (e) return e; + struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *)o; + if (p->__pyx_v_config) { + e = (*v)(p->__pyx_v_config, a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_9___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_21___cinit__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_i); - p->__pyx_v_i = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SufficientStats *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_t_1); - p->__pyx_t_1 = Py_None; Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_config); + p->__pyx_v_config = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_9___iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_21___cinit__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_9___iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_21___cinit__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -13804,7 +20889,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_9___iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_9___iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_21___cinit__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -13817,13 +20902,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_9___iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_9___iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_21___cinit__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_9___iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_21___cinit__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -13844,12 +20929,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_9___iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_9___iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_21___cinit__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_9___iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_9___iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_21___cinit__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_9___iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_21___cinit__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -13859,24 +20944,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_9___iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_9___iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_9___iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_9___iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_21___cinit__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_21___cinit__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_21___cinit__, /*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_9___iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_21___cinit__, /*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_9___iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_9___iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_21___cinit__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_21___cinit__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_9___iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_21___cinit__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -13886,7 +20971,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_9___iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_9___iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_21___cinit__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -13900,44 +20985,60 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_9___iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_10___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_22_genexpr(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *)o); - p->__pyx_v_self = 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *)o); + p->__pyx_outer_scope = 0; + p->__pyx_v_kv = 0; + p->__pyx_t_0 = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_10___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *)o; - Py_XDECREF(((PyObject *)p->__pyx_v_self)); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_22_genexpr(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *)o; + Py_XDECREF(((PyObject *)p->__pyx_outer_scope)); + Py_XDECREF(p->__pyx_v_kv); + Py_XDECREF(p->__pyx_t_0); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_10___iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_22_genexpr(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *)o; - if (p->__pyx_v_self) { - e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *)o; + if (p->__pyx_outer_scope) { + e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e; + } + if (p->__pyx_v_kv) { + e = (*v)(p->__pyx_v_kv, a); if (e) return e; + } + if (p->__pyx_t_0) { + e = (*v)(p->__pyx_t_0, a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_10___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_22_genexpr(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_CandidateSet *)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_outer_scope); + p->__pyx_outer_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_kv); + p->__pyx_v_kv = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_0); + p->__pyx_t_0 = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_10___iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_22_genexpr[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_10___iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_22_genexpr = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -13995,7 +21096,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_10___iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_10___iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_22_genexpr = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -14008,13 +21109,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_10___iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_10___iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_22_genexpr = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_10___iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_22_genexpr = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -14035,12 +21136,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_10___iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_10___iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_22_genexpr = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_10___iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_10___iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_22_genexpr"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_10___iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_22_genexpr, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -14050,24 +21151,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_10___iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_10___iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_10___iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_10___iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_22_genexpr, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_22_genexpr, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_22_genexpr, /*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_10___iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_22_genexpr, /*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_10___iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_10___iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_22_genexpr, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_22_genexpr, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_10___iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_22_genexpr, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -14077,7 +21178,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_10___iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_10___iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_22_genexpr, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -14111,29 +21212,42 @@ static struct PyModuleDef __pyx_moduledef = { static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0}, - {&__pyx_n_s_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 1, 1}, + {&__pyx_kp_s_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 1, 0}, {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0}, + {&__pyx_kp_s_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 0, 1, 0}, {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0}, - {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0}, + {&__pyx_kp_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 0}, + {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0}, {&__pyx_kp_s_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 1, 0}, - {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0}, - {&__pyx_kp_s_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 0, 1, 0}, - {&__pyx_kp_s_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 1, 0}, - {&__pyx_kp_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 0}, {&__pyx_kp_s_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 0, 1, 0}, {&__pyx_kp_s_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 1, 0}, + {&__pyx_kp_s_25, __pyx_k_25, sizeof(__pyx_k_25), 0, 0, 1, 0}, {&__pyx_kp_s_26, __pyx_k_26, sizeof(__pyx_k_26), 0, 0, 1, 0}, {&__pyx_kp_s_27, __pyx_k_27, sizeof(__pyx_k_27), 0, 0, 1, 0}, + {&__pyx_kp_s_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 0, 1, 0}, + {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0}, {&__pyx_kp_s_30, __pyx_k_30, sizeof(__pyx_k_30), 0, 0, 1, 0}, {&__pyx_kp_s_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 0, 1, 0}, - {&__pyx_kp_s_33, __pyx_k_33, sizeof(__pyx_k_33), 0, 0, 1, 0}, + {&__pyx_kp_s_34, __pyx_k_34, sizeof(__pyx_k_34), 0, 0, 1, 0}, {&__pyx_kp_s_35, __pyx_k_35, sizeof(__pyx_k_35), 0, 0, 1, 0}, {&__pyx_kp_s_37, __pyx_k_37, sizeof(__pyx_k_37), 0, 0, 1, 0}, + {&__pyx_kp_s_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 1, 0}, + {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0}, {&__pyx_kp_s_40, __pyx_k_40, sizeof(__pyx_k_40), 0, 0, 1, 0}, + {&__pyx_kp_s_42, __pyx_k_42, sizeof(__pyx_k_42), 0, 0, 1, 0}, + {&__pyx_kp_s_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 1, 0}, + {&__pyx_kp_s_44, __pyx_k_44, sizeof(__pyx_k_44), 0, 0, 1, 0}, + {&__pyx_kp_s_48, __pyx_k_48, sizeof(__pyx_k_48), 0, 0, 1, 0}, + {&__pyx_kp_s_51, __pyx_k_51, sizeof(__pyx_k_51), 0, 0, 1, 0}, + {&__pyx_kp_s_56, __pyx_k_56, sizeof(__pyx_k_56), 0, 0, 1, 0}, + {&__pyx_n_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 1}, + {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0}, + {&__pyx_kp_s_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 1, 0}, {&__pyx_n_s__BLEU, __pyx_k__BLEU, sizeof(__pyx_k__BLEU), 0, 0, 1, 1}, {&__pyx_n_s__Exception, __pyx_k__Exception, sizeof(__pyx_k__Exception), 0, 0, 1, 1}, {&__pyx_n_s__IBM_BLEU, __pyx_k__IBM_BLEU, sizeof(__pyx_k__IBM_BLEU), 0, 0, 1, 1}, {&__pyx_n_s__IndexError, __pyx_k__IndexError, sizeof(__pyx_k__IndexError), 0, 0, 1, 1}, + {&__pyx_n_s__InvalidConfig, __pyx_k__InvalidConfig, sizeof(__pyx_k__InvalidConfig), 0, 0, 1, 1}, {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1}, {&__pyx_n_s__NotImplemented, __pyx_k__NotImplemented, sizeof(__pyx_k__NotImplemented), 0, 0, 1, 1}, {&__pyx_n_s__ParseFailed, __pyx_k__ParseFailed, sizeof(__pyx_k__ParseFailed), 0, 0, 1, 1}, @@ -14144,50 +21258,73 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, {&__pyx_n_s___cdec, __pyx_k___cdec, sizeof(__pyx_k___cdec), 0, 0, 1, 1}, + {&__pyx_n_s___make_config, __pyx_k___make_config, sizeof(__pyx_k___make_config), 0, 0, 1, 1}, + {&__pyx_n_s___phrase, __pyx_k___phrase, sizeof(__pyx_k___phrase), 0, 0, 1, 1}, {&__pyx_n_s__beam_alpha, __pyx_k__beam_alpha, sizeof(__pyx_k__beam_alpha), 0, 0, 1, 1}, {&__pyx_n_s__config, __pyx_k__config, sizeof(__pyx_k__config), 0, 0, 1, 1}, - {&__pyx_n_s__decode, __pyx_k__decode, sizeof(__pyx_k__decode), 0, 0, 1, 1}, + {&__pyx_n_s__config_str, __pyx_k__config_str, sizeof(__pyx_k__config_str), 0, 0, 1, 1}, + {&__pyx_n_s__csplit, __pyx_k__csplit, sizeof(__pyx_k__csplit), 0, 0, 1, 1}, {&__pyx_n_s__delta, __pyx_k__delta, sizeof(__pyx_k__delta), 0, 0, 1, 1}, {&__pyx_n_s__density, __pyx_k__density, sizeof(__pyx_k__density), 0, 0, 1, 1}, {&__pyx_n_s__dot, __pyx_k__dot, sizeof(__pyx_k__dot), 0, 0, 1, 1}, + {&__pyx_n_s__e, __pyx_k__e, sizeof(__pyx_k__e), 0, 0, 1, 1}, {&__pyx_n_s__encode, __pyx_k__encode, sizeof(__pyx_k__encode), 0, 0, 1, 1}, {&__pyx_n_s__encoding, __pyx_k__encoding, sizeof(__pyx_k__encoding), 0, 0, 1, 1}, {&__pyx_n_s__enumerate, __pyx_k__enumerate, sizeof(__pyx_k__enumerate), 0, 0, 1, 1}, {&__pyx_n_s__eval, __pyx_k__eval, sizeof(__pyx_k__eval), 0, 0, 1, 1}, {&__pyx_n_s__evaluator, __pyx_k__evaluator, sizeof(__pyx_k__evaluator), 0, 0, 1, 1}, + {&__pyx_n_s__f, __pyx_k__f, sizeof(__pyx_k__f), 0, 0, 1, 1}, + {&__pyx_n_s__formalism, __pyx_k__formalism, sizeof(__pyx_k__formalism), 0, 0, 1, 1}, + {&__pyx_n_s__fst, __pyx_k__fst, sizeof(__pyx_k__fst), 0, 0, 1, 1}, + {&__pyx_n_s__genexpr, __pyx_k__genexpr, sizeof(__pyx_k__genexpr), 0, 0, 1, 1}, + {&__pyx_n_s__get, __pyx_k__get, sizeof(__pyx_k__get), 0, 0, 1, 1}, {&__pyx_n_s__grammar, __pyx_k__grammar, sizeof(__pyx_k__grammar), 0, 0, 1, 1}, {&__pyx_n_s__hypergraph, __pyx_k__hypergraph, sizeof(__pyx_k__hypergraph), 0, 0, 1, 1}, {&__pyx_n_s__i, __pyx_k__i, sizeof(__pyx_k__i), 0, 0, 1, 1}, + {&__pyx_n_s__in_edges, __pyx_k__in_edges, sizeof(__pyx_k__in_edges), 0, 0, 1, 1}, + {&__pyx_n_s__info, __pyx_k__info, sizeof(__pyx_k__info), 0, 0, 1, 1}, {&__pyx_n_s__inp, __pyx_k__inp, sizeof(__pyx_k__inp), 0, 0, 1, 1}, {&__pyx_n_s__items, __pyx_k__items, sizeof(__pyx_k__items), 0, 0, 1, 1}, {&__pyx_n_s__join, __pyx_k__join, sizeof(__pyx_k__join), 0, 0, 1, 1}, {&__pyx_n_s__k, __pyx_k__k, sizeof(__pyx_k__k), 0, 0, 1, 1}, + {&__pyx_n_s__key, __pyx_k__key, sizeof(__pyx_k__key), 0, 0, 1, 1}, {&__pyx_n_s__label, __pyx_k__label, sizeof(__pyx_k__label), 0, 0, 1, 1}, + {&__pyx_n_s__lexalign, __pyx_k__lexalign, sizeof(__pyx_k__lexalign), 0, 0, 1, 1}, + {&__pyx_n_s__lextrans, __pyx_k__lextrans, sizeof(__pyx_k__lextrans), 0, 0, 1, 1}, + {&__pyx_n_s__lhs, __pyx_k__lhs, sizeof(__pyx_k__lhs), 0, 0, 1, 1}, {&__pyx_n_s__lines, __pyx_k__lines, sizeof(__pyx_k__lines), 0, 0, 1, 1}, {&__pyx_n_s__name, __pyx_k__name, sizeof(__pyx_k__name), 0, 0, 1, 1}, {&__pyx_n_s__open, __pyx_k__open, sizeof(__pyx_k__open), 0, 0, 1, 1}, + {&__pyx_n_s__pb, __pyx_k__pb, sizeof(__pyx_k__pb), 0, 0, 1, 1}, + {&__pyx_n_s__phrase, __pyx_k__phrase, sizeof(__pyx_k__phrase), 0, 0, 1, 1}, {&__pyx_n_s__plf, __pyx_k__plf, sizeof(__pyx_k__plf), 0, 0, 1, 1}, {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1}, {&__pyx_n_s__refs, __pyx_k__refs, sizeof(__pyx_k__refs), 0, 0, 1, 1}, {&__pyx_n_s__replace, __pyx_k__replace, sizeof(__pyx_k__replace), 0, 0, 1, 1}, + {&__pyx_n_s__scfg, __pyx_k__scfg, sizeof(__pyx_k__scfg), 0, 0, 1, 1}, + {&__pyx_n_s__scores, __pyx_k__scores, sizeof(__pyx_k__scores), 0, 0, 1, 1}, {&__pyx_n_s__self, __pyx_k__self, sizeof(__pyx_k__self), 0, 0, 1, 1}, {&__pyx_n_s__sentence, __pyx_k__sentence, sizeof(__pyx_k__sentence), 0, 0, 1, 1}, + {&__pyx_n_s__span, __pyx_k__span, sizeof(__pyx_k__span), 0, 0, 1, 1}, {&__pyx_n_s__split, __pyx_k__split, sizeof(__pyx_k__split), 0, 0, 1, 1}, + {&__pyx_n_s__startswith, __pyx_k__startswith, sizeof(__pyx_k__startswith), 0, 0, 1, 1}, {&__pyx_n_s__strip, __pyx_k__strip, sizeof(__pyx_k__strip), 0, 0, 1, 1}, + {&__pyx_n_s__tagger, __pyx_k__tagger, sizeof(__pyx_k__tagger), 0, 0, 1, 1}, {&__pyx_n_s__utf8, __pyx_k__utf8, sizeof(__pyx_k__utf8), 0, 0, 1, 1}, + {&__pyx_n_s__value, __pyx_k__value, sizeof(__pyx_k__value), 0, 0, 1, 1}, {&__pyx_n_s__weight, __pyx_k__weight, sizeof(__pyx_k__weight), 0, 0, 1, 1}, {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 = 13; __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 = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __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[1]; __pyx_lineno = 13; __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[1]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_NotImplemented = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplemented); if (!__pyx_builtin_NotImplemented) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __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[2]; __pyx_lineno = 105; __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[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __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 = 47; __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 = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; return -1; @@ -14197,6 +21334,20 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + /* "_cdec.pyx":9 + * cdef bytes ret + * if isinstance(sentence, unicode): + * ret = sentence.encode('utf8') # <<<<<<<<<<<<<< + * elif isinstance(sentence, str): + * ret = sentence + */ + __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_2); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2)); + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":76 * elif op == 3: # != * return not (x == y) @@ -14204,96 +21355,51 @@ static int __Pyx_InitCachedConstants(void) { * * def __len__(self): */ - __pyx_k_tuple_3 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_3); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_2)); - PyTuple_SET_ITEM(__pyx_k_tuple_3, 0, ((PyObject *)__pyx_kp_s_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_3)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":17 - * hypergraph.ViterbiESentence(self.hg[0], &trans) - * cdef str sentence = GetString(trans).c_str() - * return sentence.decode('utf8') # <<<<<<<<<<<<<< - * - * def viterbi_tree(self): - */ - __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_4); - __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":21 - * def viterbi_tree(self): - * cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str() - * return tree.decode('utf8') # <<<<<<<<<<<<<< - * - * def viterbi_source_tree(self): - */ - __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_5); - __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_4)); + PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_kp_s_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_4)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5)); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":25 - * def viterbi_source_tree(self): - * cdef str tree = hypergraph.ViterbiFTree(self.hg[0]).c_str() - * return tree.decode('utf8') # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":2 + * def _phrase(phrase): + * return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) # <<<<<<<<<<<<<< * - * def viterbi_features(self): - */ - __pyx_k_tuple_6 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_6); - __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_6, 0, ((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_6)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":42 - * if not derivation: break - * sentence = GetString(derivation._yield).c_str() - * yield sentence.decode('utf8') # <<<<<<<<<<<<<< - * finally: - * del derivations + * cdef class TRule: */ - __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_7); + __pyx_k_tuple_9 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_9); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_7, 0, ((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_7)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_9)); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 - * if not derivation: break - * tree = GetString(derivation._yield).c_str() - * yield tree.decode('utf8') # <<<<<<<<<<<<<< - * finally: - * del derivations + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":177 + * elif op == 3: # != + * return not (x == y) + * raise NotImplemented('comparison not implemented for HypergraphEdge') # <<<<<<<<<<<<<< + * + * cdef class HypergraphNode: */ - __pyx_k_tuple_8 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__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)); + __pyx_k_tuple_14 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_14)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_14); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_13)); + PyTuple_SET_ITEM(__pyx_k_tuple_14, 0, ((PyObject *)__pyx_kp_s_13)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_13)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_14)); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":85 - * for k in range(hypos.size()): - * sentence = GetString(hypos[0][k].words).c_str() - * yield sentence.decode('utf8') # <<<<<<<<<<<<<< - * finally: - * del hypos + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":214 + * elif op == 3: # != + * return not (x == y) + * raise NotImplemented('comparison not implemented for HypergraphNode') # <<<<<<<<<<<<<< */ - __pyx_k_tuple_9 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__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)); + __pyx_k_tuple_16 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_16)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_16); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_15)); + PyTuple_SET_ITEM(__pyx_k_tuple_16, 0, ((PyObject *)__pyx_kp_s_15)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_15)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_16)); /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":13 * else: @@ -14302,12 +21408,12 @@ static int __Pyx_InitCachedConstants(void) { * if not isinstance(inp, str): * raise TypeError('Cannot create lattice from %s' % type(inp)) */ - __pyx_k_tuple_12 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_12); + __pyx_k_tuple_17 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_17)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_17); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_12, 0, ((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_17, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_17)); /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":21 * def __getitem__(self, int index): @@ -14316,194 +21422,243 @@ static int __Pyx_InitCachedConstants(void) { * arcs = [] * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] */ - __pyx_k_tuple_15 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_15)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_15); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_15, 0, ((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_15)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":30 - * arc = &arc_vector[i] - * label = TDConvert(arc.label) - * arcs.append((label.decode('utf8'), arc.cost, arc.dist2next)) # <<<<<<<<<<<<<< - * return tuple(arcs) - * - */ - __pyx_k_tuple_16 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_16)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_16); - __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_16, 0, ((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_16)); + __pyx_k_tuple_20 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_20); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_19)); + PyTuple_SET_ITEM(__pyx_k_tuple_20, 0, ((PyObject *)__pyx_kp_s_19)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20)); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":35 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":34 * def __setitem__(self, int index, tuple arcs): * if not 0 <= index < len(self): * raise IndexError('lattice index out of range') # <<<<<<<<<<<<<< * cdef lattice.LatticeArc* arc * for (label, cost, dist2next) in arcs: */ - __pyx_k_tuple_17 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_17)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_17); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_17, 0, ((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_17)); + __pyx_k_tuple_21 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_21)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_21); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_19)); + PyTuple_SET_ITEM(__pyx_k_tuple_21, 0, ((PyObject *)__pyx_kp_s_19)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21)); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":39 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":38 * for (label, cost, dist2next) in arcs: * if isinstance(label, unicode): * label = label.encode('utf8') # <<<<<<<<<<<<<< * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) * self.lattice[0][index].push_back(arc[0]) */ - __pyx_k_tuple_18 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_18)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_18); + __pyx_k_tuple_22 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_22)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_22); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_18, 0, ((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_22, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_18)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22)); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":65 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":64 * for i in range(len(self)): * for label, weight, delta in self[i]: * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) # <<<<<<<<<<<<<< * yield '%d [shape=doublecircle]' % len(self) * yield '}' */ - __pyx_k_tuple_25 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_25); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_23)); - PyTuple_SET_ITEM(__pyx_k_tuple_25, 0, ((PyObject *)__pyx_kp_s_23)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_23)); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_24)); - PyTuple_SET_ITEM(__pyx_k_tuple_25, 1, ((PyObject *)__pyx_kp_s_24)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_24)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_25)); + __pyx_k_tuple_29 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_29)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_29); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_27)); + PyTuple_SET_ITEM(__pyx_k_tuple_29, 0, ((PyObject *)__pyx_kp_s_27)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_27)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_28)); + PyTuple_SET_ITEM(__pyx_k_tuple_29, 1, ((PyObject *)__pyx_kp_s_28)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_28)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_29)); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":59 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":58 * * def todot(self): * def lines(): # <<<<<<<<<<<<<< * yield 'digraph lattice {' * yield 'rankdir = LR;' */ - __pyx_k_tuple_28 = PyTuple_New(4); if (unlikely(!__pyx_k_tuple_28)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_28); + __pyx_k_tuple_32 = PyTuple_New(4); if (unlikely(!__pyx_k_tuple_32)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_32); __Pyx_INCREF(((PyObject *)__pyx_n_s__i)); - PyTuple_SET_ITEM(__pyx_k_tuple_28, 0, ((PyObject *)__pyx_n_s__i)); + PyTuple_SET_ITEM(__pyx_k_tuple_32, 0, ((PyObject *)__pyx_n_s__i)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i)); __Pyx_INCREF(((PyObject *)__pyx_n_s__label)); - PyTuple_SET_ITEM(__pyx_k_tuple_28, 1, ((PyObject *)__pyx_n_s__label)); + PyTuple_SET_ITEM(__pyx_k_tuple_32, 1, ((PyObject *)__pyx_n_s__label)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__label)); __Pyx_INCREF(((PyObject *)__pyx_n_s__weight)); - PyTuple_SET_ITEM(__pyx_k_tuple_28, 2, ((PyObject *)__pyx_n_s__weight)); + PyTuple_SET_ITEM(__pyx_k_tuple_32, 2, ((PyObject *)__pyx_n_s__weight)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__weight)); __Pyx_INCREF(((PyObject *)__pyx_n_s__delta)); - PyTuple_SET_ITEM(__pyx_k_tuple_28, 3, ((PyObject *)__pyx_n_s__delta)); + PyTuple_SET_ITEM(__pyx_k_tuple_32, 3, ((PyObject *)__pyx_n_s__delta)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__delta)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_28)); - __pyx_k_codeobj_29 = (PyObject*)__Pyx_PyCode_New(0, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_30, __pyx_n_s__lines, 59, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_29)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_32)); + __pyx_k_codeobj_33 = (PyObject*)__Pyx_PyCode_New(0, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_32, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_34, __pyx_n_s__lines, 58, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_33)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":68 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":67 * yield '%d [shape=doublecircle]' % len(self) * yield '}' * return '\n'.join(lines()).encode('utf8') # <<<<<<<<<<<<<< */ - __pyx_k_tuple_32 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_32)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_32); - __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_32, 0, ((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_32)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":6 - * cdef bytes ret - * if isinstance(sentence, unicode): - * ret = sentence.encode('utf8') # <<<<<<<<<<<<<< - * elif isinstance(sentence, str): - * ret = sentence - */ - __pyx_k_tuple_34 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_34)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_34); + __pyx_k_tuple_36 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_36)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_36); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_34, 0, ((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_36, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_34)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_36)); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":89 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":79 * def __getitem__(self,int k): * if not 0 <= k < self.cs.size(): * raise IndexError('candidate set index out of range') # <<<<<<<<<<<<<< * cdef Candidate candidate = Candidate() * candidate.candidate = &self.cs[0][k] */ - __pyx_k_tuple_36 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_36)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_36); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_35)); - PyTuple_SET_ITEM(__pyx_k_tuple_36, 0, ((PyObject *)__pyx_kp_s_35)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_35)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_36)); + __pyx_k_tuple_38 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_38)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_38); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_37)); + PyTuple_SET_ITEM(__pyx_k_tuple_38, 0, ((PyObject *)__pyx_kp_s_37)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_37)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_38)); - /* "_cdec.pyx":47 - * - * def read_weights(self, cfg): - * with open(cfg) as fp: # <<<<<<<<<<<<<< + /* "_cdec.pyx":49 + * """ + * if config_str is None: + * formalism = config.get('formalism', None) # <<<<<<<<<<<<<< + * if formalism not in ('scfg', 'fst', 'lextrans', 'pb', + * 'csplit', 'tagger', 'lexalign'): + */ + __pyx_k_tuple_41 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_41)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_41); + __Pyx_INCREF(((PyObject *)__pyx_n_s__formalism)); + PyTuple_SET_ITEM(__pyx_k_tuple_41, 0, ((PyObject *)__pyx_n_s__formalism)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__formalism)); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_41, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_41)); + + /* "_cdec.pyx":87 + * with open(weights) as fp: * for line in fp: + * if line.strip().startswith('#'): continue # <<<<<<<<<<<<<< * fname, value = line.split() + * self.weights[fname.strip()] = float(value) */ - __pyx_k_tuple_38 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_38)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_38); + __pyx_k_tuple_45 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_45)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_45); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_44)); + PyTuple_SET_ITEM(__pyx_k_tuple_45, 0, ((PyObject *)__pyx_kp_s_44)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_44)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_45)); + + /* "_cdec.pyx":85 + * + * def read_weights(self, weights): + * with open(weights) as fp: # <<<<<<<<<<<<<< + * for line in fp: + * if line.strip().startswith('#'): continue + */ + __pyx_k_tuple_46 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_46)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_46); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_38, 0, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_46, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_38, 1, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_46, 1, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_38, 2, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_46, 2, Py_None); __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_38)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_46)); - /* "_cdec.pyx":54 + /* "_cdec.pyx":93 * def translate(self, sentence, grammar=None): * if isinstance(sentence, unicode): * inp = sentence.strip().encode('utf8') # <<<<<<<<<<<<<< * elif isinstance(sentence, str): * inp = sentence.strip() */ - __pyx_k_tuple_39 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_39)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_39); + __pyx_k_tuple_47 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_47)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_47); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_39, 0, ((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_47, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_39)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":153 + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_47)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":1 + * def _phrase(phrase): # <<<<<<<<<<<<<< + * return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) + * + */ + __pyx_k_tuple_49 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_49)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_49); + __Pyx_INCREF(((PyObject *)__pyx_n_s__phrase)); + PyTuple_SET_ITEM(__pyx_k_tuple_49, 0, ((PyObject *)__pyx_n_s__phrase)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__phrase)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__genexpr)); + PyTuple_SET_ITEM(__pyx_k_tuple_49, 1, ((PyObject *)__pyx_n_s__genexpr)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__genexpr)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__genexpr)); + PyTuple_SET_ITEM(__pyx_k_tuple_49, 2, ((PyObject *)__pyx_n_s__genexpr)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__genexpr)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_49)); + __pyx_k_codeobj_50 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_49, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_51, __pyx_n_s___phrase, 1, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_50)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":143 * return self.name.c_str() * * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< * TER = Scorer('TER') */ - __pyx_k_tuple_41 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_41)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_41); + __pyx_k_tuple_52 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_52); __Pyx_INCREF(((PyObject *)__pyx_n_s__IBM_BLEU)); - PyTuple_SET_ITEM(__pyx_k_tuple_41, 0, ((PyObject *)__pyx_n_s__IBM_BLEU)); + PyTuple_SET_ITEM(__pyx_k_tuple_52, 0, ((PyObject *)__pyx_n_s__IBM_BLEU)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IBM_BLEU)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_41)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_52)); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":154 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":144 * * BLEU = Scorer('IBM_BLEU') * TER = Scorer('TER') # <<<<<<<<<<<<<< */ - __pyx_k_tuple_42 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_42)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_42); + __pyx_k_tuple_53 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_53)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_53); __Pyx_INCREF(((PyObject *)__pyx_n_s__TER)); - PyTuple_SET_ITEM(__pyx_k_tuple_42, 0, ((PyObject *)__pyx_n_s__TER)); + PyTuple_SET_ITEM(__pyx_k_tuple_53, 0, ((PyObject *)__pyx_n_s__TER)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__TER)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_42)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_53)); + + /* "_cdec.pyx":27 + * class ParseFailed(Exception): pass + * + * def _make_config(config): # <<<<<<<<<<<<<< + * for key, value in config.items(): + * if isinstance(value, dict): + */ + __pyx_k_tuple_54 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_54)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_54); + __Pyx_INCREF(((PyObject *)__pyx_n_s__config)); + PyTuple_SET_ITEM(__pyx_k_tuple_54, 0, ((PyObject *)__pyx_n_s__config)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__config)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__key)); + PyTuple_SET_ITEM(__pyx_k_tuple_54, 1, ((PyObject *)__pyx_n_s__key)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__key)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__value)); + PyTuple_SET_ITEM(__pyx_k_tuple_54, 2, ((PyObject *)__pyx_n_s__value)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__value)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__name)); + PyTuple_SET_ITEM(__pyx_k_tuple_54, 3, ((PyObject *)__pyx_n_s__name)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__name)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__info)); + PyTuple_SET_ITEM(__pyx_k_tuple_54, 4, ((PyObject *)__pyx_n_s__info)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__info)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_54)); + __pyx_k_codeobj_55 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_54, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_56, __pyx_n_s___make_config, 27, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_55)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -14596,105 +21751,196 @@ PyMODINIT_FUNC PyInit__cdec(void) if (PyType_Ready(&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Hypergraph", (PyObject *)&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Hypergraph = &__pyx_type_5_cdec_Hypergraph; + if (PyType_Ready(&__pyx_type_5_cdec_TRule) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "TRule", (PyObject *)&__pyx_type_5_cdec_TRule) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_TRule = &__pyx_type_5_cdec_TRule; + __pyx_vtabptr_5_cdec_HypergraphEdge = &__pyx_vtable_5_cdec_HypergraphEdge; + __pyx_vtable_5_cdec_HypergraphEdge.init = (PyObject *(*)(struct __pyx_obj_5_cdec_HypergraphEdge *, Hypergraph *, unsigned int))__pyx_f_5_cdec_14HypergraphEdge_init; + if (PyType_Ready(&__pyx_type_5_cdec_HypergraphEdge) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_5_cdec_HypergraphEdge.tp_dict, __pyx_vtabptr_5_cdec_HypergraphEdge) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "HypergraphEdge", (PyObject *)&__pyx_type_5_cdec_HypergraphEdge) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_HypergraphEdge = &__pyx_type_5_cdec_HypergraphEdge; + __pyx_vtabptr_5_cdec_HypergraphNode = &__pyx_vtable_5_cdec_HypergraphNode; + __pyx_vtable_5_cdec_HypergraphNode.init = (PyObject *(*)(struct __pyx_obj_5_cdec_HypergraphNode *, Hypergraph *, unsigned int))__pyx_f_5_cdec_14HypergraphNode_init; + if (PyType_Ready(&__pyx_type_5_cdec_HypergraphNode) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_5_cdec_HypergraphNode.tp_dict, __pyx_vtabptr_5_cdec_HypergraphNode) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "HypergraphNode", (PyObject *)&__pyx_type_5_cdec_HypergraphNode) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_HypergraphNode = &__pyx_type_5_cdec_HypergraphNode; if (PyType_Ready(&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Lattice", (PyObject *)&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Lattice = &__pyx_type_5_cdec_Lattice; - if (PyType_Ready(&__pyx_type_5_cdec_Candidate) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Candidate", (PyObject *)&__pyx_type_5_cdec_Candidate) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_Candidate) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Candidate", (PyObject *)&__pyx_type_5_cdec_Candidate) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Candidate = &__pyx_type_5_cdec_Candidate; - if (PyType_Ready(&__pyx_type_5_cdec_SufficientStats) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "SufficientStats", (PyObject *)&__pyx_type_5_cdec_SufficientStats) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_SufficientStats) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "SufficientStats", (PyObject *)&__pyx_type_5_cdec_SufficientStats) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_SufficientStats = &__pyx_type_5_cdec_SufficientStats; - if (PyType_Ready(&__pyx_type_5_cdec_CandidateSet) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "CandidateSet", (PyObject *)&__pyx_type_5_cdec_CandidateSet) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_CandidateSet) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "CandidateSet", (PyObject *)&__pyx_type_5_cdec_CandidateSet) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_CandidateSet = &__pyx_type_5_cdec_CandidateSet; - if (PyType_Ready(&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "SegmentEvaluator", (PyObject *)&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "SegmentEvaluator", (PyObject *)&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_SegmentEvaluator = &__pyx_type_5_cdec_SegmentEvaluator; - if (PyType_Ready(&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Scorer", (PyObject *)&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Scorer", (PyObject *)&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Scorer = &__pyx_type_5_cdec_Scorer; - if (PyType_Ready(&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __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 = 15; __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___pyx_scope_struct____iter__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct____iter__ = &__pyx_type_5_cdec___pyx_scope_struct____iter__; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_1___iter__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_1___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_1___iter__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_2_kbest) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_2_kbest) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_2_kbest = &__pyx_type_5_cdec___pyx_scope_struct_2_kbest; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_tree = &__pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_4_kbest_features) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_3_kbest_trees) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_trees = &__pyx_type_5_cdec___pyx_scope_struct_3_kbest_trees; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_4_kbest_features) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features = &__pyx_type_5_cdec___pyx_scope_struct_4_kbest_features; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_5_sample) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_5_sample) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_5_sample = &__pyx_type_5_cdec___pyx_scope_struct_5_sample; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_6___iter__) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_6___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_6___iter__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_7_todot) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_7_todot = &__pyx_type_5_cdec___pyx_scope_struct_7_todot; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_8_lines) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_8_lines = &__pyx_type_5_cdec___pyx_scope_struct_8_lines; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_9___iter__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_9___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_9___iter__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_10___iter__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_10___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_10___iter__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_6___get__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_6___get__ = &__pyx_type_5_cdec___pyx_scope_struct_6___get__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_7___get__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_7___get__ = &__pyx_type_5_cdec___pyx_scope_struct_7___get__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_8__phrase) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_8__phrase = &__pyx_type_5_cdec___pyx_scope_struct_8__phrase; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_9_genexpr) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_9_genexpr = &__pyx_type_5_cdec___pyx_scope_struct_9_genexpr; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_10___str__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_10___str__ = &__pyx_type_5_cdec___pyx_scope_struct_10___str__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_11_genexpr) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_11_genexpr = &__pyx_type_5_cdec___pyx_scope_struct_11_genexpr; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_12___get__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_12___get__ = &__pyx_type_5_cdec___pyx_scope_struct_12___get__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_13___get__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_13___get__ = &__pyx_type_5_cdec___pyx_scope_struct_13___get__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_14___get__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_14___get__ = &__pyx_type_5_cdec___pyx_scope_struct_14___get__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_15___iter__) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_15___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_15___iter__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_16_todot) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_16_todot = &__pyx_type_5_cdec___pyx_scope_struct_16_todot; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_17_lines) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_17_lines = &__pyx_type_5_cdec___pyx_scope_struct_17_lines; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_18___iter__) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_18___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_18___iter__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_19___iter__) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_19___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_19___iter__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_20__make_config) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_20__make_config = &__pyx_type_5_cdec___pyx_scope_struct_20__make_config; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_21___cinit__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_21___cinit__ = &__pyx_type_5_cdec___pyx_scope_struct_21___cinit__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_22_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_22_genexpr = &__pyx_type_5_cdec___pyx_scope_struct_22_genexpr; /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ /*--- Execution code ---*/ - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":153 + /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":1 + * def _phrase(phrase): # <<<<<<<<<<<<<< + * return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) + * + */ + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5_cdec_1_phrase, NULL, __pyx_n_s___cdec); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s___phrase, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":143 * return self.name.c_str() * * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< * TER = Scorer('TER') */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_41), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_52), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":154 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":144 * * BLEU = Scorer('IBM_BLEU') * TER = Scorer('TER') # <<<<<<<<<<<<<< */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_42), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_53), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "_cdec.pyx":11 + /* "_cdec.pyx":21 * include "mteval.pxi" * * SetSilent(True) # <<<<<<<<<<<<<< + * decoder.register_feature_functions() * - * class ParseFailed(Exception): pass */ SetSilent(1); - /* "_cdec.pyx":13 + /* "_cdec.pyx":22 + * * SetSilent(True) + * decoder.register_feature_functions() # <<<<<<<<<<<<<< * - * class ParseFailed(Exception): pass # <<<<<<<<<<<<<< + * class InvalidConfig(Exception): pass + */ + register_feature_functions(); + + /* "_cdec.pyx":24 + * decoder.register_feature_functions() + * + * class InvalidConfig(Exception): pass # <<<<<<<<<<<<<< + * class ParseFailed(Exception): pass * - * cdef class Decoder: */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __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 = 13; __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 = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__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 = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_CreateClass(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1), __pyx_n_s__InvalidConfig, __pyx_n_s___cdec); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __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 = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__InvalidConfig, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __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":25 + * + * class InvalidConfig(Exception): pass + * class ParseFailed(Exception): pass # <<<<<<<<<<<<<< + * + * def _make_config(config): + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __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(__pyx_t_3); + __Pyx_INCREF(__pyx_builtin_Exception); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_builtin_Exception); + __Pyx_GIVEREF(__pyx_builtin_Exception); + __pyx_t_2 = __Pyx_CreateClass(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_1), __pyx_n_s__ParseFailed, __pyx_n_s___cdec); 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; + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__ParseFailed, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + + /* "_cdec.pyx":27 + * class ParseFailed(Exception): pass + * + * def _make_config(config): # <<<<<<<<<<<<<< + * for key, value in config.items(): + * if isinstance(value, dict): + */ + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5_cdec_3_make_config, NULL, __pyx_n_s___cdec); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s___make_config, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /* "_cdec.pyx":1 * from libcpp.string cimport string # <<<<<<<<<<<<<< * from libcpp.vector cimport vector @@ -15056,6 +22302,36 @@ static void __Pyx_RaiseArgtupleInvalid( (num_expected == 1) ? "" : "s", num_found); } +static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) { + PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname); +} + +static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject* iterator, PyObject* defval) { + PyObject* next; + if (unlikely(!PyIter_Check(iterator))) { + PyErr_Format(PyExc_TypeError, + "%.200s object is not an iterator", iterator->ob_type->tp_name); + return NULL; + } + next = (*(Py_TYPE(iterator)->tp_iternext))(iterator); + if (likely(next)) { + return next; + } else if (defval) { + if (PyErr_Occurred()) { + if(!PyErr_ExceptionMatches(PyExc_StopIteration)) + return NULL; + PyErr_Clear(); + } + Py_INCREF(defval); + return defval; + } else if (PyErr_Occurred()) { + return NULL; + } else { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } +} + static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { PyErr_Format(PyExc_ValueError, "need more than %"PY_FORMAT_SIZE_T"d value%s to unpack", @@ -15085,10 +22361,6 @@ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { -static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) { - PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname); -} - static double __Pyx__PyObject_AsDouble(PyObject* obj) { PyObject* float_value; if (Py_TYPE(obj)->tp_as_number && Py_TYPE(obj)->tp_as_number->nb_float) { @@ -15625,6 +22897,78 @@ static void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) Py_INCREF(tuple); } +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { + if (s1 == s2) { + return (equals == Py_EQ); + } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { + if (PyBytes_GET_SIZE(s1) != PyBytes_GET_SIZE(s2)) { + return (equals == Py_NE); + } else if (PyBytes_GET_SIZE(s1) == 1) { + if (equals == Py_EQ) + return (PyBytes_AS_STRING(s1)[0] == PyBytes_AS_STRING(s2)[0]); + else + return (PyBytes_AS_STRING(s1)[0] != PyBytes_AS_STRING(s2)[0]); + } else { + int result = memcmp(PyBytes_AS_STRING(s1), PyBytes_AS_STRING(s2), (size_t)PyBytes_GET_SIZE(s1)); + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { + return (equals == Py_NE); + } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { + return (equals == Py_NE); + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +} + +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { + if (s1 == s2) { + return (equals == Py_EQ); + } else if (PyUnicode_CheckExact(s1) & PyUnicode_CheckExact(s2)) { + #if CYTHON_PEP393_ENABLED + if ((PyUnicode_READY(s1) < 0) || (PyUnicode_READY(s2) < 0)) + return -1; + if (PyUnicode_GET_LENGTH(s1) != PyUnicode_GET_LENGTH(s2)) { + return (equals == Py_NE); + } else if (PyUnicode_GET_LENGTH(s1) == 1) { + Py_UCS4 ch1 = PyUnicode_READ_CHAR(s1, 0); + Py_UCS4 ch2 = PyUnicode_READ_CHAR(s2, 0); + return (equals == Py_EQ) ? (ch1 == ch2) : (ch1 != ch2); + #else + if (PyUnicode_GET_SIZE(s1) != PyUnicode_GET_SIZE(s2)) { + return (equals == Py_NE); + } else if (PyUnicode_GET_SIZE(s1) == 1) { + Py_UNICODE ch1 = PyUnicode_AS_UNICODE(s1)[0]; + Py_UNICODE ch2 = PyUnicode_AS_UNICODE(s2)[0]; + return (equals == Py_EQ) ? (ch1 == ch2) : (ch1 != ch2); + #endif + } else { + int result = PyUnicode_Compare(s1, s2); + if ((result == -1) && unlikely(PyErr_Occurred())) + return -1; + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & PyUnicode_CheckExact(s2)) { + return (equals == Py_NE); + } else if ((s2 == Py_None) & PyUnicode_CheckExact(s1)) { + return (equals == Py_NE); + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +} + static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { const unsigned char neg_one = (unsigned char)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; @@ -16025,6 +23369,25 @@ static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* } } +static void __Pyx_WriteUnraisable(const char *name, int clineno, + int lineno, const char *filename) { + PyObject *old_exc, *old_val, *old_tb; + PyObject *ctx; + __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); + #if PY_MAJOR_VERSION < 3 + ctx = PyString_FromString(name); + #else + ctx = PyUnicode_FromString(name); + #endif + __Pyx_ErrRestore(old_exc, old_val, old_tb); + if (!ctx) { + PyErr_WriteUnraisable(Py_None); + } else { + PyErr_WriteUnraisable(ctx); + Py_DECREF(ctx); + } +} + static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) { PyObject *tmp_type, *tmp_value, *tmp_tb; PyThreadState *tstate = PyThreadState_GET(); @@ -16312,25 +23675,6 @@ static int __pyx_Generator_init(void) return PyType_Ready(&__pyx_GeneratorType); } -static void __Pyx_WriteUnraisable(const char *name, int clineno, - int lineno, const char *filename) { - PyObject *old_exc, *old_val, *old_tb; - PyObject *ctx; - __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); - #if PY_MAJOR_VERSION < 3 - ctx = PyString_FromString(name); - #else - ctx = PyUnicode_FromString(name); - #endif - __Pyx_ErrRestore(old_exc, old_val, old_tb); - if (!ctx) { - PyErr_WriteUnraisable(Py_None); - } else { - PyErr_WriteUnraisable(ctx); - Py_DECREF(ctx); - } -} - static int __Pyx_check_binary_version(void) { char ctversion[4], rtversion[4]; PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); @@ -16350,6 +23694,23 @@ static int __Pyx_check_binary_version(void) { return 0; } +static int __Pyx_SetVtable(PyObject *dict, void *vtable) { +#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) + PyObject *ob = PyCapsule_New(vtable, 0, 0); +#else + PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); +#endif + if (!ob) + goto bad; + if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0) + goto bad; + Py_DECREF(ob); + return 0; +bad: + Py_XDECREF(ob); + return -1; +} + static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { int start = 0, mid = 0, end = count - 1; if (end >= 0 && code_line > entries[end].code_line) { diff --git a/python/src/_cdec.pyx b/python/src/_cdec.pyx index cccfec0b..879e8b72 100644 --- a/python/src/_cdec.pyx +++ b/python/src/_cdec.pyx @@ -3,22 +3,55 @@ from libcpp.vector cimport vector from utils cimport * cimport decoder +cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): + cdef bytes ret + if isinstance(sentence, unicode): + ret = sentence.encode('utf8') + elif isinstance(sentence, str): + ret = sentence + else: + raise TypeError(error_msg % type(sentence)) + return ret + include "vectors.pxi" include "hypergraph.pxi" include "lattice.pxi" include "mteval.pxi" SetSilent(True) +decoder.register_feature_functions() +class InvalidConfig(Exception): pass class ParseFailed(Exception): pass +def _make_config(config): + for key, value in config.items(): + if isinstance(value, dict): + for name, info in value.items(): + yield key, '%s %s' % (name, info) + elif isinstance(value, list): + for name in value: + yield key, name + else: + yield key, bytes(value) + cdef class Decoder: cdef decoder.Decoder* dec cdef DenseVector weights - def __cinit__(self, char* config): - decoder.register_feature_functions() - cdef istringstream* config_stream = new istringstream(config) + def __cinit__(self, config_str=None, **config): + """ Configuration can be given as a string: + Decoder('formalism = scfg') + or using keyword arguments: + Decoder(formalism='scfg') + """ + if config_str is None: + formalism = config.get('formalism', None) + if formalism not in ('scfg', 'fst', 'lextrans', 'pb', + 'csplit', 'tagger', 'lexalign'): + raise InvalidConfig('formalism "%s" unknown' % formalism) + config_str = '\n'.join('%s = %s' % kv for kv in _make_config(config)) + cdef istringstream* config_stream = new istringstream(config_str) self.dec = new decoder.Decoder(config_stream) del config_stream self.weights = DenseVector() @@ -43,9 +76,15 @@ cdef class Decoder: else: raise TypeError('cannot initialize weights with %s' % type(weights)) - def read_weights(self, cfg): - with open(cfg) as fp: + property formalism: + def __get__(self): + cdef variables_map* conf = &self.dec.GetConf() + return conf[0]['formalism'].as_str().c_str() + + def read_weights(self, weights): + with open(weights) as fp: for line in fp: + if line.strip().startswith('#'): continue fname, value = line.split() self.weights[fname.strip()] = float(value) diff --git a/python/src/decoder.pxd b/python/src/decoder.pxd index e2678151..660bcb39 100644 --- a/python/src/decoder.pxd +++ b/python/src/decoder.pxd @@ -1,7 +1,7 @@ from libcpp.string cimport string from libcpp.vector cimport vector from hypergraph cimport Hypergraph -from utils cimport istream, weight_t +from utils cimport istream, weight_t, variables_map cdef extern from "decoder/ff_register.h": void register_feature_functions() @@ -23,7 +23,7 @@ cdef extern from "decoder/decoder.h": vector[weight_t]& CurrentWeightVector() # void SetId(int id) - # const boost::program_options::variables_map& GetConf() const { return conf } + variables_map& GetConf() # add grammar rules (currently only supported by SCFG decoders) # that will be used on subsequent calls to Decode. rules should be in standard diff --git a/python/src/hypergraph.pxd b/python/src/hypergraph.pxd index 656b1d47..14c60dd0 100644 --- a/python/src/hypergraph.pxd +++ b/python/src/hypergraph.pxd @@ -3,32 +3,43 @@ from libcpp.vector cimport vector from utils cimport * from lattice cimport Lattice +cdef extern from "decoder/trule.h": + cdef cppclass TRule: + vector[WordID] f_ + vector[WordID] e_ + FastSparseVector[weight_t] scores_ + WordID lhs_ + int arity_ + bint IsUnary() + bint IsGoal() + cdef extern from "decoder/hg.h": cdef cppclass EdgeMask "std::vector": EdgeMask(int size) bint& operator[](int) + cdef cppclass HypergraphEdge "const Hypergraph::Edge": + int id_ + int head_node_ # position in hg.nodes_ + SmallVector[unsigned] tail_nodes_ # positions in hg.nodes_ + shared_ptr[TRule] rule_ + FastSparseVector[weight_t] feature_values_ + LogVal[double] edge_prob_ # weights.dot(feature_values_) + # typically source span: + short int i_ + short int j_ + + cdef cppclass HypergraphNode "const Hypergraph::Node": + int id_ + WordID cat_ # non-terminal category if <0, 0 if not set + vector[int] in_edges_ # positions in hg.edge_prob_ + vector[int] out_edges_ # positions in hg.edge_prob_ + cdef cppclass Hypergraph: - cppclass Edge: - int id_ - int head_node_ # position in hg.nodes_ - SmallVector[unsigned] tail_nodes_ # positions in hg.nodes_ - #TRulePtr rule_ - FastSparseVector[weight_t] feature_values_ - LogVal[double] edge_prob_ - short int i_ - short int j_ - short int prev_i_ - short int prev_j_ - cppclass Node: - int id_ - WordID cat_ - WordID NT() - vector[Edge] in_edges_ - vector[Edge] out_edges_ Hypergraph(Hypergraph) - vector[Node] nodes_ - vector[Edge] edges_ + vector[HypergraphNode] nodes_ + vector[HypergraphEdge] edges_ + int GoalNode() void Reweight(vector[weight_t]& weights) void Reweight(FastSparseVector& weights) bint PruneInsideOutside(double beam_alpha, @@ -47,6 +58,7 @@ cdef extern from "decoder/viterbi.h": FastSparseVector[weight_t] ViterbiFeatures(Hypergraph& hg, FastSparseVector[weight_t]* weights, bint fatal_dotprod_disagreement) + string JoshuaVisualizationString(Hypergraph& hg) cdef extern from "decoder/hg_io.h" namespace "HypergraphIO": bint ReadFromJSON(istream* inp, Hypergraph* out) @@ -62,7 +74,7 @@ cdef extern from "decoder/hg_intersect.h" namespace "HG": cdef extern from "decoder/hg_sampler.h" namespace "HypergraphSampler": cdef cppclass Hypothesis: vector[WordID] words - FastSparseVector[double] fmap + FastSparseVector[weight_t] fmap LogVal[double] model_score void sample_hypotheses(Hypergraph& hg, unsigned n, diff --git a/python/src/hypergraph.pxi b/python/src/hypergraph.pxi index 9d09722e..2e2c04a2 100644 --- a/python/src/hypergraph.pxi +++ b/python/src/hypergraph.pxi @@ -1,5 +1,5 @@ cimport hypergraph -cimport kbest as kb +cimport kbest cdef class Hypergraph: cdef hypergraph.Hypergraph* hg @@ -13,53 +13,54 @@ cdef class Hypergraph: def viterbi(self): cdef vector[WordID] trans hypergraph.ViterbiESentence(self.hg[0], &trans) - cdef str sentence = GetString(trans).c_str() - return sentence.decode('utf8') + return unicode(GetString(trans).c_str(), 'utf8') - def viterbi_tree(self): - cdef str tree = hypergraph.ViterbiETree(self.hg[0]).c_str() - return tree.decode('utf8') - - def viterbi_source_tree(self): - cdef str tree = hypergraph.ViterbiFTree(self.hg[0]).c_str() - return tree.decode('utf8') + def viterbi_trees(self): + f_tree = unicode(hypergraph.ViterbiFTree(self.hg[0]).c_str(), 'utf8') + e_tree = unicode(hypergraph.ViterbiETree(self.hg[0]).c_str(), 'utf8') + return (f_tree, e_tree) def viterbi_features(self): cdef SparseVector fmap = SparseVector() fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) return fmap + def viterbi_joshua(self): + return unicode(hypergraph.JoshuaVisualizationString(self.hg[0]).c_str(), 'utf8') + def kbest(self, size): - 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 bytes sentence + cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal]* derivations = new kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal](self.hg[0], size) + cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal].Derivation* derivation cdef unsigned k try: 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') + yield unicode(GetString(derivation._yield).c_str(), 'utf8') finally: del derivations - def kbest_tree(self, size): - 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 tree + def kbest_trees(self, size): + cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal]* f_derivations = new kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal](self.hg[0], size) + cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal].Derivation* f_derivation + cdef kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal]* e_derivations = new kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal](self.hg[0], size) + cdef kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal].Derivation* e_derivation cdef unsigned k try: 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') + f_derivation = f_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + e_derivation = e_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + if not f_derivation or not e_derivation: break + f_tree = unicode(GetString(f_derivation._yield).c_str(), 'utf8') + e_tree = unicode(GetString(e_derivation._yield).c_str(), 'utf8') + yield (f_tree, e_tree) finally: - del derivations + del f_derivations + del e_derivations def kbest_features(self, size): - cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) - cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal].Derivation* derivation + cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal]* derivations = new kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal](self.hg[0], size) + cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal].Derivation* derivation cdef SparseVector fmap cdef unsigned k try: @@ -77,17 +78,13 @@ cdef class Hypergraph: if self.rng == NULL: self.rng = new MT19937() hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) - cdef str sentence cdef unsigned k try: for k in range(hypos.size()): - sentence = GetString(hypos[0][k].words).c_str() - yield sentence.decode('utf8') + yield unicode(GetString(hypos[0][k].words).c_str(), 'utf8') finally: del hypos - # TODO richer k-best/sample output (feature vectors, trees?) - def intersect(self, Lattice lat): return hypergraph.Intersect(lat.lattice[0], self.hg) @@ -113,3 +110,105 @@ cdef class Hypergraph: raise TypeError('cannot reweight hypergraph with %s' % type(weights)) # TODO get feature expectations, get partition function ("inside" score) + + property edges: + def __get__(self): + cdef unsigned i + for i in range(self.hg.edges_.size()): + yield HypergraphEdge().init(self.hg, i) + + property nodes: + def __get__(self): + cdef unsigned i + for i in range(self.hg.nodes_.size()): + yield HypergraphNode().init(self.hg, i) + + property goal: + def __get__(self): + return HypergraphNode().init(self.hg, self.hg.GoalNode()) + + +include "trule.pxi" + +cdef class HypergraphEdge: + cdef hypergraph.Hypergraph* hg + cdef hypergraph.HypergraphEdge* edge + cdef public TRule trule + + cdef init(self, hypergraph.Hypergraph* hg, unsigned i): + self.hg = hg + self.edge = &hg.edges_[i] + self.trule = TRule() + self.trule.rule = self.edge.rule_.get() + return self + + def __len__(self): + return self.edge.tail_nodes_.size() + + property head_node: + def __get__(self): + return HypergraphNode().init(self.hg, self.edge.head_node_) + + property tail_nodes: + def __get__(self): + cdef unsigned i + for i in range(self.edge.tail_nodes_.size()): + yield HypergraphNode().init(self.hg, self.edge.tail_nodes_[i]) + + property span: + def __get__(self): + return (self.edge.i_, self.edge.j_) + + property feature_values: + def __get__(self): + cdef SparseVector vector = SparseVector() + vector.vector = new FastSparseVector[double](self.edge.feature_values_) + return vector + + property prob: + def __get__(self): + return self.edge.edge_prob_.as_float() + + def __richcmp__(HypergraphEdge x, HypergraphEdge y, int op): + if op == 2: # == + return x.edge == y.edge + elif op == 3: # != + return not (x == y) + raise NotImplemented('comparison not implemented for HypergraphEdge') + +cdef class HypergraphNode: + cdef hypergraph.Hypergraph* hg + cdef hypergraph.HypergraphNode* node + + cdef init(self, hypergraph.Hypergraph* hg, unsigned i): + self.hg = hg + self.node = &hg.nodes_[i] + return self + + property in_edges: + def __get__(self): + cdef unsigned i + for i in range(self.node.in_edges_.size()): + yield HypergraphEdge().init(self.hg, self.node.in_edges_[i]) + + property out_edges: + def __get__(self): + cdef unsigned i + for i in range(self.node.out_edges_.size()): + yield HypergraphEdge().init(self.hg, self.node.out_edges_[i]) + + property span: + def __get__(self): + return next(self.in_edges).span + + property cat: + def __get__(self): + if self.node.cat_: + return TDConvert(-self.node.cat_) + + def __richcmp__(HypergraphNode x, HypergraphNode y, int op): + if op == 2: # == + return x.node == y.node + elif op == 3: # != + return not (x == y) + raise NotImplemented('comparison not implemented for HypergraphNode') diff --git a/python/src/lattice.pxi b/python/src/lattice.pxi index f8341e29..c6b29e8b 100644 --- a/python/src/lattice.pxi +++ b/python/src/lattice.pxi @@ -22,12 +22,11 @@ cdef class Lattice: arcs = [] cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] cdef lattice.LatticeArc* arc - cdef str label cdef unsigned i for i in range(arc_vector.size()): arc = &arc_vector[i] - label = TDConvert(arc.label) - arcs.append((label.decode('utf8'), arc.cost, arc.dist2next)) + label = unicode(TDConvert(arc.label), 'utf8') + arcs.append((label, arc.cost, arc.dist2next)) return tuple(arcs) def __setitem__(self, int index, tuple arcs): diff --git a/python/src/mteval.pxi b/python/src/mteval.pxi index d90eb9a6..4ba73168 100644 --- a/python/src/mteval.pxi +++ b/python/src/mteval.pxi @@ -1,15 +1,5 @@ cimport mteval -cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): - cdef bytes ret - if isinstance(sentence, unicode): - ret = sentence.encode('utf8') - elif isinstance(sentence, str): - ret = sentence - else: - raise TypeError(error_msg % type(sentence)) - return ret - cdef SufficientStats as_stats(x, y): if isinstance(x, SufficientStats): return x diff --git a/python/src/trule.pxi b/python/src/trule.pxi new file mode 100644 index 00000000..6168014d --- /dev/null +++ b/python/src/trule.pxi @@ -0,0 +1,55 @@ +def _phrase(phrase): + return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) + +cdef class TRule: + cdef hypergraph.TRule* rule + + property arity: + def __get__(self): + return self.rule.arity_ + + property f: + def __get__(self): + cdef vector[WordID]* f = &self.rule.f_ + cdef WordID w + cdef words = [] + cdef unsigned i + cdef int idx = 0 + for i in range(f.size()): + w = f[0][i] + if w < 0: + idx += 1 + words.append((TDConvert(-w), idx)) + else: + words.append(unicode(TDConvert(w), encoding='utf8')) + return words + + property e: + def __get__(self): + cdef vector[WordID]* e = &self.rule.e_ + cdef WordID w + cdef words = [] + cdef unsigned i + cdef int idx = 0 + for i in range(e.size()): + w = e[0][i] + if w < 1: + idx += 1 + words.append((TDConvert(1-w), idx)) + else: + words.append(unicode(TDConvert(w), encoding='utf8')) + return words + + property scores: + def __get__(self): + cdef SparseVector scores = SparseVector() + scores.vector = new FastSparseVector[double](self.rule.scores_) + return scores + + property lhs: + def __get__(self): + return TDConvert(-self.rule.lhs_) + + def __str__(self): + scores = ' '.join('%s=%s' % feat for feat in self.scores) + return '[%s] ||| %s ||| %s ||| %s' % (self.lhs, _phrase(self.f), _phrase(self.e), scores) diff --git a/python/src/utils.pxd b/python/src/utils.pxd index 94fab5ef..15e77c49 100644 --- a/python/src/utils.pxd +++ b/python/src/utils.pxd @@ -9,7 +9,6 @@ cdef extern from "" namespace "std": pass cdef cppclass istringstream(istream): istringstream(char*) - ostream cout cdef extern from "utils/weights.h": ctypedef double weight_t @@ -25,7 +24,8 @@ cdef extern from "utils/wordid.h": cdef extern from "utils/small_vector.h": cdef cppclass SmallVector[T]: - pass + T& operator[](unsigned) + unsigned size() cdef extern from "utils/sparse_vector.h": cdef cppclass FastSparseVector[T]: @@ -84,3 +84,11 @@ cdef extern from "" namespace "boost": cdef cppclass shared_ptr[T]: shared_ptr(shared_ptr& r) T* get() + +cdef extern from "": + cdef cppclass variable_value "const boost::program_options::variable_value": + string as_str "as" () + + cdef cppclass variables_map "const boost::program_options::variables_map": + unsigned count(char* name) + variable_value& operator[](char* name) diff --git a/python/test.py b/python/test.py index 8069aa0a..54859e81 100644 --- a/python/test.py +++ b/python/test.py @@ -2,12 +2,11 @@ import cdec import gzip -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) +decoder = cdec.Decoder(formalism='scfg') # Read weights decoder.read_weights(weights) @@ -26,15 +25,17 @@ forest = decoder.translate(sentence, grammar=grammar) # Get viterbi translation print 'Output[0]:', forest.viterbi().encode('utf8') -print ' ETree[0]:', forest.viterbi_tree().encode('utf8') -print ' FTree[0]:', forest.viterbi_source_tree().encode('utf8') +f_tree, e_tree = forest.viterbi_trees() +print ' FTree[0]:', f_tree.encode('utf8') +print ' ETree[0]:', e_tree.encode('utf8') print 'LgProb[0]:', forest.viterbi_features().dot(decoder.weights) # Get k-best translations -kbest = zip(forest.kbest(5), forest.kbest_tree(5), forest.kbest_features(5)) -for i, (sentence, tree, features) in enumerate(kbest, 1): +kbest = zip(forest.kbest(5), forest.kbest_trees(5), forest.kbest_features(5)) +for i, (sentence, (f_tree, e_tree), features) in enumerate(kbest, 1): print 'Output[%d]:' % i, sentence.encode('utf8') - print ' Tree[%d]:' % i, tree.encode('utf8') + print ' FTree[%d]:' % i, f_tree.encode('utf8') + print ' ETree[%d]:' % i, e_tree.encode('utf8') print ' FVect[%d]:' % i, dict(features) # Sample translations from the forest @@ -54,8 +55,9 @@ assert (lattice == tuple(lat)) assert forest.intersect(lat) # Get best synchronous parse -print forest.viterbi_tree() -print forest.viterbi_source_tree() +f_tree, e_tree = forest.viterbi_trees() +print 'FTree:', f_tree.encode('utf8') +print 'ETree:', e_tree.encode('utf8') # Compare 1best and reference feature vectors fref = forest.viterbi_features() -- cgit v1.2.3 From 09d085e16f31b36b1177b313ee54414eb29d9082 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Fri, 20 Jul 2012 00:46:10 -0400 Subject: enable programmatic setting of grammar objects, cleanup of grammar handling --- decoder/decoder.cc | 10 +++----- decoder/decoder.h | 6 +++-- decoder/scfg_translator.cc | 63 ++++++++++++++++++---------------------------- decoder/translator.h | 4 +-- dtrain/dtrain.cc | 4 +-- python/src/_cdec.pyx | 2 +- 6 files changed, 38 insertions(+), 51 deletions(-) (limited to 'python/src') diff --git a/decoder/decoder.cc b/decoder/decoder.cc index 333f0fb6..ad4e9e07 100644 --- a/decoder/decoder.cc +++ b/decoder/decoder.cc @@ -743,16 +743,14 @@ bool Decoder::Decode(const string& input, DecoderObserver* o) { } vector& Decoder::CurrentWeightVector() { return pimpl_->CurrentWeightVector(); } const vector& Decoder::CurrentWeightVector() const { return pimpl_->CurrentWeightVector(); } -void Decoder::SetSupplementalGrammar(const std::string& grammar_string) { - assert(pimpl_->translator->GetDecoderType() == "SCFG"); - static_cast(*pimpl_->translator).SetSupplementalGrammar(grammar_string); +void Decoder::AddSupplementalGrammar(GrammarPtr gp) { + static_cast(*pimpl_->translator).AddSupplementalGrammar(gp); } -void Decoder::SetSentenceGrammarFromString(const std::string& grammar_str) { +void Decoder::AddSupplementalGrammarFromString(const std::string& grammar_string) { assert(pimpl_->translator->GetDecoderType() == "SCFG"); - static_cast(*pimpl_->translator).SetSentenceGrammarFromString(grammar_str); + static_cast(*pimpl_->translator).AddSupplementalGrammarFromString(grammar_string); } - bool DecoderImpl::Decode(const string& input, DecoderObserver* o) { string buf = input; NgramCache::Clear(); // clear ngram cache for remote LM (if used) diff --git a/decoder/decoder.h b/decoder/decoder.h index 6b2f7b16..bef2ff5e 100644 --- a/decoder/decoder.h +++ b/decoder/decoder.h @@ -37,6 +37,8 @@ struct DecoderObserver { virtual void NotifyDecodingComplete(const SentenceMetadata& smeta); }; +struct Grammar; // TODO once the decoder interface is cleaned up, + // this should be somewhere else struct Decoder { Decoder(int argc, char** argv); Decoder(std::istream* config_file); @@ -54,8 +56,8 @@ struct Decoder { // add grammar rules (currently only supported by SCFG decoders) // that will be used on subsequent calls to Decode. rules should be in standard // text format. This function does NOT read from a file. - void SetSupplementalGrammar(const std::string& grammar); - void SetSentenceGrammarFromString(const std::string& grammar_str); + void AddSupplementalGrammar(boost::shared_ptr gp); + void AddSupplementalGrammarFromString(const std::string& grammar_string); private: boost::program_options::variables_map conf; boost::shared_ptr pimpl_; diff --git a/decoder/scfg_translator.cc b/decoder/scfg_translator.cc index 185f979a..aaa6c40b 100644 --- a/decoder/scfg_translator.cc +++ b/decoder/scfg_translator.cc @@ -20,7 +20,6 @@ #define reverse_foreach BOOST_REVERSE_FOREACH using namespace std; -static bool usingSentenceGrammar = false; static bool printGrammarsUsed = false; struct SCFGTranslatorImpl { @@ -91,31 +90,31 @@ struct SCFGTranslatorImpl { bool show_tree_structure_; unsigned int ctf_iterations_; vector grammars; - GrammarPtr sup_grammar_; + set sup_grammars_; - struct Equals { Equals(const GrammarPtr& v) : v_(v) {} - bool operator()(const GrammarPtr& x) const { return x == v_; } const GrammarPtr& v_; }; + struct ContainedIn { + ContainedIn(const set& gs) : gs_(gs) {} + bool operator()(const GrammarPtr& x) const { return gs_.find(x) != gs_.end(); } + const set& gs_; + }; - void SetSupplementalGrammar(const std::string& grammar_string) { - grammars.erase(remove_if(grammars.begin(), grammars.end(), Equals(sup_grammar_)), grammars.end()); + void AddSupplementalGrammarFromString(const std::string& grammar_string) { + grammars.erase(remove_if(grammars.begin(), grammars.end(), ContainedIn(sup_grammars_)), grammars.end()); istringstream in(grammar_string); - sup_grammar_.reset(new TextGrammar(&in)); - grammars.push_back(sup_grammar_); + TextGrammar* sent_grammar = new TextGrammar(&in); + sent_grammar->SetMaxSpan(max_span_limit); + sent_grammar->SetGrammarName("SupFromString"); + AddSupplementalGrammar(GrammarPtr(sent_grammar)); } - struct NameEquals { NameEquals(const string name) : name_(name) {} - bool operator()(const GrammarPtr& x) const { return x->GetGrammarName() == name_; } const string name_; }; + void AddSupplementalGrammar(GrammarPtr gp) { + sup_grammars_.insert(gp); + grammars.push_back(gp); + } - void SetSentenceGrammarFromString(const std::string& grammar_str) { - assert(grammar_str != ""); - if (!SILENT) cerr << "Setting sentence grammar" << endl; - usingSentenceGrammar = true; - istringstream in(grammar_str); - TextGrammar* sent_grammar = new TextGrammar(&in); - sent_grammar->SetMaxSpan(max_span_limit); - sent_grammar->SetGrammarName("__psg"); - grammars.erase(remove_if(grammars.begin(), grammars.end(), NameEquals("__psg")), grammars.end()); - grammars.push_back(GrammarPtr(sent_grammar)); + void RemoveSupplementalGrammars() { + grammars.erase(remove_if(grammars.begin(), grammars.end(), ContainedIn(sup_grammars_)), grammars.end()); + sup_grammars_.clear(); } bool Translate(const string& input, @@ -301,34 +300,22 @@ Check for grammar pointer in the sentence markup, for use with sentence specific void SCFGTranslator::ProcessMarkupHintsImpl(const map& kv) { map::const_iterator it = kv.find("grammar"); - - if (it == kv.end()) { - usingSentenceGrammar= false; - return; - } - //Create sentence specific grammar from specified file name and load grammar into list of grammars - usingSentenceGrammar = true; TextGrammar* sentGrammar = new TextGrammar(it->second); sentGrammar->SetMaxSpan(pimpl_->max_span_limit); sentGrammar->SetGrammarName(it->second); - pimpl_->grammars.push_back(GrammarPtr(sentGrammar)); - + pimpl_->AddSupplementalGrammar(GrammarPtr(sentGrammar)); } -void SCFGTranslator::SetSupplementalGrammar(const std::string& grammar) { - pimpl_->SetSupplementalGrammar(grammar); +void SCFGTranslator::AddSupplementalGrammarFromString(const std::string& grammar) { + pimpl_->AddSupplementalGrammarFromString(grammar); } -void SCFGTranslator::SetSentenceGrammarFromString(const std::string& grammar_str) { - pimpl_->SetSentenceGrammarFromString(grammar_str); +void SCFGTranslator::AddSupplementalGrammar(GrammarPtr grammar) { + pimpl_->AddSupplementalGrammar(grammar); } void SCFGTranslator::SentenceCompleteImpl() { - - if(usingSentenceGrammar) // Drop the last sentence grammar from the list of grammars - { - pimpl_->grammars.pop_back(); - } + pimpl_->RemoveSupplementalGrammars(); } std::string SCFGTranslator::GetDecoderType() const { diff --git a/decoder/translator.h b/decoder/translator.h index cfd3b08a..fc2bb760 100644 --- a/decoder/translator.h +++ b/decoder/translator.h @@ -58,8 +58,8 @@ class SCFGTranslatorImpl; class SCFGTranslator : public Translator { public: SCFGTranslator(const boost::program_options::variables_map& conf); - void SetSupplementalGrammar(const std::string& grammar); - void SetSentenceGrammarFromString(const std::string& grammar); + void AddSupplementalGrammar(GrammarPtr gp); + void AddSupplementalGrammarFromString(const std::string& grammar); virtual std::string GetDecoderType() const; protected: bool TranslateImpl(const std::string& src, diff --git a/dtrain/dtrain.cc b/dtrain/dtrain.cc index b3e62914..b7a4bb6f 100644 --- a/dtrain/dtrain.cc +++ b/dtrain/dtrain.cc @@ -364,7 +364,7 @@ main(int argc, char** argv) boost::replace_all(in, "\t", "\n"); in += "\n"; grammar_buf_out << in << DTRAIN_GRAMMAR_DELIM << " " << in_split[0] << endl; - decoder.SetSentenceGrammarFromString(in); + decoder.AddSupplementalGrammarFromString(in); src_str_buf.push_back(in_split[1]); // decode observer->SetRef(ref_ids); @@ -378,7 +378,7 @@ main(int argc, char** argv) if (boost::starts_with(rule, DTRAIN_GRAMMAR_DELIM)) break; grammar_str += rule + "\n"; } - decoder.SetSentenceGrammarFromString(grammar_str); + decoder.AddSupplementalGrammarFromString(grammar_str); // decode observer->SetRef(ref_ids_buf[ii]); decoder.Decode(src_str_buf[ii], observer); diff --git a/python/src/_cdec.pyx b/python/src/_cdec.pyx index 879e8b72..164d6570 100644 --- a/python/src/_cdec.pyx +++ b/python/src/_cdec.pyx @@ -98,7 +98,7 @@ cdef class Decoder: else: raise TypeError('Cannot translate input type %s' % type(sentence)) if grammar: - self.dec.SetSentenceGrammarFromString(string( grammar)) + self.dec.AddSupplementalGrammarFromString(string( grammar)) cdef decoder.BasicObserver observer = decoder.BasicObserver() self.dec.Decode(string(inp), &observer) if observer.hypergraph == NULL: -- cgit v1.2.3 From 06f90d83a1feafad301d365a4a437e44f68be45b Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Sat, 21 Jul 2012 01:22:53 -0400 Subject: [python] Support for grammars - Translation rules can now be create programatically - Grammars = list of translation rules can be used for translation - Feature expectations on the hypergraph (inside_outside) --- python/cdec/__init__.py | 3 +- python/cdec/scfg/extractor.py | 20 +- python/setup.py | 34 +- python/src/_cdec.cpp | 23051 +++++++++++++++++++++++----------------- python/src/_cdec.pyx | 29 +- python/src/decoder.pxd | 7 +- python/src/grammar.pxd | 43 + python/src/grammar.pxi | 176 + python/src/hypergraph.pxd | 15 +- python/src/hypergraph.pxi | 28 +- python/src/lattice.pxi | 2 +- python/src/trule.pxi | 55 - python/src/utils.pxd | 2 + python/src/vectors.pxi | 1 + python/test.py | 3 + 15 files changed, 13863 insertions(+), 9606 deletions(-) create mode 100644 python/src/grammar.pxd create mode 100644 python/src/grammar.pxi delete mode 100644 python/src/trule.pxi (limited to 'python/src') diff --git a/python/cdec/__init__.py b/python/cdec/__init__.py index 0d7b8782..89c323ba 100644 --- a/python/cdec/__init__.py +++ b/python/cdec/__init__.py @@ -1,2 +1 @@ -from _cdec import Decoder, Lattice -import score +from _cdec import Decoder, Lattice, TRule, NT, NTRef diff --git a/python/cdec/scfg/extractor.py b/python/cdec/scfg/extractor.py index 0a45ddb8..1dfa2421 100644 --- a/python/cdec/scfg/extractor.py +++ b/python/cdec/scfg/extractor.py @@ -1,3 +1,5 @@ +import sys, os +import re import StringIO from itertools import chain @@ -32,7 +34,16 @@ class PhonyGrammar: pass class GrammarExtractor: - def __init__(self, config): + def __init__(self, cfg): + if isinstance(cfg, dict): + config = cfg + elif isinstance(cfg, str): + cfg_file = os.path.basename(cfg) + if not re.match(r'^\w+\.py$', cfg_file): + raise ValueError('Config must be a *.py file') + sys.path.append(os.path.dirname(cfg)) + config = __import__(cfg_file.replace('.py', '')).__dict__ + sys.path.pop() alignment = calignment.Alignment(config['a_file'], from_binary=True) self.factory = rulefactory.HieroCachingRuleFactory( # compiled alignment object (REQUIRED) @@ -99,13 +110,10 @@ class GrammarExtractor: return str(out) def main(config): - sys.path.append(os.path.dirname(config)) - module = __import__(os.path.basename(config).replace('.py', '')) - extractor = GrammarExtractor(module.__dict__) - print extractor.grammar(next(sys.stdin)) + extractor = GrammarExtractor(config) + sys.stdout.write(extractor.grammar(next(sys.stdin))) if __name__ == '__main__': - import sys, os if len(sys.argv) != 2 or not sys.argv[1].endswith('.py'): sys.stderr.write('Usage: %s config.py\n' % sys.argv[0]) sys.exit(1) diff --git a/python/setup.py b/python/setup.py index cc8b289d..701841a4 100644 --- a/python/setup.py +++ b/python/setup.py @@ -1,30 +1,50 @@ from distutils.core import setup from distutils.extension import Extension -from Cython.Distutils import build_ext +import sys import os +import glob INC = ['..', 'src/', '../decoder', '../utils', '../mteval'] LIB = ['../decoder', '../utils', '../mteval', '../training', '../klm/lm', '../klm/util'] +LINK_ARGS = [] +# Detect Boost BOOST_ROOT = os.getenv('BOOST_ROOT') if BOOST_ROOT: - INC.append(os.path.join(BOOST_ROOT, 'include/')) - LIB.append(os.path.join(BOOST_ROOT, 'lib/')) + BOOST_INC = os.path.join(BOOST_ROOT, 'include') + BOOST_LIB = os.path.join(BOOST_ROOT, 'lib') + if not os.path.exists(BOOST_INC): + sys.stderr.write('Error: could not find Boost headers in <%s>\n' % BOOST_INC) + sys.exit(1) + if not os.path.exists(BOOST_LIB): + sys.stderr.write('Error: could not find Boost libraries in <%s>\n' % BOOST_LIB) + sys.exit(1) + INC.append(BOOST_INC) + LIB.append(BOOST_LIB) + LINK_ARGS += ['-Wl,-rpath', '-Wl,'+BOOST_LIB] +else: + BOOST_LIB = '/usr/local/lib' + +# Detect -mt +if glob.glob(os.path.join(BOOST_LIB, 'libboost_program_options-mt.*')): + BOOST_PROGRAM_OPTIONS = 'boost_program_options-mt' +else: + BOOST_PROGRAM_OPTIONS = 'boost_program_options' ext_modules = [ Extension(name='_cdec', - sources=['src/_cdec.pyx'], + sources=['src/_cdec.cpp'], language='C++', include_dirs=INC, library_dirs=LIB, - libraries=['boost_program_options-mt', 'z', + libraries=[BOOST_PROGRAM_OPTIONS, 'z', 'cdec', 'utils', 'mteval', 'training', 'klm', 'klm_util'], - extra_compile_args=['-DHAVE_CONFIG_H']), + extra_compile_args=['-DHAVE_CONFIG_H'], + extra_link_args=LINK_ARGS), ] setup( name='cdec', - cmdclass={'build_ext': build_ext}, ext_modules=ext_modules, packages=['cdec', 'cdec.scfg'] ) diff --git a/python/src/_cdec.cpp b/python/src/_cdec.cpp index e86dcf7b..3c95ca50 100644 --- a/python/src/_cdec.cpp +++ b/python/src/_cdec.cpp @@ -1,4 +1,4 @@ -/* Generated by Cython 0.16 on Wed Jul 11 16:05:22 2012 */ +/* Generated by Cython 0.16 on Fri Jul 20 18:16:48 2012 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -286,14 +286,16 @@ #include "utils/sampler.h" #include #include -#include "decoder/lattice.h" #include "decoder/trule.h" +#include "decoder/grammar.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/csplit.h" +#include "decoder/inside_outside.h" #include "decoder/ff_register.h" #include "decoder/decoder.h" #include "observer.h" @@ -384,57 +386,64 @@ static const char *__pyx_filename; static const char *__pyx_f[] = { "_cdec.pyx", "vectors.pxi", + "grammar.pxi", "hypergraph.pxi", "lattice.pxi", - "trule.pxi", "mteval.pxi", }; /*--- Type declarations ---*/ struct __pyx_obj_5_cdec_Scorer; -struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config; -struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr; -struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr; -struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__; +struct __pyx_obj_5_cdec_NTRef; +struct __pyx_obj_5_cdec___pyx_scope_struct_23___cinit__; +struct __pyx_obj_5_cdec___pyx_scope_struct_24_genexpr; +struct __pyx_obj_5_cdec_Grammar; struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__; -struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__; -struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__; +struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot; +struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase; struct __pyx_obj_5_cdec_CandidateSet; struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__; +struct __pyx_obj_5_cdec_BaseTRule; struct __pyx_obj_5_cdec_TRule; -struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees; +struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr; struct __pyx_obj_5_cdec_SegmentEvaluator; -struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features; -struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample; +struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__; struct __pyx_obj_5_cdec_Candidate; -struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__; +struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr; +struct __pyx_obj_5_cdec_NT; struct __pyx_obj_5_cdec_HypergraphEdge; struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__; -struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__; +struct __pyx_obj_5_cdec___pyx_scope_struct_16___get__; +struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__; struct __pyx_obj_5_cdec_Decoder; struct __pyx_obj_5_cdec_HypergraphNode; struct __pyx_obj_5_cdec_SparseVector; -struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr; +struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__; struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__; -struct __pyx_obj_5_cdec___pyx_scope_struct____iter__; -struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest; +struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__; struct __pyx_obj_5_cdec_DenseVector; -struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines; +struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__; struct __pyx_obj_5_cdec_SufficientStats; -struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot; +struct __pyx_obj_5_cdec___pyx_scope_struct_8_kbest; +struct __pyx_obj_5_cdec___pyx_scope_struct_10_kbest_features; +struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__; +struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__; +struct __pyx_obj_5_cdec___pyx_scope_struct_9_kbest_trees; struct __pyx_obj_5_cdec_Hypergraph; struct __pyx_obj_5_cdec_Lattice; -struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase; -struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__; -struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__; +struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample; +struct __pyx_obj_5_cdec___pyx_scope_struct____iter__; +struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config; +struct __pyx_obj_5_cdec_TextGrammar; +struct __pyx_obj_5_cdec___pyx_scope_struct_19_lines; struct __pyx_opt_args_5_cdec_as_str; /* "_cdec.pyx":6 * cimport decoder * - * cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): # <<<<<<<<<<<<<< + * cdef char* as_str(data, error_msg='Cannot convert type %s to str'): # <<<<<<<<<<<<<< * cdef bytes ret - * if isinstance(sentence, unicode): + * if isinstance(data, unicode): */ struct __pyx_opt_args_5_cdec_as_str { int __pyx_n; @@ -454,39 +463,42 @@ struct __pyx_obj_5_cdec_Scorer { }; -/* "_cdec.pyx":27 - * class ParseFailed(Exception): pass +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":18 + * return '[%s]' % self.cat * - * def _make_config(config): # <<<<<<<<<<<<<< - * for key, value in config.items(): - * if isinstance(value, dict): + * cdef class NTRef: # <<<<<<<<<<<<<< + * cdef public unsigned ref + * def __init__(self, ref): + */ +struct __pyx_obj_5_cdec_NTRef { + PyObject_HEAD + unsigned int ref; +}; + + +/* "_cdec.pyx":43 + * cdef DenseVector weights + * + * def __cinit__(self, config_str=None, **config): # <<<<<<<<<<<<<< + * """ Configuration can be given as a string: + * Decoder('formalism = scfg') */ -struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config { +struct __pyx_obj_5_cdec___pyx_scope_struct_23___cinit__ { PyObject_HEAD PyObject *__pyx_v_config; - PyObject *__pyx_v_info; - PyObject *__pyx_v_key; - PyObject *__pyx_v_name; - PyObject *__pyx_v_value; - PyObject *__pyx_t_0; - PyObject *__pyx_t_1; - Py_ssize_t __pyx_t_2; - PyObject *(*__pyx_t_3)(PyObject *); - Py_ssize_t __pyx_t_4; - PyObject *(*__pyx_t_5)(PyObject *); }; -/* "_cdec.pyx":53 +/* "_cdec.pyx":54 * 'csplit', 'tagger', 'lexalign'): * raise InvalidConfig('formalism "%s" unknown' % formalism) * config_str = '\n'.join('%s = %s' % kv for kv in _make_config(config)) # <<<<<<<<<<<<<< * cdef istringstream* config_stream = new istringstream(config_str) * self.dec = new decoder.Decoder(config_stream) */ -struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr { +struct __pyx_obj_5_cdec___pyx_scope_struct_24_genexpr { PyObject_HEAD - struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *__pyx_outer_scope; + struct __pyx_obj_5_cdec___pyx_scope_struct_23___cinit__ *__pyx_outer_scope; PyObject *__pyx_v_kv; PyObject *__pyx_t_0; Py_ssize_t __pyx_t_1; @@ -494,80 +506,58 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":2 - * def _phrase(phrase): - * return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) # <<<<<<<<<<<<<< +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":146 + * self.rule.get().ComputeArity() * - * cdef class TRule: - */ -struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr { - PyObject_HEAD - struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *__pyx_outer_scope; - PyObject *__pyx_v_w; - PyObject *__pyx_t_0; - Py_ssize_t __pyx_t_1; - PyObject *(*__pyx_t_2)(PyObject *); -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":53 - * return TDConvert(-self.rule.lhs_) + * cdef class Grammar: # <<<<<<<<<<<<<< + * cdef shared_ptr[grammar.Grammar]* grammar * - * def __str__(self): # <<<<<<<<<<<<<< - * scores = ' '.join('%s=%s' % feat for feat in self.scores) - * return '[%s] ||| %s ||| %s ||| %s' % (self.lhs, _phrase(self.f), _phrase(self.e), scores) */ -struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ { +struct __pyx_obj_5_cdec_Grammar { PyObject_HEAD - struct __pyx_obj_5_cdec_TRule *__pyx_v_self; + boost::shared_ptr *grammar; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":189 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":119 * - * property in_edges: + * property nodes: * def __get__(self): # <<<<<<<<<<<<<< * cdef unsigned i - * for i in range(self.node.in_edges_.size()): + * for i in range(self.hg.nodes_.size()): */ struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ { PyObject_HEAD unsigned int __pyx_v_i; - struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; size_t __pyx_t_0; unsigned int __pyx_t_1; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":49 - * return hypergraph.AsPLF(self.lattice[0], True).c_str() +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":57 + * del self.lattice * - * def __iter__(self): # <<<<<<<<<<<<<< - * cdef unsigned i - * for i in range(len(self)): + * def todot(self): # <<<<<<<<<<<<<< + * def lines(): + * yield 'digraph lattice {' */ -struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ { +struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot { PyObject_HEAD - unsigned int __pyx_v_i; struct __pyx_obj_5_cdec_Lattice *__pyx_v_self; - Py_ssize_t __pyx_t_0; - unsigned int __pyx_t_1; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":121 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":3 + * cimport grammar + * + * def _phrase(phrase): # <<<<<<<<<<<<<< + * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) * - * property nodes: - * def __get__(self): # <<<<<<<<<<<<<< - * cdef unsigned i - * for i in range(self.hg.nodes_.size()): */ -struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ { +struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase { PyObject_HEAD - unsigned int __pyx_v_i; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; - size_t __pyx_t_0; - unsigned int __pyx_t_1; + PyObject *__pyx_v_phrase; }; @@ -586,55 +576,61 @@ struct __pyx_obj_5_cdec_CandidateSet { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":195 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":167 * - * property out_edges: + * property tail_nodes: * def __get__(self): # <<<<<<<<<<<<<< * cdef unsigned i - * for i in range(self.node.out_edges_.size()): + * for i in range(self.edge.tail_nodes_.size()): */ struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ { PyObject_HEAD unsigned int __pyx_v_i; - struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self; - size_t __pyx_t_0; + struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self; + unsigned int __pyx_t_0; unsigned int __pyx_t_1; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":4 - * return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":26 + * return '[%d]' % self.ref * - * cdef class TRule: # <<<<<<<<<<<<<< - * cdef hypergraph.TRule* rule + * cdef class BaseTRule: # <<<<<<<<<<<<<< + * cdef shared_ptr[grammar.TRule]* rule * */ -struct __pyx_obj_5_cdec_TRule { +struct __pyx_obj_5_cdec_BaseTRule { PyObject_HEAD - TRule *rule; + boost::shared_ptr *rule; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":43 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":135 + * _phrase(self.f), _phrase(self.e), scores) * - * def kbest_trees(self, size): # <<<<<<<<<<<<<< - * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal]* f_derivations = new kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal](self.hg[0], size) - * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal].Derivation* f_derivation + * cdef class TRule(BaseTRule): # <<<<<<<<<<<<<< + * def __cinit__(self, lhs, f, e, scores, a=None): + * self.rule = new shared_ptr[grammar.TRule](new grammar.TRule()) + */ +struct __pyx_obj_5_cdec_TRule { + struct __pyx_obj_5_cdec_BaseTRule __pyx_base; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":4 + * + * def _phrase(phrase): + * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) # <<<<<<<<<<<<<< + * + * cdef class NT: */ -struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees { +struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr { PyObject_HEAD - KBest::KBestDerivations,ETreeTraversal>::Derivation *__pyx_v_e_derivation; - KBest::KBestDerivations,ETreeTraversal> *__pyx_v_e_derivations; - PyObject *__pyx_v_e_tree; - KBest::KBestDerivations,FTreeTraversal>::Derivation *__pyx_v_f_derivation; - KBest::KBestDerivations,FTreeTraversal> *__pyx_v_f_derivations; - PyObject *__pyx_v_f_tree; - unsigned int __pyx_v_k; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; - PyObject *__pyx_v_size; - unsigned int __pyx_t_0; - long __pyx_t_1; + struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase *__pyx_outer_scope; + PyObject *__pyx_v_w; + PyObject *__pyx_t_0; + Py_ssize_t __pyx_t_1; + PyObject *(*__pyx_t_2)(PyObject *); }; @@ -652,41 +648,20 @@ struct __pyx_obj_5_cdec_SegmentEvaluator { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":61 - * del e_derivations - * - * def kbest_features(self, size): # <<<<<<<<<<<<<< - * cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal]* derivations = new kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal](self.hg[0], size) - * cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal].Derivation* derivation - */ -struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features { - PyObject_HEAD - KBest::KBestDerivations,FeatureVectorTraversal>::Derivation *__pyx_v_derivation; - KBest::KBestDerivations,FeatureVectorTraversal> *__pyx_v_derivations; - struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap; - unsigned int __pyx_v_k; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; - PyObject *__pyx_v_size; - unsigned int __pyx_t_0; - long __pyx_t_1; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":76 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":44 + * return self.stats.size() * - * def sample(self, unsigned n): # <<<<<<<<<<<<<< - * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() - * if self.rng == NULL: + * def __iter__(self): # <<<<<<<<<<<<<< + * for i in range(len(self)): + * yield self.stats[0][i] */ -struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample { +struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__ { PyObject_HEAD - std::vector *__pyx_v_hypos; - unsigned int __pyx_v_k; - unsigned int __pyx_v_n; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; - size_t __pyx_t_0; - unsigned int __pyx_t_1; + PyObject *__pyx_v_i; + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self; + Py_ssize_t __pyx_t_0; + PyObject *__pyx_t_1; + PyObject *(*__pyx_t_2)(PyObject *); }; @@ -704,24 +679,39 @@ struct __pyx_obj_5_cdec_Candidate { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":115 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":131 * - * property edges: - * def __get__(self): # <<<<<<<<<<<<<< - * cdef unsigned i - * for i in range(self.hg.edges_.size()): + * def __str__(self): + * scores = ' '.join('%s=%s' % feat for feat in self.scores) # <<<<<<<<<<<<<< + * return '%s ||| %s ||| %s ||| %s' % (self.lhs, + * _phrase(self.f), _phrase(self.e), scores) */ -struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ { +struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr { PyObject_HEAD - unsigned int __pyx_v_i; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; - size_t __pyx_t_0; - unsigned int __pyx_t_1; + struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ *__pyx_outer_scope; + PyObject *__pyx_v_feat; + PyObject *__pyx_t_0; + Py_ssize_t __pyx_t_1; + PyObject *(*__pyx_t_2)(PyObject *); +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":6 + * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) + * + * cdef class NT: # <<<<<<<<<<<<<< + * cdef public char* cat + * cdef public unsigned ref + */ +struct __pyx_obj_5_cdec_NT { + PyObject_HEAD + char *cat; + unsigned int ref; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":133 - * include "trule.pxi" +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":147 + * return vector * * cdef class HypergraphEdge: # <<<<<<<<<<<<<< * cdef hypergraph.Hypergraph* hg @@ -732,7 +722,7 @@ struct __pyx_obj_5_cdec_HypergraphEdge { struct __pyx_vtabstruct_5_cdec_HypergraphEdge *__pyx_vtab; Hypergraph *hg; const Hypergraph::Edge *edge; - struct __pyx_obj_5_cdec_TRule *trule; + struct __pyx_obj_5_cdec_BaseTRule *trule; }; @@ -741,36 +731,52 @@ struct __pyx_obj_5_cdec_HypergraphEdge { * * def __iter__(self): # <<<<<<<<<<<<<< * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) - * try: + * cdef unsigned i */ struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ { PyObject_HEAD - size_t __pyx_v_i; + unsigned int __pyx_v_i; FastSparseVector::const_iterator *__pyx_v_it; struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self; size_t __pyx_t_0; - size_t __pyx_t_1; + unsigned int __pyx_t_1; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":44 - * return self.stats.size() +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":209 * - * def __iter__(self): # <<<<<<<<<<<<<< - * for i in range(len(self)): - * yield self.stats[0][i] + * property out_edges: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.node.out_edges_.size()): */ -struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ { +struct __pyx_obj_5_cdec___pyx_scope_struct_16___get__ { PyObject_HEAD - PyObject *__pyx_v_i; - struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self; - Py_ssize_t __pyx_t_0; - PyObject *__pyx_t_1; - PyObject *(*__pyx_t_2)(PyObject *); + unsigned int __pyx_v_i; + struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self; + size_t __pyx_t_0; + unsigned int __pyx_t_1; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":90 + * + * property a: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * cdef vector[grammar.AlignmentPoint]* a = &self.rule.get().a_ + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ { + PyObject_HEAD + std::vector *__pyx_v_a; + unsigned int __pyx_v_i; + struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self; + size_t __pyx_t_0; + unsigned int __pyx_t_1; }; -/* "_cdec.pyx":38 +/* "_cdec.pyx":39 * yield key, bytes(value) * * cdef class Decoder: # <<<<<<<<<<<<<< @@ -784,7 +790,7 @@ struct __pyx_obj_5_cdec_Decoder { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":179 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":193 * raise NotImplemented('comparison not implemented for HypergraphEdge') * * cdef class HypergraphNode: # <<<<<<<<<<<<<< @@ -812,106 +818,83 @@ struct __pyx_obj_5_cdec_SparseVector { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":54 +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":49 + * return hypergraph.AsPLF(self.lattice[0], True).c_str() * - * def __str__(self): - * scores = ' '.join('%s=%s' % feat for feat in self.scores) # <<<<<<<<<<<<<< - * return '[%s] ||| %s ||| %s ||| %s' % (self.lhs, _phrase(self.f), _phrase(self.e), scores) + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(len(self)): */ -struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr { +struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__ { PyObject_HEAD - struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *__pyx_outer_scope; - PyObject *__pyx_v_feat; - PyObject *__pyx_t_0; - Py_ssize_t __pyx_t_1; - PyObject *(*__pyx_t_2)(PyObject *); + unsigned int __pyx_v_i; + struct __pyx_obj_5_cdec_Lattice *__pyx_v_self; + Py_ssize_t __pyx_t_0; + unsigned int __pyx_t_1; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":153 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":113 * - * property tail_nodes: + * property edges: * def __get__(self): # <<<<<<<<<<<<<< * cdef unsigned i - * for i in range(self.edge.tail_nodes_.size()): + * for i in range(self.hg.edges_.size()): */ struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ { PyObject_HEAD unsigned int __pyx_v_i; - struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self; - unsigned int __pyx_t_0; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; + size_t __pyx_t_0; unsigned int __pyx_t_1; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":22 - * self.vector[0][fid] = value +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":85 + * return candidate * * def __iter__(self): # <<<<<<<<<<<<<< - * cdef unsigned fid - * for fid in range(1, self.vector.size()): + * cdef unsigned i + * for i in range(len(self)): */ -struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ { +struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__ { PyObject_HEAD - unsigned int __pyx_v_fid; - struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self; - size_t __pyx_t_0; + unsigned int __pyx_v_i; + struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self; + Py_ssize_t __pyx_t_0; unsigned int __pyx_t_1; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":31 - * return unicode(hypergraph.JoshuaVisualizationString(self.hg[0]).c_str(), 'utf8') +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":3 + * from cython.operator cimport preincrement as pinc + * + * cdef class DenseVector: # <<<<<<<<<<<<<< + * cdef vector[weight_t]* vector # Not owned by DenseVector * - * def kbest(self, size): # <<<<<<<<<<<<<< - * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal]* derivations = new kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal](self.hg[0], size) - * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal].Derivation* derivation */ -struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest { - PyObject_HEAD - KBest::KBestDerivations,ESentenceTraversal>::Derivation *__pyx_v_derivation; - KBest::KBestDerivations,ESentenceTraversal> *__pyx_v_derivations; - unsigned int __pyx_v_k; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; - PyObject *__pyx_v_size; - unsigned int __pyx_t_0; - long __pyx_t_1; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":3 - * from cython.operator cimport preincrement as pinc - * - * cdef class DenseVector: # <<<<<<<<<<<<<< - * cdef vector[weight_t]* vector # Not owned by DenseVector - * - */ -struct __pyx_obj_5_cdec_DenseVector { +struct __pyx_obj_5_cdec_DenseVector { PyObject_HEAD std::vector *vector; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":58 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":152 + * del self.grammar * - * def todot(self): - * def lines(): # <<<<<<<<<<<<<< - * yield 'digraph lattice {' - * yield 'rankdir = LR;' + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef grammar.GrammarIter* root = self.grammar.get().GetRoot() + * cdef grammar.RuleBin* rbin = root.GetRules() */ -struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines { +struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ { PyObject_HEAD - struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *__pyx_outer_scope; - PyObject *__pyx_v_delta; - PyObject *__pyx_v_i; - PyObject *__pyx_v_label; - PyObject *__pyx_v_weight; - Py_ssize_t __pyx_t_0; - PyObject *__pyx_t_1; - PyObject *(*__pyx_t_2)(PyObject *); - PyObject *__pyx_t_3; - Py_ssize_t __pyx_t_4; - PyObject *(*__pyx_t_5)(PyObject *); + unsigned int __pyx_v_i; + const RuleBin *__pyx_v_rbin; + const GrammarIter *__pyx_v_root; + struct __pyx_obj_5_cdec_Grammar *__pyx_v_self; + struct __pyx_obj_5_cdec_TRule *__pyx_v_trule; + int __pyx_t_0; + unsigned int __pyx_t_1; }; @@ -929,16 +912,94 @@ struct __pyx_obj_5_cdec_SufficientStats { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":57 - * del self.lattice +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":31 + * return unicode(hypergraph.JoshuaVisualizationString(self.hg[0]).c_str(), 'utf8') * - * def todot(self): # <<<<<<<<<<<<<< - * def lines(): - * yield 'digraph lattice {' + * def kbest(self, size): # <<<<<<<<<<<<<< + * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal]* derivations = new kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal](self.hg[0], size) + * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal].Derivation* derivation */ -struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot { +struct __pyx_obj_5_cdec___pyx_scope_struct_8_kbest { PyObject_HEAD - struct __pyx_obj_5_cdec_Lattice *__pyx_v_self; + KBest::KBestDerivations,ESentenceTraversal>::Derivation *__pyx_v_derivation; + KBest::KBestDerivations,ESentenceTraversal> *__pyx_v_derivations; + unsigned int __pyx_v_k; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; + PyObject *__pyx_v_size; + unsigned int __pyx_t_0; + long __pyx_t_1; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":61 + * del e_derivations + * + * def kbest_features(self, size): # <<<<<<<<<<<<<< + * cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal]* derivations = new kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal](self.hg[0], size) + * cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal].Derivation* derivation + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_10_kbest_features { + PyObject_HEAD + KBest::KBestDerivations,FeatureVectorTraversal>::Derivation *__pyx_v_derivation; + KBest::KBestDerivations,FeatureVectorTraversal> *__pyx_v_derivations; + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap; + unsigned int __pyx_v_k; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; + PyObject *__pyx_v_size; + unsigned int __pyx_t_0; + long __pyx_t_1; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":203 + * + * property in_edges: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.node.in_edges_.size()): + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__ { + PyObject_HEAD + unsigned int __pyx_v_i; + struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self; + size_t __pyx_t_0; + unsigned int __pyx_t_1; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":130 + * self.rule.get().lhs_ = -TDConvert(lhs.cat) + * + * def __str__(self): # <<<<<<<<<<<<<< + * scores = ' '.join('%s=%s' % feat for feat in self.scores) + * return '%s ||| %s ||| %s ||| %s' % (self.lhs, + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ { + PyObject_HEAD + struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":43 + * del derivations + * + * def kbest_trees(self, size): # <<<<<<<<<<<<<< + * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal]* f_derivations = new kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal](self.hg[0], size) + * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal].Derivation* f_derivation + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_9_kbest_trees { + PyObject_HEAD + KBest::KBestDerivations,ETreeTraversal>::Derivation *__pyx_v_e_derivation; + KBest::KBestDerivations,ETreeTraversal> *__pyx_v_e_derivations; + PyObject *__pyx_v_e_tree; + KBest::KBestDerivations,FTreeTraversal>::Derivation *__pyx_v_f_derivation; + KBest::KBestDerivations,FTreeTraversal> *__pyx_v_f_derivations; + PyObject *__pyx_v_f_tree; + unsigned int __pyx_v_k; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; + PyObject *__pyx_v_size; + unsigned int __pyx_t_0; + long __pyx_t_1; }; @@ -969,48 +1030,100 @@ struct __pyx_obj_5_cdec_Lattice { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":1 - * def _phrase(phrase): # <<<<<<<<<<<<<< - * return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":76 + * del derivations * + * def sample(self, unsigned n): # <<<<<<<<<<<<<< + * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() + * if self.rng == NULL: */ -struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase { +struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample { PyObject_HEAD - PyObject *__pyx_v_phrase; + std::vector *__pyx_v_hypos; + unsigned int __pyx_v_k; + unsigned int __pyx_v_n; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; + size_t __pyx_t_0; + unsigned int __pyx_t_1; }; -/* "_cdec.pyx":42 - * cdef DenseVector weights +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":22 + * self.vector[0][fid] = value * - * def __cinit__(self, config_str=None, **config): # <<<<<<<<<<<<<< - * """ Configuration can be given as a string: - * Decoder('formalism = scfg') + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef unsigned fid + * for fid in range(1, self.vector.size()): + */ +struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ { + PyObject_HEAD + unsigned int __pyx_v_fid; + struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self; + size_t __pyx_t_0; + unsigned int __pyx_t_1; +}; + + +/* "_cdec.pyx":28 + * class ParseFailed(Exception): pass + * + * def _make_config(config): # <<<<<<<<<<<<<< + * for key, value in config.items(): + * if isinstance(value, dict): */ -struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ { +struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config { PyObject_HEAD PyObject *__pyx_v_config; + PyObject *__pyx_v_info; + PyObject *__pyx_v_key; + PyObject *__pyx_v_name; + PyObject *__pyx_v_value; + PyObject *__pyx_t_0; + PyObject *__pyx_t_1; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":85 - * return candidate +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":169 + * self.grammar.get().SetGrammarName(string(name)) * - * def __iter__(self): # <<<<<<<<<<<<<< - * cdef unsigned i - * for i in range(len(self)): + * cdef class TextGrammar(Grammar): # <<<<<<<<<<<<<< + * def __cinit__(self, rules): + * self.grammar = new shared_ptr[grammar.Grammar](new grammar.TextGrammar()) + */ +struct __pyx_obj_5_cdec_TextGrammar { + struct __pyx_obj_5_cdec_Grammar __pyx_base; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":58 + * + * def todot(self): + * def lines(): # <<<<<<<<<<<<<< + * yield 'digraph lattice {' + * yield 'rankdir = LR;' */ -struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ { +struct __pyx_obj_5_cdec___pyx_scope_struct_19_lines { PyObject_HEAD - unsigned int __pyx_v_i; - struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self; + struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot *__pyx_outer_scope; + PyObject *__pyx_v_delta; + PyObject *__pyx_v_i; + PyObject *__pyx_v_label; + PyObject *__pyx_v_weight; Py_ssize_t __pyx_t_0; - unsigned int __pyx_t_1; + PyObject *__pyx_t_1; + PyObject *(*__pyx_t_2)(PyObject *); + PyObject *__pyx_t_3; + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":179 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":193 * raise NotImplemented('comparison not implemented for HypergraphEdge') * * cdef class HypergraphNode: # <<<<<<<<<<<<<< @@ -1024,8 +1137,8 @@ struct __pyx_vtabstruct_5_cdec_HypergraphNode { static struct __pyx_vtabstruct_5_cdec_HypergraphNode *__pyx_vtabptr_5_cdec_HypergraphNode; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":133 - * include "trule.pxi" +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":147 + * return vector * * cdef class HypergraphEdge: # <<<<<<<<<<<<<< * cdef hypergraph.Hypergraph* hg @@ -1102,6 +1215,8 @@ static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ +static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname); + static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ @@ -1111,15 +1226,6 @@ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ -static CYTHON_INLINE int __Pyx_NegateNonNeg(int b) { - return unlikely(b < 0) ? b : !b; -} -static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) { - return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b); -} - -static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname); - static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) { if (likely(PyList_CheckExact(L))) { if (PyList_Append(L, x) < 0) return NULL; @@ -1136,15 +1242,6 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) { } } -#define __Pyx_PyIter_Next(obj) __Pyx_PyIter_Next2(obj, NULL); -static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject *, PyObject *); /*proto*/ - -static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); - -static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); - -static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/ - static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { PyObject *r; if (!j) return NULL; @@ -1217,6 +1314,22 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); } +static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); + +static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); + +static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/ + +static CYTHON_INLINE int __Pyx_NegateNonNeg(int b) { + return unlikely(b < 0) ? b : !b; +} +static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) { + return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b); +} + +#define __Pyx_PyIter_Next(obj) __Pyx_PyIter_Next2(obj, NULL); +static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject *, PyObject *); /*proto*/ + static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */ #define __Pyx_PyObject_AsDouble(obj) \ ((likely(PyFloat_CheckExact(obj))) ? \ @@ -1232,6 +1345,8 @@ static PyObject *__Pyx_FindPy2Metaclass(PyObject *bases); /*proto*/ static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, PyObject *modname); /*proto*/ +static CYTHON_INLINE WordID __Pyx_PyInt_from_py_WordID(PyObject *); + static PyObject* __Pyx_Globals(void); /*proto*/ #define __Pyx_CyFunction_USED 1 @@ -1378,6 +1493,8 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* Module declarations from 'utils' */ +/* Module declarations from 'grammar' */ + /* Module declarations from 'lattice' */ /* Module declarations from 'hypergraph' */ @@ -1391,8 +1508,13 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* Module declarations from '_cdec' */ static PyTypeObject *__pyx_ptype_5_cdec_DenseVector = 0; static PyTypeObject *__pyx_ptype_5_cdec_SparseVector = 0; -static PyTypeObject *__pyx_ptype_5_cdec_Hypergraph = 0; +static PyTypeObject *__pyx_ptype_5_cdec_NT = 0; +static PyTypeObject *__pyx_ptype_5_cdec_NTRef = 0; +static PyTypeObject *__pyx_ptype_5_cdec_BaseTRule = 0; static PyTypeObject *__pyx_ptype_5_cdec_TRule = 0; +static PyTypeObject *__pyx_ptype_5_cdec_Grammar = 0; +static PyTypeObject *__pyx_ptype_5_cdec_TextGrammar = 0; +static PyTypeObject *__pyx_ptype_5_cdec_Hypergraph = 0; static PyTypeObject *__pyx_ptype_5_cdec_HypergraphEdge = 0; static PyTypeObject *__pyx_ptype_5_cdec_HypergraphNode = 0; static PyTypeObject *__pyx_ptype_5_cdec_Lattice = 0; @@ -1404,27 +1526,29 @@ static PyTypeObject *__pyx_ptype_5_cdec_Scorer = 0; static PyTypeObject *__pyx_ptype_5_cdec_Decoder = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct____iter__ = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_1___iter__ = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_2_kbest = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_trees = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_5_sample = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_6___get__ = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_7___get__ = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_8__phrase = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_9_genexpr = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_10___str__ = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_11_genexpr = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_2__phrase = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_3_genexpr = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_4___get__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_5___str__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_6_genexpr = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_7___iter__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_8_kbest = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_9_kbest_trees = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_10_kbest_features = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_11_sample = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_12___get__ = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_13___get__ = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_14___get__ = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_15___iter__ = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_16_todot = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_17_lines = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_18___iter__ = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_19___iter__ = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_20__make_config = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_21___cinit__ = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_22_genexpr = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_15___get__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_16___get__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_17___iter__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_18_todot = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_19_lines = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_20___iter__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_21___iter__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_22__make_config = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_23___cinit__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_24_genexpr = 0; static char *__pyx_f_5_cdec_as_str(PyObject *, struct __pyx_opt_args_5_cdec_as_str *__pyx_optional_args); /*proto*/ static struct __pyx_obj_5_cdec_SufficientStats *__pyx_f_5_cdec_as_stats(PyObject *, PyObject *); /*proto*/ #define __Pyx_MODULE_NAME "_cdec" @@ -1436,6 +1560,7 @@ static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_KeyError; static PyObject *__pyx_builtin_range; static PyObject *__pyx_builtin_NotImplemented; +static PyObject *__pyx_builtin_ValueError; static PyObject *__pyx_builtin_eval; static PyObject *__pyx_builtin_enumerate; static PyObject *__pyx_builtin_IndexError; @@ -1468,6 +1593,38 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_33__mul__(PyObject *__pyx_v_x, P #if PY_MAJOR_VERSION < 3 static PyObject *__pyx_pf_5_cdec_12SparseVector_35__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ #endif +static PyObject *__pyx_pf_5_cdec_7_phrase_genexpr(PyObject *__pyx_self); /* proto */ +static PyObject *__pyx_pf_5_cdec__phrase(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_phrase); /* proto */ +static int __pyx_pf_5_cdec_2NT___init__(struct __pyx_obj_5_cdec_NT *__pyx_v_self, PyObject *__pyx_v_cat, PyObject *__pyx_v_ref); /* proto */ +static PyObject *__pyx_pf_5_cdec_2NT_2__str__(struct __pyx_obj_5_cdec_NT *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_2NT_3cat___get__(struct __pyx_obj_5_cdec_NT *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_2NT_3cat_2__set__(struct __pyx_obj_5_cdec_NT *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_5_cdec_2NT_3ref___get__(struct __pyx_obj_5_cdec_NT *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_2NT_3ref_2__set__(struct __pyx_obj_5_cdec_NT *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_5_cdec_5NTRef___init__(struct __pyx_obj_5_cdec_NTRef *__pyx_v_self, PyObject *__pyx_v_ref); /* proto */ +static PyObject *__pyx_pf_5_cdec_5NTRef_2__str__(struct __pyx_obj_5_cdec_NTRef *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_5NTRef_3ref___get__(struct __pyx_obj_5_cdec_NTRef *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_5NTRef_3ref_2__set__(struct __pyx_obj_5_cdec_NTRef *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static void __pyx_pf_5_cdec_9BaseTRule___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_9BaseTRule_5arity___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_9BaseTRule_1f___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_9BaseTRule_1f_2__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_f); /* proto */ +static PyObject *__pyx_pf_5_cdec_9BaseTRule_1e___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_9BaseTRule_1e_2__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_e); /* proto */ +static PyObject *__pyx_pf_5_cdec_9BaseTRule_1a___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_9BaseTRule_1a_3__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_a); /* proto */ +static PyObject *__pyx_pf_5_cdec_9BaseTRule_6scores___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_9BaseTRule_6scores_2__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_scores); /* proto */ +static PyObject *__pyx_pf_5_cdec_9BaseTRule_3lhs___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_9BaseTRule_3lhs_2__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_lhs); /* proto */ +static PyObject *__pyx_pf_5_cdec_9BaseTRule_7__str___genexpr(PyObject *__pyx_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_9BaseTRule_2__str__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_5TRule___cinit__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self, PyObject *__pyx_v_lhs, PyObject *__pyx_v_f, PyObject *__pyx_v_e, PyObject *__pyx_v_scores, PyObject *__pyx_v_a); /* proto */ +static void __pyx_pf_5_cdec_7Grammar___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Grammar *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_7Grammar_2__iter__(struct __pyx_obj_5_cdec_Grammar *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_7Grammar_4name___get__(struct __pyx_obj_5_cdec_Grammar *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_7Grammar_4name_2__set__(struct __pyx_obj_5_cdec_Grammar *__pyx_v_self, PyObject *__pyx_v_name); /* proto */ +static int __pyx_pf_5_cdec_11TextGrammar___cinit__(struct __pyx_obj_5_cdec_TextGrammar *__pyx_v_self, PyObject *__pyx_v_rules); /* proto */ static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_4viterbi_trees(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ @@ -1484,15 +1641,8 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec static PyObject *__pyx_pf_5_cdec_10Hypergraph_5edges___get__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_5nodes___get__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_4goal___get__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_7_phrase_genexpr(PyObject *__pyx_self); /* proto */ -static PyObject *__pyx_pf_5_cdec__phrase(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_phrase); /* proto */ -static PyObject *__pyx_pf_5_cdec_5TRule_5arity___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_5TRule_1f___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_5TRule_1e___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_5TRule_6scores___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_5TRule_3lhs___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_5TRule_7__str___genexpr(PyObject *__pyx_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_5TRule___str__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_6npaths___get__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_30inside_outside(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ static Py_ssize_t __pyx_pf_5_cdec_14HypergraphEdge___len__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_9head_node___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_10tail_nodes___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self); /* proto */ @@ -1508,7 +1658,7 @@ static PyObject *__pyx_pf_5_cdec_14HypergraphNode_9out_edges___get__(struct __py static PyObject *__pyx_pf_5_cdec_14HypergraphNode_4span___get__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_14HypergraphNode_3cat___get__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_14HypergraphNode___richcmp__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_x, struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_y, int __pyx_v_op); /* proto */ -static int __pyx_pf_5_cdec_7Lattice___init__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, PyObject *__pyx_v_inp); /* proto */ +static int __pyx_pf_5_cdec_7Lattice___cinit__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, PyObject *__pyx_v_inp); /* proto */ static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index); /* proto */ static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index, PyObject *__pyx_v_arcs); /* proto */ static Py_ssize_t __pyx_pf_5_cdec_7Lattice_6__len__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ @@ -1553,41 +1703,46 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec static char __pyx_k_1[] = "Cannot convert type %s to str"; static char __pyx_k_3[] = "cannot take the dot product of %s and SparseVector"; static char __pyx_k_4[] = "comparison not implemented for SparseVector"; -static char __pyx_k_6[] = "csplit_preserve_full_word"; -static char __pyx_k_7[] = "cannot reweight hypergraph with %s"; +static char __pyx_k_7[] = " "; static char __pyx_k_8[] = "[%s,%d]"; -static char __pyx_k_10[] = " "; +static char __pyx_k_9[] = "[%s]"; +static char __pyx_k_10[] = "[%d]"; static char __pyx_k_11[] = "%s=%s"; -static char __pyx_k_12[] = "[%s] ||| %s ||| %s ||| %s"; -static char __pyx_k_13[] = "comparison not implemented for HypergraphEdge"; -static char __pyx_k_15[] = "comparison not implemented for HypergraphNode"; -static char __pyx_k_18[] = "Cannot create lattice from %s"; -static char __pyx_k_19[] = "lattice index out of range"; -static char __pyx_k_23[] = "digraph lattice {"; - static char __pyx_k_24[] = "rankdir = LR;"; - static char __pyx_k_25[] = "node [shape=circle];"; - static char __pyx_k_26[] = "%d -> %d [label=\"%s\"];"; - static char __pyx_k_27[] = "\""; - static char __pyx_k_28[] = "\\\""; - static char __pyx_k_30[] = "%d [shape=doublecircle]"; -static char __pyx_k_31[] = "}"; -static char __pyx_k_34[] = "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi"; -static char __pyx_k_35[] = "\n"; -static char __pyx_k_37[] = "candidate set index out of range"; -static char __pyx_k_39[] = "%s %s"; -static char __pyx_k_40[] = "%s = %s"; -static char __pyx_k_42[] = "formalism \"%s\" unknown"; -static char __pyx_k_43[] = "cannot initialize weights with %s"; -static char __pyx_k_44[] = "#"; -static char __pyx_k_48[] = "Cannot translate input type %s"; -static char __pyx_k_51[] = "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi"; -static char __pyx_k_56[] = "/Users/vchahun/Sandbox/cdec/python/src/_cdec.pyx"; +static char __pyx_k_12[] = "%s ||| %s ||| %s ||| %s"; +static char __pyx_k_13[] = "the grammar should contain TRule objects"; +static char __pyx_k_15[] = "csplit_preserve_full_word"; +static char __pyx_k_16[] = "cannot reweight hypergraph with %s"; +static char __pyx_k_17[] = "comparison not implemented for HypergraphEdge"; +static char __pyx_k_19[] = "comparison not implemented for HypergraphNode"; +static char __pyx_k_22[] = "Cannot create lattice from %s"; +static char __pyx_k_23[] = "lattice index out of range"; +static char __pyx_k_27[] = "digraph lattice {"; + static char __pyx_k_28[] = "rankdir = LR;"; + static char __pyx_k_29[] = "node [shape=circle];"; + static char __pyx_k_30[] = "%d -> %d [label=\"%s\"];"; + static char __pyx_k_31[] = "\""; + static char __pyx_k_32[] = "\\\""; + static char __pyx_k_34[] = "%d [shape=doublecircle]"; +static char __pyx_k_35[] = "}"; +static char __pyx_k_38[] = "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi"; +static char __pyx_k_39[] = "\n"; +static char __pyx_k_41[] = "candidate set index out of range"; +static char __pyx_k_43[] = "%s %s"; +static char __pyx_k_44[] = "%s = %s"; +static char __pyx_k_46[] = "formalism \"%s\" unknown"; +static char __pyx_k_47[] = "cannot initialize weights with %s"; +static char __pyx_k_48[] = "#"; +static char __pyx_k_51[] = "Cannot translate input type %s"; +static char __pyx_k_54[] = "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi"; +static char __pyx_k_59[] = "/Users/vchahun/Sandbox/cdec/python/src/_cdec.pyx"; +static char __pyx_k__a[] = "a"; static char __pyx_k__e[] = "e"; static char __pyx_k__f[] = "f"; static char __pyx_k__i[] = "i"; static char __pyx_k__k[] = "k"; static char __pyx_k__pb[] = "pb"; static char __pyx_k__TER[] = "TER"; +static char __pyx_k__cat[] = "cat"; static char __pyx_k__dot[] = "dot"; static char __pyx_k__fst[] = "fst"; static char __pyx_k__get[] = "get"; @@ -1595,6 +1750,7 @@ static char __pyx_k__inp[] = "inp"; static char __pyx_k__key[] = "key"; static char __pyx_k__lhs[] = "lhs"; static char __pyx_k__plf[] = "plf"; +static char __pyx_k__ref[] = "ref"; static char __pyx_k__BLEU[] = "BLEU"; static char __pyx_k__eval[] = "eval"; static char __pyx_k__info[] = "info"; @@ -1612,6 +1768,7 @@ static char __pyx_k__items[] = "items"; static char __pyx_k__label[] = "label"; static char __pyx_k__lines[] = "lines"; static char __pyx_k__range[] = "range"; +static char __pyx_k__rules[] = "rules"; static char __pyx_k__split[] = "split"; static char __pyx_k__strip[] = "strip"; static char __pyx_k__value[] = "value"; @@ -1644,6 +1801,7 @@ static char __pyx_k__enumerate[] = "enumerate"; static char __pyx_k__evaluator[] = "evaluator"; static char __pyx_k__formalism[] = "formalism"; static char __pyx_k__IndexError[] = "IndexError"; +static char __pyx_k__ValueError[] = "ValueError"; static char __pyx_k__beam_alpha[] = "beam_alpha"; static char __pyx_k__config_str[] = "config_str"; static char __pyx_k__hypergraph[] = "hypergraph"; @@ -1657,33 +1815,36 @@ static PyObject *__pyx_kp_s_10; static PyObject *__pyx_kp_s_11; static PyObject *__pyx_kp_s_12; static PyObject *__pyx_kp_s_13; -static PyObject *__pyx_kp_s_15; -static PyObject *__pyx_kp_s_18; +static PyObject *__pyx_n_s_15; +static PyObject *__pyx_kp_s_16; +static PyObject *__pyx_kp_s_17; static PyObject *__pyx_kp_s_19; +static PyObject *__pyx_kp_s_22; static PyObject *__pyx_kp_s_23; -static PyObject *__pyx_kp_s_24; -static PyObject *__pyx_kp_s_25; -static PyObject *__pyx_kp_s_26; static PyObject *__pyx_kp_s_27; static PyObject *__pyx_kp_s_28; +static PyObject *__pyx_kp_s_29; static PyObject *__pyx_kp_s_3; static PyObject *__pyx_kp_s_30; static PyObject *__pyx_kp_s_31; +static PyObject *__pyx_kp_s_32; static PyObject *__pyx_kp_s_34; static PyObject *__pyx_kp_s_35; -static PyObject *__pyx_kp_s_37; +static PyObject *__pyx_kp_s_38; static PyObject *__pyx_kp_s_39; static PyObject *__pyx_kp_s_4; -static PyObject *__pyx_kp_s_40; -static PyObject *__pyx_kp_s_42; +static PyObject *__pyx_kp_s_41; static PyObject *__pyx_kp_s_43; static PyObject *__pyx_kp_s_44; +static PyObject *__pyx_kp_s_46; +static PyObject *__pyx_kp_s_47; static PyObject *__pyx_kp_s_48; static PyObject *__pyx_kp_s_51; -static PyObject *__pyx_kp_s_56; -static PyObject *__pyx_n_s_6; +static PyObject *__pyx_kp_s_54; +static PyObject *__pyx_kp_s_59; static PyObject *__pyx_kp_s_7; static PyObject *__pyx_kp_s_8; +static PyObject *__pyx_kp_s_9; static PyObject *__pyx_n_s__BLEU; static PyObject *__pyx_n_s__Exception; static PyObject *__pyx_n_s__IBM_BLEU; @@ -1694,6 +1855,7 @@ static PyObject *__pyx_n_s__NotImplemented; static PyObject *__pyx_n_s__ParseFailed; static PyObject *__pyx_n_s__TER; static PyObject *__pyx_n_s__TypeError; +static PyObject *__pyx_n_s__ValueError; static PyObject *__pyx_n_s____enter__; static PyObject *__pyx_n_s____exit__; static PyObject *__pyx_n_s____main__; @@ -1701,7 +1863,9 @@ static PyObject *__pyx_n_s____test__; static PyObject *__pyx_n_s___cdec; static PyObject *__pyx_n_s___make_config; static PyObject *__pyx_n_s___phrase; +static PyObject *__pyx_n_s__a; static PyObject *__pyx_n_s__beam_alpha; +static PyObject *__pyx_n_s__cat; static PyObject *__pyx_n_s__config; static PyObject *__pyx_n_s__config_str; static PyObject *__pyx_n_s__csplit; @@ -1740,8 +1904,10 @@ static PyObject *__pyx_n_s__pb; static PyObject *__pyx_n_s__phrase; static PyObject *__pyx_n_s__plf; static PyObject *__pyx_n_s__range; +static PyObject *__pyx_n_s__ref; static PyObject *__pyx_n_s__refs; static PyObject *__pyx_n_s__replace; +static PyObject *__pyx_n_s__rules; static PyObject *__pyx_n_s__scfg; static PyObject *__pyx_n_s__scores; static PyObject *__pyx_n_s__self; @@ -1758,38 +1924,38 @@ static PyObject *__pyx_int_0; static PyObject *__pyx_int_1; static PyObject *__pyx_k_tuple_2; static PyObject *__pyx_k_tuple_5; -static PyObject *__pyx_k_tuple_9; +static PyObject *__pyx_k_tuple_6; static PyObject *__pyx_k_tuple_14; -static PyObject *__pyx_k_tuple_16; -static PyObject *__pyx_k_tuple_17; +static PyObject *__pyx_k_tuple_18; static PyObject *__pyx_k_tuple_20; static PyObject *__pyx_k_tuple_21; -static PyObject *__pyx_k_tuple_22; -static PyObject *__pyx_k_tuple_29; -static PyObject *__pyx_k_tuple_32; +static PyObject *__pyx_k_tuple_24; +static PyObject *__pyx_k_tuple_25; +static PyObject *__pyx_k_tuple_26; +static PyObject *__pyx_k_tuple_33; static PyObject *__pyx_k_tuple_36; -static PyObject *__pyx_k_tuple_38; -static PyObject *__pyx_k_tuple_41; +static PyObject *__pyx_k_tuple_40; +static PyObject *__pyx_k_tuple_42; static PyObject *__pyx_k_tuple_45; -static PyObject *__pyx_k_tuple_46; -static PyObject *__pyx_k_tuple_47; static PyObject *__pyx_k_tuple_49; +static PyObject *__pyx_k_tuple_50; static PyObject *__pyx_k_tuple_52; -static PyObject *__pyx_k_tuple_53; -static PyObject *__pyx_k_tuple_54; -static PyObject *__pyx_k_codeobj_33; -static PyObject *__pyx_k_codeobj_50; -static PyObject *__pyx_k_codeobj_55; +static PyObject *__pyx_k_tuple_55; +static PyObject *__pyx_k_tuple_56; +static PyObject *__pyx_k_tuple_57; +static PyObject *__pyx_k_codeobj_37; +static PyObject *__pyx_k_codeobj_53; +static PyObject *__pyx_k_codeobj_58; /* "_cdec.pyx":6 * cimport decoder * - * cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): # <<<<<<<<<<<<<< + * cdef char* as_str(data, error_msg='Cannot convert type %s to str'): # <<<<<<<<<<<<<< * cdef bytes ret - * if isinstance(sentence, unicode): + * if isinstance(data, unicode): */ -static char *__pyx_f_5_cdec_as_str(PyObject *__pyx_v_sentence, struct __pyx_opt_args_5_cdec_as_str *__pyx_optional_args) { +static char *__pyx_f_5_cdec_as_str(PyObject *__pyx_v_data, struct __pyx_opt_args_5_cdec_as_str *__pyx_optional_args) { PyObject *__pyx_v_error_msg = ((PyObject *)__pyx_kp_s_1); PyObject *__pyx_v_ret = 0; char *__pyx_r; @@ -1809,26 +1975,26 @@ static char *__pyx_f_5_cdec_as_str(PyObject *__pyx_v_sentence, struct __pyx_opt_ } /* "_cdec.pyx":8 - * cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): + * cdef char* as_str(data, error_msg='Cannot convert type %s to str'): * cdef bytes ret - * if isinstance(sentence, unicode): # <<<<<<<<<<<<<< - * ret = sentence.encode('utf8') - * elif isinstance(sentence, str): + * if isinstance(data, unicode): # <<<<<<<<<<<<<< + * ret = data.encode('utf8') + * elif isinstance(data, str): */ __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_data, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* "_cdec.pyx":9 * cdef bytes ret - * if isinstance(sentence, unicode): - * ret = sentence.encode('utf8') # <<<<<<<<<<<<<< - * elif isinstance(sentence, str): - * ret = sentence + * if isinstance(data, unicode): + * ret = data.encode('utf8') # <<<<<<<<<<<<<< + * elif isinstance(data, str): + * ret = data */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(__pyx_v_data, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); @@ -1840,40 +2006,40 @@ static char *__pyx_f_5_cdec_as_str(PyObject *__pyx_v_sentence, struct __pyx_opt_ } /* "_cdec.pyx":10 - * if isinstance(sentence, unicode): - * ret = sentence.encode('utf8') - * elif isinstance(sentence, str): # <<<<<<<<<<<<<< - * ret = sentence + * if isinstance(data, unicode): + * ret = data.encode('utf8') + * elif isinstance(data, str): # <<<<<<<<<<<<<< + * ret = data * else: */ __pyx_t_3 = ((PyObject *)((PyObject*)(&PyString_Type))); __Pyx_INCREF(__pyx_t_3); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_3); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_data, __pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_2) { /* "_cdec.pyx":11 - * ret = sentence.encode('utf8') - * elif isinstance(sentence, str): - * ret = sentence # <<<<<<<<<<<<<< + * ret = data.encode('utf8') + * elif isinstance(data, str): + * ret = data # <<<<<<<<<<<<<< * else: - * raise TypeError(error_msg % type(sentence)) + * raise TypeError(error_msg % type(data)) */ - if (!(likely(PyBytes_CheckExact(__pyx_v_sentence))||((__pyx_v_sentence) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_sentence)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_INCREF(__pyx_v_sentence); - __pyx_v_ret = ((PyObject*)__pyx_v_sentence); + if (!(likely(PyBytes_CheckExact(__pyx_v_data))||((__pyx_v_data) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_data)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_data); + __pyx_v_ret = ((PyObject*)__pyx_v_data); goto __pyx_L3; } /*else*/ { /* "_cdec.pyx":13 - * ret = sentence + * ret = data * else: - * raise TypeError(error_msg % type(sentence)) # <<<<<<<<<<<<<< + * raise TypeError(error_msg % type(data)) # <<<<<<<<<<<<<< * return ret * */ - __pyx_t_3 = PyNumber_Remainder(__pyx_v_error_msg, ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyNumber_Remainder(__pyx_v_error_msg, ((PyObject *)Py_TYPE(__pyx_v_data))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); @@ -1891,7 +2057,7 @@ static char *__pyx_f_5_cdec_as_str(PyObject *__pyx_v_sentence, struct __pyx_opt_ /* "_cdec.pyx":14 * else: - * raise TypeError(error_msg % type(sentence)) + * raise TypeError(error_msg % type(data)) * return ret # <<<<<<<<<<<<<< * * include "vectors.pxi" @@ -2789,7 +2955,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_9__iter__(PyObject *__pyx_v_self * * def __iter__(self): # <<<<<<<<<<<<<< * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) - * try: + * cdef unsigned i */ static PyObject *__pyx_pf_5_cdec_12SparseVector_8__iter__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { @@ -2833,7 +2999,7 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_10generator1(__pyx_GeneratorObje struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; size_t __pyx_t_1; - size_t __pyx_t_2; + unsigned int __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; @@ -2853,22 +3019,22 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_10generator1(__pyx_GeneratorObje * * def __iter__(self): * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) # <<<<<<<<<<<<<< + * cdef unsigned i * try: - * for i in range(self.vector.size()): */ __pyx_cur_scope->__pyx_v_it = new FastSparseVector::const_iterator((__pyx_cur_scope->__pyx_v_self->vector[0]), 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":57 - * def __iter__(self): + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":58 * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) + * cdef unsigned i * try: # <<<<<<<<<<<<<< * for i in range(self.vector.size()): * yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second) */ /*try:*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":58 - * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":59 + * cdef unsigned i * try: * for i in range(self.vector.size()): # <<<<<<<<<<<<<< * yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second) @@ -2878,18 +3044,18 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_10generator1(__pyx_GeneratorObje for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":59 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":60 * try: * for i in range(self.vector.size()): * yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second) # <<<<<<<<<<<<<< * pinc(it[0]) # ++it * finally: */ - __pyx_t_3 = PyBytes_FromString(FD::Convert((__pyx_cur_scope->__pyx_v_it[0]).operator->()->first).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L5;} + __pyx_t_3 = PyBytes_FromString(FD::Convert((__pyx_cur_scope->__pyx_v_it[0]).operator->()->first).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L5;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_4 = PyFloat_FromDouble((__pyx_cur_scope->__pyx_v_it[0]).operator->()->second); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L5;} + __pyx_t_4 = PyFloat_FromDouble((__pyx_cur_scope->__pyx_v_it[0]).operator->()->second); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L5;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L5;} + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L5;} __Pyx_GOTREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); @@ -2909,9 +3075,9 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_10generator1(__pyx_GeneratorObje __pyx_L9_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[1]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L5;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L5;} - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":60 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":61 * for i in range(self.vector.size()): * yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second) * pinc(it[0]) # ++it # <<<<<<<<<<<<<< @@ -2922,7 +3088,7 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_10generator1(__pyx_GeneratorObje } } - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":62 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":63 * pinc(it[0]) # ++it * finally: * del it # <<<<<<<<<<<<<< @@ -2982,7 +3148,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_12dot(PyObject *__pyx_v_self, Py return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":64 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":65 * del it * * def dot(self, other): # <<<<<<<<<<<<<< @@ -3001,7 +3167,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_Sp int __pyx_clineno = 0; __Pyx_RefNannySetupContext("dot", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":65 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":66 * * def dot(self, other): * if isinstance(other, DenseVector): # <<<<<<<<<<<<<< @@ -3014,7 +3180,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_Sp __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":66 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":67 * def dot(self, other): * if isinstance(other, DenseVector): * return self.vector.dot(( other).vector[0]) # <<<<<<<<<<<<<< @@ -3022,7 +3188,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_Sp * return self.vector.dot(( other).vector[0]) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->dot((((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_other)->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->dot((((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_other)->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -3030,7 +3196,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_Sp goto __pyx_L3; } - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":67 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":68 * if isinstance(other, DenseVector): * return self.vector.dot(( other).vector[0]) * elif isinstance(other, SparseVector): # <<<<<<<<<<<<<< @@ -3043,7 +3209,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_Sp __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":68 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":69 * return self.vector.dot(( other).vector[0]) * elif isinstance(other, SparseVector): * return self.vector.dot(( other).vector[0]) # <<<<<<<<<<<<<< @@ -3051,7 +3217,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_Sp * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->dot((((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->dot((((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -3060,26 +3226,26 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_Sp } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":69 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":70 * elif isinstance(other, SparseVector): * return self.vector.dot(( other).vector[0]) * raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) # <<<<<<<<<<<<<< * * def __richcmp__(SparseVector x, SparseVector y, int op): */ - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_3), ((PyObject *)Py_TYPE(__pyx_v_other))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_3), ((PyObject *)Py_TYPE(__pyx_v_other))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; @@ -3100,8 +3266,8 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_14__richcmp__(PyObject *__pyx_v_ PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = __pyx_pf_5_cdec_12SparseVector_13__richcmp__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y), ((int)__pyx_v_op)); goto __pyx_L0; __pyx_L1_error:; @@ -3111,7 +3277,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_14__richcmp__(PyObject *__pyx_v_ return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":71 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":72 * raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) * * def __richcmp__(SparseVector x, SparseVector y, int op): # <<<<<<<<<<<<<< @@ -3129,7 +3295,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5 int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__richcmp__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":74 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":75 * if op == 2: # == * return x.vector[0] == y.vector[0] * elif op == 3: # != # <<<<<<<<<<<<<< @@ -3138,7 +3304,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5 */ switch (__pyx_v_op) { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":72 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":73 * * def __richcmp__(SparseVector x, SparseVector y, int op): * if op == 2: # == # <<<<<<<<<<<<<< @@ -3147,7 +3313,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5 */ case 2: - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":73 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":74 * def __richcmp__(SparseVector x, SparseVector y, int op): * if op == 2: # == * return x.vector[0] == y.vector[0] # <<<<<<<<<<<<<< @@ -3155,14 +3321,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5 * return not (x == y) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_x->vector[0]) == (__pyx_v_y->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_x->vector[0]) == (__pyx_v_y->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; break; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":74 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":75 * if op == 2: # == * return x.vector[0] == y.vector[0] * elif op == 3: # != # <<<<<<<<<<<<<< @@ -3171,7 +3337,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5 */ case 3: - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":75 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":76 * return x.vector[0] == y.vector[0] * elif op == 3: # != * return not (x == y) # <<<<<<<<<<<<<< @@ -3179,11 +3345,11 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5 * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -3191,18 +3357,18 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5 break; } - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":76 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":77 * elif op == 3: # != * return not (x == y) * raise NotImplemented('comparison not implemented for SparseVector') # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_t_1 = PyObject_Call(__pyx_builtin_NotImplemented, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_NotImplemented, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; @@ -3227,7 +3393,7 @@ static Py_ssize_t __pyx_pw_5_cdec_12SparseVector_16__len__(PyObject *__pyx_v_sel return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":78 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":79 * raise NotImplemented('comparison not implemented for SparseVector') * * def __len__(self): # <<<<<<<<<<<<<< @@ -3240,7 +3406,7 @@ static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_15__len__(struct __pyx_obj_5_cd __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__len__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":79 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":80 * * def __len__(self): * return self.vector.size() # <<<<<<<<<<<<<< @@ -3264,7 +3430,7 @@ static int __pyx_pw_5_cdec_12SparseVector_18__contains__(PyObject *__pyx_v_self, __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0); assert(__pyx_arg_fname); { - __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 81; __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[1]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -3277,7 +3443,7 @@ static int __pyx_pw_5_cdec_12SparseVector_18__contains__(PyObject *__pyx_v_self, return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":81 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":82 * return self.vector.size() * * def __contains__(self, char* fname): # <<<<<<<<<<<<<< @@ -3290,7 +3456,7 @@ static int __pyx_pf_5_cdec_12SparseVector_17__contains__(struct __pyx_obj_5_cdec __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__contains__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":82 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":83 * * def __contains__(self, char* fname): * return self.vector.nonzero(FDConvert(fname)) # <<<<<<<<<<<<<< @@ -3317,7 +3483,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_20__neg__(PyObject *__pyx_v_self return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":84 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":85 * return self.vector.nonzero(FDConvert(fname)) * * def __neg__(self): # <<<<<<<<<<<<<< @@ -3335,19 +3501,19 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_19__neg__(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__neg__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":85 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":86 * * def __neg__(self): * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](self.vector[0]) * result.vector[0] *= -1.0 */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":86 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":87 * def __neg__(self): * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](self.vector[0]) # <<<<<<<<<<<<<< @@ -3356,7 +3522,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_19__neg__(struct __pyx_obj_5_cde */ __pyx_v_result->vector = new FastSparseVector((__pyx_v_self->vector[0])); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":87 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":88 * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](self.vector[0]) * result.vector[0] *= -1.0 # <<<<<<<<<<<<<< @@ -3365,7 +3531,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_19__neg__(struct __pyx_obj_5_cde */ (__pyx_v_result->vector[0]) *= -1.0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":88 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":89 * result.vector = new FastSparseVector[weight_t](self.vector[0]) * result.vector[0] *= -1.0 * return result # <<<<<<<<<<<<<< @@ -3396,7 +3562,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_22__iadd__(PyObject *__pyx_v_sel PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iadd__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = __pyx_pf_5_cdec_12SparseVector_21__iadd__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); goto __pyx_L0; __pyx_L1_error:; @@ -3406,7 +3572,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_22__iadd__(PyObject *__pyx_v_sel return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":90 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":91 * return result * * def __iadd__(SparseVector self, SparseVector other): # <<<<<<<<<<<<<< @@ -3419,7 +3585,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_21__iadd__(struct __pyx_obj_5_cd __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iadd__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":91 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":92 * * def __iadd__(SparseVector self, SparseVector other): * self.vector[0] += other.vector[0] # <<<<<<<<<<<<<< @@ -3428,7 +3594,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_21__iadd__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) += (__pyx_v_other->vector[0]); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":92 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":93 * def __iadd__(SparseVector self, SparseVector other): * self.vector[0] += other.vector[0] * return self # <<<<<<<<<<<<<< @@ -3453,7 +3619,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_24__isub__(PyObject *__pyx_v_sel PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__isub__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = __pyx_pf_5_cdec_12SparseVector_23__isub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); goto __pyx_L0; __pyx_L1_error:; @@ -3463,7 +3629,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_24__isub__(PyObject *__pyx_v_sel return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":94 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":95 * return self * * def __isub__(SparseVector self, SparseVector other): # <<<<<<<<<<<<<< @@ -3476,7 +3642,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_23__isub__(struct __pyx_obj_5_cd __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__isub__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":95 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":96 * * def __isub__(SparseVector self, SparseVector other): * self.vector[0] -= other.vector[0] # <<<<<<<<<<<<<< @@ -3485,7 +3651,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_23__isub__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) -= (__pyx_v_other->vector[0]); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":96 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":97 * def __isub__(SparseVector self, SparseVector other): * self.vector[0] -= other.vector[0] * return self # <<<<<<<<<<<<<< @@ -3512,7 +3678,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_26__imul__(PyObject *__pyx_v_sel __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__imul__ (wrapper)", 0); assert(__pyx_arg_scalar); { - __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -3525,7 +3691,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_26__imul__(PyObject *__pyx_v_sel return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":98 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":99 * return self * * def __imul__(SparseVector self, float scalar): # <<<<<<<<<<<<<< @@ -3538,7 +3704,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_25__imul__(struct __pyx_obj_5_cd __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__imul__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":99 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":100 * * def __imul__(SparseVector self, float scalar): * self.vector[0] *= scalar # <<<<<<<<<<<<<< @@ -3547,7 +3713,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_25__imul__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) *= __pyx_v_scalar; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":100 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":101 * def __imul__(SparseVector self, float scalar): * self.vector[0] *= scalar * return self # <<<<<<<<<<<<<< @@ -3575,7 +3741,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_28__idiv__(PyObject *__pyx_v_sel __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__idiv__ (wrapper)", 0); assert(__pyx_arg_scalar); { - __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -3589,7 +3755,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_28__idiv__(PyObject *__pyx_v_sel } #endif /*!(#if PY_MAJOR_VERSION < 3)*/ -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":102 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":103 * return self * * def __idiv__(SparseVector self, float scalar): # <<<<<<<<<<<<<< @@ -3603,7 +3769,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__idiv__(struct __pyx_obj_5_cd __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__idiv__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":103 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":104 * * def __idiv__(SparseVector self, float scalar): * self.vector[0] /= scalar # <<<<<<<<<<<<<< @@ -3612,7 +3778,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__idiv__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) /= __pyx_v_scalar; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":104 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":105 * def __idiv__(SparseVector self, float scalar): * self.vector[0] /= scalar * return self # <<<<<<<<<<<<<< @@ -3638,8 +3804,8 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_30__add__(PyObject *__pyx_v_x, P PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__add__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = __pyx_pf_5_cdec_12SparseVector_29__add__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); goto __pyx_L0; __pyx_L1_error:; @@ -3649,7 +3815,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_30__add__(PyObject *__pyx_v_x, P return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":106 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":107 * return self * * def __add__(SparseVector x, SparseVector y): # <<<<<<<<<<<<<< @@ -3667,19 +3833,19 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_29__add__(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__add__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":107 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":108 * * def __add__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":108 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":109 * def __add__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) # <<<<<<<<<<<<<< @@ -3688,7 +3854,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_29__add__(struct __pyx_obj_5_cde */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_x->vector[0]) + (__pyx_v_y->vector[0]))); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":109 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":110 * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) * return result # <<<<<<<<<<<<<< @@ -3719,8 +3885,8 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_32__sub__(PyObject *__pyx_v_x, P PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__sub__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = __pyx_pf_5_cdec_12SparseVector_31__sub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); goto __pyx_L0; __pyx_L1_error:; @@ -3730,7 +3896,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_32__sub__(PyObject *__pyx_v_x, P return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":111 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":112 * return result * * def __sub__(SparseVector x, SparseVector y): # <<<<<<<<<<<<<< @@ -3748,19 +3914,19 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_31__sub__(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__sub__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":112 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":113 * * def __sub__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":113 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":114 * def __sub__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) # <<<<<<<<<<<<<< @@ -3769,7 +3935,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_31__sub__(struct __pyx_obj_5_cde */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_x->vector[0]) - (__pyx_v_y->vector[0]))); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":114 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":115 * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) * return result # <<<<<<<<<<<<<< @@ -3805,7 +3971,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_34__mul__(PyObject *__pyx_v_x, P return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":116 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":117 * return result * * def __mul__(x, y): # <<<<<<<<<<<<<< @@ -3827,7 +3993,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_33__mul__(PyObject *__pyx_v_x, P int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__mul__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":119 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":120 * cdef SparseVector vector * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y # <<<<<<<<<<<<<< @@ -3839,10 +4005,10 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_33__mul__(PyObject *__pyx_v_x, P __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_x; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; @@ -3850,36 +4016,36 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_33__mul__(PyObject *__pyx_v_x, P } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":120 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":121 * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x # <<<<<<<<<<<<<< * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) */ - if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_y; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":121 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":122 * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":122 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":123 * else: vector, scalar = y, x * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) # <<<<<<<<<<<<<< @@ -3888,7 +4054,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_33__mul__(PyObject *__pyx_v_x, P */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_vector->vector[0]) * __pyx_v_scalar)); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":123 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":124 * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) * return result # <<<<<<<<<<<<<< @@ -3927,7 +4093,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_36__div__(PyObject *__pyx_v_x, P } #endif /*!(#if PY_MAJOR_VERSION < 3)*/ -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":125 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":126 * return result * * def __div__(x, y): # <<<<<<<<<<<<<< @@ -3950,7 +4116,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_35__div__(PyObject *__pyx_v_x, P int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__div__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":128 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":129 * cdef SparseVector vector * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y # <<<<<<<<<<<<<< @@ -3962,10 +4128,10 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_35__div__(PyObject *__pyx_v_x, P __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_x; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; @@ -3973,36 +4139,36 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_35__div__(PyObject *__pyx_v_x, P } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":129 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":130 * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x # <<<<<<<<<<<<<< * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) */ - if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_y; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":130 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":131 * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":131 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":132 * else: vector, scalar = y, x * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) # <<<<<<<<<<<<<< @@ -4010,7 +4176,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_35__div__(PyObject *__pyx_v_x, P */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_vector->vector[0]) / __pyx_v_scalar)); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":132 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":133 * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) * return result # <<<<<<<<<<<<<< @@ -4036,376 +4202,486 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_35__div__(PyObject *__pyx_v_x, P #endif /*!(#if PY_MAJOR_VERSION < 3)*/ /* Python wrapper */ -static void __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_1_phrase(PyObject *__pyx_self, PyObject *__pyx_v_phrase); /*proto*/ +static PyMethodDef __pyx_mdef_5_cdec_1_phrase = {__Pyx_NAMESTR("_phrase"), (PyCFunction)__pyx_pw_5_cdec_1_phrase, METH_O, __Pyx_DOCSTR(0)}; +static PyObject *__pyx_pw_5_cdec_1_phrase(PyObject *__pyx_self, PyObject *__pyx_v_phrase) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_10Hypergraph___dealloc__(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannySetupContext("_phrase (wrapper)", 0); + __pyx_self = __pyx_self; + __pyx_r = __pyx_pf_5_cdec__phrase(__pyx_self, ((PyObject *)__pyx_v_phrase)); __Pyx_RefNannyFinishContext(); + return __pyx_r; } +static PyObject *__pyx_gb_5_cdec_7_phrase_2generator17(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":8 - * cdef MT19937* rng - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.hg - * if self.rng != NULL: - */ - -static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":9 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":4 * - * def __dealloc__(self): - * del self.hg # <<<<<<<<<<<<<< - * if self.rng != NULL: - * del self.rng - */ - delete __pyx_v_self->hg; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":10 - * def __dealloc__(self): - * del self.hg - * if self.rng != NULL: # <<<<<<<<<<<<<< - * del self.rng + * def _phrase(phrase): + * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) # <<<<<<<<<<<<<< * + * cdef class NT: */ - __pyx_t_1 = (__pyx_v_self->rng != NULL); - if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":11 - * del self.hg - * if self.rng != NULL: - * del self.rng # <<<<<<<<<<<<<< - * - * def viterbi(self): - */ - delete __pyx_v_self->rng; - goto __pyx_L3; +static PyObject *__pyx_pf_5_cdec_7_phrase_genexpr(PyObject *__pyx_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("genexpr", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr *)__pyx_ptype_5_cdec___pyx_scope_struct_3_genexpr->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_3_genexpr, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase *) __pyx_self; + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7_phrase_2generator17, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; } - __pyx_L3:; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec._phrase.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_3viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_3viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; +static PyObject *__pyx_gb_5_cdec_7_phrase_2generator17(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("viterbi (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_2viterbi(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase)) { __Pyx_RaiseClosureNameError("phrase"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } + if (PyList_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase)) { + __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_w); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_w); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_cur_scope->__pyx_v_w = __pyx_t_4; + __pyx_t_4 = 0; + __pyx_t_5 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_5); + __pyx_t_6 = __Pyx_TypeCheck(__pyx_cur_scope->__pyx_v_w, __pyx_t_5); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_6) { + __pyx_t_5 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_w, __pyx_n_s__encode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_6), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_4 = __pyx_t_7; + __pyx_t_7 = 0; + } else { + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_w); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_cur_scope->__pyx_v_w); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_w); + __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __pyx_t_4 = __pyx_t_5; + __pyx_t_5 = 0; + } + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return __pyx_r; + return NULL; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":13 - * del self.rng +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":3 + * cimport grammar + * + * def _phrase(phrase): # <<<<<<<<<<<<<< + * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) * - * def viterbi(self): # <<<<<<<<<<<<<< - * cdef vector[WordID] trans - * hypergraph.ViterbiESentence(self.hg[0], &trans) */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { - std::vector __pyx_v_trans; +static PyObject *__pyx_pf_5_cdec__phrase(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_phrase) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("viterbi", 0); + __Pyx_RefNannySetupContext("_phrase", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase *)__pyx_ptype_5_cdec___pyx_scope_struct_2__phrase->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_2__phrase, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_phrase = __pyx_v_phrase; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_phrase); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_phrase); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":15 - * def viterbi(self): - * cdef vector[WordID] trans - * hypergraph.ViterbiESentence(self.hg[0], &trans) # <<<<<<<<<<<<<< - * return unicode(GetString(trans).c_str(), 'utf8') + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":4 * - */ - ViterbiESentence((__pyx_v_self->hg[0]), (&__pyx_v_trans)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":16 - * cdef vector[WordID] trans - * hypergraph.ViterbiESentence(self.hg[0], &trans) - * return unicode(GetString(trans).c_str(), 'utf8') # <<<<<<<<<<<<<< + * def _phrase(phrase): + * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) # <<<<<<<<<<<<<< * - * def viterbi_trees(self): + * cdef class NT: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(TD::GetString(__pyx_v_trans).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_7), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__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_t_2 = __pyx_pf_5_cdec_7_phrase_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 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", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec._phrase", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_5viterbi_trees(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_5viterbi_trees(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5_cdec_2NT_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_2NT_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_cat = 0; + PyObject *__pyx_v_ref = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__cat,&__pyx_n_s__ref,0}; + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("viterbi_trees (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_4viterbi_trees(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + values[1] = ((PyObject *)__pyx_int_0); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__cat); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ref); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_cat = values[0]; + __pyx_v_ref = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.NT.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_2NT___init__(((struct __pyx_obj_5_cdec_NT *)__pyx_v_self), __pyx_v_cat, __pyx_v_ref); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":18 - * return unicode(GetString(trans).c_str(), 'utf8') - * - * def viterbi_trees(self): # <<<<<<<<<<<<<< - * f_tree = unicode(hypergraph.ViterbiFTree(self.hg[0]).c_str(), 'utf8') - * e_tree = unicode(hypergraph.ViterbiETree(self.hg[0]).c_str(), 'utf8') +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":9 + * cdef public char* cat + * cdef public unsigned ref + * def __init__(self, cat, ref=0): # <<<<<<<<<<<<<< + * self.cat = cat + * self.ref = ref */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_4viterbi_trees(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { - PyObject *__pyx_v_f_tree = NULL; - PyObject *__pyx_v_e_tree = NULL; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5_cdec_2NT___init__(struct __pyx_obj_5_cdec_NT *__pyx_v_self, PyObject *__pyx_v_cat, PyObject *__pyx_v_ref) { + int __pyx_r; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; + char *__pyx_t_1; + unsigned int __pyx_t_2; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("viterbi_trees", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":19 - * - * def viterbi_trees(self): - * f_tree = unicode(hypergraph.ViterbiFTree(self.hg[0]).c_str(), 'utf8') # <<<<<<<<<<<<<< - * e_tree = unicode(hypergraph.ViterbiETree(self.hg[0]).c_str(), 'utf8') - * return (f_tree, e_tree) - */ - __pyx_t_1 = PyBytes_FromString(ViterbiFTree((__pyx_v_self->hg[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_v_f_tree = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; + __Pyx_RefNannySetupContext("__init__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":20 - * def viterbi_trees(self): - * f_tree = unicode(hypergraph.ViterbiFTree(self.hg[0]).c_str(), 'utf8') - * e_tree = unicode(hypergraph.ViterbiETree(self.hg[0]).c_str(), 'utf8') # <<<<<<<<<<<<<< - * return (f_tree, e_tree) + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":10 + * cdef public unsigned ref + * def __init__(self, cat, ref=0): + * self.cat = cat # <<<<<<<<<<<<<< + * self.ref = ref * */ - __pyx_t_1 = PyBytes_FromString(ViterbiETree((__pyx_v_self->hg[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_v_e_tree = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_1 = PyBytes_AsString(__pyx_v_cat); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->cat = __pyx_t_1; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":21 - * f_tree = unicode(hypergraph.ViterbiFTree(self.hg[0]).c_str(), 'utf8') - * e_tree = unicode(hypergraph.ViterbiETree(self.hg[0]).c_str(), 'utf8') - * return (f_tree, e_tree) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":11 + * def __init__(self, cat, ref=0): + * self.cat = cat + * self.ref = ref # <<<<<<<<<<<<<< * - * def viterbi_features(self): + * def __str__(self): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_f_tree)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_f_tree)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_f_tree)); - __Pyx_INCREF(((PyObject *)__pyx_v_e_tree)); - PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_e_tree)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_e_tree)); - __pyx_r = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - goto __pyx_L0; + __pyx_t_2 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_ref); if (unlikely((__pyx_t_2 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->ref = __pyx_t_2; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_cdec.Hypergraph.viterbi_trees", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("_cdec.NT.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_f_tree); - __Pyx_XDECREF(__pyx_v_e_tree); - __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_7viterbi_features(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_7viterbi_features(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5_cdec_2NT_3__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_2NT_3__str__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("viterbi_features (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_6viterbi_features(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_2NT_2__str__(((struct __pyx_obj_5_cdec_NT *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":23 - * return (f_tree, e_tree) +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":13 + * self.ref = ref * - * def viterbi_features(self): # <<<<<<<<<<<<<< - * cdef SparseVector fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) + * def __str__(self): # <<<<<<<<<<<<<< + * if self.ref > 0: + * return '[%s,%d]' % (self.cat, self.ref) */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_6viterbi_features(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { - struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap = 0; +static PyObject *__pyx_pf_5_cdec_2NT_2__str__(struct __pyx_obj_5_cdec_NT *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("viterbi_features", 0); + __Pyx_RefNannySetupContext("__str__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":24 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":14 * - * def viterbi_features(self): - * cdef SparseVector fmap = SparseVector() # <<<<<<<<<<<<<< - * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) - * return fmap + * def __str__(self): + * if self.ref > 0: # <<<<<<<<<<<<<< + * return '[%s,%d]' % (self.cat, self.ref) + * return '[%s]' % self.cat */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_1 = (__pyx_v_self->ref > 0); + if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":25 - * def viterbi_features(self): - * cdef SparseVector fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) # <<<<<<<<<<<<<< - * return fmap + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":15 + * def __str__(self): + * if self.ref > 0: + * return '[%s,%d]' % (self.cat, self.ref) # <<<<<<<<<<<<<< + * return '[%s]' % self.cat * */ - __pyx_v_fmap->vector = new FastSparseVector(ViterbiFeatures((__pyx_v_self->hg[0]))); + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyBytes_FromString(__pyx_v_self->cat); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_3 = PyLong_FromUnsignedLong(__pyx_v_self->ref); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_8), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_r = ((PyObject *)__pyx_t_3); + __pyx_t_3 = 0; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":26 - * cdef SparseVector fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) - * return fmap # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":16 + * if self.ref > 0: + * return '[%s,%d]' % (self.cat, self.ref) + * return '[%s]' % self.cat # <<<<<<<<<<<<<< * - * def viterbi_joshua(self): + * cdef class NTRef: */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_fmap)); - __pyx_r = ((PyObject *)__pyx_v_fmap); + __pyx_t_3 = PyBytes_FromString(__pyx_v_self->cat); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_r = ((PyObject *)__pyx_t_4); + __pyx_t_4 = 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.Hypergraph.viterbi_features", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec.NT.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_fmap); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_9viterbi_joshua(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_9viterbi_joshua(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5_cdec_2NT_3cat_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_2NT_3cat_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("viterbi_joshua (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_8viterbi_joshua(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_2NT_3cat___get__(((struct __pyx_obj_5_cdec_NT *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":28 - * return fmap - * - * def viterbi_joshua(self): # <<<<<<<<<<<<<< - * return unicode(hypergraph.JoshuaVisualizationString(self.hg[0]).c_str(), 'utf8') +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":7 * + * cdef class NT: + * cdef public char* cat # <<<<<<<<<<<<<< + * cdef public unsigned ref + * def __init__(self, cat, ref=0): */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_8viterbi_joshua(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_2NT_3cat___get__(struct __pyx_obj_5_cdec_NT *__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("viterbi_joshua", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":29 - * - * def viterbi_joshua(self): - * return unicode(hypergraph.JoshuaVisualizationString(self.hg[0]).c_str(), 'utf8') # <<<<<<<<<<<<<< - * - * def kbest(self, size): - */ + __Pyx_RefNannySetupContext("__get__", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(JoshuaVisualizationString((__pyx_v_self->hg[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(__pyx_v_self->cat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_r = __pyx_t_1; + __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; @@ -4413,1030 +4689,416 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_8viterbi_joshua(struct __pyx_obj_5 goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_cdec.Hypergraph.viterbi_joshua", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.NT.cat.__get__", __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_12generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_11kbest(PyObject *__pyx_v_self, PyObject *__pyx_v_size); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_11kbest(PyObject *__pyx_v_self, PyObject *__pyx_v_size) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5_cdec_2NT_3cat_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_5_cdec_2NT_3cat_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("kbest (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_10kbest(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_size)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_2NT_3cat_2__set__(((struct __pyx_obj_5_cdec_NT *)__pyx_v_self), ((PyObject *)__pyx_v_value)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":31 - * return unicode(hypergraph.JoshuaVisualizationString(self.hg[0]).c_str(), 'utf8') - * - * def kbest(self, size): # <<<<<<<<<<<<<< - * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal]* derivations = new kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal](self.hg[0], size) - * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal].Derivation* derivation - */ - -static PyObject *__pyx_pf_5_cdec_10Hypergraph_10kbest(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size) { - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *__pyx_cur_scope; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5_cdec_2NT_3cat_2__set__(struct __pyx_obj_5_cdec_NT *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; __Pyx_RefNannyDeclarations + char *__pyx_t_1; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("kbest", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)__pyx_ptype_5_cdec___pyx_scope_struct_2_kbest->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_2_kbest, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __pyx_cur_scope->__pyx_v_size = __pyx_v_size; - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_12generator2, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = PyBytes_AsString(__pyx_v_value); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->cat = __pyx_t_1; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Hypergraph.kbest", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("_cdec.NT.cat.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_10Hypergraph_12generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)__pyx_generator->closure); - 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; +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_2NT_3ref_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_2NT_3ref_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("None", 0); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L10_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[2]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":32 - * - * def kbest(self, size): - * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal]* derivations = new kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal](self.hg[0], size) # <<<<<<<<<<<<<< - * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal].Derivation* derivation - * cdef unsigned k - */ - __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[2]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,ESentenceTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":35 - * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal].Derivation* derivation - * cdef unsigned k - * try: # <<<<<<<<<<<<<< - * for k in range(size): - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - */ - /*try:*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":36 - * cdef unsigned k - * try: - * 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[2]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L5;} - for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { - __pyx_cur_scope->__pyx_v_k = __pyx_t_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":37 - * try: - * for k in range(size): - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< - * if not derivation: break - * yield unicode(GetString(derivation._yield).c_str(), 'utf8') - */ - __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_2NT_3ref___get__(((struct __pyx_obj_5_cdec_NT *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":38 - * for k in range(size): - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break # <<<<<<<<<<<<<< - * yield unicode(GetString(derivation._yield).c_str(), 'utf8') - * finally: +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":8 + * cdef class NT: + * cdef public char* cat + * cdef public unsigned ref # <<<<<<<<<<<<<< + * def __init__(self, cat, ref=0): + * self.cat = cat */ - __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0)); - if (__pyx_t_3) { - goto __pyx_L8_break; - goto __pyx_L9; - } - __pyx_L9:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":39 - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break - * yield unicode(GetString(derivation._yield).c_str(), 'utf8') # <<<<<<<<<<<<<< - * finally: - * 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[2]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L5;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L5;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_4)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L5;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 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_generator->resume_label = 1; - return __pyx_r; - __pyx_L10_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[2]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L5;} - } - __pyx_L8_break:; - } +static PyObject *__pyx_pf_5_cdec_2NT_3ref___get__(struct __pyx_obj_5_cdec_NT *__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("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyLong_FromUnsignedLong(__pyx_v_self->ref); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":41 - * yield unicode(GetString(derivation._yield).c_str(), 'utf8') - * finally: - * del derivations # <<<<<<<<<<<<<< - * - * def kbest_trees(self, size): - */ - /*finally:*/ { - int __pyx_why; - PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; - int __pyx_exc_lineno; - __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; - __pyx_why = 0; goto __pyx_L6; - __pyx_L5: { - __pyx_why = 4; - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); - __pyx_exc_lineno = __pyx_lineno; - goto __pyx_L6; - } - __pyx_L6:; - delete __pyx_cur_scope->__pyx_v_derivations; - switch (__pyx_why) { - case 4: { - __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); - __pyx_lineno = __pyx_exc_lineno; - __pyx_exc_type = 0; - __pyx_exc_value = 0; - __pyx_exc_tb = 0; - goto __pyx_L1_error; - } - } - } - PyErr_SetNone(PyExc_StopIteration); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); 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_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.NT.ref.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); - return NULL; + return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator3(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_14kbest_trees(PyObject *__pyx_v_self, PyObject *__pyx_v_size); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_14kbest_trees(PyObject *__pyx_v_self, PyObject *__pyx_v_size) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5_cdec_2NT_3ref_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_5_cdec_2NT_3ref_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("kbest_trees (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_13kbest_trees(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_size)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_2NT_3ref_2__set__(((struct __pyx_obj_5_cdec_NT *)__pyx_v_self), ((PyObject *)__pyx_v_value)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":43 - * del derivations - * - * def kbest_trees(self, size): # <<<<<<<<<<<<<< - * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal]* f_derivations = new kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal](self.hg[0], size) - * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal].Derivation* f_derivation - */ - -static PyObject *__pyx_pf_5_cdec_10Hypergraph_13kbest_trees(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size) { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *__pyx_cur_scope; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5_cdec_2NT_3ref_2__set__(struct __pyx_obj_5_cdec_NT *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; __Pyx_RefNannyDeclarations + unsigned int __pyx_t_1; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("kbest_trees", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *)__pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_trees->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_trees, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __pyx_cur_scope->__pyx_v_size = __pyx_v_size; - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_15generator3, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->ref = __pyx_t_1; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Hypergraph.kbest_trees", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("_cdec.NT.ref.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator3(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - unsigned int __pyx_t_1; - long __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; +/* Python wrapper */ +static int __pyx_pw_5_cdec_5NTRef_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_5NTRef_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_ref = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__ref,0}; + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("None", 0); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L10_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[2]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":44 - * - * def kbest_trees(self, size): - * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal]* f_derivations = new kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal](self.hg[0], size) # <<<<<<<<<<<<<< - * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal].Derivation* f_derivation - * cdef kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal]* e_derivations = new kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal](self.hg[0], size) - */ - __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[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_cur_scope->__pyx_v_f_derivations = new KBest::KBestDerivations,FTreeTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":46 - * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal]* f_derivations = new kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal](self.hg[0], size) - * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal].Derivation* f_derivation - * cdef kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal]* e_derivations = new kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal](self.hg[0], size) # <<<<<<<<<<<<<< - * cdef kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal].Derivation* e_derivation - * cdef unsigned k - */ - __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[2]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_cur_scope->__pyx_v_e_derivations = new KBest::KBestDerivations,ETreeTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":49 - * cdef kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal].Derivation* e_derivation - * cdef unsigned k - * try: # <<<<<<<<<<<<<< - * for k in range(size): - * f_derivation = f_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - */ - /*try:*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":50 - * cdef unsigned k - * try: - * for k in range(size): # <<<<<<<<<<<<<< - * f_derivation = f_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * e_derivation = e_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - */ - __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[2]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L5;} - for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { - __pyx_cur_scope->__pyx_v_k = __pyx_t_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":51 - * try: - * for k in range(size): - * f_derivation = f_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< - * e_derivation = e_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not f_derivation or not e_derivation: break - */ - __pyx_cur_scope->__pyx_v_f_derivation = __pyx_cur_scope->__pyx_v_f_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":52 - * for k in range(size): - * f_derivation = f_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * e_derivation = e_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< - * if not f_derivation or not e_derivation: break - * f_tree = unicode(GetString(f_derivation._yield).c_str(), 'utf8') - */ - __pyx_cur_scope->__pyx_v_e_derivation = __pyx_cur_scope->__pyx_v_e_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":53 - * f_derivation = f_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * e_derivation = e_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not f_derivation or not e_derivation: break # <<<<<<<<<<<<<< - * f_tree = unicode(GetString(f_derivation._yield).c_str(), 'utf8') - * e_tree = unicode(GetString(e_derivation._yield).c_str(), 'utf8') - */ - __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_f_derivation != 0)); - if (!__pyx_t_3) { - __pyx_t_4 = (!(__pyx_cur_scope->__pyx_v_e_derivation != 0)); - __pyx_t_5 = __pyx_t_4; - } else { - __pyx_t_5 = __pyx_t_3; + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; } - if (__pyx_t_5) { - goto __pyx_L8_break; - goto __pyx_L9; + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ref); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; } - __pyx_L9:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":54 - * e_derivation = e_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not f_derivation or not e_derivation: break - * f_tree = unicode(GetString(f_derivation._yield).c_str(), 'utf8') # <<<<<<<<<<<<<< - * e_tree = unicode(GetString(e_derivation._yield).c_str(), 'utf8') - * yield (f_tree, e_tree) - */ - __pyx_t_6 = PyBytes_FromString(TD::GetString(__pyx_cur_scope->__pyx_v_f_derivation->yield).c_str()); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L5;} - __Pyx_GOTREF(((PyObject *)__pyx_t_6)); - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L5;} - __Pyx_GOTREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_6)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_6)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_t_7, 1, ((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __pyx_t_6 = 0; - __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L5;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_f_tree)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_f_tree)); - __Pyx_GIVEREF(__pyx_t_6); - __pyx_cur_scope->__pyx_v_f_tree = ((PyObject*)__pyx_t_6); - __pyx_t_6 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":55 - * if not f_derivation or not e_derivation: break - * f_tree = unicode(GetString(f_derivation._yield).c_str(), 'utf8') - * e_tree = unicode(GetString(e_derivation._yield).c_str(), 'utf8') # <<<<<<<<<<<<<< - * yield (f_tree, e_tree) - * finally: - */ - __pyx_t_6 = PyBytes_FromString(TD::GetString(__pyx_cur_scope->__pyx_v_e_derivation->yield).c_str()); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L5;} - __Pyx_GOTREF(((PyObject *)__pyx_t_6)); - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L5;} - __Pyx_GOTREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_6)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_6)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_t_7, 1, ((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __pyx_t_6 = 0; - __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L5;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_e_tree)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_e_tree)); - __Pyx_GIVEREF(__pyx_t_6); - __pyx_cur_scope->__pyx_v_e_tree = ((PyObject*)__pyx_t_6); - __pyx_t_6 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 - * f_tree = unicode(GetString(f_derivation._yield).c_str(), 'utf8') - * e_tree = unicode(GetString(e_derivation._yield).c_str(), 'utf8') - * yield (f_tree, e_tree) # <<<<<<<<<<<<<< - * finally: - * del f_derivations - */ - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L5;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_f_tree)); - PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_cur_scope->__pyx_v_f_tree)); - __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_f_tree)); - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_e_tree)); - PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_cur_scope->__pyx_v_e_tree)); - __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_e_tree)); - __pyx_r = ((PyObject *)__pyx_t_6); - __pyx_t_6 = 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_generator->resume_label = 1; - return __pyx_r; - __pyx_L10_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[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L5;} + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 20; __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_L8_break:; + __pyx_v_ref = 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[2]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.NTRef.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_5NTRef___init__(((struct __pyx_obj_5_cdec_NTRef *)__pyx_v_self), __pyx_v_ref); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":58 - * yield (f_tree, e_tree) - * finally: - * del f_derivations # <<<<<<<<<<<<<< - * del e_derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":20 + * cdef class NTRef: + * cdef public unsigned ref + * def __init__(self, ref): # <<<<<<<<<<<<<< + * self.ref = ref * */ - /*finally:*/ { - int __pyx_why; - PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; - int __pyx_exc_lineno; - __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; - __pyx_why = 0; goto __pyx_L6; - __pyx_L5: { - __pyx_why = 4; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); - __pyx_exc_lineno = __pyx_lineno; - goto __pyx_L6; - } - __pyx_L6:; - delete __pyx_cur_scope->__pyx_v_f_derivations; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":59 - * finally: - * del f_derivations - * del e_derivations # <<<<<<<<<<<<<< +static int __pyx_pf_5_cdec_5NTRef___init__(struct __pyx_obj_5_cdec_NTRef *__pyx_v_self, PyObject *__pyx_v_ref) { + int __pyx_r; + __Pyx_RefNannyDeclarations + unsigned int __pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__init__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":21 + * cdef public unsigned ref + * def __init__(self, ref): + * self.ref = ref # <<<<<<<<<<<<<< * - * def kbest_features(self, size): + * def __str__(self): */ - delete __pyx_cur_scope->__pyx_v_e_derivations; - switch (__pyx_why) { - case 4: { - __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); - __pyx_lineno = __pyx_exc_lineno; - __pyx_exc_type = 0; - __pyx_exc_value = 0; - __pyx_exc_tb = 0; - goto __pyx_L1_error; - } - } - } - PyErr_SetNone(PyExc_StopIteration); + __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_ref); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->ref = __pyx_t_1; + + __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("kbest_trees", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.NTRef.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return NULL; + return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_17kbest_features(PyObject *__pyx_v_self, PyObject *__pyx_v_size); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_17kbest_features(PyObject *__pyx_v_self, PyObject *__pyx_v_size) { +static PyObject *__pyx_pw_5_cdec_5NTRef_3__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_5NTRef_3__str__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("kbest_features (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_16kbest_features(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_size)); + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_5NTRef_2__str__(((struct __pyx_obj_5_cdec_NTRef *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":61 - * del e_derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":23 + * self.ref = ref + * + * def __str__(self): # <<<<<<<<<<<<<< + * return '[%d]' % self.ref * - * def kbest_features(self, size): # <<<<<<<<<<<<<< - * cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal]* derivations = new kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal](self.hg[0], size) - * cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal].Derivation* derivation */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_16kbest_features(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size) { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_5NTRef_2__str__(struct __pyx_obj_5_cdec_NTRef *__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("kbest_features", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)__pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __pyx_cur_scope->__pyx_v_size = __pyx_v_size; - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_18generator4, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } + __Pyx_RefNannySetupContext("__str__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":24 + * + * def __str__(self): + * return '[%d]' % self.ref # <<<<<<<<<<<<<< + * + * cdef class BaseTRule: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyLong_FromUnsignedLong(__pyx_v_self->ref); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_10), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = ((PyObject *)__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_AddTraceback("_cdec.Hypergraph.kbest_features", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec.NTRef.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - unsigned int __pyx_t_1; - long __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_5NTRef_3ref_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_5NTRef_3ref_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("None", 0); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L10_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[2]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_5NTRef_3ref___get__(((struct __pyx_obj_5_cdec_NTRef *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":62 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":19 * - * def kbest_features(self, size): - * cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal]* derivations = new kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal](self.hg[0], size) # <<<<<<<<<<<<<< - * cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal].Derivation* derivation - * cdef SparseVector fmap - */ - __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[2]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,FeatureVectorTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":66 - * cdef SparseVector fmap - * cdef unsigned k - * try: # <<<<<<<<<<<<<< - * for k in range(size): - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - */ - /*try:*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":67 - * cdef unsigned k - * try: - * 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[2]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L5;} - for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { - __pyx_cur_scope->__pyx_v_k = __pyx_t_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":68 - * try: - * for k in range(size): - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< - * if not derivation: break - * fmap = SparseVector() - */ - __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":69 - * for k in range(size): - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break # <<<<<<<<<<<<<< - * fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](derivation._yield) - */ - __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0)); - if (__pyx_t_3) { - goto __pyx_L8_break; - goto __pyx_L9; - } - __pyx_L9:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":70 - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break - * fmap = SparseVector() # <<<<<<<<<<<<<< - * fmap.vector = new FastSparseVector[weight_t](derivation._yield) - * yield fmap - */ - __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L5;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_cur_scope->__pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_4); - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":71 - * if not derivation: break - * fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](derivation._yield) # <<<<<<<<<<<<<< - * yield fmap - * finally: + * cdef class NTRef: + * cdef public unsigned ref # <<<<<<<<<<<<<< + * def __init__(self, ref): + * self.ref = ref */ - __pyx_cur_scope->__pyx_v_fmap->vector = new FastSparseVector(__pyx_cur_scope->__pyx_v_derivation->yield); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":72 - * fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](derivation._yield) - * yield fmap # <<<<<<<<<<<<<< - * finally: - * del derivations - */ - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); - __pyx_r = ((PyObject *)__pyx_cur_scope->__pyx_v_fmap); - __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_generator->resume_label = 1; - return __pyx_r; - __pyx_L10_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[2]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L5;} - } - __pyx_L8_break:; - } +static PyObject *__pyx_pf_5_cdec_5NTRef_3ref___get__(struct __pyx_obj_5_cdec_NTRef *__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("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyLong_FromUnsignedLong(__pyx_v_self->ref); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":74 - * yield fmap - * finally: - * del derivations # <<<<<<<<<<<<<< - * - * def sample(self, unsigned n): - */ - /*finally:*/ { - int __pyx_why; - PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; - int __pyx_exc_lineno; - __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; - __pyx_why = 0; goto __pyx_L6; - __pyx_L5: { - __pyx_why = 4; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); - __pyx_exc_lineno = __pyx_lineno; - goto __pyx_L6; - } - __pyx_L6:; - delete __pyx_cur_scope->__pyx_v_derivations; - switch (__pyx_why) { - case 4: { - __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); - __pyx_lineno = __pyx_exc_lineno; - __pyx_exc_type = 0; - __pyx_exc_value = 0; - __pyx_exc_tb = 0; - goto __pyx_L1_error; - } - } - } - PyErr_SetNone(PyExc_StopIteration); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("kbest_features", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.NTRef.ref.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); - return NULL; + return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_20sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_20sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n) { - unsigned int __pyx_v_n; - PyObject *__pyx_r = 0; +static int __pyx_pw_5_cdec_5NTRef_3ref_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_5_cdec_5NTRef_3ref_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("sample (wrapper)", 0); - assert(__pyx_arg_n); { - __pyx_v_n = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_n); if (unlikely((__pyx_v_n == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __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_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_19sample(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((unsigned int)__pyx_v_n)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_5NTRef_3ref_2__set__(((struct __pyx_obj_5_cdec_NTRef *)__pyx_v_self), ((PyObject *)__pyx_v_value)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":76 - * del derivations - * - * def sample(self, unsigned n): # <<<<<<<<<<<<<< - * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() - * if self.rng == NULL: - */ - -static PyObject *__pyx_pf_5_cdec_10Hypergraph_19sample(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, unsigned int __pyx_v_n) { - struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *__pyx_cur_scope; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5_cdec_5NTRef_3ref_2__set__(struct __pyx_obj_5_cdec_NTRef *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; __Pyx_RefNannyDeclarations + unsigned int __pyx_t_1; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("sample", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)__pyx_ptype_5_cdec___pyx_scope_struct_5_sample->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_5_sample, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __pyx_cur_scope->__pyx_v_n = __pyx_v_n; - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_21generator5, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->ref = __pyx_t_1; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Hypergraph.sample", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("_cdec.NTRef.ref.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)__pyx_generator->closure); - 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; +/* Python wrapper */ +static void __pyx_pw_5_cdec_9BaseTRule_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_9BaseTRule_1__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("None", 0); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L10_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[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_9BaseTRule___dealloc__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":77 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":29 + * cdef shared_ptr[grammar.TRule]* rule + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.rule * - * def sample(self, unsigned n): - * 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(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":78 - * def sample(self, unsigned n): - * 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 = (__pyx_cur_scope->__pyx_v_self->rng == NULL); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":79 - * 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 unsigned k - */ - __pyx_cur_scope->__pyx_v_self->rng = new MT19937(); - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":80 - * if self.rng == NULL: - * self.rng = new MT19937() - * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) # <<<<<<<<<<<<<< - * cdef unsigned k - * try: - */ - HypergraphSampler::sample_hypotheses((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_cur_scope->__pyx_v_n, __pyx_cur_scope->__pyx_v_self->rng, __pyx_cur_scope->__pyx_v_hypos); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":82 - * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) - * cdef unsigned k - * try: # <<<<<<<<<<<<<< - * for k in range(hypos.size()): - * yield unicode(GetString(hypos[0][k].words).c_str(), 'utf8') - */ - /*try:*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":83 - * cdef unsigned k - * try: - * for k in range(hypos.size()): # <<<<<<<<<<<<<< - * yield unicode(GetString(hypos[0][k].words).c_str(), 'utf8') - * finally: */ - __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; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":84 - * try: - * for k in range(hypos.size()): - * yield unicode(GetString(hypos[0][k].words).c_str(), 'utf8') # <<<<<<<<<<<<<< - * finally: - * 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[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_4)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 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_generator->resume_label = 1; - return __pyx_r; - __pyx_L10_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[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} - } - } +static void __pyx_pf_5_cdec_9BaseTRule___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":86 - * yield unicode(GetString(hypos[0][k].words).c_str(), 'utf8') - * finally: - * del hypos # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":30 * - * def intersect(self, Lattice lat): + * def __dealloc__(self): + * del self.rule # <<<<<<<<<<<<<< + * + * property arity: */ - /*finally:*/ { - int __pyx_why; - PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; - int __pyx_exc_lineno; - __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; - __pyx_why = 0; goto __pyx_L7; - __pyx_L6: { - __pyx_why = 4; - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); - __pyx_exc_lineno = __pyx_lineno; - goto __pyx_L7; - } - __pyx_L7:; - delete __pyx_cur_scope->__pyx_v_hypos; - switch (__pyx_why) { - case 4: { - __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); - __pyx_lineno = __pyx_exc_lineno; - __pyx_exc_type = 0; - __pyx_exc_value = 0; - __pyx_exc_tb = 0; - goto __pyx_L1_error; - } - } - } - PyErr_SetNone(PyExc_StopIteration); - 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_generator->resume_label = -1; + delete __pyx_v_self->rule; + __Pyx_RefNannyFinishContext(); - return NULL; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_23intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_23intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat) { +static PyObject *__pyx_pw_5_cdec_9BaseTRule_5arity_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9BaseTRule_5arity_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("intersect (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lat), __pyx_ptype_5_cdec_Lattice, 1, "lat", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_22intersect(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_lat)); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9BaseTRule_5arity___get__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":88 - * del hypos +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":33 * - * def intersect(self, Lattice lat): # <<<<<<<<<<<<<< - * return hypergraph.Intersect(lat.lattice[0], self.hg) + * property arity: + * def __get__(self): # <<<<<<<<<<<<<< + * return self.rule.get().arity_ * */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_22intersect(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, struct __pyx_obj_5_cdec_Lattice *__pyx_v_lat) { +static PyObject *__pyx_pf_5_cdec_9BaseTRule_5arity___get__(struct __pyx_obj_5_cdec_BaseTRule *__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("intersect", 0); + __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":89 - * - * def intersect(self, Lattice lat): - * return hypergraph.Intersect(lat.lattice[0], self.hg) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":34 + * property arity: + * def __get__(self): + * return self.rule.get().arity_ # <<<<<<<<<<<<<< * - * def prune(self, beam_alpha=0, density=0, **kwargs): + * property f: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(HG::Intersect((__pyx_v_lat->lattice[0]), __pyx_v_self->hg)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->rule->get()->arity_); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -5446,7 +5108,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_22intersect(struct __pyx_obj_5_cde goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.Hypergraph.intersect", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.BaseTRule.arity.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -5455,423 +5117,682 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_22intersect(struct __pyx_obj_5_cde } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_25prune(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_25prune(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_beam_alpha = 0; - PyObject *__pyx_v_density = 0; - PyObject *__pyx_v_kwargs = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__beam_alpha,&__pyx_n_s__density,0}; +static PyObject *__pyx_pw_5_cdec_9BaseTRule_1f_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9BaseTRule_1f_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("prune (wrapper)", 0); - __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL; - __Pyx_GOTREF(__pyx_v_kwargs); - { - PyObject* values[2] = {0,0}; - values[0] = ((PyObject *)__pyx_int_0); - values[1] = ((PyObject *)__pyx_int_0); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__beam_alpha); - if (value) { values[0] = value; kw_args--; } - } - case 1: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__density); - if (value) { values[1] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "prune") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_beam_alpha = values[0]; - __pyx_v_density = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("prune", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; - __Pyx_AddTraceback("_cdec.Hypergraph.prune", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_24prune(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), __pyx_v_beam_alpha, __pyx_v_density, __pyx_v_kwargs); - __Pyx_XDECREF(__pyx_v_kwargs); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9BaseTRule_1f___get__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":91 - * return hypergraph.Intersect(lat.lattice[0], self.hg) +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":37 * - * def prune(self, beam_alpha=0, density=0, **kwargs): # <<<<<<<<<<<<<< - * cdef hypergraph.EdgeMask* preserve_mask = NULL - * if 'csplit_preserve_full_word' in kwargs: + * property f: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef vector[WordID]* f_ = &self.rule.get().f_ + * cdef WordID w */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_24prune(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_beam_alpha, PyObject *__pyx_v_density, PyObject *__pyx_v_kwargs) { - std::vector *__pyx_v_preserve_mask; +static PyObject *__pyx_pf_5_cdec_9BaseTRule_1f___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self) { + std::vector *__pyx_v_f_; + WordID __pyx_v_w; + PyObject *__pyx_v_f = 0; + unsigned int __pyx_v_i; + int __pyx_v_idx; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - int __pyx_t_1; - double __pyx_t_2; - double __pyx_t_3; + PyObject *__pyx_t_1 = NULL; + size_t __pyx_t_2; + unsigned int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("prune", 0); + __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":92 - * - * def prune(self, beam_alpha=0, density=0, **kwargs): - * cdef hypergraph.EdgeMask* preserve_mask = NULL # <<<<<<<<<<<<<< - * if 'csplit_preserve_full_word' in kwargs: - * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":38 + * property f: + * def __get__(self): + * cdef vector[WordID]* f_ = &self.rule.get().f_ # <<<<<<<<<<<<<< + * cdef WordID w + * cdef f = [] */ - __pyx_v_preserve_mask = NULL; + __pyx_v_f_ = (&__pyx_v_self->rule->get()->f_); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":93 - * def prune(self, beam_alpha=0, density=0, **kwargs): - * cdef hypergraph.EdgeMask* preserve_mask = NULL - * if 'csplit_preserve_full_word' in kwargs: # <<<<<<<<<<<<<< - * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) - * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":40 + * cdef vector[WordID]* f_ = &self.rule.get().f_ + * cdef WordID w + * cdef f = [] # <<<<<<<<<<<<<< + * cdef unsigned i + * cdef int idx = 0 */ - __pyx_t_1 = ((PyDict_Contains(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s_6)))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_1) { + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_f = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":94 - * cdef hypergraph.EdgeMask* preserve_mask = NULL - * if 'csplit_preserve_full_word' in kwargs: - * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) # <<<<<<<<<<<<<< - * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True - * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":42 + * cdef f = [] + * cdef unsigned i + * cdef int idx = 0 # <<<<<<<<<<<<<< + * for i in range(f_.size()): + * w = f_[0][i] */ - __pyx_v_preserve_mask = new std::vector(__pyx_v_self->hg->edges_.size()); + __pyx_v_idx = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":95 - * if 'csplit_preserve_full_word' in kwargs: - * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) - * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True # <<<<<<<<<<<<<< - * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) - * if preserve_mask: + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":43 + * cdef unsigned i + * cdef int idx = 0 + * for i in range(f_.size()): # <<<<<<<<<<<<<< + * w = f_[0][i] + * if w < 0: */ - ((__pyx_v_preserve_mask[0])[CompoundSplit::GetFullWordEdgeIndex((__pyx_v_self->hg[0]))]) = 1; - goto __pyx_L3; - } - __pyx_L3:; + __pyx_t_2 = __pyx_v_f_->size(); + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":96 - * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) - * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True - * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) # <<<<<<<<<<<<<< - * if preserve_mask: - * del preserve_mask + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":44 + * cdef int idx = 0 + * for i in range(f_.size()): + * w = f_[0][i] # <<<<<<<<<<<<<< + * if w < 0: + * idx += 1 */ - __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_beam_alpha); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_density); if (unlikely((__pyx_t_3 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->hg->PruneInsideOutside(__pyx_t_2, __pyx_t_3, __pyx_v_preserve_mask, 0, 1.0, 0); + __pyx_v_w = ((__pyx_v_f_[0])[__pyx_v_i]); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":97 - * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True - * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) - * if preserve_mask: # <<<<<<<<<<<<<< - * del preserve_mask - * + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":45 + * for i in range(f_.size()): + * w = f_[0][i] + * if w < 0: # <<<<<<<<<<<<<< + * idx += 1 + * f.append(NT(TDConvert(-w), idx)) */ - __pyx_t_1 = (__pyx_v_preserve_mask != 0); - if (__pyx_t_1) { + __pyx_t_4 = (__pyx_v_w < 0); + if (__pyx_t_4) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":98 - * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) - * if preserve_mask: - * del preserve_mask # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":46 + * w = f_[0][i] + * if w < 0: + * idx += 1 # <<<<<<<<<<<<<< + * f.append(NT(TDConvert(-w), idx)) + * else: + */ + __pyx_v_idx = (__pyx_v_idx + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":47 + * if w < 0: + * idx += 1 + * f.append(NT(TDConvert(-w), idx)) # <<<<<<<<<<<<<< + * else: + * f.append(unicode(TDConvert(w), encoding='utf8')) + */ + __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_w))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_5 = PyInt_FromLong(__pyx_v_idx); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_1 = 0; + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NT)), ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyObject_Append(__pyx_v_f, __pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":49 + * f.append(NT(TDConvert(-w), idx)) + * else: + * f.append(unicode(TDConvert(w), encoding='utf8')) # <<<<<<<<<<<<<< + * return f * - * def lattice(self): # TODO direct hg -> lattice conversion in cdec */ - delete __pyx_v_preserve_mask; - goto __pyx_L4; + __pyx_t_6 = PyBytes_FromString(TD::Convert(__pyx_v_w)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_6)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_6)); + __pyx_t_6 = 0; + __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + if (PyDict_SetItem(__pyx_t_6, ((PyObject *)__pyx_n_s__encoding), ((PyObject *)__pyx_n_s__utf8)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_5), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyObject_Append(__pyx_v_f, __pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __pyx_L5:; } - __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":50 + * else: + * f.append(unicode(TDConvert(w), encoding='utf8')) + * return f # <<<<<<<<<<<<<< + * + * def __set__(self, f): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_f); + __pyx_r = __pyx_v_f; + goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Hypergraph.prune", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_cdec.BaseTRule.f.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_27lattice(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_27lattice(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5_cdec_9BaseTRule_1f_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_f); /*proto*/ +static int __pyx_pw_5_cdec_9BaseTRule_1f_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_f) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("lattice (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_26lattice(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9BaseTRule_1f_2__set__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self), ((PyObject *)__pyx_v_f)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":100 - * del preserve_mask +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":52 + * return f * - * def lattice(self): # TODO direct hg -> lattice conversion in cdec # <<<<<<<<<<<<<< - * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() - * return Lattice(eval(plf)) + * def __set__(self, f): # <<<<<<<<<<<<<< + * cdef vector[WordID]* f_ = &self.rule.get().f_ + * f_.resize(len(f)) */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_26lattice(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { - PyObject *__pyx_v_plf = 0; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5_cdec_9BaseTRule_1f_2__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_f) { + std::vector *__pyx_v_f_; + unsigned int __pyx_v_i; + CYTHON_UNUSED int __pyx_v_idx; + int __pyx_r; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_1; + unsigned int __pyx_t_2; PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + char *__pyx_t_6; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("lattice", 0); + __Pyx_RefNannySetupContext("__set__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":101 - * - * def lattice(self): # TODO direct hg -> lattice conversion in cdec - * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() # <<<<<<<<<<<<<< - * return Lattice(eval(plf)) + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":53 * + * def __set__(self, f): + * cdef vector[WordID]* f_ = &self.rule.get().f_ # <<<<<<<<<<<<<< + * f_.resize(len(f)) + * cdef unsigned i */ - __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->hg[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 101; __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[2]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_plf = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_v_f_ = (&__pyx_v_self->rule->get()->f_); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":102 - * def lattice(self): # TODO direct hg -> lattice conversion in cdec - * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() - * return Lattice(eval(plf)) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":54 + * def __set__(self, f): + * cdef vector[WordID]* f_ = &self.rule.get().f_ + * f_.resize(len(f)) # <<<<<<<<<<<<<< + * cdef unsigned i + * cdef int idx = 0 + */ + __pyx_t_1 = PyObject_Length(__pyx_v_f); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_f_->resize(__pyx_t_1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":56 + * f_.resize(len(f)) + * cdef unsigned i + * cdef int idx = 0 # <<<<<<<<<<<<<< + * for i in range(len(f)): + * if isinstance(f[i], NT): + */ + __pyx_v_idx = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":57 + * cdef unsigned i + * cdef int idx = 0 + * for i in range(len(f)): # <<<<<<<<<<<<<< + * if isinstance(f[i], NT): + * f_[0][i] = -TDConvert(f[i].cat) + */ + __pyx_t_1 = PyObject_Length(__pyx_v_f); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_v_i = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":58 + * cdef int idx = 0 + * for i in range(len(f)): + * if isinstance(f[i], NT): # <<<<<<<<<<<<<< + * f_[0][i] = -TDConvert(f[i].cat) + * else: + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_f, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NT)); + __Pyx_INCREF(__pyx_t_4); + __pyx_t_5 = __Pyx_TypeCheck(__pyx_t_3, __pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":59 + * for i in range(len(f)): + * if isinstance(f[i], NT): + * f_[0][i] = -TDConvert(f[i].cat) # <<<<<<<<<<<<<< + * else: + * f_[0][i] = TDConvert(as_str(f[i])) + */ + __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_f, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__cat); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = PyBytes_AsString(__pyx_t_3); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + ((__pyx_v_f_[0])[__pyx_v_i]) = (-TD::Convert(((char *)__pyx_t_6))); + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":61 + * f_[0][i] = -TDConvert(f[i].cat) + * else: + * f_[0][i] = TDConvert(as_str(f[i])) # <<<<<<<<<<<<<< * - * def reweight(self, weights): + * property e: */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_Globals(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - if (((PyObject *)__pyx_v_plf)) { - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__plf), ((PyObject *)__pyx_v_plf)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - if (((PyObject *)__pyx_v_self)) { - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_v_self)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_f, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + ((__pyx_v_f_[0])[__pyx_v_i]) = TD::Convert(((char *)__pyx_f_5_cdec_as_str(__pyx_t_3, NULL))); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __pyx_L5:; } - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_v_plf)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_plf)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_plf)); - PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_t_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_eval, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec.Hypergraph.lattice", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec.BaseTRule.f.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_plf); - __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_29reweight(PyObject *__pyx_v_self, PyObject *__pyx_v_weights); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_29reweight(PyObject *__pyx_v_self, PyObject *__pyx_v_weights) { +static PyObject *__pyx_pw_5_cdec_9BaseTRule_1e_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9BaseTRule_1e_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("reweight (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_28reweight(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_weights)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9BaseTRule_1e___get__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":104 - * return Lattice(eval(plf)) +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":64 * - * def reweight(self, weights): # <<<<<<<<<<<<<< - * if isinstance(weights, SparseVector): - * self.hg.Reweight(( weights).vector[0]) + * property e: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef vector[WordID]* e_ = &self.rule.get().e_ + * cdef WordID w */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_weights) { +static PyObject *__pyx_pf_5_cdec_9BaseTRule_1e___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self) { + std::vector *__pyx_v_e_; + WordID __pyx_v_w; + PyObject *__pyx_v_e = 0; + unsigned int __pyx_v_i; + int __pyx_v_idx; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; + size_t __pyx_t_2; + unsigned int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("reweight", 0); + __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":105 - * - * def reweight(self, weights): - * if isinstance(weights, SparseVector): # <<<<<<<<<<<<<< - * self.hg.Reweight(( weights).vector[0]) - * elif isinstance(weights, DenseVector): + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":65 + * property e: + * def __get__(self): + * cdef vector[WordID]* e_ = &self.rule.get().e_ # <<<<<<<<<<<<<< + * cdef WordID w + * cdef e = [] */ - __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { + __pyx_v_e_ = (&__pyx_v_self->rule->get()->e_); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":106 - * def reweight(self, weights): - * if isinstance(weights, SparseVector): - * self.hg.Reweight(( weights).vector[0]) # <<<<<<<<<<<<<< - * elif isinstance(weights, DenseVector): - * self.hg.Reweight(( weights).vector[0]) + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":67 + * cdef vector[WordID]* e_ = &self.rule.get().e_ + * cdef WordID w + * cdef e = [] # <<<<<<<<<<<<<< + * cdef unsigned i + * cdef int idx = 0 */ - __pyx_v_self->hg->Reweight((((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_weights)->vector[0])); - goto __pyx_L3; - } + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_e = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":107 - * if isinstance(weights, SparseVector): - * self.hg.Reweight(( weights).vector[0]) - * elif isinstance(weights, DenseVector): # <<<<<<<<<<<<<< - * self.hg.Reweight(( weights).vector[0]) - * else: + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":69 + * cdef e = [] + * cdef unsigned i + * cdef int idx = 0 # <<<<<<<<<<<<<< + * for i in range(e_.size()): + * w = e_[0][i] */ - __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { + __pyx_v_idx = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":108 - * self.hg.Reweight(( weights).vector[0]) - * elif isinstance(weights, DenseVector): - * self.hg.Reweight(( weights).vector[0]) # <<<<<<<<<<<<<< - * else: - * raise TypeError('cannot reweight hypergraph with %s' % type(weights)) + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":70 + * cdef unsigned i + * cdef int idx = 0 + * for i in range(e_.size()): # <<<<<<<<<<<<<< + * w = e_[0][i] + * if w < 1: */ - __pyx_v_self->hg->Reweight((((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_weights)->vector[0])); - goto __pyx_L3; - } - /*else*/ { + __pyx_t_2 = __pyx_v_e_->size(); + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":110 - * self.hg.Reweight(( weights).vector[0]) - * else: - * raise TypeError('cannot reweight hypergraph with %s' % type(weights)) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":71 + * cdef int idx = 0 + * for i in range(e_.size()): + * w = e_[0][i] # <<<<<<<<<<<<<< + * if w < 1: + * idx += 1 + */ + __pyx_v_w = ((__pyx_v_e_[0])[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":72 + * for i in range(e_.size()): + * w = e_[0][i] + * if w < 1: # <<<<<<<<<<<<<< + * idx += 1 + * e.append(NTRef(1-w)) + */ + __pyx_t_4 = (__pyx_v_w < 1); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":73 + * w = e_[0][i] + * if w < 1: + * idx += 1 # <<<<<<<<<<<<<< + * e.append(NTRef(1-w)) + * else: + */ + __pyx_v_idx = (__pyx_v_idx + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":74 + * if w < 1: + * idx += 1 + * e.append(NTRef(1-w)) # <<<<<<<<<<<<<< + * else: + * e.append(unicode(TDConvert(w), encoding='utf8')) + */ + __pyx_t_1 = PyInt_FromLong((1 - __pyx_v_w)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NTRef)), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_e, __pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":76 + * e.append(NTRef(1-w)) + * else: + * e.append(unicode(TDConvert(w), encoding='utf8')) # <<<<<<<<<<<<<< + * return e * - * # TODO get feature expectations, get partition function ("inside" score) */ - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_7), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyBytes_FromString(TD::Convert(__pyx_v_w)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_5)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); + __pyx_t_5 = 0; + __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__encoding), ((PyObject *)__pyx_n_s__utf8)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_e, __pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __pyx_L5:; } - __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":77 + * else: + * e.append(unicode(TDConvert(w), encoding='utf8')) + * return e # <<<<<<<<<<<<<< + * + * def __set__(self, e): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_e); + __pyx_r = __pyx_v_e; + 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_3); - __Pyx_AddTraceback("_cdec.Hypergraph.reweight", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_cdec.BaseTRule.e.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_e); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_10Hypergraph_5edges_2generator6(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_5edges_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_5edges_1__get__(PyObject *__pyx_v_self) { +static int __pyx_pw_5_cdec_9BaseTRule_1e_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_e); /*proto*/ +static int __pyx_pw_5_cdec_9BaseTRule_1e_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_e) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9BaseTRule_1e_2__set__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self), ((PyObject *)__pyx_v_e)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":79 + * return e + * + * def __set__(self, e): # <<<<<<<<<<<<<< + * cdef vector[WordID]* e_ = &self.rule.get().e_ + * e_.resize(len(e)) + */ + +static int __pyx_pf_5_cdec_9BaseTRule_1e_2__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_e) { + std::vector *__pyx_v_e_; + unsigned int __pyx_v_i; + int __pyx_r; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + WordID __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":80 + * + * def __set__(self, e): + * cdef vector[WordID]* e_ = &self.rule.get().e_ # <<<<<<<<<<<<<< + * e_.resize(len(e)) + * cdef unsigned i + */ + __pyx_v_e_ = (&__pyx_v_self->rule->get()->e_); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":81 + * def __set__(self, e): + * cdef vector[WordID]* e_ = &self.rule.get().e_ + * e_.resize(len(e)) # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(len(e)): + */ + __pyx_t_1 = PyObject_Length(__pyx_v_e); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_e_->resize(__pyx_t_1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":83 + * e_.resize(len(e)) + * cdef unsigned i + * for i in range(len(e)): # <<<<<<<<<<<<<< + * if isinstance(e[i], NTRef): + * e_[0][i] = 1-e[i].ref + */ + __pyx_t_1 = PyObject_Length(__pyx_v_e); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_v_i = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":84 + * cdef unsigned i + * for i in range(len(e)): + * if isinstance(e[i], NTRef): # <<<<<<<<<<<<<< + * e_[0][i] = 1-e[i].ref + * else: + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_e, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NTRef)); + __Pyx_INCREF(__pyx_t_4); + __pyx_t_5 = __Pyx_TypeCheck(__pyx_t_3, __pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":85 + * for i in range(len(e)): + * if isinstance(e[i], NTRef): + * e_[0][i] = 1-e[i].ref # <<<<<<<<<<<<<< + * else: + * e_[0][i] = TDConvert(as_str(e[i])) + */ + __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_e, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__ref); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyNumber_Subtract(__pyx_int_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyInt_from_py_WordID(__pyx_t_4); if (unlikely((__pyx_t_6 == (WordID)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + ((__pyx_v_e_[0])[__pyx_v_i]) = __pyx_t_6; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":87 + * e_[0][i] = 1-e[i].ref + * else: + * e_[0][i] = TDConvert(as_str(e[i])) # <<<<<<<<<<<<<< + * + * property a: + */ + __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_e, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + ((__pyx_v_e_[0])[__pyx_v_i]) = TD::Convert(((char *)__pyx_f_5_cdec_as_str(__pyx_t_4, NULL))); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __pyx_L5:; + } + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec.BaseTRule.e.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_5_cdec_9BaseTRule_1a_2generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_9BaseTRule_1a_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9BaseTRule_1a_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_5edges___get__(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_9BaseTRule_1a___get__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":115 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":90 * - * property edges: + * property a: * def __get__(self): # <<<<<<<<<<<<<< * cdef unsigned i - * for i in range(self.hg.edges_.size()): + * cdef vector[grammar.AlignmentPoint]* a = &self.rule.get().a_ */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_5edges___get__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_9BaseTRule_1a___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *)__pyx_ptype_5_cdec___pyx_scope_struct_6___get__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_6___get__, __pyx_empty_tuple, NULL); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ *)__pyx_ptype_5_cdec___pyx_scope_struct_4___get__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_4___get__, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -5881,7 +5802,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_5edges___get__(struct __pyx_obj_5_ __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_5edges_2generator6, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_9BaseTRule_1a_2generator2, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -5890,7 +5811,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_5edges___get__(struct __pyx_obj_5_ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Hypergraph.edges.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.BaseTRule.a.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); @@ -5899,14 +5820,15 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_5edges___get__(struct __pyx_obj_5_ return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_10Hypergraph_5edges_2generator6(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_9BaseTRule_1a_2generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *)__pyx_generator->closure); + struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; size_t __pyx_t_1; unsigned int __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { @@ -5917,33 +5839,49 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_5edges_2generator6(__pyx_Generator return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":117 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":92 * def __get__(self): * cdef unsigned i - * for i in range(self.hg.edges_.size()): # <<<<<<<<<<<<<< - * yield HypergraphEdge().init(self.hg, i) + * cdef vector[grammar.AlignmentPoint]* a = &self.rule.get().a_ # <<<<<<<<<<<<<< + * for i in range(a.size()): + * yield (a[0][i].s_, a[0][i].t_) + */ + __pyx_cur_scope->__pyx_v_a = (&__pyx_cur_scope->__pyx_v_self->rule->get()->a_); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":93 + * cdef unsigned i + * cdef vector[grammar.AlignmentPoint]* a = &self.rule.get().a_ + * for i in range(a.size()): # <<<<<<<<<<<<<< + * yield (a[0][i].s_, a[0][i].t_) * */ - __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->hg->edges_.size(); + __pyx_t_1 = __pyx_cur_scope->__pyx_v_a->size(); for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":118 - * cdef unsigned i - * for i in range(self.hg.edges_.size()): - * yield HypergraphEdge().init(self.hg, i) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":94 + * cdef vector[grammar.AlignmentPoint]* a = &self.rule.get().a_ + * for i in range(a.size()): + * yield (a[0][i].s_, a[0][i].t_) # <<<<<<<<<<<<<< * - * property nodes: + * def __set__(self, a): */ - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphEdge)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(((__pyx_cur_scope->__pyx_v_a[0])[__pyx_cur_scope->__pyx_v_i]).s_); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = ((struct __pyx_vtabstruct_5_cdec_HypergraphEdge *)((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_t_3)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_t_3), __pyx_cur_scope->__pyx_v_self->hg, __pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(((__pyx_cur_scope->__pyx_v_a[0])[__pyx_cur_scope->__pyx_v_i]).t_); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_4; + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_3 = 0; __pyx_t_4 = 0; + __pyx_r = ((PyObject *)__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); @@ -5954,13 +5892,14 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_5edges_2generator6(__pyx_Generator __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[2]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; __Pyx_XDECREF(__pyx_r); @@ -5968,460 +5907,488 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_5edges_2generator6(__pyx_Generator __Pyx_RefNannyFinishContext(); return NULL; } -static PyObject *__pyx_gb_5_cdec_10Hypergraph_5nodes_2generator7(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_5nodes_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_5nodes_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5_cdec_9BaseTRule_1a_4__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_a); /*proto*/ +static int __pyx_pw_5_cdec_9BaseTRule_1a_4__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_a) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_5nodes___get__(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9BaseTRule_1a_3__set__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self), ((PyObject *)__pyx_v_a)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":121 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":96 + * yield (a[0][i].s_, a[0][i].t_) * - * property nodes: - * def __get__(self): # <<<<<<<<<<<<<< - * cdef unsigned i - * for i in range(self.hg.nodes_.size()): + * def __set__(self, a): # <<<<<<<<<<<<<< + * cdef vector[grammar.AlignmentPoint]* a_ = &self.rule.get().a_ + * a_.resize(len(a)) */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_5nodes___get__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *__pyx_cur_scope; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5_cdec_9BaseTRule_1a_3__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_a) { + std::vector *__pyx_v_a_; + unsigned int __pyx_v_i; + int __pyx_v_s; + int __pyx_v_t; + int __pyx_r; __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *(*__pyx_t_7)(PyObject *); + int __pyx_t_8; + int __pyx_t_9; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *)__pyx_ptype_5_cdec___pyx_scope_struct_7___get__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_7___get__, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_5nodes_2generator7, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } + __Pyx_RefNannySetupContext("__set__", 0); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Hypergraph.nodes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":97 + * + * def __set__(self, a): + * cdef vector[grammar.AlignmentPoint]* a_ = &self.rule.get().a_ # <<<<<<<<<<<<<< + * a_.resize(len(a)) + * cdef unsigned i + */ + __pyx_v_a_ = (&__pyx_v_self->rule->get()->a_); -static PyObject *__pyx_gb_5_cdec_10Hypergraph_5nodes_2generator7(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - size_t __pyx_t_1; - unsigned int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("None", 0); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_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[2]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":98 + * def __set__(self, a): + * cdef vector[grammar.AlignmentPoint]* a_ = &self.rule.get().a_ + * a_.resize(len(a)) # <<<<<<<<<<<<<< + * cdef unsigned i + * cdef int s, t + */ + __pyx_t_1 = PyObject_Length(__pyx_v_a); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_a_->resize(__pyx_t_1); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":123 - * def __get__(self): + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":101 * cdef unsigned i - * for i in range(self.hg.nodes_.size()): # <<<<<<<<<<<<<< - * yield HypergraphNode().init(self.hg, i) - * + * cdef int s, t + * for i in range(len(a)): # <<<<<<<<<<<<<< + * s, t = a[i] + * a_[0][i] = grammar.AlignmentPoint(s, t) */ - __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->hg->nodes_.size(); + __pyx_t_1 = PyObject_Length(__pyx_v_a); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + __pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":124 - * cdef unsigned i - * for i in range(self.hg.nodes_.size()): - * yield HypergraphNode().init(self.hg, i) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":102 + * cdef int s, t + * for i in range(len(a)): + * s, t = a[i] # <<<<<<<<<<<<<< + * a_[0][i] = grammar.AlignmentPoint(s, t) * - * property goal: */ - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_a, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = ((struct __pyx_vtabstruct_5_cdec_HypergraphNode *)((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_3)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_3), __pyx_cur_scope->__pyx_v_self->hg, __pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 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_generator->resume_label = 1; - return __pyx_r; - __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[2]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { + PyObject* sequence = __pyx_t_3; + if (likely(PyTuple_CheckExact(sequence))) { + 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[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_4 = PyList_GET_ITEM(sequence, 0); + __pyx_t_5 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_6 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_7 = Py_TYPE(__pyx_t_6)->tp_iternext; + index = 0; __pyx_t_4 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_4)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_4); + index = 1; __pyx_t_5 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_5)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L6_unpacking_done; + __pyx_L5_unpacking_failed:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L6_unpacking_done:; + } + __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_5); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_s = __pyx_t_8; + __pyx_v_t = __pyx_t_9; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":103 + * for i in range(len(a)): + * s, t = a[i] + * a_[0][i] = grammar.AlignmentPoint(s, t) # <<<<<<<<<<<<<< + * + * property scores: + */ + ((__pyx_v_a_[0])[__pyx_v_i]) = AlignmentPoint(__pyx_v_s, __pyx_v_t); } - PyErr_SetNone(PyExc_StopIteration); + + __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_cdec.BaseTRule.a.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return NULL; + return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_4goal_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_4goal_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_9BaseTRule_6scores_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9BaseTRule_6scores_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_4goal___get__(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_9BaseTRule_6scores___get__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":127 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":106 * - * property goal: + * property scores: * def __get__(self): # <<<<<<<<<<<<<< - * return HypergraphNode().init(self.hg, self.hg.GoalNode()) - * + * cdef SparseVector scores = SparseVector() + * scores.vector = new FastSparseVector[double](self.rule.get().scores_) */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_4goal___get__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_9BaseTRule_6scores___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_scores = 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("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":128 - * property goal: + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":107 + * property scores: * def __get__(self): - * return HypergraphNode().init(self.hg, self.hg.GoalNode()) # <<<<<<<<<<<<<< + * cdef SparseVector scores = SparseVector() # <<<<<<<<<<<<<< + * scores.vector = new FastSparseVector[double](self.rule.get().scores_) + * return scores + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_scores = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":108 + * def __get__(self): + * cdef SparseVector scores = SparseVector() + * scores.vector = new FastSparseVector[double](self.rule.get().scores_) # <<<<<<<<<<<<<< + * return scores * + */ + __pyx_v_scores->vector = new FastSparseVector(__pyx_v_self->rule->get()->scores_); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":109 + * cdef SparseVector scores = SparseVector() + * scores.vector = new FastSparseVector[double](self.rule.get().scores_) + * return scores # <<<<<<<<<<<<<< * + * def __set__(self, scores): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = ((struct __pyx_vtabstruct_5_cdec_HypergraphNode *)((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_1)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_1), __pyx_v_self->hg, __pyx_v_self->hg->GoalNode()); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 128; __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; + __Pyx_INCREF(((PyObject *)__pyx_v_scores)); + __pyx_r = ((PyObject *)__pyx_v_scores); 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.goal.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.BaseTRule.scores.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_scores); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_1_phrase(PyObject *__pyx_self, PyObject *__pyx_v_phrase); /*proto*/ -static PyMethodDef __pyx_mdef_5_cdec_1_phrase = {__Pyx_NAMESTR("_phrase"), (PyCFunction)__pyx_pw_5_cdec_1_phrase, METH_O, __Pyx_DOCSTR(0)}; -static PyObject *__pyx_pw_5_cdec_1_phrase(PyObject *__pyx_self, PyObject *__pyx_v_phrase) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5_cdec_9BaseTRule_6scores_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_scores); /*proto*/ +static int __pyx_pw_5_cdec_9BaseTRule_6scores_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_scores) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_phrase (wrapper)", 0); - __pyx_self = __pyx_self; - __pyx_r = __pyx_pf_5_cdec__phrase(__pyx_self, ((PyObject *)__pyx_v_phrase)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9BaseTRule_6scores_2__set__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self), ((PyObject *)__pyx_v_scores)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_7_phrase_2generator15(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ -/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":2 - * def _phrase(phrase): - * return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) # <<<<<<<<<<<<<< +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":111 + * return scores * - * cdef class TRule: + * def __set__(self, scores): # <<<<<<<<<<<<<< + * cdef FastSparseVector[double]* scores_ = &self.rule.get().scores_ + * scores_.clear() */ -static PyObject *__pyx_pf_5_cdec_7_phrase_genexpr(PyObject *__pyx_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *__pyx_cur_scope; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5_cdec_9BaseTRule_6scores_2__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_scores) { + FastSparseVector *__pyx_v_scores_; + int __pyx_v_fid; + float __pyx_v_fval; + PyObject *__pyx_v_fname = NULL; + int __pyx_r; __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *(*__pyx_t_4)(PyObject *); + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *(*__pyx_t_8)(PyObject *); + float __pyx_t_9; + int __pyx_t_10; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("genexpr", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *)__pyx_ptype_5_cdec___pyx_scope_struct_9_genexpr->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_9_genexpr, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *) __pyx_self; - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7_phrase_2generator15, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } + __Pyx_RefNannySetupContext("__set__", 0); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec._phrase.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":112 + * + * def __set__(self, scores): + * cdef FastSparseVector[double]* scores_ = &self.rule.get().scores_ # <<<<<<<<<<<<<< + * scores_.clear() + * cdef int fid + */ + __pyx_v_scores_ = (&__pyx_v_self->rule->get()->scores_); -static PyObject *__pyx_gb_5_cdec_7_phrase_2generator15(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *(*__pyx_t_3)(PyObject *); - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("None", 0); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_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[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase)) { __Pyx_RaiseClosureNameError("phrase"); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - if (PyList_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase)) { - __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; - __pyx_t_3 = NULL; + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":113 + * def __set__(self, scores): + * cdef FastSparseVector[double]* scores_ = &self.rule.get().scores_ + * scores_.clear() # <<<<<<<<<<<<<< + * cdef int fid + * cdef float fval + */ + __pyx_v_scores_->clear(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":116 + * cdef int fid + * cdef float fval + * for fname, fval in scores.items(): # <<<<<<<<<<<<<< + * fid = FDConvert(as_str(fname)) + * if fid < 0: raise KeyError(fname) + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_scores, __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0; + __pyx_t_4 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; + __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { - if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; - } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; } else { - __pyx_t_4 = __pyx_t_3(__pyx_t_1); - if (unlikely(!__pyx_t_4)) { + __pyx_t_2 = __pyx_t_4(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } - __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_2); } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_w); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_w); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_cur_scope->__pyx_v_w = __pyx_t_4; - __pyx_t_4 = 0; - __pyx_t_5 = ((PyObject *)((PyObject*)(&PyTuple_Type))); - __Pyx_INCREF(__pyx_t_5); - __pyx_t_6 = __Pyx_TypeCheck(__pyx_cur_scope->__pyx_v_w, __pyx_t_5); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_6) { - __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_8), __pyx_cur_scope->__pyx_v_w); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __pyx_t_4 = ((PyObject *)__pyx_t_5); - __pyx_t_5 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + if (likely(PyTuple_CheckExact(sequence))) { + 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[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_5 = PyList_GET_ITEM(sequence, 0); + __pyx_t_6 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { - __pyx_t_5 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_w, __pyx_n_s__encode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_4 = __pyx_t_7; - __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_5 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L6_unpacking_done; + __pyx_L5_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L6_unpacking_done:; } - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - __Pyx_XGIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L6_resume_from_yield:; - __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; - __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; - __Pyx_RefNannyFinishContext(); - return NULL; -} + __pyx_t_9 = __pyx_PyFloat_AsFloat(__pyx_t_6); if (unlikely((__pyx_t_9 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_v_fname); + __pyx_v_fname = __pyx_t_5; + __pyx_t_5 = 0; + __pyx_v_fval = __pyx_t_9; -/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":1 - * def _phrase(phrase): # <<<<<<<<<<<<<< - * return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) - * + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":117 + * cdef float fval + * for fname, fval in scores.items(): + * fid = FDConvert(as_str(fname)) # <<<<<<<<<<<<<< + * if fid < 0: raise KeyError(fname) + * scores_.set_value(fid, fval) */ + __pyx_v_fid = FD::Convert(((char *)__pyx_f_5_cdec_as_str(__pyx_v_fname, NULL))); -static PyObject *__pyx_pf_5_cdec__phrase(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_phrase) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *__pyx_cur_scope; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_phrase", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *)__pyx_ptype_5_cdec___pyx_scope_struct_8__phrase->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_8__phrase, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_v_phrase = __pyx_v_phrase; - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_phrase); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_phrase); + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":118 + * for fname, fval in scores.items(): + * fid = FDConvert(as_str(fname)) + * if fid < 0: raise KeyError(fname) # <<<<<<<<<<<<<< + * scores_.set_value(fid, fval) + * + */ + __pyx_t_10 = (__pyx_v_fid < 0); + if (__pyx_t_10) { + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_fname); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_fname); + __Pyx_GIVEREF(__pyx_v_fname); + __pyx_t_6 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L7; + } + __pyx_L7:; - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":2 - * def _phrase(phrase): - * return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":119 + * fid = FDConvert(as_str(fname)) + * if fid < 0: raise KeyError(fname) + * scores_.set_value(fid, fval) # <<<<<<<<<<<<<< * - * cdef class TRule: + * property lhs: */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_10), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_pf_5_cdec_7_phrase_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); + __pyx_v_scores_->set_value(__pyx_v_fid, __pyx_v_fval); + } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec._phrase", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("_cdec.BaseTRule.scores.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XDECREF(__pyx_v_fname); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_5TRule_5arity_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_5TRule_5arity_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_9BaseTRule_3lhs_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9BaseTRule_3lhs_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_5TRule_5arity___get__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_9BaseTRule_3lhs___get__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":8 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":122 * - * property arity: + * property lhs: * def __get__(self): # <<<<<<<<<<<<<< - * return self.rule.arity_ + * return NT(TDConvert(-self.rule.get().lhs_)) * */ -static PyObject *__pyx_pf_5_cdec_5TRule_5arity___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_9BaseTRule_3lhs___get__(struct __pyx_obj_5_cdec_BaseTRule *__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("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":9 - * property arity: + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":123 + * property lhs: * def __get__(self): - * return self.rule.arity_ # <<<<<<<<<<<<<< + * return NT(TDConvert(-self.rule.get().lhs_)) # <<<<<<<<<<<<<< * - * property f: + * def __set__(self, lhs): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->rule->arity_); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_self->rule->get()->lhs_))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 123; __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[2]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NT)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; @@ -6430,7 +6397,8 @@ static PyObject *__pyx_pf_5_cdec_5TRule_5arity___get__(struct __pyx_obj_5_cdec_T goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.TRule.arity.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec.BaseTRule.lhs.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -6439,552 +6407,648 @@ static PyObject *__pyx_pf_5_cdec_5TRule_5arity___get__(struct __pyx_obj_5_cdec_T } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_5TRule_1f_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_5TRule_1f_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5_cdec_9BaseTRule_3lhs_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_lhs); /*proto*/ +static int __pyx_pw_5_cdec_9BaseTRule_3lhs_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_lhs) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_5TRule_1f___get__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9BaseTRule_3lhs_2__set__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self), ((PyObject *)__pyx_v_lhs)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":12 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":125 + * return NT(TDConvert(-self.rule.get().lhs_)) * - * property f: - * def __get__(self): # <<<<<<<<<<<<<< - * cdef vector[WordID]* f = &self.rule.f_ - * cdef WordID w + * def __set__(self, lhs): # <<<<<<<<<<<<<< + * if not isinstance(lhs, NT): + * lhs = NT(lhs) */ -static PyObject *__pyx_pf_5_cdec_5TRule_1f___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self) { - std::vector *__pyx_v_f; - WordID __pyx_v_w; - PyObject *__pyx_v_words = 0; - unsigned int __pyx_v_i; - int __pyx_v_idx; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5_cdec_9BaseTRule_3lhs_2__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_lhs) { + int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - size_t __pyx_t_2; - unsigned int __pyx_t_3; - int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + char *__pyx_t_5; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":13 - * property f: - * def __get__(self): - * cdef vector[WordID]* f = &self.rule.f_ # <<<<<<<<<<<<<< - * cdef WordID w - * cdef words = [] - */ - __pyx_v_f = (&__pyx_v_self->rule->f_); + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_lhs); - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":15 - * cdef vector[WordID]* f = &self.rule.f_ - * cdef WordID w - * cdef words = [] # <<<<<<<<<<<<<< - * cdef unsigned i - * cdef int idx = 0 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":126 + * + * def __set__(self, lhs): + * if not isinstance(lhs, NT): # <<<<<<<<<<<<<< + * lhs = NT(lhs) + * self.rule.get().lhs_ = -TDConvert(lhs.cat) */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_words = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NT)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_lhs, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = (!__pyx_t_2); + if (__pyx_t_3) { - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":17 - * cdef words = [] - * cdef unsigned i - * cdef int idx = 0 # <<<<<<<<<<<<<< - * for i in range(f.size()): - * w = f[0][i] + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":127 + * def __set__(self, lhs): + * if not isinstance(lhs, NT): + * lhs = NT(lhs) # <<<<<<<<<<<<<< + * self.rule.get().lhs_ = -TDConvert(lhs.cat) + * */ - __pyx_v_idx = 0; + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_lhs); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_lhs); + __Pyx_GIVEREF(__pyx_v_lhs); + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NT)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_v_lhs); + __pyx_v_lhs = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L3; + } + __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":18 - * cdef unsigned i - * cdef int idx = 0 - * for i in range(f.size()): # <<<<<<<<<<<<<< - * w = f[0][i] - * if w < 0: + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":128 + * if not isinstance(lhs, NT): + * lhs = NT(lhs) + * self.rule.get().lhs_ = -TDConvert(lhs.cat) # <<<<<<<<<<<<<< + * + * def __str__(self): */ - __pyx_t_2 = __pyx_v_f->size(); - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_i = __pyx_t_3; + __pyx_t_4 = PyObject_GetAttr(__pyx_v_lhs, __pyx_n_s__cat); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyBytes_AsString(__pyx_t_4); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_self->rule->get()->lhs_ = (-TD::Convert(((char *)__pyx_t_5))); - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":19 - * cdef int idx = 0 - * for i in range(f.size()): - * w = f[0][i] # <<<<<<<<<<<<<< - * if w < 0: - * idx += 1 - */ - __pyx_v_w = ((__pyx_v_f[0])[__pyx_v_i]); + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec.BaseTRule.lhs.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_lhs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":20 - * for i in range(f.size()): - * w = f[0][i] - * if w < 0: # <<<<<<<<<<<<<< - * idx += 1 - * words.append((TDConvert(-w), idx)) - */ - __pyx_t_4 = (__pyx_v_w < 0); - if (__pyx_t_4) { +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_9BaseTRule_3__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9BaseTRule_3__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9BaseTRule_2__str__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_5_cdec_9BaseTRule_7__str___2generator18(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":21 - * w = f[0][i] - * if w < 0: - * idx += 1 # <<<<<<<<<<<<<< - * words.append((TDConvert(-w), idx)) - * else: +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":131 + * + * def __str__(self): + * scores = ' '.join('%s=%s' % feat for feat in self.scores) # <<<<<<<<<<<<<< + * return '%s ||| %s ||| %s ||| %s' % (self.lhs, + * _phrase(self.f), _phrase(self.e), scores) */ - __pyx_v_idx = (__pyx_v_idx + 1); - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":22 - * if w < 0: - * idx += 1 - * words.append((TDConvert(-w), idx)) # <<<<<<<<<<<<<< - * else: - * words.append(unicode(TDConvert(w), encoding='utf8')) - */ - __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_w))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_5 = PyInt_FromLong(__pyx_v_idx); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_1 = 0; - __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_words, ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L5; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":24 - * words.append((TDConvert(-w), idx)) - * else: - * words.append(unicode(TDConvert(w), encoding='utf8')) # <<<<<<<<<<<<<< - * return words - * - */ - __pyx_t_5 = PyBytes_FromString(TD::Convert(__pyx_v_w)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); - __pyx_t_5 = 0; - __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__encoding), ((PyObject *)__pyx_n_s__utf8)) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_6), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_words, __pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __pyx_L5:; +static PyObject *__pyx_pf_5_cdec_9BaseTRule_7__str___genexpr(PyObject *__pyx_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("genexpr", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr *)__pyx_ptype_5_cdec___pyx_scope_struct_6_genexpr->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_6_genexpr, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ *) __pyx_self; + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_9BaseTRule_7__str___2generator18, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; } - - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":25 - * else: - * words.append(unicode(TDConvert(w), encoding='utf8')) - * return words # <<<<<<<<<<<<<< - * - * property e: - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_words); - __pyx_r = __pyx_v_words; - 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_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("_cdec.TRule.f.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.BaseTRule.__str__.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_words); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_5TRule_1e_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_5TRule_1e_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static PyObject *__pyx_gb_5_cdec_9BaseTRule_7__str___2generator18(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *(*__pyx_t_4)(PyObject *); __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_5TRule_1e___get__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self), __pyx_n_s__scores); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; + } else { + __pyx_t_1 = __pyx_t_4(__pyx_t_2); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_feat); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_feat); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_feat = __pyx_t_1; + __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), __pyx_cur_scope->__pyx_v_feat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_r = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + __Pyx_XGIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_2); + __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return __pyx_r; + return NULL; } -/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":28 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":130 + * self.rule.get().lhs_ = -TDConvert(lhs.cat) * - * property e: - * def __get__(self): # <<<<<<<<<<<<<< - * cdef vector[WordID]* e = &self.rule.e_ - * cdef WordID w + * def __str__(self): # <<<<<<<<<<<<<< + * scores = ' '.join('%s=%s' % feat for feat in self.scores) + * return '%s ||| %s ||| %s ||| %s' % (self.lhs, */ -static PyObject *__pyx_pf_5_cdec_5TRule_1e___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self) { - std::vector *__pyx_v_e; - WordID __pyx_v_w; - PyObject *__pyx_v_words = 0; - unsigned int __pyx_v_i; - int __pyx_v_idx; +static PyObject *__pyx_pf_5_cdec_9BaseTRule_2__str__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ *__pyx_cur_scope; + PyObject *__pyx_v_scores = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - size_t __pyx_t_2; - unsigned int __pyx_t_3; - int __pyx_t_4; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":29 - * property e: - * def __get__(self): - * cdef vector[WordID]* e = &self.rule.e_ # <<<<<<<<<<<<<< - * cdef WordID w - * cdef words = [] - */ - __pyx_v_e = (&__pyx_v_self->rule->e_); + __Pyx_RefNannySetupContext("__str__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ *)__pyx_ptype_5_cdec___pyx_scope_struct_5___str__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_5___str__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":31 - * cdef vector[WordID]* e = &self.rule.e_ - * cdef WordID w - * cdef words = [] # <<<<<<<<<<<<<< - * cdef unsigned i - * cdef int idx = 0 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":131 + * + * def __str__(self): + * scores = ' '.join('%s=%s' % feat for feat in self.scores) # <<<<<<<<<<<<<< + * return '%s ||| %s ||| %s ||| %s' % (self.lhs, + * _phrase(self.f), _phrase(self.e), scores) */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_7), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_v_words = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":33 - * cdef words = [] - * cdef unsigned i - * cdef int idx = 0 # <<<<<<<<<<<<<< - * for i in range(e.size()): - * w = e[0][i] - */ - __pyx_v_idx = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":34 - * cdef unsigned i - * cdef int idx = 0 - * for i in range(e.size()): # <<<<<<<<<<<<<< - * w = e[0][i] - * if w < 1: - */ - __pyx_t_2 = __pyx_v_e->size(); - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_i = __pyx_t_3; - - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":35 - * cdef int idx = 0 - * for i in range(e.size()): - * w = e[0][i] # <<<<<<<<<<<<<< - * if w < 1: - * idx += 1 - */ - __pyx_v_w = ((__pyx_v_e[0])[__pyx_v_i]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":36 - * for i in range(e.size()): - * w = e[0][i] - * if w < 1: # <<<<<<<<<<<<<< - * idx += 1 - * words.append((TDConvert(1-w), idx)) - */ - __pyx_t_4 = (__pyx_v_w < 1); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":37 - * w = e[0][i] - * if w < 1: - * idx += 1 # <<<<<<<<<<<<<< - * words.append((TDConvert(1-w), idx)) - * else: - */ - __pyx_v_idx = (__pyx_v_idx + 1); + __pyx_t_2 = __pyx_pf_5_cdec_9BaseTRule_7__str___genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_v_scores = __pyx_t_2; + __pyx_t_2 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":38 - * if w < 1: - * idx += 1 - * words.append((TDConvert(1-w), idx)) # <<<<<<<<<<<<<< - * else: - * words.append(unicode(TDConvert(w), encoding='utf8')) + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":132 + * def __str__(self): + * scores = ' '.join('%s=%s' % feat for feat in self.scores) + * return '%s ||| %s ||| %s ||| %s' % (self.lhs, # <<<<<<<<<<<<<< + * _phrase(self.f), _phrase(self.e), scores) + * */ - __pyx_t_1 = PyBytes_FromString(TD::Convert((1 - __pyx_v_w))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_5 = PyInt_FromLong(__pyx_v_idx); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_1 = 0; - __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_words, ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L5; - } - /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s__lhs); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":40 - * words.append((TDConvert(1-w), idx)) - * else: - * words.append(unicode(TDConvert(w), encoding='utf8')) # <<<<<<<<<<<<<< - * return words + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":133 + * scores = ' '.join('%s=%s' % feat for feat in self.scores) + * return '%s ||| %s ||| %s ||| %s' % (self.lhs, + * _phrase(self.f), _phrase(self.e), scores) # <<<<<<<<<<<<<< * + * cdef class TRule(BaseTRule): */ - __pyx_t_5 = PyBytes_FromString(TD::Convert(__pyx_v_w)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); - __pyx_t_5 = 0; - __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__encoding), ((PyObject *)__pyx_n_s__utf8)) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_6), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_words, __pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __pyx_L5:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":41 - * else: - * words.append(unicode(TDConvert(w), encoding='utf8')) - * return words # <<<<<<<<<<<<<< - * - * property scores: - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_words); - __pyx_r = __pyx_v_words; + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s___phrase); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s__f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___phrase); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s__e); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_scores); + PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_v_scores); + __Pyx_GIVEREF(__pyx_v_scores); + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_12), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_r = ((PyObject *)__pyx_t_3); + __pyx_t_3 = 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_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("_cdec.TRule.e.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.BaseTRule.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_words); + __Pyx_XDECREF(__pyx_v_scores); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_5TRule_6scores_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_5TRule_6scores_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5_cdec_5TRule_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_5TRule_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_lhs = 0; + PyObject *__pyx_v_f = 0; + PyObject *__pyx_v_e = 0; + PyObject *__pyx_v_scores = 0; + PyObject *__pyx_v_a = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__lhs,&__pyx_n_s__f,&__pyx_n_s__e,&__pyx_n_s__scores,&__pyx_n_s__a,0}; + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_5TRule_6scores___get__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[5] = {0,0,0,0,0}; -/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":44 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":136 * - * property scores: - * def __get__(self): # <<<<<<<<<<<<<< - * cdef SparseVector scores = SparseVector() - * scores.vector = new FastSparseVector[double](self.rule.scores_) + * cdef class TRule(BaseTRule): + * def __cinit__(self, lhs, f, e, scores, a=None): # <<<<<<<<<<<<<< + * self.rule = new shared_ptr[grammar.TRule](new grammar.TRule()) + * self.lhs = lhs */ + values[4] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__lhs); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__f); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__e); + if (likely(values[2])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, 2); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 3: + values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__scores); + if (likely(values[3])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, 3); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__a); + if (value) { values[4] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_lhs = values[0]; + __pyx_v_f = values[1]; + __pyx_v_e = values[2]; + __pyx_v_scores = values[3]; + __pyx_v_a = values[4]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.TRule.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_5TRule___cinit__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self), __pyx_v_lhs, __pyx_v_f, __pyx_v_e, __pyx_v_scores, __pyx_v_a); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} -static PyObject *__pyx_pf_5_cdec_5TRule_6scores___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self) { - struct __pyx_obj_5_cdec_SparseVector *__pyx_v_scores = 0; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5_cdec_5TRule___cinit__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self, PyObject *__pyx_v_lhs, PyObject *__pyx_v_f, PyObject *__pyx_v_e, PyObject *__pyx_v_scores, PyObject *__pyx_v_a) { + int __pyx_r; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; + int __pyx_t_1; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_RefNannySetupContext("__cinit__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":45 - * property scores: - * def __get__(self): - * cdef SparseVector scores = SparseVector() # <<<<<<<<<<<<<< - * scores.vector = new FastSparseVector[double](self.rule.scores_) - * return scores - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_scores = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); - __pyx_t_1 = 0; + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":137 + * cdef class TRule(BaseTRule): + * def __cinit__(self, lhs, f, e, scores, a=None): + * self.rule = new shared_ptr[grammar.TRule](new grammar.TRule()) # <<<<<<<<<<<<<< + * self.lhs = lhs + * self.e = e + */ + __pyx_v_self->__pyx_base.rule = new boost::shared_ptr(new TRule()); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":138 + * def __cinit__(self, lhs, f, e, scores, a=None): + * self.rule = new shared_ptr[grammar.TRule](new grammar.TRule()) + * self.lhs = lhs # <<<<<<<<<<<<<< + * self.e = e + * self.f = f + */ + if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__lhs, __pyx_v_lhs) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":139 + * self.rule = new shared_ptr[grammar.TRule](new grammar.TRule()) + * self.lhs = lhs + * self.e = e # <<<<<<<<<<<<<< + * self.f = f + * self.scores = scores + */ + if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__e, __pyx_v_e) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":140 + * self.lhs = lhs + * self.e = e + * self.f = f # <<<<<<<<<<<<<< + * self.scores = scores + * if a: + */ + if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__f, __pyx_v_f) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":141 + * self.e = e + * self.f = f + * self.scores = scores # <<<<<<<<<<<<<< + * if a: + * self.a = a + */ + if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__scores, __pyx_v_scores) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":142 + * self.f = f + * self.scores = scores + * if a: # <<<<<<<<<<<<<< + * self.a = a + * self.rule.get().ComputeArity() + */ + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_a); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":46 - * def __get__(self): - * cdef SparseVector scores = SparseVector() - * scores.vector = new FastSparseVector[double](self.rule.scores_) # <<<<<<<<<<<<<< - * return scores + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":143 + * self.scores = scores + * if a: + * self.a = a # <<<<<<<<<<<<<< + * self.rule.get().ComputeArity() * */ - __pyx_v_scores->vector = new FastSparseVector(__pyx_v_self->rule->scores_); + if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__a, __pyx_v_a) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":47 - * cdef SparseVector scores = SparseVector() - * scores.vector = new FastSparseVector[double](self.rule.scores_) - * return scores # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":144 + * if a: + * self.a = a + * self.rule.get().ComputeArity() # <<<<<<<<<<<<<< * - * property lhs: + * cdef class Grammar: */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_scores)); - __pyx_r = ((PyObject *)__pyx_v_scores); - goto __pyx_L0; + __pyx_v_self->__pyx_base.rule->get()->ComputeArity(); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.TRule.scores.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("_cdec.TRule.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_scores); - __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_5TRule_3lhs_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_5TRule_3lhs_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static void __pyx_pw_5_cdec_7Grammar_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_7Grammar_1__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_5TRule_3lhs___get__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_7Grammar___dealloc__(((struct __pyx_obj_5_cdec_Grammar *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); - return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":50 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":149 + * cdef shared_ptr[grammar.Grammar]* grammar * - * property lhs: - * def __get__(self): # <<<<<<<<<<<<<< - * return TDConvert(-self.rule.lhs_) + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.grammar * */ -static PyObject *__pyx_pf_5_cdec_5TRule_3lhs___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self) { - PyObject *__pyx_r = NULL; +static void __pyx_pf_5_cdec_7Grammar___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Grammar *__pyx_v_self) { __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":51 - * property lhs: - * def __get__(self): - * return TDConvert(-self.rule.lhs_) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":150 * - * def __str__(self): + * def __dealloc__(self): + * del self.grammar # <<<<<<<<<<<<<< + * + * def __iter__(self): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_self->rule->lhs_))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 51; __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; + delete __pyx_v_self->grammar; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.TRule.lhs.__get__", __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_7Grammar_4generator3(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_5TRule_1__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_5TRule_1__str__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_7Grammar_3__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Grammar_3__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_5TRule___str__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Grammar_2__iter__(((struct __pyx_obj_5_cdec_Grammar *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_5TRule_7__str___2generator16(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ -/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":54 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":152 + * del self.grammar * - * def __str__(self): - * scores = ' '.join('%s=%s' % feat for feat in self.scores) # <<<<<<<<<<<<<< - * return '[%s] ||| %s ||| %s ||| %s' % (self.lhs, _phrase(self.f), _phrase(self.e), scores) + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef grammar.GrammarIter* root = self.grammar.get().GetRoot() + * cdef grammar.RuleBin* rbin = root.GetRules() */ -static PyObject *__pyx_pf_5_cdec_5TRule_7__str___genexpr(PyObject *__pyx_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_7Grammar_2__iter__(struct __pyx_obj_5_cdec_Grammar *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("genexpr", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *)__pyx_ptype_5_cdec___pyx_scope_struct_11_genexpr->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_11_genexpr, __pyx_empty_tuple, NULL); + __Pyx_RefNannySetupContext("__iter__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_7___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_7___iter__, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; } __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *) __pyx_self; - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_5TRule_7__str___2generator16, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Grammar_4generator3, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -6993,7 +7057,7 @@ static PyObject *__pyx_pf_5_cdec_5TRule_7__str___genexpr(PyObject *__pyx_self) { __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.TRule.__str__.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Grammar.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); @@ -7002,14 +7066,13 @@ static PyObject *__pyx_pf_5_cdec_5TRule_7__str___genexpr(PyObject *__pyx_self) { return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_5TRule_7__str___2generator16(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_7Grammar_4generator3(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *)__pyx_generator->closure); + struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - Py_ssize_t __pyx_t_3; - PyObject *(*__pyx_t_4)(PyObject *); + int __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { @@ -7020,564 +7083,477 @@ static PyObject *__pyx_gb_5_cdec_5TRule_7__str___2generator16(__pyx_GeneratorObj return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self), __pyx_n_s__scores); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_2)) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; - } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_2)) { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; - } else { - __pyx_t_1 = __pyx_t_4(__pyx_t_2); - if (unlikely(!__pyx_t_1)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_feat); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_feat); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_v_feat = __pyx_t_1; - __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), __pyx_cur_scope->__pyx_v_feat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_r = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - __Pyx_XGIVEREF(__pyx_t_2); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L6_resume_from_yield:; - __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; - __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_2); - __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; - __Pyx_RefNannyFinishContext(); - return NULL; -} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} -/* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":53 - * return TDConvert(-self.rule.lhs_) + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":153 * - * def __str__(self): # <<<<<<<<<<<<<< - * scores = ' '.join('%s=%s' % feat for feat in self.scores) - * return '[%s] ||| %s ||| %s ||| %s' % (self.lhs, _phrase(self.f), _phrase(self.e), scores) + * def __iter__(self): + * cdef grammar.GrammarIter* root = self.grammar.get().GetRoot() # <<<<<<<<<<<<<< + * cdef grammar.RuleBin* rbin = root.GetRules() + * cdef TRule trule */ + __pyx_cur_scope->__pyx_v_root = __pyx_cur_scope->__pyx_v_self->grammar->get()->GetRoot(); -static PyObject *__pyx_pf_5_cdec_5TRule___str__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *__pyx_cur_scope; - PyObject *__pyx_v_scores = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__str__", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *)__pyx_ptype_5_cdec___pyx_scope_struct_10___str__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_10___str__, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":154 + * def __iter__(self): + * cdef grammar.GrammarIter* root = self.grammar.get().GetRoot() + * cdef grammar.RuleBin* rbin = root.GetRules() # <<<<<<<<<<<<<< + * cdef TRule trule + * cdef unsigned i + */ + __pyx_cur_scope->__pyx_v_rbin = __pyx_cur_scope->__pyx_v_root->GetRules(); - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":54 - * - * def __str__(self): - * scores = ' '.join('%s=%s' % feat for feat in self.scores) # <<<<<<<<<<<<<< - * return '[%s] ||| %s ||| %s ||| %s' % (self.lhs, _phrase(self.f), _phrase(self.e), scores) + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":157 + * cdef TRule trule + * cdef unsigned i + * for i in range(rbin.GetNumRules()): # <<<<<<<<<<<<<< + * trule = TRule() + * trule.rule = new shared_ptr[grammar.TRule](rbin.GetIthRule(i)) */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_10), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_pf_5_cdec_5TRule_7__str___genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_v_scores = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_t_1 = __pyx_cur_scope->__pyx_v_rbin->GetNumRules(); + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":55 - * def __str__(self): - * scores = ' '.join('%s=%s' % feat for feat in self.scores) - * return '[%s] ||| %s ||| %s ||| %s' % (self.lhs, _phrase(self.f), _phrase(self.e), scores) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":158 + * cdef unsigned i + * for i in range(rbin.GetNumRules()): + * trule = TRule() # <<<<<<<<<<<<<< + * trule.rule = new shared_ptr[grammar.TRule](rbin.GetIthRule(i)) + * yield trule */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s__lhs); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s___phrase); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s__f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___phrase); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s__e); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_scores); - PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_v_scores); - __Pyx_GIVEREF(__pyx_v_scores); - __pyx_t_2 = 0; - __pyx_t_1 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_12), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_r = ((PyObject *)__pyx_t_3); - __pyx_t_3 = 0; - goto __pyx_L0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_TRule)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_trule)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_trule)); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_trule = ((struct __pyx_obj_5_cdec_TRule *)__pyx_t_3); + __pyx_t_3 = 0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":159 + * for i in range(rbin.GetNumRules()): + * trule = TRule() + * trule.rule = new shared_ptr[grammar.TRule](rbin.GetIthRule(i)) # <<<<<<<<<<<<<< + * yield trule + * + */ + __pyx_cur_scope->__pyx_v_trule->__pyx_base.rule = new boost::shared_ptr(__pyx_cur_scope->__pyx_v_rbin->GetIthRule(__pyx_cur_scope->__pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":160 + * trule = TRule() + * trule.rule = new shared_ptr[grammar.TRule](rbin.GetIthRule(i)) + * yield trule # <<<<<<<<<<<<<< + * + * property name: + */ + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_trule)); + __pyx_r = ((PyObject *)__pyx_cur_scope->__pyx_v_trule); + __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_generator->resume_label = 1; + return __pyx_r; + __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[2]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("_cdec.TRule.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XDECREF(__pyx_v_scores); - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Grammar_4name_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Grammar_4name_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Grammar_4name___get__(((struct __pyx_obj_5_cdec_Grammar *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":138 - * cdef public TRule trule +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":163 + * + * property name: + * def __get__(self): # <<<<<<<<<<<<<< + * self.grammar.get().GetGrammarName().c_str() * - * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): # <<<<<<<<<<<<<< - * self.hg = hg - * self.edge = &hg.edges_[i] */ -static PyObject *__pyx_f_5_cdec_14HypergraphEdge_init(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self, Hypergraph *__pyx_v_hg, unsigned int __pyx_v_i) { +static PyObject *__pyx_pf_5_cdec_7Grammar_4name___get__(struct __pyx_obj_5_cdec_Grammar *__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("init", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":139 - * - * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): - * self.hg = hg # <<<<<<<<<<<<<< - * self.edge = &hg.edges_[i] - * self.trule = TRule() - */ - __pyx_v_self->hg = __pyx_v_hg; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":140 - * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): - * self.hg = hg - * self.edge = &hg.edges_[i] # <<<<<<<<<<<<<< - * self.trule = TRule() - * self.trule.rule = self.edge.rule_.get() - */ - __pyx_v_self->edge = (&(__pyx_v_hg->edges_[__pyx_v_i])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":141 - * self.hg = hg - * self.edge = &hg.edges_[i] - * self.trule = TRule() # <<<<<<<<<<<<<< - * self.trule.rule = self.edge.rule_.get() - * return self - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_TRule)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->trule); - __Pyx_DECREF(((PyObject *)__pyx_v_self->trule)); - __pyx_v_self->trule = ((struct __pyx_obj_5_cdec_TRule *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":142 - * self.edge = &hg.edges_[i] - * self.trule = TRule() - * self.trule.rule = self.edge.rule_.get() # <<<<<<<<<<<<<< - * return self - * - */ - __pyx_v_self->trule->rule = __pyx_v_self->edge->rule_.get(); + __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":143 - * self.trule = TRule() - * self.trule.rule = self.edge.rule_.get() - * return self # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":164 + * property name: + * def __get__(self): + * self.grammar.get().GetGrammarName().c_str() # <<<<<<<<<<<<<< * - * def __len__(self): + * def __set__(self, name): */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __pyx_r = ((PyObject *)__pyx_v_self); - goto __pyx_L0; + __pyx_v_self->grammar->get()->GetGrammarName().c_str(); __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.HypergraphEdge.init", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static Py_ssize_t __pyx_pw_5_cdec_14HypergraphEdge_1__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_5_cdec_14HypergraphEdge_1__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; +static int __pyx_pw_5_cdec_7Grammar_4name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_name); /*proto*/ +static int __pyx_pw_5_cdec_7Grammar_4name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_name) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge___len__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Grammar_4name_2__set__(((struct __pyx_obj_5_cdec_Grammar *)__pyx_v_self), ((PyObject *)__pyx_v_name)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":145 - * return self +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":166 + * self.grammar.get().GetGrammarName().c_str() * - * def __len__(self): # <<<<<<<<<<<<<< - * return self.edge.tail_nodes_.size() + * def __set__(self, name): # <<<<<<<<<<<<<< + * self.grammar.get().SetGrammarName(string(name)) * */ -static Py_ssize_t __pyx_pf_5_cdec_14HypergraphEdge___len__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { - Py_ssize_t __pyx_r; +static int __pyx_pf_5_cdec_7Grammar_4name_2__set__(struct __pyx_obj_5_cdec_Grammar *__pyx_v_self, PyObject *__pyx_v_name) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__", 0); + char *__pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":146 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":167 * - * def __len__(self): - * return self.edge.tail_nodes_.size() # <<<<<<<<<<<<<< + * def __set__(self, name): + * self.grammar.get().SetGrammarName(string(name)) # <<<<<<<<<<<<<< * - * property head_node: + * cdef class TextGrammar(Grammar): */ - __pyx_r = __pyx_v_self->edge->tail_nodes_.size(); - goto __pyx_L0; + __pyx_t_1 = PyBytes_AsString(__pyx_v_name); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->grammar->get()->SetGrammarName(std::string(((char *)__pyx_t_1))); __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Grammar.name.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_9head_node_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_9head_node_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static int __pyx_pw_5_cdec_11TextGrammar_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_11TextGrammar_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_rules = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__rules,0}; + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_9head_node___get__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__rules); + 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 170; __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_rules = values[0]; + } + 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[2]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.TextGrammar.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_11TextGrammar___cinit__(((struct __pyx_obj_5_cdec_TextGrammar *)__pyx_v_self), __pyx_v_rules); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":149 - * - * property head_node: - * def __get__(self): # <<<<<<<<<<<<<< - * return HypergraphNode().init(self.hg, self.edge.head_node_) +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":170 * + * cdef class TextGrammar(Grammar): + * def __cinit__(self, rules): # <<<<<<<<<<<<<< + * self.grammar = new shared_ptr[grammar.Grammar](new grammar.TextGrammar()) + * cdef grammar.TextGrammar* _g = self.grammar.get() */ -static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_9head_node___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { - PyObject *__pyx_r = NULL; +static int __pyx_pf_5_cdec_11TextGrammar___cinit__(struct __pyx_obj_5_cdec_TextGrammar *__pyx_v_self, PyObject *__pyx_v_rules) { + TextGrammar *__pyx_v__g; + PyObject *__pyx_v_trule = NULL; + int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + int __pyx_t_6; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_RefNannySetupContext("__cinit__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":150 - * property head_node: - * def __get__(self): - * return HypergraphNode().init(self.hg, self.edge.head_node_) # <<<<<<<<<<<<<< - * - * property tail_nodes: + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":171 + * cdef class TextGrammar(Grammar): + * def __cinit__(self, rules): + * self.grammar = new shared_ptr[grammar.Grammar](new grammar.TextGrammar()) # <<<<<<<<<<<<<< + * cdef grammar.TextGrammar* _g = self.grammar.get() + * for trule in rules: + */ + __pyx_v_self->__pyx_base.grammar = new boost::shared_ptr(new TextGrammar()); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":172 + * def __cinit__(self, rules): + * self.grammar = new shared_ptr[grammar.Grammar](new grammar.TextGrammar()) + * cdef grammar.TextGrammar* _g = self.grammar.get() # <<<<<<<<<<<<<< + * for trule in rules: + * if not isinstance(trule, BaseTRule): + */ + __pyx_v__g = ((TextGrammar *)__pyx_v_self->__pyx_base.grammar->get()); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":173 + * self.grammar = new shared_ptr[grammar.Grammar](new grammar.TextGrammar()) + * cdef grammar.TextGrammar* _g = self.grammar.get() + * for trule in rules: # <<<<<<<<<<<<<< + * if not isinstance(trule, BaseTRule): + * raise ValueError('the grammar should contain TRule objects') + */ + if (PyList_CheckExact(__pyx_v_rules) || PyTuple_CheckExact(__pyx_v_rules)) { + __pyx_t_1 = __pyx_v_rules; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_rules); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_trule); + __pyx_v_trule = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":174 + * cdef grammar.TextGrammar* _g = self.grammar.get() + * for trule in rules: + * if not isinstance(trule, BaseTRule): # <<<<<<<<<<<<<< + * raise ValueError('the grammar should contain TRule objects') + * _g.AddRule(( trule).rule[0]) */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = ((struct __pyx_vtabstruct_5_cdec_HypergraphNode *)((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_1)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_1), __pyx_v_self->hg, __pyx_v_self->edge->head_node_); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_BaseTRule)); + __Pyx_INCREF(__pyx_t_4); + __pyx_t_5 = __Pyx_TypeCheck(__pyx_v_trule, __pyx_t_4); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = (!__pyx_t_5); + if (__pyx_t_6) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":175 + * for trule in rules: + * if not isinstance(trule, BaseTRule): + * raise ValueError('the grammar should contain TRule objects') # <<<<<<<<<<<<<< + * _g.AddRule(( trule).rule[0]) + */ + __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_14), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":176 + * if not isinstance(trule, BaseTRule): + * raise ValueError('the grammar should contain TRule objects') + * _g.AddRule(( trule).rule[0]) # <<<<<<<<<<<<<< + */ + __pyx_v__g->AddRule((((struct __pyx_obj_5_cdec_TRule *)__pyx_v_trule)->__pyx_base.rule[0])); + } __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); + __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_cdec.HypergraphEdge.head_node.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec.TextGrammar.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XDECREF(__pyx_v_trule); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_14HypergraphEdge_10tail_nodes_2generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_10tail_nodes_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_10tail_nodes_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static void __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_10tail_nodes___get__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_10Hypergraph___dealloc__(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); - return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":153 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":8 + * cdef MT19937* rng * - * property tail_nodes: - * def __get__(self): # <<<<<<<<<<<<<< - * cdef unsigned i - * for i in range(self.edge.tail_nodes_.size()): + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.hg + * if self.rng != NULL: */ -static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_10tail_nodes___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *__pyx_cur_scope; - PyObject *__pyx_r = NULL; +static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { __Pyx_RefNannyDeclarations - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *)__pyx_ptype_5_cdec___pyx_scope_struct_12___get__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_12___get__, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_14HypergraphEdge_10tail_nodes_2generator8, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.HypergraphEdge.tail_nodes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + int __pyx_t_1; + __Pyx_RefNannySetupContext("__dealloc__", 0); -static PyObject *__pyx_gb_5_cdec_14HypergraphEdge_10tail_nodes_2generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - unsigned int __pyx_t_1; - unsigned int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("None", 0); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_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[2]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":9 + * + * def __dealloc__(self): + * del self.hg # <<<<<<<<<<<<<< + * if self.rng != NULL: + * del self.rng + */ + delete __pyx_v_self->hg; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":155 - * def __get__(self): - * cdef unsigned i - * for i in range(self.edge.tail_nodes_.size()): # <<<<<<<<<<<<<< - * yield HypergraphNode().init(self.hg, self.edge.tail_nodes_[i]) + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":10 + * def __dealloc__(self): + * del self.hg + * if self.rng != NULL: # <<<<<<<<<<<<<< + * del self.rng * */ - __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->edge->tail_nodes_.size(); - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + __pyx_t_1 = (__pyx_v_self->rng != NULL); + if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":156 - * cdef unsigned i - * for i in range(self.edge.tail_nodes_.size()): - * yield HypergraphNode().init(self.hg, self.edge.tail_nodes_[i]) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":11 + * del self.hg + * if self.rng != NULL: + * del self.rng # <<<<<<<<<<<<<< * - * property span: + * def viterbi(self): */ - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = ((struct __pyx_vtabstruct_5_cdec_HypergraphNode *)((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_3)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_3), __pyx_cur_scope->__pyx_v_self->hg, (__pyx_cur_scope->__pyx_v_self->edge->tail_nodes_[__pyx_cur_scope->__pyx_v_i])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 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_generator->resume_label = 1; - return __pyx_r; - __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[2]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + delete __pyx_v_self->rng; + goto __pyx_L3; } - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; + __pyx_L3:; + __Pyx_RefNannyFinishContext(); - return NULL; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_4span_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_4span_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_3viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_3viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_4span___get__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); + __Pyx_RefNannySetupContext("viterbi (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_2viterbi(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":159 - * - * property span: - * def __get__(self): # <<<<<<<<<<<<<< - * return (self.edge.i_, self.edge.j_) +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":13 + * del self.rng * + * def viterbi(self): # <<<<<<<<<<<<<< + * cdef vector[WordID] trans + * hypergraph.ViterbiESentence(self.hg[0], &trans) */ -static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_4span___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + std::vector __pyx_v_trans; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_RefNannySetupContext("viterbi", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":160 - * property span: - * def __get__(self): - * return (self.edge.i_, self.edge.j_) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":15 + * def viterbi(self): + * cdef vector[WordID] trans + * hypergraph.ViterbiESentence(self.hg[0], &trans) # <<<<<<<<<<<<<< + * return unicode(GetString(trans).c_str(), 'utf8') * - * property feature_values: + */ + ViterbiESentence((__pyx_v_self->hg[0]), (&__pyx_v_trans)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":16 + * cdef vector[WordID] trans + * hypergraph.ViterbiESentence(self.hg[0], &trans) + * return unicode(GetString(trans).c_str(), 'utf8') # <<<<<<<<<<<<<< + * + * def viterbi_trees(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->edge->i_); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyInt_FromLong(__pyx_v_self->edge->j_); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 160; __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[3]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_r = ((PyObject *)__pyx_t_3); - __pyx_t_3 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); @@ -7585,8 +7561,7 @@ static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_4span___get__(struct __pyx_obj __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec.HypergraphEdge.span.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Hypergraph.viterbi", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -7595,431 +7570,288 @@ static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_4span___get__(struct __pyx_obj } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_14feature_values_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_14feature_values_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_5viterbi_trees(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_5viterbi_trees(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_14feature_values___get__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); + __Pyx_RefNannySetupContext("viterbi_trees (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_4viterbi_trees(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":163 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":18 + * return unicode(GetString(trans).c_str(), 'utf8') * - * property feature_values: - * def __get__(self): # <<<<<<<<<<<<<< - * cdef SparseVector vector = SparseVector() - * vector.vector = new FastSparseVector[double](self.edge.feature_values_) + * def viterbi_trees(self): # <<<<<<<<<<<<<< + * f_tree = unicode(hypergraph.ViterbiFTree(self.hg[0]).c_str(), 'utf8') + * e_tree = unicode(hypergraph.ViterbiETree(self.hg[0]).c_str(), 'utf8') */ -static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_14feature_values___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { - struct __pyx_obj_5_cdec_SparseVector *__pyx_v_vector = 0; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_4viterbi_trees(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + PyObject *__pyx_v_f_tree = NULL; + PyObject *__pyx_v_e_tree = NULL; 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("__get__", 0); + __Pyx_RefNannySetupContext("viterbi_trees", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":164 - * property feature_values: - * def __get__(self): - * cdef SparseVector vector = SparseVector() # <<<<<<<<<<<<<< - * vector.vector = new FastSparseVector[double](self.edge.feature_values_) - * return vector + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":19 + * + * def viterbi_trees(self): + * f_tree = unicode(hypergraph.ViterbiFTree(self.hg[0]).c_str(), 'utf8') # <<<<<<<<<<<<<< + * e_tree = unicode(hypergraph.ViterbiETree(self.hg[0]).c_str(), 'utf8') + * return (f_tree, e_tree) */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(ViterbiFTree((__pyx_v_self->hg[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_v_f_tree = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":165 - * def __get__(self): - * cdef SparseVector vector = SparseVector() - * vector.vector = new FastSparseVector[double](self.edge.feature_values_) # <<<<<<<<<<<<<< - * return vector + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":20 + * def viterbi_trees(self): + * f_tree = unicode(hypergraph.ViterbiFTree(self.hg[0]).c_str(), 'utf8') + * e_tree = unicode(hypergraph.ViterbiETree(self.hg[0]).c_str(), 'utf8') # <<<<<<<<<<<<<< + * return (f_tree, e_tree) * */ - __pyx_v_vector->vector = new FastSparseVector(__pyx_v_self->edge->feature_values_); + __pyx_t_1 = PyBytes_FromString(ViterbiETree((__pyx_v_self->hg[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_v_e_tree = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":166 - * cdef SparseVector vector = SparseVector() - * vector.vector = new FastSparseVector[double](self.edge.feature_values_) - * return vector # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":21 + * f_tree = unicode(hypergraph.ViterbiFTree(self.hg[0]).c_str(), 'utf8') + * e_tree = unicode(hypergraph.ViterbiETree(self.hg[0]).c_str(), 'utf8') + * return (f_tree, e_tree) # <<<<<<<<<<<<<< * - * property prob: + * def viterbi_features(self): */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_vector)); - __pyx_r = ((PyObject *)__pyx_v_vector); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_f_tree)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_f_tree)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_f_tree)); + __Pyx_INCREF(((PyObject *)__pyx_v_e_tree)); + PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_e_tree)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_e_tree)); + __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.HypergraphEdge.feature_values.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec.Hypergraph.viterbi_trees", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_vector); + __Pyx_XDECREF(__pyx_v_f_tree); + __Pyx_XDECREF(__pyx_v_e_tree); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_4prob_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_4prob_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_7viterbi_features(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_7viterbi_features(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_4prob___get__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); + __Pyx_RefNannySetupContext("viterbi_features (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_6viterbi_features(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":169 - * - * property prob: - * def __get__(self): # <<<<<<<<<<<<<< - * return self.edge.edge_prob_.as_float() +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":23 + * return (f_tree, e_tree) * + * def viterbi_features(self): # <<<<<<<<<<<<<< + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) */ -static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_4prob___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_10Hypergraph_6viterbi_features(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap = 0; 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("__get__", 0); + __Pyx_RefNannySetupContext("viterbi_features", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":170 - * property prob: - * def __get__(self): - * return self.edge.edge_prob_.as_float() # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":24 * - * def __richcmp__(HypergraphEdge x, HypergraphEdge y, int op): + * def viterbi_features(self): + * cdef SparseVector fmap = SparseVector() # <<<<<<<<<<<<<< + * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) + * return fmap */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->edge->edge_prob_.as_float()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; + __pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":25 + * def viterbi_features(self): + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) # <<<<<<<<<<<<<< + * return fmap + * + */ + __pyx_v_fmap->vector = new FastSparseVector(ViterbiFeatures((__pyx_v_self->hg[0]))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":26 + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) + * return fmap # <<<<<<<<<<<<<< + * + * def viterbi_joshua(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_fmap)); + __pyx_r = ((PyObject *)__pyx_v_fmap); 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.HypergraphEdge.prob.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Hypergraph.viterbi_features", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_fmap); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_3__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op); /*proto*/ -static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_3__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_9viterbi_joshua(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_9viterbi_joshua(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_HypergraphEdge, 1, "x", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_HypergraphEdge, 1, "y", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_2__richcmp__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_x), ((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_y), ((int)__pyx_v_op)); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; + __Pyx_RefNannySetupContext("viterbi_joshua (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_8viterbi_joshua(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":172 - * return self.edge.edge_prob_.as_float() +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":28 + * return fmap + * + * def viterbi_joshua(self): # <<<<<<<<<<<<<< + * return unicode(hypergraph.JoshuaVisualizationString(self.hg[0]).c_str(), 'utf8') * - * def __richcmp__(HypergraphEdge x, HypergraphEdge y, int op): # <<<<<<<<<<<<<< - * if op == 2: # == - * return x.edge == y.edge */ -static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_2__richcmp__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_x, struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_y, int __pyx_v_op) { +static PyObject *__pyx_pf_5_cdec_10Hypergraph_8viterbi_joshua(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; + PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__richcmp__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":175 - * if op == 2: # == - * return x.edge == y.edge - * elif op == 3: # != # <<<<<<<<<<<<<< - * return not (x == y) - * raise NotImplemented('comparison not implemented for HypergraphEdge') - */ - switch (__pyx_v_op) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":173 - * - * def __richcmp__(HypergraphEdge x, HypergraphEdge y, int op): - * if op == 2: # == # <<<<<<<<<<<<<< - * return x.edge == y.edge - * elif op == 3: # != - */ - case 2: - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":174 - * def __richcmp__(HypergraphEdge x, HypergraphEdge y, int op): - * if op == 2: # == - * return x.edge == y.edge # <<<<<<<<<<<<<< - * elif op == 3: # != - * return not (x == y) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_x->edge == __pyx_v_y->edge)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":175 - * if op == 2: # == - * return x.edge == y.edge - * elif op == 3: # != # <<<<<<<<<<<<<< - * return not (x == y) - * raise NotImplemented('comparison not implemented for HypergraphEdge') - */ - case 3: + __Pyx_RefNannySetupContext("viterbi_joshua", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":176 - * return x.edge == y.edge - * elif op == 3: # != - * return not (x == y) # <<<<<<<<<<<<<< - * raise NotImplemented('comparison not implemented for HypergraphEdge') + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":29 * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - break; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":177 - * elif op == 3: # != - * return not (x == y) - * raise NotImplemented('comparison not implemented for HypergraphEdge') # <<<<<<<<<<<<<< + * def viterbi_joshua(self): + * return unicode(hypergraph.JoshuaVisualizationString(self.hg[0]).c_str(), 'utf8') # <<<<<<<<<<<<<< * - * cdef class HypergraphNode: + * def kbest(self, size): */ - __pyx_t_1 = PyObject_Call(__pyx_builtin_NotImplemented, ((PyObject *)__pyx_k_tuple_14), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(JoshuaVisualizationString((__pyx_v_self->hg[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__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_AddTraceback("_cdec.HypergraphEdge.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec.Hypergraph.viterbi_joshua", __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_12generator4(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_5trule_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_5trule_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_5trule___get__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":136 - * cdef hypergraph.Hypergraph* hg - * cdef hypergraph.HypergraphEdge* edge - * cdef public TRule trule # <<<<<<<<<<<<<< - * - * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): - */ - -static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_5trule___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self->trule)); - __pyx_r = ((PyObject *)__pyx_v_self->trule); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_5_cdec_14HypergraphEdge_5trule_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5_cdec_14HypergraphEdge_5trule_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_5trule_2__set__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self), ((PyObject *)__pyx_v_value)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5_cdec_14HypergraphEdge_5trule_2__set__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__set__", 0); - if (!(likely(((__pyx_v_value) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_value, __pyx_ptype_5_cdec_TRule))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(__pyx_v_self->trule); - __Pyx_DECREF(((PyObject *)__pyx_v_self->trule)); - __pyx_v_self->trule = ((struct __pyx_obj_5_cdec_TRule *)__pyx_v_value); - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.HypergraphEdge.trule.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_5_cdec_14HypergraphEdge_5trule_5__del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pw_5_cdec_14HypergraphEdge_5trule_5__del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_5trule_4__del__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5_cdec_14HypergraphEdge_5trule_4__del__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__", 0); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->trule); - __Pyx_DECREF(((PyObject *)__pyx_v_self->trule)); - __pyx_v_self->trule = ((struct __pyx_obj_5_cdec_TRule *)Py_None); - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":183 - * cdef hypergraph.HypergraphNode* node - * - * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): # <<<<<<<<<<<<<< - * self.hg = hg - * self.node = &hg.nodes_[i] - */ - -static PyObject *__pyx_f_5_cdec_14HypergraphNode_init(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self, Hypergraph *__pyx_v_hg, unsigned int __pyx_v_i) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("init", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":184 - * - * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): - * self.hg = hg # <<<<<<<<<<<<<< - * self.node = &hg.nodes_[i] - * return self - */ - __pyx_v_self->hg = __pyx_v_hg; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":185 - * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): - * self.hg = hg - * self.node = &hg.nodes_[i] # <<<<<<<<<<<<<< - * return self - * - */ - __pyx_v_self->node = (&(__pyx_v_hg->nodes_[__pyx_v_i])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":186 - * self.hg = hg - * self.node = &hg.nodes_[i] - * return self # <<<<<<<<<<<<<< - * - * property in_edges: - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __pyx_r = ((PyObject *)__pyx_v_self); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -static PyObject *__pyx_gb_5_cdec_14HypergraphNode_8in_edges_2generator9(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_14HypergraphNode_8in_edges_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_14HypergraphNode_8in_edges_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_11kbest(PyObject *__pyx_v_self, PyObject *__pyx_v_size); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_11kbest(PyObject *__pyx_v_self, PyObject *__pyx_v_size) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_14HypergraphNode_8in_edges___get__(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_v_self)); + __Pyx_RefNannySetupContext("kbest (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_10kbest(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_size)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":189 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":31 + * return unicode(hypergraph.JoshuaVisualizationString(self.hg[0]).c_str(), 'utf8') * - * property in_edges: - * def __get__(self): # <<<<<<<<<<<<<< - * cdef unsigned i - * for i in range(self.node.in_edges_.size()): + * def kbest(self, size): # <<<<<<<<<<<<<< + * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal]* derivations = new kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal](self.hg[0], size) + * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal].Derivation* derivation */ -static PyObject *__pyx_pf_5_cdec_14HypergraphNode_8in_edges___get__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_10kbest(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8_kbest *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *)__pyx_ptype_5_cdec___pyx_scope_struct_13___get__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_13___get__, __pyx_empty_tuple, NULL); + __Pyx_RefNannySetupContext("kbest", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_kbest *)__pyx_ptype_5_cdec___pyx_scope_struct_8_kbest->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_8_kbest, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -8028,8 +7860,11 @@ static PyObject *__pyx_pf_5_cdec_14HypergraphNode_8in_edges___get__(struct __pyx __pyx_cur_scope->__pyx_v_self = __pyx_v_self; __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __pyx_cur_scope->__pyx_v_size = __pyx_v_size; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_14HypergraphNode_8in_edges_2generator9, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_12generator4, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -8038,7 +7873,7 @@ static PyObject *__pyx_pf_5_cdec_14HypergraphNode_8in_edges___get__(struct __pyx __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.HypergraphNode.in_edges.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Hypergraph.kbest", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); @@ -8047,105 +7882,193 @@ static PyObject *__pyx_pf_5_cdec_14HypergraphNode_8in_edges___get__(struct __pyx return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_14HypergraphNode_8in_edges_2generator9(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_10Hypergraph_12generator4(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *)__pyx_generator->closure); + struct __pyx_obj_5_cdec___pyx_scope_struct_8_kbest *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8_kbest *)__pyx_generator->closure); PyObject *__pyx_r = NULL; - size_t __pyx_t_1; - unsigned int __pyx_t_2; - PyObject *__pyx_t_3 = 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", 0); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_resume_from_yield; + case 1: goto __pyx_L10_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[2]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":191 - * def __get__(self): - * cdef unsigned i - * for i in range(self.node.in_edges_.size()): # <<<<<<<<<<<<<< - * yield HypergraphEdge().init(self.hg, self.node.in_edges_[i]) + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":32 * + * def kbest(self, size): + * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal]* derivations = new kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal](self.hg[0], size) # <<<<<<<<<<<<<< + * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal].Derivation* derivation + * cdef unsigned k */ - __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->node->in_edges_.size(); - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + __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[3]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,ESentenceTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":192 - * cdef unsigned i - * for i in range(self.node.in_edges_.size()): - * yield HypergraphEdge().init(self.hg, self.node.in_edges_[i]) # <<<<<<<<<<<<<< - * - * property out_edges: + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":35 + * cdef kbest.KBestDerivations[vector[WordID], kbest.ESentenceTraversal].Derivation* derivation + * cdef unsigned k + * try: # <<<<<<<<<<<<<< + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) */ - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphEdge)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = ((struct __pyx_vtabstruct_5_cdec_HypergraphEdge *)((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_t_3)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_t_3), __pyx_cur_scope->__pyx_v_self->hg, (__pyx_cur_scope->__pyx_v_self->node->in_edges_[__pyx_cur_scope->__pyx_v_i])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 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_generator->resume_label = 1; - return __pyx_r; - __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[2]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; - __Pyx_RefNannyFinishContext(); - return NULL; -} -static PyObject *__pyx_gb_5_cdec_14HypergraphNode_9out_edges_2generator10(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_14HypergraphNode_9out_edges_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_14HypergraphNode_9out_edges_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_14HypergraphNode_9out_edges___get__(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /*try:*/ { -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":195 - * - * property out_edges: - * def __get__(self): # <<<<<<<<<<<<<< - * cdef unsigned i - * for i in range(self.node.out_edges_.size()): + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":36 + * cdef unsigned k + * try: + * 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[3]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L5;} + for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { + __pyx_cur_scope->__pyx_v_k = __pyx_t_1; -static PyObject *__pyx_pf_5_cdec_14HypergraphNode_9out_edges___get__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *__pyx_cur_scope; + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":37 + * try: + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< + * if not derivation: break + * yield unicode(GetString(derivation._yield).c_str(), 'utf8') + */ + __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":38 + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break # <<<<<<<<<<<<<< + * yield unicode(GetString(derivation._yield).c_str(), 'utf8') + * finally: + */ + __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0)); + if (__pyx_t_3) { + goto __pyx_L8_break; + goto __pyx_L9; + } + __pyx_L9:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":39 + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break + * yield unicode(GetString(derivation._yield).c_str(), 'utf8') # <<<<<<<<<<<<<< + * finally: + * 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[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 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_generator->resume_label = 1; + return __pyx_r; + __pyx_L10_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[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L5;} + } + __pyx_L8_break:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":41 + * yield unicode(GetString(derivation._yield).c_str(), 'utf8') + * finally: + * del derivations # <<<<<<<<<<<<<< + * + * def kbest_trees(self, size): + */ + /*finally:*/ { + int __pyx_why; + PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; + int __pyx_exc_lineno; + __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; + __pyx_why = 0; goto __pyx_L6; + __pyx_L5: { + __pyx_why = 4; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); + __pyx_exc_lineno = __pyx_lineno; + goto __pyx_L6; + } + __pyx_L6:; + delete __pyx_cur_scope->__pyx_v_derivations; + switch (__pyx_why) { + case 4: { + __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); + __pyx_lineno = __pyx_exc_lineno; + __pyx_exc_type = 0; + __pyx_exc_value = 0; + __pyx_exc_tb = 0; + goto __pyx_L1_error; + } + } + } + PyErr_SetNone(PyExc_StopIteration); + 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_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} +static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator5(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_14kbest_trees(PyObject *__pyx_v_self, PyObject *__pyx_v_size); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_14kbest_trees(PyObject *__pyx_v_self, PyObject *__pyx_v_size) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("kbest_trees (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_13kbest_trees(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_size)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":43 + * del derivations + * + * def kbest_trees(self, size): # <<<<<<<<<<<<<< + * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal]* f_derivations = new kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal](self.hg[0], size) + * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal].Derivation* f_derivation + */ + +static PyObject *__pyx_pf_5_cdec_10Hypergraph_13kbest_trees(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size) { + struct __pyx_obj_5_cdec___pyx_scope_struct_9_kbest_trees *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *)__pyx_ptype_5_cdec___pyx_scope_struct_14___get__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_14___get__, __pyx_empty_tuple, NULL); + __Pyx_RefNannySetupContext("kbest_trees", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_9_kbest_trees *)__pyx_ptype_5_cdec___pyx_scope_struct_9_kbest_trees->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_9_kbest_trees, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -8154,8 +8077,11 @@ static PyObject *__pyx_pf_5_cdec_14HypergraphNode_9out_edges___get__(struct __py __pyx_cur_scope->__pyx_v_self = __pyx_v_self; __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __pyx_cur_scope->__pyx_v_size = __pyx_v_size; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_14HypergraphNode_9out_edges_2generator10, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_15generator5, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -8164,7 +8090,7 @@ static PyObject *__pyx_pf_5_cdec_14HypergraphNode_9out_edges___get__(struct __py __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.HypergraphNode.out_edges.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Hypergraph.kbest_trees", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); @@ -8173,1160 +8099,1306 @@ static PyObject *__pyx_pf_5_cdec_14HypergraphNode_9out_edges___get__(struct __py return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_14HypergraphNode_9out_edges_2generator10(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator5(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *)__pyx_generator->closure); + struct __pyx_obj_5_cdec___pyx_scope_struct_9_kbest_trees *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_9_kbest_trees *)__pyx_generator->closure); PyObject *__pyx_r = NULL; - size_t __pyx_t_1; - unsigned int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; + unsigned int __pyx_t_1; + long __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_resume_from_yield; + case 1: goto __pyx_L10_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[2]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":197 - * def __get__(self): - * cdef unsigned i - * for i in range(self.node.out_edges_.size()): # <<<<<<<<<<<<<< - * yield HypergraphEdge().init(self.hg, self.node.out_edges_[i]) + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":44 * + * def kbest_trees(self, size): + * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal]* f_derivations = new kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal](self.hg[0], size) # <<<<<<<<<<<<<< + * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal].Derivation* f_derivation + * cdef kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal]* e_derivations = new kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal](self.hg[0], size) */ - __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->node->out_edges_.size(); - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + __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[3]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_f_derivations = new KBest::KBestDerivations,FTreeTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":198 - * cdef unsigned i - * for i in range(self.node.out_edges_.size()): - * yield HypergraphEdge().init(self.hg, self.node.out_edges_[i]) # <<<<<<<<<<<<<< - * - * property span: + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":46 + * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal]* f_derivations = new kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal](self.hg[0], size) + * cdef kbest.KBestDerivations[vector[WordID], kbest.FTreeTraversal].Derivation* f_derivation + * cdef kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal]* e_derivations = new kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal](self.hg[0], size) # <<<<<<<<<<<<<< + * cdef kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal].Derivation* e_derivation + * cdef unsigned k */ - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphEdge)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = ((struct __pyx_vtabstruct_5_cdec_HypergraphEdge *)((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_t_3)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_t_3), __pyx_cur_scope->__pyx_v_self->hg, (__pyx_cur_scope->__pyx_v_self->node->out_edges_[__pyx_cur_scope->__pyx_v_i])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 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_generator->resume_label = 1; - return __pyx_r; - __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[2]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; - __Pyx_RefNannyFinishContext(); - return NULL; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_14HypergraphNode_4span_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_14HypergraphNode_4span_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_14HypergraphNode_4span___get__(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + __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[3]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_e_derivations = new KBest::KBestDerivations,ETreeTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":201 - * - * property span: - * def __get__(self): # <<<<<<<<<<<<<< - * return next(self.in_edges).span - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":49 + * cdef kbest.KBestDerivations[vector[WordID], kbest.ETreeTraversal].Derivation* e_derivation + * cdef unsigned k + * try: # <<<<<<<<<<<<<< + * for k in range(size): + * f_derivation = f_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) */ + /*try:*/ { -static PyObject *__pyx_pf_5_cdec_14HypergraphNode_4span___get__(struct __pyx_obj_5_cdec_HypergraphNode *__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("__get__", 0); + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":50 + * cdef unsigned k + * try: + * for k in range(size): # <<<<<<<<<<<<<< + * f_derivation = f_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * e_derivation = e_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + */ + __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[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L5;} + for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { + __pyx_cur_scope->__pyx_v_k = __pyx_t_1; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":202 - * property span: - * def __get__(self): - * return next(self.in_edges).span # <<<<<<<<<<<<<< - * - * property cat: + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":51 + * try: + * for k in range(size): + * f_derivation = f_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< + * e_derivation = e_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not f_derivation or not e_derivation: break */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__in_edges); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyIter_Next(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__span); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 202; __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_cur_scope->__pyx_v_f_derivation = __pyx_cur_scope->__pyx_v_f_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":52 + * for k in range(size): + * f_derivation = f_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * e_derivation = e_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< + * if not f_derivation or not e_derivation: break + * f_tree = unicode(GetString(f_derivation._yield).c_str(), 'utf8') + */ + __pyx_cur_scope->__pyx_v_e_derivation = __pyx_cur_scope->__pyx_v_e_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":53 + * f_derivation = f_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * e_derivation = e_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not f_derivation or not e_derivation: break # <<<<<<<<<<<<<< + * f_tree = unicode(GetString(f_derivation._yield).c_str(), 'utf8') + * e_tree = unicode(GetString(e_derivation._yield).c_str(), 'utf8') + */ + __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_f_derivation != 0)); + if (!__pyx_t_3) { + __pyx_t_4 = (!(__pyx_cur_scope->__pyx_v_e_derivation != 0)); + __pyx_t_5 = __pyx_t_4; + } else { + __pyx_t_5 = __pyx_t_3; + } + if (__pyx_t_5) { + goto __pyx_L8_break; + goto __pyx_L9; + } + __pyx_L9:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":54 + * e_derivation = e_derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not f_derivation or not e_derivation: break + * f_tree = unicode(GetString(f_derivation._yield).c_str(), 'utf8') # <<<<<<<<<<<<<< + * e_tree = unicode(GetString(e_derivation._yield).c_str(), 'utf8') + * yield (f_tree, e_tree) + */ + __pyx_t_6 = PyBytes_FromString(TD::GetString(__pyx_cur_scope->__pyx_v_f_derivation->yield).c_str()); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_6)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_6)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_7, 1, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __pyx_t_6 = 0; + __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_f_tree)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_f_tree)); + __Pyx_GIVEREF(__pyx_t_6); + __pyx_cur_scope->__pyx_v_f_tree = ((PyObject*)__pyx_t_6); + __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":55 + * if not f_derivation or not e_derivation: break + * f_tree = unicode(GetString(f_derivation._yield).c_str(), 'utf8') + * e_tree = unicode(GetString(e_derivation._yield).c_str(), 'utf8') # <<<<<<<<<<<<<< + * yield (f_tree, e_tree) + * finally: + */ + __pyx_t_6 = PyBytes_FromString(TD::GetString(__pyx_cur_scope->__pyx_v_e_derivation->yield).c_str()); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_6)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_6)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_7, 1, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __pyx_t_6 = 0; + __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_e_tree)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_e_tree)); + __Pyx_GIVEREF(__pyx_t_6); + __pyx_cur_scope->__pyx_v_e_tree = ((PyObject*)__pyx_t_6); + __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 + * f_tree = unicode(GetString(f_derivation._yield).c_str(), 'utf8') + * e_tree = unicode(GetString(e_derivation._yield).c_str(), 'utf8') + * yield (f_tree, e_tree) # <<<<<<<<<<<<<< + * finally: + * del f_derivations + */ + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_f_tree)); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_cur_scope->__pyx_v_f_tree)); + __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_f_tree)); + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_e_tree)); + PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_cur_scope->__pyx_v_e_tree)); + __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_e_tree)); + __pyx_r = ((PyObject *)__pyx_t_6); + __pyx_t_6 = 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_generator->resume_label = 1; + return __pyx_r; + __pyx_L10_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[3]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L5;} + } + __pyx_L8_break:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":58 + * yield (f_tree, e_tree) + * finally: + * del f_derivations # <<<<<<<<<<<<<< + * del e_derivations + * + */ + /*finally:*/ { + int __pyx_why; + PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; + int __pyx_exc_lineno; + __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; + __pyx_why = 0; goto __pyx_L6; + __pyx_L5: { + __pyx_why = 4; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); + __pyx_exc_lineno = __pyx_lineno; + goto __pyx_L6; + } + __pyx_L6:; + delete __pyx_cur_scope->__pyx_v_f_derivations; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":59 + * finally: + * del f_derivations + * del e_derivations # <<<<<<<<<<<<<< + * + * def kbest_features(self, size): + */ + delete __pyx_cur_scope->__pyx_v_e_derivations; + switch (__pyx_why) { + case 4: { + __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); + __pyx_lineno = __pyx_exc_lineno; + __pyx_exc_type = 0; + __pyx_exc_value = 0; + __pyx_exc_tb = 0; + goto __pyx_L1_error; + } + } + } + PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_cdec.HypergraphNode.span.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("kbest_trees", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return __pyx_r; + return NULL; } +static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator6(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_14HypergraphNode_3cat_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_14HypergraphNode_3cat_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_17kbest_features(PyObject *__pyx_v_self, PyObject *__pyx_v_size); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_17kbest_features(PyObject *__pyx_v_self, PyObject *__pyx_v_size) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_14HypergraphNode_3cat___get__(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_v_self)); + __Pyx_RefNannySetupContext("kbest_features (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_16kbest_features(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_size)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":205 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":61 + * del e_derivations * - * property cat: - * def __get__(self): # <<<<<<<<<<<<<< - * if self.node.cat_: - * return TDConvert(-self.node.cat_) + * def kbest_features(self, size): # <<<<<<<<<<<<<< + * cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal]* derivations = new kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal](self.hg[0], size) + * cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal].Derivation* derivation */ -static PyObject *__pyx_pf_5_cdec_14HypergraphNode_3cat___get__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_10Hypergraph_16kbest_features(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size) { + struct __pyx_obj_5_cdec___pyx_scope_struct_10_kbest_features *__pyx_cur_scope; 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("__get__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":206 - * property cat: - * def __get__(self): - * if self.node.cat_: # <<<<<<<<<<<<<< - * return TDConvert(-self.node.cat_) - * - */ - if (__pyx_v_self->node->cat_) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":207 - * def __get__(self): - * if self.node.cat_: - * return TDConvert(-self.node.cat_) # <<<<<<<<<<<<<< - * - * def __richcmp__(HypergraphNode x, HypergraphNode y, int op): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_self->node->cat_))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 207; __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; - goto __pyx_L3; + __Pyx_RefNannySetupContext("kbest_features", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_10_kbest_features *)__pyx_ptype_5_cdec___pyx_scope_struct_10_kbest_features->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_10_kbest_features, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __pyx_cur_scope->__pyx_v_size = __pyx_v_size; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_18generator6, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; } - __pyx_L3:; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.HypergraphNode.cat.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Hypergraph.kbest_features", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_14HypergraphNode_1__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op); /*proto*/ -static PyObject *__pyx_pw_5_cdec_14HypergraphNode_1__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op) { - PyObject *__pyx_r = 0; +static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator6(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_10_kbest_features *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_10_kbest_features *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + unsigned int __pyx_t_1; + long __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_HypergraphNode, 1, "x", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_HypergraphNode, 1, "y", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_14HypergraphNode___richcmp__(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_v_x), ((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_v_y), ((int)__pyx_v_op)); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":209 - * return TDConvert(-self.node.cat_) - * - * def __richcmp__(HypergraphNode x, HypergraphNode y, int op): # <<<<<<<<<<<<<< - * if op == 2: # == - * return x.node == y.node + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L10_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[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":62 + * + * def kbest_features(self, size): + * cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal]* derivations = new kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal](self.hg[0], size) # <<<<<<<<<<<<<< + * cdef kbest.KBestDerivations[FastSparseVector[weight_t], kbest.FeatureVectorTraversal].Derivation* derivation + * cdef SparseVector fmap */ + __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[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,FeatureVectorTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); -static PyObject *__pyx_pf_5_cdec_14HypergraphNode___richcmp__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_x, struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_y, int __pyx_v_op) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__richcmp__", 0); + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":66 + * cdef SparseVector fmap + * cdef unsigned k + * try: # <<<<<<<<<<<<<< + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + */ + /*try:*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":212 - * if op == 2: # == - * return x.node == y.node - * elif op == 3: # != # <<<<<<<<<<<<<< - * return not (x == y) - * raise NotImplemented('comparison not implemented for HypergraphNode') + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":67 + * cdef unsigned k + * try: + * for k in range(size): # <<<<<<<<<<<<<< + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break */ - switch (__pyx_v_op) { + __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[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L5;} + for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { + __pyx_cur_scope->__pyx_v_k = __pyx_t_1; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":210 - * - * def __richcmp__(HypergraphNode x, HypergraphNode y, int op): - * if op == 2: # == # <<<<<<<<<<<<<< - * return x.node == y.node - * elif op == 3: # != + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":68 + * try: + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< + * if not derivation: break + * fmap = SparseVector() */ - case 2: + __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":211 - * def __richcmp__(HypergraphNode x, HypergraphNode y, int op): - * if op == 2: # == - * return x.node == y.node # <<<<<<<<<<<<<< - * elif op == 3: # != - * return not (x == y) + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":69 + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break # <<<<<<<<<<<<<< + * fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_x->node == __pyx_v_y->node)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - break; + __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0)); + if (__pyx_t_3) { + goto __pyx_L8_break; + goto __pyx_L9; + } + __pyx_L9:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":212 - * if op == 2: # == - * return x.node == y.node - * elif op == 3: # != # <<<<<<<<<<<<<< - * return not (x == y) - * raise NotImplemented('comparison not implemented for HypergraphNode') + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":70 + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break + * fmap = SparseVector() # <<<<<<<<<<<<<< + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) + * yield fmap */ - case 3: + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_cur_scope->__pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_4); + __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":213 - * return x.node == y.node - * elif op == 3: # != - * return not (x == y) # <<<<<<<<<<<<<< - * raise NotImplemented('comparison not implemented for HypergraphNode') + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":71 + * if not derivation: break + * fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) # <<<<<<<<<<<<<< + * yield fmap + * finally: */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - break; - } + __pyx_cur_scope->__pyx_v_fmap->vector = new FastSparseVector(__pyx_cur_scope->__pyx_v_derivation->yield); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":214 - * elif op == 3: # != - * return not (x == y) - * raise NotImplemented('comparison not implemented for HypergraphNode') # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":72 + * fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) + * yield fmap # <<<<<<<<<<<<<< + * finally: + * del derivations */ - __pyx_t_1 = PyObject_Call(__pyx_builtin_NotImplemented, ((PyObject *)__pyx_k_tuple_16), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); + __pyx_r = ((PyObject *)__pyx_cur_scope->__pyx_v_fmap); + __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_generator->resume_label = 1; + return __pyx_r; + __pyx_L10_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[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L5;} + } + __pyx_L8_break:; + } - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":74 + * yield fmap + * finally: + * del derivations # <<<<<<<<<<<<<< + * + * def sample(self, unsigned n): + */ + /*finally:*/ { + int __pyx_why; + PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; + int __pyx_exc_lineno; + __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; + __pyx_why = 0; goto __pyx_L6; + __pyx_L5: { + __pyx_why = 4; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); + __pyx_exc_lineno = __pyx_lineno; + goto __pyx_L6; + } + __pyx_L6:; + delete __pyx_cur_scope->__pyx_v_derivations; + switch (__pyx_why) { + case 4: { + __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); + __pyx_lineno = __pyx_exc_lineno; + __pyx_exc_type = 0; + __pyx_exc_value = 0; + __pyx_exc_tb = 0; + goto __pyx_L1_error; + } + } + } + PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.HypergraphNode.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("kbest_features", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return __pyx_r; + return NULL; } +static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator7(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static int __pyx_pw_5_cdec_7Lattice_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5_cdec_7Lattice_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_inp = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__inp,0}; - int __pyx_r; +static PyObject *__pyx_pw_5_cdec_10Hypergraph_20sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_20sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n) { + unsigned int __pyx_v_n; + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); - { - PyObject* values[1] = {0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__inp); - 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, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 6; __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_inp = values[0]; + __Pyx_RefNannySetupContext("sample (wrapper)", 0); + assert(__pyx_arg_n); { + __pyx_v_n = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_n); if (unlikely((__pyx_v_n == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } 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[3]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.Lattice.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Hypergraph.sample", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); - return -1; + return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_7Lattice___init__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), __pyx_v_inp); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_19sample(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((unsigned int)__pyx_v_n)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":6 - * cdef lattice.Lattice* lattice +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":76 + * del derivations * - * def __init__(self, inp): # <<<<<<<<<<<<<< - * if isinstance(inp, tuple): - * self.lattice = new lattice.Lattice(len(inp)) + * def sample(self, unsigned n): # <<<<<<<<<<<<<< + * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() + * if self.rng == NULL: */ -static int __pyx_pf_5_cdec_7Lattice___init__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, PyObject *__pyx_v_inp) { - PyObject *__pyx_v_i = NULL; - PyObject *__pyx_v_arcs = NULL; - int __pyx_r; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_19sample(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, unsigned int __pyx_v_n) { + struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample *__pyx_cur_scope; + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - Py_ssize_t __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *(*__pyx_t_5)(PyObject *); - PyObject *__pyx_t_6 = NULL; - int __pyx_t_7; - char *__pyx_t_8; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__init__", 0); - __Pyx_INCREF(__pyx_v_inp); + __Pyx_RefNannySetupContext("sample", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample *)__pyx_ptype_5_cdec___pyx_scope_struct_11_sample->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_11_sample, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __pyx_cur_scope->__pyx_v_n = __pyx_v_n; + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_21generator7, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":7 - * - * def __init__(self, inp): - * if isinstance(inp, tuple): # <<<<<<<<<<<<<< - * self.lattice = new lattice.Lattice(len(inp)) - * for i, arcs in enumerate(inp): - */ - __pyx_t_1 = ((PyObject *)((PyObject*)(&PyTuple_Type))); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_inp, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Hypergraph.sample", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":8 - * def __init__(self, inp): - * if isinstance(inp, tuple): - * self.lattice = new lattice.Lattice(len(inp)) # <<<<<<<<<<<<<< - * for i, arcs in enumerate(inp): - * self[i] = arcs +static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator7(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample *)__pyx_generator->closure); + 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", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L10_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[3]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":77 + * + * def sample(self, unsigned n): + * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() # <<<<<<<<<<<<<< + * if self.rng == NULL: + * self.rng = new MT19937() */ - __pyx_t_3 = PyObject_Length(__pyx_v_inp); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->lattice = new Lattice(__pyx_t_3); + __pyx_cur_scope->__pyx_v_hypos = new std::vector(); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":9 - * if isinstance(inp, tuple): - * self.lattice = new lattice.Lattice(len(inp)) - * for i, arcs in enumerate(inp): # <<<<<<<<<<<<<< - * self[i] = arcs - * else: + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":78 + * def sample(self, unsigned n): + * 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_INCREF(__pyx_int_0); - __pyx_t_1 = __pyx_int_0; - if (PyList_CheckExact(__pyx_v_inp) || PyTuple_CheckExact(__pyx_v_inp)) { - __pyx_t_4 = __pyx_v_inp; __Pyx_INCREF(__pyx_t_4); __pyx_t_3 = 0; - __pyx_t_5 = NULL; - } else { - __pyx_t_3 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_inp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; - } - for (;;) { - if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_4)) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_4)) break; - __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; - } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_4)) { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; - } else { - __pyx_t_6 = __pyx_t_5(__pyx_t_4); - if (unlikely(!__pyx_t_6)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_6); - } - __Pyx_XDECREF(__pyx_v_arcs); - __pyx_v_arcs = __pyx_t_6; - __pyx_t_6 = 0; - __Pyx_INCREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_1; - __pyx_t_6 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); - __pyx_t_1 = __pyx_t_6; - __pyx_t_6 = 0; + __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->rng == NULL); + if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":10 - * self.lattice = new lattice.Lattice(len(inp)) - * for i, arcs in enumerate(inp): - * self[i] = arcs # <<<<<<<<<<<<<< - * else: - * if isinstance(inp, unicode): + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":79 + * 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 unsigned k */ - if (PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_v_i, __pyx_v_arcs) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L3; + __pyx_cur_scope->__pyx_v_self->rng = new MT19937(); + goto __pyx_L4; } - /*else*/ { + __pyx_L4:; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":12 - * self[i] = arcs - * else: - * if isinstance(inp, unicode): # <<<<<<<<<<<<<< - * inp = inp.encode('utf8') - * if not isinstance(inp, str): + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":80 + * if self.rng == NULL: + * self.rng = new MT19937() + * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) # <<<<<<<<<<<<<< + * cdef unsigned k + * try: */ - __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_inp, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { + HypergraphSampler::sample_hypotheses((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_cur_scope->__pyx_v_n, __pyx_cur_scope->__pyx_v_self->rng, __pyx_cur_scope->__pyx_v_hypos); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":13 - * else: - * if isinstance(inp, unicode): - * inp = inp.encode('utf8') # <<<<<<<<<<<<<< - * if not isinstance(inp, str): - * raise TypeError('Cannot create lattice from %s' % type(inp)) + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":82 + * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) + * cdef unsigned k + * try: # <<<<<<<<<<<<<< + * for k in range(hypos.size()): + * yield unicode(GetString(hypos[0][k].words).c_str(), 'utf8') */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_inp, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_17), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_v_inp); - __pyx_v_inp = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L6; - } - __pyx_L6:; + /*try:*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":14 - * if isinstance(inp, unicode): - * inp = inp.encode('utf8') - * if not isinstance(inp, str): # <<<<<<<<<<<<<< - * raise TypeError('Cannot create lattice from %s' % type(inp)) - * self.lattice = new lattice.Lattice() + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":83 + * cdef unsigned k + * try: + * for k in range(hypos.size()): # <<<<<<<<<<<<<< + * yield unicode(GetString(hypos[0][k].words).c_str(), 'utf8') + * finally: */ - __pyx_t_4 = ((PyObject *)((PyObject*)(&PyString_Type))); - __Pyx_INCREF(__pyx_t_4); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_inp, __pyx_t_4); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_7 = (!__pyx_t_2); - if (__pyx_t_7) { + __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; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":15 - * inp = inp.encode('utf8') - * if not isinstance(inp, str): - * raise TypeError('Cannot create lattice from %s' % type(inp)) # <<<<<<<<<<<<<< - * self.lattice = new lattice.Lattice() - * lattice.ConvertTextToLattice(string(inp), self.lattice) + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":84 + * try: + * for k in range(hypos.size()): + * yield unicode(GetString(hypos[0][k].words).c_str(), 'utf8') # <<<<<<<<<<<<<< + * finally: + * del hypos */ - __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), ((PyObject *)Py_TYPE(__pyx_v_inp))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __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[3]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4)); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_4)); __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L7; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 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_generator->resume_label = 1; + return __pyx_r; + __pyx_L10_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[3]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} } - __pyx_L7:; + } - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":16 - * if not isinstance(inp, str): - * raise TypeError('Cannot create lattice from %s' % type(inp)) - * self.lattice = new lattice.Lattice() # <<<<<<<<<<<<<< - * lattice.ConvertTextToLattice(string(inp), self.lattice) + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":86 + * yield unicode(GetString(hypos[0][k].words).c_str(), 'utf8') + * finally: + * del hypos # <<<<<<<<<<<<<< * + * def intersect(self, Lattice lat): */ - __pyx_v_self->lattice = new Lattice(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":17 - * raise TypeError('Cannot create lattice from %s' % type(inp)) - * self.lattice = new lattice.Lattice() - * lattice.ConvertTextToLattice(string(inp), self.lattice) # <<<<<<<<<<<<<< + /*finally:*/ { + int __pyx_why; + PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; + int __pyx_exc_lineno; + __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; + __pyx_why = 0; goto __pyx_L7; + __pyx_L6: { + __pyx_why = 4; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); + __pyx_exc_lineno = __pyx_lineno; + goto __pyx_L7; + } + __pyx_L7:; + delete __pyx_cur_scope->__pyx_v_hypos; + switch (__pyx_why) { + case 4: { + __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); + __pyx_lineno = __pyx_exc_lineno; + __pyx_exc_type = 0; + __pyx_exc_value = 0; + __pyx_exc_tb = 0; + goto __pyx_L1_error; + } + } + } + PyErr_SetNone(PyExc_StopIteration); + 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_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_23intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_23intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("intersect (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lat), __pyx_ptype_5_cdec_Lattice, 1, "lat", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_22intersect(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_lat)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":88 + * del hypos + * + * def intersect(self, Lattice lat): # <<<<<<<<<<<<<< + * return hypergraph.Intersect(lat.lattice[0], self.hg) * - * def __getitem__(self, int index): */ - __pyx_t_8 = PyBytes_AsString(__pyx_v_inp); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - LatticeTools::ConvertTextToLattice(std::string(((char *)__pyx_t_8)), __pyx_v_self->lattice); - } - __pyx_L3:; - __pyx_r = 0; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_22intersect(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, struct __pyx_obj_5_cdec_Lattice *__pyx_v_lat) { + 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("intersect", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":89 + * + * def intersect(self, Lattice lat): + * return hypergraph.Intersect(lat.lattice[0], self.hg) # <<<<<<<<<<<<<< + * + * def prune(self, beam_alpha=0, density=0, **kwargs): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong(HG::Intersect((__pyx_v_lat->lattice[0]), __pyx_v_self->hg)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_4); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("_cdec.Lattice.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_AddTraceback("_cdec.Hypergraph.intersect", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_i); - __Pyx_XDECREF(__pyx_v_arcs); - __Pyx_XDECREF(__pyx_v_inp); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Lattice_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Lattice_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index) { - int __pyx_v_index; +static PyObject *__pyx_pw_5_cdec_10Hypergraph_25prune(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_25prune(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_beam_alpha = 0; + PyObject *__pyx_v_density = 0; + PyObject *__pyx_v_kwargs = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__beam_alpha,&__pyx_n_s__density,0}; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); - assert(__pyx_arg_index); { - __pyx_v_index = __Pyx_PyInt_AsInt(__pyx_arg_index); if (unlikely((__pyx_v_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RefNannySetupContext("prune (wrapper)", 0); + __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL; + __Pyx_GOTREF(__pyx_v_kwargs); + { + PyObject* values[2] = {0,0}; + values[0] = ((PyObject *)__pyx_int_0); + values[1] = ((PyObject *)__pyx_int_0); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__beam_alpha); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__density); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "prune") < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_beam_alpha = values[0]; + __pyx_v_density = values[1]; } goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("prune", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.Lattice.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; + __Pyx_AddTraceback("_cdec.Hypergraph.prune", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_7Lattice_2__getitem__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), ((int)__pyx_v_index)); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_24prune(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), __pyx_v_beam_alpha, __pyx_v_density, __pyx_v_kwargs); + __Pyx_XDECREF(__pyx_v_kwargs); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":19 - * lattice.ConvertTextToLattice(string(inp), self.lattice) +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":91 + * return hypergraph.Intersect(lat.lattice[0], self.hg) * - * def __getitem__(self, int index): # <<<<<<<<<<<<<< - * if not 0 <= index < len(self): - * raise IndexError('lattice index out of range') + * def prune(self, beam_alpha=0, density=0, **kwargs): # <<<<<<<<<<<<<< + * cdef hypergraph.EdgeMask* preserve_mask = NULL + * if 'csplit_preserve_full_word' in kwargs: */ -static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index) { - PyObject *__pyx_v_arcs = NULL; - std::vector __pyx_v_arc_vector; - LatticeArc *__pyx_v_arc; - unsigned int __pyx_v_i; - PyObject *__pyx_v_label = NULL; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_24prune(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_beam_alpha, PyObject *__pyx_v_density, PyObject *__pyx_v_kwargs) { + std::vector *__pyx_v_preserve_mask; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; - Py_ssize_t __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - size_t __pyx_t_5; - unsigned int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - int __pyx_t_9; + double __pyx_t_2; + double __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__getitem__", 0); + __Pyx_RefNannySetupContext("prune", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":20 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":92 * - * def __getitem__(self, int index): - * if not 0 <= index < len(self): # <<<<<<<<<<<<<< - * raise IndexError('lattice index out of range') - * arcs = [] + * def prune(self, beam_alpha=0, density=0, **kwargs): + * cdef hypergraph.EdgeMask* preserve_mask = NULL # <<<<<<<<<<<<<< + * if 'csplit_preserve_full_word' in kwargs: + * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) */ - __pyx_t_1 = (0 <= __pyx_v_index); + __pyx_v_preserve_mask = NULL; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":93 + * def prune(self, beam_alpha=0, density=0, **kwargs): + * cdef hypergraph.EdgeMask* preserve_mask = NULL + * if 'csplit_preserve_full_word' in kwargs: # <<<<<<<<<<<<<< + * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) + * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True + */ + __pyx_t_1 = ((PyDict_Contains(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s_15)))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_1) { - __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = (__pyx_v_index < __pyx_t_2); - } - __pyx_t_3 = (!__pyx_t_1); - if (__pyx_t_3) { - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":21 - * def __getitem__(self, int index): - * if not 0 <= index < len(self): - * raise IndexError('lattice index out of range') # <<<<<<<<<<<<<< - * arcs = [] - * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":94 + * cdef hypergraph.EdgeMask* preserve_mask = NULL + * if 'csplit_preserve_full_word' in kwargs: + * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) # <<<<<<<<<<<<<< + * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True + * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) */ - __pyx_t_4 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_preserve_mask = new std::vector(__pyx_v_self->hg->edges_.size()); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":95 + * if 'csplit_preserve_full_word' in kwargs: + * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) + * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True # <<<<<<<<<<<<<< + * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) + * if preserve_mask: + */ + ((__pyx_v_preserve_mask[0])[CompoundSplit::GetFullWordEdgeIndex((__pyx_v_self->hg[0]))]) = 1; goto __pyx_L3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":22 - * if not 0 <= index < len(self): - * raise IndexError('lattice index out of range') - * arcs = [] # <<<<<<<<<<<<<< - * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] - * cdef lattice.LatticeArc* arc + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":96 + * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) + * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True + * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) # <<<<<<<<<<<<<< + * if preserve_mask: + * del preserve_mask */ - __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_v_arcs = __pyx_t_4; - __pyx_t_4 = 0; + __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_beam_alpha); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_density); if (unlikely((__pyx_t_3 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->hg->PruneInsideOutside(__pyx_t_2, __pyx_t_3, __pyx_v_preserve_mask, 0, 1.0, 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":23 - * raise IndexError('lattice index out of range') - * arcs = [] - * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] # <<<<<<<<<<<<<< - * cdef lattice.LatticeArc* arc - * cdef unsigned i + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":97 + * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True + * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) + * if preserve_mask: # <<<<<<<<<<<<<< + * del preserve_mask + * */ - __pyx_v_arc_vector = ((__pyx_v_self->lattice[0])[__pyx_v_index]); + __pyx_t_1 = (__pyx_v_preserve_mask != 0); + if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":26 - * cdef lattice.LatticeArc* arc - * cdef unsigned i - * for i in range(arc_vector.size()): # <<<<<<<<<<<<<< - * arc = &arc_vector[i] - * label = unicode(TDConvert(arc.label), 'utf8') + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":98 + * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) + * if preserve_mask: + * del preserve_mask # <<<<<<<<<<<<<< + * + * def lattice(self): # TODO direct hg -> lattice conversion in cdec */ - __pyx_t_5 = __pyx_v_arc_vector.size(); - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_v_i = __pyx_t_6; + delete __pyx_v_preserve_mask; + goto __pyx_L4; + } + __pyx_L4:; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":27 - * cdef unsigned i - * for i in range(arc_vector.size()): - * arc = &arc_vector[i] # <<<<<<<<<<<<<< - * label = unicode(TDConvert(arc.label), 'utf8') - * arcs.append((label, arc.cost, arc.dist2next)) - */ - __pyx_v_arc = (&(__pyx_v_arc_vector[__pyx_v_i])); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Hypergraph.prune", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":28 - * for i in range(arc_vector.size()): - * arc = &arc_vector[i] - * label = unicode(TDConvert(arc.label), 'utf8') # <<<<<<<<<<<<<< - * arcs.append((label, arc.cost, arc.dist2next)) - * return tuple(arcs) +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_27lattice(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_27lattice(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("lattice (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_26lattice(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":100 + * del preserve_mask + * + * def lattice(self): # TODO direct hg -> lattice conversion in cdec # <<<<<<<<<<<<<< + * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() + * return Lattice(eval(plf)) */ - __pyx_t_4 = PyBytes_FromString(TD::Convert(__pyx_v_arc->label)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_4)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_t_7, 1, ((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; - __Pyx_XDECREF(((PyObject *)__pyx_v_label)); - __pyx_v_label = ((PyObject*)__pyx_t_4); - __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":29 - * arc = &arc_vector[i] - * label = unicode(TDConvert(arc.label), 'utf8') - * arcs.append((label, arc.cost, arc.dist2next)) # <<<<<<<<<<<<<< - * return tuple(arcs) +static PyObject *__pyx_pf_5_cdec_10Hypergraph_26lattice(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + PyObject *__pyx_v_plf = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("lattice", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":101 + * + * def lattice(self): # TODO direct hg -> lattice conversion in cdec + * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() # <<<<<<<<<<<<<< + * return Lattice(eval(plf)) * */ - __pyx_t_4 = PyFloat_FromDouble(__pyx_v_arc->cost); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = PyInt_FromLong(__pyx_v_arc->dist2next); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(((PyObject *)__pyx_v_label)); - PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_v_label)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_label)); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - __pyx_t_4 = 0; - __pyx_t_7 = 0; - __pyx_t_9 = PyList_Append(__pyx_v_arcs, ((PyObject *)__pyx_t_8)); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; - } + __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->hg[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 101; __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[3]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_plf = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":30 - * label = unicode(TDConvert(arc.label), 'utf8') - * arcs.append((label, arc.cost, arc.dist2next)) - * return tuple(arcs) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":102 + * def lattice(self): # TODO direct hg -> lattice conversion in cdec + * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() + * return Lattice(eval(plf)) # <<<<<<<<<<<<<< * - * def __setitem__(self, int index, tuple arcs): + * def reweight(self, weights): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_8 = ((PyObject *)PyList_AsTuple(__pyx_v_arcs)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_8)); - __pyx_r = ((PyObject *)__pyx_t_8); - __pyx_t_8 = 0; + __pyx_t_1 = __Pyx_Globals(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + if (((PyObject *)__pyx_v_plf)) { + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__plf), ((PyObject *)__pyx_v_plf)) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + if (((PyObject *)__pyx_v_self)) { + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_v_self)) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(((PyObject *)__pyx_v_plf)); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_plf)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_plf)); + PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_builtin_eval, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 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_4); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("_cdec.Lattice.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec.Hypergraph.lattice", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_arcs); - __Pyx_XDECREF(__pyx_v_label); + __Pyx_XDECREF(__pyx_v_plf); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static int __pyx_pw_5_cdec_7Lattice_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index, PyObject *__pyx_v_arcs); /*proto*/ -static int __pyx_pw_5_cdec_7Lattice_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index, PyObject *__pyx_v_arcs) { - int __pyx_v_index; - int __pyx_r; +static PyObject *__pyx_pw_5_cdec_10Hypergraph_29reweight(PyObject *__pyx_v_self, PyObject *__pyx_v_weights); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_29reweight(PyObject *__pyx_v_self, PyObject *__pyx_v_weights) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); - assert(__pyx_arg_index); { - __pyx_v_index = __Pyx_PyInt_AsInt(__pyx_arg_index); if (unlikely((__pyx_v_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.Lattice.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_arcs), (&PyTuple_Type), 1, "arcs", 1))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_7Lattice_4__setitem__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), ((int)__pyx_v_index), ((PyObject*)__pyx_v_arcs)); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = -1; - __pyx_L0:; + __Pyx_RefNannySetupContext("reweight (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_28reweight(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_weights)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":32 - * return tuple(arcs) +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":104 + * return Lattice(eval(plf)) * - * def __setitem__(self, int index, tuple arcs): # <<<<<<<<<<<<<< - * if not 0 <= index < len(self): - * raise IndexError('lattice index out of range') + * def reweight(self, weights): # <<<<<<<<<<<<<< + * if isinstance(weights, SparseVector): + * self.hg.Reweight(( weights).vector[0]) */ -static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index, PyObject *__pyx_v_arcs) { - LatticeArc *__pyx_v_arc; - PyObject *__pyx_v_label = NULL; - PyObject *__pyx_v_cost = NULL; - PyObject *__pyx_v_dist2next = NULL; - int __pyx_r; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_weights) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - int __pyx_t_1; - Py_ssize_t __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *(*__pyx_t_10)(PyObject *); - char *__pyx_t_11; - double __pyx_t_12; - int __pyx_t_13; + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__setitem__", 0); + __Pyx_RefNannySetupContext("reweight", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":33 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":105 * - * def __setitem__(self, int index, tuple arcs): - * if not 0 <= index < len(self): # <<<<<<<<<<<<<< - * raise IndexError('lattice index out of range') - * cdef lattice.LatticeArc* arc + * def reweight(self, weights): + * if isinstance(weights, SparseVector): # <<<<<<<<<<<<<< + * self.hg.Reweight(( weights).vector[0]) + * elif isinstance(weights, DenseVector): */ - __pyx_t_1 = (0 <= __pyx_v_index); - if (__pyx_t_1) { - __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = (__pyx_v_index < __pyx_t_2); - } - __pyx_t_3 = (!__pyx_t_1); - if (__pyx_t_3) { + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":34 - * def __setitem__(self, int index, tuple arcs): - * if not 0 <= index < len(self): - * raise IndexError('lattice index out of range') # <<<<<<<<<<<<<< - * cdef lattice.LatticeArc* arc - * for (label, cost, dist2next) in arcs: + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":106 + * def reweight(self, weights): + * if isinstance(weights, SparseVector): + * self.hg.Reweight(( weights).vector[0]) # <<<<<<<<<<<<<< + * elif isinstance(weights, DenseVector): + * self.hg.Reweight(( weights).vector[0]) */ - __pyx_t_4 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_21), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->hg->Reweight((((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_weights)->vector[0])); goto __pyx_L3; } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":36 - * raise IndexError('lattice index out of range') - * cdef lattice.LatticeArc* arc - * for (label, cost, dist2next) in arcs: # <<<<<<<<<<<<<< - * if isinstance(label, unicode): - * label = label.encode('utf8') - */ - if (unlikely(((PyObject *)__pyx_v_arcs) == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_4 = ((PyObject *)__pyx_v_arcs); __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0; - for (;;) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; - if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) { - PyObject* sequence = __pyx_t_5; - if (likely(PyTuple_CheckExact(sequence))) { - if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { - if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 2); - } else { - if (unlikely(PyList_GET_SIZE(sequence) != 3)) { - if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_6 = PyList_GET_ITEM(sequence, 0); - __pyx_t_7 = PyList_GET_ITEM(sequence, 1); - __pyx_t_8 = PyList_GET_ITEM(sequence, 2); - } - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_9 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; - index = 0; __pyx_t_6 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_6); - index = 1; __pyx_t_7 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - index = 2; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_8); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L7_unpacking_done; - __pyx_L6_unpacking_failed:; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L7_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_label); - __pyx_v_label = __pyx_t_6; - __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_v_cost); - __pyx_v_cost = __pyx_t_7; - __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_v_dist2next); - __pyx_v_dist2next = __pyx_t_8; - __pyx_t_8 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":37 - * cdef lattice.LatticeArc* arc - * for (label, cost, dist2next) in arcs: - * if isinstance(label, unicode): # <<<<<<<<<<<<<< - * label = label.encode('utf8') - * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) - */ - __pyx_t_5 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); - __Pyx_INCREF(__pyx_t_5); - __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_label, __pyx_t_5); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":38 - * for (label, cost, dist2next) in arcs: - * if isinstance(label, unicode): - * label = label.encode('utf8') # <<<<<<<<<<<<<< - * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) - * self.lattice[0][index].push_back(arc[0]) - */ - __pyx_t_5 = PyObject_GetAttr(__pyx_v_label, __pyx_n_s__encode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_22), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_v_label); - __pyx_v_label = __pyx_t_8; - __pyx_t_8 = 0; - goto __pyx_L8; - } - __pyx_L8:; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":39 - * if isinstance(label, unicode): - * label = label.encode('utf8') - * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) # <<<<<<<<<<<<<< - * self.lattice[0][index].push_back(arc[0]) - * del arc + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":107 + * if isinstance(weights, SparseVector): + * self.hg.Reweight(( weights).vector[0]) + * elif isinstance(weights, DenseVector): # <<<<<<<<<<<<<< + * self.hg.Reweight(( weights).vector[0]) + * else: */ - __pyx_t_11 = PyBytes_AsString(__pyx_v_label); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_v_cost); if (unlikely((__pyx_t_12 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_v_dist2next); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_arc = new LatticeArc(TD::Convert(((char *)__pyx_t_11)), __pyx_t_12, __pyx_t_13); + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":40 - * label = label.encode('utf8') - * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) - * self.lattice[0][index].push_back(arc[0]) # <<<<<<<<<<<<<< - * del arc - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":108 + * self.hg.Reweight(( weights).vector[0]) + * elif isinstance(weights, DenseVector): + * self.hg.Reweight(( weights).vector[0]) # <<<<<<<<<<<<<< + * else: + * raise TypeError('cannot reweight hypergraph with %s' % type(weights)) */ - ((__pyx_v_self->lattice[0])[__pyx_v_index]).push_back((__pyx_v_arc[0])); + __pyx_v_self->hg->Reweight((((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_weights)->vector[0])); + goto __pyx_L3; + } + /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":41 - * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) - * self.lattice[0][index].push_back(arc[0]) - * del arc # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":110 + * self.hg.Reweight(( weights).vector[0]) + * else: + * raise TypeError('cannot reweight hypergraph with %s' % type(weights)) # <<<<<<<<<<<<<< * - * def __len__(self): + * property edges: */ - delete __pyx_v_arc; + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_16), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_L3:; - __pyx_r = 0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("_cdec.Lattice.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec.Hypergraph.reweight", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_label); - __Pyx_XDECREF(__pyx_v_cost); - __Pyx_XDECREF(__pyx_v_dist2next); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5_cdec_10Hypergraph_5edges_2generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static Py_ssize_t __pyx_pw_5_cdec_7Lattice_7__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_5_cdec_7Lattice_7__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; +static PyObject *__pyx_pw_5_cdec_10Hypergraph_5edges_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_5edges_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Lattice_6__len__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_5edges___get__(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":43 - * del arc - * - * def __len__(self): # <<<<<<<<<<<<<< - * return self.lattice.size() +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":113 * + * property edges: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.hg.edges_.size()): */ -static Py_ssize_t __pyx_pf_5_cdec_7Lattice_6__len__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { - Py_ssize_t __pyx_r; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_5edges___get__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *__pyx_cur_scope; + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__", 0); + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *)__pyx_ptype_5_cdec___pyx_scope_struct_12___get__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_12___get__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_5edges_2generator8, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":44 - * - * def __len__(self): - * return self.lattice.size() # <<<<<<<<<<<<<< - * - * def __str__(self): - */ - __pyx_r = __pyx_v_self->lattice->size(); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - - __pyx_r = 0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Hypergraph.edges.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Lattice_9__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Lattice_9__str__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Lattice_8__str__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":46 - * return self.lattice.size() - * - * def __str__(self): # <<<<<<<<<<<<<< - * return hypergraph.AsPLF(self.lattice[0], True).c_str() - * - */ - -static PyObject *__pyx_pf_5_cdec_7Lattice_8__str__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { +static PyObject *__pyx_gb_5_cdec_10Hypergraph_5edges_2generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; + size_t __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__str__", 0); + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[3]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":47 - * - * def __str__(self): - * return hypergraph.AsPLF(self.lattice[0], True).c_str() # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":115 + * def __get__(self): + * cdef unsigned i + * for i in range(self.hg.edges_.size()): # <<<<<<<<<<<<<< + * yield HypergraphEdge().init(self.hg, i) * - * def __iter__(self): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->lattice[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 47; __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_t_1 = __pyx_cur_scope->__pyx_v_self->hg->edges_.size(); + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":116 + * cdef unsigned i + * for i in range(self.hg.edges_.size()): + * yield HypergraphEdge().init(self.hg, i) # <<<<<<<<<<<<<< + * + * property nodes: + */ + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphEdge)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = ((struct __pyx_vtabstruct_5_cdec_HypergraphEdge *)((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_t_3)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_t_3), __pyx_cur_scope->__pyx_v_self->hg, __pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 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_generator->resume_label = 1; + return __pyx_r; + __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[3]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + PyErr_SetNone(PyExc_StopIteration); 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_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return __pyx_r; + return NULL; } -static PyObject *__pyx_gb_5_cdec_7Lattice_12generator11(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5_cdec_10Hypergraph_5nodes_2generator9(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Lattice_11__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Lattice_11__iter__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_5nodes_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_5nodes_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Lattice_10__iter__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_5nodes___get__(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":49 - * return hypergraph.AsPLF(self.lattice[0], True).c_str() +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":119 * - * def __iter__(self): # <<<<<<<<<<<<<< - * cdef unsigned i - * for i in range(len(self)): + * property nodes: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.hg.nodes_.size()): */ -static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_5nodes___get__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__iter__", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_15___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_15___iter__, __pyx_empty_tuple, NULL); + __Pyx_RefNannySetupContext("__get__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *)__pyx_ptype_5_cdec___pyx_scope_struct_13___get__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_13___get__, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -9336,7 +9408,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lat __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Lattice_12generator11, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_5nodes_2generator9, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -9345,7 +9417,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lat __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Lattice.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Hypergraph.nodes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); @@ -9354,13 +9426,14 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lat return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_7Lattice_12generator11(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_10Hypergraph_5nodes_2generator9(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *)__pyx_generator->closure); + struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; - Py_ssize_t __pyx_t_1; + size_t __pyx_t_1; unsigned int __pyx_t_2; PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { @@ -9371,30 +9444,33 @@ static PyObject *__pyx_gb_5_cdec_7Lattice_12generator11(__pyx_GeneratorObject *_ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":51 - * def __iter__(self): - * cdef unsigned i - * for i in range(len(self)): # <<<<<<<<<<<<<< - * yield self[i] + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":121 + * def __get__(self): + * cdef unsigned i + * for i in range(self.hg.nodes_.size()): # <<<<<<<<<<<<<< + * yield HypergraphNode().init(self.hg, i) * */ - __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->hg->nodes_.size(); for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":52 - * cdef unsigned i - * for i in range(len(self)): - * yield self[i] # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":122 + * cdef unsigned i + * for i in range(self.hg.nodes_.size()): + * yield HypergraphNode().init(self.hg, i) # <<<<<<<<<<<<<< * - * def __dealloc__(self): + * property goal: */ - __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_4 = ((struct __pyx_vtabstruct_5_cdec_HypergraphNode *)((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_3)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_3), __pyx_cur_scope->__pyx_v_self->hg, __pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; __Pyx_XGIVEREF(__pyx_r); @@ -9405,13 +9481,14 @@ static PyObject *__pyx_gb_5_cdec_7Lattice_12generator11(__pyx_GeneratorObject *_ __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[3]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; @@ -9420,531 +9497,448 @@ static PyObject *__pyx_gb_5_cdec_7Lattice_12generator11(__pyx_GeneratorObject *_ } /* Python wrapper */ -static void __pyx_pw_5_cdec_7Lattice_14__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_7Lattice_14__dealloc__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_4goal_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_4goal_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_7Lattice_13__dealloc__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_4goal___get__(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":54 - * yield self[i] +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":125 * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.lattice + * property goal: + * def __get__(self): # <<<<<<<<<<<<<< + * return HypergraphNode().init(self.hg, self.hg.GoalNode()) * */ -static void __pyx_pf_5_cdec_7Lattice_13__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_10Hypergraph_4goal___get__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); + 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("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":55 - * - * def __dealloc__(self): - * del self.lattice # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":126 + * property goal: + * def __get__(self): + * return HypergraphNode().init(self.hg, self.hg.GoalNode()) # <<<<<<<<<<<<<< * - * def todot(self): + * property npaths: */ - delete __pyx_v_self->lattice; - - __Pyx_RefNannyFinishContext(); -} + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = ((struct __pyx_vtabstruct_5_cdec_HypergraphNode *)((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_1)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_1), __pyx_v_self->hg, __pyx_v_self->hg->GoalNode()); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 126; __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; -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Lattice_16todot(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Lattice_16todot(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("todot (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Lattice_15todot(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __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.goal.__get__", __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_7Lattice_5todot_2generator17(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Lattice_5todot_1lines(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyMethodDef __pyx_mdef_5_cdec_7Lattice_5todot_1lines = {__Pyx_NAMESTR("lines"), (PyCFunction)__pyx_pw_5_cdec_7Lattice_5todot_1lines, METH_NOARGS, __Pyx_DOCSTR(0)}; -static PyObject *__pyx_pw_5_cdec_7Lattice_5todot_1lines(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_6npaths_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_6npaths_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("lines (wrapper)", 0); - __pyx_self = __pyx_self; - __pyx_r = __pyx_pf_5_cdec_7Lattice_5todot_lines(__pyx_self); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_6npaths___get__(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":58 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":129 + * + * property npaths: + * def __get__(self): # <<<<<<<<<<<<<< + * return self.hg.NumberOfPaths() * - * def todot(self): - * def lines(): # <<<<<<<<<<<<<< - * yield 'digraph lattice {' - * yield 'rankdir = LR;' */ -static PyObject *__pyx_pf_5_cdec_7Lattice_5todot_lines(PyObject *__pyx_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_6npaths___get__(struct __pyx_obj_5_cdec_Hypergraph *__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("lines", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *)__pyx_ptype_5_cdec___pyx_scope_struct_17_lines->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_17_lines, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *) __Pyx_CyFunction_GetClosure(__pyx_self); - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Lattice_5todot_2generator17, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } + __Pyx_RefNannySetupContext("__get__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":130 + * property npaths: + * def __get__(self): + * return self.hg.NumberOfPaths() # <<<<<<<<<<<<<< + * + * def inside_outside(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->hg->NumberOfPaths()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_cdec.Lattice.todot.lines", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.Hypergraph.npaths.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_7Lattice_5todot_2generator17(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *)__pyx_generator->closure); +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_31inside_outside(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_31inside_outside(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("inside_outside (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_30inside_outside(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":132 + * return self.hg.NumberOfPaths() + * + * def inside_outside(self): # <<<<<<<<<<<<<< + * cdef FastSparseVector[LogVal[double]]* result = new FastSparseVector[LogVal[double]]() + * cdef LogVal[double] z = hypergraph.InsideOutside(self.hg[0], result) + */ + +static PyObject *__pyx_pf_5_cdec_10Hypergraph_30inside_outside(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + FastSparseVector > *__pyx_v_result; + LogVal __pyx_v_z; + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_vector = 0; + FastSparseVector >::const_iterator *__pyx_v_it; + CYTHON_UNUSED unsigned int __pyx_v_i; PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *(*__pyx_t_4)(PyObject *); - PyObject *__pyx_t_5 = NULL; - Py_ssize_t __pyx_t_6; - PyObject *(*__pyx_t_7)(PyObject *); - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *(*__pyx_t_12)(PyObject *); - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("None", 0); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L4_resume_from_yield; - case 2: goto __pyx_L5_resume_from_yield; - case 3: goto __pyx_L6_resume_from_yield; - case 4: goto __pyx_L13_resume_from_yield; - case 5: goto __pyx_L14_resume_from_yield; - case 6: goto __pyx_L15_resume_from_yield; - default: /* CPython raises the right error here */ - __Pyx_RefNannyFinishContext(); - return NULL; + size_t __pyx_t_2; + unsigned int __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("inside_outside", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":133 + * + * def inside_outside(self): + * cdef FastSparseVector[LogVal[double]]* result = new FastSparseVector[LogVal[double]]() # <<<<<<<<<<<<<< + * cdef LogVal[double] z = hypergraph.InsideOutside(self.hg[0], result) + * result[0] /= z + */ + __pyx_v_result = new FastSparseVector >(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":134 + * def inside_outside(self): + * cdef FastSparseVector[LogVal[double]]* result = new FastSparseVector[LogVal[double]]() + * cdef LogVal[double] z = hypergraph.InsideOutside(self.hg[0], result) # <<<<<<<<<<<<<< + * result[0] /= z + * cdef SparseVector vector = SparseVector() + */ + __pyx_v_z = InsideOutside, EdgeFeaturesAndProbWeightFunction>((__pyx_v_self->hg[0]), __pyx_v_result); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":135 + * cdef FastSparseVector[LogVal[double]]* result = new FastSparseVector[LogVal[double]]() + * cdef LogVal[double] z = hypergraph.InsideOutside(self.hg[0], result) + * result[0] /= z # <<<<<<<<<<<<<< + * cdef SparseVector vector = SparseVector() + * vector.vector = new FastSparseVector[double]() + */ + (__pyx_v_result[0]) /= __pyx_v_z; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":136 + * cdef LogVal[double] z = hypergraph.InsideOutside(self.hg[0], result) + * result[0] /= z + * cdef SparseVector vector = SparseVector() # <<<<<<<<<<<<<< + * vector.vector = new FastSparseVector[double]() + * cdef FastSparseVector[LogVal[double]].const_iterator* it = new FastSparseVector[LogVal[double]].const_iterator(result[0], False) + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":137 + * result[0] /= z + * cdef SparseVector vector = SparseVector() + * vector.vector = new FastSparseVector[double]() # <<<<<<<<<<<<<< + * cdef FastSparseVector[LogVal[double]].const_iterator* it = new FastSparseVector[LogVal[double]].const_iterator(result[0], False) + * cdef unsigned i + */ + __pyx_v_vector->vector = new FastSparseVector(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":138 + * cdef SparseVector vector = SparseVector() + * vector.vector = new FastSparseVector[double]() + * cdef FastSparseVector[LogVal[double]].const_iterator* it = new FastSparseVector[LogVal[double]].const_iterator(result[0], False) # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(result.size()): + */ + __pyx_v_it = new FastSparseVector >::const_iterator((__pyx_v_result[0]), 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":140 + * cdef FastSparseVector[LogVal[double]].const_iterator* it = new FastSparseVector[LogVal[double]].const_iterator(result[0], False) + * cdef unsigned i + * for i in range(result.size()): # <<<<<<<<<<<<<< + * vector.vector.set_value(it[0].ptr().first, log(it[0].ptr().second)) + * pinc(it[0]) # ++it + */ + __pyx_t_2 = __pyx_v_result->size(); + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":141 + * cdef unsigned i + * for i in range(result.size()): + * vector.vector.set_value(it[0].ptr().first, log(it[0].ptr().second)) # <<<<<<<<<<<<<< + * pinc(it[0]) # ++it + * del it + */ + __pyx_v_vector->vector->set_value((__pyx_v_it[0]).operator->()->first, log((__pyx_v_it[0]).operator->()->second)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":142 + * for i in range(result.size()): + * vector.vector.set_value(it[0].ptr().first, log(it[0].ptr().second)) + * pinc(it[0]) # ++it # <<<<<<<<<<<<<< + * del it + * del result + */ + (++(__pyx_v_it[0])); } - __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":59 - * def todot(self): - * def lines(): - * yield 'digraph lattice {' # <<<<<<<<<<<<<< - * yield 'rankdir = LR;' - * yield 'node [shape=circle];' + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":143 + * vector.vector.set_value(it[0].ptr().first, log(it[0].ptr().second)) + * pinc(it[0]) # ++it + * del it # <<<<<<<<<<<<<< + * del result + * return vector */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_23)); - __pyx_r = ((PyObject *)__pyx_kp_s_23); + delete __pyx_v_it; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":144 + * pinc(it[0]) # ++it + * del it + * del result # <<<<<<<<<<<<<< + * return vector + * + */ + delete __pyx_v_result; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":145 + * del it + * del result + * return vector # <<<<<<<<<<<<<< + * + * cdef class HypergraphEdge: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_vector)); + __pyx_r = ((PyObject *)__pyx_v_vector); + 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.Hypergraph.inside_outside", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_vector); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; return __pyx_r; - __pyx_L4_resume_from_yield:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +} - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":60 - * def lines(): - * yield 'digraph lattice {' - * yield 'rankdir = LR;' # <<<<<<<<<<<<<< - * yield 'node [shape=circle];' - * for i in range(len(self)): +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":152 + * cdef public BaseTRule trule + * + * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): # <<<<<<<<<<<<<< + * self.hg = hg + * self.edge = &hg.edges_[i] + */ + +static PyObject *__pyx_f_5_cdec_14HypergraphEdge_init(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self, Hypergraph *__pyx_v_hg, unsigned int __pyx_v_i) { + 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("init", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":153 + * + * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): + * self.hg = hg # <<<<<<<<<<<<<< + * self.edge = &hg.edges_[i] + * self.trule = BaseTRule() + */ + __pyx_v_self->hg = __pyx_v_hg; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":154 + * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): + * self.hg = hg + * self.edge = &hg.edges_[i] # <<<<<<<<<<<<<< + * self.trule = BaseTRule() + * self.trule.rule = new shared_ptr[grammar.TRule](self.edge.rule_) + */ + __pyx_v_self->edge = (&(__pyx_v_hg->edges_[__pyx_v_i])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":155 + * self.hg = hg + * self.edge = &hg.edges_[i] + * self.trule = BaseTRule() # <<<<<<<<<<<<<< + * self.trule.rule = new shared_ptr[grammar.TRule](self.edge.rule_) + * return self + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_BaseTRule)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->trule); + __Pyx_DECREF(((PyObject *)__pyx_v_self->trule)); + __pyx_v_self->trule = ((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":156 + * self.edge = &hg.edges_[i] + * self.trule = BaseTRule() + * self.trule.rule = new shared_ptr[grammar.TRule](self.edge.rule_) # <<<<<<<<<<<<<< + * return self + * + */ + __pyx_v_self->trule->rule = new boost::shared_ptr(__pyx_v_self->edge->rule_); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":157 + * self.trule = BaseTRule() + * self.trule.rule = new shared_ptr[grammar.TRule](self.edge.rule_) + * return self # <<<<<<<<<<<<<< + * + * def __len__(self): */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_24)); - __pyx_r = ((PyObject *)__pyx_kp_s_24); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); + 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.HypergraphEdge.init", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 2; return __pyx_r; - __pyx_L5_resume_from_yield:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +} - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":61 - * yield 'digraph lattice {' - * yield 'rankdir = LR;' - * yield 'node [shape=circle];' # <<<<<<<<<<<<<< - * for i in range(len(self)): - * for label, weight, delta in self[i]: - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_25)); - __pyx_r = ((PyObject *)__pyx_kp_s_25); - __Pyx_XGIVEREF(__pyx_r); +/* Python wrapper */ +static Py_ssize_t __pyx_pw_5_cdec_14HypergraphEdge_1__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_14HypergraphEdge_1__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge___len__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 3; return __pyx_r; - __pyx_L6_resume_from_yield:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +} - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":62 - * yield 'rankdir = LR;' - * yield 'node [shape=circle];' - * for i in range(len(self)): # <<<<<<<<<<<<<< - * for label, weight, delta in self[i]: - * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":159 + * return self + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.edge.tail_nodes_.size() + * */ - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_3)) break; - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; - } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; - } else { - __pyx_t_1 = __pyx_t_4(__pyx_t_3); - if (unlikely(!__pyx_t_1)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_i); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_i); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_v_i = __pyx_t_1; - __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":63 - * yield 'node [shape=circle];' - * for i in range(len(self)): - * for label, weight, delta in self[i]: # <<<<<<<<<<<<<< - * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) - * yield '%d [shape=doublecircle]' % len(self) +static Py_ssize_t __pyx_pf_5_cdec_14HypergraphEdge___len__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":160 + * + * def __len__(self): + * return self.edge.tail_nodes_.size() # <<<<<<<<<<<<<< + * + * property head_node: */ - __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_5 = __pyx_t_1; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; - __pyx_t_7 = NULL; - } else { - __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_5)) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break; - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; - } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_5)) { - if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break; - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; - } else { - __pyx_t_1 = __pyx_t_7(__pyx_t_5); - if (unlikely(!__pyx_t_1)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { - PyObject* sequence = __pyx_t_1; - if (likely(PyTuple_CheckExact(sequence))) { - if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { - if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); - } else { - if (unlikely(PyList_GET_SIZE(sequence) != 3)) { - if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_8 = PyList_GET_ITEM(sequence, 0); - __pyx_t_9 = PyList_GET_ITEM(sequence, 1); - __pyx_t_10 = PyList_GET_ITEM(sequence, 2); - } - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_11 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; - index = 0; __pyx_t_8 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_8)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_8); - index = 1; __pyx_t_9 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_9)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_9); - index = 2; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_10); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - goto __pyx_L12_unpacking_done; - __pyx_L11_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[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L12_unpacking_done:; - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_label); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_label); - __Pyx_GIVEREF(__pyx_t_8); - __pyx_cur_scope->__pyx_v_label = __pyx_t_8; - __pyx_t_8 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_weight); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_weight); - __Pyx_GIVEREF(__pyx_t_9); - __pyx_cur_scope->__pyx_v_weight = __pyx_t_9; - __pyx_t_9 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_delta); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_delta); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_cur_scope->__pyx_v_delta = __pyx_t_10; - __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":64 - * for i in range(len(self)): - * for label, weight, delta in self[i]: - * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) # <<<<<<<<<<<<<< - * yield '%d [shape=doublecircle]' % len(self) - * yield '}' - */ - __pyx_t_1 = PyNumber_Add(__pyx_cur_scope->__pyx_v_i, __pyx_cur_scope->__pyx_v_delta); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_label, __pyx_n_s__replace); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_9 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_k_tuple_29), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_i); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_cur_scope->__pyx_v_i); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_i); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - __pyx_t_1 = 0; - __pyx_t_9 = 0; - __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_26), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_9)); - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __pyx_r = ((PyObject *)__pyx_t_9); - __pyx_t_9 = 0; - __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; - __Pyx_XGIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; - __Pyx_XGIVEREF(__pyx_t_5); - __pyx_cur_scope->__pyx_t_3 = __pyx_t_5; - __pyx_cur_scope->__pyx_t_4 = __pyx_t_6; - __pyx_cur_scope->__pyx_t_5 = __pyx_t_7; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 4; - return __pyx_r; - __pyx_L13_resume_from_yield:; - __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; - __pyx_cur_scope->__pyx_t_1 = 0; - __Pyx_XGOTREF(__pyx_t_3); - __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; - __pyx_t_5 = __pyx_cur_scope->__pyx_t_3; - __pyx_cur_scope->__pyx_t_3 = 0; - __Pyx_XGOTREF(__pyx_t_5); - __pyx_t_6 = __pyx_cur_scope->__pyx_t_4; - __pyx_t_7 = __pyx_cur_scope->__pyx_t_5; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_v_self->edge->tail_nodes_.size(); + goto __pyx_L0; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":65 - * for label, weight, delta in self[i]: - * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) - * yield '%d [shape=doublecircle]' % len(self) # <<<<<<<<<<<<<< - * yield '}' - * return '\n'.join(lines()).encode('utf8') - */ - __pyx_t_3 = ((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self); - __Pyx_INCREF(__pyx_t_3); - __pyx_t_2 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_30), __pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = ((PyObject *)__pyx_t_5); - __pyx_t_5 = 0; - __Pyx_XGIVEREF(__pyx_r); + __pyx_r = 0; + __pyx_L0:; __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 5; return __pyx_r; - __pyx_L14_resume_from_yield:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +} - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":66 - * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) - * yield '%d [shape=doublecircle]' % len(self) - * yield '}' # <<<<<<<<<<<<<< - * return '\n'.join(lines()).encode('utf8') - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_31)); - __pyx_r = ((PyObject *)__pyx_kp_s_31); - __Pyx_XGIVEREF(__pyx_r); +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_9head_node_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_9head_node_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_9head_node___get__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 6; return __pyx_r; - __pyx_L15_resume_from_yield:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_AddTraceback("lines", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; - __Pyx_RefNannyFinishContext(); - return NULL; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":57 - * del self.lattice +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":163 + * + * property head_node: + * def __get__(self): # <<<<<<<<<<<<<< + * return HypergraphNode().init(self.hg, self.edge.head_node_) * - * def todot(self): # <<<<<<<<<<<<<< - * def lines(): - * yield 'digraph lattice {' */ -static PyObject *__pyx_pf_5_cdec_7Lattice_15todot(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *__pyx_cur_scope; - PyObject *__pyx_v_lines = 0; +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_9head_node___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("todot", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *)__pyx_ptype_5_cdec___pyx_scope_struct_16_todot->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_16_todot, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":58 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":164 + * property head_node: + * def __get__(self): + * return HypergraphNode().init(self.hg, self.edge.head_node_) # <<<<<<<<<<<<<< * - * def todot(self): - * def lines(): # <<<<<<<<<<<<<< - * yield 'digraph lattice {' - * yield 'rankdir = LR;' - */ - __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5_cdec_7Lattice_5todot_1lines, 0, ((PyObject*)__pyx_cur_scope), __pyx_n_s___cdec, ((PyObject *)__pyx_k_codeobj_33)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_lines = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":67 - * yield '%d [shape=doublecircle]' % len(self) - * yield '}' - * return '\n'.join(lines()).encode('utf8') # <<<<<<<<<<<<<< + * property tail_nodes: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_35), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_v_lines, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = ((struct __pyx_vtabstruct_5_cdec_HypergraphNode *)((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_1)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_1), __pyx_v_self->hg, __pyx_v_self->edge->head_node_); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_36), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; @@ -9954,166 +9948,160 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_15todot(struct __pyx_obj_5_cdec_Lattic __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec.Lattice.todot", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.HypergraphEdge.head_node.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_lines); - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5_cdec_14HypergraphEdge_10tail_nodes_2generator10(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":3 - * cimport mteval - * - * cdef SufficientStats as_stats(x, y): # <<<<<<<<<<<<<< - * if isinstance(x, SufficientStats): - * return x - */ - -static struct __pyx_obj_5_cdec_SufficientStats *__pyx_f_5_cdec_as_stats(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { - struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_stats = NULL; - struct __pyx_obj_5_cdec_SufficientStats *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("as_stats", 0); +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_10tail_nodes_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_10tail_nodes_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_10tail_nodes___get__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":4 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":167 * - * cdef SufficientStats as_stats(x, y): - * if isinstance(x, SufficientStats): # <<<<<<<<<<<<<< - * return x - * elif x == 0 and isinstance(y, SufficientStats): + * property tail_nodes: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.edge.tail_nodes_.size()): */ - __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":5 - * cdef SufficientStats as_stats(x, y): - * if isinstance(x, SufficientStats): - * return x # <<<<<<<<<<<<<< - * elif x == 0 and isinstance(y, SufficientStats): - * stats = SufficientStats() - */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SufficientStats))))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_INCREF(__pyx_v_x); - __pyx_r = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_x); - goto __pyx_L0; - goto __pyx_L3; +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_10tail_nodes___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *)__pyx_ptype_5_cdec___pyx_scope_struct_14___get__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_14___get__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; } - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":6 - * if isinstance(x, SufficientStats): - * return x - * elif x == 0 and isinstance(y, SufficientStats): # <<<<<<<<<<<<<< - * stats = SufficientStats() - * stats.stats = new mteval.SufficientStats() - */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_x, __pyx_int_0, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_y, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = __pyx_t_3; - } else { - __pyx_t_4 = __pyx_t_2; + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_14HypergraphEdge_10tail_nodes_2generator10, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; } - if (__pyx_t_4) { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":7 - * return x - * elif x == 0 and isinstance(y, SufficientStats): - * stats = SufficientStats() # <<<<<<<<<<<<<< - * stats.stats = new mteval.SufficientStats() - * stats.metric = ( y).metric - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_stats = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.HypergraphEdge.tail_nodes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":8 - * elif x == 0 and isinstance(y, SufficientStats): - * stats = SufficientStats() - * stats.stats = new mteval.SufficientStats() # <<<<<<<<<<<<<< - * stats.metric = ( y).metric - * return stats - */ - __pyx_v_stats->stats = new SufficientStats(); +static PyObject *__pyx_gb_5_cdec_14HypergraphEdge_10tail_nodes_2generator10(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + unsigned int __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[3]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":9 - * stats = SufficientStats() - * stats.stats = new mteval.SufficientStats() - * stats.metric = ( y).metric # <<<<<<<<<<<<<< - * return stats + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":169 + * def __get__(self): + * cdef unsigned i + * for i in range(self.edge.tail_nodes_.size()): # <<<<<<<<<<<<<< + * yield HypergraphNode().init(self.hg, self.edge.tail_nodes_[i]) * */ - __pyx_v_stats->metric = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_y)->metric; + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->edge->tail_nodes_.size(); + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":10 - * stats.stats = new mteval.SufficientStats() - * stats.metric = ( y).metric - * return stats # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":170 + * cdef unsigned i + * for i in range(self.edge.tail_nodes_.size()): + * yield HypergraphNode().init(self.hg, self.edge.tail_nodes_[i]) # <<<<<<<<<<<<<< * - * cdef class Candidate: + * property span: */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __Pyx_INCREF(((PyObject *)__pyx_v_stats)); - __pyx_r = __pyx_v_stats; - goto __pyx_L0; - goto __pyx_L3; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = ((struct __pyx_vtabstruct_5_cdec_HypergraphNode *)((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_3)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_t_3), __pyx_cur_scope->__pyx_v_self->hg, (__pyx_cur_scope->__pyx_v_self->edge->tail_nodes_[__pyx_cur_scope->__pyx_v_i])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 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_generator->resume_label = 1; + return __pyx_r; + __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[3]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_L3:; - - __pyx_r = ((struct __pyx_obj_5_cdec_SufficientStats *)Py_None); __Pyx_INCREF(Py_None); + PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.as_stats", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_stats); - __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return __pyx_r; + return NULL; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_9Candidate_5words_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_9Candidate_5words_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_4span_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_4span_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9Candidate_5words___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_4span___get__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":17 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":173 * - * property words: + * property span: * def __get__(self): # <<<<<<<<<<<<<< - * return unicode(GetString(self.candidate.ewords).c_str(), encoding='utf8') + * return (self.edge.i_, self.edge.j_) * */ -static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_4span___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -10124,29 +10112,27 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cd int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":18 - * property words: + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":174 + * property span: * def __get__(self): - * return unicode(GetString(self.candidate.ewords).c_str(), encoding='utf8') # <<<<<<<<<<<<<< + * return (self.edge.i_, self.edge.j_) # <<<<<<<<<<<<<< * - * property fmap: + * property feature_values: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(TD::GetString(__pyx_v_self->candidate->ewords).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 18; __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[5]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->edge->i_); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyInt_FromLong(__pyx_v_self->edge->j_); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __pyx_t_1 = 0; - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__encoding), ((PyObject *)__pyx_n_s__utf8)) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_r = __pyx_t_3; + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_r = ((PyObject *)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0; @@ -10156,7 +10142,7 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cd __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec.Candidate.words.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.HypergraphEdge.span.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -10165,26 +10151,26 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cd } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_9Candidate_4fmap_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_9Candidate_4fmap_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_14feature_values_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_14feature_values_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9Candidate_4fmap___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_14feature_values___get__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":21 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":177 * - * property fmap: + * property feature_values: * def __get__(self): # <<<<<<<<<<<<<< - * cdef SparseVector fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) + * cdef SparseVector vector = SparseVector() + * vector.vector = new FastSparseVector[double](self.edge.feature_values_) */ -static PyObject *__pyx_pf_5_cdec_9Candidate_4fmap___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { - struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap = 0; +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_14feature_values___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_vector = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -10193,72 +10179,72 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_4fmap___get__(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":22 - * property fmap: + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":178 + * property feature_values: * def __get__(self): - * cdef SparseVector fmap = SparseVector() # <<<<<<<<<<<<<< - * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) - * return fmap + * cdef SparseVector vector = SparseVector() # <<<<<<<<<<<<<< + * vector.vector = new FastSparseVector[double](self.edge.feature_values_) + * return vector */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":23 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":179 * def __get__(self): - * cdef SparseVector fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) # <<<<<<<<<<<<<< - * return fmap + * cdef SparseVector vector = SparseVector() + * vector.vector = new FastSparseVector[double](self.edge.feature_values_) # <<<<<<<<<<<<<< + * return vector * */ - __pyx_v_fmap->vector = new FastSparseVector(__pyx_v_self->candidate->fmap); + __pyx_v_vector->vector = new FastSparseVector(__pyx_v_self->edge->feature_values_); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":24 - * cdef SparseVector fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) - * return fmap # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":180 + * cdef SparseVector vector = SparseVector() + * vector.vector = new FastSparseVector[double](self.edge.feature_values_) + * return vector # <<<<<<<<<<<<<< * - * cdef class SufficientStats: + * property prob: */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_fmap)); - __pyx_r = ((PyObject *)__pyx_v_fmap); + __Pyx_INCREF(((PyObject *)__pyx_v_vector)); + __pyx_r = ((PyObject *)__pyx_v_vector); 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.Candidate.fmap.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.HypergraphEdge.feature_values.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_fmap); + __Pyx_XDECREF((PyObject *)__pyx_v_vector); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_9Candidate_5score_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_9Candidate_5score_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_4prob_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_4prob_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9Candidate_5score___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_4prob___get__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":14 - * cdef class Candidate: - * cdef mteval.Candidate* candidate - * cdef public float score # <<<<<<<<<<<<<< +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":183 + * + * property prob: + * def __get__(self): # <<<<<<<<<<<<<< + * return self.edge.edge_prob_.as_float() * - * property words: */ -static PyObject *__pyx_pf_5_cdec_9Candidate_5score___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_4prob___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -10266,8 +10252,16 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_5score___get__(struct __pyx_obj_5_cd const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":184 + * property prob: + * def __get__(self): + * return self.edge.edge_prob_.as_float() # <<<<<<<<<<<<<< + * + * def __richcmp__(HypergraphEdge x, HypergraphEdge y, int op): + */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->score); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->edge->edge_prob_.as_float()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -10277,7 +10271,7 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_5score___get__(struct __pyx_obj_5_cd goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.Candidate.score.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.HypergraphEdge.prob.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -10286,117 +10280,120 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_5score___get__(struct __pyx_obj_5_cd } /* Python wrapper */ -static int __pyx_pw_5_cdec_9Candidate_5score_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5_cdec_9Candidate_5score_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9Candidate_5score_2__set__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self), ((PyObject *)__pyx_v_value)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5_cdec_9Candidate_5score_2__set__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_3__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_3__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - float __pyx_t_1; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__set__", 0); - __pyx_t_1 = __pyx_PyFloat_AsFloat(__pyx_v_value); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->score = __pyx_t_1; - - __pyx_r = 0; + __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_HypergraphEdge, 1, "x", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_HypergraphEdge, 1, "y", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_2__richcmp__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_x), ((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_y), ((int)__pyx_v_op)); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Candidate.score.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* Python wrapper */ -static void __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_15SufficientStats___dealloc__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":30 - * cdef mteval.EvaluationMetric* metric - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.stats +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":186 + * return self.edge.edge_prob_.as_float() * + * def __richcmp__(HypergraphEdge x, HypergraphEdge y, int op): # <<<<<<<<<<<<<< + * if op == 2: # == + * return x.edge == y.edge */ -static void __pyx_pf_5_cdec_15SufficientStats___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_2__richcmp__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_x, struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_y, int __pyx_v_op) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__richcmp__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":31 - * - * def __dealloc__(self): - * del self.stats # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":189 + * if op == 2: # == + * return x.edge == y.edge + * elif op == 3: # != # <<<<<<<<<<<<<< + * return not (x == y) + * raise NotImplemented('comparison not implemented for HypergraphEdge') + */ + switch (__pyx_v_op) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":187 * - * property score: + * def __richcmp__(HypergraphEdge x, HypergraphEdge y, int op): + * if op == 2: # == # <<<<<<<<<<<<<< + * return x.edge == y.edge + * elif op == 3: # != */ - delete __pyx_v_self->stats; + case 2: - __Pyx_RefNannyFinishContext(); -} + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":188 + * def __richcmp__(HypergraphEdge x, HypergraphEdge y, int op): + * if op == 2: # == + * return x.edge == y.edge # <<<<<<<<<<<<<< + * elif op == 3: # != + * return not (x == y) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_x->edge == __pyx_v_y->edge)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + break; -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_5score_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_5score_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_15SufficientStats_5score___get__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":189 + * if op == 2: # == + * return x.edge == y.edge + * elif op == 3: # != # <<<<<<<<<<<<<< + * return not (x == y) + * raise NotImplemented('comparison not implemented for HypergraphEdge') + */ + case 3: -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":34 - * - * property score: - * def __get__(self): # <<<<<<<<<<<<<< - * return self.metric.ComputeScore(self.stats[0]) + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":190 + * return x.edge == y.edge + * elif op == 3: # != + * return not (x == y) # <<<<<<<<<<<<<< + * raise NotImplemented('comparison not implemented for HypergraphEdge') * */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + break; + } -static PyObject *__pyx_pf_5_cdec_15SufficientStats_5score___get__(struct __pyx_obj_5_cdec_SufficientStats *__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("__get__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":35 - * property score: - * def __get__(self): - * return self.metric.ComputeScore(self.stats[0]) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":191 + * elif op == 3: # != + * return not (x == y) + * raise NotImplemented('comparison not implemented for HypergraphEdge') # <<<<<<<<<<<<<< * - * property detail: + * cdef class HypergraphNode: */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->metric->ComputeScore((__pyx_v_self->stats[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_NotImplemented, ((PyObject *)__pyx_k_tuple_18), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.SufficientStats.score.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.HypergraphEdge.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -10405,53 +10402,34 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_5score___get__(struct __pyx_o } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_5trule_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_5trule_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_15SufficientStats_6detail___get__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_5trule___get__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":38 - * - * property detail: - * def __get__(self): # <<<<<<<<<<<<<< - * return self.metric.DetailedScore(self.stats[0]).c_str() +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":150 + * cdef hypergraph.Hypergraph* hg + * cdef hypergraph.HypergraphEdge* edge + * cdef public BaseTRule trule # <<<<<<<<<<<<<< * + * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): */ -static PyObject *__pyx_pf_5_cdec_15SufficientStats_6detail___get__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_5trule___get__(struct __pyx_obj_5_cdec_HypergraphEdge *__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("__get__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":39 - * property detail: - * def __get__(self): - * return self.metric.DetailedScore(self.stats[0]).c_str() # <<<<<<<<<<<<<< - * - * def __len__(self): - */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(__pyx_v_self->metric->DetailedScore((__pyx_v_self->stats[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_r = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; + __Pyx_INCREF(((PyObject *)__pyx_v_self->trule)); + __pyx_r = ((PyObject *)__pyx_v_self->trule); 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.SufficientStats.detail.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); @@ -10459,74 +10437,145 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_6detail___get__(struct __pyx_ } /* Python wrapper */ -static Py_ssize_t __pyx_pw_5_cdec_15SufficientStats_3__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_5_cdec_15SufficientStats_3__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; +static int __pyx_pw_5_cdec_14HypergraphEdge_5trule_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_5_cdec_14HypergraphEdge_5trule_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_15SufficientStats_2__len__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_5trule_2__set__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self), ((PyObject *)__pyx_v_value)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":41 - * return self.metric.DetailedScore(self.stats[0]).c_str() - * - * def __len__(self): # <<<<<<<<<<<<<< - * return self.stats.size() +static int __pyx_pf_5_cdec_14HypergraphEdge_5trule_2__set__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); + if (!(likely(((__pyx_v_value) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_value, __pyx_ptype_5_cdec_BaseTRule))))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->trule); + __Pyx_DECREF(((PyObject *)__pyx_v_self->trule)); + __pyx_v_self->trule = ((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_value); + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.HypergraphEdge.trule.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_14HypergraphEdge_5trule_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_5_cdec_14HypergraphEdge_5trule_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_14HypergraphEdge_5trule_4__del__(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5_cdec_14HypergraphEdge_5trule_4__del__(struct __pyx_obj_5_cdec_HypergraphEdge *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->trule); + __Pyx_DECREF(((PyObject *)__pyx_v_self->trule)); + __pyx_v_self->trule = ((struct __pyx_obj_5_cdec_BaseTRule *)Py_None); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":197 + * cdef hypergraph.HypergraphNode* node * + * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): # <<<<<<<<<<<<<< + * self.hg = hg + * self.node = &hg.nodes_[i] */ -static Py_ssize_t __pyx_pf_5_cdec_15SufficientStats_2__len__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { - Py_ssize_t __pyx_r; +static PyObject *__pyx_f_5_cdec_14HypergraphNode_init(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self, Hypergraph *__pyx_v_hg, unsigned int __pyx_v_i) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__", 0); + __Pyx_RefNannySetupContext("init", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":42 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":198 * - * def __len__(self): - * return self.stats.size() # <<<<<<<<<<<<<< + * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): + * self.hg = hg # <<<<<<<<<<<<<< + * self.node = &hg.nodes_[i] + * return self + */ + __pyx_v_self->hg = __pyx_v_hg; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":199 + * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): + * self.hg = hg + * self.node = &hg.nodes_[i] # <<<<<<<<<<<<<< + * return self * - * def __iter__(self): */ - __pyx_r = __pyx_v_self->stats->size(); + __pyx_v_self->node = (&(__pyx_v_hg->nodes_[__pyx_v_i])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":200 + * self.hg = hg + * self.node = &hg.nodes_[i] + * return self # <<<<<<<<<<<<<< + * + * property in_edges: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0; - __pyx_r = 0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator12(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5_cdec_14HypergraphNode_8in_edges_2generator11(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_5__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_5__iter__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_8in_edges_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_8in_edges_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_15SufficientStats_4__iter__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_14HypergraphNode_8in_edges___get__(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":44 - * return self.stats.size() +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":203 * - * def __iter__(self): # <<<<<<<<<<<<<< - * for i in range(len(self)): - * yield self.stats[0][i] + * property in_edges: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.node.in_edges_.size()): */ -static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_14HypergraphNode_8in_edges___get__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__iter__", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_18___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_18___iter__, __pyx_empty_tuple, NULL); + __Pyx_RefNannySetupContext("__get__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__ *)__pyx_ptype_5_cdec___pyx_scope_struct_15___get__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_15___get__, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -10536,7 +10585,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_ __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_15SufficientStats_6generator12, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_14HypergraphNode_8in_edges_2generator11, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -10545,7 +10594,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.SufficientStats.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.HypergraphNode.in_edges.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); @@ -10554,15 +10603,14 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_ return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator12(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_14HypergraphNode_8in_edges_2generator11(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *)__pyx_generator->closure); + struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; - Py_ssize_t __pyx_t_1; - PyObject *__pyx_t_2 = NULL; + size_t __pyx_t_1; + unsigned int __pyx_t_2; PyObject *__pyx_t_3 = NULL; - PyObject *(*__pyx_t_4)(PyObject *); - unsigned int __pyx_t_5; + PyObject *__pyx_t_4 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { @@ -10573,75 +10621,35 @@ static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator12(__pyx_GeneratorO return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":45 - * - * def __iter__(self): - * for i in range(len(self)): # <<<<<<<<<<<<<< - * yield self.stats[0][i] + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":205 + * def __get__(self): + * cdef unsigned i + * for i in range(self.node.in_edges_.size()): # <<<<<<<<<<<<<< + * yield HypergraphEdge().init(self.hg, self.node.in_edges_[i]) * */ - __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_1 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { - if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_3)) break; - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; - } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { - if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; - } else { - __pyx_t_2 = __pyx_t_4(__pyx_t_3); - if (unlikely(!__pyx_t_2)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_i); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_i); - __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->node->in_edges_.size(); + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - __pyx_t_2 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":46 - * def __iter__(self): - * for i in range(len(self)): - * yield self.stats[0][i] # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":206 + * cdef unsigned i + * for i in range(self.node.in_edges_.size()): + * yield HypergraphEdge().init(self.hg, self.node.in_edges_[i]) # <<<<<<<<<<<<<< * - * def __iadd__(SufficientStats self, SufficientStats other): + * property out_edges: */ - __pyx_t_5 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_i); if (unlikely((__pyx_t_5 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyFloat_FromDouble(((__pyx_cur_scope->__pyx_v_self->stats[0])[__pyx_t_5])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphEdge)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = ((struct __pyx_vtabstruct_5_cdec_HypergraphEdge *)((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_t_3)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_t_3), __pyx_cur_scope->__pyx_v_self->hg, (__pyx_cur_scope->__pyx_v_self->node->in_edges_[__pyx_cur_scope->__pyx_v_i])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; - __Pyx_XGIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); /* return from generator, yielding value */ @@ -10649,2385 +10657,2303 @@ static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator12(__pyx_GeneratorO return __pyx_r; __pyx_L6_resume_from_yield:; __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; - __pyx_cur_scope->__pyx_t_1 = 0; - __Pyx_XGOTREF(__pyx_t_3); - __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); return NULL; } +static PyObject *__pyx_gb_5_cdec_14HypergraphNode_9out_edges_2generator12(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_9out_edges_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_9out_edges_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iadd__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SufficientStats, 1, "other", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_15SufficientStats_7__iadd__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_other)); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_14HypergraphNode_9out_edges___get__(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":48 - * yield self.stats[0][i] +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":209 * - * def __iadd__(SufficientStats self, SufficientStats other): # <<<<<<<<<<<<<< - * self.stats[0] += other.stats[0] - * return self + * property out_edges: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.node.out_edges_.size()): */ -static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__iadd__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_14HypergraphNode_9out_edges___get__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_16___get__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iadd__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":49 - * - * def __iadd__(SufficientStats self, SufficientStats other): - * self.stats[0] += other.stats[0] # <<<<<<<<<<<<<< - * return self - * - */ - (__pyx_v_self->stats[0]) += (__pyx_v_other->stats[0]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":50 - * def __iadd__(SufficientStats self, SufficientStats other): - * self.stats[0] += other.stats[0] - * return self # <<<<<<<<<<<<<< - * - * def __add__(x, y): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __pyx_r = ((PyObject *)__pyx_v_self); - goto __pyx_L0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_16___get__ *)__pyx_ptype_5_cdec___pyx_scope_struct_16___get__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_16___get__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_14HypergraphNode_9out_edges_2generator12, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.HypergraphNode.out_edges.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5_cdec_14HypergraphNode_9out_edges_2generator12(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_16___get__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_16___get__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + size_t __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[3]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":211 + * def __get__(self): + * cdef unsigned i + * for i in range(self.node.out_edges_.size()): # <<<<<<<<<<<<<< + * yield HypergraphEdge().init(self.hg, self.node.out_edges_[i]) + * + */ + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->node->out_edges_.size(); + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":212 + * cdef unsigned i + * for i in range(self.node.out_edges_.size()): + * yield HypergraphEdge().init(self.hg, self.node.out_edges_[i]) # <<<<<<<<<<<<<< + * + * property span: + */ + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_HypergraphEdge)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = ((struct __pyx_vtabstruct_5_cdec_HypergraphEdge *)((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_t_3)->__pyx_vtab)->init(((struct __pyx_obj_5_cdec_HypergraphEdge *)__pyx_t_3), __pyx_cur_scope->__pyx_v_self->hg, (__pyx_cur_scope->__pyx_v_self->node->out_edges_[__pyx_cur_scope->__pyx_v_i])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 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_generator->resume_label = 1; + return __pyx_r; + __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[3]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} + /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_10__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_10__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_4span_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_4span_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__add__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_15SufficientStats_9__add__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_14HypergraphNode_4span___get__(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":52 - * return self +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":215 + * + * property span: + * def __get__(self): # <<<<<<<<<<<<<< + * return next(self.in_edges).span * - * def __add__(x, y): # <<<<<<<<<<<<<< - * cdef SufficientStats sx = as_stats(x, y) - * cdef SufficientStats sy = as_stats(y, x) */ -static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { - struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sx = 0; - struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sy = 0; - struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_result = 0; +static PyObject *__pyx_pf_5_cdec_14HypergraphNode_4span___get__(struct __pyx_obj_5_cdec_HypergraphNode *__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("__add__", 0); + __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":53 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":216 + * property span: + * def __get__(self): + * return next(self.in_edges).span # <<<<<<<<<<<<<< * - * def __add__(x, y): - * cdef SufficientStats sx = as_stats(x, y) # <<<<<<<<<<<<<< - * cdef SufficientStats sy = as_stats(y, x) - * cdef SufficientStats result = SufficientStats() + * property cat: */ - __pyx_t_1 = ((PyObject *)__pyx_f_5_cdec_as_stats(__pyx_v_x, __pyx_v_y)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__in_edges); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_v_sx = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":54 - * def __add__(x, y): - * cdef SufficientStats sx = as_stats(x, y) - * cdef SufficientStats sy = as_stats(y, x) # <<<<<<<<<<<<<< - * cdef SufficientStats result = SufficientStats() - * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) - */ - __pyx_t_1 = ((PyObject *)__pyx_f_5_cdec_as_stats(__pyx_v_y, __pyx_v_x)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyIter_Next(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__span); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_v_sy = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; __pyx_t_1 = 0; + goto __pyx_L0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":55 - * cdef SufficientStats sx = as_stats(x, y) - * cdef SufficientStats sy = as_stats(y, x) - * cdef SufficientStats result = SufficientStats() # <<<<<<<<<<<<<< - * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) - * result.metric = sx.metric - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_result = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); - __pyx_t_1 = 0; + __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.HypergraphNode.span.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":56 - * cdef SufficientStats sy = as_stats(y, x) - * cdef SufficientStats result = SufficientStats() - * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) # <<<<<<<<<<<<<< - * result.metric = sx.metric - * return result +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_3cat_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_3cat_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_14HypergraphNode_3cat___get__(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":219 + * + * property cat: + * def __get__(self): # <<<<<<<<<<<<<< + * if self.node.cat_: + * return TDConvert(-self.node.cat_) */ - __pyx_v_result->stats = new SufficientStats(operator+((__pyx_v_sx->stats[0]), (__pyx_v_sy->stats[0]))); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":57 - * cdef SufficientStats result = SufficientStats() - * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) - * result.metric = sx.metric # <<<<<<<<<<<<<< - * return result +static PyObject *__pyx_pf_5_cdec_14HypergraphNode_3cat___get__(struct __pyx_obj_5_cdec_HypergraphNode *__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("__get__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":220 + * property cat: + * def __get__(self): + * if self.node.cat_: # <<<<<<<<<<<<<< + * return TDConvert(-self.node.cat_) * */ - __pyx_v_result->metric = __pyx_v_sx->metric; + if (__pyx_v_self->node->cat_) { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":58 - * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) - * result.metric = sx.metric - * return result # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":221 + * def __get__(self): + * if self.node.cat_: + * return TDConvert(-self.node.cat_) # <<<<<<<<<<<<<< * - * cdef class CandidateSet: + * def __richcmp__(HypergraphNode x, HypergraphNode y, int op): */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - __pyx_r = ((PyObject *)__pyx_v_result); - goto __pyx_L0; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_self->node->cat_))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 221; __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; + goto __pyx_L3; + } + __pyx_L3:; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.SufficientStats.__add__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.HypergraphNode.cat.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_sx); - __Pyx_XDECREF((PyObject *)__pyx_v_sy); - __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__evaluator,0}; - int __pyx_r; +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_1__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op); /*proto*/ +static PyObject *__pyx_pw_5_cdec_14HypergraphNode_1__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[1] = {0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__evaluator); - 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __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_evaluator = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)values[0]); - } - 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[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.CandidateSet.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_evaluator), __pyx_ptype_5_cdec_SegmentEvaluator, 1, "evaluator", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12CandidateSet___cinit__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), __pyx_v_evaluator); + __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_HypergraphNode, 1, "x", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_HypergraphNode, 1, "y", 0))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_14HypergraphNode___richcmp__(((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_v_x), ((struct __pyx_obj_5_cdec_HypergraphNode *)__pyx_v_y), ((int)__pyx_v_op)); goto __pyx_L0; __pyx_L1_error:; - __pyx_r = -1; + __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":65 - * cdef mteval.CandidateSet* cs +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":223 + * return TDConvert(-self.node.cat_) * - * def __cinit__(self, SegmentEvaluator evaluator): # <<<<<<<<<<<<<< - * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) - * self.metric = evaluator.metric + * def __richcmp__(HypergraphNode x, HypergraphNode y, int op): # <<<<<<<<<<<<<< + * if op == 2: # == + * return x.node == y.node */ -static int __pyx_pf_5_cdec_12CandidateSet___cinit__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator) { - int __pyx_r; +static PyObject *__pyx_pf_5_cdec_14HypergraphNode___richcmp__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_x, struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_y, int __pyx_v_op) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":66 - * - * def __cinit__(self, SegmentEvaluator evaluator): - * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) # <<<<<<<<<<<<<< - * self.metric = evaluator.metric - * self.cs = new mteval.CandidateSet() - */ - __pyx_v_self->scorer = new boost::shared_ptr((__pyx_v_evaluator->scorer[0])); + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__richcmp__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":67 - * def __cinit__(self, SegmentEvaluator evaluator): - * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) - * self.metric = evaluator.metric # <<<<<<<<<<<<<< - * self.cs = new mteval.CandidateSet() - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":226 + * if op == 2: # == + * return x.node == y.node + * elif op == 3: # != # <<<<<<<<<<<<<< + * return not (x == y) + * raise NotImplemented('comparison not implemented for HypergraphNode') */ - __pyx_v_self->metric = __pyx_v_evaluator->metric; + switch (__pyx_v_op) { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":68 - * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) - * self.metric = evaluator.metric - * self.cs = new mteval.CandidateSet() # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":224 * - * def __dealloc__(self): + * def __richcmp__(HypergraphNode x, HypergraphNode y, int op): + * if op == 2: # == # <<<<<<<<<<<<<< + * return x.node == y.node + * elif op == 3: # != */ - __pyx_v_self->cs = new training::CandidateSet(); - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static void __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} + case 2: -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":70 - * self.cs = new mteval.CandidateSet() - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.scorer - * del self.cs + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":225 + * def __richcmp__(HypergraphNode x, HypergraphNode y, int op): + * if op == 2: # == + * return x.node == y.node # <<<<<<<<<<<<<< + * elif op == 3: # != + * return not (x == y) */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_x->node == __pyx_v_y->node)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + break; -static void __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":71 - * - * def __dealloc__(self): - * del self.scorer # <<<<<<<<<<<<<< - * del self.cs - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":226 + * if op == 2: # == + * return x.node == y.node + * elif op == 3: # != # <<<<<<<<<<<<<< + * return not (x == y) + * raise NotImplemented('comparison not implemented for HypergraphNode') */ - delete __pyx_v_self->scorer; + case 3: - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":72 - * def __dealloc__(self): - * del self.scorer - * del self.cs # <<<<<<<<<<<<<< - * - * def __len__(self): + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":227 + * return x.node == y.node + * elif op == 3: # != + * return not (x == y) # <<<<<<<<<<<<<< + * raise NotImplemented('comparison not implemented for HypergraphNode') */ - delete __pyx_v_self->cs; - - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static Py_ssize_t __pyx_pw_5_cdec_12CandidateSet_5__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_5_cdec_12CandidateSet_5__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12CandidateSet_4__len__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + break; + } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":74 - * del self.cs - * - * def __len__(self): # <<<<<<<<<<<<<< - * return self.cs.size() - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":228 + * elif op == 3: # != + * return not (x == y) + * raise NotImplemented('comparison not implemented for HypergraphNode') # <<<<<<<<<<<<<< */ + __pyx_t_1 = PyObject_Call(__pyx_builtin_NotImplemented, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;} -static Py_ssize_t __pyx_pf_5_cdec_12CandidateSet_4__len__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":75 - * - * def __len__(self): - * return self.cs.size() # <<<<<<<<<<<<<< - * - * def __getitem__(self,int k): - */ - __pyx_r = __pyx_v_self->cs->size(); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - - __pyx_r = 0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.HypergraphNode.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_k); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_k) { - int __pyx_v_k; - PyObject *__pyx_r = 0; +static int __pyx_pw_5_cdec_7Lattice_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_7Lattice_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_inp = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__inp,0}; + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); - assert(__pyx_arg_k); { - __pyx_v_k = __Pyx_PyInt_AsInt(__pyx_arg_k); if (unlikely((__pyx_v_k == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__inp); + 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __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_inp = values[0]; } 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[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.CandidateSet.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Lattice.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); - return NULL; + return -1; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12CandidateSet_6__getitem__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), ((int)__pyx_v_k)); + __pyx_r = __pyx_pf_5_cdec_7Lattice___cinit__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), __pyx_v_inp); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":77 - * return self.cs.size() +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":6 + * cdef lattice.Lattice* lattice * - * def __getitem__(self,int k): # <<<<<<<<<<<<<< - * if not 0 <= k < self.cs.size(): - * raise IndexError('candidate set index out of range') + * def __cinit__(self, inp): # <<<<<<<<<<<<<< + * if isinstance(inp, tuple): + * self.lattice = new lattice.Lattice(len(inp)) */ -static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, int __pyx_v_k) { - struct __pyx_obj_5_cdec_Candidate *__pyx_v_candidate = 0; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; +static int __pyx_pf_5_cdec_7Lattice___cinit__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, PyObject *__pyx_v_inp) { + PyObject *__pyx_v_i = NULL; + PyObject *__pyx_v_arcs = NULL; + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *(*__pyx_t_5)(PyObject *); + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + char *__pyx_t_8; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__getitem__", 0); + __Pyx_RefNannySetupContext("__cinit__", 0); + __Pyx_INCREF(__pyx_v_inp); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":78 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":7 * - * def __getitem__(self,int k): - * if not 0 <= k < self.cs.size(): # <<<<<<<<<<<<<< - * raise IndexError('candidate set index out of range') - * cdef Candidate candidate = Candidate() + * def __cinit__(self, inp): + * if isinstance(inp, tuple): # <<<<<<<<<<<<<< + * self.lattice = new lattice.Lattice(len(inp)) + * for i, arcs in enumerate(inp): */ - __pyx_t_1 = (0 <= __pyx_v_k); - if (__pyx_t_1) { - __pyx_t_1 = (__pyx_v_k < __pyx_v_self->cs->size()); - } - __pyx_t_2 = (!__pyx_t_1); + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyTuple_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_inp, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":79 - * def __getitem__(self,int k): - * if not 0 <= k < self.cs.size(): - * raise IndexError('candidate set index out of range') # <<<<<<<<<<<<<< - * cdef Candidate candidate = Candidate() - * candidate.candidate = &self.cs[0][k] + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":8 + * def __cinit__(self, inp): + * if isinstance(inp, tuple): + * self.lattice = new lattice.Lattice(len(inp)) # <<<<<<<<<<<<<< + * for i, arcs in enumerate(inp): + * self[i] = arcs */ - __pyx_t_3 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_38), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Length(__pyx_v_inp); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->lattice = new Lattice(__pyx_t_3); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":9 + * if isinstance(inp, tuple): + * self.lattice = new lattice.Lattice(len(inp)) + * for i, arcs in enumerate(inp): # <<<<<<<<<<<<<< + * self[i] = arcs + * else: + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_1 = __pyx_int_0; + if (PyList_CheckExact(__pyx_v_inp) || PyTuple_CheckExact(__pyx_v_inp)) { + __pyx_t_4 = __pyx_v_inp; __Pyx_INCREF(__pyx_t_4); __pyx_t_3 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_inp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_4)) break; + __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; + } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; + } else { + __pyx_t_6 = __pyx_t_5(__pyx_t_4); + if (unlikely(!__pyx_t_6)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_6); + } + __Pyx_XDECREF(__pyx_v_arcs); + __pyx_v_arcs = __pyx_t_6; + __pyx_t_6 = 0; + __Pyx_INCREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_1; + __pyx_t_6 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); + __pyx_t_1 = __pyx_t_6; + __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":10 + * self.lattice = new lattice.Lattice(len(inp)) + * for i, arcs in enumerate(inp): + * self[i] = arcs # <<<<<<<<<<<<<< + * else: + * if isinstance(inp, unicode): + */ + if (PyObject_SetItem(((PyObject *)__pyx_v_self), __pyx_v_i, __pyx_v_arcs) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L3; } - __pyx_L3:; + /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":80 - * if not 0 <= k < self.cs.size(): - * raise IndexError('candidate set index out of range') - * cdef Candidate candidate = Candidate() # <<<<<<<<<<<<<< - * candidate.candidate = &self.cs[0][k] - * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":12 + * self[i] = arcs + * else: + * if isinstance(inp, unicode): # <<<<<<<<<<<<<< + * inp = inp.encode('utf8') + * if not isinstance(inp, str): */ - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Candidate)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_candidate = ((struct __pyx_obj_5_cdec_Candidate *)__pyx_t_3); - __pyx_t_3 = 0; + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_inp, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":81 - * raise IndexError('candidate set index out of range') - * cdef Candidate candidate = Candidate() - * candidate.candidate = &self.cs[0][k] # <<<<<<<<<<<<<< - * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) - * return candidate + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":13 + * else: + * if isinstance(inp, unicode): + * inp = inp.encode('utf8') # <<<<<<<<<<<<<< + * if not isinstance(inp, str): + * raise TypeError('Cannot create lattice from %s' % type(inp)) */ - __pyx_v_candidate->candidate = (&((__pyx_v_self->cs[0])[__pyx_v_k])); + __pyx_t_1 = PyObject_GetAttr(__pyx_v_inp, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_21), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_v_inp); + __pyx_v_inp = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L6; + } + __pyx_L6:; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 - * cdef Candidate candidate = Candidate() - * candidate.candidate = &self.cs[0][k] - * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) # <<<<<<<<<<<<<< - * return candidate + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":14 + * if isinstance(inp, unicode): + * inp = inp.encode('utf8') + * if not isinstance(inp, str): # <<<<<<<<<<<<<< + * raise TypeError('Cannot create lattice from %s' % type(inp)) + * self.lattice = new lattice.Lattice() + */ + __pyx_t_4 = ((PyObject *)((PyObject*)(&PyString_Type))); + __Pyx_INCREF(__pyx_t_4); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_inp, __pyx_t_4); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_7 = (!__pyx_t_2); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":15 + * inp = inp.encode('utf8') + * if not isinstance(inp, str): + * raise TypeError('Cannot create lattice from %s' % type(inp)) # <<<<<<<<<<<<<< + * self.lattice = new lattice.Lattice() + * lattice.ConvertTextToLattice(string(inp), self.lattice) + */ + __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_22), ((PyObject *)Py_TYPE(__pyx_v_inp))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L7; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":16 + * if not isinstance(inp, str): + * raise TypeError('Cannot create lattice from %s' % type(inp)) + * self.lattice = new lattice.Lattice() # <<<<<<<<<<<<<< + * lattice.ConvertTextToLattice(string(inp), self.lattice) * */ - __pyx_v_candidate->score = __pyx_v_self->metric->ComputeScore(((__pyx_v_self->cs[0])[__pyx_v_k]).eval_feats); + __pyx_v_self->lattice = new Lattice(); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":83 - * candidate.candidate = &self.cs[0][k] - * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) - * return candidate # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":17 + * raise TypeError('Cannot create lattice from %s' % type(inp)) + * self.lattice = new lattice.Lattice() + * lattice.ConvertTextToLattice(string(inp), self.lattice) # <<<<<<<<<<<<<< * - * def __iter__(self): + * def __getitem__(self, int index): */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_candidate)); - __pyx_r = ((PyObject *)__pyx_v_candidate); - goto __pyx_L0; + __pyx_t_8 = PyBytes_AsString(__pyx_v_inp); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + LatticeTools::ConvertTextToLattice(std::string(((char *)__pyx_t_8)), __pyx_v_self->lattice); + } + __pyx_L3:; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec.CandidateSet.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_cdec.Lattice.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_candidate); - __Pyx_XGIVEREF(__pyx_r); + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_arcs); + __Pyx_XDECREF(__pyx_v_inp); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator13(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12CandidateSet_9__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12CandidateSet_9__iter__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_7Lattice_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Lattice_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index) { + int __pyx_v_index; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12CandidateSet_8__iter__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + assert(__pyx_arg_index); { + __pyx_v_index = __Pyx_PyInt_AsInt(__pyx_arg_index); if (unlikely((__pyx_v_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.Lattice.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_7Lattice_2__getitem__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), ((int)__pyx_v_index)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":85 - * return candidate +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":19 + * lattice.ConvertTextToLattice(string(inp), self.lattice) * - * def __iter__(self): # <<<<<<<<<<<<<< - * cdef unsigned i - * for i in range(len(self)): + * def __getitem__(self, int index): # <<<<<<<<<<<<<< + * if not 0 <= index < len(self): + * raise IndexError('lattice index out of range') */ -static PyObject *__pyx_pf_5_cdec_12CandidateSet_8__iter__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *__pyx_cur_scope; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations +static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index) { + PyObject *__pyx_v_arcs = NULL; + std::vector __pyx_v_arc_vector; + LatticeArc *__pyx_v_arc; + unsigned int __pyx_v_i; + PyObject *__pyx_v_label = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + Py_ssize_t __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + size_t __pyx_t_5; + unsigned int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__iter__", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_19___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_19___iter__, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; + __Pyx_RefNannySetupContext("__getitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":20 + * + * def __getitem__(self, int index): + * if not 0 <= index < len(self): # <<<<<<<<<<<<<< + * raise IndexError('lattice index out of range') + * arcs = [] + */ + __pyx_t_1 = (0 <= __pyx_v_index); + if (__pyx_t_1) { + __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = (__pyx_v_index < __pyx_t_2); } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12CandidateSet_10generator13, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; + __pyx_t_3 = (!__pyx_t_1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":21 + * def __getitem__(self, int index): + * if not 0 <= index < len(self): + * raise IndexError('lattice index out of range') # <<<<<<<<<<<<<< + * arcs = [] + * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] + */ + __pyx_t_4 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":22 + * if not 0 <= index < len(self): + * raise IndexError('lattice index out of range') + * arcs = [] # <<<<<<<<<<<<<< + * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] + * cdef lattice.LatticeArc* arc + */ + __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_arcs = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":23 + * raise IndexError('lattice index out of range') + * arcs = [] + * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] # <<<<<<<<<<<<<< + * cdef lattice.LatticeArc* arc + * cdef unsigned i + */ + __pyx_v_arc_vector = ((__pyx_v_self->lattice[0])[__pyx_v_index]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":26 + * cdef lattice.LatticeArc* arc + * cdef unsigned i + * for i in range(arc_vector.size()): # <<<<<<<<<<<<<< + * arc = &arc_vector[i] + * label = unicode(TDConvert(arc.label), 'utf8') + */ + __pyx_t_5 = __pyx_v_arc_vector.size(); + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_v_i = __pyx_t_6; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":27 + * cdef unsigned i + * for i in range(arc_vector.size()): + * arc = &arc_vector[i] # <<<<<<<<<<<<<< + * label = unicode(TDConvert(arc.label), 'utf8') + * arcs.append((label, arc.cost, arc.dist2next)) + */ + __pyx_v_arc = (&(__pyx_v_arc_vector[__pyx_v_i])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":28 + * for i in range(arc_vector.size()): + * arc = &arc_vector[i] + * label = unicode(TDConvert(arc.label), 'utf8') # <<<<<<<<<<<<<< + * arcs.append((label, arc.cost, arc.dist2next)) + * return tuple(arcs) + */ + __pyx_t_4 = PyBytes_FromString(TD::Convert(__pyx_v_arc->label)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_7, 1, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __Pyx_XDECREF(((PyObject *)__pyx_v_label)); + __pyx_v_label = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":29 + * arc = &arc_vector[i] + * label = unicode(TDConvert(arc.label), 'utf8') + * arcs.append((label, arc.cost, arc.dist2next)) # <<<<<<<<<<<<<< + * return tuple(arcs) + * + */ + __pyx_t_4 = PyFloat_FromDouble(__pyx_v_arc->cost); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = PyInt_FromLong(__pyx_v_arc->dist2next); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(((PyObject *)__pyx_v_label)); + PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_v_label)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_label)); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + __pyx_t_4 = 0; + __pyx_t_7 = 0; + __pyx_t_9 = PyList_Append(__pyx_v_arcs, ((PyObject *)__pyx_t_8)); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; } + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":30 + * label = unicode(TDConvert(arc.label), 'utf8') + * arcs.append((label, arc.cost, arc.dist2next)) + * return tuple(arcs) # <<<<<<<<<<<<<< + * + * def __setitem__(self, int index, tuple arcs): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_8 = ((PyObject *)PyList_AsTuple(__pyx_v_arcs)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_8)); + __pyx_r = ((PyObject *)__pyx_t_8); + __pyx_t_8 = 0; + goto __pyx_L0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.CandidateSet.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_cdec.Lattice.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XDECREF(__pyx_v_arcs); + __Pyx_XDECREF(__pyx_v_label); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator13(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - Py_ssize_t __pyx_t_1; - unsigned int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; +/* Python wrapper */ +static int __pyx_pw_5_cdec_7Lattice_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index, PyObject *__pyx_v_arcs); /*proto*/ +static int __pyx_pw_5_cdec_7Lattice_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index, PyObject *__pyx_v_arcs) { + int __pyx_v_index; + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("None", 0); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_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[5]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":87 - * def __iter__(self): - * cdef unsigned i - * for i in range(len(self)): # <<<<<<<<<<<<<< - * yield self[i] - * - */ - __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":88 - * cdef unsigned i - * for i in range(len(self)): - * yield self[i] # <<<<<<<<<<<<<< - * - * def add_kbest(self, Hypergraph hypergraph, unsigned k): - */ - __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 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_generator->resume_label = 1; - return __pyx_r; - __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[5]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); + assert(__pyx_arg_index); { + __pyx_v_index = __Pyx_PyInt_AsInt(__pyx_arg_index); if (unlikely((__pyx_v_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } - PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.Lattice.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_arcs), (&PyTuple_Type), 1, "arcs", 1))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_7Lattice_4__setitem__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), ((int)__pyx_v_index), ((PyObject*)__pyx_v_arcs)); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return NULL; + return __pyx_r; } -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph = 0; - unsigned int __pyx_v_k; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__hypergraph,&__pyx_n_s__k,0}; - PyObject *__pyx_r = 0; +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":32 + * return tuple(arcs) + * + * def __setitem__(self, int index, tuple arcs): # <<<<<<<<<<<<<< + * if not 0 <= index < len(self): + * raise IndexError('lattice index out of range') + */ + +static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index, PyObject *__pyx_v_arcs) { + LatticeArc *__pyx_v_arc; + PyObject *__pyx_v_label = NULL; + PyObject *__pyx_v_cost = NULL; + PyObject *__pyx_v_dist2next = NULL; + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("add_kbest (wrapper)", 0); - { - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__hypergraph); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, 1); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + int __pyx_t_1; + Py_ssize_t __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *(*__pyx_t_10)(PyObject *); + char *__pyx_t_11; + double __pyx_t_12; + int __pyx_t_13; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__setitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":33 + * + * def __setitem__(self, int index, tuple arcs): + * if not 0 <= index < len(self): # <<<<<<<<<<<<<< + * raise IndexError('lattice index out of range') + * cdef lattice.LatticeArc* arc + */ + __pyx_t_1 = (0 <= __pyx_v_index); + if (__pyx_t_1) { + __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = (__pyx_v_index < __pyx_t_2); + } + __pyx_t_3 = (!__pyx_t_1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":34 + * def __setitem__(self, int index, tuple arcs): + * if not 0 <= index < len(self): + * raise IndexError('lattice index out of range') # <<<<<<<<<<<<<< + * cdef lattice.LatticeArc* arc + * for (label, cost, dist2next) in arcs: + */ + __pyx_t_4 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":36 + * raise IndexError('lattice index out of range') + * cdef lattice.LatticeArc* arc + * for (label, cost, dist2next) in arcs: # <<<<<<<<<<<<<< + * if isinstance(label, unicode): + * label = label.encode('utf8') + */ + if (unlikely(((PyObject *)__pyx_v_arcs) == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_4 = ((PyObject *)__pyx_v_arcs); __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0; + for (;;) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) { + PyObject* sequence = __pyx_t_5; + if (likely(PyTuple_CheckExact(sequence))) { + if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { + if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 2); + } else { + if (unlikely(PyList_GET_SIZE(sequence) != 3)) { + if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_6 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + __pyx_t_8 = PyList_GET_ITEM(sequence, 2); } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_kbest") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + Py_ssize_t index = -1; + __pyx_t_9 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; + index = 0; __pyx_t_6 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + index = 1; __pyx_t_7 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + index = 2; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 3) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L7_unpacking_done; + __pyx_L6_unpacking_failed:; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L7_unpacking_done:; } - __pyx_v_hypergraph = ((struct __pyx_obj_5_cdec_Hypergraph *)values[0]); - __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_XDECREF(__pyx_v_label); + __pyx_v_label = __pyx_t_6; + __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_v_cost); + __pyx_v_cost = __pyx_t_7; + __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_v_dist2next); + __pyx_v_dist2next = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":37 + * cdef lattice.LatticeArc* arc + * for (label, cost, dist2next) in arcs: + * if isinstance(label, unicode): # <<<<<<<<<<<<<< + * label = label.encode('utf8') + * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) + */ + __pyx_t_5 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_5); + __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_label, __pyx_t_5); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":38 + * for (label, cost, dist2next) in arcs: + * if isinstance(label, unicode): + * label = label.encode('utf8') # <<<<<<<<<<<<<< + * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) + * self.lattice[0][index].push_back(arc[0]) + */ + __pyx_t_5 = PyObject_GetAttr(__pyx_v_label, __pyx_n_s__encode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_26), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_v_label); + __pyx_v_label = __pyx_t_8; + __pyx_t_8 = 0; + goto __pyx_L8; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":39 + * if isinstance(label, unicode): + * label = label.encode('utf8') + * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) # <<<<<<<<<<<<<< + * self.lattice[0][index].push_back(arc[0]) + * del arc + */ + __pyx_t_11 = PyBytes_AsString(__pyx_v_label); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_v_cost); if (unlikely((__pyx_t_12 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_v_dist2next); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_arc = new LatticeArc(TD::Convert(((char *)__pyx_t_11)), __pyx_t_12, __pyx_t_13); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":40 + * label = label.encode('utf8') + * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) + * self.lattice[0][index].push_back(arc[0]) # <<<<<<<<<<<<<< + * del arc + * + */ + ((__pyx_v_self->lattice[0])[__pyx_v_index]).push_back((__pyx_v_arc[0])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":41 + * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) + * self.lattice[0][index].push_back(arc[0]) + * del arc # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + delete __pyx_v_arc; } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.CandidateSet.add_kbest", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_hypergraph), __pyx_ptype_5_cdec_Hypergraph, 1, "hypergraph", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12CandidateSet_11add_kbest(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), __pyx_v_hypergraph, __pyx_v_k); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("_cdec.Lattice.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_label); + __Pyx_XDECREF(__pyx_v_cost); + __Pyx_XDECREF(__pyx_v_dist2next); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":90 - * yield self[i] +/* Python wrapper */ +static Py_ssize_t __pyx_pw_5_cdec_7Lattice_7__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_7Lattice_7__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Lattice_6__len__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":43 + * del arc * - * def add_kbest(self, Hypergraph hypergraph, unsigned k): # <<<<<<<<<<<<<< - * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) + * def __len__(self): # <<<<<<<<<<<<<< + * return self.lattice.size() * */ -static PyObject *__pyx_pf_5_cdec_12CandidateSet_11add_kbest(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph, unsigned int __pyx_v_k) { - PyObject *__pyx_r = NULL; +static Py_ssize_t __pyx_pf_5_cdec_7Lattice_6__len__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { + Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("add_kbest", 0); + __Pyx_RefNannySetupContext("__len__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":91 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":44 * - * def add_kbest(self, Hypergraph hypergraph, unsigned k): - * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) # <<<<<<<<<<<<<< + * def __len__(self): + * return self.lattice.size() # <<<<<<<<<<<<<< * - * cdef class SegmentEvaluator: + * def __str__(self): */ - __pyx_v_self->cs->AddKBestCandidates((__pyx_v_hypergraph->hg[0]), __pyx_v_k, __pyx_v_self->scorer->get()); + __pyx_r = __pyx_v_self->lattice->size(); + goto __pyx_L0; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); + __pyx_r = 0; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":97 - * cdef mteval.EvaluationMetric* metric - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.scorer - * - */ - -static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":98 - * - * def __dealloc__(self): - * del self.scorer # <<<<<<<<<<<<<< - * - * def evaluate(self, sentence): - */ - delete __pyx_v_self->scorer; - - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence); /*proto*/ -static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence) { +static PyObject *__pyx_pw_5_cdec_7Lattice_9__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Lattice_9__str__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("evaluate (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self), ((PyObject *)__pyx_v_sentence)); + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Lattice_8__str__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":100 - * del self.scorer +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":46 + * return self.lattice.size() + * + * def __str__(self): # <<<<<<<<<<<<<< + * return hypergraph.AsPLF(self.lattice[0], True).c_str() * - * def evaluate(self, sentence): # <<<<<<<<<<<<<< - * cdef vector[WordID] hyp - * cdef SufficientStats sf = SufficientStats() */ -static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, PyObject *__pyx_v_sentence) { - std::vector __pyx_v_hyp; - struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sf = 0; +static PyObject *__pyx_pf_5_cdec_7Lattice_8__str__(struct __pyx_obj_5_cdec_Lattice *__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("evaluate", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":102 - * def evaluate(self, sentence): - * cdef vector[WordID] hyp - * cdef SufficientStats sf = SufficientStats() # <<<<<<<<<<<<<< - * sf.metric = self.metric - * sf.stats = new mteval.SufficientStats() - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_sf = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":103 - * cdef vector[WordID] hyp - * cdef SufficientStats sf = SufficientStats() - * sf.metric = self.metric # <<<<<<<<<<<<<< - * sf.stats = new mteval.SufficientStats() - * ConvertSentence(string(as_str(sentence.strip())), &hyp) - */ - __pyx_v_sf->metric = __pyx_v_self->metric; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":104 - * cdef SufficientStats sf = SufficientStats() - * sf.metric = self.metric - * sf.stats = new mteval.SufficientStats() # <<<<<<<<<<<<<< - * ConvertSentence(string(as_str(sentence.strip())), &hyp) - * self.scorer.get().Evaluate(hyp, sf.stats) - */ - __pyx_v_sf->stats = new SufficientStats(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":105 - * sf.metric = self.metric - * sf.stats = new mteval.SufficientStats() - * ConvertSentence(string(as_str(sentence.strip())), &hyp) # <<<<<<<<<<<<<< - * self.scorer.get().Evaluate(hyp, sf.stats) - * return sf - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __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_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_2, NULL)), (&__pyx_v_hyp)); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_RefNannySetupContext("__str__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":106 - * sf.stats = new mteval.SufficientStats() - * ConvertSentence(string(as_str(sentence.strip())), &hyp) - * self.scorer.get().Evaluate(hyp, sf.stats) # <<<<<<<<<<<<<< - * return sf + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":47 * - */ - __pyx_v_self->scorer->get()->Evaluate(__pyx_v_hyp, __pyx_v_sf->stats); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":107 - * ConvertSentence(string(as_str(sentence.strip())), &hyp) - * self.scorer.get().Evaluate(hyp, sf.stats) - * return sf # <<<<<<<<<<<<<< + * def __str__(self): + * return hypergraph.AsPLF(self.lattice[0], True).c_str() # <<<<<<<<<<<<<< * - * def candidate_set(self): + * def __iter__(self): */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_sf)); - __pyx_r = ((PyObject *)__pyx_v_sf); + __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->lattice[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __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_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_cdec.SegmentEvaluator.evaluate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Lattice.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_sf); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5_cdec_7Lattice_12generator13(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5_cdec_7Lattice_11__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Lattice_11__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("candidate_set (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Lattice_10__iter__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":109 - * return sf - * - * def candidate_set(self): # <<<<<<<<<<<<<< - * return CandidateSet(self) +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":49 + * return hypergraph.AsPLF(self.lattice[0], True).c_str() * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(len(self)): */ -static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__ *__pyx_cur_scope; 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("candidate_set", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":110 - * - * def candidate_set(self): - * return CandidateSet(self) # <<<<<<<<<<<<<< - * - * cdef class Scorer: - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_CandidateSet)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; + __Pyx_RefNannySetupContext("__iter__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_17___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_17___iter__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Lattice_12generator13, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } __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.SegmentEvaluator.candidate_set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Lattice.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* Python wrapper */ -static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - char *__pyx_v_name; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__name,0}; - int __pyx_r; +static PyObject *__pyx_gb_5_cdec_7Lattice_12generator13(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + Py_ssize_t __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[1] = {0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__name); - 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 115; __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_name = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_RefNannyFinishContext(); + return NULL; } - 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[5]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.Scorer.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_6Scorer___cinit__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self), __pyx_v_name); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 - * cdef string* name - * - * def __cinit__(self, char* name): # <<<<<<<<<<<<<< - * self.name = new string(name) + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":51 + * def __iter__(self): + * cdef unsigned i + * for i in range(len(self)): # <<<<<<<<<<<<<< + * yield self[i] * */ + __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; -static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, char *__pyx_v_name) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":116 - * - * def __cinit__(self, char* name): - * self.name = new string(name) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":52 + * cdef unsigned i + * for i in range(len(self)): + * yield self[i] # <<<<<<<<<<<<<< * * def __dealloc__(self): */ - __pyx_v_self->name = new std::string(__pyx_v_name); - - __pyx_r = 0; + __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 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_generator->resume_label = 1; + return __pyx_r; + __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[4]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return __pyx_r; + return NULL; } /* Python wrapper */ -static void __pyx_pw_5_cdec_6Scorer_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_6Scorer_3__dealloc__(PyObject *__pyx_v_self) { +static void __pyx_pw_5_cdec_7Lattice_14__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_7Lattice_14__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_6Scorer_2__dealloc__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self)); + __pyx_pf_5_cdec_7Lattice_13__dealloc__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":118 - * self.name = new string(name) +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":54 + * yield self[i] * * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.name + * del self.lattice * */ -static void __pyx_pf_5_cdec_6Scorer_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Scorer *__pyx_v_self) { +static void __pyx_pf_5_cdec_7Lattice_13__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":119 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":55 * * def __dealloc__(self): - * del self.name # <<<<<<<<<<<<<< + * del self.lattice # <<<<<<<<<<<<<< * - * def __call__(self, refs): + * def todot(self): */ - delete __pyx_v_self->name; + delete __pyx_v_self->lattice; __Pyx_RefNannyFinishContext(); } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_refs = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__refs,0}; +static PyObject *__pyx_pw_5_cdec_7Lattice_16todot(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Lattice_16todot(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__call__ (wrapper)", 0); - { - PyObject* values[1] = {0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__refs); - 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, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 121; __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_refs = values[0]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.Scorer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannySetupContext("todot (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Lattice_15todot(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_6Scorer_4__call__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self), __pyx_v_refs); + return __pyx_r; +} +static PyObject *__pyx_gb_5_cdec_7Lattice_5todot_2generator19(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Lattice_5todot_1lines(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyMethodDef __pyx_mdef_5_cdec_7Lattice_5todot_1lines = {__Pyx_NAMESTR("lines"), (PyCFunction)__pyx_pw_5_cdec_7Lattice_5todot_1lines, METH_NOARGS, __Pyx_DOCSTR(0)}; +static PyObject *__pyx_pw_5_cdec_7Lattice_5todot_1lines(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("lines (wrapper)", 0); + __pyx_self = __pyx_self; + __pyx_r = __pyx_pf_5_cdec_7Lattice_5todot_lines(__pyx_self); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":121 - * del self.name +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":58 * - * def __call__(self, refs): # <<<<<<<<<<<<<< - * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) - * if isinstance(refs, unicode) or isinstance(refs, str): + * def todot(self): + * def lines(): # <<<<<<<<<<<<<< + * yield 'digraph lattice {' + * yield 'rankdir = LR;' */ -static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs) { - EvaluationMetric *__pyx_v_metric; - std::vector > *__pyx_v_refsv; - std::vector *__pyx_v_refv; - PyObject *__pyx_v_ref = NULL; - struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator = 0; +static PyObject *__pyx_pf_5_cdec_7Lattice_5todot_lines(PyObject *__pyx_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_19_lines *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - Py_ssize_t __pyx_t_5; - PyObject *(*__pyx_t_6)(PyObject *); - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__call__", 0); - __Pyx_INCREF(__pyx_v_refs); + __Pyx_RefNannySetupContext("lines", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_19_lines *)__pyx_ptype_5_cdec___pyx_scope_struct_19_lines->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_19_lines, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot *) __Pyx_CyFunction_GetClosure(__pyx_self); + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Lattice_5todot_2generator19, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":122 - * - * def __call__(self, refs): - * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) # <<<<<<<<<<<<<< - * if isinstance(refs, unicode) or isinstance(refs, str): - * refs = [refs] - */ - __pyx_v_metric = EvaluationMetric::Instance((__pyx_v_self->name[0])); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Lattice.todot.lines", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":123 - * def __call__(self, refs): - * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) - * if isinstance(refs, unicode) or isinstance(refs, str): # <<<<<<<<<<<<<< - * refs = [refs] - * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() - */ - __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_refs, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!__pyx_t_2) { - __pyx_t_1 = ((PyObject *)((PyObject*)(&PyString_Type))); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_refs, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = __pyx_t_3; - } else { - __pyx_t_4 = __pyx_t_2; +static PyObject *__pyx_gb_5_cdec_7Lattice_5todot_2generator19(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_19_lines *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_19_lines *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *(*__pyx_t_4)(PyObject *); + PyObject *__pyx_t_5 = NULL; + Py_ssize_t __pyx_t_6; + PyObject *(*__pyx_t_7)(PyObject *); + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *(*__pyx_t_12)(PyObject *); + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L4_resume_from_yield; + case 2: goto __pyx_L5_resume_from_yield; + case 3: goto __pyx_L6_resume_from_yield; + case 4: goto __pyx_L13_resume_from_yield; + case 5: goto __pyx_L14_resume_from_yield; + case 6: goto __pyx_L15_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_RefNannyFinishContext(); + return NULL; } - if (__pyx_t_4) { + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":124 - * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) - * if isinstance(refs, unicode) or isinstance(refs, str): - * refs = [refs] # <<<<<<<<<<<<<< - * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() - * cdef vector[WordID]* refv + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":59 + * def todot(self): + * def lines(): + * yield 'digraph lattice {' # <<<<<<<<<<<<<< + * yield 'rankdir = LR;' + * yield 'node [shape=circle];' */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_refs); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_refs); - __Pyx_GIVEREF(__pyx_v_refs); - __Pyx_DECREF(__pyx_v_refs); - __pyx_v_refs = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":125 - * if isinstance(refs, unicode) or isinstance(refs, str): - * refs = [refs] - * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() # <<<<<<<<<<<<<< - * cdef vector[WordID]* refv - * cdef bytes ref_str + __Pyx_INCREF(((PyObject *)__pyx_kp_s_27)); + __pyx_r = ((PyObject *)__pyx_kp_s_27); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L4_resume_from_yield:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":60 + * def lines(): + * yield 'digraph lattice {' + * yield 'rankdir = LR;' # <<<<<<<<<<<<<< + * yield 'node [shape=circle];' + * for i in range(len(self)): */ - __pyx_v_refsv = new std::vector >(); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_28)); + __pyx_r = ((PyObject *)__pyx_kp_s_28); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 2; + return __pyx_r; + __pyx_L5_resume_from_yield:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":128 - * cdef vector[WordID]* refv - * cdef bytes ref_str - * for ref in refs: # <<<<<<<<<<<<<< - * refv = new vector[WordID]() - * ConvertSentence(string(as_str(ref.strip())), refv) + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":61 + * yield 'digraph lattice {' + * yield 'rankdir = LR;' + * yield 'node [shape=circle];' # <<<<<<<<<<<<<< + * for i in range(len(self)): + * for label, weight, delta in self[i]: */ - if (PyList_CheckExact(__pyx_v_refs) || PyTuple_CheckExact(__pyx_v_refs)) { - __pyx_t_1 = __pyx_v_refs; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0; - __pyx_t_6 = NULL; + __Pyx_INCREF(((PyObject *)__pyx_kp_s_29)); + __pyx_r = ((PyObject *)__pyx_kp_s_29); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 3; + return __pyx_r; + __pyx_L6_resume_from_yield:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":62 + * yield 'rankdir = LR;' + * yield 'node [shape=circle];' + * for i in range(len(self)): # <<<<<<<<<<<<<< + * for label, weight, delta in self[i]: + * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) + */ + if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } + __pyx_t_1 = ((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = 0; + __pyx_t_4 = NULL; } else { - __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_refs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; + __pyx_t_2 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; for (;;) { - if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; - } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_3)) break; + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; } else { - __pyx_t_7 = __pyx_t_6(__pyx_t_1); - if (unlikely(!__pyx_t_7)) { + __pyx_t_1 = __pyx_t_4(__pyx_t_3); + if (unlikely(!__pyx_t_1)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } - __Pyx_GOTREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_t_1); } - __Pyx_XDECREF(__pyx_v_ref); - __pyx_v_ref = __pyx_t_7; - __pyx_t_7 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":129 - * cdef bytes ref_str - * for ref in refs: - * refv = new vector[WordID]() # <<<<<<<<<<<<<< - * ConvertSentence(string(as_str(ref.strip())), refv) - * refsv.push_back(refv[0]) - */ - __pyx_v_refv = new std::vector(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":130 - * for ref in refs: - * refv = new vector[WordID]() - * ConvertSentence(string(as_str(ref.strip())), refv) # <<<<<<<<<<<<<< - * refsv.push_back(refv[0]) - * del refv - */ - __pyx_t_7 = PyObject_GetAttr(__pyx_v_ref, __pyx_n_s__strip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_8, NULL)), __pyx_v_refv); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":131 - * refv = new vector[WordID]() - * ConvertSentence(string(as_str(ref.strip())), refv) - * refsv.push_back(refv[0]) # <<<<<<<<<<<<<< - * del refv - * cdef unsigned i - */ - __pyx_v_refsv->push_back((__pyx_v_refv[0])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":132 - * ConvertSentence(string(as_str(ref.strip())), refv) - * refsv.push_back(refv[0]) - * del refv # <<<<<<<<<<<<<< - * cdef unsigned i - * cdef SegmentEvaluator evaluator = SegmentEvaluator() - */ - delete __pyx_v_refv; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_i); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_i); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_i = __pyx_t_1; + __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":134 - * del refv - * cdef unsigned i - * cdef SegmentEvaluator evaluator = SegmentEvaluator() # <<<<<<<<<<<<<< - * evaluator.metric = metric - * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":63 + * yield 'node [shape=circle];' + * for i in range(len(self)): + * for label, weight, delta in self[i]: # <<<<<<<<<<<<<< + * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) + * yield '%d [shape=doublecircle]' % len(self) */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SegmentEvaluator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_evaluator = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_1 = PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i); if (!__pyx_t_1) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_5 = __pyx_t_1; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; + __pyx_t_7 = NULL; + } else { + __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_5)) { + if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break; + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; + } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_5)) { + if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break; + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; + } else { + __pyx_t_1 = __pyx_t_7(__pyx_t_5); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { + PyObject* sequence = __pyx_t_1; + if (likely(PyTuple_CheckExact(sequence))) { + if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { + if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); + } else { + if (unlikely(PyList_GET_SIZE(sequence) != 3)) { + if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_8 = PyList_GET_ITEM(sequence, 0); + __pyx_t_9 = PyList_GET_ITEM(sequence, 1); + __pyx_t_10 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_11 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; + index = 0; __pyx_t_8 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_8)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + index = 1; __pyx_t_9 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_9)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_9); + index = 2; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 3) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L12_unpacking_done; + __pyx_L11_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[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L12_unpacking_done:; + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_label); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_label); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_cur_scope->__pyx_v_label = __pyx_t_8; + __pyx_t_8 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_weight); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_weight); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_v_weight = __pyx_t_9; + __pyx_t_9 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_delta); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_delta); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_delta = __pyx_t_10; + __pyx_t_10 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":135 - * cdef unsigned i - * cdef SegmentEvaluator evaluator = SegmentEvaluator() - * evaluator.metric = metric # <<<<<<<<<<<<<< - * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) - * del refsv # in theory should not delete but store in SegmentEvaluator + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":64 + * for i in range(len(self)): + * for label, weight, delta in self[i]: + * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) # <<<<<<<<<<<<<< + * yield '%d [shape=doublecircle]' % len(self) + * yield '}' */ - __pyx_v_evaluator->metric = __pyx_v_metric; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":136 - * cdef SegmentEvaluator evaluator = SegmentEvaluator() - * evaluator.metric = metric - * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) # <<<<<<<<<<<<<< - * del refsv # in theory should not delete but store in SegmentEvaluator - * return evaluator - */ - __pyx_v_evaluator->scorer = new boost::shared_ptr(__pyx_v_metric->CreateSegmentEvaluator((__pyx_v_refsv[0]))); + __pyx_t_1 = PyNumber_Add(__pyx_cur_scope->__pyx_v_i, __pyx_cur_scope->__pyx_v_delta); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_label, __pyx_n_s__replace); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_k_tuple_33), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_cur_scope->__pyx_v_i); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_t_1 = 0; + __pyx_t_9 = 0; + __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_30), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __pyx_r = ((PyObject *)__pyx_t_9); + __pyx_t_9 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; + __Pyx_XGIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; + __Pyx_XGIVEREF(__pyx_t_5); + __pyx_cur_scope->__pyx_t_3 = __pyx_t_5; + __pyx_cur_scope->__pyx_t_4 = __pyx_t_6; + __pyx_cur_scope->__pyx_t_5 = __pyx_t_7; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 4; + return __pyx_r; + __pyx_L13_resume_from_yield:; + __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_t_3); + __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; + __pyx_t_5 = __pyx_cur_scope->__pyx_t_3; + __pyx_cur_scope->__pyx_t_3 = 0; + __Pyx_XGOTREF(__pyx_t_5); + __pyx_t_6 = __pyx_cur_scope->__pyx_t_4; + __pyx_t_7 = __pyx_cur_scope->__pyx_t_5; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":137 - * evaluator.metric = metric - * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) - * del refsv # in theory should not delete but store in SegmentEvaluator # <<<<<<<<<<<<<< - * return evaluator - * + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":65 + * for label, weight, delta in self[i]: + * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) + * yield '%d [shape=doublecircle]' % len(self) # <<<<<<<<<<<<<< + * yield '}' + * return '\n'.join(lines()).encode('utf8') */ - delete __pyx_v_refsv; + __pyx_t_3 = ((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_2 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_34), __pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = ((PyObject *)__pyx_t_5); + __pyx_t_5 = 0; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 5; + return __pyx_r; + __pyx_L14_resume_from_yield:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":138 - * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) - * del refsv # in theory should not delete but store in SegmentEvaluator - * return evaluator # <<<<<<<<<<<<<< - * - * def __str__(self): + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":66 + * yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"')) + * yield '%d [shape=doublecircle]' % len(self) + * yield '}' # <<<<<<<<<<<<<< + * return '\n'.join(lines()).encode('utf8') */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_evaluator)); - __pyx_r = ((PyObject *)__pyx_v_evaluator); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_35)); + __pyx_r = ((PyObject *)__pyx_kp_s_35); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 6; + return __pyx_r; + __pyx_L15_resume_from_yield:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("_cdec.Scorer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("lines", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; - __Pyx_XDECREF(__pyx_v_ref); - __Pyx_XDECREF((PyObject *)__pyx_v_evaluator); - __Pyx_XDECREF(__pyx_v_refs); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_6Scorer_7__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_6Scorer_7__str__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_6Scorer_6__str__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self)); + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; __Pyx_RefNannyFinishContext(); - return __pyx_r; + return NULL; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":140 - * return evaluator - * - * def __str__(self): # <<<<<<<<<<<<<< - * return self.name.c_str() +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":57 + * del self.lattice * + * def todot(self): # <<<<<<<<<<<<<< + * def lines(): + * yield 'digraph lattice {' */ -static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_7Lattice_15todot(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot *__pyx_cur_scope; + PyObject *__pyx_v_lines = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__str__", 0); + __Pyx_RefNannySetupContext("todot", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot *)__pyx_ptype_5_cdec___pyx_scope_struct_18_todot->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_18_todot, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":141 - * - * def __str__(self): - * return self.name.c_str() # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":58 * - * BLEU = Scorer('IBM_BLEU') + * def todot(self): + * def lines(): # <<<<<<<<<<<<<< + * yield 'digraph lattice {' + * yield 'rankdir = LR;' */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(__pyx_v_self->name->c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_r = ((PyObject *)__pyx_t_1); + __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_5_cdec_7Lattice_5todot_1lines, 0, ((PyObject*)__pyx_cur_scope), __pyx_n_s___cdec, ((PyObject *)__pyx_k_codeobj_37)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_lines = __pyx_t_1; __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":67 + * yield '%d [shape=doublecircle]' % len(self) + * yield '}' + * return '\n'.join(lines()).encode('utf8') # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_39), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_v_lines, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_40), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_AddTraceback("_cdec.Scorer.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec.Lattice.todot", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_lines); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_4generator14(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_3_make_config(PyObject *__pyx_self, PyObject *__pyx_v_config); /*proto*/ -static PyMethodDef __pyx_mdef_5_cdec_3_make_config = {__Pyx_NAMESTR("_make_config"), (PyCFunction)__pyx_pw_5_cdec_3_make_config, METH_O, __Pyx_DOCSTR(0)}; -static PyObject *__pyx_pw_5_cdec_3_make_config(PyObject *__pyx_self, PyObject *__pyx_v_config) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_make_config (wrapper)", 0); - __pyx_self = __pyx_self; - __pyx_r = __pyx_pf_5_cdec_2_make_config(__pyx_self, ((PyObject *)__pyx_v_config)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* "_cdec.pyx":27 - * class ParseFailed(Exception): pass +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":3 + * cimport mteval * - * def _make_config(config): # <<<<<<<<<<<<<< - * for key, value in config.items(): - * if isinstance(value, dict): + * cdef SufficientStats as_stats(x, y): # <<<<<<<<<<<<<< + * if isinstance(x, SufficientStats): + * return x */ -static PyObject *__pyx_pf_5_cdec_2_make_config(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_config) { - struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *__pyx_cur_scope; - PyObject *__pyx_r = NULL; +static struct __pyx_obj_5_cdec_SufficientStats *__pyx_f_5_cdec_as_stats(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_stats = NULL; + struct __pyx_obj_5_cdec_SufficientStats *__pyx_r = NULL; __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_make_config", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *)__pyx_ptype_5_cdec___pyx_scope_struct_20__make_config->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_20__make_config, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_v_config = __pyx_v_config; - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_config); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_config); - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_4generator14, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } + __Pyx_RefNannySetupContext("as_stats", 0); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec._make_config", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":4 + * + * cdef SufficientStats as_stats(x, y): + * if isinstance(x, SufficientStats): # <<<<<<<<<<<<<< + * return x + * elif x == 0 and isinstance(y, SufficientStats): + */ + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { -static PyObject *__pyx_gb_5_cdec_4generator14(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - Py_ssize_t __pyx_t_3; - PyObject *(*__pyx_t_4)(PyObject *); - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *(*__pyx_t_8)(PyObject *); - int __pyx_t_9; - Py_ssize_t __pyx_t_10; - PyObject *(*__pyx_t_11)(PyObject *); - PyObject *__pyx_t_12 = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("None", 0); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L13_resume_from_yield; - case 2: goto __pyx_L16_resume_from_yield; - case 3: goto __pyx_L17_resume_from_yield; - default: /* CPython raises the right error here */ - __Pyx_RefNannyFinishContext(); - return NULL; + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":5 + * cdef SufficientStats as_stats(x, y): + * if isinstance(x, SufficientStats): + * return x # <<<<<<<<<<<<<< + * elif x == 0 and isinstance(y, SufficientStats): + * stats = SufficientStats() + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SufficientStats))))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_x); + __pyx_r = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_x); + goto __pyx_L0; + goto __pyx_L3; } - __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "_cdec.pyx":28 - * - * def _make_config(config): - * for key, value in config.items(): # <<<<<<<<<<<<<< - * if isinstance(value, dict): - * for name, info in value.items(): + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":6 + * if isinstance(x, SufficientStats): + * return x + * elif x == 0 and isinstance(y, SufficientStats): # <<<<<<<<<<<<<< + * stats = SufficientStats() + * stats.stats = new mteval.SufficientStats() */ - __pyx_t_1 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_config, __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_RichCompare(__pyx_v_x, __pyx_int_0, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __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 = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0; - __pyx_t_4 = NULL; + if (__pyx_t_2) { + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_y, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __pyx_t_3; } else { - __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; + __pyx_t_4 = __pyx_t_2; } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; - } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; - } else { - __pyx_t_2 = __pyx_t_4(__pyx_t_1); - if (unlikely(!__pyx_t_2)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { - PyObject* sequence = __pyx_t_2; - if (likely(PyTuple_CheckExact(sequence))) { - 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 = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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 = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_5 = PyList_GET_ITEM(sequence, 0); - __pyx_t_6 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; - index = 0; __pyx_t_5 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_5); - index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_6); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L7_unpacking_done; - __pyx_L6_unpacking_failed:; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L7_unpacking_done:; - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_key); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_key); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_cur_scope->__pyx_v_key = __pyx_t_5; - __pyx_t_5 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_value); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_value); - __Pyx_GIVEREF(__pyx_t_6); - __pyx_cur_scope->__pyx_v_value = __pyx_t_6; - __pyx_t_6 = 0; + if (__pyx_t_4) { - /* "_cdec.pyx":29 - * def _make_config(config): - * for key, value in config.items(): - * if isinstance(value, dict): # <<<<<<<<<<<<<< - * for name, info in value.items(): - * yield key, '%s %s' % (name, info) + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":7 + * return x + * elif x == 0 and isinstance(y, SufficientStats): + * stats = SufficientStats() # <<<<<<<<<<<<<< + * stats.stats = new mteval.SufficientStats() + * stats.metric = ( y).metric */ - __pyx_t_2 = ((PyObject *)((PyObject*)(&PyDict_Type))); - __Pyx_INCREF(__pyx_t_2); - __pyx_t_9 = __Pyx_TypeCheck(__pyx_cur_scope->__pyx_v_value, __pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_9) { + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_stats = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; - /* "_cdec.pyx":30 - * for key, value in config.items(): - * if isinstance(value, dict): - * for name, info in value.items(): # <<<<<<<<<<<<<< - * yield key, '%s %s' % (name, info) - * elif isinstance(value, list): + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":8 + * elif x == 0 and isinstance(y, SufficientStats): + * stats = SufficientStats() + * stats.stats = new mteval.SufficientStats() # <<<<<<<<<<<<<< + * stats.metric = ( y).metric + * return stats */ - __pyx_t_2 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_value, __pyx_n_s__items); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyList_CheckExact(__pyx_t_6) || PyTuple_CheckExact(__pyx_t_6)) { - __pyx_t_2 = __pyx_t_6; __Pyx_INCREF(__pyx_t_2); __pyx_t_10 = 0; - __pyx_t_11 = NULL; - } else { - __pyx_t_10 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = Py_TYPE(__pyx_t_2)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - for (;;) { - if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_2)) { - if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_2)) break; - __pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; - } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_2)) { - if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; - } else { - __pyx_t_6 = __pyx_t_11(__pyx_t_2); - if (unlikely(!__pyx_t_6)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_6); - } - if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) { - PyObject* sequence = __pyx_t_6; - if (likely(PyTuple_CheckExact(sequence))) { - 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 = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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 = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_5 = PyList_GET_ITEM(sequence, 0); - __pyx_t_7 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_12 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_12)->tp_iternext; - index = 0; __pyx_t_5 = __pyx_t_8(__pyx_t_12); if (unlikely(!__pyx_t_5)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_5); - index = 1; __pyx_t_7 = __pyx_t_8(__pyx_t_12); if (unlikely(!__pyx_t_7)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_12), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - goto __pyx_L12_unpacking_done; - __pyx_L11_unpacking_failed:; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L12_unpacking_done:; - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_name); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_name); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_cur_scope->__pyx_v_name = __pyx_t_5; - __pyx_t_5 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_info); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_info); - __Pyx_GIVEREF(__pyx_t_7); - __pyx_cur_scope->__pyx_v_info = __pyx_t_7; - __pyx_t_7 = 0; + __pyx_v_stats->stats = new SufficientStats(); - /* "_cdec.pyx":31 - * if isinstance(value, dict): - * for name, info in value.items(): - * yield key, '%s %s' % (name, info) # <<<<<<<<<<<<<< - * elif isinstance(value, list): - * for name in value: - */ - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_name); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_cur_scope->__pyx_v_name); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_name); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_info); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_cur_scope->__pyx_v_info); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_info); - __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_39), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_7)); - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_cur_scope->__pyx_v_key); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_t_7)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_7)); - __pyx_t_7 = 0; - __pyx_r = ((PyObject *)__pyx_t_6); - __pyx_t_6 = 0; - __Pyx_XGIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; - __Pyx_XGIVEREF(__pyx_t_2); - __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; - __pyx_cur_scope->__pyx_t_3 = __pyx_t_4; - __pyx_cur_scope->__pyx_t_4 = __pyx_t_10; - __pyx_cur_scope->__pyx_t_5 = __pyx_t_11; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L13_resume_from_yield:; - __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; - __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; - __pyx_cur_scope->__pyx_t_1 = 0; - __Pyx_XGOTREF(__pyx_t_2); - __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - __pyx_t_4 = __pyx_cur_scope->__pyx_t_3; - __pyx_t_10 = __pyx_cur_scope->__pyx_t_4; - __pyx_t_11 = __pyx_cur_scope->__pyx_t_5; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L8; - } - - /* "_cdec.pyx":32 - * for name, info in value.items(): - * yield key, '%s %s' % (name, info) - * elif isinstance(value, list): # <<<<<<<<<<<<<< - * for name in value: - * yield key, name - */ - __pyx_t_2 = ((PyObject *)((PyObject*)(&PyList_Type))); - __Pyx_INCREF(__pyx_t_2); - __pyx_t_9 = __Pyx_TypeCheck(__pyx_cur_scope->__pyx_v_value, __pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_9) { - - /* "_cdec.pyx":33 - * yield key, '%s %s' % (name, info) - * elif isinstance(value, list): - * for name in value: # <<<<<<<<<<<<<< - * yield key, name - * else: - */ - if (PyList_CheckExact(__pyx_cur_scope->__pyx_v_value) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_value)) { - __pyx_t_2 = __pyx_cur_scope->__pyx_v_value; __Pyx_INCREF(__pyx_t_2); __pyx_t_10 = 0; - __pyx_t_11 = NULL; - } else { - __pyx_t_10 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_value); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = Py_TYPE(__pyx_t_2)->tp_iternext; - } - for (;;) { - if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_2)) { - if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_2)) break; - __pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; - } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_2)) { - if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; - } else { - __pyx_t_6 = __pyx_t_11(__pyx_t_2); - if (unlikely(!__pyx_t_6)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_6); - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_name); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_name); - __Pyx_GIVEREF(__pyx_t_6); - __pyx_cur_scope->__pyx_v_name = __pyx_t_6; - __pyx_t_6 = 0; - - /* "_cdec.pyx":34 - * elif isinstance(value, list): - * for name in value: - * yield key, name # <<<<<<<<<<<<<< - * else: - * yield key, bytes(value) + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":9 + * stats = SufficientStats() + * stats.stats = new mteval.SufficientStats() + * stats.metric = ( y).metric # <<<<<<<<<<<<<< + * return stats + * */ - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_cur_scope->__pyx_v_key); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_name); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_cur_scope->__pyx_v_name); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_name); - __pyx_r = ((PyObject *)__pyx_t_6); - __pyx_t_6 = 0; - __Pyx_XGIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; - __Pyx_XGIVEREF(__pyx_t_2); - __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; - __pyx_cur_scope->__pyx_t_3 = __pyx_t_4; - __pyx_cur_scope->__pyx_t_4 = __pyx_t_10; - __pyx_cur_scope->__pyx_t_5 = __pyx_t_11; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 2; - return __pyx_r; - __pyx_L16_resume_from_yield:; - __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; - __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; - __pyx_cur_scope->__pyx_t_1 = 0; - __Pyx_XGOTREF(__pyx_t_2); - __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - __pyx_t_4 = __pyx_cur_scope->__pyx_t_3; - __pyx_t_10 = __pyx_cur_scope->__pyx_t_4; - __pyx_t_11 = __pyx_cur_scope->__pyx_t_5; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L8; - } - /*else*/ { + __pyx_v_stats->metric = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_y)->metric; - /* "_cdec.pyx":36 - * yield key, name - * else: - * yield key, bytes(value) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":10 + * stats.stats = new mteval.SufficientStats() + * stats.metric = ( y).metric + * return stats # <<<<<<<<<<<<<< * - * cdef class Decoder: + * cdef class Candidate: */ - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_value); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_value); - __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyBytes_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_key); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_6); - __pyx_t_6 = 0; - __pyx_r = ((PyObject *)__pyx_t_2); - __pyx_t_2 = 0; - __Pyx_XGIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; - __pyx_cur_scope->__pyx_t_3 = __pyx_t_4; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 3; - return __pyx_r; - __pyx_L17_resume_from_yield:; - __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; - __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_1); - __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - __pyx_t_4 = __pyx_cur_scope->__pyx_t_3; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L8:; + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_stats)); + __pyx_r = __pyx_v_stats; + goto __pyx_L0; + goto __pyx_L3; } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - PyErr_SetNone(PyExc_StopIteration); + __pyx_L3:; + + __pyx_r = ((struct __pyx_obj_5_cdec_SufficientStats *)Py_None); __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_AddTraceback("_make_config", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.as_stats", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; + __Pyx_XDECREF((PyObject *)__pyx_v_stats); + __Pyx_XGIVEREF((PyObject *)__pyx_r); __Pyx_RefNannyFinishContext(); - return NULL; + return __pyx_r; } /* Python wrapper */ -static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_config_str = 0; - PyObject *__pyx_v_config = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__config_str,0}; - int __pyx_r; +static PyObject *__pyx_pw_5_cdec_9Candidate_5words_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9Candidate_5words_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - __pyx_v_config = PyDict_New(); if (unlikely(!__pyx_v_config)) return -1; - __Pyx_GOTREF(__pyx_v_config); - { - PyObject* values[1] = {0}; + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9Candidate_5words___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":42 - * cdef DenseVector weights +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":17 + * + * property words: + * def __get__(self): # <<<<<<<<<<<<<< + * return unicode(GetString(self.candidate.ewords).c_str(), encoding='utf8') * - * def __cinit__(self, config_str=None, **config): # <<<<<<<<<<<<<< - * """ Configuration can be given as a string: - * Decoder('formalism = scfg') - */ - values[0] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__config_str); - if (value) { values[0] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_config, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - 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; - } - } - __pyx_v_config_str = values[0]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 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_CLEAR(__pyx_v_config); - __Pyx_AddTraceback("_cdec.Decoder.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_7Decoder___cinit__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_config_str, __pyx_v_config); - __Pyx_XDECREF(__pyx_v_config); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -static PyObject *__pyx_gb_5_cdec_7Decoder_9__cinit___2generator18(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ - -/* "_cdec.pyx":53 - * 'csplit', 'tagger', 'lexalign'): - * raise InvalidConfig('formalism "%s" unknown' % formalism) - * config_str = '\n'.join('%s = %s' % kv for kv in _make_config(config)) # <<<<<<<<<<<<<< - * cdef istringstream* config_stream = new istringstream(config_str) - * self.dec = new decoder.Decoder(config_stream) */ -static PyObject *__pyx_pf_5_cdec_7Decoder_9__cinit___genexpr(PyObject *__pyx_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("genexpr", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *)__pyx_ptype_5_cdec___pyx_scope_struct_22_genexpr->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_22_genexpr, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *) __pyx_self; - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Decoder_9__cinit___2generator18, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } + __Pyx_RefNannySetupContext("__get__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":18 + * property words: + * def __get__(self): + * return unicode(GetString(self.candidate.ewords).c_str(), encoding='utf8') # <<<<<<<<<<<<<< + * + * property fmap: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(TD::GetString(__pyx_v_self->candidate->ewords).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 18; __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[5]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__encoding), ((PyObject *)__pyx_n_s__utf8)) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Decoder.__cinit__.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec.Candidate.words.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_7Decoder_9__cinit___2generator18(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - Py_ssize_t __pyx_t_4; - PyObject *(*__pyx_t_5)(PyObject *); +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_9Candidate_4fmap_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9Candidate_4fmap_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("None", 0); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_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 = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___make_config); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_config)) { __Pyx_RaiseClosureNameError("config"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __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 = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_config); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_config); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_config); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0; - __pyx_t_5 = NULL; - } else { - __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_2)) { - if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break; - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; - } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_2)) { - if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; - } else { - __pyx_t_3 = __pyx_t_5(__pyx_t_2); - if (unlikely(!__pyx_t_3)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_kv); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_kv); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_v_kv = __pyx_t_3; - __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_40), __pyx_cur_scope->__pyx_v_kv); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_r = ((PyObject *)__pyx_t_3); - __pyx_t_3 = 0; - __Pyx_XGIVEREF(__pyx_t_2); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_4; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_5; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L6_resume_from_yield:; - __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; - __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_2); - __pyx_t_4 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_5 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9Candidate_4fmap___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); - return NULL; + return __pyx_r; } -/* "_cdec.pyx":42 - * cdef DenseVector weights +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":21 * - * def __cinit__(self, config_str=None, **config): # <<<<<<<<<<<<<< - * """ Configuration can be given as a string: - * Decoder('formalism = scfg') + * property fmap: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) */ -static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_config_str, PyObject *__pyx_v_config) { - struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *__pyx_cur_scope; - PyObject *__pyx_v_formalism = NULL; - std::istringstream *__pyx_v_config_stream; - int __pyx_r; +static PyObject *__pyx_pf_5_cdec_9Candidate_4fmap___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap = 0; + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - char *__pyx_t_7; + PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *)__pyx_ptype_5_cdec___pyx_scope_struct_21___cinit__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_21___cinit__, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return -1; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_v_config = __pyx_v_config; - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_config); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_config); - __Pyx_INCREF(__pyx_v_config_str); + __Pyx_RefNannySetupContext("__get__", 0); - /* "_cdec.pyx":48 - * Decoder(formalism='scfg') - * """ - * if config_str is None: # <<<<<<<<<<<<<< - * formalism = config.get('formalism', None) - * if formalism not in ('scfg', 'fst', 'lextrans', 'pb', + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":22 + * property fmap: + * def __get__(self): + * cdef SparseVector fmap = SparseVector() # <<<<<<<<<<<<<< + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) + * return fmap */ - __pyx_t_1 = (__pyx_v_config_str == Py_None); - if (__pyx_t_1) { + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; - /* "_cdec.pyx":49 - * """ - * if config_str is None: - * formalism = config.get('formalism', None) # <<<<<<<<<<<<<< - * if formalism not in ('scfg', 'fst', 'lextrans', 'pb', - * 'csplit', 'tagger', 'lexalign'): + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":23 + * def __get__(self): + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) # <<<<<<<<<<<<<< + * return fmap + * */ - __pyx_t_2 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_config, __pyx_n_s__get); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_41), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_formalism = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_v_fmap->vector = new FastSparseVector(__pyx_v_self->candidate->fmap); - /* "_cdec.pyx":50 - * if config_str is None: - * formalism = config.get('formalism', None) - * if formalism not in ('scfg', 'fst', 'lextrans', 'pb', # <<<<<<<<<<<<<< - * 'csplit', 'tagger', 'lexalign'): - * raise InvalidConfig('formalism "%s" unknown' % formalism) - */ - __Pyx_INCREF(__pyx_v_formalism); - __pyx_t_3 = __pyx_v_formalism; - __pyx_t_1 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__scfg), Py_NE); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (((int)__pyx_t_1)) { - __pyx_t_4 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__fst), Py_NE); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_5 = ((int)__pyx_t_4); - } else { - __pyx_t_5 = ((int)__pyx_t_1); - } - if (__pyx_t_5) { - __pyx_t_1 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__lextrans), Py_NE); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = ((int)__pyx_t_1); - } else { - __pyx_t_4 = __pyx_t_5; - } - if (__pyx_t_4) { - __pyx_t_5 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__pb), Py_NE); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = ((int)__pyx_t_5); - } else { - __pyx_t_1 = __pyx_t_4; - } - if (__pyx_t_1) { - __pyx_t_4 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__csplit), Py_NE); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_5 = ((int)__pyx_t_4); - } else { - __pyx_t_5 = __pyx_t_1; - } - if (__pyx_t_5) { - __pyx_t_1 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__tagger), Py_NE); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = ((int)__pyx_t_1); - } else { - __pyx_t_4 = __pyx_t_5; - } - if (__pyx_t_4) { - __pyx_t_5 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__lexalign), Py_NE); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = ((int)__pyx_t_5); - } else { - __pyx_t_1 = __pyx_t_4; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_4 = __pyx_t_1; - if (__pyx_t_4) { - - /* "_cdec.pyx":52 - * if formalism not in ('scfg', 'fst', 'lextrans', 'pb', - * 'csplit', 'tagger', 'lexalign'): - * raise InvalidConfig('formalism "%s" unknown' % formalism) # <<<<<<<<<<<<<< - * config_str = '\n'.join('%s = %s' % kv for kv in _make_config(config)) - * cdef istringstream* config_stream = new istringstream(config_str) + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":24 + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) + * return fmap # <<<<<<<<<<<<<< + * + * cdef class SufficientStats: */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__InvalidConfig); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_42), __pyx_v_formalism); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 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 = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L4; - } - __pyx_L4:; + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_fmap)); + __pyx_r = ((PyObject *)__pyx_v_fmap); + goto __pyx_L0; - /* "_cdec.pyx":53 - * 'csplit', 'tagger', 'lexalign'): - * raise InvalidConfig('formalism "%s" unknown' % formalism) - * config_str = '\n'.join('%s = %s' % kv for kv in _make_config(config)) # <<<<<<<<<<<<<< - * cdef istringstream* config_stream = new istringstream(config_str) - * self.dec = new decoder.Decoder(config_stream) - */ - __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_35), __pyx_n_s__join); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = __pyx_pf_5_cdec_7Decoder_9__cinit___genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_6); - __pyx_t_6 = 0; - __pyx_t_6 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_v_config_str); - __pyx_v_config_str = __pyx_t_6; - __pyx_t_6 = 0; - goto __pyx_L3; - } - __pyx_L3:; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.Candidate.fmap.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_fmap); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":54 - * raise InvalidConfig('formalism "%s" unknown' % formalism) - * config_str = '\n'.join('%s = %s' % kv for kv in _make_config(config)) - * cdef istringstream* config_stream = new istringstream(config_str) # <<<<<<<<<<<<<< - * self.dec = new decoder.Decoder(config_stream) - * del config_stream - */ - __pyx_t_7 = PyBytes_AsString(__pyx_v_config_str); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_config_stream = new std::istringstream(__pyx_t_7); +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_9Candidate_5score_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9Candidate_5score_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9Candidate_5score___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":55 - * config_str = '\n'.join('%s = %s' % kv for kv in _make_config(config)) - * cdef istringstream* config_stream = new istringstream(config_str) - * self.dec = new decoder.Decoder(config_stream) # <<<<<<<<<<<<<< - * del config_stream - * self.weights = DenseVector() +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":14 + * cdef class Candidate: + * cdef mteval.Candidate* candidate + * cdef public float score # <<<<<<<<<<<<<< + * + * property words: */ - __pyx_v_self->dec = new Decoder(__pyx_v_config_stream); - /* "_cdec.pyx":56 - * cdef istringstream* config_stream = new istringstream(config_str) - * self.dec = new decoder.Decoder(config_stream) - * del config_stream # <<<<<<<<<<<<<< - * self.weights = DenseVector() - * self.weights.vector = &self.dec.CurrentWeightVector() - */ - delete __pyx_v_config_stream; +static PyObject *__pyx_pf_5_cdec_9Candidate_5score___get__(struct __pyx_obj_5_cdec_Candidate *__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("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->score); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "_cdec.pyx":57 - * self.dec = new decoder.Decoder(config_stream) - * del config_stream - * self.weights = DenseVector() # <<<<<<<<<<<<<< - * self.weights.vector = &self.dec.CurrentWeightVector() - * - */ - __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_6); - __Pyx_GOTREF(__pyx_v_self->weights); - __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); - __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)__pyx_t_6); - __pyx_t_6 = 0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.Candidate.score.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":58 - * del config_stream - * self.weights = DenseVector() - * self.weights.vector = &self.dec.CurrentWeightVector() # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - __pyx_v_self->weights->vector = (&__pyx_v_self->dec->CurrentWeightVector()); +/* Python wrapper */ +static int __pyx_pw_5_cdec_9Candidate_5score_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_5_cdec_9Candidate_5score_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9Candidate_5score_2__set__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5_cdec_9Candidate_5score_2__set__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + float __pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __pyx_PyFloat_AsFloat(__pyx_v_value); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->score = __pyx_t_1; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("_cdec.Decoder.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Candidate.score.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_formalism); - __Pyx_XDECREF(__pyx_v_config_str); - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self) { +static void __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_7Decoder_2__dealloc__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __pyx_pf_5_cdec_15SufficientStats___dealloc__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); } -/* "_cdec.pyx":60 - * self.weights.vector = &self.dec.CurrentWeightVector() +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":30 + * cdef mteval.EvaluationMetric* metric * * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.dec + * del self.stats * */ -static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { +static void __pyx_pf_5_cdec_15SufficientStats___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "_cdec.pyx":61 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":31 * * def __dealloc__(self): - * del self.dec # <<<<<<<<<<<<<< + * del self.stats # <<<<<<<<<<<<<< * - * property weights: + * property score: */ - delete __pyx_v_self->dec; + delete __pyx_v_self->stats; __Pyx_RefNannyFinishContext(); } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_15SufficientStats_5score_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_5score_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights___get__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_5score___get__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":64 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":34 * - * property weights: + * property score: * def __get__(self): # <<<<<<<<<<<<<< - * return self.weights + * return self.metric.ComputeScore(self.stats[0]) * */ -static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_15SufficientStats_5score___get__(struct __pyx_obj_5_cdec_SufficientStats *__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("__get__", 0); - /* "_cdec.pyx":65 - * property weights: + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":35 + * property score: * def __get__(self): - * return self.weights # <<<<<<<<<<<<<< + * return self.metric.ComputeScore(self.stats[0]) # <<<<<<<<<<<<<< * - * def __set__(self, weights): + * property detail: */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self->weights)); - __pyx_r = ((PyObject *)__pyx_v_self->weights); - goto __pyx_L0; + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->metric->ComputeScore((__pyx_v_self->stats[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_cdec.SufficientStats.score.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); @@ -13035,683 +12961,453 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cd } /* Python wrapper */ -static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_weights); /*proto*/ -static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_weights) { - int __pyx_r; +static PyObject *__pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_2__set__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_weights)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_6detail___get__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":67 - * return self.weights +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":38 + * + * property detail: + * def __get__(self): # <<<<<<<<<<<<<< + * return self.metric.DetailedScore(self.stats[0]).c_str() * - * def __set__(self, weights): # <<<<<<<<<<<<<< - * if isinstance(weights, DenseVector): - * self.weights.vector[0] = ( weights).vector[0] */ -static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_weights) { - PyObject *__pyx_v_fname = NULL; - PyObject *__pyx_v_fval = NULL; - int __pyx_r; +static PyObject *__pyx_pf_5_cdec_15SufficientStats_6detail___get__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - Py_ssize_t __pyx_t_4; - PyObject *(*__pyx_t_5)(PyObject *); - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *(*__pyx_t_9)(PyObject *); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__set__", 0); - - /* "_cdec.pyx":68 - * - * def __set__(self, weights): - * if isinstance(weights, DenseVector): # <<<<<<<<<<<<<< - * self.weights.vector[0] = ( weights).vector[0] - * elif isinstance(weights, SparseVector): - */ - __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "_cdec.pyx":69 - * def __set__(self, weights): - * if isinstance(weights, DenseVector): - * self.weights.vector[0] = ( weights).vector[0] # <<<<<<<<<<<<<< - * elif isinstance(weights, SparseVector): - * self.weights.vector.clear() - */ - (__pyx_v_self->weights->vector[0]) = (((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_weights)->vector[0]); - goto __pyx_L3; - } - - /* "_cdec.pyx":70 - * if isinstance(weights, DenseVector): - * self.weights.vector[0] = ( weights).vector[0] - * elif isinstance(weights, SparseVector): # <<<<<<<<<<<<<< - * self.weights.vector.clear() - * (( weights).vector[0]).init_vector(self.weights.vector) - */ - __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "_cdec.pyx":71 - * self.weights.vector[0] = ( weights).vector[0] - * elif isinstance(weights, SparseVector): - * self.weights.vector.clear() # <<<<<<<<<<<<<< - * (( weights).vector[0]).init_vector(self.weights.vector) - * elif isinstance(weights, dict): - */ - __pyx_v_self->weights->vector->clear(); - - /* "_cdec.pyx":72 - * elif isinstance(weights, SparseVector): - * self.weights.vector.clear() - * (( weights).vector[0]).init_vector(self.weights.vector) # <<<<<<<<<<<<<< - * elif isinstance(weights, dict): - * for fname, fval in weights.items(): - */ - (((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_weights)->vector[0]).init_vector(__pyx_v_self->weights->vector); - goto __pyx_L3; - } - - /* "_cdec.pyx":73 - * self.weights.vector.clear() - * (( weights).vector[0]).init_vector(self.weights.vector) - * elif isinstance(weights, dict): # <<<<<<<<<<<<<< - * for fname, fval in weights.items(): - * self.weights[fname] = fval - */ - __pyx_t_1 = ((PyObject *)((PyObject*)(&PyDict_Type))); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "_cdec.pyx":74 - * (( weights).vector[0]).init_vector(self.weights.vector) - * elif isinstance(weights, dict): - * for fname, fval in weights.items(): # <<<<<<<<<<<<<< - * self.weights[fname] = fval - * else: - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_weights, __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0; - __pyx_t_5 = NULL; - } else { - __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; - } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; - } else { - __pyx_t_3 = __pyx_t_5(__pyx_t_1); - if (unlikely(!__pyx_t_3)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { - PyObject* sequence = __pyx_t_3; - if (likely(PyTuple_CheckExact(sequence))) { - 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 = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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 = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_6 = PyList_GET_ITEM(sequence, 0); - __pyx_t_7 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_8 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; - index = 0; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_6); - index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - goto __pyx_L7_unpacking_done; - __pyx_L6_unpacking_failed:; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L7_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_fname); - __pyx_v_fname = __pyx_t_6; - __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_v_fval); - __pyx_v_fval = __pyx_t_7; - __pyx_t_7 = 0; - - /* "_cdec.pyx":75 - * elif isinstance(weights, dict): - * for fname, fval in weights.items(): - * self.weights[fname] = fval # <<<<<<<<<<<<<< - * else: - * raise TypeError('cannot initialize weights with %s' % type(weights)) - */ - if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_v_fname, __pyx_v_fval) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L3; - } - /*else*/ { + __Pyx_RefNannySetupContext("__get__", 0); - /* "_cdec.pyx":77 - * self.weights[fname] = fval - * else: - * raise TypeError('cannot initialize weights with %s' % type(weights)) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":39 + * property detail: + * def __get__(self): + * return self.metric.DetailedScore(self.stats[0]).c_str() # <<<<<<<<<<<<<< * - * property formalism: + * def __len__(self): */ - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_43), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyTuple_New(1); 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); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L3:; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(__pyx_v_self->metric->DetailedScore((__pyx_v_self->stats[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 39; __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 = 0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("_cdec.Decoder.weights.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_AddTraceback("_cdec.SufficientStats.detail.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_fname); - __Pyx_XDECREF(__pyx_v_fval); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Decoder_9formalism_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Decoder_9formalism_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; +static Py_ssize_t __pyx_pw_5_cdec_15SufficientStats_3__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_15SufficientStats_3__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_9formalism___get__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_2__len__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":80 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":41 + * return self.metric.DetailedScore(self.stats[0]).c_str() * - * property formalism: - * def __get__(self): # <<<<<<<<<<<<<< - * cdef variables_map* conf = &self.dec.GetConf() - * return conf[0]['formalism'].as_str().c_str() - */ + * def __len__(self): # <<<<<<<<<<<<<< + * return self.stats.size() + * + */ -static PyObject *__pyx_pf_5_cdec_7Decoder_9formalism___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { - const boost::program_options::variables_map *__pyx_v_conf; - PyObject *__pyx_r = NULL; +static Py_ssize_t __pyx_pf_5_cdec_15SufficientStats_2__len__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { + Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_RefNannySetupContext("__len__", 0); - /* "_cdec.pyx":81 - * property formalism: - * def __get__(self): - * cdef variables_map* conf = &self.dec.GetConf() # <<<<<<<<<<<<<< - * return conf[0]['formalism'].as_str().c_str() + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":42 * - */ - __pyx_v_conf = (&__pyx_v_self->dec->GetConf()); - - /* "_cdec.pyx":82 - * def __get__(self): - * cdef variables_map* conf = &self.dec.GetConf() - * return conf[0]['formalism'].as_str().c_str() # <<<<<<<<<<<<<< + * def __len__(self): + * return self.stats.size() # <<<<<<<<<<<<<< * - * def read_weights(self, weights): + * def __iter__(self): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(((__pyx_v_conf[0])[__pyx_k__formalism]).as().c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_r = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_r = __pyx_v_self->stats->size(); 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.Decoder.formalism.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; + __pyx_r = 0; __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator14(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_weights); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_weights) { +static PyObject *__pyx_pw_5_cdec_15SufficientStats_5__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_5__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_weights (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_4read_weights(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_weights)); + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_4__iter__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":84 - * return conf[0]['formalism'].as_str().c_str() +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":44 + * return self.stats.size() * - * def read_weights(self, weights): # <<<<<<<<<<<<<< - * with open(weights) as fp: - * for line in fp: + * def __iter__(self): # <<<<<<<<<<<<<< + * for i in range(len(self)): + * yield self.stats[0][i] */ -static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_weights) { - PyObject *__pyx_v_fp = NULL; - PyObject *__pyx_v_line = NULL; - PyObject *__pyx_v_fname = NULL; - PyObject *__pyx_v_value = NULL; +static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - Py_ssize_t __pyx_t_8; - PyObject *(*__pyx_t_9)(PyObject *); - int __pyx_t_10; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; - PyObject *(*__pyx_t_13)(PyObject *); - double __pyx_t_14; - PyObject *__pyx_t_15 = NULL; - int __pyx_t_16; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("read_weights", 0); + __Pyx_RefNannySetupContext("__iter__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_20___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_20___iter__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_15SufficientStats_6generator14, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.SufficientStats.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator14(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *(*__pyx_t_4)(PyObject *); + unsigned int __pyx_t_5; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[5]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "_cdec.pyx":85 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":45 + * + * def __iter__(self): + * for i in range(len(self)): # <<<<<<<<<<<<<< + * yield self.stats[0][i] * - * def read_weights(self, weights): - * with open(weights) as fp: # <<<<<<<<<<<<<< - * for line in fp: - * if line.strip().startswith('#'): continue */ - /*with:*/ { - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_weights); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_weights); - __Pyx_GIVEREF(__pyx_v_weights); - __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 = 85; __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 = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_1 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __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 = 85; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /*try:*/ { - { - __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - /*try:*/ { - __Pyx_INCREF(__pyx_t_4); - __pyx_v_fp = __pyx_t_4; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "_cdec.pyx":86 - * def read_weights(self, weights): - * with open(weights) as fp: - * for line in fp: # <<<<<<<<<<<<<< - * if line.strip().startswith('#'): continue - * fname, value = line.split() - */ - if (PyList_CheckExact(__pyx_v_fp) || PyTuple_CheckExact(__pyx_v_fp)) { - __pyx_t_4 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; - } else { - __pyx_t_2 = __pyx_t_9(__pyx_t_4); - if (unlikely(!__pyx_t_2)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF(__pyx_v_line); - __pyx_v_line = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { + if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_3)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { + if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; + } else { + __pyx_t_2 = __pyx_t_4(__pyx_t_3); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_i); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_i); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + __pyx_t_2 = 0; - /* "_cdec.pyx":87 - * with open(weights) as fp: - * for line in fp: - * if line.strip().startswith('#'): continue # <<<<<<<<<<<<<< - * fname, value = line.split() - * self.weights[fname.strip()] = float(value) + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":46 + * def __iter__(self): + * for i in range(len(self)): + * yield self.stats[0][i] # <<<<<<<<<<<<<< + * + * def __iadd__(SufficientStats self, SufficientStats other): */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__strip); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__startswith); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_45), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_10) { - goto __pyx_L16_continue; - goto __pyx_L18; - } - __pyx_L18:; + __pyx_t_5 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_i); if (unlikely((__pyx_t_5 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyFloat_FromDouble(((__pyx_cur_scope->__pyx_v_self->stats[0])[__pyx_t_5])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __Pyx_XGIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_t_3); + __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} - /* "_cdec.pyx":88 - * for line in fp: - * if line.strip().startswith('#'): continue - * fname, value = line.split() # <<<<<<<<<<<<<< - * self.weights[fname.strip()] = float(value) +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iadd__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SufficientStats, 1, "other", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_7__iadd__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_other)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":48 + * yield self.stats[0][i] * + * def __iadd__(SufficientStats self, SufficientStats other): # <<<<<<<<<<<<<< + * self.stats[0] += other.stats[0] + * return self */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __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 = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { - PyObject* sequence = __pyx_t_2; - if (likely(PyTuple_CheckExact(sequence))) { - 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 = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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 = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - __pyx_t_1 = PyList_GET_ITEM(sequence, 0); - __pyx_t_11 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_12 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_13 = Py_TYPE(__pyx_t_12)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_1)) goto __pyx_L19_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - index = 1; __pyx_t_11 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_11)) goto __pyx_L19_unpacking_failed; - __Pyx_GOTREF(__pyx_t_11); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - goto __pyx_L20_unpacking_done; - __pyx_L19_unpacking_failed:; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_L20_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_fname); - __pyx_v_fname = __pyx_t_1; - __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_v_value); - __pyx_v_value = __pyx_t_11; - __pyx_t_11 = 0; - /* "_cdec.pyx":89 - * if line.strip().startswith('#'): continue - * fname, value = line.split() - * self.weights[fname.strip()] = float(value) # <<<<<<<<<<<<<< +static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__iadd__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_other) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iadd__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":49 + * + * def __iadd__(SufficientStats self, SufficientStats other): + * self.stats[0] += other.stats[0] # <<<<<<<<<<<<<< + * return self * - * def translate(self, sentence, grammar=None): */ - __pyx_t_14 = __Pyx_PyObject_AsDouble(__pyx_v_value); if (unlikely(__pyx_t_14 == ((double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_2 = PyFloat_FromDouble(__pyx_t_14); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = PyObject_GetAttr(__pyx_v_fname, __pyx_n_s__strip); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_1 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_t_1, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_L16_continue:; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L14_try_end; - __pyx_L7_error:; - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + (__pyx_v_self->stats[0]) += (__pyx_v_other->stats[0]); - /* "_cdec.pyx":85 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":50 + * def __iadd__(SufficientStats self, SufficientStats other): + * self.stats[0] += other.stats[0] + * return self # <<<<<<<<<<<<<< * - * def read_weights(self, weights): - * with open(weights) as fp: # <<<<<<<<<<<<<< - * for line in fp: - * if line.strip().startswith('#'): continue + * def __add__(x, y): */ - /*except:*/ { - __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_2, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_INCREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_15 = PyObject_Call(__pyx_t_3, __pyx_t_11, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_15); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __pyx_t_16 = (!__pyx_t_10); - if (__pyx_t_16) { - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_ErrRestore(__pyx_t_4, __pyx_t_2, __pyx_t_1); - __pyx_t_4 = 0; __pyx_t_2 = 0; __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - goto __pyx_L23; - } - __pyx_L23:; - __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L8_exception_handled; - } - __pyx_L9_except_error:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - goto __pyx_L1_error; - __pyx_L8_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - __pyx_L14_try_end:; - } - } - /*finally:*/ { - if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_46, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - goto __pyx_L24; - __pyx_L3_error:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L1_error; - __pyx_L24:; - } + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); + 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_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_fp); - __Pyx_XDECREF(__pyx_v_line); - __Pyx_XDECREF(__pyx_v_fname); - __Pyx_XDECREF(__pyx_v_value); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_sentence = 0; - PyObject *__pyx_v_grammar = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sentence,&__pyx_n_s__grammar,0}; +static PyObject *__pyx_pw_5_cdec_15SufficientStats_10__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_10__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("translate (wrapper)", 0); - { - PyObject* values[2] = {0,0}; + __Pyx_RefNannySetupContext("__add__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_9__add__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":91 - * self.weights[fname.strip()] = float(value) +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":52 + * return self * - * def translate(self, sentence, grammar=None): # <<<<<<<<<<<<<< - * if isinstance(sentence, unicode): - * inp = sentence.strip().encode('utf8') - */ - values[1] = ((PyObject *)Py_None); + * def __add__(x, y): # <<<<<<<<<<<<<< + * cdef SufficientStats sx = as_stats(x, y) + * cdef SufficientStats sy = as_stats(y, x) + */ + +static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sx = 0; + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sy = 0; + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_result = 0; + 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("__add__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":53 + * + * def __add__(x, y): + * cdef SufficientStats sx = as_stats(x, y) # <<<<<<<<<<<<<< + * cdef SufficientStats sy = as_stats(y, x) + * cdef SufficientStats result = SufficientStats() + */ + __pyx_t_1 = ((PyObject *)__pyx_f_5_cdec_as_stats(__pyx_v_x, __pyx_v_y)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sx = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":54 + * def __add__(x, y): + * cdef SufficientStats sx = as_stats(x, y) + * cdef SufficientStats sy = as_stats(y, x) # <<<<<<<<<<<<<< + * cdef SufficientStats result = SufficientStats() + * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) + */ + __pyx_t_1 = ((PyObject *)__pyx_f_5_cdec_as_stats(__pyx_v_y, __pyx_v_x)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sy = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":55 + * cdef SufficientStats sx = as_stats(x, y) + * cdef SufficientStats sy = as_stats(y, x) + * cdef SufficientStats result = SufficientStats() # <<<<<<<<<<<<<< + * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) + * result.metric = sx.metric + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":56 + * cdef SufficientStats sy = as_stats(y, x) + * cdef SufficientStats result = SufficientStats() + * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) # <<<<<<<<<<<<<< + * result.metric = sx.metric + * return result + */ + __pyx_v_result->stats = new SufficientStats(operator+((__pyx_v_sx->stats[0]), (__pyx_v_sy->stats[0]))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":57 + * cdef SufficientStats result = SufficientStats() + * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) + * result.metric = sx.metric # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_v_result->metric = __pyx_v_sx->metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":58 + * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) + * result.metric = sx.metric + * return result # <<<<<<<<<<<<<< + * + * cdef class CandidateSet: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + 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.SufficientStats.__add__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_sx); + __Pyx_XDECREF((PyObject *)__pyx_v_sy); + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__evaluator,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[1] = {0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; @@ -13719,331 +13415,4591 @@ static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyO kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sentence); + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__evaluator); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; - case 1: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grammar); - if (value) { values[1] = value; kw_args--; } - } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "translate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } + } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { + goto __pyx_L5_argtuple_error; } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); } - __pyx_v_sentence = values[0]; - __pyx_v_grammar = values[1]; + __pyx_v_evaluator = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)values[0]); } 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 = 91; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.CandidateSet.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); - return NULL; + return -1; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_7Decoder_6translate(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_sentence, __pyx_v_grammar); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_evaluator), __pyx_ptype_5_cdec_SegmentEvaluator, 1, "evaluator", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12CandidateSet___cinit__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), __pyx_v_evaluator); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_sentence, PyObject *__pyx_v_grammar) { - PyObject *__pyx_v_inp = NULL; - BasicObserver __pyx_v_observer; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hg = 0; - PyObject *__pyx_r = NULL; +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":65 + * cdef mteval.CandidateSet* cs + * + * def __cinit__(self, SegmentEvaluator evaluator): # <<<<<<<<<<<<<< + * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) + * self.metric = evaluator.metric + */ + +static int __pyx_pf_5_cdec_12CandidateSet___cinit__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator) { + int __pyx_r; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - char *__pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("translate", 0); + __Pyx_RefNannySetupContext("__cinit__", 0); - /* "_cdec.pyx":92 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":66 * - * def translate(self, sentence, grammar=None): - * if isinstance(sentence, unicode): # <<<<<<<<<<<<<< - * inp = sentence.strip().encode('utf8') - * elif isinstance(sentence, str): + * def __cinit__(self, SegmentEvaluator evaluator): + * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) # <<<<<<<<<<<<<< + * self.metric = evaluator.metric + * self.cs = new mteval.CandidateSet() */ - __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { + __pyx_v_self->scorer = new boost::shared_ptr((__pyx_v_evaluator->scorer[0])); - /* "_cdec.pyx":93 - * def translate(self, sentence, grammar=None): - * if isinstance(sentence, unicode): - * inp = sentence.strip().encode('utf8') # <<<<<<<<<<<<<< - * elif isinstance(sentence, str): - * inp = sentence.strip() + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":67 + * def __cinit__(self, SegmentEvaluator evaluator): + * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) + * self.metric = evaluator.metric # <<<<<<<<<<<<<< + * self.cs = new mteval.CandidateSet() + * */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_47), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_inp = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3; - } + __pyx_v_self->metric = __pyx_v_evaluator->metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":68 + * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) + * self.metric = evaluator.metric + * self.cs = new mteval.CandidateSet() # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->cs = new training::CandidateSet(); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":70 + * self.cs = new mteval.CandidateSet() + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.scorer + * del self.cs + */ + +static void __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":71 + * + * def __dealloc__(self): + * del self.scorer # <<<<<<<<<<<<<< + * del self.cs + * + */ + delete __pyx_v_self->scorer; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":72 + * def __dealloc__(self): + * del self.scorer + * del self.cs # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + delete __pyx_v_self->cs; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_5_cdec_12CandidateSet_5__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_12CandidateSet_5__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12CandidateSet_4__len__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":74 + * del self.cs + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.cs.size() + * + */ + +static Py_ssize_t __pyx_pf_5_cdec_12CandidateSet_4__len__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":75 + * + * def __len__(self): + * return self.cs.size() # <<<<<<<<<<<<<< + * + * def __getitem__(self,int k): + */ + __pyx_r = __pyx_v_self->cs->size(); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_k); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_k) { + int __pyx_v_k; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + assert(__pyx_arg_k); { + __pyx_v_k = __Pyx_PyInt_AsInt(__pyx_arg_k); if (unlikely((__pyx_v_k == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.CandidateSet.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_12CandidateSet_6__getitem__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), ((int)__pyx_v_k)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":77 + * return self.cs.size() + * + * def __getitem__(self,int k): # <<<<<<<<<<<<<< + * if not 0 <= k < self.cs.size(): + * raise IndexError('candidate set index out of range') + */ + +static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, int __pyx_v_k) { + struct __pyx_obj_5_cdec_Candidate *__pyx_v_candidate = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__getitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":78 + * + * def __getitem__(self,int k): + * if not 0 <= k < self.cs.size(): # <<<<<<<<<<<<<< + * raise IndexError('candidate set index out of range') + * cdef Candidate candidate = Candidate() + */ + __pyx_t_1 = (0 <= __pyx_v_k); + if (__pyx_t_1) { + __pyx_t_1 = (__pyx_v_k < __pyx_v_self->cs->size()); + } + __pyx_t_2 = (!__pyx_t_1); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":79 + * def __getitem__(self,int k): + * if not 0 <= k < self.cs.size(): + * raise IndexError('candidate set index out of range') # <<<<<<<<<<<<<< + * cdef Candidate candidate = Candidate() + * candidate.candidate = &self.cs[0][k] + */ + __pyx_t_3 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_42), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":80 + * if not 0 <= k < self.cs.size(): + * raise IndexError('candidate set index out of range') + * cdef Candidate candidate = Candidate() # <<<<<<<<<<<<<< + * candidate.candidate = &self.cs[0][k] + * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) + */ + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Candidate)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_candidate = ((struct __pyx_obj_5_cdec_Candidate *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":81 + * raise IndexError('candidate set index out of range') + * cdef Candidate candidate = Candidate() + * candidate.candidate = &self.cs[0][k] # <<<<<<<<<<<<<< + * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) + * return candidate + */ + __pyx_v_candidate->candidate = (&((__pyx_v_self->cs[0])[__pyx_v_k])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 + * cdef Candidate candidate = Candidate() + * candidate.candidate = &self.cs[0][k] + * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) # <<<<<<<<<<<<<< + * return candidate + * + */ + __pyx_v_candidate->score = __pyx_v_self->metric->ComputeScore(((__pyx_v_self->cs[0])[__pyx_v_k]).eval_feats); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":83 + * candidate.candidate = &self.cs[0][k] + * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) + * return candidate # <<<<<<<<<<<<<< + * + * def __iter__(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_candidate)); + __pyx_r = ((PyObject *)__pyx_v_candidate); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec.CandidateSet.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_candidate); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator15(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_9__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_9__iter__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12CandidateSet_8__iter__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":85 + * return candidate + * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(len(self)): + */ + +static PyObject *__pyx_pf_5_cdec_12CandidateSet_8__iter__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__ *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__iter__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_21___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_21___iter__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12CandidateSet_10generator15, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.CandidateSet.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator15(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + Py_ssize_t __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[5]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":87 + * def __iter__(self): + * cdef unsigned i + * for i in range(len(self)): # <<<<<<<<<<<<<< + * yield self[i] + * + */ + __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":88 + * cdef unsigned i + * for i in range(len(self)): + * yield self[i] # <<<<<<<<<<<<<< + * + * def add_kbest(self, Hypergraph hypergraph, unsigned k): + */ + __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 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_generator->resume_label = 1; + return __pyx_r; + __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[5]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph = 0; + unsigned int __pyx_v_k; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__hypergraph,&__pyx_n_s__k,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("add_kbest (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__hypergraph); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, 1); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_kbest") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_hypergraph = ((struct __pyx_obj_5_cdec_Hypergraph *)values[0]); + __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.CandidateSet.add_kbest", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_hypergraph), __pyx_ptype_5_cdec_Hypergraph, 1, "hypergraph", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12CandidateSet_11add_kbest(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), __pyx_v_hypergraph, __pyx_v_k); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":90 + * yield self[i] + * + * def add_kbest(self, Hypergraph hypergraph, unsigned k): # <<<<<<<<<<<<<< + * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) + * + */ + +static PyObject *__pyx_pf_5_cdec_12CandidateSet_11add_kbest(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph, unsigned int __pyx_v_k) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("add_kbest", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":91 + * + * def add_kbest(self, Hypergraph hypergraph, unsigned k): + * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) # <<<<<<<<<<<<<< + * + * cdef class SegmentEvaluator: + */ + __pyx_v_self->cs->AddKBestCandidates((__pyx_v_hypergraph->hg[0]), __pyx_v_k, __pyx_v_self->scorer->get()); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":97 + * cdef mteval.EvaluationMetric* metric + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.scorer + * + */ + +static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":98 + * + * def __dealloc__(self): + * del self.scorer # <<<<<<<<<<<<<< + * + * def evaluate(self, sentence): + */ + delete __pyx_v_self->scorer; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence); /*proto*/ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("evaluate (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self), ((PyObject *)__pyx_v_sentence)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":100 + * del self.scorer + * + * def evaluate(self, sentence): # <<<<<<<<<<<<<< + * cdef vector[WordID] hyp + * cdef SufficientStats sf = SufficientStats() + */ + +static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, PyObject *__pyx_v_sentence) { + std::vector __pyx_v_hyp; + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sf = 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("evaluate", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":102 + * def evaluate(self, sentence): + * cdef vector[WordID] hyp + * cdef SufficientStats sf = SufficientStats() # <<<<<<<<<<<<<< + * sf.metric = self.metric + * sf.stats = new mteval.SufficientStats() + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sf = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":103 + * cdef vector[WordID] hyp + * cdef SufficientStats sf = SufficientStats() + * sf.metric = self.metric # <<<<<<<<<<<<<< + * sf.stats = new mteval.SufficientStats() + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + */ + __pyx_v_sf->metric = __pyx_v_self->metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":104 + * cdef SufficientStats sf = SufficientStats() + * sf.metric = self.metric + * sf.stats = new mteval.SufficientStats() # <<<<<<<<<<<<<< + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + * self.scorer.get().Evaluate(hyp, sf.stats) + */ + __pyx_v_sf->stats = new SufficientStats(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":105 + * sf.metric = self.metric + * sf.stats = new mteval.SufficientStats() + * ConvertSentence(string(as_str(sentence.strip())), &hyp) # <<<<<<<<<<<<<< + * self.scorer.get().Evaluate(hyp, sf.stats) + * return sf + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __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_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_2, NULL)), (&__pyx_v_hyp)); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":106 + * sf.stats = new mteval.SufficientStats() + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + * self.scorer.get().Evaluate(hyp, sf.stats) # <<<<<<<<<<<<<< + * return sf + * + */ + __pyx_v_self->scorer->get()->Evaluate(__pyx_v_hyp, __pyx_v_sf->stats); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":107 + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + * self.scorer.get().Evaluate(hyp, sf.stats) + * return sf # <<<<<<<<<<<<<< + * + * def candidate_set(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_sf)); + __pyx_r = ((PyObject *)__pyx_v_sf); + 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.SegmentEvaluator.evaluate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_sf); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("candidate_set (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":109 + * return sf + * + * def candidate_set(self): # <<<<<<<<<<<<<< + * return CandidateSet(self) + * + */ + +static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_obj_5_cdec_SegmentEvaluator *__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("candidate_set", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":110 + * + * def candidate_set(self): + * return CandidateSet(self) # <<<<<<<<<<<<<< + * + * cdef class Scorer: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_CandidateSet)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__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.SegmentEvaluator.candidate_set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + char *__pyx_v_name; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__name,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__name); + 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 115; __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_name = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 115; __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[5]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.Scorer.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_6Scorer___cinit__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self), __pyx_v_name); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 + * cdef string* name + * + * def __cinit__(self, char* name): # <<<<<<<<<<<<<< + * self.name = new string(name) + * + */ + +static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, char *__pyx_v_name) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":116 + * + * def __cinit__(self, char* name): + * self.name = new string(name) # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->name = new std::string(__pyx_v_name); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_6Scorer_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_6Scorer_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_6Scorer_2__dealloc__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":118 + * self.name = new string(name) + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.name + * + */ + +static void __pyx_pf_5_cdec_6Scorer_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Scorer *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":119 + * + * def __dealloc__(self): + * del self.name # <<<<<<<<<<<<<< + * + * def __call__(self, refs): + */ + delete __pyx_v_self->name; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_refs = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__refs,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__call__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__refs); + 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, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 121; __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_refs = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.Scorer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_6Scorer_4__call__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self), __pyx_v_refs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":121 + * del self.name + * + * def __call__(self, refs): # <<<<<<<<<<<<<< + * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) + * if isinstance(refs, unicode) or isinstance(refs, str): + */ + +static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs) { + EvaluationMetric *__pyx_v_metric; + std::vector > *__pyx_v_refsv; + std::vector *__pyx_v_refv; + PyObject *__pyx_v_ref = NULL; + struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + Py_ssize_t __pyx_t_5; + PyObject *(*__pyx_t_6)(PyObject *); + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__call__", 0); + __Pyx_INCREF(__pyx_v_refs); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":122 + * + * def __call__(self, refs): + * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) # <<<<<<<<<<<<<< + * if isinstance(refs, unicode) or isinstance(refs, str): + * refs = [refs] + */ + __pyx_v_metric = EvaluationMetric::Instance((__pyx_v_self->name[0])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":123 + * def __call__(self, refs): + * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) + * if isinstance(refs, unicode) or isinstance(refs, str): # <<<<<<<<<<<<<< + * refs = [refs] + * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_refs, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!__pyx_t_2) { + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyString_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_refs, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_2; + } + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":124 + * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) + * if isinstance(refs, unicode) or isinstance(refs, str): + * refs = [refs] # <<<<<<<<<<<<<< + * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() + * cdef vector[WordID]* refv + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_refs); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_refs); + __Pyx_GIVEREF(__pyx_v_refs); + __Pyx_DECREF(__pyx_v_refs); + __pyx_v_refs = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":125 + * if isinstance(refs, unicode) or isinstance(refs, str): + * refs = [refs] + * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() # <<<<<<<<<<<<<< + * cdef vector[WordID]* refv + * cdef bytes ref_str + */ + __pyx_v_refsv = new std::vector >(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":128 + * cdef vector[WordID]* refv + * cdef bytes ref_str + * for ref in refs: # <<<<<<<<<<<<<< + * refv = new vector[WordID]() + * ConvertSentence(string(as_str(ref.strip())), refv) + */ + if (PyList_CheckExact(__pyx_v_refs) || PyTuple_CheckExact(__pyx_v_refs)) { + __pyx_t_1 = __pyx_v_refs; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0; + __pyx_t_6 = NULL; + } else { + __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_refs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; + } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; + } else { + __pyx_t_7 = __pyx_t_6(__pyx_t_1); + if (unlikely(!__pyx_t_7)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_7); + } + __Pyx_XDECREF(__pyx_v_ref); + __pyx_v_ref = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":129 + * cdef bytes ref_str + * for ref in refs: + * refv = new vector[WordID]() # <<<<<<<<<<<<<< + * ConvertSentence(string(as_str(ref.strip())), refv) + * refsv.push_back(refv[0]) + */ + __pyx_v_refv = new std::vector(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":130 + * for ref in refs: + * refv = new vector[WordID]() + * ConvertSentence(string(as_str(ref.strip())), refv) # <<<<<<<<<<<<<< + * refsv.push_back(refv[0]) + * del refv + */ + __pyx_t_7 = PyObject_GetAttr(__pyx_v_ref, __pyx_n_s__strip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_8, NULL)), __pyx_v_refv); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":131 + * refv = new vector[WordID]() + * ConvertSentence(string(as_str(ref.strip())), refv) + * refsv.push_back(refv[0]) # <<<<<<<<<<<<<< + * del refv + * cdef unsigned i + */ + __pyx_v_refsv->push_back((__pyx_v_refv[0])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":132 + * ConvertSentence(string(as_str(ref.strip())), refv) + * refsv.push_back(refv[0]) + * del refv # <<<<<<<<<<<<<< + * cdef unsigned i + * cdef SegmentEvaluator evaluator = SegmentEvaluator() + */ + delete __pyx_v_refv; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":134 + * del refv + * cdef unsigned i + * cdef SegmentEvaluator evaluator = SegmentEvaluator() # <<<<<<<<<<<<<< + * evaluator.metric = metric + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SegmentEvaluator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_evaluator = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":135 + * cdef unsigned i + * cdef SegmentEvaluator evaluator = SegmentEvaluator() + * evaluator.metric = metric # <<<<<<<<<<<<<< + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + * del refsv # in theory should not delete but store in SegmentEvaluator + */ + __pyx_v_evaluator->metric = __pyx_v_metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":136 + * cdef SegmentEvaluator evaluator = SegmentEvaluator() + * evaluator.metric = metric + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) # <<<<<<<<<<<<<< + * del refsv # in theory should not delete but store in SegmentEvaluator + * return evaluator + */ + __pyx_v_evaluator->scorer = new boost::shared_ptr(__pyx_v_metric->CreateSegmentEvaluator((__pyx_v_refsv[0]))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":137 + * evaluator.metric = metric + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + * del refsv # in theory should not delete but store in SegmentEvaluator # <<<<<<<<<<<<<< + * return evaluator + * + */ + delete __pyx_v_refsv; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":138 + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + * del refsv # in theory should not delete but store in SegmentEvaluator + * return evaluator # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_evaluator)); + __pyx_r = ((PyObject *)__pyx_v_evaluator); + 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_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_cdec.Scorer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_ref); + __Pyx_XDECREF((PyObject *)__pyx_v_evaluator); + __Pyx_XDECREF(__pyx_v_refs); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_6Scorer_7__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_6Scorer_7__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_6Scorer_6__str__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":140 + * return evaluator + * + * def __str__(self): # <<<<<<<<<<<<<< + * return self.name.c_str() + * + */ + +static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer *__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__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":141 + * + * def __str__(self): + * return self.name.c_str() # <<<<<<<<<<<<<< + * + * BLEU = Scorer('IBM_BLEU') + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(__pyx_v_self->name->c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 141; __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.Scorer.__str__", __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_4generator16(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_3_make_config(PyObject *__pyx_self, PyObject *__pyx_v_config); /*proto*/ +static PyMethodDef __pyx_mdef_5_cdec_3_make_config = {__Pyx_NAMESTR("_make_config"), (PyCFunction)__pyx_pw_5_cdec_3_make_config, METH_O, __Pyx_DOCSTR(0)}; +static PyObject *__pyx_pw_5_cdec_3_make_config(PyObject *__pyx_self, PyObject *__pyx_v_config) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_make_config (wrapper)", 0); + __pyx_self = __pyx_self; + __pyx_r = __pyx_pf_5_cdec_2_make_config(__pyx_self, ((PyObject *)__pyx_v_config)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":28 + * class ParseFailed(Exception): pass + * + * def _make_config(config): # <<<<<<<<<<<<<< + * for key, value in config.items(): + * if isinstance(value, dict): + */ + +static PyObject *__pyx_pf_5_cdec_2_make_config(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_config) { + struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_make_config", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *)__pyx_ptype_5_cdec___pyx_scope_struct_22__make_config->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_22__make_config, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_config = __pyx_v_config; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_config); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_config); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_4generator16, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec._make_config", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5_cdec_4generator16(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *(*__pyx_t_4)(PyObject *); + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *(*__pyx_t_8)(PyObject *); + int __pyx_t_9; + Py_ssize_t __pyx_t_10; + PyObject *(*__pyx_t_11)(PyObject *); + PyObject *__pyx_t_12 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L13_resume_from_yield; + case 2: goto __pyx_L16_resume_from_yield; + case 3: goto __pyx_L17_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 = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "_cdec.pyx":29 + * + * def _make_config(config): + * for key, value in config.items(): # <<<<<<<<<<<<<< + * if isinstance(value, dict): + * for name, info in value.items(): + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_config, __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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 = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; + } else { + __pyx_t_2 = __pyx_t_4(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + if (likely(PyTuple_CheckExact(sequence))) { + 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 = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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 = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_5 = PyList_GET_ITEM(sequence, 0); + __pyx_t_6 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_5 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L7_unpacking_done; + __pyx_L6_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L7_unpacking_done:; + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_key); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_key); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_cur_scope->__pyx_v_key = __pyx_t_5; + __pyx_t_5 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_value); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_value); + __Pyx_GIVEREF(__pyx_t_6); + __pyx_cur_scope->__pyx_v_value = __pyx_t_6; + __pyx_t_6 = 0; + + /* "_cdec.pyx":30 + * def _make_config(config): + * for key, value in config.items(): + * if isinstance(value, dict): # <<<<<<<<<<<<<< + * for name, info in value.items(): + * yield key, '%s %s' % (name, info) + */ + __pyx_t_2 = ((PyObject *)((PyObject*)(&PyDict_Type))); + __Pyx_INCREF(__pyx_t_2); + __pyx_t_9 = __Pyx_TypeCheck(__pyx_cur_scope->__pyx_v_value, __pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_9) { + + /* "_cdec.pyx":31 + * for key, value in config.items(): + * if isinstance(value, dict): + * for name, info in value.items(): # <<<<<<<<<<<<<< + * yield key, '%s %s' % (name, info) + * elif isinstance(value, list): + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_value, __pyx_n_s__items); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyList_CheckExact(__pyx_t_6) || PyTuple_CheckExact(__pyx_t_6)) { + __pyx_t_2 = __pyx_t_6; __Pyx_INCREF(__pyx_t_2); __pyx_t_10 = 0; + __pyx_t_11 = NULL; + } else { + __pyx_t_10 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_11 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + for (;;) { + if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; + } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; + } else { + __pyx_t_6 = __pyx_t_11(__pyx_t_2); + if (unlikely(!__pyx_t_6)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_6); + } + if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) { + PyObject* sequence = __pyx_t_6; + if (likely(PyTuple_CheckExact(sequence))) { + 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 = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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 = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_5 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_12 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_12)->tp_iternext; + index = 0; __pyx_t_5 = __pyx_t_8(__pyx_t_12); if (unlikely(!__pyx_t_5)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + index = 1; __pyx_t_7 = __pyx_t_8(__pyx_t_12); if (unlikely(!__pyx_t_7)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_12), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L12_unpacking_done; + __pyx_L11_unpacking_failed:; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L12_unpacking_done:; + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_name); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_name); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_cur_scope->__pyx_v_name = __pyx_t_5; + __pyx_t_5 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_info); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_info); + __Pyx_GIVEREF(__pyx_t_7); + __pyx_cur_scope->__pyx_v_info = __pyx_t_7; + __pyx_t_7 = 0; + + /* "_cdec.pyx":32 + * if isinstance(value, dict): + * for name, info in value.items(): + * yield key, '%s %s' % (name, info) # <<<<<<<<<<<<<< + * elif isinstance(value, list): + * for name in value: + */ + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_name); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_cur_scope->__pyx_v_name); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_name); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_info); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_cur_scope->__pyx_v_info); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_info); + __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_43), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_7)); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_cur_scope->__pyx_v_key); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_t_7)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_7)); + __pyx_t_7 = 0; + __pyx_r = ((PyObject *)__pyx_t_6); + __pyx_t_6 = 0; + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __Pyx_XGIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_3 = __pyx_t_4; + __pyx_cur_scope->__pyx_t_4 = __pyx_t_10; + __pyx_cur_scope->__pyx_t_5 = __pyx_t_11; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L13_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_t_2); + __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_3; + __pyx_t_10 = __pyx_cur_scope->__pyx_t_4; + __pyx_t_11 = __pyx_cur_scope->__pyx_t_5; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L8; + } + + /* "_cdec.pyx":33 + * for name, info in value.items(): + * yield key, '%s %s' % (name, info) + * elif isinstance(value, list): # <<<<<<<<<<<<<< + * for name in value: + * yield key, name + */ + __pyx_t_2 = ((PyObject *)((PyObject*)(&PyList_Type))); + __Pyx_INCREF(__pyx_t_2); + __pyx_t_9 = __Pyx_TypeCheck(__pyx_cur_scope->__pyx_v_value, __pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_9) { + + /* "_cdec.pyx":34 + * yield key, '%s %s' % (name, info) + * elif isinstance(value, list): + * for name in value: # <<<<<<<<<<<<<< + * yield key, name + * else: + */ + if (PyList_CheckExact(__pyx_cur_scope->__pyx_v_value) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_value)) { + __pyx_t_2 = __pyx_cur_scope->__pyx_v_value; __Pyx_INCREF(__pyx_t_2); __pyx_t_10 = 0; + __pyx_t_11 = NULL; + } else { + __pyx_t_10 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_value); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_11 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; + } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; + } else { + __pyx_t_6 = __pyx_t_11(__pyx_t_2); + if (unlikely(!__pyx_t_6)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_6); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_name); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_name); + __Pyx_GIVEREF(__pyx_t_6); + __pyx_cur_scope->__pyx_v_name = __pyx_t_6; + __pyx_t_6 = 0; + + /* "_cdec.pyx":35 + * elif isinstance(value, list): + * for name in value: + * yield key, name # <<<<<<<<<<<<<< + * else: + * yield key, bytes(value) + */ + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_cur_scope->__pyx_v_key); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_name); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_cur_scope->__pyx_v_name); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_name); + __pyx_r = ((PyObject *)__pyx_t_6); + __pyx_t_6 = 0; + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __Pyx_XGIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_3 = __pyx_t_4; + __pyx_cur_scope->__pyx_t_4 = __pyx_t_10; + __pyx_cur_scope->__pyx_t_5 = __pyx_t_11; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 2; + return __pyx_r; + __pyx_L16_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_t_2); + __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_3; + __pyx_t_10 = __pyx_cur_scope->__pyx_t_4; + __pyx_t_11 = __pyx_cur_scope->__pyx_t_5; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L8; + } + /*else*/ { + + /* "_cdec.pyx":37 + * yield key, name + * else: + * yield key, bytes(value) # <<<<<<<<<<<<<< + * + * cdef class Decoder: + */ + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_value); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_value); + __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyBytes_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_key); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_key); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + __pyx_t_6 = 0; + __pyx_r = ((PyObject *)__pyx_t_2); + __pyx_t_2 = 0; + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_3 = __pyx_t_4; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 3; + return __pyx_r; + __pyx_L17_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_3; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L8:; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("_make_config", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_config_str = 0; + PyObject *__pyx_v_config = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__config_str,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + __pyx_v_config = PyDict_New(); if (unlikely(!__pyx_v_config)) return -1; + __Pyx_GOTREF(__pyx_v_config); + { + PyObject* values[1] = {0}; + + /* "_cdec.pyx":43 + * cdef DenseVector weights + * + * def __cinit__(self, config_str=None, **config): # <<<<<<<<<<<<<< + * """ Configuration can be given as a string: + * Decoder('formalism = scfg') + */ + values[0] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__config_str); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_config, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + 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; + } + } + __pyx_v_config_str = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_CLEAR(__pyx_v_config); + __Pyx_AddTraceback("_cdec.Decoder.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_7Decoder___cinit__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_config_str, __pyx_v_config); + __Pyx_XDECREF(__pyx_v_config); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_5_cdec_7Decoder_9__cinit___2generator20(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* "_cdec.pyx":54 + * 'csplit', 'tagger', 'lexalign'): + * raise InvalidConfig('formalism "%s" unknown' % formalism) + * config_str = '\n'.join('%s = %s' % kv for kv in _make_config(config)) # <<<<<<<<<<<<<< + * cdef istringstream* config_stream = new istringstream(config_str) + * self.dec = new decoder.Decoder(config_stream) + */ + +static PyObject *__pyx_pf_5_cdec_7Decoder_9__cinit___genexpr(PyObject *__pyx_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_24_genexpr *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("genexpr", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_24_genexpr *)__pyx_ptype_5_cdec___pyx_scope_struct_24_genexpr->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_24_genexpr, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_23___cinit__ *) __pyx_self; + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Decoder_9__cinit___2generator20, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Decoder.__cinit__.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5_cdec_7Decoder_9__cinit___2generator20(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_24_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_24_genexpr *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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 = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___make_config); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_config)) { __Pyx_RaiseClosureNameError("config"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __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 = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_config); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_config); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_config); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; + } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; + } else { + __pyx_t_3 = __pyx_t_5(__pyx_t_2); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_kv); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_kv); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_kv = __pyx_t_3; + __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_44), __pyx_cur_scope->__pyx_v_kv); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_r = ((PyObject *)__pyx_t_3); + __pyx_t_3 = 0; + __Pyx_XGIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_4; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_5; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_2); + __pyx_t_4 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_5 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* "_cdec.pyx":43 + * cdef DenseVector weights + * + * def __cinit__(self, config_str=None, **config): # <<<<<<<<<<<<<< + * """ Configuration can be given as a string: + * Decoder('formalism = scfg') + */ + +static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_config_str, PyObject *__pyx_v_config) { + struct __pyx_obj_5_cdec___pyx_scope_struct_23___cinit__ *__pyx_cur_scope; + PyObject *__pyx_v_formalism = NULL; + std::istringstream *__pyx_v_config_stream; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + char *__pyx_t_7; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_23___cinit__ *)__pyx_ptype_5_cdec___pyx_scope_struct_23___cinit__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_23___cinit__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return -1; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_config = __pyx_v_config; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_config); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_config); + __Pyx_INCREF(__pyx_v_config_str); + + /* "_cdec.pyx":49 + * Decoder(formalism='scfg') + * """ + * if config_str is None: # <<<<<<<<<<<<<< + * formalism = config.get('formalism', None) + * if formalism not in ('scfg', 'fst', 'lextrans', 'pb', + */ + __pyx_t_1 = (__pyx_v_config_str == Py_None); + if (__pyx_t_1) { + + /* "_cdec.pyx":50 + * """ + * if config_str is None: + * formalism = config.get('formalism', None) # <<<<<<<<<<<<<< + * if formalism not in ('scfg', 'fst', 'lextrans', 'pb', + * 'csplit', 'tagger', 'lexalign'): + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_config, __pyx_n_s__get); 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_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_45), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_formalism = __pyx_t_3; + __pyx_t_3 = 0; + + /* "_cdec.pyx":51 + * if config_str is None: + * formalism = config.get('formalism', None) + * if formalism not in ('scfg', 'fst', 'lextrans', 'pb', # <<<<<<<<<<<<<< + * 'csplit', 'tagger', 'lexalign'): + * raise InvalidConfig('formalism "%s" unknown' % formalism) + */ + __Pyx_INCREF(__pyx_v_formalism); + __pyx_t_3 = __pyx_v_formalism; + __pyx_t_1 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__scfg), Py_NE); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (((int)__pyx_t_1)) { + __pyx_t_4 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__fst), Py_NE); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = ((int)__pyx_t_4); + } else { + __pyx_t_5 = ((int)__pyx_t_1); + } + if (__pyx_t_5) { + __pyx_t_1 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__lextrans), Py_NE); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = ((int)__pyx_t_1); + } else { + __pyx_t_4 = __pyx_t_5; + } + if (__pyx_t_4) { + __pyx_t_5 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__pb), Py_NE); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = ((int)__pyx_t_5); + } else { + __pyx_t_1 = __pyx_t_4; + } + if (__pyx_t_1) { + __pyx_t_4 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__csplit), Py_NE); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = ((int)__pyx_t_4); + } else { + __pyx_t_5 = __pyx_t_1; + } + if (__pyx_t_5) { + __pyx_t_1 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__tagger), Py_NE); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = ((int)__pyx_t_1); + } else { + __pyx_t_4 = __pyx_t_5; + } + if (__pyx_t_4) { + __pyx_t_5 = __Pyx_PyString_Equals(__pyx_t_3, ((PyObject *)__pyx_n_s__lexalign), Py_NE); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = ((int)__pyx_t_5); + } else { + __pyx_t_1 = __pyx_t_4; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_4 = __pyx_t_1; + if (__pyx_t_4) { + + /* "_cdec.pyx":53 + * if formalism not in ('scfg', 'fst', 'lextrans', 'pb', + * 'csplit', 'tagger', 'lexalign'): + * raise InvalidConfig('formalism "%s" unknown' % formalism) # <<<<<<<<<<<<<< + * config_str = '\n'.join('%s = %s' % kv for kv in _make_config(config)) + * cdef istringstream* config_stream = new istringstream(config_str) + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__InvalidConfig); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_46), __pyx_v_formalism); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 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 = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L4; + } + __pyx_L4:; + + /* "_cdec.pyx":54 + * 'csplit', 'tagger', 'lexalign'): + * raise InvalidConfig('formalism "%s" unknown' % formalism) + * config_str = '\n'.join('%s = %s' % kv for kv in _make_config(config)) # <<<<<<<<<<<<<< + * cdef istringstream* config_stream = new istringstream(config_str) + * self.dec = new decoder.Decoder(config_stream) + */ + __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_39), __pyx_n_s__join); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = __pyx_pf_5_cdec_7Decoder_9__cinit___genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + __pyx_t_6 = 0; + __pyx_t_6 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_v_config_str); + __pyx_v_config_str = __pyx_t_6; + __pyx_t_6 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "_cdec.pyx":55 + * raise InvalidConfig('formalism "%s" unknown' % formalism) + * config_str = '\n'.join('%s = %s' % kv for kv in _make_config(config)) + * cdef istringstream* config_stream = new istringstream(config_str) # <<<<<<<<<<<<<< + * self.dec = new decoder.Decoder(config_stream) + * del config_stream + */ + __pyx_t_7 = PyBytes_AsString(__pyx_v_config_str); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_config_stream = new std::istringstream(__pyx_t_7); + + /* "_cdec.pyx":56 + * config_str = '\n'.join('%s = %s' % kv for kv in _make_config(config)) + * cdef istringstream* config_stream = new istringstream(config_str) + * self.dec = new decoder.Decoder(config_stream) # <<<<<<<<<<<<<< + * del config_stream + * self.weights = DenseVector() + */ + __pyx_v_self->dec = new Decoder(__pyx_v_config_stream); + + /* "_cdec.pyx":57 + * cdef istringstream* config_stream = new istringstream(config_str) + * self.dec = new decoder.Decoder(config_stream) + * del config_stream # <<<<<<<<<<<<<< + * self.weights = DenseVector() + * self.weights.vector = &self.dec.CurrentWeightVector() + */ + delete __pyx_v_config_stream; + + /* "_cdec.pyx":58 + * self.dec = new decoder.Decoder(config_stream) + * del config_stream + * self.weights = DenseVector() # <<<<<<<<<<<<<< + * self.weights.vector = &self.dec.CurrentWeightVector() + * + */ + __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)), ((PyObject *)__pyx_empty_tuple), NULL); 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_GIVEREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_v_self->weights); + __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); + __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)__pyx_t_6); + __pyx_t_6 = 0; + + /* "_cdec.pyx":59 + * del config_stream + * self.weights = DenseVector() + * self.weights.vector = &self.dec.CurrentWeightVector() # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->weights->vector = (&__pyx_v_self->dec->CurrentWeightVector()); + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_cdec.Decoder.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_formalism); + __Pyx_XDECREF(__pyx_v_config_str); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_7Decoder_2__dealloc__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "_cdec.pyx":61 + * self.weights.vector = &self.dec.CurrentWeightVector() + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.dec + * + */ + +static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "_cdec.pyx":62 + * + * def __dealloc__(self): + * del self.dec # <<<<<<<<<<<<<< + * + * property weights: + */ + delete __pyx_v_self->dec; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights___get__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":65 + * + * property weights: + * def __get__(self): # <<<<<<<<<<<<<< + * return self.weights + * + */ + +static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + + /* "_cdec.pyx":66 + * property weights: + * def __get__(self): + * return self.weights # <<<<<<<<<<<<<< + * + * def __set__(self, weights): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->weights)); + __pyx_r = ((PyObject *)__pyx_v_self->weights); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_weights); /*proto*/ +static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_weights) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_2__set__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_weights)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":68 + * return self.weights + * + * def __set__(self, weights): # <<<<<<<<<<<<<< + * if isinstance(weights, DenseVector): + * self.weights.vector[0] = ( weights).vector[0] + */ + +static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_weights) { + PyObject *__pyx_v_fname = NULL; + PyObject *__pyx_v_fval = NULL; + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *(*__pyx_t_9)(PyObject *); + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); + + /* "_cdec.pyx":69 + * + * def __set__(self, weights): + * if isinstance(weights, DenseVector): # <<<<<<<<<<<<<< + * self.weights.vector[0] = ( weights).vector[0] + * elif isinstance(weights, SparseVector): + */ + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":70 + * def __set__(self, weights): + * if isinstance(weights, DenseVector): + * self.weights.vector[0] = ( weights).vector[0] # <<<<<<<<<<<<<< + * elif isinstance(weights, SparseVector): + * self.weights.vector.clear() + */ + (__pyx_v_self->weights->vector[0]) = (((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_weights)->vector[0]); + goto __pyx_L3; + } + + /* "_cdec.pyx":71 + * if isinstance(weights, DenseVector): + * self.weights.vector[0] = ( weights).vector[0] + * elif isinstance(weights, SparseVector): # <<<<<<<<<<<<<< + * self.weights.vector.clear() + * (( weights).vector[0]).init_vector(self.weights.vector) + */ + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":72 + * self.weights.vector[0] = ( weights).vector[0] + * elif isinstance(weights, SparseVector): + * self.weights.vector.clear() # <<<<<<<<<<<<<< + * (( weights).vector[0]).init_vector(self.weights.vector) + * elif isinstance(weights, dict): + */ + __pyx_v_self->weights->vector->clear(); + + /* "_cdec.pyx":73 + * elif isinstance(weights, SparseVector): + * self.weights.vector.clear() + * (( weights).vector[0]).init_vector(self.weights.vector) # <<<<<<<<<<<<<< + * elif isinstance(weights, dict): + * for fname, fval in weights.items(): + */ + (((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_weights)->vector[0]).init_vector(__pyx_v_self->weights->vector); + goto __pyx_L3; + } + + /* "_cdec.pyx":74 + * self.weights.vector.clear() + * (( weights).vector[0]).init_vector(self.weights.vector) + * elif isinstance(weights, dict): # <<<<<<<<<<<<<< + * for fname, fval in weights.items(): + * self.weights[fname] = fval + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyDict_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_weights, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":75 + * (( weights).vector[0]).init_vector(self.weights.vector) + * elif isinstance(weights, dict): + * for fname, fval in weights.items(): # <<<<<<<<<<<<<< + * self.weights[fname] = fval + * else: + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_weights, __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; + } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; + } else { + __pyx_t_3 = __pyx_t_5(__pyx_t_1); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { + PyObject* sequence = __pyx_t_3; + if (likely(PyTuple_CheckExact(sequence))) { + 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 = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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 = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_6 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_8 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; + index = 0; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L7_unpacking_done; + __pyx_L6_unpacking_failed:; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L7_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_fname); + __pyx_v_fname = __pyx_t_6; + __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_v_fval); + __pyx_v_fval = __pyx_t_7; + __pyx_t_7 = 0; + + /* "_cdec.pyx":76 + * elif isinstance(weights, dict): + * for fname, fval in weights.items(): + * self.weights[fname] = fval # <<<<<<<<<<<<<< + * else: + * raise TypeError('cannot initialize weights with %s' % type(weights)) + */ + if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_v_fname, __pyx_v_fval) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "_cdec.pyx":78 + * self.weights[fname] = fval + * else: + * raise TypeError('cannot initialize weights with %s' % type(weights)) # <<<<<<<<<<<<<< + * + * property formalism: + */ + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_47), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_cdec.Decoder.weights.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_fname); + __Pyx_XDECREF(__pyx_v_fval); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Decoder_9formalism_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Decoder_9formalism_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_9formalism___get__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":81 + * + * property formalism: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef variables_map* conf = &self.dec.GetConf() + * return conf[0]['formalism'].as_str().c_str() + */ + +static PyObject *__pyx_pf_5_cdec_7Decoder_9formalism___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { + const boost::program_options::variables_map *__pyx_v_conf; + 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("__get__", 0); + + /* "_cdec.pyx":82 + * property formalism: + * def __get__(self): + * cdef variables_map* conf = &self.dec.GetConf() # <<<<<<<<<<<<<< + * return conf[0]['formalism'].as_str().c_str() + * + */ + __pyx_v_conf = (&__pyx_v_self->dec->GetConf()); + + /* "_cdec.pyx":83 + * def __get__(self): + * cdef variables_map* conf = &self.dec.GetConf() + * return conf[0]['formalism'].as_str().c_str() # <<<<<<<<<<<<<< + * + * def read_weights(self, weights): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(((__pyx_v_conf[0])[__pyx_k__formalism]).as().c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __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.Decoder.formalism.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_weights); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_weights) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_weights (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_4read_weights(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_weights)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":85 + * return conf[0]['formalism'].as_str().c_str() + * + * def read_weights(self, weights): # <<<<<<<<<<<<<< + * with open(weights) as fp: + * for line in fp: + */ + +static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_weights) { + PyObject *__pyx_v_fp = NULL; + PyObject *__pyx_v_line = NULL; + PyObject *__pyx_v_fname = NULL; + PyObject *__pyx_v_value = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *(*__pyx_t_13)(PyObject *); + double __pyx_t_14; + PyObject *__pyx_t_15 = NULL; + int __pyx_t_16; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_weights", 0); + + /* "_cdec.pyx":86 + * + * def read_weights(self, weights): + * with open(weights) as fp: # <<<<<<<<<<<<<< + * for line in fp: + * if line.strip().startswith('#'): continue + */ + /*with:*/ { + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_weights); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_weights); + __Pyx_GIVEREF(__pyx_v_weights); + __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 = 86; __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 = 86; __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 = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_fp = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_cdec.pyx":87 + * def read_weights(self, weights): + * with open(weights) as fp: + * for line in fp: # <<<<<<<<<<<<<< + * if line.strip().startswith('#'): continue + * fname, value = line.split() + */ + if (PyList_CheckExact(__pyx_v_fp) || PyTuple_CheckExact(__pyx_v_fp)) { + __pyx_t_4 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else { + __pyx_t_2 = __pyx_t_9(__pyx_t_4); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF(__pyx_v_line); + __pyx_v_line = __pyx_t_2; + __pyx_t_2 = 0; + + /* "_cdec.pyx":88 + * with open(weights) as fp: + * for line in fp: + * if line.strip().startswith('#'): continue # <<<<<<<<<<<<<< + * fname, value = line.split() + * self.weights[fname.strip()] = float(value) + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__strip); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__startswith); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_49), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_10) { + goto __pyx_L16_continue; + goto __pyx_L18; + } + __pyx_L18:; + + /* "_cdec.pyx":89 + * for line in fp: + * if line.strip().startswith('#'): continue + * 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 = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __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 = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + if (likely(PyTuple_CheckExact(sequence))) { + 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 = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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 = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_11 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_12 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_13 = Py_TYPE(__pyx_t_12)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_1)) goto __pyx_L19_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_11 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_11)) goto __pyx_L19_unpacking_failed; + __Pyx_GOTREF(__pyx_t_11); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L20_unpacking_done; + __pyx_L19_unpacking_failed:; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_L20_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_fname); + __pyx_v_fname = __pyx_t_1; + __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_v_value); + __pyx_v_value = __pyx_t_11; + __pyx_t_11 = 0; + + /* "_cdec.pyx":90 + * if line.strip().startswith('#'): continue + * fname, value = line.split() + * self.weights[fname.strip()] = float(value) # <<<<<<<<<<<<<< + * + * def translate(self, sentence, grammar=None): + */ + __pyx_t_14 = __Pyx_PyObject_AsDouble(__pyx_v_value); if (unlikely(__pyx_t_14 == ((double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyFloat_FromDouble(__pyx_t_14); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_11 = PyObject_GetAttr(__pyx_v_fname, __pyx_n_s__strip); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_1 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_t_1, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_L16_continue:; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_cdec.pyx":86 + * + * def read_weights(self, weights): + * with open(weights) as fp: # <<<<<<<<<<<<<< + * for line in fp: + * if line.strip().startswith('#'): continue + */ + /*except:*/ { + __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_2, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_INCREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_15 = PyObject_Call(__pyx_t_3, __pyx_t_11, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_15); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_16 = (!__pyx_t_10); + if (__pyx_t_16) { + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_ErrRestore(__pyx_t_4, __pyx_t_2, __pyx_t_1); + __pyx_t_4 = 0; __pyx_t_2 = 0; __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L23; + } + __pyx_L23:; + __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_50, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L24; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L24:; + } + + __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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_fp); + __Pyx_XDECREF(__pyx_v_line); + __Pyx_XDECREF(__pyx_v_fname); + __Pyx_XDECREF(__pyx_v_value); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_sentence = 0; + PyObject *__pyx_v_grammar = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sentence,&__pyx_n_s__grammar,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("translate (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + + /* "_cdec.pyx":92 + * self.weights[fname.strip()] = float(value) + * + * def translate(self, sentence, grammar=None): # <<<<<<<<<<<<<< + * cdef bytes input_str + * if isinstance(sentence, unicode) or isinstance(sentence, str): + */ + values[1] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sentence); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grammar); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "translate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_sentence = values[0]; + __pyx_v_grammar = values[1]; + } + 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 = 92; __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:; + __pyx_r = __pyx_pf_5_cdec_7Decoder_6translate(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_sentence, __pyx_v_grammar); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_sentence, PyObject *__pyx_v_grammar) { + PyObject *__pyx_v_input_str = 0; + BasicObserver __pyx_v_observer; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hg = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + char *__pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("translate", 0); + + /* "_cdec.pyx":94 + * def translate(self, sentence, grammar=None): + * cdef bytes input_str + * if isinstance(sentence, unicode) or isinstance(sentence, str): # <<<<<<<<<<<<<< + * input_str = as_str(sentence.strip()) + * elif isinstance(sentence, Lattice): + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!__pyx_t_2) { + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyString_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_2; + } + if (__pyx_t_4) { + + /* "_cdec.pyx":95 + * cdef bytes input_str + * if isinstance(sentence, unicode) or isinstance(sentence, str): + * input_str = as_str(sentence.strip()) # <<<<<<<<<<<<<< + * elif isinstance(sentence, Lattice): + * input_str = str(sentence) # PLF format + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyBytes_FromString(__pyx_f_5_cdec_as_str(__pyx_t_5, NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_input_str = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L3; + } + + /* "_cdec.pyx":96 + * if isinstance(sentence, unicode) or isinstance(sentence, str): + * input_str = as_str(sentence.strip()) + * elif isinstance(sentence, Lattice): # <<<<<<<<<<<<<< + * input_str = str(sentence) # PLF format + * else: + */ + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_4 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_4) { + + /* "_cdec.pyx":97 + * input_str = as_str(sentence.strip()) + * elif isinstance(sentence, Lattice): + * input_str = str(sentence) # PLF format # <<<<<<<<<<<<<< + * else: + * raise TypeError('Cannot translate input type %s' % type(sentence)) + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_sentence); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_sentence); + __Pyx_GIVEREF(__pyx_v_sentence); + __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_input_str = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "_cdec.pyx":99 + * input_str = str(sentence) # PLF format + * else: + * raise TypeError('Cannot translate input type %s' % type(sentence)) # <<<<<<<<<<<<<< + * if grammar: + * if isinstance(grammar, str) or isinstance(grammar, unicode): + */ + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_51), ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_5)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; + + /* "_cdec.pyx":100 + * else: + * raise TypeError('Cannot translate input type %s' % type(sentence)) + * if grammar: # <<<<<<<<<<<<<< + * if isinstance(grammar, str) or isinstance(grammar, unicode): + * self.dec.AddSupplementalGrammarFromString(string(as_str(grammar))) + */ + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_grammar); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_4) { + + /* "_cdec.pyx":101 + * raise TypeError('Cannot translate input type %s' % type(sentence)) + * if grammar: + * if isinstance(grammar, str) or isinstance(grammar, unicode): # <<<<<<<<<<<<<< + * self.dec.AddSupplementalGrammarFromString(string(as_str(grammar))) + * else: + */ + __pyx_t_5 = ((PyObject *)((PyObject*)(&PyString_Type))); + __Pyx_INCREF(__pyx_t_5); + __pyx_t_4 = __Pyx_TypeCheck(__pyx_v_grammar, __pyx_t_5); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (!__pyx_t_4) { + __pyx_t_5 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_5); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_grammar, __pyx_t_5); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_4; + } + if (__pyx_t_3) { + + /* "_cdec.pyx":102 + * if grammar: + * if isinstance(grammar, str) or isinstance(grammar, unicode): + * self.dec.AddSupplementalGrammarFromString(string(as_str(grammar))) # <<<<<<<<<<<<<< + * else: + * self.dec.AddSupplementalGrammar(TextGrammar(grammar).grammar[0]) + */ + __pyx_v_self->dec->AddSupplementalGrammarFromString(std::string(__pyx_f_5_cdec_as_str(__pyx_v_grammar, NULL))); + goto __pyx_L5; + } + /*else*/ { + + /* "_cdec.pyx":104 + * self.dec.AddSupplementalGrammarFromString(string(as_str(grammar))) + * else: + * self.dec.AddSupplementalGrammar(TextGrammar(grammar).grammar[0]) # <<<<<<<<<<<<<< + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + * self.dec.Decode(string(input_str), &observer) + */ + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_grammar); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_grammar); + __Pyx_GIVEREF(__pyx_v_grammar); + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_TextGrammar)), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_v_self->dec->AddSupplementalGrammar((((struct __pyx_obj_5_cdec_TextGrammar *)__pyx_t_1)->__pyx_base.grammar[0])); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __pyx_L5:; + goto __pyx_L4; + } + __pyx_L4:; + + /* "_cdec.pyx":105 + * else: + * self.dec.AddSupplementalGrammar(TextGrammar(grammar).grammar[0]) + * cdef decoder.BasicObserver observer = decoder.BasicObserver() # <<<<<<<<<<<<<< + * self.dec.Decode(string(input_str), &observer) + * if observer.hypergraph == NULL: + */ + __pyx_v_observer = BasicObserver(); + + /* "_cdec.pyx":106 + * self.dec.AddSupplementalGrammar(TextGrammar(grammar).grammar[0]) + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + * self.dec.Decode(string(input_str), &observer) # <<<<<<<<<<<<<< + * if observer.hypergraph == NULL: + * raise ParseFailed() + */ + __pyx_t_6 = PyBytes_AsString(((PyObject *)__pyx_v_input_str)); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->dec->Decode(std::string(__pyx_t_6), (&__pyx_v_observer)); + + /* "_cdec.pyx":107 + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + * self.dec.Decode(string(input_str), &observer) + * if observer.hypergraph == NULL: # <<<<<<<<<<<<<< + * raise ParseFailed() + * cdef Hypergraph hg = Hypergraph() + */ + __pyx_t_3 = (__pyx_v_observer.hypergraph == NULL); + if (__pyx_t_3) { + + /* "_cdec.pyx":108 + * self.dec.Decode(string(input_str), &observer) + * if observer.hypergraph == NULL: + * raise ParseFailed() # <<<<<<<<<<<<<< + * cdef Hypergraph hg = Hypergraph() + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__ParseFailed); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L6; + } + __pyx_L6:; + + /* "_cdec.pyx":109 + * if observer.hypergraph == NULL: + * raise ParseFailed() + * cdef Hypergraph hg = Hypergraph() # <<<<<<<<<<<<<< + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) + * return hg + */ + __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Hypergraph)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_v_hg = ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_t_5); + __pyx_t_5 = 0; + + /* "_cdec.pyx":110 + * raise ParseFailed() + * cdef Hypergraph hg = Hypergraph() + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) # <<<<<<<<<<<<<< + * return hg + */ + __pyx_v_hg->hg = new Hypergraph((__pyx_v_observer.hypergraph[0])); + + /* "_cdec.pyx":111 + * cdef Hypergraph hg = Hypergraph() + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) + * return hg # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_hg)); + __pyx_r = ((PyObject *)__pyx_v_hg); + 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_5); + __Pyx_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_input_str); + __Pyx_XDECREF((PyObject *)__pyx_v_hg); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_tp_new_5_cdec_DenseVector(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_DenseVector(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_5_cdec_DenseVector(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_5_cdec_DenseVector(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_5_cdec_11DenseVector_5__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_DenseVector[] = { + {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_10dot, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("tosparse"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_12tosparse, METH_NOARGS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_DenseVector = { + 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_DenseVector = { + __pyx_pw_5_cdec_11DenseVector_1__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5_cdec_DenseVector, /*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_DenseVector = { + __pyx_pw_5_cdec_11DenseVector_1__len__, /*mp_length*/ + __pyx_pw_5_cdec_11DenseVector_3__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5_cdec_DenseVector, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_DenseVector = { + #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_DenseVector = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.DenseVector"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_DenseVector), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_DenseVector, /*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_DenseVector, /*tp_as_number*/ + &__pyx_tp_as_sequence_DenseVector, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_DenseVector, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_DenseVector, /*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_pw_5_cdec_11DenseVector_7__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_DenseVector, /*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_DenseVector, /*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_SparseVector(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_SparseVector(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_12SparseVector_1__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_5_cdec_SparseVector(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_5_cdec_SparseVector(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_5_cdec_12SparseVector_7__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_SparseVector[] = { + {__Pyx_NAMESTR("copy"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_3copy, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_12dot, METH_O, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_SparseVector = { + __pyx_pw_5_cdec_12SparseVector_30__add__, /*nb_add*/ + __pyx_pw_5_cdec_12SparseVector_32__sub__, /*nb_subtract*/ + __pyx_pw_5_cdec_12SparseVector_34__mul__, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 + __pyx_pw_5_cdec_12SparseVector_36__div__, /*nb_divide*/ + #endif + 0, /*nb_remainder*/ + 0, /*nb_divmod*/ + 0, /*nb_power*/ + __pyx_pw_5_cdec_12SparseVector_20__neg__, /*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 + __pyx_pw_5_cdec_12SparseVector_22__iadd__, /*nb_inplace_add*/ + __pyx_pw_5_cdec_12SparseVector_24__isub__, /*nb_inplace_subtract*/ + __pyx_pw_5_cdec_12SparseVector_26__imul__, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + __pyx_pw_5_cdec_12SparseVector_28__idiv__, /*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_SparseVector = { + __pyx_pw_5_cdec_12SparseVector_16__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5_cdec_SparseVector, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + __pyx_pw_5_cdec_12SparseVector_18__contains__, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_SparseVector = { + __pyx_pw_5_cdec_12SparseVector_16__len__, /*mp_length*/ + __pyx_pw_5_cdec_12SparseVector_5__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5_cdec_SparseVector, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_SparseVector = { + #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_SparseVector = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.SparseVector"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_SparseVector), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_SparseVector, /*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_SparseVector, /*tp_as_number*/ + &__pyx_tp_as_sequence_SparseVector, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_SparseVector, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_SparseVector, /*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*/ + __pyx_pw_5_cdec_12SparseVector_14__richcmp__, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + __pyx_pw_5_cdec_12SparseVector_9__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_SparseVector, /*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_SparseVector, /*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_NT(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_NT(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} + +static PyObject *__pyx_getprop_5_cdec_2NT_cat(PyObject *o, void *x) { + return __pyx_pw_5_cdec_2NT_3cat_1__get__(o); +} + +static int __pyx_setprop_5_cdec_2NT_cat(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_2NT_3cat_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5_cdec_2NT_ref(PyObject *o, void *x) { + return __pyx_pw_5_cdec_2NT_3ref_1__get__(o); +} + +static int __pyx_setprop_5_cdec_2NT_ref(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_2NT_3ref_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_NT[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5_cdec_NT[] = { + {(char *)"cat", __pyx_getprop_5_cdec_2NT_cat, __pyx_setprop_5_cdec_2NT_cat, 0, 0}, + {(char *)"ref", __pyx_getprop_5_cdec_2NT_ref, __pyx_setprop_5_cdec_2NT_ref, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_NT = { + 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_NT = { + 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_NT = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_NT = { + #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_NT = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.NT"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_NT), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_NT, /*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_NT, /*tp_as_number*/ + &__pyx_tp_as_sequence_NT, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_NT, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_5_cdec_2NT_3__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_NT, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_NT, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5_cdec_NT, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pw_5_cdec_2NT_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5_cdec_NT, /*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_NTRef(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_NTRef(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} + +static PyObject *__pyx_getprop_5_cdec_5NTRef_ref(PyObject *o, void *x) { + return __pyx_pw_5_cdec_5NTRef_3ref_1__get__(o); +} + +static int __pyx_setprop_5_cdec_5NTRef_ref(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_5NTRef_3ref_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_NTRef[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5_cdec_NTRef[] = { + {(char *)"ref", __pyx_getprop_5_cdec_5NTRef_ref, __pyx_setprop_5_cdec_5NTRef_ref, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_NTRef = { + 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_NTRef = { + 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_NTRef = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_NTRef = { + #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_NTRef = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.NTRef"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_NTRef), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_NTRef, /*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_NTRef, /*tp_as_number*/ + &__pyx_tp_as_sequence_NTRef, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_NTRef, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_5_cdec_5NTRef_3__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_NTRef, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_NTRef, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5_cdec_NTRef, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pw_5_cdec_5NTRef_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5_cdec_NTRef, /*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_BaseTRule(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_BaseTRule(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_9BaseTRule_1__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} + +static PyObject *__pyx_getprop_5_cdec_9BaseTRule_arity(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9BaseTRule_5arity_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_9BaseTRule_f(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9BaseTRule_1f_1__get__(o); +} + +static int __pyx_setprop_5_cdec_9BaseTRule_f(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_9BaseTRule_1f_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5_cdec_9BaseTRule_e(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9BaseTRule_1e_1__get__(o); +} + +static int __pyx_setprop_5_cdec_9BaseTRule_e(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_9BaseTRule_1e_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5_cdec_9BaseTRule_a(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9BaseTRule_1a_1__get__(o); +} + +static int __pyx_setprop_5_cdec_9BaseTRule_a(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_9BaseTRule_1a_4__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5_cdec_9BaseTRule_scores(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9BaseTRule_6scores_1__get__(o); +} + +static int __pyx_setprop_5_cdec_9BaseTRule_scores(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_9BaseTRule_6scores_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5_cdec_9BaseTRule_lhs(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9BaseTRule_3lhs_1__get__(o); +} + +static int __pyx_setprop_5_cdec_9BaseTRule_lhs(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_9BaseTRule_3lhs_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_BaseTRule[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5_cdec_BaseTRule[] = { + {(char *)"arity", __pyx_getprop_5_cdec_9BaseTRule_arity, 0, 0, 0}, + {(char *)"f", __pyx_getprop_5_cdec_9BaseTRule_f, __pyx_setprop_5_cdec_9BaseTRule_f, 0, 0}, + {(char *)"e", __pyx_getprop_5_cdec_9BaseTRule_e, __pyx_setprop_5_cdec_9BaseTRule_e, 0, 0}, + {(char *)"a", __pyx_getprop_5_cdec_9BaseTRule_a, __pyx_setprop_5_cdec_9BaseTRule_a, 0, 0}, + {(char *)"scores", __pyx_getprop_5_cdec_9BaseTRule_scores, __pyx_setprop_5_cdec_9BaseTRule_scores, 0, 0}, + {(char *)"lhs", __pyx_getprop_5_cdec_9BaseTRule_lhs, __pyx_setprop_5_cdec_9BaseTRule_lhs, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_BaseTRule = { + 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_BaseTRule = { + 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_BaseTRule = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_BaseTRule = { + #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_BaseTRule = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.BaseTRule"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_BaseTRule), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_BaseTRule, /*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_BaseTRule, /*tp_as_number*/ + &__pyx_tp_as_sequence_BaseTRule, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_BaseTRule, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_5_cdec_9BaseTRule_3__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_BaseTRule, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_BaseTRule, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5_cdec_BaseTRule, /*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_BaseTRule, /*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_TRule(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = __pyx_tp_new_5_cdec_BaseTRule(t, a, k); + if (!o) return 0; + if (__pyx_pw_5_cdec_5TRule_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static PyMethodDef __pyx_methods_5_cdec_TRule[] = { + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_TRule = { + 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_TRule = { + 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_TRule = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_TRule = { + #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_TRule = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.TRule"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_TRule), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_BaseTRule, /*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_TRule, /*tp_as_number*/ + &__pyx_tp_as_sequence_TRule, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_TRule, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_TRule, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_TRule, /*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_TRule, /*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 +}; - /* "_cdec.pyx":94 - * if isinstance(sentence, unicode): - * inp = sentence.strip().encode('utf8') - * elif isinstance(sentence, str): # <<<<<<<<<<<<<< - * inp = sentence.strip() - * elif isinstance(sentence, Lattice): - */ - __pyx_t_3 = ((PyObject *)((PyObject*)(&PyString_Type))); - __Pyx_INCREF(__pyx_t_3); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_2) { +static PyObject *__pyx_tp_new_5_cdec_Grammar(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + return o; +} - /* "_cdec.pyx":95 - * inp = sentence.strip().encode('utf8') - * elif isinstance(sentence, str): - * inp = sentence.strip() # <<<<<<<<<<<<<< - * elif isinstance(sentence, Lattice): - * inp = str(sentence) # PLF format - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_inp = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L3; +static void __pyx_tp_dealloc_5_cdec_Grammar(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_7Grammar_1__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); } + (*Py_TYPE(o)->tp_free)(o); +} - /* "_cdec.pyx":96 - * elif isinstance(sentence, str): - * inp = sentence.strip() - * elif isinstance(sentence, Lattice): # <<<<<<<<<<<<<< - * inp = str(sentence) # PLF format - * else: - */ - __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "_cdec.pyx":97 - * inp = sentence.strip() - * elif isinstance(sentence, Lattice): - * inp = str(sentence) # PLF format # <<<<<<<<<<<<<< - * else: - * raise TypeError('Cannot translate input type %s' % type(sentence)) - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_sentence); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_sentence); - __Pyx_GIVEREF(__pyx_v_sentence); - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_v_inp = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3; - } - /*else*/ { +static PyObject *__pyx_getprop_5_cdec_7Grammar_name(PyObject *o, void *x) { + return __pyx_pw_5_cdec_7Grammar_4name_1__get__(o); +} - /* "_cdec.pyx":99 - * inp = str(sentence) # PLF format - * else: - * raise TypeError('Cannot translate input type %s' % type(sentence)) # <<<<<<<<<<<<<< - * if grammar: - * self.dec.SetSentenceGrammarFromString(string( grammar)) - */ - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_48), ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 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 = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +static int __pyx_setprop_5_cdec_7Grammar_name(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_7Grammar_4name_3__set__(o, v); } - __pyx_L3:; - - /* "_cdec.pyx":100 - * else: - * raise TypeError('Cannot translate input type %s' % type(sentence)) - * if grammar: # <<<<<<<<<<<<<< - * self.dec.SetSentenceGrammarFromString(string( grammar)) - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_grammar); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_2) { - - /* "_cdec.pyx":101 - * raise TypeError('Cannot translate input type %s' % type(sentence)) - * if grammar: - * self.dec.SetSentenceGrammarFromString(string( grammar)) # <<<<<<<<<<<<<< - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - * self.dec.Decode(string(inp), &observer) - */ - __pyx_t_4 = PyBytes_AsString(__pyx_v_grammar); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->dec->SetSentenceGrammarFromString(std::string(((char *)__pyx_t_4))); - goto __pyx_L4; + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; } - __pyx_L4:; - - /* "_cdec.pyx":102 - * if grammar: - * self.dec.SetSentenceGrammarFromString(string( grammar)) - * cdef decoder.BasicObserver observer = decoder.BasicObserver() # <<<<<<<<<<<<<< - * self.dec.Decode(string(inp), &observer) - * if observer.hypergraph == NULL: - */ - __pyx_v_observer = BasicObserver(); - - /* "_cdec.pyx":103 - * self.dec.SetSentenceGrammarFromString(string( grammar)) - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - * self.dec.Decode(string(inp), &observer) # <<<<<<<<<<<<<< - * if observer.hypergraph == NULL: - * raise ParseFailed() - */ - __pyx_t_4 = PyBytes_AsString(__pyx_v_inp); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->dec->Decode(std::string(((char *)__pyx_t_4)), (&__pyx_v_observer)); - - /* "_cdec.pyx":104 - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - * self.dec.Decode(string(inp), &observer) - * if observer.hypergraph == NULL: # <<<<<<<<<<<<<< - * raise ParseFailed() - * cdef Hypergraph hg = Hypergraph() - */ - __pyx_t_2 = (__pyx_v_observer.hypergraph == NULL); - if (__pyx_t_2) { +} - /* "_cdec.pyx":105 - * self.dec.Decode(string(inp), &observer) - * if observer.hypergraph == NULL: - * raise ParseFailed() # <<<<<<<<<<<<<< - * cdef Hypergraph hg = Hypergraph() - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) - */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__ParseFailed); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); 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_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L5; - } - __pyx_L5:; +static PyMethodDef __pyx_methods_5_cdec_Grammar[] = { + {0, 0, 0, 0} +}; - /* "_cdec.pyx":106 - * if observer.hypergraph == NULL: - * raise ParseFailed() - * cdef Hypergraph hg = Hypergraph() # <<<<<<<<<<<<<< - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) - * return hg - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Hypergraph)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_hg = ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_t_1); - __pyx_t_1 = 0; +static struct PyGetSetDef __pyx_getsets_5_cdec_Grammar[] = { + {(char *)"name", __pyx_getprop_5_cdec_7Grammar_name, __pyx_setprop_5_cdec_7Grammar_name, 0, 0}, + {0, 0, 0, 0, 0} +}; - /* "_cdec.pyx":107 - * raise ParseFailed() - * cdef Hypergraph hg = Hypergraph() - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) # <<<<<<<<<<<<<< - * return hg - */ - __pyx_v_hg->hg = new Hypergraph((__pyx_v_observer.hypergraph[0])); +static PyNumberMethods __pyx_tp_as_number_Grammar = { + 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 +}; - /* "_cdec.pyx":108 - * cdef Hypergraph hg = Hypergraph() - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) - * return hg # <<<<<<<<<<<<<< - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_hg)); - __pyx_r = ((PyObject *)__pyx_v_hg); - goto __pyx_L0; +static PySequenceMethods __pyx_tp_as_sequence_Grammar = { + 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*/ +}; - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_inp); - __Pyx_XDECREF((PyObject *)__pyx_v_hg); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} +static PyMappingMethods __pyx_tp_as_mapping_Grammar = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; -static PyObject *__pyx_tp_new_5_cdec_DenseVector(PyTypeObject *t, PyObject *a, PyObject *k) { - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - return o; -} +static PyBufferProcs __pyx_tp_as_buffer_Grammar = { + #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 void __pyx_tp_dealloc_5_cdec_DenseVector(PyObject *o) { - (*Py_TYPE(o)->tp_free)(o); -} -static PyObject *__pyx_sq_item_5_cdec_DenseVector(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} +static PyTypeObject __pyx_type_5_cdec_Grammar = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.Grammar"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Grammar), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_Grammar, /*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_Grammar, /*tp_as_number*/ + &__pyx_tp_as_sequence_Grammar, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Grammar, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Grammar, /*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_pw_5_cdec_7Grammar_3__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_Grammar, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5_cdec_Grammar, /*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_Grammar, /*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 int __pyx_mp_ass_subscript_5_cdec_DenseVector(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_pw_5_cdec_11DenseVector_5__setitem__(o, i, v); - } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); - return -1; +static PyObject *__pyx_tp_new_5_cdec_TextGrammar(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = __pyx_tp_new_5_cdec_Grammar(t, a, k); + if (!o) return 0; + if (__pyx_pw_5_cdec_11TextGrammar_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; } + return o; } -static PyMethodDef __pyx_methods_5_cdec_DenseVector[] = { - {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_10dot, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("tosparse"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_12tosparse, METH_NOARGS, __Pyx_DOCSTR(0)}, +static PyMethodDef __pyx_methods_5_cdec_TextGrammar[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_DenseVector = { +static PyNumberMethods __pyx_tp_as_number_TextGrammar = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -14101,11 +18057,11 @@ static PyNumberMethods __pyx_tp_as_number_DenseVector = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_DenseVector = { - __pyx_pw_5_cdec_11DenseVector_1__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence_TextGrammar = { + 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_DenseVector, /*sq_item*/ + 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -14114,13 +18070,13 @@ static PySequenceMethods __pyx_tp_as_sequence_DenseVector = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_DenseVector = { - __pyx_pw_5_cdec_11DenseVector_1__len__, /*mp_length*/ - __pyx_pw_5_cdec_11DenseVector_3__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_5_cdec_DenseVector, /*mp_ass_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping_TextGrammar = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_DenseVector = { +static PyBufferProcs __pyx_tp_as_buffer_TextGrammar = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -14141,12 +18097,12 @@ static PyBufferProcs __pyx_tp_as_buffer_DenseVector = { #endif }; -static PyTypeObject __pyx_type_5_cdec_DenseVector = { +static PyTypeObject __pyx_type_5_cdec_TextGrammar = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.DenseVector"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_DenseVector), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.TextGrammar"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_TextGrammar), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_DenseVector, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_Grammar, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -14156,24 +18112,24 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_DenseVector, /*tp_as_number*/ - &__pyx_tp_as_sequence_DenseVector, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_DenseVector, /*tp_as_mapping*/ + &__pyx_tp_as_number_TextGrammar, /*tp_as_number*/ + &__pyx_tp_as_sequence_TextGrammar, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_TextGrammar, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_DenseVector, /*tp_as_buffer*/ + &__pyx_tp_as_buffer_TextGrammar, /*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_pw_5_cdec_11DenseVector_7__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_DenseVector, /*tp_methods*/ + __pyx_methods_5_cdec_TextGrammar, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -14183,7 +18139,7 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_DenseVector, /*tp_new*/ + __pyx_tp_new_5_cdec_TextGrammar, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -14197,60 +18153,77 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_SparseVector(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_Hypergraph(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_SparseVector(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec_Hypergraph(PyObject *o) { { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); - __pyx_pw_5_cdec_12SparseVector_1__dealloc__(o); + __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); } (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_sq_item_5_cdec_SparseVector(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; + +static PyObject *__pyx_getprop_5_cdec_10Hypergraph_edges(PyObject *o, void *x) { + return __pyx_pw_5_cdec_10Hypergraph_5edges_1__get__(o); } -static int __pyx_mp_ass_subscript_5_cdec_SparseVector(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_pw_5_cdec_12SparseVector_7__setitem__(o, i, v); - } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); - return -1; - } +static PyObject *__pyx_getprop_5_cdec_10Hypergraph_nodes(PyObject *o, void *x) { + return __pyx_pw_5_cdec_10Hypergraph_5nodes_1__get__(o); } -static PyMethodDef __pyx_methods_5_cdec_SparseVector[] = { - {__Pyx_NAMESTR("copy"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_3copy, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_12dot, METH_O, __Pyx_DOCSTR(0)}, +static PyObject *__pyx_getprop_5_cdec_10Hypergraph_goal(PyObject *o, void *x) { + return __pyx_pw_5_cdec_10Hypergraph_4goal_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_10Hypergraph_npaths(PyObject *o, void *x) { + return __pyx_pw_5_cdec_10Hypergraph_6npaths_1__get__(o); +} + +static PyMethodDef __pyx_methods_5_cdec_Hypergraph[] = { + {__Pyx_NAMESTR("viterbi"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_3viterbi, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("viterbi_trees"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_5viterbi_trees, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("viterbi_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_7viterbi_features, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("viterbi_joshua"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_9viterbi_joshua, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("kbest"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_11kbest, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("kbest_trees"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_14kbest_trees, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("kbest_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_17kbest_features, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("sample"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_20sample, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("intersect"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_23intersect, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("prune"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_25prune, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("lattice"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_27lattice, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("reweight"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_29reweight, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("inside_outside"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_31inside_outside, METH_NOARGS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_30__add__, /*nb_add*/ - __pyx_pw_5_cdec_12SparseVector_32__sub__, /*nb_subtract*/ - __pyx_pw_5_cdec_12SparseVector_34__mul__, /*nb_multiply*/ +static struct PyGetSetDef __pyx_getsets_5_cdec_Hypergraph[] = { + {(char *)"edges", __pyx_getprop_5_cdec_10Hypergraph_edges, 0, 0, 0}, + {(char *)"nodes", __pyx_getprop_5_cdec_10Hypergraph_nodes, 0, 0, 0}, + {(char *)"goal", __pyx_getprop_5_cdec_10Hypergraph_goal, 0, 0, 0}, + {(char *)"npaths", __pyx_getprop_5_cdec_10Hypergraph_npaths, 0, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Hypergraph = { + 0, /*nb_add*/ + 0, /*nb_subtract*/ + 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 - __pyx_pw_5_cdec_12SparseVector_36__div__, /*nb_divide*/ + 0, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ - __pyx_pw_5_cdec_12SparseVector_20__neg__, /*nb_negative*/ + 0, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ @@ -14276,11 +18249,11 @@ static PyNumberMethods __pyx_tp_as_number_SparseVector = { #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif - __pyx_pw_5_cdec_12SparseVector_22__iadd__, /*nb_inplace_add*/ - __pyx_pw_5_cdec_12SparseVector_24__isub__, /*nb_inplace_subtract*/ - __pyx_pw_5_cdec_12SparseVector_26__imul__, /*nb_inplace_multiply*/ + 0, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 - __pyx_pw_5_cdec_12SparseVector_28__idiv__, /*nb_inplace_divide*/ + 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ @@ -14298,26 +18271,26 @@ static PyNumberMethods __pyx_tp_as_number_SparseVector = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_16__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence_Hypergraph = { + 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_SparseVector, /*sq_item*/ + 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ - __pyx_pw_5_cdec_12SparseVector_18__contains__, /*sq_contains*/ + 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_16__len__, /*mp_length*/ - __pyx_pw_5_cdec_12SparseVector_5__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_5_cdec_SparseVector, /*mp_ass_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping_Hypergraph = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_SparseVector = { +static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -14338,12 +18311,12 @@ static PyBufferProcs __pyx_tp_as_buffer_SparseVector = { #endif }; -static PyTypeObject __pyx_type_5_cdec_SparseVector = { +static PyTypeObject __pyx_type_5_cdec_Hypergraph = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.SparseVector"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_SparseVector), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.Hypergraph"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Hypergraph), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_SparseVector, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_Hypergraph, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -14353,26 +18326,26 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_SparseVector, /*tp_as_number*/ - &__pyx_tp_as_sequence_SparseVector, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_SparseVector, /*tp_as_mapping*/ + &__pyx_tp_as_number_Hypergraph, /*tp_as_number*/ + &__pyx_tp_as_sequence_Hypergraph, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Hypergraph, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_SparseVector, /*tp_as_buffer*/ + &__pyx_tp_as_buffer_Hypergraph, /*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*/ - __pyx_pw_5_cdec_12SparseVector_14__richcmp__, /*tp_richcompare*/ + 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_12SparseVector_9__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_SparseVector, /*tp_methods*/ + __pyx_methods_5_cdec_Hypergraph, /*tp_methods*/ 0, /*tp_members*/ - 0, /*tp_getset*/ + __pyx_getsets_5_cdec_Hypergraph, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -14380,7 +18353,7 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_SparseVector, /*tp_new*/ + __pyx_tp_new_5_cdec_Hypergraph, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -14393,62 +18366,90 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { 0, /*tp_version_tag*/ #endif }; +static struct __pyx_vtabstruct_5_cdec_HypergraphEdge __pyx_vtable_5_cdec_HypergraphEdge; + +static PyObject *__pyx_tp_new_5_cdec_HypergraphEdge(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec_HypergraphEdge *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_5_cdec_HypergraphEdge *)o); + p->__pyx_vtab = __pyx_vtabptr_5_cdec_HypergraphEdge; + p->trule = ((struct __pyx_obj_5_cdec_BaseTRule *)Py_None); Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_5_cdec_HypergraphEdge(PyObject *o) { + struct __pyx_obj_5_cdec_HypergraphEdge *p = (struct __pyx_obj_5_cdec_HypergraphEdge *)o; + Py_XDECREF(((PyObject *)p->trule)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_5_cdec_HypergraphEdge(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec_HypergraphEdge *p = (struct __pyx_obj_5_cdec_HypergraphEdge *)o; + if (p->trule) { + e = (*v)(((PyObject*)p->trule), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5_cdec_HypergraphEdge(PyObject *o) { + struct __pyx_obj_5_cdec_HypergraphEdge *p = (struct __pyx_obj_5_cdec_HypergraphEdge *)o; + PyObject* tmp; + tmp = ((PyObject*)p->trule); + p->trule = ((struct __pyx_obj_5_cdec_BaseTRule *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} -static PyObject *__pyx_tp_new_5_cdec_Hypergraph(PyTypeObject *t, PyObject *a, PyObject *k) { - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - return o; +static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_head_node(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphEdge_9head_node_1__get__(o); } -static void __pyx_tp_dealloc_5_cdec_Hypergraph(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - (*Py_TYPE(o)->tp_free)(o); +static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_tail_nodes(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphEdge_10tail_nodes_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_10Hypergraph_edges(PyObject *o, void *x) { - return __pyx_pw_5_cdec_10Hypergraph_5edges_1__get__(o); +static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_span(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphEdge_4span_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_10Hypergraph_nodes(PyObject *o, void *x) { - return __pyx_pw_5_cdec_10Hypergraph_5nodes_1__get__(o); +static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_feature_values(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphEdge_14feature_values_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_10Hypergraph_goal(PyObject *o, void *x) { - return __pyx_pw_5_cdec_10Hypergraph_4goal_1__get__(o); +static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_prob(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphEdge_4prob_1__get__(o); } -static PyMethodDef __pyx_methods_5_cdec_Hypergraph[] = { - {__Pyx_NAMESTR("viterbi"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_3viterbi, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("viterbi_trees"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_5viterbi_trees, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("viterbi_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_7viterbi_features, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("viterbi_joshua"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_9viterbi_joshua, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("kbest"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_11kbest, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("kbest_trees"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_14kbest_trees, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("kbest_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_17kbest_features, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("sample"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_20sample, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("intersect"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_23intersect, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("prune"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_25prune, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("lattice"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_27lattice, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("reweight"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_29reweight, METH_O, __Pyx_DOCSTR(0)}, +static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_trule(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphEdge_5trule_1__get__(o); +} + +static int __pyx_setprop_5_cdec_14HypergraphEdge_trule(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_14HypergraphEdge_5trule_3__set__(o, v); + } + else { + return __pyx_pw_5_cdec_14HypergraphEdge_5trule_5__del__(o); + } +} + +static PyMethodDef __pyx_methods_5_cdec_HypergraphEdge[] = { {0, 0, 0, 0} }; -static struct PyGetSetDef __pyx_getsets_5_cdec_Hypergraph[] = { - {(char *)"edges", __pyx_getprop_5_cdec_10Hypergraph_edges, 0, 0, 0}, - {(char *)"nodes", __pyx_getprop_5_cdec_10Hypergraph_nodes, 0, 0, 0}, - {(char *)"goal", __pyx_getprop_5_cdec_10Hypergraph_goal, 0, 0, 0}, +static struct PyGetSetDef __pyx_getsets_5_cdec_HypergraphEdge[] = { + {(char *)"head_node", __pyx_getprop_5_cdec_14HypergraphEdge_head_node, 0, 0, 0}, + {(char *)"tail_nodes", __pyx_getprop_5_cdec_14HypergraphEdge_tail_nodes, 0, 0, 0}, + {(char *)"span", __pyx_getprop_5_cdec_14HypergraphEdge_span, 0, 0, 0}, + {(char *)"feature_values", __pyx_getprop_5_cdec_14HypergraphEdge_feature_values, 0, 0, 0}, + {(char *)"prob", __pyx_getprop_5_cdec_14HypergraphEdge_prob, 0, 0, 0}, + {(char *)"trule", __pyx_getprop_5_cdec_14HypergraphEdge_trule, __pyx_setprop_5_cdec_14HypergraphEdge_trule, 0, 0}, {0, 0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_Hypergraph = { +static PyNumberMethods __pyx_tp_as_number_HypergraphEdge = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -14506,8 +18507,8 @@ static PyNumberMethods __pyx_tp_as_number_Hypergraph = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Hypergraph = { - 0, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence_HypergraphEdge = { + __pyx_pw_5_cdec_14HypergraphEdge_1__len__, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ @@ -14519,13 +18520,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Hypergraph = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Hypergraph = { - 0, /*mp_length*/ +static PyMappingMethods __pyx_tp_as_mapping_HypergraphEdge = { + __pyx_pw_5_cdec_14HypergraphEdge_1__len__, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = { +static PyBufferProcs __pyx_tp_as_buffer_HypergraphEdge = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -14546,12 +18547,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Hypergraph = { +static PyTypeObject __pyx_type_5_cdec_HypergraphEdge = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Hypergraph"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Hypergraph), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.HypergraphEdge"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_HypergraphEdge), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Hypergraph, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_HypergraphEdge, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -14561,26 +18562,26 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Hypergraph, /*tp_as_number*/ - &__pyx_tp_as_sequence_Hypergraph, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Hypergraph, /*tp_as_mapping*/ + &__pyx_tp_as_number_HypergraphEdge, /*tp_as_number*/ + &__pyx_tp_as_sequence_HypergraphEdge, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_HypergraphEdge, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Hypergraph, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer_HypergraphEdge, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ + __pyx_tp_traverse_5_cdec_HypergraphEdge, /*tp_traverse*/ + __pyx_tp_clear_5_cdec_HypergraphEdge, /*tp_clear*/ + __pyx_pw_5_cdec_14HypergraphEdge_3__richcmp__, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Hypergraph, /*tp_methods*/ + __pyx_methods_5_cdec_HypergraphEdge, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_5_cdec_Hypergraph, /*tp_getset*/ + __pyx_getsets_5_cdec_HypergraphEdge, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -14588,7 +18589,7 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Hypergraph, /*tp_new*/ + __pyx_tp_new_5_cdec_HypergraphEdge, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -14601,51 +18602,50 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { 0, /*tp_version_tag*/ #endif }; +static struct __pyx_vtabstruct_5_cdec_HypergraphNode __pyx_vtable_5_cdec_HypergraphNode; -static PyObject *__pyx_tp_new_5_cdec_TRule(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_HypergraphNode(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec_HypergraphNode *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + p = ((struct __pyx_obj_5_cdec_HypergraphNode *)o); + p->__pyx_vtab = __pyx_vtabptr_5_cdec_HypergraphNode; return o; } -static void __pyx_tp_dealloc_5_cdec_TRule(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec_HypergraphNode(PyObject *o) { (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_getprop_5_cdec_5TRule_arity(PyObject *o, void *x) { - return __pyx_pw_5_cdec_5TRule_5arity_1__get__(o); -} - -static PyObject *__pyx_getprop_5_cdec_5TRule_f(PyObject *o, void *x) { - return __pyx_pw_5_cdec_5TRule_1f_1__get__(o); +static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_in_edges(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphNode_8in_edges_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_5TRule_e(PyObject *o, void *x) { - return __pyx_pw_5_cdec_5TRule_1e_1__get__(o); +static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_out_edges(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphNode_9out_edges_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_5TRule_scores(PyObject *o, void *x) { - return __pyx_pw_5_cdec_5TRule_6scores_1__get__(o); +static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_span(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphNode_4span_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_5TRule_lhs(PyObject *o, void *x) { - return __pyx_pw_5_cdec_5TRule_3lhs_1__get__(o); +static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_cat(PyObject *o, void *x) { + return __pyx_pw_5_cdec_14HypergraphNode_3cat_1__get__(o); } -static PyMethodDef __pyx_methods_5_cdec_TRule[] = { +static PyMethodDef __pyx_methods_5_cdec_HypergraphNode[] = { {0, 0, 0, 0} }; -static struct PyGetSetDef __pyx_getsets_5_cdec_TRule[] = { - {(char *)"arity", __pyx_getprop_5_cdec_5TRule_arity, 0, 0, 0}, - {(char *)"f", __pyx_getprop_5_cdec_5TRule_f, 0, 0, 0}, - {(char *)"e", __pyx_getprop_5_cdec_5TRule_e, 0, 0, 0}, - {(char *)"scores", __pyx_getprop_5_cdec_5TRule_scores, 0, 0, 0}, - {(char *)"lhs", __pyx_getprop_5_cdec_5TRule_lhs, 0, 0, 0}, +static struct PyGetSetDef __pyx_getsets_5_cdec_HypergraphNode[] = { + {(char *)"in_edges", __pyx_getprop_5_cdec_14HypergraphNode_in_edges, 0, 0, 0}, + {(char *)"out_edges", __pyx_getprop_5_cdec_14HypergraphNode_out_edges, 0, 0, 0}, + {(char *)"span", __pyx_getprop_5_cdec_14HypergraphNode_span, 0, 0, 0}, + {(char *)"cat", __pyx_getprop_5_cdec_14HypergraphNode_cat, 0, 0, 0}, {0, 0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_TRule = { +static PyNumberMethods __pyx_tp_as_number_HypergraphNode = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -14703,7 +18703,7 @@ static PyNumberMethods __pyx_tp_as_number_TRule = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_TRule = { +static PySequenceMethods __pyx_tp_as_sequence_HypergraphNode = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -14716,13 +18716,13 @@ static PySequenceMethods __pyx_tp_as_sequence_TRule = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_TRule = { +static PyMappingMethods __pyx_tp_as_mapping_HypergraphNode = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_TRule = { +static PyBufferProcs __pyx_tp_as_buffer_HypergraphNode = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -14743,12 +18743,12 @@ static PyBufferProcs __pyx_tp_as_buffer_TRule = { #endif }; -static PyTypeObject __pyx_type_5_cdec_TRule = { +static PyTypeObject __pyx_type_5_cdec_HypergraphNode = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.TRule"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_TRule), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.HypergraphNode"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_HypergraphNode), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_TRule, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_HypergraphNode, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -14758,26 +18758,26 @@ static PyTypeObject __pyx_type_5_cdec_TRule = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_TRule, /*tp_as_number*/ - &__pyx_tp_as_sequence_TRule, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_TRule, /*tp_as_mapping*/ + &__pyx_tp_as_number_HypergraphNode, /*tp_as_number*/ + &__pyx_tp_as_sequence_HypergraphNode, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_HypergraphNode, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ - __pyx_pw_5_cdec_5TRule_1__str__, /*tp_str*/ + 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_TRule, /*tp_as_buffer*/ + &__pyx_tp_as_buffer_HypergraphNode, /*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*/ + __pyx_pw_5_cdec_14HypergraphNode_1__richcmp__, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_TRule, /*tp_methods*/ + __pyx_methods_5_cdec_HypergraphNode, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_5_cdec_TRule, /*tp_getset*/ + __pyx_getsets_5_cdec_HypergraphNode, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -14785,7 +18785,7 @@ static PyTypeObject __pyx_type_5_cdec_TRule = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_TRule, /*tp_new*/ + __pyx_tp_new_5_cdec_HypergraphNode, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -14798,90 +18798,53 @@ static PyTypeObject __pyx_type_5_cdec_TRule = { 0, /*tp_version_tag*/ #endif }; -static struct __pyx_vtabstruct_5_cdec_HypergraphEdge __pyx_vtable_5_cdec_HypergraphEdge; -static PyObject *__pyx_tp_new_5_cdec_HypergraphEdge(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec_HypergraphEdge *p; +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; - p = ((struct __pyx_obj_5_cdec_HypergraphEdge *)o); - p->__pyx_vtab = __pyx_vtabptr_5_cdec_HypergraphEdge; - p->trule = ((struct __pyx_obj_5_cdec_TRule *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_5_cdec_7Lattice_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } return o; } -static void __pyx_tp_dealloc_5_cdec_HypergraphEdge(PyObject *o) { - struct __pyx_obj_5_cdec_HypergraphEdge *p = (struct __pyx_obj_5_cdec_HypergraphEdge *)o; - Py_XDECREF(((PyObject *)p->trule)); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_5_cdec_HypergraphEdge(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_5_cdec_HypergraphEdge *p = (struct __pyx_obj_5_cdec_HypergraphEdge *)o; - if (p->trule) { - e = (*v)(((PyObject*)p->trule), a); if (e) return e; +static void __pyx_tp_dealloc_5_cdec_Lattice(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_7Lattice_14__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); } - return 0; -} - -static int __pyx_tp_clear_5_cdec_HypergraphEdge(PyObject *o) { - struct __pyx_obj_5_cdec_HypergraphEdge *p = (struct __pyx_obj_5_cdec_HypergraphEdge *)o; - PyObject* tmp; - tmp = ((PyObject*)p->trule); - p->trule = ((struct __pyx_obj_5_cdec_TRule *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_head_node(PyObject *o, void *x) { - return __pyx_pw_5_cdec_14HypergraphEdge_9head_node_1__get__(o); -} - -static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_tail_nodes(PyObject *o, void *x) { - return __pyx_pw_5_cdec_14HypergraphEdge_10tail_nodes_1__get__(o); -} - -static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_span(PyObject *o, void *x) { - return __pyx_pw_5_cdec_14HypergraphEdge_4span_1__get__(o); -} - -static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_feature_values(PyObject *o, void *x) { - return __pyx_pw_5_cdec_14HypergraphEdge_14feature_values_1__get__(o); -} - -static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_prob(PyObject *o, void *x) { - return __pyx_pw_5_cdec_14HypergraphEdge_4prob_1__get__(o); + (*Py_TYPE(o)->tp_free)(o); } - -static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_trule(PyObject *o, void *x) { - return __pyx_pw_5_cdec_14HypergraphEdge_5trule_1__get__(o); +static PyObject *__pyx_sq_item_5_cdec_Lattice(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; } -static int __pyx_setprop_5_cdec_14HypergraphEdge_trule(PyObject *o, PyObject *v, void *x) { +static int __pyx_mp_ass_subscript_5_cdec_Lattice(PyObject *o, PyObject *i, PyObject *v) { if (v) { - return __pyx_pw_5_cdec_14HypergraphEdge_5trule_3__set__(o, v); + return __pyx_pw_5_cdec_7Lattice_5__setitem__(o, i, v); } else { - return __pyx_pw_5_cdec_14HypergraphEdge_5trule_5__del__(o); + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; } } - -static PyMethodDef __pyx_methods_5_cdec_HypergraphEdge[] = { - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_5_cdec_HypergraphEdge[] = { - {(char *)"head_node", __pyx_getprop_5_cdec_14HypergraphEdge_head_node, 0, 0, 0}, - {(char *)"tail_nodes", __pyx_getprop_5_cdec_14HypergraphEdge_tail_nodes, 0, 0, 0}, - {(char *)"span", __pyx_getprop_5_cdec_14HypergraphEdge_span, 0, 0, 0}, - {(char *)"feature_values", __pyx_getprop_5_cdec_14HypergraphEdge_feature_values, 0, 0, 0}, - {(char *)"prob", __pyx_getprop_5_cdec_14HypergraphEdge_prob, 0, 0, 0}, - {(char *)"trule", __pyx_getprop_5_cdec_14HypergraphEdge_trule, __pyx_setprop_5_cdec_14HypergraphEdge_trule, 0, 0}, - {0, 0, 0, 0, 0} + +static PyMethodDef __pyx_methods_5_cdec_Lattice[] = { + {__Pyx_NAMESTR("todot"), (PyCFunction)__pyx_pw_5_cdec_7Lattice_16todot, METH_NOARGS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_HypergraphEdge = { +static PyNumberMethods __pyx_tp_as_number_Lattice = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -14939,11 +18902,11 @@ static PyNumberMethods __pyx_tp_as_number_HypergraphEdge = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_HypergraphEdge = { - __pyx_pw_5_cdec_14HypergraphEdge_1__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence_Lattice = { + __pyx_pw_5_cdec_7Lattice_7__len__, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - 0, /*sq_item*/ + __pyx_sq_item_5_cdec_Lattice, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -14952,13 +18915,13 @@ static PySequenceMethods __pyx_tp_as_sequence_HypergraphEdge = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_HypergraphEdge = { - __pyx_pw_5_cdec_14HypergraphEdge_1__len__, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping_Lattice = { + __pyx_pw_5_cdec_7Lattice_7__len__, /*mp_length*/ + __pyx_pw_5_cdec_7Lattice_3__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5_cdec_Lattice, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_HypergraphEdge = { +static PyBufferProcs __pyx_tp_as_buffer_Lattice = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -14979,12 +18942,12 @@ static PyBufferProcs __pyx_tp_as_buffer_HypergraphEdge = { #endif }; -static PyTypeObject __pyx_type_5_cdec_HypergraphEdge = { +static PyTypeObject __pyx_type_5_cdec_Lattice = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.HypergraphEdge"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_HypergraphEdge), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.Lattice"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Lattice), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_HypergraphEdge, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_Lattice, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -14994,26 +18957,26 @@ static PyTypeObject __pyx_type_5_cdec_HypergraphEdge = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_HypergraphEdge, /*tp_as_number*/ - &__pyx_tp_as_sequence_HypergraphEdge, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_HypergraphEdge, /*tp_as_mapping*/ + &__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*/ - 0, /*tp_str*/ + __pyx_pw_5_cdec_7Lattice_9__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_HypergraphEdge, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + &__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*/ - __pyx_tp_traverse_5_cdec_HypergraphEdge, /*tp_traverse*/ - __pyx_tp_clear_5_cdec_HypergraphEdge, /*tp_clear*/ - __pyx_pw_5_cdec_14HypergraphEdge_3__richcmp__, /*tp_richcompare*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ + __pyx_pw_5_cdec_7Lattice_11__iter__, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_HypergraphEdge, /*tp_methods*/ + __pyx_methods_5_cdec_Lattice, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_5_cdec_HypergraphEdge, /*tp_getset*/ + 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -15021,7 +18984,7 @@ static PyTypeObject __pyx_type_5_cdec_HypergraphEdge = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_HypergraphEdge, /*tp_new*/ + __pyx_tp_new_5_cdec_Lattice, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -15034,50 +18997,51 @@ static PyTypeObject __pyx_type_5_cdec_HypergraphEdge = { 0, /*tp_version_tag*/ #endif }; -static struct __pyx_vtabstruct_5_cdec_HypergraphNode __pyx_vtable_5_cdec_HypergraphNode; -static PyObject *__pyx_tp_new_5_cdec_HypergraphNode(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec_HypergraphNode *p; +static PyObject *__pyx_tp_new_5_cdec_Candidate(PyTypeObject *t, PyObject *a, PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec_HypergraphNode *)o); - p->__pyx_vtab = __pyx_vtabptr_5_cdec_HypergraphNode; return o; } -static void __pyx_tp_dealloc_5_cdec_HypergraphNode(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec_Candidate(PyObject *o) { (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_in_edges(PyObject *o, void *x) { - return __pyx_pw_5_cdec_14HypergraphNode_8in_edges_1__get__(o); +static PyObject *__pyx_getprop_5_cdec_9Candidate_words(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9Candidate_5words_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_out_edges(PyObject *o, void *x) { - return __pyx_pw_5_cdec_14HypergraphNode_9out_edges_1__get__(o); +static PyObject *__pyx_getprop_5_cdec_9Candidate_fmap(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9Candidate_4fmap_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_span(PyObject *o, void *x) { - return __pyx_pw_5_cdec_14HypergraphNode_4span_1__get__(o); +static PyObject *__pyx_getprop_5_cdec_9Candidate_score(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9Candidate_5score_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_cat(PyObject *o, void *x) { - return __pyx_pw_5_cdec_14HypergraphNode_3cat_1__get__(o); +static int __pyx_setprop_5_cdec_9Candidate_score(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_9Candidate_5score_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } } -static PyMethodDef __pyx_methods_5_cdec_HypergraphNode[] = { +static PyMethodDef __pyx_methods_5_cdec_Candidate[] = { {0, 0, 0, 0} }; -static struct PyGetSetDef __pyx_getsets_5_cdec_HypergraphNode[] = { - {(char *)"in_edges", __pyx_getprop_5_cdec_14HypergraphNode_in_edges, 0, 0, 0}, - {(char *)"out_edges", __pyx_getprop_5_cdec_14HypergraphNode_out_edges, 0, 0, 0}, - {(char *)"span", __pyx_getprop_5_cdec_14HypergraphNode_span, 0, 0, 0}, - {(char *)"cat", __pyx_getprop_5_cdec_14HypergraphNode_cat, 0, 0, 0}, +static struct PyGetSetDef __pyx_getsets_5_cdec_Candidate[] = { + {(char *)"words", __pyx_getprop_5_cdec_9Candidate_words, 0, 0, 0}, + {(char *)"fmap", __pyx_getprop_5_cdec_9Candidate_fmap, 0, 0, 0}, + {(char *)"score", __pyx_getprop_5_cdec_9Candidate_score, __pyx_setprop_5_cdec_9Candidate_score, 0, 0}, {0, 0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_HypergraphNode = { +static PyNumberMethods __pyx_tp_as_number_Candidate = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -15135,7 +19099,7 @@ static PyNumberMethods __pyx_tp_as_number_HypergraphNode = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_HypergraphNode = { +static PySequenceMethods __pyx_tp_as_sequence_Candidate = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -15148,13 +19112,13 @@ static PySequenceMethods __pyx_tp_as_sequence_HypergraphNode = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_HypergraphNode = { +static PyMappingMethods __pyx_tp_as_mapping_Candidate = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_HypergraphNode = { +static PyBufferProcs __pyx_tp_as_buffer_Candidate = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -15175,12 +19139,12 @@ static PyBufferProcs __pyx_tp_as_buffer_HypergraphNode = { #endif }; -static PyTypeObject __pyx_type_5_cdec_HypergraphNode = { +static PyTypeObject __pyx_type_5_cdec_Candidate = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.HypergraphNode"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_HypergraphNode), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.Candidate"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Candidate), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_HypergraphNode, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_Candidate, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -15190,26 +19154,26 @@ static PyTypeObject __pyx_type_5_cdec_HypergraphNode = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_HypergraphNode, /*tp_as_number*/ - &__pyx_tp_as_sequence_HypergraphNode, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_HypergraphNode, /*tp_as_mapping*/ + &__pyx_tp_as_number_Candidate, /*tp_as_number*/ + &__pyx_tp_as_sequence_Candidate, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Candidate, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_HypergraphNode, /*tp_as_buffer*/ + &__pyx_tp_as_buffer_Candidate, /*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*/ - __pyx_pw_5_cdec_14HypergraphNode_1__richcmp__, /*tp_richcompare*/ + 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_HypergraphNode, /*tp_methods*/ + __pyx_methods_5_cdec_Candidate, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_5_cdec_HypergraphNode, /*tp_getset*/ + __pyx_getsets_5_cdec_Candidate, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -15217,7 +19181,7 @@ static PyTypeObject __pyx_type_5_cdec_HypergraphNode = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_HypergraphNode, /*tp_new*/ + __pyx_tp_new_5_cdec_Candidate, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -15231,50 +19195,45 @@ static PyTypeObject __pyx_type_5_cdec_HypergraphNode = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Lattice(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_SufficientStats(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) { +static void __pyx_tp_dealloc_5_cdec_SufficientStats(PyObject *o) { { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); - __pyx_pw_5_cdec_7Lattice_14__dealloc__(o); + __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); } (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_sq_item_5_cdec_Lattice(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; + +static PyObject *__pyx_getprop_5_cdec_15SufficientStats_score(PyObject *o, void *x) { + return __pyx_pw_5_cdec_15SufficientStats_5score_1__get__(o); } -static int __pyx_mp_ass_subscript_5_cdec_Lattice(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_pw_5_cdec_7Lattice_5__setitem__(o, i, v); - } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); - return -1; - } +static PyObject *__pyx_getprop_5_cdec_15SufficientStats_detail(PyObject *o, void *x) { + return __pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(o); } -static PyMethodDef __pyx_methods_5_cdec_Lattice[] = { - {__Pyx_NAMESTR("todot"), (PyCFunction)__pyx_pw_5_cdec_7Lattice_16todot, METH_NOARGS, __Pyx_DOCSTR(0)}, +static PyMethodDef __pyx_methods_5_cdec_SufficientStats[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_Lattice = { - 0, /*nb_add*/ +static struct PyGetSetDef __pyx_getsets_5_cdec_SufficientStats[] = { + {(char *)"score", __pyx_getprop_5_cdec_15SufficientStats_score, 0, 0, 0}, + {(char *)"detail", __pyx_getprop_5_cdec_15SufficientStats_detail, 0, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_SufficientStats = { + __pyx_pw_5_cdec_15SufficientStats_10__add__, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 @@ -15309,7 +19268,7 @@ static PyNumberMethods __pyx_tp_as_number_Lattice = { #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif - 0, /*nb_inplace_add*/ + __pyx_pw_5_cdec_15SufficientStats_8__iadd__, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 @@ -15331,11 +19290,11 @@ static PyNumberMethods __pyx_tp_as_number_Lattice = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Lattice = { - __pyx_pw_5_cdec_7Lattice_7__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence_SufficientStats = { + __pyx_pw_5_cdec_15SufficientStats_3__len__, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_Lattice, /*sq_item*/ + 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -15344,13 +19303,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Lattice = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Lattice = { - __pyx_pw_5_cdec_7Lattice_7__len__, /*mp_length*/ - __pyx_pw_5_cdec_7Lattice_3__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_5_cdec_Lattice, /*mp_ass_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping_SufficientStats = { + __pyx_pw_5_cdec_15SufficientStats_3__len__, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Lattice = { +static PyBufferProcs __pyx_tp_as_buffer_SufficientStats = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -15371,12 +19330,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Lattice = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Lattice = { +static PyTypeObject __pyx_type_5_cdec_SufficientStats = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Lattice"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Lattice), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.SufficientStats"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_SufficientStats), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Lattice, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_SufficientStats, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -15386,34 +19345,34 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { 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*/ + &__pyx_tp_as_number_SufficientStats, /*tp_as_number*/ + &__pyx_tp_as_sequence_SufficientStats, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_SufficientStats, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ - __pyx_pw_5_cdec_7Lattice_9__str__, /*tp_str*/ + 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Lattice, /*tp_as_buffer*/ + &__pyx_tp_as_buffer_SufficientStats, /*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_pw_5_cdec_7Lattice_11__iter__, /*tp_iter*/ + __pyx_pw_5_cdec_15SufficientStats_5__iter__, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Lattice, /*tp_methods*/ + __pyx_methods_5_cdec_SufficientStats, /*tp_methods*/ 0, /*tp_members*/ - 0, /*tp_getset*/ + __pyx_getsets_5_cdec_SufficientStats, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ - __pyx_pw_5_cdec_7Lattice_1__init__, /*tp_init*/ + 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Lattice, /*tp_new*/ + __pyx_tp_new_5_cdec_SufficientStats, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -15427,50 +19386,41 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Candidate(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_CandidateSet(PyTypeObject *t, PyObject *a, PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + if (__pyx_pw_5_cdec_12CandidateSet_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } return o; } -static void __pyx_tp_dealloc_5_cdec_Candidate(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec_CandidateSet(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } (*Py_TYPE(o)->tp_free)(o); } - -static PyObject *__pyx_getprop_5_cdec_9Candidate_words(PyObject *o, void *x) { - return __pyx_pw_5_cdec_9Candidate_5words_1__get__(o); -} - -static PyObject *__pyx_getprop_5_cdec_9Candidate_fmap(PyObject *o, void *x) { - return __pyx_pw_5_cdec_9Candidate_4fmap_1__get__(o); -} - -static PyObject *__pyx_getprop_5_cdec_9Candidate_score(PyObject *o, void *x) { - return __pyx_pw_5_cdec_9Candidate_5score_1__get__(o); -} - -static int __pyx_setprop_5_cdec_9Candidate_score(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_5_cdec_9Candidate_5score_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } +static PyObject *__pyx_sq_item_5_cdec_CandidateSet(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; } -static PyMethodDef __pyx_methods_5_cdec_Candidate[] = { +static PyMethodDef __pyx_methods_5_cdec_CandidateSet[] = { + {__Pyx_NAMESTR("add_kbest"), (PyCFunction)__pyx_pw_5_cdec_12CandidateSet_12add_kbest, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; -static struct PyGetSetDef __pyx_getsets_5_cdec_Candidate[] = { - {(char *)"words", __pyx_getprop_5_cdec_9Candidate_words, 0, 0, 0}, - {(char *)"fmap", __pyx_getprop_5_cdec_9Candidate_fmap, 0, 0, 0}, - {(char *)"score", __pyx_getprop_5_cdec_9Candidate_score, __pyx_setprop_5_cdec_9Candidate_score, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_Candidate = { +static PyNumberMethods __pyx_tp_as_number_CandidateSet = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -15528,11 +19478,11 @@ static PyNumberMethods __pyx_tp_as_number_Candidate = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Candidate = { - 0, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence_CandidateSet = { + __pyx_pw_5_cdec_12CandidateSet_5__len__, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - 0, /*sq_item*/ + __pyx_sq_item_5_cdec_CandidateSet, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -15541,13 +19491,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Candidate = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Candidate = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping_CandidateSet = { + __pyx_pw_5_cdec_12CandidateSet_5__len__, /*mp_length*/ + __pyx_pw_5_cdec_12CandidateSet_7__getitem__, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Candidate = { +static PyBufferProcs __pyx_tp_as_buffer_CandidateSet = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -15568,12 +19518,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Candidate = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Candidate = { +static PyTypeObject __pyx_type_5_cdec_CandidateSet = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Candidate"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Candidate), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.CandidateSet"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_CandidateSet), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Candidate, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_CandidateSet, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -15583,26 +19533,26 @@ static PyTypeObject __pyx_type_5_cdec_Candidate = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Candidate, /*tp_as_number*/ - &__pyx_tp_as_sequence_Candidate, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Candidate, /*tp_as_mapping*/ + &__pyx_tp_as_number_CandidateSet, /*tp_as_number*/ + &__pyx_tp_as_sequence_CandidateSet, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_CandidateSet, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Candidate, /*tp_as_buffer*/ + &__pyx_tp_as_buffer_CandidateSet, /*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*/ - 0, /*tp_iter*/ + __pyx_pw_5_cdec_12CandidateSet_9__iter__, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Candidate, /*tp_methods*/ + __pyx_methods_5_cdec_CandidateSet, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_5_cdec_Candidate, /*tp_getset*/ + 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -15610,7 +19560,7 @@ static PyTypeObject __pyx_type_5_cdec_Candidate = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Candidate, /*tp_new*/ + __pyx_tp_new_5_cdec_CandidateSet, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -15624,18 +19574,18 @@ static PyTypeObject __pyx_type_5_cdec_Candidate = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_SufficientStats(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_SegmentEvaluator(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_SufficientStats(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec_SegmentEvaluator(PyObject *o) { { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); - __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(o); + __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); @@ -15643,26 +19593,14 @@ static void __pyx_tp_dealloc_5_cdec_SufficientStats(PyObject *o) { (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_getprop_5_cdec_15SufficientStats_score(PyObject *o, void *x) { - return __pyx_pw_5_cdec_15SufficientStats_5score_1__get__(o); -} - -static PyObject *__pyx_getprop_5_cdec_15SufficientStats_detail(PyObject *o, void *x) { - return __pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(o); -} - -static PyMethodDef __pyx_methods_5_cdec_SufficientStats[] = { +static PyMethodDef __pyx_methods_5_cdec_SegmentEvaluator[] = { + {__Pyx_NAMESTR("evaluate"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("candidate_set"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set, METH_NOARGS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; -static struct PyGetSetDef __pyx_getsets_5_cdec_SufficientStats[] = { - {(char *)"score", __pyx_getprop_5_cdec_15SufficientStats_score, 0, 0, 0}, - {(char *)"detail", __pyx_getprop_5_cdec_15SufficientStats_detail, 0, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_SufficientStats = { - __pyx_pw_5_cdec_15SufficientStats_10__add__, /*nb_add*/ +static PyNumberMethods __pyx_tp_as_number_SegmentEvaluator = { + 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 @@ -15697,7 +19635,7 @@ static PyNumberMethods __pyx_tp_as_number_SufficientStats = { #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif - __pyx_pw_5_cdec_15SufficientStats_8__iadd__, /*nb_inplace_add*/ + 0, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 @@ -15719,8 +19657,8 @@ static PyNumberMethods __pyx_tp_as_number_SufficientStats = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_SufficientStats = { - __pyx_pw_5_cdec_15SufficientStats_3__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence_SegmentEvaluator = { + 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ 0, /*sq_item*/ @@ -15732,13 +19670,13 @@ static PySequenceMethods __pyx_tp_as_sequence_SufficientStats = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_SufficientStats = { - __pyx_pw_5_cdec_15SufficientStats_3__len__, /*mp_length*/ +static PyMappingMethods __pyx_tp_as_mapping_SegmentEvaluator = { + 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_SufficientStats = { +static PyBufferProcs __pyx_tp_as_buffer_SegmentEvaluator = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -15759,12 +19697,12 @@ static PyBufferProcs __pyx_tp_as_buffer_SufficientStats = { #endif }; -static PyTypeObject __pyx_type_5_cdec_SufficientStats = { +static PyTypeObject __pyx_type_5_cdec_SegmentEvaluator = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.SufficientStats"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_SufficientStats), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.SegmentEvaluator"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_SegmentEvaluator), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_SufficientStats, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_SegmentEvaluator, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -15774,26 +19712,26 @@ static PyTypeObject __pyx_type_5_cdec_SufficientStats = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_SufficientStats, /*tp_as_number*/ - &__pyx_tp_as_sequence_SufficientStats, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_SufficientStats, /*tp_as_mapping*/ + &__pyx_tp_as_number_SegmentEvaluator, /*tp_as_number*/ + &__pyx_tp_as_sequence_SegmentEvaluator, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_SegmentEvaluator, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_SufficientStats, /*tp_as_buffer*/ + &__pyx_tp_as_buffer_SegmentEvaluator, /*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_pw_5_cdec_15SufficientStats_5__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_SufficientStats, /*tp_methods*/ + __pyx_methods_5_cdec_SegmentEvaluator, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_5_cdec_SufficientStats, /*tp_getset*/ + 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -15801,7 +19739,7 @@ static PyTypeObject __pyx_type_5_cdec_SufficientStats = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_SufficientStats, /*tp_new*/ + __pyx_tp_new_5_cdec_SegmentEvaluator, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -15815,41 +19753,33 @@ static PyTypeObject __pyx_type_5_cdec_SufficientStats = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_CandidateSet(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_Scorer(PyTypeObject *t, PyObject *a, PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - if (__pyx_pw_5_cdec_12CandidateSet_1__cinit__(o, a, k) < 0) { + if (__pyx_pw_5_cdec_6Scorer_1__cinit__(o, a, k) < 0) { Py_DECREF(o); o = 0; } return o; } -static void __pyx_tp_dealloc_5_cdec_CandidateSet(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec_Scorer(PyObject *o) { { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); - __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(o); + __pyx_pw_5_cdec_6Scorer_3__dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); } (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_sq_item_5_cdec_CandidateSet(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} -static PyMethodDef __pyx_methods_5_cdec_CandidateSet[] = { - {__Pyx_NAMESTR("add_kbest"), (PyCFunction)__pyx_pw_5_cdec_12CandidateSet_12add_kbest, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, +static PyMethodDef __pyx_methods_5_cdec_Scorer[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_CandidateSet = { +static PyNumberMethods __pyx_tp_as_number_Scorer = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -15907,11 +19837,11 @@ static PyNumberMethods __pyx_tp_as_number_CandidateSet = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_CandidateSet = { - __pyx_pw_5_cdec_12CandidateSet_5__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence_Scorer = { + 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_CandidateSet, /*sq_item*/ + 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -15920,13 +19850,13 @@ static PySequenceMethods __pyx_tp_as_sequence_CandidateSet = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_CandidateSet = { - __pyx_pw_5_cdec_12CandidateSet_5__len__, /*mp_length*/ - __pyx_pw_5_cdec_12CandidateSet_7__getitem__, /*mp_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping_Scorer = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_CandidateSet = { +static PyBufferProcs __pyx_tp_as_buffer_Scorer = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -15947,12 +19877,12 @@ static PyBufferProcs __pyx_tp_as_buffer_CandidateSet = { #endif }; -static PyTypeObject __pyx_type_5_cdec_CandidateSet = { +static PyTypeObject __pyx_type_5_cdec_Scorer = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.CandidateSet"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_CandidateSet), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.Scorer"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Scorer), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_CandidateSet, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_Scorer, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -15962,24 +19892,24 @@ static PyTypeObject __pyx_type_5_cdec_CandidateSet = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_CandidateSet, /*tp_as_number*/ - &__pyx_tp_as_sequence_CandidateSet, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_CandidateSet, /*tp_as_mapping*/ + &__pyx_tp_as_number_Scorer, /*tp_as_number*/ + &__pyx_tp_as_sequence_Scorer, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Scorer, /*tp_as_mapping*/ 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ + __pyx_pw_5_cdec_6Scorer_5__call__, /*tp_call*/ + __pyx_pw_5_cdec_6Scorer_7__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_CandidateSet, /*tp_as_buffer*/ + &__pyx_tp_as_buffer_Scorer, /*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_pw_5_cdec_12CandidateSet_9__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_CandidateSet, /*tp_methods*/ + __pyx_methods_5_cdec_Scorer, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -15989,7 +19919,7 @@ static PyTypeObject __pyx_type_5_cdec_CandidateSet = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_CandidateSet, /*tp_new*/ + __pyx_tp_new_5_cdec_Scorer, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -16003,32 +19933,82 @@ static PyTypeObject __pyx_type_5_cdec_CandidateSet = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_SegmentEvaluator(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_Decoder(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec_Decoder *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + p = ((struct __pyx_obj_5_cdec_Decoder *)o); + p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_5_cdec_7Decoder_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } return o; } -static void __pyx_tp_dealloc_5_cdec_SegmentEvaluator(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec_Decoder(PyObject *o) { + struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); - __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(o); + __pyx_pw_5_cdec_7Decoder_3__dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); } + Py_XDECREF(((PyObject *)p->weights)); (*Py_TYPE(o)->tp_free)(o); } -static PyMethodDef __pyx_methods_5_cdec_SegmentEvaluator[] = { - {__Pyx_NAMESTR("evaluate"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("candidate_set"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set, METH_NOARGS, __Pyx_DOCSTR(0)}, +static int __pyx_tp_traverse_5_cdec_Decoder(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; + if (p->weights) { + e = (*v)(((PyObject*)p->weights), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5_cdec_Decoder(PyObject *o) { + struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; + PyObject* tmp; + tmp = ((PyObject*)p->weights); + p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_5_cdec_7Decoder_weights(PyObject *o, void *x) { + return __pyx_pw_5_cdec_7Decoder_7weights_1__get__(o); +} + +static int __pyx_setprop_5_cdec_7Decoder_weights(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_7Decoder_7weights_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_5_cdec_7Decoder_formalism(PyObject *o, void *x) { + return __pyx_pw_5_cdec_7Decoder_9formalism_1__get__(o); +} + +static PyMethodDef __pyx_methods_5_cdec_Decoder[] = { + {__Pyx_NAMESTR("read_weights"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_5read_weights, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("translate"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_7translate, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_SegmentEvaluator = { +static struct PyGetSetDef __pyx_getsets_5_cdec_Decoder[] = { + {(char *)"weights", __pyx_getprop_5_cdec_7Decoder_weights, __pyx_setprop_5_cdec_7Decoder_weights, 0, 0}, + {(char *)"formalism", __pyx_getprop_5_cdec_7Decoder_formalism, 0, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Decoder = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -16086,7 +20066,7 @@ static PyNumberMethods __pyx_tp_as_number_SegmentEvaluator = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_SegmentEvaluator = { +static PySequenceMethods __pyx_tp_as_sequence_Decoder = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -16099,13 +20079,13 @@ static PySequenceMethods __pyx_tp_as_sequence_SegmentEvaluator = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_SegmentEvaluator = { +static PyMappingMethods __pyx_tp_as_mapping_Decoder = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_SegmentEvaluator = { +static PyBufferProcs __pyx_tp_as_buffer_Decoder = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -16126,12 +20106,12 @@ static PyBufferProcs __pyx_tp_as_buffer_SegmentEvaluator = { #endif }; -static PyTypeObject __pyx_type_5_cdec_SegmentEvaluator = { +static PyTypeObject __pyx_type_5_cdec_Decoder = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.SegmentEvaluator"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_SegmentEvaluator), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.Decoder"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Decoder), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_SegmentEvaluator, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_Decoder, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -16141,26 +20121,26 @@ static PyTypeObject __pyx_type_5_cdec_SegmentEvaluator = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_SegmentEvaluator, /*tp_as_number*/ - &__pyx_tp_as_sequence_SegmentEvaluator, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_SegmentEvaluator, /*tp_as_mapping*/ + &__pyx_tp_as_number_Decoder, /*tp_as_number*/ + &__pyx_tp_as_sequence_Decoder, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Decoder, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_SegmentEvaluator, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer_Decoder, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec_Decoder, /*tp_traverse*/ + __pyx_tp_clear_5_cdec_Decoder, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_SegmentEvaluator, /*tp_methods*/ + __pyx_methods_5_cdec_Decoder, /*tp_methods*/ 0, /*tp_members*/ - 0, /*tp_getset*/ + __pyx_getsets_5_cdec_Decoder, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -16168,7 +20148,7 @@ static PyTypeObject __pyx_type_5_cdec_SegmentEvaluator = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_SegmentEvaluator, /*tp_new*/ + __pyx_tp_new_5_cdec_Decoder, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -16182,33 +20162,44 @@ static PyTypeObject __pyx_type_5_cdec_SegmentEvaluator = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Scorer(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct____iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - if (__pyx_pw_5_cdec_6Scorer_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o); + p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec_Scorer(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_6Scorer_3__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static PyMethodDef __pyx_methods_5_cdec_Scorer[] = { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct____iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_Scorer = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -16266,7 +20257,7 @@ static PyNumberMethods __pyx_tp_as_number_Scorer = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Scorer = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct____iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -16279,13 +20270,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Scorer = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Scorer = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct____iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Scorer = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -16306,12 +20297,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Scorer = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Scorer = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Scorer"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Scorer), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct____iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct____iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Scorer, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -16321,24 +20312,24 @@ static PyTypeObject __pyx_type_5_cdec_Scorer = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Scorer, /*tp_as_number*/ - &__pyx_tp_as_sequence_Scorer, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Scorer, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct____iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct____iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct____iter__, /*tp_as_mapping*/ 0, /*tp_hash*/ - __pyx_pw_5_cdec_6Scorer_5__call__, /*tp_call*/ - __pyx_pw_5_cdec_6Scorer_7__str__, /*tp_str*/ + 0, /*tp_call*/ + 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Scorer, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct____iter__, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Scorer, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct____iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -16348,7 +20339,7 @@ static PyTypeObject __pyx_type_5_cdec_Scorer = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Scorer, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct____iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -16362,82 +20353,44 @@ static PyTypeObject __pyx_type_5_cdec_Scorer = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Decoder(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec_Decoder *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec_Decoder *)o); - p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); - if (__pyx_pw_5_cdec_7Decoder_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o); + p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec_Decoder(PyObject *o) { - struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_7Decoder_3__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - Py_XDECREF(((PyObject *)p->weights)); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec_Decoder(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; - if (p->weights) { - e = (*v)(((PyObject*)p->weights), a); if (e) return e; + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec_Decoder(PyObject *o) { - struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; PyObject* tmp; - tmp = ((PyObject*)p->weights); - p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyObject *__pyx_getprop_5_cdec_7Decoder_weights(PyObject *o, void *x) { - return __pyx_pw_5_cdec_7Decoder_7weights_1__get__(o); -} - -static int __pyx_setprop_5_cdec_7Decoder_weights(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_5_cdec_7Decoder_7weights_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} - -static PyObject *__pyx_getprop_5_cdec_7Decoder_formalism(PyObject *o, void *x) { - return __pyx_pw_5_cdec_7Decoder_9formalism_1__get__(o); -} - -static PyMethodDef __pyx_methods_5_cdec_Decoder[] = { - {__Pyx_NAMESTR("read_weights"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_5read_weights, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("translate"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_7translate, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_1___iter__[] = { {0, 0, 0, 0} }; -static struct PyGetSetDef __pyx_getsets_5_cdec_Decoder[] = { - {(char *)"weights", __pyx_getprop_5_cdec_7Decoder_weights, __pyx_setprop_5_cdec_7Decoder_weights, 0, 0}, - {(char *)"formalism", __pyx_getprop_5_cdec_7Decoder_formalism, 0, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_Decoder = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -16495,7 +20448,7 @@ static PyNumberMethods __pyx_tp_as_number_Decoder = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Decoder = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -16508,13 +20461,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Decoder = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Decoder = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Decoder = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -16535,12 +20488,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Decoder = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Decoder = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Decoder"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Decoder), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_1___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Decoder, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -16550,26 +20503,26 @@ static PyTypeObject __pyx_type_5_cdec_Decoder = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Decoder, /*tp_as_number*/ - &__pyx_tp_as_sequence_Decoder, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Decoder, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_1___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_1___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_1___iter__, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Decoder, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct_1___iter__, /*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_Decoder, /*tp_traverse*/ - __pyx_tp_clear_5_cdec_Decoder, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Decoder, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_1___iter__, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_5_cdec_Decoder, /*tp_getset*/ + 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -16577,7 +20530,7 @@ static PyTypeObject __pyx_type_5_cdec_Decoder = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Decoder, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -16591,44 +20544,44 @@ static PyTypeObject __pyx_type_5_cdec_Decoder = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct____iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_2__phrase(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o); - p->__pyx_v_self = 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase *)o); + p->__pyx_v_phrase = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; - Py_XDECREF(((PyObject *)p->__pyx_v_self)); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2__phrase(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase *)o; + Py_XDECREF(p->__pyx_v_phrase); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_2__phrase(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; - if (p->__pyx_v_self) { - e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase *)o; + if (p->__pyx_v_phrase) { + e = (*v)(p->__pyx_v_phrase, a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_2__phrase(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_phrase); + p->__pyx_v_phrase = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct____iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_2__phrase[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2__phrase = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -16686,7 +20639,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct____iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2__phrase = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -16699,13 +20652,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct____iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct____iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_2__phrase = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2__phrase = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -16726,12 +20679,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2__phrase = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct____iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct____iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_2__phrase"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2__phrase, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -16741,24 +20694,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct____iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct____iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct____iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_2__phrase, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_2__phrase, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_2__phrase, /*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____iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_2__phrase, /*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____iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_2__phrase, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_2__phrase, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct____iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_2__phrase, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -16768,7 +20721,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct____iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_2__phrase, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -16782,44 +20735,60 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_3_genexpr(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o); - p->__pyx_v_self = 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr *)o); + p->__pyx_outer_scope = 0; + p->__pyx_v_w = 0; + p->__pyx_t_0 = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; - Py_XDECREF(((PyObject *)p->__pyx_v_self)); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_genexpr(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr *)o; + Py_XDECREF(((PyObject *)p->__pyx_outer_scope)); + Py_XDECREF(p->__pyx_v_w); + Py_XDECREF(p->__pyx_t_0); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_genexpr(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; - if (p->__pyx_v_self) { - e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr *)o; + if (p->__pyx_outer_scope) { + e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e; + } + if (p->__pyx_v_w) { + e = (*v)(p->__pyx_v_w, a); if (e) return e; + } + if (p->__pyx_t_0) { + e = (*v)(p->__pyx_t_0, a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_3_genexpr(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_outer_scope); + p->__pyx_outer_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_w); + p->__pyx_v_w = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_0); + p->__pyx_t_0 = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_1___iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_3_genexpr[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_genexpr = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -16877,7 +20846,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1___iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_genexpr = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -16890,13 +20859,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1___iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1___iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_3_genexpr = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_genexpr = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -16917,12 +20886,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_genexpr = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_1___iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_3_genexpr"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_genexpr, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -16932,24 +20901,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_1___iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_1___iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_1___iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_3_genexpr, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_3_genexpr, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_3_genexpr, /*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___iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_3_genexpr, /*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___iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_genexpr, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_3_genexpr, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_1___iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_3_genexpr, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -16959,7 +20928,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_3_genexpr, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -16973,52 +20942,44 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_4___get__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ *)o); p->__pyx_v_self = 0; - p->__pyx_v_size = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_4___get__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ *)o; 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; - } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_4___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_BaseTRule *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_2_kbest[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_4___get__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4___get__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -17076,7 +21037,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4___get__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -17089,13 +21050,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_2_kbest = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_4___get__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4___get__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -17116,12 +21077,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4___get__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_2_kbest"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_4___get__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4___get__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -17131,24 +21092,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_2_kbest, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_2_kbest, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_2_kbest, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_4___get__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_4___get__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_4___get__, /*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, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_4___get__, /*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, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_4___get__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_4___get__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_2_kbest, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_4___get__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -17158,7 +21119,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_4___get__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -17172,68 +21133,44 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_trees(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_5___str__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *)o); - p->__pyx_v_e_tree = 0; - p->__pyx_v_f_tree = 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ *)o); p->__pyx_v_self = 0; - p->__pyx_v_size = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_kbest_trees(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *)o; - Py_XDECREF(((PyObject *)p->__pyx_v_e_tree)); - Py_XDECREF(((PyObject *)p->__pyx_v_f_tree)); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5___str__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_kbest_trees(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_5___str__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *)o; - if (p->__pyx_v_e_tree) { - e = (*v)(p->__pyx_v_e_tree, a); if (e) return e; - } - if (p->__pyx_v_f_tree) { - e = (*v)(p->__pyx_v_f_tree, a); if (e) return e; - } + struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ *)o; 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; - } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_3_kbest_trees(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_5___str__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_e_tree); - p->__pyx_v_e_tree = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_f_tree); - p->__pyx_v_f_tree = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_BaseTRule *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_3_kbest_trees[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_5___str__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_kbest_trees = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_5___str__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -17291,7 +21228,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_kbest_trees = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_kbest_trees = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_5___str__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -17304,13 +21241,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_kbest_trees = 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_3_kbest_trees = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_5___str__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_kbest_trees = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_5___str__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -17331,12 +21268,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_kbest_trees = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_trees = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5___str__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_3_kbest_trees"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_trees), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_5___str__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_kbest_trees, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5___str__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -17346,24 +21283,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_trees = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_3_kbest_trees, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_3_kbest_trees, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_3_kbest_trees, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_5___str__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_5___str__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_5___str__, /*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_kbest_trees, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_5___str__, /*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_kbest_trees, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_3_kbest_trees, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_5___str__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_5___str__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_3_kbest_trees, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_5___str__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -17373,7 +21310,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_trees = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_trees, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_5___str__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -17387,60 +21324,60 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_trees = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_4_kbest_features(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_6_genexpr(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o); - p->__pyx_v_fmap = 0; - p->__pyx_v_self = 0; - p->__pyx_v_size = 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr *)o); + p->__pyx_outer_scope = 0; + p->__pyx_v_feat = 0; + p->__pyx_t_0 = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; - Py_XDECREF(((PyObject *)p->__pyx_v_fmap)); - Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(p->__pyx_v_size); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_6_genexpr(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr *)o; + Py_XDECREF(((PyObject *)p->__pyx_outer_scope)); + Py_XDECREF(p->__pyx_v_feat); + Py_XDECREF(p->__pyx_t_0); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_6_genexpr(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; - if (p->__pyx_v_fmap) { - e = (*v)(((PyObject*)p->__pyx_v_fmap), a); if (e) return e; + struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr *)o; + if (p->__pyx_outer_scope) { + e = (*v)(((PyObject*)p->__pyx_outer_scope), 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_feat) { + e = (*v)(p->__pyx_v_feat, a); if (e) return e; } - if (p->__pyx_v_size) { - e = (*v)(p->__pyx_v_size, a); if (e) return e; + if (p->__pyx_t_0) { + e = (*v)(p->__pyx_t_0, a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_6_genexpr(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_fmap); - p->__pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_outer_scope); + p->__pyx_outer_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_feat); + p->__pyx_v_feat = 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); + tmp = ((PyObject*)p->__pyx_t_0); + p->__pyx_t_0 = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_4_kbest_features[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_6_genexpr[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4_kbest_features = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_6_genexpr = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -17498,7 +21435,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4_kbest_features = #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4_kbest_features = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_6_genexpr = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -17511,13 +21448,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4_kbest_feature 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_4_kbest_features = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_6_genexpr = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4_kbest_features = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_6_genexpr = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -17538,12 +21475,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4_kbest_features = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_kbest_features = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_6_genexpr = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_4_kbest_features"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_6_genexpr"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_6_genexpr, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -17553,24 +21490,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_kbest_features = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_4_kbest_features, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_4_kbest_features, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_4_kbest_features, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_6_genexpr, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_6_genexpr, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_6_genexpr, /*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_4_kbest_features, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_6_genexpr, /*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_4_kbest_features, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_6_genexpr, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_6_genexpr, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_6_genexpr, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -17580,7 +21517,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_kbest_features = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_6_genexpr, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -17594,44 +21531,52 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_kbest_features = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_5_sample(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_7___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)o); p->__pyx_v_self = 0; + p->__pyx_v_trule = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5_sample(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_7___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(((PyObject *)p->__pyx_v_trule)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_5_sample(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_7___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } + if (p->__pyx_v_trule) { + e = (*v)(((PyObject*)p->__pyx_v_trule), a); if (e) return e; + } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_5_sample(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_7___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Grammar *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_trule); + p->__pyx_v_trule = ((struct __pyx_obj_5_cdec_TRule *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_5_sample[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_7___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_5_sample = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_7___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -17689,7 +21634,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_5_sample = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_5_sample = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_7___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -17702,13 +21647,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_5_sample = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_5_sample = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_7___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_5_sample = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_7___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -17729,12 +21674,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_5_sample = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5_sample = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_5_sample"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_7___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5_sample, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_7___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -17744,24 +21689,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5_sample = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_5_sample, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_5_sample, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_5_sample, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_7___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_7___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_7___iter__, /*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_5_sample, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_7___iter__, /*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_5_sample, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_5_sample, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_7___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_7___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_5_sample, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_7___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -17771,7 +21716,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5_sample = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_5_sample, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_7___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -17785,44 +21730,52 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5_sample = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_6___get__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_8_kbest(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8_kbest *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8_kbest *)o); p->__pyx_v_self = 0; + p->__pyx_v_size = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_6___get__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8_kbest(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_kbest *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_6___get__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_8_kbest(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_8_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_kbest *)o; 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; + } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_6___get__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_8_kbest(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_kbest *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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_6___get__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_8_kbest[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_6___get__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_8_kbest = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -17880,7 +21833,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_6___get__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_6___get__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_8_kbest = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -17893,13 +21846,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_6___get__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_6___get__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_8_kbest = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_6___get__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_8_kbest = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -17920,12 +21873,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_6___get__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_6___get__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8_kbest = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_6___get__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_6___get__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_8_kbest"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_8_kbest), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_6___get__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8_kbest, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -17935,24 +21888,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_6___get__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_6___get__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_6___get__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_6___get__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_8_kbest, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_8_kbest, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_8_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_6___get__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_8_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_6___get__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_6___get__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_8_kbest, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_8_kbest, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_6___get__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_8_kbest, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -17962,7 +21915,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_6___get__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_6___get__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_8_kbest, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -17976,44 +21929,68 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_6___get__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_7___get__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_9_kbest_trees(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_9_kbest_trees *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_9_kbest_trees *)o); + p->__pyx_v_e_tree = 0; + p->__pyx_v_f_tree = 0; p->__pyx_v_self = 0; + p->__pyx_v_size = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_7___get__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_9_kbest_trees(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_9_kbest_trees *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_9_kbest_trees *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_e_tree)); + Py_XDECREF(((PyObject *)p->__pyx_v_f_tree)); Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_7___get__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_9_kbest_trees(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_9_kbest_trees *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_9_kbest_trees *)o; + if (p->__pyx_v_e_tree) { + e = (*v)(p->__pyx_v_e_tree, a); if (e) return e; + } + if (p->__pyx_v_f_tree) { + e = (*v)(p->__pyx_v_f_tree, 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; + } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_7___get__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_9_kbest_trees(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_9_kbest_trees *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_9_kbest_trees *)o; PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_e_tree); + p->__pyx_v_e_tree = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_f_tree); + p->__pyx_v_f_tree = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_self); p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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_7___get__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_9_kbest_trees[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_7___get__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_9_kbest_trees = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -18071,7 +22048,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_7___get__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_7___get__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_9_kbest_trees = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -18084,13 +22061,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_7___get__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_7___get__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_9_kbest_trees = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_7___get__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_9_kbest_trees = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -18111,12 +22088,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_7___get__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7___get__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_9_kbest_trees = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_7___get__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_7___get__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_9_kbest_trees"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_9_kbest_trees), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_7___get__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_9_kbest_trees, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -18126,24 +22103,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7___get__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_7___get__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_7___get__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_7___get__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_9_kbest_trees, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_9_kbest_trees, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_9_kbest_trees, /*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_7___get__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_9_kbest_trees, /*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_7___get__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_7___get__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_9_kbest_trees, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_9_kbest_trees, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_7___get__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_9_kbest_trees, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -18153,7 +22130,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7___get__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_7___get__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_9_kbest_trees, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -18167,44 +22144,60 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7___get__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_8__phrase(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_10_kbest_features(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_10_kbest_features *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *)o); - p->__pyx_v_phrase = 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_10_kbest_features *)o); + p->__pyx_v_fmap = 0; + p->__pyx_v_self = 0; + p->__pyx_v_size = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8__phrase(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *)o; - Py_XDECREF(p->__pyx_v_phrase); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_10_kbest_features(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_10_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_10_kbest_features *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_fmap)); + Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_8__phrase(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_10_kbest_features(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *)o; - if (p->__pyx_v_phrase) { - e = (*v)(p->__pyx_v_phrase, a); if (e) return e; + struct __pyx_obj_5_cdec___pyx_scope_struct_10_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_10_kbest_features *)o; + if (p->__pyx_v_fmap) { + e = (*v)(((PyObject*)p->__pyx_v_fmap), 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; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_8__phrase(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_10_kbest_features(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_10_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_10_kbest_features *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_phrase); - p->__pyx_v_phrase = Py_None; Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_fmap); + p->__pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)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_8__phrase[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_10_kbest_features[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_8__phrase = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_10_kbest_features = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -18262,7 +22255,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_8__phrase = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_8__phrase = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_10_kbest_features = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -18275,13 +22268,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_8__phrase = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_8__phrase = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_10_kbest_features = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_8__phrase = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_10_kbest_features = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -18302,12 +22295,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_8__phrase = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8__phrase = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_10_kbest_features = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_8__phrase"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_10_kbest_features"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_10_kbest_features), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8__phrase, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_10_kbest_features, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -18317,24 +22310,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8__phrase = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_8__phrase, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_8__phrase, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_8__phrase, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_10_kbest_features, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_10_kbest_features, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_10_kbest_features, /*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_8__phrase, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_10_kbest_features, /*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_8__phrase, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_8__phrase, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_10_kbest_features, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_10_kbest_features, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_8__phrase, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_10_kbest_features, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -18344,7 +22337,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8__phrase = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_8__phrase, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_10_kbest_features, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -18358,60 +22351,44 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8__phrase = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_9_genexpr(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_11_sample(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *)o); - p->__pyx_outer_scope = 0; - p->__pyx_v_w = 0; - p->__pyx_t_0 = 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample *)o); + p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_9_genexpr(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *)o; - Py_XDECREF(((PyObject *)p->__pyx_outer_scope)); - Py_XDECREF(p->__pyx_v_w); - Py_XDECREF(p->__pyx_t_0); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_11_sample(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_9_genexpr(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_11_sample(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *)o; - if (p->__pyx_outer_scope) { - e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e; - } - if (p->__pyx_v_w) { - e = (*v)(p->__pyx_v_w, a); if (e) return e; - } - if (p->__pyx_t_0) { - e = (*v)(p->__pyx_t_0, a); if (e) return e; + struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_9_genexpr(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_11_sample(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_outer_scope); - p->__pyx_outer_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8__phrase *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_w); - p->__pyx_v_w = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_t_0); - p->__pyx_t_0 = Py_None; Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_9_genexpr[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_11_sample[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_9_genexpr = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_11_sample = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -18469,7 +22446,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_9_genexpr = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_9_genexpr = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_11_sample = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -18482,13 +22459,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_9_genexpr = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_9_genexpr = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_11_sample = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_9_genexpr = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_11_sample = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -18509,12 +22486,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_9_genexpr = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_9_genexpr = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_11_sample = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_9_genexpr"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_9_genexpr), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_11_sample"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_9_genexpr, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_11_sample, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -18524,24 +22501,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_9_genexpr = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_9_genexpr, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_9_genexpr, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_9_genexpr, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_11_sample, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_11_sample, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_11_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_9_genexpr, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_11_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_9_genexpr, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_9_genexpr, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_11_sample, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_11_sample, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_9_genexpr, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_11_sample, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -18551,7 +22528,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_9_genexpr = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_9_genexpr, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_11_sample, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -18565,44 +22542,44 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_9_genexpr = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_10___str__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_12___get__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *)o); p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_10___str__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_12___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_10___str__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_12___get__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_10___str__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_12___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_TRule *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_10___str__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_12___get__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_10___str__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_12___get__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -18660,7 +22637,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_10___str__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_10___str__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_12___get__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -18673,13 +22650,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_10___str__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_10___str__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_12___get__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_10___str__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_12___get__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -18700,12 +22677,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_10___str__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_10___str__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_12___get__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_10___str__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_12___get__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_10___str__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_12___get__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -18715,24 +22692,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_10___str__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_10___str__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_10___str__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_10___str__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_12___get__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_12___get__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_12___get__, /*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_10___str__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_12___get__, /*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_10___str__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_10___str__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_12___get__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_12___get__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_10___str__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_12___get__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -18742,7 +22719,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_10___str__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_10___str__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_12___get__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -18756,60 +22733,44 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_10___str__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_11_genexpr(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_13___get__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *)o); - p->__pyx_outer_scope = 0; - p->__pyx_v_feat = 0; - p->__pyx_t_0 = 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *)o); + p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_11_genexpr(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *)o; - Py_XDECREF(((PyObject *)p->__pyx_outer_scope)); - Py_XDECREF(p->__pyx_v_feat); - Py_XDECREF(p->__pyx_t_0); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_13___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_11_genexpr(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_13___get__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *)o; - if (p->__pyx_outer_scope) { - e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e; - } - if (p->__pyx_v_feat) { - e = (*v)(p->__pyx_v_feat, a); if (e) return e; - } - if (p->__pyx_t_0) { - e = (*v)(p->__pyx_t_0, a); if (e) return e; + struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_11_genexpr(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_13___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_outer_scope); - p->__pyx_outer_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_10___str__ *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_feat); - p->__pyx_v_feat = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_t_0); - p->__pyx_t_0 = Py_None; Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_11_genexpr[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_13___get__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_11_genexpr = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_13___get__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -18867,7 +22828,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_11_genexpr = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_11_genexpr = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_13___get__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -18880,13 +22841,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_11_genexpr = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_11_genexpr = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_13___get__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_11_genexpr = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_13___get__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -18907,12 +22868,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_11_genexpr = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_11_genexpr = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_13___get__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_11_genexpr"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_11_genexpr), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_13___get__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_11_genexpr, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_13___get__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -18922,24 +22883,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_11_genexpr = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_11_genexpr, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_11_genexpr, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_11_genexpr, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_13___get__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_13___get__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_13___get__, /*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_11_genexpr, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_13___get__, /*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_11_genexpr, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_11_genexpr, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_13___get__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_13___get__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_11_genexpr, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_13___get__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -18949,7 +22910,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_11_genexpr = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_11_genexpr, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_13___get__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -18963,32 +22924,32 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_11_genexpr = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_12___get__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_14___get__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *)o); p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_12___get__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_14___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_12___get__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_14___get__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_12___get__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_14___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); p->__pyx_v_self = ((struct __pyx_obj_5_cdec_HypergraphEdge *)Py_None); Py_INCREF(Py_None); @@ -18996,11 +22957,11 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_12___get__(PyObject *o) { return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_12___get__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_14___get__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_12___get__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_14___get__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -19058,7 +23019,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_12___get__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_12___get__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_14___get__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -19071,13 +23032,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_12___get__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_12___get__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_14___get__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_12___get__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_14___get__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -19098,12 +23059,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_12___get__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_12___get__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_14___get__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_12___get__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_14___get__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_12___get__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_14___get__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -19113,24 +23074,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_12___get__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_12___get__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_12___get__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_12___get__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_14___get__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_14___get__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_14___get__, /*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_12___get__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_14___get__, /*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_12___get__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_12___get__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_14___get__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_14___get__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_12___get__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_14___get__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -19140,7 +23101,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_12___get__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_12___get__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_14___get__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -19154,32 +23115,32 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_12___get__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_13___get__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_15___get__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__ *)o); p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_13___get__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_15___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_13___get__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_15___get__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__ *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_13___get__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_15___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); p->__pyx_v_self = ((struct __pyx_obj_5_cdec_HypergraphNode *)Py_None); Py_INCREF(Py_None); @@ -19187,11 +23148,11 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_13___get__(PyObject *o) { return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_13___get__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_15___get__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_13___get__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_15___get__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -19249,7 +23210,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_13___get__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_13___get__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_15___get__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -19262,13 +23223,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_13___get__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_13___get__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_15___get__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_13___get__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_15___get__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -19289,12 +23250,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_13___get__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_13___get__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_15___get__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_13___get__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_15___get__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_13___get__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_15___get__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -19304,24 +23265,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_13___get__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_13___get__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_13___get__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_13___get__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_15___get__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_15___get__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_15___get__, /*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_13___get__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_15___get__, /*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_13___get__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_13___get__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_15___get__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_15___get__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_13___get__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_15___get__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -19331,7 +23292,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_13___get__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_13___get__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_15___get__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -19345,32 +23306,32 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_13___get__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_14___get__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_16___get__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_16___get__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_16___get__ *)o); p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_14___get__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_16___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_16___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_16___get__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_14___get__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_16___get__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_16___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_16___get__ *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_14___get__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_16___get__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_16___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_16___get__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); p->__pyx_v_self = ((struct __pyx_obj_5_cdec_HypergraphNode *)Py_None); Py_INCREF(Py_None); @@ -19378,11 +23339,11 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_14___get__(PyObject *o) { return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_14___get__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_16___get__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_14___get__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_16___get__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -19440,7 +23401,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_14___get__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_14___get__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_16___get__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -19453,13 +23414,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_14___get__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_14___get__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_16___get__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_14___get__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_16___get__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -19480,12 +23441,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_14___get__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_14___get__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_16___get__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_14___get__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_16___get__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_16___get__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_14___get__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_16___get__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -19495,24 +23456,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_14___get__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_14___get__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_14___get__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_14___get__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_16___get__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_16___get__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_16___get__, /*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_14___get__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_16___get__, /*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_14___get__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_14___get__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_16___get__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_16___get__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_14___get__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_16___get__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -19522,7 +23483,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_14___get__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_14___get__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_16___get__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -19536,32 +23497,32 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_14___get__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_15___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_17___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__ *)o); p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_15___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_17___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_15___iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_17___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__ *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_15___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_17___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Lattice *)Py_None); Py_INCREF(Py_None); @@ -19569,11 +23530,11 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_15___iter__(PyObject *o) { return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_15___iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_17___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_15___iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_17___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -19631,7 +23592,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_15___iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_15___iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_17___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -19644,13 +23605,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_15___iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_15___iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_17___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_15___iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_17___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -19671,12 +23632,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_15___iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_15___iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_17___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_15___iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_15___iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_17___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_15___iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_17___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -19686,24 +23647,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_15___iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_15___iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_15___iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_15___iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_17___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_17___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_17___iter__, /*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_15___iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_17___iter__, /*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_15___iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_15___iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_17___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_17___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_15___iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_17___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -19713,7 +23674,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_15___iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_15___iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_17___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -19727,32 +23688,32 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_15___iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_16_todot(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_18_todot(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot *)o); p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_16_todot(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_18_todot(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_16_todot(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_18_todot(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_16_todot(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_18_todot(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Lattice *)Py_None); Py_INCREF(Py_None); @@ -19760,11 +23721,11 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_16_todot(PyObject *o) { return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_16_todot[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_18_todot[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_16_todot = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_18_todot = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -19822,7 +23783,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_16_todot = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_16_todot = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_18_todot = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -19835,13 +23796,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_16_todot = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_16_todot = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_18_todot = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_16_todot = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_18_todot = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -19862,12 +23823,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_16_todot = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_16_todot = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_18_todot = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_16_todot"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_18_todot"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_16_todot, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_18_todot, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -19877,24 +23838,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_16_todot = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_16_todot, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_16_todot, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_16_todot, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_18_todot, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_18_todot, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_18_todot, /*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_16_todot, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_18_todot, /*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_16_todot, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_16_todot, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_18_todot, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_18_todot, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_16_todot, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_18_todot, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -19904,7 +23865,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_16_todot = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_16_todot, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_18_todot, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -19918,11 +23879,11 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_16_todot = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_17_lines(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_19_lines(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_19_lines *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_19_lines *)o); p->__pyx_outer_scope = 0; p->__pyx_v_delta = 0; p->__pyx_v_i = 0; @@ -19933,8 +23894,8 @@ static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_17_lines(PyTypeObject *t return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_17_lines(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_19_lines(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_19_lines *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_19_lines *)o; Py_XDECREF(((PyObject *)p->__pyx_outer_scope)); Py_XDECREF(p->__pyx_v_delta); Py_XDECREF(p->__pyx_v_i); @@ -19945,9 +23906,9 @@ static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_17_lines(PyObject *o) { (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_17_lines(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_19_lines(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_19_lines *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_19_lines *)o; if (p->__pyx_outer_scope) { e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e; } @@ -19972,11 +23933,11 @@ static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_17_lines(PyObject *o, vis return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_17_lines(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_19_lines(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_19_lines *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_19_lines *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_outer_scope); - p->__pyx_outer_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_16_todot *)Py_None); Py_INCREF(Py_None); + p->__pyx_outer_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_delta); p->__pyx_v_delta = Py_None; Py_INCREF(Py_None); @@ -19999,11 +23960,11 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_17_lines(PyObject *o) { return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_17_lines[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_19_lines[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_17_lines = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_19_lines = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -20061,7 +24022,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_17_lines = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_17_lines = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_19_lines = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -20074,13 +24035,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_17_lines = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_17_lines = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_19_lines = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_17_lines = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_19_lines = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -20101,12 +24062,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_17_lines = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_17_lines = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_19_lines = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_17_lines"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_17_lines), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_19_lines"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_19_lines), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_17_lines, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_19_lines, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -20116,24 +24077,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_17_lines = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_17_lines, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_17_lines, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_17_lines, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_19_lines, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_19_lines, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_19_lines, /*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_17_lines, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_19_lines, /*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_17_lines, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_17_lines, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_19_lines, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_19_lines, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_17_lines, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_19_lines, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -20143,7 +24104,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_17_lines = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_17_lines, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_19_lines, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -20157,28 +24118,28 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_17_lines = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_18___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_20___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__ *)o); p->__pyx_v_i = 0; p->__pyx_v_self = 0; p->__pyx_t_1 = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_18___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_20___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__ *)o; Py_XDECREF(p->__pyx_v_i); Py_XDECREF(((PyObject *)p->__pyx_v_self)); Py_XDECREF(p->__pyx_t_1); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_18___iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_20___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__ *)o; if (p->__pyx_v_i) { e = (*v)(p->__pyx_v_i, a); if (e) return e; } @@ -20191,8 +24152,8 @@ static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_18___iter__(PyObject *o, return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_18___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_20___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_i); p->__pyx_v_i = Py_None; Py_INCREF(Py_None); @@ -20206,11 +24167,11 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_18___iter__(PyObject *o) { return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_18___iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_20___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_18___iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_20___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -20268,7 +24229,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_18___iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_18___iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_20___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -20281,13 +24242,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_18___iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_18___iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_20___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_18___iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_20___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -20308,12 +24269,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_18___iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_18___iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_20___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_18___iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_18___iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_20___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_18___iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_20___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -20323,24 +24284,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_18___iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_18___iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_18___iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_18___iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_20___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_20___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_20___iter__, /*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_18___iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_20___iter__, /*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_18___iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_18___iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_20___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_20___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_18___iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_20___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -20350,7 +24311,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_18___iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_18___iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_20___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -20364,32 +24325,32 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_18___iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_19___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_21___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__ *)o); p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_19___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_21___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_19___iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_21___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__ *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_19___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_21___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); p->__pyx_v_self = ((struct __pyx_obj_5_cdec_CandidateSet *)Py_None); Py_INCREF(Py_None); @@ -20397,11 +24358,11 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_19___iter__(PyObject *o) { return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_19___iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_21___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_19___iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_21___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -20459,7 +24420,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_19___iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_19___iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_21___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -20472,13 +24433,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_19___iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_19___iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_21___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_19___iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_21___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -20499,12 +24460,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_19___iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_19___iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_21___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_19___iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_19___iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_21___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_19___iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_21___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -20514,24 +24475,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_19___iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_19___iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_19___iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_19___iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_21___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_21___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_21___iter__, /*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_19___iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_21___iter__, /*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_19___iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_19___iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_21___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_21___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_19___iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_21___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -20541,7 +24502,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_19___iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_19___iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_21___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -20555,11 +24516,11 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_19___iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_20__make_config(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_22__make_config(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *)o); p->__pyx_v_config = 0; p->__pyx_v_info = 0; p->__pyx_v_key = 0; @@ -20570,8 +24531,8 @@ static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_20__make_config(PyTypeOb return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_20__make_config(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_22__make_config(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *)o; Py_XDECREF(p->__pyx_v_config); Py_XDECREF(p->__pyx_v_info); Py_XDECREF(p->__pyx_v_key); @@ -20582,9 +24543,9 @@ static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_20__make_config(PyObject (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_20__make_config(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_22__make_config(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *)o; if (p->__pyx_v_config) { e = (*v)(p->__pyx_v_config, a); if (e) return e; } @@ -20609,8 +24570,8 @@ static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_20__make_config(PyObject return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_20__make_config(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_22__make_config(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_config); p->__pyx_v_config = Py_None; Py_INCREF(Py_None); @@ -20636,11 +24597,11 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_20__make_config(PyObject *o) return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_20__make_config[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_22__make_config[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_20__make_config = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_22__make_config = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -20698,7 +24659,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_20__make_config = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_20__make_config = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_22__make_config = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -20711,13 +24672,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_20__make_config 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_20__make_config = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_22__make_config = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_20__make_config = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_22__make_config = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -20738,12 +24699,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_20__make_config = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_20__make_config = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_22__make_config = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_20__make_config"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_20__make_config), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_22__make_config"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_20__make_config, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_22__make_config, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -20753,24 +24714,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_20__make_config = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_20__make_config, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_20__make_config, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_20__make_config, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_22__make_config, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_22__make_config, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_22__make_config, /*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_20__make_config, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_22__make_config, /*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_20__make_config, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_20__make_config, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_22__make_config, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_22__make_config, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_20__make_config, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_22__make_config, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -20780,7 +24741,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_20__make_config = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_20__make_config, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_22__make_config, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -20794,32 +24755,32 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_20__make_config = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_21___cinit__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_23___cinit__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_23___cinit__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_23___cinit__ *)o); p->__pyx_v_config = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_21___cinit__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_23___cinit__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_23___cinit__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_23___cinit__ *)o; Py_XDECREF(p->__pyx_v_config); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_21___cinit__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_23___cinit__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_23___cinit__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_23___cinit__ *)o; if (p->__pyx_v_config) { e = (*v)(p->__pyx_v_config, a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_21___cinit__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_23___cinit__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_23___cinit__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_23___cinit__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_config); p->__pyx_v_config = Py_None; Py_INCREF(Py_None); @@ -20827,11 +24788,11 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_21___cinit__(PyObject *o) { return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_21___cinit__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_23___cinit__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_21___cinit__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_23___cinit__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -20889,7 +24850,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_21___cinit__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_21___cinit__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_23___cinit__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -20902,13 +24863,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_21___cinit__ = 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_21___cinit__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_23___cinit__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_21___cinit__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_23___cinit__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -20929,12 +24890,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_21___cinit__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_21___cinit__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_23___cinit__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_21___cinit__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_23___cinit__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_23___cinit__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_21___cinit__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_23___cinit__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -20944,24 +24905,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_21___cinit__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_21___cinit__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_21___cinit__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_21___cinit__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_23___cinit__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_23___cinit__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_23___cinit__, /*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_21___cinit__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_23___cinit__, /*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_21___cinit__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_21___cinit__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_23___cinit__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_23___cinit__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_21___cinit__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_23___cinit__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -20971,7 +24932,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_21___cinit__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_21___cinit__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_23___cinit__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -20985,28 +24946,28 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_21___cinit__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_22_genexpr(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_24_genexpr(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_24_genexpr *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_24_genexpr *)o); p->__pyx_outer_scope = 0; p->__pyx_v_kv = 0; p->__pyx_t_0 = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_22_genexpr(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_24_genexpr(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_24_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_24_genexpr *)o; Py_XDECREF(((PyObject *)p->__pyx_outer_scope)); Py_XDECREF(p->__pyx_v_kv); Py_XDECREF(p->__pyx_t_0); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_22_genexpr(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_24_genexpr(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_24_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_24_genexpr *)o; if (p->__pyx_outer_scope) { e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e; } @@ -21019,11 +24980,11 @@ static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_22_genexpr(PyObject *o, v return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_22_genexpr(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_24_genexpr(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_24_genexpr *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_24_genexpr *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_outer_scope); - p->__pyx_outer_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_21___cinit__ *)Py_None); Py_INCREF(Py_None); + p->__pyx_outer_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_23___cinit__ *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_kv); p->__pyx_v_kv = Py_None; Py_INCREF(Py_None); @@ -21034,11 +24995,11 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_22_genexpr(PyObject *o) { return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_22_genexpr[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_24_genexpr[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_22_genexpr = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_24_genexpr = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -21096,7 +25057,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_22_genexpr = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_22_genexpr = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_24_genexpr = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -21109,13 +25070,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_22_genexpr = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_22_genexpr = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_24_genexpr = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_22_genexpr = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_24_genexpr = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -21136,12 +25097,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_22_genexpr = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_22_genexpr = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_24_genexpr = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_22_genexpr"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_22_genexpr), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_24_genexpr"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_24_genexpr), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_22_genexpr, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_24_genexpr, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -21151,24 +25112,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_22_genexpr = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_22_genexpr, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_22_genexpr, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_22_genexpr, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_24_genexpr, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_24_genexpr, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_24_genexpr, /*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_22_genexpr, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_24_genexpr, /*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_22_genexpr, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_22_genexpr, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_24_genexpr, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_24_genexpr, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_22_genexpr, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_24_genexpr, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -21178,7 +25139,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_22_genexpr = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_22_genexpr, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_24_genexpr, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -21216,33 +25177,36 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0}, {&__pyx_kp_s_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 0, 1, 0}, {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0}, - {&__pyx_kp_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 0}, - {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0}, + {&__pyx_n_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 1}, + {&__pyx_kp_s_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 1, 0}, + {&__pyx_kp_s_17, __pyx_k_17, sizeof(__pyx_k_17), 0, 0, 1, 0}, {&__pyx_kp_s_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 1, 0}, + {&__pyx_kp_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 0}, {&__pyx_kp_s_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 0, 1, 0}, - {&__pyx_kp_s_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 1, 0}, - {&__pyx_kp_s_25, __pyx_k_25, sizeof(__pyx_k_25), 0, 0, 1, 0}, - {&__pyx_kp_s_26, __pyx_k_26, sizeof(__pyx_k_26), 0, 0, 1, 0}, {&__pyx_kp_s_27, __pyx_k_27, sizeof(__pyx_k_27), 0, 0, 1, 0}, {&__pyx_kp_s_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 0, 1, 0}, + {&__pyx_kp_s_29, __pyx_k_29, sizeof(__pyx_k_29), 0, 0, 1, 0}, {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0}, {&__pyx_kp_s_30, __pyx_k_30, sizeof(__pyx_k_30), 0, 0, 1, 0}, {&__pyx_kp_s_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 0, 1, 0}, + {&__pyx_kp_s_32, __pyx_k_32, sizeof(__pyx_k_32), 0, 0, 1, 0}, {&__pyx_kp_s_34, __pyx_k_34, sizeof(__pyx_k_34), 0, 0, 1, 0}, {&__pyx_kp_s_35, __pyx_k_35, sizeof(__pyx_k_35), 0, 0, 1, 0}, - {&__pyx_kp_s_37, __pyx_k_37, sizeof(__pyx_k_37), 0, 0, 1, 0}, + {&__pyx_kp_s_38, __pyx_k_38, sizeof(__pyx_k_38), 0, 0, 1, 0}, {&__pyx_kp_s_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 1, 0}, {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0}, - {&__pyx_kp_s_40, __pyx_k_40, sizeof(__pyx_k_40), 0, 0, 1, 0}, - {&__pyx_kp_s_42, __pyx_k_42, sizeof(__pyx_k_42), 0, 0, 1, 0}, + {&__pyx_kp_s_41, __pyx_k_41, sizeof(__pyx_k_41), 0, 0, 1, 0}, {&__pyx_kp_s_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 1, 0}, {&__pyx_kp_s_44, __pyx_k_44, sizeof(__pyx_k_44), 0, 0, 1, 0}, + {&__pyx_kp_s_46, __pyx_k_46, sizeof(__pyx_k_46), 0, 0, 1, 0}, + {&__pyx_kp_s_47, __pyx_k_47, sizeof(__pyx_k_47), 0, 0, 1, 0}, {&__pyx_kp_s_48, __pyx_k_48, sizeof(__pyx_k_48), 0, 0, 1, 0}, {&__pyx_kp_s_51, __pyx_k_51, sizeof(__pyx_k_51), 0, 0, 1, 0}, - {&__pyx_kp_s_56, __pyx_k_56, sizeof(__pyx_k_56), 0, 0, 1, 0}, - {&__pyx_n_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 1}, + {&__pyx_kp_s_54, __pyx_k_54, sizeof(__pyx_k_54), 0, 0, 1, 0}, + {&__pyx_kp_s_59, __pyx_k_59, sizeof(__pyx_k_59), 0, 0, 1, 0}, {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0}, {&__pyx_kp_s_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 1, 0}, + {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0}, {&__pyx_n_s__BLEU, __pyx_k__BLEU, sizeof(__pyx_k__BLEU), 0, 0, 1, 1}, {&__pyx_n_s__Exception, __pyx_k__Exception, sizeof(__pyx_k__Exception), 0, 0, 1, 1}, {&__pyx_n_s__IBM_BLEU, __pyx_k__IBM_BLEU, sizeof(__pyx_k__IBM_BLEU), 0, 0, 1, 1}, @@ -21253,6 +25217,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__ParseFailed, __pyx_k__ParseFailed, sizeof(__pyx_k__ParseFailed), 0, 0, 1, 1}, {&__pyx_n_s__TER, __pyx_k__TER, sizeof(__pyx_k__TER), 0, 0, 1, 1}, {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1}, + {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, {&__pyx_n_s____enter__, __pyx_k____enter__, sizeof(__pyx_k____enter__), 0, 0, 1, 1}, {&__pyx_n_s____exit__, __pyx_k____exit__, sizeof(__pyx_k____exit__), 0, 0, 1, 1}, {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, @@ -21260,7 +25225,9 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s___cdec, __pyx_k___cdec, sizeof(__pyx_k___cdec), 0, 0, 1, 1}, {&__pyx_n_s___make_config, __pyx_k___make_config, sizeof(__pyx_k___make_config), 0, 0, 1, 1}, {&__pyx_n_s___phrase, __pyx_k___phrase, sizeof(__pyx_k___phrase), 0, 0, 1, 1}, + {&__pyx_n_s__a, __pyx_k__a, sizeof(__pyx_k__a), 0, 0, 1, 1}, {&__pyx_n_s__beam_alpha, __pyx_k__beam_alpha, sizeof(__pyx_k__beam_alpha), 0, 0, 1, 1}, + {&__pyx_n_s__cat, __pyx_k__cat, sizeof(__pyx_k__cat), 0, 0, 1, 1}, {&__pyx_n_s__config, __pyx_k__config, sizeof(__pyx_k__config), 0, 0, 1, 1}, {&__pyx_n_s__config_str, __pyx_k__config_str, sizeof(__pyx_k__config_str), 0, 0, 1, 1}, {&__pyx_n_s__csplit, __pyx_k__csplit, sizeof(__pyx_k__csplit), 0, 0, 1, 1}, @@ -21299,8 +25266,10 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__phrase, __pyx_k__phrase, sizeof(__pyx_k__phrase), 0, 0, 1, 1}, {&__pyx_n_s__plf, __pyx_k__plf, sizeof(__pyx_k__plf), 0, 0, 1, 1}, {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1}, + {&__pyx_n_s__ref, __pyx_k__ref, sizeof(__pyx_k__ref), 0, 0, 1, 1}, {&__pyx_n_s__refs, __pyx_k__refs, sizeof(__pyx_k__refs), 0, 0, 1, 1}, {&__pyx_n_s__replace, __pyx_k__replace, sizeof(__pyx_k__replace), 0, 0, 1, 1}, + {&__pyx_n_s__rules, __pyx_k__rules, sizeof(__pyx_k__rules), 0, 0, 1, 1}, {&__pyx_n_s__scfg, __pyx_k__scfg, sizeof(__pyx_k__scfg), 0, 0, 1, 1}, {&__pyx_n_s__scores, __pyx_k__scores, sizeof(__pyx_k__scores), 0, 0, 1, 1}, {&__pyx_n_s__self, __pyx_k__self, sizeof(__pyx_k__self), 0, 0, 1, 1}, @@ -21316,15 +25285,16 @@ 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 = 24; __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 = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __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[1]; __pyx_lineno = 13; __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[1]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_NotImplemented = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplemented); if (!__pyx_builtin_NotImplemented) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __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[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __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 = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_NotImplemented = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplemented); if (!__pyx_builtin_NotImplemented) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __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[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 21; __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 = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; return -1; @@ -21336,10 +25306,10 @@ static int __Pyx_InitCachedConstants(void) { /* "_cdec.pyx":9 * cdef bytes ret - * if isinstance(sentence, unicode): - * ret = sentence.encode('utf8') # <<<<<<<<<<<<<< - * elif isinstance(sentence, str): - * ret = sentence + * if isinstance(data, unicode): + * ret = data.encode('utf8') # <<<<<<<<<<<<<< + * elif isinstance(data, str): + * ret = data */ __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_2); @@ -21348,58 +25318,72 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2)); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":76 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":77 * elif op == 3: # != * return not (x == y) * raise NotImplemented('comparison not implemented for SparseVector') # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_5); __Pyx_INCREF(((PyObject *)__pyx_kp_s_4)); PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_kp_s_4)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_4)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5)); - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":2 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":4 + * * def _phrase(phrase): - * return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) # <<<<<<<<<<<<<< + * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) # <<<<<<<<<<<<<< * - * cdef class TRule: + * cdef class NT: */ - __pyx_k_tuple_9 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_9); + __pyx_k_tuple_6 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_6); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_9, 0, ((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_6, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_9)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_6)); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":177 - * elif op == 3: # != - * return not (x == y) - * raise NotImplemented('comparison not implemented for HypergraphEdge') # <<<<<<<<<<<<<< - * - * cdef class HypergraphNode: + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":175 + * for trule in rules: + * if not isinstance(trule, BaseTRule): + * raise ValueError('the grammar should contain TRule objects') # <<<<<<<<<<<<<< + * _g.AddRule(( trule).rule[0]) */ - __pyx_k_tuple_14 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_14)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_14 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_14)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_14); __Pyx_INCREF(((PyObject *)__pyx_kp_s_13)); PyTuple_SET_ITEM(__pyx_k_tuple_14, 0, ((PyObject *)__pyx_kp_s_13)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_13)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_14)); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":214 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":191 + * elif op == 3: # != + * return not (x == y) + * raise NotImplemented('comparison not implemented for HypergraphEdge') # <<<<<<<<<<<<<< + * + * cdef class HypergraphNode: + */ + __pyx_k_tuple_18 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_18)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_18); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_17)); + PyTuple_SET_ITEM(__pyx_k_tuple_18, 0, ((PyObject *)__pyx_kp_s_17)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_17)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_18)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":228 * elif op == 3: # != * return not (x == y) * raise NotImplemented('comparison not implemented for HypergraphNode') # <<<<<<<<<<<<<< */ - __pyx_k_tuple_16 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_16)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_16); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_15)); - PyTuple_SET_ITEM(__pyx_k_tuple_16, 0, ((PyObject *)__pyx_kp_s_15)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_15)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_16)); + __pyx_k_tuple_20 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_20); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_19)); + PyTuple_SET_ITEM(__pyx_k_tuple_20, 0, ((PyObject *)__pyx_kp_s_19)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20)); /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":13 * else: @@ -21408,12 +25392,12 @@ static int __Pyx_InitCachedConstants(void) { * if not isinstance(inp, str): * raise TypeError('Cannot create lattice from %s' % type(inp)) */ - __pyx_k_tuple_17 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_17)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_17); + __pyx_k_tuple_21 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_21)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_21); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_17, 0, ((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_21, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_17)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21)); /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":21 * def __getitem__(self, int index): @@ -21422,12 +25406,12 @@ static int __Pyx_InitCachedConstants(void) { * arcs = [] * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] */ - __pyx_k_tuple_20 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_20); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_19)); - PyTuple_SET_ITEM(__pyx_k_tuple_20, 0, ((PyObject *)__pyx_kp_s_19)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20)); + __pyx_k_tuple_24 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_24); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_23)); + PyTuple_SET_ITEM(__pyx_k_tuple_24, 0, ((PyObject *)__pyx_kp_s_23)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_23)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_24)); /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":34 * def __setitem__(self, int index, tuple arcs): @@ -21436,12 +25420,12 @@ static int __Pyx_InitCachedConstants(void) { * cdef lattice.LatticeArc* arc * for (label, cost, dist2next) in arcs: */ - __pyx_k_tuple_21 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_21)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_21); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_19)); - PyTuple_SET_ITEM(__pyx_k_tuple_21, 0, ((PyObject *)__pyx_kp_s_19)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_19)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21)); + __pyx_k_tuple_25 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_25); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_23)); + PyTuple_SET_ITEM(__pyx_k_tuple_25, 0, ((PyObject *)__pyx_kp_s_23)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_23)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_25)); /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":38 * for (label, cost, dist2next) in arcs: @@ -21450,12 +25434,12 @@ static int __Pyx_InitCachedConstants(void) { * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) * self.lattice[0][index].push_back(arc[0]) */ - __pyx_k_tuple_22 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_22)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_22); + __pyx_k_tuple_26 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_26)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_26); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_22, 0, ((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_26, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_26)); /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":64 * for i in range(len(self)): @@ -21464,15 +25448,15 @@ static int __Pyx_InitCachedConstants(void) { * yield '%d [shape=doublecircle]' % len(self) * yield '}' */ - __pyx_k_tuple_29 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_29)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_29); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_27)); - PyTuple_SET_ITEM(__pyx_k_tuple_29, 0, ((PyObject *)__pyx_kp_s_27)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_27)); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_28)); - PyTuple_SET_ITEM(__pyx_k_tuple_29, 1, ((PyObject *)__pyx_kp_s_28)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_28)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_29)); + __pyx_k_tuple_33 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_33)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_33); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_31)); + PyTuple_SET_ITEM(__pyx_k_tuple_33, 0, ((PyObject *)__pyx_kp_s_31)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_31)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_32)); + PyTuple_SET_ITEM(__pyx_k_tuple_33, 1, ((PyObject *)__pyx_kp_s_32)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_32)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_33)); /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":58 * @@ -21481,34 +25465,34 @@ static int __Pyx_InitCachedConstants(void) { * yield 'digraph lattice {' * yield 'rankdir = LR;' */ - __pyx_k_tuple_32 = PyTuple_New(4); if (unlikely(!__pyx_k_tuple_32)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_32); + __pyx_k_tuple_36 = PyTuple_New(4); if (unlikely(!__pyx_k_tuple_36)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_36); __Pyx_INCREF(((PyObject *)__pyx_n_s__i)); - PyTuple_SET_ITEM(__pyx_k_tuple_32, 0, ((PyObject *)__pyx_n_s__i)); + PyTuple_SET_ITEM(__pyx_k_tuple_36, 0, ((PyObject *)__pyx_n_s__i)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i)); __Pyx_INCREF(((PyObject *)__pyx_n_s__label)); - PyTuple_SET_ITEM(__pyx_k_tuple_32, 1, ((PyObject *)__pyx_n_s__label)); + PyTuple_SET_ITEM(__pyx_k_tuple_36, 1, ((PyObject *)__pyx_n_s__label)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__label)); __Pyx_INCREF(((PyObject *)__pyx_n_s__weight)); - PyTuple_SET_ITEM(__pyx_k_tuple_32, 2, ((PyObject *)__pyx_n_s__weight)); + PyTuple_SET_ITEM(__pyx_k_tuple_36, 2, ((PyObject *)__pyx_n_s__weight)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__weight)); __Pyx_INCREF(((PyObject *)__pyx_n_s__delta)); - PyTuple_SET_ITEM(__pyx_k_tuple_32, 3, ((PyObject *)__pyx_n_s__delta)); + PyTuple_SET_ITEM(__pyx_k_tuple_36, 3, ((PyObject *)__pyx_n_s__delta)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__delta)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_32)); - __pyx_k_codeobj_33 = (PyObject*)__Pyx_PyCode_New(0, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_32, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_34, __pyx_n_s__lines, 58, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_33)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_36)); + __pyx_k_codeobj_37 = (PyObject*)__Pyx_PyCode_New(0, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_36, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_38, __pyx_n_s__lines, 58, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_37)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":67 * yield '%d [shape=doublecircle]' % len(self) * yield '}' * return '\n'.join(lines()).encode('utf8') # <<<<<<<<<<<<<< */ - __pyx_k_tuple_36 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_36)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_36); + __pyx_k_tuple_40 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_40)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_40); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_36, 0, ((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_40, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_36)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_40)); /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":79 * def __getitem__(self,int k): @@ -21517,96 +25501,84 @@ static int __Pyx_InitCachedConstants(void) { * cdef Candidate candidate = Candidate() * candidate.candidate = &self.cs[0][k] */ - __pyx_k_tuple_38 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_38)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_38); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_37)); - PyTuple_SET_ITEM(__pyx_k_tuple_38, 0, ((PyObject *)__pyx_kp_s_37)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_37)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_38)); + __pyx_k_tuple_42 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_42)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_42); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_41)); + PyTuple_SET_ITEM(__pyx_k_tuple_42, 0, ((PyObject *)__pyx_kp_s_41)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_41)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_42)); - /* "_cdec.pyx":49 + /* "_cdec.pyx":50 * """ * if config_str is None: * formalism = config.get('formalism', None) # <<<<<<<<<<<<<< * if formalism not in ('scfg', 'fst', 'lextrans', 'pb', * 'csplit', 'tagger', 'lexalign'): */ - __pyx_k_tuple_41 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_41)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_41); + __pyx_k_tuple_45 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_45)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_45); __Pyx_INCREF(((PyObject *)__pyx_n_s__formalism)); - PyTuple_SET_ITEM(__pyx_k_tuple_41, 0, ((PyObject *)__pyx_n_s__formalism)); + PyTuple_SET_ITEM(__pyx_k_tuple_45, 0, ((PyObject *)__pyx_n_s__formalism)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__formalism)); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_41, 1, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_45, 1, Py_None); __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_41)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_45)); - /* "_cdec.pyx":87 + /* "_cdec.pyx":88 * with open(weights) as fp: * for line in fp: * if line.strip().startswith('#'): continue # <<<<<<<<<<<<<< * fname, value = line.split() * self.weights[fname.strip()] = float(value) */ - __pyx_k_tuple_45 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_45)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_45); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_44)); - PyTuple_SET_ITEM(__pyx_k_tuple_45, 0, ((PyObject *)__pyx_kp_s_44)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_44)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_45)); + __pyx_k_tuple_49 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_49)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_49); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_48)); + PyTuple_SET_ITEM(__pyx_k_tuple_49, 0, ((PyObject *)__pyx_kp_s_48)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_48)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_49)); - /* "_cdec.pyx":85 + /* "_cdec.pyx":86 * * def read_weights(self, weights): * with open(weights) as fp: # <<<<<<<<<<<<<< * for line in fp: * if line.strip().startswith('#'): continue */ - __pyx_k_tuple_46 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_46)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_46); + __pyx_k_tuple_50 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_50)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_50); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_46, 0, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_50, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_46, 1, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_50, 1, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_46, 2, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_50, 2, Py_None); __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_46)); - - /* "_cdec.pyx":93 - * def translate(self, sentence, grammar=None): - * if isinstance(sentence, unicode): - * inp = sentence.strip().encode('utf8') # <<<<<<<<<<<<<< - * elif isinstance(sentence, str): - * inp = sentence.strip() - */ - __pyx_k_tuple_47 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_47)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_47); - __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_47, 0, ((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_47)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_50)); - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":1 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":3 + * cimport grammar + * * def _phrase(phrase): # <<<<<<<<<<<<<< - * return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) + * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) * */ - __pyx_k_tuple_49 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_49)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_49); + __pyx_k_tuple_52 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_52); __Pyx_INCREF(((PyObject *)__pyx_n_s__phrase)); - PyTuple_SET_ITEM(__pyx_k_tuple_49, 0, ((PyObject *)__pyx_n_s__phrase)); + PyTuple_SET_ITEM(__pyx_k_tuple_52, 0, ((PyObject *)__pyx_n_s__phrase)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__phrase)); __Pyx_INCREF(((PyObject *)__pyx_n_s__genexpr)); - PyTuple_SET_ITEM(__pyx_k_tuple_49, 1, ((PyObject *)__pyx_n_s__genexpr)); + PyTuple_SET_ITEM(__pyx_k_tuple_52, 1, ((PyObject *)__pyx_n_s__genexpr)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__genexpr)); __Pyx_INCREF(((PyObject *)__pyx_n_s__genexpr)); - PyTuple_SET_ITEM(__pyx_k_tuple_49, 2, ((PyObject *)__pyx_n_s__genexpr)); + PyTuple_SET_ITEM(__pyx_k_tuple_52, 2, ((PyObject *)__pyx_n_s__genexpr)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__genexpr)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_49)); - __pyx_k_codeobj_50 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_49, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_51, __pyx_n_s___phrase, 1, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_50)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_52)); + __pyx_k_codeobj_53 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_52, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_54, __pyx_n_s___phrase, 3, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_53)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":143 * return self.name.c_str() @@ -21614,51 +25586,51 @@ static int __Pyx_InitCachedConstants(void) { * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< * TER = Scorer('TER') */ - __pyx_k_tuple_52 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_52); + __pyx_k_tuple_55 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_55)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_55); __Pyx_INCREF(((PyObject *)__pyx_n_s__IBM_BLEU)); - PyTuple_SET_ITEM(__pyx_k_tuple_52, 0, ((PyObject *)__pyx_n_s__IBM_BLEU)); + PyTuple_SET_ITEM(__pyx_k_tuple_55, 0, ((PyObject *)__pyx_n_s__IBM_BLEU)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IBM_BLEU)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_52)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_55)); /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":144 * * BLEU = Scorer('IBM_BLEU') * TER = Scorer('TER') # <<<<<<<<<<<<<< */ - __pyx_k_tuple_53 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_53)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_53); + __pyx_k_tuple_56 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_56)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_56); __Pyx_INCREF(((PyObject *)__pyx_n_s__TER)); - PyTuple_SET_ITEM(__pyx_k_tuple_53, 0, ((PyObject *)__pyx_n_s__TER)); + PyTuple_SET_ITEM(__pyx_k_tuple_56, 0, ((PyObject *)__pyx_n_s__TER)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__TER)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_53)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_56)); - /* "_cdec.pyx":27 + /* "_cdec.pyx":28 * class ParseFailed(Exception): pass * * def _make_config(config): # <<<<<<<<<<<<<< * for key, value in config.items(): * if isinstance(value, dict): */ - __pyx_k_tuple_54 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_54)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_54); + __pyx_k_tuple_57 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_57)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_57); __Pyx_INCREF(((PyObject *)__pyx_n_s__config)); - PyTuple_SET_ITEM(__pyx_k_tuple_54, 0, ((PyObject *)__pyx_n_s__config)); + PyTuple_SET_ITEM(__pyx_k_tuple_57, 0, ((PyObject *)__pyx_n_s__config)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__config)); __Pyx_INCREF(((PyObject *)__pyx_n_s__key)); - PyTuple_SET_ITEM(__pyx_k_tuple_54, 1, ((PyObject *)__pyx_n_s__key)); + PyTuple_SET_ITEM(__pyx_k_tuple_57, 1, ((PyObject *)__pyx_n_s__key)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__key)); __Pyx_INCREF(((PyObject *)__pyx_n_s__value)); - PyTuple_SET_ITEM(__pyx_k_tuple_54, 2, ((PyObject *)__pyx_n_s__value)); + PyTuple_SET_ITEM(__pyx_k_tuple_57, 2, ((PyObject *)__pyx_n_s__value)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__value)); __Pyx_INCREF(((PyObject *)__pyx_n_s__name)); - PyTuple_SET_ITEM(__pyx_k_tuple_54, 3, ((PyObject *)__pyx_n_s__name)); + PyTuple_SET_ITEM(__pyx_k_tuple_57, 3, ((PyObject *)__pyx_n_s__name)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__name)); __Pyx_INCREF(((PyObject *)__pyx_n_s__info)); - PyTuple_SET_ITEM(__pyx_k_tuple_54, 4, ((PyObject *)__pyx_n_s__info)); + PyTuple_SET_ITEM(__pyx_k_tuple_57, 4, ((PyObject *)__pyx_n_s__info)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__info)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_54)); - __pyx_k_codeobj_55 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_54, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_56, __pyx_n_s___make_config, 27, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_55)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_57)); + __pyx_k_codeobj_58 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_57, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_59, __pyx_n_s___make_config, 28, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_58)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -21748,26 +25720,43 @@ PyMODINIT_FUNC PyInit__cdec(void) if (PyType_Ready(&__pyx_type_5_cdec_SparseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "SparseVector", (PyObject *)&__pyx_type_5_cdec_SparseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_SparseVector = &__pyx_type_5_cdec_SparseVector; - if (PyType_Ready(&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Hypergraph", (PyObject *)&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec_Hypergraph = &__pyx_type_5_cdec_Hypergraph; - if (PyType_Ready(&__pyx_type_5_cdec_TRule) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "TRule", (PyObject *)&__pyx_type_5_cdec_TRule) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_NT) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "NT", (PyObject *)&__pyx_type_5_cdec_NT) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_NT = &__pyx_type_5_cdec_NT; + if (PyType_Ready(&__pyx_type_5_cdec_NTRef) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "NTRef", (PyObject *)&__pyx_type_5_cdec_NTRef) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_NTRef = &__pyx_type_5_cdec_NTRef; + if (PyType_Ready(&__pyx_type_5_cdec_BaseTRule) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "BaseTRule", (PyObject *)&__pyx_type_5_cdec_BaseTRule) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_BaseTRule = &__pyx_type_5_cdec_BaseTRule; + __pyx_type_5_cdec_TRule.tp_base = __pyx_ptype_5_cdec_BaseTRule; + if (PyType_Ready(&__pyx_type_5_cdec_TRule) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "TRule", (PyObject *)&__pyx_type_5_cdec_TRule) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_TRule = &__pyx_type_5_cdec_TRule; + if (PyType_Ready(&__pyx_type_5_cdec_Grammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Grammar", (PyObject *)&__pyx_type_5_cdec_Grammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_Grammar = &__pyx_type_5_cdec_Grammar; + __pyx_type_5_cdec_TextGrammar.tp_base = __pyx_ptype_5_cdec_Grammar; + if (PyType_Ready(&__pyx_type_5_cdec_TextGrammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "TextGrammar", (PyObject *)&__pyx_type_5_cdec_TextGrammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_TextGrammar = &__pyx_type_5_cdec_TextGrammar; + if (PyType_Ready(&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Hypergraph", (PyObject *)&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_Hypergraph = &__pyx_type_5_cdec_Hypergraph; __pyx_vtabptr_5_cdec_HypergraphEdge = &__pyx_vtable_5_cdec_HypergraphEdge; __pyx_vtable_5_cdec_HypergraphEdge.init = (PyObject *(*)(struct __pyx_obj_5_cdec_HypergraphEdge *, Hypergraph *, unsigned int))__pyx_f_5_cdec_14HypergraphEdge_init; - if (PyType_Ready(&__pyx_type_5_cdec_HypergraphEdge) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_5_cdec_HypergraphEdge.tp_dict, __pyx_vtabptr_5_cdec_HypergraphEdge) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "HypergraphEdge", (PyObject *)&__pyx_type_5_cdec_HypergraphEdge) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_HypergraphEdge) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_5_cdec_HypergraphEdge.tp_dict, __pyx_vtabptr_5_cdec_HypergraphEdge) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "HypergraphEdge", (PyObject *)&__pyx_type_5_cdec_HypergraphEdge) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_HypergraphEdge = &__pyx_type_5_cdec_HypergraphEdge; __pyx_vtabptr_5_cdec_HypergraphNode = &__pyx_vtable_5_cdec_HypergraphNode; __pyx_vtable_5_cdec_HypergraphNode.init = (PyObject *(*)(struct __pyx_obj_5_cdec_HypergraphNode *, Hypergraph *, unsigned int))__pyx_f_5_cdec_14HypergraphNode_init; - if (PyType_Ready(&__pyx_type_5_cdec_HypergraphNode) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_5_cdec_HypergraphNode.tp_dict, __pyx_vtabptr_5_cdec_HypergraphNode) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "HypergraphNode", (PyObject *)&__pyx_type_5_cdec_HypergraphNode) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_HypergraphNode) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_5_cdec_HypergraphNode.tp_dict, __pyx_vtabptr_5_cdec_HypergraphNode) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "HypergraphNode", (PyObject *)&__pyx_type_5_cdec_HypergraphNode) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_HypergraphNode = &__pyx_type_5_cdec_HypergraphNode; - if (PyType_Ready(&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Lattice", (PyObject *)&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Lattice", (PyObject *)&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Lattice = &__pyx_type_5_cdec_Lattice; if (PyType_Ready(&__pyx_type_5_cdec_Candidate) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Candidate", (PyObject *)&__pyx_type_5_cdec_Candidate) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -21784,68 +25773,74 @@ PyMODINIT_FUNC PyInit__cdec(void) if (PyType_Ready(&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Scorer", (PyObject *)&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Scorer = &__pyx_type_5_cdec_Scorer; - 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;} + if (PyType_Ready(&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __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 = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Decoder = &__pyx_type_5_cdec_Decoder; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct____iter__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct____iter__ = &__pyx_type_5_cdec___pyx_scope_struct____iter__; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_1___iter__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_1___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_1___iter__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_2_kbest) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_2_kbest = &__pyx_type_5_cdec___pyx_scope_struct_2_kbest; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_3_kbest_trees) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_trees = &__pyx_type_5_cdec___pyx_scope_struct_3_kbest_trees; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_4_kbest_features) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features = &__pyx_type_5_cdec___pyx_scope_struct_4_kbest_features; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_5_sample) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_5_sample = &__pyx_type_5_cdec___pyx_scope_struct_5_sample; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_6___get__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_6___get__ = &__pyx_type_5_cdec___pyx_scope_struct_6___get__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_7___get__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_7___get__ = &__pyx_type_5_cdec___pyx_scope_struct_7___get__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_8__phrase) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_8__phrase = &__pyx_type_5_cdec___pyx_scope_struct_8__phrase; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_9_genexpr) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_9_genexpr = &__pyx_type_5_cdec___pyx_scope_struct_9_genexpr; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_10___str__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_10___str__ = &__pyx_type_5_cdec___pyx_scope_struct_10___str__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_11_genexpr) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_11_genexpr = &__pyx_type_5_cdec___pyx_scope_struct_11_genexpr; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_12___get__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_2__phrase) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_2__phrase = &__pyx_type_5_cdec___pyx_scope_struct_2__phrase; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_3_genexpr) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_3_genexpr = &__pyx_type_5_cdec___pyx_scope_struct_3_genexpr; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_4___get__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_4___get__ = &__pyx_type_5_cdec___pyx_scope_struct_4___get__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_5___str__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_5___str__ = &__pyx_type_5_cdec___pyx_scope_struct_5___str__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_6_genexpr) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_6_genexpr = &__pyx_type_5_cdec___pyx_scope_struct_6_genexpr; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_7___iter__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_7___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_7___iter__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_8_kbest) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_8_kbest = &__pyx_type_5_cdec___pyx_scope_struct_8_kbest; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_9_kbest_trees) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_9_kbest_trees = &__pyx_type_5_cdec___pyx_scope_struct_9_kbest_trees; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_10_kbest_features) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_10_kbest_features = &__pyx_type_5_cdec___pyx_scope_struct_10_kbest_features; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_11_sample) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_11_sample = &__pyx_type_5_cdec___pyx_scope_struct_11_sample; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_12___get__) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_12___get__ = &__pyx_type_5_cdec___pyx_scope_struct_12___get__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_13___get__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_13___get__) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_13___get__ = &__pyx_type_5_cdec___pyx_scope_struct_13___get__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_14___get__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_14___get__) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_14___get__ = &__pyx_type_5_cdec___pyx_scope_struct_14___get__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_15___iter__) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_15___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_15___iter__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_16_todot) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_16_todot = &__pyx_type_5_cdec___pyx_scope_struct_16_todot; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_17_lines) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_17_lines = &__pyx_type_5_cdec___pyx_scope_struct_17_lines; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_18___iter__) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_18___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_18___iter__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_19___iter__) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_19___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_19___iter__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_20__make_config) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_20__make_config = &__pyx_type_5_cdec___pyx_scope_struct_20__make_config; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_21___cinit__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_21___cinit__ = &__pyx_type_5_cdec___pyx_scope_struct_21___cinit__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_22_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_22_genexpr = &__pyx_type_5_cdec___pyx_scope_struct_22_genexpr; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_15___get__) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_15___get__ = &__pyx_type_5_cdec___pyx_scope_struct_15___get__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_16___get__) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_16___get__ = &__pyx_type_5_cdec___pyx_scope_struct_16___get__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_17___iter__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_17___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_17___iter__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_18_todot) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_18_todot = &__pyx_type_5_cdec___pyx_scope_struct_18_todot; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_19_lines) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_19_lines = &__pyx_type_5_cdec___pyx_scope_struct_19_lines; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_20___iter__) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_20___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_20___iter__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_21___iter__) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_21___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_21___iter__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_22__make_config) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_22__make_config = &__pyx_type_5_cdec___pyx_scope_struct_22__make_config; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_23___cinit__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_23___cinit__ = &__pyx_type_5_cdec___pyx_scope_struct_23___cinit__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_24_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_24_genexpr = &__pyx_type_5_cdec___pyx_scope_struct_24_genexpr; /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ /*--- Execution code ---*/ - /* "/Users/vchahun/Sandbox/cdec/python/src/trule.pxi":1 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":3 + * cimport grammar + * * def _phrase(phrase): # <<<<<<<<<<<<<< - * return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) + * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) * */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5_cdec_1_phrase, NULL, __pyx_n_s___cdec); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5_cdec_1_phrase, NULL, __pyx_n_s___cdec); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s___phrase, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s___phrase, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":143 @@ -21854,7 +25849,7 @@ PyMODINIT_FUNC PyInit__cdec(void) * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< * TER = Scorer('TER') */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_52), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_55), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -21864,12 +25859,12 @@ PyMODINIT_FUNC PyInit__cdec(void) * BLEU = Scorer('IBM_BLEU') * TER = Scorer('TER') # <<<<<<<<<<<<<< */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_53), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_56), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "_cdec.pyx":21 + /* "_cdec.pyx":22 * include "mteval.pxi" * * SetSilent(True) # <<<<<<<<<<<<<< @@ -21878,7 +25873,7 @@ PyMODINIT_FUNC PyInit__cdec(void) */ SetSilent(1); - /* "_cdec.pyx":22 + /* "_cdec.pyx":23 * * SetSilent(True) * decoder.register_feature_functions() # <<<<<<<<<<<<<< @@ -21887,58 +25882,58 @@ PyMODINIT_FUNC PyInit__cdec(void) */ register_feature_functions(); - /* "_cdec.pyx":24 + /* "_cdec.pyx":25 * decoder.register_feature_functions() * * class InvalidConfig(Exception): pass # <<<<<<<<<<<<<< * class ParseFailed(Exception): pass * */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __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 = 24; __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 = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__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__InvalidConfig, __pyx_n_s___cdec); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_CreateClass(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1), __pyx_n_s__InvalidConfig, __pyx_n_s___cdec); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __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__InvalidConfig, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__InvalidConfig, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __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":25 + /* "_cdec.pyx":26 * * class InvalidConfig(Exception): pass * class ParseFailed(Exception): pass # <<<<<<<<<<<<<< * * def _make_config(config): */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __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_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_builtin_Exception); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_builtin_Exception); __Pyx_GIVEREF(__pyx_builtin_Exception); - __pyx_t_2 = __Pyx_CreateClass(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_1), __pyx_n_s__ParseFailed, __pyx_n_s___cdec); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_CreateClass(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_1), __pyx_n_s__ParseFailed, __pyx_n_s___cdec); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__ParseFailed, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__ParseFailed, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - /* "_cdec.pyx":27 + /* "_cdec.pyx":28 * class ParseFailed(Exception): pass * * def _make_config(config): # <<<<<<<<<<<<<< * for key, value in config.items(): * if isinstance(value, dict): */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5_cdec_3_make_config, NULL, __pyx_n_s___cdec); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5_cdec_3_make_config, NULL, __pyx_n_s___cdec); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s___make_config, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s___make_config, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "_cdec.pyx":1 @@ -22187,6 +26182,10 @@ static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { return 0; } +static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) { + PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname); +} + static void __Pyx_RaiseDoubleKeywordsError( const char* func_name, PyObject* kw_name) @@ -22302,35 +26301,7 @@ static void __Pyx_RaiseArgtupleInvalid( (num_expected == 1) ? "" : "s", num_found); } -static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) { - PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname); -} -static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject* iterator, PyObject* defval) { - PyObject* next; - if (unlikely(!PyIter_Check(iterator))) { - PyErr_Format(PyExc_TypeError, - "%.200s object is not an iterator", iterator->ob_type->tp_name); - return NULL; - } - next = (*(Py_TYPE(iterator)->tp_iternext))(iterator); - if (likely(next)) { - return next; - } else if (defval) { - if (PyErr_Occurred()) { - if(!PyErr_ExceptionMatches(PyExc_StopIteration)) - return NULL; - PyErr_Clear(); - } - Py_INCREF(defval); - return defval; - } else if (PyErr_Occurred()) { - return NULL; - } else { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } -} static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { PyErr_Format(PyExc_ValueError, @@ -22359,7 +26330,31 @@ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { return 0; } - +static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject* iterator, PyObject* defval) { + PyObject* next; + if (unlikely(!PyIter_Check(iterator))) { + PyErr_Format(PyExc_TypeError, + "%.200s object is not an iterator", iterator->ob_type->tp_name); + return NULL; + } + next = (*(Py_TYPE(iterator)->tp_iternext))(iterator); + if (likely(next)) { + return next; + } else if (defval) { + if (PyErr_Occurred()) { + if(!PyErr_ExceptionMatches(PyExc_StopIteration)) + return NULL; + PyErr_Clear(); + } + Py_INCREF(defval); + return defval; + } else if (PyErr_Occurred()) { + return NULL; + } else { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } +} static double __Pyx__PyObject_AsDouble(PyObject* obj) { PyObject* float_value; @@ -22500,6 +26495,58 @@ static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *na return result; } +static CYTHON_INLINE WordID __Pyx_PyInt_from_py_WordID(PyObject* x) { + const WordID neg_one = (WordID)-1, const_zero = (WordID)0; + const int is_unsigned = const_zero < neg_one; + if (sizeof(WordID) == sizeof(char)) { + if (is_unsigned) + return (WordID)__Pyx_PyInt_AsUnsignedChar(x); + else + return (WordID)__Pyx_PyInt_AsSignedChar(x); + } else if (sizeof(WordID) == sizeof(short)) { + if (is_unsigned) + return (WordID)__Pyx_PyInt_AsUnsignedShort(x); + else + return (WordID)__Pyx_PyInt_AsSignedShort(x); + } else if (sizeof(WordID) == sizeof(int)) { + if (is_unsigned) + return (WordID)__Pyx_PyInt_AsUnsignedInt(x); + else + return (WordID)__Pyx_PyInt_AsSignedInt(x); + } else if (sizeof(WordID) == sizeof(long)) { + if (is_unsigned) + return (WordID)__Pyx_PyInt_AsUnsignedLong(x); + else + return (WordID)__Pyx_PyInt_AsSignedLong(x); + } else if (sizeof(WordID) == sizeof(PY_LONG_LONG)) { + if (is_unsigned) + return (WordID)__Pyx_PyInt_AsUnsignedLongLong(x); + else + return (WordID)__Pyx_PyInt_AsSignedLongLong(x); + } else { + WordID val; + PyObject *v = __Pyx_PyNumber_Int(x); + #if PY_VERSION_HEX < 0x03000000 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } + return (WordID)-1; + } +} + static PyObject* __Pyx_Globals() { Py_ssize_t i; /*PyObject *d;*/ diff --git a/python/src/_cdec.pyx b/python/src/_cdec.pyx index 164d6570..c60f342f 100644 --- a/python/src/_cdec.pyx +++ b/python/src/_cdec.pyx @@ -3,17 +3,18 @@ from libcpp.vector cimport vector from utils cimport * cimport decoder -cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): +cdef char* as_str(data, error_msg='Cannot convert type %s to str'): cdef bytes ret - if isinstance(sentence, unicode): - ret = sentence.encode('utf8') - elif isinstance(sentence, str): - ret = sentence + if isinstance(data, unicode): + ret = data.encode('utf8') + elif isinstance(data, str): + ret = data else: - raise TypeError(error_msg % type(sentence)) + raise TypeError(error_msg % type(data)) return ret include "vectors.pxi" +include "grammar.pxi" include "hypergraph.pxi" include "lattice.pxi" include "mteval.pxi" @@ -89,18 +90,20 @@ cdef class Decoder: self.weights[fname.strip()] = float(value) def translate(self, sentence, grammar=None): - if isinstance(sentence, unicode): - inp = sentence.strip().encode('utf8') - elif isinstance(sentence, str): - inp = sentence.strip() + cdef bytes input_str + if isinstance(sentence, unicode) or isinstance(sentence, str): + input_str = as_str(sentence.strip()) elif isinstance(sentence, Lattice): - inp = str(sentence) # PLF format + input_str = str(sentence) # PLF format else: raise TypeError('Cannot translate input type %s' % type(sentence)) if grammar: - self.dec.AddSupplementalGrammarFromString(string( grammar)) + if isinstance(grammar, str) or isinstance(grammar, unicode): + self.dec.AddSupplementalGrammarFromString(string(as_str(grammar))) + else: + self.dec.AddSupplementalGrammar(TextGrammar(grammar).grammar[0]) cdef decoder.BasicObserver observer = decoder.BasicObserver() - self.dec.Decode(string(inp), &observer) + self.dec.Decode(string(input_str), &observer) if observer.hypergraph == NULL: raise ParseFailed() cdef Hypergraph hg = Hypergraph() diff --git a/python/src/decoder.pxd b/python/src/decoder.pxd index 660bcb39..d2065579 100644 --- a/python/src/decoder.pxd +++ b/python/src/decoder.pxd @@ -1,7 +1,8 @@ from libcpp.string cimport string from libcpp.vector cimport vector from hypergraph cimport Hypergraph -from utils cimport istream, weight_t, variables_map +from grammar cimport Grammar +from utils cimport * cdef extern from "decoder/ff_register.h": void register_feature_functions() @@ -28,8 +29,8 @@ cdef extern from "decoder/decoder.h": # add grammar rules (currently only supported by SCFG decoders) # that will be used on subsequent calls to Decode. rules should be in standard # text format. This function does NOT read from a file. - void SetSupplementalGrammar(string& grammar) - void SetSentenceGrammarFromString(string& grammar_str) + void AddSupplementalGrammarFromString(string& grammar_str) + void AddSupplementalGrammar(shared_ptr[Grammar] grammar) cdef extern from "observer.h": cdef cppclass BasicObserver(DecoderObserver): diff --git a/python/src/grammar.pxd b/python/src/grammar.pxd new file mode 100644 index 00000000..43806f71 --- /dev/null +++ b/python/src/grammar.pxd @@ -0,0 +1,43 @@ +from libcpp.vector cimport vector +from libcpp.string cimport string +from utils cimport * + +cdef extern from "decoder/trule.h": + + cdef cppclass AlignmentPoint: + AlignmentPoint(int s, int t) + AlignmentPoint Inverted() + short s_ + short t_ + + cdef cppclass TRule: + vector[WordID] f_ + vector[WordID] e_ + vector[AlignmentPoint] a_ + FastSparseVector[weight_t] scores_ + WordID lhs_ + int arity_ + bint IsUnary() + bint IsGoal() + void ComputeArity() + +cdef extern from "decoder/grammar.h": + cdef cppclass RuleBin "const RuleBin": + int GetNumRules() + shared_ptr[TRule] GetIthRule(int i) + int Arity() + + cdef cppclass GrammarIter "const GrammarIter": + RuleBin* GetRules() + GrammarIter* Extend(int symbol) + + cdef cppclass Grammar: + GrammarIter* GetRoot() + bint HasRuleForSpan(int i, int j, int distance) + unsigned GetCTFLevels() + string GetGrammarName() + void SetGrammarName(string) + + cdef cppclass TextGrammar(Grammar): + TextGrammar() + void AddRule(shared_ptr[TRule]& rule) diff --git a/python/src/grammar.pxi b/python/src/grammar.pxi new file mode 100644 index 00000000..80d9fbf5 --- /dev/null +++ b/python/src/grammar.pxi @@ -0,0 +1,176 @@ +cimport grammar + +def _phrase(phrase): + return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) + +cdef class NT: + cdef public char* cat + cdef public unsigned ref + def __init__(self, cat, ref=0): + self.cat = cat + self.ref = ref + + def __str__(self): + if self.ref > 0: + return '[%s,%d]' % (self.cat, self.ref) + return '[%s]' % self.cat + +cdef class NTRef: + cdef public unsigned ref + def __init__(self, ref): + self.ref = ref + + def __str__(self): + return '[%d]' % self.ref + +cdef class BaseTRule: + cdef shared_ptr[grammar.TRule]* rule + + def __dealloc__(self): + del self.rule + + property arity: + def __get__(self): + return self.rule.get().arity_ + + property f: + def __get__(self): + cdef vector[WordID]* f_ = &self.rule.get().f_ + cdef WordID w + cdef f = [] + cdef unsigned i + cdef int idx = 0 + for i in range(f_.size()): + w = f_[0][i] + if w < 0: + idx += 1 + f.append(NT(TDConvert(-w), idx)) + else: + f.append(unicode(TDConvert(w), encoding='utf8')) + return f + + def __set__(self, f): + cdef vector[WordID]* f_ = &self.rule.get().f_ + f_.resize(len(f)) + cdef unsigned i + cdef int idx = 0 + for i in range(len(f)): + if isinstance(f[i], NT): + f_[0][i] = -TDConvert(f[i].cat) + else: + f_[0][i] = TDConvert(as_str(f[i])) + + property e: + def __get__(self): + cdef vector[WordID]* e_ = &self.rule.get().e_ + cdef WordID w + cdef e = [] + cdef unsigned i + cdef int idx = 0 + for i in range(e_.size()): + w = e_[0][i] + if w < 1: + idx += 1 + e.append(NTRef(1-w)) + else: + e.append(unicode(TDConvert(w), encoding='utf8')) + return e + + def __set__(self, e): + cdef vector[WordID]* e_ = &self.rule.get().e_ + e_.resize(len(e)) + cdef unsigned i + for i in range(len(e)): + if isinstance(e[i], NTRef): + e_[0][i] = 1-e[i].ref + else: + e_[0][i] = TDConvert(as_str(e[i])) + + property a: + def __get__(self): + cdef unsigned i + cdef vector[grammar.AlignmentPoint]* a = &self.rule.get().a_ + for i in range(a.size()): + yield (a[0][i].s_, a[0][i].t_) + + def __set__(self, a): + cdef vector[grammar.AlignmentPoint]* a_ = &self.rule.get().a_ + a_.resize(len(a)) + cdef unsigned i + cdef int s, t + for i in range(len(a)): + s, t = a[i] + a_[0][i] = grammar.AlignmentPoint(s, t) + + property scores: + def __get__(self): + cdef SparseVector scores = SparseVector() + scores.vector = new FastSparseVector[double](self.rule.get().scores_) + return scores + + def __set__(self, scores): + cdef FastSparseVector[double]* scores_ = &self.rule.get().scores_ + scores_.clear() + cdef int fid + cdef float fval + for fname, fval in scores.items(): + fid = FDConvert(as_str(fname)) + if fid < 0: raise KeyError(fname) + scores_.set_value(fid, fval) + + property lhs: + def __get__(self): + return NT(TDConvert(-self.rule.get().lhs_)) + + def __set__(self, lhs): + if not isinstance(lhs, NT): + lhs = NT(lhs) + self.rule.get().lhs_ = -TDConvert(lhs.cat) + + def __str__(self): + scores = ' '.join('%s=%s' % feat for feat in self.scores) + return '%s ||| %s ||| %s ||| %s' % (self.lhs, + _phrase(self.f), _phrase(self.e), scores) + +cdef class TRule(BaseTRule): + def __cinit__(self, lhs, f, e, scores, a=None): + self.rule = new shared_ptr[grammar.TRule](new grammar.TRule()) + self.lhs = lhs + self.e = e + self.f = f + self.scores = scores + if a: + self.a = a + self.rule.get().ComputeArity() + +cdef class Grammar: + cdef shared_ptr[grammar.Grammar]* grammar + + def __dealloc__(self): + del self.grammar + + def __iter__(self): + cdef grammar.GrammarIter* root = self.grammar.get().GetRoot() + cdef grammar.RuleBin* rbin = root.GetRules() + cdef TRule trule + cdef unsigned i + for i in range(rbin.GetNumRules()): + trule = TRule() + trule.rule = new shared_ptr[grammar.TRule](rbin.GetIthRule(i)) + yield trule + + property name: + def __get__(self): + self.grammar.get().GetGrammarName().c_str() + + def __set__(self, name): + self.grammar.get().SetGrammarName(string(name)) + +cdef class TextGrammar(Grammar): + def __cinit__(self, rules): + self.grammar = new shared_ptr[grammar.Grammar](new grammar.TextGrammar()) + cdef grammar.TextGrammar* _g = self.grammar.get() + for trule in rules: + if not isinstance(trule, BaseTRule): + raise ValueError('the grammar should contain TRule objects') + _g.AddRule(( trule).rule[0]) diff --git a/python/src/hypergraph.pxd b/python/src/hypergraph.pxd index 14c60dd0..e51ccf5c 100644 --- a/python/src/hypergraph.pxd +++ b/python/src/hypergraph.pxd @@ -1,18 +1,9 @@ from libcpp.string cimport string from libcpp.vector cimport vector from utils cimport * +from grammar cimport TRule from lattice cimport Lattice -cdef extern from "decoder/trule.h": - cdef cppclass TRule: - vector[WordID] f_ - vector[WordID] e_ - FastSparseVector[weight_t] scores_ - WordID lhs_ - int arity_ - bint IsUnary() - bint IsGoal() - cdef extern from "decoder/hg.h": cdef cppclass EdgeMask "std::vector": EdgeMask(int size) @@ -40,6 +31,7 @@ cdef extern from "decoder/hg.h": vector[HypergraphNode] nodes_ vector[HypergraphEdge] edges_ int GoalNode() + double NumberOfPaths() void Reweight(vector[weight_t]& weights) void Reweight(FastSparseVector& weights) bint PruneInsideOutside(double beam_alpha, @@ -83,3 +75,6 @@ cdef extern from "decoder/hg_sampler.h" namespace "HypergraphSampler": cdef extern from "decoder/csplit.h" namespace "CompoundSplit": int GetFullWordEdgeIndex(Hypergraph& forest) + +cdef extern from "decoder/inside_outside.h": + LogVal[double] InsideOutside "InsideOutside, EdgeFeaturesAndProbWeightFunction>" (Hypergraph& hg, FastSparseVector[LogVal[double]]* result) diff --git a/python/src/hypergraph.pxi b/python/src/hypergraph.pxi index 2e2c04a2..86751cc9 100644 --- a/python/src/hypergraph.pxi +++ b/python/src/hypergraph.pxi @@ -109,8 +109,6 @@ cdef class Hypergraph: else: raise TypeError('cannot reweight hypergraph with %s' % type(weights)) - # TODO get feature expectations, get partition function ("inside" score) - property edges: def __get__(self): cdef unsigned i @@ -127,19 +125,35 @@ cdef class Hypergraph: def __get__(self): return HypergraphNode().init(self.hg, self.hg.GoalNode()) - -include "trule.pxi" + property npaths: + def __get__(self): + return self.hg.NumberOfPaths() + + def inside_outside(self): + cdef FastSparseVector[LogVal[double]]* result = new FastSparseVector[LogVal[double]]() + cdef LogVal[double] z = hypergraph.InsideOutside(self.hg[0], result) + result[0] /= z + cdef SparseVector vector = SparseVector() + vector.vector = new FastSparseVector[double]() + cdef FastSparseVector[LogVal[double]].const_iterator* it = new FastSparseVector[LogVal[double]].const_iterator(result[0], False) + cdef unsigned i + for i in range(result.size()): + vector.vector.set_value(it[0].ptr().first, log(it[0].ptr().second)) + pinc(it[0]) # ++it + del it + del result + return vector cdef class HypergraphEdge: cdef hypergraph.Hypergraph* hg cdef hypergraph.HypergraphEdge* edge - cdef public TRule trule + cdef public BaseTRule trule cdef init(self, hypergraph.Hypergraph* hg, unsigned i): self.hg = hg self.edge = &hg.edges_[i] - self.trule = TRule() - self.trule.rule = self.edge.rule_.get() + self.trule = BaseTRule() + self.trule.rule = new shared_ptr[grammar.TRule](self.edge.rule_) return self def __len__(self): diff --git a/python/src/lattice.pxi b/python/src/lattice.pxi index c6b29e8b..08405188 100644 --- a/python/src/lattice.pxi +++ b/python/src/lattice.pxi @@ -3,7 +3,7 @@ cimport lattice cdef class Lattice: cdef lattice.Lattice* lattice - def __init__(self, inp): + def __cinit__(self, inp): if isinstance(inp, tuple): self.lattice = new lattice.Lattice(len(inp)) for i, arcs in enumerate(inp): diff --git a/python/src/trule.pxi b/python/src/trule.pxi deleted file mode 100644 index 6168014d..00000000 --- a/python/src/trule.pxi +++ /dev/null @@ -1,55 +0,0 @@ -def _phrase(phrase): - return ' '.join('[%s,%d]' % w if isinstance(w, tuple) else w.encode('utf8') for w in phrase) - -cdef class TRule: - cdef hypergraph.TRule* rule - - property arity: - def __get__(self): - return self.rule.arity_ - - property f: - def __get__(self): - cdef vector[WordID]* f = &self.rule.f_ - cdef WordID w - cdef words = [] - cdef unsigned i - cdef int idx = 0 - for i in range(f.size()): - w = f[0][i] - if w < 0: - idx += 1 - words.append((TDConvert(-w), idx)) - else: - words.append(unicode(TDConvert(w), encoding='utf8')) - return words - - property e: - def __get__(self): - cdef vector[WordID]* e = &self.rule.e_ - cdef WordID w - cdef words = [] - cdef unsigned i - cdef int idx = 0 - for i in range(e.size()): - w = e[0][i] - if w < 1: - idx += 1 - words.append((TDConvert(1-w), idx)) - else: - words.append(unicode(TDConvert(w), encoding='utf8')) - return words - - property scores: - def __get__(self): - cdef SparseVector scores = SparseVector() - scores.vector = new FastSparseVector[double](self.rule.scores_) - return scores - - property lhs: - def __get__(self): - return TDConvert(-self.rule.lhs_) - - def __str__(self): - scores = ' '.join('%s=%s' % feat for feat in self.scores) - return '[%s] ||| %s ||| %s ||| %s' % (self.lhs, _phrase(self.f), _phrase(self.e), scores) diff --git a/python/src/utils.pxd b/python/src/utils.pxd index 15e77c49..f4da686b 100644 --- a/python/src/utils.pxd +++ b/python/src/utils.pxd @@ -47,6 +47,7 @@ cdef extern from "utils/sparse_vector.h": bint operator==(FastSparseVector[T]&) T dot(vector[weight_t]&) # cython bug when [T] T dot(FastSparseVector[T]&) + void clear() FastSparseVector[weight_t] operator+(FastSparseVector[weight_t]&, FastSparseVector[weight_t]&) FastSparseVector[weight_t] operator-(FastSparseVector[weight_t]&, FastSparseVector[weight_t]&) @@ -82,6 +83,7 @@ cdef extern from "utils/sampler.h": cdef extern from "" namespace "boost": cdef cppclass shared_ptr[T]: + shared_ptr(T* ptr) shared_ptr(shared_ptr& r) T* get() diff --git a/python/src/vectors.pxi b/python/src/vectors.pxi index ce95968c..cd1c2598 100644 --- a/python/src/vectors.pxi +++ b/python/src/vectors.pxi @@ -54,6 +54,7 @@ cdef class SparseVector: def __iter__(self): cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) + cdef unsigned i try: for i in range(self.vector.size()): yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second) diff --git a/python/test.py b/python/test.py index 54859e81..eb9e6a95 100644 --- a/python/test.py +++ b/python/test.py @@ -45,6 +45,9 @@ for sentence in forest.sample(5): # Get feature vector for 1best fsrc = forest.viterbi_features() +# Feature expectations +print 'Feature expectations:', dict(forest.inside_outside()) + # 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),),) -- cgit v1.2.3 From eeef93717fed2901f6fcd2e3fd11118e0e309af7 Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Mon, 23 Jul 2012 19:59:44 -0400 Subject: [python] Evaluation metrics in Python --- python/cdec/__init__.py | 2 +- python/cdec/score.py | 2 +- python/src/_cdec.cpp | 1685 +++++++++++++++++++++++++++++++++++++---------- python/src/decoder.pxd | 2 - python/src/grammar.pxd | 1 - python/src/mteval.pxd | 13 +- python/src/mteval.pxi | 59 +- python/src/observer.h | 1 - python/src/py_scorer.h | 44 ++ sa-extract/Makefile | 10 +- 10 files changed, 1462 insertions(+), 357 deletions(-) create mode 100644 python/src/py_scorer.h (limited to 'python/src') diff --git a/python/cdec/__init__.py b/python/cdec/__init__.py index 89c323ba..19058493 100644 --- a/python/cdec/__init__.py +++ b/python/cdec/__init__.py @@ -1 +1 @@ -from _cdec import Decoder, Lattice, TRule, NT, NTRef +from _cdec import Decoder, Lattice, TRule, NT, NTRef, ParseFailed, InvalidConfig diff --git a/python/cdec/score.py b/python/cdec/score.py index c107446f..d9486ef2 100644 --- a/python/cdec/score.py +++ b/python/cdec/score.py @@ -1 +1 @@ -from _cdec import BLEU, TER +from _cdec import BLEU, TER, Metric diff --git a/python/src/_cdec.cpp b/python/src/_cdec.cpp index 3c95ca50..6d704b1d 100644 --- a/python/src/_cdec.cpp +++ b/python/src/_cdec.cpp @@ -1,4 +1,4 @@ -/* Generated by Cython 0.16 on Fri Jul 20 18:16:48 2012 */ +/* Generated by Cython 0.16 on Mon Jul 23 19:56:55 2012 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -301,6 +301,7 @@ #include "observer.h" #include "decoder/kbest.h" #include "mteval/ns.h" +#include "py_scorer.h" #include "training/candidate_set.h" #ifdef _OPENMP #include @@ -423,6 +424,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__; struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__; struct __pyx_obj_5_cdec_DenseVector; struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__; +struct __pyx_obj_5_cdec_Metric; struct __pyx_obj_5_cdec_SufficientStats; struct __pyx_obj_5_cdec___pyx_scope_struct_8_kbest; struct __pyx_obj_5_cdec___pyx_scope_struct_10_kbest_features; @@ -450,16 +452,17 @@ struct __pyx_opt_args_5_cdec_as_str { PyObject *error_msg; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":112 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":117 * return CandidateSet(self) * * cdef class Scorer: # <<<<<<<<<<<<<< * cdef string* name - * + * cdef mteval.EvaluationMetric* metric */ struct __pyx_obj_5_cdec_Scorer { PyObject_HEAD std::string *name; + EvaluationMetric *metric; }; @@ -561,7 +564,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":60 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":65 * return result * * cdef class CandidateSet: # <<<<<<<<<<<<<< @@ -634,7 +637,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":93 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":98 * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) * * cdef class SegmentEvaluator: # <<<<<<<<<<<<<< @@ -653,7 +656,7 @@ struct __pyx_obj_5_cdec_SegmentEvaluator { * * def __iter__(self): # <<<<<<<<<<<<<< * for i in range(len(self)): - * yield self.stats[0][i] + * yield self[i] */ struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__ { PyObject_HEAD @@ -850,7 +853,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":85 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":90 * return candidate * * def __iter__(self): # <<<<<<<<<<<<<< @@ -898,6 +901,19 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ { }; +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":173 + * out.fields[i] = ss[i] + * + * cdef class Metric: # <<<<<<<<<<<<<< + * cdef Scorer scorer + * def __cinit__(self): + */ +struct __pyx_obj_5_cdec_Metric { + PyObject_HEAD + struct __pyx_obj_5_cdec_Scorer *scorer; +}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":26 * return fmap * @@ -1330,6 +1346,8 @@ static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) { #define __Pyx_PyIter_Next(obj) __Pyx_PyIter_Next2(obj, NULL); static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject *, PyObject *); /*proto*/ +static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); /*proto*/ + static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */ #define __Pyx_PyObject_AsDouble(obj) \ ((likely(PyFloat_CheckExact(obj))) ? \ @@ -1523,6 +1541,7 @@ static PyTypeObject *__pyx_ptype_5_cdec_SufficientStats = 0; static PyTypeObject *__pyx_ptype_5_cdec_CandidateSet = 0; static PyTypeObject *__pyx_ptype_5_cdec_SegmentEvaluator = 0; static PyTypeObject *__pyx_ptype_5_cdec_Scorer = 0; +static PyTypeObject *__pyx_ptype_5_cdec_Metric = 0; static PyTypeObject *__pyx_ptype_5_cdec_Decoder = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct____iter__ = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_1___iter__ = 0; @@ -1551,6 +1570,8 @@ static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_23___cinit__ = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_24_genexpr = 0; static char *__pyx_f_5_cdec_as_str(PyObject *, struct __pyx_opt_args_5_cdec_as_str *__pyx_optional_args); /*proto*/ static struct __pyx_obj_5_cdec_SufficientStats *__pyx_f_5_cdec_as_stats(PyObject *, PyObject *); /*proto*/ +static float __pyx_f_5_cdec__compute_score(void *, SufficientStats *); /*proto*/ +static void __pyx_f_5_cdec__compute_sufficient_stats(void *, std::string *, std::vector *, SufficientStats *); /*proto*/ #define __Pyx_MODULE_NAME "_cdec" int __pyx_module_is_main__cdec = 0; @@ -1676,8 +1697,9 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_5score___get__(struct __pyx_o static PyObject *__pyx_pf_5_cdec_15SufficientStats_6detail___get__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self); /* proto */ static Py_ssize_t __pyx_pf_5_cdec_15SufficientStats_2__len__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__iadd__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__getitem__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self, int __pyx_v_index); /* proto */ +static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__iadd__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_15SufficientStats_11__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ static int __pyx_pf_5_cdec_12CandidateSet___cinit__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator); /* proto */ static void __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self); /* proto */ static Py_ssize_t __pyx_pf_5_cdec_12CandidateSet_4__len__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self); /* proto */ @@ -1687,10 +1709,14 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_11add_kbest(struct __pyx_obj_5_c static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, PyObject *__pyx_v_sentence); /* proto */ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self); /* proto */ -static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, char *__pyx_v_name); /* proto */ +static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_name); /* proto */ static void __pyx_pf_5_cdec_6Scorer_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Scorer *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs); /* proto */ static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_6Metric___cinit__(struct __pyx_obj_5_cdec_Metric *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_6Metric_2__call__(struct __pyx_obj_5_cdec_Metric *__pyx_v_self, PyObject *__pyx_v_refs); /* proto */ +static PyObject *__pyx_pf_5_cdec_6Metric_4score(CYTHON_UNUSED struct __pyx_obj_5_cdec_Metric *__pyx_v_stats); /* proto */ +static PyObject *__pyx_pf_5_cdec_6Metric_6evaluate(CYTHON_UNUSED struct __pyx_obj_5_cdec_Metric *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_hyp, CYTHON_UNUSED PyObject *__pyx_v_refs); /* proto */ static PyObject *__pyx_pf_5_cdec_2_make_config(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_config); /* proto */ static PyObject *__pyx_pf_5_cdec_7Decoder_9__cinit___genexpr(PyObject *__pyx_self); /* proto */ static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_config_str, PyObject *__pyx_v_config); /* proto */ @@ -1726,15 +1752,16 @@ static char __pyx_k_27[] = "digraph lattice {"; static char __pyx_k_35[] = "}"; static char __pyx_k_38[] = "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi"; static char __pyx_k_39[] = "\n"; -static char __pyx_k_41[] = "candidate set index out of range"; -static char __pyx_k_43[] = "%s %s"; -static char __pyx_k_44[] = "%s = %s"; -static char __pyx_k_46[] = "formalism \"%s\" unknown"; -static char __pyx_k_47[] = "cannot initialize weights with %s"; -static char __pyx_k_48[] = "#"; -static char __pyx_k_51[] = "Cannot translate input type %s"; -static char __pyx_k_54[] = "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi"; -static char __pyx_k_59[] = "/Users/vchahun/Sandbox/cdec/python/src/_cdec.pyx"; +static char __pyx_k_41[] = "sufficient stats vector index out of range"; +static char __pyx_k_43[] = "candidate set index out of range"; +static char __pyx_k_45[] = "%s %s"; +static char __pyx_k_46[] = "%s = %s"; +static char __pyx_k_48[] = "formalism \"%s\" unknown"; +static char __pyx_k_49[] = "cannot initialize weights with %s"; +static char __pyx_k_50[] = "#"; +static char __pyx_k_53[] = "Cannot translate input type %s"; +static char __pyx_k_56[] = "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi"; +static char __pyx_k_61[] = "/Users/vchahun/Sandbox/cdec/python/src/_cdec.pyx"; static char __pyx_k__a[] = "a"; static char __pyx_k__e[] = "e"; static char __pyx_k__f[] = "f"; @@ -1746,6 +1773,7 @@ static char __pyx_k__cat[] = "cat"; static char __pyx_k__dot[] = "dot"; static char __pyx_k__fst[] = "fst"; static char __pyx_k__get[] = "get"; +static char __pyx_k__hyp[] = "hyp"; static char __pyx_k__inp[] = "inp"; static char __pyx_k__key[] = "key"; static char __pyx_k__lhs[] = "lhs"; @@ -1769,6 +1797,7 @@ static char __pyx_k__label[] = "label"; static char __pyx_k__lines[] = "lines"; static char __pyx_k__range[] = "range"; static char __pyx_k__rules[] = "rules"; +static char __pyx_k__score[] = "score"; static char __pyx_k__split[] = "split"; static char __pyx_k__strip[] = "strip"; static char __pyx_k__value[] = "value"; @@ -1788,14 +1817,17 @@ static char __pyx_k__IBM_BLEU[] = "IBM_BLEU"; static char __pyx_k__KeyError[] = "KeyError"; static char __pyx_k____exit__[] = "__exit__"; static char __pyx_k____main__[] = "__main__"; +static char __pyx_k____name__[] = "__name__"; static char __pyx_k____test__[] = "__test__"; static char __pyx_k__encoding[] = "encoding"; +static char __pyx_k__evaluate[] = "evaluate"; static char __pyx_k__in_edges[] = "in_edges"; static char __pyx_k__lexalign[] = "lexalign"; static char __pyx_k__lextrans[] = "lextrans"; static char __pyx_k__sentence[] = "sentence"; static char __pyx_k__Exception[] = "Exception"; static char __pyx_k__TypeError[] = "TypeError"; +static char __pyx_k____class__[] = "__class__"; static char __pyx_k____enter__[] = "__enter__"; static char __pyx_k__enumerate[] = "enumerate"; static char __pyx_k__evaluator[] = "evaluator"; @@ -1835,13 +1867,14 @@ static PyObject *__pyx_kp_s_39; static PyObject *__pyx_kp_s_4; static PyObject *__pyx_kp_s_41; static PyObject *__pyx_kp_s_43; -static PyObject *__pyx_kp_s_44; +static PyObject *__pyx_kp_s_45; static PyObject *__pyx_kp_s_46; -static PyObject *__pyx_kp_s_47; static PyObject *__pyx_kp_s_48; -static PyObject *__pyx_kp_s_51; -static PyObject *__pyx_kp_s_54; -static PyObject *__pyx_kp_s_59; +static PyObject *__pyx_kp_s_49; +static PyObject *__pyx_kp_s_50; +static PyObject *__pyx_kp_s_53; +static PyObject *__pyx_kp_s_56; +static PyObject *__pyx_kp_s_61; static PyObject *__pyx_kp_s_7; static PyObject *__pyx_kp_s_8; static PyObject *__pyx_kp_s_9; @@ -1856,9 +1889,11 @@ static PyObject *__pyx_n_s__ParseFailed; static PyObject *__pyx_n_s__TER; static PyObject *__pyx_n_s__TypeError; static PyObject *__pyx_n_s__ValueError; +static PyObject *__pyx_n_s____class__; static PyObject *__pyx_n_s____enter__; static PyObject *__pyx_n_s____exit__; static PyObject *__pyx_n_s____main__; +static PyObject *__pyx_n_s____name__; static PyObject *__pyx_n_s____test__; static PyObject *__pyx_n_s___cdec; static PyObject *__pyx_n_s___make_config; @@ -1877,6 +1912,7 @@ static PyObject *__pyx_n_s__encode; static PyObject *__pyx_n_s__encoding; static PyObject *__pyx_n_s__enumerate; static PyObject *__pyx_n_s__eval; +static PyObject *__pyx_n_s__evaluate; static PyObject *__pyx_n_s__evaluator; static PyObject *__pyx_n_s__f; static PyObject *__pyx_n_s__formalism; @@ -1884,6 +1920,7 @@ static PyObject *__pyx_n_s__fst; static PyObject *__pyx_n_s__genexpr; static PyObject *__pyx_n_s__get; static PyObject *__pyx_n_s__grammar; +static PyObject *__pyx_n_s__hyp; static PyObject *__pyx_n_s__hypergraph; static PyObject *__pyx_n_s__i; static PyObject *__pyx_n_s__in_edges; @@ -1909,6 +1946,7 @@ static PyObject *__pyx_n_s__refs; static PyObject *__pyx_n_s__replace; static PyObject *__pyx_n_s__rules; static PyObject *__pyx_n_s__scfg; +static PyObject *__pyx_n_s__score; static PyObject *__pyx_n_s__scores; static PyObject *__pyx_n_s__self; static PyObject *__pyx_n_s__sentence; @@ -1936,16 +1974,17 @@ static PyObject *__pyx_k_tuple_33; static PyObject *__pyx_k_tuple_36; static PyObject *__pyx_k_tuple_40; static PyObject *__pyx_k_tuple_42; -static PyObject *__pyx_k_tuple_45; -static PyObject *__pyx_k_tuple_49; -static PyObject *__pyx_k_tuple_50; +static PyObject *__pyx_k_tuple_44; +static PyObject *__pyx_k_tuple_47; +static PyObject *__pyx_k_tuple_51; static PyObject *__pyx_k_tuple_52; -static PyObject *__pyx_k_tuple_55; -static PyObject *__pyx_k_tuple_56; +static PyObject *__pyx_k_tuple_54; static PyObject *__pyx_k_tuple_57; +static PyObject *__pyx_k_tuple_58; +static PyObject *__pyx_k_tuple_59; static PyObject *__pyx_k_codeobj_37; -static PyObject *__pyx_k_codeobj_53; -static PyObject *__pyx_k_codeobj_58; +static PyObject *__pyx_k_codeobj_55; +static PyObject *__pyx_k_codeobj_60; /* "_cdec.pyx":6 * cimport decoder @@ -7390,7 +7429,7 @@ static int __pyx_pf_5_cdec_11TextGrammar___cinit__(struct __pyx_obj_5_cdec_TextG * for trule in rules: * if not isinstance(trule, BaseTRule): # <<<<<<<<<<<<<< * raise ValueError('the grammar should contain TRule objects') - * _g.AddRule(( trule).rule[0]) + * _g.AddRule(( trule).rule[0]) */ __pyx_t_4 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_BaseTRule)); __Pyx_INCREF(__pyx_t_4); @@ -7403,7 +7442,7 @@ static int __pyx_pf_5_cdec_11TextGrammar___cinit__(struct __pyx_obj_5_cdec_TextG * for trule in rules: * if not isinstance(trule, BaseTRule): * raise ValueError('the grammar should contain TRule objects') # <<<<<<<<<<<<<< - * _g.AddRule(( trule).rule[0]) + * _g.AddRule(( trule).rule[0]) */ __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_14), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); @@ -7417,9 +7456,9 @@ static int __pyx_pf_5_cdec_11TextGrammar___cinit__(struct __pyx_obj_5_cdec_TextG /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":176 * if not isinstance(trule, BaseTRule): * raise ValueError('the grammar should contain TRule objects') - * _g.AddRule(( trule).rule[0]) # <<<<<<<<<<<<<< + * _g.AddRule(( trule).rule[0]) # <<<<<<<<<<<<<< */ - __pyx_v__g->AddRule((((struct __pyx_obj_5_cdec_TRule *)__pyx_v_trule)->__pyx_base.rule[0])); + __pyx_v__g->AddRule((((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_trule)->rule[0])); } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -13071,7 +13110,7 @@ static PyObject *__pyx_pw_5_cdec_15SufficientStats_5__iter__(PyObject *__pyx_v_s * * def __iter__(self): # <<<<<<<<<<<<<< * for i in range(len(self)): - * yield self.stats[0][i] + * yield self[i] */ static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { @@ -13118,7 +13157,6 @@ static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator14(__pyx_GeneratorO PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *(*__pyx_t_4)(PyObject *); - unsigned int __pyx_t_5; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { @@ -13135,7 +13173,7 @@ static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator14(__pyx_GeneratorO * * def __iter__(self): * for i in range(len(self)): # <<<<<<<<<<<<<< - * yield self.stats[0][i] + * yield self[i] * */ __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -13185,12 +13223,11 @@ static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator14(__pyx_GeneratorO /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":46 * def __iter__(self): * for i in range(len(self)): - * yield self.stats[0][i] # <<<<<<<<<<<<<< + * yield self[i] # <<<<<<<<<<<<<< * - * def __iadd__(SufficientStats self, SufficientStats other): + * def __getitem__(self, int index): */ - __pyx_t_5 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_i); if (unlikely((__pyx_t_5 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyFloat_FromDouble(((__pyx_cur_scope->__pyx_v_self->stats[0])[__pyx_t_5])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i); if (!__pyx_t_2) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; @@ -13226,13 +13263,111 @@ static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator14(__pyx_GeneratorO } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index) { + int __pyx_v_index; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + assert(__pyx_arg_index); { + __pyx_v_index = __Pyx_PyInt_AsInt(__pyx_arg_index); if (unlikely((__pyx_v_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.SufficientStats.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_7__getitem__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self), ((int)__pyx_v_index)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":48 + * yield self[i] + * + * def __getitem__(self, int index): # <<<<<<<<<<<<<< + * if not 0 <= index < len(self): + * raise IndexError('sufficient stats vector index out of range') + */ + +static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__getitem__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self, int __pyx_v_index) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + Py_ssize_t __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__getitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":49 + * + * def __getitem__(self, int index): + * if not 0 <= index < len(self): # <<<<<<<<<<<<<< + * raise IndexError('sufficient stats vector index out of range') + * return self.stats[0][index] + */ + __pyx_t_1 = (0 <= __pyx_v_index); + if (__pyx_t_1) { + __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = (__pyx_v_index < __pyx_t_2); + } + __pyx_t_3 = (!__pyx_t_1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":50 + * def __getitem__(self, int index): + * if not 0 <= index < len(self): + * raise IndexError('sufficient stats vector index out of range') # <<<<<<<<<<<<<< + * return self.stats[0][index] + * + */ + __pyx_t_4 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_42), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":51 + * if not 0 <= index < len(self): + * raise IndexError('sufficient stats vector index out of range') + * return self.stats[0][index] # <<<<<<<<<<<<<< + * + * def __iadd__(SufficientStats self, SufficientStats other): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = PyFloat_FromDouble(((__pyx_v_self->stats[0])[__pyx_v_index])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec.SufficientStats.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_10__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_10__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iadd__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SufficientStats, 1, "other", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_15SufficientStats_7__iadd__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_other)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SufficientStats, 1, "other", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_9__iadd__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_other)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -13241,20 +13376,20 @@ static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__iadd__(PyObject *__pyx_v_s return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":48 - * yield self.stats[0][i] +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":53 + * return self.stats[0][index] * * def __iadd__(SufficientStats self, SufficientStats other): # <<<<<<<<<<<<<< * self.stats[0] += other.stats[0] * return self */ -static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__iadd__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__iadd__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_other) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iadd__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":49 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":54 * * def __iadd__(SufficientStats self, SufficientStats other): * self.stats[0] += other.stats[0] # <<<<<<<<<<<<<< @@ -13263,7 +13398,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__iadd__(struct __pyx_obj_5_ */ (__pyx_v_self->stats[0]) += (__pyx_v_other->stats[0]); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":50 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":55 * def __iadd__(SufficientStats self, SufficientStats other): * self.stats[0] += other.stats[0] * return self # <<<<<<<<<<<<<< @@ -13283,17 +13418,17 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__iadd__(struct __pyx_obj_5_ } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_10__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_15SufficientStats_10__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_15SufficientStats_12__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_12__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__add__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_15SufficientStats_9__add__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_11__add__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":52 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":57 * return self * * def __add__(x, y): # <<<<<<<<<<<<<< @@ -13301,7 +13436,7 @@ static PyObject *__pyx_pw_5_cdec_15SufficientStats_10__add__(PyObject *__pyx_v_x * cdef SufficientStats sy = as_stats(y, x) */ -static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pf_5_cdec_15SufficientStats_11__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sx = 0; struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sy = 0; struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_result = 0; @@ -13313,43 +13448,43 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(PyObject *__pyx_v_x, int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__add__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":53 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":58 * * def __add__(x, y): * cdef SufficientStats sx = as_stats(x, y) # <<<<<<<<<<<<<< * cdef SufficientStats sy = as_stats(y, x) * cdef SufficientStats result = SufficientStats() */ - __pyx_t_1 = ((PyObject *)__pyx_f_5_cdec_as_stats(__pyx_v_x, __pyx_v_y)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = ((PyObject *)__pyx_f_5_cdec_as_stats(__pyx_v_x, __pyx_v_y)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_sx = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":54 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":59 * def __add__(x, y): * cdef SufficientStats sx = as_stats(x, y) * cdef SufficientStats sy = as_stats(y, x) # <<<<<<<<<<<<<< * cdef SufficientStats result = SufficientStats() * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) */ - __pyx_t_1 = ((PyObject *)__pyx_f_5_cdec_as_stats(__pyx_v_y, __pyx_v_x)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = ((PyObject *)__pyx_f_5_cdec_as_stats(__pyx_v_y, __pyx_v_x)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_sy = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":55 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":60 * cdef SufficientStats sx = as_stats(x, y) * cdef SufficientStats sy = as_stats(y, x) * cdef SufficientStats result = SufficientStats() # <<<<<<<<<<<<<< * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) * result.metric = sx.metric */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":56 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":61 * cdef SufficientStats sy = as_stats(y, x) * cdef SufficientStats result = SufficientStats() * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) # <<<<<<<<<<<<<< @@ -13358,7 +13493,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(PyObject *__pyx_v_x, */ __pyx_v_result->stats = new SufficientStats(operator+((__pyx_v_sx->stats[0]), (__pyx_v_sy->stats[0]))); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":57 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":62 * cdef SufficientStats result = SufficientStats() * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) * result.metric = sx.metric # <<<<<<<<<<<<<< @@ -13367,7 +13502,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(PyObject *__pyx_v_x, */ __pyx_v_result->metric = __pyx_v_sx->metric; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":58 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":63 * result.stats = new mteval.SufficientStats(mteval.add(sx.stats[0], sy.stats[0])) * result.metric = sx.metric * return result # <<<<<<<<<<<<<< @@ -13420,7 +13555,7 @@ static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyO else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; @@ -13431,13 +13566,13 @@ static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyO } 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[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.CandidateSet.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_evaluator), __pyx_ptype_5_cdec_SegmentEvaluator, 1, "evaluator", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_evaluator), __pyx_ptype_5_cdec_SegmentEvaluator, 1, "evaluator", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = __pyx_pf_5_cdec_12CandidateSet___cinit__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), __pyx_v_evaluator); goto __pyx_L0; __pyx_L1_error:; @@ -13447,7 +13582,7 @@ static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyO return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":65 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":70 * cdef mteval.CandidateSet* cs * * def __cinit__(self, SegmentEvaluator evaluator): # <<<<<<<<<<<<<< @@ -13460,7 +13595,7 @@ static int __pyx_pf_5_cdec_12CandidateSet___cinit__(struct __pyx_obj_5_cdec_Cand __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":66 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":71 * * def __cinit__(self, SegmentEvaluator evaluator): * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) # <<<<<<<<<<<<<< @@ -13469,7 +13604,7 @@ static int __pyx_pf_5_cdec_12CandidateSet___cinit__(struct __pyx_obj_5_cdec_Cand */ __pyx_v_self->scorer = new boost::shared_ptr((__pyx_v_evaluator->scorer[0])); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":67 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":72 * def __cinit__(self, SegmentEvaluator evaluator): * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) * self.metric = evaluator.metric # <<<<<<<<<<<<<< @@ -13478,7 +13613,7 @@ static int __pyx_pf_5_cdec_12CandidateSet___cinit__(struct __pyx_obj_5_cdec_Cand */ __pyx_v_self->metric = __pyx_v_evaluator->metric; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":68 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":73 * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) * self.metric = evaluator.metric * self.cs = new mteval.CandidateSet() # <<<<<<<<<<<<<< @@ -13501,7 +13636,7 @@ static void __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(PyObject *__pyx_v_self) __Pyx_RefNannyFinishContext(); } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":70 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":75 * self.cs = new mteval.CandidateSet() * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -13513,7 +13648,7 @@ static void __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(CYTHON_UNUSED struct __p __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":71 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":76 * * def __dealloc__(self): * del self.scorer # <<<<<<<<<<<<<< @@ -13522,7 +13657,7 @@ static void __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(CYTHON_UNUSED struct __p */ delete __pyx_v_self->scorer; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":72 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":77 * def __dealloc__(self): * del self.scorer * del self.cs # <<<<<<<<<<<<<< @@ -13545,7 +13680,7 @@ static Py_ssize_t __pyx_pw_5_cdec_12CandidateSet_5__len__(PyObject *__pyx_v_self return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":74 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":79 * del self.cs * * def __len__(self): # <<<<<<<<<<<<<< @@ -13558,7 +13693,7 @@ static Py_ssize_t __pyx_pf_5_cdec_12CandidateSet_4__len__(struct __pyx_obj_5_cde __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__len__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":75 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":80 * * def __len__(self): * return self.cs.size() # <<<<<<<<<<<<<< @@ -13582,7 +13717,7 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_s __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); assert(__pyx_arg_k); { - __pyx_v_k = __Pyx_PyInt_AsInt(__pyx_arg_k); if (unlikely((__pyx_v_k == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_k = __Pyx_PyInt_AsInt(__pyx_arg_k); if (unlikely((__pyx_v_k == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -13595,7 +13730,7 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_s return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":77 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 * return self.cs.size() * * def __getitem__(self,int k): # <<<<<<<<<<<<<< @@ -13615,7 +13750,7 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__getitem__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":78 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":83 * * def __getitem__(self,int k): * if not 0 <= k < self.cs.size(): # <<<<<<<<<<<<<< @@ -13629,35 +13764,35 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_ __pyx_t_2 = (!__pyx_t_1); if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":79 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":84 * def __getitem__(self,int k): * if not 0 <= k < self.cs.size(): * raise IndexError('candidate set index out of range') # <<<<<<<<<<<<<< * cdef Candidate candidate = Candidate() * candidate.candidate = &self.cs[0][k] */ - __pyx_t_3 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_42), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_44), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":80 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":85 * if not 0 <= k < self.cs.size(): * raise IndexError('candidate set index out of range') * cdef Candidate candidate = Candidate() # <<<<<<<<<<<<<< * candidate.candidate = &self.cs[0][k] * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) */ - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Candidate)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Candidate)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_v_candidate = ((struct __pyx_obj_5_cdec_Candidate *)__pyx_t_3); __pyx_t_3 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":81 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":86 * raise IndexError('candidate set index out of range') * cdef Candidate candidate = Candidate() * candidate.candidate = &self.cs[0][k] # <<<<<<<<<<<<<< @@ -13666,7 +13801,7 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_ */ __pyx_v_candidate->candidate = (&((__pyx_v_self->cs[0])[__pyx_v_k])); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":87 * cdef Candidate candidate = Candidate() * candidate.candidate = &self.cs[0][k] * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) # <<<<<<<<<<<<<< @@ -13675,7 +13810,7 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_ */ __pyx_v_candidate->score = __pyx_v_self->metric->ComputeScore(((__pyx_v_self->cs[0])[__pyx_v_k]).eval_feats); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":83 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":88 * candidate.candidate = &self.cs[0][k] * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) * return candidate # <<<<<<<<<<<<<< @@ -13712,7 +13847,7 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_9__iter__(PyObject *__pyx_v_self return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":85 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":90 * return candidate * * def __iter__(self): # <<<<<<<<<<<<<< @@ -13738,7 +13873,7 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_8__iter__(struct __pyx_obj_5_cde __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12CandidateSet_10generator15, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12CandidateSet_10generator15, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -13773,27 +13908,27 @@ static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator15(__pyx_GeneratorObj return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":87 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":92 * def __iter__(self): * cdef unsigned i * for i in range(len(self)): # <<<<<<<<<<<<<< * yield self[i] * */ - __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":88 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":93 * cdef unsigned i * for i in range(len(self)): * yield self[i] # <<<<<<<<<<<<<< * * def add_kbest(self, Hypergraph hypergraph, unsigned k): */ - __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; @@ -13807,7 +13942,7 @@ static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator15(__pyx_GeneratorObj __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[5]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; @@ -13851,11 +13986,11 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_se values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k); if (likely(values[1])) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, 1); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, 1); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_kbest") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_kbest") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; @@ -13864,17 +13999,17 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_se values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_hypergraph = ((struct __pyx_obj_5_cdec_Hypergraph *)values[0]); - __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.CandidateSet.add_kbest", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_hypergraph), __pyx_ptype_5_cdec_Hypergraph, 1, "hypergraph", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_hypergraph), __pyx_ptype_5_cdec_Hypergraph, 1, "hypergraph", 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = __pyx_pf_5_cdec_12CandidateSet_11add_kbest(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), __pyx_v_hypergraph, __pyx_v_k); goto __pyx_L0; __pyx_L1_error:; @@ -13884,7 +14019,7 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_se return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":90 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":95 * yield self[i] * * def add_kbest(self, Hypergraph hypergraph, unsigned k): # <<<<<<<<<<<<<< @@ -13897,7 +14032,7 @@ static PyObject *__pyx_pf_5_cdec_12CandidateSet_11add_kbest(struct __pyx_obj_5_c __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("add_kbest", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":91 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":96 * * def add_kbest(self, Hypergraph hypergraph, unsigned k): * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) # <<<<<<<<<<<<<< @@ -13921,7 +14056,7 @@ static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_se __Pyx_RefNannyFinishContext(); } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":97 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":102 * cdef mteval.EvaluationMetric* metric * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -13933,7 +14068,7 @@ static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":98 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":103 * * def __dealloc__(self): * del self.scorer # <<<<<<<<<<<<<< @@ -13956,7 +14091,7 @@ static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_ return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":100 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":105 * del self.scorer * * def evaluate(self, sentence): # <<<<<<<<<<<<<< @@ -13976,19 +14111,19 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5 int __pyx_clineno = 0; __Pyx_RefNannySetupContext("evaluate", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":102 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":107 * def evaluate(self, sentence): * cdef vector[WordID] hyp * cdef SufficientStats sf = SufficientStats() # <<<<<<<<<<<<<< * sf.metric = self.metric * sf.stats = new mteval.SufficientStats() */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_sf = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":103 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":108 * cdef vector[WordID] hyp * cdef SufficientStats sf = SufficientStats() * sf.metric = self.metric # <<<<<<<<<<<<<< @@ -13997,7 +14132,7 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5 */ __pyx_v_sf->metric = __pyx_v_self->metric; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":104 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":109 * cdef SufficientStats sf = SufficientStats() * sf.metric = self.metric * sf.stats = new mteval.SufficientStats() # <<<<<<<<<<<<<< @@ -14006,22 +14141,22 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5 */ __pyx_v_sf->stats = new SufficientStats(); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":105 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":110 * sf.metric = self.metric * sf.stats = new mteval.SufficientStats() * ConvertSentence(string(as_str(sentence.strip())), &hyp) # <<<<<<<<<<<<<< * self.scorer.get().Evaluate(hyp, sf.stats) * return sf */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_2, NULL)), (&__pyx_v_hyp)); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":106 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":111 * sf.stats = new mteval.SufficientStats() * ConvertSentence(string(as_str(sentence.strip())), &hyp) * self.scorer.get().Evaluate(hyp, sf.stats) # <<<<<<<<<<<<<< @@ -14030,7 +14165,7 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5 */ __pyx_v_self->scorer->get()->Evaluate(__pyx_v_hyp, __pyx_v_sf->stats); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":107 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":112 * ConvertSentence(string(as_str(sentence.strip())), &hyp) * self.scorer.get().Evaluate(hyp, sf.stats) * return sf # <<<<<<<<<<<<<< @@ -14067,7 +14202,7 @@ static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__p return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":109 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":114 * return sf * * def candidate_set(self): # <<<<<<<<<<<<<< @@ -14085,7 +14220,7 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("candidate_set", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":110 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 * * def candidate_set(self): * return CandidateSet(self) # <<<<<<<<<<<<<< @@ -14093,12 +14228,12 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_ * cdef class Scorer: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_CandidateSet)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_CandidateSet)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; @@ -14121,13 +14256,22 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_ /* Python wrapper */ static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - char *__pyx_v_name; + PyObject *__pyx_v_name = 0; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__name,0}; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); { PyObject* values[1] = {0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":121 + * cdef mteval.EvaluationMetric* metric + * + * def __cinit__(self, bytes name=None): # <<<<<<<<<<<<<< + * if name: + * self.name = new string(name) + */ + values[0] = ((PyObject*)Py_None); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); @@ -14139,56 +14283,89 @@ static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject * kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__name); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__name); + if (value) { values[0] = value; kw_args--; } + } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 121; __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); + 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; + } } - __pyx_v_name = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_name = ((PyObject*)values[0]); } 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[5]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.Scorer.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_name), (&PyBytes_Type), 1, "name", 1))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = __pyx_pf_5_cdec_6Scorer___cinit__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self), __pyx_v_name); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 - * cdef string* name - * - * def __cinit__(self, char* name): # <<<<<<<<<<<<<< - * self.name = new string(name) - * - */ - -static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, char *__pyx_v_name) { +static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_name) { int __pyx_r; __Pyx_RefNannyDeclarations + int __pyx_t_1; + char *__pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":116 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":122 + * + * def __cinit__(self, bytes name=None): + * if name: # <<<<<<<<<<<<<< + * self.name = new string(name) + * self.metric = mteval.MetricInstance(self.name[0]) + */ + __pyx_t_1 = (((PyObject *)__pyx_v_name) != Py_None) && (PyBytes_GET_SIZE(((PyObject *)__pyx_v_name)) != 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":123 + * def __cinit__(self, bytes name=None): + * if name: + * self.name = new string(name) # <<<<<<<<<<<<<< + * self.metric = mteval.MetricInstance(self.name[0]) * - * def __cinit__(self, char* name): - * self.name = new string(name) # <<<<<<<<<<<<<< + */ + __pyx_t_2 = PyBytes_AsString(((PyObject *)__pyx_v_name)); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->name = new std::string(__pyx_t_2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":124 + * if name: + * self.name = new string(name) + * self.metric = mteval.MetricInstance(self.name[0]) # <<<<<<<<<<<<<< * * def __dealloc__(self): */ - __pyx_v_self->name = new std::string(__pyx_v_name); + __pyx_v_self->metric = EvaluationMetric::Instance((__pyx_v_self->name[0])); + goto __pyx_L3; + } + __pyx_L3:; __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Scorer.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } @@ -14202,8 +14379,8 @@ static void __pyx_pw_5_cdec_6Scorer_3__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyFinishContext(); } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":118 - * self.name = new string(name) +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":126 + * self.metric = mteval.MetricInstance(self.name[0]) * * def __dealloc__(self): # <<<<<<<<<<<<<< * del self.name @@ -14214,7 +14391,7 @@ static void __pyx_pf_5_cdec_6Scorer_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_ __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":119 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":127 * * def __dealloc__(self): * del self.name # <<<<<<<<<<<<<< @@ -14252,7 +14429,7 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObj else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; @@ -14263,7 +14440,7 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObj } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.Scorer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -14274,16 +14451,15 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObj return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":121 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":129 * del self.name * * def __call__(self, refs): # <<<<<<<<<<<<<< - * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) * if isinstance(refs, unicode) or isinstance(refs, str): + * refs = [refs] */ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs) { - EvaluationMetric *__pyx_v_metric; std::vector > *__pyx_v_refsv; std::vector *__pyx_v_refv; PyObject *__pyx_v_ref = NULL; @@ -14304,18 +14480,9 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score __Pyx_RefNannySetupContext("__call__", 0); __Pyx_INCREF(__pyx_v_refs); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":122 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":130 * * def __call__(self, refs): - * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) # <<<<<<<<<<<<<< - * if isinstance(refs, unicode) or isinstance(refs, str): - * refs = [refs] - */ - __pyx_v_metric = EvaluationMetric::Instance((__pyx_v_self->name[0])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":123 - * def __call__(self, refs): - * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) * if isinstance(refs, unicode) or isinstance(refs, str): # <<<<<<<<<<<<<< * refs = [refs] * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() @@ -14335,14 +14502,14 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score } if (__pyx_t_4) { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":124 - * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":131 + * def __call__(self, refs): * if isinstance(refs, unicode) or isinstance(refs, str): * refs = [refs] # <<<<<<<<<<<<<< * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() * cdef vector[WordID]* refv */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_refs); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_refs); @@ -14354,7 +14521,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":125 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":132 * if isinstance(refs, unicode) or isinstance(refs, str): * refs = [refs] * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() # <<<<<<<<<<<<<< @@ -14363,7 +14530,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_refsv = new std::vector >(); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":128 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":135 * cdef vector[WordID]* refv * cdef bytes ref_str * for ref in refs: # <<<<<<<<<<<<<< @@ -14374,7 +14541,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score __pyx_t_1 = __pyx_v_refs; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0; __pyx_t_6 = NULL; } else { - __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_refs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_refs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; } @@ -14390,7 +14557,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score if (unlikely(!__pyx_t_7)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } @@ -14400,7 +14567,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score __pyx_v_ref = __pyx_t_7; __pyx_t_7 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":129 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":136 * cdef bytes ref_str * for ref in refs: * refv = new vector[WordID]() # <<<<<<<<<<<<<< @@ -14409,22 +14576,22 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_refv = new std::vector(); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":130 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":137 * for ref in refs: * refv = new vector[WordID]() * ConvertSentence(string(as_str(ref.strip())), refv) # <<<<<<<<<<<<<< * refsv.push_back(refv[0]) * del refv */ - __pyx_t_7 = PyObject_GetAttr(__pyx_v_ref, __pyx_n_s__strip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PyObject_GetAttr(__pyx_v_ref, __pyx_n_s__strip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_8, NULL)), __pyx_v_refv); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":131 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":138 * refv = new vector[WordID]() * ConvertSentence(string(as_str(ref.strip())), refv) * refsv.push_back(refv[0]) # <<<<<<<<<<<<<< @@ -14433,7 +14600,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_refsv->push_back((__pyx_v_refv[0])); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":132 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":139 * ConvertSentence(string(as_str(ref.strip())), refv) * refsv.push_back(refv[0]) * del refv # <<<<<<<<<<<<<< @@ -14444,47 +14611,47 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":134 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":141 * del refv * cdef unsigned i * cdef SegmentEvaluator evaluator = SegmentEvaluator() # <<<<<<<<<<<<<< - * evaluator.metric = metric - * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + * evaluator.metric = self.metric + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator]( */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SegmentEvaluator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SegmentEvaluator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_evaluator = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":135 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":142 * cdef unsigned i * cdef SegmentEvaluator evaluator = SegmentEvaluator() - * evaluator.metric = metric # <<<<<<<<<<<<<< - * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) - * del refsv # in theory should not delete but store in SegmentEvaluator + * evaluator.metric = self.metric # <<<<<<<<<<<<<< + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator]( + * self.metric.CreateSegmentEvaluator(refsv[0])) */ - __pyx_v_evaluator->metric = __pyx_v_metric; + __pyx_v_evaluator->metric = __pyx_v_self->metric; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":136 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":143 * cdef SegmentEvaluator evaluator = SegmentEvaluator() - * evaluator.metric = metric - * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) # <<<<<<<<<<<<<< + * evaluator.metric = self.metric + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator]( # <<<<<<<<<<<<<< + * self.metric.CreateSegmentEvaluator(refsv[0])) * del refsv # in theory should not delete but store in SegmentEvaluator - * return evaluator */ - __pyx_v_evaluator->scorer = new boost::shared_ptr(__pyx_v_metric->CreateSegmentEvaluator((__pyx_v_refsv[0]))); + __pyx_v_evaluator->scorer = new boost::shared_ptr(__pyx_v_self->metric->CreateSegmentEvaluator((__pyx_v_refsv[0]))); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":137 - * evaluator.metric = metric - * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":145 + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator]( + * self.metric.CreateSegmentEvaluator(refsv[0])) * del refsv # in theory should not delete but store in SegmentEvaluator # <<<<<<<<<<<<<< * return evaluator * */ delete __pyx_v_refsv; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":138 - * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":146 + * self.metric.CreateSegmentEvaluator(refsv[0])) * del refsv # in theory should not delete but store in SegmentEvaluator * return evaluator # <<<<<<<<<<<<<< * @@ -14523,7 +14690,7 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_7__str__(PyObject *__pyx_v_self) { return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":140 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":148 * return evaluator * * def __str__(self): # <<<<<<<<<<<<<< @@ -14540,15 +14707,15 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__str__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":141 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":149 * * def __str__(self): * return self.name.c_str() # <<<<<<<<<<<<<< * - * BLEU = Scorer('IBM_BLEU') + * cdef float _compute_score(void* metric_, mteval.SufficientStats* stats): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(__pyx_v_self->name->c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(__pyx_v_self->name->c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; @@ -14565,71 +14732,661 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_4generator16(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ - -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_3_make_config(PyObject *__pyx_self, PyObject *__pyx_v_config); /*proto*/ -static PyMethodDef __pyx_mdef_5_cdec_3_make_config = {__Pyx_NAMESTR("_make_config"), (PyCFunction)__pyx_pw_5_cdec_3_make_config, METH_O, __Pyx_DOCSTR(0)}; -static PyObject *__pyx_pw_5_cdec_3_make_config(PyObject *__pyx_self, PyObject *__pyx_v_config) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_make_config (wrapper)", 0); - __pyx_self = __pyx_self; - __pyx_r = __pyx_pf_5_cdec_2_make_config(__pyx_self, ((PyObject *)__pyx_v_config)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -/* "_cdec.pyx":28 - * class ParseFailed(Exception): pass +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":151 + * return self.name.c_str() * - * def _make_config(config): # <<<<<<<<<<<<<< - * for key, value in config.items(): - * if isinstance(value, dict): + * cdef float _compute_score(void* metric_, mteval.SufficientStats* stats): # <<<<<<<<<<<<<< + * cdef Metric metric = metric_ + * cdef list ss = [] */ -static PyObject *__pyx_pf_5_cdec_2_make_config(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_config) { - struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *__pyx_cur_scope; - PyObject *__pyx_r = NULL; +static float __pyx_f_5_cdec__compute_score(void *__pyx_v_metric_, SufficientStats *__pyx_v_stats) { + struct __pyx_obj_5_cdec_Metric *__pyx_v_metric = 0; + PyObject *__pyx_v_ss = 0; + unsigned int __pyx_v_i; + float __pyx_r; __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + unsigned int __pyx_t_2; + unsigned int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + float __pyx_t_7; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_make_config", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *)__pyx_ptype_5_cdec___pyx_scope_struct_22__make_config->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_22__make_config, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_v_config = __pyx_v_config; - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_config); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_config); - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_4generator16, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } + __Pyx_RefNannySetupContext("_compute_score", 0); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec._make_config", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":152 + * + * cdef float _compute_score(void* metric_, mteval.SufficientStats* stats): + * cdef Metric metric = metric_ # <<<<<<<<<<<<<< + * cdef list ss = [] + * cdef unsigned i + */ + __Pyx_INCREF(((PyObject *)((struct __pyx_obj_5_cdec_Metric *)__pyx_v_metric_))); + __pyx_v_metric = ((struct __pyx_obj_5_cdec_Metric *)__pyx_v_metric_); -static PyObject *__pyx_gb_5_cdec_4generator16(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":153 + * cdef float _compute_score(void* metric_, mteval.SufficientStats* stats): + * cdef Metric metric = metric_ + * cdef list ss = [] # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(stats.size()): + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_ss = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":155 + * cdef list ss = [] + * cdef unsigned i + * for i in range(stats.size()): # <<<<<<<<<<<<<< + * ss.append(stats[0][i]) + * return metric.score(ss) + */ + __pyx_t_2 = __pyx_v_stats->size(); + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":156 + * cdef unsigned i + * for i in range(stats.size()): + * ss.append(stats[0][i]) # <<<<<<<<<<<<<< + * return metric.score(ss) + * + */ + __pyx_t_1 = PyFloat_FromDouble(((__pyx_v_stats[0])[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyList_Append(__pyx_v_ss, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":157 + * for i in range(stats.size()): + * ss.append(stats[0][i]) + * return metric.score(ss) # <<<<<<<<<<<<<< + * + * cdef void _compute_sufficient_stats(void* metric_, + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_metric), __pyx_n_s__score); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(((PyObject *)__pyx_v_ss)); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_ss)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_ss)); + __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_7 = __pyx_PyFloat_AsFloat(__pyx_t_6); if (unlikely((__pyx_t_7 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_r = __pyx_t_7; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_WriteUnraisable("_cdec._compute_score", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_metric); + __Pyx_XDECREF(__pyx_v_ss); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":159 + * return metric.score(ss) + * + * cdef void _compute_sufficient_stats(void* metric_, # <<<<<<<<<<<<<< + * string* hyp, + * vector[string]* refs, + */ + +static void __pyx_f_5_cdec__compute_sufficient_stats(void *__pyx_v_metric_, std::string *__pyx_v_hyp, std::vector *__pyx_v_refs, SufficientStats *__pyx_v_out) { + struct __pyx_obj_5_cdec_Metric *__pyx_v_metric = 0; + PyObject *__pyx_v_refs_ = 0; + unsigned int __pyx_v_i; + PyObject *__pyx_v_ss = 0; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + size_t __pyx_t_2; + unsigned int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + Py_ssize_t __pyx_t_7; + float __pyx_t_8; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_compute_sufficient_stats", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":163 + * vector[string]* refs, + * mteval.SufficientStats* out): + * cdef Metric metric = metric_ # <<<<<<<<<<<<<< + * cdef list refs_ = [] + * cdef unsigned i + */ + __Pyx_INCREF(((PyObject *)((struct __pyx_obj_5_cdec_Metric *)__pyx_v_metric_))); + __pyx_v_metric = ((struct __pyx_obj_5_cdec_Metric *)__pyx_v_metric_); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":164 + * mteval.SufficientStats* out): + * cdef Metric metric = metric_ + * cdef list refs_ = [] # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(refs.size()): + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_refs_ = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":166 + * cdef list refs_ = [] + * cdef unsigned i + * for i in range(refs.size()): # <<<<<<<<<<<<<< + * refs_.append(refs[0][i].c_str()) + * cdef list ss = metric.evaluate(hyp.c_str(), refs_) + */ + __pyx_t_2 = __pyx_v_refs->size(); + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":167 + * cdef unsigned i + * for i in range(refs.size()): + * refs_.append(refs[0][i].c_str()) # <<<<<<<<<<<<<< + * cdef list ss = metric.evaluate(hyp.c_str(), refs_) + * out.fields.resize(len(ss)) + */ + __pyx_t_1 = PyBytes_FromString(((__pyx_v_refs[0])[__pyx_v_i]).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_4 = PyList_Append(__pyx_v_refs_, ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":168 + * for i in range(refs.size()): + * refs_.append(refs[0][i].c_str()) + * cdef list ss = metric.evaluate(hyp.c_str(), refs_) # <<<<<<<<<<<<<< + * out.fields.resize(len(ss)) + * for i in range(len(ss)): + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_metric), __pyx_n_s__evaluate); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyBytes_FromString(__pyx_v_hyp->c_str()); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); + __Pyx_INCREF(((PyObject *)__pyx_v_refs_)); + PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_v_refs_)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_refs_)); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + if (!(likely(PyList_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected list, got %.200s", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_ss = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":169 + * refs_.append(refs[0][i].c_str()) + * cdef list ss = metric.evaluate(hyp.c_str(), refs_) + * out.fields.resize(len(ss)) # <<<<<<<<<<<<<< + * for i in range(len(ss)): + * out.fields[i] = ss[i] + */ + if (unlikely(((PyObject *)__pyx_v_ss) == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_7 = PyList_GET_SIZE(((PyObject *)__pyx_v_ss)); + __pyx_v_out->fields.resize(__pyx_t_7); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":170 + * cdef list ss = metric.evaluate(hyp.c_str(), refs_) + * out.fields.resize(len(ss)) + * for i in range(len(ss)): # <<<<<<<<<<<<<< + * out.fields[i] = ss[i] + * + */ + if (unlikely(((PyObject *)__pyx_v_ss) == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_7 = PyList_GET_SIZE(((PyObject *)__pyx_v_ss)); + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_7; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":171 + * out.fields.resize(len(ss)) + * for i in range(len(ss)): + * out.fields[i] = ss[i] # <<<<<<<<<<<<<< + * + * cdef class Metric: + */ + __pyx_t_5 = __Pyx_GetItemInt_List(((PyObject *)__pyx_v_ss), __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = __pyx_PyFloat_AsFloat(__pyx_t_5); if (unlikely((__pyx_t_8 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + (__pyx_v_out->fields[__pyx_v_i]) = __pyx_t_8; + } + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_WriteUnraisable("_cdec._compute_sufficient_stats", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_metric); + __Pyx_XDECREF(__pyx_v_refs_); + __Pyx_XDECREF(__pyx_v_ss); + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_6Metric_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_6Metric_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; + __pyx_r = __pyx_pf_5_cdec_6Metric___cinit__(((struct __pyx_obj_5_cdec_Metric *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":175 + * cdef class Metric: + * cdef Scorer scorer + * def __cinit__(self): # <<<<<<<<<<<<<< + * self.scorer = Scorer() + * self.scorer.name = new string(as_str(self.__class__.__name__)) + */ + +static int __pyx_pf_5_cdec_6Metric___cinit__(struct __pyx_obj_5_cdec_Metric *__pyx_v_self) { + int __pyx_r; + __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("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":176 + * cdef Scorer scorer + * def __cinit__(self): + * self.scorer = Scorer() # <<<<<<<<<<<<<< + * self.scorer.name = new string(as_str(self.__class__.__name__)) + * self.scorer.metric = mteval.PyMetricInstance(self.scorer.name[0], + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->scorer); + __Pyx_DECREF(((PyObject *)__pyx_v_self->scorer)); + __pyx_v_self->scorer = ((struct __pyx_obj_5_cdec_Scorer *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":177 + * def __cinit__(self): + * self.scorer = Scorer() + * self.scorer.name = new string(as_str(self.__class__.__name__)) # <<<<<<<<<<<<<< + * self.scorer.metric = mteval.PyMetricInstance(self.scorer.name[0], + * self, _compute_sufficient_stats, _compute_score) + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s____class__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____name__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_self->scorer->name = new std::string(__pyx_f_5_cdec_as_str(__pyx_t_2, NULL)); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":178 + * self.scorer = Scorer() + * self.scorer.name = new string(as_str(self.__class__.__name__)) + * self.scorer.metric = mteval.PyMetricInstance(self.scorer.name[0], # <<<<<<<<<<<<<< + * self, _compute_sufficient_stats, _compute_score) + * + */ + __pyx_v_self->scorer->metric = PythonEvaluationMetric::Instance((__pyx_v_self->scorer->name[0]), ((void *)__pyx_v_self), __pyx_f_5_cdec__compute_sufficient_stats, __pyx_f_5_cdec__compute_score); + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec.Metric.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_6Metric_3__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_6Metric_3__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_refs = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__refs,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__call__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__refs); + 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, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 181; __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_refs = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.Metric.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_6Metric_2__call__(((struct __pyx_obj_5_cdec_Metric *)__pyx_v_self), __pyx_v_refs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":181 + * self, _compute_sufficient_stats, _compute_score) + * + * def __call__(self, refs): # <<<<<<<<<<<<<< + * return self.scorer(refs) + * + */ + +static PyObject *__pyx_pf_5_cdec_6Metric_2__call__(struct __pyx_obj_5_cdec_Metric *__pyx_v_self, PyObject *__pyx_v_refs) { + 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("__call__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":182 + * + * def __call__(self, refs): + * return self.scorer(refs) # <<<<<<<<<<<<<< + * + * def score(SufficientStats stats): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_refs); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_refs); + __Pyx_GIVEREF(__pyx_v_refs); + __pyx_t_2 = PyObject_Call(((PyObject *)__pyx_v_self->scorer), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__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.Metric.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_6Metric_5score(PyObject *__pyx_v_stats, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_6Metric_5score(PyObject *__pyx_v_stats, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("score (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_6Metric_4score(((struct __pyx_obj_5_cdec_Metric *)__pyx_v_stats)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":184 + * return self.scorer(refs) + * + * def score(SufficientStats stats): # <<<<<<<<<<<<<< + * return 0 + * + */ + +static PyObject *__pyx_pf_5_cdec_6Metric_4score(CYTHON_UNUSED struct __pyx_obj_5_cdec_Metric *__pyx_v_stats) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("score", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":185 + * + * def score(SufficientStats stats): + * return 0 # <<<<<<<<<<<<<< + * + * def evaluate(self, hyp, refs): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_int_0); + __pyx_r = __pyx_int_0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_6Metric_7evaluate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_6Metric_7evaluate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + CYTHON_UNUSED PyObject *__pyx_v_hyp = 0; + CYTHON_UNUSED PyObject *__pyx_v_refs = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__hyp,&__pyx_n_s__refs,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("evaluate (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__hyp); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__refs); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("evaluate", 1, 2, 2, 1); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "evaluate") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_hyp = values[0]; + __pyx_v_refs = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("evaluate", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.Metric.evaluate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_6Metric_6evaluate(((struct __pyx_obj_5_cdec_Metric *)__pyx_v_self), __pyx_v_hyp, __pyx_v_refs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":187 + * return 0 + * + * def evaluate(self, hyp, refs): # <<<<<<<<<<<<<< + * return [] + * + */ + +static PyObject *__pyx_pf_5_cdec_6Metric_6evaluate(CYTHON_UNUSED struct __pyx_obj_5_cdec_Metric *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_hyp, CYTHON_UNUSED PyObject *__pyx_v_refs) { + 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("evaluate", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":188 + * + * def evaluate(self, hyp, refs): + * return [] # <<<<<<<<<<<<<< + * + * BLEU = Scorer('IBM_BLEU') + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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.Metric.evaluate", __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_4generator16(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_3_make_config(PyObject *__pyx_self, PyObject *__pyx_v_config); /*proto*/ +static PyMethodDef __pyx_mdef_5_cdec_3_make_config = {__Pyx_NAMESTR("_make_config"), (PyCFunction)__pyx_pw_5_cdec_3_make_config, METH_O, __Pyx_DOCSTR(0)}; +static PyObject *__pyx_pw_5_cdec_3_make_config(PyObject *__pyx_self, PyObject *__pyx_v_config) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_make_config (wrapper)", 0); + __pyx_self = __pyx_self; + __pyx_r = __pyx_pf_5_cdec_2_make_config(__pyx_self, ((PyObject *)__pyx_v_config)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":28 + * class ParseFailed(Exception): pass + * + * def _make_config(config): # <<<<<<<<<<<<<< + * for key, value in config.items(): + * if isinstance(value, dict): + */ + +static PyObject *__pyx_pf_5_cdec_2_make_config(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_config) { + struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_make_config", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *)__pyx_ptype_5_cdec___pyx_scope_struct_22__make_config->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_22__make_config, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_config = __pyx_v_config; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_config); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_config); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_4generator16, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec._make_config", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5_cdec_4generator16(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; Py_ssize_t __pyx_t_3; PyObject *(*__pyx_t_4)(PyObject *); PyObject *__pyx_t_5 = NULL; @@ -14866,7 +15623,7 @@ static PyObject *__pyx_gb_5_cdec_4generator16(__pyx_GeneratorObject *__pyx_gener __Pyx_INCREF(__pyx_cur_scope->__pyx_v_info); PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_cur_scope->__pyx_v_info); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_info); - __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_43), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_45), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_7)); __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -15245,7 +16002,7 @@ static PyObject *__pyx_gb_5_cdec_7Decoder_9__cinit___2generator20(__pyx_Generato __Pyx_GIVEREF(__pyx_t_3); __pyx_cur_scope->__pyx_v_kv = __pyx_t_3; __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_44), __pyx_cur_scope->__pyx_v_kv); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_46), __pyx_cur_scope->__pyx_v_kv); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __pyx_r = ((PyObject *)__pyx_t_3); __pyx_t_3 = 0; @@ -15336,7 +16093,7 @@ static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *_ */ __pyx_t_2 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_config, __pyx_n_s__get); 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_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_45), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_47), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_formalism = __pyx_t_3; @@ -15401,7 +16158,7 @@ static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *_ */ __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__InvalidConfig); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_46), __pyx_v_formalism); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_48), __pyx_v_formalism); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); @@ -15807,7 +16564,7 @@ static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_De * * property formalism: */ - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_47), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_49), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); @@ -16038,7 +16795,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__startswith); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_49), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_51), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} @@ -16207,7 +16964,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ } /*finally:*/ { if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_50, NULL); + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_52, NULL); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); @@ -16412,7 +17169,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec * if grammar: * if isinstance(grammar, str) or isinstance(grammar, unicode): */ - __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_51), ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_53), ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); @@ -19213,6 +19970,13 @@ static void __pyx_tp_dealloc_5_cdec_SufficientStats(PyObject *o) { } (*Py_TYPE(o)->tp_free)(o); } +static PyObject *__pyx_sq_item_5_cdec_SufficientStats(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} static PyObject *__pyx_getprop_5_cdec_15SufficientStats_score(PyObject *o, void *x) { return __pyx_pw_5_cdec_15SufficientStats_5score_1__get__(o); @@ -19233,7 +19997,7 @@ static struct PyGetSetDef __pyx_getsets_5_cdec_SufficientStats[] = { }; static PyNumberMethods __pyx_tp_as_number_SufficientStats = { - __pyx_pw_5_cdec_15SufficientStats_10__add__, /*nb_add*/ + __pyx_pw_5_cdec_15SufficientStats_12__add__, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 @@ -19268,7 +20032,7 @@ static PyNumberMethods __pyx_tp_as_number_SufficientStats = { #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif - __pyx_pw_5_cdec_15SufficientStats_8__iadd__, /*nb_inplace_add*/ + __pyx_pw_5_cdec_15SufficientStats_10__iadd__, /*nb_inplace_add*/ 0, /*nb_inplace_subtract*/ 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 @@ -19294,7 +20058,7 @@ static PySequenceMethods __pyx_tp_as_sequence_SufficientStats = { __pyx_pw_5_cdec_15SufficientStats_3__len__, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - 0, /*sq_item*/ + __pyx_sq_item_5_cdec_SufficientStats, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -19305,7 +20069,7 @@ static PySequenceMethods __pyx_tp_as_sequence_SufficientStats = { static PyMappingMethods __pyx_tp_as_mapping_SufficientStats = { __pyx_pw_5_cdec_15SufficientStats_3__len__, /*mp_length*/ - 0, /*mp_subscript*/ + __pyx_pw_5_cdec_15SufficientStats_8__getitem__, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; @@ -19933,6 +20697,202 @@ static PyTypeObject __pyx_type_5_cdec_Scorer = { #endif }; +static PyObject *__pyx_tp_new_5_cdec_Metric(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec_Metric *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_5_cdec_Metric *)o); + p->scorer = ((struct __pyx_obj_5_cdec_Scorer *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_5_cdec_6Metric_1__cinit__(o, __pyx_empty_tuple, NULL) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_5_cdec_Metric(PyObject *o) { + struct __pyx_obj_5_cdec_Metric *p = (struct __pyx_obj_5_cdec_Metric *)o; + Py_XDECREF(((PyObject *)p->scorer)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_5_cdec_Metric(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec_Metric *p = (struct __pyx_obj_5_cdec_Metric *)o; + if (p->scorer) { + e = (*v)(((PyObject*)p->scorer), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5_cdec_Metric(PyObject *o) { + struct __pyx_obj_5_cdec_Metric *p = (struct __pyx_obj_5_cdec_Metric *)o; + PyObject* tmp; + tmp = ((PyObject*)p->scorer); + p->scorer = ((struct __pyx_obj_5_cdec_Scorer *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_5_cdec_Metric[] = { + {__Pyx_NAMESTR("score"), (PyCFunction)__pyx_pw_5_cdec_6Metric_5score, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("evaluate"), (PyCFunction)__pyx_pw_5_cdec_6Metric_7evaluate, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Metric = { + 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_Metric = { + 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_Metric = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Metric = { + #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_Metric = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.Metric"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Metric), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_Metric, /*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_Metric, /*tp_as_number*/ + &__pyx_tp_as_sequence_Metric, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Metric, /*tp_as_mapping*/ + 0, /*tp_hash*/ + __pyx_pw_5_cdec_6Metric_3__call__, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Metric, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_5_cdec_Metric, /*tp_traverse*/ + __pyx_tp_clear_5_cdec_Metric, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_Metric, /*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_Metric, /*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_Decoder(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_5_cdec_Decoder *p; PyObject *o = (*t->tp_alloc)(t, 0); @@ -25197,13 +26157,14 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0}, {&__pyx_kp_s_41, __pyx_k_41, sizeof(__pyx_k_41), 0, 0, 1, 0}, {&__pyx_kp_s_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 1, 0}, - {&__pyx_kp_s_44, __pyx_k_44, sizeof(__pyx_k_44), 0, 0, 1, 0}, + {&__pyx_kp_s_45, __pyx_k_45, sizeof(__pyx_k_45), 0, 0, 1, 0}, {&__pyx_kp_s_46, __pyx_k_46, sizeof(__pyx_k_46), 0, 0, 1, 0}, - {&__pyx_kp_s_47, __pyx_k_47, sizeof(__pyx_k_47), 0, 0, 1, 0}, {&__pyx_kp_s_48, __pyx_k_48, sizeof(__pyx_k_48), 0, 0, 1, 0}, - {&__pyx_kp_s_51, __pyx_k_51, sizeof(__pyx_k_51), 0, 0, 1, 0}, - {&__pyx_kp_s_54, __pyx_k_54, sizeof(__pyx_k_54), 0, 0, 1, 0}, - {&__pyx_kp_s_59, __pyx_k_59, sizeof(__pyx_k_59), 0, 0, 1, 0}, + {&__pyx_kp_s_49, __pyx_k_49, sizeof(__pyx_k_49), 0, 0, 1, 0}, + {&__pyx_kp_s_50, __pyx_k_50, sizeof(__pyx_k_50), 0, 0, 1, 0}, + {&__pyx_kp_s_53, __pyx_k_53, sizeof(__pyx_k_53), 0, 0, 1, 0}, + {&__pyx_kp_s_56, __pyx_k_56, sizeof(__pyx_k_56), 0, 0, 1, 0}, + {&__pyx_kp_s_61, __pyx_k_61, sizeof(__pyx_k_61), 0, 0, 1, 0}, {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0}, {&__pyx_kp_s_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 1, 0}, {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0}, @@ -25218,9 +26179,11 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__TER, __pyx_k__TER, sizeof(__pyx_k__TER), 0, 0, 1, 1}, {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1}, {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, + {&__pyx_n_s____class__, __pyx_k____class__, sizeof(__pyx_k____class__), 0, 0, 1, 1}, {&__pyx_n_s____enter__, __pyx_k____enter__, sizeof(__pyx_k____enter__), 0, 0, 1, 1}, {&__pyx_n_s____exit__, __pyx_k____exit__, sizeof(__pyx_k____exit__), 0, 0, 1, 1}, {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, + {&__pyx_n_s____name__, __pyx_k____name__, sizeof(__pyx_k____name__), 0, 0, 1, 1}, {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, {&__pyx_n_s___cdec, __pyx_k___cdec, sizeof(__pyx_k___cdec), 0, 0, 1, 1}, {&__pyx_n_s___make_config, __pyx_k___make_config, sizeof(__pyx_k___make_config), 0, 0, 1, 1}, @@ -25239,6 +26202,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__encoding, __pyx_k__encoding, sizeof(__pyx_k__encoding), 0, 0, 1, 1}, {&__pyx_n_s__enumerate, __pyx_k__enumerate, sizeof(__pyx_k__enumerate), 0, 0, 1, 1}, {&__pyx_n_s__eval, __pyx_k__eval, sizeof(__pyx_k__eval), 0, 0, 1, 1}, + {&__pyx_n_s__evaluate, __pyx_k__evaluate, sizeof(__pyx_k__evaluate), 0, 0, 1, 1}, {&__pyx_n_s__evaluator, __pyx_k__evaluator, sizeof(__pyx_k__evaluator), 0, 0, 1, 1}, {&__pyx_n_s__f, __pyx_k__f, sizeof(__pyx_k__f), 0, 0, 1, 1}, {&__pyx_n_s__formalism, __pyx_k__formalism, sizeof(__pyx_k__formalism), 0, 0, 1, 1}, @@ -25246,6 +26210,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__genexpr, __pyx_k__genexpr, sizeof(__pyx_k__genexpr), 0, 0, 1, 1}, {&__pyx_n_s__get, __pyx_k__get, sizeof(__pyx_k__get), 0, 0, 1, 1}, {&__pyx_n_s__grammar, __pyx_k__grammar, sizeof(__pyx_k__grammar), 0, 0, 1, 1}, + {&__pyx_n_s__hyp, __pyx_k__hyp, sizeof(__pyx_k__hyp), 0, 0, 1, 1}, {&__pyx_n_s__hypergraph, __pyx_k__hypergraph, sizeof(__pyx_k__hypergraph), 0, 0, 1, 1}, {&__pyx_n_s__i, __pyx_k__i, sizeof(__pyx_k__i), 0, 0, 1, 1}, {&__pyx_n_s__in_edges, __pyx_k__in_edges, sizeof(__pyx_k__in_edges), 0, 0, 1, 1}, @@ -25271,6 +26236,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__replace, __pyx_k__replace, sizeof(__pyx_k__replace), 0, 0, 1, 1}, {&__pyx_n_s__rules, __pyx_k__rules, sizeof(__pyx_k__rules), 0, 0, 1, 1}, {&__pyx_n_s__scfg, __pyx_k__scfg, sizeof(__pyx_k__scfg), 0, 0, 1, 1}, + {&__pyx_n_s__score, __pyx_k__score, sizeof(__pyx_k__score), 0, 0, 1, 1}, {&__pyx_n_s__scores, __pyx_k__scores, sizeof(__pyx_k__scores), 0, 0, 1, 1}, {&__pyx_n_s__self, __pyx_k__self, sizeof(__pyx_k__self), 0, 0, 1, 1}, {&__pyx_n_s__sentence, __pyx_k__sentence, sizeof(__pyx_k__sentence), 0, 0, 1, 1}, @@ -25350,7 +26316,7 @@ static int __Pyx_InitCachedConstants(void) { * for trule in rules: * if not isinstance(trule, BaseTRule): * raise ValueError('the grammar should contain TRule objects') # <<<<<<<<<<<<<< - * _g.AddRule(( trule).rule[0]) + * _g.AddRule(( trule).rule[0]) */ __pyx_k_tuple_14 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_14)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_14); @@ -25494,20 +26460,34 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_40)); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":79 - * def __getitem__(self,int k): - * if not 0 <= k < self.cs.size(): - * raise IndexError('candidate set index out of range') # <<<<<<<<<<<<<< - * cdef Candidate candidate = Candidate() - * candidate.candidate = &self.cs[0][k] + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":50 + * def __getitem__(self, int index): + * if not 0 <= index < len(self): + * raise IndexError('sufficient stats vector index out of range') # <<<<<<<<<<<<<< + * return self.stats[0][index] + * */ - __pyx_k_tuple_42 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_42)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_42 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_42)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_42); __Pyx_INCREF(((PyObject *)__pyx_kp_s_41)); PyTuple_SET_ITEM(__pyx_k_tuple_42, 0, ((PyObject *)__pyx_kp_s_41)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_41)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_42)); + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":84 + * def __getitem__(self,int k): + * if not 0 <= k < self.cs.size(): + * raise IndexError('candidate set index out of range') # <<<<<<<<<<<<<< + * cdef Candidate candidate = Candidate() + * candidate.candidate = &self.cs[0][k] + */ + __pyx_k_tuple_44 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_44)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_44); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_43)); + PyTuple_SET_ITEM(__pyx_k_tuple_44, 0, ((PyObject *)__pyx_kp_s_43)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_43)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_44)); + /* "_cdec.pyx":50 * """ * if config_str is None: @@ -25515,15 +26495,15 @@ static int __Pyx_InitCachedConstants(void) { * if formalism not in ('scfg', 'fst', 'lextrans', 'pb', * 'csplit', 'tagger', 'lexalign'): */ - __pyx_k_tuple_45 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_45)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_45); + __pyx_k_tuple_47 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_47)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_47); __Pyx_INCREF(((PyObject *)__pyx_n_s__formalism)); - PyTuple_SET_ITEM(__pyx_k_tuple_45, 0, ((PyObject *)__pyx_n_s__formalism)); + PyTuple_SET_ITEM(__pyx_k_tuple_47, 0, ((PyObject *)__pyx_n_s__formalism)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__formalism)); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_45, 1, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_47, 1, Py_None); __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_45)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_47)); /* "_cdec.pyx":88 * with open(weights) as fp: @@ -25532,12 +26512,12 @@ static int __Pyx_InitCachedConstants(void) { * fname, value = line.split() * self.weights[fname.strip()] = float(value) */ - __pyx_k_tuple_49 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_49)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_49); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_48)); - PyTuple_SET_ITEM(__pyx_k_tuple_49, 0, ((PyObject *)__pyx_kp_s_48)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_48)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_49)); + __pyx_k_tuple_51 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_51)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_51); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_50)); + PyTuple_SET_ITEM(__pyx_k_tuple_51, 0, ((PyObject *)__pyx_kp_s_50)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_50)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_51)); /* "_cdec.pyx":86 * @@ -25546,18 +26526,18 @@ static int __Pyx_InitCachedConstants(void) { * for line in fp: * if line.strip().startswith('#'): continue */ - __pyx_k_tuple_50 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_50)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_50); + __pyx_k_tuple_52 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_52); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_50, 0, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_52, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_50, 1, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_52, 1, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_50, 2, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_52, 2, Py_None); __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_50)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_52)); /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":3 * cimport grammar @@ -25566,44 +26546,44 @@ static int __Pyx_InitCachedConstants(void) { * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) * */ - __pyx_k_tuple_52 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_52); + __pyx_k_tuple_54 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_54)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_54); __Pyx_INCREF(((PyObject *)__pyx_n_s__phrase)); - PyTuple_SET_ITEM(__pyx_k_tuple_52, 0, ((PyObject *)__pyx_n_s__phrase)); + PyTuple_SET_ITEM(__pyx_k_tuple_54, 0, ((PyObject *)__pyx_n_s__phrase)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__phrase)); __Pyx_INCREF(((PyObject *)__pyx_n_s__genexpr)); - PyTuple_SET_ITEM(__pyx_k_tuple_52, 1, ((PyObject *)__pyx_n_s__genexpr)); + PyTuple_SET_ITEM(__pyx_k_tuple_54, 1, ((PyObject *)__pyx_n_s__genexpr)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__genexpr)); __Pyx_INCREF(((PyObject *)__pyx_n_s__genexpr)); - PyTuple_SET_ITEM(__pyx_k_tuple_52, 2, ((PyObject *)__pyx_n_s__genexpr)); + PyTuple_SET_ITEM(__pyx_k_tuple_54, 2, ((PyObject *)__pyx_n_s__genexpr)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__genexpr)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_52)); - __pyx_k_codeobj_53 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_52, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_54, __pyx_n_s___phrase, 3, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_53)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_54)); + __pyx_k_codeobj_55 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_54, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_56, __pyx_n_s___phrase, 3, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_55)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":143 - * return self.name.c_str() + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":190 + * return [] * * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< * TER = Scorer('TER') */ - __pyx_k_tuple_55 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_55)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_55); + __pyx_k_tuple_57 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_57)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_57); __Pyx_INCREF(((PyObject *)__pyx_n_s__IBM_BLEU)); - PyTuple_SET_ITEM(__pyx_k_tuple_55, 0, ((PyObject *)__pyx_n_s__IBM_BLEU)); + PyTuple_SET_ITEM(__pyx_k_tuple_57, 0, ((PyObject *)__pyx_n_s__IBM_BLEU)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IBM_BLEU)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_55)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_57)); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":144 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":191 * * BLEU = Scorer('IBM_BLEU') * TER = Scorer('TER') # <<<<<<<<<<<<<< */ - __pyx_k_tuple_56 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_56)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_56); + __pyx_k_tuple_58 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_58)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_58); __Pyx_INCREF(((PyObject *)__pyx_n_s__TER)); - PyTuple_SET_ITEM(__pyx_k_tuple_56, 0, ((PyObject *)__pyx_n_s__TER)); + PyTuple_SET_ITEM(__pyx_k_tuple_58, 0, ((PyObject *)__pyx_n_s__TER)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__TER)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_56)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_58)); /* "_cdec.pyx":28 * class ParseFailed(Exception): pass @@ -25612,25 +26592,25 @@ static int __Pyx_InitCachedConstants(void) { * for key, value in config.items(): * if isinstance(value, dict): */ - __pyx_k_tuple_57 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_57)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_57); + __pyx_k_tuple_59 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_59)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_59); __Pyx_INCREF(((PyObject *)__pyx_n_s__config)); - PyTuple_SET_ITEM(__pyx_k_tuple_57, 0, ((PyObject *)__pyx_n_s__config)); + PyTuple_SET_ITEM(__pyx_k_tuple_59, 0, ((PyObject *)__pyx_n_s__config)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__config)); __Pyx_INCREF(((PyObject *)__pyx_n_s__key)); - PyTuple_SET_ITEM(__pyx_k_tuple_57, 1, ((PyObject *)__pyx_n_s__key)); + PyTuple_SET_ITEM(__pyx_k_tuple_59, 1, ((PyObject *)__pyx_n_s__key)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__key)); __Pyx_INCREF(((PyObject *)__pyx_n_s__value)); - PyTuple_SET_ITEM(__pyx_k_tuple_57, 2, ((PyObject *)__pyx_n_s__value)); + PyTuple_SET_ITEM(__pyx_k_tuple_59, 2, ((PyObject *)__pyx_n_s__value)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__value)); __Pyx_INCREF(((PyObject *)__pyx_n_s__name)); - PyTuple_SET_ITEM(__pyx_k_tuple_57, 3, ((PyObject *)__pyx_n_s__name)); + PyTuple_SET_ITEM(__pyx_k_tuple_59, 3, ((PyObject *)__pyx_n_s__name)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__name)); __Pyx_INCREF(((PyObject *)__pyx_n_s__info)); - PyTuple_SET_ITEM(__pyx_k_tuple_57, 4, ((PyObject *)__pyx_n_s__info)); + PyTuple_SET_ITEM(__pyx_k_tuple_59, 4, ((PyObject *)__pyx_n_s__info)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__info)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_57)); - __pyx_k_codeobj_58 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_57, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_59, __pyx_n_s___make_config, 28, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_58)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_59)); + __pyx_k_codeobj_60 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_59, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_61, __pyx_n_s___make_config, 28, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_60)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -25764,15 +26744,18 @@ PyMODINIT_FUNC PyInit__cdec(void) if (PyType_Ready(&__pyx_type_5_cdec_SufficientStats) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "SufficientStats", (PyObject *)&__pyx_type_5_cdec_SufficientStats) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_SufficientStats = &__pyx_type_5_cdec_SufficientStats; - if (PyType_Ready(&__pyx_type_5_cdec_CandidateSet) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "CandidateSet", (PyObject *)&__pyx_type_5_cdec_CandidateSet) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_CandidateSet) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "CandidateSet", (PyObject *)&__pyx_type_5_cdec_CandidateSet) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_CandidateSet = &__pyx_type_5_cdec_CandidateSet; - if (PyType_Ready(&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "SegmentEvaluator", (PyObject *)&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "SegmentEvaluator", (PyObject *)&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_SegmentEvaluator = &__pyx_type_5_cdec_SegmentEvaluator; - if (PyType_Ready(&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Scorer", (PyObject *)&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Scorer", (PyObject *)&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Scorer = &__pyx_type_5_cdec_Scorer; + if (PyType_Ready(&__pyx_type_5_cdec_Metric) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Metric", (PyObject *)&__pyx_type_5_cdec_Metric) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_Metric = &__pyx_type_5_cdec_Metric; if (PyType_Ready(&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __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 = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Decoder = &__pyx_type_5_cdec_Decoder; @@ -25818,7 +26801,7 @@ PyMODINIT_FUNC PyInit__cdec(void) __pyx_ptype_5_cdec___pyx_scope_struct_19_lines = &__pyx_type_5_cdec___pyx_scope_struct_19_lines; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_20___iter__) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_20___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_20___iter__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_21___iter__) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_21___iter__) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_21___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_21___iter__; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_22__make_config) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_22__make_config = &__pyx_type_5_cdec___pyx_scope_struct_22__make_config; @@ -25843,25 +26826,25 @@ PyMODINIT_FUNC PyInit__cdec(void) if (PyObject_SetAttr(__pyx_m, __pyx_n_s___phrase, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":143 - * return self.name.c_str() + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":190 + * return [] * * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< * TER = Scorer('TER') */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_55), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_57), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":144 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":191 * * BLEU = Scorer('IBM_BLEU') * TER = Scorer('TER') # <<<<<<<<<<<<<< */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_56), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_58), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "_cdec.pyx":22 @@ -26356,6 +27339,40 @@ static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject* iterator, PyObject* } } +static CYTHON_INLINE int __Pyx_CheckKeywordStrings( + PyObject *kwdict, + const char* function_name, + int kw_allowed) +{ + PyObject* key = 0; + Py_ssize_t pos = 0; + while (PyDict_Next(kwdict, &pos, &key, 0)) { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) + #else + if (unlikely(!PyUnicode_Check(key))) + #endif + goto invalid_keyword_type; + } + if ((!kw_allowed) && unlikely(key)) + goto invalid_keyword; + return 1; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%s() keywords must be strings", function_name); + return 0; +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%s() got an unexpected keyword argument '%s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif + return 0; +} + static double __Pyx__PyObject_AsDouble(PyObject* obj) { PyObject* float_value; if (Py_TYPE(obj)->tp_as_number && Py_TYPE(obj)->tp_as_number->nb_float) { diff --git a/python/src/decoder.pxd b/python/src/decoder.pxd index d2065579..a66166a2 100644 --- a/python/src/decoder.pxd +++ b/python/src/decoder.pxd @@ -27,8 +27,6 @@ cdef extern from "decoder/decoder.h": variables_map& GetConf() # add grammar rules (currently only supported by SCFG decoders) - # that will be used on subsequent calls to Decode. rules should be in standard - # text format. This function does NOT read from a file. void AddSupplementalGrammarFromString(string& grammar_str) void AddSupplementalGrammar(shared_ptr[Grammar] grammar) diff --git a/python/src/grammar.pxd b/python/src/grammar.pxd index 43806f71..8853a614 100644 --- a/python/src/grammar.pxd +++ b/python/src/grammar.pxd @@ -3,7 +3,6 @@ from libcpp.string cimport string from utils cimport * cdef extern from "decoder/trule.h": - cdef cppclass AlignmentPoint: AlignmentPoint(int s, int t) AlignmentPoint Inverted() diff --git a/python/src/mteval.pxd b/python/src/mteval.pxd index 52af6297..27c2808d 100644 --- a/python/src/mteval.pxd +++ b/python/src/mteval.pxd @@ -10,6 +10,7 @@ cdef extern from "mteval/ns.h": unsigned size() float operator[](unsigned i) void swap(SufficientStats& other) + vector[float] fields SufficientStats add "operator+" (SufficientStats&, SufficientStats&) @@ -26,9 +27,15 @@ cdef extern from "mteval/ns.h": vector[WordID]& refs, SufficientStats* out) -cdef extern from "mteval/ns.h" namespace "EvaluationMetric": - EvaluationMetric* Instance(string& metric_id) - EvaluationMetric* Instance() # IBM_BLEU + cdef EvaluationMetric* MetricInstance "EvaluationMetric::Instance" (string& metric_id) + +cdef extern from "py_scorer.h": + ctypedef float (*MetricScoreCallback)(void*, SufficientStats* stats) + ctypedef void (*MetricStatsCallback)(void*, + string* hyp, vector[string]* refs, SufficientStats* out) + + cdef EvaluationMetric* PyMetricInstance "PythonEvaluationMetric::Instance"( + string& metric_id, void*, MetricStatsCallback, MetricScoreCallback) cdef extern from "training/candidate_set.h" namespace "training": cdef cppclass Candidate "const training::Candidate": diff --git a/python/src/mteval.pxi b/python/src/mteval.pxi index 4ba73168..f67f4f04 100644 --- a/python/src/mteval.pxi +++ b/python/src/mteval.pxi @@ -43,7 +43,12 @@ cdef class SufficientStats: def __iter__(self): for i in range(len(self)): - yield self.stats[0][i] + yield self[i] + + def __getitem__(self, int index): + if not 0 <= index < len(self): + raise IndexError('sufficient stats vector index out of range') + return self.stats[0][index] def __iadd__(SufficientStats self, SufficientStats other): self.stats[0] += other.stats[0] @@ -111,15 +116,17 @@ cdef class SegmentEvaluator: cdef class Scorer: cdef string* name + cdef mteval.EvaluationMetric* metric - def __cinit__(self, char* name): - self.name = new string(name) + def __cinit__(self, bytes name=None): + if name: + self.name = new string(name) + self.metric = mteval.MetricInstance(self.name[0]) def __dealloc__(self): del self.name def __call__(self, refs): - cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) if isinstance(refs, unicode) or isinstance(refs, str): refs = [refs] cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() @@ -132,13 +139,53 @@ cdef class Scorer: del refv cdef unsigned i cdef SegmentEvaluator evaluator = SegmentEvaluator() - evaluator.metric = metric - evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + evaluator.metric = self.metric + evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator]( + self.metric.CreateSegmentEvaluator(refsv[0])) del refsv # in theory should not delete but store in SegmentEvaluator return evaluator def __str__(self): return self.name.c_str() +cdef float _compute_score(void* metric_, mteval.SufficientStats* stats): + cdef Metric metric = metric_ + cdef list ss = [] + cdef unsigned i + for i in range(stats.size()): + ss.append(stats[0][i]) + return metric.score(ss) + +cdef void _compute_sufficient_stats(void* metric_, + string* hyp, + vector[string]* refs, + mteval.SufficientStats* out): + cdef Metric metric = metric_ + cdef list refs_ = [] + cdef unsigned i + for i in range(refs.size()): + refs_.append(refs[0][i].c_str()) + cdef list ss = metric.evaluate(hyp.c_str(), refs_) + out.fields.resize(len(ss)) + for i in range(len(ss)): + out.fields[i] = ss[i] + +cdef class Metric: + cdef Scorer scorer + def __cinit__(self): + self.scorer = Scorer() + self.scorer.name = new string(as_str(self.__class__.__name__)) + self.scorer.metric = mteval.PyMetricInstance(self.scorer.name[0], + self, _compute_sufficient_stats, _compute_score) + + def __call__(self, refs): + return self.scorer(refs) + + def score(SufficientStats stats): + return 0 + + def evaluate(self, hyp, refs): + return [] + BLEU = Scorer('IBM_BLEU') TER = Scorer('TER') diff --git a/python/src/observer.h b/python/src/observer.h index d398f2f7..05f3c9be 100644 --- a/python/src/observer.h +++ b/python/src/observer.h @@ -1,6 +1,5 @@ #include "decoder/hg.h" #include "decoder/decoder.h" -#include struct BasicObserver: public DecoderObserver { Hypergraph* hypergraph; diff --git a/python/src/py_scorer.h b/python/src/py_scorer.h new file mode 100644 index 00000000..22dc9fee --- /dev/null +++ b/python/src/py_scorer.h @@ -0,0 +1,44 @@ +#include "ns.h" +#include "tdict.h" + +typedef float (*MetricScoreCallback)(void*, SufficientStats* stats); +typedef void (*MetricStatsCallback)(void*, + std::string *hyp, + std::vector *refs, + SufficientStats* out); + +struct PythonEvaluationMetric : public EvaluationMetric { + + PythonEvaluationMetric(const std::string& id) : EvaluationMetric(id) {} + + static EvaluationMetric* Instance(const std::string& id, + void* obj, + MetricStatsCallback statscb, + MetricScoreCallback scorecb) { + PythonEvaluationMetric* metric = new PythonEvaluationMetric(id); + metric->pymetric = obj; + metric->_compute_score = scorecb; + metric->_compute_sufficient_stats = statscb; + return metric; + } + + float ComputeScore(const SufficientStats& stats) const { + SufficientStats stats_(stats); + return _compute_score(pymetric, &stats_); + } + + void ComputeSufficientStatistics(const std::vector& hyp, + const std::vector >& refs, + SufficientStats* out) const { + std::string hyp_(TD::GetString(hyp)); + std::vector refs_; + for(unsigned i = 0; i < refs.size(); ++i) { + refs_.push_back(TD::GetString(refs[i])); + } + _compute_sufficient_stats(pymetric, &hyp_, &refs_, out); + } + + void* pymetric; + MetricStatsCallback _compute_sufficient_stats; + MetricScoreCallback _compute_score; +}; diff --git a/sa-extract/Makefile b/sa-extract/Makefile index 7b39ae4d..3145bbfe 100644 --- a/sa-extract/Makefile +++ b/sa-extract/Makefile @@ -1,17 +1,11 @@ -PYVER=python2.7 -PYDIR=/usr/local/Cellar/python/2.7.2 -PYINCLUDE=$(PYDIR)/include/$(PYVER) -CYTHON=/usr/local/share/python/cython -PYTHON=$(PYDIR)/bin/python - %.c: %.pyx - $(CYTHON) $< -o $@ + cython $< -o $@ %.o: %.cc g++ -O6 -g -fPIC -c $< all: cstrmap.c strmap.cc rule.c sym.c cdat.c cintlist.c cfloatlist.c calignment.c csuf.c clex.c rulefactory.c cveb.c lcp.c precomputation.c - $(PYTHON) setup.py build + python setup.py build clean: rm -f cdat.c cstrmap.c sym.c rule.c cintlist.c cfloatlist.c calignment.c csuf.c clex.c rulefactory.c cveb.c lcp.c precomputation.c *.so *.o *.cxx *~ *.pyc -- cgit v1.2.3 From 11b3c09e45348d3e69db57837b61097862544fec Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Wed, 25 Jul 2012 23:57:05 -0400 Subject: Character error rate metric - [python] cdec.score.CER - Cleanup .gitignore --- .gitignore | 89 +++++++++++---------------------------------------- mteval/Jamfile | 2 +- mteval/Makefile.am | 2 +- mteval/ns.cc | 3 ++ mteval/ns_cer.cc | 55 +++++++++++++++++++++++++++++++ mteval/ns_cer.h | 23 +++++++++++++ python/cdec/score.py | 2 +- python/src/_cdec.cpp | 58 +++++++++++++++++++++++++-------- python/src/mteval.pxi | 1 + 9 files changed, 147 insertions(+), 88 deletions(-) create mode 100644 mteval/ns_cer.cc create mode 100644 mteval/ns_cer.h (limited to 'python/src') diff --git a/.gitignore b/.gitignore index 943e6dc5..571360ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,19 @@ +*.log +*.bbl +*.aux +*.blg +*.idx +*.pdf +*.dvi +*.ps +*.toc +*.so +*.pyc +*swp +*.o +*.a +*~ +.* ./cdec/ decoder/bin/ gi/pf/align-tl @@ -6,21 +22,17 @@ gi/pf/nuisance_test gi/pf/pf_test gi/pf/pyp_lm jam-files/bjam -jam-files/engine/bin.linuxx86_64/ +jam-files/engine/bin.* jam-files/engine/bootstrap/ klm/lm/bin/ -klm/lm/libkenlm.so -klm/lm/libkenutil.so klm/lm/query klm/util/bin/ mteval/bin/ rampion/rampion_cccp -rst_parser/librst.a rst_parser/mst_train rst_parser/rst_parse rst_parser/rst_train training/liblbfgs/bin/ -training/liblbfgs/liblbfgs.a training/liblbfgs/ll_test utils/atools utils/bin/ @@ -28,38 +40,18 @@ utils/crp_test mira/kbest_mira utils/m_test sa-extract/calignment.c -sa-extract/calignment.so sa-extract/cdat.c -sa-extract/cdat.so sa-extract/cfloatlist.c -sa-extract/cfloatlist.so sa-extract/cintlist.c -sa-extract/cintlist.so sa-extract/clex.c -sa-extract/clex.so -sa-extract/cn.pyc -sa-extract/context_model.pyc sa-extract/cstrmap.c -sa-extract/cstrmap.so sa-extract/csuf.c -sa-extract/csuf.so sa-extract/cveb.c -sa-extract/cveb.so sa-extract/lcp.c -sa-extract/lcp.so -sa-extract/log.pyc -sa-extract/manager.pyc -sa-extract/model.pyc -sa-extract/monitor.pyc sa-extract/precomputation.c -sa-extract/precomputation.so sa-extract/rule.c -sa-extract/rule.so sa-extract/rulefactory.c -sa-extract/rulefactory.so -sa-extract/sgml.pyc sa-extract/sym.c -sa-extract/sym.so training/lbl_model training/mpi_flex_optimize training/test_ngram @@ -70,11 +62,9 @@ utils/phmt utils/small_vector_test utils/ts utils/weights_test -pro-train/.deps pro-train/mr_pro_map pro-train/mr_pro_reduce utils/reconstruct_weights -decoder/.libs training/augment_grammar training/mpi_batch_optimize training/mpi_compute_cllh @@ -83,34 +73,21 @@ training/mpi_extract_features training/mpi_extract_reachable klm/lm/build_binary extools/extractor_monolingual -gi/pf/.deps gi/pf/learn_cfg gi/pf/brat gi/pf/cbgi gi/pf/dpnaive gi/pf/itg -gi/pf/libpf.a gi/pf/pfbrat gi/pf/pfdist gi/pf/pfnaive -gi/markov_al/.deps gi/markov_al/ml gi/posterior-regularisation/prjava/lib/*.jar -klm/lm/libklm.a -klm/util/.deps -klm/util/libklm_util.a -mteval/.deps/ tests/system_tests/hmm/foo.src training/cllh_filter_grammar -klm/lm/.deps mteval/fast_score -mteval/libmteval.a mteval/mbr_kbest training/mpi_online_optimize -utils/.deps/ -utils/libutils.a -*swp -*.o dpmert/sentserver dpmert/sentclient gi/pyp-topics/src/contexts_lexer.cc @@ -128,7 +105,6 @@ decoder/rule_lexer.cc training/atools training/collapse_weights training/lbfgs_test -training/libtraining.a training/mr_optimize_reduce training/mr_em_adapted_reduce training/mr_em_map_adapter @@ -141,6 +117,7 @@ dpmert/mr_dpmert_map dpmert/mr_dpmert_reduce dpmert/scorer_test dpmert/union_forests +minrisk/minrisk_optimize Makefile Makefile.in aclocal.m4 @@ -153,48 +130,29 @@ configure depcomp install-sh missing -extools/.deps/ -extools/*.o extools/extractor extools/mr_stripe_rule_reduce -decoder/.deps/ -decoder/*.o decoder/Makefile decoder/Makefile.in decoder/cdec decoder/dict_test -decoder/libcdec.a decoder/trule_test decoder/weights_test stamp-h1 -training/.deps/ training/Makefile training/Makefile.in -training/*.o training/grammar_convert training/model1 -dpmert/.deps/ dpmert/Makefile dpmert/Makefile.in dpmert/mr_dpmert_generate_mapper_input -dpmert/*.o decoder/logval_test dtrain/dtrain -dtrain/*.o extools/build_lexical_translation extools/filter_grammar extools/score_grammar -gi/clda/src/.deps/ gi/clda/src/clda -gi/clda/src/clda.o -gi/pyp-topics/src/.deps/ -gi/pyp-topics/src/corpus.o -gi/pyp-topics/src/gammadist.o -gi/pyp-topics/src/gzstream.o -gi/pyp-topics/src/mt19937ar.o gi/pyp-topics/src/pyp-topics-train -gi/pyp-topics/src/pyp-topics.o -gi/pyp-topics/src/train.o m4/libtool.m4 m4/ltoptions.m4 m4/ltsugar.m4 @@ -208,22 +166,11 @@ gi/posterior-regularisation/prjava/prjava.jar gi/pyp-topics/src/pyp-contexts-train extools/sg_lexer.cc gi/posterior-regularisation/prjava/lib/prjava-20100715.jar -*.log -*.bbl -*.aux -*.blg -*.idx -*.pdf -*.dvi -*.ps -*.toc -*~ gi/pf/align-lexonly gi/pf/align-lexonly-pyp gi/pf/condnaive mteval/scorer_test phrasinator/gibbs_train_plm phrasinator/gibbs_train_plm_notables -.* previous.sh dist diff --git a/mteval/Jamfile b/mteval/Jamfile index 6260caea..3ed2c2cc 100644 --- a/mteval/Jamfile +++ b/mteval/Jamfile @@ -1,6 +1,6 @@ import testing ; -lib mteval : ter.cc comb_scorer.cc aer_scorer.cc scorer.cc external_scorer.cc ns.cc ns_ter.cc ns_ext.cc ns_comb.cc ns_docscorer.cc ..//utils : . : : . ..//z ; +lib mteval : ter.cc comb_scorer.cc aer_scorer.cc scorer.cc external_scorer.cc ns.cc ns_ter.cc ns_ext.cc ns_comb.cc ns_docscorer.cc ns_cer.cc ..//utils : . : : . ..//z ; exe fast_score : fast_score.cc mteval ..//utils ..//boost_program_options ; exe mbr_kbest : mbr_kbest.cc mteval ..//utils ..//boost_program_options ; alias programs : fast_score mbr_kbest ; diff --git a/mteval/Makefile.am b/mteval/Makefile.am index 8d844e24..22550c99 100644 --- a/mteval/Makefile.am +++ b/mteval/Makefile.am @@ -8,7 +8,7 @@ TESTS = scorer_test noinst_LIBRARIES = libmteval.a -libmteval_a_SOURCES = ter.cc comb_scorer.cc aer_scorer.cc scorer.cc external_scorer.cc ns.cc ns_ter.cc ns_ext.cc ns_comb.cc ns_docscorer.cc +libmteval_a_SOURCES = ter.cc comb_scorer.cc aer_scorer.cc scorer.cc external_scorer.cc ns.cc ns_ter.cc ns_ext.cc ns_comb.cc ns_docscorer.cc ns_cer.cc fast_score_SOURCES = fast_score.cc fast_score_LDADD = libmteval.a $(top_srcdir)/utils/libutils.a -lz diff --git a/mteval/ns.cc b/mteval/ns.cc index 8d354677..33952da7 100644 --- a/mteval/ns.cc +++ b/mteval/ns.cc @@ -2,6 +2,7 @@ #include "ns_ter.h" #include "ns_ext.h" #include "ns_comb.h" +#include "ns_cer.h" #include #include @@ -254,6 +255,8 @@ EvaluationMetric* EvaluationMetric::Instance(const string& imetric_id) { m = new ExternalMetric("METEOR", "java -Xmx1536m -jar /Users/cdyer/software/meteor/meteor-1.3.jar - - -mira -lower -t tune -l en"); } else if (metric_id.find("COMB:") == 0) { m = new CombinationMetric(metric_id); + } else if (metric_id == "CER") { + m = new CERMetric; } else { cerr << "Implement please: " << metric_id << endl; abort(); diff --git a/mteval/ns_cer.cc b/mteval/ns_cer.cc new file mode 100644 index 00000000..a843d471 --- /dev/null +++ b/mteval/ns_cer.cc @@ -0,0 +1,55 @@ +#include "ns_cer.h" +#include "tdict.h" + +static const unsigned kNUMFIELDS = 2; +static const unsigned kEDITDISTANCE = 0; +static const unsigned kCHARCOUNT = 1; + +bool CERMetric::IsErrorMetric() const { + return true; +} + +unsigned CERMetric::SufficientStatisticsVectorSize() const { + return 2; +} + +unsigned CERMetric::EditDistance(const std::string& hyp, + const std::string& ref) const { + const unsigned m = hyp.size(), n = ref.size(); + std::vector edit((m + 1) * 2); + for(unsigned i = 0; i < n + 1; i++) { + for(unsigned j = 0; j < m + 1; j++) { + if(i == 0) + edit[j] = j; + else if(j == 0) + edit[(i%2)*(m+1)] = i; + else + edit[(i%2)*(m+1) + j] = std::min(std::min(edit[(i%2)*(m+1) + j-1] + 1, + edit[((i-1)%2)*(m+1) + j] + 1), + edit[((i-1)%2)*(m+1) + (j-1)] + + (hyp[j-1] == ref[i-1] ? 0 : 1)); + + } + } + return edit[(n%2)*(m+1) + m]; +} + +void CERMetric::ComputeSufficientStatistics(const std::vector& hyp, + const std::vector >& refs, + SufficientStats* out) const { + out->fields.resize(kNUMFIELDS); + std::string hyp_str(TD::GetString(hyp)); + float best_score = hyp_str.size(); + for (size_t i = 0; i < refs.size(); ++i) { + std::string ref_str(TD::GetString(refs[i])); + float score = EditDistance(hyp_str, ref_str); + if (score < best_score) { + out->fields[kEDITDISTANCE] = score; + out->fields[kCHARCOUNT] = ref_str.size(); + best_score = score; + } + } +} +float CERMetric::ComputeScore(const SufficientStats& stats) const { + return stats.fields[kEDITDISTANCE] / stats.fields[kCHARCOUNT]; +} diff --git a/mteval/ns_cer.h b/mteval/ns_cer.h new file mode 100644 index 00000000..9d211181 --- /dev/null +++ b/mteval/ns_cer.h @@ -0,0 +1,23 @@ +#ifndef _NS_CER_H_ +#define _NS_CER_H_ + +#include "ns.h" + +class CERMetric : public EvaluationMetric { + friend class EvaluationMetric; + private: + unsigned EditDistance(const std::string& hyp, + const std::string& ref) const; + protected: + CERMetric() : EvaluationMetric("CER") {} + + public: + virtual bool IsErrorMetric() const; + virtual unsigned SufficientStatisticsVectorSize() const; + virtual void ComputeSufficientStatistics(const std::vector& hyp, + const std::vector >& refs, + SufficientStats* out) const; + virtual float ComputeScore(const SufficientStats& stats) const; +}; + +#endif diff --git a/python/cdec/score.py b/python/cdec/score.py index d9486ef2..22257774 100644 --- a/python/cdec/score.py +++ b/python/cdec/score.py @@ -1 +1 @@ -from _cdec import BLEU, TER, Metric +from _cdec import BLEU, TER, CER, Metric diff --git a/python/src/_cdec.cpp b/python/src/_cdec.cpp index 6d704b1d..44cd6568 100644 --- a/python/src/_cdec.cpp +++ b/python/src/_cdec.cpp @@ -1,4 +1,4 @@ -/* Generated by Cython 0.16 on Mon Jul 23 19:56:55 2012 */ +/* Generated by Cython 0.16 on Wed Jul 25 23:56:10 2012 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -1761,13 +1761,14 @@ static char __pyx_k_49[] = "cannot initialize weights with %s"; static char __pyx_k_50[] = "#"; static char __pyx_k_53[] = "Cannot translate input type %s"; static char __pyx_k_56[] = "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi"; -static char __pyx_k_61[] = "/Users/vchahun/Sandbox/cdec/python/src/_cdec.pyx"; +static char __pyx_k_62[] = "/Users/vchahun/Sandbox/cdec/python/src/_cdec.pyx"; static char __pyx_k__a[] = "a"; static char __pyx_k__e[] = "e"; static char __pyx_k__f[] = "f"; static char __pyx_k__i[] = "i"; static char __pyx_k__k[] = "k"; static char __pyx_k__pb[] = "pb"; +static char __pyx_k__CER[] = "CER"; static char __pyx_k__TER[] = "TER"; static char __pyx_k__cat[] = "cat"; static char __pyx_k__dot[] = "dot"; @@ -1874,11 +1875,12 @@ static PyObject *__pyx_kp_s_49; static PyObject *__pyx_kp_s_50; static PyObject *__pyx_kp_s_53; static PyObject *__pyx_kp_s_56; -static PyObject *__pyx_kp_s_61; +static PyObject *__pyx_kp_s_62; static PyObject *__pyx_kp_s_7; static PyObject *__pyx_kp_s_8; static PyObject *__pyx_kp_s_9; static PyObject *__pyx_n_s__BLEU; +static PyObject *__pyx_n_s__CER; static PyObject *__pyx_n_s__Exception; static PyObject *__pyx_n_s__IBM_BLEU; static PyObject *__pyx_n_s__IndexError; @@ -1982,9 +1984,10 @@ static PyObject *__pyx_k_tuple_54; static PyObject *__pyx_k_tuple_57; static PyObject *__pyx_k_tuple_58; static PyObject *__pyx_k_tuple_59; +static PyObject *__pyx_k_tuple_60; static PyObject *__pyx_k_codeobj_37; static PyObject *__pyx_k_codeobj_55; -static PyObject *__pyx_k_codeobj_60; +static PyObject *__pyx_k_codeobj_61; /* "_cdec.pyx":6 * cimport decoder @@ -26164,11 +26167,12 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_50, __pyx_k_50, sizeof(__pyx_k_50), 0, 0, 1, 0}, {&__pyx_kp_s_53, __pyx_k_53, sizeof(__pyx_k_53), 0, 0, 1, 0}, {&__pyx_kp_s_56, __pyx_k_56, sizeof(__pyx_k_56), 0, 0, 1, 0}, - {&__pyx_kp_s_61, __pyx_k_61, sizeof(__pyx_k_61), 0, 0, 1, 0}, + {&__pyx_kp_s_62, __pyx_k_62, sizeof(__pyx_k_62), 0, 0, 1, 0}, {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0}, {&__pyx_kp_s_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 1, 0}, {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0}, {&__pyx_n_s__BLEU, __pyx_k__BLEU, sizeof(__pyx_k__BLEU), 0, 0, 1, 1}, + {&__pyx_n_s__CER, __pyx_k__CER, sizeof(__pyx_k__CER), 0, 0, 1, 1}, {&__pyx_n_s__Exception, __pyx_k__Exception, sizeof(__pyx_k__Exception), 0, 0, 1, 1}, {&__pyx_n_s__IBM_BLEU, __pyx_k__IBM_BLEU, sizeof(__pyx_k__IBM_BLEU), 0, 0, 1, 1}, {&__pyx_n_s__IndexError, __pyx_k__IndexError, sizeof(__pyx_k__IndexError), 0, 0, 1, 1}, @@ -26565,6 +26569,7 @@ static int __Pyx_InitCachedConstants(void) { * * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< * TER = Scorer('TER') + * CER = Scorer('CER') */ __pyx_k_tuple_57 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_57)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_57); @@ -26577,6 +26582,7 @@ static int __Pyx_InitCachedConstants(void) { * * BLEU = Scorer('IBM_BLEU') * TER = Scorer('TER') # <<<<<<<<<<<<<< + * CER = Scorer('CER') */ __pyx_k_tuple_58 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_58)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_58); @@ -26585,6 +26591,18 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(((PyObject *)__pyx_n_s__TER)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_58)); + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":192 + * BLEU = Scorer('IBM_BLEU') + * TER = Scorer('TER') + * CER = Scorer('CER') # <<<<<<<<<<<<<< + */ + __pyx_k_tuple_59 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_59)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_59); + __Pyx_INCREF(((PyObject *)__pyx_n_s__CER)); + PyTuple_SET_ITEM(__pyx_k_tuple_59, 0, ((PyObject *)__pyx_n_s__CER)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__CER)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_59)); + /* "_cdec.pyx":28 * class ParseFailed(Exception): pass * @@ -26592,25 +26610,25 @@ static int __Pyx_InitCachedConstants(void) { * for key, value in config.items(): * if isinstance(value, dict): */ - __pyx_k_tuple_59 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_59)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_59); + __pyx_k_tuple_60 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_60)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_60); __Pyx_INCREF(((PyObject *)__pyx_n_s__config)); - PyTuple_SET_ITEM(__pyx_k_tuple_59, 0, ((PyObject *)__pyx_n_s__config)); + PyTuple_SET_ITEM(__pyx_k_tuple_60, 0, ((PyObject *)__pyx_n_s__config)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__config)); __Pyx_INCREF(((PyObject *)__pyx_n_s__key)); - PyTuple_SET_ITEM(__pyx_k_tuple_59, 1, ((PyObject *)__pyx_n_s__key)); + PyTuple_SET_ITEM(__pyx_k_tuple_60, 1, ((PyObject *)__pyx_n_s__key)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__key)); __Pyx_INCREF(((PyObject *)__pyx_n_s__value)); - PyTuple_SET_ITEM(__pyx_k_tuple_59, 2, ((PyObject *)__pyx_n_s__value)); + PyTuple_SET_ITEM(__pyx_k_tuple_60, 2, ((PyObject *)__pyx_n_s__value)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__value)); __Pyx_INCREF(((PyObject *)__pyx_n_s__name)); - PyTuple_SET_ITEM(__pyx_k_tuple_59, 3, ((PyObject *)__pyx_n_s__name)); + PyTuple_SET_ITEM(__pyx_k_tuple_60, 3, ((PyObject *)__pyx_n_s__name)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__name)); __Pyx_INCREF(((PyObject *)__pyx_n_s__info)); - PyTuple_SET_ITEM(__pyx_k_tuple_59, 4, ((PyObject *)__pyx_n_s__info)); + PyTuple_SET_ITEM(__pyx_k_tuple_60, 4, ((PyObject *)__pyx_n_s__info)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__info)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_59)); - __pyx_k_codeobj_60 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_59, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_61, __pyx_n_s___make_config, 28, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_60)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_60)); + __pyx_k_codeobj_61 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_60, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_62, __pyx_n_s___make_config, 28, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_61)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -26831,6 +26849,7 @@ PyMODINIT_FUNC PyInit__cdec(void) * * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< * TER = Scorer('TER') + * CER = Scorer('CER') */ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_57), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); @@ -26841,12 +26860,23 @@ PyMODINIT_FUNC PyInit__cdec(void) * * BLEU = Scorer('IBM_BLEU') * TER = Scorer('TER') # <<<<<<<<<<<<<< + * CER = Scorer('CER') */ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_58), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":192 + * BLEU = Scorer('IBM_BLEU') + * TER = Scorer('TER') + * CER = Scorer('CER') # <<<<<<<<<<<<<< + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_59), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__CER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /* "_cdec.pyx":22 * include "mteval.pxi" * diff --git a/python/src/mteval.pxi b/python/src/mteval.pxi index f67f4f04..52d2abc6 100644 --- a/python/src/mteval.pxi +++ b/python/src/mteval.pxi @@ -189,3 +189,4 @@ cdef class Metric: BLEU = Scorer('IBM_BLEU') TER = Scorer('TER') +CER = Scorer('CER') -- cgit v1.2.3 From b2a8bccb2bd713d9ec081cf3dad0162c2cb492d8 Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Fri, 27 Jul 2012 01:16:03 -0400 Subject: [python] Fork of the suffix-array extractor with surface improvements Available as the cdec.sa module, with commande-line helpers: python -m cdec.sa.compile -f ... -e ... -a ... -o sa-out/ -c extract.ini python -m cdec.sa.extract -c extract.ini -g grammars-out/ < input.txt > input.sgml + renamed cdec.scfg -> cdec.sa + Python README --- python/README.md | 33 + python/cdec/sa/__init__.py | 4 + python/cdec/sa/compile.py | 94 + python/cdec/sa/extract.py | 32 + python/cdec/sa/extractor.py | 73 + python/cdec/sa/features.py | 60 + python/cdec/scfg/__init__.py | 1 - python/cdec/scfg/extractor.py | 120 - python/cdec/scfg/features.py | 62 - python/setup.py | 6 +- python/src/sa/_cdec_sa.c | 62490 +++++++++++++++++++++++++++++++++++++ python/src/sa/_cdec_sa.pyx | 29 + python/src/sa/alignment.pxi | 105 + python/src/sa/bilex.pxi | 418 + python/src/sa/data_array.pxi | 146 + python/src/sa/float_list.pxi | 77 + python/src/sa/int_list.pxi | 177 + python/src/sa/lcp.pxi | 89 + python/src/sa/precomputation.pxi | 454 + python/src/sa/rule.pxi | 241 + python/src/sa/rulefactory.pxi | 1794 ++ python/src/sa/str_map.pxi | 23 + python/src/sa/strmap.cc | 232 + python/src/sa/strmap.h | 22 + python/src/sa/suffix_array.pxi | 259 + python/src/sa/sym.pxi | 101 + python/src/sa/veb.pxi | 392 + 27 files changed, 67349 insertions(+), 185 deletions(-) create mode 100644 python/README.md create mode 100644 python/cdec/sa/__init__.py create mode 100644 python/cdec/sa/compile.py create mode 100644 python/cdec/sa/extract.py create mode 100644 python/cdec/sa/extractor.py create mode 100644 python/cdec/sa/features.py delete mode 100644 python/cdec/scfg/__init__.py delete mode 100644 python/cdec/scfg/extractor.py delete mode 100644 python/cdec/scfg/features.py create mode 100644 python/src/sa/_cdec_sa.c create mode 100644 python/src/sa/_cdec_sa.pyx create mode 100644 python/src/sa/alignment.pxi create mode 100644 python/src/sa/bilex.pxi create mode 100644 python/src/sa/data_array.pxi create mode 100644 python/src/sa/float_list.pxi create mode 100644 python/src/sa/int_list.pxi create mode 100644 python/src/sa/lcp.pxi create mode 100644 python/src/sa/precomputation.pxi create mode 100644 python/src/sa/rule.pxi create mode 100644 python/src/sa/rulefactory.pxi create mode 100644 python/src/sa/str_map.pxi create mode 100644 python/src/sa/strmap.cc create mode 100644 python/src/sa/strmap.h create mode 100644 python/src/sa/suffix_array.pxi create mode 100644 python/src/sa/sym.pxi create mode 100644 python/src/sa/veb.pxi (limited to 'python/src') diff --git a/python/README.md b/python/README.md new file mode 100644 index 00000000..1ddb61a9 --- /dev/null +++ b/python/README.md @@ -0,0 +1,33 @@ +pycdec is a Python interface to cdec + +## Installation + +pycdec depends on the configobj module: + + pip install configobj + +Build and install pycdec: + + python setup.py install + +## Grammar extractor + +Compile a parallel corpus and a word alignment into a suffix array representation: + + python -m cdec.sa.compile -f f.txt -e e.txt -a a.txt -o output/ -c extract.ini + +Extract grammar rules from the compiled corpus: + + cat input.txt | python -m cdec.sa.extract -c extract.ini -g grammars/ + +This will create per-sentence grammar files in the `grammars` directory and output annotated input suitable for translation with cdec. + +## Library usage + +A basic demo of pycdec's features is available in `test.py` + +More documentation will come as the API becomes stable. + +--- + +pycdec was contributed by [Victor Chahuneau](http://victor.chahuneau.fr) \ No newline at end of file diff --git a/python/cdec/sa/__init__.py b/python/cdec/sa/__init__.py new file mode 100644 index 00000000..ddefa280 --- /dev/null +++ b/python/cdec/sa/__init__.py @@ -0,0 +1,4 @@ +from _cdec_sa import sym_tostring, sym_isvar, sym_fromstring,\ + SuffixArray, DataArray, LCP, Precomputation, Alignment, BiLex,\ + HieroCachingRuleFactory, Sampler +from extractor import GrammarExtractor diff --git a/python/cdec/sa/compile.py b/python/cdec/sa/compile.py new file mode 100644 index 00000000..061cdab2 --- /dev/null +++ b/python/cdec/sa/compile.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python +import argparse +import os +import logging +import configobj +import cdec.sa + +MAX_PHRASE_LENGTH = 4 +def precompute(f_sa, max_len, max_nt, max_size, min_gap, rank1, rank2): + lcp = cdec.sa.LCP(f_sa) + stats = sorted(lcp.compute_stats(MAX_PHRASE_LENGTH), reverse=True) + precomp = cdec.sa.Precomputation(from_stats=stats, + fsarray=f_sa, + precompute_rank=rank1, + precompute_secondary_rank=rank2, + max_length=max_len, + max_nonterminals=max_nt, + train_max_initial_size=max_size, + train_min_gap_size=min_gap) + return precomp + +def main(): + logging.basicConfig(level=logging.INFO) + logger = logging.getLogger('cdec.sa.compile') + parser = argparse.ArgumentParser(description='Compile a corpus into a suffix array.') + parser.add_argument('--maxnt', '-n', type=int, default=2, + help='Maximum number of non-terminal symbols') + parser.add_argument('--maxlen', '-l', type=int, default=5, + help='Maximum number of terminals') + parser.add_argument('--maxsize', '-s', type=int, default=15, + help='Maximum rule span') + parser.add_argument('--mingap', '-g', type=int, default=1, + help='Minimum gap size') + parser.add_argument('--rank1', '-r1', type=int, default=100, + help='Number of pre-computed frequent patterns') + parser.add_argument('--rank2', '-r2', type=int, default=10, + help='Number of pre-computed super-frequent patterns)') + parser.add_argument('-c', '--config', default='/dev/stdout', + help='Output configuration') + parser.add_argument('-o', '--output', required=True, + help='Output path') + parser.add_argument('-f', '--source', required=True, + help='Source language corpus') + parser.add_argument('-e', '--target', required=True, + help='Target language corpus') + parser.add_argument('-a', '--alignment', required=True, + help='Bitext word alignment') + args = parser.parse_args() + + param_names = ("max_len", "max_nt", "max_size", "min_gap", "rank1", "rank2") + params = (args.maxlen, args.maxnt, args.maxsize, args.mingap, args.rank1, args.rank2) + + if not os.path.exists(args.output): + os.mkdir(args.output) + + f_sa_bin = os.path.join(args.output, 'f.sa.bin') + e_bin = os.path.join(args.output, 'e.bin') + precomp_file = 'precomp.{0}.{1}.{2}.{3}.{4}.{5}.bin'.format(*params) + precomp_bin = os.path.join(args.output, precomp_file) + a_bin = os.path.join(args.output, 'a.bin') + lex_bin = os.path.join(args.output, 'lex.bin') + + logger.info('Compiling source suffix array') + f_sa = cdec.sa.SuffixArray(from_text=args.source) + f_sa.write_binary(f_sa_bin) + + logger.info('Compiling target data array') + e = cdec.sa.DataArray(from_text=args.target) + e.write_binary(e_bin) + + logger.info('Precomputing frequent phrases') + precompute(f_sa, *params).write_binary(precomp_bin) + + logger.info('Compiling alignment') + a = cdec.sa.Alignment(from_text=args.alignment) + a.write_binary(a_bin) + + logger.info('Compiling bilexical dictionary') + lex = cdec.sa.BiLex(from_data=True, alignment=a, earray=e, fsarray=f_sa) + lex.write_binary(lex_bin) + + # Write configuration + config = configobj.ConfigObj(args.config, unrepr=True) + config['f_sa_file'] = f_sa_bin + config['e_file'] = e_bin + config['a_file'] = a_bin + config['lex_file'] = lex_bin + config['precompute_file'] = precomp_bin + for name, value in zip(param_names, params): + config[name] = value + config.write() + +if __name__ == '__main__': + main() diff --git a/python/cdec/sa/extract.py b/python/cdec/sa/extract.py new file mode 100644 index 00000000..c6da5e9d --- /dev/null +++ b/python/cdec/sa/extract.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +import sys +import os +import argparse +import logging +import configobj +import cdec.sa + +def main(): + logging.basicConfig(level=logging.INFO) + parser = argparse.ArgumentParser(description='Extract grammars from a compiled corpus.') + parser.add_argument('-c', '--config', required=True, + help='Extractor configuration') + parser.add_argument('-g', '--grammars', required=True, + help='Grammar output path') + args = parser.parse_args() + + if not os.path.exists(args.grammars): + os.mkdir(args.grammars) + + extractor = cdec.sa.GrammarExtractor(configobj.ConfigObj(args.config, unrepr=True)) + for i, sentence in enumerate(sys.stdin): + sentence = sentence[:-1] + grammar_file = os.path.join(args.grammars, 'grammar.{0}'.format(i)) + with open(grammar_file, 'w') as output: + for rule in extractor.grammar(sentence): + output.write(str(rule)+'\n') + grammar_file = os.path.abspath(grammar_file) + print('{1}'.format(grammar_file, sentence)) + +if __name__ == '__main__': + main() diff --git a/python/cdec/sa/extractor.py b/python/cdec/sa/extractor.py new file mode 100644 index 00000000..c97b3c6f --- /dev/null +++ b/python/cdec/sa/extractor.py @@ -0,0 +1,73 @@ +from itertools import chain +from cdec.sa.features import EgivenFCoherent, SampleCountF, CountEF,\ + MaxLexEgivenF, MaxLexFgivenE, IsSingletonF, IsSingletonFE +import cdec.sa + +# maximum span of a grammar rule in TEST DATA +MAX_INITIAL_SIZE = 15 + +class GrammarExtractor: + def __init__(self, config): + # TODO if str, read config + alignment = cdec.sa.Alignment(from_binary=config['a_file']) + self.factory = cdec.sa.HieroCachingRuleFactory( + # compiled alignment object (REQUIRED) + alignment, + # name of generic nonterminal used by Hiero + category="[X]", + # maximum number of contiguous chunks of terminal symbols in RHS of a rule + max_chunks=config['max_nt']+1, + # maximum span of a grammar rule in TEST DATA + max_initial_size=MAX_INITIAL_SIZE, + # maximum number of symbols (both T and NT) allowed in a rule + max_length=config['max_len'], + # maximum number of nonterminals allowed in a rule (set >2 at your own risk) + max_nonterminals=config['max_nt'], + # maximum number of contiguous chunks of terminal symbols + # in target-side RHS of a rule. + max_target_chunks=config['max_nt']+1, + # maximum number of target side symbols (both T and NT) allowed in a rule. + max_target_length=MAX_INITIAL_SIZE, + # minimum span of a nonterminal in the RHS of a rule in TEST DATA + min_gap_size=1, + # filename of file containing precomputed collocations + precompute_file=config['precompute_file'], + # maximum frequency rank of patterns used to compute triples (< 20) + precompute_secondary_rank=config['rank2'], + # maximum frequency rank of patterns used to compute collocations (< 300) + precompute_rank=config['rank1'], + # require extracted rules to have at least one aligned word + require_aligned_terminal=True, + # require each contiguous chunk of extracted rules + # to have at least one aligned word + require_aligned_chunks=False, + # maximum span of a grammar rule extracted from TRAINING DATA + train_max_initial_size=config['max_size'], + # minimum span of an RHS nonterminal in a rule extracted from TRAINING DATA + train_min_gap_size=config['min_gap'], + # True if phrases should be tight, False otherwise (better but slower) + tight_phrases=True, + ) + + # lexical weighting tables + tt = cdec.sa.BiLex(from_binary=config['lex_file']) + + self.models = (EgivenFCoherent, SampleCountF, CountEF, + MaxLexFgivenE(tt), MaxLexEgivenF(tt), IsSingletonF, IsSingletonFE) + + fsarray = cdec.sa.SuffixArray(from_binary=config['f_sa_file']) + edarray = cdec.sa.DataArray(from_binary=config['e_file']) + + # lower=faster, higher=better; improvements level off above 200-300 range, + # -1 = don't sample, use all data (VERY SLOW!) + sampler = cdec.sa.Sampler(300, fsarray) + + self.factory.configure(fsarray, edarray, sampler) + + def grammar(self, sentence): + if isinstance(sentence, unicode): + sentence = sentence.encode('utf8') + cnet = chain(('',), sentence.split(), ('',)) + cnet = (cdec.sa.sym_fromstring(word, terminal=True) for word in cnet) + cnet = tuple(((word, None, 1), ) for word in cnet) + return self.factory.input(cnet, self.models) diff --git a/python/cdec/sa/features.py b/python/cdec/sa/features.py new file mode 100644 index 00000000..8d35d8e6 --- /dev/null +++ b/python/cdec/sa/features.py @@ -0,0 +1,60 @@ +from __future__ import division +import math +import cdec.sa + +MAXSCORE = 99 + +def EgivenF(fphrase, ephrase, paircount, fcount, fsample_count): # p(e|f) + return -math.log10(paircount/fcount) + +def CountEF(fphrase, ephrase, paircount, fcount, fsample_count): + return math.log10(1 + paircount) + +def SampleCountF(fphrase, ephrase, paircount, fcount, fsample_count): + return math.log10(1 + fsample_count) + +def EgivenFCoherent(fphrase, ephrase, paircount, fcount, fsample_count): + prob = paircount/fsample_count + return -math.log10(prob) if prob > 0 else MAXSCORE + +def CoherenceProb(fphrase, ephrase, paircount, fcount, fsample_count): + return -math.log10(fcount/fsample_count) + +def MaxLexEgivenF(ttable): + def feature(fphrase, ephrase, paircount, fcount, fsample_count): + fwords = [cdec.sa.sym_tostring(w) for w in fphrase if not cdec.sa.sym_isvar(w)] + fwords.append('NULL') + ewords = (cdec.sa.sym_tostring(w) for w in ephrase if not cdec.sa.sym_isvar(w)) + def score(): + for e in ewords: + maxScore = max(ttable.get_score(f, e, 0) for f in fwords) + yield -math.log10(maxScore) if maxScore > 0 else MAXSCORE + return sum(score()) + return feature + +def MaxLexFgivenE(ttable): + def feature(fphrase, ephrase, paircount, fcount, fsample_count): + fwords = (cdec.sa.sym_tostring(w) for w in fphrase if not cdec.sa.sym_isvar(w)) + ewords = [cdec.sa.sym_tostring(w) for w in ephrase if not cdec.sa.sym_isvar(w)] + ewords.append('NULL') + def score(): + for f in fwords: + maxScore = max(ttable.get_score(f, e, 1) for e in ewords) + yield -math.log10(maxScore) if maxScore > 0 else MAXSCORE + return sum(score()) + return feature + +def IsSingletonF(fphrase, ephrase, paircount, fcount, fsample_count): + return (fcount == 1) + +def IsSingletonFE(fphrase, ephrase, paircount, fcount, fsample_count): + return (paircount == 1) + +def IsNotSingletonF(fphrase, ephrase, paircount, fcount, fsample_count): + return (fcount > 1) + +def IsNotSingletonFE(fphrase, ephrase, paircount, fcount, fsample_count): + return (paircount > 1) + +def IsFEGreaterThanZero(fphrase, ephrase, paircount, fcount, fsample_count): + return (paircount > 0.01) diff --git a/python/cdec/scfg/__init__.py b/python/cdec/scfg/__init__.py deleted file mode 100644 index 6eb2f88f..00000000 --- a/python/cdec/scfg/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from extractor import GrammarExtractor diff --git a/python/cdec/scfg/extractor.py b/python/cdec/scfg/extractor.py deleted file mode 100644 index 1dfa2421..00000000 --- a/python/cdec/scfg/extractor.py +++ /dev/null @@ -1,120 +0,0 @@ -import sys, os -import re -import StringIO -from itertools import chain - -import clex -import rulefactory -import calignment -import csuf -import cdat -import sym -import log - -from features import EgivenFCoherent, SampleCountF, CountEF,\ - MaxLexEgivenF, MaxLexFgivenE, IsSingletonF, IsSingletonFE -from features import contextless - -log.level = -1 - -class Output(StringIO.StringIO): - def close(self): - pass - - def __str__(self): - return self.getvalue() - -def get_cn(sentence): - sentence = chain(('',), sentence.split(), ('',)) - sentence = (sym.fromstring(word, terminal=True) for word in sentence) - return tuple(((word, None, 1), ) for word in sentence) - -class PhonyGrammar: - def add(self, thing): - pass - -class GrammarExtractor: - def __init__(self, cfg): - if isinstance(cfg, dict): - config = cfg - elif isinstance(cfg, str): - cfg_file = os.path.basename(cfg) - if not re.match(r'^\w+\.py$', cfg_file): - raise ValueError('Config must be a *.py file') - sys.path.append(os.path.dirname(cfg)) - config = __import__(cfg_file.replace('.py', '')).__dict__ - sys.path.pop() - alignment = calignment.Alignment(config['a_file'], from_binary=True) - self.factory = rulefactory.HieroCachingRuleFactory( - # compiled alignment object (REQUIRED) - alignment=alignment, - # name of generic nonterminal used by Hiero - category="[X]", - # do not change for extraction - grammar=PhonyGrammar(), # TODO: set to None? - # maximum number of contiguous chunks of terminal symbols in RHS of a rule. If None, defaults to max_nonterminals+1 - max_chunks=None, - # maximum span of a grammar rule in TEST DATA - max_initial_size=15, - # maximum number of symbols (both T and NT) allowed in a rule - max_length=config['max_len'], - # maximum number of nonterminals allowed in a rule (set >2 at your own risk) - max_nonterminals=config['max_nt'], - # maximum number of contiguous chunks of terminal symbols in target-side RHS of a rule. If None, defaults to max_nonterminals+1 - max_target_chunks=None, - # maximum number of target side symbols (both T and NT) allowed in a rule. If None, defaults to max_initial_size - max_target_length=None, - # minimum span of a nonterminal in the RHS of a rule in TEST DATA - min_gap_size=1, - # filename of file containing precomputed collocations - precompute_file=config['precompute_file'], - # maximum frequency rank of patterns used to compute triples (don't set higher than 20). - precompute_secondary_rank=config['rank2'], - # maximum frequency rank of patterns used to compute collocations (no need to set higher than maybe 200-300) - precompute_rank=config['rank1'], - # require extracted rules to have at least one aligned word - require_aligned_terminal=True, - # require each contiguous chunk of extracted rules to have at least one aligned word - require_aligned_chunks=False, - # generate a complete grammar for each input sentence - per_sentence_grammar=True, - # maximum span of a grammar rule extracted from TRAINING DATA - train_max_initial_size=config['max_size'], - # minimum span of an RHS nonterminal in a rule extracted from TRAINING DATA - train_min_gap_size=config['min_gap'], - # True if phrases should be tight, False otherwise (False seems to give better results but is slower) - tight_phrases=True, - ) - self.fsarray = csuf.SuffixArray(config['f_sa_file'], from_binary=True) - self.edarray = cdat.DataArray(config['e_file'], from_binary=True) - - self.factory.registerContext(self) - - # lower=faster, higher=better; improvements level off above 200-300 range, -1 = don't sample, use all data (VERY SLOW!) - self.sampler = rulefactory.Sampler(300) - self.sampler.registerContext(self) - - # lexical weighting tables - tt = clex.CLex(config['lex_file'], from_binary=True) - - self.models = (EgivenFCoherent, SampleCountF, CountEF, - MaxLexFgivenE(tt), MaxLexEgivenF(tt), IsSingletonF, IsSingletonFE) - self.models = tuple(contextless(feature) for feature in self.models) - - def grammar(self, sentence): - if isinstance(sentence, unicode): - sentence = sentence.encode('utf8') - out = Output() - cn = get_cn(sentence) - self.factory.input(cn, output=out) - return str(out) - -def main(config): - extractor = GrammarExtractor(config) - sys.stdout.write(extractor.grammar(next(sys.stdin))) - -if __name__ == '__main__': - if len(sys.argv) != 2 or not sys.argv[1].endswith('.py'): - sys.stderr.write('Usage: %s config.py\n' % sys.argv[0]) - sys.exit(1) - main(*sys.argv[1:]) diff --git a/python/cdec/scfg/features.py b/python/cdec/scfg/features.py deleted file mode 100644 index 6419cdd8..00000000 --- a/python/cdec/scfg/features.py +++ /dev/null @@ -1,62 +0,0 @@ -from __future__ import division -import math -import sym - -def contextless(feature): - feature.compute_contextless_score = feature - return feature - -MAXSCORE = 99 - -def EgivenF(fphrase, ephrase, paircount, fcount, fsample_count): # p(e|f) - return -math.log10(paircount/fcount) - -def CountEF(fphrase, ephrase, paircount, fcount, fsample_count): - return math.log10(1 + paircount) - -def SampleCountF(fphrase, ephrase, paircount, fcount, fsample_count): - return math.log10(1 + fsample_count) - -def EgivenFCoherent(fphrase, ephrase, paircount, fcount, fsample_count): - prob = paircount/fsample_count - return -math.log10(prob) if prob > 0 else MAXSCORE - -def CoherenceProb(fphrase, ephrase, paircount, fcount, fsample_count): - return -math.log10(fcount/fsample_count) - -def MaxLexEgivenF(ttable): - def feature(fphrase, ephrase, paircount, fcount, fsample_count): - fwords = [sym.tostring(w) for w in fphrase if not sym.isvar(w)] + ['NULL'] - ewords = (sym.tostring(w) for w in ephrase if not sym.isvar(w)) - def score(): - for e in ewords: - maxScore = max(ttable.get_score(f, e, 0) for f in fwords) - yield -math.log10(maxScore) if maxScore > 0 else MAXSCORE - return sum(score()) - return feature - -def MaxLexFgivenE(ttable): - def feature(fphrase, ephrase, paircount, fcount, fsample_count): - fwords = (sym.tostring(w) for w in fphrase if not sym.isvar(w)) - ewords = [sym.tostring(w) for w in ephrase if not sym.isvar(w)] + ['NULL'] - def score(): - for f in fwords: - maxScore = max(ttable.get_score(f, e, 1) for e in ewords) - yield -math.log10(maxScore) if maxScore > 0 else MAXSCORE - return sum(score()) - return feature - -def IsSingletonF(fphrase, ephrase, paircount, fcount, fsample_count): - return (fcount == 1) - -def IsSingletonFE(fphrase, ephrase, paircount, fcount, fsample_count): - return (paircount == 1) - -def IsNotSingletonF(fphrase, ephrase, paircount, fcount, fsample_count): - return (fcount > 1) - -def IsNotSingletonFE(fphrase, ephrase, paircount, fcount, fsample_count): - return (paircount > 1) - -def IsFEGreaterThanZero(fphrase, ephrase, paircount, fcount, fsample_count): - return (paircount > 0.01) diff --git a/python/setup.py b/python/setup.py index 701841a4..9ae4a35c 100644 --- a/python/setup.py +++ b/python/setup.py @@ -34,17 +34,19 @@ else: ext_modules = [ Extension(name='_cdec', sources=['src/_cdec.cpp'], - language='C++', include_dirs=INC, library_dirs=LIB, libraries=[BOOST_PROGRAM_OPTIONS, 'z', 'cdec', 'utils', 'mteval', 'training', 'klm', 'klm_util'], extra_compile_args=['-DHAVE_CONFIG_H'], extra_link_args=LINK_ARGS), + Extension(name='_cdec_sa', + sources=['src/sa/_cdec_sa.c', 'src/sa/strmap.cc']) ] setup( name='cdec', ext_modules=ext_modules, - packages=['cdec', 'cdec.scfg'] + requires=['configobj'], + packages=['cdec', 'cdec.sa'] ) diff --git a/python/src/sa/_cdec_sa.c b/python/src/sa/_cdec_sa.c new file mode 100644 index 00000000..5bd9b28c --- /dev/null +++ b/python/src/sa/_cdec_sa.c @@ -0,0 +1,62490 @@ +/* Generated by Cython 0.16 on Fri Jul 27 00:18:44 2012 */ + +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#ifndef Py_PYTHON_H + #error Python headers needed to compile C extensions, please install development version of Python. +#elif PY_VERSION_HEX < 0x02040000 + #error Cython requires Python 2.4+. +#else +#include /* For offsetof */ +#ifndef offsetof +#define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) +#endif + +#if !defined(WIN32) && !defined(MS_WINDOWS) + #ifndef __stdcall + #define __stdcall + #endif + #ifndef __cdecl + #define __cdecl + #endif + #ifndef __fastcall + #define __fastcall + #endif +#endif + +#ifndef DL_IMPORT + #define DL_IMPORT(t) t +#endif +#ifndef DL_EXPORT + #define DL_EXPORT(t) t +#endif + +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif + +#ifndef Py_HUGE_VAL + #define Py_HUGE_VAL HUGE_VAL +#endif + +#ifdef PYPY_VERSION +#define CYTHON_COMPILING_IN_PYPY 1 +#define CYTHON_COMPILING_IN_CPYTHON 0 +#else +#define CYTHON_COMPILING_IN_PYPY 0 +#define CYTHON_COMPILING_IN_CPYTHON 1 +#endif + +#if CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyCFunction_Call PyObject_Call +#else + #define __Pyx_PyCFunction_Call PyCFunction_Call +#endif + +#if PY_VERSION_HEX < 0x02050000 + typedef int Py_ssize_t; + #define PY_SSIZE_T_MAX INT_MAX + #define PY_SSIZE_T_MIN INT_MIN + #define PY_FORMAT_SIZE_T "" + #define PyInt_FromSsize_t(z) PyInt_FromLong(z) + #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o) + #define PyNumber_Index(o) PyNumber_Int(o) + #define PyIndex_Check(o) PyNumber_Check(o) + #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message) + #define __PYX_BUILD_PY_SSIZE_T "i" +#else + #define __PYX_BUILD_PY_SSIZE_T "n" +#endif + +#if PY_VERSION_HEX < 0x02060000 + #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) + #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) + #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) + #define PyVarObject_HEAD_INIT(type, size) \ + PyObject_HEAD_INIT(type) size, + #define PyType_Modified(t) + + typedef struct { + void *buf; + PyObject *obj; + Py_ssize_t len; + Py_ssize_t itemsize; + int readonly; + int ndim; + char *format; + Py_ssize_t *shape; + Py_ssize_t *strides; + Py_ssize_t *suboffsets; + void *internal; + } Py_buffer; + + #define PyBUF_SIMPLE 0 + #define PyBUF_WRITABLE 0x0001 + #define PyBUF_FORMAT 0x0004 + #define PyBUF_ND 0x0008 + #define PyBUF_STRIDES (0x0010 | PyBUF_ND) + #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) + #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) + #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) + #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) + #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE) + #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE) + + typedef int (*getbufferproc)(PyObject *, Py_buffer *, int); + typedef void (*releasebufferproc)(PyObject *, Py_buffer *); +#endif + +#if PY_MAJOR_VERSION < 3 + #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ + PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else + #define __Pyx_BUILTIN_MODULE_NAME "builtins" + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ + PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#endif + +#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6 + #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict") +#endif + +#if PY_MAJOR_VERSION >= 3 + #define Py_TPFLAGS_CHECKTYPES 0 + #define Py_TPFLAGS_HAVE_INDEX 0 +#endif + +#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) + #define Py_TPFLAGS_HAVE_NEWBUFFER 0 +#endif + + +#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_GET_LENGTH) + #define CYTHON_PEP393_ENABLED 1 + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) +#else + #define CYTHON_PEP393_ENABLED 0 + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) +#endif + +#if PY_MAJOR_VERSION >= 3 + #define PyBaseString_Type PyUnicode_Type + #define PyStringObject PyUnicodeObject + #define PyString_Type PyUnicode_Type + #define PyString_Check PyUnicode_Check + #define PyString_CheckExact PyUnicode_CheckExact +#endif + +#if PY_VERSION_HEX < 0x02060000 + #define PyBytesObject PyStringObject + #define PyBytes_Type PyString_Type + #define PyBytes_Check PyString_Check + #define PyBytes_CheckExact PyString_CheckExact + #define PyBytes_FromString PyString_FromString + #define PyBytes_FromStringAndSize PyString_FromStringAndSize + #define PyBytes_FromFormat PyString_FromFormat + #define PyBytes_DecodeEscape PyString_DecodeEscape + #define PyBytes_AsString PyString_AsString + #define PyBytes_AsStringAndSize PyString_AsStringAndSize + #define PyBytes_Size PyString_Size + #define PyBytes_AS_STRING PyString_AS_STRING + #define PyBytes_GET_SIZE PyString_GET_SIZE + #define PyBytes_Repr PyString_Repr + #define PyBytes_Concat PyString_Concat + #define PyBytes_ConcatAndDel PyString_ConcatAndDel +#endif + +#if PY_VERSION_HEX < 0x02060000 + #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) + #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type) +#endif +#ifndef PySet_CheckExact + #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) +#endif + +#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) + +#if PY_MAJOR_VERSION >= 3 + #define PyIntObject PyLongObject + #define PyInt_Type PyLong_Type + #define PyInt_Check(op) PyLong_Check(op) + #define PyInt_CheckExact(op) PyLong_CheckExact(op) + #define PyInt_FromString PyLong_FromString + #define PyInt_FromUnicode PyLong_FromUnicode + #define PyInt_FromLong PyLong_FromLong + #define PyInt_FromSize_t PyLong_FromSize_t + #define PyInt_FromSsize_t PyLong_FromSsize_t + #define PyInt_AsLong PyLong_AsLong + #define PyInt_AS_LONG PyLong_AS_LONG + #define PyInt_AsSsize_t PyLong_AsSsize_t + #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask + #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask +#endif + +#if PY_MAJOR_VERSION >= 3 + #define PyBoolObject PyLongObject +#endif + +#if PY_VERSION_HEX < 0x03020000 + typedef long Py_hash_t; + #define __Pyx_PyInt_FromHash_t PyInt_FromLong + #define __Pyx_PyInt_AsHash_t PyInt_AsLong +#else + #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t + #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t +#endif + +#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300) + #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b) + #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value) + #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b) +#else + #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \ + (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \ + (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \ + (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0))) + #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \ + (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ + (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \ + (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1))) + #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \ + (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ + (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \ + (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1))) +#endif + +#if PY_MAJOR_VERSION >= 3 + #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) +#endif + +#if PY_VERSION_HEX < 0x02050000 + #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) + #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) + #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) +#else + #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) + #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) + #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) +#endif + +#if PY_VERSION_HEX < 0x02050000 + #define __Pyx_NAMESTR(n) ((char *)(n)) + #define __Pyx_DOCSTR(n) ((char *)(n)) +#else + #define __Pyx_NAMESTR(n) (n) + #define __Pyx_DOCSTR(n) (n) +#endif + +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) +#else + #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) +#endif + +#ifndef __PYX_EXTERN_C + #ifdef __cplusplus + #define __PYX_EXTERN_C extern "C" + #else + #define __PYX_EXTERN_C extern + #endif +#endif + +#if defined(WIN32) || defined(MS_WINDOWS) +#define _USE_MATH_DEFINES +#endif +#include +#define __PYX_HAVE___cdec_sa +#define __PYX_HAVE_API___cdec_sa +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "strmap.h" +#include "math.h" +#ifdef _OPENMP +#include +#endif /* _OPENMP */ + +#ifdef PYREX_WITHOUT_ASSERTIONS +#define CYTHON_WITHOUT_ASSERTIONS +#endif + + +/* inline attribute */ +#ifndef CYTHON_INLINE + #if defined(__GNUC__) + #define CYTHON_INLINE __inline__ + #elif defined(_MSC_VER) + #define CYTHON_INLINE __inline + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_INLINE inline + #else + #define CYTHON_INLINE + #endif +#endif + +/* unused attribute */ +#ifndef CYTHON_UNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +#endif + +typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ + + +/* Type Conversion Predeclarations */ + +#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s) +#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s)) + +#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None) +#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); +static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); + +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); +static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); + +#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) +#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) + +#ifdef __GNUC__ + /* Test for GCC > 2.95 */ + #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) + #define likely(x) __builtin_expect(!!(x), 1) + #define unlikely(x) __builtin_expect(!!(x), 0) + #else /* __GNUC__ > 2 ... */ + #define likely(x) (x) + #define unlikely(x) (x) + #endif /* __GNUC__ > 2 ... */ +#else /* __GNUC__ */ + #define likely(x) (x) + #define unlikely(x) (x) +#endif /* __GNUC__ */ + +static PyObject *__pyx_m; +static PyObject *__pyx_b; +static PyObject *__pyx_empty_tuple; +static PyObject *__pyx_empty_bytes; +static int __pyx_lineno; +static int __pyx_clineno = 0; +static const char * __pyx_cfilenm= __FILE__; +static const char *__pyx_filename; + + +static const char *__pyx_f[] = { + "_cdec_sa.pyx", + "float_list.pxi", + "int_list.pxi", + "data_array.pxi", + "alignment.pxi", + "bilex.pxi", + "veb.pxi", + "rule.pxi", + "rulefactory.pxi", + "lcp.pxi", + "sym.pxi", + "precomputation.pxi", + "suffix_array.pxi", + "str_map.pxi", +}; + +/*--- Type declarations ---*/ +struct __pyx_obj_8_cdec_sa_VEB; +struct __pyx_obj_8_cdec_sa_Sampler; +struct __pyx_obj_8_cdec_sa_BitSet; +struct __pyx_obj_8_cdec_sa_DataArray; +struct __pyx_obj_8_cdec_sa_TrieNode; +struct __pyx_obj_8_cdec_sa_VEBIterator; +struct __pyx_obj_8_cdec_sa_BitSetIterator; +struct __pyx_obj_8_cdec_sa_Phrase; +struct __pyx_obj_8_cdec_sa_IntList; +struct __pyx_obj_8_cdec_sa_ExtendedTrieNode; +struct __pyx_obj_8_cdec_sa_PhraseLocation; +struct __pyx_obj_8_cdec_sa_Rule; +struct __pyx_obj_8_cdec_sa_LCP; +struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory; +struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats; +struct __pyx_obj_8_cdec_sa_BiLex; +struct __pyx_obj_8_cdec_sa_SuffixArray; +struct __pyx_obj_8_cdec_sa_StringMap; +struct __pyx_obj_8_cdec_sa_TrieMap; +struct __pyx_obj_8_cdec_sa_Alphabet; +struct __pyx_obj_8_cdec_sa_Alignment; +struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input; +struct __pyx_obj_8_cdec_sa_Precomputation; +struct __pyx_obj_8_cdec_sa_FloatList; +struct __pyx_obj_8_cdec_sa_TrieTable; +struct __pyx_t_8_cdec_sa__node; +struct __pyx_t_8_cdec_sa__BitSet; +struct __pyx_t_8_cdec_sa__VEB; +struct __pyx_t_8_cdec_sa__Trie_Edge; +struct __pyx_t_8_cdec_sa__Trie_Node; +struct __pyx_t_8_cdec_sa_match_node; +struct __pyx_t_8_cdec_sa_Matching; + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":9 + * from libc.string cimport memset, strcpy, strlen + * + * cdef struct _node: # <<<<<<<<<<<<<< + * _node* smaller + * _node* bigger + */ +struct __pyx_t_8_cdec_sa__node { + struct __pyx_t_8_cdec_sa__node *smaller; + struct __pyx_t_8_cdec_sa__node *bigger; + int key; + int val; +}; + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":30 + * _init_lower_mask() + * + * cdef struct _BitSet: # <<<<<<<<<<<<<< + * long bitset + * int min_val + */ +struct __pyx_t_8_cdec_sa__BitSet { + long bitset; + int min_val; + int max_val; + int size; +}; + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":168 + * return result + * + * cdef struct _VEB: # <<<<<<<<<<<<<< + * int top_universe_size + * int num_bottom_bits + */ +struct __pyx_t_8_cdec_sa__VEB { + int top_universe_size; + int num_bottom_bits; + int max_val; + int min_val; + int size; + void *top; + void **bottom; +}; + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":10 + * cdef struct _Trie_Node # forward decl + * + * cdef struct _Trie_Edge: # <<<<<<<<<<<<<< + * int val + * _Trie_Node* node + */ +struct __pyx_t_8_cdec_sa__Trie_Edge { + int val; + struct __pyx_t_8_cdec_sa__Trie_Node *node; + struct __pyx_t_8_cdec_sa__Trie_Edge *bigger; + struct __pyx_t_8_cdec_sa__Trie_Edge *smaller; +}; + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":8 + * from libc.string cimport memset, memcpy + * + * cdef struct _Trie_Node # forward decl # <<<<<<<<<<<<<< + * + * cdef struct _Trie_Edge: + */ +struct __pyx_t_8_cdec_sa__Trie_Node { + struct __pyx_t_8_cdec_sa__Trie_Edge *root; + int *arr; + int arr_len; +}; + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":48 + * + * # linked list structure for storing matches in BaselineRuleFactory + * cdef struct match_node: # <<<<<<<<<<<<<< + * int* match + * match_node* next + */ +struct __pyx_t_8_cdec_sa_match_node { + int *match; + struct __pyx_t_8_cdec_sa_match_node *next; +}; + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":145 + * + * # struct used to encapsulate a single matching + * cdef struct Matching: # <<<<<<<<<<<<<< + * int* arr + * int start + */ +struct __pyx_t_8_cdec_sa_Matching { + int *arr; + int start; + int end; + int sent_id; + int size; +}; + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":354 + * + * + * cdef class VEB: # <<<<<<<<<<<<<< + * cdef _VEB* veb + * cdef int _findsucc(self, int i) + */ +struct __pyx_obj_8_cdec_sa_VEB { + PyObject_HEAD + struct __pyx_vtabstruct_8_cdec_sa_VEB *__pyx_vtab; + struct __pyx_t_8_cdec_sa__VEB *veb; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":79 + * + * + * cdef class Sampler: # <<<<<<<<<<<<<< + * '''A Sampler implements a logic for choosing + * samples from a population range''' + */ +struct __pyx_obj_8_cdec_sa_Sampler { + PyObject_HEAD + int sample_size; + struct __pyx_obj_8_cdec_sa_IntList *sa; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":118 + * # (entirely C-implemented) _BitSet struct. + * # Very slow; use only for debugging + * cdef class BitSet: # <<<<<<<<<<<<<< + * + * cdef _BitSet* b + */ +struct __pyx_obj_8_cdec_sa_BitSet { + PyObject_HEAD + struct __pyx_t_8_cdec_sa__BitSet *b; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":9 + * from libc.string cimport memset, strcpy, strlen + * + * cdef class DataArray: # <<<<<<<<<<<<<< + * cdef word2id + * cdef id2word + */ +struct __pyx_obj_8_cdec_sa_DataArray { + PyObject_HEAD + struct __pyx_vtabstruct_8_cdec_sa_DataArray *__pyx_vtab; + PyObject *word2id; + PyObject *id2word; + struct __pyx_obj_8_cdec_sa_IntList *data; + struct __pyx_obj_8_cdec_sa_IntList *sent_id; + struct __pyx_obj_8_cdec_sa_IntList *sent_index; + int use_sent_id; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":18 + * cdef int EPSILON = sym_fromstring('*EPS*', True) + * + * cdef class TrieNode: # <<<<<<<<<<<<<< + * cdef public children + * + */ +struct __pyx_obj_8_cdec_sa_TrieNode { + PyObject_HEAD + PyObject *children; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":340 + * + * + * cdef class VEBIterator: # <<<<<<<<<<<<<< + * cdef _VEB* v + * cdef int next_val + */ +struct __pyx_obj_8_cdec_sa_VEBIterator { + PyObject_HEAD + struct __pyx_t_8_cdec_sa__VEB *v; + int next_val; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":100 + * + * + * cdef class BitSetIterator: # <<<<<<<<<<<<<< + * cdef _BitSet* b + * cdef int next_val + */ +struct __pyx_obj_8_cdec_sa_BitSetIterator { + PyObject_HEAD + struct __pyx_t_8_cdec_sa__BitSet *b; + int next_val; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":4 + * from libc.string cimport strsep, strcpy, strlen + * + * cdef class Phrase: # <<<<<<<<<<<<<< + * cdef int *syms + * cdef int n, *varpos, n_vars + */ +struct __pyx_obj_8_cdec_sa_Phrase { + PyObject_HEAD + struct __pyx_vtabstruct_8_cdec_sa_Phrase *__pyx_vtab; + int *syms; + int n; + int *varpos; + int n_vars; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":9 + * from libc.string cimport memset, memcpy + * + * cdef class IntList: # <<<<<<<<<<<<<< + * cdef int size + * cdef int increment + */ +struct __pyx_obj_8_cdec_sa_IntList { + PyObject_HEAD + struct __pyx_vtabstruct_8_cdec_sa_IntList *__pyx_vtab; + int size; + int increment; + int len; + int *arr; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":24 + * self.children = {} + * + * cdef class ExtendedTrieNode(TrieNode): # <<<<<<<<<<<<<< + * cdef public phrase + * cdef public phrase_location + */ +struct __pyx_obj_8_cdec_sa_ExtendedTrieNode { + struct __pyx_obj_8_cdec_sa_TrieNode __pyx_base; + PyObject *phrase; + PyObject *phrase_location; + PyObject *suffix_link; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":56 + * # in the suffix array; if discontiguous, it is the set of + * # actual locations (packed into an array) + * cdef class PhraseLocation: # <<<<<<<<<<<<<< + * cdef int sa_low + * cdef int sa_high + */ +struct __pyx_obj_8_cdec_sa_PhraseLocation { + PyObject_HEAD + struct __pyx_vtabstruct_8_cdec_sa_PhraseLocation *__pyx_vtab; + int sa_low; + int sa_high; + int arr_low; + int arr_high; + struct __pyx_obj_8_cdec_sa_IntList *arr; + int num_subpatterns; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":159 + * return start + * + * cdef class Rule: # <<<<<<<<<<<<<< + * cdef public int lhs + * cdef readonly Phrase f, e + */ +struct __pyx_obj_8_cdec_sa_Rule { + PyObject_HEAD + int lhs; + struct __pyx_obj_8_cdec_sa_Phrase *f; + struct __pyx_obj_8_cdec_sa_Phrase *e; + float *cscores; + int n_scores; + PyObject *word_alignments; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":5 + * as k most frequent n-grams""" + * + * cdef class LCP: # <<<<<<<<<<<<<< + * cdef SuffixArray sa + * cdef IntList lcp + */ +struct __pyx_obj_8_cdec_sa_LCP { + PyObject_HEAD + struct __pyx_obj_8_cdec_sa_SuffixArray *sa; + struct __pyx_obj_8_cdec_sa_IntList *lcp; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":201 + * + * + * cdef class HieroCachingRuleFactory: # <<<<<<<<<<<<<< + * '''This RuleFactory implements a caching + * method using TrieTable, which makes phrase + */ +struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory { + PyObject_HEAD + struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *__pyx_vtab; + struct __pyx_obj_8_cdec_sa_TrieTable *rules; + struct __pyx_obj_8_cdec_sa_Sampler *sampler; + int max_chunks; + int max_target_chunks; + int max_length; + int max_target_length; + int max_nonterminals; + int max_initial_size; + int train_max_initial_size; + int min_gap_size; + int train_min_gap_size; + int category; + PyObject *precomputed_index; + PyObject *precomputed_collocations; + PyObject *precompute_file; + PyObject *max_rank; + int precompute_rank; + int precompute_secondary_rank; + int use_baeza_yates; + int use_index; + int use_collocations; + float by_slack_factor; + PyObject *prev_norm_prefix; + float extract_time; + struct __pyx_obj_8_cdec_sa_SuffixArray *fsa; + struct __pyx_obj_8_cdec_sa_DataArray *fda; + struct __pyx_obj_8_cdec_sa_DataArray *eda; + struct __pyx_obj_8_cdec_sa_Alignment *alignment; + struct __pyx_obj_8_cdec_sa_IntList *eid2symid; + struct __pyx_obj_8_cdec_sa_IntList *fid2symid; + int tight_phrases; + int require_aligned_terminal; + int require_aligned_chunks; + struct __pyx_obj_8_cdec_sa_IntList *findexes; + struct __pyx_obj_8_cdec_sa_IntList *findexes1; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":36 + * logger.info("LCP array completed") + * + * def compute_stats(self, int max_n): # <<<<<<<<<<<<<< + * """Note: the output of this function is not exact. In + * particular, the frequency associated with each word is + */ +struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats { + PyObject_HEAD + int __pyx_v_N; + int __pyx_v_freq; + int __pyx_v_h; + int __pyx_v_i; + int __pyx_v_ii; + int __pyx_v_iii; + int __pyx_v_j; + int __pyx_v_k; + int __pyx_v_max_n; + int __pyx_v_n; + PyObject *__pyx_v_ngram; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_ngram_start; + PyObject *__pyx_v_ngram_starts; + int __pyx_v_rs; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_run_start; + struct __pyx_obj_8_cdec_sa_LCP *__pyx_v_self; + int __pyx_v_valid; + struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_veb; + int __pyx_t_0; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":47 + * + * + * cdef class BiLex: # <<<<<<<<<<<<<< + * cdef FloatList col1 + * cdef FloatList col2 + */ +struct __pyx_obj_8_cdec_sa_BiLex { + PyObject_HEAD + struct __pyx_vtabstruct_8_cdec_sa_BiLex *__pyx_vtab; + struct __pyx_obj_8_cdec_sa_FloatList *col1; + struct __pyx_obj_8_cdec_sa_FloatList *col2; + struct __pyx_obj_8_cdec_sa_IntList *f_index; + struct __pyx_obj_8_cdec_sa_IntList *e_index; + PyObject *id2eword; + PyObject *id2fword; + PyObject *eword2id; + PyObject *fword2id; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":6 + * from libc.stdio cimport FILE, fclose, fopen + * + * cdef class SuffixArray: # <<<<<<<<<<<<<< + * cdef DataArray darray + * cdef IntList sa + */ +struct __pyx_obj_8_cdec_sa_SuffixArray { + PyObject_HEAD + struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *__pyx_vtab; + struct __pyx_obj_8_cdec_sa_DataArray *darray; + struct __pyx_obj_8_cdec_sa_IntList *sa; + struct __pyx_obj_8_cdec_sa_IntList *ha; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":8 + * char* stringmap_word(StrMap *vocab, int i) + * + * cdef class StringMap: # <<<<<<<<<<<<<< + * cdef StrMap *vocab + * cdef char *word(self, int i) + */ +struct __pyx_obj_8_cdec_sa_StringMap { + PyObject_HEAD + struct __pyx_vtabstruct_8_cdec_sa_StringMap *__pyx_vtab; + StrMap *vocab; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":109 + * trie_node_to_map(edge.node, result, prefix, include_zeros) + * + * cdef class TrieMap: # <<<<<<<<<<<<<< + * + * cdef _Trie_Node** root + */ +struct __pyx_obj_8_cdec_sa_TrieMap { + PyObject_HEAD + struct __pyx_vtabstruct_8_cdec_sa_TrieMap *__pyx_vtab; + struct __pyx_t_8_cdec_sa__Trie_Node **root; + int V; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":7 + * cdef int INDEX_MASK = (1<SetupContext((name), __LINE__, __FILE__); \ + PyGILState_Release(__pyx_gilstate_save); \ + } else { \ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \ + } +#else + #define __Pyx_RefNannySetupContext(name, acquire_gil) \ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) +#endif + #define __Pyx_RefNannyFinishContext() \ + __Pyx_RefNanny->FinishContext(&__pyx_refnanny) + #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) + #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) + #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) + #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) +#else + #define __Pyx_RefNannyDeclarations + #define __Pyx_RefNannySetupContext(name, acquire_gil) + #define __Pyx_RefNannyFinishContext() + #define __Pyx_INCREF(r) Py_INCREF(r) + #define __Pyx_DECREF(r) Py_DECREF(r) + #define __Pyx_GOTREF(r) + #define __Pyx_GIVEREF(r) + #define __Pyx_XINCREF(r) Py_XINCREF(r) + #define __Pyx_XDECREF(r) Py_XDECREF(r) + #define __Pyx_XGOTREF(r) + #define __Pyx_XGIVEREF(r) +#endif /* CYTHON_REFNANNY */ +#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) +#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) + +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ + +static int __Pyx_PyBytes_SingleTailmatch(PyObject* self, PyObject* arg, Py_ssize_t start, + Py_ssize_t end, int direction) +{ + const char* self_ptr = PyBytes_AS_STRING(self); + Py_ssize_t self_len = PyBytes_GET_SIZE(self); + const char* sub_ptr; + Py_ssize_t sub_len; + int retval; +#if PY_VERSION_HEX >= 0x02060000 + Py_buffer view; + view.obj = NULL; +#endif + if ( PyBytes_Check(arg) ) { + sub_ptr = PyBytes_AS_STRING(arg); + sub_len = PyBytes_GET_SIZE(arg); + } +#if PY_MAJOR_VERSION < 3 + else if ( PyUnicode_Check(arg) ) { + return PyUnicode_Tailmatch(self, arg, start, end, direction); + } +#endif + else { +#if PY_VERSION_HEX < 0x02060000 + if (unlikely(PyObject_AsCharBuffer(arg, &sub_ptr, &sub_len))) + return -1; +#else + if (unlikely(PyObject_GetBuffer(self, &view, PyBUF_SIMPLE) == -1)) + return -1; + sub_ptr = (const char*) view.buf; + sub_len = view.len; +#endif + } + if (end > self_len) + end = self_len; + else if (end < 0) + end += self_len; + if (end < 0) + end = 0; + if (start < 0) + start += self_len; + if (start < 0) + start = 0; + if (direction > 0) { + if (end-sub_len > start) + start = end - sub_len; + } + if (start + sub_len <= end) + retval = !memcmp(self_ptr+start, sub_ptr, sub_len); + else + retval = 0; +#if PY_VERSION_HEX >= 0x02060000 + if (view.obj) + PyBuffer_Release(&view); +#endif + return retval; +} +static int __Pyx_PyBytes_Tailmatch(PyObject* self, PyObject* substr, Py_ssize_t start, + Py_ssize_t end, int direction) +{ + if (unlikely(PyTuple_Check(substr))) { + int result; + Py_ssize_t i; + for (i = 0; i < PyTuple_GET_SIZE(substr); i++) { + result = __Pyx_PyBytes_SingleTailmatch(self, PyTuple_GET_ITEM(substr, i), + start, end, direction); + if (result) { + return result; + } + } + return 0; + } + return __Pyx_PyBytes_SingleTailmatch(self, substr, start, end, direction); +} + +static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/ + +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ + PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \ + const char* function_name); /*proto*/ + +static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ + +static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ +static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ + +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/ + +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ + +static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); /*proto*/ + +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { + PyObject *r; + if (!j) return NULL; + r = PyObject_GetItem(o, j); + Py_DECREF(j); + return r; +} +#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ + __Pyx_GetItemInt_List_Fast(o, i) : \ + __Pyx_GetItemInt_Generic(o, to_py_func(i))) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) { + if (likely(o != Py_None)) { + if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { + PyObject *r = PyList_GET_ITEM(o, i); + Py_INCREF(r); + return r; + } + else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) { + PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i); + Py_INCREF(r); + return r; + } + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} +#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ + __Pyx_GetItemInt_Tuple_Fast(o, i) : \ + __Pyx_GetItemInt_Generic(o, to_py_func(i))) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) { + if (likely(o != Py_None)) { + if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, i); + Py_INCREF(r); + return r; + } + else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) { + PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i); + Py_INCREF(r); + return r; + } + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} +#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ + __Pyx_GetItemInt_Fast(o, i) : \ + __Pyx_GetItemInt_Generic(o, to_py_func(i))) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) { + if (PyList_CheckExact(o)) { + Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); + if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) { + PyObject *r = PyList_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } + else if (PyTuple_CheckExact(o)) { + Py_ssize_t n = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); + if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } + else if (likely(i >= 0)) { + PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; + if (likely(m && m->sq_item)) { + return m->sq_item(o, i); + } + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} + +static CYTHON_INLINE int __Pyx_NegateNonNeg(int b) { + return unlikely(b < 0) ? b : !b; +} +static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) { + return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b); +} + +static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) { + if (likely(PyList_CheckExact(L))) { + if (PyList_Append(L, x) < 0) return NULL; + Py_INCREF(Py_None); + return Py_None; /* this is just to have an accurate signature */ + } + else { + PyObject *r, *m; + m = __Pyx_GetAttrString(L, "append"); + if (!m) return NULL; + r = PyObject_CallFunctionObjArgs(m, x, NULL); + Py_DECREF(m); + return r; + } +} + +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ + +static CYTHON_INLINE long __Pyx_div_long(long, long); /* proto */ + +static CYTHON_INLINE long __Pyx_mod_long(long, long); /* proto */ + +static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); + +static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); + +static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/ + +#define __Pyx_SetItemInt(o, i, v, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ + __Pyx_SetItemInt_Fast(o, i, v) : \ + __Pyx_SetItemInt_Generic(o, to_py_func(i), v)) +static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) { + int r; + if (!j) return -1; + r = PyObject_SetItem(o, j, v); + Py_DECREF(j); + return r; +} +static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v) { + if (PyList_CheckExact(o)) { + Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); + if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) { + PyObject* old = PyList_GET_ITEM(o, n); + Py_INCREF(v); + PyList_SET_ITEM(o, n, v); + Py_DECREF(old); + return 1; + } + } + else if (likely(i >= 0)) { + PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; + if (likely(m && m->sq_ass_item)) { + return m->sq_ass_item(o, i, v); + } + } + return __Pyx_SetItemInt_Generic(o, PyInt_FromSsize_t(i), v); +} + +static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */ +#define __Pyx_PyObject_AsDouble(obj) \ +((likely(PyFloat_CheckExact(obj))) ? \ + PyFloat_AS_DOUBLE(obj) : __Pyx__PyObject_AsDouble(obj)) + +static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname); + +static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, + const char *name, int exact); /*proto*/ + +#if PY_VERSION_HEX < 0x02050000 +#ifndef PyAnySet_CheckExact +#define PyAnySet_CheckExact(ob) \ + ((ob)->ob_type == &PySet_Type || \ + (ob)->ob_type == &PyFrozenSet_Type) +#define PySet_New(iterable) \ + PyObject_CallFunctionObjArgs((PyObject *)&PySet_Type, (iterable), NULL) +#define Pyx_PyFrozenSet_New(iterable) \ + PyObject_CallFunctionObjArgs((PyObject *)&PyFrozenSet_Type, (iterable), NULL) +#define PySet_Size(anyset) \ + PyObject_Size((anyset)) +#define PySet_Contains(anyset, key) \ + PySequence_Contains((anyset), (key)) +#define PySet_Pop(set) \ + PyObject_CallMethod(set, (char *)"pop", NULL) +static CYTHON_INLINE int PySet_Clear(PyObject *set) { + PyObject *ret = PyObject_CallMethod(set, (char *)"clear", NULL); + if (!ret) return -1; + Py_DECREF(ret); return 0; +} +static CYTHON_INLINE int PySet_Discard(PyObject *set, PyObject *key) { + PyObject *ret = PyObject_CallMethod(set, (char *)"discard", (char *)"O", key); + if (!ret) return -1; + Py_DECREF(ret); return 0; +} +static CYTHON_INLINE int PySet_Add(PyObject *set, PyObject *key) { + PyObject *ret = PyObject_CallMethod(set, (char *)"add", (char *)"O", key); + if (!ret) return -1; + Py_DECREF(ret); return 0; +} +#endif /* PyAnySet_CheckExact (<= Py2.4) */ +#endif /* < Py2.5 */ + +static CYTHON_INLINE void __Pyx_RaiseNoneIndexingError(void); + +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { + PyObject *value; + if (unlikely(d == Py_None)) { + __Pyx_RaiseNoneIndexingError(); + return NULL; + } + value = PyDict_GetItemWithError(d, key); + if (unlikely(!value)) { + if (!PyErr_Occurred()) + PyErr_SetObject(PyExc_KeyError, key); + return NULL; + } + Py_INCREF(value); + return value; +} +#else + #define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key) +#endif + +static CYTHON_INLINE int __Pyx_div_int(int, int); /* proto */ + +#define UNARY_NEG_WOULD_OVERFLOW(x) (((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x))) + +static CYTHON_INLINE PyObject* __Pyx_PyObject_Pop(PyObject* L) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02040000 + if (likely(PyList_CheckExact(L)) + && likely(PyList_GET_SIZE(L) > (((PyListObject*)L)->allocated >> 1))) { + Py_SIZE(L) -= 1; + return PyList_GET_ITEM(L, PyList_GET_SIZE(L)); + } +#if PY_VERSION_HEX >= 0x02050000 + else if (Py_TYPE(L) == (&PySet_Type)) { + return PySet_Pop(L); + } +#endif +#endif + return PyObject_CallMethod(L, (char*)"pop", NULL); +} + +static PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value) { + PyObject* value; +#if PY_MAJOR_VERSION >= 3 + value = PyDict_GetItemWithError(d, key); + if (unlikely(!value)) { + if (unlikely(PyErr_Occurred())) + return NULL; + if (unlikely(PyDict_SetItem(d, key, default_value) == -1)) + return NULL; + value = default_value; + } + Py_INCREF(value); +#else + if (PyString_CheckExact(key) || PyUnicode_CheckExact(key) || PyInt_CheckExact(key)) { + value = PyDict_GetItem(d, key); + if (unlikely(!value)) { + if (unlikely(PyDict_SetItem(d, key, default_value) == -1)) + return NULL; + value = default_value; + } + Py_INCREF(value); + } else { + PyObject *m; + m = __Pyx_GetAttrString(d, "setdefault"); + if (!m) return NULL; + value = PyObject_CallFunctionObjArgs(m, key, default_value, NULL); + Py_DECREF(m); + } +#endif + return value; +} + +static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ +static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ + +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/ + +static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); + +static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); + +static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); + +static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); + +static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); + +static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); + +static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); + +static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); + +static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); + +static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); + +static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); + +static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); + +static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); + +static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); + +static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); + +static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); + +static void __Pyx_WriteUnraisable(const char *name, int clineno, + int lineno, const char *filename); /*proto*/ + +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ + +#define __Pyx_Generator_USED +#include +typedef PyObject *(*__pyx_generator_body_t)(PyObject *, PyObject *); +typedef struct { + PyObject_HEAD + __pyx_generator_body_t body; + PyObject *closure; + int is_running; + int resume_label; + PyObject *exc_type; + PyObject *exc_value; + PyObject *exc_traceback; + PyObject *gi_weakreflist; + PyObject *classobj; +} __pyx_GeneratorObject; +static __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body, + PyObject *closure); +static int __pyx_Generator_init(void); + +static int __Pyx_check_binary_version(void); + +static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ + +typedef struct { + int code_line; + PyCodeObject* code_object; +} __Pyx_CodeObjectCacheEntry; +struct __Pyx_CodeObjectCache { + int count; + int max_count; + __Pyx_CodeObjectCacheEntry* entries; +}; +static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); +static PyCodeObject *__pyx_find_code_object(int code_line); +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); + +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename); /*proto*/ + +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ + + +/* Module declarations from 'libc.stdio' */ + +/* Module declarations from 'libc.stdlib' */ + +/* Module declarations from 'libc.string' */ + +/* Module declarations from 'libc.math' */ + +/* Module declarations from '_cdec_sa' */ +static PyTypeObject *__pyx_ptype_8_cdec_sa_FloatList = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_IntList = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_StringMap = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_DataArray = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_Alignment = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_BiLex = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_BitSetIterator = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_BitSet = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_VEBIterator = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_VEB = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_LCP = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_Alphabet = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_Phrase = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_Rule = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_TrieMap = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_Precomputation = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_SuffixArray = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_TrieNode = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_ExtendedTrieNode = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_TrieTable = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_PhraseLocation = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_Sampler = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa_HieroCachingRuleFactory = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa___pyx_scope_struct__compute_stats = 0; +static PyTypeObject *__pyx_ptype_8_cdec_sa___pyx_scope_struct_1_input = 0; +static int __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE; +static int __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS; +static int __pyx_v_8_cdec_sa_LOWER_MASK[32]; +static int __pyx_v_8_cdec_sa_INDEX_SHIFT; +static int __pyx_v_8_cdec_sa_INDEX_MASK; +static struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_8_cdec_sa_ALPHABET = 0; +static int __pyx_v_8_cdec_sa_PRECOMPUTE; +static int __pyx_v_8_cdec_sa_MERGE; +static int __pyx_v_8_cdec_sa_BAEZA_YATES; +static int __pyx_v_8_cdec_sa_EPSILON; +static float __pyx_f_8_cdec_sa_monitor_cpu(void); /*proto*/ +static struct __pyx_t_8_cdec_sa__node *__pyx_f_8_cdec_sa_new_node(int); /*proto*/ +static PyObject *__pyx_f_8_cdec_sa_del_node(struct __pyx_t_8_cdec_sa__node *); /*proto*/ +static int *__pyx_f_8_cdec_sa_get_val(struct __pyx_t_8_cdec_sa__node *, int); /*proto*/ +static void __pyx_f_8_cdec_sa__init_lower_mask(void); /*proto*/ +static struct __pyx_t_8_cdec_sa__BitSet *__pyx_f_8_cdec_sa_new_BitSet(void); /*proto*/ +static int __pyx_f_8_cdec_sa_bitset_findsucc(struct __pyx_t_8_cdec_sa__BitSet *, int); /*proto*/ +static int __pyx_f_8_cdec_sa_bitset_insert(struct __pyx_t_8_cdec_sa__BitSet *, int); /*proto*/ +static int __pyx_f_8_cdec_sa_bitset_contains(struct __pyx_t_8_cdec_sa__BitSet *, int); /*proto*/ +static PyObject *__pyx_f_8_cdec_sa_dec2bin(long); /*proto*/ +static struct __pyx_t_8_cdec_sa__VEB *__pyx_f_8_cdec_sa_new_VEB(int); /*proto*/ +static int __pyx_f_8_cdec_sa_VEB_insert(struct __pyx_t_8_cdec_sa__VEB *, int); /*proto*/ +static PyObject *__pyx_f_8_cdec_sa_del_VEB(struct __pyx_t_8_cdec_sa__VEB *); /*proto*/ +static int __pyx_f_8_cdec_sa_VEB_findsucc(struct __pyx_t_8_cdec_sa__VEB *, int); /*proto*/ +static int __pyx_f_8_cdec_sa_VEB_contains(struct __pyx_t_8_cdec_sa__VEB *, int); /*proto*/ +static int __pyx_f_8_cdec_sa_sym_setindex(int, int); /*proto*/ +static struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_f_8_cdec_sa_new_trie_node(void); /*proto*/ +static struct __pyx_t_8_cdec_sa__Trie_Edge *__pyx_f_8_cdec_sa_new_trie_edge(int); /*proto*/ +static PyObject *__pyx_f_8_cdec_sa_free_trie_node(struct __pyx_t_8_cdec_sa__Trie_Node *); /*proto*/ +static PyObject *__pyx_f_8_cdec_sa_free_trie_edge(struct __pyx_t_8_cdec_sa__Trie_Edge *); /*proto*/ +static struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_f_8_cdec_sa_trie_find(struct __pyx_t_8_cdec_sa__Trie_Node *, int); /*proto*/ +static PyObject *__pyx_f_8_cdec_sa_trie_node_data_append(struct __pyx_t_8_cdec_sa__Trie_Node *, int); /*proto*/ +static struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_f_8_cdec_sa_trie_insert(struct __pyx_t_8_cdec_sa__Trie_Node *, int); /*proto*/ +static PyObject *__pyx_f_8_cdec_sa_trie_node_to_map(struct __pyx_t_8_cdec_sa__Trie_Node *, PyObject *, PyObject *, int); /*proto*/ +static PyObject *__pyx_f_8_cdec_sa_trie_edge_to_map(struct __pyx_t_8_cdec_sa__Trie_Edge *, PyObject *, PyObject *, int); /*proto*/ +static void __pyx_f_8_cdec_sa_assign_matching(struct __pyx_t_8_cdec_sa_Matching *, int *, int, int, int *); /*proto*/ +static int *__pyx_f_8_cdec_sa_append_combined_matching(int *, struct __pyx_t_8_cdec_sa_Matching *, struct __pyx_t_8_cdec_sa_Matching *, int, int, int *); /*proto*/ +static int *__pyx_f_8_cdec_sa_extend_arr(int *, int *, int *, int); /*proto*/ +static int __pyx_f_8_cdec_sa_median(int, int, int); /*proto*/ +static void __pyx_f_8_cdec_sa_find_comparable_matchings(int, int, int *, int, int, int *, int *); /*proto*/ +#define __Pyx_MODULE_NAME "_cdec_sa" +int __pyx_module_is_main__cdec_sa = 0; + +/* Implementation of '_cdec_sa' */ +static PyObject *__pyx_builtin_open; +static PyObject *__pyx_builtin_IndexError; +static PyObject *__pyx_builtin_range; +static PyObject *__pyx_builtin_TypeError; +static PyObject *__pyx_builtin_enumerate; +static PyObject *__pyx_builtin_map; +static PyObject *__pyx_builtin_Exception; +static PyObject *__pyx_builtin_zip; +static PyObject *__pyx_builtin_StopIteration; +static PyObject *__pyx_builtin_cmp; +static PyObject *__pyx_builtin_ValueError; +static PyObject *__pyx_builtin_sorted; +static PyObject *__pyx_pf_8_cdec_sa_gzip_or_text(CYTHON_UNUSED PyObject *__pyx_self, char *__pyx_v_filename); /* proto */ +static int __pyx_pf_8_cdec_sa_9FloatList___cinit__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, int __pyx_v_size, int __pyx_v_increment, int __pyx_v_initial_len); /* proto */ +static void __pyx_pf_8_cdec_sa_9FloatList_2__dealloc__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9FloatList_4__getitem__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static int __pyx_pf_8_cdec_sa_9FloatList_6__setitem__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val); /* proto */ +static Py_ssize_t __pyx_pf_8_cdec_sa_9FloatList_8__len__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9FloatList_10append(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, float __pyx_v_val); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9FloatList_12write(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9FloatList_14read(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static int __pyx_pf_8_cdec_sa_7IntList___cinit__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, int __pyx_v_size, int __pyx_v_increment, int __pyx_v_initial_len); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_7IntList_2__str__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_7IntList_4index(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_val); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_7IntList_6partition(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_end); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_7IntList_8_doquicksort(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_end); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_7IntList_10sort(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_7IntList_12reset(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self); /* proto */ +static void __pyx_pf_8_cdec_sa_7IntList_14__dealloc__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_7IntList_16__getitem__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_index); /* proto */ +static int __pyx_pf_8_cdec_sa_7IntList_18__setitem__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val); /* proto */ +static Py_ssize_t __pyx_pf_8_cdec_sa_7IntList_20__len__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_7IntList_22getSize(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_7IntList_24append(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, int __pyx_v_val); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_7IntList_26extend(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_7IntList_28write(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_7IntList_30read(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static int __pyx_pf_8_cdec_sa_9StringMap___cinit__(struct __pyx_obj_8_cdec_sa_StringMap *__pyx_v_self); /* proto */ +static void __pyx_pf_8_cdec_sa_9StringMap_2__dealloc__(struct __pyx_obj_8_cdec_sa_StringMap *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_9DataArray___cinit__(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text, int __pyx_v_use_sent_id); /* proto */ +static Py_ssize_t __pyx_pf_8_cdec_sa_9DataArray_2__len__(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_4getSentId(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_6getSent(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_8getSentPos(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_loc); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_10get_id(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_word); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_12get_word(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_id); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_14write_text(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_16read_text(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_18read_binary(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_20write_binary(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_22write_enhanced_handle(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_f); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_24write_enhanced(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9Alignment_unlink(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_link); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9Alignment_2get_sent_links(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, int __pyx_v_sent_id); /* proto */ +static int __pyx_pf_8_cdec_sa_9Alignment_4__cinit__(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9Alignment_6read_text(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9Alignment_8read_binary(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9Alignment_10write_text(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9Alignment_12write_binary(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9Alignment_14write_enhanced(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9Alignment_16alignment(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static int __pyx_pf_8_cdec_sa_5BiLex___cinit__(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_from_text, PyObject *__pyx_v_from_data, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_earray, PyObject *__pyx_v_fsarray, PyObject *__pyx_v_alignment); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_5BiLex_2write_binary(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_5BiLex_4read_binary(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_5BiLex_6get_e_id(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_eword); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_5BiLex_8get_f_id(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_fword); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_5BiLex_10read_text(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_5BiLex_12write_enhanced(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_5BiLex_14get_score(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_fword, PyObject *__pyx_v_eword, PyObject *__pyx_v_col); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_5BiLex_16write_text(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_14BitSetIterator___next__(struct __pyx_obj_8_cdec_sa_BitSetIterator *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_6BitSet___cinit__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self); /* proto */ +static void __pyx_pf_8_cdec_sa_6BitSet_2__dealloc__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_6BitSet_4__iter__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_6BitSet_6insert(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_6BitSet_8findsucc(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_6BitSet_10__str__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_6BitSet_12min(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_6BitSet_14max(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self); /* proto */ +static Py_ssize_t __pyx_pf_8_cdec_sa_6BitSet_16__len__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_6BitSet_18__contains__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_11VEBIterator___next__(struct __pyx_obj_8_cdec_sa_VEBIterator *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_3VEB___cinit__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, int __pyx_v_size); /* proto */ +static void __pyx_pf_8_cdec_sa_3VEB_2__dealloc__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_3VEB_4__iter__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_3VEB_6insert(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_3VEB_8findsucc(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static Py_ssize_t __pyx_pf_8_cdec_sa_3VEB_10__len__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_3VEB_12__contains__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static int __pyx_pf_8_cdec_sa_3LCP___cinit__(struct __pyx_obj_8_cdec_sa_LCP *__pyx_v_self, struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_sa); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_3LCP_2compute_stats(struct __pyx_obj_8_cdec_sa_LCP *__pyx_v_self, int __pyx_v_max_n); /* proto */ +static int __pyx_pf_8_cdec_sa_8Alphabet___cinit__(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self); /* proto */ +static void __pyx_pf_8_cdec_sa_8Alphabet_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_8Alphabet_9terminals___get__(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_8Alphabet_12nonterminals___get__(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_2sym_tostring(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_sym); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_4sym_fromstring(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_string, int __pyx_v_terminal); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_6sym_isvar(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_sym); /* proto */ +static int __pyx_pf_8_cdec_sa_6Phrase___cinit__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_words); /* proto */ +static void __pyx_pf_8_cdec_sa_6Phrase_2__dealloc__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_4__str__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_6handle(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_8strhandle(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_10arity(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_12getvarpos(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_14getvar(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_16clen(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_k); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_18getchunk(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_ci); /* proto */ +#if PY_MAJOR_VERSION < 3 +static int __pyx_pf_8_cdec_sa_6Phrase_20__cmp__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_other); /* proto */ +#endif +static Py_hash_t __pyx_pf_8_cdec_sa_6Phrase_22__hash__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self); /* proto */ +static Py_ssize_t __pyx_pf_8_cdec_sa_6Phrase_24__len__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_26__getitem__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_28__iter__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_30subst(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_children); /* proto */ +static int __pyx_pf_8_cdec_sa_4Rule___cinit__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, int __pyx_v_lhs, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_f, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_e, PyObject *__pyx_v_scores, PyObject *__pyx_v_word_alignments); /* proto */ +static void __pyx_pf_8_cdec_sa_4Rule_2__dealloc__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ +static Py_hash_t __pyx_pf_8_cdec_sa_4Rule_4__hash__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ +#if PY_MAJOR_VERSION < 3 +static int __pyx_pf_8_cdec_sa_4Rule_6__cmp__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_other); /* proto */ +#endif +static PyObject *__pyx_pf_8_cdec_sa_4Rule_8__iadd__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_4Rule_10fmerge(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_f); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_4Rule_12arity(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_4Rule_14__str__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_4Rule_6scores___get__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_4Rule_6scores_2__set__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, PyObject *__pyx_v_s); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_4Rule_3lhs___get__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_4Rule_3lhs_2__set__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_4Rule_1f___get__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_4Rule_1e___get__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_4Rule_15word_alignments___get__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_4Rule_15word_alignments_2__set__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_8_cdec_sa_4Rule_15word_alignments_4__del__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_7TrieMap___cinit__(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, int __pyx_v_alphabet_size); /* proto */ +static void __pyx_pf_8_cdec_sa_7TrieMap_2__dealloc__(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_7TrieMap_4insert(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, PyObject *__pyx_v_pattern); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_7TrieMap_6contains(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, PyObject *__pyx_v_pattern); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_7TrieMap_8toMap(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, PyObject *__pyx_v_flag); /* proto */ +static int __pyx_pf_8_cdec_sa_14Precomputation___cinit__(struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, PyObject *__pyx_v_fsarray, PyObject *__pyx_v_from_stats, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_precompute_rank, PyObject *__pyx_v_precompute_secondary_rank, PyObject *__pyx_v_max_length, PyObject *__pyx_v_max_nonterminals, PyObject *__pyx_v_train_max_initial_size, PyObject *__pyx_v_train_min_gap_size); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_14Precomputation_2read_binary(struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_14Precomputation_4write_binary(struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_14Precomputation_6precompute(struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, PyObject *__pyx_v_stats, struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_sarray); /* proto */ +static int __pyx_pf_8_cdec_sa_11SuffixArray___cinit__(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_2__getitem__(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_4getSentId(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_6getSent(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_8getSentPos(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_loc); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_10read_text(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_12q3sort(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, int __pyx_v_i, int __pyx_v_j, int __pyx_v_h, struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_isa, PyObject *__pyx_v_pad); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_14write_text(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_16read_binary(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_18write_binary(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_20write_enhanced(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_22lookup(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_word, int __pyx_v_offset, int __pyx_v_low, int __pyx_v_high); /* proto */ +static int __pyx_pf_8_cdec_sa_8TrieNode___cinit__(struct __pyx_obj_8_cdec_sa_TrieNode *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_8TrieNode_8children___get__(struct __pyx_obj_8_cdec_sa_TrieNode *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_8TrieNode_8children_2__set__(struct __pyx_obj_8_cdec_sa_TrieNode *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_8_cdec_sa_8TrieNode_8children_4__del__(struct __pyx_obj_8_cdec_sa_TrieNode *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode___cinit__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_phrase, PyObject *__pyx_v_phrase_location, PyObject *__pyx_v_suffix_link); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_16ExtendedTrieNode_6phrase___get__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_6phrase_2__set__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_6phrase_4__del__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_16ExtendedTrieNode_15phrase_location___get__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_15phrase_location_2__set__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_15phrase_location_4__del__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_16ExtendedTrieNode_11suffix_link___get__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_11suffix_link_2__set__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_11suffix_link_4__del__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_9TrieTable___cinit__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_extended); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9TrieTable_8extended___get__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_9TrieTable_8extended_2__set__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9TrieTable_5count___get__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_9TrieTable_5count_2__set__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_9TrieTable_4root___get__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_9TrieTable_4root_2__set__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_8_cdec_sa_9TrieTable_4root_4__del__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self); /* proto */ +static int __pyx_pf_8_cdec_sa_14PhraseLocation___cinit__(struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_self, int __pyx_v_sa_low, int __pyx_v_sa_high, int __pyx_v_arr_low, int __pyx_v_arr_high, PyObject *__pyx_v_arr, int __pyx_v_num_subpatterns); /* proto */ +static int __pyx_pf_8_cdec_sa_7Sampler___cinit__(struct __pyx_obj_8_cdec_sa_Sampler *__pyx_v_self, int __pyx_v_sample_size, struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_fsarray); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_7Sampler_2sample(struct __pyx_obj_8_cdec_sa_Sampler *__pyx_v_self, struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_phrase_location); /* proto */ +static int __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory___cinit__(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_alignment, float __pyx_v_by_slack_factor, char *__pyx_v_category, PyObject *__pyx_v_max_chunks, unsigned int __pyx_v_max_initial_size, unsigned int __pyx_v_max_length, unsigned int __pyx_v_max_nonterminals, PyObject *__pyx_v_max_target_chunks, PyObject *__pyx_v_max_target_length, unsigned int __pyx_v_min_gap_size, PyObject *__pyx_v_precompute_file, unsigned int __pyx_v_precompute_secondary_rank, unsigned int __pyx_v_precompute_rank, int __pyx_v_require_aligned_terminal, int __pyx_v_require_aligned_chunks, unsigned int __pyx_v_train_max_initial_size, unsigned int __pyx_v_train_min_gap_size, int __pyx_v_tight_phrases, int __pyx_v_use_baeza_yates, int __pyx_v_use_collocations, int __pyx_v_use_index); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_2configure(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_fsarray, struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_edarray, struct __pyx_obj_8_cdec_sa_Sampler *__pyx_v_sampler); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_4pattern2phrase(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_pattern); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_6pattern2phrase_plus(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_pattern); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_8precompute(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_10get_precomputed_collocation(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_phrase); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_12advance(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_frontier, PyObject *__pyx_v_res, PyObject *__pyx_v_fwords); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_14get_all_nodes_isteps_away(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_skip, PyObject *__pyx_v_i, PyObject *__pyx_v_spanlen, PyObject *__pyx_v_pathlen, PyObject *__pyx_v_fwords, PyObject *__pyx_v_next_states, PyObject *__pyx_v_reachable_buffer); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_16reachable(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_ifrom, PyObject *__pyx_v_dist); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_18shortest(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_ifrom, PyObject *__pyx_v_ito); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_20get_next_states(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v__columns, PyObject *__pyx_v_curr_idx, PyObject *__pyx_v_min_dist); /* proto */ +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_22input(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_models); /* proto */ +static char __pyx_k_1[] = ".gz"; +static char __pyx_k_2[] = "Requested index %d of %d-length FloatList"; +static char __pyx_k_3[] = "IntList["; +static char __pyx_k_4[] = ","; +static char __pyx_k_5[] = "]"; +static char __pyx_k_6[] = "len="; +static char __pyx_k_7[] = "Requested index %d of %d-length IntList"; +static char __pyx_k_8[] = "Requested index %d:%d of %d-length IntList"; +static char __pyx_k_9[] = "Illegal key type %s for IntList"; +static char __pyx_k_13[] = "%s "; +static char __pyx_k_14[] = "\n"; +static char __pyx_k_18[] = "%d "; +static char __pyx_k_22[] = "%s %d "; +static char __pyx_k_24[] = "write_enhanced_handle"; +static char __pyx_k_28[] = "-"; +static char __pyx_k_32[] = "%d-%d "; +static char __pyx_k_39[] = "%d-%d out of bounds (I=%d,J=%d) in line %d\n"; +static char __pyx_k_42[] = ""; +static char __pyx_k_43[] = "Sort error in CLex"; +static char __pyx_k_45[] = " "; +static char __pyx_k_47[] = "%d %f %f "; +static char __pyx_k_49[] = "%d %s "; +static char __pyx_k_53[] = "%s %s %.6f %.6f\n"; +static char __pyx_k_55[] = " ("; +static char __pyx_k_56[] = ")"; +static char __pyx_k_57[] = "Constructing LCP array"; +static char __pyx_k_59[] = "LCP array completed"; +static char __pyx_k_61[] = "[%s,%d]"; +static char __pyx_k_62[] = "[%s]"; +static char __pyx_k_63[] = "\\"; +static char __pyx_k_64[] = " "; +static char __pyx_k_65[] = "Invalid LHS symbol: %d"; +static char __pyx_k_66[] = "%d-%d"; +static char __pyx_k_67[] = " ||| "; +static char __pyx_k_68[] = "precompute_secondary_rank"; +static char __pyx_k_69[] = "train_max_initial_size"; +static char __pyx_k_70[] = "Precomputing frequent intersections"; +static char __pyx_k_72[] = " Computing inverted indexes..."; +static char __pyx_k_74[] = " Computing collocations..."; +static char __pyx_k_76[] = " %d sentences"; +static char __pyx_k_81[] = "X "; +static char __pyx_k_82[] = "ERROR: unexpected pattern %s in set of precomputed collocations"; +static char __pyx_k_83[] = "RANK %d\tCOUNT, COST: %d %d\tCUMUL: %d, %d"; +static char __pyx_k_84[] = "Precomputed collocations for %d patterns out of %d possible (upper bound %d)"; +static char __pyx_k_85[] = "Precomputed inverted index for %d patterns "; +static char __pyx_k_86[] = "Precomputation took %f seconds"; +static char __pyx_k_87[] = " Bucket sort took %f seconds"; +static char __pyx_k_88[] = " Refining, sort depth = %d"; +static char __pyx_k_89[] = " Refinement took %f seconds"; +static char __pyx_k_90[] = " Finalizing sort..."; +static char __pyx_k_92[] = "Suffix array construction took %f seconds"; +static char __pyx_k_93[] = "Unexpected condition found in q3sort: sort from %d to %d"; +static char __pyx_k_98[] = "Sampling strategy: uniform, max sample size = %d"; +static char __pyx_k_99[] = "Sampling strategy: no sampling"; +static char __pyx_k__0[] = "0"; +static char __pyx_k__1[] = "1"; +static char __pyx_k__e[] = "e"; +static char __pyx_k__f[] = "f"; +static char __pyx_k__h[] = "h"; +static char __pyx_k__i[] = "i"; +static char __pyx_k__j[] = "j"; +static char __pyx_k__r[] = "r"; +static char __pyx_k__w[] = "w"; +static char __pyx_k_101[] = "require_aligned_terminal"; +static char __pyx_k_102[] = "require_aligned_chunks"; +static char __pyx_k_103[] = "[X]"; +static char __pyx_k_104[] = "Must specify an alignment object"; +static char __pyx_k_106[] = "Reading precomputed data from file %s... "; +static char __pyx_k_107[] = "Precomputation done with max nonterminals %d, decoder uses %d"; +static char __pyx_k_108[] = "Precomputation done with max terminals %d, decoder uses %d"; +static char __pyx_k_109[] = "Precomputation done with max initial size %d, decoder uses %d"; +static char __pyx_k_110[] = "Precomputation done with min gap size %d, decoder uses %d"; +static char __pyx_k_111[] = "Converting %d hash keys on precomputed inverted index... "; +static char __pyx_k_112[] = "Converting %d hash keys on precomputed collocations... "; +static char __pyx_k_113[] = "Processing precomputations took %f seconds"; +static char __pyx_k_114[] = "{"; + static char __pyx_k_115[] = "("; +static char __pyx_k_116[] = "}"; +static char __pyx_k_117[] = "get_precomputed_collocation"; +static char __pyx_k_118[] = "double binary"; +static char __pyx_k_119[] = "Keyword trie error"; +static char __pyx_k_121[] = "get_all_nodes_isteps_away"; +static char __pyx_k_122[] = "Total time for rule lookup, extraction, and scoring = %f seconds"; +static char __pyx_k_123[] = " Extract time = %f seconds"; +static char __pyx_k_124[] = "No aligned terminals"; +static char __pyx_k_125[] = "Unaligned chunk"; +static char __pyx_k_126[] = "Gaps are not tight phrases"; +static char __pyx_k_127[] = "Inside edges of preceding subphrase are not tight"; +static char __pyx_k_128[] = "Inside edges of following subphrase are not tight"; +static char __pyx_k_129[] = "Subphrase [%d, %d] failed integrity check"; +static char __pyx_k_130[] = "Didn't extract anything from [%d, %d] -> [%d, %d]"; +static char __pyx_k_131[] = "Unable to extract basic phrase"; +static char __pyx_k_134[] = "/Users/vchahun/Sandbox/cdec/python/src/sa/_cdec_sa.pyx"; +static char __pyx_k_135[] = "cdec.sa"; +static char __pyx_k_139[] = "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi"; +static char __pyx_k_144[] = "*EPS*"; +static char __pyx_k__gc[] = "gc"; +static char __pyx_k__sa[] = "sa"; +static char __pyx_k__arr[] = "arr"; +static char __pyx_k__cmp[] = "cmp"; +static char __pyx_k__col[] = "col"; +static char __pyx_k__end[] = "end"; +static char __pyx_k__isa[] = "isa"; +static char __pyx_k__ito[] = "ito"; +static char __pyx_k__lhs[] = "lhs"; +static char __pyx_k__low[] = "low"; +static char __pyx_k__map[] = "map"; +static char __pyx_k__pad[] = "pad"; +static char __pyx_k__res[] = "res"; +static char __pyx_k__sym[] = "sym"; +static char __pyx_k__zip[] = "zip"; +static char __pyx_k__NULL[] = "NULL"; +static char __pyx_k__dist[] = "dist"; +static char __pyx_k__gzip[] = "gzip"; +static char __pyx_k__high[] = "high"; +static char __pyx_k__info[] = "info"; +static char __pyx_k__join[] = "join"; +static char __pyx_k__open[] = "open"; +static char __pyx_k__seek[] = "seek"; +static char __pyx_k__size[] = "size"; +static char __pyx_k__skip[] = "skip"; +static char __pyx_k__stop[] = "stop"; +static char __pyx_k__warn[] = "warn"; +static char __pyx_k__word[] = "word"; +static char __pyx_k___SEP_[] = "_SEP_"; +static char __pyx_k__arity[] = "arity"; +static char __pyx_k__debug[] = "debug"; +static char __pyx_k__eword[] = "eword"; +static char __pyx_k__fword[] = "fword"; +static char __pyx_k__ifrom[] = "ifrom"; +static char __pyx_k__index[] = "index"; +static char __pyx_k__merge[] = "merge"; +static char __pyx_k__range[] = "range"; +static char __pyx_k__reset[] = "reset"; +static char __pyx_k__split[] = "split"; +static char __pyx_k__start[] = "start"; +static char __pyx_k__stats[] = "stats"; +static char __pyx_k__toMap[] = "toMap"; +static char __pyx_k__words[] = "words"; +static char __pyx_k__write[] = "write"; +static char __pyx_k__earray[] = "earray"; +static char __pyx_k__extend[] = "extend"; +static char __pyx_k__fwords[] = "fwords"; +static char __pyx_k__get_id[] = "get_id"; +static char __pyx_k__insert[] = "insert"; +static char __pyx_k__logger[] = "logger"; +static char __pyx_k__lookup[] = "lookup"; +static char __pyx_k__models[] = "models"; +static char __pyx_k__offset[] = "offset"; +static char __pyx_k__phrase[] = "phrase"; +static char __pyx_k__q3sort[] = "q3sort"; +static char __pyx_k__sa_low[] = "sa_low"; +static char __pyx_k__sample[] = "sample"; +static char __pyx_k__sarray[] = "sarray"; +static char __pyx_k__scores[] = "scores"; +static char __pyx_k__sorted[] = "sorted"; +static char __pyx_k__string[] = "string"; +static char __pyx_k__unlink[] = "unlink"; +static char __pyx_k__advance[] = "advance"; +static char __pyx_k__arr_low[] = "arr_low"; +static char __pyx_k__collect[] = "collect"; +static char __pyx_k__edarray[] = "edarray"; +static char __pyx_k__fsarray[] = "fsarray"; +static char __pyx_k__getSent[] = "getSent"; +static char __pyx_k__logging[] = "logging"; +static char __pyx_k__pathlen[] = "pathlen"; +static char __pyx_k__sa_high[] = "sa_high"; +static char __pyx_k__sampler[] = "sampler"; +static char __pyx_k__spanlen[] = "spanlen"; +static char __pyx_k__GzipFile[] = "GzipFile"; +static char __pyx_k____exit__[] = "__exit__"; +static char __pyx_k____main__[] = "__main__"; +static char __pyx_k____test__[] = "__test__"; +static char __pyx_k___cdec_sa[] = "_cdec_sa"; +static char __pyx_k___columns[] = "_columns"; +static char __pyx_k__arr_high[] = "arr_high"; +static char __pyx_k__category[] = "category"; +static char __pyx_k__children[] = "children"; +static char __pyx_k__curr_idx[] = "curr_idx"; +static char __pyx_k__extended[] = "extended"; +static char __pyx_k__filename[] = "filename"; +static char __pyx_k__frontier[] = "frontier"; +static char __pyx_k__get_e_id[] = "get_e_id"; +static char __pyx_k__get_f_id[] = "get_f_id"; +static char __pyx_k__get_word[] = "get_word"; +static char __pyx_k__getchunk[] = "getchunk"; +static char __pyx_k__min_dist[] = "min_dist"; +static char __pyx_k__resource[] = "resource"; +static char __pyx_k__ru_stime[] = "ru_stime"; +static char __pyx_k__ru_utime[] = "ru_utime"; +static char __pyx_k__shortest[] = "shortest"; +static char __pyx_k__terminal[] = "terminal"; +static char __pyx_k__Exception[] = "Exception"; +static char __pyx_k__TypeError[] = "TypeError"; +static char __pyx_k____enter__[] = "__enter__"; +static char __pyx_k__alignment[] = "alignment"; +static char __pyx_k__enumerate[] = "enumerate"; +static char __pyx_k__from_data[] = "from_data"; +static char __pyx_k__from_text[] = "from_text"; +static char __pyx_k__getLogger[] = "getLogger"; +static char __pyx_k__getSentId[] = "getSentId"; +static char __pyx_k__getrusage[] = "getrusage"; +static char __pyx_k__increment[] = "increment"; +static char __pyx_k__iteritems[] = "iteritems"; +static char __pyx_k__partition[] = "partition"; +static char __pyx_k__reachable[] = "reachable"; +static char __pyx_k__read_text[] = "read_text"; +static char __pyx_k__sym_isvar[] = "sym_isvar"; +static char __pyx_k__use_index[] = "use_index"; +static char __pyx_k__IndexError[] = "IndexError"; +static char __pyx_k__ValueError[] = "ValueError"; +static char __pyx_k__from_stats[] = "from_stats"; +static char __pyx_k__getSentPos[] = "getSentPos"; +static char __pyx_k__max_chunks[] = "max_chunks"; +static char __pyx_k__max_length[] = "max_length"; +static char __pyx_k__precompute[] = "precompute"; +static char __pyx_k__setdefault[] = "setdefault"; +static char __pyx_k__write_text[] = "write_text"; +static char __pyx_k__END_OF_FILE[] = "END_OF_FILE"; +static char __pyx_k__END_OF_LINE[] = "END_OF_LINE"; +static char __pyx_k__RUSAGE_SELF[] = "RUSAGE_SELF"; +static char __pyx_k__from_binary[] = "from_binary"; +static char __pyx_k__initial_len[] = "initial_len"; +static char __pyx_k__next_states[] = "next_states"; +static char __pyx_k__precomputed[] = "precomputed"; +static char __pyx_k__read_binary[] = "read_binary"; +static char __pyx_k__sample_size[] = "sample_size"; +static char __pyx_k__suffix_link[] = "suffix_link"; +static char __pyx_k__use_sent_id[] = "use_sent_id"; +static char __pyx_k___doquicksort[] = "_doquicksort"; +static char __pyx_k__gzip_or_text[] = "gzip_or_text"; +static char __pyx_k__min_gap_size[] = "min_gap_size"; +static char __pyx_k__sym_tostring[] = "sym_tostring"; +static char __pyx_k__StopIteration[] = "StopIteration"; +static char __pyx_k__alphabet_size[] = "alphabet_size"; +static char __pyx_k__tight_phrases[] = "tight_phrases"; +static char __pyx_k__pattern2phrase[] = "pattern2phrase"; +static char __pyx_k__sym_fromstring[] = "sym_fromstring"; +static char __pyx_k__by_slack_factor[] = "by_slack_factor"; +static char __pyx_k__get_next_states[] = "get_next_states"; +static char __pyx_k__num_subpatterns[] = "num_subpatterns"; +static char __pyx_k__phrase_location[] = "phrase_location"; +static char __pyx_k__precompute_file[] = "precompute_file"; +static char __pyx_k__precompute_rank[] = "precompute_rank"; +static char __pyx_k__use_baeza_yates[] = "use_baeza_yates"; +static char __pyx_k__word_alignments[] = "word_alignments"; +static char __pyx_k__max_initial_size[] = "max_initial_size"; +static char __pyx_k__max_nonterminals[] = "max_nonterminals"; +static char __pyx_k__reachable_buffer[] = "reachable_buffer"; +static char __pyx_k__use_collocations[] = "use_collocations"; +static char __pyx_k__max_target_chunks[] = "max_target_chunks"; +static char __pyx_k__max_target_length[] = "max_target_length"; +static char __pyx_k__train_min_gap_size[] = "train_min_gap_size"; +static char __pyx_k__pattern2phrase_plus[] = "pattern2phrase_plus"; +static PyObject *__pyx_kp_s_1; +static PyObject *__pyx_n_s_101; +static PyObject *__pyx_n_s_102; +static PyObject *__pyx_kp_s_104; +static PyObject *__pyx_kp_s_106; +static PyObject *__pyx_kp_s_107; +static PyObject *__pyx_kp_s_108; +static PyObject *__pyx_kp_s_109; +static PyObject *__pyx_kp_s_110; +static PyObject *__pyx_kp_s_111; +static PyObject *__pyx_kp_s_112; +static PyObject *__pyx_kp_s_113; +static PyObject *__pyx_kp_s_114; +static PyObject *__pyx_kp_s_115; +static PyObject *__pyx_kp_s_116; +static PyObject *__pyx_n_s_117; +static PyObject *__pyx_kp_s_118; +static PyObject *__pyx_kp_s_119; +static PyObject *__pyx_n_s_121; +static PyObject *__pyx_kp_s_122; +static PyObject *__pyx_kp_s_123; +static PyObject *__pyx_kp_s_124; +static PyObject *__pyx_kp_s_125; +static PyObject *__pyx_kp_s_126; +static PyObject *__pyx_kp_s_127; +static PyObject *__pyx_kp_s_128; +static PyObject *__pyx_kp_s_129; +static PyObject *__pyx_kp_s_13; +static PyObject *__pyx_kp_s_130; +static PyObject *__pyx_kp_s_131; +static PyObject *__pyx_kp_s_134; +static PyObject *__pyx_kp_s_135; +static PyObject *__pyx_kp_s_139; +static PyObject *__pyx_kp_s_14; +static PyObject *__pyx_kp_s_144; +static PyObject *__pyx_kp_s_18; +static PyObject *__pyx_kp_s_2; +static PyObject *__pyx_kp_s_22; +static PyObject *__pyx_n_s_24; +static PyObject *__pyx_kp_s_28; +static PyObject *__pyx_kp_s_3; +static PyObject *__pyx_kp_s_32; +static PyObject *__pyx_kp_s_39; +static PyObject *__pyx_kp_s_4; +static PyObject *__pyx_kp_s_42; +static PyObject *__pyx_kp_s_43; +static PyObject *__pyx_kp_s_45; +static PyObject *__pyx_kp_s_47; +static PyObject *__pyx_kp_s_49; +static PyObject *__pyx_kp_s_5; +static PyObject *__pyx_kp_s_53; +static PyObject *__pyx_kp_s_55; +static PyObject *__pyx_kp_s_56; +static PyObject *__pyx_kp_s_57; +static PyObject *__pyx_kp_s_59; +static PyObject *__pyx_kp_s_6; +static PyObject *__pyx_kp_s_61; +static PyObject *__pyx_kp_s_62; +static PyObject *__pyx_kp_s_63; +static PyObject *__pyx_kp_s_64; +static PyObject *__pyx_kp_s_65; +static PyObject *__pyx_kp_s_66; +static PyObject *__pyx_kp_s_67; +static PyObject *__pyx_n_s_68; +static PyObject *__pyx_n_s_69; +static PyObject *__pyx_kp_s_7; +static PyObject *__pyx_kp_s_70; +static PyObject *__pyx_kp_s_72; +static PyObject *__pyx_kp_s_74; +static PyObject *__pyx_kp_s_76; +static PyObject *__pyx_kp_s_8; +static PyObject *__pyx_kp_s_81; +static PyObject *__pyx_kp_s_82; +static PyObject *__pyx_kp_s_83; +static PyObject *__pyx_kp_s_84; +static PyObject *__pyx_kp_s_85; +static PyObject *__pyx_kp_s_86; +static PyObject *__pyx_kp_s_87; +static PyObject *__pyx_kp_s_88; +static PyObject *__pyx_kp_s_89; +static PyObject *__pyx_kp_s_9; +static PyObject *__pyx_kp_s_90; +static PyObject *__pyx_kp_s_92; +static PyObject *__pyx_kp_s_93; +static PyObject *__pyx_kp_s_98; +static PyObject *__pyx_kp_s_99; +static PyObject *__pyx_kp_s__0; +static PyObject *__pyx_kp_s__1; +static PyObject *__pyx_n_s__END_OF_FILE; +static PyObject *__pyx_n_s__END_OF_LINE; +static PyObject *__pyx_n_s__Exception; +static PyObject *__pyx_n_s__GzipFile; +static PyObject *__pyx_n_s__IndexError; +static PyObject *__pyx_n_s__NULL; +static PyObject *__pyx_n_s__RUSAGE_SELF; +static PyObject *__pyx_n_s__StopIteration; +static PyObject *__pyx_n_s__TypeError; +static PyObject *__pyx_n_s__ValueError; +static PyObject *__pyx_n_s____enter__; +static PyObject *__pyx_n_s____exit__; +static PyObject *__pyx_n_s____main__; +static PyObject *__pyx_n_s____test__; +static PyObject *__pyx_n_s___cdec_sa; +static PyObject *__pyx_n_s___columns; +static PyObject *__pyx_n_s___doquicksort; +static PyObject *__pyx_n_s__advance; +static PyObject *__pyx_n_s__alignment; +static PyObject *__pyx_n_s__alphabet_size; +static PyObject *__pyx_n_s__arity; +static PyObject *__pyx_n_s__arr; +static PyObject *__pyx_n_s__arr_high; +static PyObject *__pyx_n_s__arr_low; +static PyObject *__pyx_n_s__by_slack_factor; +static PyObject *__pyx_n_s__category; +static PyObject *__pyx_n_s__children; +static PyObject *__pyx_n_s__cmp; +static PyObject *__pyx_n_s__col; +static PyObject *__pyx_n_s__collect; +static PyObject *__pyx_n_s__curr_idx; +static PyObject *__pyx_n_s__debug; +static PyObject *__pyx_n_s__dist; +static PyObject *__pyx_n_s__e; +static PyObject *__pyx_n_s__earray; +static PyObject *__pyx_n_s__edarray; +static PyObject *__pyx_n_s__end; +static PyObject *__pyx_n_s__enumerate; +static PyObject *__pyx_n_s__eword; +static PyObject *__pyx_n_s__extend; +static PyObject *__pyx_n_s__extended; +static PyObject *__pyx_n_s__f; +static PyObject *__pyx_n_s__filename; +static PyObject *__pyx_n_s__from_binary; +static PyObject *__pyx_n_s__from_data; +static PyObject *__pyx_n_s__from_stats; +static PyObject *__pyx_n_s__from_text; +static PyObject *__pyx_n_s__frontier; +static PyObject *__pyx_n_s__fsarray; +static PyObject *__pyx_n_s__fword; +static PyObject *__pyx_n_s__fwords; +static PyObject *__pyx_n_s__gc; +static PyObject *__pyx_n_s__getLogger; +static PyObject *__pyx_n_s__getSent; +static PyObject *__pyx_n_s__getSentId; +static PyObject *__pyx_n_s__getSentPos; +static PyObject *__pyx_n_s__get_e_id; +static PyObject *__pyx_n_s__get_f_id; +static PyObject *__pyx_n_s__get_id; +static PyObject *__pyx_n_s__get_next_states; +static PyObject *__pyx_n_s__get_word; +static PyObject *__pyx_n_s__getchunk; +static PyObject *__pyx_n_s__getrusage; +static PyObject *__pyx_n_s__gzip; +static PyObject *__pyx_n_s__gzip_or_text; +static PyObject *__pyx_n_s__h; +static PyObject *__pyx_n_s__high; +static PyObject *__pyx_n_s__i; +static PyObject *__pyx_n_s__ifrom; +static PyObject *__pyx_n_s__increment; +static PyObject *__pyx_n_s__index; +static PyObject *__pyx_n_s__info; +static PyObject *__pyx_n_s__initial_len; +static PyObject *__pyx_n_s__insert; +static PyObject *__pyx_n_s__isa; +static PyObject *__pyx_n_s__iteritems; +static PyObject *__pyx_n_s__ito; +static PyObject *__pyx_n_s__j; +static PyObject *__pyx_n_s__join; +static PyObject *__pyx_n_s__lhs; +static PyObject *__pyx_n_s__logger; +static PyObject *__pyx_n_s__logging; +static PyObject *__pyx_n_s__lookup; +static PyObject *__pyx_n_s__low; +static PyObject *__pyx_n_s__map; +static PyObject *__pyx_n_s__max_chunks; +static PyObject *__pyx_n_s__max_initial_size; +static PyObject *__pyx_n_s__max_length; +static PyObject *__pyx_n_s__max_nonterminals; +static PyObject *__pyx_n_s__max_target_chunks; +static PyObject *__pyx_n_s__max_target_length; +static PyObject *__pyx_n_s__merge; +static PyObject *__pyx_n_s__min_dist; +static PyObject *__pyx_n_s__min_gap_size; +static PyObject *__pyx_n_s__models; +static PyObject *__pyx_n_s__next_states; +static PyObject *__pyx_n_s__num_subpatterns; +static PyObject *__pyx_n_s__offset; +static PyObject *__pyx_n_s__open; +static PyObject *__pyx_n_s__pad; +static PyObject *__pyx_n_s__partition; +static PyObject *__pyx_n_s__pathlen; +static PyObject *__pyx_n_s__pattern2phrase; +static PyObject *__pyx_n_s__pattern2phrase_plus; +static PyObject *__pyx_n_s__phrase; +static PyObject *__pyx_n_s__phrase_location; +static PyObject *__pyx_n_s__precompute; +static PyObject *__pyx_n_s__precompute_file; +static PyObject *__pyx_n_s__precompute_rank; +static PyObject *__pyx_n_s__precomputed; +static PyObject *__pyx_n_s__q3sort; +static PyObject *__pyx_n_s__range; +static PyObject *__pyx_n_s__reachable; +static PyObject *__pyx_n_s__reachable_buffer; +static PyObject *__pyx_n_s__read_binary; +static PyObject *__pyx_n_s__read_text; +static PyObject *__pyx_n_s__res; +static PyObject *__pyx_n_s__reset; +static PyObject *__pyx_n_s__resource; +static PyObject *__pyx_n_s__ru_stime; +static PyObject *__pyx_n_s__ru_utime; +static PyObject *__pyx_n_s__sa; +static PyObject *__pyx_n_s__sa_high; +static PyObject *__pyx_n_s__sa_low; +static PyObject *__pyx_n_s__sample; +static PyObject *__pyx_n_s__sample_size; +static PyObject *__pyx_n_s__sampler; +static PyObject *__pyx_n_s__sarray; +static PyObject *__pyx_n_s__scores; +static PyObject *__pyx_n_s__seek; +static PyObject *__pyx_n_s__setdefault; +static PyObject *__pyx_n_s__shortest; +static PyObject *__pyx_n_s__size; +static PyObject *__pyx_n_s__skip; +static PyObject *__pyx_n_s__sorted; +static PyObject *__pyx_n_s__spanlen; +static PyObject *__pyx_n_s__split; +static PyObject *__pyx_n_s__start; +static PyObject *__pyx_n_s__stats; +static PyObject *__pyx_n_s__stop; +static PyObject *__pyx_n_s__string; +static PyObject *__pyx_n_s__suffix_link; +static PyObject *__pyx_n_s__sym; +static PyObject *__pyx_n_s__sym_fromstring; +static PyObject *__pyx_n_s__sym_isvar; +static PyObject *__pyx_n_s__sym_tostring; +static PyObject *__pyx_n_s__terminal; +static PyObject *__pyx_n_s__tight_phrases; +static PyObject *__pyx_n_s__toMap; +static PyObject *__pyx_n_s__train_min_gap_size; +static PyObject *__pyx_n_s__unlink; +static PyObject *__pyx_n_s__use_baeza_yates; +static PyObject *__pyx_n_s__use_collocations; +static PyObject *__pyx_n_s__use_index; +static PyObject *__pyx_n_s__use_sent_id; +static PyObject *__pyx_n_s__w; +static PyObject *__pyx_n_s__warn; +static PyObject *__pyx_n_s__word; +static PyObject *__pyx_n_s__word_alignments; +static PyObject *__pyx_n_s__words; +static PyObject *__pyx_n_s__write; +static PyObject *__pyx_n_s__write_text; +static PyObject *__pyx_n_s__zip; +static PyObject *__pyx_int_0; +static PyObject *__pyx_int_1; +static PyObject *__pyx_int_2; +static PyObject *__pyx_int_5; +static PyObject *__pyx_int_neg_1; +static PyObject *__pyx_int_10; +static PyObject *__pyx_int_20; +static PyObject *__pyx_int_1000; +static PyObject *__pyx_int_65536; +static PyObject *__pyx_k_38; +static PyObject *__pyx_k_97; +static PyObject *__pyx_k_tuple_10; +static PyObject *__pyx_k_tuple_11; +static PyObject *__pyx_k_tuple_12; +static PyObject *__pyx_k_tuple_15; +static PyObject *__pyx_k_tuple_16; +static PyObject *__pyx_k_tuple_17; +static PyObject *__pyx_k_tuple_19; +static PyObject *__pyx_k_tuple_20; +static PyObject *__pyx_k_tuple_21; +static PyObject *__pyx_k_tuple_23; +static PyObject *__pyx_k_tuple_25; +static PyObject *__pyx_k_tuple_26; +static PyObject *__pyx_k_tuple_27; +static PyObject *__pyx_k_tuple_29; +static PyObject *__pyx_k_tuple_30; +static PyObject *__pyx_k_tuple_31; +static PyObject *__pyx_k_tuple_33; +static PyObject *__pyx_k_tuple_34; +static PyObject *__pyx_k_tuple_35; +static PyObject *__pyx_k_tuple_36; +static PyObject *__pyx_k_tuple_37; +static PyObject *__pyx_k_tuple_40; +static PyObject *__pyx_k_tuple_41; +static PyObject *__pyx_k_tuple_44; +static PyObject *__pyx_k_tuple_46; +static PyObject *__pyx_k_tuple_48; +static PyObject *__pyx_k_tuple_50; +static PyObject *__pyx_k_tuple_51; +static PyObject *__pyx_k_tuple_52; +static PyObject *__pyx_k_tuple_54; +static PyObject *__pyx_k_tuple_58; +static PyObject *__pyx_k_tuple_60; +static PyObject *__pyx_k_tuple_71; +static PyObject *__pyx_k_tuple_73; +static PyObject *__pyx_k_tuple_75; +static PyObject *__pyx_k_tuple_77; +static PyObject *__pyx_k_tuple_78; +static PyObject *__pyx_k_tuple_79; +static PyObject *__pyx_k_tuple_80; +static PyObject *__pyx_k_tuple_91; +static PyObject *__pyx_k_tuple_94; +static PyObject *__pyx_k_tuple_95; +static PyObject *__pyx_k_tuple_96; +static PyObject *__pyx_k_tuple_100; +static PyObject *__pyx_k_tuple_105; +static PyObject *__pyx_k_tuple_120; +static PyObject *__pyx_k_tuple_132; +static PyObject *__pyx_k_tuple_136; +static PyObject *__pyx_k_tuple_137; +static PyObject *__pyx_k_tuple_140; +static PyObject *__pyx_k_tuple_142; +static PyObject *__pyx_k_codeobj_133; +static PyObject *__pyx_k_codeobj_138; +static PyObject *__pyx_k_codeobj_141; +static PyObject *__pyx_k_codeobj_143; + +/* "_cdec_sa.pyx":5 + * import gzip + * + * cdef float monitor_cpu(): # <<<<<<<<<<<<<< + * return (resource.getrusage(resource.RUSAGE_SELF).ru_utime+ + * resource.getrusage(resource.RUSAGE_SELF).ru_stime) + */ + +static float __pyx_f_8_cdec_sa_monitor_cpu(void) { + float __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + float __pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("monitor_cpu", 0); + + /* "_cdec_sa.pyx":6 + * + * cdef float monitor_cpu(): + * return (resource.getrusage(resource.RUSAGE_SELF).ru_utime+ # <<<<<<<<<<<<<< + * resource.getrusage(resource.RUSAGE_SELF).ru_stime) + * + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__resource); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__getrusage); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__resource); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__RUSAGE_SELF); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__ru_utime); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "_cdec_sa.pyx":7 + * cdef float monitor_cpu(): + * return (resource.getrusage(resource.RUSAGE_SELF).ru_utime+ + * resource.getrusage(resource.RUSAGE_SELF).ru_stime) # <<<<<<<<<<<<<< + * + * def gzip_or_text(char* filename): + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__resource); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__getrusage); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__resource); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__RUSAGE_SELF); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__ru_stime); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyNumber_Add(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_5 = __pyx_PyFloat_AsFloat(__pyx_t_4); if (unlikely((__pyx_t_5 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_5; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_WriteUnraisable("_cdec_sa.monitor_cpu", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_1gzip_or_text(PyObject *__pyx_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyMethodDef __pyx_mdef_8_cdec_sa_1gzip_or_text = {__Pyx_NAMESTR("gzip_or_text"), (PyCFunction)__pyx_pw_8_cdec_sa_1gzip_or_text, METH_O, __Pyx_DOCSTR(0)}; +static PyObject *__pyx_pw_8_cdec_sa_1gzip_or_text(PyObject *__pyx_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("gzip_or_text (wrapper)", 0); + __pyx_self = __pyx_self; + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.gzip_or_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_gzip_or_text(__pyx_self, ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec_sa.pyx":9 + * resource.getrusage(resource.RUSAGE_SELF).ru_stime) + * + * def gzip_or_text(char* filename): # <<<<<<<<<<<<<< + * if filename.endswith('.gz'): + * return gzip.GzipFile(filename) + */ + +static PyObject *__pyx_pf_8_cdec_sa_gzip_or_text(CYTHON_UNUSED PyObject *__pyx_self, char *__pyx_v_filename) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("gzip_or_text", 0); + + /* "_cdec_sa.pyx":10 + * + * def gzip_or_text(char* filename): + * if filename.endswith('.gz'): # <<<<<<<<<<<<<< + * return gzip.GzipFile(filename) + * else: + */ + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = __Pyx_PyBytes_Tailmatch(((PyObject *)__pyx_t_1), ((PyObject *)__pyx_kp_s_1), 0, PY_SSIZE_T_MAX, 1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec_sa.pyx":11 + * def gzip_or_text(char* filename): + * if filename.endswith('.gz'): + * return gzip.GzipFile(filename) # <<<<<<<<<<<<<< + * else: + * return open(filename) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__gzip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__GzipFile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "_cdec_sa.pyx":13 + * return gzip.GzipFile(filename) + * else: + * return open(filename) # <<<<<<<<<<<<<< + * + * logger = logging.getLogger('cdec.sa') + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec_sa.gzip_or_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_9FloatList_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_9FloatList_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_size; + int __pyx_v_increment; + int __pyx_v_initial_len; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__size,&__pyx_n_s__increment,&__pyx_n_s__initial_len,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__increment); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__initial_len); + if (value) { values[2] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + if (values[0]) { + } else { + __pyx_v_size = ((int)0); + } + if (values[1]) { + } else { + __pyx_v_increment = ((int)1); + } + if (values[2]) { + } else { + __pyx_v_initial_len = ((int)0); + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + if (values[0]) { + __pyx_v_size = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_size = ((int)0); + } + if (values[1]) { + __pyx_v_increment = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_increment == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_increment = ((int)1); + } + if (values[2]) { + __pyx_v_initial_len = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_initial_len == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_initial_len = ((int)0); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.FloatList.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_9FloatList___cinit__(((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_v_self), __pyx_v_size, __pyx_v_increment, __pyx_v_initial_len); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":15 + * cdef float* arr + * + * def __cinit__(self, int size=0, int increment=1, int initial_len=0): # <<<<<<<<<<<<<< + * if initial_len > size: + * size = initial_len + */ + +static int __pyx_pf_8_cdec_sa_9FloatList___cinit__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, int __pyx_v_size, int __pyx_v_increment, int __pyx_v_initial_len) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":16 + * + * def __cinit__(self, int size=0, int increment=1, int initial_len=0): + * if initial_len > size: # <<<<<<<<<<<<<< + * size = initial_len + * self.size = size + */ + __pyx_t_1 = (__pyx_v_initial_len > __pyx_v_size); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":17 + * def __cinit__(self, int size=0, int increment=1, int initial_len=0): + * if initial_len > size: + * size = initial_len # <<<<<<<<<<<<<< + * self.size = size + * self.increment = increment + */ + __pyx_v_size = __pyx_v_initial_len; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":18 + * if initial_len > size: + * size = initial_len + * self.size = size # <<<<<<<<<<<<<< + * self.increment = increment + * self.len = initial_len + */ + __pyx_v_self->size = __pyx_v_size; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":19 + * size = initial_len + * self.size = size + * self.increment = increment # <<<<<<<<<<<<<< + * self.len = initial_len + * self.arr = malloc(size*sizeof(float)) + */ + __pyx_v_self->increment = __pyx_v_increment; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":20 + * self.size = size + * self.increment = increment + * self.len = initial_len # <<<<<<<<<<<<<< + * self.arr = malloc(size*sizeof(float)) + * memset(self.arr, 0, initial_len*sizeof(float)) + */ + __pyx_v_self->len = __pyx_v_initial_len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":21 + * self.increment = increment + * self.len = initial_len + * self.arr = malloc(size*sizeof(float)) # <<<<<<<<<<<<<< + * memset(self.arr, 0, initial_len*sizeof(float)) + * + */ + __pyx_v_self->arr = ((float *)malloc((__pyx_v_size * (sizeof(float))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":22 + * self.len = initial_len + * self.arr = malloc(size*sizeof(float)) + * memset(self.arr, 0, initial_len*sizeof(float)) # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + memset(__pyx_v_self->arr, 0, (__pyx_v_initial_len * (sizeof(float)))); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_8_cdec_sa_9FloatList_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_8_cdec_sa_9FloatList_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_8_cdec_sa_9FloatList_2__dealloc__(((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":24 + * memset(self.arr, 0, initial_len*sizeof(float)) + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * free(self.arr) + * + */ + +static void __pyx_pf_8_cdec_sa_9FloatList_2__dealloc__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":25 + * + * def __dealloc__(self): + * free(self.arr) # <<<<<<<<<<<<<< + * + * def __getitem__(self, i): + */ + free(__pyx_v_self->arr); + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9FloatList_5__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9FloatList_5__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9FloatList_4__getitem__(((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":27 + * free(self.arr) + * + * def __getitem__(self, i): # <<<<<<<<<<<<<< + * j = i + * if i<0: + */ + +static PyObject *__pyx_pf_8_cdec_sa_9FloatList_4__getitem__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_v_j = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_t_5; + Py_ssize_t __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__getitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":28 + * + * def __getitem__(self, i): + * j = i # <<<<<<<<<<<<<< + * if i<0: + * j = self.len + i + */ + __Pyx_INCREF(__pyx_v_i); + __pyx_v_j = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":29 + * def __getitem__(self, i): + * j = i + * if i<0: # <<<<<<<<<<<<<< + * j = self.len + i + * if j<0 or j>=self.len: + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_v_i, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":30 + * j = i + * if i<0: + * j = self.len + i # <<<<<<<<<<<<<< + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_v_i); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_v_j); + __pyx_v_j = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":31 + * if i<0: + * j = self.len + i + * if j<0 or j>=self.len: # <<<<<<<<<<<<<< + * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) + * return self.arr[j] + */ + __pyx_t_3 = PyObject_RichCompare(__pyx_v_j, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (!__pyx_t_2) { + __pyx_t_3 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_RichCompare(__pyx_v_j, __pyx_t_3, Py_GE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = __pyx_t_4; + } else { + __pyx_t_5 = __pyx_t_2; + } + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":32 + * j = self.len + i + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) # <<<<<<<<<<<<<< + * return self.arr[j] + * + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":33 + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) + * return self.arr[j] # <<<<<<<<<<<<<< + * + * cdef void set(self, int i, float v): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_j); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyFloat_FromDouble((__pyx_v_self->arr[__pyx_t_6])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_3); + __Pyx_AddTraceback("_cdec_sa.FloatList.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_j); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":35 + * return self.arr[j] + * + * cdef void set(self, int i, float v): # <<<<<<<<<<<<<< + * j = i + * if i<0: + */ + +static void __pyx_f_8_cdec_sa_9FloatList_set(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, int __pyx_v_i, float __pyx_v_v) { + int __pyx_v_j; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("set", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":36 + * + * cdef void set(self, int i, float v): + * j = i # <<<<<<<<<<<<<< + * if i<0: + * j = self.len + i + */ + __pyx_v_j = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":37 + * cdef void set(self, int i, float v): + * j = i + * if i<0: # <<<<<<<<<<<<<< + * j = self.len + i + * if j<0 or j>=self.len: + */ + __pyx_t_1 = (__pyx_v_i < 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":38 + * j = i + * if i<0: + * j = self.len + i # <<<<<<<<<<<<<< + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) + */ + __pyx_v_j = (__pyx_v_self->len + __pyx_v_i); + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":39 + * if i<0: + * j = self.len + i + * if j<0 or j>=self.len: # <<<<<<<<<<<<<< + * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) + * self.arr[j] = v + */ + __pyx_t_1 = (__pyx_v_j < 0); + if (!__pyx_t_1) { + __pyx_t_2 = (__pyx_v_j >= __pyx_v_self->len); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":40 + * j = self.len + i + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) # <<<<<<<<<<<<<< + * self.arr[j] = v + * + */ + __pyx_t_4 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_2), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":41 + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) + * self.arr[j] = v # <<<<<<<<<<<<<< + * + * def __setitem__(self, i, val): + */ + (__pyx_v_self->arr[__pyx_v_j]) = __pyx_v_v; + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_WriteUnraisable("_cdec_sa.FloatList.set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_9FloatList_7__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val); /*proto*/ +static int __pyx_pw_8_cdec_sa_9FloatList_7__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9FloatList_6__setitem__(((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_v_self), ((PyObject *)__pyx_v_i), ((PyObject *)__pyx_v_val)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":43 + * self.arr[j] = v + * + * def __setitem__(self, i, val): # <<<<<<<<<<<<<< + * self.set(i, val) + * + */ + +static int __pyx_pf_8_cdec_sa_9FloatList_6__setitem__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + float __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__setitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":44 + * + * def __setitem__(self, i, val): + * self.set(i, val) # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __pyx_PyFloat_AsFloat(__pyx_v_val); if (unlikely((__pyx_t_2 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + ((struct __pyx_vtabstruct_8_cdec_sa_FloatList *)__pyx_v_self->__pyx_vtab)->set(__pyx_v_self, __pyx_t_1, __pyx_t_2); + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec_sa.FloatList.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_8_cdec_sa_9FloatList_9__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_8_cdec_sa_9FloatList_9__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9FloatList_8__len__(((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":46 + * self.set(i, val) + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.len + * + */ + +static Py_ssize_t __pyx_pf_8_cdec_sa_9FloatList_8__len__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":47 + * + * def __len__(self): + * return self.len # <<<<<<<<<<<<<< + * + * def append(self, float val): + */ + __pyx_r = __pyx_v_self->len; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9FloatList_11append(PyObject *__pyx_v_self, PyObject *__pyx_arg_val); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9FloatList_11append(PyObject *__pyx_v_self, PyObject *__pyx_arg_val) { + float __pyx_v_val; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("append (wrapper)", 0); + assert(__pyx_arg_val); { + __pyx_v_val = __pyx_PyFloat_AsFloat(__pyx_arg_val); if (unlikely((__pyx_v_val == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.FloatList.append", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_9FloatList_10append(((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_v_self), ((float)__pyx_v_val)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":49 + * return self.len + * + * def append(self, float val): # <<<<<<<<<<<<<< + * if self.len == self.size: + * self.size = self.size + self.increment + */ + +static PyObject *__pyx_pf_8_cdec_sa_9FloatList_10append(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, float __pyx_v_val) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("append", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":50 + * + * def append(self, float val): + * if self.len == self.size: # <<<<<<<<<<<<<< + * self.size = self.size + self.increment + * self.arr = realloc(self.arr, self.size*sizeof(float)) + */ + __pyx_t_1 = (__pyx_v_self->len == __pyx_v_self->size); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":51 + * def append(self, float val): + * if self.len == self.size: + * self.size = self.size + self.increment # <<<<<<<<<<<<<< + * self.arr = realloc(self.arr, self.size*sizeof(float)) + * self.arr[self.len] = val + */ + __pyx_v_self->size = (__pyx_v_self->size + __pyx_v_self->increment); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":52 + * if self.len == self.size: + * self.size = self.size + self.increment + * self.arr = realloc(self.arr, self.size*sizeof(float)) # <<<<<<<<<<<<<< + * self.arr[self.len] = val + * self.len = self.len + 1 + */ + __pyx_v_self->arr = ((float *)realloc(__pyx_v_self->arr, (__pyx_v_self->size * (sizeof(float))))); + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":53 + * self.size = self.size + self.increment + * self.arr = realloc(self.arr, self.size*sizeof(float)) + * self.arr[self.len] = val # <<<<<<<<<<<<<< + * self.len = self.len + 1 + * + */ + (__pyx_v_self->arr[__pyx_v_self->len]) = __pyx_v_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":54 + * self.arr = realloc(self.arr, self.size*sizeof(float)) + * self.arr[self.len] = val + * self.len = self.len + 1 # <<<<<<<<<<<<<< + * + * cdef void write_handle(self, FILE* f): + */ + __pyx_v_self->len = (__pyx_v_self->len + 1); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":56 + * self.len = self.len + 1 + * + * cdef void write_handle(self, FILE* f): # <<<<<<<<<<<<<< + * fwrite(&(self.len), sizeof(float), 1, f) + * fwrite(self.arr, sizeof(float), self.len, f) + */ + +static void __pyx_f_8_cdec_sa_9FloatList_write_handle(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, FILE *__pyx_v_f) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_handle", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":57 + * + * cdef void write_handle(self, FILE* f): + * fwrite(&(self.len), sizeof(float), 1, f) # <<<<<<<<<<<<<< + * fwrite(self.arr, sizeof(float), self.len, f) + * + */ + fwrite((&__pyx_v_self->len), (sizeof(float)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":58 + * cdef void write_handle(self, FILE* f): + * fwrite(&(self.len), sizeof(float), 1, f) + * fwrite(self.arr, sizeof(float), self.len, f) # <<<<<<<<<<<<<< + * + * def write(self, char* filename): + */ + fwrite(__pyx_v_self->arr, (sizeof(float)), __pyx_v_self->len, __pyx_v_f); + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9FloatList_13write(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9FloatList_13write(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.FloatList.write", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_9FloatList_12write(((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":60 + * fwrite(self.arr, sizeof(float), self.len, f) + * + * def write(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "w") + */ + +static PyObject *__pyx_pf_8_cdec_sa_9FloatList_12write(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":62 + * def write(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "w") # <<<<<<<<<<<<<< + * self.write_handle(f) + * fclose(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":63 + * cdef FILE* f + * f = fopen(filename, "w") + * self.write_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + ((struct __pyx_vtabstruct_8_cdec_sa_FloatList *)__pyx_v_self->__pyx_vtab)->write_handle(__pyx_v_self, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":64 + * f = fopen(filename, "w") + * self.write_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + * + * cdef void read_handle(self, FILE* f): + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":66 + * fclose(f) + * + * cdef void read_handle(self, FILE* f): # <<<<<<<<<<<<<< + * free(self.arr) + * fread(&(self.len), sizeof(float), 1, f) + */ + +static void __pyx_f_8_cdec_sa_9FloatList_read_handle(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, FILE *__pyx_v_f) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_handle", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":67 + * + * cdef void read_handle(self, FILE* f): + * free(self.arr) # <<<<<<<<<<<<<< + * fread(&(self.len), sizeof(float), 1, f) + * self.arr = malloc(self.len * sizeof(float)) + */ + free(__pyx_v_self->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":68 + * cdef void read_handle(self, FILE* f): + * free(self.arr) + * fread(&(self.len), sizeof(float), 1, f) # <<<<<<<<<<<<<< + * self.arr = malloc(self.len * sizeof(float)) + * self.size = self.len + */ + fread((&__pyx_v_self->len), (sizeof(float)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":69 + * free(self.arr) + * fread(&(self.len), sizeof(float), 1, f) + * self.arr = malloc(self.len * sizeof(float)) # <<<<<<<<<<<<<< + * self.size = self.len + * fread(self.arr, sizeof(float), self.len, f) + */ + __pyx_v_self->arr = ((float *)malloc((__pyx_v_self->len * (sizeof(float))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":70 + * fread(&(self.len), sizeof(float), 1, f) + * self.arr = malloc(self.len * sizeof(float)) + * self.size = self.len # <<<<<<<<<<<<<< + * fread(self.arr, sizeof(float), self.len, f) + * + */ + __pyx_v_self->size = __pyx_v_self->len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":71 + * self.arr = malloc(self.len * sizeof(float)) + * self.size = self.len + * fread(self.arr, sizeof(float), self.len, f) # <<<<<<<<<<<<<< + * + * def read(self, char* filename): + */ + fread(__pyx_v_self->arr, (sizeof(float)), __pyx_v_self->len, __pyx_v_f); + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9FloatList_15read(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9FloatList_15read(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.FloatList.read", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_9FloatList_14read(((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":73 + * fread(self.arr, sizeof(float), self.len, f) + * + * def read(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "r") + */ + +static PyObject *__pyx_pf_8_cdec_sa_9FloatList_14read(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":75 + * def read(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "r") # <<<<<<<<<<<<<< + * self.read_handle(f) + * fclose(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":76 + * cdef FILE* f + * f = fopen(filename, "r") + * self.read_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_FloatList *)__pyx_v_self->__pyx_vtab)->read_handle(__pyx_v_self, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":77 + * f = fopen(filename, "r") + * self.read_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_7IntList_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_7IntList_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_size; + int __pyx_v_increment; + int __pyx_v_initial_len; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__size,&__pyx_n_s__increment,&__pyx_n_s__initial_len,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__increment); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__initial_len); + if (value) { values[2] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + if (values[0]) { + } else { + __pyx_v_size = ((int)0); + } + if (values[1]) { + } else { + __pyx_v_increment = ((int)1); + } + if (values[2]) { + } else { + __pyx_v_initial_len = ((int)0); + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + if (values[0]) { + __pyx_v_size = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_size = ((int)0); + } + if (values[1]) { + __pyx_v_increment = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_increment == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_increment = ((int)1); + } + if (values[2]) { + __pyx_v_initial_len = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_initial_len == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_initial_len = ((int)0); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.IntList.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_7IntList___cinit__(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), __pyx_v_size, __pyx_v_increment, __pyx_v_initial_len); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":15 + * cdef int* arr + * + * def __cinit__(self, int size=0, int increment=1, int initial_len=0): # <<<<<<<<<<<<<< + * if initial_len > size: + * size = initial_len + */ + +static int __pyx_pf_8_cdec_sa_7IntList___cinit__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, int __pyx_v_size, int __pyx_v_increment, int __pyx_v_initial_len) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":16 + * + * def __cinit__(self, int size=0, int increment=1, int initial_len=0): + * if initial_len > size: # <<<<<<<<<<<<<< + * size = initial_len + * self.size = size + */ + __pyx_t_1 = (__pyx_v_initial_len > __pyx_v_size); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":17 + * def __cinit__(self, int size=0, int increment=1, int initial_len=0): + * if initial_len > size: + * size = initial_len # <<<<<<<<<<<<<< + * self.size = size + * self.increment = increment + */ + __pyx_v_size = __pyx_v_initial_len; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":18 + * if initial_len > size: + * size = initial_len + * self.size = size # <<<<<<<<<<<<<< + * self.increment = increment + * self.len = initial_len + */ + __pyx_v_self->size = __pyx_v_size; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":19 + * size = initial_len + * self.size = size + * self.increment = increment # <<<<<<<<<<<<<< + * self.len = initial_len + * self.arr = malloc(size*sizeof(int)) + */ + __pyx_v_self->increment = __pyx_v_increment; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":20 + * self.size = size + * self.increment = increment + * self.len = initial_len # <<<<<<<<<<<<<< + * self.arr = malloc(size*sizeof(int)) + * memset(self.arr, 0, initial_len*sizeof(int)) + */ + __pyx_v_self->len = __pyx_v_initial_len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":21 + * self.increment = increment + * self.len = initial_len + * self.arr = malloc(size*sizeof(int)) # <<<<<<<<<<<<<< + * memset(self.arr, 0, initial_len*sizeof(int)) + * + */ + __pyx_v_self->arr = ((int *)malloc((__pyx_v_size * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":22 + * self.len = initial_len + * self.arr = malloc(size*sizeof(int)) + * memset(self.arr, 0, initial_len*sizeof(int)) # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + memset(__pyx_v_self->arr, 0, (__pyx_v_initial_len * (sizeof(int)))); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_3__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_3__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_7IntList_2__str__(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":24 + * memset(self.arr, 0, initial_len*sizeof(int)) + * + * def __str__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * ret = "IntList[" + */ + +static PyObject *__pyx_pf_8_cdec_sa_7IntList_2__str__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self) { + PyObject *__pyx_v_ret = NULL; + int __pyx_v_idx; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__str__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":26 + * def __str__(self): + * cdef unsigned i + * ret = "IntList[" # <<<<<<<<<<<<<< + * for idx in range(self.size): + * if idx>0: + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); + __pyx_v_ret = ((PyObject *)__pyx_kp_s_3); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":27 + * cdef unsigned i + * ret = "IntList[" + * for idx in range(self.size): # <<<<<<<<<<<<<< + * if idx>0: + * ret += "," + */ + __pyx_t_1 = __pyx_v_self->size; + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_v_idx = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":28 + * ret = "IntList[" + * for idx in range(self.size): + * if idx>0: # <<<<<<<<<<<<<< + * ret += "," + * ret += str(self.arr[idx]) + */ + __pyx_t_3 = (__pyx_v_idx > 0); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":29 + * for idx in range(self.size): + * if idx>0: + * ret += "," # <<<<<<<<<<<<<< + * ret += str(self.arr[idx]) + * ret += "]" + */ + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_ret, ((PyObject *)__pyx_kp_s_4)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_v_ret); + __pyx_v_ret = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":30 + * if idx>0: + * ret += "," + * ret += str(self.arr[idx]) # <<<<<<<<<<<<<< + * ret += "]" + * ret += "len=" + */ + __pyx_t_4 = PyInt_FromLong((__pyx_v_self->arr[__pyx_v_idx])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_ret, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_v_ret); + __pyx_v_ret = __pyx_t_5; + __pyx_t_5 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":31 + * ret += "," + * ret += str(self.arr[idx]) + * ret += "]" # <<<<<<<<<<<<<< + * ret += "len=" + * ret += self.len + */ + __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_ret, ((PyObject *)__pyx_kp_s_5)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_v_ret); + __pyx_v_ret = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":32 + * ret += str(self.arr[idx]) + * ret += "]" + * ret += "len=" # <<<<<<<<<<<<<< + * ret += self.len + * return ret + */ + __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_ret, ((PyObject *)__pyx_kp_s_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_v_ret); + __pyx_v_ret = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":33 + * ret += "]" + * ret += "len=" + * ret += self.len # <<<<<<<<<<<<<< + * return ret + * + */ + __pyx_t_5 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_ret, __pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_v_ret); + __pyx_v_ret = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":34 + * ret += "len=" + * ret += self.len + * return ret # <<<<<<<<<<<<<< + * + * def index(self, val): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_ret); + __pyx_r = __pyx_v_ret; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_cdec_sa.IntList.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_ret); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_5index(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_5index(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("index (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_7IntList_4index(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), ((PyObject *)__pyx_v_val)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":36 + * return ret + * + * def index(self, val): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.len): + */ + +static PyObject *__pyx_pf_8_cdec_sa_7IntList_4index(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_val) { + unsigned int __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("index", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":38 + * def index(self, val): + * cdef unsigned i + * for i in range(self.len): # <<<<<<<<<<<<<< + * if self.arr[i] == val: + * return i + */ + __pyx_t_1 = __pyx_v_self->len; + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_v_i = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":39 + * cdef unsigned i + * for i in range(self.len): + * if self.arr[i] == val: # <<<<<<<<<<<<<< + * return i + * return IndexError + */ + __pyx_t_3 = PyInt_FromLong((__pyx_v_self->arr[__pyx_v_i])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_v_val, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":40 + * for i in range(self.len): + * if self.arr[i] == val: + * return i # <<<<<<<<<<<<<< + * return IndexError + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = PyLong_FromUnsignedLong(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":41 + * if self.arr[i] == val: + * return i + * return IndexError # <<<<<<<<<<<<<< + * + * def partition(self,start,end): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_builtin_IndexError); + __pyx_r = __pyx_builtin_IndexError; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec_sa.IntList.index", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_7partition(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_7partition(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_start = 0; + PyObject *__pyx_v_end = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("partition (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("partition", 1, 2, 2, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "partition") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_start = values[0]; + __pyx_v_end = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("partition", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.IntList.partition", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_7IntList_6partition(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), __pyx_v_start, __pyx_v_end); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":43 + * return IndexError + * + * def partition(self,start,end): # <<<<<<<<<<<<<< + * pivot = self.arr[end] + * bottom = start-1 + */ + +static PyObject *__pyx_pf_8_cdec_sa_7IntList_6partition(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_end) { + PyObject *__pyx_v_pivot = NULL; + PyObject *__pyx_v_bottom = NULL; + PyObject *__pyx_v_top = NULL; + long __pyx_v_done; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + Py_ssize_t __pyx_t_5; + int __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("partition", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":44 + * + * def partition(self,start,end): + * pivot = self.arr[end] # <<<<<<<<<<<<<< + * bottom = start-1 + * top = end + */ + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_end); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->arr[__pyx_t_1])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_pivot = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":45 + * def partition(self,start,end): + * pivot = self.arr[end] + * bottom = start-1 # <<<<<<<<<<<<<< + * top = end + * done = 0 + */ + __pyx_t_2 = PyNumber_Subtract(__pyx_v_start, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_bottom = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":46 + * pivot = self.arr[end] + * bottom = start-1 + * top = end # <<<<<<<<<<<<<< + * done = 0 + * while not done: + */ + __Pyx_INCREF(__pyx_v_end); + __pyx_v_top = __pyx_v_end; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":47 + * bottom = start-1 + * top = end + * done = 0 # <<<<<<<<<<<<<< + * while not done: + * while not done: + */ + __pyx_v_done = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":48 + * top = end + * done = 0 + * while not done: # <<<<<<<<<<<<<< + * while not done: + * bottom += 1 + */ + while (1) { + __pyx_t_3 = (!__pyx_v_done); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":49 + * done = 0 + * while not done: + * while not done: # <<<<<<<<<<<<<< + * bottom += 1 + * if bottom == top: + */ + while (1) { + __pyx_t_3 = (!__pyx_v_done); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":50 + * while not done: + * while not done: + * bottom += 1 # <<<<<<<<<<<<<< + * if bottom == top: + * done = 1 + */ + __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_v_bottom, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_v_bottom); + __pyx_v_bottom = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":51 + * while not done: + * bottom += 1 + * if bottom == top: # <<<<<<<<<<<<<< + * done = 1 + * break + */ + __pyx_t_2 = PyObject_RichCompare(__pyx_v_bottom, __pyx_v_top, Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":52 + * bottom += 1 + * if bottom == top: + * done = 1 # <<<<<<<<<<<<<< + * break + * if self.arr[bottom] > pivot: + */ + __pyx_v_done = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":53 + * if bottom == top: + * done = 1 + * break # <<<<<<<<<<<<<< + * if self.arr[bottom] > pivot: + * self.arr[top] = self.arr[bottom] + */ + goto __pyx_L6_break; + goto __pyx_L7; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":54 + * done = 1 + * break + * if self.arr[bottom] > pivot: # <<<<<<<<<<<<<< + * self.arr[top] = self.arr[bottom] + * break + */ + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_bottom); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->arr[__pyx_t_1])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_v_pivot, Py_GT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":55 + * break + * if self.arr[bottom] > pivot: + * self.arr[top] = self.arr[bottom] # <<<<<<<<<<<<<< + * break + * while not done: + */ + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_bottom); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_top); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + (__pyx_v_self->arr[__pyx_t_5]) = (__pyx_v_self->arr[__pyx_t_1]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":56 + * if self.arr[bottom] > pivot: + * self.arr[top] = self.arr[bottom] + * break # <<<<<<<<<<<<<< + * while not done: + * top -= 1 + */ + goto __pyx_L6_break; + goto __pyx_L8; + } + __pyx_L8:; + } + __pyx_L6_break:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":57 + * self.arr[top] = self.arr[bottom] + * break + * while not done: # <<<<<<<<<<<<<< + * top -= 1 + * if top == bottom: + */ + while (1) { + __pyx_t_3 = (!__pyx_v_done); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":58 + * break + * while not done: + * top -= 1 # <<<<<<<<<<<<<< + * if top == bottom: + * done = 1 + */ + __pyx_t_4 = PyNumber_InPlaceSubtract(__pyx_v_top, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_v_top); + __pyx_v_top = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":59 + * while not done: + * top -= 1 + * if top == bottom: # <<<<<<<<<<<<<< + * done = 1 + * break + */ + __pyx_t_4 = PyObject_RichCompare(__pyx_v_top, __pyx_v_bottom, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":60 + * top -= 1 + * if top == bottom: + * done = 1 # <<<<<<<<<<<<<< + * break + * if self.arr[top] < pivot: + */ + __pyx_v_done = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":61 + * if top == bottom: + * done = 1 + * break # <<<<<<<<<<<<<< + * if self.arr[top] < pivot: + * self.arr[bottom] = self.arr[top] + */ + goto __pyx_L10_break; + goto __pyx_L11; + } + __pyx_L11:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":62 + * done = 1 + * break + * if self.arr[top] < pivot: # <<<<<<<<<<<<<< + * self.arr[bottom] = self.arr[top] + * break + */ + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_top); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong((__pyx_v_self->arr[__pyx_t_1])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_v_pivot, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":63 + * break + * if self.arr[top] < pivot: + * self.arr[bottom] = self.arr[top] # <<<<<<<<<<<<<< + * break + * self.arr[top] = pivot + */ + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_top); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_bottom); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + (__pyx_v_self->arr[__pyx_t_5]) = (__pyx_v_self->arr[__pyx_t_1]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":64 + * if self.arr[top] < pivot: + * self.arr[bottom] = self.arr[top] + * break # <<<<<<<<<<<<<< + * self.arr[top] = pivot + * return top + */ + goto __pyx_L10_break; + goto __pyx_L12; + } + __pyx_L12:; + } + __pyx_L10_break:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":65 + * self.arr[bottom] = self.arr[top] + * break + * self.arr[top] = pivot # <<<<<<<<<<<<<< + * return top + * + */ + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_pivot); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_top); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + (__pyx_v_self->arr[__pyx_t_1]) = __pyx_t_6; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":66 + * break + * self.arr[top] = pivot + * return top # <<<<<<<<<<<<<< + * + * def _doquicksort(self,start,end): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_top); + __pyx_r = __pyx_v_top; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec_sa.IntList.partition", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_pivot); + __Pyx_XDECREF(__pyx_v_bottom); + __Pyx_XDECREF(__pyx_v_top); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_9_doquicksort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_9_doquicksort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_start = 0; + PyObject *__pyx_v_end = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_doquicksort (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_doquicksort", 1, 2, 2, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_doquicksort") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_start = values[0]; + __pyx_v_end = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("_doquicksort", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.IntList._doquicksort", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_7IntList_8_doquicksort(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), __pyx_v_start, __pyx_v_end); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":68 + * return top + * + * def _doquicksort(self,start,end): # <<<<<<<<<<<<<< + * if start < end: + * split = self.partition(start,end) + */ + +static PyObject *__pyx_pf_8_cdec_sa_7IntList_8_doquicksort(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_end) { + PyObject *__pyx_v_split = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_doquicksort", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":69 + * + * def _doquicksort(self,start,end): + * if start < end: # <<<<<<<<<<<<<< + * split = self.partition(start,end) + * self._doquicksort(start,split-1) + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_v_end, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":70 + * def _doquicksort(self,start,end): + * if start < end: + * split = self.partition(start,end) # <<<<<<<<<<<<<< + * self._doquicksort(start,split-1) + * self._doquicksort(split+1,end) + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__partition); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_start); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_start); + __Pyx_GIVEREF(__pyx_v_start); + __Pyx_INCREF(__pyx_v_end); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_end); + __Pyx_GIVEREF(__pyx_v_end); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_v_split = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":71 + * if start < end: + * split = self.partition(start,end) + * self._doquicksort(start,split-1) # <<<<<<<<<<<<<< + * self._doquicksort(split+1,end) + * else: + */ + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___doquicksort); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyNumber_Subtract(__pyx_v_split, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_start); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_start); + __Pyx_GIVEREF(__pyx_v_start); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":72 + * split = self.partition(start,end) + * self._doquicksort(start,split-1) + * self._doquicksort(split+1,end) # <<<<<<<<<<<<<< + * else: + * return + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___doquicksort); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyNumber_Add(__pyx_v_split, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_end); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_end); + __Pyx_GIVEREF(__pyx_v_end); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":74 + * self._doquicksort(split+1,end) + * else: + * return # <<<<<<<<<<<<<< + * + * def sort(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec_sa.IntList._doquicksort", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_split); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_11sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_11sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("sort (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_7IntList_10sort(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":76 + * return + * + * def sort(self): # <<<<<<<<<<<<<< + * self._doquicksort(0,self.len-1) + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_7IntList_10sort(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("sort", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":77 + * + * def sort(self): + * self._doquicksort(0,self.len-1) # <<<<<<<<<<<<<< + * + * def reset(self): + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___doquicksort); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->len - 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + __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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.IntList.sort", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_13reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_13reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("reset (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_7IntList_12reset(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":79 + * self._doquicksort(0,self.len-1) + * + * def reset(self): # <<<<<<<<<<<<<< + * self.len = 0 + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_7IntList_12reset(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("reset", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":80 + * + * def reset(self): + * self.len = 0 # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->len = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_8_cdec_sa_7IntList_15__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_8_cdec_sa_7IntList_15__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_8_cdec_sa_7IntList_14__dealloc__(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":82 + * self.len = 0 + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * free(self.arr) + * + */ + +static void __pyx_pf_8_cdec_sa_7IntList_14__dealloc__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":83 + * + * def __dealloc__(self): + * free(self.arr) # <<<<<<<<<<<<<< + * + * def __getitem__(self, index): + */ + free(__pyx_v_self->arr); + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_17__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_17__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_7IntList_16__getitem__(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), ((PyObject *)__pyx_v_index)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":85 + * free(self.arr) + * + * def __getitem__(self, index): # <<<<<<<<<<<<<< + * cdef int i, j, k + * if isinstance(index, int): + */ + +static PyObject *__pyx_pf_8_cdec_sa_7IntList_16__getitem__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_index) { + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_k; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__getitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":87 + * def __getitem__(self, index): + * cdef int i, j, k + * if isinstance(index, int): # <<<<<<<<<<<<<< + * j = index + * if j < 0: + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyInt_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_index, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":88 + * cdef int i, j, k + * if isinstance(index, int): + * j = index # <<<<<<<<<<<<<< + * if j < 0: + * j = self.len + j + */ + __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_v_index); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_j = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":89 + * if isinstance(index, int): + * j = index + * if j < 0: # <<<<<<<<<<<<<< + * j = self.len + j + * if j<0 or j>=self.len: + */ + __pyx_t_2 = (__pyx_v_j < 0); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":90 + * j = index + * if j < 0: + * j = self.len + j # <<<<<<<<<<<<<< + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length IntList" % (index, self.len)) + */ + __pyx_v_j = (__pyx_v_self->len + __pyx_v_j); + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":91 + * if j < 0: + * j = self.len + j + * if j<0 or j>=self.len: # <<<<<<<<<<<<<< + * raise IndexError("Requested index %d of %d-length IntList" % (index, self.len)) + * return self.arr[j] + */ + __pyx_t_2 = (__pyx_v_j < 0); + if (!__pyx_t_2) { + __pyx_t_4 = (__pyx_v_j >= __pyx_v_self->len); + __pyx_t_5 = __pyx_t_4; + } else { + __pyx_t_5 = __pyx_t_2; + } + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":92 + * j = self.len + j + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length IntList" % (index, self.len)) # <<<<<<<<<<<<<< + * return self.arr[j] + * elif isinstance(index, slice): + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(__pyx_v_index); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_index); + __Pyx_GIVEREF(__pyx_v_index); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_7), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":93 + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length IntList" % (index, self.len)) + * return self.arr[j] # <<<<<<<<<<<<<< + * elif isinstance(index, slice): + * i = index.start + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong((__pyx_v_self->arr[__pyx_v_j])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":94 + * raise IndexError("Requested index %d of %d-length IntList" % (index, self.len)) + * return self.arr[j] + * elif isinstance(index, slice): # <<<<<<<<<<<<<< + * i = index.start + * j = index.stop + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PySlice_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_5 = __Pyx_TypeCheck(__pyx_v_index, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":95 + * return self.arr[j] + * elif isinstance(index, slice): + * i = index.start # <<<<<<<<<<<<<< + * j = index.stop + * if i < 0: + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_i = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":96 + * elif isinstance(index, slice): + * i = index.start + * j = index.stop # <<<<<<<<<<<<<< + * if i < 0: + * i = self.len + i + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__stop); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_j = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":97 + * i = index.start + * j = index.stop + * if i < 0: # <<<<<<<<<<<<<< + * i = self.len + i + * if j < 0: + */ + __pyx_t_5 = (__pyx_v_i < 0); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":98 + * j = index.stop + * if i < 0: + * i = self.len + i # <<<<<<<<<<<<<< + * if j < 0: + * j = self.len + j + */ + __pyx_v_i = (__pyx_v_self->len + __pyx_v_i); + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":99 + * if i < 0: + * i = self.len + i + * if j < 0: # <<<<<<<<<<<<<< + * j = self.len + j + * if i < 0 or i >= self.len or j < 0 or j > self.len: + */ + __pyx_t_5 = (__pyx_v_j < 0); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":100 + * i = self.len + i + * if j < 0: + * j = self.len + j # <<<<<<<<<<<<<< + * if i < 0 or i >= self.len or j < 0 or j > self.len: + * raise IndexError("Requested index %d:%d of %d-length IntList" % (index.start, index.stop, self.len)) + */ + __pyx_v_j = (__pyx_v_self->len + __pyx_v_j); + goto __pyx_L7; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":101 + * if j < 0: + * j = self.len + j + * if i < 0 or i >= self.len or j < 0 or j > self.len: # <<<<<<<<<<<<<< + * raise IndexError("Requested index %d:%d of %d-length IntList" % (index.start, index.stop, self.len)) + * result = () + */ + __pyx_t_5 = (__pyx_v_i < 0); + if (!__pyx_t_5) { + __pyx_t_2 = (__pyx_v_i >= __pyx_v_self->len); + if (!__pyx_t_2) { + __pyx_t_4 = (__pyx_v_j < 0); + if (!__pyx_t_4) { + __pyx_t_7 = (__pyx_v_j > __pyx_v_self->len); + __pyx_t_8 = __pyx_t_7; + } else { + __pyx_t_8 = __pyx_t_4; + } + __pyx_t_4 = __pyx_t_8; + } else { + __pyx_t_4 = __pyx_t_2; + } + __pyx_t_2 = __pyx_t_4; + } else { + __pyx_t_2 = __pyx_t_5; + } + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":102 + * j = self.len + j + * if i < 0 or i >= self.len or j < 0 or j > self.len: + * raise IndexError("Requested index %d:%d of %d-length IntList" % (index.start, index.stop, self.len)) # <<<<<<<<<<<<<< + * result = () + * for k from i <= k < j: + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__stop); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_9 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_t_1 = 0; + __pyx_t_6 = 0; + __pyx_t_9 = 0; + __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_8), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_9)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); + __pyx_t_9 = 0; + __pyx_t_9 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L8; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":103 + * if i < 0 or i >= self.len or j < 0 or j > self.len: + * raise IndexError("Requested index %d:%d of %d-length IntList" % (index.start, index.stop, self.len)) + * result = () # <<<<<<<<<<<<<< + * for k from i <= k < j: + * result = result + (self.arr[k],) + */ + __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); + __pyx_v_result = __pyx_empty_tuple; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":104 + * raise IndexError("Requested index %d:%d of %d-length IntList" % (index.start, index.stop, self.len)) + * result = () + * for k from i <= k < j: # <<<<<<<<<<<<<< + * result = result + (self.arr[k],) + * return result + */ + __pyx_t_3 = __pyx_v_j; + for (__pyx_v_k = __pyx_v_i; __pyx_v_k < __pyx_t_3; __pyx_v_k++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":105 + * result = () + * for k from i <= k < j: + * result = result + (self.arr[k],) # <<<<<<<<<<<<<< + * return result + * else: + */ + __pyx_t_9 = PyInt_FromLong((__pyx_v_self->arr[__pyx_v_k])); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_9 = PyNumber_Add(((PyObject *)__pyx_v_result), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_result)); + __pyx_v_result = __pyx_t_9; + __pyx_t_9 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":106 + * for k from i <= k < j: + * result = result + (self.arr[k],) + * return result # <<<<<<<<<<<<<< + * else: + * raise TypeError("Illegal key type %s for IntList" % type(index)) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":108 + * return result + * else: + * raise TypeError("Illegal key type %s for IntList" % type(index)) # <<<<<<<<<<<<<< + * + * cdef void set(self, int i, int val): + */ + __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), ((PyObject *)Py_TYPE(__pyx_v_index))); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_9)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); + __pyx_t_9 = 0; + __pyx_t_9 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("_cdec_sa.IntList.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":110 + * raise TypeError("Illegal key type %s for IntList" % type(index)) + * + * cdef void set(self, int i, int val): # <<<<<<<<<<<<<< + * j = i + * if i<0: + */ + +static void __pyx_f_8_cdec_sa_7IntList_set(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, int __pyx_v_i, int __pyx_v_val) { + int __pyx_v_j; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("set", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":111 + * + * cdef void set(self, int i, int val): + * j = i # <<<<<<<<<<<<<< + * if i<0: + * j = self.len + i + */ + __pyx_v_j = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":112 + * cdef void set(self, int i, int val): + * j = i + * if i<0: # <<<<<<<<<<<<<< + * j = self.len + i + * if j<0 or j>=self.len: + */ + __pyx_t_1 = (__pyx_v_i < 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":113 + * j = i + * if i<0: + * j = self.len + i # <<<<<<<<<<<<<< + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length IntList" % (i, self.len)) + */ + __pyx_v_j = (__pyx_v_self->len + __pyx_v_i); + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":114 + * if i<0: + * j = self.len + i + * if j<0 or j>=self.len: # <<<<<<<<<<<<<< + * raise IndexError("Requested index %d of %d-length IntList" % (i, self.len)) + * self.arr[j] = val + */ + __pyx_t_1 = (__pyx_v_j < 0); + if (!__pyx_t_1) { + __pyx_t_2 = (__pyx_v_j >= __pyx_v_self->len); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":115 + * j = self.len + i + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length IntList" % (i, self.len)) # <<<<<<<<<<<<<< + * self.arr[j] = val + * + */ + __pyx_t_4 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_7), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":116 + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length IntList" % (i, self.len)) + * self.arr[j] = val # <<<<<<<<<<<<<< + * + * def __setitem__(self, i, val): + */ + (__pyx_v_self->arr[__pyx_v_j]) = __pyx_v_val; + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_WriteUnraisable("_cdec_sa.IntList.set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_7IntList_19__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val); /*proto*/ +static int __pyx_pw_8_cdec_sa_7IntList_19__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_7IntList_18__setitem__(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), ((PyObject *)__pyx_v_i), ((PyObject *)__pyx_v_val)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":118 + * self.arr[j] = val + * + * def __setitem__(self, i, val): # <<<<<<<<<<<<<< + * self.set(i, val) + * + */ + +static int __pyx_pf_8_cdec_sa_7IntList_18__setitem__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__setitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":119 + * + * def __setitem__(self, i, val): + * self.set(i, val) # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_v_val); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->__pyx_vtab)->set(__pyx_v_self, __pyx_t_1, __pyx_t_2); + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec_sa.IntList.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_8_cdec_sa_7IntList_21__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_8_cdec_sa_7IntList_21__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_7IntList_20__len__(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":121 + * self.set(i, val) + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.len + * + */ + +static Py_ssize_t __pyx_pf_8_cdec_sa_7IntList_20__len__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":122 + * + * def __len__(self): + * return self.len # <<<<<<<<<<<<<< + * + * def getSize(self): + */ + __pyx_r = __pyx_v_self->len; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_23getSize(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_23getSize(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getSize (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_7IntList_22getSize(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":124 + * return self.len + * + * def getSize(self): # <<<<<<<<<<<<<< + * return self.size + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_7IntList_22getSize(struct __pyx_obj_8_cdec_sa_IntList *__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("getSize", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":125 + * + * def getSize(self): + * return self.size # <<<<<<<<<<<<<< + * + * def append(self, int val): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_cdec_sa.IntList.getSize", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_25append(PyObject *__pyx_v_self, PyObject *__pyx_arg_val); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_25append(PyObject *__pyx_v_self, PyObject *__pyx_arg_val) { + int __pyx_v_val; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("append (wrapper)", 0); + assert(__pyx_arg_val); { + __pyx_v_val = __Pyx_PyInt_AsInt(__pyx_arg_val); if (unlikely((__pyx_v_val == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.IntList.append", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_7IntList_24append(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), ((int)__pyx_v_val)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":127 + * return self.size + * + * def append(self, int val): # <<<<<<<<<<<<<< + * self._append(val) + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_7IntList_24append(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, int __pyx_v_val) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("append", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":128 + * + * def append(self, int val): + * self._append(val) # <<<<<<<<<<<<<< + * + * cdef void _append(self, int val): + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->__pyx_vtab)->_append(__pyx_v_self, __pyx_v_val); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":130 + * self._append(val) + * + * cdef void _append(self, int val): # <<<<<<<<<<<<<< + * if self.len == self.size: + * self.size = self.size + self.increment + */ + +static void __pyx_f_8_cdec_sa_7IntList__append(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, int __pyx_v_val) { + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("_append", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":131 + * + * cdef void _append(self, int val): + * if self.len == self.size: # <<<<<<<<<<<<<< + * self.size = self.size + self.increment + * self.arr = realloc(self.arr, self.size*sizeof(int)) + */ + __pyx_t_1 = (__pyx_v_self->len == __pyx_v_self->size); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":132 + * cdef void _append(self, int val): + * if self.len == self.size: + * self.size = self.size + self.increment # <<<<<<<<<<<<<< + * self.arr = realloc(self.arr, self.size*sizeof(int)) + * self.arr[self.len] = val + */ + __pyx_v_self->size = (__pyx_v_self->size + __pyx_v_self->increment); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":133 + * if self.len == self.size: + * self.size = self.size + self.increment + * self.arr = realloc(self.arr, self.size*sizeof(int)) # <<<<<<<<<<<<<< + * self.arr[self.len] = val + * self.len = self.len + 1 + */ + __pyx_v_self->arr = ((int *)realloc(__pyx_v_self->arr, (__pyx_v_self->size * (sizeof(int))))); + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":134 + * self.size = self.size + self.increment + * self.arr = realloc(self.arr, self.size*sizeof(int)) + * self.arr[self.len] = val # <<<<<<<<<<<<<< + * self.len = self.len + 1 + * + */ + (__pyx_v_self->arr[__pyx_v_self->len]) = __pyx_v_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":135 + * self.arr = realloc(self.arr, self.size*sizeof(int)) + * self.arr[self.len] = val + * self.len = self.len + 1 # <<<<<<<<<<<<<< + * + * def extend(self, other): + */ + __pyx_v_self->len = (__pyx_v_self->len + 1); + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_27extend(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_27extend(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("extend (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_7IntList_26extend(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), ((PyObject *)__pyx_v_other)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":137 + * self.len = self.len + 1 + * + * def extend(self, other): # <<<<<<<<<<<<<< + * self._extend(other) + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_7IntList_26extend(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_other) { + 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("extend", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":138 + * + * def extend(self, other): + * self._extend(other) # <<<<<<<<<<<<<< + * + * cdef void _extend(self, IntList other): + */ + if (!(likely(((__pyx_v_other) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_other, __pyx_ptype_8_cdec_sa_IntList))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_v_other; + __Pyx_INCREF(__pyx_t_1); + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->__pyx_vtab)->_extend(__pyx_v_self, ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1)); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec_sa.IntList.extend", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":140 + * self._extend(other) + * + * cdef void _extend(self, IntList other): # <<<<<<<<<<<<<< + * self._extend_arr(other.arr, other.len) + * + */ + +static void __pyx_f_8_cdec_sa_7IntList__extend(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_other) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_extend", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":141 + * + * cdef void _extend(self, IntList other): + * self._extend_arr(other.arr, other.len) # <<<<<<<<<<<<<< + * + * cdef void _extend_arr(self, int* other, int other_len): + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->__pyx_vtab)->_extend_arr(__pyx_v_self, __pyx_v_other->arr, __pyx_v_other->len); + + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":143 + * self._extend_arr(other.arr, other.len) + * + * cdef void _extend_arr(self, int* other, int other_len): # <<<<<<<<<<<<<< + * if self.size < self.len + other_len: + * self.size = self.len + other_len + */ + +static void __pyx_f_8_cdec_sa_7IntList__extend_arr(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, int *__pyx_v_other, int __pyx_v_other_len) { + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("_extend_arr", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":144 + * + * cdef void _extend_arr(self, int* other, int other_len): + * if self.size < self.len + other_len: # <<<<<<<<<<<<<< + * self.size = self.len + other_len + * self.arr = realloc(self.arr, self.size*sizeof(int)) + */ + __pyx_t_1 = (__pyx_v_self->size < (__pyx_v_self->len + __pyx_v_other_len)); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":145 + * cdef void _extend_arr(self, int* other, int other_len): + * if self.size < self.len + other_len: + * self.size = self.len + other_len # <<<<<<<<<<<<<< + * self.arr = realloc(self.arr, self.size*sizeof(int)) + * memcpy(self.arr+self.len, other, other_len*sizeof(int)) + */ + __pyx_v_self->size = (__pyx_v_self->len + __pyx_v_other_len); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":146 + * if self.size < self.len + other_len: + * self.size = self.len + other_len + * self.arr = realloc(self.arr, self.size*sizeof(int)) # <<<<<<<<<<<<<< + * memcpy(self.arr+self.len, other, other_len*sizeof(int)) + * self.len = self.len + other_len + */ + __pyx_v_self->arr = ((int *)realloc(__pyx_v_self->arr, (__pyx_v_self->size * (sizeof(int))))); + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":147 + * self.size = self.len + other_len + * self.arr = realloc(self.arr, self.size*sizeof(int)) + * memcpy(self.arr+self.len, other, other_len*sizeof(int)) # <<<<<<<<<<<<<< + * self.len = self.len + other_len + * + */ + memcpy((__pyx_v_self->arr + __pyx_v_self->len), __pyx_v_other, (__pyx_v_other_len * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":148 + * self.arr = realloc(self.arr, self.size*sizeof(int)) + * memcpy(self.arr+self.len, other, other_len*sizeof(int)) + * self.len = self.len + other_len # <<<<<<<<<<<<<< + * + * cdef void _clear(self): + */ + __pyx_v_self->len = (__pyx_v_self->len + __pyx_v_other_len); + + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":150 + * self.len = self.len + other_len + * + * cdef void _clear(self): # <<<<<<<<<<<<<< + * free(self.arr) + * self.len = 0 + */ + +static void __pyx_f_8_cdec_sa_7IntList__clear(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_clear", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":151 + * + * cdef void _clear(self): + * free(self.arr) # <<<<<<<<<<<<<< + * self.len = 0 + * self.size = 0 + */ + free(__pyx_v_self->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":152 + * cdef void _clear(self): + * free(self.arr) + * self.len = 0 # <<<<<<<<<<<<<< + * self.size = 0 + * self.arr = malloc(0) + */ + __pyx_v_self->len = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":153 + * free(self.arr) + * self.len = 0 + * self.size = 0 # <<<<<<<<<<<<<< + * self.arr = malloc(0) + * + */ + __pyx_v_self->size = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":154 + * self.len = 0 + * self.size = 0 + * self.arr = malloc(0) # <<<<<<<<<<<<<< + * + * cdef void write_handle(self, FILE* f): + */ + __pyx_v_self->arr = ((int *)malloc(0)); + + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":156 + * self.arr = malloc(0) + * + * cdef void write_handle(self, FILE* f): # <<<<<<<<<<<<<< + * fwrite(&(self.len), sizeof(int), 1, f) + * fwrite(self.arr, sizeof(int), self.len, f) + */ + +static void __pyx_f_8_cdec_sa_7IntList_write_handle(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, FILE *__pyx_v_f) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_handle", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":157 + * + * cdef void write_handle(self, FILE* f): + * fwrite(&(self.len), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fwrite(self.arr, sizeof(int), self.len, f) + * + */ + fwrite((&__pyx_v_self->len), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":158 + * cdef void write_handle(self, FILE* f): + * fwrite(&(self.len), sizeof(int), 1, f) + * fwrite(self.arr, sizeof(int), self.len, f) # <<<<<<<<<<<<<< + * + * def write(self, char* filename): + */ + fwrite(__pyx_v_self->arr, (sizeof(int)), __pyx_v_self->len, __pyx_v_f); + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_29write(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_29write(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.IntList.write", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_7IntList_28write(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":160 + * fwrite(self.arr, sizeof(int), self.len, f) + * + * def write(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "w") + */ + +static PyObject *__pyx_pf_8_cdec_sa_7IntList_28write(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":162 + * def write(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "w") # <<<<<<<<<<<<<< + * self.write_handle(f) + * fclose(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":163 + * cdef FILE* f + * f = fopen(filename, "w") + * self.write_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->__pyx_vtab)->write_handle(__pyx_v_self, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":164 + * f = fopen(filename, "w") + * self.write_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + * + * cdef void read_handle(self, FILE* f): + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":166 + * fclose(f) + * + * cdef void read_handle(self, FILE* f): # <<<<<<<<<<<<<< + * (self.arr) + * fread(&(self.len), sizeof(int), 1, f) + */ + +static void __pyx_f_8_cdec_sa_7IntList_read_handle(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, FILE *__pyx_v_f) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_handle", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":167 + * + * cdef void read_handle(self, FILE* f): + * (self.arr) # <<<<<<<<<<<<<< + * fread(&(self.len), sizeof(int), 1, f) + * self.arr = malloc(self.len * sizeof(int)) + */ + __pyx_v_self->arr; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":168 + * cdef void read_handle(self, FILE* f): + * (self.arr) + * fread(&(self.len), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * self.arr = malloc(self.len * sizeof(int)) + * self.size = self.len + */ + fread((&__pyx_v_self->len), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":169 + * (self.arr) + * fread(&(self.len), sizeof(int), 1, f) + * self.arr = malloc(self.len * sizeof(int)) # <<<<<<<<<<<<<< + * self.size = self.len + * fread(self.arr, sizeof(int), self.len, f) + */ + __pyx_v_self->arr = ((int *)malloc((__pyx_v_self->len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":170 + * fread(&(self.len), sizeof(int), 1, f) + * self.arr = malloc(self.len * sizeof(int)) + * self.size = self.len # <<<<<<<<<<<<<< + * fread(self.arr, sizeof(int), self.len, f) + * + */ + __pyx_v_self->size = __pyx_v_self->len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":171 + * self.arr = malloc(self.len * sizeof(int)) + * self.size = self.len + * fread(self.arr, sizeof(int), self.len, f) # <<<<<<<<<<<<<< + * + * def read(self, char* filename): + */ + fread(__pyx_v_self->arr, (sizeof(int)), __pyx_v_self->len, __pyx_v_f); + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_31read(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_7IntList_31read(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.IntList.read", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_7IntList_30read(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":173 + * fread(self.arr, sizeof(int), self.len, f) + * + * def read(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "r") + */ + +static PyObject *__pyx_pf_8_cdec_sa_7IntList_30read(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":175 + * def read(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "r") # <<<<<<<<<<<<<< + * self.read_handle(f) + * fclose(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":176 + * cdef FILE* f + * f = fopen(filename, "r") + * self.read_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->__pyx_vtab)->read_handle(__pyx_v_self, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":177 + * f = fopen(filename, "r") + * self.read_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_9StringMap_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_9StringMap_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; + __pyx_r = __pyx_pf_8_cdec_sa_9StringMap___cinit__(((struct __pyx_obj_8_cdec_sa_StringMap *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":13 + * cdef int index(self, char *s) + * + * def __cinit__(self): # <<<<<<<<<<<<<< + * self.vocab = stringmap_new() + * + */ + +static int __pyx_pf_8_cdec_sa_9StringMap___cinit__(struct __pyx_obj_8_cdec_sa_StringMap *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":14 + * + * def __cinit__(self): + * self.vocab = stringmap_new() # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->vocab = stringmap_new(); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_8_cdec_sa_9StringMap_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_8_cdec_sa_9StringMap_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_8_cdec_sa_9StringMap_2__dealloc__(((struct __pyx_obj_8_cdec_sa_StringMap *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":16 + * self.vocab = stringmap_new() + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * stringmap_delete(self.vocab) + * + */ + +static void __pyx_pf_8_cdec_sa_9StringMap_2__dealloc__(struct __pyx_obj_8_cdec_sa_StringMap *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":17 + * + * def __dealloc__(self): + * stringmap_delete(self.vocab) # <<<<<<<<<<<<<< + * + * cdef char *word(self, int i): + */ + stringmap_delete(__pyx_v_self->vocab); + + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":19 + * stringmap_delete(self.vocab) + * + * cdef char *word(self, int i): # <<<<<<<<<<<<<< + * return stringmap_word(self.vocab, i) + * + */ + +static char *__pyx_f_8_cdec_sa_9StringMap_word(struct __pyx_obj_8_cdec_sa_StringMap *__pyx_v_self, int __pyx_v_i) { + char *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("word", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":20 + * + * cdef char *word(self, int i): + * return stringmap_word(self.vocab, i) # <<<<<<<<<<<<<< + * + * cdef int index(self, char *s): + */ + __pyx_r = stringmap_word(__pyx_v_self->vocab, __pyx_v_i); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":22 + * return stringmap_word(self.vocab, i) + * + * cdef int index(self, char *s): # <<<<<<<<<<<<<< + * return stringmap_index(self.vocab, s) + */ + +static int __pyx_f_8_cdec_sa_9StringMap_index(struct __pyx_obj_8_cdec_sa_StringMap *__pyx_v_self, char *__pyx_v_s) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("index", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":23 + * + * cdef int index(self, char *s): + * return stringmap_index(self.vocab, s) # <<<<<<<<<<<<<< + */ + __pyx_r = stringmap_index(__pyx_v_self->vocab, __pyx_v_s); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_9DataArray_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_9DataArray_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_from_binary = 0; + PyObject *__pyx_v_from_text = 0; + int __pyx_v_use_sent_id; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__from_binary,&__pyx_n_s__from_text,&__pyx_n_s__use_sent_id,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[3] = {0,0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":17 + * cdef bint use_sent_id + * + * def __cinit__(self, from_binary=None, from_text=None, bint use_sent_id=False): # <<<<<<<<<<<<<< + * self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} + * self.id2word = ["END_OF_FILE", "END_OF_LINE"] + */ + values[0] = ((PyObject *)Py_None); + values[1] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_binary); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_text); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_sent_id); + if (value) { values[2] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + if (values[2]) { + } else { + __pyx_v_use_sent_id = ((int)0); + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_from_binary = values[0]; + __pyx_v_from_text = values[1]; + if (values[2]) { + __pyx_v_use_sent_id = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_use_sent_id == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_use_sent_id = ((int)0); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.DataArray.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_9DataArray___cinit__(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), __pyx_v_from_binary, __pyx_v_from_text, __pyx_v_use_sent_id); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_9DataArray___cinit__(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text, int __pyx_v_use_sent_id) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":18 + * + * def __cinit__(self, from_binary=None, from_text=None, bint use_sent_id=False): + * self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} # <<<<<<<<<<<<<< + * self.id2word = ["END_OF_FILE", "END_OF_LINE"] + * self.data = IntList(1000,1000) + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__END_OF_FILE), __pyx_int_0) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__END_OF_LINE), __pyx_int_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_GOTREF(__pyx_v_self->word2id); + __Pyx_DECREF(__pyx_v_self->word2id); + __pyx_v_self->word2id = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":19 + * def __cinit__(self, from_binary=None, from_text=None, bint use_sent_id=False): + * self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} + * self.id2word = ["END_OF_FILE", "END_OF_LINE"] # <<<<<<<<<<<<<< + * self.data = IntList(1000,1000) + * self.sent_id = IntList(1000,1000) + */ + __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_n_s__END_OF_FILE)); + PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__END_OF_FILE)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__END_OF_FILE)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__END_OF_LINE)); + PyList_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_n_s__END_OF_LINE)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__END_OF_LINE)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_GOTREF(__pyx_v_self->id2word); + __Pyx_DECREF(__pyx_v_self->id2word); + __pyx_v_self->id2word = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":20 + * self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} + * self.id2word = ["END_OF_FILE", "END_OF_LINE"] + * self.data = IntList(1000,1000) # <<<<<<<<<<<<<< + * self.sent_id = IntList(1000,1000) + * self.sent_index = IntList(1000,1000) + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->data); + __Pyx_DECREF(((PyObject *)__pyx_v_self->data)); + __pyx_v_self->data = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":21 + * self.id2word = ["END_OF_FILE", "END_OF_LINE"] + * self.data = IntList(1000,1000) + * self.sent_id = IntList(1000,1000) # <<<<<<<<<<<<<< + * self.sent_index = IntList(1000,1000) + * self.use_sent_id = use_sent_id + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_k_tuple_11), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->sent_id); + __Pyx_DECREF(((PyObject *)__pyx_v_self->sent_id)); + __pyx_v_self->sent_id = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":22 + * self.data = IntList(1000,1000) + * self.sent_id = IntList(1000,1000) + * self.sent_index = IntList(1000,1000) # <<<<<<<<<<<<<< + * self.use_sent_id = use_sent_id + * if from_binary: + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_k_tuple_12), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->sent_index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->sent_index)); + __pyx_v_self->sent_index = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":23 + * self.sent_id = IntList(1000,1000) + * self.sent_index = IntList(1000,1000) + * self.use_sent_id = use_sent_id # <<<<<<<<<<<<<< + * if from_binary: + * self.read_binary(from_binary) + */ + __pyx_v_self->use_sent_id = __pyx_v_use_sent_id; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":24 + * self.sent_index = IntList(1000,1000) + * self.use_sent_id = use_sent_id + * if from_binary: # <<<<<<<<<<<<<< + * self.read_binary(from_binary) + * elif from_text: + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_binary); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":25 + * self.use_sent_id = use_sent_id + * if from_binary: + * self.read_binary(from_binary) # <<<<<<<<<<<<<< + * elif from_text: + * self.read_text(from_text) + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_binary); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_from_binary); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_binary); + __Pyx_GIVEREF(__pyx_v_from_binary); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":26 + * if from_binary: + * self.read_binary(from_binary) + * elif from_text: # <<<<<<<<<<<<<< + * self.read_text(from_text) + * + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_text); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":27 + * self.read_binary(from_binary) + * elif from_text: + * self.read_text(from_text) # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_text); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_from_text); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_text); + __Pyx_GIVEREF(__pyx_v_from_text); + __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec_sa.DataArray.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_8_cdec_sa_9DataArray_3__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_8_cdec_sa_9DataArray_3__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_2__len__(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":29 + * self.read_text(from_text) + * + * def __len__(self): # <<<<<<<<<<<<<< + * return len(self.data) + * + */ + +static Py_ssize_t __pyx_pf_8_cdec_sa_9DataArray_2__len__(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":30 + * + * def __len__(self): + * return len(self.data) # <<<<<<<<<<<<<< + * + * def getSentId(self, i): + */ + __pyx_t_1 = ((PyObject *)__pyx_v_self->data); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec_sa.DataArray.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_5getSentId(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_5getSentId(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getSentId (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_4getSentId(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":32 + * return len(self.data) + * + * def getSentId(self, i): # <<<<<<<<<<<<<< + * return self.sent_id.arr[i] + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_4getSentId(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("getSentId", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":33 + * + * def getSentId(self, i): + * return self.sent_id.arr[i] # <<<<<<<<<<<<<< + * + * def getSent(self, i): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->sent_id->arr[__pyx_t_1])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_cdec_sa.DataArray.getSentId", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_7getSent(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_7getSent(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getSent (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_6getSent(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":35 + * return self.sent_id.arr[i] + * + * def getSent(self, i): # <<<<<<<<<<<<<< + * cdef int j, start, stop + * sent = [] + */ + +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_6getSent(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_i) { + int __pyx_v_start; + int __pyx_v_stop; + PyObject *__pyx_v_sent = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("getSent", 0); + __Pyx_INCREF(__pyx_v_i); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":37 + * def getSent(self, i): + * cdef int j, start, stop + * sent = [] # <<<<<<<<<<<<<< + * start = self.sent_index.arr[i] + * stop = self.sent_index.arr[i+1] + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sent = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":38 + * cdef int j, start, stop + * sent = [] + * start = self.sent_index.arr[i] # <<<<<<<<<<<<<< + * stop = self.sent_index.arr[i+1] + * for i from start <= i < stop: + */ + __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_start = (__pyx_v_self->sent_index->arr[__pyx_t_2]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":39 + * sent = [] + * start = self.sent_index.arr[i] + * stop = self.sent_index.arr[i+1] # <<<<<<<<<<<<<< + * for i from start <= i < stop: + * sent.append(self.id2word[self.data.arr[i]]) + */ + __pyx_t_1 = PyNumber_Add(__pyx_v_i, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_stop = (__pyx_v_self->sent_index->arr[__pyx_t_2]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":40 + * start = self.sent_index.arr[i] + * stop = self.sent_index.arr[i+1] + * for i from start <= i < stop: # <<<<<<<<<<<<<< + * sent.append(self.id2word[self.data.arr[i]]) + * return sent + */ + __pyx_t_3 = __pyx_v_stop; + for (__pyx_t_4 = __pyx_v_start; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) { + __pyx_t_1 = PyInt_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":41 + * stop = self.sent_index.arr[i+1] + * for i from start <= i < stop: + * sent.append(self.id2word[self.data.arr[i]]) # <<<<<<<<<<<<<< + * return sent + * + */ + __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_self->id2word, (__pyx_v_self->data->arr[__pyx_t_2]), sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyList_Append(__pyx_v_sent, __pyx_t_1); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":40 + * start = self.sent_index.arr[i] + * stop = self.sent_index.arr[i+1] + * for i from start <= i < stop: # <<<<<<<<<<<<<< + * sent.append(self.id2word[self.data.arr[i]]) + * return sent + */ + __pyx_t_1 = PyInt_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":42 + * for i from start <= i < stop: + * sent.append(self.id2word[self.data.arr[i]]) + * return sent # <<<<<<<<<<<<<< + * + * def getSentPos(self, loc): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_sent)); + __pyx_r = ((PyObject *)__pyx_v_sent); + 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_sa.DataArray.getSent", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_sent); + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_9getSentPos(PyObject *__pyx_v_self, PyObject *__pyx_v_loc); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_9getSentPos(PyObject *__pyx_v_self, PyObject *__pyx_v_loc) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getSentPos (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_8getSentPos(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_loc)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":44 + * return sent + * + * def getSentPos(self, loc): # <<<<<<<<<<<<<< + * return loc - self.sent_index.arr[self.sent_id.arr[loc]] + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_8getSentPos(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_loc) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("getSentPos", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":45 + * + * def getSentPos(self, loc): + * return loc - self.sent_index.arr[self.sent_id.arr[loc]] # <<<<<<<<<<<<<< + * + * def get_id(self, word): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_loc); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->sent_index->arr[(__pyx_v_self->sent_id->arr[__pyx_t_1])])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_Subtract(__pyx_v_loc, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.DataArray.getSentPos", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_11get_id(PyObject *__pyx_v_self, PyObject *__pyx_v_word); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_11get_id(PyObject *__pyx_v_self, PyObject *__pyx_v_word) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_id (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_10get_id(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_word)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":47 + * return loc - self.sent_index.arr[self.sent_id.arr[loc]] + * + * def get_id(self, word): # <<<<<<<<<<<<<< + * if not word in self.word2id: + * self.word2id[word] = len(self.id2word) + */ + +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_10get_id(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_word) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_id", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":48 + * + * def get_id(self, word): + * if not word in self.word2id: # <<<<<<<<<<<<<< + * self.word2id[word] = len(self.id2word) + * self.id2word.append(word) + */ + __pyx_t_1 = ((PySequence_Contains(__pyx_v_self->word2id, __pyx_v_word))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = (!__pyx_t_1); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":49 + * def get_id(self, word): + * if not word in self.word2id: + * self.word2id[word] = len(self.id2word) # <<<<<<<<<<<<<< + * self.id2word.append(word) + * return self.word2id[word] + */ + __pyx_t_3 = __pyx_v_self->id2word; + __Pyx_INCREF(__pyx_t_3); + __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyObject_SetItem(__pyx_v_self->word2id, __pyx_v_word, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":50 + * if not word in self.word2id: + * self.word2id[word] = len(self.id2word) + * self.id2word.append(word) # <<<<<<<<<<<<<< + * return self.word2id[word] + * + */ + __pyx_t_3 = __Pyx_PyObject_Append(__pyx_v_self->id2word, __pyx_v_word); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":51 + * self.word2id[word] = len(self.id2word) + * self.id2word.append(word) + * return self.word2id[word] # <<<<<<<<<<<<<< + * + * def get_word(self, id): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = PyObject_GetItem(__pyx_v_self->word2id, __pyx_v_word); if (!__pyx_t_3) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.DataArray.get_id", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_13get_word(PyObject *__pyx_v_self, PyObject *__pyx_v_id); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_13get_word(PyObject *__pyx_v_self, PyObject *__pyx_v_id) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_word (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_12get_word(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_id)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":53 + * return self.word2id[word] + * + * def get_word(self, id): # <<<<<<<<<<<<<< + * return self.id2word[id] + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_12get_word(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_id) { + 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("get_word", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":54 + * + * def get_word(self, id): + * return self.id2word[id] # <<<<<<<<<<<<<< + * + * def write_text(self, char* filename): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetItem(__pyx_v_self->id2word, __pyx_v_id); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_cdec_sa.DataArray.get_word", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_15write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_15write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_text (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.DataArray.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_14write_text(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":56 + * return self.id2word[id] + * + * def write_text(self, char* filename): # <<<<<<<<<<<<<< + * with open(filename, "w") as f: + * for w_id in self.data: + */ + +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_14write_text(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_v_w_id = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + int __pyx_t_14; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_text", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":57 + * + * def write_text(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * for w_id in self.data: + * if w_id > 1: + */ + /*with:*/ { + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_f = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":58 + * def write_text(self, char* filename): + * with open(filename, "w") as f: + * for w_id in self.data: # <<<<<<<<<<<<<< + * if w_id > 1: + * f.write("%s " % self.get_word(w_id)) + */ + if (PyList_CheckExact(((PyObject *)__pyx_v_self->data)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->data))) { + __pyx_t_4 = ((PyObject *)__pyx_v_self->data); __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(((PyObject *)__pyx_v_self->data)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; + } else { + __pyx_t_1 = __pyx_t_9(__pyx_t_4); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF(__pyx_v_w_id); + __pyx_v_w_id = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":59 + * with open(filename, "w") as f: + * for w_id in self.data: + * if w_id > 1: # <<<<<<<<<<<<<< + * f.write("%s " % self.get_word(w_id)) + * if w_id == 1: + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_v_w_id, __pyx_int_1, Py_GT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":60 + * for w_id in self.data: + * if w_id > 1: + * f.write("%s " % self.get_word(w_id)) # <<<<<<<<<<<<<< + * if w_id == 1: + * f.write("\n") + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_word); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_INCREF(__pyx_v_w_id); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_w_id); + __Pyx_GIVEREF(__pyx_v_w_id); + __pyx_t_12 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; + __pyx_t_11 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_13), __pyx_t_12); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_11)); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)__pyx_t_11)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_11)); + __pyx_t_11 = 0; + __pyx_t_11 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L18; + } + __pyx_L18:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":61 + * if w_id > 1: + * f.write("%s " % self.get_word(w_id)) + * if w_id == 1: # <<<<<<<<<<<<<< + * f.write("\n") + * + */ + __pyx_t_11 = PyObject_RichCompare(__pyx_v_w_id, __pyx_int_1, Py_EQ); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":62 + * f.write("%s " % self.get_word(w_id)) + * if w_id == 1: + * f.write("\n") # <<<<<<<<<<<<<< + * + * def read_text(self, char* filename): + */ + __pyx_t_11 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_12 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_k_tuple_15), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L19; + } + __pyx_L19:; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":57 + * + * def write_text(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * for w_id in self.data: + * if w_id > 1: + */ + /*except:*/ { + __Pyx_AddTraceback("_cdec_sa.DataArray.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_12, &__pyx_t_11) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_12); + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_INCREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_11); + __Pyx_GIVEREF(__pyx_t_11); + __pyx_t_13 = PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_13); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_14 = (!__pyx_t_10); + if (__pyx_t_14) { + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_11); + __Pyx_ErrRestore(__pyx_t_4, __pyx_t_12, __pyx_t_11); + __pyx_t_4 = 0; __pyx_t_12 = 0; __pyx_t_11 = 0; + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L22; + } + __pyx_L22:; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_16, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L23; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L23:; + } + + __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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("_cdec_sa.DataArray.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_w_id); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_17read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_17read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_text (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.DataArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_16read_text(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":64 + * f.write("\n") + * + * def read_text(self, char* filename): # <<<<<<<<<<<<<< + * cdef int word_count = 0 + * with gzip_or_text(filename) as fp: + */ + +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_16read_text(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { + int __pyx_v_word_count; + PyObject *__pyx_v_fp = NULL; + PyObject *__pyx_v_line_num = NULL; + PyObject *__pyx_v_line = NULL; + PyObject *__pyx_v_word = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + Py_ssize_t __pyx_t_11; + PyObject *(*__pyx_t_12)(PyObject *); + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + int __pyx_t_15; + PyObject *__pyx_t_16 = NULL; + int __pyx_t_17; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_text", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":65 + * + * def read_text(self, char* filename): + * cdef int word_count = 0 # <<<<<<<<<<<<<< + * with gzip_or_text(filename) as fp: + * for line_num, line in enumerate(fp): + */ + __pyx_v_word_count = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":66 + * def read_text(self, char* filename): + * cdef int word_count = 0 + * with gzip_or_text(filename) as fp: # <<<<<<<<<<<<<< + * for line_num, line in enumerate(fp): + * self.sent_index.append(word_count) + */ + /*with:*/ { + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__gzip_or_text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __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[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_1); + __pyx_v_fp = __pyx_t_1; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":67 + * cdef int word_count = 0 + * with gzip_or_text(filename) as fp: + * for line_num, line in enumerate(fp): # <<<<<<<<<<<<<< + * self.sent_index.append(word_count) + * for word in line.split(): + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_1 = __pyx_int_0; + if (PyList_CheckExact(__pyx_v_fp) || PyTuple_CheckExact(__pyx_v_fp)) { + __pyx_t_2 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_3); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_3); __pyx_t_8++; + } else { + __pyx_t_3 = __pyx_t_9(__pyx_t_2); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_line); + __pyx_v_line = __pyx_t_3; + __pyx_t_3 = 0; + __Pyx_INCREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_line_num); + __pyx_v_line_num = __pyx_t_1; + __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":68 + * with gzip_or_text(filename) as fp: + * for line_num, line in enumerate(fp): + * self.sent_index.append(word_count) # <<<<<<<<<<<<<< + * for word in line.split(): + * self.data.append(self.get_id(word)) + */ + __pyx_t_3 = PyInt_FromLong(__pyx_v_word_count); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_index), __pyx_t_3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":69 + * for line_num, line in enumerate(fp): + * self.sent_index.append(word_count) + * for word in line.split(): # <<<<<<<<<<<<<< + * self.data.append(self.get_id(word)) + * if self.use_sent_id: + */ + __pyx_t_10 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_3 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_10 = __pyx_t_3; __Pyx_INCREF(__pyx_t_10); __pyx_t_11 = 0; + __pyx_t_12 = NULL; + } else { + __pyx_t_11 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_12 = Py_TYPE(__pyx_t_10)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (!__pyx_t_12 && PyList_CheckExact(__pyx_t_10)) { + if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_10)) break; + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_11); __Pyx_INCREF(__pyx_t_3); __pyx_t_11++; + } else if (!__pyx_t_12 && PyTuple_CheckExact(__pyx_t_10)) { + if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_10)) break; + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_11); __Pyx_INCREF(__pyx_t_3); __pyx_t_11++; + } else { + __pyx_t_3 = __pyx_t_12(__pyx_t_10); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_word); + __pyx_v_word = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":70 + * self.sent_index.append(word_count) + * for word in line.split(): + * self.data.append(self.get_id(word)) # <<<<<<<<<<<<<< + * if self.use_sent_id: + * self.sent_id.append(line_num) + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_id); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_INCREF(__pyx_v_word); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_v_word); + __Pyx_GIVEREF(__pyx_v_word); + __pyx_t_14 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + __pyx_t_13 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->data), __pyx_t_14); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":71 + * for word in line.split(): + * self.data.append(self.get_id(word)) + * if self.use_sent_id: # <<<<<<<<<<<<<< + * self.sent_id.append(line_num) + * word_count = word_count + 1 + */ + if (__pyx_v_self->use_sent_id) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":72 + * self.data.append(self.get_id(word)) + * if self.use_sent_id: + * self.sent_id.append(line_num) # <<<<<<<<<<<<<< + * word_count = word_count + 1 + * self.data.append(1) + */ + __pyx_t_13 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_id), __pyx_v_line_num); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + goto __pyx_L20; + } + __pyx_L20:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":73 + * if self.use_sent_id: + * self.sent_id.append(line_num) + * word_count = word_count + 1 # <<<<<<<<<<<<<< + * self.data.append(1) + * if self.use_sent_id: + */ + __pyx_v_word_count = (__pyx_v_word_count + 1); + } + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":74 + * self.sent_id.append(line_num) + * word_count = word_count + 1 + * self.data.append(1) # <<<<<<<<<<<<<< + * if self.use_sent_id: + * self.sent_id.append(line_num) + */ + __pyx_t_10 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->data), __pyx_int_1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":75 + * word_count = word_count + 1 + * self.data.append(1) + * if self.use_sent_id: # <<<<<<<<<<<<<< + * self.sent_id.append(line_num) + * word_count = word_count + 1 + */ + if (__pyx_v_self->use_sent_id) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":76 + * self.data.append(1) + * if self.use_sent_id: + * self.sent_id.append(line_num) # <<<<<<<<<<<<<< + * word_count = word_count + 1 + * self.data.append(0) + */ + __pyx_t_10 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_id), __pyx_v_line_num); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L21; + } + __pyx_L21:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":77 + * if self.use_sent_id: + * self.sent_id.append(line_num) + * word_count = word_count + 1 # <<<<<<<<<<<<<< + * self.data.append(0) + * self.sent_index.append(word_count) + */ + __pyx_v_word_count = (__pyx_v_word_count + 1); + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":78 + * self.sent_id.append(line_num) + * word_count = word_count + 1 + * self.data.append(0) # <<<<<<<<<<<<<< + * self.sent_index.append(word_count) + * + */ + __pyx_t_1 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->data), __pyx_int_0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":79 + * word_count = word_count + 1 + * self.data.append(0) + * self.sent_index.append(word_count) # <<<<<<<<<<<<<< + * + * def read_binary(self, char* filename): + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_word_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_index), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":66 + * def read_text(self, char* filename): + * cdef int word_count = 0 + * with gzip_or_text(filename) as fp: # <<<<<<<<<<<<<< + * for line_num, line in enumerate(fp): + * self.sent_index.append(word_count) + */ + /*except:*/ { + __Pyx_AddTraceback("_cdec_sa.DataArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_1, &__pyx_t_10) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_13 = PyTuple_New(3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_t_16 = PyObject_Call(__pyx_t_4, __pyx_t_13, NULL); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_16); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + if (unlikely(__pyx_t_15 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_17 = (!__pyx_t_15); + if (__pyx_t_17) { + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_10); + __Pyx_ErrRestore(__pyx_t_2, __pyx_t_1, __pyx_t_10); + __pyx_t_2 = 0; __pyx_t_1 = 0; __pyx_t_10 = 0; + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L24; + } + __pyx_L24:; + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_4) { + __pyx_t_7 = PyObject_Call(__pyx_t_4, __pyx_k_tuple_17, NULL); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_17 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L25; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L1_error; + __pyx_L25:; + } + + __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_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_AddTraceback("_cdec_sa.DataArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_fp); + __Pyx_XDECREF(__pyx_v_line_num); + __Pyx_XDECREF(__pyx_v_line); + __Pyx_XDECREF(__pyx_v_word); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_19read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_19read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.DataArray.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_18read_binary(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":81 + * self.sent_index.append(word_count) + * + * def read_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "r") + */ + +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_18read_binary(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":83 + * def read_binary(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "r") # <<<<<<<<<<<<<< + * self.read_handle(f) + * fclose(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":84 + * cdef FILE* f + * f = fopen(filename, "r") + * self.read_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + ((struct __pyx_vtabstruct_8_cdec_sa_DataArray *)__pyx_v_self->__pyx_vtab)->read_handle(__pyx_v_self, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":85 + * f = fopen(filename, "r") + * self.read_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + * + * cdef void read_handle(self, FILE* f): + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":87 + * fclose(f) + * + * cdef void read_handle(self, FILE* f): # <<<<<<<<<<<<<< + * cdef int num_words, word_len + * cdef unsigned i + */ + +static void __pyx_f_8_cdec_sa_9DataArray_read_handle(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, FILE *__pyx_v_f) { + int __pyx_v_num_words; + int __pyx_v_word_len; + CYTHON_UNUSED unsigned int __pyx_v_i; + char *__pyx_v_c_word; + PyObject *__pyx_v_py_word = 0; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + int __pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_handle", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":92 + * cdef char* c_word + * cdef bytes py_word + * self.data.read_handle(f) # <<<<<<<<<<<<<< + * self.sent_index.read_handle(f) + * self.sent_id.read_handle(f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->data->__pyx_vtab)->read_handle(__pyx_v_self->data, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":93 + * cdef bytes py_word + * self.data.read_handle(f) + * self.sent_index.read_handle(f) # <<<<<<<<<<<<<< + * self.sent_id.read_handle(f) + * fread(&(num_words), sizeof(int), 1, f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->sent_index->__pyx_vtab)->read_handle(__pyx_v_self->sent_index, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":94 + * self.data.read_handle(f) + * self.sent_index.read_handle(f) + * self.sent_id.read_handle(f) # <<<<<<<<<<<<<< + * fread(&(num_words), sizeof(int), 1, f) + * for i in range(num_words): + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->sent_id->__pyx_vtab)->read_handle(__pyx_v_self->sent_id, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":95 + * self.sent_index.read_handle(f) + * self.sent_id.read_handle(f) + * fread(&(num_words), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * for i in range(num_words): + * fread(&(word_len), sizeof(int), 1, f) + */ + fread((&__pyx_v_num_words), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":96 + * self.sent_id.read_handle(f) + * fread(&(num_words), sizeof(int), 1, f) + * for i in range(num_words): # <<<<<<<<<<<<<< + * fread(&(word_len), sizeof(int), 1, f) + * c_word = malloc (word_len * sizeof(char)) + */ + __pyx_t_1 = __pyx_v_num_words; + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_v_i = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":97 + * fread(&(num_words), sizeof(int), 1, f) + * for i in range(num_words): + * fread(&(word_len), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * c_word = malloc (word_len * sizeof(char)) + * fread(c_word, sizeof(char), word_len, f) + */ + fread((&__pyx_v_word_len), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":98 + * for i in range(num_words): + * fread(&(word_len), sizeof(int), 1, f) + * c_word = malloc (word_len * sizeof(char)) # <<<<<<<<<<<<<< + * fread(c_word, sizeof(char), word_len, f) + * py_word = c_word + */ + __pyx_v_c_word = ((char *)malloc((__pyx_v_word_len * (sizeof(char))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":99 + * fread(&(word_len), sizeof(int), 1, f) + * c_word = malloc (word_len * sizeof(char)) + * fread(c_word, sizeof(char), word_len, f) # <<<<<<<<<<<<<< + * py_word = c_word + * free(c_word) + */ + fread(__pyx_v_c_word, (sizeof(char)), __pyx_v_word_len, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":100 + * c_word = malloc (word_len * sizeof(char)) + * fread(c_word, sizeof(char), word_len, f) + * py_word = c_word # <<<<<<<<<<<<<< + * free(c_word) + * self.word2id[py_word] = len(self.id2word) + */ + __pyx_t_3 = PyBytes_FromString(__pyx_v_c_word); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __Pyx_XDECREF(((PyObject *)__pyx_v_py_word)); + __pyx_v_py_word = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":101 + * fread(c_word, sizeof(char), word_len, f) + * py_word = c_word + * free(c_word) # <<<<<<<<<<<<<< + * self.word2id[py_word] = len(self.id2word) + * self.id2word.append(py_word) + */ + free(__pyx_v_c_word); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":102 + * py_word = c_word + * free(c_word) + * self.word2id[py_word] = len(self.id2word) # <<<<<<<<<<<<<< + * self.id2word.append(py_word) + * if len(self.sent_id) == 0: + */ + __pyx_t_3 = __pyx_v_self->id2word; + __Pyx_INCREF(__pyx_t_3); + __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyObject_SetItem(__pyx_v_self->word2id, ((PyObject *)__pyx_v_py_word), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":103 + * free(c_word) + * self.word2id[py_word] = len(self.id2word) + * self.id2word.append(py_word) # <<<<<<<<<<<<<< + * if len(self.sent_id) == 0: + * self.use_sent_id = False + */ + __pyx_t_3 = __Pyx_PyObject_Append(__pyx_v_self->id2word, ((PyObject *)__pyx_v_py_word)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":104 + * self.word2id[py_word] = len(self.id2word) + * self.id2word.append(py_word) + * if len(self.sent_id) == 0: # <<<<<<<<<<<<<< + * self.use_sent_id = False + * else: + */ + __pyx_t_3 = ((PyObject *)__pyx_v_self->sent_id); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_5 = (__pyx_t_4 == 0); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":105 + * self.id2word.append(py_word) + * if len(self.sent_id) == 0: + * self.use_sent_id = False # <<<<<<<<<<<<<< + * else: + * self.use_sent_id = True + */ + __pyx_v_self->use_sent_id = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":107 + * self.use_sent_id = False + * else: + * self.use_sent_id = True # <<<<<<<<<<<<<< + * + * cdef void write_handle(self, FILE* f): + */ + __pyx_v_self->use_sent_id = 1; + } + __pyx_L5:; + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_WriteUnraisable("_cdec_sa.DataArray.read_handle", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_py_word); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":109 + * self.use_sent_id = True + * + * cdef void write_handle(self, FILE* f): # <<<<<<<<<<<<<< + * cdef int word_len + * cdef int num_words + */ + +static void __pyx_f_8_cdec_sa_9DataArray_write_handle(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, FILE *__pyx_v_f) { + int __pyx_v_word_len; + int __pyx_v_num_words; + char *__pyx_v_c_word; + PyObject *__pyx_v_word = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *(*__pyx_t_4)(PyObject *); + char *__pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_handle", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":113 + * cdef int num_words + * cdef char* c_word + * self.data.write_handle(f) # <<<<<<<<<<<<<< + * self.sent_index.write_handle(f) + * self.sent_id.write_handle(f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->data->__pyx_vtab)->write_handle(__pyx_v_self->data, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":114 + * cdef char* c_word + * self.data.write_handle(f) + * self.sent_index.write_handle(f) # <<<<<<<<<<<<<< + * self.sent_id.write_handle(f) + * num_words = len(self.id2word) - 2 + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->sent_index->__pyx_vtab)->write_handle(__pyx_v_self->sent_index, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":115 + * self.data.write_handle(f) + * self.sent_index.write_handle(f) + * self.sent_id.write_handle(f) # <<<<<<<<<<<<<< + * num_words = len(self.id2word) - 2 + * fwrite(&(num_words), sizeof(int), 1, f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->sent_id->__pyx_vtab)->write_handle(__pyx_v_self->sent_id, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":116 + * self.sent_index.write_handle(f) + * self.sent_id.write_handle(f) + * num_words = len(self.id2word) - 2 # <<<<<<<<<<<<<< + * fwrite(&(num_words), sizeof(int), 1, f) + * for word in self.id2word[2:]: + */ + __pyx_t_1 = __pyx_v_self->id2word; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_num_words = (__pyx_t_2 - 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":117 + * self.sent_id.write_handle(f) + * num_words = len(self.id2word) - 2 + * fwrite(&(num_words), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * for word in self.id2word[2:]: + * c_word = word + */ + fwrite((&__pyx_v_num_words), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":118 + * num_words = len(self.id2word) - 2 + * fwrite(&(num_words), sizeof(int), 1, f) + * for word in self.id2word[2:]: # <<<<<<<<<<<<<< + * c_word = word + * word_len = strlen(c_word) + 1 + */ + __pyx_t_1 = __Pyx_PySequence_GetSlice(__pyx_v_self->id2word, 2, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_3)) break; + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; + } else { + __pyx_t_1 = __pyx_t_4(__pyx_t_3); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF(__pyx_v_word); + __pyx_v_word = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":119 + * fwrite(&(num_words), sizeof(int), 1, f) + * for word in self.id2word[2:]: + * c_word = word # <<<<<<<<<<<<<< + * word_len = strlen(c_word) + 1 + * fwrite(&(word_len), sizeof(int), 1, f) + */ + __pyx_t_5 = PyBytes_AsString(__pyx_v_word); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_c_word = __pyx_t_5; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":120 + * for word in self.id2word[2:]: + * c_word = word + * word_len = strlen(c_word) + 1 # <<<<<<<<<<<<<< + * fwrite(&(word_len), sizeof(int), 1, f) + * fwrite(c_word, sizeof(char), word_len, f) + */ + __pyx_v_word_len = (strlen(__pyx_v_c_word) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":121 + * c_word = word + * word_len = strlen(c_word) + 1 + * fwrite(&(word_len), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fwrite(c_word, sizeof(char), word_len, f) + * + */ + fwrite((&__pyx_v_word_len), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":122 + * word_len = strlen(c_word) + 1 + * fwrite(&(word_len), sizeof(int), 1, f) + * fwrite(c_word, sizeof(char), word_len, f) # <<<<<<<<<<<<<< + * + * def write_binary(self, char* filename): + */ + fwrite(__pyx_v_c_word, (sizeof(char)), __pyx_v_word_len, __pyx_v_f); + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_WriteUnraisable("_cdec_sa.DataArray.write_handle", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_word); + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_21write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_21write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.DataArray.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_20write_binary(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":124 + * fwrite(c_word, sizeof(char), word_len, f) + * + * def write_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "w") + */ + +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_20write_binary(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":126 + * def write_binary(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "w") # <<<<<<<<<<<<<< + * self.write_handle(f) + * fclose(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":127 + * cdef FILE* f + * f = fopen(filename, "w") + * self.write_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + ((struct __pyx_vtabstruct_8_cdec_sa_DataArray *)__pyx_v_self->__pyx_vtab)->write_handle(__pyx_v_self, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":128 + * f = fopen(filename, "w") + * self.write_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + * + * def write_enhanced_handle(self, f): + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_23write_enhanced_handle(PyObject *__pyx_v_self, PyObject *__pyx_v_f); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_23write_enhanced_handle(PyObject *__pyx_v_self, PyObject *__pyx_v_f) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_enhanced_handle (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_22write_enhanced_handle(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_f)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":130 + * fclose(f) + * + * def write_enhanced_handle(self, f): # <<<<<<<<<<<<<< + * for i in self.data: + * f.write("%d " %i) + */ + +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_22write_enhanced_handle(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_f) { + PyObject *__pyx_v_i = NULL; + PyObject *__pyx_v_word = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_enhanced_handle", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":131 + * + * def write_enhanced_handle(self, f): + * for i in self.data: # <<<<<<<<<<<<<< + * f.write("%d " %i) + * f.write("\n") + */ + if (PyList_CheckExact(((PyObject *)__pyx_v_self->data)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->data))) { + __pyx_t_1 = ((PyObject *)__pyx_v_self->data); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self->data)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":132 + * def write_enhanced_handle(self, f): + * for i in self.data: + * f.write("%d " %i) # <<<<<<<<<<<<<< + * f.write("\n") + * for i in self.sent_index: + */ + __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":133 + * for i in self.data: + * f.write("%d " %i) + * f.write("\n") # <<<<<<<<<<<<<< + * for i in self.sent_index: + * f.write("%d " %i) + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_19), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":134 + * f.write("%d " %i) + * f.write("\n") + * for i in self.sent_index: # <<<<<<<<<<<<<< + * f.write("%d " %i) + * f.write("\n") + */ + if (PyList_CheckExact(((PyObject *)__pyx_v_self->sent_index)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->sent_index))) { + __pyx_t_5 = ((PyObject *)__pyx_v_self->sent_index); __Pyx_INCREF(__pyx_t_5); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_5 = PyObject_GetIter(((PyObject *)__pyx_v_self->sent_index)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = Py_TYPE(__pyx_t_5)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_5)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_5)) break; + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_5)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_5)) break; + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; + } else { + __pyx_t_1 = __pyx_t_3(__pyx_t_5); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":135 + * f.write("\n") + * for i in self.sent_index: + * f.write("%d " %i) # <<<<<<<<<<<<<< + * f.write("\n") + * for i in self.sent_id: + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_6)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_6)); + __pyx_t_6 = 0; + __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":136 + * for i in self.sent_index: + * f.write("%d " %i) + * f.write("\n") # <<<<<<<<<<<<<< + * for i in self.sent_id: + * f.write("%d " %i) + */ + __pyx_t_5 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":137 + * f.write("%d " %i) + * f.write("\n") + * for i in self.sent_id: # <<<<<<<<<<<<<< + * f.write("%d " %i) + * f.write("\n") + */ + if (PyList_CheckExact(((PyObject *)__pyx_v_self->sent_id)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->sent_id))) { + __pyx_t_6 = ((PyObject *)__pyx_v_self->sent_id); __Pyx_INCREF(__pyx_t_6); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_6 = PyObject_GetIter(((PyObject *)__pyx_v_self->sent_id)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = Py_TYPE(__pyx_t_6)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_6)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_6)) break; + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_6)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_6)) break; + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + } else { + __pyx_t_5 = __pyx_t_3(__pyx_t_6); + if (unlikely(!__pyx_t_5)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_5); + } + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":138 + * f.write("\n") + * for i in self.sent_id: + * f.write("%d " %i) # <<<<<<<<<<<<<< + * f.write("\n") + * for word in self.id2word: + */ + __pyx_t_5 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":139 + * for i in self.sent_id: + * f.write("%d " %i) + * f.write("\n") # <<<<<<<<<<<<<< + * for word in self.id2word: + * f.write("%s %d " % (word, self.word2id[word])) + */ + __pyx_t_6 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_k_tuple_21), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":140 + * f.write("%d " %i) + * f.write("\n") + * for word in self.id2word: # <<<<<<<<<<<<<< + * f.write("%s %d " % (word, self.word2id[word])) + * f.write("\n") + */ + if (PyList_CheckExact(__pyx_v_self->id2word) || PyTuple_CheckExact(__pyx_v_self->id2word)) { + __pyx_t_4 = __pyx_v_self->id2word; __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_self->id2word); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_4)) break; + __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_6); __pyx_t_2++; + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_6); __pyx_t_2++; + } else { + __pyx_t_6 = __pyx_t_3(__pyx_t_4); + if (unlikely(!__pyx_t_6)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_6); + } + __Pyx_XDECREF(__pyx_v_word); + __pyx_v_word = __pyx_t_6; + __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":141 + * f.write("\n") + * for word in self.id2word: + * f.write("%s %d " % (word, self.word2id[word])) # <<<<<<<<<<<<<< + * f.write("\n") + * + */ + __pyx_t_6 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_1 = PyObject_GetItem(__pyx_v_self->word2id, __pyx_v_word); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_word); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_word); + __Pyx_GIVEREF(__pyx_v_word); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_22), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":142 + * for word in self.id2word: + * f.write("%s %d " % (word, self.word2id[word])) + * f.write("\n") # <<<<<<<<<<<<<< + * + * def write_enhanced(self, char* filename): + */ + __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_23), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_cdec_sa.DataArray.write_enhanced_handle", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_word); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_25write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9DataArray_25write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_enhanced (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.DataArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_24write_enhanced(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":144 + * f.write("\n") + * + * def write_enhanced(self, char* filename): # <<<<<<<<<<<<<< + * with open(filename, "w") as f: + * self.write_enhanced_handle(self, f) + */ + +static PyObject *__pyx_pf_8_cdec_sa_9DataArray_24write_enhanced(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_enhanced", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":145 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * self.write_enhanced_handle(self, f) + */ + /*with:*/ { + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_f = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":146 + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: + * self.write_enhanced_handle(self, f) # <<<<<<<<<<<<<< + */ + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s_24); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + __Pyx_INCREF(__pyx_v_f); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_f); + __Pyx_GIVEREF(__pyx_v_f); + __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":145 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * self.write_enhanced_handle(self, f) + */ + /*except:*/ { + __Pyx_AddTraceback("_cdec_sa.DataArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_1, &__pyx_t_4) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_10 = PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_10); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_11 = (!__pyx_t_9); + if (__pyx_t_11) { + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_ErrRestore(__pyx_t_2, __pyx_t_1, __pyx_t_4); + __pyx_t_2 = 0; __pyx_t_1 = 0; __pyx_t_4 = 0; + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L18; + } + __pyx_L18:; + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_25, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L19; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L19:; + } + + __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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_cdec_sa.DataArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":12 + * cdef IntList sent_index + * + * cdef int link(self, int i, int j): # <<<<<<<<<<<<<< + * """Integerizes an alignment link pair""" + * return i*65536 + j + */ + +static int __pyx_f_8_cdec_sa_9Alignment_link(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, int __pyx_v_i, int __pyx_v_j) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("link", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":14 + * cdef int link(self, int i, int j): + * """Integerizes an alignment link pair""" + * return i*65536 + j # <<<<<<<<<<<<<< + * + * def unlink(self, link): + */ + __pyx_r = ((__pyx_v_i * 65536) + __pyx_v_j); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9Alignment_1unlink(PyObject *__pyx_v_self, PyObject *__pyx_v_link); /*proto*/ +static char __pyx_doc_8_cdec_sa_9Alignment_unlink[] = "De-integerizes an alignment link pair"; +static PyObject *__pyx_pw_8_cdec_sa_9Alignment_1unlink(PyObject *__pyx_v_self, PyObject *__pyx_v_link) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("unlink (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9Alignment_unlink(((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_v_self), ((PyObject *)__pyx_v_link)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":16 + * return i*65536 + j + * + * def unlink(self, link): # <<<<<<<<<<<<<< + * """De-integerizes an alignment link pair""" + * return (link/65536, link%65536) + */ + +static PyObject *__pyx_pf_8_cdec_sa_9Alignment_unlink(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_link) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("unlink", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":18 + * def unlink(self, link): + * """De-integerizes an alignment link pair""" + * return (link/65536, link%65536) # <<<<<<<<<<<<<< + * + * cdef _unlink(self, int link, int* f, int* e): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_v_link, __pyx_int_65536); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Remainder(__pyx_v_link, __pyx_int_65536); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_r = ((PyObject *)__pyx_t_3); + __pyx_t_3 = 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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.Alignment.unlink", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":20 + * return (link/65536, link%65536) + * + * cdef _unlink(self, int link, int* f, int* e): # <<<<<<<<<<<<<< + * f[0] = link/65536 + * e[0] = link%65536 + */ + +static PyObject *__pyx_f_8_cdec_sa_9Alignment__unlink(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, int __pyx_v_link, int *__pyx_v_f, int *__pyx_v_e) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_unlink", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":21 + * + * cdef _unlink(self, int link, int* f, int* e): + * f[0] = link/65536 # <<<<<<<<<<<<<< + * e[0] = link%65536 + * + */ + (__pyx_v_f[0]) = __Pyx_div_long(__pyx_v_link, 65536); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":22 + * cdef _unlink(self, int link, int* f, int* e): + * f[0] = link/65536 + * e[0] = link%65536 # <<<<<<<<<<<<<< + * + * def get_sent_links(self, int sent_id): + */ + (__pyx_v_e[0]) = __Pyx_mod_long(__pyx_v_link, 65536); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9Alignment_3get_sent_links(PyObject *__pyx_v_self, PyObject *__pyx_arg_sent_id); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9Alignment_3get_sent_links(PyObject *__pyx_v_self, PyObject *__pyx_arg_sent_id) { + int __pyx_v_sent_id; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_sent_links (wrapper)", 0); + assert(__pyx_arg_sent_id); { + __pyx_v_sent_id = __Pyx_PyInt_AsInt(__pyx_arg_sent_id); if (unlikely((__pyx_v_sent_id == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.Alignment.get_sent_links", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_9Alignment_2get_sent_links(((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_v_self), ((int)__pyx_v_sent_id)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":24 + * e[0] = link%65536 + * + * def get_sent_links(self, int sent_id): # <<<<<<<<<<<<<< + * cdef IntList sent_links + * cdef int* arr + */ + +static PyObject *__pyx_pf_8_cdec_sa_9Alignment_2get_sent_links(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, int __pyx_v_sent_id) { + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_sent_links = 0; + int *__pyx_v_arr; + int __pyx_v_arr_len; + 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("get_sent_links", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":28 + * cdef int* arr + * cdef int arr_len + * sent_links = IntList() # <<<<<<<<<<<<<< + * arr = self._get_sent_links(sent_id, &arr_len) + * sent_links._extend_arr(arr, arr_len*2) + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sent_links = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":29 + * cdef int arr_len + * sent_links = IntList() + * arr = self._get_sent_links(sent_id, &arr_len) # <<<<<<<<<<<<<< + * sent_links._extend_arr(arr, arr_len*2) + * free(arr) + */ + __pyx_v_arr = ((struct __pyx_vtabstruct_8_cdec_sa_Alignment *)__pyx_v_self->__pyx_vtab)->_get_sent_links(__pyx_v_self, __pyx_v_sent_id, (&__pyx_v_arr_len)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":30 + * sent_links = IntList() + * arr = self._get_sent_links(sent_id, &arr_len) + * sent_links._extend_arr(arr, arr_len*2) # <<<<<<<<<<<<<< + * free(arr) + * return sent_links + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_sent_links->__pyx_vtab)->_extend_arr(__pyx_v_sent_links, __pyx_v_arr, (__pyx_v_arr_len * 2)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":31 + * arr = self._get_sent_links(sent_id, &arr_len) + * sent_links._extend_arr(arr, arr_len*2) + * free(arr) # <<<<<<<<<<<<<< + * return sent_links + * + */ + free(__pyx_v_arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":32 + * sent_links._extend_arr(arr, arr_len*2) + * free(arr) + * return sent_links # <<<<<<<<<<<<<< + * + * cdef int* _get_sent_links(self, int sent_id, int* num_links): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_sent_links)); + __pyx_r = ((PyObject *)__pyx_v_sent_links); + 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_sa.Alignment.get_sent_links", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_sent_links); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":34 + * return sent_links + * + * cdef int* _get_sent_links(self, int sent_id, int* num_links): # <<<<<<<<<<<<<< + * cdef int* sent_links + * cdef int i, start, end + */ + +static int *__pyx_f_8_cdec_sa_9Alignment__get_sent_links(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, int __pyx_v_sent_id, int *__pyx_v_num_links) { + int *__pyx_v_sent_links; + int __pyx_v_i; + int __pyx_v_start; + int __pyx_v_end; + int *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_get_sent_links", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":37 + * cdef int* sent_links + * cdef int i, start, end + * start = self.sent_index.arr[sent_id] # <<<<<<<<<<<<<< + * end = self.sent_index.arr[sent_id+1] + * num_links[0] = end - start + */ + __pyx_v_start = (__pyx_v_self->sent_index->arr[__pyx_v_sent_id]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":38 + * cdef int i, start, end + * start = self.sent_index.arr[sent_id] + * end = self.sent_index.arr[sent_id+1] # <<<<<<<<<<<<<< + * num_links[0] = end - start + * sent_links = malloc(2*num_links[0]*sizeof(int)) + */ + __pyx_v_end = (__pyx_v_self->sent_index->arr[(__pyx_v_sent_id + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":39 + * start = self.sent_index.arr[sent_id] + * end = self.sent_index.arr[sent_id+1] + * num_links[0] = end - start # <<<<<<<<<<<<<< + * sent_links = malloc(2*num_links[0]*sizeof(int)) + * for i from 0 <= i < num_links[0]: + */ + (__pyx_v_num_links[0]) = (__pyx_v_end - __pyx_v_start); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":40 + * end = self.sent_index.arr[sent_id+1] + * num_links[0] = end - start + * sent_links = malloc(2*num_links[0]*sizeof(int)) # <<<<<<<<<<<<<< + * for i from 0 <= i < num_links[0]: + * self._unlink(self.links.arr[start + i], sent_links + (2*i), sent_links + (2*i) + 1) + */ + __pyx_v_sent_links = ((int *)malloc(((2 * (__pyx_v_num_links[0])) * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":41 + * num_links[0] = end - start + * sent_links = malloc(2*num_links[0]*sizeof(int)) + * for i from 0 <= i < num_links[0]: # <<<<<<<<<<<<<< + * self._unlink(self.links.arr[start + i], sent_links + (2*i), sent_links + (2*i) + 1) + * return sent_links + */ + __pyx_t_1 = (__pyx_v_num_links[0]); + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":42 + * sent_links = malloc(2*num_links[0]*sizeof(int)) + * for i from 0 <= i < num_links[0]: + * self._unlink(self.links.arr[start + i], sent_links + (2*i), sent_links + (2*i) + 1) # <<<<<<<<<<<<<< + * return sent_links + * + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_Alignment *)__pyx_v_self->__pyx_vtab)->_unlink(__pyx_v_self, (__pyx_v_self->links->arr[(__pyx_v_start + __pyx_v_i)]), (__pyx_v_sent_links + (2 * __pyx_v_i)), ((__pyx_v_sent_links + (2 * __pyx_v_i)) + 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":43 + * for i from 0 <= i < num_links[0]: + * self._unlink(self.links.arr[start + i], sent_links + (2*i), sent_links + (2*i) + 1) + * return sent_links # <<<<<<<<<<<<<< + * + * def __cinit__(self, from_binary=None, from_text=None): + */ + __pyx_r = __pyx_v_sent_links; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_WriteUnraisable("_cdec_sa.Alignment._get_sent_links", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_9Alignment_5__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_9Alignment_5__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_from_binary = 0; + PyObject *__pyx_v_from_text = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__from_binary,&__pyx_n_s__from_text,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":45 + * return sent_links + * + * def __cinit__(self, from_binary=None, from_text=None): # <<<<<<<<<<<<<< + * self.links = IntList(1000,1000) + * self.sent_index = IntList(1000,1000) + */ + values[0] = ((PyObject *)Py_None); + values[1] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_binary); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_text); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_from_binary = values[0]; + __pyx_v_from_text = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.Alignment.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_9Alignment_4__cinit__(((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_v_self), __pyx_v_from_binary, __pyx_v_from_text); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_9Alignment_4__cinit__(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":46 + * + * def __cinit__(self, from_binary=None, from_text=None): + * self.links = IntList(1000,1000) # <<<<<<<<<<<<<< + * self.sent_index = IntList(1000,1000) + * if from_binary: + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_k_tuple_26), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->links); + __Pyx_DECREF(((PyObject *)__pyx_v_self->links)); + __pyx_v_self->links = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":47 + * def __cinit__(self, from_binary=None, from_text=None): + * self.links = IntList(1000,1000) + * self.sent_index = IntList(1000,1000) # <<<<<<<<<<<<<< + * if from_binary: + * self.read_binary(from_binary) + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_k_tuple_27), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->sent_index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->sent_index)); + __pyx_v_self->sent_index = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":48 + * self.links = IntList(1000,1000) + * self.sent_index = IntList(1000,1000) + * if from_binary: # <<<<<<<<<<<<<< + * self.read_binary(from_binary) + * elif from_text: + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_binary); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":49 + * self.sent_index = IntList(1000,1000) + * if from_binary: + * self.read_binary(from_binary) # <<<<<<<<<<<<<< + * elif from_text: + * self.read_text(from_text) + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_binary); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_from_binary); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_binary); + __Pyx_GIVEREF(__pyx_v_from_binary); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":50 + * if from_binary: + * self.read_binary(from_binary) + * elif from_text: # <<<<<<<<<<<<<< + * self.read_text(from_text) + * + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_text); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":51 + * self.read_binary(from_binary) + * elif from_text: + * self.read_text(from_text) # <<<<<<<<<<<<<< + * + * def read_text(self, char* filename): + */ + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_text); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_from_text); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_text); + __Pyx_GIVEREF(__pyx_v_from_text); + __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec_sa.Alignment.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9Alignment_7read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9Alignment_7read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_text (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.Alignment.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_9Alignment_6read_text(((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":53 + * self.read_text(from_text) + * + * def read_text(self, char* filename): # <<<<<<<<<<<<<< + * with gzip_or_text(filename) as f: + * for line in f: + */ + +static PyObject *__pyx_pf_8_cdec_sa_9Alignment_6read_text(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_v_line = NULL; + PyObject *__pyx_v_pairs = NULL; + PyObject *__pyx_v_pair = NULL; + PyObject *__pyx_v_i = NULL; + PyObject *__pyx_v_j = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + Py_ssize_t __pyx_t_10; + PyObject *(*__pyx_t_11)(PyObject *); + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + PyObject *(*__pyx_t_15)(PyObject *); + int __pyx_t_16; + int __pyx_t_17; + int __pyx_t_18; + PyObject *__pyx_t_19 = NULL; + int __pyx_t_20; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_text", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":54 + * + * def read_text(self, char* filename): + * with gzip_or_text(filename) as f: # <<<<<<<<<<<<<< + * for line in f: + * self.sent_index.append(len(self.links)) + */ + /*with:*/ { + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__gzip_or_text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __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[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_1); + __pyx_v_f = __pyx_t_1; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":55 + * def read_text(self, char* filename): + * with gzip_or_text(filename) as f: + * for line in f: # <<<<<<<<<<<<<< + * self.sent_index.append(len(self.links)) + * pairs = line.split() + */ + if (PyList_CheckExact(__pyx_v_f) || PyTuple_CheckExact(__pyx_v_f)) { + __pyx_t_1 = __pyx_v_f; __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else { + __pyx_t_2 = __pyx_t_9(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF(__pyx_v_line); + __pyx_v_line = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":56 + * with gzip_or_text(filename) as f: + * for line in f: + * self.sent_index.append(len(self.links)) # <<<<<<<<<<<<<< + * pairs = line.split() + * for pair in pairs: + */ + __pyx_t_2 = ((PyObject *)__pyx_v_self->links); + __Pyx_INCREF(__pyx_t_2); + __pyx_t_10 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_10); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_index), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":57 + * for line in f: + * self.sent_index.append(len(self.links)) + * pairs = line.split() # <<<<<<<<<<<<<< + * for pair in pairs: + * (i, j) = map(int, pair.split('-')) + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_v_pairs); + __pyx_v_pairs = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":58 + * self.sent_index.append(len(self.links)) + * pairs = line.split() + * for pair in pairs: # <<<<<<<<<<<<<< + * (i, j) = map(int, pair.split('-')) + * self.links.append(self.link(i, j)) + */ + if (PyList_CheckExact(__pyx_v_pairs) || PyTuple_CheckExact(__pyx_v_pairs)) { + __pyx_t_2 = __pyx_v_pairs; __Pyx_INCREF(__pyx_t_2); __pyx_t_10 = 0; + __pyx_t_11 = NULL; + } else { + __pyx_t_10 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_pairs); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_11 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_3); __pyx_t_10++; + } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_3); __pyx_t_10++; + } else { + __pyx_t_3 = __pyx_t_11(__pyx_t_2); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_pair); + __pyx_v_pair = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":59 + * pairs = line.split() + * for pair in pairs: + * (i, j) = map(int, pair.split('-')) # <<<<<<<<<<<<<< + * self.links.append(self.link(i, j)) + * self.sent_index.append(len(self.links)) + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_v_pair, __pyx_n_s__split); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_29), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(((PyObject *)((PyObject*)(&PyInt_Type)))); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)((PyObject*)(&PyInt_Type)))); + __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyInt_Type)))); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_12); + __Pyx_GIVEREF(__pyx_t_12); + __pyx_t_12 = 0; + __pyx_t_12 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_12))) || (PyList_CheckExact(__pyx_t_12))) { + PyObject* sequence = __pyx_t_12; + if (likely(PyTuple_CheckExact(sequence))) { + 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[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_13 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_13 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_14 = PyObject_GetIter(__pyx_t_12); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_3)) goto __pyx_L20_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + 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[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_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[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_L21_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_3; + __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_v_j); + __pyx_v_j = __pyx_t_13; + __pyx_t_13 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":60 + * for pair in pairs: + * (i, j) = map(int, pair.split('-')) + * self.links.append(self.link(i, j)) # <<<<<<<<<<<<<< + * self.sent_index.append(len(self.links)) + * + */ + __pyx_t_16 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_16 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_17 = __Pyx_PyInt_AsInt(__pyx_v_j); if (unlikely((__pyx_t_17 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_12 = PyInt_FromLong(((struct __pyx_vtabstruct_8_cdec_sa_Alignment *)__pyx_v_self->__pyx_vtab)->link(__pyx_v_self, __pyx_t_16, __pyx_t_17)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->links), __pyx_t_12); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":61 + * (i, j) = map(int, pair.split('-')) + * self.links.append(self.link(i, j)) + * self.sent_index.append(len(self.links)) # <<<<<<<<<<<<<< + * + * def read_binary(self, char* filename): + */ + __pyx_t_1 = ((PyObject *)__pyx_v_self->links); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_8 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_index), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":54 + * + * def read_text(self, char* filename): + * with gzip_or_text(filename) as f: # <<<<<<<<<<<<<< + * for line in f: + * self.sent_index.append(len(self.links)) + */ + /*except:*/ { + __Pyx_AddTraceback("_cdec_sa.Alignment.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_1, &__pyx_t_13) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_12 = PyTuple_New(3); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_13); + PyTuple_SET_ITEM(__pyx_t_12, 2, __pyx_t_13); + __Pyx_GIVEREF(__pyx_t_13); + __pyx_t_19 = PyObject_Call(__pyx_t_4, __pyx_t_12, NULL); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_19); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(__pyx_t_18 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_20 = (!__pyx_t_18); + if (__pyx_t_20) { + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_13); + __Pyx_ErrRestore(__pyx_t_2, __pyx_t_1, __pyx_t_13); + __pyx_t_2 = 0; __pyx_t_1 = 0; __pyx_t_13 = 0; + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L24; + } + __pyx_L24:; + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_4) { + __pyx_t_7 = PyObject_Call(__pyx_t_4, __pyx_k_tuple_30, NULL); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_20 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_20 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L25; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L1_error; + __pyx_L25:; + } + + __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_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_AddTraceback("_cdec_sa.Alignment.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_line); + __Pyx_XDECREF(__pyx_v_pairs); + __Pyx_XDECREF(__pyx_v_pair); + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_j); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9Alignment_9read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9Alignment_9read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.Alignment.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_9Alignment_8read_binary(((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":63 + * self.sent_index.append(len(self.links)) + * + * def read_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "r") + */ + +static PyObject *__pyx_pf_8_cdec_sa_9Alignment_8read_binary(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":65 + * def read_binary(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "r") # <<<<<<<<<<<<<< + * self.links.read_handle(f) + * self.sent_index.read_handle(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":66 + * cdef FILE* f + * f = fopen(filename, "r") + * self.links.read_handle(f) # <<<<<<<<<<<<<< + * self.sent_index.read_handle(f) + * fclose(f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->links->__pyx_vtab)->read_handle(__pyx_v_self->links, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":67 + * f = fopen(filename, "r") + * self.links.read_handle(f) + * self.sent_index.read_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->sent_index->__pyx_vtab)->read_handle(__pyx_v_self->sent_index, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":68 + * self.links.read_handle(f) + * self.sent_index.read_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + * + * def write_text(self, char* filename): + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9Alignment_11write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9Alignment_11write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_text (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.Alignment.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_9Alignment_10write_text(((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":70 + * fclose(f) + * + * def write_text(self, char* filename): # <<<<<<<<<<<<<< + * with open(filename, "w") as f: + * sent_num = 0 + */ + +static PyObject *__pyx_pf_8_cdec_sa_9Alignment_10write_text(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_v_sent_num = NULL; + PyObject *__pyx_v_i = NULL; + PyObject *__pyx_v_link = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + int __pyx_t_15; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_text", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":71 + * + * def write_text(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * sent_num = 0 + * for i, link in enumerate(self.links): + */ + /*with:*/ { + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_f = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":72 + * def write_text(self, char* filename): + * with open(filename, "w") as f: + * sent_num = 0 # <<<<<<<<<<<<<< + * for i, link in enumerate(self.links): + * while i >= self.sent_index[sent_num]: + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_sent_num = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":73 + * with open(filename, "w") as f: + * sent_num = 0 + * for i, link in enumerate(self.links): # <<<<<<<<<<<<<< + * while i >= self.sent_index[sent_num]: + * f.write("\n") + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_4 = __pyx_int_0; + if (PyList_CheckExact(((PyObject *)__pyx_v_self->links)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->links))) { + __pyx_t_1 = ((PyObject *)__pyx_v_self->links); __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self->links)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else { + __pyx_t_2 = __pyx_t_9(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF(__pyx_v_link); + __pyx_v_link = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_4; + __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); + __pyx_t_4 = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":74 + * sent_num = 0 + * for i, link in enumerate(self.links): + * while i >= self.sent_index[sent_num]: # <<<<<<<<<<<<<< + * f.write("\n") + * sent_num = sent_num + 1 + */ + while (1) { + __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_self->sent_index), __pyx_v_sent_num); if (!__pyx_t_2) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = PyObject_RichCompare(__pyx_v_i, __pyx_t_2, Py_GE); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (!__pyx_t_11) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":75 + * for i, link in enumerate(self.links): + * while i >= self.sent_index[sent_num]: + * f.write("\n") # <<<<<<<<<<<<<< + * sent_num = sent_num + 1 + * f.write("%d-%d " % self.unlink(link)) + */ + __pyx_t_10 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_k_tuple_31), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":76 + * while i >= self.sent_index[sent_num]: + * f.write("\n") + * sent_num = sent_num + 1 # <<<<<<<<<<<<<< + * f.write("%d-%d " % self.unlink(link)) + * f.write("\n") + */ + __pyx_t_2 = PyNumber_Add(__pyx_v_sent_num, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_v_sent_num); + __pyx_v_sent_num = __pyx_t_2; + __pyx_t_2 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":77 + * f.write("\n") + * sent_num = sent_num + 1 + * f.write("%d-%d " % self.unlink(link)) # <<<<<<<<<<<<<< + * f.write("\n") + * + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__unlink); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_INCREF(__pyx_v_link); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_v_link); + __Pyx_GIVEREF(__pyx_v_link); + __pyx_t_13 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __pyx_t_12 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_32), __pyx_t_13); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_12)); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_13); + PyTuple_SET_ITEM(__pyx_t_13, 0, ((PyObject *)__pyx_t_12)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_12)); + __pyx_t_12 = 0; + __pyx_t_12 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":78 + * sent_num = sent_num + 1 + * f.write("%d-%d " % self.unlink(link)) + * f.write("\n") # <<<<<<<<<<<<<< + * + * def write_binary(self, char* filename): + */ + __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_33), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":71 + * + * def write_text(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * sent_num = 0 + * for i, link in enumerate(self.links): + */ + /*except:*/ { + __Pyx_AddTraceback("_cdec_sa.Alignment.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_4, &__pyx_t_12) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = PyTuple_New(3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_12); + __Pyx_GIVEREF(__pyx_t_12); + __pyx_t_14 = PyObject_Call(__pyx_t_3, __pyx_t_13, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_14); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_15 = (!__pyx_t_11); + if (__pyx_t_15) { + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_ErrRestore(__pyx_t_1, __pyx_t_4, __pyx_t_12); + __pyx_t_1 = 0; __pyx_t_4 = 0; __pyx_t_12 = 0; + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L22; + } + __pyx_L22:; + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_34, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_15 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L23; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L23:; + } + + __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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_AddTraceback("_cdec_sa.Alignment.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_sent_num); + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_link); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9Alignment_13write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9Alignment_13write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.Alignment.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_9Alignment_12write_binary(((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":80 + * f.write("\n") + * + * def write_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "w") + */ + +static PyObject *__pyx_pf_8_cdec_sa_9Alignment_12write_binary(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":82 + * def write_binary(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "w") # <<<<<<<<<<<<<< + * self.links.write_handle(f) + * self.sent_index.write_handle(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":83 + * cdef FILE* f + * f = fopen(filename, "w") + * self.links.write_handle(f) # <<<<<<<<<<<<<< + * self.sent_index.write_handle(f) + * fclose(f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->links->__pyx_vtab)->write_handle(__pyx_v_self->links, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":84 + * f = fopen(filename, "w") + * self.links.write_handle(f) + * self.sent_index.write_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->sent_index->__pyx_vtab)->write_handle(__pyx_v_self->sent_index, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":85 + * self.links.write_handle(f) + * self.sent_index.write_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + * + * def write_enhanced(self, char* filename): + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9Alignment_15write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9Alignment_15write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_enhanced (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.Alignment.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_9Alignment_14write_enhanced(((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":87 + * fclose(f) + * + * def write_enhanced(self, char* filename): # <<<<<<<<<<<<<< + * with open(filename, "w") as f: + * sent_num = 1 + */ + +static PyObject *__pyx_pf_8_cdec_sa_9Alignment_14write_enhanced(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_v_f = NULL; + CYTHON_UNUSED long __pyx_v_sent_num; + PyObject *__pyx_v_link = NULL; + PyObject *__pyx_v_i = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + PyObject *__pyx_t_12 = NULL; + int __pyx_t_13; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_enhanced", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":88 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * sent_num = 1 + * for link in self.links: + */ + /*with:*/ { + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_f = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":89 + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: + * sent_num = 1 # <<<<<<<<<<<<<< + * for link in self.links: + * f.write("%d " % link) + */ + __pyx_v_sent_num = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":90 + * with open(filename, "w") as f: + * sent_num = 1 + * for link in self.links: # <<<<<<<<<<<<<< + * f.write("%d " % link) + * f.write("\n") + */ + if (PyList_CheckExact(((PyObject *)__pyx_v_self->links)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->links))) { + __pyx_t_4 = ((PyObject *)__pyx_v_self->links); __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(((PyObject *)__pyx_v_self->links)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; + } else { + __pyx_t_1 = __pyx_t_9(__pyx_t_4); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF(__pyx_v_link); + __pyx_v_link = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":91 + * sent_num = 1 + * for link in self.links: + * f.write("%d " % link) # <<<<<<<<<<<<<< + * f.write("\n") + * for i in self.sent_index: + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_link); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":92 + * for link in self.links: + * f.write("%d " % link) + * f.write("\n") # <<<<<<<<<<<<<< + * for i in self.sent_index: + * f.write("%d " % i) + */ + __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_35), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":93 + * f.write("%d " % link) + * f.write("\n") + * for i in self.sent_index: # <<<<<<<<<<<<<< + * f.write("%d " % i) + * f.write("\n") + */ + if (PyList_CheckExact(((PyObject *)__pyx_v_self->sent_index)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->sent_index))) { + __pyx_t_2 = ((PyObject *)__pyx_v_self->sent_index); __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(((PyObject *)__pyx_v_self->sent_index)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_4); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_4); __pyx_t_8++; + } else { + __pyx_t_4 = __pyx_t_9(__pyx_t_2); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":94 + * f.write("\n") + * for i in self.sent_index: + * f.write("%d " % i) # <<<<<<<<<<<<<< + * f.write("\n") + * + */ + __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_10)); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_10)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); + __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":95 + * for i in self.sent_index: + * f.write("%d " % i) + * f.write("\n") # <<<<<<<<<<<<<< + * + * def alignment(self, i): + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_36), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":88 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * sent_num = 1 + * for link in self.links: + */ + /*except:*/ { + __Pyx_AddTraceback("_cdec_sa.Alignment.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_10, &__pyx_t_2, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_12 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_13 = (!__pyx_t_11); + if (__pyx_t_13) { + __Pyx_GIVEREF(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_ErrRestore(__pyx_t_10, __pyx_t_2, __pyx_t_1); + __pyx_t_10 = 0; __pyx_t_2 = 0; __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L22; + } + __pyx_L22:; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_37, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L23; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L23:; + } + + __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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("_cdec_sa.Alignment.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_link); + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9Alignment_17alignment(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static char __pyx_doc_8_cdec_sa_9Alignment_16alignment[] = "Return all (e,f) pairs for sentence i"; +static PyObject *__pyx_pw_8_cdec_sa_9Alignment_17alignment(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("alignment (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9Alignment_16alignment(((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":97 + * f.write("\n") + * + * def alignment(self, i): # <<<<<<<<<<<<<< + * """Return all (e,f) pairs for sentence i""" + * cdef int j, start, end + */ + +static PyObject *__pyx_pf_8_cdec_sa_9Alignment_16alignment(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_i) { + int __pyx_v_j; + int __pyx_v_start; + int __pyx_v_end; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("alignment", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":100 + * """Return all (e,f) pairs for sentence i""" + * cdef int j, start, end + * result = [] # <<<<<<<<<<<<<< + * start = self.sent_index.arr[i] + * end = self.sent_index.arr[i+1] + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":101 + * cdef int j, start, end + * result = [] + * start = self.sent_index.arr[i] # <<<<<<<<<<<<<< + * end = self.sent_index.arr[i+1] + * for j from start <= j < end: + */ + __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_start = (__pyx_v_self->sent_index->arr[__pyx_t_2]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":102 + * result = [] + * start = self.sent_index.arr[i] + * end = self.sent_index.arr[i+1] # <<<<<<<<<<<<<< + * for j from start <= j < end: + * result.append(self.unlink(self.links.arr[j])) + */ + __pyx_t_1 = PyNumber_Add(__pyx_v_i, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_end = (__pyx_v_self->sent_index->arr[__pyx_t_2]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":103 + * start = self.sent_index.arr[i] + * end = self.sent_index.arr[i+1] + * for j from start <= j < end: # <<<<<<<<<<<<<< + * result.append(self.unlink(self.links.arr[j])) + * return result + */ + __pyx_t_3 = __pyx_v_end; + for (__pyx_v_j = __pyx_v_start; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":104 + * end = self.sent_index.arr[i+1] + * for j from start <= j < end: + * result.append(self.unlink(self.links.arr[j])) # <<<<<<<<<<<<<< + * return result + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__unlink); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyInt_FromLong((__pyx_v_self->links->arr[__pyx_v_j])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_6 = PyList_Append(__pyx_v_result, __pyx_t_4); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":105 + * for j from start <= j < end: + * result.append(self.unlink(self.links.arr[j])) + * return result # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + 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_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_cdec_sa.Alignment.alignment", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":15 + * int val + * + * cdef _node* new_node(int key): # <<<<<<<<<<<<<< + * cdef _node* n + * n = <_node*> malloc(sizeof(_node)) + */ + +static struct __pyx_t_8_cdec_sa__node *__pyx_f_8_cdec_sa_new_node(int __pyx_v_key) { + struct __pyx_t_8_cdec_sa__node *__pyx_v_n; + struct __pyx_t_8_cdec_sa__node *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("new_node", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":17 + * cdef _node* new_node(int key): + * cdef _node* n + * n = <_node*> malloc(sizeof(_node)) # <<<<<<<<<<<<<< + * n.smaller = NULL + * n.bigger = NULL + */ + __pyx_v_n = ((struct __pyx_t_8_cdec_sa__node *)malloc((sizeof(struct __pyx_t_8_cdec_sa__node)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":18 + * cdef _node* n + * n = <_node*> malloc(sizeof(_node)) + * n.smaller = NULL # <<<<<<<<<<<<<< + * n.bigger = NULL + * n.key = key + */ + __pyx_v_n->smaller = NULL; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":19 + * n = <_node*> malloc(sizeof(_node)) + * n.smaller = NULL + * n.bigger = NULL # <<<<<<<<<<<<<< + * n.key = key + * n.val = 0 + */ + __pyx_v_n->bigger = NULL; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":20 + * n.smaller = NULL + * n.bigger = NULL + * n.key = key # <<<<<<<<<<<<<< + * n.val = 0 + * return n + */ + __pyx_v_n->key = __pyx_v_key; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":21 + * n.bigger = NULL + * n.key = key + * n.val = 0 # <<<<<<<<<<<<<< + * return n + * + */ + __pyx_v_n->val = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":22 + * n.key = key + * n.val = 0 + * return n # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_n; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":25 + * + * + * cdef del_node(_node* n): # <<<<<<<<<<<<<< + * if n.smaller != NULL: + * del_node(n.smaller) + */ + +static PyObject *__pyx_f_8_cdec_sa_del_node(struct __pyx_t_8_cdec_sa__node *__pyx_v_n) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("del_node", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":26 + * + * cdef del_node(_node* n): + * if n.smaller != NULL: # <<<<<<<<<<<<<< + * del_node(n.smaller) + * if n.bigger != NULL: + */ + __pyx_t_1 = (__pyx_v_n->smaller != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":27 + * cdef del_node(_node* n): + * if n.smaller != NULL: + * del_node(n.smaller) # <<<<<<<<<<<<<< + * if n.bigger != NULL: + * del_node(n.bigger) + */ + __pyx_t_2 = __pyx_f_8_cdec_sa_del_node(__pyx_v_n->smaller); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":28 + * if n.smaller != NULL: + * del_node(n.smaller) + * if n.bigger != NULL: # <<<<<<<<<<<<<< + * del_node(n.bigger) + * free(n) + */ + __pyx_t_1 = (__pyx_v_n->bigger != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":29 + * del_node(n.smaller) + * if n.bigger != NULL: + * del_node(n.bigger) # <<<<<<<<<<<<<< + * free(n) + * + */ + __pyx_t_2 = __pyx_f_8_cdec_sa_del_node(__pyx_v_n->bigger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":30 + * if n.bigger != NULL: + * del_node(n.bigger) + * free(n) # <<<<<<<<<<<<<< + * + * cdef int* get_val(_node* n, int key): + */ + free(__pyx_v_n); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec_sa.del_node", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":32 + * free(n) + * + * cdef int* get_val(_node* n, int key): # <<<<<<<<<<<<<< + * if key == n.key: + * return &n.val + */ + +static int *__pyx_f_8_cdec_sa_get_val(struct __pyx_t_8_cdec_sa__node *__pyx_v_n, int __pyx_v_key) { + int *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("get_val", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":33 + * + * cdef int* get_val(_node* n, int key): + * if key == n.key: # <<<<<<<<<<<<<< + * return &n.val + * elif key < n.key: + */ + __pyx_t_1 = (__pyx_v_key == __pyx_v_n->key); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":34 + * cdef int* get_val(_node* n, int key): + * if key == n.key: + * return &n.val # <<<<<<<<<<<<<< + * elif key < n.key: + * if n.smaller == NULL: + */ + __pyx_r = (&__pyx_v_n->val); + goto __pyx_L0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":35 + * if key == n.key: + * return &n.val + * elif key < n.key: # <<<<<<<<<<<<<< + * if n.smaller == NULL: + * n.smaller = new_node(key) + */ + __pyx_t_1 = (__pyx_v_key < __pyx_v_n->key); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":36 + * return &n.val + * elif key < n.key: + * if n.smaller == NULL: # <<<<<<<<<<<<<< + * n.smaller = new_node(key) + * return &(n.smaller.val) + */ + __pyx_t_1 = (__pyx_v_n->smaller == NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":37 + * elif key < n.key: + * if n.smaller == NULL: + * n.smaller = new_node(key) # <<<<<<<<<<<<<< + * return &(n.smaller.val) + * return get_val(n.smaller, key) + */ + __pyx_v_n->smaller = __pyx_f_8_cdec_sa_new_node(__pyx_v_key); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":38 + * if n.smaller == NULL: + * n.smaller = new_node(key) + * return &(n.smaller.val) # <<<<<<<<<<<<<< + * return get_val(n.smaller, key) + * else: + */ + __pyx_r = (&__pyx_v_n->smaller->val); + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":39 + * n.smaller = new_node(key) + * return &(n.smaller.val) + * return get_val(n.smaller, key) # <<<<<<<<<<<<<< + * else: + * if n.bigger == NULL: + */ + __pyx_r = __pyx_f_8_cdec_sa_get_val(__pyx_v_n->smaller, __pyx_v_key); + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":41 + * return get_val(n.smaller, key) + * else: + * if n.bigger == NULL: # <<<<<<<<<<<<<< + * n.bigger = new_node(key) + * return &(n.bigger.val) + */ + __pyx_t_1 = (__pyx_v_n->bigger == NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":42 + * else: + * if n.bigger == NULL: + * n.bigger = new_node(key) # <<<<<<<<<<<<<< + * return &(n.bigger.val) + * return get_val(n.bigger, key) + */ + __pyx_v_n->bigger = __pyx_f_8_cdec_sa_new_node(__pyx_v_key); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":43 + * if n.bigger == NULL: + * n.bigger = new_node(key) + * return &(n.bigger.val) # <<<<<<<<<<<<<< + * return get_val(n.bigger, key) + * + */ + __pyx_r = (&__pyx_v_n->bigger->val); + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":44 + * n.bigger = new_node(key) + * return &(n.bigger.val) + * return get_val(n.bigger, key) # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_f_8_cdec_sa_get_val(__pyx_v_n->bigger, __pyx_v_key); + goto __pyx_L0; + } + __pyx_L3:; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_5BiLex_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_5BiLex_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_from_text = 0; + PyObject *__pyx_v_from_data = 0; + PyObject *__pyx_v_from_binary = 0; + PyObject *__pyx_v_earray = 0; + PyObject *__pyx_v_fsarray = 0; + PyObject *__pyx_v_alignment = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__from_text,&__pyx_n_s__from_data,&__pyx_n_s__from_binary,&__pyx_n_s__earray,&__pyx_n_s__fsarray,&__pyx_n_s__alignment,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[6] = {0,0,0,0,0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":54 + * cdef id2eword, id2fword, eword2id, fword2id + * + * def __cinit__(self, from_text=None, from_data=False, from_binary=None, # <<<<<<<<<<<<<< + * earray=None, fsarray=None, alignment=None): + * self.id2eword = [] + */ + values[0] = ((PyObject *)Py_None); + values[1] = __pyx_k_38; + values[2] = ((PyObject *)Py_None); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":55 + * + * def __cinit__(self, from_text=None, from_data=False, from_binary=None, + * earray=None, fsarray=None, alignment=None): # <<<<<<<<<<<<<< + * self.id2eword = [] + * self.id2fword = [] + */ + values[3] = ((PyObject *)Py_None); + values[4] = ((PyObject *)Py_None); + values[5] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_text); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_data); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_binary); + if (value) { values[2] = value; kw_args--; } + } + case 3: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__earray); + if (value) { values[3] = value; kw_args--; } + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fsarray); + if (value) { values[4] = value; kw_args--; } + } + case 5: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__alignment); + if (value) { values[5] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_from_text = values[0]; + __pyx_v_from_data = values[1]; + __pyx_v_from_binary = values[2]; + __pyx_v_earray = values[3]; + __pyx_v_fsarray = values[4]; + __pyx_v_alignment = values[5]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.BiLex.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_5BiLex___cinit__(((struct __pyx_obj_8_cdec_sa_BiLex *)__pyx_v_self), __pyx_v_from_text, __pyx_v_from_data, __pyx_v_from_binary, __pyx_v_earray, __pyx_v_fsarray, __pyx_v_alignment); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":54 + * cdef id2eword, id2fword, eword2id, fword2id + * + * def __cinit__(self, from_text=None, from_data=False, from_binary=None, # <<<<<<<<<<<<<< + * earray=None, fsarray=None, alignment=None): + * self.id2eword = [] + */ + +static int __pyx_pf_8_cdec_sa_5BiLex___cinit__(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_from_text, PyObject *__pyx_v_from_data, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_earray, PyObject *__pyx_v_fsarray, PyObject *__pyx_v_alignment) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":56 + * def __cinit__(self, from_text=None, from_data=False, from_binary=None, + * earray=None, fsarray=None, alignment=None): + * self.id2eword = [] # <<<<<<<<<<<<<< + * self.id2fword = [] + * self.eword2id = {} + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_GOTREF(__pyx_v_self->id2eword); + __Pyx_DECREF(__pyx_v_self->id2eword); + __pyx_v_self->id2eword = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":57 + * earray=None, fsarray=None, alignment=None): + * self.id2eword = [] + * self.id2fword = [] # <<<<<<<<<<<<<< + * self.eword2id = {} + * self.fword2id = {} + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_GOTREF(__pyx_v_self->id2fword); + __Pyx_DECREF(__pyx_v_self->id2fword); + __pyx_v_self->id2fword = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":58 + * self.id2eword = [] + * self.id2fword = [] + * self.eword2id = {} # <<<<<<<<<<<<<< + * self.fword2id = {} + * self.e_index = IntList() + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_GOTREF(__pyx_v_self->eword2id); + __Pyx_DECREF(__pyx_v_self->eword2id); + __pyx_v_self->eword2id = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":59 + * self.id2fword = [] + * self.eword2id = {} + * self.fword2id = {} # <<<<<<<<<<<<<< + * self.e_index = IntList() + * self.f_index = IntList() + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_GOTREF(__pyx_v_self->fword2id); + __Pyx_DECREF(__pyx_v_self->fword2id); + __pyx_v_self->fword2id = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":60 + * self.eword2id = {} + * self.fword2id = {} + * self.e_index = IntList() # <<<<<<<<<<<<<< + * self.f_index = IntList() + * self.col1 = FloatList() + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->e_index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->e_index)); + __pyx_v_self->e_index = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":61 + * self.fword2id = {} + * self.e_index = IntList() + * self.f_index = IntList() # <<<<<<<<<<<<<< + * self.col1 = FloatList() + * self.col2 = FloatList() + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->f_index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->f_index)); + __pyx_v_self->f_index = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":62 + * self.e_index = IntList() + * self.f_index = IntList() + * self.col1 = FloatList() # <<<<<<<<<<<<<< + * self.col2 = FloatList() + * if from_binary: + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_FloatList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->col1); + __Pyx_DECREF(((PyObject *)__pyx_v_self->col1)); + __pyx_v_self->col1 = ((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":63 + * self.f_index = IntList() + * self.col1 = FloatList() + * self.col2 = FloatList() # <<<<<<<<<<<<<< + * if from_binary: + * self.read_binary(from_binary) + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_FloatList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->col2); + __Pyx_DECREF(((PyObject *)__pyx_v_self->col2)); + __pyx_v_self->col2 = ((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":64 + * self.col1 = FloatList() + * self.col2 = FloatList() + * if from_binary: # <<<<<<<<<<<<<< + * self.read_binary(from_binary) + * elif from_data: + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_binary); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":65 + * self.col2 = FloatList() + * if from_binary: + * self.read_binary(from_binary) # <<<<<<<<<<<<<< + * elif from_data: + * self.compute_from_data(fsarray, earray, alignment) + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_binary); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_from_binary); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_binary); + __Pyx_GIVEREF(__pyx_v_from_binary); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":66 + * if from_binary: + * self.read_binary(from_binary) + * elif from_data: # <<<<<<<<<<<<<< + * self.compute_from_data(fsarray, earray, alignment) + * else: + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_data); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":67 + * self.read_binary(from_binary) + * elif from_data: + * self.compute_from_data(fsarray, earray, alignment) # <<<<<<<<<<<<<< + * else: + * self.read_text(from_text) + */ + if (!(likely(((__pyx_v_fsarray) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_fsarray, __pyx_ptype_8_cdec_sa_SuffixArray))))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __pyx_v_fsarray; + __Pyx_INCREF(__pyx_t_4); + if (!(likely(((__pyx_v_earray) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_earray, __pyx_ptype_8_cdec_sa_DataArray))))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_v_earray; + __Pyx_INCREF(__pyx_t_3); + if (!(likely(((__pyx_v_alignment) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_alignment, __pyx_ptype_8_cdec_sa_Alignment))))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_v_alignment; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_5 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->compute_from_data(__pyx_v_self, ((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_t_4), ((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_t_3), ((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_t_1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":69 + * self.compute_from_data(fsarray, earray, alignment) + * else: + * self.read_text(from_text) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_text); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_from_text); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_from_text); + __Pyx_GIVEREF(__pyx_v_from_text); + __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_cdec_sa.BiLex.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":72 + * + * + * cdef compute_from_data(self, SuffixArray fsa, DataArray eda, Alignment aa): # <<<<<<<<<<<<<< + * cdef int sent_id, num_links, l, i, j, f_i, e_j, I, J, V_E, V_F, num_pairs + * cdef int *fsent, *esent, *alignment, *links, *ealigned, *faligned + */ + +static PyObject *__pyx_f_8_cdec_sa_5BiLex_compute_from_data(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_fsa, struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_eda, struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_aa) { + int __pyx_v_sent_id; + int __pyx_v_num_links; + int __pyx_v_l; + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_f_i; + int __pyx_v_e_j; + int __pyx_v_I; + int __pyx_v_J; + int __pyx_v_V_E; + int __pyx_v_V_F; + int __pyx_v_num_pairs; + int *__pyx_v_fsent; + int *__pyx_v_esent; + int *__pyx_v_links; + int *__pyx_v_ealigned; + int *__pyx_v_faligned; + struct __pyx_t_8_cdec_sa__node **__pyx_v_dict; + int *__pyx_v_fmargin; + int *__pyx_v_emargin; + int *__pyx_v_count; + PyObject *__pyx_v_word = 0; + int __pyx_v_null_word; + PyObject *__pyx_v_id = NULL; + PyObject *__pyx_v_num_sents = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + int __pyx_t_9; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("compute_from_data", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":80 + * cdef int null_word + * + * null_word = 0 # <<<<<<<<<<<<<< + * for word in fsa.darray.id2word: # I miss list comprehensions + * self.id2fword.append(word) + */ + __pyx_v_null_word = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":81 + * + * null_word = 0 + * for word in fsa.darray.id2word: # I miss list comprehensions # <<<<<<<<<<<<<< + * self.id2fword.append(word) + * self.id2fword[null_word] = "NULL" + */ + if (PyList_CheckExact(__pyx_v_fsa->darray->id2word) || PyTuple_CheckExact(__pyx_v_fsa->darray->id2word)) { + __pyx_t_1 = __pyx_v_fsa->darray->id2word; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_fsa->darray->id2word); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XDECREF(((PyObject *)__pyx_v_word)); + __pyx_v_word = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":82 + * null_word = 0 + * for word in fsa.darray.id2word: # I miss list comprehensions + * self.id2fword.append(word) # <<<<<<<<<<<<<< + * self.id2fword[null_word] = "NULL" + * for id, word in enumerate(self.id2fword): + */ + __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_self->id2fword, ((PyObject *)__pyx_v_word)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":83 + * for word in fsa.darray.id2word: # I miss list comprehensions + * self.id2fword.append(word) + * self.id2fword[null_word] = "NULL" # <<<<<<<<<<<<<< + * for id, word in enumerate(self.id2fword): + * self.fword2id[word] = id + */ + if (__Pyx_SetItemInt(__pyx_v_self->id2fword, __pyx_v_null_word, ((PyObject *)__pyx_n_s__NULL), sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":84 + * self.id2fword.append(word) + * self.id2fword[null_word] = "NULL" + * for id, word in enumerate(self.id2fword): # <<<<<<<<<<<<<< + * self.fword2id[word] = id + * + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_1 = __pyx_int_0; + if (PyList_CheckExact(__pyx_v_self->id2fword) || PyTuple_CheckExact(__pyx_v_self->id2fword)) { + __pyx_t_4 = __pyx_v_self->id2fword; __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_self->id2fword); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_4)) break; + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + } else { + __pyx_t_5 = __pyx_t_3(__pyx_t_4); + if (unlikely(!__pyx_t_5)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_5); + } + if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XDECREF(((PyObject *)__pyx_v_word)); + __pyx_v_word = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; + __Pyx_INCREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_id); + __pyx_v_id = __pyx_t_1; + __pyx_t_5 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); + __pyx_t_1 = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":85 + * self.id2fword[null_word] = "NULL" + * for id, word in enumerate(self.id2fword): + * self.fword2id[word] = id # <<<<<<<<<<<<<< + * + * for word in eda.id2word: + */ + if (PyObject_SetItem(__pyx_v_self->fword2id, ((PyObject *)__pyx_v_word), __pyx_v_id) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":87 + * self.fword2id[word] = id + * + * for word in eda.id2word: # <<<<<<<<<<<<<< + * self.id2eword.append(word) + * self.id2eword[null_word] = "NULL" + */ + if (PyList_CheckExact(__pyx_v_eda->id2word) || PyTuple_CheckExact(__pyx_v_eda->id2word)) { + __pyx_t_1 = __pyx_v_eda->id2word; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_eda->id2word); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XDECREF(((PyObject *)__pyx_v_word)); + __pyx_v_word = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":88 + * + * for word in eda.id2word: + * self.id2eword.append(word) # <<<<<<<<<<<<<< + * self.id2eword[null_word] = "NULL" + * for id, word in enumerate(self.id2eword): + */ + __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_self->id2eword, ((PyObject *)__pyx_v_word)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":89 + * for word in eda.id2word: + * self.id2eword.append(word) + * self.id2eword[null_word] = "NULL" # <<<<<<<<<<<<<< + * for id, word in enumerate(self.id2eword): + * self.eword2id[word] = id + */ + if (__Pyx_SetItemInt(__pyx_v_self->id2eword, __pyx_v_null_word, ((PyObject *)__pyx_n_s__NULL), sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":90 + * self.id2eword.append(word) + * self.id2eword[null_word] = "NULL" + * for id, word in enumerate(self.id2eword): # <<<<<<<<<<<<<< + * self.eword2id[word] = id + * + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_1 = __pyx_int_0; + if (PyList_CheckExact(__pyx_v_self->id2eword) || PyTuple_CheckExact(__pyx_v_self->id2eword)) { + __pyx_t_4 = __pyx_v_self->id2eword; __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_self->id2eword); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_4)) break; + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + } else { + __pyx_t_5 = __pyx_t_3(__pyx_t_4); + if (unlikely(!__pyx_t_5)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_5); + } + if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XDECREF(((PyObject *)__pyx_v_word)); + __pyx_v_word = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; + __Pyx_INCREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_id); + __pyx_v_id = __pyx_t_1; + __pyx_t_5 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); + __pyx_t_1 = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":91 + * self.id2eword[null_word] = "NULL" + * for id, word in enumerate(self.id2eword): + * self.eword2id[word] = id # <<<<<<<<<<<<<< + * + * num_pairs = 0 + */ + if (PyObject_SetItem(__pyx_v_self->eword2id, ((PyObject *)__pyx_v_word), __pyx_v_id) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":93 + * self.eword2id[word] = id + * + * num_pairs = 0 # <<<<<<<<<<<<<< + * + * V_E = len(eda.id2word) + */ + __pyx_v_num_pairs = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":95 + * num_pairs = 0 + * + * V_E = len(eda.id2word) # <<<<<<<<<<<<<< + * V_F = len(fsa.darray.id2word) + * fmargin = malloc(V_F*sizeof(int)) + */ + __pyx_t_1 = __pyx_v_eda->id2word; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_V_E = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":96 + * + * V_E = len(eda.id2word) + * V_F = len(fsa.darray.id2word) # <<<<<<<<<<<<<< + * fmargin = malloc(V_F*sizeof(int)) + * emargin = malloc(V_E*sizeof(int)) + */ + __pyx_t_1 = __pyx_v_fsa->darray->id2word; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_V_F = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":97 + * V_E = len(eda.id2word) + * V_F = len(fsa.darray.id2word) + * fmargin = malloc(V_F*sizeof(int)) # <<<<<<<<<<<<<< + * emargin = malloc(V_E*sizeof(int)) + * memset(fmargin, 0, V_F*sizeof(int)) + */ + __pyx_v_fmargin = ((int *)malloc((__pyx_v_V_F * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":98 + * V_F = len(fsa.darray.id2word) + * fmargin = malloc(V_F*sizeof(int)) + * emargin = malloc(V_E*sizeof(int)) # <<<<<<<<<<<<<< + * memset(fmargin, 0, V_F*sizeof(int)) + * memset(emargin, 0, V_E*sizeof(int)) + */ + __pyx_v_emargin = ((int *)malloc((__pyx_v_V_E * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":99 + * fmargin = malloc(V_F*sizeof(int)) + * emargin = malloc(V_E*sizeof(int)) + * memset(fmargin, 0, V_F*sizeof(int)) # <<<<<<<<<<<<<< + * memset(emargin, 0, V_E*sizeof(int)) + * + */ + memset(__pyx_v_fmargin, 0, (__pyx_v_V_F * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":100 + * emargin = malloc(V_E*sizeof(int)) + * memset(fmargin, 0, V_F*sizeof(int)) + * memset(emargin, 0, V_E*sizeof(int)) # <<<<<<<<<<<<<< + * + * dict = <_node**> malloc(V_F*sizeof(_node*)) + */ + memset(__pyx_v_emargin, 0, (__pyx_v_V_E * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":102 + * memset(emargin, 0, V_E*sizeof(int)) + * + * dict = <_node**> malloc(V_F*sizeof(_node*)) # <<<<<<<<<<<<<< + * memset(dict, 0, V_F*sizeof(_node*)) + * + */ + __pyx_v_dict = ((struct __pyx_t_8_cdec_sa__node **)malloc((__pyx_v_V_F * (sizeof(struct __pyx_t_8_cdec_sa__node *))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":103 + * + * dict = <_node**> malloc(V_F*sizeof(_node*)) + * memset(dict, 0, V_F*sizeof(_node*)) # <<<<<<<<<<<<<< + * + * num_sents = len(fsa.darray.sent_index) + */ + memset(__pyx_v_dict, 0, (__pyx_v_V_F * (sizeof(struct __pyx_t_8_cdec_sa__node *)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":105 + * memset(dict, 0, V_F*sizeof(_node*)) + * + * num_sents = len(fsa.darray.sent_index) # <<<<<<<<<<<<<< + * for sent_id from 0 <= sent_id < num_sents-1: + * + */ + __pyx_t_1 = ((PyObject *)__pyx_v_fsa->darray->sent_index); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_num_sents = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":106 + * + * num_sents = len(fsa.darray.sent_index) + * for sent_id from 0 <= sent_id < num_sents-1: # <<<<<<<<<<<<<< + * + * fsent = fsa.darray.data.arr + fsa.darray.sent_index.arr[sent_id] + */ + __pyx_t_1 = PyNumber_Subtract(__pyx_v_num_sents, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (__pyx_v_sent_id = 0; __pyx_v_sent_id < __pyx_t_6; __pyx_v_sent_id++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":108 + * for sent_id from 0 <= sent_id < num_sents-1: + * + * fsent = fsa.darray.data.arr + fsa.darray.sent_index.arr[sent_id] # <<<<<<<<<<<<<< + * I = fsa.darray.sent_index.arr[sent_id+1] - fsa.darray.sent_index.arr[sent_id] - 1 + * faligned = malloc(I*sizeof(int)) + */ + __pyx_v_fsent = (__pyx_v_fsa->darray->data->arr + (__pyx_v_fsa->darray->sent_index->arr[__pyx_v_sent_id])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":109 + * + * fsent = fsa.darray.data.arr + fsa.darray.sent_index.arr[sent_id] + * I = fsa.darray.sent_index.arr[sent_id+1] - fsa.darray.sent_index.arr[sent_id] - 1 # <<<<<<<<<<<<<< + * faligned = malloc(I*sizeof(int)) + * memset(faligned, 0, I*sizeof(int)) + */ + __pyx_v_I = (((__pyx_v_fsa->darray->sent_index->arr[(__pyx_v_sent_id + 1)]) - (__pyx_v_fsa->darray->sent_index->arr[__pyx_v_sent_id])) - 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":110 + * fsent = fsa.darray.data.arr + fsa.darray.sent_index.arr[sent_id] + * I = fsa.darray.sent_index.arr[sent_id+1] - fsa.darray.sent_index.arr[sent_id] - 1 + * faligned = malloc(I*sizeof(int)) # <<<<<<<<<<<<<< + * memset(faligned, 0, I*sizeof(int)) + * + */ + __pyx_v_faligned = ((int *)malloc((__pyx_v_I * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":111 + * I = fsa.darray.sent_index.arr[sent_id+1] - fsa.darray.sent_index.arr[sent_id] - 1 + * faligned = malloc(I*sizeof(int)) + * memset(faligned, 0, I*sizeof(int)) # <<<<<<<<<<<<<< + * + * esent = eda.data.arr + eda.sent_index.arr[sent_id] + */ + memset(__pyx_v_faligned, 0, (__pyx_v_I * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":113 + * memset(faligned, 0, I*sizeof(int)) + * + * esent = eda.data.arr + eda.sent_index.arr[sent_id] # <<<<<<<<<<<<<< + * J = eda.sent_index.arr[sent_id+1] - eda.sent_index.arr[sent_id] - 1 + * ealigned = malloc(J*sizeof(int)) + */ + __pyx_v_esent = (__pyx_v_eda->data->arr + (__pyx_v_eda->sent_index->arr[__pyx_v_sent_id])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":114 + * + * esent = eda.data.arr + eda.sent_index.arr[sent_id] + * J = eda.sent_index.arr[sent_id+1] - eda.sent_index.arr[sent_id] - 1 # <<<<<<<<<<<<<< + * ealigned = malloc(J*sizeof(int)) + * memset(ealigned, 0, J*sizeof(int)) + */ + __pyx_v_J = (((__pyx_v_eda->sent_index->arr[(__pyx_v_sent_id + 1)]) - (__pyx_v_eda->sent_index->arr[__pyx_v_sent_id])) - 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":115 + * esent = eda.data.arr + eda.sent_index.arr[sent_id] + * J = eda.sent_index.arr[sent_id+1] - eda.sent_index.arr[sent_id] - 1 + * ealigned = malloc(J*sizeof(int)) # <<<<<<<<<<<<<< + * memset(ealigned, 0, J*sizeof(int)) + * + */ + __pyx_v_ealigned = ((int *)malloc((__pyx_v_J * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":116 + * J = eda.sent_index.arr[sent_id+1] - eda.sent_index.arr[sent_id] - 1 + * ealigned = malloc(J*sizeof(int)) + * memset(ealigned, 0, J*sizeof(int)) # <<<<<<<<<<<<<< + * + * links = aa._get_sent_links(sent_id, &num_links) + */ + memset(__pyx_v_ealigned, 0, (__pyx_v_J * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":118 + * memset(ealigned, 0, J*sizeof(int)) + * + * links = aa._get_sent_links(sent_id, &num_links) # <<<<<<<<<<<<<< + * + * for l from 0 <= l < num_links: + */ + __pyx_v_links = ((struct __pyx_vtabstruct_8_cdec_sa_Alignment *)__pyx_v_aa->__pyx_vtab)->_get_sent_links(__pyx_v_aa, __pyx_v_sent_id, (&__pyx_v_num_links)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":120 + * links = aa._get_sent_links(sent_id, &num_links) + * + * for l from 0 <= l < num_links: # <<<<<<<<<<<<<< + * i = links[l*2] + * j = links[l*2+1] + */ + __pyx_t_7 = __pyx_v_num_links; + for (__pyx_v_l = 0; __pyx_v_l < __pyx_t_7; __pyx_v_l++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":121 + * + * for l from 0 <= l < num_links: + * i = links[l*2] # <<<<<<<<<<<<<< + * j = links[l*2+1] + * if i >= I or j >= J: + */ + __pyx_v_i = (__pyx_v_links[(__pyx_v_l * 2)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":122 + * for l from 0 <= l < num_links: + * i = links[l*2] + * j = links[l*2+1] # <<<<<<<<<<<<<< + * if i >= I or j >= J: + * raise Exception("%d-%d out of bounds (I=%d,J=%d) in line %d\n" % (i,j,I,J,sent_id+1)) + */ + __pyx_v_j = (__pyx_v_links[((__pyx_v_l * 2) + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":123 + * i = links[l*2] + * j = links[l*2+1] + * if i >= I or j >= J: # <<<<<<<<<<<<<< + * raise Exception("%d-%d out of bounds (I=%d,J=%d) in line %d\n" % (i,j,I,J,sent_id+1)) + * f_i = fsent[i] + */ + __pyx_t_8 = (__pyx_v_i >= __pyx_v_I); + if (!__pyx_t_8) { + __pyx_t_9 = (__pyx_v_j >= __pyx_v_J); + __pyx_t_10 = __pyx_t_9; + } else { + __pyx_t_10 = __pyx_t_8; + } + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":124 + * j = links[l*2+1] + * if i >= I or j >= J: + * raise Exception("%d-%d out of bounds (I=%d,J=%d) in line %d\n" % (i,j,I,J,sent_id+1)) # <<<<<<<<<<<<<< + * f_i = fsent[i] + * e_j = esent[j] + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyInt_FromLong(__pyx_v_j); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyInt_FromLong(__pyx_v_I); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_11 = PyInt_FromLong(__pyx_v_J); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_12 = PyInt_FromLong((__pyx_v_sent_id + 1)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = PyTuple_New(5); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_t_11); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_13, 4, __pyx_t_12); + __Pyx_GIVEREF(__pyx_t_12); + __pyx_t_1 = 0; + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_t_11 = 0; + __pyx_t_12 = 0; + __pyx_t_12 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_39), ((PyObject *)__pyx_t_13)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_12)); + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + PyTuple_SET_ITEM(__pyx_t_13, 0, ((PyObject *)__pyx_t_12)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_12)); + __pyx_t_12 = 0; + __pyx_t_12 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + __Pyx_Raise(__pyx_t_12, 0, 0, 0); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L15; + } + __pyx_L15:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":125 + * if i >= I or j >= J: + * raise Exception("%d-%d out of bounds (I=%d,J=%d) in line %d\n" % (i,j,I,J,sent_id+1)) + * f_i = fsent[i] # <<<<<<<<<<<<<< + * e_j = esent[j] + * fmargin[f_i] = fmargin[f_i]+1 + */ + __pyx_v_f_i = (__pyx_v_fsent[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":126 + * raise Exception("%d-%d out of bounds (I=%d,J=%d) in line %d\n" % (i,j,I,J,sent_id+1)) + * f_i = fsent[i] + * e_j = esent[j] # <<<<<<<<<<<<<< + * fmargin[f_i] = fmargin[f_i]+1 + * emargin[e_j] = emargin[e_j]+1 + */ + __pyx_v_e_j = (__pyx_v_esent[__pyx_v_j]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":127 + * f_i = fsent[i] + * e_j = esent[j] + * fmargin[f_i] = fmargin[f_i]+1 # <<<<<<<<<<<<<< + * emargin[e_j] = emargin[e_j]+1 + * if dict[f_i] == NULL: + */ + (__pyx_v_fmargin[__pyx_v_f_i]) = ((__pyx_v_fmargin[__pyx_v_f_i]) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":128 + * e_j = esent[j] + * fmargin[f_i] = fmargin[f_i]+1 + * emargin[e_j] = emargin[e_j]+1 # <<<<<<<<<<<<<< + * if dict[f_i] == NULL: + * dict[f_i] = new_node(e_j) + */ + (__pyx_v_emargin[__pyx_v_e_j]) = ((__pyx_v_emargin[__pyx_v_e_j]) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":129 + * fmargin[f_i] = fmargin[f_i]+1 + * emargin[e_j] = emargin[e_j]+1 + * if dict[f_i] == NULL: # <<<<<<<<<<<<<< + * dict[f_i] = new_node(e_j) + * dict[f_i].val = 1 + */ + __pyx_t_10 = ((__pyx_v_dict[__pyx_v_f_i]) == NULL); + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":130 + * emargin[e_j] = emargin[e_j]+1 + * if dict[f_i] == NULL: + * dict[f_i] = new_node(e_j) # <<<<<<<<<<<<<< + * dict[f_i].val = 1 + * num_pairs = num_pairs + 1 + */ + (__pyx_v_dict[__pyx_v_f_i]) = __pyx_f_8_cdec_sa_new_node(__pyx_v_e_j); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":131 + * if dict[f_i] == NULL: + * dict[f_i] = new_node(e_j) + * dict[f_i].val = 1 # <<<<<<<<<<<<<< + * num_pairs = num_pairs + 1 + * else: + */ + (__pyx_v_dict[__pyx_v_f_i])->val = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":132 + * dict[f_i] = new_node(e_j) + * dict[f_i].val = 1 + * num_pairs = num_pairs + 1 # <<<<<<<<<<<<<< + * else: + * count = get_val(dict[f_i], e_j) + */ + __pyx_v_num_pairs = (__pyx_v_num_pairs + 1); + goto __pyx_L16; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":134 + * num_pairs = num_pairs + 1 + * else: + * count = get_val(dict[f_i], e_j) # <<<<<<<<<<<<<< + * if count[0] == 0: + * num_pairs = num_pairs + 1 + */ + __pyx_v_count = __pyx_f_8_cdec_sa_get_val((__pyx_v_dict[__pyx_v_f_i]), __pyx_v_e_j); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":135 + * else: + * count = get_val(dict[f_i], e_j) + * if count[0] == 0: # <<<<<<<<<<<<<< + * num_pairs = num_pairs + 1 + * count[0] = count[0] + 1 + */ + __pyx_t_10 = ((__pyx_v_count[0]) == 0); + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":136 + * count = get_val(dict[f_i], e_j) + * if count[0] == 0: + * num_pairs = num_pairs + 1 # <<<<<<<<<<<<<< + * count[0] = count[0] + 1 + * # add count + */ + __pyx_v_num_pairs = (__pyx_v_num_pairs + 1); + goto __pyx_L17; + } + __pyx_L17:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":137 + * if count[0] == 0: + * num_pairs = num_pairs + 1 + * count[0] = count[0] + 1 # <<<<<<<<<<<<<< + * # add count + * faligned[i] = 1 + */ + (__pyx_v_count[0]) = ((__pyx_v_count[0]) + 1); + } + __pyx_L16:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":139 + * count[0] = count[0] + 1 + * # add count + * faligned[i] = 1 # <<<<<<<<<<<<<< + * ealigned[j] = 1 + * for i from 0 <= i < I: + */ + (__pyx_v_faligned[__pyx_v_i]) = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":140 + * # add count + * faligned[i] = 1 + * ealigned[j] = 1 # <<<<<<<<<<<<<< + * for i from 0 <= i < I: + * if faligned[i] == 0: + */ + (__pyx_v_ealigned[__pyx_v_j]) = 1; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":141 + * faligned[i] = 1 + * ealigned[j] = 1 + * for i from 0 <= i < I: # <<<<<<<<<<<<<< + * if faligned[i] == 0: + * f_i = fsent[i] + */ + __pyx_t_7 = __pyx_v_I; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_7; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":142 + * ealigned[j] = 1 + * for i from 0 <= i < I: + * if faligned[i] == 0: # <<<<<<<<<<<<<< + * f_i = fsent[i] + * fmargin[f_i] = fmargin[f_i] + 1 + */ + __pyx_t_10 = ((__pyx_v_faligned[__pyx_v_i]) == 0); + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":143 + * for i from 0 <= i < I: + * if faligned[i] == 0: + * f_i = fsent[i] # <<<<<<<<<<<<<< + * fmargin[f_i] = fmargin[f_i] + 1 + * emargin[null_word] = emargin[null_word] + 1 + */ + __pyx_v_f_i = (__pyx_v_fsent[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":144 + * if faligned[i] == 0: + * f_i = fsent[i] + * fmargin[f_i] = fmargin[f_i] + 1 # <<<<<<<<<<<<<< + * emargin[null_word] = emargin[null_word] + 1 + * if dict[f_i] == NULL: + */ + (__pyx_v_fmargin[__pyx_v_f_i]) = ((__pyx_v_fmargin[__pyx_v_f_i]) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":145 + * f_i = fsent[i] + * fmargin[f_i] = fmargin[f_i] + 1 + * emargin[null_word] = emargin[null_word] + 1 # <<<<<<<<<<<<<< + * if dict[f_i] == NULL: + * dict[f_i] = new_node(null_word) + */ + (__pyx_v_emargin[__pyx_v_null_word]) = ((__pyx_v_emargin[__pyx_v_null_word]) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":146 + * fmargin[f_i] = fmargin[f_i] + 1 + * emargin[null_word] = emargin[null_word] + 1 + * if dict[f_i] == NULL: # <<<<<<<<<<<<<< + * dict[f_i] = new_node(null_word) + * dict[f_i].val = 1 + */ + __pyx_t_10 = ((__pyx_v_dict[__pyx_v_f_i]) == NULL); + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":147 + * emargin[null_word] = emargin[null_word] + 1 + * if dict[f_i] == NULL: + * dict[f_i] = new_node(null_word) # <<<<<<<<<<<<<< + * dict[f_i].val = 1 + * num_pairs = num_pairs + 1 + */ + (__pyx_v_dict[__pyx_v_f_i]) = __pyx_f_8_cdec_sa_new_node(__pyx_v_null_word); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":148 + * if dict[f_i] == NULL: + * dict[f_i] = new_node(null_word) + * dict[f_i].val = 1 # <<<<<<<<<<<<<< + * num_pairs = num_pairs + 1 + * else: + */ + (__pyx_v_dict[__pyx_v_f_i])->val = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":149 + * dict[f_i] = new_node(null_word) + * dict[f_i].val = 1 + * num_pairs = num_pairs + 1 # <<<<<<<<<<<<<< + * else: + * count = get_val(dict[f_i], null_word) + */ + __pyx_v_num_pairs = (__pyx_v_num_pairs + 1); + goto __pyx_L21; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":151 + * num_pairs = num_pairs + 1 + * else: + * count = get_val(dict[f_i], null_word) # <<<<<<<<<<<<<< + * if count[0] == 0: + * num_pairs = num_pairs + 1 + */ + __pyx_v_count = __pyx_f_8_cdec_sa_get_val((__pyx_v_dict[__pyx_v_f_i]), __pyx_v_null_word); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":152 + * else: + * count = get_val(dict[f_i], null_word) + * if count[0] == 0: # <<<<<<<<<<<<<< + * num_pairs = num_pairs + 1 + * count[0] = count[0] + 1 + */ + __pyx_t_10 = ((__pyx_v_count[0]) == 0); + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":153 + * count = get_val(dict[f_i], null_word) + * if count[0] == 0: + * num_pairs = num_pairs + 1 # <<<<<<<<<<<<<< + * count[0] = count[0] + 1 + * for j from 0 <= j < J: + */ + __pyx_v_num_pairs = (__pyx_v_num_pairs + 1); + goto __pyx_L22; + } + __pyx_L22:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":154 + * if count[0] == 0: + * num_pairs = num_pairs + 1 + * count[0] = count[0] + 1 # <<<<<<<<<<<<<< + * for j from 0 <= j < J: + * if ealigned[j] == 0: + */ + (__pyx_v_count[0]) = ((__pyx_v_count[0]) + 1); + } + __pyx_L21:; + goto __pyx_L20; + } + __pyx_L20:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":155 + * num_pairs = num_pairs + 1 + * count[0] = count[0] + 1 + * for j from 0 <= j < J: # <<<<<<<<<<<<<< + * if ealigned[j] == 0: + * e_j = esent[j] + */ + __pyx_t_7 = __pyx_v_J; + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_7; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":156 + * count[0] = count[0] + 1 + * for j from 0 <= j < J: + * if ealigned[j] == 0: # <<<<<<<<<<<<<< + * e_j = esent[j] + * fmargin[null_word] = fmargin[null_word] + 1 + */ + __pyx_t_10 = ((__pyx_v_ealigned[__pyx_v_j]) == 0); + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":157 + * for j from 0 <= j < J: + * if ealigned[j] == 0: + * e_j = esent[j] # <<<<<<<<<<<<<< + * fmargin[null_word] = fmargin[null_word] + 1 + * emargin[e_j] = emargin[e_j] + 1 + */ + __pyx_v_e_j = (__pyx_v_esent[__pyx_v_j]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":158 + * if ealigned[j] == 0: + * e_j = esent[j] + * fmargin[null_word] = fmargin[null_word] + 1 # <<<<<<<<<<<<<< + * emargin[e_j] = emargin[e_j] + 1 + * if dict[null_word] == NULL: + */ + (__pyx_v_fmargin[__pyx_v_null_word]) = ((__pyx_v_fmargin[__pyx_v_null_word]) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":159 + * e_j = esent[j] + * fmargin[null_word] = fmargin[null_word] + 1 + * emargin[e_j] = emargin[e_j] + 1 # <<<<<<<<<<<<<< + * if dict[null_word] == NULL: + * dict[null_word] = new_node(e_j) + */ + (__pyx_v_emargin[__pyx_v_e_j]) = ((__pyx_v_emargin[__pyx_v_e_j]) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":160 + * fmargin[null_word] = fmargin[null_word] + 1 + * emargin[e_j] = emargin[e_j] + 1 + * if dict[null_word] == NULL: # <<<<<<<<<<<<<< + * dict[null_word] = new_node(e_j) + * dict[null_word].val = 1 + */ + __pyx_t_10 = ((__pyx_v_dict[__pyx_v_null_word]) == NULL); + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":161 + * emargin[e_j] = emargin[e_j] + 1 + * if dict[null_word] == NULL: + * dict[null_word] = new_node(e_j) # <<<<<<<<<<<<<< + * dict[null_word].val = 1 + * num_pairs = num_pairs + 1 + */ + (__pyx_v_dict[__pyx_v_null_word]) = __pyx_f_8_cdec_sa_new_node(__pyx_v_e_j); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":162 + * if dict[null_word] == NULL: + * dict[null_word] = new_node(e_j) + * dict[null_word].val = 1 # <<<<<<<<<<<<<< + * num_pairs = num_pairs + 1 + * else: + */ + (__pyx_v_dict[__pyx_v_null_word])->val = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":163 + * dict[null_word] = new_node(e_j) + * dict[null_word].val = 1 + * num_pairs = num_pairs + 1 # <<<<<<<<<<<<<< + * else: + * count = get_val(dict[null_word], e_j) + */ + __pyx_v_num_pairs = (__pyx_v_num_pairs + 1); + goto __pyx_L26; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":165 + * num_pairs = num_pairs + 1 + * else: + * count = get_val(dict[null_word], e_j) # <<<<<<<<<<<<<< + * if count[0] == 0: + * num_pairs = num_pairs + 1 + */ + __pyx_v_count = __pyx_f_8_cdec_sa_get_val((__pyx_v_dict[__pyx_v_null_word]), __pyx_v_e_j); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":166 + * else: + * count = get_val(dict[null_word], e_j) + * if count[0] == 0: # <<<<<<<<<<<<<< + * num_pairs = num_pairs + 1 + * count[0] = count[0] + 1 + */ + __pyx_t_10 = ((__pyx_v_count[0]) == 0); + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":167 + * count = get_val(dict[null_word], e_j) + * if count[0] == 0: + * num_pairs = num_pairs + 1 # <<<<<<<<<<<<<< + * count[0] = count[0] + 1 + * free(links) + */ + __pyx_v_num_pairs = (__pyx_v_num_pairs + 1); + goto __pyx_L27; + } + __pyx_L27:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":168 + * if count[0] == 0: + * num_pairs = num_pairs + 1 + * count[0] = count[0] + 1 # <<<<<<<<<<<<<< + * free(links) + * free(faligned) + */ + (__pyx_v_count[0]) = ((__pyx_v_count[0]) + 1); + } + __pyx_L26:; + goto __pyx_L25; + } + __pyx_L25:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":169 + * num_pairs = num_pairs + 1 + * count[0] = count[0] + 1 + * free(links) # <<<<<<<<<<<<<< + * free(faligned) + * free(ealigned) + */ + free(__pyx_v_links); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":170 + * count[0] = count[0] + 1 + * free(links) + * free(faligned) # <<<<<<<<<<<<<< + * free(ealigned) + * self.f_index = IntList(initial_len=V_F) + */ + free(__pyx_v_faligned); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":171 + * free(links) + * free(faligned) + * free(ealigned) # <<<<<<<<<<<<<< + * self.f_index = IntList(initial_len=V_F) + * self.e_index = IntList(initial_len=num_pairs) + */ + free(__pyx_v_ealigned); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":172 + * free(faligned) + * free(ealigned) + * self.f_index = IntList(initial_len=V_F) # <<<<<<<<<<<<<< + * self.e_index = IntList(initial_len=num_pairs) + * self.col1 = FloatList(initial_len=num_pairs) + */ + __pyx_t_12 = PyDict_New(); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_12)); + __pyx_t_13 = PyInt_FromLong(__pyx_v_V_F); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + if (PyDict_SetItem(__pyx_t_12, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_13) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_12)); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __Pyx_GIVEREF(__pyx_t_13); + __Pyx_GOTREF(__pyx_v_self->f_index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->f_index)); + __pyx_v_self->f_index = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_13); + __pyx_t_13 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":173 + * free(ealigned) + * self.f_index = IntList(initial_len=V_F) + * self.e_index = IntList(initial_len=num_pairs) # <<<<<<<<<<<<<< + * self.col1 = FloatList(initial_len=num_pairs) + * self.col2 = FloatList(initial_len=num_pairs) + */ + __pyx_t_13 = PyDict_New(); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_13)); + __pyx_t_12 = PyInt_FromLong(__pyx_v_num_pairs); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + if (PyDict_SetItem(__pyx_t_13, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_12) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_13)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_GOTREF(__pyx_v_self->e_index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->e_index)); + __pyx_v_self->e_index = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_12); + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":174 + * self.f_index = IntList(initial_len=V_F) + * self.e_index = IntList(initial_len=num_pairs) + * self.col1 = FloatList(initial_len=num_pairs) # <<<<<<<<<<<<<< + * self.col2 = FloatList(initial_len=num_pairs) + * + */ + __pyx_t_12 = PyDict_New(); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_12)); + __pyx_t_13 = PyInt_FromLong(__pyx_v_num_pairs); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + if (PyDict_SetItem(__pyx_t_12, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_13) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_FloatList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_12)); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __Pyx_GIVEREF(__pyx_t_13); + __Pyx_GOTREF(__pyx_v_self->col1); + __Pyx_DECREF(((PyObject *)__pyx_v_self->col1)); + __pyx_v_self->col1 = ((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_t_13); + __pyx_t_13 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":175 + * self.e_index = IntList(initial_len=num_pairs) + * self.col1 = FloatList(initial_len=num_pairs) + * self.col2 = FloatList(initial_len=num_pairs) # <<<<<<<<<<<<<< + * + * num_pairs = 0 + */ + __pyx_t_13 = PyDict_New(); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_13)); + __pyx_t_12 = PyInt_FromLong(__pyx_v_num_pairs); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + if (PyDict_SetItem(__pyx_t_13, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_12) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_FloatList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_13)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_GOTREF(__pyx_v_self->col2); + __Pyx_DECREF(((PyObject *)__pyx_v_self->col2)); + __pyx_v_self->col2 = ((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_t_12); + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":177 + * self.col2 = FloatList(initial_len=num_pairs) + * + * num_pairs = 0 # <<<<<<<<<<<<<< + * for i from 0 <= i < V_F: + * #self.f_index[i] = num_pairs + */ + __pyx_v_num_pairs = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":178 + * + * num_pairs = 0 + * for i from 0 <= i < V_F: # <<<<<<<<<<<<<< + * #self.f_index[i] = num_pairs + * self.f_index.set(i, num_pairs) + */ + __pyx_t_6 = __pyx_v_V_F; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_6; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":180 + * for i from 0 <= i < V_F: + * #self.f_index[i] = num_pairs + * self.f_index.set(i, num_pairs) # <<<<<<<<<<<<<< + * if dict[i] != NULL: + * self._add_node(dict[i], &num_pairs, float(fmargin[i]), emargin) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->f_index->__pyx_vtab)->set(__pyx_v_self->f_index, __pyx_v_i, __pyx_v_num_pairs); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":181 + * #self.f_index[i] = num_pairs + * self.f_index.set(i, num_pairs) + * if dict[i] != NULL: # <<<<<<<<<<<<<< + * self._add_node(dict[i], &num_pairs, float(fmargin[i]), emargin) + * del_node(dict[i]) + */ + __pyx_t_10 = ((__pyx_v_dict[__pyx_v_i]) != NULL); + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":182 + * self.f_index.set(i, num_pairs) + * if dict[i] != NULL: + * self._add_node(dict[i], &num_pairs, float(fmargin[i]), emargin) # <<<<<<<<<<<<<< + * del_node(dict[i]) + * free(fmargin) + */ + __pyx_t_12 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->_add_node(__pyx_v_self, (__pyx_v_dict[__pyx_v_i]), (&__pyx_v_num_pairs), ((double)(__pyx_v_fmargin[__pyx_v_i])), __pyx_v_emargin); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":183 + * if dict[i] != NULL: + * self._add_node(dict[i], &num_pairs, float(fmargin[i]), emargin) + * del_node(dict[i]) # <<<<<<<<<<<<<< + * free(fmargin) + * free(emargin) + */ + __pyx_t_12 = __pyx_f_8_cdec_sa_del_node((__pyx_v_dict[__pyx_v_i])); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L30; + } + __pyx_L30:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":184 + * self._add_node(dict[i], &num_pairs, float(fmargin[i]), emargin) + * del_node(dict[i]) + * free(fmargin) # <<<<<<<<<<<<<< + * free(emargin) + * free(dict) + */ + free(__pyx_v_fmargin); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":185 + * del_node(dict[i]) + * free(fmargin) + * free(emargin) # <<<<<<<<<<<<<< + * free(dict) + * return + */ + free(__pyx_v_emargin); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":186 + * free(fmargin) + * free(emargin) + * free(dict) # <<<<<<<<<<<<<< + * return + * + */ + free(__pyx_v_dict); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":187 + * free(emargin) + * free(dict) + * return # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + 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_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_AddTraceback("_cdec_sa.BiLex.compute_from_data", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_word); + __Pyx_XDECREF(__pyx_v_id); + __Pyx_XDECREF(__pyx_v_num_sents); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":190 + * + * + * cdef _add_node(self, _node* n, int* num_pairs, float fmargin, int* emargin): # <<<<<<<<<<<<<< + * cdef int loc + * if n.smaller != NULL: + */ + +static PyObject *__pyx_f_8_cdec_sa_5BiLex__add_node(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, struct __pyx_t_8_cdec_sa__node *__pyx_v_n, int *__pyx_v_num_pairs, float __pyx_v_fmargin, int *__pyx_v_emargin) { + int __pyx_v_loc; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_add_node", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":192 + * cdef _add_node(self, _node* n, int* num_pairs, float fmargin, int* emargin): + * cdef int loc + * if n.smaller != NULL: # <<<<<<<<<<<<<< + * self._add_node(n.smaller, num_pairs, fmargin, emargin) + * loc = num_pairs[0] + */ + __pyx_t_1 = (__pyx_v_n->smaller != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":193 + * cdef int loc + * if n.smaller != NULL: + * self._add_node(n.smaller, num_pairs, fmargin, emargin) # <<<<<<<<<<<<<< + * loc = num_pairs[0] + * self.e_index.set(loc, n.key) + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->_add_node(__pyx_v_self, __pyx_v_n->smaller, __pyx_v_num_pairs, __pyx_v_fmargin, __pyx_v_emargin); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":194 + * if n.smaller != NULL: + * self._add_node(n.smaller, num_pairs, fmargin, emargin) + * loc = num_pairs[0] # <<<<<<<<<<<<<< + * self.e_index.set(loc, n.key) + * self.col1.set(loc, float(n.val)/fmargin) + */ + __pyx_v_loc = (__pyx_v_num_pairs[0]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":195 + * self._add_node(n.smaller, num_pairs, fmargin, emargin) + * loc = num_pairs[0] + * self.e_index.set(loc, n.key) # <<<<<<<<<<<<<< + * self.col1.set(loc, float(n.val)/fmargin) + * self.col2.set(loc, float(n.val)/float(emargin[n.key])) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->e_index->__pyx_vtab)->set(__pyx_v_self->e_index, __pyx_v_loc, __pyx_v_n->key); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":196 + * loc = num_pairs[0] + * self.e_index.set(loc, n.key) + * self.col1.set(loc, float(n.val)/fmargin) # <<<<<<<<<<<<<< + * self.col2.set(loc, float(n.val)/float(emargin[n.key])) + * num_pairs[0] = loc + 1 + */ + if (unlikely(__pyx_v_fmargin == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + ((struct __pyx_vtabstruct_8_cdec_sa_FloatList *)__pyx_v_self->col1->__pyx_vtab)->set(__pyx_v_self->col1, __pyx_v_loc, (((double)__pyx_v_n->val) / __pyx_v_fmargin)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":197 + * self.e_index.set(loc, n.key) + * self.col1.set(loc, float(n.val)/fmargin) + * self.col2.set(loc, float(n.val)/float(emargin[n.key])) # <<<<<<<<<<<<<< + * num_pairs[0] = loc + 1 + * if n.bigger != NULL: + */ + if (unlikely(((double)(__pyx_v_emargin[__pyx_v_n->key])) == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + ((struct __pyx_vtabstruct_8_cdec_sa_FloatList *)__pyx_v_self->col2->__pyx_vtab)->set(__pyx_v_self->col2, __pyx_v_loc, (((double)__pyx_v_n->val) / ((double)(__pyx_v_emargin[__pyx_v_n->key])))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":198 + * self.col1.set(loc, float(n.val)/fmargin) + * self.col2.set(loc, float(n.val)/float(emargin[n.key])) + * num_pairs[0] = loc + 1 # <<<<<<<<<<<<<< + * if n.bigger != NULL: + * self._add_node(n.bigger, num_pairs, fmargin, emargin) + */ + (__pyx_v_num_pairs[0]) = (__pyx_v_loc + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":199 + * self.col2.set(loc, float(n.val)/float(emargin[n.key])) + * num_pairs[0] = loc + 1 + * if n.bigger != NULL: # <<<<<<<<<<<<<< + * self._add_node(n.bigger, num_pairs, fmargin, emargin) + * + */ + __pyx_t_1 = (__pyx_v_n->bigger != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":200 + * num_pairs[0] = loc + 1 + * if n.bigger != NULL: + * self._add_node(n.bigger, num_pairs, fmargin, emargin) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->_add_node(__pyx_v_self, __pyx_v_n->bigger, __pyx_v_num_pairs, __pyx_v_fmargin, __pyx_v_emargin); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L4; + } + __pyx_L4:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec_sa.BiLex._add_node", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_5BiLex_3write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_5BiLex_3write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.BiLex.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_5BiLex_2write_binary(((struct __pyx_obj_8_cdec_sa_BiLex *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":203 + * + * + * def write_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "w") + */ + +static PyObject *__pyx_pf_8_cdec_sa_5BiLex_2write_binary(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + 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("write_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":205 + * def write_binary(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "w") # <<<<<<<<<<<<<< + * self.f_index.write_handle(f) + * self.e_index.write_handle(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":206 + * cdef FILE* f + * f = fopen(filename, "w") + * self.f_index.write_handle(f) # <<<<<<<<<<<<<< + * self.e_index.write_handle(f) + * self.col1.write_handle(f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->f_index->__pyx_vtab)->write_handle(__pyx_v_self->f_index, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":207 + * f = fopen(filename, "w") + * self.f_index.write_handle(f) + * self.e_index.write_handle(f) # <<<<<<<<<<<<<< + * self.col1.write_handle(f) + * self.col2.write_handle(f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->e_index->__pyx_vtab)->write_handle(__pyx_v_self->e_index, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":208 + * self.f_index.write_handle(f) + * self.e_index.write_handle(f) + * self.col1.write_handle(f) # <<<<<<<<<<<<<< + * self.col2.write_handle(f) + * self.write_wordlist(self.id2fword, f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_FloatList *)__pyx_v_self->col1->__pyx_vtab)->write_handle(__pyx_v_self->col1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":209 + * self.e_index.write_handle(f) + * self.col1.write_handle(f) + * self.col2.write_handle(f) # <<<<<<<<<<<<<< + * self.write_wordlist(self.id2fword, f) + * self.write_wordlist(self.id2eword, f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_FloatList *)__pyx_v_self->col2->__pyx_vtab)->write_handle(__pyx_v_self->col2, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":210 + * self.col1.write_handle(f) + * self.col2.write_handle(f) + * self.write_wordlist(self.id2fword, f) # <<<<<<<<<<<<<< + * self.write_wordlist(self.id2eword, f) + * fclose(f) + */ + __pyx_t_1 = __pyx_v_self->id2fword; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->write_wordlist(__pyx_v_self, __pyx_t_1, __pyx_v_f); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":211 + * self.col2.write_handle(f) + * self.write_wordlist(self.id2fword, f) + * self.write_wordlist(self.id2eword, f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + __pyx_t_2 = __pyx_v_self->id2eword; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->write_wordlist(__pyx_v_self, __pyx_t_2, __pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":212 + * self.write_wordlist(self.id2fword, f) + * self.write_wordlist(self.id2eword, f) + * fclose(f) # <<<<<<<<<<<<<< + * + * + */ + fclose(__pyx_v_f); + + __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_sa.BiLex.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":215 + * + * + * cdef write_wordlist(self, wordlist, FILE* f): # <<<<<<<<<<<<<< + * cdef int word_len + * cdef int num_words + */ + +static PyObject *__pyx_f_8_cdec_sa_5BiLex_write_wordlist(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_wordlist, FILE *__pyx_v_f) { + int __pyx_v_word_len; + int __pyx_v_num_words; + char *__pyx_v_c_word; + PyObject *__pyx_v_word = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + char *__pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_wordlist", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":220 + * cdef char* c_word + * + * num_words = len(wordlist) # <<<<<<<<<<<<<< + * fwrite(&(num_words), sizeof(int), 1, f) + * for word in wordlist: + */ + __pyx_t_1 = PyObject_Length(__pyx_v_wordlist); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_num_words = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":221 + * + * num_words = len(wordlist) + * fwrite(&(num_words), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * for word in wordlist: + * c_word = word + */ + fwrite((&__pyx_v_num_words), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":222 + * num_words = len(wordlist) + * fwrite(&(num_words), sizeof(int), 1, f) + * for word in wordlist: # <<<<<<<<<<<<<< + * c_word = word + * word_len = strlen(c_word) + 1 + */ + if (PyList_CheckExact(__pyx_v_wordlist) || PyTuple_CheckExact(__pyx_v_wordlist)) { + __pyx_t_2 = __pyx_v_wordlist; __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_1 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_wordlist); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_1); __Pyx_INCREF(__pyx_t_4); __pyx_t_1++; + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_1); __Pyx_INCREF(__pyx_t_4); __pyx_t_1++; + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_2); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_word); + __pyx_v_word = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":223 + * fwrite(&(num_words), sizeof(int), 1, f) + * for word in wordlist: + * c_word = word # <<<<<<<<<<<<<< + * word_len = strlen(c_word) + 1 + * fwrite(&(word_len), sizeof(int), 1, f) + */ + __pyx_t_5 = PyBytes_AsString(__pyx_v_word); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_c_word = __pyx_t_5; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":224 + * for word in wordlist: + * c_word = word + * word_len = strlen(c_word) + 1 # <<<<<<<<<<<<<< + * fwrite(&(word_len), sizeof(int), 1, f) + * fwrite(c_word, sizeof(char), word_len, f) + */ + __pyx_v_word_len = (strlen(__pyx_v_c_word) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":225 + * c_word = word + * word_len = strlen(c_word) + 1 + * fwrite(&(word_len), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fwrite(c_word, sizeof(char), word_len, f) + * + */ + fwrite((&__pyx_v_word_len), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":226 + * word_len = strlen(c_word) + 1 + * fwrite(&(word_len), sizeof(int), 1, f) + * fwrite(c_word, sizeof(char), word_len, f) # <<<<<<<<<<<<<< + * + * + */ + fwrite(__pyx_v_c_word, (sizeof(char)), __pyx_v_word_len, __pyx_v_f); + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec_sa.BiLex.write_wordlist", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_word); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":229 + * + * + * cdef read_wordlist(self, word2id, id2word, FILE* f): # <<<<<<<<<<<<<< + * cdef int num_words + * cdef int word_len + */ + +static PyObject *__pyx_f_8_cdec_sa_5BiLex_read_wordlist(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_word2id, PyObject *__pyx_v_id2word, FILE *__pyx_v_f) { + int __pyx_v_num_words; + int __pyx_v_word_len; + char *__pyx_v_c_word; + PyObject *__pyx_v_py_word = 0; + CYTHON_UNUSED long __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_wordlist", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":235 + * cdef bytes py_word + * + * fread(&(num_words), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * for i from 0 <= i < num_words: + * fread(&(word_len), sizeof(int), 1, f) + */ + fread((&__pyx_v_num_words), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":236 + * + * fread(&(num_words), sizeof(int), 1, f) + * for i from 0 <= i < num_words: # <<<<<<<<<<<<<< + * fread(&(word_len), sizeof(int), 1, f) + * c_word = malloc (word_len * sizeof(char)) + */ + __pyx_t_1 = __pyx_v_num_words; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":237 + * fread(&(num_words), sizeof(int), 1, f) + * for i from 0 <= i < num_words: + * fread(&(word_len), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * c_word = malloc (word_len * sizeof(char)) + * fread(c_word, sizeof(char), word_len, f) + */ + fread((&__pyx_v_word_len), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":238 + * for i from 0 <= i < num_words: + * fread(&(word_len), sizeof(int), 1, f) + * c_word = malloc (word_len * sizeof(char)) # <<<<<<<<<<<<<< + * fread(c_word, sizeof(char), word_len, f) + * py_word = c_word + */ + __pyx_v_c_word = ((char *)malloc((__pyx_v_word_len * (sizeof(char))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":239 + * fread(&(word_len), sizeof(int), 1, f) + * c_word = malloc (word_len * sizeof(char)) + * fread(c_word, sizeof(char), word_len, f) # <<<<<<<<<<<<<< + * py_word = c_word + * free(c_word) + */ + fread(__pyx_v_c_word, (sizeof(char)), __pyx_v_word_len, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":240 + * c_word = malloc (word_len * sizeof(char)) + * fread(c_word, sizeof(char), word_len, f) + * py_word = c_word # <<<<<<<<<<<<<< + * free(c_word) + * word2id[py_word] = len(id2word) + */ + __pyx_t_2 = PyBytes_FromString(__pyx_v_c_word); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 240; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_XDECREF(((PyObject *)__pyx_v_py_word)); + __pyx_v_py_word = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":241 + * fread(c_word, sizeof(char), word_len, f) + * py_word = c_word + * free(c_word) # <<<<<<<<<<<<<< + * word2id[py_word] = len(id2word) + * id2word.append(py_word) + */ + free(__pyx_v_c_word); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":242 + * py_word = c_word + * free(c_word) + * word2id[py_word] = len(id2word) # <<<<<<<<<<<<<< + * id2word.append(py_word) + * + */ + __pyx_t_3 = PyObject_Length(__pyx_v_id2word); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyObject_SetItem(__pyx_v_word2id, ((PyObject *)__pyx_v_py_word), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":243 + * free(c_word) + * word2id[py_word] = len(id2word) + * id2word.append(py_word) # <<<<<<<<<<<<<< + * + * def read_binary(self, char* filename): + */ + __pyx_t_2 = __Pyx_PyObject_Append(__pyx_v_id2word, ((PyObject *)__pyx_v_py_word)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec_sa.BiLex.read_wordlist", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_py_word); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_5BiLex_5read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_5BiLex_5read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.BiLex.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_5BiLex_4read_binary(((struct __pyx_obj_8_cdec_sa_BiLex *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":245 + * id2word.append(py_word) + * + * def read_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "r") + */ + +static PyObject *__pyx_pf_8_cdec_sa_5BiLex_4read_binary(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":247 + * def read_binary(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "r") # <<<<<<<<<<<<<< + * self.f_index.read_handle(f) + * self.e_index.read_handle(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":248 + * cdef FILE* f + * f = fopen(filename, "r") + * self.f_index.read_handle(f) # <<<<<<<<<<<<<< + * self.e_index.read_handle(f) + * self.col1.read_handle(f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->f_index->__pyx_vtab)->read_handle(__pyx_v_self->f_index, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":249 + * f = fopen(filename, "r") + * self.f_index.read_handle(f) + * self.e_index.read_handle(f) # <<<<<<<<<<<<<< + * self.col1.read_handle(f) + * self.col2.read_handle(f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->e_index->__pyx_vtab)->read_handle(__pyx_v_self->e_index, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":250 + * self.f_index.read_handle(f) + * self.e_index.read_handle(f) + * self.col1.read_handle(f) # <<<<<<<<<<<<<< + * self.col2.read_handle(f) + * self.read_wordlist(self.fword2id, self.id2fword, f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_FloatList *)__pyx_v_self->col1->__pyx_vtab)->read_handle(__pyx_v_self->col1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":251 + * self.e_index.read_handle(f) + * self.col1.read_handle(f) + * self.col2.read_handle(f) # <<<<<<<<<<<<<< + * self.read_wordlist(self.fword2id, self.id2fword, f) + * self.read_wordlist(self.eword2id, self.id2eword, f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_FloatList *)__pyx_v_self->col2->__pyx_vtab)->read_handle(__pyx_v_self->col2, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":252 + * self.col1.read_handle(f) + * self.col2.read_handle(f) + * self.read_wordlist(self.fword2id, self.id2fword, f) # <<<<<<<<<<<<<< + * self.read_wordlist(self.eword2id, self.id2eword, f) + * fclose(f) + */ + __pyx_t_1 = __pyx_v_self->fword2id; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __pyx_v_self->id2fword; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_3 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->read_wordlist(__pyx_v_self, __pyx_t_1, __pyx_t_2, __pyx_v_f); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":253 + * self.col2.read_handle(f) + * self.read_wordlist(self.fword2id, self.id2fword, f) + * self.read_wordlist(self.eword2id, self.id2eword, f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + __pyx_t_3 = __pyx_v_self->eword2id; + __Pyx_INCREF(__pyx_t_3); + __pyx_t_2 = __pyx_v_self->id2eword; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->read_wordlist(__pyx_v_self, __pyx_t_3, __pyx_t_2, __pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":254 + * self.read_wordlist(self.fword2id, self.id2fword, f) + * self.read_wordlist(self.eword2id, self.id2eword, f) + * fclose(f) # <<<<<<<<<<<<<< + * + * + */ + fclose(__pyx_v_f); + + __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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.BiLex.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_5BiLex_7get_e_id(PyObject *__pyx_v_self, PyObject *__pyx_v_eword); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_5BiLex_7get_e_id(PyObject *__pyx_v_self, PyObject *__pyx_v_eword) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_e_id (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_5BiLex_6get_e_id(((struct __pyx_obj_8_cdec_sa_BiLex *)__pyx_v_self), ((PyObject *)__pyx_v_eword)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":257 + * + * + * def get_e_id(self, eword): # <<<<<<<<<<<<<< + * if eword not in self.eword2id: + * e_id = len(self.id2eword) + */ + +static PyObject *__pyx_pf_8_cdec_sa_5BiLex_6get_e_id(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_eword) { + PyObject *__pyx_v_e_id = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_e_id", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":258 + * + * def get_e_id(self, eword): + * if eword not in self.eword2id: # <<<<<<<<<<<<<< + * e_id = len(self.id2eword) + * self.id2eword.append(eword) + */ + __pyx_t_1 = (__Pyx_NegateNonNeg(PySequence_Contains(__pyx_v_self->eword2id, __pyx_v_eword))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":259 + * def get_e_id(self, eword): + * if eword not in self.eword2id: + * e_id = len(self.id2eword) # <<<<<<<<<<<<<< + * self.id2eword.append(eword) + * self.eword2id[eword] = e_id + */ + __pyx_t_2 = __pyx_v_self->id2eword; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_e_id = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":260 + * if eword not in self.eword2id: + * e_id = len(self.id2eword) + * self.id2eword.append(eword) # <<<<<<<<<<<<<< + * self.eword2id[eword] = e_id + * return self.eword2id[eword] + */ + __pyx_t_2 = __Pyx_PyObject_Append(__pyx_v_self->id2eword, __pyx_v_eword); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":261 + * e_id = len(self.id2eword) + * self.id2eword.append(eword) + * self.eword2id[eword] = e_id # <<<<<<<<<<<<<< + * return self.eword2id[eword] + * + */ + if (PyObject_SetItem(__pyx_v_self->eword2id, __pyx_v_eword, __pyx_v_e_id) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":262 + * self.id2eword.append(eword) + * self.eword2id[eword] = e_id + * return self.eword2id[eword] # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyObject_GetItem(__pyx_v_self->eword2id, __pyx_v_eword); if (!__pyx_t_2) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_cdec_sa.BiLex.get_e_id", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_e_id); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_5BiLex_9get_f_id(PyObject *__pyx_v_self, PyObject *__pyx_v_fword); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_5BiLex_9get_f_id(PyObject *__pyx_v_self, PyObject *__pyx_v_fword) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_f_id (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_5BiLex_8get_f_id(((struct __pyx_obj_8_cdec_sa_BiLex *)__pyx_v_self), ((PyObject *)__pyx_v_fword)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":265 + * + * + * def get_f_id(self, fword): # <<<<<<<<<<<<<< + * if fword not in self.fword2id: + * f_id = len(self.id2fword) + */ + +static PyObject *__pyx_pf_8_cdec_sa_5BiLex_8get_f_id(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_fword) { + PyObject *__pyx_v_f_id = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_f_id", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":266 + * + * def get_f_id(self, fword): + * if fword not in self.fword2id: # <<<<<<<<<<<<<< + * f_id = len(self.id2fword) + * self.id2fword.append(fword) + */ + __pyx_t_1 = (__Pyx_NegateNonNeg(PySequence_Contains(__pyx_v_self->fword2id, __pyx_v_fword))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 266; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":267 + * def get_f_id(self, fword): + * if fword not in self.fword2id: + * f_id = len(self.id2fword) # <<<<<<<<<<<<<< + * self.id2fword.append(fword) + * self.fword2id[fword] = f_id + */ + __pyx_t_2 = __pyx_v_self->id2fword; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_f_id = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":268 + * if fword not in self.fword2id: + * f_id = len(self.id2fword) + * self.id2fword.append(fword) # <<<<<<<<<<<<<< + * self.fword2id[fword] = f_id + * return self.fword2id[fword] + */ + __pyx_t_2 = __Pyx_PyObject_Append(__pyx_v_self->id2fword, __pyx_v_fword); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":269 + * f_id = len(self.id2fword) + * self.id2fword.append(fword) + * self.fword2id[fword] = f_id # <<<<<<<<<<<<<< + * return self.fword2id[fword] + * + */ + if (PyObject_SetItem(__pyx_v_self->fword2id, __pyx_v_fword, __pyx_v_f_id) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":270 + * self.id2fword.append(fword) + * self.fword2id[fword] = f_id + * return self.fword2id[fword] # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyObject_GetItem(__pyx_v_self->fword2id, __pyx_v_fword); if (!__pyx_t_2) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 270; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_cdec_sa.BiLex.get_f_id", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f_id); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_5BiLex_11read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_5BiLex_11read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_text (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.BiLex.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_5BiLex_10read_text(((struct __pyx_obj_8_cdec_sa_BiLex *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":273 + * + * + * def read_text(self, char* filename): # <<<<<<<<<<<<<< + * cdef i, j, w, e_id, f_id, n_f, n_e, N + * cdef IntList fcount + */ + +static PyObject *__pyx_pf_8_cdec_sa_5BiLex_10read_text(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_v_i = 0; + PyObject *__pyx_v_j = 0; + PyObject *__pyx_v_e_id = 0; + PyObject *__pyx_v_f_id = 0; + PyObject *__pyx_v_n_f = 0; + PyObject *__pyx_v_N = 0; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_fcount = 0; + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_v_line = NULL; + PyObject *__pyx_v_fword = NULL; + PyObject *__pyx_v_eword = NULL; + PyObject *__pyx_v_score1 = NULL; + PyObject *__pyx_v_score2 = NULL; + PyObject *__pyx_v_index = NULL; + PyObject *__pyx_v_b = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *(*__pyx_t_14)(PyObject *); + Py_ssize_t __pyx_t_15; + int __pyx_t_16; + Py_ssize_t __pyx_t_17; + long __pyx_t_18; + long __pyx_t_19; + int __pyx_t_20; + double __pyx_t_21; + PyObject *__pyx_t_22 = NULL; + int __pyx_t_23; + int __pyx_t_24; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_text", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":277 + * cdef IntList fcount + * + * fcount = IntList() # <<<<<<<<<<<<<< + * with gzip_or_text(filename) as f: + * # first loop merely establishes size of array objects + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_fcount = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":278 + * + * fcount = IntList() + * with gzip_or_text(filename) as f: # <<<<<<<<<<<<<< + * # first loop merely establishes size of array objects + * for line in f: + */ + /*with:*/ { + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__gzip_or_text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __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[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_1); + __pyx_v_f = __pyx_t_1; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":280 + * with gzip_or_text(filename) as f: + * # first loop merely establishes size of array objects + * for line in f: # <<<<<<<<<<<<<< + * (fword, eword, score1, score2) = line.split() + * f_id = self.get_f_id(fword) + */ + if (PyList_CheckExact(__pyx_v_f) || PyTuple_CheckExact(__pyx_v_f)) { + __pyx_t_1 = __pyx_v_f; __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else { + __pyx_t_2 = __pyx_t_9(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF(__pyx_v_line); + __pyx_v_line = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":281 + * # first loop merely establishes size of array objects + * for line in f: + * (fword, eword, score1, score2) = line.split() # <<<<<<<<<<<<<< + * f_id = self.get_f_id(fword) + * e_id = self.get_e_id(eword) + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { + PyObject* sequence = __pyx_t_3; + if (likely(PyTuple_CheckExact(sequence))) { + if (unlikely(PyTuple_GET_SIZE(sequence) != 4)) { + if (PyTuple_GET_SIZE(sequence) > 4) __Pyx_RaiseTooManyValuesError(4); + else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_11 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_12 = PyTuple_GET_ITEM(sequence, 3); + } else { + if (unlikely(PyList_GET_SIZE(sequence) != 4)) { + if (PyList_GET_SIZE(sequence) > 4) __Pyx_RaiseTooManyValuesError(4); + else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + __pyx_t_2 = PyList_GET_ITEM(sequence, 0); + __pyx_t_10 = PyList_GET_ITEM(sequence, 1); + __pyx_t_11 = PyList_GET_ITEM(sequence, 2); + __pyx_t_12 = PyList_GET_ITEM(sequence, 3); + } + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_13 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_14 = Py_TYPE(__pyx_t_13)->tp_iternext; + index = 0; __pyx_t_2 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_2)) goto __pyx_L18_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + index = 1; __pyx_t_10 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_10)) goto __pyx_L18_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + index = 2; __pyx_t_11 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_11)) goto __pyx_L18_unpacking_failed; + __Pyx_GOTREF(__pyx_t_11); + index = 3; __pyx_t_12 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_12)) goto __pyx_L18_unpacking_failed; + __Pyx_GOTREF(__pyx_t_12); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_13), 4) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + goto __pyx_L19_unpacking_done; + __pyx_L18_unpacking_failed:; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_L19_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_fword); + __pyx_v_fword = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_v_eword); + __pyx_v_eword = __pyx_t_10; + __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_v_score1); + __pyx_v_score1 = __pyx_t_11; + __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_v_score2); + __pyx_v_score2 = __pyx_t_12; + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":282 + * for line in f: + * (fword, eword, score1, score2) = line.split() + * f_id = self.get_f_id(fword) # <<<<<<<<<<<<<< + * e_id = self.get_e_id(eword) + * while f_id >= len(fcount): + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_f_id); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_INCREF(__pyx_v_fword); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_v_fword); + __Pyx_GIVEREF(__pyx_v_fword); + __pyx_t_11 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_v_f_id); + __pyx_v_f_id = __pyx_t_11; + __pyx_t_11 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":283 + * (fword, eword, score1, score2) = line.split() + * f_id = self.get_f_id(fword) + * e_id = self.get_e_id(eword) # <<<<<<<<<<<<<< + * while f_id >= len(fcount): + * fcount.append(0) + */ + __pyx_t_11 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_e_id); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_INCREF(__pyx_v_eword); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_v_eword); + __Pyx_GIVEREF(__pyx_v_eword); + __pyx_t_3 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_v_e_id); + __pyx_v_e_id = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":284 + * f_id = self.get_f_id(fword) + * e_id = self.get_e_id(eword) + * while f_id >= len(fcount): # <<<<<<<<<<<<<< + * fcount.append(0) + * fcount.arr[f_id] = fcount.arr[f_id] + 1 + */ + while (1) { + __pyx_t_15 = PyObject_Length(((PyObject *)__pyx_v_fcount)); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_15); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = PyObject_RichCompare(__pyx_v_f_id, __pyx_t_3, Py_GE); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (!__pyx_t_16) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":285 + * e_id = self.get_e_id(eword) + * while f_id >= len(fcount): + * fcount.append(0) # <<<<<<<<<<<<<< + * fcount.arr[f_id] = fcount.arr[f_id] + 1 + * + */ + __pyx_t_12 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_fcount), __pyx_int_0); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":286 + * while f_id >= len(fcount): + * fcount.append(0) + * fcount.arr[f_id] = fcount.arr[f_id] + 1 # <<<<<<<<<<<<<< + * + * # Allocate space for dictionary in arrays + */ + __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + (__pyx_v_fcount->arr[__pyx_t_17]) = ((__pyx_v_fcount->arr[__pyx_t_15]) + 1); + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":289 + * + * # Allocate space for dictionary in arrays + * N = 0 # <<<<<<<<<<<<<< + * n_f = len(fcount) + * self.f_index = IntList(initial_len=n_f+1) + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_N = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":290 + * # Allocate space for dictionary in arrays + * N = 0 + * n_f = len(fcount) # <<<<<<<<<<<<<< + * self.f_index = IntList(initial_len=n_f+1) + * for i from 0 <= i < n_f: + */ + __pyx_t_8 = PyObject_Length(((PyObject *)__pyx_v_fcount)); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_n_f = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":291 + * N = 0 + * n_f = len(fcount) + * self.f_index = IntList(initial_len=n_f+1) # <<<<<<<<<<<<<< + * for i from 0 <= i < n_f: + * self.f_index.arr[i] = N + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_12 = PyNumber_Add(__pyx_v_n_f, __pyx_int_1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_12) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_GOTREF(__pyx_v_self->f_index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->f_index)); + __pyx_v_self->f_index = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_12); + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":292 + * n_f = len(fcount) + * self.f_index = IntList(initial_len=n_f+1) + * for i from 0 <= i < n_f: # <<<<<<<<<<<<<< + * self.f_index.arr[i] = N + * N = N + fcount.arr[i] + */ + __pyx_t_18 = __Pyx_PyInt_AsLong(__pyx_v_n_f); if (unlikely((__pyx_t_18 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_18; __pyx_t_19++) { + __pyx_t_12 = PyInt_FromLong(__pyx_t_19); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_12; + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":293 + * self.f_index = IntList(initial_len=n_f+1) + * for i from 0 <= i < n_f: + * self.f_index.arr[i] = N # <<<<<<<<<<<<<< + * N = N + fcount.arr[i] + * fcount.arr[i] = 0 + */ + __pyx_t_20 = __Pyx_PyInt_AsInt(__pyx_v_N); if (unlikely((__pyx_t_20 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + (__pyx_v_self->f_index->arr[__pyx_t_8]) = __pyx_t_20; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":294 + * for i from 0 <= i < n_f: + * self.f_index.arr[i] = N + * N = N + fcount.arr[i] # <<<<<<<<<<<<<< + * fcount.arr[i] = 0 + * self.f_index.arr[n_f] = N + */ + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_12 = PyInt_FromLong((__pyx_v_fcount->arr[__pyx_t_8])); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_1 = PyNumber_Add(__pyx_v_N, __pyx_t_12); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_v_N); + __pyx_v_N = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":295 + * self.f_index.arr[i] = N + * N = N + fcount.arr[i] + * fcount.arr[i] = 0 # <<<<<<<<<<<<<< + * self.f_index.arr[n_f] = N + * self.e_index = IntList(initial_len=N) + */ + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + (__pyx_v_fcount->arr[__pyx_t_8]) = 0; + __pyx_t_19 = __Pyx_PyInt_AsLong(__pyx_v_i); if (unlikely((__pyx_t_19 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":292 + * n_f = len(fcount) + * self.f_index = IntList(initial_len=n_f+1) + * for i from 0 <= i < n_f: # <<<<<<<<<<<<<< + * self.f_index.arr[i] = N + * N = N + fcount.arr[i] + */ + __pyx_t_1 = PyInt_FromLong(__pyx_t_19); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":296 + * N = N + fcount.arr[i] + * fcount.arr[i] = 0 + * self.f_index.arr[n_f] = N # <<<<<<<<<<<<<< + * self.e_index = IntList(initial_len=N) + * self.col1 = FloatList(initial_len=N) + */ + __pyx_t_20 = __Pyx_PyInt_AsInt(__pyx_v_N); if (unlikely((__pyx_t_20 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_n_f); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + (__pyx_v_self->f_index->arr[__pyx_t_8]) = __pyx_t_20; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":297 + * fcount.arr[i] = 0 + * self.f_index.arr[n_f] = N + * self.e_index = IntList(initial_len=N) # <<<<<<<<<<<<<< + * self.col1 = FloatList(initial_len=N) + * self.col2 = FloatList(initial_len=N) + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_v_N) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_12 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_GOTREF(__pyx_v_self->e_index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->e_index)); + __pyx_v_self->e_index = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_12); + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":298 + * self.f_index.arr[n_f] = N + * self.e_index = IntList(initial_len=N) + * self.col1 = FloatList(initial_len=N) # <<<<<<<<<<<<<< + * self.col2 = FloatList(initial_len=N) + * + */ + __pyx_t_12 = PyDict_New(); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_12)); + if (PyDict_SetItem(__pyx_t_12, ((PyObject *)__pyx_n_s__initial_len), __pyx_v_N) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_FloatList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_12)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->col1); + __Pyx_DECREF(((PyObject *)__pyx_v_self->col1)); + __pyx_v_self->col1 = ((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":299 + * self.e_index = IntList(initial_len=N) + * self.col1 = FloatList(initial_len=N) + * self.col2 = FloatList(initial_len=N) # <<<<<<<<<<<<<< + * + * # Re-read file, placing words into buckets + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_v_N) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_12 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_FloatList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_GOTREF(__pyx_v_self->col2); + __Pyx_DECREF(((PyObject *)__pyx_v_self->col2)); + __pyx_v_self->col2 = ((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_t_12); + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":302 + * + * # Re-read file, placing words into buckets + * f.seek(0) # <<<<<<<<<<<<<< + * for line in f: + * (fword, eword, score1, score2) = line.split() + */ + __pyx_t_12 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__seek); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_1 = PyObject_Call(__pyx_t_12, ((PyObject *)__pyx_k_tuple_40), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":303 + * # Re-read file, placing words into buckets + * f.seek(0) + * for line in f: # <<<<<<<<<<<<<< + * (fword, eword, score1, score2) = line.split() + * f_id = self.get_f_id(fword) + */ + if (PyList_CheckExact(__pyx_v_f) || PyTuple_CheckExact(__pyx_v_f)) { + __pyx_t_1 = __pyx_v_f; __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_12 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_12); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_12 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_12); __pyx_t_8++; + } else { + __pyx_t_12 = __pyx_t_9(__pyx_t_1); + if (unlikely(!__pyx_t_12)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_12); + } + __Pyx_XDECREF(__pyx_v_line); + __pyx_v_line = __pyx_t_12; + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":304 + * f.seek(0) + * for line in f: + * (fword, eword, score1, score2) = line.split() # <<<<<<<<<<<<<< + * f_id = self.get_f_id(fword) + * e_id = self.get_e_id(eword) + */ + __pyx_t_12 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_3 = PyObject_Call(__pyx_t_12, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { + PyObject* sequence = __pyx_t_3; + if (likely(PyTuple_CheckExact(sequence))) { + if (unlikely(PyTuple_GET_SIZE(sequence) != 4)) { + if (PyTuple_GET_SIZE(sequence) > 4) __Pyx_RaiseTooManyValuesError(4); + else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + __pyx_t_12 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 3); + } else { + if (unlikely(PyList_GET_SIZE(sequence) != 4)) { + if (PyList_GET_SIZE(sequence) > 4) __Pyx_RaiseTooManyValuesError(4); + else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + __pyx_t_12 = PyList_GET_ITEM(sequence, 0); + __pyx_t_11 = PyList_GET_ITEM(sequence, 1); + __pyx_t_10 = PyList_GET_ITEM(sequence, 2); + __pyx_t_2 = PyList_GET_ITEM(sequence, 3); + } + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_13 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_14 = Py_TYPE(__pyx_t_13)->tp_iternext; + index = 0; __pyx_t_12 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_12)) goto __pyx_L26_unpacking_failed; + __Pyx_GOTREF(__pyx_t_12); + index = 1; __pyx_t_11 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_11)) goto __pyx_L26_unpacking_failed; + __Pyx_GOTREF(__pyx_t_11); + index = 2; __pyx_t_10 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_10)) goto __pyx_L26_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + index = 3; __pyx_t_2 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_2)) goto __pyx_L26_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_13), 4) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + goto __pyx_L27_unpacking_done; + __pyx_L26_unpacking_failed:; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_L27_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_fword); + __pyx_v_fword = __pyx_t_12; + __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_v_eword); + __pyx_v_eword = __pyx_t_11; + __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_v_score1); + __pyx_v_score1 = __pyx_t_10; + __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_v_score2); + __pyx_v_score2 = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":305 + * for line in f: + * (fword, eword, score1, score2) = line.split() + * f_id = self.get_f_id(fword) # <<<<<<<<<<<<<< + * e_id = self.get_e_id(eword) + * index = self.f_index.arr[f_id] + fcount.arr[f_id] + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_f_id); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_fword); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_fword); + __Pyx_GIVEREF(__pyx_v_fword); + __pyx_t_10 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_v_f_id); + __pyx_v_f_id = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":306 + * (fword, eword, score1, score2) = line.split() + * f_id = self.get_f_id(fword) + * e_id = self.get_e_id(eword) # <<<<<<<<<<<<<< + * index = self.f_index.arr[f_id] + fcount.arr[f_id] + * fcount.arr[f_id] = fcount.arr[f_id] + 1 + */ + __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_e_id); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_eword); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_eword); + __Pyx_GIVEREF(__pyx_v_eword); + __pyx_t_3 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_v_e_id); + __pyx_v_e_id = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":307 + * f_id = self.get_f_id(fword) + * e_id = self.get_e_id(eword) + * index = self.f_index.arr[f_id] + fcount.arr[f_id] # <<<<<<<<<<<<<< + * fcount.arr[f_id] = fcount.arr[f_id] + 1 + * self.e_index.arr[index] = int(e_id) + */ + __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_3 = PyInt_FromLong(((__pyx_v_self->f_index->arr[__pyx_t_15]) + (__pyx_v_fcount->arr[__pyx_t_17]))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_v_index); + __pyx_v_index = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":308 + * e_id = self.get_e_id(eword) + * index = self.f_index.arr[f_id] + fcount.arr[f_id] + * fcount.arr[f_id] = fcount.arr[f_id] + 1 # <<<<<<<<<<<<<< + * self.e_index.arr[index] = int(e_id) + * self.col1[index] = float(score1) + */ + __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + (__pyx_v_fcount->arr[__pyx_t_15]) = ((__pyx_v_fcount->arr[__pyx_t_17]) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":309 + * index = self.f_index.arr[f_id] + fcount.arr[f_id] + * fcount.arr[f_id] = fcount.arr[f_id] + 1 + * self.e_index.arr[index] = int(e_id) # <<<<<<<<<<<<<< + * self.col1[index] = float(score1) + * self.col2[index] = float(score2) + */ + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_e_id); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_e_id); + __Pyx_GIVEREF(__pyx_v_e_id); + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_20 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_20 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_v_index); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + (__pyx_v_self->e_index->arr[__pyx_t_17]) = __pyx_t_20; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":310 + * fcount.arr[f_id] = fcount.arr[f_id] + 1 + * self.e_index.arr[index] = int(e_id) + * self.col1[index] = float(score1) # <<<<<<<<<<<<<< + * self.col2[index] = float(score2) + * + */ + __pyx_t_21 = __Pyx_PyObject_AsDouble(__pyx_v_score1); if (unlikely(__pyx_t_21 == ((double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyFloat_FromDouble(__pyx_t_21); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyObject_SetItem(((PyObject *)__pyx_v_self->col1), __pyx_v_index, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":311 + * self.e_index.arr[index] = int(e_id) + * self.col1[index] = float(score1) + * self.col2[index] = float(score2) # <<<<<<<<<<<<<< + * + * # Sort buckets by eword + */ + __pyx_t_21 = __Pyx_PyObject_AsDouble(__pyx_v_score2); if (unlikely(__pyx_t_21 == ((double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyFloat_FromDouble(__pyx_t_21); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyObject_SetItem(((PyObject *)__pyx_v_self->col2), __pyx_v_index, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":278 + * + * fcount = IntList() + * with gzip_or_text(filename) as f: # <<<<<<<<<<<<<< + * # first loop merely establishes size of array objects + * for line in f: + */ + /*except:*/ { + __Pyx_AddTraceback("_cdec_sa.BiLex.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_22 = PyObject_Call(__pyx_t_4, __pyx_t_10, NULL); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_22)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_22); + __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_22); + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_23 = (!__pyx_t_16); + if (__pyx_t_23) { + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_ErrRestore(__pyx_t_1, __pyx_t_2, __pyx_t_3); + __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_3 = 0; + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L30; + } + __pyx_L30:; + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_4) { + __pyx_t_7 = PyObject_Call(__pyx_t_4, __pyx_k_tuple_41, NULL); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_23 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_23 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L31; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L1_error; + __pyx_L31:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":314 + * + * # Sort buckets by eword + * for b from 0 <= b < n_f: # <<<<<<<<<<<<<< + * i = self.f_index.arr[b] + * j = self.f_index.arr[b+1] + */ + if (unlikely(!__pyx_v_n_f)) { __Pyx_RaiseUnboundLocalError("n_f"); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } + __pyx_t_19 = __Pyx_PyInt_AsLong(__pyx_v_n_f); if (unlikely((__pyx_t_19 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_19; __pyx_t_18++) { + __pyx_t_3 = PyInt_FromLong(__pyx_t_18); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_v_b); + __pyx_v_b = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":315 + * # Sort buckets by eword + * for b from 0 <= b < n_f: + * i = self.f_index.arr[b] # <<<<<<<<<<<<<< + * j = self.f_index.arr[b+1] + * self.qsort(i,j, "") + */ + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_b); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong((__pyx_v_self->f_index->arr[__pyx_t_8])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":316 + * for b from 0 <= b < n_f: + * i = self.f_index.arr[b] + * j = self.f_index.arr[b+1] # <<<<<<<<<<<<<< + * self.qsort(i,j, "") + * + */ + __pyx_t_3 = PyNumber_Add(__pyx_v_b, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_3); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromLong((__pyx_v_self->f_index->arr[__pyx_t_8])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_v_j); + __pyx_v_j = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":317 + * i = self.f_index.arr[b] + * j = self.f_index.arr[b+1] + * self.qsort(i,j, "") # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_20 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_20 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_24 = __Pyx_PyInt_AsInt(__pyx_v_j); if (unlikely((__pyx_t_24 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = ((PyObject *)__pyx_kp_s_42); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->qsort(__pyx_v_self, __pyx_t_20, __pyx_t_24, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_18 = __Pyx_PyInt_AsLong(__pyx_v_b); if (unlikely((__pyx_t_18 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":314 + * + * # Sort buckets by eword + * for b from 0 <= b < n_f: # <<<<<<<<<<<<<< + * i = self.f_index.arr[b] + * j = self.f_index.arr[b+1] + */ + __pyx_t_2 = PyInt_FromLong(__pyx_t_18); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_v_b); + __pyx_v_b = __pyx_t_2; + __pyx_t_2 = 0; + + __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_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_AddTraceback("_cdec_sa.BiLex.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_j); + __Pyx_XDECREF(__pyx_v_e_id); + __Pyx_XDECREF(__pyx_v_f_id); + __Pyx_XDECREF(__pyx_v_n_f); + __Pyx_XDECREF(__pyx_v_N); + __Pyx_XDECREF((PyObject *)__pyx_v_fcount); + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_line); + __Pyx_XDECREF(__pyx_v_fword); + __Pyx_XDECREF(__pyx_v_eword); + __Pyx_XDECREF(__pyx_v_score1); + __Pyx_XDECREF(__pyx_v_score2); + __Pyx_XDECREF(__pyx_v_index); + __Pyx_XDECREF(__pyx_v_b); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":320 + * + * + * cdef swap(self, int i, int j): # <<<<<<<<<<<<<< + * cdef int itmp + * cdef float ftmp + */ + +static PyObject *__pyx_f_8_cdec_sa_5BiLex_swap(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, int __pyx_v_i, int __pyx_v_j) { + int __pyx_v_itmp; + float __pyx_v_ftmp; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("swap", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":324 + * cdef float ftmp + * + * if i == j: # <<<<<<<<<<<<<< + * return + * + */ + __pyx_t_1 = (__pyx_v_i == __pyx_v_j); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":325 + * + * if i == j: + * return # <<<<<<<<<<<<<< + * + * itmp = self.e_index.arr[i] + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":327 + * return + * + * itmp = self.e_index.arr[i] # <<<<<<<<<<<<<< + * self.e_index.arr[i] = self.e_index.arr[j] + * self.e_index.arr[j] = itmp + */ + __pyx_v_itmp = (__pyx_v_self->e_index->arr[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":328 + * + * itmp = self.e_index.arr[i] + * self.e_index.arr[i] = self.e_index.arr[j] # <<<<<<<<<<<<<< + * self.e_index.arr[j] = itmp + * + */ + (__pyx_v_self->e_index->arr[__pyx_v_i]) = (__pyx_v_self->e_index->arr[__pyx_v_j]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":329 + * itmp = self.e_index.arr[i] + * self.e_index.arr[i] = self.e_index.arr[j] + * self.e_index.arr[j] = itmp # <<<<<<<<<<<<<< + * + * ftmp = self.col1.arr[i] + */ + (__pyx_v_self->e_index->arr[__pyx_v_j]) = __pyx_v_itmp; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":331 + * self.e_index.arr[j] = itmp + * + * ftmp = self.col1.arr[i] # <<<<<<<<<<<<<< + * self.col1.arr[i] = self.col1.arr[j] + * self.col1.arr[j] = ftmp + */ + __pyx_v_ftmp = (__pyx_v_self->col1->arr[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":332 + * + * ftmp = self.col1.arr[i] + * self.col1.arr[i] = self.col1.arr[j] # <<<<<<<<<<<<<< + * self.col1.arr[j] = ftmp + * + */ + (__pyx_v_self->col1->arr[__pyx_v_i]) = (__pyx_v_self->col1->arr[__pyx_v_j]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":333 + * ftmp = self.col1.arr[i] + * self.col1.arr[i] = self.col1.arr[j] + * self.col1.arr[j] = ftmp # <<<<<<<<<<<<<< + * + * ftmp = self.col2.arr[i] + */ + (__pyx_v_self->col1->arr[__pyx_v_j]) = __pyx_v_ftmp; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":335 + * self.col1.arr[j] = ftmp + * + * ftmp = self.col2.arr[i] # <<<<<<<<<<<<<< + * self.col2.arr[i] = self.col2.arr[j] + * self.col2.arr[j] = ftmp + */ + __pyx_v_ftmp = (__pyx_v_self->col2->arr[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":336 + * + * ftmp = self.col2.arr[i] + * self.col2.arr[i] = self.col2.arr[j] # <<<<<<<<<<<<<< + * self.col2.arr[j] = ftmp + * + */ + (__pyx_v_self->col2->arr[__pyx_v_i]) = (__pyx_v_self->col2->arr[__pyx_v_j]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":337 + * ftmp = self.col2.arr[i] + * self.col2.arr[i] = self.col2.arr[j] + * self.col2.arr[j] = ftmp # <<<<<<<<<<<<<< + * + * + */ + (__pyx_v_self->col2->arr[__pyx_v_j]) = __pyx_v_ftmp; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":340 + * + * + * cdef qsort(self, int i, int j, pad): # <<<<<<<<<<<<<< + * cdef int pval, p + * + */ + +static PyObject *__pyx_f_8_cdec_sa_5BiLex_qsort(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, int __pyx_v_i, int __pyx_v_j, PyObject *__pyx_v_pad) { + int __pyx_v_pval; + int __pyx_v_p; + long __pyx_v_k; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("qsort", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":343 + * cdef int pval, p + * + * if i > j: # <<<<<<<<<<<<<< + * raise Exception("Sort error in CLex") + * if i == j: #empty interval + */ + __pyx_t_1 = (__pyx_v_i > __pyx_v_j); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":344 + * + * if i > j: + * raise Exception("Sort error in CLex") # <<<<<<<<<<<<<< + * if i == j: #empty interval + * return + */ + __pyx_t_2 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_k_tuple_44), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":345 + * if i > j: + * raise Exception("Sort error in CLex") + * if i == j: #empty interval # <<<<<<<<<<<<<< + * return + * if i == j-1: # singleton interval + */ + __pyx_t_1 = (__pyx_v_i == __pyx_v_j); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":346 + * raise Exception("Sort error in CLex") + * if i == j: #empty interval + * return # <<<<<<<<<<<<<< + * if i == j-1: # singleton interval + * return + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":347 + * if i == j: #empty interval + * return + * if i == j-1: # singleton interval # <<<<<<<<<<<<<< + * return + * + */ + __pyx_t_1 = (__pyx_v_i == (__pyx_v_j - 1)); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":348 + * return + * if i == j-1: # singleton interval + * return # <<<<<<<<<<<<<< + * + * p = (i+j)/2 + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":350 + * return + * + * p = (i+j)/2 # <<<<<<<<<<<<<< + * pval = self.e_index.arr[p] + * self.swap(i, p) + */ + __pyx_v_p = __Pyx_div_long((__pyx_v_i + __pyx_v_j), 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":351 + * + * p = (i+j)/2 + * pval = self.e_index.arr[p] # <<<<<<<<<<<<<< + * self.swap(i, p) + * p = i + */ + __pyx_v_pval = (__pyx_v_self->e_index->arr[__pyx_v_p]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":352 + * p = (i+j)/2 + * pval = self.e_index.arr[p] + * self.swap(i, p) # <<<<<<<<<<<<<< + * p = i + * for k from i+1 <= k < j: + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->swap(__pyx_v_self, __pyx_v_i, __pyx_v_p); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":353 + * pval = self.e_index.arr[p] + * self.swap(i, p) + * p = i # <<<<<<<<<<<<<< + * for k from i+1 <= k < j: + * if pval >= self.e_index.arr[k]: + */ + __pyx_v_p = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":354 + * self.swap(i, p) + * p = i + * for k from i+1 <= k < j: # <<<<<<<<<<<<<< + * if pval >= self.e_index.arr[k]: + * self.swap(p+1, k) + */ + __pyx_t_3 = __pyx_v_j; + for (__pyx_v_k = (__pyx_v_i + 1); __pyx_v_k < __pyx_t_3; __pyx_v_k++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":355 + * p = i + * for k from i+1 <= k < j: + * if pval >= self.e_index.arr[k]: # <<<<<<<<<<<<<< + * self.swap(p+1, k) + * self.swap(p, p+1) + */ + __pyx_t_1 = (__pyx_v_pval >= (__pyx_v_self->e_index->arr[__pyx_v_k])); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":356 + * for k from i+1 <= k < j: + * if pval >= self.e_index.arr[k]: + * self.swap(p+1, k) # <<<<<<<<<<<<<< + * self.swap(p, p+1) + * p = p + 1 + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->swap(__pyx_v_self, (__pyx_v_p + 1), __pyx_v_k); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":357 + * if pval >= self.e_index.arr[k]: + * self.swap(p+1, k) + * self.swap(p, p+1) # <<<<<<<<<<<<<< + * p = p + 1 + * self.qsort(i,p, pad+" ") + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->swap(__pyx_v_self, __pyx_v_p, (__pyx_v_p + 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":358 + * self.swap(p+1, k) + * self.swap(p, p+1) + * p = p + 1 # <<<<<<<<<<<<<< + * self.qsort(i,p, pad+" ") + * self.qsort(p+1,j, pad+" ") + */ + __pyx_v_p = (__pyx_v_p + 1); + goto __pyx_L8; + } + __pyx_L8:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":359 + * self.swap(p, p+1) + * p = p + 1 + * self.qsort(i,p, pad+" ") # <<<<<<<<<<<<<< + * self.qsort(p+1,j, pad+" ") + * + */ + __pyx_t_2 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->qsort(__pyx_v_self, __pyx_v_i, __pyx_v_p, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":360 + * p = p + 1 + * self.qsort(i,p, pad+" ") + * self.qsort(p+1,j, pad+" ") # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_4 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->qsort(__pyx_v_self, (__pyx_v_p + 1), __pyx_v_j, __pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec_sa.BiLex.qsort", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_5BiLex_13write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_5BiLex_13write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_enhanced (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.BiLex.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_5BiLex_12write_enhanced(((struct __pyx_obj_8_cdec_sa_BiLex *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":363 + * + * + * def write_enhanced(self, char* filename): # <<<<<<<<<<<<<< + * with open(filename, "w") as f: + * for i in self.f_index: + */ + +static PyObject *__pyx_pf_8_cdec_sa_5BiLex_12write_enhanced(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_v_i = NULL; + PyObject *__pyx_v_s1 = NULL; + PyObject *__pyx_v_s2 = NULL; + PyObject *__pyx_v_w = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *(*__pyx_t_13)(PyObject *); + int __pyx_t_14; + PyObject *__pyx_t_15 = NULL; + int __pyx_t_16; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_enhanced", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":364 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * for i in self.f_index: + * f.write("%d " % i) + */ + /*with:*/ { + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_f = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":365 + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: + * for i in self.f_index: # <<<<<<<<<<<<<< + * f.write("%d " % i) + * f.write("\n") + */ + if (PyList_CheckExact(((PyObject *)__pyx_v_self->f_index)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->f_index))) { + __pyx_t_4 = ((PyObject *)__pyx_v_self->f_index); __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(((PyObject *)__pyx_v_self->f_index)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; + } else { + __pyx_t_1 = __pyx_t_9(__pyx_t_4); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":366 + * with open(filename, "w") as f: + * for i in self.f_index: + * f.write("%d " % i) # <<<<<<<<<<<<<< + * f.write("\n") + * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":367 + * for i in self.f_index: + * f.write("%d " % i) + * f.write("\n") # <<<<<<<<<<<<<< + * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): + * f.write("%d %f %f " % (i, s1, s2)) + */ + __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_46), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":368 + * f.write("%d " % i) + * f.write("\n") + * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): # <<<<<<<<<<<<<< + * f.write("%d %f %f " % (i, s1, s2)) + * f.write("\n") + */ + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_v_self->e_index)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self->e_index)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->e_index)); + __Pyx_INCREF(((PyObject *)__pyx_v_self->col1)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_self->col1)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->col1)); + __Pyx_INCREF(((PyObject *)__pyx_v_self->col2)); + PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_self->col2)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->col2)); + __pyx_t_4 = PyObject_Call(__pyx_builtin_zip, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + if (PyList_CheckExact(__pyx_t_4) || PyTuple_CheckExact(__pyx_t_4)) { + __pyx_t_2 = __pyx_t_4; __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_4); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_4); __pyx_t_8++; + } else { + __pyx_t_4 = __pyx_t_9(__pyx_t_2); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) { + PyObject* sequence = __pyx_t_4; + if (likely(PyTuple_CheckExact(sequence))) { + if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { + if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_11 = PyTuple_GET_ITEM(sequence, 2); + } else { + if (unlikely(PyList_GET_SIZE(sequence) != 3)) { + if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + __pyx_t_10 = PyList_GET_ITEM(sequence, 0); + __pyx_t_1 = PyList_GET_ITEM(sequence, 1); + __pyx_t_11 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_12 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_13 = Py_TYPE(__pyx_t_12)->tp_iternext; + index = 0; __pyx_t_10 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_10)) goto __pyx_L20_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + index = 1; __pyx_t_1 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_1)) goto __pyx_L20_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 2; __pyx_t_11 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_11)) goto __pyx_L20_unpacking_failed; + __Pyx_GOTREF(__pyx_t_11); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 3) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L21_unpacking_done; + __pyx_L20_unpacking_failed:; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_L21_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_10; + __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_v_s1); + __pyx_v_s1 = __pyx_t_1; + __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_v_s2); + __pyx_v_s2 = __pyx_t_11; + __pyx_t_11 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":369 + * f.write("\n") + * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): + * f.write("%d %f %f " % (i, s1, s2)) # <<<<<<<<<<<<<< + * f.write("\n") + * for i, w in enumerate(self.id2fword): + */ + __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_INCREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + __Pyx_INCREF(__pyx_v_s1); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_v_s1); + __Pyx_GIVEREF(__pyx_v_s1); + __Pyx_INCREF(__pyx_v_s2); + PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_v_s2); + __Pyx_GIVEREF(__pyx_v_s2); + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_47), ((PyObject *)__pyx_t_11)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; + __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_11, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":370 + * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): + * f.write("%d %f %f " % (i, s1, s2)) + * f.write("\n") # <<<<<<<<<<<<<< + * for i, w in enumerate(self.id2fword): + * f.write("%d %s " % (i, w)) + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_48), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":371 + * f.write("%d %f %f " % (i, s1, s2)) + * f.write("\n") + * for i, w in enumerate(self.id2fword): # <<<<<<<<<<<<<< + * f.write("%d %s " % (i, w)) + * f.write("\n") + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_1 = __pyx_int_0; + if (PyList_CheckExact(__pyx_v_self->id2fword) || PyTuple_CheckExact(__pyx_v_self->id2fword)) { + __pyx_t_2 = __pyx_v_self->id2fword; __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_self->id2fword); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_11 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_11); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_11 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_11); __pyx_t_8++; + } else { + __pyx_t_11 = __pyx_t_9(__pyx_t_2); + if (unlikely(!__pyx_t_11)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_11); + } + __Pyx_XDECREF(__pyx_v_w); + __pyx_v_w = __pyx_t_11; + __pyx_t_11 = 0; + __Pyx_INCREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_1; + __pyx_t_11 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_1); + __pyx_t_1 = __pyx_t_11; + __pyx_t_11 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":372 + * f.write("\n") + * for i, w in enumerate(self.id2fword): + * f.write("%d %s " % (i, w)) # <<<<<<<<<<<<<< + * f.write("\n") + * for i, w in enumerate(self.id2eword): + */ + __pyx_t_11 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + __Pyx_INCREF(__pyx_v_w); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_w); + __Pyx_GIVEREF(__pyx_v_w); + __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_49), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_10)); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_10)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); + __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":373 + * for i, w in enumerate(self.id2fword): + * f.write("%d %s " % (i, w)) + * f.write("\n") # <<<<<<<<<<<<<< + * for i, w in enumerate(self.id2eword): + * f.write("%d %s " % (i, w)) + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_50), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":374 + * f.write("%d %s " % (i, w)) + * f.write("\n") + * for i, w in enumerate(self.id2eword): # <<<<<<<<<<<<<< + * f.write("%d %s " % (i, w)) + * f.write("\n") + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_2 = __pyx_int_0; + if (PyList_CheckExact(__pyx_v_self->id2eword) || PyTuple_CheckExact(__pyx_v_self->id2eword)) { + __pyx_t_1 = __pyx_v_self->id2eword; __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_self->id2eword); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_10 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_10); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_10); __pyx_t_8++; + } else { + __pyx_t_10 = __pyx_t_9(__pyx_t_1); + if (unlikely(!__pyx_t_10)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_10); + } + __Pyx_XDECREF(__pyx_v_w); + __pyx_v_w = __pyx_t_10; + __pyx_t_10 = 0; + __Pyx_INCREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_2; + __pyx_t_10 = PyNumber_Add(__pyx_t_2, __pyx_int_1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); + __pyx_t_2 = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":375 + * f.write("\n") + * for i, w in enumerate(self.id2eword): + * f.write("%d %s " % (i, w)) # <<<<<<<<<<<<<< + * f.write("\n") + * + */ + __pyx_t_10 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + __Pyx_INCREF(__pyx_v_w); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_w); + __Pyx_GIVEREF(__pyx_v_w); + __pyx_t_11 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_49), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_11)); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_11)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_11)); + __pyx_t_11 = 0; + __pyx_t_11 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":376 + * for i, w in enumerate(self.id2eword): + * f.write("%d %s " % (i, w)) + * f.write("\n") # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_51), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":364 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * for i in self.f_index: + * f.write("%d " % i) + */ + /*except:*/ { + __Pyx_AddTraceback("_cdec_sa.BiLex.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_2, &__pyx_t_11) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_11); + __Pyx_GIVEREF(__pyx_t_11); + __pyx_t_15 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L9_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[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_16 = (!__pyx_t_14); + if (__pyx_t_16) { + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_11); + __Pyx_ErrRestore(__pyx_t_1, __pyx_t_2, __pyx_t_11); + __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_11 = 0; + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L28; + } + __pyx_L28:; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_52, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L29; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L29:; + } + + __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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("_cdec_sa.BiLex.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_s1); + __Pyx_XDECREF(__pyx_v_s2); + __Pyx_XDECREF(__pyx_v_w); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_5BiLex_15get_score(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_5BiLex_15get_score(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_fword = 0; + PyObject *__pyx_v_eword = 0; + PyObject *__pyx_v_col = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fword,&__pyx_n_s__eword,&__pyx_n_s__col,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_score (wrapper)", 0); + { + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fword); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__eword); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("get_score", 1, 3, 3, 1); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__col); + if (likely(values[2])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("get_score", 1, 3, 3, 2); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_score") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_fword = values[0]; + __pyx_v_eword = values[1]; + __pyx_v_col = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("get_score", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.BiLex.get_score", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_5BiLex_14get_score(((struct __pyx_obj_8_cdec_sa_BiLex *)__pyx_v_self), __pyx_v_fword, __pyx_v_eword, __pyx_v_col); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":379 + * + * + * def get_score(self, fword, eword, col): # <<<<<<<<<<<<<< + * cdef e_id, f_id, low, high, midpoint, val + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_5BiLex_14get_score(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_fword, PyObject *__pyx_v_eword, PyObject *__pyx_v_col) { + PyObject *__pyx_v_e_id = 0; + PyObject *__pyx_v_f_id = 0; + PyObject *__pyx_v_low = 0; + PyObject *__pyx_v_high = 0; + PyObject *__pyx_v_midpoint = 0; + PyObject *__pyx_v_val = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_score", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":382 + * cdef e_id, f_id, low, high, midpoint, val + * + * if eword not in self.eword2id: # <<<<<<<<<<<<<< + * return None + * if fword not in self.fword2id: + */ + __pyx_t_1 = (__Pyx_NegateNonNeg(PySequence_Contains(__pyx_v_self->eword2id, __pyx_v_eword))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 382; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":383 + * + * if eword not in self.eword2id: + * return None # <<<<<<<<<<<<<< + * if fword not in self.fword2id: + * return None + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_None); + __pyx_r = Py_None; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":384 + * if eword not in self.eword2id: + * return None + * if fword not in self.fword2id: # <<<<<<<<<<<<<< + * return None + * f_id = self.fword2id[fword] + */ + __pyx_t_1 = (__Pyx_NegateNonNeg(PySequence_Contains(__pyx_v_self->fword2id, __pyx_v_fword))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":385 + * return None + * if fword not in self.fword2id: + * return None # <<<<<<<<<<<<<< + * f_id = self.fword2id[fword] + * e_id = self.eword2id[eword] + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_None); + __pyx_r = Py_None; + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":386 + * if fword not in self.fword2id: + * return None + * f_id = self.fword2id[fword] # <<<<<<<<<<<<<< + * e_id = self.eword2id[eword] + * low = self.f_index.arr[f_id] + */ + __pyx_t_2 = PyObject_GetItem(__pyx_v_self->fword2id, __pyx_v_fword); if (!__pyx_t_2) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_f_id = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":387 + * return None + * f_id = self.fword2id[fword] + * e_id = self.eword2id[eword] # <<<<<<<<<<<<<< + * low = self.f_index.arr[f_id] + * high = self.f_index.arr[f_id+1] + */ + __pyx_t_2 = PyObject_GetItem(__pyx_v_self->eword2id, __pyx_v_eword); if (!__pyx_t_2) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_e_id = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":388 + * f_id = self.fword2id[fword] + * e_id = self.eword2id[eword] + * low = self.f_index.arr[f_id] # <<<<<<<<<<<<<< + * high = self.f_index.arr[f_id+1] + * while high - low > 0: + */ + __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 388; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->f_index->arr[__pyx_t_3])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 388; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_low = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":389 + * e_id = self.eword2id[eword] + * low = self.f_index.arr[f_id] + * high = self.f_index.arr[f_id+1] # <<<<<<<<<<<<<< + * while high - low > 0: + * midpoint = (low+high)/2 + */ + __pyx_t_2 = PyNumber_Add(__pyx_v_f_id, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->f_index->arr[__pyx_t_3])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_high = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":390 + * low = self.f_index.arr[f_id] + * high = self.f_index.arr[f_id+1] + * while high - low > 0: # <<<<<<<<<<<<<< + * midpoint = (low+high)/2 + * val = self.e_index.arr[midpoint] + */ + while (1) { + __pyx_t_2 = PyNumber_Subtract(__pyx_v_high, __pyx_v_low); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_GT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (!__pyx_t_1) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":391 + * high = self.f_index.arr[f_id+1] + * while high - low > 0: + * midpoint = (low+high)/2 # <<<<<<<<<<<<<< + * val = self.e_index.arr[midpoint] + * if val == e_id: + */ + __pyx_t_4 = PyNumber_Add(__pyx_v_low, __pyx_v_high); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_int_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_v_midpoint); + __pyx_v_midpoint = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":392 + * while high - low > 0: + * midpoint = (low+high)/2 + * val = self.e_index.arr[midpoint] # <<<<<<<<<<<<<< + * if val == e_id: + * if col == 0: + */ + __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_v_midpoint); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->e_index->arr[__pyx_t_3])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_v_val); + __pyx_v_val = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":393 + * midpoint = (low+high)/2 + * val = self.e_index.arr[midpoint] + * if val == e_id: # <<<<<<<<<<<<<< + * if col == 0: + * return self.col1.arr[midpoint] + */ + __pyx_t_2 = PyObject_RichCompare(__pyx_v_val, __pyx_v_e_id, Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":394 + * val = self.e_index.arr[midpoint] + * if val == e_id: + * if col == 0: # <<<<<<<<<<<<<< + * return self.col1.arr[midpoint] + * if col == 1: + */ + __pyx_t_2 = PyObject_RichCompare(__pyx_v_col, __pyx_int_0, Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 394; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 394; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":395 + * if val == e_id: + * if col == 0: + * return self.col1.arr[midpoint] # <<<<<<<<<<<<<< + * if col == 1: + * return self.col2.arr[midpoint] + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_v_midpoint); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyFloat_FromDouble((__pyx_v_self->col1->arr[__pyx_t_3])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + goto __pyx_L8; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":396 + * if col == 0: + * return self.col1.arr[midpoint] + * if col == 1: # <<<<<<<<<<<<<< + * return self.col2.arr[midpoint] + * if val > e_id: + */ + __pyx_t_2 = PyObject_RichCompare(__pyx_v_col, __pyx_int_1, Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":397 + * return self.col1.arr[midpoint] + * if col == 1: + * return self.col2.arr[midpoint] # <<<<<<<<<<<<<< + * if val > e_id: + * high = midpoint + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_v_midpoint); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyFloat_FromDouble((__pyx_v_self->col2->arr[__pyx_t_3])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + goto __pyx_L9; + } + __pyx_L9:; + goto __pyx_L7; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":398 + * if col == 1: + * return self.col2.arr[midpoint] + * if val > e_id: # <<<<<<<<<<<<<< + * high = midpoint + * if val < e_id: + */ + __pyx_t_2 = PyObject_RichCompare(__pyx_v_val, __pyx_v_e_id, Py_GT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":399 + * return self.col2.arr[midpoint] + * if val > e_id: + * high = midpoint # <<<<<<<<<<<<<< + * if val < e_id: + * low = midpoint + 1 + */ + __Pyx_INCREF(__pyx_v_midpoint); + __Pyx_DECREF(__pyx_v_high); + __pyx_v_high = __pyx_v_midpoint; + goto __pyx_L10; + } + __pyx_L10:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":400 + * if val > e_id: + * high = midpoint + * if val < e_id: # <<<<<<<<<<<<<< + * low = midpoint + 1 + * return None + */ + __pyx_t_2 = PyObject_RichCompare(__pyx_v_val, __pyx_v_e_id, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":401 + * high = midpoint + * if val < e_id: + * low = midpoint + 1 # <<<<<<<<<<<<<< + * return None + * + */ + __pyx_t_2 = PyNumber_Add(__pyx_v_midpoint, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_v_low); + __pyx_v_low = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L11; + } + __pyx_L11:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":402 + * if val < e_id: + * low = midpoint + 1 + * return None # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_None); + __pyx_r = Py_None; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec_sa.BiLex.get_score", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_e_id); + __Pyx_XDECREF(__pyx_v_f_id); + __Pyx_XDECREF(__pyx_v_low); + __Pyx_XDECREF(__pyx_v_high); + __Pyx_XDECREF(__pyx_v_midpoint); + __Pyx_XDECREF(__pyx_v_val); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_5BiLex_17write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static char __pyx_doc_8_cdec_sa_5BiLex_16write_text[] = "Note: does not guarantee writing the dictionary in the original order"; +static PyObject *__pyx_pw_8_cdec_sa_5BiLex_17write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_text (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.BiLex.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_5BiLex_16write_text(((struct __pyx_obj_8_cdec_sa_BiLex *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":405 + * + * + * def write_text(self, char* filename): # <<<<<<<<<<<<<< + * """Note: does not guarantee writing the dictionary in the original order""" + * cdef i, N, e_id, f_id + */ + +static PyObject *__pyx_pf_8_cdec_sa_5BiLex_16write_text(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_v_i = 0; + PyObject *__pyx_v_N = 0; + PyObject *__pyx_v_e_id = 0; + PyObject *__pyx_v_f_id = 0; + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_v_score1 = NULL; + PyObject *__pyx_v_score2 = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + long __pyx_t_9; + long __pyx_t_10; + int __pyx_t_11; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + int __pyx_t_14; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_text", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":409 + * cdef i, N, e_id, f_id + * + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * N = len(self.e_index) + * f_id = 0 + */ + /*with:*/ { + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_f = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":410 + * + * with open(filename, "w") as f: + * N = len(self.e_index) # <<<<<<<<<<<<<< + * f_id = 0 + * for i from 0 <= i < N: + */ + __pyx_t_4 = ((PyObject *)__pyx_v_self->e_index); + __Pyx_INCREF(__pyx_t_4); + __pyx_t_8 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_N = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":411 + * with open(filename, "w") as f: + * N = len(self.e_index) + * f_id = 0 # <<<<<<<<<<<<<< + * for i from 0 <= i < N: + * while self.f_index.arr[f_id+1] == i: + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_f_id = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":412 + * N = len(self.e_index) + * f_id = 0 + * for i from 0 <= i < N: # <<<<<<<<<<<<<< + * while self.f_index.arr[f_id+1] == i: + * f_id = f_id + 1 + */ + __pyx_t_9 = __Pyx_PyInt_AsLong(__pyx_v_N); if (unlikely((__pyx_t_9 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10++) { + __pyx_t_4 = PyInt_FromLong(__pyx_t_10); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":413 + * f_id = 0 + * for i from 0 <= i < N: + * while self.f_index.arr[f_id+1] == i: # <<<<<<<<<<<<<< + * f_id = f_id + 1 + * e_id = self.e_index.arr[i] + */ + while (1) { + __pyx_t_4 = PyNumber_Add(__pyx_v_f_id, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyInt_FromLong((__pyx_v_self->f_index->arr[__pyx_t_8])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_v_i, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!__pyx_t_11) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":414 + * for i from 0 <= i < N: + * while self.f_index.arr[f_id+1] == i: + * f_id = f_id + 1 # <<<<<<<<<<<<<< + * e_id = self.e_index.arr[i] + * score1 = self.col1.arr[i] + */ + __pyx_t_1 = PyNumber_Add(__pyx_v_f_id, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_v_f_id); + __pyx_v_f_id = __pyx_t_1; + __pyx_t_1 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":415 + * while self.f_index.arr[f_id+1] == i: + * f_id = f_id + 1 + * e_id = self.e_index.arr[i] # <<<<<<<<<<<<<< + * score1 = self.col1.arr[i] + * score2 = self.col2.arr[i] + */ + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyInt_FromLong((__pyx_v_self->e_index->arr[__pyx_t_8])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_e_id); + __pyx_v_e_id = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":416 + * f_id = f_id + 1 + * e_id = self.e_index.arr[i] + * score1 = self.col1.arr[i] # <<<<<<<<<<<<<< + * score2 = self.col2.arr[i] + * f.write("%s %s %.6f %.6f\n" % (self.id2fword[f_id], self.id2eword[e_id], score1, score2)) + */ + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyFloat_FromDouble((__pyx_v_self->col1->arr[__pyx_t_8])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_score1); + __pyx_v_score1 = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":417 + * e_id = self.e_index.arr[i] + * score1 = self.col1.arr[i] + * score2 = self.col2.arr[i] # <<<<<<<<<<<<<< + * f.write("%s %s %.6f %.6f\n" % (self.id2fword[f_id], self.id2eword[e_id], score1, score2)) + */ + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyFloat_FromDouble((__pyx_v_self->col2->arr[__pyx_t_8])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_score2); + __pyx_v_score2 = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":418 + * score1 = self.col1.arr[i] + * score2 = self.col2.arr[i] + * f.write("%s %s %.6f %.6f\n" % (self.id2fword[f_id], self.id2eword[e_id], score1, score2)) # <<<<<<<<<<<<<< + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyObject_GetItem(__pyx_v_self->id2fword, __pyx_v_f_id); if (!__pyx_t_4) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyObject_GetItem(__pyx_v_self->id2eword, __pyx_v_e_id); if (!__pyx_t_2) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_12 = PyTuple_New(4); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_score1); + PyTuple_SET_ITEM(__pyx_t_12, 2, __pyx_v_score1); + __Pyx_GIVEREF(__pyx_v_score1); + __Pyx_INCREF(__pyx_v_score2); + PyTuple_SET_ITEM(__pyx_t_12, 3, __pyx_v_score2); + __Pyx_GIVEREF(__pyx_v_score2); + __pyx_t_4 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_53), ((PyObject *)__pyx_t_12)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_10 = __Pyx_PyInt_AsLong(__pyx_v_i); if (unlikely((__pyx_t_10 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":412 + * N = len(self.e_index) + * f_id = 0 + * for i from 0 <= i < N: # <<<<<<<<<<<<<< + * while self.f_index.arr[f_id+1] == i: + * f_id = f_id + 1 + */ + __pyx_t_2 = PyInt_FromLong(__pyx_t_10); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_2; + __pyx_t_2 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":409 + * cdef i, N, e_id, f_id + * + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * N = len(self.e_index) + * f_id = 0 + */ + /*except:*/ { + __Pyx_AddTraceback("_cdec_sa.BiLex.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_12, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_12); + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_13 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_13); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_14 = (!__pyx_t_11); + if (__pyx_t_14) { + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_ErrRestore(__pyx_t_2, __pyx_t_12, __pyx_t_1); + __pyx_t_2 = 0; __pyx_t_12 = 0; __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L22; + } + __pyx_L22:; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_54, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L23; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L23:; + } + + __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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("_cdec_sa.BiLex.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_N); + __Pyx_XDECREF(__pyx_v_e_id); + __Pyx_XDECREF(__pyx_v_f_id); + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_score1); + __Pyx_XDECREF(__pyx_v_score2); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":21 + * cdef int LOWER_MASK[32] + * + * cdef void _init_lower_mask(): # <<<<<<<<<<<<<< + * cdef unsigned i + * cdef int mask = 0 + */ + +static void __pyx_f_8_cdec_sa__init_lower_mask(void) { + unsigned int __pyx_v_i; + int __pyx_v_mask; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + unsigned int __pyx_t_2; + __Pyx_RefNannySetupContext("_init_lower_mask", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":23 + * cdef void _init_lower_mask(): + * cdef unsigned i + * cdef int mask = 0 # <<<<<<<<<<<<<< + * for i in range(MIN_BOTTOM_SIZE): + * mask = (mask << 1) + 1 + */ + __pyx_v_mask = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":24 + * cdef unsigned i + * cdef int mask = 0 + * for i in range(MIN_BOTTOM_SIZE): # <<<<<<<<<<<<<< + * mask = (mask << 1) + 1 + * LOWER_MASK[i] = mask + */ + __pyx_t_1 = __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE; + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_v_i = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":25 + * cdef int mask = 0 + * for i in range(MIN_BOTTOM_SIZE): + * mask = (mask << 1) + 1 # <<<<<<<<<<<<<< + * LOWER_MASK[i] = mask + * + */ + __pyx_v_mask = ((__pyx_v_mask << 1) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":26 + * for i in range(MIN_BOTTOM_SIZE): + * mask = (mask << 1) + 1 + * LOWER_MASK[i] = mask # <<<<<<<<<<<<<< + * + * _init_lower_mask() + */ + (__pyx_v_8_cdec_sa_LOWER_MASK[__pyx_v_i]) = __pyx_v_mask; + } + + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":37 + * + * + * cdef _BitSet* new_BitSet(): # <<<<<<<<<<<<<< + * cdef _BitSet* b + * + */ + +static struct __pyx_t_8_cdec_sa__BitSet *__pyx_f_8_cdec_sa_new_BitSet(void) { + struct __pyx_t_8_cdec_sa__BitSet *__pyx_v_b; + struct __pyx_t_8_cdec_sa__BitSet *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("new_BitSet", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":40 + * cdef _BitSet* b + * + * b = <_BitSet*> malloc(sizeof(_BitSet)) # <<<<<<<<<<<<<< + * b.bitset = 0 + * b.min_val = -1 + */ + __pyx_v_b = ((struct __pyx_t_8_cdec_sa__BitSet *)malloc((sizeof(struct __pyx_t_8_cdec_sa__BitSet)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":41 + * + * b = <_BitSet*> malloc(sizeof(_BitSet)) + * b.bitset = 0 # <<<<<<<<<<<<<< + * b.min_val = -1 + * b.max_val = -1 + */ + __pyx_v_b->bitset = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":42 + * b = <_BitSet*> malloc(sizeof(_BitSet)) + * b.bitset = 0 + * b.min_val = -1 # <<<<<<<<<<<<<< + * b.max_val = -1 + * b.size = 0 + */ + __pyx_v_b->min_val = -1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":43 + * b.bitset = 0 + * b.min_val = -1 + * b.max_val = -1 # <<<<<<<<<<<<<< + * b.size = 0 + * return b + */ + __pyx_v_b->max_val = -1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":44 + * b.min_val = -1 + * b.max_val = -1 + * b.size = 0 # <<<<<<<<<<<<<< + * return b + * + */ + __pyx_v_b->size = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":45 + * b.max_val = -1 + * b.size = 0 + * return b # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_b; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":48 + * + * + * cdef int bitset_findsucc(_BitSet* b, int i): # <<<<<<<<<<<<<< + * cdef int bitset, mask + * cdef int low, high, mid + */ + +static int __pyx_f_8_cdec_sa_bitset_findsucc(struct __pyx_t_8_cdec_sa__BitSet *__pyx_v_b, int __pyx_v_i) { + int __pyx_v_bitset; + int __pyx_v_mask; + int __pyx_v_low; + int __pyx_v_high; + int __pyx_v_mid; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("bitset_findsucc", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":52 + * cdef int low, high, mid + * + * if b.max_val == -1 or i >= b.max_val: # <<<<<<<<<<<<<< + * return -1 + * if i < b.min_val: + */ + __pyx_t_1 = (__pyx_v_b->max_val == -1); + if (!__pyx_t_1) { + __pyx_t_2 = (__pyx_v_i >= __pyx_v_b->max_val); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":53 + * + * if b.max_val == -1 or i >= b.max_val: + * return -1 # <<<<<<<<<<<<<< + * if i < b.min_val: + * return b.min_val + */ + __pyx_r = -1; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":54 + * if b.max_val == -1 or i >= b.max_val: + * return -1 + * if i < b.min_val: # <<<<<<<<<<<<<< + * return b.min_val + * + */ + __pyx_t_3 = (__pyx_v_i < __pyx_v_b->min_val); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":55 + * return -1 + * if i < b.min_val: + * return b.min_val # <<<<<<<<<<<<<< + * + * bitset = b.bitset & ~LOWER_MASK[i] + */ + __pyx_r = __pyx_v_b->min_val; + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":57 + * return b.min_val + * + * bitset = b.bitset & ~LOWER_MASK[i] # <<<<<<<<<<<<<< + * low = i+1 + * high = b.max_val+1 + */ + __pyx_v_bitset = (__pyx_v_b->bitset & (~(__pyx_v_8_cdec_sa_LOWER_MASK[__pyx_v_i]))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":58 + * + * bitset = b.bitset & ~LOWER_MASK[i] + * low = i+1 # <<<<<<<<<<<<<< + * high = b.max_val+1 + * while low < high-1: + */ + __pyx_v_low = (__pyx_v_i + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":59 + * bitset = b.bitset & ~LOWER_MASK[i] + * low = i+1 + * high = b.max_val+1 # <<<<<<<<<<<<<< + * while low < high-1: + * mid = (high + low)/2 + */ + __pyx_v_high = (__pyx_v_b->max_val + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":60 + * low = i+1 + * high = b.max_val+1 + * while low < high-1: # <<<<<<<<<<<<<< + * mid = (high + low)/2 + * mask = ~(LOWER_MASK[high-1] ^ LOWER_MASK[mid-1]) + */ + while (1) { + __pyx_t_3 = (__pyx_v_low < (__pyx_v_high - 1)); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":61 + * high = b.max_val+1 + * while low < high-1: + * mid = (high + low)/2 # <<<<<<<<<<<<<< + * mask = ~(LOWER_MASK[high-1] ^ LOWER_MASK[mid-1]) + * if bitset & mask == 0: + */ + __pyx_v_mid = __Pyx_div_long((__pyx_v_high + __pyx_v_low), 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":62 + * while low < high-1: + * mid = (high + low)/2 + * mask = ~(LOWER_MASK[high-1] ^ LOWER_MASK[mid-1]) # <<<<<<<<<<<<<< + * if bitset & mask == 0: + * low = mid + */ + __pyx_v_mask = (~((__pyx_v_8_cdec_sa_LOWER_MASK[(__pyx_v_high - 1)]) ^ (__pyx_v_8_cdec_sa_LOWER_MASK[(__pyx_v_mid - 1)]))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":63 + * mid = (high + low)/2 + * mask = ~(LOWER_MASK[high-1] ^ LOWER_MASK[mid-1]) + * if bitset & mask == 0: # <<<<<<<<<<<<<< + * low = mid + * else: + */ + __pyx_t_3 = ((__pyx_v_bitset & __pyx_v_mask) == 0); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":64 + * mask = ~(LOWER_MASK[high-1] ^ LOWER_MASK[mid-1]) + * if bitset & mask == 0: + * low = mid # <<<<<<<<<<<<<< + * else: + * bitset = bitset & mask + */ + __pyx_v_low = __pyx_v_mid; + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":66 + * low = mid + * else: + * bitset = bitset & mask # <<<<<<<<<<<<<< + * high = mid + * return low + */ + __pyx_v_bitset = (__pyx_v_bitset & __pyx_v_mask); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":67 + * else: + * bitset = bitset & mask + * high = mid # <<<<<<<<<<<<<< + * return low + * + */ + __pyx_v_high = __pyx_v_mid; + } + __pyx_L7:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":68 + * bitset = bitset & mask + * high = mid + * return low # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_low; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":71 + * + * + * cdef int bitset_insert(_BitSet* b, int i): # <<<<<<<<<<<<<< + * cdef int val + * + */ + +static int __pyx_f_8_cdec_sa_bitset_insert(struct __pyx_t_8_cdec_sa__BitSet *__pyx_v_b, int __pyx_v_i) { + int __pyx_v_val; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("bitset_insert", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":74 + * cdef int val + * + * val = 1 << i # <<<<<<<<<<<<<< + * if b.bitset & val == 0: + * b.bitset = b.bitset | val + */ + __pyx_v_val = (1 << __pyx_v_i); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":75 + * + * val = 1 << i + * if b.bitset & val == 0: # <<<<<<<<<<<<<< + * b.bitset = b.bitset | val + * if b.size == 0: + */ + __pyx_t_1 = ((__pyx_v_b->bitset & __pyx_v_val) == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":76 + * val = 1 << i + * if b.bitset & val == 0: + * b.bitset = b.bitset | val # <<<<<<<<<<<<<< + * if b.size == 0: + * b.min_val = i + */ + __pyx_v_b->bitset = (__pyx_v_b->bitset | __pyx_v_val); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":77 + * if b.bitset & val == 0: + * b.bitset = b.bitset | val + * if b.size == 0: # <<<<<<<<<<<<<< + * b.min_val = i + * b.max_val = i + */ + __pyx_t_1 = (__pyx_v_b->size == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":78 + * b.bitset = b.bitset | val + * if b.size == 0: + * b.min_val = i # <<<<<<<<<<<<<< + * b.max_val = i + * else: + */ + __pyx_v_b->min_val = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":79 + * if b.size == 0: + * b.min_val = i + * b.max_val = i # <<<<<<<<<<<<<< + * else: + * if i < b.min_val: + */ + __pyx_v_b->max_val = __pyx_v_i; + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":81 + * b.max_val = i + * else: + * if i < b.min_val: # <<<<<<<<<<<<<< + * b.min_val = i + * if i > b.max_val: + */ + __pyx_t_1 = (__pyx_v_i < __pyx_v_b->min_val); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":82 + * else: + * if i < b.min_val: + * b.min_val = i # <<<<<<<<<<<<<< + * if i > b.max_val: + * b.max_val = i + */ + __pyx_v_b->min_val = __pyx_v_i; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":83 + * if i < b.min_val: + * b.min_val = i + * if i > b.max_val: # <<<<<<<<<<<<<< + * b.max_val = i + * b.size = b.size + 1 + */ + __pyx_t_1 = (__pyx_v_i > __pyx_v_b->max_val); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":84 + * b.min_val = i + * if i > b.max_val: + * b.max_val = i # <<<<<<<<<<<<<< + * b.size = b.size + 1 + * return 1 + */ + __pyx_v_b->max_val = __pyx_v_i; + goto __pyx_L6; + } + __pyx_L6:; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":85 + * if i > b.max_val: + * b.max_val = i + * b.size = b.size + 1 # <<<<<<<<<<<<<< + * return 1 + * return 0 + */ + __pyx_v_b->size = (__pyx_v_b->size + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":86 + * b.max_val = i + * b.size = b.size + 1 + * return 1 # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":87 + * b.size = b.size + 1 + * return 1 + * return 0 # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = 0; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":90 + * + * + * cdef int bitset_contains(_BitSet* b, int i): # <<<<<<<<<<<<<< + * cdef int val + * + */ + +static int __pyx_f_8_cdec_sa_bitset_contains(struct __pyx_t_8_cdec_sa__BitSet *__pyx_v_b, int __pyx_v_i) { + int __pyx_v_val; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("bitset_contains", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":93 + * cdef int val + * + * val = 1 << i # <<<<<<<<<<<<<< + * if b.bitset & val == 0: + * return 0 + */ + __pyx_v_val = (1 << __pyx_v_i); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":94 + * + * val = 1 << i + * if b.bitset & val == 0: # <<<<<<<<<<<<<< + * return 0 + * else: + */ + __pyx_t_1 = ((__pyx_v_b->bitset & __pyx_v_val) == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":95 + * val = 1 << i + * if b.bitset & val == 0: + * return 0 # <<<<<<<<<<<<<< + * else: + * return 1 + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":97 + * return 0 + * else: + * return 1 # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = 1; + goto __pyx_L0; + } + __pyx_L3:; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_14BitSetIterator_1__next__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_14BitSetIterator_1__next__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__next__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_14BitSetIterator___next__(((struct __pyx_obj_8_cdec_sa_BitSetIterator *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":104 + * cdef int next_val + * + * def __next__(self): # <<<<<<<<<<<<<< + * cdef int ret_val + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_14BitSetIterator___next__(struct __pyx_obj_8_cdec_sa_BitSetIterator *__pyx_v_self) { + int __pyx_v_ret_val; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__next__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":107 + * cdef int ret_val + * + * if self.next_val == -1: # <<<<<<<<<<<<<< + * raise StopIteration() + * ret_val = self.next_val + */ + __pyx_t_1 = (__pyx_v_self->next_val == -1); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":108 + * + * if self.next_val == -1: + * raise StopIteration() # <<<<<<<<<<<<<< + * ret_val = self.next_val + * self.next_val = bitset_findsucc(self.b, ret_val) + */ + __pyx_t_2 = PyObject_Call(__pyx_builtin_StopIteration, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[6]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":109 + * if self.next_val == -1: + * raise StopIteration() + * ret_val = self.next_val # <<<<<<<<<<<<<< + * self.next_val = bitset_findsucc(self.b, ret_val) + * return ret_val + */ + __pyx_v_ret_val = __pyx_v_self->next_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":110 + * raise StopIteration() + * ret_val = self.next_val + * self.next_val = bitset_findsucc(self.b, ret_val) # <<<<<<<<<<<<<< + * return ret_val + * + */ + __pyx_v_self->next_val = __pyx_f_8_cdec_sa_bitset_findsucc(__pyx_v_self->b, __pyx_v_ret_val); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":111 + * ret_val = self.next_val + * self.next_val = bitset_findsucc(self.b, ret_val) + * return ret_val # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyInt_FromLong(__pyx_v_ret_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_cdec_sa.BitSetIterator.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_6BitSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_6BitSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; + __pyx_r = __pyx_pf_8_cdec_sa_6BitSet___cinit__(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":122 + * cdef _BitSet* b + * + * def __cinit__(self): # <<<<<<<<<<<<<< + * self.b = new_BitSet() + * + */ + +static int __pyx_pf_8_cdec_sa_6BitSet___cinit__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":123 + * + * def __cinit__(self): + * self.b = new_BitSet() # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->b = __pyx_f_8_cdec_sa_new_BitSet(); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_8_cdec_sa_6BitSet_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_8_cdec_sa_6BitSet_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_8_cdec_sa_6BitSet_2__dealloc__(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":125 + * self.b = new_BitSet() + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * free(self.b) + * + */ + +static void __pyx_pf_8_cdec_sa_6BitSet_2__dealloc__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":126 + * + * def __dealloc__(self): + * free(self.b) # <<<<<<<<<<<<<< + * + * def __iter__(self): + */ + free(__pyx_v_self->b); + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_6BitSet_5__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_6BitSet_5__iter__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6BitSet_4__iter__(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":128 + * free(self.b) + * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef BitSetIterator it + * it = BitSetIterator() + */ + +static PyObject *__pyx_pf_8_cdec_sa_6BitSet_4__iter__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self) { + struct __pyx_obj_8_cdec_sa_BitSetIterator *__pyx_v_it = 0; + 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("__iter__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":130 + * def __iter__(self): + * cdef BitSetIterator it + * it = BitSetIterator() # <<<<<<<<<<<<<< + * it.b = self.b + * it.next_val = self.b.min_val + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_BitSetIterator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_it = ((struct __pyx_obj_8_cdec_sa_BitSetIterator *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":131 + * cdef BitSetIterator it + * it = BitSetIterator() + * it.b = self.b # <<<<<<<<<<<<<< + * it.next_val = self.b.min_val + * return it + */ + __pyx_v_it->b = __pyx_v_self->b; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":132 + * it = BitSetIterator() + * it.b = self.b + * it.next_val = self.b.min_val # <<<<<<<<<<<<<< + * return it + * + */ + __pyx_v_it->next_val = __pyx_v_self->b->min_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":133 + * it.b = self.b + * it.next_val = self.b.min_val + * return it # <<<<<<<<<<<<<< + * + * def insert(self, i): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_it)); + __pyx_r = ((PyObject *)__pyx_v_it); + 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_sa.BitSet.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_it); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_6BitSet_7insert(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_6BitSet_7insert(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("insert (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6BitSet_6insert(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":135 + * return it + * + * def insert(self, i): # <<<<<<<<<<<<<< + * return bitset_insert(self.b, i) + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_6BitSet_6insert(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("insert", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":136 + * + * def insert(self, i): + * return bitset_insert(self.b, i) # <<<<<<<<<<<<<< + * + * def findsucc(self, i): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong(__pyx_f_8_cdec_sa_bitset_insert(__pyx_v_self->b, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_cdec_sa.BitSet.insert", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_6BitSet_9findsucc(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_6BitSet_9findsucc(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("findsucc (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6BitSet_8findsucc(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":138 + * return bitset_insert(self.b, i) + * + * def findsucc(self, i): # <<<<<<<<<<<<<< + * return bitset_findsucc(self.b, i) + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_6BitSet_8findsucc(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("findsucc", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":139 + * + * def findsucc(self, i): + * return bitset_findsucc(self.b, i) # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong(__pyx_f_8_cdec_sa_bitset_findsucc(__pyx_v_self->b, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_cdec_sa.BitSet.findsucc", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_6BitSet_11__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_6BitSet_11__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6BitSet_10__str__(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":141 + * return bitset_findsucc(self.b, i) + * + * def __str__(self): # <<<<<<<<<<<<<< + * return dec2bin(self.b.bitset)+" ("+str(self.b.size)+","+str(self.b.min_val)+","+str(self.b.max_val)+")" + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_6BitSet_10__str__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__str__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":142 + * + * def __str__(self): + * return dec2bin(self.b.bitset)+" ("+str(self.b.size)+","+str(self.b.min_val)+","+str(self.b.max_val)+")" # <<<<<<<<<<<<<< + * + * def min(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = ((PyObject *)__pyx_f_8_cdec_sa_dec2bin(__pyx_v_self->b->bitset)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Add(__pyx_t_1, ((PyObject *)__pyx_kp_s_55)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->b->size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Add(((PyObject *)__pyx_t_2), __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Add(__pyx_t_3, ((PyObject *)__pyx_kp_s_4)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromLong(__pyx_v_self->b->min_val); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Add(__pyx_t_2, ((PyObject *)__pyx_kp_s_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyInt_FromLong(__pyx_v_self->b->max_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __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 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Add(__pyx_t_1, ((PyObject *)__pyx_kp_s_56)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.BitSet.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_6BitSet_13min(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_6BitSet_13min(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("min (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6BitSet_12min(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":144 + * return dec2bin(self.b.bitset)+" ("+str(self.b.size)+","+str(self.b.min_val)+","+str(self.b.max_val)+")" + * + * def min(self): # <<<<<<<<<<<<<< + * return self.b.min_val + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_6BitSet_12min(struct __pyx_obj_8_cdec_sa_BitSet *__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("min", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":145 + * + * def min(self): + * return self.b.min_val # <<<<<<<<<<<<<< + * + * def max(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->b->min_val); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_cdec_sa.BitSet.min", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_6BitSet_15max(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_6BitSet_15max(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("max (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6BitSet_14max(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":147 + * return self.b.min_val + * + * def max(self): # <<<<<<<<<<<<<< + * return self.b.max_val + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_6BitSet_14max(struct __pyx_obj_8_cdec_sa_BitSet *__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("max", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":148 + * + * def max(self): + * return self.b.max_val # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->b->max_val); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_cdec_sa.BitSet.max", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_8_cdec_sa_6BitSet_17__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_8_cdec_sa_6BitSet_17__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6BitSet_16__len__(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":150 + * return self.b.max_val + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.b.size + * + */ + +static Py_ssize_t __pyx_pf_8_cdec_sa_6BitSet_16__len__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":151 + * + * def __len__(self): + * return self.b.size # <<<<<<<<<<<<<< + * + * def __contains__(self, i): + */ + __pyx_r = __pyx_v_self->b->size; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_6BitSet_19__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static int __pyx_pw_8_cdec_sa_6BitSet_19__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6BitSet_18__contains__(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":153 + * return self.b.size + * + * def __contains__(self, i): # <<<<<<<<<<<<<< + * return bool(bitset_contains(self.b, i)) + * + */ + +static int __pyx_pf_8_cdec_sa_6BitSet_18__contains__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self, PyObject *__pyx_v_i) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__contains__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":154 + * + * def __contains__(self, i): + * return bool(bitset_contains(self.b, i)) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong(__pyx_f_8_cdec_sa_bitset_contains(__pyx_v_self->b, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = (!(!__pyx_t_3)); + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec_sa.BitSet.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":157 + * + * + * cdef str dec2bin(long i): # <<<<<<<<<<<<<< + * cdef str result = "" + * cdef unsigned d + */ + +static PyObject *__pyx_f_8_cdec_sa_dec2bin(long __pyx_v_i) { + PyObject *__pyx_v_result = 0; + CYTHON_UNUSED unsigned int __pyx_v_d; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + unsigned int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("dec2bin", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":158 + * + * cdef str dec2bin(long i): + * cdef str result = "" # <<<<<<<<<<<<<< + * cdef unsigned d + * for d in range(MIN_BOTTOM_SIZE): + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_42)); + __pyx_v_result = __pyx_kp_s_42; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":160 + * cdef str result = "" + * cdef unsigned d + * for d in range(MIN_BOTTOM_SIZE): # <<<<<<<<<<<<<< + * if i & LOWER_MASK[0] == 0: + * result = "0"+result + */ + __pyx_t_1 = __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE; + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_v_d = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":161 + * cdef unsigned d + * for d in range(MIN_BOTTOM_SIZE): + * if i & LOWER_MASK[0] == 0: # <<<<<<<<<<<<<< + * result = "0"+result + * else: + */ + __pyx_t_3 = ((__pyx_v_i & (__pyx_v_8_cdec_sa_LOWER_MASK[0])) == 0); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":162 + * for d in range(MIN_BOTTOM_SIZE): + * if i & LOWER_MASK[0] == 0: + * result = "0"+result # <<<<<<<<<<<<<< + * else: + * result = "1"+result + */ + __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_kp_s__0), ((PyObject *)__pyx_v_result)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __Pyx_DECREF(((PyObject *)__pyx_v_result)); + __pyx_v_result = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":164 + * result = "0"+result + * else: + * result = "1"+result # <<<<<<<<<<<<<< + * i = i >> 1 + * return result + */ + __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_kp_s__1), ((PyObject *)__pyx_v_result)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __Pyx_DECREF(((PyObject *)__pyx_v_result)); + __pyx_v_result = __pyx_t_4; + __pyx_t_4 = 0; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":165 + * else: + * result = "1"+result + * i = i >> 1 # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_v_i = (__pyx_v_i >> 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":166 + * result = "1"+result + * i = i >> 1 + * return result # <<<<<<<<<<<<<< + * + * cdef struct _VEB: + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = ((PyObject*)Py_None); __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec_sa.dec2bin", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":177 + * void** bottom + * + * cdef _VEB* new_VEB(int n): # <<<<<<<<<<<<<< + * cdef _VEB* veb + * cdef int num_bits, num_top_bits, i + */ + +static struct __pyx_t_8_cdec_sa__VEB *__pyx_f_8_cdec_sa_new_VEB(int __pyx_v_n) { + struct __pyx_t_8_cdec_sa__VEB *__pyx_v_veb; + int __pyx_v_num_bits; + struct __pyx_t_8_cdec_sa__VEB *__pyx_r; + __Pyx_RefNannyDeclarations + double __pyx_t_1; + double __pyx_t_2; + int __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("new_VEB", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":181 + * cdef int num_bits, num_top_bits, i + * + * veb = <_VEB*> malloc(sizeof(_VEB)) # <<<<<<<<<<<<<< + * + * num_bits = int(ceil(log(n) / log(2))) + */ + __pyx_v_veb = ((struct __pyx_t_8_cdec_sa__VEB *)malloc((sizeof(struct __pyx_t_8_cdec_sa__VEB)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":183 + * veb = <_VEB*> malloc(sizeof(_VEB)) + * + * num_bits = int(ceil(log(n) / log(2))) # <<<<<<<<<<<<<< + * veb.num_bottom_bits = num_bits/2 + * if veb.num_bottom_bits < MIN_BOTTOM_BITS: + */ + __pyx_t_1 = log(__pyx_v_n); + __pyx_t_2 = log(2.0); + if (unlikely(__pyx_t_2 == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[6]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_num_bits = ((int)ceil((__pyx_t_1 / __pyx_t_2))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":184 + * + * num_bits = int(ceil(log(n) / log(2))) + * veb.num_bottom_bits = num_bits/2 # <<<<<<<<<<<<<< + * if veb.num_bottom_bits < MIN_BOTTOM_BITS: + * veb.num_bottom_bits = MIN_BOTTOM_BITS + */ + __pyx_v_veb->num_bottom_bits = __Pyx_div_long(__pyx_v_num_bits, 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":185 + * num_bits = int(ceil(log(n) / log(2))) + * veb.num_bottom_bits = num_bits/2 + * if veb.num_bottom_bits < MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< + * veb.num_bottom_bits = MIN_BOTTOM_BITS + * veb.top_universe_size = (n >> veb.num_bottom_bits) + 1 + */ + __pyx_t_3 = (__pyx_v_veb->num_bottom_bits < __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":186 + * veb.num_bottom_bits = num_bits/2 + * if veb.num_bottom_bits < MIN_BOTTOM_BITS: + * veb.num_bottom_bits = MIN_BOTTOM_BITS # <<<<<<<<<<<<<< + * veb.top_universe_size = (n >> veb.num_bottom_bits) + 1 + * + */ + __pyx_v_veb->num_bottom_bits = __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":187 + * if veb.num_bottom_bits < MIN_BOTTOM_BITS: + * veb.num_bottom_bits = MIN_BOTTOM_BITS + * veb.top_universe_size = (n >> veb.num_bottom_bits) + 1 # <<<<<<<<<<<<<< + * + * veb.bottom = malloc(veb.top_universe_size * sizeof(void*)) + */ + __pyx_v_veb->top_universe_size = ((__pyx_v_n >> __pyx_v_veb->num_bottom_bits) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":189 + * veb.top_universe_size = (n >> veb.num_bottom_bits) + 1 + * + * veb.bottom = malloc(veb.top_universe_size * sizeof(void*)) # <<<<<<<<<<<<<< + * memset(veb.bottom, 0, veb.top_universe_size * sizeof(void*)) + * + */ + __pyx_v_veb->bottom = ((void **)malloc((__pyx_v_veb->top_universe_size * (sizeof(void *))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":190 + * + * veb.bottom = malloc(veb.top_universe_size * sizeof(void*)) + * memset(veb.bottom, 0, veb.top_universe_size * sizeof(void*)) # <<<<<<<<<<<<<< + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + */ + memset(__pyx_v_veb->bottom, 0, (__pyx_v_veb->top_universe_size * (sizeof(void *)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":192 + * memset(veb.bottom, 0, veb.top_universe_size * sizeof(void*)) + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: # <<<<<<<<<<<<<< + * veb.top = new_VEB(veb.top_universe_size) + * else: + */ + __pyx_t_3 = (__pyx_v_veb->top_universe_size > __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":193 + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * veb.top = new_VEB(veb.top_universe_size) # <<<<<<<<<<<<<< + * else: + * veb.top = new_BitSet() + */ + __pyx_v_veb->top = __pyx_f_8_cdec_sa_new_VEB(__pyx_v_veb->top_universe_size); + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":195 + * veb.top = new_VEB(veb.top_universe_size) + * else: + * veb.top = new_BitSet() # <<<<<<<<<<<<<< + * + * veb.max_val = -1 + */ + __pyx_v_veb->top = __pyx_f_8_cdec_sa_new_BitSet(); + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":197 + * veb.top = new_BitSet() + * + * veb.max_val = -1 # <<<<<<<<<<<<<< + * veb.min_val = -1 + * veb.size = 0 + */ + __pyx_v_veb->max_val = -1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":198 + * + * veb.max_val = -1 + * veb.min_val = -1 # <<<<<<<<<<<<<< + * veb.size = 0 + * return veb + */ + __pyx_v_veb->min_val = -1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":199 + * veb.max_val = -1 + * veb.min_val = -1 + * veb.size = 0 # <<<<<<<<<<<<<< + * return veb + * + */ + __pyx_v_veb->size = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":200 + * veb.min_val = -1 + * veb.size = 0 + * return veb # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_veb; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("_cdec_sa.new_VEB", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":203 + * + * + * cdef int VEB_insert(_VEB* veb, int i): # <<<<<<<<<<<<<< + * cdef _VEB* subv + * cdef _BitSet* subb + */ + +static int __pyx_f_8_cdec_sa_VEB_insert(struct __pyx_t_8_cdec_sa__VEB *__pyx_v_veb, int __pyx_v_i) { + struct __pyx_t_8_cdec_sa__VEB *__pyx_v_subv; + struct __pyx_t_8_cdec_sa__BitSet *__pyx_v_subb; + int __pyx_v_a; + int __pyx_v_b; + int __pyx_v_tmp; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("VEB_insert", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":208 + * cdef int a, b, tmp + * + * if veb.size == 0: # <<<<<<<<<<<<<< + * veb.min_val = i + * veb.max_val = i + */ + __pyx_t_1 = (__pyx_v_veb->size == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":209 + * + * if veb.size == 0: + * veb.min_val = i # <<<<<<<<<<<<<< + * veb.max_val = i + * elif i == veb.min_val or i == veb.max_val: + */ + __pyx_v_veb->min_val = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":210 + * if veb.size == 0: + * veb.min_val = i + * veb.max_val = i # <<<<<<<<<<<<<< + * elif i == veb.min_val or i == veb.max_val: + * return 0 + */ + __pyx_v_veb->max_val = __pyx_v_i; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":211 + * veb.min_val = i + * veb.max_val = i + * elif i == veb.min_val or i == veb.max_val: # <<<<<<<<<<<<<< + * return 0 + * else: + */ + __pyx_t_1 = (__pyx_v_i == __pyx_v_veb->min_val); + if (!__pyx_t_1) { + __pyx_t_2 = (__pyx_v_i == __pyx_v_veb->max_val); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":212 + * veb.max_val = i + * elif i == veb.min_val or i == veb.max_val: + * return 0 # <<<<<<<<<<<<<< + * else: + * if i < veb.min_val: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":214 + * return 0 + * else: + * if i < veb.min_val: # <<<<<<<<<<<<<< + * tmp = i + * i = veb.min_val + */ + __pyx_t_3 = (__pyx_v_i < __pyx_v_veb->min_val); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":215 + * else: + * if i < veb.min_val: + * tmp = i # <<<<<<<<<<<<<< + * i = veb.min_val + * veb.min_val = tmp + */ + __pyx_v_tmp = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":216 + * if i < veb.min_val: + * tmp = i + * i = veb.min_val # <<<<<<<<<<<<<< + * veb.min_val = tmp + * a = i >> veb.num_bottom_bits + */ + __pyx_v_i = __pyx_v_veb->min_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":217 + * tmp = i + * i = veb.min_val + * veb.min_val = tmp # <<<<<<<<<<<<<< + * a = i >> veb.num_bottom_bits + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + */ + __pyx_v_veb->min_val = __pyx_v_tmp; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":218 + * i = veb.min_val + * veb.min_val = tmp + * a = i >> veb.num_bottom_bits # <<<<<<<<<<<<<< + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + * if veb.bottom[a] == NULL: + */ + __pyx_v_a = (__pyx_v_i >> __pyx_v_veb->num_bottom_bits); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":219 + * veb.min_val = tmp + * a = i >> veb.num_bottom_bits + * b = i & LOWER_MASK[veb.num_bottom_bits-1] # <<<<<<<<<<<<<< + * if veb.bottom[a] == NULL: + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + */ + __pyx_v_b = (__pyx_v_i & (__pyx_v_8_cdec_sa_LOWER_MASK[(__pyx_v_veb->num_bottom_bits - 1)])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":220 + * a = i >> veb.num_bottom_bits + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + * if veb.bottom[a] == NULL: # <<<<<<<<<<<<<< + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * subv = <_VEB*> veb.top + */ + __pyx_t_3 = ((__pyx_v_veb->bottom[__pyx_v_a]) == NULL); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":221 + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + * if veb.bottom[a] == NULL: + * if veb.top_universe_size > MIN_BOTTOM_SIZE: # <<<<<<<<<<<<<< + * subv = <_VEB*> veb.top + * VEB_insert(subv, a) + */ + __pyx_t_3 = (__pyx_v_veb->top_universe_size > __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":222 + * if veb.bottom[a] == NULL: + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * subv = <_VEB*> veb.top # <<<<<<<<<<<<<< + * VEB_insert(subv, a) + * else: + */ + __pyx_v_subv = ((struct __pyx_t_8_cdec_sa__VEB *)__pyx_v_veb->top); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":223 + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * subv = <_VEB*> veb.top + * VEB_insert(subv, a) # <<<<<<<<<<<<<< + * else: + * subb = <_BitSet*> veb.top + */ + __pyx_f_8_cdec_sa_VEB_insert(__pyx_v_subv, __pyx_v_a); + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":225 + * VEB_insert(subv, a) + * else: + * subb = <_BitSet*> veb.top # <<<<<<<<<<<<<< + * bitset_insert(subb, a) + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + */ + __pyx_v_subb = ((struct __pyx_t_8_cdec_sa__BitSet *)__pyx_v_veb->top); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":226 + * else: + * subb = <_BitSet*> veb.top + * bitset_insert(subb, a) # <<<<<<<<<<<<<< + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * veb.bottom[a] = new_VEB(1 << veb.num_bottom_bits) + */ + __pyx_f_8_cdec_sa_bitset_insert(__pyx_v_subb, __pyx_v_a); + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":227 + * subb = <_BitSet*> veb.top + * bitset_insert(subb, a) + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< + * veb.bottom[a] = new_VEB(1 << veb.num_bottom_bits) + * else: + */ + __pyx_t_3 = (__pyx_v_veb->num_bottom_bits > __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":228 + * bitset_insert(subb, a) + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * veb.bottom[a] = new_VEB(1 << veb.num_bottom_bits) # <<<<<<<<<<<<<< + * else: + * veb.bottom[a] = new_BitSet() + */ + (__pyx_v_veb->bottom[__pyx_v_a]) = __pyx_f_8_cdec_sa_new_VEB((1 << __pyx_v_veb->num_bottom_bits)); + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":230 + * veb.bottom[a] = new_VEB(1 << veb.num_bottom_bits) + * else: + * veb.bottom[a] = new_BitSet() # <<<<<<<<<<<<<< + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[a] + */ + (__pyx_v_veb->bottom[__pyx_v_a]) = __pyx_f_8_cdec_sa_new_BitSet(); + } + __pyx_L7:; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":231 + * else: + * veb.bottom[a] = new_BitSet() + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< + * subv = <_VEB*> veb.bottom[a] + * if VEB_insert(subv, b) == 0: + */ + __pyx_t_3 = (__pyx_v_veb->num_bottom_bits > __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":232 + * veb.bottom[a] = new_BitSet() + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[a] # <<<<<<<<<<<<<< + * if VEB_insert(subv, b) == 0: + * return 0 + */ + __pyx_v_subv = ((struct __pyx_t_8_cdec_sa__VEB *)(__pyx_v_veb->bottom[__pyx_v_a])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":233 + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[a] + * if VEB_insert(subv, b) == 0: # <<<<<<<<<<<<<< + * return 0 + * else: + */ + __pyx_t_3 = (__pyx_f_8_cdec_sa_VEB_insert(__pyx_v_subv, __pyx_v_b) == 0); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":234 + * subv = <_VEB*> veb.bottom[a] + * if VEB_insert(subv, b) == 0: + * return 0 # <<<<<<<<<<<<<< + * else: + * subb = <_BitSet*> veb.bottom[a] + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L9; + } + __pyx_L9:; + goto __pyx_L8; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":236 + * return 0 + * else: + * subb = <_BitSet*> veb.bottom[a] # <<<<<<<<<<<<<< + * if bitset_insert(subb, b) == 0: + * return 0 + */ + __pyx_v_subb = ((struct __pyx_t_8_cdec_sa__BitSet *)(__pyx_v_veb->bottom[__pyx_v_a])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":237 + * else: + * subb = <_BitSet*> veb.bottom[a] + * if bitset_insert(subb, b) == 0: # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_t_3 = (__pyx_f_8_cdec_sa_bitset_insert(__pyx_v_subb, __pyx_v_b) == 0); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":238 + * subb = <_BitSet*> veb.bottom[a] + * if bitset_insert(subb, b) == 0: + * return 0 # <<<<<<<<<<<<<< + * + * if i > veb.max_val: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L10; + } + __pyx_L10:; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":240 + * return 0 + * + * if i > veb.max_val: # <<<<<<<<<<<<<< + * veb.max_val = i + * veb.size = veb.size + 1 + */ + __pyx_t_3 = (__pyx_v_i > __pyx_v_veb->max_val); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":241 + * + * if i > veb.max_val: + * veb.max_val = i # <<<<<<<<<<<<<< + * veb.size = veb.size + 1 + * return 1 + */ + __pyx_v_veb->max_val = __pyx_v_i; + goto __pyx_L11; + } + __pyx_L11:; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":242 + * if i > veb.max_val: + * veb.max_val = i + * veb.size = veb.size + 1 # <<<<<<<<<<<<<< + * return 1 + * + */ + __pyx_v_veb->size = (__pyx_v_veb->size + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":243 + * veb.max_val = i + * veb.size = veb.size + 1 + * return 1 # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = 1; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":246 + * + * + * cdef del_VEB(_VEB* veb): # <<<<<<<<<<<<<< + * cdef int i + * + */ + +static PyObject *__pyx_f_8_cdec_sa_del_VEB(struct __pyx_t_8_cdec_sa__VEB *__pyx_v_veb) { + int __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("del_VEB", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":249 + * cdef int i + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: # <<<<<<<<<<<<<< + * i = (<_VEB*> veb.top).min_val + * else: + */ + __pyx_t_1 = (__pyx_v_veb->top_universe_size > __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":250 + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * i = (<_VEB*> veb.top).min_val # <<<<<<<<<<<<<< + * else: + * i = (<_BitSet*> veb.top).min_val + */ + __pyx_v_i = ((struct __pyx_t_8_cdec_sa__VEB *)__pyx_v_veb->top)->min_val; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":252 + * i = (<_VEB*> veb.top).min_val + * else: + * i = (<_BitSet*> veb.top).min_val # <<<<<<<<<<<<<< + * + * while i != -1: + */ + __pyx_v_i = ((struct __pyx_t_8_cdec_sa__BitSet *)__pyx_v_veb->top)->min_val; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":254 + * i = (<_BitSet*> veb.top).min_val + * + * while i != -1: # <<<<<<<<<<<<<< + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * del_VEB(<_VEB*> veb.bottom[i]) + */ + while (1) { + __pyx_t_1 = (__pyx_v_i != -1); + if (!__pyx_t_1) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":255 + * + * while i != -1: + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< + * del_VEB(<_VEB*> veb.bottom[i]) + * else: + */ + __pyx_t_1 = (__pyx_v_veb->num_bottom_bits > __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":256 + * while i != -1: + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * del_VEB(<_VEB*> veb.bottom[i]) # <<<<<<<<<<<<<< + * else: + * free(<_BitSet*> veb.bottom[i]) + */ + __pyx_t_2 = __pyx_f_8_cdec_sa_del_VEB(((struct __pyx_t_8_cdec_sa__VEB *)(__pyx_v_veb->bottom[__pyx_v_i]))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":258 + * del_VEB(<_VEB*> veb.bottom[i]) + * else: + * free(<_BitSet*> veb.bottom[i]) # <<<<<<<<<<<<<< + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + */ + free(((struct __pyx_t_8_cdec_sa__BitSet *)(__pyx_v_veb->bottom[__pyx_v_i]))); + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":260 + * free(<_BitSet*> veb.bottom[i]) + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: # <<<<<<<<<<<<<< + * i = VEB_findsucc(<_VEB*> veb.top, i) + * else: + */ + __pyx_t_1 = (__pyx_v_veb->top_universe_size > __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":261 + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * i = VEB_findsucc(<_VEB*> veb.top, i) # <<<<<<<<<<<<<< + * else: + * i = bitset_findsucc(<_BitSet*> veb.top, i) + */ + __pyx_v_i = __pyx_f_8_cdec_sa_VEB_findsucc(((struct __pyx_t_8_cdec_sa__VEB *)__pyx_v_veb->top), __pyx_v_i); + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":263 + * i = VEB_findsucc(<_VEB*> veb.top, i) + * else: + * i = bitset_findsucc(<_BitSet*> veb.top, i) # <<<<<<<<<<<<<< + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + */ + __pyx_v_i = __pyx_f_8_cdec_sa_bitset_findsucc(((struct __pyx_t_8_cdec_sa__BitSet *)__pyx_v_veb->top), __pyx_v_i); + } + __pyx_L7:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":265 + * i = bitset_findsucc(<_BitSet*> veb.top, i) + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: # <<<<<<<<<<<<<< + * del_VEB(<_VEB*> veb.top) + * else: + */ + __pyx_t_1 = (__pyx_v_veb->top_universe_size > __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":266 + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * del_VEB(<_VEB*> veb.top) # <<<<<<<<<<<<<< + * else: + * free(<_BitSet*> veb.top) + */ + __pyx_t_2 = __pyx_f_8_cdec_sa_del_VEB(((struct __pyx_t_8_cdec_sa__VEB *)__pyx_v_veb->top)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 266; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L8; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":268 + * del_VEB(<_VEB*> veb.top) + * else: + * free(<_BitSet*> veb.top) # <<<<<<<<<<<<<< + * free(veb.bottom) + * free(veb) + */ + free(((struct __pyx_t_8_cdec_sa__BitSet *)__pyx_v_veb->top)); + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":269 + * else: + * free(<_BitSet*> veb.top) + * free(veb.bottom) # <<<<<<<<<<<<<< + * free(veb) + * + */ + free(__pyx_v_veb->bottom); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":270 + * free(<_BitSet*> veb.top) + * free(veb.bottom) + * free(veb) # <<<<<<<<<<<<<< + * + * + */ + free(__pyx_v_veb); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec_sa.del_VEB", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":273 + * + * + * cdef int VEB_findsucc(_VEB* veb, int i): # <<<<<<<<<<<<<< + * cdef _VEB* subv + * cdef _BitSet* subb + */ + +static int __pyx_f_8_cdec_sa_VEB_findsucc(struct __pyx_t_8_cdec_sa__VEB *__pyx_v_veb, int __pyx_v_i) { + struct __pyx_t_8_cdec_sa__VEB *__pyx_v_subv; + struct __pyx_t_8_cdec_sa__BitSet *__pyx_v_subb; + int __pyx_v_a; + int __pyx_v_b; + int __pyx_v_j; + int __pyx_v_c; + int __pyx_v_found; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("VEB_findsucc", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":278 + * cdef int a, b, j, c, found + * + * if veb.max_val == -1 or i>=veb.max_val: # <<<<<<<<<<<<<< + * return -1 + * if i < veb.min_val: + */ + __pyx_t_1 = (__pyx_v_veb->max_val == -1); + if (!__pyx_t_1) { + __pyx_t_2 = (__pyx_v_i >= __pyx_v_veb->max_val); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":279 + * + * if veb.max_val == -1 or i>=veb.max_val: + * return -1 # <<<<<<<<<<<<<< + * if i < veb.min_val: + * return veb.min_val + */ + __pyx_r = -1; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":280 + * if veb.max_val == -1 or i>=veb.max_val: + * return -1 + * if i < veb.min_val: # <<<<<<<<<<<<<< + * return veb.min_val + * + */ + __pyx_t_3 = (__pyx_v_i < __pyx_v_veb->min_val); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":281 + * return -1 + * if i < veb.min_val: + * return veb.min_val # <<<<<<<<<<<<<< + * + * a = i >> veb.num_bottom_bits + */ + __pyx_r = __pyx_v_veb->min_val; + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":283 + * return veb.min_val + * + * a = i >> veb.num_bottom_bits # <<<<<<<<<<<<<< + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + * found = 0 + */ + __pyx_v_a = (__pyx_v_i >> __pyx_v_veb->num_bottom_bits); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":284 + * + * a = i >> veb.num_bottom_bits + * b = i & LOWER_MASK[veb.num_bottom_bits-1] # <<<<<<<<<<<<<< + * found = 0 + * if veb.bottom[a] != NULL: + */ + __pyx_v_b = (__pyx_v_i & (__pyx_v_8_cdec_sa_LOWER_MASK[(__pyx_v_veb->num_bottom_bits - 1)])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":285 + * a = i >> veb.num_bottom_bits + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + * found = 0 # <<<<<<<<<<<<<< + * if veb.bottom[a] != NULL: + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + */ + __pyx_v_found = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":286 + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + * found = 0 + * if veb.bottom[a] != NULL: # <<<<<<<<<<<<<< + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[a] + */ + __pyx_t_3 = ((__pyx_v_veb->bottom[__pyx_v_a]) != NULL); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":287 + * found = 0 + * if veb.bottom[a] != NULL: + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< + * subv = <_VEB*> veb.bottom[a] + * if subv.max_val > b: + */ + __pyx_t_3 = (__pyx_v_veb->num_bottom_bits > __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":288 + * if veb.bottom[a] != NULL: + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[a] # <<<<<<<<<<<<<< + * if subv.max_val > b: + * j = (a << veb.num_bottom_bits) + VEB_findsucc(subv, b) + */ + __pyx_v_subv = ((struct __pyx_t_8_cdec_sa__VEB *)(__pyx_v_veb->bottom[__pyx_v_a])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":289 + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[a] + * if subv.max_val > b: # <<<<<<<<<<<<<< + * j = (a << veb.num_bottom_bits) + VEB_findsucc(subv, b) + * found = 1 + */ + __pyx_t_3 = (__pyx_v_subv->max_val > __pyx_v_b); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":290 + * subv = <_VEB*> veb.bottom[a] + * if subv.max_val > b: + * j = (a << veb.num_bottom_bits) + VEB_findsucc(subv, b) # <<<<<<<<<<<<<< + * found = 1 + * else: + */ + __pyx_v_j = ((__pyx_v_a << __pyx_v_veb->num_bottom_bits) + __pyx_f_8_cdec_sa_VEB_findsucc(__pyx_v_subv, __pyx_v_b)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":291 + * if subv.max_val > b: + * j = (a << veb.num_bottom_bits) + VEB_findsucc(subv, b) + * found = 1 # <<<<<<<<<<<<<< + * else: + * subb = <_BitSet*> veb.bottom[a] + */ + __pyx_v_found = 1; + goto __pyx_L7; + } + __pyx_L7:; + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":293 + * found = 1 + * else: + * subb = <_BitSet*> veb.bottom[a] # <<<<<<<<<<<<<< + * if subb.max_val > b: + * j = (a << veb.num_bottom_bits) + bitset_findsucc(subb, b) + */ + __pyx_v_subb = ((struct __pyx_t_8_cdec_sa__BitSet *)(__pyx_v_veb->bottom[__pyx_v_a])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":294 + * else: + * subb = <_BitSet*> veb.bottom[a] + * if subb.max_val > b: # <<<<<<<<<<<<<< + * j = (a << veb.num_bottom_bits) + bitset_findsucc(subb, b) + * found = 1 + */ + __pyx_t_3 = (__pyx_v_subb->max_val > __pyx_v_b); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":295 + * subb = <_BitSet*> veb.bottom[a] + * if subb.max_val > b: + * j = (a << veb.num_bottom_bits) + bitset_findsucc(subb, b) # <<<<<<<<<<<<<< + * found = 1 + * if found==0: + */ + __pyx_v_j = ((__pyx_v_a << __pyx_v_veb->num_bottom_bits) + __pyx_f_8_cdec_sa_bitset_findsucc(__pyx_v_subb, __pyx_v_b)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":296 + * if subb.max_val > b: + * j = (a << veb.num_bottom_bits) + bitset_findsucc(subb, b) + * found = 1 # <<<<<<<<<<<<<< + * if found==0: + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + */ + __pyx_v_found = 1; + goto __pyx_L8; + } + __pyx_L8:; + } + __pyx_L6:; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":297 + * j = (a << veb.num_bottom_bits) + bitset_findsucc(subb, b) + * found = 1 + * if found==0: # <<<<<<<<<<<<<< + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * subv = <_VEB*> veb.top + */ + __pyx_t_3 = (__pyx_v_found == 0); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":298 + * found = 1 + * if found==0: + * if veb.top_universe_size > MIN_BOTTOM_SIZE: # <<<<<<<<<<<<<< + * subv = <_VEB*> veb.top + * c = VEB_findsucc(subv, a) + */ + __pyx_t_3 = (__pyx_v_veb->top_universe_size > __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":299 + * if found==0: + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * subv = <_VEB*> veb.top # <<<<<<<<<<<<<< + * c = VEB_findsucc(subv, a) + * else: + */ + __pyx_v_subv = ((struct __pyx_t_8_cdec_sa__VEB *)__pyx_v_veb->top); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":300 + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * subv = <_VEB*> veb.top + * c = VEB_findsucc(subv, a) # <<<<<<<<<<<<<< + * else: + * subb = <_BitSet*> veb.top + */ + __pyx_v_c = __pyx_f_8_cdec_sa_VEB_findsucc(__pyx_v_subv, __pyx_v_a); + goto __pyx_L10; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":302 + * c = VEB_findsucc(subv, a) + * else: + * subb = <_BitSet*> veb.top # <<<<<<<<<<<<<< + * c = bitset_findsucc(subb, a) + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + */ + __pyx_v_subb = ((struct __pyx_t_8_cdec_sa__BitSet *)__pyx_v_veb->top); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":303 + * else: + * subb = <_BitSet*> veb.top + * c = bitset_findsucc(subb, a) # <<<<<<<<<<<<<< + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[c] + */ + __pyx_v_c = __pyx_f_8_cdec_sa_bitset_findsucc(__pyx_v_subb, __pyx_v_a); + } + __pyx_L10:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":304 + * subb = <_BitSet*> veb.top + * c = bitset_findsucc(subb, a) + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< + * subv = <_VEB*> veb.bottom[c] + * j = (c << veb.num_bottom_bits) + subv.min_val + */ + __pyx_t_3 = (__pyx_v_veb->num_bottom_bits > __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":305 + * c = bitset_findsucc(subb, a) + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[c] # <<<<<<<<<<<<<< + * j = (c << veb.num_bottom_bits) + subv.min_val + * else: + */ + __pyx_v_subv = ((struct __pyx_t_8_cdec_sa__VEB *)(__pyx_v_veb->bottom[__pyx_v_c])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":306 + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[c] + * j = (c << veb.num_bottom_bits) + subv.min_val # <<<<<<<<<<<<<< + * else: + * subb = <_BitSet*> veb.bottom[c] + */ + __pyx_v_j = ((__pyx_v_c << __pyx_v_veb->num_bottom_bits) + __pyx_v_subv->min_val); + goto __pyx_L11; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":308 + * j = (c << veb.num_bottom_bits) + subv.min_val + * else: + * subb = <_BitSet*> veb.bottom[c] # <<<<<<<<<<<<<< + * j = (c << veb.num_bottom_bits) + subb.min_val + * return j + */ + __pyx_v_subb = ((struct __pyx_t_8_cdec_sa__BitSet *)(__pyx_v_veb->bottom[__pyx_v_c])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":309 + * else: + * subb = <_BitSet*> veb.bottom[c] + * j = (c << veb.num_bottom_bits) + subb.min_val # <<<<<<<<<<<<<< + * return j + * + */ + __pyx_v_j = ((__pyx_v_c << __pyx_v_veb->num_bottom_bits) + __pyx_v_subb->min_val); + } + __pyx_L11:; + goto __pyx_L9; + } + __pyx_L9:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":310 + * subb = <_BitSet*> veb.bottom[c] + * j = (c << veb.num_bottom_bits) + subb.min_val + * return j # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_j; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":313 + * + * + * cdef int VEB_contains(_VEB* veb, int i): # <<<<<<<<<<<<<< + * cdef _VEB* subv + * cdef _BitSet* subb + */ + +static int __pyx_f_8_cdec_sa_VEB_contains(struct __pyx_t_8_cdec_sa__VEB *__pyx_v_veb, int __pyx_v_i) { + struct __pyx_t_8_cdec_sa__VEB *__pyx_v_subv; + struct __pyx_t_8_cdec_sa__BitSet *__pyx_v_subb; + int __pyx_v_a; + int __pyx_v_b; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + __Pyx_RefNannySetupContext("VEB_contains", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":318 + * cdef int a, b + * + * if veb.size == 0 or i < veb.min_val or i > veb.max_val: # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_t_1 = (__pyx_v_veb->size == 0); + if (!__pyx_t_1) { + __pyx_t_2 = (__pyx_v_i < __pyx_v_veb->min_val); + if (!__pyx_t_2) { + __pyx_t_3 = (__pyx_v_i > __pyx_v_veb->max_val); + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_2; + } + __pyx_t_2 = __pyx_t_4; + } else { + __pyx_t_2 = __pyx_t_1; + } + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":319 + * + * if veb.size == 0 or i < veb.min_val or i > veb.max_val: + * return 0 # <<<<<<<<<<<<<< + * + * if veb.min_val == i: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":321 + * return 0 + * + * if veb.min_val == i: # <<<<<<<<<<<<<< + * return 1 + * else: + */ + __pyx_t_2 = (__pyx_v_veb->min_val == __pyx_v_i); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":322 + * + * if veb.min_val == i: + * return 1 # <<<<<<<<<<<<<< + * else: + * if veb.size == 1: + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":324 + * return 1 + * else: + * if veb.size == 1: # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_t_2 = (__pyx_v_veb->size == 1); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":325 + * else: + * if veb.size == 1: + * return 0 # <<<<<<<<<<<<<< + * + * a = i >> veb.num_bottom_bits + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":327 + * return 0 + * + * a = i >> veb.num_bottom_bits # <<<<<<<<<<<<<< + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + * if veb.bottom[a] == NULL: + */ + __pyx_v_a = (__pyx_v_i >> __pyx_v_veb->num_bottom_bits); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":328 + * + * a = i >> veb.num_bottom_bits + * b = i & LOWER_MASK[veb.num_bottom_bits-1] # <<<<<<<<<<<<<< + * if veb.bottom[a] == NULL: + * return 0 + */ + __pyx_v_b = (__pyx_v_i & (__pyx_v_8_cdec_sa_LOWER_MASK[(__pyx_v_veb->num_bottom_bits - 1)])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":329 + * a = i >> veb.num_bottom_bits + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + * if veb.bottom[a] == NULL: # <<<<<<<<<<<<<< + * return 0 + * else: + */ + __pyx_t_2 = ((__pyx_v_veb->bottom[__pyx_v_a]) == NULL); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":330 + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + * if veb.bottom[a] == NULL: + * return 0 # <<<<<<<<<<<<<< + * else: + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":332 + * return 0 + * else: + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< + * subv = <_VEB*> veb.bottom[a] + * return VEB_contains(subv, b) + */ + __pyx_t_2 = (__pyx_v_veb->num_bottom_bits > __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":333 + * else: + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[a] # <<<<<<<<<<<<<< + * return VEB_contains(subv, b) + * else: + */ + __pyx_v_subv = ((struct __pyx_t_8_cdec_sa__VEB *)(__pyx_v_veb->bottom[__pyx_v_a])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":334 + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[a] + * return VEB_contains(subv, b) # <<<<<<<<<<<<<< + * else: + * subb = <_BitSet*> veb.bottom[a] + */ + __pyx_r = __pyx_f_8_cdec_sa_VEB_contains(__pyx_v_subv, __pyx_v_b); + goto __pyx_L0; + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":336 + * return VEB_contains(subv, b) + * else: + * subb = <_BitSet*> veb.bottom[a] # <<<<<<<<<<<<<< + * return bitset_contains(subb, b) + * + */ + __pyx_v_subb = ((struct __pyx_t_8_cdec_sa__BitSet *)(__pyx_v_veb->bottom[__pyx_v_a])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":337 + * else: + * subb = <_BitSet*> veb.bottom[a] + * return bitset_contains(subb, b) # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_f_8_cdec_sa_bitset_contains(__pyx_v_subb, __pyx_v_b); + goto __pyx_L0; + } + __pyx_L7:; + } + __pyx_L6:; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_11VEBIterator_1__next__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_11VEBIterator_1__next__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__next__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_11VEBIterator___next__(((struct __pyx_obj_8_cdec_sa_VEBIterator *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":344 + * cdef int next_val + * + * def __next__(self): # <<<<<<<<<<<<<< + * cdef int ret_val + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_11VEBIterator___next__(struct __pyx_obj_8_cdec_sa_VEBIterator *__pyx_v_self) { + int __pyx_v_ret_val; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__next__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":347 + * cdef int ret_val + * + * if self.next_val == -1: # <<<<<<<<<<<<<< + * raise StopIteration() + * ret_val = self.next_val + */ + __pyx_t_1 = (__pyx_v_self->next_val == -1); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":348 + * + * if self.next_val == -1: + * raise StopIteration() # <<<<<<<<<<<<<< + * ret_val = self.next_val + * self.next_val = VEB_findsucc(self.v, ret_val) + */ + __pyx_t_2 = PyObject_Call(__pyx_builtin_StopIteration, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[6]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":349 + * if self.next_val == -1: + * raise StopIteration() + * ret_val = self.next_val # <<<<<<<<<<<<<< + * self.next_val = VEB_findsucc(self.v, ret_val) + * return ret_val + */ + __pyx_v_ret_val = __pyx_v_self->next_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":350 + * raise StopIteration() + * ret_val = self.next_val + * self.next_val = VEB_findsucc(self.v, ret_val) # <<<<<<<<<<<<<< + * return ret_val + * + */ + __pyx_v_self->next_val = __pyx_f_8_cdec_sa_VEB_findsucc(__pyx_v_self->v, __pyx_v_ret_val); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":351 + * ret_val = self.next_val + * self.next_val = VEB_findsucc(self.v, ret_val) + * return ret_val # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyInt_FromLong(__pyx_v_ret_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_cdec_sa.VEBIterator.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_3VEB_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_3VEB_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_size; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__size,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size); + 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 360; __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_size = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 360; __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[6]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.VEB.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_3VEB___cinit__(((struct __pyx_obj_8_cdec_sa_VEB *)__pyx_v_self), __pyx_v_size); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":360 + * cdef int _first(self) + * + * def __cinit__(self, int size): # <<<<<<<<<<<<<< + * self.veb = new_VEB(size) + * + */ + +static int __pyx_pf_8_cdec_sa_3VEB___cinit__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, int __pyx_v_size) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":361 + * + * def __cinit__(self, int size): + * self.veb = new_VEB(size) # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->veb = __pyx_f_8_cdec_sa_new_VEB(__pyx_v_size); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_8_cdec_sa_3VEB_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_8_cdec_sa_3VEB_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_8_cdec_sa_3VEB_2__dealloc__(((struct __pyx_obj_8_cdec_sa_VEB *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":363 + * self.veb = new_VEB(size) + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del_VEB(self.veb) + * + */ + +static void __pyx_pf_8_cdec_sa_3VEB_2__dealloc__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self) { + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":364 + * + * def __dealloc__(self): + * del_VEB(self.veb) # <<<<<<<<<<<<<< + * + * def __iter__(self): + */ + __pyx_t_1 = __pyx_f_8_cdec_sa_del_VEB(__pyx_v_self->veb); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec_sa.VEB.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_3VEB_5__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_3VEB_5__iter__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_3VEB_4__iter__(((struct __pyx_obj_8_cdec_sa_VEB *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":366 + * del_VEB(self.veb) + * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef VEBIterator it + * it = VEBIterator() + */ + +static PyObject *__pyx_pf_8_cdec_sa_3VEB_4__iter__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self) { + struct __pyx_obj_8_cdec_sa_VEBIterator *__pyx_v_it = 0; + 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("__iter__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":368 + * def __iter__(self): + * cdef VEBIterator it + * it = VEBIterator() # <<<<<<<<<<<<<< + * it.v = self.veb + * it.next_val = self.veb.min_val + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_VEBIterator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_it = ((struct __pyx_obj_8_cdec_sa_VEBIterator *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":369 + * cdef VEBIterator it + * it = VEBIterator() + * it.v = self.veb # <<<<<<<<<<<<<< + * it.next_val = self.veb.min_val + * return it + */ + __pyx_v_it->v = __pyx_v_self->veb; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":370 + * it = VEBIterator() + * it.v = self.veb + * it.next_val = self.veb.min_val # <<<<<<<<<<<<<< + * return it + * + */ + __pyx_v_it->next_val = __pyx_v_self->veb->min_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":371 + * it.v = self.veb + * it.next_val = self.veb.min_val + * return it # <<<<<<<<<<<<<< + * + * def insert(self, i): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_it)); + __pyx_r = ((PyObject *)__pyx_v_it); + 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_sa.VEB.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_it); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_3VEB_7insert(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_3VEB_7insert(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("insert (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_3VEB_6insert(((struct __pyx_obj_8_cdec_sa_VEB *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":373 + * return it + * + * def insert(self, i): # <<<<<<<<<<<<<< + * return VEB_insert(self.veb, i) + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_3VEB_6insert(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("insert", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":374 + * + * def insert(self, i): + * return VEB_insert(self.veb, i) # <<<<<<<<<<<<<< + * + * cdef int _insert(self, int i): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong(__pyx_f_8_cdec_sa_VEB_insert(__pyx_v_self->veb, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_cdec_sa.VEB.insert", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":376 + * return VEB_insert(self.veb, i) + * + * cdef int _insert(self, int i): # <<<<<<<<<<<<<< + * return VEB_insert(self.veb, i) + * + */ + +static int __pyx_f_8_cdec_sa_3VEB__insert(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, int __pyx_v_i) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_insert", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":377 + * + * cdef int _insert(self, int i): + * return VEB_insert(self.veb, i) # <<<<<<<<<<<<<< + * + * def findsucc(self, i): + */ + __pyx_r = __pyx_f_8_cdec_sa_VEB_insert(__pyx_v_self->veb, __pyx_v_i); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_3VEB_9findsucc(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_3VEB_9findsucc(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("findsucc (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_3VEB_8findsucc(((struct __pyx_obj_8_cdec_sa_VEB *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":379 + * return VEB_insert(self.veb, i) + * + * def findsucc(self, i): # <<<<<<<<<<<<<< + * return VEB_findsucc(self.veb, i) + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_3VEB_8findsucc(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("findsucc", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":380 + * + * def findsucc(self, i): + * return VEB_findsucc(self.veb, i) # <<<<<<<<<<<<<< + * + * cdef int _first(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong(__pyx_f_8_cdec_sa_VEB_findsucc(__pyx_v_self->veb, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_cdec_sa.VEB.findsucc", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":382 + * return VEB_findsucc(self.veb, i) + * + * cdef int _first(self): # <<<<<<<<<<<<<< + * return self.veb.min_val + * + */ + +static int __pyx_f_8_cdec_sa_3VEB__first(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_first", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":383 + * + * cdef int _first(self): + * return self.veb.min_val # <<<<<<<<<<<<<< + * + * cdef int _findsucc(self, int i): + */ + __pyx_r = __pyx_v_self->veb->min_val; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":385 + * return self.veb.min_val + * + * cdef int _findsucc(self, int i): # <<<<<<<<<<<<<< + * return VEB_findsucc(self.veb, i) + * + */ + +static int __pyx_f_8_cdec_sa_3VEB__findsucc(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, int __pyx_v_i) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_findsucc", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":386 + * + * cdef int _findsucc(self, int i): + * return VEB_findsucc(self.veb, i) # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + __pyx_r = __pyx_f_8_cdec_sa_VEB_findsucc(__pyx_v_self->veb, __pyx_v_i); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_8_cdec_sa_3VEB_11__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_8_cdec_sa_3VEB_11__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_3VEB_10__len__(((struct __pyx_obj_8_cdec_sa_VEB *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":388 + * return VEB_findsucc(self.veb, i) + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.veb.size + * + */ + +static Py_ssize_t __pyx_pf_8_cdec_sa_3VEB_10__len__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":389 + * + * def __len__(self): + * return self.veb.size # <<<<<<<<<<<<<< + * + * def __contains__(self, i): + */ + __pyx_r = __pyx_v_self->veb->size; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_3VEB_13__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static int __pyx_pw_8_cdec_sa_3VEB_13__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_3VEB_12__contains__(((struct __pyx_obj_8_cdec_sa_VEB *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":391 + * return self.veb.size + * + * def __contains__(self, i): # <<<<<<<<<<<<<< + * return VEB_contains(self.veb, i) + */ + +static int __pyx_pf_8_cdec_sa_3VEB_12__contains__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, PyObject *__pyx_v_i) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__contains__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":392 + * + * def __contains__(self, i): + * return VEB_contains(self.veb, i) # <<<<<<<<<<<<<< + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_f_8_cdec_sa_VEB_contains(__pyx_v_self->veb, __pyx_t_1); + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec_sa.VEB.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_3LCP_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_3LCP_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_sa = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sa,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sa); + 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 9; __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_sa = ((struct __pyx_obj_8_cdec_sa_SuffixArray *)values[0]); + } + 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[9]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.LCP.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_sa), __pyx_ptype_8_cdec_sa_SuffixArray, 1, "sa", 0))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_8_cdec_sa_3LCP___cinit__(((struct __pyx_obj_8_cdec_sa_LCP *)__pyx_v_self), __pyx_v_sa); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":9 + * cdef IntList lcp + * + * def __cinit__(self, SuffixArray sa): # <<<<<<<<<<<<<< + * cdef int i, k, j, h, n + * cdef IntList rank + */ + +static int __pyx_pf_8_cdec_sa_3LCP___cinit__(struct __pyx_obj_8_cdec_sa_LCP *__pyx_v_self, struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_sa) { + int __pyx_v_i; + int __pyx_v_k; + int __pyx_v_j; + int __pyx_v_h; + int __pyx_v_n; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_rank = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":13 + * cdef IntList rank + * + * logger.info("Constructing LCP array") # <<<<<<<<<<<<<< + * self.sa = sa + * n = self.sa.sa.len + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_58), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":14 + * + * logger.info("Constructing LCP array") + * self.sa = sa # <<<<<<<<<<<<<< + * n = self.sa.sa.len + * self.lcp = IntList(initial_len=n) + */ + __Pyx_INCREF(((PyObject *)__pyx_v_sa)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_sa)); + __Pyx_GOTREF(__pyx_v_self->sa); + __Pyx_DECREF(((PyObject *)__pyx_v_self->sa)); + __pyx_v_self->sa = __pyx_v_sa; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":15 + * logger.info("Constructing LCP array") + * self.sa = sa + * n = self.sa.sa.len # <<<<<<<<<<<<<< + * self.lcp = IntList(initial_len=n) + * + */ + __pyx_v_n = __pyx_v_self->sa->sa->len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":16 + * self.sa = sa + * n = self.sa.sa.len + * self.lcp = IntList(initial_len=n) # <<<<<<<<<<<<<< + * + * rank = IntList(initial_len=n) + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 16; __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); + __Pyx_GOTREF(__pyx_v_self->lcp); + __Pyx_DECREF(((PyObject *)__pyx_v_self->lcp)); + __pyx_v_self->lcp = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":18 + * self.lcp = IntList(initial_len=n) + * + * rank = IntList(initial_len=n) # <<<<<<<<<<<<<< + * for i from 0 <= i < n: + * rank.arr[sa.sa.arr[i]] = i + */ + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_1 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_v_rank = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":19 + * + * rank = IntList(initial_len=n) + * for i from 0 <= i < n: # <<<<<<<<<<<<<< + * rank.arr[sa.sa.arr[i]] = i + * + */ + __pyx_t_3 = __pyx_v_n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":20 + * rank = IntList(initial_len=n) + * for i from 0 <= i < n: + * rank.arr[sa.sa.arr[i]] = i # <<<<<<<<<<<<<< + * + * h = 0 + */ + (__pyx_v_rank->arr[(__pyx_v_sa->sa->arr[__pyx_v_i])]) = __pyx_v_i; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":22 + * rank.arr[sa.sa.arr[i]] = i + * + * h = 0 # <<<<<<<<<<<<<< + * for i from 0 <= i < n: + * k = rank.arr[i] + */ + __pyx_v_h = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":23 + * + * h = 0 + * for i from 0 <= i < n: # <<<<<<<<<<<<<< + * k = rank.arr[i] + * if k == 0: + */ + __pyx_t_3 = __pyx_v_n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":24 + * h = 0 + * for i from 0 <= i < n: + * k = rank.arr[i] # <<<<<<<<<<<<<< + * if k == 0: + * self.lcp.arr[k] = -1 + */ + __pyx_v_k = (__pyx_v_rank->arr[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":25 + * for i from 0 <= i < n: + * k = rank.arr[i] + * if k == 0: # <<<<<<<<<<<<<< + * self.lcp.arr[k] = -1 + * else: + */ + __pyx_t_4 = (__pyx_v_k == 0); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":26 + * k = rank.arr[i] + * if k == 0: + * self.lcp.arr[k] = -1 # <<<<<<<<<<<<<< + * else: + * j = sa.sa.arr[k-1] + */ + (__pyx_v_self->lcp->arr[__pyx_v_k]) = -1; + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":28 + * self.lcp.arr[k] = -1 + * else: + * j = sa.sa.arr[k-1] # <<<<<<<<<<<<<< + * while i+h < n and j+h < n and sa.darray.data.arr[i+h] == sa.darray.data.arr[j+h]: + * h = h+1 + */ + __pyx_v_j = (__pyx_v_sa->sa->arr[(__pyx_v_k - 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":29 + * else: + * j = sa.sa.arr[k-1] + * while i+h < n and j+h < n and sa.darray.data.arr[i+h] == sa.darray.data.arr[j+h]: # <<<<<<<<<<<<<< + * h = h+1 + * self.lcp.arr[k] = h + */ + while (1) { + __pyx_t_4 = ((__pyx_v_i + __pyx_v_h) < __pyx_v_n); + if (__pyx_t_4) { + __pyx_t_5 = ((__pyx_v_j + __pyx_v_h) < __pyx_v_n); + if (__pyx_t_5) { + __pyx_t_6 = ((__pyx_v_sa->darray->data->arr[(__pyx_v_i + __pyx_v_h)]) == (__pyx_v_sa->darray->data->arr[(__pyx_v_j + __pyx_v_h)])); + __pyx_t_7 = __pyx_t_6; + } else { + __pyx_t_7 = __pyx_t_5; + } + __pyx_t_5 = __pyx_t_7; + } else { + __pyx_t_5 = __pyx_t_4; + } + if (!__pyx_t_5) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":30 + * j = sa.sa.arr[k-1] + * while i+h < n and j+h < n and sa.darray.data.arr[i+h] == sa.darray.data.arr[j+h]: + * h = h+1 # <<<<<<<<<<<<<< + * self.lcp.arr[k] = h + * if h > 0: + */ + __pyx_v_h = (__pyx_v_h + 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":31 + * while i+h < n and j+h < n and sa.darray.data.arr[i+h] == sa.darray.data.arr[j+h]: + * h = h+1 + * self.lcp.arr[k] = h # <<<<<<<<<<<<<< + * if h > 0: + * h = h-1 + */ + (__pyx_v_self->lcp->arr[__pyx_v_k]) = __pyx_v_h; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":32 + * h = h+1 + * self.lcp.arr[k] = h + * if h > 0: # <<<<<<<<<<<<<< + * h = h-1 + * logger.info("LCP array completed") + */ + __pyx_t_5 = (__pyx_v_h > 0); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":33 + * self.lcp.arr[k] = h + * if h > 0: + * h = h-1 # <<<<<<<<<<<<<< + * logger.info("LCP array completed") + * + */ + __pyx_v_h = (__pyx_v_h - 1); + goto __pyx_L10; + } + __pyx_L10:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":34 + * if h > 0: + * h = h-1 + * logger.info("LCP array completed") # <<<<<<<<<<<<<< + * + * def compute_stats(self, int max_n): + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_60), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec_sa.LCP.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_rank); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_8_cdec_sa_3LCP_4generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_3LCP_3compute_stats(PyObject *__pyx_v_self, PyObject *__pyx_arg_max_n); /*proto*/ +static char __pyx_doc_8_cdec_sa_3LCP_2compute_stats[] = "Note: the output of this function is not exact. In\n particular, the frequency associated with each word is \n not guaranteed to be correct. This is due to a bit of\n laxness in the design; the function is intended only to\n obtain a list of the most frequent words; for this \n purpose it is perfectly fine"; +static PyObject *__pyx_pw_8_cdec_sa_3LCP_3compute_stats(PyObject *__pyx_v_self, PyObject *__pyx_arg_max_n) { + int __pyx_v_max_n; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("compute_stats (wrapper)", 0); + assert(__pyx_arg_max_n); { + __pyx_v_max_n = __Pyx_PyInt_AsInt(__pyx_arg_max_n); if (unlikely((__pyx_v_max_n == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.LCP.compute_stats", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_3LCP_2compute_stats(((struct __pyx_obj_8_cdec_sa_LCP *)__pyx_v_self), ((int)__pyx_v_max_n)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":36 + * logger.info("LCP array completed") + * + * def compute_stats(self, int max_n): # <<<<<<<<<<<<<< + * """Note: the output of this function is not exact. In + * particular, the frequency associated with each word is + */ + +static PyObject *__pyx_pf_8_cdec_sa_3LCP_2compute_stats(struct __pyx_obj_8_cdec_sa_LCP *__pyx_v_self, int __pyx_v_max_n) { + struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("compute_stats", 0); + __pyx_cur_scope = (struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *)__pyx_ptype_8_cdec_sa___pyx_scope_struct__compute_stats->tp_new(__pyx_ptype_8_cdec_sa___pyx_scope_struct__compute_stats, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __pyx_cur_scope->__pyx_v_max_n = __pyx_v_max_n; + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_8_cdec_sa_3LCP_4generator, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec_sa.LCP.compute_stats", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_8_cdec_sa_3LCP_4generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *__pyx_cur_scope = ((struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + long __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L26_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[9]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":48 + * cdef VEB veb + * + * N = self.sa.sa.len # <<<<<<<<<<<<<< + * + * ngram_starts = [] + */ + __pyx_cur_scope->__pyx_v_N = __pyx_cur_scope->__pyx_v_self->sa->sa->len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":50 + * N = self.sa.sa.len + * + * ngram_starts = [] # <<<<<<<<<<<<<< + * for n from 0 <= n < max_n: + * ngram_starts.append(IntList(initial_len=N)) + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_cur_scope->__pyx_v_ngram_starts = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":51 + * + * ngram_starts = [] + * for n from 0 <= n < max_n: # <<<<<<<<<<<<<< + * ngram_starts.append(IntList(initial_len=N)) + * + */ + __pyx_t_2 = __pyx_cur_scope->__pyx_v_max_n; + for (__pyx_cur_scope->__pyx_v_n = 0; __pyx_cur_scope->__pyx_v_n < __pyx_t_2; __pyx_cur_scope->__pyx_v_n++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":52 + * ngram_starts = [] + * for n from 0 <= n < max_n: + * ngram_starts.append(IntList(initial_len=N)) # <<<<<<<<<<<<<< + * + * run_start = IntList(initial_len=max_n) + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_4 = PyList_Append(__pyx_cur_scope->__pyx_v_ngram_starts, __pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":54 + * ngram_starts.append(IntList(initial_len=N)) + * + * run_start = IntList(initial_len=max_n) # <<<<<<<<<<<<<< + * veb = VEB(N) + * + */ + __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_t_1 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_max_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_run_start = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":55 + * + * run_start = IntList(initial_len=max_n) + * veb = VEB(N) # <<<<<<<<<<<<<< + * + * for i from 0 <= i < N: + */ + __pyx_t_1 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_VEB)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_veb = ((struct __pyx_obj_8_cdec_sa_VEB *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":57 + * veb = VEB(N) + * + * for i from 0 <= i < N: # <<<<<<<<<<<<<< + * h = self.lcp.arr[i] + * if h < 0: + */ + __pyx_t_2 = __pyx_cur_scope->__pyx_v_N; + for (__pyx_cur_scope->__pyx_v_i = 0; __pyx_cur_scope->__pyx_v_i < __pyx_t_2; __pyx_cur_scope->__pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":58 + * + * for i from 0 <= i < N: + * h = self.lcp.arr[i] # <<<<<<<<<<<<<< + * if h < 0: + * h = 0 + */ + __pyx_cur_scope->__pyx_v_h = (__pyx_cur_scope->__pyx_v_self->lcp->arr[__pyx_cur_scope->__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":59 + * for i from 0 <= i < N: + * h = self.lcp.arr[i] + * if h < 0: # <<<<<<<<<<<<<< + * h = 0 + * for n from h <= n < max_n: + */ + __pyx_t_5 = (__pyx_cur_scope->__pyx_v_h < 0); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":60 + * h = self.lcp.arr[i] + * if h < 0: + * h = 0 # <<<<<<<<<<<<<< + * for n from h <= n < max_n: + * rs = run_start.arr[n] + */ + __pyx_cur_scope->__pyx_v_h = 0; + goto __pyx_L8; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":61 + * if h < 0: + * h = 0 + * for n from h <= n < max_n: # <<<<<<<<<<<<<< + * rs = run_start.arr[n] + * run_start.arr[n] = i + */ + __pyx_t_6 = __pyx_cur_scope->__pyx_v_max_n; + for (__pyx_cur_scope->__pyx_v_n = __pyx_cur_scope->__pyx_v_h; __pyx_cur_scope->__pyx_v_n < __pyx_t_6; __pyx_cur_scope->__pyx_v_n++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":62 + * h = 0 + * for n from h <= n < max_n: + * rs = run_start.arr[n] # <<<<<<<<<<<<<< + * run_start.arr[n] = i + * freq = i - rs + */ + __pyx_cur_scope->__pyx_v_rs = (__pyx_cur_scope->__pyx_v_run_start->arr[__pyx_cur_scope->__pyx_v_n]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":63 + * for n from h <= n < max_n: + * rs = run_start.arr[n] + * run_start.arr[n] = i # <<<<<<<<<<<<<< + * freq = i - rs + * if freq > 1000: # arbitrary, but see note below + */ + (__pyx_cur_scope->__pyx_v_run_start->arr[__pyx_cur_scope->__pyx_v_n]) = __pyx_cur_scope->__pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":64 + * rs = run_start.arr[n] + * run_start.arr[n] = i + * freq = i - rs # <<<<<<<<<<<<<< + * if freq > 1000: # arbitrary, but see note below + * veb._insert(freq) + */ + __pyx_cur_scope->__pyx_v_freq = (__pyx_cur_scope->__pyx_v_i - __pyx_cur_scope->__pyx_v_rs); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":65 + * run_start.arr[n] = i + * freq = i - rs + * if freq > 1000: # arbitrary, but see note below # <<<<<<<<<<<<<< + * veb._insert(freq) + * ngram_start = ngram_starts[n] + */ + __pyx_t_5 = (__pyx_cur_scope->__pyx_v_freq > 1000); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":66 + * freq = i - rs + * if freq > 1000: # arbitrary, but see note below + * veb._insert(freq) # <<<<<<<<<<<<<< + * ngram_start = ngram_starts[n] + * while ngram_start.arr[freq] > 0: + */ + ((struct __pyx_vtabstruct_8_cdec_sa_VEB *)__pyx_cur_scope->__pyx_v_veb->__pyx_vtab)->_insert(__pyx_cur_scope->__pyx_v_veb, __pyx_cur_scope->__pyx_v_freq); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":67 + * if freq > 1000: # arbitrary, but see note below + * veb._insert(freq) + * ngram_start = ngram_starts[n] # <<<<<<<<<<<<<< + * while ngram_start.arr[freq] > 0: + * freq = freq + 1 # cheating a bit, should be ok for sparse histogram + */ + __pyx_t_1 = __Pyx_GetItemInt_List(((PyObject *)__pyx_cur_scope->__pyx_v_ngram_starts), __pyx_cur_scope->__pyx_v_n, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8_cdec_sa_IntList))))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram_start)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram_start)); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_ngram_start = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":68 + * veb._insert(freq) + * ngram_start = ngram_starts[n] + * while ngram_start.arr[freq] > 0: # <<<<<<<<<<<<<< + * freq = freq + 1 # cheating a bit, should be ok for sparse histogram + * ngram_start.arr[freq] = rs + */ + while (1) { + __pyx_t_5 = ((__pyx_cur_scope->__pyx_v_ngram_start->arr[__pyx_cur_scope->__pyx_v_freq]) > 0); + if (!__pyx_t_5) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":69 + * ngram_start = ngram_starts[n] + * while ngram_start.arr[freq] > 0: + * freq = freq + 1 # cheating a bit, should be ok for sparse histogram # <<<<<<<<<<<<<< + * ngram_start.arr[freq] = rs + * i = veb.veb.min_val + */ + __pyx_cur_scope->__pyx_v_freq = (__pyx_cur_scope->__pyx_v_freq + 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":70 + * while ngram_start.arr[freq] > 0: + * freq = freq + 1 # cheating a bit, should be ok for sparse histogram + * ngram_start.arr[freq] = rs # <<<<<<<<<<<<<< + * i = veb.veb.min_val + * while i != -1: + */ + (__pyx_cur_scope->__pyx_v_ngram_start->arr[__pyx_cur_scope->__pyx_v_freq]) = __pyx_cur_scope->__pyx_v_rs; + goto __pyx_L11; + } + __pyx_L11:; + } + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":71 + * freq = freq + 1 # cheating a bit, should be ok for sparse histogram + * ngram_start.arr[freq] = rs + * i = veb.veb.min_val # <<<<<<<<<<<<<< + * while i != -1: + * ii = veb._findsucc(i) + */ + __pyx_cur_scope->__pyx_v_i = __pyx_cur_scope->__pyx_v_veb->veb->min_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":72 + * ngram_start.arr[freq] = rs + * i = veb.veb.min_val + * while i != -1: # <<<<<<<<<<<<<< + * ii = veb._findsucc(i) + * for n from 0 <= n < max_n: + */ + while (1) { + __pyx_t_5 = (__pyx_cur_scope->__pyx_v_i != -1); + if (!__pyx_t_5) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":73 + * i = veb.veb.min_val + * while i != -1: + * ii = veb._findsucc(i) # <<<<<<<<<<<<<< + * for n from 0 <= n < max_n: + * ngram_start = ngram_starts[n] + */ + __pyx_cur_scope->__pyx_v_ii = ((struct __pyx_vtabstruct_8_cdec_sa_VEB *)__pyx_cur_scope->__pyx_v_veb->__pyx_vtab)->_findsucc(__pyx_cur_scope->__pyx_v_veb, __pyx_cur_scope->__pyx_v_i); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":74 + * while i != -1: + * ii = veb._findsucc(i) + * for n from 0 <= n < max_n: # <<<<<<<<<<<<<< + * ngram_start = ngram_starts[n] + * iii = i + */ + __pyx_t_2 = __pyx_cur_scope->__pyx_v_max_n; + for (__pyx_cur_scope->__pyx_v_n = 0; __pyx_cur_scope->__pyx_v_n < __pyx_t_2; __pyx_cur_scope->__pyx_v_n++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":75 + * ii = veb._findsucc(i) + * for n from 0 <= n < max_n: + * ngram_start = ngram_starts[n] # <<<<<<<<<<<<<< + * iii = i + * rs = ngram_start.arr[iii] + */ + __pyx_t_1 = __Pyx_GetItemInt_List(((PyObject *)__pyx_cur_scope->__pyx_v_ngram_starts), __pyx_cur_scope->__pyx_v_n, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8_cdec_sa_IntList))))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram_start)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram_start)); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_ngram_start = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":76 + * for n from 0 <= n < max_n: + * ngram_start = ngram_starts[n] + * iii = i # <<<<<<<<<<<<<< + * rs = ngram_start.arr[iii] + * while (ii==-1 or iii < ii) and rs != 0: + */ + __pyx_cur_scope->__pyx_v_iii = __pyx_cur_scope->__pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":77 + * ngram_start = ngram_starts[n] + * iii = i + * rs = ngram_start.arr[iii] # <<<<<<<<<<<<<< + * while (ii==-1 or iii < ii) and rs != 0: + * j = self.sa.sa.arr[rs] + */ + __pyx_cur_scope->__pyx_v_rs = (__pyx_cur_scope->__pyx_v_ngram_start->arr[__pyx_cur_scope->__pyx_v_iii]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":78 + * iii = i + * rs = ngram_start.arr[iii] + * while (ii==-1 or iii < ii) and rs != 0: # <<<<<<<<<<<<<< + * j = self.sa.sa.arr[rs] + * valid = 1 + */ + while (1) { + __pyx_t_5 = (__pyx_cur_scope->__pyx_v_ii == -1); + if (!__pyx_t_5) { + __pyx_t_7 = (__pyx_cur_scope->__pyx_v_iii < __pyx_cur_scope->__pyx_v_ii); + __pyx_t_8 = __pyx_t_7; + } else { + __pyx_t_8 = __pyx_t_5; + } + if (__pyx_t_8) { + __pyx_t_5 = (__pyx_cur_scope->__pyx_v_rs != 0); + __pyx_t_7 = __pyx_t_5; + } else { + __pyx_t_7 = __pyx_t_8; + } + if (!__pyx_t_7) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":79 + * rs = ngram_start.arr[iii] + * while (ii==-1 or iii < ii) and rs != 0: + * j = self.sa.sa.arr[rs] # <<<<<<<<<<<<<< + * valid = 1 + * for k from 0 <= k < n+1: + */ + __pyx_cur_scope->__pyx_v_j = (__pyx_cur_scope->__pyx_v_self->sa->sa->arr[__pyx_cur_scope->__pyx_v_rs]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":80 + * while (ii==-1 or iii < ii) and rs != 0: + * j = self.sa.sa.arr[rs] + * valid = 1 # <<<<<<<<<<<<<< + * for k from 0 <= k < n+1: + * if self.sa.darray.data.arr[j+k] < 2: + */ + __pyx_cur_scope->__pyx_v_valid = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":81 + * j = self.sa.sa.arr[rs] + * valid = 1 + * for k from 0 <= k < n+1: # <<<<<<<<<<<<<< + * if self.sa.darray.data.arr[j+k] < 2: + * valid = 0 + */ + __pyx_t_9 = (__pyx_cur_scope->__pyx_v_n + 1); + for (__pyx_cur_scope->__pyx_v_k = 0; __pyx_cur_scope->__pyx_v_k < __pyx_t_9; __pyx_cur_scope->__pyx_v_k++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":82 + * valid = 1 + * for k from 0 <= k < n+1: + * if self.sa.darray.data.arr[j+k] < 2: # <<<<<<<<<<<<<< + * valid = 0 + * if valid: + */ + __pyx_t_7 = ((__pyx_cur_scope->__pyx_v_self->sa->darray->data->arr[(__pyx_cur_scope->__pyx_v_j + __pyx_cur_scope->__pyx_v_k)]) < 2); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":83 + * for k from 0 <= k < n+1: + * if self.sa.darray.data.arr[j+k] < 2: + * valid = 0 # <<<<<<<<<<<<<< + * if valid: + * ngram = tuple([self.sa.darray.data.arr[j+k] for k in range(n+1)]) + */ + __pyx_cur_scope->__pyx_v_valid = 0; + goto __pyx_L22; + } + __pyx_L22:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":84 + * if self.sa.darray.data.arr[j+k] < 2: + * valid = 0 + * if valid: # <<<<<<<<<<<<<< + * ngram = tuple([self.sa.darray.data.arr[j+k] for k in range(n+1)]) + * yield i, n+1, ngram + */ + if (__pyx_cur_scope->__pyx_v_valid) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":85 + * valid = 0 + * if valid: + * ngram = tuple([self.sa.darray.data.arr[j+k] for k in range(n+1)]) # <<<<<<<<<<<<<< + * yield i, n+1, ngram + * iii = iii + 1 + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = (__pyx_cur_scope->__pyx_v_n + 1); + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_9; __pyx_t_6+=1) { + __pyx_cur_scope->__pyx_v_k = __pyx_t_6; + __pyx_t_3 = PyInt_FromLong((__pyx_cur_scope->__pyx_v_self->sa->darray->data->arr[(__pyx_cur_scope->__pyx_v_j + __pyx_cur_scope->__pyx_v_k)])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (unlikely(PyList_Append(__pyx_t_1, (PyObject*)__pyx_t_3))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __pyx_t_3 = ((PyObject *)PyList_AsTuple(__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_cur_scope->__pyx_v_ngram = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":86 + * if valid: + * ngram = tuple([self.sa.darray.data.arr[j+k] for k in range(n+1)]) + * yield i, n+1, ngram # <<<<<<<<<<<<<< + * iii = iii + 1 + * rs = ngram_start.arr[iii] + */ + __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyInt_FromLong((__pyx_cur_scope->__pyx_v_n + 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram)); + PyTuple_SET_ITEM(__pyx_t_10, 2, ((PyObject *)__pyx_cur_scope->__pyx_v_ngram)); + __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram)); + __pyx_t_3 = 0; + __pyx_t_1 = 0; + __pyx_r = ((PyObject *)__pyx_t_10); + __pyx_t_10 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L26_resume_from_yield:; + __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L23; + } + __pyx_L23:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":87 + * ngram = tuple([self.sa.darray.data.arr[j+k] for k in range(n+1)]) + * yield i, n+1, ngram + * iii = iii + 1 # <<<<<<<<<<<<<< + * rs = ngram_start.arr[iii] + * i = ii + */ + __pyx_cur_scope->__pyx_v_iii = (__pyx_cur_scope->__pyx_v_iii + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":88 + * yield i, n+1, ngram + * iii = iii + 1 + * rs = ngram_start.arr[iii] # <<<<<<<<<<<<<< + * i = ii + */ + __pyx_cur_scope->__pyx_v_rs = (__pyx_cur_scope->__pyx_v_ngram_start->arr[__pyx_cur_scope->__pyx_v_iii]); + } + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":89 + * iii = iii + 1 + * rs = ngram_start.arr[iii] + * i = ii # <<<<<<<<<<<<<< + */ + __pyx_cur_scope->__pyx_v_i = __pyx_cur_scope->__pyx_v_ii; + } + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("compute_stats", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_8Alphabet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_8Alphabet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; + __pyx_r = __pyx_pf_8_cdec_sa_8Alphabet___cinit__(((struct __pyx_obj_8_cdec_sa_Alphabet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":12 + * cdef dict id2sym + * + * def __cinit__(self): # <<<<<<<<<<<<<< + * self.terminals = StringMap() + * self.nonterminals = StringMap() + */ + +static int __pyx_pf_8_cdec_sa_8Alphabet___cinit__(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":13 + * + * def __cinit__(self): + * self.terminals = StringMap() # <<<<<<<<<<<<<< + * self.nonterminals = StringMap() + * self.id2sym = {} + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_StringMap)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->terminals); + __Pyx_DECREF(((PyObject *)__pyx_v_self->terminals)); + __pyx_v_self->terminals = ((struct __pyx_obj_8_cdec_sa_StringMap *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":14 + * def __cinit__(self): + * self.terminals = StringMap() + * self.nonterminals = StringMap() # <<<<<<<<<<<<<< + * self.id2sym = {} + * self.first_nonterminal = -1 + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_StringMap)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->nonterminals); + __Pyx_DECREF(((PyObject *)__pyx_v_self->nonterminals)); + __pyx_v_self->nonterminals = ((struct __pyx_obj_8_cdec_sa_StringMap *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":15 + * self.terminals = StringMap() + * self.nonterminals = StringMap() + * self.id2sym = {} # <<<<<<<<<<<<<< + * self.first_nonterminal = -1 + * + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_GOTREF(__pyx_v_self->id2sym); + __Pyx_DECREF(((PyObject *)__pyx_v_self->id2sym)); + __pyx_v_self->id2sym = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":16 + * self.nonterminals = StringMap() + * self.id2sym = {} + * self.first_nonterminal = -1 # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->first_nonterminal = -1; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec_sa.Alphabet.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_8_cdec_sa_8Alphabet_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_8_cdec_sa_8Alphabet_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_8_cdec_sa_8Alphabet_2__dealloc__(((struct __pyx_obj_8_cdec_sa_Alphabet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":18 + * self.first_nonterminal = -1 + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * pass + * + */ + +static void __pyx_pf_8_cdec_sa_8Alphabet_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":21 + * pass + * + * cdef int isvar(self, int sym): # <<<<<<<<<<<<<< + * return sym < 0 + * + */ + +static int __pyx_f_8_cdec_sa_8Alphabet_isvar(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, int __pyx_v_sym) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("isvar", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":22 + * + * cdef int isvar(self, int sym): + * return sym < 0 # <<<<<<<<<<<<<< + * + * cdef int isword(self, int sym): + */ + __pyx_r = (__pyx_v_sym < 0); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":24 + * return sym < 0 + * + * cdef int isword(self, int sym): # <<<<<<<<<<<<<< + * return sym >= 0 + * + */ + +static int __pyx_f_8_cdec_sa_8Alphabet_isword(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, int __pyx_v_sym) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("isword", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":25 + * + * cdef int isword(self, int sym): + * return sym >= 0 # <<<<<<<<<<<<<< + * + * cdef int getindex(self, int sym): + */ + __pyx_r = (__pyx_v_sym >= 0); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":27 + * return sym >= 0 + * + * cdef int getindex(self, int sym): # <<<<<<<<<<<<<< + * return -sym & INDEX_MASK + * + */ + +static int __pyx_f_8_cdec_sa_8Alphabet_getindex(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, int __pyx_v_sym) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getindex", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":28 + * + * cdef int getindex(self, int sym): + * return -sym & INDEX_MASK # <<<<<<<<<<<<<< + * + * cdef int setindex(self, int sym, int ind): + */ + __pyx_r = ((-__pyx_v_sym) & __pyx_v_8_cdec_sa_INDEX_MASK); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":30 + * return -sym & INDEX_MASK + * + * cdef int setindex(self, int sym, int ind): # <<<<<<<<<<<<<< + * return -(-sym & ~INDEX_MASK | ind) + * + */ + +static int __pyx_f_8_cdec_sa_8Alphabet_setindex(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, int __pyx_v_sym, int __pyx_v_ind) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("setindex", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":31 + * + * cdef int setindex(self, int sym, int ind): + * return -(-sym & ~INDEX_MASK | ind) # <<<<<<<<<<<<<< + * + * cdef int clearindex(self, int sym): + */ + __pyx_r = (-(((-__pyx_v_sym) & (~__pyx_v_8_cdec_sa_INDEX_MASK)) | __pyx_v_ind)); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":33 + * return -(-sym & ~INDEX_MASK | ind) + * + * cdef int clearindex(self, int sym): # <<<<<<<<<<<<<< + * return -(-sym& ~INDEX_MASK) + * + */ + +static int __pyx_f_8_cdec_sa_8Alphabet_clearindex(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, int __pyx_v_sym) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("clearindex", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":34 + * + * cdef int clearindex(self, int sym): + * return -(-sym& ~INDEX_MASK) # <<<<<<<<<<<<<< + * + * cdef int match(self, int sym1, int sym2): + */ + __pyx_r = (-((-__pyx_v_sym) & (~__pyx_v_8_cdec_sa_INDEX_MASK))); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":36 + * return -(-sym& ~INDEX_MASK) + * + * cdef int match(self, int sym1, int sym2): # <<<<<<<<<<<<<< + * return self.clearindex(sym1) == self.clearindex(sym2); + * + */ + +static int __pyx_f_8_cdec_sa_8Alphabet_match(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, int __pyx_v_sym1, int __pyx_v_sym2) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("match", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":37 + * + * cdef int match(self, int sym1, int sym2): + * return self.clearindex(sym1) == self.clearindex(sym2); # <<<<<<<<<<<<<< + * + * cdef char* tocat(self, int sym): + */ + __pyx_r = (((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->clearindex(__pyx_v_self, __pyx_v_sym1) == ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->clearindex(__pyx_v_self, __pyx_v_sym2)); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":39 + * return self.clearindex(sym1) == self.clearindex(sym2); + * + * cdef char* tocat(self, int sym): # <<<<<<<<<<<<<< + * return self.nonterminals.word((-sym >> INDEX_SHIFT)-1) + * + */ + +static char *__pyx_f_8_cdec_sa_8Alphabet_tocat(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, int __pyx_v_sym) { + char *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("tocat", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":40 + * + * cdef char* tocat(self, int sym): + * return self.nonterminals.word((-sym >> INDEX_SHIFT)-1) # <<<<<<<<<<<<<< + * + * cdef int fromcat(self, char *s): + */ + __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_StringMap *)__pyx_v_self->nonterminals->__pyx_vtab)->word(__pyx_v_self->nonterminals, (((-__pyx_v_sym) >> __pyx_v_8_cdec_sa_INDEX_SHIFT) - 1)); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":42 + * return self.nonterminals.word((-sym >> INDEX_SHIFT)-1) + * + * cdef int fromcat(self, char *s): # <<<<<<<<<<<<<< + * cdef int i + * i = self.nonterminals.index(s) + */ + +static int __pyx_f_8_cdec_sa_8Alphabet_fromcat(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, char *__pyx_v_s) { + int __pyx_v_i; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("fromcat", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":44 + * cdef int fromcat(self, char *s): + * cdef int i + * i = self.nonterminals.index(s) # <<<<<<<<<<<<<< + * if self.first_nonterminal == -1: + * self.first_nonterminal = i + */ + __pyx_v_i = ((struct __pyx_vtabstruct_8_cdec_sa_StringMap *)__pyx_v_self->nonterminals->__pyx_vtab)->index(__pyx_v_self->nonterminals, __pyx_v_s); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":45 + * cdef int i + * i = self.nonterminals.index(s) + * if self.first_nonterminal == -1: # <<<<<<<<<<<<<< + * self.first_nonterminal = i + * if i > self.last_nonterminal: + */ + __pyx_t_1 = (__pyx_v_self->first_nonterminal == -1); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":46 + * i = self.nonterminals.index(s) + * if self.first_nonterminal == -1: + * self.first_nonterminal = i # <<<<<<<<<<<<<< + * if i > self.last_nonterminal: + * self.last_nonterminal = i + */ + __pyx_v_self->first_nonterminal = __pyx_v_i; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":47 + * if self.first_nonterminal == -1: + * self.first_nonterminal = i + * if i > self.last_nonterminal: # <<<<<<<<<<<<<< + * self.last_nonterminal = i + * return -(i+1 << INDEX_SHIFT) + */ + __pyx_t_1 = (__pyx_v_i > __pyx_v_self->last_nonterminal); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":48 + * self.first_nonterminal = i + * if i > self.last_nonterminal: + * self.last_nonterminal = i # <<<<<<<<<<<<<< + * return -(i+1 << INDEX_SHIFT) + * + */ + __pyx_v_self->last_nonterminal = __pyx_v_i; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":49 + * if i > self.last_nonterminal: + * self.last_nonterminal = i + * return -(i+1 << INDEX_SHIFT) # <<<<<<<<<<<<<< + * + * cdef char* tostring(self, int sym): + */ + __pyx_r = (-((__pyx_v_i + 1) << __pyx_v_8_cdec_sa_INDEX_SHIFT)); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":51 + * return -(i+1 << INDEX_SHIFT) + * + * cdef char* tostring(self, int sym): # <<<<<<<<<<<<<< + * cdef int ind + * if self.isvar(sym): + */ + +static char *__pyx_f_8_cdec_sa_8Alphabet_tostring(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, int __pyx_v_sym) { + int __pyx_v_ind; + char *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + char *__pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("tostring", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":53 + * cdef char* tostring(self, int sym): + * cdef int ind + * if self.isvar(sym): # <<<<<<<<<<<<<< + * if sym in self.id2sym: + * return self.id2sym[sym] + */ + __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->isvar(__pyx_v_self, __pyx_v_sym); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":54 + * cdef int ind + * if self.isvar(sym): + * if sym in self.id2sym: # <<<<<<<<<<<<<< + * return self.id2sym[sym] + * + */ + __pyx_t_2 = PyInt_FromLong(__pyx_v_sym); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (unlikely(((PyObject *)__pyx_v_self->id2sym) == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[10]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_3 = ((PyDict_Contains(((PyObject *)__pyx_v_self->id2sym), __pyx_t_2))); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":55 + * if self.isvar(sym): + * if sym in self.id2sym: + * return self.id2sym[sym] # <<<<<<<<<<<<<< + * + * ind = self.getindex(sym) + */ + __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_self->id2sym), __pyx_v_sym, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyBytes_AsString(__pyx_t_2); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_4; + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":57 + * return self.id2sym[sym] + * + * ind = self.getindex(sym) # <<<<<<<<<<<<<< + * if ind > 0: + * self.id2sym[sym] = "[%s,%d]" % (self.tocat(sym), ind) + */ + __pyx_v_ind = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->getindex(__pyx_v_self, __pyx_v_sym); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":58 + * + * ind = self.getindex(sym) + * if ind > 0: # <<<<<<<<<<<<<< + * self.id2sym[sym] = "[%s,%d]" % (self.tocat(sym), ind) + * else: + */ + __pyx_t_3 = (__pyx_v_ind > 0); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":59 + * ind = self.getindex(sym) + * if ind > 0: + * self.id2sym[sym] = "[%s,%d]" % (self.tocat(sym), ind) # <<<<<<<<<<<<<< + * else: + * self.id2sym[sym] = "[%s]" % self.tocat(sym) + */ + __pyx_t_2 = PyBytes_FromString(((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->tocat(__pyx_v_self, __pyx_v_sym)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_5 = PyInt_FromLong(__pyx_v_ind); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_2 = 0; + __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_61), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + if (__Pyx_SetItemInt(((PyObject *)__pyx_v_self->id2sym), __pyx_v_sym, ((PyObject *)__pyx_t_5), sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":61 + * self.id2sym[sym] = "[%s,%d]" % (self.tocat(sym), ind) + * else: + * self.id2sym[sym] = "[%s]" % self.tocat(sym) # <<<<<<<<<<<<<< + * return self.id2sym[sym] + * + */ + __pyx_t_5 = PyBytes_FromString(((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->tocat(__pyx_v_self, __pyx_v_sym)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_62), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + if (__Pyx_SetItemInt(((PyObject *)__pyx_v_self->id2sym), __pyx_v_sym, ((PyObject *)__pyx_t_6), sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":62 + * else: + * self.id2sym[sym] = "[%s]" % self.tocat(sym) + * return self.id2sym[sym] # <<<<<<<<<<<<<< + * + * else: + */ + __pyx_t_6 = __Pyx_GetItemInt(((PyObject *)__pyx_v_self->id2sym), __pyx_v_sym, sizeof(int), PyInt_FromLong); if (!__pyx_t_6) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = PyBytes_AsString(__pyx_t_6); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_r = __pyx_t_4; + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":65 + * + * else: + * return self.terminals.word(sym) # <<<<<<<<<<<<<< + * + * cdef int fromstring(self, char *s, bint terminal): + */ + __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_StringMap *)__pyx_v_self->terminals->__pyx_vtab)->word(__pyx_v_self->terminals, __pyx_v_sym); + goto __pyx_L0; + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_WriteUnraisable("_cdec_sa.Alphabet.tostring", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":67 + * return self.terminals.word(sym) + * + * cdef int fromstring(self, char *s, bint terminal): # <<<<<<<<<<<<<< + * """Warning: this method is allowed to alter s.""" + * cdef char *comma + */ + +static int __pyx_f_8_cdec_sa_8Alphabet_fromstring(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, char *__pyx_v_s, int __pyx_v_terminal) { + char *__pyx_v_comma; + int __pyx_v_n; + char *__pyx_v_sep; + PyObject *__pyx_v_s1 = NULL; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + char *__pyx_t_8; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("fromstring", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":71 + * cdef char *comma + * cdef int n + * n = strlen(s) # <<<<<<<<<<<<<< + * cdef char *sep + * sep = strstr(s,"_SEP_") + */ + __pyx_v_n = strlen(__pyx_v_s); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":73 + * n = strlen(s) + * cdef char *sep + * sep = strstr(s,"_SEP_") # <<<<<<<<<<<<<< + * if n >= 3 and s[0] == c'[' and s[n-1] == c']' and sep == NULL: + * if terminal: + */ + __pyx_v_sep = strstr(__pyx_v_s, __pyx_k___SEP_); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":74 + * cdef char *sep + * sep = strstr(s,"_SEP_") + * if n >= 3 and s[0] == c'[' and s[n-1] == c']' and sep == NULL: # <<<<<<<<<<<<<< + * if terminal: + * s1 = "\\"+s + */ + __pyx_t_1 = (__pyx_v_n >= 3); + if (__pyx_t_1) { + __pyx_t_2 = ((__pyx_v_s[0]) == '['); + if (__pyx_t_2) { + __pyx_t_3 = ((__pyx_v_s[(__pyx_v_n - 1)]) == ']'); + if (__pyx_t_3) { + __pyx_t_4 = (__pyx_v_sep == NULL); + __pyx_t_5 = __pyx_t_4; + } else { + __pyx_t_5 = __pyx_t_3; + } + __pyx_t_3 = __pyx_t_5; + } else { + __pyx_t_3 = __pyx_t_2; + } + __pyx_t_2 = __pyx_t_3; + } else { + __pyx_t_2 = __pyx_t_1; + } + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":75 + * sep = strstr(s,"_SEP_") + * if n >= 3 and s[0] == c'[' and s[n-1] == c']' and sep == NULL: + * if terminal: # <<<<<<<<<<<<<< + * s1 = "\\"+s + * return self.terminals.index(s1) + */ + if (__pyx_v_terminal) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":76 + * if n >= 3 and s[0] == c'[' and s[n-1] == c']' and sep == NULL: + * if terminal: + * s1 = "\\"+s # <<<<<<<<<<<<<< + * return self.terminals.index(s1) + * s[n-1] = c'\0' + */ + __pyx_t_6 = PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + __pyx_t_7 = PyNumber_Add(((PyObject *)__pyx_kp_s_63), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __pyx_v_s1 = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":77 + * if terminal: + * s1 = "\\"+s + * return self.terminals.index(s1) # <<<<<<<<<<<<<< + * s[n-1] = c'\0' + * s = s + 1 + */ + __pyx_t_8 = PyBytes_AsString(__pyx_v_s1); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_StringMap *)__pyx_v_self->terminals->__pyx_vtab)->index(__pyx_v_self->terminals, __pyx_t_8); + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":78 + * s1 = "\\"+s + * return self.terminals.index(s1) + * s[n-1] = c'\0' # <<<<<<<<<<<<<< + * s = s + 1 + * comma = strrchr(s, c',') + */ + (__pyx_v_s[(__pyx_v_n - 1)]) = '\x00'; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":79 + * return self.terminals.index(s1) + * s[n-1] = c'\0' + * s = s + 1 # <<<<<<<<<<<<<< + * comma = strrchr(s, c',') + * if comma != NULL: + */ + __pyx_v_s = (__pyx_v_s + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":80 + * s[n-1] = c'\0' + * s = s + 1 + * comma = strrchr(s, c',') # <<<<<<<<<<<<<< + * if comma != NULL: + * comma[0] = c'\0' + */ + __pyx_v_comma = strrchr(__pyx_v_s, ','); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":81 + * s = s + 1 + * comma = strrchr(s, c',') + * if comma != NULL: # <<<<<<<<<<<<<< + * comma[0] = c'\0' + * return self.setindex(self.fromcat(s), strtol(comma+1, NULL, 10)) + */ + __pyx_t_2 = (__pyx_v_comma != NULL); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":82 + * comma = strrchr(s, c',') + * if comma != NULL: + * comma[0] = c'\0' # <<<<<<<<<<<<<< + * return self.setindex(self.fromcat(s), strtol(comma+1, NULL, 10)) + * else: + */ + (__pyx_v_comma[0]) = '\x00'; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":83 + * if comma != NULL: + * comma[0] = c'\0' + * return self.setindex(self.fromcat(s), strtol(comma+1, NULL, 10)) # <<<<<<<<<<<<<< + * else: + * return self.fromcat(s) + */ + __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->setindex(__pyx_v_self, ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->fromcat(__pyx_v_self, __pyx_v_s), strtol((__pyx_v_comma + 1), NULL, 10)); + goto __pyx_L0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":85 + * return self.setindex(self.fromcat(s), strtol(comma+1, NULL, 10)) + * else: + * return self.fromcat(s) # <<<<<<<<<<<<<< + * else: + * return self.terminals.index(s) + */ + __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->fromcat(__pyx_v_self, __pyx_v_s); + goto __pyx_L0; + } + __pyx_L5:; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":87 + * return self.fromcat(s) + * else: + * return self.terminals.index(s) # <<<<<<<<<<<<<< + * + * cdef Alphabet ALPHABET = Alphabet() + */ + __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_StringMap *)__pyx_v_self->terminals->__pyx_vtab)->index(__pyx_v_self->terminals, __pyx_v_s); + goto __pyx_L0; + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_WriteUnraisable("_cdec_sa.Alphabet.fromstring", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_s1); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_8Alphabet_9terminals_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_8Alphabet_9terminals_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_8Alphabet_9terminals___get__(((struct __pyx_obj_8_cdec_sa_Alphabet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":8 + * + * cdef class Alphabet: + * cdef readonly StringMap terminals, nonterminals # <<<<<<<<<<<<<< + * cdef int first_nonterminal, last_nonterminal + * cdef dict id2sym + */ + +static PyObject *__pyx_pf_8_cdec_sa_8Alphabet_9terminals___get__(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->terminals)); + __pyx_r = ((PyObject *)__pyx_v_self->terminals); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_8Alphabet_12nonterminals_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_8Alphabet_12nonterminals_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_8Alphabet_12nonterminals___get__(((struct __pyx_obj_8_cdec_sa_Alphabet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_8_cdec_sa_8Alphabet_12nonterminals___get__(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->nonterminals)); + __pyx_r = ((PyObject *)__pyx_v_self->nonterminals); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_3sym_tostring(PyObject *__pyx_self, PyObject *__pyx_arg_sym); /*proto*/ +static PyMethodDef __pyx_mdef_8_cdec_sa_3sym_tostring = {__Pyx_NAMESTR("sym_tostring"), (PyCFunction)__pyx_pw_8_cdec_sa_3sym_tostring, METH_O, __Pyx_DOCSTR(0)}; +static PyObject *__pyx_pw_8_cdec_sa_3sym_tostring(PyObject *__pyx_self, PyObject *__pyx_arg_sym) { + int __pyx_v_sym; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("sym_tostring (wrapper)", 0); + __pyx_self = __pyx_self; + assert(__pyx_arg_sym); { + __pyx_v_sym = __Pyx_PyInt_AsInt(__pyx_arg_sym); if (unlikely((__pyx_v_sym == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.sym_tostring", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_2sym_tostring(__pyx_self, ((int)__pyx_v_sym)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":91 + * cdef Alphabet ALPHABET = Alphabet() + * + * def sym_tostring(int sym): # <<<<<<<<<<<<<< + * return ALPHABET.tostring(sym) + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_2sym_tostring(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_sym) { + 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("sym_tostring", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":92 + * + * def sym_tostring(int sym): + * return ALPHABET.tostring(sym) # <<<<<<<<<<<<<< + * + * def sym_fromstring(bytes string, bint terminal): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->tostring(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_sym)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 92; __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_sa.sym_tostring", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_5sym_fromstring(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_8_cdec_sa_5sym_fromstring = {__Pyx_NAMESTR("sym_fromstring"), (PyCFunction)__pyx_pw_8_cdec_sa_5sym_fromstring, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}; +static PyObject *__pyx_pw_8_cdec_sa_5sym_fromstring(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_string = 0; + int __pyx_v_terminal; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__string,&__pyx_n_s__terminal,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("sym_fromstring (wrapper)", 0); + __pyx_self = __pyx_self; + { + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__string); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__terminal); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("sym_fromstring", 1, 2, 2, 1); {__pyx_filename = __pyx_f[10]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sym_fromstring") < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_string = ((PyObject*)values[0]); + __pyx_v_terminal = __Pyx_PyObject_IsTrue(values[1]); if (unlikely((__pyx_v_terminal == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("sym_fromstring", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[10]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.sym_fromstring", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_string), (&PyBytes_Type), 1, "string", 1))) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_8_cdec_sa_4sym_fromstring(__pyx_self, __pyx_v_string, __pyx_v_terminal); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":94 + * return ALPHABET.tostring(sym) + * + * def sym_fromstring(bytes string, bint terminal): # <<<<<<<<<<<<<< + * return ALPHABET.fromstring(string, terminal) + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_4sym_fromstring(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_string, int __pyx_v_terminal) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + char *__pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("sym_fromstring", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":95 + * + * def sym_fromstring(bytes string, bint terminal): + * return ALPHABET.fromstring(string, terminal) # <<<<<<<<<<<<<< + * + * def sym_isvar(int sym): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_AsString(((PyObject *)__pyx_v_string)); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong(((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->fromstring(__pyx_v_8_cdec_sa_ALPHABET, __pyx_t_1, __pyx_v_terminal)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_cdec_sa.sym_fromstring", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_7sym_isvar(PyObject *__pyx_self, PyObject *__pyx_arg_sym); /*proto*/ +static PyMethodDef __pyx_mdef_8_cdec_sa_7sym_isvar = {__Pyx_NAMESTR("sym_isvar"), (PyCFunction)__pyx_pw_8_cdec_sa_7sym_isvar, METH_O, __Pyx_DOCSTR(0)}; +static PyObject *__pyx_pw_8_cdec_sa_7sym_isvar(PyObject *__pyx_self, PyObject *__pyx_arg_sym) { + int __pyx_v_sym; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("sym_isvar (wrapper)", 0); + __pyx_self = __pyx_self; + assert(__pyx_arg_sym); { + __pyx_v_sym = __Pyx_PyInt_AsInt(__pyx_arg_sym); if (unlikely((__pyx_v_sym == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.sym_isvar", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_6sym_isvar(__pyx_self, ((int)__pyx_v_sym)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":97 + * return ALPHABET.fromstring(string, terminal) + * + * def sym_isvar(int sym): # <<<<<<<<<<<<<< + * return ALPHABET.isvar(sym) + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_6sym_isvar(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_sym) { + 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("sym_isvar", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":98 + * + * def sym_isvar(int sym): + * return ALPHABET.isvar(sym) # <<<<<<<<<<<<<< + * + * cdef int sym_setindex(int sym, int id): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong(((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->isvar(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_sym)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_cdec_sa.sym_isvar", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":100 + * return ALPHABET.isvar(sym) + * + * cdef int sym_setindex(int sym, int id): # <<<<<<<<<<<<<< + * return ALPHABET.setindex(sym, id) + */ + +static int __pyx_f_8_cdec_sa_sym_setindex(int __pyx_v_sym, int __pyx_v_id) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("sym_setindex", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":101 + * + * cdef int sym_setindex(int sym, int id): + * return ALPHABET.setindex(sym, id) # <<<<<<<<<<<<<< + */ + __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->setindex(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_sym, __pyx_v_id); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_6Phrase_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_6Phrase_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_words = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__words,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__words); + 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 8; __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_words = values[0]; + } + 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[7]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.Phrase.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_6Phrase___cinit__(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self), __pyx_v_words); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":8 + * cdef int n, *varpos, n_vars + * + * def __cinit__(self, words): # <<<<<<<<<<<<<< + * cdef int i, j, n, n_vars + * n_vars = 0 + */ + +static int __pyx_pf_8_cdec_sa_6Phrase___cinit__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_words) { + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_n; + int __pyx_v_n_vars; + int __pyx_r; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":10 + * def __cinit__(self, words): + * cdef int i, j, n, n_vars + * n_vars = 0 # <<<<<<<<<<<<<< + * n = len(words) + * self.syms = malloc(n*sizeof(int)) + */ + __pyx_v_n_vars = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":11 + * cdef int i, j, n, n_vars + * n_vars = 0 + * n = len(words) # <<<<<<<<<<<<<< + * self.syms = malloc(n*sizeof(int)) + * for i from 0 <= i < n: + */ + __pyx_t_1 = PyObject_Length(__pyx_v_words); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_n = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":12 + * n_vars = 0 + * n = len(words) + * self.syms = malloc(n*sizeof(int)) # <<<<<<<<<<<<<< + * for i from 0 <= i < n: + * self.syms[i] = words[i] + */ + __pyx_v_self->syms = ((int *)malloc((__pyx_v_n * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":13 + * n = len(words) + * self.syms = malloc(n*sizeof(int)) + * for i from 0 <= i < n: # <<<<<<<<<<<<<< + * self.syms[i] = words[i] + * if ALPHABET.isvar(self.syms[i]): + */ + __pyx_t_2 = __pyx_v_n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":14 + * self.syms = malloc(n*sizeof(int)) + * for i from 0 <= i < n: + * self.syms[i] = words[i] # <<<<<<<<<<<<<< + * if ALPHABET.isvar(self.syms[i]): + * n_vars += 1 + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_words, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + (__pyx_v_self->syms[__pyx_v_i]) = __pyx_t_4; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":15 + * for i from 0 <= i < n: + * self.syms[i] = words[i] + * if ALPHABET.isvar(self.syms[i]): # <<<<<<<<<<<<<< + * n_vars += 1 + * self.n = n + */ + __pyx_t_4 = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->isvar(__pyx_v_8_cdec_sa_ALPHABET, (__pyx_v_self->syms[__pyx_v_i])); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":16 + * self.syms[i] = words[i] + * if ALPHABET.isvar(self.syms[i]): + * n_vars += 1 # <<<<<<<<<<<<<< + * self.n = n + * self.n_vars = n_vars + */ + __pyx_v_n_vars = (__pyx_v_n_vars + 1); + goto __pyx_L5; + } + __pyx_L5:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":17 + * if ALPHABET.isvar(self.syms[i]): + * n_vars += 1 + * self.n = n # <<<<<<<<<<<<<< + * self.n_vars = n_vars + * self.varpos = malloc(n_vars*sizeof(int)) + */ + __pyx_v_self->n = __pyx_v_n; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":18 + * n_vars += 1 + * self.n = n + * self.n_vars = n_vars # <<<<<<<<<<<<<< + * self.varpos = malloc(n_vars*sizeof(int)) + * j = 0 + */ + __pyx_v_self->n_vars = __pyx_v_n_vars; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":19 + * self.n = n + * self.n_vars = n_vars + * self.varpos = malloc(n_vars*sizeof(int)) # <<<<<<<<<<<<<< + * j = 0 + * for i from 0 <= i < n: + */ + __pyx_v_self->varpos = ((int *)malloc((__pyx_v_n_vars * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":20 + * self.n_vars = n_vars + * self.varpos = malloc(n_vars*sizeof(int)) + * j = 0 # <<<<<<<<<<<<<< + * for i from 0 <= i < n: + * if ALPHABET.isvar(self.syms[i]): + */ + __pyx_v_j = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":21 + * self.varpos = malloc(n_vars*sizeof(int)) + * j = 0 + * for i from 0 <= i < n: # <<<<<<<<<<<<<< + * if ALPHABET.isvar(self.syms[i]): + * self.varpos[j] = i + */ + __pyx_t_2 = __pyx_v_n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":22 + * j = 0 + * for i from 0 <= i < n: + * if ALPHABET.isvar(self.syms[i]): # <<<<<<<<<<<<<< + * self.varpos[j] = i + * j = j + 1 + */ + __pyx_t_4 = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->isvar(__pyx_v_8_cdec_sa_ALPHABET, (__pyx_v_self->syms[__pyx_v_i])); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":23 + * for i from 0 <= i < n: + * if ALPHABET.isvar(self.syms[i]): + * self.varpos[j] = i # <<<<<<<<<<<<<< + * j = j + 1 + * + */ + (__pyx_v_self->varpos[__pyx_v_j]) = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":24 + * if ALPHABET.isvar(self.syms[i]): + * self.varpos[j] = i + * j = j + 1 # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_j = (__pyx_v_j + 1); + goto __pyx_L8; + } + __pyx_L8:; + } + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.Phrase.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_8_cdec_sa_6Phrase_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_8_cdec_sa_6Phrase_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_8_cdec_sa_6Phrase_2__dealloc__(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":26 + * j = j + 1 + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * free(self.syms) + * free(self.varpos) + */ + +static void __pyx_pf_8_cdec_sa_6Phrase_2__dealloc__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":27 + * + * def __dealloc__(self): + * free(self.syms) # <<<<<<<<<<<<<< + * free(self.varpos) + * + */ + free(__pyx_v_self->syms); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":28 + * def __dealloc__(self): + * free(self.syms) + * free(self.varpos) # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + free(__pyx_v_self->varpos); + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_5__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_5__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_4__str__(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":30 + * free(self.varpos) + * + * def __str__(self): # <<<<<<<<<<<<<< + * strs = [] + * cdef int i, s + */ + +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_4__str__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self) { + PyObject *__pyx_v_strs = NULL; + int __pyx_v_i; + int __pyx_v_s; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__str__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":31 + * + * def __str__(self): + * strs = [] # <<<<<<<<<<<<<< + * cdef int i, s + * for i from 0 <= i < self.n: + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_strs = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":33 + * strs = [] + * cdef int i, s + * for i from 0 <= i < self.n: # <<<<<<<<<<<<<< + * s = self.syms[i] + * strs.append(ALPHABET.tostring(s)) + */ + __pyx_t_2 = __pyx_v_self->n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":34 + * cdef int i, s + * for i from 0 <= i < self.n: + * s = self.syms[i] # <<<<<<<<<<<<<< + * strs.append(ALPHABET.tostring(s)) + * return " ".join(strs) + */ + __pyx_v_s = (__pyx_v_self->syms[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":35 + * for i from 0 <= i < self.n: + * s = self.syms[i] + * strs.append(ALPHABET.tostring(s)) # <<<<<<<<<<<<<< + * return " ".join(strs) + * + */ + __pyx_t_1 = PyBytes_FromString(((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->tostring(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_s)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_3 = PyList_Append(__pyx_v_strs, ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":36 + * s = self.syms[i] + * strs.append(ALPHABET.tostring(s)) + * return " ".join(strs) # <<<<<<<<<<<<<< + * + * def handle(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_64), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(((PyObject *)__pyx_v_strs)); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_strs)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_strs)); + __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 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_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_cdec_sa.Phrase.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_strs); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_7handle(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_8_cdec_sa_6Phrase_6handle[] = "return a hashable representation that normalizes the ordering\n of the nonterminal indices"; +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_7handle(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("handle (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_6handle(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":38 + * return " ".join(strs) + * + * def handle(self): # <<<<<<<<<<<<<< + * """return a hashable representation that normalizes the ordering + * of the nonterminal indices""" + */ + +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_6handle(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self) { + PyObject *__pyx_v_norm = NULL; + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_s; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("handle", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":41 + * """return a hashable representation that normalizes the ordering + * of the nonterminal indices""" + * norm = [] # <<<<<<<<<<<<<< + * cdef int i, j, s + * i = 1 + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_norm = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":43 + * norm = [] + * cdef int i, j, s + * i = 1 # <<<<<<<<<<<<<< + * j = 0 + * for j from 0 <= j < self.n: + */ + __pyx_v_i = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":44 + * cdef int i, j, s + * i = 1 + * j = 0 # <<<<<<<<<<<<<< + * for j from 0 <= j < self.n: + * s = self.syms[j] + */ + __pyx_v_j = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":45 + * i = 1 + * j = 0 + * for j from 0 <= j < self.n: # <<<<<<<<<<<<<< + * s = self.syms[j] + * if ALPHABET.isvar(s): + */ + __pyx_t_2 = __pyx_v_self->n; + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_2; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":46 + * j = 0 + * for j from 0 <= j < self.n: + * s = self.syms[j] # <<<<<<<<<<<<<< + * if ALPHABET.isvar(s): + * s = ALPHABET.setindex(s,i) + */ + __pyx_v_s = (__pyx_v_self->syms[__pyx_v_j]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":47 + * for j from 0 <= j < self.n: + * s = self.syms[j] + * if ALPHABET.isvar(s): # <<<<<<<<<<<<<< + * s = ALPHABET.setindex(s,i) + * i = i + 1 + */ + __pyx_t_3 = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->isvar(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_s); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":48 + * s = self.syms[j] + * if ALPHABET.isvar(s): + * s = ALPHABET.setindex(s,i) # <<<<<<<<<<<<<< + * i = i + 1 + * norm.append(s) + */ + __pyx_v_s = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->setindex(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_s, __pyx_v_i); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":49 + * if ALPHABET.isvar(s): + * s = ALPHABET.setindex(s,i) + * i = i + 1 # <<<<<<<<<<<<<< + * norm.append(s) + * return tuple(norm) + */ + __pyx_v_i = (__pyx_v_i + 1); + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":50 + * s = ALPHABET.setindex(s,i) + * i = i + 1 + * norm.append(s) # <<<<<<<<<<<<<< + * return tuple(norm) + * + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_s); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyList_Append(__pyx_v_norm, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":51 + * i = i + 1 + * norm.append(s) + * return tuple(norm) # <<<<<<<<<<<<<< + * + * def strhandle(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = ((PyObject *)PyList_AsTuple(__pyx_v_norm)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 51; __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_sa.Phrase.handle", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_norm); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_9strhandle(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_9strhandle(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("strhandle (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_8strhandle(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":53 + * return tuple(norm) + * + * def strhandle(self): # <<<<<<<<<<<<<< + * strs = [] + * norm = [] + */ + +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_8strhandle(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self) { + CYTHON_UNUSED PyObject *__pyx_v_strs = NULL; + PyObject *__pyx_v_norm = NULL; + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_s; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("strhandle", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":54 + * + * def strhandle(self): + * strs = [] # <<<<<<<<<<<<<< + * norm = [] + * cdef int i, j, s + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_strs = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":55 + * def strhandle(self): + * strs = [] + * norm = [] # <<<<<<<<<<<<<< + * cdef int i, j, s + * i = 1 + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_norm = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":57 + * norm = [] + * cdef int i, j, s + * i = 1 # <<<<<<<<<<<<<< + * j = 0 + * for j from 0 <= j < self.n: + */ + __pyx_v_i = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":58 + * cdef int i, j, s + * i = 1 + * j = 0 # <<<<<<<<<<<<<< + * for j from 0 <= j < self.n: + * s = self.syms[j] + */ + __pyx_v_j = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":59 + * i = 1 + * j = 0 + * for j from 0 <= j < self.n: # <<<<<<<<<<<<<< + * s = self.syms[j] + * if ALPHABET.isvar(s): + */ + __pyx_t_2 = __pyx_v_self->n; + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_2; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":60 + * j = 0 + * for j from 0 <= j < self.n: + * s = self.syms[j] # <<<<<<<<<<<<<< + * if ALPHABET.isvar(s): + * s = ALPHABET.setindex(s,i) + */ + __pyx_v_s = (__pyx_v_self->syms[__pyx_v_j]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":61 + * for j from 0 <= j < self.n: + * s = self.syms[j] + * if ALPHABET.isvar(s): # <<<<<<<<<<<<<< + * s = ALPHABET.setindex(s,i) + * i = i + 1 + */ + __pyx_t_3 = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->isvar(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_s); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":62 + * s = self.syms[j] + * if ALPHABET.isvar(s): + * s = ALPHABET.setindex(s,i) # <<<<<<<<<<<<<< + * i = i + 1 + * norm.append(ALPHABET.tostring(s)) + */ + __pyx_v_s = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->setindex(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_s, __pyx_v_i); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":63 + * if ALPHABET.isvar(s): + * s = ALPHABET.setindex(s,i) + * i = i + 1 # <<<<<<<<<<<<<< + * norm.append(ALPHABET.tostring(s)) + * return " ".join(norm) + */ + __pyx_v_i = (__pyx_v_i + 1); + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":64 + * s = ALPHABET.setindex(s,i) + * i = i + 1 + * norm.append(ALPHABET.tostring(s)) # <<<<<<<<<<<<<< + * return " ".join(norm) + * + */ + __pyx_t_1 = PyBytes_FromString(((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->tostring(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_s)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_4 = PyList_Append(__pyx_v_norm, ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":65 + * i = i + 1 + * norm.append(ALPHABET.tostring(s)) + * return " ".join(norm) # <<<<<<<<<<<<<< + * + * def arity(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_64), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(((PyObject *)__pyx_v_norm)); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_norm)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_norm)); + __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_r = __pyx_t_6; + __pyx_t_6 = 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_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_cdec_sa.Phrase.strhandle", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_strs); + __Pyx_XDECREF(__pyx_v_norm); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_11arity(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_11arity(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("arity (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_10arity(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":67 + * return " ".join(norm) + * + * def arity(self): # <<<<<<<<<<<<<< + * return self.n_vars + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_10arity(struct __pyx_obj_8_cdec_sa_Phrase *__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("arity", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":68 + * + * def arity(self): + * return self.n_vars # <<<<<<<<<<<<<< + * + * def getvarpos(self, i): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->n_vars); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_cdec_sa.Phrase.arity", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_13getvarpos(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_13getvarpos(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getvarpos (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_12getvarpos(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":70 + * return self.n_vars + * + * def getvarpos(self, i): # <<<<<<<<<<<<<< + * if 0 <= i < self.n_vars: + * return self.varpos[i] + */ + +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_12getvarpos(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + Py_ssize_t __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("getvarpos", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":71 + * + * def getvarpos(self, i): + * if 0 <= i < self.n_vars: # <<<<<<<<<<<<<< + * return self.varpos[i] + * else: + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_int_0, __pyx_v_i, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_PyObject_IsTrue(__pyx_t_1)) { + __Pyx_DECREF(__pyx_t_1); + __pyx_t_2 = PyInt_FromLong(__pyx_v_self->n_vars); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_RichCompare(__pyx_v_i, __pyx_t_2, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":72 + * def getvarpos(self, i): + * if 0 <= i < self.n_vars: + * return self.varpos[i] # <<<<<<<<<<<<<< + * else: + * raise IndexError + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyInt_FromLong((__pyx_v_self->varpos[__pyx_t_4])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":74 + * return self.varpos[i] + * else: + * raise IndexError # <<<<<<<<<<<<<< + * + * def getvar(self, i): + */ + __Pyx_Raise(__pyx_builtin_IndexError, 0, 0, 0); + {__pyx_filename = __pyx_f[7]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; + + __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_sa.Phrase.getvarpos", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_15getvar(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_15getvar(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getvar (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_14getvar(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":76 + * raise IndexError + * + * def getvar(self, i): # <<<<<<<<<<<<<< + * if 0 <= i < self.n_vars: + * return self.syms[self.varpos[i]] + */ + +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_14getvar(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + Py_ssize_t __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("getvar", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":77 + * + * def getvar(self, i): + * if 0 <= i < self.n_vars: # <<<<<<<<<<<<<< + * return self.syms[self.varpos[i]] + * else: + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_int_0, __pyx_v_i, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_PyObject_IsTrue(__pyx_t_1)) { + __Pyx_DECREF(__pyx_t_1); + __pyx_t_2 = PyInt_FromLong(__pyx_v_self->n_vars); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_RichCompare(__pyx_v_i, __pyx_t_2, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":78 + * def getvar(self, i): + * if 0 <= i < self.n_vars: + * return self.syms[self.varpos[i]] # <<<<<<<<<<<<<< + * else: + * raise IndexError + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyInt_FromLong((__pyx_v_self->syms[(__pyx_v_self->varpos[__pyx_t_4])])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":80 + * return self.syms[self.varpos[i]] + * else: + * raise IndexError # <<<<<<<<<<<<<< + * + * cdef int chunkpos(self, int k): + */ + __Pyx_Raise(__pyx_builtin_IndexError, 0, 0, 0); + {__pyx_filename = __pyx_f[7]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; + + __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_sa.Phrase.getvar", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":82 + * raise IndexError + * + * cdef int chunkpos(self, int k): # <<<<<<<<<<<<<< + * if k == 0: + * return 0 + */ + +static int __pyx_f_8_cdec_sa_6Phrase_chunkpos(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, int __pyx_v_k) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("chunkpos", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":83 + * + * cdef int chunkpos(self, int k): + * if k == 0: # <<<<<<<<<<<<<< + * return 0 + * else: + */ + __pyx_t_1 = (__pyx_v_k == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":84 + * cdef int chunkpos(self, int k): + * if k == 0: + * return 0 # <<<<<<<<<<<<<< + * else: + * return self.varpos[k-1]+1 + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":86 + * return 0 + * else: + * return self.varpos[k-1]+1 # <<<<<<<<<<<<<< + * + * cdef int chunklen(self, int k): + */ + __pyx_r = ((__pyx_v_self->varpos[(__pyx_v_k - 1)]) + 1); + goto __pyx_L0; + } + __pyx_L3:; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":88 + * return self.varpos[k-1]+1 + * + * cdef int chunklen(self, int k): # <<<<<<<<<<<<<< + * if self.n_vars == 0: + * return self.n + */ + +static int __pyx_f_8_cdec_sa_6Phrase_chunklen(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, int __pyx_v_k) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("chunklen", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":89 + * + * cdef int chunklen(self, int k): + * if self.n_vars == 0: # <<<<<<<<<<<<<< + * return self.n + * elif k == 0: + */ + __pyx_t_1 = (__pyx_v_self->n_vars == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":90 + * cdef int chunklen(self, int k): + * if self.n_vars == 0: + * return self.n # <<<<<<<<<<<<<< + * elif k == 0: + * return self.varpos[0] + */ + __pyx_r = __pyx_v_self->n; + goto __pyx_L0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":91 + * if self.n_vars == 0: + * return self.n + * elif k == 0: # <<<<<<<<<<<<<< + * return self.varpos[0] + * elif k == self.n_vars: + */ + __pyx_t_1 = (__pyx_v_k == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":92 + * return self.n + * elif k == 0: + * return self.varpos[0] # <<<<<<<<<<<<<< + * elif k == self.n_vars: + * return self.n-self.varpos[k-1]-1 + */ + __pyx_r = (__pyx_v_self->varpos[0]); + goto __pyx_L0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":93 + * elif k == 0: + * return self.varpos[0] + * elif k == self.n_vars: # <<<<<<<<<<<<<< + * return self.n-self.varpos[k-1]-1 + * else: + */ + __pyx_t_1 = (__pyx_v_k == __pyx_v_self->n_vars); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":94 + * return self.varpos[0] + * elif k == self.n_vars: + * return self.n-self.varpos[k-1]-1 # <<<<<<<<<<<<<< + * else: + * return self.varpos[k]-self.varpos[k-1]-1 + */ + __pyx_r = ((__pyx_v_self->n - (__pyx_v_self->varpos[(__pyx_v_k - 1)])) - 1); + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":96 + * return self.n-self.varpos[k-1]-1 + * else: + * return self.varpos[k]-self.varpos[k-1]-1 # <<<<<<<<<<<<<< + * + * def clen(self, k): + */ + __pyx_r = (((__pyx_v_self->varpos[__pyx_v_k]) - (__pyx_v_self->varpos[(__pyx_v_k - 1)])) - 1); + goto __pyx_L0; + } + __pyx_L3:; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_17clen(PyObject *__pyx_v_self, PyObject *__pyx_v_k); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_17clen(PyObject *__pyx_v_self, PyObject *__pyx_v_k) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("clen (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_16clen(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self), ((PyObject *)__pyx_v_k)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":98 + * return self.varpos[k]-self.varpos[k-1]-1 + * + * def clen(self, k): # <<<<<<<<<<<<<< + * return self.chunklen(k) + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_16clen(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_k) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("clen", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":99 + * + * def clen(self, k): + * return self.chunklen(k) # <<<<<<<<<<<<<< + * + * def getchunk(self, ci): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_k); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong(((struct __pyx_vtabstruct_8_cdec_sa_Phrase *)__pyx_v_self->__pyx_vtab)->chunklen(__pyx_v_self, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_cdec_sa.Phrase.clen", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_19getchunk(PyObject *__pyx_v_self, PyObject *__pyx_v_ci); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_19getchunk(PyObject *__pyx_v_self, PyObject *__pyx_v_ci) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getchunk (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_18getchunk(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self), ((PyObject *)__pyx_v_ci)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":101 + * return self.chunklen(k) + * + * def getchunk(self, ci): # <<<<<<<<<<<<<< + * cdef int start, stop + * start = self.chunkpos(ci) + */ + +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_18getchunk(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_ci) { + int __pyx_v_start; + int __pyx_v_stop; + PyObject *__pyx_v_chunk = NULL; + int __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("getchunk", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":103 + * def getchunk(self, ci): + * cdef int start, stop + * start = self.chunkpos(ci) # <<<<<<<<<<<<<< + * stop = start+self.chunklen(ci) + * chunk = [] + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_ci); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_start = ((struct __pyx_vtabstruct_8_cdec_sa_Phrase *)__pyx_v_self->__pyx_vtab)->chunkpos(__pyx_v_self, __pyx_t_1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":104 + * cdef int start, stop + * start = self.chunkpos(ci) + * stop = start+self.chunklen(ci) # <<<<<<<<<<<<<< + * chunk = [] + * for i from start <= i < stop: + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_ci); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_stop = (__pyx_v_start + ((struct __pyx_vtabstruct_8_cdec_sa_Phrase *)__pyx_v_self->__pyx_vtab)->chunklen(__pyx_v_self, __pyx_t_1)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":105 + * start = self.chunkpos(ci) + * stop = start+self.chunklen(ci) + * chunk = [] # <<<<<<<<<<<<<< + * for i from start <= i < stop: + * chunk.append(self.syms[i]) + */ + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_chunk = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":106 + * stop = start+self.chunklen(ci) + * chunk = [] + * for i from start <= i < stop: # <<<<<<<<<<<<<< + * chunk.append(self.syms[i]) + * return chunk + */ + __pyx_t_1 = __pyx_v_stop; + for (__pyx_v_i = __pyx_v_start; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":107 + * chunk = [] + * for i from start <= i < stop: + * chunk.append(self.syms[i]) # <<<<<<<<<<<<<< + * return chunk + * + */ + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->syms[__pyx_v_i])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyList_Append(__pyx_v_chunk, __pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":108 + * for i from start <= i < stop: + * chunk.append(self.syms[i]) + * return chunk # <<<<<<<<<<<<<< + * + * def __cmp__(self, other): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_chunk)); + __pyx_r = ((PyObject *)__pyx_v_chunk); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec_sa.Phrase.getchunk", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_chunk); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +#if PY_MAJOR_VERSION < 3 +static int __pyx_pw_8_cdec_sa_6Phrase_21__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static int __pyx_pw_8_cdec_sa_6Phrase_21__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cmp__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_20__cmp__(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self), ((PyObject *)__pyx_v_other)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +#endif /*!(#if PY_MAJOR_VERSION < 3)*/ + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":110 + * return chunk + * + * def __cmp__(self, other): # <<<<<<<<<<<<<< + * cdef Phrase otherp + * cdef int i + */ + +#if PY_MAJOR_VERSION < 3 +static int __pyx_pf_8_cdec_sa_6Phrase_20__cmp__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_other) { + struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_otherp = 0; + int __pyx_v_i; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cmp__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":113 + * cdef Phrase otherp + * cdef int i + * otherp = other # <<<<<<<<<<<<<< + * for i from 0 <= i < min(self.n, otherp.n): + * if self.syms[i] < otherp.syms[i]: + */ + if (!(likely(((__pyx_v_other) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_other, __pyx_ptype_8_cdec_sa_Phrase))))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_other); + __pyx_v_otherp = ((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_other); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":114 + * cdef int i + * otherp = other + * for i from 0 <= i < min(self.n, otherp.n): # <<<<<<<<<<<<<< + * if self.syms[i] < otherp.syms[i]: + * return -1 + */ + __pyx_t_1 = __pyx_v_otherp->n; + __pyx_t_2 = __pyx_v_self->n; + if ((__pyx_t_1 < __pyx_t_2)) { + __pyx_t_3 = __pyx_t_1; + } else { + __pyx_t_3 = __pyx_t_2; + } + __pyx_t_1 = __pyx_t_3; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":115 + * otherp = other + * for i from 0 <= i < min(self.n, otherp.n): + * if self.syms[i] < otherp.syms[i]: # <<<<<<<<<<<<<< + * return -1 + * elif self.syms[i] > otherp.syms[i]: + */ + __pyx_t_4 = ((__pyx_v_self->syms[__pyx_v_i]) < (__pyx_v_otherp->syms[__pyx_v_i])); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":116 + * for i from 0 <= i < min(self.n, otherp.n): + * if self.syms[i] < otherp.syms[i]: + * return -1 # <<<<<<<<<<<<<< + * elif self.syms[i] > otherp.syms[i]: + * return 1 + */ + __pyx_r = -1; + goto __pyx_L0; + goto __pyx_L5; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":117 + * if self.syms[i] < otherp.syms[i]: + * return -1 + * elif self.syms[i] > otherp.syms[i]: # <<<<<<<<<<<<<< + * return 1 + * if self.n < otherp.n: + */ + __pyx_t_4 = ((__pyx_v_self->syms[__pyx_v_i]) > (__pyx_v_otherp->syms[__pyx_v_i])); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":118 + * return -1 + * elif self.syms[i] > otherp.syms[i]: + * return 1 # <<<<<<<<<<<<<< + * if self.n < otherp.n: + * return -1 + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":119 + * elif self.syms[i] > otherp.syms[i]: + * return 1 + * if self.n < otherp.n: # <<<<<<<<<<<<<< + * return -1 + * elif self.n > otherp.n: + */ + __pyx_t_4 = (__pyx_v_self->n < __pyx_v_otherp->n); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":120 + * return 1 + * if self.n < otherp.n: + * return -1 # <<<<<<<<<<<<<< + * elif self.n > otherp.n: + * return 1 + */ + __pyx_r = -1; + goto __pyx_L0; + goto __pyx_L6; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":121 + * if self.n < otherp.n: + * return -1 + * elif self.n > otherp.n: # <<<<<<<<<<<<<< + * return 1 + * else: + */ + __pyx_t_4 = (__pyx_v_self->n > __pyx_v_otherp->n); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":122 + * return -1 + * elif self.n > otherp.n: + * return 1 # <<<<<<<<<<<<<< + * else: + * return 0 + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":124 + * return 1 + * else: + * return 0 # <<<<<<<<<<<<<< + * + * def __hash__(self): + */ + __pyx_r = 0; + goto __pyx_L0; + } + __pyx_L6:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec_sa.Phrase.__cmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_otherp); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +#endif /*!(#if PY_MAJOR_VERSION < 3)*/ + +/* Python wrapper */ +static Py_hash_t __pyx_pw_8_cdec_sa_6Phrase_23__hash__(PyObject *__pyx_v_self); /*proto*/ +static Py_hash_t __pyx_pw_8_cdec_sa_6Phrase_23__hash__(PyObject *__pyx_v_self) { + Py_hash_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__hash__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_22__hash__(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":126 + * return 0 + * + * def __hash__(self): # <<<<<<<<<<<<<< + * cdef int i + * cdef unsigned h + */ + +static Py_hash_t __pyx_pf_8_cdec_sa_6Phrase_22__hash__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self) { + int __pyx_v_i; + unsigned int __pyx_v_h; + Py_hash_t __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + __Pyx_RefNannySetupContext("__hash__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":129 + * cdef int i + * cdef unsigned h + * h = 0 # <<<<<<<<<<<<<< + * for i from 0 <= i < self.n: + * if self.syms[i] > 0: + */ + __pyx_v_h = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":130 + * cdef unsigned h + * h = 0 + * for i from 0 <= i < self.n: # <<<<<<<<<<<<<< + * if self.syms[i] > 0: + * h = (h << 1) + self.syms[i] + */ + __pyx_t_1 = __pyx_v_self->n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":131 + * h = 0 + * for i from 0 <= i < self.n: + * if self.syms[i] > 0: # <<<<<<<<<<<<<< + * h = (h << 1) + self.syms[i] + * else: + */ + __pyx_t_2 = ((__pyx_v_self->syms[__pyx_v_i]) > 0); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":132 + * for i from 0 <= i < self.n: + * if self.syms[i] > 0: + * h = (h << 1) + self.syms[i] # <<<<<<<<<<<<<< + * else: + * h = (h << 1) + -self.syms[i] + */ + __pyx_v_h = ((__pyx_v_h << 1) + (__pyx_v_self->syms[__pyx_v_i])); + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":134 + * h = (h << 1) + self.syms[i] + * else: + * h = (h << 1) + -self.syms[i] # <<<<<<<<<<<<<< + * return h + * + */ + __pyx_v_h = ((__pyx_v_h << 1) + (-(__pyx_v_self->syms[__pyx_v_i]))); + } + __pyx_L5:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":135 + * else: + * h = (h << 1) + -self.syms[i] + * return h # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + __pyx_r = __pyx_v_h; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_8_cdec_sa_6Phrase_25__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_8_cdec_sa_6Phrase_25__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_24__len__(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":137 + * return h + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.n + * + */ + +static Py_ssize_t __pyx_pf_8_cdec_sa_6Phrase_24__len__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":138 + * + * def __len__(self): + * return self.n # <<<<<<<<<<<<<< + * + * def __getitem__(self, i): + */ + __pyx_r = __pyx_v_self->n; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_27__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_27__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_26__getitem__(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":140 + * return self.n + * + * def __getitem__(self, i): # <<<<<<<<<<<<<< + * return self.syms[i] + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_26__getitem__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__getitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":141 + * + * def __getitem__(self, i): + * return self.syms[i] # <<<<<<<<<<<<<< + * + * def __iter__(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->syms[__pyx_t_1])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_cdec_sa.Phrase.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_29__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_29__iter__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_28__iter__(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":143 + * return self.syms[i] + * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef int i + * l = [] + */ + +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_28__iter__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self) { + int __pyx_v_i; + PyObject *__pyx_v_l = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__iter__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":145 + * def __iter__(self): + * cdef int i + * l = [] # <<<<<<<<<<<<<< + * for i from 0 <= i < self.n: + * l.append(self.syms[i]) + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_l = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":146 + * cdef int i + * l = [] + * for i from 0 <= i < self.n: # <<<<<<<<<<<<<< + * l.append(self.syms[i]) + * return iter(l) + */ + __pyx_t_2 = __pyx_v_self->n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":147 + * l = [] + * for i from 0 <= i < self.n: + * l.append(self.syms[i]) # <<<<<<<<<<<<<< + * return iter(l) + * + */ + __pyx_t_1 = PyInt_FromLong((__pyx_v_self->syms[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyList_Append(__pyx_v_l, __pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":148 + * for i from 0 <= i < self.n: + * l.append(self.syms[i]) + * return iter(l) # <<<<<<<<<<<<<< + * + * def subst(self, start, children): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_l)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_cdec_sa.Phrase.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_l); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_31subst(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_6Phrase_31subst(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_start = 0; + PyObject *__pyx_v_children = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__children,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("subst (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__children); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("subst", 1, 2, 2, 1); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "subst") < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_start = values[0]; + __pyx_v_children = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("subst", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.Phrase.subst", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_30subst(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self), __pyx_v_start, __pyx_v_children); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":150 + * return iter(l) + * + * def subst(self, start, children): # <<<<<<<<<<<<<< + * cdef int i + * for i from 0 <= i < self.n: + */ + +static PyObject *__pyx_pf_8_cdec_sa_6Phrase_30subst(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_children) { + int __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + long __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("subst", 0); + __Pyx_INCREF(__pyx_v_start); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":152 + * def subst(self, start, children): + * cdef int i + * for i from 0 <= i < self.n: # <<<<<<<<<<<<<< + * if ALPHABET.isvar(self.syms[i]): + * start = start + children[ALPHABET.getindex(self.syms[i])-1] + */ + __pyx_t_1 = __pyx_v_self->n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":153 + * cdef int i + * for i from 0 <= i < self.n: + * if ALPHABET.isvar(self.syms[i]): # <<<<<<<<<<<<<< + * start = start + children[ALPHABET.getindex(self.syms[i])-1] + * else: + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->isvar(__pyx_v_8_cdec_sa_ALPHABET, (__pyx_v_self->syms[__pyx_v_i])); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":154 + * for i from 0 <= i < self.n: + * if ALPHABET.isvar(self.syms[i]): + * start = start + children[ALPHABET.getindex(self.syms[i])-1] # <<<<<<<<<<<<<< + * else: + * start = start + (self.syms[i],) + */ + __pyx_t_3 = (((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->getindex(__pyx_v_8_cdec_sa_ALPHABET, (__pyx_v_self->syms[__pyx_v_i])) - 1); + __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_children, __pyx_t_3, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyNumber_Add(__pyx_v_start, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_v_start); + __pyx_v_start = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":156 + * start = start + children[ALPHABET.getindex(self.syms[i])-1] + * else: + * start = start + (self.syms[i],) # <<<<<<<<<<<<<< + * return start + * + */ + __pyx_t_5 = PyInt_FromLong((__pyx_v_self->syms[__pyx_v_i])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Add(__pyx_v_start, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_v_start); + __pyx_v_start = __pyx_t_5; + __pyx_t_5 = 0; + } + __pyx_L5:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":157 + * else: + * start = start + (self.syms[i],) + * return start # <<<<<<<<<<<<<< + * + * cdef class Rule: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_start); + __pyx_r = __pyx_v_start; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_cdec_sa.Phrase.subst", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_start); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_4Rule_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_4Rule_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_lhs; + struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_f = 0; + struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_e = 0; + PyObject *__pyx_v_scores = 0; + PyObject *__pyx_v_word_alignments = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__lhs,&__pyx_n_s__f,&__pyx_n_s__e,&__pyx_n_s__scores,&__pyx_n_s__word_alignments,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[5] = {0,0,0,0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":167 + * + * def __cinit__(self, int lhs, Phrase f, Phrase e, + * scores=None, word_alignments=None): # <<<<<<<<<<<<<< + * cdef int i, n + * cdef char *rest + */ + values[3] = ((PyObject *)Py_None); + values[4] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__lhs); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__f); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 1); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__e); + if (likely(values[2])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 2); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 3: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__scores); + if (value) { values[3] = value; kw_args--; } + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__word_alignments); + if (value) { values[4] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_lhs = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_lhs == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_f = ((struct __pyx_obj_8_cdec_sa_Phrase *)values[1]); + __pyx_v_e = ((struct __pyx_obj_8_cdec_sa_Phrase *)values[2]); + __pyx_v_scores = values[3]; + __pyx_v_word_alignments = values[4]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.Rule.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_f), __pyx_ptype_8_cdec_sa_Phrase, 1, "f", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_e), __pyx_ptype_8_cdec_sa_Phrase, 1, "e", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_8_cdec_sa_4Rule___cinit__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self), __pyx_v_lhs, __pyx_v_f, __pyx_v_e, __pyx_v_scores, __pyx_v_word_alignments); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":166 + * cdef public word_alignments + * + * def __cinit__(self, int lhs, Phrase f, Phrase e, # <<<<<<<<<<<<<< + * scores=None, word_alignments=None): + * cdef int i, n + */ + +static int __pyx_pf_8_cdec_sa_4Rule___cinit__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, int __pyx_v_lhs, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_f, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_e, PyObject *__pyx_v_scores, PyObject *__pyx_v_word_alignments) { + int __pyx_v_i; + int __pyx_v_n; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + int __pyx_t_5; + float __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":171 + * cdef char *rest + * + * if not ALPHABET.isvar(lhs): # <<<<<<<<<<<<<< + * raise Exception('Invalid LHS symbol: %d' % lhs) + * + */ + __pyx_t_1 = (!((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->isvar(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_lhs)); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":172 + * + * if not ALPHABET.isvar(lhs): + * raise Exception('Invalid LHS symbol: %d' % lhs) # <<<<<<<<<<<<<< + * + * self.lhs = lhs + */ + __pyx_t_2 = PyInt_FromLong(__pyx_v_lhs); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_65), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + {__pyx_filename = __pyx_f[7]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":174 + * raise Exception('Invalid LHS symbol: %d' % lhs) + * + * self.lhs = lhs # <<<<<<<<<<<<<< + * self.f = f + * self.e = e + */ + __pyx_v_self->lhs = __pyx_v_lhs; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":175 + * + * self.lhs = lhs + * self.f = f # <<<<<<<<<<<<<< + * self.e = e + * + */ + __Pyx_INCREF(((PyObject *)__pyx_v_f)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_f)); + __Pyx_GOTREF(__pyx_v_self->f); + __Pyx_DECREF(((PyObject *)__pyx_v_self->f)); + __pyx_v_self->f = __pyx_v_f; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":176 + * self.lhs = lhs + * self.f = f + * self.e = e # <<<<<<<<<<<<<< + * + * self.word_alignments = word_alignments + */ + __Pyx_INCREF(((PyObject *)__pyx_v_e)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_e)); + __Pyx_GOTREF(__pyx_v_self->e); + __Pyx_DECREF(((PyObject *)__pyx_v_self->e)); + __pyx_v_self->e = __pyx_v_e; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":178 + * self.e = e + * + * self.word_alignments = word_alignments # <<<<<<<<<<<<<< + * if scores is None: + * self.cscores = NULL + */ + __Pyx_INCREF(__pyx_v_word_alignments); + __Pyx_GIVEREF(__pyx_v_word_alignments); + __Pyx_GOTREF(__pyx_v_self->word_alignments); + __Pyx_DECREF(__pyx_v_self->word_alignments); + __pyx_v_self->word_alignments = __pyx_v_word_alignments; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":179 + * + * self.word_alignments = word_alignments + * if scores is None: # <<<<<<<<<<<<<< + * self.cscores = NULL + * self.n_scores = 0 + */ + __pyx_t_1 = (__pyx_v_scores == Py_None); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":180 + * self.word_alignments = word_alignments + * if scores is None: + * self.cscores = NULL # <<<<<<<<<<<<<< + * self.n_scores = 0 + * else: + */ + __pyx_v_self->cscores = NULL; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":181 + * if scores is None: + * self.cscores = NULL + * self.n_scores = 0 # <<<<<<<<<<<<<< + * else: + * n = len(scores) + */ + __pyx_v_self->n_scores = 0; + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":183 + * self.n_scores = 0 + * else: + * n = len(scores) # <<<<<<<<<<<<<< + * self.cscores = malloc(n*sizeof(float)) + * self.n_scores = n + */ + __pyx_t_4 = PyObject_Length(__pyx_v_scores); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_n = __pyx_t_4; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":184 + * else: + * n = len(scores) + * self.cscores = malloc(n*sizeof(float)) # <<<<<<<<<<<<<< + * self.n_scores = n + * for i from 0 <= i < n: + */ + __pyx_v_self->cscores = ((float *)malloc((__pyx_v_n * (sizeof(float))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":185 + * n = len(scores) + * self.cscores = malloc(n*sizeof(float)) + * self.n_scores = n # <<<<<<<<<<<<<< + * for i from 0 <= i < n: + * self.cscores[i] = scores[i] + */ + __pyx_v_self->n_scores = __pyx_v_n; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":186 + * self.cscores = malloc(n*sizeof(float)) + * self.n_scores = n + * for i from 0 <= i < n: # <<<<<<<<<<<<<< + * self.cscores[i] = scores[i] + * + */ + __pyx_t_5 = __pyx_v_n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_5; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":187 + * self.n_scores = n + * for i from 0 <= i < n: + * self.cscores[i] = scores[i] # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_scores, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = __pyx_PyFloat_AsFloat(__pyx_t_3); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + (__pyx_v_self->cscores[__pyx_v_i]) = __pyx_t_6; + } + } + __pyx_L4:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.Rule.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_8_cdec_sa_4Rule_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_8_cdec_sa_4Rule_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_8_cdec_sa_4Rule_2__dealloc__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":189 + * self.cscores[i] = scores[i] + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * if self.cscores != NULL: + * free(self.cscores) + */ + +static void __pyx_pf_8_cdec_sa_4Rule_2__dealloc__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self) { + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":190 + * + * def __dealloc__(self): + * if self.cscores != NULL: # <<<<<<<<<<<<<< + * free(self.cscores) + * + */ + __pyx_t_1 = (__pyx_v_self->cscores != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":191 + * def __dealloc__(self): + * if self.cscores != NULL: + * free(self.cscores) # <<<<<<<<<<<<<< + * + * def __hash__(self): + */ + free(__pyx_v_self->cscores); + goto __pyx_L3; + } + __pyx_L3:; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static Py_hash_t __pyx_pw_8_cdec_sa_4Rule_5__hash__(PyObject *__pyx_v_self); /*proto*/ +static Py_hash_t __pyx_pw_8_cdec_sa_4Rule_5__hash__(PyObject *__pyx_v_self) { + Py_hash_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__hash__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_4Rule_4__hash__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":193 + * free(self.cscores) + * + * def __hash__(self): # <<<<<<<<<<<<<< + * return hash((self.lhs, self.f, self.e)) + * + */ + +static Py_hash_t __pyx_pf_8_cdec_sa_4Rule_4__hash__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self) { + Py_hash_t __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_hash_t __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__hash__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":194 + * + * def __hash__(self): + * return hash((self.lhs, self.f, self.e)) # <<<<<<<<<<<<<< + * + * def __cmp__(self, Rule other): + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->lhs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_self->f)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_self->f)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->f)); + __Pyx_INCREF(((PyObject *)__pyx_v_self->e)); + PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_self->e)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->e)); + __pyx_t_1 = 0; + __pyx_t_3 = PyObject_Hash(((PyObject *)__pyx_t_2)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec_sa.Rule.__hash__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +#if PY_MAJOR_VERSION < 3 +static int __pyx_pw_8_cdec_sa_4Rule_7__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static int __pyx_pw_8_cdec_sa_4Rule_7__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cmp__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_8_cdec_sa_Rule, 1, "other", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_8_cdec_sa_4Rule_6__cmp__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self), ((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_other)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +#endif /*!(#if PY_MAJOR_VERSION < 3)*/ + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":196 + * return hash((self.lhs, self.f, self.e)) + * + * def __cmp__(self, Rule other): # <<<<<<<<<<<<<< + * return cmp((self.lhs, self.f, self.e, self.word_alignments), (other.lhs, other.f, other.e, self.word_alignments)) + * + */ + +#if PY_MAJOR_VERSION < 3 +static int __pyx_pf_8_cdec_sa_4Rule_6__cmp__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_other) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cmp__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":197 + * + * def __cmp__(self, Rule other): + * return cmp((self.lhs, self.f, self.e, self.word_alignments), (other.lhs, other.f, other.e, self.word_alignments)) # <<<<<<<<<<<<<< + * + * def __iadd__(self, Rule other): + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->lhs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_self->f)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_self->f)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->f)); + __Pyx_INCREF(((PyObject *)__pyx_v_self->e)); + PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_self->e)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->e)); + __Pyx_INCREF(__pyx_v_self->word_alignments); + PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_self->word_alignments); + __Pyx_GIVEREF(__pyx_v_self->word_alignments); + __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromLong(__pyx_v_other->lhs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_other->f)); + PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_other->f)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_other->f)); + __Pyx_INCREF(((PyObject *)__pyx_v_other->e)); + PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_other->e)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_other->e)); + __Pyx_INCREF(__pyx_v_self->word_alignments); + PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_v_self->word_alignments); + __Pyx_GIVEREF(__pyx_v_self->word_alignments); + __pyx_t_1 = 0; + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_t_3)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_cmp, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_4; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.Rule.__cmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +#endif /*!(#if PY_MAJOR_VERSION < 3)*/ + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_4Rule_9__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_4Rule_9__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iadd__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_8_cdec_sa_Rule, 1, "other", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_8_cdec_sa_4Rule_8__iadd__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self), ((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_other)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":199 + * return cmp((self.lhs, self.f, self.e, self.word_alignments), (other.lhs, other.f, other.e, self.word_alignments)) + * + * def __iadd__(self, Rule other): # <<<<<<<<<<<<<< + * if self.n_scores != other.n_scores: + * raise ValueError + */ + +static PyObject *__pyx_pf_8_cdec_sa_4Rule_8__iadd__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_other) { + long __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__iadd__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":200 + * + * def __iadd__(self, Rule other): + * if self.n_scores != other.n_scores: # <<<<<<<<<<<<<< + * raise ValueError + * for i from 0 <= i < self.n_scores: + */ + __pyx_t_1 = (__pyx_v_self->n_scores != __pyx_v_other->n_scores); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":201 + * def __iadd__(self, Rule other): + * if self.n_scores != other.n_scores: + * raise ValueError # <<<<<<<<<<<<<< + * for i from 0 <= i < self.n_scores: + * self.cscores[i] = self.cscores[i] + other.cscores[i] + */ + __Pyx_Raise(__pyx_builtin_ValueError, 0, 0, 0); + {__pyx_filename = __pyx_f[7]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":202 + * if self.n_scores != other.n_scores: + * raise ValueError + * for i from 0 <= i < self.n_scores: # <<<<<<<<<<<<<< + * self.cscores[i] = self.cscores[i] + other.cscores[i] + * return self + */ + __pyx_t_2 = __pyx_v_self->n_scores; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":203 + * raise ValueError + * for i from 0 <= i < self.n_scores: + * self.cscores[i] = self.cscores[i] + other.cscores[i] # <<<<<<<<<<<<<< + * return self + * + */ + (__pyx_v_self->cscores[__pyx_v_i]) = ((__pyx_v_self->cscores[__pyx_v_i]) + (__pyx_v_other->cscores[__pyx_v_i])); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":204 + * for i from 0 <= i < self.n_scores: + * self.cscores[i] = self.cscores[i] + other.cscores[i] + * return self # <<<<<<<<<<<<<< + * + * def fmerge(self, Phrase f): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec_sa.Rule.__iadd__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_4Rule_11fmerge(PyObject *__pyx_v_self, PyObject *__pyx_v_f); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_4Rule_11fmerge(PyObject *__pyx_v_self, PyObject *__pyx_v_f) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("fmerge (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_f), __pyx_ptype_8_cdec_sa_Phrase, 1, "f", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_8_cdec_sa_4Rule_10fmerge(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self), ((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_f)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":206 + * return self + * + * def fmerge(self, Phrase f): # <<<<<<<<<<<<<< + * if self.f == f: + * self.f = f + */ + +static PyObject *__pyx_pf_8_cdec_sa_4Rule_10fmerge(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_f) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("fmerge", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":207 + * + * def fmerge(self, Phrase f): + * if self.f == f: # <<<<<<<<<<<<<< + * self.f = f + * + */ + __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_self->f), ((PyObject *)__pyx_v_f), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":208 + * def fmerge(self, Phrase f): + * if self.f == f: + * self.f = f # <<<<<<<<<<<<<< + * + * def arity(self): + */ + __Pyx_INCREF(((PyObject *)__pyx_v_f)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_f)); + __Pyx_GOTREF(__pyx_v_self->f); + __Pyx_DECREF(((PyObject *)__pyx_v_self->f)); + __pyx_v_self->f = __pyx_v_f; + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec_sa.Rule.fmerge", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_4Rule_13arity(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_4Rule_13arity(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("arity (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_4Rule_12arity(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":210 + * self.f = f + * + * def arity(self): # <<<<<<<<<<<<<< + * return self.f.arity() + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_4Rule_12arity(struct __pyx_obj_8_cdec_sa_Rule *__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("arity", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":211 + * + * def arity(self): + * return self.f.arity() # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->f), __pyx_n_s__arity); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 211; __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_sa.Rule.arity", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_4Rule_15__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_4Rule_15__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_4Rule_14__str__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":213 + * return self.f.arity() + * + * def __str__(self): # <<<<<<<<<<<<<< + * scorestrs = [] + * for i from 0 <= i < self.n_scores: + */ + +static PyObject *__pyx_pf_8_cdec_sa_4Rule_14__str__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self) { + PyObject *__pyx_v_scorestrs = NULL; + long __pyx_v_i; + PyObject *__pyx_v_fields = NULL; + PyObject *__pyx_v_alignstr = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + Py_ssize_t __pyx_t_10; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__str__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":214 + * + * def __str__(self): + * scorestrs = [] # <<<<<<<<<<<<<< + * for i from 0 <= i < self.n_scores: + * scorestrs.append(str(self.cscores[i])) + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_scorestrs = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":215 + * def __str__(self): + * scorestrs = [] + * for i from 0 <= i < self.n_scores: # <<<<<<<<<<<<<< + * scorestrs.append(str(self.cscores[i])) + * fields = [ALPHABET.tostring(self.lhs), str(self.f), str(self.e), " ".join(scorestrs)] + */ + __pyx_t_2 = __pyx_v_self->n_scores; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":216 + * scorestrs = [] + * for i from 0 <= i < self.n_scores: + * scorestrs.append(str(self.cscores[i])) # <<<<<<<<<<<<<< + * fields = [ALPHABET.tostring(self.lhs), str(self.f), str(self.e), " ".join(scorestrs)] + * if self.word_alignments is not None: + */ + __pyx_t_1 = PyFloat_FromDouble((__pyx_v_self->cscores[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_4 = PyList_Append(__pyx_v_scorestrs, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":217 + * for i from 0 <= i < self.n_scores: + * scorestrs.append(str(self.cscores[i])) + * fields = [ALPHABET.tostring(self.lhs), str(self.f), str(self.e), " ".join(scorestrs)] # <<<<<<<<<<<<<< + * if self.word_alignments is not None: + * alignstr = [] + */ + __pyx_t_1 = PyBytes_FromString(((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->tostring(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_self->lhs)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(((PyObject *)__pyx_v_self->f)); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->f)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->f)); + __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(((PyObject *)__pyx_v_self->e)); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->e)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->e)); + __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_64), __pyx_n_s__join); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(((PyObject *)__pyx_v_scorestrs)); + PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_scorestrs)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_scorestrs)); + __pyx_t_8 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __pyx_t_7 = PyList_New(4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + PyList_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + PyList_SET_ITEM(__pyx_t_7, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + PyList_SET_ITEM(__pyx_t_7, 2, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + PyList_SET_ITEM(__pyx_t_7, 3, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_1 = 0; + __pyx_t_5 = 0; + __pyx_t_6 = 0; + __pyx_t_8 = 0; + __pyx_v_fields = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":218 + * scorestrs.append(str(self.cscores[i])) + * fields = [ALPHABET.tostring(self.lhs), str(self.f), str(self.e), " ".join(scorestrs)] + * if self.word_alignments is not None: # <<<<<<<<<<<<<< + * alignstr = [] + * for i from 0 <= i < len(self.word_alignments): + */ + __pyx_t_9 = (__pyx_v_self->word_alignments != Py_None); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":219 + * fields = [ALPHABET.tostring(self.lhs), str(self.f), str(self.e), " ".join(scorestrs)] + * if self.word_alignments is not None: + * alignstr = [] # <<<<<<<<<<<<<< + * for i from 0 <= i < len(self.word_alignments): + * alignstr.append("%d-%d" % (self.word_alignments[i]/65536, self.word_alignments[i]%65536)) + */ + __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_v_alignstr = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":220 + * if self.word_alignments is not None: + * alignstr = [] + * for i from 0 <= i < len(self.word_alignments): # <<<<<<<<<<<<<< + * alignstr.append("%d-%d" % (self.word_alignments[i]/65536, self.word_alignments[i]%65536)) + * #for s,t in self.word_alignments: + */ + __pyx_t_7 = __pyx_v_self->word_alignments; + __Pyx_INCREF(__pyx_t_7); + __pyx_t_10 = PyObject_Length(__pyx_t_7); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_10; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":221 + * alignstr = [] + * for i from 0 <= i < len(self.word_alignments): + * alignstr.append("%d-%d" % (self.word_alignments[i]/65536, self.word_alignments[i]%65536)) # <<<<<<<<<<<<<< + * #for s,t in self.word_alignments: + * #alignstr.append("%d-%d" % (s,t)) + */ + __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_self->word_alignments, __pyx_v_i, sizeof(long), PyInt_FromLong); if (!__pyx_t_7) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyNumber_Divide(__pyx_t_7, __pyx_int_65536); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_self->word_alignments, __pyx_v_i, sizeof(long), PyInt_FromLong); if (!__pyx_t_7) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = PyNumber_Remainder(__pyx_t_7, __pyx_int_65536); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + __pyx_t_8 = 0; + __pyx_t_6 = 0; + __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_66), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __pyx_t_4 = PyList_Append(__pyx_v_alignstr, ((PyObject *)__pyx_t_6)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":224 + * #for s,t in self.word_alignments: + * #alignstr.append("%d-%d" % (s,t)) + * fields.append(" ".join(alignstr)) # <<<<<<<<<<<<<< + * + * return " ||| ".join(fields) + */ + __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_64), __pyx_n_s__join); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(((PyObject *)__pyx_v_alignstr)); + PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_alignstr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_alignstr)); + __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __pyx_t_4 = PyList_Append(__pyx_v_fields, __pyx_t_8); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":226 + * fields.append(" ".join(alignstr)) + * + * return " ||| ".join(fields) # <<<<<<<<<<<<<< + * + * property scores: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_67), __pyx_n_s__join); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(((PyObject *)__pyx_v_fields)); + PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_fields)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fields)); + __pyx_t_6 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __pyx_r = __pyx_t_6; + __pyx_t_6 = 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_3); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_cdec_sa.Rule.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_scorestrs); + __Pyx_XDECREF(__pyx_v_fields); + __Pyx_XDECREF(__pyx_v_alignstr); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_4Rule_6scores_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_4Rule_6scores_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_4Rule_6scores___get__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":229 + * + * property scores: + * def __get__(self): # <<<<<<<<<<<<<< + * s = [None]*self.n_scores + * for i from 0 <= i < self.n_scores: + */ + +static PyObject *__pyx_pf_8_cdec_sa_4Rule_6scores___get__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self) { + PyObject *__pyx_v_s = NULL; + long __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":230 + * property scores: + * def __get__(self): + * s = [None]*self.n_scores # <<<<<<<<<<<<<< + * for i from 0 <= i < self.n_scores: + * s[i] = self.cscores[i] + */ + __pyx_t_1 = PyList_New(1 * ((__pyx_v_self->n_scores<0) ? 0:__pyx_v_self->n_scores)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + { Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < __pyx_v_self->n_scores; __pyx_temp++) { + __Pyx_INCREF(Py_None); + PyList_SET_ITEM(__pyx_t_1, __pyx_temp, Py_None); + __Pyx_GIVEREF(Py_None); + } + } + __pyx_v_s = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":231 + * def __get__(self): + * s = [None]*self.n_scores + * for i from 0 <= i < self.n_scores: # <<<<<<<<<<<<<< + * s[i] = self.cscores[i] + * return s + */ + __pyx_t_2 = __pyx_v_self->n_scores; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":232 + * s = [None]*self.n_scores + * for i from 0 <= i < self.n_scores: + * s[i] = self.cscores[i] # <<<<<<<<<<<<<< + * return s + * + */ + __pyx_t_1 = PyFloat_FromDouble((__pyx_v_self->cscores[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_SetItemInt(((PyObject *)__pyx_v_s), __pyx_v_i, __pyx_t_1, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":233 + * for i from 0 <= i < self.n_scores: + * s[i] = self.cscores[i] + * return s # <<<<<<<<<<<<<< + * + * def __set__(self, s): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_s)); + __pyx_r = ((PyObject *)__pyx_v_s); + 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_sa.Rule.scores.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_s); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_4Rule_6scores_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_s); /*proto*/ +static int __pyx_pw_8_cdec_sa_4Rule_6scores_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_s) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_4Rule_6scores_2__set__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self), ((PyObject *)__pyx_v_s)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":235 + * return s + * + * def __set__(self, s): # <<<<<<<<<<<<<< + * if self.cscores != NULL: + * free(self.cscores) + */ + +static int __pyx_pf_8_cdec_sa_4Rule_6scores_2__set__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, PyObject *__pyx_v_s) { + long __pyx_v_i; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + Py_ssize_t __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + float __pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":236 + * + * def __set__(self, s): + * if self.cscores != NULL: # <<<<<<<<<<<<<< + * free(self.cscores) + * self.cscores = malloc(len(s)*sizeof(float)) + */ + __pyx_t_1 = (__pyx_v_self->cscores != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":237 + * def __set__(self, s): + * if self.cscores != NULL: + * free(self.cscores) # <<<<<<<<<<<<<< + * self.cscores = malloc(len(s)*sizeof(float)) + * self.n_scores = len(s) + */ + free(__pyx_v_self->cscores); + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":238 + * if self.cscores != NULL: + * free(self.cscores) + * self.cscores = malloc(len(s)*sizeof(float)) # <<<<<<<<<<<<<< + * self.n_scores = len(s) + * for i from 0 <= i < self.n_scores: + */ + __pyx_t_2 = PyObject_Length(__pyx_v_s); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->cscores = ((float *)malloc((__pyx_t_2 * (sizeof(float))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":239 + * free(self.cscores) + * self.cscores = malloc(len(s)*sizeof(float)) + * self.n_scores = len(s) # <<<<<<<<<<<<<< + * for i from 0 <= i < self.n_scores: + * self.cscores[i] = s[i] + */ + __pyx_t_2 = PyObject_Length(__pyx_v_s); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->n_scores = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":240 + * self.cscores = malloc(len(s)*sizeof(float)) + * self.n_scores = len(s) + * for i from 0 <= i < self.n_scores: # <<<<<<<<<<<<<< + * self.cscores[i] = s[i] + */ + __pyx_t_3 = __pyx_v_self->n_scores; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":241 + * self.n_scores = len(s) + * for i from 0 <= i < self.n_scores: + * self.cscores[i] = s[i] # <<<<<<<<<<<<<< + */ + __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_s, __pyx_v_i, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __pyx_PyFloat_AsFloat(__pyx_t_4); if (unlikely((__pyx_t_5 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + (__pyx_v_self->cscores[__pyx_v_i]) = __pyx_t_5; + } + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec_sa.Rule.scores.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_4Rule_3lhs_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_4Rule_3lhs_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_4Rule_3lhs___get__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":160 + * + * cdef class Rule: + * cdef public int lhs # <<<<<<<<<<<<<< + * cdef readonly Phrase f, e + * cdef float *cscores + */ + +static PyObject *__pyx_pf_8_cdec_sa_4Rule_3lhs___get__(struct __pyx_obj_8_cdec_sa_Rule *__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("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->lhs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_cdec_sa.Rule.lhs.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_4Rule_3lhs_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_8_cdec_sa_4Rule_3lhs_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_4Rule_3lhs_2__set__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_4Rule_3lhs_2__set__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->lhs = __pyx_t_1; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec_sa.Rule.lhs.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_4Rule_1f_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_4Rule_1f_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_4Rule_1f___get__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":161 + * cdef class Rule: + * cdef public int lhs + * cdef readonly Phrase f, e # <<<<<<<<<<<<<< + * cdef float *cscores + * cdef int n_scores + */ + +static PyObject *__pyx_pf_8_cdec_sa_4Rule_1f___get__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->f)); + __pyx_r = ((PyObject *)__pyx_v_self->f); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_4Rule_1e_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_4Rule_1e_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_4Rule_1e___get__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_8_cdec_sa_4Rule_1e___get__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->e)); + __pyx_r = ((PyObject *)__pyx_v_self->e); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_4Rule_15word_alignments_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_4Rule_15word_alignments_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_4Rule_15word_alignments___get__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":164 + * cdef float *cscores + * cdef int n_scores + * cdef public word_alignments # <<<<<<<<<<<<<< + * + * def __cinit__(self, int lhs, Phrase f, Phrase e, + */ + +static PyObject *__pyx_pf_8_cdec_sa_4Rule_15word_alignments___get__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->word_alignments); + __pyx_r = __pyx_v_self->word_alignments; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_4Rule_15word_alignments_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_8_cdec_sa_4Rule_15word_alignments_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_4Rule_15word_alignments_2__set__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_4Rule_15word_alignments_2__set__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->word_alignments); + __Pyx_DECREF(__pyx_v_self->word_alignments); + __pyx_v_self->word_alignments = __pyx_v_value; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_4Rule_15word_alignments_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_8_cdec_sa_4Rule_15word_alignments_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_4Rule_15word_alignments_4__del__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_4Rule_15word_alignments_4__del__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->word_alignments); + __Pyx_DECREF(__pyx_v_self->word_alignments); + __pyx_v_self->word_alignments = Py_None; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":21 + * int arr_len + * + * cdef _Trie_Node* new_trie_node(): # <<<<<<<<<<<<<< + * cdef _Trie_Node* node + * node = <_Trie_Node*> malloc(sizeof(_Trie_Node)) + */ + +static struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_f_8_cdec_sa_new_trie_node(void) { + struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node; + struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("new_trie_node", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":23 + * cdef _Trie_Node* new_trie_node(): + * cdef _Trie_Node* node + * node = <_Trie_Node*> malloc(sizeof(_Trie_Node)) # <<<<<<<<<<<<<< + * node.root = NULL + * node.arr_len = 0 + */ + __pyx_v_node = ((struct __pyx_t_8_cdec_sa__Trie_Node *)malloc((sizeof(struct __pyx_t_8_cdec_sa__Trie_Node)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":24 + * cdef _Trie_Node* node + * node = <_Trie_Node*> malloc(sizeof(_Trie_Node)) + * node.root = NULL # <<<<<<<<<<<<<< + * node.arr_len = 0 + * node.arr = malloc(sizeof(0*sizeof(int))) + */ + __pyx_v_node->root = NULL; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":25 + * node = <_Trie_Node*> malloc(sizeof(_Trie_Node)) + * node.root = NULL + * node.arr_len = 0 # <<<<<<<<<<<<<< + * node.arr = malloc(sizeof(0*sizeof(int))) + * return node + */ + __pyx_v_node->arr_len = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":26 + * node.root = NULL + * node.arr_len = 0 + * node.arr = malloc(sizeof(0*sizeof(int))) # <<<<<<<<<<<<<< + * return node + * + */ + __pyx_v_node->arr = ((int *)malloc((sizeof((0 * (sizeof(int))))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":27 + * node.arr_len = 0 + * node.arr = malloc(sizeof(0*sizeof(int))) + * return node # <<<<<<<<<<<<<< + * + * cdef _Trie_Edge* new_trie_edge(int val): + */ + __pyx_r = __pyx_v_node; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":29 + * return node + * + * cdef _Trie_Edge* new_trie_edge(int val): # <<<<<<<<<<<<<< + * cdef _Trie_Edge* edge + * edge = <_Trie_Edge*> malloc(sizeof(_Trie_Edge)) + */ + +static struct __pyx_t_8_cdec_sa__Trie_Edge *__pyx_f_8_cdec_sa_new_trie_edge(int __pyx_v_val) { + struct __pyx_t_8_cdec_sa__Trie_Edge *__pyx_v_edge; + struct __pyx_t_8_cdec_sa__Trie_Edge *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("new_trie_edge", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":31 + * cdef _Trie_Edge* new_trie_edge(int val): + * cdef _Trie_Edge* edge + * edge = <_Trie_Edge*> malloc(sizeof(_Trie_Edge)) # <<<<<<<<<<<<<< + * edge.node = new_trie_node() + * edge.bigger = NULL + */ + __pyx_v_edge = ((struct __pyx_t_8_cdec_sa__Trie_Edge *)malloc((sizeof(struct __pyx_t_8_cdec_sa__Trie_Edge)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":32 + * cdef _Trie_Edge* edge + * edge = <_Trie_Edge*> malloc(sizeof(_Trie_Edge)) + * edge.node = new_trie_node() # <<<<<<<<<<<<<< + * edge.bigger = NULL + * edge.smaller = NULL + */ + __pyx_v_edge->node = __pyx_f_8_cdec_sa_new_trie_node(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":33 + * edge = <_Trie_Edge*> malloc(sizeof(_Trie_Edge)) + * edge.node = new_trie_node() + * edge.bigger = NULL # <<<<<<<<<<<<<< + * edge.smaller = NULL + * edge.val = val + */ + __pyx_v_edge->bigger = NULL; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":34 + * edge.node = new_trie_node() + * edge.bigger = NULL + * edge.smaller = NULL # <<<<<<<<<<<<<< + * edge.val = val + * return edge + */ + __pyx_v_edge->smaller = NULL; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":35 + * edge.bigger = NULL + * edge.smaller = NULL + * edge.val = val # <<<<<<<<<<<<<< + * return edge + * + */ + __pyx_v_edge->val = __pyx_v_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":36 + * edge.smaller = NULL + * edge.val = val + * return edge # <<<<<<<<<<<<<< + * + * cdef free_trie_node(_Trie_Node* node): + */ + __pyx_r = __pyx_v_edge; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":38 + * return edge + * + * cdef free_trie_node(_Trie_Node* node): # <<<<<<<<<<<<<< + * if node != NULL: + * free_trie_edge(node.root) + */ + +static PyObject *__pyx_f_8_cdec_sa_free_trie_node(struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("free_trie_node", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":39 + * + * cdef free_trie_node(_Trie_Node* node): + * if node != NULL: # <<<<<<<<<<<<<< + * free_trie_edge(node.root) + * free(node.arr) + */ + __pyx_t_1 = (__pyx_v_node != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":40 + * cdef free_trie_node(_Trie_Node* node): + * if node != NULL: + * free_trie_edge(node.root) # <<<<<<<<<<<<<< + * free(node.arr) + * + */ + __pyx_t_2 = __pyx_f_8_cdec_sa_free_trie_edge(__pyx_v_node->root); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":41 + * if node != NULL: + * free_trie_edge(node.root) + * free(node.arr) # <<<<<<<<<<<<<< + * + * cdef free_trie_edge(_Trie_Edge* edge): + */ + free(__pyx_v_node->arr); + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec_sa.free_trie_node", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":43 + * free(node.arr) + * + * cdef free_trie_edge(_Trie_Edge* edge): # <<<<<<<<<<<<<< + * if edge != NULL: + * free_trie_node(edge.node) + */ + +static PyObject *__pyx_f_8_cdec_sa_free_trie_edge(struct __pyx_t_8_cdec_sa__Trie_Edge *__pyx_v_edge) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("free_trie_edge", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":44 + * + * cdef free_trie_edge(_Trie_Edge* edge): + * if edge != NULL: # <<<<<<<<<<<<<< + * free_trie_node(edge.node) + * free_trie_edge(edge.bigger) + */ + __pyx_t_1 = (__pyx_v_edge != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":45 + * cdef free_trie_edge(_Trie_Edge* edge): + * if edge != NULL: + * free_trie_node(edge.node) # <<<<<<<<<<<<<< + * free_trie_edge(edge.bigger) + * free_trie_edge(edge.smaller) + */ + __pyx_t_2 = __pyx_f_8_cdec_sa_free_trie_node(__pyx_v_edge->node); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":46 + * if edge != NULL: + * free_trie_node(edge.node) + * free_trie_edge(edge.bigger) # <<<<<<<<<<<<<< + * free_trie_edge(edge.smaller) + * + */ + __pyx_t_2 = __pyx_f_8_cdec_sa_free_trie_edge(__pyx_v_edge->bigger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":47 + * free_trie_node(edge.node) + * free_trie_edge(edge.bigger) + * free_trie_edge(edge.smaller) # <<<<<<<<<<<<<< + * + * cdef _Trie_Node* trie_find(_Trie_Node* node, int val): + */ + __pyx_t_2 = __pyx_f_8_cdec_sa_free_trie_edge(__pyx_v_edge->smaller); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec_sa.free_trie_edge", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":49 + * free_trie_edge(edge.smaller) + * + * cdef _Trie_Node* trie_find(_Trie_Node* node, int val): # <<<<<<<<<<<<<< + * cdef _Trie_Edge* cur + * cur = node.root + */ + +static struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_f_8_cdec_sa_trie_find(struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node, int __pyx_v_val) { + struct __pyx_t_8_cdec_sa__Trie_Edge *__pyx_v_cur; + struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("trie_find", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":51 + * cdef _Trie_Node* trie_find(_Trie_Node* node, int val): + * cdef _Trie_Edge* cur + * cur = node.root # <<<<<<<<<<<<<< + * while cur != NULL and cur.val != val: + * if val > cur.val: + */ + __pyx_v_cur = __pyx_v_node->root; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":52 + * cdef _Trie_Edge* cur + * cur = node.root + * while cur != NULL and cur.val != val: # <<<<<<<<<<<<<< + * if val > cur.val: + * cur = cur.bigger + */ + while (1) { + __pyx_t_1 = (__pyx_v_cur != NULL); + if (__pyx_t_1) { + __pyx_t_2 = (__pyx_v_cur->val != __pyx_v_val); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":53 + * cur = node.root + * while cur != NULL and cur.val != val: + * if val > cur.val: # <<<<<<<<<<<<<< + * cur = cur.bigger + * elif val < cur.val: + */ + __pyx_t_3 = (__pyx_v_val > __pyx_v_cur->val); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":54 + * while cur != NULL and cur.val != val: + * if val > cur.val: + * cur = cur.bigger # <<<<<<<<<<<<<< + * elif val < cur.val: + * cur = cur.smaller + */ + __pyx_v_cur = __pyx_v_cur->bigger; + goto __pyx_L5; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":55 + * if val > cur.val: + * cur = cur.bigger + * elif val < cur.val: # <<<<<<<<<<<<<< + * cur = cur.smaller + * if cur == NULL: + */ + __pyx_t_3 = (__pyx_v_val < __pyx_v_cur->val); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":56 + * cur = cur.bigger + * elif val < cur.val: + * cur = cur.smaller # <<<<<<<<<<<<<< + * if cur == NULL: + * return NULL + */ + __pyx_v_cur = __pyx_v_cur->smaller; + goto __pyx_L5; + } + __pyx_L5:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":57 + * elif val < cur.val: + * cur = cur.smaller + * if cur == NULL: # <<<<<<<<<<<<<< + * return NULL + * else: + */ + __pyx_t_3 = (__pyx_v_cur == NULL); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":58 + * cur = cur.smaller + * if cur == NULL: + * return NULL # <<<<<<<<<<<<<< + * else: + * return cur.node + */ + __pyx_r = NULL; + goto __pyx_L0; + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":60 + * return NULL + * else: + * return cur.node # <<<<<<<<<<<<<< + * + * cdef trie_node_data_append(_Trie_Node* node, int val): + */ + __pyx_r = __pyx_v_cur->node; + goto __pyx_L0; + } + __pyx_L6:; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":62 + * return cur.node + * + * cdef trie_node_data_append(_Trie_Node* node, int val): # <<<<<<<<<<<<<< + * cdef int new_len + * new_len = node.arr_len + 1 + */ + +static PyObject *__pyx_f_8_cdec_sa_trie_node_data_append(struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node, int __pyx_v_val) { + int __pyx_v_new_len; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("trie_node_data_append", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":64 + * cdef trie_node_data_append(_Trie_Node* node, int val): + * cdef int new_len + * new_len = node.arr_len + 1 # <<<<<<<<<<<<<< + * node.arr = realloc(node.arr, new_len*sizeof(int)) + * node.arr[node.arr_len] = val + */ + __pyx_v_new_len = (__pyx_v_node->arr_len + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":65 + * cdef int new_len + * new_len = node.arr_len + 1 + * node.arr = realloc(node.arr, new_len*sizeof(int)) # <<<<<<<<<<<<<< + * node.arr[node.arr_len] = val + * node.arr_len = new_len + */ + __pyx_v_node->arr = ((int *)realloc(__pyx_v_node->arr, (__pyx_v_new_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":66 + * new_len = node.arr_len + 1 + * node.arr = realloc(node.arr, new_len*sizeof(int)) + * node.arr[node.arr_len] = val # <<<<<<<<<<<<<< + * node.arr_len = new_len + * + */ + (__pyx_v_node->arr[__pyx_v_node->arr_len]) = __pyx_v_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":67 + * node.arr = realloc(node.arr, new_len*sizeof(int)) + * node.arr[node.arr_len] = val + * node.arr_len = new_len # <<<<<<<<<<<<<< + * + * cdef trie_node_data_extend(_Trie_Node* node, int* vals, int num_vals): + */ + __pyx_v_node->arr_len = __pyx_v_new_len; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":69 + * node.arr_len = new_len + * + * cdef trie_node_data_extend(_Trie_Node* node, int* vals, int num_vals): # <<<<<<<<<<<<<< + * cdef int new_len + * new_len = node.arr_len + num_vals + */ + +static PyObject *__pyx_f_8_cdec_sa_trie_node_data_extend(struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node, int *__pyx_v_vals, int __pyx_v_num_vals) { + int __pyx_v_new_len; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("trie_node_data_extend", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":71 + * cdef trie_node_data_extend(_Trie_Node* node, int* vals, int num_vals): + * cdef int new_len + * new_len = node.arr_len + num_vals # <<<<<<<<<<<<<< + * node.arr = realloc(node.arr, new_len*sizeof(int)) + * memcpy(node.arr + node.arr_len, vals, num_vals*sizeof(int)) + */ + __pyx_v_new_len = (__pyx_v_node->arr_len + __pyx_v_num_vals); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":72 + * cdef int new_len + * new_len = node.arr_len + num_vals + * node.arr = realloc(node.arr, new_len*sizeof(int)) # <<<<<<<<<<<<<< + * memcpy(node.arr + node.arr_len, vals, num_vals*sizeof(int)) + * node.arr_len = new_len + */ + __pyx_v_node->arr = ((int *)realloc(__pyx_v_node->arr, (__pyx_v_new_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":73 + * new_len = node.arr_len + num_vals + * node.arr = realloc(node.arr, new_len*sizeof(int)) + * memcpy(node.arr + node.arr_len, vals, num_vals*sizeof(int)) # <<<<<<<<<<<<<< + * node.arr_len = new_len + * + */ + memcpy((__pyx_v_node->arr + __pyx_v_node->arr_len), __pyx_v_vals, (__pyx_v_num_vals * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":74 + * node.arr = realloc(node.arr, new_len*sizeof(int)) + * memcpy(node.arr + node.arr_len, vals, num_vals*sizeof(int)) + * node.arr_len = new_len # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_node->arr_len = __pyx_v_new_len; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":77 + * + * + * cdef _Trie_Node* trie_insert(_Trie_Node* node, int val): # <<<<<<<<<<<<<< + * cdef _Trie_Edge** cur + * cur = &node.root + */ + +static struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_f_8_cdec_sa_trie_insert(struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node, int __pyx_v_val) { + struct __pyx_t_8_cdec_sa__Trie_Edge **__pyx_v_cur; + struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("trie_insert", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":79 + * cdef _Trie_Node* trie_insert(_Trie_Node* node, int val): + * cdef _Trie_Edge** cur + * cur = &node.root # <<<<<<<<<<<<<< + * while cur[0] != NULL and cur[0].val != val: + * if val > cur[0].val: + */ + __pyx_v_cur = (&__pyx_v_node->root); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":80 + * cdef _Trie_Edge** cur + * cur = &node.root + * while cur[0] != NULL and cur[0].val != val: # <<<<<<<<<<<<<< + * if val > cur[0].val: + * cur = &cur[0].bigger + */ + while (1) { + __pyx_t_1 = ((__pyx_v_cur[0]) != NULL); + if (__pyx_t_1) { + __pyx_t_2 = ((__pyx_v_cur[0])->val != __pyx_v_val); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":81 + * cur = &node.root + * while cur[0] != NULL and cur[0].val != val: + * if val > cur[0].val: # <<<<<<<<<<<<<< + * cur = &cur[0].bigger + * elif val < cur[0].val: + */ + __pyx_t_3 = (__pyx_v_val > (__pyx_v_cur[0])->val); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":82 + * while cur[0] != NULL and cur[0].val != val: + * if val > cur[0].val: + * cur = &cur[0].bigger # <<<<<<<<<<<<<< + * elif val < cur[0].val: + * cur = &cur[0].smaller + */ + __pyx_v_cur = (&(__pyx_v_cur[0])->bigger); + goto __pyx_L5; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":83 + * if val > cur[0].val: + * cur = &cur[0].bigger + * elif val < cur[0].val: # <<<<<<<<<<<<<< + * cur = &cur[0].smaller + * if cur[0] == NULL: + */ + __pyx_t_3 = (__pyx_v_val < (__pyx_v_cur[0])->val); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":84 + * cur = &cur[0].bigger + * elif val < cur[0].val: + * cur = &cur[0].smaller # <<<<<<<<<<<<<< + * if cur[0] == NULL: + * cur[0] = new_trie_edge(val) + */ + __pyx_v_cur = (&(__pyx_v_cur[0])->smaller); + goto __pyx_L5; + } + __pyx_L5:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":85 + * elif val < cur[0].val: + * cur = &cur[0].smaller + * if cur[0] == NULL: # <<<<<<<<<<<<<< + * cur[0] = new_trie_edge(val) + * return cur[0].node + */ + __pyx_t_3 = ((__pyx_v_cur[0]) == NULL); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":86 + * cur = &cur[0].smaller + * if cur[0] == NULL: + * cur[0] = new_trie_edge(val) # <<<<<<<<<<<<<< + * return cur[0].node + * + */ + (__pyx_v_cur[0]) = __pyx_f_8_cdec_sa_new_trie_edge(__pyx_v_val); + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":87 + * if cur[0] == NULL: + * cur[0] = new_trie_edge(val) + * return cur[0].node # <<<<<<<<<<<<<< + * + * cdef trie_node_to_map(_Trie_Node* node, result, prefix, int include_zeros): + */ + __pyx_r = (__pyx_v_cur[0])->node; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":89 + * return cur[0].node + * + * cdef trie_node_to_map(_Trie_Node* node, result, prefix, int include_zeros): # <<<<<<<<<<<<<< + * cdef IntList arr + * + */ + +static PyObject *__pyx_f_8_cdec_sa_trie_node_to_map(struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node, PyObject *__pyx_v_result, PyObject *__pyx_v_prefix, int __pyx_v_include_zeros) { + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_arr = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("trie_node_to_map", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":92 + * cdef IntList arr + * + * if include_zeros or node.arr_len > 0: # <<<<<<<<<<<<<< + * arr = IntList() + * free(arr.arr) + */ + if (!__pyx_v_include_zeros) { + __pyx_t_1 = (__pyx_v_node->arr_len > 0); + __pyx_t_2 = __pyx_t_1; + } else { + __pyx_t_2 = __pyx_v_include_zeros; + } + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":93 + * + * if include_zeros or node.arr_len > 0: + * arr = IntList() # <<<<<<<<<<<<<< + * free(arr.arr) + * arr.arr = malloc(node.arr_len * sizeof(int)) + */ + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_arr = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":94 + * if include_zeros or node.arr_len > 0: + * arr = IntList() + * free(arr.arr) # <<<<<<<<<<<<<< + * arr.arr = malloc(node.arr_len * sizeof(int)) + * memcpy(arr.arr, node.arr, node.arr_len * sizeof(int)) + */ + free(__pyx_v_arr->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":95 + * arr = IntList() + * free(arr.arr) + * arr.arr = malloc(node.arr_len * sizeof(int)) # <<<<<<<<<<<<<< + * memcpy(arr.arr, node.arr, node.arr_len * sizeof(int)) + * arr.len = node.arr_len + */ + __pyx_v_arr->arr = ((int *)malloc((__pyx_v_node->arr_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":96 + * free(arr.arr) + * arr.arr = malloc(node.arr_len * sizeof(int)) + * memcpy(arr.arr, node.arr, node.arr_len * sizeof(int)) # <<<<<<<<<<<<<< + * arr.len = node.arr_len + * arr.size = node.arr_len + */ + memcpy(__pyx_v_arr->arr, __pyx_v_node->arr, (__pyx_v_node->arr_len * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":97 + * arr.arr = malloc(node.arr_len * sizeof(int)) + * memcpy(arr.arr, node.arr, node.arr_len * sizeof(int)) + * arr.len = node.arr_len # <<<<<<<<<<<<<< + * arr.size = node.arr_len + * result[prefix] = arr + */ + __pyx_v_arr->len = __pyx_v_node->arr_len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":98 + * memcpy(arr.arr, node.arr, node.arr_len * sizeof(int)) + * arr.len = node.arr_len + * arr.size = node.arr_len # <<<<<<<<<<<<<< + * result[prefix] = arr + * trie_edge_to_map(node.root, result, prefix, include_zeros) + */ + __pyx_v_arr->size = __pyx_v_node->arr_len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":99 + * arr.len = node.arr_len + * arr.size = node.arr_len + * result[prefix] = arr # <<<<<<<<<<<<<< + * trie_edge_to_map(node.root, result, prefix, include_zeros) + * + */ + if (PyObject_SetItem(__pyx_v_result, __pyx_v_prefix, ((PyObject *)__pyx_v_arr)) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":100 + * arr.size = node.arr_len + * result[prefix] = arr + * trie_edge_to_map(node.root, result, prefix, include_zeros) # <<<<<<<<<<<<<< + * + * cdef trie_edge_to_map(_Trie_Edge* edge, result, prefix, int include_zeros): + */ + __pyx_t_3 = __pyx_f_8_cdec_sa_trie_edge_to_map(__pyx_v_node->root, __pyx_v_result, __pyx_v_prefix, __pyx_v_include_zeros); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.trie_node_to_map", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_arr); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":102 + * trie_edge_to_map(node.root, result, prefix, include_zeros) + * + * cdef trie_edge_to_map(_Trie_Edge* edge, result, prefix, int include_zeros): # <<<<<<<<<<<<<< + * if edge != NULL: + * trie_edge_to_map(edge.smaller, result, prefix, include_zeros) + */ + +static PyObject *__pyx_f_8_cdec_sa_trie_edge_to_map(struct __pyx_t_8_cdec_sa__Trie_Edge *__pyx_v_edge, PyObject *__pyx_v_result, PyObject *__pyx_v_prefix, int __pyx_v_include_zeros) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("trie_edge_to_map", 0); + __Pyx_INCREF(__pyx_v_prefix); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":103 + * + * cdef trie_edge_to_map(_Trie_Edge* edge, result, prefix, int include_zeros): + * if edge != NULL: # <<<<<<<<<<<<<< + * trie_edge_to_map(edge.smaller, result, prefix, include_zeros) + * trie_edge_to_map(edge.bigger, result, prefix, include_zeros) + */ + __pyx_t_1 = (__pyx_v_edge != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":104 + * cdef trie_edge_to_map(_Trie_Edge* edge, result, prefix, int include_zeros): + * if edge != NULL: + * trie_edge_to_map(edge.smaller, result, prefix, include_zeros) # <<<<<<<<<<<<<< + * trie_edge_to_map(edge.bigger, result, prefix, include_zeros) + * prefix = prefix + (edge.val,) + */ + __pyx_t_2 = __pyx_f_8_cdec_sa_trie_edge_to_map(__pyx_v_edge->smaller, __pyx_v_result, __pyx_v_prefix, __pyx_v_include_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":105 + * if edge != NULL: + * trie_edge_to_map(edge.smaller, result, prefix, include_zeros) + * trie_edge_to_map(edge.bigger, result, prefix, include_zeros) # <<<<<<<<<<<<<< + * prefix = prefix + (edge.val,) + * trie_node_to_map(edge.node, result, prefix, include_zeros) + */ + __pyx_t_2 = __pyx_f_8_cdec_sa_trie_edge_to_map(__pyx_v_edge->bigger, __pyx_v_result, __pyx_v_prefix, __pyx_v_include_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":106 + * trie_edge_to_map(edge.smaller, result, prefix, include_zeros) + * trie_edge_to_map(edge.bigger, result, prefix, include_zeros) + * prefix = prefix + (edge.val,) # <<<<<<<<<<<<<< + * trie_node_to_map(edge.node, result, prefix, include_zeros) + * + */ + __pyx_t_2 = PyInt_FromLong(__pyx_v_edge->val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Add(__pyx_v_prefix, ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_v_prefix); + __pyx_v_prefix = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":107 + * trie_edge_to_map(edge.bigger, result, prefix, include_zeros) + * prefix = prefix + (edge.val,) + * trie_node_to_map(edge.node, result, prefix, include_zeros) # <<<<<<<<<<<<<< + * + * cdef class TrieMap: + */ + __pyx_t_2 = __pyx_f_8_cdec_sa_trie_node_to_map(__pyx_v_edge->node, __pyx_v_result, __pyx_v_prefix, __pyx_v_include_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.trie_edge_to_map", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_prefix); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_7TrieMap_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_7TrieMap_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_alphabet_size; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__alphabet_size,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__alphabet_size); + 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 114; __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_alphabet_size = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_alphabet_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 114; __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[11]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.TrieMap.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_7TrieMap___cinit__(((struct __pyx_obj_8_cdec_sa_TrieMap *)__pyx_v_self), __pyx_v_alphabet_size); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":114 + * cdef int V + * + * def __cinit__(self, int alphabet_size): # <<<<<<<<<<<<<< + * self.V = alphabet_size + * self.root = <_Trie_Node**> malloc(self.V * sizeof(_Trie_Node*)) + */ + +static int __pyx_pf_8_cdec_sa_7TrieMap___cinit__(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, int __pyx_v_alphabet_size) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":115 + * + * def __cinit__(self, int alphabet_size): + * self.V = alphabet_size # <<<<<<<<<<<<<< + * self.root = <_Trie_Node**> malloc(self.V * sizeof(_Trie_Node*)) + * memset(self.root, 0, self.V * sizeof(_Trie_Node*)) + */ + __pyx_v_self->V = __pyx_v_alphabet_size; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":116 + * def __cinit__(self, int alphabet_size): + * self.V = alphabet_size + * self.root = <_Trie_Node**> malloc(self.V * sizeof(_Trie_Node*)) # <<<<<<<<<<<<<< + * memset(self.root, 0, self.V * sizeof(_Trie_Node*)) + * + */ + __pyx_v_self->root = ((struct __pyx_t_8_cdec_sa__Trie_Node **)malloc((__pyx_v_self->V * (sizeof(struct __pyx_t_8_cdec_sa__Trie_Node *))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":117 + * self.V = alphabet_size + * self.root = <_Trie_Node**> malloc(self.V * sizeof(_Trie_Node*)) + * memset(self.root, 0, self.V * sizeof(_Trie_Node*)) # <<<<<<<<<<<<<< + * + * + */ + memset(__pyx_v_self->root, 0, (__pyx_v_self->V * (sizeof(struct __pyx_t_8_cdec_sa__Trie_Node *)))); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_8_cdec_sa_7TrieMap_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_8_cdec_sa_7TrieMap_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_8_cdec_sa_7TrieMap_2__dealloc__(((struct __pyx_obj_8_cdec_sa_TrieMap *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":120 + * + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * cdef int i + * for i from 0 <= i < self.V: + */ + +static void __pyx_pf_8_cdec_sa_7TrieMap_2__dealloc__(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self) { + int __pyx_v_i; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":122 + * def __dealloc__(self): + * cdef int i + * for i from 0 <= i < self.V: # <<<<<<<<<<<<<< + * if self.root[i] != NULL: + * free_trie_node(self.root[i]) + */ + __pyx_t_1 = __pyx_v_self->V; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":123 + * cdef int i + * for i from 0 <= i < self.V: + * if self.root[i] != NULL: # <<<<<<<<<<<<<< + * free_trie_node(self.root[i]) + * free(self.root) + */ + __pyx_t_2 = ((__pyx_v_self->root[__pyx_v_i]) != NULL); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":124 + * for i from 0 <= i < self.V: + * if self.root[i] != NULL: + * free_trie_node(self.root[i]) # <<<<<<<<<<<<<< + * free(self.root) + * + */ + __pyx_t_3 = __pyx_f_8_cdec_sa_free_trie_node((__pyx_v_self->root[__pyx_v_i])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L5; + } + __pyx_L5:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":125 + * if self.root[i] != NULL: + * free_trie_node(self.root[i]) + * free(self.root) # <<<<<<<<<<<<<< + * + * + */ + free(__pyx_v_self->root); + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.TrieMap.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_7TrieMap_5insert(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_7TrieMap_5insert(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("insert (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_7TrieMap_4insert(((struct __pyx_obj_8_cdec_sa_TrieMap *)__pyx_v_self), ((PyObject *)__pyx_v_pattern)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":128 + * + * + * def insert(self, pattern): # <<<<<<<<<<<<<< + * cdef int* p + * cdef int i, l + */ + +static PyObject *__pyx_pf_8_cdec_sa_7TrieMap_4insert(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, PyObject *__pyx_v_pattern) { + int *__pyx_v_p; + int __pyx_v_i; + int __pyx_v_l; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("insert", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":131 + * cdef int* p + * cdef int i, l + * l = len(pattern) # <<<<<<<<<<<<<< + * p = malloc(l*sizeof(int)) + * for i from 0 <= i < l: + */ + __pyx_t_1 = PyObject_Length(__pyx_v_pattern); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_l = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":132 + * cdef int i, l + * l = len(pattern) + * p = malloc(l*sizeof(int)) # <<<<<<<<<<<<<< + * for i from 0 <= i < l: + * p[i] = pattern[i] + */ + __pyx_v_p = ((int *)malloc((__pyx_v_l * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":133 + * l = len(pattern) + * p = malloc(l*sizeof(int)) + * for i from 0 <= i < l: # <<<<<<<<<<<<<< + * p[i] = pattern[i] + * self._insert(p,l) + */ + __pyx_t_2 = __pyx_v_l; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":134 + * p = malloc(l*sizeof(int)) + * for i from 0 <= i < l: + * p[i] = pattern[i] # <<<<<<<<<<<<<< + * self._insert(p,l) + * free(p) + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_pattern, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + (__pyx_v_p[__pyx_v_i]) = __pyx_t_4; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":135 + * for i from 0 <= i < l: + * p[i] = pattern[i] + * self._insert(p,l) # <<<<<<<<<<<<<< + * free(p) + * + */ + ((struct __pyx_vtabstruct_8_cdec_sa_TrieMap *)__pyx_v_self->__pyx_vtab)->_insert(__pyx_v_self, __pyx_v_p, __pyx_v_l); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":136 + * p[i] = pattern[i] + * self._insert(p,l) + * free(p) # <<<<<<<<<<<<<< + * + * + */ + free(__pyx_v_p); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.TrieMap.insert", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":139 + * + * + * cdef _Trie_Node* _insert(self, int* pattern, int pattern_len): # <<<<<<<<<<<<<< + * cdef int i + * cdef _Trie_Node* node + */ + +static struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_f_8_cdec_sa_7TrieMap__insert(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, int *__pyx_v_pattern, int __pyx_v_pattern_len) { + int __pyx_v_i; + struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node; + struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + __Pyx_RefNannySetupContext("_insert", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":142 + * cdef int i + * cdef _Trie_Node* node + * if self.root[pattern[0]] == NULL: # <<<<<<<<<<<<<< + * self.root[pattern[0]] = new_trie_node() + * node = self.root[pattern[0]] + */ + __pyx_t_1 = ((__pyx_v_self->root[(__pyx_v_pattern[0])]) == NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":143 + * cdef _Trie_Node* node + * if self.root[pattern[0]] == NULL: + * self.root[pattern[0]] = new_trie_node() # <<<<<<<<<<<<<< + * node = self.root[pattern[0]] + * for i from 1 <= i < pattern_len: + */ + (__pyx_v_self->root[(__pyx_v_pattern[0])]) = __pyx_f_8_cdec_sa_new_trie_node(); + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":144 + * if self.root[pattern[0]] == NULL: + * self.root[pattern[0]] = new_trie_node() + * node = self.root[pattern[0]] # <<<<<<<<<<<<<< + * for i from 1 <= i < pattern_len: + * node = trie_insert(node, pattern[i]) + */ + __pyx_v_node = (__pyx_v_self->root[(__pyx_v_pattern[0])]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":145 + * self.root[pattern[0]] = new_trie_node() + * node = self.root[pattern[0]] + * for i from 1 <= i < pattern_len: # <<<<<<<<<<<<<< + * node = trie_insert(node, pattern[i]) + * return node + */ + __pyx_t_2 = __pyx_v_pattern_len; + for (__pyx_v_i = 1; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":146 + * node = self.root[pattern[0]] + * for i from 1 <= i < pattern_len: + * node = trie_insert(node, pattern[i]) # <<<<<<<<<<<<<< + * return node + * + */ + __pyx_v_node = __pyx_f_8_cdec_sa_trie_insert(__pyx_v_node, (__pyx_v_pattern[__pyx_v_i])); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":147 + * for i from 1 <= i < pattern_len: + * node = trie_insert(node, pattern[i]) + * return node # <<<<<<<<<<<<<< + * + * def contains(self, pattern): + */ + __pyx_r = __pyx_v_node; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_7TrieMap_7contains(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_7TrieMap_7contains(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("contains (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_7TrieMap_6contains(((struct __pyx_obj_8_cdec_sa_TrieMap *)__pyx_v_self), ((PyObject *)__pyx_v_pattern)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":149 + * return node + * + * def contains(self, pattern): # <<<<<<<<<<<<<< + * cdef int* p + * cdef int i, l + */ + +static PyObject *__pyx_pf_8_cdec_sa_7TrieMap_6contains(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, PyObject *__pyx_v_pattern) { + int *__pyx_v_p; + int __pyx_v_i; + int __pyx_v_l; + struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("contains", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":153 + * cdef int i, l + * cdef _Trie_Node* node + * l = len(pattern) # <<<<<<<<<<<<<< + * p = malloc(l*sizeof(int)) + * for i from 0 <= i < l: + */ + __pyx_t_1 = PyObject_Length(__pyx_v_pattern); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_l = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":154 + * cdef _Trie_Node* node + * l = len(pattern) + * p = malloc(l*sizeof(int)) # <<<<<<<<<<<<<< + * for i from 0 <= i < l: + * p[i] = pattern[i] + */ + __pyx_v_p = ((int *)malloc((__pyx_v_l * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":155 + * l = len(pattern) + * p = malloc(l*sizeof(int)) + * for i from 0 <= i < l: # <<<<<<<<<<<<<< + * p[i] = pattern[i] + * node = self._contains(p,l) + */ + __pyx_t_2 = __pyx_v_l; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":156 + * p = malloc(l*sizeof(int)) + * for i from 0 <= i < l: + * p[i] = pattern[i] # <<<<<<<<<<<<<< + * node = self._contains(p,l) + * free(p) + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_pattern, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + (__pyx_v_p[__pyx_v_i]) = __pyx_t_4; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":157 + * for i from 0 <= i < l: + * p[i] = pattern[i] + * node = self._contains(p,l) # <<<<<<<<<<<<<< + * free(p) + * if node == NULL: + */ + __pyx_v_node = ((struct __pyx_vtabstruct_8_cdec_sa_TrieMap *)__pyx_v_self->__pyx_vtab)->_contains(__pyx_v_self, __pyx_v_p, __pyx_v_l); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":158 + * p[i] = pattern[i] + * node = self._contains(p,l) + * free(p) # <<<<<<<<<<<<<< + * if node == NULL: + * return False + */ + free(__pyx_v_p); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":159 + * node = self._contains(p,l) + * free(p) + * if node == NULL: # <<<<<<<<<<<<<< + * return False + * else: + */ + __pyx_t_5 = (__pyx_v_node == NULL); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":160 + * free(p) + * if node == NULL: + * return False # <<<<<<<<<<<<<< + * else: + * return True + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":162 + * return False + * else: + * return True # <<<<<<<<<<<<<< + * + * cdef _Trie_Node* _contains(self, int* pattern, int pattern_len): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + } + __pyx_L5:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.TrieMap.contains", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":164 + * return True + * + * cdef _Trie_Node* _contains(self, int* pattern, int pattern_len): # <<<<<<<<<<<<<< + * cdef int i + * cdef _Trie_Node* node + */ + +static struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_f_8_cdec_sa_7TrieMap__contains(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, int *__pyx_v_pattern, int __pyx_v_pattern_len) { + int __pyx_v_i; + struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node; + struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("_contains", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":167 + * cdef int i + * cdef _Trie_Node* node + * node = self.root[pattern[0]] # <<<<<<<<<<<<<< + * i = 1 + * while node != NULL and i < pattern_len: + */ + __pyx_v_node = (__pyx_v_self->root[(__pyx_v_pattern[0])]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":168 + * cdef _Trie_Node* node + * node = self.root[pattern[0]] + * i = 1 # <<<<<<<<<<<<<< + * while node != NULL and i < pattern_len: + * node = trie_find(node, pattern[i]) + */ + __pyx_v_i = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":169 + * node = self.root[pattern[0]] + * i = 1 + * while node != NULL and i < pattern_len: # <<<<<<<<<<<<<< + * node = trie_find(node, pattern[i]) + * i = i+1 + */ + while (1) { + __pyx_t_1 = (__pyx_v_node != NULL); + if (__pyx_t_1) { + __pyx_t_2 = (__pyx_v_i < __pyx_v_pattern_len); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":170 + * i = 1 + * while node != NULL and i < pattern_len: + * node = trie_find(node, pattern[i]) # <<<<<<<<<<<<<< + * i = i+1 + * return node + */ + __pyx_v_node = __pyx_f_8_cdec_sa_trie_find(__pyx_v_node, (__pyx_v_pattern[__pyx_v_i])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":171 + * while node != NULL and i < pattern_len: + * node = trie_find(node, pattern[i]) + * i = i+1 # <<<<<<<<<<<<<< + * return node + * + */ + __pyx_v_i = (__pyx_v_i + 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":172 + * node = trie_find(node, pattern[i]) + * i = i+1 + * return node # <<<<<<<<<<<<<< + * + * def toMap(self, flag): + */ + __pyx_r = __pyx_v_node; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_7TrieMap_9toMap(PyObject *__pyx_v_self, PyObject *__pyx_v_flag); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_7TrieMap_9toMap(PyObject *__pyx_v_self, PyObject *__pyx_v_flag) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("toMap (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_7TrieMap_8toMap(((struct __pyx_obj_8_cdec_sa_TrieMap *)__pyx_v_self), ((PyObject *)__pyx_v_flag)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":174 + * return node + * + * def toMap(self, flag): # <<<<<<<<<<<<<< + * cdef int i, include_zeros + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_7TrieMap_8toMap(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, PyObject *__pyx_v_flag) { + int __pyx_v_i; + int __pyx_v_include_zeros; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("toMap", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":177 + * cdef int i, include_zeros + * + * if flag: # <<<<<<<<<<<<<< + * include_zeros=1 + * else: + */ + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_flag); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":178 + * + * if flag: + * include_zeros=1 # <<<<<<<<<<<<<< + * else: + * include_zeros=0 + */ + __pyx_v_include_zeros = 1; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":180 + * include_zeros=1 + * else: + * include_zeros=0 # <<<<<<<<<<<<<< + * result = {} + * for i from 0 <= i < self.V: + */ + __pyx_v_include_zeros = 0; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":181 + * else: + * include_zeros=0 + * result = {} # <<<<<<<<<<<<<< + * for i from 0 <= i < self.V: + * if self.root[i] != NULL: + */ + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_v_result = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":182 + * include_zeros=0 + * result = {} + * for i from 0 <= i < self.V: # <<<<<<<<<<<<<< + * if self.root[i] != NULL: + * trie_node_to_map(self.root[i], result, (i,), include_zeros) + */ + __pyx_t_3 = __pyx_v_self->V; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":183 + * result = {} + * for i from 0 <= i < self.V: + * if self.root[i] != NULL: # <<<<<<<<<<<<<< + * trie_node_to_map(self.root[i], result, (i,), include_zeros) + * return result + */ + __pyx_t_1 = ((__pyx_v_self->root[__pyx_v_i]) != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":184 + * for i from 0 <= i < self.V: + * if self.root[i] != NULL: + * trie_node_to_map(self.root[i], result, (i,), include_zeros) # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_t_2 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = __pyx_f_8_cdec_sa_trie_node_to_map((__pyx_v_self->root[__pyx_v_i]), ((PyObject *)__pyx_v_result), ((PyObject *)__pyx_t_4), __pyx_v_include_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L6; + } + __pyx_L6:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":185 + * if self.root[i] != NULL: + * trie_node_to_map(self.root[i], result, (i,), include_zeros) + * return result # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec_sa.TrieMap.toMap", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_14Precomputation_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_14Precomputation_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_fsarray = 0; + PyObject *__pyx_v_from_stats = 0; + PyObject *__pyx_v_from_binary = 0; + PyObject *__pyx_v_precompute_rank = 0; + PyObject *__pyx_v_precompute_secondary_rank = 0; + PyObject *__pyx_v_max_length = 0; + PyObject *__pyx_v_max_nonterminals = 0; + PyObject *__pyx_v_train_max_initial_size = 0; + PyObject *__pyx_v_train_min_gap_size = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fsarray,&__pyx_n_s__from_stats,&__pyx_n_s__from_binary,&__pyx_n_s__precompute_rank,&__pyx_n_s_68,&__pyx_n_s__max_length,&__pyx_n_s__max_nonterminals,&__pyx_n_s_69,&__pyx_n_s__train_min_gap_size,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[9] = {0,0,0,0,0,0,0,0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":200 + * cdef write_map(self, m, FILE* f) + * + * def __cinit__(self, fsarray=None, from_stats=None, from_binary=None, # <<<<<<<<<<<<<< + * precompute_rank=1000, precompute_secondary_rank=20, + * max_length=5, max_nonterminals=2, + */ + values[0] = ((PyObject *)Py_None); + values[1] = ((PyObject *)Py_None); + values[2] = ((PyObject *)Py_None); + values[3] = ((PyObject *)__pyx_int_1000); + values[4] = ((PyObject *)__pyx_int_20); + values[5] = ((PyObject *)__pyx_int_5); + values[6] = ((PyObject *)__pyx_int_2); + values[7] = ((PyObject *)__pyx_int_10); + values[8] = ((PyObject *)__pyx_int_2); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fsarray); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_stats); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_binary); + if (value) { values[2] = value; kw_args--; } + } + case 3: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__precompute_rank); + if (value) { values[3] = value; kw_args--; } + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_68); + if (value) { values[4] = value; kw_args--; } + } + case 5: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_length); + if (value) { values[5] = value; kw_args--; } + } + case 6: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_nonterminals); + if (value) { values[6] = value; kw_args--; } + } + case 7: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_69); + if (value) { values[7] = value; kw_args--; } + } + case 8: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__train_min_gap_size); + if (value) { values[8] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_fsarray = values[0]; + __pyx_v_from_stats = values[1]; + __pyx_v_from_binary = values[2]; + __pyx_v_precompute_rank = values[3]; + __pyx_v_precompute_secondary_rank = values[4]; + __pyx_v_max_length = values[5]; + __pyx_v_max_nonterminals = values[6]; + __pyx_v_train_max_initial_size = values[7]; + __pyx_v_train_min_gap_size = values[8]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 9, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[11]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.Precomputation.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_14Precomputation___cinit__(((struct __pyx_obj_8_cdec_sa_Precomputation *)__pyx_v_self), __pyx_v_fsarray, __pyx_v_from_stats, __pyx_v_from_binary, __pyx_v_precompute_rank, __pyx_v_precompute_secondary_rank, __pyx_v_max_length, __pyx_v_max_nonterminals, __pyx_v_train_max_initial_size, __pyx_v_train_min_gap_size); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_14Precomputation___cinit__(struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, PyObject *__pyx_v_fsarray, PyObject *__pyx_v_from_stats, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_precompute_rank, PyObject *__pyx_v_precompute_secondary_rank, PyObject *__pyx_v_max_length, PyObject *__pyx_v_max_nonterminals, PyObject *__pyx_v_train_max_initial_size, PyObject *__pyx_v_train_min_gap_size) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":204 + * max_length=5, max_nonterminals=2, + * train_max_initial_size=10, train_min_gap_size=2): + * self.precompute_rank = precompute_rank # <<<<<<<<<<<<<< + * self.precompute_secondary_rank = precompute_secondary_rank + * self.max_length = max_length + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_precompute_rank); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->precompute_rank = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":205 + * train_max_initial_size=10, train_min_gap_size=2): + * self.precompute_rank = precompute_rank + * self.precompute_secondary_rank = precompute_secondary_rank # <<<<<<<<<<<<<< + * self.max_length = max_length + * self.max_nonterminals = max_nonterminals + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_precompute_secondary_rank); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->precompute_secondary_rank = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":206 + * self.precompute_rank = precompute_rank + * self.precompute_secondary_rank = precompute_secondary_rank + * self.max_length = max_length # <<<<<<<<<<<<<< + * self.max_nonterminals = max_nonterminals + * self.train_max_initial_size = train_max_initial_size + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_max_length); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->max_length = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":207 + * self.precompute_secondary_rank = precompute_secondary_rank + * self.max_length = max_length + * self.max_nonterminals = max_nonterminals # <<<<<<<<<<<<<< + * self.train_max_initial_size = train_max_initial_size + * self.train_min_gap_size = train_min_gap_size + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_max_nonterminals); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->max_nonterminals = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":208 + * self.max_length = max_length + * self.max_nonterminals = max_nonterminals + * self.train_max_initial_size = train_max_initial_size # <<<<<<<<<<<<<< + * self.train_min_gap_size = train_min_gap_size + * if from_binary: + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_train_max_initial_size); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->train_max_initial_size = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":209 + * self.max_nonterminals = max_nonterminals + * self.train_max_initial_size = train_max_initial_size + * self.train_min_gap_size = train_min_gap_size # <<<<<<<<<<<<<< + * if from_binary: + * self.read_binary(from_binary) + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_train_min_gap_size); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->train_min_gap_size = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":210 + * self.train_max_initial_size = train_max_initial_size + * self.train_min_gap_size = train_min_gap_size + * if from_binary: # <<<<<<<<<<<<<< + * self.read_binary(from_binary) + * elif from_stats: + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_binary); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":211 + * self.train_min_gap_size = train_min_gap_size + * if from_binary: + * self.read_binary(from_binary) # <<<<<<<<<<<<<< + * elif from_stats: + * self.precompute(from_stats, fsarray) + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_binary); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_from_binary); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_from_binary); + __Pyx_GIVEREF(__pyx_v_from_binary); + __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":212 + * if from_binary: + * self.read_binary(from_binary) + * elif from_stats: # <<<<<<<<<<<<<< + * self.precompute(from_stats, fsarray) + * + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_stats); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":213 + * self.read_binary(from_binary) + * elif from_stats: + * self.precompute(from_stats, fsarray) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__precompute); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_from_stats); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_from_stats); + __Pyx_GIVEREF(__pyx_v_from_stats); + __Pyx_INCREF(__pyx_v_fsarray); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_fsarray); + __Pyx_GIVEREF(__pyx_v_fsarray); + __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_cdec_sa.Precomputation.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_14Precomputation_3read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_14Precomputation_3read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.Precomputation.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_14Precomputation_2read_binary(((struct __pyx_obj_8_cdec_sa_Precomputation *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":216 + * + * + * def read_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "r") + */ + +static PyObject *__pyx_pf_8_cdec_sa_14Precomputation_2read_binary(struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + 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("read_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":218 + * def read_binary(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "r") # <<<<<<<<<<<<<< + * fread(&(self.precompute_rank), sizeof(int), 1, f) + * fread(&(self.precompute_secondary_rank), sizeof(int), 1, f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":219 + * cdef FILE* f + * f = fopen(filename, "r") + * fread(&(self.precompute_rank), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fread(&(self.precompute_secondary_rank), sizeof(int), 1, f) + * fread(&(self.max_length), sizeof(int), 1, f) + */ + fread((&__pyx_v_self->precompute_rank), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":220 + * f = fopen(filename, "r") + * fread(&(self.precompute_rank), sizeof(int), 1, f) + * fread(&(self.precompute_secondary_rank), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fread(&(self.max_length), sizeof(int), 1, f) + * fread(&(self.max_nonterminals), sizeof(int), 1, f) + */ + fread((&__pyx_v_self->precompute_secondary_rank), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":221 + * fread(&(self.precompute_rank), sizeof(int), 1, f) + * fread(&(self.precompute_secondary_rank), sizeof(int), 1, f) + * fread(&(self.max_length), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fread(&(self.max_nonterminals), sizeof(int), 1, f) + * fread(&(self.train_max_initial_size), sizeof(int), 1, f) + */ + fread((&__pyx_v_self->max_length), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":222 + * fread(&(self.precompute_secondary_rank), sizeof(int), 1, f) + * fread(&(self.max_length), sizeof(int), 1, f) + * fread(&(self.max_nonterminals), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fread(&(self.train_max_initial_size), sizeof(int), 1, f) + * fread(&(self.train_min_gap_size), sizeof(int), 1, f) + */ + fread((&__pyx_v_self->max_nonterminals), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":223 + * fread(&(self.max_length), sizeof(int), 1, f) + * fread(&(self.max_nonterminals), sizeof(int), 1, f) + * fread(&(self.train_max_initial_size), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fread(&(self.train_min_gap_size), sizeof(int), 1, f) + * self.precomputed_index = self.read_map(f) + */ + fread((&__pyx_v_self->train_max_initial_size), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":224 + * fread(&(self.max_nonterminals), sizeof(int), 1, f) + * fread(&(self.train_max_initial_size), sizeof(int), 1, f) + * fread(&(self.train_min_gap_size), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * self.precomputed_index = self.read_map(f) + * self.precomputed_collocations = self.read_map(f) + */ + fread((&__pyx_v_self->train_min_gap_size), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":225 + * fread(&(self.train_max_initial_size), sizeof(int), 1, f) + * fread(&(self.train_min_gap_size), sizeof(int), 1, f) + * self.precomputed_index = self.read_map(f) # <<<<<<<<<<<<<< + * self.precomputed_collocations = self.read_map(f) + * fclose(f) + */ + __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_Precomputation *)__pyx_v_self->__pyx_vtab)->read_map(__pyx_v_self, __pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->precomputed_index); + __Pyx_DECREF(__pyx_v_self->precomputed_index); + __pyx_v_self->precomputed_index = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":226 + * fread(&(self.train_min_gap_size), sizeof(int), 1, f) + * self.precomputed_index = self.read_map(f) + * self.precomputed_collocations = self.read_map(f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_Precomputation *)__pyx_v_self->__pyx_vtab)->read_map(__pyx_v_self, __pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->precomputed_collocations); + __Pyx_DECREF(__pyx_v_self->precomputed_collocations); + __pyx_v_self->precomputed_collocations = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":227 + * self.precomputed_index = self.read_map(f) + * self.precomputed_collocations = self.read_map(f) + * fclose(f) # <<<<<<<<<<<<<< + * + * + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec_sa.Precomputation.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_14Precomputation_5write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_14Precomputation_5write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.Precomputation.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_14Precomputation_4write_binary(((struct __pyx_obj_8_cdec_sa_Precomputation *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":230 + * + * + * def write_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "w") + */ + +static PyObject *__pyx_pf_8_cdec_sa_14Precomputation_4write_binary(struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + 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("write_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":232 + * def write_binary(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "w") # <<<<<<<<<<<<<< + * fwrite(&(self.precompute_rank), sizeof(int), 1, f) + * fwrite(&(self.precompute_secondary_rank), sizeof(int), 1, f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":233 + * cdef FILE* f + * f = fopen(filename, "w") + * fwrite(&(self.precompute_rank), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fwrite(&(self.precompute_secondary_rank), sizeof(int), 1, f) + * fwrite(&(self.max_length), sizeof(int), 1, f) + */ + fwrite((&__pyx_v_self->precompute_rank), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":234 + * f = fopen(filename, "w") + * fwrite(&(self.precompute_rank), sizeof(int), 1, f) + * fwrite(&(self.precompute_secondary_rank), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fwrite(&(self.max_length), sizeof(int), 1, f) + * fwrite(&(self.max_nonterminals), sizeof(int), 1, f) + */ + fwrite((&__pyx_v_self->precompute_secondary_rank), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":235 + * fwrite(&(self.precompute_rank), sizeof(int), 1, f) + * fwrite(&(self.precompute_secondary_rank), sizeof(int), 1, f) + * fwrite(&(self.max_length), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fwrite(&(self.max_nonterminals), sizeof(int), 1, f) + * fwrite(&(self.train_max_initial_size), sizeof(int), 1, f) + */ + fwrite((&__pyx_v_self->max_length), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":236 + * fwrite(&(self.precompute_secondary_rank), sizeof(int), 1, f) + * fwrite(&(self.max_length), sizeof(int), 1, f) + * fwrite(&(self.max_nonterminals), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fwrite(&(self.train_max_initial_size), sizeof(int), 1, f) + * fwrite(&(self.train_min_gap_size), sizeof(int), 1, f) + */ + fwrite((&__pyx_v_self->max_nonterminals), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":237 + * fwrite(&(self.max_length), sizeof(int), 1, f) + * fwrite(&(self.max_nonterminals), sizeof(int), 1, f) + * fwrite(&(self.train_max_initial_size), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fwrite(&(self.train_min_gap_size), sizeof(int), 1, f) + * self.write_map(self.precomputed_index, f) + */ + fwrite((&__pyx_v_self->train_max_initial_size), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":238 + * fwrite(&(self.max_nonterminals), sizeof(int), 1, f) + * fwrite(&(self.train_max_initial_size), sizeof(int), 1, f) + * fwrite(&(self.train_min_gap_size), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * self.write_map(self.precomputed_index, f) + * self.write_map(self.precomputed_collocations, f) + */ + fwrite((&__pyx_v_self->train_min_gap_size), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":239 + * fwrite(&(self.train_max_initial_size), sizeof(int), 1, f) + * fwrite(&(self.train_min_gap_size), sizeof(int), 1, f) + * self.write_map(self.precomputed_index, f) # <<<<<<<<<<<<<< + * self.write_map(self.precomputed_collocations, f) + * fclose(f) + */ + __pyx_t_1 = __pyx_v_self->precomputed_index; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_Precomputation *)__pyx_v_self->__pyx_vtab)->write_map(__pyx_v_self, __pyx_t_1, __pyx_v_f); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":240 + * fwrite(&(self.train_min_gap_size), sizeof(int), 1, f) + * self.write_map(self.precomputed_index, f) + * self.write_map(self.precomputed_collocations, f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + __pyx_t_2 = __pyx_v_self->precomputed_collocations; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_Precomputation *)__pyx_v_self->__pyx_vtab)->write_map(__pyx_v_self, __pyx_t_2, __pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 240; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":241 + * self.write_map(self.precomputed_index, f) + * self.write_map(self.precomputed_collocations, f) + * fclose(f) # <<<<<<<<<<<<<< + * + * + */ + fclose(__pyx_v_f); + + __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_sa.Precomputation.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":244 + * + * + * cdef write_map(self, m, FILE* f): # <<<<<<<<<<<<<< + * cdef int i, N + * cdef IntList arr + */ + +static PyObject *__pyx_f_8_cdec_sa_14Precomputation_write_map(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, PyObject *__pyx_v_m, FILE *__pyx_v_f) { + int __pyx_v_i; + int __pyx_v_N; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_arr = 0; + PyObject *__pyx_v_pattern = NULL; + PyObject *__pyx_v_val = NULL; + PyObject *__pyx_v_word_id = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *(*__pyx_t_4)(PyObject *); + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *(*__pyx_t_8)(PyObject *); + Py_ssize_t __pyx_t_9; + PyObject *(*__pyx_t_10)(PyObject *); + int __pyx_t_11; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_map", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":248 + * cdef IntList arr + * + * N = len(m) # <<<<<<<<<<<<<< + * fwrite(&(N), sizeof(int), 1, f) + * for pattern, val in m.iteritems(): + */ + __pyx_t_1 = PyObject_Length(__pyx_v_m); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_N = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":249 + * + * N = len(m) + * fwrite(&(N), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * for pattern, val in m.iteritems(): + * N = len(pattern) + */ + fwrite((&__pyx_v_N), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":250 + * N = len(m) + * fwrite(&(N), sizeof(int), 1, f) + * for pattern, val in m.iteritems(): # <<<<<<<<<<<<<< + * N = len(pattern) + * fwrite(&(N), sizeof(int), 1, f) + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_m, __pyx_n_s__iteritems); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_1 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; + } else { + __pyx_t_3 = __pyx_t_4(__pyx_t_2); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { + PyObject* sequence = __pyx_t_3; + if (likely(PyTuple_CheckExact(sequence))) { + 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[11]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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[11]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_5 = PyList_GET_ITEM(sequence, 0); + __pyx_t_6 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_5 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L6_unpacking_done; + __pyx_L5_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[11]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L6_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_pattern); + __pyx_v_pattern = __pyx_t_5; + __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_v_val); + __pyx_v_val = __pyx_t_6; + __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":251 + * fwrite(&(N), sizeof(int), 1, f) + * for pattern, val in m.iteritems(): + * N = len(pattern) # <<<<<<<<<<<<<< + * fwrite(&(N), sizeof(int), 1, f) + * for word_id in pattern: + */ + __pyx_t_9 = PyObject_Length(__pyx_v_pattern); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 251; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_N = __pyx_t_9; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":252 + * for pattern, val in m.iteritems(): + * N = len(pattern) + * fwrite(&(N), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * for word_id in pattern: + * i = word_id + */ + fwrite((&__pyx_v_N), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":253 + * N = len(pattern) + * fwrite(&(N), sizeof(int), 1, f) + * for word_id in pattern: # <<<<<<<<<<<<<< + * i = word_id + * fwrite(&(i), sizeof(int), 1, f) + */ + if (PyList_CheckExact(__pyx_v_pattern) || PyTuple_CheckExact(__pyx_v_pattern)) { + __pyx_t_3 = __pyx_v_pattern; __Pyx_INCREF(__pyx_t_3); __pyx_t_9 = 0; + __pyx_t_10 = NULL; + } else { + __pyx_t_9 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_pattern); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = Py_TYPE(__pyx_t_3)->tp_iternext; + } + for (;;) { + if (!__pyx_t_10 && PyList_CheckExact(__pyx_t_3)) { + if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_3)) break; + __pyx_t_6 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_9); __Pyx_INCREF(__pyx_t_6); __pyx_t_9++; + } else if (!__pyx_t_10 && PyTuple_CheckExact(__pyx_t_3)) { + if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_9); __Pyx_INCREF(__pyx_t_6); __pyx_t_9++; + } else { + __pyx_t_6 = __pyx_t_10(__pyx_t_3); + if (unlikely(!__pyx_t_6)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_6); + } + __Pyx_XDECREF(__pyx_v_word_id); + __pyx_v_word_id = __pyx_t_6; + __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":254 + * fwrite(&(N), sizeof(int), 1, f) + * for word_id in pattern: + * i = word_id # <<<<<<<<<<<<<< + * fwrite(&(i), sizeof(int), 1, f) + * arr = val + */ + __pyx_t_11 = __Pyx_PyInt_AsInt(__pyx_v_word_id); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_i = __pyx_t_11; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":255 + * for word_id in pattern: + * i = word_id + * fwrite(&(i), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * arr = val + * arr.write_handle(f) + */ + fwrite((&__pyx_v_i), (sizeof(int)), 1, __pyx_v_f); + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":256 + * i = word_id + * fwrite(&(i), sizeof(int), 1, f) + * arr = val # <<<<<<<<<<<<<< + * arr.write_handle(f) + * + */ + if (!(likely(((__pyx_v_val) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_val, __pyx_ptype_8_cdec_sa_IntList))))) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_val); + __Pyx_XDECREF(((PyObject *)__pyx_v_arr)); + __pyx_v_arr = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_val); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":257 + * fwrite(&(i), sizeof(int), 1, f) + * arr = val + * arr.write_handle(f) # <<<<<<<<<<<<<< + * + * + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_arr->__pyx_vtab)->write_handle(__pyx_v_arr, __pyx_v_f); + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("_cdec_sa.Precomputation.write_map", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_arr); + __Pyx_XDECREF(__pyx_v_pattern); + __Pyx_XDECREF(__pyx_v_val); + __Pyx_XDECREF(__pyx_v_word_id); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":260 + * + * + * cdef read_map(self, FILE* f): # <<<<<<<<<<<<<< + * cdef int i, j, k, word_id, N + * cdef IntList arr + */ + +static PyObject *__pyx_f_8_cdec_sa_14Precomputation_read_map(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, FILE *__pyx_v_f) { + int __pyx_v_i; + CYTHON_UNUSED int __pyx_v_j; + CYTHON_UNUSED int __pyx_v_k; + int __pyx_v_word_id; + int __pyx_v_N; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_arr = 0; + PyObject *__pyx_v_m = NULL; + PyObject *__pyx_v_key = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_map", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":264 + * cdef IntList arr + * + * m = {} # <<<<<<<<<<<<<< + * fread(&(N), sizeof(int), 1, f) + * for j from 0 <= j < N: + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 264; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_v_m = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":265 + * + * m = {} + * fread(&(N), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * for j from 0 <= j < N: + * fread(&(i), sizeof(int), 1, f) + */ + fread((&__pyx_v_N), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":266 + * m = {} + * fread(&(N), sizeof(int), 1, f) + * for j from 0 <= j < N: # <<<<<<<<<<<<<< + * fread(&(i), sizeof(int), 1, f) + * key = () + */ + __pyx_t_2 = __pyx_v_N; + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_2; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":267 + * fread(&(N), sizeof(int), 1, f) + * for j from 0 <= j < N: + * fread(&(i), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * key = () + * for k from 0 <= k < i: + */ + fread((&__pyx_v_i), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":268 + * for j from 0 <= j < N: + * fread(&(i), sizeof(int), 1, f) + * key = () # <<<<<<<<<<<<<< + * for k from 0 <= k < i: + * fread(&(word_id), sizeof(int), 1, f) + */ + __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); + __Pyx_XDECREF(((PyObject *)__pyx_v_key)); + __pyx_v_key = __pyx_empty_tuple; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":269 + * fread(&(i), sizeof(int), 1, f) + * key = () + * for k from 0 <= k < i: # <<<<<<<<<<<<<< + * fread(&(word_id), sizeof(int), 1, f) + * key = key + (word_id,) + */ + __pyx_t_3 = __pyx_v_i; + for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_3; __pyx_v_k++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":270 + * key = () + * for k from 0 <= k < i: + * fread(&(word_id), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * key = key + (word_id,) + * arr = IntList() + */ + fread((&__pyx_v_word_id), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":271 + * for k from 0 <= k < i: + * fread(&(word_id), sizeof(int), 1, f) + * key = key + (word_id,) # <<<<<<<<<<<<<< + * arr = IntList() + * arr.read_handle(f) + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_word_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Add(((PyObject *)__pyx_v_key), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_key)); + __pyx_v_key = __pyx_t_1; + __pyx_t_1 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":272 + * fread(&(word_id), sizeof(int), 1, f) + * key = key + (word_id,) + * arr = IntList() # <<<<<<<<<<<<<< + * arr.read_handle(f) + * m[key] = arr + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 272; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF(((PyObject *)__pyx_v_arr)); + __pyx_v_arr = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":273 + * key = key + (word_id,) + * arr = IntList() + * arr.read_handle(f) # <<<<<<<<<<<<<< + * m[key] = arr + * return m + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_arr->__pyx_vtab)->read_handle(__pyx_v_arr, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":274 + * arr = IntList() + * arr.read_handle(f) + * m[key] = arr # <<<<<<<<<<<<<< + * return m + * + */ + if (PyDict_SetItem(((PyObject *)__pyx_v_m), ((PyObject *)__pyx_v_key), ((PyObject *)__pyx_v_arr)) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":275 + * arr.read_handle(f) + * m[key] = arr + * return m # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_m)); + __pyx_r = ((PyObject *)__pyx_v_m); + 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_4); + __Pyx_AddTraceback("_cdec_sa.Precomputation.read_map", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_arr); + __Pyx_XDECREF(__pyx_v_m); + __Pyx_XDECREF(__pyx_v_key); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_14Precomputation_7precompute(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_14Precomputation_7precompute(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_stats = 0; + struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_sarray = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__stats,&__pyx_n_s__sarray,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("precompute (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__stats); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sarray); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("precompute", 1, 2, 2, 1); {__pyx_filename = __pyx_f[11]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "precompute") < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_stats = values[0]; + __pyx_v_sarray = ((struct __pyx_obj_8_cdec_sa_SuffixArray *)values[1]); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("precompute", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[11]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.Precomputation.precompute", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_sarray), __pyx_ptype_8_cdec_sa_SuffixArray, 1, "sarray", 0))) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_8_cdec_sa_14Precomputation_6precompute(((struct __pyx_obj_8_cdec_sa_Precomputation *)__pyx_v_self), __pyx_v_stats, __pyx_v_sarray); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":278 + * + * + * def precompute(self, stats, SuffixArray sarray): # <<<<<<<<<<<<<< + * cdef int i, l, N, max_pattern_len, i1, l1, i2, l2, i3, l3, ptr1, ptr2, ptr3, is_super, sent_count, max_rank + * cdef DataArray darray = sarray.darray + */ + +static PyObject *__pyx_pf_8_cdec_sa_14Precomputation_6precompute(struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, PyObject *__pyx_v_stats, struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_sarray) { + int __pyx_v_i; + int __pyx_v_l; + int __pyx_v_N; + int __pyx_v_max_pattern_len; + int __pyx_v_i1; + int __pyx_v_l1; + int __pyx_v_i2; + int __pyx_v_l2; + int __pyx_v_i3; + int __pyx_v_l3; + int __pyx_v_ptr1; + int __pyx_v_ptr2; + int __pyx_v_ptr3; + int __pyx_v_is_super; + int __pyx_v_sent_count; + int __pyx_v_max_rank; + struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_darray = 0; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_data = 0; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_queue = 0; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_cost_by_rank = 0; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_count_by_rank = 0; + struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_frequent_patterns = 0; + struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_super_frequent_patterns = 0; + struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_collocations = 0; + struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node; + PyObject *__pyx_v_I_set = NULL; + PyObject *__pyx_v_J_set = NULL; + PyObject *__pyx_v_J2_set = NULL; + PyObject *__pyx_v_IJ_set = NULL; + PyObject *__pyx_v_pattern_rank = NULL; + float __pyx_v_start_time; + PyObject *__pyx_v_rank = NULL; + CYTHON_UNUSED PyObject *__pyx_v__ = NULL; + PyObject *__pyx_v_phrase = NULL; + int __pyx_v_sa_word_id; + PyObject *__pyx_v_x = NULL; + PyObject *__pyx_v_pattern1 = NULL; + PyObject *__pyx_v_pattern2 = NULL; + PyObject *__pyx_v_combined_pattern = NULL; + PyObject *__pyx_v_pattern = NULL; + PyObject *__pyx_v_arr = NULL; + PyObject *__pyx_v_s = NULL; + PyObject *__pyx_v_word_id = NULL; + PyObject *__pyx_v_chunk = NULL; + PyObject *__pyx_v_arity = NULL; + PyObject *__pyx_v_cumul_cost = NULL; + PyObject *__pyx_v_cumul_count = NULL; + PyObject *__pyx_v_num_found_patterns = NULL; + float __pyx_v_stop_time; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *(*__pyx_t_4)(PyObject *); + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *(*__pyx_t_10)(PyObject *); + int __pyx_t_11; + Py_ssize_t __pyx_t_12; + int __pyx_t_13; + Py_ssize_t __pyx_t_14; + int __pyx_t_15; + int __pyx_t_16; + int __pyx_t_17; + int __pyx_t_18; + int __pyx_t_19; + PyObject *(*__pyx_t_20)(PyObject *); + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("precompute", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":280 + * def precompute(self, stats, SuffixArray sarray): + * cdef int i, l, N, max_pattern_len, i1, l1, i2, l2, i3, l3, ptr1, ptr2, ptr3, is_super, sent_count, max_rank + * cdef DataArray darray = sarray.darray # <<<<<<<<<<<<<< + * cdef IntList data, queue, cost_by_rank, count_by_rank + * cdef TrieMap frequent_patterns, super_frequent_patterns, collocations + */ + __Pyx_INCREF(((PyObject *)__pyx_v_sarray->darray)); + __pyx_v_darray = __pyx_v_sarray->darray; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":285 + * cdef _Trie_Node* node + * + * data = darray.data # <<<<<<<<<<<<<< + * + * frequent_patterns = TrieMap(len(darray.id2word)) + */ + __Pyx_INCREF(((PyObject *)__pyx_v_darray->data)); + __pyx_v_data = __pyx_v_darray->data; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":287 + * data = darray.data + * + * frequent_patterns = TrieMap(len(darray.id2word)) # <<<<<<<<<<<<<< + * super_frequent_patterns = TrieMap(len(darray.id2word)) + * collocations = TrieMap(len(darray.id2word)) + */ + __pyx_t_1 = __pyx_v_darray->id2word; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_TrieMap)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_v_frequent_patterns = ((struct __pyx_obj_8_cdec_sa_TrieMap *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":288 + * + * frequent_patterns = TrieMap(len(darray.id2word)) + * super_frequent_patterns = TrieMap(len(darray.id2word)) # <<<<<<<<<<<<<< + * collocations = TrieMap(len(darray.id2word)) + * + */ + __pyx_t_1 = __pyx_v_darray->id2word; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_TrieMap)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_v_super_frequent_patterns = ((struct __pyx_obj_8_cdec_sa_TrieMap *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":289 + * frequent_patterns = TrieMap(len(darray.id2word)) + * super_frequent_patterns = TrieMap(len(darray.id2word)) + * collocations = TrieMap(len(darray.id2word)) # <<<<<<<<<<<<<< + * + * I_set = set() + */ + __pyx_t_1 = __pyx_v_darray->id2word; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_TrieMap)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_v_collocations = ((struct __pyx_obj_8_cdec_sa_TrieMap *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":291 + * collocations = TrieMap(len(darray.id2word)) + * + * I_set = set() # <<<<<<<<<<<<<< + * J_set = set() + * J2_set = set() + */ + __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_v_I_set = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":292 + * + * I_set = set() + * J_set = set() # <<<<<<<<<<<<<< + * J2_set = set() + * IJ_set = set() + */ + __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_v_J_set = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":293 + * I_set = set() + * J_set = set() + * J2_set = set() # <<<<<<<<<<<<<< + * IJ_set = set() + * pattern_rank = {} + */ + __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_v_J2_set = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":294 + * J_set = set() + * J2_set = set() + * IJ_set = set() # <<<<<<<<<<<<<< + * pattern_rank = {} + * + */ + __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_v_IJ_set = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":295 + * J2_set = set() + * IJ_set = set() + * pattern_rank = {} # <<<<<<<<<<<<<< + * + * logger.info("Precomputing frequent intersections") + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_v_pattern_rank = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":297 + * pattern_rank = {} + * + * logger.info("Precomputing frequent intersections") # <<<<<<<<<<<<<< + * cdef float start_time = monitor_cpu() + * + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__info); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_71), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":298 + * + * logger.info("Precomputing frequent intersections") + * cdef float start_time = monitor_cpu() # <<<<<<<<<<<<<< + * + * max_pattern_len = 0 + */ + __pyx_v_start_time = __pyx_f_8_cdec_sa_monitor_cpu(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":300 + * cdef float start_time = monitor_cpu() + * + * max_pattern_len = 0 # <<<<<<<<<<<<<< + * for rank, (_, _, phrase) in enumerate(stats): + * if rank >= self.precompute_rank: + */ + __pyx_v_max_pattern_len = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":301 + * + * max_pattern_len = 0 + * for rank, (_, _, phrase) in enumerate(stats): # <<<<<<<<<<<<<< + * if rank >= self.precompute_rank: + * break + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_1 = __pyx_int_0; + if (PyList_CheckExact(__pyx_v_stats) || PyTuple_CheckExact(__pyx_v_stats)) { + __pyx_t_3 = __pyx_v_stats; __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_stats); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; + } + for (;;) { + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_3)) break; + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + } else { + __pyx_t_5 = __pyx_t_4(__pyx_t_3); + if (unlikely(!__pyx_t_5)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_5); + } + if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) { + PyObject* sequence = __pyx_t_5; + if (likely(PyTuple_CheckExact(sequence))) { + if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { + if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[11]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 2); + } else { + if (unlikely(PyList_GET_SIZE(sequence) != 3)) { + if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[11]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_6 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + __pyx_t_8 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_9 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; + index = 0; __pyx_t_6 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + index = 1; __pyx_t_7 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_7)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + index = 2; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 3) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L6_unpacking_done; + __pyx_L5_unpacking_failed:; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[11]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L6_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v__); + __pyx_v__ = __pyx_t_6; + __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_v__); + __pyx_v__ = __pyx_t_7; + __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_v_phrase); + __pyx_v_phrase = __pyx_t_8; + __pyx_t_8 = 0; + __Pyx_INCREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_rank); + __pyx_v_rank = __pyx_t_1; + __pyx_t_5 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); + __pyx_t_1 = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":302 + * max_pattern_len = 0 + * for rank, (_, _, phrase) in enumerate(stats): + * if rank >= self.precompute_rank: # <<<<<<<<<<<<<< + * break + * max_pattern_len = max(max_pattern_len, len(phrase)) + */ + __pyx_t_5 = PyInt_FromLong(__pyx_v_self->precompute_rank); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = PyObject_RichCompare(__pyx_v_rank, __pyx_t_5, Py_GE); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":303 + * for rank, (_, _, phrase) in enumerate(stats): + * if rank >= self.precompute_rank: + * break # <<<<<<<<<<<<<< + * max_pattern_len = max(max_pattern_len, len(phrase)) + * frequent_patterns.insert(phrase) + */ + goto __pyx_L4_break; + goto __pyx_L7; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":304 + * if rank >= self.precompute_rank: + * break + * max_pattern_len = max(max_pattern_len, len(phrase)) # <<<<<<<<<<<<<< + * frequent_patterns.insert(phrase) + * I_set.add(phrase) + */ + __pyx_t_12 = PyObject_Length(__pyx_v_phrase); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_13 = __pyx_v_max_pattern_len; + if ((__pyx_t_12 > __pyx_t_13)) { + __pyx_t_14 = __pyx_t_12; + } else { + __pyx_t_14 = __pyx_t_13; + } + __pyx_v_max_pattern_len = __pyx_t_14; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":305 + * break + * max_pattern_len = max(max_pattern_len, len(phrase)) + * frequent_patterns.insert(phrase) # <<<<<<<<<<<<<< + * I_set.add(phrase) + * pattern_rank[phrase] = rank + */ + __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_v_frequent_patterns), __pyx_n_s__insert); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_phrase); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_phrase); + __Pyx_GIVEREF(__pyx_v_phrase); + __pyx_t_7 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":306 + * max_pattern_len = max(max_pattern_len, len(phrase)) + * frequent_patterns.insert(phrase) + * I_set.add(phrase) # <<<<<<<<<<<<<< + * pattern_rank[phrase] = rank + * if rank < self.precompute_secondary_rank: + */ + __pyx_t_15 = PySet_Add(__pyx_v_I_set, __pyx_v_phrase); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":307 + * frequent_patterns.insert(phrase) + * I_set.add(phrase) + * pattern_rank[phrase] = rank # <<<<<<<<<<<<<< + * if rank < self.precompute_secondary_rank: + * super_frequent_patterns.insert(phrase) + */ + if (PyDict_SetItem(((PyObject *)__pyx_v_pattern_rank), __pyx_v_phrase, __pyx_v_rank) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":308 + * I_set.add(phrase) + * pattern_rank[phrase] = rank + * if rank < self.precompute_secondary_rank: # <<<<<<<<<<<<<< + * super_frequent_patterns.insert(phrase) + * J_set.add(phrase) + */ + __pyx_t_7 = PyInt_FromLong(__pyx_v_self->precompute_secondary_rank); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_rank, __pyx_t_7, Py_LT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":309 + * pattern_rank[phrase] = rank + * if rank < self.precompute_secondary_rank: + * super_frequent_patterns.insert(phrase) # <<<<<<<<<<<<<< + * J_set.add(phrase) + * + */ + __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_super_frequent_patterns), __pyx_n_s__insert); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_v_phrase); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_phrase); + __Pyx_GIVEREF(__pyx_v_phrase); + __pyx_t_8 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":310 + * if rank < self.precompute_secondary_rank: + * super_frequent_patterns.insert(phrase) + * J_set.add(phrase) # <<<<<<<<<<<<<< + * + * queue = IntList(increment=1000) + */ + __pyx_t_15 = PySet_Add(__pyx_v_J_set, __pyx_v_phrase); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L8; + } + __pyx_L8:; + } + __pyx_L4_break:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":312 + * J_set.add(phrase) + * + * queue = IntList(increment=1000) # <<<<<<<<<<<<<< + * + * logger.info(" Computing inverted indexes...") + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 312; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__increment), __pyx_int_1000) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 312; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 312; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_v_queue = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":314 + * queue = IntList(increment=1000) + * + * logger.info(" Computing inverted indexes...") # <<<<<<<<<<<<<< + * N = len(data) + * for i from 0 <= i < N: + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_73), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":315 + * + * logger.info(" Computing inverted indexes...") + * N = len(data) # <<<<<<<<<<<<<< + * for i from 0 <= i < N: + * sa_word_id = data.arr[i] + */ + __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_data)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_N = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":316 + * logger.info(" Computing inverted indexes...") + * N = len(data) + * for i from 0 <= i < N: # <<<<<<<<<<<<<< + * sa_word_id = data.arr[i] + * if sa_word_id == 1: + */ + __pyx_t_13 = __pyx_v_N; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_13; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":317 + * N = len(data) + * for i from 0 <= i < N: + * sa_word_id = data.arr[i] # <<<<<<<<<<<<<< + * if sa_word_id == 1: + * queue._append(-1) + */ + __pyx_v_sa_word_id = (__pyx_v_data->arr[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":318 + * for i from 0 <= i < N: + * sa_word_id = data.arr[i] + * if sa_word_id == 1: # <<<<<<<<<<<<<< + * queue._append(-1) + * else: + */ + __pyx_t_11 = (__pyx_v_sa_word_id == 1); + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":319 + * sa_word_id = data.arr[i] + * if sa_word_id == 1: + * queue._append(-1) # <<<<<<<<<<<<<< + * else: + * for l from 1 <= l <= max_pattern_len: + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_queue->__pyx_vtab)->_append(__pyx_v_queue, -1); + goto __pyx_L11; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":321 + * queue._append(-1) + * else: + * for l from 1 <= l <= max_pattern_len: # <<<<<<<<<<<<<< + * node = frequent_patterns._contains(data.arr+i, l) + * if node == NULL: + */ + __pyx_t_16 = __pyx_v_max_pattern_len; + for (__pyx_v_l = 1; __pyx_v_l <= __pyx_t_16; __pyx_v_l++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":322 + * else: + * for l from 1 <= l <= max_pattern_len: + * node = frequent_patterns._contains(data.arr+i, l) # <<<<<<<<<<<<<< + * if node == NULL: + * break + */ + __pyx_v_node = ((struct __pyx_vtabstruct_8_cdec_sa_TrieMap *)__pyx_v_frequent_patterns->__pyx_vtab)->_contains(__pyx_v_frequent_patterns, (__pyx_v_data->arr + __pyx_v_i), __pyx_v_l); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":323 + * for l from 1 <= l <= max_pattern_len: + * node = frequent_patterns._contains(data.arr+i, l) + * if node == NULL: # <<<<<<<<<<<<<< + * break + * queue._append(i) + */ + __pyx_t_11 = (__pyx_v_node == NULL); + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":324 + * node = frequent_patterns._contains(data.arr+i, l) + * if node == NULL: + * break # <<<<<<<<<<<<<< + * queue._append(i) + * queue._append(l) + */ + goto __pyx_L13_break; + goto __pyx_L14; + } + __pyx_L14:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":325 + * if node == NULL: + * break + * queue._append(i) # <<<<<<<<<<<<<< + * queue._append(l) + * trie_node_data_append(node, i) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_queue->__pyx_vtab)->_append(__pyx_v_queue, __pyx_v_i); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":326 + * break + * queue._append(i) + * queue._append(l) # <<<<<<<<<<<<<< + * trie_node_data_append(node, i) + * + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_queue->__pyx_vtab)->_append(__pyx_v_queue, __pyx_v_l); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":327 + * queue._append(i) + * queue._append(l) + * trie_node_data_append(node, i) # <<<<<<<<<<<<<< + * + * logger.info(" Computing collocations...") + */ + __pyx_t_3 = __pyx_f_8_cdec_sa_trie_node_data_append(__pyx_v_node, __pyx_v_i); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __pyx_L13_break:; + } + __pyx_L11:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":329 + * trie_node_data_append(node, i) + * + * logger.info(" Computing collocations...") # <<<<<<<<<<<<<< + * N = len(queue) + * ptr1 = 0 + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_75), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":330 + * + * logger.info(" Computing collocations...") + * N = len(queue) # <<<<<<<<<<<<<< + * ptr1 = 0 + * sent_count = 0 + */ + __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_queue)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_N = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":331 + * logger.info(" Computing collocations...") + * N = len(queue) + * ptr1 = 0 # <<<<<<<<<<<<<< + * sent_count = 0 + * while ptr1 < N: # main loop + */ + __pyx_v_ptr1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":332 + * N = len(queue) + * ptr1 = 0 + * sent_count = 0 # <<<<<<<<<<<<<< + * while ptr1 < N: # main loop + * i1 = queue.arr[ptr1] + */ + __pyx_v_sent_count = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":333 + * ptr1 = 0 + * sent_count = 0 + * while ptr1 < N: # main loop # <<<<<<<<<<<<<< + * i1 = queue.arr[ptr1] + * if i1 > -1: + */ + while (1) { + __pyx_t_11 = (__pyx_v_ptr1 < __pyx_v_N); + if (!__pyx_t_11) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":334 + * sent_count = 0 + * while ptr1 < N: # main loop + * i1 = queue.arr[ptr1] # <<<<<<<<<<<<<< + * if i1 > -1: + * l1 = queue.arr[ptr1+1] + */ + __pyx_v_i1 = (__pyx_v_queue->arr[__pyx_v_ptr1]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":335 + * while ptr1 < N: # main loop + * i1 = queue.arr[ptr1] + * if i1 > -1: # <<<<<<<<<<<<<< + * l1 = queue.arr[ptr1+1] + * ptr2 = ptr1 + 2 + */ + __pyx_t_11 = (__pyx_v_i1 > -1); + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":336 + * i1 = queue.arr[ptr1] + * if i1 > -1: + * l1 = queue.arr[ptr1+1] # <<<<<<<<<<<<<< + * ptr2 = ptr1 + 2 + * while ptr2 < N: + */ + __pyx_v_l1 = (__pyx_v_queue->arr[(__pyx_v_ptr1 + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":337 + * if i1 > -1: + * l1 = queue.arr[ptr1+1] + * ptr2 = ptr1 + 2 # <<<<<<<<<<<<<< + * while ptr2 < N: + * i2 = queue.arr[ptr2] + */ + __pyx_v_ptr2 = (__pyx_v_ptr1 + 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":338 + * l1 = queue.arr[ptr1+1] + * ptr2 = ptr1 + 2 + * while ptr2 < N: # <<<<<<<<<<<<<< + * i2 = queue.arr[ptr2] + * if i2 == -1 or i2 - i1 >= self.train_max_initial_size: + */ + while (1) { + __pyx_t_11 = (__pyx_v_ptr2 < __pyx_v_N); + if (!__pyx_t_11) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":339 + * ptr2 = ptr1 + 2 + * while ptr2 < N: + * i2 = queue.arr[ptr2] # <<<<<<<<<<<<<< + * if i2 == -1 or i2 - i1 >= self.train_max_initial_size: + * break + */ + __pyx_v_i2 = (__pyx_v_queue->arr[__pyx_v_ptr2]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":340 + * while ptr2 < N: + * i2 = queue.arr[ptr2] + * if i2 == -1 or i2 - i1 >= self.train_max_initial_size: # <<<<<<<<<<<<<< + * break + * l2 = queue.arr[ptr2+1] + */ + __pyx_t_11 = (__pyx_v_i2 == -1); + if (!__pyx_t_11) { + __pyx_t_17 = ((__pyx_v_i2 - __pyx_v_i1) >= __pyx_v_self->train_max_initial_size); + __pyx_t_18 = __pyx_t_17; + } else { + __pyx_t_18 = __pyx_t_11; + } + if (__pyx_t_18) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":341 + * i2 = queue.arr[ptr2] + * if i2 == -1 or i2 - i1 >= self.train_max_initial_size: + * break # <<<<<<<<<<<<<< + * l2 = queue.arr[ptr2+1] + * if (i2 - i1 - l1 >= self.train_min_gap_size and + */ + goto __pyx_L19_break; + goto __pyx_L20; + } + __pyx_L20:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":342 + * if i2 == -1 or i2 - i1 >= self.train_max_initial_size: + * break + * l2 = queue.arr[ptr2+1] # <<<<<<<<<<<<<< + * if (i2 - i1 - l1 >= self.train_min_gap_size and + * i2 + l2 - i1 <= self.train_max_initial_size and + */ + __pyx_v_l2 = (__pyx_v_queue->arr[(__pyx_v_ptr2 + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":343 + * break + * l2 = queue.arr[ptr2+1] + * if (i2 - i1 - l1 >= self.train_min_gap_size and # <<<<<<<<<<<<<< + * i2 + l2 - i1 <= self.train_max_initial_size and + * l1+l2+1 <= self.max_length): + */ + __pyx_t_18 = (((__pyx_v_i2 - __pyx_v_i1) - __pyx_v_l1) >= __pyx_v_self->train_min_gap_size); + if (__pyx_t_18) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":344 + * l2 = queue.arr[ptr2+1] + * if (i2 - i1 - l1 >= self.train_min_gap_size and + * i2 + l2 - i1 <= self.train_max_initial_size and # <<<<<<<<<<<<<< + * l1+l2+1 <= self.max_length): + * node = collocations._insert(data.arr+i1, l1) + */ + __pyx_t_11 = (((__pyx_v_i2 + __pyx_v_l2) - __pyx_v_i1) <= __pyx_v_self->train_max_initial_size); + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":345 + * if (i2 - i1 - l1 >= self.train_min_gap_size and + * i2 + l2 - i1 <= self.train_max_initial_size and + * l1+l2+1 <= self.max_length): # <<<<<<<<<<<<<< + * node = collocations._insert(data.arr+i1, l1) + * node = trie_insert(node, -1) + */ + __pyx_t_17 = (((__pyx_v_l1 + __pyx_v_l2) + 1) <= __pyx_v_self->max_length); + __pyx_t_19 = __pyx_t_17; + } else { + __pyx_t_19 = __pyx_t_11; + } + __pyx_t_11 = __pyx_t_19; + } else { + __pyx_t_11 = __pyx_t_18; + } + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":346 + * i2 + l2 - i1 <= self.train_max_initial_size and + * l1+l2+1 <= self.max_length): + * node = collocations._insert(data.arr+i1, l1) # <<<<<<<<<<<<<< + * node = trie_insert(node, -1) + * for i from i2 <= i < i2+l2: + */ + __pyx_v_node = ((struct __pyx_vtabstruct_8_cdec_sa_TrieMap *)__pyx_v_collocations->__pyx_vtab)->_insert(__pyx_v_collocations, (__pyx_v_data->arr + __pyx_v_i1), __pyx_v_l1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":347 + * l1+l2+1 <= self.max_length): + * node = collocations._insert(data.arr+i1, l1) + * node = trie_insert(node, -1) # <<<<<<<<<<<<<< + * for i from i2 <= i < i2+l2: + * node = trie_insert(node, data.arr[i]) + */ + __pyx_v_node = __pyx_f_8_cdec_sa_trie_insert(__pyx_v_node, -1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":348 + * node = collocations._insert(data.arr+i1, l1) + * node = trie_insert(node, -1) + * for i from i2 <= i < i2+l2: # <<<<<<<<<<<<<< + * node = trie_insert(node, data.arr[i]) + * trie_node_data_append(node, i1) + */ + __pyx_t_13 = (__pyx_v_i2 + __pyx_v_l2); + for (__pyx_v_i = __pyx_v_i2; __pyx_v_i < __pyx_t_13; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":349 + * node = trie_insert(node, -1) + * for i from i2 <= i < i2+l2: + * node = trie_insert(node, data.arr[i]) # <<<<<<<<<<<<<< + * trie_node_data_append(node, i1) + * trie_node_data_append(node, i2) + */ + __pyx_v_node = __pyx_f_8_cdec_sa_trie_insert(__pyx_v_node, (__pyx_v_data->arr[__pyx_v_i])); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":350 + * for i from i2 <= i < i2+l2: + * node = trie_insert(node, data.arr[i]) + * trie_node_data_append(node, i1) # <<<<<<<<<<<<<< + * trie_node_data_append(node, i2) + * if super_frequent_patterns._contains(data.arr+i2, l2) != NULL: + */ + __pyx_t_3 = __pyx_f_8_cdec_sa_trie_node_data_append(__pyx_v_node, __pyx_v_i1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":351 + * node = trie_insert(node, data.arr[i]) + * trie_node_data_append(node, i1) + * trie_node_data_append(node, i2) # <<<<<<<<<<<<<< + * if super_frequent_patterns._contains(data.arr+i2, l2) != NULL: + * if super_frequent_patterns._contains(data.arr+i1, l1) != NULL: + */ + __pyx_t_3 = __pyx_f_8_cdec_sa_trie_node_data_append(__pyx_v_node, __pyx_v_i2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":352 + * trie_node_data_append(node, i1) + * trie_node_data_append(node, i2) + * if super_frequent_patterns._contains(data.arr+i2, l2) != NULL: # <<<<<<<<<<<<<< + * if super_frequent_patterns._contains(data.arr+i1, l1) != NULL: + * is_super = 1 + */ + __pyx_t_11 = (((struct __pyx_vtabstruct_8_cdec_sa_TrieMap *)__pyx_v_super_frequent_patterns->__pyx_vtab)->_contains(__pyx_v_super_frequent_patterns, (__pyx_v_data->arr + __pyx_v_i2), __pyx_v_l2) != NULL); + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":353 + * trie_node_data_append(node, i2) + * if super_frequent_patterns._contains(data.arr+i2, l2) != NULL: + * if super_frequent_patterns._contains(data.arr+i1, l1) != NULL: # <<<<<<<<<<<<<< + * is_super = 1 + * else: + */ + __pyx_t_11 = (((struct __pyx_vtabstruct_8_cdec_sa_TrieMap *)__pyx_v_super_frequent_patterns->__pyx_vtab)->_contains(__pyx_v_super_frequent_patterns, (__pyx_v_data->arr + __pyx_v_i1), __pyx_v_l1) != NULL); + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":354 + * if super_frequent_patterns._contains(data.arr+i2, l2) != NULL: + * if super_frequent_patterns._contains(data.arr+i1, l1) != NULL: + * is_super = 1 # <<<<<<<<<<<<<< + * else: + * is_super = 0 + */ + __pyx_v_is_super = 1; + goto __pyx_L25; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":356 + * is_super = 1 + * else: + * is_super = 0 # <<<<<<<<<<<<<< + * ptr3 = ptr2 + 2 + * while ptr3 < N: + */ + __pyx_v_is_super = 0; + } + __pyx_L25:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":357 + * else: + * is_super = 0 + * ptr3 = ptr2 + 2 # <<<<<<<<<<<<<< + * while ptr3 < N: + * i3 = queue.arr[ptr3] + */ + __pyx_v_ptr3 = (__pyx_v_ptr2 + 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":358 + * is_super = 0 + * ptr3 = ptr2 + 2 + * while ptr3 < N: # <<<<<<<<<<<<<< + * i3 = queue.arr[ptr3] + * if i3 == -1 or i3 - i1 >= self.train_max_initial_size: + */ + while (1) { + __pyx_t_11 = (__pyx_v_ptr3 < __pyx_v_N); + if (!__pyx_t_11) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":359 + * ptr3 = ptr2 + 2 + * while ptr3 < N: + * i3 = queue.arr[ptr3] # <<<<<<<<<<<<<< + * if i3 == -1 or i3 - i1 >= self.train_max_initial_size: + * break + */ + __pyx_v_i3 = (__pyx_v_queue->arr[__pyx_v_ptr3]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":360 + * while ptr3 < N: + * i3 = queue.arr[ptr3] + * if i3 == -1 or i3 - i1 >= self.train_max_initial_size: # <<<<<<<<<<<<<< + * break + * l3 = queue.arr[ptr3+1] + */ + __pyx_t_11 = (__pyx_v_i3 == -1); + if (!__pyx_t_11) { + __pyx_t_18 = ((__pyx_v_i3 - __pyx_v_i1) >= __pyx_v_self->train_max_initial_size); + __pyx_t_19 = __pyx_t_18; + } else { + __pyx_t_19 = __pyx_t_11; + } + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":361 + * i3 = queue.arr[ptr3] + * if i3 == -1 or i3 - i1 >= self.train_max_initial_size: + * break # <<<<<<<<<<<<<< + * l3 = queue.arr[ptr3+1] + * if (i3 - i2 - l2 >= self.train_min_gap_size and + */ + goto __pyx_L27_break; + goto __pyx_L28; + } + __pyx_L28:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":362 + * if i3 == -1 or i3 - i1 >= self.train_max_initial_size: + * break + * l3 = queue.arr[ptr3+1] # <<<<<<<<<<<<<< + * if (i3 - i2 - l2 >= self.train_min_gap_size and + * i3 + l3 - i1 <= self.train_max_initial_size and + */ + __pyx_v_l3 = (__pyx_v_queue->arr[(__pyx_v_ptr3 + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":363 + * break + * l3 = queue.arr[ptr3+1] + * if (i3 - i2 - l2 >= self.train_min_gap_size and # <<<<<<<<<<<<<< + * i3 + l3 - i1 <= self.train_max_initial_size and + * l1+l2+l3+2 <= self.max_length): + */ + __pyx_t_19 = (((__pyx_v_i3 - __pyx_v_i2) - __pyx_v_l2) >= __pyx_v_self->train_min_gap_size); + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":364 + * l3 = queue.arr[ptr3+1] + * if (i3 - i2 - l2 >= self.train_min_gap_size and + * i3 + l3 - i1 <= self.train_max_initial_size and # <<<<<<<<<<<<<< + * l1+l2+l3+2 <= self.max_length): + * if is_super or super_frequent_patterns._contains(data.arr+i3, l3) != NULL: + */ + __pyx_t_11 = (((__pyx_v_i3 + __pyx_v_l3) - __pyx_v_i1) <= __pyx_v_self->train_max_initial_size); + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":365 + * if (i3 - i2 - l2 >= self.train_min_gap_size and + * i3 + l3 - i1 <= self.train_max_initial_size and + * l1+l2+l3+2 <= self.max_length): # <<<<<<<<<<<<<< + * if is_super or super_frequent_patterns._contains(data.arr+i3, l3) != NULL: + * node = collocations._insert(data.arr+i1, l1) + */ + __pyx_t_18 = ((((__pyx_v_l1 + __pyx_v_l2) + __pyx_v_l3) + 2) <= __pyx_v_self->max_length); + __pyx_t_17 = __pyx_t_18; + } else { + __pyx_t_17 = __pyx_t_11; + } + __pyx_t_11 = __pyx_t_17; + } else { + __pyx_t_11 = __pyx_t_19; + } + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":366 + * i3 + l3 - i1 <= self.train_max_initial_size and + * l1+l2+l3+2 <= self.max_length): + * if is_super or super_frequent_patterns._contains(data.arr+i3, l3) != NULL: # <<<<<<<<<<<<<< + * node = collocations._insert(data.arr+i1, l1) + * node = trie_insert(node, -1) + */ + if (!__pyx_v_is_super) { + __pyx_t_11 = (((struct __pyx_vtabstruct_8_cdec_sa_TrieMap *)__pyx_v_super_frequent_patterns->__pyx_vtab)->_contains(__pyx_v_super_frequent_patterns, (__pyx_v_data->arr + __pyx_v_i3), __pyx_v_l3) != NULL); + __pyx_t_19 = __pyx_t_11; + } else { + __pyx_t_19 = __pyx_v_is_super; + } + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":367 + * l1+l2+l3+2 <= self.max_length): + * if is_super or super_frequent_patterns._contains(data.arr+i3, l3) != NULL: + * node = collocations._insert(data.arr+i1, l1) # <<<<<<<<<<<<<< + * node = trie_insert(node, -1) + * for i from i2 <= i < i2+l2: + */ + __pyx_v_node = ((struct __pyx_vtabstruct_8_cdec_sa_TrieMap *)__pyx_v_collocations->__pyx_vtab)->_insert(__pyx_v_collocations, (__pyx_v_data->arr + __pyx_v_i1), __pyx_v_l1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":368 + * if is_super or super_frequent_patterns._contains(data.arr+i3, l3) != NULL: + * node = collocations._insert(data.arr+i1, l1) + * node = trie_insert(node, -1) # <<<<<<<<<<<<<< + * for i from i2 <= i < i2+l2: + * node = trie_insert(node, data.arr[i]) + */ + __pyx_v_node = __pyx_f_8_cdec_sa_trie_insert(__pyx_v_node, -1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":369 + * node = collocations._insert(data.arr+i1, l1) + * node = trie_insert(node, -1) + * for i from i2 <= i < i2+l2: # <<<<<<<<<<<<<< + * node = trie_insert(node, data.arr[i]) + * node = trie_insert(node, -1) + */ + __pyx_t_13 = (__pyx_v_i2 + __pyx_v_l2); + for (__pyx_v_i = __pyx_v_i2; __pyx_v_i < __pyx_t_13; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":370 + * node = trie_insert(node, -1) + * for i from i2 <= i < i2+l2: + * node = trie_insert(node, data.arr[i]) # <<<<<<<<<<<<<< + * node = trie_insert(node, -1) + * for i from i3 <= i < i3+l3: + */ + __pyx_v_node = __pyx_f_8_cdec_sa_trie_insert(__pyx_v_node, (__pyx_v_data->arr[__pyx_v_i])); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":371 + * for i from i2 <= i < i2+l2: + * node = trie_insert(node, data.arr[i]) + * node = trie_insert(node, -1) # <<<<<<<<<<<<<< + * for i from i3 <= i < i3+l3: + * node = trie_insert(node, data.arr[i]) + */ + __pyx_v_node = __pyx_f_8_cdec_sa_trie_insert(__pyx_v_node, -1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":372 + * node = trie_insert(node, data.arr[i]) + * node = trie_insert(node, -1) + * for i from i3 <= i < i3+l3: # <<<<<<<<<<<<<< + * node = trie_insert(node, data.arr[i]) + * trie_node_data_append(node, i1) + */ + __pyx_t_13 = (__pyx_v_i3 + __pyx_v_l3); + for (__pyx_v_i = __pyx_v_i3; __pyx_v_i < __pyx_t_13; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":373 + * node = trie_insert(node, -1) + * for i from i3 <= i < i3+l3: + * node = trie_insert(node, data.arr[i]) # <<<<<<<<<<<<<< + * trie_node_data_append(node, i1) + * trie_node_data_append(node, i2) + */ + __pyx_v_node = __pyx_f_8_cdec_sa_trie_insert(__pyx_v_node, (__pyx_v_data->arr[__pyx_v_i])); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":374 + * for i from i3 <= i < i3+l3: + * node = trie_insert(node, data.arr[i]) + * trie_node_data_append(node, i1) # <<<<<<<<<<<<<< + * trie_node_data_append(node, i2) + * trie_node_data_append(node, i3) + */ + __pyx_t_3 = __pyx_f_8_cdec_sa_trie_node_data_append(__pyx_v_node, __pyx_v_i1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":375 + * node = trie_insert(node, data.arr[i]) + * trie_node_data_append(node, i1) + * trie_node_data_append(node, i2) # <<<<<<<<<<<<<< + * trie_node_data_append(node, i3) + * ptr3 = ptr3 + 2 + */ + __pyx_t_3 = __pyx_f_8_cdec_sa_trie_node_data_append(__pyx_v_node, __pyx_v_i2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":376 + * trie_node_data_append(node, i1) + * trie_node_data_append(node, i2) + * trie_node_data_append(node, i3) # <<<<<<<<<<<<<< + * ptr3 = ptr3 + 2 + * ptr2 = ptr2 + 2 + */ + __pyx_t_3 = __pyx_f_8_cdec_sa_trie_node_data_append(__pyx_v_node, __pyx_v_i3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L30; + } + __pyx_L30:; + goto __pyx_L29; + } + __pyx_L29:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":377 + * trie_node_data_append(node, i2) + * trie_node_data_append(node, i3) + * ptr3 = ptr3 + 2 # <<<<<<<<<<<<<< + * ptr2 = ptr2 + 2 + * ptr1 = ptr1 + 2 + */ + __pyx_v_ptr3 = (__pyx_v_ptr3 + 2); + } + __pyx_L27_break:; + goto __pyx_L24; + } + __pyx_L24:; + goto __pyx_L21; + } + __pyx_L21:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":378 + * trie_node_data_append(node, i3) + * ptr3 = ptr3 + 2 + * ptr2 = ptr2 + 2 # <<<<<<<<<<<<<< + * ptr1 = ptr1 + 2 + * else: + */ + __pyx_v_ptr2 = (__pyx_v_ptr2 + 2); + } + __pyx_L19_break:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":379 + * ptr3 = ptr3 + 2 + * ptr2 = ptr2 + 2 + * ptr1 = ptr1 + 2 # <<<<<<<<<<<<<< + * else: + * sent_count = sent_count + 1 + */ + __pyx_v_ptr1 = (__pyx_v_ptr1 + 2); + goto __pyx_L17; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":381 + * ptr1 = ptr1 + 2 + * else: + * sent_count = sent_count + 1 # <<<<<<<<<<<<<< + * if sent_count % 10000 == 0: + * logger.debug(" %d sentences", sent_count) + */ + __pyx_v_sent_count = (__pyx_v_sent_count + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":382 + * else: + * sent_count = sent_count + 1 + * if sent_count % 10000 == 0: # <<<<<<<<<<<<<< + * logger.debug(" %d sentences", sent_count) + * ptr1 = ptr1 + 1 + */ + __pyx_t_19 = (__Pyx_mod_long(__pyx_v_sent_count, 10000) == 0); + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":383 + * sent_count = sent_count + 1 + * if sent_count % 10000 == 0: + * logger.debug(" %d sentences", sent_count) # <<<<<<<<<<<<<< + * ptr1 = ptr1 + 1 + * + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__debug); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromLong(__pyx_v_sent_count); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_76)); + PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_kp_s_76)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_76)); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L35; + } + __pyx_L35:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":384 + * if sent_count % 10000 == 0: + * logger.debug(" %d sentences", sent_count) + * ptr1 = ptr1 + 1 # <<<<<<<<<<<<<< + * + * self.precomputed_collocations = collocations.toMap(False) + */ + __pyx_v_ptr1 = (__pyx_v_ptr1 + 1); + } + __pyx_L17:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":386 + * ptr1 = ptr1 + 1 + * + * self.precomputed_collocations = collocations.toMap(False) # <<<<<<<<<<<<<< + * self.precomputed_index = frequent_patterns.toMap(True) + * + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_collocations), __pyx_n_s__toMap); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_8 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_GIVEREF(__pyx_t_8); + __Pyx_GOTREF(__pyx_v_self->precomputed_collocations); + __Pyx_DECREF(__pyx_v_self->precomputed_collocations); + __pyx_v_self->precomputed_collocations = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":387 + * + * self.precomputed_collocations = collocations.toMap(False) + * self.precomputed_index = frequent_patterns.toMap(True) # <<<<<<<<<<<<<< + * + * x = 0 + */ + __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_v_frequent_patterns), __pyx_n_s__toMap); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->precomputed_index); + __Pyx_DECREF(__pyx_v_self->precomputed_index); + __pyx_v_self->precomputed_index = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":389 + * self.precomputed_index = frequent_patterns.toMap(True) + * + * x = 0 # <<<<<<<<<<<<<< + * for pattern1 in J_set: + * for pattern2 in J_set: + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_x = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":390 + * + * x = 0 + * for pattern1 in J_set: # <<<<<<<<<<<<<< + * for pattern2 in J_set: + * if len(pattern1) + len(pattern2) + 1 < self.max_length: + */ + __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_J_set)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; + for (;;) { + { + __pyx_t_3 = __pyx_t_4(__pyx_t_1); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_pattern1); + __pyx_v_pattern1 = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":391 + * x = 0 + * for pattern1 in J_set: + * for pattern2 in J_set: # <<<<<<<<<<<<<< + * if len(pattern1) + len(pattern2) + 1 < self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 + */ + __pyx_t_3 = PyObject_GetIter(((PyObject *)__pyx_v_J_set)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_20 = Py_TYPE(__pyx_t_3)->tp_iternext; + for (;;) { + { + __pyx_t_8 = __pyx_t_20(__pyx_t_3); + if (unlikely(!__pyx_t_8)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_8); + } + __Pyx_XDECREF(__pyx_v_pattern2); + __pyx_v_pattern2 = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":392 + * for pattern1 in J_set: + * for pattern2 in J_set: + * if len(pattern1) + len(pattern2) + 1 < self.max_length: # <<<<<<<<<<<<<< + * combined_pattern = pattern1 + (-1,) + pattern2 + * J2_set.add(combined_pattern) + */ + __pyx_t_2 = PyObject_Length(__pyx_v_pattern1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_14 = PyObject_Length(__pyx_v_pattern2); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_19 = (((__pyx_t_2 + __pyx_t_14) + 1) < __pyx_v_self->max_length); + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":393 + * for pattern2 in J_set: + * if len(pattern1) + len(pattern2) + 1 < self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 # <<<<<<<<<<<<<< + * J2_set.add(combined_pattern) + * + */ + __pyx_t_8 = PyNumber_Add(__pyx_v_pattern1, ((PyObject *)__pyx_k_tuple_77)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = PyNumber_Add(__pyx_t_8, __pyx_v_pattern2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_v_combined_pattern); + __pyx_v_combined_pattern = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":394 + * if len(pattern1) + len(pattern2) + 1 < self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 + * J2_set.add(combined_pattern) # <<<<<<<<<<<<<< + * + * for pattern1 in I_set: + */ + __pyx_t_15 = PySet_Add(__pyx_v_J2_set, __pyx_v_combined_pattern); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 394; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L40; + } + __pyx_L40:; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":396 + * J2_set.add(combined_pattern) + * + * for pattern1 in I_set: # <<<<<<<<<<<<<< + * for pattern2 in I_set: + * x = x+1 + */ + __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_I_set)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; + for (;;) { + { + __pyx_t_3 = __pyx_t_4(__pyx_t_1); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_pattern1); + __pyx_v_pattern1 = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":397 + * + * for pattern1 in I_set: + * for pattern2 in I_set: # <<<<<<<<<<<<<< + * x = x+1 + * if len(pattern1) + len(pattern2) + 1 <= self.max_length: + */ + __pyx_t_3 = PyObject_GetIter(((PyObject *)__pyx_v_I_set)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_20 = Py_TYPE(__pyx_t_3)->tp_iternext; + for (;;) { + { + __pyx_t_7 = __pyx_t_20(__pyx_t_3); + if (unlikely(!__pyx_t_7)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_7); + } + __Pyx_XDECREF(__pyx_v_pattern2); + __pyx_v_pattern2 = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":398 + * for pattern1 in I_set: + * for pattern2 in I_set: + * x = x+1 # <<<<<<<<<<<<<< + * if len(pattern1) + len(pattern2) + 1 <= self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 + */ + __pyx_t_7 = PyNumber_Add(__pyx_v_x, __pyx_int_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_v_x); + __pyx_v_x = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":399 + * for pattern2 in I_set: + * x = x+1 + * if len(pattern1) + len(pattern2) + 1 <= self.max_length: # <<<<<<<<<<<<<< + * combined_pattern = pattern1 + (-1,) + pattern2 + * IJ_set.add(combined_pattern) + */ + __pyx_t_14 = PyObject_Length(__pyx_v_pattern1); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Length(__pyx_v_pattern2); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_19 = (((__pyx_t_14 + __pyx_t_2) + 1) <= __pyx_v_self->max_length); + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":400 + * x = x+1 + * if len(pattern1) + len(pattern2) + 1 <= self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 # <<<<<<<<<<<<<< + * IJ_set.add(combined_pattern) + * + */ + __pyx_t_7 = PyNumber_Add(__pyx_v_pattern1, ((PyObject *)__pyx_k_tuple_78)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyNumber_Add(__pyx_t_7, __pyx_v_pattern2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_v_combined_pattern); + __pyx_v_combined_pattern = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":401 + * if len(pattern1) + len(pattern2) + 1 <= self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 + * IJ_set.add(combined_pattern) # <<<<<<<<<<<<<< + * + * for pattern1 in I_set: + */ + __pyx_t_15 = PySet_Add(__pyx_v_IJ_set, __pyx_v_combined_pattern); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L45; + } + __pyx_L45:; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":403 + * IJ_set.add(combined_pattern) + * + * for pattern1 in I_set: # <<<<<<<<<<<<<< + * for pattern2 in J2_set: + * x = x+2 + */ + __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_I_set)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; + for (;;) { + { + __pyx_t_3 = __pyx_t_4(__pyx_t_1); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_pattern1); + __pyx_v_pattern1 = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":404 + * + * for pattern1 in I_set: + * for pattern2 in J2_set: # <<<<<<<<<<<<<< + * x = x+2 + * if len(pattern1) + len(pattern2) + 1<= self.max_length: + */ + __pyx_t_3 = PyObject_GetIter(((PyObject *)__pyx_v_J2_set)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_20 = Py_TYPE(__pyx_t_3)->tp_iternext; + for (;;) { + { + __pyx_t_8 = __pyx_t_20(__pyx_t_3); + if (unlikely(!__pyx_t_8)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_8); + } + __Pyx_XDECREF(__pyx_v_pattern2); + __pyx_v_pattern2 = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":405 + * for pattern1 in I_set: + * for pattern2 in J2_set: + * x = x+2 # <<<<<<<<<<<<<< + * if len(pattern1) + len(pattern2) + 1<= self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 + */ + __pyx_t_8 = PyNumber_Add(__pyx_v_x, __pyx_int_2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_v_x); + __pyx_v_x = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":406 + * for pattern2 in J2_set: + * x = x+2 + * if len(pattern1) + len(pattern2) + 1<= self.max_length: # <<<<<<<<<<<<<< + * combined_pattern = pattern1 + (-1,) + pattern2 + * IJ_set.add(combined_pattern) + */ + __pyx_t_2 = PyObject_Length(__pyx_v_pattern1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_14 = PyObject_Length(__pyx_v_pattern2); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_19 = (((__pyx_t_2 + __pyx_t_14) + 1) <= __pyx_v_self->max_length); + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":407 + * x = x+2 + * if len(pattern1) + len(pattern2) + 1<= self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 # <<<<<<<<<<<<<< + * IJ_set.add(combined_pattern) + * combined_pattern = pattern2 + (-1,) + pattern1 + */ + __pyx_t_8 = PyNumber_Add(__pyx_v_pattern1, ((PyObject *)__pyx_k_tuple_79)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = PyNumber_Add(__pyx_t_8, __pyx_v_pattern2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_v_combined_pattern); + __pyx_v_combined_pattern = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":408 + * if len(pattern1) + len(pattern2) + 1<= self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 + * IJ_set.add(combined_pattern) # <<<<<<<<<<<<<< + * combined_pattern = pattern2 + (-1,) + pattern1 + * IJ_set.add(combined_pattern) + */ + __pyx_t_15 = PySet_Add(__pyx_v_IJ_set, __pyx_v_combined_pattern); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":409 + * combined_pattern = pattern1 + (-1,) + pattern2 + * IJ_set.add(combined_pattern) + * combined_pattern = pattern2 + (-1,) + pattern1 # <<<<<<<<<<<<<< + * IJ_set.add(combined_pattern) + * + */ + __pyx_t_7 = PyNumber_Add(__pyx_v_pattern2, ((PyObject *)__pyx_k_tuple_80)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyNumber_Add(__pyx_t_7, __pyx_v_pattern1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_v_combined_pattern); + __pyx_v_combined_pattern = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":410 + * IJ_set.add(combined_pattern) + * combined_pattern = pattern2 + (-1,) + pattern1 + * IJ_set.add(combined_pattern) # <<<<<<<<<<<<<< + * + * N = len(pattern_rank) + */ + __pyx_t_15 = PySet_Add(__pyx_v_IJ_set, __pyx_v_combined_pattern); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L50; + } + __pyx_L50:; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":412 + * IJ_set.add(combined_pattern) + * + * N = len(pattern_rank) # <<<<<<<<<<<<<< + * cost_by_rank = IntList(initial_len=N) + * count_by_rank = IntList(initial_len=N) + */ + __pyx_t_14 = PyDict_Size(((PyObject *)__pyx_v_pattern_rank)); + __pyx_v_N = __pyx_t_14; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":413 + * + * N = len(pattern_rank) + * cost_by_rank = IntList(initial_len=N) # <<<<<<<<<<<<<< + * count_by_rank = IntList(initial_len=N) + * for pattern, arr in self.precomputed_collocations.iteritems(): + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_v_cost_by_rank = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":414 + * N = len(pattern_rank) + * cost_by_rank = IntList(initial_len=N) + * count_by_rank = IntList(initial_len=N) # <<<<<<<<<<<<<< + * for pattern, arr in self.precomputed_collocations.iteritems(): + * if pattern not in IJ_set: + */ + __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_v_count_by_rank = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":415 + * cost_by_rank = IntList(initial_len=N) + * count_by_rank = IntList(initial_len=N) + * for pattern, arr in self.precomputed_collocations.iteritems(): # <<<<<<<<<<<<<< + * if pattern not in IJ_set: + * s = "" + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_self->precomputed_collocations, __pyx_n_s__iteritems); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_14 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_14 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_14); __Pyx_INCREF(__pyx_t_3); __pyx_t_14++; + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_14); __Pyx_INCREF(__pyx_t_3); __pyx_t_14++; + } else { + __pyx_t_3 = __pyx_t_4(__pyx_t_1); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { + PyObject* sequence = __pyx_t_3; + if (likely(PyTuple_CheckExact(sequence))) { + 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[11]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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[11]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_8 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_5 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_10 = Py_TYPE(__pyx_t_5)->tp_iternext; + index = 0; __pyx_t_8 = __pyx_t_10(__pyx_t_5); if (unlikely(!__pyx_t_8)) goto __pyx_L53_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + index = 1; __pyx_t_7 = __pyx_t_10(__pyx_t_5); if (unlikely(!__pyx_t_7)) goto __pyx_L53_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_5), 2) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L54_unpacking_done; + __pyx_L53_unpacking_failed:; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[11]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L54_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_pattern); + __pyx_v_pattern = __pyx_t_8; + __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_v_arr); + __pyx_v_arr = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":416 + * count_by_rank = IntList(initial_len=N) + * for pattern, arr in self.precomputed_collocations.iteritems(): + * if pattern not in IJ_set: # <<<<<<<<<<<<<< + * s = "" + * for word_id in pattern: + */ + __pyx_t_19 = (__Pyx_NegateNonNeg(PySequence_Contains(((PyObject *)__pyx_v_IJ_set), __pyx_v_pattern))); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":417 + * for pattern, arr in self.precomputed_collocations.iteritems(): + * if pattern not in IJ_set: + * s = "" # <<<<<<<<<<<<<< + * for word_id in pattern: + * if word_id == -1: + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_42)); + __Pyx_XDECREF(__pyx_v_s); + __pyx_v_s = ((PyObject *)__pyx_kp_s_42); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":418 + * if pattern not in IJ_set: + * s = "" + * for word_id in pattern: # <<<<<<<<<<<<<< + * if word_id == -1: + * s = s + "X " + */ + if (PyList_CheckExact(__pyx_v_pattern) || PyTuple_CheckExact(__pyx_v_pattern)) { + __pyx_t_3 = __pyx_v_pattern; __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = 0; + __pyx_t_20 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_pattern); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_20 = Py_TYPE(__pyx_t_3)->tp_iternext; + } + for (;;) { + if (!__pyx_t_20 && PyList_CheckExact(__pyx_t_3)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_3)) break; + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_7); __pyx_t_2++; + } else if (!__pyx_t_20 && PyTuple_CheckExact(__pyx_t_3)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_7); __pyx_t_2++; + } else { + __pyx_t_7 = __pyx_t_20(__pyx_t_3); + if (unlikely(!__pyx_t_7)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_7); + } + __Pyx_XDECREF(__pyx_v_word_id); + __pyx_v_word_id = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":419 + * s = "" + * for word_id in pattern: + * if word_id == -1: # <<<<<<<<<<<<<< + * s = s + "X " + * else: + */ + __pyx_t_7 = PyObject_RichCompare(__pyx_v_word_id, __pyx_int_neg_1, Py_EQ); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 419; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 419; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":420 + * for word_id in pattern: + * if word_id == -1: + * s = s + "X " # <<<<<<<<<<<<<< + * else: + * s = s + darray.id2word[word_id] + " " + */ + __pyx_t_7 = PyNumber_Add(__pyx_v_s, ((PyObject *)__pyx_kp_s_81)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_v_s); + __pyx_v_s = __pyx_t_7; + __pyx_t_7 = 0; + goto __pyx_L58; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":422 + * s = s + "X " + * else: + * s = s + darray.id2word[word_id] + " " # <<<<<<<<<<<<<< + * logger.warn("ERROR: unexpected pattern %s in set of precomputed collocations", s) + * else: + */ + __pyx_t_7 = PyObject_GetItem(__pyx_v_darray->id2word, __pyx_v_word_id); if (!__pyx_t_7) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyNumber_Add(__pyx_v_s, __pyx_t_7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = PyNumber_Add(__pyx_t_8, ((PyObject *)__pyx_kp_s_64)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_v_s); + __pyx_v_s = __pyx_t_7; + __pyx_t_7 = 0; + } + __pyx_L58:; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":423 + * else: + * s = s + darray.id2word[word_id] + " " + * logger.warn("ERROR: unexpected pattern %s in set of precomputed collocations", s) # <<<<<<<<<<<<<< + * else: + * chunk = () + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__warn); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_82)); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_82)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_82)); + __Pyx_INCREF(__pyx_v_s); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_s); + __Pyx_GIVEREF(__pyx_v_s); + __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L55; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":425 + * logger.warn("ERROR: unexpected pattern %s in set of precomputed collocations", s) + * else: + * chunk = () # <<<<<<<<<<<<<< + * max_rank = 0 + * arity = 0 + */ + __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); + __Pyx_XDECREF(((PyObject *)__pyx_v_chunk)); + __pyx_v_chunk = __pyx_empty_tuple; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":426 + * else: + * chunk = () + * max_rank = 0 # <<<<<<<<<<<<<< + * arity = 0 + * for word_id in pattern: + */ + __pyx_v_max_rank = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":427 + * chunk = () + * max_rank = 0 + * arity = 0 # <<<<<<<<<<<<<< + * for word_id in pattern: + * if word_id == -1: + */ + __Pyx_INCREF(__pyx_int_0); + __Pyx_XDECREF(__pyx_v_arity); + __pyx_v_arity = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":428 + * max_rank = 0 + * arity = 0 + * for word_id in pattern: # <<<<<<<<<<<<<< + * if word_id == -1: + * max_rank = max(max_rank, pattern_rank[chunk]) + */ + if (PyList_CheckExact(__pyx_v_pattern) || PyTuple_CheckExact(__pyx_v_pattern)) { + __pyx_t_8 = __pyx_v_pattern; __Pyx_INCREF(__pyx_t_8); __pyx_t_2 = 0; + __pyx_t_20 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_pattern); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_20 = Py_TYPE(__pyx_t_8)->tp_iternext; + } + for (;;) { + if (!__pyx_t_20 && PyList_CheckExact(__pyx_t_8)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_8)) break; + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; + } else if (!__pyx_t_20 && PyTuple_CheckExact(__pyx_t_8)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_8)) break; + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; + } else { + __pyx_t_3 = __pyx_t_20(__pyx_t_8); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_word_id); + __pyx_v_word_id = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":429 + * arity = 0 + * for word_id in pattern: + * if word_id == -1: # <<<<<<<<<<<<<< + * max_rank = max(max_rank, pattern_rank[chunk]) + * arity = arity + 1 + */ + __pyx_t_3 = PyObject_RichCompare(__pyx_v_word_id, __pyx_int_neg_1, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":430 + * for word_id in pattern: + * if word_id == -1: + * max_rank = max(max_rank, pattern_rank[chunk]) # <<<<<<<<<<<<<< + * arity = arity + 1 + * chunk = () + */ + __pyx_t_3 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_pattern_rank), ((PyObject *)__pyx_v_chunk)); if (!__pyx_t_3) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_13 = __pyx_v_max_rank; + __pyx_t_5 = PyInt_FromLong(__pyx_t_13); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyObject_RichCompare(__pyx_t_3, __pyx_t_5, Py_GT); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_19) { + __Pyx_INCREF(__pyx_t_3); + __pyx_t_7 = __pyx_t_3; + } else { + __pyx_t_6 = PyInt_FromLong(__pyx_t_13); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __pyx_t_6; + __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_max_rank = __pyx_t_13; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":431 + * if word_id == -1: + * max_rank = max(max_rank, pattern_rank[chunk]) + * arity = arity + 1 # <<<<<<<<<<<<<< + * chunk = () + * else: + */ + __pyx_t_7 = PyNumber_Add(__pyx_v_arity, __pyx_int_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_v_arity); + __pyx_v_arity = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":432 + * max_rank = max(max_rank, pattern_rank[chunk]) + * arity = arity + 1 + * chunk = () # <<<<<<<<<<<<<< + * else: + * chunk = chunk + (word_id,) + */ + __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); + __Pyx_DECREF(((PyObject *)__pyx_v_chunk)); + __pyx_v_chunk = __pyx_empty_tuple; + goto __pyx_L61; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":434 + * chunk = () + * else: + * chunk = chunk + (word_id,) # <<<<<<<<<<<<<< + * max_rank = max(max_rank, pattern_rank[chunk]) + * cost_by_rank.arr[max_rank] = cost_by_rank.arr[max_rank] + (4*len(arr)) + */ + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_v_word_id); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_word_id); + __Pyx_GIVEREF(__pyx_v_word_id); + __pyx_t_3 = PyNumber_Add(((PyObject *)__pyx_v_chunk), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_chunk)); + __pyx_v_chunk = __pyx_t_3; + __pyx_t_3 = 0; + } + __pyx_L61:; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":435 + * else: + * chunk = chunk + (word_id,) + * max_rank = max(max_rank, pattern_rank[chunk]) # <<<<<<<<<<<<<< + * cost_by_rank.arr[max_rank] = cost_by_rank.arr[max_rank] + (4*len(arr)) + * count_by_rank.arr[max_rank] = count_by_rank.arr[max_rank] + (len(arr)/(arity+1)) + */ + __pyx_t_8 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_pattern_rank), ((PyObject *)__pyx_v_chunk)); if (!__pyx_t_8) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_13 = __pyx_v_max_rank; + __pyx_t_7 = PyInt_FromLong(__pyx_t_13); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = PyObject_RichCompare(__pyx_t_8, __pyx_t_7, Py_GT); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_19) { + __Pyx_INCREF(__pyx_t_8); + __pyx_t_3 = __pyx_t_8; + } else { + __pyx_t_6 = PyInt_FromLong(__pyx_t_13); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = __pyx_t_6; + __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_max_rank = __pyx_t_13; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":436 + * chunk = chunk + (word_id,) + * max_rank = max(max_rank, pattern_rank[chunk]) + * cost_by_rank.arr[max_rank] = cost_by_rank.arr[max_rank] + (4*len(arr)) # <<<<<<<<<<<<<< + * count_by_rank.arr[max_rank] = count_by_rank.arr[max_rank] + (len(arr)/(arity+1)) + * + */ + __pyx_t_2 = PyObject_Length(__pyx_v_arr); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + (__pyx_v_cost_by_rank->arr[__pyx_v_max_rank]) = ((__pyx_v_cost_by_rank->arr[__pyx_v_max_rank]) + (4 * __pyx_t_2)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":437 + * max_rank = max(max_rank, pattern_rank[chunk]) + * cost_by_rank.arr[max_rank] = cost_by_rank.arr[max_rank] + (4*len(arr)) + * count_by_rank.arr[max_rank] = count_by_rank.arr[max_rank] + (len(arr)/(arity+1)) # <<<<<<<<<<<<<< + * + * cumul_cost = 0 + */ + __pyx_t_3 = PyInt_FromLong((__pyx_v_count_by_rank->arr[__pyx_v_max_rank])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_Length(__pyx_v_arr); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_6 = PyNumber_Add(__pyx_v_arity, __pyx_int_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyNumber_Divide(__pyx_t_8, __pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = PyNumber_Add(__pyx_t_3, __pyx_t_7); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + (__pyx_v_count_by_rank->arr[__pyx_v_max_rank]) = __pyx_t_13; + } + __pyx_L55:; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":439 + * count_by_rank.arr[max_rank] = count_by_rank.arr[max_rank] + (len(arr)/(arity+1)) + * + * cumul_cost = 0 # <<<<<<<<<<<<<< + * cumul_count = 0 + * for i from 0 <= i < N: + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_cumul_cost = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":440 + * + * cumul_cost = 0 + * cumul_count = 0 # <<<<<<<<<<<<<< + * for i from 0 <= i < N: + * cumul_cost = cumul_cost + cost_by_rank.arr[i] + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_cumul_count = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":441 + * cumul_cost = 0 + * cumul_count = 0 + * for i from 0 <= i < N: # <<<<<<<<<<<<<< + * cumul_cost = cumul_cost + cost_by_rank.arr[i] + * cumul_count = cumul_count + count_by_rank.arr[i] + */ + __pyx_t_13 = __pyx_v_N; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_13; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":442 + * cumul_count = 0 + * for i from 0 <= i < N: + * cumul_cost = cumul_cost + cost_by_rank.arr[i] # <<<<<<<<<<<<<< + * cumul_count = cumul_count + count_by_rank.arr[i] + * logger.debug("RANK %d\tCOUNT, COST: %d %d\tCUMUL: %d, %d", i, count_by_rank.arr[i], cost_by_rank.arr[i], cumul_count, cumul_cost) + */ + __pyx_t_1 = PyInt_FromLong((__pyx_v_cost_by_rank->arr[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = PyNumber_Add(__pyx_v_cumul_cost, __pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_v_cumul_cost); + __pyx_v_cumul_cost = __pyx_t_6; + __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":443 + * for i from 0 <= i < N: + * cumul_cost = cumul_cost + cost_by_rank.arr[i] + * cumul_count = cumul_count + count_by_rank.arr[i] # <<<<<<<<<<<<<< + * logger.debug("RANK %d\tCOUNT, COST: %d %d\tCUMUL: %d, %d", i, count_by_rank.arr[i], cost_by_rank.arr[i], cumul_count, cumul_cost) + * + */ + __pyx_t_6 = PyInt_FromLong((__pyx_v_count_by_rank->arr[__pyx_v_i])); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_1 = PyNumber_Add(__pyx_v_cumul_count, __pyx_t_6); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_v_cumul_count); + __pyx_v_cumul_count = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":444 + * cumul_cost = cumul_cost + cost_by_rank.arr[i] + * cumul_count = cumul_count + count_by_rank.arr[i] + * logger.debug("RANK %d\tCOUNT, COST: %d %d\tCUMUL: %d, %d", i, count_by_rank.arr[i], cost_by_rank.arr[i], cumul_count, cumul_cost) # <<<<<<<<<<<<<< + * + * num_found_patterns = len(self.precomputed_collocations) + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__debug); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = PyInt_FromLong((__pyx_v_count_by_rank->arr[__pyx_v_i])); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_3 = PyInt_FromLong((__pyx_v_cost_by_rank->arr[__pyx_v_i])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = PyTuple_New(6); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_83)); + PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_kp_s_83)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_83)); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_cumul_count); + PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_v_cumul_count); + __Pyx_GIVEREF(__pyx_v_cumul_count); + __Pyx_INCREF(__pyx_v_cumul_cost); + PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_v_cumul_cost); + __Pyx_GIVEREF(__pyx_v_cumul_cost); + __pyx_t_1 = 0; + __pyx_t_7 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":446 + * logger.debug("RANK %d\tCOUNT, COST: %d %d\tCUMUL: %d, %d", i, count_by_rank.arr[i], cost_by_rank.arr[i], cumul_count, cumul_cost) + * + * num_found_patterns = len(self.precomputed_collocations) # <<<<<<<<<<<<<< + * for pattern in IJ_set: + * if pattern not in self.precomputed_collocations: + */ + __pyx_t_3 = __pyx_v_self->precomputed_collocations; + __Pyx_INCREF(__pyx_t_3); + __pyx_t_14 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_14); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_num_found_patterns = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":447 + * + * num_found_patterns = len(self.precomputed_collocations) + * for pattern in IJ_set: # <<<<<<<<<<<<<< + * if pattern not in self.precomputed_collocations: + * self.precomputed_collocations[pattern] = IntList() + */ + __pyx_t_3 = PyObject_GetIter(((PyObject *)__pyx_v_IJ_set)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; + for (;;) { + { + __pyx_t_8 = __pyx_t_4(__pyx_t_3); + if (unlikely(!__pyx_t_8)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_8); + } + __Pyx_XDECREF(__pyx_v_pattern); + __pyx_v_pattern = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":448 + * num_found_patterns = len(self.precomputed_collocations) + * for pattern in IJ_set: + * if pattern not in self.precomputed_collocations: # <<<<<<<<<<<<<< + * self.precomputed_collocations[pattern] = IntList() + * + */ + __pyx_t_19 = (__Pyx_NegateNonNeg(PySequence_Contains(__pyx_v_self->precomputed_collocations, __pyx_v_pattern))); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":449 + * for pattern in IJ_set: + * if pattern not in self.precomputed_collocations: + * self.precomputed_collocations[pattern] = IntList() # <<<<<<<<<<<<<< + * + * cdef float stop_time = monitor_cpu() + */ + __pyx_t_8 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + if (PyObject_SetItem(__pyx_v_self->precomputed_collocations, __pyx_v_pattern, __pyx_t_8) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L66; + } + __pyx_L66:; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":451 + * self.precomputed_collocations[pattern] = IntList() + * + * cdef float stop_time = monitor_cpu() # <<<<<<<<<<<<<< + * logger.info("Precomputed collocations for %d patterns out of %d possible (upper bound %d)", num_found_patterns, len(self.precomputed_collocations), x) + * logger.info("Precomputed inverted index for %d patterns ", len(self.precomputed_index)) + */ + __pyx_v_stop_time = __pyx_f_8_cdec_sa_monitor_cpu(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":452 + * + * cdef float stop_time = monitor_cpu() + * logger.info("Precomputed collocations for %d patterns out of %d possible (upper bound %d)", num_found_patterns, len(self.precomputed_collocations), x) # <<<<<<<<<<<<<< + * logger.info("Precomputed inverted index for %d patterns ", len(self.precomputed_index)) + * logger.info("Precomputation took %f seconds", (stop_time - start_time)) + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __pyx_v_self->precomputed_collocations; + __Pyx_INCREF(__pyx_t_3); + __pyx_t_14 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_14); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PyTuple_New(4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_84)); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_kp_s_84)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_84)); + __Pyx_INCREF(__pyx_v_num_found_patterns); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_num_found_patterns); + __Pyx_GIVEREF(__pyx_v_num_found_patterns); + PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_x); + PyTuple_SET_ITEM(__pyx_t_6, 3, __pyx_v_x); + __Pyx_GIVEREF(__pyx_v_x); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":453 + * cdef float stop_time = monitor_cpu() + * logger.info("Precomputed collocations for %d patterns out of %d possible (upper bound %d)", num_found_patterns, len(self.precomputed_collocations), x) + * logger.info("Precomputed inverted index for %d patterns ", len(self.precomputed_index)) # <<<<<<<<<<<<<< + * logger.info("Precomputation took %f seconds", (stop_time - start_time)) + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __pyx_v_self->precomputed_index; + __Pyx_INCREF(__pyx_t_3); + __pyx_t_14 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_14); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_85)); + PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_kp_s_85)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_85)); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":454 + * logger.info("Precomputed collocations for %d patterns out of %d possible (upper bound %d)", num_found_patterns, len(self.precomputed_collocations), x) + * logger.info("Precomputed inverted index for %d patterns ", len(self.precomputed_index)) + * logger.info("Precomputation took %f seconds", (stop_time - start_time)) # <<<<<<<<<<<<<< + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyFloat_FromDouble((__pyx_v_stop_time - __pyx_v_start_time)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_86)); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_kp_s_86)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_86)); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("_cdec_sa.Precomputation.precompute", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_darray); + __Pyx_XDECREF((PyObject *)__pyx_v_data); + __Pyx_XDECREF((PyObject *)__pyx_v_queue); + __Pyx_XDECREF((PyObject *)__pyx_v_cost_by_rank); + __Pyx_XDECREF((PyObject *)__pyx_v_count_by_rank); + __Pyx_XDECREF((PyObject *)__pyx_v_frequent_patterns); + __Pyx_XDECREF((PyObject *)__pyx_v_super_frequent_patterns); + __Pyx_XDECREF((PyObject *)__pyx_v_collocations); + __Pyx_XDECREF(__pyx_v_I_set); + __Pyx_XDECREF(__pyx_v_J_set); + __Pyx_XDECREF(__pyx_v_J2_set); + __Pyx_XDECREF(__pyx_v_IJ_set); + __Pyx_XDECREF(__pyx_v_pattern_rank); + __Pyx_XDECREF(__pyx_v_rank); + __Pyx_XDECREF(__pyx_v__); + __Pyx_XDECREF(__pyx_v_phrase); + __Pyx_XDECREF(__pyx_v_x); + __Pyx_XDECREF(__pyx_v_pattern1); + __Pyx_XDECREF(__pyx_v_pattern2); + __Pyx_XDECREF(__pyx_v_combined_pattern); + __Pyx_XDECREF(__pyx_v_pattern); + __Pyx_XDECREF(__pyx_v_arr); + __Pyx_XDECREF(__pyx_v_s); + __Pyx_XDECREF(__pyx_v_word_id); + __Pyx_XDECREF(__pyx_v_chunk); + __Pyx_XDECREF(__pyx_v_arity); + __Pyx_XDECREF(__pyx_v_cumul_cost); + __Pyx_XDECREF(__pyx_v_cumul_count); + __Pyx_XDECREF(__pyx_v_num_found_patterns); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_11SuffixArray_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_11SuffixArray_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_from_binary = 0; + PyObject *__pyx_v_from_text = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__from_binary,&__pyx_n_s__from_text,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":11 + * cdef IntList ha + * + * def __cinit__(self, from_binary=None, from_text=None): # <<<<<<<<<<<<<< + * self.darray = DataArray() + * self.sa = IntList() + */ + values[0] = ((PyObject *)Py_None); + values[1] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_binary); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_text); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_from_binary = values[0]; + __pyx_v_from_text = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.SuffixArray.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray___cinit__(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), __pyx_v_from_binary, __pyx_v_from_text); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_11SuffixArray___cinit__(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":12 + * + * def __cinit__(self, from_binary=None, from_text=None): + * self.darray = DataArray() # <<<<<<<<<<<<<< + * self.sa = IntList() + * self.ha = IntList() + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_DataArray)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->darray); + __Pyx_DECREF(((PyObject *)__pyx_v_self->darray)); + __pyx_v_self->darray = ((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":13 + * def __cinit__(self, from_binary=None, from_text=None): + * self.darray = DataArray() + * self.sa = IntList() # <<<<<<<<<<<<<< + * self.ha = IntList() + * if from_binary: + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->sa); + __Pyx_DECREF(((PyObject *)__pyx_v_self->sa)); + __pyx_v_self->sa = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":14 + * self.darray = DataArray() + * self.sa = IntList() + * self.ha = IntList() # <<<<<<<<<<<<<< + * if from_binary: + * self.read_binary(from_binary) + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->ha); + __Pyx_DECREF(((PyObject *)__pyx_v_self->ha)); + __pyx_v_self->ha = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":15 + * self.sa = IntList() + * self.ha = IntList() + * if from_binary: # <<<<<<<<<<<<<< + * self.read_binary(from_binary) + * elif from_text: + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_binary); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":16 + * self.ha = IntList() + * if from_binary: + * self.read_binary(from_binary) # <<<<<<<<<<<<<< + * elif from_text: + * self.read_text(from_text) + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_binary); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_from_binary); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_binary); + __Pyx_GIVEREF(__pyx_v_from_binary); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":17 + * if from_binary: + * self.read_binary(from_binary) + * elif from_text: # <<<<<<<<<<<<<< + * self.read_text(from_text) + * + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_text); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":18 + * self.read_binary(from_binary) + * elif from_text: + * self.read_text(from_text) # <<<<<<<<<<<<<< + * + * def __getitem__(self, i): + */ + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_text); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_from_text); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_text); + __Pyx_GIVEREF(__pyx_v_from_text); + __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec_sa.SuffixArray.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_2__getitem__(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":20 + * self.read_text(from_text) + * + * def __getitem__(self, i): # <<<<<<<<<<<<<< + * return self.sa.arr[i] + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_2__getitem__(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__getitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":21 + * + * def __getitem__(self, i): + * return self.sa.arr[i] # <<<<<<<<<<<<<< + * + * def getSentId(self, i): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->sa->arr[__pyx_t_1])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_cdec_sa.SuffixArray.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_5getSentId(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_5getSentId(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getSentId (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_4getSentId(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":23 + * return self.sa.arr[i] + * + * def getSentId(self, i): # <<<<<<<<<<<<<< + * return self.darray.getSentId(i) + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_4getSentId(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("getSentId", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":24 + * + * def getSentId(self, i): + * return self.darray.getSentId(i) # <<<<<<<<<<<<<< + * + * def getSent(self, i): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->darray), __pyx_n_s__getSentId); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.SuffixArray.getSentId", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_7getSent(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_7getSent(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getSent (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_6getSent(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":26 + * return self.darray.getSentId(i) + * + * def getSent(self, i): # <<<<<<<<<<<<<< + * return self.darray.getSent(i) + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_6getSent(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("getSent", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":27 + * + * def getSent(self, i): + * return self.darray.getSent(i) # <<<<<<<<<<<<<< + * + * def getSentPos(self, loc): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->darray), __pyx_n_s__getSent); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.SuffixArray.getSent", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_9getSentPos(PyObject *__pyx_v_self, PyObject *__pyx_v_loc); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_9getSentPos(PyObject *__pyx_v_self, PyObject *__pyx_v_loc) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getSentPos (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_8getSentPos(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), ((PyObject *)__pyx_v_loc)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":29 + * return self.darray.getSent(i) + * + * def getSentPos(self, loc): # <<<<<<<<<<<<<< + * return self.darray.getSentPos(loc) + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_8getSentPos(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_loc) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("getSentPos", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":30 + * + * def getSentPos(self, loc): + * return self.darray.getSentPos(loc) # <<<<<<<<<<<<<< + * + * def read_text(self, char* filename): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->darray), __pyx_n_s__getSentPos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_loc); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_loc); + __Pyx_GIVEREF(__pyx_v_loc); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.SuffixArray.getSentPos", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_11read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static char __pyx_doc_8_cdec_sa_11SuffixArray_10read_text[] = "Constructs suffix array using the algorithm\n of Larsson & Sadahkane (1999)"; +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_11read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_text (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.SuffixArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_10read_text(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":32 + * return self.darray.getSentPos(loc) + * + * def read_text(self, char* filename): # <<<<<<<<<<<<<< + * '''Constructs suffix array using the algorithm + * of Larsson & Sadahkane (1999)''' + */ + +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_10read_text(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename) { + int __pyx_v_V; + int __pyx_v_N; + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_h; + int __pyx_v_a_i; + int __pyx_v_n; + int __pyx_v_current_run; + int __pyx_v_skip; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_isa = 0; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_word_count = 0; + float __pyx_v_sort_start_time; + float __pyx_v_start_time; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + long __pyx_t_5; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_text", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":38 + * cdef IntList isa, word_count + * + * self.darray = DataArray(from_text=filename, use_sent_id=True) # <<<<<<<<<<<<<< + * N = len(self.darray) + * V = len(self.darray.id2word) + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__from_text), ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__use_sent_id), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_DataArray)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 38; __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); + __Pyx_GOTREF(__pyx_v_self->darray); + __Pyx_DECREF(((PyObject *)__pyx_v_self->darray)); + __pyx_v_self->darray = ((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":39 + * + * self.darray = DataArray(from_text=filename, use_sent_id=True) + * N = len(self.darray) # <<<<<<<<<<<<<< + * V = len(self.darray.id2word) + * + */ + __pyx_t_2 = ((PyObject *)__pyx_v_self->darray); + __Pyx_INCREF(__pyx_t_2); + __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_N = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":40 + * self.darray = DataArray(from_text=filename, use_sent_id=True) + * N = len(self.darray) + * V = len(self.darray.id2word) # <<<<<<<<<<<<<< + * + * self.sa = IntList(initial_len=N) + */ + __pyx_t_2 = __pyx_v_self->darray->id2word; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_V = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":42 + * V = len(self.darray.id2word) + * + * self.sa = IntList(initial_len=N) # <<<<<<<<<<<<<< + * self.ha = IntList(initial_len=V+1) + * + */ + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->sa); + __Pyx_DECREF(((PyObject *)__pyx_v_self->sa)); + __pyx_v_self->sa = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":43 + * + * self.sa = IntList(initial_len=N) + * self.ha = IntList(initial_len=V+1) # <<<<<<<<<<<<<< + * + * isa = IntList(initial_len=N) + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyInt_FromLong((__pyx_v_V + 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 43; __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); + __Pyx_GOTREF(__pyx_v_self->ha); + __Pyx_DECREF(((PyObject *)__pyx_v_self->ha)); + __pyx_v_self->ha = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":45 + * self.ha = IntList(initial_len=V+1) + * + * isa = IntList(initial_len=N) # <<<<<<<<<<<<<< + * word_count = IntList(initial_len=V+1) + * + */ + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_v_isa = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":46 + * + * isa = IntList(initial_len=N) + * word_count = IntList(initial_len=V+1) # <<<<<<<<<<<<<< + * + * '''Step 1: bucket sort data''' + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyInt_FromLong((__pyx_v_V + 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_v_word_count = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":49 + * + * '''Step 1: bucket sort data''' + * cdef float sort_start_time = monitor_cpu() # <<<<<<<<<<<<<< + * cdef float start_time = sort_start_time + * for i from 0 <= i < N: + */ + __pyx_v_sort_start_time = __pyx_f_8_cdec_sa_monitor_cpu(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":50 + * '''Step 1: bucket sort data''' + * cdef float sort_start_time = monitor_cpu() + * cdef float start_time = sort_start_time # <<<<<<<<<<<<<< + * for i from 0 <= i < N: + * a_i = self.darray.data.arr[i] + */ + __pyx_v_start_time = __pyx_v_sort_start_time; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":51 + * cdef float sort_start_time = monitor_cpu() + * cdef float start_time = sort_start_time + * for i from 0 <= i < N: # <<<<<<<<<<<<<< + * a_i = self.darray.data.arr[i] + * word_count.arr[a_i] = word_count.arr[a_i] + 1 + */ + __pyx_t_4 = __pyx_v_N; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":52 + * cdef float start_time = sort_start_time + * for i from 0 <= i < N: + * a_i = self.darray.data.arr[i] # <<<<<<<<<<<<<< + * word_count.arr[a_i] = word_count.arr[a_i] + 1 + * + */ + __pyx_v_a_i = (__pyx_v_self->darray->data->arr[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":53 + * for i from 0 <= i < N: + * a_i = self.darray.data.arr[i] + * word_count.arr[a_i] = word_count.arr[a_i] + 1 # <<<<<<<<<<<<<< + * + * n = 0 + */ + (__pyx_v_word_count->arr[__pyx_v_a_i]) = ((__pyx_v_word_count->arr[__pyx_v_a_i]) + 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":55 + * word_count.arr[a_i] = word_count.arr[a_i] + 1 + * + * n = 0 # <<<<<<<<<<<<<< + * for i from 0 <= i < V+1: + * self.ha.arr[i] = n + */ + __pyx_v_n = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":56 + * + * n = 0 + * for i from 0 <= i < V+1: # <<<<<<<<<<<<<< + * self.ha.arr[i] = n + * n = n + word_count.arr[i] + */ + __pyx_t_5 = (__pyx_v_V + 1); + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_5; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":57 + * n = 0 + * for i from 0 <= i < V+1: + * self.ha.arr[i] = n # <<<<<<<<<<<<<< + * n = n + word_count.arr[i] + * word_count.arr[i] = 0 + */ + (__pyx_v_self->ha->arr[__pyx_v_i]) = __pyx_v_n; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":58 + * for i from 0 <= i < V+1: + * self.ha.arr[i] = n + * n = n + word_count.arr[i] # <<<<<<<<<<<<<< + * word_count.arr[i] = 0 + * + */ + __pyx_v_n = (__pyx_v_n + (__pyx_v_word_count->arr[__pyx_v_i])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":59 + * self.ha.arr[i] = n + * n = n + word_count.arr[i] + * word_count.arr[i] = 0 # <<<<<<<<<<<<<< + * + * for i from 0 <= i < N: + */ + (__pyx_v_word_count->arr[__pyx_v_i]) = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":61 + * word_count.arr[i] = 0 + * + * for i from 0 <= i < N: # <<<<<<<<<<<<<< + * a_i = self.darray.data.arr[i] + * self.sa.arr[self.ha.arr[a_i] + word_count.arr[a_i]] = i + */ + __pyx_t_4 = __pyx_v_N; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":62 + * + * for i from 0 <= i < N: + * a_i = self.darray.data.arr[i] # <<<<<<<<<<<<<< + * self.sa.arr[self.ha.arr[a_i] + word_count.arr[a_i]] = i + * isa.arr[i] = self.ha.arr[a_i + 1] - 1 # bucket pointer is last index in bucket + */ + __pyx_v_a_i = (__pyx_v_self->darray->data->arr[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":63 + * for i from 0 <= i < N: + * a_i = self.darray.data.arr[i] + * self.sa.arr[self.ha.arr[a_i] + word_count.arr[a_i]] = i # <<<<<<<<<<<<<< + * isa.arr[i] = self.ha.arr[a_i + 1] - 1 # bucket pointer is last index in bucket + * word_count.arr[a_i] = word_count.arr[a_i] + 1 + */ + (__pyx_v_self->sa->arr[((__pyx_v_self->ha->arr[__pyx_v_a_i]) + (__pyx_v_word_count->arr[__pyx_v_a_i]))]) = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":64 + * a_i = self.darray.data.arr[i] + * self.sa.arr[self.ha.arr[a_i] + word_count.arr[a_i]] = i + * isa.arr[i] = self.ha.arr[a_i + 1] - 1 # bucket pointer is last index in bucket # <<<<<<<<<<<<<< + * word_count.arr[a_i] = word_count.arr[a_i] + 1 + * + */ + (__pyx_v_isa->arr[__pyx_v_i]) = ((__pyx_v_self->ha->arr[(__pyx_v_a_i + 1)]) - 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":65 + * self.sa.arr[self.ha.arr[a_i] + word_count.arr[a_i]] = i + * isa.arr[i] = self.ha.arr[a_i + 1] - 1 # bucket pointer is last index in bucket + * word_count.arr[a_i] = word_count.arr[a_i] + 1 # <<<<<<<<<<<<<< + * + * '''Determine size of initial runs''' + */ + (__pyx_v_word_count->arr[__pyx_v_a_i]) = ((__pyx_v_word_count->arr[__pyx_v_a_i]) + 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":68 + * + * '''Determine size of initial runs''' + * current_run = 0 # <<<<<<<<<<<<<< + * for i from 0 <= i < V+1: + * if i < V and self.ha.arr[i+1] - self.ha.arr[i] == 1: + */ + __pyx_v_current_run = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":69 + * '''Determine size of initial runs''' + * current_run = 0 + * for i from 0 <= i < V+1: # <<<<<<<<<<<<<< + * if i < V and self.ha.arr[i+1] - self.ha.arr[i] == 1: + * current_run = current_run + 1 + */ + __pyx_t_5 = (__pyx_v_V + 1); + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_5; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":70 + * current_run = 0 + * for i from 0 <= i < V+1: + * if i < V and self.ha.arr[i+1] - self.ha.arr[i] == 1: # <<<<<<<<<<<<<< + * current_run = current_run + 1 + * else: + */ + __pyx_t_6 = (__pyx_v_i < __pyx_v_V); + if (__pyx_t_6) { + __pyx_t_7 = (((__pyx_v_self->ha->arr[(__pyx_v_i + 1)]) - (__pyx_v_self->ha->arr[__pyx_v_i])) == 1); + __pyx_t_8 = __pyx_t_7; + } else { + __pyx_t_8 = __pyx_t_6; + } + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":71 + * for i from 0 <= i < V+1: + * if i < V and self.ha.arr[i+1] - self.ha.arr[i] == 1: + * current_run = current_run + 1 # <<<<<<<<<<<<<< + * else: + * if current_run > 0: + */ + __pyx_v_current_run = (__pyx_v_current_run + 1); + goto __pyx_L11; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":73 + * current_run = current_run + 1 + * else: + * if current_run > 0: # <<<<<<<<<<<<<< + * self.sa.arr[self.ha.arr[i] - current_run] = -current_run + * current_run = 0 + */ + __pyx_t_8 = (__pyx_v_current_run > 0); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":74 + * else: + * if current_run > 0: + * self.sa.arr[self.ha.arr[i] - current_run] = -current_run # <<<<<<<<<<<<<< + * current_run = 0 + * + */ + (__pyx_v_self->sa->arr[((__pyx_v_self->ha->arr[__pyx_v_i]) - __pyx_v_current_run)]) = (-__pyx_v_current_run); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":75 + * if current_run > 0: + * self.sa.arr[self.ha.arr[i] - current_run] = -current_run + * current_run = 0 # <<<<<<<<<<<<<< + * + * logger.info(" Bucket sort took %f seconds", (monitor_cpu() - sort_start_time)) + */ + __pyx_v_current_run = 0; + goto __pyx_L12; + } + __pyx_L12:; + } + __pyx_L11:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":77 + * current_run = 0 + * + * logger.info(" Bucket sort took %f seconds", (monitor_cpu() - sort_start_time)) # <<<<<<<<<<<<<< + * + * '''Step 2: prefix-doubling sort''' + */ + __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__info); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyFloat_FromDouble((__pyx_f_8_cdec_sa_monitor_cpu() - __pyx_v_sort_start_time)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_87)); + PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_kp_s_87)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_87)); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":80 + * + * '''Step 2: prefix-doubling sort''' + * h = 1 # <<<<<<<<<<<<<< + * while self.sa.arr[0] != -N: + * sort_start_time = monitor_cpu() + */ + __pyx_v_h = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":81 + * '''Step 2: prefix-doubling sort''' + * h = 1 + * while self.sa.arr[0] != -N: # <<<<<<<<<<<<<< + * sort_start_time = monitor_cpu() + * logger.debug(" Refining, sort depth = %d", h) + */ + while (1) { + __pyx_t_8 = ((__pyx_v_self->sa->arr[0]) != (-__pyx_v_N)); + if (!__pyx_t_8) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":82 + * h = 1 + * while self.sa.arr[0] != -N: + * sort_start_time = monitor_cpu() # <<<<<<<<<<<<<< + * logger.debug(" Refining, sort depth = %d", h) + * i = 0 + */ + __pyx_v_sort_start_time = __pyx_f_8_cdec_sa_monitor_cpu(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":83 + * while self.sa.arr[0] != -N: + * sort_start_time = monitor_cpu() + * logger.debug(" Refining, sort depth = %d", h) # <<<<<<<<<<<<<< + * i = 0 + * skip = 0 + */ + __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__debug); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_88)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_88)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_88)); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":84 + * sort_start_time = monitor_cpu() + * logger.debug(" Refining, sort depth = %d", h) + * i = 0 # <<<<<<<<<<<<<< + * skip = 0 + * while i < N: + */ + __pyx_v_i = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":85 + * logger.debug(" Refining, sort depth = %d", h) + * i = 0 + * skip = 0 # <<<<<<<<<<<<<< + * while i < N: + * if self.sa.arr[i] < 0: + */ + __pyx_v_skip = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":86 + * i = 0 + * skip = 0 + * while i < N: # <<<<<<<<<<<<<< + * if self.sa.arr[i] < 0: + * skip = skip + self.sa.arr[i] + */ + while (1) { + __pyx_t_8 = (__pyx_v_i < __pyx_v_N); + if (!__pyx_t_8) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":87 + * skip = 0 + * while i < N: + * if self.sa.arr[i] < 0: # <<<<<<<<<<<<<< + * skip = skip + self.sa.arr[i] + * i = i - self.sa.arr[i] + */ + __pyx_t_8 = ((__pyx_v_self->sa->arr[__pyx_v_i]) < 0); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":88 + * while i < N: + * if self.sa.arr[i] < 0: + * skip = skip + self.sa.arr[i] # <<<<<<<<<<<<<< + * i = i - self.sa.arr[i] + * else: + */ + __pyx_v_skip = (__pyx_v_skip + (__pyx_v_self->sa->arr[__pyx_v_i])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":89 + * if self.sa.arr[i] < 0: + * skip = skip + self.sa.arr[i] + * i = i - self.sa.arr[i] # <<<<<<<<<<<<<< + * else: + * if skip < 0: + */ + __pyx_v_i = (__pyx_v_i - (__pyx_v_self->sa->arr[__pyx_v_i])); + goto __pyx_L17; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":91 + * i = i - self.sa.arr[i] + * else: + * if skip < 0: # <<<<<<<<<<<<<< + * self.sa.arr[i+skip] = skip + * skip = 0 + */ + __pyx_t_8 = (__pyx_v_skip < 0); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":92 + * else: + * if skip < 0: + * self.sa.arr[i+skip] = skip # <<<<<<<<<<<<<< + * skip = 0 + * j = isa.arr[self.sa.arr[i]] + */ + (__pyx_v_self->sa->arr[(__pyx_v_i + __pyx_v_skip)]) = __pyx_v_skip; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":93 + * if skip < 0: + * self.sa.arr[i+skip] = skip + * skip = 0 # <<<<<<<<<<<<<< + * j = isa.arr[self.sa.arr[i]] + * self.q3sort(i, j, h, isa) + */ + __pyx_v_skip = 0; + goto __pyx_L18; + } + __pyx_L18:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":94 + * self.sa.arr[i+skip] = skip + * skip = 0 + * j = isa.arr[self.sa.arr[i]] # <<<<<<<<<<<<<< + * self.q3sort(i, j, h, isa) + * i = j+1 + */ + __pyx_v_j = (__pyx_v_isa->arr[(__pyx_v_self->sa->arr[__pyx_v_i])]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":95 + * skip = 0 + * j = isa.arr[self.sa.arr[i]] + * self.q3sort(i, j, h, isa) # <<<<<<<<<<<<<< + * i = j+1 + * if skip < 0: + */ + __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__q3sort); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = PyInt_FromLong(__pyx_v_j); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_11 = PyTuple_New(4); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __Pyx_INCREF(((PyObject *)__pyx_v_isa)); + PyTuple_SET_ITEM(__pyx_t_11, 3, ((PyObject *)__pyx_v_isa)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_isa)); + __pyx_t_1 = 0; + __pyx_t_9 = 0; + __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":96 + * j = isa.arr[self.sa.arr[i]] + * self.q3sort(i, j, h, isa) + * i = j+1 # <<<<<<<<<<<<<< + * if skip < 0: + * self.sa.arr[i+skip] = skip + */ + __pyx_v_i = (__pyx_v_j + 1); + } + __pyx_L17:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":97 + * self.q3sort(i, j, h, isa) + * i = j+1 + * if skip < 0: # <<<<<<<<<<<<<< + * self.sa.arr[i+skip] = skip + * h = h * 2 + */ + __pyx_t_8 = (__pyx_v_skip < 0); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":98 + * i = j+1 + * if skip < 0: + * self.sa.arr[i+skip] = skip # <<<<<<<<<<<<<< + * h = h * 2 + * logger.debug(" Refinement took %f seconds", (monitor_cpu() - sort_start_time)) + */ + (__pyx_v_self->sa->arr[(__pyx_v_i + __pyx_v_skip)]) = __pyx_v_skip; + goto __pyx_L19; + } + __pyx_L19:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":99 + * if skip < 0: + * self.sa.arr[i+skip] = skip + * h = h * 2 # <<<<<<<<<<<<<< + * logger.debug(" Refinement took %f seconds", (monitor_cpu() - sort_start_time)) + * + */ + __pyx_v_h = (__pyx_v_h * 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":100 + * self.sa.arr[i+skip] = skip + * h = h * 2 + * logger.debug(" Refinement took %f seconds", (monitor_cpu() - sort_start_time)) # <<<<<<<<<<<<<< + * + * '''Step 3: read off suffix array from inverse suffix array''' + */ + __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_11 = PyObject_GetAttr(__pyx_t_10, __pyx_n_s__debug); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = PyFloat_FromDouble((__pyx_f_8_cdec_sa_monitor_cpu() - __pyx_v_sort_start_time)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_89)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_89)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_89)); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":103 + * + * '''Step 3: read off suffix array from inverse suffix array''' + * logger.info(" Finalizing sort...") # <<<<<<<<<<<<<< + * for i from 0 <= i < N: + * j = isa.arr[i] + */ + __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_10, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_91), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":104 + * '''Step 3: read off suffix array from inverse suffix array''' + * logger.info(" Finalizing sort...") + * for i from 0 <= i < N: # <<<<<<<<<<<<<< + * j = isa.arr[i] + * self.sa.arr[j] = i + */ + __pyx_t_4 = __pyx_v_N; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":105 + * logger.info(" Finalizing sort...") + * for i from 0 <= i < N: + * j = isa.arr[i] # <<<<<<<<<<<<<< + * self.sa.arr[j] = i + * logger.info("Suffix array construction took %f seconds", (monitor_cpu() - start_time)) + */ + __pyx_v_j = (__pyx_v_isa->arr[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":106 + * for i from 0 <= i < N: + * j = isa.arr[i] + * self.sa.arr[j] = i # <<<<<<<<<<<<<< + * logger.info("Suffix array construction took %f seconds", (monitor_cpu() - start_time)) + * + */ + (__pyx_v_self->sa->arr[__pyx_v_j]) = __pyx_v_i; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":107 + * j = isa.arr[i] + * self.sa.arr[j] = i + * logger.info("Suffix array construction took %f seconds", (monitor_cpu() - start_time)) # <<<<<<<<<<<<<< + * + * def q3sort(self, int i, int j, int h, IntList isa, pad=""): + */ + __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_10, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = PyFloat_FromDouble((__pyx_f_8_cdec_sa_monitor_cpu() - __pyx_v_start_time)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_92)); + PyTuple_SET_ITEM(__pyx_t_11, 0, ((PyObject *)__pyx_kp_s_92)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_92)); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + __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_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("_cdec_sa.SuffixArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_isa); + __Pyx_XDECREF((PyObject *)__pyx_v_word_count); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_13q3sort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_8_cdec_sa_11SuffixArray_12q3sort[] = "This is a ternary quicksort. It divides the array into\n three partitions: items less than the pivot, items equal\n to pivot, and items greater than pivot. The first and last\n of these partitions are then recursively sorted"; +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_13q3sort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_h; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_isa = 0; + PyObject *__pyx_v_pad = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__i,&__pyx_n_s__j,&__pyx_n_s__h,&__pyx_n_s__isa,&__pyx_n_s__pad,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("q3sort (wrapper)", 0); + { + PyObject* values[5] = {0,0,0,0,0}; + values[4] = ((PyObject *)__pyx_kp_s_42); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__i); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__j); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("q3sort", 0, 4, 5, 1); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__h); + if (likely(values[2])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("q3sort", 0, 4, 5, 2); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 3: + values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__isa); + if (likely(values[3])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("q3sort", 0, 4, 5, 3); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pad); + if (value) { values[4] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "q3sort") < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_i = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_i == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_j = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_j == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_h = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_h == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_isa = ((struct __pyx_obj_8_cdec_sa_IntList *)values[3]); + __pyx_v_pad = values[4]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("q3sort", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.SuffixArray.q3sort", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_isa), __pyx_ptype_8_cdec_sa_IntList, 1, "isa", 0))) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_12q3sort(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), __pyx_v_i, __pyx_v_j, __pyx_v_h, __pyx_v_isa, __pyx_v_pad); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":109 + * logger.info("Suffix array construction took %f seconds", (monitor_cpu() - start_time)) + * + * def q3sort(self, int i, int j, int h, IntList isa, pad=""): # <<<<<<<<<<<<<< + * '''This is a ternary quicksort. It divides the array into + * three partitions: items less than the pivot, items equal + */ + +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_12q3sort(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, int __pyx_v_i, int __pyx_v_j, int __pyx_v_h, struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_isa, PyObject *__pyx_v_pad) { + int __pyx_v_k; + int __pyx_v_midpoint; + int __pyx_v_pval; + int __pyx_v_phead; + int __pyx_v_ptail; + int __pyx_v_tmp; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + long __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("q3sort", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":116 + * cdef int k, midpoint, pval, phead, ptail, tmp + * + * if j-i < -1: # <<<<<<<<<<<<<< + * raise Exception("Unexpected condition found in q3sort: sort from %d to %d" % (i,j)) + * if j-i == -1: # recursive base case -- empty interval + */ + __pyx_t_1 = ((__pyx_v_j - __pyx_v_i) < -1); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":117 + * + * if j-i < -1: + * raise Exception("Unexpected condition found in q3sort: sort from %d to %d" % (i,j)) # <<<<<<<<<<<<<< + * if j-i == -1: # recursive base case -- empty interval + * return + */ + __pyx_t_2 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyInt_FromLong(__pyx_v_j); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_93), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__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[12]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":118 + * if j-i < -1: + * raise Exception("Unexpected condition found in q3sort: sort from %d to %d" % (i,j)) + * if j-i == -1: # recursive base case -- empty interval # <<<<<<<<<<<<<< + * return + * if (j-i == 0): # recursive base case -- singleton interval + */ + __pyx_t_1 = ((__pyx_v_j - __pyx_v_i) == -1); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":119 + * raise Exception("Unexpected condition found in q3sort: sort from %d to %d" % (i,j)) + * if j-i == -1: # recursive base case -- empty interval + * return # <<<<<<<<<<<<<< + * if (j-i == 0): # recursive base case -- singleton interval + * isa.arr[self.sa.arr[i]] = i + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":120 + * if j-i == -1: # recursive base case -- empty interval + * return + * if (j-i == 0): # recursive base case -- singleton interval # <<<<<<<<<<<<<< + * isa.arr[self.sa.arr[i]] = i + * self.sa.arr[i] = -1 + */ + __pyx_t_1 = ((__pyx_v_j - __pyx_v_i) == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":121 + * return + * if (j-i == 0): # recursive base case -- singleton interval + * isa.arr[self.sa.arr[i]] = i # <<<<<<<<<<<<<< + * self.sa.arr[i] = -1 + * return + */ + (__pyx_v_isa->arr[(__pyx_v_self->sa->arr[__pyx_v_i])]) = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":122 + * if (j-i == 0): # recursive base case -- singleton interval + * isa.arr[self.sa.arr[i]] = i + * self.sa.arr[i] = -1 # <<<<<<<<<<<<<< + * return + * + */ + (__pyx_v_self->sa->arr[__pyx_v_i]) = -1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":123 + * isa.arr[self.sa.arr[i]] = i + * self.sa.arr[i] = -1 + * return # <<<<<<<<<<<<<< + * + * # NOTE: choosing the first item as a pivot value resulted in + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":132 + * # If the method of assigning word_id's is changed, this method + * # may need to be reconsidered as well. + * midpoint = (i+j)/2 # <<<<<<<<<<<<<< + * pval = isa.arr[self.sa.arr[midpoint] + h] + * if i != midpoint: + */ + __pyx_v_midpoint = __Pyx_div_long((__pyx_v_i + __pyx_v_j), 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":133 + * # may need to be reconsidered as well. + * midpoint = (i+j)/2 + * pval = isa.arr[self.sa.arr[midpoint] + h] # <<<<<<<<<<<<<< + * if i != midpoint: + * tmp = self.sa.arr[midpoint] + */ + __pyx_v_pval = (__pyx_v_isa->arr[((__pyx_v_self->sa->arr[__pyx_v_midpoint]) + __pyx_v_h)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":134 + * midpoint = (i+j)/2 + * pval = isa.arr[self.sa.arr[midpoint] + h] + * if i != midpoint: # <<<<<<<<<<<<<< + * tmp = self.sa.arr[midpoint] + * self.sa.arr[midpoint] = self.sa.arr[i] + */ + __pyx_t_1 = (__pyx_v_i != __pyx_v_midpoint); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":135 + * pval = isa.arr[self.sa.arr[midpoint] + h] + * if i != midpoint: + * tmp = self.sa.arr[midpoint] # <<<<<<<<<<<<<< + * self.sa.arr[midpoint] = self.sa.arr[i] + * self.sa.arr[i] = tmp + */ + __pyx_v_tmp = (__pyx_v_self->sa->arr[__pyx_v_midpoint]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":136 + * if i != midpoint: + * tmp = self.sa.arr[midpoint] + * self.sa.arr[midpoint] = self.sa.arr[i] # <<<<<<<<<<<<<< + * self.sa.arr[i] = tmp + * phead = i + */ + (__pyx_v_self->sa->arr[__pyx_v_midpoint]) = (__pyx_v_self->sa->arr[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":137 + * tmp = self.sa.arr[midpoint] + * self.sa.arr[midpoint] = self.sa.arr[i] + * self.sa.arr[i] = tmp # <<<<<<<<<<<<<< + * phead = i + * ptail = i + */ + (__pyx_v_self->sa->arr[__pyx_v_i]) = __pyx_v_tmp; + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":138 + * self.sa.arr[midpoint] = self.sa.arr[i] + * self.sa.arr[i] = tmp + * phead = i # <<<<<<<<<<<<<< + * ptail = i + * + */ + __pyx_v_phead = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":139 + * self.sa.arr[i] = tmp + * phead = i + * ptail = i # <<<<<<<<<<<<<< + * + * # find the three partitions. phead marks the first element + */ + __pyx_v_ptail = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":143 + * # find the three partitions. phead marks the first element + * # of the middle partition, and ptail marks the last element + * for k from i+1 <= k < j+1: # <<<<<<<<<<<<<< + * if isa.arr[self.sa.arr[k] + h] < pval: + * if k > ptail+1: + */ + __pyx_t_5 = (__pyx_v_j + 1); + for (__pyx_v_k = (__pyx_v_i + 1); __pyx_v_k < __pyx_t_5; __pyx_v_k++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":144 + * # of the middle partition, and ptail marks the last element + * for k from i+1 <= k < j+1: + * if isa.arr[self.sa.arr[k] + h] < pval: # <<<<<<<<<<<<<< + * if k > ptail+1: + * tmp = self.sa.arr[phead] + */ + __pyx_t_1 = ((__pyx_v_isa->arr[((__pyx_v_self->sa->arr[__pyx_v_k]) + __pyx_v_h)]) < __pyx_v_pval); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":145 + * for k from i+1 <= k < j+1: + * if isa.arr[self.sa.arr[k] + h] < pval: + * if k > ptail+1: # <<<<<<<<<<<<<< + * tmp = self.sa.arr[phead] + * self.sa.arr[phead] = self.sa.arr[k] + */ + __pyx_t_1 = (__pyx_v_k > (__pyx_v_ptail + 1)); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":146 + * if isa.arr[self.sa.arr[k] + h] < pval: + * if k > ptail+1: + * tmp = self.sa.arr[phead] # <<<<<<<<<<<<<< + * self.sa.arr[phead] = self.sa.arr[k] + * self.sa.arr[k] = self.sa.arr[ptail+1] + */ + __pyx_v_tmp = (__pyx_v_self->sa->arr[__pyx_v_phead]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":147 + * if k > ptail+1: + * tmp = self.sa.arr[phead] + * self.sa.arr[phead] = self.sa.arr[k] # <<<<<<<<<<<<<< + * self.sa.arr[k] = self.sa.arr[ptail+1] + * self.sa.arr[ptail+1] = tmp + */ + (__pyx_v_self->sa->arr[__pyx_v_phead]) = (__pyx_v_self->sa->arr[__pyx_v_k]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":148 + * tmp = self.sa.arr[phead] + * self.sa.arr[phead] = self.sa.arr[k] + * self.sa.arr[k] = self.sa.arr[ptail+1] # <<<<<<<<<<<<<< + * self.sa.arr[ptail+1] = tmp + * else: # k == ptail+1 + */ + (__pyx_v_self->sa->arr[__pyx_v_k]) = (__pyx_v_self->sa->arr[(__pyx_v_ptail + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":149 + * self.sa.arr[phead] = self.sa.arr[k] + * self.sa.arr[k] = self.sa.arr[ptail+1] + * self.sa.arr[ptail+1] = tmp # <<<<<<<<<<<<<< + * else: # k == ptail+1 + * tmp = self.sa.arr[phead] + */ + (__pyx_v_self->sa->arr[(__pyx_v_ptail + 1)]) = __pyx_v_tmp; + goto __pyx_L10; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":151 + * self.sa.arr[ptail+1] = tmp + * else: # k == ptail+1 + * tmp = self.sa.arr[phead] # <<<<<<<<<<<<<< + * self.sa.arr[phead] = self.sa.arr[k] + * self.sa.arr[k] = tmp + */ + __pyx_v_tmp = (__pyx_v_self->sa->arr[__pyx_v_phead]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":152 + * else: # k == ptail+1 + * tmp = self.sa.arr[phead] + * self.sa.arr[phead] = self.sa.arr[k] # <<<<<<<<<<<<<< + * self.sa.arr[k] = tmp + * phead = phead + 1 + */ + (__pyx_v_self->sa->arr[__pyx_v_phead]) = (__pyx_v_self->sa->arr[__pyx_v_k]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":153 + * tmp = self.sa.arr[phead] + * self.sa.arr[phead] = self.sa.arr[k] + * self.sa.arr[k] = tmp # <<<<<<<<<<<<<< + * phead = phead + 1 + * ptail = ptail + 1 + */ + (__pyx_v_self->sa->arr[__pyx_v_k]) = __pyx_v_tmp; + } + __pyx_L10:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":154 + * self.sa.arr[phead] = self.sa.arr[k] + * self.sa.arr[k] = tmp + * phead = phead + 1 # <<<<<<<<<<<<<< + * ptail = ptail + 1 + * else: + */ + __pyx_v_phead = (__pyx_v_phead + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":155 + * self.sa.arr[k] = tmp + * phead = phead + 1 + * ptail = ptail + 1 # <<<<<<<<<<<<<< + * else: + * if isa.arr[self.sa.arr[k] + h] == pval: + */ + __pyx_v_ptail = (__pyx_v_ptail + 1); + goto __pyx_L9; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":157 + * ptail = ptail + 1 + * else: + * if isa.arr[self.sa.arr[k] + h] == pval: # <<<<<<<<<<<<<< + * if k > ptail+1: + * tmp = self.sa.arr[ptail+1] + */ + __pyx_t_1 = ((__pyx_v_isa->arr[((__pyx_v_self->sa->arr[__pyx_v_k]) + __pyx_v_h)]) == __pyx_v_pval); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":158 + * else: + * if isa.arr[self.sa.arr[k] + h] == pval: + * if k > ptail+1: # <<<<<<<<<<<<<< + * tmp = self.sa.arr[ptail+1] + * self.sa.arr[ptail+1] = self.sa.arr[k] + */ + __pyx_t_1 = (__pyx_v_k > (__pyx_v_ptail + 1)); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":159 + * if isa.arr[self.sa.arr[k] + h] == pval: + * if k > ptail+1: + * tmp = self.sa.arr[ptail+1] # <<<<<<<<<<<<<< + * self.sa.arr[ptail+1] = self.sa.arr[k] + * self.sa.arr[k] = tmp + */ + __pyx_v_tmp = (__pyx_v_self->sa->arr[(__pyx_v_ptail + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":160 + * if k > ptail+1: + * tmp = self.sa.arr[ptail+1] + * self.sa.arr[ptail+1] = self.sa.arr[k] # <<<<<<<<<<<<<< + * self.sa.arr[k] = tmp + * ptail = ptail + 1 + */ + (__pyx_v_self->sa->arr[(__pyx_v_ptail + 1)]) = (__pyx_v_self->sa->arr[__pyx_v_k]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":161 + * tmp = self.sa.arr[ptail+1] + * self.sa.arr[ptail+1] = self.sa.arr[k] + * self.sa.arr[k] = tmp # <<<<<<<<<<<<<< + * ptail = ptail + 1 + * + */ + (__pyx_v_self->sa->arr[__pyx_v_k]) = __pyx_v_tmp; + goto __pyx_L12; + } + __pyx_L12:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":162 + * self.sa.arr[ptail+1] = self.sa.arr[k] + * self.sa.arr[k] = tmp + * ptail = ptail + 1 # <<<<<<<<<<<<<< + * + * # recursively sort smaller suffixes + */ + __pyx_v_ptail = (__pyx_v_ptail + 1); + goto __pyx_L11; + } + __pyx_L11:; + } + __pyx_L9:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":165 + * + * # recursively sort smaller suffixes + * self.q3sort(i, phead-1, h, isa, pad+" ") # <<<<<<<<<<<<<< + * + * # update suffixes with pivot value + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__q3sort); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyInt_FromLong((__pyx_v_phead - 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyTuple_New(5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + __Pyx_INCREF(((PyObject *)__pyx_v_isa)); + PyTuple_SET_ITEM(__pyx_t_8, 3, ((PyObject *)__pyx_v_isa)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_isa)); + PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + __pyx_t_4 = 0; + __pyx_t_2 = 0; + __pyx_t_6 = 0; + __pyx_t_7 = 0; + __pyx_t_7 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":169 + * # update suffixes with pivot value + * # corresponds to update_group function in Larsson & Sadakane + * for k from phead <= k < ptail+1: # <<<<<<<<<<<<<< + * isa.arr[self.sa.arr[k]] = ptail + * if phead == ptail: + */ + __pyx_t_5 = (__pyx_v_ptail + 1); + for (__pyx_v_k = __pyx_v_phead; __pyx_v_k < __pyx_t_5; __pyx_v_k++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":170 + * # corresponds to update_group function in Larsson & Sadakane + * for k from phead <= k < ptail+1: + * isa.arr[self.sa.arr[k]] = ptail # <<<<<<<<<<<<<< + * if phead == ptail: + * self.sa.arr[phead] = -1 + */ + (__pyx_v_isa->arr[(__pyx_v_self->sa->arr[__pyx_v_k])]) = __pyx_v_ptail; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":171 + * for k from phead <= k < ptail+1: + * isa.arr[self.sa.arr[k]] = ptail + * if phead == ptail: # <<<<<<<<<<<<<< + * self.sa.arr[phead] = -1 + * + */ + __pyx_t_1 = (__pyx_v_phead == __pyx_v_ptail); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":172 + * isa.arr[self.sa.arr[k]] = ptail + * if phead == ptail: + * self.sa.arr[phead] = -1 # <<<<<<<<<<<<<< + * + * # recursively sort larger suffixes + */ + (__pyx_v_self->sa->arr[__pyx_v_phead]) = -1; + goto __pyx_L15; + } + __pyx_L15:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":175 + * + * # recursively sort larger suffixes + * self.q3sort(ptail+1, j, h, isa, pad+" ") # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__q3sort); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyInt_FromLong((__pyx_v_ptail + 1)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = PyInt_FromLong(__pyx_v_j); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_2 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + __Pyx_INCREF(((PyObject *)__pyx_v_isa)); + PyTuple_SET_ITEM(__pyx_t_4, 3, ((PyObject *)__pyx_v_isa)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_isa)); + PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_8 = 0; + __pyx_t_3 = 0; + __pyx_t_6 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_cdec_sa.SuffixArray.q3sort", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_15write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_15write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_text (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.SuffixArray.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_14write_text(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":178 + * + * + * def write_text(self, char* filename): # <<<<<<<<<<<<<< + * self.darray.write_text(filename) + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_14write_text(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_text", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":179 + * + * def write_text(self, char* filename): + * self.darray.write_text(filename) # <<<<<<<<<<<<<< + * + * def read_binary(self, char* filename): + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->darray), __pyx_n_s__write_text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 179; __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[12]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + __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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.SuffixArray.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_17read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_17read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.SuffixArray.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_16read_binary(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":181 + * self.darray.write_text(filename) + * + * def read_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE *f + * f = fopen(filename, "r") + */ + +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_16read_binary(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":183 + * def read_binary(self, char* filename): + * cdef FILE *f + * f = fopen(filename, "r") # <<<<<<<<<<<<<< + * self.darray.read_handle(f) + * self.sa.read_handle(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":184 + * cdef FILE *f + * f = fopen(filename, "r") + * self.darray.read_handle(f) # <<<<<<<<<<<<<< + * self.sa.read_handle(f) + * self.ha.read_handle(f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_DataArray *)__pyx_v_self->darray->__pyx_vtab)->read_handle(__pyx_v_self->darray, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":185 + * f = fopen(filename, "r") + * self.darray.read_handle(f) + * self.sa.read_handle(f) # <<<<<<<<<<<<<< + * self.ha.read_handle(f) + * fclose(f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->sa->__pyx_vtab)->read_handle(__pyx_v_self->sa, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":186 + * self.darray.read_handle(f) + * self.sa.read_handle(f) + * self.ha.read_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->ha->__pyx_vtab)->read_handle(__pyx_v_self->ha, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":187 + * self.sa.read_handle(f) + * self.ha.read_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + * + * def write_binary(self, char* filename): + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_19write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_19write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.SuffixArray.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_18write_binary(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":189 + * fclose(f) + * + * def write_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "w") + */ + +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_18write_binary(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":191 + * def write_binary(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "w") # <<<<<<<<<<<<<< + * self.darray.write_handle(f) + * self.sa.write_handle(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":192 + * cdef FILE* f + * f = fopen(filename, "w") + * self.darray.write_handle(f) # <<<<<<<<<<<<<< + * self.sa.write_handle(f) + * self.ha.write_handle(f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_DataArray *)__pyx_v_self->darray->__pyx_vtab)->write_handle(__pyx_v_self->darray, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":193 + * f = fopen(filename, "w") + * self.darray.write_handle(f) + * self.sa.write_handle(f) # <<<<<<<<<<<<<< + * self.ha.write_handle(f) + * fclose(f) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->sa->__pyx_vtab)->write_handle(__pyx_v_self->sa, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":194 + * self.darray.write_handle(f) + * self.sa.write_handle(f) + * self.ha.write_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->ha->__pyx_vtab)->write_handle(__pyx_v_self->ha, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":195 + * self.sa.write_handle(f) + * self.ha.write_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + * + * def write_enhanced(self, char* filename): + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_21write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_21write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_enhanced (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.SuffixArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_20write_enhanced(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":197 + * fclose(f) + * + * def write_enhanced(self, char* filename): # <<<<<<<<<<<<<< + * with open(filename, "w") as f: + * self.darray.write_enhanced_handle(f) + */ + +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_20write_enhanced(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_v_a_i = NULL; + PyObject *__pyx_v_w_i = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + PyObject *__pyx_t_12 = NULL; + int __pyx_t_13; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_enhanced", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":198 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * self.darray.write_enhanced_handle(f) + * for a_i in self.sa: + */ + /*with:*/ { + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_f = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":199 + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: + * self.darray.write_enhanced_handle(f) # <<<<<<<<<<<<<< + * for a_i in self.sa: + * f.write("%d " % a_i) + */ + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self->darray), __pyx_n_s_24); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_f); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_f); + __Pyx_GIVEREF(__pyx_v_f); + __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":200 + * with open(filename, "w") as f: + * self.darray.write_enhanced_handle(f) + * for a_i in self.sa: # <<<<<<<<<<<<<< + * f.write("%d " % a_i) + * f.write("\n") + */ + if (PyList_CheckExact(((PyObject *)__pyx_v_self->sa)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->sa))) { + __pyx_t_2 = ((PyObject *)__pyx_v_self->sa); __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(((PyObject *)__pyx_v_self->sa)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; + } else { + __pyx_t_1 = __pyx_t_9(__pyx_t_2); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[12]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF(__pyx_v_a_i); + __pyx_v_a_i = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":201 + * self.darray.write_enhanced_handle(f) + * for a_i in self.sa: + * f.write("%d " % a_i) # <<<<<<<<<<<<<< + * f.write("\n") + * for w_i in self.ha: + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_a_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":202 + * for a_i in self.sa: + * f.write("%d " % a_i) + * f.write("\n") # <<<<<<<<<<<<<< + * for w_i in self.ha: + * f.write("%d " % w_i) + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_94), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":203 + * f.write("%d " % a_i) + * f.write("\n") + * for w_i in self.ha: # <<<<<<<<<<<<<< + * f.write("%d " % w_i) + * f.write("\n") + */ + if (PyList_CheckExact(((PyObject *)__pyx_v_self->ha)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->ha))) { + __pyx_t_4 = ((PyObject *)__pyx_v_self->ha); __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(((PyObject *)__pyx_v_self->ha)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else { + __pyx_t_2 = __pyx_t_9(__pyx_t_4); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[12]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF(__pyx_v_w_i); + __pyx_v_w_i = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":204 + * f.write("\n") + * for w_i in self.ha: + * f.write("%d " % w_i) # <<<<<<<<<<<<<< + * f.write("\n") + * + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_w_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_10)); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_10)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); + __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":205 + * for w_i in self.ha: + * f.write("%d " % w_i) + * f.write("\n") # <<<<<<<<<<<<<< + * + * cdef int __search_high(self, int word_id, int offset, int low, int high): + */ + __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_10 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_95), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":198 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * self.darray.write_enhanced_handle(f) + * for a_i in self.sa: + */ + /*except:*/ { + __Pyx_AddTraceback("_cdec_sa.SuffixArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_10, &__pyx_t_4, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_12 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_13 = (!__pyx_t_11); + if (__pyx_t_13) { + __Pyx_GIVEREF(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_ErrRestore(__pyx_t_10, __pyx_t_4, __pyx_t_1); + __pyx_t_10 = 0; __pyx_t_4 = 0; __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L22; + } + __pyx_L22:; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_96, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L23; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L23:; + } + + __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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("_cdec_sa.SuffixArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_a_i); + __Pyx_XDECREF(__pyx_v_w_i); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":207 + * f.write("\n") + * + * cdef int __search_high(self, int word_id, int offset, int low, int high): # <<<<<<<<<<<<<< + * cdef int midpoint + * + */ + +static int __pyx_f_8_cdec_sa_11SuffixArray___search_high(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, int __pyx_v_word_id, int __pyx_v_offset, int __pyx_v_low, int __pyx_v_high) { + int __pyx_v_midpoint; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__search_high", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":210 + * cdef int midpoint + * + * if low >= high: # <<<<<<<<<<<<<< + * return high + * midpoint = (high + low) / 2 + */ + __pyx_t_1 = (__pyx_v_low >= __pyx_v_high); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":211 + * + * if low >= high: + * return high # <<<<<<<<<<<<<< + * midpoint = (high + low) / 2 + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + */ + __pyx_r = __pyx_v_high; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":212 + * if low >= high: + * return high + * midpoint = (high + low) / 2 # <<<<<<<<<<<<<< + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + * return self.__search_high(word_id, offset, midpoint+1, high) + */ + __pyx_v_midpoint = __Pyx_div_long((__pyx_v_high + __pyx_v_low), 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":213 + * return high + * midpoint = (high + low) / 2 + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: # <<<<<<<<<<<<<< + * return self.__search_high(word_id, offset, midpoint+1, high) + * else: + */ + __pyx_t_1 = ((__pyx_v_self->darray->data->arr[((__pyx_v_self->sa->arr[__pyx_v_midpoint]) + __pyx_v_offset)]) == __pyx_v_word_id); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":214 + * midpoint = (high + low) / 2 + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + * return self.__search_high(word_id, offset, midpoint+1, high) # <<<<<<<<<<<<<< + * else: + * return self.__search_high(word_id, offset, low, midpoint) + */ + __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___search_high(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, (__pyx_v_midpoint + 1), __pyx_v_high); + goto __pyx_L0; + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":216 + * return self.__search_high(word_id, offset, midpoint+1, high) + * else: + * return self.__search_high(word_id, offset, low, midpoint) # <<<<<<<<<<<<<< + * + * cdef int __search_low(self, int word_id, int offset, int low, int high): + */ + __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___search_high(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, __pyx_v_low, __pyx_v_midpoint); + goto __pyx_L0; + } + __pyx_L4:; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":218 + * return self.__search_high(word_id, offset, low, midpoint) + * + * cdef int __search_low(self, int word_id, int offset, int low, int high): # <<<<<<<<<<<<<< + * cdef int midpoint + * + */ + +static int __pyx_f_8_cdec_sa_11SuffixArray___search_low(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, int __pyx_v_word_id, int __pyx_v_offset, int __pyx_v_low, int __pyx_v_high) { + int __pyx_v_midpoint; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__search_low", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":221 + * cdef int midpoint + * + * if low >= high: # <<<<<<<<<<<<<< + * return high + * midpoint = (high + low) / 2 + */ + __pyx_t_1 = (__pyx_v_low >= __pyx_v_high); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":222 + * + * if low >= high: + * return high # <<<<<<<<<<<<<< + * midpoint = (high + low) / 2 + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + */ + __pyx_r = __pyx_v_high; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":223 + * if low >= high: + * return high + * midpoint = (high + low) / 2 # <<<<<<<<<<<<<< + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + * return self.__search_low(word_id, offset, low, midpoint) + */ + __pyx_v_midpoint = __Pyx_div_long((__pyx_v_high + __pyx_v_low), 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":224 + * return high + * midpoint = (high + low) / 2 + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: # <<<<<<<<<<<<<< + * return self.__search_low(word_id, offset, low, midpoint) + * else: + */ + __pyx_t_1 = ((__pyx_v_self->darray->data->arr[((__pyx_v_self->sa->arr[__pyx_v_midpoint]) + __pyx_v_offset)]) == __pyx_v_word_id); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":225 + * midpoint = (high + low) / 2 + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + * return self.__search_low(word_id, offset, low, midpoint) # <<<<<<<<<<<<<< + * else: + * return self.__search_low(word_id, offset, midpoint+1, high) + */ + __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___search_low(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, __pyx_v_low, __pyx_v_midpoint); + goto __pyx_L0; + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":227 + * return self.__search_low(word_id, offset, low, midpoint) + * else: + * return self.__search_low(word_id, offset, midpoint+1, high) # <<<<<<<<<<<<<< + * + * cdef __get_range(self, int word_id, int offset, int low, int high, int midpoint): + */ + __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___search_low(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, (__pyx_v_midpoint + 1), __pyx_v_high); + goto __pyx_L0; + } + __pyx_L4:; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":229 + * return self.__search_low(word_id, offset, midpoint+1, high) + * + * cdef __get_range(self, int word_id, int offset, int low, int high, int midpoint): # <<<<<<<<<<<<<< + * return (self.__search_low(word_id, offset, low, midpoint), + * self.__search_high(word_id, offset, midpoint, high)) + */ + +static PyObject *__pyx_f_8_cdec_sa_11SuffixArray___get_range(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, int __pyx_v_word_id, int __pyx_v_offset, int __pyx_v_low, int __pyx_v_high, int __pyx_v_midpoint) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get_range", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":230 + * + * cdef __get_range(self, int word_id, int offset, int low, int high, int midpoint): + * return (self.__search_low(word_id, offset, low, midpoint), # <<<<<<<<<<<<<< + * self.__search_high(word_id, offset, midpoint, high)) + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong(((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___search_low(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, __pyx_v_low, __pyx_v_midpoint)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":231 + * cdef __get_range(self, int word_id, int offset, int low, int high, int midpoint): + * return (self.__search_low(word_id, offset, low, midpoint), + * self.__search_high(word_id, offset, midpoint, high)) # <<<<<<<<<<<<<< + * + * cdef __lookup_helper(self, int word_id, int offset, int low, int high): + */ + __pyx_t_2 = PyInt_FromLong(((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___search_high(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, __pyx_v_midpoint, __pyx_v_high)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_r = ((PyObject *)__pyx_t_3); + __pyx_t_3 = 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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.SuffixArray.__get_range", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":233 + * self.__search_high(word_id, offset, midpoint, high)) + * + * cdef __lookup_helper(self, int word_id, int offset, int low, int high): # <<<<<<<<<<<<<< + * cdef int midpoint + * + */ + +static PyObject *__pyx_f_8_cdec_sa_11SuffixArray___lookup_helper(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, int __pyx_v_word_id, int __pyx_v_offset, int __pyx_v_low, int __pyx_v_high) { + int __pyx_v_midpoint; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__lookup_helper", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":236 + * cdef int midpoint + * + * if offset == 0: # <<<<<<<<<<<<<< + * return (self.ha.arr[word_id], self.ha.arr[word_id+1]) + * if low >= high: + */ + __pyx_t_1 = (__pyx_v_offset == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":237 + * + * if offset == 0: + * return (self.ha.arr[word_id], self.ha.arr[word_id+1]) # <<<<<<<<<<<<<< + * if low >= high: + * return None + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->ha->arr[__pyx_v_word_id])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyInt_FromLong((__pyx_v_self->ha->arr[(__pyx_v_word_id + 1)])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_r = ((PyObject *)__pyx_t_4); + __pyx_t_4 = 0; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":238 + * if offset == 0: + * return (self.ha.arr[word_id], self.ha.arr[word_id+1]) + * if low >= high: # <<<<<<<<<<<<<< + * return None + * + */ + __pyx_t_1 = (__pyx_v_low >= __pyx_v_high); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":239 + * return (self.ha.arr[word_id], self.ha.arr[word_id+1]) + * if low >= high: + * return None # <<<<<<<<<<<<<< + * + * midpoint = (high + low) / 2 + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_None); + __pyx_r = Py_None; + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":241 + * return None + * + * midpoint = (high + low) / 2 # <<<<<<<<<<<<<< + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + * return self.__get_range(word_id, offset, low, high, midpoint) + */ + __pyx_v_midpoint = __Pyx_div_long((__pyx_v_high + __pyx_v_low), 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":242 + * + * midpoint = (high + low) / 2 + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: # <<<<<<<<<<<<<< + * return self.__get_range(word_id, offset, low, high, midpoint) + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] > word_id: + */ + __pyx_t_1 = ((__pyx_v_self->darray->data->arr[((__pyx_v_self->sa->arr[__pyx_v_midpoint]) + __pyx_v_offset)]) == __pyx_v_word_id); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":243 + * midpoint = (high + low) / 2 + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + * return self.__get_range(word_id, offset, low, high, midpoint) # <<<<<<<<<<<<<< + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] > word_id: + * return self.__lookup_helper(word_id, offset, low, midpoint) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = ((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___get_range(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, __pyx_v_low, __pyx_v_high, __pyx_v_midpoint); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":244 + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + * return self.__get_range(word_id, offset, low, high, midpoint) + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] > word_id: # <<<<<<<<<<<<<< + * return self.__lookup_helper(word_id, offset, low, midpoint) + * else: + */ + __pyx_t_1 = ((__pyx_v_self->darray->data->arr[((__pyx_v_self->sa->arr[__pyx_v_midpoint]) + __pyx_v_offset)]) > __pyx_v_word_id); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":245 + * return self.__get_range(word_id, offset, low, high, midpoint) + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] > word_id: + * return self.__lookup_helper(word_id, offset, low, midpoint) # <<<<<<<<<<<<<< + * else: + * return self.__lookup_helper(word_id, offset, midpoint+1, high) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = ((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___lookup_helper(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, __pyx_v_low, __pyx_v_midpoint); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":247 + * return self.__lookup_helper(word_id, offset, low, midpoint) + * else: + * return self.__lookup_helper(word_id, offset, midpoint+1, high) # <<<<<<<<<<<<<< + * + * def lookup(self, word, int offset, int low, int high): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = ((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___lookup_helper(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, (__pyx_v_midpoint + 1), __pyx_v_high); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + } + __pyx_L6:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec_sa.SuffixArray.__lookup_helper", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_23lookup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_23lookup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_word = 0; + int __pyx_v_offset; + int __pyx_v_low; + int __pyx_v_high; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__word,&__pyx_n_s__offset,&__pyx_n_s__low,&__pyx_n_s__high,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("lookup (wrapper)", 0); + { + PyObject* values[4] = {0,0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__word); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__offset); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("lookup", 1, 4, 4, 1); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__low); + if (likely(values[2])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("lookup", 1, 4, 4, 2); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 3: + values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__high); + if (likely(values[3])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("lookup", 1, 4, 4, 3); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "lookup") < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + } + __pyx_v_word = values[0]; + __pyx_v_offset = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_offset == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_low = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_low == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_high = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_high == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("lookup", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.SuffixArray.lookup", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_22lookup(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), __pyx_v_word, __pyx_v_offset, __pyx_v_low, __pyx_v_high); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":249 + * return self.__lookup_helper(word_id, offset, midpoint+1, high) + * + * def lookup(self, word, int offset, int low, int high): # <<<<<<<<<<<<<< + * cdef int wordid + * if low == -1: + */ + +static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_22lookup(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_word, int __pyx_v_offset, int __pyx_v_low, int __pyx_v_high) { + PyObject *__pyx_v_word_id = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("lookup", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":251 + * def lookup(self, word, int offset, int low, int high): + * cdef int wordid + * if low == -1: # <<<<<<<<<<<<<< + * low = 0 + * if high == -1: + */ + __pyx_t_1 = (__pyx_v_low == -1); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":252 + * cdef int wordid + * if low == -1: + * low = 0 # <<<<<<<<<<<<<< + * if high == -1: + * high = len(self.sa) + */ + __pyx_v_low = 0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":253 + * if low == -1: + * low = 0 + * if high == -1: # <<<<<<<<<<<<<< + * high = len(self.sa) + * if word in self.darray.word2id: + */ + __pyx_t_1 = (__pyx_v_high == -1); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":254 + * low = 0 + * if high == -1: + * high = len(self.sa) # <<<<<<<<<<<<<< + * if word in self.darray.word2id: + * word_id = self.darray.word2id[word] + */ + __pyx_t_2 = ((PyObject *)__pyx_v_self->sa); + __Pyx_INCREF(__pyx_t_2); + __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_high = __pyx_t_3; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":255 + * if high == -1: + * high = len(self.sa) + * if word in self.darray.word2id: # <<<<<<<<<<<<<< + * word_id = self.darray.word2id[word] + * return self.__lookup_helper(word_id, offset, low, high) + */ + __pyx_t_1 = ((PySequence_Contains(__pyx_v_self->darray->word2id, __pyx_v_word))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":256 + * high = len(self.sa) + * if word in self.darray.word2id: + * word_id = self.darray.word2id[word] # <<<<<<<<<<<<<< + * return self.__lookup_helper(word_id, offset, low, high) + * else: + */ + __pyx_t_2 = PyObject_GetItem(__pyx_v_self->darray->word2id, __pyx_v_word); if (!__pyx_t_2) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_word_id = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":257 + * if word in self.darray.word2id: + * word_id = self.darray.word2id[word] + * return self.__lookup_helper(word_id, offset, low, high) # <<<<<<<<<<<<<< + * else: + * return None + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_word_id); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___lookup_helper(__pyx_v_self, __pyx_t_4, __pyx_v_offset, __pyx_v_low, __pyx_v_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":259 + * return self.__lookup_helper(word_id, offset, low, high) + * else: + * return None # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_None); + __pyx_r = Py_None; + goto __pyx_L0; + } + __pyx_L5:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec_sa.SuffixArray.lookup", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_word_id); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_8TrieNode_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_8TrieNode_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; + __pyx_r = __pyx_pf_8_cdec_sa_8TrieNode___cinit__(((struct __pyx_obj_8_cdec_sa_TrieNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":21 + * cdef public children + * + * def __cinit__(self): # <<<<<<<<<<<<<< + * self.children = {} + * + */ + +static int __pyx_pf_8_cdec_sa_8TrieNode___cinit__(struct __pyx_obj_8_cdec_sa_TrieNode *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":22 + * + * def __cinit__(self): + * self.children = {} # <<<<<<<<<<<<<< + * + * cdef class ExtendedTrieNode(TrieNode): + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_GOTREF(__pyx_v_self->children); + __Pyx_DECREF(__pyx_v_self->children); + __pyx_v_self->children = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec_sa.TrieNode.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_8TrieNode_8children_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_8TrieNode_8children_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_8TrieNode_8children___get__(((struct __pyx_obj_8_cdec_sa_TrieNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":19 + * + * cdef class TrieNode: + * cdef public children # <<<<<<<<<<<<<< + * + * def __cinit__(self): + */ + +static PyObject *__pyx_pf_8_cdec_sa_8TrieNode_8children___get__(struct __pyx_obj_8_cdec_sa_TrieNode *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->children); + __pyx_r = __pyx_v_self->children; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_8TrieNode_8children_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_8_cdec_sa_8TrieNode_8children_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_8TrieNode_8children_2__set__(((struct __pyx_obj_8_cdec_sa_TrieNode *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_8TrieNode_8children_2__set__(struct __pyx_obj_8_cdec_sa_TrieNode *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->children); + __Pyx_DECREF(__pyx_v_self->children); + __pyx_v_self->children = __pyx_v_value; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_8TrieNode_8children_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_8_cdec_sa_8TrieNode_8children_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_8TrieNode_8children_4__del__(((struct __pyx_obj_8_cdec_sa_TrieNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_8TrieNode_8children_4__del__(struct __pyx_obj_8_cdec_sa_TrieNode *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->children); + __Pyx_DECREF(__pyx_v_self->children); + __pyx_v_self->children = Py_None; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_phrase = 0; + PyObject *__pyx_v_phrase_location = 0; + PyObject *__pyx_v_suffix_link = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__phrase,&__pyx_n_s__phrase_location,&__pyx_n_s__suffix_link,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[3] = {0,0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":29 + * cdef public suffix_link + * + * def __cinit__(self, phrase=None, phrase_location=None, suffix_link=None): # <<<<<<<<<<<<<< + * self.phrase = phrase + * self.phrase_location = phrase_location + */ + values[0] = ((PyObject *)Py_None); + values[1] = ((PyObject *)Py_None); + values[2] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__phrase); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__phrase_location); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__suffix_link); + if (value) { values[2] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_phrase = values[0]; + __pyx_v_phrase_location = values[1]; + __pyx_v_suffix_link = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.ExtendedTrieNode.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode___cinit__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self), __pyx_v_phrase, __pyx_v_phrase_location, __pyx_v_suffix_link); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode___cinit__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_phrase, PyObject *__pyx_v_phrase_location, PyObject *__pyx_v_suffix_link) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":30 + * + * def __cinit__(self, phrase=None, phrase_location=None, suffix_link=None): + * self.phrase = phrase # <<<<<<<<<<<<<< + * self.phrase_location = phrase_location + * self.suffix_link = suffix_link + */ + __Pyx_INCREF(__pyx_v_phrase); + __Pyx_GIVEREF(__pyx_v_phrase); + __Pyx_GOTREF(__pyx_v_self->phrase); + __Pyx_DECREF(__pyx_v_self->phrase); + __pyx_v_self->phrase = __pyx_v_phrase; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":31 + * def __cinit__(self, phrase=None, phrase_location=None, suffix_link=None): + * self.phrase = phrase + * self.phrase_location = phrase_location # <<<<<<<<<<<<<< + * self.suffix_link = suffix_link + * + */ + __Pyx_INCREF(__pyx_v_phrase_location); + __Pyx_GIVEREF(__pyx_v_phrase_location); + __Pyx_GOTREF(__pyx_v_self->phrase_location); + __Pyx_DECREF(__pyx_v_self->phrase_location); + __pyx_v_self->phrase_location = __pyx_v_phrase_location; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":32 + * self.phrase = phrase + * self.phrase_location = phrase_location + * self.suffix_link = suffix_link # <<<<<<<<<<<<<< + * + * + */ + __Pyx_INCREF(__pyx_v_suffix_link); + __Pyx_GIVEREF(__pyx_v_suffix_link); + __Pyx_GOTREF(__pyx_v_self->suffix_link); + __Pyx_DECREF(__pyx_v_self->suffix_link); + __pyx_v_self->suffix_link = __pyx_v_suffix_link; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_16ExtendedTrieNode_6phrase_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_16ExtendedTrieNode_6phrase_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode_6phrase___get__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":25 + * + * cdef class ExtendedTrieNode(TrieNode): + * cdef public phrase # <<<<<<<<<<<<<< + * cdef public phrase_location + * cdef public suffix_link + */ + +static PyObject *__pyx_pf_8_cdec_sa_16ExtendedTrieNode_6phrase___get__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->phrase); + __pyx_r = __pyx_v_self->phrase; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_6phrase_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_6phrase_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode_6phrase_2__set__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_6phrase_2__set__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->phrase); + __Pyx_DECREF(__pyx_v_self->phrase); + __pyx_v_self->phrase = __pyx_v_value; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_6phrase_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_6phrase_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode_6phrase_4__del__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_6phrase_4__del__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->phrase); + __Pyx_DECREF(__pyx_v_self->phrase); + __pyx_v_self->phrase = Py_None; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_16ExtendedTrieNode_15phrase_location_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_16ExtendedTrieNode_15phrase_location_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode_15phrase_location___get__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":26 + * cdef class ExtendedTrieNode(TrieNode): + * cdef public phrase + * cdef public phrase_location # <<<<<<<<<<<<<< + * cdef public suffix_link + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_16ExtendedTrieNode_15phrase_location___get__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->phrase_location); + __pyx_r = __pyx_v_self->phrase_location; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_15phrase_location_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_15phrase_location_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode_15phrase_location_2__set__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_15phrase_location_2__set__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->phrase_location); + __Pyx_DECREF(__pyx_v_self->phrase_location); + __pyx_v_self->phrase_location = __pyx_v_value; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_15phrase_location_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_15phrase_location_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode_15phrase_location_4__del__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_15phrase_location_4__del__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->phrase_location); + __Pyx_DECREF(__pyx_v_self->phrase_location); + __pyx_v_self->phrase_location = Py_None; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_16ExtendedTrieNode_11suffix_link_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_16ExtendedTrieNode_11suffix_link_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode_11suffix_link___get__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":27 + * cdef public phrase + * cdef public phrase_location + * cdef public suffix_link # <<<<<<<<<<<<<< + * + * def __cinit__(self, phrase=None, phrase_location=None, suffix_link=None): + */ + +static PyObject *__pyx_pf_8_cdec_sa_16ExtendedTrieNode_11suffix_link___get__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->suffix_link); + __pyx_r = __pyx_v_self->suffix_link; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_11suffix_link_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_11suffix_link_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode_11suffix_link_2__set__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_11suffix_link_2__set__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->suffix_link); + __Pyx_DECREF(__pyx_v_self->suffix_link); + __pyx_v_self->suffix_link = __pyx_v_value; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_11suffix_link_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_11suffix_link_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode_11suffix_link_4__del__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_11suffix_link_4__del__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->suffix_link); + __Pyx_DECREF(__pyx_v_self->suffix_link); + __pyx_v_self->suffix_link = Py_None; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_9TrieTable_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_9TrieTable_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_extended = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__extended,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[1] = {0}; + values[0] = __pyx_k_97; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__extended); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + 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; + } + } + __pyx_v_extended = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.TrieTable.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_9TrieTable___cinit__(((struct __pyx_obj_8_cdec_sa_TrieTable *)__pyx_v_self), __pyx_v_extended); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":39 + * cdef public int count + * cdef public root + * def __cinit__(self, extended=False): # <<<<<<<<<<<<<< + * self.count = 0 + * self.extended = extended + */ + +static int __pyx_pf_8_cdec_sa_9TrieTable___cinit__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_extended) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":40 + * cdef public root + * def __cinit__(self, extended=False): + * self.count = 0 # <<<<<<<<<<<<<< + * self.extended = extended + * if extended: + */ + __pyx_v_self->count = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":41 + * def __cinit__(self, extended=False): + * self.count = 0 + * self.extended = extended # <<<<<<<<<<<<<< + * if extended: + * self.root = ExtendedTrieNode() + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_extended); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->extended = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":42 + * self.count = 0 + * self.extended = extended + * if extended: # <<<<<<<<<<<<<< + * self.root = ExtendedTrieNode() + * else: + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_extended); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":43 + * self.extended = extended + * if extended: + * self.root = ExtendedTrieNode() # <<<<<<<<<<<<<< + * else: + * self.root = TrieNode() + */ + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->root); + __Pyx_DECREF(__pyx_v_self->root); + __pyx_v_self->root = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":45 + * self.root = ExtendedTrieNode() + * else: + * self.root = TrieNode() # <<<<<<<<<<<<<< + * + * # linked list structure for storing matches in BaselineRuleFactory + */ + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_TrieNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->root); + __Pyx_DECREF(__pyx_v_self->root); + __pyx_v_self->root = __pyx_t_3; + __pyx_t_3 = 0; + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.TrieTable.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9TrieTable_8extended_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9TrieTable_8extended_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9TrieTable_8extended___get__(((struct __pyx_obj_8_cdec_sa_TrieTable *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":36 + * + * cdef class TrieTable: + * cdef public int extended # <<<<<<<<<<<<<< + * cdef public int count + * cdef public root + */ + +static PyObject *__pyx_pf_8_cdec_sa_9TrieTable_8extended___get__(struct __pyx_obj_8_cdec_sa_TrieTable *__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("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->extended); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_cdec_sa.TrieTable.extended.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_9TrieTable_8extended_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_8_cdec_sa_9TrieTable_8extended_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9TrieTable_8extended_2__set__(((struct __pyx_obj_8_cdec_sa_TrieTable *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_9TrieTable_8extended_2__set__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->extended = __pyx_t_1; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec_sa.TrieTable.extended.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9TrieTable_5count_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9TrieTable_5count_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9TrieTable_5count___get__(((struct __pyx_obj_8_cdec_sa_TrieTable *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":37 + * cdef class TrieTable: + * cdef public int extended + * cdef public int count # <<<<<<<<<<<<<< + * cdef public root + * def __cinit__(self, extended=False): + */ + +static PyObject *__pyx_pf_8_cdec_sa_9TrieTable_5count___get__(struct __pyx_obj_8_cdec_sa_TrieTable *__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("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_cdec_sa.TrieTable.count.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_9TrieTable_5count_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_8_cdec_sa_9TrieTable_5count_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9TrieTable_5count_2__set__(((struct __pyx_obj_8_cdec_sa_TrieTable *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_9TrieTable_5count_2__set__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->count = __pyx_t_1; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec_sa.TrieTable.count.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_9TrieTable_4root_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_9TrieTable_4root_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9TrieTable_4root___get__(((struct __pyx_obj_8_cdec_sa_TrieTable *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":38 + * cdef public int extended + * cdef public int count + * cdef public root # <<<<<<<<<<<<<< + * def __cinit__(self, extended=False): + * self.count = 0 + */ + +static PyObject *__pyx_pf_8_cdec_sa_9TrieTable_4root___get__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->root); + __pyx_r = __pyx_v_self->root; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_9TrieTable_4root_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_8_cdec_sa_9TrieTable_4root_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9TrieTable_4root_2__set__(((struct __pyx_obj_8_cdec_sa_TrieTable *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_9TrieTable_4root_2__set__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->root); + __Pyx_DECREF(__pyx_v_self->root); + __pyx_v_self->root = __pyx_v_value; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_9TrieTable_4root_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_8_cdec_sa_9TrieTable_4root_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_9TrieTable_4root_4__del__(((struct __pyx_obj_8_cdec_sa_TrieTable *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_8_cdec_sa_9TrieTable_4root_4__del__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->root); + __Pyx_DECREF(__pyx_v_self->root); + __pyx_v_self->root = Py_None; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":65 + * + * # returns true if sent_id is contained + * cdef int contains(self, int sent_id): # <<<<<<<<<<<<<< + * return 1 + * + */ + +static int __pyx_f_8_cdec_sa_14PhraseLocation_contains(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_self, CYTHON_UNUSED int __pyx_v_sent_id) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("contains", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":66 + * # returns true if sent_id is contained + * cdef int contains(self, int sent_id): + * return 1 # <<<<<<<<<<<<<< + * + * def __cinit__(self, int sa_low=-1, int sa_high=-1, int arr_low=-1, int arr_high=-1, + */ + __pyx_r = 1; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_14PhraseLocation_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_14PhraseLocation_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_sa_low; + int __pyx_v_sa_high; + int __pyx_v_arr_low; + int __pyx_v_arr_high; + PyObject *__pyx_v_arr = 0; + int __pyx_v_num_subpatterns; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sa_low,&__pyx_n_s__sa_high,&__pyx_n_s__arr_low,&__pyx_n_s__arr_high,&__pyx_n_s__arr,&__pyx_n_s__num_subpatterns,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[6] = {0,0,0,0,0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":69 + * + * def __cinit__(self, int sa_low=-1, int sa_high=-1, int arr_low=-1, int arr_high=-1, + * arr=None, int num_subpatterns=1): # <<<<<<<<<<<<<< + * self.sa_low = sa_low + * self.sa_high = sa_high + */ + values[4] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sa_low); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sa_high); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__arr_low); + if (value) { values[2] = value; kw_args--; } + } + case 3: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__arr_high); + if (value) { values[3] = value; kw_args--; } + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__arr); + if (value) { values[4] = value; kw_args--; } + } + case 5: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__num_subpatterns); + if (value) { values[5] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + if (values[0]) { + } else { + __pyx_v_sa_low = ((int)-1); + } + if (values[1]) { + } else { + __pyx_v_sa_high = ((int)-1); + } + if (values[2]) { + } else { + __pyx_v_arr_low = ((int)-1); + } + if (values[3]) { + } else { + __pyx_v_arr_high = ((int)-1); + } + if (values[5]) { + } else { + __pyx_v_num_subpatterns = ((int)1); + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + if (values[0]) { + __pyx_v_sa_low = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_sa_low == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_sa_low = ((int)-1); + } + if (values[1]) { + __pyx_v_sa_high = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_sa_high == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_sa_high = ((int)-1); + } + if (values[2]) { + __pyx_v_arr_low = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_arr_low == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_arr_low = ((int)-1); + } + if (values[3]) { + __pyx_v_arr_high = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_arr_high == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_arr_high = ((int)-1); + } + __pyx_v_arr = values[4]; + if (values[5]) { + __pyx_v_num_subpatterns = __Pyx_PyInt_AsInt(values[5]); if (unlikely((__pyx_v_num_subpatterns == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_num_subpatterns = ((int)1); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.PhraseLocation.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_14PhraseLocation___cinit__(((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_v_self), __pyx_v_sa_low, __pyx_v_sa_high, __pyx_v_arr_low, __pyx_v_arr_high, __pyx_v_arr, __pyx_v_num_subpatterns); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":68 + * return 1 + * + * def __cinit__(self, int sa_low=-1, int sa_high=-1, int arr_low=-1, int arr_high=-1, # <<<<<<<<<<<<<< + * arr=None, int num_subpatterns=1): + * self.sa_low = sa_low + */ + +static int __pyx_pf_8_cdec_sa_14PhraseLocation___cinit__(struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_self, int __pyx_v_sa_low, int __pyx_v_sa_high, int __pyx_v_arr_low, int __pyx_v_arr_high, PyObject *__pyx_v_arr, int __pyx_v_num_subpatterns) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":70 + * def __cinit__(self, int sa_low=-1, int sa_high=-1, int arr_low=-1, int arr_high=-1, + * arr=None, int num_subpatterns=1): + * self.sa_low = sa_low # <<<<<<<<<<<<<< + * self.sa_high = sa_high + * self.arr_low = arr_low + */ + __pyx_v_self->sa_low = __pyx_v_sa_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":71 + * arr=None, int num_subpatterns=1): + * self.sa_low = sa_low + * self.sa_high = sa_high # <<<<<<<<<<<<<< + * self.arr_low = arr_low + * self.arr_high = arr_high + */ + __pyx_v_self->sa_high = __pyx_v_sa_high; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":72 + * self.sa_low = sa_low + * self.sa_high = sa_high + * self.arr_low = arr_low # <<<<<<<<<<<<<< + * self.arr_high = arr_high + * self.arr = arr + */ + __pyx_v_self->arr_low = __pyx_v_arr_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":73 + * self.sa_high = sa_high + * self.arr_low = arr_low + * self.arr_high = arr_high # <<<<<<<<<<<<<< + * self.arr = arr + * self.num_subpatterns = num_subpatterns + */ + __pyx_v_self->arr_high = __pyx_v_arr_high; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":74 + * self.arr_low = arr_low + * self.arr_high = arr_high + * self.arr = arr # <<<<<<<<<<<<<< + * self.num_subpatterns = num_subpatterns + * + */ + if (!(likely(((__pyx_v_arr) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_arr, __pyx_ptype_8_cdec_sa_IntList))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_arr); + __Pyx_GIVEREF(__pyx_v_arr); + __Pyx_GOTREF(__pyx_v_self->arr); + __Pyx_DECREF(((PyObject *)__pyx_v_self->arr)); + __pyx_v_self->arr = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":75 + * self.arr_high = arr_high + * self.arr = arr + * self.num_subpatterns = num_subpatterns # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_self->num_subpatterns = __pyx_v_num_subpatterns; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec_sa.PhraseLocation.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_7Sampler_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_7Sampler_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_sample_size; + struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_fsarray = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sample_size,&__pyx_n_s__fsarray,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sample_size); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fsarray); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 2, 2, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_sample_size = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_sample_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_fsarray = ((struct __pyx_obj_8_cdec_sa_SuffixArray *)values[1]); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.Sampler.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fsarray), __pyx_ptype_8_cdec_sa_SuffixArray, 1, "fsarray", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_8_cdec_sa_7Sampler___cinit__(((struct __pyx_obj_8_cdec_sa_Sampler *)__pyx_v_self), __pyx_v_sample_size, __pyx_v_fsarray); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":86 + * cdef IntList sa + * + * def __cinit__(self, int sample_size, SuffixArray fsarray): # <<<<<<<<<<<<<< + * self.sample_size = sample_size + * self.sa = fsarray.sa + */ + +static int __pyx_pf_8_cdec_sa_7Sampler___cinit__(struct __pyx_obj_8_cdec_sa_Sampler *__pyx_v_self, int __pyx_v_sample_size, struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_fsarray) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":87 + * + * def __cinit__(self, int sample_size, SuffixArray fsarray): + * self.sample_size = sample_size # <<<<<<<<<<<<<< + * self.sa = fsarray.sa + * if sample_size > 0: + */ + __pyx_v_self->sample_size = __pyx_v_sample_size; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":88 + * def __cinit__(self, int sample_size, SuffixArray fsarray): + * self.sample_size = sample_size + * self.sa = fsarray.sa # <<<<<<<<<<<<<< + * if sample_size > 0: + * logger.info("Sampling strategy: uniform, max sample size = %d", sample_size) + */ + __Pyx_INCREF(((PyObject *)__pyx_v_fsarray->sa)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fsarray->sa)); + __Pyx_GOTREF(__pyx_v_self->sa); + __Pyx_DECREF(((PyObject *)__pyx_v_self->sa)); + __pyx_v_self->sa = __pyx_v_fsarray->sa; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":89 + * self.sample_size = sample_size + * self.sa = fsarray.sa + * if sample_size > 0: # <<<<<<<<<<<<<< + * logger.info("Sampling strategy: uniform, max sample size = %d", sample_size) + * else: + */ + __pyx_t_1 = (__pyx_v_sample_size > 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":90 + * self.sa = fsarray.sa + * if sample_size > 0: + * logger.info("Sampling strategy: uniform, max sample size = %d", sample_size) # <<<<<<<<<<<<<< + * else: + * logger.info("Sampling strategy: no sampling") + */ + __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__info); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyInt_FromLong(__pyx_v_sample_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_98)); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_s_98)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_98)); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":92 + * logger.info("Sampling strategy: uniform, max sample size = %d", sample_size) + * else: + * logger.info("Sampling strategy: no sampling") # <<<<<<<<<<<<<< + * + * def sample(self, PhraseLocation phrase_location): + */ + __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__info); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_100), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec_sa.Sampler.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_7Sampler_3sample(PyObject *__pyx_v_self, PyObject *__pyx_v_phrase_location); /*proto*/ +static char __pyx_doc_8_cdec_sa_7Sampler_2sample[] = "Returns a sample of the locations for\n the phrase. If there are less than self.sample_size\n locations, return all of them; otherwise, return\n up to self.sample_size locations. In the latter case,\n we choose to sample UNIFORMLY -- that is, the locations\n are chosen at uniform intervals over the entire set, rather\n than randomly. This makes the algorithm deterministic, which\n is good for things like MERT"; +static PyObject *__pyx_pw_8_cdec_sa_7Sampler_3sample(PyObject *__pyx_v_self, PyObject *__pyx_v_phrase_location) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("sample (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_phrase_location), __pyx_ptype_8_cdec_sa_PhraseLocation, 1, "phrase_location", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_8_cdec_sa_7Sampler_2sample(((struct __pyx_obj_8_cdec_sa_Sampler *)__pyx_v_self), ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_v_phrase_location)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":94 + * logger.info("Sampling strategy: no sampling") + * + * def sample(self, PhraseLocation phrase_location): # <<<<<<<<<<<<<< + * '''Returns a sample of the locations for + * the phrase. If there are less than self.sample_size + */ + +static PyObject *__pyx_pf_8_cdec_sa_7Sampler_2sample(struct __pyx_obj_8_cdec_sa_Sampler *__pyx_v_self, struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_phrase_location) { + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_sample = 0; + double __pyx_v_i; + double __pyx_v_stepsize; + int __pyx_v_num_locations; + int __pyx_v_val; + int __pyx_v_j; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("sample", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":107 + * cdef int num_locations, val, j + * + * sample = IntList() # <<<<<<<<<<<<<< + * if phrase_location.arr is None: + * num_locations = phrase_location.sa_high - phrase_location.sa_low + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sample = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":108 + * + * sample = IntList() + * if phrase_location.arr is None: # <<<<<<<<<<<<<< + * num_locations = phrase_location.sa_high - phrase_location.sa_low + * if self.sample_size == -1 or num_locations <= self.sample_size: + */ + __pyx_t_2 = (((PyObject *)__pyx_v_phrase_location->arr) == Py_None); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":109 + * sample = IntList() + * if phrase_location.arr is None: + * num_locations = phrase_location.sa_high - phrase_location.sa_low # <<<<<<<<<<<<<< + * if self.sample_size == -1 or num_locations <= self.sample_size: + * sample._extend_arr(self.sa.arr + phrase_location.sa_low, num_locations) + */ + __pyx_v_num_locations = (__pyx_v_phrase_location->sa_high - __pyx_v_phrase_location->sa_low); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":110 + * if phrase_location.arr is None: + * num_locations = phrase_location.sa_high - phrase_location.sa_low + * if self.sample_size == -1 or num_locations <= self.sample_size: # <<<<<<<<<<<<<< + * sample._extend_arr(self.sa.arr + phrase_location.sa_low, num_locations) + * else: + */ + __pyx_t_2 = (__pyx_v_self->sample_size == -1); + if (!__pyx_t_2) { + __pyx_t_3 = (__pyx_v_num_locations <= __pyx_v_self->sample_size); + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_2; + } + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":111 + * num_locations = phrase_location.sa_high - phrase_location.sa_low + * if self.sample_size == -1 or num_locations <= self.sample_size: + * sample._extend_arr(self.sa.arr + phrase_location.sa_low, num_locations) # <<<<<<<<<<<<<< + * else: + * stepsize = float(num_locations)/float(self.sample_size) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_sample->__pyx_vtab)->_extend_arr(__pyx_v_sample, (__pyx_v_self->sa->arr + __pyx_v_phrase_location->sa_low), __pyx_v_num_locations); + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":113 + * sample._extend_arr(self.sa.arr + phrase_location.sa_low, num_locations) + * else: + * stepsize = float(num_locations)/float(self.sample_size) # <<<<<<<<<<<<<< + * i = phrase_location.sa_low + * while i < phrase_location.sa_high and sample.len < self.sample_size: + */ + if (unlikely(((double)__pyx_v_self->sample_size) == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_stepsize = (((double)__pyx_v_num_locations) / ((double)__pyx_v_self->sample_size)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":114 + * else: + * stepsize = float(num_locations)/float(self.sample_size) + * i = phrase_location.sa_low # <<<<<<<<<<<<<< + * while i < phrase_location.sa_high and sample.len < self.sample_size: + * '''Note: int(i) not guaranteed to have the desired + */ + __pyx_v_i = __pyx_v_phrase_location->sa_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":115 + * stepsize = float(num_locations)/float(self.sample_size) + * i = phrase_location.sa_low + * while i < phrase_location.sa_high and sample.len < self.sample_size: # <<<<<<<<<<<<<< + * '''Note: int(i) not guaranteed to have the desired + * effect, according to the python documentation''' + */ + while (1) { + __pyx_t_4 = (__pyx_v_i < __pyx_v_phrase_location->sa_high); + if (__pyx_t_4) { + __pyx_t_2 = (__pyx_v_sample->len < __pyx_v_self->sample_size); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_4; + } + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":118 + * '''Note: int(i) not guaranteed to have the desired + * effect, according to the python documentation''' + * if fmod(i,1.0) > 0.5: # <<<<<<<<<<<<<< + * val = int(ceil(i)) + * else: + */ + __pyx_t_3 = (fmod(__pyx_v_i, 1.0) > 0.5); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":119 + * effect, according to the python documentation''' + * if fmod(i,1.0) > 0.5: + * val = int(ceil(i)) # <<<<<<<<<<<<<< + * else: + * val = int(floor(i)) + */ + __pyx_v_val = ((int)ceil(__pyx_v_i)); + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":121 + * val = int(ceil(i)) + * else: + * val = int(floor(i)) # <<<<<<<<<<<<<< + * sample._append(self.sa.arr[val]) + * i = i + stepsize + */ + __pyx_v_val = ((int)floor(__pyx_v_i)); + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":122 + * else: + * val = int(floor(i)) + * sample._append(self.sa.arr[val]) # <<<<<<<<<<<<<< + * i = i + stepsize + * else: + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_sample->__pyx_vtab)->_append(__pyx_v_sample, (__pyx_v_self->sa->arr[__pyx_v_val])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":123 + * val = int(floor(i)) + * sample._append(self.sa.arr[val]) + * i = i + stepsize # <<<<<<<<<<<<<< + * else: + * num_locations = (phrase_location.arr_high - phrase_location.arr_low) / phrase_location.num_subpatterns + */ + __pyx_v_i = (__pyx_v_i + __pyx_v_stepsize); + } + } + __pyx_L4:; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":125 + * i = i + stepsize + * else: + * num_locations = (phrase_location.arr_high - phrase_location.arr_low) / phrase_location.num_subpatterns # <<<<<<<<<<<<<< + * if self.sample_size == -1 or num_locations <= self.sample_size: + * sample = phrase_location.arr + */ + __pyx_t_5 = (__pyx_v_phrase_location->arr_high - __pyx_v_phrase_location->arr_low); + if (unlikely(__pyx_v_phrase_location->num_subpatterns == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_phrase_location->num_subpatterns == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_5))) { + PyErr_Format(PyExc_OverflowError, "value too large to perform division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_num_locations = __Pyx_div_int(__pyx_t_5, __pyx_v_phrase_location->num_subpatterns); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":126 + * else: + * num_locations = (phrase_location.arr_high - phrase_location.arr_low) / phrase_location.num_subpatterns + * if self.sample_size == -1 or num_locations <= self.sample_size: # <<<<<<<<<<<<<< + * sample = phrase_location.arr + * else: + */ + __pyx_t_3 = (__pyx_v_self->sample_size == -1); + if (!__pyx_t_3) { + __pyx_t_4 = (__pyx_v_num_locations <= __pyx_v_self->sample_size); + __pyx_t_2 = __pyx_t_4; + } else { + __pyx_t_2 = __pyx_t_3; + } + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":127 + * num_locations = (phrase_location.arr_high - phrase_location.arr_low) / phrase_location.num_subpatterns + * if self.sample_size == -1 or num_locations <= self.sample_size: + * sample = phrase_location.arr # <<<<<<<<<<<<<< + * else: + * stepsize = float(num_locations)/float(self.sample_size) + */ + __Pyx_INCREF(((PyObject *)__pyx_v_phrase_location->arr)); + __Pyx_DECREF(((PyObject *)__pyx_v_sample)); + __pyx_v_sample = __pyx_v_phrase_location->arr; + goto __pyx_L8; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":129 + * sample = phrase_location.arr + * else: + * stepsize = float(num_locations)/float(self.sample_size) # <<<<<<<<<<<<<< + * i = phrase_location.arr_low + * while i < num_locations and sample.len < self.sample_size * phrase_location.num_subpatterns: + */ + if (unlikely(((double)__pyx_v_self->sample_size) == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_stepsize = (((double)__pyx_v_num_locations) / ((double)__pyx_v_self->sample_size)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":130 + * else: + * stepsize = float(num_locations)/float(self.sample_size) + * i = phrase_location.arr_low # <<<<<<<<<<<<<< + * while i < num_locations and sample.len < self.sample_size * phrase_location.num_subpatterns: + * '''Note: int(i) not guaranteed to have the desired + */ + __pyx_v_i = __pyx_v_phrase_location->arr_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":131 + * stepsize = float(num_locations)/float(self.sample_size) + * i = phrase_location.arr_low + * while i < num_locations and sample.len < self.sample_size * phrase_location.num_subpatterns: # <<<<<<<<<<<<<< + * '''Note: int(i) not guaranteed to have the desired + * effect, according to the python documentation''' + */ + while (1) { + __pyx_t_2 = (__pyx_v_i < __pyx_v_num_locations); + if (__pyx_t_2) { + __pyx_t_3 = (__pyx_v_sample->len < (__pyx_v_self->sample_size * __pyx_v_phrase_location->num_subpatterns)); + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_2; + } + if (!__pyx_t_4) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":134 + * '''Note: int(i) not guaranteed to have the desired + * effect, according to the python documentation''' + * if fmod(i,1.0) > 0.5: # <<<<<<<<<<<<<< + * val = int(ceil(i)) + * else: + */ + __pyx_t_4 = (fmod(__pyx_v_i, 1.0) > 0.5); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":135 + * effect, according to the python documentation''' + * if fmod(i,1.0) > 0.5: + * val = int(ceil(i)) # <<<<<<<<<<<<<< + * else: + * val = int(floor(i)) + */ + __pyx_v_val = ((int)ceil(__pyx_v_i)); + goto __pyx_L11; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":137 + * val = int(ceil(i)) + * else: + * val = int(floor(i)) # <<<<<<<<<<<<<< + * j = phrase_location.arr_low + (val*phrase_location.num_subpatterns) + * sample._extend_arr(phrase_location.arr.arr + j, phrase_location.num_subpatterns) + */ + __pyx_v_val = ((int)floor(__pyx_v_i)); + } + __pyx_L11:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":138 + * else: + * val = int(floor(i)) + * j = phrase_location.arr_low + (val*phrase_location.num_subpatterns) # <<<<<<<<<<<<<< + * sample._extend_arr(phrase_location.arr.arr + j, phrase_location.num_subpatterns) + * i = i + stepsize + */ + __pyx_v_j = (__pyx_v_phrase_location->arr_low + (__pyx_v_val * __pyx_v_phrase_location->num_subpatterns)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":139 + * val = int(floor(i)) + * j = phrase_location.arr_low + (val*phrase_location.num_subpatterns) + * sample._extend_arr(phrase_location.arr.arr + j, phrase_location.num_subpatterns) # <<<<<<<<<<<<<< + * i = i + stepsize + * return sample + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_sample->__pyx_vtab)->_extend_arr(__pyx_v_sample, (__pyx_v_phrase_location->arr->arr + __pyx_v_j), __pyx_v_phrase_location->num_subpatterns); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":140 + * j = phrase_location.arr_low + (val*phrase_location.num_subpatterns) + * sample._extend_arr(phrase_location.arr.arr + j, phrase_location.num_subpatterns) + * i = i + stepsize # <<<<<<<<<<<<<< + * return sample + * + */ + __pyx_v_i = (__pyx_v_i + __pyx_v_stepsize); + } + } + __pyx_L8:; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":141 + * sample._extend_arr(phrase_location.arr.arr + j, phrase_location.num_subpatterns) + * i = i + stepsize + * return sample # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_sample)); + __pyx_r = ((PyObject *)__pyx_v_sample); + 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_sa.Sampler.sample", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_sample); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":153 + * + * + * cdef void assign_matching(Matching* m, int* arr, int start, int step, int* sent_id_arr): # <<<<<<<<<<<<<< + * m.arr = arr + * m.start = start + */ + +static void __pyx_f_8_cdec_sa_assign_matching(struct __pyx_t_8_cdec_sa_Matching *__pyx_v_m, int *__pyx_v_arr, int __pyx_v_start, int __pyx_v_step, int *__pyx_v_sent_id_arr) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("assign_matching", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":154 + * + * cdef void assign_matching(Matching* m, int* arr, int start, int step, int* sent_id_arr): + * m.arr = arr # <<<<<<<<<<<<<< + * m.start = start + * m.end = start + step + */ + __pyx_v_m->arr = __pyx_v_arr; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":155 + * cdef void assign_matching(Matching* m, int* arr, int start, int step, int* sent_id_arr): + * m.arr = arr + * m.start = start # <<<<<<<<<<<<<< + * m.end = start + step + * m.sent_id = sent_id_arr[arr[start]] + */ + __pyx_v_m->start = __pyx_v_start; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":156 + * m.arr = arr + * m.start = start + * m.end = start + step # <<<<<<<<<<<<<< + * m.sent_id = sent_id_arr[arr[start]] + * m.size = step + */ + __pyx_v_m->end = (__pyx_v_start + __pyx_v_step); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":157 + * m.start = start + * m.end = start + step + * m.sent_id = sent_id_arr[arr[start]] # <<<<<<<<<<<<<< + * m.size = step + * + */ + __pyx_v_m->sent_id = (__pyx_v_sent_id_arr[(__pyx_v_arr[__pyx_v_start])]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":158 + * m.end = start + step + * m.sent_id = sent_id_arr[arr[start]] + * m.size = step # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_m->size = __pyx_v_step; + + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":161 + * + * + * cdef int* append_combined_matching(int* arr, Matching* loc1, Matching* loc2, # <<<<<<<<<<<<<< + * int offset_by_one, int num_subpatterns, int* result_len): + * cdef int i, new_len + */ + +static int *__pyx_f_8_cdec_sa_append_combined_matching(int *__pyx_v_arr, struct __pyx_t_8_cdec_sa_Matching *__pyx_v_loc1, struct __pyx_t_8_cdec_sa_Matching *__pyx_v_loc2, CYTHON_UNUSED int __pyx_v_offset_by_one, int __pyx_v_num_subpatterns, int *__pyx_v_result_len) { + int __pyx_v_i; + int __pyx_v_new_len; + int *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + __Pyx_RefNannySetupContext("append_combined_matching", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":165 + * cdef int i, new_len + * + * new_len = result_len[0] + num_subpatterns # <<<<<<<<<<<<<< + * arr = realloc(arr, new_len*sizeof(int)) + * + */ + __pyx_v_new_len = ((__pyx_v_result_len[0]) + __pyx_v_num_subpatterns); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":166 + * + * new_len = result_len[0] + num_subpatterns + * arr = realloc(arr, new_len*sizeof(int)) # <<<<<<<<<<<<<< + * + * for i from 0 <= i < loc1.size: + */ + __pyx_v_arr = ((int *)realloc(__pyx_v_arr, (__pyx_v_new_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":168 + * arr = realloc(arr, new_len*sizeof(int)) + * + * for i from 0 <= i < loc1.size: # <<<<<<<<<<<<<< + * arr[result_len[0]+i] = loc1.arr[loc1.start+i] + * if num_subpatterns > loc1.size: + */ + __pyx_t_1 = __pyx_v_loc1->size; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":169 + * + * for i from 0 <= i < loc1.size: + * arr[result_len[0]+i] = loc1.arr[loc1.start+i] # <<<<<<<<<<<<<< + * if num_subpatterns > loc1.size: + * arr[new_len-1] = loc2.arr[loc2.end-1] + */ + (__pyx_v_arr[((__pyx_v_result_len[0]) + __pyx_v_i)]) = (__pyx_v_loc1->arr[(__pyx_v_loc1->start + __pyx_v_i)]); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":170 + * for i from 0 <= i < loc1.size: + * arr[result_len[0]+i] = loc1.arr[loc1.start+i] + * if num_subpatterns > loc1.size: # <<<<<<<<<<<<<< + * arr[new_len-1] = loc2.arr[loc2.end-1] + * result_len[0] = new_len + */ + __pyx_t_2 = (__pyx_v_num_subpatterns > __pyx_v_loc1->size); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":171 + * arr[result_len[0]+i] = loc1.arr[loc1.start+i] + * if num_subpatterns > loc1.size: + * arr[new_len-1] = loc2.arr[loc2.end-1] # <<<<<<<<<<<<<< + * result_len[0] = new_len + * return arr + */ + (__pyx_v_arr[(__pyx_v_new_len - 1)]) = (__pyx_v_loc2->arr[(__pyx_v_loc2->end - 1)]); + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":172 + * if num_subpatterns > loc1.size: + * arr[new_len-1] = loc2.arr[loc2.end-1] + * result_len[0] = new_len # <<<<<<<<<<<<<< + * return arr + * + */ + (__pyx_v_result_len[0]) = __pyx_v_new_len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":173 + * arr[new_len-1] = loc2.arr[loc2.end-1] + * result_len[0] = new_len + * return arr # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_arr; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":176 + * + * + * cdef int* extend_arr(int* arr, int* arr_len, int* appendix, int appendix_len): # <<<<<<<<<<<<<< + * cdef int new_len + * + */ + +static int *__pyx_f_8_cdec_sa_extend_arr(int *__pyx_v_arr, int *__pyx_v_arr_len, int *__pyx_v_appendix, int __pyx_v_appendix_len) { + int __pyx_v_new_len; + int *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("extend_arr", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":179 + * cdef int new_len + * + * new_len = arr_len[0] + appendix_len # <<<<<<<<<<<<<< + * arr = realloc(arr, new_len*sizeof(int)) + * memcpy(arr+arr_len[0], appendix, appendix_len*sizeof(int)) + */ + __pyx_v_new_len = ((__pyx_v_arr_len[0]) + __pyx_v_appendix_len); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":180 + * + * new_len = arr_len[0] + appendix_len + * arr = realloc(arr, new_len*sizeof(int)) # <<<<<<<<<<<<<< + * memcpy(arr+arr_len[0], appendix, appendix_len*sizeof(int)) + * arr_len[0] = new_len + */ + __pyx_v_arr = ((int *)realloc(__pyx_v_arr, (__pyx_v_new_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":181 + * new_len = arr_len[0] + appendix_len + * arr = realloc(arr, new_len*sizeof(int)) + * memcpy(arr+arr_len[0], appendix, appendix_len*sizeof(int)) # <<<<<<<<<<<<<< + * arr_len[0] = new_len + * return arr + */ + memcpy((__pyx_v_arr + (__pyx_v_arr_len[0])), __pyx_v_appendix, (__pyx_v_appendix_len * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":182 + * arr = realloc(arr, new_len*sizeof(int)) + * memcpy(arr+arr_len[0], appendix, appendix_len*sizeof(int)) + * arr_len[0] = new_len # <<<<<<<<<<<<<< + * return arr + * + */ + (__pyx_v_arr_len[0]) = __pyx_v_new_len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":183 + * memcpy(arr+arr_len[0], appendix, appendix_len*sizeof(int)) + * arr_len[0] = new_len + * return arr # <<<<<<<<<<<<<< + * + * cdef int median(int low, int high, int step): + */ + __pyx_r = __pyx_v_arr; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":185 + * return arr + * + * cdef int median(int low, int high, int step): # <<<<<<<<<<<<<< + * return low + (((high - low)/step)/2)*step + * + */ + +static int __pyx_f_8_cdec_sa_median(int __pyx_v_low, int __pyx_v_high, int __pyx_v_step) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("median", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":186 + * + * cdef int median(int low, int high, int step): + * return low + (((high - low)/step)/2)*step # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_1 = (__pyx_v_high - __pyx_v_low); + if (unlikely(__pyx_v_step == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_step == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_1))) { + PyErr_Format(PyExc_OverflowError, "value too large to perform division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_r = (__pyx_v_low + (__Pyx_div_long(__Pyx_div_int(__pyx_t_1, __pyx_v_step), 2) * __pyx_v_step)); + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("_cdec_sa.median", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":189 + * + * + * cdef void find_comparable_matchings(int low, int high, int* arr, int step, int loc, int* loc_minus, int* loc_plus): # <<<<<<<<<<<<<< + * # Returns (minus, plus) indices for the portion of the array + * # in which all matchings have the same first index as the one + */ + +static void __pyx_f_8_cdec_sa_find_comparable_matchings(int __pyx_v_low, int __pyx_v_high, int *__pyx_v_arr, int __pyx_v_step, int __pyx_v_loc, int *__pyx_v_loc_minus, int *__pyx_v_loc_plus) { + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("find_comparable_matchings", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":193 + * # in which all matchings have the same first index as the one + * # starting at loc + * loc_plus[0] = loc + step # <<<<<<<<<<<<<< + * while loc_plus[0] < high and arr[loc_plus[0]] == arr[loc]: + * loc_plus[0] = loc_plus[0] + step + */ + (__pyx_v_loc_plus[0]) = (__pyx_v_loc + __pyx_v_step); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":194 + * # starting at loc + * loc_plus[0] = loc + step + * while loc_plus[0] < high and arr[loc_plus[0]] == arr[loc]: # <<<<<<<<<<<<<< + * loc_plus[0] = loc_plus[0] + step + * loc_minus[0] = loc + */ + while (1) { + __pyx_t_1 = ((__pyx_v_loc_plus[0]) < __pyx_v_high); + if (__pyx_t_1) { + __pyx_t_2 = ((__pyx_v_arr[(__pyx_v_loc_plus[0])]) == (__pyx_v_arr[__pyx_v_loc])); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":195 + * loc_plus[0] = loc + step + * while loc_plus[0] < high and arr[loc_plus[0]] == arr[loc]: + * loc_plus[0] = loc_plus[0] + step # <<<<<<<<<<<<<< + * loc_minus[0] = loc + * while loc_minus[0]-step >= low and arr[loc_minus[0]-step] == arr[loc]: + */ + (__pyx_v_loc_plus[0]) = ((__pyx_v_loc_plus[0]) + __pyx_v_step); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":196 + * while loc_plus[0] < high and arr[loc_plus[0]] == arr[loc]: + * loc_plus[0] = loc_plus[0] + step + * loc_minus[0] = loc # <<<<<<<<<<<<<< + * while loc_minus[0]-step >= low and arr[loc_minus[0]-step] == arr[loc]: + * loc_minus[0] = loc_minus[0] - step + */ + (__pyx_v_loc_minus[0]) = __pyx_v_loc; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":197 + * loc_plus[0] = loc_plus[0] + step + * loc_minus[0] = loc + * while loc_minus[0]-step >= low and arr[loc_minus[0]-step] == arr[loc]: # <<<<<<<<<<<<<< + * loc_minus[0] = loc_minus[0] - step + * + */ + while (1) { + __pyx_t_3 = (((__pyx_v_loc_minus[0]) - __pyx_v_step) >= __pyx_v_low); + if (__pyx_t_3) { + __pyx_t_1 = ((__pyx_v_arr[((__pyx_v_loc_minus[0]) - __pyx_v_step)]) == (__pyx_v_arr[__pyx_v_loc])); + __pyx_t_2 = __pyx_t_1; + } else { + __pyx_t_2 = __pyx_t_3; + } + if (!__pyx_t_2) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":198 + * loc_minus[0] = loc + * while loc_minus[0]-step >= low and arr[loc_minus[0]-step] == arr[loc]: + * loc_minus[0] = loc_minus[0] - step # <<<<<<<<<<<<<< + * + * + */ + (__pyx_v_loc_minus[0]) = ((__pyx_v_loc_minus[0]) - __pyx_v_step); + } + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static int __pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_alignment = 0; + float __pyx_v_by_slack_factor; + char *__pyx_v_category; + PyObject *__pyx_v_max_chunks = 0; + unsigned int __pyx_v_max_initial_size; + unsigned int __pyx_v_max_length; + unsigned int __pyx_v_max_nonterminals; + PyObject *__pyx_v_max_target_chunks = 0; + PyObject *__pyx_v_max_target_length = 0; + unsigned int __pyx_v_min_gap_size; + PyObject *__pyx_v_precompute_file = 0; + unsigned int __pyx_v_precompute_secondary_rank; + unsigned int __pyx_v_precompute_rank; + int __pyx_v_require_aligned_terminal; + int __pyx_v_require_aligned_chunks; + unsigned int __pyx_v_train_max_initial_size; + unsigned int __pyx_v_train_min_gap_size; + int __pyx_v_tight_phrases; + int __pyx_v_use_baeza_yates; + int __pyx_v_use_collocations; + int __pyx_v_use_index; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__alignment,&__pyx_n_s__by_slack_factor,&__pyx_n_s__category,&__pyx_n_s__max_chunks,&__pyx_n_s__max_initial_size,&__pyx_n_s__max_length,&__pyx_n_s__max_nonterminals,&__pyx_n_s__max_target_chunks,&__pyx_n_s__max_target_length,&__pyx_n_s__min_gap_size,&__pyx_n_s__precompute_file,&__pyx_n_s_68,&__pyx_n_s__precompute_rank,&__pyx_n_s_101,&__pyx_n_s_102,&__pyx_n_s_69,&__pyx_n_s__train_min_gap_size,&__pyx_n_s__tight_phrases,&__pyx_n_s__use_baeza_yates,&__pyx_n_s__use_collocations,&__pyx_n_s__use_index,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[21] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":257 + * char* category="[X]", + * # maximum number of contiguous chunks of terminal symbols in RHS of a rule. If None, defaults to max_nonterminals+1 + * max_chunks=None, # <<<<<<<<<<<<<< + * # maximum span of a grammar rule in TEST DATA + * unsigned max_initial_size=10, + */ + values[3] = ((PyObject *)Py_None); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":265 + * unsigned max_nonterminals=2, + * # maximum number of contiguous chunks of terminal symbols in target-side RHS of a rule. If None, defaults to max_nonterminals+1 + * max_target_chunks=None, # <<<<<<<<<<<<<< + * # maximum number of target side symbols (both T and NT) allowed in a rule. If None, defaults to max_initial_size + * max_target_length=None, + */ + values[7] = ((PyObject *)Py_None); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":267 + * max_target_chunks=None, + * # maximum number of target side symbols (both T and NT) allowed in a rule. If None, defaults to max_initial_size + * max_target_length=None, # <<<<<<<<<<<<<< + * # minimum span of a nonterminal in the RHS of a rule in TEST DATA + * unsigned min_gap_size=2, + */ + values[8] = ((PyObject *)Py_None); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":271 + * unsigned min_gap_size=2, + * # filename of file containing precomputed collocations + * precompute_file=None, # <<<<<<<<<<<<<< + * # maximum frequency rank of patterns used to compute triples (don't set higher than 20). + * unsigned precompute_secondary_rank=20, + */ + values[10] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 21: values[20] = PyTuple_GET_ITEM(__pyx_args, 20); + case 20: values[19] = PyTuple_GET_ITEM(__pyx_args, 19); + case 19: values[18] = PyTuple_GET_ITEM(__pyx_args, 18); + case 18: values[17] = PyTuple_GET_ITEM(__pyx_args, 17); + case 17: values[16] = PyTuple_GET_ITEM(__pyx_args, 16); + case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15); + case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14); + case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13); + case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); + case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); + case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); + case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__alignment); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__by_slack_factor); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__category); + if (value) { values[2] = value; kw_args--; } + } + case 3: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_chunks); + if (value) { values[3] = value; kw_args--; } + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_initial_size); + if (value) { values[4] = value; kw_args--; } + } + case 5: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_length); + if (value) { values[5] = value; kw_args--; } + } + case 6: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_nonterminals); + if (value) { values[6] = value; kw_args--; } + } + case 7: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_target_chunks); + if (value) { values[7] = value; kw_args--; } + } + case 8: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_target_length); + if (value) { values[8] = value; kw_args--; } + } + case 9: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__min_gap_size); + if (value) { values[9] = value; kw_args--; } + } + case 10: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__precompute_file); + if (value) { values[10] = value; kw_args--; } + } + case 11: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_68); + if (value) { values[11] = value; kw_args--; } + } + case 12: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__precompute_rank); + if (value) { values[12] = value; kw_args--; } + } + case 13: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_101); + if (value) { values[13] = value; kw_args--; } + } + case 14: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_102); + if (value) { values[14] = value; kw_args--; } + } + case 15: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_69); + if (value) { values[15] = value; kw_args--; } + } + case 16: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__train_min_gap_size); + if (value) { values[16] = value; kw_args--; } + } + case 17: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tight_phrases); + if (value) { values[17] = value; kw_args--; } + } + case 18: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_baeza_yates); + if (value) { values[18] = value; kw_args--; } + } + case 19: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_collocations); + if (value) { values[19] = value; kw_args--; } + } + case 20: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_index); + if (value) { values[20] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + if (values[1]) { + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":253 + * Alignment alignment, + * # parameter for double-binary search; doesn't seem to matter much + * float by_slack_factor=1.0, # <<<<<<<<<<<<<< + * # name of generic nonterminal used by Hiero + * char* category="[X]", + */ + __pyx_v_by_slack_factor = ((float)1.0); + } + if (values[2]) { + } else { + __pyx_v_category = ((char *)__pyx_k_103); + } + if (values[4]) { + } else { + __pyx_v_max_initial_size = ((unsigned int)10); + } + if (values[5]) { + } else { + __pyx_v_max_length = ((unsigned int)5); + } + if (values[6]) { + } else { + __pyx_v_max_nonterminals = ((unsigned int)2); + } + if (values[9]) { + } else { + __pyx_v_min_gap_size = ((unsigned int)2); + } + if (values[11]) { + } else { + __pyx_v_precompute_secondary_rank = ((unsigned int)20); + } + if (values[12]) { + } else { + __pyx_v_precompute_rank = ((unsigned int)100); + } + if (values[13]) { + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":277 + * unsigned precompute_rank=100, + * # require extracted rules to have at least one aligned word + * bint require_aligned_terminal=True, # <<<<<<<<<<<<<< + * # require each contiguous chunk of extracted rules to have at least one aligned word + * bint require_aligned_chunks=False, + */ + __pyx_v_require_aligned_terminal = ((int)1); + } + if (values[14]) { + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":279 + * bint require_aligned_terminal=True, + * # require each contiguous chunk of extracted rules to have at least one aligned word + * bint require_aligned_chunks=False, # <<<<<<<<<<<<<< + * # maximum span of a grammar rule extracted from TRAINING DATA + * unsigned train_max_initial_size=10, + */ + __pyx_v_require_aligned_chunks = ((int)0); + } + if (values[15]) { + } else { + __pyx_v_train_max_initial_size = ((unsigned int)10); + } + if (values[16]) { + } else { + __pyx_v_train_min_gap_size = ((unsigned int)2); + } + if (values[17]) { + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":285 + * unsigned train_min_gap_size=2, + * # True if phrases should be tight, False otherwise (False == slower but better results) + * bint tight_phrases=False, # <<<<<<<<<<<<<< + * # True to require use of double-binary alg, false otherwise + * bint use_baeza_yates=True, + */ + __pyx_v_tight_phrases = ((int)0); + } + if (values[18]) { + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":287 + * bint tight_phrases=False, + * # True to require use of double-binary alg, false otherwise + * bint use_baeza_yates=True, # <<<<<<<<<<<<<< + * # True to enable used of precomputed collocations + * bint use_collocations=True, + */ + __pyx_v_use_baeza_yates = ((int)1); + } + if (values[19]) { + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":289 + * bint use_baeza_yates=True, + * # True to enable used of precomputed collocations + * bint use_collocations=True, # <<<<<<<<<<<<<< + * # True to enable use of precomputed inverted indices + * bint use_index=True): + */ + __pyx_v_use_collocations = ((int)1); + } + if (values[20]) { + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":291 + * bint use_collocations=True, + * # True to enable use of precomputed inverted indices + * bint use_index=True): # <<<<<<<<<<<<<< + * '''Note: we make a distinction between the min_gap_size + * and max_initial_size used in test and train. The latter + */ + __pyx_v_use_index = ((int)1); + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 21: values[20] = PyTuple_GET_ITEM(__pyx_args, 20); + case 20: values[19] = PyTuple_GET_ITEM(__pyx_args, 19); + case 19: values[18] = PyTuple_GET_ITEM(__pyx_args, 18); + case 18: values[17] = PyTuple_GET_ITEM(__pyx_args, 17); + case 17: values[16] = PyTuple_GET_ITEM(__pyx_args, 16); + case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15); + case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14); + case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13); + case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); + case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); + case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); + case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_alignment = ((struct __pyx_obj_8_cdec_sa_Alignment *)values[0]); + if (values[1]) { + __pyx_v_by_slack_factor = __pyx_PyFloat_AsFloat(values[1]); if (unlikely((__pyx_v_by_slack_factor == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":253 + * Alignment alignment, + * # parameter for double-binary search; doesn't seem to matter much + * float by_slack_factor=1.0, # <<<<<<<<<<<<<< + * # name of generic nonterminal used by Hiero + * char* category="[X]", + */ + __pyx_v_by_slack_factor = ((float)1.0); + } + if (values[2]) { + __pyx_v_category = PyBytes_AsString(values[2]); if (unlikely((!__pyx_v_category) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_category = ((char *)__pyx_k_103); + } + __pyx_v_max_chunks = values[3]; + if (values[4]) { + __pyx_v_max_initial_size = __Pyx_PyInt_AsUnsignedInt(values[4]); if (unlikely((__pyx_v_max_initial_size == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_max_initial_size = ((unsigned int)10); + } + if (values[5]) { + __pyx_v_max_length = __Pyx_PyInt_AsUnsignedInt(values[5]); if (unlikely((__pyx_v_max_length == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_max_length = ((unsigned int)5); + } + if (values[6]) { + __pyx_v_max_nonterminals = __Pyx_PyInt_AsUnsignedInt(values[6]); if (unlikely((__pyx_v_max_nonterminals == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_max_nonterminals = ((unsigned int)2); + } + __pyx_v_max_target_chunks = values[7]; + __pyx_v_max_target_length = values[8]; + if (values[9]) { + __pyx_v_min_gap_size = __Pyx_PyInt_AsUnsignedInt(values[9]); if (unlikely((__pyx_v_min_gap_size == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_min_gap_size = ((unsigned int)2); + } + __pyx_v_precompute_file = values[10]; + if (values[11]) { + __pyx_v_precompute_secondary_rank = __Pyx_PyInt_AsUnsignedInt(values[11]); if (unlikely((__pyx_v_precompute_secondary_rank == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_precompute_secondary_rank = ((unsigned int)20); + } + if (values[12]) { + __pyx_v_precompute_rank = __Pyx_PyInt_AsUnsignedInt(values[12]); if (unlikely((__pyx_v_precompute_rank == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_precompute_rank = ((unsigned int)100); + } + if (values[13]) { + __pyx_v_require_aligned_terminal = __Pyx_PyObject_IsTrue(values[13]); if (unlikely((__pyx_v_require_aligned_terminal == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":277 + * unsigned precompute_rank=100, + * # require extracted rules to have at least one aligned word + * bint require_aligned_terminal=True, # <<<<<<<<<<<<<< + * # require each contiguous chunk of extracted rules to have at least one aligned word + * bint require_aligned_chunks=False, + */ + __pyx_v_require_aligned_terminal = ((int)1); + } + if (values[14]) { + __pyx_v_require_aligned_chunks = __Pyx_PyObject_IsTrue(values[14]); if (unlikely((__pyx_v_require_aligned_chunks == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":279 + * bint require_aligned_terminal=True, + * # require each contiguous chunk of extracted rules to have at least one aligned word + * bint require_aligned_chunks=False, # <<<<<<<<<<<<<< + * # maximum span of a grammar rule extracted from TRAINING DATA + * unsigned train_max_initial_size=10, + */ + __pyx_v_require_aligned_chunks = ((int)0); + } + if (values[15]) { + __pyx_v_train_max_initial_size = __Pyx_PyInt_AsUnsignedInt(values[15]); if (unlikely((__pyx_v_train_max_initial_size == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_train_max_initial_size = ((unsigned int)10); + } + if (values[16]) { + __pyx_v_train_min_gap_size = __Pyx_PyInt_AsUnsignedInt(values[16]); if (unlikely((__pyx_v_train_min_gap_size == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_train_min_gap_size = ((unsigned int)2); + } + if (values[17]) { + __pyx_v_tight_phrases = __Pyx_PyObject_IsTrue(values[17]); if (unlikely((__pyx_v_tight_phrases == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":285 + * unsigned train_min_gap_size=2, + * # True if phrases should be tight, False otherwise (False == slower but better results) + * bint tight_phrases=False, # <<<<<<<<<<<<<< + * # True to require use of double-binary alg, false otherwise + * bint use_baeza_yates=True, + */ + __pyx_v_tight_phrases = ((int)0); + } + if (values[18]) { + __pyx_v_use_baeza_yates = __Pyx_PyObject_IsTrue(values[18]); if (unlikely((__pyx_v_use_baeza_yates == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":287 + * bint tight_phrases=False, + * # True to require use of double-binary alg, false otherwise + * bint use_baeza_yates=True, # <<<<<<<<<<<<<< + * # True to enable used of precomputed collocations + * bint use_collocations=True, + */ + __pyx_v_use_baeza_yates = ((int)1); + } + if (values[19]) { + __pyx_v_use_collocations = __Pyx_PyObject_IsTrue(values[19]); if (unlikely((__pyx_v_use_collocations == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":289 + * bint use_baeza_yates=True, + * # True to enable used of precomputed collocations + * bint use_collocations=True, # <<<<<<<<<<<<<< + * # True to enable use of precomputed inverted indices + * bint use_index=True): + */ + __pyx_v_use_collocations = ((int)1); + } + if (values[20]) { + __pyx_v_use_index = __Pyx_PyObject_IsTrue(values[20]); if (unlikely((__pyx_v_use_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":291 + * bint use_collocations=True, + * # True to enable use of precomputed inverted indices + * bint use_index=True): # <<<<<<<<<<<<<< + * '''Note: we make a distinction between the min_gap_size + * and max_initial_size used in test and train. The latter + */ + __pyx_v_use_index = ((int)1); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 21, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_alignment), __pyx_ptype_8_cdec_sa_Alignment, 1, "alignment", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 251; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory___cinit__(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_alignment, __pyx_v_by_slack_factor, __pyx_v_category, __pyx_v_max_chunks, __pyx_v_max_initial_size, __pyx_v_max_length, __pyx_v_max_nonterminals, __pyx_v_max_target_chunks, __pyx_v_max_target_length, __pyx_v_min_gap_size, __pyx_v_precompute_file, __pyx_v_precompute_secondary_rank, __pyx_v_precompute_rank, __pyx_v_require_aligned_terminal, __pyx_v_require_aligned_chunks, __pyx_v_train_max_initial_size, __pyx_v_train_min_gap_size, __pyx_v_tight_phrases, __pyx_v_use_baeza_yates, __pyx_v_use_collocations, __pyx_v_use_index); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":249 + * cdef IntList findexes1 + * + * def __cinit__(self, # <<<<<<<<<<<<<< + * # compiled alignment object (REQUIRED) + * Alignment alignment, + */ + +static int __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory___cinit__(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_alignment, float __pyx_v_by_slack_factor, char *__pyx_v_category, PyObject *__pyx_v_max_chunks, unsigned int __pyx_v_max_initial_size, unsigned int __pyx_v_max_length, unsigned int __pyx_v_max_nonterminals, PyObject *__pyx_v_max_target_chunks, PyObject *__pyx_v_max_target_length, unsigned int __pyx_v_min_gap_size, PyObject *__pyx_v_precompute_file, unsigned int __pyx_v_precompute_secondary_rank, unsigned int __pyx_v_precompute_rank, int __pyx_v_require_aligned_terminal, int __pyx_v_require_aligned_chunks, unsigned int __pyx_v_train_max_initial_size, unsigned int __pyx_v_train_min_gap_size, int __pyx_v_tight_phrases, int __pyx_v_use_baeza_yates, int __pyx_v_use_collocations, int __pyx_v_use_index) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":297 + * respectively. This is because Chiang's model does not require + * them to be the same, therefore we don't either.''' + * self.rules = TrieTable(True) # cache # <<<<<<<<<<<<<< + * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) + * if alignment is None: + */ + __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_TrieTable)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->rules); + __Pyx_DECREF(((PyObject *)__pyx_v_self->rules)); + __pyx_v_self->rules = ((struct __pyx_obj_8_cdec_sa_TrieTable *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":298 + * them to be the same, therefore we don't either.''' + * self.rules = TrieTable(True) # cache + * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) # <<<<<<<<<<<<<< + * if alignment is None: + * raise Exception("Must specify an alignment object") + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_PhraseLocation)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__phrase_location), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 298; __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); + __Pyx_GOTREF(__pyx_v_self->rules->root); + __Pyx_DECREF(__pyx_v_self->rules->root); + __pyx_v_self->rules->root = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":299 + * self.rules = TrieTable(True) # cache + * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) + * if alignment is None: # <<<<<<<<<<<<<< + * raise Exception("Must specify an alignment object") + * self.alignment = alignment + */ + __pyx_t_3 = (((PyObject *)__pyx_v_alignment) == Py_None); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":300 + * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) + * if alignment is None: + * raise Exception("Must specify an alignment object") # <<<<<<<<<<<<<< + * self.alignment = alignment + * + */ + __pyx_t_2 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_k_tuple_105), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":301 + * if alignment is None: + * raise Exception("Must specify an alignment object") + * self.alignment = alignment # <<<<<<<<<<<<<< + * + * # grammar parameters and settings + */ + __Pyx_INCREF(((PyObject *)__pyx_v_alignment)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_alignment)); + __Pyx_GOTREF(__pyx_v_self->alignment); + __Pyx_DECREF(((PyObject *)__pyx_v_self->alignment)); + __pyx_v_self->alignment = __pyx_v_alignment; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":305 + * # grammar parameters and settings + * # NOTE: setting max_nonterminals > 2 is not currently supported in Hiero + * self.max_length = max_length # <<<<<<<<<<<<<< + * self.max_nonterminals = max_nonterminals + * self.max_initial_size = max_initial_size + */ + __pyx_v_self->max_length = __pyx_v_max_length; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":306 + * # NOTE: setting max_nonterminals > 2 is not currently supported in Hiero + * self.max_length = max_length + * self.max_nonterminals = max_nonterminals # <<<<<<<<<<<<<< + * self.max_initial_size = max_initial_size + * self.train_max_initial_size = train_max_initial_size + */ + __pyx_v_self->max_nonterminals = __pyx_v_max_nonterminals; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":307 + * self.max_length = max_length + * self.max_nonterminals = max_nonterminals + * self.max_initial_size = max_initial_size # <<<<<<<<<<<<<< + * self.train_max_initial_size = train_max_initial_size + * self.min_gap_size = min_gap_size + */ + __pyx_v_self->max_initial_size = __pyx_v_max_initial_size; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":308 + * self.max_nonterminals = max_nonterminals + * self.max_initial_size = max_initial_size + * self.train_max_initial_size = train_max_initial_size # <<<<<<<<<<<<<< + * self.min_gap_size = min_gap_size + * self.train_min_gap_size = train_min_gap_size + */ + __pyx_v_self->train_max_initial_size = __pyx_v_train_max_initial_size; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":309 + * self.max_initial_size = max_initial_size + * self.train_max_initial_size = train_max_initial_size + * self.min_gap_size = min_gap_size # <<<<<<<<<<<<<< + * self.train_min_gap_size = train_min_gap_size + * self.category = sym_fromstring(category, False) + */ + __pyx_v_self->min_gap_size = __pyx_v_min_gap_size; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":310 + * self.train_max_initial_size = train_max_initial_size + * self.min_gap_size = min_gap_size + * self.train_min_gap_size = train_min_gap_size # <<<<<<<<<<<<<< + * self.category = sym_fromstring(category, False) + * + */ + __pyx_v_self->train_min_gap_size = __pyx_v_train_min_gap_size; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":311 + * self.min_gap_size = min_gap_size + * self.train_min_gap_size = train_min_gap_size + * self.category = sym_fromstring(category, False) # <<<<<<<<<<<<<< + * + * if max_chunks is None: + */ + __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_fromstring); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyBytes_FromString(__pyx_v_category); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_4 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 311; __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[8]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_1 = 0; + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_self->category = __pyx_t_6; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":313 + * self.category = sym_fromstring(category, False) + * + * if max_chunks is None: # <<<<<<<<<<<<<< + * self.max_chunks = self.max_nonterminals + 1 + * else: + */ + __pyx_t_3 = (__pyx_v_max_chunks == Py_None); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":314 + * + * if max_chunks is None: + * self.max_chunks = self.max_nonterminals + 1 # <<<<<<<<<<<<<< + * else: + * self.max_chunks = max_chunks + */ + __pyx_v_self->max_chunks = (__pyx_v_self->max_nonterminals + 1); + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":316 + * self.max_chunks = self.max_nonterminals + 1 + * else: + * self.max_chunks = max_chunks # <<<<<<<<<<<<<< + * + * if max_target_chunks is None: + */ + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_max_chunks); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->max_chunks = __pyx_t_6; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":318 + * self.max_chunks = max_chunks + * + * if max_target_chunks is None: # <<<<<<<<<<<<<< + * self.max_target_chunks = self.max_nonterminals + 1 + * else: + */ + __pyx_t_3 = (__pyx_v_max_target_chunks == Py_None); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":319 + * + * if max_target_chunks is None: + * self.max_target_chunks = self.max_nonterminals + 1 # <<<<<<<<<<<<<< + * else: + * self.max_target_chunks = max_target_chunks + */ + __pyx_v_self->max_target_chunks = (__pyx_v_self->max_nonterminals + 1); + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":321 + * self.max_target_chunks = self.max_nonterminals + 1 + * else: + * self.max_target_chunks = max_target_chunks # <<<<<<<<<<<<<< + * + * if max_target_length is None: + */ + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_max_target_chunks); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->max_target_chunks = __pyx_t_6; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":323 + * self.max_target_chunks = max_target_chunks + * + * if max_target_length is None: # <<<<<<<<<<<<<< + * self.max_target_length = max_initial_size + * else: + */ + __pyx_t_3 = (__pyx_v_max_target_length == Py_None); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":324 + * + * if max_target_length is None: + * self.max_target_length = max_initial_size # <<<<<<<<<<<<<< + * else: + * self.max_target_length = max_target_length + */ + __pyx_v_self->max_target_length = __pyx_v_max_initial_size; + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":326 + * self.max_target_length = max_initial_size + * else: + * self.max_target_length = max_target_length # <<<<<<<<<<<<<< + * + * # algorithmic parameters and settings + */ + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_max_target_length); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->max_target_length = __pyx_t_6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":329 + * + * # algorithmic parameters and settings + * self.precomputed_collocations = {} # <<<<<<<<<<<<<< + * self.precomputed_index = {} + * self.use_index = use_index + */ + __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __Pyx_GOTREF(__pyx_v_self->precomputed_collocations); + __Pyx_DECREF(__pyx_v_self->precomputed_collocations); + __pyx_v_self->precomputed_collocations = ((PyObject *)__pyx_t_4); + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":330 + * # algorithmic parameters and settings + * self.precomputed_collocations = {} + * self.precomputed_index = {} # <<<<<<<<<<<<<< + * self.use_index = use_index + * self.use_collocations = use_collocations + */ + __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __Pyx_GOTREF(__pyx_v_self->precomputed_index); + __Pyx_DECREF(__pyx_v_self->precomputed_index); + __pyx_v_self->precomputed_index = ((PyObject *)__pyx_t_4); + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":331 + * self.precomputed_collocations = {} + * self.precomputed_index = {} + * self.use_index = use_index # <<<<<<<<<<<<<< + * self.use_collocations = use_collocations + * self.max_rank = {} + */ + __pyx_v_self->use_index = __pyx_v_use_index; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":332 + * self.precomputed_index = {} + * self.use_index = use_index + * self.use_collocations = use_collocations # <<<<<<<<<<<<<< + * self.max_rank = {} + * self.precompute_file = precompute_file + */ + __pyx_v_self->use_collocations = __pyx_v_use_collocations; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":333 + * self.use_index = use_index + * self.use_collocations = use_collocations + * self.max_rank = {} # <<<<<<<<<<<<<< + * self.precompute_file = precompute_file + * self.precompute_rank = precompute_rank + */ + __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __Pyx_GOTREF(__pyx_v_self->max_rank); + __Pyx_DECREF(__pyx_v_self->max_rank); + __pyx_v_self->max_rank = ((PyObject *)__pyx_t_4); + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":334 + * self.use_collocations = use_collocations + * self.max_rank = {} + * self.precompute_file = precompute_file # <<<<<<<<<<<<<< + * self.precompute_rank = precompute_rank + * self.precompute_secondary_rank = precompute_secondary_rank + */ + __Pyx_INCREF(__pyx_v_precompute_file); + __Pyx_GIVEREF(__pyx_v_precompute_file); + __Pyx_GOTREF(__pyx_v_self->precompute_file); + __Pyx_DECREF(__pyx_v_self->precompute_file); + __pyx_v_self->precompute_file = __pyx_v_precompute_file; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":335 + * self.max_rank = {} + * self.precompute_file = precompute_file + * self.precompute_rank = precompute_rank # <<<<<<<<<<<<<< + * self.precompute_secondary_rank = precompute_secondary_rank + * self.use_baeza_yates = use_baeza_yates + */ + __pyx_v_self->precompute_rank = __pyx_v_precompute_rank; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":336 + * self.precompute_file = precompute_file + * self.precompute_rank = precompute_rank + * self.precompute_secondary_rank = precompute_secondary_rank # <<<<<<<<<<<<<< + * self.use_baeza_yates = use_baeza_yates + * self.by_slack_factor = by_slack_factor + */ + __pyx_v_self->precompute_secondary_rank = __pyx_v_precompute_secondary_rank; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":337 + * self.precompute_rank = precompute_rank + * self.precompute_secondary_rank = precompute_secondary_rank + * self.use_baeza_yates = use_baeza_yates # <<<<<<<<<<<<<< + * self.by_slack_factor = by_slack_factor + * if tight_phrases: + */ + __pyx_v_self->use_baeza_yates = __pyx_v_use_baeza_yates; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":338 + * self.precompute_secondary_rank = precompute_secondary_rank + * self.use_baeza_yates = use_baeza_yates + * self.by_slack_factor = by_slack_factor # <<<<<<<<<<<<<< + * if tight_phrases: + * self.tight_phrases = 1 + */ + __pyx_v_self->by_slack_factor = __pyx_v_by_slack_factor; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":339 + * self.use_baeza_yates = use_baeza_yates + * self.by_slack_factor = by_slack_factor + * if tight_phrases: # <<<<<<<<<<<<<< + * self.tight_phrases = 1 + * else: + */ + if (__pyx_v_tight_phrases) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":340 + * self.by_slack_factor = by_slack_factor + * if tight_phrases: + * self.tight_phrases = 1 # <<<<<<<<<<<<<< + * else: + * self.tight_phrases = 0 + */ + __pyx_v_self->tight_phrases = 1; + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":342 + * self.tight_phrases = 1 + * else: + * self.tight_phrases = 0 # <<<<<<<<<<<<<< + * + * if require_aligned_chunks: + */ + __pyx_v_self->tight_phrases = 0; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":344 + * self.tight_phrases = 0 + * + * if require_aligned_chunks: # <<<<<<<<<<<<<< + * # one condition is a stronger version of the other. + * self.require_aligned_chunks = 1 + */ + if (__pyx_v_require_aligned_chunks) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":346 + * if require_aligned_chunks: + * # one condition is a stronger version of the other. + * self.require_aligned_chunks = 1 # <<<<<<<<<<<<<< + * self.require_aligned_terminal = 1 + * elif require_aligned_terminal: + */ + __pyx_v_self->require_aligned_chunks = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":347 + * # one condition is a stronger version of the other. + * self.require_aligned_chunks = 1 + * self.require_aligned_terminal = 1 # <<<<<<<<<<<<<< + * elif require_aligned_terminal: + * self.require_aligned_chunks = 0 + */ + __pyx_v_self->require_aligned_terminal = 1; + goto __pyx_L8; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":348 + * self.require_aligned_chunks = 1 + * self.require_aligned_terminal = 1 + * elif require_aligned_terminal: # <<<<<<<<<<<<<< + * self.require_aligned_chunks = 0 + * self.require_aligned_terminal = 1 + */ + if (__pyx_v_require_aligned_terminal) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":349 + * self.require_aligned_terminal = 1 + * elif require_aligned_terminal: + * self.require_aligned_chunks = 0 # <<<<<<<<<<<<<< + * self.require_aligned_terminal = 1 + * else: + */ + __pyx_v_self->require_aligned_chunks = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":350 + * elif require_aligned_terminal: + * self.require_aligned_chunks = 0 + * self.require_aligned_terminal = 1 # <<<<<<<<<<<<<< + * else: + * self.require_aligned_chunks = 0 + */ + __pyx_v_self->require_aligned_terminal = 1; + goto __pyx_L8; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":352 + * self.require_aligned_terminal = 1 + * else: + * self.require_aligned_chunks = 0 # <<<<<<<<<<<<<< + * self.require_aligned_terminal = 0 + * + */ + __pyx_v_self->require_aligned_chunks = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":353 + * else: + * self.require_aligned_chunks = 0 + * self.require_aligned_terminal = 0 # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_self->require_aligned_terminal = 0; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":357 + * + * # diagnostics + * self.prev_norm_prefix = () # <<<<<<<<<<<<<< + * + * self.findexes = IntList(initial_len=10) + */ + __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); + __Pyx_GIVEREF(((PyObject *)__pyx_empty_tuple)); + __Pyx_GOTREF(__pyx_v_self->prev_norm_prefix); + __Pyx_DECREF(__pyx_v_self->prev_norm_prefix); + __pyx_v_self->prev_norm_prefix = ((PyObject *)__pyx_empty_tuple); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":359 + * self.prev_norm_prefix = () + * + * self.findexes = IntList(initial_len=10) # <<<<<<<<<<<<<< + * self.findexes1 = IntList(initial_len=10) + * + */ + __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__initial_len), __pyx_int_10) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_GIVEREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_v_self->findexes); + __Pyx_DECREF(((PyObject *)__pyx_v_self->findexes)); + __pyx_v_self->findexes = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_5); + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":360 + * + * self.findexes = IntList(initial_len=10) + * self.findexes1 = IntList(initial_len=10) # <<<<<<<<<<<<<< + * + * def configure(self, SuffixArray fsarray, DataArray edarray, Sampler sampler): + */ + __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__initial_len), __pyx_int_10) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_v_self->findexes1); + __Pyx_DECREF(((PyObject *)__pyx_v_self->findexes1)); + __pyx_v_self->findexes1 = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_4); + __pyx_t_4 = 0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_3configure(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_8_cdec_sa_23HieroCachingRuleFactory_2configure[] = "This gives the RuleFactory access to the Context object.\n Here we also use it to precompute the most expensive intersections\n in the corpus quickly."; +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_3configure(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_fsarray = 0; + struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_edarray = 0; + struct __pyx_obj_8_cdec_sa_Sampler *__pyx_v_sampler = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fsarray,&__pyx_n_s__edarray,&__pyx_n_s__sampler,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("configure (wrapper)", 0); + { + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fsarray); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__edarray); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("configure", 1, 3, 3, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sampler); + if (likely(values[2])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("configure", 1, 3, 3, 2); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "configure") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_fsarray = ((struct __pyx_obj_8_cdec_sa_SuffixArray *)values[0]); + __pyx_v_edarray = ((struct __pyx_obj_8_cdec_sa_DataArray *)values[1]); + __pyx_v_sampler = ((struct __pyx_obj_8_cdec_sa_Sampler *)values[2]); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("configure", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.configure", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fsarray), __pyx_ptype_8_cdec_sa_SuffixArray, 1, "fsarray", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_edarray), __pyx_ptype_8_cdec_sa_DataArray, 1, "edarray", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_sampler), __pyx_ptype_8_cdec_sa_Sampler, 1, "sampler", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_2configure(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_fsarray, __pyx_v_edarray, __pyx_v_sampler); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":362 + * self.findexes1 = IntList(initial_len=10) + * + * def configure(self, SuffixArray fsarray, DataArray edarray, Sampler sampler): # <<<<<<<<<<<<<< + * '''This gives the RuleFactory access to the Context object. + * Here we also use it to precompute the most expensive intersections + */ + +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_2configure(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_fsarray, struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_edarray, struct __pyx_obj_8_cdec_sa_Sampler *__pyx_v_sampler) { + 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("configure", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":366 + * Here we also use it to precompute the most expensive intersections + * in the corpus quickly.''' + * self.fsa = fsarray # <<<<<<<<<<<<<< + * self.fda = fsarray.darray + * self.eda = edarray + */ + __Pyx_INCREF(((PyObject *)__pyx_v_fsarray)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fsarray)); + __Pyx_GOTREF(__pyx_v_self->fsa); + __Pyx_DECREF(((PyObject *)__pyx_v_self->fsa)); + __pyx_v_self->fsa = __pyx_v_fsarray; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":367 + * in the corpus quickly.''' + * self.fsa = fsarray + * self.fda = fsarray.darray # <<<<<<<<<<<<<< + * self.eda = edarray + * self.fid2symid = self.set_idmap(self.fda) + */ + __Pyx_INCREF(((PyObject *)__pyx_v_fsarray->darray)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fsarray->darray)); + __Pyx_GOTREF(__pyx_v_self->fda); + __Pyx_DECREF(((PyObject *)__pyx_v_self->fda)); + __pyx_v_self->fda = __pyx_v_fsarray->darray; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":368 + * self.fsa = fsarray + * self.fda = fsarray.darray + * self.eda = edarray # <<<<<<<<<<<<<< + * self.fid2symid = self.set_idmap(self.fda) + * self.eid2symid = self.set_idmap(self.eda) + */ + __Pyx_INCREF(((PyObject *)__pyx_v_edarray)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_edarray)); + __Pyx_GOTREF(__pyx_v_self->eda); + __Pyx_DECREF(((PyObject *)__pyx_v_self->eda)); + __pyx_v_self->eda = __pyx_v_edarray; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":369 + * self.fda = fsarray.darray + * self.eda = edarray + * self.fid2symid = self.set_idmap(self.fda) # <<<<<<<<<<<<<< + * self.eid2symid = self.set_idmap(self.eda) + * self.precompute() + */ + __pyx_t_1 = ((PyObject *)__pyx_v_self->fda); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->set_idmap(__pyx_v_self, ((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_8_cdec_sa_IntList))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_v_self->fid2symid); + __Pyx_DECREF(((PyObject *)__pyx_v_self->fid2symid)); + __pyx_v_self->fid2symid = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":370 + * self.eda = edarray + * self.fid2symid = self.set_idmap(self.fda) + * self.eid2symid = self.set_idmap(self.eda) # <<<<<<<<<<<<<< + * self.precompute() + * self.sampler = sampler + */ + __pyx_t_2 = ((PyObject *)__pyx_v_self->eda); + __Pyx_INCREF(__pyx_t_2); + __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->set_idmap(__pyx_v_self, ((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8_cdec_sa_IntList))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->eid2symid); + __Pyx_DECREF(((PyObject *)__pyx_v_self->eid2symid)); + __pyx_v_self->eid2symid = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":371 + * self.fid2symid = self.set_idmap(self.fda) + * self.eid2symid = self.set_idmap(self.eda) + * self.precompute() # <<<<<<<<<<<<<< + * self.sampler = sampler + * + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__precompute); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":372 + * self.eid2symid = self.set_idmap(self.eda) + * self.precompute() + * self.sampler = sampler # <<<<<<<<<<<<<< + * + * cdef set_idmap(self, DataArray darray): + */ + __Pyx_INCREF(((PyObject *)__pyx_v_sampler)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_sampler)); + __Pyx_GOTREF(__pyx_v_self->sampler); + __Pyx_DECREF(((PyObject *)__pyx_v_self->sampler)); + __pyx_v_self->sampler = __pyx_v_sampler; + + __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_sa.HieroCachingRuleFactory.configure", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":374 + * self.sampler = sampler + * + * cdef set_idmap(self, DataArray darray): # <<<<<<<<<<<<<< + * cdef int word_id, new_word_id, N + * cdef IntList idmap + */ + +static PyObject *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_set_idmap(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_darray) { + int __pyx_v_word_id; + int __pyx_v_new_word_id; + int __pyx_v_N; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_idmap = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("set_idmap", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":378 + * cdef IntList idmap + * + * N = len(darray.id2word) # <<<<<<<<<<<<<< + * idmap = IntList(initial_len=N) + * for word_id from 0 <= word_id < N: + */ + __pyx_t_1 = __pyx_v_darray->id2word; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_N = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":379 + * + * N = len(darray.id2word) + * idmap = IntList(initial_len=N) # <<<<<<<<<<<<<< + * for word_id from 0 <= word_id < N: + * new_word_id = sym_fromstring(darray.id2word[word_id], True) + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_v_idmap = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":380 + * N = len(darray.id2word) + * idmap = IntList(initial_len=N) + * for word_id from 0 <= word_id < N: # <<<<<<<<<<<<<< + * new_word_id = sym_fromstring(darray.id2word[word_id], True) + * idmap.arr[word_id] = new_word_id + */ + __pyx_t_4 = __pyx_v_N; + for (__pyx_v_word_id = 0; __pyx_v_word_id < __pyx_t_4; __pyx_v_word_id++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":381 + * idmap = IntList(initial_len=N) + * for word_id from 0 <= word_id < N: + * new_word_id = sym_fromstring(darray.id2word[word_id], True) # <<<<<<<<<<<<<< + * idmap.arr[word_id] = new_word_id + * return idmap + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_fromstring); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_darray->id2word, __pyx_v_word_id, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_1 = 0; + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __pyx_t_7 = __Pyx_PyInt_AsInt(__pyx_t_5); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_new_word_id = __pyx_t_7; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":382 + * for word_id from 0 <= word_id < N: + * new_word_id = sym_fromstring(darray.id2word[word_id], True) + * idmap.arr[word_id] = new_word_id # <<<<<<<<<<<<<< + * return idmap + * + */ + (__pyx_v_idmap->arr[__pyx_v_word_id]) = __pyx_v_new_word_id; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":383 + * new_word_id = sym_fromstring(darray.id2word[word_id], True) + * idmap.arr[word_id] = new_word_id + * return idmap # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_idmap)); + __pyx_r = ((PyObject *)__pyx_v_idmap); + 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_3); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.set_idmap", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_idmap); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_5pattern2phrase(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_5pattern2phrase(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("pattern2phrase (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_4pattern2phrase(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), ((PyObject *)__pyx_v_pattern)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":386 + * + * + * def pattern2phrase(self, pattern): # <<<<<<<<<<<<<< + * # pattern is a tuple, which we must convert to a hiero Phrase + * result = () + */ + +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_4pattern2phrase(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_pattern) { + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_v_arity = NULL; + PyObject *__pyx_v_word_id = NULL; + PyObject *__pyx_v_new_id = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("pattern2phrase", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":388 + * def pattern2phrase(self, pattern): + * # pattern is a tuple, which we must convert to a hiero Phrase + * result = () # <<<<<<<<<<<<<< + * arity = 0 + * for word_id in pattern: + */ + __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); + __pyx_v_result = __pyx_empty_tuple; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":389 + * # pattern is a tuple, which we must convert to a hiero Phrase + * result = () + * arity = 0 # <<<<<<<<<<<<<< + * for word_id in pattern: + * if word_id == -1: + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_arity = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":390 + * result = () + * arity = 0 + * for word_id in pattern: # <<<<<<<<<<<<<< + * if word_id == -1: + * arity = arity + 1 + */ + if (PyList_CheckExact(__pyx_v_pattern) || PyTuple_CheckExact(__pyx_v_pattern)) { + __pyx_t_1 = __pyx_v_pattern; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_pattern); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_word_id); + __pyx_v_word_id = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":391 + * arity = 0 + * for word_id in pattern: + * if word_id == -1: # <<<<<<<<<<<<<< + * arity = arity + 1 + * new_id = sym_setindex(self.category, arity) + */ + __pyx_t_4 = PyObject_RichCompare(__pyx_v_word_id, __pyx_int_neg_1, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":392 + * for word_id in pattern: + * if word_id == -1: + * arity = arity + 1 # <<<<<<<<<<<<<< + * new_id = sym_setindex(self.category, arity) + * else: + */ + __pyx_t_4 = PyNumber_Add(__pyx_v_arity, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_v_arity); + __pyx_v_arity = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":393 + * if word_id == -1: + * arity = arity + 1 + * new_id = sym_setindex(self.category, arity) # <<<<<<<<<<<<<< + * else: + * new_id = sym_fromstring(self.fda.id2word[word_id], True) + */ + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_arity); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_t_6)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_v_new_id); + __pyx_v_new_id = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":395 + * new_id = sym_setindex(self.category, arity) + * else: + * new_id = sym_fromstring(self.fda.id2word[word_id], True) # <<<<<<<<<<<<<< + * result = result + (new_id,) + * return Phrase(result) + */ + __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_fromstring); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = PyObject_GetItem(__pyx_v_self->fda->id2word, __pyx_v_word_id); if (!__pyx_t_7) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_7 = 0; + __pyx_t_8 = 0; + __pyx_t_8 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_v_new_id); + __pyx_v_new_id = __pyx_t_8; + __pyx_t_8 = 0; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":396 + * else: + * new_id = sym_fromstring(self.fda.id2word[word_id], True) + * result = result + (new_id,) # <<<<<<<<<<<<<< + * return Phrase(result) + * + */ + __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(__pyx_v_new_id); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_new_id); + __Pyx_GIVEREF(__pyx_v_new_id); + __pyx_t_9 = PyNumber_Add(((PyObject *)__pyx_v_result), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_result)); + __pyx_v_result = __pyx_t_9; + __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":397 + * new_id = sym_fromstring(self.fda.id2word[word_id], True) + * result = result + (new_id,) + * return Phrase(result) # <<<<<<<<<<<<<< + * + * def pattern2phrase_plus(self, pattern): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_result)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_result)); + __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_r = __pyx_t_9; + __pyx_t_9 = 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_4); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.pattern2phrase", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_arity); + __Pyx_XDECREF(__pyx_v_word_id); + __Pyx_XDECREF(__pyx_v_new_id); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_7pattern2phrase_plus(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_7pattern2phrase_plus(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("pattern2phrase_plus (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_6pattern2phrase_plus(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), ((PyObject *)__pyx_v_pattern)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":399 + * return Phrase(result) + * + * def pattern2phrase_plus(self, pattern): # <<<<<<<<<<<<<< + * # returns a list containing both the pattern, and pattern + * # suffixed/prefixed with the NT category. + */ + +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_6pattern2phrase_plus(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_pattern) { + PyObject *__pyx_v_patterns = NULL; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_v_arity = NULL; + PyObject *__pyx_v_word_id = NULL; + PyObject *__pyx_v_new_id = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + int __pyx_t_10; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("pattern2phrase_plus", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":402 + * # returns a list containing both the pattern, and pattern + * # suffixed/prefixed with the NT category. + * patterns = [] # <<<<<<<<<<<<<< + * result = () + * arity = 0 + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_patterns = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":403 + * # suffixed/prefixed with the NT category. + * patterns = [] + * result = () # <<<<<<<<<<<<<< + * arity = 0 + * for word_id in pattern: + */ + __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); + __pyx_v_result = __pyx_empty_tuple; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":404 + * patterns = [] + * result = () + * arity = 0 # <<<<<<<<<<<<<< + * for word_id in pattern: + * if word_id == -1: + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_arity = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":405 + * result = () + * arity = 0 + * for word_id in pattern: # <<<<<<<<<<<<<< + * if word_id == -1: + * arity = arity + 1 + */ + if (PyList_CheckExact(__pyx_v_pattern) || PyTuple_CheckExact(__pyx_v_pattern)) { + __pyx_t_1 = __pyx_v_pattern; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_pattern); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_word_id); + __pyx_v_word_id = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":406 + * arity = 0 + * for word_id in pattern: + * if word_id == -1: # <<<<<<<<<<<<<< + * arity = arity + 1 + * new_id = sym_setindex(self.category, arity) + */ + __pyx_t_4 = PyObject_RichCompare(__pyx_v_word_id, __pyx_int_neg_1, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":407 + * for word_id in pattern: + * if word_id == -1: + * arity = arity + 1 # <<<<<<<<<<<<<< + * new_id = sym_setindex(self.category, arity) + * else: + */ + __pyx_t_4 = PyNumber_Add(__pyx_v_arity, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_v_arity); + __pyx_v_arity = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":408 + * if word_id == -1: + * arity = arity + 1 + * new_id = sym_setindex(self.category, arity) # <<<<<<<<<<<<<< + * else: + * new_id = sym_fromstring(self.fda.id2word[word_id], True) + */ + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_arity); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_t_6)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_v_new_id); + __pyx_v_new_id = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":410 + * new_id = sym_setindex(self.category, arity) + * else: + * new_id = sym_fromstring(self.fda.id2word[word_id], True) # <<<<<<<<<<<<<< + * result = result + (new_id,) + * patterns.append(Phrase(result)) + */ + __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_fromstring); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = PyObject_GetItem(__pyx_v_self->fda->id2word, __pyx_v_word_id); if (!__pyx_t_7) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_7 = 0; + __pyx_t_8 = 0; + __pyx_t_8 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_v_new_id); + __pyx_v_new_id = __pyx_t_8; + __pyx_t_8 = 0; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":411 + * else: + * new_id = sym_fromstring(self.fda.id2word[word_id], True) + * result = result + (new_id,) # <<<<<<<<<<<<<< + * patterns.append(Phrase(result)) + * patterns.append(Phrase(result + (sym_setindex(self.category, 1),))) + */ + __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 411; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(__pyx_v_new_id); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_new_id); + __Pyx_GIVEREF(__pyx_v_new_id); + __pyx_t_9 = PyNumber_Add(((PyObject *)__pyx_v_result), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 411; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_result)); + __pyx_v_result = __pyx_t_9; + __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":412 + * new_id = sym_fromstring(self.fda.id2word[word_id], True) + * result = result + (new_id,) + * patterns.append(Phrase(result)) # <<<<<<<<<<<<<< + * patterns.append(Phrase(result + (sym_setindex(self.category, 1),))) + * patterns.append(Phrase((sym_setindex(self.category, 1),) + result)) + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_result)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_result)); + __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_10 = PyList_Append(__pyx_v_patterns, __pyx_t_9); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":413 + * result = result + (new_id,) + * patterns.append(Phrase(result)) + * patterns.append(Phrase(result + (sym_setindex(self.category, 1),))) # <<<<<<<<<<<<<< + * patterns.append(Phrase((sym_setindex(self.category, 1),) + result)) + * return patterns + */ + __pyx_t_9 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, 1)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_9 = PyNumber_Add(((PyObject *)__pyx_v_result), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __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[8]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_9)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); + __pyx_t_9 = 0; + __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_10 = PyList_Append(__pyx_v_patterns, __pyx_t_9); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":414 + * patterns.append(Phrase(result)) + * patterns.append(Phrase(result + (sym_setindex(self.category, 1),))) + * patterns.append(Phrase((sym_setindex(self.category, 1),) + result)) # <<<<<<<<<<<<<< + * return patterns + * + */ + __pyx_t_9 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, 1)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_9 = PyNumber_Add(((PyObject *)__pyx_t_1), ((PyObject *)__pyx_v_result)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __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[8]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_9)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); + __pyx_t_9 = 0; + __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_10 = PyList_Append(__pyx_v_patterns, __pyx_t_9); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":415 + * patterns.append(Phrase(result + (sym_setindex(self.category, 1),))) + * patterns.append(Phrase((sym_setindex(self.category, 1),) + result)) + * return patterns # <<<<<<<<<<<<<< + * + * def precompute(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_patterns)); + __pyx_r = ((PyObject *)__pyx_v_patterns); + 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_4); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.pattern2phrase_plus", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_patterns); + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_arity); + __Pyx_XDECREF(__pyx_v_word_id); + __Pyx_XDECREF(__pyx_v_new_id); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_9precompute(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_9precompute(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("precompute (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_8precompute(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":417 + * return patterns + * + * def precompute(self): # <<<<<<<<<<<<<< + * cdef Precomputation pre + * + */ + +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_8precompute(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self) { + struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_pre = 0; + PyObject *__pyx_v_start_time = NULL; + PyObject *__pyx_v_pattern = NULL; + PyObject *__pyx_v_arr = NULL; + PyObject *__pyx_v_phrases = NULL; + PyObject *__pyx_v_phrase = NULL; + PyObject *__pyx_v_stop_time = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + Py_ssize_t __pyx_t_6; + PyObject *(*__pyx_t_7)(PyObject *); + PyObject *__pyx_t_8 = NULL; + PyObject *(*__pyx_t_9)(PyObject *); + Py_ssize_t __pyx_t_10; + PyObject *(*__pyx_t_11)(PyObject *); + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("precompute", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":420 + * cdef Precomputation pre + * + * if self.precompute_file is not None: # <<<<<<<<<<<<<< + * start_time = monitor_cpu() + * logger.info("Reading precomputed data from file %s... ", self.precompute_file) + */ + __pyx_t_1 = (__pyx_v_self->precompute_file != Py_None); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":421 + * + * if self.precompute_file is not None: + * start_time = monitor_cpu() # <<<<<<<<<<<<<< + * logger.info("Reading precomputed data from file %s... ", self.precompute_file) + * pre = Precomputation(from_binary=self.precompute_file) + */ + __pyx_t_2 = PyFloat_FromDouble(__pyx_f_8_cdec_sa_monitor_cpu()); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 421; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_start_time = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":422 + * if self.precompute_file is not None: + * start_time = monitor_cpu() + * logger.info("Reading precomputed data from file %s... ", self.precompute_file) # <<<<<<<<<<<<<< + * pre = Precomputation(from_binary=self.precompute_file) + * # check parameters of precomputation -- some are critical and some are not + */ + __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__info); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_106)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_106)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_106)); + __Pyx_INCREF(__pyx_v_self->precompute_file); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_self->precompute_file); + __Pyx_GIVEREF(__pyx_v_self->precompute_file); + __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":423 + * start_time = monitor_cpu() + * logger.info("Reading precomputed data from file %s... ", self.precompute_file) + * pre = Precomputation(from_binary=self.precompute_file) # <<<<<<<<<<<<<< + * # check parameters of precomputation -- some are critical and some are not + * if pre.max_nonterminals != self.max_nonterminals: + */ + __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__from_binary), __pyx_v_self->precompute_file) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Precomputation)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_v_pre = ((struct __pyx_obj_8_cdec_sa_Precomputation *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":425 + * pre = Precomputation(from_binary=self.precompute_file) + * # check parameters of precomputation -- some are critical and some are not + * if pre.max_nonterminals != self.max_nonterminals: # <<<<<<<<<<<<<< + * logger.warn("Precomputation done with max nonterminals %d, decoder uses %d", pre.max_nonterminals, self.max_nonterminals) + * if pre.max_length != self.max_length: + */ + __pyx_t_1 = (__pyx_v_pre->max_nonterminals != __pyx_v_self->max_nonterminals); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":426 + * # check parameters of precomputation -- some are critical and some are not + * if pre.max_nonterminals != self.max_nonterminals: + * logger.warn("Precomputation done with max nonterminals %d, decoder uses %d", pre.max_nonterminals, self.max_nonterminals) # <<<<<<<<<<<<<< + * if pre.max_length != self.max_length: + * logger.warn("Precomputation done with max terminals %d, decoder uses %d", pre.max_length, self.max_length) + */ + __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__warn); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyInt_FromLong(__pyx_v_pre->max_nonterminals); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyInt_FromLong(__pyx_v_self->max_nonterminals); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_107)); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_107)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_107)); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":427 + * if pre.max_nonterminals != self.max_nonterminals: + * logger.warn("Precomputation done with max nonterminals %d, decoder uses %d", pre.max_nonterminals, self.max_nonterminals) + * if pre.max_length != self.max_length: # <<<<<<<<<<<<<< + * logger.warn("Precomputation done with max terminals %d, decoder uses %d", pre.max_length, self.max_length) + * if pre.train_max_initial_size != self.train_max_initial_size: + */ + __pyx_t_1 = (__pyx_v_pre->max_length != __pyx_v_self->max_length); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":428 + * logger.warn("Precomputation done with max nonterminals %d, decoder uses %d", pre.max_nonterminals, self.max_nonterminals) + * if pre.max_length != self.max_length: + * logger.warn("Precomputation done with max terminals %d, decoder uses %d", pre.max_length, self.max_length) # <<<<<<<<<<<<<< + * if pre.train_max_initial_size != self.train_max_initial_size: + * raise Exception("Precomputation done with max initial size %d, decoder uses %d" % (pre.train_max_initial_size, self.train_max_initial_size)) + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__warn); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromLong(__pyx_v_pre->max_length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyInt_FromLong(__pyx_v_self->max_length); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_108)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_108)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_108)); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_3 = 0; + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":429 + * if pre.max_length != self.max_length: + * logger.warn("Precomputation done with max terminals %d, decoder uses %d", pre.max_length, self.max_length) + * if pre.train_max_initial_size != self.train_max_initial_size: # <<<<<<<<<<<<<< + * raise Exception("Precomputation done with max initial size %d, decoder uses %d" % (pre.train_max_initial_size, self.train_max_initial_size)) + * if pre.train_min_gap_size != self.train_min_gap_size: + */ + __pyx_t_1 = (__pyx_v_pre->train_max_initial_size != __pyx_v_self->train_max_initial_size); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":430 + * logger.warn("Precomputation done with max terminals %d, decoder uses %d", pre.max_length, self.max_length) + * if pre.train_max_initial_size != self.train_max_initial_size: + * raise Exception("Precomputation done with max initial size %d, decoder uses %d" % (pre.train_max_initial_size, self.train_max_initial_size)) # <<<<<<<<<<<<<< + * if pre.train_min_gap_size != self.train_min_gap_size: + * raise Exception("Precomputation done with min gap size %d, decoder uses %d" % (pre.train_min_gap_size, self.train_min_gap_size)) + */ + __pyx_t_4 = PyInt_FromLong(__pyx_v_pre->train_max_initial_size); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyInt_FromLong(__pyx_v_self->train_max_initial_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_4 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_109), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":431 + * if pre.train_max_initial_size != self.train_max_initial_size: + * raise Exception("Precomputation done with max initial size %d, decoder uses %d" % (pre.train_max_initial_size, self.train_max_initial_size)) + * if pre.train_min_gap_size != self.train_min_gap_size: # <<<<<<<<<<<<<< + * raise Exception("Precomputation done with min gap size %d, decoder uses %d" % (pre.train_min_gap_size, self.train_min_gap_size)) + * if self.use_index: + */ + __pyx_t_1 = (__pyx_v_pre->train_min_gap_size != __pyx_v_self->train_min_gap_size); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":432 + * raise Exception("Precomputation done with max initial size %d, decoder uses %d" % (pre.train_max_initial_size, self.train_max_initial_size)) + * if pre.train_min_gap_size != self.train_min_gap_size: + * raise Exception("Precomputation done with min gap size %d, decoder uses %d" % (pre.train_min_gap_size, self.train_min_gap_size)) # <<<<<<<<<<<<<< + * if self.use_index: + * logger.info("Converting %d hash keys on precomputed inverted index... ", len(pre.precomputed_index)) + */ + __pyx_t_2 = PyInt_FromLong(__pyx_v_pre->train_min_gap_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = PyInt_FromLong(__pyx_v_self->train_min_gap_size); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_2 = 0; + __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_110), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_5)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L7; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":433 + * if pre.train_min_gap_size != self.train_min_gap_size: + * raise Exception("Precomputation done with min gap size %d, decoder uses %d" % (pre.train_min_gap_size, self.train_min_gap_size)) + * if self.use_index: # <<<<<<<<<<<<<< + * logger.info("Converting %d hash keys on precomputed inverted index... ", len(pre.precomputed_index)) + * for pattern, arr in pre.precomputed_index.iteritems(): + */ + if (__pyx_v_self->use_index) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":434 + * raise Exception("Precomputation done with min gap size %d, decoder uses %d" % (pre.train_min_gap_size, self.train_min_gap_size)) + * if self.use_index: + * logger.info("Converting %d hash keys on precomputed inverted index... ", len(pre.precomputed_index)) # <<<<<<<<<<<<<< + * for pattern, arr in pre.precomputed_index.iteritems(): + * phrases = self.pattern2phrase_plus(pattern) + */ + __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__info); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __pyx_v_pre->precomputed_index; + __Pyx_INCREF(__pyx_t_5); + __pyx_t_6 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_111)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_111)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_111)); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":435 + * if self.use_index: + * logger.info("Converting %d hash keys on precomputed inverted index... ", len(pre.precomputed_index)) + * for pattern, arr in pre.precomputed_index.iteritems(): # <<<<<<<<<<<<<< + * phrases = self.pattern2phrase_plus(pattern) + * for phrase in phrases: + */ + __pyx_t_5 = PyObject_GetAttr(__pyx_v_pre->precomputed_index, __pyx_n_s__iteritems); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_5 = __pyx_t_2; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; + __pyx_t_7 = NULL; + } else { + __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_5)) { + if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; + } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_5)) { + if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; + } else { + __pyx_t_2 = __pyx_t_7(__pyx_t_5); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + if (likely(PyTuple_CheckExact(sequence))) { + 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[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_4 = PyList_GET_ITEM(sequence, 0); + __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_8 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; + index = 0; __pyx_t_4 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_4)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_4); + index = 1; __pyx_t_3 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_3)) goto __pyx_L11_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L12_unpacking_done; + __pyx_L11_unpacking_failed:; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L12_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_pattern); + __pyx_v_pattern = __pyx_t_4; + __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_v_arr); + __pyx_v_arr = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":436 + * logger.info("Converting %d hash keys on precomputed inverted index... ", len(pre.precomputed_index)) + * for pattern, arr in pre.precomputed_index.iteritems(): + * phrases = self.pattern2phrase_plus(pattern) # <<<<<<<<<<<<<< + * for phrase in phrases: + * self.precomputed_index[phrase] = arr + */ + __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__pattern2phrase_plus); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_pattern); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_pattern); + __Pyx_GIVEREF(__pyx_v_pattern); + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_v_phrases); + __pyx_v_phrases = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":437 + * for pattern, arr in pre.precomputed_index.iteritems(): + * phrases = self.pattern2phrase_plus(pattern) + * for phrase in phrases: # <<<<<<<<<<<<<< + * self.precomputed_index[phrase] = arr + * if self.use_collocations: + */ + if (PyList_CheckExact(__pyx_v_phrases) || PyTuple_CheckExact(__pyx_v_phrases)) { + __pyx_t_4 = __pyx_v_phrases; __Pyx_INCREF(__pyx_t_4); __pyx_t_10 = 0; + __pyx_t_11 = NULL; + } else { + __pyx_t_10 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_phrases); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_11 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_4)) break; + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_10); __Pyx_INCREF(__pyx_t_3); __pyx_t_10++; + } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_10); __Pyx_INCREF(__pyx_t_3); __pyx_t_10++; + } else { + __pyx_t_3 = __pyx_t_11(__pyx_t_4); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_phrase); + __pyx_v_phrase = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":438 + * phrases = self.pattern2phrase_plus(pattern) + * for phrase in phrases: + * self.precomputed_index[phrase] = arr # <<<<<<<<<<<<<< + * if self.use_collocations: + * logger.info("Converting %d hash keys on precomputed collocations... ", len(pre.precomputed_collocations)) + */ + if (PyObject_SetItem(__pyx_v_self->precomputed_index, __pyx_v_phrase, __pyx_v_arr) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 438; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L8; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":439 + * for phrase in phrases: + * self.precomputed_index[phrase] = arr + * if self.use_collocations: # <<<<<<<<<<<<<< + * logger.info("Converting %d hash keys on precomputed collocations... ", len(pre.precomputed_collocations)) + * for pattern, arr in pre.precomputed_collocations.iteritems(): + */ + if (__pyx_v_self->use_collocations) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":440 + * self.precomputed_index[phrase] = arr + * if self.use_collocations: + * logger.info("Converting %d hash keys on precomputed collocations... ", len(pre.precomputed_collocations)) # <<<<<<<<<<<<<< + * for pattern, arr in pre.precomputed_collocations.iteritems(): + * phrase = self.pattern2phrase(pattern) + */ + __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__info); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __pyx_v_pre->precomputed_collocations; + __Pyx_INCREF(__pyx_t_5); + __pyx_t_6 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_112)); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_112)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_112)); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":441 + * if self.use_collocations: + * logger.info("Converting %d hash keys on precomputed collocations... ", len(pre.precomputed_collocations)) + * for pattern, arr in pre.precomputed_collocations.iteritems(): # <<<<<<<<<<<<<< + * phrase = self.pattern2phrase(pattern) + * self.precomputed_collocations[phrase] = arr + */ + __pyx_t_5 = PyObject_GetAttr(__pyx_v_pre->precomputed_collocations, __pyx_n_s__iteritems); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_5 = __pyx_t_3; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; + __pyx_t_7 = NULL; + } else { + __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_5)) { + if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break; + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; + } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_5)) { + if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break; + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; + } else { + __pyx_t_3 = __pyx_t_7(__pyx_t_5); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { + PyObject* sequence = __pyx_t_3; + if (likely(PyTuple_CheckExact(sequence))) { + 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[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_4 = PyList_GET_ITEM(sequence, 0); + __pyx_t_2 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_8 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; + index = 0; __pyx_t_4 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_4)) goto __pyx_L18_unpacking_failed; + __Pyx_GOTREF(__pyx_t_4); + index = 1; __pyx_t_2 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_2)) goto __pyx_L18_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L19_unpacking_done; + __pyx_L18_unpacking_failed:; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L19_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_pattern); + __pyx_v_pattern = __pyx_t_4; + __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_v_arr); + __pyx_v_arr = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":442 + * logger.info("Converting %d hash keys on precomputed collocations... ", len(pre.precomputed_collocations)) + * for pattern, arr in pre.precomputed_collocations.iteritems(): + * phrase = self.pattern2phrase(pattern) # <<<<<<<<<<<<<< + * self.precomputed_collocations[phrase] = arr + * stop_time = monitor_cpu() + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__pattern2phrase); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_pattern); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_pattern); + __Pyx_GIVEREF(__pyx_v_pattern); + __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_v_phrase); + __pyx_v_phrase = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":443 + * for pattern, arr in pre.precomputed_collocations.iteritems(): + * phrase = self.pattern2phrase(pattern) + * self.precomputed_collocations[phrase] = arr # <<<<<<<<<<<<<< + * stop_time = monitor_cpu() + * logger.info("Processing precomputations took %f seconds", stop_time - start_time) + */ + if (PyObject_SetItem(__pyx_v_self->precomputed_collocations, __pyx_v_phrase, __pyx_v_arr) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L15; + } + __pyx_L15:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":444 + * phrase = self.pattern2phrase(pattern) + * self.precomputed_collocations[phrase] = arr + * stop_time = monitor_cpu() # <<<<<<<<<<<<<< + * logger.info("Processing precomputations took %f seconds", stop_time - start_time) + * + */ + __pyx_t_5 = PyFloat_FromDouble(__pyx_f_8_cdec_sa_monitor_cpu()); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_v_stop_time = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":445 + * self.precomputed_collocations[phrase] = arr + * stop_time = monitor_cpu() + * logger.info("Processing precomputations took %f seconds", stop_time - start_time) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__info); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Subtract(__pyx_v_stop_time, __pyx_v_start_time); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_113)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_113)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_113)); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.precompute", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_pre); + __Pyx_XDECREF(__pyx_v_start_time); + __Pyx_XDECREF(__pyx_v_pattern); + __Pyx_XDECREF(__pyx_v_arr); + __Pyx_XDECREF(__pyx_v_phrases); + __Pyx_XDECREF(__pyx_v_phrase); + __Pyx_XDECREF(__pyx_v_stop_time); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_11get_precomputed_collocation(PyObject *__pyx_v_self, PyObject *__pyx_v_phrase); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_11get_precomputed_collocation(PyObject *__pyx_v_self, PyObject *__pyx_v_phrase) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_precomputed_collocation (wrapper)", 0); + __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_10get_precomputed_collocation(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), ((PyObject *)__pyx_v_phrase)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":448 + * + * + * def get_precomputed_collocation(self, phrase): # <<<<<<<<<<<<<< + * if phrase in self.precomputed_collocations: + * arr = self.precomputed_collocations[phrase] + */ + +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_10get_precomputed_collocation(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_phrase) { + PyObject *__pyx_v_arr = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_precomputed_collocation", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":449 + * + * def get_precomputed_collocation(self, phrase): + * if phrase in self.precomputed_collocations: # <<<<<<<<<<<<<< + * arr = self.precomputed_collocations[phrase] + * return PhraseLocation(arr=arr, arr_low=0, arr_high=len(arr), num_subpatterns=phrase.arity()+1) + */ + __pyx_t_1 = ((PySequence_Contains(__pyx_v_self->precomputed_collocations, __pyx_v_phrase))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":450 + * def get_precomputed_collocation(self, phrase): + * if phrase in self.precomputed_collocations: + * arr = self.precomputed_collocations[phrase] # <<<<<<<<<<<<<< + * return PhraseLocation(arr=arr, arr_low=0, arr_high=len(arr), num_subpatterns=phrase.arity()+1) + * return None + */ + __pyx_t_2 = PyObject_GetItem(__pyx_v_self->precomputed_collocations, __pyx_v_phrase); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_arr = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":451 + * if phrase in self.precomputed_collocations: + * arr = self.precomputed_collocations[phrase] + * return PhraseLocation(arr=arr, arr_low=0, arr_high=len(arr), num_subpatterns=phrase.arity()+1) # <<<<<<<<<<<<<< + * return None + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__arr), __pyx_v_arr) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__arr_low), __pyx_int_0) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Length(__pyx_v_arr); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__arr_high), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyObject_GetAttr(__pyx_v_phrase, __pyx_n_s__arity); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyNumber_Add(__pyx_t_5, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__num_subpatterns), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_PhraseLocation)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":452 + * arr = self.precomputed_collocations[phrase] + * return PhraseLocation(arr=arr, arr_low=0, arr_high=len(arr), num_subpatterns=phrase.arity()+1) + * return None # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_None); + __pyx_r = Py_None; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.get_precomputed_collocation", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_arr); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":455 + * + * + * cdef int* baeza_yates_helper(self, int low1, int high1, int* arr1, int step1, # <<<<<<<<<<<<<< + * int low2, int high2, int* arr2, int step2, + * int offset_by_one, int len_last, int num_subpatterns, int* result_len): + */ + +static int *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_baeza_yates_helper(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, int __pyx_v_low1, int __pyx_v_high1, int *__pyx_v_arr1, int __pyx_v_step1, int __pyx_v_low2, int __pyx_v_high2, int *__pyx_v_arr2, int __pyx_v_step2, int __pyx_v_offset_by_one, int __pyx_v_len_last, int __pyx_v_num_subpatterns, int *__pyx_v_result_len) { + int __pyx_v_i1; + int __pyx_v_i2; + int __pyx_v_med1; + int __pyx_v_med2; + int __pyx_v_med1_plus; + int __pyx_v_med1_minus; + int __pyx_v_med2_minus; + int __pyx_v_med2_plus; + int __pyx_v_d_first; + int __pyx_v_qsetsize; + int __pyx_v_dsetsize; + int __pyx_v_tmp; + int __pyx_v_search_low; + int __pyx_v_search_high; + int __pyx_v_med_result_len; + int __pyx_v_low_result_len; + int __pyx_v_high_result_len; + long __pyx_v_comparison; + int *__pyx_v_result; + int *__pyx_v_low_result; + int *__pyx_v_med_result; + int *__pyx_v_high_result; + struct __pyx_t_8_cdec_sa_Matching __pyx_v_loc1; + struct __pyx_t_8_cdec_sa_Matching __pyx_v_loc2; + int *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + double __pyx_t_5; + double __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("baeza_yates_helper", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":468 + * cdef Matching loc1, loc2 + * + * result = malloc(0*sizeof(int*)) # <<<<<<<<<<<<<< + * + * d_first = 0 + */ + __pyx_v_result = ((int *)malloc((0 * (sizeof(int *))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":470 + * result = malloc(0*sizeof(int*)) + * + * d_first = 0 # <<<<<<<<<<<<<< + * if high1 - low1 > high2 - low2: + * d_first = 1 + */ + __pyx_v_d_first = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":471 + * + * d_first = 0 + * if high1 - low1 > high2 - low2: # <<<<<<<<<<<<<< + * d_first = 1 + * + */ + __pyx_t_1 = ((__pyx_v_high1 - __pyx_v_low1) > (__pyx_v_high2 - __pyx_v_low2)); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":472 + * d_first = 0 + * if high1 - low1 > high2 - low2: + * d_first = 1 # <<<<<<<<<<<<<< + * + * # First, check to see if we are at any of the recursive base cases + */ + __pyx_v_d_first = 1; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":476 + * # First, check to see if we are at any of the recursive base cases + * # Case 1: one of the sets is empty + * if low1 >= high1 or low2 >= high2: # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_t_1 = (__pyx_v_low1 >= __pyx_v_high1); + if (!__pyx_t_1) { + __pyx_t_2 = (__pyx_v_low2 >= __pyx_v_high2); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":477 + * # Case 1: one of the sets is empty + * if low1 >= high1 or low2 >= high2: + * return result # <<<<<<<<<<<<<< + * + * # Case 2: sets are non-overlapping + */ + __pyx_r = __pyx_v_result; + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":480 + * + * # Case 2: sets are non-overlapping + * assign_matching(&loc1, arr1, high1-step1, step1, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * assign_matching(&loc2, arr2, low2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == -1: + */ + __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc1), __pyx_v_arr1, (__pyx_v_high1 - __pyx_v_step1), __pyx_v_step1, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":481 + * # Case 2: sets are non-overlapping + * assign_matching(&loc1, arr1, high1-step1, step1, self.fda.sent_id.arr) + * assign_matching(&loc2, arr2, low2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == -1: + * return result + */ + __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, __pyx_v_low2, __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":482 + * assign_matching(&loc1, arr1, high1-step1, step1, self.fda.sent_id.arr) + * assign_matching(&loc2, arr2, low2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == -1: # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_t_3 = (((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last) == -1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":483 + * assign_matching(&loc2, arr2, low2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == -1: + * return result # <<<<<<<<<<<<<< + * + * assign_matching(&loc1, arr1, low1, step1, self.fda.sent_id.arr) + */ + __pyx_r = __pyx_v_result; + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":485 + * return result + * + * assign_matching(&loc1, arr1, low1, step1, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * assign_matching(&loc2, arr2, high2-step2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: + */ + __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc1), __pyx_v_arr1, __pyx_v_low1, __pyx_v_step1, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":486 + * + * assign_matching(&loc1, arr1, low1, step1, self.fda.sent_id.arr) + * assign_matching(&loc2, arr2, high2-step2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: + * return result + */ + __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, (__pyx_v_high2 - __pyx_v_step2), __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":487 + * assign_matching(&loc1, arr1, low1, step1, self.fda.sent_id.arr) + * assign_matching(&loc2, arr2, high2-step2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_t_3 = (((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last) == 1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":488 + * assign_matching(&loc2, arr2, high2-step2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: + * return result # <<<<<<<<<<<<<< + * + * # Case 3: query set and data set do not meet size mismatch constraints; + */ + __pyx_r = __pyx_v_result; + goto __pyx_L0; + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":492 + * # Case 3: query set and data set do not meet size mismatch constraints; + * # We use mergesort instead in this case + * qsetsize = (high1-low1) / step1 # <<<<<<<<<<<<<< + * dsetsize = (high2-low2) / step2 + * if d_first: + */ + __pyx_t_4 = (__pyx_v_high1 - __pyx_v_low1); + if (unlikely(__pyx_v_step1 == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_step1 == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_4))) { + PyErr_Format(PyExc_OverflowError, "value too large to perform division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_qsetsize = __Pyx_div_int(__pyx_t_4, __pyx_v_step1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":493 + * # We use mergesort instead in this case + * qsetsize = (high1-low1) / step1 + * dsetsize = (high2-low2) / step2 # <<<<<<<<<<<<<< + * if d_first: + * tmp = qsetsize + */ + __pyx_t_4 = (__pyx_v_high2 - __pyx_v_low2); + if (unlikely(__pyx_v_step2 == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 493; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_step2 == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_4))) { + PyErr_Format(PyExc_OverflowError, "value too large to perform division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 493; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_dsetsize = __Pyx_div_int(__pyx_t_4, __pyx_v_step2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":494 + * qsetsize = (high1-low1) / step1 + * dsetsize = (high2-low2) / step2 + * if d_first: # <<<<<<<<<<<<<< + * tmp = qsetsize + * qsetsize = dsetsize + */ + if (__pyx_v_d_first) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":495 + * dsetsize = (high2-low2) / step2 + * if d_first: + * tmp = qsetsize # <<<<<<<<<<<<<< + * qsetsize = dsetsize + * dsetsize = tmp + */ + __pyx_v_tmp = __pyx_v_qsetsize; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":496 + * if d_first: + * tmp = qsetsize + * qsetsize = dsetsize # <<<<<<<<<<<<<< + * dsetsize = tmp + * + */ + __pyx_v_qsetsize = __pyx_v_dsetsize; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":497 + * tmp = qsetsize + * qsetsize = dsetsize + * dsetsize = tmp # <<<<<<<<<<<<<< + * + * if self.by_slack_factor * qsetsize * log(dsetsize) / log(2) > dsetsize: + */ + __pyx_v_dsetsize = __pyx_v_tmp; + goto __pyx_L7; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":499 + * dsetsize = tmp + * + * if self.by_slack_factor * qsetsize * log(dsetsize) / log(2) > dsetsize: # <<<<<<<<<<<<<< + * free(result) + * return self.merge_helper(low1, high1, arr1, step1, low2, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, result_len) + */ + __pyx_t_5 = ((__pyx_v_self->by_slack_factor * __pyx_v_qsetsize) * log(__pyx_v_dsetsize)); + __pyx_t_6 = log(2.0); + if (unlikely(__pyx_t_6 == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_3 = ((__pyx_t_5 / __pyx_t_6) > __pyx_v_dsetsize); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":500 + * + * if self.by_slack_factor * qsetsize * log(dsetsize) / log(2) > dsetsize: + * free(result) # <<<<<<<<<<<<<< + * return self.merge_helper(low1, high1, arr1, step1, low2, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, result_len) + * + */ + free(__pyx_v_result); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":501 + * if self.by_slack_factor * qsetsize * log(dsetsize) / log(2) > dsetsize: + * free(result) + * return self.merge_helper(low1, high1, arr1, step1, low2, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, result_len) # <<<<<<<<<<<<<< + * + * # binary search. There are two flavors, depending on + */ + __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->merge_helper(__pyx_v_self, __pyx_v_low1, __pyx_v_high1, __pyx_v_arr1, __pyx_v_step1, __pyx_v_low2, __pyx_v_high2, __pyx_v_arr2, __pyx_v_step2, __pyx_v_offset_by_one, __pyx_v_len_last, __pyx_v_num_subpatterns, __pyx_v_result_len); + goto __pyx_L0; + goto __pyx_L8; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":505 + * # binary search. There are two flavors, depending on + * # whether the queryset or dataset is first + * if d_first: # <<<<<<<<<<<<<< + * med2 = median(low2, high2, step2) + * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) + */ + if (__pyx_v_d_first) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":506 + * # whether the queryset or dataset is first + * if d_first: + * med2 = median(low2, high2, step2) # <<<<<<<<<<<<<< + * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) + * + */ + __pyx_v_med2 = __pyx_f_8_cdec_sa_median(__pyx_v_low2, __pyx_v_high2, __pyx_v_step2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":507 + * if d_first: + * med2 = median(low2, high2, step2) + * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * + * search_low = low1 + */ + __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, __pyx_v_med2, __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":509 + * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) + * + * search_low = low1 # <<<<<<<<<<<<<< + * search_high = high1 + * while search_low < search_high: + */ + __pyx_v_search_low = __pyx_v_low1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":510 + * + * search_low = low1 + * search_high = high1 # <<<<<<<<<<<<<< + * while search_low < search_high: + * med1 = median(search_low, search_high, step1) + */ + __pyx_v_search_high = __pyx_v_high1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":511 + * search_low = low1 + * search_high = high1 + * while search_low < search_high: # <<<<<<<<<<<<<< + * med1 = median(search_low, search_high, step1) + * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) + */ + while (1) { + __pyx_t_3 = (__pyx_v_search_low < __pyx_v_search_high); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":512 + * search_high = high1 + * while search_low < search_high: + * med1 = median(search_low, search_high, step1) # <<<<<<<<<<<<<< + * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) + */ + __pyx_v_med1 = __pyx_f_8_cdec_sa_median(__pyx_v_search_low, __pyx_v_search_high, __pyx_v_step1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":513 + * while search_low < search_high: + * med1 = median(search_low, search_high, step1) + * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) # <<<<<<<<<<<<<< + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) + * if comparison == -1: + */ + __pyx_f_8_cdec_sa_find_comparable_matchings(__pyx_v_low1, __pyx_v_high1, __pyx_v_arr1, __pyx_v_step1, __pyx_v_med1, (&__pyx_v_med1_minus), (&__pyx_v_med1_plus)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":514 + * med1 = median(search_low, search_high, step1) + * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) # <<<<<<<<<<<<<< + * if comparison == -1: + * search_low = med1_plus + */ + __pyx_v_comparison = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings_set(__pyx_v_self, __pyx_v_med1_minus, __pyx_v_med1_plus, __pyx_v_arr1, __pyx_v_step1, (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":517 + * if comparison == -1: + * search_low = med1_plus + * elif comparison == 1: # <<<<<<<<<<<<<< + * search_high = med1_minus + * else: + */ + switch (__pyx_v_comparison) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":515 + * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) + * if comparison == -1: # <<<<<<<<<<<<<< + * search_low = med1_plus + * elif comparison == 1: + */ + case -1: + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":516 + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) + * if comparison == -1: + * search_low = med1_plus # <<<<<<<<<<<<<< + * elif comparison == 1: + * search_high = med1_minus + */ + __pyx_v_search_low = __pyx_v_med1_plus; + break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":517 + * if comparison == -1: + * search_low = med1_plus + * elif comparison == 1: # <<<<<<<<<<<<<< + * search_high = med1_minus + * else: + */ + case 1: + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":518 + * search_low = med1_plus + * elif comparison == 1: + * search_high = med1_minus # <<<<<<<<<<<<<< + * else: + * break + */ + __pyx_v_search_high = __pyx_v_med1_minus; + break; + default: + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":520 + * search_high = med1_minus + * else: + * break # <<<<<<<<<<<<<< + * else: + * med1 = median(low1, high1, step1) + */ + goto __pyx_L11_break; + break; + } + } + __pyx_L11_break:; + goto __pyx_L9; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":522 + * break + * else: + * med1 = median(low1, high1, step1) # <<<<<<<<<<<<<< + * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) + * + */ + __pyx_v_med1 = __pyx_f_8_cdec_sa_median(__pyx_v_low1, __pyx_v_high1, __pyx_v_step1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":523 + * else: + * med1 = median(low1, high1, step1) + * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) # <<<<<<<<<<<<<< + * + * search_low = low2 + */ + __pyx_f_8_cdec_sa_find_comparable_matchings(__pyx_v_low1, __pyx_v_high1, __pyx_v_arr1, __pyx_v_step1, __pyx_v_med1, (&__pyx_v_med1_minus), (&__pyx_v_med1_plus)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":525 + * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) + * + * search_low = low2 # <<<<<<<<<<<<<< + * search_high = high2 + * while search_low < search_high: + */ + __pyx_v_search_low = __pyx_v_low2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":526 + * + * search_low = low2 + * search_high = high2 # <<<<<<<<<<<<<< + * while search_low < search_high: + * med2 = median(search_low, search_high, step2) + */ + __pyx_v_search_high = __pyx_v_high2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":527 + * search_low = low2 + * search_high = high2 + * while search_low < search_high: # <<<<<<<<<<<<<< + * med2 = median(search_low, search_high, step2) + * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) + */ + while (1) { + __pyx_t_3 = (__pyx_v_search_low < __pyx_v_search_high); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":528 + * search_high = high2 + * while search_low < search_high: + * med2 = median(search_low, search_high, step2) # <<<<<<<<<<<<<< + * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) + */ + __pyx_v_med2 = __pyx_f_8_cdec_sa_median(__pyx_v_search_low, __pyx_v_search_high, __pyx_v_step2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":529 + * while search_low < search_high: + * med2 = median(search_low, search_high, step2) + * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) + * if comparison == -1: + */ + __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, __pyx_v_med2, __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":530 + * med2 = median(search_low, search_high, step2) + * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) # <<<<<<<<<<<<<< + * if comparison == -1: + * search_high = med2 + */ + __pyx_v_comparison = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings_set(__pyx_v_self, __pyx_v_med1_minus, __pyx_v_med1_plus, __pyx_v_arr1, __pyx_v_step1, (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":533 + * if comparison == -1: + * search_high = med2 + * elif comparison == 1: # <<<<<<<<<<<<<< + * search_low = med2 + step2 + * else: + */ + switch (__pyx_v_comparison) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":531 + * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) + * if comparison == -1: # <<<<<<<<<<<<<< + * search_high = med2 + * elif comparison == 1: + */ + case -1: + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":532 + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) + * if comparison == -1: + * search_high = med2 # <<<<<<<<<<<<<< + * elif comparison == 1: + * search_low = med2 + step2 + */ + __pyx_v_search_high = __pyx_v_med2; + break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":533 + * if comparison == -1: + * search_high = med2 + * elif comparison == 1: # <<<<<<<<<<<<<< + * search_low = med2 + step2 + * else: + */ + case 1: + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":534 + * search_high = med2 + * elif comparison == 1: + * search_low = med2 + step2 # <<<<<<<<<<<<<< + * else: + * break + */ + __pyx_v_search_low = (__pyx_v_med2 + __pyx_v_step2); + break; + default: + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":536 + * search_low = med2 + step2 + * else: + * break # <<<<<<<<<<<<<< + * + * med_result_len = 0 + */ + goto __pyx_L13_break; + break; + } + } + __pyx_L13_break:; + } + __pyx_L9:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":538 + * break + * + * med_result_len = 0 # <<<<<<<<<<<<<< + * med_result = malloc(0*sizeof(int*)) + * if search_high > search_low: + */ + __pyx_v_med_result_len = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":539 + * + * med_result_len = 0 + * med_result = malloc(0*sizeof(int*)) # <<<<<<<<<<<<<< + * if search_high > search_low: + * # Then there is a match for the median element of Q + */ + __pyx_v_med_result = ((int *)malloc((0 * (sizeof(int *))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":540 + * med_result_len = 0 + * med_result = malloc(0*sizeof(int*)) + * if search_high > search_low: # <<<<<<<<<<<<<< + * # Then there is a match for the median element of Q + * # What we want to find is the group of all bindings in the first set + */ + __pyx_t_3 = (__pyx_v_search_high > __pyx_v_search_low); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":546 + * # want to store the bindings for all of those elements. We can + * # subsequently throw all of them away. + * med2_minus = med2 # <<<<<<<<<<<<<< + * med2_plus = med2 + step2 + * i1 = med1_minus + */ + __pyx_v_med2_minus = __pyx_v_med2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":547 + * # subsequently throw all of them away. + * med2_minus = med2 + * med2_plus = med2 + step2 # <<<<<<<<<<<<<< + * i1 = med1_minus + * while i1 < med1_plus: + */ + __pyx_v_med2_plus = (__pyx_v_med2 + __pyx_v_step2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":548 + * med2_minus = med2 + * med2_plus = med2 + step2 + * i1 = med1_minus # <<<<<<<<<<<<<< + * while i1 < med1_plus: + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + */ + __pyx_v_i1 = __pyx_v_med1_minus; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":549 + * med2_plus = med2 + step2 + * i1 = med1_minus + * while i1 < med1_plus: # <<<<<<<<<<<<<< + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + * while med2_minus-step2 >= low2: + */ + while (1) { + __pyx_t_3 = (__pyx_v_i1 < __pyx_v_med1_plus); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":550 + * i1 = med1_minus + * while i1 < med1_plus: + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * while med2_minus-step2 >= low2: + * assign_matching(&loc2, arr2, med2_minus-step2, step2, self.fda.sent_id.arr) + */ + __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc1), __pyx_v_arr1, __pyx_v_i1, __pyx_v_step1, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":551 + * while i1 < med1_plus: + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + * while med2_minus-step2 >= low2: # <<<<<<<<<<<<<< + * assign_matching(&loc2, arr2, med2_minus-step2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) < 1: + */ + while (1) { + __pyx_t_3 = ((__pyx_v_med2_minus - __pyx_v_step2) >= __pyx_v_low2); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":552 + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + * while med2_minus-step2 >= low2: + * assign_matching(&loc2, arr2, med2_minus-step2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) < 1: + * med2_minus = med2_minus - step2 + */ + __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, (__pyx_v_med2_minus - __pyx_v_step2), __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":553 + * while med2_minus-step2 >= low2: + * assign_matching(&loc2, arr2, med2_minus-step2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) < 1: # <<<<<<<<<<<<<< + * med2_minus = med2_minus - step2 + * else: + */ + __pyx_t_3 = (((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last) < 1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":554 + * assign_matching(&loc2, arr2, med2_minus-step2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) < 1: + * med2_minus = med2_minus - step2 # <<<<<<<<<<<<<< + * else: + * break + */ + __pyx_v_med2_minus = (__pyx_v_med2_minus - __pyx_v_step2); + goto __pyx_L19; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":556 + * med2_minus = med2_minus - step2 + * else: + * break # <<<<<<<<<<<<<< + * i2 = med2_minus + * while i2 < high2: + */ + goto __pyx_L18_break; + } + __pyx_L19:; + } + __pyx_L18_break:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":557 + * else: + * break + * i2 = med2_minus # <<<<<<<<<<<<<< + * while i2 < high2: + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) + */ + __pyx_v_i2 = __pyx_v_med2_minus; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":558 + * break + * i2 = med2_minus + * while i2 < high2: # <<<<<<<<<<<<<< + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) + * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) + */ + while (1) { + __pyx_t_3 = (__pyx_v_i2 < __pyx_v_high2); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":559 + * i2 = med2_minus + * while i2 < high2: + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) + * if comparison == 0: + */ + __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, __pyx_v_i2, __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":560 + * while i2 < high2: + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) + * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) # <<<<<<<<<<<<<< + * if comparison == 0: + * pass + */ + __pyx_v_comparison = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":561 + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) + * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) + * if comparison == 0: # <<<<<<<<<<<<<< + * pass + * med_result = append_combined_matching(med_result, &loc1, &loc2, offset_by_one, num_subpatterns, &med_result_len) + */ + __pyx_t_3 = (__pyx_v_comparison == 0); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":563 + * if comparison == 0: + * pass + * med_result = append_combined_matching(med_result, &loc1, &loc2, offset_by_one, num_subpatterns, &med_result_len) # <<<<<<<<<<<<<< + * if comparison == -1: + * break + */ + __pyx_v_med_result = __pyx_f_8_cdec_sa_append_combined_matching(__pyx_v_med_result, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_num_subpatterns, (&__pyx_v_med_result_len)); + goto __pyx_L22; + } + __pyx_L22:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":564 + * pass + * med_result = append_combined_matching(med_result, &loc1, &loc2, offset_by_one, num_subpatterns, &med_result_len) + * if comparison == -1: # <<<<<<<<<<<<<< + * break + * i2 = i2 + step2 + */ + __pyx_t_3 = (__pyx_v_comparison == -1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":565 + * med_result = append_combined_matching(med_result, &loc1, &loc2, offset_by_one, num_subpatterns, &med_result_len) + * if comparison == -1: + * break # <<<<<<<<<<<<<< + * i2 = i2 + step2 + * if i2 > med2_plus: + */ + goto __pyx_L21_break; + goto __pyx_L23; + } + __pyx_L23:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":566 + * if comparison == -1: + * break + * i2 = i2 + step2 # <<<<<<<<<<<<<< + * if i2 > med2_plus: + * med2_plus = i2 + */ + __pyx_v_i2 = (__pyx_v_i2 + __pyx_v_step2); + } + __pyx_L21_break:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":567 + * break + * i2 = i2 + step2 + * if i2 > med2_plus: # <<<<<<<<<<<<<< + * med2_plus = i2 + * i1 = i1 + step1 + */ + __pyx_t_3 = (__pyx_v_i2 > __pyx_v_med2_plus); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":568 + * i2 = i2 + step2 + * if i2 > med2_plus: + * med2_plus = i2 # <<<<<<<<<<<<<< + * i1 = i1 + step1 + * + */ + __pyx_v_med2_plus = __pyx_v_i2; + goto __pyx_L24; + } + __pyx_L24:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":569 + * if i2 > med2_plus: + * med2_plus = i2 + * i1 = i1 + step1 # <<<<<<<<<<<<<< + * + * tmp = med1_minus + */ + __pyx_v_i1 = (__pyx_v_i1 + __pyx_v_step1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":571 + * i1 = i1 + step1 + * + * tmp = med1_minus # <<<<<<<<<<<<<< + * med1_minus = med1_plus + * med1_plus = tmp + */ + __pyx_v_tmp = __pyx_v_med1_minus; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":572 + * + * tmp = med1_minus + * med1_minus = med1_plus # <<<<<<<<<<<<<< + * med1_plus = tmp + * else: + */ + __pyx_v_med1_minus = __pyx_v_med1_plus; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":573 + * tmp = med1_minus + * med1_minus = med1_plus + * med1_plus = tmp # <<<<<<<<<<<<<< + * else: + * # No match; need to figure out the point of division in D and Q + */ + __pyx_v_med1_plus = __pyx_v_tmp; + goto __pyx_L14; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":576 + * else: + * # No match; need to figure out the point of division in D and Q + * med2_minus = med2 # <<<<<<<<<<<<<< + * med2_plus = med2 + * if d_first: + */ + __pyx_v_med2_minus = __pyx_v_med2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":577 + * # No match; need to figure out the point of division in D and Q + * med2_minus = med2 + * med2_plus = med2 # <<<<<<<<<<<<<< + * if d_first: + * med2_minus = med2_minus + step2 + */ + __pyx_v_med2_plus = __pyx_v_med2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":578 + * med2_minus = med2 + * med2_plus = med2 + * if d_first: # <<<<<<<<<<<<<< + * med2_minus = med2_minus + step2 + * if comparison == -1: + */ + if (__pyx_v_d_first) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":579 + * med2_plus = med2 + * if d_first: + * med2_minus = med2_minus + step2 # <<<<<<<<<<<<<< + * if comparison == -1: + * med1_minus = med1_plus + */ + __pyx_v_med2_minus = (__pyx_v_med2_minus + __pyx_v_step2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":580 + * if d_first: + * med2_minus = med2_minus + step2 + * if comparison == -1: # <<<<<<<<<<<<<< + * med1_minus = med1_plus + * if comparison == 1: + */ + __pyx_t_3 = (__pyx_v_comparison == -1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":581 + * med2_minus = med2_minus + step2 + * if comparison == -1: + * med1_minus = med1_plus # <<<<<<<<<<<<<< + * if comparison == 1: + * med1_plus = med1_minus + */ + __pyx_v_med1_minus = __pyx_v_med1_plus; + goto __pyx_L26; + } + __pyx_L26:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":582 + * if comparison == -1: + * med1_minus = med1_plus + * if comparison == 1: # <<<<<<<<<<<<<< + * med1_plus = med1_minus + * else: + */ + __pyx_t_3 = (__pyx_v_comparison == 1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":583 + * med1_minus = med1_plus + * if comparison == 1: + * med1_plus = med1_minus # <<<<<<<<<<<<<< + * else: + * tmp = med1_minus + */ + __pyx_v_med1_plus = __pyx_v_med1_minus; + goto __pyx_L27; + } + __pyx_L27:; + goto __pyx_L25; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":585 + * med1_plus = med1_minus + * else: + * tmp = med1_minus # <<<<<<<<<<<<<< + * med1_minus = med1_plus + * med1_plus = tmp + */ + __pyx_v_tmp = __pyx_v_med1_minus; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":586 + * else: + * tmp = med1_minus + * med1_minus = med1_plus # <<<<<<<<<<<<<< + * med1_plus = tmp + * if comparison == 1: + */ + __pyx_v_med1_minus = __pyx_v_med1_plus; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":587 + * tmp = med1_minus + * med1_minus = med1_plus + * med1_plus = tmp # <<<<<<<<<<<<<< + * if comparison == 1: + * med2_minus = med2_minus + step2 + */ + __pyx_v_med1_plus = __pyx_v_tmp; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":588 + * med1_minus = med1_plus + * med1_plus = tmp + * if comparison == 1: # <<<<<<<<<<<<<< + * med2_minus = med2_minus + step2 + * med2_plus = med2_plus + step2 + */ + __pyx_t_3 = (__pyx_v_comparison == 1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":589 + * med1_plus = tmp + * if comparison == 1: + * med2_minus = med2_minus + step2 # <<<<<<<<<<<<<< + * med2_plus = med2_plus + step2 + * + */ + __pyx_v_med2_minus = (__pyx_v_med2_minus + __pyx_v_step2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":590 + * if comparison == 1: + * med2_minus = med2_minus + step2 + * med2_plus = med2_plus + step2 # <<<<<<<<<<<<<< + * + * low_result_len = 0 + */ + __pyx_v_med2_plus = (__pyx_v_med2_plus + __pyx_v_step2); + goto __pyx_L28; + } + __pyx_L28:; + } + __pyx_L25:; + } + __pyx_L14:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":592 + * med2_plus = med2_plus + step2 + * + * low_result_len = 0 # <<<<<<<<<<<<<< + * low_result = self.baeza_yates_helper(low1, med1_plus, arr1, step1, low2, med2_plus, arr2, step2, offset_by_one, len_last, num_subpatterns, &low_result_len) + * high_result_len = 0 + */ + __pyx_v_low_result_len = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":593 + * + * low_result_len = 0 + * low_result = self.baeza_yates_helper(low1, med1_plus, arr1, step1, low2, med2_plus, arr2, step2, offset_by_one, len_last, num_subpatterns, &low_result_len) # <<<<<<<<<<<<<< + * high_result_len = 0 + * high_result = self.baeza_yates_helper(med1_minus, high1, arr1, step1, med2_minus, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, &high_result_len) + */ + __pyx_v_low_result = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->baeza_yates_helper(__pyx_v_self, __pyx_v_low1, __pyx_v_med1_plus, __pyx_v_arr1, __pyx_v_step1, __pyx_v_low2, __pyx_v_med2_plus, __pyx_v_arr2, __pyx_v_step2, __pyx_v_offset_by_one, __pyx_v_len_last, __pyx_v_num_subpatterns, (&__pyx_v_low_result_len)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":594 + * low_result_len = 0 + * low_result = self.baeza_yates_helper(low1, med1_plus, arr1, step1, low2, med2_plus, arr2, step2, offset_by_one, len_last, num_subpatterns, &low_result_len) + * high_result_len = 0 # <<<<<<<<<<<<<< + * high_result = self.baeza_yates_helper(med1_minus, high1, arr1, step1, med2_minus, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, &high_result_len) + * + */ + __pyx_v_high_result_len = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":595 + * low_result = self.baeza_yates_helper(low1, med1_plus, arr1, step1, low2, med2_plus, arr2, step2, offset_by_one, len_last, num_subpatterns, &low_result_len) + * high_result_len = 0 + * high_result = self.baeza_yates_helper(med1_minus, high1, arr1, step1, med2_minus, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, &high_result_len) # <<<<<<<<<<<<<< + * + * result = extend_arr(result, result_len, low_result, low_result_len) + */ + __pyx_v_high_result = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->baeza_yates_helper(__pyx_v_self, __pyx_v_med1_minus, __pyx_v_high1, __pyx_v_arr1, __pyx_v_step1, __pyx_v_med2_minus, __pyx_v_high2, __pyx_v_arr2, __pyx_v_step2, __pyx_v_offset_by_one, __pyx_v_len_last, __pyx_v_num_subpatterns, (&__pyx_v_high_result_len)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":597 + * high_result = self.baeza_yates_helper(med1_minus, high1, arr1, step1, med2_minus, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, &high_result_len) + * + * result = extend_arr(result, result_len, low_result, low_result_len) # <<<<<<<<<<<<<< + * result = extend_arr(result, result_len, med_result, med_result_len) + * result = extend_arr(result, result_len, high_result, high_result_len) + */ + __pyx_v_result = __pyx_f_8_cdec_sa_extend_arr(__pyx_v_result, __pyx_v_result_len, __pyx_v_low_result, __pyx_v_low_result_len); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":598 + * + * result = extend_arr(result, result_len, low_result, low_result_len) + * result = extend_arr(result, result_len, med_result, med_result_len) # <<<<<<<<<<<<<< + * result = extend_arr(result, result_len, high_result, high_result_len) + * free(low_result) + */ + __pyx_v_result = __pyx_f_8_cdec_sa_extend_arr(__pyx_v_result, __pyx_v_result_len, __pyx_v_med_result, __pyx_v_med_result_len); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":599 + * result = extend_arr(result, result_len, low_result, low_result_len) + * result = extend_arr(result, result_len, med_result, med_result_len) + * result = extend_arr(result, result_len, high_result, high_result_len) # <<<<<<<<<<<<<< + * free(low_result) + * free(med_result) + */ + __pyx_v_result = __pyx_f_8_cdec_sa_extend_arr(__pyx_v_result, __pyx_v_result_len, __pyx_v_high_result, __pyx_v_high_result_len); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":600 + * result = extend_arr(result, result_len, med_result, med_result_len) + * result = extend_arr(result, result_len, high_result, high_result_len) + * free(low_result) # <<<<<<<<<<<<<< + * free(med_result) + * free(high_result) + */ + free(__pyx_v_low_result); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":601 + * result = extend_arr(result, result_len, high_result, high_result_len) + * free(low_result) + * free(med_result) # <<<<<<<<<<<<<< + * free(high_result) + * + */ + free(__pyx_v_med_result); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":602 + * free(low_result) + * free(med_result) + * free(high_result) # <<<<<<<<<<<<<< + * + * return result + */ + free(__pyx_v_high_result); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":604 + * free(high_result) + * + * return result # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("_cdec_sa.HieroCachingRuleFactory.baeza_yates_helper", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":608 + * + * + * cdef long compare_matchings_set(self, int i1_minus, int i1_plus, int* arr1, int step1, # <<<<<<<<<<<<<< + * Matching* loc2, int offset_by_one, int len_last): + * """ + */ + +static long __pyx_f_8_cdec_sa_23HieroCachingRuleFactory_compare_matchings_set(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, int __pyx_v_i1_minus, int __pyx_v_i1_plus, int *__pyx_v_arr1, int __pyx_v_step1, struct __pyx_t_8_cdec_sa_Matching *__pyx_v_loc2, int __pyx_v_offset_by_one, int __pyx_v_len_last) { + int __pyx_v_i1; + int __pyx_v_comparison; + int __pyx_v_prev_comparison; + struct __pyx_t_8_cdec_sa_Matching __pyx_v_l1_stack; + struct __pyx_t_8_cdec_sa_Matching *__pyx_v_loc1; + long __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("compare_matchings_set", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":619 + * cdef Matching* loc1 + * + * loc1 = &l1_stack # <<<<<<<<<<<<<< + * + * i1 = i1_minus + */ + __pyx_v_loc1 = (&__pyx_v_l1_stack); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":621 + * loc1 = &l1_stack + * + * i1 = i1_minus # <<<<<<<<<<<<<< + * while i1 < i1_plus: + * assign_matching(loc1, arr1, i1, step1, self.fda.sent_id.arr) + */ + __pyx_v_i1 = __pyx_v_i1_minus; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":622 + * + * i1 = i1_minus + * while i1 < i1_plus: # <<<<<<<<<<<<<< + * assign_matching(loc1, arr1, i1, step1, self.fda.sent_id.arr) + * comparison = self.compare_matchings(loc1, loc2, offset_by_one, len_last) + */ + while (1) { + __pyx_t_1 = (__pyx_v_i1 < __pyx_v_i1_plus); + if (!__pyx_t_1) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":623 + * i1 = i1_minus + * while i1 < i1_plus: + * assign_matching(loc1, arr1, i1, step1, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * comparison = self.compare_matchings(loc1, loc2, offset_by_one, len_last) + * if comparison == 0: + */ + __pyx_f_8_cdec_sa_assign_matching(__pyx_v_loc1, __pyx_v_arr1, __pyx_v_i1, __pyx_v_step1, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":624 + * while i1 < i1_plus: + * assign_matching(loc1, arr1, i1, step1, self.fda.sent_id.arr) + * comparison = self.compare_matchings(loc1, loc2, offset_by_one, len_last) # <<<<<<<<<<<<<< + * if comparison == 0: + * prev_comparison = 0 + */ + __pyx_v_comparison = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, __pyx_v_loc1, __pyx_v_loc2, __pyx_v_offset_by_one, __pyx_v_len_last); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":625 + * assign_matching(loc1, arr1, i1, step1, self.fda.sent_id.arr) + * comparison = self.compare_matchings(loc1, loc2, offset_by_one, len_last) + * if comparison == 0: # <<<<<<<<<<<<<< + * prev_comparison = 0 + * break + */ + __pyx_t_1 = (__pyx_v_comparison == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":626 + * comparison = self.compare_matchings(loc1, loc2, offset_by_one, len_last) + * if comparison == 0: + * prev_comparison = 0 # <<<<<<<<<<<<<< + * break + * elif i1 == i1_minus: + */ + __pyx_v_prev_comparison = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":627 + * if comparison == 0: + * prev_comparison = 0 + * break # <<<<<<<<<<<<<< + * elif i1 == i1_minus: + * prev_comparison = comparison + */ + goto __pyx_L4_break; + goto __pyx_L5; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":628 + * prev_comparison = 0 + * break + * elif i1 == i1_minus: # <<<<<<<<<<<<<< + * prev_comparison = comparison + * else: + */ + __pyx_t_1 = (__pyx_v_i1 == __pyx_v_i1_minus); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":629 + * break + * elif i1 == i1_minus: + * prev_comparison = comparison # <<<<<<<<<<<<<< + * else: + * if comparison != prev_comparison: + */ + __pyx_v_prev_comparison = __pyx_v_comparison; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":631 + * prev_comparison = comparison + * else: + * if comparison != prev_comparison: # <<<<<<<<<<<<<< + * prev_comparison = 0 + * break + */ + __pyx_t_1 = (__pyx_v_comparison != __pyx_v_prev_comparison); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":632 + * else: + * if comparison != prev_comparison: + * prev_comparison = 0 # <<<<<<<<<<<<<< + * break + * i1 = i1 + step1 + */ + __pyx_v_prev_comparison = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":633 + * if comparison != prev_comparison: + * prev_comparison = 0 + * break # <<<<<<<<<<<<<< + * i1 = i1 + step1 + * return prev_comparison + */ + goto __pyx_L4_break; + goto __pyx_L6; + } + __pyx_L6:; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":634 + * prev_comparison = 0 + * break + * i1 = i1 + step1 # <<<<<<<<<<<<<< + * return prev_comparison + * + */ + __pyx_v_i1 = (__pyx_v_i1 + __pyx_v_step1); + } + __pyx_L4_break:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":635 + * break + * i1 = i1 + step1 + * return prev_comparison # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_prev_comparison; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":638 + * + * + * cdef long compare_matchings(self, Matching* loc1, Matching* loc2, int offset_by_one, int len_last): # <<<<<<<<<<<<<< + * cdef int i + * + */ + +static long __pyx_f_8_cdec_sa_23HieroCachingRuleFactory_compare_matchings(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_t_8_cdec_sa_Matching *__pyx_v_loc1, struct __pyx_t_8_cdec_sa_Matching *__pyx_v_loc2, int __pyx_v_offset_by_one, int __pyx_v_len_last) { + int __pyx_v_i; + long __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + __Pyx_RefNannySetupContext("compare_matchings", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":641 + * cdef int i + * + * if loc1.sent_id > loc2.sent_id: # <<<<<<<<<<<<<< + * return 1 + * if loc2.sent_id > loc1.sent_id: + */ + __pyx_t_1 = (__pyx_v_loc1->sent_id > __pyx_v_loc2->sent_id); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":642 + * + * if loc1.sent_id > loc2.sent_id: + * return 1 # <<<<<<<<<<<<<< + * if loc2.sent_id > loc1.sent_id: + * return -1 + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":643 + * if loc1.sent_id > loc2.sent_id: + * return 1 + * if loc2.sent_id > loc1.sent_id: # <<<<<<<<<<<<<< + * return -1 + * + */ + __pyx_t_1 = (__pyx_v_loc2->sent_id > __pyx_v_loc1->sent_id); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":644 + * return 1 + * if loc2.sent_id > loc1.sent_id: + * return -1 # <<<<<<<<<<<<<< + * + * if loc1.size == 1 and loc2.size == 1: + */ + __pyx_r = -1; + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":646 + * return -1 + * + * if loc1.size == 1 and loc2.size == 1: # <<<<<<<<<<<<<< + * if loc2.arr[loc2.start] - loc1.arr[loc1.start] <= self.train_min_gap_size: + * return 1 + */ + __pyx_t_1 = (__pyx_v_loc1->size == 1); + if (__pyx_t_1) { + __pyx_t_2 = (__pyx_v_loc2->size == 1); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":647 + * + * if loc1.size == 1 and loc2.size == 1: + * if loc2.arr[loc2.start] - loc1.arr[loc1.start] <= self.train_min_gap_size: # <<<<<<<<<<<<<< + * return 1 + * + */ + __pyx_t_3 = (((__pyx_v_loc2->arr[__pyx_v_loc2->start]) - (__pyx_v_loc1->arr[__pyx_v_loc1->start])) <= __pyx_v_self->train_min_gap_size); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":648 + * if loc1.size == 1 and loc2.size == 1: + * if loc2.arr[loc2.start] - loc1.arr[loc1.start] <= self.train_min_gap_size: + * return 1 # <<<<<<<<<<<<<< + * + * elif offset_by_one: + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L6; + } + __pyx_L6:; + goto __pyx_L5; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":650 + * return 1 + * + * elif offset_by_one: # <<<<<<<<<<<<<< + * for i from 1 <= i < loc1.size: + * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i-1]: + */ + if (__pyx_v_offset_by_one) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":651 + * + * elif offset_by_one: + * for i from 1 <= i < loc1.size: # <<<<<<<<<<<<<< + * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i-1]: + * return 1 + */ + __pyx_t_4 = __pyx_v_loc1->size; + for (__pyx_v_i = 1; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":652 + * elif offset_by_one: + * for i from 1 <= i < loc1.size: + * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i-1]: # <<<<<<<<<<<<<< + * return 1 + * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i-1]: + */ + __pyx_t_3 = ((__pyx_v_loc1->arr[(__pyx_v_loc1->start + __pyx_v_i)]) > (__pyx_v_loc2->arr[((__pyx_v_loc2->start + __pyx_v_i) - 1)])); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":653 + * for i from 1 <= i < loc1.size: + * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i-1]: + * return 1 # <<<<<<<<<<<<<< + * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i-1]: + * return -1 + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L9; + } + __pyx_L9:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":654 + * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i-1]: + * return 1 + * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i-1]: # <<<<<<<<<<<<<< + * return -1 + * + */ + __pyx_t_3 = ((__pyx_v_loc1->arr[(__pyx_v_loc1->start + __pyx_v_i)]) < (__pyx_v_loc2->arr[((__pyx_v_loc2->start + __pyx_v_i) - 1)])); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":655 + * return 1 + * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i-1]: + * return -1 # <<<<<<<<<<<<<< + * + * else: + */ + __pyx_r = -1; + goto __pyx_L0; + goto __pyx_L10; + } + __pyx_L10:; + } + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":658 + * + * else: + * if loc1.arr[loc1.start]+1 > loc2.arr[loc2.start]: # <<<<<<<<<<<<<< + * return 1 + * if loc1.arr[loc1.start]+1 < loc2.arr[loc2.start]: + */ + __pyx_t_3 = (((__pyx_v_loc1->arr[__pyx_v_loc1->start]) + 1) > (__pyx_v_loc2->arr[__pyx_v_loc2->start])); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":659 + * else: + * if loc1.arr[loc1.start]+1 > loc2.arr[loc2.start]: + * return 1 # <<<<<<<<<<<<<< + * if loc1.arr[loc1.start]+1 < loc2.arr[loc2.start]: + * return -1 + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L11; + } + __pyx_L11:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":660 + * if loc1.arr[loc1.start]+1 > loc2.arr[loc2.start]: + * return 1 + * if loc1.arr[loc1.start]+1 < loc2.arr[loc2.start]: # <<<<<<<<<<<<<< + * return -1 + * + */ + __pyx_t_3 = (((__pyx_v_loc1->arr[__pyx_v_loc1->start]) + 1) < (__pyx_v_loc2->arr[__pyx_v_loc2->start])); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":661 + * return 1 + * if loc1.arr[loc1.start]+1 < loc2.arr[loc2.start]: + * return -1 # <<<<<<<<<<<<<< + * + * for i from 1 <= i < loc1.size: + */ + __pyx_r = -1; + goto __pyx_L0; + goto __pyx_L12; + } + __pyx_L12:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":663 + * return -1 + * + * for i from 1 <= i < loc1.size: # <<<<<<<<<<<<<< + * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i]: + * return 1 + */ + __pyx_t_4 = __pyx_v_loc1->size; + for (__pyx_v_i = 1; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":664 + * + * for i from 1 <= i < loc1.size: + * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i]: # <<<<<<<<<<<<<< + * return 1 + * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i]: + */ + __pyx_t_3 = ((__pyx_v_loc1->arr[(__pyx_v_loc1->start + __pyx_v_i)]) > (__pyx_v_loc2->arr[(__pyx_v_loc2->start + __pyx_v_i)])); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":665 + * for i from 1 <= i < loc1.size: + * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i]: + * return 1 # <<<<<<<<<<<<<< + * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i]: + * return -1 + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L15; + } + __pyx_L15:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":666 + * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i]: + * return 1 + * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i]: # <<<<<<<<<<<<<< + * return -1 + * + */ + __pyx_t_3 = ((__pyx_v_loc1->arr[(__pyx_v_loc1->start + __pyx_v_i)]) < (__pyx_v_loc2->arr[(__pyx_v_loc2->start + __pyx_v_i)])); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":667 + * return 1 + * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i]: + * return -1 # <<<<<<<<<<<<<< + * + * if loc2.arr[loc2.end-1] + len_last - loc1.arr[loc1.start] > self.train_max_initial_size: + */ + __pyx_r = -1; + goto __pyx_L0; + goto __pyx_L16; + } + __pyx_L16:; + } + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":669 + * return -1 + * + * if loc2.arr[loc2.end-1] + len_last - loc1.arr[loc1.start] > self.train_max_initial_size: # <<<<<<<<<<<<<< + * return -1 + * return 0 + */ + __pyx_t_3 = ((((__pyx_v_loc2->arr[(__pyx_v_loc2->end - 1)]) + __pyx_v_len_last) - (__pyx_v_loc1->arr[__pyx_v_loc1->start])) > __pyx_v_self->train_max_initial_size); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":670 + * + * if loc2.arr[loc2.end-1] + len_last - loc1.arr[loc1.start] > self.train_max_initial_size: + * return -1 # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_r = -1; + goto __pyx_L0; + goto __pyx_L17; + } + __pyx_L17:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":671 + * if loc2.arr[loc2.end-1] + len_last - loc1.arr[loc1.start] > self.train_max_initial_size: + * return -1 + * return 0 # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = 0; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":674 + * + * + * cdef int* merge_helper(self, int low1, int high1, int* arr1, int step1, # <<<<<<<<<<<<<< + * int low2, int high2, int* arr2, int step2, + * int offset_by_one, int len_last, int num_subpatterns, int* result_len): + */ + +static int *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_merge_helper(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, int __pyx_v_low1, int __pyx_v_high1, int *__pyx_v_arr1, int __pyx_v_step1, int __pyx_v_low2, int __pyx_v_high2, int *__pyx_v_arr2, int __pyx_v_step2, int __pyx_v_offset_by_one, int __pyx_v_len_last, int __pyx_v_num_subpatterns, int *__pyx_v_result_len) { + int __pyx_v_i1; + int __pyx_v_i2; + int __pyx_v_j1; + int __pyx_v_j2; + long __pyx_v_comparison; + int *__pyx_v_result; + struct __pyx_t_8_cdec_sa_Matching __pyx_v_loc1; + struct __pyx_t_8_cdec_sa_Matching __pyx_v_loc2; + int *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("merge_helper", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":682 + * cdef Matching loc1, loc2 + * + * result_len[0] = 0 # <<<<<<<<<<<<<< + * result = malloc(0*sizeof(int)) + * + */ + (__pyx_v_result_len[0]) = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":683 + * + * result_len[0] = 0 + * result = malloc(0*sizeof(int)) # <<<<<<<<<<<<<< + * + * i1 = low1 + */ + __pyx_v_result = ((int *)malloc((0 * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":685 + * result = malloc(0*sizeof(int)) + * + * i1 = low1 # <<<<<<<<<<<<<< + * i2 = low2 + * while i1 < high1 and i2 < high2: + */ + __pyx_v_i1 = __pyx_v_low1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":686 + * + * i1 = low1 + * i2 = low2 # <<<<<<<<<<<<<< + * while i1 < high1 and i2 < high2: + * + */ + __pyx_v_i2 = __pyx_v_low2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":687 + * i1 = low1 + * i2 = low2 + * while i1 < high1 and i2 < high2: # <<<<<<<<<<<<<< + * + * # First, pop all unneeded loc2's off the stack + */ + while (1) { + __pyx_t_1 = (__pyx_v_i1 < __pyx_v_high1); + if (__pyx_t_1) { + __pyx_t_2 = (__pyx_v_i2 < __pyx_v_high2); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":690 + * + * # First, pop all unneeded loc2's off the stack + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * while i2 < high2: + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) + */ + __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc1), __pyx_v_arr1, __pyx_v_i1, __pyx_v_step1, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":691 + * # First, pop all unneeded loc2's off the stack + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + * while i2 < high2: # <<<<<<<<<<<<<< + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: + */ + while (1) { + __pyx_t_3 = (__pyx_v_i2 < __pyx_v_high2); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":692 + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + * while i2 < high2: + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: + * i2 = i2 + step2 + */ + __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, __pyx_v_i2, __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":693 + * while i2 < high2: + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: # <<<<<<<<<<<<<< + * i2 = i2 + step2 + * else: + */ + __pyx_t_3 = (((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last) == 1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":694 + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: + * i2 = i2 + step2 # <<<<<<<<<<<<<< + * else: + * break + */ + __pyx_v_i2 = (__pyx_v_i2 + __pyx_v_step2); + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":696 + * i2 = i2 + step2 + * else: + * break # <<<<<<<<<<<<<< + * + * # Next: process all loc1's with the same starting val + */ + goto __pyx_L6_break; + } + __pyx_L7:; + } + __pyx_L6_break:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":699 + * + * # Next: process all loc1's with the same starting val + * j1 = i1 # <<<<<<<<<<<<<< + * while i1 < high1 and arr1[j1] == arr1[i1]: + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + */ + __pyx_v_j1 = __pyx_v_i1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":700 + * # Next: process all loc1's with the same starting val + * j1 = i1 + * while i1 < high1 and arr1[j1] == arr1[i1]: # <<<<<<<<<<<<<< + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + * j2 = i2 + */ + while (1) { + __pyx_t_3 = (__pyx_v_i1 < __pyx_v_high1); + if (__pyx_t_3) { + __pyx_t_1 = ((__pyx_v_arr1[__pyx_v_j1]) == (__pyx_v_arr1[__pyx_v_i1])); + __pyx_t_2 = __pyx_t_1; + } else { + __pyx_t_2 = __pyx_t_3; + } + if (!__pyx_t_2) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":701 + * j1 = i1 + * while i1 < high1 and arr1[j1] == arr1[i1]: + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * j2 = i2 + * while j2 < high2: + */ + __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc1), __pyx_v_arr1, __pyx_v_i1, __pyx_v_step1, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":702 + * while i1 < high1 and arr1[j1] == arr1[i1]: + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + * j2 = i2 # <<<<<<<<<<<<<< + * while j2 < high2: + * assign_matching(&loc2, arr2, j2, step2, self.fda.sent_id.arr) + */ + __pyx_v_j2 = __pyx_v_i2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":703 + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + * j2 = i2 + * while j2 < high2: # <<<<<<<<<<<<<< + * assign_matching(&loc2, arr2, j2, step2, self.fda.sent_id.arr) + * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) + */ + while (1) { + __pyx_t_2 = (__pyx_v_j2 < __pyx_v_high2); + if (!__pyx_t_2) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":704 + * j2 = i2 + * while j2 < high2: + * assign_matching(&loc2, arr2, j2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) + * if comparison == 0: + */ + __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, __pyx_v_j2, __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":705 + * while j2 < high2: + * assign_matching(&loc2, arr2, j2, step2, self.fda.sent_id.arr) + * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) # <<<<<<<<<<<<<< + * if comparison == 0: + * result = append_combined_matching(result, &loc1, &loc2, offset_by_one, num_subpatterns, result_len) + */ + __pyx_v_comparison = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":706 + * assign_matching(&loc2, arr2, j2, step2, self.fda.sent_id.arr) + * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) + * if comparison == 0: # <<<<<<<<<<<<<< + * result = append_combined_matching(result, &loc1, &loc2, offset_by_one, num_subpatterns, result_len) + * if comparison == 1: + */ + __pyx_t_2 = (__pyx_v_comparison == 0); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":707 + * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) + * if comparison == 0: + * result = append_combined_matching(result, &loc1, &loc2, offset_by_one, num_subpatterns, result_len) # <<<<<<<<<<<<<< + * if comparison == 1: + * pass + */ + __pyx_v_result = __pyx_f_8_cdec_sa_append_combined_matching(__pyx_v_result, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_num_subpatterns, __pyx_v_result_len); + goto __pyx_L12; + } + __pyx_L12:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":708 + * if comparison == 0: + * result = append_combined_matching(result, &loc1, &loc2, offset_by_one, num_subpatterns, result_len) + * if comparison == 1: # <<<<<<<<<<<<<< + * pass + * if comparison == -1: + */ + __pyx_t_2 = (__pyx_v_comparison == 1); + if (__pyx_t_2) { + goto __pyx_L13; + } + __pyx_L13:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":710 + * if comparison == 1: + * pass + * if comparison == -1: # <<<<<<<<<<<<<< + * break + * else: + */ + __pyx_t_2 = (__pyx_v_comparison == -1); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":711 + * pass + * if comparison == -1: + * break # <<<<<<<<<<<<<< + * else: + * j2 = j2 + step2 + */ + goto __pyx_L11_break; + goto __pyx_L14; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":713 + * break + * else: + * j2 = j2 + step2 # <<<<<<<<<<<<<< + * i1 = i1 + step1 + * return result + */ + __pyx_v_j2 = (__pyx_v_j2 + __pyx_v_step2); + } + __pyx_L14:; + } + __pyx_L11_break:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":714 + * else: + * j2 = j2 + step2 + * i1 = i1 + step1 # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_v_i1 = (__pyx_v_i1 + __pyx_v_step1); + } + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":715 + * j2 = j2 + step2 + * i1 = i1 + step1 + * return result # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":718 + * + * + * cdef void sort_phrase_loc(self, IntList arr, PhraseLocation loc, Phrase phrase): # <<<<<<<<<<<<<< + * cdef int i, j + * cdef VEB veb + */ + +static void __pyx_f_8_cdec_sa_23HieroCachingRuleFactory_sort_phrase_loc(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_arr, struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_loc, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_phrase) { + int __pyx_v_i; + int __pyx_v_j; + struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_veb = 0; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("sort_phrase_loc", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":723 + * cdef IntList result + * + * if phrase in self.precomputed_index: # <<<<<<<<<<<<<< + * loc.arr = self.precomputed_index[phrase] + * else: + */ + __pyx_t_1 = ((PySequence_Contains(__pyx_v_self->precomputed_index, ((PyObject *)__pyx_v_phrase)))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":724 + * + * if phrase in self.precomputed_index: + * loc.arr = self.precomputed_index[phrase] # <<<<<<<<<<<<<< + * else: + * loc.arr = IntList(initial_len=loc.sa_high-loc.sa_low) + */ + __pyx_t_2 = PyObject_GetItem(__pyx_v_self->precomputed_index, ((PyObject *)__pyx_v_phrase)); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_8_cdec_sa_IntList))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_v_loc->arr); + __Pyx_DECREF(((PyObject *)__pyx_v_loc->arr)); + __pyx_v_loc->arr = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_2); + __pyx_t_2 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":726 + * loc.arr = self.precomputed_index[phrase] + * else: + * loc.arr = IntList(initial_len=loc.sa_high-loc.sa_low) # <<<<<<<<<<<<<< + * veb = VEB(arr.len) + * for i from loc.sa_low <= i < loc.sa_high: + */ + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_3 = PyInt_FromLong((__pyx_v_loc->sa_high - __pyx_v_loc->sa_low)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_loc->arr); + __Pyx_DECREF(((PyObject *)__pyx_v_loc->arr)); + __pyx_v_loc->arr = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":727 + * else: + * loc.arr = IntList(initial_len=loc.sa_high-loc.sa_low) + * veb = VEB(arr.len) # <<<<<<<<<<<<<< + * for i from loc.sa_low <= i < loc.sa_high: + * veb._insert(arr.arr[i]) + */ + __pyx_t_3 = PyInt_FromLong(__pyx_v_arr->len); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_VEB)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_v_veb = ((struct __pyx_obj_8_cdec_sa_VEB *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":728 + * loc.arr = IntList(initial_len=loc.sa_high-loc.sa_low) + * veb = VEB(arr.len) + * for i from loc.sa_low <= i < loc.sa_high: # <<<<<<<<<<<<<< + * veb._insert(arr.arr[i]) + * i = veb.veb.min_val + */ + __pyx_t_4 = __pyx_v_loc->sa_high; + for (__pyx_v_i = __pyx_v_loc->sa_low; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":729 + * veb = VEB(arr.len) + * for i from loc.sa_low <= i < loc.sa_high: + * veb._insert(arr.arr[i]) # <<<<<<<<<<<<<< + * i = veb.veb.min_val + * for j from 0 <= j < loc.sa_high-loc.sa_low: + */ + ((struct __pyx_vtabstruct_8_cdec_sa_VEB *)__pyx_v_veb->__pyx_vtab)->_insert(__pyx_v_veb, (__pyx_v_arr->arr[__pyx_v_i])); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":730 + * for i from loc.sa_low <= i < loc.sa_high: + * veb._insert(arr.arr[i]) + * i = veb.veb.min_val # <<<<<<<<<<<<<< + * for j from 0 <= j < loc.sa_high-loc.sa_low: + * loc.arr.arr[j] = i + */ + __pyx_v_i = __pyx_v_veb->veb->min_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":731 + * veb._insert(arr.arr[i]) + * i = veb.veb.min_val + * for j from 0 <= j < loc.sa_high-loc.sa_low: # <<<<<<<<<<<<<< + * loc.arr.arr[j] = i + * i = veb._findsucc(i) + */ + __pyx_t_4 = (__pyx_v_loc->sa_high - __pyx_v_loc->sa_low); + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_4; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":732 + * i = veb.veb.min_val + * for j from 0 <= j < loc.sa_high-loc.sa_low: + * loc.arr.arr[j] = i # <<<<<<<<<<<<<< + * i = veb._findsucc(i) + * loc.arr_low = 0 + */ + (__pyx_v_loc->arr->arr[__pyx_v_j]) = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":733 + * for j from 0 <= j < loc.sa_high-loc.sa_low: + * loc.arr.arr[j] = i + * i = veb._findsucc(i) # <<<<<<<<<<<<<< + * loc.arr_low = 0 + * loc.arr_high = loc.arr.len + */ + __pyx_v_i = ((struct __pyx_vtabstruct_8_cdec_sa_VEB *)__pyx_v_veb->__pyx_vtab)->_findsucc(__pyx_v_veb, __pyx_v_i); + } + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":734 + * loc.arr.arr[j] = i + * i = veb._findsucc(i) + * loc.arr_low = 0 # <<<<<<<<<<<<<< + * loc.arr_high = loc.arr.len + * + */ + __pyx_v_loc->arr_low = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":735 + * i = veb._findsucc(i) + * loc.arr_low = 0 + * loc.arr_high = loc.arr.len # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_loc->arr_high = __pyx_v_loc->arr->len; + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_WriteUnraisable("_cdec_sa.HieroCachingRuleFactory.sort_phrase_loc", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_veb); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":738 + * + * + * cdef intersect_helper(self, Phrase prefix, Phrase suffix, # <<<<<<<<<<<<<< + * PhraseLocation prefix_loc, PhraseLocation suffix_loc, int algorithm): + * + */ + +static PyObject *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_intersect_helper(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_prefix, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_suffix, struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_prefix_loc, struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_suffix_loc, int __pyx_v_algorithm) { + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_arr1 = 0; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_arr2 = 0; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_result = 0; + int __pyx_v_low1; + int __pyx_v_high1; + int __pyx_v_step1; + int __pyx_v_low2; + int __pyx_v_high2; + int __pyx_v_step2; + int __pyx_v_offset_by_one; + int __pyx_v_len_last; + int __pyx_v_num_subpatterns; + int __pyx_v_result_len; + int *__pyx_v_result_ptr; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + Py_ssize_t __pyx_t_5; + int __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("intersect_helper", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":745 + * cdef int* result_ptr + * + * result_len = 0 # <<<<<<<<<<<<<< + * + * if sym_isvar(suffix[0]): + */ + __pyx_v_result_len = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":747 + * result_len = 0 + * + * if sym_isvar(suffix[0]): # <<<<<<<<<<<<<< + * offset_by_one = 1 + * else: + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_isvar); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_suffix), 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":748 + * + * if sym_isvar(suffix[0]): + * offset_by_one = 1 # <<<<<<<<<<<<<< + * else: + * offset_by_one = 0 + */ + __pyx_v_offset_by_one = 1; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":750 + * offset_by_one = 1 + * else: + * offset_by_one = 0 # <<<<<<<<<<<<<< + * + * len_last = len(suffix.getchunk(suffix.arity())) + */ + __pyx_v_offset_by_one = 0; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":752 + * offset_by_one = 0 + * + * len_last = len(suffix.getchunk(suffix.arity())) # <<<<<<<<<<<<<< + * + * if prefix_loc.arr is None: + */ + __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_suffix), __pyx_n_s__getchunk); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_suffix), __pyx_n_s__arity); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_5 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_len_last = __pyx_t_5; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":754 + * len_last = len(suffix.getchunk(suffix.arity())) + * + * if prefix_loc.arr is None: # <<<<<<<<<<<<<< + * self.sort_phrase_loc(self.fsa.sa, prefix_loc, prefix) + * arr1 = prefix_loc.arr + */ + __pyx_t_4 = (((PyObject *)__pyx_v_prefix_loc->arr) == Py_None); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":755 + * + * if prefix_loc.arr is None: + * self.sort_phrase_loc(self.fsa.sa, prefix_loc, prefix) # <<<<<<<<<<<<<< + * arr1 = prefix_loc.arr + * low1 = prefix_loc.arr_low + */ + __pyx_t_1 = ((PyObject *)__pyx_v_self->fsa->sa); + __Pyx_INCREF(__pyx_t_1); + ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->sort_phrase_loc(__pyx_v_self, ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1), __pyx_v_prefix_loc, __pyx_v_prefix); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":756 + * if prefix_loc.arr is None: + * self.sort_phrase_loc(self.fsa.sa, prefix_loc, prefix) + * arr1 = prefix_loc.arr # <<<<<<<<<<<<<< + * low1 = prefix_loc.arr_low + * high1 = prefix_loc.arr_high + */ + __Pyx_INCREF(((PyObject *)__pyx_v_prefix_loc->arr)); + __pyx_v_arr1 = __pyx_v_prefix_loc->arr; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":757 + * self.sort_phrase_loc(self.fsa.sa, prefix_loc, prefix) + * arr1 = prefix_loc.arr + * low1 = prefix_loc.arr_low # <<<<<<<<<<<<<< + * high1 = prefix_loc.arr_high + * step1 = prefix_loc.num_subpatterns + */ + __pyx_v_low1 = __pyx_v_prefix_loc->arr_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":758 + * arr1 = prefix_loc.arr + * low1 = prefix_loc.arr_low + * high1 = prefix_loc.arr_high # <<<<<<<<<<<<<< + * step1 = prefix_loc.num_subpatterns + * + */ + __pyx_v_high1 = __pyx_v_prefix_loc->arr_high; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":759 + * low1 = prefix_loc.arr_low + * high1 = prefix_loc.arr_high + * step1 = prefix_loc.num_subpatterns # <<<<<<<<<<<<<< + * + * if suffix_loc.arr is None: + */ + __pyx_v_step1 = __pyx_v_prefix_loc->num_subpatterns; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":761 + * step1 = prefix_loc.num_subpatterns + * + * if suffix_loc.arr is None: # <<<<<<<<<<<<<< + * self.sort_phrase_loc(self.fsa.sa, suffix_loc, suffix) + * arr2 = suffix_loc.arr + */ + __pyx_t_4 = (((PyObject *)__pyx_v_suffix_loc->arr) == Py_None); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":762 + * + * if suffix_loc.arr is None: + * self.sort_phrase_loc(self.fsa.sa, suffix_loc, suffix) # <<<<<<<<<<<<<< + * arr2 = suffix_loc.arr + * low2 = suffix_loc.arr_low + */ + __pyx_t_1 = ((PyObject *)__pyx_v_self->fsa->sa); + __Pyx_INCREF(__pyx_t_1); + ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->sort_phrase_loc(__pyx_v_self, ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1), __pyx_v_suffix_loc, __pyx_v_suffix); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":763 + * if suffix_loc.arr is None: + * self.sort_phrase_loc(self.fsa.sa, suffix_loc, suffix) + * arr2 = suffix_loc.arr # <<<<<<<<<<<<<< + * low2 = suffix_loc.arr_low + * high2 = suffix_loc.arr_high + */ + __Pyx_INCREF(((PyObject *)__pyx_v_suffix_loc->arr)); + __pyx_v_arr2 = __pyx_v_suffix_loc->arr; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":764 + * self.sort_phrase_loc(self.fsa.sa, suffix_loc, suffix) + * arr2 = suffix_loc.arr + * low2 = suffix_loc.arr_low # <<<<<<<<<<<<<< + * high2 = suffix_loc.arr_high + * step2 = suffix_loc.num_subpatterns + */ + __pyx_v_low2 = __pyx_v_suffix_loc->arr_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":765 + * arr2 = suffix_loc.arr + * low2 = suffix_loc.arr_low + * high2 = suffix_loc.arr_high # <<<<<<<<<<<<<< + * step2 = suffix_loc.num_subpatterns + * + */ + __pyx_v_high2 = __pyx_v_suffix_loc->arr_high; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":766 + * low2 = suffix_loc.arr_low + * high2 = suffix_loc.arr_high + * step2 = suffix_loc.num_subpatterns # <<<<<<<<<<<<<< + * + * num_subpatterns = prefix.arity()+1 + */ + __pyx_v_step2 = __pyx_v_suffix_loc->num_subpatterns; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":768 + * step2 = suffix_loc.num_subpatterns + * + * num_subpatterns = prefix.arity()+1 # <<<<<<<<<<<<<< + * + * if algorithm == MERGE: + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_prefix), __pyx_n_s__arity); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Add(__pyx_t_3, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_num_subpatterns = __pyx_t_6; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":770 + * num_subpatterns = prefix.arity()+1 + * + * if algorithm == MERGE: # <<<<<<<<<<<<<< + * result_ptr = self.merge_helper(low1, high1, arr1.arr, step1, + * low2, high2, arr2.arr, step2, + */ + __pyx_t_4 = (__pyx_v_algorithm == __pyx_v_8_cdec_sa_MERGE); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":773 + * result_ptr = self.merge_helper(low1, high1, arr1.arr, step1, + * low2, high2, arr2.arr, step2, + * offset_by_one, len_last, num_subpatterns, &result_len) # <<<<<<<<<<<<<< + * else: + * result_ptr = self.baeza_yates_helper(low1, high1, arr1.arr, step1, + */ + __pyx_v_result_ptr = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->merge_helper(__pyx_v_self, __pyx_v_low1, __pyx_v_high1, __pyx_v_arr1->arr, __pyx_v_step1, __pyx_v_low2, __pyx_v_high2, __pyx_v_arr2->arr, __pyx_v_step2, __pyx_v_offset_by_one, __pyx_v_len_last, __pyx_v_num_subpatterns, (&__pyx_v_result_len)); + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":777 + * result_ptr = self.baeza_yates_helper(low1, high1, arr1.arr, step1, + * low2, high2, arr2.arr, step2, + * offset_by_one, len_last, num_subpatterns, &result_len) # <<<<<<<<<<<<<< + * + * if result_len == 0: + */ + __pyx_v_result_ptr = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->baeza_yates_helper(__pyx_v_self, __pyx_v_low1, __pyx_v_high1, __pyx_v_arr1->arr, __pyx_v_step1, __pyx_v_low2, __pyx_v_high2, __pyx_v_arr2->arr, __pyx_v_step2, __pyx_v_offset_by_one, __pyx_v_len_last, __pyx_v_num_subpatterns, (&__pyx_v_result_len)); + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":779 + * offset_by_one, len_last, num_subpatterns, &result_len) + * + * if result_len == 0: # <<<<<<<<<<<<<< + * free(result_ptr) + * return None + */ + __pyx_t_4 = (__pyx_v_result_len == 0); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":780 + * + * if result_len == 0: + * free(result_ptr) # <<<<<<<<<<<<<< + * return None + * else: + */ + free(__pyx_v_result_ptr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":781 + * if result_len == 0: + * free(result_ptr) + * return None # <<<<<<<<<<<<<< + * else: + * result = IntList() + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_None); + __pyx_r = Py_None; + goto __pyx_L0; + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":783 + * return None + * else: + * result = IntList() # <<<<<<<<<<<<<< + * free(result.arr) + * result.arr = result_ptr + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":784 + * else: + * result = IntList() + * free(result.arr) # <<<<<<<<<<<<<< + * result.arr = result_ptr + * result.len = result_len + */ + free(__pyx_v_result->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":785 + * result = IntList() + * free(result.arr) + * result.arr = result_ptr # <<<<<<<<<<<<<< + * result.len = result_len + * result.size = result_len + */ + __pyx_v_result->arr = __pyx_v_result_ptr; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":786 + * free(result.arr) + * result.arr = result_ptr + * result.len = result_len # <<<<<<<<<<<<<< + * result.size = result_len + * return PhraseLocation(arr_low=0, arr_high=result_len, arr=result, num_subpatterns=num_subpatterns) + */ + __pyx_v_result->len = __pyx_v_result_len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":787 + * result.arr = result_ptr + * result.len = result_len + * result.size = result_len # <<<<<<<<<<<<<< + * return PhraseLocation(arr_low=0, arr_high=result_len, arr=result, num_subpatterns=num_subpatterns) + * + */ + __pyx_v_result->size = __pyx_v_result_len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":788 + * result.len = result_len + * result.size = result_len + * return PhraseLocation(arr_low=0, arr_high=result_len, arr=result, num_subpatterns=num_subpatterns) # <<<<<<<<<<<<<< + * + * cdef loc2str(self, PhraseLocation loc): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__arr_low), __pyx_int_0) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(__pyx_v_result_len); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__arr_high), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__arr), ((PyObject *)__pyx_v_result)) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(__pyx_v_num_subpatterns); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__num_subpatterns), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_PhraseLocation)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + } + __pyx_L7:; + + __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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.intersect_helper", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_arr1); + __Pyx_XDECREF((PyObject *)__pyx_v_arr2); + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":790 + * return PhraseLocation(arr_low=0, arr_high=result_len, arr=result, num_subpatterns=num_subpatterns) + * + * cdef loc2str(self, PhraseLocation loc): # <<<<<<<<<<<<<< + * cdef int i, j + * result = "{" + */ + +static PyObject *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_loc2str(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_loc) { + int __pyx_v_i; + int __pyx_v_j; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("loc2str", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":792 + * cdef loc2str(self, PhraseLocation loc): + * cdef int i, j + * result = "{" # <<<<<<<<<<<<<< + * i = 0 + * while i < loc.arr_high: + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_114)); + __pyx_v_result = ((PyObject *)__pyx_kp_s_114); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":793 + * cdef int i, j + * result = "{" + * i = 0 # <<<<<<<<<<<<<< + * while i < loc.arr_high: + * result = result + "(" + */ + __pyx_v_i = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":794 + * result = "{" + * i = 0 + * while i < loc.arr_high: # <<<<<<<<<<<<<< + * result = result + "(" + * for j from i <= j < i + loc.num_subpatterns: + */ + while (1) { + __pyx_t_1 = (__pyx_v_i < __pyx_v_loc->arr_high); + if (!__pyx_t_1) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":795 + * i = 0 + * while i < loc.arr_high: + * result = result + "(" # <<<<<<<<<<<<<< + * for j from i <= j < i + loc.num_subpatterns: + * result = result + ("%d " %loc.arr[j]) + */ + __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_kp_s_115)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":796 + * while i < loc.arr_high: + * result = result + "(" + * for j from i <= j < i + loc.num_subpatterns: # <<<<<<<<<<<<<< + * result = result + ("%d " %loc.arr[j]) + * result = result + ")" + */ + __pyx_t_3 = (__pyx_v_i + __pyx_v_loc->num_subpatterns); + for (__pyx_v_j = __pyx_v_i; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":797 + * result = result + "(" + * for j from i <= j < i + loc.num_subpatterns: + * result = result + ("%d " %loc.arr[j]) # <<<<<<<<<<<<<< + * result = result + ")" + * i = i + loc.num_subpatterns + */ + __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_loc->arr), __pyx_v_j, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_t_2; + __pyx_t_2 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":798 + * for j from i <= j < i + loc.num_subpatterns: + * result = result + ("%d " %loc.arr[j]) + * result = result + ")" # <<<<<<<<<<<<<< + * i = i + loc.num_subpatterns + * result = result + "}" + */ + __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_kp_s_56)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":799 + * result = result + ("%d " %loc.arr[j]) + * result = result + ")" + * i = i + loc.num_subpatterns # <<<<<<<<<<<<<< + * result = result + "}" + * return result + */ + __pyx_v_i = (__pyx_v_i + __pyx_v_loc->num_subpatterns); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":800 + * result = result + ")" + * i = i + loc.num_subpatterns + * result = result + "}" # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_kp_s_116)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":801 + * i = i + loc.num_subpatterns + * result = result + "}" + * return result # <<<<<<<<<<<<<< + * + * cdef PhraseLocation intersect(self, prefix_node, suffix_node, Phrase phrase): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.loc2str", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":803 + * return result + * + * cdef PhraseLocation intersect(self, prefix_node, suffix_node, Phrase phrase): # <<<<<<<<<<<<<< + * cdef Phrase prefix, suffix + * cdef PhraseLocation prefix_loc, suffix_loc, result + */ + +static struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_intersect(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_prefix_node, PyObject *__pyx_v_suffix_node, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_phrase) { + struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_prefix = 0; + struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_suffix = 0; + struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_prefix_loc = 0; + struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_suffix_loc = 0; + struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_result = 0; + CYTHON_UNUSED PyObject *__pyx_v_intersect_method = NULL; + struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("intersect", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":807 + * cdef PhraseLocation prefix_loc, suffix_loc, result + * + * prefix = prefix_node.phrase # <<<<<<<<<<<<<< + * suffix = suffix_node.phrase + * prefix_loc = prefix_node.phrase_location + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_prefix_node, __pyx_n_s__phrase); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 807; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8_cdec_sa_Phrase))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 807; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_prefix = ((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":808 + * + * prefix = prefix_node.phrase + * suffix = suffix_node.phrase # <<<<<<<<<<<<<< + * prefix_loc = prefix_node.phrase_location + * suffix_loc = suffix_node.phrase_location + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_suffix_node, __pyx_n_s__phrase); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8_cdec_sa_Phrase))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_suffix = ((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":809 + * prefix = prefix_node.phrase + * suffix = suffix_node.phrase + * prefix_loc = prefix_node.phrase_location # <<<<<<<<<<<<<< + * suffix_loc = suffix_node.phrase_location + * + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_prefix_node, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 809; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8_cdec_sa_PhraseLocation))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 809; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_prefix_loc = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":810 + * suffix = suffix_node.phrase + * prefix_loc = prefix_node.phrase_location + * suffix_loc = suffix_node.phrase_location # <<<<<<<<<<<<<< + * + * result = self.get_precomputed_collocation(phrase) + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_suffix_node, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 810; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8_cdec_sa_PhraseLocation))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 810; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_suffix_loc = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":812 + * suffix_loc = suffix_node.phrase_location + * + * result = self.get_precomputed_collocation(phrase) # <<<<<<<<<<<<<< + * if result is not None: + * intersect_method = "precomputed" + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s_117); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_v_phrase)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_phrase)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_phrase)); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_8_cdec_sa_PhraseLocation))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_result = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":813 + * + * result = self.get_precomputed_collocation(phrase) + * if result is not None: # <<<<<<<<<<<<<< + * intersect_method = "precomputed" + * + */ + __pyx_t_4 = (((PyObject *)__pyx_v_result) != Py_None); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":814 + * result = self.get_precomputed_collocation(phrase) + * if result is not None: + * intersect_method = "precomputed" # <<<<<<<<<<<<<< + * + * if result is None: + */ + __Pyx_INCREF(((PyObject *)__pyx_n_s__precomputed)); + __pyx_v_intersect_method = ((PyObject *)__pyx_n_s__precomputed); + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":816 + * intersect_method = "precomputed" + * + * if result is None: # <<<<<<<<<<<<<< + * if self.use_baeza_yates: + * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, BAEZA_YATES) + */ + __pyx_t_4 = (((PyObject *)__pyx_v_result) == Py_None); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":817 + * + * if result is None: + * if self.use_baeza_yates: # <<<<<<<<<<<<<< + * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, BAEZA_YATES) + * intersect_method="double binary" + */ + if (__pyx_v_self->use_baeza_yates) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":818 + * if result is None: + * if self.use_baeza_yates: + * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, BAEZA_YATES) # <<<<<<<<<<<<<< + * intersect_method="double binary" + * else: + */ + __pyx_t_3 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->intersect_helper(__pyx_v_self, __pyx_v_prefix, __pyx_v_suffix, __pyx_v_prefix_loc, __pyx_v_suffix_loc, __pyx_v_8_cdec_sa_BAEZA_YATES); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_8_cdec_sa_PhraseLocation))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_v_result)); + __pyx_v_result = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":819 + * if self.use_baeza_yates: + * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, BAEZA_YATES) + * intersect_method="double binary" # <<<<<<<<<<<<<< + * else: + * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, MERGE) + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_118)); + __Pyx_XDECREF(__pyx_v_intersect_method); + __pyx_v_intersect_method = ((PyObject *)__pyx_kp_s_118); + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":821 + * intersect_method="double binary" + * else: + * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, MERGE) # <<<<<<<<<<<<<< + * intersect_method="merge" + * return result + */ + __pyx_t_3 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->intersect_helper(__pyx_v_self, __pyx_v_prefix, __pyx_v_suffix, __pyx_v_prefix_loc, __pyx_v_suffix_loc, __pyx_v_8_cdec_sa_MERGE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_8_cdec_sa_PhraseLocation))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_v_result)); + __pyx_v_result = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":822 + * else: + * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, MERGE) + * intersect_method="merge" # <<<<<<<<<<<<<< + * return result + * + */ + __Pyx_INCREF(((PyObject *)__pyx_n_s__merge)); + __Pyx_XDECREF(__pyx_v_intersect_method); + __pyx_v_intersect_method = ((PyObject *)__pyx_n_s__merge); + } + __pyx_L5:; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":823 + * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, MERGE) + * intersect_method="merge" + * return result # <<<<<<<<<<<<<< + * + * def advance(self, frontier, res, fwords): + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)Py_None); __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.intersect", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_prefix); + __Pyx_XDECREF((PyObject *)__pyx_v_suffix); + __Pyx_XDECREF((PyObject *)__pyx_v_prefix_loc); + __Pyx_XDECREF((PyObject *)__pyx_v_suffix_loc); + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XDECREF(__pyx_v_intersect_method); + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_13advance(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_13advance(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_frontier = 0; + PyObject *__pyx_v_res = 0; + PyObject *__pyx_v_fwords = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__frontier,&__pyx_n_s__res,&__pyx_n_s__fwords,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("advance (wrapper)", 0); + { + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__frontier); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__res); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("advance", 1, 3, 3, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fwords); + if (likely(values[2])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("advance", 1, 3, 3, 2); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "advance") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_frontier = values[0]; + __pyx_v_res = values[1]; + __pyx_v_fwords = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("advance", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.advance", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_12advance(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_frontier, __pyx_v_res, __pyx_v_fwords); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":825 + * return result + * + * def advance(self, frontier, res, fwords): # <<<<<<<<<<<<<< + * cdef unsigned na + * nf = [] + */ + +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_12advance(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_frontier, PyObject *__pyx_v_res, PyObject *__pyx_v_fwords) { + unsigned int __pyx_v_na; + PyObject *__pyx_v_nf = NULL; + PyObject *__pyx_v_toskip = NULL; + PyObject *__pyx_v_i = NULL; + PyObject *__pyx_v_alt = NULL; + PyObject *__pyx_v_pathlen = NULL; + PyObject *__pyx_v_spanlen = NULL; + PyObject *__pyx_v_ni = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *(*__pyx_t_8)(PyObject *); + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + int __pyx_t_12; + Py_ssize_t __pyx_t_13; + int __pyx_t_14; + int __pyx_t_15; + unsigned int __pyx_t_16; + int __pyx_t_17; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("advance", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":827 + * def advance(self, frontier, res, fwords): + * cdef unsigned na + * nf = [] # <<<<<<<<<<<<<< + * for (toskip, (i, alt, pathlen)) in frontier: + * spanlen = fwords[i][alt][2] + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_nf = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":828 + * cdef unsigned na + * nf = [] + * for (toskip, (i, alt, pathlen)) in frontier: # <<<<<<<<<<<<<< + * spanlen = fwords[i][alt][2] + * if (toskip == 0): + */ + if (PyList_CheckExact(__pyx_v_frontier) || PyTuple_CheckExact(__pyx_v_frontier)) { + __pyx_t_1 = __pyx_v_frontier; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_frontier); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) { + PyObject* sequence = __pyx_t_4; + if (likely(PyTuple_CheckExact(sequence))) { + 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[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_5 = PyList_GET_ITEM(sequence, 0); + __pyx_t_6 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_5 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L6_unpacking_done; + __pyx_L5_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L6_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_toskip); + __pyx_v_toskip = __pyx_t_5; + __pyx_t_5 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) { + PyObject* sequence = __pyx_t_6; + if (likely(PyTuple_CheckExact(sequence))) { + if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { + if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); + } else { + if (unlikely(PyList_GET_SIZE(sequence) != 3)) { + if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_7 = PyList_GET_ITEM(sequence, 0); + __pyx_t_9 = PyList_GET_ITEM(sequence, 1); + __pyx_t_10 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_11 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_11)->tp_iternext; + index = 0; __pyx_t_7 = __pyx_t_8(__pyx_t_11); if (unlikely(!__pyx_t_7)) goto __pyx_L7_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + index = 1; __pyx_t_9 = __pyx_t_8(__pyx_t_11); if (unlikely(!__pyx_t_9)) goto __pyx_L7_unpacking_failed; + __Pyx_GOTREF(__pyx_t_9); + index = 2; __pyx_t_10 = __pyx_t_8(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L7_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_11), 3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L8_unpacking_done; + __pyx_L7_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[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L8_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_7; + __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_v_alt); + __pyx_v_alt = __pyx_t_9; + __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_v_pathlen); + __pyx_v_pathlen = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":829 + * nf = [] + * for (toskip, (i, alt, pathlen)) in frontier: + * spanlen = fwords[i][alt][2] # <<<<<<<<<<<<<< + * if (toskip == 0): + * res.append((i, alt, pathlen)) + */ + __pyx_t_4 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_i); if (!__pyx_t_4) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = PyObject_GetItem(__pyx_t_4, __pyx_v_alt); if (!__pyx_t_6) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_6, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_v_spanlen); + __pyx_v_spanlen = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":830 + * for (toskip, (i, alt, pathlen)) in frontier: + * spanlen = fwords[i][alt][2] + * if (toskip == 0): # <<<<<<<<<<<<<< + * res.append((i, alt, pathlen)) + * ni = i + spanlen + */ + __pyx_t_4 = PyObject_RichCompare(__pyx_v_toskip, __pyx_int_0, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_12) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":831 + * spanlen = fwords[i][alt][2] + * if (toskip == 0): + * res.append((i, alt, pathlen)) # <<<<<<<<<<<<<< + * ni = i + spanlen + * if (ni < len(fwords) and (pathlen + 1) < self.max_initial_size): + */ + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + __Pyx_INCREF(__pyx_v_alt); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_alt); + __Pyx_GIVEREF(__pyx_v_alt); + __Pyx_INCREF(__pyx_v_pathlen); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_pathlen); + __Pyx_GIVEREF(__pyx_v_pathlen); + __pyx_t_6 = __Pyx_PyObject_Append(__pyx_v_res, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L9; + } + __pyx_L9:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":832 + * if (toskip == 0): + * res.append((i, alt, pathlen)) + * ni = i + spanlen # <<<<<<<<<<<<<< + * if (ni < len(fwords) and (pathlen + 1) < self.max_initial_size): + * for na in range(len(fwords[ni])): + */ + __pyx_t_6 = PyNumber_Add(__pyx_v_i, __pyx_v_spanlen); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_v_ni); + __pyx_v_ni = __pyx_t_6; + __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":833 + * res.append((i, alt, pathlen)) + * ni = i + spanlen + * if (ni < len(fwords) and (pathlen + 1) < self.max_initial_size): # <<<<<<<<<<<<<< + * for na in range(len(fwords[ni])): + * nf.append((toskip - 1, (ni, na, pathlen + 1))) + */ + __pyx_t_13 = PyObject_Length(__pyx_v_fwords); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyInt_FromSsize_t(__pyx_t_13); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_ni, __pyx_t_6, Py_LT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_12) { + __pyx_t_4 = PyNumber_Add(__pyx_v_pathlen, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = PyInt_FromLong(__pyx_v_self->max_initial_size); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_t_6, Py_LT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_15 = __pyx_t_14; + } else { + __pyx_t_15 = __pyx_t_12; + } + if (__pyx_t_15) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":834 + * ni = i + spanlen + * if (ni < len(fwords) and (pathlen + 1) < self.max_initial_size): + * for na in range(len(fwords[ni])): # <<<<<<<<<<<<<< + * nf.append((toskip - 1, (ni, na, pathlen + 1))) + * if (len(nf) > 0): + */ + __pyx_t_5 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ni); if (!__pyx_t_5) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_13 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_13; __pyx_t_16+=1) { + __pyx_v_na = __pyx_t_16; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":835 + * if (ni < len(fwords) and (pathlen + 1) < self.max_initial_size): + * for na in range(len(fwords[ni])): + * nf.append((toskip - 1, (ni, na, pathlen + 1))) # <<<<<<<<<<<<<< + * if (len(nf) > 0): + * return self.advance(nf, res, fwords) + */ + __pyx_t_5 = PyNumber_Subtract(__pyx_v_toskip, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyLong_FromUnsignedLong(__pyx_v_na); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = PyNumber_Add(__pyx_v_pathlen, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_v_ni); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_ni); + __Pyx_GIVEREF(__pyx_v_ni); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_6 = 0; + __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_t_10)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); + __pyx_t_5 = 0; + __pyx_t_10 = 0; + __pyx_t_17 = PyList_Append(__pyx_v_nf, ((PyObject *)__pyx_t_4)); if (unlikely(__pyx_t_17 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + } + goto __pyx_L10; + } + __pyx_L10:; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":836 + * for na in range(len(fwords[ni])): + * nf.append((toskip - 1, (ni, na, pathlen + 1))) + * if (len(nf) > 0): # <<<<<<<<<<<<<< + * return self.advance(nf, res, fwords) + * else: + */ + __pyx_t_2 = PyList_GET_SIZE(((PyObject *)__pyx_v_nf)); + __pyx_t_15 = (__pyx_t_2 > 0); + if (__pyx_t_15) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":837 + * nf.append((toskip - 1, (ni, na, pathlen + 1))) + * if (len(nf) > 0): + * return self.advance(nf, res, fwords) # <<<<<<<<<<<<<< + * else: + * return res + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__advance); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(((PyObject *)__pyx_v_nf)); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_nf)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_nf)); + __Pyx_INCREF(__pyx_v_res); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_res); + __Pyx_GIVEREF(__pyx_v_res); + __Pyx_INCREF(__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_fwords); + __Pyx_GIVEREF(__pyx_v_fwords); + __pyx_t_10 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_r = __pyx_t_10; + __pyx_t_10 = 0; + goto __pyx_L0; + goto __pyx_L13; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":839 + * return self.advance(nf, res, fwords) + * else: + * return res # <<<<<<<<<<<<<< + * + * def get_all_nodes_isteps_away(self, skip, i, spanlen, pathlen, fwords, next_states, reachable_buffer): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_res); + __pyx_r = __pyx_v_res; + goto __pyx_L0; + } + __pyx_L13:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.advance", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_nf); + __Pyx_XDECREF(__pyx_v_toskip); + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_alt); + __Pyx_XDECREF(__pyx_v_pathlen); + __Pyx_XDECREF(__pyx_v_spanlen); + __Pyx_XDECREF(__pyx_v_ni); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_15get_all_nodes_isteps_away(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_15get_all_nodes_isteps_away(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_skip = 0; + PyObject *__pyx_v_i = 0; + PyObject *__pyx_v_spanlen = 0; + PyObject *__pyx_v_pathlen = 0; + PyObject *__pyx_v_fwords = 0; + PyObject *__pyx_v_next_states = 0; + PyObject *__pyx_v_reachable_buffer = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__skip,&__pyx_n_s__i,&__pyx_n_s__spanlen,&__pyx_n_s__pathlen,&__pyx_n_s__fwords,&__pyx_n_s__next_states,&__pyx_n_s__reachable_buffer,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_all_nodes_isteps_away (wrapper)", 0); + { + PyObject* values[7] = {0,0,0,0,0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__skip); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__i); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__spanlen); + if (likely(values[2])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, 2); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 3: + values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pathlen); + if (likely(values[3])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, 3); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 4: + values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fwords); + if (likely(values[4])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, 4); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 5: + values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__next_states); + if (likely(values[5])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, 5); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 6: + values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reachable_buffer); + if (likely(values[6])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, 6); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_all_nodes_isteps_away") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 7) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + } + __pyx_v_skip = values[0]; + __pyx_v_i = values[1]; + __pyx_v_spanlen = values[2]; + __pyx_v_pathlen = values[3]; + __pyx_v_fwords = values[4]; + __pyx_v_next_states = values[5]; + __pyx_v_reachable_buffer = values[6]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.get_all_nodes_isteps_away", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_14get_all_nodes_isteps_away(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_skip, __pyx_v_i, __pyx_v_spanlen, __pyx_v_pathlen, __pyx_v_fwords, __pyx_v_next_states, __pyx_v_reachable_buffer); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":841 + * return res + * + * def get_all_nodes_isteps_away(self, skip, i, spanlen, pathlen, fwords, next_states, reachable_buffer): # <<<<<<<<<<<<<< + * cdef unsigned alt_it + * frontier = [] + */ + +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_14get_all_nodes_isteps_away(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_skip, PyObject *__pyx_v_i, PyObject *__pyx_v_spanlen, PyObject *__pyx_v_pathlen, PyObject *__pyx_v_fwords, PyObject *__pyx_v_next_states, PyObject *__pyx_v_reachable_buffer) { + PyObject *__pyx_v_frontier = NULL; + PyObject *__pyx_v_key = NULL; + PyObject *__pyx_v_reachable = NULL; + PyObject *__pyx_v_nextreachable = NULL; + PyObject *__pyx_v_next_id = NULL; + PyObject *__pyx_v_jump = NULL; + PyObject *__pyx_v_alt_id = NULL; + PyObject *__pyx_v_newel = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + PyObject *(*__pyx_t_6)(PyObject *); + Py_ssize_t __pyx_t_7; + PyObject *(*__pyx_t_8)(PyObject *); + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + Py_ssize_t __pyx_t_11; + PyObject *(*__pyx_t_12)(PyObject *); + PyObject *__pyx_t_13 = NULL; + int __pyx_t_14; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_all_nodes_isteps_away", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":843 + * def get_all_nodes_isteps_away(self, skip, i, spanlen, pathlen, fwords, next_states, reachable_buffer): + * cdef unsigned alt_it + * frontier = [] # <<<<<<<<<<<<<< + * if (i+spanlen+skip >= len(next_states)): + * return frontier + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 843; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_frontier = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":844 + * cdef unsigned alt_it + * frontier = [] + * if (i+spanlen+skip >= len(next_states)): # <<<<<<<<<<<<<< + * return frontier + * key = tuple([i,spanlen]) + */ + __pyx_t_1 = PyNumber_Add(__pyx_v_i, __pyx_v_spanlen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_v_skip); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = PyObject_Length(__pyx_v_next_states); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_1, Py_GE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":845 + * frontier = [] + * if (i+spanlen+skip >= len(next_states)): + * return frontier # <<<<<<<<<<<<<< + * key = tuple([i,spanlen]) + * reachable = [] + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_frontier)); + __pyx_r = ((PyObject *)__pyx_v_frontier); + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":846 + * if (i+spanlen+skip >= len(next_states)): + * return frontier + * key = tuple([i,spanlen]) # <<<<<<<<<<<<<< + * reachable = [] + * if (key in reachable_buffer): + */ + __pyx_t_4 = PyList_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_i); + PyList_SET_ITEM(__pyx_t_4, 0, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + __Pyx_INCREF(__pyx_v_spanlen); + PyList_SET_ITEM(__pyx_t_4, 1, __pyx_v_spanlen); + __Pyx_GIVEREF(__pyx_v_spanlen); + __pyx_t_1 = ((PyObject *)PyList_AsTuple(__pyx_t_4)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_v_key = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":847 + * return frontier + * key = tuple([i,spanlen]) + * reachable = [] # <<<<<<<<<<<<<< + * if (key in reachable_buffer): + * reachable = reachable_buffer[key] + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 847; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_reachable = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":848 + * key = tuple([i,spanlen]) + * reachable = [] + * if (key in reachable_buffer): # <<<<<<<<<<<<<< + * reachable = reachable_buffer[key] + * else: + */ + __pyx_t_5 = ((PySequence_Contains(__pyx_v_reachable_buffer, ((PyObject *)__pyx_v_key)))); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 848; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":849 + * reachable = [] + * if (key in reachable_buffer): + * reachable = reachable_buffer[key] # <<<<<<<<<<<<<< + * else: + * reachable = self.reachable(fwords, i, spanlen) + */ + __pyx_t_1 = PyObject_GetItem(__pyx_v_reachable_buffer, ((PyObject *)__pyx_v_key)); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_v_reachable); + __pyx_v_reachable = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":851 + * reachable = reachable_buffer[key] + * else: + * reachable = self.reachable(fwords, i, spanlen) # <<<<<<<<<<<<<< + * reachable_buffer[key] = reachable + * for nextreachable in reachable: + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__reachable); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 851; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 851; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_fwords); + __Pyx_GIVEREF(__pyx_v_fwords); + __Pyx_INCREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + __Pyx_INCREF(__pyx_v_spanlen); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_spanlen); + __Pyx_GIVEREF(__pyx_v_spanlen); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 851; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_v_reachable); + __pyx_v_reachable = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":852 + * else: + * reachable = self.reachable(fwords, i, spanlen) + * reachable_buffer[key] = reachable # <<<<<<<<<<<<<< + * for nextreachable in reachable: + * for next_id in next_states[nextreachable]: + */ + if (PyObject_SetItem(__pyx_v_reachable_buffer, ((PyObject *)__pyx_v_key), __pyx_v_reachable) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 852; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":853 + * reachable = self.reachable(fwords, i, spanlen) + * reachable_buffer[key] = reachable + * for nextreachable in reachable: # <<<<<<<<<<<<<< + * for next_id in next_states[nextreachable]: + * jump = self.shortest(fwords,i,next_id) + */ + if (PyList_CheckExact(__pyx_v_reachable) || PyTuple_CheckExact(__pyx_v_reachable)) { + __pyx_t_2 = __pyx_v_reachable; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; + __pyx_t_6 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_reachable); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; + } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; + } else { + __pyx_t_4 = __pyx_t_6(__pyx_t_2); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_nextreachable); + __pyx_v_nextreachable = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":854 + * reachable_buffer[key] = reachable + * for nextreachable in reachable: + * for next_id in next_states[nextreachable]: # <<<<<<<<<<<<<< + * jump = self.shortest(fwords,i,next_id) + * if jump < skip: + */ + __pyx_t_4 = PyObject_GetItem(__pyx_v_next_states, __pyx_v_nextreachable); if (!__pyx_t_4) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + if (PyList_CheckExact(__pyx_t_4) || PyTuple_CheckExact(__pyx_t_4)) { + __pyx_t_1 = __pyx_t_4; __Pyx_INCREF(__pyx_t_1); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + } else { + __pyx_t_7 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + for (;;) { + if (!__pyx_t_8 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; + } else if (!__pyx_t_8 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; + } else { + __pyx_t_4 = __pyx_t_8(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_next_id); + __pyx_v_next_id = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":855 + * for nextreachable in reachable: + * for next_id in next_states[nextreachable]: + * jump = self.shortest(fwords,i,next_id) # <<<<<<<<<<<<<< + * if jump < skip: + * continue + */ + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__shortest); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 855; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 855; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_INCREF(__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_fwords); + __Pyx_GIVEREF(__pyx_v_fwords); + __Pyx_INCREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + __Pyx_INCREF(__pyx_v_next_id); + PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_v_next_id); + __Pyx_GIVEREF(__pyx_v_next_id); + __pyx_t_10 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 855; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_v_jump); + __pyx_v_jump = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":856 + * for next_id in next_states[nextreachable]: + * jump = self.shortest(fwords,i,next_id) + * if jump < skip: # <<<<<<<<<<<<<< + * continue + * if pathlen+jump <= self.max_initial_size: + */ + __pyx_t_10 = PyObject_RichCompare(__pyx_v_jump, __pyx_v_skip, Py_LT); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 856; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 856; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":857 + * jump = self.shortest(fwords,i,next_id) + * if jump < skip: + * continue # <<<<<<<<<<<<<< + * if pathlen+jump <= self.max_initial_size: + * for alt_id in range(len(fwords[next_id])): + */ + goto __pyx_L7_continue; + goto __pyx_L9; + } + __pyx_L9:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":858 + * if jump < skip: + * continue + * if pathlen+jump <= self.max_initial_size: # <<<<<<<<<<<<<< + * for alt_id in range(len(fwords[next_id])): + * if (fwords[next_id][alt_id][0] != EPSILON): + */ + __pyx_t_10 = PyNumber_Add(__pyx_v_pathlen, __pyx_v_jump); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 858; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyInt_FromLong(__pyx_v_self->max_initial_size); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 858; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_10, __pyx_t_9, Py_LE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 858; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 858; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":859 + * continue + * if pathlen+jump <= self.max_initial_size: + * for alt_id in range(len(fwords[next_id])): # <<<<<<<<<<<<<< + * if (fwords[next_id][alt_id][0] != EPSILON): + * newel = (next_id,alt_id,pathlen+jump) + */ + __pyx_t_4 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_next_id); if (!__pyx_t_4) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_11 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_11); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + if (PyList_CheckExact(__pyx_t_4) || PyTuple_CheckExact(__pyx_t_4)) { + __pyx_t_9 = __pyx_t_4; __Pyx_INCREF(__pyx_t_9); __pyx_t_11 = 0; + __pyx_t_12 = NULL; + } else { + __pyx_t_11 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_12 = Py_TYPE(__pyx_t_9)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + for (;;) { + if (!__pyx_t_12 && PyList_CheckExact(__pyx_t_9)) { + if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_9)) break; + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_11); __Pyx_INCREF(__pyx_t_4); __pyx_t_11++; + } else if (!__pyx_t_12 && PyTuple_CheckExact(__pyx_t_9)) { + if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_9)) break; + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_11); __Pyx_INCREF(__pyx_t_4); __pyx_t_11++; + } else { + __pyx_t_4 = __pyx_t_12(__pyx_t_9); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_alt_id); + __pyx_v_alt_id = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":860 + * if pathlen+jump <= self.max_initial_size: + * for alt_id in range(len(fwords[next_id])): + * if (fwords[next_id][alt_id][0] != EPSILON): # <<<<<<<<<<<<<< + * newel = (next_id,alt_id,pathlen+jump) + * if newel not in frontier: + */ + __pyx_t_4 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_next_id); if (!__pyx_t_4) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_10 = PyObject_GetItem(__pyx_t_4, __pyx_v_alt_id); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_10, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = PyInt_FromLong(__pyx_v_8_cdec_sa_EPSILON); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_13 = PyObject_RichCompare(__pyx_t_4, __pyx_t_10, Py_NE); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":861 + * for alt_id in range(len(fwords[next_id])): + * if (fwords[next_id][alt_id][0] != EPSILON): + * newel = (next_id,alt_id,pathlen+jump) # <<<<<<<<<<<<<< + * if newel not in frontier: + * frontier.append((next_id,alt_id,pathlen+jump)) + */ + __pyx_t_13 = PyNumber_Add(__pyx_v_pathlen, __pyx_v_jump); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_v_next_id); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_next_id); + __Pyx_GIVEREF(__pyx_v_next_id); + __Pyx_INCREF(__pyx_v_alt_id); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_alt_id); + __Pyx_GIVEREF(__pyx_v_alt_id); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_13); + __Pyx_GIVEREF(__pyx_t_13); + __pyx_t_13 = 0; + __Pyx_XDECREF(((PyObject *)__pyx_v_newel)); + __pyx_v_newel = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":862 + * if (fwords[next_id][alt_id][0] != EPSILON): + * newel = (next_id,alt_id,pathlen+jump) + * if newel not in frontier: # <<<<<<<<<<<<<< + * frontier.append((next_id,alt_id,pathlen+jump)) + * return frontier + */ + __pyx_t_5 = (__Pyx_NegateNonNeg(PySequence_Contains(((PyObject *)__pyx_v_frontier), ((PyObject *)__pyx_v_newel)))); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 862; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":863 + * newel = (next_id,alt_id,pathlen+jump) + * if newel not in frontier: + * frontier.append((next_id,alt_id,pathlen+jump)) # <<<<<<<<<<<<<< + * return frontier + * + */ + __pyx_t_10 = PyNumber_Add(__pyx_v_pathlen, __pyx_v_jump); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_13 = PyTuple_New(3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_INCREF(__pyx_v_next_id); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_v_next_id); + __Pyx_GIVEREF(__pyx_v_next_id); + __Pyx_INCREF(__pyx_v_alt_id); + PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_v_alt_id); + __Pyx_GIVEREF(__pyx_v_alt_id); + PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_t_10 = 0; + __pyx_t_14 = PyList_Append(__pyx_v_frontier, ((PyObject *)__pyx_t_13)); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + goto __pyx_L14; + } + __pyx_L14:; + goto __pyx_L13; + } + __pyx_L13:; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L10; + } + __pyx_L10:; + __pyx_L7_continue:; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":864 + * if newel not in frontier: + * frontier.append((next_id,alt_id,pathlen+jump)) + * return frontier # <<<<<<<<<<<<<< + * + * def reachable(self, fwords, ifrom, dist): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_frontier)); + __pyx_r = ((PyObject *)__pyx_v_frontier); + 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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.get_all_nodes_isteps_away", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_frontier); + __Pyx_XDECREF(__pyx_v_key); + __Pyx_XDECREF(__pyx_v_reachable); + __Pyx_XDECREF(__pyx_v_nextreachable); + __Pyx_XDECREF(__pyx_v_next_id); + __Pyx_XDECREF(__pyx_v_jump); + __Pyx_XDECREF(__pyx_v_alt_id); + __Pyx_XDECREF(__pyx_v_newel); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_17reachable(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_17reachable(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_fwords = 0; + PyObject *__pyx_v_ifrom = 0; + PyObject *__pyx_v_dist = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fwords,&__pyx_n_s__ifrom,&__pyx_n_s__dist,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("reachable (wrapper)", 0); + { + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fwords); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ifrom); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("reachable", 1, 3, 3, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dist); + if (likely(values[2])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("reachable", 1, 3, 3, 2); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "reachable") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_fwords = values[0]; + __pyx_v_ifrom = values[1]; + __pyx_v_dist = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("reachable", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.reachable", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_16reachable(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_fwords, __pyx_v_ifrom, __pyx_v_dist); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":866 + * return frontier + * + * def reachable(self, fwords, ifrom, dist): # <<<<<<<<<<<<<< + * ret = [] + * if (ifrom >= len(fwords)): + */ + +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_16reachable(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_ifrom, PyObject *__pyx_v_dist) { + PyObject *__pyx_v_ret = NULL; + PyObject *__pyx_v_alt_id = NULL; + PyObject *__pyx_v_ifromchild = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + Py_ssize_t __pyx_t_10; + PyObject *(*__pyx_t_11)(PyObject *); + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("reachable", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":867 + * + * def reachable(self, fwords, ifrom, dist): + * ret = [] # <<<<<<<<<<<<<< + * if (ifrom >= len(fwords)): + * return ret + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_ret = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":868 + * def reachable(self, fwords, ifrom, dist): + * ret = [] + * if (ifrom >= len(fwords)): # <<<<<<<<<<<<<< + * return ret + * for alt_id in range(len(fwords[ifrom])): + */ + __pyx_t_2 = PyObject_Length(__pyx_v_fwords); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_ifrom, __pyx_t_1, Py_GE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":869 + * ret = [] + * if (ifrom >= len(fwords)): + * return ret # <<<<<<<<<<<<<< + * for alt_id in range(len(fwords[ifrom])): + * if (fwords[ifrom][alt_id][0] == EPSILON): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_ret)); + __pyx_r = ((PyObject *)__pyx_v_ret); + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":870 + * if (ifrom >= len(fwords)): + * return ret + * for alt_id in range(len(fwords[ifrom])): # <<<<<<<<<<<<<< + * if (fwords[ifrom][alt_id][0] == EPSILON): + * ret.extend(self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist)) + */ + __pyx_t_3 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ifrom); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; + } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; + } else { + __pyx_t_3 = __pyx_t_5(__pyx_t_1); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_alt_id); + __pyx_v_alt_id = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":871 + * return ret + * for alt_id in range(len(fwords[ifrom])): + * if (fwords[ifrom][alt_id][0] == EPSILON): # <<<<<<<<<<<<<< + * ret.extend(self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist)) + * else: + */ + __pyx_t_3 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ifrom); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PyObject_GetItem(__pyx_t_3, __pyx_v_alt_id); if (!__pyx_t_6) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_6, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = PyInt_FromLong(__pyx_v_8_cdec_sa_EPSILON); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PyObject_RichCompare(__pyx_t_3, __pyx_t_6, Py_EQ); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":872 + * for alt_id in range(len(fwords[ifrom])): + * if (fwords[ifrom][alt_id][0] == EPSILON): + * ret.extend(self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist)) # <<<<<<<<<<<<<< + * else: + * if (dist==0): + */ + __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_ret), __pyx_n_s__extend); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__reachable); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ifrom); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = PyObject_GetItem(__pyx_t_3, __pyx_v_alt_id); if (!__pyx_t_8) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_8, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = PyNumber_Add(__pyx_v_ifrom, __pyx_t_3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_fwords); + __Pyx_GIVEREF(__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __Pyx_INCREF(__pyx_v_dist); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_dist); + __Pyx_GIVEREF(__pyx_v_dist); + __pyx_t_8 = 0; + __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":874 + * ret.extend(self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist)) + * else: + * if (dist==0): # <<<<<<<<<<<<<< + * if (ifrom not in ret): + * ret.append(ifrom) + */ + __pyx_t_8 = PyObject_RichCompare(__pyx_v_dist, __pyx_int_0, Py_EQ); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":875 + * else: + * if (dist==0): + * if (ifrom not in ret): # <<<<<<<<<<<<<< + * ret.append(ifrom) + * else: + */ + __pyx_t_4 = (__Pyx_NegateNonNeg(PySequence_Contains(((PyObject *)__pyx_v_ret), __pyx_v_ifrom))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":876 + * if (dist==0): + * if (ifrom not in ret): + * ret.append(ifrom) # <<<<<<<<<<<<<< + * else: + * for ifromchild in self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist-1): + */ + __pyx_t_9 = PyList_Append(__pyx_v_ret, __pyx_v_ifrom); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 876; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L8; + } + __pyx_L8:; + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":878 + * ret.append(ifrom) + * else: + * for ifromchild in self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist-1): # <<<<<<<<<<<<<< + * if (ifromchild not in ret): + * ret.append(ifromchild) + */ + __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__reachable); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ifrom); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = PyObject_GetItem(__pyx_t_3, __pyx_v_alt_id); if (!__pyx_t_7) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_7, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = PyNumber_Add(__pyx_v_ifrom, __pyx_t_3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Subtract(__pyx_v_dist, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_fwords); + __Pyx_GIVEREF(__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_7 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_6 = __pyx_t_3; __Pyx_INCREF(__pyx_t_6); __pyx_t_10 = 0; + __pyx_t_11 = NULL; + } else { + __pyx_t_10 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_11 = Py_TYPE(__pyx_t_6)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_6)) { + if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_6)) break; + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_10); __Pyx_INCREF(__pyx_t_3); __pyx_t_10++; + } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_6)) { + if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_6)) break; + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_10); __Pyx_INCREF(__pyx_t_3); __pyx_t_10++; + } else { + __pyx_t_3 = __pyx_t_11(__pyx_t_6); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_ifromchild); + __pyx_v_ifromchild = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":879 + * else: + * for ifromchild in self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist-1): + * if (ifromchild not in ret): # <<<<<<<<<<<<<< + * ret.append(ifromchild) + * + */ + __pyx_t_4 = (__Pyx_NegateNonNeg(PySequence_Contains(((PyObject *)__pyx_v_ret), __pyx_v_ifromchild))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 879; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":880 + * for ifromchild in self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist-1): + * if (ifromchild not in ret): + * ret.append(ifromchild) # <<<<<<<<<<<<<< + * + * return ret + */ + __pyx_t_9 = PyList_Append(__pyx_v_ret, __pyx_v_ifromchild); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 880; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L11; + } + __pyx_L11:; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __pyx_L7:; + } + __pyx_L6:; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":882 + * ret.append(ifromchild) + * + * return ret # <<<<<<<<<<<<<< + * + * def shortest(self, fwords, ifrom, ito): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_ret)); + __pyx_r = ((PyObject *)__pyx_v_ret); + 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_3); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.reachable", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_ret); + __Pyx_XDECREF(__pyx_v_alt_id); + __Pyx_XDECREF(__pyx_v_ifromchild); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_19shortest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_19shortest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_fwords = 0; + PyObject *__pyx_v_ifrom = 0; + PyObject *__pyx_v_ito = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fwords,&__pyx_n_s__ifrom,&__pyx_n_s__ito,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("shortest (wrapper)", 0); + { + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fwords); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ifrom); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("shortest", 1, 3, 3, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ito); + if (likely(values[2])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("shortest", 1, 3, 3, 2); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "shortest") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_fwords = values[0]; + __pyx_v_ifrom = values[1]; + __pyx_v_ito = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("shortest", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.shortest", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_18shortest(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_fwords, __pyx_v_ifrom, __pyx_v_ito); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":884 + * return ret + * + * def shortest(self, fwords, ifrom, ito): # <<<<<<<<<<<<<< + * cdef unsigned alt_id + * min = 1000 + */ + +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_18shortest(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_ifrom, PyObject *__pyx_v_ito) { + unsigned int __pyx_v_alt_id; + PyObject *__pyx_v_min = NULL; + PyObject *__pyx_v_currmin = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + Py_ssize_t __pyx_t_3; + unsigned int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("shortest", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":886 + * def shortest(self, fwords, ifrom, ito): + * cdef unsigned alt_id + * min = 1000 # <<<<<<<<<<<<<< + * if (ifrom > ito): + * return min + */ + __Pyx_INCREF(__pyx_int_1000); + __pyx_v_min = __pyx_int_1000; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":887 + * cdef unsigned alt_id + * min = 1000 + * if (ifrom > ito): # <<<<<<<<<<<<<< + * return min + * if (ifrom == ito): + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_v_ifrom, __pyx_v_ito, Py_GT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":888 + * min = 1000 + * if (ifrom > ito): + * return min # <<<<<<<<<<<<<< + * if (ifrom == ito): + * return 0 + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_min); + __pyx_r = __pyx_v_min; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":889 + * if (ifrom > ito): + * return min + * if (ifrom == ito): # <<<<<<<<<<<<<< + * return 0 + * for alt_id in range(len(fwords[ifrom])): + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_v_ifrom, __pyx_v_ito, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":890 + * return min + * if (ifrom == ito): + * return 0 # <<<<<<<<<<<<<< + * for alt_id in range(len(fwords[ifrom])): + * currmin = self.shortest(fwords,ifrom+fwords[ifrom][alt_id][2],ito) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_int_0); + __pyx_r = __pyx_int_0; + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":891 + * if (ifrom == ito): + * return 0 + * for alt_id in range(len(fwords[ifrom])): # <<<<<<<<<<<<<< + * currmin = self.shortest(fwords,ifrom+fwords[ifrom][alt_id][2],ito) + * if (fwords[ifrom][alt_id][0] != EPSILON): + */ + __pyx_t_1 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ifrom); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 891; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 891; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_alt_id = __pyx_t_4; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":892 + * return 0 + * for alt_id in range(len(fwords[ifrom])): + * currmin = self.shortest(fwords,ifrom+fwords[ifrom][alt_id][2],ito) # <<<<<<<<<<<<<< + * if (fwords[ifrom][alt_id][0] != EPSILON): + * currmin += 1 + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__shortest); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ifrom); if (!__pyx_t_5) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_5, __pyx_v_alt_id, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_6) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_6, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = PyNumber_Add(__pyx_v_ifrom, __pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_fwords); + __Pyx_GIVEREF(__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + __Pyx_INCREF(__pyx_v_ito); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_ito); + __Pyx_GIVEREF(__pyx_v_ito); + __pyx_t_6 = 0; + __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_v_currmin); + __pyx_v_currmin = __pyx_t_6; + __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":893 + * for alt_id in range(len(fwords[ifrom])): + * currmin = self.shortest(fwords,ifrom+fwords[ifrom][alt_id][2],ito) + * if (fwords[ifrom][alt_id][0] != EPSILON): # <<<<<<<<<<<<<< + * currmin += 1 + * if (currmin 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__min_dist); + if (value) { values[2] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_next_states") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 899; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v__columns = values[0]; + __pyx_v_curr_idx = values[1]; + __pyx_v_min_dist = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("get_next_states", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 899; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.get_next_states", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_20get_next_states(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v__columns, __pyx_v_curr_idx, __pyx_v_min_dist); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":899 + * return min + * + * def get_next_states(self, _columns, curr_idx, min_dist=2): # <<<<<<<<<<<<<< + * result = [] + * candidate = [[curr_idx,0]] + */ + +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_20get_next_states(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v__columns, PyObject *__pyx_v_curr_idx, PyObject *__pyx_v_min_dist) { + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_v_candidate = NULL; + PyObject *__pyx_v_curr = NULL; + PyObject *__pyx_v_curr_col = NULL; + PyObject *__pyx_v_alt = NULL; + PyObject *__pyx_v_next_id = NULL; + PyObject *__pyx_v_jump = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_next_states", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":900 + * + * def get_next_states(self, _columns, curr_idx, min_dist=2): + * result = [] # <<<<<<<<<<<<<< + * candidate = [[curr_idx,0]] + * + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 900; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":901 + * def get_next_states(self, _columns, curr_idx, min_dist=2): + * result = [] + * candidate = [[curr_idx,0]] # <<<<<<<<<<<<<< + * + * while len(candidate) > 0: + */ + __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 901; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_curr_idx); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_curr_idx); + __Pyx_GIVEREF(__pyx_v_curr_idx); + __Pyx_INCREF(__pyx_int_0); + PyList_SET_ITEM(__pyx_t_1, 1, __pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 901; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_v_candidate = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":903 + * candidate = [[curr_idx,0]] + * + * while len(candidate) > 0: # <<<<<<<<<<<<<< + * curr = candidate.pop() + * if curr[0] >= len(_columns): + */ + while (1) { + __pyx_t_3 = PyList_GET_SIZE(((PyObject *)__pyx_v_candidate)); + __pyx_t_4 = (__pyx_t_3 > 0); + if (!__pyx_t_4) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":904 + * + * while len(candidate) > 0: + * curr = candidate.pop() # <<<<<<<<<<<<<< + * if curr[0] >= len(_columns): + * continue + */ + __pyx_t_2 = __Pyx_PyObject_Pop(((PyObject *)__pyx_v_candidate)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 904; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_v_curr); + __pyx_v_curr = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":905 + * while len(candidate) > 0: + * curr = candidate.pop() + * if curr[0] >= len(_columns): # <<<<<<<<<<<<<< + * continue + * if curr[0] not in result and min_dist <= curr[1] <= self.max_initial_size: + */ + __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_curr, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 905; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyObject_Length(__pyx_v__columns); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 905; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 905; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyObject_RichCompare(__pyx_t_2, __pyx_t_1, Py_GE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 905; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 905; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":906 + * curr = candidate.pop() + * if curr[0] >= len(_columns): + * continue # <<<<<<<<<<<<<< + * if curr[0] not in result and min_dist <= curr[1] <= self.max_initial_size: + * result.append(curr[0]); + */ + goto __pyx_L3_continue; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":907 + * if curr[0] >= len(_columns): + * continue + * if curr[0] not in result and min_dist <= curr[1] <= self.max_initial_size: # <<<<<<<<<<<<<< + * result.append(curr[0]); + * curr_col = _columns[curr[0]] + */ + __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_curr, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = (__Pyx_NegateNonNeg(PySequence_Contains(((PyObject *)__pyx_v_result), __pyx_t_5))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_4) { + __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_curr, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyObject_RichCompare(__pyx_v_min_dist, __pyx_t_5, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_PyObject_IsTrue(__pyx_t_1)) { + __Pyx_DECREF(__pyx_t_1); + __pyx_t_2 = PyInt_FromLong(__pyx_v_self->max_initial_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_RichCompare(__pyx_t_5, __pyx_t_2, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_7 = __pyx_t_6; + } else { + __pyx_t_7 = __pyx_t_4; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":908 + * continue + * if curr[0] not in result and min_dist <= curr[1] <= self.max_initial_size: + * result.append(curr[0]); # <<<<<<<<<<<<<< + * curr_col = _columns[curr[0]] + * for alt in curr_col: + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_curr, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 908; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = PyList_Append(__pyx_v_result, __pyx_t_1); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 908; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":909 + * if curr[0] not in result and min_dist <= curr[1] <= self.max_initial_size: + * result.append(curr[0]); + * curr_col = _columns[curr[0]] # <<<<<<<<<<<<<< + * for alt in curr_col: + * next_id = curr[0]+alt[2] + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_curr, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 909; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyObject_GetItem(__pyx_v__columns, __pyx_t_1); if (!__pyx_t_5) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 909; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_v_curr_col); + __pyx_v_curr_col = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":910 + * result.append(curr[0]); + * curr_col = _columns[curr[0]] + * for alt in curr_col: # <<<<<<<<<<<<<< + * next_id = curr[0]+alt[2] + * jump = 1 + */ + if (PyList_CheckExact(__pyx_v_curr_col) || PyTuple_CheckExact(__pyx_v_curr_col)) { + __pyx_t_5 = __pyx_v_curr_col; __Pyx_INCREF(__pyx_t_5); __pyx_t_3 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_curr_col); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 910; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_9 = Py_TYPE(__pyx_t_5)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_5)) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_5)) break; + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_5)) { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_5)) break; + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; + } else { + __pyx_t_1 = __pyx_t_9(__pyx_t_5); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 910; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF(__pyx_v_alt); + __pyx_v_alt = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":911 + * curr_col = _columns[curr[0]] + * for alt in curr_col: + * next_id = curr[0]+alt[2] # <<<<<<<<<<<<<< + * jump = 1 + * if (alt[0] == EPSILON): + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_curr, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 911; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_alt, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 911; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = PyNumber_Add(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 911; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_v_next_id); + __pyx_v_next_id = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":912 + * for alt in curr_col: + * next_id = curr[0]+alt[2] + * jump = 1 # <<<<<<<<<<<<<< + * if (alt[0] == EPSILON): + * jump = 0 + */ + __Pyx_INCREF(__pyx_int_1); + __Pyx_XDECREF(__pyx_v_jump); + __pyx_v_jump = __pyx_int_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":913 + * next_id = curr[0]+alt[2] + * jump = 1 + * if (alt[0] == EPSILON): # <<<<<<<<<<<<<< + * jump = 0 + * if next_id not in result and min_dist <= curr[1]+jump <= self.max_initial_size+1: + */ + __pyx_t_10 = __Pyx_GetItemInt(__pyx_v_alt, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 913; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = PyInt_FromLong(__pyx_v_8_cdec_sa_EPSILON); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 913; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_RichCompare(__pyx_t_10, __pyx_t_2, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 913; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 913; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":914 + * jump = 1 + * if (alt[0] == EPSILON): + * jump = 0 # <<<<<<<<<<<<<< + * if next_id not in result and min_dist <= curr[1]+jump <= self.max_initial_size+1: + * candidate.append([next_id,curr[1]+jump]) + */ + __Pyx_INCREF(__pyx_int_0); + __Pyx_DECREF(__pyx_v_jump); + __pyx_v_jump = __pyx_int_0; + goto __pyx_L9; + } + __pyx_L9:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":915 + * if (alt[0] == EPSILON): + * jump = 0 + * if next_id not in result and min_dist <= curr[1]+jump <= self.max_initial_size+1: # <<<<<<<<<<<<<< + * candidate.append([next_id,curr[1]+jump]) + * return sorted(result); + */ + __pyx_t_7 = (__Pyx_NegateNonNeg(PySequence_Contains(((PyObject *)__pyx_v_result), __pyx_v_next_id))); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_7) { + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_curr, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_v_jump); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_RichCompare(__pyx_v_min_dist, __pyx_t_2, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_PyObject_IsTrue(__pyx_t_1)) { + __Pyx_DECREF(__pyx_t_1); + __pyx_t_10 = PyInt_FromLong((__pyx_v_self->max_initial_size + 1)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_t_10, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_6 = __pyx_t_4; + } else { + __pyx_t_6 = __pyx_t_7; + } + if (__pyx_t_6) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":916 + * jump = 0 + * if next_id not in result and min_dist <= curr[1]+jump <= self.max_initial_size+1: + * candidate.append([next_id,curr[1]+jump]) # <<<<<<<<<<<<<< + * return sorted(result); + * + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_curr, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 916; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_v_jump); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 916; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 916; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_next_id); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_next_id); + __Pyx_GIVEREF(__pyx_v_next_id); + PyList_SET_ITEM(__pyx_t_1, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_8 = PyList_Append(__pyx_v_candidate, ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 916; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + goto __pyx_L10; + } + __pyx_L10:; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_L3_continue:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":917 + * if next_id not in result and min_dist <= curr[1]+jump <= self.max_initial_size+1: + * candidate.append([next_id,curr[1]+jump]) + * return sorted(result); # <<<<<<<<<<<<<< + * + * def input(self, fwords, models): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 917; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_result)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_result)); + __pyx_t_1 = PyObject_Call(__pyx_builtin_sorted, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 917; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 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_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.get_next_states", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_candidate); + __Pyx_XDECREF(__pyx_v_curr); + __Pyx_XDECREF(__pyx_v_curr_col); + __Pyx_XDECREF(__pyx_v_alt); + __Pyx_XDECREF(__pyx_v_next_id); + __Pyx_XDECREF(__pyx_v_jump); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_8_cdec_sa_23HieroCachingRuleFactory_24generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_23input(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_8_cdec_sa_23HieroCachingRuleFactory_22input[] = "When this function is called on the RuleFactory,\n it looks up all of the rules that can be used to translate\n the input sentence"; +static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_23input(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_fwords = 0; + PyObject *__pyx_v_models = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fwords,&__pyx_n_s__models,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("input (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fwords); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__models); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("input", 1, 2, 2, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "input") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_fwords = values[0]; + __pyx_v_models = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("input", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.input", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_22input(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_fwords, __pyx_v_models); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":919 + * return sorted(result); + * + * def input(self, fwords, models): # <<<<<<<<<<<<<< + * '''When this function is called on the RuleFactory, + * it looks up all of the rules that can be used to translate + */ + +static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_22input(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_models) { + struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("input", 0); + __pyx_cur_scope = (struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *)__pyx_ptype_8_cdec_sa___pyx_scope_struct_1_input->tp_new(__pyx_ptype_8_cdec_sa___pyx_scope_struct_1_input, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __pyx_cur_scope->__pyx_v_fwords = __pyx_v_fwords; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fwords); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_fwords); + __pyx_cur_scope->__pyx_v_models = __pyx_v_models; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_models); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_models); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_8_cdec_sa_23HieroCachingRuleFactory_24generator1, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.input", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_8_cdec_sa_23HieroCachingRuleFactory_24generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *__pyx_cur_scope = ((struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + Py_ssize_t __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + PyObject *__pyx_t_16 = NULL; + PyObject *(*__pyx_t_17)(PyObject *); + int __pyx_t_18; + int __pyx_t_19; + float __pyx_t_20; + Py_ssize_t __pyx_t_21; + PyObject *__pyx_t_22 = NULL; + PyObject *__pyx_t_23 = NULL; + Py_ssize_t __pyx_t_24; + PyObject *(*__pyx_t_25)(PyObject *); + Py_ssize_t __pyx_t_26; + PyObject *(*__pyx_t_27)(PyObject *); + int __pyx_t_28; + int __pyx_t_29; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L63_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[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":930 + * cdef Phrase hiero_phrase + * + * flen = len(fwords) # <<<<<<<<<<<<<< + * start_time = monitor_cpu() + * self.extract_time = 0.0 + */ + __pyx_t_1 = PyObject_Length(__pyx_cur_scope->__pyx_v_fwords); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 930; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_flen = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":931 + * + * flen = len(fwords) + * start_time = monitor_cpu() # <<<<<<<<<<<<<< + * self.extract_time = 0.0 + * nodes_isteps_away_buffer = {} + */ + __pyx_cur_scope->__pyx_v_start_time = __pyx_f_8_cdec_sa_monitor_cpu(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":932 + * flen = len(fwords) + * start_time = monitor_cpu() + * self.extract_time = 0.0 # <<<<<<<<<<<<<< + * nodes_isteps_away_buffer = {} + * hit = 0 + */ + __pyx_cur_scope->__pyx_v_self->extract_time = 0.0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":933 + * start_time = monitor_cpu() + * self.extract_time = 0.0 + * nodes_isteps_away_buffer = {} # <<<<<<<<<<<<<< + * hit = 0 + * reachable_buffer = {} + */ + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 933; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_cur_scope->__pyx_v_nodes_isteps_away_buffer = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":934 + * self.extract_time = 0.0 + * nodes_isteps_away_buffer = {} + * hit = 0 # <<<<<<<<<<<<<< + * reachable_buffer = {} + * + */ + __pyx_cur_scope->__pyx_v_hit = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":935 + * nodes_isteps_away_buffer = {} + * hit = 0 + * reachable_buffer = {} # <<<<<<<<<<<<<< + * + * # Do not cache between sentences + */ + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 935; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_cur_scope->__pyx_v_reachable_buffer = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":938 + * + * # Do not cache between sentences + * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) # <<<<<<<<<<<<<< + * + * frontier = [] + */ + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_PhraseLocation)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__phrase_location), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->rules->root); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->rules->root); + __pyx_cur_scope->__pyx_v_self->rules->root = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":940 + * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) + * + * frontier = [] # <<<<<<<<<<<<<< + * for i in range(len(fwords)): + * for alt in range(0, len(fwords[i])): + */ + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 940; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_cur_scope->__pyx_v_frontier = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":941 + * + * frontier = [] + * for i in range(len(fwords)): # <<<<<<<<<<<<<< + * for alt in range(0, len(fwords[i])): + * if fwords[i][alt][0] != EPSILON: + */ + __pyx_t_1 = PyObject_Length(__pyx_cur_scope->__pyx_v_fwords); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_1; __pyx_t_4+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_4; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":942 + * frontier = [] + * for i in range(len(fwords)): + * for alt in range(0, len(fwords[i])): # <<<<<<<<<<<<<< + * if fwords[i][alt][0] != EPSILON: + * frontier.append((i, i, alt, 0, self.rules.root, (), False)) + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_fwords, __pyx_cur_scope->__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 942; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 942; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_cur_scope->__pyx_v_alt = __pyx_t_6; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":943 + * for i in range(len(fwords)): + * for alt in range(0, len(fwords[i])): + * if fwords[i][alt][0] != EPSILON: # <<<<<<<<<<<<<< + * frontier.append((i, i, alt, 0, self.rules.root, (), False)) + * + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_fwords, __pyx_cur_scope->__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_3, __pyx_cur_scope->__pyx_v_alt, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyInt_FromLong(__pyx_v_8_cdec_sa_EPSILON); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_NE); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":944 + * for alt in range(0, len(fwords[i])): + * if fwords[i][alt][0] != EPSILON: + * frontier.append((i, i, alt, 0, self.rules.root, (), False)) # <<<<<<<<<<<<<< + * + * xroot = None + */ + __pyx_t_7 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_2 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_alt); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_9 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyTuple_New(7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_INCREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_self->rules->root); + PyTuple_SET_ITEM(__pyx_t_10, 4, __pyx_cur_scope->__pyx_v_self->rules->root); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_self->rules->root); + __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); + PyTuple_SET_ITEM(__pyx_t_10, 5, ((PyObject *)__pyx_empty_tuple)); + __Pyx_GIVEREF(((PyObject *)__pyx_empty_tuple)); + PyTuple_SET_ITEM(__pyx_t_10, 6, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_t_7 = 0; + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_9 = 0; + __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_frontier, ((PyObject *)__pyx_t_10)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + goto __pyx_L8; + } + __pyx_L8:; + } + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":946 + * frontier.append((i, i, alt, 0, self.rules.root, (), False)) + * + * xroot = None # <<<<<<<<<<<<<< + * x1 = sym_setindex(self.category, 1) + * if x1 in self.rules.root.children: + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __pyx_cur_scope->__pyx_v_xroot = Py_None; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":947 + * + * xroot = None + * x1 = sym_setindex(self.category, 1) # <<<<<<<<<<<<<< + * if x1 in self.rules.root.children: + * xroot = self.rules.root.children[x1] + */ + __pyx_cur_scope->__pyx_v_x1 = __pyx_f_8_cdec_sa_sym_setindex(__pyx_cur_scope->__pyx_v_self->category, 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":948 + * xroot = None + * x1 = sym_setindex(self.category, 1) + * if x1 in self.rules.root.children: # <<<<<<<<<<<<<< + * xroot = self.rules.root.children[x1] + * else: + */ + __pyx_t_10 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_x1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_self->rules->root, __pyx_n_s__children); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = ((PySequence_Contains(__pyx_t_9, __pyx_t_10))); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":949 + * x1 = sym_setindex(self.category, 1) + * if x1 in self.rules.root.children: + * xroot = self.rules.root.children[x1] # <<<<<<<<<<<<<< + * else: + * xroot = ExtendedTrieNode(suffix_link=self.rules.root, phrase_location=PhraseLocation()) + */ + __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_self->rules->root, __pyx_n_s__children); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 949; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = __Pyx_GetItemInt(__pyx_t_9, __pyx_cur_scope->__pyx_v_x1, sizeof(int), PyInt_FromLong); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 949; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_xroot); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_xroot); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_xroot = __pyx_t_10; + __pyx_t_10 = 0; + goto __pyx_L9; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":951 + * xroot = self.rules.root.children[x1] + * else: + * xroot = ExtendedTrieNode(suffix_link=self.rules.root, phrase_location=PhraseLocation()) # <<<<<<<<<<<<<< + * self.rules.root.children[x1] = xroot + * + */ + __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_10)); + if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__suffix_link), __pyx_cur_scope->__pyx_v_self->rules->root) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_PhraseLocation)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__phrase_location), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_xroot); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_xroot); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_v_xroot = __pyx_t_9; + __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":952 + * else: + * xroot = ExtendedTrieNode(suffix_link=self.rules.root, phrase_location=PhraseLocation()) + * self.rules.root.children[x1] = xroot # <<<<<<<<<<<<<< + * + * for i in range(self.min_gap_size, len(fwords)): + */ + __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_self->rules->root, __pyx_n_s__children); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 952; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + if (__Pyx_SetItemInt(__pyx_t_9, __pyx_cur_scope->__pyx_v_x1, __pyx_cur_scope->__pyx_v_xroot, sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 952; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __pyx_L9:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":954 + * self.rules.root.children[x1] = xroot + * + * for i in range(self.min_gap_size, len(fwords)): # <<<<<<<<<<<<<< + * for alt in range(0, len(fwords[i])): + * if fwords[i][alt][0] != EPSILON: + */ + __pyx_t_1 = PyObject_Length(__pyx_cur_scope->__pyx_v_fwords); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_4 = __pyx_cur_scope->__pyx_v_self->min_gap_size; __pyx_t_4 < __pyx_t_1; __pyx_t_4+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_4; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":955 + * + * for i in range(self.min_gap_size, len(fwords)): + * for alt in range(0, len(fwords[i])): # <<<<<<<<<<<<<< + * if fwords[i][alt][0] != EPSILON: + * frontier.append((i-self.min_gap_size, i, alt, self.min_gap_size, xroot, (x1,), True)) + */ + __pyx_t_9 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_fwords, __pyx_cur_scope->__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 955; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_5 = PyObject_Length(__pyx_t_9); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 955; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_cur_scope->__pyx_v_alt = __pyx_t_6; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":956 + * for i in range(self.min_gap_size, len(fwords)): + * for alt in range(0, len(fwords[i])): + * if fwords[i][alt][0] != EPSILON: # <<<<<<<<<<<<<< + * frontier.append((i-self.min_gap_size, i, alt, self.min_gap_size, xroot, (x1,), True)) + * + */ + __pyx_t_9 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_fwords, __pyx_cur_scope->__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = __Pyx_GetItemInt(__pyx_t_9, __pyx_cur_scope->__pyx_v_alt, sizeof(int), PyInt_FromLong); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_GetItemInt(__pyx_t_10, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = PyInt_FromLong(__pyx_v_8_cdec_sa_EPSILON); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_3 = PyObject_RichCompare(__pyx_t_9, __pyx_t_10, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":957 + * for alt in range(0, len(fwords[i])): + * if fwords[i][alt][0] != EPSILON: + * frontier.append((i-self.min_gap_size, i, alt, self.min_gap_size, xroot, (x1,), True)) # <<<<<<<<<<<<<< + * + * next_states = [] + */ + __pyx_t_3 = PyInt_FromLong((__pyx_cur_scope->__pyx_v_i - __pyx_cur_scope->__pyx_v_self->min_gap_size)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_alt); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_2 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->min_gap_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_x1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_13 = PyTuple_New(7); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_xroot); + PyTuple_SET_ITEM(__pyx_t_13, 4, __pyx_cur_scope->__pyx_v_xroot); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_xroot); + PyTuple_SET_ITEM(__pyx_t_13, 5, ((PyObject *)__pyx_t_12)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_12)); + PyTuple_SET_ITEM(__pyx_t_13, 6, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + __pyx_t_3 = 0; + __pyx_t_10 = 0; + __pyx_t_9 = 0; + __pyx_t_2 = 0; + __pyx_t_12 = 0; + __pyx_t_7 = 0; + __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_frontier, ((PyObject *)__pyx_t_13)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + goto __pyx_L14; + } + __pyx_L14:; + } + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":959 + * frontier.append((i-self.min_gap_size, i, alt, self.min_gap_size, xroot, (x1,), True)) + * + * next_states = [] # <<<<<<<<<<<<<< + * for i in range(len(fwords)): + * next_states.append(self.get_next_states(fwords,i,self.min_gap_size)) + */ + __pyx_t_13 = PyList_New(0); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 959; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_GIVEREF(((PyObject *)__pyx_t_13)); + __pyx_cur_scope->__pyx_v_next_states = __pyx_t_13; + __pyx_t_13 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":960 + * + * next_states = [] + * for i in range(len(fwords)): # <<<<<<<<<<<<<< + * next_states.append(self.get_next_states(fwords,i,self.min_gap_size)) + * + */ + __pyx_t_1 = PyObject_Length(__pyx_cur_scope->__pyx_v_fwords); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 960; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_1; __pyx_t_4+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_4; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":961 + * next_states = [] + * for i in range(len(fwords)): + * next_states.append(self.get_next_states(fwords,i,self.min_gap_size)) # <<<<<<<<<<<<<< + * + * while len(frontier) > 0: + */ + __pyx_t_13 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s__get_next_states); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_7 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->min_gap_size); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_fwords); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_12); + __Pyx_GIVEREF(__pyx_t_12); + __pyx_t_7 = 0; + __pyx_t_12 = 0; + __pyx_t_12 = PyObject_Call(__pyx_t_13, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_next_states, __pyx_t_12); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":963 + * next_states.append(self.get_next_states(fwords,i,self.min_gap_size)) + * + * while len(frontier) > 0: # <<<<<<<<<<<<<< + * new_frontier = [] + * for k, i, alt, pathlen, node, prefix, is_shadow_path in frontier: + */ + while (1) { + __pyx_t_1 = PyList_GET_SIZE(((PyObject *)__pyx_cur_scope->__pyx_v_frontier)); + __pyx_t_8 = (__pyx_t_1 > 0); + if (!__pyx_t_8) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":964 + * + * while len(frontier) > 0: + * new_frontier = [] # <<<<<<<<<<<<<< + * for k, i, alt, pathlen, node, prefix, is_shadow_path in frontier: + * word_id = fwords[i][alt][0] + */ + __pyx_t_12 = PyList_New(0); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 964; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_new_frontier)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_new_frontier)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_12)); + __pyx_cur_scope->__pyx_v_new_frontier = __pyx_t_12; + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":965 + * while len(frontier) > 0: + * new_frontier = [] + * for k, i, alt, pathlen, node, prefix, is_shadow_path in frontier: # <<<<<<<<<<<<<< + * word_id = fwords[i][alt][0] + * spanlen = fwords[i][alt][2] + */ + __pyx_t_12 = ((PyObject *)__pyx_cur_scope->__pyx_v_frontier); __Pyx_INCREF(__pyx_t_12); __pyx_t_1 = 0; + for (;;) { + if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_12)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_12, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + if (likely(PyTuple_CheckExact(sequence))) { + if (unlikely(PyTuple_GET_SIZE(sequence) != 7)) { + if (PyTuple_GET_SIZE(sequence) > 7) __Pyx_RaiseTooManyValuesError(7); + else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_13 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_9 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 3); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 4); + __pyx_t_14 = PyTuple_GET_ITEM(sequence, 5); + __pyx_t_15 = PyTuple_GET_ITEM(sequence, 6); + } else { + if (unlikely(PyList_GET_SIZE(sequence) != 7)) { + if (PyList_GET_SIZE(sequence) > 7) __Pyx_RaiseTooManyValuesError(7); + else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_13 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + __pyx_t_9 = PyList_GET_ITEM(sequence, 2); + __pyx_t_10 = PyList_GET_ITEM(sequence, 3); + __pyx_t_3 = PyList_GET_ITEM(sequence, 4); + __pyx_t_14 = PyList_GET_ITEM(sequence, 5); + __pyx_t_15 = PyList_GET_ITEM(sequence, 6); + } + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_16 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_17 = Py_TYPE(__pyx_t_16)->tp_iternext; + index = 0; __pyx_t_13 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_13)) goto __pyx_L21_unpacking_failed; + __Pyx_GOTREF(__pyx_t_13); + index = 1; __pyx_t_7 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_7)) goto __pyx_L21_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + index = 2; __pyx_t_9 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_9)) goto __pyx_L21_unpacking_failed; + __Pyx_GOTREF(__pyx_t_9); + index = 3; __pyx_t_10 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_10)) goto __pyx_L21_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + index = 4; __pyx_t_3 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_3)) goto __pyx_L21_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 5; __pyx_t_14 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_14)) goto __pyx_L21_unpacking_failed; + __Pyx_GOTREF(__pyx_t_14); + index = 6; __pyx_t_15 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_15)) goto __pyx_L21_unpacking_failed; + __Pyx_GOTREF(__pyx_t_15); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_16), 7) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + goto __pyx_L22_unpacking_done; + __pyx_L21_unpacking_failed:; + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L22_unpacking_done:; + } + __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_13); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_t_9); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_cur_scope->__pyx_v_k = __pyx_t_4; + __pyx_cur_scope->__pyx_v_i = __pyx_t_6; + __pyx_cur_scope->__pyx_v_alt = __pyx_t_18; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_pathlen); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_pathlen); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_pathlen = __pyx_t_10; + __pyx_t_10 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_node); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_node); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_node = __pyx_t_3; + __pyx_t_3 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_prefix); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_prefix); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_cur_scope->__pyx_v_prefix = __pyx_t_14; + __pyx_t_14 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_is_shadow_path); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_is_shadow_path); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_cur_scope->__pyx_v_is_shadow_path = __pyx_t_15; + __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":966 + * new_frontier = [] + * for k, i, alt, pathlen, node, prefix, is_shadow_path in frontier: + * word_id = fwords[i][alt][0] # <<<<<<<<<<<<<< + * spanlen = fwords[i][alt][2] + * # TODO get rid of k -- pathlen is replacing it + */ + __pyx_t_2 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_fwords, __pyx_cur_scope->__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 966; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = __Pyx_GetItemInt(__pyx_t_2, __pyx_cur_scope->__pyx_v_alt, sizeof(int), PyInt_FromLong); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 966; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_15, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 966; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_word_id); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_word_id); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_v_word_id = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":967 + * for k, i, alt, pathlen, node, prefix, is_shadow_path in frontier: + * word_id = fwords[i][alt][0] + * spanlen = fwords[i][alt][2] # <<<<<<<<<<<<<< + * # TODO get rid of k -- pathlen is replacing it + * if word_id == EPSILON: + */ + __pyx_t_2 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_fwords, __pyx_cur_scope->__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = __Pyx_GetItemInt(__pyx_t_2, __pyx_cur_scope->__pyx_v_alt, sizeof(int), PyInt_FromLong); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_15, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_spanlen); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_spanlen); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_v_spanlen = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":969 + * spanlen = fwords[i][alt][2] + * # TODO get rid of k -- pathlen is replacing it + * if word_id == EPSILON: # <<<<<<<<<<<<<< + * # skipping because word_id is epsilon + * if i+spanlen >= len(fwords): + */ + __pyx_t_2 = PyInt_FromLong(__pyx_v_8_cdec_sa_EPSILON); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 969; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_word_id, __pyx_t_2, Py_EQ); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 969; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 969; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":971 + * if word_id == EPSILON: + * # skipping because word_id is epsilon + * if i+spanlen >= len(fwords): # <<<<<<<<<<<<<< + * continue + * for nualt in range(0,len(fwords[i+spanlen])): + */ + __pyx_t_15 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_2 = PyNumber_Add(__pyx_t_15, __pyx_cur_scope->__pyx_v_spanlen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_5 = PyObject_Length(__pyx_cur_scope->__pyx_v_fwords); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_15 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_14 = PyObject_RichCompare(__pyx_t_2, __pyx_t_15, Py_GE); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":972 + * # skipping because word_id is epsilon + * if i+spanlen >= len(fwords): + * continue # <<<<<<<<<<<<<< + * for nualt in range(0,len(fwords[i+spanlen])): + * frontier.append((k, i+spanlen, nualt, pathlen, node, prefix, is_shadow_path)) + */ + goto __pyx_L19_continue; + goto __pyx_L24; + } + __pyx_L24:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":973 + * if i+spanlen >= len(fwords): + * continue + * for nualt in range(0,len(fwords[i+spanlen])): # <<<<<<<<<<<<<< + * frontier.append((k, i+spanlen, nualt, pathlen, node, prefix, is_shadow_path)) + * continue + */ + __pyx_t_14 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = PyNumber_Add(__pyx_t_14, __pyx_cur_scope->__pyx_v_spanlen); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = PyObject_GetItem(__pyx_cur_scope->__pyx_v_fwords, __pyx_t_15); if (!__pyx_t_14) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_5 = PyObject_Length(__pyx_t_14); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_5; __pyx_t_18+=1) { + __pyx_cur_scope->__pyx_v_nualt = __pyx_t_18; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":974 + * continue + * for nualt in range(0,len(fwords[i+spanlen])): + * frontier.append((k, i+spanlen, nualt, pathlen, node, prefix, is_shadow_path)) # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_14 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_k); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_2 = PyNumber_Add(__pyx_t_15, __pyx_cur_scope->__pyx_v_spanlen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_nualt); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = PyTuple_New(7); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_15); + __Pyx_GIVEREF(__pyx_t_15); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_pathlen); + PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_cur_scope->__pyx_v_pathlen); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_pathlen); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_node); + PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_cur_scope->__pyx_v_node); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_node); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_prefix); + PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_cur_scope->__pyx_v_prefix); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_prefix); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_is_shadow_path); + PyTuple_SET_ITEM(__pyx_t_3, 6, __pyx_cur_scope->__pyx_v_is_shadow_path); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_is_shadow_path); + __pyx_t_14 = 0; + __pyx_t_2 = 0; + __pyx_t_15 = 0; + __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_frontier, ((PyObject *)__pyx_t_3)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":975 + * for nualt in range(0,len(fwords[i+spanlen])): + * frontier.append((k, i+spanlen, nualt, pathlen, node, prefix, is_shadow_path)) + * continue # <<<<<<<<<<<<<< + * + * phrase = prefix + (word_id,) + */ + goto __pyx_L19_continue; + goto __pyx_L23; + } + __pyx_L23:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":977 + * continue + * + * phrase = prefix + (word_id,) # <<<<<<<<<<<<<< + * str_phrase = map(sym_tostring, phrase) + * hiero_phrase = Phrase(phrase) + */ + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_word_id); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_cur_scope->__pyx_v_word_id); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_word_id); + __pyx_t_15 = PyNumber_Add(__pyx_cur_scope->__pyx_v_prefix, ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_phrase); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_phrase); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_cur_scope->__pyx_v_phrase = __pyx_t_15; + __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":978 + * + * phrase = prefix + (word_id,) + * str_phrase = map(sym_tostring, phrase) # <<<<<<<<<<<<<< + * hiero_phrase = Phrase(phrase) + * arity = hiero_phrase.arity() + */ + __pyx_t_15 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_tostring); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_15); + __Pyx_GIVEREF(__pyx_t_15); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_phrase); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_cur_scope->__pyx_v_phrase); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_phrase); + __pyx_t_15 = 0; + __pyx_t_15 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_str_phrase); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_str_phrase); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_cur_scope->__pyx_v_str_phrase = __pyx_t_15; + __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":979 + * phrase = prefix + (word_id,) + * str_phrase = map(sym_tostring, phrase) + * hiero_phrase = Phrase(phrase) # <<<<<<<<<<<<<< + * arity = hiero_phrase.arity() + * + */ + __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 979; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_phrase); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_cur_scope->__pyx_v_phrase); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_phrase); + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 979; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_hiero_phrase)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_hiero_phrase)); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_hiero_phrase = ((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":980 + * str_phrase = map(sym_tostring, phrase) + * hiero_phrase = Phrase(phrase) + * arity = hiero_phrase.arity() # <<<<<<<<<<<<<< + * + * lookup_required = False + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_hiero_phrase), __pyx_n_s__arity); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 980; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_15 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 980; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_t_15); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 980; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_cur_scope->__pyx_v_arity = __pyx_t_18; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":982 + * arity = hiero_phrase.arity() + * + * lookup_required = False # <<<<<<<<<<<<<< + * if word_id in node.children: + * if node.children[word_id] is None: + */ + __pyx_cur_scope->__pyx_v_lookup_required = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":983 + * + * lookup_required = False + * if word_id in node.children: # <<<<<<<<<<<<<< + * if node.children[word_id] is None: + * # Path dead-ends at this node + */ + __pyx_t_15 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 983; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_8 = ((PySequence_Contains(__pyx_t_15, __pyx_cur_scope->__pyx_v_word_id))); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 983; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":984 + * lookup_required = False + * if word_id in node.children: + * if node.children[word_id] is None: # <<<<<<<<<<<<<< + * # Path dead-ends at this node + * continue + */ + __pyx_t_15 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 984; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = PyObject_GetItem(__pyx_t_15, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 984; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_8 = (__pyx_t_3 == Py_None); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":986 + * if node.children[word_id] is None: + * # Path dead-ends at this node + * continue # <<<<<<<<<<<<<< + * else: + * # Path continues at this node + */ + goto __pyx_L19_continue; + goto __pyx_L28; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":989 + * else: + * # Path continues at this node + * node = node.children[word_id] # <<<<<<<<<<<<<< + * else: + * if node.suffix_link is None: + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 989; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_15 = PyObject_GetItem(__pyx_t_3, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 989; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_node); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_node); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_cur_scope->__pyx_v_node = __pyx_t_15; + __pyx_t_15 = 0; + } + __pyx_L28:; + goto __pyx_L27; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":991 + * node = node.children[word_id] + * else: + * if node.suffix_link is None: # <<<<<<<<<<<<<< + * # Current node is root; lookup required + * lookup_required = True + */ + __pyx_t_15 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 991; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_8 = (__pyx_t_15 == Py_None); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":993 + * if node.suffix_link is None: + * # Current node is root; lookup required + * lookup_required = True # <<<<<<<<<<<<<< + * else: + * if word_id in node.suffix_link.children: + */ + __pyx_cur_scope->__pyx_v_lookup_required = 1; + goto __pyx_L29; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":995 + * lookup_required = True + * else: + * if word_id in node.suffix_link.children: # <<<<<<<<<<<<<< + * if node.suffix_link.children[word_id] is None: + * # Suffix link reports path is dead end + */ + __pyx_t_15 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_15, __pyx_n_s__children); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_8 = ((PySequence_Contains(__pyx_t_3, __pyx_cur_scope->__pyx_v_word_id))); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":996 + * else: + * if word_id in node.suffix_link.children: + * if node.suffix_link.children[word_id] is None: # <<<<<<<<<<<<<< + * # Suffix link reports path is dead end + * node.children[word_id] = None + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 996; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_15 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__children); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 996; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_GetItem(__pyx_t_15, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 996; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_8 = (__pyx_t_3 == Py_None); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":998 + * if node.suffix_link.children[word_id] is None: + * # Suffix link reports path is dead end + * node.children[word_id] = None # <<<<<<<<<<<<<< + * continue + * else: + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 998; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyObject_SetItem(__pyx_t_3, __pyx_cur_scope->__pyx_v_word_id, Py_None) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 998; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":999 + * # Suffix link reports path is dead end + * node.children[word_id] = None + * continue # <<<<<<<<<<<<<< + * else: + * # Suffix link indicates lookup is reqired + */ + goto __pyx_L19_continue; + goto __pyx_L31; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1002 + * else: + * # Suffix link indicates lookup is reqired + * lookup_required = True # <<<<<<<<<<<<<< + * else: + * #ERROR: We never get here + */ + __pyx_cur_scope->__pyx_v_lookup_required = 1; + } + __pyx_L31:; + goto __pyx_L30; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1005 + * else: + * #ERROR: We never get here + * raise Exception("Keyword trie error") # <<<<<<<<<<<<<< + * # checking whether lookup_required + * if lookup_required: + */ + __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_k_tuple_120), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L30:; + } + __pyx_L29:; + } + __pyx_L27:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1007 + * raise Exception("Keyword trie error") + * # checking whether lookup_required + * if lookup_required: # <<<<<<<<<<<<<< + * new_node = None + * if is_shadow_path: + */ + if (__pyx_cur_scope->__pyx_v_lookup_required) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1008 + * # checking whether lookup_required + * if lookup_required: + * new_node = None # <<<<<<<<<<<<<< + * if is_shadow_path: + * # Extending shadow path + */ + __Pyx_INCREF(Py_None); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_new_node); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_new_node); + __Pyx_GIVEREF(Py_None); + __pyx_cur_scope->__pyx_v_new_node = Py_None; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1009 + * if lookup_required: + * new_node = None + * if is_shadow_path: # <<<<<<<<<<<<<< + * # Extending shadow path + * # on the shadow path we don't do any search, we just use info from suffix link + */ + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_is_shadow_path); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1009; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1012 + * # Extending shadow path + * # on the shadow path we don't do any search, we just use info from suffix link + * new_node = ExtendedTrieNode(phrase_location=node.suffix_link.children[word_id].phrase_location, # <<<<<<<<<<<<<< + * suffix_link=node.suffix_link.children[word_id], + * phrase=hiero_phrase) + */ + __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_t_15 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_15, __pyx_n_s__children); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = PyObject_GetItem(__pyx_t_2, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_GetAttr(__pyx_t_15, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__phrase_location), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1013 + * # on the shadow path we don't do any search, we just use info from suffix link + * new_node = ExtendedTrieNode(phrase_location=node.suffix_link.children[word_id].phrase_location, + * suffix_link=node.suffix_link.children[word_id], # <<<<<<<<<<<<<< + * phrase=hiero_phrase) + * else: + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1013; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__children); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1013; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_GetItem(__pyx_t_15, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1013; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__suffix_link), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1014 + * new_node = ExtendedTrieNode(phrase_location=node.suffix_link.children[word_id].phrase_location, + * suffix_link=node.suffix_link.children[word_id], + * phrase=hiero_phrase) # <<<<<<<<<<<<<< + * else: + * if arity > 0: + */ + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__phrase), ((PyObject *)__pyx_cur_scope->__pyx_v_hiero_phrase)) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_new_node); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_new_node); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_v_new_node = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L33; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1016 + * phrase=hiero_phrase) + * else: + * if arity > 0: # <<<<<<<<<<<<<< + * # Intersecting because of arity > 0 + * phrase_location = self.intersect(node, node.suffix_link.children[word_id], hiero_phrase) + */ + __pyx_t_8 = (__pyx_cur_scope->__pyx_v_arity > 0); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1018 + * if arity > 0: + * # Intersecting because of arity > 0 + * phrase_location = self.intersect(node, node.suffix_link.children[word_id], hiero_phrase) # <<<<<<<<<<<<<< + * else: + * # Suffix array search + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__children); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_GetItem(__pyx_t_3, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = ((PyObject *)((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_cur_scope->__pyx_v_self->__pyx_vtab)->intersect(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_node, __pyx_t_2, __pyx_cur_scope->__pyx_v_hiero_phrase)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_phrase_location = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_t_3); + __pyx_t_3 = 0; + goto __pyx_L34; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1021 + * else: + * # Suffix array search + * phrase_location = node.phrase_location # <<<<<<<<<<<<<< + * sa_range = self.fsa.lookup(str_phrase[-1], len(str_phrase)-1, phrase_location.sa_low, phrase_location.sa_high) + * if sa_range is not None: + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_8_cdec_sa_PhraseLocation))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_phrase_location = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1022 + * # Suffix array search + * phrase_location = node.phrase_location + * sa_range = self.fsa.lookup(str_phrase[-1], len(str_phrase)-1, phrase_location.sa_low, phrase_location.sa_high) # <<<<<<<<<<<<<< + * if sa_range is not None: + * phrase_location = PhraseLocation(sa_low=sa_range[0], sa_high=sa_range[1]) + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self->fsa), __pyx_n_s__lookup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_str_phrase, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = PyObject_Length(__pyx_cur_scope->__pyx_v_str_phrase); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_15 = PyInt_FromSsize_t((__pyx_t_5 - 1)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_14 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_phrase_location->sa_low); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_10 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_phrase_location->sa_high); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyTuple_New(4); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_15); + __Pyx_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_t_2 = 0; + __pyx_t_15 = 0; + __pyx_t_14 = 0; + __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_sa_range); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_sa_range); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_sa_range = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1023 + * phrase_location = node.phrase_location + * sa_range = self.fsa.lookup(str_phrase[-1], len(str_phrase)-1, phrase_location.sa_low, phrase_location.sa_high) + * if sa_range is not None: # <<<<<<<<<<<<<< + * phrase_location = PhraseLocation(sa_low=sa_range[0], sa_high=sa_range[1]) + * else: + */ + __pyx_t_8 = (__pyx_cur_scope->__pyx_v_sa_range != Py_None); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1024 + * sa_range = self.fsa.lookup(str_phrase[-1], len(str_phrase)-1, phrase_location.sa_low, phrase_location.sa_high) + * if sa_range is not None: + * phrase_location = PhraseLocation(sa_low=sa_range[0], sa_high=sa_range[1]) # <<<<<<<<<<<<<< + * else: + * phrase_location = None + */ + __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_10)); + __pyx_t_9 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_sa_range, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__sa_low), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_sa_range, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__sa_high), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_PhraseLocation)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_GOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_v_phrase_location = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_t_9); + __pyx_t_9 = 0; + goto __pyx_L35; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1026 + * phrase_location = PhraseLocation(sa_low=sa_range[0], sa_high=sa_range[1]) + * else: + * phrase_location = None # <<<<<<<<<<<<<< + * + * if phrase_location is None: + */ + __Pyx_INCREF(Py_None); + __Pyx_GOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); + __Pyx_GIVEREF(Py_None); + __pyx_cur_scope->__pyx_v_phrase_location = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)Py_None); + } + __pyx_L35:; + } + __pyx_L34:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1028 + * phrase_location = None + * + * if phrase_location is None: # <<<<<<<<<<<<<< + * node.children[word_id] = None + * # Search failed + */ + __pyx_t_8 = (((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location) == Py_None); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1029 + * + * if phrase_location is None: + * node.children[word_id] = None # <<<<<<<<<<<<<< + * # Search failed + * continue + */ + __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1029; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + if (PyObject_SetItem(__pyx_t_9, __pyx_cur_scope->__pyx_v_word_id, Py_None) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1029; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1031 + * node.children[word_id] = None + * # Search failed + * continue # <<<<<<<<<<<<<< + * # Search succeeded + * suffix_link = self.rules.root + */ + goto __pyx_L19_continue; + goto __pyx_L36; + } + __pyx_L36:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1033 + * continue + * # Search succeeded + * suffix_link = self.rules.root # <<<<<<<<<<<<<< + * if node.suffix_link is not None: + * suffix_link = node.suffix_link.children[word_id] + */ + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_self->rules->root); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_suffix_link); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_suffix_link); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_self->rules->root); + __pyx_cur_scope->__pyx_v_suffix_link = __pyx_cur_scope->__pyx_v_self->rules->root; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1034 + * # Search succeeded + * suffix_link = self.rules.root + * if node.suffix_link is not None: # <<<<<<<<<<<<<< + * suffix_link = node.suffix_link.children[word_id] + * new_node = ExtendedTrieNode(phrase_location=phrase_location, + */ + __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1034; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = (__pyx_t_9 != Py_None); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1035 + * suffix_link = self.rules.root + * if node.suffix_link is not None: + * suffix_link = node.suffix_link.children[word_id] # <<<<<<<<<<<<<< + * new_node = ExtendedTrieNode(phrase_location=phrase_location, + * suffix_link=suffix_link, + */ + __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1035; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__children); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1035; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = PyObject_GetItem(__pyx_t_10, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1035; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_suffix_link); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_suffix_link); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_v_suffix_link = __pyx_t_9; + __pyx_t_9 = 0; + goto __pyx_L37; + } + __pyx_L37:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1036 + * if node.suffix_link is not None: + * suffix_link = node.suffix_link.children[word_id] + * new_node = ExtendedTrieNode(phrase_location=phrase_location, # <<<<<<<<<<<<<< + * suffix_link=suffix_link, + * phrase=hiero_phrase) + */ + __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__phrase_location), ((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1037 + * suffix_link = node.suffix_link.children[word_id] + * new_node = ExtendedTrieNode(phrase_location=phrase_location, + * suffix_link=suffix_link, # <<<<<<<<<<<<<< + * phrase=hiero_phrase) + * node.children[word_id] = new_node + */ + if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__suffix_link), __pyx_cur_scope->__pyx_v_suffix_link) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1038 + * new_node = ExtendedTrieNode(phrase_location=phrase_location, + * suffix_link=suffix_link, + * phrase=hiero_phrase) # <<<<<<<<<<<<<< + * node.children[word_id] = new_node + * node = new_node + */ + if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__phrase), ((PyObject *)__pyx_cur_scope->__pyx_v_hiero_phrase)) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_10 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_9)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_new_node); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_new_node); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_new_node = __pyx_t_10; + __pyx_t_10 = 0; + } + __pyx_L33:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1039 + * suffix_link=suffix_link, + * phrase=hiero_phrase) + * node.children[word_id] = new_node # <<<<<<<<<<<<<< + * node = new_node + * + */ + __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1039; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + if (PyObject_SetItem(__pyx_t_10, __pyx_cur_scope->__pyx_v_word_id, __pyx_cur_scope->__pyx_v_new_node) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1039; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1040 + * phrase=hiero_phrase) + * node.children[word_id] = new_node + * node = new_node # <<<<<<<<<<<<<< + * + * '''Automatically add a trailing X node, if allowed -- + */ + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_new_node); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_node); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_node); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_new_node); + __pyx_cur_scope->__pyx_v_node = __pyx_cur_scope->__pyx_v_new_node; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1045 + * This should happen before we get to extraction (so that + * the node will exist if needed)''' + * if arity < self.max_nonterminals: # <<<<<<<<<<<<<< + * xcat_index = arity+1 + * xcat = sym_setindex(self.category, xcat_index) + */ + __pyx_t_8 = (__pyx_cur_scope->__pyx_v_arity < __pyx_cur_scope->__pyx_v_self->max_nonterminals); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1046 + * the node will exist if needed)''' + * if arity < self.max_nonterminals: + * xcat_index = arity+1 # <<<<<<<<<<<<<< + * xcat = sym_setindex(self.category, xcat_index) + * suffix_link_xcat_index = xcat_index + */ + __pyx_t_10 = PyInt_FromLong((__pyx_cur_scope->__pyx_v_arity + 1)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_xcat_index); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_xcat_index); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_xcat_index = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1047 + * if arity < self.max_nonterminals: + * xcat_index = arity+1 + * xcat = sym_setindex(self.category, xcat_index) # <<<<<<<<<<<<<< + * suffix_link_xcat_index = xcat_index + * if is_shadow_path: + */ + __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_cur_scope->__pyx_v_xcat_index); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_xcat = __pyx_f_8_cdec_sa_sym_setindex(__pyx_cur_scope->__pyx_v_self->category, __pyx_t_18); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1048 + * xcat_index = arity+1 + * xcat = sym_setindex(self.category, xcat_index) + * suffix_link_xcat_index = xcat_index # <<<<<<<<<<<<<< + * if is_shadow_path: + * suffix_link_xcat_index = xcat_index-1 + */ + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_xcat_index); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_suffix_link_xcat_index); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_suffix_link_xcat_index); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_xcat_index); + __pyx_cur_scope->__pyx_v_suffix_link_xcat_index = __pyx_cur_scope->__pyx_v_xcat_index; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1049 + * xcat = sym_setindex(self.category, xcat_index) + * suffix_link_xcat_index = xcat_index + * if is_shadow_path: # <<<<<<<<<<<<<< + * suffix_link_xcat_index = xcat_index-1 + * suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) + */ + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_is_shadow_path); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1049; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1050 + * suffix_link_xcat_index = xcat_index + * if is_shadow_path: + * suffix_link_xcat_index = xcat_index-1 # <<<<<<<<<<<<<< + * suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) + * node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, + */ + __pyx_t_10 = PyNumber_Subtract(__pyx_cur_scope->__pyx_v_xcat_index, __pyx_int_1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1050; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_suffix_link_xcat_index); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_suffix_link_xcat_index); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_suffix_link_xcat_index = __pyx_t_10; + __pyx_t_10 = 0; + goto __pyx_L39; + } + __pyx_L39:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1051 + * if is_shadow_path: + * suffix_link_xcat_index = xcat_index-1 + * suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) # <<<<<<<<<<<<<< + * node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, + * suffix_link=node.suffix_link.children[suffix_link_xcat], + */ + __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_cur_scope->__pyx_v_suffix_link_xcat_index); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_suffix_link_xcat = __pyx_f_8_cdec_sa_sym_setindex(__pyx_cur_scope->__pyx_v_self->category, __pyx_t_18); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1052 + * suffix_link_xcat_index = xcat_index-1 + * suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) + * node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, # <<<<<<<<<<<<<< + * suffix_link=node.suffix_link.children[suffix_link_xcat], + * phrase= Phrase(phrase + (xcat,))) + */ + __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_10)); + __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__phrase_location), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1053 + * suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) + * node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, + * suffix_link=node.suffix_link.children[suffix_link_xcat], # <<<<<<<<<<<<<< + * phrase= Phrase(phrase + (xcat,))) + * + */ + __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__children); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_GetItemInt(__pyx_t_3, __pyx_cur_scope->__pyx_v_suffix_link_xcat, sizeof(int), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__suffix_link), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1054 + * node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, + * suffix_link=node.suffix_link.children[suffix_link_xcat], + * phrase= Phrase(phrase + (xcat,))) # <<<<<<<<<<<<<< + * + * # sample from range + */ + __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_xcat); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_9 = PyNumber_Add(__pyx_cur_scope->__pyx_v_phrase, ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__phrase), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1052 + * suffix_link_xcat_index = xcat_index-1 + * suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) + * node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, # <<<<<<<<<<<<<< + * suffix_link=node.suffix_link.children[suffix_link_xcat], + * phrase= Phrase(phrase + (xcat,))) + */ + __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + if (__Pyx_SetItemInt(__pyx_t_10, __pyx_cur_scope->__pyx_v_xcat, __pyx_t_9, sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L38; + } + __pyx_L38:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1057 + * + * # sample from range + * if not is_shadow_path: # <<<<<<<<<<<<<< + * sample = self.sampler.sample(node.phrase_location) + * num_subpatterns = ( node.phrase_location).num_subpatterns + */ + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_is_shadow_path); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1057; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_19 = (!__pyx_t_8); + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1058 + * # sample from range + * if not is_shadow_path: + * sample = self.sampler.sample(node.phrase_location) # <<<<<<<<<<<<<< + * num_subpatterns = ( node.phrase_location).num_subpatterns + * chunklen = IntList(initial_len=num_subpatterns) + */ + __pyx_t_9 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self->sampler), __pyx_n_s__sample); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + if (!(likely(((__pyx_t_10) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_10, __pyx_ptype_8_cdec_sa_IntList))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_sample)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_sample)); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_sample = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_10); + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1059 + * if not is_shadow_path: + * sample = self.sampler.sample(node.phrase_location) + * num_subpatterns = ( node.phrase_location).num_subpatterns # <<<<<<<<<<<<<< + * chunklen = IntList(initial_len=num_subpatterns) + * for j from 0 <= j < num_subpatterns: + */ + __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_num_subpatterns = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_t_10)->num_subpatterns; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1060 + * sample = self.sampler.sample(node.phrase_location) + * num_subpatterns = ( node.phrase_location).num_subpatterns + * chunklen = IntList(initial_len=num_subpatterns) # <<<<<<<<<<<<<< + * for j from 0 <= j < num_subpatterns: + * chunklen.arr[j] = hiero_phrase.chunklen(j) + */ + __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_10)); + __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_num_subpatterns); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_chunklen)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_chunklen)); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_chunklen = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1061 + * num_subpatterns = ( node.phrase_location).num_subpatterns + * chunklen = IntList(initial_len=num_subpatterns) + * for j from 0 <= j < num_subpatterns: # <<<<<<<<<<<<<< + * chunklen.arr[j] = hiero_phrase.chunklen(j) + * extracts = [] + */ + __pyx_t_18 = __pyx_cur_scope->__pyx_v_num_subpatterns; + for (__pyx_cur_scope->__pyx_v_j = 0; __pyx_cur_scope->__pyx_v_j < __pyx_t_18; __pyx_cur_scope->__pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1062 + * chunklen = IntList(initial_len=num_subpatterns) + * for j from 0 <= j < num_subpatterns: + * chunklen.arr[j] = hiero_phrase.chunklen(j) # <<<<<<<<<<<<<< + * extracts = [] + * j = 0 + */ + (__pyx_cur_scope->__pyx_v_chunklen->arr[__pyx_cur_scope->__pyx_v_j]) = ((struct __pyx_vtabstruct_8_cdec_sa_Phrase *)__pyx_cur_scope->__pyx_v_hiero_phrase->__pyx_vtab)->chunklen(__pyx_cur_scope->__pyx_v_hiero_phrase, __pyx_cur_scope->__pyx_v_j); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1063 + * for j from 0 <= j < num_subpatterns: + * chunklen.arr[j] = hiero_phrase.chunklen(j) + * extracts = [] # <<<<<<<<<<<<<< + * j = 0 + * extract_start = monitor_cpu() + */ + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1063; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_extracts)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_extracts)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_cur_scope->__pyx_v_extracts = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1064 + * chunklen.arr[j] = hiero_phrase.chunklen(j) + * extracts = [] + * j = 0 # <<<<<<<<<<<<<< + * extract_start = monitor_cpu() + * while j < sample.len: + */ + __pyx_cur_scope->__pyx_v_j = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1065 + * extracts = [] + * j = 0 + * extract_start = monitor_cpu() # <<<<<<<<<<<<<< + * while j < sample.len: + * extract = [] + */ + __pyx_t_3 = PyFloat_FromDouble(__pyx_f_8_cdec_sa_monitor_cpu()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_extract_start); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_extract_start); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_extract_start = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1066 + * j = 0 + * extract_start = monitor_cpu() + * while j < sample.len: # <<<<<<<<<<<<<< + * extract = [] + * + */ + while (1) { + __pyx_t_19 = (__pyx_cur_scope->__pyx_v_j < __pyx_cur_scope->__pyx_v_sample->len); + if (!__pyx_t_19) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1067 + * extract_start = monitor_cpu() + * while j < sample.len: + * extract = [] # <<<<<<<<<<<<<< + * + * assign_matching(&matching, sample.arr, j, num_subpatterns, self.fda.sent_id.arr) + */ + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1067; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_extract); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_extract); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_cur_scope->__pyx_v_extract = ((PyObject *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1069 + * extract = [] + * + * assign_matching(&matching, sample.arr, j, num_subpatterns, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * extract = self.extract(hiero_phrase, &matching, chunklen.arr, num_subpatterns) + * extracts.extend(extract) + */ + __pyx_f_8_cdec_sa_assign_matching((&__pyx_cur_scope->__pyx_v_matching), __pyx_cur_scope->__pyx_v_sample->arr, __pyx_cur_scope->__pyx_v_j, __pyx_cur_scope->__pyx_v_num_subpatterns, __pyx_cur_scope->__pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1070 + * + * assign_matching(&matching, sample.arr, j, num_subpatterns, self.fda.sent_id.arr) + * extract = self.extract(hiero_phrase, &matching, chunklen.arr, num_subpatterns) # <<<<<<<<<<<<<< + * extracts.extend(extract) + * j = j + num_subpatterns + */ + __pyx_t_3 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_cur_scope->__pyx_v_self->__pyx_vtab)->extract(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_hiero_phrase, (&__pyx_cur_scope->__pyx_v_matching), __pyx_cur_scope->__pyx_v_chunklen->arr, __pyx_cur_scope->__pyx_v_num_subpatterns); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_extract); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_extract); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_extract = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1071 + * assign_matching(&matching, sample.arr, j, num_subpatterns, self.fda.sent_id.arr) + * extract = self.extract(hiero_phrase, &matching, chunklen.arr, num_subpatterns) + * extracts.extend(extract) # <<<<<<<<<<<<<< + * j = j + num_subpatterns + * + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_extracts), __pyx_n_s__extend); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_extract); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_cur_scope->__pyx_v_extract); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_extract); + __pyx_t_9 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1072 + * extract = self.extract(hiero_phrase, &matching, chunklen.arr, num_subpatterns) + * extracts.extend(extract) + * j = j + num_subpatterns # <<<<<<<<<<<<<< + * + * num_samples = sample.len/num_subpatterns + */ + __pyx_cur_scope->__pyx_v_j = (__pyx_cur_scope->__pyx_v_j + __pyx_cur_scope->__pyx_v_num_subpatterns); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1074 + * j = j + num_subpatterns + * + * num_samples = sample.len/num_subpatterns # <<<<<<<<<<<<<< + * extract_stop = monitor_cpu() + * self.extract_time = self.extract_time + extract_stop - extract_start + */ + if (unlikely(__pyx_cur_scope->__pyx_v_num_subpatterns == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1074; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + else if (sizeof(int) == sizeof(long) && unlikely(__pyx_cur_scope->__pyx_v_num_subpatterns == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_cur_scope->__pyx_v_sample->len))) { + PyErr_Format(PyExc_OverflowError, "value too large to perform division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1074; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_cur_scope->__pyx_v_num_samples = __Pyx_div_int(__pyx_cur_scope->__pyx_v_sample->len, __pyx_cur_scope->__pyx_v_num_subpatterns); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1075 + * + * num_samples = sample.len/num_subpatterns + * extract_stop = monitor_cpu() # <<<<<<<<<<<<<< + * self.extract_time = self.extract_time + extract_stop - extract_start + * if len(extracts) > 0: + */ + __pyx_t_9 = PyFloat_FromDouble(__pyx_f_8_cdec_sa_monitor_cpu()); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_extract_stop); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_extract_stop); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_v_extract_stop = __pyx_t_9; + __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1076 + * num_samples = sample.len/num_subpatterns + * extract_stop = monitor_cpu() + * self.extract_time = self.extract_time + extract_stop - extract_start # <<<<<<<<<<<<<< + * if len(extracts) > 0: + * fphrases = {} + */ + __pyx_t_9 = PyFloat_FromDouble(__pyx_cur_scope->__pyx_v_self->extract_time); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyNumber_Add(__pyx_t_9, __pyx_cur_scope->__pyx_v_extract_stop); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = PyNumber_Subtract(__pyx_t_10, __pyx_cur_scope->__pyx_v_extract_start); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_20 = __pyx_PyFloat_AsFloat(__pyx_t_9); if (unlikely((__pyx_t_20 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_cur_scope->__pyx_v_self->extract_time = __pyx_t_20; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1077 + * extract_stop = monitor_cpu() + * self.extract_time = self.extract_time + extract_stop - extract_start + * if len(extracts) > 0: # <<<<<<<<<<<<<< + * fphrases = {} + * fals = {} + */ + __pyx_t_5 = PyList_GET_SIZE(((PyObject *)__pyx_cur_scope->__pyx_v_extracts)); + __pyx_t_19 = (__pyx_t_5 > 0); + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1078 + * self.extract_time = self.extract_time + extract_stop - extract_start + * if len(extracts) > 0: + * fphrases = {} # <<<<<<<<<<<<<< + * fals = {} + * fcount = {} + */ + __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1078; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); + __pyx_cur_scope->__pyx_v_fphrases = __pyx_t_9; + __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1079 + * if len(extracts) > 0: + * fphrases = {} + * fals = {} # <<<<<<<<<<<<<< + * fcount = {} + * for f, e, count, als in extracts: + */ + __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1079; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fals)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fals)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); + __pyx_cur_scope->__pyx_v_fals = __pyx_t_9; + __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1080 + * fphrases = {} + * fals = {} + * fcount = {} # <<<<<<<<<<<<<< + * for f, e, count, als in extracts: + * fcount.setdefault(f, 0.0) + */ + __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fcount)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fcount)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); + __pyx_cur_scope->__pyx_v_fcount = __pyx_t_9; + __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1081 + * fals = {} + * fcount = {} + * for f, e, count, als in extracts: # <<<<<<<<<<<<<< + * fcount.setdefault(f, 0.0) + * fcount[f] = fcount[f] + count + */ + __pyx_t_9 = ((PyObject *)__pyx_cur_scope->__pyx_v_extracts); __Pyx_INCREF(__pyx_t_9); __pyx_t_5 = 0; + for (;;) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_9)) break; + __pyx_t_10 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_5); __Pyx_INCREF(__pyx_t_10); __pyx_t_5++; + if ((likely(PyTuple_CheckExact(__pyx_t_10))) || (PyList_CheckExact(__pyx_t_10))) { + PyObject* sequence = __pyx_t_10; + if (likely(PyTuple_CheckExact(sequence))) { + if (unlikely(PyTuple_GET_SIZE(sequence) != 4)) { + if (PyTuple_GET_SIZE(sequence) > 4) __Pyx_RaiseTooManyValuesError(4); + else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1081; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_14 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_15 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 3); + } else { + if (unlikely(PyList_GET_SIZE(sequence) != 4)) { + if (PyList_GET_SIZE(sequence) > 4) __Pyx_RaiseTooManyValuesError(4); + else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1081; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_14 = PyList_GET_ITEM(sequence, 1); + __pyx_t_15 = PyList_GET_ITEM(sequence, 2); + __pyx_t_2 = PyList_GET_ITEM(sequence, 3); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(__pyx_t_15); + __Pyx_INCREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1081; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_17 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_17(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L48_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 1; __pyx_t_14 = __pyx_t_17(__pyx_t_7); if (unlikely(!__pyx_t_14)) goto __pyx_L48_unpacking_failed; + __Pyx_GOTREF(__pyx_t_14); + index = 2; __pyx_t_15 = __pyx_t_17(__pyx_t_7); if (unlikely(!__pyx_t_15)) goto __pyx_L48_unpacking_failed; + __Pyx_GOTREF(__pyx_t_15); + index = 3; __pyx_t_2 = __pyx_t_17(__pyx_t_7); if (unlikely(!__pyx_t_2)) goto __pyx_L48_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_7), 4) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1081; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L49_unpacking_done; + __pyx_L48_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1081; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L49_unpacking_done:; + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_f); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_f); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_f = __pyx_t_3; + __pyx_t_3 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_e); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_e); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_cur_scope->__pyx_v_e = __pyx_t_14; + __pyx_t_14 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_count); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_count); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_cur_scope->__pyx_v_count = __pyx_t_15; + __pyx_t_15 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_als); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_als); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_v_als = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1082 + * fcount = {} + * for f, e, count, als in extracts: + * fcount.setdefault(f, 0.0) # <<<<<<<<<<<<<< + * fcount[f] = fcount[f] + count + * fphrases.setdefault(f, {}) + */ + __pyx_t_10 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = __Pyx_PyDict_SetDefault(((PyObject *)__pyx_cur_scope->__pyx_v_fcount), __pyx_cur_scope->__pyx_v_f, __pyx_t_10); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1083 + * for f, e, count, als in extracts: + * fcount.setdefault(f, 0.0) + * fcount[f] = fcount[f] + count # <<<<<<<<<<<<<< + * fphrases.setdefault(f, {}) + * fphrases[f].setdefault(e, {}) + */ + __pyx_t_2 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fcount), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = PyNumber_Add(__pyx_t_2, __pyx_cur_scope->__pyx_v_count); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fcount), __pyx_cur_scope->__pyx_v_f, __pyx_t_10) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1084 + * fcount.setdefault(f, 0.0) + * fcount[f] = fcount[f] + count + * fphrases.setdefault(f, {}) # <<<<<<<<<<<<<< + * fphrases[f].setdefault(e, {}) + * fphrases[f][e].setdefault(als,0.0) + */ + __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_10)); + __pyx_t_2 = __Pyx_PyDict_SetDefault(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases), __pyx_cur_scope->__pyx_v_f, ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1085 + * fcount[f] = fcount[f] + count + * fphrases.setdefault(f, {}) + * fphrases[f].setdefault(e, {}) # <<<<<<<<<<<<<< + * fphrases[f][e].setdefault(als,0.0) + * fphrases[f][e][als] = fphrases[f][e][als] + count + */ + __pyx_t_2 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__setdefault); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_e); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_cur_scope->__pyx_v_e); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_e); + PyTuple_SET_ITEM(__pyx_t_15, 1, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1086 + * fphrases.setdefault(f, {}) + * fphrases[f].setdefault(e, {}) + * fphrases[f][e].setdefault(als,0.0) # <<<<<<<<<<<<<< + * fphrases[f][e][als] = fphrases[f][e][als] + count + * for f, elist in fphrases.iteritems(): + */ + __pyx_t_2 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = PyObject_GetItem(__pyx_t_2, __pyx_cur_scope->__pyx_v_e); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_GetAttr(__pyx_t_15, __pyx_n_s__setdefault); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_als); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_cur_scope->__pyx_v_als); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_als); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_15); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_t_15 = 0; + __pyx_t_15 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1087 + * fphrases[f].setdefault(e, {}) + * fphrases[f][e].setdefault(als,0.0) + * fphrases[f][e][als] = fphrases[f][e][als] + count # <<<<<<<<<<<<<< + * for f, elist in fphrases.iteritems(): + * f_margin = fcount[f] + */ + __pyx_t_15 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_10 = PyObject_GetItem(__pyx_t_15, __pyx_cur_scope->__pyx_v_e); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = PyObject_GetItem(__pyx_t_10, __pyx_cur_scope->__pyx_v_als); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = PyNumber_Add(__pyx_t_15, __pyx_cur_scope->__pyx_v_count); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_2 = PyObject_GetItem(__pyx_t_15, __pyx_cur_scope->__pyx_v_e); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (PyObject_SetItem(__pyx_t_2, __pyx_cur_scope->__pyx_v_als, __pyx_t_10) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1088 + * fphrases[f][e].setdefault(als,0.0) + * fphrases[f][e][als] = fphrases[f][e][als] + count + * for f, elist in fphrases.iteritems(): # <<<<<<<<<<<<<< + * f_margin = fcount[f] + * for e, alslist in elist.iteritems(): + */ + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases)); + __Pyx_XDECREF(__pyx_t_9); + __pyx_t_9 = ((PyObject *)__pyx_cur_scope->__pyx_v_fphrases); + __pyx_t_5 = 0; + __pyx_t_21 = PyDict_Size(__pyx_t_9); + while (1) { + if (unlikely(__pyx_t_21 != PyDict_Size(__pyx_t_9))) { + PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration"); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1088; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + if (!PyDict_Next(__pyx_t_9, (&__pyx_t_5), (&__pyx_t_22), (&__pyx_t_23))) break; + __Pyx_INCREF(((PyObject *)__pyx_t_22)); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_f); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_f); + __Pyx_GIVEREF(__pyx_t_22); + __pyx_cur_scope->__pyx_v_f = __pyx_t_22; + __Pyx_INCREF(((PyObject *)__pyx_t_23)); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_elist); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_elist); + __Pyx_GIVEREF(__pyx_t_23); + __pyx_cur_scope->__pyx_v_elist = __pyx_t_23; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1089 + * fphrases[f][e][als] = fphrases[f][e][als] + count + * for f, elist in fphrases.iteritems(): + * f_margin = fcount[f] # <<<<<<<<<<<<<< + * for e, alslist in elist.iteritems(): + * alignment = None + */ + __pyx_t_10 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fcount), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_f_margin); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_f_margin); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_f_margin = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1090 + * for f, elist in fphrases.iteritems(): + * f_margin = fcount[f] + * for e, alslist in elist.iteritems(): # <<<<<<<<<<<<<< + * alignment = None + * count = 0 + */ + __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_elist, __pyx_n_s__iteritems); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_10 = __pyx_t_2; __Pyx_INCREF(__pyx_t_10); __pyx_t_24 = 0; + __pyx_t_25 = NULL; + } else { + __pyx_t_24 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_25 = Py_TYPE(__pyx_t_10)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (!__pyx_t_25 && PyList_CheckExact(__pyx_t_10)) { + if (__pyx_t_24 >= PyList_GET_SIZE(__pyx_t_10)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_24); __Pyx_INCREF(__pyx_t_2); __pyx_t_24++; + } else if (!__pyx_t_25 && PyTuple_CheckExact(__pyx_t_10)) { + if (__pyx_t_24 >= PyTuple_GET_SIZE(__pyx_t_10)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_24); __Pyx_INCREF(__pyx_t_2); __pyx_t_24++; + } else { + __pyx_t_2 = __pyx_t_25(__pyx_t_10); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + if (likely(PyTuple_CheckExact(sequence))) { + 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[8]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_15 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_14 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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[8]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_15 = PyList_GET_ITEM(sequence, 0); + __pyx_t_14 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_15); + __Pyx_INCREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_17 = Py_TYPE(__pyx_t_3)->tp_iternext; + index = 0; __pyx_t_15 = __pyx_t_17(__pyx_t_3); if (unlikely(!__pyx_t_15)) goto __pyx_L54_unpacking_failed; + __Pyx_GOTREF(__pyx_t_15); + index = 1; __pyx_t_14 = __pyx_t_17(__pyx_t_3); if (unlikely(!__pyx_t_14)) goto __pyx_L54_unpacking_failed; + __Pyx_GOTREF(__pyx_t_14); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_3), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L55_unpacking_done; + __pyx_L54_unpacking_failed:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L55_unpacking_done:; + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_e); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_e); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_cur_scope->__pyx_v_e = __pyx_t_15; + __pyx_t_15 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_alslist); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_alslist); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_cur_scope->__pyx_v_alslist = __pyx_t_14; + __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1091 + * f_margin = fcount[f] + * for e, alslist in elist.iteritems(): + * alignment = None # <<<<<<<<<<<<<< + * count = 0 + * for als, currcount in alslist.iteritems(): + */ + __Pyx_INCREF(Py_None); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_alignment); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_alignment); + __Pyx_GIVEREF(Py_None); + __pyx_cur_scope->__pyx_v_alignment = Py_None; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1092 + * for e, alslist in elist.iteritems(): + * alignment = None + * count = 0 # <<<<<<<<<<<<<< + * for als, currcount in alslist.iteritems(): + * if currcount > count: + */ + __Pyx_INCREF(__pyx_int_0); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_count); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_count); + __Pyx_GIVEREF(__pyx_int_0); + __pyx_cur_scope->__pyx_v_count = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1093 + * alignment = None + * count = 0 + * for als, currcount in alslist.iteritems(): # <<<<<<<<<<<<<< + * if currcount > count: + * alignment = als + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_alslist, __pyx_n_s__iteritems); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyList_CheckExact(__pyx_t_14) || PyTuple_CheckExact(__pyx_t_14)) { + __pyx_t_2 = __pyx_t_14; __Pyx_INCREF(__pyx_t_2); __pyx_t_26 = 0; + __pyx_t_27 = NULL; + } else { + __pyx_t_26 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_27 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + for (;;) { + if (!__pyx_t_27 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_26 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_14 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_26); __Pyx_INCREF(__pyx_t_14); __pyx_t_26++; + } else if (!__pyx_t_27 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_26 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_14 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_26); __Pyx_INCREF(__pyx_t_14); __pyx_t_26++; + } else { + __pyx_t_14 = __pyx_t_27(__pyx_t_2); + if (unlikely(!__pyx_t_14)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_14); + } + if ((likely(PyTuple_CheckExact(__pyx_t_14))) || (PyList_CheckExact(__pyx_t_14))) { + PyObject* sequence = __pyx_t_14; + if (likely(PyTuple_CheckExact(sequence))) { + 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[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_15 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_15 = PyList_GET_ITEM(sequence, 0); + __pyx_t_3 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_15); + __Pyx_INCREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_17 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_15 = __pyx_t_17(__pyx_t_7); if (unlikely(!__pyx_t_15)) goto __pyx_L58_unpacking_failed; + __Pyx_GOTREF(__pyx_t_15); + index = 1; __pyx_t_3 = __pyx_t_17(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L58_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L59_unpacking_done; + __pyx_L58_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L59_unpacking_done:; + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_als); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_als); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_cur_scope->__pyx_v_als = __pyx_t_15; + __pyx_t_15 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_currcount); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_currcount); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_currcount = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1094 + * count = 0 + * for als, currcount in alslist.iteritems(): + * if currcount > count: # <<<<<<<<<<<<<< + * alignment = als + * count = currcount + */ + __pyx_t_14 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_currcount, __pyx_cur_scope->__pyx_v_count, Py_GT); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1094; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1094; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1095 + * for als, currcount in alslist.iteritems(): + * if currcount > count: + * alignment = als # <<<<<<<<<<<<<< + * count = currcount + * scores = [] + */ + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_als); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_alignment); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_alignment); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_als); + __pyx_cur_scope->__pyx_v_alignment = __pyx_cur_scope->__pyx_v_als; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1096 + * if currcount > count: + * alignment = als + * count = currcount # <<<<<<<<<<<<<< + * scores = [] + * for model in models: + */ + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_currcount); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_count); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_count); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_currcount); + __pyx_cur_scope->__pyx_v_count = __pyx_cur_scope->__pyx_v_currcount; + goto __pyx_L60; + } + __pyx_L60:; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1097 + * alignment = als + * count = currcount + * scores = [] # <<<<<<<<<<<<<< + * for model in models: + * scores.append(model(f, e, count, fcount[f], num_samples)) + */ + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_scores)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_scores)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_cur_scope->__pyx_v_scores = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1098 + * count = currcount + * scores = [] + * for model in models: # <<<<<<<<<<<<<< + * scores.append(model(f, e, count, fcount[f], num_samples)) + * yield Rule(self.category, f, e, + */ + if (PyList_CheckExact(__pyx_cur_scope->__pyx_v_models) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_models)) { + __pyx_t_2 = __pyx_cur_scope->__pyx_v_models; __Pyx_INCREF(__pyx_t_2); __pyx_t_26 = 0; + __pyx_t_27 = NULL; + } else { + __pyx_t_26 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_models); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_27 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_27 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_26 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_14 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_26); __Pyx_INCREF(__pyx_t_14); __pyx_t_26++; + } else if (!__pyx_t_27 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_26 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_14 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_26); __Pyx_INCREF(__pyx_t_14); __pyx_t_26++; + } else { + __pyx_t_14 = __pyx_t_27(__pyx_t_2); + if (unlikely(!__pyx_t_14)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_14); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_model); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_model); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_cur_scope->__pyx_v_model = __pyx_t_14; + __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1099 + * scores = [] + * for model in models: + * scores.append(model(f, e, count, fcount[f], num_samples)) # <<<<<<<<<<<<<< + * yield Rule(self.category, f, e, + * scores=scores, word_alignments=alignment) + */ + __pyx_t_14 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fcount), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_14) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_num_samples); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_15 = PyTuple_New(5); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_f); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_cur_scope->__pyx_v_f); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_f); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_e); + PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_cur_scope->__pyx_v_e); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_e); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_count); + PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_cur_scope->__pyx_v_count); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_count); + PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_15, 4, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_14 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_cur_scope->__pyx_v_model, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_scores, __pyx_t_3); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1100 + * for model in models: + * scores.append(model(f, e, count, fcount[f], num_samples)) + * yield Rule(self.category, f, e, # <<<<<<<<<<<<<< + * scores=scores, word_alignments=alignment) + * + */ + __pyx_t_2 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->category); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_f); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_cur_scope->__pyx_v_f); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_f); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_e); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_cur_scope->__pyx_v_e); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_e); + __pyx_t_2 = 0; + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1101 + * scores.append(model(f, e, count, fcount[f], num_samples)) + * yield Rule(self.category, f, e, + * scores=scores, word_alignments=alignment) # <<<<<<<<<<<<<< + * + * if len(phrase) < self.max_length and i+spanlen < len(fwords) and pathlen+1 <= self.max_initial_size: + */ + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__scores), ((PyObject *)__pyx_cur_scope->__pyx_v_scores)) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__word_alignments), __pyx_cur_scope->__pyx_v_alignment) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_15 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Rule)), ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_r = __pyx_t_15; + __pyx_t_15 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_5; + __Pyx_XGIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_t_2 = __pyx_t_9; + __Pyx_XGIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_t_3 = __pyx_t_10; + __Pyx_XGIVEREF(__pyx_t_12); + __pyx_cur_scope->__pyx_t_4 = __pyx_t_12; + __pyx_cur_scope->__pyx_t_5 = __pyx_t_21; + __pyx_cur_scope->__pyx_t_6 = __pyx_t_24; + __pyx_cur_scope->__pyx_t_7 = __pyx_t_25; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L63_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_5 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_9 = __pyx_cur_scope->__pyx_t_2; + __pyx_cur_scope->__pyx_t_2 = 0; + __Pyx_XGOTREF(__pyx_t_9); + __pyx_t_10 = __pyx_cur_scope->__pyx_t_3; + __pyx_cur_scope->__pyx_t_3 = 0; + __Pyx_XGOTREF(__pyx_t_10); + __pyx_t_12 = __pyx_cur_scope->__pyx_t_4; + __pyx_cur_scope->__pyx_t_4 = 0; + __Pyx_XGOTREF(__pyx_t_12); + __pyx_t_21 = __pyx_cur_scope->__pyx_t_5; + __pyx_t_24 = __pyx_cur_scope->__pyx_t_6; + __pyx_t_25 = __pyx_cur_scope->__pyx_t_7; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L45; + } + __pyx_L45:; + goto __pyx_L40; + } + __pyx_L40:; + goto __pyx_L32; + } + __pyx_L32:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1103 + * scores=scores, word_alignments=alignment) + * + * if len(phrase) < self.max_length and i+spanlen < len(fwords) and pathlen+1 <= self.max_initial_size: # <<<<<<<<<<<<<< + * for alt_id in range(len(fwords[i+spanlen])): + * new_frontier.append((k, i+spanlen, alt_id, pathlen + 1, node, phrase, is_shadow_path)) + */ + __pyx_t_21 = PyObject_Length(__pyx_cur_scope->__pyx_v_phrase); if (unlikely(__pyx_t_21 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_19 = (__pyx_t_21 < __pyx_cur_scope->__pyx_v_self->max_length); + if (__pyx_t_19) { + __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyNumber_Add(__pyx_t_9, __pyx_cur_scope->__pyx_v_spanlen); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_21 = PyObject_Length(__pyx_cur_scope->__pyx_v_fwords); if (unlikely(__pyx_t_21 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = PyInt_FromSsize_t(__pyx_t_21); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_15 = PyObject_RichCompare(__pyx_t_10, __pyx_t_9, Py_LT); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (__pyx_t_8) { + __pyx_t_15 = PyNumber_Add(__pyx_cur_scope->__pyx_v_pathlen, __pyx_int_1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->max_initial_size); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyObject_RichCompare(__pyx_t_15, __pyx_t_9, Py_LE); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_28 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_28 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_29 = __pyx_t_28; + } else { + __pyx_t_29 = __pyx_t_8; + } + __pyx_t_8 = __pyx_t_29; + } else { + __pyx_t_8 = __pyx_t_19; + } + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1104 + * + * if len(phrase) < self.max_length and i+spanlen < len(fwords) and pathlen+1 <= self.max_initial_size: + * for alt_id in range(len(fwords[i+spanlen])): # <<<<<<<<<<<<<< + * new_frontier.append((k, i+spanlen, alt_id, pathlen + 1, node, phrase, is_shadow_path)) + * num_subpatterns = arity + */ + __pyx_t_10 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyNumber_Add(__pyx_t_10, __pyx_cur_scope->__pyx_v_spanlen); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = PyObject_GetItem(__pyx_cur_scope->__pyx_v_fwords, __pyx_t_9); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_21 = PyObject_Length(__pyx_t_10); if (unlikely(__pyx_t_21 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_21; __pyx_t_18+=1) { + __pyx_cur_scope->__pyx_v_alt_id = __pyx_t_18; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1105 + * if len(phrase) < self.max_length and i+spanlen < len(fwords) and pathlen+1 <= self.max_initial_size: + * for alt_id in range(len(fwords[i+spanlen])): + * new_frontier.append((k, i+spanlen, alt_id, pathlen + 1, node, phrase, is_shadow_path)) # <<<<<<<<<<<<<< + * num_subpatterns = arity + * if not is_shadow_path: + */ + __pyx_t_10 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_k); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_15 = PyNumber_Add(__pyx_t_9, __pyx_cur_scope->__pyx_v_spanlen); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_alt_id); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_2 = PyNumber_Add(__pyx_cur_scope->__pyx_v_pathlen, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(7); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_15); + __Pyx_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_node); + PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_cur_scope->__pyx_v_node); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_node); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_phrase); + PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_cur_scope->__pyx_v_phrase); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_phrase); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_is_shadow_path); + PyTuple_SET_ITEM(__pyx_t_3, 6, __pyx_cur_scope->__pyx_v_is_shadow_path); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_is_shadow_path); + __pyx_t_10 = 0; + __pyx_t_15 = 0; + __pyx_t_9 = 0; + __pyx_t_2 = 0; + __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_new_frontier, ((PyObject *)__pyx_t_3)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1106 + * for alt_id in range(len(fwords[i+spanlen])): + * new_frontier.append((k, i+spanlen, alt_id, pathlen + 1, node, phrase, is_shadow_path)) + * num_subpatterns = arity # <<<<<<<<<<<<<< + * if not is_shadow_path: + * num_subpatterns = num_subpatterns + 1 + */ + __pyx_cur_scope->__pyx_v_num_subpatterns = __pyx_cur_scope->__pyx_v_arity; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1107 + * new_frontier.append((k, i+spanlen, alt_id, pathlen + 1, node, phrase, is_shadow_path)) + * num_subpatterns = arity + * if not is_shadow_path: # <<<<<<<<<<<<<< + * num_subpatterns = num_subpatterns + 1 + * if len(phrase)+1 < self.max_length and arity < self.max_nonterminals and num_subpatterns < self.max_chunks: + */ + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_is_shadow_path); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_19 = (!__pyx_t_8); + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1108 + * num_subpatterns = arity + * if not is_shadow_path: + * num_subpatterns = num_subpatterns + 1 # <<<<<<<<<<<<<< + * if len(phrase)+1 < self.max_length and arity < self.max_nonterminals and num_subpatterns < self.max_chunks: + * xcat = sym_setindex(self.category, arity+1) + */ + __pyx_cur_scope->__pyx_v_num_subpatterns = (__pyx_cur_scope->__pyx_v_num_subpatterns + 1); + goto __pyx_L67; + } + __pyx_L67:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1109 + * if not is_shadow_path: + * num_subpatterns = num_subpatterns + 1 + * if len(phrase)+1 < self.max_length and arity < self.max_nonterminals and num_subpatterns < self.max_chunks: # <<<<<<<<<<<<<< + * xcat = sym_setindex(self.category, arity+1) + * xnode = node.children[xcat] + */ + __pyx_t_21 = PyObject_Length(__pyx_cur_scope->__pyx_v_phrase); if (unlikely(__pyx_t_21 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_19 = ((__pyx_t_21 + 1) < __pyx_cur_scope->__pyx_v_self->max_length); + if (__pyx_t_19) { + __pyx_t_8 = (__pyx_cur_scope->__pyx_v_arity < __pyx_cur_scope->__pyx_v_self->max_nonterminals); + if (__pyx_t_8) { + __pyx_t_29 = (__pyx_cur_scope->__pyx_v_num_subpatterns < __pyx_cur_scope->__pyx_v_self->max_chunks); + __pyx_t_28 = __pyx_t_29; + } else { + __pyx_t_28 = __pyx_t_8; + } + __pyx_t_8 = __pyx_t_28; + } else { + __pyx_t_8 = __pyx_t_19; + } + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1110 + * num_subpatterns = num_subpatterns + 1 + * if len(phrase)+1 < self.max_length and arity < self.max_nonterminals and num_subpatterns < self.max_chunks: + * xcat = sym_setindex(self.category, arity+1) # <<<<<<<<<<<<<< + * xnode = node.children[xcat] + * # I put spanlen=1 below + */ + __pyx_cur_scope->__pyx_v_xcat = __pyx_f_8_cdec_sa_sym_setindex(__pyx_cur_scope->__pyx_v_self->category, (__pyx_cur_scope->__pyx_v_arity + 1)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1111 + * if len(phrase)+1 < self.max_length and arity < self.max_nonterminals and num_subpatterns < self.max_chunks: + * xcat = sym_setindex(self.category, arity+1) + * xnode = node.children[xcat] # <<<<<<<<<<<<<< + * # I put spanlen=1 below + * key = tuple([self.min_gap_size, i, 1, pathlen]) + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_3, __pyx_cur_scope->__pyx_v_xcat, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_xnode); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_xnode); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_v_xnode = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1113 + * xnode = node.children[xcat] + * # I put spanlen=1 below + * key = tuple([self.min_gap_size, i, 1, pathlen]) # <<<<<<<<<<<<<< + * frontier_nodes = [] + * if (key in nodes_isteps_away_buffer): + */ + __pyx_t_2 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->min_gap_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_9 = PyList_New(4); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + PyList_SET_ITEM(__pyx_t_9, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyList_SET_ITEM(__pyx_t_9, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_INCREF(__pyx_int_1); + PyList_SET_ITEM(__pyx_t_9, 2, __pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_pathlen); + PyList_SET_ITEM(__pyx_t_9, 3, __pyx_cur_scope->__pyx_v_pathlen); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_pathlen); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = ((PyObject *)PyList_AsTuple(__pyx_t_9)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_key)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_key)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_cur_scope->__pyx_v_key = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1114 + * # I put spanlen=1 below + * key = tuple([self.min_gap_size, i, 1, pathlen]) + * frontier_nodes = [] # <<<<<<<<<<<<<< + * if (key in nodes_isteps_away_buffer): + * frontier_nodes = nodes_isteps_away_buffer[key] + */ + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_frontier_nodes); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_frontier_nodes); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_cur_scope->__pyx_v_frontier_nodes = ((PyObject *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1115 + * key = tuple([self.min_gap_size, i, 1, pathlen]) + * frontier_nodes = [] + * if (key in nodes_isteps_away_buffer): # <<<<<<<<<<<<<< + * frontier_nodes = nodes_isteps_away_buffer[key] + * else: + */ + __pyx_t_8 = ((PyDict_Contains(((PyObject *)__pyx_cur_scope->__pyx_v_nodes_isteps_away_buffer), ((PyObject *)__pyx_cur_scope->__pyx_v_key)))); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1116 + * frontier_nodes = [] + * if (key in nodes_isteps_away_buffer): + * frontier_nodes = nodes_isteps_away_buffer[key] # <<<<<<<<<<<<<< + * else: + * frontier_nodes = self.get_all_nodes_isteps_away(self.min_gap_size, i, 1, pathlen, fwords, next_states, reachable_buffer) + */ + __pyx_t_3 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_nodes_isteps_away_buffer), ((PyObject *)__pyx_cur_scope->__pyx_v_key)); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_frontier_nodes); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_frontier_nodes); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_frontier_nodes = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L69; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1118 + * frontier_nodes = nodes_isteps_away_buffer[key] + * else: + * frontier_nodes = self.get_all_nodes_isteps_away(self.min_gap_size, i, 1, pathlen, fwords, next_states, reachable_buffer) # <<<<<<<<<<<<<< + * nodes_isteps_away_buffer[key] = frontier_nodes + * + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_121); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->min_gap_size); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_2 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = PyTuple_New(7); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_pathlen); + PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_cur_scope->__pyx_v_pathlen); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_pathlen); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_15, 4, __pyx_cur_scope->__pyx_v_fwords); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_fwords); + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_next_states)); + PyTuple_SET_ITEM(__pyx_t_15, 5, ((PyObject *)__pyx_cur_scope->__pyx_v_next_states)); + __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_next_states)); + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_reachable_buffer)); + PyTuple_SET_ITEM(__pyx_t_15, 6, ((PyObject *)__pyx_cur_scope->__pyx_v_reachable_buffer)); + __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_reachable_buffer)); + __pyx_t_9 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_frontier_nodes); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_frontier_nodes); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_v_frontier_nodes = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1119 + * else: + * frontier_nodes = self.get_all_nodes_isteps_away(self.min_gap_size, i, 1, pathlen, fwords, next_states, reachable_buffer) + * nodes_isteps_away_buffer[key] = frontier_nodes # <<<<<<<<<<<<<< + * + * for (i, alt, pathlen) in frontier_nodes: + */ + if (PyDict_SetItem(((PyObject *)__pyx_cur_scope->__pyx_v_nodes_isteps_away_buffer), ((PyObject *)__pyx_cur_scope->__pyx_v_key), __pyx_cur_scope->__pyx_v_frontier_nodes) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L69:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1121 + * nodes_isteps_away_buffer[key] = frontier_nodes + * + * for (i, alt, pathlen) in frontier_nodes: # <<<<<<<<<<<<<< + * new_frontier.append((k, i, alt, pathlen, xnode, phrase +(xcat,), is_shadow_path)) + * frontier = new_frontier + */ + if (PyList_CheckExact(__pyx_cur_scope->__pyx_v_frontier_nodes) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_frontier_nodes)) { + __pyx_t_2 = __pyx_cur_scope->__pyx_v_frontier_nodes; __Pyx_INCREF(__pyx_t_2); __pyx_t_21 = 0; + __pyx_t_25 = NULL; + } else { + __pyx_t_21 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_frontier_nodes); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_25 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_25 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_21 >= PyList_GET_SIZE(__pyx_t_2)) break; + __pyx_t_15 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_21); __Pyx_INCREF(__pyx_t_15); __pyx_t_21++; + } else if (!__pyx_t_25 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_21 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + __pyx_t_15 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_21); __Pyx_INCREF(__pyx_t_15); __pyx_t_21++; + } else { + __pyx_t_15 = __pyx_t_25(__pyx_t_2); + if (unlikely(!__pyx_t_15)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_15); + } + if ((likely(PyTuple_CheckExact(__pyx_t_15))) || (PyList_CheckExact(__pyx_t_15))) { + PyObject* sequence = __pyx_t_15; + if (likely(PyTuple_CheckExact(sequence))) { + if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { + if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); + } else { + if (unlikely(PyList_GET_SIZE(sequence) != 3)) { + if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); + else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_9 = PyList_GET_ITEM(sequence, 1); + __pyx_t_10 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_14 = PyObject_GetIter(__pyx_t_15); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_17 = Py_TYPE(__pyx_t_14)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_17(__pyx_t_14); if (unlikely(!__pyx_t_3)) goto __pyx_L72_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + index = 1; __pyx_t_9 = __pyx_t_17(__pyx_t_14); if (unlikely(!__pyx_t_9)) goto __pyx_L72_unpacking_failed; + __Pyx_GOTREF(__pyx_t_9); + index = 2; __pyx_t_10 = __pyx_t_17(__pyx_t_14); if (unlikely(!__pyx_t_10)) goto __pyx_L72_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_14), 3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + goto __pyx_L73_unpacking_done; + __pyx_L72_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[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L73_unpacking_done:; + } + __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_9); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_cur_scope->__pyx_v_i = __pyx_t_18; + __pyx_cur_scope->__pyx_v_alt = __pyx_t_6; + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_pathlen); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_pathlen); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_pathlen = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1122 + * + * for (i, alt, pathlen) in frontier_nodes: + * new_frontier.append((k, i, alt, pathlen, xnode, phrase +(xcat,), is_shadow_path)) # <<<<<<<<<<<<<< + * frontier = new_frontier + * + */ + __pyx_t_15 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_k); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_10 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_alt); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_xcat); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Add(__pyx_cur_scope->__pyx_v_phrase, ((PyObject *)__pyx_t_14)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; + __pyx_t_14 = PyTuple_New(7); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_15); + __Pyx_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_pathlen); + PyTuple_SET_ITEM(__pyx_t_14, 3, __pyx_cur_scope->__pyx_v_pathlen); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_pathlen); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_xnode); + PyTuple_SET_ITEM(__pyx_t_14, 4, __pyx_cur_scope->__pyx_v_xnode); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_xnode); + PyTuple_SET_ITEM(__pyx_t_14, 5, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_is_shadow_path); + PyTuple_SET_ITEM(__pyx_t_14, 6, __pyx_cur_scope->__pyx_v_is_shadow_path); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_is_shadow_path); + __pyx_t_15 = 0; + __pyx_t_10 = 0; + __pyx_t_9 = 0; + __pyx_t_3 = 0; + __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_new_frontier, ((PyObject *)__pyx_t_14)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L68; + } + __pyx_L68:; + goto __pyx_L64; + } + __pyx_L64:; + __pyx_L19_continue:; + } + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1123 + * for (i, alt, pathlen) in frontier_nodes: + * new_frontier.append((k, i, alt, pathlen, xnode, phrase +(xcat,), is_shadow_path)) + * frontier = new_frontier # <<<<<<<<<<<<<< + * + * stop_time = monitor_cpu() + */ + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_new_frontier)); + __Pyx_GOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_frontier)); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope->__pyx_v_frontier)); + __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_new_frontier)); + __pyx_cur_scope->__pyx_v_frontier = __pyx_cur_scope->__pyx_v_new_frontier; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1125 + * frontier = new_frontier + * + * stop_time = monitor_cpu() # <<<<<<<<<<<<<< + * logger.info("Total time for rule lookup, extraction, and scoring = %f seconds", (stop_time - start_time)) + * gc.collect() + */ + __pyx_t_12 = PyFloat_FromDouble(__pyx_f_8_cdec_sa_monitor_cpu()); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_12); + __pyx_cur_scope->__pyx_v_stop_time = __pyx_t_12; + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1126 + * + * stop_time = monitor_cpu() + * logger.info("Total time for rule lookup, extraction, and scoring = %f seconds", (stop_time - start_time)) # <<<<<<<<<<<<<< + * gc.collect() + * logger.info(" Extract time = %f seconds", self.extract_time) + */ + __pyx_t_12 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_12, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = PyFloat_FromDouble(__pyx_cur_scope->__pyx_v_start_time); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_14 = PyNumber_Subtract(__pyx_cur_scope->__pyx_v_stop_time, __pyx_t_12); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_122)); + PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)__pyx_kp_s_122)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_122)); + PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_t_14 = 0; + __pyx_t_14 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1127 + * stop_time = monitor_cpu() + * logger.info("Total time for rule lookup, extraction, and scoring = %f seconds", (stop_time - start_time)) + * gc.collect() # <<<<<<<<<<<<<< + * logger.info(" Extract time = %f seconds", self.extract_time) + * + */ + __pyx_t_14 = __Pyx_GetName(__pyx_m, __pyx_n_s__gc); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_12 = PyObject_GetAttr(__pyx_t_14, __pyx_n_s__collect); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = PyObject_Call(__pyx_t_12, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1128 + * logger.info("Total time for rule lookup, extraction, and scoring = %f seconds", (stop_time - start_time)) + * gc.collect() + * logger.info(" Extract time = %f seconds", self.extract_time) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_14 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_12 = PyObject_GetAttr(__pyx_t_14, __pyx_n_s__info); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = PyFloat_FromDouble(__pyx_cur_scope->__pyx_v_self->extract_time); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_123)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_123)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_123)); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_t_14 = 0; + __pyx_t_14 = PyObject_Call(__pyx_t_12, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_XDECREF(__pyx_t_15); + __Pyx_XDECREF(__pyx_t_16); + __Pyx_AddTraceback("input", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1131 + * + * + * cdef int find_fixpoint(self, # <<<<<<<<<<<<<< + * int f_low, f_high, + * int* f_links_low, int* f_links_high, + */ + +static int __pyx_f_8_cdec_sa_23HieroCachingRuleFactory_find_fixpoint(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, int __pyx_v_f_low, PyObject *__pyx_v_f_high, int *__pyx_v_f_links_low, int *__pyx_v_f_links_high, int *__pyx_v_e_links_low, int *__pyx_v_e_links_high, int __pyx_v_e_in_low, int __pyx_v_e_in_high, int *__pyx_v_e_low, int *__pyx_v_e_high, int *__pyx_v_f_back_low, int *__pyx_v_f_back_high, int __pyx_v_f_sent_len, int __pyx_v_e_sent_len, int __pyx_v_max_f_len, int __pyx_v_max_e_len, int __pyx_v_min_fx_size, int __pyx_v_min_ex_size, int __pyx_v_max_new_x, int __pyx_v_allow_low_x, int __pyx_v_allow_high_x, int __pyx_v_allow_arbitrary_x, CYTHON_UNUSED int __pyx_v_write_log) { + int __pyx_v_e_low_prev; + int __pyx_v_e_high_prev; + int __pyx_v_f_low_prev; + int __pyx_v_f_high_prev; + int __pyx_v_new_x; + int __pyx_v_new_low_x; + int __pyx_v_new_high_x; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("find_fixpoint", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1146 + * cdef int e_low_prev, e_high_prev, f_low_prev, f_high_prev, new_x, new_low_x, new_high_x + * + * e_low[0] = e_in_low # <<<<<<<<<<<<<< + * e_high[0] = e_in_high + * self.find_projection(f_low, f_high, f_links_low, f_links_high, e_low, e_high) + */ + (__pyx_v_e_low[0]) = __pyx_v_e_in_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1147 + * + * e_low[0] = e_in_low + * e_high[0] = e_in_high # <<<<<<<<<<<<<< + * self.find_projection(f_low, f_high, f_links_low, f_links_high, e_low, e_high) + * if e_low[0] == -1: + */ + (__pyx_v_e_high[0]) = __pyx_v_e_in_high; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1148 + * e_low[0] = e_in_low + * e_high[0] = e_in_high + * self.find_projection(f_low, f_high, f_links_low, f_links_high, e_low, e_high) # <<<<<<<<<<<<<< + * if e_low[0] == -1: + * # low-priority corner case: if phrase w is unaligned, + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_f_high); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_projection(__pyx_v_self, __pyx_v_f_low, __pyx_t_1, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_low, __pyx_v_e_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1149 + * e_high[0] = e_in_high + * self.find_projection(f_low, f_high, f_links_low, f_links_high, e_low, e_high) + * if e_low[0] == -1: # <<<<<<<<<<<<<< + * # low-priority corner case: if phrase w is unaligned, + * # but we don't require aligned terminals, then returning + */ + __pyx_t_3 = ((__pyx_v_e_low[0]) == -1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1155 + * # rule X -> X_1 w X_2 / X_1 X_2. This is probably + * # not worth the bother, though. + * return 0 # <<<<<<<<<<<<<< + * elif e_in_low != -1 and e_low[0] != e_in_low: + * if e_in_low - e_low[0] < min_ex_size: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1156 + * # not worth the bother, though. + * return 0 + * elif e_in_low != -1 and e_low[0] != e_in_low: # <<<<<<<<<<<<<< + * if e_in_low - e_low[0] < min_ex_size: + * e_low[0] = e_in_low - min_ex_size + */ + __pyx_t_3 = (__pyx_v_e_in_low != -1); + if (__pyx_t_3) { + __pyx_t_4 = ((__pyx_v_e_low[0]) != __pyx_v_e_in_low); + __pyx_t_5 = __pyx_t_4; + } else { + __pyx_t_5 = __pyx_t_3; + } + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1157 + * return 0 + * elif e_in_low != -1 and e_low[0] != e_in_low: + * if e_in_low - e_low[0] < min_ex_size: # <<<<<<<<<<<<<< + * e_low[0] = e_in_low - min_ex_size + * if e_low[0] < 0: + */ + __pyx_t_5 = ((__pyx_v_e_in_low - (__pyx_v_e_low[0])) < __pyx_v_min_ex_size); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1158 + * elif e_in_low != -1 and e_low[0] != e_in_low: + * if e_in_low - e_low[0] < min_ex_size: + * e_low[0] = e_in_low - min_ex_size # <<<<<<<<<<<<<< + * if e_low[0] < 0: + * return 0 + */ + (__pyx_v_e_low[0]) = (__pyx_v_e_in_low - __pyx_v_min_ex_size); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1159 + * if e_in_low - e_low[0] < min_ex_size: + * e_low[0] = e_in_low - min_ex_size + * if e_low[0] < 0: # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_t_5 = ((__pyx_v_e_low[0]) < 0); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1160 + * e_low[0] = e_in_low - min_ex_size + * if e_low[0] < 0: + * return 0 # <<<<<<<<<<<<<< + * + * if e_high[0] - e_low[0] > max_e_len: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + goto __pyx_L4; + } + __pyx_L4:; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1162 + * return 0 + * + * if e_high[0] - e_low[0] > max_e_len: # <<<<<<<<<<<<<< + * return 0 + * elif e_in_high != -1 and e_high[0] != e_in_high: + */ + __pyx_t_5 = (((__pyx_v_e_high[0]) - (__pyx_v_e_low[0])) > __pyx_v_max_e_len); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1163 + * + * if e_high[0] - e_low[0] > max_e_len: + * return 0 # <<<<<<<<<<<<<< + * elif e_in_high != -1 and e_high[0] != e_in_high: + * if e_high[0] - e_in_high < min_ex_size: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L6; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1164 + * if e_high[0] - e_low[0] > max_e_len: + * return 0 + * elif e_in_high != -1 and e_high[0] != e_in_high: # <<<<<<<<<<<<<< + * if e_high[0] - e_in_high < min_ex_size: + * e_high[0] = e_in_high + min_ex_size + */ + __pyx_t_5 = (__pyx_v_e_in_high != -1); + if (__pyx_t_5) { + __pyx_t_3 = ((__pyx_v_e_high[0]) != __pyx_v_e_in_high); + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_5; + } + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1165 + * return 0 + * elif e_in_high != -1 and e_high[0] != e_in_high: + * if e_high[0] - e_in_high < min_ex_size: # <<<<<<<<<<<<<< + * e_high[0] = e_in_high + min_ex_size + * if e_high[0] > e_sent_len: + */ + __pyx_t_4 = (((__pyx_v_e_high[0]) - __pyx_v_e_in_high) < __pyx_v_min_ex_size); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1166 + * elif e_in_high != -1 and e_high[0] != e_in_high: + * if e_high[0] - e_in_high < min_ex_size: + * e_high[0] = e_in_high + min_ex_size # <<<<<<<<<<<<<< + * if e_high[0] > e_sent_len: + * return 0 + */ + (__pyx_v_e_high[0]) = (__pyx_v_e_in_high + __pyx_v_min_ex_size); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1167 + * if e_high[0] - e_in_high < min_ex_size: + * e_high[0] = e_in_high + min_ex_size + * if e_high[0] > e_sent_len: # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_t_4 = ((__pyx_v_e_high[0]) > __pyx_v_e_sent_len); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1168 + * e_high[0] = e_in_high + min_ex_size + * if e_high[0] > e_sent_len: + * return 0 # <<<<<<<<<<<<<< + * + * f_back_low[0] = -1 + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L8; + } + __pyx_L8:; + goto __pyx_L7; + } + __pyx_L7:; + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1170 + * return 0 + * + * f_back_low[0] = -1 # <<<<<<<<<<<<<< + * f_back_high[0] = -1 + * f_low_prev = f_low + */ + (__pyx_v_f_back_low[0]) = -1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1171 + * + * f_back_low[0] = -1 + * f_back_high[0] = -1 # <<<<<<<<<<<<<< + * f_low_prev = f_low + * f_high_prev = f_high + */ + (__pyx_v_f_back_high[0]) = -1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1172 + * f_back_low[0] = -1 + * f_back_high[0] = -1 + * f_low_prev = f_low # <<<<<<<<<<<<<< + * f_high_prev = f_high + * new_x = 0 + */ + __pyx_v_f_low_prev = __pyx_v_f_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1173 + * f_back_high[0] = -1 + * f_low_prev = f_low + * f_high_prev = f_high # <<<<<<<<<<<<<< + * new_x = 0 + * new_low_x = 0 + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_f_high); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_f_high_prev = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1174 + * f_low_prev = f_low + * f_high_prev = f_high + * new_x = 0 # <<<<<<<<<<<<<< + * new_low_x = 0 + * new_high_x = 0 + */ + __pyx_v_new_x = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1175 + * f_high_prev = f_high + * new_x = 0 + * new_low_x = 0 # <<<<<<<<<<<<<< + * new_high_x = 0 + * + */ + __pyx_v_new_low_x = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1176 + * new_x = 0 + * new_low_x = 0 + * new_high_x = 0 # <<<<<<<<<<<<<< + * + * while True: + */ + __pyx_v_new_high_x = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1178 + * new_high_x = 0 + * + * while True: # <<<<<<<<<<<<<< + * + * if f_back_low[0] == -1: + */ + while (1) { + if (!1) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1180 + * while True: + * + * if f_back_low[0] == -1: # <<<<<<<<<<<<<< + * self.find_projection(e_low[0], e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) + * else: + */ + __pyx_t_4 = ((__pyx_v_f_back_low[0]) == -1); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1181 + * + * if f_back_low[0] == -1: + * self.find_projection(e_low[0], e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) # <<<<<<<<<<<<<< + * else: + * self.find_projection(e_low[0], e_low_prev, e_links_low, e_links_high, f_back_low, f_back_high) + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_projection(__pyx_v_self, (__pyx_v_e_low[0]), (__pyx_v_e_high[0]), __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_f_back_low, __pyx_v_f_back_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L11; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1183 + * self.find_projection(e_low[0], e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) + * else: + * self.find_projection(e_low[0], e_low_prev, e_links_low, e_links_high, f_back_low, f_back_high) # <<<<<<<<<<<<<< + * self.find_projection(e_high_prev, e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) + * + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_projection(__pyx_v_self, (__pyx_v_e_low[0]), __pyx_v_e_low_prev, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_f_back_low, __pyx_v_f_back_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1184 + * else: + * self.find_projection(e_low[0], e_low_prev, e_links_low, e_links_high, f_back_low, f_back_high) + * self.find_projection(e_high_prev, e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) # <<<<<<<<<<<<<< + * + * if f_back_low[0] > f_low: + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_projection(__pyx_v_self, __pyx_v_e_high_prev, (__pyx_v_e_high[0]), __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_f_back_low, __pyx_v_f_back_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1184; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __pyx_L11:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1186 + * self.find_projection(e_high_prev, e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) + * + * if f_back_low[0] > f_low: # <<<<<<<<<<<<<< + * f_back_low[0] = f_low + * + */ + __pyx_t_4 = ((__pyx_v_f_back_low[0]) > __pyx_v_f_low); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1187 + * + * if f_back_low[0] > f_low: + * f_back_low[0] = f_low # <<<<<<<<<<<<<< + * + * if f_back_high[0] < f_high: + */ + (__pyx_v_f_back_low[0]) = __pyx_v_f_low; + goto __pyx_L12; + } + __pyx_L12:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1189 + * f_back_low[0] = f_low + * + * if f_back_high[0] < f_high: # <<<<<<<<<<<<<< + * f_back_high[0] = f_high + * + */ + __pyx_t_2 = PyInt_FromLong((__pyx_v_f_back_high[0])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1189; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = PyObject_RichCompare(__pyx_t_2, __pyx_v_f_high, Py_LT); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1189; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1189; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1190 + * + * if f_back_high[0] < f_high: + * f_back_high[0] = f_high # <<<<<<<<<<<<<< + * + * if f_back_low[0] == f_low_prev and f_back_high[0] == f_high_prev: + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_f_high); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + (__pyx_v_f_back_high[0]) = __pyx_t_1; + goto __pyx_L13; + } + __pyx_L13:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1192 + * f_back_high[0] = f_high + * + * if f_back_low[0] == f_low_prev and f_back_high[0] == f_high_prev: # <<<<<<<<<<<<<< + * return 1 + * + */ + __pyx_t_4 = ((__pyx_v_f_back_low[0]) == __pyx_v_f_low_prev); + if (__pyx_t_4) { + __pyx_t_5 = ((__pyx_v_f_back_high[0]) == __pyx_v_f_high_prev); + __pyx_t_3 = __pyx_t_5; + } else { + __pyx_t_3 = __pyx_t_4; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1193 + * + * if f_back_low[0] == f_low_prev and f_back_high[0] == f_high_prev: + * return 1 # <<<<<<<<<<<<<< + * + * if allow_low_x == 0 and f_back_low[0] < f_low: + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L14; + } + __pyx_L14:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1195 + * return 1 + * + * if allow_low_x == 0 and f_back_low[0] < f_low: # <<<<<<<<<<<<<< + * # FAIL: f phrase is not tight + * return 0 + */ + __pyx_t_3 = (__pyx_v_allow_low_x == 0); + if (__pyx_t_3) { + __pyx_t_4 = ((__pyx_v_f_back_low[0]) < __pyx_v_f_low); + __pyx_t_5 = __pyx_t_4; + } else { + __pyx_t_5 = __pyx_t_3; + } + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1197 + * if allow_low_x == 0 and f_back_low[0] < f_low: + * # FAIL: f phrase is not tight + * return 0 # <<<<<<<<<<<<<< + * + * if f_back_high[0] - f_back_low[0] > max_f_len: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L15; + } + __pyx_L15:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1199 + * return 0 + * + * if f_back_high[0] - f_back_low[0] > max_f_len: # <<<<<<<<<<<<<< + * # FAIL: f back projection is too wide + * return 0 + */ + __pyx_t_5 = (((__pyx_v_f_back_high[0]) - (__pyx_v_f_back_low[0])) > __pyx_v_max_f_len); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1201 + * if f_back_high[0] - f_back_low[0] > max_f_len: + * # FAIL: f back projection is too wide + * return 0 # <<<<<<<<<<<<<< + * + * if allow_high_x == 0 and f_back_high[0] > f_high: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L16; + } + __pyx_L16:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1203 + * return 0 + * + * if allow_high_x == 0 and f_back_high[0] > f_high: # <<<<<<<<<<<<<< + * # FAIL: extension on high side not allowed + * return 0 + */ + __pyx_t_5 = (__pyx_v_allow_high_x == 0); + if (__pyx_t_5) { + __pyx_t_6 = PyInt_FromLong((__pyx_v_f_back_high[0])); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_2 = PyObject_RichCompare(__pyx_t_6, __pyx_v_f_high, Py_GT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_5; + } + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1205 + * if allow_high_x == 0 and f_back_high[0] > f_high: + * # FAIL: extension on high side not allowed + * return 0 # <<<<<<<<<<<<<< + * + * if f_low != f_back_low[0]: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L17; + } + __pyx_L17:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1207 + * return 0 + * + * if f_low != f_back_low[0]: # <<<<<<<<<<<<<< + * if new_low_x == 0: + * if new_x >= max_new_x: + */ + __pyx_t_4 = (__pyx_v_f_low != (__pyx_v_f_back_low[0])); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1208 + * + * if f_low != f_back_low[0]: + * if new_low_x == 0: # <<<<<<<<<<<<<< + * if new_x >= max_new_x: + * # FAIL: extension required on low side violates max # of gaps + */ + __pyx_t_4 = (__pyx_v_new_low_x == 0); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1209 + * if f_low != f_back_low[0]: + * if new_low_x == 0: + * if new_x >= max_new_x: # <<<<<<<<<<<<<< + * # FAIL: extension required on low side violates max # of gaps + * return 0 + */ + __pyx_t_4 = (__pyx_v_new_x >= __pyx_v_max_new_x); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1211 + * if new_x >= max_new_x: + * # FAIL: extension required on low side violates max # of gaps + * return 0 # <<<<<<<<<<<<<< + * else: + * new_x = new_x + 1 + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L20; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1213 + * return 0 + * else: + * new_x = new_x + 1 # <<<<<<<<<<<<<< + * new_low_x = 1 + * if f_low - f_back_low[0] < min_fx_size: + */ + __pyx_v_new_x = (__pyx_v_new_x + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1214 + * else: + * new_x = new_x + 1 + * new_low_x = 1 # <<<<<<<<<<<<<< + * if f_low - f_back_low[0] < min_fx_size: + * f_back_low[0] = f_low - min_fx_size + */ + __pyx_v_new_low_x = 1; + } + __pyx_L20:; + goto __pyx_L19; + } + __pyx_L19:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1215 + * new_x = new_x + 1 + * new_low_x = 1 + * if f_low - f_back_low[0] < min_fx_size: # <<<<<<<<<<<<<< + * f_back_low[0] = f_low - min_fx_size + * if f_back_high[0] - f_back_low[0] > max_f_len: + */ + __pyx_t_4 = ((__pyx_v_f_low - (__pyx_v_f_back_low[0])) < __pyx_v_min_fx_size); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1216 + * new_low_x = 1 + * if f_low - f_back_low[0] < min_fx_size: + * f_back_low[0] = f_low - min_fx_size # <<<<<<<<<<<<<< + * if f_back_high[0] - f_back_low[0] > max_f_len: + * # FAIL: extension required on low side violates max initial length + */ + (__pyx_v_f_back_low[0]) = (__pyx_v_f_low - __pyx_v_min_fx_size); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1217 + * if f_low - f_back_low[0] < min_fx_size: + * f_back_low[0] = f_low - min_fx_size + * if f_back_high[0] - f_back_low[0] > max_f_len: # <<<<<<<<<<<<<< + * # FAIL: extension required on low side violates max initial length + * return 0 + */ + __pyx_t_4 = (((__pyx_v_f_back_high[0]) - (__pyx_v_f_back_low[0])) > __pyx_v_max_f_len); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1219 + * if f_back_high[0] - f_back_low[0] > max_f_len: + * # FAIL: extension required on low side violates max initial length + * return 0 # <<<<<<<<<<<<<< + * if f_back_low[0] < 0: + * # FAIL: extension required on low side violates sentence boundary + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L22; + } + __pyx_L22:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1220 + * # FAIL: extension required on low side violates max initial length + * return 0 + * if f_back_low[0] < 0: # <<<<<<<<<<<<<< + * # FAIL: extension required on low side violates sentence boundary + * return 0 + */ + __pyx_t_4 = ((__pyx_v_f_back_low[0]) < 0); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1222 + * if f_back_low[0] < 0: + * # FAIL: extension required on low side violates sentence boundary + * return 0 # <<<<<<<<<<<<<< + * + * if f_high != f_back_high[0]: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L23; + } + __pyx_L23:; + goto __pyx_L21; + } + __pyx_L21:; + goto __pyx_L18; + } + __pyx_L18:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1224 + * return 0 + * + * if f_high != f_back_high[0]: # <<<<<<<<<<<<<< + * if new_high_x == 0: + * if new_x >= max_new_x: + */ + __pyx_t_2 = PyInt_FromLong((__pyx_v_f_back_high[0])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = PyObject_RichCompare(__pyx_v_f_high, __pyx_t_2, Py_NE); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1225 + * + * if f_high != f_back_high[0]: + * if new_high_x == 0: # <<<<<<<<<<<<<< + * if new_x >= max_new_x: + * # FAIL: extension required on high side violates max # of gaps + */ + __pyx_t_4 = (__pyx_v_new_high_x == 0); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1226 + * if f_high != f_back_high[0]: + * if new_high_x == 0: + * if new_x >= max_new_x: # <<<<<<<<<<<<<< + * # FAIL: extension required on high side violates max # of gaps + * return 0 + */ + __pyx_t_4 = (__pyx_v_new_x >= __pyx_v_max_new_x); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1228 + * if new_x >= max_new_x: + * # FAIL: extension required on high side violates max # of gaps + * return 0 # <<<<<<<<<<<<<< + * else: + * new_x = new_x + 1 + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L26; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1230 + * return 0 + * else: + * new_x = new_x + 1 # <<<<<<<<<<<<<< + * new_high_x = 1 + * if f_back_high[0] - f_high < min_fx_size: + */ + __pyx_v_new_x = (__pyx_v_new_x + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1231 + * else: + * new_x = new_x + 1 + * new_high_x = 1 # <<<<<<<<<<<<<< + * if f_back_high[0] - f_high < min_fx_size: + * f_back_high[0] = f_high + min_fx_size + */ + __pyx_v_new_high_x = 1; + } + __pyx_L26:; + goto __pyx_L25; + } + __pyx_L25:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1232 + * new_x = new_x + 1 + * new_high_x = 1 + * if f_back_high[0] - f_high < min_fx_size: # <<<<<<<<<<<<<< + * f_back_high[0] = f_high + min_fx_size + * if f_back_high[0] - f_back_low[0] > max_f_len: + */ + __pyx_t_6 = PyInt_FromLong((__pyx_v_f_back_high[0])); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_2 = PyNumber_Subtract(__pyx_t_6, __pyx_v_f_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = PyInt_FromLong(__pyx_v_min_fx_size); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PyObject_RichCompare(__pyx_t_2, __pyx_t_6, Py_LT); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1233 + * new_high_x = 1 + * if f_back_high[0] - f_high < min_fx_size: + * f_back_high[0] = f_high + min_fx_size # <<<<<<<<<<<<<< + * if f_back_high[0] - f_back_low[0] > max_f_len: + * # FAIL: extension required on high side violates max initial length + */ + __pyx_t_7 = PyInt_FromLong(__pyx_v_min_fx_size); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1233; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = PyNumber_Add(__pyx_v_f_high, __pyx_t_7); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1233; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1233; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + (__pyx_v_f_back_high[0]) = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1234 + * if f_back_high[0] - f_high < min_fx_size: + * f_back_high[0] = f_high + min_fx_size + * if f_back_high[0] - f_back_low[0] > max_f_len: # <<<<<<<<<<<<<< + * # FAIL: extension required on high side violates max initial length + * return 0 + */ + __pyx_t_4 = (((__pyx_v_f_back_high[0]) - (__pyx_v_f_back_low[0])) > __pyx_v_max_f_len); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1236 + * if f_back_high[0] - f_back_low[0] > max_f_len: + * # FAIL: extension required on high side violates max initial length + * return 0 # <<<<<<<<<<<<<< + * if f_back_high[0] > f_sent_len: + * # FAIL: extension required on high side violates sentence boundary + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L28; + } + __pyx_L28:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1237 + * # FAIL: extension required on high side violates max initial length + * return 0 + * if f_back_high[0] > f_sent_len: # <<<<<<<<<<<<<< + * # FAIL: extension required on high side violates sentence boundary + * return 0 + */ + __pyx_t_4 = ((__pyx_v_f_back_high[0]) > __pyx_v_f_sent_len); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1239 + * if f_back_high[0] > f_sent_len: + * # FAIL: extension required on high side violates sentence boundary + * return 0 # <<<<<<<<<<<<<< + * + * e_low_prev = e_low[0] + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L29; + } + __pyx_L29:; + goto __pyx_L27; + } + __pyx_L27:; + goto __pyx_L24; + } + __pyx_L24:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1241 + * return 0 + * + * e_low_prev = e_low[0] # <<<<<<<<<<<<<< + * e_high_prev = e_high[0] + * + */ + __pyx_v_e_low_prev = (__pyx_v_e_low[0]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1242 + * + * e_low_prev = e_low[0] + * e_high_prev = e_high[0] # <<<<<<<<<<<<<< + * + * self.find_projection(f_back_low[0], f_low_prev, f_links_low, f_links_high, e_low, e_high) + */ + __pyx_v_e_high_prev = (__pyx_v_e_high[0]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1244 + * e_high_prev = e_high[0] + * + * self.find_projection(f_back_low[0], f_low_prev, f_links_low, f_links_high, e_low, e_high) # <<<<<<<<<<<<<< + * self.find_projection(f_high_prev, f_back_high[0], f_links_low, f_links_high, e_low, e_high) + * if e_low[0] == e_low_prev and e_high[0] == e_high_prev: + */ + __pyx_t_6 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_projection(__pyx_v_self, (__pyx_v_f_back_low[0]), __pyx_v_f_low_prev, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_low, __pyx_v_e_high); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1245 + * + * self.find_projection(f_back_low[0], f_low_prev, f_links_low, f_links_high, e_low, e_high) + * self.find_projection(f_high_prev, f_back_high[0], f_links_low, f_links_high, e_low, e_high) # <<<<<<<<<<<<<< + * if e_low[0] == e_low_prev and e_high[0] == e_high_prev: + * return 1 + */ + __pyx_t_6 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_projection(__pyx_v_self, __pyx_v_f_high_prev, (__pyx_v_f_back_high[0]), __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_low, __pyx_v_e_high); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1245; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1246 + * self.find_projection(f_back_low[0], f_low_prev, f_links_low, f_links_high, e_low, e_high) + * self.find_projection(f_high_prev, f_back_high[0], f_links_low, f_links_high, e_low, e_high) + * if e_low[0] == e_low_prev and e_high[0] == e_high_prev: # <<<<<<<<<<<<<< + * return 1 + * if allow_arbitrary_x == 0: + */ + __pyx_t_4 = ((__pyx_v_e_low[0]) == __pyx_v_e_low_prev); + if (__pyx_t_4) { + __pyx_t_5 = ((__pyx_v_e_high[0]) == __pyx_v_e_high_prev); + __pyx_t_3 = __pyx_t_5; + } else { + __pyx_t_3 = __pyx_t_4; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1247 + * self.find_projection(f_high_prev, f_back_high[0], f_links_low, f_links_high, e_low, e_high) + * if e_low[0] == e_low_prev and e_high[0] == e_high_prev: + * return 1 # <<<<<<<<<<<<<< + * if allow_arbitrary_x == 0: + * # FAIL: arbitrary expansion not permitted + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L30; + } + __pyx_L30:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1248 + * if e_low[0] == e_low_prev and e_high[0] == e_high_prev: + * return 1 + * if allow_arbitrary_x == 0: # <<<<<<<<<<<<<< + * # FAIL: arbitrary expansion not permitted + * return 0 + */ + __pyx_t_3 = (__pyx_v_allow_arbitrary_x == 0); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1250 + * if allow_arbitrary_x == 0: + * # FAIL: arbitrary expansion not permitted + * return 0 # <<<<<<<<<<<<<< + * if e_high[0] - e_low[0] > max_e_len: + * # FAIL: re-projection violates sentence max phrase length + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L31; + } + __pyx_L31:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1251 + * # FAIL: arbitrary expansion not permitted + * return 0 + * if e_high[0] - e_low[0] > max_e_len: # <<<<<<<<<<<<<< + * # FAIL: re-projection violates sentence max phrase length + * return 0 + */ + __pyx_t_3 = (((__pyx_v_e_high[0]) - (__pyx_v_e_low[0])) > __pyx_v_max_e_len); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1253 + * if e_high[0] - e_low[0] > max_e_len: + * # FAIL: re-projection violates sentence max phrase length + * return 0 # <<<<<<<<<<<<<< + * f_low_prev = f_back_low[0] + * f_high_prev = f_back_high[0] + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L32; + } + __pyx_L32:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1254 + * # FAIL: re-projection violates sentence max phrase length + * return 0 + * f_low_prev = f_back_low[0] # <<<<<<<<<<<<<< + * f_high_prev = f_back_high[0] + * + */ + __pyx_v_f_low_prev = (__pyx_v_f_back_low[0]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1255 + * return 0 + * f_low_prev = f_back_low[0] + * f_high_prev = f_back_high[0] # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_f_high_prev = (__pyx_v_f_back_high[0]); + } + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_WriteUnraisable("_cdec_sa.HieroCachingRuleFactory.find_fixpoint", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1258 + * + * + * cdef find_projection(self, int in_low, int in_high, int* in_links_low, int* in_links_high, # <<<<<<<<<<<<<< + * int* out_low, int* out_high): + * cdef int i + */ + +static PyObject *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_find_projection(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, int __pyx_v_in_low, int __pyx_v_in_high, int *__pyx_v_in_links_low, int *__pyx_v_in_links_high, int *__pyx_v_out_low, int *__pyx_v_out_high) { + int __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + __Pyx_RefNannySetupContext("find_projection", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1261 + * int* out_low, int* out_high): + * cdef int i + * for i from in_low <= i < in_high: # <<<<<<<<<<<<<< + * if in_links_low[i] != -1: + * if out_low[0] == -1 or in_links_low[i] < out_low[0]: + */ + __pyx_t_1 = __pyx_v_in_high; + for (__pyx_v_i = __pyx_v_in_low; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1262 + * cdef int i + * for i from in_low <= i < in_high: + * if in_links_low[i] != -1: # <<<<<<<<<<<<<< + * if out_low[0] == -1 or in_links_low[i] < out_low[0]: + * out_low[0] = in_links_low[i] + */ + __pyx_t_2 = ((__pyx_v_in_links_low[__pyx_v_i]) != -1); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1263 + * for i from in_low <= i < in_high: + * if in_links_low[i] != -1: + * if out_low[0] == -1 or in_links_low[i] < out_low[0]: # <<<<<<<<<<<<<< + * out_low[0] = in_links_low[i] + * if out_high[0] == -1 or in_links_high[i] > out_high[0]: + */ + __pyx_t_2 = ((__pyx_v_out_low[0]) == -1); + if (!__pyx_t_2) { + __pyx_t_3 = ((__pyx_v_in_links_low[__pyx_v_i]) < (__pyx_v_out_low[0])); + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_2; + } + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1264 + * if in_links_low[i] != -1: + * if out_low[0] == -1 or in_links_low[i] < out_low[0]: + * out_low[0] = in_links_low[i] # <<<<<<<<<<<<<< + * if out_high[0] == -1 or in_links_high[i] > out_high[0]: + * out_high[0] = in_links_high[i] + */ + (__pyx_v_out_low[0]) = (__pyx_v_in_links_low[__pyx_v_i]); + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1265 + * if out_low[0] == -1 or in_links_low[i] < out_low[0]: + * out_low[0] = in_links_low[i] + * if out_high[0] == -1 or in_links_high[i] > out_high[0]: # <<<<<<<<<<<<<< + * out_high[0] = in_links_high[i] + * + */ + __pyx_t_4 = ((__pyx_v_out_high[0]) == -1); + if (!__pyx_t_4) { + __pyx_t_2 = ((__pyx_v_in_links_high[__pyx_v_i]) > (__pyx_v_out_high[0])); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_4; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1266 + * out_low[0] = in_links_low[i] + * if out_high[0] == -1 or in_links_high[i] > out_high[0]: + * out_high[0] = in_links_high[i] # <<<<<<<<<<<<<< + * + * + */ + (__pyx_v_out_high[0]) = (__pyx_v_in_links_high[__pyx_v_i]); + goto __pyx_L7; + } + __pyx_L7:; + goto __pyx_L5; + } + __pyx_L5:; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1269 + * + * + * cdef int* int_arr_extend(self, int* arr, int* arr_len, int* data, int data_len): # <<<<<<<<<<<<<< + * cdef int new_len + * new_len = arr_len[0] + data_len + */ + +static int *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_int_arr_extend(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, int *__pyx_v_arr, int *__pyx_v_arr_len, int *__pyx_v_data, int __pyx_v_data_len) { + int __pyx_v_new_len; + int *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("int_arr_extend", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1271 + * cdef int* int_arr_extend(self, int* arr, int* arr_len, int* data, int data_len): + * cdef int new_len + * new_len = arr_len[0] + data_len # <<<<<<<<<<<<<< + * arr = realloc(arr, new_len*sizeof(int)) + * memcpy(arr+arr_len[0], data, data_len*sizeof(int)) + */ + __pyx_v_new_len = ((__pyx_v_arr_len[0]) + __pyx_v_data_len); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1272 + * cdef int new_len + * new_len = arr_len[0] + data_len + * arr = realloc(arr, new_len*sizeof(int)) # <<<<<<<<<<<<<< + * memcpy(arr+arr_len[0], data, data_len*sizeof(int)) + * arr_len[0] = new_len + */ + __pyx_v_arr = ((int *)realloc(__pyx_v_arr, (__pyx_v_new_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1273 + * new_len = arr_len[0] + data_len + * arr = realloc(arr, new_len*sizeof(int)) + * memcpy(arr+arr_len[0], data, data_len*sizeof(int)) # <<<<<<<<<<<<<< + * arr_len[0] = new_len + * return arr + */ + memcpy((__pyx_v_arr + (__pyx_v_arr_len[0])), __pyx_v_data, (__pyx_v_data_len * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1274 + * arr = realloc(arr, new_len*sizeof(int)) + * memcpy(arr+arr_len[0], data, data_len*sizeof(int)) + * arr_len[0] = new_len # <<<<<<<<<<<<<< + * return arr + * + */ + (__pyx_v_arr_len[0]) = __pyx_v_new_len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1275 + * memcpy(arr+arr_len[0], data, data_len*sizeof(int)) + * arr_len[0] = new_len + * return arr # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_arr; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1278 + * + * + * cdef extract_phrases(self, int e_low, int e_high, int* e_gap_low, int* e_gap_high, int* e_links_low, int num_gaps, # <<<<<<<<<<<<<< + * int f_low, int f_high, int* f_gap_low, int* f_gap_high, int* f_links_low, + * int sent_id, int e_sent_len, int e_sent_start): + */ + +static PyObject *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_extract_phrases(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, int __pyx_v_e_low, int __pyx_v_e_high, int *__pyx_v_e_gap_low, int *__pyx_v_e_gap_high, int *__pyx_v_e_links_low, int __pyx_v_num_gaps, CYTHON_UNUSED int __pyx_v_f_low, CYTHON_UNUSED int __pyx_v_f_high, CYTHON_UNUSED int *__pyx_v_f_gap_low, CYTHON_UNUSED int *__pyx_v_f_gap_high, CYTHON_UNUSED int *__pyx_v_f_links_low, CYTHON_UNUSED int __pyx_v_sent_id, int __pyx_v_e_sent_len, int __pyx_v_e_sent_start) { + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_k; + int __pyx_v_m; + int __pyx_v_n; + int *__pyx_v_e_gap_order; + int __pyx_v_e_x_low; + int __pyx_v_e_x_high; + int __pyx_v_e_x_gap_low; + int __pyx_v_e_x_gap_high; + int *__pyx_v_e_gaps1; + int *__pyx_v_e_gaps2; + int __pyx_v_len1; + int __pyx_v_len2; + int __pyx_v_step; + int __pyx_v_num_chunks; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_ephr_arr = 0; + PyObject *__pyx_v_result = 0; + PyObject *__pyx_v_indexes = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + long __pyx_t_9; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("extract_phrases", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1286 + * cdef result + * + * result = [] # <<<<<<<<<<<<<< + * len1 = 0 + * e_gaps1 = malloc(0) + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1287 + * + * result = [] + * len1 = 0 # <<<<<<<<<<<<<< + * e_gaps1 = malloc(0) + * ephr_arr = IntList() + */ + __pyx_v_len1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1288 + * result = [] + * len1 = 0 + * e_gaps1 = malloc(0) # <<<<<<<<<<<<<< + * ephr_arr = IntList() + * + */ + __pyx_v_e_gaps1 = ((int *)malloc(0)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1289 + * len1 = 0 + * e_gaps1 = malloc(0) + * ephr_arr = IntList() # <<<<<<<<<<<<<< + * + * e_gap_order = malloc(num_gaps*sizeof(int)) + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1289; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_ephr_arr = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1291 + * ephr_arr = IntList() + * + * e_gap_order = malloc(num_gaps*sizeof(int)) # <<<<<<<<<<<<<< + * if num_gaps > 0: + * e_gap_order[0] = 0 + */ + __pyx_v_e_gap_order = ((int *)malloc((__pyx_v_num_gaps * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1292 + * + * e_gap_order = malloc(num_gaps*sizeof(int)) + * if num_gaps > 0: # <<<<<<<<<<<<<< + * e_gap_order[0] = 0 + * for i from 1 <= i < num_gaps: + */ + __pyx_t_2 = (__pyx_v_num_gaps > 0); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1293 + * e_gap_order = malloc(num_gaps*sizeof(int)) + * if num_gaps > 0: + * e_gap_order[0] = 0 # <<<<<<<<<<<<<< + * for i from 1 <= i < num_gaps: + * for j from 0 <= j < i: + */ + (__pyx_v_e_gap_order[0]) = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1294 + * if num_gaps > 0: + * e_gap_order[0] = 0 + * for i from 1 <= i < num_gaps: # <<<<<<<<<<<<<< + * for j from 0 <= j < i: + * if e_gap_low[i] < e_gap_low[j]: + */ + __pyx_t_3 = __pyx_v_num_gaps; + for (__pyx_v_i = 1; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1295 + * e_gap_order[0] = 0 + * for i from 1 <= i < num_gaps: + * for j from 0 <= j < i: # <<<<<<<<<<<<<< + * if e_gap_low[i] < e_gap_low[j]: + * for k from j <= k < i: + */ + __pyx_t_4 = __pyx_v_i; + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_4; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1296 + * for i from 1 <= i < num_gaps: + * for j from 0 <= j < i: + * if e_gap_low[i] < e_gap_low[j]: # <<<<<<<<<<<<<< + * for k from j <= k < i: + * e_gap_order[k+1] = e_gap_order[k] + */ + __pyx_t_2 = ((__pyx_v_e_gap_low[__pyx_v_i]) < (__pyx_v_e_gap_low[__pyx_v_j])); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1297 + * for j from 0 <= j < i: + * if e_gap_low[i] < e_gap_low[j]: + * for k from j <= k < i: # <<<<<<<<<<<<<< + * e_gap_order[k+1] = e_gap_order[k] + * e_gap_order[j] = i + */ + __pyx_t_5 = __pyx_v_i; + for (__pyx_v_k = __pyx_v_j; __pyx_v_k < __pyx_t_5; __pyx_v_k++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1298 + * if e_gap_low[i] < e_gap_low[j]: + * for k from j <= k < i: + * e_gap_order[k+1] = e_gap_order[k] # <<<<<<<<<<<<<< + * e_gap_order[j] = i + * break + */ + (__pyx_v_e_gap_order[(__pyx_v_k + 1)]) = (__pyx_v_e_gap_order[__pyx_v_k]); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1299 + * for k from j <= k < i: + * e_gap_order[k+1] = e_gap_order[k] + * e_gap_order[j] = i # <<<<<<<<<<<<<< + * break + * else: + */ + (__pyx_v_e_gap_order[__pyx_v_j]) = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1300 + * e_gap_order[k+1] = e_gap_order[k] + * e_gap_order[j] = i + * break # <<<<<<<<<<<<<< + * else: + * e_gap_order[i] = i + */ + goto __pyx_L7_break; + goto __pyx_L8; + } + __pyx_L8:; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1302 + * break + * else: + * e_gap_order[i] = i # <<<<<<<<<<<<<< + * + * e_x_low = e_low + */ + (__pyx_v_e_gap_order[__pyx_v_i]) = __pyx_v_i; + } + __pyx_L7_break:; + } + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1304 + * e_gap_order[i] = i + * + * e_x_low = e_low # <<<<<<<<<<<<<< + * e_x_high = e_high + * if self.tight_phrases == 0: + */ + __pyx_v_e_x_low = __pyx_v_e_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1305 + * + * e_x_low = e_low + * e_x_high = e_high # <<<<<<<<<<<<<< + * if self.tight_phrases == 0: + * while e_x_low > 0 and e_high - e_x_low < self.train_max_initial_size and e_links_low[e_x_low-1] == -1: + */ + __pyx_v_e_x_high = __pyx_v_e_high; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1306 + * e_x_low = e_low + * e_x_high = e_high + * if self.tight_phrases == 0: # <<<<<<<<<<<<<< + * while e_x_low > 0 and e_high - e_x_low < self.train_max_initial_size and e_links_low[e_x_low-1] == -1: + * e_x_low = e_x_low - 1 + */ + __pyx_t_2 = (__pyx_v_self->tight_phrases == 0); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1307 + * e_x_high = e_high + * if self.tight_phrases == 0: + * while e_x_low > 0 and e_high - e_x_low < self.train_max_initial_size and e_links_low[e_x_low-1] == -1: # <<<<<<<<<<<<<< + * e_x_low = e_x_low - 1 + * while e_x_high < e_sent_len and e_x_high - e_low < self.train_max_initial_size and e_links_low[e_x_high] == -1: + */ + while (1) { + __pyx_t_2 = (__pyx_v_e_x_low > 0); + if (__pyx_t_2) { + __pyx_t_6 = ((__pyx_v_e_high - __pyx_v_e_x_low) < __pyx_v_self->train_max_initial_size); + if (__pyx_t_6) { + __pyx_t_7 = ((__pyx_v_e_links_low[(__pyx_v_e_x_low - 1)]) == -1); + __pyx_t_8 = __pyx_t_7; + } else { + __pyx_t_8 = __pyx_t_6; + } + __pyx_t_6 = __pyx_t_8; + } else { + __pyx_t_6 = __pyx_t_2; + } + if (!__pyx_t_6) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1308 + * if self.tight_phrases == 0: + * while e_x_low > 0 and e_high - e_x_low < self.train_max_initial_size and e_links_low[e_x_low-1] == -1: + * e_x_low = e_x_low - 1 # <<<<<<<<<<<<<< + * while e_x_high < e_sent_len and e_x_high - e_low < self.train_max_initial_size and e_links_low[e_x_high] == -1: + * e_x_high = e_x_high + 1 + */ + __pyx_v_e_x_low = (__pyx_v_e_x_low - 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1309 + * while e_x_low > 0 and e_high - e_x_low < self.train_max_initial_size and e_links_low[e_x_low-1] == -1: + * e_x_low = e_x_low - 1 + * while e_x_high < e_sent_len and e_x_high - e_low < self.train_max_initial_size and e_links_low[e_x_high] == -1: # <<<<<<<<<<<<<< + * e_x_high = e_x_high + 1 + * + */ + while (1) { + __pyx_t_6 = (__pyx_v_e_x_high < __pyx_v_e_sent_len); + if (__pyx_t_6) { + __pyx_t_2 = ((__pyx_v_e_x_high - __pyx_v_e_low) < __pyx_v_self->train_max_initial_size); + if (__pyx_t_2) { + __pyx_t_8 = ((__pyx_v_e_links_low[__pyx_v_e_x_high]) == -1); + __pyx_t_7 = __pyx_t_8; + } else { + __pyx_t_7 = __pyx_t_2; + } + __pyx_t_2 = __pyx_t_7; + } else { + __pyx_t_2 = __pyx_t_6; + } + if (!__pyx_t_2) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1310 + * e_x_low = e_x_low - 1 + * while e_x_high < e_sent_len and e_x_high - e_low < self.train_max_initial_size and e_links_low[e_x_high] == -1: + * e_x_high = e_x_high + 1 # <<<<<<<<<<<<<< + * + * for i from e_x_low <= i <= e_low: + */ + __pyx_v_e_x_high = (__pyx_v_e_x_high + 1); + } + goto __pyx_L11; + } + __pyx_L11:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1312 + * e_x_high = e_x_high + 1 + * + * for i from e_x_low <= i <= e_low: # <<<<<<<<<<<<<< + * e_gaps1 = self.int_arr_extend(e_gaps1, &len1, &i, 1) + * + */ + __pyx_t_3 = __pyx_v_e_low; + for (__pyx_v_i = __pyx_v_e_x_low; __pyx_v_i <= __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1313 + * + * for i from e_x_low <= i <= e_low: + * e_gaps1 = self.int_arr_extend(e_gaps1, &len1, &i, 1) # <<<<<<<<<<<<<< + * + * for i from 0 <= i < num_gaps: + */ + __pyx_v_e_gaps1 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->int_arr_extend(__pyx_v_self, __pyx_v_e_gaps1, (&__pyx_v_len1), (&__pyx_v_i), 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1315 + * e_gaps1 = self.int_arr_extend(e_gaps1, &len1, &i, 1) + * + * for i from 0 <= i < num_gaps: # <<<<<<<<<<<<<< + * e_gaps2 = malloc(0) + * len2 = 0 + */ + __pyx_t_3 = __pyx_v_num_gaps; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1316 + * + * for i from 0 <= i < num_gaps: + * e_gaps2 = malloc(0) # <<<<<<<<<<<<<< + * len2 = 0 + * + */ + __pyx_v_e_gaps2 = ((int *)malloc(0)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1317 + * for i from 0 <= i < num_gaps: + * e_gaps2 = malloc(0) + * len2 = 0 # <<<<<<<<<<<<<< + * + * j = e_gap_order[i] + */ + __pyx_v_len2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1319 + * len2 = 0 + * + * j = e_gap_order[i] # <<<<<<<<<<<<<< + * e_x_gap_low = e_gap_low[j] + * e_x_gap_high = e_gap_high[j] + */ + __pyx_v_j = (__pyx_v_e_gap_order[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1320 + * + * j = e_gap_order[i] + * e_x_gap_low = e_gap_low[j] # <<<<<<<<<<<<<< + * e_x_gap_high = e_gap_high[j] + * if self.tight_phrases == 0: + */ + __pyx_v_e_x_gap_low = (__pyx_v_e_gap_low[__pyx_v_j]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1321 + * j = e_gap_order[i] + * e_x_gap_low = e_gap_low[j] + * e_x_gap_high = e_gap_high[j] # <<<<<<<<<<<<<< + * if self.tight_phrases == 0: + * while e_x_gap_low > e_x_low and e_links_low[e_x_gap_low-1] == -1: + */ + __pyx_v_e_x_gap_high = (__pyx_v_e_gap_high[__pyx_v_j]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1322 + * e_x_gap_low = e_gap_low[j] + * e_x_gap_high = e_gap_high[j] + * if self.tight_phrases == 0: # <<<<<<<<<<<<<< + * while e_x_gap_low > e_x_low and e_links_low[e_x_gap_low-1] == -1: + * e_x_gap_low = e_x_gap_low - 1 + */ + __pyx_t_2 = (__pyx_v_self->tight_phrases == 0); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1323 + * e_x_gap_high = e_gap_high[j] + * if self.tight_phrases == 0: + * while e_x_gap_low > e_x_low and e_links_low[e_x_gap_low-1] == -1: # <<<<<<<<<<<<<< + * e_x_gap_low = e_x_gap_low - 1 + * while e_x_gap_high < e_x_high and e_links_low[e_x_gap_high] == -1: + */ + while (1) { + __pyx_t_2 = (__pyx_v_e_x_gap_low > __pyx_v_e_x_low); + if (__pyx_t_2) { + __pyx_t_6 = ((__pyx_v_e_links_low[(__pyx_v_e_x_gap_low - 1)]) == -1); + __pyx_t_7 = __pyx_t_6; + } else { + __pyx_t_7 = __pyx_t_2; + } + if (!__pyx_t_7) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1324 + * if self.tight_phrases == 0: + * while e_x_gap_low > e_x_low and e_links_low[e_x_gap_low-1] == -1: + * e_x_gap_low = e_x_gap_low - 1 # <<<<<<<<<<<<<< + * while e_x_gap_high < e_x_high and e_links_low[e_x_gap_high] == -1: + * e_x_gap_high = e_x_gap_high + 1 + */ + __pyx_v_e_x_gap_low = (__pyx_v_e_x_gap_low - 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1325 + * while e_x_gap_low > e_x_low and e_links_low[e_x_gap_low-1] == -1: + * e_x_gap_low = e_x_gap_low - 1 + * while e_x_gap_high < e_x_high and e_links_low[e_x_gap_high] == -1: # <<<<<<<<<<<<<< + * e_x_gap_high = e_x_gap_high + 1 + * + */ + while (1) { + __pyx_t_7 = (__pyx_v_e_x_gap_high < __pyx_v_e_x_high); + if (__pyx_t_7) { + __pyx_t_2 = ((__pyx_v_e_links_low[__pyx_v_e_x_gap_high]) == -1); + __pyx_t_6 = __pyx_t_2; + } else { + __pyx_t_6 = __pyx_t_7; + } + if (!__pyx_t_6) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1326 + * e_x_gap_low = e_x_gap_low - 1 + * while e_x_gap_high < e_x_high and e_links_low[e_x_gap_high] == -1: + * e_x_gap_high = e_x_gap_high + 1 # <<<<<<<<<<<<<< + * + * k = 0 + */ + __pyx_v_e_x_gap_high = (__pyx_v_e_x_gap_high + 1); + } + goto __pyx_L20; + } + __pyx_L20:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1328 + * e_x_gap_high = e_x_gap_high + 1 + * + * k = 0 # <<<<<<<<<<<<<< + * step = 1+(i*2) + * while k < len1: + */ + __pyx_v_k = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1329 + * + * k = 0 + * step = 1+(i*2) # <<<<<<<<<<<<<< + * while k < len1: + * for m from e_x_gap_low <= m <= e_gap_low[j]: + */ + __pyx_v_step = (1 + (__pyx_v_i * 2)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1330 + * k = 0 + * step = 1+(i*2) + * while k < len1: # <<<<<<<<<<<<<< + * for m from e_x_gap_low <= m <= e_gap_low[j]: + * if m >= e_gaps1[k+step-1]: + */ + while (1) { + __pyx_t_6 = (__pyx_v_k < __pyx_v_len1); + if (!__pyx_t_6) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1331 + * step = 1+(i*2) + * while k < len1: + * for m from e_x_gap_low <= m <= e_gap_low[j]: # <<<<<<<<<<<<<< + * if m >= e_gaps1[k+step-1]: + * for n from e_gap_high[j] <= n <= e_x_gap_high: + */ + __pyx_t_4 = (__pyx_v_e_gap_low[__pyx_v_j]); + for (__pyx_v_m = __pyx_v_e_x_gap_low; __pyx_v_m <= __pyx_t_4; __pyx_v_m++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1332 + * while k < len1: + * for m from e_x_gap_low <= m <= e_gap_low[j]: + * if m >= e_gaps1[k+step-1]: # <<<<<<<<<<<<<< + * for n from e_gap_high[j] <= n <= e_x_gap_high: + * if n-m >= 1: # extractor.py doesn't restrict target-side gap length + */ + __pyx_t_6 = (__pyx_v_m >= (__pyx_v_e_gaps1[((__pyx_v_k + __pyx_v_step) - 1)])); + if (__pyx_t_6) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1333 + * for m from e_x_gap_low <= m <= e_gap_low[j]: + * if m >= e_gaps1[k+step-1]: + * for n from e_gap_high[j] <= n <= e_x_gap_high: # <<<<<<<<<<<<<< + * if n-m >= 1: # extractor.py doesn't restrict target-side gap length + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+k, step) + */ + __pyx_t_5 = __pyx_v_e_x_gap_high; + for (__pyx_v_n = (__pyx_v_e_gap_high[__pyx_v_j]); __pyx_v_n <= __pyx_t_5; __pyx_v_n++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1334 + * if m >= e_gaps1[k+step-1]: + * for n from e_gap_high[j] <= n <= e_x_gap_high: + * if n-m >= 1: # extractor.py doesn't restrict target-side gap length # <<<<<<<<<<<<<< + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+k, step) + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &m, 1) + */ + __pyx_t_6 = ((__pyx_v_n - __pyx_v_m) >= 1); + if (__pyx_t_6) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1335 + * for n from e_gap_high[j] <= n <= e_x_gap_high: + * if n-m >= 1: # extractor.py doesn't restrict target-side gap length + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+k, step) # <<<<<<<<<<<<<< + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &m, 1) + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &n, 1) + */ + __pyx_v_e_gaps2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->int_arr_extend(__pyx_v_self, __pyx_v_e_gaps2, (&__pyx_v_len2), (__pyx_v_e_gaps1 + __pyx_v_k), __pyx_v_step); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1336 + * if n-m >= 1: # extractor.py doesn't restrict target-side gap length + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+k, step) + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &m, 1) # <<<<<<<<<<<<<< + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &n, 1) + * k = k + step + */ + __pyx_v_e_gaps2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->int_arr_extend(__pyx_v_self, __pyx_v_e_gaps2, (&__pyx_v_len2), (&__pyx_v_m), 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1337 + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+k, step) + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &m, 1) + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &n, 1) # <<<<<<<<<<<<<< + * k = k + step + * free(e_gaps1) + */ + __pyx_v_e_gaps2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->int_arr_extend(__pyx_v_self, __pyx_v_e_gaps2, (&__pyx_v_len2), (&__pyx_v_n), 1); + goto __pyx_L32; + } + __pyx_L32:; + } + goto __pyx_L29; + } + __pyx_L29:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1338 + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &m, 1) + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &n, 1) + * k = k + step # <<<<<<<<<<<<<< + * free(e_gaps1) + * e_gaps1 = e_gaps2 + */ + __pyx_v_k = (__pyx_v_k + __pyx_v_step); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1339 + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &n, 1) + * k = k + step + * free(e_gaps1) # <<<<<<<<<<<<<< + * e_gaps1 = e_gaps2 + * len1 = len2 + */ + free(__pyx_v_e_gaps1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1340 + * k = k + step + * free(e_gaps1) + * e_gaps1 = e_gaps2 # <<<<<<<<<<<<<< + * len1 = len2 + * + */ + __pyx_v_e_gaps1 = __pyx_v_e_gaps2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1341 + * free(e_gaps1) + * e_gaps1 = e_gaps2 + * len1 = len2 # <<<<<<<<<<<<<< + * + * step = 1+(num_gaps*2) + */ + __pyx_v_len1 = __pyx_v_len2; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1343 + * len1 = len2 + * + * step = 1+(num_gaps*2) # <<<<<<<<<<<<<< + * e_gaps2 = malloc(0) + * len2 = 0 + */ + __pyx_v_step = (1 + (__pyx_v_num_gaps * 2)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1344 + * + * step = 1+(num_gaps*2) + * e_gaps2 = malloc(0) # <<<<<<<<<<<<<< + * len2 = 0 + * for i from e_high <= i <= e_x_high: + */ + __pyx_v_e_gaps2 = ((int *)malloc(0)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1345 + * step = 1+(num_gaps*2) + * e_gaps2 = malloc(0) + * len2 = 0 # <<<<<<<<<<<<<< + * for i from e_high <= i <= e_x_high: + * j = 0 + */ + __pyx_v_len2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1346 + * e_gaps2 = malloc(0) + * len2 = 0 + * for i from e_high <= i <= e_x_high: # <<<<<<<<<<<<<< + * j = 0 + * while j < len1: + */ + __pyx_t_3 = __pyx_v_e_x_high; + for (__pyx_v_i = __pyx_v_e_high; __pyx_v_i <= __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1347 + * len2 = 0 + * for i from e_high <= i <= e_x_high: + * j = 0 # <<<<<<<<<<<<<< + * while j < len1: + * if i - e_gaps1[j] <= self.train_max_initial_size and i >= e_gaps1[j+step-1]: + */ + __pyx_v_j = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1348 + * for i from e_high <= i <= e_x_high: + * j = 0 + * while j < len1: # <<<<<<<<<<<<<< + * if i - e_gaps1[j] <= self.train_max_initial_size and i >= e_gaps1[j+step-1]: + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+j, step) + */ + while (1) { + __pyx_t_6 = (__pyx_v_j < __pyx_v_len1); + if (!__pyx_t_6) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1349 + * j = 0 + * while j < len1: + * if i - e_gaps1[j] <= self.train_max_initial_size and i >= e_gaps1[j+step-1]: # <<<<<<<<<<<<<< + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+j, step) + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &i, 1) + */ + __pyx_t_6 = ((__pyx_v_i - (__pyx_v_e_gaps1[__pyx_v_j])) <= __pyx_v_self->train_max_initial_size); + if (__pyx_t_6) { + __pyx_t_7 = (__pyx_v_i >= (__pyx_v_e_gaps1[((__pyx_v_j + __pyx_v_step) - 1)])); + __pyx_t_2 = __pyx_t_7; + } else { + __pyx_t_2 = __pyx_t_6; + } + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1350 + * while j < len1: + * if i - e_gaps1[j] <= self.train_max_initial_size and i >= e_gaps1[j+step-1]: + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+j, step) # <<<<<<<<<<<<<< + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &i, 1) + * j = j + step + */ + __pyx_v_e_gaps2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->int_arr_extend(__pyx_v_self, __pyx_v_e_gaps2, (&__pyx_v_len2), (__pyx_v_e_gaps1 + __pyx_v_j), __pyx_v_step); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1351 + * if i - e_gaps1[j] <= self.train_max_initial_size and i >= e_gaps1[j+step-1]: + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+j, step) + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &i, 1) # <<<<<<<<<<<<<< + * j = j + step + * free(e_gaps1) + */ + __pyx_v_e_gaps2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->int_arr_extend(__pyx_v_self, __pyx_v_e_gaps2, (&__pyx_v_len2), (&__pyx_v_i), 1); + goto __pyx_L37; + } + __pyx_L37:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1352 + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+j, step) + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &i, 1) + * j = j + step # <<<<<<<<<<<<<< + * free(e_gaps1) + * e_gaps1 = e_gaps2 + */ + __pyx_v_j = (__pyx_v_j + __pyx_v_step); + } + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1353 + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &i, 1) + * j = j + step + * free(e_gaps1) # <<<<<<<<<<<<<< + * e_gaps1 = e_gaps2 + * len1 = len2 + */ + free(__pyx_v_e_gaps1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1354 + * j = j + step + * free(e_gaps1) + * e_gaps1 = e_gaps2 # <<<<<<<<<<<<<< + * len1 = len2 + * + */ + __pyx_v_e_gaps1 = __pyx_v_e_gaps2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1355 + * free(e_gaps1) + * e_gaps1 = e_gaps2 + * len1 = len2 # <<<<<<<<<<<<<< + * + * step = (num_gaps+1)*2 + */ + __pyx_v_len1 = __pyx_v_len2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1357 + * len1 = len2 + * + * step = (num_gaps+1)*2 # <<<<<<<<<<<<<< + * i = 0 + * + */ + __pyx_v_step = ((__pyx_v_num_gaps + 1) * 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1358 + * + * step = (num_gaps+1)*2 + * i = 0 # <<<<<<<<<<<<<< + * + * while i < len1: + */ + __pyx_v_i = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1360 + * i = 0 + * + * while i < len1: # <<<<<<<<<<<<<< + * ephr_arr._clear() + * num_chunks = 0 + */ + while (1) { + __pyx_t_2 = (__pyx_v_i < __pyx_v_len1); + if (!__pyx_t_2) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1361 + * + * while i < len1: + * ephr_arr._clear() # <<<<<<<<<<<<<< + * num_chunks = 0 + * indexes = [] + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_ephr_arr->__pyx_vtab)->_clear(__pyx_v_ephr_arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1362 + * while i < len1: + * ephr_arr._clear() + * num_chunks = 0 # <<<<<<<<<<<<<< + * indexes = [] + * for j from 0 <= j < num_gaps+1: + */ + __pyx_v_num_chunks = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1363 + * ephr_arr._clear() + * num_chunks = 0 + * indexes = [] # <<<<<<<<<<<<<< + * for j from 0 <= j < num_gaps+1: + * if e_gaps1[i+2*j] < e_gaps1[i+(2*j)+1]: + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1363; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF(((PyObject *)__pyx_v_indexes)); + __pyx_v_indexes = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1364 + * num_chunks = 0 + * indexes = [] + * for j from 0 <= j < num_gaps+1: # <<<<<<<<<<<<<< + * if e_gaps1[i+2*j] < e_gaps1[i+(2*j)+1]: + * num_chunks = num_chunks + 1 + */ + __pyx_t_9 = (__pyx_v_num_gaps + 1); + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_9; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1365 + * indexes = [] + * for j from 0 <= j < num_gaps+1: + * if e_gaps1[i+2*j] < e_gaps1[i+(2*j)+1]: # <<<<<<<<<<<<<< + * num_chunks = num_chunks + 1 + * for k from e_gaps1[i+2*j] <= k < e_gaps1[i+(2*j)+1]: + */ + __pyx_t_2 = ((__pyx_v_e_gaps1[(__pyx_v_i + (2 * __pyx_v_j))]) < (__pyx_v_e_gaps1[((__pyx_v_i + (2 * __pyx_v_j)) + 1)])); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1366 + * for j from 0 <= j < num_gaps+1: + * if e_gaps1[i+2*j] < e_gaps1[i+(2*j)+1]: + * num_chunks = num_chunks + 1 # <<<<<<<<<<<<<< + * for k from e_gaps1[i+2*j] <= k < e_gaps1[i+(2*j)+1]: + * indexes.append(k) + */ + __pyx_v_num_chunks = (__pyx_v_num_chunks + 1); + goto __pyx_L42; + } + __pyx_L42:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1367 + * if e_gaps1[i+2*j] < e_gaps1[i+(2*j)+1]: + * num_chunks = num_chunks + 1 + * for k from e_gaps1[i+2*j] <= k < e_gaps1[i+(2*j)+1]: # <<<<<<<<<<<<<< + * indexes.append(k) + * ephr_arr._append(self.eid2symid[self.eda.data.arr[e_sent_start+k]]) + */ + __pyx_t_3 = (__pyx_v_e_gaps1[((__pyx_v_i + (2 * __pyx_v_j)) + 1)]); + for (__pyx_v_k = (__pyx_v_e_gaps1[(__pyx_v_i + (2 * __pyx_v_j))]); __pyx_v_k < __pyx_t_3; __pyx_v_k++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1368 + * num_chunks = num_chunks + 1 + * for k from e_gaps1[i+2*j] <= k < e_gaps1[i+(2*j)+1]: + * indexes.append(k) # <<<<<<<<<<<<<< + * ephr_arr._append(self.eid2symid[self.eda.data.arr[e_sent_start+k]]) + * if j < num_gaps: + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_k); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = PyList_Append(__pyx_v_indexes, __pyx_t_1); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1369 + * for k from e_gaps1[i+2*j] <= k < e_gaps1[i+(2*j)+1]: + * indexes.append(k) + * ephr_arr._append(self.eid2symid[self.eda.data.arr[e_sent_start+k]]) # <<<<<<<<<<<<<< + * if j < num_gaps: + * indexes.append(sym_setindex(self.category, e_gap_order[j]+1)) + */ + __pyx_t_4 = (__pyx_v_self->eda->data->arr[(__pyx_v_e_sent_start + __pyx_v_k)]); + __pyx_t_1 = __Pyx_GetItemInt(((PyObject *)__pyx_v_self->eid2symid), __pyx_t_4, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1369; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1369; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_ephr_arr->__pyx_vtab)->_append(__pyx_v_ephr_arr, __pyx_t_4); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1370 + * indexes.append(k) + * ephr_arr._append(self.eid2symid[self.eda.data.arr[e_sent_start+k]]) + * if j < num_gaps: # <<<<<<<<<<<<<< + * indexes.append(sym_setindex(self.category, e_gap_order[j]+1)) + * ephr_arr._append(sym_setindex(self.category, e_gap_order[j]+1)) + */ + __pyx_t_2 = (__pyx_v_j < __pyx_v_num_gaps); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1371 + * ephr_arr._append(self.eid2symid[self.eda.data.arr[e_sent_start+k]]) + * if j < num_gaps: + * indexes.append(sym_setindex(self.category, e_gap_order[j]+1)) # <<<<<<<<<<<<<< + * ephr_arr._append(sym_setindex(self.category, e_gap_order[j]+1)) + * i = i + step + */ + __pyx_t_1 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, ((__pyx_v_e_gap_order[__pyx_v_j]) + 1))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = PyList_Append(__pyx_v_indexes, __pyx_t_1); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1372 + * if j < num_gaps: + * indexes.append(sym_setindex(self.category, e_gap_order[j]+1)) + * ephr_arr._append(sym_setindex(self.category, e_gap_order[j]+1)) # <<<<<<<<<<<<<< + * i = i + step + * if ephr_arr.len <= self.max_target_length and num_chunks <= self.max_target_chunks: + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_ephr_arr->__pyx_vtab)->_append(__pyx_v_ephr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, ((__pyx_v_e_gap_order[__pyx_v_j]) + 1))); + goto __pyx_L45; + } + __pyx_L45:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1373 + * indexes.append(sym_setindex(self.category, e_gap_order[j]+1)) + * ephr_arr._append(sym_setindex(self.category, e_gap_order[j]+1)) + * i = i + step # <<<<<<<<<<<<<< + * if ephr_arr.len <= self.max_target_length and num_chunks <= self.max_target_chunks: + * result.append((Phrase(ephr_arr),indexes)) + */ + __pyx_v_i = (__pyx_v_i + __pyx_v_step); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1374 + * ephr_arr._append(sym_setindex(self.category, e_gap_order[j]+1)) + * i = i + step + * if ephr_arr.len <= self.max_target_length and num_chunks <= self.max_target_chunks: # <<<<<<<<<<<<<< + * result.append((Phrase(ephr_arr),indexes)) + * + */ + __pyx_t_2 = (__pyx_v_ephr_arr->len <= __pyx_v_self->max_target_length); + if (__pyx_t_2) { + __pyx_t_6 = (__pyx_v_num_chunks <= __pyx_v_self->max_target_chunks); + __pyx_t_7 = __pyx_t_6; + } else { + __pyx_t_7 = __pyx_t_2; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1375 + * i = i + step + * if ephr_arr.len <= self.max_target_length and num_chunks <= self.max_target_chunks: + * result.append((Phrase(ephr_arr),indexes)) # <<<<<<<<<<<<<< + * + * free(e_gaps1) + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1375; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_ephr_arr)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_ephr_arr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_ephr_arr)); + __pyx_t_11 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1375; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1375; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_11); + __Pyx_GIVEREF(__pyx_t_11); + __Pyx_INCREF(((PyObject *)__pyx_v_indexes)); + PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_indexes)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_indexes)); + __pyx_t_11 = 0; + __pyx_t_11 = __Pyx_PyObject_Append(__pyx_v_result, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1375; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L46; + } + __pyx_L46:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1377 + * result.append((Phrase(ephr_arr),indexes)) + * + * free(e_gaps1) # <<<<<<<<<<<<<< + * free(e_gap_order) + * return result + */ + free(__pyx_v_e_gaps1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1378 + * + * free(e_gaps1) + * free(e_gap_order) # <<<<<<<<<<<<<< + * return result + * + */ + free(__pyx_v_e_gap_order); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1379 + * free(e_gaps1) + * free(e_gap_order) + * return result # <<<<<<<<<<<<<< + * + * cdef create_alignments(self, int* sent_links, int num_links, findexes, eindexes): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + 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_11); + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.extract_phrases", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_ephr_arr); + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_indexes); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1381 + * return result + * + * cdef create_alignments(self, int* sent_links, int num_links, findexes, eindexes): # <<<<<<<<<<<<<< + * cdef unsigned i + * ret = IntList() + */ + +static PyObject *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_create_alignments(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, int *__pyx_v_sent_links, int __pyx_v_num_links, PyObject *__pyx_v_findexes, PyObject *__pyx_v_eindexes) { + unsigned int __pyx_v_i; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_ret = NULL; + PyObject *__pyx_v_s = NULL; + PyObject *__pyx_v_idx = NULL; + PyObject *__pyx_v_j = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + unsigned int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + Py_ssize_t __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("create_alignments", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1383 + * cdef create_alignments(self, int* sent_links, int num_links, findexes, eindexes): + * cdef unsigned i + * ret = IntList() # <<<<<<<<<<<<<< + * for i in range(len(findexes)): + * s = findexes[i] + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_ret = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1384 + * cdef unsigned i + * ret = IntList() + * for i in range(len(findexes)): # <<<<<<<<<<<<<< + * s = findexes[i] + * if (s<0): + */ + __pyx_t_2 = PyObject_Length(__pyx_v_findexes); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1384; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1385 + * ret = IntList() + * for i in range(len(findexes)): + * s = findexes[i] # <<<<<<<<<<<<<< + * if (s<0): + * continue + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_findexes, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1385; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_s); + __pyx_v_s = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1386 + * for i in range(len(findexes)): + * s = findexes[i] + * if (s<0): # <<<<<<<<<<<<<< + * continue + * idx = 0 + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_v_s, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1387 + * s = findexes[i] + * if (s<0): + * continue # <<<<<<<<<<<<<< + * idx = 0 + * while (idx < num_links*2): + */ + goto __pyx_L3_continue; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1388 + * if (s<0): + * continue + * idx = 0 # <<<<<<<<<<<<<< + * while (idx < num_links*2): + * if (sent_links[idx] == s): + */ + __Pyx_INCREF(__pyx_int_0); + __Pyx_XDECREF(__pyx_v_idx); + __pyx_v_idx = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1389 + * continue + * idx = 0 + * while (idx < num_links*2): # <<<<<<<<<<<<<< + * if (sent_links[idx] == s): + * j = eindexes.index(sent_links[idx+1]) + */ + while (1) { + __pyx_t_1 = PyInt_FromLong((__pyx_v_num_links * 2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_idx, __pyx_t_1, Py_LT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (!__pyx_t_4) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1390 + * idx = 0 + * while (idx < num_links*2): + * if (sent_links[idx] == s): # <<<<<<<<<<<<<< + * j = eindexes.index(sent_links[idx+1]) + * ret.append(i*65536+j) + */ + __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_idx); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyInt_FromLong((__pyx_v_sent_links[__pyx_t_6])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyObject_RichCompare(__pyx_t_5, __pyx_v_s, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1391 + * while (idx < num_links*2): + * if (sent_links[idx] == s): + * j = eindexes.index(sent_links[idx+1]) # <<<<<<<<<<<<<< + * ret.append(i*65536+j) + * idx += 2 + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_eindexes, __pyx_n_s__index); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyNumber_Add(__pyx_v_idx, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_t_5); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyInt_FromLong((__pyx_v_sent_links[__pyx_t_6])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_v_j); + __pyx_v_j = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1392 + * if (sent_links[idx] == s): + * j = eindexes.index(sent_links[idx+1]) + * ret.append(i*65536+j) # <<<<<<<<<<<<<< + * idx += 2 + * return ret + */ + __pyx_t_5 = PyInt_FromLong((__pyx_v_i * 65536)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = PyNumber_Add(__pyx_t_5, __pyx_v_j); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_ret), __pyx_t_7); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L8; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1393 + * j = eindexes.index(sent_links[idx+1]) + * ret.append(i*65536+j) + * idx += 2 # <<<<<<<<<<<<<< + * return ret + * + */ + __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_idx, __pyx_int_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_v_idx); + __pyx_v_idx = __pyx_t_5; + __pyx_t_5 = 0; + } + __pyx_L3_continue:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1394 + * ret.append(i*65536+j) + * idx += 2 + * return ret # <<<<<<<<<<<<<< + * + * cdef extract(self, Phrase phrase, Matching* matching, int* chunklen, int num_chunks): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_ret)); + __pyx_r = ((PyObject *)__pyx_v_ret); + 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_5); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.create_alignments", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_ret); + __Pyx_XDECREF(__pyx_v_s); + __Pyx_XDECREF(__pyx_v_idx); + __Pyx_XDECREF(__pyx_v_j); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1396 + * return ret + * + * cdef extract(self, Phrase phrase, Matching* matching, int* chunklen, int num_chunks): # <<<<<<<<<<<<<< + * cdef int* sent_links, *e_links_low, *e_links_high, *f_links_low, *f_links_high + * cdef int *f_gap_low, *f_gap_high, *e_gap_low, *e_gap_high, num_gaps, gap_start + */ + +static PyObject *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_extract(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_phrase, struct __pyx_t_8_cdec_sa_Matching *__pyx_v_matching, int *__pyx_v_chunklen, int __pyx_v_num_chunks) { + int *__pyx_v_sent_links; + int *__pyx_v_e_links_low; + int *__pyx_v_e_links_high; + int *__pyx_v_f_links_low; + int *__pyx_v_f_links_high; + int *__pyx_v_f_gap_low; + int *__pyx_v_f_gap_high; + int *__pyx_v_e_gap_low; + int *__pyx_v_e_gap_high; + int __pyx_v_num_gaps; + int __pyx_v_gap_start; + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_e_i; + int __pyx_v_f_i; + int __pyx_v_num_links; + int __pyx_v_num_aligned_chunks; + int __pyx_v_met_constraints; + int __pyx_v_x; + int __pyx_v_f_low; + int __pyx_v_f_high; + int __pyx_v_e_low; + int __pyx_v_e_high; + int __pyx_v_f_back_low; + int __pyx_v_f_back_high; + int __pyx_v_e_sent_start; + int __pyx_v_e_sent_end; + int __pyx_v_f_sent_start; + int __pyx_v_f_sent_end; + int __pyx_v_e_sent_len; + int __pyx_v_f_sent_len; + CYTHON_UNUSED int __pyx_v_e_word_count; + int __pyx_v_f_x_low; + int __pyx_v_f_x_high; + int __pyx_v_e_x_low; + int __pyx_v_e_x_high; + int __pyx_v_phrase_len; + float __pyx_v_pair_count; + PyObject *__pyx_v_extracts = 0; + PyObject *__pyx_v_phrase_list = 0; + struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_fphr_arr = 0; + struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_fphr = 0; + CYTHON_UNUSED PyObject *__pyx_v_reason_for_failure = 0; + PyObject *__pyx_v_sofar = NULL; + PyObject *__pyx_v_als = NULL; + PyObject *__pyx_v_al = NULL; + long __pyx_v_gap_error; + PyObject *__pyx_v_phrase2 = NULL; + PyObject *__pyx_v_eindexes = NULL; + PyObject *__pyx_v_als1 = NULL; + PyObject *__pyx_v_als2 = NULL; + PyObject *__pyx_v_als3 = NULL; + PyObject *__pyx_v_als4 = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + long __pyx_t_12; + Py_ssize_t __pyx_t_13; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + PyObject *(*__pyx_t_16)(PyObject *); + PyObject *(*__pyx_t_17)(PyObject *); + int __pyx_t_18; + int __pyx_t_19; + int __pyx_t_20; + int __pyx_t_21; + int __pyx_t_22; + int __pyx_t_23; + int __pyx_t_24; + int __pyx_t_25; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("extract", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1409 + * cdef reason_for_failure + * + * fphr_arr = IntList() # <<<<<<<<<<<<<< + * phrase_len = phrase.n + * extracts = [] + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_fphr_arr = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1410 + * + * fphr_arr = IntList() + * phrase_len = phrase.n # <<<<<<<<<<<<<< + * extracts = [] + * sent_links = self.alignment._get_sent_links(matching.sent_id, &num_links) + */ + __pyx_v_phrase_len = __pyx_v_phrase->n; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1411 + * fphr_arr = IntList() + * phrase_len = phrase.n + * extracts = [] # <<<<<<<<<<<<<< + * sent_links = self.alignment._get_sent_links(matching.sent_id, &num_links) + * + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1411; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_extracts = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1412 + * phrase_len = phrase.n + * extracts = [] + * sent_links = self.alignment._get_sent_links(matching.sent_id, &num_links) # <<<<<<<<<<<<<< + * + * e_sent_start = self.eda.sent_index.arr[matching.sent_id] + */ + __pyx_v_sent_links = ((struct __pyx_vtabstruct_8_cdec_sa_Alignment *)__pyx_v_self->alignment->__pyx_vtab)->_get_sent_links(__pyx_v_self->alignment, __pyx_v_matching->sent_id, (&__pyx_v_num_links)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1414 + * sent_links = self.alignment._get_sent_links(matching.sent_id, &num_links) + * + * e_sent_start = self.eda.sent_index.arr[matching.sent_id] # <<<<<<<<<<<<<< + * e_sent_end = self.eda.sent_index.arr[matching.sent_id+1] + * e_sent_len = e_sent_end - e_sent_start - 1 + */ + __pyx_v_e_sent_start = (__pyx_v_self->eda->sent_index->arr[__pyx_v_matching->sent_id]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1415 + * + * e_sent_start = self.eda.sent_index.arr[matching.sent_id] + * e_sent_end = self.eda.sent_index.arr[matching.sent_id+1] # <<<<<<<<<<<<<< + * e_sent_len = e_sent_end - e_sent_start - 1 + * f_sent_start = self.fda.sent_index.arr[matching.sent_id] + */ + __pyx_v_e_sent_end = (__pyx_v_self->eda->sent_index->arr[(__pyx_v_matching->sent_id + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1416 + * e_sent_start = self.eda.sent_index.arr[matching.sent_id] + * e_sent_end = self.eda.sent_index.arr[matching.sent_id+1] + * e_sent_len = e_sent_end - e_sent_start - 1 # <<<<<<<<<<<<<< + * f_sent_start = self.fda.sent_index.arr[matching.sent_id] + * f_sent_end = self.fda.sent_index.arr[matching.sent_id+1] + */ + __pyx_v_e_sent_len = ((__pyx_v_e_sent_end - __pyx_v_e_sent_start) - 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1417 + * e_sent_end = self.eda.sent_index.arr[matching.sent_id+1] + * e_sent_len = e_sent_end - e_sent_start - 1 + * f_sent_start = self.fda.sent_index.arr[matching.sent_id] # <<<<<<<<<<<<<< + * f_sent_end = self.fda.sent_index.arr[matching.sent_id+1] + * f_sent_len = f_sent_end - f_sent_start - 1 + */ + __pyx_v_f_sent_start = (__pyx_v_self->fda->sent_index->arr[__pyx_v_matching->sent_id]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1418 + * e_sent_len = e_sent_end - e_sent_start - 1 + * f_sent_start = self.fda.sent_index.arr[matching.sent_id] + * f_sent_end = self.fda.sent_index.arr[matching.sent_id+1] # <<<<<<<<<<<<<< + * f_sent_len = f_sent_end - f_sent_start - 1 + * + */ + __pyx_v_f_sent_end = (__pyx_v_self->fda->sent_index->arr[(__pyx_v_matching->sent_id + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1419 + * f_sent_start = self.fda.sent_index.arr[matching.sent_id] + * f_sent_end = self.fda.sent_index.arr[matching.sent_id+1] + * f_sent_len = f_sent_end - f_sent_start - 1 # <<<<<<<<<<<<<< + * + * self.findexes1.reset() + */ + __pyx_v_f_sent_len = ((__pyx_v_f_sent_end - __pyx_v_f_sent_start) - 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1421 + * f_sent_len = f_sent_end - f_sent_start - 1 + * + * self.findexes1.reset() # <<<<<<<<<<<<<< + * sofar = 0 + * for i in range(num_chunks): + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes1), __pyx_n_s__reset); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1422 + * + * self.findexes1.reset() + * sofar = 0 # <<<<<<<<<<<<<< + * for i in range(num_chunks): + * for j in range(chunklen[i]): + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_sofar = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1423 + * self.findexes1.reset() + * sofar = 0 + * for i in range(num_chunks): # <<<<<<<<<<<<<< + * for j in range(chunklen[i]): + * self.findexes1.append(matching.arr[matching.start+i]+j-f_sent_start); + */ + __pyx_t_3 = __pyx_v_num_chunks; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_i = __pyx_t_4; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1424 + * sofar = 0 + * for i in range(num_chunks): + * for j in range(chunklen[i]): # <<<<<<<<<<<<<< + * self.findexes1.append(matching.arr[matching.start+i]+j-f_sent_start); + * sofar += 1 + */ + __pyx_t_5 = (__pyx_v_chunklen[__pyx_v_i]); + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_v_j = __pyx_t_6; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1425 + * for i in range(num_chunks): + * for j in range(chunklen[i]): + * self.findexes1.append(matching.arr[matching.start+i]+j-f_sent_start); # <<<<<<<<<<<<<< + * sofar += 1 + * if (i+1arr[(__pyx_v_matching->start + __pyx_v_i)]) + __pyx_v_j) - __pyx_v_f_sent_start)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1425; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes1), __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1425; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1426 + * for j in range(chunklen[i]): + * self.findexes1.append(matching.arr[matching.start+i]+j-f_sent_start); + * sofar += 1 # <<<<<<<<<<<<<< + * if (i+1findexes1), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1429 + * if (i+1 malloc(e_sent_len*sizeof(int)) # <<<<<<<<<<<<<< + * e_links_high = malloc(e_sent_len*sizeof(int)) + * f_links_low = malloc(f_sent_len*sizeof(int)) + */ + __pyx_v_e_links_low = ((int *)malloc((__pyx_v_e_sent_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1433 + * + * e_links_low = malloc(e_sent_len*sizeof(int)) + * e_links_high = malloc(e_sent_len*sizeof(int)) # <<<<<<<<<<<<<< + * f_links_low = malloc(f_sent_len*sizeof(int)) + * f_links_high = malloc(f_sent_len*sizeof(int)) + */ + __pyx_v_e_links_high = ((int *)malloc((__pyx_v_e_sent_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1434 + * e_links_low = malloc(e_sent_len*sizeof(int)) + * e_links_high = malloc(e_sent_len*sizeof(int)) + * f_links_low = malloc(f_sent_len*sizeof(int)) # <<<<<<<<<<<<<< + * f_links_high = malloc(f_sent_len*sizeof(int)) + * f_gap_low = malloc((num_chunks+1)*sizeof(int)) + */ + __pyx_v_f_links_low = ((int *)malloc((__pyx_v_f_sent_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1435 + * e_links_high = malloc(e_sent_len*sizeof(int)) + * f_links_low = malloc(f_sent_len*sizeof(int)) + * f_links_high = malloc(f_sent_len*sizeof(int)) # <<<<<<<<<<<<<< + * f_gap_low = malloc((num_chunks+1)*sizeof(int)) + * f_gap_high = malloc((num_chunks+1)*sizeof(int)) + */ + __pyx_v_f_links_high = ((int *)malloc((__pyx_v_f_sent_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1436 + * f_links_low = malloc(f_sent_len*sizeof(int)) + * f_links_high = malloc(f_sent_len*sizeof(int)) + * f_gap_low = malloc((num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< + * f_gap_high = malloc((num_chunks+1)*sizeof(int)) + * e_gap_low = malloc((num_chunks+1)*sizeof(int)) + */ + __pyx_v_f_gap_low = ((int *)malloc(((__pyx_v_num_chunks + 1) * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1437 + * f_links_high = malloc(f_sent_len*sizeof(int)) + * f_gap_low = malloc((num_chunks+1)*sizeof(int)) + * f_gap_high = malloc((num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< + * e_gap_low = malloc((num_chunks+1)*sizeof(int)) + * e_gap_high = malloc((num_chunks+1)*sizeof(int)) + */ + __pyx_v_f_gap_high = ((int *)malloc(((__pyx_v_num_chunks + 1) * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1438 + * f_gap_low = malloc((num_chunks+1)*sizeof(int)) + * f_gap_high = malloc((num_chunks+1)*sizeof(int)) + * e_gap_low = malloc((num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< + * e_gap_high = malloc((num_chunks+1)*sizeof(int)) + * memset(f_gap_low, 0, (num_chunks+1)*sizeof(int)) + */ + __pyx_v_e_gap_low = ((int *)malloc(((__pyx_v_num_chunks + 1) * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1439 + * f_gap_high = malloc((num_chunks+1)*sizeof(int)) + * e_gap_low = malloc((num_chunks+1)*sizeof(int)) + * e_gap_high = malloc((num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< + * memset(f_gap_low, 0, (num_chunks+1)*sizeof(int)) + * memset(f_gap_high, 0, (num_chunks+1)*sizeof(int)) + */ + __pyx_v_e_gap_high = ((int *)malloc(((__pyx_v_num_chunks + 1) * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1440 + * e_gap_low = malloc((num_chunks+1)*sizeof(int)) + * e_gap_high = malloc((num_chunks+1)*sizeof(int)) + * memset(f_gap_low, 0, (num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< + * memset(f_gap_high, 0, (num_chunks+1)*sizeof(int)) + * memset(e_gap_low, 0, (num_chunks+1)*sizeof(int)) + */ + memset(__pyx_v_f_gap_low, 0, ((__pyx_v_num_chunks + 1) * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1441 + * e_gap_high = malloc((num_chunks+1)*sizeof(int)) + * memset(f_gap_low, 0, (num_chunks+1)*sizeof(int)) + * memset(f_gap_high, 0, (num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< + * memset(e_gap_low, 0, (num_chunks+1)*sizeof(int)) + * memset(e_gap_high, 0, (num_chunks+1)*sizeof(int)) + */ + memset(__pyx_v_f_gap_high, 0, ((__pyx_v_num_chunks + 1) * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1442 + * memset(f_gap_low, 0, (num_chunks+1)*sizeof(int)) + * memset(f_gap_high, 0, (num_chunks+1)*sizeof(int)) + * memset(e_gap_low, 0, (num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< + * memset(e_gap_high, 0, (num_chunks+1)*sizeof(int)) + * + */ + memset(__pyx_v_e_gap_low, 0, ((__pyx_v_num_chunks + 1) * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1443 + * memset(f_gap_high, 0, (num_chunks+1)*sizeof(int)) + * memset(e_gap_low, 0, (num_chunks+1)*sizeof(int)) + * memset(e_gap_high, 0, (num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< + * + * reason_for_failure = "" + */ + memset(__pyx_v_e_gap_high, 0, ((__pyx_v_num_chunks + 1) * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1445 + * memset(e_gap_high, 0, (num_chunks+1)*sizeof(int)) + * + * reason_for_failure = "" # <<<<<<<<<<<<<< + * + * for i from 0 <= i < e_sent_len: + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_42)); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_42); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1447 + * reason_for_failure = "" + * + * for i from 0 <= i < e_sent_len: # <<<<<<<<<<<<<< + * e_links_low[i] = -1 + * e_links_high[i] = -1 + */ + __pyx_t_3 = __pyx_v_e_sent_len; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1448 + * + * for i from 0 <= i < e_sent_len: + * e_links_low[i] = -1 # <<<<<<<<<<<<<< + * e_links_high[i] = -1 + * for i from 0 <= i < f_sent_len: + */ + (__pyx_v_e_links_low[__pyx_v_i]) = -1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1449 + * for i from 0 <= i < e_sent_len: + * e_links_low[i] = -1 + * e_links_high[i] = -1 # <<<<<<<<<<<<<< + * for i from 0 <= i < f_sent_len: + * f_links_low[i] = -1 + */ + (__pyx_v_e_links_high[__pyx_v_i]) = -1; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1450 + * e_links_low[i] = -1 + * e_links_high[i] = -1 + * for i from 0 <= i < f_sent_len: # <<<<<<<<<<<<<< + * f_links_low[i] = -1 + * f_links_high[i] = -1 + */ + __pyx_t_3 = __pyx_v_f_sent_len; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1451 + * e_links_high[i] = -1 + * for i from 0 <= i < f_sent_len: + * f_links_low[i] = -1 # <<<<<<<<<<<<<< + * f_links_high[i] = -1 + * + */ + (__pyx_v_f_links_low[__pyx_v_i]) = -1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1452 + * for i from 0 <= i < f_sent_len: + * f_links_low[i] = -1 + * f_links_high[i] = -1 # <<<<<<<<<<<<<< + * + * # this is really inefficient -- might be good to + */ + (__pyx_v_f_links_high[__pyx_v_i]) = -1; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1458 + * # links that we care about (but then how to look up + * # when we want to check something on the e side?) + * i = 0 # <<<<<<<<<<<<<< + * while i < num_links*2: + * f_i = sent_links[i] + */ + __pyx_v_i = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1459 + * # when we want to check something on the e side?) + * i = 0 + * while i < num_links*2: # <<<<<<<<<<<<<< + * f_i = sent_links[i] + * e_i = sent_links[i+1] + */ + while (1) { + __pyx_t_7 = (__pyx_v_i < (__pyx_v_num_links * 2)); + if (!__pyx_t_7) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1460 + * i = 0 + * while i < num_links*2: + * f_i = sent_links[i] # <<<<<<<<<<<<<< + * e_i = sent_links[i+1] + * if f_links_low[f_i] == -1 or f_links_low[f_i] > e_i: + */ + __pyx_v_f_i = (__pyx_v_sent_links[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1461 + * while i < num_links*2: + * f_i = sent_links[i] + * e_i = sent_links[i+1] # <<<<<<<<<<<<<< + * if f_links_low[f_i] == -1 or f_links_low[f_i] > e_i: + * f_links_low[f_i] = e_i + */ + __pyx_v_e_i = (__pyx_v_sent_links[(__pyx_v_i + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1462 + * f_i = sent_links[i] + * e_i = sent_links[i+1] + * if f_links_low[f_i] == -1 or f_links_low[f_i] > e_i: # <<<<<<<<<<<<<< + * f_links_low[f_i] = e_i + * if f_links_high[f_i] == -1 or f_links_high[f_i] < e_i + 1: + */ + __pyx_t_7 = ((__pyx_v_f_links_low[__pyx_v_f_i]) == -1); + if (!__pyx_t_7) { + __pyx_t_8 = ((__pyx_v_f_links_low[__pyx_v_f_i]) > __pyx_v_e_i); + __pyx_t_9 = __pyx_t_8; + } else { + __pyx_t_9 = __pyx_t_7; + } + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1463 + * e_i = sent_links[i+1] + * if f_links_low[f_i] == -1 or f_links_low[f_i] > e_i: + * f_links_low[f_i] = e_i # <<<<<<<<<<<<<< + * if f_links_high[f_i] == -1 or f_links_high[f_i] < e_i + 1: + * f_links_high[f_i] = e_i + 1 + */ + (__pyx_v_f_links_low[__pyx_v_f_i]) = __pyx_v_e_i; + goto __pyx_L14; + } + __pyx_L14:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1464 + * if f_links_low[f_i] == -1 or f_links_low[f_i] > e_i: + * f_links_low[f_i] = e_i + * if f_links_high[f_i] == -1 or f_links_high[f_i] < e_i + 1: # <<<<<<<<<<<<<< + * f_links_high[f_i] = e_i + 1 + * if e_links_low[e_i] == -1 or e_links_low[e_i] > f_i: + */ + __pyx_t_9 = ((__pyx_v_f_links_high[__pyx_v_f_i]) == -1); + if (!__pyx_t_9) { + __pyx_t_7 = ((__pyx_v_f_links_high[__pyx_v_f_i]) < (__pyx_v_e_i + 1)); + __pyx_t_8 = __pyx_t_7; + } else { + __pyx_t_8 = __pyx_t_9; + } + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1465 + * f_links_low[f_i] = e_i + * if f_links_high[f_i] == -1 or f_links_high[f_i] < e_i + 1: + * f_links_high[f_i] = e_i + 1 # <<<<<<<<<<<<<< + * if e_links_low[e_i] == -1 or e_links_low[e_i] > f_i: + * e_links_low[e_i] = f_i + */ + (__pyx_v_f_links_high[__pyx_v_f_i]) = (__pyx_v_e_i + 1); + goto __pyx_L15; + } + __pyx_L15:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1466 + * if f_links_high[f_i] == -1 or f_links_high[f_i] < e_i + 1: + * f_links_high[f_i] = e_i + 1 + * if e_links_low[e_i] == -1 or e_links_low[e_i] > f_i: # <<<<<<<<<<<<<< + * e_links_low[e_i] = f_i + * if e_links_high[e_i] == -1 or e_links_high[e_i] < f_i + 1: + */ + __pyx_t_8 = ((__pyx_v_e_links_low[__pyx_v_e_i]) == -1); + if (!__pyx_t_8) { + __pyx_t_9 = ((__pyx_v_e_links_low[__pyx_v_e_i]) > __pyx_v_f_i); + __pyx_t_7 = __pyx_t_9; + } else { + __pyx_t_7 = __pyx_t_8; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1467 + * f_links_high[f_i] = e_i + 1 + * if e_links_low[e_i] == -1 or e_links_low[e_i] > f_i: + * e_links_low[e_i] = f_i # <<<<<<<<<<<<<< + * if e_links_high[e_i] == -1 or e_links_high[e_i] < f_i + 1: + * e_links_high[e_i] = f_i + 1 + */ + (__pyx_v_e_links_low[__pyx_v_e_i]) = __pyx_v_f_i; + goto __pyx_L16; + } + __pyx_L16:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1468 + * if e_links_low[e_i] == -1 or e_links_low[e_i] > f_i: + * e_links_low[e_i] = f_i + * if e_links_high[e_i] == -1 or e_links_high[e_i] < f_i + 1: # <<<<<<<<<<<<<< + * e_links_high[e_i] = f_i + 1 + * i = i + 2 + */ + __pyx_t_7 = ((__pyx_v_e_links_high[__pyx_v_e_i]) == -1); + if (!__pyx_t_7) { + __pyx_t_8 = ((__pyx_v_e_links_high[__pyx_v_e_i]) < (__pyx_v_f_i + 1)); + __pyx_t_9 = __pyx_t_8; + } else { + __pyx_t_9 = __pyx_t_7; + } + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1469 + * e_links_low[e_i] = f_i + * if e_links_high[e_i] == -1 or e_links_high[e_i] < f_i + 1: + * e_links_high[e_i] = f_i + 1 # <<<<<<<<<<<<<< + * i = i + 2 + * + */ + (__pyx_v_e_links_high[__pyx_v_e_i]) = (__pyx_v_f_i + 1); + goto __pyx_L17; + } + __pyx_L17:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1470 + * if e_links_high[e_i] == -1 or e_links_high[e_i] < f_i + 1: + * e_links_high[e_i] = f_i + 1 + * i = i + 2 # <<<<<<<<<<<<<< + * + * als = [] + */ + __pyx_v_i = (__pyx_v_i + 2); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1472 + * i = i + 2 + * + * als = [] # <<<<<<<<<<<<<< + * for x in range(matching.start,matching.end): + * al = (matching.arr[x]-f_sent_start,f_links_low[matching.arr[x]-f_sent_start]) + */ + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1472; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_als = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1473 + * + * als = [] + * for x in range(matching.start,matching.end): # <<<<<<<<<<<<<< + * al = (matching.arr[x]-f_sent_start,f_links_low[matching.arr[x]-f_sent_start]) + * als.append(al) + */ + __pyx_t_3 = __pyx_v_matching->end; + for (__pyx_t_4 = __pyx_v_matching->start; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_x = __pyx_t_4; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1474 + * als = [] + * for x in range(matching.start,matching.end): + * al = (matching.arr[x]-f_sent_start,f_links_low[matching.arr[x]-f_sent_start]) # <<<<<<<<<<<<<< + * als.append(al) + * # check all source-side alignment constraints + */ + __pyx_t_2 = PyInt_FromLong(((__pyx_v_matching->arr[__pyx_v_x]) - __pyx_v_f_sent_start)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1474; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyInt_FromLong((__pyx_v_f_links_low[((__pyx_v_matching->arr[__pyx_v_x]) - __pyx_v_f_sent_start)])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1474; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1474; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __Pyx_XDECREF(((PyObject *)__pyx_v_al)); + __pyx_v_al = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1475 + * for x in range(matching.start,matching.end): + * al = (matching.arr[x]-f_sent_start,f_links_low[matching.arr[x]-f_sent_start]) + * als.append(al) # <<<<<<<<<<<<<< + * # check all source-side alignment constraints + * met_constraints = 1 + */ + __pyx_t_11 = PyList_Append(__pyx_v_als, ((PyObject *)__pyx_v_al)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1475; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1477 + * als.append(al) + * # check all source-side alignment constraints + * met_constraints = 1 # <<<<<<<<<<<<<< + * if self.require_aligned_terminal: + * num_aligned_chunks = 0 + */ + __pyx_v_met_constraints = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1478 + * # check all source-side alignment constraints + * met_constraints = 1 + * if self.require_aligned_terminal: # <<<<<<<<<<<<<< + * num_aligned_chunks = 0 + * for i from 0 <= i < num_chunks: + */ + if (__pyx_v_self->require_aligned_terminal) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1479 + * met_constraints = 1 + * if self.require_aligned_terminal: + * num_aligned_chunks = 0 # <<<<<<<<<<<<<< + * for i from 0 <= i < num_chunks: + * for j from 0 <= j < chunklen[i]: + */ + __pyx_v_num_aligned_chunks = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1480 + * if self.require_aligned_terminal: + * num_aligned_chunks = 0 + * for i from 0 <= i < num_chunks: # <<<<<<<<<<<<<< + * for j from 0 <= j < chunklen[i]: + * if f_links_low[matching.arr[matching.start+i]+j-f_sent_start] > -1: + */ + __pyx_t_3 = __pyx_v_num_chunks; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1481 + * num_aligned_chunks = 0 + * for i from 0 <= i < num_chunks: + * for j from 0 <= j < chunklen[i]: # <<<<<<<<<<<<<< + * if f_links_low[matching.arr[matching.start+i]+j-f_sent_start] > -1: + * num_aligned_chunks = num_aligned_chunks + 1 + */ + __pyx_t_4 = (__pyx_v_chunklen[__pyx_v_i]); + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_4; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1482 + * for i from 0 <= i < num_chunks: + * for j from 0 <= j < chunklen[i]: + * if f_links_low[matching.arr[matching.start+i]+j-f_sent_start] > -1: # <<<<<<<<<<<<<< + * num_aligned_chunks = num_aligned_chunks + 1 + * break + */ + __pyx_t_9 = ((__pyx_v_f_links_low[(((__pyx_v_matching->arr[(__pyx_v_matching->start + __pyx_v_i)]) + __pyx_v_j) - __pyx_v_f_sent_start)]) > -1); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1483 + * for j from 0 <= j < chunklen[i]: + * if f_links_low[matching.arr[matching.start+i]+j-f_sent_start] > -1: + * num_aligned_chunks = num_aligned_chunks + 1 # <<<<<<<<<<<<<< + * break + * if num_aligned_chunks == 0: + */ + __pyx_v_num_aligned_chunks = (__pyx_v_num_aligned_chunks + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1484 + * if f_links_low[matching.arr[matching.start+i]+j-f_sent_start] > -1: + * num_aligned_chunks = num_aligned_chunks + 1 + * break # <<<<<<<<<<<<<< + * if num_aligned_chunks == 0: + * reason_for_failure = "No aligned terminals" + */ + goto __pyx_L24_break; + goto __pyx_L25; + } + __pyx_L25:; + } + __pyx_L24_break:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1485 + * num_aligned_chunks = num_aligned_chunks + 1 + * break + * if num_aligned_chunks == 0: # <<<<<<<<<<<<<< + * reason_for_failure = "No aligned terminals" + * met_constraints = 0 + */ + __pyx_t_9 = (__pyx_v_num_aligned_chunks == 0); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1486 + * break + * if num_aligned_chunks == 0: + * reason_for_failure = "No aligned terminals" # <<<<<<<<<<<<<< + * met_constraints = 0 + * if self.require_aligned_chunks and num_aligned_chunks < num_chunks: + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_124)); + __Pyx_DECREF(__pyx_v_reason_for_failure); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_124); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1487 + * if num_aligned_chunks == 0: + * reason_for_failure = "No aligned terminals" + * met_constraints = 0 # <<<<<<<<<<<<<< + * if self.require_aligned_chunks and num_aligned_chunks < num_chunks: + * reason_for_failure = "Unaligned chunk" + */ + __pyx_v_met_constraints = 0; + goto __pyx_L26; + } + __pyx_L26:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1488 + * reason_for_failure = "No aligned terminals" + * met_constraints = 0 + * if self.require_aligned_chunks and num_aligned_chunks < num_chunks: # <<<<<<<<<<<<<< + * reason_for_failure = "Unaligned chunk" + * met_constraints = 0 + */ + if (__pyx_v_self->require_aligned_chunks) { + __pyx_t_9 = (__pyx_v_num_aligned_chunks < __pyx_v_num_chunks); + __pyx_t_7 = __pyx_t_9; + } else { + __pyx_t_7 = __pyx_v_self->require_aligned_chunks; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1489 + * met_constraints = 0 + * if self.require_aligned_chunks and num_aligned_chunks < num_chunks: + * reason_for_failure = "Unaligned chunk" # <<<<<<<<<<<<<< + * met_constraints = 0 + * + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_125)); + __Pyx_DECREF(__pyx_v_reason_for_failure); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_125); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1490 + * if self.require_aligned_chunks and num_aligned_chunks < num_chunks: + * reason_for_failure = "Unaligned chunk" + * met_constraints = 0 # <<<<<<<<<<<<<< + * + * if met_constraints and self.tight_phrases: + */ + __pyx_v_met_constraints = 0; + goto __pyx_L27; + } + __pyx_L27:; + goto __pyx_L20; + } + __pyx_L20:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1492 + * met_constraints = 0 + * + * if met_constraints and self.tight_phrases: # <<<<<<<<<<<<<< + * # outside edge constraints are checked later + * for i from 0 <= i < num_chunks-1: + */ + if (__pyx_v_met_constraints) { + __pyx_t_7 = __pyx_v_self->tight_phrases; + } else { + __pyx_t_7 = __pyx_v_met_constraints; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1494 + * if met_constraints and self.tight_phrases: + * # outside edge constraints are checked later + * for i from 0 <= i < num_chunks-1: # <<<<<<<<<<<<<< + * if f_links_low[matching.arr[matching.start+i]+chunklen[i]-f_sent_start] == -1: + * reason_for_failure = "Gaps are not tight phrases" + */ + __pyx_t_12 = (__pyx_v_num_chunks - 1); + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_12; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1495 + * # outside edge constraints are checked later + * for i from 0 <= i < num_chunks-1: + * if f_links_low[matching.arr[matching.start+i]+chunklen[i]-f_sent_start] == -1: # <<<<<<<<<<<<<< + * reason_for_failure = "Gaps are not tight phrases" + * met_constraints = 0 + */ + __pyx_t_7 = ((__pyx_v_f_links_low[(((__pyx_v_matching->arr[(__pyx_v_matching->start + __pyx_v_i)]) + (__pyx_v_chunklen[__pyx_v_i])) - __pyx_v_f_sent_start)]) == -1); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1496 + * for i from 0 <= i < num_chunks-1: + * if f_links_low[matching.arr[matching.start+i]+chunklen[i]-f_sent_start] == -1: + * reason_for_failure = "Gaps are not tight phrases" # <<<<<<<<<<<<<< + * met_constraints = 0 + * break + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_126)); + __Pyx_DECREF(__pyx_v_reason_for_failure); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_126); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1497 + * if f_links_low[matching.arr[matching.start+i]+chunklen[i]-f_sent_start] == -1: + * reason_for_failure = "Gaps are not tight phrases" + * met_constraints = 0 # <<<<<<<<<<<<<< + * break + * if f_links_low[matching.arr[matching.start+i+1]-1-f_sent_start] == -1: + */ + __pyx_v_met_constraints = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1498 + * reason_for_failure = "Gaps are not tight phrases" + * met_constraints = 0 + * break # <<<<<<<<<<<<<< + * if f_links_low[matching.arr[matching.start+i+1]-1-f_sent_start] == -1: + * reason_for_failure = "Gaps are not tight phrases" + */ + goto __pyx_L30_break; + goto __pyx_L31; + } + __pyx_L31:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1499 + * met_constraints = 0 + * break + * if f_links_low[matching.arr[matching.start+i+1]-1-f_sent_start] == -1: # <<<<<<<<<<<<<< + * reason_for_failure = "Gaps are not tight phrases" + * met_constraints = 0 + */ + __pyx_t_7 = ((__pyx_v_f_links_low[(((__pyx_v_matching->arr[((__pyx_v_matching->start + __pyx_v_i) + 1)]) - 1) - __pyx_v_f_sent_start)]) == -1); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1500 + * break + * if f_links_low[matching.arr[matching.start+i+1]-1-f_sent_start] == -1: + * reason_for_failure = "Gaps are not tight phrases" # <<<<<<<<<<<<<< + * met_constraints = 0 + * break + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_126)); + __Pyx_DECREF(__pyx_v_reason_for_failure); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_126); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1501 + * if f_links_low[matching.arr[matching.start+i+1]-1-f_sent_start] == -1: + * reason_for_failure = "Gaps are not tight phrases" + * met_constraints = 0 # <<<<<<<<<<<<<< + * break + * + */ + __pyx_v_met_constraints = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1502 + * reason_for_failure = "Gaps are not tight phrases" + * met_constraints = 0 + * break # <<<<<<<<<<<<<< + * + * f_low = matching.arr[matching.start] - f_sent_start + */ + goto __pyx_L30_break; + goto __pyx_L32; + } + __pyx_L32:; + } + __pyx_L30_break:; + goto __pyx_L28; + } + __pyx_L28:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1504 + * break + * + * f_low = matching.arr[matching.start] - f_sent_start # <<<<<<<<<<<<<< + * f_high = matching.arr[matching.start + matching.size - 1] + chunklen[num_chunks-1] - f_sent_start + * if met_constraints: + */ + __pyx_v_f_low = ((__pyx_v_matching->arr[__pyx_v_matching->start]) - __pyx_v_f_sent_start); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1505 + * + * f_low = matching.arr[matching.start] - f_sent_start + * f_high = matching.arr[matching.start + matching.size - 1] + chunklen[num_chunks-1] - f_sent_start # <<<<<<<<<<<<<< + * if met_constraints: + * + */ + __pyx_v_f_high = (((__pyx_v_matching->arr[((__pyx_v_matching->start + __pyx_v_matching->size) - 1)]) + (__pyx_v_chunklen[(__pyx_v_num_chunks - 1)])) - __pyx_v_f_sent_start); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1506 + * f_low = matching.arr[matching.start] - f_sent_start + * f_high = matching.arr[matching.start + matching.size - 1] + chunklen[num_chunks-1] - f_sent_start + * if met_constraints: # <<<<<<<<<<<<<< + * + * if self.find_fixpoint(f_low, f_high, f_links_low, f_links_high, e_links_low, e_links_high, + */ + if (__pyx_v_met_constraints) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1508 + * if met_constraints: + * + * if self.find_fixpoint(f_low, f_high, f_links_low, f_links_high, e_links_low, e_links_high, # <<<<<<<<<<<<<< + * -1, -1, &e_low, &e_high, &f_back_low, &f_back_high, f_sent_len, e_sent_len, + * self.train_max_initial_size, self.train_max_initial_size, + */ + __pyx_t_10 = PyInt_FromLong(__pyx_v_f_high); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1508; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1512 + * self.train_max_initial_size, self.train_max_initial_size, + * self.train_min_gap_size, 0, + * self.max_nonterminals - num_chunks + 1, 1, 1, 0, 0): # <<<<<<<<<<<<<< + * gap_error = 0 + * num_gaps = 0 + */ + __pyx_t_3 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_low, __pyx_t_10, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, -1, -1, (&__pyx_v_e_low), (&__pyx_v_e_high), (&__pyx_v_f_back_low), (&__pyx_v_f_back_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_min_gap_size, 0, ((__pyx_v_self->max_nonterminals - __pyx_v_num_chunks) + 1), 1, 1, 0, 0); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1513 + * self.train_min_gap_size, 0, + * self.max_nonterminals - num_chunks + 1, 1, 1, 0, 0): + * gap_error = 0 # <<<<<<<<<<<<<< + * num_gaps = 0 + * + */ + __pyx_v_gap_error = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1514 + * self.max_nonterminals - num_chunks + 1, 1, 1, 0, 0): + * gap_error = 0 + * num_gaps = 0 # <<<<<<<<<<<<<< + * + * if f_back_low < f_low: + */ + __pyx_v_num_gaps = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1516 + * num_gaps = 0 + * + * if f_back_low < f_low: # <<<<<<<<<<<<<< + * f_gap_low[0] = f_back_low + * f_gap_high[0] = f_low + */ + __pyx_t_7 = (__pyx_v_f_back_low < __pyx_v_f_low); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1517 + * + * if f_back_low < f_low: + * f_gap_low[0] = f_back_low # <<<<<<<<<<<<<< + * f_gap_high[0] = f_low + * num_gaps = 1 + */ + (__pyx_v_f_gap_low[0]) = __pyx_v_f_back_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1518 + * if f_back_low < f_low: + * f_gap_low[0] = f_back_low + * f_gap_high[0] = f_low # <<<<<<<<<<<<<< + * num_gaps = 1 + * gap_start = 0 + */ + (__pyx_v_f_gap_high[0]) = __pyx_v_f_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1519 + * f_gap_low[0] = f_back_low + * f_gap_high[0] = f_low + * num_gaps = 1 # <<<<<<<<<<<<<< + * gap_start = 0 + * phrase_len = phrase_len+1 + */ + __pyx_v_num_gaps = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1520 + * f_gap_high[0] = f_low + * num_gaps = 1 + * gap_start = 0 # <<<<<<<<<<<<<< + * phrase_len = phrase_len+1 + * if phrase_len > self.max_length: + */ + __pyx_v_gap_start = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1521 + * num_gaps = 1 + * gap_start = 0 + * phrase_len = phrase_len+1 # <<<<<<<<<<<<<< + * if phrase_len > self.max_length: + * gap_error = 1 + */ + __pyx_v_phrase_len = (__pyx_v_phrase_len + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1522 + * gap_start = 0 + * phrase_len = phrase_len+1 + * if phrase_len > self.max_length: # <<<<<<<<<<<<<< + * gap_error = 1 + * if self.tight_phrases: + */ + __pyx_t_7 = (__pyx_v_phrase_len > __pyx_v_self->max_length); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1523 + * phrase_len = phrase_len+1 + * if phrase_len > self.max_length: + * gap_error = 1 # <<<<<<<<<<<<<< + * if self.tight_phrases: + * if f_links_low[f_back_low] == -1 or f_links_low[f_low-1] == -1: + */ + __pyx_v_gap_error = 1; + goto __pyx_L36; + } + __pyx_L36:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1524 + * if phrase_len > self.max_length: + * gap_error = 1 + * if self.tight_phrases: # <<<<<<<<<<<<<< + * if f_links_low[f_back_low] == -1 or f_links_low[f_low-1] == -1: + * gap_error = 1 + */ + if (__pyx_v_self->tight_phrases) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1525 + * gap_error = 1 + * if self.tight_phrases: + * if f_links_low[f_back_low] == -1 or f_links_low[f_low-1] == -1: # <<<<<<<<<<<<<< + * gap_error = 1 + * reason_for_failure = "Inside edges of preceding subphrase are not tight" + */ + __pyx_t_7 = ((__pyx_v_f_links_low[__pyx_v_f_back_low]) == -1); + if (!__pyx_t_7) { + __pyx_t_9 = ((__pyx_v_f_links_low[(__pyx_v_f_low - 1)]) == -1); + __pyx_t_8 = __pyx_t_9; + } else { + __pyx_t_8 = __pyx_t_7; + } + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1526 + * if self.tight_phrases: + * if f_links_low[f_back_low] == -1 or f_links_low[f_low-1] == -1: + * gap_error = 1 # <<<<<<<<<<<<<< + * reason_for_failure = "Inside edges of preceding subphrase are not tight" + * else: + */ + __pyx_v_gap_error = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1527 + * if f_links_low[f_back_low] == -1 or f_links_low[f_low-1] == -1: + * gap_error = 1 + * reason_for_failure = "Inside edges of preceding subphrase are not tight" # <<<<<<<<<<<<<< + * else: + * gap_start = 1 + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_127)); + __Pyx_DECREF(__pyx_v_reason_for_failure); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_127); + goto __pyx_L38; + } + __pyx_L38:; + goto __pyx_L37; + } + __pyx_L37:; + goto __pyx_L35; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1529 + * reason_for_failure = "Inside edges of preceding subphrase are not tight" + * else: + * gap_start = 1 # <<<<<<<<<<<<<< + * if self.tight_phrases and f_links_low[f_low] == -1: + * # this is not a hard error. we can't extract this phrase + */ + __pyx_v_gap_start = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1530 + * else: + * gap_start = 1 + * if self.tight_phrases and f_links_low[f_low] == -1: # <<<<<<<<<<<<<< + * # this is not a hard error. we can't extract this phrase + * # but we still might be able to extract a superphrase + */ + if (__pyx_v_self->tight_phrases) { + __pyx_t_8 = ((__pyx_v_f_links_low[__pyx_v_f_low]) == -1); + __pyx_t_7 = __pyx_t_8; + } else { + __pyx_t_7 = __pyx_v_self->tight_phrases; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1533 + * # this is not a hard error. we can't extract this phrase + * # but we still might be able to extract a superphrase + * met_constraints = 0 # <<<<<<<<<<<<<< + * + * for i from 0 <= i < matching.size - 1: + */ + __pyx_v_met_constraints = 0; + goto __pyx_L39; + } + __pyx_L39:; + } + __pyx_L35:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1535 + * met_constraints = 0 + * + * for i from 0 <= i < matching.size - 1: # <<<<<<<<<<<<<< + * f_gap_low[1+i] = matching.arr[matching.start+i] + chunklen[i] - f_sent_start + * f_gap_high[1+i] = matching.arr[matching.start+i+1] - f_sent_start + */ + __pyx_t_12 = (__pyx_v_matching->size - 1); + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_12; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1536 + * + * for i from 0 <= i < matching.size - 1: + * f_gap_low[1+i] = matching.arr[matching.start+i] + chunklen[i] - f_sent_start # <<<<<<<<<<<<<< + * f_gap_high[1+i] = matching.arr[matching.start+i+1] - f_sent_start + * num_gaps = num_gaps + 1 + */ + (__pyx_v_f_gap_low[(1 + __pyx_v_i)]) = (((__pyx_v_matching->arr[(__pyx_v_matching->start + __pyx_v_i)]) + (__pyx_v_chunklen[__pyx_v_i])) - __pyx_v_f_sent_start); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1537 + * for i from 0 <= i < matching.size - 1: + * f_gap_low[1+i] = matching.arr[matching.start+i] + chunklen[i] - f_sent_start + * f_gap_high[1+i] = matching.arr[matching.start+i+1] - f_sent_start # <<<<<<<<<<<<<< + * num_gaps = num_gaps + 1 + * + */ + (__pyx_v_f_gap_high[(1 + __pyx_v_i)]) = ((__pyx_v_matching->arr[((__pyx_v_matching->start + __pyx_v_i) + 1)]) - __pyx_v_f_sent_start); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1538 + * f_gap_low[1+i] = matching.arr[matching.start+i] + chunklen[i] - f_sent_start + * f_gap_high[1+i] = matching.arr[matching.start+i+1] - f_sent_start + * num_gaps = num_gaps + 1 # <<<<<<<<<<<<<< + * + * if f_high < f_back_high: + */ + __pyx_v_num_gaps = (__pyx_v_num_gaps + 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1540 + * num_gaps = num_gaps + 1 + * + * if f_high < f_back_high: # <<<<<<<<<<<<<< + * f_gap_low[gap_start+num_gaps] = f_high + * f_gap_high[gap_start+num_gaps] = f_back_high + */ + __pyx_t_7 = (__pyx_v_f_high < __pyx_v_f_back_high); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1541 + * + * if f_high < f_back_high: + * f_gap_low[gap_start+num_gaps] = f_high # <<<<<<<<<<<<<< + * f_gap_high[gap_start+num_gaps] = f_back_high + * num_gaps = num_gaps + 1 + */ + (__pyx_v_f_gap_low[(__pyx_v_gap_start + __pyx_v_num_gaps)]) = __pyx_v_f_high; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1542 + * if f_high < f_back_high: + * f_gap_low[gap_start+num_gaps] = f_high + * f_gap_high[gap_start+num_gaps] = f_back_high # <<<<<<<<<<<<<< + * num_gaps = num_gaps + 1 + * phrase_len = phrase_len+1 + */ + (__pyx_v_f_gap_high[(__pyx_v_gap_start + __pyx_v_num_gaps)]) = __pyx_v_f_back_high; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1543 + * f_gap_low[gap_start+num_gaps] = f_high + * f_gap_high[gap_start+num_gaps] = f_back_high + * num_gaps = num_gaps + 1 # <<<<<<<<<<<<<< + * phrase_len = phrase_len+1 + * if phrase_len > self.max_length: + */ + __pyx_v_num_gaps = (__pyx_v_num_gaps + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1544 + * f_gap_high[gap_start+num_gaps] = f_back_high + * num_gaps = num_gaps + 1 + * phrase_len = phrase_len+1 # <<<<<<<<<<<<<< + * if phrase_len > self.max_length: + * gap_error = 1 + */ + __pyx_v_phrase_len = (__pyx_v_phrase_len + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1545 + * num_gaps = num_gaps + 1 + * phrase_len = phrase_len+1 + * if phrase_len > self.max_length: # <<<<<<<<<<<<<< + * gap_error = 1 + * if self.tight_phrases: + */ + __pyx_t_7 = (__pyx_v_phrase_len > __pyx_v_self->max_length); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1546 + * phrase_len = phrase_len+1 + * if phrase_len > self.max_length: + * gap_error = 1 # <<<<<<<<<<<<<< + * if self.tight_phrases: + * if f_links_low[f_back_high-1] == -1 or f_links_low[f_high] == -1: + */ + __pyx_v_gap_error = 1; + goto __pyx_L43; + } + __pyx_L43:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1547 + * if phrase_len > self.max_length: + * gap_error = 1 + * if self.tight_phrases: # <<<<<<<<<<<<<< + * if f_links_low[f_back_high-1] == -1 or f_links_low[f_high] == -1: + * gap_error = 1 + */ + if (__pyx_v_self->tight_phrases) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1548 + * gap_error = 1 + * if self.tight_phrases: + * if f_links_low[f_back_high-1] == -1 or f_links_low[f_high] == -1: # <<<<<<<<<<<<<< + * gap_error = 1 + * reason_for_failure = "Inside edges of following subphrase are not tight" + */ + __pyx_t_7 = ((__pyx_v_f_links_low[(__pyx_v_f_back_high - 1)]) == -1); + if (!__pyx_t_7) { + __pyx_t_8 = ((__pyx_v_f_links_low[__pyx_v_f_high]) == -1); + __pyx_t_9 = __pyx_t_8; + } else { + __pyx_t_9 = __pyx_t_7; + } + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1549 + * if self.tight_phrases: + * if f_links_low[f_back_high-1] == -1 or f_links_low[f_high] == -1: + * gap_error = 1 # <<<<<<<<<<<<<< + * reason_for_failure = "Inside edges of following subphrase are not tight" + * else: + */ + __pyx_v_gap_error = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1550 + * if f_links_low[f_back_high-1] == -1 or f_links_low[f_high] == -1: + * gap_error = 1 + * reason_for_failure = "Inside edges of following subphrase are not tight" # <<<<<<<<<<<<<< + * else: + * if self.tight_phrases and f_links_low[f_high-1] == -1: + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_128)); + __Pyx_DECREF(__pyx_v_reason_for_failure); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_128); + goto __pyx_L45; + } + __pyx_L45:; + goto __pyx_L44; + } + __pyx_L44:; + goto __pyx_L42; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1552 + * reason_for_failure = "Inside edges of following subphrase are not tight" + * else: + * if self.tight_phrases and f_links_low[f_high-1] == -1: # <<<<<<<<<<<<<< + * met_constraints = 0 + * + */ + if (__pyx_v_self->tight_phrases) { + __pyx_t_9 = ((__pyx_v_f_links_low[(__pyx_v_f_high - 1)]) == -1); + __pyx_t_7 = __pyx_t_9; + } else { + __pyx_t_7 = __pyx_v_self->tight_phrases; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1553 + * else: + * if self.tight_phrases and f_links_low[f_high-1] == -1: + * met_constraints = 0 # <<<<<<<<<<<<<< + * + * if gap_error == 0: + */ + __pyx_v_met_constraints = 0; + goto __pyx_L46; + } + __pyx_L46:; + } + __pyx_L42:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1555 + * met_constraints = 0 + * + * if gap_error == 0: # <<<<<<<<<<<<<< + * e_word_count = e_high - e_low + * for i from 0 <= i < num_gaps: # check integrity of subphrases + */ + __pyx_t_7 = (__pyx_v_gap_error == 0); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1556 + * + * if gap_error == 0: + * e_word_count = e_high - e_low # <<<<<<<<<<<<<< + * for i from 0 <= i < num_gaps: # check integrity of subphrases + * if self.find_fixpoint(f_gap_low[gap_start+i], f_gap_high[gap_start+i], + */ + __pyx_v_e_word_count = (__pyx_v_e_high - __pyx_v_e_low); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1557 + * if gap_error == 0: + * e_word_count = e_high - e_low + * for i from 0 <= i < num_gaps: # check integrity of subphrases # <<<<<<<<<<<<<< + * if self.find_fixpoint(f_gap_low[gap_start+i], f_gap_high[gap_start+i], + * f_links_low, f_links_high, e_links_low, e_links_high, + */ + __pyx_t_3 = __pyx_v_num_gaps; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1558 + * e_word_count = e_high - e_low + * for i from 0 <= i < num_gaps: # check integrity of subphrases + * if self.find_fixpoint(f_gap_low[gap_start+i], f_gap_high[gap_start+i], # <<<<<<<<<<<<<< + * f_links_low, f_links_high, e_links_low, e_links_high, + * -1, -1, e_gap_low+gap_start+i, e_gap_high+gap_start+i, + */ + __pyx_t_10 = PyInt_FromLong((__pyx_v_f_gap_high[(__pyx_v_gap_start + __pyx_v_i)])); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1558; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1563 + * f_gap_low+gap_start+i, f_gap_high+gap_start+i, + * f_sent_len, e_sent_len, + * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< + * 0, 0, 0, 0, 0, 0, 0) == 0: + * gap_error = 1 + */ + __pyx_t_7 = (((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, (__pyx_v_f_gap_low[(__pyx_v_gap_start + __pyx_v_i)]), __pyx_t_10, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, -1, -1, ((__pyx_v_e_gap_low + __pyx_v_gap_start) + __pyx_v_i), ((__pyx_v_e_gap_high + __pyx_v_gap_start) + __pyx_v_i), ((__pyx_v_f_gap_low + __pyx_v_gap_start) + __pyx_v_i), ((__pyx_v_f_gap_high + __pyx_v_gap_start) + __pyx_v_i), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 0, 0, 0, 0, 0, 0, 0) == 0); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1565 + * self.train_max_initial_size, self.train_max_initial_size, + * 0, 0, 0, 0, 0, 0, 0) == 0: + * gap_error = 1 # <<<<<<<<<<<<<< + * reason_for_failure = "Subphrase [%d, %d] failed integrity check" % (f_gap_low[gap_start+i], f_gap_high[gap_start+i]) + * break + */ + __pyx_v_gap_error = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1566 + * 0, 0, 0, 0, 0, 0, 0) == 0: + * gap_error = 1 + * reason_for_failure = "Subphrase [%d, %d] failed integrity check" % (f_gap_low[gap_start+i], f_gap_high[gap_start+i]) # <<<<<<<<<<<<<< + * break + * + */ + __pyx_t_10 = PyInt_FromLong((__pyx_v_f_gap_low[(__pyx_v_gap_start + __pyx_v_i)])); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1566; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_1 = PyInt_FromLong((__pyx_v_f_gap_high[(__pyx_v_gap_start + __pyx_v_i)])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1566; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1566; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_10 = 0; + __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_129), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1566; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_v_reason_for_failure); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1567 + * gap_error = 1 + * reason_for_failure = "Subphrase [%d, %d] failed integrity check" % (f_gap_low[gap_start+i], f_gap_high[gap_start+i]) + * break # <<<<<<<<<<<<<< + * + * if gap_error == 0: + */ + goto __pyx_L49_break; + goto __pyx_L50; + } + __pyx_L50:; + } + __pyx_L49_break:; + goto __pyx_L47; + } + __pyx_L47:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1569 + * break + * + * if gap_error == 0: # <<<<<<<<<<<<<< + * i = 1 + * self.findexes.reset() + */ + __pyx_t_7 = (__pyx_v_gap_error == 0); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1570 + * + * if gap_error == 0: + * i = 1 # <<<<<<<<<<<<<< + * self.findexes.reset() + * if f_back_low < f_low: + */ + __pyx_v_i = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1571 + * if gap_error == 0: + * i = 1 + * self.findexes.reset() # <<<<<<<<<<<<<< + * if f_back_low < f_low: + * fphr_arr._append(sym_setindex(self.category, i)) + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__reset); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1571; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1571; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1572 + * i = 1 + * self.findexes.reset() + * if f_back_low < f_low: # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 + */ + __pyx_t_7 = (__pyx_v_f_back_low < __pyx_v_f_low); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1573 + * self.findexes.reset() + * if f_back_low < f_low: + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * i = i+1 + * self.findexes.append(sym_setindex(self.category, i)) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1574 + * if f_back_low < f_low: + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 # <<<<<<<<<<<<<< + * self.findexes.append(sym_setindex(self.category, i)) + * self.findexes.extend(self.findexes1) + */ + __pyx_v_i = (__pyx_v_i + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1575 + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 + * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: + */ + __pyx_t_2 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L52; + } + __pyx_L52:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1576 + * i = i+1 + * self.findexes.append(sym_setindex(self.category, i)) + * self.findexes.extend(self.findexes1) # <<<<<<<<<<<<<< + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__extend); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1576; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1576; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_v_self->findexes1)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self->findexes1)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->findexes1)); + __pyx_t_10 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1576; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1577 + * self.findexes.append(sym_setindex(self.category, i)) + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: # <<<<<<<<<<<<<< + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) + */ + __pyx_t_3 = __pyx_v_phrase->n; + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1578 + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i + 1 + */ + __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_isvar); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1578; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = PyInt_FromLong((__pyx_v_phrase->syms[__pyx_v_j])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1578; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1578; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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_t_10, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1578; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1578; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1579 + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * i = i + 1 + * else: + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1580 + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i + 1 # <<<<<<<<<<<<<< + * else: + * fphr_arr._append(phrase.syms[j]) + */ + __pyx_v_i = (__pyx_v_i + 1); + goto __pyx_L55; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1582 + * i = i + 1 + * else: + * fphr_arr._append(phrase.syms[j]) # <<<<<<<<<<<<<< + * if f_back_high > f_high: + * fphr_arr._append(sym_setindex(self.category, i)) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, (__pyx_v_phrase->syms[__pyx_v_j])); + } + __pyx_L55:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1583 + * else: + * fphr_arr._append(phrase.syms[j]) + * if f_back_high > f_high: # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) + */ + __pyx_t_7 = (__pyx_v_f_back_high > __pyx_v_f_high); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1584 + * fphr_arr._append(phrase.syms[j]) + * if f_back_high > f_high: + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * self.findexes.append(sym_setindex(self.category, i)) + * + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1585 + * if f_back_high > f_high: + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * + * fphr = Phrase(fphr_arr) + */ + __pyx_t_2 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1585; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1585; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L56; + } + __pyx_L56:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1587 + * self.findexes.append(sym_setindex(self.category, i)) + * + * fphr = Phrase(fphr_arr) # <<<<<<<<<<<<<< + * if met_constraints: + * phrase_list = self.extract_phrases(e_low, e_high, e_gap_low + gap_start, e_gap_high + gap_start, e_links_low, num_gaps, + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1587; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_fphr_arr)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_fphr_arr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr_arr)); + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1587; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_v_fphr = ((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1588 + * + * fphr = Phrase(fphr_arr) + * if met_constraints: # <<<<<<<<<<<<<< + * phrase_list = self.extract_phrases(e_low, e_high, e_gap_low + gap_start, e_gap_high + gap_start, e_links_low, num_gaps, + * f_back_low, f_back_high, f_gap_low + gap_start, f_gap_high + gap_start, f_links_low, + */ + if (__pyx_v_met_constraints) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1591 + * phrase_list = self.extract_phrases(e_low, e_high, e_gap_low + gap_start, e_gap_high + gap_start, e_links_low, num_gaps, + * f_back_low, f_back_high, f_gap_low + gap_start, f_gap_high + gap_start, f_links_low, + * matching.sent_id, e_sent_len, e_sent_start) # <<<<<<<<<<<<<< + * if len(phrase_list) > 0: + * pair_count = 1.0 / len(phrase_list) + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->extract_phrases(__pyx_v_self, __pyx_v_e_low, __pyx_v_e_high, (__pyx_v_e_gap_low + __pyx_v_gap_start), (__pyx_v_e_gap_high + __pyx_v_gap_start), __pyx_v_e_links_low, __pyx_v_num_gaps, __pyx_v_f_back_low, __pyx_v_f_back_high, (__pyx_v_f_gap_low + __pyx_v_gap_start), (__pyx_v_f_gap_high + __pyx_v_gap_start), __pyx_v_f_links_low, __pyx_v_matching->sent_id, __pyx_v_e_sent_len, __pyx_v_e_sent_start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1589; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_phrase_list = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1592 + * f_back_low, f_back_high, f_gap_low + gap_start, f_gap_high + gap_start, f_links_low, + * matching.sent_id, e_sent_len, e_sent_start) + * if len(phrase_list) > 0: # <<<<<<<<<<<<<< + * pair_count = 1.0 / len(phrase_list) + * else: + */ + __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = (__pyx_t_13 > 0); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1593 + * matching.sent_id, e_sent_len, e_sent_start) + * if len(phrase_list) > 0: + * pair_count = 1.0 / len(phrase_list) # <<<<<<<<<<<<<< + * else: + * pair_count = 0 + */ + __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1593; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__pyx_t_13 == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1593; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_pair_count = (1.0 / __pyx_t_13); + goto __pyx_L58; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1595 + * pair_count = 1.0 / len(phrase_list) + * else: + * pair_count = 0 # <<<<<<<<<<<<<< + * reason_for_failure = "Didn't extract anything from [%d, %d] -> [%d, %d]" % (f_back_low, f_back_high, e_low, e_high) + * for (phrase2,eindexes) in phrase_list: + */ + __pyx_v_pair_count = 0.0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1596 + * else: + * pair_count = 0 + * reason_for_failure = "Didn't extract anything from [%d, %d] -> [%d, %d]" % (f_back_low, f_back_high, e_low, e_high) # <<<<<<<<<<<<<< + * for (phrase2,eindexes) in phrase_list: + * als1 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + */ + __pyx_t_2 = PyInt_FromLong(__pyx_v_f_back_low); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyInt_FromLong(__pyx_v_f_back_high); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = PyInt_FromLong(__pyx_v_e_low); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_14 = PyInt_FromLong(__pyx_v_e_high); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = PyTuple_New(4); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __pyx_t_10 = 0; + __pyx_t_14 = 0; + __pyx_t_14 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_130), ((PyObject *)__pyx_t_15)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_14)); + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_v_reason_for_failure); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_t_14); + __pyx_t_14 = 0; + } + __pyx_L58:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1597 + * pair_count = 0 + * reason_for_failure = "Didn't extract anything from [%d, %d] -> [%d, %d]" % (f_back_low, f_back_high, e_low, e_high) + * for (phrase2,eindexes) in phrase_list: # <<<<<<<<<<<<<< + * als1 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + * extracts.append((fphr, phrase2, pair_count, tuple(als1))) + */ + if (PyList_CheckExact(__pyx_v_phrase_list) || PyTuple_CheckExact(__pyx_v_phrase_list)) { + __pyx_t_14 = __pyx_v_phrase_list; __Pyx_INCREF(__pyx_t_14); __pyx_t_13 = 0; + __pyx_t_16 = NULL; + } else { + __pyx_t_13 = -1; __pyx_t_14 = PyObject_GetIter(__pyx_v_phrase_list); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_16 = Py_TYPE(__pyx_t_14)->tp_iternext; + } + for (;;) { + if (!__pyx_t_16 && PyList_CheckExact(__pyx_t_14)) { + if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_14)) break; + __pyx_t_15 = PyList_GET_ITEM(__pyx_t_14, __pyx_t_13); __Pyx_INCREF(__pyx_t_15); __pyx_t_13++; + } else if (!__pyx_t_16 && PyTuple_CheckExact(__pyx_t_14)) { + if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_14)) break; + __pyx_t_15 = PyTuple_GET_ITEM(__pyx_t_14, __pyx_t_13); __Pyx_INCREF(__pyx_t_15); __pyx_t_13++; + } else { + __pyx_t_15 = __pyx_t_16(__pyx_t_14); + if (unlikely(!__pyx_t_15)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_15); + } + if ((likely(PyTuple_CheckExact(__pyx_t_15))) || (PyList_CheckExact(__pyx_t_15))) { + PyObject* sequence = __pyx_t_15; + if (likely(PyTuple_CheckExact(sequence))) { + 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[8]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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[8]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_10 = PyList_GET_ITEM(sequence, 0); + __pyx_t_1 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_2 = PyObject_GetIter(__pyx_t_15); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_17 = Py_TYPE(__pyx_t_2)->tp_iternext; + index = 0; __pyx_t_10 = __pyx_t_17(__pyx_t_2); if (unlikely(!__pyx_t_10)) goto __pyx_L61_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + index = 1; __pyx_t_1 = __pyx_t_17(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L61_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_2), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L62_unpacking_done; + __pyx_L61_unpacking_failed:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L62_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_phrase2); + __pyx_v_phrase2 = __pyx_t_10; + __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_v_eindexes); + __pyx_v_eindexes = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1598 + * reason_for_failure = "Didn't extract anything from [%d, %d] -> [%d, %d]" % (f_back_low, f_back_high, e_low, e_high) + * for (phrase2,eindexes) in phrase_list: + * als1 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) # <<<<<<<<<<<<<< + * extracts.append((fphr, phrase2, pair_count, tuple(als1))) + * + */ + __pyx_t_15 = ((PyObject *)__pyx_v_self->findexes); + __Pyx_INCREF(__pyx_t_15); + __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->create_alignments(__pyx_v_self, __pyx_v_sent_links, __pyx_v_num_links, __pyx_t_15, __pyx_v_eindexes); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_v_als1); + __pyx_v_als1 = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1599 + * for (phrase2,eindexes) in phrase_list: + * als1 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + * extracts.append((fphr, phrase2, pair_count, tuple(als1))) # <<<<<<<<<<<<<< + * + * if (num_gaps < self.max_nonterminals and + */ + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_pair_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(__pyx_v_als1); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_als1); + __Pyx_GIVEREF(__pyx_v_als1); + __pyx_t_10 = PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __pyx_t_15 = PyTuple_New(4); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(((PyObject *)__pyx_v_fphr)); + PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)__pyx_v_fphr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr)); + __Pyx_INCREF(__pyx_v_phrase2); + PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_v_phrase2); + __Pyx_GIVEREF(__pyx_v_phrase2); + PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_t_1 = 0; + __pyx_t_10 = 0; + __pyx_t_10 = __Pyx_PyObject_Append(__pyx_v_extracts, ((PyObject *)__pyx_t_15)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + goto __pyx_L57; + } + __pyx_L57:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1601 + * extracts.append((fphr, phrase2, pair_count, tuple(als1))) + * + * if (num_gaps < self.max_nonterminals and # <<<<<<<<<<<<<< + * phrase_len < self.max_length and + * f_back_high - f_back_low + self.train_min_gap_size <= self.train_max_initial_size): + */ + __pyx_t_7 = (__pyx_v_num_gaps < __pyx_v_self->max_nonterminals); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1602 + * + * if (num_gaps < self.max_nonterminals and + * phrase_len < self.max_length and # <<<<<<<<<<<<<< + * f_back_high - f_back_low + self.train_min_gap_size <= self.train_max_initial_size): + * if (f_back_low == f_low and + */ + __pyx_t_9 = (__pyx_v_phrase_len < __pyx_v_self->max_length); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1603 + * if (num_gaps < self.max_nonterminals and + * phrase_len < self.max_length and + * f_back_high - f_back_low + self.train_min_gap_size <= self.train_max_initial_size): # <<<<<<<<<<<<<< + * if (f_back_low == f_low and + * f_low >= self.train_min_gap_size and + */ + __pyx_t_8 = (((__pyx_v_f_back_high - __pyx_v_f_back_low) + __pyx_v_self->train_min_gap_size) <= __pyx_v_self->train_max_initial_size); + __pyx_t_18 = __pyx_t_8; + } else { + __pyx_t_18 = __pyx_t_9; + } + __pyx_t_9 = __pyx_t_18; + } else { + __pyx_t_9 = __pyx_t_7; + } + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1604 + * phrase_len < self.max_length and + * f_back_high - f_back_low + self.train_min_gap_size <= self.train_max_initial_size): + * if (f_back_low == f_low and # <<<<<<<<<<<<<< + * f_low >= self.train_min_gap_size and + * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_back_high-1] != -1))): + */ + __pyx_t_9 = (__pyx_v_f_back_low == __pyx_v_f_low); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1605 + * f_back_high - f_back_low + self.train_min_gap_size <= self.train_max_initial_size): + * if (f_back_low == f_low and + * f_low >= self.train_min_gap_size and # <<<<<<<<<<<<<< + * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_back_high-1] != -1))): + * f_x_low = f_low-self.train_min_gap_size + */ + __pyx_t_7 = (__pyx_v_f_low >= __pyx_v_self->train_min_gap_size); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1606 + * if (f_back_low == f_low and + * f_low >= self.train_min_gap_size and + * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_back_high-1] != -1))): # <<<<<<<<<<<<<< + * f_x_low = f_low-self.train_min_gap_size + * met_constraints = 1 + */ + __pyx_t_18 = (!__pyx_v_self->tight_phrases); + if (!__pyx_t_18) { + __pyx_t_8 = ((__pyx_v_f_links_low[(__pyx_v_f_low - 1)]) != -1); + if (__pyx_t_8) { + __pyx_t_19 = ((__pyx_v_f_links_low[(__pyx_v_f_back_high - 1)]) != -1); + __pyx_t_20 = __pyx_t_19; + } else { + __pyx_t_20 = __pyx_t_8; + } + __pyx_t_8 = __pyx_t_20; + } else { + __pyx_t_8 = __pyx_t_18; + } + __pyx_t_18 = __pyx_t_8; + } else { + __pyx_t_18 = __pyx_t_7; + } + __pyx_t_7 = __pyx_t_18; + } else { + __pyx_t_7 = __pyx_t_9; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1607 + * f_low >= self.train_min_gap_size and + * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_back_high-1] != -1))): + * f_x_low = f_low-self.train_min_gap_size # <<<<<<<<<<<<<< + * met_constraints = 1 + * if self.tight_phrases: + */ + __pyx_v_f_x_low = (__pyx_v_f_low - __pyx_v_self->train_min_gap_size); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1608 + * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_back_high-1] != -1))): + * f_x_low = f_low-self.train_min_gap_size + * met_constraints = 1 # <<<<<<<<<<<<<< + * if self.tight_phrases: + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: + */ + __pyx_v_met_constraints = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1609 + * f_x_low = f_low-self.train_min_gap_size + * met_constraints = 1 + * if self.tight_phrases: # <<<<<<<<<<<<<< + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: + * f_x_low = f_x_low - 1 + */ + if (__pyx_v_self->tight_phrases) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1610 + * met_constraints = 1 + * if self.tight_phrases: + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: # <<<<<<<<<<<<<< + * f_x_low = f_x_low - 1 + * if f_x_low < 0 or f_back_high - f_x_low > self.train_max_initial_size: + */ + while (1) { + __pyx_t_7 = (__pyx_v_f_x_low >= 0); + if (__pyx_t_7) { + __pyx_t_9 = ((__pyx_v_f_links_low[__pyx_v_f_x_low]) == -1); + __pyx_t_18 = __pyx_t_9; + } else { + __pyx_t_18 = __pyx_t_7; + } + if (!__pyx_t_18) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1611 + * if self.tight_phrases: + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: + * f_x_low = f_x_low - 1 # <<<<<<<<<<<<<< + * if f_x_low < 0 or f_back_high - f_x_low > self.train_max_initial_size: + * met_constraints = 0 + */ + __pyx_v_f_x_low = (__pyx_v_f_x_low - 1); + } + goto __pyx_L65; + } + __pyx_L65:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1612 + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: + * f_x_low = f_x_low - 1 + * if f_x_low < 0 or f_back_high - f_x_low > self.train_max_initial_size: # <<<<<<<<<<<<<< + * met_constraints = 0 + * + */ + __pyx_t_18 = (__pyx_v_f_x_low < 0); + if (!__pyx_t_18) { + __pyx_t_7 = ((__pyx_v_f_back_high - __pyx_v_f_x_low) > __pyx_v_self->train_max_initial_size); + __pyx_t_9 = __pyx_t_7; + } else { + __pyx_t_9 = __pyx_t_18; + } + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1613 + * f_x_low = f_x_low - 1 + * if f_x_low < 0 or f_back_high - f_x_low > self.train_max_initial_size: + * met_constraints = 0 # <<<<<<<<<<<<<< + * + * if (met_constraints and + */ + __pyx_v_met_constraints = 0; + goto __pyx_L68; + } + __pyx_L68:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1615 + * met_constraints = 0 + * + * if (met_constraints and # <<<<<<<<<<<<<< + * self.find_fixpoint(f_x_low, f_back_high, + * f_links_low, f_links_high, e_links_low, e_links_high, + */ + if (__pyx_v_met_constraints) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1616 + * + * if (met_constraints and + * self.find_fixpoint(f_x_low, f_back_high, # <<<<<<<<<<<<<< + * f_links_low, f_links_high, e_links_low, e_links_high, + * e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, + */ + __pyx_t_14 = PyInt_FromLong(__pyx_v_f_back_high); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1616; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1620 + * e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, + * f_sent_len, e_sent_len, + * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< + * 1, 1, 1, 1, 0, 1, 0) and + * ((not self.tight_phrases) or f_links_low[f_x_low] != -1) and + */ + if (((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_x_low, __pyx_t_14, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_e_low, __pyx_v_e_high, (&__pyx_v_e_x_low), (&__pyx_v_e_x_high), (&__pyx_v_f_x_low), (&__pyx_v_f_x_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 1, 1, 1, 1, 0, 1, 0)) { + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1622 + * self.train_max_initial_size, self.train_max_initial_size, + * 1, 1, 1, 1, 0, 1, 0) and + * ((not self.tight_phrases) or f_links_low[f_x_low] != -1) and # <<<<<<<<<<<<<< + * self.find_fixpoint(f_x_low, f_low, # check integrity of new subphrase + * f_links_low, f_links_high, e_links_low, e_links_high, + */ + __pyx_t_9 = (!__pyx_v_self->tight_phrases); + if (!__pyx_t_9) { + __pyx_t_18 = ((__pyx_v_f_links_low[__pyx_v_f_x_low]) != -1); + __pyx_t_7 = __pyx_t_18; + } else { + __pyx_t_7 = __pyx_t_9; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1623 + * 1, 1, 1, 1, 0, 1, 0) and + * ((not self.tight_phrases) or f_links_low[f_x_low] != -1) and + * self.find_fixpoint(f_x_low, f_low, # check integrity of new subphrase # <<<<<<<<<<<<<< + * f_links_low, f_links_high, e_links_low, e_links_high, + * -1, -1, e_gap_low, e_gap_high, f_gap_low, f_gap_high, + */ + __pyx_t_10 = PyInt_FromLong(__pyx_v_f_low); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1623; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1627 + * -1, -1, e_gap_low, e_gap_high, f_gap_low, f_gap_high, + * f_sent_len, e_sent_len, + * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< + * 0, 0, 0, 0, 0, 0, 0)): + * fphr_arr._clear() + */ + __pyx_t_9 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_x_low, __pyx_t_10, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, -1, -1, __pyx_v_e_gap_low, __pyx_v_e_gap_high, __pyx_v_f_gap_low, __pyx_v_f_gap_high, __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 0, 0, 0, 0, 0, 0, 0); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } else { + __pyx_t_9 = __pyx_t_7; + } + __pyx_t_7 = __pyx_t_9; + } else { + __pyx_t_7 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_x_low, __pyx_t_14, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_e_low, __pyx_v_e_high, (&__pyx_v_e_x_low), (&__pyx_v_e_x_high), (&__pyx_v_f_x_low), (&__pyx_v_f_x_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 1, 1, 1, 1, 0, 1, 0); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } + __pyx_t_9 = __pyx_t_7; + } else { + __pyx_t_9 = __pyx_v_met_constraints; + } + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1629 + * self.train_max_initial_size, self.train_max_initial_size, + * 0, 0, 0, 0, 0, 0, 0)): + * fphr_arr._clear() # <<<<<<<<<<<<<< + * i = 1 + * self.findexes.reset() + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_clear(__pyx_v_fphr_arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1630 + * 0, 0, 0, 0, 0, 0, 0)): + * fphr_arr._clear() + * i = 1 # <<<<<<<<<<<<<< + * self.findexes.reset() + * self.findexes.append(sym_setindex(self.category, i)) + */ + __pyx_v_i = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1631 + * fphr_arr._clear() + * i = 1 + * self.findexes.reset() # <<<<<<<<<<<<<< + * self.findexes.append(sym_setindex(self.category, i)) + * fphr_arr._append(sym_setindex(self.category, i)) + */ + __pyx_t_14 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__reset); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1631; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_10 = PyObject_Call(__pyx_t_14, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1631; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1632 + * i = 1 + * self.findexes.reset() + * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 + */ + __pyx_t_10 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1632; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_14 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_10); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1632; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1633 + * self.findexes.reset() + * self.findexes.append(sym_setindex(self.category, i)) + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * i = i+1 + * self.findexes.extend(self.findexes1) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1634 + * self.findexes.append(sym_setindex(self.category, i)) + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 # <<<<<<<<<<<<<< + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: + */ + __pyx_v_i = (__pyx_v_i + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1635 + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 + * self.findexes.extend(self.findexes1) # <<<<<<<<<<<<<< + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): + */ + __pyx_t_14 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__extend); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1635; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1635; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(((PyObject *)__pyx_v_self->findexes1)); + PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_v_self->findexes1)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->findexes1)); + __pyx_t_15 = PyObject_Call(__pyx_t_14, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1635; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1636 + * i = i+1 + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: # <<<<<<<<<<<<<< + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) + */ + __pyx_t_3 = __pyx_v_phrase->n; + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1637 + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i + 1 + */ + __pyx_t_15 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_isvar); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_10 = PyInt_FromLong((__pyx_v_phrase->syms[__pyx_v_j])); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_15, ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1638 + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * i = i + 1 + * else: + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1639 + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i + 1 # <<<<<<<<<<<<<< + * else: + * fphr_arr._append(phrase.syms[j]) + */ + __pyx_v_i = (__pyx_v_i + 1); + goto __pyx_L72; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1641 + * i = i + 1 + * else: + * fphr_arr._append(phrase.syms[j]) # <<<<<<<<<<<<<< + * if f_back_high > f_high: + * fphr_arr._append(sym_setindex(self.category, i)) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, (__pyx_v_phrase->syms[__pyx_v_j])); + } + __pyx_L72:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1642 + * else: + * fphr_arr._append(phrase.syms[j]) + * if f_back_high > f_high: # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) + */ + __pyx_t_9 = (__pyx_v_f_back_high > __pyx_v_f_high); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1643 + * fphr_arr._append(phrase.syms[j]) + * if f_back_high > f_high: + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * self.findexes.append(sym_setindex(self.category, i)) + * fphr = Phrase(fphr_arr) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1644 + * if f_back_high > f_high: + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * fphr = Phrase(fphr_arr) + * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+1, + */ + __pyx_t_10 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1644; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_14 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_10); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1644; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + goto __pyx_L73; + } + __pyx_L73:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1645 + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) + * fphr = Phrase(fphr_arr) # <<<<<<<<<<<<<< + * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+1, + * f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, matching.sent_id, + */ + __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1645; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_INCREF(((PyObject *)__pyx_v_fphr_arr)); + PyTuple_SET_ITEM(__pyx_t_14, 0, ((PyObject *)__pyx_v_fphr_arr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr_arr)); + __pyx_t_10 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1645; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_fphr)); + __pyx_v_fphr = ((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_t_10); + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1648 + * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+1, + * f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, matching.sent_id, + * e_sent_len, e_sent_start) # <<<<<<<<<<<<<< + * if len(phrase_list) > 0: + * pair_count = 1.0 / len(phrase_list) + */ + __pyx_t_10 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->extract_phrases(__pyx_v_self, __pyx_v_e_x_low, __pyx_v_e_x_high, __pyx_v_e_gap_low, __pyx_v_e_gap_high, __pyx_v_e_links_low, (__pyx_v_num_gaps + 1), __pyx_v_f_x_low, __pyx_v_f_x_high, __pyx_v_f_gap_low, __pyx_v_f_gap_high, __pyx_v_f_links_low, __pyx_v_matching->sent_id, __pyx_v_e_sent_len, __pyx_v_e_sent_start); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1646; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_v_phrase_list); + __pyx_v_phrase_list = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1649 + * f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, matching.sent_id, + * e_sent_len, e_sent_start) + * if len(phrase_list) > 0: # <<<<<<<<<<<<<< + * pair_count = 1.0 / len(phrase_list) + * else: + */ + __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1649; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = (__pyx_t_13 > 0); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1650 + * e_sent_len, e_sent_start) + * if len(phrase_list) > 0: + * pair_count = 1.0 / len(phrase_list) # <<<<<<<<<<<<<< + * else: + * pair_count = 0 + */ + __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1650; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__pyx_t_13 == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1650; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_pair_count = (1.0 / __pyx_t_13); + goto __pyx_L74; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1652 + * pair_count = 1.0 / len(phrase_list) + * else: + * pair_count = 0 # <<<<<<<<<<<<<< + * for phrase2,eindexes in phrase_list: + * als2 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + */ + __pyx_v_pair_count = 0.0; + } + __pyx_L74:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1653 + * else: + * pair_count = 0 + * for phrase2,eindexes in phrase_list: # <<<<<<<<<<<<<< + * als2 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + * extracts.append((fphr, phrase2, pair_count, tuple(als2))) + */ + if (PyList_CheckExact(__pyx_v_phrase_list) || PyTuple_CheckExact(__pyx_v_phrase_list)) { + __pyx_t_10 = __pyx_v_phrase_list; __Pyx_INCREF(__pyx_t_10); __pyx_t_13 = 0; + __pyx_t_16 = NULL; + } else { + __pyx_t_13 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_v_phrase_list); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_16 = Py_TYPE(__pyx_t_10)->tp_iternext; + } + for (;;) { + if (!__pyx_t_16 && PyList_CheckExact(__pyx_t_10)) { + if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_10)) break; + __pyx_t_14 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_13); __Pyx_INCREF(__pyx_t_14); __pyx_t_13++; + } else if (!__pyx_t_16 && PyTuple_CheckExact(__pyx_t_10)) { + if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_10)) break; + __pyx_t_14 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_13); __Pyx_INCREF(__pyx_t_14); __pyx_t_13++; + } else { + __pyx_t_14 = __pyx_t_16(__pyx_t_10); + if (unlikely(!__pyx_t_14)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_14); + } + if ((likely(PyTuple_CheckExact(__pyx_t_14))) || (PyList_CheckExact(__pyx_t_14))) { + PyObject* sequence = __pyx_t_14; + if (likely(PyTuple_CheckExact(sequence))) { + 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[8]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_15 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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[8]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_15 = PyList_GET_ITEM(sequence, 0); + __pyx_t_1 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_15); + __Pyx_INCREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_2 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_17 = Py_TYPE(__pyx_t_2)->tp_iternext; + index = 0; __pyx_t_15 = __pyx_t_17(__pyx_t_2); if (unlikely(!__pyx_t_15)) goto __pyx_L77_unpacking_failed; + __Pyx_GOTREF(__pyx_t_15); + index = 1; __pyx_t_1 = __pyx_t_17(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L77_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_2), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L78_unpacking_done; + __pyx_L77_unpacking_failed:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L78_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_phrase2); + __pyx_v_phrase2 = __pyx_t_15; + __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_v_eindexes); + __pyx_v_eindexes = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1654 + * pair_count = 0 + * for phrase2,eindexes in phrase_list: + * als2 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) # <<<<<<<<<<<<<< + * extracts.append((fphr, phrase2, pair_count, tuple(als2))) + * + */ + __pyx_t_14 = ((PyObject *)__pyx_v_self->findexes); + __Pyx_INCREF(__pyx_t_14); + __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->create_alignments(__pyx_v_self, __pyx_v_sent_links, __pyx_v_num_links, __pyx_t_14, __pyx_v_eindexes); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1654; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_v_als2); + __pyx_v_als2 = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1655 + * for phrase2,eindexes in phrase_list: + * als2 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + * extracts.append((fphr, phrase2, pair_count, tuple(als2))) # <<<<<<<<<<<<<< + * + * if (f_back_high == f_high and + */ + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_pair_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_INCREF(__pyx_v_als2); + PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_v_als2); + __Pyx_GIVEREF(__pyx_v_als2); + __pyx_t_15 = PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; + __pyx_t_14 = PyTuple_New(4); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_INCREF(((PyObject *)__pyx_v_fphr)); + PyTuple_SET_ITEM(__pyx_t_14, 0, ((PyObject *)__pyx_v_fphr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr)); + __Pyx_INCREF(__pyx_v_phrase2); + PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_v_phrase2); + __Pyx_GIVEREF(__pyx_v_phrase2); + PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_14, 3, __pyx_t_15); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_t_1 = 0; + __pyx_t_15 = 0; + __pyx_t_15 = __Pyx_PyObject_Append(__pyx_v_extracts, ((PyObject *)__pyx_t_14)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L69; + } + __pyx_L69:; + goto __pyx_L64; + } + __pyx_L64:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1657 + * extracts.append((fphr, phrase2, pair_count, tuple(als2))) + * + * if (f_back_high == f_high and # <<<<<<<<<<<<<< + * f_sent_len - f_high >= self.train_min_gap_size and + * ((not self.tight_phrases) or (f_links_low[f_high] != -1 and f_links_low[f_back_low] != -1))): + */ + __pyx_t_9 = (__pyx_v_f_back_high == __pyx_v_f_high); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1658 + * + * if (f_back_high == f_high and + * f_sent_len - f_high >= self.train_min_gap_size and # <<<<<<<<<<<<<< + * ((not self.tight_phrases) or (f_links_low[f_high] != -1 and f_links_low[f_back_low] != -1))): + * f_x_high = f_high+self.train_min_gap_size + */ + __pyx_t_7 = ((__pyx_v_f_sent_len - __pyx_v_f_high) >= __pyx_v_self->train_min_gap_size); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1659 + * if (f_back_high == f_high and + * f_sent_len - f_high >= self.train_min_gap_size and + * ((not self.tight_phrases) or (f_links_low[f_high] != -1 and f_links_low[f_back_low] != -1))): # <<<<<<<<<<<<<< + * f_x_high = f_high+self.train_min_gap_size + * met_constraints = 1 + */ + __pyx_t_18 = (!__pyx_v_self->tight_phrases); + if (!__pyx_t_18) { + __pyx_t_8 = ((__pyx_v_f_links_low[__pyx_v_f_high]) != -1); + if (__pyx_t_8) { + __pyx_t_20 = ((__pyx_v_f_links_low[__pyx_v_f_back_low]) != -1); + __pyx_t_19 = __pyx_t_20; + } else { + __pyx_t_19 = __pyx_t_8; + } + __pyx_t_8 = __pyx_t_19; + } else { + __pyx_t_8 = __pyx_t_18; + } + __pyx_t_18 = __pyx_t_8; + } else { + __pyx_t_18 = __pyx_t_7; + } + __pyx_t_7 = __pyx_t_18; + } else { + __pyx_t_7 = __pyx_t_9; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1660 + * f_sent_len - f_high >= self.train_min_gap_size and + * ((not self.tight_phrases) or (f_links_low[f_high] != -1 and f_links_low[f_back_low] != -1))): + * f_x_high = f_high+self.train_min_gap_size # <<<<<<<<<<<<<< + * met_constraints = 1 + * if self.tight_phrases: + */ + __pyx_v_f_x_high = (__pyx_v_f_high + __pyx_v_self->train_min_gap_size); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1661 + * ((not self.tight_phrases) or (f_links_low[f_high] != -1 and f_links_low[f_back_low] != -1))): + * f_x_high = f_high+self.train_min_gap_size + * met_constraints = 1 # <<<<<<<<<<<<<< + * if self.tight_phrases: + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: + */ + __pyx_v_met_constraints = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1662 + * f_x_high = f_high+self.train_min_gap_size + * met_constraints = 1 + * if self.tight_phrases: # <<<<<<<<<<<<<< + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: + * f_x_high = f_x_high + 1 + */ + if (__pyx_v_self->tight_phrases) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1663 + * met_constraints = 1 + * if self.tight_phrases: + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: # <<<<<<<<<<<<<< + * f_x_high = f_x_high + 1 + * if f_x_high > f_sent_len or f_x_high - f_back_low > self.train_max_initial_size: + */ + while (1) { + __pyx_t_7 = (__pyx_v_f_x_high <= __pyx_v_f_sent_len); + if (__pyx_t_7) { + __pyx_t_9 = ((__pyx_v_f_links_low[(__pyx_v_f_x_high - 1)]) == -1); + __pyx_t_18 = __pyx_t_9; + } else { + __pyx_t_18 = __pyx_t_7; + } + if (!__pyx_t_18) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1664 + * if self.tight_phrases: + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: + * f_x_high = f_x_high + 1 # <<<<<<<<<<<<<< + * if f_x_high > f_sent_len or f_x_high - f_back_low > self.train_max_initial_size: + * met_constraints = 0 + */ + __pyx_v_f_x_high = (__pyx_v_f_x_high + 1); + } + goto __pyx_L80; + } + __pyx_L80:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1665 + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: + * f_x_high = f_x_high + 1 + * if f_x_high > f_sent_len or f_x_high - f_back_low > self.train_max_initial_size: # <<<<<<<<<<<<<< + * met_constraints = 0 + * + */ + __pyx_t_18 = (__pyx_v_f_x_high > __pyx_v_f_sent_len); + if (!__pyx_t_18) { + __pyx_t_7 = ((__pyx_v_f_x_high - __pyx_v_f_back_low) > __pyx_v_self->train_max_initial_size); + __pyx_t_9 = __pyx_t_7; + } else { + __pyx_t_9 = __pyx_t_18; + } + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1666 + * f_x_high = f_x_high + 1 + * if f_x_high > f_sent_len or f_x_high - f_back_low > self.train_max_initial_size: + * met_constraints = 0 # <<<<<<<<<<<<<< + * + * if (met_constraints and + */ + __pyx_v_met_constraints = 0; + goto __pyx_L83; + } + __pyx_L83:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1668 + * met_constraints = 0 + * + * if (met_constraints and # <<<<<<<<<<<<<< + * self.find_fixpoint(f_back_low, f_x_high, + * f_links_low, f_links_high, e_links_low, e_links_high, + */ + if (__pyx_v_met_constraints) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1669 + * + * if (met_constraints and + * self.find_fixpoint(f_back_low, f_x_high, # <<<<<<<<<<<<<< + * f_links_low, f_links_high, e_links_low, e_links_high, + * e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, + */ + __pyx_t_10 = PyInt_FromLong(__pyx_v_f_x_high); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1669; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1673 + * e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, + * f_sent_len, e_sent_len, + * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< + * 1, 1, 1, 0, 1, 1, 0) and + * ((not self.tight_phrases) or f_links_low[f_x_high-1] != -1) and + */ + if (((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_back_low, __pyx_t_10, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_e_low, __pyx_v_e_high, (&__pyx_v_e_x_low), (&__pyx_v_e_x_high), (&__pyx_v_f_x_low), (&__pyx_v_f_x_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 1, 1, 1, 0, 1, 1, 0)) { + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1675 + * self.train_max_initial_size, self.train_max_initial_size, + * 1, 1, 1, 0, 1, 1, 0) and + * ((not self.tight_phrases) or f_links_low[f_x_high-1] != -1) and # <<<<<<<<<<<<<< + * self.find_fixpoint(f_high, f_x_high, + * f_links_low, f_links_high, e_links_low, e_links_high, + */ + __pyx_t_9 = (!__pyx_v_self->tight_phrases); + if (!__pyx_t_9) { + __pyx_t_18 = ((__pyx_v_f_links_low[(__pyx_v_f_x_high - 1)]) != -1); + __pyx_t_7 = __pyx_t_18; + } else { + __pyx_t_7 = __pyx_t_9; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1676 + * 1, 1, 1, 0, 1, 1, 0) and + * ((not self.tight_phrases) or f_links_low[f_x_high-1] != -1) and + * self.find_fixpoint(f_high, f_x_high, # <<<<<<<<<<<<<< + * f_links_low, f_links_high, e_links_low, e_links_high, + * -1, -1, e_gap_low+gap_start+num_gaps, e_gap_high+gap_start+num_gaps, + */ + __pyx_t_15 = PyInt_FromLong(__pyx_v_f_x_high); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1676; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1681 + * f_gap_low+gap_start+num_gaps, f_gap_high+gap_start+num_gaps, + * f_sent_len, e_sent_len, + * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< + * 0, 0, 0, 0, 0, 0, 0)): + * fphr_arr._clear() + */ + __pyx_t_9 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_high, __pyx_t_15, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, -1, -1, ((__pyx_v_e_gap_low + __pyx_v_gap_start) + __pyx_v_num_gaps), ((__pyx_v_e_gap_high + __pyx_v_gap_start) + __pyx_v_num_gaps), ((__pyx_v_f_gap_low + __pyx_v_gap_start) + __pyx_v_num_gaps), ((__pyx_v_f_gap_high + __pyx_v_gap_start) + __pyx_v_num_gaps), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 0, 0, 0, 0, 0, 0, 0); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } else { + __pyx_t_9 = __pyx_t_7; + } + __pyx_t_7 = __pyx_t_9; + } else { + __pyx_t_7 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_back_low, __pyx_t_10, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_e_low, __pyx_v_e_high, (&__pyx_v_e_x_low), (&__pyx_v_e_x_high), (&__pyx_v_f_x_low), (&__pyx_v_f_x_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 1, 1, 1, 0, 1, 1, 0); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __pyx_t_9 = __pyx_t_7; + } else { + __pyx_t_9 = __pyx_v_met_constraints; + } + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1683 + * self.train_max_initial_size, self.train_max_initial_size, + * 0, 0, 0, 0, 0, 0, 0)): + * fphr_arr._clear() # <<<<<<<<<<<<<< + * i = 1 + * self.findexes.reset() + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_clear(__pyx_v_fphr_arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1684 + * 0, 0, 0, 0, 0, 0, 0)): + * fphr_arr._clear() + * i = 1 # <<<<<<<<<<<<<< + * self.findexes.reset() + * if f_back_low < f_low: + */ + __pyx_v_i = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1685 + * fphr_arr._clear() + * i = 1 + * self.findexes.reset() # <<<<<<<<<<<<<< + * if f_back_low < f_low: + * fphr_arr._append(sym_setindex(self.category, i)) + */ + __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__reset); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1685; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_15 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1685; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1686 + * i = 1 + * self.findexes.reset() + * if f_back_low < f_low: # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 + */ + __pyx_t_9 = (__pyx_v_f_back_low < __pyx_v_f_low); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1687 + * self.findexes.reset() + * if f_back_low < f_low: + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * i = i+1 + * self.findexes.append(sym_setindex(self.category, i)) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1688 + * if f_back_low < f_low: + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 # <<<<<<<<<<<<<< + * self.findexes.append(sym_setindex(self.category, i)) + * self.findexes.extend(self.findexes1) + */ + __pyx_v_i = (__pyx_v_i + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1689 + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 + * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: + */ + __pyx_t_15 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1689; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_10 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_15); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1689; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L85; + } + __pyx_L85:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1690 + * i = i+1 + * self.findexes.append(sym_setindex(self.category, i)) + * self.findexes.extend(self.findexes1) # <<<<<<<<<<<<<< + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): + */ + __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__extend); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1690; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1690; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(((PyObject *)__pyx_v_self->findexes1)); + PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)__pyx_v_self->findexes1)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->findexes1)); + __pyx_t_14 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1690; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1691 + * self.findexes.append(sym_setindex(self.category, i)) + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: # <<<<<<<<<<<<<< + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) + */ + __pyx_t_3 = __pyx_v_phrase->n; + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1692 + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i + 1 + */ + __pyx_t_14 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_isvar); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = PyInt_FromLong((__pyx_v_phrase->syms[__pyx_v_j])); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_15); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_t_15 = 0; + __pyx_t_15 = PyObject_Call(__pyx_t_14, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1693 + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * i = i + 1 + * else: + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1694 + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i + 1 # <<<<<<<<<<<<<< + * else: + * fphr_arr._append(phrase.syms[j]) + */ + __pyx_v_i = (__pyx_v_i + 1); + goto __pyx_L88; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1696 + * i = i + 1 + * else: + * fphr_arr._append(phrase.syms[j]) # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, (__pyx_v_phrase->syms[__pyx_v_j])); + } + __pyx_L88:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1697 + * else: + * fphr_arr._append(phrase.syms[j]) + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * self.findexes.append(sym_setindex(self.category, i)) + * fphr = Phrase(fphr_arr) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1698 + * fphr_arr._append(phrase.syms[j]) + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * fphr = Phrase(fphr_arr) + * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low+gap_start, e_gap_high+gap_start, e_links_low, num_gaps+1, + */ + __pyx_t_15 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1698; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_10 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_15); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1698; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1699 + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) + * fphr = Phrase(fphr_arr) # <<<<<<<<<<<<<< + * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low+gap_start, e_gap_high+gap_start, e_links_low, num_gaps+1, + * f_x_low, f_x_high, f_gap_low+gap_start, f_gap_high+gap_start, f_links_low, + */ + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1699; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(((PyObject *)__pyx_v_fphr_arr)); + PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_v_fphr_arr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr_arr)); + __pyx_t_15 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1699; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_fphr)); + __pyx_v_fphr = ((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_t_15); + __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1702 + * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low+gap_start, e_gap_high+gap_start, e_links_low, num_gaps+1, + * f_x_low, f_x_high, f_gap_low+gap_start, f_gap_high+gap_start, f_links_low, + * matching.sent_id, e_sent_len, e_sent_start) # <<<<<<<<<<<<<< + * if len(phrase_list) > 0: + * pair_count = 1.0 / len(phrase_list) + */ + __pyx_t_15 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->extract_phrases(__pyx_v_self, __pyx_v_e_x_low, __pyx_v_e_x_high, (__pyx_v_e_gap_low + __pyx_v_gap_start), (__pyx_v_e_gap_high + __pyx_v_gap_start), __pyx_v_e_links_low, (__pyx_v_num_gaps + 1), __pyx_v_f_x_low, __pyx_v_f_x_high, (__pyx_v_f_gap_low + __pyx_v_gap_start), (__pyx_v_f_gap_high + __pyx_v_gap_start), __pyx_v_f_links_low, __pyx_v_matching->sent_id, __pyx_v_e_sent_len, __pyx_v_e_sent_start); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_XDECREF(__pyx_v_phrase_list); + __pyx_v_phrase_list = __pyx_t_15; + __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1703 + * f_x_low, f_x_high, f_gap_low+gap_start, f_gap_high+gap_start, f_links_low, + * matching.sent_id, e_sent_len, e_sent_start) + * if len(phrase_list) > 0: # <<<<<<<<<<<<<< + * pair_count = 1.0 / len(phrase_list) + * else: + */ + __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1703; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = (__pyx_t_13 > 0); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1704 + * matching.sent_id, e_sent_len, e_sent_start) + * if len(phrase_list) > 0: + * pair_count = 1.0 / len(phrase_list) # <<<<<<<<<<<<<< + * else: + * pair_count = 0 + */ + __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1704; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__pyx_t_13 == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1704; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_pair_count = (1.0 / __pyx_t_13); + goto __pyx_L89; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1706 + * pair_count = 1.0 / len(phrase_list) + * else: + * pair_count = 0 # <<<<<<<<<<<<<< + * for phrase2, eindexes in phrase_list: + * als3 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + */ + __pyx_v_pair_count = 0.0; + } + __pyx_L89:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1707 + * else: + * pair_count = 0 + * for phrase2, eindexes in phrase_list: # <<<<<<<<<<<<<< + * als3 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + * extracts.append((fphr, phrase2, pair_count, tuple(als3))) + */ + if (PyList_CheckExact(__pyx_v_phrase_list) || PyTuple_CheckExact(__pyx_v_phrase_list)) { + __pyx_t_15 = __pyx_v_phrase_list; __Pyx_INCREF(__pyx_t_15); __pyx_t_13 = 0; + __pyx_t_16 = NULL; + } else { + __pyx_t_13 = -1; __pyx_t_15 = PyObject_GetIter(__pyx_v_phrase_list); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_16 = Py_TYPE(__pyx_t_15)->tp_iternext; + } + for (;;) { + if (!__pyx_t_16 && PyList_CheckExact(__pyx_t_15)) { + if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_15)) break; + __pyx_t_10 = PyList_GET_ITEM(__pyx_t_15, __pyx_t_13); __Pyx_INCREF(__pyx_t_10); __pyx_t_13++; + } else if (!__pyx_t_16 && PyTuple_CheckExact(__pyx_t_15)) { + if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_15)) break; + __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_15, __pyx_t_13); __Pyx_INCREF(__pyx_t_10); __pyx_t_13++; + } else { + __pyx_t_10 = __pyx_t_16(__pyx_t_15); + if (unlikely(!__pyx_t_10)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_10); + } + if ((likely(PyTuple_CheckExact(__pyx_t_10))) || (PyList_CheckExact(__pyx_t_10))) { + PyObject* sequence = __pyx_t_10; + if (likely(PyTuple_CheckExact(sequence))) { + 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[8]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_14 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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[8]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_14 = PyList_GET_ITEM(sequence, 0); + __pyx_t_1 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_2 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_17 = Py_TYPE(__pyx_t_2)->tp_iternext; + index = 0; __pyx_t_14 = __pyx_t_17(__pyx_t_2); if (unlikely(!__pyx_t_14)) goto __pyx_L92_unpacking_failed; + __Pyx_GOTREF(__pyx_t_14); + index = 1; __pyx_t_1 = __pyx_t_17(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L92_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_2), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L93_unpacking_done; + __pyx_L92_unpacking_failed:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L93_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_phrase2); + __pyx_v_phrase2 = __pyx_t_14; + __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_v_eindexes); + __pyx_v_eindexes = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1708 + * pair_count = 0 + * for phrase2, eindexes in phrase_list: + * als3 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) # <<<<<<<<<<<<<< + * extracts.append((fphr, phrase2, pair_count, tuple(als3))) + * if (num_gaps < self.max_nonterminals - 1 and + */ + __pyx_t_10 = ((PyObject *)__pyx_v_self->findexes); + __Pyx_INCREF(__pyx_t_10); + __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->create_alignments(__pyx_v_self, __pyx_v_sent_links, __pyx_v_num_links, __pyx_t_10, __pyx_v_eindexes); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_v_als3); + __pyx_v_als3 = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1709 + * for phrase2, eindexes in phrase_list: + * als3 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + * extracts.append((fphr, phrase2, pair_count, tuple(als3))) # <<<<<<<<<<<<<< + * if (num_gaps < self.max_nonterminals - 1 and + * phrase_len+1 < self.max_length and + */ + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_pair_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_v_als3); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_als3); + __Pyx_GIVEREF(__pyx_v_als3); + __pyx_t_14 = PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __pyx_t_10 = PyTuple_New(4); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(((PyObject *)__pyx_v_fphr)); + PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_v_fphr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr)); + __Pyx_INCREF(__pyx_v_phrase2); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_phrase2); + __Pyx_GIVEREF(__pyx_v_phrase2); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_t_1 = 0; + __pyx_t_14 = 0; + __pyx_t_14 = __Pyx_PyObject_Append(__pyx_v_extracts, ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + goto __pyx_L84; + } + __pyx_L84:; + goto __pyx_L79; + } + __pyx_L79:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1710 + * als3 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + * extracts.append((fphr, phrase2, pair_count, tuple(als3))) + * if (num_gaps < self.max_nonterminals - 1 and # <<<<<<<<<<<<<< + * phrase_len+1 < self.max_length and + * f_back_high == f_high and + */ + __pyx_t_9 = (__pyx_v_num_gaps < (__pyx_v_self->max_nonterminals - 1)); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1711 + * extracts.append((fphr, phrase2, pair_count, tuple(als3))) + * if (num_gaps < self.max_nonterminals - 1 and + * phrase_len+1 < self.max_length and # <<<<<<<<<<<<<< + * f_back_high == f_high and + * f_back_low == f_low and + */ + __pyx_t_7 = ((__pyx_v_phrase_len + 1) < __pyx_v_self->max_length); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1712 + * if (num_gaps < self.max_nonterminals - 1 and + * phrase_len+1 < self.max_length and + * f_back_high == f_high and # <<<<<<<<<<<<<< + * f_back_low == f_low and + * f_back_high - f_back_low + (2*self.train_min_gap_size) <= self.train_max_initial_size and + */ + __pyx_t_18 = (__pyx_v_f_back_high == __pyx_v_f_high); + if (__pyx_t_18) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1713 + * phrase_len+1 < self.max_length and + * f_back_high == f_high and + * f_back_low == f_low and # <<<<<<<<<<<<<< + * f_back_high - f_back_low + (2*self.train_min_gap_size) <= self.train_max_initial_size and + * f_low >= self.train_min_gap_size and + */ + __pyx_t_8 = (__pyx_v_f_back_low == __pyx_v_f_low); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1714 + * f_back_high == f_high and + * f_back_low == f_low and + * f_back_high - f_back_low + (2*self.train_min_gap_size) <= self.train_max_initial_size and # <<<<<<<<<<<<<< + * f_low >= self.train_min_gap_size and + * f_high <= f_sent_len - self.train_min_gap_size and + */ + __pyx_t_19 = (((__pyx_v_f_back_high - __pyx_v_f_back_low) + (2 * __pyx_v_self->train_min_gap_size)) <= __pyx_v_self->train_max_initial_size); + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1715 + * f_back_low == f_low and + * f_back_high - f_back_low + (2*self.train_min_gap_size) <= self.train_max_initial_size and + * f_low >= self.train_min_gap_size and # <<<<<<<<<<<<<< + * f_high <= f_sent_len - self.train_min_gap_size and + * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_high] != -1))): + */ + __pyx_t_20 = (__pyx_v_f_low >= __pyx_v_self->train_min_gap_size); + if (__pyx_t_20) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1716 + * f_back_high - f_back_low + (2*self.train_min_gap_size) <= self.train_max_initial_size and + * f_low >= self.train_min_gap_size and + * f_high <= f_sent_len - self.train_min_gap_size and # <<<<<<<<<<<<<< + * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_high] != -1))): + * + */ + __pyx_t_21 = (__pyx_v_f_high <= (__pyx_v_f_sent_len - __pyx_v_self->train_min_gap_size)); + if (__pyx_t_21) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1717 + * f_low >= self.train_min_gap_size and + * f_high <= f_sent_len - self.train_min_gap_size and + * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_high] != -1))): # <<<<<<<<<<<<<< + * + * met_constraints = 1 + */ + __pyx_t_22 = (!__pyx_v_self->tight_phrases); + if (!__pyx_t_22) { + __pyx_t_23 = ((__pyx_v_f_links_low[(__pyx_v_f_low - 1)]) != -1); + if (__pyx_t_23) { + __pyx_t_24 = ((__pyx_v_f_links_low[__pyx_v_f_high]) != -1); + __pyx_t_25 = __pyx_t_24; + } else { + __pyx_t_25 = __pyx_t_23; + } + __pyx_t_23 = __pyx_t_25; + } else { + __pyx_t_23 = __pyx_t_22; + } + __pyx_t_22 = __pyx_t_23; + } else { + __pyx_t_22 = __pyx_t_21; + } + __pyx_t_21 = __pyx_t_22; + } else { + __pyx_t_21 = __pyx_t_20; + } + __pyx_t_20 = __pyx_t_21; + } else { + __pyx_t_20 = __pyx_t_19; + } + __pyx_t_19 = __pyx_t_20; + } else { + __pyx_t_19 = __pyx_t_8; + } + __pyx_t_8 = __pyx_t_19; + } else { + __pyx_t_8 = __pyx_t_18; + } + __pyx_t_18 = __pyx_t_8; + } else { + __pyx_t_18 = __pyx_t_7; + } + __pyx_t_7 = __pyx_t_18; + } else { + __pyx_t_7 = __pyx_t_9; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1719 + * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_high] != -1))): + * + * met_constraints = 1 # <<<<<<<<<<<<<< + * f_x_low = f_low-self.train_min_gap_size + * if self.tight_phrases: + */ + __pyx_v_met_constraints = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1720 + * + * met_constraints = 1 + * f_x_low = f_low-self.train_min_gap_size # <<<<<<<<<<<<<< + * if self.tight_phrases: + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: + */ + __pyx_v_f_x_low = (__pyx_v_f_low - __pyx_v_self->train_min_gap_size); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1721 + * met_constraints = 1 + * f_x_low = f_low-self.train_min_gap_size + * if self.tight_phrases: # <<<<<<<<<<<<<< + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: + * f_x_low = f_x_low - 1 + */ + if (__pyx_v_self->tight_phrases) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1722 + * f_x_low = f_low-self.train_min_gap_size + * if self.tight_phrases: + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: # <<<<<<<<<<<<<< + * f_x_low = f_x_low - 1 + * if f_x_low < 0: + */ + while (1) { + __pyx_t_7 = (__pyx_v_f_x_low >= 0); + if (__pyx_t_7) { + __pyx_t_9 = ((__pyx_v_f_links_low[__pyx_v_f_x_low]) == -1); + __pyx_t_18 = __pyx_t_9; + } else { + __pyx_t_18 = __pyx_t_7; + } + if (!__pyx_t_18) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1723 + * if self.tight_phrases: + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: + * f_x_low = f_x_low - 1 # <<<<<<<<<<<<<< + * if f_x_low < 0: + * met_constraints = 0 + */ + __pyx_v_f_x_low = (__pyx_v_f_x_low - 1); + } + goto __pyx_L95; + } + __pyx_L95:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1724 + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: + * f_x_low = f_x_low - 1 + * if f_x_low < 0: # <<<<<<<<<<<<<< + * met_constraints = 0 + * + */ + __pyx_t_18 = (__pyx_v_f_x_low < 0); + if (__pyx_t_18) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1725 + * f_x_low = f_x_low - 1 + * if f_x_low < 0: + * met_constraints = 0 # <<<<<<<<<<<<<< + * + * f_x_high = f_high+self.train_min_gap_size + */ + __pyx_v_met_constraints = 0; + goto __pyx_L98; + } + __pyx_L98:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1727 + * met_constraints = 0 + * + * f_x_high = f_high+self.train_min_gap_size # <<<<<<<<<<<<<< + * if self.tight_phrases: + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: + */ + __pyx_v_f_x_high = (__pyx_v_f_high + __pyx_v_self->train_min_gap_size); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1728 + * + * f_x_high = f_high+self.train_min_gap_size + * if self.tight_phrases: # <<<<<<<<<<<<<< + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: + * f_x_high = f_x_high + 1 + */ + if (__pyx_v_self->tight_phrases) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1729 + * f_x_high = f_high+self.train_min_gap_size + * if self.tight_phrases: + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: # <<<<<<<<<<<<<< + * f_x_high = f_x_high + 1 + * if f_x_high > f_sent_len or f_x_high - f_x_low > self.train_max_initial_size: + */ + while (1) { + __pyx_t_18 = (__pyx_v_f_x_high <= __pyx_v_f_sent_len); + if (__pyx_t_18) { + __pyx_t_7 = ((__pyx_v_f_links_low[(__pyx_v_f_x_high - 1)]) == -1); + __pyx_t_9 = __pyx_t_7; + } else { + __pyx_t_9 = __pyx_t_18; + } + if (!__pyx_t_9) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1730 + * if self.tight_phrases: + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: + * f_x_high = f_x_high + 1 # <<<<<<<<<<<<<< + * if f_x_high > f_sent_len or f_x_high - f_x_low > self.train_max_initial_size: + * met_constraints = 0 + */ + __pyx_v_f_x_high = (__pyx_v_f_x_high + 1); + } + goto __pyx_L99; + } + __pyx_L99:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1731 + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: + * f_x_high = f_x_high + 1 + * if f_x_high > f_sent_len or f_x_high - f_x_low > self.train_max_initial_size: # <<<<<<<<<<<<<< + * met_constraints = 0 + * + */ + __pyx_t_9 = (__pyx_v_f_x_high > __pyx_v_f_sent_len); + if (!__pyx_t_9) { + __pyx_t_18 = ((__pyx_v_f_x_high - __pyx_v_f_x_low) > __pyx_v_self->train_max_initial_size); + __pyx_t_7 = __pyx_t_18; + } else { + __pyx_t_7 = __pyx_t_9; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1732 + * f_x_high = f_x_high + 1 + * if f_x_high > f_sent_len or f_x_high - f_x_low > self.train_max_initial_size: + * met_constraints = 0 # <<<<<<<<<<<<<< + * + * if (met_constraints and + */ + __pyx_v_met_constraints = 0; + goto __pyx_L102; + } + __pyx_L102:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1734 + * met_constraints = 0 + * + * if (met_constraints and # <<<<<<<<<<<<<< + * self.find_fixpoint(f_x_low, f_x_high, + * f_links_low, f_links_high, e_links_low, e_links_high, + */ + if (__pyx_v_met_constraints) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1735 + * + * if (met_constraints and + * self.find_fixpoint(f_x_low, f_x_high, # <<<<<<<<<<<<<< + * f_links_low, f_links_high, e_links_low, e_links_high, + * e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, + */ + __pyx_t_15 = PyInt_FromLong(__pyx_v_f_x_high); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1735; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1739 + * e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, + * f_sent_len, e_sent_len, + * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< + * 1, 1, 2, 1, 1, 1, 1) and + * ((not self.tight_phrases) or (f_links_low[f_x_low] != -1 and f_links_low[f_x_high-1] != -1)) and + */ + if (((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_x_low, __pyx_t_15, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_e_low, __pyx_v_e_high, (&__pyx_v_e_x_low), (&__pyx_v_e_x_high), (&__pyx_v_f_x_low), (&__pyx_v_f_x_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 1, 1, 2, 1, 1, 1, 1)) { + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1741 + * self.train_max_initial_size, self.train_max_initial_size, + * 1, 1, 2, 1, 1, 1, 1) and + * ((not self.tight_phrases) or (f_links_low[f_x_low] != -1 and f_links_low[f_x_high-1] != -1)) and # <<<<<<<<<<<<<< + * self.find_fixpoint(f_x_low, f_low, + * f_links_low, f_links_high, e_links_low, e_links_high, + */ + __pyx_t_7 = (!__pyx_v_self->tight_phrases); + if (!__pyx_t_7) { + __pyx_t_9 = ((__pyx_v_f_links_low[__pyx_v_f_x_low]) != -1); + if (__pyx_t_9) { + __pyx_t_18 = ((__pyx_v_f_links_low[(__pyx_v_f_x_high - 1)]) != -1); + __pyx_t_8 = __pyx_t_18; + } else { + __pyx_t_8 = __pyx_t_9; + } + __pyx_t_9 = __pyx_t_8; + } else { + __pyx_t_9 = __pyx_t_7; + } + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1742 + * 1, 1, 2, 1, 1, 1, 1) and + * ((not self.tight_phrases) or (f_links_low[f_x_low] != -1 and f_links_low[f_x_high-1] != -1)) and + * self.find_fixpoint(f_x_low, f_low, # <<<<<<<<<<<<<< + * f_links_low, f_links_high, e_links_low, e_links_high, + * -1, -1, e_gap_low, e_gap_high, f_gap_low, f_gap_high, + */ + __pyx_t_14 = PyInt_FromLong(__pyx_v_f_low); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1742; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1746 + * -1, -1, e_gap_low, e_gap_high, f_gap_low, f_gap_high, + * f_sent_len, e_sent_len, + * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< + * 0, 0, 0, 0, 0, 0, 0) and + * self.find_fixpoint(f_high, f_x_high, + */ + __pyx_t_3 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_x_low, __pyx_t_14, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, -1, -1, __pyx_v_e_gap_low, __pyx_v_e_gap_high, __pyx_v_f_gap_low, __pyx_v_f_gap_high, __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 0, 0, 0, 0, 0, 0, 0); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1748 + * self.train_max_initial_size, self.train_max_initial_size, + * 0, 0, 0, 0, 0, 0, 0) and + * self.find_fixpoint(f_high, f_x_high, # <<<<<<<<<<<<<< + * f_links_low, f_links_high, e_links_low, e_links_high, + * -1, -1, e_gap_low+1+num_gaps, e_gap_high+1+num_gaps, + */ + __pyx_t_14 = PyInt_FromLong(__pyx_v_f_x_high); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1753 + * f_gap_low+1+num_gaps, f_gap_high+1+num_gaps, + * f_sent_len, e_sent_len, + * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< + * 0, 0, 0, 0, 0, 0, 0)): + * fphr_arr._clear() + */ + __pyx_t_4 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_high, __pyx_t_14, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, -1, -1, ((__pyx_v_e_gap_low + 1) + __pyx_v_num_gaps), ((__pyx_v_e_gap_high + 1) + __pyx_v_num_gaps), ((__pyx_v_f_gap_low + 1) + __pyx_v_num_gaps), ((__pyx_v_f_gap_high + 1) + __pyx_v_num_gaps), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 0, 0, 0, 0, 0, 0, 0); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_7 = __pyx_t_4; + } else { + __pyx_t_7 = __pyx_t_3; + } + __pyx_t_8 = __pyx_t_7; + } else { + __pyx_t_8 = __pyx_t_9; + } + __pyx_t_9 = __pyx_t_8; + } else { + __pyx_t_9 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_x_low, __pyx_t_15, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_e_low, __pyx_v_e_high, (&__pyx_v_e_x_low), (&__pyx_v_e_x_high), (&__pyx_v_f_x_low), (&__pyx_v_f_x_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 1, 1, 2, 1, 1, 1, 1); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } + __pyx_t_8 = __pyx_t_9; + } else { + __pyx_t_8 = __pyx_v_met_constraints; + } + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1755 + * self.train_max_initial_size, self.train_max_initial_size, + * 0, 0, 0, 0, 0, 0, 0)): + * fphr_arr._clear() # <<<<<<<<<<<<<< + * i = 1 + * self.findexes.reset() + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_clear(__pyx_v_fphr_arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1756 + * 0, 0, 0, 0, 0, 0, 0)): + * fphr_arr._clear() + * i = 1 # <<<<<<<<<<<<<< + * self.findexes.reset() + * self.findexes.append(sym_setindex(self.category, i)) + */ + __pyx_v_i = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1757 + * fphr_arr._clear() + * i = 1 + * self.findexes.reset() # <<<<<<<<<<<<<< + * self.findexes.append(sym_setindex(self.category, i)) + * fphr_arr._append(sym_setindex(self.category, i)) + */ + __pyx_t_15 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__reset); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1757; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_14 = PyObject_Call(__pyx_t_15, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1757; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1758 + * i = 1 + * self.findexes.reset() + * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 + */ + __pyx_t_14 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1758; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_14); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1758; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1759 + * self.findexes.reset() + * self.findexes.append(sym_setindex(self.category, i)) + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * i = i+1 + * self.findexes.extend(self.findexes1) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1760 + * self.findexes.append(sym_setindex(self.category, i)) + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 # <<<<<<<<<<<<<< + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: + */ + __pyx_v_i = (__pyx_v_i + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1761 + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 + * self.findexes.extend(self.findexes1) # <<<<<<<<<<<<<< + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): + */ + __pyx_t_15 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__extend); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1761; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1761; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_INCREF(((PyObject *)__pyx_v_self->findexes1)); + PyTuple_SET_ITEM(__pyx_t_14, 0, ((PyObject *)__pyx_v_self->findexes1)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->findexes1)); + __pyx_t_10 = PyObject_Call(__pyx_t_15, ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1761; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1762 + * i = i+1 + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: # <<<<<<<<<<<<<< + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) + */ + __pyx_t_3 = __pyx_v_phrase->n; + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1763 + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i + 1 + */ + __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_isvar); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1763; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_14 = PyInt_FromLong((__pyx_v_phrase->syms[__pyx_v_j])); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1763; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1763; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_t_14 = 0; + __pyx_t_14 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1763; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1763; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1764 + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * i = i + 1 + * else: + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1765 + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i + 1 # <<<<<<<<<<<<<< + * else: + * fphr_arr._append(phrase.syms[j]) + */ + __pyx_v_i = (__pyx_v_i + 1); + goto __pyx_L106; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1767 + * i = i + 1 + * else: + * fphr_arr._append(phrase.syms[j]) # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, (__pyx_v_phrase->syms[__pyx_v_j])); + } + __pyx_L106:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1768 + * else: + * fphr_arr._append(phrase.syms[j]) + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * self.findexes.append(sym_setindex(self.category, i)) + * fphr = Phrase(fphr_arr) + */ + ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1769 + * fphr_arr._append(phrase.syms[j]) + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * fphr = Phrase(fphr_arr) + * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+2, + */ + __pyx_t_14 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1769; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_14); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1769; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1770 + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) + * fphr = Phrase(fphr_arr) # <<<<<<<<<<<<<< + * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+2, + * f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, + */ + __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1770; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(((PyObject *)__pyx_v_fphr_arr)); + PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)__pyx_v_fphr_arr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr_arr)); + __pyx_t_14 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1770; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_fphr)); + __pyx_v_fphr = ((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_t_14); + __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1773 + * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+2, + * f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, + * matching.sent_id, e_sent_len, e_sent_start) # <<<<<<<<<<<<<< + * if len(phrase_list) > 0: + * pair_count = 1.0 / len(phrase_list) + */ + __pyx_t_14 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->extract_phrases(__pyx_v_self, __pyx_v_e_x_low, __pyx_v_e_x_high, __pyx_v_e_gap_low, __pyx_v_e_gap_high, __pyx_v_e_links_low, (__pyx_v_num_gaps + 2), __pyx_v_f_x_low, __pyx_v_f_x_high, __pyx_v_f_gap_low, __pyx_v_f_gap_high, __pyx_v_f_links_low, __pyx_v_matching->sent_id, __pyx_v_e_sent_len, __pyx_v_e_sent_start); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1771; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_XDECREF(__pyx_v_phrase_list); + __pyx_v_phrase_list = __pyx_t_14; + __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1774 + * f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, + * matching.sent_id, e_sent_len, e_sent_start) + * if len(phrase_list) > 0: # <<<<<<<<<<<<<< + * pair_count = 1.0 / len(phrase_list) + * else: + */ + __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1774; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = (__pyx_t_13 > 0); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1775 + * matching.sent_id, e_sent_len, e_sent_start) + * if len(phrase_list) > 0: + * pair_count = 1.0 / len(phrase_list) # <<<<<<<<<<<<<< + * else: + * pair_count = 0 + */ + __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1775; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__pyx_t_13 == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1775; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_pair_count = (1.0 / __pyx_t_13); + goto __pyx_L107; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1777 + * pair_count = 1.0 / len(phrase_list) + * else: + * pair_count = 0 # <<<<<<<<<<<<<< + * for phrase2, eindexes in phrase_list: + * als4 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + */ + __pyx_v_pair_count = 0.0; + } + __pyx_L107:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1778 + * else: + * pair_count = 0 + * for phrase2, eindexes in phrase_list: # <<<<<<<<<<<<<< + * als4 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + * extracts.append((fphr, phrase2, pair_count, tuple(als4))) + */ + if (PyList_CheckExact(__pyx_v_phrase_list) || PyTuple_CheckExact(__pyx_v_phrase_list)) { + __pyx_t_14 = __pyx_v_phrase_list; __Pyx_INCREF(__pyx_t_14); __pyx_t_13 = 0; + __pyx_t_16 = NULL; + } else { + __pyx_t_13 = -1; __pyx_t_14 = PyObject_GetIter(__pyx_v_phrase_list); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_16 = Py_TYPE(__pyx_t_14)->tp_iternext; + } + for (;;) { + if (!__pyx_t_16 && PyList_CheckExact(__pyx_t_14)) { + if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_14)) break; + __pyx_t_15 = PyList_GET_ITEM(__pyx_t_14, __pyx_t_13); __Pyx_INCREF(__pyx_t_15); __pyx_t_13++; + } else if (!__pyx_t_16 && PyTuple_CheckExact(__pyx_t_14)) { + if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_14)) break; + __pyx_t_15 = PyTuple_GET_ITEM(__pyx_t_14, __pyx_t_13); __Pyx_INCREF(__pyx_t_15); __pyx_t_13++; + } else { + __pyx_t_15 = __pyx_t_16(__pyx_t_14); + if (unlikely(!__pyx_t_15)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_15); + } + if ((likely(PyTuple_CheckExact(__pyx_t_15))) || (PyList_CheckExact(__pyx_t_15))) { + PyObject* sequence = __pyx_t_15; + if (likely(PyTuple_CheckExact(sequence))) { + 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[8]; __pyx_lineno = 1778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); + } else { + 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[8]; __pyx_lineno = 1778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_10 = PyList_GET_ITEM(sequence, 0); + __pyx_t_1 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_2 = PyObject_GetIter(__pyx_t_15); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_17 = Py_TYPE(__pyx_t_2)->tp_iternext; + index = 0; __pyx_t_10 = __pyx_t_17(__pyx_t_2); if (unlikely(!__pyx_t_10)) goto __pyx_L110_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + index = 1; __pyx_t_1 = __pyx_t_17(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L110_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_2), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L111_unpacking_done; + __pyx_L110_unpacking_failed:; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L111_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_phrase2); + __pyx_v_phrase2 = __pyx_t_10; + __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_v_eindexes); + __pyx_v_eindexes = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1779 + * pair_count = 0 + * for phrase2, eindexes in phrase_list: + * als4 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) # <<<<<<<<<<<<<< + * extracts.append((fphr, phrase2, pair_count, tuple(als4))) + * else: + */ + __pyx_t_15 = ((PyObject *)__pyx_v_self->findexes); + __Pyx_INCREF(__pyx_t_15); + __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->create_alignments(__pyx_v_self, __pyx_v_sent_links, __pyx_v_num_links, __pyx_t_15, __pyx_v_eindexes); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1779; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_v_als4); + __pyx_v_als4 = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1780 + * for phrase2, eindexes in phrase_list: + * als4 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + * extracts.append((fphr, phrase2, pair_count, tuple(als4))) # <<<<<<<<<<<<<< + * else: + * reason_for_failure = "Unable to extract basic phrase" + */ + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_pair_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1780; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1780; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(__pyx_v_als4); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_als4); + __Pyx_GIVEREF(__pyx_v_als4); + __pyx_t_10 = PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1780; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __pyx_t_15 = PyTuple_New(4); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1780; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(((PyObject *)__pyx_v_fphr)); + PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)__pyx_v_fphr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr)); + __Pyx_INCREF(__pyx_v_phrase2); + PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_v_phrase2); + __Pyx_GIVEREF(__pyx_v_phrase2); + PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_t_1 = 0; + __pyx_t_10 = 0; + __pyx_t_10 = __Pyx_PyObject_Append(__pyx_v_extracts, ((PyObject *)__pyx_t_15)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1780; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + goto __pyx_L103; + } + __pyx_L103:; + goto __pyx_L94; + } + __pyx_L94:; + goto __pyx_L63; + } + __pyx_L63:; + goto __pyx_L51; + } + __pyx_L51:; + goto __pyx_L34; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1782 + * extracts.append((fphr, phrase2, pair_count, tuple(als4))) + * else: + * reason_for_failure = "Unable to extract basic phrase" # <<<<<<<<<<<<<< + * + * free(sent_links) + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_131)); + __Pyx_DECREF(__pyx_v_reason_for_failure); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_131); + } + __pyx_L34:; + goto __pyx_L33; + } + __pyx_L33:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1784 + * reason_for_failure = "Unable to extract basic phrase" + * + * free(sent_links) # <<<<<<<<<<<<<< + * free(f_links_low) + * free(f_links_high) + */ + free(__pyx_v_sent_links); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1785 + * + * free(sent_links) + * free(f_links_low) # <<<<<<<<<<<<<< + * free(f_links_high) + * free(e_links_low) + */ + free(__pyx_v_f_links_low); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1786 + * free(sent_links) + * free(f_links_low) + * free(f_links_high) # <<<<<<<<<<<<<< + * free(e_links_low) + * free(e_links_high) + */ + free(__pyx_v_f_links_high); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1787 + * free(f_links_low) + * free(f_links_high) + * free(e_links_low) # <<<<<<<<<<<<<< + * free(e_links_high) + * free(f_gap_low) + */ + free(__pyx_v_e_links_low); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1788 + * free(f_links_high) + * free(e_links_low) + * free(e_links_high) # <<<<<<<<<<<<<< + * free(f_gap_low) + * free(f_gap_high) + */ + free(__pyx_v_e_links_high); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1789 + * free(e_links_low) + * free(e_links_high) + * free(f_gap_low) # <<<<<<<<<<<<<< + * free(f_gap_high) + * free(e_gap_low) + */ + free(__pyx_v_f_gap_low); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1790 + * free(e_links_high) + * free(f_gap_low) + * free(f_gap_high) # <<<<<<<<<<<<<< + * free(e_gap_low) + * free(e_gap_high) + */ + free(__pyx_v_f_gap_high); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1791 + * free(f_gap_low) + * free(f_gap_high) + * free(e_gap_low) # <<<<<<<<<<<<<< + * free(e_gap_high) + * + */ + free(__pyx_v_e_gap_low); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1792 + * free(f_gap_high) + * free(e_gap_low) + * free(e_gap_high) # <<<<<<<<<<<<<< + * + * return extracts + */ + free(__pyx_v_e_gap_high); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1794 + * free(e_gap_high) + * + * return extracts # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_extracts); + __pyx_r = __pyx_v_extracts; + 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_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_XDECREF(__pyx_t_15); + __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.extract", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_extracts); + __Pyx_XDECREF(__pyx_v_phrase_list); + __Pyx_XDECREF((PyObject *)__pyx_v_fphr_arr); + __Pyx_XDECREF((PyObject *)__pyx_v_fphr); + __Pyx_XDECREF(__pyx_v_reason_for_failure); + __Pyx_XDECREF(__pyx_v_sofar); + __Pyx_XDECREF(__pyx_v_als); + __Pyx_XDECREF(__pyx_v_al); + __Pyx_XDECREF(__pyx_v_phrase2); + __Pyx_XDECREF(__pyx_v_eindexes); + __Pyx_XDECREF(__pyx_v_als1); + __Pyx_XDECREF(__pyx_v_als2); + __Pyx_XDECREF(__pyx_v_als3); + __Pyx_XDECREF(__pyx_v_als4); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static struct __pyx_vtabstruct_8_cdec_sa_FloatList __pyx_vtable_8_cdec_sa_FloatList; + +static PyObject *__pyx_tp_new_8_cdec_sa_FloatList(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_FloatList *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_FloatList *)o); + p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_FloatList; + if (__pyx_pw_8_cdec_sa_9FloatList_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_FloatList(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_8_cdec_sa_9FloatList_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_8_cdec_sa_FloatList(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_8_cdec_sa_FloatList(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_8_cdec_sa_9FloatList_7__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_8_cdec_sa_FloatList[] = { + {__Pyx_NAMESTR("append"), (PyCFunction)__pyx_pw_8_cdec_sa_9FloatList_11append, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write"), (PyCFunction)__pyx_pw_8_cdec_sa_9FloatList_13write, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read"), (PyCFunction)__pyx_pw_8_cdec_sa_9FloatList_15read, METH_O, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_FloatList = { + 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_FloatList = { + __pyx_pw_8_cdec_sa_9FloatList_9__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_8_cdec_sa_FloatList, /*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_FloatList = { + __pyx_pw_8_cdec_sa_9FloatList_9__len__, /*mp_length*/ + __pyx_pw_8_cdec_sa_9FloatList_5__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_8_cdec_sa_FloatList, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_FloatList = { + #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_8_cdec_sa_FloatList = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.FloatList"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_FloatList), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_FloatList, /*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_FloatList, /*tp_as_number*/ + &__pyx_tp_as_sequence_FloatList, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_FloatList, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_FloatList, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_FloatList, /*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_8_cdec_sa_FloatList, /*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 struct __pyx_vtabstruct_8_cdec_sa_IntList __pyx_vtable_8_cdec_sa_IntList; + +static PyObject *__pyx_tp_new_8_cdec_sa_IntList(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_IntList *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_IntList *)o); + p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_IntList; + if (__pyx_pw_8_cdec_sa_7IntList_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_IntList(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_8_cdec_sa_7IntList_15__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_8_cdec_sa_IntList(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_8_cdec_sa_IntList(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_8_cdec_sa_7IntList_19__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_8_cdec_sa_IntList[] = { + {__Pyx_NAMESTR("index"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_5index, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("partition"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_7partition, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("_doquicksort"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_9_doquicksort, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("sort"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_11sort, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("reset"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_13reset, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("getSize"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_23getSize, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("append"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_25append, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("extend"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_27extend, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_29write, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_31read, METH_O, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_IntList = { + 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_IntList = { + __pyx_pw_8_cdec_sa_7IntList_21__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_8_cdec_sa_IntList, /*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_IntList = { + __pyx_pw_8_cdec_sa_7IntList_21__len__, /*mp_length*/ + __pyx_pw_8_cdec_sa_7IntList_17__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_8_cdec_sa_IntList, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_IntList = { + #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_8_cdec_sa_IntList = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.IntList"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_IntList), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_IntList, /*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_IntList, /*tp_as_number*/ + &__pyx_tp_as_sequence_IntList, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_IntList, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_8_cdec_sa_7IntList_3__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_IntList, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_IntList, /*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_8_cdec_sa_IntList, /*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 struct __pyx_vtabstruct_8_cdec_sa_StringMap __pyx_vtable_8_cdec_sa_StringMap; + +static PyObject *__pyx_tp_new_8_cdec_sa_StringMap(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_StringMap *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_StringMap *)o); + p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_StringMap; + if (__pyx_pw_8_cdec_sa_9StringMap_1__cinit__(o, __pyx_empty_tuple, NULL) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_StringMap(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_8_cdec_sa_9StringMap_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_8_cdec_sa_StringMap[] = { + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_StringMap = { + 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_StringMap = { + 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_StringMap = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_StringMap = { + #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_8_cdec_sa_StringMap = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.StringMap"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_StringMap), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_StringMap, /*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_StringMap, /*tp_as_number*/ + &__pyx_tp_as_sequence_StringMap, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_StringMap, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_StringMap, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_StringMap, /*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_8_cdec_sa_StringMap, /*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 struct __pyx_vtabstruct_8_cdec_sa_DataArray __pyx_vtable_8_cdec_sa_DataArray; + +static PyObject *__pyx_tp_new_8_cdec_sa_DataArray(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_DataArray *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_DataArray *)o); + p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_DataArray; + p->word2id = Py_None; Py_INCREF(Py_None); + p->id2word = Py_None; Py_INCREF(Py_None); + p->data = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->sent_id = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->sent_index = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_8_cdec_sa_9DataArray_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_DataArray(PyObject *o) { + struct __pyx_obj_8_cdec_sa_DataArray *p = (struct __pyx_obj_8_cdec_sa_DataArray *)o; + Py_XDECREF(p->word2id); + Py_XDECREF(p->id2word); + Py_XDECREF(((PyObject *)p->data)); + Py_XDECREF(((PyObject *)p->sent_id)); + Py_XDECREF(((PyObject *)p->sent_index)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_8_cdec_sa_DataArray(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_8_cdec_sa_DataArray *p = (struct __pyx_obj_8_cdec_sa_DataArray *)o; + if (p->word2id) { + e = (*v)(p->word2id, a); if (e) return e; + } + if (p->id2word) { + e = (*v)(p->id2word, a); if (e) return e; + } + if (p->data) { + e = (*v)(((PyObject*)p->data), a); if (e) return e; + } + if (p->sent_id) { + e = (*v)(((PyObject*)p->sent_id), a); if (e) return e; + } + if (p->sent_index) { + e = (*v)(((PyObject*)p->sent_index), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_8_cdec_sa_DataArray(PyObject *o) { + struct __pyx_obj_8_cdec_sa_DataArray *p = (struct __pyx_obj_8_cdec_sa_DataArray *)o; + PyObject* tmp; + tmp = ((PyObject*)p->word2id); + p->word2id = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->id2word); + p->id2word = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->data); + p->data = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->sent_id); + p->sent_id = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->sent_index); + p->sent_index = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_8_cdec_sa_DataArray[] = { + {__Pyx_NAMESTR("getSentId"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_5getSentId, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("getSent"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_7getSent, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("getSentPos"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_9getSentPos, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_id"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_11get_id, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_word"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_13get_word, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_text"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_15write_text, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_text"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_17read_text, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_19read_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_21write_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_enhanced_handle"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_23write_enhanced_handle, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_enhanced"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_25write_enhanced, METH_O, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_DataArray = { + 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_DataArray = { + __pyx_pw_8_cdec_sa_9DataArray_3__len__, /*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_DataArray = { + __pyx_pw_8_cdec_sa_9DataArray_3__len__, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_DataArray = { + #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_8_cdec_sa_DataArray = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.DataArray"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_DataArray), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_DataArray, /*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_DataArray, /*tp_as_number*/ + &__pyx_tp_as_sequence_DataArray, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_DataArray, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_DataArray, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_8_cdec_sa_DataArray, /*tp_traverse*/ + __pyx_tp_clear_8_cdec_sa_DataArray, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_DataArray, /*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_8_cdec_sa_DataArray, /*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 struct __pyx_vtabstruct_8_cdec_sa_Alignment __pyx_vtable_8_cdec_sa_Alignment; + +static PyObject *__pyx_tp_new_8_cdec_sa_Alignment(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_Alignment *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_Alignment *)o); + p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_Alignment; + p->links = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->sent_index = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_8_cdec_sa_9Alignment_5__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_Alignment(PyObject *o) { + struct __pyx_obj_8_cdec_sa_Alignment *p = (struct __pyx_obj_8_cdec_sa_Alignment *)o; + Py_XDECREF(((PyObject *)p->links)); + Py_XDECREF(((PyObject *)p->sent_index)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_8_cdec_sa_Alignment(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_8_cdec_sa_Alignment *p = (struct __pyx_obj_8_cdec_sa_Alignment *)o; + if (p->links) { + e = (*v)(((PyObject*)p->links), a); if (e) return e; + } + if (p->sent_index) { + e = (*v)(((PyObject*)p->sent_index), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_8_cdec_sa_Alignment(PyObject *o) { + struct __pyx_obj_8_cdec_sa_Alignment *p = (struct __pyx_obj_8_cdec_sa_Alignment *)o; + PyObject* tmp; + tmp = ((PyObject*)p->links); + p->links = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->sent_index); + p->sent_index = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_8_cdec_sa_Alignment[] = { + {__Pyx_NAMESTR("unlink"), (PyCFunction)__pyx_pw_8_cdec_sa_9Alignment_1unlink, METH_O, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_9Alignment_unlink)}, + {__Pyx_NAMESTR("get_sent_links"), (PyCFunction)__pyx_pw_8_cdec_sa_9Alignment_3get_sent_links, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_text"), (PyCFunction)__pyx_pw_8_cdec_sa_9Alignment_7read_text, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_9Alignment_9read_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_text"), (PyCFunction)__pyx_pw_8_cdec_sa_9Alignment_11write_text, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_9Alignment_13write_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_enhanced"), (PyCFunction)__pyx_pw_8_cdec_sa_9Alignment_15write_enhanced, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("alignment"), (PyCFunction)__pyx_pw_8_cdec_sa_9Alignment_17alignment, METH_O, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_9Alignment_16alignment)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Alignment = { + 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_Alignment = { + 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_Alignment = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Alignment = { + #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_8_cdec_sa_Alignment = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.Alignment"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_Alignment), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_Alignment, /*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_Alignment, /*tp_as_number*/ + &__pyx_tp_as_sequence_Alignment, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Alignment, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Alignment, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_8_cdec_sa_Alignment, /*tp_traverse*/ + __pyx_tp_clear_8_cdec_sa_Alignment, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_Alignment, /*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_8_cdec_sa_Alignment, /*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 struct __pyx_vtabstruct_8_cdec_sa_BiLex __pyx_vtable_8_cdec_sa_BiLex; + +static PyObject *__pyx_tp_new_8_cdec_sa_BiLex(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_BiLex *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_BiLex *)o); + p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_BiLex; + p->col1 = ((struct __pyx_obj_8_cdec_sa_FloatList *)Py_None); Py_INCREF(Py_None); + p->col2 = ((struct __pyx_obj_8_cdec_sa_FloatList *)Py_None); Py_INCREF(Py_None); + p->f_index = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->e_index = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->id2eword = Py_None; Py_INCREF(Py_None); + p->id2fword = Py_None; Py_INCREF(Py_None); + p->eword2id = Py_None; Py_INCREF(Py_None); + p->fword2id = Py_None; Py_INCREF(Py_None); + if (__pyx_pw_8_cdec_sa_5BiLex_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_BiLex(PyObject *o) { + struct __pyx_obj_8_cdec_sa_BiLex *p = (struct __pyx_obj_8_cdec_sa_BiLex *)o; + Py_XDECREF(((PyObject *)p->col1)); + Py_XDECREF(((PyObject *)p->col2)); + Py_XDECREF(((PyObject *)p->f_index)); + Py_XDECREF(((PyObject *)p->e_index)); + Py_XDECREF(p->id2eword); + Py_XDECREF(p->id2fword); + Py_XDECREF(p->eword2id); + Py_XDECREF(p->fword2id); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_8_cdec_sa_BiLex(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_8_cdec_sa_BiLex *p = (struct __pyx_obj_8_cdec_sa_BiLex *)o; + if (p->col1) { + e = (*v)(((PyObject*)p->col1), a); if (e) return e; + } + if (p->col2) { + e = (*v)(((PyObject*)p->col2), a); if (e) return e; + } + if (p->f_index) { + e = (*v)(((PyObject*)p->f_index), a); if (e) return e; + } + if (p->e_index) { + e = (*v)(((PyObject*)p->e_index), a); if (e) return e; + } + if (p->id2eword) { + e = (*v)(p->id2eword, a); if (e) return e; + } + if (p->id2fword) { + e = (*v)(p->id2fword, a); if (e) return e; + } + if (p->eword2id) { + e = (*v)(p->eword2id, a); if (e) return e; + } + if (p->fword2id) { + e = (*v)(p->fword2id, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_8_cdec_sa_BiLex(PyObject *o) { + struct __pyx_obj_8_cdec_sa_BiLex *p = (struct __pyx_obj_8_cdec_sa_BiLex *)o; + PyObject* tmp; + tmp = ((PyObject*)p->col1); + p->col1 = ((struct __pyx_obj_8_cdec_sa_FloatList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->col2); + p->col2 = ((struct __pyx_obj_8_cdec_sa_FloatList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->f_index); + p->f_index = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->e_index); + p->e_index = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->id2eword); + p->id2eword = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->id2fword); + p->id2fword = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->eword2id); + p->eword2id = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->fword2id); + p->fword2id = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_8_cdec_sa_BiLex[] = { + {__Pyx_NAMESTR("write_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_5BiLex_3write_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_5BiLex_5read_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_e_id"), (PyCFunction)__pyx_pw_8_cdec_sa_5BiLex_7get_e_id, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_f_id"), (PyCFunction)__pyx_pw_8_cdec_sa_5BiLex_9get_f_id, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_text"), (PyCFunction)__pyx_pw_8_cdec_sa_5BiLex_11read_text, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_enhanced"), (PyCFunction)__pyx_pw_8_cdec_sa_5BiLex_13write_enhanced, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_score"), (PyCFunction)__pyx_pw_8_cdec_sa_5BiLex_15get_score, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_text"), (PyCFunction)__pyx_pw_8_cdec_sa_5BiLex_17write_text, METH_O, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_5BiLex_16write_text)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_BiLex = { + 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_BiLex = { + 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_BiLex = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_BiLex = { + #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_8_cdec_sa_BiLex = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.BiLex"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_BiLex), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_BiLex, /*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_BiLex, /*tp_as_number*/ + &__pyx_tp_as_sequence_BiLex, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_BiLex, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_BiLex, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_8_cdec_sa_BiLex, /*tp_traverse*/ + __pyx_tp_clear_8_cdec_sa_BiLex, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_BiLex, /*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_8_cdec_sa_BiLex, /*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_8_cdec_sa_BitSetIterator(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_BitSetIterator(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} + +static PyMethodDef __pyx_methods_8_cdec_sa_BitSetIterator[] = { + {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_8_cdec_sa_14BitSetIterator_1__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_BitSetIterator = { + 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_BitSetIterator = { + 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_BitSetIterator = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_BitSetIterator = { + #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_8_cdec_sa_BitSetIterator = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.BitSetIterator"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_BitSetIterator), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_BitSetIterator, /*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_BitSetIterator, /*tp_as_number*/ + &__pyx_tp_as_sequence_BitSetIterator, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_BitSetIterator, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_BitSetIterator, /*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*/ + 0, /*tp_iter*/ + __pyx_pw_8_cdec_sa_14BitSetIterator_1__next__, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_BitSetIterator, /*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_8_cdec_sa_BitSetIterator, /*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_8_cdec_sa_BitSet(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + if (__pyx_pw_8_cdec_sa_6BitSet_1__cinit__(o, __pyx_empty_tuple, NULL) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_BitSet(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_8_cdec_sa_6BitSet_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_8_cdec_sa_BitSet[] = { + {__Pyx_NAMESTR("insert"), (PyCFunction)__pyx_pw_8_cdec_sa_6BitSet_7insert, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("findsucc"), (PyCFunction)__pyx_pw_8_cdec_sa_6BitSet_9findsucc, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("min"), (PyCFunction)__pyx_pw_8_cdec_sa_6BitSet_13min, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("max"), (PyCFunction)__pyx_pw_8_cdec_sa_6BitSet_15max, METH_NOARGS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_BitSet = { + 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_BitSet = { + __pyx_pw_8_cdec_sa_6BitSet_17__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + 0, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + __pyx_pw_8_cdec_sa_6BitSet_19__contains__, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_BitSet = { + __pyx_pw_8_cdec_sa_6BitSet_17__len__, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_BitSet = { + #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_8_cdec_sa_BitSet = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.BitSet"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_BitSet), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_BitSet, /*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_BitSet, /*tp_as_number*/ + &__pyx_tp_as_sequence_BitSet, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_BitSet, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_8_cdec_sa_6BitSet_11__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_BitSet, /*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_pw_8_cdec_sa_6BitSet_5__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_BitSet, /*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_8_cdec_sa_BitSet, /*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_8_cdec_sa_VEBIterator(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_VEBIterator(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} + +static PyMethodDef __pyx_methods_8_cdec_sa_VEBIterator[] = { + {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_8_cdec_sa_11VEBIterator_1__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_VEBIterator = { + 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_VEBIterator = { + 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_VEBIterator = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_VEBIterator = { + #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_8_cdec_sa_VEBIterator = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.VEBIterator"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_VEBIterator), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_VEBIterator, /*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_VEBIterator, /*tp_as_number*/ + &__pyx_tp_as_sequence_VEBIterator, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_VEBIterator, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_VEBIterator, /*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*/ + 0, /*tp_iter*/ + __pyx_pw_8_cdec_sa_11VEBIterator_1__next__, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_VEBIterator, /*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_8_cdec_sa_VEBIterator, /*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 struct __pyx_vtabstruct_8_cdec_sa_VEB __pyx_vtable_8_cdec_sa_VEB; + +static PyObject *__pyx_tp_new_8_cdec_sa_VEB(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_VEB *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_VEB *)o); + p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_VEB; + if (__pyx_pw_8_cdec_sa_3VEB_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_VEB(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_8_cdec_sa_3VEB_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_8_cdec_sa_VEB[] = { + {__Pyx_NAMESTR("insert"), (PyCFunction)__pyx_pw_8_cdec_sa_3VEB_7insert, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("findsucc"), (PyCFunction)__pyx_pw_8_cdec_sa_3VEB_9findsucc, METH_O, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_VEB = { + 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_VEB = { + __pyx_pw_8_cdec_sa_3VEB_11__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + 0, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + __pyx_pw_8_cdec_sa_3VEB_13__contains__, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_VEB = { + __pyx_pw_8_cdec_sa_3VEB_11__len__, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_VEB = { + #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_8_cdec_sa_VEB = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.VEB"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_VEB), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_VEB, /*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_VEB, /*tp_as_number*/ + &__pyx_tp_as_sequence_VEB, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_VEB, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_VEB, /*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_pw_8_cdec_sa_3VEB_5__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_VEB, /*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_8_cdec_sa_VEB, /*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_8_cdec_sa_LCP(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_LCP *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_LCP *)o); + p->sa = ((struct __pyx_obj_8_cdec_sa_SuffixArray *)Py_None); Py_INCREF(Py_None); + p->lcp = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_8_cdec_sa_3LCP_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_LCP(PyObject *o) { + struct __pyx_obj_8_cdec_sa_LCP *p = (struct __pyx_obj_8_cdec_sa_LCP *)o; + Py_XDECREF(((PyObject *)p->sa)); + Py_XDECREF(((PyObject *)p->lcp)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_8_cdec_sa_LCP(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_8_cdec_sa_LCP *p = (struct __pyx_obj_8_cdec_sa_LCP *)o; + if (p->sa) { + e = (*v)(((PyObject*)p->sa), a); if (e) return e; + } + if (p->lcp) { + e = (*v)(((PyObject*)p->lcp), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_8_cdec_sa_LCP(PyObject *o) { + struct __pyx_obj_8_cdec_sa_LCP *p = (struct __pyx_obj_8_cdec_sa_LCP *)o; + PyObject* tmp; + tmp = ((PyObject*)p->sa); + p->sa = ((struct __pyx_obj_8_cdec_sa_SuffixArray *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->lcp); + p->lcp = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_8_cdec_sa_LCP[] = { + {__Pyx_NAMESTR("compute_stats"), (PyCFunction)__pyx_pw_8_cdec_sa_3LCP_3compute_stats, METH_O, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_3LCP_2compute_stats)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_LCP = { + 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_LCP = { + 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_LCP = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_LCP = { + #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_8_cdec_sa_LCP = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.LCP"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_LCP), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_LCP, /*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_LCP, /*tp_as_number*/ + &__pyx_tp_as_sequence_LCP, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_LCP, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_LCP, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_8_cdec_sa_LCP, /*tp_traverse*/ + __pyx_tp_clear_8_cdec_sa_LCP, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_LCP, /*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_8_cdec_sa_LCP, /*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 struct __pyx_vtabstruct_8_cdec_sa_Alphabet __pyx_vtable_8_cdec_sa_Alphabet; + +static PyObject *__pyx_tp_new_8_cdec_sa_Alphabet(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_Alphabet *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_Alphabet *)o); + p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_Alphabet; + p->terminals = ((struct __pyx_obj_8_cdec_sa_StringMap *)Py_None); Py_INCREF(Py_None); + p->nonterminals = ((struct __pyx_obj_8_cdec_sa_StringMap *)Py_None); Py_INCREF(Py_None); + p->id2sym = ((PyObject*)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_8_cdec_sa_8Alphabet_1__cinit__(o, __pyx_empty_tuple, NULL) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_Alphabet(PyObject *o) { + struct __pyx_obj_8_cdec_sa_Alphabet *p = (struct __pyx_obj_8_cdec_sa_Alphabet *)o; + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_8_cdec_sa_8Alphabet_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + Py_XDECREF(((PyObject *)p->terminals)); + Py_XDECREF(((PyObject *)p->nonterminals)); + Py_XDECREF(((PyObject *)p->id2sym)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_8_cdec_sa_Alphabet(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_8_cdec_sa_Alphabet *p = (struct __pyx_obj_8_cdec_sa_Alphabet *)o; + if (p->terminals) { + e = (*v)(((PyObject*)p->terminals), a); if (e) return e; + } + if (p->nonterminals) { + e = (*v)(((PyObject*)p->nonterminals), a); if (e) return e; + } + if (p->id2sym) { + e = (*v)(p->id2sym, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_8_cdec_sa_Alphabet(PyObject *o) { + struct __pyx_obj_8_cdec_sa_Alphabet *p = (struct __pyx_obj_8_cdec_sa_Alphabet *)o; + PyObject* tmp; + tmp = ((PyObject*)p->terminals); + p->terminals = ((struct __pyx_obj_8_cdec_sa_StringMap *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->nonterminals); + p->nonterminals = ((struct __pyx_obj_8_cdec_sa_StringMap *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->id2sym); + p->id2sym = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_8_cdec_sa_8Alphabet_terminals(PyObject *o, void *x) { + return __pyx_pw_8_cdec_sa_8Alphabet_9terminals_1__get__(o); +} + +static PyObject *__pyx_getprop_8_cdec_sa_8Alphabet_nonterminals(PyObject *o, void *x) { + return __pyx_pw_8_cdec_sa_8Alphabet_12nonterminals_1__get__(o); +} + +static PyMethodDef __pyx_methods_8_cdec_sa_Alphabet[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_8_cdec_sa_Alphabet[] = { + {(char *)"terminals", __pyx_getprop_8_cdec_sa_8Alphabet_terminals, 0, 0, 0}, + {(char *)"nonterminals", __pyx_getprop_8_cdec_sa_8Alphabet_nonterminals, 0, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Alphabet = { + 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_Alphabet = { + 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_Alphabet = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Alphabet = { + #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_8_cdec_sa_Alphabet = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.Alphabet"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_Alphabet), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_Alphabet, /*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_Alphabet, /*tp_as_number*/ + &__pyx_tp_as_sequence_Alphabet, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Alphabet, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Alphabet, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_8_cdec_sa_Alphabet, /*tp_traverse*/ + __pyx_tp_clear_8_cdec_sa_Alphabet, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_Alphabet, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_8_cdec_sa_Alphabet, /*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_8_cdec_sa_Alphabet, /*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 struct __pyx_vtabstruct_8_cdec_sa_Phrase __pyx_vtable_8_cdec_sa_Phrase; + +static PyObject *__pyx_tp_new_8_cdec_sa_Phrase(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_Phrase *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_Phrase *)o); + p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_Phrase; + if (__pyx_pw_8_cdec_sa_6Phrase_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_Phrase(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_8_cdec_sa_6Phrase_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_8_cdec_sa_Phrase(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static PyMethodDef __pyx_methods_8_cdec_sa_Phrase[] = { + {__Pyx_NAMESTR("handle"), (PyCFunction)__pyx_pw_8_cdec_sa_6Phrase_7handle, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_6Phrase_6handle)}, + {__Pyx_NAMESTR("strhandle"), (PyCFunction)__pyx_pw_8_cdec_sa_6Phrase_9strhandle, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("arity"), (PyCFunction)__pyx_pw_8_cdec_sa_6Phrase_11arity, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("getvarpos"), (PyCFunction)__pyx_pw_8_cdec_sa_6Phrase_13getvarpos, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("getvar"), (PyCFunction)__pyx_pw_8_cdec_sa_6Phrase_15getvar, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("clen"), (PyCFunction)__pyx_pw_8_cdec_sa_6Phrase_17clen, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("getchunk"), (PyCFunction)__pyx_pw_8_cdec_sa_6Phrase_19getchunk, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("subst"), (PyCFunction)__pyx_pw_8_cdec_sa_6Phrase_31subst, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Phrase = { + 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_Phrase = { + __pyx_pw_8_cdec_sa_6Phrase_25__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_8_cdec_sa_Phrase, /*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_Phrase = { + __pyx_pw_8_cdec_sa_6Phrase_25__len__, /*mp_length*/ + __pyx_pw_8_cdec_sa_6Phrase_27__getitem__, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Phrase = { + #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_8_cdec_sa_Phrase = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.Phrase"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_Phrase), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_Phrase, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + __pyx_pw_8_cdec_sa_6Phrase_21__cmp__, /*tp_compare*/ + #else + 0, /*reserved*/ + #endif + 0, /*tp_repr*/ + &__pyx_tp_as_number_Phrase, /*tp_as_number*/ + &__pyx_tp_as_sequence_Phrase, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Phrase, /*tp_as_mapping*/ + __pyx_pw_8_cdec_sa_6Phrase_23__hash__, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_8_cdec_sa_6Phrase_5__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Phrase, /*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_pw_8_cdec_sa_6Phrase_29__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_Phrase, /*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_8_cdec_sa_Phrase, /*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_8_cdec_sa_Rule(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_Rule *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_Rule *)o); + p->f = ((struct __pyx_obj_8_cdec_sa_Phrase *)Py_None); Py_INCREF(Py_None); + p->e = ((struct __pyx_obj_8_cdec_sa_Phrase *)Py_None); Py_INCREF(Py_None); + p->word_alignments = Py_None; Py_INCREF(Py_None); + if (__pyx_pw_8_cdec_sa_4Rule_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_Rule(PyObject *o) { + struct __pyx_obj_8_cdec_sa_Rule *p = (struct __pyx_obj_8_cdec_sa_Rule *)o; + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_8_cdec_sa_4Rule_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + Py_XDECREF(((PyObject *)p->f)); + Py_XDECREF(((PyObject *)p->e)); + Py_XDECREF(p->word_alignments); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_8_cdec_sa_Rule(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_8_cdec_sa_Rule *p = (struct __pyx_obj_8_cdec_sa_Rule *)o; + if (p->f) { + e = (*v)(((PyObject*)p->f), a); if (e) return e; + } + if (p->e) { + e = (*v)(((PyObject*)p->e), a); if (e) return e; + } + if (p->word_alignments) { + e = (*v)(p->word_alignments, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_8_cdec_sa_Rule(PyObject *o) { + struct __pyx_obj_8_cdec_sa_Rule *p = (struct __pyx_obj_8_cdec_sa_Rule *)o; + PyObject* tmp; + tmp = ((PyObject*)p->f); + p->f = ((struct __pyx_obj_8_cdec_sa_Phrase *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->e); + p->e = ((struct __pyx_obj_8_cdec_sa_Phrase *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->word_alignments); + p->word_alignments = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_8_cdec_sa_4Rule_scores(PyObject *o, void *x) { + return __pyx_pw_8_cdec_sa_4Rule_6scores_1__get__(o); +} + +static int __pyx_setprop_8_cdec_sa_4Rule_scores(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_8_cdec_sa_4Rule_6scores_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_8_cdec_sa_4Rule_lhs(PyObject *o, void *x) { + return __pyx_pw_8_cdec_sa_4Rule_3lhs_1__get__(o); +} + +static int __pyx_setprop_8_cdec_sa_4Rule_lhs(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_8_cdec_sa_4Rule_3lhs_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_8_cdec_sa_4Rule_f(PyObject *o, void *x) { + return __pyx_pw_8_cdec_sa_4Rule_1f_1__get__(o); +} + +static PyObject *__pyx_getprop_8_cdec_sa_4Rule_e(PyObject *o, void *x) { + return __pyx_pw_8_cdec_sa_4Rule_1e_1__get__(o); +} + +static PyObject *__pyx_getprop_8_cdec_sa_4Rule_word_alignments(PyObject *o, void *x) { + return __pyx_pw_8_cdec_sa_4Rule_15word_alignments_1__get__(o); +} + +static int __pyx_setprop_8_cdec_sa_4Rule_word_alignments(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_8_cdec_sa_4Rule_15word_alignments_3__set__(o, v); + } + else { + return __pyx_pw_8_cdec_sa_4Rule_15word_alignments_5__del__(o); + } +} + +static PyMethodDef __pyx_methods_8_cdec_sa_Rule[] = { + {__Pyx_NAMESTR("fmerge"), (PyCFunction)__pyx_pw_8_cdec_sa_4Rule_11fmerge, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("arity"), (PyCFunction)__pyx_pw_8_cdec_sa_4Rule_13arity, METH_NOARGS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_8_cdec_sa_Rule[] = { + {(char *)"scores", __pyx_getprop_8_cdec_sa_4Rule_scores, __pyx_setprop_8_cdec_sa_4Rule_scores, 0, 0}, + {(char *)"lhs", __pyx_getprop_8_cdec_sa_4Rule_lhs, __pyx_setprop_8_cdec_sa_4Rule_lhs, 0, 0}, + {(char *)"f", __pyx_getprop_8_cdec_sa_4Rule_f, 0, 0, 0}, + {(char *)"e", __pyx_getprop_8_cdec_sa_4Rule_e, 0, 0, 0}, + {(char *)"word_alignments", __pyx_getprop_8_cdec_sa_4Rule_word_alignments, __pyx_setprop_8_cdec_sa_4Rule_word_alignments, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Rule = { + 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 + __pyx_pw_8_cdec_sa_4Rule_9__iadd__, /*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_Rule = { + 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_Rule = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Rule = { + #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_8_cdec_sa_Rule = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.Rule"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_Rule), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_Rule, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + __pyx_pw_8_cdec_sa_4Rule_7__cmp__, /*tp_compare*/ + #else + 0, /*reserved*/ + #endif + 0, /*tp_repr*/ + &__pyx_tp_as_number_Rule, /*tp_as_number*/ + &__pyx_tp_as_sequence_Rule, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Rule, /*tp_as_mapping*/ + __pyx_pw_8_cdec_sa_4Rule_5__hash__, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_8_cdec_sa_4Rule_15__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Rule, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_8_cdec_sa_Rule, /*tp_traverse*/ + __pyx_tp_clear_8_cdec_sa_Rule, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_Rule, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_8_cdec_sa_Rule, /*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_8_cdec_sa_Rule, /*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 struct __pyx_vtabstruct_8_cdec_sa_TrieMap __pyx_vtable_8_cdec_sa_TrieMap; + +static PyObject *__pyx_tp_new_8_cdec_sa_TrieMap(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_TrieMap *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_TrieMap *)o); + p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_TrieMap; + if (__pyx_pw_8_cdec_sa_7TrieMap_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_TrieMap(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_8_cdec_sa_7TrieMap_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_8_cdec_sa_TrieMap[] = { + {__Pyx_NAMESTR("insert"), (PyCFunction)__pyx_pw_8_cdec_sa_7TrieMap_5insert, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("contains"), (PyCFunction)__pyx_pw_8_cdec_sa_7TrieMap_7contains, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("toMap"), (PyCFunction)__pyx_pw_8_cdec_sa_7TrieMap_9toMap, METH_O, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_TrieMap = { + 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_TrieMap = { + 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_TrieMap = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_TrieMap = { + #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_8_cdec_sa_TrieMap = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.TrieMap"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_TrieMap), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_TrieMap, /*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_TrieMap, /*tp_as_number*/ + &__pyx_tp_as_sequence_TrieMap, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_TrieMap, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_TrieMap, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_TrieMap, /*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_8_cdec_sa_TrieMap, /*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 struct __pyx_vtabstruct_8_cdec_sa_Precomputation __pyx_vtable_8_cdec_sa_Precomputation; + +static PyObject *__pyx_tp_new_8_cdec_sa_Precomputation(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_Precomputation *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_Precomputation *)o); + p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_Precomputation; + p->precomputed_index = Py_None; Py_INCREF(Py_None); + p->precomputed_collocations = Py_None; Py_INCREF(Py_None); + if (__pyx_pw_8_cdec_sa_14Precomputation_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_Precomputation(PyObject *o) { + struct __pyx_obj_8_cdec_sa_Precomputation *p = (struct __pyx_obj_8_cdec_sa_Precomputation *)o; + Py_XDECREF(p->precomputed_index); + Py_XDECREF(p->precomputed_collocations); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_8_cdec_sa_Precomputation(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_8_cdec_sa_Precomputation *p = (struct __pyx_obj_8_cdec_sa_Precomputation *)o; + if (p->precomputed_index) { + e = (*v)(p->precomputed_index, a); if (e) return e; + } + if (p->precomputed_collocations) { + e = (*v)(p->precomputed_collocations, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_8_cdec_sa_Precomputation(PyObject *o) { + struct __pyx_obj_8_cdec_sa_Precomputation *p = (struct __pyx_obj_8_cdec_sa_Precomputation *)o; + PyObject* tmp; + tmp = ((PyObject*)p->precomputed_index); + p->precomputed_index = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->precomputed_collocations); + p->precomputed_collocations = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_8_cdec_sa_Precomputation[] = { + {__Pyx_NAMESTR("read_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_14Precomputation_3read_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_14Precomputation_5write_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("precompute"), (PyCFunction)__pyx_pw_8_cdec_sa_14Precomputation_7precompute, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Precomputation = { + 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_Precomputation = { + 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_Precomputation = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Precomputation = { + #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_8_cdec_sa_Precomputation = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.Precomputation"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_Precomputation), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_Precomputation, /*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_Precomputation, /*tp_as_number*/ + &__pyx_tp_as_sequence_Precomputation, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Precomputation, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Precomputation, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_8_cdec_sa_Precomputation, /*tp_traverse*/ + __pyx_tp_clear_8_cdec_sa_Precomputation, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_Precomputation, /*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_8_cdec_sa_Precomputation, /*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 struct __pyx_vtabstruct_8_cdec_sa_SuffixArray __pyx_vtable_8_cdec_sa_SuffixArray; + +static PyObject *__pyx_tp_new_8_cdec_sa_SuffixArray(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_SuffixArray *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_SuffixArray *)o); + p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_SuffixArray; + p->darray = ((struct __pyx_obj_8_cdec_sa_DataArray *)Py_None); Py_INCREF(Py_None); + p->sa = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->ha = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_8_cdec_sa_11SuffixArray_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_SuffixArray(PyObject *o) { + struct __pyx_obj_8_cdec_sa_SuffixArray *p = (struct __pyx_obj_8_cdec_sa_SuffixArray *)o; + Py_XDECREF(((PyObject *)p->darray)); + Py_XDECREF(((PyObject *)p->sa)); + Py_XDECREF(((PyObject *)p->ha)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_8_cdec_sa_SuffixArray(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_8_cdec_sa_SuffixArray *p = (struct __pyx_obj_8_cdec_sa_SuffixArray *)o; + if (p->darray) { + e = (*v)(((PyObject*)p->darray), a); if (e) return e; + } + if (p->sa) { + e = (*v)(((PyObject*)p->sa), a); if (e) return e; + } + if (p->ha) { + e = (*v)(((PyObject*)p->ha), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_8_cdec_sa_SuffixArray(PyObject *o) { + struct __pyx_obj_8_cdec_sa_SuffixArray *p = (struct __pyx_obj_8_cdec_sa_SuffixArray *)o; + PyObject* tmp; + tmp = ((PyObject*)p->darray); + p->darray = ((struct __pyx_obj_8_cdec_sa_DataArray *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->sa); + p->sa = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->ha); + p->ha = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} +static PyObject *__pyx_sq_item_8_cdec_sa_SuffixArray(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static PyMethodDef __pyx_methods_8_cdec_sa_SuffixArray[] = { + {__Pyx_NAMESTR("getSentId"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_5getSentId, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("getSent"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_7getSent, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("getSentPos"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_9getSentPos, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_text"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_11read_text, METH_O, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_11SuffixArray_10read_text)}, + {__Pyx_NAMESTR("q3sort"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_13q3sort, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_11SuffixArray_12q3sort)}, + {__Pyx_NAMESTR("write_text"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_15write_text, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_17read_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_19write_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_enhanced"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_21write_enhanced, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("lookup"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_23lookup, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_SuffixArray = { + 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_SuffixArray = { + 0, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_8_cdec_sa_SuffixArray, /*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_SuffixArray = { + 0, /*mp_length*/ + __pyx_pw_8_cdec_sa_11SuffixArray_3__getitem__, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_SuffixArray = { + #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_8_cdec_sa_SuffixArray = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.SuffixArray"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_SuffixArray), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_SuffixArray, /*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_SuffixArray, /*tp_as_number*/ + &__pyx_tp_as_sequence_SuffixArray, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_SuffixArray, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_SuffixArray, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_8_cdec_sa_SuffixArray, /*tp_traverse*/ + __pyx_tp_clear_8_cdec_sa_SuffixArray, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_SuffixArray, /*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_8_cdec_sa_SuffixArray, /*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_8_cdec_sa_TrieNode(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_TrieNode *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_TrieNode *)o); + p->children = Py_None; Py_INCREF(Py_None); + if (__pyx_pw_8_cdec_sa_8TrieNode_1__cinit__(o, __pyx_empty_tuple, NULL) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_TrieNode(PyObject *o) { + struct __pyx_obj_8_cdec_sa_TrieNode *p = (struct __pyx_obj_8_cdec_sa_TrieNode *)o; + Py_XDECREF(p->children); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_8_cdec_sa_TrieNode(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_8_cdec_sa_TrieNode *p = (struct __pyx_obj_8_cdec_sa_TrieNode *)o; + if (p->children) { + e = (*v)(p->children, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_8_cdec_sa_TrieNode(PyObject *o) { + struct __pyx_obj_8_cdec_sa_TrieNode *p = (struct __pyx_obj_8_cdec_sa_TrieNode *)o; + PyObject* tmp; + tmp = ((PyObject*)p->children); + p->children = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_8_cdec_sa_8TrieNode_children(PyObject *o, void *x) { + return __pyx_pw_8_cdec_sa_8TrieNode_8children_1__get__(o); +} + +static int __pyx_setprop_8_cdec_sa_8TrieNode_children(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_8_cdec_sa_8TrieNode_8children_3__set__(o, v); + } + else { + return __pyx_pw_8_cdec_sa_8TrieNode_8children_5__del__(o); + } +} + +static PyMethodDef __pyx_methods_8_cdec_sa_TrieNode[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_8_cdec_sa_TrieNode[] = { + {(char *)"children", __pyx_getprop_8_cdec_sa_8TrieNode_children, __pyx_setprop_8_cdec_sa_8TrieNode_children, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_TrieNode = { + 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_TrieNode = { + 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_TrieNode = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_TrieNode = { + #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_8_cdec_sa_TrieNode = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.TrieNode"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_TrieNode), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_TrieNode, /*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_TrieNode, /*tp_as_number*/ + &__pyx_tp_as_sequence_TrieNode, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_TrieNode, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_TrieNode, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_8_cdec_sa_TrieNode, /*tp_traverse*/ + __pyx_tp_clear_8_cdec_sa_TrieNode, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_TrieNode, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_8_cdec_sa_TrieNode, /*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_8_cdec_sa_TrieNode, /*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_8_cdec_sa_ExtendedTrieNode(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *p; + PyObject *o = __pyx_tp_new_8_cdec_sa_TrieNode(t, a, k); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)o); + p->phrase = Py_None; Py_INCREF(Py_None); + p->phrase_location = Py_None; Py_INCREF(Py_None); + p->suffix_link = Py_None; Py_INCREF(Py_None); + if (__pyx_pw_8_cdec_sa_16ExtendedTrieNode_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_ExtendedTrieNode(PyObject *o) { + struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *p = (struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)o; + Py_XDECREF(p->phrase); + Py_XDECREF(p->phrase_location); + Py_XDECREF(p->suffix_link); + __pyx_tp_dealloc_8_cdec_sa_TrieNode(o); +} + +static int __pyx_tp_traverse_8_cdec_sa_ExtendedTrieNode(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *p = (struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)o; + e = __pyx_tp_traverse_8_cdec_sa_TrieNode(o, v, a); if (e) return e; + if (p->phrase) { + e = (*v)(p->phrase, a); if (e) return e; + } + if (p->phrase_location) { + e = (*v)(p->phrase_location, a); if (e) return e; + } + if (p->suffix_link) { + e = (*v)(p->suffix_link, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_8_cdec_sa_ExtendedTrieNode(PyObject *o) { + struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *p = (struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)o; + PyObject* tmp; + __pyx_tp_clear_8_cdec_sa_TrieNode(o); + tmp = ((PyObject*)p->phrase); + p->phrase = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->phrase_location); + p->phrase_location = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->suffix_link); + p->suffix_link = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_8_cdec_sa_16ExtendedTrieNode_phrase(PyObject *o, void *x) { + return __pyx_pw_8_cdec_sa_16ExtendedTrieNode_6phrase_1__get__(o); +} + +static int __pyx_setprop_8_cdec_sa_16ExtendedTrieNode_phrase(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_8_cdec_sa_16ExtendedTrieNode_6phrase_3__set__(o, v); + } + else { + return __pyx_pw_8_cdec_sa_16ExtendedTrieNode_6phrase_5__del__(o); + } +} + +static PyObject *__pyx_getprop_8_cdec_sa_16ExtendedTrieNode_phrase_location(PyObject *o, void *x) { + return __pyx_pw_8_cdec_sa_16ExtendedTrieNode_15phrase_location_1__get__(o); +} + +static int __pyx_setprop_8_cdec_sa_16ExtendedTrieNode_phrase_location(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_8_cdec_sa_16ExtendedTrieNode_15phrase_location_3__set__(o, v); + } + else { + return __pyx_pw_8_cdec_sa_16ExtendedTrieNode_15phrase_location_5__del__(o); + } +} + +static PyObject *__pyx_getprop_8_cdec_sa_16ExtendedTrieNode_suffix_link(PyObject *o, void *x) { + return __pyx_pw_8_cdec_sa_16ExtendedTrieNode_11suffix_link_1__get__(o); +} + +static int __pyx_setprop_8_cdec_sa_16ExtendedTrieNode_suffix_link(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_8_cdec_sa_16ExtendedTrieNode_11suffix_link_3__set__(o, v); + } + else { + return __pyx_pw_8_cdec_sa_16ExtendedTrieNode_11suffix_link_5__del__(o); + } +} + +static PyMethodDef __pyx_methods_8_cdec_sa_ExtendedTrieNode[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_8_cdec_sa_ExtendedTrieNode[] = { + {(char *)"phrase", __pyx_getprop_8_cdec_sa_16ExtendedTrieNode_phrase, __pyx_setprop_8_cdec_sa_16ExtendedTrieNode_phrase, 0, 0}, + {(char *)"phrase_location", __pyx_getprop_8_cdec_sa_16ExtendedTrieNode_phrase_location, __pyx_setprop_8_cdec_sa_16ExtendedTrieNode_phrase_location, 0, 0}, + {(char *)"suffix_link", __pyx_getprop_8_cdec_sa_16ExtendedTrieNode_suffix_link, __pyx_setprop_8_cdec_sa_16ExtendedTrieNode_suffix_link, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_ExtendedTrieNode = { + 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_ExtendedTrieNode = { + 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_ExtendedTrieNode = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_ExtendedTrieNode = { + #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_8_cdec_sa_ExtendedTrieNode = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.ExtendedTrieNode"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_ExtendedTrieNode, /*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_ExtendedTrieNode, /*tp_as_number*/ + &__pyx_tp_as_sequence_ExtendedTrieNode, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_ExtendedTrieNode, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_ExtendedTrieNode, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_8_cdec_sa_ExtendedTrieNode, /*tp_traverse*/ + __pyx_tp_clear_8_cdec_sa_ExtendedTrieNode, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_ExtendedTrieNode, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_8_cdec_sa_ExtendedTrieNode, /*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_8_cdec_sa_ExtendedTrieNode, /*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_8_cdec_sa_TrieTable(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_TrieTable *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_TrieTable *)o); + p->root = Py_None; Py_INCREF(Py_None); + if (__pyx_pw_8_cdec_sa_9TrieTable_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_TrieTable(PyObject *o) { + struct __pyx_obj_8_cdec_sa_TrieTable *p = (struct __pyx_obj_8_cdec_sa_TrieTable *)o; + Py_XDECREF(p->root); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_8_cdec_sa_TrieTable(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_8_cdec_sa_TrieTable *p = (struct __pyx_obj_8_cdec_sa_TrieTable *)o; + if (p->root) { + e = (*v)(p->root, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_8_cdec_sa_TrieTable(PyObject *o) { + struct __pyx_obj_8_cdec_sa_TrieTable *p = (struct __pyx_obj_8_cdec_sa_TrieTable *)o; + PyObject* tmp; + tmp = ((PyObject*)p->root); + p->root = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_8_cdec_sa_9TrieTable_extended(PyObject *o, void *x) { + return __pyx_pw_8_cdec_sa_9TrieTable_8extended_1__get__(o); +} + +static int __pyx_setprop_8_cdec_sa_9TrieTable_extended(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_8_cdec_sa_9TrieTable_8extended_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_8_cdec_sa_9TrieTable_count(PyObject *o, void *x) { + return __pyx_pw_8_cdec_sa_9TrieTable_5count_1__get__(o); +} + +static int __pyx_setprop_8_cdec_sa_9TrieTable_count(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_8_cdec_sa_9TrieTable_5count_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_8_cdec_sa_9TrieTable_root(PyObject *o, void *x) { + return __pyx_pw_8_cdec_sa_9TrieTable_4root_1__get__(o); +} + +static int __pyx_setprop_8_cdec_sa_9TrieTable_root(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_8_cdec_sa_9TrieTable_4root_3__set__(o, v); + } + else { + return __pyx_pw_8_cdec_sa_9TrieTable_4root_5__del__(o); + } +} + +static PyMethodDef __pyx_methods_8_cdec_sa_TrieTable[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_8_cdec_sa_TrieTable[] = { + {(char *)"extended", __pyx_getprop_8_cdec_sa_9TrieTable_extended, __pyx_setprop_8_cdec_sa_9TrieTable_extended, 0, 0}, + {(char *)"count", __pyx_getprop_8_cdec_sa_9TrieTable_count, __pyx_setprop_8_cdec_sa_9TrieTable_count, 0, 0}, + {(char *)"root", __pyx_getprop_8_cdec_sa_9TrieTable_root, __pyx_setprop_8_cdec_sa_9TrieTable_root, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_TrieTable = { + 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_TrieTable = { + 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_TrieTable = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_TrieTable = { + #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_8_cdec_sa_TrieTable = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.TrieTable"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_TrieTable), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_TrieTable, /*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_TrieTable, /*tp_as_number*/ + &__pyx_tp_as_sequence_TrieTable, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_TrieTable, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_TrieTable, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_8_cdec_sa_TrieTable, /*tp_traverse*/ + __pyx_tp_clear_8_cdec_sa_TrieTable, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_TrieTable, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_8_cdec_sa_TrieTable, /*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_8_cdec_sa_TrieTable, /*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 struct __pyx_vtabstruct_8_cdec_sa_PhraseLocation __pyx_vtable_8_cdec_sa_PhraseLocation; + +static PyObject *__pyx_tp_new_8_cdec_sa_PhraseLocation(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_PhraseLocation *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)o); + p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_PhraseLocation; + p->arr = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_8_cdec_sa_14PhraseLocation_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_PhraseLocation(PyObject *o) { + struct __pyx_obj_8_cdec_sa_PhraseLocation *p = (struct __pyx_obj_8_cdec_sa_PhraseLocation *)o; + Py_XDECREF(((PyObject *)p->arr)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_8_cdec_sa_PhraseLocation(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_8_cdec_sa_PhraseLocation *p = (struct __pyx_obj_8_cdec_sa_PhraseLocation *)o; + if (p->arr) { + e = (*v)(((PyObject*)p->arr), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_8_cdec_sa_PhraseLocation(PyObject *o) { + struct __pyx_obj_8_cdec_sa_PhraseLocation *p = (struct __pyx_obj_8_cdec_sa_PhraseLocation *)o; + PyObject* tmp; + tmp = ((PyObject*)p->arr); + p->arr = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_8_cdec_sa_PhraseLocation[] = { + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_PhraseLocation = { + 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_PhraseLocation = { + 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_PhraseLocation = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_PhraseLocation = { + #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_8_cdec_sa_PhraseLocation = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.PhraseLocation"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_PhraseLocation), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_PhraseLocation, /*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_PhraseLocation, /*tp_as_number*/ + &__pyx_tp_as_sequence_PhraseLocation, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_PhraseLocation, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_PhraseLocation, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_8_cdec_sa_PhraseLocation, /*tp_traverse*/ + __pyx_tp_clear_8_cdec_sa_PhraseLocation, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_PhraseLocation, /*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_8_cdec_sa_PhraseLocation, /*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_8_cdec_sa_Sampler(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_Sampler *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_Sampler *)o); + p->sa = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_8_cdec_sa_7Sampler_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_Sampler(PyObject *o) { + struct __pyx_obj_8_cdec_sa_Sampler *p = (struct __pyx_obj_8_cdec_sa_Sampler *)o; + Py_XDECREF(((PyObject *)p->sa)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_8_cdec_sa_Sampler(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_8_cdec_sa_Sampler *p = (struct __pyx_obj_8_cdec_sa_Sampler *)o; + if (p->sa) { + e = (*v)(((PyObject*)p->sa), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_8_cdec_sa_Sampler(PyObject *o) { + struct __pyx_obj_8_cdec_sa_Sampler *p = (struct __pyx_obj_8_cdec_sa_Sampler *)o; + PyObject* tmp; + tmp = ((PyObject*)p->sa); + p->sa = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_8_cdec_sa_Sampler[] = { + {__Pyx_NAMESTR("sample"), (PyCFunction)__pyx_pw_8_cdec_sa_7Sampler_3sample, METH_O, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_7Sampler_2sample)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Sampler = { + 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_Sampler = { + 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_Sampler = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Sampler = { + #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_8_cdec_sa_Sampler = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.Sampler"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_Sampler), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_Sampler, /*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_Sampler, /*tp_as_number*/ + &__pyx_tp_as_sequence_Sampler, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Sampler, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Sampler, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + __Pyx_DOCSTR("A Sampler implements a logic for choosing\n samples from a population range"), /*tp_doc*/ + __pyx_tp_traverse_8_cdec_sa_Sampler, /*tp_traverse*/ + __pyx_tp_clear_8_cdec_sa_Sampler, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_Sampler, /*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_8_cdec_sa_Sampler, /*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 struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory; + +static PyObject *__pyx_tp_new_8_cdec_sa_HieroCachingRuleFactory(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)o); + p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_HieroCachingRuleFactory; + p->rules = ((struct __pyx_obj_8_cdec_sa_TrieTable *)Py_None); Py_INCREF(Py_None); + p->sampler = ((struct __pyx_obj_8_cdec_sa_Sampler *)Py_None); Py_INCREF(Py_None); + p->precomputed_index = Py_None; Py_INCREF(Py_None); + p->precomputed_collocations = Py_None; Py_INCREF(Py_None); + p->precompute_file = Py_None; Py_INCREF(Py_None); + p->max_rank = Py_None; Py_INCREF(Py_None); + p->prev_norm_prefix = Py_None; Py_INCREF(Py_None); + p->fsa = ((struct __pyx_obj_8_cdec_sa_SuffixArray *)Py_None); Py_INCREF(Py_None); + p->fda = ((struct __pyx_obj_8_cdec_sa_DataArray *)Py_None); Py_INCREF(Py_None); + p->eda = ((struct __pyx_obj_8_cdec_sa_DataArray *)Py_None); Py_INCREF(Py_None); + p->alignment = ((struct __pyx_obj_8_cdec_sa_Alignment *)Py_None); Py_INCREF(Py_None); + p->eid2symid = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->fid2symid = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->findexes = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->findexes1 = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa_HieroCachingRuleFactory(PyObject *o) { + struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *p = (struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)o; + Py_XDECREF(((PyObject *)p->rules)); + Py_XDECREF(((PyObject *)p->sampler)); + Py_XDECREF(p->precomputed_index); + Py_XDECREF(p->precomputed_collocations); + Py_XDECREF(p->precompute_file); + Py_XDECREF(p->max_rank); + Py_XDECREF(p->prev_norm_prefix); + Py_XDECREF(((PyObject *)p->fsa)); + Py_XDECREF(((PyObject *)p->fda)); + Py_XDECREF(((PyObject *)p->eda)); + Py_XDECREF(((PyObject *)p->alignment)); + Py_XDECREF(((PyObject *)p->eid2symid)); + Py_XDECREF(((PyObject *)p->fid2symid)); + Py_XDECREF(((PyObject *)p->findexes)); + Py_XDECREF(((PyObject *)p->findexes1)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_8_cdec_sa_HieroCachingRuleFactory(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *p = (struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)o; + if (p->rules) { + e = (*v)(((PyObject*)p->rules), a); if (e) return e; + } + if (p->sampler) { + e = (*v)(((PyObject*)p->sampler), a); if (e) return e; + } + if (p->precomputed_index) { + e = (*v)(p->precomputed_index, a); if (e) return e; + } + if (p->precomputed_collocations) { + e = (*v)(p->precomputed_collocations, a); if (e) return e; + } + if (p->precompute_file) { + e = (*v)(p->precompute_file, a); if (e) return e; + } + if (p->max_rank) { + e = (*v)(p->max_rank, a); if (e) return e; + } + if (p->prev_norm_prefix) { + e = (*v)(p->prev_norm_prefix, a); if (e) return e; + } + if (p->fsa) { + e = (*v)(((PyObject*)p->fsa), a); if (e) return e; + } + if (p->fda) { + e = (*v)(((PyObject*)p->fda), a); if (e) return e; + } + if (p->eda) { + e = (*v)(((PyObject*)p->eda), a); if (e) return e; + } + if (p->alignment) { + e = (*v)(((PyObject*)p->alignment), a); if (e) return e; + } + if (p->eid2symid) { + e = (*v)(((PyObject*)p->eid2symid), a); if (e) return e; + } + if (p->fid2symid) { + e = (*v)(((PyObject*)p->fid2symid), a); if (e) return e; + } + if (p->findexes) { + e = (*v)(((PyObject*)p->findexes), a); if (e) return e; + } + if (p->findexes1) { + e = (*v)(((PyObject*)p->findexes1), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_8_cdec_sa_HieroCachingRuleFactory(PyObject *o) { + struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *p = (struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)o; + PyObject* tmp; + tmp = ((PyObject*)p->rules); + p->rules = ((struct __pyx_obj_8_cdec_sa_TrieTable *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->sampler); + p->sampler = ((struct __pyx_obj_8_cdec_sa_Sampler *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->precomputed_index); + p->precomputed_index = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->precomputed_collocations); + p->precomputed_collocations = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->precompute_file); + p->precompute_file = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->max_rank); + p->max_rank = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->prev_norm_prefix); + p->prev_norm_prefix = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->fsa); + p->fsa = ((struct __pyx_obj_8_cdec_sa_SuffixArray *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->fda); + p->fda = ((struct __pyx_obj_8_cdec_sa_DataArray *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->eda); + p->eda = ((struct __pyx_obj_8_cdec_sa_DataArray *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->alignment); + p->alignment = ((struct __pyx_obj_8_cdec_sa_Alignment *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->eid2symid); + p->eid2symid = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->fid2symid); + p->fid2symid = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->findexes); + p->findexes = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->findexes1); + p->findexes1 = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_8_cdec_sa_HieroCachingRuleFactory[] = { + {__Pyx_NAMESTR("configure"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_3configure, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_23HieroCachingRuleFactory_2configure)}, + {__Pyx_NAMESTR("pattern2phrase"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_5pattern2phrase, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("pattern2phrase_plus"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_7pattern2phrase_plus, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("precompute"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_9precompute, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_precomputed_collocation"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_11get_precomputed_collocation, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("advance"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_13advance, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_all_nodes_isteps_away"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_15get_all_nodes_isteps_away, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("reachable"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_17reachable, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("shortest"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_19shortest, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_next_states"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_21get_next_states, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("input"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_23input, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_23HieroCachingRuleFactory_22input)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_HieroCachingRuleFactory = { + 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_HieroCachingRuleFactory = { + 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_HieroCachingRuleFactory = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_HieroCachingRuleFactory = { + #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_8_cdec_sa_HieroCachingRuleFactory = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.HieroCachingRuleFactory"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa_HieroCachingRuleFactory, /*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_HieroCachingRuleFactory, /*tp_as_number*/ + &__pyx_tp_as_sequence_HieroCachingRuleFactory, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_HieroCachingRuleFactory, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_HieroCachingRuleFactory, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + __Pyx_DOCSTR("This RuleFactory implements a caching \n method using TrieTable, which makes phrase\n generation somewhat speedier -- phrases only\n need to be extracted once (however, it is\n quite possible they need to be scored \n for each input sentence, for contextual models)"), /*tp_doc*/ + __pyx_tp_traverse_8_cdec_sa_HieroCachingRuleFactory, /*tp_traverse*/ + __pyx_tp_clear_8_cdec_sa_HieroCachingRuleFactory, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa_HieroCachingRuleFactory, /*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_8_cdec_sa_HieroCachingRuleFactory, /*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_8_cdec_sa___pyx_scope_struct__compute_stats(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *)o); + p->__pyx_v_ngram = 0; + p->__pyx_v_ngram_start = 0; + p->__pyx_v_ngram_starts = 0; + p->__pyx_v_run_start = 0; + p->__pyx_v_self = 0; + p->__pyx_v_veb = 0; + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa___pyx_scope_struct__compute_stats(PyObject *o) { + struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *p = (struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_ngram)); + Py_XDECREF(((PyObject *)p->__pyx_v_ngram_start)); + Py_XDECREF(((PyObject *)p->__pyx_v_ngram_starts)); + Py_XDECREF(((PyObject *)p->__pyx_v_run_start)); + Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(((PyObject *)p->__pyx_v_veb)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_8_cdec_sa___pyx_scope_struct__compute_stats(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *p = (struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *)o; + if (p->__pyx_v_ngram) { + e = (*v)(p->__pyx_v_ngram, a); if (e) return e; + } + if (p->__pyx_v_ngram_start) { + e = (*v)(((PyObject*)p->__pyx_v_ngram_start), a); if (e) return e; + } + if (p->__pyx_v_ngram_starts) { + e = (*v)(p->__pyx_v_ngram_starts, a); if (e) return e; + } + if (p->__pyx_v_run_start) { + e = (*v)(((PyObject*)p->__pyx_v_run_start), 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_veb) { + e = (*v)(((PyObject*)p->__pyx_v_veb), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_8_cdec_sa___pyx_scope_struct__compute_stats(PyObject *o) { + struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *p = (struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_ngram); + p->__pyx_v_ngram = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_ngram_start); + p->__pyx_v_ngram_start = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_ngram_starts); + p->__pyx_v_ngram_starts = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_run_start); + p->__pyx_v_run_start = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_8_cdec_sa_LCP *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_veb); + p->__pyx_v_veb = ((struct __pyx_obj_8_cdec_sa_VEB *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_8_cdec_sa___pyx_scope_struct__compute_stats[] = { + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct__compute_stats = { + 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__compute_stats = { + 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__compute_stats = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct__compute_stats = { + #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_8_cdec_sa___pyx_scope_struct__compute_stats = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.__pyx_scope_struct__compute_stats"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa___pyx_scope_struct__compute_stats, /*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__compute_stats, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct__compute_stats, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct__compute_stats, /*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__compute_stats, /*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_8_cdec_sa___pyx_scope_struct__compute_stats, /*tp_traverse*/ + __pyx_tp_clear_8_cdec_sa___pyx_scope_struct__compute_stats, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa___pyx_scope_struct__compute_stats, /*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_8_cdec_sa___pyx_scope_struct__compute_stats, /*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_8_cdec_sa___pyx_scope_struct_1_input(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *)o); + p->__pyx_v_alignment = 0; + p->__pyx_v_als = 0; + p->__pyx_v_alslist = 0; + p->__pyx_v_chunklen = 0; + p->__pyx_v_count = 0; + p->__pyx_v_currcount = 0; + p->__pyx_v_e = 0; + p->__pyx_v_elist = 0; + p->__pyx_v_extract = 0; + p->__pyx_v_extract_start = 0; + p->__pyx_v_extract_stop = 0; + p->__pyx_v_extracts = 0; + p->__pyx_v_f = 0; + p->__pyx_v_f_margin = 0; + p->__pyx_v_fals = 0; + p->__pyx_v_fcount = 0; + p->__pyx_v_fphrases = 0; + p->__pyx_v_frontier = 0; + p->__pyx_v_frontier_nodes = 0; + p->__pyx_v_fwords = 0; + p->__pyx_v_hiero_phrase = 0; + p->__pyx_v_is_shadow_path = 0; + p->__pyx_v_key = 0; + p->__pyx_v_model = 0; + p->__pyx_v_models = 0; + p->__pyx_v_new_frontier = 0; + p->__pyx_v_new_node = 0; + p->__pyx_v_next_states = 0; + p->__pyx_v_node = 0; + p->__pyx_v_nodes_isteps_away_buffer = 0; + p->__pyx_v_pathlen = 0; + p->__pyx_v_phrase = 0; + p->__pyx_v_phrase_location = 0; + p->__pyx_v_prefix = 0; + p->__pyx_v_reachable_buffer = 0; + p->__pyx_v_sa_range = 0; + p->__pyx_v_sample = 0; + p->__pyx_v_scores = 0; + p->__pyx_v_self = 0; + p->__pyx_v_spanlen = 0; + p->__pyx_v_stop_time = 0; + p->__pyx_v_str_phrase = 0; + p->__pyx_v_suffix_link = 0; + p->__pyx_v_suffix_link_xcat_index = 0; + p->__pyx_v_word_id = 0; + p->__pyx_v_xcat_index = 0; + p->__pyx_v_xnode = 0; + p->__pyx_v_xroot = 0; + p->__pyx_t_2 = 0; + p->__pyx_t_3 = 0; + p->__pyx_t_4 = 0; + return o; +} + +static void __pyx_tp_dealloc_8_cdec_sa___pyx_scope_struct_1_input(PyObject *o) { + struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *p = (struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *)o; + Py_XDECREF(p->__pyx_v_alignment); + Py_XDECREF(p->__pyx_v_als); + Py_XDECREF(p->__pyx_v_alslist); + Py_XDECREF(((PyObject *)p->__pyx_v_chunklen)); + Py_XDECREF(p->__pyx_v_count); + Py_XDECREF(p->__pyx_v_currcount); + Py_XDECREF(p->__pyx_v_e); + Py_XDECREF(p->__pyx_v_elist); + Py_XDECREF(p->__pyx_v_extract); + Py_XDECREF(p->__pyx_v_extract_start); + Py_XDECREF(p->__pyx_v_extract_stop); + Py_XDECREF(((PyObject *)p->__pyx_v_extracts)); + Py_XDECREF(p->__pyx_v_f); + Py_XDECREF(p->__pyx_v_f_margin); + Py_XDECREF(((PyObject *)p->__pyx_v_fals)); + Py_XDECREF(((PyObject *)p->__pyx_v_fcount)); + Py_XDECREF(((PyObject *)p->__pyx_v_fphrases)); + Py_XDECREF(((PyObject *)p->__pyx_v_frontier)); + Py_XDECREF(p->__pyx_v_frontier_nodes); + Py_XDECREF(p->__pyx_v_fwords); + Py_XDECREF(((PyObject *)p->__pyx_v_hiero_phrase)); + Py_XDECREF(p->__pyx_v_is_shadow_path); + Py_XDECREF(((PyObject *)p->__pyx_v_key)); + Py_XDECREF(p->__pyx_v_model); + Py_XDECREF(p->__pyx_v_models); + Py_XDECREF(((PyObject *)p->__pyx_v_new_frontier)); + Py_XDECREF(p->__pyx_v_new_node); + Py_XDECREF(((PyObject *)p->__pyx_v_next_states)); + Py_XDECREF(p->__pyx_v_node); + Py_XDECREF(((PyObject *)p->__pyx_v_nodes_isteps_away_buffer)); + Py_XDECREF(p->__pyx_v_pathlen); + Py_XDECREF(p->__pyx_v_phrase); + Py_XDECREF(((PyObject *)p->__pyx_v_phrase_location)); + Py_XDECREF(p->__pyx_v_prefix); + Py_XDECREF(((PyObject *)p->__pyx_v_reachable_buffer)); + Py_XDECREF(p->__pyx_v_sa_range); + Py_XDECREF(((PyObject *)p->__pyx_v_sample)); + Py_XDECREF(((PyObject *)p->__pyx_v_scores)); + Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(p->__pyx_v_spanlen); + Py_XDECREF(p->__pyx_v_stop_time); + Py_XDECREF(p->__pyx_v_str_phrase); + Py_XDECREF(p->__pyx_v_suffix_link); + Py_XDECREF(p->__pyx_v_suffix_link_xcat_index); + Py_XDECREF(p->__pyx_v_word_id); + Py_XDECREF(p->__pyx_v_xcat_index); + Py_XDECREF(p->__pyx_v_xnode); + Py_XDECREF(p->__pyx_v_xroot); + Py_XDECREF(p->__pyx_t_2); + Py_XDECREF(p->__pyx_t_3); + Py_XDECREF(p->__pyx_t_4); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_8_cdec_sa___pyx_scope_struct_1_input(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *p = (struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *)o; + if (p->__pyx_v_alignment) { + e = (*v)(p->__pyx_v_alignment, a); if (e) return e; + } + if (p->__pyx_v_als) { + e = (*v)(p->__pyx_v_als, a); if (e) return e; + } + if (p->__pyx_v_alslist) { + e = (*v)(p->__pyx_v_alslist, a); if (e) return e; + } + if (p->__pyx_v_chunklen) { + e = (*v)(((PyObject*)p->__pyx_v_chunklen), a); if (e) return e; + } + if (p->__pyx_v_count) { + e = (*v)(p->__pyx_v_count, a); if (e) return e; + } + if (p->__pyx_v_currcount) { + e = (*v)(p->__pyx_v_currcount, a); if (e) return e; + } + if (p->__pyx_v_e) { + e = (*v)(p->__pyx_v_e, a); if (e) return e; + } + if (p->__pyx_v_elist) { + e = (*v)(p->__pyx_v_elist, a); if (e) return e; + } + if (p->__pyx_v_extract) { + e = (*v)(p->__pyx_v_extract, a); if (e) return e; + } + if (p->__pyx_v_extract_start) { + e = (*v)(p->__pyx_v_extract_start, a); if (e) return e; + } + if (p->__pyx_v_extract_stop) { + e = (*v)(p->__pyx_v_extract_stop, a); if (e) return e; + } + if (p->__pyx_v_extracts) { + e = (*v)(p->__pyx_v_extracts, a); if (e) return e; + } + if (p->__pyx_v_f) { + e = (*v)(p->__pyx_v_f, a); if (e) return e; + } + if (p->__pyx_v_f_margin) { + e = (*v)(p->__pyx_v_f_margin, a); if (e) return e; + } + if (p->__pyx_v_fals) { + e = (*v)(p->__pyx_v_fals, a); if (e) return e; + } + if (p->__pyx_v_fcount) { + e = (*v)(p->__pyx_v_fcount, a); if (e) return e; + } + if (p->__pyx_v_fphrases) { + e = (*v)(p->__pyx_v_fphrases, a); if (e) return e; + } + if (p->__pyx_v_frontier) { + e = (*v)(p->__pyx_v_frontier, a); if (e) return e; + } + if (p->__pyx_v_frontier_nodes) { + e = (*v)(p->__pyx_v_frontier_nodes, a); if (e) return e; + } + if (p->__pyx_v_fwords) { + e = (*v)(p->__pyx_v_fwords, a); if (e) return e; + } + if (p->__pyx_v_hiero_phrase) { + e = (*v)(((PyObject*)p->__pyx_v_hiero_phrase), a); if (e) return e; + } + if (p->__pyx_v_is_shadow_path) { + e = (*v)(p->__pyx_v_is_shadow_path, a); if (e) return e; + } + if (p->__pyx_v_key) { + e = (*v)(p->__pyx_v_key, a); if (e) return e; + } + if (p->__pyx_v_model) { + e = (*v)(p->__pyx_v_model, a); if (e) return e; + } + if (p->__pyx_v_models) { + e = (*v)(p->__pyx_v_models, a); if (e) return e; + } + if (p->__pyx_v_new_frontier) { + e = (*v)(p->__pyx_v_new_frontier, a); if (e) return e; + } + if (p->__pyx_v_new_node) { + e = (*v)(p->__pyx_v_new_node, a); if (e) return e; + } + if (p->__pyx_v_next_states) { + e = (*v)(p->__pyx_v_next_states, a); if (e) return e; + } + if (p->__pyx_v_node) { + e = (*v)(p->__pyx_v_node, a); if (e) return e; + } + if (p->__pyx_v_nodes_isteps_away_buffer) { + e = (*v)(p->__pyx_v_nodes_isteps_away_buffer, a); if (e) return e; + } + if (p->__pyx_v_pathlen) { + e = (*v)(p->__pyx_v_pathlen, a); if (e) return e; + } + if (p->__pyx_v_phrase) { + e = (*v)(p->__pyx_v_phrase, a); if (e) return e; + } + if (p->__pyx_v_phrase_location) { + e = (*v)(((PyObject*)p->__pyx_v_phrase_location), a); if (e) return e; + } + if (p->__pyx_v_prefix) { + e = (*v)(p->__pyx_v_prefix, a); if (e) return e; + } + if (p->__pyx_v_reachable_buffer) { + e = (*v)(p->__pyx_v_reachable_buffer, a); if (e) return e; + } + if (p->__pyx_v_sa_range) { + e = (*v)(p->__pyx_v_sa_range, a); if (e) return e; + } + if (p->__pyx_v_sample) { + e = (*v)(((PyObject*)p->__pyx_v_sample), a); if (e) return e; + } + if (p->__pyx_v_scores) { + e = (*v)(p->__pyx_v_scores, 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_spanlen) { + e = (*v)(p->__pyx_v_spanlen, a); if (e) return e; + } + if (p->__pyx_v_stop_time) { + e = (*v)(p->__pyx_v_stop_time, a); if (e) return e; + } + if (p->__pyx_v_str_phrase) { + e = (*v)(p->__pyx_v_str_phrase, a); if (e) return e; + } + if (p->__pyx_v_suffix_link) { + e = (*v)(p->__pyx_v_suffix_link, a); if (e) return e; + } + if (p->__pyx_v_suffix_link_xcat_index) { + e = (*v)(p->__pyx_v_suffix_link_xcat_index, a); if (e) return e; + } + if (p->__pyx_v_word_id) { + e = (*v)(p->__pyx_v_word_id, a); if (e) return e; + } + if (p->__pyx_v_xcat_index) { + e = (*v)(p->__pyx_v_xcat_index, a); if (e) return e; + } + if (p->__pyx_v_xnode) { + e = (*v)(p->__pyx_v_xnode, a); if (e) return e; + } + if (p->__pyx_v_xroot) { + e = (*v)(p->__pyx_v_xroot, a); if (e) return e; + } + if (p->__pyx_t_2) { + e = (*v)(p->__pyx_t_2, a); if (e) return e; + } + if (p->__pyx_t_3) { + e = (*v)(p->__pyx_t_3, a); if (e) return e; + } + if (p->__pyx_t_4) { + e = (*v)(p->__pyx_t_4, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_8_cdec_sa___pyx_scope_struct_1_input(PyObject *o) { + struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *p = (struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_alignment); + p->__pyx_v_alignment = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_als); + p->__pyx_v_als = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_alslist); + p->__pyx_v_alslist = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_chunklen); + p->__pyx_v_chunklen = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_count); + p->__pyx_v_count = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_currcount); + p->__pyx_v_currcount = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_e); + p->__pyx_v_e = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_elist); + p->__pyx_v_elist = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_extract); + p->__pyx_v_extract = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_extract_start); + p->__pyx_v_extract_start = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_extract_stop); + p->__pyx_v_extract_stop = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_extracts); + p->__pyx_v_extracts = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_f); + p->__pyx_v_f = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_f_margin); + p->__pyx_v_f_margin = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_fals); + p->__pyx_v_fals = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_fcount); + p->__pyx_v_fcount = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_fphrases); + p->__pyx_v_fphrases = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_frontier); + p->__pyx_v_frontier = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_frontier_nodes); + p->__pyx_v_frontier_nodes = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_fwords); + p->__pyx_v_fwords = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_hiero_phrase); + p->__pyx_v_hiero_phrase = ((struct __pyx_obj_8_cdec_sa_Phrase *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_is_shadow_path); + p->__pyx_v_is_shadow_path = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_key); + p->__pyx_v_key = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_model); + p->__pyx_v_model = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_models); + p->__pyx_v_models = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_new_frontier); + p->__pyx_v_new_frontier = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_new_node); + p->__pyx_v_new_node = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_next_states); + p->__pyx_v_next_states = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_node); + p->__pyx_v_node = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_nodes_isteps_away_buffer); + p->__pyx_v_nodes_isteps_away_buffer = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_pathlen); + p->__pyx_v_pathlen = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_phrase); + p->__pyx_v_phrase = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_phrase_location); + p->__pyx_v_phrase_location = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_prefix); + p->__pyx_v_prefix = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_reachable_buffer); + p->__pyx_v_reachable_buffer = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_sa_range); + p->__pyx_v_sa_range = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_sample); + p->__pyx_v_sample = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_scores); + p->__pyx_v_scores = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_spanlen); + p->__pyx_v_spanlen = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_stop_time); + p->__pyx_v_stop_time = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_str_phrase); + p->__pyx_v_str_phrase = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_suffix_link); + p->__pyx_v_suffix_link = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_suffix_link_xcat_index); + p->__pyx_v_suffix_link_xcat_index = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_word_id); + p->__pyx_v_word_id = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_xcat_index); + p->__pyx_v_xcat_index = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_xnode); + p->__pyx_v_xnode = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_xroot); + p->__pyx_v_xroot = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_2); + p->__pyx_t_2 = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_3); + p->__pyx_t_3 = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_4); + p->__pyx_t_4 = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_8_cdec_sa___pyx_scope_struct_1_input[] = { + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1_input = { + 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_input = { + 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_input = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1_input = { + #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_8_cdec_sa___pyx_scope_struct_1_input = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec_sa.__pyx_scope_struct_1_input"), /*tp_name*/ + sizeof(struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_8_cdec_sa___pyx_scope_struct_1_input, /*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_input, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_1_input, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_1_input, /*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_input, /*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_8_cdec_sa___pyx_scope_struct_1_input, /*tp_traverse*/ + __pyx_tp_clear_8_cdec_sa___pyx_scope_struct_1_input, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_8_cdec_sa___pyx_scope_struct_1_input, /*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_8_cdec_sa___pyx_scope_struct_1_input, /*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} +}; + +#if PY_MAJOR_VERSION >= 3 +static struct PyModuleDef __pyx_moduledef = { + PyModuleDef_HEAD_INIT, + __Pyx_NAMESTR("_cdec_sa"), + 0, /* m_doc */ + -1, /* m_size */ + __pyx_methods /* m_methods */, + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ +}; +#endif + +static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0}, + {&__pyx_n_s_101, __pyx_k_101, sizeof(__pyx_k_101), 0, 0, 1, 1}, + {&__pyx_n_s_102, __pyx_k_102, sizeof(__pyx_k_102), 0, 0, 1, 1}, + {&__pyx_kp_s_104, __pyx_k_104, sizeof(__pyx_k_104), 0, 0, 1, 0}, + {&__pyx_kp_s_106, __pyx_k_106, sizeof(__pyx_k_106), 0, 0, 1, 0}, + {&__pyx_kp_s_107, __pyx_k_107, sizeof(__pyx_k_107), 0, 0, 1, 0}, + {&__pyx_kp_s_108, __pyx_k_108, sizeof(__pyx_k_108), 0, 0, 1, 0}, + {&__pyx_kp_s_109, __pyx_k_109, sizeof(__pyx_k_109), 0, 0, 1, 0}, + {&__pyx_kp_s_110, __pyx_k_110, sizeof(__pyx_k_110), 0, 0, 1, 0}, + {&__pyx_kp_s_111, __pyx_k_111, sizeof(__pyx_k_111), 0, 0, 1, 0}, + {&__pyx_kp_s_112, __pyx_k_112, sizeof(__pyx_k_112), 0, 0, 1, 0}, + {&__pyx_kp_s_113, __pyx_k_113, sizeof(__pyx_k_113), 0, 0, 1, 0}, + {&__pyx_kp_s_114, __pyx_k_114, sizeof(__pyx_k_114), 0, 0, 1, 0}, + {&__pyx_kp_s_115, __pyx_k_115, sizeof(__pyx_k_115), 0, 0, 1, 0}, + {&__pyx_kp_s_116, __pyx_k_116, sizeof(__pyx_k_116), 0, 0, 1, 0}, + {&__pyx_n_s_117, __pyx_k_117, sizeof(__pyx_k_117), 0, 0, 1, 1}, + {&__pyx_kp_s_118, __pyx_k_118, sizeof(__pyx_k_118), 0, 0, 1, 0}, + {&__pyx_kp_s_119, __pyx_k_119, sizeof(__pyx_k_119), 0, 0, 1, 0}, + {&__pyx_n_s_121, __pyx_k_121, sizeof(__pyx_k_121), 0, 0, 1, 1}, + {&__pyx_kp_s_122, __pyx_k_122, sizeof(__pyx_k_122), 0, 0, 1, 0}, + {&__pyx_kp_s_123, __pyx_k_123, sizeof(__pyx_k_123), 0, 0, 1, 0}, + {&__pyx_kp_s_124, __pyx_k_124, sizeof(__pyx_k_124), 0, 0, 1, 0}, + {&__pyx_kp_s_125, __pyx_k_125, sizeof(__pyx_k_125), 0, 0, 1, 0}, + {&__pyx_kp_s_126, __pyx_k_126, sizeof(__pyx_k_126), 0, 0, 1, 0}, + {&__pyx_kp_s_127, __pyx_k_127, sizeof(__pyx_k_127), 0, 0, 1, 0}, + {&__pyx_kp_s_128, __pyx_k_128, sizeof(__pyx_k_128), 0, 0, 1, 0}, + {&__pyx_kp_s_129, __pyx_k_129, sizeof(__pyx_k_129), 0, 0, 1, 0}, + {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0}, + {&__pyx_kp_s_130, __pyx_k_130, sizeof(__pyx_k_130), 0, 0, 1, 0}, + {&__pyx_kp_s_131, __pyx_k_131, sizeof(__pyx_k_131), 0, 0, 1, 0}, + {&__pyx_kp_s_134, __pyx_k_134, sizeof(__pyx_k_134), 0, 0, 1, 0}, + {&__pyx_kp_s_135, __pyx_k_135, sizeof(__pyx_k_135), 0, 0, 1, 0}, + {&__pyx_kp_s_139, __pyx_k_139, sizeof(__pyx_k_139), 0, 0, 1, 0}, + {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0}, + {&__pyx_kp_s_144, __pyx_k_144, sizeof(__pyx_k_144), 0, 0, 1, 0}, + {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0}, + {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0}, + {&__pyx_kp_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 0}, + {&__pyx_n_s_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 1, 1}, + {&__pyx_kp_s_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 0, 1, 0}, + {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0}, + {&__pyx_kp_s_32, __pyx_k_32, sizeof(__pyx_k_32), 0, 0, 1, 0}, + {&__pyx_kp_s_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 1, 0}, + {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0}, + {&__pyx_kp_s_42, __pyx_k_42, sizeof(__pyx_k_42), 0, 0, 1, 0}, + {&__pyx_kp_s_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 1, 0}, + {&__pyx_kp_s_45, __pyx_k_45, sizeof(__pyx_k_45), 0, 0, 1, 0}, + {&__pyx_kp_s_47, __pyx_k_47, sizeof(__pyx_k_47), 0, 0, 1, 0}, + {&__pyx_kp_s_49, __pyx_k_49, sizeof(__pyx_k_49), 0, 0, 1, 0}, + {&__pyx_kp_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 0}, + {&__pyx_kp_s_53, __pyx_k_53, sizeof(__pyx_k_53), 0, 0, 1, 0}, + {&__pyx_kp_s_55, __pyx_k_55, sizeof(__pyx_k_55), 0, 0, 1, 0}, + {&__pyx_kp_s_56, __pyx_k_56, sizeof(__pyx_k_56), 0, 0, 1, 0}, + {&__pyx_kp_s_57, __pyx_k_57, sizeof(__pyx_k_57), 0, 0, 1, 0}, + {&__pyx_kp_s_59, __pyx_k_59, sizeof(__pyx_k_59), 0, 0, 1, 0}, + {&__pyx_kp_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 0}, + {&__pyx_kp_s_61, __pyx_k_61, sizeof(__pyx_k_61), 0, 0, 1, 0}, + {&__pyx_kp_s_62, __pyx_k_62, sizeof(__pyx_k_62), 0, 0, 1, 0}, + {&__pyx_kp_s_63, __pyx_k_63, sizeof(__pyx_k_63), 0, 0, 1, 0}, + {&__pyx_kp_s_64, __pyx_k_64, sizeof(__pyx_k_64), 0, 0, 1, 0}, + {&__pyx_kp_s_65, __pyx_k_65, sizeof(__pyx_k_65), 0, 0, 1, 0}, + {&__pyx_kp_s_66, __pyx_k_66, sizeof(__pyx_k_66), 0, 0, 1, 0}, + {&__pyx_kp_s_67, __pyx_k_67, sizeof(__pyx_k_67), 0, 0, 1, 0}, + {&__pyx_n_s_68, __pyx_k_68, sizeof(__pyx_k_68), 0, 0, 1, 1}, + {&__pyx_n_s_69, __pyx_k_69, sizeof(__pyx_k_69), 0, 0, 1, 1}, + {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0}, + {&__pyx_kp_s_70, __pyx_k_70, sizeof(__pyx_k_70), 0, 0, 1, 0}, + {&__pyx_kp_s_72, __pyx_k_72, sizeof(__pyx_k_72), 0, 0, 1, 0}, + {&__pyx_kp_s_74, __pyx_k_74, sizeof(__pyx_k_74), 0, 0, 1, 0}, + {&__pyx_kp_s_76, __pyx_k_76, sizeof(__pyx_k_76), 0, 0, 1, 0}, + {&__pyx_kp_s_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 1, 0}, + {&__pyx_kp_s_81, __pyx_k_81, sizeof(__pyx_k_81), 0, 0, 1, 0}, + {&__pyx_kp_s_82, __pyx_k_82, sizeof(__pyx_k_82), 0, 0, 1, 0}, + {&__pyx_kp_s_83, __pyx_k_83, sizeof(__pyx_k_83), 0, 0, 1, 0}, + {&__pyx_kp_s_84, __pyx_k_84, sizeof(__pyx_k_84), 0, 0, 1, 0}, + {&__pyx_kp_s_85, __pyx_k_85, sizeof(__pyx_k_85), 0, 0, 1, 0}, + {&__pyx_kp_s_86, __pyx_k_86, sizeof(__pyx_k_86), 0, 0, 1, 0}, + {&__pyx_kp_s_87, __pyx_k_87, sizeof(__pyx_k_87), 0, 0, 1, 0}, + {&__pyx_kp_s_88, __pyx_k_88, sizeof(__pyx_k_88), 0, 0, 1, 0}, + {&__pyx_kp_s_89, __pyx_k_89, sizeof(__pyx_k_89), 0, 0, 1, 0}, + {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0}, + {&__pyx_kp_s_90, __pyx_k_90, sizeof(__pyx_k_90), 0, 0, 1, 0}, + {&__pyx_kp_s_92, __pyx_k_92, sizeof(__pyx_k_92), 0, 0, 1, 0}, + {&__pyx_kp_s_93, __pyx_k_93, sizeof(__pyx_k_93), 0, 0, 1, 0}, + {&__pyx_kp_s_98, __pyx_k_98, sizeof(__pyx_k_98), 0, 0, 1, 0}, + {&__pyx_kp_s_99, __pyx_k_99, sizeof(__pyx_k_99), 0, 0, 1, 0}, + {&__pyx_kp_s__0, __pyx_k__0, sizeof(__pyx_k__0), 0, 0, 1, 0}, + {&__pyx_kp_s__1, __pyx_k__1, sizeof(__pyx_k__1), 0, 0, 1, 0}, + {&__pyx_n_s__END_OF_FILE, __pyx_k__END_OF_FILE, sizeof(__pyx_k__END_OF_FILE), 0, 0, 1, 1}, + {&__pyx_n_s__END_OF_LINE, __pyx_k__END_OF_LINE, sizeof(__pyx_k__END_OF_LINE), 0, 0, 1, 1}, + {&__pyx_n_s__Exception, __pyx_k__Exception, sizeof(__pyx_k__Exception), 0, 0, 1, 1}, + {&__pyx_n_s__GzipFile, __pyx_k__GzipFile, sizeof(__pyx_k__GzipFile), 0, 0, 1, 1}, + {&__pyx_n_s__IndexError, __pyx_k__IndexError, sizeof(__pyx_k__IndexError), 0, 0, 1, 1}, + {&__pyx_n_s__NULL, __pyx_k__NULL, sizeof(__pyx_k__NULL), 0, 0, 1, 1}, + {&__pyx_n_s__RUSAGE_SELF, __pyx_k__RUSAGE_SELF, sizeof(__pyx_k__RUSAGE_SELF), 0, 0, 1, 1}, + {&__pyx_n_s__StopIteration, __pyx_k__StopIteration, sizeof(__pyx_k__StopIteration), 0, 0, 1, 1}, + {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1}, + {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, + {&__pyx_n_s____enter__, __pyx_k____enter__, sizeof(__pyx_k____enter__), 0, 0, 1, 1}, + {&__pyx_n_s____exit__, __pyx_k____exit__, sizeof(__pyx_k____exit__), 0, 0, 1, 1}, + {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, + {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, + {&__pyx_n_s___cdec_sa, __pyx_k___cdec_sa, sizeof(__pyx_k___cdec_sa), 0, 0, 1, 1}, + {&__pyx_n_s___columns, __pyx_k___columns, sizeof(__pyx_k___columns), 0, 0, 1, 1}, + {&__pyx_n_s___doquicksort, __pyx_k___doquicksort, sizeof(__pyx_k___doquicksort), 0, 0, 1, 1}, + {&__pyx_n_s__advance, __pyx_k__advance, sizeof(__pyx_k__advance), 0, 0, 1, 1}, + {&__pyx_n_s__alignment, __pyx_k__alignment, sizeof(__pyx_k__alignment), 0, 0, 1, 1}, + {&__pyx_n_s__alphabet_size, __pyx_k__alphabet_size, sizeof(__pyx_k__alphabet_size), 0, 0, 1, 1}, + {&__pyx_n_s__arity, __pyx_k__arity, sizeof(__pyx_k__arity), 0, 0, 1, 1}, + {&__pyx_n_s__arr, __pyx_k__arr, sizeof(__pyx_k__arr), 0, 0, 1, 1}, + {&__pyx_n_s__arr_high, __pyx_k__arr_high, sizeof(__pyx_k__arr_high), 0, 0, 1, 1}, + {&__pyx_n_s__arr_low, __pyx_k__arr_low, sizeof(__pyx_k__arr_low), 0, 0, 1, 1}, + {&__pyx_n_s__by_slack_factor, __pyx_k__by_slack_factor, sizeof(__pyx_k__by_slack_factor), 0, 0, 1, 1}, + {&__pyx_n_s__category, __pyx_k__category, sizeof(__pyx_k__category), 0, 0, 1, 1}, + {&__pyx_n_s__children, __pyx_k__children, sizeof(__pyx_k__children), 0, 0, 1, 1}, + {&__pyx_n_s__cmp, __pyx_k__cmp, sizeof(__pyx_k__cmp), 0, 0, 1, 1}, + {&__pyx_n_s__col, __pyx_k__col, sizeof(__pyx_k__col), 0, 0, 1, 1}, + {&__pyx_n_s__collect, __pyx_k__collect, sizeof(__pyx_k__collect), 0, 0, 1, 1}, + {&__pyx_n_s__curr_idx, __pyx_k__curr_idx, sizeof(__pyx_k__curr_idx), 0, 0, 1, 1}, + {&__pyx_n_s__debug, __pyx_k__debug, sizeof(__pyx_k__debug), 0, 0, 1, 1}, + {&__pyx_n_s__dist, __pyx_k__dist, sizeof(__pyx_k__dist), 0, 0, 1, 1}, + {&__pyx_n_s__e, __pyx_k__e, sizeof(__pyx_k__e), 0, 0, 1, 1}, + {&__pyx_n_s__earray, __pyx_k__earray, sizeof(__pyx_k__earray), 0, 0, 1, 1}, + {&__pyx_n_s__edarray, __pyx_k__edarray, sizeof(__pyx_k__edarray), 0, 0, 1, 1}, + {&__pyx_n_s__end, __pyx_k__end, sizeof(__pyx_k__end), 0, 0, 1, 1}, + {&__pyx_n_s__enumerate, __pyx_k__enumerate, sizeof(__pyx_k__enumerate), 0, 0, 1, 1}, + {&__pyx_n_s__eword, __pyx_k__eword, sizeof(__pyx_k__eword), 0, 0, 1, 1}, + {&__pyx_n_s__extend, __pyx_k__extend, sizeof(__pyx_k__extend), 0, 0, 1, 1}, + {&__pyx_n_s__extended, __pyx_k__extended, sizeof(__pyx_k__extended), 0, 0, 1, 1}, + {&__pyx_n_s__f, __pyx_k__f, sizeof(__pyx_k__f), 0, 0, 1, 1}, + {&__pyx_n_s__filename, __pyx_k__filename, sizeof(__pyx_k__filename), 0, 0, 1, 1}, + {&__pyx_n_s__from_binary, __pyx_k__from_binary, sizeof(__pyx_k__from_binary), 0, 0, 1, 1}, + {&__pyx_n_s__from_data, __pyx_k__from_data, sizeof(__pyx_k__from_data), 0, 0, 1, 1}, + {&__pyx_n_s__from_stats, __pyx_k__from_stats, sizeof(__pyx_k__from_stats), 0, 0, 1, 1}, + {&__pyx_n_s__from_text, __pyx_k__from_text, sizeof(__pyx_k__from_text), 0, 0, 1, 1}, + {&__pyx_n_s__frontier, __pyx_k__frontier, sizeof(__pyx_k__frontier), 0, 0, 1, 1}, + {&__pyx_n_s__fsarray, __pyx_k__fsarray, sizeof(__pyx_k__fsarray), 0, 0, 1, 1}, + {&__pyx_n_s__fword, __pyx_k__fword, sizeof(__pyx_k__fword), 0, 0, 1, 1}, + {&__pyx_n_s__fwords, __pyx_k__fwords, sizeof(__pyx_k__fwords), 0, 0, 1, 1}, + {&__pyx_n_s__gc, __pyx_k__gc, sizeof(__pyx_k__gc), 0, 0, 1, 1}, + {&__pyx_n_s__getLogger, __pyx_k__getLogger, sizeof(__pyx_k__getLogger), 0, 0, 1, 1}, + {&__pyx_n_s__getSent, __pyx_k__getSent, sizeof(__pyx_k__getSent), 0, 0, 1, 1}, + {&__pyx_n_s__getSentId, __pyx_k__getSentId, sizeof(__pyx_k__getSentId), 0, 0, 1, 1}, + {&__pyx_n_s__getSentPos, __pyx_k__getSentPos, sizeof(__pyx_k__getSentPos), 0, 0, 1, 1}, + {&__pyx_n_s__get_e_id, __pyx_k__get_e_id, sizeof(__pyx_k__get_e_id), 0, 0, 1, 1}, + {&__pyx_n_s__get_f_id, __pyx_k__get_f_id, sizeof(__pyx_k__get_f_id), 0, 0, 1, 1}, + {&__pyx_n_s__get_id, __pyx_k__get_id, sizeof(__pyx_k__get_id), 0, 0, 1, 1}, + {&__pyx_n_s__get_next_states, __pyx_k__get_next_states, sizeof(__pyx_k__get_next_states), 0, 0, 1, 1}, + {&__pyx_n_s__get_word, __pyx_k__get_word, sizeof(__pyx_k__get_word), 0, 0, 1, 1}, + {&__pyx_n_s__getchunk, __pyx_k__getchunk, sizeof(__pyx_k__getchunk), 0, 0, 1, 1}, + {&__pyx_n_s__getrusage, __pyx_k__getrusage, sizeof(__pyx_k__getrusage), 0, 0, 1, 1}, + {&__pyx_n_s__gzip, __pyx_k__gzip, sizeof(__pyx_k__gzip), 0, 0, 1, 1}, + {&__pyx_n_s__gzip_or_text, __pyx_k__gzip_or_text, sizeof(__pyx_k__gzip_or_text), 0, 0, 1, 1}, + {&__pyx_n_s__h, __pyx_k__h, sizeof(__pyx_k__h), 0, 0, 1, 1}, + {&__pyx_n_s__high, __pyx_k__high, sizeof(__pyx_k__high), 0, 0, 1, 1}, + {&__pyx_n_s__i, __pyx_k__i, sizeof(__pyx_k__i), 0, 0, 1, 1}, + {&__pyx_n_s__ifrom, __pyx_k__ifrom, sizeof(__pyx_k__ifrom), 0, 0, 1, 1}, + {&__pyx_n_s__increment, __pyx_k__increment, sizeof(__pyx_k__increment), 0, 0, 1, 1}, + {&__pyx_n_s__index, __pyx_k__index, sizeof(__pyx_k__index), 0, 0, 1, 1}, + {&__pyx_n_s__info, __pyx_k__info, sizeof(__pyx_k__info), 0, 0, 1, 1}, + {&__pyx_n_s__initial_len, __pyx_k__initial_len, sizeof(__pyx_k__initial_len), 0, 0, 1, 1}, + {&__pyx_n_s__insert, __pyx_k__insert, sizeof(__pyx_k__insert), 0, 0, 1, 1}, + {&__pyx_n_s__isa, __pyx_k__isa, sizeof(__pyx_k__isa), 0, 0, 1, 1}, + {&__pyx_n_s__iteritems, __pyx_k__iteritems, sizeof(__pyx_k__iteritems), 0, 0, 1, 1}, + {&__pyx_n_s__ito, __pyx_k__ito, sizeof(__pyx_k__ito), 0, 0, 1, 1}, + {&__pyx_n_s__j, __pyx_k__j, sizeof(__pyx_k__j), 0, 0, 1, 1}, + {&__pyx_n_s__join, __pyx_k__join, sizeof(__pyx_k__join), 0, 0, 1, 1}, + {&__pyx_n_s__lhs, __pyx_k__lhs, sizeof(__pyx_k__lhs), 0, 0, 1, 1}, + {&__pyx_n_s__logger, __pyx_k__logger, sizeof(__pyx_k__logger), 0, 0, 1, 1}, + {&__pyx_n_s__logging, __pyx_k__logging, sizeof(__pyx_k__logging), 0, 0, 1, 1}, + {&__pyx_n_s__lookup, __pyx_k__lookup, sizeof(__pyx_k__lookup), 0, 0, 1, 1}, + {&__pyx_n_s__low, __pyx_k__low, sizeof(__pyx_k__low), 0, 0, 1, 1}, + {&__pyx_n_s__map, __pyx_k__map, sizeof(__pyx_k__map), 0, 0, 1, 1}, + {&__pyx_n_s__max_chunks, __pyx_k__max_chunks, sizeof(__pyx_k__max_chunks), 0, 0, 1, 1}, + {&__pyx_n_s__max_initial_size, __pyx_k__max_initial_size, sizeof(__pyx_k__max_initial_size), 0, 0, 1, 1}, + {&__pyx_n_s__max_length, __pyx_k__max_length, sizeof(__pyx_k__max_length), 0, 0, 1, 1}, + {&__pyx_n_s__max_nonterminals, __pyx_k__max_nonterminals, sizeof(__pyx_k__max_nonterminals), 0, 0, 1, 1}, + {&__pyx_n_s__max_target_chunks, __pyx_k__max_target_chunks, sizeof(__pyx_k__max_target_chunks), 0, 0, 1, 1}, + {&__pyx_n_s__max_target_length, __pyx_k__max_target_length, sizeof(__pyx_k__max_target_length), 0, 0, 1, 1}, + {&__pyx_n_s__merge, __pyx_k__merge, sizeof(__pyx_k__merge), 0, 0, 1, 1}, + {&__pyx_n_s__min_dist, __pyx_k__min_dist, sizeof(__pyx_k__min_dist), 0, 0, 1, 1}, + {&__pyx_n_s__min_gap_size, __pyx_k__min_gap_size, sizeof(__pyx_k__min_gap_size), 0, 0, 1, 1}, + {&__pyx_n_s__models, __pyx_k__models, sizeof(__pyx_k__models), 0, 0, 1, 1}, + {&__pyx_n_s__next_states, __pyx_k__next_states, sizeof(__pyx_k__next_states), 0, 0, 1, 1}, + {&__pyx_n_s__num_subpatterns, __pyx_k__num_subpatterns, sizeof(__pyx_k__num_subpatterns), 0, 0, 1, 1}, + {&__pyx_n_s__offset, __pyx_k__offset, sizeof(__pyx_k__offset), 0, 0, 1, 1}, + {&__pyx_n_s__open, __pyx_k__open, sizeof(__pyx_k__open), 0, 0, 1, 1}, + {&__pyx_n_s__pad, __pyx_k__pad, sizeof(__pyx_k__pad), 0, 0, 1, 1}, + {&__pyx_n_s__partition, __pyx_k__partition, sizeof(__pyx_k__partition), 0, 0, 1, 1}, + {&__pyx_n_s__pathlen, __pyx_k__pathlen, sizeof(__pyx_k__pathlen), 0, 0, 1, 1}, + {&__pyx_n_s__pattern2phrase, __pyx_k__pattern2phrase, sizeof(__pyx_k__pattern2phrase), 0, 0, 1, 1}, + {&__pyx_n_s__pattern2phrase_plus, __pyx_k__pattern2phrase_plus, sizeof(__pyx_k__pattern2phrase_plus), 0, 0, 1, 1}, + {&__pyx_n_s__phrase, __pyx_k__phrase, sizeof(__pyx_k__phrase), 0, 0, 1, 1}, + {&__pyx_n_s__phrase_location, __pyx_k__phrase_location, sizeof(__pyx_k__phrase_location), 0, 0, 1, 1}, + {&__pyx_n_s__precompute, __pyx_k__precompute, sizeof(__pyx_k__precompute), 0, 0, 1, 1}, + {&__pyx_n_s__precompute_file, __pyx_k__precompute_file, sizeof(__pyx_k__precompute_file), 0, 0, 1, 1}, + {&__pyx_n_s__precompute_rank, __pyx_k__precompute_rank, sizeof(__pyx_k__precompute_rank), 0, 0, 1, 1}, + {&__pyx_n_s__precomputed, __pyx_k__precomputed, sizeof(__pyx_k__precomputed), 0, 0, 1, 1}, + {&__pyx_n_s__q3sort, __pyx_k__q3sort, sizeof(__pyx_k__q3sort), 0, 0, 1, 1}, + {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1}, + {&__pyx_n_s__reachable, __pyx_k__reachable, sizeof(__pyx_k__reachable), 0, 0, 1, 1}, + {&__pyx_n_s__reachable_buffer, __pyx_k__reachable_buffer, sizeof(__pyx_k__reachable_buffer), 0, 0, 1, 1}, + {&__pyx_n_s__read_binary, __pyx_k__read_binary, sizeof(__pyx_k__read_binary), 0, 0, 1, 1}, + {&__pyx_n_s__read_text, __pyx_k__read_text, sizeof(__pyx_k__read_text), 0, 0, 1, 1}, + {&__pyx_n_s__res, __pyx_k__res, sizeof(__pyx_k__res), 0, 0, 1, 1}, + {&__pyx_n_s__reset, __pyx_k__reset, sizeof(__pyx_k__reset), 0, 0, 1, 1}, + {&__pyx_n_s__resource, __pyx_k__resource, sizeof(__pyx_k__resource), 0, 0, 1, 1}, + {&__pyx_n_s__ru_stime, __pyx_k__ru_stime, sizeof(__pyx_k__ru_stime), 0, 0, 1, 1}, + {&__pyx_n_s__ru_utime, __pyx_k__ru_utime, sizeof(__pyx_k__ru_utime), 0, 0, 1, 1}, + {&__pyx_n_s__sa, __pyx_k__sa, sizeof(__pyx_k__sa), 0, 0, 1, 1}, + {&__pyx_n_s__sa_high, __pyx_k__sa_high, sizeof(__pyx_k__sa_high), 0, 0, 1, 1}, + {&__pyx_n_s__sa_low, __pyx_k__sa_low, sizeof(__pyx_k__sa_low), 0, 0, 1, 1}, + {&__pyx_n_s__sample, __pyx_k__sample, sizeof(__pyx_k__sample), 0, 0, 1, 1}, + {&__pyx_n_s__sample_size, __pyx_k__sample_size, sizeof(__pyx_k__sample_size), 0, 0, 1, 1}, + {&__pyx_n_s__sampler, __pyx_k__sampler, sizeof(__pyx_k__sampler), 0, 0, 1, 1}, + {&__pyx_n_s__sarray, __pyx_k__sarray, sizeof(__pyx_k__sarray), 0, 0, 1, 1}, + {&__pyx_n_s__scores, __pyx_k__scores, sizeof(__pyx_k__scores), 0, 0, 1, 1}, + {&__pyx_n_s__seek, __pyx_k__seek, sizeof(__pyx_k__seek), 0, 0, 1, 1}, + {&__pyx_n_s__setdefault, __pyx_k__setdefault, sizeof(__pyx_k__setdefault), 0, 0, 1, 1}, + {&__pyx_n_s__shortest, __pyx_k__shortest, sizeof(__pyx_k__shortest), 0, 0, 1, 1}, + {&__pyx_n_s__size, __pyx_k__size, sizeof(__pyx_k__size), 0, 0, 1, 1}, + {&__pyx_n_s__skip, __pyx_k__skip, sizeof(__pyx_k__skip), 0, 0, 1, 1}, + {&__pyx_n_s__sorted, __pyx_k__sorted, sizeof(__pyx_k__sorted), 0, 0, 1, 1}, + {&__pyx_n_s__spanlen, __pyx_k__spanlen, sizeof(__pyx_k__spanlen), 0, 0, 1, 1}, + {&__pyx_n_s__split, __pyx_k__split, sizeof(__pyx_k__split), 0, 0, 1, 1}, + {&__pyx_n_s__start, __pyx_k__start, sizeof(__pyx_k__start), 0, 0, 1, 1}, + {&__pyx_n_s__stats, __pyx_k__stats, sizeof(__pyx_k__stats), 0, 0, 1, 1}, + {&__pyx_n_s__stop, __pyx_k__stop, sizeof(__pyx_k__stop), 0, 0, 1, 1}, + {&__pyx_n_s__string, __pyx_k__string, sizeof(__pyx_k__string), 0, 0, 1, 1}, + {&__pyx_n_s__suffix_link, __pyx_k__suffix_link, sizeof(__pyx_k__suffix_link), 0, 0, 1, 1}, + {&__pyx_n_s__sym, __pyx_k__sym, sizeof(__pyx_k__sym), 0, 0, 1, 1}, + {&__pyx_n_s__sym_fromstring, __pyx_k__sym_fromstring, sizeof(__pyx_k__sym_fromstring), 0, 0, 1, 1}, + {&__pyx_n_s__sym_isvar, __pyx_k__sym_isvar, sizeof(__pyx_k__sym_isvar), 0, 0, 1, 1}, + {&__pyx_n_s__sym_tostring, __pyx_k__sym_tostring, sizeof(__pyx_k__sym_tostring), 0, 0, 1, 1}, + {&__pyx_n_s__terminal, __pyx_k__terminal, sizeof(__pyx_k__terminal), 0, 0, 1, 1}, + {&__pyx_n_s__tight_phrases, __pyx_k__tight_phrases, sizeof(__pyx_k__tight_phrases), 0, 0, 1, 1}, + {&__pyx_n_s__toMap, __pyx_k__toMap, sizeof(__pyx_k__toMap), 0, 0, 1, 1}, + {&__pyx_n_s__train_min_gap_size, __pyx_k__train_min_gap_size, sizeof(__pyx_k__train_min_gap_size), 0, 0, 1, 1}, + {&__pyx_n_s__unlink, __pyx_k__unlink, sizeof(__pyx_k__unlink), 0, 0, 1, 1}, + {&__pyx_n_s__use_baeza_yates, __pyx_k__use_baeza_yates, sizeof(__pyx_k__use_baeza_yates), 0, 0, 1, 1}, + {&__pyx_n_s__use_collocations, __pyx_k__use_collocations, sizeof(__pyx_k__use_collocations), 0, 0, 1, 1}, + {&__pyx_n_s__use_index, __pyx_k__use_index, sizeof(__pyx_k__use_index), 0, 0, 1, 1}, + {&__pyx_n_s__use_sent_id, __pyx_k__use_sent_id, sizeof(__pyx_k__use_sent_id), 0, 0, 1, 1}, + {&__pyx_n_s__w, __pyx_k__w, sizeof(__pyx_k__w), 0, 0, 1, 1}, + {&__pyx_n_s__warn, __pyx_k__warn, sizeof(__pyx_k__warn), 0, 0, 1, 1}, + {&__pyx_n_s__word, __pyx_k__word, sizeof(__pyx_k__word), 0, 0, 1, 1}, + {&__pyx_n_s__word_alignments, __pyx_k__word_alignments, sizeof(__pyx_k__word_alignments), 0, 0, 1, 1}, + {&__pyx_n_s__words, __pyx_k__words, sizeof(__pyx_k__words), 0, 0, 1, 1}, + {&__pyx_n_s__write, __pyx_k__write, sizeof(__pyx_k__write), 0, 0, 1, 1}, + {&__pyx_n_s__write_text, __pyx_k__write_text, sizeof(__pyx_k__write_text), 0, 0, 1, 1}, + {&__pyx_n_s__zip, __pyx_k__zip, sizeof(__pyx_k__zip), 0, 0, 1, 1}, + {0, 0, 0, 0, 0, 0, 0} +}; +static int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_open = __Pyx_GetName(__pyx_b, __pyx_n_s__open); if (!__pyx_builtin_open) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __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[2]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_map = __Pyx_GetName(__pyx_b, __pyx_n_s__map); if (!__pyx_builtin_map) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __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[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_zip = __Pyx_GetName(__pyx_b, __pyx_n_s__zip); if (!__pyx_builtin_zip) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_StopIteration = __Pyx_GetName(__pyx_b, __pyx_n_s__StopIteration); if (!__pyx_builtin_StopIteration) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_cmp = __Pyx_GetName(__pyx_b, __pyx_n_s__cmp); if (!__pyx_builtin_cmp) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_sorted = __Pyx_GetName(__pyx_b, __pyx_n_s__sorted); if (!__pyx_builtin_sorted) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 917; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + return 0; + __pyx_L1_error:; + return -1; +} + +static int __Pyx_InitCachedConstants(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":20 + * self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} + * self.id2word = ["END_OF_FILE", "END_OF_LINE"] + * self.data = IntList(1000,1000) # <<<<<<<<<<<<<< + * self.sent_id = IntList(1000,1000) + * self.sent_index = IntList(1000,1000) + */ + __pyx_k_tuple_10 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_10); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_10, 0, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_10, 1, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_10)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":21 + * self.id2word = ["END_OF_FILE", "END_OF_LINE"] + * self.data = IntList(1000,1000) + * self.sent_id = IntList(1000,1000) # <<<<<<<<<<<<<< + * self.sent_index = IntList(1000,1000) + * self.use_sent_id = use_sent_id + */ + __pyx_k_tuple_11 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_11); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_11, 0, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_11, 1, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_11)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":22 + * self.data = IntList(1000,1000) + * self.sent_id = IntList(1000,1000) + * self.sent_index = IntList(1000,1000) # <<<<<<<<<<<<<< + * self.use_sent_id = use_sent_id + * if from_binary: + */ + __pyx_k_tuple_12 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_12); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_12, 0, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_12, 1, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":62 + * f.write("%s " % self.get_word(w_id)) + * if w_id == 1: + * f.write("\n") # <<<<<<<<<<<<<< + * + * def read_text(self, char* filename): + */ + __pyx_k_tuple_15 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_15)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_15); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_15, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_15)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":57 + * + * def write_text(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * for w_id in self.data: + * if w_id > 1: + */ + __pyx_k_tuple_16 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_16)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_16); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_16, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_16, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_16, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_16)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":66 + * def read_text(self, char* filename): + * cdef int word_count = 0 + * with gzip_or_text(filename) as fp: # <<<<<<<<<<<<<< + * for line_num, line in enumerate(fp): + * self.sent_index.append(word_count) + */ + __pyx_k_tuple_17 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_17)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_17); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_17, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_17, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_17, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_17)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":133 + * for i in self.data: + * f.write("%d " %i) + * f.write("\n") # <<<<<<<<<<<<<< + * for i in self.sent_index: + * f.write("%d " %i) + */ + __pyx_k_tuple_19 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_19)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_19); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_19, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_19)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":136 + * for i in self.sent_index: + * f.write("%d " %i) + * f.write("\n") # <<<<<<<<<<<<<< + * for i in self.sent_id: + * f.write("%d " %i) + */ + __pyx_k_tuple_20 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_20); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_20, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":139 + * for i in self.sent_id: + * f.write("%d " %i) + * f.write("\n") # <<<<<<<<<<<<<< + * for word in self.id2word: + * f.write("%s %d " % (word, self.word2id[word])) + */ + __pyx_k_tuple_21 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_21)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_21); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_21, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":142 + * for word in self.id2word: + * f.write("%s %d " % (word, self.word2id[word])) + * f.write("\n") # <<<<<<<<<<<<<< + * + * def write_enhanced(self, char* filename): + */ + __pyx_k_tuple_23 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_23)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_23); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_23, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_23)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":145 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * self.write_enhanced_handle(self, f) + */ + __pyx_k_tuple_25 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_25); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_25, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_25, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_25, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_25)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":46 + * + * def __cinit__(self, from_binary=None, from_text=None): + * self.links = IntList(1000,1000) # <<<<<<<<<<<<<< + * self.sent_index = IntList(1000,1000) + * if from_binary: + */ + __pyx_k_tuple_26 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_26)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_26); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_26, 0, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_26, 1, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_26)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":47 + * def __cinit__(self, from_binary=None, from_text=None): + * self.links = IntList(1000,1000) + * self.sent_index = IntList(1000,1000) # <<<<<<<<<<<<<< + * if from_binary: + * self.read_binary(from_binary) + */ + __pyx_k_tuple_27 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_27)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_27); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_27, 0, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_27, 1, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_27)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":59 + * pairs = line.split() + * for pair in pairs: + * (i, j) = map(int, pair.split('-')) # <<<<<<<<<<<<<< + * self.links.append(self.link(i, j)) + * self.sent_index.append(len(self.links)) + */ + __pyx_k_tuple_29 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_29)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_29); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_28)); + PyTuple_SET_ITEM(__pyx_k_tuple_29, 0, ((PyObject *)__pyx_kp_s_28)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_28)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_29)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":54 + * + * def read_text(self, char* filename): + * with gzip_or_text(filename) as f: # <<<<<<<<<<<<<< + * for line in f: + * self.sent_index.append(len(self.links)) + */ + __pyx_k_tuple_30 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_30)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_30); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_30, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_30, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_30, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_30)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":75 + * for i, link in enumerate(self.links): + * while i >= self.sent_index[sent_num]: + * f.write("\n") # <<<<<<<<<<<<<< + * sent_num = sent_num + 1 + * f.write("%d-%d " % self.unlink(link)) + */ + __pyx_k_tuple_31 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_31)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_31); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_31, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_31)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":78 + * sent_num = sent_num + 1 + * f.write("%d-%d " % self.unlink(link)) + * f.write("\n") # <<<<<<<<<<<<<< + * + * def write_binary(self, char* filename): + */ + __pyx_k_tuple_33 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_33)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_33); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_33, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_33)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":71 + * + * def write_text(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * sent_num = 0 + * for i, link in enumerate(self.links): + */ + __pyx_k_tuple_34 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_34)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_34); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_34, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_34, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_34, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_34)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":92 + * for link in self.links: + * f.write("%d " % link) + * f.write("\n") # <<<<<<<<<<<<<< + * for i in self.sent_index: + * f.write("%d " % i) + */ + __pyx_k_tuple_35 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_35)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_35); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_35, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_35)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":95 + * for i in self.sent_index: + * f.write("%d " % i) + * f.write("\n") # <<<<<<<<<<<<<< + * + * def alignment(self, i): + */ + __pyx_k_tuple_36 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_36)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_36); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_36, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_36)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":88 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * sent_num = 1 + * for link in self.links: + */ + __pyx_k_tuple_37 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_37)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_37); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_37, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_37, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_37, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_37)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":302 + * + * # Re-read file, placing words into buckets + * f.seek(0) # <<<<<<<<<<<<<< + * for line in f: + * (fword, eword, score1, score2) = line.split() + */ + __pyx_k_tuple_40 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_40)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_40); + __Pyx_INCREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_k_tuple_40, 0, __pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_40)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":278 + * + * fcount = IntList() + * with gzip_or_text(filename) as f: # <<<<<<<<<<<<<< + * # first loop merely establishes size of array objects + * for line in f: + */ + __pyx_k_tuple_41 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_41)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_41); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_41, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_41, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_41, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_41)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":344 + * + * if i > j: + * raise Exception("Sort error in CLex") # <<<<<<<<<<<<<< + * if i == j: #empty interval + * return + */ + __pyx_k_tuple_44 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_44)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_44); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_43)); + PyTuple_SET_ITEM(__pyx_k_tuple_44, 0, ((PyObject *)__pyx_kp_s_43)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_43)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_44)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":367 + * for i in self.f_index: + * f.write("%d " % i) + * f.write("\n") # <<<<<<<<<<<<<< + * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): + * f.write("%d %f %f " % (i, s1, s2)) + */ + __pyx_k_tuple_46 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_46)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_46); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_46, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_46)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":370 + * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): + * f.write("%d %f %f " % (i, s1, s2)) + * f.write("\n") # <<<<<<<<<<<<<< + * for i, w in enumerate(self.id2fword): + * f.write("%d %s " % (i, w)) + */ + __pyx_k_tuple_48 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_48)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_48); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_48, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_48)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":373 + * for i, w in enumerate(self.id2fword): + * f.write("%d %s " % (i, w)) + * f.write("\n") # <<<<<<<<<<<<<< + * for i, w in enumerate(self.id2eword): + * f.write("%d %s " % (i, w)) + */ + __pyx_k_tuple_50 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_50)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_50); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_50, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_50)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":376 + * for i, w in enumerate(self.id2eword): + * f.write("%d %s " % (i, w)) + * f.write("\n") # <<<<<<<<<<<<<< + * + * + */ + __pyx_k_tuple_51 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_51)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_51); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_51, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_51)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":364 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * for i in self.f_index: + * f.write("%d " % i) + */ + __pyx_k_tuple_52 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_52); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_52, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_52, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_52, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_52)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":409 + * cdef i, N, e_id, f_id + * + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * N = len(self.e_index) + * f_id = 0 + */ + __pyx_k_tuple_54 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_54)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_54); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_54, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_54, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_54, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_54)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":13 + * cdef IntList rank + * + * logger.info("Constructing LCP array") # <<<<<<<<<<<<<< + * self.sa = sa + * n = self.sa.sa.len + */ + __pyx_k_tuple_58 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_58)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_58); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_57)); + PyTuple_SET_ITEM(__pyx_k_tuple_58, 0, ((PyObject *)__pyx_kp_s_57)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_57)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_58)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":34 + * if h > 0: + * h = h-1 + * logger.info("LCP array completed") # <<<<<<<<<<<<<< + * + * def compute_stats(self, int max_n): + */ + __pyx_k_tuple_60 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_60)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_60); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_59)); + PyTuple_SET_ITEM(__pyx_k_tuple_60, 0, ((PyObject *)__pyx_kp_s_59)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_59)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_60)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":297 + * pattern_rank = {} + * + * logger.info("Precomputing frequent intersections") # <<<<<<<<<<<<<< + * cdef float start_time = monitor_cpu() + * + */ + __pyx_k_tuple_71 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_71)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_71); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_70)); + PyTuple_SET_ITEM(__pyx_k_tuple_71, 0, ((PyObject *)__pyx_kp_s_70)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_70)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_71)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":314 + * queue = IntList(increment=1000) + * + * logger.info(" Computing inverted indexes...") # <<<<<<<<<<<<<< + * N = len(data) + * for i from 0 <= i < N: + */ + __pyx_k_tuple_73 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_73)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_73); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_72)); + PyTuple_SET_ITEM(__pyx_k_tuple_73, 0, ((PyObject *)__pyx_kp_s_72)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_72)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_73)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":329 + * trie_node_data_append(node, i) + * + * logger.info(" Computing collocations...") # <<<<<<<<<<<<<< + * N = len(queue) + * ptr1 = 0 + */ + __pyx_k_tuple_75 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_75)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_75); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_74)); + PyTuple_SET_ITEM(__pyx_k_tuple_75, 0, ((PyObject *)__pyx_kp_s_74)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_74)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_75)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":393 + * for pattern2 in J_set: + * if len(pattern1) + len(pattern2) + 1 < self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 # <<<<<<<<<<<<<< + * J2_set.add(combined_pattern) + * + */ + __pyx_k_tuple_77 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_77)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_77); + __Pyx_INCREF(__pyx_int_neg_1); + PyTuple_SET_ITEM(__pyx_k_tuple_77, 0, __pyx_int_neg_1); + __Pyx_GIVEREF(__pyx_int_neg_1); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_77)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":400 + * x = x+1 + * if len(pattern1) + len(pattern2) + 1 <= self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 # <<<<<<<<<<<<<< + * IJ_set.add(combined_pattern) + * + */ + __pyx_k_tuple_78 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_78)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_78); + __Pyx_INCREF(__pyx_int_neg_1); + PyTuple_SET_ITEM(__pyx_k_tuple_78, 0, __pyx_int_neg_1); + __Pyx_GIVEREF(__pyx_int_neg_1); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_78)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":407 + * x = x+2 + * if len(pattern1) + len(pattern2) + 1<= self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 # <<<<<<<<<<<<<< + * IJ_set.add(combined_pattern) + * combined_pattern = pattern2 + (-1,) + pattern1 + */ + __pyx_k_tuple_79 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_79)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_79); + __Pyx_INCREF(__pyx_int_neg_1); + PyTuple_SET_ITEM(__pyx_k_tuple_79, 0, __pyx_int_neg_1); + __Pyx_GIVEREF(__pyx_int_neg_1); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_79)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":409 + * combined_pattern = pattern1 + (-1,) + pattern2 + * IJ_set.add(combined_pattern) + * combined_pattern = pattern2 + (-1,) + pattern1 # <<<<<<<<<<<<<< + * IJ_set.add(combined_pattern) + * + */ + __pyx_k_tuple_80 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_80)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_80); + __Pyx_INCREF(__pyx_int_neg_1); + PyTuple_SET_ITEM(__pyx_k_tuple_80, 0, __pyx_int_neg_1); + __Pyx_GIVEREF(__pyx_int_neg_1); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_80)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":103 + * + * '''Step 3: read off suffix array from inverse suffix array''' + * logger.info(" Finalizing sort...") # <<<<<<<<<<<<<< + * for i from 0 <= i < N: + * j = isa.arr[i] + */ + __pyx_k_tuple_91 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_91)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_91); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_90)); + PyTuple_SET_ITEM(__pyx_k_tuple_91, 0, ((PyObject *)__pyx_kp_s_90)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_90)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_91)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":202 + * for a_i in self.sa: + * f.write("%d " % a_i) + * f.write("\n") # <<<<<<<<<<<<<< + * for w_i in self.ha: + * f.write("%d " % w_i) + */ + __pyx_k_tuple_94 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_94)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_94); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_94, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_94)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":205 + * for w_i in self.ha: + * f.write("%d " % w_i) + * f.write("\n") # <<<<<<<<<<<<<< + * + * cdef int __search_high(self, int word_id, int offset, int low, int high): + */ + __pyx_k_tuple_95 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_95)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_95); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_95, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_95)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":198 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * self.darray.write_enhanced_handle(f) + * for a_i in self.sa: + */ + __pyx_k_tuple_96 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_96)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_96); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_96, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_96, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_96, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_96)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":92 + * logger.info("Sampling strategy: uniform, max sample size = %d", sample_size) + * else: + * logger.info("Sampling strategy: no sampling") # <<<<<<<<<<<<<< + * + * def sample(self, PhraseLocation phrase_location): + */ + __pyx_k_tuple_100 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_100)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_100); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_99)); + PyTuple_SET_ITEM(__pyx_k_tuple_100, 0, ((PyObject *)__pyx_kp_s_99)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_99)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_100)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":300 + * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) + * if alignment is None: + * raise Exception("Must specify an alignment object") # <<<<<<<<<<<<<< + * self.alignment = alignment + * + */ + __pyx_k_tuple_105 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_105)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_105); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_104)); + PyTuple_SET_ITEM(__pyx_k_tuple_105, 0, ((PyObject *)__pyx_kp_s_104)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_104)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_105)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1005 + * else: + * #ERROR: We never get here + * raise Exception("Keyword trie error") # <<<<<<<<<<<<<< + * # checking whether lookup_required + * if lookup_required: + */ + __pyx_k_tuple_120 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_120)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_120); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_119)); + PyTuple_SET_ITEM(__pyx_k_tuple_120, 0, ((PyObject *)__pyx_kp_s_119)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_119)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_120)); + + /* "_cdec_sa.pyx":9 + * resource.getrusage(resource.RUSAGE_SELF).ru_stime) + * + * def gzip_or_text(char* filename): # <<<<<<<<<<<<<< + * if filename.endswith('.gz'): + * return gzip.GzipFile(filename) + */ + __pyx_k_tuple_132 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_132)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_132); + __Pyx_INCREF(((PyObject *)__pyx_n_s__filename)); + PyTuple_SET_ITEM(__pyx_k_tuple_132, 0, ((PyObject *)__pyx_n_s__filename)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__filename)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__filename)); + PyTuple_SET_ITEM(__pyx_k_tuple_132, 1, ((PyObject *)__pyx_n_s__filename)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__filename)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_132)); + __pyx_k_codeobj_133 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_132, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_134, __pyx_n_s__gzip_or_text, 9, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_133)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "_cdec_sa.pyx":15 + * return open(filename) + * + * logger = logging.getLogger('cdec.sa') # <<<<<<<<<<<<<< + * + * include "float_list.pxi" + */ + __pyx_k_tuple_136 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_136)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_136); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_135)); + PyTuple_SET_ITEM(__pyx_k_tuple_136, 0, ((PyObject *)__pyx_kp_s_135)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_135)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_136)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":91 + * cdef Alphabet ALPHABET = Alphabet() + * + * def sym_tostring(int sym): # <<<<<<<<<<<<<< + * return ALPHABET.tostring(sym) + * + */ + __pyx_k_tuple_137 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_137)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_137); + __Pyx_INCREF(((PyObject *)__pyx_n_s__sym)); + PyTuple_SET_ITEM(__pyx_k_tuple_137, 0, ((PyObject *)__pyx_n_s__sym)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__sym)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__sym)); + PyTuple_SET_ITEM(__pyx_k_tuple_137, 1, ((PyObject *)__pyx_n_s__sym)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__sym)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_137)); + __pyx_k_codeobj_138 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_137, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_139, __pyx_n_s__sym_tostring, 91, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_138)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":94 + * return ALPHABET.tostring(sym) + * + * def sym_fromstring(bytes string, bint terminal): # <<<<<<<<<<<<<< + * return ALPHABET.fromstring(string, terminal) + * + */ + __pyx_k_tuple_140 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_140)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_140); + __Pyx_INCREF(((PyObject *)__pyx_n_s__string)); + PyTuple_SET_ITEM(__pyx_k_tuple_140, 0, ((PyObject *)__pyx_n_s__string)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__string)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__terminal)); + PyTuple_SET_ITEM(__pyx_k_tuple_140, 1, ((PyObject *)__pyx_n_s__terminal)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__terminal)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_140)); + __pyx_k_codeobj_141 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_139, __pyx_n_s__sym_fromstring, 94, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_141)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":97 + * return ALPHABET.fromstring(string, terminal) + * + * def sym_isvar(int sym): # <<<<<<<<<<<<<< + * return ALPHABET.isvar(sym) + * + */ + __pyx_k_tuple_142 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_142)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_142); + __Pyx_INCREF(((PyObject *)__pyx_n_s__sym)); + PyTuple_SET_ITEM(__pyx_k_tuple_142, 0, ((PyObject *)__pyx_n_s__sym)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__sym)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__sym)); + PyTuple_SET_ITEM(__pyx_k_tuple_142, 1, ((PyObject *)__pyx_n_s__sym)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__sym)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_142)); + __pyx_k_codeobj_143 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_142, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_139, __pyx_n_s__sym_isvar, 97, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_143)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static int __Pyx_InitGlobals(void) { + if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_5 = PyInt_FromLong(5); if (unlikely(!__pyx_int_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_10 = PyInt_FromLong(10); if (unlikely(!__pyx_int_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_20 = PyInt_FromLong(20); if (unlikely(!__pyx_int_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_1000 = PyInt_FromLong(1000); if (unlikely(!__pyx_int_1000)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_65536 = PyInt_FromLong(65536); if (unlikely(!__pyx_int_65536)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + return 0; + __pyx_L1_error:; + return -1; +} + +#if PY_MAJOR_VERSION < 3 +PyMODINIT_FUNC init_cdec_sa(void); /*proto*/ +PyMODINIT_FUNC init_cdec_sa(void) +#else +PyMODINIT_FUNC PyInit__cdec_sa(void); /*proto*/ +PyMODINIT_FUNC PyInit__cdec_sa(void) +#endif +{ + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + __Pyx_RefNannyDeclarations + #if CYTHON_REFNANNY + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); + if (!__Pyx_RefNanny) { + PyErr_Clear(); + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); + if (!__Pyx_RefNanny) + Py_FatalError("failed to import 'refnanny' module"); + } + #endif + __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit__cdec_sa(void)", 0); + if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #ifdef __Pyx_CyFunction_USED + if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif + #ifdef __Pyx_FusedFunction_USED + if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif + #ifdef __Pyx_Generator_USED + if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif + /*--- Library function declarations ---*/ + /*--- Threads initialization code ---*/ + #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS + #ifdef WITH_THREAD /* Python build with threading support? */ + PyEval_InitThreads(); + #endif + #endif + /*--- Module creation code ---*/ + #if PY_MAJOR_VERSION < 3 + __pyx_m = Py_InitModule4(__Pyx_NAMESTR("_cdec_sa"), __pyx_methods, 0, 0, PYTHON_API_VERSION); + #else + __pyx_m = PyModule_Create(&__pyx_moduledef); + #endif + if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #if PY_MAJOR_VERSION < 3 + Py_INCREF(__pyx_m); + #endif + __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); + if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + /*--- Initialize various global constants etc. ---*/ + if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_module_is_main__cdec_sa) { + if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + } + /*--- Builtin init code ---*/ + if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /*--- Constants init code ---*/ + if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /*--- Global init code ---*/ + __pyx_v_8_cdec_sa_ALPHABET = ((struct __pyx_obj_8_cdec_sa_Alphabet *)Py_None); Py_INCREF(Py_None); + /*--- Variable export code ---*/ + /*--- Function export code ---*/ + /*--- Type init code ---*/ + __pyx_vtabptr_8_cdec_sa_FloatList = &__pyx_vtable_8_cdec_sa_FloatList; + __pyx_vtable_8_cdec_sa_FloatList.set = (void (*)(struct __pyx_obj_8_cdec_sa_FloatList *, int, float))__pyx_f_8_cdec_sa_9FloatList_set; + __pyx_vtable_8_cdec_sa_FloatList.write_handle = (void (*)(struct __pyx_obj_8_cdec_sa_FloatList *, FILE *))__pyx_f_8_cdec_sa_9FloatList_write_handle; + __pyx_vtable_8_cdec_sa_FloatList.read_handle = (void (*)(struct __pyx_obj_8_cdec_sa_FloatList *, FILE *))__pyx_f_8_cdec_sa_9FloatList_read_handle; + if (PyType_Ready(&__pyx_type_8_cdec_sa_FloatList) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_FloatList.tp_dict, __pyx_vtabptr_8_cdec_sa_FloatList) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "FloatList", (PyObject *)&__pyx_type_8_cdec_sa_FloatList) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_FloatList = &__pyx_type_8_cdec_sa_FloatList; + __pyx_vtabptr_8_cdec_sa_IntList = &__pyx_vtable_8_cdec_sa_IntList; + __pyx_vtable_8_cdec_sa_IntList.set = (void (*)(struct __pyx_obj_8_cdec_sa_IntList *, int, int))__pyx_f_8_cdec_sa_7IntList_set; + __pyx_vtable_8_cdec_sa_IntList._append = (void (*)(struct __pyx_obj_8_cdec_sa_IntList *, int))__pyx_f_8_cdec_sa_7IntList__append; + __pyx_vtable_8_cdec_sa_IntList._extend = (void (*)(struct __pyx_obj_8_cdec_sa_IntList *, struct __pyx_obj_8_cdec_sa_IntList *))__pyx_f_8_cdec_sa_7IntList__extend; + __pyx_vtable_8_cdec_sa_IntList._extend_arr = (void (*)(struct __pyx_obj_8_cdec_sa_IntList *, int *, int))__pyx_f_8_cdec_sa_7IntList__extend_arr; + __pyx_vtable_8_cdec_sa_IntList._clear = (void (*)(struct __pyx_obj_8_cdec_sa_IntList *))__pyx_f_8_cdec_sa_7IntList__clear; + __pyx_vtable_8_cdec_sa_IntList.write_handle = (void (*)(struct __pyx_obj_8_cdec_sa_IntList *, FILE *))__pyx_f_8_cdec_sa_7IntList_write_handle; + __pyx_vtable_8_cdec_sa_IntList.read_handle = (void (*)(struct __pyx_obj_8_cdec_sa_IntList *, FILE *))__pyx_f_8_cdec_sa_7IntList_read_handle; + if (PyType_Ready(&__pyx_type_8_cdec_sa_IntList) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_IntList.tp_dict, __pyx_vtabptr_8_cdec_sa_IntList) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "IntList", (PyObject *)&__pyx_type_8_cdec_sa_IntList) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_IntList = &__pyx_type_8_cdec_sa_IntList; + __pyx_vtabptr_8_cdec_sa_StringMap = &__pyx_vtable_8_cdec_sa_StringMap; + __pyx_vtable_8_cdec_sa_StringMap.word = (char *(*)(struct __pyx_obj_8_cdec_sa_StringMap *, int))__pyx_f_8_cdec_sa_9StringMap_word; + __pyx_vtable_8_cdec_sa_StringMap.index = (int (*)(struct __pyx_obj_8_cdec_sa_StringMap *, char *))__pyx_f_8_cdec_sa_9StringMap_index; + if (PyType_Ready(&__pyx_type_8_cdec_sa_StringMap) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_StringMap.tp_dict, __pyx_vtabptr_8_cdec_sa_StringMap) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "StringMap", (PyObject *)&__pyx_type_8_cdec_sa_StringMap) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_StringMap = &__pyx_type_8_cdec_sa_StringMap; + __pyx_vtabptr_8_cdec_sa_DataArray = &__pyx_vtable_8_cdec_sa_DataArray; + __pyx_vtable_8_cdec_sa_DataArray.read_handle = (void (*)(struct __pyx_obj_8_cdec_sa_DataArray *, FILE *))__pyx_f_8_cdec_sa_9DataArray_read_handle; + __pyx_vtable_8_cdec_sa_DataArray.write_handle = (void (*)(struct __pyx_obj_8_cdec_sa_DataArray *, FILE *))__pyx_f_8_cdec_sa_9DataArray_write_handle; + if (PyType_Ready(&__pyx_type_8_cdec_sa_DataArray) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_DataArray.tp_dict, __pyx_vtabptr_8_cdec_sa_DataArray) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "DataArray", (PyObject *)&__pyx_type_8_cdec_sa_DataArray) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_DataArray = &__pyx_type_8_cdec_sa_DataArray; + __pyx_vtabptr_8_cdec_sa_Alignment = &__pyx_vtable_8_cdec_sa_Alignment; + __pyx_vtable_8_cdec_sa_Alignment.link = (int (*)(struct __pyx_obj_8_cdec_sa_Alignment *, int, int))__pyx_f_8_cdec_sa_9Alignment_link; + __pyx_vtable_8_cdec_sa_Alignment._unlink = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_Alignment *, int, int *, int *))__pyx_f_8_cdec_sa_9Alignment__unlink; + __pyx_vtable_8_cdec_sa_Alignment._get_sent_links = (int *(*)(struct __pyx_obj_8_cdec_sa_Alignment *, int, int *))__pyx_f_8_cdec_sa_9Alignment__get_sent_links; + if (PyType_Ready(&__pyx_type_8_cdec_sa_Alignment) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_Alignment.tp_dict, __pyx_vtabptr_8_cdec_sa_Alignment) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Alignment", (PyObject *)&__pyx_type_8_cdec_sa_Alignment) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_Alignment = &__pyx_type_8_cdec_sa_Alignment; + __pyx_vtabptr_8_cdec_sa_BiLex = &__pyx_vtable_8_cdec_sa_BiLex; + __pyx_vtable_8_cdec_sa_BiLex.compute_from_data = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_BiLex *, struct __pyx_obj_8_cdec_sa_SuffixArray *, struct __pyx_obj_8_cdec_sa_DataArray *, struct __pyx_obj_8_cdec_sa_Alignment *))__pyx_f_8_cdec_sa_5BiLex_compute_from_data; + __pyx_vtable_8_cdec_sa_BiLex._add_node = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_BiLex *, struct __pyx_t_8_cdec_sa__node *, int *, float, int *))__pyx_f_8_cdec_sa_5BiLex__add_node; + __pyx_vtable_8_cdec_sa_BiLex.write_wordlist = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_BiLex *, PyObject *, FILE *))__pyx_f_8_cdec_sa_5BiLex_write_wordlist; + __pyx_vtable_8_cdec_sa_BiLex.read_wordlist = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_BiLex *, PyObject *, PyObject *, FILE *))__pyx_f_8_cdec_sa_5BiLex_read_wordlist; + __pyx_vtable_8_cdec_sa_BiLex.swap = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_BiLex *, int, int))__pyx_f_8_cdec_sa_5BiLex_swap; + __pyx_vtable_8_cdec_sa_BiLex.qsort = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_BiLex *, int, int, PyObject *))__pyx_f_8_cdec_sa_5BiLex_qsort; + if (PyType_Ready(&__pyx_type_8_cdec_sa_BiLex) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_BiLex.tp_dict, __pyx_vtabptr_8_cdec_sa_BiLex) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "BiLex", (PyObject *)&__pyx_type_8_cdec_sa_BiLex) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_BiLex = &__pyx_type_8_cdec_sa_BiLex; + if (PyType_Ready(&__pyx_type_8_cdec_sa_BitSetIterator) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "BitSetIterator", (PyObject *)&__pyx_type_8_cdec_sa_BitSetIterator) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_BitSetIterator = &__pyx_type_8_cdec_sa_BitSetIterator; + if (PyType_Ready(&__pyx_type_8_cdec_sa_BitSet) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "BitSet", (PyObject *)&__pyx_type_8_cdec_sa_BitSet) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_BitSet = &__pyx_type_8_cdec_sa_BitSet; + if (PyType_Ready(&__pyx_type_8_cdec_sa_VEBIterator) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "VEBIterator", (PyObject *)&__pyx_type_8_cdec_sa_VEBIterator) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_VEBIterator = &__pyx_type_8_cdec_sa_VEBIterator; + __pyx_vtabptr_8_cdec_sa_VEB = &__pyx_vtable_8_cdec_sa_VEB; + __pyx_vtable_8_cdec_sa_VEB._findsucc = (int (*)(struct __pyx_obj_8_cdec_sa_VEB *, int))__pyx_f_8_cdec_sa_3VEB__findsucc; + __pyx_vtable_8_cdec_sa_VEB._insert = (int (*)(struct __pyx_obj_8_cdec_sa_VEB *, int))__pyx_f_8_cdec_sa_3VEB__insert; + __pyx_vtable_8_cdec_sa_VEB._first = (int (*)(struct __pyx_obj_8_cdec_sa_VEB *))__pyx_f_8_cdec_sa_3VEB__first; + if (PyType_Ready(&__pyx_type_8_cdec_sa_VEB) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_VEB.tp_dict, __pyx_vtabptr_8_cdec_sa_VEB) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "VEB", (PyObject *)&__pyx_type_8_cdec_sa_VEB) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_VEB = &__pyx_type_8_cdec_sa_VEB; + if (PyType_Ready(&__pyx_type_8_cdec_sa_LCP) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "LCP", (PyObject *)&__pyx_type_8_cdec_sa_LCP) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_LCP = &__pyx_type_8_cdec_sa_LCP; + __pyx_vtabptr_8_cdec_sa_Alphabet = &__pyx_vtable_8_cdec_sa_Alphabet; + __pyx_vtable_8_cdec_sa_Alphabet.isvar = (int (*)(struct __pyx_obj_8_cdec_sa_Alphabet *, int))__pyx_f_8_cdec_sa_8Alphabet_isvar; + __pyx_vtable_8_cdec_sa_Alphabet.isword = (int (*)(struct __pyx_obj_8_cdec_sa_Alphabet *, int))__pyx_f_8_cdec_sa_8Alphabet_isword; + __pyx_vtable_8_cdec_sa_Alphabet.getindex = (int (*)(struct __pyx_obj_8_cdec_sa_Alphabet *, int))__pyx_f_8_cdec_sa_8Alphabet_getindex; + __pyx_vtable_8_cdec_sa_Alphabet.setindex = (int (*)(struct __pyx_obj_8_cdec_sa_Alphabet *, int, int))__pyx_f_8_cdec_sa_8Alphabet_setindex; + __pyx_vtable_8_cdec_sa_Alphabet.clearindex = (int (*)(struct __pyx_obj_8_cdec_sa_Alphabet *, int))__pyx_f_8_cdec_sa_8Alphabet_clearindex; + __pyx_vtable_8_cdec_sa_Alphabet.match = (int (*)(struct __pyx_obj_8_cdec_sa_Alphabet *, int, int))__pyx_f_8_cdec_sa_8Alphabet_match; + __pyx_vtable_8_cdec_sa_Alphabet.tocat = (char *(*)(struct __pyx_obj_8_cdec_sa_Alphabet *, int))__pyx_f_8_cdec_sa_8Alphabet_tocat; + __pyx_vtable_8_cdec_sa_Alphabet.fromcat = (int (*)(struct __pyx_obj_8_cdec_sa_Alphabet *, char *))__pyx_f_8_cdec_sa_8Alphabet_fromcat; + __pyx_vtable_8_cdec_sa_Alphabet.tostring = (char *(*)(struct __pyx_obj_8_cdec_sa_Alphabet *, int))__pyx_f_8_cdec_sa_8Alphabet_tostring; + __pyx_vtable_8_cdec_sa_Alphabet.fromstring = (int (*)(struct __pyx_obj_8_cdec_sa_Alphabet *, char *, int))__pyx_f_8_cdec_sa_8Alphabet_fromstring; + if (PyType_Ready(&__pyx_type_8_cdec_sa_Alphabet) < 0) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_Alphabet.tp_dict, __pyx_vtabptr_8_cdec_sa_Alphabet) < 0) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Alphabet", (PyObject *)&__pyx_type_8_cdec_sa_Alphabet) < 0) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_Alphabet = &__pyx_type_8_cdec_sa_Alphabet; + __pyx_vtabptr_8_cdec_sa_Phrase = &__pyx_vtable_8_cdec_sa_Phrase; + __pyx_vtable_8_cdec_sa_Phrase.chunkpos = (int (*)(struct __pyx_obj_8_cdec_sa_Phrase *, int))__pyx_f_8_cdec_sa_6Phrase_chunkpos; + __pyx_vtable_8_cdec_sa_Phrase.chunklen = (int (*)(struct __pyx_obj_8_cdec_sa_Phrase *, int))__pyx_f_8_cdec_sa_6Phrase_chunklen; + if (PyType_Ready(&__pyx_type_8_cdec_sa_Phrase) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_Phrase.tp_dict, __pyx_vtabptr_8_cdec_sa_Phrase) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Phrase", (PyObject *)&__pyx_type_8_cdec_sa_Phrase) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_Phrase = &__pyx_type_8_cdec_sa_Phrase; + if (PyType_Ready(&__pyx_type_8_cdec_sa_Rule) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Rule", (PyObject *)&__pyx_type_8_cdec_sa_Rule) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_Rule = &__pyx_type_8_cdec_sa_Rule; + __pyx_vtabptr_8_cdec_sa_TrieMap = &__pyx_vtable_8_cdec_sa_TrieMap; + __pyx_vtable_8_cdec_sa_TrieMap._insert = (struct __pyx_t_8_cdec_sa__Trie_Node *(*)(struct __pyx_obj_8_cdec_sa_TrieMap *, int *, int))__pyx_f_8_cdec_sa_7TrieMap__insert; + __pyx_vtable_8_cdec_sa_TrieMap._contains = (struct __pyx_t_8_cdec_sa__Trie_Node *(*)(struct __pyx_obj_8_cdec_sa_TrieMap *, int *, int))__pyx_f_8_cdec_sa_7TrieMap__contains; + if (PyType_Ready(&__pyx_type_8_cdec_sa_TrieMap) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_TrieMap.tp_dict, __pyx_vtabptr_8_cdec_sa_TrieMap) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "TrieMap", (PyObject *)&__pyx_type_8_cdec_sa_TrieMap) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_TrieMap = &__pyx_type_8_cdec_sa_TrieMap; + __pyx_vtabptr_8_cdec_sa_Precomputation = &__pyx_vtable_8_cdec_sa_Precomputation; + __pyx_vtable_8_cdec_sa_Precomputation.read_map = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_Precomputation *, FILE *))__pyx_f_8_cdec_sa_14Precomputation_read_map; + __pyx_vtable_8_cdec_sa_Precomputation.write_map = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_Precomputation *, PyObject *, FILE *))__pyx_f_8_cdec_sa_14Precomputation_write_map; + if (PyType_Ready(&__pyx_type_8_cdec_sa_Precomputation) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_Precomputation.tp_dict, __pyx_vtabptr_8_cdec_sa_Precomputation) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Precomputation", (PyObject *)&__pyx_type_8_cdec_sa_Precomputation) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_Precomputation = &__pyx_type_8_cdec_sa_Precomputation; + __pyx_vtabptr_8_cdec_sa_SuffixArray = &__pyx_vtable_8_cdec_sa_SuffixArray; + __pyx_vtable_8_cdec_sa_SuffixArray.__pyx___search_high = (int (*)(struct __pyx_obj_8_cdec_sa_SuffixArray *, int, int, int, int))__pyx_f_8_cdec_sa_11SuffixArray___search_high; + __pyx_vtable_8_cdec_sa_SuffixArray.__pyx___search_low = (int (*)(struct __pyx_obj_8_cdec_sa_SuffixArray *, int, int, int, int))__pyx_f_8_cdec_sa_11SuffixArray___search_low; + __pyx_vtable_8_cdec_sa_SuffixArray.__pyx___get_range = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_SuffixArray *, int, int, int, int, int))__pyx_f_8_cdec_sa_11SuffixArray___get_range; + __pyx_vtable_8_cdec_sa_SuffixArray.__pyx___lookup_helper = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_SuffixArray *, int, int, int, int))__pyx_f_8_cdec_sa_11SuffixArray___lookup_helper; + if (PyType_Ready(&__pyx_type_8_cdec_sa_SuffixArray) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_SuffixArray.tp_dict, __pyx_vtabptr_8_cdec_sa_SuffixArray) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "SuffixArray", (PyObject *)&__pyx_type_8_cdec_sa_SuffixArray) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_SuffixArray = &__pyx_type_8_cdec_sa_SuffixArray; + if (PyType_Ready(&__pyx_type_8_cdec_sa_TrieNode) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "TrieNode", (PyObject *)&__pyx_type_8_cdec_sa_TrieNode) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_TrieNode = &__pyx_type_8_cdec_sa_TrieNode; + __pyx_type_8_cdec_sa_ExtendedTrieNode.tp_base = __pyx_ptype_8_cdec_sa_TrieNode; + if (PyType_Ready(&__pyx_type_8_cdec_sa_ExtendedTrieNode) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "ExtendedTrieNode", (PyObject *)&__pyx_type_8_cdec_sa_ExtendedTrieNode) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_ExtendedTrieNode = &__pyx_type_8_cdec_sa_ExtendedTrieNode; + if (PyType_Ready(&__pyx_type_8_cdec_sa_TrieTable) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "TrieTable", (PyObject *)&__pyx_type_8_cdec_sa_TrieTable) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_TrieTable = &__pyx_type_8_cdec_sa_TrieTable; + __pyx_vtabptr_8_cdec_sa_PhraseLocation = &__pyx_vtable_8_cdec_sa_PhraseLocation; + __pyx_vtable_8_cdec_sa_PhraseLocation.contains = (int (*)(struct __pyx_obj_8_cdec_sa_PhraseLocation *, int))__pyx_f_8_cdec_sa_14PhraseLocation_contains; + if (PyType_Ready(&__pyx_type_8_cdec_sa_PhraseLocation) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_PhraseLocation.tp_dict, __pyx_vtabptr_8_cdec_sa_PhraseLocation) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "PhraseLocation", (PyObject *)&__pyx_type_8_cdec_sa_PhraseLocation) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_PhraseLocation = &__pyx_type_8_cdec_sa_PhraseLocation; + if (PyType_Ready(&__pyx_type_8_cdec_sa_Sampler) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Sampler", (PyObject *)&__pyx_type_8_cdec_sa_Sampler) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_Sampler = &__pyx_type_8_cdec_sa_Sampler; + __pyx_vtabptr_8_cdec_sa_HieroCachingRuleFactory = &__pyx_vtable_8_cdec_sa_HieroCachingRuleFactory; + __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.set_idmap = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, struct __pyx_obj_8_cdec_sa_DataArray *))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_set_idmap; + __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.baeza_yates_helper = (int *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, int, int, int *, int, int, int, int *, int, int, int, int, int *))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_baeza_yates_helper; + __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.compare_matchings_set = (long (*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, int, int, int *, int, struct __pyx_t_8_cdec_sa_Matching *, int, int))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_compare_matchings_set; + __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.compare_matchings = (long (*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, struct __pyx_t_8_cdec_sa_Matching *, struct __pyx_t_8_cdec_sa_Matching *, int, int))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_compare_matchings; + __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.merge_helper = (int *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, int, int, int *, int, int, int, int *, int, int, int, int, int *))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_merge_helper; + __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.sort_phrase_loc = (void (*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, struct __pyx_obj_8_cdec_sa_IntList *, struct __pyx_obj_8_cdec_sa_PhraseLocation *, struct __pyx_obj_8_cdec_sa_Phrase *))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_sort_phrase_loc; + __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.intersect_helper = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, struct __pyx_obj_8_cdec_sa_Phrase *, struct __pyx_obj_8_cdec_sa_Phrase *, struct __pyx_obj_8_cdec_sa_PhraseLocation *, struct __pyx_obj_8_cdec_sa_PhraseLocation *, int))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_intersect_helper; + __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.loc2str = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, struct __pyx_obj_8_cdec_sa_PhraseLocation *))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_loc2str; + __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.intersect = (struct __pyx_obj_8_cdec_sa_PhraseLocation *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, PyObject *, PyObject *, struct __pyx_obj_8_cdec_sa_Phrase *))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_intersect; + __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.find_fixpoint = (int (*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, int, PyObject *, int *, int *, int *, int *, int, int, int *, int *, int *, int *, int, int, int, int, int, int, int, int, int, int, int))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_find_fixpoint; + __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.find_projection = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, int, int, int *, int *, int *, int *))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_find_projection; + __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.int_arr_extend = (int *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, int *, int *, int *, int))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_int_arr_extend; + __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.extract_phrases = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, int, int, int *, int *, int *, int, int, int, int *, int *, int *, int, int, int))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_extract_phrases; + __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.create_alignments = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, int *, int, PyObject *, PyObject *))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_create_alignments; + __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.extract = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, struct __pyx_obj_8_cdec_sa_Phrase *, struct __pyx_t_8_cdec_sa_Matching *, int *, int))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_extract; + if (PyType_Ready(&__pyx_type_8_cdec_sa_HieroCachingRuleFactory) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_HieroCachingRuleFactory.tp_dict, __pyx_vtabptr_8_cdec_sa_HieroCachingRuleFactory) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "HieroCachingRuleFactory", (PyObject *)&__pyx_type_8_cdec_sa_HieroCachingRuleFactory) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa_HieroCachingRuleFactory = &__pyx_type_8_cdec_sa_HieroCachingRuleFactory; + if (PyType_Ready(&__pyx_type_8_cdec_sa___pyx_scope_struct__compute_stats) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa___pyx_scope_struct__compute_stats = &__pyx_type_8_cdec_sa___pyx_scope_struct__compute_stats; + if (PyType_Ready(&__pyx_type_8_cdec_sa___pyx_scope_struct_1_input) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_8_cdec_sa___pyx_scope_struct_1_input = &__pyx_type_8_cdec_sa___pyx_scope_struct_1_input; + /*--- Type import code ---*/ + /*--- Variable import code ---*/ + /*--- Function import code ---*/ + /*--- Execution code ---*/ + + /* "_cdec_sa.pyx":1 + * import logging # <<<<<<<<<<<<<< + * import resource + * import gzip + */ + __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__logging), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__logging, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_cdec_sa.pyx":2 + * import logging + * import resource # <<<<<<<<<<<<<< + * import gzip + * + */ + __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__resource), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__resource, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_cdec_sa.pyx":3 + * import logging + * import resource + * import gzip # <<<<<<<<<<<<<< + * + * cdef float monitor_cpu(): + */ + __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__gzip), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__gzip, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_cdec_sa.pyx":9 + * resource.getrusage(resource.RUSAGE_SELF).ru_stime) + * + * def gzip_or_text(char* filename): # <<<<<<<<<<<<<< + * if filename.endswith('.gz'): + * return gzip.GzipFile(filename) + */ + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8_cdec_sa_1gzip_or_text, NULL, __pyx_n_s___cdec_sa); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__gzip_or_text, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_cdec_sa.pyx":15 + * return open(filename) + * + * logger = logging.getLogger('cdec.sa') # <<<<<<<<<<<<<< + * + * include "float_list.pxi" + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logging); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__getLogger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_136), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__logger, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":54 + * cdef id2eword, id2fword, eword2id, fword2id + * + * def __cinit__(self, from_text=None, from_data=False, from_binary=None, # <<<<<<<<<<<<<< + * earray=None, fsarray=None, alignment=None): + * self.id2eword = [] + */ + __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_k_38 = __pyx_t_1; + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":17 + * from libc.string cimport memset + * + * cdef int MIN_BOTTOM_SIZE = 32 # <<<<<<<<<<<<<< + * cdef int MIN_BOTTOM_BITS = 5 + * cdef int LOWER_MASK[32] + */ + __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE = 32; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":18 + * + * cdef int MIN_BOTTOM_SIZE = 32 + * cdef int MIN_BOTTOM_BITS = 5 # <<<<<<<<<<<<<< + * cdef int LOWER_MASK[32] + * + */ + __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS = 5; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":28 + * LOWER_MASK[i] = mask + * + * _init_lower_mask() # <<<<<<<<<<<<<< + * + * cdef struct _BitSet: + */ + __pyx_f_8_cdec_sa__init_lower_mask(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":4 + * from libc.stdlib cimport malloc, realloc, strtol + * + * cdef int INDEX_SHIFT = 3 # <<<<<<<<<<<<<< + * cdef int INDEX_MASK = (1<= 3 + "%s() got multiple values for keyword argument '%U'", func_name, kw_name); + #else + "%s() got multiple values for keyword argument '%s'", func_name, + PyString_AS_STRING(kw_name)); + #endif +} + +static int __Pyx_ParseOptionalKeywords( + PyObject *kwds, + PyObject **argnames[], + PyObject *kwds2, + PyObject *values[], + Py_ssize_t num_pos_args, + const char* function_name) +{ + PyObject *key = 0, *value = 0; + Py_ssize_t pos = 0; + PyObject*** name; + PyObject*** first_kw_arg = argnames + num_pos_args; + while (PyDict_Next(kwds, &pos, &key, &value)) { + name = first_kw_arg; + while (*name && (**name != key)) name++; + if (*name) { + values[name-argnames] = value; + } else { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) { + #else + if (unlikely(!PyUnicode_Check(key))) { + #endif + goto invalid_keyword_type; + } else { + for (name = first_kw_arg; *name; name++) { + #if PY_MAJOR_VERSION >= 3 + if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && + PyUnicode_Compare(**name, key) == 0) break; + #else + if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && + _PyString_Eq(**name, key)) break; + #endif + } + if (*name) { + values[name-argnames] = value; + } else { + for (name=argnames; name != first_kw_arg; name++) { + if (**name == key) goto arg_passed_twice; + #if PY_MAJOR_VERSION >= 3 + if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && + PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice; + #else + if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && + _PyString_Eq(**name, key)) goto arg_passed_twice; + #endif + } + if (kwds2) { + if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; + } else { + goto invalid_keyword; + } + } + } + } + } + return 0; +arg_passed_twice: + __Pyx_RaiseDoubleKeywordsError(function_name, **name); + goto bad; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%s() keywords must be strings", function_name); + goto bad; +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%s() got an unexpected keyword argument '%s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif +bad: + return -1; +} + +static void __Pyx_RaiseArgtupleInvalid( + const char* func_name, + int exact, + Py_ssize_t num_min, + Py_ssize_t num_max, + Py_ssize_t num_found) +{ + Py_ssize_t num_expected; + const char *more_or_less; + if (num_found < num_min) { + num_expected = num_min; + more_or_less = "at least"; + } else { + num_expected = num_max; + more_or_less = "at most"; + } + if (exact) { + more_or_less = "exactly"; + } + PyErr_Format(PyExc_TypeError, + "%s() takes %s %"PY_FORMAT_SIZE_T"d positional argument%s (%"PY_FORMAT_SIZE_T"d given)", + func_name, more_or_less, num_expected, + (num_expected == 1) ? "" : "s", num_found); +} + +static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { +#if CYTHON_COMPILING_IN_CPYTHON + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyThreadState *tstate = PyThreadState_GET(); + tmp_type = tstate->curexc_type; + tmp_value = tstate->curexc_value; + tmp_tb = tstate->curexc_traceback; + tstate->curexc_type = type; + tstate->curexc_value = value; + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#else + PyErr_Restore(type, value, tb); +#endif +} +static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { +#if CYTHON_COMPILING_IN_CPYTHON + PyThreadState *tstate = PyThreadState_GET(); + *type = tstate->curexc_type; + *value = tstate->curexc_value; + *tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +#else + PyErr_Fetch(type, value, tb); +#endif +} + +#if PY_MAJOR_VERSION < 3 +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, + CYTHON_UNUSED PyObject *cause) { + Py_XINCREF(type); + Py_XINCREF(value); + Py_XINCREF(tb); + if (tb == Py_None) { + Py_DECREF(tb); + tb = 0; + } + else if (tb != NULL && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto raise_error; + } + if (value == NULL) { + value = Py_None; + Py_INCREF(value); + } + #if PY_VERSION_HEX < 0x02050000 + if (!PyClass_Check(type)) + #else + if (!PyType_Check(type)) + #endif + { + if (value != Py_None) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto raise_error; + } + Py_DECREF(value); + value = type; + #if PY_VERSION_HEX < 0x02050000 + if (PyInstance_Check(type)) { + type = (PyObject*) ((PyInstanceObject*)type)->in_class; + Py_INCREF(type); + } + else { + type = 0; + PyErr_SetString(PyExc_TypeError, + "raise: exception must be an old-style class or instance"); + goto raise_error; + } + #else + type = (PyObject*) Py_TYPE(type); + Py_INCREF(type); + if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto raise_error; + } + #endif + } + __Pyx_ErrRestore(type, value, tb); + return; +raise_error: + Py_XDECREF(value); + Py_XDECREF(type); + Py_XDECREF(tb); + return; +} +#else /* Python 3+ */ +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + if (tb == Py_None) { + tb = 0; + } else if (tb && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto bad; + } + if (value == Py_None) + value = 0; + if (PyExceptionInstance_Check(type)) { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto bad; + } + value = type; + type = (PyObject*) Py_TYPE(value); + } else if (!PyExceptionClass_Check(type)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto bad; + } + if (cause) { + PyObject *fixed_cause; + if (PyExceptionClass_Check(cause)) { + fixed_cause = PyObject_CallObject(cause, NULL); + if (fixed_cause == NULL) + goto bad; + } + else if (PyExceptionInstance_Check(cause)) { + fixed_cause = cause; + Py_INCREF(fixed_cause); + } + else { + PyErr_SetString(PyExc_TypeError, + "exception causes must derive from " + "BaseException"); + goto bad; + } + if (!value) { + value = PyObject_CallObject(type, NULL); + } + PyException_SetCause(value, fixed_cause); + } + PyErr_SetObject(type, value); + if (tb) { + PyThreadState *tstate = PyThreadState_GET(); + PyObject* tmp_tb = tstate->curexc_traceback; + if (tb != tmp_tb) { + Py_INCREF(tb); + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_tb); + } + } +bad: + return; +} +#endif + +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { + if (unlikely(!type)) { + PyErr_Format(PyExc_SystemError, "Missing type object"); + return 0; + } + if (likely(PyObject_TypeCheck(obj, type))) + return 1; + PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", + Py_TYPE(obj)->tp_name, type->tp_name); + return 0; +} + +static CYTHON_INLINE int __Pyx_CheckKeywordStrings( + PyObject *kwdict, + const char* function_name, + int kw_allowed) +{ + PyObject* key = 0; + Py_ssize_t pos = 0; + while (PyDict_Next(kwdict, &pos, &key, 0)) { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) + #else + if (unlikely(!PyUnicode_Check(key))) + #endif + goto invalid_keyword_type; + } + if ((!kw_allowed) && unlikely(key)) + goto invalid_keyword; + return 1; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%s() keywords must be strings", function_name); + return 0; +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%s() got an unexpected keyword argument '%s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif + return 0; +} + + + +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) { + PyObject *local_type, *local_value, *local_tb; + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyThreadState *tstate = PyThreadState_GET(); + local_type = tstate->curexc_type; + local_value = tstate->curexc_value; + local_tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; + PyErr_NormalizeException(&local_type, &local_value, &local_tb); + if (unlikely(tstate->curexc_type)) + goto bad; + #if PY_MAJOR_VERSION >= 3 + if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) + goto bad; + #endif + *type = local_type; + *value = local_value; + *tb = local_tb; + Py_INCREF(local_type); + Py_INCREF(local_value); + Py_INCREF(local_tb); + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = local_type; + tstate->exc_value = local_value; + tstate->exc_traceback = local_tb; + /* Make sure tstate is in a consistent state when we XDECREF + these objects (XDECREF may run arbitrary code). */ + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); + return 0; +bad: + *type = 0; + *value = 0; + *tb = 0; + Py_XDECREF(local_type); + Py_XDECREF(local_value); + Py_XDECREF(local_tb); + return -1; +} + +static CYTHON_INLINE long __Pyx_div_long(long a, long b) { + long q = a / b; + long r = a - q*b; + q -= ((r != 0) & ((r ^ b) < 0)); + return q; +} + +static CYTHON_INLINE long __Pyx_mod_long(long a, long b) { + long r = a % b; + r += ((r != 0) & ((r ^ b) < 0)) * b; + return r; +} + +static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { + PyErr_Format(PyExc_ValueError, + "need more than %"PY_FORMAT_SIZE_T"d value%s to unpack", + index, (index == 1) ? "" : "s"); +} + +static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { + PyErr_Format(PyExc_ValueError, + "too many values to unpack (expected %"PY_FORMAT_SIZE_T"d)", expected); +} + +static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { + if (unlikely(retval)) { + Py_DECREF(retval); + __Pyx_RaiseTooManyValuesError(expected); + return -1; + } else if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) { + PyErr_Clear(); + return 0; + } else { + return -1; + } + } + return 0; +} + + + +static double __Pyx__PyObject_AsDouble(PyObject* obj) { + PyObject* float_value; + if (Py_TYPE(obj)->tp_as_number && Py_TYPE(obj)->tp_as_number->nb_float) { + return PyFloat_AsDouble(obj); + } else if (PyUnicode_CheckExact(obj) || PyBytes_CheckExact(obj)) { +#if PY_MAJOR_VERSION >= 3 + float_value = PyFloat_FromString(obj); +#else + float_value = PyFloat_FromString(obj, 0); +#endif + } else { + PyObject* args = PyTuple_New(1); + if (unlikely(!args)) goto bad; + PyTuple_SET_ITEM(args, 0, obj); + float_value = PyObject_Call((PyObject*)&PyFloat_Type, args, 0); + PyTuple_SET_ITEM(args, 0, 0); + Py_DECREF(args); + } + if (likely(float_value)) { + double value = PyFloat_AS_DOUBLE(float_value); + Py_DECREF(float_value); + return value; + } +bad: + return (double)-1; +} + +static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) { + PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname); +} + +static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, + const char *name, int exact) +{ + if (!type) { + PyErr_Format(PyExc_SystemError, "Missing type object"); + return 0; + } + if (none_allowed && obj == Py_None) return 1; + else if (exact) { + if (Py_TYPE(obj) == type) return 1; + } + else { + if (PyObject_TypeCheck(obj, type)) return 1; + } + PyErr_Format(PyExc_TypeError, + "Argument '%s' has incorrect type (expected %s, got %s)", + name, type->tp_name, Py_TYPE(obj)->tp_name); + return 0; +} + +static CYTHON_INLINE void __Pyx_RaiseNoneIndexingError(void) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is unsubscriptable"); +} + +static CYTHON_INLINE int __Pyx_div_int(int a, int b) { + int q = a / b; + int r = a - q*b; + q -= ((r != 0) & ((r ^ b) < 0)); + return q; +} + +static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) { + PyThreadState *tstate = PyThreadState_GET(); + *type = tstate->exc_type; + *value = tstate->exc_value; + *tb = tstate->exc_traceback; + Py_XINCREF(*type); + Py_XINCREF(*value); + Py_XINCREF(*tb); +} +static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyThreadState *tstate = PyThreadState_GET(); + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = type; + tstate->exc_value = value; + tstate->exc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +} + +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) { + PyObject *py_import = 0; + PyObject *empty_list = 0; + PyObject *module = 0; + PyObject *global_dict = 0; + PyObject *empty_dict = 0; + PyObject *list; + py_import = __Pyx_GetAttrString(__pyx_b, "__import__"); + if (!py_import) + goto bad; + if (from_list) + list = from_list; + else { + empty_list = PyList_New(0); + if (!empty_list) + goto bad; + list = empty_list; + } + global_dict = PyModule_GetDict(__pyx_m); + if (!global_dict) + goto bad; + empty_dict = PyDict_New(); + if (!empty_dict) + goto bad; + #if PY_VERSION_HEX >= 0x02050000 + { + #if PY_MAJOR_VERSION >= 3 + if (level == -1) { + if (strchr(__Pyx_MODULE_NAME, '.')) { + /* try package relative import first */ + PyObject *py_level = PyInt_FromLong(1); + if (!py_level) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, py_level, NULL); + Py_DECREF(py_level); + if (!module) { + if (!PyErr_ExceptionMatches(PyExc_ImportError)) + goto bad; + PyErr_Clear(); + } + } + level = 0; /* try absolute import on failure */ + } + #endif + if (!module) { + PyObject *py_level = PyInt_FromLong(level); + if (!py_level) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, py_level, NULL); + Py_DECREF(py_level); + } + } + #else + if (level>0) { + PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4."); + goto bad; + } + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, NULL); + #endif +bad: + Py_XDECREF(empty_list); + Py_XDECREF(py_import); + Py_XDECREF(empty_dict); + return module; +} + +static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { + const unsigned char neg_one = (unsigned char)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(unsigned char) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(unsigned char)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to unsigned char" : + "value too large to convert to unsigned char"); + } + return (unsigned char)-1; + } + return (unsigned char)val; + } + return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); +} + +static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { + const unsigned short neg_one = (unsigned short)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(unsigned short) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(unsigned short)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to unsigned short" : + "value too large to convert to unsigned short"); + } + return (unsigned short)-1; + } + return (unsigned short)val; + } + return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); +} + +static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { + const unsigned int neg_one = (unsigned int)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(unsigned int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(unsigned int)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to unsigned int" : + "value too large to convert to unsigned int"); + } + return (unsigned int)-1; + } + return (unsigned int)val; + } + return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); +} + +static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) { + const char neg_one = (char)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(char) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(char)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to char" : + "value too large to convert to char"); + } + return (char)-1; + } + return (char)val; + } + return (char)__Pyx_PyInt_AsLong(x); +} + +static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) { + const short neg_one = (short)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(short) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(short)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to short" : + "value too large to convert to short"); + } + return (short)-1; + } + return (short)val; + } + return (short)__Pyx_PyInt_AsLong(x); +} + +static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) { + const int neg_one = (int)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(int)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to int" : + "value too large to convert to int"); + } + return (int)-1; + } + return (int)val; + } + return (int)__Pyx_PyInt_AsLong(x); +} + +static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { + const signed char neg_one = (signed char)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(signed char) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(signed char)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to signed char" : + "value too large to convert to signed char"); + } + return (signed char)-1; + } + return (signed char)val; + } + return (signed char)__Pyx_PyInt_AsSignedLong(x); +} + +static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { + const signed short neg_one = (signed short)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(signed short) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(signed short)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to signed short" : + "value too large to convert to signed short"); + } + return (signed short)-1; + } + return (signed short)val; + } + return (signed short)__Pyx_PyInt_AsSignedLong(x); +} + +static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { + const signed int neg_one = (signed int)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(signed int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(signed int)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to signed int" : + "value too large to convert to signed int"); + } + return (signed int)-1; + } + return (signed int)val; + } + return (signed int)__Pyx_PyInt_AsSignedLong(x); +} + +static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) { + const int neg_one = (int)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(int)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to int" : + "value too large to convert to int"); + } + return (int)-1; + } + return (int)val; + } + return (int)__Pyx_PyInt_AsLong(x); +} + +static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { + const unsigned long neg_one = (unsigned long)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned long"); + return (unsigned long)-1; + } + return (unsigned long)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned long"); + return (unsigned long)-1; + } + return (unsigned long)PyLong_AsUnsignedLong(x); + } else { + return (unsigned long)PyLong_AsLong(x); + } + } else { + unsigned long val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (unsigned long)-1; + val = __Pyx_PyInt_AsUnsignedLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { + const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned PY_LONG_LONG"); + return (unsigned PY_LONG_LONG)-1; + } + return (unsigned PY_LONG_LONG)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned PY_LONG_LONG"); + return (unsigned PY_LONG_LONG)-1; + } + return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); + } else { + return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x); + } + } else { + unsigned PY_LONG_LONG val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (unsigned PY_LONG_LONG)-1; + val = __Pyx_PyInt_AsUnsignedLongLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { + const long neg_one = (long)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long)-1; + } + return (long)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long)-1; + } + return (long)PyLong_AsUnsignedLong(x); + } else { + return (long)PyLong_AsLong(x); + } + } else { + long val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (long)-1; + val = __Pyx_PyInt_AsLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { + const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to PY_LONG_LONG"); + return (PY_LONG_LONG)-1; + } + return (PY_LONG_LONG)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to PY_LONG_LONG"); + return (PY_LONG_LONG)-1; + } + return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); + } else { + return (PY_LONG_LONG)PyLong_AsLongLong(x); + } + } else { + PY_LONG_LONG val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (PY_LONG_LONG)-1; + val = __Pyx_PyInt_AsLongLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { + const signed long neg_one = (signed long)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to signed long"); + return (signed long)-1; + } + return (signed long)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to signed long"); + return (signed long)-1; + } + return (signed long)PyLong_AsUnsignedLong(x); + } else { + return (signed long)PyLong_AsLong(x); + } + } else { + signed long val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (signed long)-1; + val = __Pyx_PyInt_AsSignedLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { + const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to signed PY_LONG_LONG"); + return (signed PY_LONG_LONG)-1; + } + return (signed PY_LONG_LONG)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to signed PY_LONG_LONG"); + return (signed PY_LONG_LONG)-1; + } + return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); + } else { + return (signed PY_LONG_LONG)PyLong_AsLongLong(x); + } + } else { + signed PY_LONG_LONG val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (signed PY_LONG_LONG)-1; + val = __Pyx_PyInt_AsSignedLongLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static void __Pyx_WriteUnraisable(const char *name, int clineno, + int lineno, const char *filename) { + PyObject *old_exc, *old_val, *old_tb; + PyObject *ctx; + __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); + #if PY_MAJOR_VERSION < 3 + ctx = PyString_FromString(name); + #else + ctx = PyUnicode_FromString(name); + #endif + __Pyx_ErrRestore(old_exc, old_val, old_tb); + if (!ctx) { + PyErr_WriteUnraisable(Py_None); + } else { + PyErr_WriteUnraisable(ctx); + Py_DECREF(ctx); + } +} + +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyThreadState *tstate = PyThreadState_GET(); + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = *type; + tstate->exc_value = *value; + tstate->exc_traceback = *tb; + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} + +static PyObject *__Pyx_Generator_Next(PyObject *self); +static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value); +static PyObject *__Pyx_Generator_Close(PyObject *self); +static PyObject *__Pyx_Generator_Throw(PyObject *gen, PyObject *args); +static CYTHON_INLINE +void __Pyx_Generator_ExceptionClear(__pyx_GeneratorObject *self) +{ + PyObject *exc_type = self->exc_type; + PyObject *exc_value = self->exc_value; + PyObject *exc_traceback = self->exc_traceback; + self->exc_type = NULL; + self->exc_value = NULL; + self->exc_traceback = NULL; + Py_XDECREF(exc_type); + Py_XDECREF(exc_value); + Py_XDECREF(exc_traceback); +} +static CYTHON_INLINE +PyObject *__Pyx_Generator_SendEx(__pyx_GeneratorObject *self, PyObject *value) +{ + PyObject *retval; + if (unlikely(self->is_running)) { + PyErr_SetString(PyExc_ValueError, + "generator already executing"); + return NULL; + } + if (unlikely(self->resume_label == 0)) { + if (unlikely(value && value != Py_None)) { + PyErr_SetString(PyExc_TypeError, + "can't send non-None value to a " + "just-started generator"); + return NULL; + } + } + if (unlikely(self->resume_label == -1)) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + if (value) + __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, &self->exc_traceback); + else + __Pyx_Generator_ExceptionClear(self); + self->is_running = 1; + retval = self->body((PyObject *) self, value); + self->is_running = 0; + if (retval) + __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, &self->exc_traceback); + else + __Pyx_Generator_ExceptionClear(self); + return retval; +} +static PyObject *__Pyx_Generator_Next(PyObject *self) +{ + return __Pyx_Generator_SendEx((__pyx_GeneratorObject *) self, Py_None); +} +static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value) +{ + return __Pyx_Generator_SendEx((__pyx_GeneratorObject *) self, value); +} +static PyObject *__Pyx_Generator_Close(PyObject *self) +{ + __pyx_GeneratorObject *generator = (__pyx_GeneratorObject *) self; + PyObject *retval; +#if PY_VERSION_HEX < 0x02050000 + PyErr_SetNone(PyExc_StopIteration); +#else + PyErr_SetNone(PyExc_GeneratorExit); +#endif + retval = __Pyx_Generator_SendEx(generator, NULL); + if (retval) { + Py_DECREF(retval); + PyErr_SetString(PyExc_RuntimeError, + "generator ignored GeneratorExit"); + return NULL; + } +#if PY_VERSION_HEX < 0x02050000 + if (PyErr_ExceptionMatches(PyExc_StopIteration)) +#else + if (PyErr_ExceptionMatches(PyExc_StopIteration) + || PyErr_ExceptionMatches(PyExc_GeneratorExit)) +#endif + { + PyErr_Clear(); /* ignore these errors */ + Py_INCREF(Py_None); + return Py_None; + } + return NULL; +} +static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args) +{ + __pyx_GeneratorObject *generator = (__pyx_GeneratorObject *) self; + PyObject *typ; + PyObject *tb = NULL; + PyObject *val = NULL; + if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb)) + return NULL; + __Pyx_Raise(typ, val, tb, NULL); + return __Pyx_Generator_SendEx(generator, NULL); +} +static int +__Pyx_Generator_traverse(PyObject *self, visitproc visit, void *arg) +{ + __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; + Py_VISIT(gen->closure); + Py_VISIT(gen->classobj); + Py_VISIT(gen->exc_type); + Py_VISIT(gen->exc_value); + Py_VISIT(gen->exc_traceback); + return 0; +} +static void +__Pyx_Generator_dealloc(PyObject *self) +{ + __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; + PyObject_GC_UnTrack(gen); + if (gen->gi_weakreflist != NULL) + PyObject_ClearWeakRefs(self); + PyObject_GC_Track(self); + if (gen->resume_label > 0) { + Py_TYPE(gen)->tp_del(self); + if (self->ob_refcnt > 0) + return; /* resurrected. :( */ + } + PyObject_GC_UnTrack(self); + Py_CLEAR(gen->closure); + Py_CLEAR(gen->classobj); + Py_CLEAR(gen->exc_type); + Py_CLEAR(gen->exc_value); + Py_CLEAR(gen->exc_traceback); + PyObject_GC_Del(gen); +} +static void +__Pyx_Generator_del(PyObject *self) +{ + PyObject *res; + PyObject *error_type, *error_value, *error_traceback; + __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; + if (gen->resume_label <= 0) + return ; + assert(self->ob_refcnt == 0); + self->ob_refcnt = 1; + __Pyx_ErrFetch(&error_type, &error_value, &error_traceback); + res = __Pyx_Generator_Close(self); + if (res == NULL) + PyErr_WriteUnraisable(self); + else + Py_DECREF(res); + __Pyx_ErrRestore(error_type, error_value, error_traceback); + /* Undo the temporary resurrection; can't use DECREF here, it would + * cause a recursive call. + */ + assert(self->ob_refcnt > 0); + if (--self->ob_refcnt == 0) + return; /* this is the normal path out */ + /* close() resurrected it! Make it look like the original Py_DECREF + * never happened. + */ + { + Py_ssize_t refcnt = self->ob_refcnt; + _Py_NewReference(self); + self->ob_refcnt = refcnt; + } + assert(PyType_IS_GC(self->ob_type) && + _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED); + /* If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so + * we need to undo that. */ + _Py_DEC_REFTOTAL; + /* If Py_TRACE_REFS, _Py_NewReference re-added self to the object + * chain, so no more to do there. + * If COUNT_ALLOCS, the original decref bumped tp_frees, and + * _Py_NewReference bumped tp_allocs: both of those need to be + * undone. + */ +#ifdef COUNT_ALLOCS + --self->ob_type->tp_frees; + --self->ob_type->tp_allocs; +#endif +} +static PyMemberDef __pyx_Generator_memberlist[] = { + {(char *) "gi_running", + T_INT, + offsetof(__pyx_GeneratorObject, is_running), + READONLY, + NULL}, + {0, 0, 0, 0, 0} +}; +static PyMethodDef __pyx_Generator_methods[] = { + {__Pyx_NAMESTR("send"), (PyCFunction) __Pyx_Generator_Send, METH_O, 0}, + {__Pyx_NAMESTR("throw"), (PyCFunction) __Pyx_Generator_Throw, METH_VARARGS, 0}, + {__Pyx_NAMESTR("close"), (PyCFunction) __Pyx_Generator_Close, METH_NOARGS, 0}, + {0, 0, 0, 0} +}; +static PyTypeObject __pyx_GeneratorType = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("generator"), /*tp_name*/ + sizeof(__pyx_GeneratorObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + (destructor) __Pyx_Generator_dealloc,/*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ +#if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ +#else + 0, /*reserved*/ +#endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + PyObject_GenericGetAttr, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags*/ + 0, /*tp_doc*/ + (traverseproc) __Pyx_Generator_traverse, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + offsetof(__pyx_GeneratorObject, gi_weakreflist), /* tp_weaklistoffse */ + PyObject_SelfIter, /*tp_iter*/ + (iternextfunc) __Pyx_Generator_Next, /*tp_iternext*/ + __pyx_Generator_methods, /*tp_methods*/ + __pyx_Generator_memberlist, /*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*/ + 0, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + __Pyx_Generator_del, /*tp_del*/ +#if PY_VERSION_HEX >= 0x02060000 + 0, /*tp_version_tag*/ +#endif +}; +static +__pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body, + PyObject *closure) +{ + __pyx_GeneratorObject *gen = + PyObject_GC_New(__pyx_GeneratorObject, &__pyx_GeneratorType); + if (gen == NULL) + return NULL; + gen->body = body; + gen->closure = closure; + Py_XINCREF(closure); + gen->is_running = 0; + gen->resume_label = 0; + gen->classobj = NULL; + gen->exc_type = NULL; + gen->exc_value = NULL; + gen->exc_traceback = NULL; + gen->gi_weakreflist = NULL; + PyObject_GC_Track(gen); + return gen; +} +static int __pyx_Generator_init(void) +{ + return PyType_Ready(&__pyx_GeneratorType); +} + +static int __Pyx_check_binary_version(void) { + char ctversion[4], rtversion[4]; + PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); + PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); + if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { + char message[200]; + PyOS_snprintf(message, sizeof(message), + "compiletime version %s of module '%.100s' " + "does not match runtime version %s", + ctversion, __Pyx_MODULE_NAME, rtversion); + #if PY_VERSION_HEX < 0x02050000 + return PyErr_Warn(NULL, message); + #else + return PyErr_WarnEx(NULL, message, 1); + #endif + } + return 0; +} + +static int __Pyx_SetVtable(PyObject *dict, void *vtable) { +#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) + PyObject *ob = PyCapsule_New(vtable, 0, 0); +#else + PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); +#endif + if (!ob) + goto bad; + if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0) + goto bad; + Py_DECREF(ob); + return 0; +bad: + Py_XDECREF(ob); + return -1; +} + +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { + int start = 0, mid = 0, end = count - 1; + if (end >= 0 && code_line > entries[end].code_line) { + return count; + } + while (start < end) { + mid = (start + end) / 2; + if (code_line < entries[mid].code_line) { + end = mid; + } else if (code_line > entries[mid].code_line) { + start = mid + 1; + } else { + return mid; + } + } + if (code_line <= entries[mid].code_line) { + return mid; + } else { + return mid + 1; + } +} +static PyCodeObject *__pyx_find_code_object(int code_line) { + PyCodeObject* code_object; + int pos; + if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { + return NULL; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { + return NULL; + } + code_object = __pyx_code_cache.entries[pos].code_object; + Py_INCREF(code_object); + return code_object; +} +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { + int pos, i; + __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; + if (unlikely(!code_line)) { + return; + } + if (unlikely(!entries)) { + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); + if (likely(entries)) { + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = 64; + __pyx_code_cache.count = 1; + entries[0].code_line = code_line; + entries[0].code_object = code_object; + Py_INCREF(code_object); + } + return; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { + PyCodeObject* tmp = entries[pos].code_object; + entries[pos].code_object = code_object; + Py_DECREF(tmp); + return; + } + if (__pyx_code_cache.count == __pyx_code_cache.max_count) { + int new_max = __pyx_code_cache.max_count + 64; + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( + __pyx_code_cache.entries, new_max*sizeof(__Pyx_CodeObjectCacheEntry)); + if (unlikely(!entries)) { + return; + } + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = new_max; + } + for (i=__pyx_code_cache.count; i>pos; i--) { + entries[i] = entries[i-1]; + } + entries[pos].code_line = code_line; + entries[pos].code_object = code_object; + __pyx_code_cache.count++; + Py_INCREF(code_object); +} + +#include "compile.h" +#include "frameobject.h" +#include "traceback.h" +static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( + const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyObject *py_srcfile = 0; + PyObject *py_funcname = 0; + #if PY_MAJOR_VERSION < 3 + py_srcfile = PyString_FromString(filename); + #else + py_srcfile = PyUnicode_FromString(filename); + #endif + if (!py_srcfile) goto bad; + if (c_line) { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + #else + py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + #endif + } + else { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromString(funcname); + #else + py_funcname = PyUnicode_FromString(funcname); + #endif + } + if (!py_funcname) goto bad; + py_code = __Pyx_PyCode_New( + 0, /*int argcount,*/ + 0, /*int kwonlyargcount,*/ + 0, /*int nlocals,*/ + 0, /*int stacksize,*/ + 0, /*int flags,*/ + __pyx_empty_bytes, /*PyObject *code,*/ + __pyx_empty_tuple, /*PyObject *consts,*/ + __pyx_empty_tuple, /*PyObject *names,*/ + __pyx_empty_tuple, /*PyObject *varnames,*/ + __pyx_empty_tuple, /*PyObject *freevars,*/ + __pyx_empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + py_line, /*int firstlineno,*/ + __pyx_empty_bytes /*PyObject *lnotab*/ + ); + Py_DECREF(py_srcfile); + Py_DECREF(py_funcname); + return py_code; +bad: + Py_XDECREF(py_srcfile); + Py_XDECREF(py_funcname); + return NULL; +} +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyObject *py_globals = 0; + PyFrameObject *py_frame = 0; + py_code = __pyx_find_code_object(c_line ? c_line : py_line); + if (!py_code) { + py_code = __Pyx_CreateCodeObjectForTraceback( + funcname, c_line, py_line, filename); + if (!py_code) goto bad; + __pyx_insert_code_object(c_line ? c_line : py_line, py_code); + } + py_globals = PyModule_GetDict(__pyx_m); + if (!py_globals) goto bad; + py_frame = PyFrame_New( + PyThreadState_GET(), /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + py_globals, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + py_frame->f_lineno = py_line; + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} + +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + while (t->p) { + #if PY_MAJOR_VERSION < 3 + if (t->is_unicode) { + *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); + } else if (t->intern) { + *t->p = PyString_InternFromString(t->s); + } else { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + } + #else /* Python 3+ has unicode identifiers */ + if (t->is_unicode | t->is_str) { + if (t->intern) { + *t->p = PyUnicode_InternFromString(t->s); + } else if (t->encoding) { + *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); + } else { + *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); + } + } else { + *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); + } + #endif + if (!*t->p) + return -1; + ++t; + } + return 0; +} + + +/* Type Conversion Functions */ + +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { + int is_true = x == Py_True; + if (is_true | (x == Py_False) | (x == Py_None)) return is_true; + else return PyObject_IsTrue(x); +} + +static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { + PyNumberMethods *m; + const char *name = NULL; + PyObject *res = NULL; +#if PY_VERSION_HEX < 0x03000000 + if (PyInt_Check(x) || PyLong_Check(x)) +#else + if (PyLong_Check(x)) +#endif + return Py_INCREF(x), x; + m = Py_TYPE(x)->tp_as_number; +#if PY_VERSION_HEX < 0x03000000 + if (m && m->nb_int) { + name = "int"; + res = PyNumber_Int(x); + } + else if (m && m->nb_long) { + name = "long"; + res = PyNumber_Long(x); + } +#else + if (m && m->nb_int) { + name = "int"; + res = PyNumber_Long(x); + } +#endif + if (res) { +#if PY_VERSION_HEX < 0x03000000 + if (!PyInt_Check(res) && !PyLong_Check(res)) { +#else + if (!PyLong_Check(res)) { +#endif + PyErr_Format(PyExc_TypeError, + "__%s__ returned non-%s (type %.200s)", + name, name, Py_TYPE(res)->tp_name); + Py_DECREF(res); + return NULL; + } + } + else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, + "an integer is required"); + } + return res; +} + +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { + Py_ssize_t ival; + PyObject* x = PyNumber_Index(b); + if (!x) return -1; + ival = PyInt_AsSsize_t(x); + Py_DECREF(x); + return ival; +} + +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { +#if PY_VERSION_HEX < 0x02050000 + if (ival <= LONG_MAX) + return PyInt_FromLong((long)ival); + else { + unsigned char *bytes = (unsigned char *) &ival; + int one = 1; int little = (int)*(unsigned char*)&one; + return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); + } +#else + return PyInt_FromSize_t(ival); +#endif +} + +static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { + unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); + if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { + return (size_t)-1; + } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to size_t"); + return (size_t)-1; + } + return (size_t)val; +} + + +#endif /* Py_PYTHON_H */ diff --git a/python/src/sa/_cdec_sa.pyx b/python/src/sa/_cdec_sa.pyx new file mode 100644 index 00000000..710f8cb4 --- /dev/null +++ b/python/src/sa/_cdec_sa.pyx @@ -0,0 +1,29 @@ +import logging +import resource +import gzip + +cdef float monitor_cpu(): + return (resource.getrusage(resource.RUSAGE_SELF).ru_utime+ + resource.getrusage(resource.RUSAGE_SELF).ru_stime) + +def gzip_or_text(char* filename): + if filename.endswith('.gz'): + return gzip.GzipFile(filename) + else: + return open(filename) + +logger = logging.getLogger('cdec.sa') + +include "float_list.pxi" +include "int_list.pxi" +include "str_map.pxi" +include "data_array.pxi" +include "alignment.pxi" +include "bilex.pxi" +include "veb.pxi" +include "lcp.pxi" +include "sym.pxi" +include "rule.pxi" +include "precomputation.pxi" +include "suffix_array.pxi" +include "rulefactory.pxi" diff --git a/python/src/sa/alignment.pxi b/python/src/sa/alignment.pxi new file mode 100644 index 00000000..842899ad --- /dev/null +++ b/python/src/sa/alignment.pxi @@ -0,0 +1,105 @@ +from libc.stdio cimport FILE, fopen, fread, fwrite, fclose +from libc.stdlib cimport malloc, realloc, free + +# Note: Callison-Burch uses short instead of int. +# We have the space for our corpus, so this is not a problem; +# May need to revisit if things get really tight, though. + +cdef class Alignment: + cdef IntList links + cdef IntList sent_index + + cdef int link(self, int i, int j): + """Integerizes an alignment link pair""" + return i*65536 + j + + def unlink(self, link): + """De-integerizes an alignment link pair""" + return (link/65536, link%65536) + + cdef _unlink(self, int link, int* f, int* e): + f[0] = link/65536 + e[0] = link%65536 + + def get_sent_links(self, int sent_id): + cdef IntList sent_links + cdef int* arr + cdef int arr_len + sent_links = IntList() + arr = self._get_sent_links(sent_id, &arr_len) + sent_links._extend_arr(arr, arr_len*2) + free(arr) + return sent_links + + cdef int* _get_sent_links(self, int sent_id, int* num_links): + cdef int* sent_links + cdef int i, start, end + start = self.sent_index.arr[sent_id] + end = self.sent_index.arr[sent_id+1] + num_links[0] = end - start + sent_links = malloc(2*num_links[0]*sizeof(int)) + for i from 0 <= i < num_links[0]: + self._unlink(self.links.arr[start + i], sent_links + (2*i), sent_links + (2*i) + 1) + return sent_links + + def __cinit__(self, from_binary=None, from_text=None): + self.links = IntList(1000,1000) + self.sent_index = IntList(1000,1000) + if from_binary: + self.read_binary(from_binary) + elif from_text: + self.read_text(from_text) + + def read_text(self, char* filename): + with gzip_or_text(filename) as f: + for line in f: + self.sent_index.append(len(self.links)) + pairs = line.split() + for pair in pairs: + (i, j) = map(int, pair.split('-')) + self.links.append(self.link(i, j)) + self.sent_index.append(len(self.links)) + + def read_binary(self, char* filename): + cdef FILE* f + f = fopen(filename, "r") + self.links.read_handle(f) + self.sent_index.read_handle(f) + fclose(f) + + def write_text(self, char* filename): + with open(filename, "w") as f: + sent_num = 0 + for i, link in enumerate(self.links): + while i >= self.sent_index[sent_num]: + f.write("\n") + sent_num = sent_num + 1 + f.write("%d-%d " % self.unlink(link)) + f.write("\n") + + def write_binary(self, char* filename): + cdef FILE* f + f = fopen(filename, "w") + self.links.write_handle(f) + self.sent_index.write_handle(f) + fclose(f) + + def write_enhanced(self, char* filename): + with open(filename, "w") as f: + sent_num = 1 + for link in self.links: + f.write("%d " % link) + f.write("\n") + for i in self.sent_index: + f.write("%d " % i) + f.write("\n") + + def alignment(self, i): + """Return all (e,f) pairs for sentence i""" + cdef int j, start, end + result = [] + start = self.sent_index.arr[i] + end = self.sent_index.arr[i+1] + for j from start <= j < end: + result.append(self.unlink(self.links.arr[j])) + return result diff --git a/python/src/sa/bilex.pxi b/python/src/sa/bilex.pxi new file mode 100644 index 00000000..27d1be49 --- /dev/null +++ b/python/src/sa/bilex.pxi @@ -0,0 +1,418 @@ +# defines bilexical dictionaries in C, with some convenience methods +# for reading arrays directly as globs directly from disk. +# Adam Lopez + +from libc.stdio cimport FILE, fopen, fread, fwrite, fclose +from libc.stdlib cimport malloc, realloc, free +from libc.string cimport memset, strcpy, strlen + +cdef struct _node: + _node* smaller + _node* bigger + int key + int val + +cdef _node* new_node(int key): + cdef _node* n + n = <_node*> malloc(sizeof(_node)) + n.smaller = NULL + n.bigger = NULL + n.key = key + n.val = 0 + return n + + +cdef del_node(_node* n): + if n.smaller != NULL: + del_node(n.smaller) + if n.bigger != NULL: + del_node(n.bigger) + free(n) + +cdef int* get_val(_node* n, int key): + if key == n.key: + return &n.val + elif key < n.key: + if n.smaller == NULL: + n.smaller = new_node(key) + return &(n.smaller.val) + return get_val(n.smaller, key) + else: + if n.bigger == NULL: + n.bigger = new_node(key) + return &(n.bigger.val) + return get_val(n.bigger, key) + + +cdef class BiLex: + cdef FloatList col1 + cdef FloatList col2 + cdef IntList f_index + cdef IntList e_index + cdef id2eword, id2fword, eword2id, fword2id + + def __cinit__(self, from_text=None, from_data=False, from_binary=None, + earray=None, fsarray=None, alignment=None): + self.id2eword = [] + self.id2fword = [] + self.eword2id = {} + self.fword2id = {} + self.e_index = IntList() + self.f_index = IntList() + self.col1 = FloatList() + self.col2 = FloatList() + if from_binary: + self.read_binary(from_binary) + elif from_data: + self.compute_from_data(fsarray, earray, alignment) + else: + self.read_text(from_text) + + + cdef compute_from_data(self, SuffixArray fsa, DataArray eda, Alignment aa): + cdef int sent_id, num_links, l, i, j, f_i, e_j, I, J, V_E, V_F, num_pairs + cdef int *fsent, *esent, *alignment, *links, *ealigned, *faligned + cdef _node** dict + cdef int *fmargin, *emargin, *count + cdef bytes word + cdef int null_word + + null_word = 0 + for word in fsa.darray.id2word: # I miss list comprehensions + self.id2fword.append(word) + self.id2fword[null_word] = "NULL" + for id, word in enumerate(self.id2fword): + self.fword2id[word] = id + + for word in eda.id2word: + self.id2eword.append(word) + self.id2eword[null_word] = "NULL" + for id, word in enumerate(self.id2eword): + self.eword2id[word] = id + + num_pairs = 0 + + V_E = len(eda.id2word) + V_F = len(fsa.darray.id2word) + fmargin = malloc(V_F*sizeof(int)) + emargin = malloc(V_E*sizeof(int)) + memset(fmargin, 0, V_F*sizeof(int)) + memset(emargin, 0, V_E*sizeof(int)) + + dict = <_node**> malloc(V_F*sizeof(_node*)) + memset(dict, 0, V_F*sizeof(_node*)) + + num_sents = len(fsa.darray.sent_index) + for sent_id from 0 <= sent_id < num_sents-1: + + fsent = fsa.darray.data.arr + fsa.darray.sent_index.arr[sent_id] + I = fsa.darray.sent_index.arr[sent_id+1] - fsa.darray.sent_index.arr[sent_id] - 1 + faligned = malloc(I*sizeof(int)) + memset(faligned, 0, I*sizeof(int)) + + esent = eda.data.arr + eda.sent_index.arr[sent_id] + J = eda.sent_index.arr[sent_id+1] - eda.sent_index.arr[sent_id] - 1 + ealigned = malloc(J*sizeof(int)) + memset(ealigned, 0, J*sizeof(int)) + + links = aa._get_sent_links(sent_id, &num_links) + + for l from 0 <= l < num_links: + i = links[l*2] + j = links[l*2+1] + if i >= I or j >= J: + raise Exception("%d-%d out of bounds (I=%d,J=%d) in line %d\n" % (i,j,I,J,sent_id+1)) + f_i = fsent[i] + e_j = esent[j] + fmargin[f_i] = fmargin[f_i]+1 + emargin[e_j] = emargin[e_j]+1 + if dict[f_i] == NULL: + dict[f_i] = new_node(e_j) + dict[f_i].val = 1 + num_pairs = num_pairs + 1 + else: + count = get_val(dict[f_i], e_j) + if count[0] == 0: + num_pairs = num_pairs + 1 + count[0] = count[0] + 1 + # add count + faligned[i] = 1 + ealigned[j] = 1 + for i from 0 <= i < I: + if faligned[i] == 0: + f_i = fsent[i] + fmargin[f_i] = fmargin[f_i] + 1 + emargin[null_word] = emargin[null_word] + 1 + if dict[f_i] == NULL: + dict[f_i] = new_node(null_word) + dict[f_i].val = 1 + num_pairs = num_pairs + 1 + else: + count = get_val(dict[f_i], null_word) + if count[0] == 0: + num_pairs = num_pairs + 1 + count[0] = count[0] + 1 + for j from 0 <= j < J: + if ealigned[j] == 0: + e_j = esent[j] + fmargin[null_word] = fmargin[null_word] + 1 + emargin[e_j] = emargin[e_j] + 1 + if dict[null_word] == NULL: + dict[null_word] = new_node(e_j) + dict[null_word].val = 1 + num_pairs = num_pairs + 1 + else: + count = get_val(dict[null_word], e_j) + if count[0] == 0: + num_pairs = num_pairs + 1 + count[0] = count[0] + 1 + free(links) + free(faligned) + free(ealigned) + self.f_index = IntList(initial_len=V_F) + self.e_index = IntList(initial_len=num_pairs) + self.col1 = FloatList(initial_len=num_pairs) + self.col2 = FloatList(initial_len=num_pairs) + + num_pairs = 0 + for i from 0 <= i < V_F: + #self.f_index[i] = num_pairs + self.f_index.set(i, num_pairs) + if dict[i] != NULL: + self._add_node(dict[i], &num_pairs, float(fmargin[i]), emargin) + del_node(dict[i]) + free(fmargin) + free(emargin) + free(dict) + return + + + cdef _add_node(self, _node* n, int* num_pairs, float fmargin, int* emargin): + cdef int loc + if n.smaller != NULL: + self._add_node(n.smaller, num_pairs, fmargin, emargin) + loc = num_pairs[0] + self.e_index.set(loc, n.key) + self.col1.set(loc, float(n.val)/fmargin) + self.col2.set(loc, float(n.val)/float(emargin[n.key])) + num_pairs[0] = loc + 1 + if n.bigger != NULL: + self._add_node(n.bigger, num_pairs, fmargin, emargin) + + + def write_binary(self, char* filename): + cdef FILE* f + f = fopen(filename, "w") + self.f_index.write_handle(f) + self.e_index.write_handle(f) + self.col1.write_handle(f) + self.col2.write_handle(f) + self.write_wordlist(self.id2fword, f) + self.write_wordlist(self.id2eword, f) + fclose(f) + + + cdef write_wordlist(self, wordlist, FILE* f): + cdef int word_len + cdef int num_words + cdef char* c_word + + num_words = len(wordlist) + fwrite(&(num_words), sizeof(int), 1, f) + for word in wordlist: + c_word = word + word_len = strlen(c_word) + 1 + fwrite(&(word_len), sizeof(int), 1, f) + fwrite(c_word, sizeof(char), word_len, f) + + + cdef read_wordlist(self, word2id, id2word, FILE* f): + cdef int num_words + cdef int word_len + cdef char* c_word + cdef bytes py_word + + fread(&(num_words), sizeof(int), 1, f) + for i from 0 <= i < num_words: + fread(&(word_len), sizeof(int), 1, f) + c_word = malloc (word_len * sizeof(char)) + fread(c_word, sizeof(char), word_len, f) + py_word = c_word + free(c_word) + word2id[py_word] = len(id2word) + id2word.append(py_word) + + def read_binary(self, char* filename): + cdef FILE* f + f = fopen(filename, "r") + self.f_index.read_handle(f) + self.e_index.read_handle(f) + self.col1.read_handle(f) + self.col2.read_handle(f) + self.read_wordlist(self.fword2id, self.id2fword, f) + self.read_wordlist(self.eword2id, self.id2eword, f) + fclose(f) + + + def get_e_id(self, eword): + if eword not in self.eword2id: + e_id = len(self.id2eword) + self.id2eword.append(eword) + self.eword2id[eword] = e_id + return self.eword2id[eword] + + + def get_f_id(self, fword): + if fword not in self.fword2id: + f_id = len(self.id2fword) + self.id2fword.append(fword) + self.fword2id[fword] = f_id + return self.fword2id[fword] + + + def read_text(self, char* filename): + cdef i, j, w, e_id, f_id, n_f, n_e, N + cdef IntList fcount + + fcount = IntList() + with gzip_or_text(filename) as f: + # first loop merely establishes size of array objects + for line in f: + (fword, eword, score1, score2) = line.split() + f_id = self.get_f_id(fword) + e_id = self.get_e_id(eword) + while f_id >= len(fcount): + fcount.append(0) + fcount.arr[f_id] = fcount.arr[f_id] + 1 + + # Allocate space for dictionary in arrays + N = 0 + n_f = len(fcount) + self.f_index = IntList(initial_len=n_f+1) + for i from 0 <= i < n_f: + self.f_index.arr[i] = N + N = N + fcount.arr[i] + fcount.arr[i] = 0 + self.f_index.arr[n_f] = N + self.e_index = IntList(initial_len=N) + self.col1 = FloatList(initial_len=N) + self.col2 = FloatList(initial_len=N) + + # Re-read file, placing words into buckets + f.seek(0) + for line in f: + (fword, eword, score1, score2) = line.split() + f_id = self.get_f_id(fword) + e_id = self.get_e_id(eword) + index = self.f_index.arr[f_id] + fcount.arr[f_id] + fcount.arr[f_id] = fcount.arr[f_id] + 1 + self.e_index.arr[index] = int(e_id) + self.col1[index] = float(score1) + self.col2[index] = float(score2) + + # Sort buckets by eword + for b from 0 <= b < n_f: + i = self.f_index.arr[b] + j = self.f_index.arr[b+1] + self.qsort(i,j, "") + + + cdef swap(self, int i, int j): + cdef int itmp + cdef float ftmp + + if i == j: + return + + itmp = self.e_index.arr[i] + self.e_index.arr[i] = self.e_index.arr[j] + self.e_index.arr[j] = itmp + + ftmp = self.col1.arr[i] + self.col1.arr[i] = self.col1.arr[j] + self.col1.arr[j] = ftmp + + ftmp = self.col2.arr[i] + self.col2.arr[i] = self.col2.arr[j] + self.col2.arr[j] = ftmp + + + cdef qsort(self, int i, int j, pad): + cdef int pval, p + + if i > j: + raise Exception("Sort error in CLex") + if i == j: #empty interval + return + if i == j-1: # singleton interval + return + + p = (i+j)/2 + pval = self.e_index.arr[p] + self.swap(i, p) + p = i + for k from i+1 <= k < j: + if pval >= self.e_index.arr[k]: + self.swap(p+1, k) + self.swap(p, p+1) + p = p + 1 + self.qsort(i,p, pad+" ") + self.qsort(p+1,j, pad+" ") + + + def write_enhanced(self, char* filename): + with open(filename, "w") as f: + for i in self.f_index: + f.write("%d " % i) + f.write("\n") + for i, s1, s2 in zip(self.e_index, self.col1, self.col2): + f.write("%d %f %f " % (i, s1, s2)) + f.write("\n") + for i, w in enumerate(self.id2fword): + f.write("%d %s " % (i, w)) + f.write("\n") + for i, w in enumerate(self.id2eword): + f.write("%d %s " % (i, w)) + f.write("\n") + + + def get_score(self, fword, eword, col): + cdef e_id, f_id, low, high, midpoint, val + + if eword not in self.eword2id: + return None + if fword not in self.fword2id: + return None + f_id = self.fword2id[fword] + e_id = self.eword2id[eword] + low = self.f_index.arr[f_id] + high = self.f_index.arr[f_id+1] + while high - low > 0: + midpoint = (low+high)/2 + val = self.e_index.arr[midpoint] + if val == e_id: + if col == 0: + return self.col1.arr[midpoint] + if col == 1: + return self.col2.arr[midpoint] + if val > e_id: + high = midpoint + if val < e_id: + low = midpoint + 1 + return None + + + def write_text(self, char* filename): + """Note: does not guarantee writing the dictionary in the original order""" + cdef i, N, e_id, f_id + + with open(filename, "w") as f: + N = len(self.e_index) + f_id = 0 + for i from 0 <= i < N: + while self.f_index.arr[f_id+1] == i: + f_id = f_id + 1 + e_id = self.e_index.arr[i] + score1 = self.col1.arr[i] + score2 = self.col2.arr[i] + f.write("%s %s %.6f %.6f\n" % (self.id2fword[f_id], self.id2eword[e_id], score1, score2)) diff --git a/python/src/sa/data_array.pxi b/python/src/sa/data_array.pxi new file mode 100644 index 00000000..1c044694 --- /dev/null +++ b/python/src/sa/data_array.pxi @@ -0,0 +1,146 @@ +# Defines "data arrays" that can be directly written to/read from disk in binary format +# In particular, the array itself is written/read directly as a glob of binary data +# Adam Lopez + +from libc.stdio cimport FILE, fopen, fread, fwrite, fclose +from libc.stdlib cimport malloc, realloc, free +from libc.string cimport memset, strcpy, strlen + +cdef class DataArray: + cdef word2id + cdef id2word + cdef IntList data + cdef IntList sent_id + cdef IntList sent_index + cdef bint use_sent_id + + def __cinit__(self, from_binary=None, from_text=None, bint use_sent_id=False): + self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} + self.id2word = ["END_OF_FILE", "END_OF_LINE"] + self.data = IntList(1000,1000) + self.sent_id = IntList(1000,1000) + self.sent_index = IntList(1000,1000) + self.use_sent_id = use_sent_id + if from_binary: + self.read_binary(from_binary) + elif from_text: + self.read_text(from_text) + + def __len__(self): + return len(self.data) + + def getSentId(self, i): + return self.sent_id.arr[i] + + def getSent(self, i): + cdef int j, start, stop + sent = [] + start = self.sent_index.arr[i] + stop = self.sent_index.arr[i+1] + for i from start <= i < stop: + sent.append(self.id2word[self.data.arr[i]]) + return sent + + def getSentPos(self, loc): + return loc - self.sent_index.arr[self.sent_id.arr[loc]] + + def get_id(self, word): + if not word in self.word2id: + self.word2id[word] = len(self.id2word) + self.id2word.append(word) + return self.word2id[word] + + def get_word(self, id): + return self.id2word[id] + + def write_text(self, char* filename): + with open(filename, "w") as f: + for w_id in self.data: + if w_id > 1: + f.write("%s " % self.get_word(w_id)) + if w_id == 1: + f.write("\n") + + def read_text(self, char* filename): + cdef int word_count = 0 + with gzip_or_text(filename) as fp: + for line_num, line in enumerate(fp): + self.sent_index.append(word_count) + for word in line.split(): + self.data.append(self.get_id(word)) + if self.use_sent_id: + self.sent_id.append(line_num) + word_count = word_count + 1 + self.data.append(1) + if self.use_sent_id: + self.sent_id.append(line_num) + word_count = word_count + 1 + self.data.append(0) + self.sent_index.append(word_count) + + def read_binary(self, char* filename): + cdef FILE* f + f = fopen(filename, "r") + self.read_handle(f) + fclose(f) + + cdef void read_handle(self, FILE* f): + cdef int num_words, word_len + cdef unsigned i + cdef char* c_word + cdef bytes py_word + self.data.read_handle(f) + self.sent_index.read_handle(f) + self.sent_id.read_handle(f) + fread(&(num_words), sizeof(int), 1, f) + for i in range(num_words): + fread(&(word_len), sizeof(int), 1, f) + c_word = malloc (word_len * sizeof(char)) + fread(c_word, sizeof(char), word_len, f) + py_word = c_word + free(c_word) + self.word2id[py_word] = len(self.id2word) + self.id2word.append(py_word) + if len(self.sent_id) == 0: + self.use_sent_id = False + else: + self.use_sent_id = True + + cdef void write_handle(self, FILE* f): + cdef int word_len + cdef int num_words + cdef char* c_word + self.data.write_handle(f) + self.sent_index.write_handle(f) + self.sent_id.write_handle(f) + num_words = len(self.id2word) - 2 + fwrite(&(num_words), sizeof(int), 1, f) + for word in self.id2word[2:]: + c_word = word + word_len = strlen(c_word) + 1 + fwrite(&(word_len), sizeof(int), 1, f) + fwrite(c_word, sizeof(char), word_len, f) + + def write_binary(self, char* filename): + cdef FILE* f + f = fopen(filename, "w") + self.write_handle(f) + fclose(f) + + def write_enhanced_handle(self, f): + for i in self.data: + f.write("%d " %i) + f.write("\n") + for i in self.sent_index: + f.write("%d " %i) + f.write("\n") + for i in self.sent_id: + f.write("%d " %i) + f.write("\n") + for word in self.id2word: + f.write("%s %d " % (word, self.word2id[word])) + f.write("\n") + + def write_enhanced(self, char* filename): + with open(filename, "w") as f: + self.write_enhanced_handle(self, f) diff --git a/python/src/sa/float_list.pxi b/python/src/sa/float_list.pxi new file mode 100644 index 00000000..88ffd5fc --- /dev/null +++ b/python/src/sa/float_list.pxi @@ -0,0 +1,77 @@ +# defines int arrays in C, with some convenience methods +# for reading arrays directly as globs directly from disk. +# Adam Lopez + +from libc.stdio cimport FILE, fopen, fread, fwrite, fclose +from libc.stdlib cimport malloc, realloc, free +from libc.string cimport memset, strcpy, strlen + +cdef class FloatList: + cdef int size + cdef int increment + cdef int len + cdef float* arr + + def __cinit__(self, int size=0, int increment=1, int initial_len=0): + if initial_len > size: + size = initial_len + self.size = size + self.increment = increment + self.len = initial_len + self.arr = malloc(size*sizeof(float)) + memset(self.arr, 0, initial_len*sizeof(float)) + + def __dealloc__(self): + free(self.arr) + + def __getitem__(self, i): + j = i + if i<0: + j = self.len + i + if j<0 or j>=self.len: + raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) + return self.arr[j] + + cdef void set(self, int i, float v): + j = i + if i<0: + j = self.len + i + if j<0 or j>=self.len: + raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) + self.arr[j] = v + + def __setitem__(self, i, val): + self.set(i, val) + + def __len__(self): + return self.len + + def append(self, float val): + if self.len == self.size: + self.size = self.size + self.increment + self.arr = realloc(self.arr, self.size*sizeof(float)) + self.arr[self.len] = val + self.len = self.len + 1 + + cdef void write_handle(self, FILE* f): + fwrite(&(self.len), sizeof(float), 1, f) + fwrite(self.arr, sizeof(float), self.len, f) + + def write(self, char* filename): + cdef FILE* f + f = fopen(filename, "w") + self.write_handle(f) + fclose(f) + + cdef void read_handle(self, FILE* f): + free(self.arr) + fread(&(self.len), sizeof(float), 1, f) + self.arr = malloc(self.len * sizeof(float)) + self.size = self.len + fread(self.arr, sizeof(float), self.len, f) + + def read(self, char* filename): + cdef FILE* f + f = fopen(filename, "r") + self.read_handle(f) + fclose(f) diff --git a/python/src/sa/int_list.pxi b/python/src/sa/int_list.pxi new file mode 100644 index 00000000..ad14bc9c --- /dev/null +++ b/python/src/sa/int_list.pxi @@ -0,0 +1,177 @@ +# defines int arrays in C, with some convenience methods +# for reading arrays as globs directly from disk. +# Adam Lopez + +from libc.stdio cimport FILE, fopen, fread, fwrite, fclose +from libc.stdlib cimport malloc, realloc, free +from libc.string cimport memset, memcpy + +cdef class IntList: + cdef int size + cdef int increment + cdef int len + cdef int* arr + + def __cinit__(self, int size=0, int increment=1, int initial_len=0): + if initial_len > size: + size = initial_len + self.size = size + self.increment = increment + self.len = initial_len + self.arr = malloc(size*sizeof(int)) + memset(self.arr, 0, initial_len*sizeof(int)) + + def __str__(self): + cdef unsigned i + ret = "IntList[" + for idx in range(self.size): + if idx>0: + ret += "," + ret += str(self.arr[idx]) + ret += "]" + ret += "len=" + ret += self.len + return ret + + def index(self, val): + cdef unsigned i + for i in range(self.len): + if self.arr[i] == val: + return i + return IndexError + + def partition(self,start,end): + pivot = self.arr[end] + bottom = start-1 + top = end + done = 0 + while not done: + while not done: + bottom += 1 + if bottom == top: + done = 1 + break + if self.arr[bottom] > pivot: + self.arr[top] = self.arr[bottom] + break + while not done: + top -= 1 + if top == bottom: + done = 1 + break + if self.arr[top] < pivot: + self.arr[bottom] = self.arr[top] + break + self.arr[top] = pivot + return top + + def _doquicksort(self,start,end): + if start < end: + split = self.partition(start,end) + self._doquicksort(start,split-1) + self._doquicksort(split+1,end) + else: + return + + def sort(self): + self._doquicksort(0,self.len-1) + + def reset(self): + self.len = 0 + + def __dealloc__(self): + free(self.arr) + + def __getitem__(self, index): + cdef int i, j, k + if isinstance(index, int): + j = index + if j < 0: + j = self.len + j + if j<0 or j>=self.len: + raise IndexError("Requested index %d of %d-length IntList" % (index, self.len)) + return self.arr[j] + elif isinstance(index, slice): + i = index.start + j = index.stop + if i < 0: + i = self.len + i + if j < 0: + j = self.len + j + if i < 0 or i >= self.len or j < 0 or j > self.len: + raise IndexError("Requested index %d:%d of %d-length IntList" % (index.start, index.stop, self.len)) + result = () + for k from i <= k < j: + result = result + (self.arr[k],) + return result + else: + raise TypeError("Illegal key type %s for IntList" % type(index)) + + cdef void set(self, int i, int val): + j = i + if i<0: + j = self.len + i + if j<0 or j>=self.len: + raise IndexError("Requested index %d of %d-length IntList" % (i, self.len)) + self.arr[j] = val + + def __setitem__(self, i, val): + self.set(i, val) + + def __len__(self): + return self.len + + def getSize(self): + return self.size + + def append(self, int val): + self._append(val) + + cdef void _append(self, int val): + if self.len == self.size: + self.size = self.size + self.increment + self.arr = realloc(self.arr, self.size*sizeof(int)) + self.arr[self.len] = val + self.len = self.len + 1 + + def extend(self, other): + self._extend(other) + + cdef void _extend(self, IntList other): + self._extend_arr(other.arr, other.len) + + cdef void _extend_arr(self, int* other, int other_len): + if self.size < self.len + other_len: + self.size = self.len + other_len + self.arr = realloc(self.arr, self.size*sizeof(int)) + memcpy(self.arr+self.len, other, other_len*sizeof(int)) + self.len = self.len + other_len + + cdef void _clear(self): + free(self.arr) + self.len = 0 + self.size = 0 + self.arr = malloc(0) + + cdef void write_handle(self, FILE* f): + fwrite(&(self.len), sizeof(int), 1, f) + fwrite(self.arr, sizeof(int), self.len, f) + + def write(self, char* filename): + cdef FILE* f + f = fopen(filename, "w") + self.write_handle(f) + fclose(f) + + cdef void read_handle(self, FILE* f): + (self.arr) + fread(&(self.len), sizeof(int), 1, f) + self.arr = malloc(self.len * sizeof(int)) + self.size = self.len + fread(self.arr, sizeof(int), self.len, f) + + def read(self, char* filename): + cdef FILE* f + f = fopen(filename, "r") + self.read_handle(f) + fclose(f) diff --git a/python/src/sa/lcp.pxi b/python/src/sa/lcp.pxi new file mode 100644 index 00000000..8e86e611 --- /dev/null +++ b/python/src/sa/lcp.pxi @@ -0,0 +1,89 @@ +"""Compute LCP array for a suffix array using the Kasai et al. algorithm +Can also be used to compute statistics such +as k most frequent n-grams""" + +cdef class LCP: + cdef SuffixArray sa + cdef IntList lcp + + def __cinit__(self, SuffixArray sa): + cdef int i, k, j, h, n + cdef IntList rank + + logger.info("Constructing LCP array") + self.sa = sa + n = self.sa.sa.len + self.lcp = IntList(initial_len=n) + + rank = IntList(initial_len=n) + for i from 0 <= i < n: + rank.arr[sa.sa.arr[i]] = i + + h = 0 + for i from 0 <= i < n: + k = rank.arr[i] + if k == 0: + self.lcp.arr[k] = -1 + else: + j = sa.sa.arr[k-1] + while i+h < n and j+h < n and sa.darray.data.arr[i+h] == sa.darray.data.arr[j+h]: + h = h+1 + self.lcp.arr[k] = h + if h > 0: + h = h-1 + logger.info("LCP array completed") + + def compute_stats(self, int max_n): + """Note: the output of this function is not exact. In + particular, the frequency associated with each word is + not guaranteed to be correct. This is due to a bit of + laxness in the design; the function is intended only to + obtain a list of the most frequent words; for this + purpose it is perfectly fine""" + cdef int i, ii, iii, j, k, h, n, N, rs, freq, valid + cdef IntList run_start + cdef IntList ngram_start + cdef VEB veb + + N = self.sa.sa.len + + ngram_starts = [] + for n from 0 <= n < max_n: + ngram_starts.append(IntList(initial_len=N)) + + run_start = IntList(initial_len=max_n) + veb = VEB(N) + + for i from 0 <= i < N: + h = self.lcp.arr[i] + if h < 0: + h = 0 + for n from h <= n < max_n: + rs = run_start.arr[n] + run_start.arr[n] = i + freq = i - rs + if freq > 1000: # arbitrary, but see note below + veb._insert(freq) + ngram_start = ngram_starts[n] + while ngram_start.arr[freq] > 0: + freq = freq + 1 # cheating a bit, should be ok for sparse histogram + ngram_start.arr[freq] = rs + i = veb.veb.min_val + while i != -1: + ii = veb._findsucc(i) + for n from 0 <= n < max_n: + ngram_start = ngram_starts[n] + iii = i + rs = ngram_start.arr[iii] + while (ii==-1 or iii < ii) and rs != 0: + j = self.sa.sa.arr[rs] + valid = 1 + for k from 0 <= k < n+1: + if self.sa.darray.data.arr[j+k] < 2: + valid = 0 + if valid: + ngram = tuple([self.sa.darray.data.arr[j+k] for k in range(n+1)]) + yield i, n+1, ngram + iii = iii + 1 + rs = ngram_start.arr[iii] + i = ii diff --git a/python/src/sa/precomputation.pxi b/python/src/sa/precomputation.pxi new file mode 100644 index 00000000..a3527f47 --- /dev/null +++ b/python/src/sa/precomputation.pxi @@ -0,0 +1,454 @@ +# precomputes a set of collocations by advancing over the text. +# warning: nasty C code + +from libc.stdio cimport FILE, fopen, fread, fwrite, fclose +from libc.stdlib cimport malloc, realloc, free +from libc.string cimport memset, memcpy + +cdef struct _Trie_Node # forward decl + +cdef struct _Trie_Edge: + int val + _Trie_Node* node + _Trie_Edge* bigger + _Trie_Edge* smaller + +cdef struct _Trie_Node: + _Trie_Edge* root + int* arr + int arr_len + +cdef _Trie_Node* new_trie_node(): + cdef _Trie_Node* node + node = <_Trie_Node*> malloc(sizeof(_Trie_Node)) + node.root = NULL + node.arr_len = 0 + node.arr = malloc(sizeof(0*sizeof(int))) + return node + +cdef _Trie_Edge* new_trie_edge(int val): + cdef _Trie_Edge* edge + edge = <_Trie_Edge*> malloc(sizeof(_Trie_Edge)) + edge.node = new_trie_node() + edge.bigger = NULL + edge.smaller = NULL + edge.val = val + return edge + +cdef free_trie_node(_Trie_Node* node): + if node != NULL: + free_trie_edge(node.root) + free(node.arr) + +cdef free_trie_edge(_Trie_Edge* edge): + if edge != NULL: + free_trie_node(edge.node) + free_trie_edge(edge.bigger) + free_trie_edge(edge.smaller) + +cdef _Trie_Node* trie_find(_Trie_Node* node, int val): + cdef _Trie_Edge* cur + cur = node.root + while cur != NULL and cur.val != val: + if val > cur.val: + cur = cur.bigger + elif val < cur.val: + cur = cur.smaller + if cur == NULL: + return NULL + else: + return cur.node + +cdef trie_node_data_append(_Trie_Node* node, int val): + cdef int new_len + new_len = node.arr_len + 1 + node.arr = realloc(node.arr, new_len*sizeof(int)) + node.arr[node.arr_len] = val + node.arr_len = new_len + +cdef trie_node_data_extend(_Trie_Node* node, int* vals, int num_vals): + cdef int new_len + new_len = node.arr_len + num_vals + node.arr = realloc(node.arr, new_len*sizeof(int)) + memcpy(node.arr + node.arr_len, vals, num_vals*sizeof(int)) + node.arr_len = new_len + + +cdef _Trie_Node* trie_insert(_Trie_Node* node, int val): + cdef _Trie_Edge** cur + cur = &node.root + while cur[0] != NULL and cur[0].val != val: + if val > cur[0].val: + cur = &cur[0].bigger + elif val < cur[0].val: + cur = &cur[0].smaller + if cur[0] == NULL: + cur[0] = new_trie_edge(val) + return cur[0].node + +cdef trie_node_to_map(_Trie_Node* node, result, prefix, int include_zeros): + cdef IntList arr + + if include_zeros or node.arr_len > 0: + arr = IntList() + free(arr.arr) + arr.arr = malloc(node.arr_len * sizeof(int)) + memcpy(arr.arr, node.arr, node.arr_len * sizeof(int)) + arr.len = node.arr_len + arr.size = node.arr_len + result[prefix] = arr + trie_edge_to_map(node.root, result, prefix, include_zeros) + +cdef trie_edge_to_map(_Trie_Edge* edge, result, prefix, int include_zeros): + if edge != NULL: + trie_edge_to_map(edge.smaller, result, prefix, include_zeros) + trie_edge_to_map(edge.bigger, result, prefix, include_zeros) + prefix = prefix + (edge.val,) + trie_node_to_map(edge.node, result, prefix, include_zeros) + +cdef class TrieMap: + + cdef _Trie_Node** root + cdef int V + + def __cinit__(self, int alphabet_size): + self.V = alphabet_size + self.root = <_Trie_Node**> malloc(self.V * sizeof(_Trie_Node*)) + memset(self.root, 0, self.V * sizeof(_Trie_Node*)) + + + def __dealloc__(self): + cdef int i + for i from 0 <= i < self.V: + if self.root[i] != NULL: + free_trie_node(self.root[i]) + free(self.root) + + + def insert(self, pattern): + cdef int* p + cdef int i, l + l = len(pattern) + p = malloc(l*sizeof(int)) + for i from 0 <= i < l: + p[i] = pattern[i] + self._insert(p,l) + free(p) + + + cdef _Trie_Node* _insert(self, int* pattern, int pattern_len): + cdef int i + cdef _Trie_Node* node + if self.root[pattern[0]] == NULL: + self.root[pattern[0]] = new_trie_node() + node = self.root[pattern[0]] + for i from 1 <= i < pattern_len: + node = trie_insert(node, pattern[i]) + return node + + def contains(self, pattern): + cdef int* p + cdef int i, l + cdef _Trie_Node* node + l = len(pattern) + p = malloc(l*sizeof(int)) + for i from 0 <= i < l: + p[i] = pattern[i] + node = self._contains(p,l) + free(p) + if node == NULL: + return False + else: + return True + + cdef _Trie_Node* _contains(self, int* pattern, int pattern_len): + cdef int i + cdef _Trie_Node* node + node = self.root[pattern[0]] + i = 1 + while node != NULL and i < pattern_len: + node = trie_find(node, pattern[i]) + i = i+1 + return node + + def toMap(self, flag): + cdef int i, include_zeros + + if flag: + include_zeros=1 + else: + include_zeros=0 + result = {} + for i from 0 <= i < self.V: + if self.root[i] != NULL: + trie_node_to_map(self.root[i], result, (i,), include_zeros) + return result + + +cdef class Precomputation: + cdef int precompute_rank + cdef int precompute_secondary_rank + cdef int max_length + cdef int max_nonterminals + cdef int train_max_initial_size + cdef int train_min_gap_size + cdef precomputed_index + cdef precomputed_collocations + cdef read_map(self, FILE* f) + cdef write_map(self, m, FILE* f) + + def __cinit__(self, fsarray=None, from_stats=None, from_binary=None, + precompute_rank=1000, precompute_secondary_rank=20, + max_length=5, max_nonterminals=2, + train_max_initial_size=10, train_min_gap_size=2): + self.precompute_rank = precompute_rank + self.precompute_secondary_rank = precompute_secondary_rank + self.max_length = max_length + self.max_nonterminals = max_nonterminals + self.train_max_initial_size = train_max_initial_size + self.train_min_gap_size = train_min_gap_size + if from_binary: + self.read_binary(from_binary) + elif from_stats: + self.precompute(from_stats, fsarray) + + + def read_binary(self, char* filename): + cdef FILE* f + f = fopen(filename, "r") + fread(&(self.precompute_rank), sizeof(int), 1, f) + fread(&(self.precompute_secondary_rank), sizeof(int), 1, f) + fread(&(self.max_length), sizeof(int), 1, f) + fread(&(self.max_nonterminals), sizeof(int), 1, f) + fread(&(self.train_max_initial_size), sizeof(int), 1, f) + fread(&(self.train_min_gap_size), sizeof(int), 1, f) + self.precomputed_index = self.read_map(f) + self.precomputed_collocations = self.read_map(f) + fclose(f) + + + def write_binary(self, char* filename): + cdef FILE* f + f = fopen(filename, "w") + fwrite(&(self.precompute_rank), sizeof(int), 1, f) + fwrite(&(self.precompute_secondary_rank), sizeof(int), 1, f) + fwrite(&(self.max_length), sizeof(int), 1, f) + fwrite(&(self.max_nonterminals), sizeof(int), 1, f) + fwrite(&(self.train_max_initial_size), sizeof(int), 1, f) + fwrite(&(self.train_min_gap_size), sizeof(int), 1, f) + self.write_map(self.precomputed_index, f) + self.write_map(self.precomputed_collocations, f) + fclose(f) + + + cdef write_map(self, m, FILE* f): + cdef int i, N + cdef IntList arr + + N = len(m) + fwrite(&(N), sizeof(int), 1, f) + for pattern, val in m.iteritems(): + N = len(pattern) + fwrite(&(N), sizeof(int), 1, f) + for word_id in pattern: + i = word_id + fwrite(&(i), sizeof(int), 1, f) + arr = val + arr.write_handle(f) + + + cdef read_map(self, FILE* f): + cdef int i, j, k, word_id, N + cdef IntList arr + + m = {} + fread(&(N), sizeof(int), 1, f) + for j from 0 <= j < N: + fread(&(i), sizeof(int), 1, f) + key = () + for k from 0 <= k < i: + fread(&(word_id), sizeof(int), 1, f) + key = key + (word_id,) + arr = IntList() + arr.read_handle(f) + m[key] = arr + return m + + + def precompute(self, stats, SuffixArray sarray): + cdef int i, l, N, max_pattern_len, i1, l1, i2, l2, i3, l3, ptr1, ptr2, ptr3, is_super, sent_count, max_rank + cdef DataArray darray = sarray.darray + cdef IntList data, queue, cost_by_rank, count_by_rank + cdef TrieMap frequent_patterns, super_frequent_patterns, collocations + cdef _Trie_Node* node + + data = darray.data + + frequent_patterns = TrieMap(len(darray.id2word)) + super_frequent_patterns = TrieMap(len(darray.id2word)) + collocations = TrieMap(len(darray.id2word)) + + I_set = set() + J_set = set() + J2_set = set() + IJ_set = set() + pattern_rank = {} + + logger.info("Precomputing frequent intersections") + cdef float start_time = monitor_cpu() + + max_pattern_len = 0 + for rank, (_, _, phrase) in enumerate(stats): + if rank >= self.precompute_rank: + break + max_pattern_len = max(max_pattern_len, len(phrase)) + frequent_patterns.insert(phrase) + I_set.add(phrase) + pattern_rank[phrase] = rank + if rank < self.precompute_secondary_rank: + super_frequent_patterns.insert(phrase) + J_set.add(phrase) + + queue = IntList(increment=1000) + + logger.info(" Computing inverted indexes...") + N = len(data) + for i from 0 <= i < N: + sa_word_id = data.arr[i] + if sa_word_id == 1: + queue._append(-1) + else: + for l from 1 <= l <= max_pattern_len: + node = frequent_patterns._contains(data.arr+i, l) + if node == NULL: + break + queue._append(i) + queue._append(l) + trie_node_data_append(node, i) + + logger.info(" Computing collocations...") + N = len(queue) + ptr1 = 0 + sent_count = 0 + while ptr1 < N: # main loop + i1 = queue.arr[ptr1] + if i1 > -1: + l1 = queue.arr[ptr1+1] + ptr2 = ptr1 + 2 + while ptr2 < N: + i2 = queue.arr[ptr2] + if i2 == -1 or i2 - i1 >= self.train_max_initial_size: + break + l2 = queue.arr[ptr2+1] + if (i2 - i1 - l1 >= self.train_min_gap_size and + i2 + l2 - i1 <= self.train_max_initial_size and + l1+l2+1 <= self.max_length): + node = collocations._insert(data.arr+i1, l1) + node = trie_insert(node, -1) + for i from i2 <= i < i2+l2: + node = trie_insert(node, data.arr[i]) + trie_node_data_append(node, i1) + trie_node_data_append(node, i2) + if super_frequent_patterns._contains(data.arr+i2, l2) != NULL: + if super_frequent_patterns._contains(data.arr+i1, l1) != NULL: + is_super = 1 + else: + is_super = 0 + ptr3 = ptr2 + 2 + while ptr3 < N: + i3 = queue.arr[ptr3] + if i3 == -1 or i3 - i1 >= self.train_max_initial_size: + break + l3 = queue.arr[ptr3+1] + if (i3 - i2 - l2 >= self.train_min_gap_size and + i3 + l3 - i1 <= self.train_max_initial_size and + l1+l2+l3+2 <= self.max_length): + if is_super or super_frequent_patterns._contains(data.arr+i3, l3) != NULL: + node = collocations._insert(data.arr+i1, l1) + node = trie_insert(node, -1) + for i from i2 <= i < i2+l2: + node = trie_insert(node, data.arr[i]) + node = trie_insert(node, -1) + for i from i3 <= i < i3+l3: + node = trie_insert(node, data.arr[i]) + trie_node_data_append(node, i1) + trie_node_data_append(node, i2) + trie_node_data_append(node, i3) + ptr3 = ptr3 + 2 + ptr2 = ptr2 + 2 + ptr1 = ptr1 + 2 + else: + sent_count = sent_count + 1 + if sent_count % 10000 == 0: + logger.debug(" %d sentences", sent_count) + ptr1 = ptr1 + 1 + + self.precomputed_collocations = collocations.toMap(False) + self.precomputed_index = frequent_patterns.toMap(True) + + x = 0 + for pattern1 in J_set: + for pattern2 in J_set: + if len(pattern1) + len(pattern2) + 1 < self.max_length: + combined_pattern = pattern1 + (-1,) + pattern2 + J2_set.add(combined_pattern) + + for pattern1 in I_set: + for pattern2 in I_set: + x = x+1 + if len(pattern1) + len(pattern2) + 1 <= self.max_length: + combined_pattern = pattern1 + (-1,) + pattern2 + IJ_set.add(combined_pattern) + + for pattern1 in I_set: + for pattern2 in J2_set: + x = x+2 + if len(pattern1) + len(pattern2) + 1<= self.max_length: + combined_pattern = pattern1 + (-1,) + pattern2 + IJ_set.add(combined_pattern) + combined_pattern = pattern2 + (-1,) + pattern1 + IJ_set.add(combined_pattern) + + N = len(pattern_rank) + cost_by_rank = IntList(initial_len=N) + count_by_rank = IntList(initial_len=N) + for pattern, arr in self.precomputed_collocations.iteritems(): + if pattern not in IJ_set: + s = "" + for word_id in pattern: + if word_id == -1: + s = s + "X " + else: + s = s + darray.id2word[word_id] + " " + logger.warn("ERROR: unexpected pattern %s in set of precomputed collocations", s) + else: + chunk = () + max_rank = 0 + arity = 0 + for word_id in pattern: + if word_id == -1: + max_rank = max(max_rank, pattern_rank[chunk]) + arity = arity + 1 + chunk = () + else: + chunk = chunk + (word_id,) + max_rank = max(max_rank, pattern_rank[chunk]) + cost_by_rank.arr[max_rank] = cost_by_rank.arr[max_rank] + (4*len(arr)) + count_by_rank.arr[max_rank] = count_by_rank.arr[max_rank] + (len(arr)/(arity+1)) + + cumul_cost = 0 + cumul_count = 0 + for i from 0 <= i < N: + cumul_cost = cumul_cost + cost_by_rank.arr[i] + cumul_count = cumul_count + count_by_rank.arr[i] + logger.debug("RANK %d\tCOUNT, COST: %d %d\tCUMUL: %d, %d", i, count_by_rank.arr[i], cost_by_rank.arr[i], cumul_count, cumul_cost) + + num_found_patterns = len(self.precomputed_collocations) + for pattern in IJ_set: + if pattern not in self.precomputed_collocations: + self.precomputed_collocations[pattern] = IntList() + + cdef float stop_time = monitor_cpu() + logger.info("Precomputed collocations for %d patterns out of %d possible (upper bound %d)", num_found_patterns, len(self.precomputed_collocations), x) + logger.info("Precomputed inverted index for %d patterns ", len(self.precomputed_index)) + logger.info("Precomputation took %f seconds", (stop_time - start_time)) diff --git a/python/src/sa/rule.pxi b/python/src/sa/rule.pxi new file mode 100644 index 00000000..9c34f66d --- /dev/null +++ b/python/src/sa/rule.pxi @@ -0,0 +1,241 @@ +from libc.stdlib cimport malloc, calloc, realloc, free, strtof, strtol +from libc.string cimport strsep, strcpy, strlen + +cdef class Phrase: + cdef int *syms + cdef int n, *varpos, n_vars + + def __cinit__(self, words): + cdef int i, j, n, n_vars + n_vars = 0 + n = len(words) + self.syms = malloc(n*sizeof(int)) + for i from 0 <= i < n: + self.syms[i] = words[i] + if ALPHABET.isvar(self.syms[i]): + n_vars += 1 + self.n = n + self.n_vars = n_vars + self.varpos = malloc(n_vars*sizeof(int)) + j = 0 + for i from 0 <= i < n: + if ALPHABET.isvar(self.syms[i]): + self.varpos[j] = i + j = j + 1 + + def __dealloc__(self): + free(self.syms) + free(self.varpos) + + def __str__(self): + strs = [] + cdef int i, s + for i from 0 <= i < self.n: + s = self.syms[i] + strs.append(ALPHABET.tostring(s)) + return " ".join(strs) + + def handle(self): + """return a hashable representation that normalizes the ordering + of the nonterminal indices""" + norm = [] + cdef int i, j, s + i = 1 + j = 0 + for j from 0 <= j < self.n: + s = self.syms[j] + if ALPHABET.isvar(s): + s = ALPHABET.setindex(s,i) + i = i + 1 + norm.append(s) + return tuple(norm) + + def strhandle(self): + strs = [] + norm = [] + cdef int i, j, s + i = 1 + j = 0 + for j from 0 <= j < self.n: + s = self.syms[j] + if ALPHABET.isvar(s): + s = ALPHABET.setindex(s,i) + i = i + 1 + norm.append(ALPHABET.tostring(s)) + return " ".join(norm) + + def arity(self): + return self.n_vars + + def getvarpos(self, i): + if 0 <= i < self.n_vars: + return self.varpos[i] + else: + raise IndexError + + def getvar(self, i): + if 0 <= i < self.n_vars: + return self.syms[self.varpos[i]] + else: + raise IndexError + + cdef int chunkpos(self, int k): + if k == 0: + return 0 + else: + return self.varpos[k-1]+1 + + cdef int chunklen(self, int k): + if self.n_vars == 0: + return self.n + elif k == 0: + return self.varpos[0] + elif k == self.n_vars: + return self.n-self.varpos[k-1]-1 + else: + return self.varpos[k]-self.varpos[k-1]-1 + + def clen(self, k): + return self.chunklen(k) + + def getchunk(self, ci): + cdef int start, stop + start = self.chunkpos(ci) + stop = start+self.chunklen(ci) + chunk = [] + for i from start <= i < stop: + chunk.append(self.syms[i]) + return chunk + + def __cmp__(self, other): + cdef Phrase otherp + cdef int i + otherp = other + for i from 0 <= i < min(self.n, otherp.n): + if self.syms[i] < otherp.syms[i]: + return -1 + elif self.syms[i] > otherp.syms[i]: + return 1 + if self.n < otherp.n: + return -1 + elif self.n > otherp.n: + return 1 + else: + return 0 + + def __hash__(self): + cdef int i + cdef unsigned h + h = 0 + for i from 0 <= i < self.n: + if self.syms[i] > 0: + h = (h << 1) + self.syms[i] + else: + h = (h << 1) + -self.syms[i] + return h + + def __len__(self): + return self.n + + def __getitem__(self, i): + return self.syms[i] + + def __iter__(self): + cdef int i + l = [] + for i from 0 <= i < self.n: + l.append(self.syms[i]) + return iter(l) + + def subst(self, start, children): + cdef int i + for i from 0 <= i < self.n: + if ALPHABET.isvar(self.syms[i]): + start = start + children[ALPHABET.getindex(self.syms[i])-1] + else: + start = start + (self.syms[i],) + return start + +cdef class Rule: + cdef public int lhs + cdef readonly Phrase f, e + cdef float *cscores + cdef int n_scores + cdef public word_alignments + + def __cinit__(self, int lhs, Phrase f, Phrase e, + scores=None, word_alignments=None): + cdef int i, n + cdef char *rest + + if not ALPHABET.isvar(lhs): + raise Exception('Invalid LHS symbol: %d' % lhs) + + self.lhs = lhs + self.f = f + self.e = e + + self.word_alignments = word_alignments + if scores is None: + self.cscores = NULL + self.n_scores = 0 + else: + n = len(scores) + self.cscores = malloc(n*sizeof(float)) + self.n_scores = n + for i from 0 <= i < n: + self.cscores[i] = scores[i] + + def __dealloc__(self): + if self.cscores != NULL: + free(self.cscores) + + def __hash__(self): + return hash((self.lhs, self.f, self.e)) + + def __cmp__(self, Rule other): + return cmp((self.lhs, self.f, self.e, self.word_alignments), (other.lhs, other.f, other.e, self.word_alignments)) + + def __iadd__(self, Rule other): + if self.n_scores != other.n_scores: + raise ValueError + for i from 0 <= i < self.n_scores: + self.cscores[i] = self.cscores[i] + other.cscores[i] + return self + + def fmerge(self, Phrase f): + if self.f == f: + self.f = f + + def arity(self): + return self.f.arity() + + def __str__(self): + scorestrs = [] + for i from 0 <= i < self.n_scores: + scorestrs.append(str(self.cscores[i])) + fields = [ALPHABET.tostring(self.lhs), str(self.f), str(self.e), " ".join(scorestrs)] + if self.word_alignments is not None: + alignstr = [] + for i from 0 <= i < len(self.word_alignments): + alignstr.append("%d-%d" % (self.word_alignments[i]/65536, self.word_alignments[i]%65536)) + #for s,t in self.word_alignments: + #alignstr.append("%d-%d" % (s,t)) + fields.append(" ".join(alignstr)) + + return " ||| ".join(fields) + + property scores: + def __get__(self): + s = [None]*self.n_scores + for i from 0 <= i < self.n_scores: + s[i] = self.cscores[i] + return s + + def __set__(self, s): + if self.cscores != NULL: + free(self.cscores) + self.cscores = malloc(len(s)*sizeof(float)) + self.n_scores = len(s) + for i from 0 <= i < self.n_scores: + self.cscores[i] = s[i] diff --git a/python/src/sa/rulefactory.pxi b/python/src/sa/rulefactory.pxi new file mode 100644 index 00000000..24bb680f --- /dev/null +++ b/python/src/sa/rulefactory.pxi @@ -0,0 +1,1794 @@ +# Implementation of the algorithms described in +# Lopez, EMNLP-CoNLL 2007 +# Much faster than the Python numbers reported there. +# Note to reader: this code is closer to C than Python +import gc + +from libc.stdlib cimport malloc, realloc, free +from libc.string cimport memset, memcpy +from libc.math cimport fmod, ceil, floor, log + +cdef int PRECOMPUTE = 0 +cdef int MERGE = 1 +cdef int BAEZA_YATES = 2 + +# NOTE: was encoded as a non-terminal in the previous version +cdef int EPSILON = sym_fromstring('*EPS*', True) + +cdef class TrieNode: + cdef public children + + def __cinit__(self): + self.children = {} + +cdef class ExtendedTrieNode(TrieNode): + cdef public phrase + cdef public phrase_location + cdef public suffix_link + + def __cinit__(self, phrase=None, phrase_location=None, suffix_link=None): + self.phrase = phrase + self.phrase_location = phrase_location + self.suffix_link = suffix_link + + +cdef class TrieTable: + cdef public int extended + cdef public int count + cdef public root + def __cinit__(self, extended=False): + self.count = 0 + self.extended = extended + if extended: + self.root = ExtendedTrieNode() + else: + self.root = TrieNode() + +# linked list structure for storing matches in BaselineRuleFactory +cdef struct match_node: + int* match + match_node* next + +# encodes information needed to find a (hierarchical) phrase +# in the text. If phrase is contiguous, that's just a range +# in the suffix array; if discontiguous, it is the set of +# actual locations (packed into an array) +cdef class PhraseLocation: + cdef int sa_low + cdef int sa_high + cdef int arr_low + cdef int arr_high + cdef IntList arr + cdef int num_subpatterns + + # returns true if sent_id is contained + cdef int contains(self, int sent_id): + return 1 + + def __cinit__(self, int sa_low=-1, int sa_high=-1, int arr_low=-1, int arr_high=-1, + arr=None, int num_subpatterns=1): + self.sa_low = sa_low + self.sa_high = sa_high + self.arr_low = arr_low + self.arr_high = arr_high + self.arr = arr + self.num_subpatterns = num_subpatterns + + + +cdef class Sampler: + '''A Sampler implements a logic for choosing + samples from a population range''' + + cdef int sample_size + cdef IntList sa + + def __cinit__(self, int sample_size, SuffixArray fsarray): + self.sample_size = sample_size + self.sa = fsarray.sa + if sample_size > 0: + logger.info("Sampling strategy: uniform, max sample size = %d", sample_size) + else: + logger.info("Sampling strategy: no sampling") + + def sample(self, PhraseLocation phrase_location): + '''Returns a sample of the locations for + the phrase. If there are less than self.sample_size + locations, return all of them; otherwise, return + up to self.sample_size locations. In the latter case, + we choose to sample UNIFORMLY -- that is, the locations + are chosen at uniform intervals over the entire set, rather + than randomly. This makes the algorithm deterministic, which + is good for things like MERT''' + cdef IntList sample + cdef double i, stepsize + cdef int num_locations, val, j + + sample = IntList() + if phrase_location.arr is None: + num_locations = phrase_location.sa_high - phrase_location.sa_low + if self.sample_size == -1 or num_locations <= self.sample_size: + sample._extend_arr(self.sa.arr + phrase_location.sa_low, num_locations) + else: + stepsize = float(num_locations)/float(self.sample_size) + i = phrase_location.sa_low + while i < phrase_location.sa_high and sample.len < self.sample_size: + '''Note: int(i) not guaranteed to have the desired + effect, according to the python documentation''' + if fmod(i,1.0) > 0.5: + val = int(ceil(i)) + else: + val = int(floor(i)) + sample._append(self.sa.arr[val]) + i = i + stepsize + else: + num_locations = (phrase_location.arr_high - phrase_location.arr_low) / phrase_location.num_subpatterns + if self.sample_size == -1 or num_locations <= self.sample_size: + sample = phrase_location.arr + else: + stepsize = float(num_locations)/float(self.sample_size) + i = phrase_location.arr_low + while i < num_locations and sample.len < self.sample_size * phrase_location.num_subpatterns: + '''Note: int(i) not guaranteed to have the desired + effect, according to the python documentation''' + if fmod(i,1.0) > 0.5: + val = int(ceil(i)) + else: + val = int(floor(i)) + j = phrase_location.arr_low + (val*phrase_location.num_subpatterns) + sample._extend_arr(phrase_location.arr.arr + j, phrase_location.num_subpatterns) + i = i + stepsize + return sample + + +# struct used to encapsulate a single matching +cdef struct Matching: + int* arr + int start + int end + int sent_id + int size + + +cdef void assign_matching(Matching* m, int* arr, int start, int step, int* sent_id_arr): + m.arr = arr + m.start = start + m.end = start + step + m.sent_id = sent_id_arr[arr[start]] + m.size = step + + +cdef int* append_combined_matching(int* arr, Matching* loc1, Matching* loc2, + int offset_by_one, int num_subpatterns, int* result_len): + cdef int i, new_len + + new_len = result_len[0] + num_subpatterns + arr = realloc(arr, new_len*sizeof(int)) + + for i from 0 <= i < loc1.size: + arr[result_len[0]+i] = loc1.arr[loc1.start+i] + if num_subpatterns > loc1.size: + arr[new_len-1] = loc2.arr[loc2.end-1] + result_len[0] = new_len + return arr + + +cdef int* extend_arr(int* arr, int* arr_len, int* appendix, int appendix_len): + cdef int new_len + + new_len = arr_len[0] + appendix_len + arr = realloc(arr, new_len*sizeof(int)) + memcpy(arr+arr_len[0], appendix, appendix_len*sizeof(int)) + arr_len[0] = new_len + return arr + +cdef int median(int low, int high, int step): + return low + (((high - low)/step)/2)*step + + +cdef void find_comparable_matchings(int low, int high, int* arr, int step, int loc, int* loc_minus, int* loc_plus): + # Returns (minus, plus) indices for the portion of the array + # in which all matchings have the same first index as the one + # starting at loc + loc_plus[0] = loc + step + while loc_plus[0] < high and arr[loc_plus[0]] == arr[loc]: + loc_plus[0] = loc_plus[0] + step + loc_minus[0] = loc + while loc_minus[0]-step >= low and arr[loc_minus[0]-step] == arr[loc]: + loc_minus[0] = loc_minus[0] - step + + +cdef class HieroCachingRuleFactory: + '''This RuleFactory implements a caching + method using TrieTable, which makes phrase + generation somewhat speedier -- phrases only + need to be extracted once (however, it is + quite possible they need to be scored + for each input sentence, for contextual models)''' + + cdef TrieTable rules + cdef Sampler sampler + + cdef int max_chunks + cdef int max_target_chunks + cdef int max_length + cdef int max_target_length + cdef int max_nonterminals + cdef int max_initial_size + cdef int train_max_initial_size + cdef int min_gap_size + cdef int train_min_gap_size + cdef int category + + cdef precomputed_index + cdef precomputed_collocations + cdef precompute_file + cdef max_rank + cdef int precompute_rank, precompute_secondary_rank + cdef bint use_baeza_yates + cdef bint use_index + cdef bint use_collocations + cdef float by_slack_factor + + cdef prev_norm_prefix + cdef float extract_time + cdef SuffixArray fsa + cdef DataArray fda + cdef DataArray eda + + cdef Alignment alignment + cdef IntList eid2symid + cdef IntList fid2symid + cdef int tight_phrases + cdef int require_aligned_terminal + cdef int require_aligned_chunks + + cdef IntList findexes + cdef IntList findexes1 + + def __cinit__(self, + # compiled alignment object (REQUIRED) + Alignment alignment, + # parameter for double-binary search; doesn't seem to matter much + float by_slack_factor=1.0, + # name of generic nonterminal used by Hiero + char* category="[X]", + # maximum number of contiguous chunks of terminal symbols in RHS of a rule. If None, defaults to max_nonterminals+1 + max_chunks=None, + # maximum span of a grammar rule in TEST DATA + unsigned max_initial_size=10, + # maximum number of symbols (both T and NT) allowed in a rule + unsigned max_length=5, + # maximum number of nonterminals allowed in a rule (set >2 at your own risk) + unsigned max_nonterminals=2, + # maximum number of contiguous chunks of terminal symbols in target-side RHS of a rule. If None, defaults to max_nonterminals+1 + max_target_chunks=None, + # maximum number of target side symbols (both T and NT) allowed in a rule. If None, defaults to max_initial_size + max_target_length=None, + # minimum span of a nonterminal in the RHS of a rule in TEST DATA + unsigned min_gap_size=2, + # filename of file containing precomputed collocations + precompute_file=None, + # maximum frequency rank of patterns used to compute triples (don't set higher than 20). + unsigned precompute_secondary_rank=20, + # maximum frequency rank of patterns used to compute collocations (no need to set higher than maybe 200-300) + unsigned precompute_rank=100, + # require extracted rules to have at least one aligned word + bint require_aligned_terminal=True, + # require each contiguous chunk of extracted rules to have at least one aligned word + bint require_aligned_chunks=False, + # maximum span of a grammar rule extracted from TRAINING DATA + unsigned train_max_initial_size=10, + # minimum span of an RHS nonterminal in a rule extracted from TRAINING DATA + unsigned train_min_gap_size=2, + # True if phrases should be tight, False otherwise (False == slower but better results) + bint tight_phrases=False, + # True to require use of double-binary alg, false otherwise + bint use_baeza_yates=True, + # True to enable used of precomputed collocations + bint use_collocations=True, + # True to enable use of precomputed inverted indices + bint use_index=True): + '''Note: we make a distinction between the min_gap_size + and max_initial_size used in test and train. The latter + are represented by train_min_gap_size and train_max_initial_size, + respectively. This is because Chiang's model does not require + them to be the same, therefore we don't either.''' + self.rules = TrieTable(True) # cache + self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) + if alignment is None: + raise Exception("Must specify an alignment object") + self.alignment = alignment + + # grammar parameters and settings + # NOTE: setting max_nonterminals > 2 is not currently supported in Hiero + self.max_length = max_length + self.max_nonterminals = max_nonterminals + self.max_initial_size = max_initial_size + self.train_max_initial_size = train_max_initial_size + self.min_gap_size = min_gap_size + self.train_min_gap_size = train_min_gap_size + self.category = sym_fromstring(category, False) + + if max_chunks is None: + self.max_chunks = self.max_nonterminals + 1 + else: + self.max_chunks = max_chunks + + if max_target_chunks is None: + self.max_target_chunks = self.max_nonterminals + 1 + else: + self.max_target_chunks = max_target_chunks + + if max_target_length is None: + self.max_target_length = max_initial_size + else: + self.max_target_length = max_target_length + + # algorithmic parameters and settings + self.precomputed_collocations = {} + self.precomputed_index = {} + self.use_index = use_index + self.use_collocations = use_collocations + self.max_rank = {} + self.precompute_file = precompute_file + self.precompute_rank = precompute_rank + self.precompute_secondary_rank = precompute_secondary_rank + self.use_baeza_yates = use_baeza_yates + self.by_slack_factor = by_slack_factor + if tight_phrases: + self.tight_phrases = 1 + else: + self.tight_phrases = 0 + + if require_aligned_chunks: + # one condition is a stronger version of the other. + self.require_aligned_chunks = 1 + self.require_aligned_terminal = 1 + elif require_aligned_terminal: + self.require_aligned_chunks = 0 + self.require_aligned_terminal = 1 + else: + self.require_aligned_chunks = 0 + self.require_aligned_terminal = 0 + + + # diagnostics + self.prev_norm_prefix = () + + self.findexes = IntList(initial_len=10) + self.findexes1 = IntList(initial_len=10) + + def configure(self, SuffixArray fsarray, DataArray edarray, Sampler sampler): + '''This gives the RuleFactory access to the Context object. + Here we also use it to precompute the most expensive intersections + in the corpus quickly.''' + self.fsa = fsarray + self.fda = fsarray.darray + self.eda = edarray + self.fid2symid = self.set_idmap(self.fda) + self.eid2symid = self.set_idmap(self.eda) + self.precompute() + self.sampler = sampler + + cdef set_idmap(self, DataArray darray): + cdef int word_id, new_word_id, N + cdef IntList idmap + + N = len(darray.id2word) + idmap = IntList(initial_len=N) + for word_id from 0 <= word_id < N: + new_word_id = sym_fromstring(darray.id2word[word_id], True) + idmap.arr[word_id] = new_word_id + return idmap + + + def pattern2phrase(self, pattern): + # pattern is a tuple, which we must convert to a hiero Phrase + result = () + arity = 0 + for word_id in pattern: + if word_id == -1: + arity = arity + 1 + new_id = sym_setindex(self.category, arity) + else: + new_id = sym_fromstring(self.fda.id2word[word_id], True) + result = result + (new_id,) + return Phrase(result) + + def pattern2phrase_plus(self, pattern): + # returns a list containing both the pattern, and pattern + # suffixed/prefixed with the NT category. + patterns = [] + result = () + arity = 0 + for word_id in pattern: + if word_id == -1: + arity = arity + 1 + new_id = sym_setindex(self.category, arity) + else: + new_id = sym_fromstring(self.fda.id2word[word_id], True) + result = result + (new_id,) + patterns.append(Phrase(result)) + patterns.append(Phrase(result + (sym_setindex(self.category, 1),))) + patterns.append(Phrase((sym_setindex(self.category, 1),) + result)) + return patterns + + def precompute(self): + cdef Precomputation pre + + if self.precompute_file is not None: + start_time = monitor_cpu() + logger.info("Reading precomputed data from file %s... ", self.precompute_file) + pre = Precomputation(from_binary=self.precompute_file) + # check parameters of precomputation -- some are critical and some are not + if pre.max_nonterminals != self.max_nonterminals: + logger.warn("Precomputation done with max nonterminals %d, decoder uses %d", pre.max_nonterminals, self.max_nonterminals) + if pre.max_length != self.max_length: + logger.warn("Precomputation done with max terminals %d, decoder uses %d", pre.max_length, self.max_length) + if pre.train_max_initial_size != self.train_max_initial_size: + raise Exception("Precomputation done with max initial size %d, decoder uses %d" % (pre.train_max_initial_size, self.train_max_initial_size)) + if pre.train_min_gap_size != self.train_min_gap_size: + raise Exception("Precomputation done with min gap size %d, decoder uses %d" % (pre.train_min_gap_size, self.train_min_gap_size)) + if self.use_index: + logger.info("Converting %d hash keys on precomputed inverted index... ", len(pre.precomputed_index)) + for pattern, arr in pre.precomputed_index.iteritems(): + phrases = self.pattern2phrase_plus(pattern) + for phrase in phrases: + self.precomputed_index[phrase] = arr + if self.use_collocations: + logger.info("Converting %d hash keys on precomputed collocations... ", len(pre.precomputed_collocations)) + for pattern, arr in pre.precomputed_collocations.iteritems(): + phrase = self.pattern2phrase(pattern) + self.precomputed_collocations[phrase] = arr + stop_time = monitor_cpu() + logger.info("Processing precomputations took %f seconds", stop_time - start_time) + + + def get_precomputed_collocation(self, phrase): + if phrase in self.precomputed_collocations: + arr = self.precomputed_collocations[phrase] + return PhraseLocation(arr=arr, arr_low=0, arr_high=len(arr), num_subpatterns=phrase.arity()+1) + return None + + + cdef int* baeza_yates_helper(self, int low1, int high1, int* arr1, int step1, + int low2, int high2, int* arr2, int step2, + int offset_by_one, int len_last, int num_subpatterns, int* result_len): + cdef int i1, i2, j1, j2, med1, med2, med1_plus, med1_minus, med2_minus, med2_plus + cdef int d_first, qsetsize, dsetsize, tmp, search_low, search_high + cdef int med_result_len, low_result_len, high_result_len + cdef long comparison + cdef int* result + cdef int* low_result + cdef int* med_result + cdef int* high_result + cdef Matching loc1, loc2 + + result = malloc(0*sizeof(int*)) + + d_first = 0 + if high1 - low1 > high2 - low2: + d_first = 1 + + # First, check to see if we are at any of the recursive base cases + # Case 1: one of the sets is empty + if low1 >= high1 or low2 >= high2: + return result + + # Case 2: sets are non-overlapping + assign_matching(&loc1, arr1, high1-step1, step1, self.fda.sent_id.arr) + assign_matching(&loc2, arr2, low2, step2, self.fda.sent_id.arr) + if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == -1: + return result + + assign_matching(&loc1, arr1, low1, step1, self.fda.sent_id.arr) + assign_matching(&loc2, arr2, high2-step2, step2, self.fda.sent_id.arr) + if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: + return result + + # Case 3: query set and data set do not meet size mismatch constraints; + # We use mergesort instead in this case + qsetsize = (high1-low1) / step1 + dsetsize = (high2-low2) / step2 + if d_first: + tmp = qsetsize + qsetsize = dsetsize + dsetsize = tmp + + if self.by_slack_factor * qsetsize * log(dsetsize) / log(2) > dsetsize: + free(result) + return self.merge_helper(low1, high1, arr1, step1, low2, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, result_len) + + # binary search. There are two flavors, depending on + # whether the queryset or dataset is first + if d_first: + med2 = median(low2, high2, step2) + assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) + + search_low = low1 + search_high = high1 + while search_low < search_high: + med1 = median(search_low, search_high, step1) + find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) + comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) + if comparison == -1: + search_low = med1_plus + elif comparison == 1: + search_high = med1_minus + else: + break + else: + med1 = median(low1, high1, step1) + find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) + + search_low = low2 + search_high = high2 + while search_low < search_high: + med2 = median(search_low, search_high, step2) + assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) + comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) + if comparison == -1: + search_high = med2 + elif comparison == 1: + search_low = med2 + step2 + else: + break + + med_result_len = 0 + med_result = malloc(0*sizeof(int*)) + if search_high > search_low: + # Then there is a match for the median element of Q + # What we want to find is the group of all bindings in the first set + # s.t. their first element == the first element of med1. Then we + # want to store the bindings for all of those elements. We can + # subsequently throw all of them away. + med2_minus = med2 + med2_plus = med2 + step2 + i1 = med1_minus + while i1 < med1_plus: + assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + while med2_minus-step2 >= low2: + assign_matching(&loc2, arr2, med2_minus-step2, step2, self.fda.sent_id.arr) + if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) < 1: + med2_minus = med2_minus - step2 + else: + break + i2 = med2_minus + while i2 < high2: + assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) + comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) + if comparison == 0: + pass + med_result = append_combined_matching(med_result, &loc1, &loc2, offset_by_one, num_subpatterns, &med_result_len) + if comparison == -1: + break + i2 = i2 + step2 + if i2 > med2_plus: + med2_plus = i2 + i1 = i1 + step1 + + tmp = med1_minus + med1_minus = med1_plus + med1_plus = tmp + else: + # No match; need to figure out the point of division in D and Q + med2_minus = med2 + med2_plus = med2 + if d_first: + med2_minus = med2_minus + step2 + if comparison == -1: + med1_minus = med1_plus + if comparison == 1: + med1_plus = med1_minus + else: + tmp = med1_minus + med1_minus = med1_plus + med1_plus = tmp + if comparison == 1: + med2_minus = med2_minus + step2 + med2_plus = med2_plus + step2 + + low_result_len = 0 + low_result = self.baeza_yates_helper(low1, med1_plus, arr1, step1, low2, med2_plus, arr2, step2, offset_by_one, len_last, num_subpatterns, &low_result_len) + high_result_len = 0 + high_result = self.baeza_yates_helper(med1_minus, high1, arr1, step1, med2_minus, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, &high_result_len) + + result = extend_arr(result, result_len, low_result, low_result_len) + result = extend_arr(result, result_len, med_result, med_result_len) + result = extend_arr(result, result_len, high_result, high_result_len) + free(low_result) + free(med_result) + free(high_result) + + return result + + + + cdef long compare_matchings_set(self, int i1_minus, int i1_plus, int* arr1, int step1, + Matching* loc2, int offset_by_one, int len_last): + """ + Compares a *set* of bindings, all with the same first element, + to a single binding. Returns -1 if all comparisons == -1, 1 if all + comparisons == 1, and 0 otherwise. + """ + cdef int i1, comparison, prev_comparison + cdef Matching l1_stack + cdef Matching* loc1 + + loc1 = &l1_stack + + i1 = i1_minus + while i1 < i1_plus: + assign_matching(loc1, arr1, i1, step1, self.fda.sent_id.arr) + comparison = self.compare_matchings(loc1, loc2, offset_by_one, len_last) + if comparison == 0: + prev_comparison = 0 + break + elif i1 == i1_minus: + prev_comparison = comparison + else: + if comparison != prev_comparison: + prev_comparison = 0 + break + i1 = i1 + step1 + return prev_comparison + + + cdef long compare_matchings(self, Matching* loc1, Matching* loc2, int offset_by_one, int len_last): + cdef int i + + if loc1.sent_id > loc2.sent_id: + return 1 + if loc2.sent_id > loc1.sent_id: + return -1 + + if loc1.size == 1 and loc2.size == 1: + if loc2.arr[loc2.start] - loc1.arr[loc1.start] <= self.train_min_gap_size: + return 1 + + elif offset_by_one: + for i from 1 <= i < loc1.size: + if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i-1]: + return 1 + if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i-1]: + return -1 + + else: + if loc1.arr[loc1.start]+1 > loc2.arr[loc2.start]: + return 1 + if loc1.arr[loc1.start]+1 < loc2.arr[loc2.start]: + return -1 + + for i from 1 <= i < loc1.size: + if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i]: + return 1 + if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i]: + return -1 + + if loc2.arr[loc2.end-1] + len_last - loc1.arr[loc1.start] > self.train_max_initial_size: + return -1 + return 0 + + + cdef int* merge_helper(self, int low1, int high1, int* arr1, int step1, + int low2, int high2, int* arr2, int step2, + int offset_by_one, int len_last, int num_subpatterns, int* result_len): + cdef int i1, i2, j1, j2 + cdef long comparison + cdef int* result + cdef Matching loc1, loc2 + + result_len[0] = 0 + result = malloc(0*sizeof(int)) + + i1 = low1 + i2 = low2 + while i1 < high1 and i2 < high2: + + # First, pop all unneeded loc2's off the stack + assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + while i2 < high2: + assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) + if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: + i2 = i2 + step2 + else: + break + + # Next: process all loc1's with the same starting val + j1 = i1 + while i1 < high1 and arr1[j1] == arr1[i1]: + assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + j2 = i2 + while j2 < high2: + assign_matching(&loc2, arr2, j2, step2, self.fda.sent_id.arr) + comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) + if comparison == 0: + result = append_combined_matching(result, &loc1, &loc2, offset_by_one, num_subpatterns, result_len) + if comparison == 1: + pass + if comparison == -1: + break + else: + j2 = j2 + step2 + i1 = i1 + step1 + return result + + + cdef void sort_phrase_loc(self, IntList arr, PhraseLocation loc, Phrase phrase): + cdef int i, j + cdef VEB veb + cdef IntList result + + if phrase in self.precomputed_index: + loc.arr = self.precomputed_index[phrase] + else: + loc.arr = IntList(initial_len=loc.sa_high-loc.sa_low) + veb = VEB(arr.len) + for i from loc.sa_low <= i < loc.sa_high: + veb._insert(arr.arr[i]) + i = veb.veb.min_val + for j from 0 <= j < loc.sa_high-loc.sa_low: + loc.arr.arr[j] = i + i = veb._findsucc(i) + loc.arr_low = 0 + loc.arr_high = loc.arr.len + + + cdef intersect_helper(self, Phrase prefix, Phrase suffix, + PhraseLocation prefix_loc, PhraseLocation suffix_loc, int algorithm): + + cdef IntList arr1, arr2, result + cdef int low1, high1, step1, low2, high2, step2, offset_by_one, len_last, num_subpatterns, result_len + cdef int* result_ptr + + result_len = 0 + + if sym_isvar(suffix[0]): + offset_by_one = 1 + else: + offset_by_one = 0 + + len_last = len(suffix.getchunk(suffix.arity())) + + if prefix_loc.arr is None: + self.sort_phrase_loc(self.fsa.sa, prefix_loc, prefix) + arr1 = prefix_loc.arr + low1 = prefix_loc.arr_low + high1 = prefix_loc.arr_high + step1 = prefix_loc.num_subpatterns + + if suffix_loc.arr is None: + self.sort_phrase_loc(self.fsa.sa, suffix_loc, suffix) + arr2 = suffix_loc.arr + low2 = suffix_loc.arr_low + high2 = suffix_loc.arr_high + step2 = suffix_loc.num_subpatterns + + num_subpatterns = prefix.arity()+1 + + if algorithm == MERGE: + result_ptr = self.merge_helper(low1, high1, arr1.arr, step1, + low2, high2, arr2.arr, step2, + offset_by_one, len_last, num_subpatterns, &result_len) + else: + result_ptr = self.baeza_yates_helper(low1, high1, arr1.arr, step1, + low2, high2, arr2.arr, step2, + offset_by_one, len_last, num_subpatterns, &result_len) + + if result_len == 0: + free(result_ptr) + return None + else: + result = IntList() + free(result.arr) + result.arr = result_ptr + result.len = result_len + result.size = result_len + return PhraseLocation(arr_low=0, arr_high=result_len, arr=result, num_subpatterns=num_subpatterns) + + cdef loc2str(self, PhraseLocation loc): + cdef int i, j + result = "{" + i = 0 + while i < loc.arr_high: + result = result + "(" + for j from i <= j < i + loc.num_subpatterns: + result = result + ("%d " %loc.arr[j]) + result = result + ")" + i = i + loc.num_subpatterns + result = result + "}" + return result + + cdef PhraseLocation intersect(self, prefix_node, suffix_node, Phrase phrase): + cdef Phrase prefix, suffix + cdef PhraseLocation prefix_loc, suffix_loc, result + + prefix = prefix_node.phrase + suffix = suffix_node.phrase + prefix_loc = prefix_node.phrase_location + suffix_loc = suffix_node.phrase_location + + result = self.get_precomputed_collocation(phrase) + if result is not None: + intersect_method = "precomputed" + + if result is None: + if self.use_baeza_yates: + result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, BAEZA_YATES) + intersect_method="double binary" + else: + result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, MERGE) + intersect_method="merge" + return result + + def advance(self, frontier, res, fwords): + cdef unsigned na + nf = [] + for (toskip, (i, alt, pathlen)) in frontier: + spanlen = fwords[i][alt][2] + if (toskip == 0): + res.append((i, alt, pathlen)) + ni = i + spanlen + if (ni < len(fwords) and (pathlen + 1) < self.max_initial_size): + for na in range(len(fwords[ni])): + nf.append((toskip - 1, (ni, na, pathlen + 1))) + if (len(nf) > 0): + return self.advance(nf, res, fwords) + else: + return res + + def get_all_nodes_isteps_away(self, skip, i, spanlen, pathlen, fwords, next_states, reachable_buffer): + cdef unsigned alt_it + frontier = [] + if (i+spanlen+skip >= len(next_states)): + return frontier + key = tuple([i,spanlen]) + reachable = [] + if (key in reachable_buffer): + reachable = reachable_buffer[key] + else: + reachable = self.reachable(fwords, i, spanlen) + reachable_buffer[key] = reachable + for nextreachable in reachable: + for next_id in next_states[nextreachable]: + jump = self.shortest(fwords,i,next_id) + if jump < skip: + continue + if pathlen+jump <= self.max_initial_size: + for alt_id in range(len(fwords[next_id])): + if (fwords[next_id][alt_id][0] != EPSILON): + newel = (next_id,alt_id,pathlen+jump) + if newel not in frontier: + frontier.append((next_id,alt_id,pathlen+jump)) + return frontier + + def reachable(self, fwords, ifrom, dist): + ret = [] + if (ifrom >= len(fwords)): + return ret + for alt_id in range(len(fwords[ifrom])): + if (fwords[ifrom][alt_id][0] == EPSILON): + ret.extend(self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist)) + else: + if (dist==0): + if (ifrom not in ret): + ret.append(ifrom) + else: + for ifromchild in self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist-1): + if (ifromchild not in ret): + ret.append(ifromchild) + + return ret + + def shortest(self, fwords, ifrom, ito): + cdef unsigned alt_id + min = 1000 + if (ifrom > ito): + return min + if (ifrom == ito): + return 0 + for alt_id in range(len(fwords[ifrom])): + currmin = self.shortest(fwords,ifrom+fwords[ifrom][alt_id][2],ito) + if (fwords[ifrom][alt_id][0] != EPSILON): + currmin += 1 + if (currmin 0: + curr = candidate.pop() + if curr[0] >= len(_columns): + continue + if curr[0] not in result and min_dist <= curr[1] <= self.max_initial_size: + result.append(curr[0]); + curr_col = _columns[curr[0]] + for alt in curr_col: + next_id = curr[0]+alt[2] + jump = 1 + if (alt[0] == EPSILON): + jump = 0 + if next_id not in result and min_dist <= curr[1]+jump <= self.max_initial_size+1: + candidate.append([next_id,curr[1]+jump]) + return sorted(result); + + def input(self, fwords, models): + '''When this function is called on the RuleFactory, + it looks up all of the rules that can be used to translate + the input sentence''' + cdef int i, j, k, flen, arity, num_subpatterns, num_samples, alt, alt_id, nualt + cdef float start_time + cdef PhraseLocation phrase_location + cdef IntList sample, chunklen + cdef Matching matching + cdef Phrase hiero_phrase + + flen = len(fwords) + start_time = monitor_cpu() + self.extract_time = 0.0 + nodes_isteps_away_buffer = {} + hit = 0 + reachable_buffer = {} + + # Do not cache between sentences + self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) + + frontier = [] + for i in range(len(fwords)): + for alt in range(0, len(fwords[i])): + if fwords[i][alt][0] != EPSILON: + frontier.append((i, i, alt, 0, self.rules.root, (), False)) + + xroot = None + x1 = sym_setindex(self.category, 1) + if x1 in self.rules.root.children: + xroot = self.rules.root.children[x1] + else: + xroot = ExtendedTrieNode(suffix_link=self.rules.root, phrase_location=PhraseLocation()) + self.rules.root.children[x1] = xroot + + for i in range(self.min_gap_size, len(fwords)): + for alt in range(0, len(fwords[i])): + if fwords[i][alt][0] != EPSILON: + frontier.append((i-self.min_gap_size, i, alt, self.min_gap_size, xroot, (x1,), True)) + + next_states = [] + for i in range(len(fwords)): + next_states.append(self.get_next_states(fwords,i,self.min_gap_size)) + + while len(frontier) > 0: + new_frontier = [] + for k, i, alt, pathlen, node, prefix, is_shadow_path in frontier: + word_id = fwords[i][alt][0] + spanlen = fwords[i][alt][2] + # TODO get rid of k -- pathlen is replacing it + if word_id == EPSILON: + # skipping because word_id is epsilon + if i+spanlen >= len(fwords): + continue + for nualt in range(0,len(fwords[i+spanlen])): + frontier.append((k, i+spanlen, nualt, pathlen, node, prefix, is_shadow_path)) + continue + + phrase = prefix + (word_id,) + str_phrase = map(sym_tostring, phrase) + hiero_phrase = Phrase(phrase) + arity = hiero_phrase.arity() + + lookup_required = False + if word_id in node.children: + if node.children[word_id] is None: + # Path dead-ends at this node + continue + else: + # Path continues at this node + node = node.children[word_id] + else: + if node.suffix_link is None: + # Current node is root; lookup required + lookup_required = True + else: + if word_id in node.suffix_link.children: + if node.suffix_link.children[word_id] is None: + # Suffix link reports path is dead end + node.children[word_id] = None + continue + else: + # Suffix link indicates lookup is reqired + lookup_required = True + else: + #ERROR: We never get here + raise Exception("Keyword trie error") + # checking whether lookup_required + if lookup_required: + new_node = None + if is_shadow_path: + # Extending shadow path + # on the shadow path we don't do any search, we just use info from suffix link + new_node = ExtendedTrieNode(phrase_location=node.suffix_link.children[word_id].phrase_location, + suffix_link=node.suffix_link.children[word_id], + phrase=hiero_phrase) + else: + if arity > 0: + # Intersecting because of arity > 0 + phrase_location = self.intersect(node, node.suffix_link.children[word_id], hiero_phrase) + else: + # Suffix array search + phrase_location = node.phrase_location + sa_range = self.fsa.lookup(str_phrase[-1], len(str_phrase)-1, phrase_location.sa_low, phrase_location.sa_high) + if sa_range is not None: + phrase_location = PhraseLocation(sa_low=sa_range[0], sa_high=sa_range[1]) + else: + phrase_location = None + + if phrase_location is None: + node.children[word_id] = None + # Search failed + continue + # Search succeeded + suffix_link = self.rules.root + if node.suffix_link is not None: + suffix_link = node.suffix_link.children[word_id] + new_node = ExtendedTrieNode(phrase_location=phrase_location, + suffix_link=suffix_link, + phrase=hiero_phrase) + node.children[word_id] = new_node + node = new_node + + '''Automatically add a trailing X node, if allowed -- + This should happen before we get to extraction (so that + the node will exist if needed)''' + if arity < self.max_nonterminals: + xcat_index = arity+1 + xcat = sym_setindex(self.category, xcat_index) + suffix_link_xcat_index = xcat_index + if is_shadow_path: + suffix_link_xcat_index = xcat_index-1 + suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) + node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, + suffix_link=node.suffix_link.children[suffix_link_xcat], + phrase= Phrase(phrase + (xcat,))) + + # sample from range + if not is_shadow_path: + sample = self.sampler.sample(node.phrase_location) + num_subpatterns = ( node.phrase_location).num_subpatterns + chunklen = IntList(initial_len=num_subpatterns) + for j from 0 <= j < num_subpatterns: + chunklen.arr[j] = hiero_phrase.chunklen(j) + extracts = [] + j = 0 + extract_start = monitor_cpu() + while j < sample.len: + extract = [] + + assign_matching(&matching, sample.arr, j, num_subpatterns, self.fda.sent_id.arr) + extract = self.extract(hiero_phrase, &matching, chunklen.arr, num_subpatterns) + extracts.extend(extract) + j = j + num_subpatterns + + num_samples = sample.len/num_subpatterns + extract_stop = monitor_cpu() + self.extract_time = self.extract_time + extract_stop - extract_start + if len(extracts) > 0: + fphrases = {} + fals = {} + fcount = {} + for f, e, count, als in extracts: + fcount.setdefault(f, 0.0) + fcount[f] = fcount[f] + count + fphrases.setdefault(f, {}) + fphrases[f].setdefault(e, {}) + fphrases[f][e].setdefault(als,0.0) + fphrases[f][e][als] = fphrases[f][e][als] + count + for f, elist in fphrases.iteritems(): + f_margin = fcount[f] + for e, alslist in elist.iteritems(): + alignment = None + count = 0 + for als, currcount in alslist.iteritems(): + if currcount > count: + alignment = als + count = currcount + scores = [] + for model in models: + scores.append(model(f, e, count, fcount[f], num_samples)) + yield Rule(self.category, f, e, + scores=scores, word_alignments=alignment) + + if len(phrase) < self.max_length and i+spanlen < len(fwords) and pathlen+1 <= self.max_initial_size: + for alt_id in range(len(fwords[i+spanlen])): + new_frontier.append((k, i+spanlen, alt_id, pathlen + 1, node, phrase, is_shadow_path)) + num_subpatterns = arity + if not is_shadow_path: + num_subpatterns = num_subpatterns + 1 + if len(phrase)+1 < self.max_length and arity < self.max_nonterminals and num_subpatterns < self.max_chunks: + xcat = sym_setindex(self.category, arity+1) + xnode = node.children[xcat] + # I put spanlen=1 below + key = tuple([self.min_gap_size, i, 1, pathlen]) + frontier_nodes = [] + if (key in nodes_isteps_away_buffer): + frontier_nodes = nodes_isteps_away_buffer[key] + else: + frontier_nodes = self.get_all_nodes_isteps_away(self.min_gap_size, i, 1, pathlen, fwords, next_states, reachable_buffer) + nodes_isteps_away_buffer[key] = frontier_nodes + + for (i, alt, pathlen) in frontier_nodes: + new_frontier.append((k, i, alt, pathlen, xnode, phrase +(xcat,), is_shadow_path)) + frontier = new_frontier + + stop_time = monitor_cpu() + logger.info("Total time for rule lookup, extraction, and scoring = %f seconds", (stop_time - start_time)) + gc.collect() + logger.info(" Extract time = %f seconds", self.extract_time) + + + cdef int find_fixpoint(self, + int f_low, f_high, + int* f_links_low, int* f_links_high, + int* e_links_low, int* e_links_high, + int e_in_low, int e_in_high, + int* e_low, int* e_high, + int* f_back_low, int* f_back_high, + int f_sent_len, int e_sent_len, + int max_f_len, int max_e_len, + int min_fx_size, int min_ex_size, + int max_new_x, + int allow_low_x, int allow_high_x, + int allow_arbitrary_x, int write_log): + cdef int e_low_prev, e_high_prev, f_low_prev, f_high_prev, new_x, new_low_x, new_high_x + + e_low[0] = e_in_low + e_high[0] = e_in_high + self.find_projection(f_low, f_high, f_links_low, f_links_high, e_low, e_high) + if e_low[0] == -1: + # low-priority corner case: if phrase w is unaligned, + # but we don't require aligned terminals, then returning + # an error here might prevent extraction of allowed + # rule X -> X_1 w X_2 / X_1 X_2. This is probably + # not worth the bother, though. + return 0 + elif e_in_low != -1 and e_low[0] != e_in_low: + if e_in_low - e_low[0] < min_ex_size: + e_low[0] = e_in_low - min_ex_size + if e_low[0] < 0: + return 0 + + if e_high[0] - e_low[0] > max_e_len: + return 0 + elif e_in_high != -1 and e_high[0] != e_in_high: + if e_high[0] - e_in_high < min_ex_size: + e_high[0] = e_in_high + min_ex_size + if e_high[0] > e_sent_len: + return 0 + + f_back_low[0] = -1 + f_back_high[0] = -1 + f_low_prev = f_low + f_high_prev = f_high + new_x = 0 + new_low_x = 0 + new_high_x = 0 + + while True: + + if f_back_low[0] == -1: + self.find_projection(e_low[0], e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) + else: + self.find_projection(e_low[0], e_low_prev, e_links_low, e_links_high, f_back_low, f_back_high) + self.find_projection(e_high_prev, e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) + + if f_back_low[0] > f_low: + f_back_low[0] = f_low + + if f_back_high[0] < f_high: + f_back_high[0] = f_high + + if f_back_low[0] == f_low_prev and f_back_high[0] == f_high_prev: + return 1 + + if allow_low_x == 0 and f_back_low[0] < f_low: + # FAIL: f phrase is not tight + return 0 + + if f_back_high[0] - f_back_low[0] > max_f_len: + # FAIL: f back projection is too wide + return 0 + + if allow_high_x == 0 and f_back_high[0] > f_high: + # FAIL: extension on high side not allowed + return 0 + + if f_low != f_back_low[0]: + if new_low_x == 0: + if new_x >= max_new_x: + # FAIL: extension required on low side violates max # of gaps + return 0 + else: + new_x = new_x + 1 + new_low_x = 1 + if f_low - f_back_low[0] < min_fx_size: + f_back_low[0] = f_low - min_fx_size + if f_back_high[0] - f_back_low[0] > max_f_len: + # FAIL: extension required on low side violates max initial length + return 0 + if f_back_low[0] < 0: + # FAIL: extension required on low side violates sentence boundary + return 0 + + if f_high != f_back_high[0]: + if new_high_x == 0: + if new_x >= max_new_x: + # FAIL: extension required on high side violates max # of gaps + return 0 + else: + new_x = new_x + 1 + new_high_x = 1 + if f_back_high[0] - f_high < min_fx_size: + f_back_high[0] = f_high + min_fx_size + if f_back_high[0] - f_back_low[0] > max_f_len: + # FAIL: extension required on high side violates max initial length + return 0 + if f_back_high[0] > f_sent_len: + # FAIL: extension required on high side violates sentence boundary + return 0 + + e_low_prev = e_low[0] + e_high_prev = e_high[0] + + self.find_projection(f_back_low[0], f_low_prev, f_links_low, f_links_high, e_low, e_high) + self.find_projection(f_high_prev, f_back_high[0], f_links_low, f_links_high, e_low, e_high) + if e_low[0] == e_low_prev and e_high[0] == e_high_prev: + return 1 + if allow_arbitrary_x == 0: + # FAIL: arbitrary expansion not permitted + return 0 + if e_high[0] - e_low[0] > max_e_len: + # FAIL: re-projection violates sentence max phrase length + return 0 + f_low_prev = f_back_low[0] + f_high_prev = f_back_high[0] + + + cdef find_projection(self, int in_low, int in_high, int* in_links_low, int* in_links_high, + int* out_low, int* out_high): + cdef int i + for i from in_low <= i < in_high: + if in_links_low[i] != -1: + if out_low[0] == -1 or in_links_low[i] < out_low[0]: + out_low[0] = in_links_low[i] + if out_high[0] == -1 or in_links_high[i] > out_high[0]: + out_high[0] = in_links_high[i] + + + cdef int* int_arr_extend(self, int* arr, int* arr_len, int* data, int data_len): + cdef int new_len + new_len = arr_len[0] + data_len + arr = realloc(arr, new_len*sizeof(int)) + memcpy(arr+arr_len[0], data, data_len*sizeof(int)) + arr_len[0] = new_len + return arr + + + cdef extract_phrases(self, int e_low, int e_high, int* e_gap_low, int* e_gap_high, int* e_links_low, int num_gaps, + int f_low, int f_high, int* f_gap_low, int* f_gap_high, int* f_links_low, + int sent_id, int e_sent_len, int e_sent_start): + cdef int i, j, k, m, n, *e_gap_order, e_x_low, e_x_high, e_x_gap_low, e_x_gap_high + cdef int *e_gaps1, *e_gaps2, len1, len2, step, num_chunks + cdef IntList ephr_arr + cdef result + + result = [] + len1 = 0 + e_gaps1 = malloc(0) + ephr_arr = IntList() + + e_gap_order = malloc(num_gaps*sizeof(int)) + if num_gaps > 0: + e_gap_order[0] = 0 + for i from 1 <= i < num_gaps: + for j from 0 <= j < i: + if e_gap_low[i] < e_gap_low[j]: + for k from j <= k < i: + e_gap_order[k+1] = e_gap_order[k] + e_gap_order[j] = i + break + else: + e_gap_order[i] = i + + e_x_low = e_low + e_x_high = e_high + if self.tight_phrases == 0: + while e_x_low > 0 and e_high - e_x_low < self.train_max_initial_size and e_links_low[e_x_low-1] == -1: + e_x_low = e_x_low - 1 + while e_x_high < e_sent_len and e_x_high - e_low < self.train_max_initial_size and e_links_low[e_x_high] == -1: + e_x_high = e_x_high + 1 + + for i from e_x_low <= i <= e_low: + e_gaps1 = self.int_arr_extend(e_gaps1, &len1, &i, 1) + + for i from 0 <= i < num_gaps: + e_gaps2 = malloc(0) + len2 = 0 + + j = e_gap_order[i] + e_x_gap_low = e_gap_low[j] + e_x_gap_high = e_gap_high[j] + if self.tight_phrases == 0: + while e_x_gap_low > e_x_low and e_links_low[e_x_gap_low-1] == -1: + e_x_gap_low = e_x_gap_low - 1 + while e_x_gap_high < e_x_high and e_links_low[e_x_gap_high] == -1: + e_x_gap_high = e_x_gap_high + 1 + + k = 0 + step = 1+(i*2) + while k < len1: + for m from e_x_gap_low <= m <= e_gap_low[j]: + if m >= e_gaps1[k+step-1]: + for n from e_gap_high[j] <= n <= e_x_gap_high: + if n-m >= 1: # extractor.py doesn't restrict target-side gap length + e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+k, step) + e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &m, 1) + e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &n, 1) + k = k + step + free(e_gaps1) + e_gaps1 = e_gaps2 + len1 = len2 + + step = 1+(num_gaps*2) + e_gaps2 = malloc(0) + len2 = 0 + for i from e_high <= i <= e_x_high: + j = 0 + while j < len1: + if i - e_gaps1[j] <= self.train_max_initial_size and i >= e_gaps1[j+step-1]: + e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+j, step) + e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &i, 1) + j = j + step + free(e_gaps1) + e_gaps1 = e_gaps2 + len1 = len2 + + step = (num_gaps+1)*2 + i = 0 + + while i < len1: + ephr_arr._clear() + num_chunks = 0 + indexes = [] + for j from 0 <= j < num_gaps+1: + if e_gaps1[i+2*j] < e_gaps1[i+(2*j)+1]: + num_chunks = num_chunks + 1 + for k from e_gaps1[i+2*j] <= k < e_gaps1[i+(2*j)+1]: + indexes.append(k) + ephr_arr._append(self.eid2symid[self.eda.data.arr[e_sent_start+k]]) + if j < num_gaps: + indexes.append(sym_setindex(self.category, e_gap_order[j]+1)) + ephr_arr._append(sym_setindex(self.category, e_gap_order[j]+1)) + i = i + step + if ephr_arr.len <= self.max_target_length and num_chunks <= self.max_target_chunks: + result.append((Phrase(ephr_arr),indexes)) + + free(e_gaps1) + free(e_gap_order) + return result + + cdef create_alignments(self, int* sent_links, int num_links, findexes, eindexes): + cdef unsigned i + ret = IntList() + for i in range(len(findexes)): + s = findexes[i] + if (s<0): + continue + idx = 0 + while (idx < num_links*2): + if (sent_links[idx] == s): + j = eindexes.index(sent_links[idx+1]) + ret.append(i*65536+j) + idx += 2 + return ret + + cdef extract(self, Phrase phrase, Matching* matching, int* chunklen, int num_chunks): + cdef int* sent_links, *e_links_low, *e_links_high, *f_links_low, *f_links_high + cdef int *f_gap_low, *f_gap_high, *e_gap_low, *e_gap_high, num_gaps, gap_start + cdef int i, j, k, e_i, f_i, num_links, num_aligned_chunks, met_constraints, x + cdef int f_low, f_high, e_low, e_high, f_back_low, f_back_high + cdef int e_sent_start, e_sent_end, f_sent_start, f_sent_end, e_sent_len, f_sent_len + cdef int e_word_count, f_x_low, f_x_high, e_x_low, e_x_high, phrase_len + cdef float pair_count + cdef extracts, phrase_list + cdef IntList fphr_arr + cdef Phrase fphr + cdef reason_for_failure + + fphr_arr = IntList() + phrase_len = phrase.n + extracts = [] + sent_links = self.alignment._get_sent_links(matching.sent_id, &num_links) + + e_sent_start = self.eda.sent_index.arr[matching.sent_id] + e_sent_end = self.eda.sent_index.arr[matching.sent_id+1] + e_sent_len = e_sent_end - e_sent_start - 1 + f_sent_start = self.fda.sent_index.arr[matching.sent_id] + f_sent_end = self.fda.sent_index.arr[matching.sent_id+1] + f_sent_len = f_sent_end - f_sent_start - 1 + + self.findexes1.reset() + sofar = 0 + for i in range(num_chunks): + for j in range(chunklen[i]): + self.findexes1.append(matching.arr[matching.start+i]+j-f_sent_start); + sofar += 1 + if (i+1 malloc(e_sent_len*sizeof(int)) + e_links_high = malloc(e_sent_len*sizeof(int)) + f_links_low = malloc(f_sent_len*sizeof(int)) + f_links_high = malloc(f_sent_len*sizeof(int)) + f_gap_low = malloc((num_chunks+1)*sizeof(int)) + f_gap_high = malloc((num_chunks+1)*sizeof(int)) + e_gap_low = malloc((num_chunks+1)*sizeof(int)) + e_gap_high = malloc((num_chunks+1)*sizeof(int)) + memset(f_gap_low, 0, (num_chunks+1)*sizeof(int)) + memset(f_gap_high, 0, (num_chunks+1)*sizeof(int)) + memset(e_gap_low, 0, (num_chunks+1)*sizeof(int)) + memset(e_gap_high, 0, (num_chunks+1)*sizeof(int)) + + reason_for_failure = "" + + for i from 0 <= i < e_sent_len: + e_links_low[i] = -1 + e_links_high[i] = -1 + for i from 0 <= i < f_sent_len: + f_links_low[i] = -1 + f_links_high[i] = -1 + + # this is really inefficient -- might be good to + # somehow replace with binary search just for the f + # links that we care about (but then how to look up + # when we want to check something on the e side?) + i = 0 + while i < num_links*2: + f_i = sent_links[i] + e_i = sent_links[i+1] + if f_links_low[f_i] == -1 or f_links_low[f_i] > e_i: + f_links_low[f_i] = e_i + if f_links_high[f_i] == -1 or f_links_high[f_i] < e_i + 1: + f_links_high[f_i] = e_i + 1 + if e_links_low[e_i] == -1 or e_links_low[e_i] > f_i: + e_links_low[e_i] = f_i + if e_links_high[e_i] == -1 or e_links_high[e_i] < f_i + 1: + e_links_high[e_i] = f_i + 1 + i = i + 2 + + als = [] + for x in range(matching.start,matching.end): + al = (matching.arr[x]-f_sent_start,f_links_low[matching.arr[x]-f_sent_start]) + als.append(al) + # check all source-side alignment constraints + met_constraints = 1 + if self.require_aligned_terminal: + num_aligned_chunks = 0 + for i from 0 <= i < num_chunks: + for j from 0 <= j < chunklen[i]: + if f_links_low[matching.arr[matching.start+i]+j-f_sent_start] > -1: + num_aligned_chunks = num_aligned_chunks + 1 + break + if num_aligned_chunks == 0: + reason_for_failure = "No aligned terminals" + met_constraints = 0 + if self.require_aligned_chunks and num_aligned_chunks < num_chunks: + reason_for_failure = "Unaligned chunk" + met_constraints = 0 + + if met_constraints and self.tight_phrases: + # outside edge constraints are checked later + for i from 0 <= i < num_chunks-1: + if f_links_low[matching.arr[matching.start+i]+chunklen[i]-f_sent_start] == -1: + reason_for_failure = "Gaps are not tight phrases" + met_constraints = 0 + break + if f_links_low[matching.arr[matching.start+i+1]-1-f_sent_start] == -1: + reason_for_failure = "Gaps are not tight phrases" + met_constraints = 0 + break + + f_low = matching.arr[matching.start] - f_sent_start + f_high = matching.arr[matching.start + matching.size - 1] + chunklen[num_chunks-1] - f_sent_start + if met_constraints: + + if self.find_fixpoint(f_low, f_high, f_links_low, f_links_high, e_links_low, e_links_high, + -1, -1, &e_low, &e_high, &f_back_low, &f_back_high, f_sent_len, e_sent_len, + self.train_max_initial_size, self.train_max_initial_size, + self.train_min_gap_size, 0, + self.max_nonterminals - num_chunks + 1, 1, 1, 0, 0): + gap_error = 0 + num_gaps = 0 + + if f_back_low < f_low: + f_gap_low[0] = f_back_low + f_gap_high[0] = f_low + num_gaps = 1 + gap_start = 0 + phrase_len = phrase_len+1 + if phrase_len > self.max_length: + gap_error = 1 + if self.tight_phrases: + if f_links_low[f_back_low] == -1 or f_links_low[f_low-1] == -1: + gap_error = 1 + reason_for_failure = "Inside edges of preceding subphrase are not tight" + else: + gap_start = 1 + if self.tight_phrases and f_links_low[f_low] == -1: + # this is not a hard error. we can't extract this phrase + # but we still might be able to extract a superphrase + met_constraints = 0 + + for i from 0 <= i < matching.size - 1: + f_gap_low[1+i] = matching.arr[matching.start+i] + chunklen[i] - f_sent_start + f_gap_high[1+i] = matching.arr[matching.start+i+1] - f_sent_start + num_gaps = num_gaps + 1 + + if f_high < f_back_high: + f_gap_low[gap_start+num_gaps] = f_high + f_gap_high[gap_start+num_gaps] = f_back_high + num_gaps = num_gaps + 1 + phrase_len = phrase_len+1 + if phrase_len > self.max_length: + gap_error = 1 + if self.tight_phrases: + if f_links_low[f_back_high-1] == -1 or f_links_low[f_high] == -1: + gap_error = 1 + reason_for_failure = "Inside edges of following subphrase are not tight" + else: + if self.tight_phrases and f_links_low[f_high-1] == -1: + met_constraints = 0 + + if gap_error == 0: + e_word_count = e_high - e_low + for i from 0 <= i < num_gaps: # check integrity of subphrases + if self.find_fixpoint(f_gap_low[gap_start+i], f_gap_high[gap_start+i], + f_links_low, f_links_high, e_links_low, e_links_high, + -1, -1, e_gap_low+gap_start+i, e_gap_high+gap_start+i, + f_gap_low+gap_start+i, f_gap_high+gap_start+i, + f_sent_len, e_sent_len, + self.train_max_initial_size, self.train_max_initial_size, + 0, 0, 0, 0, 0, 0, 0) == 0: + gap_error = 1 + reason_for_failure = "Subphrase [%d, %d] failed integrity check" % (f_gap_low[gap_start+i], f_gap_high[gap_start+i]) + break + + if gap_error == 0: + i = 1 + self.findexes.reset() + if f_back_low < f_low: + fphr_arr._append(sym_setindex(self.category, i)) + i = i+1 + self.findexes.append(sym_setindex(self.category, i)) + self.findexes.extend(self.findexes1) + for j from 0 <= j < phrase.n: + if sym_isvar(phrase.syms[j]): + fphr_arr._append(sym_setindex(self.category, i)) + i = i + 1 + else: + fphr_arr._append(phrase.syms[j]) + if f_back_high > f_high: + fphr_arr._append(sym_setindex(self.category, i)) + self.findexes.append(sym_setindex(self.category, i)) + + fphr = Phrase(fphr_arr) + if met_constraints: + phrase_list = self.extract_phrases(e_low, e_high, e_gap_low + gap_start, e_gap_high + gap_start, e_links_low, num_gaps, + f_back_low, f_back_high, f_gap_low + gap_start, f_gap_high + gap_start, f_links_low, + matching.sent_id, e_sent_len, e_sent_start) + if len(phrase_list) > 0: + pair_count = 1.0 / len(phrase_list) + else: + pair_count = 0 + reason_for_failure = "Didn't extract anything from [%d, %d] -> [%d, %d]" % (f_back_low, f_back_high, e_low, e_high) + for (phrase2,eindexes) in phrase_list: + als1 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + extracts.append((fphr, phrase2, pair_count, tuple(als1))) + + if (num_gaps < self.max_nonterminals and + phrase_len < self.max_length and + f_back_high - f_back_low + self.train_min_gap_size <= self.train_max_initial_size): + if (f_back_low == f_low and + f_low >= self.train_min_gap_size and + ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_back_high-1] != -1))): + f_x_low = f_low-self.train_min_gap_size + met_constraints = 1 + if self.tight_phrases: + while f_x_low >= 0 and f_links_low[f_x_low] == -1: + f_x_low = f_x_low - 1 + if f_x_low < 0 or f_back_high - f_x_low > self.train_max_initial_size: + met_constraints = 0 + + if (met_constraints and + self.find_fixpoint(f_x_low, f_back_high, + f_links_low, f_links_high, e_links_low, e_links_high, + e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, + f_sent_len, e_sent_len, + self.train_max_initial_size, self.train_max_initial_size, + 1, 1, 1, 1, 0, 1, 0) and + ((not self.tight_phrases) or f_links_low[f_x_low] != -1) and + self.find_fixpoint(f_x_low, f_low, # check integrity of new subphrase + f_links_low, f_links_high, e_links_low, e_links_high, + -1, -1, e_gap_low, e_gap_high, f_gap_low, f_gap_high, + f_sent_len, e_sent_len, + self.train_max_initial_size, self.train_max_initial_size, + 0, 0, 0, 0, 0, 0, 0)): + fphr_arr._clear() + i = 1 + self.findexes.reset() + self.findexes.append(sym_setindex(self.category, i)) + fphr_arr._append(sym_setindex(self.category, i)) + i = i+1 + self.findexes.extend(self.findexes1) + for j from 0 <= j < phrase.n: + if sym_isvar(phrase.syms[j]): + fphr_arr._append(sym_setindex(self.category, i)) + i = i + 1 + else: + fphr_arr._append(phrase.syms[j]) + if f_back_high > f_high: + fphr_arr._append(sym_setindex(self.category, i)) + self.findexes.append(sym_setindex(self.category, i)) + fphr = Phrase(fphr_arr) + phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+1, + f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, matching.sent_id, + e_sent_len, e_sent_start) + if len(phrase_list) > 0: + pair_count = 1.0 / len(phrase_list) + else: + pair_count = 0 + for phrase2,eindexes in phrase_list: + als2 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + extracts.append((fphr, phrase2, pair_count, tuple(als2))) + + if (f_back_high == f_high and + f_sent_len - f_high >= self.train_min_gap_size and + ((not self.tight_phrases) or (f_links_low[f_high] != -1 and f_links_low[f_back_low] != -1))): + f_x_high = f_high+self.train_min_gap_size + met_constraints = 1 + if self.tight_phrases: + while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: + f_x_high = f_x_high + 1 + if f_x_high > f_sent_len or f_x_high - f_back_low > self.train_max_initial_size: + met_constraints = 0 + + if (met_constraints and + self.find_fixpoint(f_back_low, f_x_high, + f_links_low, f_links_high, e_links_low, e_links_high, + e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, + f_sent_len, e_sent_len, + self.train_max_initial_size, self.train_max_initial_size, + 1, 1, 1, 0, 1, 1, 0) and + ((not self.tight_phrases) or f_links_low[f_x_high-1] != -1) and + self.find_fixpoint(f_high, f_x_high, + f_links_low, f_links_high, e_links_low, e_links_high, + -1, -1, e_gap_low+gap_start+num_gaps, e_gap_high+gap_start+num_gaps, + f_gap_low+gap_start+num_gaps, f_gap_high+gap_start+num_gaps, + f_sent_len, e_sent_len, + self.train_max_initial_size, self.train_max_initial_size, + 0, 0, 0, 0, 0, 0, 0)): + fphr_arr._clear() + i = 1 + self.findexes.reset() + if f_back_low < f_low: + fphr_arr._append(sym_setindex(self.category, i)) + i = i+1 + self.findexes.append(sym_setindex(self.category, i)) + self.findexes.extend(self.findexes1) + for j from 0 <= j < phrase.n: + if sym_isvar(phrase.syms[j]): + fphr_arr._append(sym_setindex(self.category, i)) + i = i + 1 + else: + fphr_arr._append(phrase.syms[j]) + fphr_arr._append(sym_setindex(self.category, i)) + self.findexes.append(sym_setindex(self.category, i)) + fphr = Phrase(fphr_arr) + phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low+gap_start, e_gap_high+gap_start, e_links_low, num_gaps+1, + f_x_low, f_x_high, f_gap_low+gap_start, f_gap_high+gap_start, f_links_low, + matching.sent_id, e_sent_len, e_sent_start) + if len(phrase_list) > 0: + pair_count = 1.0 / len(phrase_list) + else: + pair_count = 0 + for phrase2, eindexes in phrase_list: + als3 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + extracts.append((fphr, phrase2, pair_count, tuple(als3))) + if (num_gaps < self.max_nonterminals - 1 and + phrase_len+1 < self.max_length and + f_back_high == f_high and + f_back_low == f_low and + f_back_high - f_back_low + (2*self.train_min_gap_size) <= self.train_max_initial_size and + f_low >= self.train_min_gap_size and + f_high <= f_sent_len - self.train_min_gap_size and + ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_high] != -1))): + + met_constraints = 1 + f_x_low = f_low-self.train_min_gap_size + if self.tight_phrases: + while f_x_low >= 0 and f_links_low[f_x_low] == -1: + f_x_low = f_x_low - 1 + if f_x_low < 0: + met_constraints = 0 + + f_x_high = f_high+self.train_min_gap_size + if self.tight_phrases: + while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: + f_x_high = f_x_high + 1 + if f_x_high > f_sent_len or f_x_high - f_x_low > self.train_max_initial_size: + met_constraints = 0 + + if (met_constraints and + self.find_fixpoint(f_x_low, f_x_high, + f_links_low, f_links_high, e_links_low, e_links_high, + e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, + f_sent_len, e_sent_len, + self.train_max_initial_size, self.train_max_initial_size, + 1, 1, 2, 1, 1, 1, 1) and + ((not self.tight_phrases) or (f_links_low[f_x_low] != -1 and f_links_low[f_x_high-1] != -1)) and + self.find_fixpoint(f_x_low, f_low, + f_links_low, f_links_high, e_links_low, e_links_high, + -1, -1, e_gap_low, e_gap_high, f_gap_low, f_gap_high, + f_sent_len, e_sent_len, + self.train_max_initial_size, self.train_max_initial_size, + 0, 0, 0, 0, 0, 0, 0) and + self.find_fixpoint(f_high, f_x_high, + f_links_low, f_links_high, e_links_low, e_links_high, + -1, -1, e_gap_low+1+num_gaps, e_gap_high+1+num_gaps, + f_gap_low+1+num_gaps, f_gap_high+1+num_gaps, + f_sent_len, e_sent_len, + self.train_max_initial_size, self.train_max_initial_size, + 0, 0, 0, 0, 0, 0, 0)): + fphr_arr._clear() + i = 1 + self.findexes.reset() + self.findexes.append(sym_setindex(self.category, i)) + fphr_arr._append(sym_setindex(self.category, i)) + i = i+1 + self.findexes.extend(self.findexes1) + for j from 0 <= j < phrase.n: + if sym_isvar(phrase.syms[j]): + fphr_arr._append(sym_setindex(self.category, i)) + i = i + 1 + else: + fphr_arr._append(phrase.syms[j]) + fphr_arr._append(sym_setindex(self.category, i)) + self.findexes.append(sym_setindex(self.category, i)) + fphr = Phrase(fphr_arr) + phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+2, + f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, + matching.sent_id, e_sent_len, e_sent_start) + if len(phrase_list) > 0: + pair_count = 1.0 / len(phrase_list) + else: + pair_count = 0 + for phrase2, eindexes in phrase_list: + als4 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + extracts.append((fphr, phrase2, pair_count, tuple(als4))) + else: + reason_for_failure = "Unable to extract basic phrase" + + free(sent_links) + free(f_links_low) + free(f_links_high) + free(e_links_low) + free(e_links_high) + free(f_gap_low) + free(f_gap_high) + free(e_gap_low) + free(e_gap_high) + + return extracts diff --git a/python/src/sa/str_map.pxi b/python/src/sa/str_map.pxi new file mode 100644 index 00000000..3a8439a4 --- /dev/null +++ b/python/src/sa/str_map.pxi @@ -0,0 +1,23 @@ +cdef extern from "strmap.h": + ctypedef struct StrMap + StrMap* stringmap_new() + void stringmap_delete(StrMap *vocab) + int stringmap_index(StrMap *vocab, char *s) + char* stringmap_word(StrMap *vocab, int i) + +cdef class StringMap: + cdef StrMap *vocab + cdef char *word(self, int i) + cdef int index(self, char *s) + + def __cinit__(self): + self.vocab = stringmap_new() + + def __dealloc__(self): + stringmap_delete(self.vocab) + + cdef char *word(self, int i): + return stringmap_word(self.vocab, i) + + cdef int index(self, char *s): + return stringmap_index(self.vocab, s) diff --git a/python/src/sa/strmap.cc b/python/src/sa/strmap.cc new file mode 100644 index 00000000..5040477e --- /dev/null +++ b/python/src/sa/strmap.cc @@ -0,0 +1,232 @@ +#include "strmap.h" + +#include +#include +#include +#include + +using namespace std; +using namespace std::tr1; + +#undef HAVE_64_BITS + +#if INTPTR_MAX == INT32_MAX +# define HAVE_64_BITS 0 +#elif INTPTR_MAX >= INT64_MAX +# define HAVE_64_BITS 1 +#else +# error "couldn't tell if HAVE_64_BITS from INTPTR_MAX INT32_MAX INT64_MAX" +#endif + +typedef uintptr_t MurmurInt; + +// MurmurHash2, by Austin Appleby + +static const uint32_t DEFAULT_SEED=2654435769U; + +#if HAVE_64_BITS +//MurmurInt MurmurHash(void const *key, int len, uint32_t seed=DEFAULT_SEED); + +inline uint64_t MurmurHash64( const void * key, int len, unsigned int seed=DEFAULT_SEED ) +{ + const uint64_t m = 0xc6a4a7935bd1e995ULL; + const int r = 47; + + uint64_t h = seed ^ (len * m); + + const uint64_t * data = (const uint64_t *)key; + const uint64_t * end = data + (len/8); + + while(data != end) + { + uint64_t k = *data++; + + k *= m; + k ^= k >> r; + k *= m; + + h ^= k; + h *= m; + } + + const unsigned char * data2 = (const unsigned char*)data; + + switch(len & 7) + { + case 7: h ^= uint64_t(data2[6]) << 48; + case 6: h ^= uint64_t(data2[5]) << 40; + case 5: h ^= uint64_t(data2[4]) << 32; + case 4: h ^= uint64_t(data2[3]) << 24; + case 3: h ^= uint64_t(data2[2]) << 16; + case 2: h ^= uint64_t(data2[1]) << 8; + case 1: h ^= uint64_t(data2[0]); + h *= m; + }; + + h ^= h >> r; + h *= m; + h ^= h >> r; + + return h; +} + +inline uint32_t MurmurHash32(void const *key, int len, uint32_t seed=DEFAULT_SEED) +{ + return (uint32_t) MurmurHash64(key,len,seed); +} + +inline MurmurInt MurmurHash(void const *key, int len, uint32_t seed=DEFAULT_SEED) +{ + return MurmurHash64(key,len,seed); +} + +#else +// 32-bit + +// Note - This code makes a few assumptions about how your machine behaves - +// 1. We can read a 4-byte value from any address without crashing +// 2. sizeof(int) == 4 +inline uint32_t MurmurHash32 ( const void * key, int len, uint32_t seed=DEFAULT_SEED) +{ + // 'm' and 'r' are mixing constants generated offline. + // They're not really 'magic', they just happen to work well. + + const uint32_t m = 0x5bd1e995; + const int r = 24; + + // Initialize the hash to a 'random' value + + uint32_t h = seed ^ len; + + // Mix 4 bytes at a time into the hash + + const unsigned char * data = (const unsigned char *)key; + + while(len >= 4) + { + uint32_t k = *(uint32_t *)data; + + k *= m; + k ^= k >> r; + k *= m; + + h *= m; + h ^= k; + + data += 4; + len -= 4; + } + + // Handle the last few bytes of the input array + + switch(len) + { + case 3: h ^= data[2] << 16; + case 2: h ^= data[1] << 8; + case 1: h ^= data[0]; + h *= m; + }; + + // Do a few final mixes of the hash to ensure the last few + // bytes are well-incorporated. + + h ^= h >> 13; + h *= m; + h ^= h >> 15; + + return h; +} + +inline MurmurInt MurmurHash ( const void * key, int len, uint32_t seed=DEFAULT_SEED) { + return MurmurHash32(key,len,seed); +} + +// 64-bit hash for 32-bit platforms + +inline uint64_t MurmurHash64 ( const void * key, int len, uint32_t seed=DEFAULT_SEED) +{ + const uint32_t m = 0x5bd1e995; + const int r = 24; + + uint32_t h1 = seed ^ len; + uint32_t h2 = 0; + + const uint32_t * data = (const uint32_t *)key; + + while(len >= 8) + { + uint32_t k1 = *data++; + k1 *= m; k1 ^= k1 >> r; k1 *= m; + h1 *= m; h1 ^= k1; + len -= 4; + + uint32_t k2 = *data++; + k2 *= m; k2 ^= k2 >> r; k2 *= m; + h2 *= m; h2 ^= k2; + len -= 4; + } + + if(len >= 4) + { + uint32_t k1 = *data++; + k1 *= m; k1 ^= k1 >> r; k1 *= m; + h1 *= m; h1 ^= k1; + len -= 4; + } + + switch(len) + { + case 3: h2 ^= ((unsigned char*)data)[2] << 16; + case 2: h2 ^= ((unsigned char*)data)[1] << 8; + case 1: h2 ^= ((unsigned char*)data)[0]; + h2 *= m; + }; + + h1 ^= h2 >> 18; h1 *= m; + h2 ^= h1 >> 22; h2 *= m; + h1 ^= h2 >> 17; h1 *= m; + h2 ^= h1 >> 19; h2 *= m; + + uint64_t h = h1; + + h = (h << 32) | h2; + + return h; +} + +#endif +//32bit + +struct MurmurHasher { + size_t operator()(const string& s) const { + return MurmurHash(s.c_str(), s.size()); + } +}; + +struct StrMap { + StrMap() { keys_.reserve(10000); keys_.push_back(""); map_[keys_[0]] = 0; } + unordered_map map_; + vector keys_; +}; + +StrMap* stringmap_new() { + return new StrMap; +} + +void stringmap_delete(StrMap *vocab) { + delete vocab; +} + +int stringmap_index(StrMap *vocab, char *s) { + int& cell = vocab->map_[s]; + if (!cell) { + cell = vocab->keys_.size(); + vocab->keys_.push_back(s); + } + return cell; +} + +char* stringmap_word(StrMap *vocab, int i) { + return const_cast(vocab->keys_[i].c_str()); +} + diff --git a/python/src/sa/strmap.h b/python/src/sa/strmap.h new file mode 100644 index 00000000..a218a4c0 --- /dev/null +++ b/python/src/sa/strmap.h @@ -0,0 +1,22 @@ +#ifndef _STRMAP_H_ +#define _STRMAP_H_ + +#ifdef __cplusplus + extern "C" { +#else + typedef struct StrMap StrMap; /* dummy type to stand in for class */ +#endif + +struct StrMap; + +StrMap* stringmap_new(); +void stringmap_delete(StrMap *vocab); +int stringmap_index(StrMap *vocab, char *s); +char* stringmap_word(StrMap *vocab, int i); + +#ifdef __cplusplus + } +#endif + + +#endif diff --git a/python/src/sa/suffix_array.pxi b/python/src/sa/suffix_array.pxi new file mode 100644 index 00000000..20e6261d --- /dev/null +++ b/python/src/sa/suffix_array.pxi @@ -0,0 +1,259 @@ +# Defines suffix arrays that can be directly written to/read from disk in binary format +# Adam Lopez + +from libc.stdio cimport FILE, fclose, fopen + +cdef class SuffixArray: + cdef DataArray darray + cdef IntList sa + cdef IntList ha + + def __cinit__(self, from_binary=None, from_text=None): + self.darray = DataArray() + self.sa = IntList() + self.ha = IntList() + if from_binary: + self.read_binary(from_binary) + elif from_text: + self.read_text(from_text) + + def __getitem__(self, i): + return self.sa.arr[i] + + def getSentId(self, i): + return self.darray.getSentId(i) + + def getSent(self, i): + return self.darray.getSent(i) + + def getSentPos(self, loc): + return self.darray.getSentPos(loc) + + def read_text(self, char* filename): + '''Constructs suffix array using the algorithm + of Larsson & Sadahkane (1999)''' + cdef int V, N, i, j, h, a_i, n, current_run, skip + cdef IntList isa, word_count + + self.darray = DataArray(from_text=filename, use_sent_id=True) + N = len(self.darray) + V = len(self.darray.id2word) + + self.sa = IntList(initial_len=N) + self.ha = IntList(initial_len=V+1) + + isa = IntList(initial_len=N) + word_count = IntList(initial_len=V+1) + + '''Step 1: bucket sort data''' + cdef float sort_start_time = monitor_cpu() + cdef float start_time = sort_start_time + for i from 0 <= i < N: + a_i = self.darray.data.arr[i] + word_count.arr[a_i] = word_count.arr[a_i] + 1 + + n = 0 + for i from 0 <= i < V+1: + self.ha.arr[i] = n + n = n + word_count.arr[i] + word_count.arr[i] = 0 + + for i from 0 <= i < N: + a_i = self.darray.data.arr[i] + self.sa.arr[self.ha.arr[a_i] + word_count.arr[a_i]] = i + isa.arr[i] = self.ha.arr[a_i + 1] - 1 # bucket pointer is last index in bucket + word_count.arr[a_i] = word_count.arr[a_i] + 1 + + '''Determine size of initial runs''' + current_run = 0 + for i from 0 <= i < V+1: + if i < V and self.ha.arr[i+1] - self.ha.arr[i] == 1: + current_run = current_run + 1 + else: + if current_run > 0: + self.sa.arr[self.ha.arr[i] - current_run] = -current_run + current_run = 0 + + logger.info(" Bucket sort took %f seconds", (monitor_cpu() - sort_start_time)) + + '''Step 2: prefix-doubling sort''' + h = 1 + while self.sa.arr[0] != -N: + sort_start_time = monitor_cpu() + logger.debug(" Refining, sort depth = %d", h) + i = 0 + skip = 0 + while i < N: + if self.sa.arr[i] < 0: + skip = skip + self.sa.arr[i] + i = i - self.sa.arr[i] + else: + if skip < 0: + self.sa.arr[i+skip] = skip + skip = 0 + j = isa.arr[self.sa.arr[i]] + self.q3sort(i, j, h, isa) + i = j+1 + if skip < 0: + self.sa.arr[i+skip] = skip + h = h * 2 + logger.debug(" Refinement took %f seconds", (monitor_cpu() - sort_start_time)) + + '''Step 3: read off suffix array from inverse suffix array''' + logger.info(" Finalizing sort...") + for i from 0 <= i < N: + j = isa.arr[i] + self.sa.arr[j] = i + logger.info("Suffix array construction took %f seconds", (monitor_cpu() - start_time)) + + def q3sort(self, int i, int j, int h, IntList isa, pad=""): + '''This is a ternary quicksort. It divides the array into + three partitions: items less than the pivot, items equal + to pivot, and items greater than pivot. The first and last + of these partitions are then recursively sorted''' + cdef int k, midpoint, pval, phead, ptail, tmp + + if j-i < -1: + raise Exception("Unexpected condition found in q3sort: sort from %d to %d" % (i,j)) + if j-i == -1: # recursive base case -- empty interval + return + if (j-i == 0): # recursive base case -- singleton interval + isa.arr[self.sa.arr[i]] = i + self.sa.arr[i] = -1 + return + + # NOTE: choosing the first item as a pivot value resulted in + # stack overflow for some very large buckets. I think there + # is a natural bias towards order due the way the word ids are + # assigned; thus this resulted in the range to the left of the + # pivot being nearly empty. Therefore, choose the middle item. + # If the method of assigning word_id's is changed, this method + # may need to be reconsidered as well. + midpoint = (i+j)/2 + pval = isa.arr[self.sa.arr[midpoint] + h] + if i != midpoint: + tmp = self.sa.arr[midpoint] + self.sa.arr[midpoint] = self.sa.arr[i] + self.sa.arr[i] = tmp + phead = i + ptail = i + + # find the three partitions. phead marks the first element + # of the middle partition, and ptail marks the last element + for k from i+1 <= k < j+1: + if isa.arr[self.sa.arr[k] + h] < pval: + if k > ptail+1: + tmp = self.sa.arr[phead] + self.sa.arr[phead] = self.sa.arr[k] + self.sa.arr[k] = self.sa.arr[ptail+1] + self.sa.arr[ptail+1] = tmp + else: # k == ptail+1 + tmp = self.sa.arr[phead] + self.sa.arr[phead] = self.sa.arr[k] + self.sa.arr[k] = tmp + phead = phead + 1 + ptail = ptail + 1 + else: + if isa.arr[self.sa.arr[k] + h] == pval: + if k > ptail+1: + tmp = self.sa.arr[ptail+1] + self.sa.arr[ptail+1] = self.sa.arr[k] + self.sa.arr[k] = tmp + ptail = ptail + 1 + + # recursively sort smaller suffixes + self.q3sort(i, phead-1, h, isa, pad+" ") + + # update suffixes with pivot value + # corresponds to update_group function in Larsson & Sadakane + for k from phead <= k < ptail+1: + isa.arr[self.sa.arr[k]] = ptail + if phead == ptail: + self.sa.arr[phead] = -1 + + # recursively sort larger suffixes + self.q3sort(ptail+1, j, h, isa, pad+" ") + + + def write_text(self, char* filename): + self.darray.write_text(filename) + + def read_binary(self, char* filename): + cdef FILE *f + f = fopen(filename, "r") + self.darray.read_handle(f) + self.sa.read_handle(f) + self.ha.read_handle(f) + fclose(f) + + def write_binary(self, char* filename): + cdef FILE* f + f = fopen(filename, "w") + self.darray.write_handle(f) + self.sa.write_handle(f) + self.ha.write_handle(f) + fclose(f) + + def write_enhanced(self, char* filename): + with open(filename, "w") as f: + self.darray.write_enhanced_handle(f) + for a_i in self.sa: + f.write("%d " % a_i) + f.write("\n") + for w_i in self.ha: + f.write("%d " % w_i) + f.write("\n") + + cdef int __search_high(self, int word_id, int offset, int low, int high): + cdef int midpoint + + if low >= high: + return high + midpoint = (high + low) / 2 + if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + return self.__search_high(word_id, offset, midpoint+1, high) + else: + return self.__search_high(word_id, offset, low, midpoint) + + cdef int __search_low(self, int word_id, int offset, int low, int high): + cdef int midpoint + + if low >= high: + return high + midpoint = (high + low) / 2 + if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + return self.__search_low(word_id, offset, low, midpoint) + else: + return self.__search_low(word_id, offset, midpoint+1, high) + + cdef __get_range(self, int word_id, int offset, int low, int high, int midpoint): + return (self.__search_low(word_id, offset, low, midpoint), + self.__search_high(word_id, offset, midpoint, high)) + + cdef __lookup_helper(self, int word_id, int offset, int low, int high): + cdef int midpoint + + if offset == 0: + return (self.ha.arr[word_id], self.ha.arr[word_id+1]) + if low >= high: + return None + + midpoint = (high + low) / 2 + if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + return self.__get_range(word_id, offset, low, high, midpoint) + if self.darray.data.arr[self.sa.arr[midpoint] + offset] > word_id: + return self.__lookup_helper(word_id, offset, low, midpoint) + else: + return self.__lookup_helper(word_id, offset, midpoint+1, high) + + def lookup(self, word, int offset, int low, int high): + cdef int wordid + if low == -1: + low = 0 + if high == -1: + high = len(self.sa) + if word in self.darray.word2id: + word_id = self.darray.word2id[word] + return self.__lookup_helper(word_id, offset, low, high) + else: + return None diff --git a/python/src/sa/sym.pxi b/python/src/sa/sym.pxi new file mode 100644 index 00000000..3fd6c5a7 --- /dev/null +++ b/python/src/sa/sym.pxi @@ -0,0 +1,101 @@ +from libc.string cimport strrchr, strstr, strcpy, strlen +from libc.stdlib cimport malloc, realloc, strtol + +cdef int INDEX_SHIFT = 3 +cdef int INDEX_MASK = (1<= 0 + + cdef int getindex(self, int sym): + return -sym & INDEX_MASK + + cdef int setindex(self, int sym, int ind): + return -(-sym & ~INDEX_MASK | ind) + + cdef int clearindex(self, int sym): + return -(-sym& ~INDEX_MASK) + + cdef int match(self, int sym1, int sym2): + return self.clearindex(sym1) == self.clearindex(sym2); + + cdef char* tocat(self, int sym): + return self.nonterminals.word((-sym >> INDEX_SHIFT)-1) + + cdef int fromcat(self, char *s): + cdef int i + i = self.nonterminals.index(s) + if self.first_nonterminal == -1: + self.first_nonterminal = i + if i > self.last_nonterminal: + self.last_nonterminal = i + return -(i+1 << INDEX_SHIFT) + + cdef char* tostring(self, int sym): + cdef int ind + if self.isvar(sym): + if sym in self.id2sym: + return self.id2sym[sym] + + ind = self.getindex(sym) + if ind > 0: + self.id2sym[sym] = "[%s,%d]" % (self.tocat(sym), ind) + else: + self.id2sym[sym] = "[%s]" % self.tocat(sym) + return self.id2sym[sym] + + else: + return self.terminals.word(sym) + + cdef int fromstring(self, char *s, bint terminal): + """Warning: this method is allowed to alter s.""" + cdef char *comma + cdef int n + n = strlen(s) + cdef char *sep + sep = strstr(s,"_SEP_") + if n >= 3 and s[0] == c'[' and s[n-1] == c']' and sep == NULL: + if terminal: + s1 = "\\"+s + return self.terminals.index(s1) + s[n-1] = c'\0' + s = s + 1 + comma = strrchr(s, c',') + if comma != NULL: + comma[0] = c'\0' + return self.setindex(self.fromcat(s), strtol(comma+1, NULL, 10)) + else: + return self.fromcat(s) + else: + return self.terminals.index(s) + +cdef Alphabet ALPHABET = Alphabet() + +def sym_tostring(int sym): + return ALPHABET.tostring(sym) + +def sym_fromstring(bytes string, bint terminal): + return ALPHABET.fromstring(string, terminal) + +def sym_isvar(int sym): + return ALPHABET.isvar(sym) + +cdef int sym_setindex(int sym, int id): + return ALPHABET.setindex(sym, id) diff --git a/python/src/sa/veb.pxi b/python/src/sa/veb.pxi new file mode 100644 index 00000000..40af3a68 --- /dev/null +++ b/python/src/sa/veb.pxi @@ -0,0 +1,392 @@ +"""This module implements a partial stratified tree (van Emde Boas, 1977). +Only insert findsucc, __iter__, and __contains__ are implemented. +Delete is currently not supported. +There is very little error-checking in this code -- it is designed +to be used in the limited situation described in Lopez (EMNLP-CoNLL 2007), +which doesn't cover all of the possible ways that you could misuse it +(e.g. trying to insert a key larger than the universe size) +Other notes -- this code is really rather ugly C code masquerading as +Pyrex/Python. Virtual function calls are bypassed by hand in several +places for the sake of efficiency, and other Python niceties are +removed for the same reason.""" + +from libc.stdlib cimport malloc, free +from libc.math cimport log, ceil +from libc.string cimport memset + +cdef int MIN_BOTTOM_SIZE = 32 +cdef int MIN_BOTTOM_BITS = 5 +cdef int LOWER_MASK[32] + +cdef void _init_lower_mask(): + cdef unsigned i + cdef int mask = 0 + for i in range(MIN_BOTTOM_SIZE): + mask = (mask << 1) + 1 + LOWER_MASK[i] = mask + +_init_lower_mask() + +cdef struct _BitSet: + long bitset + int min_val + int max_val + int size + + +cdef _BitSet* new_BitSet(): + cdef _BitSet* b + + b = <_BitSet*> malloc(sizeof(_BitSet)) + b.bitset = 0 + b.min_val = -1 + b.max_val = -1 + b.size = 0 + return b + + +cdef int bitset_findsucc(_BitSet* b, int i): + cdef int bitset, mask + cdef int low, high, mid + + if b.max_val == -1 or i >= b.max_val: + return -1 + if i < b.min_val: + return b.min_val + + bitset = b.bitset & ~LOWER_MASK[i] + low = i+1 + high = b.max_val+1 + while low < high-1: + mid = (high + low)/2 + mask = ~(LOWER_MASK[high-1] ^ LOWER_MASK[mid-1]) + if bitset & mask == 0: + low = mid + else: + bitset = bitset & mask + high = mid + return low + + +cdef int bitset_insert(_BitSet* b, int i): + cdef int val + + val = 1 << i + if b.bitset & val == 0: + b.bitset = b.bitset | val + if b.size == 0: + b.min_val = i + b.max_val = i + else: + if i < b.min_val: + b.min_val = i + if i > b.max_val: + b.max_val = i + b.size = b.size + 1 + return 1 + return 0 + + +cdef int bitset_contains(_BitSet* b, int i): + cdef int val + + val = 1 << i + if b.bitset & val == 0: + return 0 + else: + return 1 + + +cdef class BitSetIterator: + cdef _BitSet* b + cdef int next_val + + def __next__(self): + cdef int ret_val + + if self.next_val == -1: + raise StopIteration() + ret_val = self.next_val + self.next_val = bitset_findsucc(self.b, ret_val) + return ret_val + + + +# This is a Python wrapper class to give access to the +# (entirely C-implemented) _BitSet struct. +# Very slow; use only for debugging +cdef class BitSet: + + cdef _BitSet* b + + def __cinit__(self): + self.b = new_BitSet() + + def __dealloc__(self): + free(self.b) + + def __iter__(self): + cdef BitSetIterator it + it = BitSetIterator() + it.b = self.b + it.next_val = self.b.min_val + return it + + def insert(self, i): + return bitset_insert(self.b, i) + + def findsucc(self, i): + return bitset_findsucc(self.b, i) + + def __str__(self): + return dec2bin(self.b.bitset)+" ("+str(self.b.size)+","+str(self.b.min_val)+","+str(self.b.max_val)+")" + + def min(self): + return self.b.min_val + + def max(self): + return self.b.max_val + + def __len__(self): + return self.b.size + + def __contains__(self, i): + return bool(bitset_contains(self.b, i)) + + +cdef str dec2bin(long i): + cdef str result = "" + cdef unsigned d + for d in range(MIN_BOTTOM_SIZE): + if i & LOWER_MASK[0] == 0: + result = "0"+result + else: + result = "1"+result + i = i >> 1 + return result + +cdef struct _VEB: + int top_universe_size + int num_bottom_bits + int max_val + int min_val + int size + void* top + void** bottom + +cdef _VEB* new_VEB(int n): + cdef _VEB* veb + cdef int num_bits, num_top_bits, i + + veb = <_VEB*> malloc(sizeof(_VEB)) + + num_bits = int(ceil(log(n) / log(2))) + veb.num_bottom_bits = num_bits/2 + if veb.num_bottom_bits < MIN_BOTTOM_BITS: + veb.num_bottom_bits = MIN_BOTTOM_BITS + veb.top_universe_size = (n >> veb.num_bottom_bits) + 1 + + veb.bottom = malloc(veb.top_universe_size * sizeof(void*)) + memset(veb.bottom, 0, veb.top_universe_size * sizeof(void*)) + + if veb.top_universe_size > MIN_BOTTOM_SIZE: + veb.top = new_VEB(veb.top_universe_size) + else: + veb.top = new_BitSet() + + veb.max_val = -1 + veb.min_val = -1 + veb.size = 0 + return veb + + +cdef int VEB_insert(_VEB* veb, int i): + cdef _VEB* subv + cdef _BitSet* subb + cdef int a, b, tmp + + if veb.size == 0: + veb.min_val = i + veb.max_val = i + elif i == veb.min_val or i == veb.max_val: + return 0 + else: + if i < veb.min_val: + tmp = i + i = veb.min_val + veb.min_val = tmp + a = i >> veb.num_bottom_bits + b = i & LOWER_MASK[veb.num_bottom_bits-1] + if veb.bottom[a] == NULL: + if veb.top_universe_size > MIN_BOTTOM_SIZE: + subv = <_VEB*> veb.top + VEB_insert(subv, a) + else: + subb = <_BitSet*> veb.top + bitset_insert(subb, a) + if veb.num_bottom_bits > MIN_BOTTOM_BITS: + veb.bottom[a] = new_VEB(1 << veb.num_bottom_bits) + else: + veb.bottom[a] = new_BitSet() + if veb.num_bottom_bits > MIN_BOTTOM_BITS: + subv = <_VEB*> veb.bottom[a] + if VEB_insert(subv, b) == 0: + return 0 + else: + subb = <_BitSet*> veb.bottom[a] + if bitset_insert(subb, b) == 0: + return 0 + + if i > veb.max_val: + veb.max_val = i + veb.size = veb.size + 1 + return 1 + + +cdef del_VEB(_VEB* veb): + cdef int i + + if veb.top_universe_size > MIN_BOTTOM_SIZE: + i = (<_VEB*> veb.top).min_val + else: + i = (<_BitSet*> veb.top).min_val + + while i != -1: + if veb.num_bottom_bits > MIN_BOTTOM_BITS: + del_VEB(<_VEB*> veb.bottom[i]) + else: + free(<_BitSet*> veb.bottom[i]) + + if veb.top_universe_size > MIN_BOTTOM_SIZE: + i = VEB_findsucc(<_VEB*> veb.top, i) + else: + i = bitset_findsucc(<_BitSet*> veb.top, i) + + if veb.top_universe_size > MIN_BOTTOM_SIZE: + del_VEB(<_VEB*> veb.top) + else: + free(<_BitSet*> veb.top) + free(veb.bottom) + free(veb) + + +cdef int VEB_findsucc(_VEB* veb, int i): + cdef _VEB* subv + cdef _BitSet* subb + cdef int a, b, j, c, found + + if veb.max_val == -1 or i>=veb.max_val: + return -1 + if i < veb.min_val: + return veb.min_val + + a = i >> veb.num_bottom_bits + b = i & LOWER_MASK[veb.num_bottom_bits-1] + found = 0 + if veb.bottom[a] != NULL: + if veb.num_bottom_bits > MIN_BOTTOM_BITS: + subv = <_VEB*> veb.bottom[a] + if subv.max_val > b: + j = (a << veb.num_bottom_bits) + VEB_findsucc(subv, b) + found = 1 + else: + subb = <_BitSet*> veb.bottom[a] + if subb.max_val > b: + j = (a << veb.num_bottom_bits) + bitset_findsucc(subb, b) + found = 1 + if found==0: + if veb.top_universe_size > MIN_BOTTOM_SIZE: + subv = <_VEB*> veb.top + c = VEB_findsucc(subv, a) + else: + subb = <_BitSet*> veb.top + c = bitset_findsucc(subb, a) + if veb.num_bottom_bits > MIN_BOTTOM_BITS: + subv = <_VEB*> veb.bottom[c] + j = (c << veb.num_bottom_bits) + subv.min_val + else: + subb = <_BitSet*> veb.bottom[c] + j = (c << veb.num_bottom_bits) + subb.min_val + return j + + +cdef int VEB_contains(_VEB* veb, int i): + cdef _VEB* subv + cdef _BitSet* subb + cdef int a, b + + if veb.size == 0 or i < veb.min_val or i > veb.max_val: + return 0 + + if veb.min_val == i: + return 1 + else: + if veb.size == 1: + return 0 + + a = i >> veb.num_bottom_bits + b = i & LOWER_MASK[veb.num_bottom_bits-1] + if veb.bottom[a] == NULL: + return 0 + else: + if veb.num_bottom_bits > MIN_BOTTOM_BITS: + subv = <_VEB*> veb.bottom[a] + return VEB_contains(subv, b) + else: + subb = <_BitSet*> veb.bottom[a] + return bitset_contains(subb, b) + + +cdef class VEBIterator: + cdef _VEB* v + cdef int next_val + + def __next__(self): + cdef int ret_val + + if self.next_val == -1: + raise StopIteration() + ret_val = self.next_val + self.next_val = VEB_findsucc(self.v, ret_val) + return ret_val + + +cdef class VEB: + cdef _VEB* veb + cdef int _findsucc(self, int i) + cdef int _insert(self, int i) + cdef int _first(self) + + def __cinit__(self, int size): + self.veb = new_VEB(size) + + def __dealloc__(self): + del_VEB(self.veb) + + def __iter__(self): + cdef VEBIterator it + it = VEBIterator() + it.v = self.veb + it.next_val = self.veb.min_val + return it + + def insert(self, i): + return VEB_insert(self.veb, i) + + cdef int _insert(self, int i): + return VEB_insert(self.veb, i) + + def findsucc(self, i): + return VEB_findsucc(self.veb, i) + + cdef int _first(self): + return self.veb.min_val + + cdef int _findsucc(self, int i): + return VEB_findsucc(self.veb, i) + + def __len__(self): + return self.veb.size + + def __contains__(self, i): + return VEB_contains(self.veb, i) -- cgit v1.2.3 From 1d481414a2fa8505a2591c88e2b7b8f86a682ca2 Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Fri, 27 Jul 2012 22:25:15 -0400 Subject: [python] conversion from cdec.sa.Rule to cdec.TRule + remove configobj dependency + re-structure packages (no more top-level library) + "const" stuff + use __new__ instead of constructor for some objects --- python/README.md | 6 +- python/cdec/configobj.py | 2468 ++ python/cdec/sa/__init__.py | 2 +- python/cdec/sa/compile.py | 4 +- python/cdec/sa/extract.py | 3 +- python/cdec/sa/extractor.py | 7 +- python/cdec/sa/features.py | 11 +- python/setup.py | 6 +- python/src/_cdec.cpp | 5999 ++-- python/src/_cdec.pyx | 10 +- python/src/grammar.pxd | 13 +- python/src/grammar.pxi | 61 +- python/src/hypergraph.pxd | 18 +- python/src/hypergraph.pxi | 18 +- python/src/lattice.pxi | 6 +- python/src/mteval.pxd | 6 +- python/src/mteval.pxi | 4 +- python/src/sa/_cdec_sa.c | 62490 --------------------------------------- python/src/sa/_cdec_sa.pyx | 29 - python/src/sa/_sa.c | 63140 ++++++++++++++++++++++++++++++++++++++++ python/src/sa/_sa.pxd | 17 + python/src/sa/_sa.pyx | 29 + python/src/sa/rule.pxi | 39 +- python/src/sa/rulefactory.pxi | 3 +- python/src/sa/sym.pxi | 16 +- python/src/utils.pxd | 5 +- python/src/vectors.pxi | 26 +- 27 files changed, 69537 insertions(+), 64899 deletions(-) create mode 100644 python/cdec/configobj.py delete mode 100644 python/src/sa/_cdec_sa.c delete mode 100644 python/src/sa/_cdec_sa.pyx create mode 100644 python/src/sa/_sa.c create mode 100644 python/src/sa/_sa.pxd create mode 100644 python/src/sa/_sa.pyx (limited to 'python/src') diff --git a/python/README.md b/python/README.md index 1ddb61a9..da9f9387 100644 --- a/python/README.md +++ b/python/README.md @@ -2,10 +2,6 @@ pycdec is a Python interface to cdec ## Installation -pycdec depends on the configobj module: - - pip install configobj - Build and install pycdec: python setup.py install @@ -30,4 +26,4 @@ More documentation will come as the API becomes stable. --- -pycdec was contributed by [Victor Chahuneau](http://victor.chahuneau.fr) \ No newline at end of file +pycdec was contributed by [Victor Chahuneau](http://victor.chahuneau.fr) diff --git a/python/cdec/configobj.py b/python/cdec/configobj.py new file mode 100644 index 00000000..c1f6e6df --- /dev/null +++ b/python/cdec/configobj.py @@ -0,0 +1,2468 @@ +# configobj.py +# A config file reader/writer that supports nested sections in config files. +# Copyright (C) 2005-2010 Michael Foord, Nicola Larosa +# E-mail: fuzzyman AT voidspace DOT org DOT uk +# nico AT tekNico DOT net + +# ConfigObj 4 +# http://www.voidspace.org.uk/python/configobj.html + +# Released subject to the BSD License +# Please see http://www.voidspace.org.uk/python/license.shtml + +# Scripts maintained at http://www.voidspace.org.uk/python/index.shtml +# For information about bugfixes, updates and support, please join the +# ConfigObj mailing list: +# http://lists.sourceforge.net/lists/listinfo/configobj-develop +# Comments, suggestions and bug reports welcome. + +from __future__ import generators + +import os +import re +import sys + +from codecs import BOM_UTF8, BOM_UTF16, BOM_UTF16_BE, BOM_UTF16_LE + + +# imported lazily to avoid startup performance hit if it isn't used +compiler = None + +# A dictionary mapping BOM to +# the encoding to decode with, and what to set the +# encoding attribute to. +BOMS = { + BOM_UTF8: ('utf_8', None), + BOM_UTF16_BE: ('utf16_be', 'utf_16'), + BOM_UTF16_LE: ('utf16_le', 'utf_16'), + BOM_UTF16: ('utf_16', 'utf_16'), + } +# All legal variants of the BOM codecs. +# TODO: the list of aliases is not meant to be exhaustive, is there a +# better way ? +BOM_LIST = { + 'utf_16': 'utf_16', + 'u16': 'utf_16', + 'utf16': 'utf_16', + 'utf-16': 'utf_16', + 'utf16_be': 'utf16_be', + 'utf_16_be': 'utf16_be', + 'utf-16be': 'utf16_be', + 'utf16_le': 'utf16_le', + 'utf_16_le': 'utf16_le', + 'utf-16le': 'utf16_le', + 'utf_8': 'utf_8', + 'u8': 'utf_8', + 'utf': 'utf_8', + 'utf8': 'utf_8', + 'utf-8': 'utf_8', + } + +# Map of encodings to the BOM to write. +BOM_SET = { + 'utf_8': BOM_UTF8, + 'utf_16': BOM_UTF16, + 'utf16_be': BOM_UTF16_BE, + 'utf16_le': BOM_UTF16_LE, + None: BOM_UTF8 + } + + +def match_utf8(encoding): + return BOM_LIST.get(encoding.lower()) == 'utf_8' + + +# Quote strings used for writing values +squot = "'%s'" +dquot = '"%s"' +noquot = "%s" +wspace_plus = ' \r\n\v\t\'"' +tsquot = '"""%s"""' +tdquot = "'''%s'''" + +# Sentinel for use in getattr calls to replace hasattr +MISSING = object() + +__version__ = '4.7.2' + +try: + any +except NameError: + def any(iterable): + for entry in iterable: + if entry: + return True + return False + + +__all__ = ( + '__version__', + 'DEFAULT_INDENT_TYPE', + 'DEFAULT_INTERPOLATION', + 'ConfigObjError', + 'NestingError', + 'ParseError', + 'DuplicateError', + 'ConfigspecError', + 'ConfigObj', + 'SimpleVal', + 'InterpolationError', + 'InterpolationLoopError', + 'MissingInterpolationOption', + 'RepeatSectionError', + 'ReloadError', + 'UnreprError', + 'UnknownType', + 'flatten_errors', + 'get_extra_values' +) + +DEFAULT_INTERPOLATION = 'configparser' +DEFAULT_INDENT_TYPE = ' ' +MAX_INTERPOL_DEPTH = 10 + +OPTION_DEFAULTS = { + 'interpolation': True, + 'raise_errors': False, + 'list_values': True, + 'create_empty': False, + 'file_error': False, + 'configspec': None, + 'stringify': True, + # option may be set to one of ('', ' ', '\t') + 'indent_type': None, + 'encoding': None, + 'default_encoding': None, + 'unrepr': False, + 'write_empty_values': False, +} + + + +def getObj(s): + global compiler + if compiler is None: + import compiler + s = "a=" + s + p = compiler.parse(s) + return p.getChildren()[1].getChildren()[0].getChildren()[1] + + +class UnknownType(Exception): + pass + + +class Builder(object): + + def build(self, o): + m = getattr(self, 'build_' + o.__class__.__name__, None) + if m is None: + raise UnknownType(o.__class__.__name__) + return m(o) + + def build_List(self, o): + return map(self.build, o.getChildren()) + + def build_Const(self, o): + return o.value + + def build_Dict(self, o): + d = {} + i = iter(map(self.build, o.getChildren())) + for el in i: + d[el] = i.next() + return d + + def build_Tuple(self, o): + return tuple(self.build_List(o)) + + def build_Name(self, o): + if o.name == 'None': + return None + if o.name == 'True': + return True + if o.name == 'False': + return False + + # An undefined Name + raise UnknownType('Undefined Name') + + def build_Add(self, o): + real, imag = map(self.build_Const, o.getChildren()) + try: + real = float(real) + except TypeError: + raise UnknownType('Add') + if not isinstance(imag, complex) or imag.real != 0.0: + raise UnknownType('Add') + return real+imag + + def build_Getattr(self, o): + parent = self.build(o.expr) + return getattr(parent, o.attrname) + + def build_UnarySub(self, o): + return -self.build_Const(o.getChildren()[0]) + + def build_UnaryAdd(self, o): + return self.build_Const(o.getChildren()[0]) + + +_builder = Builder() + + +def unrepr(s): + if not s: + return s + return _builder.build(getObj(s)) + + + +class ConfigObjError(SyntaxError): + """ + This is the base class for all errors that ConfigObj raises. + It is a subclass of SyntaxError. + """ + def __init__(self, message='', line_number=None, line=''): + self.line = line + self.line_number = line_number + SyntaxError.__init__(self, message) + + +class NestingError(ConfigObjError): + """ + This error indicates a level of nesting that doesn't match. + """ + + +class ParseError(ConfigObjError): + """ + This error indicates that a line is badly written. + It is neither a valid ``key = value`` line, + nor a valid section marker line. + """ + + +class ReloadError(IOError): + """ + A 'reload' operation failed. + This exception is a subclass of ``IOError``. + """ + def __init__(self): + IOError.__init__(self, 'reload failed, filename is not set.') + + +class DuplicateError(ConfigObjError): + """ + The keyword or section specified already exists. + """ + + +class ConfigspecError(ConfigObjError): + """ + An error occured whilst parsing a configspec. + """ + + +class InterpolationError(ConfigObjError): + """Base class for the two interpolation errors.""" + + +class InterpolationLoopError(InterpolationError): + """Maximum interpolation depth exceeded in string interpolation.""" + + def __init__(self, option): + InterpolationError.__init__( + self, + 'interpolation loop detected in value "%s".' % option) + + +class RepeatSectionError(ConfigObjError): + """ + This error indicates additional sections in a section with a + ``__many__`` (repeated) section. + """ + + +class MissingInterpolationOption(InterpolationError): + """A value specified for interpolation was missing.""" + def __init__(self, option): + msg = 'missing option "%s" in interpolation.' % option + InterpolationError.__init__(self, msg) + + +class UnreprError(ConfigObjError): + """An error parsing in unrepr mode.""" + + + +class InterpolationEngine(object): + """ + A helper class to help perform string interpolation. + + This class is an abstract base class; its descendants perform + the actual work. + """ + + # compiled regexp to use in self.interpolate() + _KEYCRE = re.compile(r"%\(([^)]*)\)s") + _cookie = '%' + + def __init__(self, section): + # the Section instance that "owns" this engine + self.section = section + + + def interpolate(self, key, value): + # short-cut + if not self._cookie in value: + return value + + def recursive_interpolate(key, value, section, backtrail): + """The function that does the actual work. + + ``value``: the string we're trying to interpolate. + ``section``: the section in which that string was found + ``backtrail``: a dict to keep track of where we've been, + to detect and prevent infinite recursion loops + + This is similar to a depth-first-search algorithm. + """ + # Have we been here already? + if (key, section.name) in backtrail: + # Yes - infinite loop detected + raise InterpolationLoopError(key) + # Place a marker on our backtrail so we won't come back here again + backtrail[(key, section.name)] = 1 + + # Now start the actual work + match = self._KEYCRE.search(value) + while match: + # The actual parsing of the match is implementation-dependent, + # so delegate to our helper function + k, v, s = self._parse_match(match) + if k is None: + # That's the signal that no further interpolation is needed + replacement = v + else: + # Further interpolation may be needed to obtain final value + replacement = recursive_interpolate(k, v, s, backtrail) + # Replace the matched string with its final value + start, end = match.span() + value = ''.join((value[:start], replacement, value[end:])) + new_search_start = start + len(replacement) + # Pick up the next interpolation key, if any, for next time + # through the while loop + match = self._KEYCRE.search(value, new_search_start) + + # Now safe to come back here again; remove marker from backtrail + del backtrail[(key, section.name)] + + return value + + # Back in interpolate(), all we have to do is kick off the recursive + # function with appropriate starting values + value = recursive_interpolate(key, value, self.section, {}) + return value + + + def _fetch(self, key): + """Helper function to fetch values from owning section. + + Returns a 2-tuple: the value, and the section where it was found. + """ + # switch off interpolation before we try and fetch anything ! + save_interp = self.section.main.interpolation + self.section.main.interpolation = False + + # Start at section that "owns" this InterpolationEngine + current_section = self.section + while True: + # try the current section first + val = current_section.get(key) + if val is not None and not isinstance(val, Section): + break + # try "DEFAULT" next + val = current_section.get('DEFAULT', {}).get(key) + if val is not None and not isinstance(val, Section): + break + # move up to parent and try again + # top-level's parent is itself + if current_section.parent is current_section: + # reached top level, time to give up + break + current_section = current_section.parent + + # restore interpolation to previous value before returning + self.section.main.interpolation = save_interp + if val is None: + raise MissingInterpolationOption(key) + return val, current_section + + + def _parse_match(self, match): + """Implementation-dependent helper function. + + Will be passed a match object corresponding to the interpolation + key we just found (e.g., "%(foo)s" or "$foo"). Should look up that + key in the appropriate config file section (using the ``_fetch()`` + helper function) and return a 3-tuple: (key, value, section) + + ``key`` is the name of the key we're looking for + ``value`` is the value found for that key + ``section`` is a reference to the section where it was found + + ``key`` and ``section`` should be None if no further + interpolation should be performed on the resulting value + (e.g., if we interpolated "$$" and returned "$"). + """ + raise NotImplementedError() + + + +class ConfigParserInterpolation(InterpolationEngine): + """Behaves like ConfigParser.""" + _cookie = '%' + _KEYCRE = re.compile(r"%\(([^)]*)\)s") + + def _parse_match(self, match): + key = match.group(1) + value, section = self._fetch(key) + return key, value, section + + + +class TemplateInterpolation(InterpolationEngine): + """Behaves like string.Template.""" + _cookie = '$' + _delimiter = '$' + _KEYCRE = re.compile(r""" + \$(?: + (?P\$) | # Two $ signs + (?P[_a-z][_a-z0-9]*) | # $name format + {(?P[^}]*)} # ${name} format + ) + """, re.IGNORECASE | re.VERBOSE) + + def _parse_match(self, match): + # Valid name (in or out of braces): fetch value from section + key = match.group('named') or match.group('braced') + if key is not None: + value, section = self._fetch(key) + return key, value, section + # Escaped delimiter (e.g., $$): return single delimiter + if match.group('escaped') is not None: + # Return None for key and section to indicate it's time to stop + return None, self._delimiter, None + # Anything else: ignore completely, just return it unchanged + return None, match.group(), None + + +interpolation_engines = { + 'configparser': ConfigParserInterpolation, + 'template': TemplateInterpolation, +} + + +def __newobj__(cls, *args): + # Hack for pickle + return cls.__new__(cls, *args) + +class Section(dict): + """ + A dictionary-like object that represents a section in a config file. + + It does string interpolation if the 'interpolation' attribute + of the 'main' object is set to True. + + Interpolation is tried first from this object, then from the 'DEFAULT' + section of this object, next from the parent and its 'DEFAULT' section, + and so on until the main object is reached. + + A Section will behave like an ordered dictionary - following the + order of the ``scalars`` and ``sections`` attributes. + You can use this to change the order of members. + + Iteration follows the order: scalars, then sections. + """ + + + def __setstate__(self, state): + dict.update(self, state[0]) + self.__dict__.update(state[1]) + + def __reduce__(self): + state = (dict(self), self.__dict__) + return (__newobj__, (self.__class__,), state) + + + def __init__(self, parent, depth, main, indict=None, name=None): + """ + * parent is the section above + * depth is the depth level of this section + * main is the main ConfigObj + * indict is a dictionary to initialise the section with + """ + if indict is None: + indict = {} + dict.__init__(self) + # used for nesting level *and* interpolation + self.parent = parent + # used for the interpolation attribute + self.main = main + # level of nesting depth of this Section + self.depth = depth + # purely for information + self.name = name + # + self._initialise() + # we do this explicitly so that __setitem__ is used properly + # (rather than just passing to ``dict.__init__``) + for entry, value in indict.iteritems(): + self[entry] = value + + + def _initialise(self): + # the sequence of scalar values in this Section + self.scalars = [] + # the sequence of sections in this Section + self.sections = [] + # for comments :-) + self.comments = {} + self.inline_comments = {} + # the configspec + self.configspec = None + # for defaults + self.defaults = [] + self.default_values = {} + self.extra_values = [] + self._created = False + + + def _interpolate(self, key, value): + try: + # do we already have an interpolation engine? + engine = self._interpolation_engine + except AttributeError: + # not yet: first time running _interpolate(), so pick the engine + name = self.main.interpolation + if name == True: # note that "if name:" would be incorrect here + # backwards-compatibility: interpolation=True means use default + name = DEFAULT_INTERPOLATION + name = name.lower() # so that "Template", "template", etc. all work + class_ = interpolation_engines.get(name, None) + if class_ is None: + # invalid value for self.main.interpolation + self.main.interpolation = False + return value + else: + # save reference to engine so we don't have to do this again + engine = self._interpolation_engine = class_(self) + # let the engine do the actual work + return engine.interpolate(key, value) + + + def __getitem__(self, key): + """Fetch the item and do string interpolation.""" + val = dict.__getitem__(self, key) + if self.main.interpolation: + if isinstance(val, basestring): + return self._interpolate(key, val) + if isinstance(val, list): + def _check(entry): + if isinstance(entry, basestring): + return self._interpolate(key, entry) + return entry + new = [_check(entry) for entry in val] + if new != val: + return new + return val + + + def __setitem__(self, key, value, unrepr=False): + """ + Correctly set a value. + + Making dictionary values Section instances. + (We have to special case 'Section' instances - which are also dicts) + + Keys must be strings. + Values need only be strings (or lists of strings) if + ``main.stringify`` is set. + + ``unrepr`` must be set when setting a value to a dictionary, without + creating a new sub-section. + """ + if not isinstance(key, basestring): + raise ValueError('The key "%s" is not a string.' % key) + + # add the comment + if key not in self.comments: + self.comments[key] = [] + self.inline_comments[key] = '' + # remove the entry from defaults + if key in self.defaults: + self.defaults.remove(key) + # + if isinstance(value, Section): + if key not in self: + self.sections.append(key) + dict.__setitem__(self, key, value) + elif isinstance(value, dict) and not unrepr: + # First create the new depth level, + # then create the section + if key not in self: + self.sections.append(key) + new_depth = self.depth + 1 + dict.__setitem__( + self, + key, + Section( + self, + new_depth, + self.main, + indict=value, + name=key)) + else: + if key not in self: + self.scalars.append(key) + if not self.main.stringify: + if isinstance(value, basestring): + pass + elif isinstance(value, (list, tuple)): + for entry in value: + if not isinstance(entry, basestring): + raise TypeError('Value is not a string "%s".' % entry) + else: + raise TypeError('Value is not a string "%s".' % value) + dict.__setitem__(self, key, value) + + + def __delitem__(self, key): + """Remove items from the sequence when deleting.""" + dict. __delitem__(self, key) + if key in self.scalars: + self.scalars.remove(key) + else: + self.sections.remove(key) + del self.comments[key] + del self.inline_comments[key] + + + def get(self, key, default=None): + """A version of ``get`` that doesn't bypass string interpolation.""" + try: + return self[key] + except KeyError: + return default + + + def update(self, indict): + """ + A version of update that uses our ``__setitem__``. + """ + for entry in indict: + self[entry] = indict[entry] + + + def pop(self, key, default=MISSING): + """ + 'D.pop(k[,d]) -> v, remove specified key and return the corresponding value. + If key is not found, d is returned if given, otherwise KeyError is raised' + """ + try: + val = self[key] + except KeyError: + if default is MISSING: + raise + val = default + else: + del self[key] + return val + + + def popitem(self): + """Pops the first (key,val)""" + sequence = (self.scalars + self.sections) + if not sequence: + raise KeyError(": 'popitem(): dictionary is empty'") + key = sequence[0] + val = self[key] + del self[key] + return key, val + + + def clear(self): + """ + A version of clear that also affects scalars/sections + Also clears comments and configspec. + + Leaves other attributes alone : + depth/main/parent are not affected + """ + dict.clear(self) + self.scalars = [] + self.sections = [] + self.comments = {} + self.inline_comments = {} + self.configspec = None + self.defaults = [] + self.extra_values = [] + + + def setdefault(self, key, default=None): + """A version of setdefault that sets sequence if appropriate.""" + try: + return self[key] + except KeyError: + self[key] = default + return self[key] + + + def items(self): + """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + return zip((self.scalars + self.sections), self.values()) + + + def keys(self): + """D.keys() -> list of D's keys""" + return (self.scalars + self.sections) + + + def values(self): + """D.values() -> list of D's values""" + return [self[key] for key in (self.scalars + self.sections)] + + + def iteritems(self): + """D.iteritems() -> an iterator over the (key, value) items of D""" + return iter(self.items()) + + + def iterkeys(self): + """D.iterkeys() -> an iterator over the keys of D""" + return iter((self.scalars + self.sections)) + + __iter__ = iterkeys + + + def itervalues(self): + """D.itervalues() -> an iterator over the values of D""" + return iter(self.values()) + + + def __repr__(self): + """x.__repr__() <==> repr(x)""" + def _getval(key): + try: + return self[key] + except MissingInterpolationOption: + return dict.__getitem__(self, key) + return '{%s}' % ', '.join([('%s: %s' % (repr(key), repr(_getval(key)))) + for key in (self.scalars + self.sections)]) + + __str__ = __repr__ + __str__.__doc__ = "x.__str__() <==> str(x)" + + + # Extra methods - not in a normal dictionary + + def dict(self): + """ + Return a deepcopy of self as a dictionary. + + All members that are ``Section`` instances are recursively turned to + ordinary dictionaries - by calling their ``dict`` method. + + >>> n = a.dict() + >>> n == a + 1 + >>> n is a + 0 + """ + newdict = {} + for entry in self: + this_entry = self[entry] + if isinstance(this_entry, Section): + this_entry = this_entry.dict() + elif isinstance(this_entry, list): + # create a copy rather than a reference + this_entry = list(this_entry) + elif isinstance(this_entry, tuple): + # create a copy rather than a reference + this_entry = tuple(this_entry) + newdict[entry] = this_entry + return newdict + + + def merge(self, indict): + """ + A recursive update - useful for merging config files. + + >>> a = '''[section1] + ... option1 = True + ... [[subsection]] + ... more_options = False + ... # end of file'''.splitlines() + >>> b = '''# File is user.ini + ... [section1] + ... option1 = False + ... # end of file'''.splitlines() + >>> c1 = ConfigObj(b) + >>> c2 = ConfigObj(a) + >>> c2.merge(c1) + >>> c2 + ConfigObj({'section1': {'option1': 'False', 'subsection': {'more_options': 'False'}}}) + """ + for key, val in indict.items(): + if (key in self and isinstance(self[key], dict) and + isinstance(val, dict)): + self[key].merge(val) + else: + self[key] = val + + + def rename(self, oldkey, newkey): + """ + Change a keyname to another, without changing position in sequence. + + Implemented so that transformations can be made on keys, + as well as on values. (used by encode and decode) + + Also renames comments. + """ + if oldkey in self.scalars: + the_list = self.scalars + elif oldkey in self.sections: + the_list = self.sections + else: + raise KeyError('Key "%s" not found.' % oldkey) + pos = the_list.index(oldkey) + # + val = self[oldkey] + dict.__delitem__(self, oldkey) + dict.__setitem__(self, newkey, val) + the_list.remove(oldkey) + the_list.insert(pos, newkey) + comm = self.comments[oldkey] + inline_comment = self.inline_comments[oldkey] + del self.comments[oldkey] + del self.inline_comments[oldkey] + self.comments[newkey] = comm + self.inline_comments[newkey] = inline_comment + + + def walk(self, function, raise_errors=True, + call_on_sections=False, **keywargs): + """ + Walk every member and call a function on the keyword and value. + + Return a dictionary of the return values + + If the function raises an exception, raise the errror + unless ``raise_errors=False``, in which case set the return value to + ``False``. + + Any unrecognised keyword arguments you pass to walk, will be pased on + to the function you pass in. + + Note: if ``call_on_sections`` is ``True`` then - on encountering a + subsection, *first* the function is called for the *whole* subsection, + and then recurses into it's members. This means your function must be + able to handle strings, dictionaries and lists. This allows you + to change the key of subsections as well as for ordinary members. The + return value when called on the whole subsection has to be discarded. + + See the encode and decode methods for examples, including functions. + + .. admonition:: caution + + You can use ``walk`` to transform the names of members of a section + but you mustn't add or delete members. + + >>> config = '''[XXXXsection] + ... XXXXkey = XXXXvalue'''.splitlines() + >>> cfg = ConfigObj(config) + >>> cfg + ConfigObj({'XXXXsection': {'XXXXkey': 'XXXXvalue'}}) + >>> def transform(section, key): + ... val = section[key] + ... newkey = key.replace('XXXX', 'CLIENT1') + ... section.rename(key, newkey) + ... if isinstance(val, (tuple, list, dict)): + ... pass + ... else: + ... val = val.replace('XXXX', 'CLIENT1') + ... section[newkey] = val + >>> cfg.walk(transform, call_on_sections=True) + {'CLIENT1section': {'CLIENT1key': None}} + >>> cfg + ConfigObj({'CLIENT1section': {'CLIENT1key': 'CLIENT1value'}}) + """ + out = {} + # scalars first + for i in range(len(self.scalars)): + entry = self.scalars[i] + try: + val = function(self, entry, **keywargs) + # bound again in case name has changed + entry = self.scalars[i] + out[entry] = val + except Exception: + if raise_errors: + raise + else: + entry = self.scalars[i] + out[entry] = False + # then sections + for i in range(len(self.sections)): + entry = self.sections[i] + if call_on_sections: + try: + function(self, entry, **keywargs) + except Exception: + if raise_errors: + raise + else: + entry = self.sections[i] + out[entry] = False + # bound again in case name has changed + entry = self.sections[i] + # previous result is discarded + out[entry] = self[entry].walk( + function, + raise_errors=raise_errors, + call_on_sections=call_on_sections, + **keywargs) + return out + + + def as_bool(self, key): + """ + Accepts a key as input. The corresponding value must be a string or + the objects (``True`` or 1) or (``False`` or 0). We allow 0 and 1 to + retain compatibility with Python 2.2. + + If the string is one of ``True``, ``On``, ``Yes``, or ``1`` it returns + ``True``. + + If the string is one of ``False``, ``Off``, ``No``, or ``0`` it returns + ``False``. + + ``as_bool`` is not case sensitive. + + Any other input will raise a ``ValueError``. + + >>> a = ConfigObj() + >>> a['a'] = 'fish' + >>> a.as_bool('a') + Traceback (most recent call last): + ValueError: Value "fish" is neither True nor False + >>> a['b'] = 'True' + >>> a.as_bool('b') + 1 + >>> a['b'] = 'off' + >>> a.as_bool('b') + 0 + """ + val = self[key] + if val == True: + return True + elif val == False: + return False + else: + try: + if not isinstance(val, basestring): + # TODO: Why do we raise a KeyError here? + raise KeyError() + else: + return self.main._bools[val.lower()] + except KeyError: + raise ValueError('Value "%s" is neither True nor False' % val) + + + def as_int(self, key): + """ + A convenience method which coerces the specified value to an integer. + + If the value is an invalid literal for ``int``, a ``ValueError`` will + be raised. + + >>> a = ConfigObj() + >>> a['a'] = 'fish' + >>> a.as_int('a') + Traceback (most recent call last): + ValueError: invalid literal for int() with base 10: 'fish' + >>> a['b'] = '1' + >>> a.as_int('b') + 1 + >>> a['b'] = '3.2' + >>> a.as_int('b') + Traceback (most recent call last): + ValueError: invalid literal for int() with base 10: '3.2' + """ + return int(self[key]) + + + def as_float(self, key): + """ + A convenience method which coerces the specified value to a float. + + If the value is an invalid literal for ``float``, a ``ValueError`` will + be raised. + + >>> a = ConfigObj() + >>> a['a'] = 'fish' + >>> a.as_float('a') + Traceback (most recent call last): + ValueError: invalid literal for float(): fish + >>> a['b'] = '1' + >>> a.as_float('b') + 1.0 + >>> a['b'] = '3.2' + >>> a.as_float('b') + 3.2000000000000002 + """ + return float(self[key]) + + + def as_list(self, key): + """ + A convenience method which fetches the specified value, guaranteeing + that it is a list. + + >>> a = ConfigObj() + >>> a['a'] = 1 + >>> a.as_list('a') + [1] + >>> a['a'] = (1,) + >>> a.as_list('a') + [1] + >>> a['a'] = [1] + >>> a.as_list('a') + [1] + """ + result = self[key] + if isinstance(result, (tuple, list)): + return list(result) + return [result] + + + def restore_default(self, key): + """ + Restore (and return) default value for the specified key. + + This method will only work for a ConfigObj that was created + with a configspec and has been validated. + + If there is no default value for this key, ``KeyError`` is raised. + """ + default = self.default_values[key] + dict.__setitem__(self, key, default) + if key not in self.defaults: + self.defaults.append(key) + return default + + + def restore_defaults(self): + """ + Recursively restore default values to all members + that have them. + + This method will only work for a ConfigObj that was created + with a configspec and has been validated. + + It doesn't delete or modify entries without default values. + """ + for key in self.default_values: + self.restore_default(key) + + for section in self.sections: + self[section].restore_defaults() + + +class ConfigObj(Section): + """An object to read, create, and write config files.""" + + _keyword = re.compile(r'''^ # line start + (\s*) # indentation + ( # keyword + (?:".*?")| # double quotes + (?:'.*?')| # single quotes + (?:[^'"=].*?) # no quotes + ) + \s*=\s* # divider + (.*) # value (including list values and comments) + $ # line end + ''', + re.VERBOSE) + + _sectionmarker = re.compile(r'''^ + (\s*) # 1: indentation + ((?:\[\s*)+) # 2: section marker open + ( # 3: section name open + (?:"\s*\S.*?\s*")| # at least one non-space with double quotes + (?:'\s*\S.*?\s*')| # at least one non-space with single quotes + (?:[^'"\s].*?) # at least one non-space unquoted + ) # section name close + ((?:\s*\])+) # 4: section marker close + \s*(\#.*)? # 5: optional comment + $''', + re.VERBOSE) + + # this regexp pulls list values out as a single string + # or single values and comments + # FIXME: this regex adds a '' to the end of comma terminated lists + # workaround in ``_handle_value`` + _valueexp = re.compile(r'''^ + (?: + (?: + ( + (?: + (?: + (?:".*?")| # double quotes + (?:'.*?')| # single quotes + (?:[^'",\#][^,\#]*?) # unquoted + ) + \s*,\s* # comma + )* # match all list items ending in a comma (if any) + ) + ( + (?:".*?")| # double quotes + (?:'.*?')| # single quotes + (?:[^'",\#\s][^,]*?)| # unquoted + (?:(? 1: + msg = "Parsing failed with several errors.\nFirst error %s" % info + error = ConfigObjError(msg) + else: + error = self._errors[0] + # set the errors attribute; it's a list of tuples: + # (error_type, message, line_number) + error.errors = self._errors + # set the config attribute + error.config = self + raise error + # delete private attributes + del self._errors + + if configspec is None: + self.configspec = None + else: + self._handle_configspec(configspec) + + + def _initialise(self, options=None): + if options is None: + options = OPTION_DEFAULTS + + # initialise a few variables + self.filename = None + self._errors = [] + self.raise_errors = options['raise_errors'] + self.interpolation = options['interpolation'] + self.list_values = options['list_values'] + self.create_empty = options['create_empty'] + self.file_error = options['file_error'] + self.stringify = options['stringify'] + self.indent_type = options['indent_type'] + self.encoding = options['encoding'] + self.default_encoding = options['default_encoding'] + self.BOM = False + self.newlines = None + self.write_empty_values = options['write_empty_values'] + self.unrepr = options['unrepr'] + + self.initial_comment = [] + self.final_comment = [] + self.configspec = None + + if self._inspec: + self.list_values = False + + # Clear section attributes as well + Section._initialise(self) + + + def __repr__(self): + def _getval(key): + try: + return self[key] + except MissingInterpolationOption: + return dict.__getitem__(self, key) + return ('ConfigObj({%s})' % + ', '.join([('%s: %s' % (repr(key), repr(_getval(key)))) + for key in (self.scalars + self.sections)])) + + + def _handle_bom(self, infile): + """ + Handle any BOM, and decode if necessary. + + If an encoding is specified, that *must* be used - but the BOM should + still be removed (and the BOM attribute set). + + (If the encoding is wrongly specified, then a BOM for an alternative + encoding won't be discovered or removed.) + + If an encoding is not specified, UTF8 or UTF16 BOM will be detected and + removed. The BOM attribute will be set. UTF16 will be decoded to + unicode. + + NOTE: This method must not be called with an empty ``infile``. + + Specifying the *wrong* encoding is likely to cause a + ``UnicodeDecodeError``. + + ``infile`` must always be returned as a list of lines, but may be + passed in as a single string. + """ + if ((self.encoding is not None) and + (self.encoding.lower() not in BOM_LIST)): + # No need to check for a BOM + # the encoding specified doesn't have one + # just decode + return self._decode(infile, self.encoding) + + if isinstance(infile, (list, tuple)): + line = infile[0] + else: + line = infile + if self.encoding is not None: + # encoding explicitly supplied + # And it could have an associated BOM + # TODO: if encoding is just UTF16 - we ought to check for both + # TODO: big endian and little endian versions. + enc = BOM_LIST[self.encoding.lower()] + if enc == 'utf_16': + # For UTF16 we try big endian and little endian + for BOM, (encoding, final_encoding) in BOMS.items(): + if not final_encoding: + # skip UTF8 + continue + if infile.startswith(BOM): + ### BOM discovered + ##self.BOM = True + # Don't need to remove BOM + return self._decode(infile, encoding) + + # If we get this far, will *probably* raise a DecodeError + # As it doesn't appear to start with a BOM + return self._decode(infile, self.encoding) + + # Must be UTF8 + BOM = BOM_SET[enc] + if not line.startswith(BOM): + return self._decode(infile, self.encoding) + + newline = line[len(BOM):] + + # BOM removed + if isinstance(infile, (list, tuple)): + infile[0] = newline + else: + infile = newline + self.BOM = True + return self._decode(infile, self.encoding) + + # No encoding specified - so we need to check for UTF8/UTF16 + for BOM, (encoding, final_encoding) in BOMS.items(): + if not line.startswith(BOM): + continue + else: + # BOM discovered + self.encoding = final_encoding + if not final_encoding: + self.BOM = True + # UTF8 + # remove BOM + newline = line[len(BOM):] + if isinstance(infile, (list, tuple)): + infile[0] = newline + else: + infile = newline + # UTF8 - don't decode + if isinstance(infile, basestring): + return infile.splitlines(True) + else: + return infile + # UTF16 - have to decode + return self._decode(infile, encoding) + + # No BOM discovered and no encoding specified, just return + if isinstance(infile, basestring): + # infile read from a file will be a single string + return infile.splitlines(True) + return infile + + + def _a_to_u(self, aString): + """Decode ASCII strings to unicode if a self.encoding is specified.""" + if self.encoding: + return aString.decode('ascii') + else: + return aString + + + def _decode(self, infile, encoding): + """ + Decode infile to unicode. Using the specified encoding. + + if is a string, it also needs converting to a list. + """ + if isinstance(infile, basestring): + # can't be unicode + # NOTE: Could raise a ``UnicodeDecodeError`` + return infile.decode(encoding).splitlines(True) + for i, line in enumerate(infile): + if not isinstance(line, unicode): + # NOTE: The isinstance test here handles mixed lists of unicode/string + # NOTE: But the decode will break on any non-string values + # NOTE: Or could raise a ``UnicodeDecodeError`` + infile[i] = line.decode(encoding) + return infile + + + def _decode_element(self, line): + """Decode element to unicode if necessary.""" + if not self.encoding: + return line + if isinstance(line, str) and self.default_encoding: + return line.decode(self.default_encoding) + return line + + + def _str(self, value): + """ + Used by ``stringify`` within validate, to turn non-string values + into strings. + """ + if not isinstance(value, basestring): + return str(value) + else: + return value + + + def _parse(self, infile): + """Actually parse the config file.""" + temp_list_values = self.list_values + if self.unrepr: + self.list_values = False + + comment_list = [] + done_start = False + this_section = self + maxline = len(infile) - 1 + cur_index = -1 + reset_comment = False + + while cur_index < maxline: + if reset_comment: + comment_list = [] + cur_index += 1 + line = infile[cur_index] + sline = line.strip() + # do we have anything on the line ? + if not sline or sline.startswith('#'): + reset_comment = False + comment_list.append(line) + continue + + if not done_start: + # preserve initial comment + self.initial_comment = comment_list + comment_list = [] + done_start = True + + reset_comment = True + # first we check if it's a section marker + mat = self._sectionmarker.match(line) + if mat is not None: + # is a section line + (indent, sect_open, sect_name, sect_close, comment) = mat.groups() + if indent and (self.indent_type is None): + self.indent_type = indent + cur_depth = sect_open.count('[') + if cur_depth != sect_close.count(']'): + self._handle_error("Cannot compute the section depth at line %s.", + NestingError, infile, cur_index) + continue + + if cur_depth < this_section.depth: + # the new section is dropping back to a previous level + try: + parent = self._match_depth(this_section, + cur_depth).parent + except SyntaxError: + self._handle_error("Cannot compute nesting level at line %s.", + NestingError, infile, cur_index) + continue + elif cur_depth == this_section.depth: + # the new section is a sibling of the current section + parent = this_section.parent + elif cur_depth == this_section.depth + 1: + # the new section is a child the current section + parent = this_section + else: + self._handle_error("Section too nested at line %s.", + NestingError, infile, cur_index) + + sect_name = self._unquote(sect_name) + if sect_name in parent: + self._handle_error('Duplicate section name at line %s.', + DuplicateError, infile, cur_index) + continue + + # create the new section + this_section = Section( + parent, + cur_depth, + self, + name=sect_name) + parent[sect_name] = this_section + parent.inline_comments[sect_name] = comment + parent.comments[sect_name] = comment_list + continue + # + # it's not a section marker, + # so it should be a valid ``key = value`` line + mat = self._keyword.match(line) + if mat is None: + # it neither matched as a keyword + # or a section marker + self._handle_error( + 'Invalid line at line "%s".', + ParseError, infile, cur_index) + else: + # is a keyword value + # value will include any inline comment + (indent, key, value) = mat.groups() + if indent and (self.indent_type is None): + self.indent_type = indent + # check for a multiline value + if value[:3] in ['"""', "'''"]: + try: + value, comment, cur_index = self._multiline( + value, infile, cur_index, maxline) + except SyntaxError: + self._handle_error( + 'Parse error in value at line %s.', + ParseError, infile, cur_index) + continue + else: + if self.unrepr: + comment = '' + try: + value = unrepr(value) + except Exception, e: + if type(e) == UnknownType: + msg = 'Unknown name or type in value at line %s.' + else: + msg = 'Parse error in value at line %s.' + self._handle_error(msg, UnreprError, infile, + cur_index) + continue + else: + if self.unrepr: + comment = '' + try: + value = unrepr(value) + except Exception, e: + if isinstance(e, UnknownType): + msg = 'Unknown name or type in value at line %s.' + else: + msg = 'Parse error in value at line %s.' + self._handle_error(msg, UnreprError, infile, + cur_index) + continue + else: + # extract comment and lists + try: + (value, comment) = self._handle_value(value) + except SyntaxError: + self._handle_error( + 'Parse error in value at line %s.', + ParseError, infile, cur_index) + continue + # + key = self._unquote(key) + if key in this_section: + self._handle_error( + 'Duplicate keyword name at line %s.', + DuplicateError, infile, cur_index) + continue + # add the key. + # we set unrepr because if we have got this far we will never + # be creating a new section + this_section.__setitem__(key, value, unrepr=True) + this_section.inline_comments[key] = comment + this_section.comments[key] = comment_list + continue + # + if self.indent_type is None: + # no indentation used, set the type accordingly + self.indent_type = '' + + # preserve the final comment + if not self and not self.initial_comment: + self.initial_comment = comment_list + elif not reset_comment: + self.final_comment = comment_list + self.list_values = temp_list_values + + + def _match_depth(self, sect, depth): + """ + Given a section and a depth level, walk back through the sections + parents to see if the depth level matches a previous section. + + Return a reference to the right section, + or raise a SyntaxError. + """ + while depth < sect.depth: + if sect is sect.parent: + # we've reached the top level already + raise SyntaxError() + sect = sect.parent + if sect.depth == depth: + return sect + # shouldn't get here + raise SyntaxError() + + + def _handle_error(self, text, ErrorClass, infile, cur_index): + """ + Handle an error according to the error settings. + + Either raise the error or store it. + The error will have occured at ``cur_index`` + """ + line = infile[cur_index] + cur_index += 1 + message = text % cur_index + error = ErrorClass(message, cur_index, line) + if self.raise_errors: + # raise the error - parsing stops here + raise error + # store the error + # reraise when parsing has finished + self._errors.append(error) + + + def _unquote(self, value): + """Return an unquoted version of a value""" + if not value: + # should only happen during parsing of lists + raise SyntaxError + if (value[0] == value[-1]) and (value[0] in ('"', "'")): + value = value[1:-1] + return value + + + def _quote(self, value, multiline=True): + """ + Return a safely quoted version of a value. + + Raise a ConfigObjError if the value cannot be safely quoted. + If multiline is ``True`` (default) then use triple quotes + if necessary. + + * Don't quote values that don't need it. + * Recursively quote members of a list and return a comma joined list. + * Multiline is ``False`` for lists. + * Obey list syntax for empty and single member lists. + + If ``list_values=False`` then the value is only quoted if it contains + a ``\\n`` (is multiline) or '#'. + + If ``write_empty_values`` is set, and the value is an empty string, it + won't be quoted. + """ + if multiline and self.write_empty_values and value == '': + # Only if multiline is set, so that it is used for values not + # keys, and not values that are part of a list + return '' + + if multiline and isinstance(value, (list, tuple)): + if not value: + return ',' + elif len(value) == 1: + return self._quote(value[0], multiline=False) + ',' + return ', '.join([self._quote(val, multiline=False) + for val in value]) + if not isinstance(value, basestring): + if self.stringify: + value = str(value) + else: + raise TypeError('Value "%s" is not a string.' % value) + + if not value: + return '""' + + no_lists_no_quotes = not self.list_values and '\n' not in value and '#' not in value + need_triple = multiline and ((("'" in value) and ('"' in value)) or ('\n' in value )) + hash_triple_quote = multiline and not need_triple and ("'" in value) and ('"' in value) and ('#' in value) + check_for_single = (no_lists_no_quotes or not need_triple) and not hash_triple_quote + + if check_for_single: + if not self.list_values: + # we don't quote if ``list_values=False`` + quot = noquot + # for normal values either single or double quotes will do + elif '\n' in value: + # will only happen if multiline is off - e.g. '\n' in key + raise ConfigObjError('Value "%s" cannot be safely quoted.' % value) + elif ((value[0] not in wspace_plus) and + (value[-1] not in wspace_plus) and + (',' not in value)): + quot = noquot + else: + quot = self._get_single_quote(value) + else: + # if value has '\n' or "'" *and* '"', it will need triple quotes + quot = self._get_triple_quote(value) + + if quot == noquot and '#' in value and self.list_values: + quot = self._get_single_quote(value) + + return quot % value + + + def _get_single_quote(self, value): + if ("'" in value) and ('"' in value): + raise ConfigObjError('Value "%s" cannot be safely quoted.' % value) + elif '"' in value: + quot = squot + else: + quot = dquot + return quot + + + def _get_triple_quote(self, value): + if (value.find('"""') != -1) and (value.find("'''") != -1): + raise ConfigObjError('Value "%s" cannot be safely quoted.' % value) + if value.find('"""') == -1: + quot = tdquot + else: + quot = tsquot + return quot + + + def _handle_value(self, value): + """ + Given a value string, unquote, remove comment, + handle lists. (including empty and single member lists) + """ + if self._inspec: + # Parsing a configspec so don't handle comments + return (value, '') + # do we look for lists in values ? + if not self.list_values: + mat = self._nolistvalue.match(value) + if mat is None: + raise SyntaxError() + # NOTE: we don't unquote here + return mat.groups() + # + mat = self._valueexp.match(value) + if mat is None: + # the value is badly constructed, probably badly quoted, + # or an invalid list + raise SyntaxError() + (list_values, single, empty_list, comment) = mat.groups() + if (list_values == '') and (single is None): + # change this if you want to accept empty values + raise SyntaxError() + # NOTE: note there is no error handling from here if the regex + # is wrong: then incorrect values will slip through + if empty_list is not None: + # the single comma - meaning an empty list + return ([], comment) + if single is not None: + # handle empty values + if list_values and not single: + # FIXME: the '' is a workaround because our regex now matches + # '' at the end of a list if it has a trailing comma + single = None + else: + single = single or '""' + single = self._unquote(single) + if list_values == '': + # not a list value + return (single, comment) + the_list = self._listvalueexp.findall(list_values) + the_list = [self._unquote(val) for val in the_list] + if single is not None: + the_list += [single] + return (the_list, comment) + + + def _multiline(self, value, infile, cur_index, maxline): + """Extract the value, where we are in a multiline situation.""" + quot = value[:3] + newvalue = value[3:] + single_line = self._triple_quote[quot][0] + multi_line = self._triple_quote[quot][1] + mat = single_line.match(value) + if mat is not None: + retval = list(mat.groups()) + retval.append(cur_index) + return retval + elif newvalue.find(quot) != -1: + # somehow the triple quote is missing + raise SyntaxError() + # + while cur_index < maxline: + cur_index += 1 + newvalue += '\n' + line = infile[cur_index] + if line.find(quot) == -1: + newvalue += line + else: + # end of multiline, process it + break + else: + # we've got to the end of the config, oops... + raise SyntaxError() + mat = multi_line.match(line) + if mat is None: + # a badly formed line + raise SyntaxError() + (value, comment) = mat.groups() + return (newvalue + value, comment, cur_index) + + + def _handle_configspec(self, configspec): + """Parse the configspec.""" + # FIXME: Should we check that the configspec was created with the + # correct settings ? (i.e. ``list_values=False``) + if not isinstance(configspec, ConfigObj): + try: + configspec = ConfigObj(configspec, + raise_errors=True, + file_error=True, + _inspec=True) + except ConfigObjError, e: + # FIXME: Should these errors have a reference + # to the already parsed ConfigObj ? + raise ConfigspecError('Parsing configspec failed: %s' % e) + except IOError, e: + raise IOError('Reading configspec failed: %s' % e) + + self.configspec = configspec + + + + def _set_configspec(self, section, copy): + """ + Called by validate. Handles setting the configspec on subsections + including sections to be validated by __many__ + """ + configspec = section.configspec + many = configspec.get('__many__') + if isinstance(many, dict): + for entry in section.sections: + if entry not in configspec: + section[entry].configspec = many + + for entry in configspec.sections: + if entry == '__many__': + continue + if entry not in section: + section[entry] = {} + section[entry]._created = True + if copy: + # copy comments + section.comments[entry] = configspec.comments.get(entry, []) + section.inline_comments[entry] = configspec.inline_comments.get(entry, '') + + # Could be a scalar when we expect a section + if isinstance(section[entry], Section): + section[entry].configspec = configspec[entry] + + + def _write_line(self, indent_string, entry, this_entry, comment): + """Write an individual line, for the write method""" + # NOTE: the calls to self._quote here handles non-StringType values. + if not self.unrepr: + val = self._decode_element(self._quote(this_entry)) + else: + val = repr(this_entry) + return '%s%s%s%s%s' % (indent_string, + self._decode_element(self._quote(entry, multiline=False)), + self._a_to_u(' = '), + val, + self._decode_element(comment)) + + + def _write_marker(self, indent_string, depth, entry, comment): + """Write a section marker line""" + return '%s%s%s%s%s' % (indent_string, + self._a_to_u('[' * depth), + self._quote(self._decode_element(entry), multiline=False), + self._a_to_u(']' * depth), + self._decode_element(comment)) + + + def _handle_comment(self, comment): + """Deal with a comment.""" + if not comment: + return '' + start = self.indent_type + if not comment.startswith('#'): + start += self._a_to_u(' # ') + return (start + comment) + + + # Public methods + + def write(self, outfile=None, section=None): + """ + Write the current ConfigObj as a file + + tekNico: FIXME: use StringIO instead of real files + + >>> filename = a.filename + >>> a.filename = 'test.ini' + >>> a.write() + >>> a.filename = filename + >>> a == ConfigObj('test.ini', raise_errors=True) + 1 + >>> import os + >>> os.remove('test.ini') + """ + if self.indent_type is None: + # this can be true if initialised from a dictionary + self.indent_type = DEFAULT_INDENT_TYPE + + out = [] + cs = self._a_to_u('#') + csp = self._a_to_u('# ') + if section is None: + int_val = self.interpolation + self.interpolation = False + section = self + for line in self.initial_comment: + line = self._decode_element(line) + stripped_line = line.strip() + if stripped_line and not stripped_line.startswith(cs): + line = csp + line + out.append(line) + + indent_string = self.indent_type * section.depth + for entry in (section.scalars + section.sections): + if entry in section.defaults: + # don't write out default values + continue + for comment_line in section.comments[entry]: + comment_line = self._decode_element(comment_line.lstrip()) + if comment_line and not comment_line.startswith(cs): + comment_line = csp + comment_line + out.append(indent_string + comment_line) + this_entry = section[entry] + comment = self._handle_comment(section.inline_comments[entry]) + + if isinstance(this_entry, dict): + # a section + out.append(self._write_marker( + indent_string, + this_entry.depth, + entry, + comment)) + out.extend(self.write(section=this_entry)) + else: + out.append(self._write_line( + indent_string, + entry, + this_entry, + comment)) + + if section is self: + for line in self.final_comment: + line = self._decode_element(line) + stripped_line = line.strip() + if stripped_line and not stripped_line.startswith(cs): + line = csp + line + out.append(line) + self.interpolation = int_val + + if section is not self: + return out + + if (self.filename is None) and (outfile is None): + # output a list of lines + # might need to encode + # NOTE: This will *screw* UTF16, each line will start with the BOM + if self.encoding: + out = [l.encode(self.encoding) for l in out] + if (self.BOM and ((self.encoding is None) or + (BOM_LIST.get(self.encoding.lower()) == 'utf_8'))): + # Add the UTF8 BOM + if not out: + out.append('') + out[0] = BOM_UTF8 + out[0] + return out + + # Turn the list to a string, joined with correct newlines + newline = self.newlines or os.linesep + if (getattr(outfile, 'mode', None) is not None and outfile.mode == 'w' + and sys.platform == 'win32' and newline == '\r\n'): + # Windows specific hack to avoid writing '\r\r\n' + newline = '\n' + output = self._a_to_u(newline).join(out) + if self.encoding: + output = output.encode(self.encoding) + if self.BOM and ((self.encoding is None) or match_utf8(self.encoding)): + # Add the UTF8 BOM + output = BOM_UTF8 + output + + if not output.endswith(newline): + output += newline + if outfile is not None: + outfile.write(output) + else: + h = open(self.filename, 'wb') + h.write(output) + h.close() + + + def validate(self, validator, preserve_errors=False, copy=False, + section=None): + """ + Test the ConfigObj against a configspec. + + It uses the ``validator`` object from *validate.py*. + + To run ``validate`` on the current ConfigObj, call: :: + + test = config.validate(validator) + + (Normally having previously passed in the configspec when the ConfigObj + was created - you can dynamically assign a dictionary of checks to the + ``configspec`` attribute of a section though). + + It returns ``True`` if everything passes, or a dictionary of + pass/fails (True/False). If every member of a subsection passes, it + will just have the value ``True``. (It also returns ``False`` if all + members fail). + + In addition, it converts the values from strings to their native + types if their checks pass (and ``stringify`` is set). + + If ``preserve_errors`` is ``True`` (``False`` is default) then instead + of a marking a fail with a ``False``, it will preserve the actual + exception object. This can contain info about the reason for failure. + For example the ``VdtValueTooSmallError`` indicates that the value + supplied was too small. If a value (or section) is missing it will + still be marked as ``False``. + + You must have the validate module to use ``preserve_errors=True``. + + You can then use the ``flatten_errors`` function to turn your nested + results dictionary into a flattened list of failures - useful for + displaying meaningful error messages. + """ + if section is None: + if self.configspec is None: + raise ValueError('No configspec supplied.') + if preserve_errors: + # We do this once to remove a top level dependency on the validate module + # Which makes importing configobj faster + from validate import VdtMissingValue + self._vdtMissingValue = VdtMissingValue + + section = self + + if copy: + section.initial_comment = section.configspec.initial_comment + section.final_comment = section.configspec.final_comment + section.encoding = section.configspec.encoding + section.BOM = section.configspec.BOM + section.newlines = section.configspec.newlines + section.indent_type = section.configspec.indent_type + + # + # section.default_values.clear() #?? + configspec = section.configspec + self._set_configspec(section, copy) + + + def validate_entry(entry, spec, val, missing, ret_true, ret_false): + section.default_values.pop(entry, None) + + try: + section.default_values[entry] = validator.get_default_value(configspec[entry]) + except (KeyError, AttributeError, validator.baseErrorClass): + # No default, bad default or validator has no 'get_default_value' + # (e.g. SimpleVal) + pass + + try: + check = validator.check(spec, + val, + missing=missing + ) + except validator.baseErrorClass, e: + if not preserve_errors or isinstance(e, self._vdtMissingValue): + out[entry] = False + else: + # preserve the error + out[entry] = e + ret_false = False + ret_true = False + else: + ret_false = False + out[entry] = True + if self.stringify or missing: + # if we are doing type conversion + # or the value is a supplied default + if not self.stringify: + if isinstance(check, (list, tuple)): + # preserve lists + check = [self._str(item) for item in check] + elif missing and check is None: + # convert the None from a default to a '' + check = '' + else: + check = self._str(check) + if (check != val) or missing: + section[entry] = check + if not copy and missing and entry not in section.defaults: + section.defaults.append(entry) + return ret_true, ret_false + + # + out = {} + ret_true = True + ret_false = True + + unvalidated = [k for k in section.scalars if k not in configspec] + incorrect_sections = [k for k in configspec.sections if k in section.scalars] + incorrect_scalars = [k for k in configspec.scalars if k in section.sections] + + for entry in configspec.scalars: + if entry in ('__many__', '___many___'): + # reserved names + continue + if (not entry in section.scalars) or (entry in section.defaults): + # missing entries + # or entries from defaults + missing = True + val = None + if copy and entry not in section.scalars: + # copy comments + section.comments[entry] = ( + configspec.comments.get(entry, [])) + section.inline_comments[entry] = ( + configspec.inline_comments.get(entry, '')) + # + else: + missing = False + val = section[entry] + + ret_true, ret_false = validate_entry(entry, configspec[entry], val, + missing, ret_true, ret_false) + + many = None + if '__many__' in configspec.scalars: + many = configspec['__many__'] + elif '___many___' in configspec.scalars: + many = configspec['___many___'] + + if many is not None: + for entry in unvalidated: + val = section[entry] + ret_true, ret_false = validate_entry(entry, many, val, False, + ret_true, ret_false) + unvalidated = [] + + for entry in incorrect_scalars: + ret_true = False + if not preserve_errors: + out[entry] = False + else: + ret_false = False + msg = 'Value %r was provided as a section' % entry + out[entry] = validator.baseErrorClass(msg) + for entry in incorrect_sections: + ret_true = False + if not preserve_errors: + out[entry] = False + else: + ret_false = False + msg = 'Section %r was provided as a single value' % entry + out[entry] = validator.baseErrorClass(msg) + + # Missing sections will have been created as empty ones when the + # configspec was read. + for entry in section.sections: + # FIXME: this means DEFAULT is not copied in copy mode + if section is self and entry == 'DEFAULT': + continue + if section[entry].configspec is None: + unvalidated.append(entry) + continue + if copy: + section.comments[entry] = configspec.comments.get(entry, []) + section.inline_comments[entry] = configspec.inline_comments.get(entry, '') + check = self.validate(validator, preserve_errors=preserve_errors, copy=copy, section=section[entry]) + out[entry] = check + if check == False: + ret_true = False + elif check == True: + ret_false = False + else: + ret_true = False + + section.extra_values = unvalidated + if preserve_errors and not section._created: + # If the section wasn't created (i.e. it wasn't missing) + # then we can't return False, we need to preserve errors + ret_false = False + # + if ret_false and preserve_errors and out: + # If we are preserving errors, but all + # the failures are from missing sections / values + # then we can return False. Otherwise there is a + # real failure that we need to preserve. + ret_false = not any(out.values()) + if ret_true: + return True + elif ret_false: + return False + return out + + + def reset(self): + """Clear ConfigObj instance and restore to 'freshly created' state.""" + self.clear() + self._initialise() + # FIXME: Should be done by '_initialise', but ConfigObj constructor (and reload) + # requires an empty dictionary + self.configspec = None + # Just to be sure ;-) + self._original_configspec = None + + + def reload(self): + """ + Reload a ConfigObj from file. + + This method raises a ``ReloadError`` if the ConfigObj doesn't have + a filename attribute pointing to a file. + """ + if not isinstance(self.filename, basestring): + raise ReloadError() + + filename = self.filename + current_options = {} + for entry in OPTION_DEFAULTS: + if entry == 'configspec': + continue + current_options[entry] = getattr(self, entry) + + configspec = self._original_configspec + current_options['configspec'] = configspec + + self.clear() + self._initialise(current_options) + self._load(filename, configspec) + + + +class SimpleVal(object): + """ + A simple validator. + Can be used to check that all members expected are present. + + To use it, provide a configspec with all your members in (the value given + will be ignored). Pass an instance of ``SimpleVal`` to the ``validate`` + method of your ``ConfigObj``. ``validate`` will return ``True`` if all + members are present, or a dictionary with True/False meaning + present/missing. (Whole missing sections will be replaced with ``False``) + """ + + def __init__(self): + self.baseErrorClass = ConfigObjError + + def check(self, check, member, missing=False): + """A dummy check method, always returns the value unchanged.""" + if missing: + raise self.baseErrorClass() + return member + + +def flatten_errors(cfg, res, levels=None, results=None): + """ + An example function that will turn a nested dictionary of results + (as returned by ``ConfigObj.validate``) into a flat list. + + ``cfg`` is the ConfigObj instance being checked, ``res`` is the results + dictionary returned by ``validate``. + + (This is a recursive function, so you shouldn't use the ``levels`` or + ``results`` arguments - they are used by the function.) + + Returns a list of keys that failed. Each member of the list is a tuple:: + + ([list of sections...], key, result) + + If ``validate`` was called with ``preserve_errors=False`` (the default) + then ``result`` will always be ``False``. + + *list of sections* is a flattened list of sections that the key was found + in. + + If the section was missing (or a section was expected and a scalar provided + - or vice-versa) then key will be ``None``. + + If the value (or section) was missing then ``result`` will be ``False``. + + If ``validate`` was called with ``preserve_errors=True`` and a value + was present, but failed the check, then ``result`` will be the exception + object returned. You can use this as a string that describes the failure. + + For example *The value "3" is of the wrong type*. + """ + if levels is None: + # first time called + levels = [] + results = [] + if res == True: + return results + if res == False or isinstance(res, Exception): + results.append((levels[:], None, res)) + if levels: + levels.pop() + return results + for (key, val) in res.items(): + if val == True: + continue + if isinstance(cfg.get(key), dict): + # Go down one level + levels.append(key) + flatten_errors(cfg[key], val, levels, results) + continue + results.append((levels[:], key, val)) + # + # Go up one level + if levels: + levels.pop() + # + return results + + +def get_extra_values(conf, _prepend=()): + """ + Find all the values and sections not in the configspec from a validated + ConfigObj. + + ``get_extra_values`` returns a list of tuples where each tuple represents + either an extra section, or an extra value. + + The tuples contain two values, a tuple representing the section the value + is in and the name of the extra values. For extra values in the top level + section the first member will be an empty tuple. For values in the 'foo' + section the first member will be ``('foo',)``. For members in the 'bar' + subsection of the 'foo' section the first member will be ``('foo', 'bar')``. + + NOTE: If you call ``get_extra_values`` on a ConfigObj instance that hasn't + been validated it will return an empty list. + """ + out = [] + + out.extend([(_prepend, name) for name in conf.extra_values]) + for name in conf.sections: + if name not in conf.extra_values: + out.extend(get_extra_values(conf[name], _prepend + (name,))) + return out + + +"""*A programming language is a medium of expression.* - Paul Graham""" diff --git a/python/cdec/sa/__init__.py b/python/cdec/sa/__init__.py index ddefa280..8645e837 100644 --- a/python/cdec/sa/__init__.py +++ b/python/cdec/sa/__init__.py @@ -1,4 +1,4 @@ -from _cdec_sa import sym_tostring, sym_isvar, sym_fromstring,\ +from _sa import sym_fromstring,\ SuffixArray, DataArray, LCP, Precomputation, Alignment, BiLex,\ HieroCachingRuleFactory, Sampler from extractor import GrammarExtractor diff --git a/python/cdec/sa/compile.py b/python/cdec/sa/compile.py index 061cdab2..30e605a6 100644 --- a/python/cdec/sa/compile.py +++ b/python/cdec/sa/compile.py @@ -2,7 +2,7 @@ import argparse import os import logging -import configobj +import cdec.configobj import cdec.sa MAX_PHRASE_LENGTH = 4 @@ -80,7 +80,7 @@ def main(): lex.write_binary(lex_bin) # Write configuration - config = configobj.ConfigObj(args.config, unrepr=True) + config = cdec.configobj.ConfigObj(args.config, unrepr=True) config['f_sa_file'] = f_sa_bin config['e_file'] = e_bin config['a_file'] = a_bin diff --git a/python/cdec/sa/extract.py b/python/cdec/sa/extract.py index c6da5e9d..918aa3bb 100644 --- a/python/cdec/sa/extract.py +++ b/python/cdec/sa/extract.py @@ -3,7 +3,6 @@ import sys import os import argparse import logging -import configobj import cdec.sa def main(): @@ -18,7 +17,7 @@ def main(): if not os.path.exists(args.grammars): os.mkdir(args.grammars) - extractor = cdec.sa.GrammarExtractor(configobj.ConfigObj(args.config, unrepr=True)) + extractor = cdec.sa.GrammarExtractor(args.config) for i, sentence in enumerate(sys.stdin): sentence = sentence[:-1] grammar_file = os.path.join(args.grammars, 'grammar.{0}'.format(i)) diff --git a/python/cdec/sa/extractor.py b/python/cdec/sa/extractor.py index c97b3c6f..bb912e16 100644 --- a/python/cdec/sa/extractor.py +++ b/python/cdec/sa/extractor.py @@ -1,4 +1,6 @@ from itertools import chain +import os +import cdec.configobj from cdec.sa.features import EgivenFCoherent, SampleCountF, CountEF,\ MaxLexEgivenF, MaxLexFgivenE, IsSingletonF, IsSingletonFE import cdec.sa @@ -8,7 +10,10 @@ MAX_INITIAL_SIZE = 15 class GrammarExtractor: def __init__(self, config): - # TODO if str, read config + if isinstance(config, str) or isinstance(config, unicode): + if not os.path.exists(config): + raise IOError('cannot read configuration from {0}'.format(config)) + config = cdec.configobj.ConfigObj(config, unrepr=True) alignment = cdec.sa.Alignment(from_binary=config['a_file']) self.factory = cdec.sa.HieroCachingRuleFactory( # compiled alignment object (REQUIRED) diff --git a/python/cdec/sa/features.py b/python/cdec/sa/features.py index 8d35d8e6..325b9e13 100644 --- a/python/cdec/sa/features.py +++ b/python/cdec/sa/features.py @@ -1,6 +1,5 @@ from __future__ import division import math -import cdec.sa MAXSCORE = 99 @@ -22,11 +21,10 @@ def CoherenceProb(fphrase, ephrase, paircount, fcount, fsample_count): def MaxLexEgivenF(ttable): def feature(fphrase, ephrase, paircount, fcount, fsample_count): - fwords = [cdec.sa.sym_tostring(w) for w in fphrase if not cdec.sa.sym_isvar(w)] + fwords = fphrase.words fwords.append('NULL') - ewords = (cdec.sa.sym_tostring(w) for w in ephrase if not cdec.sa.sym_isvar(w)) def score(): - for e in ewords: + for e in ephrase.words: maxScore = max(ttable.get_score(f, e, 0) for f in fwords) yield -math.log10(maxScore) if maxScore > 0 else MAXSCORE return sum(score()) @@ -34,11 +32,10 @@ def MaxLexEgivenF(ttable): def MaxLexFgivenE(ttable): def feature(fphrase, ephrase, paircount, fcount, fsample_count): - fwords = (cdec.sa.sym_tostring(w) for w in fphrase if not cdec.sa.sym_isvar(w)) - ewords = [cdec.sa.sym_tostring(w) for w in ephrase if not cdec.sa.sym_isvar(w)] + ewords = ephrase.words ewords.append('NULL') def score(): - for f in fwords: + for f in fphrase.words: maxScore = max(ttable.get_score(f, e, 1) for e in ewords) yield -math.log10(maxScore) if maxScore > 0 else MAXSCORE return sum(score()) diff --git a/python/setup.py b/python/setup.py index 9ae4a35c..1d1d7e45 100644 --- a/python/setup.py +++ b/python/setup.py @@ -32,7 +32,7 @@ else: BOOST_PROGRAM_OPTIONS = 'boost_program_options' ext_modules = [ - Extension(name='_cdec', + Extension(name='cdec._cdec', sources=['src/_cdec.cpp'], include_dirs=INC, library_dirs=LIB, @@ -40,8 +40,8 @@ ext_modules = [ 'cdec', 'utils', 'mteval', 'training', 'klm', 'klm_util'], extra_compile_args=['-DHAVE_CONFIG_H'], extra_link_args=LINK_ARGS), - Extension(name='_cdec_sa', - sources=['src/sa/_cdec_sa.c', 'src/sa/strmap.cc']) + Extension(name='cdec.sa._sa', + sources=['src/sa/_sa.c', 'src/sa/strmap.cc']) ] setup( diff --git a/python/src/_cdec.cpp b/python/src/_cdec.cpp index 44cd6568..20b86169 100644 --- a/python/src/_cdec.cpp +++ b/python/src/_cdec.cpp @@ -1,4 +1,4 @@ -/* Generated by Cython 0.16 on Wed Jul 25 23:56:10 2012 */ +/* Generated by Cython 0.17.beta1 on Fri Jul 27 22:15:28 2012 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -47,12 +47,6 @@ #define CYTHON_COMPILING_IN_CPYTHON 1 #endif -#if CYTHON_COMPILING_IN_PYPY - #define __Pyx_PyCFunction_Call PyObject_Call -#else - #define __Pyx_PyCFunction_Call PyCFunction_Call -#endif - #if PY_VERSION_HEX < 0x02050000 typedef int Py_ssize_t; #define PY_SSIZE_T_MAX INT_MAX @@ -60,8 +54,11 @@ #define PY_FORMAT_SIZE_T "" #define PyInt_FromSsize_t(z) PyInt_FromLong(z) #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o) - #define PyNumber_Index(o) PyNumber_Int(o) - #define PyIndex_Check(o) PyNumber_Check(o) + #define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \ + (PyErr_Format(PyExc_TypeError, \ + "expected index value, got %.200s", Py_TYPE(o)->tp_name), \ + (PyObject*)0)) + #define PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && !PyComplex_Check(o)) #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message) #define __PYX_BUILD_PY_SSIZE_T "i" #else @@ -130,14 +127,20 @@ #endif -#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_GET_LENGTH) +#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) #define CYTHON_PEP393_ENABLED 1 - #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) + #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ? \ + 0 : _PyUnicode_Ready((PyObject *)(op))) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) + #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) #else #define CYTHON_PEP393_ENABLED 0 - #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) + #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) + + #define __Pyx_PyUnicode_READ(k, d, i) ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i])) #endif #if PY_MAJOR_VERSION >= 3 @@ -270,6 +273,7 @@ #include #define __PYX_HAVE___cdec #define __PYX_HAVE_API___cdec +#include "string.h" #include #include #include @@ -357,7 +361,11 @@ static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); +#if CYTHON_COMPILING_IN_CPYTHON #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) +#else +#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) +#endif #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) #ifdef __GNUC__ @@ -391,6 +399,8 @@ static const char *__pyx_f[] = { "hypergraph.pxi", "lattice.pxi", "mteval.pxi", + "stringsource", + "cdec.sa._sa.pxd", }; /*--- Type declarations ---*/ @@ -398,15 +408,15 @@ struct __pyx_obj_5_cdec_Scorer; struct __pyx_obj_5_cdec_NTRef; struct __pyx_obj_5_cdec___pyx_scope_struct_23___cinit__; struct __pyx_obj_5_cdec___pyx_scope_struct_24_genexpr; +struct __pyx_obj_4cdec_2sa_3_sa_Phrase; struct __pyx_obj_5_cdec_Grammar; struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__; struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot; struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase; struct __pyx_obj_5_cdec_CandidateSet; struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__; -struct __pyx_obj_5_cdec_BaseTRule; struct __pyx_obj_5_cdec_TRule; -struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr; +struct __pyx_obj_4cdec_2sa_3_sa_Rule; struct __pyx_obj_5_cdec_SegmentEvaluator; struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__; struct __pyx_obj_5_cdec_Candidate; @@ -420,7 +430,7 @@ struct __pyx_obj_5_cdec_Decoder; struct __pyx_obj_5_cdec_HypergraphNode; struct __pyx_obj_5_cdec_SparseVector; struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__; -struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__; +struct __pyx_obj_5_cdec___pyx_scope_struct____iter__; struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__; struct __pyx_obj_5_cdec_DenseVector; struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__; @@ -430,11 +440,12 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_8_kbest; struct __pyx_obj_5_cdec___pyx_scope_struct_10_kbest_features; struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__; struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__; +struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr; struct __pyx_obj_5_cdec___pyx_scope_struct_9_kbest_trees; struct __pyx_obj_5_cdec_Hypergraph; struct __pyx_obj_5_cdec_Lattice; struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample; -struct __pyx_obj_5_cdec___pyx_scope_struct____iter__; +struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__; struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config; struct __pyx_obj_5_cdec_TextGrammar; struct __pyx_obj_5_cdec___pyx_scope_struct_19_lines; @@ -443,13 +454,13 @@ struct __pyx_opt_args_5_cdec_as_str; /* "_cdec.pyx":6 * cimport decoder * - * cdef char* as_str(data, error_msg='Cannot convert type %s to str'): # <<<<<<<<<<<<<< + * cdef char* as_str(data, char* error_msg='Cannot convert type %s to str'): # <<<<<<<<<<<<<< * cdef bytes ret * if isinstance(data, unicode): */ struct __pyx_opt_args_5_cdec_as_str { int __pyx_n; - PyObject *error_msg; + char *error_msg; }; /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":117 @@ -466,7 +477,7 @@ struct __pyx_obj_5_cdec_Scorer { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":18 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":20 * return '[%s]' % self.cat * * cdef class NTRef: # <<<<<<<<<<<<<< @@ -509,8 +520,23 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_24_genexpr { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":146 - * self.rule.get().ComputeArity() +/* "/Users/vchahun/Sandbox/cdec/python/src/cdec.sa._sa.pxd":1 + * cdef class Phrase: # <<<<<<<<<<<<<< + * cdef int *syms + * cdef int n, *varpos, n_vars + */ +struct __pyx_obj_4cdec_2sa_3_sa_Phrase { + PyObject_HEAD + struct __pyx_vtabstruct_4cdec_2sa_3_sa_Phrase *__pyx_vtab; + int *syms; + int n; + int *varpos; + int n_vars; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":169 + * _phrase(self.f), _phrase(self.e), scores) * * cdef class Grammar: # <<<<<<<<<<<<<< * cdef shared_ptr[grammar.Grammar]* grammar @@ -539,7 +565,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ { /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":57 - * del self.lattice + * yield self[i] * * def todot(self): # <<<<<<<<<<<<<< * def lines(): @@ -551,8 +577,8 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":3 - * cimport grammar +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":5 + * import cdec.sa._sa as _sa * * def _phrase(phrase): # <<<<<<<<<<<<<< * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) @@ -595,45 +621,34 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":26 - * return '[%d]' % self.ref +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":50 + * return TRule(lhs, f, e, scores, a) * - * cdef class BaseTRule: # <<<<<<<<<<<<<< + * cdef class TRule: # <<<<<<<<<<<<<< * cdef shared_ptr[grammar.TRule]* rule * */ -struct __pyx_obj_5_cdec_BaseTRule { +struct __pyx_obj_5_cdec_TRule { PyObject_HEAD boost::shared_ptr *rule; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":135 - * _phrase(self.f), _phrase(self.e), scores) - * - * cdef class TRule(BaseTRule): # <<<<<<<<<<<<<< - * def __cinit__(self, lhs, f, e, scores, a=None): - * self.rule = new shared_ptr[grammar.TRule](new grammar.TRule()) - */ -struct __pyx_obj_5_cdec_TRule { - struct __pyx_obj_5_cdec_BaseTRule __pyx_base; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":4 +/* "/Users/vchahun/Sandbox/cdec/python/src/cdec.sa._sa.pxd":7 + * cdef public int chunklen(self, int k) * - * def _phrase(phrase): - * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) # <<<<<<<<<<<<<< - * - * cdef class NT: + * cdef class Rule: # <<<<<<<<<<<<<< + * cdef public int lhs + * cdef readonly Phrase f, e */ -struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr { +struct __pyx_obj_4cdec_2sa_3_sa_Rule { PyObject_HEAD - struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase *__pyx_outer_scope; - PyObject *__pyx_v_w; - PyObject *__pyx_t_0; - Py_ssize_t __pyx_t_1; - PyObject *(*__pyx_t_2)(PyObject *); + int lhs; + struct __pyx_obj_4cdec_2sa_3_sa_Phrase *f; + struct __pyx_obj_4cdec_2sa_3_sa_Phrase *e; + float *cscores; + int n_scores; + PyObject *word_alignments; }; @@ -672,7 +687,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__ { * return stats * * cdef class Candidate: # <<<<<<<<<<<<<< - * cdef mteval.Candidate* candidate + * cdef mteval.const_Candidate* candidate * cdef public float score */ struct __pyx_obj_5_cdec_Candidate { @@ -682,7 +697,7 @@ struct __pyx_obj_5_cdec_Candidate { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":131 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":165 * * def __str__(self): * scores = ' '.join('%s=%s' % feat for feat in self.scores) # <<<<<<<<<<<<<< @@ -699,7 +714,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":6 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":8 * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) * * cdef class NT: # <<<<<<<<<<<<<< @@ -724,12 +739,12 @@ struct __pyx_obj_5_cdec_HypergraphEdge { PyObject_HEAD struct __pyx_vtabstruct_5_cdec_HypergraphEdge *__pyx_vtab; Hypergraph *hg; - const Hypergraph::Edge *edge; - struct __pyx_obj_5_cdec_BaseTRule *trule; + Hypergraph::Edge *edge; + struct __pyx_obj_5_cdec_TRule *trule; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":55 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":67 * self.vector.set_value(fid, value) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -762,7 +777,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_16___get__ { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":90 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":124 * * property a: * def __get__(self): # <<<<<<<<<<<<<< @@ -773,7 +788,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ { PyObject_HEAD std::vector *__pyx_v_a; unsigned int __pyx_v_i; - struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self; + struct __pyx_obj_5_cdec_TRule *__pyx_v_self; size_t __pyx_t_0; unsigned int __pyx_t_1; }; @@ -804,11 +819,11 @@ struct __pyx_obj_5_cdec_HypergraphNode { PyObject_HEAD struct __pyx_vtabstruct_5_cdec_HypergraphNode *__pyx_vtab; Hypergraph *hg; - const Hypergraph::Node *node; + Hypergraph::Node *node; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":36 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":45 * return sparse * * cdef class SparseVector: # <<<<<<<<<<<<<< @@ -821,7 +836,7 @@ struct __pyx_obj_5_cdec_SparseVector { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":49 +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":52 * return hypergraph.AsPLF(self.lattice[0], True).c_str() * * def __iter__(self): # <<<<<<<<<<<<<< @@ -837,17 +852,17 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__ { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":113 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":31 + * self.vector[0][fid] = value * - * property edges: - * def __get__(self): # <<<<<<<<<<<<<< - * cdef unsigned i - * for i in range(self.hg.edges_.size()): + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef unsigned fid + * for fid in range(1, self.vector.size()): */ -struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ { +struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ { PyObject_HEAD - unsigned int __pyx_v_i; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; + unsigned int __pyx_v_fid; + struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self; size_t __pyx_t_0; unsigned int __pyx_t_1; }; @@ -873,21 +888,22 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__ { * from cython.operator cimport preincrement as pinc * * cdef class DenseVector: # <<<<<<<<<<<<<< - * cdef vector[weight_t]* vector # Not owned by DenseVector - * + * cdef vector[weight_t]* vector + * cdef bint owned # if True, do not manage memory */ struct __pyx_obj_5_cdec_DenseVector { PyObject_HEAD std::vector *vector; + int owned; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":152 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":175 * del self.grammar * * def __iter__(self): # <<<<<<<<<<<<<< - * cdef grammar.GrammarIter* root = self.grammar.get().GetRoot() - * cdef grammar.RuleBin* rbin = root.GetRules() + * cdef grammar.const_GrammarIter* root = self.grammar.get().GetRoot() + * cdef grammar.const_RuleBin* rbin = root.GetRules() */ struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ { PyObject_HEAD @@ -983,7 +999,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__ { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":130 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":164 * self.rule.get().lhs_ = -TDConvert(lhs.cat) * * def __str__(self): # <<<<<<<<<<<<<< @@ -992,7 +1008,24 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__ { */ struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ { PyObject_HEAD - struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self; + struct __pyx_obj_5_cdec_TRule *__pyx_v_self; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":6 + * + * def _phrase(phrase): + * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) # <<<<<<<<<<<<<< + * + * cdef class NT: + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr { + PyObject_HEAD + struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase *__pyx_outer_scope; + PyObject *__pyx_v_w; + PyObject *__pyx_t_0; + Py_ssize_t __pyx_t_1; + PyObject *(*__pyx_t_2)(PyObject *); }; @@ -1064,17 +1097,17 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":22 - * self.vector[0][fid] = value +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":113 * - * def __iter__(self): # <<<<<<<<<<<<<< - * cdef unsigned fid - * for fid in range(1, self.vector.size()): + * property edges: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.hg.edges_.size()): */ -struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ { +struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ { PyObject_HEAD - unsigned int __pyx_v_fid; - struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self; + unsigned int __pyx_v_i; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; size_t __pyx_t_0; unsigned int __pyx_t_1; }; @@ -1103,7 +1136,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":169 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":192 * self.grammar.get().SetGrammarName(string(name)) * * cdef class TextGrammar(Grammar): # <<<<<<<<<<<<<< @@ -1139,6 +1172,19 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_19_lines { +/* "/Users/vchahun/Sandbox/cdec/python/src/cdec.sa._sa.pxd":1 + * cdef class Phrase: # <<<<<<<<<<<<<< + * cdef int *syms + * cdef int n, *varpos, n_vars + */ + +struct __pyx_vtabstruct_4cdec_2sa_3_sa_Phrase { + int (*chunkpos)(struct __pyx_obj_4cdec_2sa_3_sa_Phrase *, int); + int (*chunklen)(struct __pyx_obj_4cdec_2sa_3_sa_Phrase *, int); +}; +static struct __pyx_vtabstruct_4cdec_2sa_3_sa_Phrase *__pyx_vtabptr_4cdec_2sa_3_sa_Phrase; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":193 * raise NotImplemented('comparison not implemented for HypergraphEdge') * @@ -1226,9 +1272,19 @@ static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyOb static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/ +static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ + +static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); /*proto*/ + static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, const char *name, int exact); /*proto*/ +static CYTHON_INLINE PyObject* __Pyx_tp_new(PyObject* type_obj) { + return (PyObject*) (((PyTypeObject*)(type_obj))->tp_new( + (PyTypeObject*)(type_obj), __pyx_empty_tuple, NULL)); +} + static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname); @@ -1239,16 +1295,28 @@ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \ const char* function_name); /*proto*/ -static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, - Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) { + PyListObject* L = (PyListObject*) list; + Py_ssize_t len = Py_SIZE(list); + if (likely(L->allocated > len)) { + Py_INCREF(x); + PyList_SET_ITEM(list, len, x); + Py_SIZE(list) = len+1; + return 0; + } + return PyList_Append(list, x); +} +#else +#define __Pyx_PyList_Append(L,x) PyList_Append(L,x) +#endif static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) { if (likely(PyList_CheckExact(L))) { - if (PyList_Append(L, x) < 0) return NULL; + if (unlikely(PyList_Append(L, x) < 0)) return NULL; Py_INCREF(Py_None); return Py_None; /* this is just to have an accurate signature */ - } - else { + } else { PyObject *r, *m; m = __Pyx_GetAttrString(L, "append"); if (!m) return NULL; @@ -1269,42 +1337,47 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j __Pyx_GetItemInt_List_Fast(o, i) : \ __Pyx_GetItemInt_Generic(o, to_py_func(i))) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) { - if (likely(o != Py_None)) { - if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { - PyObject *r = PyList_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) { - PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i); - Py_INCREF(r); - return r; - } +#if CYTHON_COMPILING_IN_CPYTHON + if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { + PyObject *r = PyList_GET_ITEM(o, i); + Py_INCREF(r); + return r; + } + else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) { + PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i); + Py_INCREF(r); + return r; } return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif } #define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ __Pyx_GetItemInt_Tuple_Fast(o, i) : \ __Pyx_GetItemInt_Generic(o, to_py_func(i))) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) { - if (likely(o != Py_None)) { - if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) { - PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i); - Py_INCREF(r); - return r; - } +#if CYTHON_COMPILING_IN_CPYTHON + if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, i); + Py_INCREF(r); + return r; + } + else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) { + PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i); + Py_INCREF(r); + return r; } return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif } #define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ __Pyx_GetItemInt_Fast(o, i) : \ __Pyx_GetItemInt_Generic(o, to_py_func(i))) static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) { +#if CYTHON_COMPILING_IN_CPYTHON if (PyList_CheckExact(o)) { Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) { @@ -1320,19 +1393,30 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) Py_INCREF(r); return r; } - } - else if (likely(i >= 0)) { + } else { /* inlined PySequence_GetItem() */ PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; if (likely(m && m->sq_item)) { + if (unlikely(i < 0) && likely(m->sq_length)) { + Py_ssize_t l = m->sq_length(o); + if (unlikely(l < 0)) return NULL; + i += l; + } return m->sq_item(o, i); } } +#else + if (PySequence_Check(o)) { + return PySequence_GetItem(o, i); + } +#endif return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); } +static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); + static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); -static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); +static CYTHON_INLINE int __Pyx_IterFinish(void); /*proto*/ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/ @@ -1343,26 +1427,72 @@ static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) { return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b); } -#define __Pyx_PyIter_Next(obj) __Pyx_PyIter_Next2(obj, NULL); +#define __Pyx_PyIter_Next(obj) __Pyx_PyIter_Next2(obj, NULL) static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject *, PyObject *); /*proto*/ -static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); /*proto*/ - static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */ +#if CYTHON_COMPILING_IN_PYPY +#define __Pyx_PyObject_AsDouble(obj) \ +(likely(PyFloat_CheckExact(obj)) ? PyFloat_AS_DOUBLE(obj) : \ + likely(PyInt_CheckExact(obj)) ? \ + PyFloat_AsDouble(obj) : __Pyx__PyObject_AsDouble(obj)) +#else #define __Pyx_PyObject_AsDouble(obj) \ ((likely(PyFloat_CheckExact(obj))) ? \ PyFloat_AS_DOUBLE(obj) : __Pyx__PyObject_AsDouble(obj)) +#endif static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/ + static PyObject *__Pyx_FindPy2Metaclass(PyObject *bases); /*proto*/ static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, PyObject *modname); /*proto*/ +#ifndef __Pyx_CppExn2PyErr +#include +#include +#include +#include +static void __Pyx_CppExn2PyErr() { + try { + if (PyErr_Occurred()) + ; // let the latest Python exn pass through and ignore the current one + else + throw; + } catch (const std::bad_alloc& exn) { + PyErr_SetString(PyExc_MemoryError, exn.what()); + } catch (const std::bad_cast& exn) { + PyErr_SetString(PyExc_TypeError, exn.what()); + } catch (const std::domain_error& exn) { + PyErr_SetString(PyExc_ValueError, exn.what()); + } catch (const std::invalid_argument& exn) { + PyErr_SetString(PyExc_ValueError, exn.what()); + } catch (const std::ios_base::failure& exn) { + PyErr_SetString(PyExc_IOError, exn.what()); + } catch (const std::out_of_range& exn) { + PyErr_SetString(PyExc_IndexError, exn.what()); + } catch (const std::overflow_error& exn) { + PyErr_SetString(PyExc_OverflowError, exn.what()); + } catch (const std::range_error& exn) { + PyErr_SetString(PyExc_ArithmeticError, exn.what()); + } catch (const std::underflow_error& exn) { + PyErr_SetString(PyExc_ArithmeticError, exn.what()); + } catch (const std::exception& exn) { + PyErr_SetString(PyExc_RuntimeError, exn.what()); + } + catch (...) + { + PyErr_SetString(PyExc_RuntimeError, "Unknown exception"); + } +} +#endif + static CYTHON_INLINE WordID __Pyx_PyInt_from_py_WordID(PyObject *); static PyObject* __Pyx_Globals(void); /*proto*/ @@ -1460,6 +1590,7 @@ static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, #define __Pyx_Generator_USED #include +#include typedef PyObject *(*__pyx_generator_body_t)(PyObject *, PyObject *); typedef struct { PyObject_HEAD @@ -1472,15 +1603,38 @@ typedef struct { PyObject *exc_traceback; PyObject *gi_weakreflist; PyObject *classobj; + PyObject *yieldfrom; } __pyx_GeneratorObject; static __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body, PyObject *closure); static int __pyx_Generator_init(void); +static int __Pyx_Generator_clear(PyObject* self); +#if 1 || PY_VERSION_HEX < 0x030300B0 +static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue); +#else +#define __Pyx_PyGen_FetchStopIterationValue(pvalue) PyGen_FetchStopIterationValue(pvalue) +#endif static int __Pyx_check_binary_version(void); static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ +#if !defined(__Pyx_PyIdentifier_FromString) +#if PY_MAJOR_VERSION < 3 + #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s) +#else + #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s) +#endif +#endif + +static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict); /*proto*/ + +static PyObject *__Pyx_ImportModule(const char *name); /*proto*/ + +static void* __Pyx_GetVtable(PyObject *dict); /*proto*/ + +static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig); /*proto*/ + typedef struct { int code_line; PyCodeObject* code_object; @@ -1501,6 +1655,8 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ +/* Module declarations from 'libc.string' */ + /* Module declarations from 'libcpp.string' */ /* Module declarations from 'libcpp.vector' */ @@ -1519,6 +1675,14 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* Module declarations from 'decoder' */ +/* Module declarations from 'cdec.sa._sa' */ +static PyTypeObject *__pyx_ptype_4cdec_2sa_3_sa_Phrase = 0; +static PyTypeObject *__pyx_ptype_4cdec_2sa_3_sa_Rule = 0; +static char *(*__pyx_f_4cdec_2sa_3_sa_sym_tostring)(int); /*proto*/ +static char *(*__pyx_f_4cdec_2sa_3_sa_sym_tocat)(int); /*proto*/ +static int (*__pyx_f_4cdec_2sa_3_sa_sym_isvar)(int); /*proto*/ +static int (*__pyx_f_4cdec_2sa_3_sa_sym_getindex)(int); /*proto*/ + /* Module declarations from 'kbest' */ /* Module declarations from 'mteval' */ @@ -1528,7 +1692,6 @@ static PyTypeObject *__pyx_ptype_5_cdec_DenseVector = 0; static PyTypeObject *__pyx_ptype_5_cdec_SparseVector = 0; static PyTypeObject *__pyx_ptype_5_cdec_NT = 0; static PyTypeObject *__pyx_ptype_5_cdec_NTRef = 0; -static PyTypeObject *__pyx_ptype_5_cdec_BaseTRule = 0; static PyTypeObject *__pyx_ptype_5_cdec_TRule = 0; static PyTypeObject *__pyx_ptype_5_cdec_Grammar = 0; static PyTypeObject *__pyx_ptype_5_cdec_TextGrammar = 0; @@ -1569,9 +1732,11 @@ static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_22__make_config = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_23___cinit__ = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_24_genexpr = 0; static char *__pyx_f_5_cdec_as_str(PyObject *, struct __pyx_opt_args_5_cdec_as_str *__pyx_optional_args); /*proto*/ +static struct __pyx_obj_5_cdec_TRule *__pyx_f_5_cdec_convert_rule(struct __pyx_obj_4cdec_2sa_3_sa_Rule *); /*proto*/ static struct __pyx_obj_5_cdec_SufficientStats *__pyx_f_5_cdec_as_stats(PyObject *, PyObject *); /*proto*/ static float __pyx_f_5_cdec__compute_score(void *, SufficientStats *); /*proto*/ static void __pyx_f_5_cdec__compute_sufficient_stats(void *, std::string *, std::vector *, SufficientStats *); /*proto*/ +static PyObject *__pyx_convert_string_to_py_(const std::string &); /*proto*/ #define __Pyx_MODULE_NAME "_cdec" int __pyx_module_is_main__cdec = 0; @@ -1586,33 +1751,36 @@ static PyObject *__pyx_builtin_eval; static PyObject *__pyx_builtin_enumerate; static PyObject *__pyx_builtin_IndexError; static PyObject *__pyx_builtin_open; -static Py_ssize_t __pyx_pf_5_cdec_11DenseVector___len__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_2__getitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ -static int __pyx_pf_5_cdec_11DenseVector_4__setitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value); /* proto */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_6__iter__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_9dot(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_11tosparse(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ -static void __pyx_pf_5_cdec_12SparseVector___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_2copy(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_4__getitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ -static int __pyx_pf_5_cdec_12SparseVector_6__setitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_8__iter__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, PyObject *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y, int __pyx_v_op); /* proto */ -static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_15__len__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ -static int __pyx_pf_5_cdec_12SparseVector_17__contains__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_19__neg__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_21__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_23__isub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_25__imul__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ +static int __pyx_pf_5_cdec_11DenseVector___init__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ +static void __pyx_pf_5_cdec_11DenseVector_2__dealloc__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ +static Py_ssize_t __pyx_pf_5_cdec_11DenseVector_4__len__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_11DenseVector_6__getitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ +static int __pyx_pf_5_cdec_11DenseVector_8__setitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value); /* proto */ +static PyObject *__pyx_pf_5_cdec_11DenseVector_10__iter__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_11DenseVector_13dot(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_11DenseVector_15tosparse(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_12SparseVector___init__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ +static void __pyx_pf_5_cdec_12SparseVector_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_4copy(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_6__getitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ +static int __pyx_pf_5_cdec_12SparseVector_8__setitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_10__iter__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_13dot(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, PyObject *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_15__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y, int __pyx_v_op); /* proto */ +static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_17__len__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_12SparseVector_19__contains__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_21__neg__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_23__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_25__isub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_27__imul__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pf_5_cdec_12SparseVector_27__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_29__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ #endif -static PyObject *__pyx_pf_5_cdec_12SparseVector_29__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_31__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_33__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_31__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_33__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_35__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pf_5_cdec_12SparseVector_35__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_37__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ #endif static PyObject *__pyx_pf_5_cdec_7_phrase_genexpr(PyObject *__pyx_self); /* proto */ static PyObject *__pyx_pf_5_cdec__phrase(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_phrase); /* proto */ @@ -1626,21 +1794,21 @@ static int __pyx_pf_5_cdec_5NTRef___init__(struct __pyx_obj_5_cdec_NTRef *__pyx_ static PyObject *__pyx_pf_5_cdec_5NTRef_2__str__(struct __pyx_obj_5_cdec_NTRef *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_5NTRef_3ref___get__(struct __pyx_obj_5_cdec_NTRef *__pyx_v_self); /* proto */ static int __pyx_pf_5_cdec_5NTRef_3ref_2__set__(struct __pyx_obj_5_cdec_NTRef *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static void __pyx_pf_5_cdec_9BaseTRule___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_9BaseTRule_5arity___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_9BaseTRule_1f___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self); /* proto */ -static int __pyx_pf_5_cdec_9BaseTRule_1f_2__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_f); /* proto */ -static PyObject *__pyx_pf_5_cdec_9BaseTRule_1e___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self); /* proto */ -static int __pyx_pf_5_cdec_9BaseTRule_1e_2__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_e); /* proto */ -static PyObject *__pyx_pf_5_cdec_9BaseTRule_1a___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self); /* proto */ -static int __pyx_pf_5_cdec_9BaseTRule_1a_3__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_a); /* proto */ -static PyObject *__pyx_pf_5_cdec_9BaseTRule_6scores___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self); /* proto */ -static int __pyx_pf_5_cdec_9BaseTRule_6scores_2__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_scores); /* proto */ -static PyObject *__pyx_pf_5_cdec_9BaseTRule_3lhs___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self); /* proto */ -static int __pyx_pf_5_cdec_9BaseTRule_3lhs_2__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_lhs); /* proto */ -static PyObject *__pyx_pf_5_cdec_9BaseTRule_7__str___genexpr(PyObject *__pyx_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_9BaseTRule_2__str__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self); /* proto */ -static int __pyx_pf_5_cdec_5TRule___cinit__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self, PyObject *__pyx_v_lhs, PyObject *__pyx_v_f, PyObject *__pyx_v_e, PyObject *__pyx_v_scores, PyObject *__pyx_v_a); /* proto */ +static int __pyx_pf_5_cdec_5TRule___init__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self, PyObject *__pyx_v_lhs, PyObject *__pyx_v_f, PyObject *__pyx_v_e, PyObject *__pyx_v_scores, PyObject *__pyx_v_a); /* proto */ +static void __pyx_pf_5_cdec_5TRule_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_5TRule_5arity___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_5TRule_1f___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_5TRule_1f_2__set__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self, PyObject *__pyx_v_f); /* proto */ +static PyObject *__pyx_pf_5_cdec_5TRule_1e___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_5TRule_1e_2__set__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self, PyObject *__pyx_v_e); /* proto */ +static PyObject *__pyx_pf_5_cdec_5TRule_1a___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_5TRule_1a_3__set__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self, PyObject *__pyx_v_a); /* proto */ +static PyObject *__pyx_pf_5_cdec_5TRule_6scores___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_5TRule_6scores_2__set__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self, PyObject *__pyx_v_scores); /* proto */ +static PyObject *__pyx_pf_5_cdec_5TRule_3lhs___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_5TRule_3lhs_2__set__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self, PyObject *__pyx_v_lhs); /* proto */ +static PyObject *__pyx_pf_5_cdec_5TRule_7__str___genexpr(PyObject *__pyx_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_5TRule_4__str__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ static void __pyx_pf_5_cdec_7Grammar___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Grammar *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_7Grammar_2__iter__(struct __pyx_obj_5_cdec_Grammar *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_7Grammar_4name___get__(struct __pyx_obj_5_cdec_Grammar *__pyx_v_self); /* proto */ @@ -1680,12 +1848,12 @@ static PyObject *__pyx_pf_5_cdec_14HypergraphNode_4span___get__(struct __pyx_obj static PyObject *__pyx_pf_5_cdec_14HypergraphNode_3cat___get__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_14HypergraphNode___richcmp__(struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_x, struct __pyx_obj_5_cdec_HypergraphNode *__pyx_v_y, int __pyx_v_op); /* proto */ static int __pyx_pf_5_cdec_7Lattice___cinit__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, PyObject *__pyx_v_inp); /* proto */ -static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index); /* proto */ -static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index, PyObject *__pyx_v_arcs); /* proto */ -static Py_ssize_t __pyx_pf_5_cdec_7Lattice_6__len__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_7Lattice_8__str__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ -static void __pyx_pf_5_cdec_7Lattice_13__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ +static void __pyx_pf_5_cdec_7Lattice_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_7Lattice_4__getitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index); /* proto */ +static int __pyx_pf_5_cdec_7Lattice_6__setitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index, PyObject *__pyx_v_arcs); /* proto */ +static Py_ssize_t __pyx_pf_5_cdec_7Lattice_8__len__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_7Lattice_10__str__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_7Lattice_12__iter__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_7Lattice_5todot_lines(PyObject *__pyx_self); /* proto */ static PyObject *__pyx_pf_5_cdec_7Lattice_15todot(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self); /* proto */ @@ -1760,8 +1928,10 @@ static char __pyx_k_48[] = "formalism \"%s\" unknown"; static char __pyx_k_49[] = "cannot initialize weights with %s"; static char __pyx_k_50[] = "#"; static char __pyx_k_53[] = "Cannot translate input type %s"; -static char __pyx_k_56[] = "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi"; -static char __pyx_k_62[] = "/Users/vchahun/Sandbox/cdec/python/src/_cdec.pyx"; +static char __pyx_k_54[] = "cdec.sa._sa"; +static char __pyx_k_55[] = "*"; +static char __pyx_k_58[] = "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi"; +static char __pyx_k_64[] = "/Users/vchahun/Sandbox/cdec/python/src/_cdec.pyx"; static char __pyx_k__a[] = "a"; static char __pyx_k__e[] = "e"; static char __pyx_k__f[] = "f"; @@ -1770,6 +1940,7 @@ static char __pyx_k__k[] = "k"; static char __pyx_k__pb[] = "pb"; static char __pyx_k__CER[] = "CER"; static char __pyx_k__TER[] = "TER"; +static char __pyx_k___sa[] = "_sa"; static char __pyx_k__cat[] = "cat"; static char __pyx_k__dot[] = "dot"; static char __pyx_k__fst[] = "fst"; @@ -1805,6 +1976,7 @@ static char __pyx_k__value[] = "value"; static char __pyx_k__config[] = "config"; static char __pyx_k__csplit[] = "csplit"; static char __pyx_k__encode[] = "encode"; +static char __pyx_k__format[] = "format"; static char __pyx_k__phrase[] = "phrase"; static char __pyx_k__scores[] = "scores"; static char __pyx_k__tagger[] = "tagger"; @@ -1840,10 +2012,10 @@ static char __pyx_k__config_str[] = "config_str"; static char __pyx_k__hypergraph[] = "hypergraph"; static char __pyx_k__startswith[] = "startswith"; static char __pyx_k__ParseFailed[] = "ParseFailed"; +static char __pyx_k__PhraseModel_[] = "PhraseModel_"; static char __pyx_k___make_config[] = "_make_config"; static char __pyx_k__InvalidConfig[] = "InvalidConfig"; static char __pyx_k__NotImplemented[] = "NotImplemented"; -static PyObject *__pyx_kp_s_1; static PyObject *__pyx_kp_s_10; static PyObject *__pyx_kp_s_11; static PyObject *__pyx_kp_s_12; @@ -1874,8 +2046,10 @@ static PyObject *__pyx_kp_s_48; static PyObject *__pyx_kp_s_49; static PyObject *__pyx_kp_s_50; static PyObject *__pyx_kp_s_53; -static PyObject *__pyx_kp_s_56; -static PyObject *__pyx_kp_s_62; +static PyObject *__pyx_n_s_54; +static PyObject *__pyx_n_s_55; +static PyObject *__pyx_kp_s_58; +static PyObject *__pyx_kp_s_64; static PyObject *__pyx_kp_s_7; static PyObject *__pyx_kp_s_8; static PyObject *__pyx_kp_s_9; @@ -1888,6 +2062,7 @@ static PyObject *__pyx_n_s__InvalidConfig; static PyObject *__pyx_n_s__KeyError; static PyObject *__pyx_n_s__NotImplemented; static PyObject *__pyx_n_s__ParseFailed; +static PyObject *__pyx_n_s__PhraseModel_; static PyObject *__pyx_n_s__TER; static PyObject *__pyx_n_s__TypeError; static PyObject *__pyx_n_s__ValueError; @@ -1900,6 +2075,7 @@ static PyObject *__pyx_n_s____test__; static PyObject *__pyx_n_s___cdec; static PyObject *__pyx_n_s___make_config; static PyObject *__pyx_n_s___phrase; +static PyObject *__pyx_n_s___sa; static PyObject *__pyx_n_s__a; static PyObject *__pyx_n_s__beam_alpha; static PyObject *__pyx_n_s__cat; @@ -1918,6 +2094,7 @@ static PyObject *__pyx_n_s__evaluate; static PyObject *__pyx_n_s__evaluator; static PyObject *__pyx_n_s__f; static PyObject *__pyx_n_s__formalism; +static PyObject *__pyx_n_s__format; static PyObject *__pyx_n_s__fst; static PyObject *__pyx_n_s__genexpr; static PyObject *__pyx_n_s__get; @@ -1962,6 +2139,7 @@ static PyObject *__pyx_n_s__value; static PyObject *__pyx_n_s__weight; static PyObject *__pyx_int_0; static PyObject *__pyx_int_1; +static PyObject *__pyx_int_65536; static PyObject *__pyx_k_tuple_2; static PyObject *__pyx_k_tuple_5; static PyObject *__pyx_k_tuple_6; @@ -1980,32 +2158,33 @@ static PyObject *__pyx_k_tuple_44; static PyObject *__pyx_k_tuple_47; static PyObject *__pyx_k_tuple_51; static PyObject *__pyx_k_tuple_52; -static PyObject *__pyx_k_tuple_54; -static PyObject *__pyx_k_tuple_57; -static PyObject *__pyx_k_tuple_58; +static PyObject *__pyx_k_tuple_56; static PyObject *__pyx_k_tuple_59; static PyObject *__pyx_k_tuple_60; +static PyObject *__pyx_k_tuple_61; +static PyObject *__pyx_k_tuple_62; static PyObject *__pyx_k_codeobj_37; -static PyObject *__pyx_k_codeobj_55; -static PyObject *__pyx_k_codeobj_61; +static PyObject *__pyx_k_codeobj_57; +static PyObject *__pyx_k_codeobj_63; /* "_cdec.pyx":6 * cimport decoder * - * cdef char* as_str(data, error_msg='Cannot convert type %s to str'): # <<<<<<<<<<<<<< + * cdef char* as_str(data, char* error_msg='Cannot convert type %s to str'): # <<<<<<<<<<<<<< * cdef bytes ret * if isinstance(data, unicode): */ static char *__pyx_f_5_cdec_as_str(PyObject *__pyx_v_data, struct __pyx_opt_args_5_cdec_as_str *__pyx_optional_args) { - PyObject *__pyx_v_error_msg = ((PyObject *)__pyx_kp_s_1); + char *__pyx_v_error_msg = ((char *)__pyx_k_1); PyObject *__pyx_v_ret = 0; char *__pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; - char *__pyx_t_4; + PyObject *__pyx_t_4 = NULL; + char *__pyx_t_5; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -2017,7 +2196,7 @@ static char *__pyx_f_5_cdec_as_str(PyObject *__pyx_v_data, struct __pyx_opt_args } /* "_cdec.pyx":8 - * cdef char* as_str(data, error_msg='Cannot convert type %s to str'): + * cdef char* as_str(data, char* error_msg='Cannot convert type %s to str'): * cdef bytes ret * if isinstance(data, unicode): # <<<<<<<<<<<<<< * ret = data.encode('utf8') @@ -2065,7 +2244,7 @@ static char *__pyx_f_5_cdec_as_str(PyObject *__pyx_v_data, struct __pyx_opt_args * elif isinstance(data, str): * ret = data # <<<<<<<<<<<<<< * else: - * raise TypeError(error_msg % type(data)) + * raise TypeError(error_msg.format(type(data))) */ if (!(likely(PyBytes_CheckExact(__pyx_v_data))||((__pyx_v_data) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_data)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_INCREF(__pyx_v_data); @@ -2077,35 +2256,47 @@ static char *__pyx_f_5_cdec_as_str(PyObject *__pyx_v_data, struct __pyx_opt_args /* "_cdec.pyx":13 * ret = data * else: - * raise TypeError(error_msg % type(data)) # <<<<<<<<<<<<<< + * raise TypeError(error_msg.format(type(data))) # <<<<<<<<<<<<<< * return ret * */ - __pyx_t_3 = PyNumber_Remainder(__pyx_v_error_msg, ((PyObject *)Py_TYPE(__pyx_v_data))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyBytes_FromString(__pyx_v_error_msg); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_t_3), __pyx_n_s__format); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_data))); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)Py_TYPE(__pyx_v_data))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_v_data))); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L3:; /* "_cdec.pyx":14 * else: - * raise TypeError(error_msg % type(data)) + * raise TypeError(error_msg.format(type(data))) * return ret # <<<<<<<<<<<<<< * * include "vectors.pxi" */ - __pyx_t_4 = PyBytes_AsString(((PyObject *)__pyx_v_ret)); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_t_4; + __pyx_t_5 = PyBytes_AsString(((PyObject *)__pyx_v_ret)); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_t_5; goto __pyx_L0; __pyx_r = 0; @@ -2113,6 +2304,7 @@ static char *__pyx_f_5_cdec_as_str(PyObject *__pyx_v_data, struct __pyx_opt_args __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __Pyx_WriteUnraisable("_cdec.as_str", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; @@ -2122,96 +2314,193 @@ static char *__pyx_f_5_cdec_as_str(PyObject *__pyx_v_data, struct __pyx_opt_args } /* Python wrapper */ -static Py_ssize_t __pyx_pw_5_cdec_11DenseVector_1__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_5_cdec_11DenseVector_1__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; +static int __pyx_pw_5_cdec_11DenseVector_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_11DenseVector_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_11DenseVector___len__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1; + __pyx_r = __pyx_pf_5_cdec_11DenseVector___init__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":6 - * cdef vector[weight_t]* vector # Not owned by DenseVector - * - * def __len__(self): # <<<<<<<<<<<<<< - * return self.vector.size() +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":7 + * cdef bint owned # if True, do not manage memory * + * def __init__(self): # <<<<<<<<<<<<<< + * self.vector = new vector[weight_t]() + * self.owned = False */ -static Py_ssize_t __pyx_pf_5_cdec_11DenseVector___len__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { - Py_ssize_t __pyx_r; +static int __pyx_pf_5_cdec_11DenseVector___init__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__", 0); + __Pyx_RefNannySetupContext("__init__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":7 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":8 * - * def __len__(self): - * return self.vector.size() # <<<<<<<<<<<<<< + * def __init__(self): + * self.vector = new vector[weight_t]() # <<<<<<<<<<<<<< + * self.owned = False * - * def __getitem__(self, char* fname): */ - __pyx_r = __pyx_v_self->vector->size(); - goto __pyx_L0; + __pyx_v_self->vector = new std::vector(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":9 + * def __init__(self): + * self.vector = new vector[weight_t]() + * self.owned = False # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->owned = 0; __pyx_r = 0; - __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_11DenseVector_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ -static PyObject *__pyx_pw_5_cdec_11DenseVector_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { - char *__pyx_v_fname; - PyObject *__pyx_r = 0; +static void __pyx_pw_5_cdec_11DenseVector_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_11DenseVector_3__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); - assert(__pyx_arg_fname); { - __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.DenseVector.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_11DenseVector_2__getitem__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_11DenseVector_2__dealloc__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); - return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":9 - * return self.vector.size() +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":11 + * self.owned = False * - * def __getitem__(self, char* fname): # <<<<<<<<<<<<<< - * cdef int fid = FDConvert(fname) - * if 0 <= fid < self.vector.size(): + * def __dealloc__(self): # <<<<<<<<<<<<<< + * if not self.owned: + * del self.vector */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_2__getitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname) { - int __pyx_v_fid; - PyObject *__pyx_r = NULL; +static void __pyx_pf_5_cdec_11DenseVector_2__dealloc__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { __Pyx_RefNannyDeclarations int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__getitem__", 0); + __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":10 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":12 * - * def __getitem__(self, char* fname): - * cdef int fid = FDConvert(fname) # <<<<<<<<<<<<<< + * def __dealloc__(self): + * if not self.owned: # <<<<<<<<<<<<<< + * del self.vector + * + */ + __pyx_t_1 = (!__pyx_v_self->owned); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":13 + * def __dealloc__(self): + * if not self.owned: + * del self.vector # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + delete __pyx_v_self->vector; + goto __pyx_L3; + } + __pyx_L3:; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_5_cdec_11DenseVector_5__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_11DenseVector_5__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_11DenseVector_4__len__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":15 + * del self.vector + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.vector.size() + * + */ + +static Py_ssize_t __pyx_pf_5_cdec_11DenseVector_4__len__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":16 + * + * def __len__(self): + * return self.vector.size() # <<<<<<<<<<<<<< + * + * def __getitem__(self, char* fname): + */ + __pyx_r = __pyx_v_self->vector->size(); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_11DenseVector_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ +static PyObject *__pyx_pw_5_cdec_11DenseVector_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { + char *__pyx_v_fname; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + assert(__pyx_arg_fname); { + __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.DenseVector.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_11DenseVector_6__getitem__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":18 + * return self.vector.size() + * + * def __getitem__(self, char* fname): # <<<<<<<<<<<<<< + * cdef int fid = FDConvert(fname) + * if 0 <= fid < self.vector.size(): + */ + +static PyObject *__pyx_pf_5_cdec_11DenseVector_6__getitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname) { + int __pyx_v_fid; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__getitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":19 + * + * def __getitem__(self, char* fname): + * cdef int fid = FDConvert(fname) # <<<<<<<<<<<<<< * if 0 <= fid < self.vector.size(): * return self.vector[0][fid] */ __pyx_v_fid = FD::Convert(__pyx_v_fname); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":11 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":20 * def __getitem__(self, char* fname): * cdef int fid = FDConvert(fname) * if 0 <= fid < self.vector.size(): # <<<<<<<<<<<<<< @@ -2224,7 +2513,7 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_2__getitem__(struct __pyx_obj_5_c } if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":12 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":21 * cdef int fid = FDConvert(fname) * if 0 <= fid < self.vector.size(): * return self.vector[0][fid] # <<<<<<<<<<<<<< @@ -2232,7 +2521,7 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_2__getitem__(struct __pyx_obj_5_c * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyFloat_FromDouble(((__pyx_v_self->vector[0])[__pyx_v_fid])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyFloat_FromDouble(((__pyx_v_self->vector[0])[__pyx_v_fid])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; @@ -2241,26 +2530,26 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_2__getitem__(struct __pyx_obj_5_c } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":13 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":22 * if 0 <= fid < self.vector.size(): * return self.vector[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[1]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 22; __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[1]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__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[1]; __pyx_lineno = 13; __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[1]; __pyx_lineno = 22; __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[1]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; @@ -2276,18 +2565,18 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_2__getitem__(struct __pyx_obj_5_c } /* Python wrapper */ -static int __pyx_pw_5_cdec_11DenseVector_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value); /*proto*/ -static int __pyx_pw_5_cdec_11DenseVector_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value) { +static int __pyx_pw_5_cdec_11DenseVector_9__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value); /*proto*/ +static int __pyx_pw_5_cdec_11DenseVector_9__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value) { char *__pyx_v_fname; float __pyx_v_value; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); assert(__pyx_arg_fname); { - __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __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[1]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } assert(__pyx_arg_value); { - __pyx_v_value = __pyx_PyFloat_AsFloat(__pyx_arg_value); if (unlikely((__pyx_v_value == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_value = __pyx_PyFloat_AsFloat(__pyx_arg_value); if (unlikely((__pyx_v_value == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -2295,12 +2584,12 @@ static int __pyx_pw_5_cdec_11DenseVector_5__setitem__(PyObject *__pyx_v_self, Py __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_11DenseVector_4__setitem__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((char *)__pyx_v_fname), ((float)__pyx_v_value)); + __pyx_r = __pyx_pf_5_cdec_11DenseVector_8__setitem__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((char *)__pyx_v_fname), ((float)__pyx_v_value)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":15 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":24 * raise KeyError(fname) * * def __setitem__(self, char* fname, float value): # <<<<<<<<<<<<<< @@ -2308,7 +2597,7 @@ static int __pyx_pw_5_cdec_11DenseVector_5__setitem__(PyObject *__pyx_v_self, Py * if fid < 0: raise KeyError(fname) */ -static int __pyx_pf_5_cdec_11DenseVector_4__setitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value) { +static int __pyx_pf_5_cdec_11DenseVector_8__setitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value) { int __pyx_v_fid; int __pyx_r; __Pyx_RefNannyDeclarations @@ -2320,7 +2609,7 @@ static int __pyx_pf_5_cdec_11DenseVector_4__setitem__(struct __pyx_obj_5_cdec_De int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setitem__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":16 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":25 * * def __setitem__(self, char* fname, float value): * cdef int fid = FDConvert(fname) # <<<<<<<<<<<<<< @@ -2329,7 +2618,7 @@ static int __pyx_pf_5_cdec_11DenseVector_4__setitem__(struct __pyx_obj_5_cdec_De */ __pyx_v_fid = FD::Convert(((char *)__pyx_v_fname)); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":17 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":26 * def __setitem__(self, char* fname, float value): * cdef int fid = FDConvert(fname) * if fid < 0: raise KeyError(fname) # <<<<<<<<<<<<<< @@ -2338,24 +2627,24 @@ static int __pyx_pf_5_cdec_11DenseVector_4__setitem__(struct __pyx_obj_5_cdec_De */ __pyx_t_1 = (__pyx_v_fid < 0); if (__pyx_t_1) { - __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 26; __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[1]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__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[1]; __pyx_lineno = 17; __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[1]; __pyx_lineno = 26; __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[1]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":18 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":27 * cdef int fid = FDConvert(fname) * if fid < 0: raise KeyError(fname) * if self.vector.size() <= fid: # <<<<<<<<<<<<<< @@ -2365,7 +2654,7 @@ static int __pyx_pf_5_cdec_11DenseVector_4__setitem__(struct __pyx_obj_5_cdec_De __pyx_t_1 = (__pyx_v_self->vector->size() <= __pyx_v_fid); if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":19 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":28 * if fid < 0: raise KeyError(fname) * if self.vector.size() <= fid: * self.vector.resize(fid + 1) # <<<<<<<<<<<<<< @@ -2377,7 +2666,7 @@ static int __pyx_pf_5_cdec_11DenseVector_4__setitem__(struct __pyx_obj_5_cdec_De } __pyx_L4:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":20 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":29 * if self.vector.size() <= fid: * self.vector.resize(fid + 1) * self.vector[0][fid] = value # <<<<<<<<<<<<<< @@ -2397,20 +2686,20 @@ static int __pyx_pf_5_cdec_11DenseVector_4__setitem__(struct __pyx_obj_5_cdec_De __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_11DenseVector_8generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5_cdec_11DenseVector_12generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_11DenseVector_7__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_11DenseVector_7__iter__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_11DenseVector_11__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_11DenseVector_11__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_11DenseVector_6__iter__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_11DenseVector_10__iter__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":22 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":31 * self.vector[0][fid] = value * * def __iter__(self): # <<<<<<<<<<<<<< @@ -2418,7 +2707,7 @@ static PyObject *__pyx_pw_5_cdec_11DenseVector_7__iter__(PyObject *__pyx_v_self) * for fid in range(1, self.vector.size()): */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_6__iter__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_11DenseVector_10__iter__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -2436,7 +2725,7 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_6__iter__(struct __pyx_obj_5_cdec __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_11DenseVector_8generator, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_11DenseVector_12generator, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -2454,7 +2743,7 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_6__iter__(struct __pyx_obj_5_cdec return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_11DenseVector_8generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_11DenseVector_12generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; @@ -2473,9 +2762,9 @@ static PyObject *__pyx_gb_5_cdec_11DenseVector_8generator(__pyx_GeneratorObject return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":24 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":33 * def __iter__(self): * cdef unsigned fid * for fid in range(1, self.vector.size()): # <<<<<<<<<<<<<< @@ -2486,18 +2775,18 @@ static PyObject *__pyx_gb_5_cdec_11DenseVector_8generator(__pyx_GeneratorObject for (__pyx_t_2 = 1; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_cur_scope->__pyx_v_fid = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":25 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":34 * cdef unsigned fid * for fid in range(1, self.vector.size()): * yield FDConvert(fid).c_str(), self.vector[0][fid] # <<<<<<<<<<<<<< * * def dot(self, SparseVector other): */ - __pyx_t_3 = PyBytes_FromString(FD::Convert(__pyx_cur_scope->__pyx_v_fid).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 25; __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[1]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_4 = PyFloat_FromDouble(((__pyx_cur_scope->__pyx_v_self->vector[0])[__pyx_cur_scope->__pyx_v_fid])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyFloat_FromDouble(((__pyx_cur_scope->__pyx_v_self->vector[0])[__pyx_cur_scope->__pyx_v_fid])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 34; __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[1]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); @@ -2517,7 +2806,7 @@ static PyObject *__pyx_gb_5_cdec_11DenseVector_8generator(__pyx_GeneratorObject __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[1]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; @@ -2529,18 +2818,19 @@ static PyObject *__pyx_gb_5_cdec_11DenseVector_8generator(__pyx_GeneratorObject __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_11DenseVector_10dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_11DenseVector_10dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_11DenseVector_14dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_11DenseVector_14dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("dot (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_11DenseVector_9dot(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_11DenseVector_13dot(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2549,7 +2839,7 @@ static PyObject *__pyx_pw_5_cdec_11DenseVector_10dot(PyObject *__pyx_v_self, PyO return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":27 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":36 * yield FDConvert(fid).c_str(), self.vector[0][fid] * * def dot(self, SparseVector other): # <<<<<<<<<<<<<< @@ -2557,7 +2847,7 @@ static PyObject *__pyx_pw_5_cdec_11DenseVector_10dot(PyObject *__pyx_v_self, PyO * */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_9dot(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_11DenseVector_13dot(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -2568,7 +2858,7 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_9dot(struct __pyx_obj_5_cdec_Dens int __pyx_clineno = 0; __Pyx_RefNannySetupContext("dot", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":28 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":37 * * def dot(self, SparseVector other): * return other.dot(self) # <<<<<<<<<<<<<< @@ -2576,14 +2866,14 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_9dot(struct __pyx_obj_5_cdec_Dens * def tosparse(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_other), __pyx_n_s__dot); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_other), __pyx_n_s__dot); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; @@ -2606,25 +2896,25 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_9dot(struct __pyx_obj_5_cdec_Dens } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_11DenseVector_12tosparse(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_11DenseVector_12tosparse(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5_cdec_11DenseVector_16tosparse(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_11DenseVector_16tosparse(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("tosparse (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_11DenseVector_11tosparse(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_11DenseVector_15tosparse(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":30 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":39 * return other.dot(self) * * def tosparse(self): # <<<<<<<<<<<<<< - * cdef SparseVector sparse = SparseVector() + * cdef SparseVector sparse = SparseVector.__new__(SparseVector) * sparse.vector = new FastSparseVector[weight_t]() */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_11tosparse(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_11DenseVector_15tosparse(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_sparse = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -2634,29 +2924,30 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_11tosparse(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("tosparse", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":31 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":40 * * def tosparse(self): - * cdef SparseVector sparse = SparseVector() # <<<<<<<<<<<<<< + * cdef SparseVector sparse = SparseVector.__new__(SparseVector) # <<<<<<<<<<<<<< * sparse.vector = new FastSparseVector[weight_t]() * InitSparseVector(self.vector[0], sparse.vector) */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5_cdec_SparseVector)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); + if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5_cdec_SparseVector)))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_sparse = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":32 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":41 * def tosparse(self): - * cdef SparseVector sparse = SparseVector() + * cdef SparseVector sparse = SparseVector.__new__(SparseVector) * sparse.vector = new FastSparseVector[weight_t]() # <<<<<<<<<<<<<< * InitSparseVector(self.vector[0], sparse.vector) * return sparse */ __pyx_v_sparse->vector = new FastSparseVector(); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":33 - * cdef SparseVector sparse = SparseVector() + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":42 + * cdef SparseVector sparse = SparseVector.__new__(SparseVector) * sparse.vector = new FastSparseVector[weight_t]() * InitSparseVector(self.vector[0], sparse.vector) # <<<<<<<<<<<<<< * return sparse @@ -2664,7 +2955,7 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_11tosparse(struct __pyx_obj_5_cde */ Weights::InitSparseVector((__pyx_v_self->vector[0]), __pyx_v_sparse->vector); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":34 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":43 * sparse.vector = new FastSparseVector[weight_t]() * InitSparseVector(self.vector[0], sparse.vector) * return sparse # <<<<<<<<<<<<<< @@ -2690,27 +2981,68 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_11tosparse(struct __pyx_obj_5_cde } /* Python wrapper */ -static void __pyx_pw_5_cdec_12SparseVector_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_12SparseVector_1__dealloc__(PyObject *__pyx_v_self) { +static int __pyx_pw_5_cdec_12SparseVector_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_12SparseVector_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_12SparseVector___dealloc__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1; + __pyx_r = __pyx_pf_5_cdec_12SparseVector___init__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":39 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":48 * cdef FastSparseVector[weight_t]* vector * + * def __init__(self): # <<<<<<<<<<<<<< + * self.vector = new FastSparseVector[weight_t]() + * + */ + +static int __pyx_pf_5_cdec_12SparseVector___init__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":49 + * + * def __init__(self): + * self.vector = new FastSparseVector[weight_t]() # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->vector = new FastSparseVector(); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_12SparseVector_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_12SparseVector_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_12SparseVector_2__dealloc__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":51 + * self.vector = new FastSparseVector[weight_t]() + * * def __dealloc__(self): # <<<<<<<<<<<<<< * del self.vector * */ -static void __pyx_pf_5_cdec_12SparseVector___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { +static void __pyx_pf_5_cdec_12SparseVector_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":40 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":52 * * def __dealloc__(self): * del self.vector # <<<<<<<<<<<<<< @@ -2723,17 +3055,17 @@ static void __pyx_pf_5_cdec_12SparseVector___dealloc__(CYTHON_UNUSED struct __py } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_3copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_3copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_5copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_5copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("copy (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_2copy(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_4copy(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":42 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":54 * del self.vector * * def copy(self): # <<<<<<<<<<<<<< @@ -2741,7 +3073,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_3copy(PyObject *__pyx_v_self, CY * */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_2copy(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_4copy(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -2750,7 +3082,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_2copy(struct __pyx_obj_5_cdec_Sp int __pyx_clineno = 0; __Pyx_RefNannySetupContext("copy", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":43 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":55 * * def copy(self): * return self * 1 # <<<<<<<<<<<<<< @@ -2758,7 +3090,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_2copy(struct __pyx_obj_5_cdec_Sp * def __getitem__(self, char* fname): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyNumber_Multiply(((PyObject *)__pyx_v_self), __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyNumber_Multiply(((PyObject *)__pyx_v_self), __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2777,14 +3109,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_2copy(struct __pyx_obj_5_cdec_Sp } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_5__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_5__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { char *__pyx_v_fname; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); assert(__pyx_arg_fname); { - __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 45; __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[1]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -2792,12 +3124,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_5__getitem__(PyObject *__pyx_v_s __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12SparseVector_4__getitem__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_6__getitem__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":45 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":57 * return self * 1 * * def __getitem__(self, char* fname): # <<<<<<<<<<<<<< @@ -2805,7 +3137,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_5__getitem__(PyObject *__pyx_v_s * if fid < 0: raise KeyError(fname) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_4__getitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_6__getitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname) { int __pyx_v_fid; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -2817,7 +3149,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_4__getitem__(struct __pyx_obj_5_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__getitem__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":46 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":58 * * def __getitem__(self, char* fname): * cdef int fid = FDConvert(fname) # <<<<<<<<<<<<<< @@ -2826,7 +3158,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_4__getitem__(struct __pyx_obj_5_ */ __pyx_v_fid = FD::Convert(__pyx_v_fname); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":47 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":59 * def __getitem__(self, char* fname): * cdef int fid = FDConvert(fname) * if fid < 0: raise KeyError(fname) # <<<<<<<<<<<<<< @@ -2835,24 +3167,24 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_4__getitem__(struct __pyx_obj_5_ */ __pyx_t_1 = (__pyx_v_fid < 0); if (__pyx_t_1) { - __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 59; __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[1]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__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[1]; __pyx_lineno = 47; __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[1]; __pyx_lineno = 59; __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[1]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":48 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":60 * cdef int fid = FDConvert(fname) * if fid < 0: raise KeyError(fname) * return self.vector.value(fid) # <<<<<<<<<<<<<< @@ -2860,7 +3192,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_4__getitem__(struct __pyx_obj_5_ * def __setitem__(self, char* fname, float value): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyFloat_FromDouble(__pyx_v_self->vector->value(__pyx_v_fid)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_self->vector->value(__pyx_v_fid)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; @@ -2880,18 +3212,18 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_4__getitem__(struct __pyx_obj_5_ } /* Python wrapper */ -static int __pyx_pw_5_cdec_12SparseVector_7__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value); /*proto*/ -static int __pyx_pw_5_cdec_12SparseVector_7__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value) { +static int __pyx_pw_5_cdec_12SparseVector_9__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value); /*proto*/ +static int __pyx_pw_5_cdec_12SparseVector_9__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value) { char *__pyx_v_fname; float __pyx_v_value; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); assert(__pyx_arg_fname); { - __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 50; __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[1]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } assert(__pyx_arg_value); { - __pyx_v_value = __pyx_PyFloat_AsFloat(__pyx_arg_value); if (unlikely((__pyx_v_value == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_value = __pyx_PyFloat_AsFloat(__pyx_arg_value); if (unlikely((__pyx_v_value == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -2899,12 +3231,12 @@ static int __pyx_pw_5_cdec_12SparseVector_7__setitem__(PyObject *__pyx_v_self, P __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12SparseVector_6__setitem__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname), ((float)__pyx_v_value)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_8__setitem__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname), ((float)__pyx_v_value)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":50 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":62 * return self.vector.value(fid) * * def __setitem__(self, char* fname, float value): # <<<<<<<<<<<<<< @@ -2912,7 +3244,7 @@ static int __pyx_pw_5_cdec_12SparseVector_7__setitem__(PyObject *__pyx_v_self, P * if fid < 0: raise KeyError(fname) */ -static int __pyx_pf_5_cdec_12SparseVector_6__setitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value) { +static int __pyx_pf_5_cdec_12SparseVector_8__setitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value) { int __pyx_v_fid; int __pyx_r; __Pyx_RefNannyDeclarations @@ -2924,7 +3256,7 @@ static int __pyx_pf_5_cdec_12SparseVector_6__setitem__(struct __pyx_obj_5_cdec_S int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setitem__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":51 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":63 * * def __setitem__(self, char* fname, float value): * cdef int fid = FDConvert(fname) # <<<<<<<<<<<<<< @@ -2933,7 +3265,7 @@ static int __pyx_pf_5_cdec_12SparseVector_6__setitem__(struct __pyx_obj_5_cdec_S */ __pyx_v_fid = FD::Convert(((char *)__pyx_v_fname)); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":52 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":64 * def __setitem__(self, char* fname, float value): * cdef int fid = FDConvert(fname) * if fid < 0: raise KeyError(fname) # <<<<<<<<<<<<<< @@ -2942,24 +3274,24 @@ static int __pyx_pf_5_cdec_12SparseVector_6__setitem__(struct __pyx_obj_5_cdec_S */ __pyx_t_1 = (__pyx_v_fid < 0); if (__pyx_t_1) { - __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 64; __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[1]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__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[1]; __pyx_lineno = 52; __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[1]; __pyx_lineno = 64; __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[1]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":53 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":65 * cdef int fid = FDConvert(fname) * if fid < 0: raise KeyError(fname) * self.vector.set_value(fid, value) # <<<<<<<<<<<<<< @@ -2979,20 +3311,20 @@ static int __pyx_pf_5_cdec_12SparseVector_6__setitem__(struct __pyx_obj_5_cdec_S __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_12SparseVector_10generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5_cdec_12SparseVector_12generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_9__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_9__iter__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_11__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_11__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_8__iter__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_10__iter__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":55 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":67 * self.vector.set_value(fid, value) * * def __iter__(self): # <<<<<<<<<<<<<< @@ -3000,7 +3332,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_9__iter__(PyObject *__pyx_v_self * cdef unsigned i */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_8__iter__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_10__iter__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -3018,7 +3350,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_8__iter__(struct __pyx_obj_5_cde __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12SparseVector_10generator1, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12SparseVector_12generator1, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -3036,7 +3368,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_8__iter__(struct __pyx_obj_5_cde return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_12SparseVector_10generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_12SparseVector_12generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; @@ -3055,9 +3387,9 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_10generator1(__pyx_GeneratorObje return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":56 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":68 * * def __iter__(self): * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) # <<<<<<<<<<<<<< @@ -3066,7 +3398,7 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_10generator1(__pyx_GeneratorObje */ __pyx_cur_scope->__pyx_v_it = new FastSparseVector::const_iterator((__pyx_cur_scope->__pyx_v_self->vector[0]), 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":58 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":70 * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) * cdef unsigned i * try: # <<<<<<<<<<<<<< @@ -3075,7 +3407,7 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_10generator1(__pyx_GeneratorObje */ /*try:*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":59 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":71 * cdef unsigned i * try: * for i in range(self.vector.size()): # <<<<<<<<<<<<<< @@ -3086,18 +3418,18 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_10generator1(__pyx_GeneratorObje for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":60 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":72 * try: * for i in range(self.vector.size()): * yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second) # <<<<<<<<<<<<<< * pinc(it[0]) # ++it * finally: */ - __pyx_t_3 = PyBytes_FromString(FD::Convert((__pyx_cur_scope->__pyx_v_it[0]).operator->()->first).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L5;} + __pyx_t_3 = PyBytes_FromString(FD::Convert((__pyx_cur_scope->__pyx_v_it[0]).operator->()->first).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L5;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_4 = PyFloat_FromDouble((__pyx_cur_scope->__pyx_v_it[0]).operator->()->second); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L5;} + __pyx_t_4 = PyFloat_FromDouble((__pyx_cur_scope->__pyx_v_it[0]).operator->()->second); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L5;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L5;} + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L5;} __Pyx_GOTREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); @@ -3117,9 +3449,9 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_10generator1(__pyx_GeneratorObje __pyx_L9_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[1]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L5;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L5;} - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":61 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":73 * for i in range(self.vector.size()): * yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second) * pinc(it[0]) # ++it # <<<<<<<<<<<<<< @@ -3130,7 +3462,7 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_10generator1(__pyx_GeneratorObje } } - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":63 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":75 * pinc(it[0]) # ++it * finally: * del it # <<<<<<<<<<<<<< @@ -3175,22 +3507,23 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_10generator1(__pyx_GeneratorObje __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_12dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_12dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_14dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_14dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("dot (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_11dot(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((PyObject *)__pyx_v_other)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_13dot(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((PyObject *)__pyx_v_other)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":65 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":77 * del it * * def dot(self, other): # <<<<<<<<<<<<<< @@ -3198,7 +3531,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_12dot(PyObject *__pyx_v_self, Py * return self.vector.dot(( other).vector[0]) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_13dot(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -3209,7 +3542,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_Sp int __pyx_clineno = 0; __Pyx_RefNannySetupContext("dot", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":66 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":78 * * def dot(self, other): * if isinstance(other, DenseVector): # <<<<<<<<<<<<<< @@ -3222,7 +3555,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_Sp __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":67 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":79 * def dot(self, other): * if isinstance(other, DenseVector): * return self.vector.dot(( other).vector[0]) # <<<<<<<<<<<<<< @@ -3230,7 +3563,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_Sp * return self.vector.dot(( other).vector[0]) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->dot((((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_other)->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->dot((((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_other)->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -3238,7 +3571,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_Sp goto __pyx_L3; } - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":68 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":80 * if isinstance(other, DenseVector): * return self.vector.dot(( other).vector[0]) * elif isinstance(other, SparseVector): # <<<<<<<<<<<<<< @@ -3251,7 +3584,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_Sp __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":69 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":81 * return self.vector.dot(( other).vector[0]) * elif isinstance(other, SparseVector): * return self.vector.dot(( other).vector[0]) # <<<<<<<<<<<<<< @@ -3259,7 +3592,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_Sp * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->dot((((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->dot((((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -3268,26 +3601,26 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_Sp } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":70 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":82 * elif isinstance(other, SparseVector): * return self.vector.dot(( other).vector[0]) * raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) # <<<<<<<<<<<<<< * * def __richcmp__(SparseVector x, SparseVector y, int op): */ - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_3), ((PyObject *)Py_TYPE(__pyx_v_other))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_3), ((PyObject *)Py_TYPE(__pyx_v_other))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; @@ -3303,14 +3636,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_Sp } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_14__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_14__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_16__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_16__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_13__richcmp__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y), ((int)__pyx_v_op)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_15__richcmp__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y), ((int)__pyx_v_op)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -3319,7 +3652,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_14__richcmp__(PyObject *__pyx_v_ return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":72 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":84 * raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) * * def __richcmp__(SparseVector x, SparseVector y, int op): # <<<<<<<<<<<<<< @@ -3327,7 +3660,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_14__richcmp__(PyObject *__pyx_v_ * return x.vector[0] == y.vector[0] */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y, int __pyx_v_op) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_15__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y, int __pyx_v_op) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -3337,7 +3670,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5 int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__richcmp__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":75 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":87 * if op == 2: # == * return x.vector[0] == y.vector[0] * elif op == 3: # != # <<<<<<<<<<<<<< @@ -3346,7 +3679,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5 */ switch (__pyx_v_op) { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":73 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":85 * * def __richcmp__(SparseVector x, SparseVector y, int op): * if op == 2: # == # <<<<<<<<<<<<<< @@ -3355,7 +3688,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5 */ case 2: - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":74 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":86 * def __richcmp__(SparseVector x, SparseVector y, int op): * if op == 2: # == * return x.vector[0] == y.vector[0] # <<<<<<<<<<<<<< @@ -3363,14 +3696,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5 * return not (x == y) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_x->vector[0]) == (__pyx_v_y->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_x->vector[0]) == (__pyx_v_y->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; break; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":75 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":87 * if op == 2: # == * return x.vector[0] == y.vector[0] * elif op == 3: # != # <<<<<<<<<<<<<< @@ -3379,7 +3712,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5 */ case 3: - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":76 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":88 * return x.vector[0] == y.vector[0] * elif op == 3: # != * return not (x == y) # <<<<<<<<<<<<<< @@ -3387,11 +3720,11 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5 * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -3399,18 +3732,18 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5 break; } - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":77 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":89 * elif op == 3: # != * return not (x == y) * raise NotImplemented('comparison not implemented for SparseVector') # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_t_1 = PyObject_Call(__pyx_builtin_NotImplemented, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_NotImplemented, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; @@ -3425,17 +3758,17 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5 } /* Python wrapper */ -static Py_ssize_t __pyx_pw_5_cdec_12SparseVector_16__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_5_cdec_12SparseVector_16__len__(PyObject *__pyx_v_self) { +static Py_ssize_t __pyx_pw_5_cdec_12SparseVector_18__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_12SparseVector_18__len__(PyObject *__pyx_v_self) { Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_15__len__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_17__len__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":79 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":91 * raise NotImplemented('comparison not implemented for SparseVector') * * def __len__(self): # <<<<<<<<<<<<<< @@ -3443,12 +3776,12 @@ static Py_ssize_t __pyx_pw_5_cdec_12SparseVector_16__len__(PyObject *__pyx_v_sel * */ -static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_15__len__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { +static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_17__len__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__len__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":80 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":92 * * def __len__(self): * return self.vector.size() # <<<<<<<<<<<<<< @@ -3465,14 +3798,14 @@ static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_15__len__(struct __pyx_obj_5_cd } /* Python wrapper */ -static int __pyx_pw_5_cdec_12SparseVector_18__contains__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ -static int __pyx_pw_5_cdec_12SparseVector_18__contains__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { +static int __pyx_pw_5_cdec_12SparseVector_20__contains__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ +static int __pyx_pw_5_cdec_12SparseVector_20__contains__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { char *__pyx_v_fname; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0); assert(__pyx_arg_fname); { - __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 82; __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[1]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -3480,12 +3813,12 @@ static int __pyx_pw_5_cdec_12SparseVector_18__contains__(PyObject *__pyx_v_self, __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12SparseVector_17__contains__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_19__contains__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":82 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":94 * return self.vector.size() * * def __contains__(self, char* fname): # <<<<<<<<<<<<<< @@ -3493,12 +3826,12 @@ static int __pyx_pw_5_cdec_12SparseVector_18__contains__(PyObject *__pyx_v_self, * */ -static int __pyx_pf_5_cdec_12SparseVector_17__contains__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname) { +static int __pyx_pf_5_cdec_12SparseVector_19__contains__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__contains__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":83 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":95 * * def __contains__(self, char* fname): * return self.vector.nonzero(FDConvert(fname)) # <<<<<<<<<<<<<< @@ -3515,25 +3848,25 @@ static int __pyx_pf_5_cdec_12SparseVector_17__contains__(struct __pyx_obj_5_cdec } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_20__neg__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_20__neg__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_22__neg__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_22__neg__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__neg__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_19__neg__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_21__neg__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":85 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":97 * return self.vector.nonzero(FDConvert(fname)) * * def __neg__(self): # <<<<<<<<<<<<<< - * cdef SparseVector result = SparseVector() + * cdef SparseVector result = SparseVector.__new__(SparseVector) * result.vector = new FastSparseVector[weight_t](self.vector[0]) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_19__neg__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_21__neg__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -3543,29 +3876,30 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_19__neg__(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__neg__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":86 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":98 * * def __neg__(self): - * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< + * cdef SparseVector result = SparseVector.__new__(SparseVector) # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](self.vector[0]) * result.vector[0] *= -1.0 */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5_cdec_SparseVector)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); + if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5_cdec_SparseVector)))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":87 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":99 * def __neg__(self): - * cdef SparseVector result = SparseVector() + * cdef SparseVector result = SparseVector.__new__(SparseVector) * result.vector = new FastSparseVector[weight_t](self.vector[0]) # <<<<<<<<<<<<<< * result.vector[0] *= -1.0 * return result */ __pyx_v_result->vector = new FastSparseVector((__pyx_v_self->vector[0])); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":88 - * cdef SparseVector result = SparseVector() + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":100 + * cdef SparseVector result = SparseVector.__new__(SparseVector) * result.vector = new FastSparseVector[weight_t](self.vector[0]) * result.vector[0] *= -1.0 # <<<<<<<<<<<<<< * return result @@ -3573,7 +3907,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_19__neg__(struct __pyx_obj_5_cde */ (__pyx_v_result->vector[0]) *= -1.0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":89 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":101 * result.vector = new FastSparseVector[weight_t](self.vector[0]) * result.vector[0] *= -1.0 * return result # <<<<<<<<<<<<<< @@ -3599,13 +3933,13 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_19__neg__(struct __pyx_obj_5_cde } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_22__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_22__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_24__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_24__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iadd__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_21__iadd__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_23__iadd__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -3614,7 +3948,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_22__iadd__(PyObject *__pyx_v_sel return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":91 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":103 * return result * * def __iadd__(SparseVector self, SparseVector other): # <<<<<<<<<<<<<< @@ -3622,12 +3956,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_22__iadd__(PyObject *__pyx_v_sel * return self */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_21__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_23__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iadd__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":92 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":104 * * def __iadd__(SparseVector self, SparseVector other): * self.vector[0] += other.vector[0] # <<<<<<<<<<<<<< @@ -3636,7 +3970,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_21__iadd__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) += (__pyx_v_other->vector[0]); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":93 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":105 * def __iadd__(SparseVector self, SparseVector other): * self.vector[0] += other.vector[0] * return self # <<<<<<<<<<<<<< @@ -3656,13 +3990,13 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_21__iadd__(struct __pyx_obj_5_cd } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_24__isub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_24__isub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_26__isub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_26__isub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__isub__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_23__isub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_25__isub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -3671,7 +4005,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_24__isub__(PyObject *__pyx_v_sel return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":95 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":107 * return self * * def __isub__(SparseVector self, SparseVector other): # <<<<<<<<<<<<<< @@ -3679,12 +4013,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_24__isub__(PyObject *__pyx_v_sel * return self */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_23__isub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_25__isub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__isub__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":96 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":108 * * def __isub__(SparseVector self, SparseVector other): * self.vector[0] -= other.vector[0] # <<<<<<<<<<<<<< @@ -3693,7 +4027,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_23__isub__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) -= (__pyx_v_other->vector[0]); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":97 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":109 * def __isub__(SparseVector self, SparseVector other): * self.vector[0] -= other.vector[0] * return self # <<<<<<<<<<<<<< @@ -3713,14 +4047,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_23__isub__(struct __pyx_obj_5_cd } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_26__imul__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_26__imul__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_28__imul__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_28__imul__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar) { float __pyx_v_scalar; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__imul__ (wrapper)", 0); assert(__pyx_arg_scalar); { - __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -3728,12 +4062,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_26__imul__(PyObject *__pyx_v_sel __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12SparseVector_25__imul__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((float)__pyx_v_scalar)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_27__imul__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((float)__pyx_v_scalar)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":99 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":111 * return self * * def __imul__(SparseVector self, float scalar): # <<<<<<<<<<<<<< @@ -3741,12 +4075,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_26__imul__(PyObject *__pyx_v_sel * return self */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_25__imul__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_27__imul__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__imul__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":100 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":112 * * def __imul__(SparseVector self, float scalar): * self.vector[0] *= scalar # <<<<<<<<<<<<<< @@ -3755,7 +4089,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_25__imul__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) *= __pyx_v_scalar; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":101 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":113 * def __imul__(SparseVector self, float scalar): * self.vector[0] *= scalar * return self # <<<<<<<<<<<<<< @@ -3776,14 +4110,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_25__imul__(struct __pyx_obj_5_cd /* Python wrapper */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pw_5_cdec_12SparseVector_28__idiv__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_28__idiv__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_30__idiv__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_30__idiv__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar) { float __pyx_v_scalar; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__idiv__ (wrapper)", 0); assert(__pyx_arg_scalar); { - __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -3791,13 +4125,13 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_28__idiv__(PyObject *__pyx_v_sel __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12SparseVector_27__idiv__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((float)__pyx_v_scalar)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_29__idiv__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((float)__pyx_v_scalar)); __Pyx_RefNannyFinishContext(); return __pyx_r; } #endif /*!(#if PY_MAJOR_VERSION < 3)*/ -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":103 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":115 * return self * * def __idiv__(SparseVector self, float scalar): # <<<<<<<<<<<<<< @@ -3806,12 +4140,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_28__idiv__(PyObject *__pyx_v_sel */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pf_5_cdec_12SparseVector_27__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_29__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__idiv__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":104 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":116 * * def __idiv__(SparseVector self, float scalar): * self.vector[0] /= scalar # <<<<<<<<<<<<<< @@ -3820,7 +4154,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__idiv__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) /= __pyx_v_scalar; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":105 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":117 * def __idiv__(SparseVector self, float scalar): * self.vector[0] /= scalar * return self # <<<<<<<<<<<<<< @@ -3841,14 +4175,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__idiv__(struct __pyx_obj_5_cd #endif /*!(#if PY_MAJOR_VERSION < 3)*/ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_30__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_30__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_32__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_32__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__add__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_29__add__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_31__add__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -3857,15 +4191,15 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_30__add__(PyObject *__pyx_v_x, P return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":107 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":119 * return self * * def __add__(SparseVector x, SparseVector y): # <<<<<<<<<<<<<< - * cdef SparseVector result = SparseVector() + * cdef SparseVector result = SparseVector.__new__(SparseVector) * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_29__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_31__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -3875,29 +4209,30 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_29__add__(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__add__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":108 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":120 * * def __add__(SparseVector x, SparseVector y): - * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< + * cdef SparseVector result = SparseVector.__new__(SparseVector) # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5_cdec_SparseVector)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); + if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5_cdec_SparseVector)))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":109 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":121 * def __add__(SparseVector x, SparseVector y): - * cdef SparseVector result = SparseVector() + * cdef SparseVector result = SparseVector.__new__(SparseVector) * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) # <<<<<<<<<<<<<< * return result * */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_x->vector[0]) + (__pyx_v_y->vector[0]))); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":110 - * cdef SparseVector result = SparseVector() + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":122 + * cdef SparseVector result = SparseVector.__new__(SparseVector) * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) * return result # <<<<<<<<<<<<<< * @@ -3922,14 +4257,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_29__add__(struct __pyx_obj_5_cde } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_32__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_32__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_34__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_34__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__sub__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_31__sub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_33__sub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -3938,15 +4273,15 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_32__sub__(PyObject *__pyx_v_x, P return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":112 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":124 * return result * * def __sub__(SparseVector x, SparseVector y): # <<<<<<<<<<<<<< - * cdef SparseVector result = SparseVector() + * cdef SparseVector result = SparseVector.__new__(SparseVector) * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_31__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_33__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -3956,29 +4291,30 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_31__sub__(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__sub__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":113 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":125 * * def __sub__(SparseVector x, SparseVector y): - * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< + * cdef SparseVector result = SparseVector.__new__(SparseVector) # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5_cdec_SparseVector)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); + if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5_cdec_SparseVector)))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":114 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":126 * def __sub__(SparseVector x, SparseVector y): - * cdef SparseVector result = SparseVector() + * cdef SparseVector result = SparseVector.__new__(SparseVector) * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) # <<<<<<<<<<<<<< * return result * */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_x->vector[0]) - (__pyx_v_y->vector[0]))); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":115 - * cdef SparseVector result = SparseVector() + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":127 + * cdef SparseVector result = SparseVector.__new__(SparseVector) * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) * return result # <<<<<<<<<<<<<< * @@ -4003,17 +4339,17 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_31__sub__(struct __pyx_obj_5_cde } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_34__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_34__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_36__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_36__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__mul__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_33__mul__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_35__mul__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":117 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":129 * return result * * def __mul__(x, y): # <<<<<<<<<<<<<< @@ -4021,7 +4357,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_34__mul__(PyObject *__pyx_v_x, P * cdef float scalar */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_33__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_35__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_vector = 0; float __pyx_v_scalar; struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; @@ -4035,22 +4371,22 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_33__mul__(PyObject *__pyx_v_x, P int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__mul__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":120 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":132 * cdef SparseVector vector * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y # <<<<<<<<<<<<<< * else: vector, scalar = y, x - * cdef SparseVector result = SparseVector() + * cdef SparseVector result = SparseVector.__new__(SparseVector) */ __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_x; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; @@ -4058,46 +4394,47 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_33__mul__(PyObject *__pyx_v_x, P } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":121 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":133 * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x # <<<<<<<<<<<<<< - * cdef SparseVector result = SparseVector() + * cdef SparseVector result = SparseVector.__new__(SparseVector) * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) */ - if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_y; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":122 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":134 * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x - * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< + * cdef SparseVector result = SparseVector.__new__(SparseVector) # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5_cdec_SparseVector)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); + if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5_cdec_SparseVector)))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":123 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":135 * else: vector, scalar = y, x - * cdef SparseVector result = SparseVector() + * cdef SparseVector result = SparseVector.__new__(SparseVector) * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) # <<<<<<<<<<<<<< * return result * */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_vector->vector[0]) * __pyx_v_scalar)); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":124 - * cdef SparseVector result = SparseVector() + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":136 + * cdef SparseVector result = SparseVector.__new__(SparseVector) * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) * return result # <<<<<<<<<<<<<< * @@ -4124,18 +4461,18 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_33__mul__(PyObject *__pyx_v_x, P /* Python wrapper */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pw_5_cdec_12SparseVector_36__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_36__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_38__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_38__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__div__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_35__div__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_37__div__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); __Pyx_RefNannyFinishContext(); return __pyx_r; } #endif /*!(#if PY_MAJOR_VERSION < 3)*/ -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":126 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":138 * return result * * def __div__(x, y): # <<<<<<<<<<<<<< @@ -4144,7 +4481,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_36__div__(PyObject *__pyx_v_x, P */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pf_5_cdec_12SparseVector_35__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_37__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_vector = 0; float __pyx_v_scalar; struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; @@ -4158,22 +4495,22 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_35__div__(PyObject *__pyx_v_x, P int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__div__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":129 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":141 * cdef SparseVector vector * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y # <<<<<<<<<<<<<< * else: vector, scalar = y, x - * cdef SparseVector result = SparseVector() + * cdef SparseVector result = SparseVector.__new__(SparseVector) */ __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_x; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; @@ -4181,45 +4518,46 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_35__div__(PyObject *__pyx_v_x, P } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":130 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":142 * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x # <<<<<<<<<<<<<< - * cdef SparseVector result = SparseVector() + * cdef SparseVector result = SparseVector.__new__(SparseVector) * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) */ - if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_y; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":131 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":143 * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x - * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< + * cdef SparseVector result = SparseVector.__new__(SparseVector) # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5_cdec_SparseVector)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); + if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5_cdec_SparseVector)))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":132 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":144 * else: vector, scalar = y, x - * cdef SparseVector result = SparseVector() + * cdef SparseVector result = SparseVector.__new__(SparseVector) * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) # <<<<<<<<<<<<<< * return result */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_vector->vector[0]) / __pyx_v_scalar)); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":133 - * cdef SparseVector result = SparseVector() + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":145 + * cdef SparseVector result = SparseVector.__new__(SparseVector) * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) * return result # <<<<<<<<<<<<<< */ @@ -4250,14 +4588,13 @@ static PyObject *__pyx_pw_5_cdec_1_phrase(PyObject *__pyx_self, PyObject *__pyx_ PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("_phrase (wrapper)", 0); - __pyx_self = __pyx_self; __pyx_r = __pyx_pf_5_cdec__phrase(__pyx_self, ((PyObject *)__pyx_v_phrase)); __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_gb_5_cdec_7_phrase_2generator17(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":4 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":6 * * def _phrase(phrase): * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) # <<<<<<<<<<<<<< @@ -4283,7 +4620,7 @@ static PyObject *__pyx_pf_5_cdec_7_phrase_genexpr(PyObject *__pyx_self) { __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7_phrase_2generator17, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7_phrase_2generator17, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -4322,29 +4659,37 @@ static PyObject *__pyx_gb_5_cdec_7_phrase_2generator17(__pyx_GeneratorObject *__ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase)) { __Pyx_RaiseClosureNameError("phrase"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase)) { __Pyx_RaiseClosureNameError("phrase"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } if (PyList_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase)) { __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; __pyx_t_3 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_phrase); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; } for (;;) { if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else { __pyx_t_4 = __pyx_t_3(__pyx_t_1); if (unlikely(!__pyx_t_4)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } @@ -4360,20 +4705,20 @@ static PyObject *__pyx_gb_5_cdec_7_phrase_2generator17(__pyx_GeneratorObject *__ __pyx_t_6 = __Pyx_TypeCheck(__pyx_cur_scope->__pyx_v_w, __pyx_t_5); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_6) { - __pyx_t_5 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_w, __pyx_n_s__encode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_w, __pyx_n_s__encode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_6), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_6), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_4 = __pyx_t_7; __pyx_t_7 = 0; } else { - __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_INCREF(__pyx_cur_scope->__pyx_v_w); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_cur_scope->__pyx_v_w); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_w); - __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; __pyx_t_4 = __pyx_t_5; @@ -4396,7 +4741,7 @@ static PyObject *__pyx_gb_5_cdec_7_phrase_2generator17(__pyx_GeneratorObject *__ __Pyx_XGOTREF(__pyx_t_1); __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; PyErr_SetNone(PyExc_StopIteration); @@ -4410,12 +4755,13 @@ static PyObject *__pyx_gb_5_cdec_7_phrase_2generator17(__pyx_GeneratorObject *__ __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":3 - * cimport grammar +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":5 + * import cdec.sa._sa as _sa * * def _phrase(phrase): # <<<<<<<<<<<<<< * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) @@ -4443,7 +4789,7 @@ static PyObject *__pyx_pf_5_cdec__phrase(CYTHON_UNUSED PyObject *__pyx_self, PyO __Pyx_INCREF(__pyx_cur_scope->__pyx_v_phrase); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_phrase); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":4 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":6 * * def _phrase(phrase): * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) # <<<<<<<<<<<<<< @@ -4451,16 +4797,16 @@ static PyObject *__pyx_pf_5_cdec__phrase(CYTHON_UNUSED PyObject *__pyx_self, PyO * cdef class NT: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_7), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_7), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_pf_5_cdec_7_phrase_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __pyx_pf_5_cdec_7_phrase_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; @@ -4488,11 +4834,11 @@ static int __pyx_pw_5_cdec_2NT_1__init__(PyObject *__pyx_v_self, PyObject *__pyx static int __pyx_pw_5_cdec_2NT_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_cat = 0; PyObject *__pyx_v_ref = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__cat,&__pyx_n_s__ref,0}; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__cat,&__pyx_n_s__ref,0}; PyObject* values[2] = {0,0}; values[1] = ((PyObject *)__pyx_int_0); if (unlikely(__pyx_kwds)) { @@ -4507,8 +4853,7 @@ static int __pyx_pw_5_cdec_2NT_1__init__(PyObject *__pyx_v_self, PyObject *__pyx kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__cat); - if (likely(values[0])) kw_args--; + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__cat)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (kw_args > 0) { @@ -4517,7 +4862,7 @@ static int __pyx_pw_5_cdec_2NT_1__init__(PyObject *__pyx_v_self, PyObject *__pyx } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -4532,7 +4877,7 @@ static int __pyx_pw_5_cdec_2NT_1__init__(PyObject *__pyx_v_self, PyObject *__pyx } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.NT.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -4543,7 +4888,7 @@ static int __pyx_pw_5_cdec_2NT_1__init__(PyObject *__pyx_v_self, PyObject *__pyx return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":9 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":11 * cdef public char* cat * cdef public unsigned ref * def __init__(self, cat, ref=0): # <<<<<<<<<<<<<< @@ -4561,24 +4906,24 @@ static int __pyx_pf_5_cdec_2NT___init__(struct __pyx_obj_5_cdec_NT *__pyx_v_self int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__init__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":10 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":12 * cdef public unsigned ref * def __init__(self, cat, ref=0): * self.cat = cat # <<<<<<<<<<<<<< * self.ref = ref * */ - __pyx_t_1 = PyBytes_AsString(__pyx_v_cat); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_AsString(__pyx_v_cat); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->cat = __pyx_t_1; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":11 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":13 * def __init__(self, cat, ref=0): * self.cat = cat * self.ref = ref # <<<<<<<<<<<<<< * * def __str__(self): */ - __pyx_t_2 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_ref); if (unlikely((__pyx_t_2 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_ref); if (unlikely((__pyx_t_2 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->ref = __pyx_t_2; __pyx_r = 0; @@ -4602,7 +4947,7 @@ static PyObject *__pyx_pw_5_cdec_2NT_3__str__(PyObject *__pyx_v_self) { return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":13 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":15 * self.ref = ref * * def __str__(self): # <<<<<<<<<<<<<< @@ -4622,7 +4967,7 @@ static PyObject *__pyx_pf_5_cdec_2NT_2__str__(struct __pyx_obj_5_cdec_NT *__pyx_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__str__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":14 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":16 * * def __str__(self): * if self.ref > 0: # <<<<<<<<<<<<<< @@ -4632,7 +4977,7 @@ static PyObject *__pyx_pf_5_cdec_2NT_2__str__(struct __pyx_obj_5_cdec_NT *__pyx_ __pyx_t_1 = (__pyx_v_self->ref > 0); if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":15 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":17 * def __str__(self): * if self.ref > 0: * return '[%s,%d]' % (self.cat, self.ref) # <<<<<<<<<<<<<< @@ -4640,11 +4985,11 @@ static PyObject *__pyx_pf_5_cdec_2NT_2__str__(struct __pyx_obj_5_cdec_NT *__pyx_ * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyBytes_FromString(__pyx_v_self->cat); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyBytes_FromString(__pyx_v_self->cat); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_t_3 = PyLong_FromUnsignedLong(__pyx_v_self->ref); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyLong_FromUnsignedLong(__pyx_v_self->ref); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_2)); __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); @@ -4652,7 +4997,7 @@ static PyObject *__pyx_pf_5_cdec_2NT_2__str__(struct __pyx_obj_5_cdec_NT *__pyx_ __Pyx_GIVEREF(__pyx_t_3); __pyx_t_2 = 0; __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_8), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_8), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_r = ((PyObject *)__pyx_t_3); @@ -4662,7 +5007,7 @@ static PyObject *__pyx_pf_5_cdec_2NT_2__str__(struct __pyx_obj_5_cdec_NT *__pyx_ } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":16 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":18 * if self.ref > 0: * return '[%s,%d]' % (self.cat, self.ref) * return '[%s]' % self.cat # <<<<<<<<<<<<<< @@ -4670,9 +5015,9 @@ static PyObject *__pyx_pf_5_cdec_2NT_2__str__(struct __pyx_obj_5_cdec_NT *__pyx_ * cdef class NTRef: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyBytes_FromString(__pyx_v_self->cat); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyBytes_FromString(__pyx_v_self->cat); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_r = ((PyObject *)__pyx_t_4); @@ -4704,7 +5049,7 @@ static PyObject *__pyx_pw_5_cdec_2NT_3cat_1__get__(PyObject *__pyx_v_self) { return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":7 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":9 * * cdef class NT: * cdef public char* cat # <<<<<<<<<<<<<< @@ -4721,7 +5066,7 @@ static PyObject *__pyx_pf_5_cdec_2NT_3cat___get__(struct __pyx_obj_5_cdec_NT *__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(__pyx_v_self->cat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(__pyx_v_self->cat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; @@ -4758,7 +5103,7 @@ static int __pyx_pf_5_cdec_2NT_3cat_2__set__(struct __pyx_obj_5_cdec_NT *__pyx_v const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - __pyx_t_1 = PyBytes_AsString(__pyx_v_value); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_AsString(__pyx_v_value); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->cat = __pyx_t_1; __pyx_r = 0; @@ -4782,7 +5127,7 @@ static PyObject *__pyx_pw_5_cdec_2NT_3ref_1__get__(PyObject *__pyx_v_self) { return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":8 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":10 * cdef class NT: * cdef public char* cat * cdef public unsigned ref # <<<<<<<<<<<<<< @@ -4799,7 +5144,7 @@ static PyObject *__pyx_pf_5_cdec_2NT_3ref___get__(struct __pyx_obj_5_cdec_NT *__ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyLong_FromUnsignedLong(__pyx_v_self->ref); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyLong_FromUnsignedLong(__pyx_v_self->ref); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -4836,7 +5181,7 @@ static int __pyx_pf_5_cdec_2NT_3ref_2__set__(struct __pyx_obj_5_cdec_NT *__pyx_v const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->ref = __pyx_t_1; __pyx_r = 0; @@ -4853,11 +5198,11 @@ static int __pyx_pf_5_cdec_2NT_3ref_2__set__(struct __pyx_obj_5_cdec_NT *__pyx_v static int __pyx_pw_5_cdec_5NTRef_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_5_cdec_5NTRef_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_ref = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__ref,0}; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__ref,0}; PyObject* values[1] = {0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; @@ -4870,12 +5215,11 @@ static int __pyx_pw_5_cdec_5NTRef_1__init__(PyObject *__pyx_v_self, PyObject *__ kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ref); - if (likely(values[0])) kw_args--; + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ref)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; @@ -4886,7 +5230,7 @@ static int __pyx_pw_5_cdec_5NTRef_1__init__(PyObject *__pyx_v_self, PyObject *__ } 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[2]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.NTRef.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -4897,7 +5241,7 @@ static int __pyx_pw_5_cdec_5NTRef_1__init__(PyObject *__pyx_v_self, PyObject *__ return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":20 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":22 * cdef class NTRef: * cdef public unsigned ref * def __init__(self, ref): # <<<<<<<<<<<<<< @@ -4914,14 +5258,14 @@ static int __pyx_pf_5_cdec_5NTRef___init__(struct __pyx_obj_5_cdec_NTRef *__pyx_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__init__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":21 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":23 * cdef public unsigned ref * def __init__(self, ref): * self.ref = ref # <<<<<<<<<<<<<< * * def __str__(self): */ - __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_ref); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_ref); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->ref = __pyx_t_1; __pyx_r = 0; @@ -4945,7 +5289,7 @@ static PyObject *__pyx_pw_5_cdec_5NTRef_3__str__(PyObject *__pyx_v_self) { return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":23 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":25 * self.ref = ref * * def __str__(self): # <<<<<<<<<<<<<< @@ -4963,17 +5307,17 @@ static PyObject *__pyx_pf_5_cdec_5NTRef_2__str__(struct __pyx_obj_5_cdec_NTRef * int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__str__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":24 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":26 * * def __str__(self): * return '[%d]' % self.ref # <<<<<<<<<<<<<< * - * cdef class BaseTRule: + * cdef TRule convert_rule(_sa.Rule rule): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyLong_FromUnsignedLong(__pyx_v_self->ref); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyLong_FromUnsignedLong(__pyx_v_self->ref); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_10), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_10), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = ((PyObject *)__pyx_t_2); @@ -5004,7 +5348,7 @@ static PyObject *__pyx_pw_5_cdec_5NTRef_3ref_1__get__(PyObject *__pyx_v_self) { return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":19 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":21 * * cdef class NTRef: * cdef public unsigned ref # <<<<<<<<<<<<<< @@ -5021,7 +5365,7 @@ static PyObject *__pyx_pf_5_cdec_5NTRef_3ref___get__(struct __pyx_obj_5_cdec_NTR int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyLong_FromUnsignedLong(__pyx_v_self->ref); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyLong_FromUnsignedLong(__pyx_v_self->ref); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -5058,7 +5402,7 @@ static int __pyx_pf_5_cdec_5NTRef_3ref_2__set__(struct __pyx_obj_5_cdec_NTRef *_ const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->ref = __pyx_t_1; __pyx_r = 0; @@ -5071,78 +5415,639 @@ static int __pyx_pf_5_cdec_5NTRef_3ref_2__set__(struct __pyx_obj_5_cdec_NTRef *_ return __pyx_r; } -/* Python wrapper */ -static void __pyx_pw_5_cdec_9BaseTRule_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_9BaseTRule_1__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_9BaseTRule___dealloc__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":29 - * cdef shared_ptr[grammar.TRule]* rule - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.rule - * - */ - -static void __pyx_pf_5_cdec_9BaseTRule___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":30 - * - * def __dealloc__(self): - * del self.rule # <<<<<<<<<<<<<< - * - * property arity: - */ - delete __pyx_v_self->rule; - - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_9BaseTRule_5arity_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_9BaseTRule_5arity_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9BaseTRule_5arity___get__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":33 - * - * property arity: - * def __get__(self): # <<<<<<<<<<<<<< - * return self.rule.get().arity_ +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":28 + * return '[%d]' % self.ref * + * cdef TRule convert_rule(_sa.Rule rule): # <<<<<<<<<<<<<< + * cdef unsigned i + * cdef lhs = _sa.sym_tocat(rule.lhs) */ -static PyObject *__pyx_pf_5_cdec_9BaseTRule_5arity___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self) { - PyObject *__pyx_r = NULL; +static struct __pyx_obj_5_cdec_TRule *__pyx_f_5_cdec_convert_rule(struct __pyx_obj_4cdec_2sa_3_sa_Rule *__pyx_v_rule) { + unsigned int __pyx_v_i; + PyObject *__pyx_v_lhs = 0; + PyObject *__pyx_v_scores = 0; + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_v_e = NULL; + int *__pyx_v_fsyms; + int *__pyx_v_esyms; + PyObject *__pyx_v_a = 0; + PyObject *__pyx_v_point = NULL; + struct __pyx_obj_5_cdec_TRule *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + unsigned int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + int __pyx_t_7; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_RefNannySetupContext("convert_rule", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":34 - * property arity: - * def __get__(self): - * return self.rule.get().arity_ # <<<<<<<<<<<<<< - * - * property f: + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":30 + * cdef TRule convert_rule(_sa.Rule rule): + * cdef unsigned i + * cdef lhs = _sa.sym_tocat(rule.lhs) # <<<<<<<<<<<<<< + * cdef scores = {} + * for i in range(rule.n_scores): */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->rule->get()->arity_); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; + __pyx_t_1 = PyBytes_FromString(__pyx_f_4cdec_2sa_3_sa_sym_tocat(__pyx_v_rule->lhs)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_v_lhs = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":31 + * cdef unsigned i + * cdef lhs = _sa.sym_tocat(rule.lhs) + * cdef scores = {} # <<<<<<<<<<<<<< + * for i in range(rule.n_scores): + * scores['PhraseModel_'+str(i)] = rule.cscores[i] + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_v_scores = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":32 + * cdef lhs = _sa.sym_tocat(rule.lhs) + * cdef scores = {} + * for i in range(rule.n_scores): # <<<<<<<<<<<<<< + * scores['PhraseModel_'+str(i)] = rule.cscores[i] + * f, e = [], [] + */ + __pyx_t_2 = __pyx_v_rule->n_scores; + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":33 + * cdef scores = {} + * for i in range(rule.n_scores): + * scores['PhraseModel_'+str(i)] = rule.cscores[i] # <<<<<<<<<<<<<< + * f, e = [], [] + * cdef int* fsyms = rule.f.syms + */ + __pyx_t_1 = PyFloat_FromDouble((__pyx_v_rule->cscores[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyLong_FromUnsignedLong(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Add(((PyObject *)__pyx_n_s__PhraseModel_), __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyObject_SetItem(__pyx_v_scores, __pyx_t_5, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":34 + * for i in range(rule.n_scores): + * scores['PhraseModel_'+str(i)] = rule.cscores[i] + * f, e = [], [] # <<<<<<<<<<<<<< + * cdef int* fsyms = rule.f.syms + * for i in range(rule.f.n): + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_v_f = __pyx_t_1; + __pyx_t_1 = 0; + __pyx_v_e = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":35 + * scores['PhraseModel_'+str(i)] = rule.cscores[i] + * f, e = [], [] + * cdef int* fsyms = rule.f.syms # <<<<<<<<<<<<<< + * for i in range(rule.f.n): + * if _sa.sym_isvar(fsyms[i]): + */ + __pyx_v_fsyms = __pyx_v_rule->f->syms; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":36 + * f, e = [], [] + * cdef int* fsyms = rule.f.syms + * for i in range(rule.f.n): # <<<<<<<<<<<<<< + * if _sa.sym_isvar(fsyms[i]): + * f.append(NT(_sa.sym_tocat(fsyms[i]))) + */ + __pyx_t_2 = __pyx_v_rule->f->n; + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":37 + * cdef int* fsyms = rule.f.syms + * for i in range(rule.f.n): + * if _sa.sym_isvar(fsyms[i]): # <<<<<<<<<<<<<< + * f.append(NT(_sa.sym_tocat(fsyms[i]))) + * else: + */ + __pyx_t_6 = __pyx_f_4cdec_2sa_3_sa_sym_isvar((__pyx_v_fsyms[__pyx_v_i])); + if (__pyx_t_6) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":38 + * for i in range(rule.f.n): + * if _sa.sym_isvar(fsyms[i]): + * f.append(NT(_sa.sym_tocat(fsyms[i]))) # <<<<<<<<<<<<<< + * else: + * f.append(_sa.sym_tostring(fsyms[i])) + */ + __pyx_t_5 = PyBytes_FromString(__pyx_f_4cdec_2sa_3_sa_sym_tocat((__pyx_v_fsyms[__pyx_v_i]))); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_5)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NT)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_7 = PyList_Append(__pyx_v_f, __pyx_t_5); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":40 + * f.append(NT(_sa.sym_tocat(fsyms[i]))) + * else: + * f.append(_sa.sym_tostring(fsyms[i])) # <<<<<<<<<<<<<< + * cdef int* esyms = rule.e.syms + * for i in range(rule.e.n): + */ + __pyx_t_5 = PyBytes_FromString(__pyx_f_4cdec_2sa_3_sa_sym_tostring((__pyx_v_fsyms[__pyx_v_i]))); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __pyx_t_7 = PyList_Append(__pyx_v_f, ((PyObject *)__pyx_t_5)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + } + __pyx_L7:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":41 + * else: + * f.append(_sa.sym_tostring(fsyms[i])) + * cdef int* esyms = rule.e.syms # <<<<<<<<<<<<<< + * for i in range(rule.e.n): + * if _sa.sym_isvar(esyms[i]): + */ + __pyx_v_esyms = __pyx_v_rule->e->syms; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":42 + * f.append(_sa.sym_tostring(fsyms[i])) + * cdef int* esyms = rule.e.syms + * for i in range(rule.e.n): # <<<<<<<<<<<<<< + * if _sa.sym_isvar(esyms[i]): + * e.append(NTRef(_sa.sym_getindex(esyms[i]))) + */ + __pyx_t_2 = __pyx_v_rule->e->n; + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":43 + * cdef int* esyms = rule.e.syms + * for i in range(rule.e.n): + * if _sa.sym_isvar(esyms[i]): # <<<<<<<<<<<<<< + * e.append(NTRef(_sa.sym_getindex(esyms[i]))) + * else: + */ + __pyx_t_6 = __pyx_f_4cdec_2sa_3_sa_sym_isvar((__pyx_v_esyms[__pyx_v_i])); + if (__pyx_t_6) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":44 + * for i in range(rule.e.n): + * if _sa.sym_isvar(esyms[i]): + * e.append(NTRef(_sa.sym_getindex(esyms[i]))) # <<<<<<<<<<<<<< + * else: + * e.append(_sa.sym_tostring(esyms[i])) + */ + __pyx_t_5 = PyInt_FromLong(__pyx_f_4cdec_2sa_3_sa_sym_getindex((__pyx_v_esyms[__pyx_v_i]))); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NTRef)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_7 = PyList_Append(__pyx_v_e, __pyx_t_5); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L10; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":46 + * e.append(NTRef(_sa.sym_getindex(esyms[i]))) + * else: + * e.append(_sa.sym_tostring(esyms[i])) # <<<<<<<<<<<<<< + * cdef a = [(point/65536, point%65536) for point in rule.word_alignments] + * return TRule(lhs, f, e, scores, a) + */ + __pyx_t_5 = PyBytes_FromString(__pyx_f_4cdec_2sa_3_sa_sym_tostring((__pyx_v_esyms[__pyx_v_i]))); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __pyx_t_7 = PyList_Append(__pyx_v_e, ((PyObject *)__pyx_t_5)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + } + __pyx_L10:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":47 + * else: + * e.append(_sa.sym_tostring(esyms[i])) + * cdef a = [(point/65536, point%65536) for point in rule.word_alignments] # <<<<<<<<<<<<<< + * return TRule(lhs, f, e, scores, a) + * + */ + __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + if (PyList_CheckExact(__pyx_v_rule->word_alignments) || PyTuple_CheckExact(__pyx_v_rule->word_alignments)) { + __pyx_t_1 = __pyx_v_rule->word_alignments; __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_rule->word_alignments); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_4); __pyx_t_8++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_4); __pyx_t_8++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_4 = __pyx_t_9(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_point); + __pyx_v_point = __pyx_t_4; + __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyNumber_Divide(__pyx_v_point, __pyx_int_65536); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_10 = PyNumber_Remainder(__pyx_v_point, __pyx_int_65536); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_t_4 = 0; + __pyx_t_10 = 0; + if (unlikely(__Pyx_PyList_Append(__pyx_t_5, (PyObject*)__pyx_t_11))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_INCREF(((PyObject *)__pyx_t_5)); + __pyx_v_a = ((PyObject *)__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":48 + * e.append(_sa.sym_tostring(esyms[i])) + * cdef a = [(point/65536, point%65536) for point in rule.word_alignments] + * return TRule(lhs, f, e, scores, a) # <<<<<<<<<<<<<< + * + * cdef class TRule: + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_lhs); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_lhs); + __Pyx_GIVEREF(__pyx_v_lhs); + __Pyx_INCREF(((PyObject *)__pyx_v_f)); + PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_f)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_f)); + __Pyx_INCREF(((PyObject *)__pyx_v_e)); + PyTuple_SET_ITEM(__pyx_t_5, 2, ((PyObject *)__pyx_v_e)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_e)); + __Pyx_INCREF(__pyx_v_scores); + PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_v_scores); + __Pyx_GIVEREF(__pyx_v_scores); + __Pyx_INCREF(__pyx_v_a); + PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_v_a); + __Pyx_GIVEREF(__pyx_v_a); + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_TRule)), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_r = ((struct __pyx_obj_5_cdec_TRule *)__pyx_t_1); + __pyx_t_1 = 0; + goto __pyx_L0; + + __pyx_r = ((struct __pyx_obj_5_cdec_TRule *)Py_None); __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("_cdec.convert_rule", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_lhs); + __Pyx_XDECREF(__pyx_v_scores); + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_e); + __Pyx_XDECREF(__pyx_v_a); + __Pyx_XDECREF(__pyx_v_point); + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_5TRule_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_5TRule_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_lhs = 0; + PyObject *__pyx_v_f = 0; + PyObject *__pyx_v_e = 0; + PyObject *__pyx_v_scores = 0; + PyObject *__pyx_v_a = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__lhs,&__pyx_n_s__f,&__pyx_n_s__e,&__pyx_n_s__scores,&__pyx_n_s__a,0}; + PyObject* values[5] = {0,0,0,0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":53 + * cdef shared_ptr[grammar.TRule]* rule + * + * def __init__(self, lhs, f, e, scores, a=None): # <<<<<<<<<<<<<< + * self.rule = new shared_ptr[grammar.TRule](new grammar.TRule()) + * self.lhs = lhs + */ + values[4] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__lhs)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__f)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__e)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 2); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 3: + if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__scores)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 3); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__a); + if (value) { values[4] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_lhs = values[0]; + __pyx_v_f = values[1]; + __pyx_v_e = values[2]; + __pyx_v_scores = values[3]; + __pyx_v_a = values[4]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.TRule.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_5TRule___init__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self), __pyx_v_lhs, __pyx_v_f, __pyx_v_e, __pyx_v_scores, __pyx_v_a); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5_cdec_5TRule___init__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self, PyObject *__pyx_v_lhs, PyObject *__pyx_v_f, PyObject *__pyx_v_e, PyObject *__pyx_v_scores, PyObject *__pyx_v_a) { + int __pyx_r; + __Pyx_RefNannyDeclarations + TRule *__pyx_t_1; + int __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__init__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":54 + * + * def __init__(self, lhs, f, e, scores, a=None): + * self.rule = new shared_ptr[grammar.TRule](new grammar.TRule()) # <<<<<<<<<<<<<< + * self.lhs = lhs + * self.e = e + */ + try {__pyx_t_1 = new TRule();} catch(...) {__Pyx_CppExn2PyErr(); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}} + __pyx_v_self->rule = new boost::shared_ptr(__pyx_t_1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":55 + * def __init__(self, lhs, f, e, scores, a=None): + * self.rule = new shared_ptr[grammar.TRule](new grammar.TRule()) + * self.lhs = lhs # <<<<<<<<<<<<<< + * self.e = e + * self.f = f + */ + if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__lhs, __pyx_v_lhs) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":56 + * self.rule = new shared_ptr[grammar.TRule](new grammar.TRule()) + * self.lhs = lhs + * self.e = e # <<<<<<<<<<<<<< + * self.f = f + * self.scores = scores + */ + if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__e, __pyx_v_e) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":57 + * self.lhs = lhs + * self.e = e + * self.f = f # <<<<<<<<<<<<<< + * self.scores = scores + * if a: + */ + if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__f, __pyx_v_f) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":58 + * self.e = e + * self.f = f + * self.scores = scores # <<<<<<<<<<<<<< + * if a: + * self.a = a + */ + if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__scores, __pyx_v_scores) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":59 + * self.f = f + * self.scores = scores + * if a: # <<<<<<<<<<<<<< + * self.a = a + * self.rule.get().ComputeArity() + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_a); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":60 + * self.scores = scores + * if a: + * self.a = a # <<<<<<<<<<<<<< + * self.rule.get().ComputeArity() + * + */ + if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__a, __pyx_v_a) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":61 + * if a: + * self.a = a + * self.rule.get().ComputeArity() # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->rule->get()->ComputeArity(); + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.TRule.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_5TRule_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_5TRule_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_5TRule_2__dealloc__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":63 + * self.rule.get().ComputeArity() + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.rule + * + */ + +static void __pyx_pf_5_cdec_5TRule_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_TRule *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":64 + * + * def __dealloc__(self): + * del self.rule # <<<<<<<<<<<<<< + * + * property arity: + */ + delete __pyx_v_self->rule; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_5TRule_5arity_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_5TRule_5arity_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_5TRule_5arity___get__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":67 + * + * property arity: + * def __get__(self): # <<<<<<<<<<<<<< + * return self.rule.get().arity_ + * + */ + +static PyObject *__pyx_pf_5_cdec_5TRule_5arity___get__(struct __pyx_obj_5_cdec_TRule *__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("__get__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":68 + * property arity: + * def __get__(self): + * return self.rule.get().arity_ # <<<<<<<<<<<<<< + * + * property f: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->rule->get()->arity_); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; @@ -5150,7 +6055,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_5arity___get__(struct __pyx_obj_5_cd goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.BaseTRule.arity.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.TRule.arity.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -5159,17 +6064,17 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_5arity___get__(struct __pyx_obj_5_cd } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_9BaseTRule_1f_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_9BaseTRule_1f_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_5TRule_1f_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_5TRule_1f_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9BaseTRule_1f___get__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_5TRule_1f___get__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":37 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":71 * * property f: * def __get__(self): # <<<<<<<<<<<<<< @@ -5177,7 +6082,7 @@ static PyObject *__pyx_pw_5_cdec_9BaseTRule_1f_1__get__(PyObject *__pyx_v_self) * cdef WordID w */ -static PyObject *__pyx_pf_5_cdec_9BaseTRule_1f___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_5TRule_1f___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self) { std::vector *__pyx_v_f_; WordID __pyx_v_w; PyObject *__pyx_v_f = 0; @@ -5196,7 +6101,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1f___get__(struct __pyx_obj_5_cdec_B int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":38 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":72 * property f: * def __get__(self): * cdef vector[WordID]* f_ = &self.rule.get().f_ # <<<<<<<<<<<<<< @@ -5205,19 +6110,19 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1f___get__(struct __pyx_obj_5_cdec_B */ __pyx_v_f_ = (&__pyx_v_self->rule->get()->f_); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":40 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":74 * cdef vector[WordID]* f_ = &self.rule.get().f_ * cdef WordID w * cdef f = [] # <<<<<<<<<<<<<< * cdef unsigned i * cdef int idx = 0 */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_f = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":42 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":76 * cdef f = [] * cdef unsigned i * cdef int idx = 0 # <<<<<<<<<<<<<< @@ -5226,7 +6131,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1f___get__(struct __pyx_obj_5_cdec_B */ __pyx_v_idx = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":43 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":77 * cdef unsigned i * cdef int idx = 0 * for i in range(f_.size()): # <<<<<<<<<<<<<< @@ -5237,7 +6142,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1f___get__(struct __pyx_obj_5_cdec_B for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v_i = __pyx_t_3; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":44 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":78 * cdef int idx = 0 * for i in range(f_.size()): * w = f_[0][i] # <<<<<<<<<<<<<< @@ -5246,7 +6151,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1f___get__(struct __pyx_obj_5_cdec_B */ __pyx_v_w = ((__pyx_v_f_[0])[__pyx_v_i]); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":45 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":79 * for i in range(f_.size()): * w = f_[0][i] * if w < 0: # <<<<<<<<<<<<<< @@ -5256,7 +6161,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1f___get__(struct __pyx_obj_5_cdec_B __pyx_t_4 = (__pyx_v_w < 0); if (__pyx_t_4) { - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":46 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":80 * w = f_[0][i] * if w < 0: * idx += 1 # <<<<<<<<<<<<<< @@ -5265,18 +6170,18 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1f___get__(struct __pyx_obj_5_cdec_B */ __pyx_v_idx = (__pyx_v_idx + 1); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":47 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":81 * if w < 0: * idx += 1 * f.append(NT(TDConvert(-w), idx)) # <<<<<<<<<<<<<< * else: * f.append(unicode(TDConvert(w), encoding='utf8')) */ - __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_w))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_w))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_5 = PyInt_FromLong(__pyx_v_idx); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyInt_FromLong(__pyx_v_idx); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); @@ -5284,10 +6189,10 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1f___get__(struct __pyx_obj_5_cdec_B __Pyx_GIVEREF(__pyx_t_5); __pyx_t_1 = 0; __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NT)), ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NT)), ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyObject_Append(__pyx_v_f, __pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __Pyx_PyObject_Append(__pyx_v_f, __pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; @@ -5295,28 +6200,28 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1f___get__(struct __pyx_obj_5_cdec_B } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":49 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":83 * f.append(NT(TDConvert(-w), idx)) * else: * f.append(unicode(TDConvert(w), encoding='utf8')) # <<<<<<<<<<<<<< * return f * */ - __pyx_t_6 = PyBytes_FromString(TD::Convert(__pyx_v_w)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyBytes_FromString(TD::Convert(__pyx_v_w)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_6)); - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_6)); __Pyx_GIVEREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_6)); - if (PyDict_SetItem(__pyx_t_6, ((PyObject *)__pyx_n_s__encoding), ((PyObject *)__pyx_n_s__utf8)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_5), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_6, ((PyObject *)__pyx_n_s__encoding), ((PyObject *)__pyx_n_s__utf8)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_5), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __pyx_t_6 = __Pyx_PyObject_Append(__pyx_v_f, __pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __Pyx_PyObject_Append(__pyx_v_f, __pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; @@ -5324,7 +6229,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1f___get__(struct __pyx_obj_5_cdec_B __pyx_L5:; } - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":50 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":84 * else: * f.append(unicode(TDConvert(w), encoding='utf8')) * return f # <<<<<<<<<<<<<< @@ -5342,7 +6247,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1f___get__(struct __pyx_obj_5_cdec_B __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("_cdec.BaseTRule.f.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.TRule.f.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_f); @@ -5352,17 +6257,17 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1f___get__(struct __pyx_obj_5_cdec_B } /* Python wrapper */ -static int __pyx_pw_5_cdec_9BaseTRule_1f_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_f); /*proto*/ -static int __pyx_pw_5_cdec_9BaseTRule_1f_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_f) { +static int __pyx_pw_5_cdec_5TRule_1f_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_f); /*proto*/ +static int __pyx_pw_5_cdec_5TRule_1f_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_f) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9BaseTRule_1f_2__set__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self), ((PyObject *)__pyx_v_f)); + __pyx_r = __pyx_pf_5_cdec_5TRule_1f_2__set__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self), ((PyObject *)__pyx_v_f)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":52 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":86 * return f * * def __set__(self, f): # <<<<<<<<<<<<<< @@ -5370,7 +6275,7 @@ static int __pyx_pw_5_cdec_9BaseTRule_1f_3__set__(PyObject *__pyx_v_self, PyObje * f_.resize(len(f)) */ -static int __pyx_pf_5_cdec_9BaseTRule_1f_2__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_f) { +static int __pyx_pf_5_cdec_5TRule_1f_2__set__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self, PyObject *__pyx_v_f) { std::vector *__pyx_v_f_; unsigned int __pyx_v_i; CYTHON_UNUSED int __pyx_v_idx; @@ -5387,7 +6292,7 @@ static int __pyx_pf_5_cdec_9BaseTRule_1f_2__set__(struct __pyx_obj_5_cdec_BaseTR int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":53 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":87 * * def __set__(self, f): * cdef vector[WordID]* f_ = &self.rule.get().f_ # <<<<<<<<<<<<<< @@ -5396,17 +6301,17 @@ static int __pyx_pf_5_cdec_9BaseTRule_1f_2__set__(struct __pyx_obj_5_cdec_BaseTR */ __pyx_v_f_ = (&__pyx_v_self->rule->get()->f_); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":54 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":88 * def __set__(self, f): * cdef vector[WordID]* f_ = &self.rule.get().f_ * f_.resize(len(f)) # <<<<<<<<<<<<<< * cdef unsigned i * cdef int idx = 0 */ - __pyx_t_1 = PyObject_Length(__pyx_v_f); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Length(__pyx_v_f); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_f_->resize(__pyx_t_1); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":56 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":90 * f_.resize(len(f)) * cdef unsigned i * cdef int idx = 0 # <<<<<<<<<<<<<< @@ -5415,25 +6320,25 @@ static int __pyx_pf_5_cdec_9BaseTRule_1f_2__set__(struct __pyx_obj_5_cdec_BaseTR */ __pyx_v_idx = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":57 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":91 * cdef unsigned i * cdef int idx = 0 * for i in range(len(f)): # <<<<<<<<<<<<<< * if isinstance(f[i], NT): * f_[0][i] = -TDConvert(f[i].cat) */ - __pyx_t_1 = PyObject_Length(__pyx_v_f); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Length(__pyx_v_f); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":58 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":92 * cdef int idx = 0 * for i in range(len(f)): * if isinstance(f[i], NT): # <<<<<<<<<<<<<< * f_[0][i] = -TDConvert(f[i].cat) * else: */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_f, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_f, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NT)); __Pyx_INCREF(__pyx_t_4); @@ -5442,33 +6347,33 @@ static int __pyx_pf_5_cdec_9BaseTRule_1f_2__set__(struct __pyx_obj_5_cdec_BaseTR __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_5) { - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":59 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":93 * for i in range(len(f)): * if isinstance(f[i], NT): * f_[0][i] = -TDConvert(f[i].cat) # <<<<<<<<<<<<<< * else: * f_[0][i] = TDConvert(as_str(f[i])) */ - __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_f, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_f, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__cat); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__cat); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_6 = PyBytes_AsString(__pyx_t_3); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyBytes_AsString(__pyx_t_3); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; ((__pyx_v_f_[0])[__pyx_v_i]) = (-TD::Convert(((char *)__pyx_t_6))); goto __pyx_L5; } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":61 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":95 * f_[0][i] = -TDConvert(f[i].cat) * else: * f_[0][i] = TDConvert(as_str(f[i])) # <<<<<<<<<<<<<< * * property e: */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_f, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_f, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); ((__pyx_v_f_[0])[__pyx_v_i]) = TD::Convert(((char *)__pyx_f_5_cdec_as_str(__pyx_t_3, NULL))); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -5481,7 +6386,7 @@ static int __pyx_pf_5_cdec_9BaseTRule_1f_2__set__(struct __pyx_obj_5_cdec_BaseTR __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec.BaseTRule.f.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.TRule.f.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); @@ -5489,17 +6394,17 @@ static int __pyx_pf_5_cdec_9BaseTRule_1f_2__set__(struct __pyx_obj_5_cdec_BaseTR } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_9BaseTRule_1e_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_9BaseTRule_1e_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_5TRule_1e_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_5TRule_1e_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9BaseTRule_1e___get__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_5TRule_1e___get__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":64 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":98 * * property e: * def __get__(self): # <<<<<<<<<<<<<< @@ -5507,7 +6412,7 @@ static PyObject *__pyx_pw_5_cdec_9BaseTRule_1e_1__get__(PyObject *__pyx_v_self) * cdef WordID w */ -static PyObject *__pyx_pf_5_cdec_9BaseTRule_1e___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_5TRule_1e___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self) { std::vector *__pyx_v_e_; WordID __pyx_v_w; PyObject *__pyx_v_e = 0; @@ -5526,7 +6431,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1e___get__(struct __pyx_obj_5_cdec_B int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":65 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":99 * property e: * def __get__(self): * cdef vector[WordID]* e_ = &self.rule.get().e_ # <<<<<<<<<<<<<< @@ -5535,19 +6440,19 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1e___get__(struct __pyx_obj_5_cdec_B */ __pyx_v_e_ = (&__pyx_v_self->rule->get()->e_); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":67 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":101 * cdef vector[WordID]* e_ = &self.rule.get().e_ * cdef WordID w * cdef e = [] # <<<<<<<<<<<<<< * cdef unsigned i * cdef int idx = 0 */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_e = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":69 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":103 * cdef e = [] * cdef unsigned i * cdef int idx = 0 # <<<<<<<<<<<<<< @@ -5556,7 +6461,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1e___get__(struct __pyx_obj_5_cdec_B */ __pyx_v_idx = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":70 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":104 * cdef unsigned i * cdef int idx = 0 * for i in range(e_.size()): # <<<<<<<<<<<<<< @@ -5567,7 +6472,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1e___get__(struct __pyx_obj_5_cdec_B for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v_i = __pyx_t_3; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":71 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":105 * cdef int idx = 0 * for i in range(e_.size()): * w = e_[0][i] # <<<<<<<<<<<<<< @@ -5576,7 +6481,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1e___get__(struct __pyx_obj_5_cdec_B */ __pyx_v_w = ((__pyx_v_e_[0])[__pyx_v_i]); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":72 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":106 * for i in range(e_.size()): * w = e_[0][i] * if w < 1: # <<<<<<<<<<<<<< @@ -5586,7 +6491,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1e___get__(struct __pyx_obj_5_cdec_B __pyx_t_4 = (__pyx_v_w < 1); if (__pyx_t_4) { - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":73 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":107 * w = e_[0][i] * if w < 1: * idx += 1 # <<<<<<<<<<<<<< @@ -5595,24 +6500,24 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1e___get__(struct __pyx_obj_5_cdec_B */ __pyx_v_idx = (__pyx_v_idx + 1); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":74 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":108 * if w < 1: * idx += 1 * e.append(NTRef(1-w)) # <<<<<<<<<<<<<< * else: * e.append(unicode(TDConvert(w), encoding='utf8')) */ - __pyx_t_1 = PyInt_FromLong((1 - __pyx_v_w)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyInt_FromLong((1 - __pyx_v_w)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NTRef)), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NTRef)), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_e, __pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_e, __pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; @@ -5620,28 +6525,28 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1e___get__(struct __pyx_obj_5_cdec_B } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":76 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":110 * e.append(NTRef(1-w)) * else: * e.append(unicode(TDConvert(w), encoding='utf8')) # <<<<<<<<<<<<<< * return e * */ - __pyx_t_5 = PyBytes_FromString(TD::Convert(__pyx_v_w)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyBytes_FromString(TD::Convert(__pyx_v_w)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_5)); __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__encoding), ((PyObject *)__pyx_n_s__utf8)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__encoding), ((PyObject *)__pyx_n_s__utf8)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_e, __pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyObject_Append(__pyx_v_e, __pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; @@ -5649,7 +6554,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1e___get__(struct __pyx_obj_5_cdec_B __pyx_L5:; } - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":77 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":111 * else: * e.append(unicode(TDConvert(w), encoding='utf8')) * return e # <<<<<<<<<<<<<< @@ -5667,7 +6572,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1e___get__(struct __pyx_obj_5_cdec_B __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("_cdec.BaseTRule.e.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.TRule.e.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_e); @@ -5677,17 +6582,17 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1e___get__(struct __pyx_obj_5_cdec_B } /* Python wrapper */ -static int __pyx_pw_5_cdec_9BaseTRule_1e_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_e); /*proto*/ -static int __pyx_pw_5_cdec_9BaseTRule_1e_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_e) { +static int __pyx_pw_5_cdec_5TRule_1e_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_e); /*proto*/ +static int __pyx_pw_5_cdec_5TRule_1e_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_e) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9BaseTRule_1e_2__set__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self), ((PyObject *)__pyx_v_e)); + __pyx_r = __pyx_pf_5_cdec_5TRule_1e_2__set__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self), ((PyObject *)__pyx_v_e)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":79 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":113 * return e * * def __set__(self, e): # <<<<<<<<<<<<<< @@ -5695,7 +6600,7 @@ static int __pyx_pw_5_cdec_9BaseTRule_1e_3__set__(PyObject *__pyx_v_self, PyObje * e_.resize(len(e)) */ -static int __pyx_pf_5_cdec_9BaseTRule_1e_2__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_e) { +static int __pyx_pf_5_cdec_5TRule_1e_2__set__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self, PyObject *__pyx_v_e) { std::vector *__pyx_v_e_; unsigned int __pyx_v_i; int __pyx_r; @@ -5711,7 +6616,7 @@ static int __pyx_pf_5_cdec_9BaseTRule_1e_2__set__(struct __pyx_obj_5_cdec_BaseTR int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":80 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":114 * * def __set__(self, e): * cdef vector[WordID]* e_ = &self.rule.get().e_ # <<<<<<<<<<<<<< @@ -5720,35 +6625,35 @@ static int __pyx_pf_5_cdec_9BaseTRule_1e_2__set__(struct __pyx_obj_5_cdec_BaseTR */ __pyx_v_e_ = (&__pyx_v_self->rule->get()->e_); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":81 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":115 * def __set__(self, e): * cdef vector[WordID]* e_ = &self.rule.get().e_ * e_.resize(len(e)) # <<<<<<<<<<<<<< * cdef unsigned i * for i in range(len(e)): */ - __pyx_t_1 = PyObject_Length(__pyx_v_e); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Length(__pyx_v_e); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_e_->resize(__pyx_t_1); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":83 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":117 * e_.resize(len(e)) * cdef unsigned i * for i in range(len(e)): # <<<<<<<<<<<<<< * if isinstance(e[i], NTRef): * e_[0][i] = 1-e[i].ref */ - __pyx_t_1 = PyObject_Length(__pyx_v_e); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Length(__pyx_v_e); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":84 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":118 * cdef unsigned i * for i in range(len(e)): * if isinstance(e[i], NTRef): # <<<<<<<<<<<<<< * e_[0][i] = 1-e[i].ref * else: */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_e, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_e, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NTRef)); __Pyx_INCREF(__pyx_t_4); @@ -5757,36 +6662,36 @@ static int __pyx_pf_5_cdec_9BaseTRule_1e_2__set__(struct __pyx_obj_5_cdec_BaseTR __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_5) { - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":85 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":119 * for i in range(len(e)): * if isinstance(e[i], NTRef): * e_[0][i] = 1-e[i].ref # <<<<<<<<<<<<<< * else: * e_[0][i] = TDConvert(as_str(e[i])) */ - __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_e, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_e, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__ref); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__ref); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_Subtract(__pyx_int_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyNumber_Subtract(__pyx_int_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyInt_from_py_WordID(__pyx_t_4); if (unlikely((__pyx_t_6 == (WordID)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __Pyx_PyInt_from_py_WordID(__pyx_t_4); if (unlikely((__pyx_t_6 == (WordID)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; ((__pyx_v_e_[0])[__pyx_v_i]) = __pyx_t_6; goto __pyx_L5; } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":87 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":121 * e_[0][i] = 1-e[i].ref * else: * e_[0][i] = TDConvert(as_str(e[i])) # <<<<<<<<<<<<<< * * property a: */ - __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_e, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_e, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); ((__pyx_v_e_[0])[__pyx_v_i]) = TD::Convert(((char *)__pyx_f_5_cdec_as_str(__pyx_t_4, NULL))); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -5799,26 +6704,26 @@ static int __pyx_pf_5_cdec_9BaseTRule_1e_2__set__(struct __pyx_obj_5_cdec_BaseTR __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec.BaseTRule.e.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.TRule.e.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_9BaseTRule_1a_2generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5_cdec_5TRule_1a_2generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_9BaseTRule_1a_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_9BaseTRule_1a_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_5TRule_1a_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_5TRule_1a_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9BaseTRule_1a___get__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_5TRule_1a___get__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":90 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":124 * * property a: * def __get__(self): # <<<<<<<<<<<<<< @@ -5826,7 +6731,7 @@ static PyObject *__pyx_pw_5_cdec_9BaseTRule_1a_1__get__(PyObject *__pyx_v_self) * cdef vector[grammar.AlignmentPoint]* a = &self.rule.get().a_ */ -static PyObject *__pyx_pf_5_cdec_9BaseTRule_1a___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_5TRule_1a___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self) { struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -5844,7 +6749,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1a___get__(struct __pyx_obj_5_cdec_B __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_9BaseTRule_1a_2generator2, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_5TRule_1a_2generator2, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -5853,7 +6758,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1a___get__(struct __pyx_obj_5_cdec_B __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.BaseTRule.a.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.TRule.a.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); @@ -5862,7 +6767,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_1a___get__(struct __pyx_obj_5_cdec_B return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_9BaseTRule_1a_2generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_5TRule_1a_2generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; @@ -5881,9 +6786,9 @@ static PyObject *__pyx_gb_5_cdec_9BaseTRule_1a_2generator2(__pyx_GeneratorObject return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":92 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":126 * def __get__(self): * cdef unsigned i * cdef vector[grammar.AlignmentPoint]* a = &self.rule.get().a_ # <<<<<<<<<<<<<< @@ -5892,7 +6797,7 @@ static PyObject *__pyx_gb_5_cdec_9BaseTRule_1a_2generator2(__pyx_GeneratorObject */ __pyx_cur_scope->__pyx_v_a = (&__pyx_cur_scope->__pyx_v_self->rule->get()->a_); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":93 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":127 * cdef unsigned i * cdef vector[grammar.AlignmentPoint]* a = &self.rule.get().a_ * for i in range(a.size()): # <<<<<<<<<<<<<< @@ -5903,18 +6808,18 @@ static PyObject *__pyx_gb_5_cdec_9BaseTRule_1a_2generator2(__pyx_GeneratorObject for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":94 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":128 * cdef vector[grammar.AlignmentPoint]* a = &self.rule.get().a_ * for i in range(a.size()): * yield (a[0][i].s_, a[0][i].t_) # <<<<<<<<<<<<<< * * def __set__(self, a): */ - __pyx_t_3 = PyInt_FromLong(((__pyx_cur_scope->__pyx_v_a[0])[__pyx_cur_scope->__pyx_v_i]).s_); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong(((__pyx_cur_scope->__pyx_v_a[0])[__pyx_cur_scope->__pyx_v_i]).s_); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyInt_FromLong(((__pyx_cur_scope->__pyx_v_a[0])[__pyx_cur_scope->__pyx_v_i]).t_); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(((__pyx_cur_scope->__pyx_v_a[0])[__pyx_cur_scope->__pyx_v_i]).t_); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 128; __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[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); @@ -5934,7 +6839,7 @@ static PyObject *__pyx_gb_5_cdec_9BaseTRule_1a_2generator2(__pyx_GeneratorObject __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[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; @@ -5946,22 +6851,23 @@ static PyObject *__pyx_gb_5_cdec_9BaseTRule_1a_2generator2(__pyx_GeneratorObject __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } /* Python wrapper */ -static int __pyx_pw_5_cdec_9BaseTRule_1a_4__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_a); /*proto*/ -static int __pyx_pw_5_cdec_9BaseTRule_1a_4__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_a) { +static int __pyx_pw_5_cdec_5TRule_1a_4__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_a); /*proto*/ +static int __pyx_pw_5_cdec_5TRule_1a_4__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_a) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9BaseTRule_1a_3__set__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self), ((PyObject *)__pyx_v_a)); + __pyx_r = __pyx_pf_5_cdec_5TRule_1a_3__set__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self), ((PyObject *)__pyx_v_a)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":96 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":130 * yield (a[0][i].s_, a[0][i].t_) * * def __set__(self, a): # <<<<<<<<<<<<<< @@ -5969,7 +6875,7 @@ static int __pyx_pw_5_cdec_9BaseTRule_1a_4__set__(PyObject *__pyx_v_self, PyObje * a_.resize(len(a)) */ -static int __pyx_pf_5_cdec_9BaseTRule_1a_3__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_a) { +static int __pyx_pf_5_cdec_5TRule_1a_3__set__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self, PyObject *__pyx_v_a) { std::vector *__pyx_v_a_; unsigned int __pyx_v_i; int __pyx_v_s; @@ -5990,7 +6896,7 @@ static int __pyx_pf_5_cdec_9BaseTRule_1a_3__set__(struct __pyx_obj_5_cdec_BaseTR int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":97 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":131 * * def __set__(self, a): * cdef vector[grammar.AlignmentPoint]* a_ = &self.rule.get().a_ # <<<<<<<<<<<<<< @@ -5999,61 +6905,67 @@ static int __pyx_pf_5_cdec_9BaseTRule_1a_3__set__(struct __pyx_obj_5_cdec_BaseTR */ __pyx_v_a_ = (&__pyx_v_self->rule->get()->a_); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":98 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":132 * def __set__(self, a): * cdef vector[grammar.AlignmentPoint]* a_ = &self.rule.get().a_ * a_.resize(len(a)) # <<<<<<<<<<<<<< * cdef unsigned i * cdef int s, t */ - __pyx_t_1 = PyObject_Length(__pyx_v_a); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Length(__pyx_v_a); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_a_->resize(__pyx_t_1); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":101 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":135 * cdef unsigned i * cdef int s, t * for i in range(len(a)): # <<<<<<<<<<<<<< * s, t = a[i] * a_[0][i] = grammar.AlignmentPoint(s, t) */ - __pyx_t_1 = PyObject_Length(__pyx_v_a); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Length(__pyx_v_a); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":102 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":136 * cdef int s, t * for i in range(len(a)): * s, t = a[i] # <<<<<<<<<<<<<< * a_[0][i] = grammar.AlignmentPoint(s, t) * */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_a, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_a, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { PyObject* sequence = __pyx_t_3; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON if (likely(PyTuple_CheckExact(sequence))) { - 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[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); } else { - 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[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } __pyx_t_4 = PyList_GET_ITEM(sequence, 0); __pyx_t_5 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(__pyx_t_5); + #else + __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { + } else + { Py_ssize_t index = -1; - __pyx_t_6 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_7 = Py_TYPE(__pyx_t_6)->tp_iternext; @@ -6061,24 +6973,25 @@ static int __pyx_pf_5_cdec_9BaseTRule_1a_3__set__(struct __pyx_obj_5_cdec_BaseTR __Pyx_GOTREF(__pyx_t_4); index = 1; __pyx_t_5 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_5)) goto __pyx_L5_unpacking_failed; __Pyx_GOTREF(__pyx_t_5); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = NULL; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; goto __pyx_L6_unpacking_done; __pyx_L5_unpacking_failed:; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L6_unpacking_done:; } - __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_5); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = __Pyx_PyInt_AsInt(__pyx_t_5); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_s = __pyx_t_8; __pyx_v_t = __pyx_t_9; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":103 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":137 * for i in range(len(a)): * s, t = a[i] * a_[0][i] = grammar.AlignmentPoint(s, t) # <<<<<<<<<<<<<< @@ -6095,7 +7008,7 @@ static int __pyx_pf_5_cdec_9BaseTRule_1a_3__set__(struct __pyx_obj_5_cdec_BaseTR __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("_cdec.BaseTRule.a.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.TRule.a.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_RefNannyFinishContext(); @@ -6103,25 +7016,25 @@ static int __pyx_pf_5_cdec_9BaseTRule_1a_3__set__(struct __pyx_obj_5_cdec_BaseTR } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_9BaseTRule_6scores_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_9BaseTRule_6scores_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_5TRule_6scores_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_5TRule_6scores_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9BaseTRule_6scores___get__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_5TRule_6scores___get__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":106 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":140 * * property scores: * def __get__(self): # <<<<<<<<<<<<<< - * cdef SparseVector scores = SparseVector() + * cdef SparseVector scores = SparseVector.__new__(SparseVector) * scores.vector = new FastSparseVector[double](self.rule.get().scores_) */ -static PyObject *__pyx_pf_5_cdec_9BaseTRule_6scores___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_5TRule_6scores___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_scores = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -6131,29 +7044,30 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_6scores___get__(struct __pyx_obj_5_c int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":107 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":141 * property scores: * def __get__(self): - * cdef SparseVector scores = SparseVector() # <<<<<<<<<<<<<< + * cdef SparseVector scores = SparseVector.__new__(SparseVector) # <<<<<<<<<<<<<< * scores.vector = new FastSparseVector[double](self.rule.get().scores_) * return scores */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5_cdec_SparseVector)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); + if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5_cdec_SparseVector)))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_scores = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":108 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":142 * def __get__(self): - * cdef SparseVector scores = SparseVector() + * cdef SparseVector scores = SparseVector.__new__(SparseVector) * scores.vector = new FastSparseVector[double](self.rule.get().scores_) # <<<<<<<<<<<<<< * return scores * */ __pyx_v_scores->vector = new FastSparseVector(__pyx_v_self->rule->get()->scores_); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":109 - * cdef SparseVector scores = SparseVector() + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":143 + * cdef SparseVector scores = SparseVector.__new__(SparseVector) * scores.vector = new FastSparseVector[double](self.rule.get().scores_) * return scores # <<<<<<<<<<<<<< * @@ -6168,7 +7082,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_6scores___get__(struct __pyx_obj_5_c goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.BaseTRule.scores.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.TRule.scores.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_scores); @@ -6178,17 +7092,17 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_6scores___get__(struct __pyx_obj_5_c } /* Python wrapper */ -static int __pyx_pw_5_cdec_9BaseTRule_6scores_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_scores); /*proto*/ -static int __pyx_pw_5_cdec_9BaseTRule_6scores_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_scores) { +static int __pyx_pw_5_cdec_5TRule_6scores_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_scores); /*proto*/ +static int __pyx_pw_5_cdec_5TRule_6scores_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_scores) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9BaseTRule_6scores_2__set__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self), ((PyObject *)__pyx_v_scores)); + __pyx_r = __pyx_pf_5_cdec_5TRule_6scores_2__set__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self), ((PyObject *)__pyx_v_scores)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":111 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":145 * return scores * * def __set__(self, scores): # <<<<<<<<<<<<<< @@ -6196,7 +7110,7 @@ static int __pyx_pw_5_cdec_9BaseTRule_6scores_3__set__(PyObject *__pyx_v_self, P * scores_.clear() */ -static int __pyx_pf_5_cdec_9BaseTRule_6scores_2__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_scores) { +static int __pyx_pf_5_cdec_5TRule_6scores_2__set__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self, PyObject *__pyx_v_scores) { FastSparseVector *__pyx_v_scores_; int __pyx_v_fid; float __pyx_v_fval; @@ -6218,7 +7132,7 @@ static int __pyx_pf_5_cdec_9BaseTRule_6scores_2__set__(struct __pyx_obj_5_cdec_B int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":112 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":146 * * def __set__(self, scores): * cdef FastSparseVector[double]* scores_ = &self.rule.get().scores_ # <<<<<<<<<<<<<< @@ -6227,7 +7141,7 @@ static int __pyx_pf_5_cdec_9BaseTRule_6scores_2__set__(struct __pyx_obj_5_cdec_B */ __pyx_v_scores_ = (&__pyx_v_self->rule->get()->scores_); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":113 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":147 * def __set__(self, scores): * cdef FastSparseVector[double]* scores_ = &self.rule.get().scores_ * scores_.clear() # <<<<<<<<<<<<<< @@ -6236,23 +7150,23 @@ static int __pyx_pf_5_cdec_9BaseTRule_6scores_2__set__(struct __pyx_obj_5_cdec_B */ __pyx_v_scores_->clear(); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":116 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":150 * cdef int fid * cdef float fval * for fname, fval in scores.items(): # <<<<<<<<<<<<<< * fid = FDConvert(as_str(fname)) * if fid < 0: raise KeyError(fname) */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_scores, __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(__pyx_v_scores, __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) { __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0; __pyx_t_4 = NULL; } else { - __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; } @@ -6260,16 +7174,24 @@ static int __pyx_pf_5_cdec_9BaseTRule_6scores_2__set__(struct __pyx_obj_5_cdec_B for (;;) { if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_1)) { if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_1)) { if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else { __pyx_t_2 = __pyx_t_4(__pyx_t_1); if (unlikely(!__pyx_t_2)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } @@ -6277,29 +7199,35 @@ static int __pyx_pf_5_cdec_9BaseTRule_6scores_2__set__(struct __pyx_obj_5_cdec_B } if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { PyObject* sequence = __pyx_t_2; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON if (likely(PyTuple_CheckExact(sequence))) { - 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[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); } else { - 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[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } __pyx_t_5 = PyList_GET_ITEM(sequence, 0); __pyx_t_6 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(__pyx_t_6); + #else + __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else { + } else + { Py_ssize_t index = -1; - __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; @@ -6307,24 +7235,25 @@ static int __pyx_pf_5_cdec_9BaseTRule_6scores_2__set__(struct __pyx_obj_5_cdec_B __Pyx_GOTREF(__pyx_t_5); index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed; __Pyx_GOTREF(__pyx_t_6); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = NULL; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; goto __pyx_L6_unpacking_done; __pyx_L5_unpacking_failed:; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L6_unpacking_done:; } - __pyx_t_9 = __pyx_PyFloat_AsFloat(__pyx_t_6); if (unlikely((__pyx_t_9 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = __pyx_PyFloat_AsFloat(__pyx_t_6); if (unlikely((__pyx_t_9 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF(__pyx_v_fname); __pyx_v_fname = __pyx_t_5; __pyx_t_5 = 0; __pyx_v_fval = __pyx_t_9; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":117 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":151 * cdef float fval * for fname, fval in scores.items(): * fid = FDConvert(as_str(fname)) # <<<<<<<<<<<<<< @@ -6333,7 +7262,7 @@ static int __pyx_pf_5_cdec_9BaseTRule_6scores_2__set__(struct __pyx_obj_5_cdec_B */ __pyx_v_fid = FD::Convert(((char *)__pyx_f_5_cdec_as_str(__pyx_v_fname, NULL))); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":118 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":152 * for fname, fval in scores.items(): * fid = FDConvert(as_str(fname)) * if fid < 0: raise KeyError(fname) # <<<<<<<<<<<<<< @@ -6342,22 +7271,22 @@ static int __pyx_pf_5_cdec_9BaseTRule_6scores_2__set__(struct __pyx_obj_5_cdec_B */ __pyx_t_10 = (__pyx_v_fid < 0); if (__pyx_t_10) { - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v_fname); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_fname); __Pyx_GIVEREF(__pyx_v_fname); - __pyx_t_6 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_6, 0, 0, 0); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L7; } __pyx_L7:; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":119 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":153 * fid = FDConvert(as_str(fname)) * if fid < 0: raise KeyError(fname) * scores_.set_value(fid, fval) # <<<<<<<<<<<<<< @@ -6376,7 +7305,7 @@ static int __pyx_pf_5_cdec_9BaseTRule_6scores_2__set__(struct __pyx_obj_5_cdec_B __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("_cdec.BaseTRule.scores.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.TRule.scores.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_XDECREF(__pyx_v_fname); @@ -6385,17 +7314,17 @@ static int __pyx_pf_5_cdec_9BaseTRule_6scores_2__set__(struct __pyx_obj_5_cdec_B } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_9BaseTRule_3lhs_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_9BaseTRule_3lhs_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_5TRule_3lhs_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_5TRule_3lhs_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9BaseTRule_3lhs___get__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_5TRule_3lhs___get__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":122 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":156 * * property lhs: * def __get__(self): # <<<<<<<<<<<<<< @@ -6403,7 +7332,7 @@ static PyObject *__pyx_pw_5_cdec_9BaseTRule_3lhs_1__get__(PyObject *__pyx_v_self * */ -static PyObject *__pyx_pf_5_cdec_9BaseTRule_3lhs___get__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_5TRule_3lhs___get__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -6413,7 +7342,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_3lhs___get__(struct __pyx_obj_5_cdec int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":123 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":157 * property lhs: * def __get__(self): * return NT(TDConvert(-self.rule.get().lhs_)) # <<<<<<<<<<<<<< @@ -6421,14 +7350,14 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_3lhs___get__(struct __pyx_obj_5_cdec * def __set__(self, lhs): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_self->rule->get()->lhs_))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(TD::Convert((-__pyx_v_self->rule->get()->lhs_))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 157; __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[2]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NT)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NT)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; @@ -6440,7 +7369,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_3lhs___get__(struct __pyx_obj_5_cdec __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_cdec.BaseTRule.lhs.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.TRule.lhs.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -6449,17 +7378,17 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_3lhs___get__(struct __pyx_obj_5_cdec } /* Python wrapper */ -static int __pyx_pw_5_cdec_9BaseTRule_3lhs_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_lhs); /*proto*/ -static int __pyx_pw_5_cdec_9BaseTRule_3lhs_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_lhs) { +static int __pyx_pw_5_cdec_5TRule_3lhs_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_lhs); /*proto*/ +static int __pyx_pw_5_cdec_5TRule_3lhs_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_lhs) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9BaseTRule_3lhs_2__set__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self), ((PyObject *)__pyx_v_lhs)); + __pyx_r = __pyx_pf_5_cdec_5TRule_3lhs_2__set__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self), ((PyObject *)__pyx_v_lhs)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":125 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":159 * return NT(TDConvert(-self.rule.get().lhs_)) * * def __set__(self, lhs): # <<<<<<<<<<<<<< @@ -6467,7 +7396,7 @@ static int __pyx_pw_5_cdec_9BaseTRule_3lhs_3__set__(PyObject *__pyx_v_self, PyOb * lhs = NT(lhs) */ -static int __pyx_pf_5_cdec_9BaseTRule_3lhs_2__set__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self, PyObject *__pyx_v_lhs) { +static int __pyx_pf_5_cdec_5TRule_3lhs_2__set__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self, PyObject *__pyx_v_lhs) { int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -6481,7 +7410,7 @@ static int __pyx_pf_5_cdec_9BaseTRule_3lhs_2__set__(struct __pyx_obj_5_cdec_Base __Pyx_RefNannySetupContext("__set__", 0); __Pyx_INCREF(__pyx_v_lhs); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":126 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":160 * * def __set__(self, lhs): * if not isinstance(lhs, NT): # <<<<<<<<<<<<<< @@ -6495,19 +7424,19 @@ static int __pyx_pf_5_cdec_9BaseTRule_3lhs_2__set__(struct __pyx_obj_5_cdec_Base __pyx_t_3 = (!__pyx_t_2); if (__pyx_t_3) { - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":127 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":161 * def __set__(self, lhs): * if not isinstance(lhs, NT): * lhs = NT(lhs) # <<<<<<<<<<<<<< * self.rule.get().lhs_ = -TDConvert(lhs.cat) * */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_lhs); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_lhs); __Pyx_GIVEREF(__pyx_v_lhs); - __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NT)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NT)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_v_lhs); @@ -6517,16 +7446,16 @@ static int __pyx_pf_5_cdec_9BaseTRule_3lhs_2__set__(struct __pyx_obj_5_cdec_Base } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":128 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":162 * if not isinstance(lhs, NT): * lhs = NT(lhs) * self.rule.get().lhs_ = -TDConvert(lhs.cat) # <<<<<<<<<<<<<< * * def __str__(self): */ - __pyx_t_4 = PyObject_GetAttr(__pyx_v_lhs, __pyx_n_s__cat); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_GetAttr(__pyx_v_lhs, __pyx_n_s__cat); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyBytes_AsString(__pyx_t_4); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyBytes_AsString(__pyx_t_4); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_self->rule->get()->lhs_ = (-TD::Convert(((char *)__pyx_t_5))); @@ -6535,7 +7464,7 @@ static int __pyx_pf_5_cdec_9BaseTRule_3lhs_2__set__(struct __pyx_obj_5_cdec_Base __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec.BaseTRule.lhs.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.TRule.lhs.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_XDECREF(__pyx_v_lhs); @@ -6544,18 +7473,18 @@ static int __pyx_pf_5_cdec_9BaseTRule_3lhs_2__set__(struct __pyx_obj_5_cdec_Base } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_9BaseTRule_3__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_9BaseTRule_3__str__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_5TRule_5__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_5TRule_5__str__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_9BaseTRule_2__str__(((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_5TRule_4__str__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_9BaseTRule_7__str___2generator18(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5_cdec_5TRule_7__str___2generator18(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":131 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":165 * * def __str__(self): * scores = ' '.join('%s=%s' % feat for feat in self.scores) # <<<<<<<<<<<<<< @@ -6563,7 +7492,7 @@ static PyObject *__pyx_gb_5_cdec_9BaseTRule_7__str___2generator18(__pyx_Generato * _phrase(self.f), _phrase(self.e), scores) */ -static PyObject *__pyx_pf_5_cdec_9BaseTRule_7__str___genexpr(PyObject *__pyx_self) { +static PyObject *__pyx_pf_5_cdec_5TRule_7__str___genexpr(PyObject *__pyx_self) { struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -6581,7 +7510,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_7__str___genexpr(PyObject *__pyx_sel __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_9BaseTRule_7__str___2generator18, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_5TRule_7__str___2generator18, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -6590,7 +7519,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_7__str___genexpr(PyObject *__pyx_sel __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.BaseTRule.__str__.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.TRule.__str__.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); @@ -6599,7 +7528,7 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_7__str___genexpr(PyObject *__pyx_sel return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_9BaseTRule_7__str___2generator18(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_5TRule_7__str___2generator18(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr *)__pyx_generator->closure); PyObject *__pyx_r = NULL; @@ -6617,15 +7546,15 @@ static PyObject *__pyx_gb_5_cdec_9BaseTRule_7__str___2generator18(__pyx_Generato return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self), __pyx_n_s__scores); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self)) { __Pyx_RaiseClosureNameError("self"); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_self), __pyx_n_s__scores); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; __pyx_t_4 = NULL; } else { - __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; } @@ -6633,16 +7562,24 @@ static PyObject *__pyx_gb_5_cdec_9BaseTRule_7__str___2generator18(__pyx_Generato for (;;) { if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_2)) { if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_2)) { if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else { __pyx_t_1 = __pyx_t_4(__pyx_t_2); if (unlikely(!__pyx_t_1)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } @@ -6653,7 +7590,7 @@ static PyObject *__pyx_gb_5_cdec_9BaseTRule_7__str___2generator18(__pyx_Generato __Pyx_GIVEREF(__pyx_t_1); __pyx_cur_scope->__pyx_v_feat = __pyx_t_1; __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), __pyx_cur_scope->__pyx_v_feat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), __pyx_cur_scope->__pyx_v_feat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; @@ -6672,7 +7609,7 @@ static PyObject *__pyx_gb_5_cdec_9BaseTRule_7__str___2generator18(__pyx_Generato __Pyx_XGOTREF(__pyx_t_2); __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; PyErr_SetNone(PyExc_StopIteration); @@ -6684,11 +7621,12 @@ static PyObject *__pyx_gb_5_cdec_9BaseTRule_7__str___2generator18(__pyx_Generato __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":130 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":164 * self.rule.get().lhs_ = -TDConvert(lhs.cat) * * def __str__(self): # <<<<<<<<<<<<<< @@ -6696,7 +7634,7 @@ static PyObject *__pyx_gb_5_cdec_9BaseTRule_7__str___2generator18(__pyx_Generato * return '%s ||| %s ||| %s ||| %s' % (self.lhs, */ -static PyObject *__pyx_pf_5_cdec_9BaseTRule_2__str__(struct __pyx_obj_5_cdec_BaseTRule *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_5TRule_4__str__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self) { struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ *__pyx_cur_scope; PyObject *__pyx_v_scores = NULL; PyObject *__pyx_r = NULL; @@ -6720,301 +7658,108 @@ static PyObject *__pyx_pf_5_cdec_9BaseTRule_2__str__(struct __pyx_obj_5_cdec_Bas __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":131 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":165 * * def __str__(self): * scores = ' '.join('%s=%s' % feat for feat in self.scores) # <<<<<<<<<<<<<< * return '%s ||| %s ||| %s ||| %s' % (self.lhs, * _phrase(self.f), _phrase(self.e), scores) */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_7), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_7), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __pyx_pf_5_cdec_9BaseTRule_7__str___genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __pyx_pf_5_cdec_5TRule_7__str___genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_v_scores = __pyx_t_2; __pyx_t_2 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":132 - * def __str__(self): - * scores = ' '.join('%s=%s' % feat for feat in self.scores) - * return '%s ||| %s ||| %s ||| %s' % (self.lhs, # <<<<<<<<<<<<<< - * _phrase(self.f), _phrase(self.e), scores) - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s__lhs); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":133 - * scores = ' '.join('%s=%s' % feat for feat in self.scores) - * return '%s ||| %s ||| %s ||| %s' % (self.lhs, - * _phrase(self.f), _phrase(self.e), scores) # <<<<<<<<<<<<<< - * - * cdef class TRule(BaseTRule): - */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s___phrase); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s__f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___phrase); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s__e); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_scores); - PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_v_scores); - __Pyx_GIVEREF(__pyx_v_scores); - __pyx_t_2 = 0; - __pyx_t_1 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_12), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_r = ((PyObject *)__pyx_t_3); - __pyx_t_3 = 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_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("_cdec.BaseTRule.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_scores); - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_5_cdec_5TRule_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5_cdec_5TRule_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_lhs = 0; - PyObject *__pyx_v_f = 0; - PyObject *__pyx_v_e = 0; - PyObject *__pyx_v_scores = 0; - PyObject *__pyx_v_a = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__lhs,&__pyx_n_s__f,&__pyx_n_s__e,&__pyx_n_s__scores,&__pyx_n_s__a,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[5] = {0,0,0,0,0}; - - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":136 - * - * cdef class TRule(BaseTRule): - * def __cinit__(self, lhs, f, e, scores, a=None): # <<<<<<<<<<<<<< - * self.rule = new shared_ptr[grammar.TRule](new grammar.TRule()) - * self.lhs = lhs - */ - values[4] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__lhs); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__f); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__e); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, 2); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__scores); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, 3); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__a); - if (value) { values[4] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_lhs = values[0]; - __pyx_v_f = values[1]; - __pyx_v_e = values[2]; - __pyx_v_scores = values[3]; - __pyx_v_a = values[4]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.TRule.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_5TRule___cinit__(((struct __pyx_obj_5_cdec_TRule *)__pyx_v_self), __pyx_v_lhs, __pyx_v_f, __pyx_v_e, __pyx_v_scores, __pyx_v_a); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_5_cdec_5TRule___cinit__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self, PyObject *__pyx_v_lhs, PyObject *__pyx_v_f, PyObject *__pyx_v_e, PyObject *__pyx_v_scores, PyObject *__pyx_v_a) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":137 - * cdef class TRule(BaseTRule): - * def __cinit__(self, lhs, f, e, scores, a=None): - * self.rule = new shared_ptr[grammar.TRule](new grammar.TRule()) # <<<<<<<<<<<<<< - * self.lhs = lhs - * self.e = e - */ - __pyx_v_self->__pyx_base.rule = new boost::shared_ptr(new TRule()); - - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":138 - * def __cinit__(self, lhs, f, e, scores, a=None): - * self.rule = new shared_ptr[grammar.TRule](new grammar.TRule()) - * self.lhs = lhs # <<<<<<<<<<<<<< - * self.e = e - * self.f = f - */ - if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__lhs, __pyx_v_lhs) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":139 - * self.rule = new shared_ptr[grammar.TRule](new grammar.TRule()) - * self.lhs = lhs - * self.e = e # <<<<<<<<<<<<<< - * self.f = f - * self.scores = scores - */ - if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__e, __pyx_v_e) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":140 - * self.lhs = lhs - * self.e = e - * self.f = f # <<<<<<<<<<<<<< - * self.scores = scores - * if a: - */ - if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__f, __pyx_v_f) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":141 - * self.e = e - * self.f = f - * self.scores = scores # <<<<<<<<<<<<<< - * if a: - * self.a = a - */ - if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__scores, __pyx_v_scores) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":142 - * self.f = f - * self.scores = scores - * if a: # <<<<<<<<<<<<<< - * self.a = a - * self.rule.get().ComputeArity() - */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_a); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":143 - * self.scores = scores - * if a: - * self.a = a # <<<<<<<<<<<<<< - * self.rule.get().ComputeArity() + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":166 + * def __str__(self): + * scores = ' '.join('%s=%s' % feat for feat in self.scores) + * return '%s ||| %s ||| %s ||| %s' % (self.lhs, # <<<<<<<<<<<<<< + * _phrase(self.f), _phrase(self.e), scores) * */ - if (PyObject_SetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__a, __pyx_v_a) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s__lhs); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":144 - * if a: - * self.a = a - * self.rule.get().ComputeArity() # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":167 + * scores = ' '.join('%s=%s' % feat for feat in self.scores) + * return '%s ||| %s ||| %s ||| %s' % (self.lhs, + * _phrase(self.f), _phrase(self.e), scores) # <<<<<<<<<<<<<< * * cdef class Grammar: */ - __pyx_v_self->__pyx_base.rule->get()->ComputeArity(); + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s___phrase); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s__f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___phrase); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s__e); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_scores); + PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_v_scores); + __Pyx_GIVEREF(__pyx_v_scores); + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_12), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_r = ((PyObject *)__pyx_t_3); + __pyx_t_3 = 0; + goto __pyx_L0; - __pyx_r = 0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.TRule.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_cdec.TRule.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_scores); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } @@ -7028,7 +7773,7 @@ static void __pyx_pw_5_cdec_7Grammar_1__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyFinishContext(); } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":149 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":172 * cdef shared_ptr[grammar.Grammar]* grammar * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -7040,7 +7785,7 @@ static void __pyx_pf_5_cdec_7Grammar___dealloc__(CYTHON_UNUSED struct __pyx_obj_ __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":150 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":173 * * def __dealloc__(self): * del self.grammar # <<<<<<<<<<<<<< @@ -7064,12 +7809,12 @@ static PyObject *__pyx_pw_5_cdec_7Grammar_3__iter__(PyObject *__pyx_v_self) { return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":152 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":175 * del self.grammar * * def __iter__(self): # <<<<<<<<<<<<<< - * cdef grammar.GrammarIter* root = self.grammar.get().GetRoot() - * cdef grammar.RuleBin* rbin = root.GetRules() + * cdef grammar.const_GrammarIter* root = self.grammar.get().GetRoot() + * cdef grammar.const_RuleBin* rbin = root.GetRules() */ static PyObject *__pyx_pf_5_cdec_7Grammar_2__iter__(struct __pyx_obj_5_cdec_Grammar *__pyx_v_self) { @@ -7090,7 +7835,7 @@ static PyObject *__pyx_pf_5_cdec_7Grammar_2__iter__(struct __pyx_obj_5_cdec_Gram __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Grammar_4generator3, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Grammar_4generator3, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -7125,63 +7870,64 @@ static PyObject *__pyx_gb_5_cdec_7Grammar_4generator3(__pyx_GeneratorObject *__p return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":153 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":176 * * def __iter__(self): - * cdef grammar.GrammarIter* root = self.grammar.get().GetRoot() # <<<<<<<<<<<<<< - * cdef grammar.RuleBin* rbin = root.GetRules() + * cdef grammar.const_GrammarIter* root = self.grammar.get().GetRoot() # <<<<<<<<<<<<<< + * cdef grammar.const_RuleBin* rbin = root.GetRules() * cdef TRule trule */ __pyx_cur_scope->__pyx_v_root = __pyx_cur_scope->__pyx_v_self->grammar->get()->GetRoot(); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":154 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":177 * def __iter__(self): - * cdef grammar.GrammarIter* root = self.grammar.get().GetRoot() - * cdef grammar.RuleBin* rbin = root.GetRules() # <<<<<<<<<<<<<< + * cdef grammar.const_GrammarIter* root = self.grammar.get().GetRoot() + * cdef grammar.const_RuleBin* rbin = root.GetRules() # <<<<<<<<<<<<<< * cdef TRule trule * cdef unsigned i */ __pyx_cur_scope->__pyx_v_rbin = __pyx_cur_scope->__pyx_v_root->GetRules(); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":157 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":180 * cdef TRule trule * cdef unsigned i * for i in range(rbin.GetNumRules()): # <<<<<<<<<<<<<< - * trule = TRule() + * trule = TRule.__new__(TRule) * trule.rule = new shared_ptr[grammar.TRule](rbin.GetIthRule(i)) */ __pyx_t_1 = __pyx_cur_scope->__pyx_v_rbin->GetNumRules(); for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":158 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":181 * cdef unsigned i * for i in range(rbin.GetNumRules()): - * trule = TRule() # <<<<<<<<<<<<<< + * trule = TRule.__new__(TRule) # <<<<<<<<<<<<<< * trule.rule = new shared_ptr[grammar.TRule](rbin.GetIthRule(i)) * yield trule */ - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_TRule)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5_cdec_TRule)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); + if (!(likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5_cdec_TRule)))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_trule)); __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_trule)); __Pyx_GIVEREF(__pyx_t_3); __pyx_cur_scope->__pyx_v_trule = ((struct __pyx_obj_5_cdec_TRule *)__pyx_t_3); __pyx_t_3 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":159 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":182 * for i in range(rbin.GetNumRules()): - * trule = TRule() + * trule = TRule.__new__(TRule) * trule.rule = new shared_ptr[grammar.TRule](rbin.GetIthRule(i)) # <<<<<<<<<<<<<< * yield trule * */ - __pyx_cur_scope->__pyx_v_trule->__pyx_base.rule = new boost::shared_ptr(__pyx_cur_scope->__pyx_v_rbin->GetIthRule(__pyx_cur_scope->__pyx_v_i)); + __pyx_cur_scope->__pyx_v_trule->rule = new boost::shared_ptr(__pyx_cur_scope->__pyx_v_rbin->GetIthRule(__pyx_cur_scope->__pyx_v_i)); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":160 - * trule = TRule() + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":183 + * trule = TRule.__new__(TRule) * trule.rule = new shared_ptr[grammar.TRule](rbin.GetIthRule(i)) * yield trule # <<<<<<<<<<<<<< * @@ -7199,7 +7945,7 @@ static PyObject *__pyx_gb_5_cdec_7Grammar_4generator3(__pyx_GeneratorObject *__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[2]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; @@ -7209,6 +7955,7 @@ static PyObject *__pyx_gb_5_cdec_7Grammar_4generator3(__pyx_GeneratorObject *__p __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } @@ -7224,7 +7971,7 @@ static PyObject *__pyx_pw_5_cdec_7Grammar_4name_1__get__(PyObject *__pyx_v_self) return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":163 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":186 * * property name: * def __get__(self): # <<<<<<<<<<<<<< @@ -7237,7 +7984,7 @@ static PyObject *__pyx_pf_5_cdec_7Grammar_4name___get__(struct __pyx_obj_5_cdec_ __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":164 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":187 * property name: * def __get__(self): * self.grammar.get().GetGrammarName().c_str() # <<<<<<<<<<<<<< @@ -7263,7 +8010,7 @@ static int __pyx_pw_5_cdec_7Grammar_4name_3__set__(PyObject *__pyx_v_self, PyObj return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":166 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":189 * self.grammar.get().GetGrammarName().c_str() * * def __set__(self, name): # <<<<<<<<<<<<<< @@ -7280,14 +8027,14 @@ static int __pyx_pf_5_cdec_7Grammar_4name_2__set__(struct __pyx_obj_5_cdec_Gramm int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":167 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":190 * * def __set__(self, name): * self.grammar.get().SetGrammarName(string(name)) # <<<<<<<<<<<<<< * * cdef class TextGrammar(Grammar): */ - __pyx_t_1 = PyBytes_AsString(__pyx_v_name); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_AsString(__pyx_v_name); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->grammar->get()->SetGrammarName(std::string(((char *)__pyx_t_1))); __pyx_r = 0; @@ -7304,11 +8051,11 @@ static int __pyx_pf_5_cdec_7Grammar_4name_2__set__(struct __pyx_obj_5_cdec_Gramm static int __pyx_pw_5_cdec_11TextGrammar_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_5_cdec_11TextGrammar_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_rules = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__rules,0}; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__rules,0}; PyObject* values[1] = {0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; @@ -7321,12 +8068,11 @@ static int __pyx_pw_5_cdec_11TextGrammar_1__cinit__(PyObject *__pyx_v_self, PyOb kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__rules); - if (likely(values[0])) kw_args--; + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__rules)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; @@ -7337,7 +8083,7 @@ static int __pyx_pw_5_cdec_11TextGrammar_1__cinit__(PyObject *__pyx_v_self, PyOb } 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[2]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.TextGrammar.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -7348,7 +8094,7 @@ static int __pyx_pw_5_cdec_11TextGrammar_1__cinit__(PyObject *__pyx_v_self, PyOb return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":170 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":193 * * cdef class TextGrammar(Grammar): * def __cinit__(self, rules): # <<<<<<<<<<<<<< @@ -7366,13 +8112,14 @@ static int __pyx_pf_5_cdec_11TextGrammar___cinit__(struct __pyx_obj_5_cdec_TextG PyObject *(*__pyx_t_3)(PyObject *); PyObject *__pyx_t_4 = NULL; int __pyx_t_5; - int __pyx_t_6; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":171 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":194 * cdef class TextGrammar(Grammar): * def __cinit__(self, rules): * self.grammar = new shared_ptr[grammar.Grammar](new grammar.TextGrammar()) # <<<<<<<<<<<<<< @@ -7381,43 +8128,51 @@ static int __pyx_pf_5_cdec_11TextGrammar___cinit__(struct __pyx_obj_5_cdec_TextG */ __pyx_v_self->__pyx_base.grammar = new boost::shared_ptr(new TextGrammar()); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":172 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":195 * def __cinit__(self, rules): * self.grammar = new shared_ptr[grammar.Grammar](new grammar.TextGrammar()) * cdef grammar.TextGrammar* _g = self.grammar.get() # <<<<<<<<<<<<<< * for trule in rules: - * if not isinstance(trule, BaseTRule): + * if isinstance(trule, _sa.Rule): */ __pyx_v__g = ((TextGrammar *)__pyx_v_self->__pyx_base.grammar->get()); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":173 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":196 * self.grammar = new shared_ptr[grammar.Grammar](new grammar.TextGrammar()) * cdef grammar.TextGrammar* _g = self.grammar.get() * for trule in rules: # <<<<<<<<<<<<<< - * if not isinstance(trule, BaseTRule): - * raise ValueError('the grammar should contain TRule objects') + * if isinstance(trule, _sa.Rule): + * trule = convert_rule(trule) */ if (PyList_CheckExact(__pyx_v_rules) || PyTuple_CheckExact(__pyx_v_rules)) { __pyx_t_1 = __pyx_v_rules; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; __pyx_t_3 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_rules); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_rules); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; } for (;;) { if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else { __pyx_t_4 = __pyx_t_3(__pyx_t_1); if (unlikely(!__pyx_t_4)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } @@ -7427,41 +8182,73 @@ static int __pyx_pf_5_cdec_11TextGrammar___cinit__(struct __pyx_obj_5_cdec_TextG __pyx_v_trule = __pyx_t_4; __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":174 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":197 * cdef grammar.TextGrammar* _g = self.grammar.get() * for trule in rules: - * if not isinstance(trule, BaseTRule): # <<<<<<<<<<<<<< - * raise ValueError('the grammar should contain TRule objects') - * _g.AddRule(( trule).rule[0]) + * if isinstance(trule, _sa.Rule): # <<<<<<<<<<<<<< + * trule = convert_rule(trule) + * elif not isinstance(trule, TRule): */ - __pyx_t_4 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_BaseTRule)); + __pyx_t_4 = ((PyObject *)((PyObject*)__pyx_ptype_4cdec_2sa_3_sa_Rule)); __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = __Pyx_TypeCheck(__pyx_v_trule, __pyx_t_4); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_6 = (!__pyx_t_5); - if (__pyx_t_6) { + if (__pyx_t_5) { - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":175 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":198 * for trule in rules: - * if not isinstance(trule, BaseTRule): - * raise ValueError('the grammar should contain TRule objects') # <<<<<<<<<<<<<< - * _g.AddRule(( trule).rule[0]) + * if isinstance(trule, _sa.Rule): + * trule = convert_rule(trule) # <<<<<<<<<<<<<< + * elif not isinstance(trule, TRule): + * raise ValueError('the grammar should contain TRule objects') */ - __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_14), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); + if (!(likely(((__pyx_v_trule) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_trule, __pyx_ptype_4cdec_2sa_3_sa_Rule))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __pyx_v_trule; + __Pyx_INCREF(__pyx_t_4); + __pyx_t_6 = ((PyObject *)__pyx_f_5_cdec_convert_rule(((struct __pyx_obj_4cdec_2sa_3_sa_Rule *)__pyx_t_4))); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_v_trule); + __pyx_v_trule = __pyx_t_6; + __pyx_t_6 = 0; + goto __pyx_L5; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":199 + * if isinstance(trule, _sa.Rule): + * trule = convert_rule(trule) + * elif not isinstance(trule, TRule): # <<<<<<<<<<<<<< + * raise ValueError('the grammar should contain TRule objects') + * _g.AddRule(( trule).rule[0]) + */ + __pyx_t_6 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_TRule)); + __Pyx_INCREF(__pyx_t_6); + __pyx_t_5 = __Pyx_TypeCheck(__pyx_v_trule, __pyx_t_6); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_7 = (!__pyx_t_5); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":200 + * trule = convert_rule(trule) + * elif not isinstance(trule, TRule): + * raise ValueError('the grammar should contain TRule objects') # <<<<<<<<<<<<<< + * _g.AddRule(( trule).rule[0]) + */ + __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_14), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_Raise(__pyx_t_6, 0, 0, 0); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L5; } __pyx_L5:; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":176 - * if not isinstance(trule, BaseTRule): + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":201 + * elif not isinstance(trule, TRule): * raise ValueError('the grammar should contain TRule objects') - * _g.AddRule(( trule).rule[0]) # <<<<<<<<<<<<<< + * _g.AddRule(( trule).rule[0]) # <<<<<<<<<<<<<< */ - __pyx_v__g->AddRule((((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_trule)->rule[0])); + __pyx_v__g->AddRule((((struct __pyx_obj_5_cdec_TRule *)__pyx_v_trule)->rule[0])); } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -7470,6 +8257,7 @@ static int __pyx_pf_5_cdec_11TextGrammar___cinit__(struct __pyx_obj_5_cdec_TextG __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("_cdec.TextGrammar.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; @@ -7738,7 +8526,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_7viterbi_features(PyObject *__pyx_ * return (f_tree, e_tree) * * def viterbi_features(self): # <<<<<<<<<<<<<< - * cdef SparseVector fmap = SparseVector() + * cdef SparseVector fmap = SparseVector.__new__(SparseVector) * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) */ @@ -7755,18 +8543,19 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_6viterbi_features(struct __pyx_obj /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":24 * * def viterbi_features(self): - * cdef SparseVector fmap = SparseVector() # <<<<<<<<<<<<<< + * cdef SparseVector fmap = SparseVector.__new__(SparseVector) # <<<<<<<<<<<<<< * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) * return fmap */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5_cdec_SparseVector)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); + if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5_cdec_SparseVector)))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":25 * def viterbi_features(self): - * cdef SparseVector fmap = SparseVector() + * cdef SparseVector fmap = SparseVector.__new__(SparseVector) * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) # <<<<<<<<<<<<<< * return fmap * @@ -7774,7 +8563,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_6viterbi_features(struct __pyx_obj __pyx_v_fmap->vector = new FastSparseVector(ViterbiFeatures((__pyx_v_self->hg[0]))); /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":26 - * cdef SparseVector fmap = SparseVector() + * cdef SparseVector fmap = SparseVector.__new__(SparseVector) * fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) * return fmap # <<<<<<<<<<<<<< * @@ -8078,6 +8867,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_12generator4(__pyx_GeneratorObject __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } @@ -8378,6 +9168,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator5(__pyx_GeneratorObject __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } @@ -8496,7 +9287,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator6(__pyx_GeneratorObject * for k in range(size): * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< * if not derivation: break - * fmap = SparseVector() + * fmap = SparseVector.__new__(SparseVector) */ __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); @@ -8504,7 +9295,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator6(__pyx_GeneratorObject * for k in range(size): * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) * if not derivation: break # <<<<<<<<<<<<<< - * fmap = SparseVector() + * fmap = SparseVector.__new__(SparseVector) * fmap.vector = new FastSparseVector[weight_t](derivation._yield) */ __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0)); @@ -8517,12 +9308,13 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator6(__pyx_GeneratorObject /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":70 * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) * if not derivation: break - * fmap = SparseVector() # <<<<<<<<<<<<<< + * fmap = SparseVector.__new__(SparseVector) # <<<<<<<<<<<<<< * fmap.vector = new FastSparseVector[weight_t](derivation._yield) * yield fmap */ - __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L5;} + __pyx_t_4 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5_cdec_SparseVector)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L5;} __Pyx_GOTREF(__pyx_t_4); + if (!(likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5_cdec_SparseVector)))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L5;} __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); __Pyx_GIVEREF(__pyx_t_4); @@ -8531,7 +9323,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator6(__pyx_GeneratorObject /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":71 * if not derivation: break - * fmap = SparseVector() + * fmap = SparseVector.__new__(SparseVector) * fmap.vector = new FastSparseVector[weight_t](derivation._yield) # <<<<<<<<<<<<<< * yield fmap * finally: @@ -8539,7 +9331,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator6(__pyx_GeneratorObject __pyx_cur_scope->__pyx_v_fmap->vector = new FastSparseVector(__pyx_cur_scope->__pyx_v_derivation->yield); /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":72 - * fmap = SparseVector() + * fmap = SparseVector.__new__(SparseVector) * fmap.vector = new FastSparseVector[weight_t](derivation._yield) * yield fmap # <<<<<<<<<<<<<< * finally: @@ -8603,6 +9395,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator6(__pyx_GeneratorObject __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } @@ -8679,10 +9472,11 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator7(__pyx_GeneratorObject struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample *)__pyx_generator->closure); PyObject *__pyx_r = NULL; int __pyx_t_1; - size_t __pyx_t_2; - unsigned int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; + MT19937 *__pyx_t_2; + size_t __pyx_t_3; + unsigned int __pyx_t_4; PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { @@ -8721,7 +9515,8 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator7(__pyx_GeneratorObject * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) * cdef unsigned k */ - __pyx_cur_scope->__pyx_v_self->rng = new MT19937(); + try {__pyx_t_2 = new MT19937();} catch(...) {__Pyx_CppExn2PyErr(); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}} + __pyx_cur_scope->__pyx_v_self->rng = __pyx_t_2; goto __pyx_L4; } __pyx_L4:; @@ -8751,9 +9546,9 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator7(__pyx_GeneratorObject * yield unicode(GetString(hypos[0][k].words).c_str(), 'utf8') * finally: */ - __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; + __pyx_t_3 = __pyx_cur_scope->__pyx_v_hypos->size(); + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_cur_scope->__pyx_v_k = __pyx_t_4; /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":84 * try: @@ -8762,31 +9557,31 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator7(__pyx_GeneratorObject * finally: * 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[3]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_4)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __pyx_t_5 = PyBytes_FromString(TD::GetString(((__pyx_cur_scope->__pyx_v_hypos[0])[__pyx_cur_scope->__pyx_v_k]).words).c_str()); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_4; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); /* return from generator, yielding value */ __pyx_generator->resume_label = 1; return __pyx_r; __pyx_L10_resume_from_yield:; - __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_1; if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} } } @@ -8806,8 +9601,8 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator7(__pyx_GeneratorObject __pyx_why = 0; goto __pyx_L7; __pyx_L6: { __pyx_why = 4; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); __pyx_exc_lineno = __pyx_lineno; goto __pyx_L7; @@ -8828,12 +9623,13 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator7(__pyx_GeneratorObject PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("sample", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } @@ -8903,13 +9699,13 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_25prune(PyObject *__pyx_v_self, Py PyObject *__pyx_v_beam_alpha = 0; PyObject *__pyx_v_density = 0; PyObject *__pyx_v_kwargs = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__beam_alpha,&__pyx_n_s__density,0}; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("prune (wrapper)", 0); __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL; __Pyx_GOTREF(__pyx_v_kwargs); { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__beam_alpha,&__pyx_n_s__density,0}; PyObject* values[2] = {0,0}; values[0] = ((PyObject *)__pyx_int_0); values[1] = ((PyObject *)__pyx_int_0); @@ -9408,6 +10204,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_5edges_2generator8(__pyx_Generator __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } @@ -9534,6 +10331,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_5nodes_2generator9(__pyx_Generator __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } @@ -9666,15 +10464,15 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_31inside_outside(PyObject *__pyx_v * return self.hg.NumberOfPaths() * * def inside_outside(self): # <<<<<<<<<<<<<< - * cdef FastSparseVector[LogVal[double]]* result = new FastSparseVector[LogVal[double]]() - * cdef LogVal[double] z = hypergraph.InsideOutside(self.hg[0], result) + * cdef FastSparseVector[prob_t]* result = new FastSparseVector[prob_t]() + * cdef prob_t z = hypergraph.InsideOutside(self.hg[0], result) */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_30inside_outside(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { - FastSparseVector > *__pyx_v_result; - LogVal __pyx_v_z; + FastSparseVector *__pyx_v_result; + prob_t __pyx_v_z; struct __pyx_obj_5_cdec_SparseVector *__pyx_v_vector = 0; - FastSparseVector >::const_iterator *__pyx_v_it; + FastSparseVector::const_iterator *__pyx_v_it; CYTHON_UNUSED unsigned int __pyx_v_i; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -9689,62 +10487,63 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_30inside_outside(struct __pyx_obj_ /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":133 * * def inside_outside(self): - * cdef FastSparseVector[LogVal[double]]* result = new FastSparseVector[LogVal[double]]() # <<<<<<<<<<<<<< - * cdef LogVal[double] z = hypergraph.InsideOutside(self.hg[0], result) + * cdef FastSparseVector[prob_t]* result = new FastSparseVector[prob_t]() # <<<<<<<<<<<<<< + * cdef prob_t z = hypergraph.InsideOutside(self.hg[0], result) * result[0] /= z */ - __pyx_v_result = new FastSparseVector >(); + __pyx_v_result = new FastSparseVector(); /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":134 * def inside_outside(self): - * cdef FastSparseVector[LogVal[double]]* result = new FastSparseVector[LogVal[double]]() - * cdef LogVal[double] z = hypergraph.InsideOutside(self.hg[0], result) # <<<<<<<<<<<<<< + * cdef FastSparseVector[prob_t]* result = new FastSparseVector[prob_t]() + * cdef prob_t z = hypergraph.InsideOutside(self.hg[0], result) # <<<<<<<<<<<<<< * result[0] /= z - * cdef SparseVector vector = SparseVector() + * cdef SparseVector vector = SparseVector.__new__(SparseVector) */ __pyx_v_z = InsideOutside, EdgeFeaturesAndProbWeightFunction>((__pyx_v_self->hg[0]), __pyx_v_result); /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":135 - * cdef FastSparseVector[LogVal[double]]* result = new FastSparseVector[LogVal[double]]() - * cdef LogVal[double] z = hypergraph.InsideOutside(self.hg[0], result) + * cdef FastSparseVector[prob_t]* result = new FastSparseVector[prob_t]() + * cdef prob_t z = hypergraph.InsideOutside(self.hg[0], result) * result[0] /= z # <<<<<<<<<<<<<< - * cdef SparseVector vector = SparseVector() + * cdef SparseVector vector = SparseVector.__new__(SparseVector) * vector.vector = new FastSparseVector[double]() */ (__pyx_v_result[0]) /= __pyx_v_z; /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":136 - * cdef LogVal[double] z = hypergraph.InsideOutside(self.hg[0], result) + * cdef prob_t z = hypergraph.InsideOutside(self.hg[0], result) * result[0] /= z - * cdef SparseVector vector = SparseVector() # <<<<<<<<<<<<<< + * cdef SparseVector vector = SparseVector.__new__(SparseVector) # <<<<<<<<<<<<<< * vector.vector = new FastSparseVector[double]() - * cdef FastSparseVector[LogVal[double]].const_iterator* it = new FastSparseVector[LogVal[double]].const_iterator(result[0], False) + * cdef FastSparseVector[prob_t].const_iterator* it = new FastSparseVector[prob_t].const_iterator(result[0], False) */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5_cdec_SparseVector)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); + if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5_cdec_SparseVector)))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":137 * result[0] /= z - * cdef SparseVector vector = SparseVector() + * cdef SparseVector vector = SparseVector.__new__(SparseVector) * vector.vector = new FastSparseVector[double]() # <<<<<<<<<<<<<< - * cdef FastSparseVector[LogVal[double]].const_iterator* it = new FastSparseVector[LogVal[double]].const_iterator(result[0], False) + * cdef FastSparseVector[prob_t].const_iterator* it = new FastSparseVector[prob_t].const_iterator(result[0], False) * cdef unsigned i */ __pyx_v_vector->vector = new FastSparseVector(); /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":138 - * cdef SparseVector vector = SparseVector() + * cdef SparseVector vector = SparseVector.__new__(SparseVector) * vector.vector = new FastSparseVector[double]() - * cdef FastSparseVector[LogVal[double]].const_iterator* it = new FastSparseVector[LogVal[double]].const_iterator(result[0], False) # <<<<<<<<<<<<<< + * cdef FastSparseVector[prob_t].const_iterator* it = new FastSparseVector[prob_t].const_iterator(result[0], False) # <<<<<<<<<<<<<< * cdef unsigned i * for i in range(result.size()): */ - __pyx_v_it = new FastSparseVector >::const_iterator((__pyx_v_result[0]), 0); + __pyx_v_it = new FastSparseVector::const_iterator((__pyx_v_result[0]), 0); /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":140 - * cdef FastSparseVector[LogVal[double]].const_iterator* it = new FastSparseVector[LogVal[double]].const_iterator(result[0], False) + * cdef FastSparseVector[prob_t].const_iterator* it = new FastSparseVector[prob_t].const_iterator(result[0], False) * cdef unsigned i * for i in range(result.size()): # <<<<<<<<<<<<<< * vector.vector.set_value(it[0].ptr().first, log(it[0].ptr().second)) @@ -9817,7 +10616,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_30inside_outside(struct __pyx_obj_ } /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":152 - * cdef public BaseTRule trule + * cdef public TRule trule * * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): # <<<<<<<<<<<<<< * self.hg = hg @@ -9838,7 +10637,7 @@ static PyObject *__pyx_f_5_cdec_14HypergraphEdge_init(struct __pyx_obj_5_cdec_Hy * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): * self.hg = hg # <<<<<<<<<<<<<< * self.edge = &hg.edges_[i] - * self.trule = BaseTRule() + * self.trule = TRule.__new__(TRule) */ __pyx_v_self->hg = __pyx_v_hg; @@ -9846,7 +10645,7 @@ static PyObject *__pyx_f_5_cdec_14HypergraphEdge_init(struct __pyx_obj_5_cdec_Hy * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): * self.hg = hg * self.edge = &hg.edges_[i] # <<<<<<<<<<<<<< - * self.trule = BaseTRule() + * self.trule = TRule.__new__(TRule) * self.trule.rule = new shared_ptr[grammar.TRule](self.edge.rule_) */ __pyx_v_self->edge = (&(__pyx_v_hg->edges_[__pyx_v_i])); @@ -9854,21 +10653,22 @@ static PyObject *__pyx_f_5_cdec_14HypergraphEdge_init(struct __pyx_obj_5_cdec_Hy /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":155 * self.hg = hg * self.edge = &hg.edges_[i] - * self.trule = BaseTRule() # <<<<<<<<<<<<<< + * self.trule = TRule.__new__(TRule) # <<<<<<<<<<<<<< * self.trule.rule = new shared_ptr[grammar.TRule](self.edge.rule_) * return self */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_BaseTRule)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5_cdec_TRule)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); + if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5_cdec_TRule)))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->trule); __Pyx_DECREF(((PyObject *)__pyx_v_self->trule)); - __pyx_v_self->trule = ((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_t_1); + __pyx_v_self->trule = ((struct __pyx_obj_5_cdec_TRule *)__pyx_t_1); __pyx_t_1 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":156 * self.edge = &hg.edges_[i] - * self.trule = BaseTRule() + * self.trule = TRule.__new__(TRule) * self.trule.rule = new shared_ptr[grammar.TRule](self.edge.rule_) # <<<<<<<<<<<<<< * return self * @@ -9876,7 +10676,7 @@ static PyObject *__pyx_f_5_cdec_14HypergraphEdge_init(struct __pyx_obj_5_cdec_Hy __pyx_v_self->trule->rule = new boost::shared_ptr(__pyx_v_self->edge->rule_); /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":157 - * self.trule = BaseTRule() + * self.trule = TRule.__new__(TRule) * self.trule.rule = new shared_ptr[grammar.TRule](self.edge.rule_) * return self # <<<<<<<<<<<<<< * @@ -10120,6 +10920,7 @@ static PyObject *__pyx_gb_5_cdec_14HypergraphEdge_10tail_nodes_2generator10(__py __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } @@ -10207,7 +11008,7 @@ static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_14feature_values_1__get__(PyOb * * property feature_values: * def __get__(self): # <<<<<<<<<<<<<< - * cdef SparseVector vector = SparseVector() + * cdef SparseVector vector = SparseVector.__new__(SparseVector) * vector.vector = new FastSparseVector[double](self.edge.feature_values_) */ @@ -10224,18 +11025,19 @@ static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_14feature_values___get__(struc /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":178 * property feature_values: * def __get__(self): - * cdef SparseVector vector = SparseVector() # <<<<<<<<<<<<<< + * cdef SparseVector vector = SparseVector.__new__(SparseVector) # <<<<<<<<<<<<<< * vector.vector = new FastSparseVector[double](self.edge.feature_values_) * return vector */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5_cdec_SparseVector)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); + if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5_cdec_SparseVector)))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":179 * def __get__(self): - * cdef SparseVector vector = SparseVector() + * cdef SparseVector vector = SparseVector.__new__(SparseVector) * vector.vector = new FastSparseVector[double](self.edge.feature_values_) # <<<<<<<<<<<<<< * return vector * @@ -10243,7 +11045,7 @@ static PyObject *__pyx_pf_5_cdec_14HypergraphEdge_14feature_values___get__(struc __pyx_v_vector->vector = new FastSparseVector(__pyx_v_self->edge->feature_values_); /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":180 - * cdef SparseVector vector = SparseVector() + * cdef SparseVector vector = SparseVector.__new__(SparseVector) * vector.vector = new FastSparseVector[double](self.edge.feature_values_) * return vector # <<<<<<<<<<<<<< * @@ -10457,7 +11259,7 @@ static PyObject *__pyx_pw_5_cdec_14HypergraphEdge_5trule_1__get__(PyObject *__py /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":150 * cdef hypergraph.Hypergraph* hg * cdef hypergraph.HypergraphEdge* edge - * cdef public BaseTRule trule # <<<<<<<<<<<<<< + * cdef public TRule trule # <<<<<<<<<<<<<< * * cdef init(self, hypergraph.Hypergraph* hg, unsigned i): */ @@ -10496,12 +11298,12 @@ static int __pyx_pf_5_cdec_14HypergraphEdge_5trule_2__set__(struct __pyx_obj_5_c const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - if (!(likely(((__pyx_v_value) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_value, __pyx_ptype_5_cdec_BaseTRule))))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_value) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_value, __pyx_ptype_5_cdec_TRule))))) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); __Pyx_GOTREF(__pyx_v_self->trule); __Pyx_DECREF(((PyObject *)__pyx_v_self->trule)); - __pyx_v_self->trule = ((struct __pyx_obj_5_cdec_BaseTRule *)__pyx_v_value); + __pyx_v_self->trule = ((struct __pyx_obj_5_cdec_TRule *)__pyx_v_value); __pyx_r = 0; goto __pyx_L0; @@ -10532,7 +11334,7 @@ static int __pyx_pf_5_cdec_14HypergraphEdge_5trule_4__del__(struct __pyx_obj_5_c __Pyx_GIVEREF(Py_None); __Pyx_GOTREF(__pyx_v_self->trule); __Pyx_DECREF(((PyObject *)__pyx_v_self->trule)); - __pyx_v_self->trule = ((struct __pyx_obj_5_cdec_BaseTRule *)Py_None); + __pyx_v_self->trule = ((struct __pyx_obj_5_cdec_TRule *)Py_None); __pyx_r = 0; __Pyx_RefNannyFinishContext(); @@ -10711,6 +11513,7 @@ static PyObject *__pyx_gb_5_cdec_14HypergraphNode_8in_edges_2generator11(__pyx_G __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } @@ -10837,6 +11640,7 @@ static PyObject *__pyx_gb_5_cdec_14HypergraphNode_9out_edges_2generator12(__pyx_ __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } @@ -11092,11 +11896,11 @@ static PyObject *__pyx_pf_5_cdec_14HypergraphNode___richcmp__(struct __pyx_obj_5 static int __pyx_pw_5_cdec_7Lattice_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_5_cdec_7Lattice_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_inp = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__inp,0}; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__inp,0}; PyObject* values[1] = {0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; @@ -11109,8 +11913,7 @@ static int __pyx_pw_5_cdec_7Lattice_1__cinit__(PyObject *__pyx_v_self, PyObject kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__inp); - if (likely(values[0])) kw_args--; + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__inp)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { @@ -11206,10 +12009,18 @@ static int __pyx_pf_5_cdec_7Lattice___cinit__(struct __pyx_obj_5_cdec_Lattice *_ for (;;) { if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_4)) { if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; + #else + __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_4)) { if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_3); __Pyx_INCREF(__pyx_t_6); __pyx_t_3++; + #else + __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else { __pyx_t_6 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_6)) { @@ -11332,7 +12143,7 @@ static int __pyx_pf_5_cdec_7Lattice___cinit__(struct __pyx_obj_5_cdec_Lattice *_ * self.lattice = new lattice.Lattice() * lattice.ConvertTextToLattice(string(inp), self.lattice) # <<<<<<<<<<<<<< * - * def __getitem__(self, int index): + * def __dealloc__(self): */ __pyx_t_8 = PyBytes_AsString(__pyx_v_inp); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} LatticeTools::ConvertTextToLattice(std::string(((char *)__pyx_t_8)), __pyx_v_self->lattice); @@ -11356,14 +12167,47 @@ static int __pyx_pf_5_cdec_7Lattice___cinit__(struct __pyx_obj_5_cdec_Lattice *_ } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Lattice_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Lattice_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index) { +static void __pyx_pw_5_cdec_7Lattice_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_7Lattice_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_7Lattice_2__dealloc__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":19 + * lattice.ConvertTextToLattice(string(inp), self.lattice) + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.lattice + * + */ + +static void __pyx_pf_5_cdec_7Lattice_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":20 + * + * def __dealloc__(self): + * del self.lattice # <<<<<<<<<<<<<< + * + * def __getitem__(self, int index): + */ + delete __pyx_v_self->lattice; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Lattice_5__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Lattice_5__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index) { int __pyx_v_index; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); assert(__pyx_arg_index); { - __pyx_v_index = __Pyx_PyInt_AsInt(__pyx_arg_index); if (unlikely((__pyx_v_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_index = __Pyx_PyInt_AsInt(__pyx_arg_index); if (unlikely((__pyx_v_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -11371,20 +12215,20 @@ static PyObject *__pyx_pw_5_cdec_7Lattice_3__getitem__(PyObject *__pyx_v_self, P __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_7Lattice_2__getitem__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), ((int)__pyx_v_index)); + __pyx_r = __pyx_pf_5_cdec_7Lattice_4__getitem__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), ((int)__pyx_v_index)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":19 - * lattice.ConvertTextToLattice(string(inp), self.lattice) +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":22 + * del self.lattice * * def __getitem__(self, int index): # <<<<<<<<<<<<<< * if not 0 <= index < len(self): * raise IndexError('lattice index out of range') */ -static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index) { +static PyObject *__pyx_pf_5_cdec_7Lattice_4__getitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index) { PyObject *__pyx_v_arcs = NULL; std::vector __pyx_v_arc_vector; LatticeArc *__pyx_v_arc; @@ -11406,7 +12250,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_L int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__getitem__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":20 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":23 * * def __getitem__(self, int index): * if not 0 <= index < len(self): # <<<<<<<<<<<<<< @@ -11415,41 +12259,41 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_L */ __pyx_t_1 = (0 <= __pyx_v_index); if (__pyx_t_1) { - __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = (__pyx_v_index < __pyx_t_2); } __pyx_t_3 = (!__pyx_t_1); if (__pyx_t_3) { - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":21 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":24 * def __getitem__(self, int index): * if not 0 <= index < len(self): * raise IndexError('lattice index out of range') # <<<<<<<<<<<<<< * arcs = [] * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] */ - __pyx_t_4 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":22 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":25 * if not 0 <= index < len(self): * raise IndexError('lattice index out of range') * arcs = [] # <<<<<<<<<<<<<< * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] * cdef lattice.LatticeArc* arc */ - __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_v_arcs = __pyx_t_4; __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":23 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":26 * raise IndexError('lattice index out of range') * arcs = [] * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] # <<<<<<<<<<<<<< @@ -11458,7 +12302,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_L */ __pyx_v_arc_vector = ((__pyx_v_self->lattice[0])[__pyx_v_index]); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":26 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":29 * cdef lattice.LatticeArc* arc * cdef unsigned i * for i in range(arc_vector.size()): # <<<<<<<<<<<<<< @@ -11469,7 +12313,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_L for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { __pyx_v_i = __pyx_t_6; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":27 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":30 * cdef unsigned i * for i in range(arc_vector.size()): * arc = &arc_vector[i] # <<<<<<<<<<<<<< @@ -11478,16 +12322,16 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_L */ __pyx_v_arc = (&(__pyx_v_arc_vector[__pyx_v_i])); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":28 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":31 * for i in range(arc_vector.size()): * arc = &arc_vector[i] * label = unicode(TDConvert(arc.label), 'utf8') # <<<<<<<<<<<<<< * arcs.append((label, arc.cost, arc.dist2next)) * return tuple(arcs) */ - __pyx_t_4 = PyBytes_FromString(TD::Convert(__pyx_v_arc->label)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyBytes_FromString(TD::Convert(__pyx_v_arc->label)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_4)); __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); @@ -11495,25 +12339,25 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_L PyTuple_SET_ITEM(__pyx_t_7, 1, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; __Pyx_XDECREF(((PyObject *)__pyx_v_label)); __pyx_v_label = ((PyObject*)__pyx_t_4); __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":29 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":32 * arc = &arc_vector[i] * label = unicode(TDConvert(arc.label), 'utf8') * arcs.append((label, arc.cost, arc.dist2next)) # <<<<<<<<<<<<<< * return tuple(arcs) * */ - __pyx_t_4 = PyFloat_FromDouble(__pyx_v_arc->cost); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyFloat_FromDouble(__pyx_v_arc->cost); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = PyInt_FromLong(__pyx_v_arc->dist2next); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PyInt_FromLong(__pyx_v_arc->dist2next); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_INCREF(((PyObject *)__pyx_v_label)); PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_v_label)); @@ -11524,11 +12368,11 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_L __Pyx_GIVEREF(__pyx_t_7); __pyx_t_4 = 0; __pyx_t_7 = 0; - __pyx_t_9 = PyList_Append(__pyx_v_arcs, ((PyObject *)__pyx_t_8)); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = PyList_Append(__pyx_v_arcs, ((PyObject *)__pyx_t_8)); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; } - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":30 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":33 * label = unicode(TDConvert(arc.label), 'utf8') * arcs.append((label, arc.cost, arc.dist2next)) * return tuple(arcs) # <<<<<<<<<<<<<< @@ -11536,7 +12380,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_L * def __setitem__(self, int index, tuple arcs): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_8 = ((PyObject *)PyList_AsTuple(__pyx_v_arcs)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = ((PyObject *)PyList_AsTuple(__pyx_v_arcs)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_8)); __pyx_r = ((PyObject *)__pyx_t_8); __pyx_t_8 = 0; @@ -11559,14 +12403,14 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_L } /* Python wrapper */ -static int __pyx_pw_5_cdec_7Lattice_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index, PyObject *__pyx_v_arcs); /*proto*/ -static int __pyx_pw_5_cdec_7Lattice_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index, PyObject *__pyx_v_arcs) { +static int __pyx_pw_5_cdec_7Lattice_7__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index, PyObject *__pyx_v_arcs); /*proto*/ +static int __pyx_pw_5_cdec_7Lattice_7__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_index, PyObject *__pyx_v_arcs) { int __pyx_v_index; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); assert(__pyx_arg_index); { - __pyx_v_index = __Pyx_PyInt_AsInt(__pyx_arg_index); if (unlikely((__pyx_v_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_index = __Pyx_PyInt_AsInt(__pyx_arg_index); if (unlikely((__pyx_v_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -11574,8 +12418,8 @@ static int __pyx_pw_5_cdec_7Lattice_5__setitem__(PyObject *__pyx_v_self, PyObjec __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_arcs), (&PyTuple_Type), 1, "arcs", 1))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_7Lattice_4__setitem__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), ((int)__pyx_v_index), ((PyObject*)__pyx_v_arcs)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_arcs), (&PyTuple_Type), 1, "arcs", 1))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_7Lattice_6__setitem__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self), ((int)__pyx_v_index), ((PyObject*)__pyx_v_arcs)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = -1; @@ -11584,7 +12428,7 @@ static int __pyx_pw_5_cdec_7Lattice_5__setitem__(PyObject *__pyx_v_self, PyObjec return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":32 +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":35 * return tuple(arcs) * * def __setitem__(self, int index, tuple arcs): # <<<<<<<<<<<<<< @@ -11592,7 +12436,7 @@ static int __pyx_pw_5_cdec_7Lattice_5__setitem__(PyObject *__pyx_v_self, PyObjec * raise IndexError('lattice index out of range') */ -static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index, PyObject *__pyx_v_arcs) { +static int __pyx_pf_5_cdec_7Lattice_6__setitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index, PyObject *__pyx_v_arcs) { LatticeArc *__pyx_v_arc; PyObject *__pyx_v_label = NULL; PyObject *__pyx_v_cost = NULL; @@ -11617,7 +12461,7 @@ static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setitem__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":33 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":36 * * def __setitem__(self, int index, tuple arcs): * if not 0 <= index < len(self): # <<<<<<<<<<<<<< @@ -11626,29 +12470,29 @@ static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice */ __pyx_t_1 = (0 <= __pyx_v_index); if (__pyx_t_1) { - __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_self)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = (__pyx_v_index < __pyx_t_2); } __pyx_t_3 = (!__pyx_t_1); if (__pyx_t_3) { - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":34 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":37 * def __setitem__(self, int index, tuple arcs): * if not 0 <= index < len(self): * raise IndexError('lattice index out of range') # <<<<<<<<<<<<<< * cdef lattice.LatticeArc* arc * for (label, cost, dist2next) in arcs: */ - __pyx_t_4 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":36 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":39 * raise IndexError('lattice index out of range') * cdef lattice.LatticeArc* arc * for (label, cost, dist2next) in arcs: # <<<<<<<<<<<<<< @@ -11656,29 +12500,35 @@ static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice * label = label.encode('utf8') */ if (unlikely(((PyObject *)__pyx_v_arcs) == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_t_4 = ((PyObject *)__pyx_v_arcs); __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0; for (;;) { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) { PyObject* sequence = __pyx_t_5; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 3)) { + if (size > 3) __Pyx_RaiseTooManyValuesError(3); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON if (likely(PyTuple_CheckExact(sequence))) { - if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { - if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); __pyx_t_8 = PyTuple_GET_ITEM(sequence, 2); } else { - if (unlikely(PyList_GET_SIZE(sequence) != 3)) { - if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } __pyx_t_6 = PyList_GET_ITEM(sequence, 0); __pyx_t_7 = PyList_GET_ITEM(sequence, 1); __pyx_t_8 = PyList_GET_ITEM(sequence, 2); @@ -11686,10 +12536,16 @@ static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(__pyx_t_7); __Pyx_INCREF(__pyx_t_8); + #else + __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else { + } else + { Py_ssize_t index = -1; - __pyx_t_9 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; @@ -11699,14 +12555,15 @@ static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice __Pyx_GOTREF(__pyx_t_7); index = 2; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed; __Pyx_GOTREF(__pyx_t_8); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 3) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 3) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_10 = NULL; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; goto __pyx_L7_unpacking_done; __pyx_L6_unpacking_failed:; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_10 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L7_unpacking_done:; } __Pyx_XDECREF(__pyx_v_label); @@ -11719,7 +12576,7 @@ static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice __pyx_v_dist2next = __pyx_t_8; __pyx_t_8 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":37 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":40 * cdef lattice.LatticeArc* arc * for (label, cost, dist2next) in arcs: * if isinstance(label, unicode): # <<<<<<<<<<<<<< @@ -11732,16 +12589,16 @@ static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_3) { - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":38 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":41 * for (label, cost, dist2next) in arcs: * if isinstance(label, unicode): * label = label.encode('utf8') # <<<<<<<<<<<<<< * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) * self.lattice[0][index].push_back(arc[0]) */ - __pyx_t_5 = PyObject_GetAttr(__pyx_v_label, __pyx_n_s__encode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_GetAttr(__pyx_v_label, __pyx_n_s__encode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_26), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_26), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_v_label); @@ -11751,19 +12608,19 @@ static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice } __pyx_L8:; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":39 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":42 * if isinstance(label, unicode): * label = label.encode('utf8') * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) # <<<<<<<<<<<<<< * self.lattice[0][index].push_back(arc[0]) * del arc */ - __pyx_t_11 = PyBytes_AsString(__pyx_v_label); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_v_cost); if (unlikely((__pyx_t_12 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_v_dist2next); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_11 = PyBytes_AsString(__pyx_v_label); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_v_cost); if (unlikely((__pyx_t_12 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_v_dist2next); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_arc = new LatticeArc(TD::Convert(((char *)__pyx_t_11)), __pyx_t_12, __pyx_t_13); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":40 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":43 * label = label.encode('utf8') * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) * self.lattice[0][index].push_back(arc[0]) # <<<<<<<<<<<<<< @@ -11772,7 +12629,7 @@ static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice */ ((__pyx_v_self->lattice[0])[__pyx_v_index]).push_back((__pyx_v_arc[0])); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":41 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":44 * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) * self.lattice[0][index].push_back(arc[0]) * del arc # <<<<<<<<<<<<<< @@ -11803,17 +12660,17 @@ static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice } /* Python wrapper */ -static Py_ssize_t __pyx_pw_5_cdec_7Lattice_7__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_5_cdec_7Lattice_7__len__(PyObject *__pyx_v_self) { +static Py_ssize_t __pyx_pw_5_cdec_7Lattice_9__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_7Lattice_9__len__(PyObject *__pyx_v_self) { Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Lattice_6__len__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_7Lattice_8__len__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":43 +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":46 * del arc * * def __len__(self): # <<<<<<<<<<<<<< @@ -11821,12 +12678,12 @@ static Py_ssize_t __pyx_pw_5_cdec_7Lattice_7__len__(PyObject *__pyx_v_self) { * */ -static Py_ssize_t __pyx_pf_5_cdec_7Lattice_6__len__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { +static Py_ssize_t __pyx_pf_5_cdec_7Lattice_8__len__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__len__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":44 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":47 * * def __len__(self): * return self.lattice.size() # <<<<<<<<<<<<<< @@ -11843,17 +12700,17 @@ static Py_ssize_t __pyx_pf_5_cdec_7Lattice_6__len__(struct __pyx_obj_5_cdec_Latt } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Lattice_9__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Lattice_9__str__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_7Lattice_11__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Lattice_11__str__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Lattice_8__str__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_7Lattice_10__str__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":46 +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":49 * return self.lattice.size() * * def __str__(self): # <<<<<<<<<<<<<< @@ -11861,7 +12718,7 @@ static PyObject *__pyx_pw_5_cdec_7Lattice_9__str__(PyObject *__pyx_v_self) { * */ -static PyObject *__pyx_pf_5_cdec_7Lattice_8__str__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_7Lattice_10__str__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -11870,7 +12727,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_8__str__(struct __pyx_obj_5_cdec_Latti int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__str__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":47 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":50 * * def __str__(self): * return hypergraph.AsPLF(self.lattice[0], True).c_str() # <<<<<<<<<<<<<< @@ -11878,7 +12735,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_8__str__(struct __pyx_obj_5_cdec_Latti * def __iter__(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->lattice[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->lattice[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; @@ -11895,20 +12752,20 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_8__str__(struct __pyx_obj_5_cdec_Latti __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_7Lattice_12generator13(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5_cdec_7Lattice_14generator13(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Lattice_11__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Lattice_11__iter__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_7Lattice_13__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Lattice_13__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Lattice_10__iter__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_7Lattice_12__iter__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":49 +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":52 * return hypergraph.AsPLF(self.lattice[0], True).c_str() * * def __iter__(self): # <<<<<<<<<<<<<< @@ -11916,7 +12773,7 @@ static PyObject *__pyx_pw_5_cdec_7Lattice_11__iter__(PyObject *__pyx_v_self) { * for i in range(len(self)): */ -static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_7Lattice_12__iter__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -11934,7 +12791,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lat __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Lattice_12generator13, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Lattice_14generator13, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -11952,7 +12809,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lat return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_7Lattice_12generator13(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_7Lattice_14generator13(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; @@ -11969,27 +12826,27 @@ static PyObject *__pyx_gb_5_cdec_7Lattice_12generator13(__pyx_GeneratorObject *_ return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":51 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":54 * def __iter__(self): * cdef unsigned i * for i in range(len(self)): # <<<<<<<<<<<<<< * yield self[i] * */ - __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":52 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":55 * cdef unsigned i * for i in range(len(self)): * yield self[i] # <<<<<<<<<<<<<< * - * def __dealloc__(self): + * def todot(self): */ - __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; @@ -12003,7 +12860,7 @@ static PyObject *__pyx_gb_5_cdec_7Lattice_12generator13(__pyx_GeneratorObject *_ __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[4]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; @@ -12013,43 +12870,11 @@ static PyObject *__pyx_gb_5_cdec_7Lattice_12generator13(__pyx_GeneratorObject *_ __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } -/* Python wrapper */ -static void __pyx_pw_5_cdec_7Lattice_14__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_7Lattice_14__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_7Lattice_13__dealloc__(((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":54 - * yield self[i] - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.lattice - * - */ - -static void __pyx_pf_5_cdec_7Lattice_13__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":55 - * - * def __dealloc__(self): - * del self.lattice # <<<<<<<<<<<<<< - * - * def todot(self): - */ - delete __pyx_v_self->lattice; - - __Pyx_RefNannyFinishContext(); -} - /* Python wrapper */ static PyObject *__pyx_pw_5_cdec_7Lattice_16todot(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_pw_5_cdec_7Lattice_16todot(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { @@ -12069,7 +12894,6 @@ static PyObject *__pyx_pw_5_cdec_7Lattice_5todot_1lines(PyObject *__pyx_self, CY PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("lines (wrapper)", 0); - __pyx_self = __pyx_self; __pyx_r = __pyx_pf_5_cdec_7Lattice_5todot_lines(__pyx_self); __Pyx_RefNannyFinishContext(); return __pyx_r; @@ -12237,10 +13061,18 @@ static PyObject *__pyx_gb_5_cdec_7Lattice_5todot_2generator19(__pyx_GeneratorObj for (;;) { if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else { __pyx_t_1 = __pyx_t_4(__pyx_t_3); if (unlikely(!__pyx_t_1)) { @@ -12279,10 +13111,18 @@ static PyObject *__pyx_gb_5_cdec_7Lattice_5todot_2generator19(__pyx_GeneratorObj for (;;) { if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_5)) { if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_1 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_5)) { if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else { __pyx_t_1 = __pyx_t_7(__pyx_t_5); if (unlikely(!__pyx_t_1)) { @@ -12296,21 +13136,22 @@ static PyObject *__pyx_gb_5_cdec_7Lattice_5todot_2generator19(__pyx_GeneratorObj } if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { PyObject* sequence = __pyx_t_1; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 3)) { + if (size > 3) __Pyx_RaiseTooManyValuesError(3); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON if (likely(PyTuple_CheckExact(sequence))) { - if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { - if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); } else { - if (unlikely(PyList_GET_SIZE(sequence) != 3)) { - if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } __pyx_t_8 = PyList_GET_ITEM(sequence, 0); __pyx_t_9 = PyList_GET_ITEM(sequence, 1); __pyx_t_10 = PyList_GET_ITEM(sequence, 2); @@ -12318,8 +13159,14 @@ static PyObject *__pyx_gb_5_cdec_7Lattice_5todot_2generator19(__pyx_GeneratorObj __Pyx_INCREF(__pyx_t_8); __Pyx_INCREF(__pyx_t_9); __Pyx_INCREF(__pyx_t_10); + #else + __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_10 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else { + } else + { Py_ssize_t index = -1; __pyx_t_11 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); @@ -12332,12 +13179,13 @@ static PyObject *__pyx_gb_5_cdec_7Lattice_5todot_2generator19(__pyx_GeneratorObj index = 2; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L11_unpacking_failed; __Pyx_GOTREF(__pyx_t_10); if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 3) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_12 = NULL; __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; goto __pyx_L12_unpacking_done; __pyx_L11_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_t_12 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L12_unpacking_done:; } @@ -12472,12 +13320,13 @@ static PyObject *__pyx_gb_5_cdec_7Lattice_5todot_2generator19(__pyx_GeneratorObj __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":57 - * del self.lattice + * yield self[i] * * def todot(self): # <<<<<<<<<<<<<< * def lines(): @@ -12777,7 +13626,7 @@ static PyObject *__pyx_pw_5_cdec_9Candidate_4fmap_1__get__(PyObject *__pyx_v_sel * * property fmap: * def __get__(self): # <<<<<<<<<<<<<< - * cdef SparseVector fmap = SparseVector() + * cdef SparseVector fmap = SparseVector.__new__(SparseVector) * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) */ @@ -12794,18 +13643,19 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_4fmap___get__(struct __pyx_obj_5_cde /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":22 * property fmap: * def __get__(self): - * cdef SparseVector fmap = SparseVector() # <<<<<<<<<<<<<< + * cdef SparseVector fmap = SparseVector.__new__(SparseVector) # <<<<<<<<<<<<<< * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) * return fmap */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5_cdec_SparseVector)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); + if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5_cdec_SparseVector)))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":23 * def __get__(self): - * cdef SparseVector fmap = SparseVector() + * cdef SparseVector fmap = SparseVector.__new__(SparseVector) * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) # <<<<<<<<<<<<<< * return fmap * @@ -12813,7 +13663,7 @@ static PyObject *__pyx_pf_5_cdec_9Candidate_4fmap___get__(struct __pyx_obj_5_cde __pyx_v_fmap->vector = new FastSparseVector(__pyx_v_self->candidate->fmap); /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":24 - * cdef SparseVector fmap = SparseVector() + * cdef SparseVector fmap = SparseVector.__new__(SparseVector) * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) * return fmap # <<<<<<<<<<<<<< * @@ -12850,7 +13700,7 @@ static PyObject *__pyx_pw_5_cdec_9Candidate_5score_1__get__(PyObject *__pyx_v_se /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":14 * cdef class Candidate: - * cdef mteval.Candidate* candidate + * cdef mteval.const_Candidate* candidate * cdef public float score # <<<<<<<<<<<<<< * * property words: @@ -13202,10 +14052,18 @@ static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator14(__pyx_GeneratorO for (;;) { if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else { __pyx_t_2 = __pyx_t_4(__pyx_t_3); if (unlikely(!__pyx_t_2)) { @@ -13261,6 +14119,7 @@ static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator14(__pyx_GeneratorO __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } @@ -13536,11 +14395,11 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_11__add__(PyObject *__pyx_v_x static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__evaluator,0}; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__evaluator,0}; PyObject* values[1] = {0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; @@ -13553,8 +14412,7 @@ static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyO kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__evaluator); - if (likely(values[0])) kw_args--; + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__evaluator)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { @@ -13955,6 +14813,7 @@ static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator15(__pyx_GeneratorObj __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } @@ -13964,11 +14823,11 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_se static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph = 0; unsigned int __pyx_v_k; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__hypergraph,&__pyx_n_s__k,0}; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("add_kbest (wrapper)", 0); { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__hypergraph,&__pyx_n_s__k,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; @@ -13982,12 +14841,10 @@ static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_se kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__hypergraph); - if (likely(values[0])) kw_args--; + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__hypergraph)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k); - if (likely(values[1])) kw_args--; + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, 1); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } @@ -14260,11 +15117,11 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_ static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_name = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__name,0}; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__name,0}; PyObject* values[1] = {0}; /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":121 @@ -14410,11 +15267,11 @@ static void __pyx_pf_5_cdec_6Scorer_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_ static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_refs = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__refs,0}; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__call__ (wrapper)", 0); { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__refs,0}; PyObject* values[1] = {0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; @@ -14427,8 +15284,7 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObj kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__refs); - if (likely(values[0])) kw_args--; + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__refs)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { @@ -14551,10 +15407,18 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Score for (;;) { if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_1)) { if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) { if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; + #else + __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else { __pyx_t_7 = __pyx_t_6(__pyx_t_1); if (unlikely(!__pyx_t_7)) { @@ -14954,9 +15818,10 @@ static void __pyx_f_5_cdec__compute_sufficient_stats(void *__pyx_v_metric_, std: * out.fields[i] = ss[i] */ if (unlikely(((PyObject *)__pyx_v_ss) == Py_None)) { - PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_7 = PyList_GET_SIZE(((PyObject *)__pyx_v_ss)); + __pyx_t_7 = PyList_GET_SIZE(((PyObject *)__pyx_v_ss)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_out->fields.resize(__pyx_t_7); /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":170 @@ -14967,9 +15832,10 @@ static void __pyx_f_5_cdec__compute_sufficient_stats(void *__pyx_v_metric_, std: * */ if (unlikely(((PyObject *)__pyx_v_ss) == Py_None)) { - PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_7 = PyList_GET_SIZE(((PyObject *)__pyx_v_ss)); + __pyx_t_7 = PyList_GET_SIZE(((PyObject *)__pyx_v_ss)); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;} for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_7; __pyx_t_3+=1) { __pyx_v_i = __pyx_t_3; @@ -14980,6 +15846,10 @@ static void __pyx_f_5_cdec__compute_sufficient_stats(void *__pyx_v_metric_, std: * * cdef class Metric: */ + if (unlikely(((PyObject *)__pyx_v_ss) == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } __pyx_t_5 = __Pyx_GetItemInt_List(((PyObject *)__pyx_v_ss), __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __pyx_t_8 = __pyx_PyFloat_AsFloat(__pyx_t_5); if (unlikely((__pyx_t_8 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -15087,11 +15957,11 @@ static int __pyx_pf_5_cdec_6Metric___cinit__(struct __pyx_obj_5_cdec_Metric *__p static PyObject *__pyx_pw_5_cdec_6Metric_3__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_pw_5_cdec_6Metric_3__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_refs = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__refs,0}; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__call__ (wrapper)", 0); { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__refs,0}; PyObject* values[1] = {0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; @@ -15104,8 +15974,7 @@ static PyObject *__pyx_pw_5_cdec_6Metric_3__call__(PyObject *__pyx_v_self, PyObj kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__refs); - if (likely(values[0])) kw_args--; + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__refs)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { @@ -15230,11 +16099,11 @@ static PyObject *__pyx_pw_5_cdec_6Metric_7evaluate(PyObject *__pyx_v_self, PyObj static PyObject *__pyx_pw_5_cdec_6Metric_7evaluate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { CYTHON_UNUSED PyObject *__pyx_v_hyp = 0; CYTHON_UNUSED PyObject *__pyx_v_refs = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__hyp,&__pyx_n_s__refs,0}; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("evaluate (wrapper)", 0); { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__hyp,&__pyx_n_s__refs,0}; PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; @@ -15248,12 +16117,10 @@ static PyObject *__pyx_pw_5_cdec_6Metric_7evaluate(PyObject *__pyx_v_self, PyObj kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__hyp); - if (likely(values[0])) kw_args--; + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__hyp)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__refs); - if (likely(values[1])) kw_args--; + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__refs)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("evaluate", 1, 2, 2, 1); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } @@ -15334,7 +16201,6 @@ static PyObject *__pyx_pw_5_cdec_3_make_config(PyObject *__pyx_self, PyObject *_ PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("_make_config (wrapper)", 0); - __pyx_self = __pyx_self; __pyx_r = __pyx_pf_5_cdec_2_make_config(__pyx_self, ((PyObject *)__pyx_v_config)); __Pyx_RefNannyFinishContext(); return __pyx_r; @@ -15438,10 +16304,18 @@ static PyObject *__pyx_gb_5_cdec_4generator16(__pyx_GeneratorObject *__pyx_gener for (;;) { if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_1)) { if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_1)) { if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else { __pyx_t_2 = __pyx_t_4(__pyx_t_1); if (unlikely(!__pyx_t_2)) { @@ -15455,27 +16329,33 @@ static PyObject *__pyx_gb_5_cdec_4generator16(__pyx_GeneratorObject *__pyx_gener } if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { PyObject* sequence = __pyx_t_2; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON if (likely(PyTuple_CheckExact(sequence))) { - 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 = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); } else { - 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 = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } __pyx_t_5 = PyList_GET_ITEM(sequence, 0); __pyx_t_6 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(__pyx_t_6); + #else + __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else { + } else + { Py_ssize_t index = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); @@ -15486,12 +16366,13 @@ static PyObject *__pyx_gb_5_cdec_4generator16(__pyx_GeneratorObject *__pyx_gener index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed; __Pyx_GOTREF(__pyx_t_6); if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = NULL; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; goto __pyx_L7_unpacking_done; __pyx_L6_unpacking_failed:; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L7_unpacking_done:; } @@ -15543,10 +16424,18 @@ static PyObject *__pyx_gb_5_cdec_4generator16(__pyx_GeneratorObject *__pyx_gener for (;;) { if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_2)) { if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; + #else + __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_2)) { if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; + #else + __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else { __pyx_t_6 = __pyx_t_11(__pyx_t_2); if (unlikely(!__pyx_t_6)) { @@ -15560,27 +16449,33 @@ static PyObject *__pyx_gb_5_cdec_4generator16(__pyx_GeneratorObject *__pyx_gener } if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) { PyObject* sequence = __pyx_t_6; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON if (likely(PyTuple_CheckExact(sequence))) { - 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 = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); } else { - 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 = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } __pyx_t_5 = PyList_GET_ITEM(sequence, 0); __pyx_t_7 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(__pyx_t_7); + #else + __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } else { + } else + { Py_ssize_t index = -1; __pyx_t_12 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_12); @@ -15591,12 +16486,13 @@ static PyObject *__pyx_gb_5_cdec_4generator16(__pyx_GeneratorObject *__pyx_gener index = 1; __pyx_t_7 = __pyx_t_8(__pyx_t_12); if (unlikely(!__pyx_t_7)) goto __pyx_L11_unpacking_failed; __Pyx_GOTREF(__pyx_t_7); if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_12), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = NULL; __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; goto __pyx_L12_unpacking_done; __pyx_L11_unpacking_failed:; __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L12_unpacking_done:; } @@ -15700,10 +16596,18 @@ static PyObject *__pyx_gb_5_cdec_4generator16(__pyx_GeneratorObject *__pyx_gener for (;;) { if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_2)) { if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_6 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; + #else + __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_2)) { if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; + #else + __pyx_t_6 = PySequence_ITEM(__pyx_t_2, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else { __pyx_t_6 = __pyx_t_11(__pyx_t_2); if (unlikely(!__pyx_t_6)) { @@ -15827,6 +16731,7 @@ static PyObject *__pyx_gb_5_cdec_4generator16(__pyx_GeneratorObject *__pyx_gener __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } @@ -15836,13 +16741,13 @@ static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_config_str = 0; PyObject *__pyx_v_config = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__config_str,0}; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); __pyx_v_config = PyDict_New(); if (unlikely(!__pyx_v_config)) return -1; __Pyx_GOTREF(__pyx_v_config); { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__config_str,0}; PyObject* values[1] = {0}; /* "_cdec.pyx":43 @@ -15985,10 +16890,18 @@ static PyObject *__pyx_gb_5_cdec_7Decoder_9__cinit___2generator20(__pyx_Generato for (;;) { if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_2)) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_2)) { if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else { __pyx_t_3 = __pyx_t_5(__pyx_t_2); if (unlikely(!__pyx_t_3)) { @@ -16037,6 +16950,7 @@ static PyObject *__pyx_gb_5_cdec_7Decoder_9__cinit___2generator20(__pyx_Generato __pyx_L0:; __Pyx_XDECREF(__pyx_r); __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); __Pyx_RefNannyFinishContext(); return NULL; } @@ -16221,7 +17135,7 @@ static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *_ * cdef istringstream* config_stream = new istringstream(config_str) * self.dec = new decoder.Decoder(config_stream) # <<<<<<<<<<<<<< * del config_stream - * self.weights = DenseVector() + * self.weights = DenseVector.__new__(DenseVector) */ __pyx_v_self->dec = new Decoder(__pyx_v_config_stream); @@ -16229,7 +17143,7 @@ static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *_ * cdef istringstream* config_stream = new istringstream(config_str) * self.dec = new decoder.Decoder(config_stream) * del config_stream # <<<<<<<<<<<<<< - * self.weights = DenseVector() + * self.weights = DenseVector.__new__(DenseVector) * self.weights.vector = &self.dec.CurrentWeightVector() */ delete __pyx_v_config_stream; @@ -16237,12 +17151,13 @@ static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *_ /* "_cdec.pyx":58 * self.dec = new decoder.Decoder(config_stream) * del config_stream - * self.weights = DenseVector() # <<<<<<<<<<<<<< + * self.weights = DenseVector.__new__(DenseVector) # <<<<<<<<<<<<<< * self.weights.vector = &self.dec.CurrentWeightVector() - * + * self.weights.owned = True */ - __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5_cdec_DenseVector)); 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); + if (!(likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5_cdec_DenseVector)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GIVEREF(__pyx_t_6); __Pyx_GOTREF(__pyx_v_self->weights); __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); @@ -16251,12 +17166,21 @@ static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *_ /* "_cdec.pyx":59 * del config_stream - * self.weights = DenseVector() + * self.weights = DenseVector.__new__(DenseVector) * self.weights.vector = &self.dec.CurrentWeightVector() # <<<<<<<<<<<<<< + * self.weights.owned = True + * + */ + __pyx_v_self->weights->vector = (&__pyx_v_self->dec->CurrentWeightVector()); + + /* "_cdec.pyx":60 + * self.weights = DenseVector.__new__(DenseVector) + * self.weights.vector = &self.dec.CurrentWeightVector() + * self.weights.owned = True # <<<<<<<<<<<<<< * * def __dealloc__(self): */ - __pyx_v_self->weights->vector = (&__pyx_v_self->dec->CurrentWeightVector()); + __pyx_v_self->weights->owned = 1; __pyx_r = 0; goto __pyx_L0; @@ -16283,8 +17207,8 @@ static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyFinishContext(); } -/* "_cdec.pyx":61 - * self.weights.vector = &self.dec.CurrentWeightVector() +/* "_cdec.pyx":62 + * self.weights.owned = True * * def __dealloc__(self): # <<<<<<<<<<<<<< * del self.dec @@ -16295,7 +17219,7 @@ static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "_cdec.pyx":62 + /* "_cdec.pyx":63 * * def __dealloc__(self): * del self.dec # <<<<<<<<<<<<<< @@ -16318,7 +17242,7 @@ static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_se return __pyx_r; } -/* "_cdec.pyx":65 +/* "_cdec.pyx":66 * * property weights: * def __get__(self): # <<<<<<<<<<<<<< @@ -16331,7 +17255,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cd __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); - /* "_cdec.pyx":66 + /* "_cdec.pyx":67 * property weights: * def __get__(self): * return self.weights # <<<<<<<<<<<<<< @@ -16361,7 +17285,7 @@ static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, Py return __pyx_r; } -/* "_cdec.pyx":68 +/* "_cdec.pyx":69 * return self.weights * * def __set__(self, weights): # <<<<<<<<<<<<<< @@ -16388,7 +17312,7 @@ static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_De int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - /* "_cdec.pyx":69 + /* "_cdec.pyx":70 * * def __set__(self, weights): * if isinstance(weights, DenseVector): # <<<<<<<<<<<<<< @@ -16401,7 +17325,7 @@ static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_De __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "_cdec.pyx":70 + /* "_cdec.pyx":71 * def __set__(self, weights): * if isinstance(weights, DenseVector): * self.weights.vector[0] = ( weights).vector[0] # <<<<<<<<<<<<<< @@ -16412,7 +17336,7 @@ static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_De goto __pyx_L3; } - /* "_cdec.pyx":71 + /* "_cdec.pyx":72 * if isinstance(weights, DenseVector): * self.weights.vector[0] = ( weights).vector[0] * elif isinstance(weights, SparseVector): # <<<<<<<<<<<<<< @@ -16425,7 +17349,7 @@ static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_De __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "_cdec.pyx":72 + /* "_cdec.pyx":73 * self.weights.vector[0] = ( weights).vector[0] * elif isinstance(weights, SparseVector): * self.weights.vector.clear() # <<<<<<<<<<<<<< @@ -16434,23 +17358,23 @@ static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_De */ __pyx_v_self->weights->vector->clear(); - /* "_cdec.pyx":73 + /* "_cdec.pyx":74 * elif isinstance(weights, SparseVector): * self.weights.vector.clear() * (( weights).vector[0]).init_vector(self.weights.vector) # <<<<<<<<<<<<<< * elif isinstance(weights, dict): - * for fname, fval in weights.items(): + * self.weights.vector.clear() */ (((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_weights)->vector[0]).init_vector(__pyx_v_self->weights->vector); goto __pyx_L3; } - /* "_cdec.pyx":74 + /* "_cdec.pyx":75 * self.weights.vector.clear() * (( weights).vector[0]).init_vector(self.weights.vector) * elif isinstance(weights, dict): # <<<<<<<<<<<<<< + * self.weights.vector.clear() * for fname, fval in weights.items(): - * self.weights[fname] = fval */ __pyx_t_1 = ((PyObject *)((PyObject*)(&PyDict_Type))); __Pyx_INCREF(__pyx_t_1); @@ -16458,23 +17382,32 @@ static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_De __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "_cdec.pyx":75 + /* "_cdec.pyx":76 * (( weights).vector[0]).init_vector(self.weights.vector) * elif isinstance(weights, dict): + * self.weights.vector.clear() # <<<<<<<<<<<<<< + * for fname, fval in weights.items(): + * self.weights[fname] = fval + */ + __pyx_v_self->weights->vector->clear(); + + /* "_cdec.pyx":77 + * elif isinstance(weights, dict): + * self.weights.vector.clear() * for fname, fval in weights.items(): # <<<<<<<<<<<<<< * self.weights[fname] = fval * else: */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_weights, __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(__pyx_v_weights, __pyx_n_s__items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((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_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { __pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0; __pyx_t_5 = NULL; } else { - __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; } @@ -16482,16 +17415,24 @@ static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_De for (;;) { if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_1)) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_1)) { if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif } else { __pyx_t_3 = __pyx_t_5(__pyx_t_1); if (unlikely(!__pyx_t_3)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } @@ -16499,29 +17440,35 @@ static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_De } if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { PyObject* sequence = __pyx_t_3; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON if (likely(PyTuple_CheckExact(sequence))) { - 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 = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); } else { - 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 = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } __pyx_t_6 = PyList_GET_ITEM(sequence, 0); __pyx_t_7 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(__pyx_t_7); + #else + __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { + } else + { Py_ssize_t index = -1; - __pyx_t_8 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; @@ -16529,14 +17476,15 @@ static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_De __Pyx_GOTREF(__pyx_t_6); index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed; __Pyx_GOTREF(__pyx_t_7); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = NULL; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; goto __pyx_L7_unpacking_done; __pyx_L6_unpacking_failed:; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_L7_unpacking_done:; } __Pyx_XDECREF(__pyx_v_fname); @@ -16546,40 +17494,40 @@ static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_De __pyx_v_fval = __pyx_t_7; __pyx_t_7 = 0; - /* "_cdec.pyx":76 - * elif isinstance(weights, dict): + /* "_cdec.pyx":78 + * self.weights.vector.clear() * for fname, fval in weights.items(): * self.weights[fname] = fval # <<<<<<<<<<<<<< * else: * raise TypeError('cannot initialize weights with %s' % type(weights)) */ - if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_v_fname, __pyx_v_fval) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_v_fname, __pyx_v_fval) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L3; } /*else*/ { - /* "_cdec.pyx":78 + /* "_cdec.pyx":80 * self.weights[fname] = fval * else: * raise TypeError('cannot initialize weights with %s' % type(weights)) # <<<<<<<<<<<<<< * * property formalism: */ - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_49), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_49), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __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 = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L3:; @@ -16611,12 +17559,12 @@ static PyObject *__pyx_pw_5_cdec_7Decoder_9formalism_1__get__(PyObject *__pyx_v_ return __pyx_r; } -/* "_cdec.pyx":81 +/* "_cdec.pyx":83 * * property formalism: * def __get__(self): # <<<<<<<<<<<<<< * cdef variables_map* conf = &self.dec.GetConf() - * return conf[0]['formalism'].as_str().c_str() + * return conf[0]['formalism'].as_str() */ static PyObject *__pyx_pf_5_cdec_7Decoder_9formalism___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { @@ -16629,24 +17577,24 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_9formalism___get__(struct __pyx_obj_5_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - /* "_cdec.pyx":82 + /* "_cdec.pyx":84 * property formalism: * def __get__(self): * cdef variables_map* conf = &self.dec.GetConf() # <<<<<<<<<<<<<< - * return conf[0]['formalism'].as_str().c_str() + * return conf[0]['formalism'].as_str() * */ __pyx_v_conf = (&__pyx_v_self->dec->GetConf()); - /* "_cdec.pyx":83 + /* "_cdec.pyx":85 * def __get__(self): * cdef variables_map* conf = &self.dec.GetConf() - * return conf[0]['formalism'].as_str().c_str() # <<<<<<<<<<<<<< + * return conf[0]['formalism'].as_str() # <<<<<<<<<<<<<< * * def read_weights(self, weights): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(((__pyx_v_conf[0])[__pyx_k__formalism]).as().c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_convert_string_to_py_(((__pyx_v_conf[0])[__pyx_k__formalism]).as()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; @@ -16675,8 +17623,8 @@ static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, return __pyx_r; } -/* "_cdec.pyx":85 - * return conf[0]['formalism'].as_str().c_str() +/* "_cdec.pyx":87 + * return conf[0]['formalism'].as_str() * * def read_weights(self, weights): # <<<<<<<<<<<<<< * with open(weights) as fp: @@ -16711,7 +17659,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_weights", 0); - /* "_cdec.pyx":86 + /* "_cdec.pyx":88 * * def read_weights(self, weights): * with open(weights) as fp: # <<<<<<<<<<<<<< @@ -16719,19 +17667,19 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ * if line.strip().startswith('#'): continue */ /*with:*/ { - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __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 = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_weights); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_weights); __Pyx_GIVEREF(__pyx_v_weights); - __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 = 86; __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 = 88; __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 = 86; __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 = 88; __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 = 86; __pyx_clineno = __LINE__; goto __pyx_L3_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 = 88; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; @@ -16746,7 +17694,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ __pyx_v_fp = __pyx_t_4; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "_cdec.pyx":87 + /* "_cdec.pyx":89 * def read_weights(self, weights): * with open(weights) as fp: * for line in fp: # <<<<<<<<<<<<<< @@ -16757,23 +17705,31 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ __pyx_t_4 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; __pyx_t_9 = NULL; } else { - __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; } for (;;) { if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif } else { __pyx_t_2 = __pyx_t_9(__pyx_t_4); if (unlikely(!__pyx_t_2)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} } break; } @@ -16783,25 +17739,25 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ __pyx_v_line = __pyx_t_2; __pyx_t_2 = 0; - /* "_cdec.pyx":88 + /* "_cdec.pyx":90 * with open(weights) as fp: * for line in fp: * if line.strip().startswith('#'): continue # <<<<<<<<<<<<<< * fname, value = line.split() * self.weights[fname.strip()] = float(value) */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__strip); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__strip); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__startswith); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__startswith); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_51), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_51), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_10) { goto __pyx_L16_continue; @@ -16809,43 +17765,49 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ } __pyx_L18:; - /* "_cdec.pyx":89 + /* "_cdec.pyx":91 * for line in fp: * if line.strip().startswith('#'): continue * 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 = 89; __pyx_clineno = __LINE__; goto __pyx_L7_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 = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); - __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 = 89; __pyx_clineno = __LINE__; goto __pyx_L7_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 = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { PyObject* sequence = __pyx_t_2; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON if (likely(PyTuple_CheckExact(sequence))) { - 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 = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); } else { - 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 = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } __pyx_t_1 = PyList_GET_ITEM(sequence, 0); __pyx_t_11 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(__pyx_t_11); + #else + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_11 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else { + } else + { Py_ssize_t index = -1; - __pyx_t_12 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_12 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_13 = Py_TYPE(__pyx_t_12)->tp_iternext; @@ -16853,14 +17815,15 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ __Pyx_GOTREF(__pyx_t_1); index = 1; __pyx_t_11 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_11)) goto __pyx_L19_unpacking_failed; __Pyx_GOTREF(__pyx_t_11); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_13 = NULL; __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; goto __pyx_L20_unpacking_done; __pyx_L19_unpacking_failed:; __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_13 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __pyx_L20_unpacking_done:; } __Pyx_XDECREF(__pyx_v_fname); @@ -16870,22 +17833,22 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ __pyx_v_value = __pyx_t_11; __pyx_t_11 = 0; - /* "_cdec.pyx":90 + /* "_cdec.pyx":92 * if line.strip().startswith('#'): continue * fname, value = line.split() * self.weights[fname.strip()] = float(value) # <<<<<<<<<<<<<< * * def translate(self, sentence, grammar=None): */ - __pyx_t_14 = __Pyx_PyObject_AsDouble(__pyx_v_value); if (unlikely(__pyx_t_14 == ((double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_2 = PyFloat_FromDouble(__pyx_t_14); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_14 = __Pyx_PyObject_AsDouble(__pyx_v_value); if (unlikely(__pyx_t_14 == ((double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyFloat_FromDouble(__pyx_t_14); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = PyObject_GetAttr(__pyx_v_fname, __pyx_n_s__strip); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_11 = PyObject_GetAttr(__pyx_v_fname, __pyx_n_s__strip); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_11); - __pyx_t_1 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_t_1, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_t_1, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_L16_continue:; @@ -16903,7 +17866,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "_cdec.pyx":86 + /* "_cdec.pyx":88 * * def read_weights(self, weights): * with open(weights) as fp: # <<<<<<<<<<<<<< @@ -16912,11 +17875,11 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ */ /*except:*/ { __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_2, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_2, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_GOTREF(__pyx_t_2); __Pyx_GOTREF(__pyx_t_1); - __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} __Pyx_GOTREF(__pyx_t_11); __Pyx_INCREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_4); @@ -16929,11 +17892,11 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ __Pyx_GIVEREF(__pyx_t_1); __pyx_t_15 = PyObject_Call(__pyx_t_3, __pyx_t_11, NULL); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} __Pyx_GOTREF(__pyx_t_15); __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_15); __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} __pyx_t_16 = (!__pyx_t_10); if (__pyx_t_16) { __Pyx_GIVEREF(__pyx_t_4); @@ -16941,7 +17904,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ __Pyx_GIVEREF(__pyx_t_1); __Pyx_ErrRestore(__pyx_t_4, __pyx_t_2, __pyx_t_1); __pyx_t_4 = 0; __pyx_t_2 = 0; __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} goto __pyx_L23; } __pyx_L23:; @@ -16969,11 +17932,11 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_ if (__pyx_t_3) { __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_52, NULL); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_7); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } } goto __pyx_L24; @@ -17008,14 +17971,14 @@ static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyO static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_sentence = 0; PyObject *__pyx_v_grammar = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sentence,&__pyx_n_s__grammar,0}; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("translate (wrapper)", 0); { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sentence,&__pyx_n_s__grammar,0}; PyObject* values[2] = {0,0}; - /* "_cdec.pyx":92 + /* "_cdec.pyx":94 * self.weights[fname.strip()] = float(value) * * def translate(self, sentence, grammar=None): # <<<<<<<<<<<<<< @@ -17035,8 +17998,7 @@ static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyO kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sentence); - if (likely(values[0])) kw_args--; + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sentence)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (kw_args > 0) { @@ -17045,7 +18007,7 @@ static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyO } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "translate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "translate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -17060,7 +18022,7 @@ static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(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 = 92; __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 = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -17088,7 +18050,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec int __pyx_clineno = 0; __Pyx_RefNannySetupContext("translate", 0); - /* "_cdec.pyx":94 + /* "_cdec.pyx":96 * def translate(self, sentence, grammar=None): * cdef bytes input_str * if isinstance(sentence, unicode) or isinstance(sentence, str): # <<<<<<<<<<<<<< @@ -17110,19 +18072,19 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec } if (__pyx_t_4) { - /* "_cdec.pyx":95 + /* "_cdec.pyx":97 * cdef bytes input_str * if isinstance(sentence, unicode) or isinstance(sentence, str): * input_str = as_str(sentence.strip()) # <<<<<<<<<<<<<< * elif isinstance(sentence, Lattice): * input_str = str(sentence) # PLF format */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyBytes_FromString(__pyx_f_5_cdec_as_str(__pyx_t_5, NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(__pyx_f_5_cdec_as_str(__pyx_t_5, NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_input_str = __pyx_t_1; @@ -17130,7 +18092,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec goto __pyx_L3; } - /* "_cdec.pyx":96 + /* "_cdec.pyx":98 * if isinstance(sentence, unicode) or isinstance(sentence, str): * input_str = as_str(sentence.strip()) * elif isinstance(sentence, Lattice): # <<<<<<<<<<<<<< @@ -17143,62 +18105,62 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_4) { - /* "_cdec.pyx":97 + /* "_cdec.pyx":99 * input_str = as_str(sentence.strip()) * elif isinstance(sentence, Lattice): * input_str = str(sentence) # PLF format # <<<<<<<<<<<<<< * else: * raise TypeError('Cannot translate input type %s' % type(sentence)) */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __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 = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_sentence); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_sentence); __Pyx_GIVEREF(__pyx_v_sentence); - __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_input_str = ((PyObject*)__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L3; } /*else*/ { - /* "_cdec.pyx":99 + /* "_cdec.pyx":101 * input_str = str(sentence) # PLF format * else: * raise TypeError('Cannot translate input type %s' % type(sentence)) # <<<<<<<<<<<<<< * if grammar: * if isinstance(grammar, str) or isinstance(grammar, unicode): */ - __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_53), ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_53), ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __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 = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_5)); __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L3:; - /* "_cdec.pyx":100 + /* "_cdec.pyx":102 * else: * raise TypeError('Cannot translate input type %s' % type(sentence)) * if grammar: # <<<<<<<<<<<<<< * if isinstance(grammar, str) or isinstance(grammar, unicode): * self.dec.AddSupplementalGrammarFromString(string(as_str(grammar))) */ - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_grammar); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_grammar); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_4) { - /* "_cdec.pyx":101 + /* "_cdec.pyx":103 * raise TypeError('Cannot translate input type %s' % type(sentence)) * if grammar: * if isinstance(grammar, str) or isinstance(grammar, unicode): # <<<<<<<<<<<<<< @@ -17220,7 +18182,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec } if (__pyx_t_3) { - /* "_cdec.pyx":102 + /* "_cdec.pyx":104 * if grammar: * if isinstance(grammar, str) or isinstance(grammar, unicode): * self.dec.AddSupplementalGrammarFromString(string(as_str(grammar))) # <<<<<<<<<<<<<< @@ -17232,19 +18194,19 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec } /*else*/ { - /* "_cdec.pyx":104 + /* "_cdec.pyx":106 * self.dec.AddSupplementalGrammarFromString(string(as_str(grammar))) * else: * self.dec.AddSupplementalGrammar(TextGrammar(grammar).grammar[0]) # <<<<<<<<<<<<<< * cdef decoder.BasicObserver observer = decoder.BasicObserver() * self.dec.Decode(string(input_str), &observer) */ - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF(__pyx_v_grammar); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_grammar); __Pyx_GIVEREF(__pyx_v_grammar); - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_TextGrammar)), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_TextGrammar)), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; __pyx_v_self->dec->AddSupplementalGrammar((((struct __pyx_obj_5_cdec_TextGrammar *)__pyx_t_1)->__pyx_base.grammar[0])); @@ -17255,7 +18217,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec } __pyx_L4:; - /* "_cdec.pyx":105 + /* "_cdec.pyx":107 * else: * self.dec.AddSupplementalGrammar(TextGrammar(grammar).grammar[0]) * cdef decoder.BasicObserver observer = decoder.BasicObserver() # <<<<<<<<<<<<<< @@ -17264,17 +18226,17 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec */ __pyx_v_observer = BasicObserver(); - /* "_cdec.pyx":106 + /* "_cdec.pyx":108 * self.dec.AddSupplementalGrammar(TextGrammar(grammar).grammar[0]) * cdef decoder.BasicObserver observer = decoder.BasicObserver() * self.dec.Decode(string(input_str), &observer) # <<<<<<<<<<<<<< * if observer.hypergraph == NULL: * raise ParseFailed() */ - __pyx_t_6 = PyBytes_AsString(((PyObject *)__pyx_v_input_str)); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyBytes_AsString(((PyObject *)__pyx_v_input_str)); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->dec->Decode(std::string(__pyx_t_6), (&__pyx_v_observer)); - /* "_cdec.pyx":107 + /* "_cdec.pyx":109 * cdef decoder.BasicObserver observer = decoder.BasicObserver() * self.dec.Decode(string(input_str), &observer) * if observer.hypergraph == NULL: # <<<<<<<<<<<<<< @@ -17284,38 +18246,38 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec __pyx_t_3 = (__pyx_v_observer.hypergraph == NULL); if (__pyx_t_3) { - /* "_cdec.pyx":108 + /* "_cdec.pyx":110 * self.dec.Decode(string(input_str), &observer) * if observer.hypergraph == NULL: * raise ParseFailed() # <<<<<<<<<<<<<< * cdef Hypergraph hg = Hypergraph() * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__ParseFailed); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__ParseFailed); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L6; } __pyx_L6:; - /* "_cdec.pyx":109 + /* "_cdec.pyx":111 * if observer.hypergraph == NULL: * raise ParseFailed() * cdef Hypergraph hg = Hypergraph() # <<<<<<<<<<<<<< * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) * return hg */ - __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Hypergraph)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Hypergraph)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __pyx_v_hg = ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_t_5); __pyx_t_5 = 0; - /* "_cdec.pyx":110 + /* "_cdec.pyx":112 * raise ParseFailed() * cdef Hypergraph hg = Hypergraph() * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) # <<<<<<<<<<<<<< @@ -17323,7 +18285,7 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec */ __pyx_v_hg->hg = new Hypergraph((__pyx_v_observer.hypergraph[0])); - /* "_cdec.pyx":111 + /* "_cdec.pyx":113 * cdef Hypergraph hg = Hypergraph() * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) * return hg # <<<<<<<<<<<<<< @@ -17348,13 +18310,65 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Dec return __pyx_r; } -static PyObject *__pyx_tp_new_5_cdec_DenseVector(PyTypeObject *t, PyObject *a, PyObject *k) { +/* "string.to_py":25 + * + * @cname("__pyx_convert_string_to_py_") + * cdef object __pyx_convert_string_to_py_(string& s): # <<<<<<<<<<<<<< + * return s.data()[:s.size()] + * + */ + +static PyObject *__pyx_convert_string_to_py_(const std::string &__pyx_v_s) { + 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("__pyx_convert_string_to_py_", 0); + + /* "string.to_py":26 + * @cname("__pyx_convert_string_to_py_") + * cdef object __pyx_convert_string_to_py_(string& s): + * return s.data()[:s.size()] # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromStringAndSize(__pyx_v_s.data() + 0, __pyx_v_s.size() - 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 26; __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("string.to_py.__pyx_convert_string_to_py_", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_tp_new_5_cdec_DenseVector(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; return o; } static void __pyx_tp_dealloc_5_cdec_DenseVector(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_11DenseVector_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } (*Py_TYPE(o)->tp_free)(o); } static PyObject *__pyx_sq_item_5_cdec_DenseVector(PyObject *o, Py_ssize_t i) { @@ -17367,7 +18381,7 @@ static PyObject *__pyx_sq_item_5_cdec_DenseVector(PyObject *o, Py_ssize_t i) { static int __pyx_mp_ass_subscript_5_cdec_DenseVector(PyObject *o, PyObject *i, PyObject *v) { if (v) { - return __pyx_pw_5_cdec_11DenseVector_5__setitem__(o, i, v); + return __pyx_pw_5_cdec_11DenseVector_9__setitem__(o, i, v); } else { PyErr_Format(PyExc_NotImplementedError, @@ -17377,8 +18391,8 @@ static int __pyx_mp_ass_subscript_5_cdec_DenseVector(PyObject *o, PyObject *i, P } static PyMethodDef __pyx_methods_5_cdec_DenseVector[] = { - {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_10dot, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("tosparse"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_12tosparse, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_14dot, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("tosparse"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_16tosparse, METH_NOARGS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; @@ -17441,7 +18455,7 @@ static PyNumberMethods __pyx_tp_as_number_DenseVector = { }; static PySequenceMethods __pyx_tp_as_sequence_DenseVector = { - __pyx_pw_5_cdec_11DenseVector_1__len__, /*sq_length*/ + __pyx_pw_5_cdec_11DenseVector_5__len__, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ __pyx_sq_item_5_cdec_DenseVector, /*sq_item*/ @@ -17454,8 +18468,8 @@ static PySequenceMethods __pyx_tp_as_sequence_DenseVector = { }; static PyMappingMethods __pyx_tp_as_mapping_DenseVector = { - __pyx_pw_5_cdec_11DenseVector_1__len__, /*mp_length*/ - __pyx_pw_5_cdec_11DenseVector_3__getitem__, /*mp_subscript*/ + __pyx_pw_5_cdec_11DenseVector_5__len__, /*mp_length*/ + __pyx_pw_5_cdec_11DenseVector_7__getitem__, /*mp_subscript*/ __pyx_mp_ass_subscript_5_cdec_DenseVector, /*mp_ass_subscript*/ }; @@ -17510,7 +18524,7 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_11DenseVector_7__iter__, /*tp_iter*/ + __pyx_pw_5_cdec_11DenseVector_11__iter__, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_5_cdec_DenseVector, /*tp_methods*/ 0, /*tp_members*/ @@ -17520,7 +18534,7 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ - 0, /*tp_init*/ + __pyx_pw_5_cdec_11DenseVector_1__init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_5_cdec_DenseVector, /*tp_new*/ 0, /*tp_free*/ @@ -17536,7 +18550,7 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_SparseVector(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_SparseVector(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; return o; @@ -17547,7 +18561,7 @@ static void __pyx_tp_dealloc_5_cdec_SparseVector(PyObject *o) { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); - __pyx_pw_5_cdec_12SparseVector_1__dealloc__(o); + __pyx_pw_5_cdec_12SparseVector_3__dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); @@ -17564,7 +18578,7 @@ static PyObject *__pyx_sq_item_5_cdec_SparseVector(PyObject *o, Py_ssize_t i) { static int __pyx_mp_ass_subscript_5_cdec_SparseVector(PyObject *o, PyObject *i, PyObject *v) { if (v) { - return __pyx_pw_5_cdec_12SparseVector_7__setitem__(o, i, v); + return __pyx_pw_5_cdec_12SparseVector_9__setitem__(o, i, v); } else { PyErr_Format(PyExc_NotImplementedError, @@ -17574,22 +18588,22 @@ static int __pyx_mp_ass_subscript_5_cdec_SparseVector(PyObject *o, PyObject *i, } static PyMethodDef __pyx_methods_5_cdec_SparseVector[] = { - {__Pyx_NAMESTR("copy"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_3copy, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_12dot, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("copy"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_5copy, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_14dot, METH_O, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_30__add__, /*nb_add*/ - __pyx_pw_5_cdec_12SparseVector_32__sub__, /*nb_subtract*/ - __pyx_pw_5_cdec_12SparseVector_34__mul__, /*nb_multiply*/ + __pyx_pw_5_cdec_12SparseVector_32__add__, /*nb_add*/ + __pyx_pw_5_cdec_12SparseVector_34__sub__, /*nb_subtract*/ + __pyx_pw_5_cdec_12SparseVector_36__mul__, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 - __pyx_pw_5_cdec_12SparseVector_36__div__, /*nb_divide*/ + __pyx_pw_5_cdec_12SparseVector_38__div__, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ 0, /*nb_power*/ - __pyx_pw_5_cdec_12SparseVector_20__neg__, /*nb_negative*/ + __pyx_pw_5_cdec_12SparseVector_22__neg__, /*nb_negative*/ 0, /*nb_positive*/ 0, /*nb_absolute*/ 0, /*nb_nonzero*/ @@ -17615,11 +18629,11 @@ static PyNumberMethods __pyx_tp_as_number_SparseVector = { #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif - __pyx_pw_5_cdec_12SparseVector_22__iadd__, /*nb_inplace_add*/ - __pyx_pw_5_cdec_12SparseVector_24__isub__, /*nb_inplace_subtract*/ - __pyx_pw_5_cdec_12SparseVector_26__imul__, /*nb_inplace_multiply*/ + __pyx_pw_5_cdec_12SparseVector_24__iadd__, /*nb_inplace_add*/ + __pyx_pw_5_cdec_12SparseVector_26__isub__, /*nb_inplace_subtract*/ + __pyx_pw_5_cdec_12SparseVector_28__imul__, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 - __pyx_pw_5_cdec_12SparseVector_28__idiv__, /*nb_inplace_divide*/ + __pyx_pw_5_cdec_12SparseVector_30__idiv__, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ @@ -17638,21 +18652,21 @@ static PyNumberMethods __pyx_tp_as_number_SparseVector = { }; static PySequenceMethods __pyx_tp_as_sequence_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_16__len__, /*sq_length*/ + __pyx_pw_5_cdec_12SparseVector_18__len__, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ __pyx_sq_item_5_cdec_SparseVector, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ - __pyx_pw_5_cdec_12SparseVector_18__contains__, /*sq_contains*/ + __pyx_pw_5_cdec_12SparseVector_20__contains__, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_16__len__, /*mp_length*/ - __pyx_pw_5_cdec_12SparseVector_5__getitem__, /*mp_subscript*/ + __pyx_pw_5_cdec_12SparseVector_18__len__, /*mp_length*/ + __pyx_pw_5_cdec_12SparseVector_7__getitem__, /*mp_subscript*/ __pyx_mp_ass_subscript_5_cdec_SparseVector, /*mp_ass_subscript*/ }; @@ -17705,9 +18719,9 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { 0, /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ - __pyx_pw_5_cdec_12SparseVector_14__richcmp__, /*tp_richcompare*/ + __pyx_pw_5_cdec_12SparseVector_16__richcmp__, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_12SparseVector_9__iter__, /*tp_iter*/ + __pyx_pw_5_cdec_12SparseVector_11__iter__, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_5_cdec_SparseVector, /*tp_methods*/ 0, /*tp_members*/ @@ -17717,7 +18731,7 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ - 0, /*tp_init*/ + __pyx_pw_5_cdec_12SparseVector_1__init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_5_cdec_SparseVector, /*tp_new*/ 0, /*tp_free*/ @@ -17733,7 +18747,7 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_NT(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_NT(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; return o; @@ -17743,11 +18757,11 @@ static void __pyx_tp_dealloc_5_cdec_NT(PyObject *o) { (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_getprop_5_cdec_2NT_cat(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_2NT_cat(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_2NT_3cat_1__get__(o); } -static int __pyx_setprop_5_cdec_2NT_cat(PyObject *o, PyObject *v, void *x) { +static int __pyx_setprop_5_cdec_2NT_cat(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { return __pyx_pw_5_cdec_2NT_3cat_3__set__(o, v); } @@ -17757,11 +18771,11 @@ static int __pyx_setprop_5_cdec_2NT_cat(PyObject *o, PyObject *v, void *x) { } } -static PyObject *__pyx_getprop_5_cdec_2NT_ref(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_2NT_ref(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_2NT_3ref_1__get__(o); } -static int __pyx_setprop_5_cdec_2NT_ref(PyObject *o, PyObject *v, void *x) { +static int __pyx_setprop_5_cdec_2NT_ref(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { return __pyx_pw_5_cdec_2NT_3ref_3__set__(o, v); } @@ -17935,7 +18949,7 @@ static PyTypeObject __pyx_type_5_cdec_NT = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_NTRef(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_NTRef(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; return o; @@ -17945,11 +18959,11 @@ static void __pyx_tp_dealloc_5_cdec_NTRef(PyObject *o) { (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_getprop_5_cdec_5NTRef_ref(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_5NTRef_ref(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_5NTRef_3ref_1__get__(o); } -static int __pyx_setprop_5_cdec_5NTRef_ref(PyObject *o, PyObject *v, void *x) { +static int __pyx_setprop_5_cdec_5NTRef_ref(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { return __pyx_pw_5_cdec_5NTRef_3ref_3__set__(o, v); } @@ -18122,18 +19136,18 @@ static PyTypeObject __pyx_type_5_cdec_NTRef = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_BaseTRule(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_TRule(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; return o; } -static void __pyx_tp_dealloc_5_cdec_BaseTRule(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec_TRule(PyObject *o) { { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); - __pyx_pw_5_cdec_9BaseTRule_1__dealloc__(o); + __pyx_pw_5_cdec_5TRule_3__dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); @@ -18141,31 +19155,17 @@ static void __pyx_tp_dealloc_5_cdec_BaseTRule(PyObject *o) { (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_getprop_5_cdec_9BaseTRule_arity(PyObject *o, void *x) { - return __pyx_pw_5_cdec_9BaseTRule_5arity_1__get__(o); -} - -static PyObject *__pyx_getprop_5_cdec_9BaseTRule_f(PyObject *o, void *x) { - return __pyx_pw_5_cdec_9BaseTRule_1f_1__get__(o); -} - -static int __pyx_setprop_5_cdec_9BaseTRule_f(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_5_cdec_9BaseTRule_1f_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } +static PyObject *__pyx_getprop_5_cdec_5TRule_arity(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5_cdec_5TRule_5arity_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_9BaseTRule_e(PyObject *o, void *x) { - return __pyx_pw_5_cdec_9BaseTRule_1e_1__get__(o); +static PyObject *__pyx_getprop_5_cdec_5TRule_f(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5_cdec_5TRule_1f_1__get__(o); } -static int __pyx_setprop_5_cdec_9BaseTRule_e(PyObject *o, PyObject *v, void *x) { +static int __pyx_setprop_5_cdec_5TRule_f(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { - return __pyx_pw_5_cdec_9BaseTRule_1e_3__set__(o, v); + return __pyx_pw_5_cdec_5TRule_1f_3__set__(o, v); } else { PyErr_SetString(PyExc_NotImplementedError, "__del__"); @@ -18173,13 +19173,13 @@ static int __pyx_setprop_5_cdec_9BaseTRule_e(PyObject *o, PyObject *v, void *x) } } -static PyObject *__pyx_getprop_5_cdec_9BaseTRule_a(PyObject *o, void *x) { - return __pyx_pw_5_cdec_9BaseTRule_1a_1__get__(o); +static PyObject *__pyx_getprop_5_cdec_5TRule_e(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5_cdec_5TRule_1e_1__get__(o); } -static int __pyx_setprop_5_cdec_9BaseTRule_a(PyObject *o, PyObject *v, void *x) { +static int __pyx_setprop_5_cdec_5TRule_e(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { - return __pyx_pw_5_cdec_9BaseTRule_1a_4__set__(o, v); + return __pyx_pw_5_cdec_5TRule_1e_3__set__(o, v); } else { PyErr_SetString(PyExc_NotImplementedError, "__del__"); @@ -18187,13 +19187,13 @@ static int __pyx_setprop_5_cdec_9BaseTRule_a(PyObject *o, PyObject *v, void *x) } } -static PyObject *__pyx_getprop_5_cdec_9BaseTRule_scores(PyObject *o, void *x) { - return __pyx_pw_5_cdec_9BaseTRule_6scores_1__get__(o); +static PyObject *__pyx_getprop_5_cdec_5TRule_a(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5_cdec_5TRule_1a_1__get__(o); } -static int __pyx_setprop_5_cdec_9BaseTRule_scores(PyObject *o, PyObject *v, void *x) { +static int __pyx_setprop_5_cdec_5TRule_a(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { - return __pyx_pw_5_cdec_9BaseTRule_6scores_3__set__(o, v); + return __pyx_pw_5_cdec_5TRule_1a_4__set__(o, v); } else { PyErr_SetString(PyExc_NotImplementedError, "__del__"); @@ -18201,201 +19201,48 @@ static int __pyx_setprop_5_cdec_9BaseTRule_scores(PyObject *o, PyObject *v, void } } -static PyObject *__pyx_getprop_5_cdec_9BaseTRule_lhs(PyObject *o, void *x) { - return __pyx_pw_5_cdec_9BaseTRule_3lhs_1__get__(o); +static PyObject *__pyx_getprop_5_cdec_5TRule_scores(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5_cdec_5TRule_6scores_1__get__(o); } -static int __pyx_setprop_5_cdec_9BaseTRule_lhs(PyObject *o, PyObject *v, void *x) { +static int __pyx_setprop_5_cdec_5TRule_scores(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { - return __pyx_pw_5_cdec_9BaseTRule_3lhs_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + return __pyx_pw_5_cdec_5TRule_6scores_3__set__(o, v); } -} - -static PyMethodDef __pyx_methods_5_cdec_BaseTRule[] = { - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_5_cdec_BaseTRule[] = { - {(char *)"arity", __pyx_getprop_5_cdec_9BaseTRule_arity, 0, 0, 0}, - {(char *)"f", __pyx_getprop_5_cdec_9BaseTRule_f, __pyx_setprop_5_cdec_9BaseTRule_f, 0, 0}, - {(char *)"e", __pyx_getprop_5_cdec_9BaseTRule_e, __pyx_setprop_5_cdec_9BaseTRule_e, 0, 0}, - {(char *)"a", __pyx_getprop_5_cdec_9BaseTRule_a, __pyx_setprop_5_cdec_9BaseTRule_a, 0, 0}, - {(char *)"scores", __pyx_getprop_5_cdec_9BaseTRule_scores, __pyx_setprop_5_cdec_9BaseTRule_scores, 0, 0}, - {(char *)"lhs", __pyx_getprop_5_cdec_9BaseTRule_lhs, __pyx_setprop_5_cdec_9BaseTRule_lhs, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_BaseTRule = { - 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_BaseTRule = { - 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_BaseTRule = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_BaseTRule = { - #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_BaseTRule = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.BaseTRule"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_BaseTRule), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_BaseTRule, /*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_BaseTRule, /*tp_as_number*/ - &__pyx_tp_as_sequence_BaseTRule, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_BaseTRule, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - __pyx_pw_5_cdec_9BaseTRule_3__str__, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_BaseTRule, /*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*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_5_cdec_BaseTRule, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_5_cdec_BaseTRule, /*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_BaseTRule, /*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 -}; + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} -static PyObject *__pyx_tp_new_5_cdec_TRule(PyTypeObject *t, PyObject *a, PyObject *k) { - PyObject *o = __pyx_tp_new_5_cdec_BaseTRule(t, a, k); - if (!o) return 0; - if (__pyx_pw_5_cdec_5TRule_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; +static PyObject *__pyx_getprop_5_cdec_5TRule_lhs(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_5_cdec_5TRule_3lhs_1__get__(o); +} + +static int __pyx_setprop_5_cdec_5TRule_lhs(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_5_cdec_5TRule_3lhs_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; } - return o; } static PyMethodDef __pyx_methods_5_cdec_TRule[] = { {0, 0, 0, 0} }; +static struct PyGetSetDef __pyx_getsets_5_cdec_TRule[] = { + {(char *)"arity", __pyx_getprop_5_cdec_5TRule_arity, 0, 0, 0}, + {(char *)"f", __pyx_getprop_5_cdec_5TRule_f, __pyx_setprop_5_cdec_5TRule_f, 0, 0}, + {(char *)"e", __pyx_getprop_5_cdec_5TRule_e, __pyx_setprop_5_cdec_5TRule_e, 0, 0}, + {(char *)"a", __pyx_getprop_5_cdec_5TRule_a, __pyx_setprop_5_cdec_5TRule_a, 0, 0}, + {(char *)"scores", __pyx_getprop_5_cdec_5TRule_scores, __pyx_setprop_5_cdec_5TRule_scores, 0, 0}, + {(char *)"lhs", __pyx_getprop_5_cdec_5TRule_lhs, __pyx_setprop_5_cdec_5TRule_lhs, 0, 0}, + {0, 0, 0, 0, 0} +}; + static PyNumberMethods __pyx_tp_as_number_TRule = { 0, /*nb_add*/ 0, /*nb_subtract*/ @@ -18499,7 +19346,7 @@ static PyTypeObject __pyx_type_5_cdec_TRule = { __Pyx_NAMESTR("_cdec.TRule"), /*tp_name*/ sizeof(struct __pyx_obj_5_cdec_TRule), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_BaseTRule, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_TRule, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -18514,7 +19361,7 @@ static PyTypeObject __pyx_type_5_cdec_TRule = { &__pyx_tp_as_mapping_TRule, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ - 0, /*tp_str*/ + __pyx_pw_5_cdec_5TRule_5__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_TRule, /*tp_as_buffer*/ @@ -18528,13 +19375,13 @@ static PyTypeObject __pyx_type_5_cdec_TRule = { 0, /*tp_iternext*/ __pyx_methods_5_cdec_TRule, /*tp_methods*/ 0, /*tp_members*/ - 0, /*tp_getset*/ + __pyx_getsets_5_cdec_TRule, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ - 0, /*tp_init*/ + __pyx_pw_5_cdec_5TRule_1__init__, /*tp_init*/ 0, /*tp_alloc*/ __pyx_tp_new_5_cdec_TRule, /*tp_new*/ 0, /*tp_free*/ @@ -18550,7 +19397,7 @@ static PyTypeObject __pyx_type_5_cdec_TRule = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Grammar(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_Grammar(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; return o; @@ -18569,11 +19416,11 @@ static void __pyx_tp_dealloc_5_cdec_Grammar(PyObject *o) { (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_getprop_5_cdec_7Grammar_name(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_7Grammar_name(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_7Grammar_4name_1__get__(o); } -static int __pyx_setprop_5_cdec_7Grammar_name(PyObject *o, PyObject *v, void *x) { +static int __pyx_setprop_5_cdec_7Grammar_name(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { return __pyx_pw_5_cdec_7Grammar_4name_3__set__(o, v); } @@ -18887,7 +19734,11 @@ static PyTypeObject __pyx_type_5_cdec_TextGrammar = { 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5_cdec_7Grammar_3__iter__, /*tp_iter*/ + #else 0, /*tp_iter*/ + #endif 0, /*tp_iternext*/ __pyx_methods_5_cdec_TextGrammar, /*tp_methods*/ 0, /*tp_members*/ @@ -18913,7 +19764,7 @@ static PyTypeObject __pyx_type_5_cdec_TextGrammar = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Hypergraph(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_Hypergraph(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; return o; @@ -18932,19 +19783,19 @@ static void __pyx_tp_dealloc_5_cdec_Hypergraph(PyObject *o) { (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_getprop_5_cdec_10Hypergraph_edges(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_10Hypergraph_edges(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_10Hypergraph_5edges_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_10Hypergraph_nodes(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_10Hypergraph_nodes(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_10Hypergraph_5nodes_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_10Hypergraph_goal(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_10Hypergraph_goal(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_10Hypergraph_4goal_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_10Hypergraph_npaths(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_10Hypergraph_npaths(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_10Hypergraph_6npaths_1__get__(o); } @@ -19128,13 +19979,13 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { }; static struct __pyx_vtabstruct_5_cdec_HypergraphEdge __pyx_vtable_5_cdec_HypergraphEdge; -static PyObject *__pyx_tp_new_5_cdec_HypergraphEdge(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_HypergraphEdge(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec_HypergraphEdge *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; p = ((struct __pyx_obj_5_cdec_HypergraphEdge *)o); p->__pyx_vtab = __pyx_vtabptr_5_cdec_HypergraphEdge; - p->trule = ((struct __pyx_obj_5_cdec_BaseTRule *)Py_None); Py_INCREF(Py_None); + p->trule = ((struct __pyx_obj_5_cdec_TRule *)Py_None); Py_INCREF(Py_None); return o; } @@ -19157,36 +20008,36 @@ static int __pyx_tp_clear_5_cdec_HypergraphEdge(PyObject *o) { struct __pyx_obj_5_cdec_HypergraphEdge *p = (struct __pyx_obj_5_cdec_HypergraphEdge *)o; PyObject* tmp; tmp = ((PyObject*)p->trule); - p->trule = ((struct __pyx_obj_5_cdec_BaseTRule *)Py_None); Py_INCREF(Py_None); + p->trule = ((struct __pyx_obj_5_cdec_TRule *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_head_node(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_head_node(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_14HypergraphEdge_9head_node_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_tail_nodes(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_tail_nodes(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_14HypergraphEdge_10tail_nodes_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_span(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_span(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_14HypergraphEdge_4span_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_feature_values(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_feature_values(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_14HypergraphEdge_14feature_values_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_prob(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_prob(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_14HypergraphEdge_4prob_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_trule(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_14HypergraphEdge_trule(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_14HypergraphEdge_5trule_1__get__(o); } -static int __pyx_setprop_5_cdec_14HypergraphEdge_trule(PyObject *o, PyObject *v, void *x) { +static int __pyx_setprop_5_cdec_14HypergraphEdge_trule(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { return __pyx_pw_5_cdec_14HypergraphEdge_5trule_3__set__(o, v); } @@ -19364,7 +20215,7 @@ static PyTypeObject __pyx_type_5_cdec_HypergraphEdge = { }; static struct __pyx_vtabstruct_5_cdec_HypergraphNode __pyx_vtable_5_cdec_HypergraphNode; -static PyObject *__pyx_tp_new_5_cdec_HypergraphNode(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_HypergraphNode(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec_HypergraphNode *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -19377,19 +20228,19 @@ static void __pyx_tp_dealloc_5_cdec_HypergraphNode(PyObject *o) { (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_in_edges(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_in_edges(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_14HypergraphNode_8in_edges_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_out_edges(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_out_edges(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_14HypergraphNode_9out_edges_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_span(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_span(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_14HypergraphNode_4span_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_cat(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_14HypergraphNode_cat(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_14HypergraphNode_3cat_1__get__(o); } @@ -19573,7 +20424,7 @@ static void __pyx_tp_dealloc_5_cdec_Lattice(PyObject *o) { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); - __pyx_pw_5_cdec_7Lattice_14__dealloc__(o); + __pyx_pw_5_cdec_7Lattice_3__dealloc__(o); if (PyErr_Occurred()) PyErr_WriteUnraisable(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); @@ -19590,7 +20441,7 @@ static PyObject *__pyx_sq_item_5_cdec_Lattice(PyObject *o, Py_ssize_t i) { static int __pyx_mp_ass_subscript_5_cdec_Lattice(PyObject *o, PyObject *i, PyObject *v) { if (v) { - return __pyx_pw_5_cdec_7Lattice_5__setitem__(o, i, v); + return __pyx_pw_5_cdec_7Lattice_7__setitem__(o, i, v); } else { PyErr_Format(PyExc_NotImplementedError, @@ -19663,7 +20514,7 @@ static PyNumberMethods __pyx_tp_as_number_Lattice = { }; static PySequenceMethods __pyx_tp_as_sequence_Lattice = { - __pyx_pw_5_cdec_7Lattice_7__len__, /*sq_length*/ + __pyx_pw_5_cdec_7Lattice_9__len__, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ __pyx_sq_item_5_cdec_Lattice, /*sq_item*/ @@ -19676,8 +20527,8 @@ static PySequenceMethods __pyx_tp_as_sequence_Lattice = { }; static PyMappingMethods __pyx_tp_as_mapping_Lattice = { - __pyx_pw_5_cdec_7Lattice_7__len__, /*mp_length*/ - __pyx_pw_5_cdec_7Lattice_3__getitem__, /*mp_subscript*/ + __pyx_pw_5_cdec_7Lattice_9__len__, /*mp_length*/ + __pyx_pw_5_cdec_7Lattice_5__getitem__, /*mp_subscript*/ __pyx_mp_ass_subscript_5_cdec_Lattice, /*mp_ass_subscript*/ }; @@ -19722,7 +20573,7 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { &__pyx_tp_as_mapping_Lattice, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ - __pyx_pw_5_cdec_7Lattice_9__str__, /*tp_str*/ + __pyx_pw_5_cdec_7Lattice_11__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_Lattice, /*tp_as_buffer*/ @@ -19732,7 +20583,7 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_7Lattice_11__iter__, /*tp_iter*/ + __pyx_pw_5_cdec_7Lattice_13__iter__, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_5_cdec_Lattice, /*tp_methods*/ 0, /*tp_members*/ @@ -19758,7 +20609,7 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Candidate(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_Candidate(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; return o; @@ -19768,19 +20619,19 @@ static void __pyx_tp_dealloc_5_cdec_Candidate(PyObject *o) { (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_getprop_5_cdec_9Candidate_words(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_9Candidate_words(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_9Candidate_5words_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_9Candidate_fmap(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_9Candidate_fmap(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_9Candidate_4fmap_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_9Candidate_score(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_9Candidate_score(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_9Candidate_5score_1__get__(o); } -static int __pyx_setprop_5_cdec_9Candidate_score(PyObject *o, PyObject *v, void *x) { +static int __pyx_setprop_5_cdec_9Candidate_score(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { return __pyx_pw_5_cdec_9Candidate_5score_3__set__(o, v); } @@ -19955,7 +20806,7 @@ static PyTypeObject __pyx_type_5_cdec_Candidate = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_SufficientStats(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_SufficientStats(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; return o; @@ -19981,11 +20832,11 @@ static PyObject *__pyx_sq_item_5_cdec_SufficientStats(PyObject *o, Py_ssize_t i) return r; } -static PyObject *__pyx_getprop_5_cdec_15SufficientStats_score(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_15SufficientStats_score(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_15SufficientStats_5score_1__get__(o); } -static PyObject *__pyx_getprop_5_cdec_15SufficientStats_detail(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_15SufficientStats_detail(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(o); } @@ -20341,7 +21192,7 @@ static PyTypeObject __pyx_type_5_cdec_CandidateSet = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_SegmentEvaluator(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_SegmentEvaluator(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; return o; @@ -20700,7 +21551,7 @@ static PyTypeObject __pyx_type_5_cdec_Scorer = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Metric(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_Metric(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec_Metric *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -20941,11 +21792,11 @@ static int __pyx_tp_clear_5_cdec_Decoder(PyObject *o) { return 0; } -static PyObject *__pyx_getprop_5_cdec_7Decoder_weights(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_7Decoder_weights(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_7Decoder_7weights_1__get__(o); } -static int __pyx_setprop_5_cdec_7Decoder_weights(PyObject *o, PyObject *v, void *x) { +static int __pyx_setprop_5_cdec_7Decoder_weights(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { if (v) { return __pyx_pw_5_cdec_7Decoder_7weights_3__set__(o, v); } @@ -20955,7 +21806,7 @@ static int __pyx_setprop_5_cdec_7Decoder_weights(PyObject *o, PyObject *v, void } } -static PyObject *__pyx_getprop_5_cdec_7Decoder_formalism(PyObject *o, void *x) { +static PyObject *__pyx_getprop_5_cdec_7Decoder_formalism(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_7Decoder_9formalism_1__get__(o); } @@ -21125,7 +21976,7 @@ static PyTypeObject __pyx_type_5_cdec_Decoder = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct____iter__(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct____iter__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -21316,7 +22167,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -21507,7 +22358,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_2__phrase(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_2__phrase(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_2__phrase *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -21698,7 +22549,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2__phrase = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_3_genexpr(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_3_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_3_genexpr *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -21905,7 +22756,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_genexpr = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_4___get__(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_4___get__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -21933,7 +22784,7 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_4___get__(PyObject *o) { struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4___get__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_BaseTRule *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_TRule *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } @@ -22096,7 +22947,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4___get__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_5___str__(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_5___str__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -22124,7 +22975,7 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_5___str__(PyObject *o) { struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5___str__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_BaseTRule *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_TRule *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } @@ -22287,7 +23138,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5___str__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_6_genexpr(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_6_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -22494,7 +23345,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_6_genexpr = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_7___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_7___iter__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -22693,7 +23544,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7___iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_8_kbest(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_8_kbest(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_8_kbest *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -22892,7 +23743,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8_kbest = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_9_kbest_trees(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_9_kbest_trees(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_9_kbest_trees *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -23107,7 +23958,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_9_kbest_trees = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_10_kbest_features(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_10_kbest_features(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_10_kbest_features *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -23314,7 +24165,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_10_kbest_features = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_11_sample(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_11_sample(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_11_sample *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -23505,7 +24356,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_11_sample = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_12___get__(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_12___get__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_12___get__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -23696,7 +24547,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_12___get__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_13___get__(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_13___get__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_13___get__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -23887,7 +24738,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_13___get__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_14___get__(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_14___get__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -24078,7 +24929,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_14___get__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_15___get__(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_15___get__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_15___get__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -24269,7 +25120,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_15___get__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_16___get__(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_16___get__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_16___get__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -24460,7 +25311,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_16___get__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_17___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_17___iter__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_17___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -24651,7 +25502,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_17___iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_18_todot(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_18_todot(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_18_todot *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -24842,7 +25693,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_18_todot = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_19_lines(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_19_lines(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_19_lines *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -25081,7 +25932,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_19_lines = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_20___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_20___iter__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -25288,7 +26139,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_20___iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_21___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_21___iter__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_21___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -25479,7 +26330,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_21___iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_22__make_config(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_22__make_config(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -25718,7 +26569,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_22__make_config = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_23___cinit__(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_23___cinit__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_23___cinit__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -25909,7 +26760,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_23___cinit__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_24_genexpr(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_24_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { struct __pyx_obj_5_cdec___pyx_scope_struct_24_genexpr *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -26135,7 +26986,6 @@ static struct PyModuleDef __pyx_moduledef = { #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0}, {&__pyx_kp_s_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 1, 0}, {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0}, {&__pyx_kp_s_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 0, 1, 0}, @@ -26166,8 +27016,10 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_49, __pyx_k_49, sizeof(__pyx_k_49), 0, 0, 1, 0}, {&__pyx_kp_s_50, __pyx_k_50, sizeof(__pyx_k_50), 0, 0, 1, 0}, {&__pyx_kp_s_53, __pyx_k_53, sizeof(__pyx_k_53), 0, 0, 1, 0}, - {&__pyx_kp_s_56, __pyx_k_56, sizeof(__pyx_k_56), 0, 0, 1, 0}, - {&__pyx_kp_s_62, __pyx_k_62, sizeof(__pyx_k_62), 0, 0, 1, 0}, + {&__pyx_n_s_54, __pyx_k_54, sizeof(__pyx_k_54), 0, 0, 1, 1}, + {&__pyx_n_s_55, __pyx_k_55, sizeof(__pyx_k_55), 0, 0, 1, 1}, + {&__pyx_kp_s_58, __pyx_k_58, sizeof(__pyx_k_58), 0, 0, 1, 0}, + {&__pyx_kp_s_64, __pyx_k_64, sizeof(__pyx_k_64), 0, 0, 1, 0}, {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0}, {&__pyx_kp_s_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 1, 0}, {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0}, @@ -26180,6 +27032,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1}, {&__pyx_n_s__NotImplemented, __pyx_k__NotImplemented, sizeof(__pyx_k__NotImplemented), 0, 0, 1, 1}, {&__pyx_n_s__ParseFailed, __pyx_k__ParseFailed, sizeof(__pyx_k__ParseFailed), 0, 0, 1, 1}, + {&__pyx_n_s__PhraseModel_, __pyx_k__PhraseModel_, sizeof(__pyx_k__PhraseModel_), 0, 0, 1, 1}, {&__pyx_n_s__TER, __pyx_k__TER, sizeof(__pyx_k__TER), 0, 0, 1, 1}, {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1}, {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, @@ -26192,6 +27045,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s___cdec, __pyx_k___cdec, sizeof(__pyx_k___cdec), 0, 0, 1, 1}, {&__pyx_n_s___make_config, __pyx_k___make_config, sizeof(__pyx_k___make_config), 0, 0, 1, 1}, {&__pyx_n_s___phrase, __pyx_k___phrase, sizeof(__pyx_k___phrase), 0, 0, 1, 1}, + {&__pyx_n_s___sa, __pyx_k___sa, sizeof(__pyx_k___sa), 0, 0, 1, 1}, {&__pyx_n_s__a, __pyx_k__a, sizeof(__pyx_k__a), 0, 0, 1, 1}, {&__pyx_n_s__beam_alpha, __pyx_k__beam_alpha, sizeof(__pyx_k__beam_alpha), 0, 0, 1, 1}, {&__pyx_n_s__cat, __pyx_k__cat, sizeof(__pyx_k__cat), 0, 0, 1, 1}, @@ -26210,6 +27064,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__evaluator, __pyx_k__evaluator, sizeof(__pyx_k__evaluator), 0, 0, 1, 1}, {&__pyx_n_s__f, __pyx_k__f, sizeof(__pyx_k__f), 0, 0, 1, 1}, {&__pyx_n_s__formalism, __pyx_k__formalism, sizeof(__pyx_k__formalism), 0, 0, 1, 1}, + {&__pyx_n_s__format, __pyx_k__format, sizeof(__pyx_k__format), 0, 0, 1, 1}, {&__pyx_n_s__fst, __pyx_k__fst, sizeof(__pyx_k__fst), 0, 0, 1, 1}, {&__pyx_n_s__genexpr, __pyx_k__genexpr, sizeof(__pyx_k__genexpr), 0, 0, 1, 1}, {&__pyx_n_s__get, __pyx_k__get, sizeof(__pyx_k__get), 0, 0, 1, 1}, @@ -26257,14 +27112,14 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { 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 = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __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[1]; __pyx_lineno = 13; __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[1]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_NotImplemented = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplemented); if (!__pyx_builtin_NotImplemented) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __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[1]; __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[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_NotImplemented = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplemented); if (!__pyx_builtin_NotImplemented) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 200; __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[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 21; __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 = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __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 = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; return -1; @@ -26288,41 +27143,41 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2)); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":77 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":89 * elif op == 3: # != * return not (x == y) * raise NotImplemented('comparison not implemented for SparseVector') # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_5); __Pyx_INCREF(((PyObject *)__pyx_kp_s_4)); PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_kp_s_4)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_4)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5)); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":4 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":6 * * def _phrase(phrase): * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) # <<<<<<<<<<<<<< * * cdef class NT: */ - __pyx_k_tuple_6 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_6 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_6); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); PyTuple_SET_ITEM(__pyx_k_tuple_6, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_6)); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":175 - * for trule in rules: - * if not isinstance(trule, BaseTRule): + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":200 + * trule = convert_rule(trule) + * elif not isinstance(trule, TRule): * raise ValueError('the grammar should contain TRule objects') # <<<<<<<<<<<<<< - * _g.AddRule(( trule).rule[0]) + * _g.AddRule(( trule).rule[0]) */ - __pyx_k_tuple_14 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_14)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_14 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_14)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_14); __Pyx_INCREF(((PyObject *)__pyx_kp_s_13)); PyTuple_SET_ITEM(__pyx_k_tuple_14, 0, ((PyObject *)__pyx_kp_s_13)); @@ -26369,42 +27224,42 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21)); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":21 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":24 * def __getitem__(self, int index): * if not 0 <= index < len(self): * raise IndexError('lattice index out of range') # <<<<<<<<<<<<<< * arcs = [] * cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index] */ - __pyx_k_tuple_24 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_24 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_24); __Pyx_INCREF(((PyObject *)__pyx_kp_s_23)); PyTuple_SET_ITEM(__pyx_k_tuple_24, 0, ((PyObject *)__pyx_kp_s_23)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_23)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_24)); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":34 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":37 * def __setitem__(self, int index, tuple arcs): * if not 0 <= index < len(self): * raise IndexError('lattice index out of range') # <<<<<<<<<<<<<< * cdef lattice.LatticeArc* arc * for (label, cost, dist2next) in arcs: */ - __pyx_k_tuple_25 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_25 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_25); __Pyx_INCREF(((PyObject *)__pyx_kp_s_23)); PyTuple_SET_ITEM(__pyx_k_tuple_25, 0, ((PyObject *)__pyx_kp_s_23)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_23)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_25)); - /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":38 + /* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":41 * for (label, cost, dist2next) in arcs: * if isinstance(label, unicode): * label = label.encode('utf8') # <<<<<<<<<<<<<< * arc = new lattice.LatticeArc(TDConvert(label), cost, dist2next) * self.lattice[0][index].push_back(arc[0]) */ - __pyx_k_tuple_26 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_26)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_26 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_26)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_26); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); PyTuple_SET_ITEM(__pyx_k_tuple_26, 0, ((PyObject *)__pyx_n_s__utf8)); @@ -26509,28 +27364,28 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(Py_None); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_47)); - /* "_cdec.pyx":88 + /* "_cdec.pyx":90 * with open(weights) as fp: * for line in fp: * if line.strip().startswith('#'): continue # <<<<<<<<<<<<<< * fname, value = line.split() * self.weights[fname.strip()] = float(value) */ - __pyx_k_tuple_51 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_51)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_51 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_51)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_51); __Pyx_INCREF(((PyObject *)__pyx_kp_s_50)); PyTuple_SET_ITEM(__pyx_k_tuple_51, 0, ((PyObject *)__pyx_kp_s_50)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_50)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_51)); - /* "_cdec.pyx":86 + /* "_cdec.pyx":88 * * def read_weights(self, weights): * with open(weights) as fp: # <<<<<<<<<<<<<< * for line in fp: * if line.strip().startswith('#'): continue */ - __pyx_k_tuple_52 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_52 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_52); __Pyx_INCREF(Py_None); PyTuple_SET_ITEM(__pyx_k_tuple_52, 0, Py_None); @@ -26543,26 +27398,26 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(Py_None); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_52)); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":3 - * cimport grammar + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":5 + * import cdec.sa._sa as _sa * * def _phrase(phrase): # <<<<<<<<<<<<<< * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) * */ - __pyx_k_tuple_54 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_54)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_54); + __pyx_k_tuple_56 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_56)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_56); __Pyx_INCREF(((PyObject *)__pyx_n_s__phrase)); - PyTuple_SET_ITEM(__pyx_k_tuple_54, 0, ((PyObject *)__pyx_n_s__phrase)); + PyTuple_SET_ITEM(__pyx_k_tuple_56, 0, ((PyObject *)__pyx_n_s__phrase)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__phrase)); __Pyx_INCREF(((PyObject *)__pyx_n_s__genexpr)); - PyTuple_SET_ITEM(__pyx_k_tuple_54, 1, ((PyObject *)__pyx_n_s__genexpr)); + PyTuple_SET_ITEM(__pyx_k_tuple_56, 1, ((PyObject *)__pyx_n_s__genexpr)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__genexpr)); __Pyx_INCREF(((PyObject *)__pyx_n_s__genexpr)); - PyTuple_SET_ITEM(__pyx_k_tuple_54, 2, ((PyObject *)__pyx_n_s__genexpr)); + PyTuple_SET_ITEM(__pyx_k_tuple_56, 2, ((PyObject *)__pyx_n_s__genexpr)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__genexpr)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_54)); - __pyx_k_codeobj_55 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_54, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_56, __pyx_n_s___phrase, 3, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_55)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_56)); + __pyx_k_codeobj_57 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_56, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_58, __pyx_n_s___phrase, 5, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_57)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":190 * return [] @@ -26571,12 +27426,12 @@ static int __Pyx_InitCachedConstants(void) { * TER = Scorer('TER') * CER = Scorer('CER') */ - __pyx_k_tuple_57 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_57)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_57); + __pyx_k_tuple_59 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_59)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_59); __Pyx_INCREF(((PyObject *)__pyx_n_s__IBM_BLEU)); - PyTuple_SET_ITEM(__pyx_k_tuple_57, 0, ((PyObject *)__pyx_n_s__IBM_BLEU)); + PyTuple_SET_ITEM(__pyx_k_tuple_59, 0, ((PyObject *)__pyx_n_s__IBM_BLEU)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IBM_BLEU)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_57)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_59)); /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":191 * @@ -26584,24 +27439,24 @@ static int __Pyx_InitCachedConstants(void) { * TER = Scorer('TER') # <<<<<<<<<<<<<< * CER = Scorer('CER') */ - __pyx_k_tuple_58 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_58)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_58); + __pyx_k_tuple_60 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_60)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_60); __Pyx_INCREF(((PyObject *)__pyx_n_s__TER)); - PyTuple_SET_ITEM(__pyx_k_tuple_58, 0, ((PyObject *)__pyx_n_s__TER)); + PyTuple_SET_ITEM(__pyx_k_tuple_60, 0, ((PyObject *)__pyx_n_s__TER)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__TER)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_58)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_60)); /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":192 * BLEU = Scorer('IBM_BLEU') * TER = Scorer('TER') * CER = Scorer('CER') # <<<<<<<<<<<<<< */ - __pyx_k_tuple_59 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_59)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_59); + __pyx_k_tuple_61 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_61)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_61); __Pyx_INCREF(((PyObject *)__pyx_n_s__CER)); - PyTuple_SET_ITEM(__pyx_k_tuple_59, 0, ((PyObject *)__pyx_n_s__CER)); + PyTuple_SET_ITEM(__pyx_k_tuple_61, 0, ((PyObject *)__pyx_n_s__CER)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__CER)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_59)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_61)); /* "_cdec.pyx":28 * class ParseFailed(Exception): pass @@ -26610,25 +27465,25 @@ static int __Pyx_InitCachedConstants(void) { * for key, value in config.items(): * if isinstance(value, dict): */ - __pyx_k_tuple_60 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_60)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_60); + __pyx_k_tuple_62 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_62)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_62); __Pyx_INCREF(((PyObject *)__pyx_n_s__config)); - PyTuple_SET_ITEM(__pyx_k_tuple_60, 0, ((PyObject *)__pyx_n_s__config)); + PyTuple_SET_ITEM(__pyx_k_tuple_62, 0, ((PyObject *)__pyx_n_s__config)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__config)); __Pyx_INCREF(((PyObject *)__pyx_n_s__key)); - PyTuple_SET_ITEM(__pyx_k_tuple_60, 1, ((PyObject *)__pyx_n_s__key)); + PyTuple_SET_ITEM(__pyx_k_tuple_62, 1, ((PyObject *)__pyx_n_s__key)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__key)); __Pyx_INCREF(((PyObject *)__pyx_n_s__value)); - PyTuple_SET_ITEM(__pyx_k_tuple_60, 2, ((PyObject *)__pyx_n_s__value)); + PyTuple_SET_ITEM(__pyx_k_tuple_62, 2, ((PyObject *)__pyx_n_s__value)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__value)); __Pyx_INCREF(((PyObject *)__pyx_n_s__name)); - PyTuple_SET_ITEM(__pyx_k_tuple_60, 3, ((PyObject *)__pyx_n_s__name)); + PyTuple_SET_ITEM(__pyx_k_tuple_62, 3, ((PyObject *)__pyx_n_s__name)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__name)); __Pyx_INCREF(((PyObject *)__pyx_n_s__info)); - PyTuple_SET_ITEM(__pyx_k_tuple_60, 4, ((PyObject *)__pyx_n_s__info)); + PyTuple_SET_ITEM(__pyx_k_tuple_62, 4, ((PyObject *)__pyx_n_s__info)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__info)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_60)); - __pyx_k_codeobj_61 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_60, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_62, __pyx_n_s___make_config, 28, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_61)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_62)); + __pyx_k_codeobj_63 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_62, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_64, __pyx_n_s___make_config, 28, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_63)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -26640,6 +27495,7 @@ static int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_65536 = PyInt_FromLong(65536); if (unlikely(!__pyx_int_65536)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; return 0; __pyx_L1_error:; return -1; @@ -26656,6 +27512,7 @@ PyMODINIT_FUNC PyInit__cdec(void) PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; __Pyx_RefNannyDeclarations #if CYTHON_REFNANNY __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); @@ -26698,6 +27555,9 @@ PyMODINIT_FUNC PyInit__cdec(void) #endif __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #if CYTHON_COMPILING_IN_PYPY + Py_INCREF(__pyx_b); + #endif if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; /*--- Initialize various global constants etc. ---*/ if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -26715,28 +27575,24 @@ PyMODINIT_FUNC PyInit__cdec(void) if (PyType_Ready(&__pyx_type_5_cdec_DenseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "DenseVector", (PyObject *)&__pyx_type_5_cdec_DenseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_DenseVector = &__pyx_type_5_cdec_DenseVector; - if (PyType_Ready(&__pyx_type_5_cdec_SparseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "SparseVector", (PyObject *)&__pyx_type_5_cdec_SparseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_SparseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "SparseVector", (PyObject *)&__pyx_type_5_cdec_SparseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_SparseVector = &__pyx_type_5_cdec_SparseVector; - if (PyType_Ready(&__pyx_type_5_cdec_NT) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "NT", (PyObject *)&__pyx_type_5_cdec_NT) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_NT) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "NT", (PyObject *)&__pyx_type_5_cdec_NT) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_NT = &__pyx_type_5_cdec_NT; - if (PyType_Ready(&__pyx_type_5_cdec_NTRef) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "NTRef", (PyObject *)&__pyx_type_5_cdec_NTRef) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_NTRef) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "NTRef", (PyObject *)&__pyx_type_5_cdec_NTRef) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_NTRef = &__pyx_type_5_cdec_NTRef; - if (PyType_Ready(&__pyx_type_5_cdec_BaseTRule) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "BaseTRule", (PyObject *)&__pyx_type_5_cdec_BaseTRule) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec_BaseTRule = &__pyx_type_5_cdec_BaseTRule; - __pyx_type_5_cdec_TRule.tp_base = __pyx_ptype_5_cdec_BaseTRule; - if (PyType_Ready(&__pyx_type_5_cdec_TRule) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "TRule", (PyObject *)&__pyx_type_5_cdec_TRule) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_TRule) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "TRule", (PyObject *)&__pyx_type_5_cdec_TRule) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_TRule = &__pyx_type_5_cdec_TRule; - if (PyType_Ready(&__pyx_type_5_cdec_Grammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Grammar", (PyObject *)&__pyx_type_5_cdec_Grammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_Grammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Grammar", (PyObject *)&__pyx_type_5_cdec_Grammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Grammar = &__pyx_type_5_cdec_Grammar; __pyx_type_5_cdec_TextGrammar.tp_base = __pyx_ptype_5_cdec_Grammar; - if (PyType_Ready(&__pyx_type_5_cdec_TextGrammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "TextGrammar", (PyObject *)&__pyx_type_5_cdec_TextGrammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_TextGrammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "TextGrammar", (PyObject *)&__pyx_type_5_cdec_TextGrammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_TextGrammar = &__pyx_type_5_cdec_TextGrammar; if (PyType_Ready(&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Hypergraph", (PyObject *)&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -26777,21 +27633,21 @@ PyMODINIT_FUNC PyInit__cdec(void) if (PyType_Ready(&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __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 = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Decoder = &__pyx_type_5_cdec_Decoder; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct____iter__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct____iter__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct____iter__ = &__pyx_type_5_cdec___pyx_scope_struct____iter__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_1___iter__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_1___iter__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_1___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_1___iter__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_2__phrase) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_2__phrase) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_2__phrase = &__pyx_type_5_cdec___pyx_scope_struct_2__phrase; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_3_genexpr) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_3_genexpr) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_3_genexpr = &__pyx_type_5_cdec___pyx_scope_struct_3_genexpr; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_4___get__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_4___get__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_4___get__ = &__pyx_type_5_cdec___pyx_scope_struct_4___get__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_5___str__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_5___str__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_5___str__ = &__pyx_type_5_cdec___pyx_scope_struct_5___str__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_6_genexpr) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_6_genexpr) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_6_genexpr = &__pyx_type_5_cdec___pyx_scope_struct_6_genexpr; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_7___iter__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_7___iter__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_7___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_7___iter__; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_8_kbest) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_8_kbest = &__pyx_type_5_cdec___pyx_scope_struct_8_kbest; @@ -26811,7 +27667,7 @@ PyMODINIT_FUNC PyInit__cdec(void) __pyx_ptype_5_cdec___pyx_scope_struct_15___get__ = &__pyx_type_5_cdec___pyx_scope_struct_15___get__; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_16___get__) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_16___get__ = &__pyx_type_5_cdec___pyx_scope_struct_16___get__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_17___iter__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_17___iter__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_17___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_17___iter__; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_18_todot) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_18_todot = &__pyx_type_5_cdec___pyx_scope_struct_18_todot; @@ -26828,21 +27684,48 @@ PyMODINIT_FUNC PyInit__cdec(void) if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_24_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_24_genexpr = &__pyx_type_5_cdec___pyx_scope_struct_24_genexpr; /*--- Type import code ---*/ + __pyx_ptype_4cdec_2sa_3_sa_Phrase = __Pyx_ImportType("cdec.sa._sa", "Phrase", sizeof(struct __pyx_obj_4cdec_2sa_3_sa_Phrase), 1); if (unlikely(!__pyx_ptype_4cdec_2sa_3_sa_Phrase)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_vtabptr_4cdec_2sa_3_sa_Phrase = (struct __pyx_vtabstruct_4cdec_2sa_3_sa_Phrase*)__Pyx_GetVtable(__pyx_ptype_4cdec_2sa_3_sa_Phrase->tp_dict); if (unlikely(!__pyx_vtabptr_4cdec_2sa_3_sa_Phrase)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_4cdec_2sa_3_sa_Rule = __Pyx_ImportType("cdec.sa._sa", "Rule", sizeof(struct __pyx_obj_4cdec_2sa_3_sa_Rule), 1); if (unlikely(!__pyx_ptype_4cdec_2sa_3_sa_Rule)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Variable import code ---*/ /*--- Function import code ---*/ + __pyx_t_1 = __Pyx_ImportModule("cdec.sa._sa"); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_ImportFunction(__pyx_t_1, "sym_tostring", (void (**)(void))&__pyx_f_4cdec_2sa_3_sa_sym_tostring, "char *(int)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_ImportFunction(__pyx_t_1, "sym_tocat", (void (**)(void))&__pyx_f_4cdec_2sa_3_sa_sym_tocat, "char *(int)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_ImportFunction(__pyx_t_1, "sym_isvar", (void (**)(void))&__pyx_f_4cdec_2sa_3_sa_sym_isvar, "int (int)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_ImportFunction(__pyx_t_1, "sym_getindex", (void (**)(void))&__pyx_f_4cdec_2sa_3_sa_sym_getindex, "int (int)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + Py_DECREF(__pyx_t_1); __pyx_t_1 = 0; /*--- Execution code ---*/ /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":3 * cimport grammar + * cimport cdec.sa._sa as _sa + * import cdec.sa._sa as _sa # <<<<<<<<<<<<<< + * + * def _phrase(phrase): + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_n_s_55)); + PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_n_s_55)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s_55)); + __pyx_t_3 = __Pyx_Import(((PyObject *)__pyx_n_s_54), ((PyObject *)__pyx_t_2), -1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 3; __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___sa, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":5 + * import cdec.sa._sa as _sa * * def _phrase(phrase): # <<<<<<<<<<<<<< * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) * */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5_cdec_1_phrase, NULL, __pyx_n_s___cdec); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s___phrase, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_5_cdec_1_phrase, NULL, __pyx_n_s___cdec); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s___phrase, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":190 * return [] @@ -26851,10 +27734,10 @@ PyMODINIT_FUNC PyInit__cdec(void) * TER = Scorer('TER') * CER = Scorer('CER') */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_57), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_59), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":191 * @@ -26862,20 +27745,20 @@ PyMODINIT_FUNC PyInit__cdec(void) * TER = Scorer('TER') # <<<<<<<<<<<<<< * CER = Scorer('CER') */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_58), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_60), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":192 * BLEU = Scorer('IBM_BLEU') * TER = Scorer('TER') * CER = Scorer('CER') # <<<<<<<<<<<<<< */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_59), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__CER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_61), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__CER, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "_cdec.pyx":22 * include "mteval.pxi" @@ -26902,19 +27785,19 @@ PyMODINIT_FUNC PyInit__cdec(void) * class ParseFailed(Exception): pass * */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_3 = PyDict_New(); 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)); __pyx_t_2 = PyTuple_New(1); 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_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__InvalidConfig, __pyx_n_s___cdec); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_CreateClass(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_3), __pyx_n_s__InvalidConfig, __pyx_n_s___cdec); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__InvalidConfig, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __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; + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__InvalidConfig, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; /* "_cdec.pyx":26 * @@ -26923,19 +27806,19 @@ PyMODINIT_FUNC PyInit__cdec(void) * * def _make_config(config): */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); + __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_builtin_Exception); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_builtin_Exception); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_builtin_Exception); __Pyx_GIVEREF(__pyx_builtin_Exception); - __pyx_t_2 = __Pyx_CreateClass(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_1), __pyx_n_s__ParseFailed, __pyx_n_s___cdec); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_CreateClass(((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_3), __pyx_n_s__ParseFailed, __pyx_n_s___cdec); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; if (PyObject_SetAttr(__pyx_m, __pyx_n_s__ParseFailed, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; /* "_cdec.pyx":28 * class ParseFailed(Exception): pass @@ -26944,25 +27827,34 @@ PyMODINIT_FUNC PyInit__cdec(void) * for key, value in config.items(): * if isinstance(value, dict): */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5_cdec_3_make_config, NULL, __pyx_n_s___cdec); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s___make_config, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_5_cdec_3_make_config, NULL, __pyx_n_s___cdec); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s___make_config, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* "_cdec.pyx":1 * from libcpp.string cimport string # <<<<<<<<<<<<<< * from libcpp.vector cimport vector * from utils cimport * */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __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)); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + + /* "string.to_py":25 + * + * @cname("__pyx_convert_string_to_py_") + * cdef object __pyx_convert_string_to_py_(string& s): # <<<<<<<<<<<<<< + * return s.data()[:s.size()] + * + */ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); if (__pyx_m) { __Pyx_AddTraceback("init _cdec", __pyx_clineno, __pyx_lineno, __pyx_filename); Py_DECREF(__pyx_m); __pyx_m = 0; @@ -27163,6 +28055,71 @@ bad: } #endif +static void __Pyx_RaiseArgtupleInvalid( + const char* func_name, + int exact, + Py_ssize_t num_min, + Py_ssize_t num_max, + Py_ssize_t num_found) +{ + Py_ssize_t num_expected; + const char *more_or_less; + if (num_found < num_min) { + num_expected = num_min; + more_or_less = "at least"; + } else { + num_expected = num_max; + more_or_less = "at most"; + } + if (exact) { + more_or_less = "exactly"; + } + PyErr_Format(PyExc_TypeError, + "%s() takes %s %" PY_FORMAT_SIZE_T "d positional argument%s (%" PY_FORMAT_SIZE_T "d given)", + func_name, more_or_less, num_expected, + (num_expected == 1) ? "" : "s", num_found); +} + +static CYTHON_INLINE int __Pyx_CheckKeywordStrings( + PyObject *kwdict, + const char* function_name, + int kw_allowed) +{ + PyObject* key = 0; + Py_ssize_t pos = 0; +#if CPYTHON_COMPILING_IN_PYPY + if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0)) + goto invalid_keyword; + return 1; +#else + while (PyDict_Next(kwdict, &pos, &key, 0)) { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) + #else + if (unlikely(!PyUnicode_Check(key))) + #endif + goto invalid_keyword_type; + } + if ((!kw_allowed) && unlikely(key)) + goto invalid_keyword; + return 1; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%s() keywords must be strings", function_name); + return 0; +#endif +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%s() got an unexpected keyword argument '%s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif + return 0; +} + static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, const char *name, int exact) { @@ -27289,42 +28246,49 @@ bad: return -1; } -static void __Pyx_RaiseArgtupleInvalid( - const char* func_name, - int exact, - Py_ssize_t num_min, - Py_ssize_t num_max, - Py_ssize_t num_found) -{ - Py_ssize_t num_expected; - const char *more_or_less; - if (num_found < num_min) { - num_expected = num_min; - more_or_less = "at least"; - } else { - num_expected = num_max; - more_or_less = "at most"; - } - if (exact) { - more_or_less = "exactly"; - } - PyErr_Format(PyExc_TypeError, - "%s() takes %s %"PY_FORMAT_SIZE_T"d positional argument%s (%"PY_FORMAT_SIZE_T"d given)", - func_name, more_or_less, num_expected, - (num_expected == 1) ? "" : "s", num_found); +static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { + PyErr_Format(PyExc_ValueError, + "too many values to unpack (expected %" PY_FORMAT_SIZE_T "d)", expected); } - - static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { PyErr_Format(PyExc_ValueError, - "need more than %"PY_FORMAT_SIZE_T"d value%s to unpack", + "need more than %" PY_FORMAT_SIZE_T "d value%s to unpack", index, (index == 1) ? "" : "s"); } -static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { - PyErr_Format(PyExc_ValueError, - "too many values to unpack (expected %"PY_FORMAT_SIZE_T"d)", expected); +static CYTHON_INLINE int __Pyx_IterFinish(void) { +#if CYTHON_COMPILING_IN_CPYTHON + PyThreadState *tstate = PyThreadState_GET(); + PyObject* exc_type = tstate->curexc_type; + if (unlikely(exc_type)) { + if (likely(exc_type == PyExc_StopIteration) || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)) { + PyObject *exc_value, *exc_tb; + exc_value = tstate->curexc_value; + exc_tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; + Py_DECREF(exc_type); + Py_XDECREF(exc_value); + Py_XDECREF(exc_tb); + return 0; + } else { + return -1; + } + } + return 0; +#else + if (unlikely(PyErr_Occurred())) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) { + PyErr_Clear(); + return 0; + } else { + return -1; + } + } + return 0; +#endif } static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { @@ -27332,79 +28296,54 @@ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { Py_DECREF(retval); __Pyx_RaiseTooManyValuesError(expected); return -1; - } else if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) { - PyErr_Clear(); - return 0; - } else { - return -1; - } + } else { + return __Pyx_IterFinish(); } return 0; } static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject* iterator, PyObject* defval) { PyObject* next; - if (unlikely(!PyIter_Check(iterator))) { + iternextfunc iternext = Py_TYPE(iterator)->tp_iternext; +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(!iternext)) { +#else + if (unlikely(!iternext) || unlikely(!PyIter_Check(iterator))) { +#endif PyErr_Format(PyExc_TypeError, - "%.200s object is not an iterator", iterator->ob_type->tp_name); + "%.200s object is not an iterator", Py_TYPE(iterator)->tp_name); return NULL; } - next = (*(Py_TYPE(iterator)->tp_iternext))(iterator); - if (likely(next)) { + next = iternext(iterator); + if (likely(next)) return next; - } else if (defval) { - if (PyErr_Occurred()) { - if(!PyErr_ExceptionMatches(PyExc_StopIteration)) - return NULL; - PyErr_Clear(); - } - Py_INCREF(defval); - return defval; - } else if (PyErr_Occurred()) { - return NULL; - } else { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } -} - -static CYTHON_INLINE int __Pyx_CheckKeywordStrings( - PyObject *kwdict, - const char* function_name, - int kw_allowed) -{ - PyObject* key = 0; - Py_ssize_t pos = 0; - while (PyDict_Next(kwdict, &pos, &key, 0)) { - #if PY_MAJOR_VERSION < 3 - if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) - #else - if (unlikely(!PyUnicode_Check(key))) - #endif - goto invalid_keyword_type; - } - if ((!kw_allowed) && unlikely(key)) - goto invalid_keyword; - return 1; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%s() keywords must be strings", function_name); - return 0; -invalid_keyword: - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION < 3 - "%s() got an unexpected keyword argument '%s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); - #endif - return 0; +#if CYTHON_COMPILING_IN_CPYTHON +#if PY_VERSION_HEX >= 0x03010000 || (PY_MAJOR_VERSION < 3 && PY_VERSION_HEX >= 0x02070000) + if (unlikely(iternext == &_PyObject_NextNotImplemented)) + return NULL; +#endif +#endif + if (defval) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (unlikely(exc_type != PyExc_StopIteration) && + !PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)) + return NULL; + PyErr_Clear(); + } + Py_INCREF(defval); + return defval; + } + if (!PyErr_Occurred()) + PyErr_SetNone(PyExc_StopIteration); + return NULL; } static double __Pyx__PyObject_AsDouble(PyObject* obj) { PyObject* float_value; +#if CYTHON_COMPILING_IN_PYPY + float_value = PyNumber_Float(obj); +#else if (Py_TYPE(obj)->tp_as_number && Py_TYPE(obj)->tp_as_number->nb_float) { return PyFloat_AsDouble(obj); } else if (PyUnicode_CheckExact(obj) || PyBytes_CheckExact(obj)) { @@ -27421,6 +28360,7 @@ static double __Pyx__PyObject_AsDouble(PyObject* obj) { PyTuple_SET_ITEM(args, 0, 0); Py_DECREF(args); } +#endif if (likely(float_value)) { double value = PyFloat_AS_DOUBLE(float_value); Py_DECREF(float_value); @@ -27432,6 +28372,7 @@ bad: static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) { PyObject *local_type, *local_value, *local_tb; +#if CYTHON_COMPILING_IN_CPYTHON PyObject *tmp_type, *tmp_value, *tmp_tb; PyThreadState *tstate = PyThreadState_GET(); local_type = tstate->curexc_type; @@ -27440,19 +28381,27 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) tstate->curexc_type = 0; tstate->curexc_value = 0; tstate->curexc_traceback = 0; +#else + PyErr_Fetch(&local_type, &local_value, &local_tb); +#endif PyErr_NormalizeException(&local_type, &local_value, &local_tb); +#if CYTHON_COMPILING_IN_CPYTHON if (unlikely(tstate->curexc_type)) +#else + if (unlikely(PyErr_Occurred())) +#endif goto bad; #if PY_MAJOR_VERSION >= 3 if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) goto bad; #endif - *type = local_type; - *value = local_value; - *tb = local_tb; Py_INCREF(local_type); Py_INCREF(local_value); Py_INCREF(local_tb); + *type = local_type; + *value = local_value; + *tb = local_tb; +#if CYTHON_COMPILING_IN_CPYTHON tmp_type = tstate->exc_type; tmp_value = tstate->exc_value; tmp_tb = tstate->exc_traceback; @@ -27460,10 +28409,13 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) tstate->exc_value = local_value; tstate->exc_traceback = local_tb; /* Make sure tstate is in a consistent state when we XDECREF - these objects (XDECREF may run arbitrary code). */ + these objects (DECREF may run arbitrary code). */ Py_XDECREF(tmp_type); Py_XDECREF(tmp_value); Py_XDECREF(tmp_tb); +#else + PyErr_SetExcInfo(local_type, local_value, local_tb); +#endif return 0; bad: *type = 0; @@ -27476,6 +28428,7 @@ bad: } static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) { +#if CYTHON_COMPILING_IN_CPYTHON PyThreadState *tstate = PyThreadState_GET(); *type = tstate->exc_type; *value = tstate->exc_value; @@ -27483,8 +28436,12 @@ static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, Py_XINCREF(*type); Py_XINCREF(*value); Py_XINCREF(*tb); +#else + PyErr_GetExcInfo(type, value, tb); +#endif } static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) { +#if CYTHON_COMPILING_IN_CPYTHON PyObject *tmp_type, *tmp_value, *tmp_tb; PyThreadState *tstate = PyThreadState_GET(); tmp_type = tstate->exc_type; @@ -27496,11 +28453,82 @@ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) Py_XDECREF(tmp_type); Py_XDECREF(tmp_value); Py_XDECREF(tmp_tb); +#else + PyErr_SetExcInfo(type, value, tb); +#endif +} + +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) { + PyObject *py_import = 0; + PyObject *empty_list = 0; + PyObject *module = 0; + PyObject *global_dict = 0; + PyObject *empty_dict = 0; + PyObject *list; + py_import = __Pyx_GetAttrString(__pyx_b, "__import__"); + if (!py_import) + goto bad; + if (from_list) + list = from_list; + else { + empty_list = PyList_New(0); + if (!empty_list) + goto bad; + list = empty_list; + } + global_dict = PyModule_GetDict(__pyx_m); + if (!global_dict) + goto bad; + empty_dict = PyDict_New(); + if (!empty_dict) + goto bad; + #if PY_VERSION_HEX >= 0x02050000 + { + #if PY_MAJOR_VERSION >= 3 + if (level == -1) { + if (strchr(__Pyx_MODULE_NAME, '.')) { + /* try package relative import first */ + PyObject *py_level = PyInt_FromLong(1); + if (!py_level) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, py_level, NULL); + Py_DECREF(py_level); + if (!module) { + if (!PyErr_ExceptionMatches(PyExc_ImportError)) + goto bad; + PyErr_Clear(); + } + } + level = 0; /* try absolute import on failure */ + } + #endif + if (!module) { + PyObject *py_level = PyInt_FromLong(level); + if (!py_level) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, py_level, NULL); + Py_DECREF(py_level); + } + } + #else + if (level>0) { + PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4."); + goto bad; + } + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, NULL); + #endif +bad: + Py_XDECREF(empty_list); + Py_XDECREF(py_import); + Py_XDECREF(empty_dict); + return module; } static PyObject *__Pyx_FindPy2Metaclass(PyObject *bases) { PyObject *metaclass; - /* Default metaclass */ #if PY_MAJOR_VERSION < 3 if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) { PyObject *base = PyTuple_GET_ITEM(bases, 0); @@ -27530,7 +28558,6 @@ static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *na PyObject *metaclass; if (PyDict_SetItemString(dict, "__module__", modname) < 0) return NULL; - /* Python2 __metaclass__ */ metaclass = PyDict_GetItemString(dict, "__metaclass__"); if (metaclass) { Py_INCREF(metaclass); @@ -27912,6 +28939,56 @@ __Pyx_CyFunction_repr(__pyx_CyFunctionObject *op) PyString_AsString(func_name), (void *)op); #endif } +#if CYTHON_COMPILING_IN_PYPY +static PyObject * __Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) { + PyCFunctionObject* f = (PyCFunctionObject*)func; + PyCFunction meth = PyCFunction_GET_FUNCTION(func); + PyObject *self = PyCFunction_GET_SELF(func); + Py_ssize_t size; + switch (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)) { + case METH_VARARGS: + if (likely(kw == NULL) || PyDict_Size(kw) == 0) + return (*meth)(self, arg); + break; + case METH_VARARGS | METH_KEYWORDS: + return (*(PyCFunctionWithKeywords)meth)(self, arg, kw); + case METH_NOARGS: + if (likely(kw == NULL) || PyDict_Size(kw) == 0) { + size = PyTuple_GET_SIZE(arg); + if (size == 0) + return (*meth)(self, NULL); + PyErr_Format(PyExc_TypeError, + "%.200s() takes no arguments (%zd given)", + f->m_ml->ml_name, size); + return NULL; + } + break; + case METH_O: + if (likely(kw == NULL) || PyDict_Size(kw) == 0) { + size = PyTuple_GET_SIZE(arg); + if (size == 1) + return (*meth)(self, PyTuple_GET_ITEM(arg, 0)); + PyErr_Format(PyExc_TypeError, + "%.200s() takes exactly one argument (%zd given)", + f->m_ml->ml_name, size); + return NULL; + } + break; + default: + PyErr_SetString(PyExc_SystemError, "Bad call flags in " + "__Pyx_CyFunction_Call. METH_OLDARGS is no " + "longer supported!"); + return NULL; + } + PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments", + f->m_ml->ml_name); + return NULL; +} +#else +static PyObject * __Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) { + return PyCFunction_Call(func, arg, kw); +} +#endif static PyTypeObject __pyx_CyFunctionType_type = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("cython_function_or_method"), /*tp_name*/ @@ -27931,7 +29008,7 @@ static PyTypeObject __pyx_CyFunctionType_type = { 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash*/ - __Pyx_PyCFunction_Call, /*tp_call*/ + __Pyx_CyFunction_Call, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ @@ -27967,15 +29044,16 @@ static PyTypeObject __pyx_CyFunctionType_type = { 0, /*tp_version_tag*/ #endif }; -static int __Pyx_CyFunction_init(void) -{ +static int __Pyx_CyFunction_init(void) { +#if !CYTHON_COMPILING_IN_PYPY + __pyx_CyFunctionType_type.tp_call = PyCFunction_Call; +#endif if (PyType_Ready(&__pyx_CyFunctionType_type) < 0) return -1; __pyx_CyFunctionType = &__pyx_CyFunctionType_type; return 0; } -void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) -{ +static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) { __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; m->defaults = PyMem_Malloc(size); if (!m->defaults) @@ -27984,14 +29062,16 @@ void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) m->defaults_pyobjects = pyobjects; return m->defaults; } -static void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) -{ +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) { __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; m->defaults_tuple = tuple; Py_INCREF(tuple); } static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else if (s1 == s2) { return (equals == Py_EQ); } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { @@ -28019,9 +29099,13 @@ static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int eq Py_DECREF(py_result); return result; } +#endif } static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else if (s1 == s2) { return (equals == Py_EQ); } else if (PyUnicode_CheckExact(s1) & PyUnicode_CheckExact(s2)) { @@ -28061,6 +29145,7 @@ static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int Py_DECREF(py_result); return result; } +#endif } static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { @@ -28463,8 +29548,8 @@ static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* } } -static void __Pyx_WriteUnraisable(const char *name, int clineno, - int lineno, const char *filename) { +static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, + CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename) { PyObject *old_exc, *old_val, *old_tb; PyObject *ctx; __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); @@ -28484,6 +29569,7 @@ static void __Pyx_WriteUnraisable(const char *name, int clineno, static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) { PyObject *tmp_type, *tmp_value, *tmp_tb; +#if CYTHON_COMPILING_IN_CPYTHON PyThreadState *tstate = PyThreadState_GET(); tmp_type = tstate->exc_type; tmp_value = tstate->exc_value; @@ -28491,6 +29577,10 @@ static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, tstate->exc_type = *type; tstate->exc_value = *value; tstate->exc_traceback = *tb; +#else + PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb); + PyErr_SetExcInfo(*type, *value, *tb); +#endif *type = tmp_type; *value = tmp_value; *tb = tmp_tb; @@ -28500,9 +29590,70 @@ static PyObject *__Pyx_Generator_Next(PyObject *self); static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value); static PyObject *__Pyx_Generator_Close(PyObject *self); static PyObject *__Pyx_Generator_Throw(PyObject *gen, PyObject *args); +static PyTypeObject *__pyx_GeneratorType = 0; +#define __Pyx_Generator_CheckExact(obj) (Py_TYPE(obj) == __pyx_GeneratorType) +#define __Pyx_Generator_Undelegate(gen) Py_CLEAR((gen)->yieldfrom) +#if 1 || PY_VERSION_HEX < 0x030300B0 +static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue) { + PyObject *et, *ev, *tb; + PyObject *value = NULL; + __Pyx_ErrFetch(&et, &ev, &tb); + if (!et) { + Py_XDECREF(tb); + Py_XDECREF(ev); + Py_INCREF(Py_None); + *pvalue = Py_None; + return 0; + } + if (unlikely(et != PyExc_StopIteration) && + unlikely(!PyErr_GivenExceptionMatches(et, PyExc_StopIteration))) { + __Pyx_ErrRestore(et, ev, tb); + return -1; + } + if (likely(et == PyExc_StopIteration)) { + if (likely(!ev) || !PyObject_IsInstance(ev, PyExc_StopIteration)) { + if (!ev) { + Py_INCREF(Py_None); + ev = Py_None; + } + Py_XDECREF(tb); + Py_DECREF(et); + *pvalue = ev; + return 0; + } + } + PyErr_NormalizeException(&et, &ev, &tb); + if (unlikely(!PyObject_IsInstance(ev, PyExc_StopIteration))) { + __Pyx_ErrRestore(et, ev, tb); + return -1; + } + Py_XDECREF(tb); + Py_DECREF(et); +#if PY_VERSION_HEX >= 0x030300A0 + value = ((PyStopIterationObject *)ev)->value; + Py_INCREF(value); + Py_DECREF(ev); +#else + { + PyObject* args = PyObject_GetAttrString(ev, "args"); + Py_DECREF(ev); + if (likely(args)) { + value = PyObject_GetItem(args, 0); + Py_DECREF(args); + } + if (unlikely(!value)) { + __Pyx_ErrRestore(NULL, NULL, NULL); + Py_INCREF(Py_None); + value = Py_None; + } + } +#endif + *pvalue = value; + return 0; +} +#endif static CYTHON_INLINE -void __Pyx_Generator_ExceptionClear(__pyx_GeneratorObject *self) -{ +void __Pyx_Generator_ExceptionClear(__pyx_GeneratorObject *self) { PyObject *exc_type = self->exc_type; PyObject *exc_value = self->exc_value; PyObject *exc_traceback = self->exc_traceback; @@ -28514,14 +29665,18 @@ void __Pyx_Generator_ExceptionClear(__pyx_GeneratorObject *self) Py_XDECREF(exc_traceback); } static CYTHON_INLINE -PyObject *__Pyx_Generator_SendEx(__pyx_GeneratorObject *self, PyObject *value) -{ - PyObject *retval; - if (unlikely(self->is_running)) { +int __Pyx_Generator_CheckRunning(__pyx_GeneratorObject *gen) { + if (unlikely(gen->is_running)) { PyErr_SetString(PyExc_ValueError, "generator already executing"); - return NULL; + return 1; } + return 0; +} +static CYTHON_INLINE +PyObject *__Pyx_Generator_SendEx(__pyx_GeneratorObject *self, PyObject *value) { + PyObject *retval; + assert(!self->is_running); if (unlikely(self->resume_label == 0)) { if (unlikely(value && value != Py_None)) { PyErr_SetString(PyExc_TypeError, @@ -28534,81 +29689,240 @@ PyObject *__Pyx_Generator_SendEx(__pyx_GeneratorObject *self, PyObject *value) PyErr_SetNone(PyExc_StopIteration); return NULL; } - if (value) - __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, &self->exc_traceback); - else + if (value) { +#if CYTHON_COMPILING_IN_PYPY +#else + /* Generators always return to their most recent caller, not + * necessarily their creator. */ + if (self->exc_traceback) { + PyThreadState *tstate = PyThreadState_GET(); + PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback; + PyFrameObject *f = tb->tb_frame; + Py_XINCREF(tstate->frame); + assert(f->f_back == NULL); + f->f_back = tstate->frame; + } +#endif + __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, + &self->exc_traceback); + } else { __Pyx_Generator_ExceptionClear(self); + } self->is_running = 1; retval = self->body((PyObject *) self, value); self->is_running = 0; - if (retval) - __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, &self->exc_traceback); - else + if (retval) { + __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, + &self->exc_traceback); +#if CYTHON_COMPILING_IN_PYPY +#else + /* Don't keep the reference to f_back any longer than necessary. It + * may keep a chain of frames alive or it could create a reference + * cycle. */ + if (self->exc_traceback) { + PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback; + PyFrameObject *f = tb->tb_frame; + Py_CLEAR(f->f_back); + } +#endif + } else { __Pyx_Generator_ExceptionClear(self); + } return retval; } -static PyObject *__Pyx_Generator_Next(PyObject *self) -{ - return __Pyx_Generator_SendEx((__pyx_GeneratorObject *) self, Py_None); +static CYTHON_INLINE +PyObject *__Pyx_Generator_FinishDelegation(__pyx_GeneratorObject *gen) { + PyObject *ret; + PyObject *val = NULL; + __Pyx_Generator_Undelegate(gen); + __Pyx_PyGen_FetchStopIterationValue(&val); + ret = __Pyx_Generator_SendEx(gen, val); + Py_XDECREF(val); + return ret; +} +static PyObject *__Pyx_Generator_Next(PyObject *self) { + __pyx_GeneratorObject *gen = (__pyx_GeneratorObject*) self; + PyObject *yf = gen->yieldfrom; + if (unlikely(__Pyx_Generator_CheckRunning(gen))) + return NULL; + if (yf) { + PyObject *ret; + gen->is_running = 1; + ret = Py_TYPE(yf)->tp_iternext(yf); + gen->is_running = 0; + if (likely(ret)) { + return ret; + } + return __Pyx_Generator_FinishDelegation(gen); + } + return __Pyx_Generator_SendEx(gen, Py_None); } -static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value) -{ - return __Pyx_Generator_SendEx((__pyx_GeneratorObject *) self, value); +static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value) { + __pyx_GeneratorObject *gen = (__pyx_GeneratorObject*) self; + PyObject *yf = gen->yieldfrom; + if (unlikely(__Pyx_Generator_CheckRunning(gen))) + return NULL; + if (yf) { + PyObject *ret; + gen->is_running = 1; + if (__Pyx_Generator_CheckExact(yf)) { + ret = __Pyx_Generator_Send(yf, value); + } else { + if (value == Py_None) + ret = PyIter_Next(yf); + else + ret = PyObject_CallMethod(yf, (char*)"send", (char*)"O", value); + } + gen->is_running = 0; + if (likely(ret)) { + return ret; + } + return __Pyx_Generator_FinishDelegation(gen); + } + return __Pyx_Generator_SendEx(gen, value); +} +static int __Pyx_Generator_CloseIter(__pyx_GeneratorObject *gen, PyObject *yf) { + PyObject *retval = NULL; + int err = 0; + if (__Pyx_Generator_CheckExact(yf)) { + retval = __Pyx_Generator_Close(yf); + if (!retval) + return -1; + } else { + PyObject *meth; + gen->is_running = 1; + meth = PyObject_GetAttrString(yf, "close"); + if (unlikely(!meth)) { + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_WriteUnraisable(yf); + } + PyErr_Clear(); + } else { + retval = PyObject_CallFunction(meth, NULL); + Py_DECREF(meth); + if (!retval) + err = -1; + } + gen->is_running = 0; + } + Py_XDECREF(retval); + return err; } -static PyObject *__Pyx_Generator_Close(PyObject *self) -{ - __pyx_GeneratorObject *generator = (__pyx_GeneratorObject *) self; - PyObject *retval; +static PyObject *__Pyx_Generator_Close(PyObject *self) { + __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; + PyObject *retval, *raised_exception; + PyObject *yf = gen->yieldfrom; + int err = 0; + if (unlikely(__Pyx_Generator_CheckRunning(gen))) + return NULL; + if (yf) { + Py_INCREF(yf); + err = __Pyx_Generator_CloseIter(gen, yf); + __Pyx_Generator_Undelegate(gen); + Py_DECREF(yf); + } + if (err == 0) #if PY_VERSION_HEX < 0x02050000 - PyErr_SetNone(PyExc_StopIteration); + PyErr_SetNone(PyExc_StopIteration); #else - PyErr_SetNone(PyExc_GeneratorExit); + PyErr_SetNone(PyExc_GeneratorExit); #endif - retval = __Pyx_Generator_SendEx(generator, NULL); + retval = __Pyx_Generator_SendEx(gen, NULL); if (retval) { Py_DECREF(retval); PyErr_SetString(PyExc_RuntimeError, "generator ignored GeneratorExit"); return NULL; } -#if PY_VERSION_HEX < 0x02050000 - if (PyErr_ExceptionMatches(PyExc_StopIteration)) -#else - if (PyErr_ExceptionMatches(PyExc_StopIteration) - || PyErr_ExceptionMatches(PyExc_GeneratorExit)) + raised_exception = PyErr_Occurred(); + if (!raised_exception + || raised_exception == PyExc_StopIteration +#if PY_VERSION_HEX >= 0x02050000 + || raised_exception == PyExc_GeneratorExit + || PyErr_GivenExceptionMatches(raised_exception, PyExc_GeneratorExit) #endif + || PyErr_GivenExceptionMatches(raised_exception, PyExc_StopIteration)) { - PyErr_Clear(); /* ignore these errors */ + if (raised_exception) PyErr_Clear(); /* ignore these errors */ Py_INCREF(Py_None); return Py_None; } return NULL; } -static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args) -{ - __pyx_GeneratorObject *generator = (__pyx_GeneratorObject *) self; +static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args) { + __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; PyObject *typ; PyObject *tb = NULL; PyObject *val = NULL; + PyObject *yf = gen->yieldfrom; if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb)) return NULL; + if (unlikely(__Pyx_Generator_CheckRunning(gen))) + return NULL; + if (yf) { + PyObject *ret; + Py_INCREF(yf); +#if PY_VERSION_HEX >= 0x02050000 + if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit)) { + int err = __Pyx_Generator_CloseIter(gen, yf); + Py_DECREF(yf); + __Pyx_Generator_Undelegate(gen); + if (err < 0) + return __Pyx_Generator_SendEx(gen, NULL); + goto throw_here; + } +#endif + gen->is_running = 1; + if (__Pyx_Generator_CheckExact(yf)) { + ret = __Pyx_Generator_Throw(yf, args); + } else { + PyObject *meth = PyObject_GetAttrString(yf, "throw"); + if (unlikely(!meth)) { + Py_DECREF(yf); + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { + gen->is_running = 0; + return NULL; + } + PyErr_Clear(); + __Pyx_Generator_Undelegate(gen); + gen->is_running = 0; + goto throw_here; + } + ret = PyObject_CallObject(meth, args); + Py_DECREF(meth); + } + gen->is_running = 0; + Py_DECREF(yf); + if (!ret) { + ret = __Pyx_Generator_FinishDelegation(gen); + } + return ret; + } +throw_here: __Pyx_Raise(typ, val, tb, NULL); - return __Pyx_Generator_SendEx(generator, NULL); + return __Pyx_Generator_SendEx(gen, NULL); } -static int -__Pyx_Generator_traverse(PyObject *self, visitproc visit, void *arg) -{ +static int __Pyx_Generator_traverse(PyObject *self, visitproc visit, void *arg) { __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; Py_VISIT(gen->closure); Py_VISIT(gen->classobj); + Py_VISIT(gen->yieldfrom); Py_VISIT(gen->exc_type); Py_VISIT(gen->exc_value); Py_VISIT(gen->exc_traceback); return 0; } -static void -__Pyx_Generator_dealloc(PyObject *self) -{ +static int __Pyx_Generator_clear(PyObject *self) { + __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; + Py_CLEAR(gen->closure); + Py_CLEAR(gen->classobj); + Py_CLEAR(gen->yieldfrom); + Py_CLEAR(gen->exc_type); + Py_CLEAR(gen->exc_value); + Py_CLEAR(gen->exc_traceback); + return 0; +} +static void __Pyx_Generator_dealloc(PyObject *self) { __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; PyObject_GC_UnTrack(gen); if (gen->gi_weakreflist != NULL) @@ -28620,16 +29934,10 @@ __Pyx_Generator_dealloc(PyObject *self) return; /* resurrected. :( */ } PyObject_GC_UnTrack(self); - Py_CLEAR(gen->closure); - Py_CLEAR(gen->classobj); - Py_CLEAR(gen->exc_type); - Py_CLEAR(gen->exc_value); - Py_CLEAR(gen->exc_traceback); + __Pyx_Generator_clear(self); PyObject_GC_Del(gen); } -static void -__Pyx_Generator_del(PyObject *self) -{ +static void __Pyx_Generator_del(PyObject *self) { PyObject *res; PyObject *error_type, *error_value, *error_traceback; __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; @@ -28658,11 +29966,13 @@ __Pyx_Generator_del(PyObject *self) _Py_NewReference(self); self->ob_refcnt = refcnt; } +#if CYTHON_COMPILING_FOR_CPYTHON assert(PyType_IS_GC(self->ob_type) && _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED); /* If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so * we need to undo that. */ _Py_DEC_REFTOTAL; +#endif /* If Py_TRACE_REFS, _Py_NewReference re-added self to the object * chain, so no more to do there. * If COUNT_ALLOCS, the original decref bumped tp_frees, and @@ -28670,13 +29980,17 @@ __Pyx_Generator_del(PyObject *self) * undone. */ #ifdef COUNT_ALLOCS - --self->ob_type->tp_frees; - --self->ob_type->tp_allocs; + --Py_TYPE(self)->tp_frees; + --Py_TYPE(self)->tp_allocs; #endif } static PyMemberDef __pyx_Generator_memberlist[] = { {(char *) "gi_running", +#if PY_VERSION_HEX >= 0x02060000 + T_BOOL, +#else T_INT, +#endif offsetof(__pyx_GeneratorObject, is_running), READONLY, NULL}, @@ -28688,7 +30002,7 @@ static PyMethodDef __pyx_Generator_methods[] = { {__Pyx_NAMESTR("close"), (PyCFunction) __Pyx_Generator_Close, METH_NOARGS, 0}, {0, 0, 0, 0} }; -static PyTypeObject __pyx_GeneratorType = { +static PyTypeObject __pyx_GeneratorType_type = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("generator"), /*tp_name*/ sizeof(__pyx_GeneratorObject), /*tp_basicsize*/ @@ -28709,7 +30023,7 @@ static PyTypeObject __pyx_GeneratorType = { 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ - PyObject_GenericGetAttr, /*tp_getattro*/ + 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags*/ @@ -28718,7 +30032,7 @@ static PyTypeObject __pyx_GeneratorType = { 0, /*tp_clear*/ 0, /*tp_richcompare*/ offsetof(__pyx_GeneratorObject, gi_weakreflist), /* tp_weaklistoffse */ - PyObject_SelfIter, /*tp_iter*/ + 0, /*tp_iter*/ (iternextfunc) __Pyx_Generator_Next, /*tp_iternext*/ __pyx_Generator_methods, /*tp_methods*/ __pyx_Generator_memberlist, /*tp_members*/ @@ -28743,12 +30057,10 @@ static PyTypeObject __pyx_GeneratorType = { 0, /*tp_version_tag*/ #endif }; -static -__pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body, - PyObject *closure) -{ +static __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body, + PyObject *closure) { __pyx_GeneratorObject *gen = - PyObject_GC_New(__pyx_GeneratorObject, &__pyx_GeneratorType); + PyObject_GC_New(__pyx_GeneratorObject, &__pyx_GeneratorType_type); if (gen == NULL) return NULL; gen->body = body; @@ -28757,6 +30069,7 @@ __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body, gen->is_running = 0; gen->resume_label = 0; gen->classobj = NULL; + gen->yieldfrom = NULL; gen->exc_type = NULL; gen->exc_value = NULL; gen->exc_traceback = NULL; @@ -28764,9 +30077,14 @@ __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body, PyObject_GC_Track(gen); return gen; } -static int __pyx_Generator_init(void) -{ - return PyType_Ready(&__pyx_GeneratorType); +static int __pyx_Generator_init(void) { + __pyx_GeneratorType_type.tp_getattro = PyObject_GenericGetAttr; + __pyx_GeneratorType_type.tp_iter = PyObject_SelfIter; + if (PyType_Ready(&__pyx_GeneratorType_type)) { + return -1; + } + __pyx_GeneratorType = &__pyx_GeneratorType_type; + return 0; } static int __Pyx_check_binary_version(void) { @@ -28805,6 +30123,147 @@ bad: return -1; } +#ifndef __PYX_HAVE_RT_ImportType +#define __PYX_HAVE_RT_ImportType +static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, + size_t size, int strict) +{ + PyObject *py_module = 0; + PyObject *result = 0; + PyObject *py_name = 0; + char warning[200]; + py_module = __Pyx_ImportModule(module_name); + if (!py_module) + goto bad; + py_name = __Pyx_PyIdentifier_FromString(class_name); + if (!py_name) + goto bad; + result = PyObject_GetAttr(py_module, py_name); + Py_DECREF(py_name); + py_name = 0; + Py_DECREF(py_module); + py_module = 0; + if (!result) + goto bad; + if (!PyType_Check(result)) { + PyErr_Format(PyExc_TypeError, + "%s.%s is not a type object", + module_name, class_name); + goto bad; + } + if (!strict && (size_t)((PyTypeObject *)result)->tp_basicsize > size) { + PyOS_snprintf(warning, sizeof(warning), + "%s.%s size changed, may indicate binary incompatibility", + module_name, class_name); + #if PY_VERSION_HEX < 0x02050000 + if (PyErr_Warn(NULL, warning) < 0) goto bad; + #else + if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; + #endif + } + else if ((size_t)((PyTypeObject *)result)->tp_basicsize != size) { + PyErr_Format(PyExc_ValueError, + "%s.%s has the wrong size, try recompiling", + module_name, class_name); + goto bad; + } + return (PyTypeObject *)result; +bad: + Py_XDECREF(py_module); + Py_XDECREF(result); + return NULL; +} +#endif + +#ifndef __PYX_HAVE_RT_ImportModule +#define __PYX_HAVE_RT_ImportModule +static PyObject *__Pyx_ImportModule(const char *name) { + PyObject *py_name = 0; + PyObject *py_module = 0; + py_name = __Pyx_PyIdentifier_FromString(name); + if (!py_name) + goto bad; + py_module = PyImport_Import(py_name); + Py_DECREF(py_name); + return py_module; +bad: + Py_XDECREF(py_name); + return 0; +} +#endif + +static void* __Pyx_GetVtable(PyObject *dict) { + void* ptr; + PyObject *ob = PyMapping_GetItemString(dict, (char *)"__pyx_vtable__"); + if (!ob) + goto bad; +#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) + ptr = PyCapsule_GetPointer(ob, 0); +#else + ptr = PyCObject_AsVoidPtr(ob); +#endif + if (!ptr && !PyErr_Occurred()) + PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type"); + Py_DECREF(ob); + return ptr; +bad: + Py_XDECREF(ob); + return NULL; +} + +#ifndef __PYX_HAVE_RT_ImportFunction +#define __PYX_HAVE_RT_ImportFunction +static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig) { + PyObject *d = 0; + PyObject *cobj = 0; + union { + void (*fp)(void); + void *p; + } tmp; + d = PyObject_GetAttrString(module, (char *)"__pyx_capi__"); + if (!d) + goto bad; + cobj = PyDict_GetItemString(d, funcname); + if (!cobj) { + PyErr_Format(PyExc_ImportError, + "%s does not export expected C function %s", + PyModule_GetName(module), funcname); + goto bad; + } +#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) + if (!PyCapsule_IsValid(cobj, sig)) { + PyErr_Format(PyExc_TypeError, + "C function %s.%s has wrong signature (expected %s, got %s)", + PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj)); + goto bad; + } + tmp.p = PyCapsule_GetPointer(cobj, sig); +#else + {const char *desc, *s1, *s2; + desc = (const char *)PyCObject_GetDesc(cobj); + if (!desc) + goto bad; + s1 = desc; s2 = sig; + while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; } + if (*s1 != *s2) { + PyErr_Format(PyExc_TypeError, + "C function %s.%s has wrong signature (expected %s, got %s)", + PyModule_GetName(module), funcname, sig, desc); + goto bad; + } + tmp.p = PyCObject_AsVoidPtr(cobj);} +#endif + *f = tmp.fp; + if (!(*f)) + goto bad; + Py_DECREF(d); + return 0; +bad: + Py_XDECREF(d); + return -1; +} +#endif + static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { int start = 0, mid = 0, end = count - 1; if (end >= 0 && code_line > entries[end].code_line) { diff --git a/python/src/_cdec.pyx b/python/src/_cdec.pyx index c60f342f..e93474fe 100644 --- a/python/src/_cdec.pyx +++ b/python/src/_cdec.pyx @@ -3,14 +3,14 @@ from libcpp.vector cimport vector from utils cimport * cimport decoder -cdef char* as_str(data, error_msg='Cannot convert type %s to str'): +cdef char* as_str(data, char* error_msg='Cannot convert type %s to str'): cdef bytes ret if isinstance(data, unicode): ret = data.encode('utf8') elif isinstance(data, str): ret = data else: - raise TypeError(error_msg % type(data)) + raise TypeError(error_msg.format(type(data))) return ret include "vectors.pxi" @@ -55,8 +55,9 @@ cdef class Decoder: cdef istringstream* config_stream = new istringstream(config_str) self.dec = new decoder.Decoder(config_stream) del config_stream - self.weights = DenseVector() + self.weights = DenseVector.__new__(DenseVector) self.weights.vector = &self.dec.CurrentWeightVector() + self.weights.owned = True def __dealloc__(self): del self.dec @@ -72,6 +73,7 @@ cdef class Decoder: self.weights.vector.clear() (( weights).vector[0]).init_vector(self.weights.vector) elif isinstance(weights, dict): + self.weights.vector.clear() for fname, fval in weights.items(): self.weights[fname] = fval else: @@ -80,7 +82,7 @@ cdef class Decoder: property formalism: def __get__(self): cdef variables_map* conf = &self.dec.GetConf() - return conf[0]['formalism'].as_str().c_str() + return conf[0]['formalism'].as_str() def read_weights(self, weights): with open(weights) as fp: diff --git a/python/src/grammar.pxd b/python/src/grammar.pxd index 8853a614..833de2e3 100644 --- a/python/src/grammar.pxd +++ b/python/src/grammar.pxd @@ -21,17 +21,20 @@ cdef extern from "decoder/trule.h": void ComputeArity() cdef extern from "decoder/grammar.h": - cdef cppclass RuleBin "const RuleBin": + cdef cppclass RuleBin: int GetNumRules() shared_ptr[TRule] GetIthRule(int i) int Arity() - cdef cppclass GrammarIter "const GrammarIter": - RuleBin* GetRules() - GrammarIter* Extend(int symbol) + ctypedef RuleBin const_RuleBin "const RuleBin" + + cdef cppclass GrammarIter: + const_RuleBin* GetRules() + + ctypedef GrammarIter const_GrammarIter "const GrammarIter" cdef cppclass Grammar: - GrammarIter* GetRoot() + const_GrammarIter* GetRoot() bint HasRuleForSpan(int i, int j, int distance) unsigned GetCTFLevels() string GetGrammarName() diff --git a/python/src/grammar.pxi b/python/src/grammar.pxi index 80d9fbf5..5ec21422 100644 --- a/python/src/grammar.pxi +++ b/python/src/grammar.pxi @@ -1,4 +1,6 @@ cimport grammar +cimport cdec.sa._sa as _sa +import cdec.sa._sa as _sa def _phrase(phrase): return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) @@ -23,9 +25,41 @@ cdef class NTRef: def __str__(self): return '[%d]' % self.ref -cdef class BaseTRule: +cdef TRule convert_rule(_sa.Rule rule): + cdef unsigned i + cdef lhs = _sa.sym_tocat(rule.lhs) + cdef scores = {} + for i in range(rule.n_scores): + scores['PhraseModel_'+str(i)] = rule.cscores[i] + f, e = [], [] + cdef int* fsyms = rule.f.syms + for i in range(rule.f.n): + if _sa.sym_isvar(fsyms[i]): + f.append(NT(_sa.sym_tocat(fsyms[i]))) + else: + f.append(_sa.sym_tostring(fsyms[i])) + cdef int* esyms = rule.e.syms + for i in range(rule.e.n): + if _sa.sym_isvar(esyms[i]): + e.append(NTRef(_sa.sym_getindex(esyms[i]))) + else: + e.append(_sa.sym_tostring(esyms[i])) + cdef a = [(point/65536, point%65536) for point in rule.word_alignments] + return TRule(lhs, f, e, scores, a) + +cdef class TRule: cdef shared_ptr[grammar.TRule]* rule + def __init__(self, lhs, f, e, scores, a=None): + self.rule = new shared_ptr[grammar.TRule](new grammar.TRule()) + self.lhs = lhs + self.e = e + self.f = f + self.scores = scores + if a: + self.a = a + self.rule.get().ComputeArity() + def __dealloc__(self): del self.rule @@ -104,7 +138,7 @@ cdef class BaseTRule: property scores: def __get__(self): - cdef SparseVector scores = SparseVector() + cdef SparseVector scores = SparseVector.__new__(SparseVector) scores.vector = new FastSparseVector[double](self.rule.get().scores_) return scores @@ -132,17 +166,6 @@ cdef class BaseTRule: return '%s ||| %s ||| %s ||| %s' % (self.lhs, _phrase(self.f), _phrase(self.e), scores) -cdef class TRule(BaseTRule): - def __cinit__(self, lhs, f, e, scores, a=None): - self.rule = new shared_ptr[grammar.TRule](new grammar.TRule()) - self.lhs = lhs - self.e = e - self.f = f - self.scores = scores - if a: - self.a = a - self.rule.get().ComputeArity() - cdef class Grammar: cdef shared_ptr[grammar.Grammar]* grammar @@ -150,12 +173,12 @@ cdef class Grammar: del self.grammar def __iter__(self): - cdef grammar.GrammarIter* root = self.grammar.get().GetRoot() - cdef grammar.RuleBin* rbin = root.GetRules() + cdef grammar.const_GrammarIter* root = self.grammar.get().GetRoot() + cdef grammar.const_RuleBin* rbin = root.GetRules() cdef TRule trule cdef unsigned i for i in range(rbin.GetNumRules()): - trule = TRule() + trule = TRule.__new__(TRule) trule.rule = new shared_ptr[grammar.TRule](rbin.GetIthRule(i)) yield trule @@ -171,6 +194,8 @@ cdef class TextGrammar(Grammar): self.grammar = new shared_ptr[grammar.Grammar](new grammar.TextGrammar()) cdef grammar.TextGrammar* _g = self.grammar.get() for trule in rules: - if not isinstance(trule, BaseTRule): + if isinstance(trule, _sa.Rule): + trule = convert_rule(trule) + elif not isinstance(trule, TRule): raise ValueError('the grammar should contain TRule objects') - _g.AddRule(( trule).rule[0]) + _g.AddRule(( trule).rule[0]) diff --git a/python/src/hypergraph.pxd b/python/src/hypergraph.pxd index e51ccf5c..886660bf 100644 --- a/python/src/hypergraph.pxd +++ b/python/src/hypergraph.pxd @@ -9,23 +9,27 @@ cdef extern from "decoder/hg.h": EdgeMask(int size) bint& operator[](int) - cdef cppclass HypergraphEdge "const Hypergraph::Edge": + cdef cppclass HypergraphEdge "Hypergraph::Edge": int id_ int head_node_ # position in hg.nodes_ SmallVector[unsigned] tail_nodes_ # positions in hg.nodes_ shared_ptr[TRule] rule_ FastSparseVector[weight_t] feature_values_ - LogVal[double] edge_prob_ # weights.dot(feature_values_) + prob_t edge_prob_ # weights.dot(feature_values_) # typically source span: short int i_ short int j_ - cdef cppclass HypergraphNode "const Hypergraph::Node": + ctypedef HypergraphEdge const_HypergraphEdge "const Hypergraph::Edge" + + cdef cppclass HypergraphNode "Hypergraph::Node": int id_ WordID cat_ # non-terminal category if <0, 0 if not set vector[int] in_edges_ # positions in hg.edge_prob_ vector[int] out_edges_ # positions in hg.edge_prob_ + ctypedef HypergraphNode const_HypergraphNode "const Hypergraph::Node" + cdef cppclass Hypergraph: Hypergraph(Hypergraph) vector[HypergraphNode] nodes_ @@ -42,9 +46,9 @@ cdef extern from "decoder/hg.h": bint safe_inside) cdef extern from "decoder/viterbi.h": - LogVal[double] ViterbiESentence(Hypergraph& hg, vector[WordID]* trans) + prob_t ViterbiESentence(Hypergraph& hg, vector[WordID]* trans) string ViterbiETree(Hypergraph& hg) - LogVal[double] ViterbiFSentence(Hypergraph& hg, vector[WordID]* trans) + prob_t ViterbiFSentence(Hypergraph& hg, vector[WordID]* trans) string ViterbiFTree(Hypergraph& hg) FastSparseVector[weight_t] ViterbiFeatures(Hypergraph& hg) FastSparseVector[weight_t] ViterbiFeatures(Hypergraph& hg, @@ -67,7 +71,7 @@ cdef extern from "decoder/hg_sampler.h" namespace "HypergraphSampler": cdef cppclass Hypothesis: vector[WordID] words FastSparseVector[weight_t] fmap - LogVal[double] model_score + prob_t model_score void sample_hypotheses(Hypergraph& hg, unsigned n, MT19937* rng, @@ -77,4 +81,4 @@ cdef extern from "decoder/csplit.h" namespace "CompoundSplit": int GetFullWordEdgeIndex(Hypergraph& forest) cdef extern from "decoder/inside_outside.h": - LogVal[double] InsideOutside "InsideOutside, EdgeFeaturesAndProbWeightFunction>" (Hypergraph& hg, FastSparseVector[LogVal[double]]* result) + prob_t InsideOutside "InsideOutside, EdgeFeaturesAndProbWeightFunction>" (Hypergraph& hg, FastSparseVector[prob_t]* result) diff --git a/python/src/hypergraph.pxi b/python/src/hypergraph.pxi index 86751cc9..b210f440 100644 --- a/python/src/hypergraph.pxi +++ b/python/src/hypergraph.pxi @@ -21,7 +21,7 @@ cdef class Hypergraph: return (f_tree, e_tree) def viterbi_features(self): - cdef SparseVector fmap = SparseVector() + cdef SparseVector fmap = SparseVector.__new__(SparseVector) fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0])) return fmap @@ -67,7 +67,7 @@ cdef class Hypergraph: for k in range(size): derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) if not derivation: break - fmap = SparseVector() + fmap = SparseVector.__new__(SparseVector) fmap.vector = new FastSparseVector[weight_t](derivation._yield) yield fmap finally: @@ -130,12 +130,12 @@ cdef class Hypergraph: return self.hg.NumberOfPaths() def inside_outside(self): - cdef FastSparseVector[LogVal[double]]* result = new FastSparseVector[LogVal[double]]() - cdef LogVal[double] z = hypergraph.InsideOutside(self.hg[0], result) + cdef FastSparseVector[prob_t]* result = new FastSparseVector[prob_t]() + cdef prob_t z = hypergraph.InsideOutside(self.hg[0], result) result[0] /= z - cdef SparseVector vector = SparseVector() + cdef SparseVector vector = SparseVector.__new__(SparseVector) vector.vector = new FastSparseVector[double]() - cdef FastSparseVector[LogVal[double]].const_iterator* it = new FastSparseVector[LogVal[double]].const_iterator(result[0], False) + cdef FastSparseVector[prob_t].const_iterator* it = new FastSparseVector[prob_t].const_iterator(result[0], False) cdef unsigned i for i in range(result.size()): vector.vector.set_value(it[0].ptr().first, log(it[0].ptr().second)) @@ -147,12 +147,12 @@ cdef class Hypergraph: cdef class HypergraphEdge: cdef hypergraph.Hypergraph* hg cdef hypergraph.HypergraphEdge* edge - cdef public BaseTRule trule + cdef public TRule trule cdef init(self, hypergraph.Hypergraph* hg, unsigned i): self.hg = hg self.edge = &hg.edges_[i] - self.trule = BaseTRule() + self.trule = TRule.__new__(TRule) self.trule.rule = new shared_ptr[grammar.TRule](self.edge.rule_) return self @@ -175,7 +175,7 @@ cdef class HypergraphEdge: property feature_values: def __get__(self): - cdef SparseVector vector = SparseVector() + cdef SparseVector vector = SparseVector.__new__(SparseVector) vector.vector = new FastSparseVector[double](self.edge.feature_values_) return vector diff --git a/python/src/lattice.pxi b/python/src/lattice.pxi index 08405188..14864549 100644 --- a/python/src/lattice.pxi +++ b/python/src/lattice.pxi @@ -16,6 +16,9 @@ cdef class Lattice: self.lattice = new lattice.Lattice() lattice.ConvertTextToLattice(string(inp), self.lattice) + def __dealloc__(self): + del self.lattice + def __getitem__(self, int index): if not 0 <= index < len(self): raise IndexError('lattice index out of range') @@ -51,9 +54,6 @@ cdef class Lattice: for i in range(len(self)): yield self[i] - def __dealloc__(self): - del self.lattice - def todot(self): def lines(): yield 'digraph lattice {' diff --git a/python/src/mteval.pxd b/python/src/mteval.pxd index 27c2808d..c97c4b34 100644 --- a/python/src/mteval.pxd +++ b/python/src/mteval.pxd @@ -38,15 +38,17 @@ cdef extern from "py_scorer.h": string& metric_id, void*, MetricStatsCallback, MetricScoreCallback) cdef extern from "training/candidate_set.h" namespace "training": - cdef cppclass Candidate "const training::Candidate": + cdef cppclass Candidate: vector[WordID] ewords FastSparseVector[weight_t] fmap SufficientStats eval_feats + ctypedef Candidate const_Candidate "const training::Candidate" + cdef cppclass CandidateSet: CandidateSet() unsigned size() - Candidate& operator[](unsigned i) + const_Candidate& operator[](unsigned i) void ReadFromFile(string& file) void WriteToFile(string& file) void AddKBestCandidates(Hypergraph& hg, diff --git a/python/src/mteval.pxi b/python/src/mteval.pxi index 52d2abc6..cd1c3c81 100644 --- a/python/src/mteval.pxi +++ b/python/src/mteval.pxi @@ -10,7 +10,7 @@ cdef SufficientStats as_stats(x, y): return stats cdef class Candidate: - cdef mteval.Candidate* candidate + cdef mteval.const_Candidate* candidate cdef public float score property words: @@ -19,7 +19,7 @@ cdef class Candidate: property fmap: def __get__(self): - cdef SparseVector fmap = SparseVector() + cdef SparseVector fmap = SparseVector.__new__(SparseVector) fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) return fmap diff --git a/python/src/sa/_cdec_sa.c b/python/src/sa/_cdec_sa.c deleted file mode 100644 index 5bd9b28c..00000000 --- a/python/src/sa/_cdec_sa.c +++ /dev/null @@ -1,62490 +0,0 @@ -/* Generated by Cython 0.16 on Fri Jul 27 00:18:44 2012 */ - -#define PY_SSIZE_T_CLEAN -#include "Python.h" -#ifndef Py_PYTHON_H - #error Python headers needed to compile C extensions, please install development version of Python. -#elif PY_VERSION_HEX < 0x02040000 - #error Cython requires Python 2.4+. -#else -#include /* For offsetof */ -#ifndef offsetof -#define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) -#endif - -#if !defined(WIN32) && !defined(MS_WINDOWS) - #ifndef __stdcall - #define __stdcall - #endif - #ifndef __cdecl - #define __cdecl - #endif - #ifndef __fastcall - #define __fastcall - #endif -#endif - -#ifndef DL_IMPORT - #define DL_IMPORT(t) t -#endif -#ifndef DL_EXPORT - #define DL_EXPORT(t) t -#endif - -#ifndef PY_LONG_LONG - #define PY_LONG_LONG LONG_LONG -#endif - -#ifndef Py_HUGE_VAL - #define Py_HUGE_VAL HUGE_VAL -#endif - -#ifdef PYPY_VERSION -#define CYTHON_COMPILING_IN_PYPY 1 -#define CYTHON_COMPILING_IN_CPYTHON 0 -#else -#define CYTHON_COMPILING_IN_PYPY 0 -#define CYTHON_COMPILING_IN_CPYTHON 1 -#endif - -#if CYTHON_COMPILING_IN_PYPY - #define __Pyx_PyCFunction_Call PyObject_Call -#else - #define __Pyx_PyCFunction_Call PyCFunction_Call -#endif - -#if PY_VERSION_HEX < 0x02050000 - typedef int Py_ssize_t; - #define PY_SSIZE_T_MAX INT_MAX - #define PY_SSIZE_T_MIN INT_MIN - #define PY_FORMAT_SIZE_T "" - #define PyInt_FromSsize_t(z) PyInt_FromLong(z) - #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o) - #define PyNumber_Index(o) PyNumber_Int(o) - #define PyIndex_Check(o) PyNumber_Check(o) - #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message) - #define __PYX_BUILD_PY_SSIZE_T "i" -#else - #define __PYX_BUILD_PY_SSIZE_T "n" -#endif - -#if PY_VERSION_HEX < 0x02060000 - #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) - #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) - #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) - #define PyVarObject_HEAD_INIT(type, size) \ - PyObject_HEAD_INIT(type) size, - #define PyType_Modified(t) - - typedef struct { - void *buf; - PyObject *obj; - Py_ssize_t len; - Py_ssize_t itemsize; - int readonly; - int ndim; - char *format; - Py_ssize_t *shape; - Py_ssize_t *strides; - Py_ssize_t *suboffsets; - void *internal; - } Py_buffer; - - #define PyBUF_SIMPLE 0 - #define PyBUF_WRITABLE 0x0001 - #define PyBUF_FORMAT 0x0004 - #define PyBUF_ND 0x0008 - #define PyBUF_STRIDES (0x0010 | PyBUF_ND) - #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) - #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) - #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) - #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) - #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE) - #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE) - - typedef int (*getbufferproc)(PyObject *, Py_buffer *, int); - typedef void (*releasebufferproc)(PyObject *, Py_buffer *); -#endif - -#if PY_MAJOR_VERSION < 3 - #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" - #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ - PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) -#else - #define __Pyx_BUILTIN_MODULE_NAME "builtins" - #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ - PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) -#endif - -#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6 - #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict") -#endif - -#if PY_MAJOR_VERSION >= 3 - #define Py_TPFLAGS_CHECKTYPES 0 - #define Py_TPFLAGS_HAVE_INDEX 0 -#endif - -#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) - #define Py_TPFLAGS_HAVE_NEWBUFFER 0 -#endif - - -#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_GET_LENGTH) - #define CYTHON_PEP393_ENABLED 1 - #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) - #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) -#else - #define CYTHON_PEP393_ENABLED 0 - #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) - #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) -#endif - -#if PY_MAJOR_VERSION >= 3 - #define PyBaseString_Type PyUnicode_Type - #define PyStringObject PyUnicodeObject - #define PyString_Type PyUnicode_Type - #define PyString_Check PyUnicode_Check - #define PyString_CheckExact PyUnicode_CheckExact -#endif - -#if PY_VERSION_HEX < 0x02060000 - #define PyBytesObject PyStringObject - #define PyBytes_Type PyString_Type - #define PyBytes_Check PyString_Check - #define PyBytes_CheckExact PyString_CheckExact - #define PyBytes_FromString PyString_FromString - #define PyBytes_FromStringAndSize PyString_FromStringAndSize - #define PyBytes_FromFormat PyString_FromFormat - #define PyBytes_DecodeEscape PyString_DecodeEscape - #define PyBytes_AsString PyString_AsString - #define PyBytes_AsStringAndSize PyString_AsStringAndSize - #define PyBytes_Size PyString_Size - #define PyBytes_AS_STRING PyString_AS_STRING - #define PyBytes_GET_SIZE PyString_GET_SIZE - #define PyBytes_Repr PyString_Repr - #define PyBytes_Concat PyString_Concat - #define PyBytes_ConcatAndDel PyString_ConcatAndDel -#endif - -#if PY_VERSION_HEX < 0x02060000 - #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) - #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type) -#endif -#ifndef PySet_CheckExact - #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) -#endif - -#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) - -#if PY_MAJOR_VERSION >= 3 - #define PyIntObject PyLongObject - #define PyInt_Type PyLong_Type - #define PyInt_Check(op) PyLong_Check(op) - #define PyInt_CheckExact(op) PyLong_CheckExact(op) - #define PyInt_FromString PyLong_FromString - #define PyInt_FromUnicode PyLong_FromUnicode - #define PyInt_FromLong PyLong_FromLong - #define PyInt_FromSize_t PyLong_FromSize_t - #define PyInt_FromSsize_t PyLong_FromSsize_t - #define PyInt_AsLong PyLong_AsLong - #define PyInt_AS_LONG PyLong_AS_LONG - #define PyInt_AsSsize_t PyLong_AsSsize_t - #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask - #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask -#endif - -#if PY_MAJOR_VERSION >= 3 - #define PyBoolObject PyLongObject -#endif - -#if PY_VERSION_HEX < 0x03020000 - typedef long Py_hash_t; - #define __Pyx_PyInt_FromHash_t PyInt_FromLong - #define __Pyx_PyInt_AsHash_t PyInt_AsLong -#else - #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t - #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t -#endif - -#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300) - #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b) - #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value) - #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b) -#else - #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0))) - #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1))) - #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1))) -#endif - -#if PY_MAJOR_VERSION >= 3 - #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) -#endif - -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) -#else - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) -#endif - -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_NAMESTR(n) ((char *)(n)) - #define __Pyx_DOCSTR(n) ((char *)(n)) -#else - #define __Pyx_NAMESTR(n) (n) - #define __Pyx_DOCSTR(n) (n) -#endif - -#if PY_MAJOR_VERSION >= 3 - #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) - #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) -#else - #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) - #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) -#endif - -#ifndef __PYX_EXTERN_C - #ifdef __cplusplus - #define __PYX_EXTERN_C extern "C" - #else - #define __PYX_EXTERN_C extern - #endif -#endif - -#if defined(WIN32) || defined(MS_WINDOWS) -#define _USE_MATH_DEFINES -#endif -#include -#define __PYX_HAVE___cdec_sa -#define __PYX_HAVE_API___cdec_sa -#include "stdio.h" -#include "stdlib.h" -#include "string.h" -#include "strmap.h" -#include "math.h" -#ifdef _OPENMP -#include -#endif /* _OPENMP */ - -#ifdef PYREX_WITHOUT_ASSERTIONS -#define CYTHON_WITHOUT_ASSERTIONS -#endif - - -/* inline attribute */ -#ifndef CYTHON_INLINE - #if defined(__GNUC__) - #define CYTHON_INLINE __inline__ - #elif defined(_MSC_VER) - #define CYTHON_INLINE __inline - #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - #define CYTHON_INLINE inline - #else - #define CYTHON_INLINE - #endif -#endif - -/* unused attribute */ -#ifndef CYTHON_UNUSED -# if defined(__GNUC__) -# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -#endif - -typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ - - -/* Type Conversion Predeclarations */ - -#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s) -#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s)) - -#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None) -#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) -static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); -static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); - -static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); -static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); - -#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) -#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) - -#ifdef __GNUC__ - /* Test for GCC > 2.95 */ - #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) - #define likely(x) __builtin_expect(!!(x), 1) - #define unlikely(x) __builtin_expect(!!(x), 0) - #else /* __GNUC__ > 2 ... */ - #define likely(x) (x) - #define unlikely(x) (x) - #endif /* __GNUC__ > 2 ... */ -#else /* __GNUC__ */ - #define likely(x) (x) - #define unlikely(x) (x) -#endif /* __GNUC__ */ - -static PyObject *__pyx_m; -static PyObject *__pyx_b; -static PyObject *__pyx_empty_tuple; -static PyObject *__pyx_empty_bytes; -static int __pyx_lineno; -static int __pyx_clineno = 0; -static const char * __pyx_cfilenm= __FILE__; -static const char *__pyx_filename; - - -static const char *__pyx_f[] = { - "_cdec_sa.pyx", - "float_list.pxi", - "int_list.pxi", - "data_array.pxi", - "alignment.pxi", - "bilex.pxi", - "veb.pxi", - "rule.pxi", - "rulefactory.pxi", - "lcp.pxi", - "sym.pxi", - "precomputation.pxi", - "suffix_array.pxi", - "str_map.pxi", -}; - -/*--- Type declarations ---*/ -struct __pyx_obj_8_cdec_sa_VEB; -struct __pyx_obj_8_cdec_sa_Sampler; -struct __pyx_obj_8_cdec_sa_BitSet; -struct __pyx_obj_8_cdec_sa_DataArray; -struct __pyx_obj_8_cdec_sa_TrieNode; -struct __pyx_obj_8_cdec_sa_VEBIterator; -struct __pyx_obj_8_cdec_sa_BitSetIterator; -struct __pyx_obj_8_cdec_sa_Phrase; -struct __pyx_obj_8_cdec_sa_IntList; -struct __pyx_obj_8_cdec_sa_ExtendedTrieNode; -struct __pyx_obj_8_cdec_sa_PhraseLocation; -struct __pyx_obj_8_cdec_sa_Rule; -struct __pyx_obj_8_cdec_sa_LCP; -struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory; -struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats; -struct __pyx_obj_8_cdec_sa_BiLex; -struct __pyx_obj_8_cdec_sa_SuffixArray; -struct __pyx_obj_8_cdec_sa_StringMap; -struct __pyx_obj_8_cdec_sa_TrieMap; -struct __pyx_obj_8_cdec_sa_Alphabet; -struct __pyx_obj_8_cdec_sa_Alignment; -struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input; -struct __pyx_obj_8_cdec_sa_Precomputation; -struct __pyx_obj_8_cdec_sa_FloatList; -struct __pyx_obj_8_cdec_sa_TrieTable; -struct __pyx_t_8_cdec_sa__node; -struct __pyx_t_8_cdec_sa__BitSet; -struct __pyx_t_8_cdec_sa__VEB; -struct __pyx_t_8_cdec_sa__Trie_Edge; -struct __pyx_t_8_cdec_sa__Trie_Node; -struct __pyx_t_8_cdec_sa_match_node; -struct __pyx_t_8_cdec_sa_Matching; - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":9 - * from libc.string cimport memset, strcpy, strlen - * - * cdef struct _node: # <<<<<<<<<<<<<< - * _node* smaller - * _node* bigger - */ -struct __pyx_t_8_cdec_sa__node { - struct __pyx_t_8_cdec_sa__node *smaller; - struct __pyx_t_8_cdec_sa__node *bigger; - int key; - int val; -}; - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":30 - * _init_lower_mask() - * - * cdef struct _BitSet: # <<<<<<<<<<<<<< - * long bitset - * int min_val - */ -struct __pyx_t_8_cdec_sa__BitSet { - long bitset; - int min_val; - int max_val; - int size; -}; - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":168 - * return result - * - * cdef struct _VEB: # <<<<<<<<<<<<<< - * int top_universe_size - * int num_bottom_bits - */ -struct __pyx_t_8_cdec_sa__VEB { - int top_universe_size; - int num_bottom_bits; - int max_val; - int min_val; - int size; - void *top; - void **bottom; -}; - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":10 - * cdef struct _Trie_Node # forward decl - * - * cdef struct _Trie_Edge: # <<<<<<<<<<<<<< - * int val - * _Trie_Node* node - */ -struct __pyx_t_8_cdec_sa__Trie_Edge { - int val; - struct __pyx_t_8_cdec_sa__Trie_Node *node; - struct __pyx_t_8_cdec_sa__Trie_Edge *bigger; - struct __pyx_t_8_cdec_sa__Trie_Edge *smaller; -}; - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":8 - * from libc.string cimport memset, memcpy - * - * cdef struct _Trie_Node # forward decl # <<<<<<<<<<<<<< - * - * cdef struct _Trie_Edge: - */ -struct __pyx_t_8_cdec_sa__Trie_Node { - struct __pyx_t_8_cdec_sa__Trie_Edge *root; - int *arr; - int arr_len; -}; - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":48 - * - * # linked list structure for storing matches in BaselineRuleFactory - * cdef struct match_node: # <<<<<<<<<<<<<< - * int* match - * match_node* next - */ -struct __pyx_t_8_cdec_sa_match_node { - int *match; - struct __pyx_t_8_cdec_sa_match_node *next; -}; - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":145 - * - * # struct used to encapsulate a single matching - * cdef struct Matching: # <<<<<<<<<<<<<< - * int* arr - * int start - */ -struct __pyx_t_8_cdec_sa_Matching { - int *arr; - int start; - int end; - int sent_id; - int size; -}; - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":354 - * - * - * cdef class VEB: # <<<<<<<<<<<<<< - * cdef _VEB* veb - * cdef int _findsucc(self, int i) - */ -struct __pyx_obj_8_cdec_sa_VEB { - PyObject_HEAD - struct __pyx_vtabstruct_8_cdec_sa_VEB *__pyx_vtab; - struct __pyx_t_8_cdec_sa__VEB *veb; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":79 - * - * - * cdef class Sampler: # <<<<<<<<<<<<<< - * '''A Sampler implements a logic for choosing - * samples from a population range''' - */ -struct __pyx_obj_8_cdec_sa_Sampler { - PyObject_HEAD - int sample_size; - struct __pyx_obj_8_cdec_sa_IntList *sa; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":118 - * # (entirely C-implemented) _BitSet struct. - * # Very slow; use only for debugging - * cdef class BitSet: # <<<<<<<<<<<<<< - * - * cdef _BitSet* b - */ -struct __pyx_obj_8_cdec_sa_BitSet { - PyObject_HEAD - struct __pyx_t_8_cdec_sa__BitSet *b; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":9 - * from libc.string cimport memset, strcpy, strlen - * - * cdef class DataArray: # <<<<<<<<<<<<<< - * cdef word2id - * cdef id2word - */ -struct __pyx_obj_8_cdec_sa_DataArray { - PyObject_HEAD - struct __pyx_vtabstruct_8_cdec_sa_DataArray *__pyx_vtab; - PyObject *word2id; - PyObject *id2word; - struct __pyx_obj_8_cdec_sa_IntList *data; - struct __pyx_obj_8_cdec_sa_IntList *sent_id; - struct __pyx_obj_8_cdec_sa_IntList *sent_index; - int use_sent_id; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":18 - * cdef int EPSILON = sym_fromstring('*EPS*', True) - * - * cdef class TrieNode: # <<<<<<<<<<<<<< - * cdef public children - * - */ -struct __pyx_obj_8_cdec_sa_TrieNode { - PyObject_HEAD - PyObject *children; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":340 - * - * - * cdef class VEBIterator: # <<<<<<<<<<<<<< - * cdef _VEB* v - * cdef int next_val - */ -struct __pyx_obj_8_cdec_sa_VEBIterator { - PyObject_HEAD - struct __pyx_t_8_cdec_sa__VEB *v; - int next_val; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":100 - * - * - * cdef class BitSetIterator: # <<<<<<<<<<<<<< - * cdef _BitSet* b - * cdef int next_val - */ -struct __pyx_obj_8_cdec_sa_BitSetIterator { - PyObject_HEAD - struct __pyx_t_8_cdec_sa__BitSet *b; - int next_val; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":4 - * from libc.string cimport strsep, strcpy, strlen - * - * cdef class Phrase: # <<<<<<<<<<<<<< - * cdef int *syms - * cdef int n, *varpos, n_vars - */ -struct __pyx_obj_8_cdec_sa_Phrase { - PyObject_HEAD - struct __pyx_vtabstruct_8_cdec_sa_Phrase *__pyx_vtab; - int *syms; - int n; - int *varpos; - int n_vars; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":9 - * from libc.string cimport memset, memcpy - * - * cdef class IntList: # <<<<<<<<<<<<<< - * cdef int size - * cdef int increment - */ -struct __pyx_obj_8_cdec_sa_IntList { - PyObject_HEAD - struct __pyx_vtabstruct_8_cdec_sa_IntList *__pyx_vtab; - int size; - int increment; - int len; - int *arr; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":24 - * self.children = {} - * - * cdef class ExtendedTrieNode(TrieNode): # <<<<<<<<<<<<<< - * cdef public phrase - * cdef public phrase_location - */ -struct __pyx_obj_8_cdec_sa_ExtendedTrieNode { - struct __pyx_obj_8_cdec_sa_TrieNode __pyx_base; - PyObject *phrase; - PyObject *phrase_location; - PyObject *suffix_link; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":56 - * # in the suffix array; if discontiguous, it is the set of - * # actual locations (packed into an array) - * cdef class PhraseLocation: # <<<<<<<<<<<<<< - * cdef int sa_low - * cdef int sa_high - */ -struct __pyx_obj_8_cdec_sa_PhraseLocation { - PyObject_HEAD - struct __pyx_vtabstruct_8_cdec_sa_PhraseLocation *__pyx_vtab; - int sa_low; - int sa_high; - int arr_low; - int arr_high; - struct __pyx_obj_8_cdec_sa_IntList *arr; - int num_subpatterns; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":159 - * return start - * - * cdef class Rule: # <<<<<<<<<<<<<< - * cdef public int lhs - * cdef readonly Phrase f, e - */ -struct __pyx_obj_8_cdec_sa_Rule { - PyObject_HEAD - int lhs; - struct __pyx_obj_8_cdec_sa_Phrase *f; - struct __pyx_obj_8_cdec_sa_Phrase *e; - float *cscores; - int n_scores; - PyObject *word_alignments; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":5 - * as k most frequent n-grams""" - * - * cdef class LCP: # <<<<<<<<<<<<<< - * cdef SuffixArray sa - * cdef IntList lcp - */ -struct __pyx_obj_8_cdec_sa_LCP { - PyObject_HEAD - struct __pyx_obj_8_cdec_sa_SuffixArray *sa; - struct __pyx_obj_8_cdec_sa_IntList *lcp; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":201 - * - * - * cdef class HieroCachingRuleFactory: # <<<<<<<<<<<<<< - * '''This RuleFactory implements a caching - * method using TrieTable, which makes phrase - */ -struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory { - PyObject_HEAD - struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *__pyx_vtab; - struct __pyx_obj_8_cdec_sa_TrieTable *rules; - struct __pyx_obj_8_cdec_sa_Sampler *sampler; - int max_chunks; - int max_target_chunks; - int max_length; - int max_target_length; - int max_nonterminals; - int max_initial_size; - int train_max_initial_size; - int min_gap_size; - int train_min_gap_size; - int category; - PyObject *precomputed_index; - PyObject *precomputed_collocations; - PyObject *precompute_file; - PyObject *max_rank; - int precompute_rank; - int precompute_secondary_rank; - int use_baeza_yates; - int use_index; - int use_collocations; - float by_slack_factor; - PyObject *prev_norm_prefix; - float extract_time; - struct __pyx_obj_8_cdec_sa_SuffixArray *fsa; - struct __pyx_obj_8_cdec_sa_DataArray *fda; - struct __pyx_obj_8_cdec_sa_DataArray *eda; - struct __pyx_obj_8_cdec_sa_Alignment *alignment; - struct __pyx_obj_8_cdec_sa_IntList *eid2symid; - struct __pyx_obj_8_cdec_sa_IntList *fid2symid; - int tight_phrases; - int require_aligned_terminal; - int require_aligned_chunks; - struct __pyx_obj_8_cdec_sa_IntList *findexes; - struct __pyx_obj_8_cdec_sa_IntList *findexes1; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":36 - * logger.info("LCP array completed") - * - * def compute_stats(self, int max_n): # <<<<<<<<<<<<<< - * """Note: the output of this function is not exact. In - * particular, the frequency associated with each word is - */ -struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats { - PyObject_HEAD - int __pyx_v_N; - int __pyx_v_freq; - int __pyx_v_h; - int __pyx_v_i; - int __pyx_v_ii; - int __pyx_v_iii; - int __pyx_v_j; - int __pyx_v_k; - int __pyx_v_max_n; - int __pyx_v_n; - PyObject *__pyx_v_ngram; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_ngram_start; - PyObject *__pyx_v_ngram_starts; - int __pyx_v_rs; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_run_start; - struct __pyx_obj_8_cdec_sa_LCP *__pyx_v_self; - int __pyx_v_valid; - struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_veb; - int __pyx_t_0; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":47 - * - * - * cdef class BiLex: # <<<<<<<<<<<<<< - * cdef FloatList col1 - * cdef FloatList col2 - */ -struct __pyx_obj_8_cdec_sa_BiLex { - PyObject_HEAD - struct __pyx_vtabstruct_8_cdec_sa_BiLex *__pyx_vtab; - struct __pyx_obj_8_cdec_sa_FloatList *col1; - struct __pyx_obj_8_cdec_sa_FloatList *col2; - struct __pyx_obj_8_cdec_sa_IntList *f_index; - struct __pyx_obj_8_cdec_sa_IntList *e_index; - PyObject *id2eword; - PyObject *id2fword; - PyObject *eword2id; - PyObject *fword2id; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":6 - * from libc.stdio cimport FILE, fclose, fopen - * - * cdef class SuffixArray: # <<<<<<<<<<<<<< - * cdef DataArray darray - * cdef IntList sa - */ -struct __pyx_obj_8_cdec_sa_SuffixArray { - PyObject_HEAD - struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *__pyx_vtab; - struct __pyx_obj_8_cdec_sa_DataArray *darray; - struct __pyx_obj_8_cdec_sa_IntList *sa; - struct __pyx_obj_8_cdec_sa_IntList *ha; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":8 - * char* stringmap_word(StrMap *vocab, int i) - * - * cdef class StringMap: # <<<<<<<<<<<<<< - * cdef StrMap *vocab - * cdef char *word(self, int i) - */ -struct __pyx_obj_8_cdec_sa_StringMap { - PyObject_HEAD - struct __pyx_vtabstruct_8_cdec_sa_StringMap *__pyx_vtab; - StrMap *vocab; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":109 - * trie_node_to_map(edge.node, result, prefix, include_zeros) - * - * cdef class TrieMap: # <<<<<<<<<<<<<< - * - * cdef _Trie_Node** root - */ -struct __pyx_obj_8_cdec_sa_TrieMap { - PyObject_HEAD - struct __pyx_vtabstruct_8_cdec_sa_TrieMap *__pyx_vtab; - struct __pyx_t_8_cdec_sa__Trie_Node **root; - int V; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":7 - * cdef int INDEX_MASK = (1<SetupContext((name), __LINE__, __FILE__); \ - PyGILState_Release(__pyx_gilstate_save); \ - } else { \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \ - } -#else - #define __Pyx_RefNannySetupContext(name, acquire_gil) \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) -#endif - #define __Pyx_RefNannyFinishContext() \ - __Pyx_RefNanny->FinishContext(&__pyx_refnanny) - #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) - #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) - #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) - #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) - #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) -#else - #define __Pyx_RefNannyDeclarations - #define __Pyx_RefNannySetupContext(name, acquire_gil) - #define __Pyx_RefNannyFinishContext() - #define __Pyx_INCREF(r) Py_INCREF(r) - #define __Pyx_DECREF(r) Py_DECREF(r) - #define __Pyx_GOTREF(r) - #define __Pyx_GIVEREF(r) - #define __Pyx_XINCREF(r) Py_XINCREF(r) - #define __Pyx_XDECREF(r) Py_XDECREF(r) - #define __Pyx_XGOTREF(r) - #define __Pyx_XGIVEREF(r) -#endif /* CYTHON_REFNANNY */ -#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) -#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ - -static int __Pyx_PyBytes_SingleTailmatch(PyObject* self, PyObject* arg, Py_ssize_t start, - Py_ssize_t end, int direction) -{ - const char* self_ptr = PyBytes_AS_STRING(self); - Py_ssize_t self_len = PyBytes_GET_SIZE(self); - const char* sub_ptr; - Py_ssize_t sub_len; - int retval; -#if PY_VERSION_HEX >= 0x02060000 - Py_buffer view; - view.obj = NULL; -#endif - if ( PyBytes_Check(arg) ) { - sub_ptr = PyBytes_AS_STRING(arg); - sub_len = PyBytes_GET_SIZE(arg); - } -#if PY_MAJOR_VERSION < 3 - else if ( PyUnicode_Check(arg) ) { - return PyUnicode_Tailmatch(self, arg, start, end, direction); - } -#endif - else { -#if PY_VERSION_HEX < 0x02060000 - if (unlikely(PyObject_AsCharBuffer(arg, &sub_ptr, &sub_len))) - return -1; -#else - if (unlikely(PyObject_GetBuffer(self, &view, PyBUF_SIMPLE) == -1)) - return -1; - sub_ptr = (const char*) view.buf; - sub_len = view.len; -#endif - } - if (end > self_len) - end = self_len; - else if (end < 0) - end += self_len; - if (end < 0) - end = 0; - if (start < 0) - start += self_len; - if (start < 0) - start = 0; - if (direction > 0) { - if (end-sub_len > start) - start = end - sub_len; - } - if (start + sub_len <= end) - retval = !memcmp(self_ptr+start, sub_ptr, sub_len); - else - retval = 0; -#if PY_VERSION_HEX >= 0x02060000 - if (view.obj) - PyBuffer_Release(&view); -#endif - return retval; -} -static int __Pyx_PyBytes_Tailmatch(PyObject* self, PyObject* substr, Py_ssize_t start, - Py_ssize_t end, int direction) -{ - if (unlikely(PyTuple_Check(substr))) { - int result; - Py_ssize_t i; - for (i = 0; i < PyTuple_GET_SIZE(substr); i++) { - result = __Pyx_PyBytes_SingleTailmatch(self, PyTuple_GET_ITEM(substr, i), - start, end, direction); - if (result) { - return result; - } - } - return 0; - } - return __Pyx_PyBytes_SingleTailmatch(self, substr, start, end, direction); -} - -static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/ - -static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ - PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \ - const char* function_name); /*proto*/ - -static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, - Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ - -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ - -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/ - -static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ - -static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); /*proto*/ - -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { - PyObject *r; - if (!j) return NULL; - r = PyObject_GetItem(o, j); - Py_DECREF(j); - return r; -} -#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_List_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) { - if (likely(o != Py_None)) { - if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { - PyObject *r = PyList_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) { - PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i); - Py_INCREF(r); - return r; - } - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -} -#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_Tuple_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) { - if (likely(o != Py_None)) { - if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) { - PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i); - Py_INCREF(r); - return r; - } - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -} -#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_GetItemInt_Fast(o, i) : \ - __Pyx_GetItemInt_Generic(o, to_py_func(i))) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) { - if (PyList_CheckExact(o)) { - Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); - if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) { - PyObject *r = PyList_GET_ITEM(o, n); - Py_INCREF(r); - return r; - } - } - else if (PyTuple_CheckExact(o)) { - Py_ssize_t n = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); - if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, n); - Py_INCREF(r); - return r; - } - } - else if (likely(i >= 0)) { - PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; - if (likely(m && m->sq_item)) { - return m->sq_item(o, i); - } - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -} - -static CYTHON_INLINE int __Pyx_NegateNonNeg(int b) { - return unlikely(b < 0) ? b : !b; -} -static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) { - return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b); -} - -static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) { - if (likely(PyList_CheckExact(L))) { - if (PyList_Append(L, x) < 0) return NULL; - Py_INCREF(Py_None); - return Py_None; /* this is just to have an accurate signature */ - } - else { - PyObject *r, *m; - m = __Pyx_GetAttrString(L, "append"); - if (!m) return NULL; - r = PyObject_CallFunctionObjArgs(m, x, NULL); - Py_DECREF(m); - return r; - } -} - -static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ - -static CYTHON_INLINE long __Pyx_div_long(long, long); /* proto */ - -static CYTHON_INLINE long __Pyx_mod_long(long, long); /* proto */ - -static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); - -static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); - -static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/ - -#define __Pyx_SetItemInt(o, i, v, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ - __Pyx_SetItemInt_Fast(o, i, v) : \ - __Pyx_SetItemInt_Generic(o, to_py_func(i), v)) -static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) { - int r; - if (!j) return -1; - r = PyObject_SetItem(o, j, v); - Py_DECREF(j); - return r; -} -static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v) { - if (PyList_CheckExact(o)) { - Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); - if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) { - PyObject* old = PyList_GET_ITEM(o, n); - Py_INCREF(v); - PyList_SET_ITEM(o, n, v); - Py_DECREF(old); - return 1; - } - } - else if (likely(i >= 0)) { - PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; - if (likely(m && m->sq_ass_item)) { - return m->sq_ass_item(o, i, v); - } - } - return __Pyx_SetItemInt_Generic(o, PyInt_FromSsize_t(i), v); -} - -static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */ -#define __Pyx_PyObject_AsDouble(obj) \ -((likely(PyFloat_CheckExact(obj))) ? \ - PyFloat_AS_DOUBLE(obj) : __Pyx__PyObject_AsDouble(obj)) - -static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname); - -static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, - const char *name, int exact); /*proto*/ - -#if PY_VERSION_HEX < 0x02050000 -#ifndef PyAnySet_CheckExact -#define PyAnySet_CheckExact(ob) \ - ((ob)->ob_type == &PySet_Type || \ - (ob)->ob_type == &PyFrozenSet_Type) -#define PySet_New(iterable) \ - PyObject_CallFunctionObjArgs((PyObject *)&PySet_Type, (iterable), NULL) -#define Pyx_PyFrozenSet_New(iterable) \ - PyObject_CallFunctionObjArgs((PyObject *)&PyFrozenSet_Type, (iterable), NULL) -#define PySet_Size(anyset) \ - PyObject_Size((anyset)) -#define PySet_Contains(anyset, key) \ - PySequence_Contains((anyset), (key)) -#define PySet_Pop(set) \ - PyObject_CallMethod(set, (char *)"pop", NULL) -static CYTHON_INLINE int PySet_Clear(PyObject *set) { - PyObject *ret = PyObject_CallMethod(set, (char *)"clear", NULL); - if (!ret) return -1; - Py_DECREF(ret); return 0; -} -static CYTHON_INLINE int PySet_Discard(PyObject *set, PyObject *key) { - PyObject *ret = PyObject_CallMethod(set, (char *)"discard", (char *)"O", key); - if (!ret) return -1; - Py_DECREF(ret); return 0; -} -static CYTHON_INLINE int PySet_Add(PyObject *set, PyObject *key) { - PyObject *ret = PyObject_CallMethod(set, (char *)"add", (char *)"O", key); - if (!ret) return -1; - Py_DECREF(ret); return 0; -} -#endif /* PyAnySet_CheckExact (<= Py2.4) */ -#endif /* < Py2.5 */ - -static CYTHON_INLINE void __Pyx_RaiseNoneIndexingError(void); - -#if PY_MAJOR_VERSION >= 3 -static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { - PyObject *value; - if (unlikely(d == Py_None)) { - __Pyx_RaiseNoneIndexingError(); - return NULL; - } - value = PyDict_GetItemWithError(d, key); - if (unlikely(!value)) { - if (!PyErr_Occurred()) - PyErr_SetObject(PyExc_KeyError, key); - return NULL; - } - Py_INCREF(value); - return value; -} -#else - #define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key) -#endif - -static CYTHON_INLINE int __Pyx_div_int(int, int); /* proto */ - -#define UNARY_NEG_WOULD_OVERFLOW(x) (((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x))) - -static CYTHON_INLINE PyObject* __Pyx_PyObject_Pop(PyObject* L) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02040000 - if (likely(PyList_CheckExact(L)) - && likely(PyList_GET_SIZE(L) > (((PyListObject*)L)->allocated >> 1))) { - Py_SIZE(L) -= 1; - return PyList_GET_ITEM(L, PyList_GET_SIZE(L)); - } -#if PY_VERSION_HEX >= 0x02050000 - else if (Py_TYPE(L) == (&PySet_Type)) { - return PySet_Pop(L); - } -#endif -#endif - return PyObject_CallMethod(L, (char*)"pop", NULL); -} - -static PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value) { - PyObject* value; -#if PY_MAJOR_VERSION >= 3 - value = PyDict_GetItemWithError(d, key); - if (unlikely(!value)) { - if (unlikely(PyErr_Occurred())) - return NULL; - if (unlikely(PyDict_SetItem(d, key, default_value) == -1)) - return NULL; - value = default_value; - } - Py_INCREF(value); -#else - if (PyString_CheckExact(key) || PyUnicode_CheckExact(key) || PyInt_CheckExact(key)) { - value = PyDict_GetItem(d, key); - if (unlikely(!value)) { - if (unlikely(PyDict_SetItem(d, key, default_value) == -1)) - return NULL; - value = default_value; - } - Py_INCREF(value); - } else { - PyObject *m; - m = __Pyx_GetAttrString(d, "setdefault"); - if (!m) return NULL; - value = PyObject_CallFunctionObjArgs(m, key, default_value, NULL); - Py_DECREF(m); - } -#endif - return value; -} - -static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ -static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ - -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/ - -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); - -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); - -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); - -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); - -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); - -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); - -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); - -static void __Pyx_WriteUnraisable(const char *name, int clineno, - int lineno, const char *filename); /*proto*/ - -static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ - -#define __Pyx_Generator_USED -#include -typedef PyObject *(*__pyx_generator_body_t)(PyObject *, PyObject *); -typedef struct { - PyObject_HEAD - __pyx_generator_body_t body; - PyObject *closure; - int is_running; - int resume_label; - PyObject *exc_type; - PyObject *exc_value; - PyObject *exc_traceback; - PyObject *gi_weakreflist; - PyObject *classobj; -} __pyx_GeneratorObject; -static __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body, - PyObject *closure); -static int __pyx_Generator_init(void); - -static int __Pyx_check_binary_version(void); - -static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ - -typedef struct { - int code_line; - PyCodeObject* code_object; -} __Pyx_CodeObjectCacheEntry; -struct __Pyx_CodeObjectCache { - int count; - int max_count; - __Pyx_CodeObjectCacheEntry* entries; -}; -static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; -static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); -static PyCodeObject *__pyx_find_code_object(int code_line); -static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); - -static void __Pyx_AddTraceback(const char *funcname, int c_line, - int py_line, const char *filename); /*proto*/ - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ - - -/* Module declarations from 'libc.stdio' */ - -/* Module declarations from 'libc.stdlib' */ - -/* Module declarations from 'libc.string' */ - -/* Module declarations from 'libc.math' */ - -/* Module declarations from '_cdec_sa' */ -static PyTypeObject *__pyx_ptype_8_cdec_sa_FloatList = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_IntList = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_StringMap = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_DataArray = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_Alignment = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_BiLex = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_BitSetIterator = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_BitSet = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_VEBIterator = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_VEB = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_LCP = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_Alphabet = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_Phrase = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_Rule = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_TrieMap = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_Precomputation = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_SuffixArray = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_TrieNode = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_ExtendedTrieNode = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_TrieTable = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_PhraseLocation = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_Sampler = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa_HieroCachingRuleFactory = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa___pyx_scope_struct__compute_stats = 0; -static PyTypeObject *__pyx_ptype_8_cdec_sa___pyx_scope_struct_1_input = 0; -static int __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE; -static int __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS; -static int __pyx_v_8_cdec_sa_LOWER_MASK[32]; -static int __pyx_v_8_cdec_sa_INDEX_SHIFT; -static int __pyx_v_8_cdec_sa_INDEX_MASK; -static struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_8_cdec_sa_ALPHABET = 0; -static int __pyx_v_8_cdec_sa_PRECOMPUTE; -static int __pyx_v_8_cdec_sa_MERGE; -static int __pyx_v_8_cdec_sa_BAEZA_YATES; -static int __pyx_v_8_cdec_sa_EPSILON; -static float __pyx_f_8_cdec_sa_monitor_cpu(void); /*proto*/ -static struct __pyx_t_8_cdec_sa__node *__pyx_f_8_cdec_sa_new_node(int); /*proto*/ -static PyObject *__pyx_f_8_cdec_sa_del_node(struct __pyx_t_8_cdec_sa__node *); /*proto*/ -static int *__pyx_f_8_cdec_sa_get_val(struct __pyx_t_8_cdec_sa__node *, int); /*proto*/ -static void __pyx_f_8_cdec_sa__init_lower_mask(void); /*proto*/ -static struct __pyx_t_8_cdec_sa__BitSet *__pyx_f_8_cdec_sa_new_BitSet(void); /*proto*/ -static int __pyx_f_8_cdec_sa_bitset_findsucc(struct __pyx_t_8_cdec_sa__BitSet *, int); /*proto*/ -static int __pyx_f_8_cdec_sa_bitset_insert(struct __pyx_t_8_cdec_sa__BitSet *, int); /*proto*/ -static int __pyx_f_8_cdec_sa_bitset_contains(struct __pyx_t_8_cdec_sa__BitSet *, int); /*proto*/ -static PyObject *__pyx_f_8_cdec_sa_dec2bin(long); /*proto*/ -static struct __pyx_t_8_cdec_sa__VEB *__pyx_f_8_cdec_sa_new_VEB(int); /*proto*/ -static int __pyx_f_8_cdec_sa_VEB_insert(struct __pyx_t_8_cdec_sa__VEB *, int); /*proto*/ -static PyObject *__pyx_f_8_cdec_sa_del_VEB(struct __pyx_t_8_cdec_sa__VEB *); /*proto*/ -static int __pyx_f_8_cdec_sa_VEB_findsucc(struct __pyx_t_8_cdec_sa__VEB *, int); /*proto*/ -static int __pyx_f_8_cdec_sa_VEB_contains(struct __pyx_t_8_cdec_sa__VEB *, int); /*proto*/ -static int __pyx_f_8_cdec_sa_sym_setindex(int, int); /*proto*/ -static struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_f_8_cdec_sa_new_trie_node(void); /*proto*/ -static struct __pyx_t_8_cdec_sa__Trie_Edge *__pyx_f_8_cdec_sa_new_trie_edge(int); /*proto*/ -static PyObject *__pyx_f_8_cdec_sa_free_trie_node(struct __pyx_t_8_cdec_sa__Trie_Node *); /*proto*/ -static PyObject *__pyx_f_8_cdec_sa_free_trie_edge(struct __pyx_t_8_cdec_sa__Trie_Edge *); /*proto*/ -static struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_f_8_cdec_sa_trie_find(struct __pyx_t_8_cdec_sa__Trie_Node *, int); /*proto*/ -static PyObject *__pyx_f_8_cdec_sa_trie_node_data_append(struct __pyx_t_8_cdec_sa__Trie_Node *, int); /*proto*/ -static struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_f_8_cdec_sa_trie_insert(struct __pyx_t_8_cdec_sa__Trie_Node *, int); /*proto*/ -static PyObject *__pyx_f_8_cdec_sa_trie_node_to_map(struct __pyx_t_8_cdec_sa__Trie_Node *, PyObject *, PyObject *, int); /*proto*/ -static PyObject *__pyx_f_8_cdec_sa_trie_edge_to_map(struct __pyx_t_8_cdec_sa__Trie_Edge *, PyObject *, PyObject *, int); /*proto*/ -static void __pyx_f_8_cdec_sa_assign_matching(struct __pyx_t_8_cdec_sa_Matching *, int *, int, int, int *); /*proto*/ -static int *__pyx_f_8_cdec_sa_append_combined_matching(int *, struct __pyx_t_8_cdec_sa_Matching *, struct __pyx_t_8_cdec_sa_Matching *, int, int, int *); /*proto*/ -static int *__pyx_f_8_cdec_sa_extend_arr(int *, int *, int *, int); /*proto*/ -static int __pyx_f_8_cdec_sa_median(int, int, int); /*proto*/ -static void __pyx_f_8_cdec_sa_find_comparable_matchings(int, int, int *, int, int, int *, int *); /*proto*/ -#define __Pyx_MODULE_NAME "_cdec_sa" -int __pyx_module_is_main__cdec_sa = 0; - -/* Implementation of '_cdec_sa' */ -static PyObject *__pyx_builtin_open; -static PyObject *__pyx_builtin_IndexError; -static PyObject *__pyx_builtin_range; -static PyObject *__pyx_builtin_TypeError; -static PyObject *__pyx_builtin_enumerate; -static PyObject *__pyx_builtin_map; -static PyObject *__pyx_builtin_Exception; -static PyObject *__pyx_builtin_zip; -static PyObject *__pyx_builtin_StopIteration; -static PyObject *__pyx_builtin_cmp; -static PyObject *__pyx_builtin_ValueError; -static PyObject *__pyx_builtin_sorted; -static PyObject *__pyx_pf_8_cdec_sa_gzip_or_text(CYTHON_UNUSED PyObject *__pyx_self, char *__pyx_v_filename); /* proto */ -static int __pyx_pf_8_cdec_sa_9FloatList___cinit__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, int __pyx_v_size, int __pyx_v_increment, int __pyx_v_initial_len); /* proto */ -static void __pyx_pf_8_cdec_sa_9FloatList_2__dealloc__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9FloatList_4__getitem__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ -static int __pyx_pf_8_cdec_sa_9FloatList_6__setitem__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val); /* proto */ -static Py_ssize_t __pyx_pf_8_cdec_sa_9FloatList_8__len__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9FloatList_10append(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, float __pyx_v_val); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9FloatList_12write(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9FloatList_14read(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static int __pyx_pf_8_cdec_sa_7IntList___cinit__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, int __pyx_v_size, int __pyx_v_increment, int __pyx_v_initial_len); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_7IntList_2__str__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_7IntList_4index(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_val); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_7IntList_6partition(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_end); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_7IntList_8_doquicksort(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_end); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_7IntList_10sort(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_7IntList_12reset(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self); /* proto */ -static void __pyx_pf_8_cdec_sa_7IntList_14__dealloc__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_7IntList_16__getitem__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_index); /* proto */ -static int __pyx_pf_8_cdec_sa_7IntList_18__setitem__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val); /* proto */ -static Py_ssize_t __pyx_pf_8_cdec_sa_7IntList_20__len__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_7IntList_22getSize(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_7IntList_24append(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, int __pyx_v_val); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_7IntList_26extend(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_7IntList_28write(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_7IntList_30read(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static int __pyx_pf_8_cdec_sa_9StringMap___cinit__(struct __pyx_obj_8_cdec_sa_StringMap *__pyx_v_self); /* proto */ -static void __pyx_pf_8_cdec_sa_9StringMap_2__dealloc__(struct __pyx_obj_8_cdec_sa_StringMap *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_9DataArray___cinit__(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text, int __pyx_v_use_sent_id); /* proto */ -static Py_ssize_t __pyx_pf_8_cdec_sa_9DataArray_2__len__(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_4getSentId(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_6getSent(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_8getSentPos(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_loc); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_10get_id(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_word); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_12get_word(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_id); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_14write_text(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_16read_text(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_18read_binary(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_20write_binary(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_22write_enhanced_handle(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_f); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_24write_enhanced(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9Alignment_unlink(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_link); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9Alignment_2get_sent_links(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, int __pyx_v_sent_id); /* proto */ -static int __pyx_pf_8_cdec_sa_9Alignment_4__cinit__(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9Alignment_6read_text(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9Alignment_8read_binary(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9Alignment_10write_text(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9Alignment_12write_binary(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9Alignment_14write_enhanced(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9Alignment_16alignment(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ -static int __pyx_pf_8_cdec_sa_5BiLex___cinit__(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_from_text, PyObject *__pyx_v_from_data, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_earray, PyObject *__pyx_v_fsarray, PyObject *__pyx_v_alignment); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_5BiLex_2write_binary(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_5BiLex_4read_binary(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_5BiLex_6get_e_id(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_eword); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_5BiLex_8get_f_id(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_fword); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_5BiLex_10read_text(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_5BiLex_12write_enhanced(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_5BiLex_14get_score(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_fword, PyObject *__pyx_v_eword, PyObject *__pyx_v_col); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_5BiLex_16write_text(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_14BitSetIterator___next__(struct __pyx_obj_8_cdec_sa_BitSetIterator *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_6BitSet___cinit__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self); /* proto */ -static void __pyx_pf_8_cdec_sa_6BitSet_2__dealloc__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_6BitSet_4__iter__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_6BitSet_6insert(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_6BitSet_8findsucc(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_6BitSet_10__str__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_6BitSet_12min(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_6BitSet_14max(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self); /* proto */ -static Py_ssize_t __pyx_pf_8_cdec_sa_6BitSet_16__len__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_6BitSet_18__contains__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_11VEBIterator___next__(struct __pyx_obj_8_cdec_sa_VEBIterator *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_3VEB___cinit__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, int __pyx_v_size); /* proto */ -static void __pyx_pf_8_cdec_sa_3VEB_2__dealloc__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_3VEB_4__iter__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_3VEB_6insert(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_3VEB_8findsucc(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ -static Py_ssize_t __pyx_pf_8_cdec_sa_3VEB_10__len__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_3VEB_12__contains__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ -static int __pyx_pf_8_cdec_sa_3LCP___cinit__(struct __pyx_obj_8_cdec_sa_LCP *__pyx_v_self, struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_sa); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_3LCP_2compute_stats(struct __pyx_obj_8_cdec_sa_LCP *__pyx_v_self, int __pyx_v_max_n); /* proto */ -static int __pyx_pf_8_cdec_sa_8Alphabet___cinit__(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self); /* proto */ -static void __pyx_pf_8_cdec_sa_8Alphabet_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_8Alphabet_9terminals___get__(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_8Alphabet_12nonterminals___get__(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_2sym_tostring(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_sym); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_4sym_fromstring(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_string, int __pyx_v_terminal); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_6sym_isvar(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_sym); /* proto */ -static int __pyx_pf_8_cdec_sa_6Phrase___cinit__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_words); /* proto */ -static void __pyx_pf_8_cdec_sa_6Phrase_2__dealloc__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_4__str__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_6handle(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_8strhandle(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_10arity(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_12getvarpos(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_14getvar(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_16clen(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_k); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_18getchunk(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_ci); /* proto */ -#if PY_MAJOR_VERSION < 3 -static int __pyx_pf_8_cdec_sa_6Phrase_20__cmp__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_other); /* proto */ -#endif -static Py_hash_t __pyx_pf_8_cdec_sa_6Phrase_22__hash__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self); /* proto */ -static Py_ssize_t __pyx_pf_8_cdec_sa_6Phrase_24__len__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_26__getitem__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_28__iter__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_30subst(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_children); /* proto */ -static int __pyx_pf_8_cdec_sa_4Rule___cinit__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, int __pyx_v_lhs, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_f, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_e, PyObject *__pyx_v_scores, PyObject *__pyx_v_word_alignments); /* proto */ -static void __pyx_pf_8_cdec_sa_4Rule_2__dealloc__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ -static Py_hash_t __pyx_pf_8_cdec_sa_4Rule_4__hash__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ -#if PY_MAJOR_VERSION < 3 -static int __pyx_pf_8_cdec_sa_4Rule_6__cmp__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_other); /* proto */ -#endif -static PyObject *__pyx_pf_8_cdec_sa_4Rule_8__iadd__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_4Rule_10fmerge(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_f); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_4Rule_12arity(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_4Rule_14__str__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_4Rule_6scores___get__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_4Rule_6scores_2__set__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, PyObject *__pyx_v_s); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_4Rule_3lhs___get__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_4Rule_3lhs_2__set__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_4Rule_1f___get__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_4Rule_1e___get__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_4Rule_15word_alignments___get__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_4Rule_15word_alignments_2__set__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static int __pyx_pf_8_cdec_sa_4Rule_15word_alignments_4__del__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_7TrieMap___cinit__(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, int __pyx_v_alphabet_size); /* proto */ -static void __pyx_pf_8_cdec_sa_7TrieMap_2__dealloc__(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_7TrieMap_4insert(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, PyObject *__pyx_v_pattern); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_7TrieMap_6contains(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, PyObject *__pyx_v_pattern); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_7TrieMap_8toMap(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, PyObject *__pyx_v_flag); /* proto */ -static int __pyx_pf_8_cdec_sa_14Precomputation___cinit__(struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, PyObject *__pyx_v_fsarray, PyObject *__pyx_v_from_stats, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_precompute_rank, PyObject *__pyx_v_precompute_secondary_rank, PyObject *__pyx_v_max_length, PyObject *__pyx_v_max_nonterminals, PyObject *__pyx_v_train_max_initial_size, PyObject *__pyx_v_train_min_gap_size); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_14Precomputation_2read_binary(struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_14Precomputation_4write_binary(struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_14Precomputation_6precompute(struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, PyObject *__pyx_v_stats, struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_sarray); /* proto */ -static int __pyx_pf_8_cdec_sa_11SuffixArray___cinit__(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_2__getitem__(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_4getSentId(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_6getSent(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_8getSentPos(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_loc); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_10read_text(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_12q3sort(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, int __pyx_v_i, int __pyx_v_j, int __pyx_v_h, struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_isa, PyObject *__pyx_v_pad); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_14write_text(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_16read_binary(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_18write_binary(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_20write_enhanced(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_22lookup(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_word, int __pyx_v_offset, int __pyx_v_low, int __pyx_v_high); /* proto */ -static int __pyx_pf_8_cdec_sa_8TrieNode___cinit__(struct __pyx_obj_8_cdec_sa_TrieNode *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_8TrieNode_8children___get__(struct __pyx_obj_8_cdec_sa_TrieNode *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_8TrieNode_8children_2__set__(struct __pyx_obj_8_cdec_sa_TrieNode *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static int __pyx_pf_8_cdec_sa_8TrieNode_8children_4__del__(struct __pyx_obj_8_cdec_sa_TrieNode *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode___cinit__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_phrase, PyObject *__pyx_v_phrase_location, PyObject *__pyx_v_suffix_link); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_16ExtendedTrieNode_6phrase___get__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_6phrase_2__set__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_6phrase_4__del__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_16ExtendedTrieNode_15phrase_location___get__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_15phrase_location_2__set__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_15phrase_location_4__del__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_16ExtendedTrieNode_11suffix_link___get__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_11suffix_link_2__set__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_11suffix_link_4__del__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_9TrieTable___cinit__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_extended); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9TrieTable_8extended___get__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_9TrieTable_8extended_2__set__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9TrieTable_5count___get__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_9TrieTable_5count_2__set__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_9TrieTable_4root___get__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_9TrieTable_4root_2__set__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static int __pyx_pf_8_cdec_sa_9TrieTable_4root_4__del__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self); /* proto */ -static int __pyx_pf_8_cdec_sa_14PhraseLocation___cinit__(struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_self, int __pyx_v_sa_low, int __pyx_v_sa_high, int __pyx_v_arr_low, int __pyx_v_arr_high, PyObject *__pyx_v_arr, int __pyx_v_num_subpatterns); /* proto */ -static int __pyx_pf_8_cdec_sa_7Sampler___cinit__(struct __pyx_obj_8_cdec_sa_Sampler *__pyx_v_self, int __pyx_v_sample_size, struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_fsarray); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_7Sampler_2sample(struct __pyx_obj_8_cdec_sa_Sampler *__pyx_v_self, struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_phrase_location); /* proto */ -static int __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory___cinit__(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_alignment, float __pyx_v_by_slack_factor, char *__pyx_v_category, PyObject *__pyx_v_max_chunks, unsigned int __pyx_v_max_initial_size, unsigned int __pyx_v_max_length, unsigned int __pyx_v_max_nonterminals, PyObject *__pyx_v_max_target_chunks, PyObject *__pyx_v_max_target_length, unsigned int __pyx_v_min_gap_size, PyObject *__pyx_v_precompute_file, unsigned int __pyx_v_precompute_secondary_rank, unsigned int __pyx_v_precompute_rank, int __pyx_v_require_aligned_terminal, int __pyx_v_require_aligned_chunks, unsigned int __pyx_v_train_max_initial_size, unsigned int __pyx_v_train_min_gap_size, int __pyx_v_tight_phrases, int __pyx_v_use_baeza_yates, int __pyx_v_use_collocations, int __pyx_v_use_index); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_2configure(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_fsarray, struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_edarray, struct __pyx_obj_8_cdec_sa_Sampler *__pyx_v_sampler); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_4pattern2phrase(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_pattern); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_6pattern2phrase_plus(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_pattern); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_8precompute(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_10get_precomputed_collocation(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_phrase); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_12advance(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_frontier, PyObject *__pyx_v_res, PyObject *__pyx_v_fwords); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_14get_all_nodes_isteps_away(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_skip, PyObject *__pyx_v_i, PyObject *__pyx_v_spanlen, PyObject *__pyx_v_pathlen, PyObject *__pyx_v_fwords, PyObject *__pyx_v_next_states, PyObject *__pyx_v_reachable_buffer); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_16reachable(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_ifrom, PyObject *__pyx_v_dist); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_18shortest(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_ifrom, PyObject *__pyx_v_ito); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_20get_next_states(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v__columns, PyObject *__pyx_v_curr_idx, PyObject *__pyx_v_min_dist); /* proto */ -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_22input(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_models); /* proto */ -static char __pyx_k_1[] = ".gz"; -static char __pyx_k_2[] = "Requested index %d of %d-length FloatList"; -static char __pyx_k_3[] = "IntList["; -static char __pyx_k_4[] = ","; -static char __pyx_k_5[] = "]"; -static char __pyx_k_6[] = "len="; -static char __pyx_k_7[] = "Requested index %d of %d-length IntList"; -static char __pyx_k_8[] = "Requested index %d:%d of %d-length IntList"; -static char __pyx_k_9[] = "Illegal key type %s for IntList"; -static char __pyx_k_13[] = "%s "; -static char __pyx_k_14[] = "\n"; -static char __pyx_k_18[] = "%d "; -static char __pyx_k_22[] = "%s %d "; -static char __pyx_k_24[] = "write_enhanced_handle"; -static char __pyx_k_28[] = "-"; -static char __pyx_k_32[] = "%d-%d "; -static char __pyx_k_39[] = "%d-%d out of bounds (I=%d,J=%d) in line %d\n"; -static char __pyx_k_42[] = ""; -static char __pyx_k_43[] = "Sort error in CLex"; -static char __pyx_k_45[] = " "; -static char __pyx_k_47[] = "%d %f %f "; -static char __pyx_k_49[] = "%d %s "; -static char __pyx_k_53[] = "%s %s %.6f %.6f\n"; -static char __pyx_k_55[] = " ("; -static char __pyx_k_56[] = ")"; -static char __pyx_k_57[] = "Constructing LCP array"; -static char __pyx_k_59[] = "LCP array completed"; -static char __pyx_k_61[] = "[%s,%d]"; -static char __pyx_k_62[] = "[%s]"; -static char __pyx_k_63[] = "\\"; -static char __pyx_k_64[] = " "; -static char __pyx_k_65[] = "Invalid LHS symbol: %d"; -static char __pyx_k_66[] = "%d-%d"; -static char __pyx_k_67[] = " ||| "; -static char __pyx_k_68[] = "precompute_secondary_rank"; -static char __pyx_k_69[] = "train_max_initial_size"; -static char __pyx_k_70[] = "Precomputing frequent intersections"; -static char __pyx_k_72[] = " Computing inverted indexes..."; -static char __pyx_k_74[] = " Computing collocations..."; -static char __pyx_k_76[] = " %d sentences"; -static char __pyx_k_81[] = "X "; -static char __pyx_k_82[] = "ERROR: unexpected pattern %s in set of precomputed collocations"; -static char __pyx_k_83[] = "RANK %d\tCOUNT, COST: %d %d\tCUMUL: %d, %d"; -static char __pyx_k_84[] = "Precomputed collocations for %d patterns out of %d possible (upper bound %d)"; -static char __pyx_k_85[] = "Precomputed inverted index for %d patterns "; -static char __pyx_k_86[] = "Precomputation took %f seconds"; -static char __pyx_k_87[] = " Bucket sort took %f seconds"; -static char __pyx_k_88[] = " Refining, sort depth = %d"; -static char __pyx_k_89[] = " Refinement took %f seconds"; -static char __pyx_k_90[] = " Finalizing sort..."; -static char __pyx_k_92[] = "Suffix array construction took %f seconds"; -static char __pyx_k_93[] = "Unexpected condition found in q3sort: sort from %d to %d"; -static char __pyx_k_98[] = "Sampling strategy: uniform, max sample size = %d"; -static char __pyx_k_99[] = "Sampling strategy: no sampling"; -static char __pyx_k__0[] = "0"; -static char __pyx_k__1[] = "1"; -static char __pyx_k__e[] = "e"; -static char __pyx_k__f[] = "f"; -static char __pyx_k__h[] = "h"; -static char __pyx_k__i[] = "i"; -static char __pyx_k__j[] = "j"; -static char __pyx_k__r[] = "r"; -static char __pyx_k__w[] = "w"; -static char __pyx_k_101[] = "require_aligned_terminal"; -static char __pyx_k_102[] = "require_aligned_chunks"; -static char __pyx_k_103[] = "[X]"; -static char __pyx_k_104[] = "Must specify an alignment object"; -static char __pyx_k_106[] = "Reading precomputed data from file %s... "; -static char __pyx_k_107[] = "Precomputation done with max nonterminals %d, decoder uses %d"; -static char __pyx_k_108[] = "Precomputation done with max terminals %d, decoder uses %d"; -static char __pyx_k_109[] = "Precomputation done with max initial size %d, decoder uses %d"; -static char __pyx_k_110[] = "Precomputation done with min gap size %d, decoder uses %d"; -static char __pyx_k_111[] = "Converting %d hash keys on precomputed inverted index... "; -static char __pyx_k_112[] = "Converting %d hash keys on precomputed collocations... "; -static char __pyx_k_113[] = "Processing precomputations took %f seconds"; -static char __pyx_k_114[] = "{"; - static char __pyx_k_115[] = "("; -static char __pyx_k_116[] = "}"; -static char __pyx_k_117[] = "get_precomputed_collocation"; -static char __pyx_k_118[] = "double binary"; -static char __pyx_k_119[] = "Keyword trie error"; -static char __pyx_k_121[] = "get_all_nodes_isteps_away"; -static char __pyx_k_122[] = "Total time for rule lookup, extraction, and scoring = %f seconds"; -static char __pyx_k_123[] = " Extract time = %f seconds"; -static char __pyx_k_124[] = "No aligned terminals"; -static char __pyx_k_125[] = "Unaligned chunk"; -static char __pyx_k_126[] = "Gaps are not tight phrases"; -static char __pyx_k_127[] = "Inside edges of preceding subphrase are not tight"; -static char __pyx_k_128[] = "Inside edges of following subphrase are not tight"; -static char __pyx_k_129[] = "Subphrase [%d, %d] failed integrity check"; -static char __pyx_k_130[] = "Didn't extract anything from [%d, %d] -> [%d, %d]"; -static char __pyx_k_131[] = "Unable to extract basic phrase"; -static char __pyx_k_134[] = "/Users/vchahun/Sandbox/cdec/python/src/sa/_cdec_sa.pyx"; -static char __pyx_k_135[] = "cdec.sa"; -static char __pyx_k_139[] = "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi"; -static char __pyx_k_144[] = "*EPS*"; -static char __pyx_k__gc[] = "gc"; -static char __pyx_k__sa[] = "sa"; -static char __pyx_k__arr[] = "arr"; -static char __pyx_k__cmp[] = "cmp"; -static char __pyx_k__col[] = "col"; -static char __pyx_k__end[] = "end"; -static char __pyx_k__isa[] = "isa"; -static char __pyx_k__ito[] = "ito"; -static char __pyx_k__lhs[] = "lhs"; -static char __pyx_k__low[] = "low"; -static char __pyx_k__map[] = "map"; -static char __pyx_k__pad[] = "pad"; -static char __pyx_k__res[] = "res"; -static char __pyx_k__sym[] = "sym"; -static char __pyx_k__zip[] = "zip"; -static char __pyx_k__NULL[] = "NULL"; -static char __pyx_k__dist[] = "dist"; -static char __pyx_k__gzip[] = "gzip"; -static char __pyx_k__high[] = "high"; -static char __pyx_k__info[] = "info"; -static char __pyx_k__join[] = "join"; -static char __pyx_k__open[] = "open"; -static char __pyx_k__seek[] = "seek"; -static char __pyx_k__size[] = "size"; -static char __pyx_k__skip[] = "skip"; -static char __pyx_k__stop[] = "stop"; -static char __pyx_k__warn[] = "warn"; -static char __pyx_k__word[] = "word"; -static char __pyx_k___SEP_[] = "_SEP_"; -static char __pyx_k__arity[] = "arity"; -static char __pyx_k__debug[] = "debug"; -static char __pyx_k__eword[] = "eword"; -static char __pyx_k__fword[] = "fword"; -static char __pyx_k__ifrom[] = "ifrom"; -static char __pyx_k__index[] = "index"; -static char __pyx_k__merge[] = "merge"; -static char __pyx_k__range[] = "range"; -static char __pyx_k__reset[] = "reset"; -static char __pyx_k__split[] = "split"; -static char __pyx_k__start[] = "start"; -static char __pyx_k__stats[] = "stats"; -static char __pyx_k__toMap[] = "toMap"; -static char __pyx_k__words[] = "words"; -static char __pyx_k__write[] = "write"; -static char __pyx_k__earray[] = "earray"; -static char __pyx_k__extend[] = "extend"; -static char __pyx_k__fwords[] = "fwords"; -static char __pyx_k__get_id[] = "get_id"; -static char __pyx_k__insert[] = "insert"; -static char __pyx_k__logger[] = "logger"; -static char __pyx_k__lookup[] = "lookup"; -static char __pyx_k__models[] = "models"; -static char __pyx_k__offset[] = "offset"; -static char __pyx_k__phrase[] = "phrase"; -static char __pyx_k__q3sort[] = "q3sort"; -static char __pyx_k__sa_low[] = "sa_low"; -static char __pyx_k__sample[] = "sample"; -static char __pyx_k__sarray[] = "sarray"; -static char __pyx_k__scores[] = "scores"; -static char __pyx_k__sorted[] = "sorted"; -static char __pyx_k__string[] = "string"; -static char __pyx_k__unlink[] = "unlink"; -static char __pyx_k__advance[] = "advance"; -static char __pyx_k__arr_low[] = "arr_low"; -static char __pyx_k__collect[] = "collect"; -static char __pyx_k__edarray[] = "edarray"; -static char __pyx_k__fsarray[] = "fsarray"; -static char __pyx_k__getSent[] = "getSent"; -static char __pyx_k__logging[] = "logging"; -static char __pyx_k__pathlen[] = "pathlen"; -static char __pyx_k__sa_high[] = "sa_high"; -static char __pyx_k__sampler[] = "sampler"; -static char __pyx_k__spanlen[] = "spanlen"; -static char __pyx_k__GzipFile[] = "GzipFile"; -static char __pyx_k____exit__[] = "__exit__"; -static char __pyx_k____main__[] = "__main__"; -static char __pyx_k____test__[] = "__test__"; -static char __pyx_k___cdec_sa[] = "_cdec_sa"; -static char __pyx_k___columns[] = "_columns"; -static char __pyx_k__arr_high[] = "arr_high"; -static char __pyx_k__category[] = "category"; -static char __pyx_k__children[] = "children"; -static char __pyx_k__curr_idx[] = "curr_idx"; -static char __pyx_k__extended[] = "extended"; -static char __pyx_k__filename[] = "filename"; -static char __pyx_k__frontier[] = "frontier"; -static char __pyx_k__get_e_id[] = "get_e_id"; -static char __pyx_k__get_f_id[] = "get_f_id"; -static char __pyx_k__get_word[] = "get_word"; -static char __pyx_k__getchunk[] = "getchunk"; -static char __pyx_k__min_dist[] = "min_dist"; -static char __pyx_k__resource[] = "resource"; -static char __pyx_k__ru_stime[] = "ru_stime"; -static char __pyx_k__ru_utime[] = "ru_utime"; -static char __pyx_k__shortest[] = "shortest"; -static char __pyx_k__terminal[] = "terminal"; -static char __pyx_k__Exception[] = "Exception"; -static char __pyx_k__TypeError[] = "TypeError"; -static char __pyx_k____enter__[] = "__enter__"; -static char __pyx_k__alignment[] = "alignment"; -static char __pyx_k__enumerate[] = "enumerate"; -static char __pyx_k__from_data[] = "from_data"; -static char __pyx_k__from_text[] = "from_text"; -static char __pyx_k__getLogger[] = "getLogger"; -static char __pyx_k__getSentId[] = "getSentId"; -static char __pyx_k__getrusage[] = "getrusage"; -static char __pyx_k__increment[] = "increment"; -static char __pyx_k__iteritems[] = "iteritems"; -static char __pyx_k__partition[] = "partition"; -static char __pyx_k__reachable[] = "reachable"; -static char __pyx_k__read_text[] = "read_text"; -static char __pyx_k__sym_isvar[] = "sym_isvar"; -static char __pyx_k__use_index[] = "use_index"; -static char __pyx_k__IndexError[] = "IndexError"; -static char __pyx_k__ValueError[] = "ValueError"; -static char __pyx_k__from_stats[] = "from_stats"; -static char __pyx_k__getSentPos[] = "getSentPos"; -static char __pyx_k__max_chunks[] = "max_chunks"; -static char __pyx_k__max_length[] = "max_length"; -static char __pyx_k__precompute[] = "precompute"; -static char __pyx_k__setdefault[] = "setdefault"; -static char __pyx_k__write_text[] = "write_text"; -static char __pyx_k__END_OF_FILE[] = "END_OF_FILE"; -static char __pyx_k__END_OF_LINE[] = "END_OF_LINE"; -static char __pyx_k__RUSAGE_SELF[] = "RUSAGE_SELF"; -static char __pyx_k__from_binary[] = "from_binary"; -static char __pyx_k__initial_len[] = "initial_len"; -static char __pyx_k__next_states[] = "next_states"; -static char __pyx_k__precomputed[] = "precomputed"; -static char __pyx_k__read_binary[] = "read_binary"; -static char __pyx_k__sample_size[] = "sample_size"; -static char __pyx_k__suffix_link[] = "suffix_link"; -static char __pyx_k__use_sent_id[] = "use_sent_id"; -static char __pyx_k___doquicksort[] = "_doquicksort"; -static char __pyx_k__gzip_or_text[] = "gzip_or_text"; -static char __pyx_k__min_gap_size[] = "min_gap_size"; -static char __pyx_k__sym_tostring[] = "sym_tostring"; -static char __pyx_k__StopIteration[] = "StopIteration"; -static char __pyx_k__alphabet_size[] = "alphabet_size"; -static char __pyx_k__tight_phrases[] = "tight_phrases"; -static char __pyx_k__pattern2phrase[] = "pattern2phrase"; -static char __pyx_k__sym_fromstring[] = "sym_fromstring"; -static char __pyx_k__by_slack_factor[] = "by_slack_factor"; -static char __pyx_k__get_next_states[] = "get_next_states"; -static char __pyx_k__num_subpatterns[] = "num_subpatterns"; -static char __pyx_k__phrase_location[] = "phrase_location"; -static char __pyx_k__precompute_file[] = "precompute_file"; -static char __pyx_k__precompute_rank[] = "precompute_rank"; -static char __pyx_k__use_baeza_yates[] = "use_baeza_yates"; -static char __pyx_k__word_alignments[] = "word_alignments"; -static char __pyx_k__max_initial_size[] = "max_initial_size"; -static char __pyx_k__max_nonterminals[] = "max_nonterminals"; -static char __pyx_k__reachable_buffer[] = "reachable_buffer"; -static char __pyx_k__use_collocations[] = "use_collocations"; -static char __pyx_k__max_target_chunks[] = "max_target_chunks"; -static char __pyx_k__max_target_length[] = "max_target_length"; -static char __pyx_k__train_min_gap_size[] = "train_min_gap_size"; -static char __pyx_k__pattern2phrase_plus[] = "pattern2phrase_plus"; -static PyObject *__pyx_kp_s_1; -static PyObject *__pyx_n_s_101; -static PyObject *__pyx_n_s_102; -static PyObject *__pyx_kp_s_104; -static PyObject *__pyx_kp_s_106; -static PyObject *__pyx_kp_s_107; -static PyObject *__pyx_kp_s_108; -static PyObject *__pyx_kp_s_109; -static PyObject *__pyx_kp_s_110; -static PyObject *__pyx_kp_s_111; -static PyObject *__pyx_kp_s_112; -static PyObject *__pyx_kp_s_113; -static PyObject *__pyx_kp_s_114; -static PyObject *__pyx_kp_s_115; -static PyObject *__pyx_kp_s_116; -static PyObject *__pyx_n_s_117; -static PyObject *__pyx_kp_s_118; -static PyObject *__pyx_kp_s_119; -static PyObject *__pyx_n_s_121; -static PyObject *__pyx_kp_s_122; -static PyObject *__pyx_kp_s_123; -static PyObject *__pyx_kp_s_124; -static PyObject *__pyx_kp_s_125; -static PyObject *__pyx_kp_s_126; -static PyObject *__pyx_kp_s_127; -static PyObject *__pyx_kp_s_128; -static PyObject *__pyx_kp_s_129; -static PyObject *__pyx_kp_s_13; -static PyObject *__pyx_kp_s_130; -static PyObject *__pyx_kp_s_131; -static PyObject *__pyx_kp_s_134; -static PyObject *__pyx_kp_s_135; -static PyObject *__pyx_kp_s_139; -static PyObject *__pyx_kp_s_14; -static PyObject *__pyx_kp_s_144; -static PyObject *__pyx_kp_s_18; -static PyObject *__pyx_kp_s_2; -static PyObject *__pyx_kp_s_22; -static PyObject *__pyx_n_s_24; -static PyObject *__pyx_kp_s_28; -static PyObject *__pyx_kp_s_3; -static PyObject *__pyx_kp_s_32; -static PyObject *__pyx_kp_s_39; -static PyObject *__pyx_kp_s_4; -static PyObject *__pyx_kp_s_42; -static PyObject *__pyx_kp_s_43; -static PyObject *__pyx_kp_s_45; -static PyObject *__pyx_kp_s_47; -static PyObject *__pyx_kp_s_49; -static PyObject *__pyx_kp_s_5; -static PyObject *__pyx_kp_s_53; -static PyObject *__pyx_kp_s_55; -static PyObject *__pyx_kp_s_56; -static PyObject *__pyx_kp_s_57; -static PyObject *__pyx_kp_s_59; -static PyObject *__pyx_kp_s_6; -static PyObject *__pyx_kp_s_61; -static PyObject *__pyx_kp_s_62; -static PyObject *__pyx_kp_s_63; -static PyObject *__pyx_kp_s_64; -static PyObject *__pyx_kp_s_65; -static PyObject *__pyx_kp_s_66; -static PyObject *__pyx_kp_s_67; -static PyObject *__pyx_n_s_68; -static PyObject *__pyx_n_s_69; -static PyObject *__pyx_kp_s_7; -static PyObject *__pyx_kp_s_70; -static PyObject *__pyx_kp_s_72; -static PyObject *__pyx_kp_s_74; -static PyObject *__pyx_kp_s_76; -static PyObject *__pyx_kp_s_8; -static PyObject *__pyx_kp_s_81; -static PyObject *__pyx_kp_s_82; -static PyObject *__pyx_kp_s_83; -static PyObject *__pyx_kp_s_84; -static PyObject *__pyx_kp_s_85; -static PyObject *__pyx_kp_s_86; -static PyObject *__pyx_kp_s_87; -static PyObject *__pyx_kp_s_88; -static PyObject *__pyx_kp_s_89; -static PyObject *__pyx_kp_s_9; -static PyObject *__pyx_kp_s_90; -static PyObject *__pyx_kp_s_92; -static PyObject *__pyx_kp_s_93; -static PyObject *__pyx_kp_s_98; -static PyObject *__pyx_kp_s_99; -static PyObject *__pyx_kp_s__0; -static PyObject *__pyx_kp_s__1; -static PyObject *__pyx_n_s__END_OF_FILE; -static PyObject *__pyx_n_s__END_OF_LINE; -static PyObject *__pyx_n_s__Exception; -static PyObject *__pyx_n_s__GzipFile; -static PyObject *__pyx_n_s__IndexError; -static PyObject *__pyx_n_s__NULL; -static PyObject *__pyx_n_s__RUSAGE_SELF; -static PyObject *__pyx_n_s__StopIteration; -static PyObject *__pyx_n_s__TypeError; -static PyObject *__pyx_n_s__ValueError; -static PyObject *__pyx_n_s____enter__; -static PyObject *__pyx_n_s____exit__; -static PyObject *__pyx_n_s____main__; -static PyObject *__pyx_n_s____test__; -static PyObject *__pyx_n_s___cdec_sa; -static PyObject *__pyx_n_s___columns; -static PyObject *__pyx_n_s___doquicksort; -static PyObject *__pyx_n_s__advance; -static PyObject *__pyx_n_s__alignment; -static PyObject *__pyx_n_s__alphabet_size; -static PyObject *__pyx_n_s__arity; -static PyObject *__pyx_n_s__arr; -static PyObject *__pyx_n_s__arr_high; -static PyObject *__pyx_n_s__arr_low; -static PyObject *__pyx_n_s__by_slack_factor; -static PyObject *__pyx_n_s__category; -static PyObject *__pyx_n_s__children; -static PyObject *__pyx_n_s__cmp; -static PyObject *__pyx_n_s__col; -static PyObject *__pyx_n_s__collect; -static PyObject *__pyx_n_s__curr_idx; -static PyObject *__pyx_n_s__debug; -static PyObject *__pyx_n_s__dist; -static PyObject *__pyx_n_s__e; -static PyObject *__pyx_n_s__earray; -static PyObject *__pyx_n_s__edarray; -static PyObject *__pyx_n_s__end; -static PyObject *__pyx_n_s__enumerate; -static PyObject *__pyx_n_s__eword; -static PyObject *__pyx_n_s__extend; -static PyObject *__pyx_n_s__extended; -static PyObject *__pyx_n_s__f; -static PyObject *__pyx_n_s__filename; -static PyObject *__pyx_n_s__from_binary; -static PyObject *__pyx_n_s__from_data; -static PyObject *__pyx_n_s__from_stats; -static PyObject *__pyx_n_s__from_text; -static PyObject *__pyx_n_s__frontier; -static PyObject *__pyx_n_s__fsarray; -static PyObject *__pyx_n_s__fword; -static PyObject *__pyx_n_s__fwords; -static PyObject *__pyx_n_s__gc; -static PyObject *__pyx_n_s__getLogger; -static PyObject *__pyx_n_s__getSent; -static PyObject *__pyx_n_s__getSentId; -static PyObject *__pyx_n_s__getSentPos; -static PyObject *__pyx_n_s__get_e_id; -static PyObject *__pyx_n_s__get_f_id; -static PyObject *__pyx_n_s__get_id; -static PyObject *__pyx_n_s__get_next_states; -static PyObject *__pyx_n_s__get_word; -static PyObject *__pyx_n_s__getchunk; -static PyObject *__pyx_n_s__getrusage; -static PyObject *__pyx_n_s__gzip; -static PyObject *__pyx_n_s__gzip_or_text; -static PyObject *__pyx_n_s__h; -static PyObject *__pyx_n_s__high; -static PyObject *__pyx_n_s__i; -static PyObject *__pyx_n_s__ifrom; -static PyObject *__pyx_n_s__increment; -static PyObject *__pyx_n_s__index; -static PyObject *__pyx_n_s__info; -static PyObject *__pyx_n_s__initial_len; -static PyObject *__pyx_n_s__insert; -static PyObject *__pyx_n_s__isa; -static PyObject *__pyx_n_s__iteritems; -static PyObject *__pyx_n_s__ito; -static PyObject *__pyx_n_s__j; -static PyObject *__pyx_n_s__join; -static PyObject *__pyx_n_s__lhs; -static PyObject *__pyx_n_s__logger; -static PyObject *__pyx_n_s__logging; -static PyObject *__pyx_n_s__lookup; -static PyObject *__pyx_n_s__low; -static PyObject *__pyx_n_s__map; -static PyObject *__pyx_n_s__max_chunks; -static PyObject *__pyx_n_s__max_initial_size; -static PyObject *__pyx_n_s__max_length; -static PyObject *__pyx_n_s__max_nonterminals; -static PyObject *__pyx_n_s__max_target_chunks; -static PyObject *__pyx_n_s__max_target_length; -static PyObject *__pyx_n_s__merge; -static PyObject *__pyx_n_s__min_dist; -static PyObject *__pyx_n_s__min_gap_size; -static PyObject *__pyx_n_s__models; -static PyObject *__pyx_n_s__next_states; -static PyObject *__pyx_n_s__num_subpatterns; -static PyObject *__pyx_n_s__offset; -static PyObject *__pyx_n_s__open; -static PyObject *__pyx_n_s__pad; -static PyObject *__pyx_n_s__partition; -static PyObject *__pyx_n_s__pathlen; -static PyObject *__pyx_n_s__pattern2phrase; -static PyObject *__pyx_n_s__pattern2phrase_plus; -static PyObject *__pyx_n_s__phrase; -static PyObject *__pyx_n_s__phrase_location; -static PyObject *__pyx_n_s__precompute; -static PyObject *__pyx_n_s__precompute_file; -static PyObject *__pyx_n_s__precompute_rank; -static PyObject *__pyx_n_s__precomputed; -static PyObject *__pyx_n_s__q3sort; -static PyObject *__pyx_n_s__range; -static PyObject *__pyx_n_s__reachable; -static PyObject *__pyx_n_s__reachable_buffer; -static PyObject *__pyx_n_s__read_binary; -static PyObject *__pyx_n_s__read_text; -static PyObject *__pyx_n_s__res; -static PyObject *__pyx_n_s__reset; -static PyObject *__pyx_n_s__resource; -static PyObject *__pyx_n_s__ru_stime; -static PyObject *__pyx_n_s__ru_utime; -static PyObject *__pyx_n_s__sa; -static PyObject *__pyx_n_s__sa_high; -static PyObject *__pyx_n_s__sa_low; -static PyObject *__pyx_n_s__sample; -static PyObject *__pyx_n_s__sample_size; -static PyObject *__pyx_n_s__sampler; -static PyObject *__pyx_n_s__sarray; -static PyObject *__pyx_n_s__scores; -static PyObject *__pyx_n_s__seek; -static PyObject *__pyx_n_s__setdefault; -static PyObject *__pyx_n_s__shortest; -static PyObject *__pyx_n_s__size; -static PyObject *__pyx_n_s__skip; -static PyObject *__pyx_n_s__sorted; -static PyObject *__pyx_n_s__spanlen; -static PyObject *__pyx_n_s__split; -static PyObject *__pyx_n_s__start; -static PyObject *__pyx_n_s__stats; -static PyObject *__pyx_n_s__stop; -static PyObject *__pyx_n_s__string; -static PyObject *__pyx_n_s__suffix_link; -static PyObject *__pyx_n_s__sym; -static PyObject *__pyx_n_s__sym_fromstring; -static PyObject *__pyx_n_s__sym_isvar; -static PyObject *__pyx_n_s__sym_tostring; -static PyObject *__pyx_n_s__terminal; -static PyObject *__pyx_n_s__tight_phrases; -static PyObject *__pyx_n_s__toMap; -static PyObject *__pyx_n_s__train_min_gap_size; -static PyObject *__pyx_n_s__unlink; -static PyObject *__pyx_n_s__use_baeza_yates; -static PyObject *__pyx_n_s__use_collocations; -static PyObject *__pyx_n_s__use_index; -static PyObject *__pyx_n_s__use_sent_id; -static PyObject *__pyx_n_s__w; -static PyObject *__pyx_n_s__warn; -static PyObject *__pyx_n_s__word; -static PyObject *__pyx_n_s__word_alignments; -static PyObject *__pyx_n_s__words; -static PyObject *__pyx_n_s__write; -static PyObject *__pyx_n_s__write_text; -static PyObject *__pyx_n_s__zip; -static PyObject *__pyx_int_0; -static PyObject *__pyx_int_1; -static PyObject *__pyx_int_2; -static PyObject *__pyx_int_5; -static PyObject *__pyx_int_neg_1; -static PyObject *__pyx_int_10; -static PyObject *__pyx_int_20; -static PyObject *__pyx_int_1000; -static PyObject *__pyx_int_65536; -static PyObject *__pyx_k_38; -static PyObject *__pyx_k_97; -static PyObject *__pyx_k_tuple_10; -static PyObject *__pyx_k_tuple_11; -static PyObject *__pyx_k_tuple_12; -static PyObject *__pyx_k_tuple_15; -static PyObject *__pyx_k_tuple_16; -static PyObject *__pyx_k_tuple_17; -static PyObject *__pyx_k_tuple_19; -static PyObject *__pyx_k_tuple_20; -static PyObject *__pyx_k_tuple_21; -static PyObject *__pyx_k_tuple_23; -static PyObject *__pyx_k_tuple_25; -static PyObject *__pyx_k_tuple_26; -static PyObject *__pyx_k_tuple_27; -static PyObject *__pyx_k_tuple_29; -static PyObject *__pyx_k_tuple_30; -static PyObject *__pyx_k_tuple_31; -static PyObject *__pyx_k_tuple_33; -static PyObject *__pyx_k_tuple_34; -static PyObject *__pyx_k_tuple_35; -static PyObject *__pyx_k_tuple_36; -static PyObject *__pyx_k_tuple_37; -static PyObject *__pyx_k_tuple_40; -static PyObject *__pyx_k_tuple_41; -static PyObject *__pyx_k_tuple_44; -static PyObject *__pyx_k_tuple_46; -static PyObject *__pyx_k_tuple_48; -static PyObject *__pyx_k_tuple_50; -static PyObject *__pyx_k_tuple_51; -static PyObject *__pyx_k_tuple_52; -static PyObject *__pyx_k_tuple_54; -static PyObject *__pyx_k_tuple_58; -static PyObject *__pyx_k_tuple_60; -static PyObject *__pyx_k_tuple_71; -static PyObject *__pyx_k_tuple_73; -static PyObject *__pyx_k_tuple_75; -static PyObject *__pyx_k_tuple_77; -static PyObject *__pyx_k_tuple_78; -static PyObject *__pyx_k_tuple_79; -static PyObject *__pyx_k_tuple_80; -static PyObject *__pyx_k_tuple_91; -static PyObject *__pyx_k_tuple_94; -static PyObject *__pyx_k_tuple_95; -static PyObject *__pyx_k_tuple_96; -static PyObject *__pyx_k_tuple_100; -static PyObject *__pyx_k_tuple_105; -static PyObject *__pyx_k_tuple_120; -static PyObject *__pyx_k_tuple_132; -static PyObject *__pyx_k_tuple_136; -static PyObject *__pyx_k_tuple_137; -static PyObject *__pyx_k_tuple_140; -static PyObject *__pyx_k_tuple_142; -static PyObject *__pyx_k_codeobj_133; -static PyObject *__pyx_k_codeobj_138; -static PyObject *__pyx_k_codeobj_141; -static PyObject *__pyx_k_codeobj_143; - -/* "_cdec_sa.pyx":5 - * import gzip - * - * cdef float monitor_cpu(): # <<<<<<<<<<<<<< - * return (resource.getrusage(resource.RUSAGE_SELF).ru_utime+ - * resource.getrusage(resource.RUSAGE_SELF).ru_stime) - */ - -static float __pyx_f_8_cdec_sa_monitor_cpu(void) { - float __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - float __pyx_t_5; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("monitor_cpu", 0); - - /* "_cdec_sa.pyx":6 - * - * cdef float monitor_cpu(): - * return (resource.getrusage(resource.RUSAGE_SELF).ru_utime+ # <<<<<<<<<<<<<< - * resource.getrusage(resource.RUSAGE_SELF).ru_stime) - * - */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__resource); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__getrusage); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__resource); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__RUSAGE_SELF); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__ru_utime); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "_cdec_sa.pyx":7 - * cdef float monitor_cpu(): - * return (resource.getrusage(resource.RUSAGE_SELF).ru_utime+ - * resource.getrusage(resource.RUSAGE_SELF).ru_stime) # <<<<<<<<<<<<<< - * - * def gzip_or_text(char* filename): - */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__resource); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__getrusage); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__resource); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__RUSAGE_SELF); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__ru_stime); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_Add(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = __pyx_PyFloat_AsFloat(__pyx_t_4); if (unlikely((__pyx_t_5 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_r = __pyx_t_5; - goto __pyx_L0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_WriteUnraisable("_cdec_sa.monitor_cpu", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_1gzip_or_text(PyObject *__pyx_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyMethodDef __pyx_mdef_8_cdec_sa_1gzip_or_text = {__Pyx_NAMESTR("gzip_or_text"), (PyCFunction)__pyx_pw_8_cdec_sa_1gzip_or_text, METH_O, __Pyx_DOCSTR(0)}; -static PyObject *__pyx_pw_8_cdec_sa_1gzip_or_text(PyObject *__pyx_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("gzip_or_text (wrapper)", 0); - __pyx_self = __pyx_self; - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.gzip_or_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_gzip_or_text(__pyx_self, ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "_cdec_sa.pyx":9 - * resource.getrusage(resource.RUSAGE_SELF).ru_stime) - * - * def gzip_or_text(char* filename): # <<<<<<<<<<<<<< - * if filename.endswith('.gz'): - * return gzip.GzipFile(filename) - */ - -static PyObject *__pyx_pf_8_cdec_sa_gzip_or_text(CYTHON_UNUSED PyObject *__pyx_self, char *__pyx_v_filename) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("gzip_or_text", 0); - - /* "_cdec_sa.pyx":10 - * - * def gzip_or_text(char* filename): - * if filename.endswith('.gz'): # <<<<<<<<<<<<<< - * return gzip.GzipFile(filename) - * else: - */ - __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = __Pyx_PyBytes_Tailmatch(((PyObject *)__pyx_t_1), ((PyObject *)__pyx_kp_s_1), 0, PY_SSIZE_T_MAX, 1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "_cdec_sa.pyx":11 - * def gzip_or_text(char* filename): - * if filename.endswith('.gz'): - * return gzip.GzipFile(filename) # <<<<<<<<<<<<<< - * else: - * return open(filename) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__gzip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__GzipFile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - goto __pyx_L3; - } - /*else*/ { - - /* "_cdec_sa.pyx":13 - * return gzip.GzipFile(filename) - * else: - * return open(filename) # <<<<<<<<<<<<<< - * - * logger = logging.getLogger('cdec.sa') - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec_sa.gzip_or_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_9FloatList_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_9FloatList_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_v_size; - int __pyx_v_increment; - int __pyx_v_initial_len; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__size,&__pyx_n_s__increment,&__pyx_n_s__initial_len,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[3] = {0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size); - if (value) { values[0] = value; kw_args--; } - } - case 1: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__increment); - if (value) { values[1] = value; kw_args--; } - } - case 2: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__initial_len); - if (value) { values[2] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - if (values[0]) { - } else { - __pyx_v_size = ((int)0); - } - if (values[1]) { - } else { - __pyx_v_increment = ((int)1); - } - if (values[2]) { - } else { - __pyx_v_initial_len = ((int)0); - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - } - if (values[0]) { - __pyx_v_size = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_size = ((int)0); - } - if (values[1]) { - __pyx_v_increment = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_increment == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_increment = ((int)1); - } - if (values[2]) { - __pyx_v_initial_len = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_initial_len == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_initial_len = ((int)0); - } - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.FloatList.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_9FloatList___cinit__(((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_v_self), __pyx_v_size, __pyx_v_increment, __pyx_v_initial_len); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":15 - * cdef float* arr - * - * def __cinit__(self, int size=0, int increment=1, int initial_len=0): # <<<<<<<<<<<<<< - * if initial_len > size: - * size = initial_len - */ - -static int __pyx_pf_8_cdec_sa_9FloatList___cinit__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, int __pyx_v_size, int __pyx_v_increment, int __pyx_v_initial_len) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":16 - * - * def __cinit__(self, int size=0, int increment=1, int initial_len=0): - * if initial_len > size: # <<<<<<<<<<<<<< - * size = initial_len - * self.size = size - */ - __pyx_t_1 = (__pyx_v_initial_len > __pyx_v_size); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":17 - * def __cinit__(self, int size=0, int increment=1, int initial_len=0): - * if initial_len > size: - * size = initial_len # <<<<<<<<<<<<<< - * self.size = size - * self.increment = increment - */ - __pyx_v_size = __pyx_v_initial_len; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":18 - * if initial_len > size: - * size = initial_len - * self.size = size # <<<<<<<<<<<<<< - * self.increment = increment - * self.len = initial_len - */ - __pyx_v_self->size = __pyx_v_size; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":19 - * size = initial_len - * self.size = size - * self.increment = increment # <<<<<<<<<<<<<< - * self.len = initial_len - * self.arr = malloc(size*sizeof(float)) - */ - __pyx_v_self->increment = __pyx_v_increment; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":20 - * self.size = size - * self.increment = increment - * self.len = initial_len # <<<<<<<<<<<<<< - * self.arr = malloc(size*sizeof(float)) - * memset(self.arr, 0, initial_len*sizeof(float)) - */ - __pyx_v_self->len = __pyx_v_initial_len; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":21 - * self.increment = increment - * self.len = initial_len - * self.arr = malloc(size*sizeof(float)) # <<<<<<<<<<<<<< - * memset(self.arr, 0, initial_len*sizeof(float)) - * - */ - __pyx_v_self->arr = ((float *)malloc((__pyx_v_size * (sizeof(float))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":22 - * self.len = initial_len - * self.arr = malloc(size*sizeof(float)) - * memset(self.arr, 0, initial_len*sizeof(float)) # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - memset(__pyx_v_self->arr, 0, (__pyx_v_initial_len * (sizeof(float)))); - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static void __pyx_pw_8_cdec_sa_9FloatList_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_8_cdec_sa_9FloatList_3__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_8_cdec_sa_9FloatList_2__dealloc__(((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":24 - * memset(self.arr, 0, initial_len*sizeof(float)) - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * free(self.arr) - * - */ - -static void __pyx_pf_8_cdec_sa_9FloatList_2__dealloc__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":25 - * - * def __dealloc__(self): - * free(self.arr) # <<<<<<<<<<<<<< - * - * def __getitem__(self, i): - */ - free(__pyx_v_self->arr); - - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9FloatList_5__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9FloatList_5__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9FloatList_4__getitem__(((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_v_self), ((PyObject *)__pyx_v_i)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":27 - * free(self.arr) - * - * def __getitem__(self, i): # <<<<<<<<<<<<<< - * j = i - * if i<0: - */ - -static PyObject *__pyx_pf_8_cdec_sa_9FloatList_4__getitem__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_v_j = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - int __pyx_t_5; - Py_ssize_t __pyx_t_6; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__getitem__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":28 - * - * def __getitem__(self, i): - * j = i # <<<<<<<<<<<<<< - * if i<0: - * j = self.len + i - */ - __Pyx_INCREF(__pyx_v_i); - __pyx_v_j = __pyx_v_i; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":29 - * def __getitem__(self, i): - * j = i - * if i<0: # <<<<<<<<<<<<<< - * j = self.len + i - * if j<0 or j>=self.len: - */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_i, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":30 - * j = i - * if i<0: - * j = self.len + i # <<<<<<<<<<<<<< - * if j<0 or j>=self.len: - * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) - */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_v_i); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_v_j); - __pyx_v_j = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":31 - * if i<0: - * j = self.len + i - * if j<0 or j>=self.len: # <<<<<<<<<<<<<< - * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) - * return self.arr[j] - */ - __pyx_t_3 = PyObject_RichCompare(__pyx_v_j, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (!__pyx_t_2) { - __pyx_t_3 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_RichCompare(__pyx_v_j, __pyx_t_3, Py_GE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = __pyx_t_4; - } else { - __pyx_t_5 = __pyx_t_2; - } - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":32 - * j = self.len + i - * if j<0 or j>=self.len: - * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) # <<<<<<<<<<<<<< - * return self.arr[j] - * - */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_i); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_i); - __Pyx_GIVEREF(__pyx_v_i); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":33 - * if j<0 or j>=self.len: - * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) - * return self.arr[j] # <<<<<<<<<<<<<< - * - * cdef void set(self, int i, float v): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_j); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = PyFloat_FromDouble((__pyx_v_self->arr[__pyx_t_6])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __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_3); - __Pyx_AddTraceback("_cdec_sa.FloatList.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_j); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":35 - * return self.arr[j] - * - * cdef void set(self, int i, float v): # <<<<<<<<<<<<<< - * j = i - * if i<0: - */ - -static void __pyx_f_8_cdec_sa_9FloatList_set(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, int __pyx_v_i, float __pyx_v_v) { - int __pyx_v_j; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("set", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":36 - * - * cdef void set(self, int i, float v): - * j = i # <<<<<<<<<<<<<< - * if i<0: - * j = self.len + i - */ - __pyx_v_j = __pyx_v_i; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":37 - * cdef void set(self, int i, float v): - * j = i - * if i<0: # <<<<<<<<<<<<<< - * j = self.len + i - * if j<0 or j>=self.len: - */ - __pyx_t_1 = (__pyx_v_i < 0); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":38 - * j = i - * if i<0: - * j = self.len + i # <<<<<<<<<<<<<< - * if j<0 or j>=self.len: - * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) - */ - __pyx_v_j = (__pyx_v_self->len + __pyx_v_i); - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":39 - * if i<0: - * j = self.len + i - * if j<0 or j>=self.len: # <<<<<<<<<<<<<< - * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) - * self.arr[j] = v - */ - __pyx_t_1 = (__pyx_v_j < 0); - if (!__pyx_t_1) { - __pyx_t_2 = (__pyx_v_j >= __pyx_v_self->len); - __pyx_t_3 = __pyx_t_2; - } else { - __pyx_t_3 = __pyx_t_1; - } - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":40 - * j = self.len + i - * if j<0 or j>=self.len: - * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) # <<<<<<<<<<<<<< - * self.arr[j] = v - * - */ - __pyx_t_4 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_4 = 0; - __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_2), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); - __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":41 - * if j<0 or j>=self.len: - * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) - * self.arr[j] = v # <<<<<<<<<<<<<< - * - * def __setitem__(self, i, val): - */ - (__pyx_v_self->arr[__pyx_v_j]) = __pyx_v_v; - - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_WriteUnraisable("_cdec_sa.FloatList.set", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_9FloatList_7__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val); /*proto*/ -static int __pyx_pw_8_cdec_sa_9FloatList_7__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9FloatList_6__setitem__(((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_v_self), ((PyObject *)__pyx_v_i), ((PyObject *)__pyx_v_val)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":43 - * self.arr[j] = v - * - * def __setitem__(self, i, val): # <<<<<<<<<<<<<< - * self.set(i, val) - * - */ - -static int __pyx_pf_8_cdec_sa_9FloatList_6__setitem__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - float __pyx_t_2; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__setitem__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":44 - * - * def __setitem__(self, i, val): - * self.set(i, val) # <<<<<<<<<<<<<< - * - * def __len__(self): - */ - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = __pyx_PyFloat_AsFloat(__pyx_v_val); if (unlikely((__pyx_t_2 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - ((struct __pyx_vtabstruct_8_cdec_sa_FloatList *)__pyx_v_self->__pyx_vtab)->set(__pyx_v_self, __pyx_t_1, __pyx_t_2); - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec_sa.FloatList.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static Py_ssize_t __pyx_pw_8_cdec_sa_9FloatList_9__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_8_cdec_sa_9FloatList_9__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9FloatList_8__len__(((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":46 - * self.set(i, val) - * - * def __len__(self): # <<<<<<<<<<<<<< - * return self.len - * - */ - -static Py_ssize_t __pyx_pf_8_cdec_sa_9FloatList_8__len__(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":47 - * - * def __len__(self): - * return self.len # <<<<<<<<<<<<<< - * - * def append(self, float val): - */ - __pyx_r = __pyx_v_self->len; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9FloatList_11append(PyObject *__pyx_v_self, PyObject *__pyx_arg_val); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9FloatList_11append(PyObject *__pyx_v_self, PyObject *__pyx_arg_val) { - float __pyx_v_val; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("append (wrapper)", 0); - assert(__pyx_arg_val); { - __pyx_v_val = __pyx_PyFloat_AsFloat(__pyx_arg_val); if (unlikely((__pyx_v_val == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.FloatList.append", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_9FloatList_10append(((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_v_self), ((float)__pyx_v_val)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":49 - * return self.len - * - * def append(self, float val): # <<<<<<<<<<<<<< - * if self.len == self.size: - * self.size = self.size + self.increment - */ - -static PyObject *__pyx_pf_8_cdec_sa_9FloatList_10append(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, float __pyx_v_val) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("append", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":50 - * - * def append(self, float val): - * if self.len == self.size: # <<<<<<<<<<<<<< - * self.size = self.size + self.increment - * self.arr = realloc(self.arr, self.size*sizeof(float)) - */ - __pyx_t_1 = (__pyx_v_self->len == __pyx_v_self->size); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":51 - * def append(self, float val): - * if self.len == self.size: - * self.size = self.size + self.increment # <<<<<<<<<<<<<< - * self.arr = realloc(self.arr, self.size*sizeof(float)) - * self.arr[self.len] = val - */ - __pyx_v_self->size = (__pyx_v_self->size + __pyx_v_self->increment); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":52 - * if self.len == self.size: - * self.size = self.size + self.increment - * self.arr = realloc(self.arr, self.size*sizeof(float)) # <<<<<<<<<<<<<< - * self.arr[self.len] = val - * self.len = self.len + 1 - */ - __pyx_v_self->arr = ((float *)realloc(__pyx_v_self->arr, (__pyx_v_self->size * (sizeof(float))))); - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":53 - * self.size = self.size + self.increment - * self.arr = realloc(self.arr, self.size*sizeof(float)) - * self.arr[self.len] = val # <<<<<<<<<<<<<< - * self.len = self.len + 1 - * - */ - (__pyx_v_self->arr[__pyx_v_self->len]) = __pyx_v_val; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":54 - * self.arr = realloc(self.arr, self.size*sizeof(float)) - * self.arr[self.len] = val - * self.len = self.len + 1 # <<<<<<<<<<<<<< - * - * cdef void write_handle(self, FILE* f): - */ - __pyx_v_self->len = (__pyx_v_self->len + 1); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":56 - * self.len = self.len + 1 - * - * cdef void write_handle(self, FILE* f): # <<<<<<<<<<<<<< - * fwrite(&(self.len), sizeof(float), 1, f) - * fwrite(self.arr, sizeof(float), self.len, f) - */ - -static void __pyx_f_8_cdec_sa_9FloatList_write_handle(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, FILE *__pyx_v_f) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_handle", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":57 - * - * cdef void write_handle(self, FILE* f): - * fwrite(&(self.len), sizeof(float), 1, f) # <<<<<<<<<<<<<< - * fwrite(self.arr, sizeof(float), self.len, f) - * - */ - fwrite((&__pyx_v_self->len), (sizeof(float)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":58 - * cdef void write_handle(self, FILE* f): - * fwrite(&(self.len), sizeof(float), 1, f) - * fwrite(self.arr, sizeof(float), self.len, f) # <<<<<<<<<<<<<< - * - * def write(self, char* filename): - */ - fwrite(__pyx_v_self->arr, (sizeof(float)), __pyx_v_self->len, __pyx_v_f); - - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9FloatList_13write(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9FloatList_13write(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.FloatList.write", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_9FloatList_12write(((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":60 - * fwrite(self.arr, sizeof(float), self.len, f) - * - * def write(self, char* filename): # <<<<<<<<<<<<<< - * cdef FILE* f - * f = fopen(filename, "w") - */ - -static PyObject *__pyx_pf_8_cdec_sa_9FloatList_12write(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, char *__pyx_v_filename) { - FILE *__pyx_v_f; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":62 - * def write(self, char* filename): - * cdef FILE* f - * f = fopen(filename, "w") # <<<<<<<<<<<<<< - * self.write_handle(f) - * fclose(f) - */ - __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":63 - * cdef FILE* f - * f = fopen(filename, "w") - * self.write_handle(f) # <<<<<<<<<<<<<< - * fclose(f) - * - */ - ((struct __pyx_vtabstruct_8_cdec_sa_FloatList *)__pyx_v_self->__pyx_vtab)->write_handle(__pyx_v_self, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":64 - * f = fopen(filename, "w") - * self.write_handle(f) - * fclose(f) # <<<<<<<<<<<<<< - * - * cdef void read_handle(self, FILE* f): - */ - fclose(__pyx_v_f); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":66 - * fclose(f) - * - * cdef void read_handle(self, FILE* f): # <<<<<<<<<<<<<< - * free(self.arr) - * fread(&(self.len), sizeof(float), 1, f) - */ - -static void __pyx_f_8_cdec_sa_9FloatList_read_handle(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, FILE *__pyx_v_f) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_handle", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":67 - * - * cdef void read_handle(self, FILE* f): - * free(self.arr) # <<<<<<<<<<<<<< - * fread(&(self.len), sizeof(float), 1, f) - * self.arr = malloc(self.len * sizeof(float)) - */ - free(__pyx_v_self->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":68 - * cdef void read_handle(self, FILE* f): - * free(self.arr) - * fread(&(self.len), sizeof(float), 1, f) # <<<<<<<<<<<<<< - * self.arr = malloc(self.len * sizeof(float)) - * self.size = self.len - */ - fread((&__pyx_v_self->len), (sizeof(float)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":69 - * free(self.arr) - * fread(&(self.len), sizeof(float), 1, f) - * self.arr = malloc(self.len * sizeof(float)) # <<<<<<<<<<<<<< - * self.size = self.len - * fread(self.arr, sizeof(float), self.len, f) - */ - __pyx_v_self->arr = ((float *)malloc((__pyx_v_self->len * (sizeof(float))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":70 - * fread(&(self.len), sizeof(float), 1, f) - * self.arr = malloc(self.len * sizeof(float)) - * self.size = self.len # <<<<<<<<<<<<<< - * fread(self.arr, sizeof(float), self.len, f) - * - */ - __pyx_v_self->size = __pyx_v_self->len; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":71 - * self.arr = malloc(self.len * sizeof(float)) - * self.size = self.len - * fread(self.arr, sizeof(float), self.len, f) # <<<<<<<<<<<<<< - * - * def read(self, char* filename): - */ - fread(__pyx_v_self->arr, (sizeof(float)), __pyx_v_self->len, __pyx_v_f); - - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9FloatList_15read(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9FloatList_15read(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.FloatList.read", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_9FloatList_14read(((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":73 - * fread(self.arr, sizeof(float), self.len, f) - * - * def read(self, char* filename): # <<<<<<<<<<<<<< - * cdef FILE* f - * f = fopen(filename, "r") - */ - -static PyObject *__pyx_pf_8_cdec_sa_9FloatList_14read(struct __pyx_obj_8_cdec_sa_FloatList *__pyx_v_self, char *__pyx_v_filename) { - FILE *__pyx_v_f; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":75 - * def read(self, char* filename): - * cdef FILE* f - * f = fopen(filename, "r") # <<<<<<<<<<<<<< - * self.read_handle(f) - * fclose(f) - */ - __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":76 - * cdef FILE* f - * f = fopen(filename, "r") - * self.read_handle(f) # <<<<<<<<<<<<<< - * fclose(f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_FloatList *)__pyx_v_self->__pyx_vtab)->read_handle(__pyx_v_self, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":77 - * f = fopen(filename, "r") - * self.read_handle(f) - * fclose(f) # <<<<<<<<<<<<<< - */ - fclose(__pyx_v_f); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_7IntList_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_7IntList_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_v_size; - int __pyx_v_increment; - int __pyx_v_initial_len; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__size,&__pyx_n_s__increment,&__pyx_n_s__initial_len,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[3] = {0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size); - if (value) { values[0] = value; kw_args--; } - } - case 1: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__increment); - if (value) { values[1] = value; kw_args--; } - } - case 2: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__initial_len); - if (value) { values[2] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - if (values[0]) { - } else { - __pyx_v_size = ((int)0); - } - if (values[1]) { - } else { - __pyx_v_increment = ((int)1); - } - if (values[2]) { - } else { - __pyx_v_initial_len = ((int)0); - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - } - if (values[0]) { - __pyx_v_size = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_size = ((int)0); - } - if (values[1]) { - __pyx_v_increment = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_increment == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_increment = ((int)1); - } - if (values[2]) { - __pyx_v_initial_len = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_initial_len == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_initial_len = ((int)0); - } - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.IntList.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_7IntList___cinit__(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), __pyx_v_size, __pyx_v_increment, __pyx_v_initial_len); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":15 - * cdef int* arr - * - * def __cinit__(self, int size=0, int increment=1, int initial_len=0): # <<<<<<<<<<<<<< - * if initial_len > size: - * size = initial_len - */ - -static int __pyx_pf_8_cdec_sa_7IntList___cinit__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, int __pyx_v_size, int __pyx_v_increment, int __pyx_v_initial_len) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":16 - * - * def __cinit__(self, int size=0, int increment=1, int initial_len=0): - * if initial_len > size: # <<<<<<<<<<<<<< - * size = initial_len - * self.size = size - */ - __pyx_t_1 = (__pyx_v_initial_len > __pyx_v_size); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":17 - * def __cinit__(self, int size=0, int increment=1, int initial_len=0): - * if initial_len > size: - * size = initial_len # <<<<<<<<<<<<<< - * self.size = size - * self.increment = increment - */ - __pyx_v_size = __pyx_v_initial_len; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":18 - * if initial_len > size: - * size = initial_len - * self.size = size # <<<<<<<<<<<<<< - * self.increment = increment - * self.len = initial_len - */ - __pyx_v_self->size = __pyx_v_size; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":19 - * size = initial_len - * self.size = size - * self.increment = increment # <<<<<<<<<<<<<< - * self.len = initial_len - * self.arr = malloc(size*sizeof(int)) - */ - __pyx_v_self->increment = __pyx_v_increment; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":20 - * self.size = size - * self.increment = increment - * self.len = initial_len # <<<<<<<<<<<<<< - * self.arr = malloc(size*sizeof(int)) - * memset(self.arr, 0, initial_len*sizeof(int)) - */ - __pyx_v_self->len = __pyx_v_initial_len; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":21 - * self.increment = increment - * self.len = initial_len - * self.arr = malloc(size*sizeof(int)) # <<<<<<<<<<<<<< - * memset(self.arr, 0, initial_len*sizeof(int)) - * - */ - __pyx_v_self->arr = ((int *)malloc((__pyx_v_size * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":22 - * self.len = initial_len - * self.arr = malloc(size*sizeof(int)) - * memset(self.arr, 0, initial_len*sizeof(int)) # <<<<<<<<<<<<<< - * - * def __str__(self): - */ - memset(__pyx_v_self->arr, 0, (__pyx_v_initial_len * (sizeof(int)))); - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_3__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_3__str__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_7IntList_2__str__(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":24 - * memset(self.arr, 0, initial_len*sizeof(int)) - * - * def __str__(self): # <<<<<<<<<<<<<< - * cdef unsigned i - * ret = "IntList[" - */ - -static PyObject *__pyx_pf_8_cdec_sa_7IntList_2__str__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self) { - PyObject *__pyx_v_ret = NULL; - int __pyx_v_idx; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__str__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":26 - * def __str__(self): - * cdef unsigned i - * ret = "IntList[" # <<<<<<<<<<<<<< - * for idx in range(self.size): - * if idx>0: - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); - __pyx_v_ret = ((PyObject *)__pyx_kp_s_3); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":27 - * cdef unsigned i - * ret = "IntList[" - * for idx in range(self.size): # <<<<<<<<<<<<<< - * if idx>0: - * ret += "," - */ - __pyx_t_1 = __pyx_v_self->size; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_idx = __pyx_t_2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":28 - * ret = "IntList[" - * for idx in range(self.size): - * if idx>0: # <<<<<<<<<<<<<< - * ret += "," - * ret += str(self.arr[idx]) - */ - __pyx_t_3 = (__pyx_v_idx > 0); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":29 - * for idx in range(self.size): - * if idx>0: - * ret += "," # <<<<<<<<<<<<<< - * ret += str(self.arr[idx]) - * ret += "]" - */ - __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_ret, ((PyObject *)__pyx_kp_s_4)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_v_ret); - __pyx_v_ret = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":30 - * if idx>0: - * ret += "," - * ret += str(self.arr[idx]) # <<<<<<<<<<<<<< - * ret += "]" - * ret += "len=" - */ - __pyx_t_4 = PyInt_FromLong((__pyx_v_self->arr[__pyx_v_idx])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_ret, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_v_ret); - __pyx_v_ret = __pyx_t_5; - __pyx_t_5 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":31 - * ret += "," - * ret += str(self.arr[idx]) - * ret += "]" # <<<<<<<<<<<<<< - * ret += "len=" - * ret += self.len - */ - __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_ret, ((PyObject *)__pyx_kp_s_5)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_v_ret); - __pyx_v_ret = __pyx_t_5; - __pyx_t_5 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":32 - * ret += str(self.arr[idx]) - * ret += "]" - * ret += "len=" # <<<<<<<<<<<<<< - * ret += self.len - * return ret - */ - __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_ret, ((PyObject *)__pyx_kp_s_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_v_ret); - __pyx_v_ret = __pyx_t_5; - __pyx_t_5 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":33 - * ret += "]" - * ret += "len=" - * ret += self.len # <<<<<<<<<<<<<< - * return ret - * - */ - __pyx_t_5 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_ret, __pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_v_ret); - __pyx_v_ret = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":34 - * ret += "len=" - * ret += self.len - * return ret # <<<<<<<<<<<<<< - * - * def index(self, val): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_ret); - __pyx_r = __pyx_v_ret; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("_cdec_sa.IntList.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_ret); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_5index(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_5index(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("index (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_7IntList_4index(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), ((PyObject *)__pyx_v_val)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":36 - * return ret - * - * def index(self, val): # <<<<<<<<<<<<<< - * cdef unsigned i - * for i in range(self.len): - */ - -static PyObject *__pyx_pf_8_cdec_sa_7IntList_4index(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_val) { - unsigned int __pyx_v_i; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - unsigned int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("index", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":38 - * def index(self, val): - * cdef unsigned i - * for i in range(self.len): # <<<<<<<<<<<<<< - * if self.arr[i] == val: - * return i - */ - __pyx_t_1 = __pyx_v_self->len; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":39 - * cdef unsigned i - * for i in range(self.len): - * if self.arr[i] == val: # <<<<<<<<<<<<<< - * return i - * return IndexError - */ - __pyx_t_3 = PyInt_FromLong((__pyx_v_self->arr[__pyx_v_i])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_v_val, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":40 - * for i in range(self.len): - * if self.arr[i] == val: - * return i # <<<<<<<<<<<<<< - * return IndexError - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = PyLong_FromUnsignedLong(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; - goto __pyx_L5; - } - __pyx_L5:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":41 - * if self.arr[i] == val: - * return i - * return IndexError # <<<<<<<<<<<<<< - * - * def partition(self,start,end): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_builtin_IndexError); - __pyx_r = __pyx_builtin_IndexError; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec_sa.IntList.index", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_7partition(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_7partition(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_start = 0; - PyObject *__pyx_v_end = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,0}; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("partition (wrapper)", 0); - { - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("partition", 1, 2, 2, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "partition") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_start = values[0]; - __pyx_v_end = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("partition", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.IntList.partition", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_7IntList_6partition(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), __pyx_v_start, __pyx_v_end); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":43 - * return IndexError - * - * def partition(self,start,end): # <<<<<<<<<<<<<< - * pivot = self.arr[end] - * bottom = start-1 - */ - -static PyObject *__pyx_pf_8_cdec_sa_7IntList_6partition(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_end) { - PyObject *__pyx_v_pivot = NULL; - PyObject *__pyx_v_bottom = NULL; - PyObject *__pyx_v_top = NULL; - long __pyx_v_done; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - Py_ssize_t __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - Py_ssize_t __pyx_t_5; - int __pyx_t_6; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("partition", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":44 - * - * def partition(self,start,end): - * pivot = self.arr[end] # <<<<<<<<<<<<<< - * bottom = start-1 - * top = end - */ - __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_end); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromLong((__pyx_v_self->arr[__pyx_t_1])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_pivot = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":45 - * def partition(self,start,end): - * pivot = self.arr[end] - * bottom = start-1 # <<<<<<<<<<<<<< - * top = end - * done = 0 - */ - __pyx_t_2 = PyNumber_Subtract(__pyx_v_start, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_bottom = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":46 - * pivot = self.arr[end] - * bottom = start-1 - * top = end # <<<<<<<<<<<<<< - * done = 0 - * while not done: - */ - __Pyx_INCREF(__pyx_v_end); - __pyx_v_top = __pyx_v_end; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":47 - * bottom = start-1 - * top = end - * done = 0 # <<<<<<<<<<<<<< - * while not done: - * while not done: - */ - __pyx_v_done = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":48 - * top = end - * done = 0 - * while not done: # <<<<<<<<<<<<<< - * while not done: - * bottom += 1 - */ - while (1) { - __pyx_t_3 = (!__pyx_v_done); - if (!__pyx_t_3) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":49 - * done = 0 - * while not done: - * while not done: # <<<<<<<<<<<<<< - * bottom += 1 - * if bottom == top: - */ - while (1) { - __pyx_t_3 = (!__pyx_v_done); - if (!__pyx_t_3) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":50 - * while not done: - * while not done: - * bottom += 1 # <<<<<<<<<<<<<< - * if bottom == top: - * done = 1 - */ - __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_v_bottom, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_v_bottom); - __pyx_v_bottom = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":51 - * while not done: - * bottom += 1 - * if bottom == top: # <<<<<<<<<<<<<< - * done = 1 - * break - */ - __pyx_t_2 = PyObject_RichCompare(__pyx_v_bottom, __pyx_v_top, Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":52 - * bottom += 1 - * if bottom == top: - * done = 1 # <<<<<<<<<<<<<< - * break - * if self.arr[bottom] > pivot: - */ - __pyx_v_done = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":53 - * if bottom == top: - * done = 1 - * break # <<<<<<<<<<<<<< - * if self.arr[bottom] > pivot: - * self.arr[top] = self.arr[bottom] - */ - goto __pyx_L6_break; - goto __pyx_L7; - } - __pyx_L7:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":54 - * done = 1 - * break - * if self.arr[bottom] > pivot: # <<<<<<<<<<<<<< - * self.arr[top] = self.arr[bottom] - * break - */ - __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_bottom); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromLong((__pyx_v_self->arr[__pyx_t_1])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_v_pivot, Py_GT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":55 - * break - * if self.arr[bottom] > pivot: - * self.arr[top] = self.arr[bottom] # <<<<<<<<<<<<<< - * break - * while not done: - */ - __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_bottom); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_top); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - (__pyx_v_self->arr[__pyx_t_5]) = (__pyx_v_self->arr[__pyx_t_1]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":56 - * if self.arr[bottom] > pivot: - * self.arr[top] = self.arr[bottom] - * break # <<<<<<<<<<<<<< - * while not done: - * top -= 1 - */ - goto __pyx_L6_break; - goto __pyx_L8; - } - __pyx_L8:; - } - __pyx_L6_break:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":57 - * self.arr[top] = self.arr[bottom] - * break - * while not done: # <<<<<<<<<<<<<< - * top -= 1 - * if top == bottom: - */ - while (1) { - __pyx_t_3 = (!__pyx_v_done); - if (!__pyx_t_3) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":58 - * break - * while not done: - * top -= 1 # <<<<<<<<<<<<<< - * if top == bottom: - * done = 1 - */ - __pyx_t_4 = PyNumber_InPlaceSubtract(__pyx_v_top, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_v_top); - __pyx_v_top = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":59 - * while not done: - * top -= 1 - * if top == bottom: # <<<<<<<<<<<<<< - * done = 1 - * break - */ - __pyx_t_4 = PyObject_RichCompare(__pyx_v_top, __pyx_v_bottom, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":60 - * top -= 1 - * if top == bottom: - * done = 1 # <<<<<<<<<<<<<< - * break - * if self.arr[top] < pivot: - */ - __pyx_v_done = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":61 - * if top == bottom: - * done = 1 - * break # <<<<<<<<<<<<<< - * if self.arr[top] < pivot: - * self.arr[bottom] = self.arr[top] - */ - goto __pyx_L10_break; - goto __pyx_L11; - } - __pyx_L11:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":62 - * done = 1 - * break - * if self.arr[top] < pivot: # <<<<<<<<<<<<<< - * self.arr[bottom] = self.arr[top] - * break - */ - __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_top); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = PyInt_FromLong((__pyx_v_self->arr[__pyx_t_1])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_v_pivot, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":63 - * break - * if self.arr[top] < pivot: - * self.arr[bottom] = self.arr[top] # <<<<<<<<<<<<<< - * break - * self.arr[top] = pivot - */ - __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_top); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_bottom); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - (__pyx_v_self->arr[__pyx_t_5]) = (__pyx_v_self->arr[__pyx_t_1]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":64 - * if self.arr[top] < pivot: - * self.arr[bottom] = self.arr[top] - * break # <<<<<<<<<<<<<< - * self.arr[top] = pivot - * return top - */ - goto __pyx_L10_break; - goto __pyx_L12; - } - __pyx_L12:; - } - __pyx_L10_break:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":65 - * self.arr[bottom] = self.arr[top] - * break - * self.arr[top] = pivot # <<<<<<<<<<<<<< - * return top - * - */ - __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_pivot); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_top); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - (__pyx_v_self->arr[__pyx_t_1]) = __pyx_t_6; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":66 - * break - * self.arr[top] = pivot - * return top # <<<<<<<<<<<<<< - * - * def _doquicksort(self,start,end): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_top); - __pyx_r = __pyx_v_top; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec_sa.IntList.partition", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_pivot); - __Pyx_XDECREF(__pyx_v_bottom); - __Pyx_XDECREF(__pyx_v_top); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_9_doquicksort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_9_doquicksort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_start = 0; - PyObject *__pyx_v_end = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,0}; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_doquicksort (wrapper)", 0); - { - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("_doquicksort", 1, 2, 2, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_doquicksort") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_start = values[0]; - __pyx_v_end = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_doquicksort", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.IntList._doquicksort", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_7IntList_8_doquicksort(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), __pyx_v_start, __pyx_v_end); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":68 - * return top - * - * def _doquicksort(self,start,end): # <<<<<<<<<<<<<< - * if start < end: - * split = self.partition(start,end) - */ - -static PyObject *__pyx_pf_8_cdec_sa_7IntList_8_doquicksort(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_end) { - PyObject *__pyx_v_split = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_doquicksort", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":69 - * - * def _doquicksort(self,start,end): - * if start < end: # <<<<<<<<<<<<<< - * split = self.partition(start,end) - * self._doquicksort(start,split-1) - */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_v_end, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":70 - * def _doquicksort(self,start,end): - * if start < end: - * split = self.partition(start,end) # <<<<<<<<<<<<<< - * self._doquicksort(start,split-1) - * self._doquicksort(split+1,end) - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__partition); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_start); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_start); - __Pyx_GIVEREF(__pyx_v_start); - __Pyx_INCREF(__pyx_v_end); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_end); - __Pyx_GIVEREF(__pyx_v_end); - __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_v_split = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":71 - * if start < end: - * split = self.partition(start,end) - * self._doquicksort(start,split-1) # <<<<<<<<<<<<<< - * self._doquicksort(split+1,end) - * else: - */ - __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___doquicksort); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyNumber_Subtract(__pyx_v_split, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_start); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_start); - __Pyx_GIVEREF(__pyx_v_start); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":72 - * split = self.partition(start,end) - * self._doquicksort(start,split-1) - * self._doquicksort(split+1,end) # <<<<<<<<<<<<<< - * else: - * return - */ - __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___doquicksort); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyNumber_Add(__pyx_v_split, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_end); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_end); - __Pyx_GIVEREF(__pyx_v_end); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":74 - * self._doquicksort(split+1,end) - * else: - * return # <<<<<<<<<<<<<< - * - * def sort(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec_sa.IntList._doquicksort", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_split); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_11sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_11sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("sort (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_7IntList_10sort(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":76 - * return - * - * def sort(self): # <<<<<<<<<<<<<< - * self._doquicksort(0,self.len-1) - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_7IntList_10sort(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("sort", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":77 - * - * def sort(self): - * self._doquicksort(0,self.len-1) # <<<<<<<<<<<<<< - * - * def reset(self): - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___doquicksort); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyInt_FromLong((__pyx_v_self->len - 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - __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_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.IntList.sort", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_13reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_13reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("reset (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_7IntList_12reset(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":79 - * self._doquicksort(0,self.len-1) - * - * def reset(self): # <<<<<<<<<<<<<< - * self.len = 0 - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_7IntList_12reset(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("reset", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":80 - * - * def reset(self): - * self.len = 0 # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - __pyx_v_self->len = 0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static void __pyx_pw_8_cdec_sa_7IntList_15__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_8_cdec_sa_7IntList_15__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_8_cdec_sa_7IntList_14__dealloc__(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":82 - * self.len = 0 - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * free(self.arr) - * - */ - -static void __pyx_pf_8_cdec_sa_7IntList_14__dealloc__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":83 - * - * def __dealloc__(self): - * free(self.arr) # <<<<<<<<<<<<<< - * - * def __getitem__(self, index): - */ - free(__pyx_v_self->arr); - - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_17__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_17__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_7IntList_16__getitem__(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), ((PyObject *)__pyx_v_index)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":85 - * free(self.arr) - * - * def __getitem__(self, index): # <<<<<<<<<<<<<< - * cdef int i, j, k - * if isinstance(index, int): - */ - -static PyObject *__pyx_pf_8_cdec_sa_7IntList_16__getitem__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_index) { - int __pyx_v_i; - int __pyx_v_j; - int __pyx_v_k; - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - int __pyx_t_7; - int __pyx_t_8; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__getitem__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":87 - * def __getitem__(self, index): - * cdef int i, j, k - * if isinstance(index, int): # <<<<<<<<<<<<<< - * j = index - * if j < 0: - */ - __pyx_t_1 = ((PyObject *)((PyObject*)(&PyInt_Type))); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_index, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":88 - * cdef int i, j, k - * if isinstance(index, int): - * j = index # <<<<<<<<<<<<<< - * if j < 0: - * j = self.len + j - */ - __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_v_index); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_j = __pyx_t_3; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":89 - * if isinstance(index, int): - * j = index - * if j < 0: # <<<<<<<<<<<<<< - * j = self.len + j - * if j<0 or j>=self.len: - */ - __pyx_t_2 = (__pyx_v_j < 0); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":90 - * j = index - * if j < 0: - * j = self.len + j # <<<<<<<<<<<<<< - * if j<0 or j>=self.len: - * raise IndexError("Requested index %d of %d-length IntList" % (index, self.len)) - */ - __pyx_v_j = (__pyx_v_self->len + __pyx_v_j); - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":91 - * if j < 0: - * j = self.len + j - * if j<0 or j>=self.len: # <<<<<<<<<<<<<< - * raise IndexError("Requested index %d of %d-length IntList" % (index, self.len)) - * return self.arr[j] - */ - __pyx_t_2 = (__pyx_v_j < 0); - if (!__pyx_t_2) { - __pyx_t_4 = (__pyx_v_j >= __pyx_v_self->len); - __pyx_t_5 = __pyx_t_4; - } else { - __pyx_t_5 = __pyx_t_2; - } - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":92 - * j = self.len + j - * if j<0 or j>=self.len: - * raise IndexError("Requested index %d of %d-length IntList" % (index, self.len)) # <<<<<<<<<<<<<< - * return self.arr[j] - * elif isinstance(index, slice): - */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_INCREF(__pyx_v_index); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_index); - __Pyx_GIVEREF(__pyx_v_index); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_7), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":93 - * if j<0 or j>=self.len: - * raise IndexError("Requested index %d of %d-length IntList" % (index, self.len)) - * return self.arr[j] # <<<<<<<<<<<<<< - * elif isinstance(index, slice): - * i = index.start - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong((__pyx_v_self->arr[__pyx_v_j])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - goto __pyx_L3; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":94 - * raise IndexError("Requested index %d of %d-length IntList" % (index, self.len)) - * return self.arr[j] - * elif isinstance(index, slice): # <<<<<<<<<<<<<< - * i = index.start - * j = index.stop - */ - __pyx_t_1 = ((PyObject *)((PyObject*)(&PySlice_Type))); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_5 = __Pyx_TypeCheck(__pyx_v_index, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":95 - * return self.arr[j] - * elif isinstance(index, slice): - * i = index.start # <<<<<<<<<<<<<< - * j = index.stop - * if i < 0: - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_i = __pyx_t_3; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":96 - * elif isinstance(index, slice): - * i = index.start - * j = index.stop # <<<<<<<<<<<<<< - * if i < 0: - * i = self.len + i - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__stop); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_j = __pyx_t_3; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":97 - * i = index.start - * j = index.stop - * if i < 0: # <<<<<<<<<<<<<< - * i = self.len + i - * if j < 0: - */ - __pyx_t_5 = (__pyx_v_i < 0); - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":98 - * j = index.stop - * if i < 0: - * i = self.len + i # <<<<<<<<<<<<<< - * if j < 0: - * j = self.len + j - */ - __pyx_v_i = (__pyx_v_self->len + __pyx_v_i); - goto __pyx_L6; - } - __pyx_L6:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":99 - * if i < 0: - * i = self.len + i - * if j < 0: # <<<<<<<<<<<<<< - * j = self.len + j - * if i < 0 or i >= self.len or j < 0 or j > self.len: - */ - __pyx_t_5 = (__pyx_v_j < 0); - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":100 - * i = self.len + i - * if j < 0: - * j = self.len + j # <<<<<<<<<<<<<< - * if i < 0 or i >= self.len or j < 0 or j > self.len: - * raise IndexError("Requested index %d:%d of %d-length IntList" % (index.start, index.stop, self.len)) - */ - __pyx_v_j = (__pyx_v_self->len + __pyx_v_j); - goto __pyx_L7; - } - __pyx_L7:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":101 - * if j < 0: - * j = self.len + j - * if i < 0 or i >= self.len or j < 0 or j > self.len: # <<<<<<<<<<<<<< - * raise IndexError("Requested index %d:%d of %d-length IntList" % (index.start, index.stop, self.len)) - * result = () - */ - __pyx_t_5 = (__pyx_v_i < 0); - if (!__pyx_t_5) { - __pyx_t_2 = (__pyx_v_i >= __pyx_v_self->len); - if (!__pyx_t_2) { - __pyx_t_4 = (__pyx_v_j < 0); - if (!__pyx_t_4) { - __pyx_t_7 = (__pyx_v_j > __pyx_v_self->len); - __pyx_t_8 = __pyx_t_7; - } else { - __pyx_t_8 = __pyx_t_4; - } - __pyx_t_4 = __pyx_t_8; - } else { - __pyx_t_4 = __pyx_t_2; - } - __pyx_t_2 = __pyx_t_4; - } else { - __pyx_t_2 = __pyx_t_5; - } - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":102 - * j = self.len + j - * if i < 0 or i >= self.len or j < 0 or j > self.len: - * raise IndexError("Requested index %d:%d of %d-length IntList" % (index.start, index.stop, self.len)) # <<<<<<<<<<<<<< - * result = () - * for k from i <= k < j: - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__stop); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_9 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - __pyx_t_1 = 0; - __pyx_t_6 = 0; - __pyx_t_9 = 0; - __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_8), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_9)); - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_9)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); - __pyx_t_9 = 0; - __pyx_t_9 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_Raise(__pyx_t_9, 0, 0, 0); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L8; - } - __pyx_L8:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":103 - * if i < 0 or i >= self.len or j < 0 or j > self.len: - * raise IndexError("Requested index %d:%d of %d-length IntList" % (index.start, index.stop, self.len)) - * result = () # <<<<<<<<<<<<<< - * for k from i <= k < j: - * result = result + (self.arr[k],) - */ - __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); - __pyx_v_result = __pyx_empty_tuple; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":104 - * raise IndexError("Requested index %d:%d of %d-length IntList" % (index.start, index.stop, self.len)) - * result = () - * for k from i <= k < j: # <<<<<<<<<<<<<< - * result = result + (self.arr[k],) - * return result - */ - __pyx_t_3 = __pyx_v_j; - for (__pyx_v_k = __pyx_v_i; __pyx_v_k < __pyx_t_3; __pyx_v_k++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":105 - * result = () - * for k from i <= k < j: - * result = result + (self.arr[k],) # <<<<<<<<<<<<<< - * return result - * else: - */ - __pyx_t_9 = PyInt_FromLong((__pyx_v_self->arr[__pyx_v_k])); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - __pyx_t_9 = 0; - __pyx_t_9 = PyNumber_Add(((PyObject *)__pyx_v_result), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_9)); - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_result)); - __pyx_v_result = __pyx_t_9; - __pyx_t_9 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":106 - * for k from i <= k < j: - * result = result + (self.arr[k],) - * return result # <<<<<<<<<<<<<< - * else: - * raise TypeError("Illegal key type %s for IntList" % type(index)) - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - __pyx_r = ((PyObject *)__pyx_v_result); - goto __pyx_L0; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":108 - * return result - * else: - * raise TypeError("Illegal key type %s for IntList" % type(index)) # <<<<<<<<<<<<<< - * - * cdef void set(self, int i, int val): - */ - __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), ((PyObject *)Py_TYPE(__pyx_v_index))); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_9)); - __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_9)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); - __pyx_t_9 = 0; - __pyx_t_9 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_Raise(__pyx_t_9, 0, 0, 0); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("_cdec_sa.IntList.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":110 - * raise TypeError("Illegal key type %s for IntList" % type(index)) - * - * cdef void set(self, int i, int val): # <<<<<<<<<<<<<< - * j = i - * if i<0: - */ - -static void __pyx_f_8_cdec_sa_7IntList_set(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, int __pyx_v_i, int __pyx_v_val) { - int __pyx_v_j; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("set", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":111 - * - * cdef void set(self, int i, int val): - * j = i # <<<<<<<<<<<<<< - * if i<0: - * j = self.len + i - */ - __pyx_v_j = __pyx_v_i; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":112 - * cdef void set(self, int i, int val): - * j = i - * if i<0: # <<<<<<<<<<<<<< - * j = self.len + i - * if j<0 or j>=self.len: - */ - __pyx_t_1 = (__pyx_v_i < 0); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":113 - * j = i - * if i<0: - * j = self.len + i # <<<<<<<<<<<<<< - * if j<0 or j>=self.len: - * raise IndexError("Requested index %d of %d-length IntList" % (i, self.len)) - */ - __pyx_v_j = (__pyx_v_self->len + __pyx_v_i); - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":114 - * if i<0: - * j = self.len + i - * if j<0 or j>=self.len: # <<<<<<<<<<<<<< - * raise IndexError("Requested index %d of %d-length IntList" % (i, self.len)) - * self.arr[j] = val - */ - __pyx_t_1 = (__pyx_v_j < 0); - if (!__pyx_t_1) { - __pyx_t_2 = (__pyx_v_j >= __pyx_v_self->len); - __pyx_t_3 = __pyx_t_2; - } else { - __pyx_t_3 = __pyx_t_1; - } - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":115 - * j = self.len + i - * if j<0 or j>=self.len: - * raise IndexError("Requested index %d of %d-length IntList" % (i, self.len)) # <<<<<<<<<<<<<< - * self.arr[j] = val - * - */ - __pyx_t_4 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_4 = 0; - __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_7), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); - __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":116 - * if j<0 or j>=self.len: - * raise IndexError("Requested index %d of %d-length IntList" % (i, self.len)) - * self.arr[j] = val # <<<<<<<<<<<<<< - * - * def __setitem__(self, i, val): - */ - (__pyx_v_self->arr[__pyx_v_j]) = __pyx_v_val; - - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_WriteUnraisable("_cdec_sa.IntList.set", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_7IntList_19__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val); /*proto*/ -static int __pyx_pw_8_cdec_sa_7IntList_19__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_7IntList_18__setitem__(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), ((PyObject *)__pyx_v_i), ((PyObject *)__pyx_v_val)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":118 - * self.arr[j] = val - * - * def __setitem__(self, i, val): # <<<<<<<<<<<<<< - * self.set(i, val) - * - */ - -static int __pyx_pf_8_cdec_sa_7IntList_18__setitem__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__setitem__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":119 - * - * def __setitem__(self, i, val): - * self.set(i, val) # <<<<<<<<<<<<<< - * - * def __len__(self): - */ - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_v_val); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->__pyx_vtab)->set(__pyx_v_self, __pyx_t_1, __pyx_t_2); - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec_sa.IntList.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static Py_ssize_t __pyx_pw_8_cdec_sa_7IntList_21__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_8_cdec_sa_7IntList_21__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_7IntList_20__len__(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":121 - * self.set(i, val) - * - * def __len__(self): # <<<<<<<<<<<<<< - * return self.len - * - */ - -static Py_ssize_t __pyx_pf_8_cdec_sa_7IntList_20__len__(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":122 - * - * def __len__(self): - * return self.len # <<<<<<<<<<<<<< - * - * def getSize(self): - */ - __pyx_r = __pyx_v_self->len; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_23getSize(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_23getSize(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("getSize (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_7IntList_22getSize(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":124 - * return self.len - * - * def getSize(self): # <<<<<<<<<<<<<< - * return self.size - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_7IntList_22getSize(struct __pyx_obj_8_cdec_sa_IntList *__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("getSize", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":125 - * - * def getSize(self): - * return self.size # <<<<<<<<<<<<<< - * - * def append(self, int val): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __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_AddTraceback("_cdec_sa.IntList.getSize", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_25append(PyObject *__pyx_v_self, PyObject *__pyx_arg_val); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_25append(PyObject *__pyx_v_self, PyObject *__pyx_arg_val) { - int __pyx_v_val; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("append (wrapper)", 0); - assert(__pyx_arg_val); { - __pyx_v_val = __Pyx_PyInt_AsInt(__pyx_arg_val); if (unlikely((__pyx_v_val == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.IntList.append", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_7IntList_24append(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), ((int)__pyx_v_val)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":127 - * return self.size - * - * def append(self, int val): # <<<<<<<<<<<<<< - * self._append(val) - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_7IntList_24append(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, int __pyx_v_val) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("append", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":128 - * - * def append(self, int val): - * self._append(val) # <<<<<<<<<<<<<< - * - * cdef void _append(self, int val): - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->__pyx_vtab)->_append(__pyx_v_self, __pyx_v_val); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":130 - * self._append(val) - * - * cdef void _append(self, int val): # <<<<<<<<<<<<<< - * if self.len == self.size: - * self.size = self.size + self.increment - */ - -static void __pyx_f_8_cdec_sa_7IntList__append(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, int __pyx_v_val) { - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("_append", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":131 - * - * cdef void _append(self, int val): - * if self.len == self.size: # <<<<<<<<<<<<<< - * self.size = self.size + self.increment - * self.arr = realloc(self.arr, self.size*sizeof(int)) - */ - __pyx_t_1 = (__pyx_v_self->len == __pyx_v_self->size); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":132 - * cdef void _append(self, int val): - * if self.len == self.size: - * self.size = self.size + self.increment # <<<<<<<<<<<<<< - * self.arr = realloc(self.arr, self.size*sizeof(int)) - * self.arr[self.len] = val - */ - __pyx_v_self->size = (__pyx_v_self->size + __pyx_v_self->increment); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":133 - * if self.len == self.size: - * self.size = self.size + self.increment - * self.arr = realloc(self.arr, self.size*sizeof(int)) # <<<<<<<<<<<<<< - * self.arr[self.len] = val - * self.len = self.len + 1 - */ - __pyx_v_self->arr = ((int *)realloc(__pyx_v_self->arr, (__pyx_v_self->size * (sizeof(int))))); - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":134 - * self.size = self.size + self.increment - * self.arr = realloc(self.arr, self.size*sizeof(int)) - * self.arr[self.len] = val # <<<<<<<<<<<<<< - * self.len = self.len + 1 - * - */ - (__pyx_v_self->arr[__pyx_v_self->len]) = __pyx_v_val; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":135 - * self.arr = realloc(self.arr, self.size*sizeof(int)) - * self.arr[self.len] = val - * self.len = self.len + 1 # <<<<<<<<<<<<<< - * - * def extend(self, other): - */ - __pyx_v_self->len = (__pyx_v_self->len + 1); - - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_27extend(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_27extend(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("extend (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_7IntList_26extend(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), ((PyObject *)__pyx_v_other)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":137 - * self.len = self.len + 1 - * - * def extend(self, other): # <<<<<<<<<<<<<< - * self._extend(other) - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_7IntList_26extend(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, PyObject *__pyx_v_other) { - 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("extend", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":138 - * - * def extend(self, other): - * self._extend(other) # <<<<<<<<<<<<<< - * - * cdef void _extend(self, IntList other): - */ - if (!(likely(((__pyx_v_other) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_other, __pyx_ptype_8_cdec_sa_IntList))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = __pyx_v_other; - __Pyx_INCREF(__pyx_t_1); - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->__pyx_vtab)->_extend(__pyx_v_self, ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1)); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec_sa.IntList.extend", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":140 - * self._extend(other) - * - * cdef void _extend(self, IntList other): # <<<<<<<<<<<<<< - * self._extend_arr(other.arr, other.len) - * - */ - -static void __pyx_f_8_cdec_sa_7IntList__extend(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_other) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_extend", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":141 - * - * cdef void _extend(self, IntList other): - * self._extend_arr(other.arr, other.len) # <<<<<<<<<<<<<< - * - * cdef void _extend_arr(self, int* other, int other_len): - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->__pyx_vtab)->_extend_arr(__pyx_v_self, __pyx_v_other->arr, __pyx_v_other->len); - - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":143 - * self._extend_arr(other.arr, other.len) - * - * cdef void _extend_arr(self, int* other, int other_len): # <<<<<<<<<<<<<< - * if self.size < self.len + other_len: - * self.size = self.len + other_len - */ - -static void __pyx_f_8_cdec_sa_7IntList__extend_arr(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, int *__pyx_v_other, int __pyx_v_other_len) { - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("_extend_arr", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":144 - * - * cdef void _extend_arr(self, int* other, int other_len): - * if self.size < self.len + other_len: # <<<<<<<<<<<<<< - * self.size = self.len + other_len - * self.arr = realloc(self.arr, self.size*sizeof(int)) - */ - __pyx_t_1 = (__pyx_v_self->size < (__pyx_v_self->len + __pyx_v_other_len)); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":145 - * cdef void _extend_arr(self, int* other, int other_len): - * if self.size < self.len + other_len: - * self.size = self.len + other_len # <<<<<<<<<<<<<< - * self.arr = realloc(self.arr, self.size*sizeof(int)) - * memcpy(self.arr+self.len, other, other_len*sizeof(int)) - */ - __pyx_v_self->size = (__pyx_v_self->len + __pyx_v_other_len); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":146 - * if self.size < self.len + other_len: - * self.size = self.len + other_len - * self.arr = realloc(self.arr, self.size*sizeof(int)) # <<<<<<<<<<<<<< - * memcpy(self.arr+self.len, other, other_len*sizeof(int)) - * self.len = self.len + other_len - */ - __pyx_v_self->arr = ((int *)realloc(__pyx_v_self->arr, (__pyx_v_self->size * (sizeof(int))))); - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":147 - * self.size = self.len + other_len - * self.arr = realloc(self.arr, self.size*sizeof(int)) - * memcpy(self.arr+self.len, other, other_len*sizeof(int)) # <<<<<<<<<<<<<< - * self.len = self.len + other_len - * - */ - memcpy((__pyx_v_self->arr + __pyx_v_self->len), __pyx_v_other, (__pyx_v_other_len * (sizeof(int)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":148 - * self.arr = realloc(self.arr, self.size*sizeof(int)) - * memcpy(self.arr+self.len, other, other_len*sizeof(int)) - * self.len = self.len + other_len # <<<<<<<<<<<<<< - * - * cdef void _clear(self): - */ - __pyx_v_self->len = (__pyx_v_self->len + __pyx_v_other_len); - - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":150 - * self.len = self.len + other_len - * - * cdef void _clear(self): # <<<<<<<<<<<<<< - * free(self.arr) - * self.len = 0 - */ - -static void __pyx_f_8_cdec_sa_7IntList__clear(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_clear", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":151 - * - * cdef void _clear(self): - * free(self.arr) # <<<<<<<<<<<<<< - * self.len = 0 - * self.size = 0 - */ - free(__pyx_v_self->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":152 - * cdef void _clear(self): - * free(self.arr) - * self.len = 0 # <<<<<<<<<<<<<< - * self.size = 0 - * self.arr = malloc(0) - */ - __pyx_v_self->len = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":153 - * free(self.arr) - * self.len = 0 - * self.size = 0 # <<<<<<<<<<<<<< - * self.arr = malloc(0) - * - */ - __pyx_v_self->size = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":154 - * self.len = 0 - * self.size = 0 - * self.arr = malloc(0) # <<<<<<<<<<<<<< - * - * cdef void write_handle(self, FILE* f): - */ - __pyx_v_self->arr = ((int *)malloc(0)); - - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":156 - * self.arr = malloc(0) - * - * cdef void write_handle(self, FILE* f): # <<<<<<<<<<<<<< - * fwrite(&(self.len), sizeof(int), 1, f) - * fwrite(self.arr, sizeof(int), self.len, f) - */ - -static void __pyx_f_8_cdec_sa_7IntList_write_handle(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, FILE *__pyx_v_f) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_handle", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":157 - * - * cdef void write_handle(self, FILE* f): - * fwrite(&(self.len), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * fwrite(self.arr, sizeof(int), self.len, f) - * - */ - fwrite((&__pyx_v_self->len), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":158 - * cdef void write_handle(self, FILE* f): - * fwrite(&(self.len), sizeof(int), 1, f) - * fwrite(self.arr, sizeof(int), self.len, f) # <<<<<<<<<<<<<< - * - * def write(self, char* filename): - */ - fwrite(__pyx_v_self->arr, (sizeof(int)), __pyx_v_self->len, __pyx_v_f); - - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_29write(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_29write(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.IntList.write", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_7IntList_28write(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":160 - * fwrite(self.arr, sizeof(int), self.len, f) - * - * def write(self, char* filename): # <<<<<<<<<<<<<< - * cdef FILE* f - * f = fopen(filename, "w") - */ - -static PyObject *__pyx_pf_8_cdec_sa_7IntList_28write(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, char *__pyx_v_filename) { - FILE *__pyx_v_f; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":162 - * def write(self, char* filename): - * cdef FILE* f - * f = fopen(filename, "w") # <<<<<<<<<<<<<< - * self.write_handle(f) - * fclose(f) - */ - __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":163 - * cdef FILE* f - * f = fopen(filename, "w") - * self.write_handle(f) # <<<<<<<<<<<<<< - * fclose(f) - * - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->__pyx_vtab)->write_handle(__pyx_v_self, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":164 - * f = fopen(filename, "w") - * self.write_handle(f) - * fclose(f) # <<<<<<<<<<<<<< - * - * cdef void read_handle(self, FILE* f): - */ - fclose(__pyx_v_f); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":166 - * fclose(f) - * - * cdef void read_handle(self, FILE* f): # <<<<<<<<<<<<<< - * (self.arr) - * fread(&(self.len), sizeof(int), 1, f) - */ - -static void __pyx_f_8_cdec_sa_7IntList_read_handle(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, FILE *__pyx_v_f) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_handle", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":167 - * - * cdef void read_handle(self, FILE* f): - * (self.arr) # <<<<<<<<<<<<<< - * fread(&(self.len), sizeof(int), 1, f) - * self.arr = malloc(self.len * sizeof(int)) - */ - __pyx_v_self->arr; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":168 - * cdef void read_handle(self, FILE* f): - * (self.arr) - * fread(&(self.len), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * self.arr = malloc(self.len * sizeof(int)) - * self.size = self.len - */ - fread((&__pyx_v_self->len), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":169 - * (self.arr) - * fread(&(self.len), sizeof(int), 1, f) - * self.arr = malloc(self.len * sizeof(int)) # <<<<<<<<<<<<<< - * self.size = self.len - * fread(self.arr, sizeof(int), self.len, f) - */ - __pyx_v_self->arr = ((int *)malloc((__pyx_v_self->len * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":170 - * fread(&(self.len), sizeof(int), 1, f) - * self.arr = malloc(self.len * sizeof(int)) - * self.size = self.len # <<<<<<<<<<<<<< - * fread(self.arr, sizeof(int), self.len, f) - * - */ - __pyx_v_self->size = __pyx_v_self->len; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":171 - * self.arr = malloc(self.len * sizeof(int)) - * self.size = self.len - * fread(self.arr, sizeof(int), self.len, f) # <<<<<<<<<<<<<< - * - * def read(self, char* filename): - */ - fread(__pyx_v_self->arr, (sizeof(int)), __pyx_v_self->len, __pyx_v_f); - - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_31read(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_7IntList_31read(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.IntList.read", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_7IntList_30read(((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":173 - * fread(self.arr, sizeof(int), self.len, f) - * - * def read(self, char* filename): # <<<<<<<<<<<<<< - * cdef FILE* f - * f = fopen(filename, "r") - */ - -static PyObject *__pyx_pf_8_cdec_sa_7IntList_30read(struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_self, char *__pyx_v_filename) { - FILE *__pyx_v_f; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":175 - * def read(self, char* filename): - * cdef FILE* f - * f = fopen(filename, "r") # <<<<<<<<<<<<<< - * self.read_handle(f) - * fclose(f) - */ - __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":176 - * cdef FILE* f - * f = fopen(filename, "r") - * self.read_handle(f) # <<<<<<<<<<<<<< - * fclose(f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->__pyx_vtab)->read_handle(__pyx_v_self, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":177 - * f = fopen(filename, "r") - * self.read_handle(f) - * fclose(f) # <<<<<<<<<<<<<< - */ - fclose(__pyx_v_f); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_9StringMap_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_9StringMap_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} - if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; - __pyx_r = __pyx_pf_8_cdec_sa_9StringMap___cinit__(((struct __pyx_obj_8_cdec_sa_StringMap *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":13 - * cdef int index(self, char *s) - * - * def __cinit__(self): # <<<<<<<<<<<<<< - * self.vocab = stringmap_new() - * - */ - -static int __pyx_pf_8_cdec_sa_9StringMap___cinit__(struct __pyx_obj_8_cdec_sa_StringMap *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":14 - * - * def __cinit__(self): - * self.vocab = stringmap_new() # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - __pyx_v_self->vocab = stringmap_new(); - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static void __pyx_pw_8_cdec_sa_9StringMap_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_8_cdec_sa_9StringMap_3__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_8_cdec_sa_9StringMap_2__dealloc__(((struct __pyx_obj_8_cdec_sa_StringMap *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":16 - * self.vocab = stringmap_new() - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * stringmap_delete(self.vocab) - * - */ - -static void __pyx_pf_8_cdec_sa_9StringMap_2__dealloc__(struct __pyx_obj_8_cdec_sa_StringMap *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":17 - * - * def __dealloc__(self): - * stringmap_delete(self.vocab) # <<<<<<<<<<<<<< - * - * cdef char *word(self, int i): - */ - stringmap_delete(__pyx_v_self->vocab); - - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":19 - * stringmap_delete(self.vocab) - * - * cdef char *word(self, int i): # <<<<<<<<<<<<<< - * return stringmap_word(self.vocab, i) - * - */ - -static char *__pyx_f_8_cdec_sa_9StringMap_word(struct __pyx_obj_8_cdec_sa_StringMap *__pyx_v_self, int __pyx_v_i) { - char *__pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("word", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":20 - * - * cdef char *word(self, int i): - * return stringmap_word(self.vocab, i) # <<<<<<<<<<<<<< - * - * cdef int index(self, char *s): - */ - __pyx_r = stringmap_word(__pyx_v_self->vocab, __pyx_v_i); - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":22 - * return stringmap_word(self.vocab, i) - * - * cdef int index(self, char *s): # <<<<<<<<<<<<<< - * return stringmap_index(self.vocab, s) - */ - -static int __pyx_f_8_cdec_sa_9StringMap_index(struct __pyx_obj_8_cdec_sa_StringMap *__pyx_v_self, char *__pyx_v_s) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("index", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":23 - * - * cdef int index(self, char *s): - * return stringmap_index(self.vocab, s) # <<<<<<<<<<<<<< - */ - __pyx_r = stringmap_index(__pyx_v_self->vocab, __pyx_v_s); - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_9DataArray_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_9DataArray_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_from_binary = 0; - PyObject *__pyx_v_from_text = 0; - int __pyx_v_use_sent_id; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__from_binary,&__pyx_n_s__from_text,&__pyx_n_s__use_sent_id,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[3] = {0,0,0}; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":17 - * cdef bint use_sent_id - * - * def __cinit__(self, from_binary=None, from_text=None, bint use_sent_id=False): # <<<<<<<<<<<<<< - * self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} - * self.id2word = ["END_OF_FILE", "END_OF_LINE"] - */ - values[0] = ((PyObject *)Py_None); - values[1] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_binary); - if (value) { values[0] = value; kw_args--; } - } - case 1: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_text); - if (value) { values[1] = value; kw_args--; } - } - case 2: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_sent_id); - if (value) { values[2] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - if (values[2]) { - } else { - __pyx_v_use_sent_id = ((int)0); - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_from_binary = values[0]; - __pyx_v_from_text = values[1]; - if (values[2]) { - __pyx_v_use_sent_id = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_use_sent_id == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_use_sent_id = ((int)0); - } - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.DataArray.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_9DataArray___cinit__(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), __pyx_v_from_binary, __pyx_v_from_text, __pyx_v_use_sent_id); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_9DataArray___cinit__(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text, int __pyx_v_use_sent_id) { - int __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":18 - * - * def __cinit__(self, from_binary=None, from_text=None, bint use_sent_id=False): - * self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} # <<<<<<<<<<<<<< - * self.id2word = ["END_OF_FILE", "END_OF_LINE"] - * self.data = IntList(1000,1000) - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__END_OF_FILE), __pyx_int_0) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__END_OF_LINE), __pyx_int_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_GOTREF(__pyx_v_self->word2id); - __Pyx_DECREF(__pyx_v_self->word2id); - __pyx_v_self->word2id = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":19 - * def __cinit__(self, from_binary=None, from_text=None, bint use_sent_id=False): - * self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} - * self.id2word = ["END_OF_FILE", "END_OF_LINE"] # <<<<<<<<<<<<<< - * self.data = IntList(1000,1000) - * self.sent_id = IntList(1000,1000) - */ - __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_n_s__END_OF_FILE)); - PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__END_OF_FILE)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__END_OF_FILE)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__END_OF_LINE)); - PyList_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_n_s__END_OF_LINE)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__END_OF_LINE)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_GOTREF(__pyx_v_self->id2word); - __Pyx_DECREF(__pyx_v_self->id2word); - __pyx_v_self->id2word = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":20 - * self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} - * self.id2word = ["END_OF_FILE", "END_OF_LINE"] - * self.data = IntList(1000,1000) # <<<<<<<<<<<<<< - * self.sent_id = IntList(1000,1000) - * self.sent_index = IntList(1000,1000) - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->data); - __Pyx_DECREF(((PyObject *)__pyx_v_self->data)); - __pyx_v_self->data = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":21 - * self.id2word = ["END_OF_FILE", "END_OF_LINE"] - * self.data = IntList(1000,1000) - * self.sent_id = IntList(1000,1000) # <<<<<<<<<<<<<< - * self.sent_index = IntList(1000,1000) - * self.use_sent_id = use_sent_id - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_k_tuple_11), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->sent_id); - __Pyx_DECREF(((PyObject *)__pyx_v_self->sent_id)); - __pyx_v_self->sent_id = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":22 - * self.data = IntList(1000,1000) - * self.sent_id = IntList(1000,1000) - * self.sent_index = IntList(1000,1000) # <<<<<<<<<<<<<< - * self.use_sent_id = use_sent_id - * if from_binary: - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_k_tuple_12), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->sent_index); - __Pyx_DECREF(((PyObject *)__pyx_v_self->sent_index)); - __pyx_v_self->sent_index = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":23 - * self.sent_id = IntList(1000,1000) - * self.sent_index = IntList(1000,1000) - * self.use_sent_id = use_sent_id # <<<<<<<<<<<<<< - * if from_binary: - * self.read_binary(from_binary) - */ - __pyx_v_self->use_sent_id = __pyx_v_use_sent_id; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":24 - * self.sent_index = IntList(1000,1000) - * self.use_sent_id = use_sent_id - * if from_binary: # <<<<<<<<<<<<<< - * self.read_binary(from_binary) - * elif from_text: - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_binary); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":25 - * self.use_sent_id = use_sent_id - * if from_binary: - * self.read_binary(from_binary) # <<<<<<<<<<<<<< - * elif from_text: - * self.read_text(from_text) - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_binary); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_from_binary); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_binary); - __Pyx_GIVEREF(__pyx_v_from_binary); - __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L3; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":26 - * if from_binary: - * self.read_binary(from_binary) - * elif from_text: # <<<<<<<<<<<<<< - * self.read_text(from_text) - * - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_text); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":27 - * self.read_binary(from_binary) - * elif from_text: - * self.read_text(from_text) # <<<<<<<<<<<<<< - * - * def __len__(self): - */ - __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_text); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_from_text); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_text); - __Pyx_GIVEREF(__pyx_v_from_text); - __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L3; - } - __pyx_L3:; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec_sa.DataArray.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static Py_ssize_t __pyx_pw_8_cdec_sa_9DataArray_3__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_8_cdec_sa_9DataArray_3__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_2__len__(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":29 - * self.read_text(from_text) - * - * def __len__(self): # <<<<<<<<<<<<<< - * return len(self.data) - * - */ - -static Py_ssize_t __pyx_pf_8_cdec_sa_9DataArray_2__len__(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__len__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":30 - * - * def __len__(self): - * return len(self.data) # <<<<<<<<<<<<<< - * - * def getSentId(self, i): - */ - __pyx_t_1 = ((PyObject *)__pyx_v_self->data); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - goto __pyx_L0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec_sa.DataArray.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_5getSentId(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_5getSentId(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("getSentId (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_4getSentId(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_i)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":32 - * return len(self.data) - * - * def getSentId(self, i): # <<<<<<<<<<<<<< - * return self.sent_id.arr[i] - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_4getSentId(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - Py_ssize_t __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("getSentId", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":33 - * - * def getSentId(self, i): - * return self.sent_id.arr[i] # <<<<<<<<<<<<<< - * - * def getSent(self, i): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromLong((__pyx_v_self->sent_id->arr[__pyx_t_1])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __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_2); - __Pyx_AddTraceback("_cdec_sa.DataArray.getSentId", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_7getSent(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_7getSent(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("getSent (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_6getSent(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_i)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":35 - * return self.sent_id.arr[i] - * - * def getSent(self, i): # <<<<<<<<<<<<<< - * cdef int j, start, stop - * sent = [] - */ - -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_6getSent(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_i) { - int __pyx_v_start; - int __pyx_v_stop; - PyObject *__pyx_v_sent = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("getSent", 0); - __Pyx_INCREF(__pyx_v_i); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":37 - * def getSent(self, i): - * cdef int j, start, stop - * sent = [] # <<<<<<<<<<<<<< - * start = self.sent_index.arr[i] - * stop = self.sent_index.arr[i+1] - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_sent = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":38 - * cdef int j, start, stop - * sent = [] - * start = self.sent_index.arr[i] # <<<<<<<<<<<<<< - * stop = self.sent_index.arr[i+1] - * for i from start <= i < stop: - */ - __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_start = (__pyx_v_self->sent_index->arr[__pyx_t_2]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":39 - * sent = [] - * start = self.sent_index.arr[i] - * stop = self.sent_index.arr[i+1] # <<<<<<<<<<<<<< - * for i from start <= i < stop: - * sent.append(self.id2word[self.data.arr[i]]) - */ - __pyx_t_1 = PyNumber_Add(__pyx_v_i, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_stop = (__pyx_v_self->sent_index->arr[__pyx_t_2]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":40 - * start = self.sent_index.arr[i] - * stop = self.sent_index.arr[i+1] - * for i from start <= i < stop: # <<<<<<<<<<<<<< - * sent.append(self.id2word[self.data.arr[i]]) - * return sent - */ - __pyx_t_3 = __pyx_v_stop; - for (__pyx_t_4 = __pyx_v_start; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) { - __pyx_t_1 = PyInt_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":41 - * stop = self.sent_index.arr[i+1] - * for i from start <= i < stop: - * sent.append(self.id2word[self.data.arr[i]]) # <<<<<<<<<<<<<< - * return sent - * - */ - __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_self->id2word, (__pyx_v_self->data->arr[__pyx_t_2]), sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyList_Append(__pyx_v_sent, __pyx_t_1); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":40 - * start = self.sent_index.arr[i] - * stop = self.sent_index.arr[i+1] - * for i from start <= i < stop: # <<<<<<<<<<<<<< - * sent.append(self.id2word[self.data.arr[i]]) - * return sent - */ - __pyx_t_1 = PyInt_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":42 - * for i from start <= i < stop: - * sent.append(self.id2word[self.data.arr[i]]) - * return sent # <<<<<<<<<<<<<< - * - * def getSentPos(self, loc): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_sent)); - __pyx_r = ((PyObject *)__pyx_v_sent); - 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_sa.DataArray.getSent", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_sent); - __Pyx_XDECREF(__pyx_v_i); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_9getSentPos(PyObject *__pyx_v_self, PyObject *__pyx_v_loc); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_9getSentPos(PyObject *__pyx_v_self, PyObject *__pyx_v_loc) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("getSentPos (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_8getSentPos(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_loc)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":44 - * return sent - * - * def getSentPos(self, loc): # <<<<<<<<<<<<<< - * return loc - self.sent_index.arr[self.sent_id.arr[loc]] - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_8getSentPos(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_loc) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - Py_ssize_t __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("getSentPos", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":45 - * - * def getSentPos(self, loc): - * return loc - self.sent_index.arr[self.sent_id.arr[loc]] # <<<<<<<<<<<<<< - * - * def get_id(self, word): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_loc); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromLong((__pyx_v_self->sent_index->arr[(__pyx_v_self->sent_id->arr[__pyx_t_1])])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_Subtract(__pyx_v_loc, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.DataArray.getSentPos", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_11get_id(PyObject *__pyx_v_self, PyObject *__pyx_v_word); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_11get_id(PyObject *__pyx_v_self, PyObject *__pyx_v_word) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_id (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_10get_id(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_word)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":47 - * return loc - self.sent_index.arr[self.sent_id.arr[loc]] - * - * def get_id(self, word): # <<<<<<<<<<<<<< - * if not word in self.word2id: - * self.word2id[word] = len(self.id2word) - */ - -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_10get_id(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_word) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - Py_ssize_t __pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get_id", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":48 - * - * def get_id(self, word): - * if not word in self.word2id: # <<<<<<<<<<<<<< - * self.word2id[word] = len(self.id2word) - * self.id2word.append(word) - */ - __pyx_t_1 = ((PySequence_Contains(__pyx_v_self->word2id, __pyx_v_word))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = (!__pyx_t_1); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":49 - * def get_id(self, word): - * if not word in self.word2id: - * self.word2id[word] = len(self.id2word) # <<<<<<<<<<<<<< - * self.id2word.append(word) - * return self.word2id[word] - */ - __pyx_t_3 = __pyx_v_self->id2word; - __Pyx_INCREF(__pyx_t_3); - __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (PyObject_SetItem(__pyx_v_self->word2id, __pyx_v_word, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":50 - * if not word in self.word2id: - * self.word2id[word] = len(self.id2word) - * self.id2word.append(word) # <<<<<<<<<<<<<< - * return self.word2id[word] - * - */ - __pyx_t_3 = __Pyx_PyObject_Append(__pyx_v_self->id2word, __pyx_v_word); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":51 - * self.word2id[word] = len(self.id2word) - * self.id2word.append(word) - * return self.word2id[word] # <<<<<<<<<<<<<< - * - * def get_word(self, id): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyObject_GetItem(__pyx_v_self->word2id, __pyx_v_word); if (!__pyx_t_3) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.DataArray.get_id", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_13get_word(PyObject *__pyx_v_self, PyObject *__pyx_v_id); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_13get_word(PyObject *__pyx_v_self, PyObject *__pyx_v_id) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_word (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_12get_word(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_id)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":53 - * return self.word2id[word] - * - * def get_word(self, id): # <<<<<<<<<<<<<< - * return self.id2word[id] - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_12get_word(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_id) { - 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("get_word", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":54 - * - * def get_word(self, id): - * return self.id2word[id] # <<<<<<<<<<<<<< - * - * def write_text(self, char* filename): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetItem(__pyx_v_self->id2word, __pyx_v_id); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __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_AddTraceback("_cdec_sa.DataArray.get_word", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_15write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_15write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_text (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.DataArray.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_14write_text(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":56 - * return self.id2word[id] - * - * def write_text(self, char* filename): # <<<<<<<<<<<<<< - * with open(filename, "w") as f: - * for w_id in self.data: - */ - -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_14write_text(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { - PyObject *__pyx_v_f = NULL; - PyObject *__pyx_v_w_id = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - Py_ssize_t __pyx_t_8; - PyObject *(*__pyx_t_9)(PyObject *); - int __pyx_t_10; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; - PyObject *__pyx_t_13 = NULL; - int __pyx_t_14; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("write_text", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":57 - * - * def write_text(self, char* filename): - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * for w_id in self.data: - * if w_id > 1: - */ - /*with:*/ { - __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /*try:*/ { - { - __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - /*try:*/ { - __Pyx_INCREF(__pyx_t_4); - __pyx_v_f = __pyx_t_4; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":58 - * def write_text(self, char* filename): - * with open(filename, "w") as f: - * for w_id in self.data: # <<<<<<<<<<<<<< - * if w_id > 1: - * f.write("%s " % self.get_word(w_id)) - */ - if (PyList_CheckExact(((PyObject *)__pyx_v_self->data)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->data))) { - __pyx_t_4 = ((PyObject *)__pyx_v_self->data); __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(((PyObject *)__pyx_v_self->data)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; - } else { - __pyx_t_1 = __pyx_t_9(__pyx_t_4); - if (unlikely(!__pyx_t_1)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XDECREF(__pyx_v_w_id); - __pyx_v_w_id = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":59 - * with open(filename, "w") as f: - * for w_id in self.data: - * if w_id > 1: # <<<<<<<<<<<<<< - * f.write("%s " % self.get_word(w_id)) - * if w_id == 1: - */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_w_id, __pyx_int_1, Py_GT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_10) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":60 - * for w_id in self.data: - * if w_id > 1: - * f.write("%s " % self.get_word(w_id)) # <<<<<<<<<<<<<< - * if w_id == 1: - * f.write("\n") - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_word); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_INCREF(__pyx_v_w_id); - PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_w_id); - __Pyx_GIVEREF(__pyx_v_w_id); - __pyx_t_12 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; - __pyx_t_11 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_13), __pyx_t_12); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_11)); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)__pyx_t_11)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_11)); - __pyx_t_11 = 0; - __pyx_t_11 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - goto __pyx_L18; - } - __pyx_L18:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":61 - * if w_id > 1: - * f.write("%s " % self.get_word(w_id)) - * if w_id == 1: # <<<<<<<<<<<<<< - * f.write("\n") - * - */ - __pyx_t_11 = PyObject_RichCompare(__pyx_v_w_id, __pyx_int_1, Py_EQ); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (__pyx_t_10) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":62 - * f.write("%s " % self.get_word(w_id)) - * if w_id == 1: - * f.write("\n") # <<<<<<<<<<<<<< - * - * def read_text(self, char* filename): - */ - __pyx_t_11 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_12 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_k_tuple_15), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - goto __pyx_L19; - } - __pyx_L19:; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L14_try_end; - __pyx_L7_error:; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":57 - * - * def write_text(self, char* filename): - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * for w_id in self.data: - * if w_id > 1: - */ - /*except:*/ { - __Pyx_AddTraceback("_cdec_sa.DataArray.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_12, &__pyx_t_11) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GOTREF(__pyx_t_12); - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_12); - __Pyx_GIVEREF(__pyx_t_12); - __Pyx_INCREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_11); - __Pyx_GIVEREF(__pyx_t_11); - __pyx_t_13 = PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_13); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __pyx_t_14 = (!__pyx_t_10); - if (__pyx_t_14) { - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_12); - __Pyx_GIVEREF(__pyx_t_11); - __Pyx_ErrRestore(__pyx_t_4, __pyx_t_12, __pyx_t_11); - __pyx_t_4 = 0; __pyx_t_12 = 0; __pyx_t_11 = 0; - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - goto __pyx_L22; - } - __pyx_L22:; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - goto __pyx_L8_exception_handled; - } - __pyx_L9_except_error:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - goto __pyx_L1_error; - __pyx_L8_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - __pyx_L14_try_end:; - } - } - /*finally:*/ { - if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_16, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - goto __pyx_L23; - __pyx_L3_error:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L1_error; - __pyx_L23:; - } - - __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_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_AddTraceback("_cdec_sa.DataArray.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_f); - __Pyx_XDECREF(__pyx_v_w_id); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_17read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_17read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_text (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.DataArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_16read_text(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":64 - * f.write("\n") - * - * def read_text(self, char* filename): # <<<<<<<<<<<<<< - * cdef int word_count = 0 - * with gzip_or_text(filename) as fp: - */ - -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_16read_text(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { - int __pyx_v_word_count; - PyObject *__pyx_v_fp = NULL; - PyObject *__pyx_v_line_num = NULL; - PyObject *__pyx_v_line = NULL; - PyObject *__pyx_v_word = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - Py_ssize_t __pyx_t_8; - PyObject *(*__pyx_t_9)(PyObject *); - PyObject *__pyx_t_10 = NULL; - Py_ssize_t __pyx_t_11; - PyObject *(*__pyx_t_12)(PyObject *); - PyObject *__pyx_t_13 = NULL; - PyObject *__pyx_t_14 = NULL; - int __pyx_t_15; - PyObject *__pyx_t_16 = NULL; - int __pyx_t_17; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("read_text", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":65 - * - * def read_text(self, char* filename): - * cdef int word_count = 0 # <<<<<<<<<<<<<< - * with gzip_or_text(filename) as fp: - * for line_num, line in enumerate(fp): - */ - __pyx_v_word_count = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":66 - * def read_text(self, char* filename): - * cdef int word_count = 0 - * with gzip_or_text(filename) as fp: # <<<<<<<<<<<<<< - * for line_num, line in enumerate(fp): - * self.sent_index.append(word_count) - */ - /*with:*/ { - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__gzip_or_text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __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[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__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_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /*try:*/ { - { - __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - /*try:*/ { - __Pyx_INCREF(__pyx_t_1); - __pyx_v_fp = __pyx_t_1; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":67 - * cdef int word_count = 0 - * with gzip_or_text(filename) as fp: - * for line_num, line in enumerate(fp): # <<<<<<<<<<<<<< - * self.sent_index.append(word_count) - * for word in line.split(): - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_t_1 = __pyx_int_0; - if (PyList_CheckExact(__pyx_v_fp) || PyTuple_CheckExact(__pyx_v_fp)) { - __pyx_t_2 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_9 = Py_TYPE(__pyx_t_2)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_2)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break; - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_3); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_2)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_3); __pyx_t_8++; - } else { - __pyx_t_3 = __pyx_t_9(__pyx_t_2); - if (unlikely(!__pyx_t_3)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF(__pyx_v_line); - __pyx_v_line = __pyx_t_3; - __pyx_t_3 = 0; - __Pyx_INCREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_v_line_num); - __pyx_v_line_num = __pyx_t_1; - __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); - __pyx_t_1 = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":68 - * with gzip_or_text(filename) as fp: - * for line_num, line in enumerate(fp): - * self.sent_index.append(word_count) # <<<<<<<<<<<<<< - * for word in line.split(): - * self.data.append(self.get_id(word)) - */ - __pyx_t_3 = PyInt_FromLong(__pyx_v_word_count); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_index), __pyx_t_3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":69 - * for line_num, line in enumerate(fp): - * self.sent_index.append(word_count) - * for word in line.split(): # <<<<<<<<<<<<<< - * self.data.append(self.get_id(word)) - * if self.use_sent_id: - */ - __pyx_t_10 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_3 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_10 = __pyx_t_3; __Pyx_INCREF(__pyx_t_10); __pyx_t_11 = 0; - __pyx_t_12 = NULL; - } else { - __pyx_t_11 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_12 = Py_TYPE(__pyx_t_10)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (!__pyx_t_12 && PyList_CheckExact(__pyx_t_10)) { - if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_10)) break; - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_11); __Pyx_INCREF(__pyx_t_3); __pyx_t_11++; - } else if (!__pyx_t_12 && PyTuple_CheckExact(__pyx_t_10)) { - if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_10)) break; - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_11); __Pyx_INCREF(__pyx_t_3); __pyx_t_11++; - } else { - __pyx_t_3 = __pyx_t_12(__pyx_t_10); - if (unlikely(!__pyx_t_3)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF(__pyx_v_word); - __pyx_v_word = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":70 - * self.sent_index.append(word_count) - * for word in line.split(): - * self.data.append(self.get_id(word)) # <<<<<<<<<<<<<< - * if self.use_sent_id: - * self.sent_id.append(line_num) - */ - __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_id); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_INCREF(__pyx_v_word); - PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_v_word); - __Pyx_GIVEREF(__pyx_v_word); - __pyx_t_14 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; - __pyx_t_13 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->data), __pyx_t_14); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":71 - * for word in line.split(): - * self.data.append(self.get_id(word)) - * if self.use_sent_id: # <<<<<<<<<<<<<< - * self.sent_id.append(line_num) - * word_count = word_count + 1 - */ - if (__pyx_v_self->use_sent_id) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":72 - * self.data.append(self.get_id(word)) - * if self.use_sent_id: - * self.sent_id.append(line_num) # <<<<<<<<<<<<<< - * word_count = word_count + 1 - * self.data.append(1) - */ - __pyx_t_13 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_id), __pyx_v_line_num); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - goto __pyx_L20; - } - __pyx_L20:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":73 - * if self.use_sent_id: - * self.sent_id.append(line_num) - * word_count = word_count + 1 # <<<<<<<<<<<<<< - * self.data.append(1) - * if self.use_sent_id: - */ - __pyx_v_word_count = (__pyx_v_word_count + 1); - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":74 - * self.sent_id.append(line_num) - * word_count = word_count + 1 - * self.data.append(1) # <<<<<<<<<<<<<< - * if self.use_sent_id: - * self.sent_id.append(line_num) - */ - __pyx_t_10 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->data), __pyx_int_1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":75 - * word_count = word_count + 1 - * self.data.append(1) - * if self.use_sent_id: # <<<<<<<<<<<<<< - * self.sent_id.append(line_num) - * word_count = word_count + 1 - */ - if (__pyx_v_self->use_sent_id) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":76 - * self.data.append(1) - * if self.use_sent_id: - * self.sent_id.append(line_num) # <<<<<<<<<<<<<< - * word_count = word_count + 1 - * self.data.append(0) - */ - __pyx_t_10 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_id), __pyx_v_line_num); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - goto __pyx_L21; - } - __pyx_L21:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":77 - * if self.use_sent_id: - * self.sent_id.append(line_num) - * word_count = word_count + 1 # <<<<<<<<<<<<<< - * self.data.append(0) - * self.sent_index.append(word_count) - */ - __pyx_v_word_count = (__pyx_v_word_count + 1); - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":78 - * self.sent_id.append(line_num) - * word_count = word_count + 1 - * self.data.append(0) # <<<<<<<<<<<<<< - * self.sent_index.append(word_count) - * - */ - __pyx_t_1 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->data), __pyx_int_0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":79 - * word_count = word_count + 1 - * self.data.append(0) - * self.sent_index.append(word_count) # <<<<<<<<<<<<<< - * - * def read_binary(self, char* filename): - */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_word_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_index), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L14_try_end; - __pyx_L7_error:; - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":66 - * def read_text(self, char* filename): - * cdef int word_count = 0 - * with gzip_or_text(filename) as fp: # <<<<<<<<<<<<<< - * for line_num, line in enumerate(fp): - * self.sent_index.append(word_count) - */ - /*except:*/ { - __Pyx_AddTraceback("_cdec_sa.DataArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_1, &__pyx_t_10) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_13 = PyTuple_New(3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_INCREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_t_16 = PyObject_Call(__pyx_t_4, __pyx_t_13, NULL); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_16); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - if (unlikely(__pyx_t_15 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __pyx_t_17 = (!__pyx_t_15); - if (__pyx_t_17) { - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_10); - __Pyx_ErrRestore(__pyx_t_2, __pyx_t_1, __pyx_t_10); - __pyx_t_2 = 0; __pyx_t_1 = 0; __pyx_t_10 = 0; - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - goto __pyx_L24; - } - __pyx_L24:; - __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - goto __pyx_L8_exception_handled; - } - __pyx_L9_except_error:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - goto __pyx_L1_error; - __pyx_L8_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - __pyx_L14_try_end:; - } - } - /*finally:*/ { - if (__pyx_t_4) { - __pyx_t_7 = PyObject_Call(__pyx_t_4, __pyx_k_tuple_17, NULL); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_17 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - goto __pyx_L25; - __pyx_L3_error:; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L1_error; - __pyx_L25:; - } - - __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_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_13); - __Pyx_XDECREF(__pyx_t_14); - __Pyx_AddTraceback("_cdec_sa.DataArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_fp); - __Pyx_XDECREF(__pyx_v_line_num); - __Pyx_XDECREF(__pyx_v_line); - __Pyx_XDECREF(__pyx_v_word); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_19read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_19read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_binary (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.DataArray.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_18read_binary(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":81 - * self.sent_index.append(word_count) - * - * def read_binary(self, char* filename): # <<<<<<<<<<<<<< - * cdef FILE* f - * f = fopen(filename, "r") - */ - -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_18read_binary(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { - FILE *__pyx_v_f; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_binary", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":83 - * def read_binary(self, char* filename): - * cdef FILE* f - * f = fopen(filename, "r") # <<<<<<<<<<<<<< - * self.read_handle(f) - * fclose(f) - */ - __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":84 - * cdef FILE* f - * f = fopen(filename, "r") - * self.read_handle(f) # <<<<<<<<<<<<<< - * fclose(f) - * - */ - ((struct __pyx_vtabstruct_8_cdec_sa_DataArray *)__pyx_v_self->__pyx_vtab)->read_handle(__pyx_v_self, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":85 - * f = fopen(filename, "r") - * self.read_handle(f) - * fclose(f) # <<<<<<<<<<<<<< - * - * cdef void read_handle(self, FILE* f): - */ - fclose(__pyx_v_f); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":87 - * fclose(f) - * - * cdef void read_handle(self, FILE* f): # <<<<<<<<<<<<<< - * cdef int num_words, word_len - * cdef unsigned i - */ - -static void __pyx_f_8_cdec_sa_9DataArray_read_handle(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, FILE *__pyx_v_f) { - int __pyx_v_num_words; - int __pyx_v_word_len; - CYTHON_UNUSED unsigned int __pyx_v_i; - char *__pyx_v_c_word; - PyObject *__pyx_v_py_word = 0; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - unsigned int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - Py_ssize_t __pyx_t_4; - int __pyx_t_5; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("read_handle", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":92 - * cdef char* c_word - * cdef bytes py_word - * self.data.read_handle(f) # <<<<<<<<<<<<<< - * self.sent_index.read_handle(f) - * self.sent_id.read_handle(f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->data->__pyx_vtab)->read_handle(__pyx_v_self->data, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":93 - * cdef bytes py_word - * self.data.read_handle(f) - * self.sent_index.read_handle(f) # <<<<<<<<<<<<<< - * self.sent_id.read_handle(f) - * fread(&(num_words), sizeof(int), 1, f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->sent_index->__pyx_vtab)->read_handle(__pyx_v_self->sent_index, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":94 - * self.data.read_handle(f) - * self.sent_index.read_handle(f) - * self.sent_id.read_handle(f) # <<<<<<<<<<<<<< - * fread(&(num_words), sizeof(int), 1, f) - * for i in range(num_words): - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->sent_id->__pyx_vtab)->read_handle(__pyx_v_self->sent_id, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":95 - * self.sent_index.read_handle(f) - * self.sent_id.read_handle(f) - * fread(&(num_words), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * for i in range(num_words): - * fread(&(word_len), sizeof(int), 1, f) - */ - fread((&__pyx_v_num_words), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":96 - * self.sent_id.read_handle(f) - * fread(&(num_words), sizeof(int), 1, f) - * for i in range(num_words): # <<<<<<<<<<<<<< - * fread(&(word_len), sizeof(int), 1, f) - * c_word = malloc (word_len * sizeof(char)) - */ - __pyx_t_1 = __pyx_v_num_words; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":97 - * fread(&(num_words), sizeof(int), 1, f) - * for i in range(num_words): - * fread(&(word_len), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * c_word = malloc (word_len * sizeof(char)) - * fread(c_word, sizeof(char), word_len, f) - */ - fread((&__pyx_v_word_len), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":98 - * for i in range(num_words): - * fread(&(word_len), sizeof(int), 1, f) - * c_word = malloc (word_len * sizeof(char)) # <<<<<<<<<<<<<< - * fread(c_word, sizeof(char), word_len, f) - * py_word = c_word - */ - __pyx_v_c_word = ((char *)malloc((__pyx_v_word_len * (sizeof(char))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":99 - * fread(&(word_len), sizeof(int), 1, f) - * c_word = malloc (word_len * sizeof(char)) - * fread(c_word, sizeof(char), word_len, f) # <<<<<<<<<<<<<< - * py_word = c_word - * free(c_word) - */ - fread(__pyx_v_c_word, (sizeof(char)), __pyx_v_word_len, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":100 - * c_word = malloc (word_len * sizeof(char)) - * fread(c_word, sizeof(char), word_len, f) - * py_word = c_word # <<<<<<<<<<<<<< - * free(c_word) - * self.word2id[py_word] = len(self.id2word) - */ - __pyx_t_3 = PyBytes_FromString(__pyx_v_c_word); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __Pyx_XDECREF(((PyObject *)__pyx_v_py_word)); - __pyx_v_py_word = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":101 - * fread(c_word, sizeof(char), word_len, f) - * py_word = c_word - * free(c_word) # <<<<<<<<<<<<<< - * self.word2id[py_word] = len(self.id2word) - * self.id2word.append(py_word) - */ - free(__pyx_v_c_word); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":102 - * py_word = c_word - * free(c_word) - * self.word2id[py_word] = len(self.id2word) # <<<<<<<<<<<<<< - * self.id2word.append(py_word) - * if len(self.sent_id) == 0: - */ - __pyx_t_3 = __pyx_v_self->id2word; - __Pyx_INCREF(__pyx_t_3); - __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (PyObject_SetItem(__pyx_v_self->word2id, ((PyObject *)__pyx_v_py_word), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":103 - * free(c_word) - * self.word2id[py_word] = len(self.id2word) - * self.id2word.append(py_word) # <<<<<<<<<<<<<< - * if len(self.sent_id) == 0: - * self.use_sent_id = False - */ - __pyx_t_3 = __Pyx_PyObject_Append(__pyx_v_self->id2word, ((PyObject *)__pyx_v_py_word)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":104 - * self.word2id[py_word] = len(self.id2word) - * self.id2word.append(py_word) - * if len(self.sent_id) == 0: # <<<<<<<<<<<<<< - * self.use_sent_id = False - * else: - */ - __pyx_t_3 = ((PyObject *)__pyx_v_self->sent_id); - __Pyx_INCREF(__pyx_t_3); - __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_5 = (__pyx_t_4 == 0); - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":105 - * self.id2word.append(py_word) - * if len(self.sent_id) == 0: - * self.use_sent_id = False # <<<<<<<<<<<<<< - * else: - * self.use_sent_id = True - */ - __pyx_v_self->use_sent_id = 0; - goto __pyx_L5; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":107 - * self.use_sent_id = False - * else: - * self.use_sent_id = True # <<<<<<<<<<<<<< - * - * cdef void write_handle(self, FILE* f): - */ - __pyx_v_self->use_sent_id = 1; - } - __pyx_L5:; - - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_WriteUnraisable("_cdec_sa.DataArray.read_handle", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_py_word); - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":109 - * self.use_sent_id = True - * - * cdef void write_handle(self, FILE* f): # <<<<<<<<<<<<<< - * cdef int word_len - * cdef int num_words - */ - -static void __pyx_f_8_cdec_sa_9DataArray_write_handle(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, FILE *__pyx_v_f) { - int __pyx_v_word_len; - int __pyx_v_num_words; - char *__pyx_v_c_word; - PyObject *__pyx_v_word = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *(*__pyx_t_4)(PyObject *); - char *__pyx_t_5; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("write_handle", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":113 - * cdef int num_words - * cdef char* c_word - * self.data.write_handle(f) # <<<<<<<<<<<<<< - * self.sent_index.write_handle(f) - * self.sent_id.write_handle(f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->data->__pyx_vtab)->write_handle(__pyx_v_self->data, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":114 - * cdef char* c_word - * self.data.write_handle(f) - * self.sent_index.write_handle(f) # <<<<<<<<<<<<<< - * self.sent_id.write_handle(f) - * num_words = len(self.id2word) - 2 - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->sent_index->__pyx_vtab)->write_handle(__pyx_v_self->sent_index, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":115 - * self.data.write_handle(f) - * self.sent_index.write_handle(f) - * self.sent_id.write_handle(f) # <<<<<<<<<<<<<< - * num_words = len(self.id2word) - 2 - * fwrite(&(num_words), sizeof(int), 1, f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->sent_id->__pyx_vtab)->write_handle(__pyx_v_self->sent_id, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":116 - * self.sent_index.write_handle(f) - * self.sent_id.write_handle(f) - * num_words = len(self.id2word) - 2 # <<<<<<<<<<<<<< - * fwrite(&(num_words), sizeof(int), 1, f) - * for word in self.id2word[2:]: - */ - __pyx_t_1 = __pyx_v_self->id2word; - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_num_words = (__pyx_t_2 - 2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":117 - * self.sent_id.write_handle(f) - * num_words = len(self.id2word) - 2 - * fwrite(&(num_words), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * for word in self.id2word[2:]: - * c_word = word - */ - fwrite((&__pyx_v_num_words), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":118 - * num_words = len(self.id2word) - 2 - * fwrite(&(num_words), sizeof(int), 1, f) - * for word in self.id2word[2:]: # <<<<<<<<<<<<<< - * c_word = word - * word_len = strlen(c_word) + 1 - */ - __pyx_t_1 = __Pyx_PySequence_GetSlice(__pyx_v_self->id2word, 2, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { - __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_3)) break; - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; - } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; - } else { - __pyx_t_1 = __pyx_t_4(__pyx_t_3); - if (unlikely(!__pyx_t_1)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XDECREF(__pyx_v_word); - __pyx_v_word = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":119 - * fwrite(&(num_words), sizeof(int), 1, f) - * for word in self.id2word[2:]: - * c_word = word # <<<<<<<<<<<<<< - * word_len = strlen(c_word) + 1 - * fwrite(&(word_len), sizeof(int), 1, f) - */ - __pyx_t_5 = PyBytes_AsString(__pyx_v_word); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_c_word = __pyx_t_5; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":120 - * for word in self.id2word[2:]: - * c_word = word - * word_len = strlen(c_word) + 1 # <<<<<<<<<<<<<< - * fwrite(&(word_len), sizeof(int), 1, f) - * fwrite(c_word, sizeof(char), word_len, f) - */ - __pyx_v_word_len = (strlen(__pyx_v_c_word) + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":121 - * c_word = word - * word_len = strlen(c_word) + 1 - * fwrite(&(word_len), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * fwrite(c_word, sizeof(char), word_len, f) - * - */ - fwrite((&__pyx_v_word_len), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":122 - * word_len = strlen(c_word) + 1 - * fwrite(&(word_len), sizeof(int), 1, f) - * fwrite(c_word, sizeof(char), word_len, f) # <<<<<<<<<<<<<< - * - * def write_binary(self, char* filename): - */ - fwrite(__pyx_v_c_word, (sizeof(char)), __pyx_v_word_len, __pyx_v_f); - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_WriteUnraisable("_cdec_sa.DataArray.write_handle", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_word); - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_21write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_21write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_binary (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.DataArray.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_20write_binary(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":124 - * fwrite(c_word, sizeof(char), word_len, f) - * - * def write_binary(self, char* filename): # <<<<<<<<<<<<<< - * cdef FILE* f - * f = fopen(filename, "w") - */ - -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_20write_binary(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { - FILE *__pyx_v_f; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_binary", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":126 - * def write_binary(self, char* filename): - * cdef FILE* f - * f = fopen(filename, "w") # <<<<<<<<<<<<<< - * self.write_handle(f) - * fclose(f) - */ - __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":127 - * cdef FILE* f - * f = fopen(filename, "w") - * self.write_handle(f) # <<<<<<<<<<<<<< - * fclose(f) - * - */ - ((struct __pyx_vtabstruct_8_cdec_sa_DataArray *)__pyx_v_self->__pyx_vtab)->write_handle(__pyx_v_self, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":128 - * f = fopen(filename, "w") - * self.write_handle(f) - * fclose(f) # <<<<<<<<<<<<<< - * - * def write_enhanced_handle(self, f): - */ - fclose(__pyx_v_f); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_23write_enhanced_handle(PyObject *__pyx_v_self, PyObject *__pyx_v_f); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_23write_enhanced_handle(PyObject *__pyx_v_self, PyObject *__pyx_v_f) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_enhanced_handle (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_22write_enhanced_handle(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_f)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":130 - * fclose(f) - * - * def write_enhanced_handle(self, f): # <<<<<<<<<<<<<< - * for i in self.data: - * f.write("%d " %i) - */ - -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_22write_enhanced_handle(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_f) { - PyObject *__pyx_v_i = NULL; - PyObject *__pyx_v_word = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *(*__pyx_t_3)(PyObject *); - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("write_enhanced_handle", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":131 - * - * def write_enhanced_handle(self, f): - * for i in self.data: # <<<<<<<<<<<<<< - * f.write("%d " %i) - * f.write("\n") - */ - if (PyList_CheckExact(((PyObject *)__pyx_v_self->data)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->data))) { - __pyx_t_1 = ((PyObject *)__pyx_v_self->data); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; - __pyx_t_3 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self->data)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; - } - for (;;) { - if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; - } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; - } else { - __pyx_t_4 = __pyx_t_3(__pyx_t_1); - if (unlikely(!__pyx_t_4)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XDECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":132 - * def write_enhanced_handle(self, f): - * for i in self.data: - * f.write("%d " %i) # <<<<<<<<<<<<<< - * f.write("\n") - * for i in self.sent_index: - */ - __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); - __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":133 - * for i in self.data: - * f.write("%d " %i) - * f.write("\n") # <<<<<<<<<<<<<< - * for i in self.sent_index: - * f.write("%d " %i) - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_19), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":134 - * f.write("%d " %i) - * f.write("\n") - * for i in self.sent_index: # <<<<<<<<<<<<<< - * f.write("%d " %i) - * f.write("\n") - */ - if (PyList_CheckExact(((PyObject *)__pyx_v_self->sent_index)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->sent_index))) { - __pyx_t_5 = ((PyObject *)__pyx_v_self->sent_index); __Pyx_INCREF(__pyx_t_5); __pyx_t_2 = 0; - __pyx_t_3 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_5 = PyObject_GetIter(((PyObject *)__pyx_v_self->sent_index)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = Py_TYPE(__pyx_t_5)->tp_iternext; - } - for (;;) { - if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_5)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_5)) break; - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; - } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_5)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_5)) break; - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; - } else { - __pyx_t_1 = __pyx_t_3(__pyx_t_5); - if (unlikely(!__pyx_t_1)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XDECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":135 - * f.write("\n") - * for i in self.sent_index: - * f.write("%d " %i) # <<<<<<<<<<<<<< - * f.write("\n") - * for i in self.sent_id: - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_6)); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_6)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_6)); - __pyx_t_6 = 0; - __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":136 - * for i in self.sent_index: - * f.write("%d " %i) - * f.write("\n") # <<<<<<<<<<<<<< - * for i in self.sent_id: - * f.write("%d " %i) - */ - __pyx_t_5 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":137 - * f.write("%d " %i) - * f.write("\n") - * for i in self.sent_id: # <<<<<<<<<<<<<< - * f.write("%d " %i) - * f.write("\n") - */ - if (PyList_CheckExact(((PyObject *)__pyx_v_self->sent_id)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->sent_id))) { - __pyx_t_6 = ((PyObject *)__pyx_v_self->sent_id); __Pyx_INCREF(__pyx_t_6); __pyx_t_2 = 0; - __pyx_t_3 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_6 = PyObject_GetIter(((PyObject *)__pyx_v_self->sent_id)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_3 = Py_TYPE(__pyx_t_6)->tp_iternext; - } - for (;;) { - if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_6)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_6)) break; - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; - } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_6)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_6)) break; - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; - } else { - __pyx_t_5 = __pyx_t_3(__pyx_t_6); - if (unlikely(!__pyx_t_5)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_5); - } - __Pyx_XDECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_5; - __pyx_t_5 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":138 - * f.write("\n") - * for i in self.sent_id: - * f.write("%d " %i) # <<<<<<<<<<<<<< - * f.write("\n") - * for word in self.id2word: - */ - __pyx_t_5 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); - __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":139 - * for i in self.sent_id: - * f.write("%d " %i) - * f.write("\n") # <<<<<<<<<<<<<< - * for word in self.id2word: - * f.write("%s %d " % (word, self.word2id[word])) - */ - __pyx_t_6 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_4 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_k_tuple_21), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":140 - * f.write("%d " %i) - * f.write("\n") - * for word in self.id2word: # <<<<<<<<<<<<<< - * f.write("%s %d " % (word, self.word2id[word])) - * f.write("\n") - */ - if (PyList_CheckExact(__pyx_v_self->id2word) || PyTuple_CheckExact(__pyx_v_self->id2word)) { - __pyx_t_4 = __pyx_v_self->id2word; __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0; - __pyx_t_3 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_self->id2word); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = Py_TYPE(__pyx_t_4)->tp_iternext; - } - for (;;) { - if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_4)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_4)) break; - __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_6); __pyx_t_2++; - } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_4)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_6); __pyx_t_2++; - } else { - __pyx_t_6 = __pyx_t_3(__pyx_t_4); - if (unlikely(!__pyx_t_6)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_6); - } - __Pyx_XDECREF(__pyx_v_word); - __pyx_v_word = __pyx_t_6; - __pyx_t_6 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":141 - * f.write("\n") - * for word in self.id2word: - * f.write("%s %d " % (word, self.word2id[word])) # <<<<<<<<<<<<<< - * f.write("\n") - * - */ - __pyx_t_6 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_1 = PyObject_GetItem(__pyx_v_self->word2id, __pyx_v_word); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(__pyx_v_word); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_word); - __Pyx_GIVEREF(__pyx_v_word); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_22), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":142 - * for word in self.id2word: - * f.write("%s %d " % (word, self.word2id[word])) - * f.write("\n") # <<<<<<<<<<<<<< - * - * def write_enhanced(self, char* filename): - */ - __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_23), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("_cdec_sa.DataArray.write_enhanced_handle", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_i); - __Pyx_XDECREF(__pyx_v_word); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_25write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9DataArray_25write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_enhanced (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.DataArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_9DataArray_24write_enhanced(((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":144 - * f.write("\n") - * - * def write_enhanced(self, char* filename): # <<<<<<<<<<<<<< - * with open(filename, "w") as f: - * self.write_enhanced_handle(self, f) - */ - -static PyObject *__pyx_pf_8_cdec_sa_9DataArray_24write_enhanced(struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { - PyObject *__pyx_v_f = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - int __pyx_t_9; - PyObject *__pyx_t_10 = NULL; - int __pyx_t_11; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("write_enhanced", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":145 - * - * def write_enhanced(self, char* filename): - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * self.write_enhanced_handle(self, f) - */ - /*with:*/ { - __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /*try:*/ { - { - __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - /*try:*/ { - __Pyx_INCREF(__pyx_t_4); - __pyx_v_f = __pyx_t_4; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":146 - * def write_enhanced(self, char* filename): - * with open(filename, "w") as f: - * self.write_enhanced_handle(self, f) # <<<<<<<<<<<<<< - */ - __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s_24); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - __Pyx_INCREF(__pyx_v_f); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_f); - __Pyx_GIVEREF(__pyx_v_f); - __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L14_try_end; - __pyx_L7_error:; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":145 - * - * def write_enhanced(self, char* filename): - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * self.write_enhanced_handle(self, f) - */ - /*except:*/ { - __Pyx_AddTraceback("_cdec_sa.DataArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_1, &__pyx_t_4) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_10 = PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_10); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __pyx_t_11 = (!__pyx_t_9); - if (__pyx_t_11) { - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_ErrRestore(__pyx_t_2, __pyx_t_1, __pyx_t_4); - __pyx_t_2 = 0; __pyx_t_1 = 0; __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - goto __pyx_L18; - } - __pyx_L18:; - __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L8_exception_handled; - } - __pyx_L9_except_error:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - goto __pyx_L1_error; - __pyx_L8_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - __pyx_L14_try_end:; - } - } - /*finally:*/ { - if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_25, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - goto __pyx_L19; - __pyx_L3_error:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L1_error; - __pyx_L19:; - } - - __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_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("_cdec_sa.DataArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_f); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":12 - * cdef IntList sent_index - * - * cdef int link(self, int i, int j): # <<<<<<<<<<<<<< - * """Integerizes an alignment link pair""" - * return i*65536 + j - */ - -static int __pyx_f_8_cdec_sa_9Alignment_link(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, int __pyx_v_i, int __pyx_v_j) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("link", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":14 - * cdef int link(self, int i, int j): - * """Integerizes an alignment link pair""" - * return i*65536 + j # <<<<<<<<<<<<<< - * - * def unlink(self, link): - */ - __pyx_r = ((__pyx_v_i * 65536) + __pyx_v_j); - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9Alignment_1unlink(PyObject *__pyx_v_self, PyObject *__pyx_v_link); /*proto*/ -static char __pyx_doc_8_cdec_sa_9Alignment_unlink[] = "De-integerizes an alignment link pair"; -static PyObject *__pyx_pw_8_cdec_sa_9Alignment_1unlink(PyObject *__pyx_v_self, PyObject *__pyx_v_link) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("unlink (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9Alignment_unlink(((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_v_self), ((PyObject *)__pyx_v_link)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":16 - * return i*65536 + j - * - * def unlink(self, link): # <<<<<<<<<<<<<< - * """De-integerizes an alignment link pair""" - * return (link/65536, link%65536) - */ - -static PyObject *__pyx_pf_8_cdec_sa_9Alignment_unlink(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_link) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("unlink", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":18 - * def unlink(self, link): - * """De-integerizes an alignment link pair""" - * return (link/65536, link%65536) # <<<<<<<<<<<<<< - * - * cdef _unlink(self, int link, int* f, int* e): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_v_link, __pyx_int_65536); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyNumber_Remainder(__pyx_v_link, __pyx_int_65536); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_r = ((PyObject *)__pyx_t_3); - __pyx_t_3 = 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_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.Alignment.unlink", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":20 - * return (link/65536, link%65536) - * - * cdef _unlink(self, int link, int* f, int* e): # <<<<<<<<<<<<<< - * f[0] = link/65536 - * e[0] = link%65536 - */ - -static PyObject *__pyx_f_8_cdec_sa_9Alignment__unlink(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, int __pyx_v_link, int *__pyx_v_f, int *__pyx_v_e) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_unlink", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":21 - * - * cdef _unlink(self, int link, int* f, int* e): - * f[0] = link/65536 # <<<<<<<<<<<<<< - * e[0] = link%65536 - * - */ - (__pyx_v_f[0]) = __Pyx_div_long(__pyx_v_link, 65536); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":22 - * cdef _unlink(self, int link, int* f, int* e): - * f[0] = link/65536 - * e[0] = link%65536 # <<<<<<<<<<<<<< - * - * def get_sent_links(self, int sent_id): - */ - (__pyx_v_e[0]) = __Pyx_mod_long(__pyx_v_link, 65536); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9Alignment_3get_sent_links(PyObject *__pyx_v_self, PyObject *__pyx_arg_sent_id); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9Alignment_3get_sent_links(PyObject *__pyx_v_self, PyObject *__pyx_arg_sent_id) { - int __pyx_v_sent_id; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_sent_links (wrapper)", 0); - assert(__pyx_arg_sent_id); { - __pyx_v_sent_id = __Pyx_PyInt_AsInt(__pyx_arg_sent_id); if (unlikely((__pyx_v_sent_id == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.Alignment.get_sent_links", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_9Alignment_2get_sent_links(((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_v_self), ((int)__pyx_v_sent_id)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":24 - * e[0] = link%65536 - * - * def get_sent_links(self, int sent_id): # <<<<<<<<<<<<<< - * cdef IntList sent_links - * cdef int* arr - */ - -static PyObject *__pyx_pf_8_cdec_sa_9Alignment_2get_sent_links(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, int __pyx_v_sent_id) { - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_sent_links = 0; - int *__pyx_v_arr; - int __pyx_v_arr_len; - 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("get_sent_links", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":28 - * cdef int* arr - * cdef int arr_len - * sent_links = IntList() # <<<<<<<<<<<<<< - * arr = self._get_sent_links(sent_id, &arr_len) - * sent_links._extend_arr(arr, arr_len*2) - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_sent_links = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":29 - * cdef int arr_len - * sent_links = IntList() - * arr = self._get_sent_links(sent_id, &arr_len) # <<<<<<<<<<<<<< - * sent_links._extend_arr(arr, arr_len*2) - * free(arr) - */ - __pyx_v_arr = ((struct __pyx_vtabstruct_8_cdec_sa_Alignment *)__pyx_v_self->__pyx_vtab)->_get_sent_links(__pyx_v_self, __pyx_v_sent_id, (&__pyx_v_arr_len)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":30 - * sent_links = IntList() - * arr = self._get_sent_links(sent_id, &arr_len) - * sent_links._extend_arr(arr, arr_len*2) # <<<<<<<<<<<<<< - * free(arr) - * return sent_links - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_sent_links->__pyx_vtab)->_extend_arr(__pyx_v_sent_links, __pyx_v_arr, (__pyx_v_arr_len * 2)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":31 - * arr = self._get_sent_links(sent_id, &arr_len) - * sent_links._extend_arr(arr, arr_len*2) - * free(arr) # <<<<<<<<<<<<<< - * return sent_links - * - */ - free(__pyx_v_arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":32 - * sent_links._extend_arr(arr, arr_len*2) - * free(arr) - * return sent_links # <<<<<<<<<<<<<< - * - * cdef int* _get_sent_links(self, int sent_id, int* num_links): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_sent_links)); - __pyx_r = ((PyObject *)__pyx_v_sent_links); - 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_sa.Alignment.get_sent_links", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_sent_links); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":34 - * return sent_links - * - * cdef int* _get_sent_links(self, int sent_id, int* num_links): # <<<<<<<<<<<<<< - * cdef int* sent_links - * cdef int i, start, end - */ - -static int *__pyx_f_8_cdec_sa_9Alignment__get_sent_links(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, int __pyx_v_sent_id, int *__pyx_v_num_links) { - int *__pyx_v_sent_links; - int __pyx_v_i; - int __pyx_v_start; - int __pyx_v_end; - int *__pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_get_sent_links", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":37 - * cdef int* sent_links - * cdef int i, start, end - * start = self.sent_index.arr[sent_id] # <<<<<<<<<<<<<< - * end = self.sent_index.arr[sent_id+1] - * num_links[0] = end - start - */ - __pyx_v_start = (__pyx_v_self->sent_index->arr[__pyx_v_sent_id]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":38 - * cdef int i, start, end - * start = self.sent_index.arr[sent_id] - * end = self.sent_index.arr[sent_id+1] # <<<<<<<<<<<<<< - * num_links[0] = end - start - * sent_links = malloc(2*num_links[0]*sizeof(int)) - */ - __pyx_v_end = (__pyx_v_self->sent_index->arr[(__pyx_v_sent_id + 1)]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":39 - * start = self.sent_index.arr[sent_id] - * end = self.sent_index.arr[sent_id+1] - * num_links[0] = end - start # <<<<<<<<<<<<<< - * sent_links = malloc(2*num_links[0]*sizeof(int)) - * for i from 0 <= i < num_links[0]: - */ - (__pyx_v_num_links[0]) = (__pyx_v_end - __pyx_v_start); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":40 - * end = self.sent_index.arr[sent_id+1] - * num_links[0] = end - start - * sent_links = malloc(2*num_links[0]*sizeof(int)) # <<<<<<<<<<<<<< - * for i from 0 <= i < num_links[0]: - * self._unlink(self.links.arr[start + i], sent_links + (2*i), sent_links + (2*i) + 1) - */ - __pyx_v_sent_links = ((int *)malloc(((2 * (__pyx_v_num_links[0])) * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":41 - * num_links[0] = end - start - * sent_links = malloc(2*num_links[0]*sizeof(int)) - * for i from 0 <= i < num_links[0]: # <<<<<<<<<<<<<< - * self._unlink(self.links.arr[start + i], sent_links + (2*i), sent_links + (2*i) + 1) - * return sent_links - */ - __pyx_t_1 = (__pyx_v_num_links[0]); - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":42 - * sent_links = malloc(2*num_links[0]*sizeof(int)) - * for i from 0 <= i < num_links[0]: - * self._unlink(self.links.arr[start + i], sent_links + (2*i), sent_links + (2*i) + 1) # <<<<<<<<<<<<<< - * return sent_links - * - */ - __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_Alignment *)__pyx_v_self->__pyx_vtab)->_unlink(__pyx_v_self, (__pyx_v_self->links->arr[(__pyx_v_start + __pyx_v_i)]), (__pyx_v_sent_links + (2 * __pyx_v_i)), ((__pyx_v_sent_links + (2 * __pyx_v_i)) + 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":43 - * for i from 0 <= i < num_links[0]: - * self._unlink(self.links.arr[start + i], sent_links + (2*i), sent_links + (2*i) + 1) - * return sent_links # <<<<<<<<<<<<<< - * - * def __cinit__(self, from_binary=None, from_text=None): - */ - __pyx_r = __pyx_v_sent_links; - goto __pyx_L0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_WriteUnraisable("_cdec_sa.Alignment._get_sent_links", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_9Alignment_5__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_9Alignment_5__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_from_binary = 0; - PyObject *__pyx_v_from_text = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__from_binary,&__pyx_n_s__from_text,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[2] = {0,0}; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":45 - * return sent_links - * - * def __cinit__(self, from_binary=None, from_text=None): # <<<<<<<<<<<<<< - * self.links = IntList(1000,1000) - * self.sent_index = IntList(1000,1000) - */ - values[0] = ((PyObject *)Py_None); - values[1] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_binary); - if (value) { values[0] = value; kw_args--; } - } - case 1: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_text); - if (value) { values[1] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_from_binary = values[0]; - __pyx_v_from_text = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.Alignment.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_9Alignment_4__cinit__(((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_v_self), __pyx_v_from_binary, __pyx_v_from_text); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_9Alignment_4__cinit__(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text) { - int __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":46 - * - * def __cinit__(self, from_binary=None, from_text=None): - * self.links = IntList(1000,1000) # <<<<<<<<<<<<<< - * self.sent_index = IntList(1000,1000) - * if from_binary: - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_k_tuple_26), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->links); - __Pyx_DECREF(((PyObject *)__pyx_v_self->links)); - __pyx_v_self->links = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":47 - * def __cinit__(self, from_binary=None, from_text=None): - * self.links = IntList(1000,1000) - * self.sent_index = IntList(1000,1000) # <<<<<<<<<<<<<< - * if from_binary: - * self.read_binary(from_binary) - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_k_tuple_27), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->sent_index); - __Pyx_DECREF(((PyObject *)__pyx_v_self->sent_index)); - __pyx_v_self->sent_index = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":48 - * self.links = IntList(1000,1000) - * self.sent_index = IntList(1000,1000) - * if from_binary: # <<<<<<<<<<<<<< - * self.read_binary(from_binary) - * elif from_text: - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_binary); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":49 - * self.sent_index = IntList(1000,1000) - * if from_binary: - * self.read_binary(from_binary) # <<<<<<<<<<<<<< - * elif from_text: - * self.read_text(from_text) - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_binary); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_from_binary); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_binary); - __Pyx_GIVEREF(__pyx_v_from_binary); - __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L3; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":50 - * if from_binary: - * self.read_binary(from_binary) - * elif from_text: # <<<<<<<<<<<<<< - * self.read_text(from_text) - * - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_text); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":51 - * self.read_binary(from_binary) - * elif from_text: - * self.read_text(from_text) # <<<<<<<<<<<<<< - * - * def read_text(self, char* filename): - */ - __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_text); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_from_text); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_text); - __Pyx_GIVEREF(__pyx_v_from_text); - __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L3; - } - __pyx_L3:; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec_sa.Alignment.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9Alignment_7read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9Alignment_7read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_text (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.Alignment.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_9Alignment_6read_text(((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":53 - * self.read_text(from_text) - * - * def read_text(self, char* filename): # <<<<<<<<<<<<<< - * with gzip_or_text(filename) as f: - * for line in f: - */ - -static PyObject *__pyx_pf_8_cdec_sa_9Alignment_6read_text(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename) { - PyObject *__pyx_v_f = NULL; - PyObject *__pyx_v_line = NULL; - PyObject *__pyx_v_pairs = NULL; - PyObject *__pyx_v_pair = NULL; - PyObject *__pyx_v_i = NULL; - PyObject *__pyx_v_j = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - Py_ssize_t __pyx_t_8; - PyObject *(*__pyx_t_9)(PyObject *); - Py_ssize_t __pyx_t_10; - PyObject *(*__pyx_t_11)(PyObject *); - PyObject *__pyx_t_12 = NULL; - PyObject *__pyx_t_13 = NULL; - PyObject *__pyx_t_14 = NULL; - PyObject *(*__pyx_t_15)(PyObject *); - int __pyx_t_16; - int __pyx_t_17; - int __pyx_t_18; - PyObject *__pyx_t_19 = NULL; - int __pyx_t_20; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("read_text", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":54 - * - * def read_text(self, char* filename): - * with gzip_or_text(filename) as f: # <<<<<<<<<<<<<< - * for line in f: - * self.sent_index.append(len(self.links)) - */ - /*with:*/ { - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__gzip_or_text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __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[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__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_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /*try:*/ { - { - __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - /*try:*/ { - __Pyx_INCREF(__pyx_t_1); - __pyx_v_f = __pyx_t_1; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":55 - * def read_text(self, char* filename): - * with gzip_or_text(filename) as f: - * for line in f: # <<<<<<<<<<<<<< - * self.sent_index.append(len(self.links)) - * pairs = line.split() - */ - if (PyList_CheckExact(__pyx_v_f) || PyTuple_CheckExact(__pyx_v_f)) { - __pyx_t_1 = __pyx_v_f; __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; - } else { - __pyx_t_2 = __pyx_t_9(__pyx_t_1); - if (unlikely(!__pyx_t_2)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF(__pyx_v_line); - __pyx_v_line = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":56 - * with gzip_or_text(filename) as f: - * for line in f: - * self.sent_index.append(len(self.links)) # <<<<<<<<<<<<<< - * pairs = line.split() - * for pair in pairs: - */ - __pyx_t_2 = ((PyObject *)__pyx_v_self->links); - __Pyx_INCREF(__pyx_t_2); - __pyx_t_10 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_10); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_index), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":57 - * for line in f: - * self.sent_index.append(len(self.links)) - * pairs = line.split() # <<<<<<<<<<<<<< - * for pair in pairs: - * (i, j) = map(int, pair.split('-')) - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_v_pairs); - __pyx_v_pairs = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":58 - * self.sent_index.append(len(self.links)) - * pairs = line.split() - * for pair in pairs: # <<<<<<<<<<<<<< - * (i, j) = map(int, pair.split('-')) - * self.links.append(self.link(i, j)) - */ - if (PyList_CheckExact(__pyx_v_pairs) || PyTuple_CheckExact(__pyx_v_pairs)) { - __pyx_t_2 = __pyx_v_pairs; __Pyx_INCREF(__pyx_t_2); __pyx_t_10 = 0; - __pyx_t_11 = NULL; - } else { - __pyx_t_10 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_pairs); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = Py_TYPE(__pyx_t_2)->tp_iternext; - } - for (;;) { - if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_2)) { - if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_2)) break; - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_3); __pyx_t_10++; - } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_2)) { - if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_3); __pyx_t_10++; - } else { - __pyx_t_3 = __pyx_t_11(__pyx_t_2); - if (unlikely(!__pyx_t_3)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF(__pyx_v_pair); - __pyx_v_pair = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":59 - * pairs = line.split() - * for pair in pairs: - * (i, j) = map(int, pair.split('-')) # <<<<<<<<<<<<<< - * self.links.append(self.link(i, j)) - * self.sent_index.append(len(self.links)) - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_pair, __pyx_n_s__split); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_12 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_29), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)((PyObject*)(&PyInt_Type)))); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)((PyObject*)(&PyInt_Type)))); - __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyInt_Type)))); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_12); - __Pyx_GIVEREF(__pyx_t_12); - __pyx_t_12 = 0; - __pyx_t_12 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_12))) || (PyList_CheckExact(__pyx_t_12))) { - PyObject* sequence = __pyx_t_12; - if (likely(PyTuple_CheckExact(sequence))) { - 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[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_13 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - __pyx_t_3 = PyList_GET_ITEM(sequence, 0); - __pyx_t_13 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_14 = PyObject_GetIter(__pyx_t_12); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_3)) goto __pyx_L20_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - 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[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_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[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_L21_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_3; - __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_v_j); - __pyx_v_j = __pyx_t_13; - __pyx_t_13 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":60 - * for pair in pairs: - * (i, j) = map(int, pair.split('-')) - * self.links.append(self.link(i, j)) # <<<<<<<<<<<<<< - * self.sent_index.append(len(self.links)) - * - */ - __pyx_t_16 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_16 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_17 = __Pyx_PyInt_AsInt(__pyx_v_j); if (unlikely((__pyx_t_17 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_12 = PyInt_FromLong(((struct __pyx_vtabstruct_8_cdec_sa_Alignment *)__pyx_v_self->__pyx_vtab)->link(__pyx_v_self, __pyx_t_16, __pyx_t_17)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_13 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->links), __pyx_t_12); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":61 - * (i, j) = map(int, pair.split('-')) - * self.links.append(self.link(i, j)) - * self.sent_index.append(len(self.links)) # <<<<<<<<<<<<<< - * - * def read_binary(self, char* filename): - */ - __pyx_t_1 = ((PyObject *)__pyx_v_self->links); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_8 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_index), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L14_try_end; - __pyx_L7_error:; - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":54 - * - * def read_text(self, char* filename): - * with gzip_or_text(filename) as f: # <<<<<<<<<<<<<< - * for line in f: - * self.sent_index.append(len(self.links)) - */ - /*except:*/ { - __Pyx_AddTraceback("_cdec_sa.Alignment.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_1, &__pyx_t_13) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_12 = PyTuple_New(3); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_INCREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_13); - PyTuple_SET_ITEM(__pyx_t_12, 2, __pyx_t_13); - __Pyx_GIVEREF(__pyx_t_13); - __pyx_t_19 = PyObject_Call(__pyx_t_4, __pyx_t_12, NULL); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_19); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - if (unlikely(__pyx_t_18 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __pyx_t_20 = (!__pyx_t_18); - if (__pyx_t_20) { - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_13); - __Pyx_ErrRestore(__pyx_t_2, __pyx_t_1, __pyx_t_13); - __pyx_t_2 = 0; __pyx_t_1 = 0; __pyx_t_13 = 0; - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - goto __pyx_L24; - } - __pyx_L24:; - __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - goto __pyx_L8_exception_handled; - } - __pyx_L9_except_error:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - goto __pyx_L1_error; - __pyx_L8_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - __pyx_L14_try_end:; - } - } - /*finally:*/ { - if (__pyx_t_4) { - __pyx_t_7 = PyObject_Call(__pyx_t_4, __pyx_k_tuple_30, NULL); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_20 = __Pyx_PyObject_IsTrue(__pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_20 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - goto __pyx_L25; - __pyx_L3_error:; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L1_error; - __pyx_L25:; - } - - __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_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_XDECREF(__pyx_t_13); - __Pyx_XDECREF(__pyx_t_14); - __Pyx_AddTraceback("_cdec_sa.Alignment.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_f); - __Pyx_XDECREF(__pyx_v_line); - __Pyx_XDECREF(__pyx_v_pairs); - __Pyx_XDECREF(__pyx_v_pair); - __Pyx_XDECREF(__pyx_v_i); - __Pyx_XDECREF(__pyx_v_j); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9Alignment_9read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9Alignment_9read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_binary (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.Alignment.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_9Alignment_8read_binary(((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":63 - * self.sent_index.append(len(self.links)) - * - * def read_binary(self, char* filename): # <<<<<<<<<<<<<< - * cdef FILE* f - * f = fopen(filename, "r") - */ - -static PyObject *__pyx_pf_8_cdec_sa_9Alignment_8read_binary(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename) { - FILE *__pyx_v_f; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_binary", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":65 - * def read_binary(self, char* filename): - * cdef FILE* f - * f = fopen(filename, "r") # <<<<<<<<<<<<<< - * self.links.read_handle(f) - * self.sent_index.read_handle(f) - */ - __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":66 - * cdef FILE* f - * f = fopen(filename, "r") - * self.links.read_handle(f) # <<<<<<<<<<<<<< - * self.sent_index.read_handle(f) - * fclose(f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->links->__pyx_vtab)->read_handle(__pyx_v_self->links, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":67 - * f = fopen(filename, "r") - * self.links.read_handle(f) - * self.sent_index.read_handle(f) # <<<<<<<<<<<<<< - * fclose(f) - * - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->sent_index->__pyx_vtab)->read_handle(__pyx_v_self->sent_index, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":68 - * self.links.read_handle(f) - * self.sent_index.read_handle(f) - * fclose(f) # <<<<<<<<<<<<<< - * - * def write_text(self, char* filename): - */ - fclose(__pyx_v_f); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9Alignment_11write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9Alignment_11write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_text (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.Alignment.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_9Alignment_10write_text(((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":70 - * fclose(f) - * - * def write_text(self, char* filename): # <<<<<<<<<<<<<< - * with open(filename, "w") as f: - * sent_num = 0 - */ - -static PyObject *__pyx_pf_8_cdec_sa_9Alignment_10write_text(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename) { - PyObject *__pyx_v_f = NULL; - PyObject *__pyx_v_sent_num = NULL; - PyObject *__pyx_v_i = NULL; - PyObject *__pyx_v_link = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - Py_ssize_t __pyx_t_8; - PyObject *(*__pyx_t_9)(PyObject *); - PyObject *__pyx_t_10 = NULL; - int __pyx_t_11; - PyObject *__pyx_t_12 = NULL; - PyObject *__pyx_t_13 = NULL; - PyObject *__pyx_t_14 = NULL; - int __pyx_t_15; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("write_text", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":71 - * - * def write_text(self, char* filename): - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * sent_num = 0 - * for i, link in enumerate(self.links): - */ - /*with:*/ { - __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /*try:*/ { - { - __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - /*try:*/ { - __Pyx_INCREF(__pyx_t_4); - __pyx_v_f = __pyx_t_4; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":72 - * def write_text(self, char* filename): - * with open(filename, "w") as f: - * sent_num = 0 # <<<<<<<<<<<<<< - * for i, link in enumerate(self.links): - * while i >= self.sent_index[sent_num]: - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_v_sent_num = __pyx_int_0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":73 - * with open(filename, "w") as f: - * sent_num = 0 - * for i, link in enumerate(self.links): # <<<<<<<<<<<<<< - * while i >= self.sent_index[sent_num]: - * f.write("\n") - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_t_4 = __pyx_int_0; - if (PyList_CheckExact(((PyObject *)__pyx_v_self->links)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->links))) { - __pyx_t_1 = ((PyObject *)__pyx_v_self->links); __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self->links)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; - } else { - __pyx_t_2 = __pyx_t_9(__pyx_t_1); - if (unlikely(!__pyx_t_2)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF(__pyx_v_link); - __pyx_v_link = __pyx_t_2; - __pyx_t_2 = 0; - __Pyx_INCREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_4; - __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); - __pyx_t_4 = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":74 - * sent_num = 0 - * for i, link in enumerate(self.links): - * while i >= self.sent_index[sent_num]: # <<<<<<<<<<<<<< - * f.write("\n") - * sent_num = sent_num + 1 - */ - while (1) { - __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_self->sent_index), __pyx_v_sent_num); if (!__pyx_t_2) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = PyObject_RichCompare(__pyx_v_i, __pyx_t_2, Py_GE); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (!__pyx_t_11) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":75 - * for i, link in enumerate(self.links): - * while i >= self.sent_index[sent_num]: - * f.write("\n") # <<<<<<<<<<<<<< - * sent_num = sent_num + 1 - * f.write("%d-%d " % self.unlink(link)) - */ - __pyx_t_10 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_k_tuple_31), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":76 - * while i >= self.sent_index[sent_num]: - * f.write("\n") - * sent_num = sent_num + 1 # <<<<<<<<<<<<<< - * f.write("%d-%d " % self.unlink(link)) - * f.write("\n") - */ - __pyx_t_2 = PyNumber_Add(__pyx_v_sent_num, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_v_sent_num); - __pyx_v_sent_num = __pyx_t_2; - __pyx_t_2 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":77 - * f.write("\n") - * sent_num = sent_num + 1 - * f.write("%d-%d " % self.unlink(link)) # <<<<<<<<<<<<<< - * f.write("\n") - * - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__unlink); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_INCREF(__pyx_v_link); - PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_v_link); - __Pyx_GIVEREF(__pyx_v_link); - __pyx_t_13 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; - __pyx_t_12 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_32), __pyx_t_13); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_12)); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_13); - PyTuple_SET_ITEM(__pyx_t_13, 0, ((PyObject *)__pyx_t_12)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_12)); - __pyx_t_12 = 0; - __pyx_t_12 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":78 - * sent_num = sent_num + 1 - * f.write("%d-%d " % self.unlink(link)) - * f.write("\n") # <<<<<<<<<<<<<< - * - * def write_binary(self, char* filename): - */ - __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_33), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L14_try_end; - __pyx_L7_error:; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":71 - * - * def write_text(self, char* filename): - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * sent_num = 0 - * for i, link in enumerate(self.links): - */ - /*except:*/ { - __Pyx_AddTraceback("_cdec_sa.Alignment.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_4, &__pyx_t_12) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_13 = PyTuple_New(3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_INCREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_12); - __Pyx_GIVEREF(__pyx_t_12); - __pyx_t_14 = PyObject_Call(__pyx_t_3, __pyx_t_13, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_14); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __pyx_t_15 = (!__pyx_t_11); - if (__pyx_t_15) { - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_12); - __Pyx_ErrRestore(__pyx_t_1, __pyx_t_4, __pyx_t_12); - __pyx_t_1 = 0; __pyx_t_4 = 0; __pyx_t_12 = 0; - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - goto __pyx_L22; - } - __pyx_L22:; - __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - goto __pyx_L8_exception_handled; - } - __pyx_L9_except_error:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - goto __pyx_L1_error; - __pyx_L8_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - __pyx_L14_try_end:; - } - } - /*finally:*/ { - if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_34, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_15 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - goto __pyx_L23; - __pyx_L3_error:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L1_error; - __pyx_L23:; - } - - __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_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_XDECREF(__pyx_t_13); - __Pyx_AddTraceback("_cdec_sa.Alignment.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_f); - __Pyx_XDECREF(__pyx_v_sent_num); - __Pyx_XDECREF(__pyx_v_i); - __Pyx_XDECREF(__pyx_v_link); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9Alignment_13write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9Alignment_13write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_binary (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.Alignment.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_9Alignment_12write_binary(((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":80 - * f.write("\n") - * - * def write_binary(self, char* filename): # <<<<<<<<<<<<<< - * cdef FILE* f - * f = fopen(filename, "w") - */ - -static PyObject *__pyx_pf_8_cdec_sa_9Alignment_12write_binary(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename) { - FILE *__pyx_v_f; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_binary", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":82 - * def write_binary(self, char* filename): - * cdef FILE* f - * f = fopen(filename, "w") # <<<<<<<<<<<<<< - * self.links.write_handle(f) - * self.sent_index.write_handle(f) - */ - __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":83 - * cdef FILE* f - * f = fopen(filename, "w") - * self.links.write_handle(f) # <<<<<<<<<<<<<< - * self.sent_index.write_handle(f) - * fclose(f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->links->__pyx_vtab)->write_handle(__pyx_v_self->links, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":84 - * f = fopen(filename, "w") - * self.links.write_handle(f) - * self.sent_index.write_handle(f) # <<<<<<<<<<<<<< - * fclose(f) - * - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->sent_index->__pyx_vtab)->write_handle(__pyx_v_self->sent_index, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":85 - * self.links.write_handle(f) - * self.sent_index.write_handle(f) - * fclose(f) # <<<<<<<<<<<<<< - * - * def write_enhanced(self, char* filename): - */ - fclose(__pyx_v_f); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9Alignment_15write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9Alignment_15write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_enhanced (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.Alignment.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_9Alignment_14write_enhanced(((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":87 - * fclose(f) - * - * def write_enhanced(self, char* filename): # <<<<<<<<<<<<<< - * with open(filename, "w") as f: - * sent_num = 1 - */ - -static PyObject *__pyx_pf_8_cdec_sa_9Alignment_14write_enhanced(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, char *__pyx_v_filename) { - PyObject *__pyx_v_f = NULL; - CYTHON_UNUSED long __pyx_v_sent_num; - PyObject *__pyx_v_link = NULL; - PyObject *__pyx_v_i = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - Py_ssize_t __pyx_t_8; - PyObject *(*__pyx_t_9)(PyObject *); - PyObject *__pyx_t_10 = NULL; - int __pyx_t_11; - PyObject *__pyx_t_12 = NULL; - int __pyx_t_13; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("write_enhanced", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":88 - * - * def write_enhanced(self, char* filename): - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * sent_num = 1 - * for link in self.links: - */ - /*with:*/ { - __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /*try:*/ { - { - __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - /*try:*/ { - __Pyx_INCREF(__pyx_t_4); - __pyx_v_f = __pyx_t_4; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":89 - * def write_enhanced(self, char* filename): - * with open(filename, "w") as f: - * sent_num = 1 # <<<<<<<<<<<<<< - * for link in self.links: - * f.write("%d " % link) - */ - __pyx_v_sent_num = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":90 - * with open(filename, "w") as f: - * sent_num = 1 - * for link in self.links: # <<<<<<<<<<<<<< - * f.write("%d " % link) - * f.write("\n") - */ - if (PyList_CheckExact(((PyObject *)__pyx_v_self->links)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->links))) { - __pyx_t_4 = ((PyObject *)__pyx_v_self->links); __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(((PyObject *)__pyx_v_self->links)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; - } else { - __pyx_t_1 = __pyx_t_9(__pyx_t_4); - if (unlikely(!__pyx_t_1)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XDECREF(__pyx_v_link); - __pyx_v_link = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":91 - * sent_num = 1 - * for link in self.links: - * f.write("%d " % link) # <<<<<<<<<<<<<< - * f.write("\n") - * for i in self.sent_index: - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_link); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":92 - * for link in self.links: - * f.write("%d " % link) - * f.write("\n") # <<<<<<<<<<<<<< - * for i in self.sent_index: - * f.write("%d " % i) - */ - __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_35), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":93 - * f.write("%d " % link) - * f.write("\n") - * for i in self.sent_index: # <<<<<<<<<<<<<< - * f.write("%d " % i) - * f.write("\n") - */ - if (PyList_CheckExact(((PyObject *)__pyx_v_self->sent_index)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->sent_index))) { - __pyx_t_2 = ((PyObject *)__pyx_v_self->sent_index); __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(((PyObject *)__pyx_v_self->sent_index)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_9 = Py_TYPE(__pyx_t_2)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_2)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break; - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_4); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_2)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_4); __pyx_t_8++; - } else { - __pyx_t_4 = __pyx_t_9(__pyx_t_2); - if (unlikely(!__pyx_t_4)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XDECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":94 - * f.write("\n") - * for i in self.sent_index: - * f.write("%d " % i) # <<<<<<<<<<<<<< - * f.write("\n") - * - */ - __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_10)); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_10)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); - __pyx_t_10 = 0; - __pyx_t_10 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":95 - * for i in self.sent_index: - * f.write("%d " % i) - * f.write("\n") # <<<<<<<<<<<<<< - * - * def alignment(self, i): - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_36), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L14_try_end; - __pyx_L7_error:; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":88 - * - * def write_enhanced(self, char* filename): - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * sent_num = 1 - * for link in self.links: - */ - /*except:*/ { - __Pyx_AddTraceback("_cdec_sa.Alignment.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_10, &__pyx_t_2, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - __Pyx_INCREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_12 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_12); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __pyx_t_13 = (!__pyx_t_11); - if (__pyx_t_13) { - __Pyx_GIVEREF(__pyx_t_10); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_ErrRestore(__pyx_t_10, __pyx_t_2, __pyx_t_1); - __pyx_t_10 = 0; __pyx_t_2 = 0; __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - goto __pyx_L22; - } - __pyx_L22:; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L8_exception_handled; - } - __pyx_L9_except_error:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - goto __pyx_L1_error; - __pyx_L8_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - __pyx_L14_try_end:; - } - } - /*finally:*/ { - if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_37, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - goto __pyx_L23; - __pyx_L3_error:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L1_error; - __pyx_L23:; - } - - __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_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("_cdec_sa.Alignment.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_f); - __Pyx_XDECREF(__pyx_v_link); - __Pyx_XDECREF(__pyx_v_i); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9Alignment_17alignment(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ -static char __pyx_doc_8_cdec_sa_9Alignment_16alignment[] = "Return all (e,f) pairs for sentence i"; -static PyObject *__pyx_pw_8_cdec_sa_9Alignment_17alignment(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("alignment (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9Alignment_16alignment(((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_v_self), ((PyObject *)__pyx_v_i)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":97 - * f.write("\n") - * - * def alignment(self, i): # <<<<<<<<<<<<<< - * """Return all (e,f) pairs for sentence i""" - * cdef int j, start, end - */ - -static PyObject *__pyx_pf_8_cdec_sa_9Alignment_16alignment(struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_i) { - int __pyx_v_j; - int __pyx_v_start; - int __pyx_v_end; - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("alignment", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":100 - * """Return all (e,f) pairs for sentence i""" - * cdef int j, start, end - * result = [] # <<<<<<<<<<<<<< - * start = self.sent_index.arr[i] - * end = self.sent_index.arr[i+1] - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_result = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":101 - * cdef int j, start, end - * result = [] - * start = self.sent_index.arr[i] # <<<<<<<<<<<<<< - * end = self.sent_index.arr[i+1] - * for j from start <= j < end: - */ - __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_start = (__pyx_v_self->sent_index->arr[__pyx_t_2]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":102 - * result = [] - * start = self.sent_index.arr[i] - * end = self.sent_index.arr[i+1] # <<<<<<<<<<<<<< - * for j from start <= j < end: - * result.append(self.unlink(self.links.arr[j])) - */ - __pyx_t_1 = PyNumber_Add(__pyx_v_i, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_end = (__pyx_v_self->sent_index->arr[__pyx_t_2]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":103 - * start = self.sent_index.arr[i] - * end = self.sent_index.arr[i+1] - * for j from start <= j < end: # <<<<<<<<<<<<<< - * result.append(self.unlink(self.links.arr[j])) - * return result - */ - __pyx_t_3 = __pyx_v_end; - for (__pyx_v_j = __pyx_v_start; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":104 - * end = self.sent_index.arr[i+1] - * for j from start <= j < end: - * result.append(self.unlink(self.links.arr[j])) # <<<<<<<<<<<<<< - * return result - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__unlink); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyInt_FromLong((__pyx_v_self->links->arr[__pyx_v_j])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_t_6 = PyList_Append(__pyx_v_result, __pyx_t_4); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":105 - * for j from start <= j < end: - * result.append(self.unlink(self.links.arr[j])) - * return result # <<<<<<<<<<<<<< - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - __pyx_r = ((PyObject *)__pyx_v_result); - 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_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("_cdec_sa.Alignment.alignment", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":15 - * int val - * - * cdef _node* new_node(int key): # <<<<<<<<<<<<<< - * cdef _node* n - * n = <_node*> malloc(sizeof(_node)) - */ - -static struct __pyx_t_8_cdec_sa__node *__pyx_f_8_cdec_sa_new_node(int __pyx_v_key) { - struct __pyx_t_8_cdec_sa__node *__pyx_v_n; - struct __pyx_t_8_cdec_sa__node *__pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("new_node", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":17 - * cdef _node* new_node(int key): - * cdef _node* n - * n = <_node*> malloc(sizeof(_node)) # <<<<<<<<<<<<<< - * n.smaller = NULL - * n.bigger = NULL - */ - __pyx_v_n = ((struct __pyx_t_8_cdec_sa__node *)malloc((sizeof(struct __pyx_t_8_cdec_sa__node)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":18 - * cdef _node* n - * n = <_node*> malloc(sizeof(_node)) - * n.smaller = NULL # <<<<<<<<<<<<<< - * n.bigger = NULL - * n.key = key - */ - __pyx_v_n->smaller = NULL; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":19 - * n = <_node*> malloc(sizeof(_node)) - * n.smaller = NULL - * n.bigger = NULL # <<<<<<<<<<<<<< - * n.key = key - * n.val = 0 - */ - __pyx_v_n->bigger = NULL; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":20 - * n.smaller = NULL - * n.bigger = NULL - * n.key = key # <<<<<<<<<<<<<< - * n.val = 0 - * return n - */ - __pyx_v_n->key = __pyx_v_key; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":21 - * n.bigger = NULL - * n.key = key - * n.val = 0 # <<<<<<<<<<<<<< - * return n - * - */ - __pyx_v_n->val = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":22 - * n.key = key - * n.val = 0 - * return n # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = __pyx_v_n; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":25 - * - * - * cdef del_node(_node* n): # <<<<<<<<<<<<<< - * if n.smaller != NULL: - * del_node(n.smaller) - */ - -static PyObject *__pyx_f_8_cdec_sa_del_node(struct __pyx_t_8_cdec_sa__node *__pyx_v_n) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("del_node", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":26 - * - * cdef del_node(_node* n): - * if n.smaller != NULL: # <<<<<<<<<<<<<< - * del_node(n.smaller) - * if n.bigger != NULL: - */ - __pyx_t_1 = (__pyx_v_n->smaller != NULL); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":27 - * cdef del_node(_node* n): - * if n.smaller != NULL: - * del_node(n.smaller) # <<<<<<<<<<<<<< - * if n.bigger != NULL: - * del_node(n.bigger) - */ - __pyx_t_2 = __pyx_f_8_cdec_sa_del_node(__pyx_v_n->smaller); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":28 - * if n.smaller != NULL: - * del_node(n.smaller) - * if n.bigger != NULL: # <<<<<<<<<<<<<< - * del_node(n.bigger) - * free(n) - */ - __pyx_t_1 = (__pyx_v_n->bigger != NULL); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":29 - * del_node(n.smaller) - * if n.bigger != NULL: - * del_node(n.bigger) # <<<<<<<<<<<<<< - * free(n) - * - */ - __pyx_t_2 = __pyx_f_8_cdec_sa_del_node(__pyx_v_n->bigger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":30 - * if n.bigger != NULL: - * del_node(n.bigger) - * free(n) # <<<<<<<<<<<<<< - * - * cdef int* get_val(_node* n, int key): - */ - free(__pyx_v_n); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_cdec_sa.del_node", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":32 - * free(n) - * - * cdef int* get_val(_node* n, int key): # <<<<<<<<<<<<<< - * if key == n.key: - * return &n.val - */ - -static int *__pyx_f_8_cdec_sa_get_val(struct __pyx_t_8_cdec_sa__node *__pyx_v_n, int __pyx_v_key) { - int *__pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("get_val", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":33 - * - * cdef int* get_val(_node* n, int key): - * if key == n.key: # <<<<<<<<<<<<<< - * return &n.val - * elif key < n.key: - */ - __pyx_t_1 = (__pyx_v_key == __pyx_v_n->key); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":34 - * cdef int* get_val(_node* n, int key): - * if key == n.key: - * return &n.val # <<<<<<<<<<<<<< - * elif key < n.key: - * if n.smaller == NULL: - */ - __pyx_r = (&__pyx_v_n->val); - goto __pyx_L0; - goto __pyx_L3; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":35 - * if key == n.key: - * return &n.val - * elif key < n.key: # <<<<<<<<<<<<<< - * if n.smaller == NULL: - * n.smaller = new_node(key) - */ - __pyx_t_1 = (__pyx_v_key < __pyx_v_n->key); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":36 - * return &n.val - * elif key < n.key: - * if n.smaller == NULL: # <<<<<<<<<<<<<< - * n.smaller = new_node(key) - * return &(n.smaller.val) - */ - __pyx_t_1 = (__pyx_v_n->smaller == NULL); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":37 - * elif key < n.key: - * if n.smaller == NULL: - * n.smaller = new_node(key) # <<<<<<<<<<<<<< - * return &(n.smaller.val) - * return get_val(n.smaller, key) - */ - __pyx_v_n->smaller = __pyx_f_8_cdec_sa_new_node(__pyx_v_key); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":38 - * if n.smaller == NULL: - * n.smaller = new_node(key) - * return &(n.smaller.val) # <<<<<<<<<<<<<< - * return get_val(n.smaller, key) - * else: - */ - __pyx_r = (&__pyx_v_n->smaller->val); - goto __pyx_L0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":39 - * n.smaller = new_node(key) - * return &(n.smaller.val) - * return get_val(n.smaller, key) # <<<<<<<<<<<<<< - * else: - * if n.bigger == NULL: - */ - __pyx_r = __pyx_f_8_cdec_sa_get_val(__pyx_v_n->smaller, __pyx_v_key); - goto __pyx_L0; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":41 - * return get_val(n.smaller, key) - * else: - * if n.bigger == NULL: # <<<<<<<<<<<<<< - * n.bigger = new_node(key) - * return &(n.bigger.val) - */ - __pyx_t_1 = (__pyx_v_n->bigger == NULL); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":42 - * else: - * if n.bigger == NULL: - * n.bigger = new_node(key) # <<<<<<<<<<<<<< - * return &(n.bigger.val) - * return get_val(n.bigger, key) - */ - __pyx_v_n->bigger = __pyx_f_8_cdec_sa_new_node(__pyx_v_key); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":43 - * if n.bigger == NULL: - * n.bigger = new_node(key) - * return &(n.bigger.val) # <<<<<<<<<<<<<< - * return get_val(n.bigger, key) - * - */ - __pyx_r = (&__pyx_v_n->bigger->val); - goto __pyx_L0; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":44 - * n.bigger = new_node(key) - * return &(n.bigger.val) - * return get_val(n.bigger, key) # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = __pyx_f_8_cdec_sa_get_val(__pyx_v_n->bigger, __pyx_v_key); - goto __pyx_L0; - } - __pyx_L3:; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_5BiLex_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_5BiLex_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_from_text = 0; - PyObject *__pyx_v_from_data = 0; - PyObject *__pyx_v_from_binary = 0; - PyObject *__pyx_v_earray = 0; - PyObject *__pyx_v_fsarray = 0; - PyObject *__pyx_v_alignment = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__from_text,&__pyx_n_s__from_data,&__pyx_n_s__from_binary,&__pyx_n_s__earray,&__pyx_n_s__fsarray,&__pyx_n_s__alignment,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[6] = {0,0,0,0,0,0}; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":54 - * cdef id2eword, id2fword, eword2id, fword2id - * - * def __cinit__(self, from_text=None, from_data=False, from_binary=None, # <<<<<<<<<<<<<< - * earray=None, fsarray=None, alignment=None): - * self.id2eword = [] - */ - values[0] = ((PyObject *)Py_None); - values[1] = __pyx_k_38; - values[2] = ((PyObject *)Py_None); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":55 - * - * def __cinit__(self, from_text=None, from_data=False, from_binary=None, - * earray=None, fsarray=None, alignment=None): # <<<<<<<<<<<<<< - * self.id2eword = [] - * self.id2fword = [] - */ - values[3] = ((PyObject *)Py_None); - values[4] = ((PyObject *)Py_None); - values[5] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_text); - if (value) { values[0] = value; kw_args--; } - } - case 1: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_data); - if (value) { values[1] = value; kw_args--; } - } - case 2: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_binary); - if (value) { values[2] = value; kw_args--; } - } - case 3: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__earray); - if (value) { values[3] = value; kw_args--; } - } - case 4: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fsarray); - if (value) { values[4] = value; kw_args--; } - } - case 5: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__alignment); - if (value) { values[5] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_from_text = values[0]; - __pyx_v_from_data = values[1]; - __pyx_v_from_binary = values[2]; - __pyx_v_earray = values[3]; - __pyx_v_fsarray = values[4]; - __pyx_v_alignment = values[5]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.BiLex.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_5BiLex___cinit__(((struct __pyx_obj_8_cdec_sa_BiLex *)__pyx_v_self), __pyx_v_from_text, __pyx_v_from_data, __pyx_v_from_binary, __pyx_v_earray, __pyx_v_fsarray, __pyx_v_alignment); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":54 - * cdef id2eword, id2fword, eword2id, fword2id - * - * def __cinit__(self, from_text=None, from_data=False, from_binary=None, # <<<<<<<<<<<<<< - * earray=None, fsarray=None, alignment=None): - * self.id2eword = [] - */ - -static int __pyx_pf_8_cdec_sa_5BiLex___cinit__(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_from_text, PyObject *__pyx_v_from_data, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_earray, PyObject *__pyx_v_fsarray, PyObject *__pyx_v_alignment) { - int __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":56 - * def __cinit__(self, from_text=None, from_data=False, from_binary=None, - * earray=None, fsarray=None, alignment=None): - * self.id2eword = [] # <<<<<<<<<<<<<< - * self.id2fword = [] - * self.eword2id = {} - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_GOTREF(__pyx_v_self->id2eword); - __Pyx_DECREF(__pyx_v_self->id2eword); - __pyx_v_self->id2eword = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":57 - * earray=None, fsarray=None, alignment=None): - * self.id2eword = [] - * self.id2fword = [] # <<<<<<<<<<<<<< - * self.eword2id = {} - * self.fword2id = {} - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_GOTREF(__pyx_v_self->id2fword); - __Pyx_DECREF(__pyx_v_self->id2fword); - __pyx_v_self->id2fword = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":58 - * self.id2eword = [] - * self.id2fword = [] - * self.eword2id = {} # <<<<<<<<<<<<<< - * self.fword2id = {} - * self.e_index = IntList() - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_GOTREF(__pyx_v_self->eword2id); - __Pyx_DECREF(__pyx_v_self->eword2id); - __pyx_v_self->eword2id = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":59 - * self.id2fword = [] - * self.eword2id = {} - * self.fword2id = {} # <<<<<<<<<<<<<< - * self.e_index = IntList() - * self.f_index = IntList() - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_GOTREF(__pyx_v_self->fword2id); - __Pyx_DECREF(__pyx_v_self->fword2id); - __pyx_v_self->fword2id = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":60 - * self.eword2id = {} - * self.fword2id = {} - * self.e_index = IntList() # <<<<<<<<<<<<<< - * self.f_index = IntList() - * self.col1 = FloatList() - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->e_index); - __Pyx_DECREF(((PyObject *)__pyx_v_self->e_index)); - __pyx_v_self->e_index = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":61 - * self.fword2id = {} - * self.e_index = IntList() - * self.f_index = IntList() # <<<<<<<<<<<<<< - * self.col1 = FloatList() - * self.col2 = FloatList() - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->f_index); - __Pyx_DECREF(((PyObject *)__pyx_v_self->f_index)); - __pyx_v_self->f_index = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":62 - * self.e_index = IntList() - * self.f_index = IntList() - * self.col1 = FloatList() # <<<<<<<<<<<<<< - * self.col2 = FloatList() - * if from_binary: - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_FloatList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->col1); - __Pyx_DECREF(((PyObject *)__pyx_v_self->col1)); - __pyx_v_self->col1 = ((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":63 - * self.f_index = IntList() - * self.col1 = FloatList() - * self.col2 = FloatList() # <<<<<<<<<<<<<< - * if from_binary: - * self.read_binary(from_binary) - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_FloatList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->col2); - __Pyx_DECREF(((PyObject *)__pyx_v_self->col2)); - __pyx_v_self->col2 = ((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":64 - * self.col1 = FloatList() - * self.col2 = FloatList() - * if from_binary: # <<<<<<<<<<<<<< - * self.read_binary(from_binary) - * elif from_data: - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_binary); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":65 - * self.col2 = FloatList() - * if from_binary: - * self.read_binary(from_binary) # <<<<<<<<<<<<<< - * elif from_data: - * self.compute_from_data(fsarray, earray, alignment) - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_binary); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_from_binary); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_binary); - __Pyx_GIVEREF(__pyx_v_from_binary); - __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L3; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":66 - * if from_binary: - * self.read_binary(from_binary) - * elif from_data: # <<<<<<<<<<<<<< - * self.compute_from_data(fsarray, earray, alignment) - * else: - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_data); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":67 - * self.read_binary(from_binary) - * elif from_data: - * self.compute_from_data(fsarray, earray, alignment) # <<<<<<<<<<<<<< - * else: - * self.read_text(from_text) - */ - if (!(likely(((__pyx_v_fsarray) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_fsarray, __pyx_ptype_8_cdec_sa_SuffixArray))))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = __pyx_v_fsarray; - __Pyx_INCREF(__pyx_t_4); - if (!(likely(((__pyx_v_earray) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_earray, __pyx_ptype_8_cdec_sa_DataArray))))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = __pyx_v_earray; - __Pyx_INCREF(__pyx_t_3); - if (!(likely(((__pyx_v_alignment) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_alignment, __pyx_ptype_8_cdec_sa_Alignment))))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = __pyx_v_alignment; - __Pyx_INCREF(__pyx_t_1); - __pyx_t_5 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->compute_from_data(__pyx_v_self, ((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_t_4), ((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_t_3), ((struct __pyx_obj_8_cdec_sa_Alignment *)__pyx_t_1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":69 - * self.compute_from_data(fsarray, earray, alignment) - * else: - * self.read_text(from_text) # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_text); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_from_text); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_from_text); - __Pyx_GIVEREF(__pyx_v_from_text); - __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __pyx_L3:; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("_cdec_sa.BiLex.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":72 - * - * - * cdef compute_from_data(self, SuffixArray fsa, DataArray eda, Alignment aa): # <<<<<<<<<<<<<< - * cdef int sent_id, num_links, l, i, j, f_i, e_j, I, J, V_E, V_F, num_pairs - * cdef int *fsent, *esent, *alignment, *links, *ealigned, *faligned - */ - -static PyObject *__pyx_f_8_cdec_sa_5BiLex_compute_from_data(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_fsa, struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_eda, struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_aa) { - int __pyx_v_sent_id; - int __pyx_v_num_links; - int __pyx_v_l; - int __pyx_v_i; - int __pyx_v_j; - int __pyx_v_f_i; - int __pyx_v_e_j; - int __pyx_v_I; - int __pyx_v_J; - int __pyx_v_V_E; - int __pyx_v_V_F; - int __pyx_v_num_pairs; - int *__pyx_v_fsent; - int *__pyx_v_esent; - int *__pyx_v_links; - int *__pyx_v_ealigned; - int *__pyx_v_faligned; - struct __pyx_t_8_cdec_sa__node **__pyx_v_dict; - int *__pyx_v_fmargin; - int *__pyx_v_emargin; - int *__pyx_v_count; - PyObject *__pyx_v_word = 0; - int __pyx_v_null_word; - PyObject *__pyx_v_id = NULL; - PyObject *__pyx_v_num_sents = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *(*__pyx_t_3)(PyObject *); - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - int __pyx_t_10; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; - PyObject *__pyx_t_13 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("compute_from_data", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":80 - * cdef int null_word - * - * null_word = 0 # <<<<<<<<<<<<<< - * for word in fsa.darray.id2word: # I miss list comprehensions - * self.id2fword.append(word) - */ - __pyx_v_null_word = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":81 - * - * null_word = 0 - * for word in fsa.darray.id2word: # I miss list comprehensions # <<<<<<<<<<<<<< - * self.id2fword.append(word) - * self.id2fword[null_word] = "NULL" - */ - if (PyList_CheckExact(__pyx_v_fsa->darray->id2word) || PyTuple_CheckExact(__pyx_v_fsa->darray->id2word)) { - __pyx_t_1 = __pyx_v_fsa->darray->id2word; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; - __pyx_t_3 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_fsa->darray->id2word); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; - } - for (;;) { - if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; - } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; - } else { - __pyx_t_4 = __pyx_t_3(__pyx_t_1); - if (unlikely(!__pyx_t_4)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XDECREF(((PyObject *)__pyx_v_word)); - __pyx_v_word = ((PyObject*)__pyx_t_4); - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":82 - * null_word = 0 - * for word in fsa.darray.id2word: # I miss list comprehensions - * self.id2fword.append(word) # <<<<<<<<<<<<<< - * self.id2fword[null_word] = "NULL" - * for id, word in enumerate(self.id2fword): - */ - __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_self->id2fword, ((PyObject *)__pyx_v_word)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":83 - * for word in fsa.darray.id2word: # I miss list comprehensions - * self.id2fword.append(word) - * self.id2fword[null_word] = "NULL" # <<<<<<<<<<<<<< - * for id, word in enumerate(self.id2fword): - * self.fword2id[word] = id - */ - if (__Pyx_SetItemInt(__pyx_v_self->id2fword, __pyx_v_null_word, ((PyObject *)__pyx_n_s__NULL), sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":84 - * self.id2fword.append(word) - * self.id2fword[null_word] = "NULL" - * for id, word in enumerate(self.id2fword): # <<<<<<<<<<<<<< - * self.fword2id[word] = id - * - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_t_1 = __pyx_int_0; - if (PyList_CheckExact(__pyx_v_self->id2fword) || PyTuple_CheckExact(__pyx_v_self->id2fword)) { - __pyx_t_4 = __pyx_v_self->id2fword; __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0; - __pyx_t_3 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_self->id2fword); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = Py_TYPE(__pyx_t_4)->tp_iternext; - } - for (;;) { - if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_4)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_4)) break; - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; - } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_4)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; - } else { - __pyx_t_5 = __pyx_t_3(__pyx_t_4); - if (unlikely(!__pyx_t_5)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_5); - } - if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XDECREF(((PyObject *)__pyx_v_word)); - __pyx_v_word = ((PyObject*)__pyx_t_5); - __pyx_t_5 = 0; - __Pyx_INCREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_v_id); - __pyx_v_id = __pyx_t_1; - __pyx_t_5 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); - __pyx_t_1 = __pyx_t_5; - __pyx_t_5 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":85 - * self.id2fword[null_word] = "NULL" - * for id, word in enumerate(self.id2fword): - * self.fword2id[word] = id # <<<<<<<<<<<<<< - * - * for word in eda.id2word: - */ - if (PyObject_SetItem(__pyx_v_self->fword2id, ((PyObject *)__pyx_v_word), __pyx_v_id) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":87 - * self.fword2id[word] = id - * - * for word in eda.id2word: # <<<<<<<<<<<<<< - * self.id2eword.append(word) - * self.id2eword[null_word] = "NULL" - */ - if (PyList_CheckExact(__pyx_v_eda->id2word) || PyTuple_CheckExact(__pyx_v_eda->id2word)) { - __pyx_t_1 = __pyx_v_eda->id2word; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; - __pyx_t_3 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_eda->id2word); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; - } - for (;;) { - if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; - } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; - } else { - __pyx_t_4 = __pyx_t_3(__pyx_t_1); - if (unlikely(!__pyx_t_4)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XDECREF(((PyObject *)__pyx_v_word)); - __pyx_v_word = ((PyObject*)__pyx_t_4); - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":88 - * - * for word in eda.id2word: - * self.id2eword.append(word) # <<<<<<<<<<<<<< - * self.id2eword[null_word] = "NULL" - * for id, word in enumerate(self.id2eword): - */ - __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_self->id2eword, ((PyObject *)__pyx_v_word)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":89 - * for word in eda.id2word: - * self.id2eword.append(word) - * self.id2eword[null_word] = "NULL" # <<<<<<<<<<<<<< - * for id, word in enumerate(self.id2eword): - * self.eword2id[word] = id - */ - if (__Pyx_SetItemInt(__pyx_v_self->id2eword, __pyx_v_null_word, ((PyObject *)__pyx_n_s__NULL), sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":90 - * self.id2eword.append(word) - * self.id2eword[null_word] = "NULL" - * for id, word in enumerate(self.id2eword): # <<<<<<<<<<<<<< - * self.eword2id[word] = id - * - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_t_1 = __pyx_int_0; - if (PyList_CheckExact(__pyx_v_self->id2eword) || PyTuple_CheckExact(__pyx_v_self->id2eword)) { - __pyx_t_4 = __pyx_v_self->id2eword; __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0; - __pyx_t_3 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_self->id2eword); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = Py_TYPE(__pyx_t_4)->tp_iternext; - } - for (;;) { - if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_4)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_4)) break; - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; - } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_4)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; - } else { - __pyx_t_5 = __pyx_t_3(__pyx_t_4); - if (unlikely(!__pyx_t_5)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_5); - } - if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XDECREF(((PyObject *)__pyx_v_word)); - __pyx_v_word = ((PyObject*)__pyx_t_5); - __pyx_t_5 = 0; - __Pyx_INCREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_v_id); - __pyx_v_id = __pyx_t_1; - __pyx_t_5 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); - __pyx_t_1 = __pyx_t_5; - __pyx_t_5 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":91 - * self.id2eword[null_word] = "NULL" - * for id, word in enumerate(self.id2eword): - * self.eword2id[word] = id # <<<<<<<<<<<<<< - * - * num_pairs = 0 - */ - if (PyObject_SetItem(__pyx_v_self->eword2id, ((PyObject *)__pyx_v_word), __pyx_v_id) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":93 - * self.eword2id[word] = id - * - * num_pairs = 0 # <<<<<<<<<<<<<< - * - * V_E = len(eda.id2word) - */ - __pyx_v_num_pairs = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":95 - * num_pairs = 0 - * - * V_E = len(eda.id2word) # <<<<<<<<<<<<<< - * V_F = len(fsa.darray.id2word) - * fmargin = malloc(V_F*sizeof(int)) - */ - __pyx_t_1 = __pyx_v_eda->id2word; - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_V_E = __pyx_t_2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":96 - * - * V_E = len(eda.id2word) - * V_F = len(fsa.darray.id2word) # <<<<<<<<<<<<<< - * fmargin = malloc(V_F*sizeof(int)) - * emargin = malloc(V_E*sizeof(int)) - */ - __pyx_t_1 = __pyx_v_fsa->darray->id2word; - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_V_F = __pyx_t_2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":97 - * V_E = len(eda.id2word) - * V_F = len(fsa.darray.id2word) - * fmargin = malloc(V_F*sizeof(int)) # <<<<<<<<<<<<<< - * emargin = malloc(V_E*sizeof(int)) - * memset(fmargin, 0, V_F*sizeof(int)) - */ - __pyx_v_fmargin = ((int *)malloc((__pyx_v_V_F * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":98 - * V_F = len(fsa.darray.id2word) - * fmargin = malloc(V_F*sizeof(int)) - * emargin = malloc(V_E*sizeof(int)) # <<<<<<<<<<<<<< - * memset(fmargin, 0, V_F*sizeof(int)) - * memset(emargin, 0, V_E*sizeof(int)) - */ - __pyx_v_emargin = ((int *)malloc((__pyx_v_V_E * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":99 - * fmargin = malloc(V_F*sizeof(int)) - * emargin = malloc(V_E*sizeof(int)) - * memset(fmargin, 0, V_F*sizeof(int)) # <<<<<<<<<<<<<< - * memset(emargin, 0, V_E*sizeof(int)) - * - */ - memset(__pyx_v_fmargin, 0, (__pyx_v_V_F * (sizeof(int)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":100 - * emargin = malloc(V_E*sizeof(int)) - * memset(fmargin, 0, V_F*sizeof(int)) - * memset(emargin, 0, V_E*sizeof(int)) # <<<<<<<<<<<<<< - * - * dict = <_node**> malloc(V_F*sizeof(_node*)) - */ - memset(__pyx_v_emargin, 0, (__pyx_v_V_E * (sizeof(int)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":102 - * memset(emargin, 0, V_E*sizeof(int)) - * - * dict = <_node**> malloc(V_F*sizeof(_node*)) # <<<<<<<<<<<<<< - * memset(dict, 0, V_F*sizeof(_node*)) - * - */ - __pyx_v_dict = ((struct __pyx_t_8_cdec_sa__node **)malloc((__pyx_v_V_F * (sizeof(struct __pyx_t_8_cdec_sa__node *))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":103 - * - * dict = <_node**> malloc(V_F*sizeof(_node*)) - * memset(dict, 0, V_F*sizeof(_node*)) # <<<<<<<<<<<<<< - * - * num_sents = len(fsa.darray.sent_index) - */ - memset(__pyx_v_dict, 0, (__pyx_v_V_F * (sizeof(struct __pyx_t_8_cdec_sa__node *)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":105 - * memset(dict, 0, V_F*sizeof(_node*)) - * - * num_sents = len(fsa.darray.sent_index) # <<<<<<<<<<<<<< - * for sent_id from 0 <= sent_id < num_sents-1: - * - */ - __pyx_t_1 = ((PyObject *)__pyx_v_fsa->darray->sent_index); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_num_sents = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":106 - * - * num_sents = len(fsa.darray.sent_index) - * for sent_id from 0 <= sent_id < num_sents-1: # <<<<<<<<<<<<<< - * - * fsent = fsa.darray.data.arr + fsa.darray.sent_index.arr[sent_id] - */ - __pyx_t_1 = PyNumber_Subtract(__pyx_v_num_sents, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (__pyx_v_sent_id = 0; __pyx_v_sent_id < __pyx_t_6; __pyx_v_sent_id++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":108 - * for sent_id from 0 <= sent_id < num_sents-1: - * - * fsent = fsa.darray.data.arr + fsa.darray.sent_index.arr[sent_id] # <<<<<<<<<<<<<< - * I = fsa.darray.sent_index.arr[sent_id+1] - fsa.darray.sent_index.arr[sent_id] - 1 - * faligned = malloc(I*sizeof(int)) - */ - __pyx_v_fsent = (__pyx_v_fsa->darray->data->arr + (__pyx_v_fsa->darray->sent_index->arr[__pyx_v_sent_id])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":109 - * - * fsent = fsa.darray.data.arr + fsa.darray.sent_index.arr[sent_id] - * I = fsa.darray.sent_index.arr[sent_id+1] - fsa.darray.sent_index.arr[sent_id] - 1 # <<<<<<<<<<<<<< - * faligned = malloc(I*sizeof(int)) - * memset(faligned, 0, I*sizeof(int)) - */ - __pyx_v_I = (((__pyx_v_fsa->darray->sent_index->arr[(__pyx_v_sent_id + 1)]) - (__pyx_v_fsa->darray->sent_index->arr[__pyx_v_sent_id])) - 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":110 - * fsent = fsa.darray.data.arr + fsa.darray.sent_index.arr[sent_id] - * I = fsa.darray.sent_index.arr[sent_id+1] - fsa.darray.sent_index.arr[sent_id] - 1 - * faligned = malloc(I*sizeof(int)) # <<<<<<<<<<<<<< - * memset(faligned, 0, I*sizeof(int)) - * - */ - __pyx_v_faligned = ((int *)malloc((__pyx_v_I * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":111 - * I = fsa.darray.sent_index.arr[sent_id+1] - fsa.darray.sent_index.arr[sent_id] - 1 - * faligned = malloc(I*sizeof(int)) - * memset(faligned, 0, I*sizeof(int)) # <<<<<<<<<<<<<< - * - * esent = eda.data.arr + eda.sent_index.arr[sent_id] - */ - memset(__pyx_v_faligned, 0, (__pyx_v_I * (sizeof(int)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":113 - * memset(faligned, 0, I*sizeof(int)) - * - * esent = eda.data.arr + eda.sent_index.arr[sent_id] # <<<<<<<<<<<<<< - * J = eda.sent_index.arr[sent_id+1] - eda.sent_index.arr[sent_id] - 1 - * ealigned = malloc(J*sizeof(int)) - */ - __pyx_v_esent = (__pyx_v_eda->data->arr + (__pyx_v_eda->sent_index->arr[__pyx_v_sent_id])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":114 - * - * esent = eda.data.arr + eda.sent_index.arr[sent_id] - * J = eda.sent_index.arr[sent_id+1] - eda.sent_index.arr[sent_id] - 1 # <<<<<<<<<<<<<< - * ealigned = malloc(J*sizeof(int)) - * memset(ealigned, 0, J*sizeof(int)) - */ - __pyx_v_J = (((__pyx_v_eda->sent_index->arr[(__pyx_v_sent_id + 1)]) - (__pyx_v_eda->sent_index->arr[__pyx_v_sent_id])) - 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":115 - * esent = eda.data.arr + eda.sent_index.arr[sent_id] - * J = eda.sent_index.arr[sent_id+1] - eda.sent_index.arr[sent_id] - 1 - * ealigned = malloc(J*sizeof(int)) # <<<<<<<<<<<<<< - * memset(ealigned, 0, J*sizeof(int)) - * - */ - __pyx_v_ealigned = ((int *)malloc((__pyx_v_J * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":116 - * J = eda.sent_index.arr[sent_id+1] - eda.sent_index.arr[sent_id] - 1 - * ealigned = malloc(J*sizeof(int)) - * memset(ealigned, 0, J*sizeof(int)) # <<<<<<<<<<<<<< - * - * links = aa._get_sent_links(sent_id, &num_links) - */ - memset(__pyx_v_ealigned, 0, (__pyx_v_J * (sizeof(int)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":118 - * memset(ealigned, 0, J*sizeof(int)) - * - * links = aa._get_sent_links(sent_id, &num_links) # <<<<<<<<<<<<<< - * - * for l from 0 <= l < num_links: - */ - __pyx_v_links = ((struct __pyx_vtabstruct_8_cdec_sa_Alignment *)__pyx_v_aa->__pyx_vtab)->_get_sent_links(__pyx_v_aa, __pyx_v_sent_id, (&__pyx_v_num_links)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":120 - * links = aa._get_sent_links(sent_id, &num_links) - * - * for l from 0 <= l < num_links: # <<<<<<<<<<<<<< - * i = links[l*2] - * j = links[l*2+1] - */ - __pyx_t_7 = __pyx_v_num_links; - for (__pyx_v_l = 0; __pyx_v_l < __pyx_t_7; __pyx_v_l++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":121 - * - * for l from 0 <= l < num_links: - * i = links[l*2] # <<<<<<<<<<<<<< - * j = links[l*2+1] - * if i >= I or j >= J: - */ - __pyx_v_i = (__pyx_v_links[(__pyx_v_l * 2)]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":122 - * for l from 0 <= l < num_links: - * i = links[l*2] - * j = links[l*2+1] # <<<<<<<<<<<<<< - * if i >= I or j >= J: - * raise Exception("%d-%d out of bounds (I=%d,J=%d) in line %d\n" % (i,j,I,J,sent_id+1)) - */ - __pyx_v_j = (__pyx_v_links[((__pyx_v_l * 2) + 1)]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":123 - * i = links[l*2] - * j = links[l*2+1] - * if i >= I or j >= J: # <<<<<<<<<<<<<< - * raise Exception("%d-%d out of bounds (I=%d,J=%d) in line %d\n" % (i,j,I,J,sent_id+1)) - * f_i = fsent[i] - */ - __pyx_t_8 = (__pyx_v_i >= __pyx_v_I); - if (!__pyx_t_8) { - __pyx_t_9 = (__pyx_v_j >= __pyx_v_J); - __pyx_t_10 = __pyx_t_9; - } else { - __pyx_t_10 = __pyx_t_8; - } - if (__pyx_t_10) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":124 - * j = links[l*2+1] - * if i >= I or j >= J: - * raise Exception("%d-%d out of bounds (I=%d,J=%d) in line %d\n" % (i,j,I,J,sent_id+1)) # <<<<<<<<<<<<<< - * f_i = fsent[i] - * e_j = esent[j] - */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyInt_FromLong(__pyx_v_j); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyInt_FromLong(__pyx_v_I); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_11 = PyInt_FromLong(__pyx_v_J); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_12 = PyInt_FromLong((__pyx_v_sent_id + 1)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_13 = PyTuple_New(5); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_t_11); - __Pyx_GIVEREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_13, 4, __pyx_t_12); - __Pyx_GIVEREF(__pyx_t_12); - __pyx_t_1 = 0; - __pyx_t_4 = 0; - __pyx_t_5 = 0; - __pyx_t_11 = 0; - __pyx_t_12 = 0; - __pyx_t_12 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_39), ((PyObject *)__pyx_t_13)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_12)); - __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; - __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - PyTuple_SET_ITEM(__pyx_t_13, 0, ((PyObject *)__pyx_t_12)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_12)); - __pyx_t_12 = 0; - __pyx_t_12 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; - __Pyx_Raise(__pyx_t_12, 0, 0, 0); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L15; - } - __pyx_L15:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":125 - * if i >= I or j >= J: - * raise Exception("%d-%d out of bounds (I=%d,J=%d) in line %d\n" % (i,j,I,J,sent_id+1)) - * f_i = fsent[i] # <<<<<<<<<<<<<< - * e_j = esent[j] - * fmargin[f_i] = fmargin[f_i]+1 - */ - __pyx_v_f_i = (__pyx_v_fsent[__pyx_v_i]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":126 - * raise Exception("%d-%d out of bounds (I=%d,J=%d) in line %d\n" % (i,j,I,J,sent_id+1)) - * f_i = fsent[i] - * e_j = esent[j] # <<<<<<<<<<<<<< - * fmargin[f_i] = fmargin[f_i]+1 - * emargin[e_j] = emargin[e_j]+1 - */ - __pyx_v_e_j = (__pyx_v_esent[__pyx_v_j]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":127 - * f_i = fsent[i] - * e_j = esent[j] - * fmargin[f_i] = fmargin[f_i]+1 # <<<<<<<<<<<<<< - * emargin[e_j] = emargin[e_j]+1 - * if dict[f_i] == NULL: - */ - (__pyx_v_fmargin[__pyx_v_f_i]) = ((__pyx_v_fmargin[__pyx_v_f_i]) + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":128 - * e_j = esent[j] - * fmargin[f_i] = fmargin[f_i]+1 - * emargin[e_j] = emargin[e_j]+1 # <<<<<<<<<<<<<< - * if dict[f_i] == NULL: - * dict[f_i] = new_node(e_j) - */ - (__pyx_v_emargin[__pyx_v_e_j]) = ((__pyx_v_emargin[__pyx_v_e_j]) + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":129 - * fmargin[f_i] = fmargin[f_i]+1 - * emargin[e_j] = emargin[e_j]+1 - * if dict[f_i] == NULL: # <<<<<<<<<<<<<< - * dict[f_i] = new_node(e_j) - * dict[f_i].val = 1 - */ - __pyx_t_10 = ((__pyx_v_dict[__pyx_v_f_i]) == NULL); - if (__pyx_t_10) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":130 - * emargin[e_j] = emargin[e_j]+1 - * if dict[f_i] == NULL: - * dict[f_i] = new_node(e_j) # <<<<<<<<<<<<<< - * dict[f_i].val = 1 - * num_pairs = num_pairs + 1 - */ - (__pyx_v_dict[__pyx_v_f_i]) = __pyx_f_8_cdec_sa_new_node(__pyx_v_e_j); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":131 - * if dict[f_i] == NULL: - * dict[f_i] = new_node(e_j) - * dict[f_i].val = 1 # <<<<<<<<<<<<<< - * num_pairs = num_pairs + 1 - * else: - */ - (__pyx_v_dict[__pyx_v_f_i])->val = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":132 - * dict[f_i] = new_node(e_j) - * dict[f_i].val = 1 - * num_pairs = num_pairs + 1 # <<<<<<<<<<<<<< - * else: - * count = get_val(dict[f_i], e_j) - */ - __pyx_v_num_pairs = (__pyx_v_num_pairs + 1); - goto __pyx_L16; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":134 - * num_pairs = num_pairs + 1 - * else: - * count = get_val(dict[f_i], e_j) # <<<<<<<<<<<<<< - * if count[0] == 0: - * num_pairs = num_pairs + 1 - */ - __pyx_v_count = __pyx_f_8_cdec_sa_get_val((__pyx_v_dict[__pyx_v_f_i]), __pyx_v_e_j); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":135 - * else: - * count = get_val(dict[f_i], e_j) - * if count[0] == 0: # <<<<<<<<<<<<<< - * num_pairs = num_pairs + 1 - * count[0] = count[0] + 1 - */ - __pyx_t_10 = ((__pyx_v_count[0]) == 0); - if (__pyx_t_10) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":136 - * count = get_val(dict[f_i], e_j) - * if count[0] == 0: - * num_pairs = num_pairs + 1 # <<<<<<<<<<<<<< - * count[0] = count[0] + 1 - * # add count - */ - __pyx_v_num_pairs = (__pyx_v_num_pairs + 1); - goto __pyx_L17; - } - __pyx_L17:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":137 - * if count[0] == 0: - * num_pairs = num_pairs + 1 - * count[0] = count[0] + 1 # <<<<<<<<<<<<<< - * # add count - * faligned[i] = 1 - */ - (__pyx_v_count[0]) = ((__pyx_v_count[0]) + 1); - } - __pyx_L16:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":139 - * count[0] = count[0] + 1 - * # add count - * faligned[i] = 1 # <<<<<<<<<<<<<< - * ealigned[j] = 1 - * for i from 0 <= i < I: - */ - (__pyx_v_faligned[__pyx_v_i]) = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":140 - * # add count - * faligned[i] = 1 - * ealigned[j] = 1 # <<<<<<<<<<<<<< - * for i from 0 <= i < I: - * if faligned[i] == 0: - */ - (__pyx_v_ealigned[__pyx_v_j]) = 1; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":141 - * faligned[i] = 1 - * ealigned[j] = 1 - * for i from 0 <= i < I: # <<<<<<<<<<<<<< - * if faligned[i] == 0: - * f_i = fsent[i] - */ - __pyx_t_7 = __pyx_v_I; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_7; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":142 - * ealigned[j] = 1 - * for i from 0 <= i < I: - * if faligned[i] == 0: # <<<<<<<<<<<<<< - * f_i = fsent[i] - * fmargin[f_i] = fmargin[f_i] + 1 - */ - __pyx_t_10 = ((__pyx_v_faligned[__pyx_v_i]) == 0); - if (__pyx_t_10) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":143 - * for i from 0 <= i < I: - * if faligned[i] == 0: - * f_i = fsent[i] # <<<<<<<<<<<<<< - * fmargin[f_i] = fmargin[f_i] + 1 - * emargin[null_word] = emargin[null_word] + 1 - */ - __pyx_v_f_i = (__pyx_v_fsent[__pyx_v_i]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":144 - * if faligned[i] == 0: - * f_i = fsent[i] - * fmargin[f_i] = fmargin[f_i] + 1 # <<<<<<<<<<<<<< - * emargin[null_word] = emargin[null_word] + 1 - * if dict[f_i] == NULL: - */ - (__pyx_v_fmargin[__pyx_v_f_i]) = ((__pyx_v_fmargin[__pyx_v_f_i]) + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":145 - * f_i = fsent[i] - * fmargin[f_i] = fmargin[f_i] + 1 - * emargin[null_word] = emargin[null_word] + 1 # <<<<<<<<<<<<<< - * if dict[f_i] == NULL: - * dict[f_i] = new_node(null_word) - */ - (__pyx_v_emargin[__pyx_v_null_word]) = ((__pyx_v_emargin[__pyx_v_null_word]) + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":146 - * fmargin[f_i] = fmargin[f_i] + 1 - * emargin[null_word] = emargin[null_word] + 1 - * if dict[f_i] == NULL: # <<<<<<<<<<<<<< - * dict[f_i] = new_node(null_word) - * dict[f_i].val = 1 - */ - __pyx_t_10 = ((__pyx_v_dict[__pyx_v_f_i]) == NULL); - if (__pyx_t_10) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":147 - * emargin[null_word] = emargin[null_word] + 1 - * if dict[f_i] == NULL: - * dict[f_i] = new_node(null_word) # <<<<<<<<<<<<<< - * dict[f_i].val = 1 - * num_pairs = num_pairs + 1 - */ - (__pyx_v_dict[__pyx_v_f_i]) = __pyx_f_8_cdec_sa_new_node(__pyx_v_null_word); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":148 - * if dict[f_i] == NULL: - * dict[f_i] = new_node(null_word) - * dict[f_i].val = 1 # <<<<<<<<<<<<<< - * num_pairs = num_pairs + 1 - * else: - */ - (__pyx_v_dict[__pyx_v_f_i])->val = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":149 - * dict[f_i] = new_node(null_word) - * dict[f_i].val = 1 - * num_pairs = num_pairs + 1 # <<<<<<<<<<<<<< - * else: - * count = get_val(dict[f_i], null_word) - */ - __pyx_v_num_pairs = (__pyx_v_num_pairs + 1); - goto __pyx_L21; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":151 - * num_pairs = num_pairs + 1 - * else: - * count = get_val(dict[f_i], null_word) # <<<<<<<<<<<<<< - * if count[0] == 0: - * num_pairs = num_pairs + 1 - */ - __pyx_v_count = __pyx_f_8_cdec_sa_get_val((__pyx_v_dict[__pyx_v_f_i]), __pyx_v_null_word); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":152 - * else: - * count = get_val(dict[f_i], null_word) - * if count[0] == 0: # <<<<<<<<<<<<<< - * num_pairs = num_pairs + 1 - * count[0] = count[0] + 1 - */ - __pyx_t_10 = ((__pyx_v_count[0]) == 0); - if (__pyx_t_10) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":153 - * count = get_val(dict[f_i], null_word) - * if count[0] == 0: - * num_pairs = num_pairs + 1 # <<<<<<<<<<<<<< - * count[0] = count[0] + 1 - * for j from 0 <= j < J: - */ - __pyx_v_num_pairs = (__pyx_v_num_pairs + 1); - goto __pyx_L22; - } - __pyx_L22:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":154 - * if count[0] == 0: - * num_pairs = num_pairs + 1 - * count[0] = count[0] + 1 # <<<<<<<<<<<<<< - * for j from 0 <= j < J: - * if ealigned[j] == 0: - */ - (__pyx_v_count[0]) = ((__pyx_v_count[0]) + 1); - } - __pyx_L21:; - goto __pyx_L20; - } - __pyx_L20:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":155 - * num_pairs = num_pairs + 1 - * count[0] = count[0] + 1 - * for j from 0 <= j < J: # <<<<<<<<<<<<<< - * if ealigned[j] == 0: - * e_j = esent[j] - */ - __pyx_t_7 = __pyx_v_J; - for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_7; __pyx_v_j++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":156 - * count[0] = count[0] + 1 - * for j from 0 <= j < J: - * if ealigned[j] == 0: # <<<<<<<<<<<<<< - * e_j = esent[j] - * fmargin[null_word] = fmargin[null_word] + 1 - */ - __pyx_t_10 = ((__pyx_v_ealigned[__pyx_v_j]) == 0); - if (__pyx_t_10) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":157 - * for j from 0 <= j < J: - * if ealigned[j] == 0: - * e_j = esent[j] # <<<<<<<<<<<<<< - * fmargin[null_word] = fmargin[null_word] + 1 - * emargin[e_j] = emargin[e_j] + 1 - */ - __pyx_v_e_j = (__pyx_v_esent[__pyx_v_j]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":158 - * if ealigned[j] == 0: - * e_j = esent[j] - * fmargin[null_word] = fmargin[null_word] + 1 # <<<<<<<<<<<<<< - * emargin[e_j] = emargin[e_j] + 1 - * if dict[null_word] == NULL: - */ - (__pyx_v_fmargin[__pyx_v_null_word]) = ((__pyx_v_fmargin[__pyx_v_null_word]) + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":159 - * e_j = esent[j] - * fmargin[null_word] = fmargin[null_word] + 1 - * emargin[e_j] = emargin[e_j] + 1 # <<<<<<<<<<<<<< - * if dict[null_word] == NULL: - * dict[null_word] = new_node(e_j) - */ - (__pyx_v_emargin[__pyx_v_e_j]) = ((__pyx_v_emargin[__pyx_v_e_j]) + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":160 - * fmargin[null_word] = fmargin[null_word] + 1 - * emargin[e_j] = emargin[e_j] + 1 - * if dict[null_word] == NULL: # <<<<<<<<<<<<<< - * dict[null_word] = new_node(e_j) - * dict[null_word].val = 1 - */ - __pyx_t_10 = ((__pyx_v_dict[__pyx_v_null_word]) == NULL); - if (__pyx_t_10) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":161 - * emargin[e_j] = emargin[e_j] + 1 - * if dict[null_word] == NULL: - * dict[null_word] = new_node(e_j) # <<<<<<<<<<<<<< - * dict[null_word].val = 1 - * num_pairs = num_pairs + 1 - */ - (__pyx_v_dict[__pyx_v_null_word]) = __pyx_f_8_cdec_sa_new_node(__pyx_v_e_j); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":162 - * if dict[null_word] == NULL: - * dict[null_word] = new_node(e_j) - * dict[null_word].val = 1 # <<<<<<<<<<<<<< - * num_pairs = num_pairs + 1 - * else: - */ - (__pyx_v_dict[__pyx_v_null_word])->val = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":163 - * dict[null_word] = new_node(e_j) - * dict[null_word].val = 1 - * num_pairs = num_pairs + 1 # <<<<<<<<<<<<<< - * else: - * count = get_val(dict[null_word], e_j) - */ - __pyx_v_num_pairs = (__pyx_v_num_pairs + 1); - goto __pyx_L26; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":165 - * num_pairs = num_pairs + 1 - * else: - * count = get_val(dict[null_word], e_j) # <<<<<<<<<<<<<< - * if count[0] == 0: - * num_pairs = num_pairs + 1 - */ - __pyx_v_count = __pyx_f_8_cdec_sa_get_val((__pyx_v_dict[__pyx_v_null_word]), __pyx_v_e_j); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":166 - * else: - * count = get_val(dict[null_word], e_j) - * if count[0] == 0: # <<<<<<<<<<<<<< - * num_pairs = num_pairs + 1 - * count[0] = count[0] + 1 - */ - __pyx_t_10 = ((__pyx_v_count[0]) == 0); - if (__pyx_t_10) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":167 - * count = get_val(dict[null_word], e_j) - * if count[0] == 0: - * num_pairs = num_pairs + 1 # <<<<<<<<<<<<<< - * count[0] = count[0] + 1 - * free(links) - */ - __pyx_v_num_pairs = (__pyx_v_num_pairs + 1); - goto __pyx_L27; - } - __pyx_L27:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":168 - * if count[0] == 0: - * num_pairs = num_pairs + 1 - * count[0] = count[0] + 1 # <<<<<<<<<<<<<< - * free(links) - * free(faligned) - */ - (__pyx_v_count[0]) = ((__pyx_v_count[0]) + 1); - } - __pyx_L26:; - goto __pyx_L25; - } - __pyx_L25:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":169 - * num_pairs = num_pairs + 1 - * count[0] = count[0] + 1 - * free(links) # <<<<<<<<<<<<<< - * free(faligned) - * free(ealigned) - */ - free(__pyx_v_links); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":170 - * count[0] = count[0] + 1 - * free(links) - * free(faligned) # <<<<<<<<<<<<<< - * free(ealigned) - * self.f_index = IntList(initial_len=V_F) - */ - free(__pyx_v_faligned); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":171 - * free(links) - * free(faligned) - * free(ealigned) # <<<<<<<<<<<<<< - * self.f_index = IntList(initial_len=V_F) - * self.e_index = IntList(initial_len=num_pairs) - */ - free(__pyx_v_ealigned); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":172 - * free(faligned) - * free(ealigned) - * self.f_index = IntList(initial_len=V_F) # <<<<<<<<<<<<<< - * self.e_index = IntList(initial_len=num_pairs) - * self.col1 = FloatList(initial_len=num_pairs) - */ - __pyx_t_12 = PyDict_New(); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_12)); - __pyx_t_13 = PyInt_FromLong(__pyx_v_V_F); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - if (PyDict_SetItem(__pyx_t_12, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_13) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_13 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_12)); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; - __Pyx_GIVEREF(__pyx_t_13); - __Pyx_GOTREF(__pyx_v_self->f_index); - __Pyx_DECREF(((PyObject *)__pyx_v_self->f_index)); - __pyx_v_self->f_index = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_13); - __pyx_t_13 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":173 - * free(ealigned) - * self.f_index = IntList(initial_len=V_F) - * self.e_index = IntList(initial_len=num_pairs) # <<<<<<<<<<<<<< - * self.col1 = FloatList(initial_len=num_pairs) - * self.col2 = FloatList(initial_len=num_pairs) - */ - __pyx_t_13 = PyDict_New(); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_13)); - __pyx_t_12 = PyInt_FromLong(__pyx_v_num_pairs); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - if (PyDict_SetItem(__pyx_t_13, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_12) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_13)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; - __Pyx_GIVEREF(__pyx_t_12); - __Pyx_GOTREF(__pyx_v_self->e_index); - __Pyx_DECREF(((PyObject *)__pyx_v_self->e_index)); - __pyx_v_self->e_index = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_12); - __pyx_t_12 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":174 - * self.f_index = IntList(initial_len=V_F) - * self.e_index = IntList(initial_len=num_pairs) - * self.col1 = FloatList(initial_len=num_pairs) # <<<<<<<<<<<<<< - * self.col2 = FloatList(initial_len=num_pairs) - * - */ - __pyx_t_12 = PyDict_New(); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_12)); - __pyx_t_13 = PyInt_FromLong(__pyx_v_num_pairs); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - if (PyDict_SetItem(__pyx_t_12, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_13) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_13 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_FloatList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_12)); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; - __Pyx_GIVEREF(__pyx_t_13); - __Pyx_GOTREF(__pyx_v_self->col1); - __Pyx_DECREF(((PyObject *)__pyx_v_self->col1)); - __pyx_v_self->col1 = ((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_t_13); - __pyx_t_13 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":175 - * self.e_index = IntList(initial_len=num_pairs) - * self.col1 = FloatList(initial_len=num_pairs) - * self.col2 = FloatList(initial_len=num_pairs) # <<<<<<<<<<<<<< - * - * num_pairs = 0 - */ - __pyx_t_13 = PyDict_New(); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_13)); - __pyx_t_12 = PyInt_FromLong(__pyx_v_num_pairs); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - if (PyDict_SetItem(__pyx_t_13, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_12) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_FloatList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_13)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; - __Pyx_GIVEREF(__pyx_t_12); - __Pyx_GOTREF(__pyx_v_self->col2); - __Pyx_DECREF(((PyObject *)__pyx_v_self->col2)); - __pyx_v_self->col2 = ((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_t_12); - __pyx_t_12 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":177 - * self.col2 = FloatList(initial_len=num_pairs) - * - * num_pairs = 0 # <<<<<<<<<<<<<< - * for i from 0 <= i < V_F: - * #self.f_index[i] = num_pairs - */ - __pyx_v_num_pairs = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":178 - * - * num_pairs = 0 - * for i from 0 <= i < V_F: # <<<<<<<<<<<<<< - * #self.f_index[i] = num_pairs - * self.f_index.set(i, num_pairs) - */ - __pyx_t_6 = __pyx_v_V_F; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_6; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":180 - * for i from 0 <= i < V_F: - * #self.f_index[i] = num_pairs - * self.f_index.set(i, num_pairs) # <<<<<<<<<<<<<< - * if dict[i] != NULL: - * self._add_node(dict[i], &num_pairs, float(fmargin[i]), emargin) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->f_index->__pyx_vtab)->set(__pyx_v_self->f_index, __pyx_v_i, __pyx_v_num_pairs); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":181 - * #self.f_index[i] = num_pairs - * self.f_index.set(i, num_pairs) - * if dict[i] != NULL: # <<<<<<<<<<<<<< - * self._add_node(dict[i], &num_pairs, float(fmargin[i]), emargin) - * del_node(dict[i]) - */ - __pyx_t_10 = ((__pyx_v_dict[__pyx_v_i]) != NULL); - if (__pyx_t_10) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":182 - * self.f_index.set(i, num_pairs) - * if dict[i] != NULL: - * self._add_node(dict[i], &num_pairs, float(fmargin[i]), emargin) # <<<<<<<<<<<<<< - * del_node(dict[i]) - * free(fmargin) - */ - __pyx_t_12 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->_add_node(__pyx_v_self, (__pyx_v_dict[__pyx_v_i]), (&__pyx_v_num_pairs), ((double)(__pyx_v_fmargin[__pyx_v_i])), __pyx_v_emargin); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":183 - * if dict[i] != NULL: - * self._add_node(dict[i], &num_pairs, float(fmargin[i]), emargin) - * del_node(dict[i]) # <<<<<<<<<<<<<< - * free(fmargin) - * free(emargin) - */ - __pyx_t_12 = __pyx_f_8_cdec_sa_del_node((__pyx_v_dict[__pyx_v_i])); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - goto __pyx_L30; - } - __pyx_L30:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":184 - * self._add_node(dict[i], &num_pairs, float(fmargin[i]), emargin) - * del_node(dict[i]) - * free(fmargin) # <<<<<<<<<<<<<< - * free(emargin) - * free(dict) - */ - free(__pyx_v_fmargin); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":185 - * del_node(dict[i]) - * free(fmargin) - * free(emargin) # <<<<<<<<<<<<<< - * free(dict) - * return - */ - free(__pyx_v_emargin); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":186 - * free(fmargin) - * free(emargin) - * free(dict) # <<<<<<<<<<<<<< - * return - * - */ - free(__pyx_v_dict); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":187 - * free(emargin) - * free(dict) - * return # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - 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_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_XDECREF(__pyx_t_13); - __Pyx_AddTraceback("_cdec_sa.BiLex.compute_from_data", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_word); - __Pyx_XDECREF(__pyx_v_id); - __Pyx_XDECREF(__pyx_v_num_sents); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":190 - * - * - * cdef _add_node(self, _node* n, int* num_pairs, float fmargin, int* emargin): # <<<<<<<<<<<<<< - * cdef int loc - * if n.smaller != NULL: - */ - -static PyObject *__pyx_f_8_cdec_sa_5BiLex__add_node(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, struct __pyx_t_8_cdec_sa__node *__pyx_v_n, int *__pyx_v_num_pairs, float __pyx_v_fmargin, int *__pyx_v_emargin) { - int __pyx_v_loc; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("_add_node", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":192 - * cdef _add_node(self, _node* n, int* num_pairs, float fmargin, int* emargin): - * cdef int loc - * if n.smaller != NULL: # <<<<<<<<<<<<<< - * self._add_node(n.smaller, num_pairs, fmargin, emargin) - * loc = num_pairs[0] - */ - __pyx_t_1 = (__pyx_v_n->smaller != NULL); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":193 - * cdef int loc - * if n.smaller != NULL: - * self._add_node(n.smaller, num_pairs, fmargin, emargin) # <<<<<<<<<<<<<< - * loc = num_pairs[0] - * self.e_index.set(loc, n.key) - */ - __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->_add_node(__pyx_v_self, __pyx_v_n->smaller, __pyx_v_num_pairs, __pyx_v_fmargin, __pyx_v_emargin); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":194 - * if n.smaller != NULL: - * self._add_node(n.smaller, num_pairs, fmargin, emargin) - * loc = num_pairs[0] # <<<<<<<<<<<<<< - * self.e_index.set(loc, n.key) - * self.col1.set(loc, float(n.val)/fmargin) - */ - __pyx_v_loc = (__pyx_v_num_pairs[0]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":195 - * self._add_node(n.smaller, num_pairs, fmargin, emargin) - * loc = num_pairs[0] - * self.e_index.set(loc, n.key) # <<<<<<<<<<<<<< - * self.col1.set(loc, float(n.val)/fmargin) - * self.col2.set(loc, float(n.val)/float(emargin[n.key])) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->e_index->__pyx_vtab)->set(__pyx_v_self->e_index, __pyx_v_loc, __pyx_v_n->key); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":196 - * loc = num_pairs[0] - * self.e_index.set(loc, n.key) - * self.col1.set(loc, float(n.val)/fmargin) # <<<<<<<<<<<<<< - * self.col2.set(loc, float(n.val)/float(emargin[n.key])) - * num_pairs[0] = loc + 1 - */ - if (unlikely(__pyx_v_fmargin == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - ((struct __pyx_vtabstruct_8_cdec_sa_FloatList *)__pyx_v_self->col1->__pyx_vtab)->set(__pyx_v_self->col1, __pyx_v_loc, (((double)__pyx_v_n->val) / __pyx_v_fmargin)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":197 - * self.e_index.set(loc, n.key) - * self.col1.set(loc, float(n.val)/fmargin) - * self.col2.set(loc, float(n.val)/float(emargin[n.key])) # <<<<<<<<<<<<<< - * num_pairs[0] = loc + 1 - * if n.bigger != NULL: - */ - if (unlikely(((double)(__pyx_v_emargin[__pyx_v_n->key])) == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - ((struct __pyx_vtabstruct_8_cdec_sa_FloatList *)__pyx_v_self->col2->__pyx_vtab)->set(__pyx_v_self->col2, __pyx_v_loc, (((double)__pyx_v_n->val) / ((double)(__pyx_v_emargin[__pyx_v_n->key])))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":198 - * self.col1.set(loc, float(n.val)/fmargin) - * self.col2.set(loc, float(n.val)/float(emargin[n.key])) - * num_pairs[0] = loc + 1 # <<<<<<<<<<<<<< - * if n.bigger != NULL: - * self._add_node(n.bigger, num_pairs, fmargin, emargin) - */ - (__pyx_v_num_pairs[0]) = (__pyx_v_loc + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":199 - * self.col2.set(loc, float(n.val)/float(emargin[n.key])) - * num_pairs[0] = loc + 1 - * if n.bigger != NULL: # <<<<<<<<<<<<<< - * self._add_node(n.bigger, num_pairs, fmargin, emargin) - * - */ - __pyx_t_1 = (__pyx_v_n->bigger != NULL); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":200 - * num_pairs[0] = loc + 1 - * if n.bigger != NULL: - * self._add_node(n.bigger, num_pairs, fmargin, emargin) # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->_add_node(__pyx_v_self, __pyx_v_n->bigger, __pyx_v_num_pairs, __pyx_v_fmargin, __pyx_v_emargin); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L4; - } - __pyx_L4:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_cdec_sa.BiLex._add_node", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_5BiLex_3write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_5BiLex_3write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_binary (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.BiLex.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_5BiLex_2write_binary(((struct __pyx_obj_8_cdec_sa_BiLex *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":203 - * - * - * def write_binary(self, char* filename): # <<<<<<<<<<<<<< - * cdef FILE* f - * f = fopen(filename, "w") - */ - -static PyObject *__pyx_pf_8_cdec_sa_5BiLex_2write_binary(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename) { - FILE *__pyx_v_f; - 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("write_binary", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":205 - * def write_binary(self, char* filename): - * cdef FILE* f - * f = fopen(filename, "w") # <<<<<<<<<<<<<< - * self.f_index.write_handle(f) - * self.e_index.write_handle(f) - */ - __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":206 - * cdef FILE* f - * f = fopen(filename, "w") - * self.f_index.write_handle(f) # <<<<<<<<<<<<<< - * self.e_index.write_handle(f) - * self.col1.write_handle(f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->f_index->__pyx_vtab)->write_handle(__pyx_v_self->f_index, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":207 - * f = fopen(filename, "w") - * self.f_index.write_handle(f) - * self.e_index.write_handle(f) # <<<<<<<<<<<<<< - * self.col1.write_handle(f) - * self.col2.write_handle(f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->e_index->__pyx_vtab)->write_handle(__pyx_v_self->e_index, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":208 - * self.f_index.write_handle(f) - * self.e_index.write_handle(f) - * self.col1.write_handle(f) # <<<<<<<<<<<<<< - * self.col2.write_handle(f) - * self.write_wordlist(self.id2fword, f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_FloatList *)__pyx_v_self->col1->__pyx_vtab)->write_handle(__pyx_v_self->col1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":209 - * self.e_index.write_handle(f) - * self.col1.write_handle(f) - * self.col2.write_handle(f) # <<<<<<<<<<<<<< - * self.write_wordlist(self.id2fword, f) - * self.write_wordlist(self.id2eword, f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_FloatList *)__pyx_v_self->col2->__pyx_vtab)->write_handle(__pyx_v_self->col2, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":210 - * self.col1.write_handle(f) - * self.col2.write_handle(f) - * self.write_wordlist(self.id2fword, f) # <<<<<<<<<<<<<< - * self.write_wordlist(self.id2eword, f) - * fclose(f) - */ - __pyx_t_1 = __pyx_v_self->id2fword; - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->write_wordlist(__pyx_v_self, __pyx_t_1, __pyx_v_f); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":211 - * self.col2.write_handle(f) - * self.write_wordlist(self.id2fword, f) - * self.write_wordlist(self.id2eword, f) # <<<<<<<<<<<<<< - * fclose(f) - * - */ - __pyx_t_2 = __pyx_v_self->id2eword; - __Pyx_INCREF(__pyx_t_2); - __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->write_wordlist(__pyx_v_self, __pyx_t_2, __pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":212 - * self.write_wordlist(self.id2fword, f) - * self.write_wordlist(self.id2eword, f) - * fclose(f) # <<<<<<<<<<<<<< - * - * - */ - fclose(__pyx_v_f); - - __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_sa.BiLex.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":215 - * - * - * cdef write_wordlist(self, wordlist, FILE* f): # <<<<<<<<<<<<<< - * cdef int word_len - * cdef int num_words - */ - -static PyObject *__pyx_f_8_cdec_sa_5BiLex_write_wordlist(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_wordlist, FILE *__pyx_v_f) { - int __pyx_v_word_len; - int __pyx_v_num_words; - char *__pyx_v_c_word; - PyObject *__pyx_v_word = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - Py_ssize_t __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *(*__pyx_t_3)(PyObject *); - PyObject *__pyx_t_4 = NULL; - char *__pyx_t_5; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("write_wordlist", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":220 - * cdef char* c_word - * - * num_words = len(wordlist) # <<<<<<<<<<<<<< - * fwrite(&(num_words), sizeof(int), 1, f) - * for word in wordlist: - */ - __pyx_t_1 = PyObject_Length(__pyx_v_wordlist); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_num_words = __pyx_t_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":221 - * - * num_words = len(wordlist) - * fwrite(&(num_words), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * for word in wordlist: - * c_word = word - */ - fwrite((&__pyx_v_num_words), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":222 - * num_words = len(wordlist) - * fwrite(&(num_words), sizeof(int), 1, f) - * for word in wordlist: # <<<<<<<<<<<<<< - * c_word = word - * word_len = strlen(c_word) + 1 - */ - if (PyList_CheckExact(__pyx_v_wordlist) || PyTuple_CheckExact(__pyx_v_wordlist)) { - __pyx_t_2 = __pyx_v_wordlist; __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = 0; - __pyx_t_3 = NULL; - } else { - __pyx_t_1 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_wordlist); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = Py_TYPE(__pyx_t_2)->tp_iternext; - } - for (;;) { - if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_2)) { - if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_2)) break; - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_1); __Pyx_INCREF(__pyx_t_4); __pyx_t_1++; - } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_2)) { - if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_1); __Pyx_INCREF(__pyx_t_4); __pyx_t_1++; - } else { - __pyx_t_4 = __pyx_t_3(__pyx_t_2); - if (unlikely(!__pyx_t_4)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XDECREF(__pyx_v_word); - __pyx_v_word = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":223 - * fwrite(&(num_words), sizeof(int), 1, f) - * for word in wordlist: - * c_word = word # <<<<<<<<<<<<<< - * word_len = strlen(c_word) + 1 - * fwrite(&(word_len), sizeof(int), 1, f) - */ - __pyx_t_5 = PyBytes_AsString(__pyx_v_word); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_c_word = __pyx_t_5; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":224 - * for word in wordlist: - * c_word = word - * word_len = strlen(c_word) + 1 # <<<<<<<<<<<<<< - * fwrite(&(word_len), sizeof(int), 1, f) - * fwrite(c_word, sizeof(char), word_len, f) - */ - __pyx_v_word_len = (strlen(__pyx_v_c_word) + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":225 - * c_word = word - * word_len = strlen(c_word) + 1 - * fwrite(&(word_len), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * fwrite(c_word, sizeof(char), word_len, f) - * - */ - fwrite((&__pyx_v_word_len), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":226 - * word_len = strlen(c_word) + 1 - * fwrite(&(word_len), sizeof(int), 1, f) - * fwrite(c_word, sizeof(char), word_len, f) # <<<<<<<<<<<<<< - * - * - */ - fwrite(__pyx_v_c_word, (sizeof(char)), __pyx_v_word_len, __pyx_v_f); - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec_sa.BiLex.write_wordlist", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_word); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":229 - * - * - * cdef read_wordlist(self, word2id, id2word, FILE* f): # <<<<<<<<<<<<<< - * cdef int num_words - * cdef int word_len - */ - -static PyObject *__pyx_f_8_cdec_sa_5BiLex_read_wordlist(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_word2id, PyObject *__pyx_v_id2word, FILE *__pyx_v_f) { - int __pyx_v_num_words; - int __pyx_v_word_len; - char *__pyx_v_c_word; - PyObject *__pyx_v_py_word = 0; - CYTHON_UNUSED long __pyx_v_i; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - Py_ssize_t __pyx_t_3; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("read_wordlist", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":235 - * cdef bytes py_word - * - * fread(&(num_words), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * for i from 0 <= i < num_words: - * fread(&(word_len), sizeof(int), 1, f) - */ - fread((&__pyx_v_num_words), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":236 - * - * fread(&(num_words), sizeof(int), 1, f) - * for i from 0 <= i < num_words: # <<<<<<<<<<<<<< - * fread(&(word_len), sizeof(int), 1, f) - * c_word = malloc (word_len * sizeof(char)) - */ - __pyx_t_1 = __pyx_v_num_words; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":237 - * fread(&(num_words), sizeof(int), 1, f) - * for i from 0 <= i < num_words: - * fread(&(word_len), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * c_word = malloc (word_len * sizeof(char)) - * fread(c_word, sizeof(char), word_len, f) - */ - fread((&__pyx_v_word_len), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":238 - * for i from 0 <= i < num_words: - * fread(&(word_len), sizeof(int), 1, f) - * c_word = malloc (word_len * sizeof(char)) # <<<<<<<<<<<<<< - * fread(c_word, sizeof(char), word_len, f) - * py_word = c_word - */ - __pyx_v_c_word = ((char *)malloc((__pyx_v_word_len * (sizeof(char))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":239 - * fread(&(word_len), sizeof(int), 1, f) - * c_word = malloc (word_len * sizeof(char)) - * fread(c_word, sizeof(char), word_len, f) # <<<<<<<<<<<<<< - * py_word = c_word - * free(c_word) - */ - fread(__pyx_v_c_word, (sizeof(char)), __pyx_v_word_len, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":240 - * c_word = malloc (word_len * sizeof(char)) - * fread(c_word, sizeof(char), word_len, f) - * py_word = c_word # <<<<<<<<<<<<<< - * free(c_word) - * word2id[py_word] = len(id2word) - */ - __pyx_t_2 = PyBytes_FromString(__pyx_v_c_word); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 240; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __Pyx_XDECREF(((PyObject *)__pyx_v_py_word)); - __pyx_v_py_word = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":241 - * fread(c_word, sizeof(char), word_len, f) - * py_word = c_word - * free(c_word) # <<<<<<<<<<<<<< - * word2id[py_word] = len(id2word) - * id2word.append(py_word) - */ - free(__pyx_v_c_word); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":242 - * py_word = c_word - * free(c_word) - * word2id[py_word] = len(id2word) # <<<<<<<<<<<<<< - * id2word.append(py_word) - * - */ - __pyx_t_3 = PyObject_Length(__pyx_v_id2word); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - if (PyObject_SetItem(__pyx_v_word2id, ((PyObject *)__pyx_v_py_word), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":243 - * free(c_word) - * word2id[py_word] = len(id2word) - * id2word.append(py_word) # <<<<<<<<<<<<<< - * - * def read_binary(self, char* filename): - */ - __pyx_t_2 = __Pyx_PyObject_Append(__pyx_v_id2word, ((PyObject *)__pyx_v_py_word)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_cdec_sa.BiLex.read_wordlist", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_py_word); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_5BiLex_5read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_5BiLex_5read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_binary (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.BiLex.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_5BiLex_4read_binary(((struct __pyx_obj_8_cdec_sa_BiLex *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":245 - * id2word.append(py_word) - * - * def read_binary(self, char* filename): # <<<<<<<<<<<<<< - * cdef FILE* f - * f = fopen(filename, "r") - */ - -static PyObject *__pyx_pf_8_cdec_sa_5BiLex_4read_binary(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename) { - FILE *__pyx_v_f; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("read_binary", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":247 - * def read_binary(self, char* filename): - * cdef FILE* f - * f = fopen(filename, "r") # <<<<<<<<<<<<<< - * self.f_index.read_handle(f) - * self.e_index.read_handle(f) - */ - __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":248 - * cdef FILE* f - * f = fopen(filename, "r") - * self.f_index.read_handle(f) # <<<<<<<<<<<<<< - * self.e_index.read_handle(f) - * self.col1.read_handle(f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->f_index->__pyx_vtab)->read_handle(__pyx_v_self->f_index, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":249 - * f = fopen(filename, "r") - * self.f_index.read_handle(f) - * self.e_index.read_handle(f) # <<<<<<<<<<<<<< - * self.col1.read_handle(f) - * self.col2.read_handle(f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->e_index->__pyx_vtab)->read_handle(__pyx_v_self->e_index, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":250 - * self.f_index.read_handle(f) - * self.e_index.read_handle(f) - * self.col1.read_handle(f) # <<<<<<<<<<<<<< - * self.col2.read_handle(f) - * self.read_wordlist(self.fword2id, self.id2fword, f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_FloatList *)__pyx_v_self->col1->__pyx_vtab)->read_handle(__pyx_v_self->col1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":251 - * self.e_index.read_handle(f) - * self.col1.read_handle(f) - * self.col2.read_handle(f) # <<<<<<<<<<<<<< - * self.read_wordlist(self.fword2id, self.id2fword, f) - * self.read_wordlist(self.eword2id, self.id2eword, f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_FloatList *)__pyx_v_self->col2->__pyx_vtab)->read_handle(__pyx_v_self->col2, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":252 - * self.col1.read_handle(f) - * self.col2.read_handle(f) - * self.read_wordlist(self.fword2id, self.id2fword, f) # <<<<<<<<<<<<<< - * self.read_wordlist(self.eword2id, self.id2eword, f) - * fclose(f) - */ - __pyx_t_1 = __pyx_v_self->fword2id; - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __pyx_v_self->id2fword; - __Pyx_INCREF(__pyx_t_2); - __pyx_t_3 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->read_wordlist(__pyx_v_self, __pyx_t_1, __pyx_t_2, __pyx_v_f); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":253 - * self.col2.read_handle(f) - * self.read_wordlist(self.fword2id, self.id2fword, f) - * self.read_wordlist(self.eword2id, self.id2eword, f) # <<<<<<<<<<<<<< - * fclose(f) - * - */ - __pyx_t_3 = __pyx_v_self->eword2id; - __Pyx_INCREF(__pyx_t_3); - __pyx_t_2 = __pyx_v_self->id2eword; - __Pyx_INCREF(__pyx_t_2); - __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->read_wordlist(__pyx_v_self, __pyx_t_3, __pyx_t_2, __pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":254 - * self.read_wordlist(self.fword2id, self.id2fword, f) - * self.read_wordlist(self.eword2id, self.id2eword, f) - * fclose(f) # <<<<<<<<<<<<<< - * - * - */ - fclose(__pyx_v_f); - - __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_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.BiLex.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_5BiLex_7get_e_id(PyObject *__pyx_v_self, PyObject *__pyx_v_eword); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_5BiLex_7get_e_id(PyObject *__pyx_v_self, PyObject *__pyx_v_eword) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_e_id (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_5BiLex_6get_e_id(((struct __pyx_obj_8_cdec_sa_BiLex *)__pyx_v_self), ((PyObject *)__pyx_v_eword)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":257 - * - * - * def get_e_id(self, eword): # <<<<<<<<<<<<<< - * if eword not in self.eword2id: - * e_id = len(self.id2eword) - */ - -static PyObject *__pyx_pf_8_cdec_sa_5BiLex_6get_e_id(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_eword) { - PyObject *__pyx_v_e_id = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - Py_ssize_t __pyx_t_3; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get_e_id", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":258 - * - * def get_e_id(self, eword): - * if eword not in self.eword2id: # <<<<<<<<<<<<<< - * e_id = len(self.id2eword) - * self.id2eword.append(eword) - */ - __pyx_t_1 = (__Pyx_NegateNonNeg(PySequence_Contains(__pyx_v_self->eword2id, __pyx_v_eword))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":259 - * def get_e_id(self, eword): - * if eword not in self.eword2id: - * e_id = len(self.id2eword) # <<<<<<<<<<<<<< - * self.id2eword.append(eword) - * self.eword2id[eword] = e_id - */ - __pyx_t_2 = __pyx_v_self->id2eword; - __Pyx_INCREF(__pyx_t_2); - __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_e_id = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":260 - * if eword not in self.eword2id: - * e_id = len(self.id2eword) - * self.id2eword.append(eword) # <<<<<<<<<<<<<< - * self.eword2id[eword] = e_id - * return self.eword2id[eword] - */ - __pyx_t_2 = __Pyx_PyObject_Append(__pyx_v_self->id2eword, __pyx_v_eword); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":261 - * e_id = len(self.id2eword) - * self.id2eword.append(eword) - * self.eword2id[eword] = e_id # <<<<<<<<<<<<<< - * return self.eword2id[eword] - * - */ - if (PyObject_SetItem(__pyx_v_self->eword2id, __pyx_v_eword, __pyx_v_e_id) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":262 - * self.id2eword.append(eword) - * self.eword2id[eword] = e_id - * return self.eword2id[eword] # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyObject_GetItem(__pyx_v_self->eword2id, __pyx_v_eword); if (!__pyx_t_2) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __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_2); - __Pyx_AddTraceback("_cdec_sa.BiLex.get_e_id", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_e_id); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_5BiLex_9get_f_id(PyObject *__pyx_v_self, PyObject *__pyx_v_fword); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_5BiLex_9get_f_id(PyObject *__pyx_v_self, PyObject *__pyx_v_fword) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_f_id (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_5BiLex_8get_f_id(((struct __pyx_obj_8_cdec_sa_BiLex *)__pyx_v_self), ((PyObject *)__pyx_v_fword)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":265 - * - * - * def get_f_id(self, fword): # <<<<<<<<<<<<<< - * if fword not in self.fword2id: - * f_id = len(self.id2fword) - */ - -static PyObject *__pyx_pf_8_cdec_sa_5BiLex_8get_f_id(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_fword) { - PyObject *__pyx_v_f_id = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - Py_ssize_t __pyx_t_3; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get_f_id", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":266 - * - * def get_f_id(self, fword): - * if fword not in self.fword2id: # <<<<<<<<<<<<<< - * f_id = len(self.id2fword) - * self.id2fword.append(fword) - */ - __pyx_t_1 = (__Pyx_NegateNonNeg(PySequence_Contains(__pyx_v_self->fword2id, __pyx_v_fword))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 266; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":267 - * def get_f_id(self, fword): - * if fword not in self.fword2id: - * f_id = len(self.id2fword) # <<<<<<<<<<<<<< - * self.id2fword.append(fword) - * self.fword2id[fword] = f_id - */ - __pyx_t_2 = __pyx_v_self->id2fword; - __Pyx_INCREF(__pyx_t_2); - __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_f_id = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":268 - * if fword not in self.fword2id: - * f_id = len(self.id2fword) - * self.id2fword.append(fword) # <<<<<<<<<<<<<< - * self.fword2id[fword] = f_id - * return self.fword2id[fword] - */ - __pyx_t_2 = __Pyx_PyObject_Append(__pyx_v_self->id2fword, __pyx_v_fword); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":269 - * f_id = len(self.id2fword) - * self.id2fword.append(fword) - * self.fword2id[fword] = f_id # <<<<<<<<<<<<<< - * return self.fword2id[fword] - * - */ - if (PyObject_SetItem(__pyx_v_self->fword2id, __pyx_v_fword, __pyx_v_f_id) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":270 - * self.id2fword.append(fword) - * self.fword2id[fword] = f_id - * return self.fword2id[fword] # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyObject_GetItem(__pyx_v_self->fword2id, __pyx_v_fword); if (!__pyx_t_2) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 270; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __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_2); - __Pyx_AddTraceback("_cdec_sa.BiLex.get_f_id", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_f_id); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_5BiLex_11read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_5BiLex_11read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_text (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.BiLex.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_5BiLex_10read_text(((struct __pyx_obj_8_cdec_sa_BiLex *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":273 - * - * - * def read_text(self, char* filename): # <<<<<<<<<<<<<< - * cdef i, j, w, e_id, f_id, n_f, n_e, N - * cdef IntList fcount - */ - -static PyObject *__pyx_pf_8_cdec_sa_5BiLex_10read_text(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename) { - PyObject *__pyx_v_i = 0; - PyObject *__pyx_v_j = 0; - PyObject *__pyx_v_e_id = 0; - PyObject *__pyx_v_f_id = 0; - PyObject *__pyx_v_n_f = 0; - PyObject *__pyx_v_N = 0; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_fcount = 0; - PyObject *__pyx_v_f = NULL; - PyObject *__pyx_v_line = NULL; - PyObject *__pyx_v_fword = NULL; - PyObject *__pyx_v_eword = NULL; - PyObject *__pyx_v_score1 = NULL; - PyObject *__pyx_v_score2 = NULL; - PyObject *__pyx_v_index = NULL; - PyObject *__pyx_v_b = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - Py_ssize_t __pyx_t_8; - PyObject *(*__pyx_t_9)(PyObject *); - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; - PyObject *__pyx_t_13 = NULL; - PyObject *(*__pyx_t_14)(PyObject *); - Py_ssize_t __pyx_t_15; - int __pyx_t_16; - Py_ssize_t __pyx_t_17; - long __pyx_t_18; - long __pyx_t_19; - int __pyx_t_20; - double __pyx_t_21; - PyObject *__pyx_t_22 = NULL; - int __pyx_t_23; - int __pyx_t_24; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("read_text", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":277 - * cdef IntList fcount - * - * fcount = IntList() # <<<<<<<<<<<<<< - * with gzip_or_text(filename) as f: - * # first loop merely establishes size of array objects - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_fcount = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":278 - * - * fcount = IntList() - * with gzip_or_text(filename) as f: # <<<<<<<<<<<<<< - * # first loop merely establishes size of array objects - * for line in f: - */ - /*with:*/ { - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__gzip_or_text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __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[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__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_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /*try:*/ { - { - __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - /*try:*/ { - __Pyx_INCREF(__pyx_t_1); - __pyx_v_f = __pyx_t_1; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":280 - * with gzip_or_text(filename) as f: - * # first loop merely establishes size of array objects - * for line in f: # <<<<<<<<<<<<<< - * (fword, eword, score1, score2) = line.split() - * f_id = self.get_f_id(fword) - */ - if (PyList_CheckExact(__pyx_v_f) || PyTuple_CheckExact(__pyx_v_f)) { - __pyx_t_1 = __pyx_v_f; __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; - } else { - __pyx_t_2 = __pyx_t_9(__pyx_t_1); - if (unlikely(!__pyx_t_2)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF(__pyx_v_line); - __pyx_v_line = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":281 - * # first loop merely establishes size of array objects - * for line in f: - * (fword, eword, score1, score2) = line.split() # <<<<<<<<<<<<<< - * f_id = self.get_f_id(fword) - * e_id = self.get_e_id(eword) - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { - PyObject* sequence = __pyx_t_3; - if (likely(PyTuple_CheckExact(sequence))) { - if (unlikely(PyTuple_GET_SIZE(sequence) != 4)) { - if (PyTuple_GET_SIZE(sequence) > 4) __Pyx_RaiseTooManyValuesError(4); - else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_11 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_12 = PyTuple_GET_ITEM(sequence, 3); - } else { - if (unlikely(PyList_GET_SIZE(sequence) != 4)) { - if (PyList_GET_SIZE(sequence) > 4) __Pyx_RaiseTooManyValuesError(4); - else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_10 = PyList_GET_ITEM(sequence, 1); - __pyx_t_11 = PyList_GET_ITEM(sequence, 2); - __pyx_t_12 = PyList_GET_ITEM(sequence, 3); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_13 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_14 = Py_TYPE(__pyx_t_13)->tp_iternext; - index = 0; __pyx_t_2 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_2)) goto __pyx_L18_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - index = 1; __pyx_t_10 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_10)) goto __pyx_L18_unpacking_failed; - __Pyx_GOTREF(__pyx_t_10); - index = 2; __pyx_t_11 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_11)) goto __pyx_L18_unpacking_failed; - __Pyx_GOTREF(__pyx_t_11); - index = 3; __pyx_t_12 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_12)) goto __pyx_L18_unpacking_failed; - __Pyx_GOTREF(__pyx_t_12); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_13), 4) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - goto __pyx_L19_unpacking_done; - __pyx_L18_unpacking_failed:; - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_L19_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_fword); - __pyx_v_fword = __pyx_t_2; - __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_v_eword); - __pyx_v_eword = __pyx_t_10; - __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_v_score1); - __pyx_v_score1 = __pyx_t_11; - __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_v_score2); - __pyx_v_score2 = __pyx_t_12; - __pyx_t_12 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":282 - * for line in f: - * (fword, eword, score1, score2) = line.split() - * f_id = self.get_f_id(fword) # <<<<<<<<<<<<<< - * e_id = self.get_e_id(eword) - * while f_id >= len(fcount): - */ - __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_f_id); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_INCREF(__pyx_v_fword); - PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_v_fword); - __Pyx_GIVEREF(__pyx_v_fword); - __pyx_t_11 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; - __Pyx_XDECREF(__pyx_v_f_id); - __pyx_v_f_id = __pyx_t_11; - __pyx_t_11 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":283 - * (fword, eword, score1, score2) = line.split() - * f_id = self.get_f_id(fword) - * e_id = self.get_e_id(eword) # <<<<<<<<<<<<<< - * while f_id >= len(fcount): - * fcount.append(0) - */ - __pyx_t_11 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_e_id); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_INCREF(__pyx_v_eword); - PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_v_eword); - __Pyx_GIVEREF(__pyx_v_eword); - __pyx_t_3 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; - __Pyx_XDECREF(__pyx_v_e_id); - __pyx_v_e_id = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":284 - * f_id = self.get_f_id(fword) - * e_id = self.get_e_id(eword) - * while f_id >= len(fcount): # <<<<<<<<<<<<<< - * fcount.append(0) - * fcount.arr[f_id] = fcount.arr[f_id] + 1 - */ - while (1) { - __pyx_t_15 = PyObject_Length(((PyObject *)__pyx_v_fcount)); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_15); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_12 = PyObject_RichCompare(__pyx_v_f_id, __pyx_t_3, Py_GE); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (!__pyx_t_16) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":285 - * e_id = self.get_e_id(eword) - * while f_id >= len(fcount): - * fcount.append(0) # <<<<<<<<<<<<<< - * fcount.arr[f_id] = fcount.arr[f_id] + 1 - * - */ - __pyx_t_12 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_fcount), __pyx_int_0); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":286 - * while f_id >= len(fcount): - * fcount.append(0) - * fcount.arr[f_id] = fcount.arr[f_id] + 1 # <<<<<<<<<<<<<< - * - * # Allocate space for dictionary in arrays - */ - __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - (__pyx_v_fcount->arr[__pyx_t_17]) = ((__pyx_v_fcount->arr[__pyx_t_15]) + 1); - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":289 - * - * # Allocate space for dictionary in arrays - * N = 0 # <<<<<<<<<<<<<< - * n_f = len(fcount) - * self.f_index = IntList(initial_len=n_f+1) - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_v_N = __pyx_int_0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":290 - * # Allocate space for dictionary in arrays - * N = 0 - * n_f = len(fcount) # <<<<<<<<<<<<<< - * self.f_index = IntList(initial_len=n_f+1) - * for i from 0 <= i < n_f: - */ - __pyx_t_8 = PyObject_Length(((PyObject *)__pyx_v_fcount)); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_n_f = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":291 - * N = 0 - * n_f = len(fcount) - * self.f_index = IntList(initial_len=n_f+1) # <<<<<<<<<<<<<< - * for i from 0 <= i < n_f: - * self.f_index.arr[i] = N - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_12 = PyNumber_Add(__pyx_v_n_f, __pyx_int_1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_12) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_GIVEREF(__pyx_t_12); - __Pyx_GOTREF(__pyx_v_self->f_index); - __Pyx_DECREF(((PyObject *)__pyx_v_self->f_index)); - __pyx_v_self->f_index = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_12); - __pyx_t_12 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":292 - * n_f = len(fcount) - * self.f_index = IntList(initial_len=n_f+1) - * for i from 0 <= i < n_f: # <<<<<<<<<<<<<< - * self.f_index.arr[i] = N - * N = N + fcount.arr[i] - */ - __pyx_t_18 = __Pyx_PyInt_AsLong(__pyx_v_n_f); if (unlikely((__pyx_t_18 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_18; __pyx_t_19++) { - __pyx_t_12 = PyInt_FromLong(__pyx_t_19); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_XDECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_12; - __pyx_t_12 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":293 - * self.f_index = IntList(initial_len=n_f+1) - * for i from 0 <= i < n_f: - * self.f_index.arr[i] = N # <<<<<<<<<<<<<< - * N = N + fcount.arr[i] - * fcount.arr[i] = 0 - */ - __pyx_t_20 = __Pyx_PyInt_AsInt(__pyx_v_N); if (unlikely((__pyx_t_20 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - (__pyx_v_self->f_index->arr[__pyx_t_8]) = __pyx_t_20; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":294 - * for i from 0 <= i < n_f: - * self.f_index.arr[i] = N - * N = N + fcount.arr[i] # <<<<<<<<<<<<<< - * fcount.arr[i] = 0 - * self.f_index.arr[n_f] = N - */ - __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_12 = PyInt_FromLong((__pyx_v_fcount->arr[__pyx_t_8])); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_1 = PyNumber_Add(__pyx_v_N, __pyx_t_12); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_v_N); - __pyx_v_N = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":295 - * self.f_index.arr[i] = N - * N = N + fcount.arr[i] - * fcount.arr[i] = 0 # <<<<<<<<<<<<<< - * self.f_index.arr[n_f] = N - * self.e_index = IntList(initial_len=N) - */ - __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - (__pyx_v_fcount->arr[__pyx_t_8]) = 0; - __pyx_t_19 = __Pyx_PyInt_AsLong(__pyx_v_i); if (unlikely((__pyx_t_19 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":292 - * n_f = len(fcount) - * self.f_index = IntList(initial_len=n_f+1) - * for i from 0 <= i < n_f: # <<<<<<<<<<<<<< - * self.f_index.arr[i] = N - * N = N + fcount.arr[i] - */ - __pyx_t_1 = PyInt_FromLong(__pyx_t_19); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":296 - * N = N + fcount.arr[i] - * fcount.arr[i] = 0 - * self.f_index.arr[n_f] = N # <<<<<<<<<<<<<< - * self.e_index = IntList(initial_len=N) - * self.col1 = FloatList(initial_len=N) - */ - __pyx_t_20 = __Pyx_PyInt_AsInt(__pyx_v_N); if (unlikely((__pyx_t_20 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_n_f); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - (__pyx_v_self->f_index->arr[__pyx_t_8]) = __pyx_t_20; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":297 - * fcount.arr[i] = 0 - * self.f_index.arr[n_f] = N - * self.e_index = IntList(initial_len=N) # <<<<<<<<<<<<<< - * self.col1 = FloatList(initial_len=N) - * self.col2 = FloatList(initial_len=N) - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_v_N) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_12 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_GIVEREF(__pyx_t_12); - __Pyx_GOTREF(__pyx_v_self->e_index); - __Pyx_DECREF(((PyObject *)__pyx_v_self->e_index)); - __pyx_v_self->e_index = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_12); - __pyx_t_12 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":298 - * self.f_index.arr[n_f] = N - * self.e_index = IntList(initial_len=N) - * self.col1 = FloatList(initial_len=N) # <<<<<<<<<<<<<< - * self.col2 = FloatList(initial_len=N) - * - */ - __pyx_t_12 = PyDict_New(); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_12)); - if (PyDict_SetItem(__pyx_t_12, ((PyObject *)__pyx_n_s__initial_len), __pyx_v_N) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_FloatList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_12)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->col1); - __Pyx_DECREF(((PyObject *)__pyx_v_self->col1)); - __pyx_v_self->col1 = ((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":299 - * self.e_index = IntList(initial_len=N) - * self.col1 = FloatList(initial_len=N) - * self.col2 = FloatList(initial_len=N) # <<<<<<<<<<<<<< - * - * # Re-read file, placing words into buckets - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_v_N) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_12 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_FloatList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_GIVEREF(__pyx_t_12); - __Pyx_GOTREF(__pyx_v_self->col2); - __Pyx_DECREF(((PyObject *)__pyx_v_self->col2)); - __pyx_v_self->col2 = ((struct __pyx_obj_8_cdec_sa_FloatList *)__pyx_t_12); - __pyx_t_12 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":302 - * - * # Re-read file, placing words into buckets - * f.seek(0) # <<<<<<<<<<<<<< - * for line in f: - * (fword, eword, score1, score2) = line.split() - */ - __pyx_t_12 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__seek); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_1 = PyObject_Call(__pyx_t_12, ((PyObject *)__pyx_k_tuple_40), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":303 - * # Re-read file, placing words into buckets - * f.seek(0) - * for line in f: # <<<<<<<<<<<<<< - * (fword, eword, score1, score2) = line.split() - * f_id = self.get_f_id(fword) - */ - if (PyList_CheckExact(__pyx_v_f) || PyTuple_CheckExact(__pyx_v_f)) { - __pyx_t_1 = __pyx_v_f; __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_12 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_12); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_12 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_12); __pyx_t_8++; - } else { - __pyx_t_12 = __pyx_t_9(__pyx_t_1); - if (unlikely(!__pyx_t_12)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_12); - } - __Pyx_XDECREF(__pyx_v_line); - __pyx_v_line = __pyx_t_12; - __pyx_t_12 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":304 - * f.seek(0) - * for line in f: - * (fword, eword, score1, score2) = line.split() # <<<<<<<<<<<<<< - * f_id = self.get_f_id(fword) - * e_id = self.get_e_id(eword) - */ - __pyx_t_12 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_3 = PyObject_Call(__pyx_t_12, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { - PyObject* sequence = __pyx_t_3; - if (likely(PyTuple_CheckExact(sequence))) { - if (unlikely(PyTuple_GET_SIZE(sequence) != 4)) { - if (PyTuple_GET_SIZE(sequence) > 4) __Pyx_RaiseTooManyValuesError(4); - else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - __pyx_t_12 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 3); - } else { - if (unlikely(PyList_GET_SIZE(sequence) != 4)) { - if (PyList_GET_SIZE(sequence) > 4) __Pyx_RaiseTooManyValuesError(4); - else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - __pyx_t_12 = PyList_GET_ITEM(sequence, 0); - __pyx_t_11 = PyList_GET_ITEM(sequence, 1); - __pyx_t_10 = PyList_GET_ITEM(sequence, 2); - __pyx_t_2 = PyList_GET_ITEM(sequence, 3); - } - __Pyx_INCREF(__pyx_t_12); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_13 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_14 = Py_TYPE(__pyx_t_13)->tp_iternext; - index = 0; __pyx_t_12 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_12)) goto __pyx_L26_unpacking_failed; - __Pyx_GOTREF(__pyx_t_12); - index = 1; __pyx_t_11 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_11)) goto __pyx_L26_unpacking_failed; - __Pyx_GOTREF(__pyx_t_11); - index = 2; __pyx_t_10 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_10)) goto __pyx_L26_unpacking_failed; - __Pyx_GOTREF(__pyx_t_10); - index = 3; __pyx_t_2 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_2)) goto __pyx_L26_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_13), 4) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - goto __pyx_L27_unpacking_done; - __pyx_L26_unpacking_failed:; - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_L27_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_fword); - __pyx_v_fword = __pyx_t_12; - __pyx_t_12 = 0; - __Pyx_XDECREF(__pyx_v_eword); - __pyx_v_eword = __pyx_t_11; - __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_v_score1); - __pyx_v_score1 = __pyx_t_10; - __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_v_score2); - __pyx_v_score2 = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":305 - * for line in f: - * (fword, eword, score1, score2) = line.split() - * f_id = self.get_f_id(fword) # <<<<<<<<<<<<<< - * e_id = self.get_e_id(eword) - * index = self.f_index.arr[f_id] + fcount.arr[f_id] - */ - __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_f_id); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_fword); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_fword); - __Pyx_GIVEREF(__pyx_v_fword); - __pyx_t_10 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_v_f_id); - __pyx_v_f_id = __pyx_t_10; - __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":306 - * (fword, eword, score1, score2) = line.split() - * f_id = self.get_f_id(fword) - * e_id = self.get_e_id(eword) # <<<<<<<<<<<<<< - * index = self.f_index.arr[f_id] + fcount.arr[f_id] - * fcount.arr[f_id] = fcount.arr[f_id] + 1 - */ - __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_e_id); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_eword); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_eword); - __Pyx_GIVEREF(__pyx_v_eword); - __pyx_t_3 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_v_e_id); - __pyx_v_e_id = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":307 - * f_id = self.get_f_id(fword) - * e_id = self.get_e_id(eword) - * index = self.f_index.arr[f_id] + fcount.arr[f_id] # <<<<<<<<<<<<<< - * fcount.arr[f_id] = fcount.arr[f_id] + 1 - * self.e_index.arr[index] = int(e_id) - */ - __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_3 = PyInt_FromLong(((__pyx_v_self->f_index->arr[__pyx_t_15]) + (__pyx_v_fcount->arr[__pyx_t_17]))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_v_index); - __pyx_v_index = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":308 - * e_id = self.get_e_id(eword) - * index = self.f_index.arr[f_id] + fcount.arr[f_id] - * fcount.arr[f_id] = fcount.arr[f_id] + 1 # <<<<<<<<<<<<<< - * self.e_index.arr[index] = int(e_id) - * self.col1[index] = float(score1) - */ - __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - (__pyx_v_fcount->arr[__pyx_t_15]) = ((__pyx_v_fcount->arr[__pyx_t_17]) + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":309 - * index = self.f_index.arr[f_id] + fcount.arr[f_id] - * fcount.arr[f_id] = fcount.arr[f_id] + 1 - * self.e_index.arr[index] = int(e_id) # <<<<<<<<<<<<<< - * self.col1[index] = float(score1) - * self.col2[index] = float(score2) - */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_e_id); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_e_id); - __Pyx_GIVEREF(__pyx_v_e_id); - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_20 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_20 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_v_index); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - (__pyx_v_self->e_index->arr[__pyx_t_17]) = __pyx_t_20; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":310 - * fcount.arr[f_id] = fcount.arr[f_id] + 1 - * self.e_index.arr[index] = int(e_id) - * self.col1[index] = float(score1) # <<<<<<<<<<<<<< - * self.col2[index] = float(score2) - * - */ - __pyx_t_21 = __Pyx_PyObject_AsDouble(__pyx_v_score1); if (unlikely(__pyx_t_21 == ((double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_2 = PyFloat_FromDouble(__pyx_t_21); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - if (PyObject_SetItem(((PyObject *)__pyx_v_self->col1), __pyx_v_index, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":311 - * self.e_index.arr[index] = int(e_id) - * self.col1[index] = float(score1) - * self.col2[index] = float(score2) # <<<<<<<<<<<<<< - * - * # Sort buckets by eword - */ - __pyx_t_21 = __Pyx_PyObject_AsDouble(__pyx_v_score2); if (unlikely(__pyx_t_21 == ((double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_2 = PyFloat_FromDouble(__pyx_t_21); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - if (PyObject_SetItem(((PyObject *)__pyx_v_self->col2), __pyx_v_index, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L14_try_end; - __pyx_L7_error:; - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":278 - * - * fcount = IntList() - * with gzip_or_text(filename) as f: # <<<<<<<<<<<<<< - * # first loop merely establishes size of array objects - * for line in f: - */ - /*except:*/ { - __Pyx_AddTraceback("_cdec_sa.BiLex.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_22 = PyObject_Call(__pyx_t_4, __pyx_t_10, NULL); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_22)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_22); - __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_22); - __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; - if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __pyx_t_23 = (!__pyx_t_16); - if (__pyx_t_23) { - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_3); - __Pyx_ErrRestore(__pyx_t_1, __pyx_t_2, __pyx_t_3); - __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - goto __pyx_L30; - } - __pyx_L30:; - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L8_exception_handled; - } - __pyx_L9_except_error:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - goto __pyx_L1_error; - __pyx_L8_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - __pyx_L14_try_end:; - } - } - /*finally:*/ { - if (__pyx_t_4) { - __pyx_t_7 = PyObject_Call(__pyx_t_4, __pyx_k_tuple_41, NULL); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_23 = __Pyx_PyObject_IsTrue(__pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_23 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - goto __pyx_L31; - __pyx_L3_error:; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L1_error; - __pyx_L31:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":314 - * - * # Sort buckets by eword - * for b from 0 <= b < n_f: # <<<<<<<<<<<<<< - * i = self.f_index.arr[b] - * j = self.f_index.arr[b+1] - */ - if (unlikely(!__pyx_v_n_f)) { __Pyx_RaiseUnboundLocalError("n_f"); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_19 = __Pyx_PyInt_AsLong(__pyx_v_n_f); if (unlikely((__pyx_t_19 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_19; __pyx_t_18++) { - __pyx_t_3 = PyInt_FromLong(__pyx_t_18); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_v_b); - __pyx_v_b = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":315 - * # Sort buckets by eword - * for b from 0 <= b < n_f: - * i = self.f_index.arr[b] # <<<<<<<<<<<<<< - * j = self.f_index.arr[b+1] - * self.qsort(i,j, "") - */ - __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_b); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = PyInt_FromLong((__pyx_v_self->f_index->arr[__pyx_t_8])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":316 - * for b from 0 <= b < n_f: - * i = self.f_index.arr[b] - * j = self.f_index.arr[b+1] # <<<<<<<<<<<<<< - * self.qsort(i,j, "") - * - */ - __pyx_t_3 = PyNumber_Add(__pyx_v_b, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_3); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyInt_FromLong((__pyx_v_self->f_index->arr[__pyx_t_8])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_v_j); - __pyx_v_j = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":317 - * i = self.f_index.arr[b] - * j = self.f_index.arr[b+1] - * self.qsort(i,j, "") # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_20 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_20 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_24 = __Pyx_PyInt_AsInt(__pyx_v_j); if (unlikely((__pyx_t_24 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = ((PyObject *)__pyx_kp_s_42); - __Pyx_INCREF(__pyx_t_3); - __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->qsort(__pyx_v_self, __pyx_t_20, __pyx_t_24, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_18 = __Pyx_PyInt_AsLong(__pyx_v_b); if (unlikely((__pyx_t_18 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":314 - * - * # Sort buckets by eword - * for b from 0 <= b < n_f: # <<<<<<<<<<<<<< - * i = self.f_index.arr[b] - * j = self.f_index.arr[b+1] - */ - __pyx_t_2 = PyInt_FromLong(__pyx_t_18); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_v_b); - __pyx_v_b = __pyx_t_2; - __pyx_t_2 = 0; - - __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_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_XDECREF(__pyx_t_13); - __Pyx_AddTraceback("_cdec_sa.BiLex.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_i); - __Pyx_XDECREF(__pyx_v_j); - __Pyx_XDECREF(__pyx_v_e_id); - __Pyx_XDECREF(__pyx_v_f_id); - __Pyx_XDECREF(__pyx_v_n_f); - __Pyx_XDECREF(__pyx_v_N); - __Pyx_XDECREF((PyObject *)__pyx_v_fcount); - __Pyx_XDECREF(__pyx_v_f); - __Pyx_XDECREF(__pyx_v_line); - __Pyx_XDECREF(__pyx_v_fword); - __Pyx_XDECREF(__pyx_v_eword); - __Pyx_XDECREF(__pyx_v_score1); - __Pyx_XDECREF(__pyx_v_score2); - __Pyx_XDECREF(__pyx_v_index); - __Pyx_XDECREF(__pyx_v_b); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":320 - * - * - * cdef swap(self, int i, int j): # <<<<<<<<<<<<<< - * cdef int itmp - * cdef float ftmp - */ - -static PyObject *__pyx_f_8_cdec_sa_5BiLex_swap(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, int __pyx_v_i, int __pyx_v_j) { - int __pyx_v_itmp; - float __pyx_v_ftmp; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("swap", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":324 - * cdef float ftmp - * - * if i == j: # <<<<<<<<<<<<<< - * return - * - */ - __pyx_t_1 = (__pyx_v_i == __pyx_v_j); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":325 - * - * if i == j: - * return # <<<<<<<<<<<<<< - * - * itmp = self.e_index.arr[i] - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":327 - * return - * - * itmp = self.e_index.arr[i] # <<<<<<<<<<<<<< - * self.e_index.arr[i] = self.e_index.arr[j] - * self.e_index.arr[j] = itmp - */ - __pyx_v_itmp = (__pyx_v_self->e_index->arr[__pyx_v_i]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":328 - * - * itmp = self.e_index.arr[i] - * self.e_index.arr[i] = self.e_index.arr[j] # <<<<<<<<<<<<<< - * self.e_index.arr[j] = itmp - * - */ - (__pyx_v_self->e_index->arr[__pyx_v_i]) = (__pyx_v_self->e_index->arr[__pyx_v_j]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":329 - * itmp = self.e_index.arr[i] - * self.e_index.arr[i] = self.e_index.arr[j] - * self.e_index.arr[j] = itmp # <<<<<<<<<<<<<< - * - * ftmp = self.col1.arr[i] - */ - (__pyx_v_self->e_index->arr[__pyx_v_j]) = __pyx_v_itmp; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":331 - * self.e_index.arr[j] = itmp - * - * ftmp = self.col1.arr[i] # <<<<<<<<<<<<<< - * self.col1.arr[i] = self.col1.arr[j] - * self.col1.arr[j] = ftmp - */ - __pyx_v_ftmp = (__pyx_v_self->col1->arr[__pyx_v_i]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":332 - * - * ftmp = self.col1.arr[i] - * self.col1.arr[i] = self.col1.arr[j] # <<<<<<<<<<<<<< - * self.col1.arr[j] = ftmp - * - */ - (__pyx_v_self->col1->arr[__pyx_v_i]) = (__pyx_v_self->col1->arr[__pyx_v_j]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":333 - * ftmp = self.col1.arr[i] - * self.col1.arr[i] = self.col1.arr[j] - * self.col1.arr[j] = ftmp # <<<<<<<<<<<<<< - * - * ftmp = self.col2.arr[i] - */ - (__pyx_v_self->col1->arr[__pyx_v_j]) = __pyx_v_ftmp; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":335 - * self.col1.arr[j] = ftmp - * - * ftmp = self.col2.arr[i] # <<<<<<<<<<<<<< - * self.col2.arr[i] = self.col2.arr[j] - * self.col2.arr[j] = ftmp - */ - __pyx_v_ftmp = (__pyx_v_self->col2->arr[__pyx_v_i]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":336 - * - * ftmp = self.col2.arr[i] - * self.col2.arr[i] = self.col2.arr[j] # <<<<<<<<<<<<<< - * self.col2.arr[j] = ftmp - * - */ - (__pyx_v_self->col2->arr[__pyx_v_i]) = (__pyx_v_self->col2->arr[__pyx_v_j]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":337 - * ftmp = self.col2.arr[i] - * self.col2.arr[i] = self.col2.arr[j] - * self.col2.arr[j] = ftmp # <<<<<<<<<<<<<< - * - * - */ - (__pyx_v_self->col2->arr[__pyx_v_j]) = __pyx_v_ftmp; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":340 - * - * - * cdef qsort(self, int i, int j, pad): # <<<<<<<<<<<<<< - * cdef int pval, p - * - */ - -static PyObject *__pyx_f_8_cdec_sa_5BiLex_qsort(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, int __pyx_v_i, int __pyx_v_j, PyObject *__pyx_v_pad) { - int __pyx_v_pval; - int __pyx_v_p; - long __pyx_v_k; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("qsort", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":343 - * cdef int pval, p - * - * if i > j: # <<<<<<<<<<<<<< - * raise Exception("Sort error in CLex") - * if i == j: #empty interval - */ - __pyx_t_1 = (__pyx_v_i > __pyx_v_j); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":344 - * - * if i > j: - * raise Exception("Sort error in CLex") # <<<<<<<<<<<<<< - * if i == j: #empty interval - * return - */ - __pyx_t_2 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_k_tuple_44), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":345 - * if i > j: - * raise Exception("Sort error in CLex") - * if i == j: #empty interval # <<<<<<<<<<<<<< - * return - * if i == j-1: # singleton interval - */ - __pyx_t_1 = (__pyx_v_i == __pyx_v_j); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":346 - * raise Exception("Sort error in CLex") - * if i == j: #empty interval - * return # <<<<<<<<<<<<<< - * if i == j-1: # singleton interval - * return - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":347 - * if i == j: #empty interval - * return - * if i == j-1: # singleton interval # <<<<<<<<<<<<<< - * return - * - */ - __pyx_t_1 = (__pyx_v_i == (__pyx_v_j - 1)); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":348 - * return - * if i == j-1: # singleton interval - * return # <<<<<<<<<<<<<< - * - * p = (i+j)/2 - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":350 - * return - * - * p = (i+j)/2 # <<<<<<<<<<<<<< - * pval = self.e_index.arr[p] - * self.swap(i, p) - */ - __pyx_v_p = __Pyx_div_long((__pyx_v_i + __pyx_v_j), 2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":351 - * - * p = (i+j)/2 - * pval = self.e_index.arr[p] # <<<<<<<<<<<<<< - * self.swap(i, p) - * p = i - */ - __pyx_v_pval = (__pyx_v_self->e_index->arr[__pyx_v_p]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":352 - * p = (i+j)/2 - * pval = self.e_index.arr[p] - * self.swap(i, p) # <<<<<<<<<<<<<< - * p = i - * for k from i+1 <= k < j: - */ - __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->swap(__pyx_v_self, __pyx_v_i, __pyx_v_p); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":353 - * pval = self.e_index.arr[p] - * self.swap(i, p) - * p = i # <<<<<<<<<<<<<< - * for k from i+1 <= k < j: - * if pval >= self.e_index.arr[k]: - */ - __pyx_v_p = __pyx_v_i; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":354 - * self.swap(i, p) - * p = i - * for k from i+1 <= k < j: # <<<<<<<<<<<<<< - * if pval >= self.e_index.arr[k]: - * self.swap(p+1, k) - */ - __pyx_t_3 = __pyx_v_j; - for (__pyx_v_k = (__pyx_v_i + 1); __pyx_v_k < __pyx_t_3; __pyx_v_k++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":355 - * p = i - * for k from i+1 <= k < j: - * if pval >= self.e_index.arr[k]: # <<<<<<<<<<<<<< - * self.swap(p+1, k) - * self.swap(p, p+1) - */ - __pyx_t_1 = (__pyx_v_pval >= (__pyx_v_self->e_index->arr[__pyx_v_k])); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":356 - * for k from i+1 <= k < j: - * if pval >= self.e_index.arr[k]: - * self.swap(p+1, k) # <<<<<<<<<<<<<< - * self.swap(p, p+1) - * p = p + 1 - */ - __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->swap(__pyx_v_self, (__pyx_v_p + 1), __pyx_v_k); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":357 - * if pval >= self.e_index.arr[k]: - * self.swap(p+1, k) - * self.swap(p, p+1) # <<<<<<<<<<<<<< - * p = p + 1 - * self.qsort(i,p, pad+" ") - */ - __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->swap(__pyx_v_self, __pyx_v_p, (__pyx_v_p + 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":358 - * self.swap(p+1, k) - * self.swap(p, p+1) - * p = p + 1 # <<<<<<<<<<<<<< - * self.qsort(i,p, pad+" ") - * self.qsort(p+1,j, pad+" ") - */ - __pyx_v_p = (__pyx_v_p + 1); - goto __pyx_L8; - } - __pyx_L8:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":359 - * self.swap(p, p+1) - * p = p + 1 - * self.qsort(i,p, pad+" ") # <<<<<<<<<<<<<< - * self.qsort(p+1,j, pad+" ") - * - */ - __pyx_t_2 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->qsort(__pyx_v_self, __pyx_v_i, __pyx_v_p, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":360 - * p = p + 1 - * self.qsort(i,p, pad+" ") - * self.qsort(p+1,j, pad+" ") # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_4 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_BiLex *)__pyx_v_self->__pyx_vtab)->qsort(__pyx_v_self, (__pyx_v_p + 1), __pyx_v_j, __pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec_sa.BiLex.qsort", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_5BiLex_13write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_5BiLex_13write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_enhanced (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.BiLex.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_5BiLex_12write_enhanced(((struct __pyx_obj_8_cdec_sa_BiLex *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":363 - * - * - * def write_enhanced(self, char* filename): # <<<<<<<<<<<<<< - * with open(filename, "w") as f: - * for i in self.f_index: - */ - -static PyObject *__pyx_pf_8_cdec_sa_5BiLex_12write_enhanced(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename) { - PyObject *__pyx_v_f = NULL; - PyObject *__pyx_v_i = NULL; - PyObject *__pyx_v_s1 = NULL; - PyObject *__pyx_v_s2 = NULL; - PyObject *__pyx_v_w = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - Py_ssize_t __pyx_t_8; - PyObject *(*__pyx_t_9)(PyObject *); - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; - PyObject *(*__pyx_t_13)(PyObject *); - int __pyx_t_14; - PyObject *__pyx_t_15 = NULL; - int __pyx_t_16; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("write_enhanced", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":364 - * - * def write_enhanced(self, char* filename): - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * for i in self.f_index: - * f.write("%d " % i) - */ - /*with:*/ { - __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /*try:*/ { - { - __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - /*try:*/ { - __Pyx_INCREF(__pyx_t_4); - __pyx_v_f = __pyx_t_4; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":365 - * def write_enhanced(self, char* filename): - * with open(filename, "w") as f: - * for i in self.f_index: # <<<<<<<<<<<<<< - * f.write("%d " % i) - * f.write("\n") - */ - if (PyList_CheckExact(((PyObject *)__pyx_v_self->f_index)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->f_index))) { - __pyx_t_4 = ((PyObject *)__pyx_v_self->f_index); __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(((PyObject *)__pyx_v_self->f_index)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; - } else { - __pyx_t_1 = __pyx_t_9(__pyx_t_4); - if (unlikely(!__pyx_t_1)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XDECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":366 - * with open(filename, "w") as f: - * for i in self.f_index: - * f.write("%d " % i) # <<<<<<<<<<<<<< - * f.write("\n") - * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":367 - * for i in self.f_index: - * f.write("%d " % i) - * f.write("\n") # <<<<<<<<<<<<<< - * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): - * f.write("%d %f %f " % (i, s1, s2)) - */ - __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_46), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":368 - * f.write("%d " % i) - * f.write("\n") - * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): # <<<<<<<<<<<<<< - * f.write("%d %f %f " % (i, s1, s2)) - * f.write("\n") - */ - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_v_self->e_index)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self->e_index)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->e_index)); - __Pyx_INCREF(((PyObject *)__pyx_v_self->col1)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_self->col1)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->col1)); - __Pyx_INCREF(((PyObject *)__pyx_v_self->col2)); - PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_self->col2)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->col2)); - __pyx_t_4 = PyObject_Call(__pyx_builtin_zip, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - if (PyList_CheckExact(__pyx_t_4) || PyTuple_CheckExact(__pyx_t_4)) { - __pyx_t_2 = __pyx_t_4; __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_9 = Py_TYPE(__pyx_t_2)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_2)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break; - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_4); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_2)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_4); __pyx_t_8++; - } else { - __pyx_t_4 = __pyx_t_9(__pyx_t_2); - if (unlikely(!__pyx_t_4)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) { - PyObject* sequence = __pyx_t_4; - if (likely(PyTuple_CheckExact(sequence))) { - if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { - if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_11 = PyTuple_GET_ITEM(sequence, 2); - } else { - if (unlikely(PyList_GET_SIZE(sequence) != 3)) { - if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - __pyx_t_10 = PyList_GET_ITEM(sequence, 0); - __pyx_t_1 = PyList_GET_ITEM(sequence, 1); - __pyx_t_11 = PyList_GET_ITEM(sequence, 2); - } - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_12 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_13 = Py_TYPE(__pyx_t_12)->tp_iternext; - index = 0; __pyx_t_10 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_10)) goto __pyx_L20_unpacking_failed; - __Pyx_GOTREF(__pyx_t_10); - index = 1; __pyx_t_1 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_1)) goto __pyx_L20_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - index = 2; __pyx_t_11 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_11)) goto __pyx_L20_unpacking_failed; - __Pyx_GOTREF(__pyx_t_11); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 3) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - goto __pyx_L21_unpacking_done; - __pyx_L20_unpacking_failed:; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_L21_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_10; - __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_v_s1); - __pyx_v_s1 = __pyx_t_1; - __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_v_s2); - __pyx_v_s2 = __pyx_t_11; - __pyx_t_11 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":369 - * f.write("\n") - * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): - * f.write("%d %f %f " % (i, s1, s2)) # <<<<<<<<<<<<<< - * f.write("\n") - * for i, w in enumerate(self.id2fword): - */ - __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_INCREF(__pyx_v_i); - PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_i); - __Pyx_GIVEREF(__pyx_v_i); - __Pyx_INCREF(__pyx_v_s1); - PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_v_s1); - __Pyx_GIVEREF(__pyx_v_s1); - __Pyx_INCREF(__pyx_v_s2); - PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_v_s2); - __Pyx_GIVEREF(__pyx_v_s2); - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_47), ((PyObject *)__pyx_t_11)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; - __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_11, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":370 - * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): - * f.write("%d %f %f " % (i, s1, s2)) - * f.write("\n") # <<<<<<<<<<<<<< - * for i, w in enumerate(self.id2fword): - * f.write("%d %s " % (i, w)) - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_48), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":371 - * f.write("%d %f %f " % (i, s1, s2)) - * f.write("\n") - * for i, w in enumerate(self.id2fword): # <<<<<<<<<<<<<< - * f.write("%d %s " % (i, w)) - * f.write("\n") - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_t_1 = __pyx_int_0; - if (PyList_CheckExact(__pyx_v_self->id2fword) || PyTuple_CheckExact(__pyx_v_self->id2fword)) { - __pyx_t_2 = __pyx_v_self->id2fword; __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_self->id2fword); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_9 = Py_TYPE(__pyx_t_2)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_2)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break; - __pyx_t_11 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_11); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_2)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - __pyx_t_11 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_11); __pyx_t_8++; - } else { - __pyx_t_11 = __pyx_t_9(__pyx_t_2); - if (unlikely(!__pyx_t_11)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_11); - } - __Pyx_XDECREF(__pyx_v_w); - __pyx_v_w = __pyx_t_11; - __pyx_t_11 = 0; - __Pyx_INCREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_1; - __pyx_t_11 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_1); - __pyx_t_1 = __pyx_t_11; - __pyx_t_11 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":372 - * f.write("\n") - * for i, w in enumerate(self.id2fword): - * f.write("%d %s " % (i, w)) # <<<<<<<<<<<<<< - * f.write("\n") - * for i, w in enumerate(self.id2eword): - */ - __pyx_t_11 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_i); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_i); - __Pyx_GIVEREF(__pyx_v_i); - __Pyx_INCREF(__pyx_v_w); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_w); - __Pyx_GIVEREF(__pyx_v_w); - __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_49), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_10)); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_10)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); - __pyx_t_10 = 0; - __pyx_t_10 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":373 - * for i, w in enumerate(self.id2fword): - * f.write("%d %s " % (i, w)) - * f.write("\n") # <<<<<<<<<<<<<< - * for i, w in enumerate(self.id2eword): - * f.write("%d %s " % (i, w)) - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_50), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":374 - * f.write("%d %s " % (i, w)) - * f.write("\n") - * for i, w in enumerate(self.id2eword): # <<<<<<<<<<<<<< - * f.write("%d %s " % (i, w)) - * f.write("\n") - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_t_2 = __pyx_int_0; - if (PyList_CheckExact(__pyx_v_self->id2eword) || PyTuple_CheckExact(__pyx_v_self->id2eword)) { - __pyx_t_1 = __pyx_v_self->id2eword; __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_self->id2eword); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_10 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_10); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_10); __pyx_t_8++; - } else { - __pyx_t_10 = __pyx_t_9(__pyx_t_1); - if (unlikely(!__pyx_t_10)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_10); - } - __Pyx_XDECREF(__pyx_v_w); - __pyx_v_w = __pyx_t_10; - __pyx_t_10 = 0; - __Pyx_INCREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_2; - __pyx_t_10 = PyNumber_Add(__pyx_t_2, __pyx_int_1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_2); - __pyx_t_2 = __pyx_t_10; - __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":375 - * f.write("\n") - * for i, w in enumerate(self.id2eword): - * f.write("%d %s " % (i, w)) # <<<<<<<<<<<<<< - * f.write("\n") - * - */ - __pyx_t_10 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_i); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_i); - __Pyx_GIVEREF(__pyx_v_i); - __Pyx_INCREF(__pyx_v_w); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_w); - __Pyx_GIVEREF(__pyx_v_w); - __pyx_t_11 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_49), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_11)); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_11)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_11)); - __pyx_t_11 = 0; - __pyx_t_11 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":376 - * for i, w in enumerate(self.id2eword): - * f.write("%d %s " % (i, w)) - * f.write("\n") # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_51), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L14_try_end; - __pyx_L7_error:; - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":364 - * - * def write_enhanced(self, char* filename): - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * for i in self.f_index: - * f.write("%d " % i) - */ - /*except:*/ { - __Pyx_AddTraceback("_cdec_sa.BiLex.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_2, &__pyx_t_11) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GOTREF(__pyx_t_11); - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_11); - __Pyx_GIVEREF(__pyx_t_11); - __pyx_t_15 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L9_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[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __pyx_t_16 = (!__pyx_t_14); - if (__pyx_t_16) { - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_11); - __Pyx_ErrRestore(__pyx_t_1, __pyx_t_2, __pyx_t_11); - __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_11 = 0; - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - goto __pyx_L28; - } - __pyx_L28:; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - goto __pyx_L8_exception_handled; - } - __pyx_L9_except_error:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - goto __pyx_L1_error; - __pyx_L8_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - __pyx_L14_try_end:; - } - } - /*finally:*/ { - if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_52, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - goto __pyx_L29; - __pyx_L3_error:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L1_error; - __pyx_L29:; - } - - __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_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_AddTraceback("_cdec_sa.BiLex.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_f); - __Pyx_XDECREF(__pyx_v_i); - __Pyx_XDECREF(__pyx_v_s1); - __Pyx_XDECREF(__pyx_v_s2); - __Pyx_XDECREF(__pyx_v_w); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_5BiLex_15get_score(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_5BiLex_15get_score(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_fword = 0; - PyObject *__pyx_v_eword = 0; - PyObject *__pyx_v_col = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fword,&__pyx_n_s__eword,&__pyx_n_s__col,0}; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_score (wrapper)", 0); - { - PyObject* values[3] = {0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fword); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__eword); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("get_score", 1, 3, 3, 1); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__col); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("get_score", 1, 3, 3, 2); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_score") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - } - __pyx_v_fword = values[0]; - __pyx_v_eword = values[1]; - __pyx_v_col = values[2]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get_score", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.BiLex.get_score", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_5BiLex_14get_score(((struct __pyx_obj_8_cdec_sa_BiLex *)__pyx_v_self), __pyx_v_fword, __pyx_v_eword, __pyx_v_col); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":379 - * - * - * def get_score(self, fword, eword, col): # <<<<<<<<<<<<<< - * cdef e_id, f_id, low, high, midpoint, val - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_5BiLex_14get_score(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_fword, PyObject *__pyx_v_eword, PyObject *__pyx_v_col) { - PyObject *__pyx_v_e_id = 0; - PyObject *__pyx_v_f_id = 0; - PyObject *__pyx_v_low = 0; - PyObject *__pyx_v_high = 0; - PyObject *__pyx_v_midpoint = 0; - PyObject *__pyx_v_val = 0; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - Py_ssize_t __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get_score", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":382 - * cdef e_id, f_id, low, high, midpoint, val - * - * if eword not in self.eword2id: # <<<<<<<<<<<<<< - * return None - * if fword not in self.fword2id: - */ - __pyx_t_1 = (__Pyx_NegateNonNeg(PySequence_Contains(__pyx_v_self->eword2id, __pyx_v_eword))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 382; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":383 - * - * if eword not in self.eword2id: - * return None # <<<<<<<<<<<<<< - * if fword not in self.fword2id: - * return None - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(Py_None); - __pyx_r = Py_None; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":384 - * if eword not in self.eword2id: - * return None - * if fword not in self.fword2id: # <<<<<<<<<<<<<< - * return None - * f_id = self.fword2id[fword] - */ - __pyx_t_1 = (__Pyx_NegateNonNeg(PySequence_Contains(__pyx_v_self->fword2id, __pyx_v_fword))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":385 - * return None - * if fword not in self.fword2id: - * return None # <<<<<<<<<<<<<< - * f_id = self.fword2id[fword] - * e_id = self.eword2id[eword] - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(Py_None); - __pyx_r = Py_None; - goto __pyx_L0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":386 - * if fword not in self.fword2id: - * return None - * f_id = self.fword2id[fword] # <<<<<<<<<<<<<< - * e_id = self.eword2id[eword] - * low = self.f_index.arr[f_id] - */ - __pyx_t_2 = PyObject_GetItem(__pyx_v_self->fword2id, __pyx_v_fword); if (!__pyx_t_2) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_f_id = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":387 - * return None - * f_id = self.fword2id[fword] - * e_id = self.eword2id[eword] # <<<<<<<<<<<<<< - * low = self.f_index.arr[f_id] - * high = self.f_index.arr[f_id+1] - */ - __pyx_t_2 = PyObject_GetItem(__pyx_v_self->eword2id, __pyx_v_eword); if (!__pyx_t_2) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_e_id = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":388 - * f_id = self.fword2id[fword] - * e_id = self.eword2id[eword] - * low = self.f_index.arr[f_id] # <<<<<<<<<<<<<< - * high = self.f_index.arr[f_id+1] - * while high - low > 0: - */ - __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 388; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromLong((__pyx_v_self->f_index->arr[__pyx_t_3])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 388; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_low = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":389 - * e_id = self.eword2id[eword] - * low = self.f_index.arr[f_id] - * high = self.f_index.arr[f_id+1] # <<<<<<<<<<<<<< - * while high - low > 0: - * midpoint = (low+high)/2 - */ - __pyx_t_2 = PyNumber_Add(__pyx_v_f_id, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyInt_FromLong((__pyx_v_self->f_index->arr[__pyx_t_3])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_high = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":390 - * low = self.f_index.arr[f_id] - * high = self.f_index.arr[f_id+1] - * while high - low > 0: # <<<<<<<<<<<<<< - * midpoint = (low+high)/2 - * val = self.e_index.arr[midpoint] - */ - while (1) { - __pyx_t_2 = PyNumber_Subtract(__pyx_v_high, __pyx_v_low); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_GT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (!__pyx_t_1) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":391 - * high = self.f_index.arr[f_id+1] - * while high - low > 0: - * midpoint = (low+high)/2 # <<<<<<<<<<<<<< - * val = self.e_index.arr[midpoint] - * if val == e_id: - */ - __pyx_t_4 = PyNumber_Add(__pyx_v_low, __pyx_v_high); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_int_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_v_midpoint); - __pyx_v_midpoint = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":392 - * while high - low > 0: - * midpoint = (low+high)/2 - * val = self.e_index.arr[midpoint] # <<<<<<<<<<<<<< - * if val == e_id: - * if col == 0: - */ - __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_v_midpoint); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromLong((__pyx_v_self->e_index->arr[__pyx_t_3])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_v_val); - __pyx_v_val = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":393 - * midpoint = (low+high)/2 - * val = self.e_index.arr[midpoint] - * if val == e_id: # <<<<<<<<<<<<<< - * if col == 0: - * return self.col1.arr[midpoint] - */ - __pyx_t_2 = PyObject_RichCompare(__pyx_v_val, __pyx_v_e_id, Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":394 - * val = self.e_index.arr[midpoint] - * if val == e_id: - * if col == 0: # <<<<<<<<<<<<<< - * return self.col1.arr[midpoint] - * if col == 1: - */ - __pyx_t_2 = PyObject_RichCompare(__pyx_v_col, __pyx_int_0, Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 394; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 394; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":395 - * if val == e_id: - * if col == 0: - * return self.col1.arr[midpoint] # <<<<<<<<<<<<<< - * if col == 1: - * return self.col2.arr[midpoint] - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_v_midpoint); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyFloat_FromDouble((__pyx_v_self->col1->arr[__pyx_t_3])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - goto __pyx_L8; - } - __pyx_L8:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":396 - * if col == 0: - * return self.col1.arr[midpoint] - * if col == 1: # <<<<<<<<<<<<<< - * return self.col2.arr[midpoint] - * if val > e_id: - */ - __pyx_t_2 = PyObject_RichCompare(__pyx_v_col, __pyx_int_1, Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":397 - * return self.col1.arr[midpoint] - * if col == 1: - * return self.col2.arr[midpoint] # <<<<<<<<<<<<<< - * if val > e_id: - * high = midpoint - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_v_midpoint); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyFloat_FromDouble((__pyx_v_self->col2->arr[__pyx_t_3])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - goto __pyx_L9; - } - __pyx_L9:; - goto __pyx_L7; - } - __pyx_L7:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":398 - * if col == 1: - * return self.col2.arr[midpoint] - * if val > e_id: # <<<<<<<<<<<<<< - * high = midpoint - * if val < e_id: - */ - __pyx_t_2 = PyObject_RichCompare(__pyx_v_val, __pyx_v_e_id, Py_GT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":399 - * return self.col2.arr[midpoint] - * if val > e_id: - * high = midpoint # <<<<<<<<<<<<<< - * if val < e_id: - * low = midpoint + 1 - */ - __Pyx_INCREF(__pyx_v_midpoint); - __Pyx_DECREF(__pyx_v_high); - __pyx_v_high = __pyx_v_midpoint; - goto __pyx_L10; - } - __pyx_L10:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":400 - * if val > e_id: - * high = midpoint - * if val < e_id: # <<<<<<<<<<<<<< - * low = midpoint + 1 - * return None - */ - __pyx_t_2 = PyObject_RichCompare(__pyx_v_val, __pyx_v_e_id, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":401 - * high = midpoint - * if val < e_id: - * low = midpoint + 1 # <<<<<<<<<<<<<< - * return None - * - */ - __pyx_t_2 = PyNumber_Add(__pyx_v_midpoint, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_v_low); - __pyx_v_low = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L11; - } - __pyx_L11:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":402 - * if val < e_id: - * low = midpoint + 1 - * return None # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(Py_None); - __pyx_r = Py_None; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec_sa.BiLex.get_score", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_e_id); - __Pyx_XDECREF(__pyx_v_f_id); - __Pyx_XDECREF(__pyx_v_low); - __Pyx_XDECREF(__pyx_v_high); - __Pyx_XDECREF(__pyx_v_midpoint); - __Pyx_XDECREF(__pyx_v_val); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_5BiLex_17write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static char __pyx_doc_8_cdec_sa_5BiLex_16write_text[] = "Note: does not guarantee writing the dictionary in the original order"; -static PyObject *__pyx_pw_8_cdec_sa_5BiLex_17write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_text (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.BiLex.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_5BiLex_16write_text(((struct __pyx_obj_8_cdec_sa_BiLex *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":405 - * - * - * def write_text(self, char* filename): # <<<<<<<<<<<<<< - * """Note: does not guarantee writing the dictionary in the original order""" - * cdef i, N, e_id, f_id - */ - -static PyObject *__pyx_pf_8_cdec_sa_5BiLex_16write_text(struct __pyx_obj_8_cdec_sa_BiLex *__pyx_v_self, char *__pyx_v_filename) { - PyObject *__pyx_v_i = 0; - PyObject *__pyx_v_N = 0; - PyObject *__pyx_v_e_id = 0; - PyObject *__pyx_v_f_id = 0; - PyObject *__pyx_v_f = NULL; - PyObject *__pyx_v_score1 = NULL; - PyObject *__pyx_v_score2 = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - Py_ssize_t __pyx_t_8; - long __pyx_t_9; - long __pyx_t_10; - int __pyx_t_11; - PyObject *__pyx_t_12 = NULL; - PyObject *__pyx_t_13 = NULL; - int __pyx_t_14; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("write_text", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":409 - * cdef i, N, e_id, f_id - * - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * N = len(self.e_index) - * f_id = 0 - */ - /*with:*/ { - __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /*try:*/ { - { - __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - /*try:*/ { - __Pyx_INCREF(__pyx_t_4); - __pyx_v_f = __pyx_t_4; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":410 - * - * with open(filename, "w") as f: - * N = len(self.e_index) # <<<<<<<<<<<<<< - * f_id = 0 - * for i from 0 <= i < N: - */ - __pyx_t_4 = ((PyObject *)__pyx_v_self->e_index); - __Pyx_INCREF(__pyx_t_4); - __pyx_t_8 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_v_N = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":411 - * with open(filename, "w") as f: - * N = len(self.e_index) - * f_id = 0 # <<<<<<<<<<<<<< - * for i from 0 <= i < N: - * while self.f_index.arr[f_id+1] == i: - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_v_f_id = __pyx_int_0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":412 - * N = len(self.e_index) - * f_id = 0 - * for i from 0 <= i < N: # <<<<<<<<<<<<<< - * while self.f_index.arr[f_id+1] == i: - * f_id = f_id + 1 - */ - __pyx_t_9 = __Pyx_PyInt_AsLong(__pyx_v_N); if (unlikely((__pyx_t_9 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10++) { - __pyx_t_4 = PyInt_FromLong(__pyx_t_10); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":413 - * f_id = 0 - * for i from 0 <= i < N: - * while self.f_index.arr[f_id+1] == i: # <<<<<<<<<<<<<< - * f_id = f_id + 1 - * e_id = self.e_index.arr[i] - */ - while (1) { - __pyx_t_4 = PyNumber_Add(__pyx_v_f_id, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyInt_FromLong((__pyx_v_self->f_index->arr[__pyx_t_8])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_v_i, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!__pyx_t_11) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":414 - * for i from 0 <= i < N: - * while self.f_index.arr[f_id+1] == i: - * f_id = f_id + 1 # <<<<<<<<<<<<<< - * e_id = self.e_index.arr[i] - * score1 = self.col1.arr[i] - */ - __pyx_t_1 = PyNumber_Add(__pyx_v_f_id, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_v_f_id); - __pyx_v_f_id = __pyx_t_1; - __pyx_t_1 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":415 - * while self.f_index.arr[f_id+1] == i: - * f_id = f_id + 1 - * e_id = self.e_index.arr[i] # <<<<<<<<<<<<<< - * score1 = self.col1.arr[i] - * score2 = self.col2.arr[i] - */ - __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_1 = PyInt_FromLong((__pyx_v_self->e_index->arr[__pyx_t_8])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_v_e_id); - __pyx_v_e_id = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":416 - * f_id = f_id + 1 - * e_id = self.e_index.arr[i] - * score1 = self.col1.arr[i] # <<<<<<<<<<<<<< - * score2 = self.col2.arr[i] - * f.write("%s %s %.6f %.6f\n" % (self.id2fword[f_id], self.id2eword[e_id], score1, score2)) - */ - __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_1 = PyFloat_FromDouble((__pyx_v_self->col1->arr[__pyx_t_8])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_v_score1); - __pyx_v_score1 = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":417 - * e_id = self.e_index.arr[i] - * score1 = self.col1.arr[i] - * score2 = self.col2.arr[i] # <<<<<<<<<<<<<< - * f.write("%s %s %.6f %.6f\n" % (self.id2fword[f_id], self.id2eword[e_id], score1, score2)) - */ - __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_1 = PyFloat_FromDouble((__pyx_v_self->col2->arr[__pyx_t_8])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_v_score2); - __pyx_v_score2 = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":418 - * score1 = self.col1.arr[i] - * score2 = self.col2.arr[i] - * f.write("%s %s %.6f %.6f\n" % (self.id2fword[f_id], self.id2eword[e_id], score1, score2)) # <<<<<<<<<<<<<< - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyObject_GetItem(__pyx_v_self->id2fword, __pyx_v_f_id); if (!__pyx_t_4) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyObject_GetItem(__pyx_v_self->id2eword, __pyx_v_e_id); if (!__pyx_t_2) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_12 = PyTuple_New(4); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_score1); - PyTuple_SET_ITEM(__pyx_t_12, 2, __pyx_v_score1); - __Pyx_GIVEREF(__pyx_v_score1); - __Pyx_INCREF(__pyx_v_score2); - PyTuple_SET_ITEM(__pyx_t_12, 3, __pyx_v_score2); - __Pyx_GIVEREF(__pyx_v_score2); - __pyx_t_4 = 0; - __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_53), ((PyObject *)__pyx_t_12)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; - __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)__pyx_t_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_10 = __Pyx_PyInt_AsLong(__pyx_v_i); if (unlikely((__pyx_t_10 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":412 - * N = len(self.e_index) - * f_id = 0 - * for i from 0 <= i < N: # <<<<<<<<<<<<<< - * while self.f_index.arr[f_id+1] == i: - * f_id = f_id + 1 - */ - __pyx_t_2 = PyInt_FromLong(__pyx_t_10); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_2; - __pyx_t_2 = 0; - } - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L14_try_end; - __pyx_L7_error:; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":409 - * cdef i, N, e_id, f_id - * - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * N = len(self.e_index) - * f_id = 0 - */ - /*except:*/ { - __Pyx_AddTraceback("_cdec_sa.BiLex.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_12, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_GOTREF(__pyx_t_12); - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_12); - __Pyx_GIVEREF(__pyx_t_12); - __Pyx_INCREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_13 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_13); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __pyx_t_14 = (!__pyx_t_11); - if (__pyx_t_14) { - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_12); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_ErrRestore(__pyx_t_2, __pyx_t_12, __pyx_t_1); - __pyx_t_2 = 0; __pyx_t_12 = 0; __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - goto __pyx_L22; - } - __pyx_L22:; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L8_exception_handled; - } - __pyx_L9_except_error:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - goto __pyx_L1_error; - __pyx_L8_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - __pyx_L14_try_end:; - } - } - /*finally:*/ { - if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_54, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - goto __pyx_L23; - __pyx_L3_error:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L1_error; - __pyx_L23:; - } - - __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_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_AddTraceback("_cdec_sa.BiLex.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_i); - __Pyx_XDECREF(__pyx_v_N); - __Pyx_XDECREF(__pyx_v_e_id); - __Pyx_XDECREF(__pyx_v_f_id); - __Pyx_XDECREF(__pyx_v_f); - __Pyx_XDECREF(__pyx_v_score1); - __Pyx_XDECREF(__pyx_v_score2); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":21 - * cdef int LOWER_MASK[32] - * - * cdef void _init_lower_mask(): # <<<<<<<<<<<<<< - * cdef unsigned i - * cdef int mask = 0 - */ - -static void __pyx_f_8_cdec_sa__init_lower_mask(void) { - unsigned int __pyx_v_i; - int __pyx_v_mask; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - unsigned int __pyx_t_2; - __Pyx_RefNannySetupContext("_init_lower_mask", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":23 - * cdef void _init_lower_mask(): - * cdef unsigned i - * cdef int mask = 0 # <<<<<<<<<<<<<< - * for i in range(MIN_BOTTOM_SIZE): - * mask = (mask << 1) + 1 - */ - __pyx_v_mask = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":24 - * cdef unsigned i - * cdef int mask = 0 - * for i in range(MIN_BOTTOM_SIZE): # <<<<<<<<<<<<<< - * mask = (mask << 1) + 1 - * LOWER_MASK[i] = mask - */ - __pyx_t_1 = __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_i = __pyx_t_2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":25 - * cdef int mask = 0 - * for i in range(MIN_BOTTOM_SIZE): - * mask = (mask << 1) + 1 # <<<<<<<<<<<<<< - * LOWER_MASK[i] = mask - * - */ - __pyx_v_mask = ((__pyx_v_mask << 1) + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":26 - * for i in range(MIN_BOTTOM_SIZE): - * mask = (mask << 1) + 1 - * LOWER_MASK[i] = mask # <<<<<<<<<<<<<< - * - * _init_lower_mask() - */ - (__pyx_v_8_cdec_sa_LOWER_MASK[__pyx_v_i]) = __pyx_v_mask; - } - - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":37 - * - * - * cdef _BitSet* new_BitSet(): # <<<<<<<<<<<<<< - * cdef _BitSet* b - * - */ - -static struct __pyx_t_8_cdec_sa__BitSet *__pyx_f_8_cdec_sa_new_BitSet(void) { - struct __pyx_t_8_cdec_sa__BitSet *__pyx_v_b; - struct __pyx_t_8_cdec_sa__BitSet *__pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("new_BitSet", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":40 - * cdef _BitSet* b - * - * b = <_BitSet*> malloc(sizeof(_BitSet)) # <<<<<<<<<<<<<< - * b.bitset = 0 - * b.min_val = -1 - */ - __pyx_v_b = ((struct __pyx_t_8_cdec_sa__BitSet *)malloc((sizeof(struct __pyx_t_8_cdec_sa__BitSet)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":41 - * - * b = <_BitSet*> malloc(sizeof(_BitSet)) - * b.bitset = 0 # <<<<<<<<<<<<<< - * b.min_val = -1 - * b.max_val = -1 - */ - __pyx_v_b->bitset = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":42 - * b = <_BitSet*> malloc(sizeof(_BitSet)) - * b.bitset = 0 - * b.min_val = -1 # <<<<<<<<<<<<<< - * b.max_val = -1 - * b.size = 0 - */ - __pyx_v_b->min_val = -1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":43 - * b.bitset = 0 - * b.min_val = -1 - * b.max_val = -1 # <<<<<<<<<<<<<< - * b.size = 0 - * return b - */ - __pyx_v_b->max_val = -1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":44 - * b.min_val = -1 - * b.max_val = -1 - * b.size = 0 # <<<<<<<<<<<<<< - * return b - * - */ - __pyx_v_b->size = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":45 - * b.max_val = -1 - * b.size = 0 - * return b # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = __pyx_v_b; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":48 - * - * - * cdef int bitset_findsucc(_BitSet* b, int i): # <<<<<<<<<<<<<< - * cdef int bitset, mask - * cdef int low, high, mid - */ - -static int __pyx_f_8_cdec_sa_bitset_findsucc(struct __pyx_t_8_cdec_sa__BitSet *__pyx_v_b, int __pyx_v_i) { - int __pyx_v_bitset; - int __pyx_v_mask; - int __pyx_v_low; - int __pyx_v_high; - int __pyx_v_mid; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("bitset_findsucc", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":52 - * cdef int low, high, mid - * - * if b.max_val == -1 or i >= b.max_val: # <<<<<<<<<<<<<< - * return -1 - * if i < b.min_val: - */ - __pyx_t_1 = (__pyx_v_b->max_val == -1); - if (!__pyx_t_1) { - __pyx_t_2 = (__pyx_v_i >= __pyx_v_b->max_val); - __pyx_t_3 = __pyx_t_2; - } else { - __pyx_t_3 = __pyx_t_1; - } - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":53 - * - * if b.max_val == -1 or i >= b.max_val: - * return -1 # <<<<<<<<<<<<<< - * if i < b.min_val: - * return b.min_val - */ - __pyx_r = -1; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":54 - * if b.max_val == -1 or i >= b.max_val: - * return -1 - * if i < b.min_val: # <<<<<<<<<<<<<< - * return b.min_val - * - */ - __pyx_t_3 = (__pyx_v_i < __pyx_v_b->min_val); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":55 - * return -1 - * if i < b.min_val: - * return b.min_val # <<<<<<<<<<<<<< - * - * bitset = b.bitset & ~LOWER_MASK[i] - */ - __pyx_r = __pyx_v_b->min_val; - goto __pyx_L0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":57 - * return b.min_val - * - * bitset = b.bitset & ~LOWER_MASK[i] # <<<<<<<<<<<<<< - * low = i+1 - * high = b.max_val+1 - */ - __pyx_v_bitset = (__pyx_v_b->bitset & (~(__pyx_v_8_cdec_sa_LOWER_MASK[__pyx_v_i]))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":58 - * - * bitset = b.bitset & ~LOWER_MASK[i] - * low = i+1 # <<<<<<<<<<<<<< - * high = b.max_val+1 - * while low < high-1: - */ - __pyx_v_low = (__pyx_v_i + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":59 - * bitset = b.bitset & ~LOWER_MASK[i] - * low = i+1 - * high = b.max_val+1 # <<<<<<<<<<<<<< - * while low < high-1: - * mid = (high + low)/2 - */ - __pyx_v_high = (__pyx_v_b->max_val + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":60 - * low = i+1 - * high = b.max_val+1 - * while low < high-1: # <<<<<<<<<<<<<< - * mid = (high + low)/2 - * mask = ~(LOWER_MASK[high-1] ^ LOWER_MASK[mid-1]) - */ - while (1) { - __pyx_t_3 = (__pyx_v_low < (__pyx_v_high - 1)); - if (!__pyx_t_3) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":61 - * high = b.max_val+1 - * while low < high-1: - * mid = (high + low)/2 # <<<<<<<<<<<<<< - * mask = ~(LOWER_MASK[high-1] ^ LOWER_MASK[mid-1]) - * if bitset & mask == 0: - */ - __pyx_v_mid = __Pyx_div_long((__pyx_v_high + __pyx_v_low), 2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":62 - * while low < high-1: - * mid = (high + low)/2 - * mask = ~(LOWER_MASK[high-1] ^ LOWER_MASK[mid-1]) # <<<<<<<<<<<<<< - * if bitset & mask == 0: - * low = mid - */ - __pyx_v_mask = (~((__pyx_v_8_cdec_sa_LOWER_MASK[(__pyx_v_high - 1)]) ^ (__pyx_v_8_cdec_sa_LOWER_MASK[(__pyx_v_mid - 1)]))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":63 - * mid = (high + low)/2 - * mask = ~(LOWER_MASK[high-1] ^ LOWER_MASK[mid-1]) - * if bitset & mask == 0: # <<<<<<<<<<<<<< - * low = mid - * else: - */ - __pyx_t_3 = ((__pyx_v_bitset & __pyx_v_mask) == 0); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":64 - * mask = ~(LOWER_MASK[high-1] ^ LOWER_MASK[mid-1]) - * if bitset & mask == 0: - * low = mid # <<<<<<<<<<<<<< - * else: - * bitset = bitset & mask - */ - __pyx_v_low = __pyx_v_mid; - goto __pyx_L7; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":66 - * low = mid - * else: - * bitset = bitset & mask # <<<<<<<<<<<<<< - * high = mid - * return low - */ - __pyx_v_bitset = (__pyx_v_bitset & __pyx_v_mask); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":67 - * else: - * bitset = bitset & mask - * high = mid # <<<<<<<<<<<<<< - * return low - * - */ - __pyx_v_high = __pyx_v_mid; - } - __pyx_L7:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":68 - * bitset = bitset & mask - * high = mid - * return low # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = __pyx_v_low; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":71 - * - * - * cdef int bitset_insert(_BitSet* b, int i): # <<<<<<<<<<<<<< - * cdef int val - * - */ - -static int __pyx_f_8_cdec_sa_bitset_insert(struct __pyx_t_8_cdec_sa__BitSet *__pyx_v_b, int __pyx_v_i) { - int __pyx_v_val; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("bitset_insert", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":74 - * cdef int val - * - * val = 1 << i # <<<<<<<<<<<<<< - * if b.bitset & val == 0: - * b.bitset = b.bitset | val - */ - __pyx_v_val = (1 << __pyx_v_i); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":75 - * - * val = 1 << i - * if b.bitset & val == 0: # <<<<<<<<<<<<<< - * b.bitset = b.bitset | val - * if b.size == 0: - */ - __pyx_t_1 = ((__pyx_v_b->bitset & __pyx_v_val) == 0); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":76 - * val = 1 << i - * if b.bitset & val == 0: - * b.bitset = b.bitset | val # <<<<<<<<<<<<<< - * if b.size == 0: - * b.min_val = i - */ - __pyx_v_b->bitset = (__pyx_v_b->bitset | __pyx_v_val); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":77 - * if b.bitset & val == 0: - * b.bitset = b.bitset | val - * if b.size == 0: # <<<<<<<<<<<<<< - * b.min_val = i - * b.max_val = i - */ - __pyx_t_1 = (__pyx_v_b->size == 0); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":78 - * b.bitset = b.bitset | val - * if b.size == 0: - * b.min_val = i # <<<<<<<<<<<<<< - * b.max_val = i - * else: - */ - __pyx_v_b->min_val = __pyx_v_i; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":79 - * if b.size == 0: - * b.min_val = i - * b.max_val = i # <<<<<<<<<<<<<< - * else: - * if i < b.min_val: - */ - __pyx_v_b->max_val = __pyx_v_i; - goto __pyx_L4; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":81 - * b.max_val = i - * else: - * if i < b.min_val: # <<<<<<<<<<<<<< - * b.min_val = i - * if i > b.max_val: - */ - __pyx_t_1 = (__pyx_v_i < __pyx_v_b->min_val); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":82 - * else: - * if i < b.min_val: - * b.min_val = i # <<<<<<<<<<<<<< - * if i > b.max_val: - * b.max_val = i - */ - __pyx_v_b->min_val = __pyx_v_i; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":83 - * if i < b.min_val: - * b.min_val = i - * if i > b.max_val: # <<<<<<<<<<<<<< - * b.max_val = i - * b.size = b.size + 1 - */ - __pyx_t_1 = (__pyx_v_i > __pyx_v_b->max_val); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":84 - * b.min_val = i - * if i > b.max_val: - * b.max_val = i # <<<<<<<<<<<<<< - * b.size = b.size + 1 - * return 1 - */ - __pyx_v_b->max_val = __pyx_v_i; - goto __pyx_L6; - } - __pyx_L6:; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":85 - * if i > b.max_val: - * b.max_val = i - * b.size = b.size + 1 # <<<<<<<<<<<<<< - * return 1 - * return 0 - */ - __pyx_v_b->size = (__pyx_v_b->size + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":86 - * b.max_val = i - * b.size = b.size + 1 - * return 1 # <<<<<<<<<<<<<< - * return 0 - * - */ - __pyx_r = 1; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":87 - * b.size = b.size + 1 - * return 1 - * return 0 # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = 0; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":90 - * - * - * cdef int bitset_contains(_BitSet* b, int i): # <<<<<<<<<<<<<< - * cdef int val - * - */ - -static int __pyx_f_8_cdec_sa_bitset_contains(struct __pyx_t_8_cdec_sa__BitSet *__pyx_v_b, int __pyx_v_i) { - int __pyx_v_val; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("bitset_contains", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":93 - * cdef int val - * - * val = 1 << i # <<<<<<<<<<<<<< - * if b.bitset & val == 0: - * return 0 - */ - __pyx_v_val = (1 << __pyx_v_i); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":94 - * - * val = 1 << i - * if b.bitset & val == 0: # <<<<<<<<<<<<<< - * return 0 - * else: - */ - __pyx_t_1 = ((__pyx_v_b->bitset & __pyx_v_val) == 0); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":95 - * val = 1 << i - * if b.bitset & val == 0: - * return 0 # <<<<<<<<<<<<<< - * else: - * return 1 - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":97 - * return 0 - * else: - * return 1 # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = 1; - goto __pyx_L0; - } - __pyx_L3:; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_14BitSetIterator_1__next__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_14BitSetIterator_1__next__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__next__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_14BitSetIterator___next__(((struct __pyx_obj_8_cdec_sa_BitSetIterator *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":104 - * cdef int next_val - * - * def __next__(self): # <<<<<<<<<<<<<< - * cdef int ret_val - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_14BitSetIterator___next__(struct __pyx_obj_8_cdec_sa_BitSetIterator *__pyx_v_self) { - int __pyx_v_ret_val; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__next__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":107 - * cdef int ret_val - * - * if self.next_val == -1: # <<<<<<<<<<<<<< - * raise StopIteration() - * ret_val = self.next_val - */ - __pyx_t_1 = (__pyx_v_self->next_val == -1); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":108 - * - * if self.next_val == -1: - * raise StopIteration() # <<<<<<<<<<<<<< - * ret_val = self.next_val - * self.next_val = bitset_findsucc(self.b, ret_val) - */ - __pyx_t_2 = PyObject_Call(__pyx_builtin_StopIteration, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[6]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":109 - * if self.next_val == -1: - * raise StopIteration() - * ret_val = self.next_val # <<<<<<<<<<<<<< - * self.next_val = bitset_findsucc(self.b, ret_val) - * return ret_val - */ - __pyx_v_ret_val = __pyx_v_self->next_val; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":110 - * raise StopIteration() - * ret_val = self.next_val - * self.next_val = bitset_findsucc(self.b, ret_val) # <<<<<<<<<<<<<< - * return ret_val - * - */ - __pyx_v_self->next_val = __pyx_f_8_cdec_sa_bitset_findsucc(__pyx_v_self->b, __pyx_v_ret_val); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":111 - * ret_val = self.next_val - * self.next_val = bitset_findsucc(self.b, ret_val) - * return ret_val # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyInt_FromLong(__pyx_v_ret_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __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_2); - __Pyx_AddTraceback("_cdec_sa.BitSetIterator.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_6BitSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_6BitSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} - if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; - __pyx_r = __pyx_pf_8_cdec_sa_6BitSet___cinit__(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":122 - * cdef _BitSet* b - * - * def __cinit__(self): # <<<<<<<<<<<<<< - * self.b = new_BitSet() - * - */ - -static int __pyx_pf_8_cdec_sa_6BitSet___cinit__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":123 - * - * def __cinit__(self): - * self.b = new_BitSet() # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - __pyx_v_self->b = __pyx_f_8_cdec_sa_new_BitSet(); - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static void __pyx_pw_8_cdec_sa_6BitSet_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_8_cdec_sa_6BitSet_3__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_8_cdec_sa_6BitSet_2__dealloc__(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":125 - * self.b = new_BitSet() - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * free(self.b) - * - */ - -static void __pyx_pf_8_cdec_sa_6BitSet_2__dealloc__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":126 - * - * def __dealloc__(self): - * free(self.b) # <<<<<<<<<<<<<< - * - * def __iter__(self): - */ - free(__pyx_v_self->b); - - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_6BitSet_5__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_6BitSet_5__iter__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6BitSet_4__iter__(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":128 - * free(self.b) - * - * def __iter__(self): # <<<<<<<<<<<<<< - * cdef BitSetIterator it - * it = BitSetIterator() - */ - -static PyObject *__pyx_pf_8_cdec_sa_6BitSet_4__iter__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self) { - struct __pyx_obj_8_cdec_sa_BitSetIterator *__pyx_v_it = 0; - 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("__iter__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":130 - * def __iter__(self): - * cdef BitSetIterator it - * it = BitSetIterator() # <<<<<<<<<<<<<< - * it.b = self.b - * it.next_val = self.b.min_val - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_BitSetIterator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_it = ((struct __pyx_obj_8_cdec_sa_BitSetIterator *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":131 - * cdef BitSetIterator it - * it = BitSetIterator() - * it.b = self.b # <<<<<<<<<<<<<< - * it.next_val = self.b.min_val - * return it - */ - __pyx_v_it->b = __pyx_v_self->b; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":132 - * it = BitSetIterator() - * it.b = self.b - * it.next_val = self.b.min_val # <<<<<<<<<<<<<< - * return it - * - */ - __pyx_v_it->next_val = __pyx_v_self->b->min_val; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":133 - * it.b = self.b - * it.next_val = self.b.min_val - * return it # <<<<<<<<<<<<<< - * - * def insert(self, i): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_it)); - __pyx_r = ((PyObject *)__pyx_v_it); - 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_sa.BitSet.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_it); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_6BitSet_7insert(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_6BitSet_7insert(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("insert (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6BitSet_6insert(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self), ((PyObject *)__pyx_v_i)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":135 - * return it - * - * def insert(self, i): # <<<<<<<<<<<<<< - * return bitset_insert(self.b, i) - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_6BitSet_6insert(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("insert", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":136 - * - * def insert(self, i): - * return bitset_insert(self.b, i) # <<<<<<<<<<<<<< - * - * def findsucc(self, i): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromLong(__pyx_f_8_cdec_sa_bitset_insert(__pyx_v_self->b, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __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_2); - __Pyx_AddTraceback("_cdec_sa.BitSet.insert", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_6BitSet_9findsucc(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_6BitSet_9findsucc(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("findsucc (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6BitSet_8findsucc(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self), ((PyObject *)__pyx_v_i)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":138 - * return bitset_insert(self.b, i) - * - * def findsucc(self, i): # <<<<<<<<<<<<<< - * return bitset_findsucc(self.b, i) - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_6BitSet_8findsucc(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("findsucc", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":139 - * - * def findsucc(self, i): - * return bitset_findsucc(self.b, i) # <<<<<<<<<<<<<< - * - * def __str__(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromLong(__pyx_f_8_cdec_sa_bitset_findsucc(__pyx_v_self->b, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __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_2); - __Pyx_AddTraceback("_cdec_sa.BitSet.findsucc", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_6BitSet_11__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_6BitSet_11__str__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6BitSet_10__str__(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":141 - * return bitset_findsucc(self.b, i) - * - * def __str__(self): # <<<<<<<<<<<<<< - * return dec2bin(self.b.bitset)+" ("+str(self.b.size)+","+str(self.b.min_val)+","+str(self.b.max_val)+")" - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_6BitSet_10__str__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__str__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":142 - * - * def __str__(self): - * return dec2bin(self.b.bitset)+" ("+str(self.b.size)+","+str(self.b.min_val)+","+str(self.b.max_val)+")" # <<<<<<<<<<<<<< - * - * def min(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((PyObject *)__pyx_f_8_cdec_sa_dec2bin(__pyx_v_self->b->bitset)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyNumber_Add(__pyx_t_1, ((PyObject *)__pyx_kp_s_55)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->b->size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Add(((PyObject *)__pyx_t_2), __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Add(__pyx_t_3, ((PyObject *)__pyx_kp_s_4)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyInt_FromLong(__pyx_v_self->b->min_val); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Add(__pyx_t_2, ((PyObject *)__pyx_kp_s_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyInt_FromLong(__pyx_v_self->b->max_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__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(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __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 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Add(__pyx_t_1, ((PyObject *)__pyx_kp_s_56)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __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_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.BitSet.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_6BitSet_13min(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_6BitSet_13min(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("min (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6BitSet_12min(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":144 - * return dec2bin(self.b.bitset)+" ("+str(self.b.size)+","+str(self.b.min_val)+","+str(self.b.max_val)+")" - * - * def min(self): # <<<<<<<<<<<<<< - * return self.b.min_val - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_6BitSet_12min(struct __pyx_obj_8_cdec_sa_BitSet *__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("min", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":145 - * - * def min(self): - * return self.b.min_val # <<<<<<<<<<<<<< - * - * def max(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->b->min_val); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __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_AddTraceback("_cdec_sa.BitSet.min", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_6BitSet_15max(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_6BitSet_15max(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("max (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6BitSet_14max(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":147 - * return self.b.min_val - * - * def max(self): # <<<<<<<<<<<<<< - * return self.b.max_val - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_6BitSet_14max(struct __pyx_obj_8_cdec_sa_BitSet *__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("max", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":148 - * - * def max(self): - * return self.b.max_val # <<<<<<<<<<<<<< - * - * def __len__(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->b->max_val); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __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_AddTraceback("_cdec_sa.BitSet.max", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static Py_ssize_t __pyx_pw_8_cdec_sa_6BitSet_17__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_8_cdec_sa_6BitSet_17__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6BitSet_16__len__(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":150 - * return self.b.max_val - * - * def __len__(self): # <<<<<<<<<<<<<< - * return self.b.size - * - */ - -static Py_ssize_t __pyx_pf_8_cdec_sa_6BitSet_16__len__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":151 - * - * def __len__(self): - * return self.b.size # <<<<<<<<<<<<<< - * - * def __contains__(self, i): - */ - __pyx_r = __pyx_v_self->b->size; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_6BitSet_19__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ -static int __pyx_pw_8_cdec_sa_6BitSet_19__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6BitSet_18__contains__(((struct __pyx_obj_8_cdec_sa_BitSet *)__pyx_v_self), ((PyObject *)__pyx_v_i)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":153 - * return self.b.size - * - * def __contains__(self, i): # <<<<<<<<<<<<<< - * return bool(bitset_contains(self.b, i)) - * - */ - -static int __pyx_pf_8_cdec_sa_6BitSet_18__contains__(struct __pyx_obj_8_cdec_sa_BitSet *__pyx_v_self, PyObject *__pyx_v_i) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__contains__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":154 - * - * def __contains__(self, i): - * return bool(bitset_contains(self.b, i)) # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromLong(__pyx_f_8_cdec_sa_bitset_contains(__pyx_v_self->b, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = (!(!__pyx_t_3)); - goto __pyx_L0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_cdec_sa.BitSet.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":157 - * - * - * cdef str dec2bin(long i): # <<<<<<<<<<<<<< - * cdef str result = "" - * cdef unsigned d - */ - -static PyObject *__pyx_f_8_cdec_sa_dec2bin(long __pyx_v_i) { - PyObject *__pyx_v_result = 0; - CYTHON_UNUSED unsigned int __pyx_v_d; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - unsigned int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("dec2bin", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":158 - * - * cdef str dec2bin(long i): - * cdef str result = "" # <<<<<<<<<<<<<< - * cdef unsigned d - * for d in range(MIN_BOTTOM_SIZE): - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_42)); - __pyx_v_result = __pyx_kp_s_42; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":160 - * cdef str result = "" - * cdef unsigned d - * for d in range(MIN_BOTTOM_SIZE): # <<<<<<<<<<<<<< - * if i & LOWER_MASK[0] == 0: - * result = "0"+result - */ - __pyx_t_1 = __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE; - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_v_d = __pyx_t_2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":161 - * cdef unsigned d - * for d in range(MIN_BOTTOM_SIZE): - * if i & LOWER_MASK[0] == 0: # <<<<<<<<<<<<<< - * result = "0"+result - * else: - */ - __pyx_t_3 = ((__pyx_v_i & (__pyx_v_8_cdec_sa_LOWER_MASK[0])) == 0); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":162 - * for d in range(MIN_BOTTOM_SIZE): - * if i & LOWER_MASK[0] == 0: - * result = "0"+result # <<<<<<<<<<<<<< - * else: - * result = "1"+result - */ - __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_kp_s__0), ((PyObject *)__pyx_v_result)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __Pyx_DECREF(((PyObject *)__pyx_v_result)); - __pyx_v_result = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L5; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":164 - * result = "0"+result - * else: - * result = "1"+result # <<<<<<<<<<<<<< - * i = i >> 1 - * return result - */ - __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_kp_s__1), ((PyObject *)__pyx_v_result)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __Pyx_DECREF(((PyObject *)__pyx_v_result)); - __pyx_v_result = __pyx_t_4; - __pyx_t_4 = 0; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":165 - * else: - * result = "1"+result - * i = i >> 1 # <<<<<<<<<<<<<< - * return result - * - */ - __pyx_v_i = (__pyx_v_i >> 1); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":166 - * result = "1"+result - * i = i >> 1 - * return result # <<<<<<<<<<<<<< - * - * cdef struct _VEB: - */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - __pyx_r = __pyx_v_result; - goto __pyx_L0; - - __pyx_r = ((PyObject*)Py_None); __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec_sa.dec2bin", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":177 - * void** bottom - * - * cdef _VEB* new_VEB(int n): # <<<<<<<<<<<<<< - * cdef _VEB* veb - * cdef int num_bits, num_top_bits, i - */ - -static struct __pyx_t_8_cdec_sa__VEB *__pyx_f_8_cdec_sa_new_VEB(int __pyx_v_n) { - struct __pyx_t_8_cdec_sa__VEB *__pyx_v_veb; - int __pyx_v_num_bits; - struct __pyx_t_8_cdec_sa__VEB *__pyx_r; - __Pyx_RefNannyDeclarations - double __pyx_t_1; - double __pyx_t_2; - int __pyx_t_3; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("new_VEB", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":181 - * cdef int num_bits, num_top_bits, i - * - * veb = <_VEB*> malloc(sizeof(_VEB)) # <<<<<<<<<<<<<< - * - * num_bits = int(ceil(log(n) / log(2))) - */ - __pyx_v_veb = ((struct __pyx_t_8_cdec_sa__VEB *)malloc((sizeof(struct __pyx_t_8_cdec_sa__VEB)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":183 - * veb = <_VEB*> malloc(sizeof(_VEB)) - * - * num_bits = int(ceil(log(n) / log(2))) # <<<<<<<<<<<<<< - * veb.num_bottom_bits = num_bits/2 - * if veb.num_bottom_bits < MIN_BOTTOM_BITS: - */ - __pyx_t_1 = log(__pyx_v_n); - __pyx_t_2 = log(2.0); - if (unlikely(__pyx_t_2 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[6]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_num_bits = ((int)ceil((__pyx_t_1 / __pyx_t_2))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":184 - * - * num_bits = int(ceil(log(n) / log(2))) - * veb.num_bottom_bits = num_bits/2 # <<<<<<<<<<<<<< - * if veb.num_bottom_bits < MIN_BOTTOM_BITS: - * veb.num_bottom_bits = MIN_BOTTOM_BITS - */ - __pyx_v_veb->num_bottom_bits = __Pyx_div_long(__pyx_v_num_bits, 2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":185 - * num_bits = int(ceil(log(n) / log(2))) - * veb.num_bottom_bits = num_bits/2 - * if veb.num_bottom_bits < MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< - * veb.num_bottom_bits = MIN_BOTTOM_BITS - * veb.top_universe_size = (n >> veb.num_bottom_bits) + 1 - */ - __pyx_t_3 = (__pyx_v_veb->num_bottom_bits < __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":186 - * veb.num_bottom_bits = num_bits/2 - * if veb.num_bottom_bits < MIN_BOTTOM_BITS: - * veb.num_bottom_bits = MIN_BOTTOM_BITS # <<<<<<<<<<<<<< - * veb.top_universe_size = (n >> veb.num_bottom_bits) + 1 - * - */ - __pyx_v_veb->num_bottom_bits = __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":187 - * if veb.num_bottom_bits < MIN_BOTTOM_BITS: - * veb.num_bottom_bits = MIN_BOTTOM_BITS - * veb.top_universe_size = (n >> veb.num_bottom_bits) + 1 # <<<<<<<<<<<<<< - * - * veb.bottom = malloc(veb.top_universe_size * sizeof(void*)) - */ - __pyx_v_veb->top_universe_size = ((__pyx_v_n >> __pyx_v_veb->num_bottom_bits) + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":189 - * veb.top_universe_size = (n >> veb.num_bottom_bits) + 1 - * - * veb.bottom = malloc(veb.top_universe_size * sizeof(void*)) # <<<<<<<<<<<<<< - * memset(veb.bottom, 0, veb.top_universe_size * sizeof(void*)) - * - */ - __pyx_v_veb->bottom = ((void **)malloc((__pyx_v_veb->top_universe_size * (sizeof(void *))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":190 - * - * veb.bottom = malloc(veb.top_universe_size * sizeof(void*)) - * memset(veb.bottom, 0, veb.top_universe_size * sizeof(void*)) # <<<<<<<<<<<<<< - * - * if veb.top_universe_size > MIN_BOTTOM_SIZE: - */ - memset(__pyx_v_veb->bottom, 0, (__pyx_v_veb->top_universe_size * (sizeof(void *)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":192 - * memset(veb.bottom, 0, veb.top_universe_size * sizeof(void*)) - * - * if veb.top_universe_size > MIN_BOTTOM_SIZE: # <<<<<<<<<<<<<< - * veb.top = new_VEB(veb.top_universe_size) - * else: - */ - __pyx_t_3 = (__pyx_v_veb->top_universe_size > __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":193 - * - * if veb.top_universe_size > MIN_BOTTOM_SIZE: - * veb.top = new_VEB(veb.top_universe_size) # <<<<<<<<<<<<<< - * else: - * veb.top = new_BitSet() - */ - __pyx_v_veb->top = __pyx_f_8_cdec_sa_new_VEB(__pyx_v_veb->top_universe_size); - goto __pyx_L4; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":195 - * veb.top = new_VEB(veb.top_universe_size) - * else: - * veb.top = new_BitSet() # <<<<<<<<<<<<<< - * - * veb.max_val = -1 - */ - __pyx_v_veb->top = __pyx_f_8_cdec_sa_new_BitSet(); - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":197 - * veb.top = new_BitSet() - * - * veb.max_val = -1 # <<<<<<<<<<<<<< - * veb.min_val = -1 - * veb.size = 0 - */ - __pyx_v_veb->max_val = -1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":198 - * - * veb.max_val = -1 - * veb.min_val = -1 # <<<<<<<<<<<<<< - * veb.size = 0 - * return veb - */ - __pyx_v_veb->min_val = -1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":199 - * veb.max_val = -1 - * veb.min_val = -1 - * veb.size = 0 # <<<<<<<<<<<<<< - * return veb - * - */ - __pyx_v_veb->size = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":200 - * veb.min_val = -1 - * veb.size = 0 - * return veb # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = __pyx_v_veb; - goto __pyx_L0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_WriteUnraisable("_cdec_sa.new_VEB", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":203 - * - * - * cdef int VEB_insert(_VEB* veb, int i): # <<<<<<<<<<<<<< - * cdef _VEB* subv - * cdef _BitSet* subb - */ - -static int __pyx_f_8_cdec_sa_VEB_insert(struct __pyx_t_8_cdec_sa__VEB *__pyx_v_veb, int __pyx_v_i) { - struct __pyx_t_8_cdec_sa__VEB *__pyx_v_subv; - struct __pyx_t_8_cdec_sa__BitSet *__pyx_v_subb; - int __pyx_v_a; - int __pyx_v_b; - int __pyx_v_tmp; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("VEB_insert", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":208 - * cdef int a, b, tmp - * - * if veb.size == 0: # <<<<<<<<<<<<<< - * veb.min_val = i - * veb.max_val = i - */ - __pyx_t_1 = (__pyx_v_veb->size == 0); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":209 - * - * if veb.size == 0: - * veb.min_val = i # <<<<<<<<<<<<<< - * veb.max_val = i - * elif i == veb.min_val or i == veb.max_val: - */ - __pyx_v_veb->min_val = __pyx_v_i; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":210 - * if veb.size == 0: - * veb.min_val = i - * veb.max_val = i # <<<<<<<<<<<<<< - * elif i == veb.min_val or i == veb.max_val: - * return 0 - */ - __pyx_v_veb->max_val = __pyx_v_i; - goto __pyx_L3; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":211 - * veb.min_val = i - * veb.max_val = i - * elif i == veb.min_val or i == veb.max_val: # <<<<<<<<<<<<<< - * return 0 - * else: - */ - __pyx_t_1 = (__pyx_v_i == __pyx_v_veb->min_val); - if (!__pyx_t_1) { - __pyx_t_2 = (__pyx_v_i == __pyx_v_veb->max_val); - __pyx_t_3 = __pyx_t_2; - } else { - __pyx_t_3 = __pyx_t_1; - } - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":212 - * veb.max_val = i - * elif i == veb.min_val or i == veb.max_val: - * return 0 # <<<<<<<<<<<<<< - * else: - * if i < veb.min_val: - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":214 - * return 0 - * else: - * if i < veb.min_val: # <<<<<<<<<<<<<< - * tmp = i - * i = veb.min_val - */ - __pyx_t_3 = (__pyx_v_i < __pyx_v_veb->min_val); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":215 - * else: - * if i < veb.min_val: - * tmp = i # <<<<<<<<<<<<<< - * i = veb.min_val - * veb.min_val = tmp - */ - __pyx_v_tmp = __pyx_v_i; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":216 - * if i < veb.min_val: - * tmp = i - * i = veb.min_val # <<<<<<<<<<<<<< - * veb.min_val = tmp - * a = i >> veb.num_bottom_bits - */ - __pyx_v_i = __pyx_v_veb->min_val; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":217 - * tmp = i - * i = veb.min_val - * veb.min_val = tmp # <<<<<<<<<<<<<< - * a = i >> veb.num_bottom_bits - * b = i & LOWER_MASK[veb.num_bottom_bits-1] - */ - __pyx_v_veb->min_val = __pyx_v_tmp; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":218 - * i = veb.min_val - * veb.min_val = tmp - * a = i >> veb.num_bottom_bits # <<<<<<<<<<<<<< - * b = i & LOWER_MASK[veb.num_bottom_bits-1] - * if veb.bottom[a] == NULL: - */ - __pyx_v_a = (__pyx_v_i >> __pyx_v_veb->num_bottom_bits); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":219 - * veb.min_val = tmp - * a = i >> veb.num_bottom_bits - * b = i & LOWER_MASK[veb.num_bottom_bits-1] # <<<<<<<<<<<<<< - * if veb.bottom[a] == NULL: - * if veb.top_universe_size > MIN_BOTTOM_SIZE: - */ - __pyx_v_b = (__pyx_v_i & (__pyx_v_8_cdec_sa_LOWER_MASK[(__pyx_v_veb->num_bottom_bits - 1)])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":220 - * a = i >> veb.num_bottom_bits - * b = i & LOWER_MASK[veb.num_bottom_bits-1] - * if veb.bottom[a] == NULL: # <<<<<<<<<<<<<< - * if veb.top_universe_size > MIN_BOTTOM_SIZE: - * subv = <_VEB*> veb.top - */ - __pyx_t_3 = ((__pyx_v_veb->bottom[__pyx_v_a]) == NULL); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":221 - * b = i & LOWER_MASK[veb.num_bottom_bits-1] - * if veb.bottom[a] == NULL: - * if veb.top_universe_size > MIN_BOTTOM_SIZE: # <<<<<<<<<<<<<< - * subv = <_VEB*> veb.top - * VEB_insert(subv, a) - */ - __pyx_t_3 = (__pyx_v_veb->top_universe_size > __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":222 - * if veb.bottom[a] == NULL: - * if veb.top_universe_size > MIN_BOTTOM_SIZE: - * subv = <_VEB*> veb.top # <<<<<<<<<<<<<< - * VEB_insert(subv, a) - * else: - */ - __pyx_v_subv = ((struct __pyx_t_8_cdec_sa__VEB *)__pyx_v_veb->top); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":223 - * if veb.top_universe_size > MIN_BOTTOM_SIZE: - * subv = <_VEB*> veb.top - * VEB_insert(subv, a) # <<<<<<<<<<<<<< - * else: - * subb = <_BitSet*> veb.top - */ - __pyx_f_8_cdec_sa_VEB_insert(__pyx_v_subv, __pyx_v_a); - goto __pyx_L6; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":225 - * VEB_insert(subv, a) - * else: - * subb = <_BitSet*> veb.top # <<<<<<<<<<<<<< - * bitset_insert(subb, a) - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - */ - __pyx_v_subb = ((struct __pyx_t_8_cdec_sa__BitSet *)__pyx_v_veb->top); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":226 - * else: - * subb = <_BitSet*> veb.top - * bitset_insert(subb, a) # <<<<<<<<<<<<<< - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - * veb.bottom[a] = new_VEB(1 << veb.num_bottom_bits) - */ - __pyx_f_8_cdec_sa_bitset_insert(__pyx_v_subb, __pyx_v_a); - } - __pyx_L6:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":227 - * subb = <_BitSet*> veb.top - * bitset_insert(subb, a) - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< - * veb.bottom[a] = new_VEB(1 << veb.num_bottom_bits) - * else: - */ - __pyx_t_3 = (__pyx_v_veb->num_bottom_bits > __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":228 - * bitset_insert(subb, a) - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - * veb.bottom[a] = new_VEB(1 << veb.num_bottom_bits) # <<<<<<<<<<<<<< - * else: - * veb.bottom[a] = new_BitSet() - */ - (__pyx_v_veb->bottom[__pyx_v_a]) = __pyx_f_8_cdec_sa_new_VEB((1 << __pyx_v_veb->num_bottom_bits)); - goto __pyx_L7; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":230 - * veb.bottom[a] = new_VEB(1 << veb.num_bottom_bits) - * else: - * veb.bottom[a] = new_BitSet() # <<<<<<<<<<<<<< - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - * subv = <_VEB*> veb.bottom[a] - */ - (__pyx_v_veb->bottom[__pyx_v_a]) = __pyx_f_8_cdec_sa_new_BitSet(); - } - __pyx_L7:; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":231 - * else: - * veb.bottom[a] = new_BitSet() - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< - * subv = <_VEB*> veb.bottom[a] - * if VEB_insert(subv, b) == 0: - */ - __pyx_t_3 = (__pyx_v_veb->num_bottom_bits > __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":232 - * veb.bottom[a] = new_BitSet() - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - * subv = <_VEB*> veb.bottom[a] # <<<<<<<<<<<<<< - * if VEB_insert(subv, b) == 0: - * return 0 - */ - __pyx_v_subv = ((struct __pyx_t_8_cdec_sa__VEB *)(__pyx_v_veb->bottom[__pyx_v_a])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":233 - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - * subv = <_VEB*> veb.bottom[a] - * if VEB_insert(subv, b) == 0: # <<<<<<<<<<<<<< - * return 0 - * else: - */ - __pyx_t_3 = (__pyx_f_8_cdec_sa_VEB_insert(__pyx_v_subv, __pyx_v_b) == 0); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":234 - * subv = <_VEB*> veb.bottom[a] - * if VEB_insert(subv, b) == 0: - * return 0 # <<<<<<<<<<<<<< - * else: - * subb = <_BitSet*> veb.bottom[a] - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L9; - } - __pyx_L9:; - goto __pyx_L8; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":236 - * return 0 - * else: - * subb = <_BitSet*> veb.bottom[a] # <<<<<<<<<<<<<< - * if bitset_insert(subb, b) == 0: - * return 0 - */ - __pyx_v_subb = ((struct __pyx_t_8_cdec_sa__BitSet *)(__pyx_v_veb->bottom[__pyx_v_a])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":237 - * else: - * subb = <_BitSet*> veb.bottom[a] - * if bitset_insert(subb, b) == 0: # <<<<<<<<<<<<<< - * return 0 - * - */ - __pyx_t_3 = (__pyx_f_8_cdec_sa_bitset_insert(__pyx_v_subb, __pyx_v_b) == 0); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":238 - * subb = <_BitSet*> veb.bottom[a] - * if bitset_insert(subb, b) == 0: - * return 0 # <<<<<<<<<<<<<< - * - * if i > veb.max_val: - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L10; - } - __pyx_L10:; - } - __pyx_L8:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":240 - * return 0 - * - * if i > veb.max_val: # <<<<<<<<<<<<<< - * veb.max_val = i - * veb.size = veb.size + 1 - */ - __pyx_t_3 = (__pyx_v_i > __pyx_v_veb->max_val); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":241 - * - * if i > veb.max_val: - * veb.max_val = i # <<<<<<<<<<<<<< - * veb.size = veb.size + 1 - * return 1 - */ - __pyx_v_veb->max_val = __pyx_v_i; - goto __pyx_L11; - } - __pyx_L11:; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":242 - * if i > veb.max_val: - * veb.max_val = i - * veb.size = veb.size + 1 # <<<<<<<<<<<<<< - * return 1 - * - */ - __pyx_v_veb->size = (__pyx_v_veb->size + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":243 - * veb.max_val = i - * veb.size = veb.size + 1 - * return 1 # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = 1; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":246 - * - * - * cdef del_VEB(_VEB* veb): # <<<<<<<<<<<<<< - * cdef int i - * - */ - -static PyObject *__pyx_f_8_cdec_sa_del_VEB(struct __pyx_t_8_cdec_sa__VEB *__pyx_v_veb) { - int __pyx_v_i; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("del_VEB", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":249 - * cdef int i - * - * if veb.top_universe_size > MIN_BOTTOM_SIZE: # <<<<<<<<<<<<<< - * i = (<_VEB*> veb.top).min_val - * else: - */ - __pyx_t_1 = (__pyx_v_veb->top_universe_size > __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":250 - * - * if veb.top_universe_size > MIN_BOTTOM_SIZE: - * i = (<_VEB*> veb.top).min_val # <<<<<<<<<<<<<< - * else: - * i = (<_BitSet*> veb.top).min_val - */ - __pyx_v_i = ((struct __pyx_t_8_cdec_sa__VEB *)__pyx_v_veb->top)->min_val; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":252 - * i = (<_VEB*> veb.top).min_val - * else: - * i = (<_BitSet*> veb.top).min_val # <<<<<<<<<<<<<< - * - * while i != -1: - */ - __pyx_v_i = ((struct __pyx_t_8_cdec_sa__BitSet *)__pyx_v_veb->top)->min_val; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":254 - * i = (<_BitSet*> veb.top).min_val - * - * while i != -1: # <<<<<<<<<<<<<< - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - * del_VEB(<_VEB*> veb.bottom[i]) - */ - while (1) { - __pyx_t_1 = (__pyx_v_i != -1); - if (!__pyx_t_1) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":255 - * - * while i != -1: - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< - * del_VEB(<_VEB*> veb.bottom[i]) - * else: - */ - __pyx_t_1 = (__pyx_v_veb->num_bottom_bits > __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":256 - * while i != -1: - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - * del_VEB(<_VEB*> veb.bottom[i]) # <<<<<<<<<<<<<< - * else: - * free(<_BitSet*> veb.bottom[i]) - */ - __pyx_t_2 = __pyx_f_8_cdec_sa_del_VEB(((struct __pyx_t_8_cdec_sa__VEB *)(__pyx_v_veb->bottom[__pyx_v_i]))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L6; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":258 - * del_VEB(<_VEB*> veb.bottom[i]) - * else: - * free(<_BitSet*> veb.bottom[i]) # <<<<<<<<<<<<<< - * - * if veb.top_universe_size > MIN_BOTTOM_SIZE: - */ - free(((struct __pyx_t_8_cdec_sa__BitSet *)(__pyx_v_veb->bottom[__pyx_v_i]))); - } - __pyx_L6:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":260 - * free(<_BitSet*> veb.bottom[i]) - * - * if veb.top_universe_size > MIN_BOTTOM_SIZE: # <<<<<<<<<<<<<< - * i = VEB_findsucc(<_VEB*> veb.top, i) - * else: - */ - __pyx_t_1 = (__pyx_v_veb->top_universe_size > __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":261 - * - * if veb.top_universe_size > MIN_BOTTOM_SIZE: - * i = VEB_findsucc(<_VEB*> veb.top, i) # <<<<<<<<<<<<<< - * else: - * i = bitset_findsucc(<_BitSet*> veb.top, i) - */ - __pyx_v_i = __pyx_f_8_cdec_sa_VEB_findsucc(((struct __pyx_t_8_cdec_sa__VEB *)__pyx_v_veb->top), __pyx_v_i); - goto __pyx_L7; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":263 - * i = VEB_findsucc(<_VEB*> veb.top, i) - * else: - * i = bitset_findsucc(<_BitSet*> veb.top, i) # <<<<<<<<<<<<<< - * - * if veb.top_universe_size > MIN_BOTTOM_SIZE: - */ - __pyx_v_i = __pyx_f_8_cdec_sa_bitset_findsucc(((struct __pyx_t_8_cdec_sa__BitSet *)__pyx_v_veb->top), __pyx_v_i); - } - __pyx_L7:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":265 - * i = bitset_findsucc(<_BitSet*> veb.top, i) - * - * if veb.top_universe_size > MIN_BOTTOM_SIZE: # <<<<<<<<<<<<<< - * del_VEB(<_VEB*> veb.top) - * else: - */ - __pyx_t_1 = (__pyx_v_veb->top_universe_size > __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":266 - * - * if veb.top_universe_size > MIN_BOTTOM_SIZE: - * del_VEB(<_VEB*> veb.top) # <<<<<<<<<<<<<< - * else: - * free(<_BitSet*> veb.top) - */ - __pyx_t_2 = __pyx_f_8_cdec_sa_del_VEB(((struct __pyx_t_8_cdec_sa__VEB *)__pyx_v_veb->top)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 266; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L8; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":268 - * del_VEB(<_VEB*> veb.top) - * else: - * free(<_BitSet*> veb.top) # <<<<<<<<<<<<<< - * free(veb.bottom) - * free(veb) - */ - free(((struct __pyx_t_8_cdec_sa__BitSet *)__pyx_v_veb->top)); - } - __pyx_L8:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":269 - * else: - * free(<_BitSet*> veb.top) - * free(veb.bottom) # <<<<<<<<<<<<<< - * free(veb) - * - */ - free(__pyx_v_veb->bottom); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":270 - * free(<_BitSet*> veb.top) - * free(veb.bottom) - * free(veb) # <<<<<<<<<<<<<< - * - * - */ - free(__pyx_v_veb); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_cdec_sa.del_VEB", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":273 - * - * - * cdef int VEB_findsucc(_VEB* veb, int i): # <<<<<<<<<<<<<< - * cdef _VEB* subv - * cdef _BitSet* subb - */ - -static int __pyx_f_8_cdec_sa_VEB_findsucc(struct __pyx_t_8_cdec_sa__VEB *__pyx_v_veb, int __pyx_v_i) { - struct __pyx_t_8_cdec_sa__VEB *__pyx_v_subv; - struct __pyx_t_8_cdec_sa__BitSet *__pyx_v_subb; - int __pyx_v_a; - int __pyx_v_b; - int __pyx_v_j; - int __pyx_v_c; - int __pyx_v_found; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("VEB_findsucc", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":278 - * cdef int a, b, j, c, found - * - * if veb.max_val == -1 or i>=veb.max_val: # <<<<<<<<<<<<<< - * return -1 - * if i < veb.min_val: - */ - __pyx_t_1 = (__pyx_v_veb->max_val == -1); - if (!__pyx_t_1) { - __pyx_t_2 = (__pyx_v_i >= __pyx_v_veb->max_val); - __pyx_t_3 = __pyx_t_2; - } else { - __pyx_t_3 = __pyx_t_1; - } - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":279 - * - * if veb.max_val == -1 or i>=veb.max_val: - * return -1 # <<<<<<<<<<<<<< - * if i < veb.min_val: - * return veb.min_val - */ - __pyx_r = -1; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":280 - * if veb.max_val == -1 or i>=veb.max_val: - * return -1 - * if i < veb.min_val: # <<<<<<<<<<<<<< - * return veb.min_val - * - */ - __pyx_t_3 = (__pyx_v_i < __pyx_v_veb->min_val); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":281 - * return -1 - * if i < veb.min_val: - * return veb.min_val # <<<<<<<<<<<<<< - * - * a = i >> veb.num_bottom_bits - */ - __pyx_r = __pyx_v_veb->min_val; - goto __pyx_L0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":283 - * return veb.min_val - * - * a = i >> veb.num_bottom_bits # <<<<<<<<<<<<<< - * b = i & LOWER_MASK[veb.num_bottom_bits-1] - * found = 0 - */ - __pyx_v_a = (__pyx_v_i >> __pyx_v_veb->num_bottom_bits); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":284 - * - * a = i >> veb.num_bottom_bits - * b = i & LOWER_MASK[veb.num_bottom_bits-1] # <<<<<<<<<<<<<< - * found = 0 - * if veb.bottom[a] != NULL: - */ - __pyx_v_b = (__pyx_v_i & (__pyx_v_8_cdec_sa_LOWER_MASK[(__pyx_v_veb->num_bottom_bits - 1)])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":285 - * a = i >> veb.num_bottom_bits - * b = i & LOWER_MASK[veb.num_bottom_bits-1] - * found = 0 # <<<<<<<<<<<<<< - * if veb.bottom[a] != NULL: - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - */ - __pyx_v_found = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":286 - * b = i & LOWER_MASK[veb.num_bottom_bits-1] - * found = 0 - * if veb.bottom[a] != NULL: # <<<<<<<<<<<<<< - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - * subv = <_VEB*> veb.bottom[a] - */ - __pyx_t_3 = ((__pyx_v_veb->bottom[__pyx_v_a]) != NULL); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":287 - * found = 0 - * if veb.bottom[a] != NULL: - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< - * subv = <_VEB*> veb.bottom[a] - * if subv.max_val > b: - */ - __pyx_t_3 = (__pyx_v_veb->num_bottom_bits > __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":288 - * if veb.bottom[a] != NULL: - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - * subv = <_VEB*> veb.bottom[a] # <<<<<<<<<<<<<< - * if subv.max_val > b: - * j = (a << veb.num_bottom_bits) + VEB_findsucc(subv, b) - */ - __pyx_v_subv = ((struct __pyx_t_8_cdec_sa__VEB *)(__pyx_v_veb->bottom[__pyx_v_a])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":289 - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - * subv = <_VEB*> veb.bottom[a] - * if subv.max_val > b: # <<<<<<<<<<<<<< - * j = (a << veb.num_bottom_bits) + VEB_findsucc(subv, b) - * found = 1 - */ - __pyx_t_3 = (__pyx_v_subv->max_val > __pyx_v_b); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":290 - * subv = <_VEB*> veb.bottom[a] - * if subv.max_val > b: - * j = (a << veb.num_bottom_bits) + VEB_findsucc(subv, b) # <<<<<<<<<<<<<< - * found = 1 - * else: - */ - __pyx_v_j = ((__pyx_v_a << __pyx_v_veb->num_bottom_bits) + __pyx_f_8_cdec_sa_VEB_findsucc(__pyx_v_subv, __pyx_v_b)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":291 - * if subv.max_val > b: - * j = (a << veb.num_bottom_bits) + VEB_findsucc(subv, b) - * found = 1 # <<<<<<<<<<<<<< - * else: - * subb = <_BitSet*> veb.bottom[a] - */ - __pyx_v_found = 1; - goto __pyx_L7; - } - __pyx_L7:; - goto __pyx_L6; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":293 - * found = 1 - * else: - * subb = <_BitSet*> veb.bottom[a] # <<<<<<<<<<<<<< - * if subb.max_val > b: - * j = (a << veb.num_bottom_bits) + bitset_findsucc(subb, b) - */ - __pyx_v_subb = ((struct __pyx_t_8_cdec_sa__BitSet *)(__pyx_v_veb->bottom[__pyx_v_a])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":294 - * else: - * subb = <_BitSet*> veb.bottom[a] - * if subb.max_val > b: # <<<<<<<<<<<<<< - * j = (a << veb.num_bottom_bits) + bitset_findsucc(subb, b) - * found = 1 - */ - __pyx_t_3 = (__pyx_v_subb->max_val > __pyx_v_b); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":295 - * subb = <_BitSet*> veb.bottom[a] - * if subb.max_val > b: - * j = (a << veb.num_bottom_bits) + bitset_findsucc(subb, b) # <<<<<<<<<<<<<< - * found = 1 - * if found==0: - */ - __pyx_v_j = ((__pyx_v_a << __pyx_v_veb->num_bottom_bits) + __pyx_f_8_cdec_sa_bitset_findsucc(__pyx_v_subb, __pyx_v_b)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":296 - * if subb.max_val > b: - * j = (a << veb.num_bottom_bits) + bitset_findsucc(subb, b) - * found = 1 # <<<<<<<<<<<<<< - * if found==0: - * if veb.top_universe_size > MIN_BOTTOM_SIZE: - */ - __pyx_v_found = 1; - goto __pyx_L8; - } - __pyx_L8:; - } - __pyx_L6:; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":297 - * j = (a << veb.num_bottom_bits) + bitset_findsucc(subb, b) - * found = 1 - * if found==0: # <<<<<<<<<<<<<< - * if veb.top_universe_size > MIN_BOTTOM_SIZE: - * subv = <_VEB*> veb.top - */ - __pyx_t_3 = (__pyx_v_found == 0); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":298 - * found = 1 - * if found==0: - * if veb.top_universe_size > MIN_BOTTOM_SIZE: # <<<<<<<<<<<<<< - * subv = <_VEB*> veb.top - * c = VEB_findsucc(subv, a) - */ - __pyx_t_3 = (__pyx_v_veb->top_universe_size > __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":299 - * if found==0: - * if veb.top_universe_size > MIN_BOTTOM_SIZE: - * subv = <_VEB*> veb.top # <<<<<<<<<<<<<< - * c = VEB_findsucc(subv, a) - * else: - */ - __pyx_v_subv = ((struct __pyx_t_8_cdec_sa__VEB *)__pyx_v_veb->top); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":300 - * if veb.top_universe_size > MIN_BOTTOM_SIZE: - * subv = <_VEB*> veb.top - * c = VEB_findsucc(subv, a) # <<<<<<<<<<<<<< - * else: - * subb = <_BitSet*> veb.top - */ - __pyx_v_c = __pyx_f_8_cdec_sa_VEB_findsucc(__pyx_v_subv, __pyx_v_a); - goto __pyx_L10; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":302 - * c = VEB_findsucc(subv, a) - * else: - * subb = <_BitSet*> veb.top # <<<<<<<<<<<<<< - * c = bitset_findsucc(subb, a) - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - */ - __pyx_v_subb = ((struct __pyx_t_8_cdec_sa__BitSet *)__pyx_v_veb->top); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":303 - * else: - * subb = <_BitSet*> veb.top - * c = bitset_findsucc(subb, a) # <<<<<<<<<<<<<< - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - * subv = <_VEB*> veb.bottom[c] - */ - __pyx_v_c = __pyx_f_8_cdec_sa_bitset_findsucc(__pyx_v_subb, __pyx_v_a); - } - __pyx_L10:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":304 - * subb = <_BitSet*> veb.top - * c = bitset_findsucc(subb, a) - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< - * subv = <_VEB*> veb.bottom[c] - * j = (c << veb.num_bottom_bits) + subv.min_val - */ - __pyx_t_3 = (__pyx_v_veb->num_bottom_bits > __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":305 - * c = bitset_findsucc(subb, a) - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - * subv = <_VEB*> veb.bottom[c] # <<<<<<<<<<<<<< - * j = (c << veb.num_bottom_bits) + subv.min_val - * else: - */ - __pyx_v_subv = ((struct __pyx_t_8_cdec_sa__VEB *)(__pyx_v_veb->bottom[__pyx_v_c])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":306 - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - * subv = <_VEB*> veb.bottom[c] - * j = (c << veb.num_bottom_bits) + subv.min_val # <<<<<<<<<<<<<< - * else: - * subb = <_BitSet*> veb.bottom[c] - */ - __pyx_v_j = ((__pyx_v_c << __pyx_v_veb->num_bottom_bits) + __pyx_v_subv->min_val); - goto __pyx_L11; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":308 - * j = (c << veb.num_bottom_bits) + subv.min_val - * else: - * subb = <_BitSet*> veb.bottom[c] # <<<<<<<<<<<<<< - * j = (c << veb.num_bottom_bits) + subb.min_val - * return j - */ - __pyx_v_subb = ((struct __pyx_t_8_cdec_sa__BitSet *)(__pyx_v_veb->bottom[__pyx_v_c])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":309 - * else: - * subb = <_BitSet*> veb.bottom[c] - * j = (c << veb.num_bottom_bits) + subb.min_val # <<<<<<<<<<<<<< - * return j - * - */ - __pyx_v_j = ((__pyx_v_c << __pyx_v_veb->num_bottom_bits) + __pyx_v_subb->min_val); - } - __pyx_L11:; - goto __pyx_L9; - } - __pyx_L9:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":310 - * subb = <_BitSet*> veb.bottom[c] - * j = (c << veb.num_bottom_bits) + subb.min_val - * return j # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = __pyx_v_j; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":313 - * - * - * cdef int VEB_contains(_VEB* veb, int i): # <<<<<<<<<<<<<< - * cdef _VEB* subv - * cdef _BitSet* subb - */ - -static int __pyx_f_8_cdec_sa_VEB_contains(struct __pyx_t_8_cdec_sa__VEB *__pyx_v_veb, int __pyx_v_i) { - struct __pyx_t_8_cdec_sa__VEB *__pyx_v_subv; - struct __pyx_t_8_cdec_sa__BitSet *__pyx_v_subb; - int __pyx_v_a; - int __pyx_v_b; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - __Pyx_RefNannySetupContext("VEB_contains", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":318 - * cdef int a, b - * - * if veb.size == 0 or i < veb.min_val or i > veb.max_val: # <<<<<<<<<<<<<< - * return 0 - * - */ - __pyx_t_1 = (__pyx_v_veb->size == 0); - if (!__pyx_t_1) { - __pyx_t_2 = (__pyx_v_i < __pyx_v_veb->min_val); - if (!__pyx_t_2) { - __pyx_t_3 = (__pyx_v_i > __pyx_v_veb->max_val); - __pyx_t_4 = __pyx_t_3; - } else { - __pyx_t_4 = __pyx_t_2; - } - __pyx_t_2 = __pyx_t_4; - } else { - __pyx_t_2 = __pyx_t_1; - } - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":319 - * - * if veb.size == 0 or i < veb.min_val or i > veb.max_val: - * return 0 # <<<<<<<<<<<<<< - * - * if veb.min_val == i: - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":321 - * return 0 - * - * if veb.min_val == i: # <<<<<<<<<<<<<< - * return 1 - * else: - */ - __pyx_t_2 = (__pyx_v_veb->min_val == __pyx_v_i); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":322 - * - * if veb.min_val == i: - * return 1 # <<<<<<<<<<<<<< - * else: - * if veb.size == 1: - */ - __pyx_r = 1; - goto __pyx_L0; - goto __pyx_L4; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":324 - * return 1 - * else: - * if veb.size == 1: # <<<<<<<<<<<<<< - * return 0 - * - */ - __pyx_t_2 = (__pyx_v_veb->size == 1); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":325 - * else: - * if veb.size == 1: - * return 0 # <<<<<<<<<<<<<< - * - * a = i >> veb.num_bottom_bits - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L5; - } - __pyx_L5:; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":327 - * return 0 - * - * a = i >> veb.num_bottom_bits # <<<<<<<<<<<<<< - * b = i & LOWER_MASK[veb.num_bottom_bits-1] - * if veb.bottom[a] == NULL: - */ - __pyx_v_a = (__pyx_v_i >> __pyx_v_veb->num_bottom_bits); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":328 - * - * a = i >> veb.num_bottom_bits - * b = i & LOWER_MASK[veb.num_bottom_bits-1] # <<<<<<<<<<<<<< - * if veb.bottom[a] == NULL: - * return 0 - */ - __pyx_v_b = (__pyx_v_i & (__pyx_v_8_cdec_sa_LOWER_MASK[(__pyx_v_veb->num_bottom_bits - 1)])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":329 - * a = i >> veb.num_bottom_bits - * b = i & LOWER_MASK[veb.num_bottom_bits-1] - * if veb.bottom[a] == NULL: # <<<<<<<<<<<<<< - * return 0 - * else: - */ - __pyx_t_2 = ((__pyx_v_veb->bottom[__pyx_v_a]) == NULL); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":330 - * b = i & LOWER_MASK[veb.num_bottom_bits-1] - * if veb.bottom[a] == NULL: - * return 0 # <<<<<<<<<<<<<< - * else: - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L6; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":332 - * return 0 - * else: - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< - * subv = <_VEB*> veb.bottom[a] - * return VEB_contains(subv, b) - */ - __pyx_t_2 = (__pyx_v_veb->num_bottom_bits > __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":333 - * else: - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - * subv = <_VEB*> veb.bottom[a] # <<<<<<<<<<<<<< - * return VEB_contains(subv, b) - * else: - */ - __pyx_v_subv = ((struct __pyx_t_8_cdec_sa__VEB *)(__pyx_v_veb->bottom[__pyx_v_a])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":334 - * if veb.num_bottom_bits > MIN_BOTTOM_BITS: - * subv = <_VEB*> veb.bottom[a] - * return VEB_contains(subv, b) # <<<<<<<<<<<<<< - * else: - * subb = <_BitSet*> veb.bottom[a] - */ - __pyx_r = __pyx_f_8_cdec_sa_VEB_contains(__pyx_v_subv, __pyx_v_b); - goto __pyx_L0; - goto __pyx_L7; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":336 - * return VEB_contains(subv, b) - * else: - * subb = <_BitSet*> veb.bottom[a] # <<<<<<<<<<<<<< - * return bitset_contains(subb, b) - * - */ - __pyx_v_subb = ((struct __pyx_t_8_cdec_sa__BitSet *)(__pyx_v_veb->bottom[__pyx_v_a])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":337 - * else: - * subb = <_BitSet*> veb.bottom[a] - * return bitset_contains(subb, b) # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = __pyx_f_8_cdec_sa_bitset_contains(__pyx_v_subb, __pyx_v_b); - goto __pyx_L0; - } - __pyx_L7:; - } - __pyx_L6:; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_11VEBIterator_1__next__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_11VEBIterator_1__next__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__next__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_11VEBIterator___next__(((struct __pyx_obj_8_cdec_sa_VEBIterator *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":344 - * cdef int next_val - * - * def __next__(self): # <<<<<<<<<<<<<< - * cdef int ret_val - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_11VEBIterator___next__(struct __pyx_obj_8_cdec_sa_VEBIterator *__pyx_v_self) { - int __pyx_v_ret_val; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__next__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":347 - * cdef int ret_val - * - * if self.next_val == -1: # <<<<<<<<<<<<<< - * raise StopIteration() - * ret_val = self.next_val - */ - __pyx_t_1 = (__pyx_v_self->next_val == -1); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":348 - * - * if self.next_val == -1: - * raise StopIteration() # <<<<<<<<<<<<<< - * ret_val = self.next_val - * self.next_val = VEB_findsucc(self.v, ret_val) - */ - __pyx_t_2 = PyObject_Call(__pyx_builtin_StopIteration, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[6]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":349 - * if self.next_val == -1: - * raise StopIteration() - * ret_val = self.next_val # <<<<<<<<<<<<<< - * self.next_val = VEB_findsucc(self.v, ret_val) - * return ret_val - */ - __pyx_v_ret_val = __pyx_v_self->next_val; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":350 - * raise StopIteration() - * ret_val = self.next_val - * self.next_val = VEB_findsucc(self.v, ret_val) # <<<<<<<<<<<<<< - * return ret_val - * - */ - __pyx_v_self->next_val = __pyx_f_8_cdec_sa_VEB_findsucc(__pyx_v_self->v, __pyx_v_ret_val); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":351 - * ret_val = self.next_val - * self.next_val = VEB_findsucc(self.v, ret_val) - * return ret_val # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyInt_FromLong(__pyx_v_ret_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __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_2); - __Pyx_AddTraceback("_cdec_sa.VEBIterator.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_3VEB_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_3VEB_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_v_size; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__size,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[1] = {0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size); - 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 360; __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_size = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 360; __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[6]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.VEB.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_3VEB___cinit__(((struct __pyx_obj_8_cdec_sa_VEB *)__pyx_v_self), __pyx_v_size); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":360 - * cdef int _first(self) - * - * def __cinit__(self, int size): # <<<<<<<<<<<<<< - * self.veb = new_VEB(size) - * - */ - -static int __pyx_pf_8_cdec_sa_3VEB___cinit__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, int __pyx_v_size) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":361 - * - * def __cinit__(self, int size): - * self.veb = new_VEB(size) # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - __pyx_v_self->veb = __pyx_f_8_cdec_sa_new_VEB(__pyx_v_size); - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static void __pyx_pw_8_cdec_sa_3VEB_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_8_cdec_sa_3VEB_3__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_8_cdec_sa_3VEB_2__dealloc__(((struct __pyx_obj_8_cdec_sa_VEB *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":363 - * self.veb = new_VEB(size) - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del_VEB(self.veb) - * - */ - -static void __pyx_pf_8_cdec_sa_3VEB_2__dealloc__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self) { - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":364 - * - * def __dealloc__(self): - * del_VEB(self.veb) # <<<<<<<<<<<<<< - * - * def __iter__(self): - */ - __pyx_t_1 = __pyx_f_8_cdec_sa_del_VEB(__pyx_v_self->veb); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec_sa.VEB.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_3VEB_5__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_3VEB_5__iter__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_3VEB_4__iter__(((struct __pyx_obj_8_cdec_sa_VEB *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":366 - * del_VEB(self.veb) - * - * def __iter__(self): # <<<<<<<<<<<<<< - * cdef VEBIterator it - * it = VEBIterator() - */ - -static PyObject *__pyx_pf_8_cdec_sa_3VEB_4__iter__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self) { - struct __pyx_obj_8_cdec_sa_VEBIterator *__pyx_v_it = 0; - 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("__iter__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":368 - * def __iter__(self): - * cdef VEBIterator it - * it = VEBIterator() # <<<<<<<<<<<<<< - * it.v = self.veb - * it.next_val = self.veb.min_val - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_VEBIterator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_it = ((struct __pyx_obj_8_cdec_sa_VEBIterator *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":369 - * cdef VEBIterator it - * it = VEBIterator() - * it.v = self.veb # <<<<<<<<<<<<<< - * it.next_val = self.veb.min_val - * return it - */ - __pyx_v_it->v = __pyx_v_self->veb; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":370 - * it = VEBIterator() - * it.v = self.veb - * it.next_val = self.veb.min_val # <<<<<<<<<<<<<< - * return it - * - */ - __pyx_v_it->next_val = __pyx_v_self->veb->min_val; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":371 - * it.v = self.veb - * it.next_val = self.veb.min_val - * return it # <<<<<<<<<<<<<< - * - * def insert(self, i): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_it)); - __pyx_r = ((PyObject *)__pyx_v_it); - 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_sa.VEB.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_it); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_3VEB_7insert(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_3VEB_7insert(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("insert (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_3VEB_6insert(((struct __pyx_obj_8_cdec_sa_VEB *)__pyx_v_self), ((PyObject *)__pyx_v_i)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":373 - * return it - * - * def insert(self, i): # <<<<<<<<<<<<<< - * return VEB_insert(self.veb, i) - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_3VEB_6insert(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("insert", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":374 - * - * def insert(self, i): - * return VEB_insert(self.veb, i) # <<<<<<<<<<<<<< - * - * cdef int _insert(self, int i): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromLong(__pyx_f_8_cdec_sa_VEB_insert(__pyx_v_self->veb, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __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_2); - __Pyx_AddTraceback("_cdec_sa.VEB.insert", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":376 - * return VEB_insert(self.veb, i) - * - * cdef int _insert(self, int i): # <<<<<<<<<<<<<< - * return VEB_insert(self.veb, i) - * - */ - -static int __pyx_f_8_cdec_sa_3VEB__insert(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, int __pyx_v_i) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_insert", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":377 - * - * cdef int _insert(self, int i): - * return VEB_insert(self.veb, i) # <<<<<<<<<<<<<< - * - * def findsucc(self, i): - */ - __pyx_r = __pyx_f_8_cdec_sa_VEB_insert(__pyx_v_self->veb, __pyx_v_i); - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_3VEB_9findsucc(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_3VEB_9findsucc(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("findsucc (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_3VEB_8findsucc(((struct __pyx_obj_8_cdec_sa_VEB *)__pyx_v_self), ((PyObject *)__pyx_v_i)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":379 - * return VEB_insert(self.veb, i) - * - * def findsucc(self, i): # <<<<<<<<<<<<<< - * return VEB_findsucc(self.veb, i) - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_3VEB_8findsucc(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("findsucc", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":380 - * - * def findsucc(self, i): - * return VEB_findsucc(self.veb, i) # <<<<<<<<<<<<<< - * - * cdef int _first(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromLong(__pyx_f_8_cdec_sa_VEB_findsucc(__pyx_v_self->veb, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __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_2); - __Pyx_AddTraceback("_cdec_sa.VEB.findsucc", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":382 - * return VEB_findsucc(self.veb, i) - * - * cdef int _first(self): # <<<<<<<<<<<<<< - * return self.veb.min_val - * - */ - -static int __pyx_f_8_cdec_sa_3VEB__first(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_first", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":383 - * - * cdef int _first(self): - * return self.veb.min_val # <<<<<<<<<<<<<< - * - * cdef int _findsucc(self, int i): - */ - __pyx_r = __pyx_v_self->veb->min_val; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":385 - * return self.veb.min_val - * - * cdef int _findsucc(self, int i): # <<<<<<<<<<<<<< - * return VEB_findsucc(self.veb, i) - * - */ - -static int __pyx_f_8_cdec_sa_3VEB__findsucc(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, int __pyx_v_i) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("_findsucc", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":386 - * - * cdef int _findsucc(self, int i): - * return VEB_findsucc(self.veb, i) # <<<<<<<<<<<<<< - * - * def __len__(self): - */ - __pyx_r = __pyx_f_8_cdec_sa_VEB_findsucc(__pyx_v_self->veb, __pyx_v_i); - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static Py_ssize_t __pyx_pw_8_cdec_sa_3VEB_11__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_8_cdec_sa_3VEB_11__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_3VEB_10__len__(((struct __pyx_obj_8_cdec_sa_VEB *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":388 - * return VEB_findsucc(self.veb, i) - * - * def __len__(self): # <<<<<<<<<<<<<< - * return self.veb.size - * - */ - -static Py_ssize_t __pyx_pf_8_cdec_sa_3VEB_10__len__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":389 - * - * def __len__(self): - * return self.veb.size # <<<<<<<<<<<<<< - * - * def __contains__(self, i): - */ - __pyx_r = __pyx_v_self->veb->size; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_3VEB_13__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ -static int __pyx_pw_8_cdec_sa_3VEB_13__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_3VEB_12__contains__(((struct __pyx_obj_8_cdec_sa_VEB *)__pyx_v_self), ((PyObject *)__pyx_v_i)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":391 - * return self.veb.size - * - * def __contains__(self, i): # <<<<<<<<<<<<<< - * return VEB_contains(self.veb, i) - */ - -static int __pyx_pf_8_cdec_sa_3VEB_12__contains__(struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_self, PyObject *__pyx_v_i) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__contains__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":392 - * - * def __contains__(self, i): - * return VEB_contains(self.veb, i) # <<<<<<<<<<<<<< - */ - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_f_8_cdec_sa_VEB_contains(__pyx_v_self->veb, __pyx_t_1); - goto __pyx_L0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec_sa.VEB.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_3LCP_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_3LCP_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_sa = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sa,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[1] = {0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sa); - 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 9; __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_sa = ((struct __pyx_obj_8_cdec_sa_SuffixArray *)values[0]); - } - 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[9]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.LCP.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_sa), __pyx_ptype_8_cdec_sa_SuffixArray, 1, "sa", 0))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_8_cdec_sa_3LCP___cinit__(((struct __pyx_obj_8_cdec_sa_LCP *)__pyx_v_self), __pyx_v_sa); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":9 - * cdef IntList lcp - * - * def __cinit__(self, SuffixArray sa): # <<<<<<<<<<<<<< - * cdef int i, k, j, h, n - * cdef IntList rank - */ - -static int __pyx_pf_8_cdec_sa_3LCP___cinit__(struct __pyx_obj_8_cdec_sa_LCP *__pyx_v_self, struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_sa) { - int __pyx_v_i; - int __pyx_v_k; - int __pyx_v_j; - int __pyx_v_h; - int __pyx_v_n; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_rank = 0; - int __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - int __pyx_t_7; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":13 - * cdef IntList rank - * - * logger.info("Constructing LCP array") # <<<<<<<<<<<<<< - * self.sa = sa - * n = self.sa.sa.len - */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_58), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":14 - * - * logger.info("Constructing LCP array") - * self.sa = sa # <<<<<<<<<<<<<< - * n = self.sa.sa.len - * self.lcp = IntList(initial_len=n) - */ - __Pyx_INCREF(((PyObject *)__pyx_v_sa)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_sa)); - __Pyx_GOTREF(__pyx_v_self->sa); - __Pyx_DECREF(((PyObject *)__pyx_v_self->sa)); - __pyx_v_self->sa = __pyx_v_sa; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":15 - * logger.info("Constructing LCP array") - * self.sa = sa - * n = self.sa.sa.len # <<<<<<<<<<<<<< - * self.lcp = IntList(initial_len=n) - * - */ - __pyx_v_n = __pyx_v_self->sa->sa->len; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":16 - * self.sa = sa - * n = self.sa.sa.len - * self.lcp = IntList(initial_len=n) # <<<<<<<<<<<<<< - * - * rank = IntList(initial_len=n) - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 16; __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); - __Pyx_GOTREF(__pyx_v_self->lcp); - __Pyx_DECREF(((PyObject *)__pyx_v_self->lcp)); - __pyx_v_self->lcp = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":18 - * self.lcp = IntList(initial_len=n) - * - * rank = IntList(initial_len=n) # <<<<<<<<<<<<<< - * for i from 0 <= i < n: - * rank.arr[sa.sa.arr[i]] = i - */ - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_t_1 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_v_rank = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":19 - * - * rank = IntList(initial_len=n) - * for i from 0 <= i < n: # <<<<<<<<<<<<<< - * rank.arr[sa.sa.arr[i]] = i - * - */ - __pyx_t_3 = __pyx_v_n; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":20 - * rank = IntList(initial_len=n) - * for i from 0 <= i < n: - * rank.arr[sa.sa.arr[i]] = i # <<<<<<<<<<<<<< - * - * h = 0 - */ - (__pyx_v_rank->arr[(__pyx_v_sa->sa->arr[__pyx_v_i])]) = __pyx_v_i; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":22 - * rank.arr[sa.sa.arr[i]] = i - * - * h = 0 # <<<<<<<<<<<<<< - * for i from 0 <= i < n: - * k = rank.arr[i] - */ - __pyx_v_h = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":23 - * - * h = 0 - * for i from 0 <= i < n: # <<<<<<<<<<<<<< - * k = rank.arr[i] - * if k == 0: - */ - __pyx_t_3 = __pyx_v_n; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":24 - * h = 0 - * for i from 0 <= i < n: - * k = rank.arr[i] # <<<<<<<<<<<<<< - * if k == 0: - * self.lcp.arr[k] = -1 - */ - __pyx_v_k = (__pyx_v_rank->arr[__pyx_v_i]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":25 - * for i from 0 <= i < n: - * k = rank.arr[i] - * if k == 0: # <<<<<<<<<<<<<< - * self.lcp.arr[k] = -1 - * else: - */ - __pyx_t_4 = (__pyx_v_k == 0); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":26 - * k = rank.arr[i] - * if k == 0: - * self.lcp.arr[k] = -1 # <<<<<<<<<<<<<< - * else: - * j = sa.sa.arr[k-1] - */ - (__pyx_v_self->lcp->arr[__pyx_v_k]) = -1; - goto __pyx_L7; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":28 - * self.lcp.arr[k] = -1 - * else: - * j = sa.sa.arr[k-1] # <<<<<<<<<<<<<< - * while i+h < n and j+h < n and sa.darray.data.arr[i+h] == sa.darray.data.arr[j+h]: - * h = h+1 - */ - __pyx_v_j = (__pyx_v_sa->sa->arr[(__pyx_v_k - 1)]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":29 - * else: - * j = sa.sa.arr[k-1] - * while i+h < n and j+h < n and sa.darray.data.arr[i+h] == sa.darray.data.arr[j+h]: # <<<<<<<<<<<<<< - * h = h+1 - * self.lcp.arr[k] = h - */ - while (1) { - __pyx_t_4 = ((__pyx_v_i + __pyx_v_h) < __pyx_v_n); - if (__pyx_t_4) { - __pyx_t_5 = ((__pyx_v_j + __pyx_v_h) < __pyx_v_n); - if (__pyx_t_5) { - __pyx_t_6 = ((__pyx_v_sa->darray->data->arr[(__pyx_v_i + __pyx_v_h)]) == (__pyx_v_sa->darray->data->arr[(__pyx_v_j + __pyx_v_h)])); - __pyx_t_7 = __pyx_t_6; - } else { - __pyx_t_7 = __pyx_t_5; - } - __pyx_t_5 = __pyx_t_7; - } else { - __pyx_t_5 = __pyx_t_4; - } - if (!__pyx_t_5) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":30 - * j = sa.sa.arr[k-1] - * while i+h < n and j+h < n and sa.darray.data.arr[i+h] == sa.darray.data.arr[j+h]: - * h = h+1 # <<<<<<<<<<<<<< - * self.lcp.arr[k] = h - * if h > 0: - */ - __pyx_v_h = (__pyx_v_h + 1); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":31 - * while i+h < n and j+h < n and sa.darray.data.arr[i+h] == sa.darray.data.arr[j+h]: - * h = h+1 - * self.lcp.arr[k] = h # <<<<<<<<<<<<<< - * if h > 0: - * h = h-1 - */ - (__pyx_v_self->lcp->arr[__pyx_v_k]) = __pyx_v_h; - } - __pyx_L7:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":32 - * h = h+1 - * self.lcp.arr[k] = h - * if h > 0: # <<<<<<<<<<<<<< - * h = h-1 - * logger.info("LCP array completed") - */ - __pyx_t_5 = (__pyx_v_h > 0); - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":33 - * self.lcp.arr[k] = h - * if h > 0: - * h = h-1 # <<<<<<<<<<<<<< - * logger.info("LCP array completed") - * - */ - __pyx_v_h = (__pyx_v_h - 1); - goto __pyx_L10; - } - __pyx_L10:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":34 - * if h > 0: - * h = h-1 - * logger.info("LCP array completed") # <<<<<<<<<<<<<< - * - * def compute_stats(self, int max_n): - */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_60), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_cdec_sa.LCP.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_rank); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -static PyObject *__pyx_gb_8_cdec_sa_3LCP_4generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_3LCP_3compute_stats(PyObject *__pyx_v_self, PyObject *__pyx_arg_max_n); /*proto*/ -static char __pyx_doc_8_cdec_sa_3LCP_2compute_stats[] = "Note: the output of this function is not exact. In\n particular, the frequency associated with each word is \n not guaranteed to be correct. This is due to a bit of\n laxness in the design; the function is intended only to\n obtain a list of the most frequent words; for this \n purpose it is perfectly fine"; -static PyObject *__pyx_pw_8_cdec_sa_3LCP_3compute_stats(PyObject *__pyx_v_self, PyObject *__pyx_arg_max_n) { - int __pyx_v_max_n; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("compute_stats (wrapper)", 0); - assert(__pyx_arg_max_n); { - __pyx_v_max_n = __Pyx_PyInt_AsInt(__pyx_arg_max_n); if (unlikely((__pyx_v_max_n == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.LCP.compute_stats", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_3LCP_2compute_stats(((struct __pyx_obj_8_cdec_sa_LCP *)__pyx_v_self), ((int)__pyx_v_max_n)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":36 - * logger.info("LCP array completed") - * - * def compute_stats(self, int max_n): # <<<<<<<<<<<<<< - * """Note: the output of this function is not exact. In - * particular, the frequency associated with each word is - */ - -static PyObject *__pyx_pf_8_cdec_sa_3LCP_2compute_stats(struct __pyx_obj_8_cdec_sa_LCP *__pyx_v_self, int __pyx_v_max_n) { - struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *__pyx_cur_scope; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("compute_stats", 0); - __pyx_cur_scope = (struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *)__pyx_ptype_8_cdec_sa___pyx_scope_struct__compute_stats->tp_new(__pyx_ptype_8_cdec_sa___pyx_scope_struct__compute_stats, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __pyx_cur_scope->__pyx_v_max_n = __pyx_v_max_n; - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_8_cdec_sa_3LCP_4generator, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec_sa.LCP.compute_stats", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_gb_8_cdec_sa_3LCP_4generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *__pyx_cur_scope = ((struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - long __pyx_t_9; - PyObject *__pyx_t_10 = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("None", 0); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L26_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[9]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":48 - * cdef VEB veb - * - * N = self.sa.sa.len # <<<<<<<<<<<<<< - * - * ngram_starts = [] - */ - __pyx_cur_scope->__pyx_v_N = __pyx_cur_scope->__pyx_v_self->sa->sa->len; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":50 - * N = self.sa.sa.len - * - * ngram_starts = [] # <<<<<<<<<<<<<< - * for n from 0 <= n < max_n: - * ngram_starts.append(IntList(initial_len=N)) - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __pyx_cur_scope->__pyx_v_ngram_starts = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":51 - * - * ngram_starts = [] - * for n from 0 <= n < max_n: # <<<<<<<<<<<<<< - * ngram_starts.append(IntList(initial_len=N)) - * - */ - __pyx_t_2 = __pyx_cur_scope->__pyx_v_max_n; - for (__pyx_cur_scope->__pyx_v_n = 0; __pyx_cur_scope->__pyx_v_n < __pyx_t_2; __pyx_cur_scope->__pyx_v_n++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":52 - * ngram_starts = [] - * for n from 0 <= n < max_n: - * ngram_starts.append(IntList(initial_len=N)) # <<<<<<<<<<<<<< - * - * run_start = IntList(initial_len=max_n) - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_4 = PyList_Append(__pyx_cur_scope->__pyx_v_ngram_starts, __pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":54 - * ngram_starts.append(IntList(initial_len=N)) - * - * run_start = IntList(initial_len=max_n) # <<<<<<<<<<<<<< - * veb = VEB(N) - * - */ - __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_1 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_max_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_GIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_v_run_start = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":55 - * - * run_start = IntList(initial_len=max_n) - * veb = VEB(N) # <<<<<<<<<<<<<< - * - * for i from 0 <= i < N: - */ - __pyx_t_1 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_VEB)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_GIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_v_veb = ((struct __pyx_obj_8_cdec_sa_VEB *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":57 - * veb = VEB(N) - * - * for i from 0 <= i < N: # <<<<<<<<<<<<<< - * h = self.lcp.arr[i] - * if h < 0: - */ - __pyx_t_2 = __pyx_cur_scope->__pyx_v_N; - for (__pyx_cur_scope->__pyx_v_i = 0; __pyx_cur_scope->__pyx_v_i < __pyx_t_2; __pyx_cur_scope->__pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":58 - * - * for i from 0 <= i < N: - * h = self.lcp.arr[i] # <<<<<<<<<<<<<< - * if h < 0: - * h = 0 - */ - __pyx_cur_scope->__pyx_v_h = (__pyx_cur_scope->__pyx_v_self->lcp->arr[__pyx_cur_scope->__pyx_v_i]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":59 - * for i from 0 <= i < N: - * h = self.lcp.arr[i] - * if h < 0: # <<<<<<<<<<<<<< - * h = 0 - * for n from h <= n < max_n: - */ - __pyx_t_5 = (__pyx_cur_scope->__pyx_v_h < 0); - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":60 - * h = self.lcp.arr[i] - * if h < 0: - * h = 0 # <<<<<<<<<<<<<< - * for n from h <= n < max_n: - * rs = run_start.arr[n] - */ - __pyx_cur_scope->__pyx_v_h = 0; - goto __pyx_L8; - } - __pyx_L8:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":61 - * if h < 0: - * h = 0 - * for n from h <= n < max_n: # <<<<<<<<<<<<<< - * rs = run_start.arr[n] - * run_start.arr[n] = i - */ - __pyx_t_6 = __pyx_cur_scope->__pyx_v_max_n; - for (__pyx_cur_scope->__pyx_v_n = __pyx_cur_scope->__pyx_v_h; __pyx_cur_scope->__pyx_v_n < __pyx_t_6; __pyx_cur_scope->__pyx_v_n++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":62 - * h = 0 - * for n from h <= n < max_n: - * rs = run_start.arr[n] # <<<<<<<<<<<<<< - * run_start.arr[n] = i - * freq = i - rs - */ - __pyx_cur_scope->__pyx_v_rs = (__pyx_cur_scope->__pyx_v_run_start->arr[__pyx_cur_scope->__pyx_v_n]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":63 - * for n from h <= n < max_n: - * rs = run_start.arr[n] - * run_start.arr[n] = i # <<<<<<<<<<<<<< - * freq = i - rs - * if freq > 1000: # arbitrary, but see note below - */ - (__pyx_cur_scope->__pyx_v_run_start->arr[__pyx_cur_scope->__pyx_v_n]) = __pyx_cur_scope->__pyx_v_i; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":64 - * rs = run_start.arr[n] - * run_start.arr[n] = i - * freq = i - rs # <<<<<<<<<<<<<< - * if freq > 1000: # arbitrary, but see note below - * veb._insert(freq) - */ - __pyx_cur_scope->__pyx_v_freq = (__pyx_cur_scope->__pyx_v_i - __pyx_cur_scope->__pyx_v_rs); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":65 - * run_start.arr[n] = i - * freq = i - rs - * if freq > 1000: # arbitrary, but see note below # <<<<<<<<<<<<<< - * veb._insert(freq) - * ngram_start = ngram_starts[n] - */ - __pyx_t_5 = (__pyx_cur_scope->__pyx_v_freq > 1000); - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":66 - * freq = i - rs - * if freq > 1000: # arbitrary, but see note below - * veb._insert(freq) # <<<<<<<<<<<<<< - * ngram_start = ngram_starts[n] - * while ngram_start.arr[freq] > 0: - */ - ((struct __pyx_vtabstruct_8_cdec_sa_VEB *)__pyx_cur_scope->__pyx_v_veb->__pyx_vtab)->_insert(__pyx_cur_scope->__pyx_v_veb, __pyx_cur_scope->__pyx_v_freq); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":67 - * if freq > 1000: # arbitrary, but see note below - * veb._insert(freq) - * ngram_start = ngram_starts[n] # <<<<<<<<<<<<<< - * while ngram_start.arr[freq] > 0: - * freq = freq + 1 # cheating a bit, should be ok for sparse histogram - */ - __pyx_t_1 = __Pyx_GetItemInt_List(((PyObject *)__pyx_cur_scope->__pyx_v_ngram_starts), __pyx_cur_scope->__pyx_v_n, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8_cdec_sa_IntList))))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram_start)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram_start)); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_v_ngram_start = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":68 - * veb._insert(freq) - * ngram_start = ngram_starts[n] - * while ngram_start.arr[freq] > 0: # <<<<<<<<<<<<<< - * freq = freq + 1 # cheating a bit, should be ok for sparse histogram - * ngram_start.arr[freq] = rs - */ - while (1) { - __pyx_t_5 = ((__pyx_cur_scope->__pyx_v_ngram_start->arr[__pyx_cur_scope->__pyx_v_freq]) > 0); - if (!__pyx_t_5) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":69 - * ngram_start = ngram_starts[n] - * while ngram_start.arr[freq] > 0: - * freq = freq + 1 # cheating a bit, should be ok for sparse histogram # <<<<<<<<<<<<<< - * ngram_start.arr[freq] = rs - * i = veb.veb.min_val - */ - __pyx_cur_scope->__pyx_v_freq = (__pyx_cur_scope->__pyx_v_freq + 1); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":70 - * while ngram_start.arr[freq] > 0: - * freq = freq + 1 # cheating a bit, should be ok for sparse histogram - * ngram_start.arr[freq] = rs # <<<<<<<<<<<<<< - * i = veb.veb.min_val - * while i != -1: - */ - (__pyx_cur_scope->__pyx_v_ngram_start->arr[__pyx_cur_scope->__pyx_v_freq]) = __pyx_cur_scope->__pyx_v_rs; - goto __pyx_L11; - } - __pyx_L11:; - } - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":71 - * freq = freq + 1 # cheating a bit, should be ok for sparse histogram - * ngram_start.arr[freq] = rs - * i = veb.veb.min_val # <<<<<<<<<<<<<< - * while i != -1: - * ii = veb._findsucc(i) - */ - __pyx_cur_scope->__pyx_v_i = __pyx_cur_scope->__pyx_v_veb->veb->min_val; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":72 - * ngram_start.arr[freq] = rs - * i = veb.veb.min_val - * while i != -1: # <<<<<<<<<<<<<< - * ii = veb._findsucc(i) - * for n from 0 <= n < max_n: - */ - while (1) { - __pyx_t_5 = (__pyx_cur_scope->__pyx_v_i != -1); - if (!__pyx_t_5) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":73 - * i = veb.veb.min_val - * while i != -1: - * ii = veb._findsucc(i) # <<<<<<<<<<<<<< - * for n from 0 <= n < max_n: - * ngram_start = ngram_starts[n] - */ - __pyx_cur_scope->__pyx_v_ii = ((struct __pyx_vtabstruct_8_cdec_sa_VEB *)__pyx_cur_scope->__pyx_v_veb->__pyx_vtab)->_findsucc(__pyx_cur_scope->__pyx_v_veb, __pyx_cur_scope->__pyx_v_i); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":74 - * while i != -1: - * ii = veb._findsucc(i) - * for n from 0 <= n < max_n: # <<<<<<<<<<<<<< - * ngram_start = ngram_starts[n] - * iii = i - */ - __pyx_t_2 = __pyx_cur_scope->__pyx_v_max_n; - for (__pyx_cur_scope->__pyx_v_n = 0; __pyx_cur_scope->__pyx_v_n < __pyx_t_2; __pyx_cur_scope->__pyx_v_n++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":75 - * ii = veb._findsucc(i) - * for n from 0 <= n < max_n: - * ngram_start = ngram_starts[n] # <<<<<<<<<<<<<< - * iii = i - * rs = ngram_start.arr[iii] - */ - __pyx_t_1 = __Pyx_GetItemInt_List(((PyObject *)__pyx_cur_scope->__pyx_v_ngram_starts), __pyx_cur_scope->__pyx_v_n, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8_cdec_sa_IntList))))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram_start)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram_start)); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_v_ngram_start = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":76 - * for n from 0 <= n < max_n: - * ngram_start = ngram_starts[n] - * iii = i # <<<<<<<<<<<<<< - * rs = ngram_start.arr[iii] - * while (ii==-1 or iii < ii) and rs != 0: - */ - __pyx_cur_scope->__pyx_v_iii = __pyx_cur_scope->__pyx_v_i; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":77 - * ngram_start = ngram_starts[n] - * iii = i - * rs = ngram_start.arr[iii] # <<<<<<<<<<<<<< - * while (ii==-1 or iii < ii) and rs != 0: - * j = self.sa.sa.arr[rs] - */ - __pyx_cur_scope->__pyx_v_rs = (__pyx_cur_scope->__pyx_v_ngram_start->arr[__pyx_cur_scope->__pyx_v_iii]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":78 - * iii = i - * rs = ngram_start.arr[iii] - * while (ii==-1 or iii < ii) and rs != 0: # <<<<<<<<<<<<<< - * j = self.sa.sa.arr[rs] - * valid = 1 - */ - while (1) { - __pyx_t_5 = (__pyx_cur_scope->__pyx_v_ii == -1); - if (!__pyx_t_5) { - __pyx_t_7 = (__pyx_cur_scope->__pyx_v_iii < __pyx_cur_scope->__pyx_v_ii); - __pyx_t_8 = __pyx_t_7; - } else { - __pyx_t_8 = __pyx_t_5; - } - if (__pyx_t_8) { - __pyx_t_5 = (__pyx_cur_scope->__pyx_v_rs != 0); - __pyx_t_7 = __pyx_t_5; - } else { - __pyx_t_7 = __pyx_t_8; - } - if (!__pyx_t_7) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":79 - * rs = ngram_start.arr[iii] - * while (ii==-1 or iii < ii) and rs != 0: - * j = self.sa.sa.arr[rs] # <<<<<<<<<<<<<< - * valid = 1 - * for k from 0 <= k < n+1: - */ - __pyx_cur_scope->__pyx_v_j = (__pyx_cur_scope->__pyx_v_self->sa->sa->arr[__pyx_cur_scope->__pyx_v_rs]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":80 - * while (ii==-1 or iii < ii) and rs != 0: - * j = self.sa.sa.arr[rs] - * valid = 1 # <<<<<<<<<<<<<< - * for k from 0 <= k < n+1: - * if self.sa.darray.data.arr[j+k] < 2: - */ - __pyx_cur_scope->__pyx_v_valid = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":81 - * j = self.sa.sa.arr[rs] - * valid = 1 - * for k from 0 <= k < n+1: # <<<<<<<<<<<<<< - * if self.sa.darray.data.arr[j+k] < 2: - * valid = 0 - */ - __pyx_t_9 = (__pyx_cur_scope->__pyx_v_n + 1); - for (__pyx_cur_scope->__pyx_v_k = 0; __pyx_cur_scope->__pyx_v_k < __pyx_t_9; __pyx_cur_scope->__pyx_v_k++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":82 - * valid = 1 - * for k from 0 <= k < n+1: - * if self.sa.darray.data.arr[j+k] < 2: # <<<<<<<<<<<<<< - * valid = 0 - * if valid: - */ - __pyx_t_7 = ((__pyx_cur_scope->__pyx_v_self->sa->darray->data->arr[(__pyx_cur_scope->__pyx_v_j + __pyx_cur_scope->__pyx_v_k)]) < 2); - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":83 - * for k from 0 <= k < n+1: - * if self.sa.darray.data.arr[j+k] < 2: - * valid = 0 # <<<<<<<<<<<<<< - * if valid: - * ngram = tuple([self.sa.darray.data.arr[j+k] for k in range(n+1)]) - */ - __pyx_cur_scope->__pyx_v_valid = 0; - goto __pyx_L22; - } - __pyx_L22:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":84 - * if self.sa.darray.data.arr[j+k] < 2: - * valid = 0 - * if valid: # <<<<<<<<<<<<<< - * ngram = tuple([self.sa.darray.data.arr[j+k] for k in range(n+1)]) - * yield i, n+1, ngram - */ - if (__pyx_cur_scope->__pyx_v_valid) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":85 - * valid = 0 - * if valid: - * ngram = tuple([self.sa.darray.data.arr[j+k] for k in range(n+1)]) # <<<<<<<<<<<<<< - * yield i, n+1, ngram - * iii = iii + 1 - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = (__pyx_cur_scope->__pyx_v_n + 1); - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_9; __pyx_t_6+=1) { - __pyx_cur_scope->__pyx_v_k = __pyx_t_6; - __pyx_t_3 = PyInt_FromLong((__pyx_cur_scope->__pyx_v_self->sa->darray->data->arr[(__pyx_cur_scope->__pyx_v_j + __pyx_cur_scope->__pyx_v_k)])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (unlikely(PyList_Append(__pyx_t_1, (PyObject*)__pyx_t_3))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __pyx_t_3 = ((PyObject *)PyList_AsTuple(__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); - __pyx_cur_scope->__pyx_v_ngram = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":86 - * if valid: - * ngram = tuple([self.sa.darray.data.arr[j+k] for k in range(n+1)]) - * yield i, n+1, ngram # <<<<<<<<<<<<<< - * iii = iii + 1 - * rs = ngram_start.arr[iii] - */ - __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyInt_FromLong((__pyx_cur_scope->__pyx_v_n + 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram)); - PyTuple_SET_ITEM(__pyx_t_10, 2, ((PyObject *)__pyx_cur_scope->__pyx_v_ngram)); - __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram)); - __pyx_t_3 = 0; - __pyx_t_1 = 0; - __pyx_r = ((PyObject *)__pyx_t_10); - __pyx_t_10 = 0; - __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L26_resume_from_yield:; - __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L23; - } - __pyx_L23:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":87 - * ngram = tuple([self.sa.darray.data.arr[j+k] for k in range(n+1)]) - * yield i, n+1, ngram - * iii = iii + 1 # <<<<<<<<<<<<<< - * rs = ngram_start.arr[iii] - * i = ii - */ - __pyx_cur_scope->__pyx_v_iii = (__pyx_cur_scope->__pyx_v_iii + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":88 - * yield i, n+1, ngram - * iii = iii + 1 - * rs = ngram_start.arr[iii] # <<<<<<<<<<<<<< - * i = ii - */ - __pyx_cur_scope->__pyx_v_rs = (__pyx_cur_scope->__pyx_v_ngram_start->arr[__pyx_cur_scope->__pyx_v_iii]); - } - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":89 - * iii = iii + 1 - * rs = ngram_start.arr[iii] - * i = ii # <<<<<<<<<<<<<< - */ - __pyx_cur_scope->__pyx_v_i = __pyx_cur_scope->__pyx_v_ii; - } - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("compute_stats", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; - __Pyx_RefNannyFinishContext(); - return NULL; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_8Alphabet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_8Alphabet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} - if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; - __pyx_r = __pyx_pf_8_cdec_sa_8Alphabet___cinit__(((struct __pyx_obj_8_cdec_sa_Alphabet *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":12 - * cdef dict id2sym - * - * def __cinit__(self): # <<<<<<<<<<<<<< - * self.terminals = StringMap() - * self.nonterminals = StringMap() - */ - -static int __pyx_pf_8_cdec_sa_8Alphabet___cinit__(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":13 - * - * def __cinit__(self): - * self.terminals = StringMap() # <<<<<<<<<<<<<< - * self.nonterminals = StringMap() - * self.id2sym = {} - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_StringMap)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->terminals); - __Pyx_DECREF(((PyObject *)__pyx_v_self->terminals)); - __pyx_v_self->terminals = ((struct __pyx_obj_8_cdec_sa_StringMap *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":14 - * def __cinit__(self): - * self.terminals = StringMap() - * self.nonterminals = StringMap() # <<<<<<<<<<<<<< - * self.id2sym = {} - * self.first_nonterminal = -1 - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_StringMap)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->nonterminals); - __Pyx_DECREF(((PyObject *)__pyx_v_self->nonterminals)); - __pyx_v_self->nonterminals = ((struct __pyx_obj_8_cdec_sa_StringMap *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":15 - * self.terminals = StringMap() - * self.nonterminals = StringMap() - * self.id2sym = {} # <<<<<<<<<<<<<< - * self.first_nonterminal = -1 - * - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_GOTREF(__pyx_v_self->id2sym); - __Pyx_DECREF(((PyObject *)__pyx_v_self->id2sym)); - __pyx_v_self->id2sym = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":16 - * self.nonterminals = StringMap() - * self.id2sym = {} - * self.first_nonterminal = -1 # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - __pyx_v_self->first_nonterminal = -1; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec_sa.Alphabet.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static void __pyx_pw_8_cdec_sa_8Alphabet_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_8_cdec_sa_8Alphabet_3__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_8_cdec_sa_8Alphabet_2__dealloc__(((struct __pyx_obj_8_cdec_sa_Alphabet *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":18 - * self.first_nonterminal = -1 - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * pass - * - */ - -static void __pyx_pf_8_cdec_sa_8Alphabet_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); - - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":21 - * pass - * - * cdef int isvar(self, int sym): # <<<<<<<<<<<<<< - * return sym < 0 - * - */ - -static int __pyx_f_8_cdec_sa_8Alphabet_isvar(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, int __pyx_v_sym) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("isvar", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":22 - * - * cdef int isvar(self, int sym): - * return sym < 0 # <<<<<<<<<<<<<< - * - * cdef int isword(self, int sym): - */ - __pyx_r = (__pyx_v_sym < 0); - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":24 - * return sym < 0 - * - * cdef int isword(self, int sym): # <<<<<<<<<<<<<< - * return sym >= 0 - * - */ - -static int __pyx_f_8_cdec_sa_8Alphabet_isword(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, int __pyx_v_sym) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("isword", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":25 - * - * cdef int isword(self, int sym): - * return sym >= 0 # <<<<<<<<<<<<<< - * - * cdef int getindex(self, int sym): - */ - __pyx_r = (__pyx_v_sym >= 0); - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":27 - * return sym >= 0 - * - * cdef int getindex(self, int sym): # <<<<<<<<<<<<<< - * return -sym & INDEX_MASK - * - */ - -static int __pyx_f_8_cdec_sa_8Alphabet_getindex(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, int __pyx_v_sym) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("getindex", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":28 - * - * cdef int getindex(self, int sym): - * return -sym & INDEX_MASK # <<<<<<<<<<<<<< - * - * cdef int setindex(self, int sym, int ind): - */ - __pyx_r = ((-__pyx_v_sym) & __pyx_v_8_cdec_sa_INDEX_MASK); - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":30 - * return -sym & INDEX_MASK - * - * cdef int setindex(self, int sym, int ind): # <<<<<<<<<<<<<< - * return -(-sym & ~INDEX_MASK | ind) - * - */ - -static int __pyx_f_8_cdec_sa_8Alphabet_setindex(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, int __pyx_v_sym, int __pyx_v_ind) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("setindex", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":31 - * - * cdef int setindex(self, int sym, int ind): - * return -(-sym & ~INDEX_MASK | ind) # <<<<<<<<<<<<<< - * - * cdef int clearindex(self, int sym): - */ - __pyx_r = (-(((-__pyx_v_sym) & (~__pyx_v_8_cdec_sa_INDEX_MASK)) | __pyx_v_ind)); - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":33 - * return -(-sym & ~INDEX_MASK | ind) - * - * cdef int clearindex(self, int sym): # <<<<<<<<<<<<<< - * return -(-sym& ~INDEX_MASK) - * - */ - -static int __pyx_f_8_cdec_sa_8Alphabet_clearindex(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, int __pyx_v_sym) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("clearindex", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":34 - * - * cdef int clearindex(self, int sym): - * return -(-sym& ~INDEX_MASK) # <<<<<<<<<<<<<< - * - * cdef int match(self, int sym1, int sym2): - */ - __pyx_r = (-((-__pyx_v_sym) & (~__pyx_v_8_cdec_sa_INDEX_MASK))); - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":36 - * return -(-sym& ~INDEX_MASK) - * - * cdef int match(self, int sym1, int sym2): # <<<<<<<<<<<<<< - * return self.clearindex(sym1) == self.clearindex(sym2); - * - */ - -static int __pyx_f_8_cdec_sa_8Alphabet_match(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, int __pyx_v_sym1, int __pyx_v_sym2) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("match", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":37 - * - * cdef int match(self, int sym1, int sym2): - * return self.clearindex(sym1) == self.clearindex(sym2); # <<<<<<<<<<<<<< - * - * cdef char* tocat(self, int sym): - */ - __pyx_r = (((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->clearindex(__pyx_v_self, __pyx_v_sym1) == ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->clearindex(__pyx_v_self, __pyx_v_sym2)); - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":39 - * return self.clearindex(sym1) == self.clearindex(sym2); - * - * cdef char* tocat(self, int sym): # <<<<<<<<<<<<<< - * return self.nonterminals.word((-sym >> INDEX_SHIFT)-1) - * - */ - -static char *__pyx_f_8_cdec_sa_8Alphabet_tocat(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, int __pyx_v_sym) { - char *__pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("tocat", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":40 - * - * cdef char* tocat(self, int sym): - * return self.nonterminals.word((-sym >> INDEX_SHIFT)-1) # <<<<<<<<<<<<<< - * - * cdef int fromcat(self, char *s): - */ - __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_StringMap *)__pyx_v_self->nonterminals->__pyx_vtab)->word(__pyx_v_self->nonterminals, (((-__pyx_v_sym) >> __pyx_v_8_cdec_sa_INDEX_SHIFT) - 1)); - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":42 - * return self.nonterminals.word((-sym >> INDEX_SHIFT)-1) - * - * cdef int fromcat(self, char *s): # <<<<<<<<<<<<<< - * cdef int i - * i = self.nonterminals.index(s) - */ - -static int __pyx_f_8_cdec_sa_8Alphabet_fromcat(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, char *__pyx_v_s) { - int __pyx_v_i; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("fromcat", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":44 - * cdef int fromcat(self, char *s): - * cdef int i - * i = self.nonterminals.index(s) # <<<<<<<<<<<<<< - * if self.first_nonterminal == -1: - * self.first_nonterminal = i - */ - __pyx_v_i = ((struct __pyx_vtabstruct_8_cdec_sa_StringMap *)__pyx_v_self->nonterminals->__pyx_vtab)->index(__pyx_v_self->nonterminals, __pyx_v_s); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":45 - * cdef int i - * i = self.nonterminals.index(s) - * if self.first_nonterminal == -1: # <<<<<<<<<<<<<< - * self.first_nonterminal = i - * if i > self.last_nonterminal: - */ - __pyx_t_1 = (__pyx_v_self->first_nonterminal == -1); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":46 - * i = self.nonterminals.index(s) - * if self.first_nonterminal == -1: - * self.first_nonterminal = i # <<<<<<<<<<<<<< - * if i > self.last_nonterminal: - * self.last_nonterminal = i - */ - __pyx_v_self->first_nonterminal = __pyx_v_i; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":47 - * if self.first_nonterminal == -1: - * self.first_nonterminal = i - * if i > self.last_nonterminal: # <<<<<<<<<<<<<< - * self.last_nonterminal = i - * return -(i+1 << INDEX_SHIFT) - */ - __pyx_t_1 = (__pyx_v_i > __pyx_v_self->last_nonterminal); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":48 - * self.first_nonterminal = i - * if i > self.last_nonterminal: - * self.last_nonterminal = i # <<<<<<<<<<<<<< - * return -(i+1 << INDEX_SHIFT) - * - */ - __pyx_v_self->last_nonterminal = __pyx_v_i; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":49 - * if i > self.last_nonterminal: - * self.last_nonterminal = i - * return -(i+1 << INDEX_SHIFT) # <<<<<<<<<<<<<< - * - * cdef char* tostring(self, int sym): - */ - __pyx_r = (-((__pyx_v_i + 1) << __pyx_v_8_cdec_sa_INDEX_SHIFT)); - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":51 - * return -(i+1 << INDEX_SHIFT) - * - * cdef char* tostring(self, int sym): # <<<<<<<<<<<<<< - * cdef int ind - * if self.isvar(sym): - */ - -static char *__pyx_f_8_cdec_sa_8Alphabet_tostring(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, int __pyx_v_sym) { - int __pyx_v_ind; - char *__pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - char *__pyx_t_4; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("tostring", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":53 - * cdef char* tostring(self, int sym): - * cdef int ind - * if self.isvar(sym): # <<<<<<<<<<<<<< - * if sym in self.id2sym: - * return self.id2sym[sym] - */ - __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->isvar(__pyx_v_self, __pyx_v_sym); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":54 - * cdef int ind - * if self.isvar(sym): - * if sym in self.id2sym: # <<<<<<<<<<<<<< - * return self.id2sym[sym] - * - */ - __pyx_t_2 = PyInt_FromLong(__pyx_v_sym); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - if (unlikely(((PyObject *)__pyx_v_self->id2sym) == Py_None)) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); {__pyx_filename = __pyx_f[10]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_3 = ((PyDict_Contains(((PyObject *)__pyx_v_self->id2sym), __pyx_t_2))); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":55 - * if self.isvar(sym): - * if sym in self.id2sym: - * return self.id2sym[sym] # <<<<<<<<<<<<<< - * - * ind = self.getindex(sym) - */ - __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_self->id2sym), __pyx_v_sym, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyBytes_AsString(__pyx_t_2); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_4; - goto __pyx_L0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":57 - * return self.id2sym[sym] - * - * ind = self.getindex(sym) # <<<<<<<<<<<<<< - * if ind > 0: - * self.id2sym[sym] = "[%s,%d]" % (self.tocat(sym), ind) - */ - __pyx_v_ind = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->getindex(__pyx_v_self, __pyx_v_sym); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":58 - * - * ind = self.getindex(sym) - * if ind > 0: # <<<<<<<<<<<<<< - * self.id2sym[sym] = "[%s,%d]" % (self.tocat(sym), ind) - * else: - */ - __pyx_t_3 = (__pyx_v_ind > 0); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":59 - * ind = self.getindex(sym) - * if ind > 0: - * self.id2sym[sym] = "[%s,%d]" % (self.tocat(sym), ind) # <<<<<<<<<<<<<< - * else: - * self.id2sym[sym] = "[%s]" % self.tocat(sym) - */ - __pyx_t_2 = PyBytes_FromString(((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->tocat(__pyx_v_self, __pyx_v_sym)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_t_5 = PyInt_FromLong(__pyx_v_ind); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_2 = 0; - __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_61), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - if (__Pyx_SetItemInt(((PyObject *)__pyx_v_self->id2sym), __pyx_v_sym, ((PyObject *)__pyx_t_5), sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - goto __pyx_L5; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":61 - * self.id2sym[sym] = "[%s,%d]" % (self.tocat(sym), ind) - * else: - * self.id2sym[sym] = "[%s]" % self.tocat(sym) # <<<<<<<<<<<<<< - * return self.id2sym[sym] - * - */ - __pyx_t_5 = PyBytes_FromString(((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->tocat(__pyx_v_self, __pyx_v_sym)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_62), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_6)); - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - if (__Pyx_SetItemInt(((PyObject *)__pyx_v_self->id2sym), __pyx_v_sym, ((PyObject *)__pyx_t_6), sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":62 - * else: - * self.id2sym[sym] = "[%s]" % self.tocat(sym) - * return self.id2sym[sym] # <<<<<<<<<<<<<< - * - * else: - */ - __pyx_t_6 = __Pyx_GetItemInt(((PyObject *)__pyx_v_self->id2sym), __pyx_v_sym, sizeof(int), PyInt_FromLong); if (!__pyx_t_6) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_4 = PyBytes_AsString(__pyx_t_6); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_r = __pyx_t_4; - goto __pyx_L0; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":65 - * - * else: - * return self.terminals.word(sym) # <<<<<<<<<<<<<< - * - * cdef int fromstring(self, char *s, bint terminal): - */ - __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_StringMap *)__pyx_v_self->terminals->__pyx_vtab)->word(__pyx_v_self->terminals, __pyx_v_sym); - goto __pyx_L0; - } - __pyx_L3:; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_WriteUnraisable("_cdec_sa.Alphabet.tostring", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":67 - * return self.terminals.word(sym) - * - * cdef int fromstring(self, char *s, bint terminal): # <<<<<<<<<<<<<< - * """Warning: this method is allowed to alter s.""" - * cdef char *comma - */ - -static int __pyx_f_8_cdec_sa_8Alphabet_fromstring(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self, char *__pyx_v_s, int __pyx_v_terminal) { - char *__pyx_v_comma; - int __pyx_v_n; - char *__pyx_v_sep; - PyObject *__pyx_v_s1 = NULL; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - char *__pyx_t_8; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("fromstring", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":71 - * cdef char *comma - * cdef int n - * n = strlen(s) # <<<<<<<<<<<<<< - * cdef char *sep - * sep = strstr(s,"_SEP_") - */ - __pyx_v_n = strlen(__pyx_v_s); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":73 - * n = strlen(s) - * cdef char *sep - * sep = strstr(s,"_SEP_") # <<<<<<<<<<<<<< - * if n >= 3 and s[0] == c'[' and s[n-1] == c']' and sep == NULL: - * if terminal: - */ - __pyx_v_sep = strstr(__pyx_v_s, __pyx_k___SEP_); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":74 - * cdef char *sep - * sep = strstr(s,"_SEP_") - * if n >= 3 and s[0] == c'[' and s[n-1] == c']' and sep == NULL: # <<<<<<<<<<<<<< - * if terminal: - * s1 = "\\"+s - */ - __pyx_t_1 = (__pyx_v_n >= 3); - if (__pyx_t_1) { - __pyx_t_2 = ((__pyx_v_s[0]) == '['); - if (__pyx_t_2) { - __pyx_t_3 = ((__pyx_v_s[(__pyx_v_n - 1)]) == ']'); - if (__pyx_t_3) { - __pyx_t_4 = (__pyx_v_sep == NULL); - __pyx_t_5 = __pyx_t_4; - } else { - __pyx_t_5 = __pyx_t_3; - } - __pyx_t_3 = __pyx_t_5; - } else { - __pyx_t_3 = __pyx_t_2; - } - __pyx_t_2 = __pyx_t_3; - } else { - __pyx_t_2 = __pyx_t_1; - } - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":75 - * sep = strstr(s,"_SEP_") - * if n >= 3 and s[0] == c'[' and s[n-1] == c']' and sep == NULL: - * if terminal: # <<<<<<<<<<<<<< - * s1 = "\\"+s - * return self.terminals.index(s1) - */ - if (__pyx_v_terminal) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":76 - * if n >= 3 and s[0] == c'[' and s[n-1] == c']' and sep == NULL: - * if terminal: - * s1 = "\\"+s # <<<<<<<<<<<<<< - * return self.terminals.index(s1) - * s[n-1] = c'\0' - */ - __pyx_t_6 = PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_6)); - __pyx_t_7 = PyNumber_Add(((PyObject *)__pyx_kp_s_63), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __pyx_v_s1 = __pyx_t_7; - __pyx_t_7 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":77 - * if terminal: - * s1 = "\\"+s - * return self.terminals.index(s1) # <<<<<<<<<<<<<< - * s[n-1] = c'\0' - * s = s + 1 - */ - __pyx_t_8 = PyBytes_AsString(__pyx_v_s1); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_StringMap *)__pyx_v_self->terminals->__pyx_vtab)->index(__pyx_v_self->terminals, __pyx_t_8); - goto __pyx_L0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":78 - * s1 = "\\"+s - * return self.terminals.index(s1) - * s[n-1] = c'\0' # <<<<<<<<<<<<<< - * s = s + 1 - * comma = strrchr(s, c',') - */ - (__pyx_v_s[(__pyx_v_n - 1)]) = '\x00'; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":79 - * return self.terminals.index(s1) - * s[n-1] = c'\0' - * s = s + 1 # <<<<<<<<<<<<<< - * comma = strrchr(s, c',') - * if comma != NULL: - */ - __pyx_v_s = (__pyx_v_s + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":80 - * s[n-1] = c'\0' - * s = s + 1 - * comma = strrchr(s, c',') # <<<<<<<<<<<<<< - * if comma != NULL: - * comma[0] = c'\0' - */ - __pyx_v_comma = strrchr(__pyx_v_s, ','); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":81 - * s = s + 1 - * comma = strrchr(s, c',') - * if comma != NULL: # <<<<<<<<<<<<<< - * comma[0] = c'\0' - * return self.setindex(self.fromcat(s), strtol(comma+1, NULL, 10)) - */ - __pyx_t_2 = (__pyx_v_comma != NULL); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":82 - * comma = strrchr(s, c',') - * if comma != NULL: - * comma[0] = c'\0' # <<<<<<<<<<<<<< - * return self.setindex(self.fromcat(s), strtol(comma+1, NULL, 10)) - * else: - */ - (__pyx_v_comma[0]) = '\x00'; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":83 - * if comma != NULL: - * comma[0] = c'\0' - * return self.setindex(self.fromcat(s), strtol(comma+1, NULL, 10)) # <<<<<<<<<<<<<< - * else: - * return self.fromcat(s) - */ - __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->setindex(__pyx_v_self, ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->fromcat(__pyx_v_self, __pyx_v_s), strtol((__pyx_v_comma + 1), NULL, 10)); - goto __pyx_L0; - goto __pyx_L5; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":85 - * return self.setindex(self.fromcat(s), strtol(comma+1, NULL, 10)) - * else: - * return self.fromcat(s) # <<<<<<<<<<<<<< - * else: - * return self.terminals.index(s) - */ - __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->fromcat(__pyx_v_self, __pyx_v_s); - goto __pyx_L0; - } - __pyx_L5:; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":87 - * return self.fromcat(s) - * else: - * return self.terminals.index(s) # <<<<<<<<<<<<<< - * - * cdef Alphabet ALPHABET = Alphabet() - */ - __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_StringMap *)__pyx_v_self->terminals->__pyx_vtab)->index(__pyx_v_self->terminals, __pyx_v_s); - goto __pyx_L0; - } - __pyx_L3:; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_WriteUnraisable("_cdec_sa.Alphabet.fromstring", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_s1); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_8Alphabet_9terminals_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_8Alphabet_9terminals_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_8Alphabet_9terminals___get__(((struct __pyx_obj_8_cdec_sa_Alphabet *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":8 - * - * cdef class Alphabet: - * cdef readonly StringMap terminals, nonterminals # <<<<<<<<<<<<<< - * cdef int first_nonterminal, last_nonterminal - * cdef dict id2sym - */ - -static PyObject *__pyx_pf_8_cdec_sa_8Alphabet_9terminals___get__(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self->terminals)); - __pyx_r = ((PyObject *)__pyx_v_self->terminals); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_8Alphabet_12nonterminals_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_8Alphabet_12nonterminals_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_8Alphabet_12nonterminals___get__(((struct __pyx_obj_8_cdec_sa_Alphabet *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8_cdec_sa_8Alphabet_12nonterminals___get__(struct __pyx_obj_8_cdec_sa_Alphabet *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self->nonterminals)); - __pyx_r = ((PyObject *)__pyx_v_self->nonterminals); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_3sym_tostring(PyObject *__pyx_self, PyObject *__pyx_arg_sym); /*proto*/ -static PyMethodDef __pyx_mdef_8_cdec_sa_3sym_tostring = {__Pyx_NAMESTR("sym_tostring"), (PyCFunction)__pyx_pw_8_cdec_sa_3sym_tostring, METH_O, __Pyx_DOCSTR(0)}; -static PyObject *__pyx_pw_8_cdec_sa_3sym_tostring(PyObject *__pyx_self, PyObject *__pyx_arg_sym) { - int __pyx_v_sym; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("sym_tostring (wrapper)", 0); - __pyx_self = __pyx_self; - assert(__pyx_arg_sym); { - __pyx_v_sym = __Pyx_PyInt_AsInt(__pyx_arg_sym); if (unlikely((__pyx_v_sym == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.sym_tostring", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_2sym_tostring(__pyx_self, ((int)__pyx_v_sym)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":91 - * cdef Alphabet ALPHABET = Alphabet() - * - * def sym_tostring(int sym): # <<<<<<<<<<<<<< - * return ALPHABET.tostring(sym) - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_2sym_tostring(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_sym) { - 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("sym_tostring", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":92 - * - * def sym_tostring(int sym): - * return ALPHABET.tostring(sym) # <<<<<<<<<<<<<< - * - * def sym_fromstring(bytes string, bint terminal): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->tostring(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_sym)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 92; __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_sa.sym_tostring", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_5sym_fromstring(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyMethodDef __pyx_mdef_8_cdec_sa_5sym_fromstring = {__Pyx_NAMESTR("sym_fromstring"), (PyCFunction)__pyx_pw_8_cdec_sa_5sym_fromstring, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}; -static PyObject *__pyx_pw_8_cdec_sa_5sym_fromstring(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_string = 0; - int __pyx_v_terminal; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__string,&__pyx_n_s__terminal,0}; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("sym_fromstring (wrapper)", 0); - __pyx_self = __pyx_self; - { - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__string); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__terminal); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("sym_fromstring", 1, 2, 2, 1); {__pyx_filename = __pyx_f[10]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sym_fromstring") < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_string = ((PyObject*)values[0]); - __pyx_v_terminal = __Pyx_PyObject_IsTrue(values[1]); if (unlikely((__pyx_v_terminal == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("sym_fromstring", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[10]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.sym_fromstring", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_string), (&PyBytes_Type), 1, "string", 1))) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_8_cdec_sa_4sym_fromstring(__pyx_self, __pyx_v_string, __pyx_v_terminal); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":94 - * return ALPHABET.tostring(sym) - * - * def sym_fromstring(bytes string, bint terminal): # <<<<<<<<<<<<<< - * return ALPHABET.fromstring(string, terminal) - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_4sym_fromstring(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_string, int __pyx_v_terminal) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - char *__pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("sym_fromstring", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":95 - * - * def sym_fromstring(bytes string, bint terminal): - * return ALPHABET.fromstring(string, terminal) # <<<<<<<<<<<<<< - * - * def sym_isvar(int sym): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_AsString(((PyObject *)__pyx_v_string)); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromLong(((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->fromstring(__pyx_v_8_cdec_sa_ALPHABET, __pyx_t_1, __pyx_v_terminal)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __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_2); - __Pyx_AddTraceback("_cdec_sa.sym_fromstring", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_7sym_isvar(PyObject *__pyx_self, PyObject *__pyx_arg_sym); /*proto*/ -static PyMethodDef __pyx_mdef_8_cdec_sa_7sym_isvar = {__Pyx_NAMESTR("sym_isvar"), (PyCFunction)__pyx_pw_8_cdec_sa_7sym_isvar, METH_O, __Pyx_DOCSTR(0)}; -static PyObject *__pyx_pw_8_cdec_sa_7sym_isvar(PyObject *__pyx_self, PyObject *__pyx_arg_sym) { - int __pyx_v_sym; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("sym_isvar (wrapper)", 0); - __pyx_self = __pyx_self; - assert(__pyx_arg_sym); { - __pyx_v_sym = __Pyx_PyInt_AsInt(__pyx_arg_sym); if (unlikely((__pyx_v_sym == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.sym_isvar", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_6sym_isvar(__pyx_self, ((int)__pyx_v_sym)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":97 - * return ALPHABET.fromstring(string, terminal) - * - * def sym_isvar(int sym): # <<<<<<<<<<<<<< - * return ALPHABET.isvar(sym) - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_6sym_isvar(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_sym) { - 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("sym_isvar", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":98 - * - * def sym_isvar(int sym): - * return ALPHABET.isvar(sym) # <<<<<<<<<<<<<< - * - * cdef int sym_setindex(int sym, int id): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->isvar(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_sym)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __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_AddTraceback("_cdec_sa.sym_isvar", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":100 - * return ALPHABET.isvar(sym) - * - * cdef int sym_setindex(int sym, int id): # <<<<<<<<<<<<<< - * return ALPHABET.setindex(sym, id) - */ - -static int __pyx_f_8_cdec_sa_sym_setindex(int __pyx_v_sym, int __pyx_v_id) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("sym_setindex", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":101 - * - * cdef int sym_setindex(int sym, int id): - * return ALPHABET.setindex(sym, id) # <<<<<<<<<<<<<< - */ - __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->setindex(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_sym, __pyx_v_id); - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_6Phrase_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_6Phrase_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_words = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__words,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[1] = {0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__words); - 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 8; __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_words = values[0]; - } - 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[7]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.Phrase.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_6Phrase___cinit__(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self), __pyx_v_words); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":8 - * cdef int n, *varpos, n_vars - * - * def __cinit__(self, words): # <<<<<<<<<<<<<< - * cdef int i, j, n, n_vars - * n_vars = 0 - */ - -static int __pyx_pf_8_cdec_sa_6Phrase___cinit__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_words) { - int __pyx_v_i; - int __pyx_v_j; - int __pyx_v_n; - int __pyx_v_n_vars; - int __pyx_r; - __Pyx_RefNannyDeclarations - Py_ssize_t __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":10 - * def __cinit__(self, words): - * cdef int i, j, n, n_vars - * n_vars = 0 # <<<<<<<<<<<<<< - * n = len(words) - * self.syms = malloc(n*sizeof(int)) - */ - __pyx_v_n_vars = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":11 - * cdef int i, j, n, n_vars - * n_vars = 0 - * n = len(words) # <<<<<<<<<<<<<< - * self.syms = malloc(n*sizeof(int)) - * for i from 0 <= i < n: - */ - __pyx_t_1 = PyObject_Length(__pyx_v_words); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_n = __pyx_t_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":12 - * n_vars = 0 - * n = len(words) - * self.syms = malloc(n*sizeof(int)) # <<<<<<<<<<<<<< - * for i from 0 <= i < n: - * self.syms[i] = words[i] - */ - __pyx_v_self->syms = ((int *)malloc((__pyx_v_n * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":13 - * n = len(words) - * self.syms = malloc(n*sizeof(int)) - * for i from 0 <= i < n: # <<<<<<<<<<<<<< - * self.syms[i] = words[i] - * if ALPHABET.isvar(self.syms[i]): - */ - __pyx_t_2 = __pyx_v_n; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":14 - * self.syms = malloc(n*sizeof(int)) - * for i from 0 <= i < n: - * self.syms[i] = words[i] # <<<<<<<<<<<<<< - * if ALPHABET.isvar(self.syms[i]): - * n_vars += 1 - */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_words, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - (__pyx_v_self->syms[__pyx_v_i]) = __pyx_t_4; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":15 - * for i from 0 <= i < n: - * self.syms[i] = words[i] - * if ALPHABET.isvar(self.syms[i]): # <<<<<<<<<<<<<< - * n_vars += 1 - * self.n = n - */ - __pyx_t_4 = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->isvar(__pyx_v_8_cdec_sa_ALPHABET, (__pyx_v_self->syms[__pyx_v_i])); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":16 - * self.syms[i] = words[i] - * if ALPHABET.isvar(self.syms[i]): - * n_vars += 1 # <<<<<<<<<<<<<< - * self.n = n - * self.n_vars = n_vars - */ - __pyx_v_n_vars = (__pyx_v_n_vars + 1); - goto __pyx_L5; - } - __pyx_L5:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":17 - * if ALPHABET.isvar(self.syms[i]): - * n_vars += 1 - * self.n = n # <<<<<<<<<<<<<< - * self.n_vars = n_vars - * self.varpos = malloc(n_vars*sizeof(int)) - */ - __pyx_v_self->n = __pyx_v_n; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":18 - * n_vars += 1 - * self.n = n - * self.n_vars = n_vars # <<<<<<<<<<<<<< - * self.varpos = malloc(n_vars*sizeof(int)) - * j = 0 - */ - __pyx_v_self->n_vars = __pyx_v_n_vars; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":19 - * self.n = n - * self.n_vars = n_vars - * self.varpos = malloc(n_vars*sizeof(int)) # <<<<<<<<<<<<<< - * j = 0 - * for i from 0 <= i < n: - */ - __pyx_v_self->varpos = ((int *)malloc((__pyx_v_n_vars * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":20 - * self.n_vars = n_vars - * self.varpos = malloc(n_vars*sizeof(int)) - * j = 0 # <<<<<<<<<<<<<< - * for i from 0 <= i < n: - * if ALPHABET.isvar(self.syms[i]): - */ - __pyx_v_j = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":21 - * self.varpos = malloc(n_vars*sizeof(int)) - * j = 0 - * for i from 0 <= i < n: # <<<<<<<<<<<<<< - * if ALPHABET.isvar(self.syms[i]): - * self.varpos[j] = i - */ - __pyx_t_2 = __pyx_v_n; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":22 - * j = 0 - * for i from 0 <= i < n: - * if ALPHABET.isvar(self.syms[i]): # <<<<<<<<<<<<<< - * self.varpos[j] = i - * j = j + 1 - */ - __pyx_t_4 = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->isvar(__pyx_v_8_cdec_sa_ALPHABET, (__pyx_v_self->syms[__pyx_v_i])); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":23 - * for i from 0 <= i < n: - * if ALPHABET.isvar(self.syms[i]): - * self.varpos[j] = i # <<<<<<<<<<<<<< - * j = j + 1 - * - */ - (__pyx_v_self->varpos[__pyx_v_j]) = __pyx_v_i; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":24 - * if ALPHABET.isvar(self.syms[i]): - * self.varpos[j] = i - * j = j + 1 # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - __pyx_v_j = (__pyx_v_j + 1); - goto __pyx_L8; - } - __pyx_L8:; - } - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.Phrase.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static void __pyx_pw_8_cdec_sa_6Phrase_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_8_cdec_sa_6Phrase_3__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_8_cdec_sa_6Phrase_2__dealloc__(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":26 - * j = j + 1 - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * free(self.syms) - * free(self.varpos) - */ - -static void __pyx_pf_8_cdec_sa_6Phrase_2__dealloc__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":27 - * - * def __dealloc__(self): - * free(self.syms) # <<<<<<<<<<<<<< - * free(self.varpos) - * - */ - free(__pyx_v_self->syms); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":28 - * def __dealloc__(self): - * free(self.syms) - * free(self.varpos) # <<<<<<<<<<<<<< - * - * def __str__(self): - */ - free(__pyx_v_self->varpos); - - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_5__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_5__str__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_4__str__(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":30 - * free(self.varpos) - * - * def __str__(self): # <<<<<<<<<<<<<< - * strs = [] - * cdef int i, s - */ - -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_4__str__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self) { - PyObject *__pyx_v_strs = NULL; - int __pyx_v_i; - int __pyx_v_s; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__str__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":31 - * - * def __str__(self): - * strs = [] # <<<<<<<<<<<<<< - * cdef int i, s - * for i from 0 <= i < self.n: - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_strs = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":33 - * strs = [] - * cdef int i, s - * for i from 0 <= i < self.n: # <<<<<<<<<<<<<< - * s = self.syms[i] - * strs.append(ALPHABET.tostring(s)) - */ - __pyx_t_2 = __pyx_v_self->n; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":34 - * cdef int i, s - * for i from 0 <= i < self.n: - * s = self.syms[i] # <<<<<<<<<<<<<< - * strs.append(ALPHABET.tostring(s)) - * return " ".join(strs) - */ - __pyx_v_s = (__pyx_v_self->syms[__pyx_v_i]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":35 - * for i from 0 <= i < self.n: - * s = self.syms[i] - * strs.append(ALPHABET.tostring(s)) # <<<<<<<<<<<<<< - * return " ".join(strs) - * - */ - __pyx_t_1 = PyBytes_FromString(((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->tostring(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_s)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyList_Append(__pyx_v_strs, ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":36 - * s = self.syms[i] - * strs.append(ALPHABET.tostring(s)) - * return " ".join(strs) # <<<<<<<<<<<<<< - * - * def handle(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_64), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(((PyObject *)__pyx_v_strs)); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_strs)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_strs)); - __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 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_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("_cdec_sa.Phrase.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_strs); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_7handle(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static char __pyx_doc_8_cdec_sa_6Phrase_6handle[] = "return a hashable representation that normalizes the ordering\n of the nonterminal indices"; -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_7handle(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("handle (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_6handle(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":38 - * return " ".join(strs) - * - * def handle(self): # <<<<<<<<<<<<<< - * """return a hashable representation that normalizes the ordering - * of the nonterminal indices""" - */ - -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_6handle(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self) { - PyObject *__pyx_v_norm = NULL; - int __pyx_v_i; - int __pyx_v_j; - int __pyx_v_s; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("handle", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":41 - * """return a hashable representation that normalizes the ordering - * of the nonterminal indices""" - * norm = [] # <<<<<<<<<<<<<< - * cdef int i, j, s - * i = 1 - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_norm = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":43 - * norm = [] - * cdef int i, j, s - * i = 1 # <<<<<<<<<<<<<< - * j = 0 - * for j from 0 <= j < self.n: - */ - __pyx_v_i = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":44 - * cdef int i, j, s - * i = 1 - * j = 0 # <<<<<<<<<<<<<< - * for j from 0 <= j < self.n: - * s = self.syms[j] - */ - __pyx_v_j = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":45 - * i = 1 - * j = 0 - * for j from 0 <= j < self.n: # <<<<<<<<<<<<<< - * s = self.syms[j] - * if ALPHABET.isvar(s): - */ - __pyx_t_2 = __pyx_v_self->n; - for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_2; __pyx_v_j++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":46 - * j = 0 - * for j from 0 <= j < self.n: - * s = self.syms[j] # <<<<<<<<<<<<<< - * if ALPHABET.isvar(s): - * s = ALPHABET.setindex(s,i) - */ - __pyx_v_s = (__pyx_v_self->syms[__pyx_v_j]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":47 - * for j from 0 <= j < self.n: - * s = self.syms[j] - * if ALPHABET.isvar(s): # <<<<<<<<<<<<<< - * s = ALPHABET.setindex(s,i) - * i = i + 1 - */ - __pyx_t_3 = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->isvar(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_s); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":48 - * s = self.syms[j] - * if ALPHABET.isvar(s): - * s = ALPHABET.setindex(s,i) # <<<<<<<<<<<<<< - * i = i + 1 - * norm.append(s) - */ - __pyx_v_s = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->setindex(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_s, __pyx_v_i); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":49 - * if ALPHABET.isvar(s): - * s = ALPHABET.setindex(s,i) - * i = i + 1 # <<<<<<<<<<<<<< - * norm.append(s) - * return tuple(norm) - */ - __pyx_v_i = (__pyx_v_i + 1); - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":50 - * s = ALPHABET.setindex(s,i) - * i = i + 1 - * norm.append(s) # <<<<<<<<<<<<<< - * return tuple(norm) - * - */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_s); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyList_Append(__pyx_v_norm, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":51 - * i = i + 1 - * norm.append(s) - * return tuple(norm) # <<<<<<<<<<<<<< - * - * def strhandle(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = ((PyObject *)PyList_AsTuple(__pyx_v_norm)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 51; __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_sa.Phrase.handle", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_norm); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_9strhandle(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_9strhandle(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("strhandle (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_8strhandle(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":53 - * return tuple(norm) - * - * def strhandle(self): # <<<<<<<<<<<<<< - * strs = [] - * norm = [] - */ - -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_8strhandle(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self) { - CYTHON_UNUSED PyObject *__pyx_v_strs = NULL; - PyObject *__pyx_v_norm = NULL; - int __pyx_v_i; - int __pyx_v_j; - int __pyx_v_s; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("strhandle", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":54 - * - * def strhandle(self): - * strs = [] # <<<<<<<<<<<<<< - * norm = [] - * cdef int i, j, s - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_strs = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":55 - * def strhandle(self): - * strs = [] - * norm = [] # <<<<<<<<<<<<<< - * cdef int i, j, s - * i = 1 - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_norm = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":57 - * norm = [] - * cdef int i, j, s - * i = 1 # <<<<<<<<<<<<<< - * j = 0 - * for j from 0 <= j < self.n: - */ - __pyx_v_i = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":58 - * cdef int i, j, s - * i = 1 - * j = 0 # <<<<<<<<<<<<<< - * for j from 0 <= j < self.n: - * s = self.syms[j] - */ - __pyx_v_j = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":59 - * i = 1 - * j = 0 - * for j from 0 <= j < self.n: # <<<<<<<<<<<<<< - * s = self.syms[j] - * if ALPHABET.isvar(s): - */ - __pyx_t_2 = __pyx_v_self->n; - for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_2; __pyx_v_j++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":60 - * j = 0 - * for j from 0 <= j < self.n: - * s = self.syms[j] # <<<<<<<<<<<<<< - * if ALPHABET.isvar(s): - * s = ALPHABET.setindex(s,i) - */ - __pyx_v_s = (__pyx_v_self->syms[__pyx_v_j]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":61 - * for j from 0 <= j < self.n: - * s = self.syms[j] - * if ALPHABET.isvar(s): # <<<<<<<<<<<<<< - * s = ALPHABET.setindex(s,i) - * i = i + 1 - */ - __pyx_t_3 = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->isvar(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_s); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":62 - * s = self.syms[j] - * if ALPHABET.isvar(s): - * s = ALPHABET.setindex(s,i) # <<<<<<<<<<<<<< - * i = i + 1 - * norm.append(ALPHABET.tostring(s)) - */ - __pyx_v_s = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->setindex(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_s, __pyx_v_i); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":63 - * if ALPHABET.isvar(s): - * s = ALPHABET.setindex(s,i) - * i = i + 1 # <<<<<<<<<<<<<< - * norm.append(ALPHABET.tostring(s)) - * return " ".join(norm) - */ - __pyx_v_i = (__pyx_v_i + 1); - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":64 - * s = ALPHABET.setindex(s,i) - * i = i + 1 - * norm.append(ALPHABET.tostring(s)) # <<<<<<<<<<<<<< - * return " ".join(norm) - * - */ - __pyx_t_1 = PyBytes_FromString(((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->tostring(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_s)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_4 = PyList_Append(__pyx_v_norm, ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":65 - * i = i + 1 - * norm.append(ALPHABET.tostring(s)) - * return " ".join(norm) # <<<<<<<<<<<<<< - * - * def arity(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_64), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(((PyObject *)__pyx_v_norm)); - PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_norm)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_norm)); - __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_r = __pyx_t_6; - __pyx_t_6 = 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_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("_cdec_sa.Phrase.strhandle", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_strs); - __Pyx_XDECREF(__pyx_v_norm); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_11arity(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_11arity(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("arity (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_10arity(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":67 - * return " ".join(norm) - * - * def arity(self): # <<<<<<<<<<<<<< - * return self.n_vars - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_10arity(struct __pyx_obj_8_cdec_sa_Phrase *__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("arity", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":68 - * - * def arity(self): - * return self.n_vars # <<<<<<<<<<<<<< - * - * def getvarpos(self, i): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->n_vars); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __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_AddTraceback("_cdec_sa.Phrase.arity", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_13getvarpos(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_13getvarpos(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("getvarpos (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_12getvarpos(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self), ((PyObject *)__pyx_v_i)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":70 - * return self.n_vars - * - * def getvarpos(self, i): # <<<<<<<<<<<<<< - * if 0 <= i < self.n_vars: - * return self.varpos[i] - */ - -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_12getvarpos(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - Py_ssize_t __pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("getvarpos", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":71 - * - * def getvarpos(self, i): - * if 0 <= i < self.n_vars: # <<<<<<<<<<<<<< - * return self.varpos[i] - * else: - */ - __pyx_t_1 = PyObject_RichCompare(__pyx_int_0, __pyx_v_i, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_PyObject_IsTrue(__pyx_t_1)) { - __Pyx_DECREF(__pyx_t_1); - __pyx_t_2 = PyInt_FromLong(__pyx_v_self->n_vars); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_RichCompare(__pyx_v_i, __pyx_t_2, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":72 - * def getvarpos(self, i): - * if 0 <= i < self.n_vars: - * return self.varpos[i] # <<<<<<<<<<<<<< - * else: - * raise IndexError - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = PyInt_FromLong((__pyx_v_self->varpos[__pyx_t_4])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":74 - * return self.varpos[i] - * else: - * raise IndexError # <<<<<<<<<<<<<< - * - * def getvar(self, i): - */ - __Pyx_Raise(__pyx_builtin_IndexError, 0, 0, 0); - {__pyx_filename = __pyx_f[7]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L3:; - - __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_sa.Phrase.getvarpos", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_15getvar(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_15getvar(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("getvar (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_14getvar(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self), ((PyObject *)__pyx_v_i)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":76 - * raise IndexError - * - * def getvar(self, i): # <<<<<<<<<<<<<< - * if 0 <= i < self.n_vars: - * return self.syms[self.varpos[i]] - */ - -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_14getvar(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - Py_ssize_t __pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("getvar", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":77 - * - * def getvar(self, i): - * if 0 <= i < self.n_vars: # <<<<<<<<<<<<<< - * return self.syms[self.varpos[i]] - * else: - */ - __pyx_t_1 = PyObject_RichCompare(__pyx_int_0, __pyx_v_i, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_PyObject_IsTrue(__pyx_t_1)) { - __Pyx_DECREF(__pyx_t_1); - __pyx_t_2 = PyInt_FromLong(__pyx_v_self->n_vars); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_RichCompare(__pyx_v_i, __pyx_t_2, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":78 - * def getvar(self, i): - * if 0 <= i < self.n_vars: - * return self.syms[self.varpos[i]] # <<<<<<<<<<<<<< - * else: - * raise IndexError - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = PyInt_FromLong((__pyx_v_self->syms[(__pyx_v_self->varpos[__pyx_t_4])])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":80 - * return self.syms[self.varpos[i]] - * else: - * raise IndexError # <<<<<<<<<<<<<< - * - * cdef int chunkpos(self, int k): - */ - __Pyx_Raise(__pyx_builtin_IndexError, 0, 0, 0); - {__pyx_filename = __pyx_f[7]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L3:; - - __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_sa.Phrase.getvar", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":82 - * raise IndexError - * - * cdef int chunkpos(self, int k): # <<<<<<<<<<<<<< - * if k == 0: - * return 0 - */ - -static int __pyx_f_8_cdec_sa_6Phrase_chunkpos(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, int __pyx_v_k) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("chunkpos", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":83 - * - * cdef int chunkpos(self, int k): - * if k == 0: # <<<<<<<<<<<<<< - * return 0 - * else: - */ - __pyx_t_1 = (__pyx_v_k == 0); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":84 - * cdef int chunkpos(self, int k): - * if k == 0: - * return 0 # <<<<<<<<<<<<<< - * else: - * return self.varpos[k-1]+1 - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":86 - * return 0 - * else: - * return self.varpos[k-1]+1 # <<<<<<<<<<<<<< - * - * cdef int chunklen(self, int k): - */ - __pyx_r = ((__pyx_v_self->varpos[(__pyx_v_k - 1)]) + 1); - goto __pyx_L0; - } - __pyx_L3:; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":88 - * return self.varpos[k-1]+1 - * - * cdef int chunklen(self, int k): # <<<<<<<<<<<<<< - * if self.n_vars == 0: - * return self.n - */ - -static int __pyx_f_8_cdec_sa_6Phrase_chunklen(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, int __pyx_v_k) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("chunklen", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":89 - * - * cdef int chunklen(self, int k): - * if self.n_vars == 0: # <<<<<<<<<<<<<< - * return self.n - * elif k == 0: - */ - __pyx_t_1 = (__pyx_v_self->n_vars == 0); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":90 - * cdef int chunklen(self, int k): - * if self.n_vars == 0: - * return self.n # <<<<<<<<<<<<<< - * elif k == 0: - * return self.varpos[0] - */ - __pyx_r = __pyx_v_self->n; - goto __pyx_L0; - goto __pyx_L3; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":91 - * if self.n_vars == 0: - * return self.n - * elif k == 0: # <<<<<<<<<<<<<< - * return self.varpos[0] - * elif k == self.n_vars: - */ - __pyx_t_1 = (__pyx_v_k == 0); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":92 - * return self.n - * elif k == 0: - * return self.varpos[0] # <<<<<<<<<<<<<< - * elif k == self.n_vars: - * return self.n-self.varpos[k-1]-1 - */ - __pyx_r = (__pyx_v_self->varpos[0]); - goto __pyx_L0; - goto __pyx_L3; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":93 - * elif k == 0: - * return self.varpos[0] - * elif k == self.n_vars: # <<<<<<<<<<<<<< - * return self.n-self.varpos[k-1]-1 - * else: - */ - __pyx_t_1 = (__pyx_v_k == __pyx_v_self->n_vars); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":94 - * return self.varpos[0] - * elif k == self.n_vars: - * return self.n-self.varpos[k-1]-1 # <<<<<<<<<<<<<< - * else: - * return self.varpos[k]-self.varpos[k-1]-1 - */ - __pyx_r = ((__pyx_v_self->n - (__pyx_v_self->varpos[(__pyx_v_k - 1)])) - 1); - goto __pyx_L0; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":96 - * return self.n-self.varpos[k-1]-1 - * else: - * return self.varpos[k]-self.varpos[k-1]-1 # <<<<<<<<<<<<<< - * - * def clen(self, k): - */ - __pyx_r = (((__pyx_v_self->varpos[__pyx_v_k]) - (__pyx_v_self->varpos[(__pyx_v_k - 1)])) - 1); - goto __pyx_L0; - } - __pyx_L3:; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_17clen(PyObject *__pyx_v_self, PyObject *__pyx_v_k); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_17clen(PyObject *__pyx_v_self, PyObject *__pyx_v_k) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("clen (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_16clen(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self), ((PyObject *)__pyx_v_k)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":98 - * return self.varpos[k]-self.varpos[k-1]-1 - * - * def clen(self, k): # <<<<<<<<<<<<<< - * return self.chunklen(k) - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_16clen(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_k) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("clen", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":99 - * - * def clen(self, k): - * return self.chunklen(k) # <<<<<<<<<<<<<< - * - * def getchunk(self, ci): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_k); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromLong(((struct __pyx_vtabstruct_8_cdec_sa_Phrase *)__pyx_v_self->__pyx_vtab)->chunklen(__pyx_v_self, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __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_2); - __Pyx_AddTraceback("_cdec_sa.Phrase.clen", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_19getchunk(PyObject *__pyx_v_self, PyObject *__pyx_v_ci); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_19getchunk(PyObject *__pyx_v_self, PyObject *__pyx_v_ci) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("getchunk (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_18getchunk(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self), ((PyObject *)__pyx_v_ci)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":101 - * return self.chunklen(k) - * - * def getchunk(self, ci): # <<<<<<<<<<<<<< - * cdef int start, stop - * start = self.chunkpos(ci) - */ - -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_18getchunk(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_ci) { - int __pyx_v_start; - int __pyx_v_stop; - PyObject *__pyx_v_chunk = NULL; - int __pyx_v_i; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("getchunk", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":103 - * def getchunk(self, ci): - * cdef int start, stop - * start = self.chunkpos(ci) # <<<<<<<<<<<<<< - * stop = start+self.chunklen(ci) - * chunk = [] - */ - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_ci); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_start = ((struct __pyx_vtabstruct_8_cdec_sa_Phrase *)__pyx_v_self->__pyx_vtab)->chunkpos(__pyx_v_self, __pyx_t_1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":104 - * cdef int start, stop - * start = self.chunkpos(ci) - * stop = start+self.chunklen(ci) # <<<<<<<<<<<<<< - * chunk = [] - * for i from start <= i < stop: - */ - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_ci); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_stop = (__pyx_v_start + ((struct __pyx_vtabstruct_8_cdec_sa_Phrase *)__pyx_v_self->__pyx_vtab)->chunklen(__pyx_v_self, __pyx_t_1)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":105 - * start = self.chunkpos(ci) - * stop = start+self.chunklen(ci) - * chunk = [] # <<<<<<<<<<<<<< - * for i from start <= i < stop: - * chunk.append(self.syms[i]) - */ - __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_chunk = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":106 - * stop = start+self.chunklen(ci) - * chunk = [] - * for i from start <= i < stop: # <<<<<<<<<<<<<< - * chunk.append(self.syms[i]) - * return chunk - */ - __pyx_t_1 = __pyx_v_stop; - for (__pyx_v_i = __pyx_v_start; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":107 - * chunk = [] - * for i from start <= i < stop: - * chunk.append(self.syms[i]) # <<<<<<<<<<<<<< - * return chunk - * - */ - __pyx_t_2 = PyInt_FromLong((__pyx_v_self->syms[__pyx_v_i])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyList_Append(__pyx_v_chunk, __pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":108 - * for i from start <= i < stop: - * chunk.append(self.syms[i]) - * return chunk # <<<<<<<<<<<<<< - * - * def __cmp__(self, other): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_chunk)); - __pyx_r = ((PyObject *)__pyx_v_chunk); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_cdec_sa.Phrase.getchunk", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_chunk); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -#if PY_MAJOR_VERSION < 3 -static int __pyx_pw_8_cdec_sa_6Phrase_21__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static int __pyx_pw_8_cdec_sa_6Phrase_21__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cmp__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_20__cmp__(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self), ((PyObject *)__pyx_v_other)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -#endif /*!(#if PY_MAJOR_VERSION < 3)*/ - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":110 - * return chunk - * - * def __cmp__(self, other): # <<<<<<<<<<<<<< - * cdef Phrase otherp - * cdef int i - */ - -#if PY_MAJOR_VERSION < 3 -static int __pyx_pf_8_cdec_sa_6Phrase_20__cmp__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_other) { - struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_otherp = 0; - int __pyx_v_i; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cmp__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":113 - * cdef Phrase otherp - * cdef int i - * otherp = other # <<<<<<<<<<<<<< - * for i from 0 <= i < min(self.n, otherp.n): - * if self.syms[i] < otherp.syms[i]: - */ - if (!(likely(((__pyx_v_other) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_other, __pyx_ptype_8_cdec_sa_Phrase))))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_INCREF(__pyx_v_other); - __pyx_v_otherp = ((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_other); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":114 - * cdef int i - * otherp = other - * for i from 0 <= i < min(self.n, otherp.n): # <<<<<<<<<<<<<< - * if self.syms[i] < otherp.syms[i]: - * return -1 - */ - __pyx_t_1 = __pyx_v_otherp->n; - __pyx_t_2 = __pyx_v_self->n; - if ((__pyx_t_1 < __pyx_t_2)) { - __pyx_t_3 = __pyx_t_1; - } else { - __pyx_t_3 = __pyx_t_2; - } - __pyx_t_1 = __pyx_t_3; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":115 - * otherp = other - * for i from 0 <= i < min(self.n, otherp.n): - * if self.syms[i] < otherp.syms[i]: # <<<<<<<<<<<<<< - * return -1 - * elif self.syms[i] > otherp.syms[i]: - */ - __pyx_t_4 = ((__pyx_v_self->syms[__pyx_v_i]) < (__pyx_v_otherp->syms[__pyx_v_i])); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":116 - * for i from 0 <= i < min(self.n, otherp.n): - * if self.syms[i] < otherp.syms[i]: - * return -1 # <<<<<<<<<<<<<< - * elif self.syms[i] > otherp.syms[i]: - * return 1 - */ - __pyx_r = -1; - goto __pyx_L0; - goto __pyx_L5; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":117 - * if self.syms[i] < otherp.syms[i]: - * return -1 - * elif self.syms[i] > otherp.syms[i]: # <<<<<<<<<<<<<< - * return 1 - * if self.n < otherp.n: - */ - __pyx_t_4 = ((__pyx_v_self->syms[__pyx_v_i]) > (__pyx_v_otherp->syms[__pyx_v_i])); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":118 - * return -1 - * elif self.syms[i] > otherp.syms[i]: - * return 1 # <<<<<<<<<<<<<< - * if self.n < otherp.n: - * return -1 - */ - __pyx_r = 1; - goto __pyx_L0; - goto __pyx_L5; - } - __pyx_L5:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":119 - * elif self.syms[i] > otherp.syms[i]: - * return 1 - * if self.n < otherp.n: # <<<<<<<<<<<<<< - * return -1 - * elif self.n > otherp.n: - */ - __pyx_t_4 = (__pyx_v_self->n < __pyx_v_otherp->n); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":120 - * return 1 - * if self.n < otherp.n: - * return -1 # <<<<<<<<<<<<<< - * elif self.n > otherp.n: - * return 1 - */ - __pyx_r = -1; - goto __pyx_L0; - goto __pyx_L6; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":121 - * if self.n < otherp.n: - * return -1 - * elif self.n > otherp.n: # <<<<<<<<<<<<<< - * return 1 - * else: - */ - __pyx_t_4 = (__pyx_v_self->n > __pyx_v_otherp->n); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":122 - * return -1 - * elif self.n > otherp.n: - * return 1 # <<<<<<<<<<<<<< - * else: - * return 0 - */ - __pyx_r = 1; - goto __pyx_L0; - goto __pyx_L6; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":124 - * return 1 - * else: - * return 0 # <<<<<<<<<<<<<< - * - * def __hash__(self): - */ - __pyx_r = 0; - goto __pyx_L0; - } - __pyx_L6:; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec_sa.Phrase.__cmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_otherp); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -#endif /*!(#if PY_MAJOR_VERSION < 3)*/ - -/* Python wrapper */ -static Py_hash_t __pyx_pw_8_cdec_sa_6Phrase_23__hash__(PyObject *__pyx_v_self); /*proto*/ -static Py_hash_t __pyx_pw_8_cdec_sa_6Phrase_23__hash__(PyObject *__pyx_v_self) { - Py_hash_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__hash__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_22__hash__(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":126 - * return 0 - * - * def __hash__(self): # <<<<<<<<<<<<<< - * cdef int i - * cdef unsigned h - */ - -static Py_hash_t __pyx_pf_8_cdec_sa_6Phrase_22__hash__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self) { - int __pyx_v_i; - unsigned int __pyx_v_h; - Py_hash_t __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - __Pyx_RefNannySetupContext("__hash__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":129 - * cdef int i - * cdef unsigned h - * h = 0 # <<<<<<<<<<<<<< - * for i from 0 <= i < self.n: - * if self.syms[i] > 0: - */ - __pyx_v_h = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":130 - * cdef unsigned h - * h = 0 - * for i from 0 <= i < self.n: # <<<<<<<<<<<<<< - * if self.syms[i] > 0: - * h = (h << 1) + self.syms[i] - */ - __pyx_t_1 = __pyx_v_self->n; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":131 - * h = 0 - * for i from 0 <= i < self.n: - * if self.syms[i] > 0: # <<<<<<<<<<<<<< - * h = (h << 1) + self.syms[i] - * else: - */ - __pyx_t_2 = ((__pyx_v_self->syms[__pyx_v_i]) > 0); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":132 - * for i from 0 <= i < self.n: - * if self.syms[i] > 0: - * h = (h << 1) + self.syms[i] # <<<<<<<<<<<<<< - * else: - * h = (h << 1) + -self.syms[i] - */ - __pyx_v_h = ((__pyx_v_h << 1) + (__pyx_v_self->syms[__pyx_v_i])); - goto __pyx_L5; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":134 - * h = (h << 1) + self.syms[i] - * else: - * h = (h << 1) + -self.syms[i] # <<<<<<<<<<<<<< - * return h - * - */ - __pyx_v_h = ((__pyx_v_h << 1) + (-(__pyx_v_self->syms[__pyx_v_i]))); - } - __pyx_L5:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":135 - * else: - * h = (h << 1) + -self.syms[i] - * return h # <<<<<<<<<<<<<< - * - * def __len__(self): - */ - __pyx_r = __pyx_v_h; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static Py_ssize_t __pyx_pw_8_cdec_sa_6Phrase_25__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_8_cdec_sa_6Phrase_25__len__(PyObject *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_24__len__(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":137 - * return h - * - * def __len__(self): # <<<<<<<<<<<<<< - * return self.n - * - */ - -static Py_ssize_t __pyx_pf_8_cdec_sa_6Phrase_24__len__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self) { - Py_ssize_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__len__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":138 - * - * def __len__(self): - * return self.n # <<<<<<<<<<<<<< - * - * def __getitem__(self, i): - */ - __pyx_r = __pyx_v_self->n; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_27__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_27__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_26__getitem__(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self), ((PyObject *)__pyx_v_i)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":140 - * return self.n - * - * def __getitem__(self, i): # <<<<<<<<<<<<<< - * return self.syms[i] - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_26__getitem__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - Py_ssize_t __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__getitem__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":141 - * - * def __getitem__(self, i): - * return self.syms[i] # <<<<<<<<<<<<<< - * - * def __iter__(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromLong((__pyx_v_self->syms[__pyx_t_1])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __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_2); - __Pyx_AddTraceback("_cdec_sa.Phrase.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_29__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_29__iter__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_28__iter__(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":143 - * return self.syms[i] - * - * def __iter__(self): # <<<<<<<<<<<<<< - * cdef int i - * l = [] - */ - -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_28__iter__(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self) { - int __pyx_v_i; - PyObject *__pyx_v_l = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__iter__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":145 - * def __iter__(self): - * cdef int i - * l = [] # <<<<<<<<<<<<<< - * for i from 0 <= i < self.n: - * l.append(self.syms[i]) - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_l = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":146 - * cdef int i - * l = [] - * for i from 0 <= i < self.n: # <<<<<<<<<<<<<< - * l.append(self.syms[i]) - * return iter(l) - */ - __pyx_t_2 = __pyx_v_self->n; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":147 - * l = [] - * for i from 0 <= i < self.n: - * l.append(self.syms[i]) # <<<<<<<<<<<<<< - * return iter(l) - * - */ - __pyx_t_1 = PyInt_FromLong((__pyx_v_self->syms[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyList_Append(__pyx_v_l, __pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":148 - * for i from 0 <= i < self.n: - * l.append(self.syms[i]) - * return iter(l) # <<<<<<<<<<<<<< - * - * def subst(self, start, children): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_l)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __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_AddTraceback("_cdec_sa.Phrase.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_l); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_31subst(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_6Phrase_31subst(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_start = 0; - PyObject *__pyx_v_children = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__children,0}; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("subst (wrapper)", 0); - { - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__children); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("subst", 1, 2, 2, 1); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "subst") < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_start = values[0]; - __pyx_v_children = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("subst", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.Phrase.subst", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_6Phrase_30subst(((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_self), __pyx_v_start, __pyx_v_children); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":150 - * return iter(l) - * - * def subst(self, start, children): # <<<<<<<<<<<<<< - * cdef int i - * for i from 0 <= i < self.n: - */ - -static PyObject *__pyx_pf_8_cdec_sa_6Phrase_30subst(struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_children) { - int __pyx_v_i; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - long __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("subst", 0); - __Pyx_INCREF(__pyx_v_start); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":152 - * def subst(self, start, children): - * cdef int i - * for i from 0 <= i < self.n: # <<<<<<<<<<<<<< - * if ALPHABET.isvar(self.syms[i]): - * start = start + children[ALPHABET.getindex(self.syms[i])-1] - */ - __pyx_t_1 = __pyx_v_self->n; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":153 - * cdef int i - * for i from 0 <= i < self.n: - * if ALPHABET.isvar(self.syms[i]): # <<<<<<<<<<<<<< - * start = start + children[ALPHABET.getindex(self.syms[i])-1] - * else: - */ - __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->isvar(__pyx_v_8_cdec_sa_ALPHABET, (__pyx_v_self->syms[__pyx_v_i])); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":154 - * for i from 0 <= i < self.n: - * if ALPHABET.isvar(self.syms[i]): - * start = start + children[ALPHABET.getindex(self.syms[i])-1] # <<<<<<<<<<<<<< - * else: - * start = start + (self.syms[i],) - */ - __pyx_t_3 = (((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->getindex(__pyx_v_8_cdec_sa_ALPHABET, (__pyx_v_self->syms[__pyx_v_i])) - 1); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_children, __pyx_t_3, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyNumber_Add(__pyx_v_start, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_v_start); - __pyx_v_start = __pyx_t_5; - __pyx_t_5 = 0; - goto __pyx_L5; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":156 - * start = start + children[ALPHABET.getindex(self.syms[i])-1] - * else: - * start = start + (self.syms[i],) # <<<<<<<<<<<<<< - * return start - * - */ - __pyx_t_5 = PyInt_FromLong((__pyx_v_self->syms[__pyx_v_i])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Add(__pyx_v_start, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_v_start); - __pyx_v_start = __pyx_t_5; - __pyx_t_5 = 0; - } - __pyx_L5:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":157 - * else: - * start = start + (self.syms[i],) - * return start # <<<<<<<<<<<<<< - * - * cdef class Rule: - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_start); - __pyx_r = __pyx_v_start; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("_cdec_sa.Phrase.subst", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_start); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_4Rule_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_4Rule_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_v_lhs; - struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_f = 0; - struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_e = 0; - PyObject *__pyx_v_scores = 0; - PyObject *__pyx_v_word_alignments = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__lhs,&__pyx_n_s__f,&__pyx_n_s__e,&__pyx_n_s__scores,&__pyx_n_s__word_alignments,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[5] = {0,0,0,0,0}; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":167 - * - * def __cinit__(self, int lhs, Phrase f, Phrase e, - * scores=None, word_alignments=None): # <<<<<<<<<<<<<< - * cdef int i, n - * cdef char *rest - */ - values[3] = ((PyObject *)Py_None); - values[4] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__lhs); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__f); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 1); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__e); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 2); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__scores); - if (value) { values[3] = value; kw_args--; } - } - case 4: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__word_alignments); - if (value) { values[4] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_lhs = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_lhs == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_f = ((struct __pyx_obj_8_cdec_sa_Phrase *)values[1]); - __pyx_v_e = ((struct __pyx_obj_8_cdec_sa_Phrase *)values[2]); - __pyx_v_scores = values[3]; - __pyx_v_word_alignments = values[4]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.Rule.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_f), __pyx_ptype_8_cdec_sa_Phrase, 1, "f", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_e), __pyx_ptype_8_cdec_sa_Phrase, 1, "e", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_8_cdec_sa_4Rule___cinit__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self), __pyx_v_lhs, __pyx_v_f, __pyx_v_e, __pyx_v_scores, __pyx_v_word_alignments); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":166 - * cdef public word_alignments - * - * def __cinit__(self, int lhs, Phrase f, Phrase e, # <<<<<<<<<<<<<< - * scores=None, word_alignments=None): - * cdef int i, n - */ - -static int __pyx_pf_8_cdec_sa_4Rule___cinit__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, int __pyx_v_lhs, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_f, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_e, PyObject *__pyx_v_scores, PyObject *__pyx_v_word_alignments) { - int __pyx_v_i; - int __pyx_v_n; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - Py_ssize_t __pyx_t_4; - int __pyx_t_5; - float __pyx_t_6; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":171 - * cdef char *rest - * - * if not ALPHABET.isvar(lhs): # <<<<<<<<<<<<<< - * raise Exception('Invalid LHS symbol: %d' % lhs) - * - */ - __pyx_t_1 = (!((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->isvar(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_lhs)); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":172 - * - * if not ALPHABET.isvar(lhs): - * raise Exception('Invalid LHS symbol: %d' % lhs) # <<<<<<<<<<<<<< - * - * self.lhs = lhs - */ - __pyx_t_2 = PyInt_FromLong(__pyx_v_lhs); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_65), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[7]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":174 - * raise Exception('Invalid LHS symbol: %d' % lhs) - * - * self.lhs = lhs # <<<<<<<<<<<<<< - * self.f = f - * self.e = e - */ - __pyx_v_self->lhs = __pyx_v_lhs; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":175 - * - * self.lhs = lhs - * self.f = f # <<<<<<<<<<<<<< - * self.e = e - * - */ - __Pyx_INCREF(((PyObject *)__pyx_v_f)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_f)); - __Pyx_GOTREF(__pyx_v_self->f); - __Pyx_DECREF(((PyObject *)__pyx_v_self->f)); - __pyx_v_self->f = __pyx_v_f; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":176 - * self.lhs = lhs - * self.f = f - * self.e = e # <<<<<<<<<<<<<< - * - * self.word_alignments = word_alignments - */ - __Pyx_INCREF(((PyObject *)__pyx_v_e)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_e)); - __Pyx_GOTREF(__pyx_v_self->e); - __Pyx_DECREF(((PyObject *)__pyx_v_self->e)); - __pyx_v_self->e = __pyx_v_e; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":178 - * self.e = e - * - * self.word_alignments = word_alignments # <<<<<<<<<<<<<< - * if scores is None: - * self.cscores = NULL - */ - __Pyx_INCREF(__pyx_v_word_alignments); - __Pyx_GIVEREF(__pyx_v_word_alignments); - __Pyx_GOTREF(__pyx_v_self->word_alignments); - __Pyx_DECREF(__pyx_v_self->word_alignments); - __pyx_v_self->word_alignments = __pyx_v_word_alignments; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":179 - * - * self.word_alignments = word_alignments - * if scores is None: # <<<<<<<<<<<<<< - * self.cscores = NULL - * self.n_scores = 0 - */ - __pyx_t_1 = (__pyx_v_scores == Py_None); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":180 - * self.word_alignments = word_alignments - * if scores is None: - * self.cscores = NULL # <<<<<<<<<<<<<< - * self.n_scores = 0 - * else: - */ - __pyx_v_self->cscores = NULL; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":181 - * if scores is None: - * self.cscores = NULL - * self.n_scores = 0 # <<<<<<<<<<<<<< - * else: - * n = len(scores) - */ - __pyx_v_self->n_scores = 0; - goto __pyx_L4; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":183 - * self.n_scores = 0 - * else: - * n = len(scores) # <<<<<<<<<<<<<< - * self.cscores = malloc(n*sizeof(float)) - * self.n_scores = n - */ - __pyx_t_4 = PyObject_Length(__pyx_v_scores); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_n = __pyx_t_4; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":184 - * else: - * n = len(scores) - * self.cscores = malloc(n*sizeof(float)) # <<<<<<<<<<<<<< - * self.n_scores = n - * for i from 0 <= i < n: - */ - __pyx_v_self->cscores = ((float *)malloc((__pyx_v_n * (sizeof(float))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":185 - * n = len(scores) - * self.cscores = malloc(n*sizeof(float)) - * self.n_scores = n # <<<<<<<<<<<<<< - * for i from 0 <= i < n: - * self.cscores[i] = scores[i] - */ - __pyx_v_self->n_scores = __pyx_v_n; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":186 - * self.cscores = malloc(n*sizeof(float)) - * self.n_scores = n - * for i from 0 <= i < n: # <<<<<<<<<<<<<< - * self.cscores[i] = scores[i] - * - */ - __pyx_t_5 = __pyx_v_n; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_5; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":187 - * self.n_scores = n - * for i from 0 <= i < n: - * self.cscores[i] = scores[i] # <<<<<<<<<<<<<< - * - * def __dealloc__(self): - */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_scores, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = __pyx_PyFloat_AsFloat(__pyx_t_3); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - (__pyx_v_self->cscores[__pyx_v_i]) = __pyx_t_6; - } - } - __pyx_L4:; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.Rule.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static void __pyx_pw_8_cdec_sa_4Rule_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_8_cdec_sa_4Rule_3__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_8_cdec_sa_4Rule_2__dealloc__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":189 - * self.cscores[i] = scores[i] - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * if self.cscores != NULL: - * free(self.cscores) - */ - -static void __pyx_pf_8_cdec_sa_4Rule_2__dealloc__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self) { - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":190 - * - * def __dealloc__(self): - * if self.cscores != NULL: # <<<<<<<<<<<<<< - * free(self.cscores) - * - */ - __pyx_t_1 = (__pyx_v_self->cscores != NULL); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":191 - * def __dealloc__(self): - * if self.cscores != NULL: - * free(self.cscores) # <<<<<<<<<<<<<< - * - * def __hash__(self): - */ - free(__pyx_v_self->cscores); - goto __pyx_L3; - } - __pyx_L3:; - - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static Py_hash_t __pyx_pw_8_cdec_sa_4Rule_5__hash__(PyObject *__pyx_v_self); /*proto*/ -static Py_hash_t __pyx_pw_8_cdec_sa_4Rule_5__hash__(PyObject *__pyx_v_self) { - Py_hash_t __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__hash__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_4Rule_4__hash__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":193 - * free(self.cscores) - * - * def __hash__(self): # <<<<<<<<<<<<<< - * return hash((self.lhs, self.f, self.e)) - * - */ - -static Py_hash_t __pyx_pf_8_cdec_sa_4Rule_4__hash__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self) { - Py_hash_t __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - Py_hash_t __pyx_t_3; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__hash__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":194 - * - * def __hash__(self): - * return hash((self.lhs, self.f, self.e)) # <<<<<<<<<<<<<< - * - * def __cmp__(self, Rule other): - */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->lhs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_self->f)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_self->f)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->f)); - __Pyx_INCREF(((PyObject *)__pyx_v_self->e)); - PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_self->e)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->e)); - __pyx_t_1 = 0; - __pyx_t_3 = PyObject_Hash(((PyObject *)__pyx_t_2)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - goto __pyx_L0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_cdec_sa.Rule.__hash__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -#if PY_MAJOR_VERSION < 3 -static int __pyx_pw_8_cdec_sa_4Rule_7__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static int __pyx_pw_8_cdec_sa_4Rule_7__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cmp__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_8_cdec_sa_Rule, 1, "other", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_8_cdec_sa_4Rule_6__cmp__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self), ((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_other)); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -#endif /*!(#if PY_MAJOR_VERSION < 3)*/ - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":196 - * return hash((self.lhs, self.f, self.e)) - * - * def __cmp__(self, Rule other): # <<<<<<<<<<<<<< - * return cmp((self.lhs, self.f, self.e, self.word_alignments), (other.lhs, other.f, other.e, self.word_alignments)) - * - */ - -#if PY_MAJOR_VERSION < 3 -static int __pyx_pf_8_cdec_sa_4Rule_6__cmp__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_other) { - int __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cmp__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":197 - * - * def __cmp__(self, Rule other): - * return cmp((self.lhs, self.f, self.e, self.word_alignments), (other.lhs, other.f, other.e, self.word_alignments)) # <<<<<<<<<<<<<< - * - * def __iadd__(self, Rule other): - */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->lhs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_self->f)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_self->f)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->f)); - __Pyx_INCREF(((PyObject *)__pyx_v_self->e)); - PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_self->e)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->e)); - __Pyx_INCREF(__pyx_v_self->word_alignments); - PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_self->word_alignments); - __Pyx_GIVEREF(__pyx_v_self->word_alignments); - __pyx_t_1 = 0; - __pyx_t_1 = PyInt_FromLong(__pyx_v_other->lhs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_other->f)); - PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_other->f)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_other->f)); - __Pyx_INCREF(((PyObject *)__pyx_v_other->e)); - PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_other->e)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_other->e)); - __Pyx_INCREF(__pyx_v_self->word_alignments); - PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_v_self->word_alignments); - __Pyx_GIVEREF(__pyx_v_self->word_alignments); - __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); - PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_t_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); - __pyx_t_2 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_cmp, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_r = __pyx_t_4; - goto __pyx_L0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.Rule.__cmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -#endif /*!(#if PY_MAJOR_VERSION < 3)*/ - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_4Rule_9__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_4Rule_9__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__iadd__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_8_cdec_sa_Rule, 1, "other", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_8_cdec_sa_4Rule_8__iadd__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self), ((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_other)); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":199 - * return cmp((self.lhs, self.f, self.e, self.word_alignments), (other.lhs, other.f, other.e, self.word_alignments)) - * - * def __iadd__(self, Rule other): # <<<<<<<<<<<<<< - * if self.n_scores != other.n_scores: - * raise ValueError - */ - -static PyObject *__pyx_pf_8_cdec_sa_4Rule_8__iadd__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_other) { - long __pyx_v_i; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__iadd__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":200 - * - * def __iadd__(self, Rule other): - * if self.n_scores != other.n_scores: # <<<<<<<<<<<<<< - * raise ValueError - * for i from 0 <= i < self.n_scores: - */ - __pyx_t_1 = (__pyx_v_self->n_scores != __pyx_v_other->n_scores); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":201 - * def __iadd__(self, Rule other): - * if self.n_scores != other.n_scores: - * raise ValueError # <<<<<<<<<<<<<< - * for i from 0 <= i < self.n_scores: - * self.cscores[i] = self.cscores[i] + other.cscores[i] - */ - __Pyx_Raise(__pyx_builtin_ValueError, 0, 0, 0); - {__pyx_filename = __pyx_f[7]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":202 - * if self.n_scores != other.n_scores: - * raise ValueError - * for i from 0 <= i < self.n_scores: # <<<<<<<<<<<<<< - * self.cscores[i] = self.cscores[i] + other.cscores[i] - * return self - */ - __pyx_t_2 = __pyx_v_self->n_scores; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":203 - * raise ValueError - * for i from 0 <= i < self.n_scores: - * self.cscores[i] = self.cscores[i] + other.cscores[i] # <<<<<<<<<<<<<< - * return self - * - */ - (__pyx_v_self->cscores[__pyx_v_i]) = ((__pyx_v_self->cscores[__pyx_v_i]) + (__pyx_v_other->cscores[__pyx_v_i])); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":204 - * for i from 0 <= i < self.n_scores: - * self.cscores[i] = self.cscores[i] + other.cscores[i] - * return self # <<<<<<<<<<<<<< - * - * def fmerge(self, Phrase f): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self)); - __pyx_r = ((PyObject *)__pyx_v_self); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec_sa.Rule.__iadd__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_4Rule_11fmerge(PyObject *__pyx_v_self, PyObject *__pyx_v_f); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_4Rule_11fmerge(PyObject *__pyx_v_self, PyObject *__pyx_v_f) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("fmerge (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_f), __pyx_ptype_8_cdec_sa_Phrase, 1, "f", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_8_cdec_sa_4Rule_10fmerge(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self), ((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_v_f)); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":206 - * return self - * - * def fmerge(self, Phrase f): # <<<<<<<<<<<<<< - * if self.f == f: - * self.f = f - */ - -static PyObject *__pyx_pf_8_cdec_sa_4Rule_10fmerge(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_f) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("fmerge", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":207 - * - * def fmerge(self, Phrase f): - * if self.f == f: # <<<<<<<<<<<<<< - * self.f = f - * - */ - __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_self->f), ((PyObject *)__pyx_v_f), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":208 - * def fmerge(self, Phrase f): - * if self.f == f: - * self.f = f # <<<<<<<<<<<<<< - * - * def arity(self): - */ - __Pyx_INCREF(((PyObject *)__pyx_v_f)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_f)); - __Pyx_GOTREF(__pyx_v_self->f); - __Pyx_DECREF(((PyObject *)__pyx_v_self->f)); - __pyx_v_self->f = __pyx_v_f; - goto __pyx_L3; - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec_sa.Rule.fmerge", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_4Rule_13arity(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_4Rule_13arity(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("arity (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_4Rule_12arity(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":210 - * self.f = f - * - * def arity(self): # <<<<<<<<<<<<<< - * return self.f.arity() - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_4Rule_12arity(struct __pyx_obj_8_cdec_sa_Rule *__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("arity", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":211 - * - * def arity(self): - * return self.f.arity() # <<<<<<<<<<<<<< - * - * def __str__(self): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->f), __pyx_n_s__arity); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 211; __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_sa.Rule.arity", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_4Rule_15__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_4Rule_15__str__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_4Rule_14__str__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":213 - * return self.f.arity() - * - * def __str__(self): # <<<<<<<<<<<<<< - * scorestrs = [] - * for i from 0 <= i < self.n_scores: - */ - -static PyObject *__pyx_pf_8_cdec_sa_4Rule_14__str__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self) { - PyObject *__pyx_v_scorestrs = NULL; - long __pyx_v_i; - PyObject *__pyx_v_fields = NULL; - PyObject *__pyx_v_alignstr = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - int __pyx_t_9; - Py_ssize_t __pyx_t_10; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__str__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":214 - * - * def __str__(self): - * scorestrs = [] # <<<<<<<<<<<<<< - * for i from 0 <= i < self.n_scores: - * scorestrs.append(str(self.cscores[i])) - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_scorestrs = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":215 - * def __str__(self): - * scorestrs = [] - * for i from 0 <= i < self.n_scores: # <<<<<<<<<<<<<< - * scorestrs.append(str(self.cscores[i])) - * fields = [ALPHABET.tostring(self.lhs), str(self.f), str(self.e), " ".join(scorestrs)] - */ - __pyx_t_2 = __pyx_v_self->n_scores; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":216 - * scorestrs = [] - * for i from 0 <= i < self.n_scores: - * scorestrs.append(str(self.cscores[i])) # <<<<<<<<<<<<<< - * fields = [ALPHABET.tostring(self.lhs), str(self.f), str(self.e), " ".join(scorestrs)] - * if self.word_alignments is not None: - */ - __pyx_t_1 = PyFloat_FromDouble((__pyx_v_self->cscores[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_4 = PyList_Append(__pyx_v_scorestrs, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":217 - * for i from 0 <= i < self.n_scores: - * scorestrs.append(str(self.cscores[i])) - * fields = [ALPHABET.tostring(self.lhs), str(self.f), str(self.e), " ".join(scorestrs)] # <<<<<<<<<<<<<< - * if self.word_alignments is not None: - * alignstr = [] - */ - __pyx_t_1 = PyBytes_FromString(((struct __pyx_vtabstruct_8_cdec_sa_Alphabet *)__pyx_v_8_cdec_sa_ALPHABET->__pyx_vtab)->tostring(__pyx_v_8_cdec_sa_ALPHABET, __pyx_v_self->lhs)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_v_self->f)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->f)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->f)); - __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_v_self->e)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->e)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->e)); - __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_64), __pyx_n_s__join); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(((PyObject *)__pyx_v_scorestrs)); - PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_scorestrs)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_scorestrs)); - __pyx_t_8 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; - __pyx_t_7 = PyList_New(4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - PyList_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - PyList_SET_ITEM(__pyx_t_7, 1, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - PyList_SET_ITEM(__pyx_t_7, 2, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_6); - PyList_SET_ITEM(__pyx_t_7, 3, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - __pyx_t_1 = 0; - __pyx_t_5 = 0; - __pyx_t_6 = 0; - __pyx_t_8 = 0; - __pyx_v_fields = __pyx_t_7; - __pyx_t_7 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":218 - * scorestrs.append(str(self.cscores[i])) - * fields = [ALPHABET.tostring(self.lhs), str(self.f), str(self.e), " ".join(scorestrs)] - * if self.word_alignments is not None: # <<<<<<<<<<<<<< - * alignstr = [] - * for i from 0 <= i < len(self.word_alignments): - */ - __pyx_t_9 = (__pyx_v_self->word_alignments != Py_None); - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":219 - * fields = [ALPHABET.tostring(self.lhs), str(self.f), str(self.e), " ".join(scorestrs)] - * if self.word_alignments is not None: - * alignstr = [] # <<<<<<<<<<<<<< - * for i from 0 <= i < len(self.word_alignments): - * alignstr.append("%d-%d" % (self.word_alignments[i]/65536, self.word_alignments[i]%65536)) - */ - __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_v_alignstr = __pyx_t_7; - __pyx_t_7 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":220 - * if self.word_alignments is not None: - * alignstr = [] - * for i from 0 <= i < len(self.word_alignments): # <<<<<<<<<<<<<< - * alignstr.append("%d-%d" % (self.word_alignments[i]/65536, self.word_alignments[i]%65536)) - * #for s,t in self.word_alignments: - */ - __pyx_t_7 = __pyx_v_self->word_alignments; - __Pyx_INCREF(__pyx_t_7); - __pyx_t_10 = PyObject_Length(__pyx_t_7); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_10; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":221 - * alignstr = [] - * for i from 0 <= i < len(self.word_alignments): - * alignstr.append("%d-%d" % (self.word_alignments[i]/65536, self.word_alignments[i]%65536)) # <<<<<<<<<<<<<< - * #for s,t in self.word_alignments: - * #alignstr.append("%d-%d" % (s,t)) - */ - __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_self->word_alignments, __pyx_v_i, sizeof(long), PyInt_FromLong); if (!__pyx_t_7) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyNumber_Divide(__pyx_t_7, __pyx_int_65536); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_self->word_alignments, __pyx_v_i, sizeof(long), PyInt_FromLong); if (!__pyx_t_7) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = PyNumber_Remainder(__pyx_t_7, __pyx_int_65536); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_6); - __pyx_t_8 = 0; - __pyx_t_6 = 0; - __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_66), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_6)); - __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; - __pyx_t_4 = PyList_Append(__pyx_v_alignstr, ((PyObject *)__pyx_t_6)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":224 - * #for s,t in self.word_alignments: - * #alignstr.append("%d-%d" % (s,t)) - * fields.append(" ".join(alignstr)) # <<<<<<<<<<<<<< - * - * return " ||| ".join(fields) - */ - __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_64), __pyx_n_s__join); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(((PyObject *)__pyx_v_alignstr)); - PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_alignstr)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_alignstr)); - __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; - __pyx_t_4 = PyList_Append(__pyx_v_fields, __pyx_t_8); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":226 - * fields.append(" ".join(alignstr)) - * - * return " ||| ".join(fields) # <<<<<<<<<<<<<< - * - * property scores: - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_67), __pyx_n_s__join); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(((PyObject *)__pyx_v_fields)); - PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_fields)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_fields)); - __pyx_t_6 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; - __pyx_r = __pyx_t_6; - __pyx_t_6 = 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_3); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("_cdec_sa.Rule.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_scorestrs); - __Pyx_XDECREF(__pyx_v_fields); - __Pyx_XDECREF(__pyx_v_alignstr); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_4Rule_6scores_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_4Rule_6scores_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_4Rule_6scores___get__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":229 - * - * property scores: - * def __get__(self): # <<<<<<<<<<<<<< - * s = [None]*self.n_scores - * for i from 0 <= i < self.n_scores: - */ - -static PyObject *__pyx_pf_8_cdec_sa_4Rule_6scores___get__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self) { - PyObject *__pyx_v_s = NULL; - long __pyx_v_i; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":230 - * property scores: - * def __get__(self): - * s = [None]*self.n_scores # <<<<<<<<<<<<<< - * for i from 0 <= i < self.n_scores: - * s[i] = self.cscores[i] - */ - __pyx_t_1 = PyList_New(1 * ((__pyx_v_self->n_scores<0) ? 0:__pyx_v_self->n_scores)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - { Py_ssize_t __pyx_temp; - for (__pyx_temp=0; __pyx_temp < __pyx_v_self->n_scores; __pyx_temp++) { - __Pyx_INCREF(Py_None); - PyList_SET_ITEM(__pyx_t_1, __pyx_temp, Py_None); - __Pyx_GIVEREF(Py_None); - } - } - __pyx_v_s = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":231 - * def __get__(self): - * s = [None]*self.n_scores - * for i from 0 <= i < self.n_scores: # <<<<<<<<<<<<<< - * s[i] = self.cscores[i] - * return s - */ - __pyx_t_2 = __pyx_v_self->n_scores; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":232 - * s = [None]*self.n_scores - * for i from 0 <= i < self.n_scores: - * s[i] = self.cscores[i] # <<<<<<<<<<<<<< - * return s - * - */ - __pyx_t_1 = PyFloat_FromDouble((__pyx_v_self->cscores[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_SetItemInt(((PyObject *)__pyx_v_s), __pyx_v_i, __pyx_t_1, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":233 - * for i from 0 <= i < self.n_scores: - * s[i] = self.cscores[i] - * return s # <<<<<<<<<<<<<< - * - * def __set__(self, s): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_s)); - __pyx_r = ((PyObject *)__pyx_v_s); - 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_sa.Rule.scores.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_s); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_4Rule_6scores_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_s); /*proto*/ -static int __pyx_pw_8_cdec_sa_4Rule_6scores_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_s) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_4Rule_6scores_2__set__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self), ((PyObject *)__pyx_v_s)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":235 - * return s - * - * def __set__(self, s): # <<<<<<<<<<<<<< - * if self.cscores != NULL: - * free(self.cscores) - */ - -static int __pyx_pf_8_cdec_sa_4Rule_6scores_2__set__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, PyObject *__pyx_v_s) { - long __pyx_v_i; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - Py_ssize_t __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - float __pyx_t_5; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__set__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":236 - * - * def __set__(self, s): - * if self.cscores != NULL: # <<<<<<<<<<<<<< - * free(self.cscores) - * self.cscores = malloc(len(s)*sizeof(float)) - */ - __pyx_t_1 = (__pyx_v_self->cscores != NULL); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":237 - * def __set__(self, s): - * if self.cscores != NULL: - * free(self.cscores) # <<<<<<<<<<<<<< - * self.cscores = malloc(len(s)*sizeof(float)) - * self.n_scores = len(s) - */ - free(__pyx_v_self->cscores); - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":238 - * if self.cscores != NULL: - * free(self.cscores) - * self.cscores = malloc(len(s)*sizeof(float)) # <<<<<<<<<<<<<< - * self.n_scores = len(s) - * for i from 0 <= i < self.n_scores: - */ - __pyx_t_2 = PyObject_Length(__pyx_v_s); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->cscores = ((float *)malloc((__pyx_t_2 * (sizeof(float))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":239 - * free(self.cscores) - * self.cscores = malloc(len(s)*sizeof(float)) - * self.n_scores = len(s) # <<<<<<<<<<<<<< - * for i from 0 <= i < self.n_scores: - * self.cscores[i] = s[i] - */ - __pyx_t_2 = PyObject_Length(__pyx_v_s); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->n_scores = __pyx_t_2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":240 - * self.cscores = malloc(len(s)*sizeof(float)) - * self.n_scores = len(s) - * for i from 0 <= i < self.n_scores: # <<<<<<<<<<<<<< - * self.cscores[i] = s[i] - */ - __pyx_t_3 = __pyx_v_self->n_scores; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":241 - * self.n_scores = len(s) - * for i from 0 <= i < self.n_scores: - * self.cscores[i] = s[i] # <<<<<<<<<<<<<< - */ - __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_s, __pyx_v_i, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __pyx_PyFloat_AsFloat(__pyx_t_4); if (unlikely((__pyx_t_5 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - (__pyx_v_self->cscores[__pyx_v_i]) = __pyx_t_5; - } - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec_sa.Rule.scores.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_4Rule_3lhs_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_4Rule_3lhs_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_4Rule_3lhs___get__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":160 - * - * cdef class Rule: - * cdef public int lhs # <<<<<<<<<<<<<< - * cdef readonly Phrase f, e - * cdef float *cscores - */ - -static PyObject *__pyx_pf_8_cdec_sa_4Rule_3lhs___get__(struct __pyx_obj_8_cdec_sa_Rule *__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("__get__", 0); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->lhs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __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_AddTraceback("_cdec_sa.Rule.lhs.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_4Rule_3lhs_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_8_cdec_sa_4Rule_3lhs_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_4Rule_3lhs_2__set__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self), ((PyObject *)__pyx_v_value)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_4Rule_3lhs_2__set__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__set__", 0); - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->lhs = __pyx_t_1; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec_sa.Rule.lhs.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_4Rule_1f_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_4Rule_1f_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_4Rule_1f___get__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":161 - * cdef class Rule: - * cdef public int lhs - * cdef readonly Phrase f, e # <<<<<<<<<<<<<< - * cdef float *cscores - * cdef int n_scores - */ - -static PyObject *__pyx_pf_8_cdec_sa_4Rule_1f___get__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self->f)); - __pyx_r = ((PyObject *)__pyx_v_self->f); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_4Rule_1e_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_4Rule_1e_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_4Rule_1e___get__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8_cdec_sa_4Rule_1e___get__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self->e)); - __pyx_r = ((PyObject *)__pyx_v_self->e); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_4Rule_15word_alignments_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_4Rule_15word_alignments_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_4Rule_15word_alignments___get__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":164 - * cdef float *cscores - * cdef int n_scores - * cdef public word_alignments # <<<<<<<<<<<<<< - * - * def __cinit__(self, int lhs, Phrase f, Phrase e, - */ - -static PyObject *__pyx_pf_8_cdec_sa_4Rule_15word_alignments___get__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->word_alignments); - __pyx_r = __pyx_v_self->word_alignments; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_4Rule_15word_alignments_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_8_cdec_sa_4Rule_15word_alignments_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_4Rule_15word_alignments_2__set__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self), ((PyObject *)__pyx_v_value)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_4Rule_15word_alignments_2__set__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(__pyx_v_self->word_alignments); - __Pyx_DECREF(__pyx_v_self->word_alignments); - __pyx_v_self->word_alignments = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_4Rule_15word_alignments_5__del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pw_8_cdec_sa_4Rule_15word_alignments_5__del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_4Rule_15word_alignments_4__del__(((struct __pyx_obj_8_cdec_sa_Rule *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_4Rule_15word_alignments_4__del__(struct __pyx_obj_8_cdec_sa_Rule *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__", 0); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->word_alignments); - __Pyx_DECREF(__pyx_v_self->word_alignments); - __pyx_v_self->word_alignments = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":21 - * int arr_len - * - * cdef _Trie_Node* new_trie_node(): # <<<<<<<<<<<<<< - * cdef _Trie_Node* node - * node = <_Trie_Node*> malloc(sizeof(_Trie_Node)) - */ - -static struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_f_8_cdec_sa_new_trie_node(void) { - struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node; - struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("new_trie_node", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":23 - * cdef _Trie_Node* new_trie_node(): - * cdef _Trie_Node* node - * node = <_Trie_Node*> malloc(sizeof(_Trie_Node)) # <<<<<<<<<<<<<< - * node.root = NULL - * node.arr_len = 0 - */ - __pyx_v_node = ((struct __pyx_t_8_cdec_sa__Trie_Node *)malloc((sizeof(struct __pyx_t_8_cdec_sa__Trie_Node)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":24 - * cdef _Trie_Node* node - * node = <_Trie_Node*> malloc(sizeof(_Trie_Node)) - * node.root = NULL # <<<<<<<<<<<<<< - * node.arr_len = 0 - * node.arr = malloc(sizeof(0*sizeof(int))) - */ - __pyx_v_node->root = NULL; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":25 - * node = <_Trie_Node*> malloc(sizeof(_Trie_Node)) - * node.root = NULL - * node.arr_len = 0 # <<<<<<<<<<<<<< - * node.arr = malloc(sizeof(0*sizeof(int))) - * return node - */ - __pyx_v_node->arr_len = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":26 - * node.root = NULL - * node.arr_len = 0 - * node.arr = malloc(sizeof(0*sizeof(int))) # <<<<<<<<<<<<<< - * return node - * - */ - __pyx_v_node->arr = ((int *)malloc((sizeof((0 * (sizeof(int))))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":27 - * node.arr_len = 0 - * node.arr = malloc(sizeof(0*sizeof(int))) - * return node # <<<<<<<<<<<<<< - * - * cdef _Trie_Edge* new_trie_edge(int val): - */ - __pyx_r = __pyx_v_node; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":29 - * return node - * - * cdef _Trie_Edge* new_trie_edge(int val): # <<<<<<<<<<<<<< - * cdef _Trie_Edge* edge - * edge = <_Trie_Edge*> malloc(sizeof(_Trie_Edge)) - */ - -static struct __pyx_t_8_cdec_sa__Trie_Edge *__pyx_f_8_cdec_sa_new_trie_edge(int __pyx_v_val) { - struct __pyx_t_8_cdec_sa__Trie_Edge *__pyx_v_edge; - struct __pyx_t_8_cdec_sa__Trie_Edge *__pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("new_trie_edge", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":31 - * cdef _Trie_Edge* new_trie_edge(int val): - * cdef _Trie_Edge* edge - * edge = <_Trie_Edge*> malloc(sizeof(_Trie_Edge)) # <<<<<<<<<<<<<< - * edge.node = new_trie_node() - * edge.bigger = NULL - */ - __pyx_v_edge = ((struct __pyx_t_8_cdec_sa__Trie_Edge *)malloc((sizeof(struct __pyx_t_8_cdec_sa__Trie_Edge)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":32 - * cdef _Trie_Edge* edge - * edge = <_Trie_Edge*> malloc(sizeof(_Trie_Edge)) - * edge.node = new_trie_node() # <<<<<<<<<<<<<< - * edge.bigger = NULL - * edge.smaller = NULL - */ - __pyx_v_edge->node = __pyx_f_8_cdec_sa_new_trie_node(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":33 - * edge = <_Trie_Edge*> malloc(sizeof(_Trie_Edge)) - * edge.node = new_trie_node() - * edge.bigger = NULL # <<<<<<<<<<<<<< - * edge.smaller = NULL - * edge.val = val - */ - __pyx_v_edge->bigger = NULL; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":34 - * edge.node = new_trie_node() - * edge.bigger = NULL - * edge.smaller = NULL # <<<<<<<<<<<<<< - * edge.val = val - * return edge - */ - __pyx_v_edge->smaller = NULL; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":35 - * edge.bigger = NULL - * edge.smaller = NULL - * edge.val = val # <<<<<<<<<<<<<< - * return edge - * - */ - __pyx_v_edge->val = __pyx_v_val; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":36 - * edge.smaller = NULL - * edge.val = val - * return edge # <<<<<<<<<<<<<< - * - * cdef free_trie_node(_Trie_Node* node): - */ - __pyx_r = __pyx_v_edge; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":38 - * return edge - * - * cdef free_trie_node(_Trie_Node* node): # <<<<<<<<<<<<<< - * if node != NULL: - * free_trie_edge(node.root) - */ - -static PyObject *__pyx_f_8_cdec_sa_free_trie_node(struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("free_trie_node", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":39 - * - * cdef free_trie_node(_Trie_Node* node): - * if node != NULL: # <<<<<<<<<<<<<< - * free_trie_edge(node.root) - * free(node.arr) - */ - __pyx_t_1 = (__pyx_v_node != NULL); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":40 - * cdef free_trie_node(_Trie_Node* node): - * if node != NULL: - * free_trie_edge(node.root) # <<<<<<<<<<<<<< - * free(node.arr) - * - */ - __pyx_t_2 = __pyx_f_8_cdec_sa_free_trie_edge(__pyx_v_node->root); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":41 - * if node != NULL: - * free_trie_edge(node.root) - * free(node.arr) # <<<<<<<<<<<<<< - * - * cdef free_trie_edge(_Trie_Edge* edge): - */ - free(__pyx_v_node->arr); - goto __pyx_L3; - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_cdec_sa.free_trie_node", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":43 - * free(node.arr) - * - * cdef free_trie_edge(_Trie_Edge* edge): # <<<<<<<<<<<<<< - * if edge != NULL: - * free_trie_node(edge.node) - */ - -static PyObject *__pyx_f_8_cdec_sa_free_trie_edge(struct __pyx_t_8_cdec_sa__Trie_Edge *__pyx_v_edge) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("free_trie_edge", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":44 - * - * cdef free_trie_edge(_Trie_Edge* edge): - * if edge != NULL: # <<<<<<<<<<<<<< - * free_trie_node(edge.node) - * free_trie_edge(edge.bigger) - */ - __pyx_t_1 = (__pyx_v_edge != NULL); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":45 - * cdef free_trie_edge(_Trie_Edge* edge): - * if edge != NULL: - * free_trie_node(edge.node) # <<<<<<<<<<<<<< - * free_trie_edge(edge.bigger) - * free_trie_edge(edge.smaller) - */ - __pyx_t_2 = __pyx_f_8_cdec_sa_free_trie_node(__pyx_v_edge->node); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":46 - * if edge != NULL: - * free_trie_node(edge.node) - * free_trie_edge(edge.bigger) # <<<<<<<<<<<<<< - * free_trie_edge(edge.smaller) - * - */ - __pyx_t_2 = __pyx_f_8_cdec_sa_free_trie_edge(__pyx_v_edge->bigger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":47 - * free_trie_node(edge.node) - * free_trie_edge(edge.bigger) - * free_trie_edge(edge.smaller) # <<<<<<<<<<<<<< - * - * cdef _Trie_Node* trie_find(_Trie_Node* node, int val): - */ - __pyx_t_2 = __pyx_f_8_cdec_sa_free_trie_edge(__pyx_v_edge->smaller); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L3; - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_cdec_sa.free_trie_edge", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":49 - * free_trie_edge(edge.smaller) - * - * cdef _Trie_Node* trie_find(_Trie_Node* node, int val): # <<<<<<<<<<<<<< - * cdef _Trie_Edge* cur - * cur = node.root - */ - -static struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_f_8_cdec_sa_trie_find(struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node, int __pyx_v_val) { - struct __pyx_t_8_cdec_sa__Trie_Edge *__pyx_v_cur; - struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("trie_find", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":51 - * cdef _Trie_Node* trie_find(_Trie_Node* node, int val): - * cdef _Trie_Edge* cur - * cur = node.root # <<<<<<<<<<<<<< - * while cur != NULL and cur.val != val: - * if val > cur.val: - */ - __pyx_v_cur = __pyx_v_node->root; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":52 - * cdef _Trie_Edge* cur - * cur = node.root - * while cur != NULL and cur.val != val: # <<<<<<<<<<<<<< - * if val > cur.val: - * cur = cur.bigger - */ - while (1) { - __pyx_t_1 = (__pyx_v_cur != NULL); - if (__pyx_t_1) { - __pyx_t_2 = (__pyx_v_cur->val != __pyx_v_val); - __pyx_t_3 = __pyx_t_2; - } else { - __pyx_t_3 = __pyx_t_1; - } - if (!__pyx_t_3) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":53 - * cur = node.root - * while cur != NULL and cur.val != val: - * if val > cur.val: # <<<<<<<<<<<<<< - * cur = cur.bigger - * elif val < cur.val: - */ - __pyx_t_3 = (__pyx_v_val > __pyx_v_cur->val); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":54 - * while cur != NULL and cur.val != val: - * if val > cur.val: - * cur = cur.bigger # <<<<<<<<<<<<<< - * elif val < cur.val: - * cur = cur.smaller - */ - __pyx_v_cur = __pyx_v_cur->bigger; - goto __pyx_L5; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":55 - * if val > cur.val: - * cur = cur.bigger - * elif val < cur.val: # <<<<<<<<<<<<<< - * cur = cur.smaller - * if cur == NULL: - */ - __pyx_t_3 = (__pyx_v_val < __pyx_v_cur->val); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":56 - * cur = cur.bigger - * elif val < cur.val: - * cur = cur.smaller # <<<<<<<<<<<<<< - * if cur == NULL: - * return NULL - */ - __pyx_v_cur = __pyx_v_cur->smaller; - goto __pyx_L5; - } - __pyx_L5:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":57 - * elif val < cur.val: - * cur = cur.smaller - * if cur == NULL: # <<<<<<<<<<<<<< - * return NULL - * else: - */ - __pyx_t_3 = (__pyx_v_cur == NULL); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":58 - * cur = cur.smaller - * if cur == NULL: - * return NULL # <<<<<<<<<<<<<< - * else: - * return cur.node - */ - __pyx_r = NULL; - goto __pyx_L0; - goto __pyx_L6; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":60 - * return NULL - * else: - * return cur.node # <<<<<<<<<<<<<< - * - * cdef trie_node_data_append(_Trie_Node* node, int val): - */ - __pyx_r = __pyx_v_cur->node; - goto __pyx_L0; - } - __pyx_L6:; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":62 - * return cur.node - * - * cdef trie_node_data_append(_Trie_Node* node, int val): # <<<<<<<<<<<<<< - * cdef int new_len - * new_len = node.arr_len + 1 - */ - -static PyObject *__pyx_f_8_cdec_sa_trie_node_data_append(struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node, int __pyx_v_val) { - int __pyx_v_new_len; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("trie_node_data_append", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":64 - * cdef trie_node_data_append(_Trie_Node* node, int val): - * cdef int new_len - * new_len = node.arr_len + 1 # <<<<<<<<<<<<<< - * node.arr = realloc(node.arr, new_len*sizeof(int)) - * node.arr[node.arr_len] = val - */ - __pyx_v_new_len = (__pyx_v_node->arr_len + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":65 - * cdef int new_len - * new_len = node.arr_len + 1 - * node.arr = realloc(node.arr, new_len*sizeof(int)) # <<<<<<<<<<<<<< - * node.arr[node.arr_len] = val - * node.arr_len = new_len - */ - __pyx_v_node->arr = ((int *)realloc(__pyx_v_node->arr, (__pyx_v_new_len * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":66 - * new_len = node.arr_len + 1 - * node.arr = realloc(node.arr, new_len*sizeof(int)) - * node.arr[node.arr_len] = val # <<<<<<<<<<<<<< - * node.arr_len = new_len - * - */ - (__pyx_v_node->arr[__pyx_v_node->arr_len]) = __pyx_v_val; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":67 - * node.arr = realloc(node.arr, new_len*sizeof(int)) - * node.arr[node.arr_len] = val - * node.arr_len = new_len # <<<<<<<<<<<<<< - * - * cdef trie_node_data_extend(_Trie_Node* node, int* vals, int num_vals): - */ - __pyx_v_node->arr_len = __pyx_v_new_len; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":69 - * node.arr_len = new_len - * - * cdef trie_node_data_extend(_Trie_Node* node, int* vals, int num_vals): # <<<<<<<<<<<<<< - * cdef int new_len - * new_len = node.arr_len + num_vals - */ - -static PyObject *__pyx_f_8_cdec_sa_trie_node_data_extend(struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node, int *__pyx_v_vals, int __pyx_v_num_vals) { - int __pyx_v_new_len; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("trie_node_data_extend", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":71 - * cdef trie_node_data_extend(_Trie_Node* node, int* vals, int num_vals): - * cdef int new_len - * new_len = node.arr_len + num_vals # <<<<<<<<<<<<<< - * node.arr = realloc(node.arr, new_len*sizeof(int)) - * memcpy(node.arr + node.arr_len, vals, num_vals*sizeof(int)) - */ - __pyx_v_new_len = (__pyx_v_node->arr_len + __pyx_v_num_vals); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":72 - * cdef int new_len - * new_len = node.arr_len + num_vals - * node.arr = realloc(node.arr, new_len*sizeof(int)) # <<<<<<<<<<<<<< - * memcpy(node.arr + node.arr_len, vals, num_vals*sizeof(int)) - * node.arr_len = new_len - */ - __pyx_v_node->arr = ((int *)realloc(__pyx_v_node->arr, (__pyx_v_new_len * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":73 - * new_len = node.arr_len + num_vals - * node.arr = realloc(node.arr, new_len*sizeof(int)) - * memcpy(node.arr + node.arr_len, vals, num_vals*sizeof(int)) # <<<<<<<<<<<<<< - * node.arr_len = new_len - * - */ - memcpy((__pyx_v_node->arr + __pyx_v_node->arr_len), __pyx_v_vals, (__pyx_v_num_vals * (sizeof(int)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":74 - * node.arr = realloc(node.arr, new_len*sizeof(int)) - * memcpy(node.arr + node.arr_len, vals, num_vals*sizeof(int)) - * node.arr_len = new_len # <<<<<<<<<<<<<< - * - * - */ - __pyx_v_node->arr_len = __pyx_v_new_len; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":77 - * - * - * cdef _Trie_Node* trie_insert(_Trie_Node* node, int val): # <<<<<<<<<<<<<< - * cdef _Trie_Edge** cur - * cur = &node.root - */ - -static struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_f_8_cdec_sa_trie_insert(struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node, int __pyx_v_val) { - struct __pyx_t_8_cdec_sa__Trie_Edge **__pyx_v_cur; - struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("trie_insert", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":79 - * cdef _Trie_Node* trie_insert(_Trie_Node* node, int val): - * cdef _Trie_Edge** cur - * cur = &node.root # <<<<<<<<<<<<<< - * while cur[0] != NULL and cur[0].val != val: - * if val > cur[0].val: - */ - __pyx_v_cur = (&__pyx_v_node->root); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":80 - * cdef _Trie_Edge** cur - * cur = &node.root - * while cur[0] != NULL and cur[0].val != val: # <<<<<<<<<<<<<< - * if val > cur[0].val: - * cur = &cur[0].bigger - */ - while (1) { - __pyx_t_1 = ((__pyx_v_cur[0]) != NULL); - if (__pyx_t_1) { - __pyx_t_2 = ((__pyx_v_cur[0])->val != __pyx_v_val); - __pyx_t_3 = __pyx_t_2; - } else { - __pyx_t_3 = __pyx_t_1; - } - if (!__pyx_t_3) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":81 - * cur = &node.root - * while cur[0] != NULL and cur[0].val != val: - * if val > cur[0].val: # <<<<<<<<<<<<<< - * cur = &cur[0].bigger - * elif val < cur[0].val: - */ - __pyx_t_3 = (__pyx_v_val > (__pyx_v_cur[0])->val); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":82 - * while cur[0] != NULL and cur[0].val != val: - * if val > cur[0].val: - * cur = &cur[0].bigger # <<<<<<<<<<<<<< - * elif val < cur[0].val: - * cur = &cur[0].smaller - */ - __pyx_v_cur = (&(__pyx_v_cur[0])->bigger); - goto __pyx_L5; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":83 - * if val > cur[0].val: - * cur = &cur[0].bigger - * elif val < cur[0].val: # <<<<<<<<<<<<<< - * cur = &cur[0].smaller - * if cur[0] == NULL: - */ - __pyx_t_3 = (__pyx_v_val < (__pyx_v_cur[0])->val); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":84 - * cur = &cur[0].bigger - * elif val < cur[0].val: - * cur = &cur[0].smaller # <<<<<<<<<<<<<< - * if cur[0] == NULL: - * cur[0] = new_trie_edge(val) - */ - __pyx_v_cur = (&(__pyx_v_cur[0])->smaller); - goto __pyx_L5; - } - __pyx_L5:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":85 - * elif val < cur[0].val: - * cur = &cur[0].smaller - * if cur[0] == NULL: # <<<<<<<<<<<<<< - * cur[0] = new_trie_edge(val) - * return cur[0].node - */ - __pyx_t_3 = ((__pyx_v_cur[0]) == NULL); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":86 - * cur = &cur[0].smaller - * if cur[0] == NULL: - * cur[0] = new_trie_edge(val) # <<<<<<<<<<<<<< - * return cur[0].node - * - */ - (__pyx_v_cur[0]) = __pyx_f_8_cdec_sa_new_trie_edge(__pyx_v_val); - goto __pyx_L6; - } - __pyx_L6:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":87 - * if cur[0] == NULL: - * cur[0] = new_trie_edge(val) - * return cur[0].node # <<<<<<<<<<<<<< - * - * cdef trie_node_to_map(_Trie_Node* node, result, prefix, int include_zeros): - */ - __pyx_r = (__pyx_v_cur[0])->node; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":89 - * return cur[0].node - * - * cdef trie_node_to_map(_Trie_Node* node, result, prefix, int include_zeros): # <<<<<<<<<<<<<< - * cdef IntList arr - * - */ - -static PyObject *__pyx_f_8_cdec_sa_trie_node_to_map(struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node, PyObject *__pyx_v_result, PyObject *__pyx_v_prefix, int __pyx_v_include_zeros) { - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_arr = 0; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("trie_node_to_map", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":92 - * cdef IntList arr - * - * if include_zeros or node.arr_len > 0: # <<<<<<<<<<<<<< - * arr = IntList() - * free(arr.arr) - */ - if (!__pyx_v_include_zeros) { - __pyx_t_1 = (__pyx_v_node->arr_len > 0); - __pyx_t_2 = __pyx_t_1; - } else { - __pyx_t_2 = __pyx_v_include_zeros; - } - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":93 - * - * if include_zeros or node.arr_len > 0: - * arr = IntList() # <<<<<<<<<<<<<< - * free(arr.arr) - * arr.arr = malloc(node.arr_len * sizeof(int)) - */ - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_arr = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":94 - * if include_zeros or node.arr_len > 0: - * arr = IntList() - * free(arr.arr) # <<<<<<<<<<<<<< - * arr.arr = malloc(node.arr_len * sizeof(int)) - * memcpy(arr.arr, node.arr, node.arr_len * sizeof(int)) - */ - free(__pyx_v_arr->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":95 - * arr = IntList() - * free(arr.arr) - * arr.arr = malloc(node.arr_len * sizeof(int)) # <<<<<<<<<<<<<< - * memcpy(arr.arr, node.arr, node.arr_len * sizeof(int)) - * arr.len = node.arr_len - */ - __pyx_v_arr->arr = ((int *)malloc((__pyx_v_node->arr_len * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":96 - * free(arr.arr) - * arr.arr = malloc(node.arr_len * sizeof(int)) - * memcpy(arr.arr, node.arr, node.arr_len * sizeof(int)) # <<<<<<<<<<<<<< - * arr.len = node.arr_len - * arr.size = node.arr_len - */ - memcpy(__pyx_v_arr->arr, __pyx_v_node->arr, (__pyx_v_node->arr_len * (sizeof(int)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":97 - * arr.arr = malloc(node.arr_len * sizeof(int)) - * memcpy(arr.arr, node.arr, node.arr_len * sizeof(int)) - * arr.len = node.arr_len # <<<<<<<<<<<<<< - * arr.size = node.arr_len - * result[prefix] = arr - */ - __pyx_v_arr->len = __pyx_v_node->arr_len; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":98 - * memcpy(arr.arr, node.arr, node.arr_len * sizeof(int)) - * arr.len = node.arr_len - * arr.size = node.arr_len # <<<<<<<<<<<<<< - * result[prefix] = arr - * trie_edge_to_map(node.root, result, prefix, include_zeros) - */ - __pyx_v_arr->size = __pyx_v_node->arr_len; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":99 - * arr.len = node.arr_len - * arr.size = node.arr_len - * result[prefix] = arr # <<<<<<<<<<<<<< - * trie_edge_to_map(node.root, result, prefix, include_zeros) - * - */ - if (PyObject_SetItem(__pyx_v_result, __pyx_v_prefix, ((PyObject *)__pyx_v_arr)) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":100 - * arr.size = node.arr_len - * result[prefix] = arr - * trie_edge_to_map(node.root, result, prefix, include_zeros) # <<<<<<<<<<<<<< - * - * cdef trie_edge_to_map(_Trie_Edge* edge, result, prefix, int include_zeros): - */ - __pyx_t_3 = __pyx_f_8_cdec_sa_trie_edge_to_map(__pyx_v_node->root, __pyx_v_result, __pyx_v_prefix, __pyx_v_include_zeros); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.trie_node_to_map", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_arr); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":102 - * trie_edge_to_map(node.root, result, prefix, include_zeros) - * - * cdef trie_edge_to_map(_Trie_Edge* edge, result, prefix, int include_zeros): # <<<<<<<<<<<<<< - * if edge != NULL: - * trie_edge_to_map(edge.smaller, result, prefix, include_zeros) - */ - -static PyObject *__pyx_f_8_cdec_sa_trie_edge_to_map(struct __pyx_t_8_cdec_sa__Trie_Edge *__pyx_v_edge, PyObject *__pyx_v_result, PyObject *__pyx_v_prefix, int __pyx_v_include_zeros) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("trie_edge_to_map", 0); - __Pyx_INCREF(__pyx_v_prefix); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":103 - * - * cdef trie_edge_to_map(_Trie_Edge* edge, result, prefix, int include_zeros): - * if edge != NULL: # <<<<<<<<<<<<<< - * trie_edge_to_map(edge.smaller, result, prefix, include_zeros) - * trie_edge_to_map(edge.bigger, result, prefix, include_zeros) - */ - __pyx_t_1 = (__pyx_v_edge != NULL); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":104 - * cdef trie_edge_to_map(_Trie_Edge* edge, result, prefix, int include_zeros): - * if edge != NULL: - * trie_edge_to_map(edge.smaller, result, prefix, include_zeros) # <<<<<<<<<<<<<< - * trie_edge_to_map(edge.bigger, result, prefix, include_zeros) - * prefix = prefix + (edge.val,) - */ - __pyx_t_2 = __pyx_f_8_cdec_sa_trie_edge_to_map(__pyx_v_edge->smaller, __pyx_v_result, __pyx_v_prefix, __pyx_v_include_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":105 - * if edge != NULL: - * trie_edge_to_map(edge.smaller, result, prefix, include_zeros) - * trie_edge_to_map(edge.bigger, result, prefix, include_zeros) # <<<<<<<<<<<<<< - * prefix = prefix + (edge.val,) - * trie_node_to_map(edge.node, result, prefix, include_zeros) - */ - __pyx_t_2 = __pyx_f_8_cdec_sa_trie_edge_to_map(__pyx_v_edge->bigger, __pyx_v_result, __pyx_v_prefix, __pyx_v_include_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":106 - * trie_edge_to_map(edge.smaller, result, prefix, include_zeros) - * trie_edge_to_map(edge.bigger, result, prefix, include_zeros) - * prefix = prefix + (edge.val,) # <<<<<<<<<<<<<< - * trie_node_to_map(edge.node, result, prefix, include_zeros) - * - */ - __pyx_t_2 = PyInt_FromLong(__pyx_v_edge->val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Add(__pyx_v_prefix, ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_v_prefix); - __pyx_v_prefix = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":107 - * trie_edge_to_map(edge.bigger, result, prefix, include_zeros) - * prefix = prefix + (edge.val,) - * trie_node_to_map(edge.node, result, prefix, include_zeros) # <<<<<<<<<<<<<< - * - * cdef class TrieMap: - */ - __pyx_t_2 = __pyx_f_8_cdec_sa_trie_node_to_map(__pyx_v_edge->node, __pyx_v_result, __pyx_v_prefix, __pyx_v_include_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L3; - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.trie_edge_to_map", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_prefix); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_7TrieMap_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_7TrieMap_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_v_alphabet_size; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__alphabet_size,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[1] = {0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__alphabet_size); - 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, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 114; __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_alphabet_size = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_alphabet_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 114; __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[11]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.TrieMap.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_7TrieMap___cinit__(((struct __pyx_obj_8_cdec_sa_TrieMap *)__pyx_v_self), __pyx_v_alphabet_size); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":114 - * cdef int V - * - * def __cinit__(self, int alphabet_size): # <<<<<<<<<<<<<< - * self.V = alphabet_size - * self.root = <_Trie_Node**> malloc(self.V * sizeof(_Trie_Node*)) - */ - -static int __pyx_pf_8_cdec_sa_7TrieMap___cinit__(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, int __pyx_v_alphabet_size) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":115 - * - * def __cinit__(self, int alphabet_size): - * self.V = alphabet_size # <<<<<<<<<<<<<< - * self.root = <_Trie_Node**> malloc(self.V * sizeof(_Trie_Node*)) - * memset(self.root, 0, self.V * sizeof(_Trie_Node*)) - */ - __pyx_v_self->V = __pyx_v_alphabet_size; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":116 - * def __cinit__(self, int alphabet_size): - * self.V = alphabet_size - * self.root = <_Trie_Node**> malloc(self.V * sizeof(_Trie_Node*)) # <<<<<<<<<<<<<< - * memset(self.root, 0, self.V * sizeof(_Trie_Node*)) - * - */ - __pyx_v_self->root = ((struct __pyx_t_8_cdec_sa__Trie_Node **)malloc((__pyx_v_self->V * (sizeof(struct __pyx_t_8_cdec_sa__Trie_Node *))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":117 - * self.V = alphabet_size - * self.root = <_Trie_Node**> malloc(self.V * sizeof(_Trie_Node*)) - * memset(self.root, 0, self.V * sizeof(_Trie_Node*)) # <<<<<<<<<<<<<< - * - * - */ - memset(__pyx_v_self->root, 0, (__pyx_v_self->V * (sizeof(struct __pyx_t_8_cdec_sa__Trie_Node *)))); - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static void __pyx_pw_8_cdec_sa_7TrieMap_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_8_cdec_sa_7TrieMap_3__dealloc__(PyObject *__pyx_v_self) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_8_cdec_sa_7TrieMap_2__dealloc__(((struct __pyx_obj_8_cdec_sa_TrieMap *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":120 - * - * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * cdef int i - * for i from 0 <= i < self.V: - */ - -static void __pyx_pf_8_cdec_sa_7TrieMap_2__dealloc__(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self) { - int __pyx_v_i; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__dealloc__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":122 - * def __dealloc__(self): - * cdef int i - * for i from 0 <= i < self.V: # <<<<<<<<<<<<<< - * if self.root[i] != NULL: - * free_trie_node(self.root[i]) - */ - __pyx_t_1 = __pyx_v_self->V; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":123 - * cdef int i - * for i from 0 <= i < self.V: - * if self.root[i] != NULL: # <<<<<<<<<<<<<< - * free_trie_node(self.root[i]) - * free(self.root) - */ - __pyx_t_2 = ((__pyx_v_self->root[__pyx_v_i]) != NULL); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":124 - * for i from 0 <= i < self.V: - * if self.root[i] != NULL: - * free_trie_node(self.root[i]) # <<<<<<<<<<<<<< - * free(self.root) - * - */ - __pyx_t_3 = __pyx_f_8_cdec_sa_free_trie_node((__pyx_v_self->root[__pyx_v_i])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L5; - } - __pyx_L5:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":125 - * if self.root[i] != NULL: - * free_trie_node(self.root[i]) - * free(self.root) # <<<<<<<<<<<<<< - * - * - */ - free(__pyx_v_self->root); - - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.TrieMap.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_7TrieMap_5insert(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_7TrieMap_5insert(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("insert (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_7TrieMap_4insert(((struct __pyx_obj_8_cdec_sa_TrieMap *)__pyx_v_self), ((PyObject *)__pyx_v_pattern)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":128 - * - * - * def insert(self, pattern): # <<<<<<<<<<<<<< - * cdef int* p - * cdef int i, l - */ - -static PyObject *__pyx_pf_8_cdec_sa_7TrieMap_4insert(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, PyObject *__pyx_v_pattern) { - int *__pyx_v_p; - int __pyx_v_i; - int __pyx_v_l; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - Py_ssize_t __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("insert", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":131 - * cdef int* p - * cdef int i, l - * l = len(pattern) # <<<<<<<<<<<<<< - * p = malloc(l*sizeof(int)) - * for i from 0 <= i < l: - */ - __pyx_t_1 = PyObject_Length(__pyx_v_pattern); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_l = __pyx_t_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":132 - * cdef int i, l - * l = len(pattern) - * p = malloc(l*sizeof(int)) # <<<<<<<<<<<<<< - * for i from 0 <= i < l: - * p[i] = pattern[i] - */ - __pyx_v_p = ((int *)malloc((__pyx_v_l * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":133 - * l = len(pattern) - * p = malloc(l*sizeof(int)) - * for i from 0 <= i < l: # <<<<<<<<<<<<<< - * p[i] = pattern[i] - * self._insert(p,l) - */ - __pyx_t_2 = __pyx_v_l; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":134 - * p = malloc(l*sizeof(int)) - * for i from 0 <= i < l: - * p[i] = pattern[i] # <<<<<<<<<<<<<< - * self._insert(p,l) - * free(p) - */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_pattern, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - (__pyx_v_p[__pyx_v_i]) = __pyx_t_4; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":135 - * for i from 0 <= i < l: - * p[i] = pattern[i] - * self._insert(p,l) # <<<<<<<<<<<<<< - * free(p) - * - */ - ((struct __pyx_vtabstruct_8_cdec_sa_TrieMap *)__pyx_v_self->__pyx_vtab)->_insert(__pyx_v_self, __pyx_v_p, __pyx_v_l); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":136 - * p[i] = pattern[i] - * self._insert(p,l) - * free(p) # <<<<<<<<<<<<<< - * - * - */ - free(__pyx_v_p); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.TrieMap.insert", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":139 - * - * - * cdef _Trie_Node* _insert(self, int* pattern, int pattern_len): # <<<<<<<<<<<<<< - * cdef int i - * cdef _Trie_Node* node - */ - -static struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_f_8_cdec_sa_7TrieMap__insert(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, int *__pyx_v_pattern, int __pyx_v_pattern_len) { - int __pyx_v_i; - struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node; - struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - __Pyx_RefNannySetupContext("_insert", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":142 - * cdef int i - * cdef _Trie_Node* node - * if self.root[pattern[0]] == NULL: # <<<<<<<<<<<<<< - * self.root[pattern[0]] = new_trie_node() - * node = self.root[pattern[0]] - */ - __pyx_t_1 = ((__pyx_v_self->root[(__pyx_v_pattern[0])]) == NULL); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":143 - * cdef _Trie_Node* node - * if self.root[pattern[0]] == NULL: - * self.root[pattern[0]] = new_trie_node() # <<<<<<<<<<<<<< - * node = self.root[pattern[0]] - * for i from 1 <= i < pattern_len: - */ - (__pyx_v_self->root[(__pyx_v_pattern[0])]) = __pyx_f_8_cdec_sa_new_trie_node(); - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":144 - * if self.root[pattern[0]] == NULL: - * self.root[pattern[0]] = new_trie_node() - * node = self.root[pattern[0]] # <<<<<<<<<<<<<< - * for i from 1 <= i < pattern_len: - * node = trie_insert(node, pattern[i]) - */ - __pyx_v_node = (__pyx_v_self->root[(__pyx_v_pattern[0])]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":145 - * self.root[pattern[0]] = new_trie_node() - * node = self.root[pattern[0]] - * for i from 1 <= i < pattern_len: # <<<<<<<<<<<<<< - * node = trie_insert(node, pattern[i]) - * return node - */ - __pyx_t_2 = __pyx_v_pattern_len; - for (__pyx_v_i = 1; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":146 - * node = self.root[pattern[0]] - * for i from 1 <= i < pattern_len: - * node = trie_insert(node, pattern[i]) # <<<<<<<<<<<<<< - * return node - * - */ - __pyx_v_node = __pyx_f_8_cdec_sa_trie_insert(__pyx_v_node, (__pyx_v_pattern[__pyx_v_i])); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":147 - * for i from 1 <= i < pattern_len: - * node = trie_insert(node, pattern[i]) - * return node # <<<<<<<<<<<<<< - * - * def contains(self, pattern): - */ - __pyx_r = __pyx_v_node; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_7TrieMap_7contains(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_7TrieMap_7contains(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("contains (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_7TrieMap_6contains(((struct __pyx_obj_8_cdec_sa_TrieMap *)__pyx_v_self), ((PyObject *)__pyx_v_pattern)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":149 - * return node - * - * def contains(self, pattern): # <<<<<<<<<<<<<< - * cdef int* p - * cdef int i, l - */ - -static PyObject *__pyx_pf_8_cdec_sa_7TrieMap_6contains(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, PyObject *__pyx_v_pattern) { - int *__pyx_v_p; - int __pyx_v_i; - int __pyx_v_l; - struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - Py_ssize_t __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("contains", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":153 - * cdef int i, l - * cdef _Trie_Node* node - * l = len(pattern) # <<<<<<<<<<<<<< - * p = malloc(l*sizeof(int)) - * for i from 0 <= i < l: - */ - __pyx_t_1 = PyObject_Length(__pyx_v_pattern); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_l = __pyx_t_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":154 - * cdef _Trie_Node* node - * l = len(pattern) - * p = malloc(l*sizeof(int)) # <<<<<<<<<<<<<< - * for i from 0 <= i < l: - * p[i] = pattern[i] - */ - __pyx_v_p = ((int *)malloc((__pyx_v_l * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":155 - * l = len(pattern) - * p = malloc(l*sizeof(int)) - * for i from 0 <= i < l: # <<<<<<<<<<<<<< - * p[i] = pattern[i] - * node = self._contains(p,l) - */ - __pyx_t_2 = __pyx_v_l; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":156 - * p = malloc(l*sizeof(int)) - * for i from 0 <= i < l: - * p[i] = pattern[i] # <<<<<<<<<<<<<< - * node = self._contains(p,l) - * free(p) - */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_pattern, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - (__pyx_v_p[__pyx_v_i]) = __pyx_t_4; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":157 - * for i from 0 <= i < l: - * p[i] = pattern[i] - * node = self._contains(p,l) # <<<<<<<<<<<<<< - * free(p) - * if node == NULL: - */ - __pyx_v_node = ((struct __pyx_vtabstruct_8_cdec_sa_TrieMap *)__pyx_v_self->__pyx_vtab)->_contains(__pyx_v_self, __pyx_v_p, __pyx_v_l); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":158 - * p[i] = pattern[i] - * node = self._contains(p,l) - * free(p) # <<<<<<<<<<<<<< - * if node == NULL: - * return False - */ - free(__pyx_v_p); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":159 - * node = self._contains(p,l) - * free(p) - * if node == NULL: # <<<<<<<<<<<<<< - * return False - * else: - */ - __pyx_t_5 = (__pyx_v_node == NULL); - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":160 - * free(p) - * if node == NULL: - * return False # <<<<<<<<<<<<<< - * else: - * return True - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - goto __pyx_L5; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":162 - * return False - * else: - * return True # <<<<<<<<<<<<<< - * - * cdef _Trie_Node* _contains(self, int* pattern, int pattern_len): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - } - __pyx_L5:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.TrieMap.contains", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":164 - * return True - * - * cdef _Trie_Node* _contains(self, int* pattern, int pattern_len): # <<<<<<<<<<<<<< - * cdef int i - * cdef _Trie_Node* node - */ - -static struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_f_8_cdec_sa_7TrieMap__contains(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, int *__pyx_v_pattern, int __pyx_v_pattern_len) { - int __pyx_v_i; - struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node; - struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("_contains", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":167 - * cdef int i - * cdef _Trie_Node* node - * node = self.root[pattern[0]] # <<<<<<<<<<<<<< - * i = 1 - * while node != NULL and i < pattern_len: - */ - __pyx_v_node = (__pyx_v_self->root[(__pyx_v_pattern[0])]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":168 - * cdef _Trie_Node* node - * node = self.root[pattern[0]] - * i = 1 # <<<<<<<<<<<<<< - * while node != NULL and i < pattern_len: - * node = trie_find(node, pattern[i]) - */ - __pyx_v_i = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":169 - * node = self.root[pattern[0]] - * i = 1 - * while node != NULL and i < pattern_len: # <<<<<<<<<<<<<< - * node = trie_find(node, pattern[i]) - * i = i+1 - */ - while (1) { - __pyx_t_1 = (__pyx_v_node != NULL); - if (__pyx_t_1) { - __pyx_t_2 = (__pyx_v_i < __pyx_v_pattern_len); - __pyx_t_3 = __pyx_t_2; - } else { - __pyx_t_3 = __pyx_t_1; - } - if (!__pyx_t_3) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":170 - * i = 1 - * while node != NULL and i < pattern_len: - * node = trie_find(node, pattern[i]) # <<<<<<<<<<<<<< - * i = i+1 - * return node - */ - __pyx_v_node = __pyx_f_8_cdec_sa_trie_find(__pyx_v_node, (__pyx_v_pattern[__pyx_v_i])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":171 - * while node != NULL and i < pattern_len: - * node = trie_find(node, pattern[i]) - * i = i+1 # <<<<<<<<<<<<<< - * return node - * - */ - __pyx_v_i = (__pyx_v_i + 1); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":172 - * node = trie_find(node, pattern[i]) - * i = i+1 - * return node # <<<<<<<<<<<<<< - * - * def toMap(self, flag): - */ - __pyx_r = __pyx_v_node; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_7TrieMap_9toMap(PyObject *__pyx_v_self, PyObject *__pyx_v_flag); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_7TrieMap_9toMap(PyObject *__pyx_v_self, PyObject *__pyx_v_flag) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("toMap (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_7TrieMap_8toMap(((struct __pyx_obj_8_cdec_sa_TrieMap *)__pyx_v_self), ((PyObject *)__pyx_v_flag)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":174 - * return node - * - * def toMap(self, flag): # <<<<<<<<<<<<<< - * cdef int i, include_zeros - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_7TrieMap_8toMap(struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_self, PyObject *__pyx_v_flag) { - int __pyx_v_i; - int __pyx_v_include_zeros; - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("toMap", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":177 - * cdef int i, include_zeros - * - * if flag: # <<<<<<<<<<<<<< - * include_zeros=1 - * else: - */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_flag); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":178 - * - * if flag: - * include_zeros=1 # <<<<<<<<<<<<<< - * else: - * include_zeros=0 - */ - __pyx_v_include_zeros = 1; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":180 - * include_zeros=1 - * else: - * include_zeros=0 # <<<<<<<<<<<<<< - * result = {} - * for i from 0 <= i < self.V: - */ - __pyx_v_include_zeros = 0; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":181 - * else: - * include_zeros=0 - * result = {} # <<<<<<<<<<<<<< - * for i from 0 <= i < self.V: - * if self.root[i] != NULL: - */ - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_v_result = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":182 - * include_zeros=0 - * result = {} - * for i from 0 <= i < self.V: # <<<<<<<<<<<<<< - * if self.root[i] != NULL: - * trie_node_to_map(self.root[i], result, (i,), include_zeros) - */ - __pyx_t_3 = __pyx_v_self->V; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":183 - * result = {} - * for i from 0 <= i < self.V: - * if self.root[i] != NULL: # <<<<<<<<<<<<<< - * trie_node_to_map(self.root[i], result, (i,), include_zeros) - * return result - */ - __pyx_t_1 = ((__pyx_v_self->root[__pyx_v_i]) != NULL); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":184 - * for i from 0 <= i < self.V: - * if self.root[i] != NULL: - * trie_node_to_map(self.root[i], result, (i,), include_zeros) # <<<<<<<<<<<<<< - * return result - * - */ - __pyx_t_2 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = __pyx_f_8_cdec_sa_trie_node_to_map((__pyx_v_self->root[__pyx_v_i]), ((PyObject *)__pyx_v_result), ((PyObject *)__pyx_t_4), __pyx_v_include_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L6; - } - __pyx_L6:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":185 - * if self.root[i] != NULL: - * trie_node_to_map(self.root[i], result, (i,), include_zeros) - * return result # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - __pyx_r = ((PyObject *)__pyx_v_result); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec_sa.TrieMap.toMap", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_14Precomputation_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_14Precomputation_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_fsarray = 0; - PyObject *__pyx_v_from_stats = 0; - PyObject *__pyx_v_from_binary = 0; - PyObject *__pyx_v_precompute_rank = 0; - PyObject *__pyx_v_precompute_secondary_rank = 0; - PyObject *__pyx_v_max_length = 0; - PyObject *__pyx_v_max_nonterminals = 0; - PyObject *__pyx_v_train_max_initial_size = 0; - PyObject *__pyx_v_train_min_gap_size = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fsarray,&__pyx_n_s__from_stats,&__pyx_n_s__from_binary,&__pyx_n_s__precompute_rank,&__pyx_n_s_68,&__pyx_n_s__max_length,&__pyx_n_s__max_nonterminals,&__pyx_n_s_69,&__pyx_n_s__train_min_gap_size,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[9] = {0,0,0,0,0,0,0,0,0}; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":200 - * cdef write_map(self, m, FILE* f) - * - * def __cinit__(self, fsarray=None, from_stats=None, from_binary=None, # <<<<<<<<<<<<<< - * precompute_rank=1000, precompute_secondary_rank=20, - * max_length=5, max_nonterminals=2, - */ - values[0] = ((PyObject *)Py_None); - values[1] = ((PyObject *)Py_None); - values[2] = ((PyObject *)Py_None); - values[3] = ((PyObject *)__pyx_int_1000); - values[4] = ((PyObject *)__pyx_int_20); - values[5] = ((PyObject *)__pyx_int_5); - values[6] = ((PyObject *)__pyx_int_2); - values[7] = ((PyObject *)__pyx_int_10); - values[8] = ((PyObject *)__pyx_int_2); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fsarray); - if (value) { values[0] = value; kw_args--; } - } - case 1: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_stats); - if (value) { values[1] = value; kw_args--; } - } - case 2: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_binary); - if (value) { values[2] = value; kw_args--; } - } - case 3: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__precompute_rank); - if (value) { values[3] = value; kw_args--; } - } - case 4: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_68); - if (value) { values[4] = value; kw_args--; } - } - case 5: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_length); - if (value) { values[5] = value; kw_args--; } - } - case 6: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_nonterminals); - if (value) { values[6] = value; kw_args--; } - } - case 7: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_69); - if (value) { values[7] = value; kw_args--; } - } - case 8: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__train_min_gap_size); - if (value) { values[8] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_fsarray = values[0]; - __pyx_v_from_stats = values[1]; - __pyx_v_from_binary = values[2]; - __pyx_v_precompute_rank = values[3]; - __pyx_v_precompute_secondary_rank = values[4]; - __pyx_v_max_length = values[5]; - __pyx_v_max_nonterminals = values[6]; - __pyx_v_train_max_initial_size = values[7]; - __pyx_v_train_min_gap_size = values[8]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 9, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[11]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.Precomputation.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_14Precomputation___cinit__(((struct __pyx_obj_8_cdec_sa_Precomputation *)__pyx_v_self), __pyx_v_fsarray, __pyx_v_from_stats, __pyx_v_from_binary, __pyx_v_precompute_rank, __pyx_v_precompute_secondary_rank, __pyx_v_max_length, __pyx_v_max_nonterminals, __pyx_v_train_max_initial_size, __pyx_v_train_min_gap_size); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_14Precomputation___cinit__(struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, PyObject *__pyx_v_fsarray, PyObject *__pyx_v_from_stats, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_precompute_rank, PyObject *__pyx_v_precompute_secondary_rank, PyObject *__pyx_v_max_length, PyObject *__pyx_v_max_nonterminals, PyObject *__pyx_v_train_max_initial_size, PyObject *__pyx_v_train_min_gap_size) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":204 - * max_length=5, max_nonterminals=2, - * train_max_initial_size=10, train_min_gap_size=2): - * self.precompute_rank = precompute_rank # <<<<<<<<<<<<<< - * self.precompute_secondary_rank = precompute_secondary_rank - * self.max_length = max_length - */ - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_precompute_rank); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->precompute_rank = __pyx_t_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":205 - * train_max_initial_size=10, train_min_gap_size=2): - * self.precompute_rank = precompute_rank - * self.precompute_secondary_rank = precompute_secondary_rank # <<<<<<<<<<<<<< - * self.max_length = max_length - * self.max_nonterminals = max_nonterminals - */ - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_precompute_secondary_rank); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->precompute_secondary_rank = __pyx_t_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":206 - * self.precompute_rank = precompute_rank - * self.precompute_secondary_rank = precompute_secondary_rank - * self.max_length = max_length # <<<<<<<<<<<<<< - * self.max_nonterminals = max_nonterminals - * self.train_max_initial_size = train_max_initial_size - */ - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_max_length); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->max_length = __pyx_t_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":207 - * self.precompute_secondary_rank = precompute_secondary_rank - * self.max_length = max_length - * self.max_nonterminals = max_nonterminals # <<<<<<<<<<<<<< - * self.train_max_initial_size = train_max_initial_size - * self.train_min_gap_size = train_min_gap_size - */ - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_max_nonterminals); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->max_nonterminals = __pyx_t_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":208 - * self.max_length = max_length - * self.max_nonterminals = max_nonterminals - * self.train_max_initial_size = train_max_initial_size # <<<<<<<<<<<<<< - * self.train_min_gap_size = train_min_gap_size - * if from_binary: - */ - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_train_max_initial_size); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->train_max_initial_size = __pyx_t_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":209 - * self.max_nonterminals = max_nonterminals - * self.train_max_initial_size = train_max_initial_size - * self.train_min_gap_size = train_min_gap_size # <<<<<<<<<<<<<< - * if from_binary: - * self.read_binary(from_binary) - */ - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_train_min_gap_size); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->train_min_gap_size = __pyx_t_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":210 - * self.train_max_initial_size = train_max_initial_size - * self.train_min_gap_size = train_min_gap_size - * if from_binary: # <<<<<<<<<<<<<< - * self.read_binary(from_binary) - * elif from_stats: - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_binary); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":211 - * self.train_min_gap_size = train_min_gap_size - * if from_binary: - * self.read_binary(from_binary) # <<<<<<<<<<<<<< - * elif from_stats: - * self.precompute(from_stats, fsarray) - */ - __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_binary); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_from_binary); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_from_binary); - __Pyx_GIVEREF(__pyx_v_from_binary); - __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L3; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":212 - * if from_binary: - * self.read_binary(from_binary) - * elif from_stats: # <<<<<<<<<<<<<< - * self.precompute(from_stats, fsarray) - * - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_stats); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":213 - * self.read_binary(from_binary) - * elif from_stats: - * self.precompute(from_stats, fsarray) # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__precompute); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_from_stats); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_from_stats); - __Pyx_GIVEREF(__pyx_v_from_stats); - __Pyx_INCREF(__pyx_v_fsarray); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_fsarray); - __Pyx_GIVEREF(__pyx_v_fsarray); - __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L3; - } - __pyx_L3:; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("_cdec_sa.Precomputation.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_14Precomputation_3read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_14Precomputation_3read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_binary (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.Precomputation.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_14Precomputation_2read_binary(((struct __pyx_obj_8_cdec_sa_Precomputation *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":216 - * - * - * def read_binary(self, char* filename): # <<<<<<<<<<<<<< - * cdef FILE* f - * f = fopen(filename, "r") - */ - -static PyObject *__pyx_pf_8_cdec_sa_14Precomputation_2read_binary(struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, char *__pyx_v_filename) { - FILE *__pyx_v_f; - 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("read_binary", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":218 - * def read_binary(self, char* filename): - * cdef FILE* f - * f = fopen(filename, "r") # <<<<<<<<<<<<<< - * fread(&(self.precompute_rank), sizeof(int), 1, f) - * fread(&(self.precompute_secondary_rank), sizeof(int), 1, f) - */ - __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":219 - * cdef FILE* f - * f = fopen(filename, "r") - * fread(&(self.precompute_rank), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * fread(&(self.precompute_secondary_rank), sizeof(int), 1, f) - * fread(&(self.max_length), sizeof(int), 1, f) - */ - fread((&__pyx_v_self->precompute_rank), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":220 - * f = fopen(filename, "r") - * fread(&(self.precompute_rank), sizeof(int), 1, f) - * fread(&(self.precompute_secondary_rank), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * fread(&(self.max_length), sizeof(int), 1, f) - * fread(&(self.max_nonterminals), sizeof(int), 1, f) - */ - fread((&__pyx_v_self->precompute_secondary_rank), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":221 - * fread(&(self.precompute_rank), sizeof(int), 1, f) - * fread(&(self.precompute_secondary_rank), sizeof(int), 1, f) - * fread(&(self.max_length), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * fread(&(self.max_nonterminals), sizeof(int), 1, f) - * fread(&(self.train_max_initial_size), sizeof(int), 1, f) - */ - fread((&__pyx_v_self->max_length), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":222 - * fread(&(self.precompute_secondary_rank), sizeof(int), 1, f) - * fread(&(self.max_length), sizeof(int), 1, f) - * fread(&(self.max_nonterminals), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * fread(&(self.train_max_initial_size), sizeof(int), 1, f) - * fread(&(self.train_min_gap_size), sizeof(int), 1, f) - */ - fread((&__pyx_v_self->max_nonterminals), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":223 - * fread(&(self.max_length), sizeof(int), 1, f) - * fread(&(self.max_nonterminals), sizeof(int), 1, f) - * fread(&(self.train_max_initial_size), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * fread(&(self.train_min_gap_size), sizeof(int), 1, f) - * self.precomputed_index = self.read_map(f) - */ - fread((&__pyx_v_self->train_max_initial_size), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":224 - * fread(&(self.max_nonterminals), sizeof(int), 1, f) - * fread(&(self.train_max_initial_size), sizeof(int), 1, f) - * fread(&(self.train_min_gap_size), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * self.precomputed_index = self.read_map(f) - * self.precomputed_collocations = self.read_map(f) - */ - fread((&__pyx_v_self->train_min_gap_size), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":225 - * fread(&(self.train_max_initial_size), sizeof(int), 1, f) - * fread(&(self.train_min_gap_size), sizeof(int), 1, f) - * self.precomputed_index = self.read_map(f) # <<<<<<<<<<<<<< - * self.precomputed_collocations = self.read_map(f) - * fclose(f) - */ - __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_Precomputation *)__pyx_v_self->__pyx_vtab)->read_map(__pyx_v_self, __pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->precomputed_index); - __Pyx_DECREF(__pyx_v_self->precomputed_index); - __pyx_v_self->precomputed_index = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":226 - * fread(&(self.train_min_gap_size), sizeof(int), 1, f) - * self.precomputed_index = self.read_map(f) - * self.precomputed_collocations = self.read_map(f) # <<<<<<<<<<<<<< - * fclose(f) - * - */ - __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_Precomputation *)__pyx_v_self->__pyx_vtab)->read_map(__pyx_v_self, __pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->precomputed_collocations); - __Pyx_DECREF(__pyx_v_self->precomputed_collocations); - __pyx_v_self->precomputed_collocations = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":227 - * self.precomputed_index = self.read_map(f) - * self.precomputed_collocations = self.read_map(f) - * fclose(f) # <<<<<<<<<<<<<< - * - * - */ - fclose(__pyx_v_f); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec_sa.Precomputation.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_14Precomputation_5write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_14Precomputation_5write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_binary (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.Precomputation.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_14Precomputation_4write_binary(((struct __pyx_obj_8_cdec_sa_Precomputation *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":230 - * - * - * def write_binary(self, char* filename): # <<<<<<<<<<<<<< - * cdef FILE* f - * f = fopen(filename, "w") - */ - -static PyObject *__pyx_pf_8_cdec_sa_14Precomputation_4write_binary(struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, char *__pyx_v_filename) { - FILE *__pyx_v_f; - 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("write_binary", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":232 - * def write_binary(self, char* filename): - * cdef FILE* f - * f = fopen(filename, "w") # <<<<<<<<<<<<<< - * fwrite(&(self.precompute_rank), sizeof(int), 1, f) - * fwrite(&(self.precompute_secondary_rank), sizeof(int), 1, f) - */ - __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":233 - * cdef FILE* f - * f = fopen(filename, "w") - * fwrite(&(self.precompute_rank), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * fwrite(&(self.precompute_secondary_rank), sizeof(int), 1, f) - * fwrite(&(self.max_length), sizeof(int), 1, f) - */ - fwrite((&__pyx_v_self->precompute_rank), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":234 - * f = fopen(filename, "w") - * fwrite(&(self.precompute_rank), sizeof(int), 1, f) - * fwrite(&(self.precompute_secondary_rank), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * fwrite(&(self.max_length), sizeof(int), 1, f) - * fwrite(&(self.max_nonterminals), sizeof(int), 1, f) - */ - fwrite((&__pyx_v_self->precompute_secondary_rank), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":235 - * fwrite(&(self.precompute_rank), sizeof(int), 1, f) - * fwrite(&(self.precompute_secondary_rank), sizeof(int), 1, f) - * fwrite(&(self.max_length), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * fwrite(&(self.max_nonterminals), sizeof(int), 1, f) - * fwrite(&(self.train_max_initial_size), sizeof(int), 1, f) - */ - fwrite((&__pyx_v_self->max_length), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":236 - * fwrite(&(self.precompute_secondary_rank), sizeof(int), 1, f) - * fwrite(&(self.max_length), sizeof(int), 1, f) - * fwrite(&(self.max_nonterminals), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * fwrite(&(self.train_max_initial_size), sizeof(int), 1, f) - * fwrite(&(self.train_min_gap_size), sizeof(int), 1, f) - */ - fwrite((&__pyx_v_self->max_nonterminals), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":237 - * fwrite(&(self.max_length), sizeof(int), 1, f) - * fwrite(&(self.max_nonterminals), sizeof(int), 1, f) - * fwrite(&(self.train_max_initial_size), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * fwrite(&(self.train_min_gap_size), sizeof(int), 1, f) - * self.write_map(self.precomputed_index, f) - */ - fwrite((&__pyx_v_self->train_max_initial_size), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":238 - * fwrite(&(self.max_nonterminals), sizeof(int), 1, f) - * fwrite(&(self.train_max_initial_size), sizeof(int), 1, f) - * fwrite(&(self.train_min_gap_size), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * self.write_map(self.precomputed_index, f) - * self.write_map(self.precomputed_collocations, f) - */ - fwrite((&__pyx_v_self->train_min_gap_size), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":239 - * fwrite(&(self.train_max_initial_size), sizeof(int), 1, f) - * fwrite(&(self.train_min_gap_size), sizeof(int), 1, f) - * self.write_map(self.precomputed_index, f) # <<<<<<<<<<<<<< - * self.write_map(self.precomputed_collocations, f) - * fclose(f) - */ - __pyx_t_1 = __pyx_v_self->precomputed_index; - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_Precomputation *)__pyx_v_self->__pyx_vtab)->write_map(__pyx_v_self, __pyx_t_1, __pyx_v_f); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":240 - * fwrite(&(self.train_min_gap_size), sizeof(int), 1, f) - * self.write_map(self.precomputed_index, f) - * self.write_map(self.precomputed_collocations, f) # <<<<<<<<<<<<<< - * fclose(f) - * - */ - __pyx_t_2 = __pyx_v_self->precomputed_collocations; - __Pyx_INCREF(__pyx_t_2); - __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_Precomputation *)__pyx_v_self->__pyx_vtab)->write_map(__pyx_v_self, __pyx_t_2, __pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 240; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":241 - * self.write_map(self.precomputed_index, f) - * self.write_map(self.precomputed_collocations, f) - * fclose(f) # <<<<<<<<<<<<<< - * - * - */ - fclose(__pyx_v_f); - - __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_sa.Precomputation.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":244 - * - * - * cdef write_map(self, m, FILE* f): # <<<<<<<<<<<<<< - * cdef int i, N - * cdef IntList arr - */ - -static PyObject *__pyx_f_8_cdec_sa_14Precomputation_write_map(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, PyObject *__pyx_v_m, FILE *__pyx_v_f) { - int __pyx_v_i; - int __pyx_v_N; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_arr = 0; - PyObject *__pyx_v_pattern = NULL; - PyObject *__pyx_v_val = NULL; - PyObject *__pyx_v_word_id = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - Py_ssize_t __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *(*__pyx_t_4)(PyObject *); - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *(*__pyx_t_8)(PyObject *); - Py_ssize_t __pyx_t_9; - PyObject *(*__pyx_t_10)(PyObject *); - int __pyx_t_11; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("write_map", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":248 - * cdef IntList arr - * - * N = len(m) # <<<<<<<<<<<<<< - * fwrite(&(N), sizeof(int), 1, f) - * for pattern, val in m.iteritems(): - */ - __pyx_t_1 = PyObject_Length(__pyx_v_m); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_N = __pyx_t_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":249 - * - * N = len(m) - * fwrite(&(N), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * for pattern, val in m.iteritems(): - * N = len(pattern) - */ - fwrite((&__pyx_v_N), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":250 - * N = len(m) - * fwrite(&(N), sizeof(int), 1, f) - * for pattern, val in m.iteritems(): # <<<<<<<<<<<<<< - * N = len(pattern) - * fwrite(&(N), sizeof(int), 1, f) - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_m, __pyx_n_s__iteritems); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_1 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_2)) { - if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_2)) break; - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; - } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_2)) { - if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; - } else { - __pyx_t_3 = __pyx_t_4(__pyx_t_2); - if (unlikely(!__pyx_t_3)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { - PyObject* sequence = __pyx_t_3; - if (likely(PyTuple_CheckExact(sequence))) { - 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[11]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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[11]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_5 = PyList_GET_ITEM(sequence, 0); - __pyx_t_6 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_7 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; - index = 0; __pyx_t_5 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_5); - index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_6); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L6_unpacking_done; - __pyx_L5_unpacking_failed:; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[11]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L6_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_pattern); - __pyx_v_pattern = __pyx_t_5; - __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_v_val); - __pyx_v_val = __pyx_t_6; - __pyx_t_6 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":251 - * fwrite(&(N), sizeof(int), 1, f) - * for pattern, val in m.iteritems(): - * N = len(pattern) # <<<<<<<<<<<<<< - * fwrite(&(N), sizeof(int), 1, f) - * for word_id in pattern: - */ - __pyx_t_9 = PyObject_Length(__pyx_v_pattern); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 251; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_N = __pyx_t_9; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":252 - * for pattern, val in m.iteritems(): - * N = len(pattern) - * fwrite(&(N), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * for word_id in pattern: - * i = word_id - */ - fwrite((&__pyx_v_N), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":253 - * N = len(pattern) - * fwrite(&(N), sizeof(int), 1, f) - * for word_id in pattern: # <<<<<<<<<<<<<< - * i = word_id - * fwrite(&(i), sizeof(int), 1, f) - */ - if (PyList_CheckExact(__pyx_v_pattern) || PyTuple_CheckExact(__pyx_v_pattern)) { - __pyx_t_3 = __pyx_v_pattern; __Pyx_INCREF(__pyx_t_3); __pyx_t_9 = 0; - __pyx_t_10 = NULL; - } else { - __pyx_t_9 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_pattern); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = Py_TYPE(__pyx_t_3)->tp_iternext; - } - for (;;) { - if (!__pyx_t_10 && PyList_CheckExact(__pyx_t_3)) { - if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_3)) break; - __pyx_t_6 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_9); __Pyx_INCREF(__pyx_t_6); __pyx_t_9++; - } else if (!__pyx_t_10 && PyTuple_CheckExact(__pyx_t_3)) { - if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_9); __Pyx_INCREF(__pyx_t_6); __pyx_t_9++; - } else { - __pyx_t_6 = __pyx_t_10(__pyx_t_3); - if (unlikely(!__pyx_t_6)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_6); - } - __Pyx_XDECREF(__pyx_v_word_id); - __pyx_v_word_id = __pyx_t_6; - __pyx_t_6 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":254 - * fwrite(&(N), sizeof(int), 1, f) - * for word_id in pattern: - * i = word_id # <<<<<<<<<<<<<< - * fwrite(&(i), sizeof(int), 1, f) - * arr = val - */ - __pyx_t_11 = __Pyx_PyInt_AsInt(__pyx_v_word_id); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_i = __pyx_t_11; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":255 - * for word_id in pattern: - * i = word_id - * fwrite(&(i), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * arr = val - * arr.write_handle(f) - */ - fwrite((&__pyx_v_i), (sizeof(int)), 1, __pyx_v_f); - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":256 - * i = word_id - * fwrite(&(i), sizeof(int), 1, f) - * arr = val # <<<<<<<<<<<<<< - * arr.write_handle(f) - * - */ - if (!(likely(((__pyx_v_val) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_val, __pyx_ptype_8_cdec_sa_IntList))))) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_INCREF(__pyx_v_val); - __Pyx_XDECREF(((PyObject *)__pyx_v_arr)); - __pyx_v_arr = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_val); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":257 - * fwrite(&(i), sizeof(int), 1, f) - * arr = val - * arr.write_handle(f) # <<<<<<<<<<<<<< - * - * - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_arr->__pyx_vtab)->write_handle(__pyx_v_arr, __pyx_v_f); - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("_cdec_sa.Precomputation.write_map", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_arr); - __Pyx_XDECREF(__pyx_v_pattern); - __Pyx_XDECREF(__pyx_v_val); - __Pyx_XDECREF(__pyx_v_word_id); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":260 - * - * - * cdef read_map(self, FILE* f): # <<<<<<<<<<<<<< - * cdef int i, j, k, word_id, N - * cdef IntList arr - */ - -static PyObject *__pyx_f_8_cdec_sa_14Precomputation_read_map(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, FILE *__pyx_v_f) { - int __pyx_v_i; - CYTHON_UNUSED int __pyx_v_j; - CYTHON_UNUSED int __pyx_v_k; - int __pyx_v_word_id; - int __pyx_v_N; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_arr = 0; - PyObject *__pyx_v_m = NULL; - PyObject *__pyx_v_key = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("read_map", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":264 - * cdef IntList arr - * - * m = {} # <<<<<<<<<<<<<< - * fread(&(N), sizeof(int), 1, f) - * for j from 0 <= j < N: - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 264; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_v_m = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":265 - * - * m = {} - * fread(&(N), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * for j from 0 <= j < N: - * fread(&(i), sizeof(int), 1, f) - */ - fread((&__pyx_v_N), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":266 - * m = {} - * fread(&(N), sizeof(int), 1, f) - * for j from 0 <= j < N: # <<<<<<<<<<<<<< - * fread(&(i), sizeof(int), 1, f) - * key = () - */ - __pyx_t_2 = __pyx_v_N; - for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_2; __pyx_v_j++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":267 - * fread(&(N), sizeof(int), 1, f) - * for j from 0 <= j < N: - * fread(&(i), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * key = () - * for k from 0 <= k < i: - */ - fread((&__pyx_v_i), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":268 - * for j from 0 <= j < N: - * fread(&(i), sizeof(int), 1, f) - * key = () # <<<<<<<<<<<<<< - * for k from 0 <= k < i: - * fread(&(word_id), sizeof(int), 1, f) - */ - __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); - __Pyx_XDECREF(((PyObject *)__pyx_v_key)); - __pyx_v_key = __pyx_empty_tuple; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":269 - * fread(&(i), sizeof(int), 1, f) - * key = () - * for k from 0 <= k < i: # <<<<<<<<<<<<<< - * fread(&(word_id), sizeof(int), 1, f) - * key = key + (word_id,) - */ - __pyx_t_3 = __pyx_v_i; - for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_3; __pyx_v_k++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":270 - * key = () - * for k from 0 <= k < i: - * fread(&(word_id), sizeof(int), 1, f) # <<<<<<<<<<<<<< - * key = key + (word_id,) - * arr = IntList() - */ - fread((&__pyx_v_word_id), (sizeof(int)), 1, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":271 - * for k from 0 <= k < i: - * fread(&(word_id), sizeof(int), 1, f) - * key = key + (word_id,) # <<<<<<<<<<<<<< - * arr = IntList() - * arr.read_handle(f) - */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_word_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Add(((PyObject *)__pyx_v_key), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_key)); - __pyx_v_key = __pyx_t_1; - __pyx_t_1 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":272 - * fread(&(word_id), sizeof(int), 1, f) - * key = key + (word_id,) - * arr = IntList() # <<<<<<<<<<<<<< - * arr.read_handle(f) - * m[key] = arr - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 272; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_XDECREF(((PyObject *)__pyx_v_arr)); - __pyx_v_arr = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":273 - * key = key + (word_id,) - * arr = IntList() - * arr.read_handle(f) # <<<<<<<<<<<<<< - * m[key] = arr - * return m - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_arr->__pyx_vtab)->read_handle(__pyx_v_arr, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":274 - * arr = IntList() - * arr.read_handle(f) - * m[key] = arr # <<<<<<<<<<<<<< - * return m - * - */ - if (PyDict_SetItem(((PyObject *)__pyx_v_m), ((PyObject *)__pyx_v_key), ((PyObject *)__pyx_v_arr)) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":275 - * arr.read_handle(f) - * m[key] = arr - * return m # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_m)); - __pyx_r = ((PyObject *)__pyx_v_m); - 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_4); - __Pyx_AddTraceback("_cdec_sa.Precomputation.read_map", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_arr); - __Pyx_XDECREF(__pyx_v_m); - __Pyx_XDECREF(__pyx_v_key); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_14Precomputation_7precompute(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_14Precomputation_7precompute(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_stats = 0; - struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_sarray = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__stats,&__pyx_n_s__sarray,0}; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("precompute (wrapper)", 0); - { - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__stats); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sarray); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("precompute", 1, 2, 2, 1); {__pyx_filename = __pyx_f[11]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "precompute") < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_stats = values[0]; - __pyx_v_sarray = ((struct __pyx_obj_8_cdec_sa_SuffixArray *)values[1]); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("precompute", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[11]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.Precomputation.precompute", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_sarray), __pyx_ptype_8_cdec_sa_SuffixArray, 1, "sarray", 0))) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_8_cdec_sa_14Precomputation_6precompute(((struct __pyx_obj_8_cdec_sa_Precomputation *)__pyx_v_self), __pyx_v_stats, __pyx_v_sarray); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":278 - * - * - * def precompute(self, stats, SuffixArray sarray): # <<<<<<<<<<<<<< - * cdef int i, l, N, max_pattern_len, i1, l1, i2, l2, i3, l3, ptr1, ptr2, ptr3, is_super, sent_count, max_rank - * cdef DataArray darray = sarray.darray - */ - -static PyObject *__pyx_pf_8_cdec_sa_14Precomputation_6precompute(struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_self, PyObject *__pyx_v_stats, struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_sarray) { - int __pyx_v_i; - int __pyx_v_l; - int __pyx_v_N; - int __pyx_v_max_pattern_len; - int __pyx_v_i1; - int __pyx_v_l1; - int __pyx_v_i2; - int __pyx_v_l2; - int __pyx_v_i3; - int __pyx_v_l3; - int __pyx_v_ptr1; - int __pyx_v_ptr2; - int __pyx_v_ptr3; - int __pyx_v_is_super; - int __pyx_v_sent_count; - int __pyx_v_max_rank; - struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_darray = 0; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_data = 0; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_queue = 0; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_cost_by_rank = 0; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_count_by_rank = 0; - struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_frequent_patterns = 0; - struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_super_frequent_patterns = 0; - struct __pyx_obj_8_cdec_sa_TrieMap *__pyx_v_collocations = 0; - struct __pyx_t_8_cdec_sa__Trie_Node *__pyx_v_node; - PyObject *__pyx_v_I_set = NULL; - PyObject *__pyx_v_J_set = NULL; - PyObject *__pyx_v_J2_set = NULL; - PyObject *__pyx_v_IJ_set = NULL; - PyObject *__pyx_v_pattern_rank = NULL; - float __pyx_v_start_time; - PyObject *__pyx_v_rank = NULL; - CYTHON_UNUSED PyObject *__pyx_v__ = NULL; - PyObject *__pyx_v_phrase = NULL; - int __pyx_v_sa_word_id; - PyObject *__pyx_v_x = NULL; - PyObject *__pyx_v_pattern1 = NULL; - PyObject *__pyx_v_pattern2 = NULL; - PyObject *__pyx_v_combined_pattern = NULL; - PyObject *__pyx_v_pattern = NULL; - PyObject *__pyx_v_arr = NULL; - PyObject *__pyx_v_s = NULL; - PyObject *__pyx_v_word_id = NULL; - PyObject *__pyx_v_chunk = NULL; - PyObject *__pyx_v_arity = NULL; - PyObject *__pyx_v_cumul_cost = NULL; - PyObject *__pyx_v_cumul_count = NULL; - PyObject *__pyx_v_num_found_patterns = NULL; - float __pyx_v_stop_time; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *(*__pyx_t_4)(PyObject *); - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *(*__pyx_t_10)(PyObject *); - int __pyx_t_11; - Py_ssize_t __pyx_t_12; - int __pyx_t_13; - Py_ssize_t __pyx_t_14; - int __pyx_t_15; - int __pyx_t_16; - int __pyx_t_17; - int __pyx_t_18; - int __pyx_t_19; - PyObject *(*__pyx_t_20)(PyObject *); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("precompute", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":280 - * def precompute(self, stats, SuffixArray sarray): - * cdef int i, l, N, max_pattern_len, i1, l1, i2, l2, i3, l3, ptr1, ptr2, ptr3, is_super, sent_count, max_rank - * cdef DataArray darray = sarray.darray # <<<<<<<<<<<<<< - * cdef IntList data, queue, cost_by_rank, count_by_rank - * cdef TrieMap frequent_patterns, super_frequent_patterns, collocations - */ - __Pyx_INCREF(((PyObject *)__pyx_v_sarray->darray)); - __pyx_v_darray = __pyx_v_sarray->darray; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":285 - * cdef _Trie_Node* node - * - * data = darray.data # <<<<<<<<<<<<<< - * - * frequent_patterns = TrieMap(len(darray.id2word)) - */ - __Pyx_INCREF(((PyObject *)__pyx_v_darray->data)); - __pyx_v_data = __pyx_v_darray->data; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":287 - * data = darray.data - * - * frequent_patterns = TrieMap(len(darray.id2word)) # <<<<<<<<<<<<<< - * super_frequent_patterns = TrieMap(len(darray.id2word)) - * collocations = TrieMap(len(darray.id2word)) - */ - __pyx_t_1 = __pyx_v_darray->id2word; - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_TrieMap)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_v_frequent_patterns = ((struct __pyx_obj_8_cdec_sa_TrieMap *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":288 - * - * frequent_patterns = TrieMap(len(darray.id2word)) - * super_frequent_patterns = TrieMap(len(darray.id2word)) # <<<<<<<<<<<<<< - * collocations = TrieMap(len(darray.id2word)) - * - */ - __pyx_t_1 = __pyx_v_darray->id2word; - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_TrieMap)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_v_super_frequent_patterns = ((struct __pyx_obj_8_cdec_sa_TrieMap *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":289 - * frequent_patterns = TrieMap(len(darray.id2word)) - * super_frequent_patterns = TrieMap(len(darray.id2word)) - * collocations = TrieMap(len(darray.id2word)) # <<<<<<<<<<<<<< - * - * I_set = set() - */ - __pyx_t_1 = __pyx_v_darray->id2word; - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_TrieMap)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_v_collocations = ((struct __pyx_obj_8_cdec_sa_TrieMap *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":291 - * collocations = TrieMap(len(darray.id2word)) - * - * I_set = set() # <<<<<<<<<<<<<< - * J_set = set() - * J2_set = set() - */ - __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_v_I_set = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":292 - * - * I_set = set() - * J_set = set() # <<<<<<<<<<<<<< - * J2_set = set() - * IJ_set = set() - */ - __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_v_J_set = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":293 - * I_set = set() - * J_set = set() - * J2_set = set() # <<<<<<<<<<<<<< - * IJ_set = set() - * pattern_rank = {} - */ - __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_v_J2_set = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":294 - * J_set = set() - * J2_set = set() - * IJ_set = set() # <<<<<<<<<<<<<< - * pattern_rank = {} - * - */ - __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_v_IJ_set = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":295 - * J2_set = set() - * IJ_set = set() - * pattern_rank = {} # <<<<<<<<<<<<<< - * - * logger.info("Precomputing frequent intersections") - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_v_pattern_rank = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":297 - * pattern_rank = {} - * - * logger.info("Precomputing frequent intersections") # <<<<<<<<<<<<<< - * cdef float start_time = monitor_cpu() - * - */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__info); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_71), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":298 - * - * logger.info("Precomputing frequent intersections") - * cdef float start_time = monitor_cpu() # <<<<<<<<<<<<<< - * - * max_pattern_len = 0 - */ - __pyx_v_start_time = __pyx_f_8_cdec_sa_monitor_cpu(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":300 - * cdef float start_time = monitor_cpu() - * - * max_pattern_len = 0 # <<<<<<<<<<<<<< - * for rank, (_, _, phrase) in enumerate(stats): - * if rank >= self.precompute_rank: - */ - __pyx_v_max_pattern_len = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":301 - * - * max_pattern_len = 0 - * for rank, (_, _, phrase) in enumerate(stats): # <<<<<<<<<<<<<< - * if rank >= self.precompute_rank: - * break - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_t_1 = __pyx_int_0; - if (PyList_CheckExact(__pyx_v_stats) || PyTuple_CheckExact(__pyx_v_stats)) { - __pyx_t_3 = __pyx_v_stats; __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_stats); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; - } - for (;;) { - if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_3)) break; - __pyx_t_5 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; - } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; - } else { - __pyx_t_5 = __pyx_t_4(__pyx_t_3); - if (unlikely(!__pyx_t_5)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_5); - } - if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) { - PyObject* sequence = __pyx_t_5; - if (likely(PyTuple_CheckExact(sequence))) { - if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { - if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[11]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 2); - } else { - if (unlikely(PyList_GET_SIZE(sequence) != 3)) { - if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[11]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_6 = PyList_GET_ITEM(sequence, 0); - __pyx_t_7 = PyList_GET_ITEM(sequence, 1); - __pyx_t_8 = PyList_GET_ITEM(sequence, 2); - } - __Pyx_INCREF(__pyx_t_6); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_9 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; - index = 0; __pyx_t_6 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_6); - index = 1; __pyx_t_7 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_7)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - index = 2; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_8); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 3) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L6_unpacking_done; - __pyx_L5_unpacking_failed:; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[11]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L6_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v__); - __pyx_v__ = __pyx_t_6; - __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_v__); - __pyx_v__ = __pyx_t_7; - __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_v_phrase); - __pyx_v_phrase = __pyx_t_8; - __pyx_t_8 = 0; - __Pyx_INCREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_v_rank); - __pyx_v_rank = __pyx_t_1; - __pyx_t_5 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); - __pyx_t_1 = __pyx_t_5; - __pyx_t_5 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":302 - * max_pattern_len = 0 - * for rank, (_, _, phrase) in enumerate(stats): - * if rank >= self.precompute_rank: # <<<<<<<<<<<<<< - * break - * max_pattern_len = max(max_pattern_len, len(phrase)) - */ - __pyx_t_5 = PyInt_FromLong(__pyx_v_self->precompute_rank); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_8 = PyObject_RichCompare(__pyx_v_rank, __pyx_t_5, Py_GE); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (__pyx_t_11) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":303 - * for rank, (_, _, phrase) in enumerate(stats): - * if rank >= self.precompute_rank: - * break # <<<<<<<<<<<<<< - * max_pattern_len = max(max_pattern_len, len(phrase)) - * frequent_patterns.insert(phrase) - */ - goto __pyx_L4_break; - goto __pyx_L7; - } - __pyx_L7:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":304 - * if rank >= self.precompute_rank: - * break - * max_pattern_len = max(max_pattern_len, len(phrase)) # <<<<<<<<<<<<<< - * frequent_patterns.insert(phrase) - * I_set.add(phrase) - */ - __pyx_t_12 = PyObject_Length(__pyx_v_phrase); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_13 = __pyx_v_max_pattern_len; - if ((__pyx_t_12 > __pyx_t_13)) { - __pyx_t_14 = __pyx_t_12; - } else { - __pyx_t_14 = __pyx_t_13; - } - __pyx_v_max_pattern_len = __pyx_t_14; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":305 - * break - * max_pattern_len = max(max_pattern_len, len(phrase)) - * frequent_patterns.insert(phrase) # <<<<<<<<<<<<<< - * I_set.add(phrase) - * pattern_rank[phrase] = rank - */ - __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_v_frequent_patterns), __pyx_n_s__insert); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(__pyx_v_phrase); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_phrase); - __Pyx_GIVEREF(__pyx_v_phrase); - __pyx_t_7 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":306 - * max_pattern_len = max(max_pattern_len, len(phrase)) - * frequent_patterns.insert(phrase) - * I_set.add(phrase) # <<<<<<<<<<<<<< - * pattern_rank[phrase] = rank - * if rank < self.precompute_secondary_rank: - */ - __pyx_t_15 = PySet_Add(__pyx_v_I_set, __pyx_v_phrase); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":307 - * frequent_patterns.insert(phrase) - * I_set.add(phrase) - * pattern_rank[phrase] = rank # <<<<<<<<<<<<<< - * if rank < self.precompute_secondary_rank: - * super_frequent_patterns.insert(phrase) - */ - if (PyDict_SetItem(((PyObject *)__pyx_v_pattern_rank), __pyx_v_phrase, __pyx_v_rank) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":308 - * I_set.add(phrase) - * pattern_rank[phrase] = rank - * if rank < self.precompute_secondary_rank: # <<<<<<<<<<<<<< - * super_frequent_patterns.insert(phrase) - * J_set.add(phrase) - */ - __pyx_t_7 = PyInt_FromLong(__pyx_v_self->precompute_secondary_rank); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_rank, __pyx_t_7, Py_LT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_11) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":309 - * pattern_rank[phrase] = rank - * if rank < self.precompute_secondary_rank: - * super_frequent_patterns.insert(phrase) # <<<<<<<<<<<<<< - * J_set.add(phrase) - * - */ - __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_super_frequent_patterns), __pyx_n_s__insert); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(__pyx_v_phrase); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_phrase); - __Pyx_GIVEREF(__pyx_v_phrase); - __pyx_t_8 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":310 - * if rank < self.precompute_secondary_rank: - * super_frequent_patterns.insert(phrase) - * J_set.add(phrase) # <<<<<<<<<<<<<< - * - * queue = IntList(increment=1000) - */ - __pyx_t_15 = PySet_Add(__pyx_v_J_set, __pyx_v_phrase); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L8; - } - __pyx_L8:; - } - __pyx_L4_break:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":312 - * J_set.add(phrase) - * - * queue = IntList(increment=1000) # <<<<<<<<<<<<<< - * - * logger.info(" Computing inverted indexes...") - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 312; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__increment), __pyx_int_1000) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 312; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 312; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_v_queue = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":314 - * queue = IntList(increment=1000) - * - * logger.info(" Computing inverted indexes...") # <<<<<<<<<<<<<< - * N = len(data) - * for i from 0 <= i < N: - */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_73), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":315 - * - * logger.info(" Computing inverted indexes...") - * N = len(data) # <<<<<<<<<<<<<< - * for i from 0 <= i < N: - * sa_word_id = data.arr[i] - */ - __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_data)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_N = __pyx_t_2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":316 - * logger.info(" Computing inverted indexes...") - * N = len(data) - * for i from 0 <= i < N: # <<<<<<<<<<<<<< - * sa_word_id = data.arr[i] - * if sa_word_id == 1: - */ - __pyx_t_13 = __pyx_v_N; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_13; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":317 - * N = len(data) - * for i from 0 <= i < N: - * sa_word_id = data.arr[i] # <<<<<<<<<<<<<< - * if sa_word_id == 1: - * queue._append(-1) - */ - __pyx_v_sa_word_id = (__pyx_v_data->arr[__pyx_v_i]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":318 - * for i from 0 <= i < N: - * sa_word_id = data.arr[i] - * if sa_word_id == 1: # <<<<<<<<<<<<<< - * queue._append(-1) - * else: - */ - __pyx_t_11 = (__pyx_v_sa_word_id == 1); - if (__pyx_t_11) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":319 - * sa_word_id = data.arr[i] - * if sa_word_id == 1: - * queue._append(-1) # <<<<<<<<<<<<<< - * else: - * for l from 1 <= l <= max_pattern_len: - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_queue->__pyx_vtab)->_append(__pyx_v_queue, -1); - goto __pyx_L11; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":321 - * queue._append(-1) - * else: - * for l from 1 <= l <= max_pattern_len: # <<<<<<<<<<<<<< - * node = frequent_patterns._contains(data.arr+i, l) - * if node == NULL: - */ - __pyx_t_16 = __pyx_v_max_pattern_len; - for (__pyx_v_l = 1; __pyx_v_l <= __pyx_t_16; __pyx_v_l++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":322 - * else: - * for l from 1 <= l <= max_pattern_len: - * node = frequent_patterns._contains(data.arr+i, l) # <<<<<<<<<<<<<< - * if node == NULL: - * break - */ - __pyx_v_node = ((struct __pyx_vtabstruct_8_cdec_sa_TrieMap *)__pyx_v_frequent_patterns->__pyx_vtab)->_contains(__pyx_v_frequent_patterns, (__pyx_v_data->arr + __pyx_v_i), __pyx_v_l); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":323 - * for l from 1 <= l <= max_pattern_len: - * node = frequent_patterns._contains(data.arr+i, l) - * if node == NULL: # <<<<<<<<<<<<<< - * break - * queue._append(i) - */ - __pyx_t_11 = (__pyx_v_node == NULL); - if (__pyx_t_11) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":324 - * node = frequent_patterns._contains(data.arr+i, l) - * if node == NULL: - * break # <<<<<<<<<<<<<< - * queue._append(i) - * queue._append(l) - */ - goto __pyx_L13_break; - goto __pyx_L14; - } - __pyx_L14:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":325 - * if node == NULL: - * break - * queue._append(i) # <<<<<<<<<<<<<< - * queue._append(l) - * trie_node_data_append(node, i) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_queue->__pyx_vtab)->_append(__pyx_v_queue, __pyx_v_i); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":326 - * break - * queue._append(i) - * queue._append(l) # <<<<<<<<<<<<<< - * trie_node_data_append(node, i) - * - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_queue->__pyx_vtab)->_append(__pyx_v_queue, __pyx_v_l); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":327 - * queue._append(i) - * queue._append(l) - * trie_node_data_append(node, i) # <<<<<<<<<<<<<< - * - * logger.info(" Computing collocations...") - */ - __pyx_t_3 = __pyx_f_8_cdec_sa_trie_node_data_append(__pyx_v_node, __pyx_v_i); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __pyx_L13_break:; - } - __pyx_L11:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":329 - * trie_node_data_append(node, i) - * - * logger.info(" Computing collocations...") # <<<<<<<<<<<<<< - * N = len(queue) - * ptr1 = 0 - */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_75), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":330 - * - * logger.info(" Computing collocations...") - * N = len(queue) # <<<<<<<<<<<<<< - * ptr1 = 0 - * sent_count = 0 - */ - __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_queue)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_N = __pyx_t_2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":331 - * logger.info(" Computing collocations...") - * N = len(queue) - * ptr1 = 0 # <<<<<<<<<<<<<< - * sent_count = 0 - * while ptr1 < N: # main loop - */ - __pyx_v_ptr1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":332 - * N = len(queue) - * ptr1 = 0 - * sent_count = 0 # <<<<<<<<<<<<<< - * while ptr1 < N: # main loop - * i1 = queue.arr[ptr1] - */ - __pyx_v_sent_count = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":333 - * ptr1 = 0 - * sent_count = 0 - * while ptr1 < N: # main loop # <<<<<<<<<<<<<< - * i1 = queue.arr[ptr1] - * if i1 > -1: - */ - while (1) { - __pyx_t_11 = (__pyx_v_ptr1 < __pyx_v_N); - if (!__pyx_t_11) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":334 - * sent_count = 0 - * while ptr1 < N: # main loop - * i1 = queue.arr[ptr1] # <<<<<<<<<<<<<< - * if i1 > -1: - * l1 = queue.arr[ptr1+1] - */ - __pyx_v_i1 = (__pyx_v_queue->arr[__pyx_v_ptr1]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":335 - * while ptr1 < N: # main loop - * i1 = queue.arr[ptr1] - * if i1 > -1: # <<<<<<<<<<<<<< - * l1 = queue.arr[ptr1+1] - * ptr2 = ptr1 + 2 - */ - __pyx_t_11 = (__pyx_v_i1 > -1); - if (__pyx_t_11) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":336 - * i1 = queue.arr[ptr1] - * if i1 > -1: - * l1 = queue.arr[ptr1+1] # <<<<<<<<<<<<<< - * ptr2 = ptr1 + 2 - * while ptr2 < N: - */ - __pyx_v_l1 = (__pyx_v_queue->arr[(__pyx_v_ptr1 + 1)]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":337 - * if i1 > -1: - * l1 = queue.arr[ptr1+1] - * ptr2 = ptr1 + 2 # <<<<<<<<<<<<<< - * while ptr2 < N: - * i2 = queue.arr[ptr2] - */ - __pyx_v_ptr2 = (__pyx_v_ptr1 + 2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":338 - * l1 = queue.arr[ptr1+1] - * ptr2 = ptr1 + 2 - * while ptr2 < N: # <<<<<<<<<<<<<< - * i2 = queue.arr[ptr2] - * if i2 == -1 or i2 - i1 >= self.train_max_initial_size: - */ - while (1) { - __pyx_t_11 = (__pyx_v_ptr2 < __pyx_v_N); - if (!__pyx_t_11) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":339 - * ptr2 = ptr1 + 2 - * while ptr2 < N: - * i2 = queue.arr[ptr2] # <<<<<<<<<<<<<< - * if i2 == -1 or i2 - i1 >= self.train_max_initial_size: - * break - */ - __pyx_v_i2 = (__pyx_v_queue->arr[__pyx_v_ptr2]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":340 - * while ptr2 < N: - * i2 = queue.arr[ptr2] - * if i2 == -1 or i2 - i1 >= self.train_max_initial_size: # <<<<<<<<<<<<<< - * break - * l2 = queue.arr[ptr2+1] - */ - __pyx_t_11 = (__pyx_v_i2 == -1); - if (!__pyx_t_11) { - __pyx_t_17 = ((__pyx_v_i2 - __pyx_v_i1) >= __pyx_v_self->train_max_initial_size); - __pyx_t_18 = __pyx_t_17; - } else { - __pyx_t_18 = __pyx_t_11; - } - if (__pyx_t_18) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":341 - * i2 = queue.arr[ptr2] - * if i2 == -1 or i2 - i1 >= self.train_max_initial_size: - * break # <<<<<<<<<<<<<< - * l2 = queue.arr[ptr2+1] - * if (i2 - i1 - l1 >= self.train_min_gap_size and - */ - goto __pyx_L19_break; - goto __pyx_L20; - } - __pyx_L20:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":342 - * if i2 == -1 or i2 - i1 >= self.train_max_initial_size: - * break - * l2 = queue.arr[ptr2+1] # <<<<<<<<<<<<<< - * if (i2 - i1 - l1 >= self.train_min_gap_size and - * i2 + l2 - i1 <= self.train_max_initial_size and - */ - __pyx_v_l2 = (__pyx_v_queue->arr[(__pyx_v_ptr2 + 1)]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":343 - * break - * l2 = queue.arr[ptr2+1] - * if (i2 - i1 - l1 >= self.train_min_gap_size and # <<<<<<<<<<<<<< - * i2 + l2 - i1 <= self.train_max_initial_size and - * l1+l2+1 <= self.max_length): - */ - __pyx_t_18 = (((__pyx_v_i2 - __pyx_v_i1) - __pyx_v_l1) >= __pyx_v_self->train_min_gap_size); - if (__pyx_t_18) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":344 - * l2 = queue.arr[ptr2+1] - * if (i2 - i1 - l1 >= self.train_min_gap_size and - * i2 + l2 - i1 <= self.train_max_initial_size and # <<<<<<<<<<<<<< - * l1+l2+1 <= self.max_length): - * node = collocations._insert(data.arr+i1, l1) - */ - __pyx_t_11 = (((__pyx_v_i2 + __pyx_v_l2) - __pyx_v_i1) <= __pyx_v_self->train_max_initial_size); - if (__pyx_t_11) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":345 - * if (i2 - i1 - l1 >= self.train_min_gap_size and - * i2 + l2 - i1 <= self.train_max_initial_size and - * l1+l2+1 <= self.max_length): # <<<<<<<<<<<<<< - * node = collocations._insert(data.arr+i1, l1) - * node = trie_insert(node, -1) - */ - __pyx_t_17 = (((__pyx_v_l1 + __pyx_v_l2) + 1) <= __pyx_v_self->max_length); - __pyx_t_19 = __pyx_t_17; - } else { - __pyx_t_19 = __pyx_t_11; - } - __pyx_t_11 = __pyx_t_19; - } else { - __pyx_t_11 = __pyx_t_18; - } - if (__pyx_t_11) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":346 - * i2 + l2 - i1 <= self.train_max_initial_size and - * l1+l2+1 <= self.max_length): - * node = collocations._insert(data.arr+i1, l1) # <<<<<<<<<<<<<< - * node = trie_insert(node, -1) - * for i from i2 <= i < i2+l2: - */ - __pyx_v_node = ((struct __pyx_vtabstruct_8_cdec_sa_TrieMap *)__pyx_v_collocations->__pyx_vtab)->_insert(__pyx_v_collocations, (__pyx_v_data->arr + __pyx_v_i1), __pyx_v_l1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":347 - * l1+l2+1 <= self.max_length): - * node = collocations._insert(data.arr+i1, l1) - * node = trie_insert(node, -1) # <<<<<<<<<<<<<< - * for i from i2 <= i < i2+l2: - * node = trie_insert(node, data.arr[i]) - */ - __pyx_v_node = __pyx_f_8_cdec_sa_trie_insert(__pyx_v_node, -1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":348 - * node = collocations._insert(data.arr+i1, l1) - * node = trie_insert(node, -1) - * for i from i2 <= i < i2+l2: # <<<<<<<<<<<<<< - * node = trie_insert(node, data.arr[i]) - * trie_node_data_append(node, i1) - */ - __pyx_t_13 = (__pyx_v_i2 + __pyx_v_l2); - for (__pyx_v_i = __pyx_v_i2; __pyx_v_i < __pyx_t_13; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":349 - * node = trie_insert(node, -1) - * for i from i2 <= i < i2+l2: - * node = trie_insert(node, data.arr[i]) # <<<<<<<<<<<<<< - * trie_node_data_append(node, i1) - * trie_node_data_append(node, i2) - */ - __pyx_v_node = __pyx_f_8_cdec_sa_trie_insert(__pyx_v_node, (__pyx_v_data->arr[__pyx_v_i])); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":350 - * for i from i2 <= i < i2+l2: - * node = trie_insert(node, data.arr[i]) - * trie_node_data_append(node, i1) # <<<<<<<<<<<<<< - * trie_node_data_append(node, i2) - * if super_frequent_patterns._contains(data.arr+i2, l2) != NULL: - */ - __pyx_t_3 = __pyx_f_8_cdec_sa_trie_node_data_append(__pyx_v_node, __pyx_v_i1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":351 - * node = trie_insert(node, data.arr[i]) - * trie_node_data_append(node, i1) - * trie_node_data_append(node, i2) # <<<<<<<<<<<<<< - * if super_frequent_patterns._contains(data.arr+i2, l2) != NULL: - * if super_frequent_patterns._contains(data.arr+i1, l1) != NULL: - */ - __pyx_t_3 = __pyx_f_8_cdec_sa_trie_node_data_append(__pyx_v_node, __pyx_v_i2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":352 - * trie_node_data_append(node, i1) - * trie_node_data_append(node, i2) - * if super_frequent_patterns._contains(data.arr+i2, l2) != NULL: # <<<<<<<<<<<<<< - * if super_frequent_patterns._contains(data.arr+i1, l1) != NULL: - * is_super = 1 - */ - __pyx_t_11 = (((struct __pyx_vtabstruct_8_cdec_sa_TrieMap *)__pyx_v_super_frequent_patterns->__pyx_vtab)->_contains(__pyx_v_super_frequent_patterns, (__pyx_v_data->arr + __pyx_v_i2), __pyx_v_l2) != NULL); - if (__pyx_t_11) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":353 - * trie_node_data_append(node, i2) - * if super_frequent_patterns._contains(data.arr+i2, l2) != NULL: - * if super_frequent_patterns._contains(data.arr+i1, l1) != NULL: # <<<<<<<<<<<<<< - * is_super = 1 - * else: - */ - __pyx_t_11 = (((struct __pyx_vtabstruct_8_cdec_sa_TrieMap *)__pyx_v_super_frequent_patterns->__pyx_vtab)->_contains(__pyx_v_super_frequent_patterns, (__pyx_v_data->arr + __pyx_v_i1), __pyx_v_l1) != NULL); - if (__pyx_t_11) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":354 - * if super_frequent_patterns._contains(data.arr+i2, l2) != NULL: - * if super_frequent_patterns._contains(data.arr+i1, l1) != NULL: - * is_super = 1 # <<<<<<<<<<<<<< - * else: - * is_super = 0 - */ - __pyx_v_is_super = 1; - goto __pyx_L25; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":356 - * is_super = 1 - * else: - * is_super = 0 # <<<<<<<<<<<<<< - * ptr3 = ptr2 + 2 - * while ptr3 < N: - */ - __pyx_v_is_super = 0; - } - __pyx_L25:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":357 - * else: - * is_super = 0 - * ptr3 = ptr2 + 2 # <<<<<<<<<<<<<< - * while ptr3 < N: - * i3 = queue.arr[ptr3] - */ - __pyx_v_ptr3 = (__pyx_v_ptr2 + 2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":358 - * is_super = 0 - * ptr3 = ptr2 + 2 - * while ptr3 < N: # <<<<<<<<<<<<<< - * i3 = queue.arr[ptr3] - * if i3 == -1 or i3 - i1 >= self.train_max_initial_size: - */ - while (1) { - __pyx_t_11 = (__pyx_v_ptr3 < __pyx_v_N); - if (!__pyx_t_11) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":359 - * ptr3 = ptr2 + 2 - * while ptr3 < N: - * i3 = queue.arr[ptr3] # <<<<<<<<<<<<<< - * if i3 == -1 or i3 - i1 >= self.train_max_initial_size: - * break - */ - __pyx_v_i3 = (__pyx_v_queue->arr[__pyx_v_ptr3]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":360 - * while ptr3 < N: - * i3 = queue.arr[ptr3] - * if i3 == -1 or i3 - i1 >= self.train_max_initial_size: # <<<<<<<<<<<<<< - * break - * l3 = queue.arr[ptr3+1] - */ - __pyx_t_11 = (__pyx_v_i3 == -1); - if (!__pyx_t_11) { - __pyx_t_18 = ((__pyx_v_i3 - __pyx_v_i1) >= __pyx_v_self->train_max_initial_size); - __pyx_t_19 = __pyx_t_18; - } else { - __pyx_t_19 = __pyx_t_11; - } - if (__pyx_t_19) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":361 - * i3 = queue.arr[ptr3] - * if i3 == -1 or i3 - i1 >= self.train_max_initial_size: - * break # <<<<<<<<<<<<<< - * l3 = queue.arr[ptr3+1] - * if (i3 - i2 - l2 >= self.train_min_gap_size and - */ - goto __pyx_L27_break; - goto __pyx_L28; - } - __pyx_L28:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":362 - * if i3 == -1 or i3 - i1 >= self.train_max_initial_size: - * break - * l3 = queue.arr[ptr3+1] # <<<<<<<<<<<<<< - * if (i3 - i2 - l2 >= self.train_min_gap_size and - * i3 + l3 - i1 <= self.train_max_initial_size and - */ - __pyx_v_l3 = (__pyx_v_queue->arr[(__pyx_v_ptr3 + 1)]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":363 - * break - * l3 = queue.arr[ptr3+1] - * if (i3 - i2 - l2 >= self.train_min_gap_size and # <<<<<<<<<<<<<< - * i3 + l3 - i1 <= self.train_max_initial_size and - * l1+l2+l3+2 <= self.max_length): - */ - __pyx_t_19 = (((__pyx_v_i3 - __pyx_v_i2) - __pyx_v_l2) >= __pyx_v_self->train_min_gap_size); - if (__pyx_t_19) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":364 - * l3 = queue.arr[ptr3+1] - * if (i3 - i2 - l2 >= self.train_min_gap_size and - * i3 + l3 - i1 <= self.train_max_initial_size and # <<<<<<<<<<<<<< - * l1+l2+l3+2 <= self.max_length): - * if is_super or super_frequent_patterns._contains(data.arr+i3, l3) != NULL: - */ - __pyx_t_11 = (((__pyx_v_i3 + __pyx_v_l3) - __pyx_v_i1) <= __pyx_v_self->train_max_initial_size); - if (__pyx_t_11) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":365 - * if (i3 - i2 - l2 >= self.train_min_gap_size and - * i3 + l3 - i1 <= self.train_max_initial_size and - * l1+l2+l3+2 <= self.max_length): # <<<<<<<<<<<<<< - * if is_super or super_frequent_patterns._contains(data.arr+i3, l3) != NULL: - * node = collocations._insert(data.arr+i1, l1) - */ - __pyx_t_18 = ((((__pyx_v_l1 + __pyx_v_l2) + __pyx_v_l3) + 2) <= __pyx_v_self->max_length); - __pyx_t_17 = __pyx_t_18; - } else { - __pyx_t_17 = __pyx_t_11; - } - __pyx_t_11 = __pyx_t_17; - } else { - __pyx_t_11 = __pyx_t_19; - } - if (__pyx_t_11) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":366 - * i3 + l3 - i1 <= self.train_max_initial_size and - * l1+l2+l3+2 <= self.max_length): - * if is_super or super_frequent_patterns._contains(data.arr+i3, l3) != NULL: # <<<<<<<<<<<<<< - * node = collocations._insert(data.arr+i1, l1) - * node = trie_insert(node, -1) - */ - if (!__pyx_v_is_super) { - __pyx_t_11 = (((struct __pyx_vtabstruct_8_cdec_sa_TrieMap *)__pyx_v_super_frequent_patterns->__pyx_vtab)->_contains(__pyx_v_super_frequent_patterns, (__pyx_v_data->arr + __pyx_v_i3), __pyx_v_l3) != NULL); - __pyx_t_19 = __pyx_t_11; - } else { - __pyx_t_19 = __pyx_v_is_super; - } - if (__pyx_t_19) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":367 - * l1+l2+l3+2 <= self.max_length): - * if is_super or super_frequent_patterns._contains(data.arr+i3, l3) != NULL: - * node = collocations._insert(data.arr+i1, l1) # <<<<<<<<<<<<<< - * node = trie_insert(node, -1) - * for i from i2 <= i < i2+l2: - */ - __pyx_v_node = ((struct __pyx_vtabstruct_8_cdec_sa_TrieMap *)__pyx_v_collocations->__pyx_vtab)->_insert(__pyx_v_collocations, (__pyx_v_data->arr + __pyx_v_i1), __pyx_v_l1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":368 - * if is_super or super_frequent_patterns._contains(data.arr+i3, l3) != NULL: - * node = collocations._insert(data.arr+i1, l1) - * node = trie_insert(node, -1) # <<<<<<<<<<<<<< - * for i from i2 <= i < i2+l2: - * node = trie_insert(node, data.arr[i]) - */ - __pyx_v_node = __pyx_f_8_cdec_sa_trie_insert(__pyx_v_node, -1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":369 - * node = collocations._insert(data.arr+i1, l1) - * node = trie_insert(node, -1) - * for i from i2 <= i < i2+l2: # <<<<<<<<<<<<<< - * node = trie_insert(node, data.arr[i]) - * node = trie_insert(node, -1) - */ - __pyx_t_13 = (__pyx_v_i2 + __pyx_v_l2); - for (__pyx_v_i = __pyx_v_i2; __pyx_v_i < __pyx_t_13; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":370 - * node = trie_insert(node, -1) - * for i from i2 <= i < i2+l2: - * node = trie_insert(node, data.arr[i]) # <<<<<<<<<<<<<< - * node = trie_insert(node, -1) - * for i from i3 <= i < i3+l3: - */ - __pyx_v_node = __pyx_f_8_cdec_sa_trie_insert(__pyx_v_node, (__pyx_v_data->arr[__pyx_v_i])); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":371 - * for i from i2 <= i < i2+l2: - * node = trie_insert(node, data.arr[i]) - * node = trie_insert(node, -1) # <<<<<<<<<<<<<< - * for i from i3 <= i < i3+l3: - * node = trie_insert(node, data.arr[i]) - */ - __pyx_v_node = __pyx_f_8_cdec_sa_trie_insert(__pyx_v_node, -1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":372 - * node = trie_insert(node, data.arr[i]) - * node = trie_insert(node, -1) - * for i from i3 <= i < i3+l3: # <<<<<<<<<<<<<< - * node = trie_insert(node, data.arr[i]) - * trie_node_data_append(node, i1) - */ - __pyx_t_13 = (__pyx_v_i3 + __pyx_v_l3); - for (__pyx_v_i = __pyx_v_i3; __pyx_v_i < __pyx_t_13; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":373 - * node = trie_insert(node, -1) - * for i from i3 <= i < i3+l3: - * node = trie_insert(node, data.arr[i]) # <<<<<<<<<<<<<< - * trie_node_data_append(node, i1) - * trie_node_data_append(node, i2) - */ - __pyx_v_node = __pyx_f_8_cdec_sa_trie_insert(__pyx_v_node, (__pyx_v_data->arr[__pyx_v_i])); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":374 - * for i from i3 <= i < i3+l3: - * node = trie_insert(node, data.arr[i]) - * trie_node_data_append(node, i1) # <<<<<<<<<<<<<< - * trie_node_data_append(node, i2) - * trie_node_data_append(node, i3) - */ - __pyx_t_3 = __pyx_f_8_cdec_sa_trie_node_data_append(__pyx_v_node, __pyx_v_i1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":375 - * node = trie_insert(node, data.arr[i]) - * trie_node_data_append(node, i1) - * trie_node_data_append(node, i2) # <<<<<<<<<<<<<< - * trie_node_data_append(node, i3) - * ptr3 = ptr3 + 2 - */ - __pyx_t_3 = __pyx_f_8_cdec_sa_trie_node_data_append(__pyx_v_node, __pyx_v_i2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":376 - * trie_node_data_append(node, i1) - * trie_node_data_append(node, i2) - * trie_node_data_append(node, i3) # <<<<<<<<<<<<<< - * ptr3 = ptr3 + 2 - * ptr2 = ptr2 + 2 - */ - __pyx_t_3 = __pyx_f_8_cdec_sa_trie_node_data_append(__pyx_v_node, __pyx_v_i3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L30; - } - __pyx_L30:; - goto __pyx_L29; - } - __pyx_L29:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":377 - * trie_node_data_append(node, i2) - * trie_node_data_append(node, i3) - * ptr3 = ptr3 + 2 # <<<<<<<<<<<<<< - * ptr2 = ptr2 + 2 - * ptr1 = ptr1 + 2 - */ - __pyx_v_ptr3 = (__pyx_v_ptr3 + 2); - } - __pyx_L27_break:; - goto __pyx_L24; - } - __pyx_L24:; - goto __pyx_L21; - } - __pyx_L21:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":378 - * trie_node_data_append(node, i3) - * ptr3 = ptr3 + 2 - * ptr2 = ptr2 + 2 # <<<<<<<<<<<<<< - * ptr1 = ptr1 + 2 - * else: - */ - __pyx_v_ptr2 = (__pyx_v_ptr2 + 2); - } - __pyx_L19_break:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":379 - * ptr3 = ptr3 + 2 - * ptr2 = ptr2 + 2 - * ptr1 = ptr1 + 2 # <<<<<<<<<<<<<< - * else: - * sent_count = sent_count + 1 - */ - __pyx_v_ptr1 = (__pyx_v_ptr1 + 2); - goto __pyx_L17; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":381 - * ptr1 = ptr1 + 2 - * else: - * sent_count = sent_count + 1 # <<<<<<<<<<<<<< - * if sent_count % 10000 == 0: - * logger.debug(" %d sentences", sent_count) - */ - __pyx_v_sent_count = (__pyx_v_sent_count + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":382 - * else: - * sent_count = sent_count + 1 - * if sent_count % 10000 == 0: # <<<<<<<<<<<<<< - * logger.debug(" %d sentences", sent_count) - * ptr1 = ptr1 + 1 - */ - __pyx_t_19 = (__Pyx_mod_long(__pyx_v_sent_count, 10000) == 0); - if (__pyx_t_19) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":383 - * sent_count = sent_count + 1 - * if sent_count % 10000 == 0: - * logger.debug(" %d sentences", sent_count) # <<<<<<<<<<<<<< - * ptr1 = ptr1 + 1 - * - */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__debug); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyInt_FromLong(__pyx_v_sent_count); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_76)); - PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_kp_s_76)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_76)); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L35; - } - __pyx_L35:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":384 - * if sent_count % 10000 == 0: - * logger.debug(" %d sentences", sent_count) - * ptr1 = ptr1 + 1 # <<<<<<<<<<<<<< - * - * self.precomputed_collocations = collocations.toMap(False) - */ - __pyx_v_ptr1 = (__pyx_v_ptr1 + 1); - } - __pyx_L17:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":386 - * ptr1 = ptr1 + 1 - * - * self.precomputed_collocations = collocations.toMap(False) # <<<<<<<<<<<<<< - * self.precomputed_index = frequent_patterns.toMap(True) - * - */ - __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_collocations), __pyx_n_s__toMap); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_8 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_GIVEREF(__pyx_t_8); - __Pyx_GOTREF(__pyx_v_self->precomputed_collocations); - __Pyx_DECREF(__pyx_v_self->precomputed_collocations); - __pyx_v_self->precomputed_collocations = __pyx_t_8; - __pyx_t_8 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":387 - * - * self.precomputed_collocations = collocations.toMap(False) - * self.precomputed_index = frequent_patterns.toMap(True) # <<<<<<<<<<<<<< - * - * x = 0 - */ - __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_v_frequent_patterns), __pyx_n_s__toMap); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->precomputed_index); - __Pyx_DECREF(__pyx_v_self->precomputed_index); - __pyx_v_self->precomputed_index = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":389 - * self.precomputed_index = frequent_patterns.toMap(True) - * - * x = 0 # <<<<<<<<<<<<<< - * for pattern1 in J_set: - * for pattern2 in J_set: - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_v_x = __pyx_int_0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":390 - * - * x = 0 - * for pattern1 in J_set: # <<<<<<<<<<<<<< - * for pattern2 in J_set: - * if len(pattern1) + len(pattern2) + 1 < self.max_length: - */ - __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_J_set)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; - for (;;) { - { - __pyx_t_3 = __pyx_t_4(__pyx_t_1); - if (unlikely(!__pyx_t_3)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF(__pyx_v_pattern1); - __pyx_v_pattern1 = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":391 - * x = 0 - * for pattern1 in J_set: - * for pattern2 in J_set: # <<<<<<<<<<<<<< - * if len(pattern1) + len(pattern2) + 1 < self.max_length: - * combined_pattern = pattern1 + (-1,) + pattern2 - */ - __pyx_t_3 = PyObject_GetIter(((PyObject *)__pyx_v_J_set)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_20 = Py_TYPE(__pyx_t_3)->tp_iternext; - for (;;) { - { - __pyx_t_8 = __pyx_t_20(__pyx_t_3); - if (unlikely(!__pyx_t_8)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_8); - } - __Pyx_XDECREF(__pyx_v_pattern2); - __pyx_v_pattern2 = __pyx_t_8; - __pyx_t_8 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":392 - * for pattern1 in J_set: - * for pattern2 in J_set: - * if len(pattern1) + len(pattern2) + 1 < self.max_length: # <<<<<<<<<<<<<< - * combined_pattern = pattern1 + (-1,) + pattern2 - * J2_set.add(combined_pattern) - */ - __pyx_t_2 = PyObject_Length(__pyx_v_pattern1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_14 = PyObject_Length(__pyx_v_pattern2); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_19 = (((__pyx_t_2 + __pyx_t_14) + 1) < __pyx_v_self->max_length); - if (__pyx_t_19) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":393 - * for pattern2 in J_set: - * if len(pattern1) + len(pattern2) + 1 < self.max_length: - * combined_pattern = pattern1 + (-1,) + pattern2 # <<<<<<<<<<<<<< - * J2_set.add(combined_pattern) - * - */ - __pyx_t_8 = PyNumber_Add(__pyx_v_pattern1, ((PyObject *)__pyx_k_tuple_77)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = PyNumber_Add(__pyx_t_8, __pyx_v_pattern2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_XDECREF(__pyx_v_combined_pattern); - __pyx_v_combined_pattern = __pyx_t_7; - __pyx_t_7 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":394 - * if len(pattern1) + len(pattern2) + 1 < self.max_length: - * combined_pattern = pattern1 + (-1,) + pattern2 - * J2_set.add(combined_pattern) # <<<<<<<<<<<<<< - * - * for pattern1 in I_set: - */ - __pyx_t_15 = PySet_Add(__pyx_v_J2_set, __pyx_v_combined_pattern); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 394; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L40; - } - __pyx_L40:; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":396 - * J2_set.add(combined_pattern) - * - * for pattern1 in I_set: # <<<<<<<<<<<<<< - * for pattern2 in I_set: - * x = x+1 - */ - __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_I_set)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; - for (;;) { - { - __pyx_t_3 = __pyx_t_4(__pyx_t_1); - if (unlikely(!__pyx_t_3)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF(__pyx_v_pattern1); - __pyx_v_pattern1 = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":397 - * - * for pattern1 in I_set: - * for pattern2 in I_set: # <<<<<<<<<<<<<< - * x = x+1 - * if len(pattern1) + len(pattern2) + 1 <= self.max_length: - */ - __pyx_t_3 = PyObject_GetIter(((PyObject *)__pyx_v_I_set)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_20 = Py_TYPE(__pyx_t_3)->tp_iternext; - for (;;) { - { - __pyx_t_7 = __pyx_t_20(__pyx_t_3); - if (unlikely(!__pyx_t_7)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_7); - } - __Pyx_XDECREF(__pyx_v_pattern2); - __pyx_v_pattern2 = __pyx_t_7; - __pyx_t_7 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":398 - * for pattern1 in I_set: - * for pattern2 in I_set: - * x = x+1 # <<<<<<<<<<<<<< - * if len(pattern1) + len(pattern2) + 1 <= self.max_length: - * combined_pattern = pattern1 + (-1,) + pattern2 - */ - __pyx_t_7 = PyNumber_Add(__pyx_v_x, __pyx_int_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_v_x); - __pyx_v_x = __pyx_t_7; - __pyx_t_7 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":399 - * for pattern2 in I_set: - * x = x+1 - * if len(pattern1) + len(pattern2) + 1 <= self.max_length: # <<<<<<<<<<<<<< - * combined_pattern = pattern1 + (-1,) + pattern2 - * IJ_set.add(combined_pattern) - */ - __pyx_t_14 = PyObject_Length(__pyx_v_pattern1); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyObject_Length(__pyx_v_pattern2); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_19 = (((__pyx_t_14 + __pyx_t_2) + 1) <= __pyx_v_self->max_length); - if (__pyx_t_19) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":400 - * x = x+1 - * if len(pattern1) + len(pattern2) + 1 <= self.max_length: - * combined_pattern = pattern1 + (-1,) + pattern2 # <<<<<<<<<<<<<< - * IJ_set.add(combined_pattern) - * - */ - __pyx_t_7 = PyNumber_Add(__pyx_v_pattern1, ((PyObject *)__pyx_k_tuple_78)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyNumber_Add(__pyx_t_7, __pyx_v_pattern2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_v_combined_pattern); - __pyx_v_combined_pattern = __pyx_t_8; - __pyx_t_8 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":401 - * if len(pattern1) + len(pattern2) + 1 <= self.max_length: - * combined_pattern = pattern1 + (-1,) + pattern2 - * IJ_set.add(combined_pattern) # <<<<<<<<<<<<<< - * - * for pattern1 in I_set: - */ - __pyx_t_15 = PySet_Add(__pyx_v_IJ_set, __pyx_v_combined_pattern); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L45; - } - __pyx_L45:; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":403 - * IJ_set.add(combined_pattern) - * - * for pattern1 in I_set: # <<<<<<<<<<<<<< - * for pattern2 in J2_set: - * x = x+2 - */ - __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_I_set)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; - for (;;) { - { - __pyx_t_3 = __pyx_t_4(__pyx_t_1); - if (unlikely(!__pyx_t_3)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF(__pyx_v_pattern1); - __pyx_v_pattern1 = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":404 - * - * for pattern1 in I_set: - * for pattern2 in J2_set: # <<<<<<<<<<<<<< - * x = x+2 - * if len(pattern1) + len(pattern2) + 1<= self.max_length: - */ - __pyx_t_3 = PyObject_GetIter(((PyObject *)__pyx_v_J2_set)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_20 = Py_TYPE(__pyx_t_3)->tp_iternext; - for (;;) { - { - __pyx_t_8 = __pyx_t_20(__pyx_t_3); - if (unlikely(!__pyx_t_8)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_8); - } - __Pyx_XDECREF(__pyx_v_pattern2); - __pyx_v_pattern2 = __pyx_t_8; - __pyx_t_8 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":405 - * for pattern1 in I_set: - * for pattern2 in J2_set: - * x = x+2 # <<<<<<<<<<<<<< - * if len(pattern1) + len(pattern2) + 1<= self.max_length: - * combined_pattern = pattern1 + (-1,) + pattern2 - */ - __pyx_t_8 = PyNumber_Add(__pyx_v_x, __pyx_int_2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_v_x); - __pyx_v_x = __pyx_t_8; - __pyx_t_8 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":406 - * for pattern2 in J2_set: - * x = x+2 - * if len(pattern1) + len(pattern2) + 1<= self.max_length: # <<<<<<<<<<<<<< - * combined_pattern = pattern1 + (-1,) + pattern2 - * IJ_set.add(combined_pattern) - */ - __pyx_t_2 = PyObject_Length(__pyx_v_pattern1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_14 = PyObject_Length(__pyx_v_pattern2); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_19 = (((__pyx_t_2 + __pyx_t_14) + 1) <= __pyx_v_self->max_length); - if (__pyx_t_19) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":407 - * x = x+2 - * if len(pattern1) + len(pattern2) + 1<= self.max_length: - * combined_pattern = pattern1 + (-1,) + pattern2 # <<<<<<<<<<<<<< - * IJ_set.add(combined_pattern) - * combined_pattern = pattern2 + (-1,) + pattern1 - */ - __pyx_t_8 = PyNumber_Add(__pyx_v_pattern1, ((PyObject *)__pyx_k_tuple_79)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = PyNumber_Add(__pyx_t_8, __pyx_v_pattern2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_XDECREF(__pyx_v_combined_pattern); - __pyx_v_combined_pattern = __pyx_t_7; - __pyx_t_7 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":408 - * if len(pattern1) + len(pattern2) + 1<= self.max_length: - * combined_pattern = pattern1 + (-1,) + pattern2 - * IJ_set.add(combined_pattern) # <<<<<<<<<<<<<< - * combined_pattern = pattern2 + (-1,) + pattern1 - * IJ_set.add(combined_pattern) - */ - __pyx_t_15 = PySet_Add(__pyx_v_IJ_set, __pyx_v_combined_pattern); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":409 - * combined_pattern = pattern1 + (-1,) + pattern2 - * IJ_set.add(combined_pattern) - * combined_pattern = pattern2 + (-1,) + pattern1 # <<<<<<<<<<<<<< - * IJ_set.add(combined_pattern) - * - */ - __pyx_t_7 = PyNumber_Add(__pyx_v_pattern2, ((PyObject *)__pyx_k_tuple_80)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyNumber_Add(__pyx_t_7, __pyx_v_pattern1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_v_combined_pattern); - __pyx_v_combined_pattern = __pyx_t_8; - __pyx_t_8 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":410 - * IJ_set.add(combined_pattern) - * combined_pattern = pattern2 + (-1,) + pattern1 - * IJ_set.add(combined_pattern) # <<<<<<<<<<<<<< - * - * N = len(pattern_rank) - */ - __pyx_t_15 = PySet_Add(__pyx_v_IJ_set, __pyx_v_combined_pattern); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L50; - } - __pyx_L50:; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":412 - * IJ_set.add(combined_pattern) - * - * N = len(pattern_rank) # <<<<<<<<<<<<<< - * cost_by_rank = IntList(initial_len=N) - * count_by_rank = IntList(initial_len=N) - */ - __pyx_t_14 = PyDict_Size(((PyObject *)__pyx_v_pattern_rank)); - __pyx_v_N = __pyx_t_14; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":413 - * - * N = len(pattern_rank) - * cost_by_rank = IntList(initial_len=N) # <<<<<<<<<<<<<< - * count_by_rank = IntList(initial_len=N) - * for pattern, arr in self.precomputed_collocations.iteritems(): - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_v_cost_by_rank = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":414 - * N = len(pattern_rank) - * cost_by_rank = IntList(initial_len=N) - * count_by_rank = IntList(initial_len=N) # <<<<<<<<<<<<<< - * for pattern, arr in self.precomputed_collocations.iteritems(): - * if pattern not in IJ_set: - */ - __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_v_count_by_rank = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":415 - * cost_by_rank = IntList(initial_len=N) - * count_by_rank = IntList(initial_len=N) - * for pattern, arr in self.precomputed_collocations.iteritems(): # <<<<<<<<<<<<<< - * if pattern not in IJ_set: - * s = "" - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_self->precomputed_collocations, __pyx_n_s__iteritems); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_14 = 0; - __pyx_t_4 = NULL; - } else { - __pyx_t_14 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_14); __Pyx_INCREF(__pyx_t_3); __pyx_t_14++; - } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_14); __Pyx_INCREF(__pyx_t_3); __pyx_t_14++; - } else { - __pyx_t_3 = __pyx_t_4(__pyx_t_1); - if (unlikely(!__pyx_t_3)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { - PyObject* sequence = __pyx_t_3; - if (likely(PyTuple_CheckExact(sequence))) { - 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[11]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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[11]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_8 = PyList_GET_ITEM(sequence, 0); - __pyx_t_7 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_5 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_10 = Py_TYPE(__pyx_t_5)->tp_iternext; - index = 0; __pyx_t_8 = __pyx_t_10(__pyx_t_5); if (unlikely(!__pyx_t_8)) goto __pyx_L53_unpacking_failed; - __Pyx_GOTREF(__pyx_t_8); - index = 1; __pyx_t_7 = __pyx_t_10(__pyx_t_5); if (unlikely(!__pyx_t_7)) goto __pyx_L53_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_5), 2) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L54_unpacking_done; - __pyx_L53_unpacking_failed:; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[11]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L54_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_pattern); - __pyx_v_pattern = __pyx_t_8; - __pyx_t_8 = 0; - __Pyx_XDECREF(__pyx_v_arr); - __pyx_v_arr = __pyx_t_7; - __pyx_t_7 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":416 - * count_by_rank = IntList(initial_len=N) - * for pattern, arr in self.precomputed_collocations.iteritems(): - * if pattern not in IJ_set: # <<<<<<<<<<<<<< - * s = "" - * for word_id in pattern: - */ - __pyx_t_19 = (__Pyx_NegateNonNeg(PySequence_Contains(((PyObject *)__pyx_v_IJ_set), __pyx_v_pattern))); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_19) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":417 - * for pattern, arr in self.precomputed_collocations.iteritems(): - * if pattern not in IJ_set: - * s = "" # <<<<<<<<<<<<<< - * for word_id in pattern: - * if word_id == -1: - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_42)); - __Pyx_XDECREF(__pyx_v_s); - __pyx_v_s = ((PyObject *)__pyx_kp_s_42); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":418 - * if pattern not in IJ_set: - * s = "" - * for word_id in pattern: # <<<<<<<<<<<<<< - * if word_id == -1: - * s = s + "X " - */ - if (PyList_CheckExact(__pyx_v_pattern) || PyTuple_CheckExact(__pyx_v_pattern)) { - __pyx_t_3 = __pyx_v_pattern; __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = 0; - __pyx_t_20 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_pattern); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_20 = Py_TYPE(__pyx_t_3)->tp_iternext; - } - for (;;) { - if (!__pyx_t_20 && PyList_CheckExact(__pyx_t_3)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_3)) break; - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_7); __pyx_t_2++; - } else if (!__pyx_t_20 && PyTuple_CheckExact(__pyx_t_3)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_3)) break; - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_7); __pyx_t_2++; - } else { - __pyx_t_7 = __pyx_t_20(__pyx_t_3); - if (unlikely(!__pyx_t_7)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_7); - } - __Pyx_XDECREF(__pyx_v_word_id); - __pyx_v_word_id = __pyx_t_7; - __pyx_t_7 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":419 - * s = "" - * for word_id in pattern: - * if word_id == -1: # <<<<<<<<<<<<<< - * s = s + "X " - * else: - */ - __pyx_t_7 = PyObject_RichCompare(__pyx_v_word_id, __pyx_int_neg_1, Py_EQ); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 419; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 419; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (__pyx_t_19) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":420 - * for word_id in pattern: - * if word_id == -1: - * s = s + "X " # <<<<<<<<<<<<<< - * else: - * s = s + darray.id2word[word_id] + " " - */ - __pyx_t_7 = PyNumber_Add(__pyx_v_s, ((PyObject *)__pyx_kp_s_81)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_v_s); - __pyx_v_s = __pyx_t_7; - __pyx_t_7 = 0; - goto __pyx_L58; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":422 - * s = s + "X " - * else: - * s = s + darray.id2word[word_id] + " " # <<<<<<<<<<<<<< - * logger.warn("ERROR: unexpected pattern %s in set of precomputed collocations", s) - * else: - */ - __pyx_t_7 = PyObject_GetItem(__pyx_v_darray->id2word, __pyx_v_word_id); if (!__pyx_t_7) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyNumber_Add(__pyx_v_s, __pyx_t_7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Add(__pyx_t_8, ((PyObject *)__pyx_kp_s_64)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_v_s); - __pyx_v_s = __pyx_t_7; - __pyx_t_7 = 0; - } - __pyx_L58:; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":423 - * else: - * s = s + darray.id2word[word_id] + " " - * logger.warn("ERROR: unexpected pattern %s in set of precomputed collocations", s) # <<<<<<<<<<<<<< - * else: - * chunk = () - */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__warn); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_82)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_82)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_82)); - __Pyx_INCREF(__pyx_v_s); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_s); - __Pyx_GIVEREF(__pyx_v_s); - __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - goto __pyx_L55; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":425 - * logger.warn("ERROR: unexpected pattern %s in set of precomputed collocations", s) - * else: - * chunk = () # <<<<<<<<<<<<<< - * max_rank = 0 - * arity = 0 - */ - __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); - __Pyx_XDECREF(((PyObject *)__pyx_v_chunk)); - __pyx_v_chunk = __pyx_empty_tuple; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":426 - * else: - * chunk = () - * max_rank = 0 # <<<<<<<<<<<<<< - * arity = 0 - * for word_id in pattern: - */ - __pyx_v_max_rank = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":427 - * chunk = () - * max_rank = 0 - * arity = 0 # <<<<<<<<<<<<<< - * for word_id in pattern: - * if word_id == -1: - */ - __Pyx_INCREF(__pyx_int_0); - __Pyx_XDECREF(__pyx_v_arity); - __pyx_v_arity = __pyx_int_0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":428 - * max_rank = 0 - * arity = 0 - * for word_id in pattern: # <<<<<<<<<<<<<< - * if word_id == -1: - * max_rank = max(max_rank, pattern_rank[chunk]) - */ - if (PyList_CheckExact(__pyx_v_pattern) || PyTuple_CheckExact(__pyx_v_pattern)) { - __pyx_t_8 = __pyx_v_pattern; __Pyx_INCREF(__pyx_t_8); __pyx_t_2 = 0; - __pyx_t_20 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_pattern); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_20 = Py_TYPE(__pyx_t_8)->tp_iternext; - } - for (;;) { - if (!__pyx_t_20 && PyList_CheckExact(__pyx_t_8)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_8)) break; - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; - } else if (!__pyx_t_20 && PyTuple_CheckExact(__pyx_t_8)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_8)) break; - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; - } else { - __pyx_t_3 = __pyx_t_20(__pyx_t_8); - if (unlikely(!__pyx_t_3)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF(__pyx_v_word_id); - __pyx_v_word_id = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":429 - * arity = 0 - * for word_id in pattern: - * if word_id == -1: # <<<<<<<<<<<<<< - * max_rank = max(max_rank, pattern_rank[chunk]) - * arity = arity + 1 - */ - __pyx_t_3 = PyObject_RichCompare(__pyx_v_word_id, __pyx_int_neg_1, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_19) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":430 - * for word_id in pattern: - * if word_id == -1: - * max_rank = max(max_rank, pattern_rank[chunk]) # <<<<<<<<<<<<<< - * arity = arity + 1 - * chunk = () - */ - __pyx_t_3 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_pattern_rank), ((PyObject *)__pyx_v_chunk)); if (!__pyx_t_3) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_13 = __pyx_v_max_rank; - __pyx_t_5 = PyInt_FromLong(__pyx_t_13); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PyObject_RichCompare(__pyx_t_3, __pyx_t_5, Py_GT); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (__pyx_t_19) { - __Pyx_INCREF(__pyx_t_3); - __pyx_t_7 = __pyx_t_3; - } else { - __pyx_t_6 = PyInt_FromLong(__pyx_t_13); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __pyx_t_6; - __pyx_t_6 = 0; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_v_max_rank = __pyx_t_13; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":431 - * if word_id == -1: - * max_rank = max(max_rank, pattern_rank[chunk]) - * arity = arity + 1 # <<<<<<<<<<<<<< - * chunk = () - * else: - */ - __pyx_t_7 = PyNumber_Add(__pyx_v_arity, __pyx_int_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_v_arity); - __pyx_v_arity = __pyx_t_7; - __pyx_t_7 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":432 - * max_rank = max(max_rank, pattern_rank[chunk]) - * arity = arity + 1 - * chunk = () # <<<<<<<<<<<<<< - * else: - * chunk = chunk + (word_id,) - */ - __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); - __Pyx_DECREF(((PyObject *)__pyx_v_chunk)); - __pyx_v_chunk = __pyx_empty_tuple; - goto __pyx_L61; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":434 - * chunk = () - * else: - * chunk = chunk + (word_id,) # <<<<<<<<<<<<<< - * max_rank = max(max_rank, pattern_rank[chunk]) - * cost_by_rank.arr[max_rank] = cost_by_rank.arr[max_rank] + (4*len(arr)) - */ - __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(__pyx_v_word_id); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_word_id); - __Pyx_GIVEREF(__pyx_v_word_id); - __pyx_t_3 = PyNumber_Add(((PyObject *)__pyx_v_chunk), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_chunk)); - __pyx_v_chunk = __pyx_t_3; - __pyx_t_3 = 0; - } - __pyx_L61:; - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":435 - * else: - * chunk = chunk + (word_id,) - * max_rank = max(max_rank, pattern_rank[chunk]) # <<<<<<<<<<<<<< - * cost_by_rank.arr[max_rank] = cost_by_rank.arr[max_rank] + (4*len(arr)) - * count_by_rank.arr[max_rank] = count_by_rank.arr[max_rank] + (len(arr)/(arity+1)) - */ - __pyx_t_8 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_pattern_rank), ((PyObject *)__pyx_v_chunk)); if (!__pyx_t_8) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_13 = __pyx_v_max_rank; - __pyx_t_7 = PyInt_FromLong(__pyx_t_13); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = PyObject_RichCompare(__pyx_t_8, __pyx_t_7, Py_GT); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (__pyx_t_19) { - __Pyx_INCREF(__pyx_t_8); - __pyx_t_3 = __pyx_t_8; - } else { - __pyx_t_6 = PyInt_FromLong(__pyx_t_13); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_3 = __pyx_t_6; - __pyx_t_6 = 0; - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_max_rank = __pyx_t_13; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":436 - * chunk = chunk + (word_id,) - * max_rank = max(max_rank, pattern_rank[chunk]) - * cost_by_rank.arr[max_rank] = cost_by_rank.arr[max_rank] + (4*len(arr)) # <<<<<<<<<<<<<< - * count_by_rank.arr[max_rank] = count_by_rank.arr[max_rank] + (len(arr)/(arity+1)) - * - */ - __pyx_t_2 = PyObject_Length(__pyx_v_arr); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - (__pyx_v_cost_by_rank->arr[__pyx_v_max_rank]) = ((__pyx_v_cost_by_rank->arr[__pyx_v_max_rank]) + (4 * __pyx_t_2)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":437 - * max_rank = max(max_rank, pattern_rank[chunk]) - * cost_by_rank.arr[max_rank] = cost_by_rank.arr[max_rank] + (4*len(arr)) - * count_by_rank.arr[max_rank] = count_by_rank.arr[max_rank] + (len(arr)/(arity+1)) # <<<<<<<<<<<<<< - * - * cumul_cost = 0 - */ - __pyx_t_3 = PyInt_FromLong((__pyx_v_count_by_rank->arr[__pyx_v_max_rank])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_Length(__pyx_v_arr); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_8 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_6 = PyNumber_Add(__pyx_v_arity, __pyx_int_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = __Pyx_PyNumber_Divide(__pyx_t_8, __pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyNumber_Add(__pyx_t_3, __pyx_t_7); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_13 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - (__pyx_v_count_by_rank->arr[__pyx_v_max_rank]) = __pyx_t_13; - } - __pyx_L55:; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":439 - * count_by_rank.arr[max_rank] = count_by_rank.arr[max_rank] + (len(arr)/(arity+1)) - * - * cumul_cost = 0 # <<<<<<<<<<<<<< - * cumul_count = 0 - * for i from 0 <= i < N: - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_v_cumul_cost = __pyx_int_0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":440 - * - * cumul_cost = 0 - * cumul_count = 0 # <<<<<<<<<<<<<< - * for i from 0 <= i < N: - * cumul_cost = cumul_cost + cost_by_rank.arr[i] - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_v_cumul_count = __pyx_int_0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":441 - * cumul_cost = 0 - * cumul_count = 0 - * for i from 0 <= i < N: # <<<<<<<<<<<<<< - * cumul_cost = cumul_cost + cost_by_rank.arr[i] - * cumul_count = cumul_count + count_by_rank.arr[i] - */ - __pyx_t_13 = __pyx_v_N; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_13; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":442 - * cumul_count = 0 - * for i from 0 <= i < N: - * cumul_cost = cumul_cost + cost_by_rank.arr[i] # <<<<<<<<<<<<<< - * cumul_count = cumul_count + count_by_rank.arr[i] - * logger.debug("RANK %d\tCOUNT, COST: %d %d\tCUMUL: %d, %d", i, count_by_rank.arr[i], cost_by_rank.arr[i], cumul_count, cumul_cost) - */ - __pyx_t_1 = PyInt_FromLong((__pyx_v_cost_by_rank->arr[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = PyNumber_Add(__pyx_v_cumul_cost, __pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_v_cumul_cost); - __pyx_v_cumul_cost = __pyx_t_6; - __pyx_t_6 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":443 - * for i from 0 <= i < N: - * cumul_cost = cumul_cost + cost_by_rank.arr[i] - * cumul_count = cumul_count + count_by_rank.arr[i] # <<<<<<<<<<<<<< - * logger.debug("RANK %d\tCOUNT, COST: %d %d\tCUMUL: %d, %d", i, count_by_rank.arr[i], cost_by_rank.arr[i], cumul_count, cumul_cost) - * - */ - __pyx_t_6 = PyInt_FromLong((__pyx_v_count_by_rank->arr[__pyx_v_i])); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_1 = PyNumber_Add(__pyx_v_cumul_count, __pyx_t_6); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_v_cumul_count); - __pyx_v_cumul_count = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":444 - * cumul_cost = cumul_cost + cost_by_rank.arr[i] - * cumul_count = cumul_count + count_by_rank.arr[i] - * logger.debug("RANK %d\tCOUNT, COST: %d %d\tCUMUL: %d, %d", i, count_by_rank.arr[i], cost_by_rank.arr[i], cumul_count, cumul_cost) # <<<<<<<<<<<<<< - * - * num_found_patterns = len(self.precomputed_collocations) - */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__debug); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = PyInt_FromLong((__pyx_v_count_by_rank->arr[__pyx_v_i])); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_3 = PyInt_FromLong((__pyx_v_cost_by_rank->arr[__pyx_v_i])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = PyTuple_New(6); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_83)); - PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_kp_s_83)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_83)); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_cumul_count); - PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_v_cumul_count); - __Pyx_GIVEREF(__pyx_v_cumul_count); - __Pyx_INCREF(__pyx_v_cumul_cost); - PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_v_cumul_cost); - __Pyx_GIVEREF(__pyx_v_cumul_cost); - __pyx_t_1 = 0; - __pyx_t_7 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":446 - * logger.debug("RANK %d\tCOUNT, COST: %d %d\tCUMUL: %d, %d", i, count_by_rank.arr[i], cost_by_rank.arr[i], cumul_count, cumul_cost) - * - * num_found_patterns = len(self.precomputed_collocations) # <<<<<<<<<<<<<< - * for pattern in IJ_set: - * if pattern not in self.precomputed_collocations: - */ - __pyx_t_3 = __pyx_v_self->precomputed_collocations; - __Pyx_INCREF(__pyx_t_3); - __pyx_t_14 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_14); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_v_num_found_patterns = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":447 - * - * num_found_patterns = len(self.precomputed_collocations) - * for pattern in IJ_set: # <<<<<<<<<<<<<< - * if pattern not in self.precomputed_collocations: - * self.precomputed_collocations[pattern] = IntList() - */ - __pyx_t_3 = PyObject_GetIter(((PyObject *)__pyx_v_IJ_set)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; - for (;;) { - { - __pyx_t_8 = __pyx_t_4(__pyx_t_3); - if (unlikely(!__pyx_t_8)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[11]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_8); - } - __Pyx_XDECREF(__pyx_v_pattern); - __pyx_v_pattern = __pyx_t_8; - __pyx_t_8 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":448 - * num_found_patterns = len(self.precomputed_collocations) - * for pattern in IJ_set: - * if pattern not in self.precomputed_collocations: # <<<<<<<<<<<<<< - * self.precomputed_collocations[pattern] = IntList() - * - */ - __pyx_t_19 = (__Pyx_NegateNonNeg(PySequence_Contains(__pyx_v_self->precomputed_collocations, __pyx_v_pattern))); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_19) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":449 - * for pattern in IJ_set: - * if pattern not in self.precomputed_collocations: - * self.precomputed_collocations[pattern] = IntList() # <<<<<<<<<<<<<< - * - * cdef float stop_time = monitor_cpu() - */ - __pyx_t_8 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - if (PyObject_SetItem(__pyx_v_self->precomputed_collocations, __pyx_v_pattern, __pyx_t_8) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - goto __pyx_L66; - } - __pyx_L66:; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":451 - * self.precomputed_collocations[pattern] = IntList() - * - * cdef float stop_time = monitor_cpu() # <<<<<<<<<<<<<< - * logger.info("Precomputed collocations for %d patterns out of %d possible (upper bound %d)", num_found_patterns, len(self.precomputed_collocations), x) - * logger.info("Precomputed inverted index for %d patterns ", len(self.precomputed_index)) - */ - __pyx_v_stop_time = __pyx_f_8_cdec_sa_monitor_cpu(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":452 - * - * cdef float stop_time = monitor_cpu() - * logger.info("Precomputed collocations for %d patterns out of %d possible (upper bound %d)", num_found_patterns, len(self.precomputed_collocations), x) # <<<<<<<<<<<<<< - * logger.info("Precomputed inverted index for %d patterns ", len(self.precomputed_index)) - * logger.info("Precomputation took %f seconds", (stop_time - start_time)) - */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __pyx_v_self->precomputed_collocations; - __Pyx_INCREF(__pyx_t_3); - __pyx_t_14 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_14); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = PyTuple_New(4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_84)); - PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_kp_s_84)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_84)); - __Pyx_INCREF(__pyx_v_num_found_patterns); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_num_found_patterns); - __Pyx_GIVEREF(__pyx_v_num_found_patterns); - PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_x); - PyTuple_SET_ITEM(__pyx_t_6, 3, __pyx_v_x); - __Pyx_GIVEREF(__pyx_v_x); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":453 - * cdef float stop_time = monitor_cpu() - * logger.info("Precomputed collocations for %d patterns out of %d possible (upper bound %d)", num_found_patterns, len(self.precomputed_collocations), x) - * logger.info("Precomputed inverted index for %d patterns ", len(self.precomputed_index)) # <<<<<<<<<<<<<< - * logger.info("Precomputation took %f seconds", (stop_time - start_time)) - */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __pyx_v_self->precomputed_index; - __Pyx_INCREF(__pyx_t_3); - __pyx_t_14 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_14); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_85)); - PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_kp_s_85)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_85)); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":454 - * logger.info("Precomputed collocations for %d patterns out of %d possible (upper bound %d)", num_found_patterns, len(self.precomputed_collocations), x) - * logger.info("Precomputed inverted index for %d patterns ", len(self.precomputed_index)) - * logger.info("Precomputation took %f seconds", (stop_time - start_time)) # <<<<<<<<<<<<<< - */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyFloat_FromDouble((__pyx_v_stop_time - __pyx_v_start_time)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_86)); - PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_kp_s_86)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_86)); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("_cdec_sa.Precomputation.precompute", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_darray); - __Pyx_XDECREF((PyObject *)__pyx_v_data); - __Pyx_XDECREF((PyObject *)__pyx_v_queue); - __Pyx_XDECREF((PyObject *)__pyx_v_cost_by_rank); - __Pyx_XDECREF((PyObject *)__pyx_v_count_by_rank); - __Pyx_XDECREF((PyObject *)__pyx_v_frequent_patterns); - __Pyx_XDECREF((PyObject *)__pyx_v_super_frequent_patterns); - __Pyx_XDECREF((PyObject *)__pyx_v_collocations); - __Pyx_XDECREF(__pyx_v_I_set); - __Pyx_XDECREF(__pyx_v_J_set); - __Pyx_XDECREF(__pyx_v_J2_set); - __Pyx_XDECREF(__pyx_v_IJ_set); - __Pyx_XDECREF(__pyx_v_pattern_rank); - __Pyx_XDECREF(__pyx_v_rank); - __Pyx_XDECREF(__pyx_v__); - __Pyx_XDECREF(__pyx_v_phrase); - __Pyx_XDECREF(__pyx_v_x); - __Pyx_XDECREF(__pyx_v_pattern1); - __Pyx_XDECREF(__pyx_v_pattern2); - __Pyx_XDECREF(__pyx_v_combined_pattern); - __Pyx_XDECREF(__pyx_v_pattern); - __Pyx_XDECREF(__pyx_v_arr); - __Pyx_XDECREF(__pyx_v_s); - __Pyx_XDECREF(__pyx_v_word_id); - __Pyx_XDECREF(__pyx_v_chunk); - __Pyx_XDECREF(__pyx_v_arity); - __Pyx_XDECREF(__pyx_v_cumul_cost); - __Pyx_XDECREF(__pyx_v_cumul_count); - __Pyx_XDECREF(__pyx_v_num_found_patterns); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_11SuffixArray_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_11SuffixArray_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_from_binary = 0; - PyObject *__pyx_v_from_text = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__from_binary,&__pyx_n_s__from_text,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[2] = {0,0}; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":11 - * cdef IntList ha - * - * def __cinit__(self, from_binary=None, from_text=None): # <<<<<<<<<<<<<< - * self.darray = DataArray() - * self.sa = IntList() - */ - values[0] = ((PyObject *)Py_None); - values[1] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_binary); - if (value) { values[0] = value; kw_args--; } - } - case 1: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_text); - if (value) { values[1] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_from_binary = values[0]; - __pyx_v_from_text = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.SuffixArray.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray___cinit__(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), __pyx_v_from_binary, __pyx_v_from_text); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_11SuffixArray___cinit__(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text) { - int __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":12 - * - * def __cinit__(self, from_binary=None, from_text=None): - * self.darray = DataArray() # <<<<<<<<<<<<<< - * self.sa = IntList() - * self.ha = IntList() - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_DataArray)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->darray); - __Pyx_DECREF(((PyObject *)__pyx_v_self->darray)); - __pyx_v_self->darray = ((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":13 - * def __cinit__(self, from_binary=None, from_text=None): - * self.darray = DataArray() - * self.sa = IntList() # <<<<<<<<<<<<<< - * self.ha = IntList() - * if from_binary: - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->sa); - __Pyx_DECREF(((PyObject *)__pyx_v_self->sa)); - __pyx_v_self->sa = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":14 - * self.darray = DataArray() - * self.sa = IntList() - * self.ha = IntList() # <<<<<<<<<<<<<< - * if from_binary: - * self.read_binary(from_binary) - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->ha); - __Pyx_DECREF(((PyObject *)__pyx_v_self->ha)); - __pyx_v_self->ha = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":15 - * self.sa = IntList() - * self.ha = IntList() - * if from_binary: # <<<<<<<<<<<<<< - * self.read_binary(from_binary) - * elif from_text: - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_binary); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":16 - * self.ha = IntList() - * if from_binary: - * self.read_binary(from_binary) # <<<<<<<<<<<<<< - * elif from_text: - * self.read_text(from_text) - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_binary); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_from_binary); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_binary); - __Pyx_GIVEREF(__pyx_v_from_binary); - __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L3; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":17 - * if from_binary: - * self.read_binary(from_binary) - * elif from_text: # <<<<<<<<<<<<<< - * self.read_text(from_text) - * - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_text); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":18 - * self.read_binary(from_binary) - * elif from_text: - * self.read_text(from_text) # <<<<<<<<<<<<<< - * - * def __getitem__(self, i): - */ - __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_text); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_from_text); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_text); - __Pyx_GIVEREF(__pyx_v_from_text); - __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L3; - } - __pyx_L3:; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec_sa.SuffixArray.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_2__getitem__(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), ((PyObject *)__pyx_v_i)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":20 - * self.read_text(from_text) - * - * def __getitem__(self, i): # <<<<<<<<<<<<<< - * return self.sa.arr[i] - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_2__getitem__(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - Py_ssize_t __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__getitem__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":21 - * - * def __getitem__(self, i): - * return self.sa.arr[i] # <<<<<<<<<<<<<< - * - * def getSentId(self, i): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromLong((__pyx_v_self->sa->arr[__pyx_t_1])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __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_2); - __Pyx_AddTraceback("_cdec_sa.SuffixArray.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_5getSentId(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_5getSentId(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("getSentId (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_4getSentId(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), ((PyObject *)__pyx_v_i)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":23 - * return self.sa.arr[i] - * - * def getSentId(self, i): # <<<<<<<<<<<<<< - * return self.darray.getSentId(i) - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_4getSentId(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("getSentId", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":24 - * - * def getSentId(self, i): - * return self.darray.getSentId(i) # <<<<<<<<<<<<<< - * - * def getSent(self, i): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->darray), __pyx_n_s__getSentId); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_i); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_i); - __Pyx_GIVEREF(__pyx_v_i); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 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_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.SuffixArray.getSentId", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_7getSent(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_7getSent(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("getSent (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_6getSent(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), ((PyObject *)__pyx_v_i)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":26 - * return self.darray.getSentId(i) - * - * def getSent(self, i): # <<<<<<<<<<<<<< - * return self.darray.getSent(i) - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_6getSent(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("getSent", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":27 - * - * def getSent(self, i): - * return self.darray.getSent(i) # <<<<<<<<<<<<<< - * - * def getSentPos(self, loc): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->darray), __pyx_n_s__getSent); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_i); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_i); - __Pyx_GIVEREF(__pyx_v_i); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 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_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.SuffixArray.getSent", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_9getSentPos(PyObject *__pyx_v_self, PyObject *__pyx_v_loc); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_9getSentPos(PyObject *__pyx_v_self, PyObject *__pyx_v_loc) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("getSentPos (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_8getSentPos(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), ((PyObject *)__pyx_v_loc)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":29 - * return self.darray.getSent(i) - * - * def getSentPos(self, loc): # <<<<<<<<<<<<<< - * return self.darray.getSentPos(loc) - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_8getSentPos(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_loc) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("getSentPos", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":30 - * - * def getSentPos(self, loc): - * return self.darray.getSentPos(loc) # <<<<<<<<<<<<<< - * - * def read_text(self, char* filename): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->darray), __pyx_n_s__getSentPos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_loc); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_loc); - __Pyx_GIVEREF(__pyx_v_loc); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 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_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.SuffixArray.getSentPos", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_11read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static char __pyx_doc_8_cdec_sa_11SuffixArray_10read_text[] = "Constructs suffix array using the algorithm\n of Larsson & Sadahkane (1999)"; -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_11read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_text (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.SuffixArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_10read_text(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":32 - * return self.darray.getSentPos(loc) - * - * def read_text(self, char* filename): # <<<<<<<<<<<<<< - * '''Constructs suffix array using the algorithm - * of Larsson & Sadahkane (1999)''' - */ - -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_10read_text(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename) { - int __pyx_v_V; - int __pyx_v_N; - int __pyx_v_i; - int __pyx_v_j; - int __pyx_v_h; - int __pyx_v_a_i; - int __pyx_v_n; - int __pyx_v_current_run; - int __pyx_v_skip; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_isa = 0; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_word_count = 0; - float __pyx_v_sort_start_time; - float __pyx_v_start_time; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - Py_ssize_t __pyx_t_3; - int __pyx_t_4; - long __pyx_t_5; - int __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("read_text", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":38 - * cdef IntList isa, word_count - * - * self.darray = DataArray(from_text=filename, use_sent_id=True) # <<<<<<<<<<<<<< - * N = len(self.darray) - * V = len(self.darray.id2word) - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__from_text), ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__use_sent_id), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_DataArray)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 38; __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); - __Pyx_GOTREF(__pyx_v_self->darray); - __Pyx_DECREF(((PyObject *)__pyx_v_self->darray)); - __pyx_v_self->darray = ((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":39 - * - * self.darray = DataArray(from_text=filename, use_sent_id=True) - * N = len(self.darray) # <<<<<<<<<<<<<< - * V = len(self.darray.id2word) - * - */ - __pyx_t_2 = ((PyObject *)__pyx_v_self->darray); - __Pyx_INCREF(__pyx_t_2); - __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_N = __pyx_t_3; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":40 - * self.darray = DataArray(from_text=filename, use_sent_id=True) - * N = len(self.darray) - * V = len(self.darray.id2word) # <<<<<<<<<<<<<< - * - * self.sa = IntList(initial_len=N) - */ - __pyx_t_2 = __pyx_v_self->darray->id2word; - __Pyx_INCREF(__pyx_t_2); - __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_V = __pyx_t_3; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":42 - * V = len(self.darray.id2word) - * - * self.sa = IntList(initial_len=N) # <<<<<<<<<<<<<< - * self.ha = IntList(initial_len=V+1) - * - */ - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->sa); - __Pyx_DECREF(((PyObject *)__pyx_v_self->sa)); - __pyx_v_self->sa = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":43 - * - * self.sa = IntList(initial_len=N) - * self.ha = IntList(initial_len=V+1) # <<<<<<<<<<<<<< - * - * isa = IntList(initial_len=N) - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyInt_FromLong((__pyx_v_V + 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 43; __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); - __Pyx_GOTREF(__pyx_v_self->ha); - __Pyx_DECREF(((PyObject *)__pyx_v_self->ha)); - __pyx_v_self->ha = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":45 - * self.ha = IntList(initial_len=V+1) - * - * isa = IntList(initial_len=N) # <<<<<<<<<<<<<< - * word_count = IntList(initial_len=V+1) - * - */ - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_v_isa = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":46 - * - * isa = IntList(initial_len=N) - * word_count = IntList(initial_len=V+1) # <<<<<<<<<<<<<< - * - * '''Step 1: bucket sort data''' - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyInt_FromLong((__pyx_v_V + 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_v_word_count = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":49 - * - * '''Step 1: bucket sort data''' - * cdef float sort_start_time = monitor_cpu() # <<<<<<<<<<<<<< - * cdef float start_time = sort_start_time - * for i from 0 <= i < N: - */ - __pyx_v_sort_start_time = __pyx_f_8_cdec_sa_monitor_cpu(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":50 - * '''Step 1: bucket sort data''' - * cdef float sort_start_time = monitor_cpu() - * cdef float start_time = sort_start_time # <<<<<<<<<<<<<< - * for i from 0 <= i < N: - * a_i = self.darray.data.arr[i] - */ - __pyx_v_start_time = __pyx_v_sort_start_time; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":51 - * cdef float sort_start_time = monitor_cpu() - * cdef float start_time = sort_start_time - * for i from 0 <= i < N: # <<<<<<<<<<<<<< - * a_i = self.darray.data.arr[i] - * word_count.arr[a_i] = word_count.arr[a_i] + 1 - */ - __pyx_t_4 = __pyx_v_N; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":52 - * cdef float start_time = sort_start_time - * for i from 0 <= i < N: - * a_i = self.darray.data.arr[i] # <<<<<<<<<<<<<< - * word_count.arr[a_i] = word_count.arr[a_i] + 1 - * - */ - __pyx_v_a_i = (__pyx_v_self->darray->data->arr[__pyx_v_i]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":53 - * for i from 0 <= i < N: - * a_i = self.darray.data.arr[i] - * word_count.arr[a_i] = word_count.arr[a_i] + 1 # <<<<<<<<<<<<<< - * - * n = 0 - */ - (__pyx_v_word_count->arr[__pyx_v_a_i]) = ((__pyx_v_word_count->arr[__pyx_v_a_i]) + 1); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":55 - * word_count.arr[a_i] = word_count.arr[a_i] + 1 - * - * n = 0 # <<<<<<<<<<<<<< - * for i from 0 <= i < V+1: - * self.ha.arr[i] = n - */ - __pyx_v_n = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":56 - * - * n = 0 - * for i from 0 <= i < V+1: # <<<<<<<<<<<<<< - * self.ha.arr[i] = n - * n = n + word_count.arr[i] - */ - __pyx_t_5 = (__pyx_v_V + 1); - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_5; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":57 - * n = 0 - * for i from 0 <= i < V+1: - * self.ha.arr[i] = n # <<<<<<<<<<<<<< - * n = n + word_count.arr[i] - * word_count.arr[i] = 0 - */ - (__pyx_v_self->ha->arr[__pyx_v_i]) = __pyx_v_n; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":58 - * for i from 0 <= i < V+1: - * self.ha.arr[i] = n - * n = n + word_count.arr[i] # <<<<<<<<<<<<<< - * word_count.arr[i] = 0 - * - */ - __pyx_v_n = (__pyx_v_n + (__pyx_v_word_count->arr[__pyx_v_i])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":59 - * self.ha.arr[i] = n - * n = n + word_count.arr[i] - * word_count.arr[i] = 0 # <<<<<<<<<<<<<< - * - * for i from 0 <= i < N: - */ - (__pyx_v_word_count->arr[__pyx_v_i]) = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":61 - * word_count.arr[i] = 0 - * - * for i from 0 <= i < N: # <<<<<<<<<<<<<< - * a_i = self.darray.data.arr[i] - * self.sa.arr[self.ha.arr[a_i] + word_count.arr[a_i]] = i - */ - __pyx_t_4 = __pyx_v_N; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":62 - * - * for i from 0 <= i < N: - * a_i = self.darray.data.arr[i] # <<<<<<<<<<<<<< - * self.sa.arr[self.ha.arr[a_i] + word_count.arr[a_i]] = i - * isa.arr[i] = self.ha.arr[a_i + 1] - 1 # bucket pointer is last index in bucket - */ - __pyx_v_a_i = (__pyx_v_self->darray->data->arr[__pyx_v_i]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":63 - * for i from 0 <= i < N: - * a_i = self.darray.data.arr[i] - * self.sa.arr[self.ha.arr[a_i] + word_count.arr[a_i]] = i # <<<<<<<<<<<<<< - * isa.arr[i] = self.ha.arr[a_i + 1] - 1 # bucket pointer is last index in bucket - * word_count.arr[a_i] = word_count.arr[a_i] + 1 - */ - (__pyx_v_self->sa->arr[((__pyx_v_self->ha->arr[__pyx_v_a_i]) + (__pyx_v_word_count->arr[__pyx_v_a_i]))]) = __pyx_v_i; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":64 - * a_i = self.darray.data.arr[i] - * self.sa.arr[self.ha.arr[a_i] + word_count.arr[a_i]] = i - * isa.arr[i] = self.ha.arr[a_i + 1] - 1 # bucket pointer is last index in bucket # <<<<<<<<<<<<<< - * word_count.arr[a_i] = word_count.arr[a_i] + 1 - * - */ - (__pyx_v_isa->arr[__pyx_v_i]) = ((__pyx_v_self->ha->arr[(__pyx_v_a_i + 1)]) - 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":65 - * self.sa.arr[self.ha.arr[a_i] + word_count.arr[a_i]] = i - * isa.arr[i] = self.ha.arr[a_i + 1] - 1 # bucket pointer is last index in bucket - * word_count.arr[a_i] = word_count.arr[a_i] + 1 # <<<<<<<<<<<<<< - * - * '''Determine size of initial runs''' - */ - (__pyx_v_word_count->arr[__pyx_v_a_i]) = ((__pyx_v_word_count->arr[__pyx_v_a_i]) + 1); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":68 - * - * '''Determine size of initial runs''' - * current_run = 0 # <<<<<<<<<<<<<< - * for i from 0 <= i < V+1: - * if i < V and self.ha.arr[i+1] - self.ha.arr[i] == 1: - */ - __pyx_v_current_run = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":69 - * '''Determine size of initial runs''' - * current_run = 0 - * for i from 0 <= i < V+1: # <<<<<<<<<<<<<< - * if i < V and self.ha.arr[i+1] - self.ha.arr[i] == 1: - * current_run = current_run + 1 - */ - __pyx_t_5 = (__pyx_v_V + 1); - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_5; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":70 - * current_run = 0 - * for i from 0 <= i < V+1: - * if i < V and self.ha.arr[i+1] - self.ha.arr[i] == 1: # <<<<<<<<<<<<<< - * current_run = current_run + 1 - * else: - */ - __pyx_t_6 = (__pyx_v_i < __pyx_v_V); - if (__pyx_t_6) { - __pyx_t_7 = (((__pyx_v_self->ha->arr[(__pyx_v_i + 1)]) - (__pyx_v_self->ha->arr[__pyx_v_i])) == 1); - __pyx_t_8 = __pyx_t_7; - } else { - __pyx_t_8 = __pyx_t_6; - } - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":71 - * for i from 0 <= i < V+1: - * if i < V and self.ha.arr[i+1] - self.ha.arr[i] == 1: - * current_run = current_run + 1 # <<<<<<<<<<<<<< - * else: - * if current_run > 0: - */ - __pyx_v_current_run = (__pyx_v_current_run + 1); - goto __pyx_L11; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":73 - * current_run = current_run + 1 - * else: - * if current_run > 0: # <<<<<<<<<<<<<< - * self.sa.arr[self.ha.arr[i] - current_run] = -current_run - * current_run = 0 - */ - __pyx_t_8 = (__pyx_v_current_run > 0); - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":74 - * else: - * if current_run > 0: - * self.sa.arr[self.ha.arr[i] - current_run] = -current_run # <<<<<<<<<<<<<< - * current_run = 0 - * - */ - (__pyx_v_self->sa->arr[((__pyx_v_self->ha->arr[__pyx_v_i]) - __pyx_v_current_run)]) = (-__pyx_v_current_run); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":75 - * if current_run > 0: - * self.sa.arr[self.ha.arr[i] - current_run] = -current_run - * current_run = 0 # <<<<<<<<<<<<<< - * - * logger.info(" Bucket sort took %f seconds", (monitor_cpu() - sort_start_time)) - */ - __pyx_v_current_run = 0; - goto __pyx_L12; - } - __pyx_L12:; - } - __pyx_L11:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":77 - * current_run = 0 - * - * logger.info(" Bucket sort took %f seconds", (monitor_cpu() - sort_start_time)) # <<<<<<<<<<<<<< - * - * '''Step 2: prefix-doubling sort''' - */ - __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__info); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyFloat_FromDouble((__pyx_f_8_cdec_sa_monitor_cpu() - __pyx_v_sort_start_time)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_87)); - PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_kp_s_87)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_87)); - PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":80 - * - * '''Step 2: prefix-doubling sort''' - * h = 1 # <<<<<<<<<<<<<< - * while self.sa.arr[0] != -N: - * sort_start_time = monitor_cpu() - */ - __pyx_v_h = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":81 - * '''Step 2: prefix-doubling sort''' - * h = 1 - * while self.sa.arr[0] != -N: # <<<<<<<<<<<<<< - * sort_start_time = monitor_cpu() - * logger.debug(" Refining, sort depth = %d", h) - */ - while (1) { - __pyx_t_8 = ((__pyx_v_self->sa->arr[0]) != (-__pyx_v_N)); - if (!__pyx_t_8) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":82 - * h = 1 - * while self.sa.arr[0] != -N: - * sort_start_time = monitor_cpu() # <<<<<<<<<<<<<< - * logger.debug(" Refining, sort depth = %d", h) - * i = 0 - */ - __pyx_v_sort_start_time = __pyx_f_8_cdec_sa_monitor_cpu(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":83 - * while self.sa.arr[0] != -N: - * sort_start_time = monitor_cpu() - * logger.debug(" Refining, sort depth = %d", h) # <<<<<<<<<<<<<< - * i = 0 - * skip = 0 - */ - __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_9 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__debug); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_88)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_88)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_88)); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":84 - * sort_start_time = monitor_cpu() - * logger.debug(" Refining, sort depth = %d", h) - * i = 0 # <<<<<<<<<<<<<< - * skip = 0 - * while i < N: - */ - __pyx_v_i = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":85 - * logger.debug(" Refining, sort depth = %d", h) - * i = 0 - * skip = 0 # <<<<<<<<<<<<<< - * while i < N: - * if self.sa.arr[i] < 0: - */ - __pyx_v_skip = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":86 - * i = 0 - * skip = 0 - * while i < N: # <<<<<<<<<<<<<< - * if self.sa.arr[i] < 0: - * skip = skip + self.sa.arr[i] - */ - while (1) { - __pyx_t_8 = (__pyx_v_i < __pyx_v_N); - if (!__pyx_t_8) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":87 - * skip = 0 - * while i < N: - * if self.sa.arr[i] < 0: # <<<<<<<<<<<<<< - * skip = skip + self.sa.arr[i] - * i = i - self.sa.arr[i] - */ - __pyx_t_8 = ((__pyx_v_self->sa->arr[__pyx_v_i]) < 0); - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":88 - * while i < N: - * if self.sa.arr[i] < 0: - * skip = skip + self.sa.arr[i] # <<<<<<<<<<<<<< - * i = i - self.sa.arr[i] - * else: - */ - __pyx_v_skip = (__pyx_v_skip + (__pyx_v_self->sa->arr[__pyx_v_i])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":89 - * if self.sa.arr[i] < 0: - * skip = skip + self.sa.arr[i] - * i = i - self.sa.arr[i] # <<<<<<<<<<<<<< - * else: - * if skip < 0: - */ - __pyx_v_i = (__pyx_v_i - (__pyx_v_self->sa->arr[__pyx_v_i])); - goto __pyx_L17; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":91 - * i = i - self.sa.arr[i] - * else: - * if skip < 0: # <<<<<<<<<<<<<< - * self.sa.arr[i+skip] = skip - * skip = 0 - */ - __pyx_t_8 = (__pyx_v_skip < 0); - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":92 - * else: - * if skip < 0: - * self.sa.arr[i+skip] = skip # <<<<<<<<<<<<<< - * skip = 0 - * j = isa.arr[self.sa.arr[i]] - */ - (__pyx_v_self->sa->arr[(__pyx_v_i + __pyx_v_skip)]) = __pyx_v_skip; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":93 - * if skip < 0: - * self.sa.arr[i+skip] = skip - * skip = 0 # <<<<<<<<<<<<<< - * j = isa.arr[self.sa.arr[i]] - * self.q3sort(i, j, h, isa) - */ - __pyx_v_skip = 0; - goto __pyx_L18; - } - __pyx_L18:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":94 - * self.sa.arr[i+skip] = skip - * skip = 0 - * j = isa.arr[self.sa.arr[i]] # <<<<<<<<<<<<<< - * self.q3sort(i, j, h, isa) - * i = j+1 - */ - __pyx_v_j = (__pyx_v_isa->arr[(__pyx_v_self->sa->arr[__pyx_v_i])]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":95 - * skip = 0 - * j = isa.arr[self.sa.arr[i]] - * self.q3sort(i, j, h, isa) # <<<<<<<<<<<<<< - * i = j+1 - * if skip < 0: - */ - __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__q3sort); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = PyInt_FromLong(__pyx_v_j); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_11 = PyTuple_New(4); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - __Pyx_INCREF(((PyObject *)__pyx_v_isa)); - PyTuple_SET_ITEM(__pyx_t_11, 3, ((PyObject *)__pyx_v_isa)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_isa)); - __pyx_t_1 = 0; - __pyx_t_9 = 0; - __pyx_t_10 = 0; - __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":96 - * j = isa.arr[self.sa.arr[i]] - * self.q3sort(i, j, h, isa) - * i = j+1 # <<<<<<<<<<<<<< - * if skip < 0: - * self.sa.arr[i+skip] = skip - */ - __pyx_v_i = (__pyx_v_j + 1); - } - __pyx_L17:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":97 - * self.q3sort(i, j, h, isa) - * i = j+1 - * if skip < 0: # <<<<<<<<<<<<<< - * self.sa.arr[i+skip] = skip - * h = h * 2 - */ - __pyx_t_8 = (__pyx_v_skip < 0); - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":98 - * i = j+1 - * if skip < 0: - * self.sa.arr[i+skip] = skip # <<<<<<<<<<<<<< - * h = h * 2 - * logger.debug(" Refinement took %f seconds", (monitor_cpu() - sort_start_time)) - */ - (__pyx_v_self->sa->arr[(__pyx_v_i + __pyx_v_skip)]) = __pyx_v_skip; - goto __pyx_L19; - } - __pyx_L19:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":99 - * if skip < 0: - * self.sa.arr[i+skip] = skip - * h = h * 2 # <<<<<<<<<<<<<< - * logger.debug(" Refinement took %f seconds", (monitor_cpu() - sort_start_time)) - * - */ - __pyx_v_h = (__pyx_v_h * 2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":100 - * self.sa.arr[i+skip] = skip - * h = h * 2 - * logger.debug(" Refinement took %f seconds", (monitor_cpu() - sort_start_time)) # <<<<<<<<<<<<<< - * - * '''Step 3: read off suffix array from inverse suffix array''' - */ - __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_11 = PyObject_GetAttr(__pyx_t_10, __pyx_n_s__debug); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = PyFloat_FromDouble((__pyx_f_8_cdec_sa_monitor_cpu() - __pyx_v_sort_start_time)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_89)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_89)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_89)); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_t_10 = 0; - __pyx_t_10 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":103 - * - * '''Step 3: read off suffix array from inverse suffix array''' - * logger.info(" Finalizing sort...") # <<<<<<<<<<<<<< - * for i from 0 <= i < N: - * j = isa.arr[i] - */ - __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_10, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_91), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":104 - * '''Step 3: read off suffix array from inverse suffix array''' - * logger.info(" Finalizing sort...") - * for i from 0 <= i < N: # <<<<<<<<<<<<<< - * j = isa.arr[i] - * self.sa.arr[j] = i - */ - __pyx_t_4 = __pyx_v_N; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":105 - * logger.info(" Finalizing sort...") - * for i from 0 <= i < N: - * j = isa.arr[i] # <<<<<<<<<<<<<< - * self.sa.arr[j] = i - * logger.info("Suffix array construction took %f seconds", (monitor_cpu() - start_time)) - */ - __pyx_v_j = (__pyx_v_isa->arr[__pyx_v_i]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":106 - * for i from 0 <= i < N: - * j = isa.arr[i] - * self.sa.arr[j] = i # <<<<<<<<<<<<<< - * logger.info("Suffix array construction took %f seconds", (monitor_cpu() - start_time)) - * - */ - (__pyx_v_self->sa->arr[__pyx_v_j]) = __pyx_v_i; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":107 - * j = isa.arr[i] - * self.sa.arr[j] = i - * logger.info("Suffix array construction took %f seconds", (monitor_cpu() - start_time)) # <<<<<<<<<<<<<< - * - * def q3sort(self, int i, int j, int h, IntList isa, pad=""): - */ - __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_10, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = PyFloat_FromDouble((__pyx_f_8_cdec_sa_monitor_cpu() - __pyx_v_start_time)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_92)); - PyTuple_SET_ITEM(__pyx_t_11, 0, ((PyObject *)__pyx_kp_s_92)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_92)); - PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_t_10 = 0; - __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - __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_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_AddTraceback("_cdec_sa.SuffixArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_isa); - __Pyx_XDECREF((PyObject *)__pyx_v_word_count); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_13q3sort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8_cdec_sa_11SuffixArray_12q3sort[] = "This is a ternary quicksort. It divides the array into\n three partitions: items less than the pivot, items equal\n to pivot, and items greater than pivot. The first and last\n of these partitions are then recursively sorted"; -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_13q3sort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_v_i; - int __pyx_v_j; - int __pyx_v_h; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_isa = 0; - PyObject *__pyx_v_pad = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__i,&__pyx_n_s__j,&__pyx_n_s__h,&__pyx_n_s__isa,&__pyx_n_s__pad,0}; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("q3sort (wrapper)", 0); - { - PyObject* values[5] = {0,0,0,0,0}; - values[4] = ((PyObject *)__pyx_kp_s_42); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__i); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__j); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("q3sort", 0, 4, 5, 1); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__h); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("q3sort", 0, 4, 5, 2); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__isa); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("q3sort", 0, 4, 5, 3); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pad); - if (value) { values[4] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "q3sort") < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_i = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_i == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_j = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_j == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_h = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_h == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_isa = ((struct __pyx_obj_8_cdec_sa_IntList *)values[3]); - __pyx_v_pad = values[4]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("q3sort", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.SuffixArray.q3sort", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_isa), __pyx_ptype_8_cdec_sa_IntList, 1, "isa", 0))) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_12q3sort(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), __pyx_v_i, __pyx_v_j, __pyx_v_h, __pyx_v_isa, __pyx_v_pad); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":109 - * logger.info("Suffix array construction took %f seconds", (monitor_cpu() - start_time)) - * - * def q3sort(self, int i, int j, int h, IntList isa, pad=""): # <<<<<<<<<<<<<< - * '''This is a ternary quicksort. It divides the array into - * three partitions: items less than the pivot, items equal - */ - -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_12q3sort(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, int __pyx_v_i, int __pyx_v_j, int __pyx_v_h, struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_isa, PyObject *__pyx_v_pad) { - int __pyx_v_k; - int __pyx_v_midpoint; - int __pyx_v_pval; - int __pyx_v_phead; - int __pyx_v_ptail; - int __pyx_v_tmp; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - long __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("q3sort", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":116 - * cdef int k, midpoint, pval, phead, ptail, tmp - * - * if j-i < -1: # <<<<<<<<<<<<<< - * raise Exception("Unexpected condition found in q3sort: sort from %d to %d" % (i,j)) - * if j-i == -1: # recursive base case -- empty interval - */ - __pyx_t_1 = ((__pyx_v_j - __pyx_v_i) < -1); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":117 - * - * if j-i < -1: - * raise Exception("Unexpected condition found in q3sort: sort from %d to %d" % (i,j)) # <<<<<<<<<<<<<< - * if j-i == -1: # recursive base case -- empty interval - * return - */ - __pyx_t_2 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyInt_FromLong(__pyx_v_j); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_2 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_93), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__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[12]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":118 - * if j-i < -1: - * raise Exception("Unexpected condition found in q3sort: sort from %d to %d" % (i,j)) - * if j-i == -1: # recursive base case -- empty interval # <<<<<<<<<<<<<< - * return - * if (j-i == 0): # recursive base case -- singleton interval - */ - __pyx_t_1 = ((__pyx_v_j - __pyx_v_i) == -1); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":119 - * raise Exception("Unexpected condition found in q3sort: sort from %d to %d" % (i,j)) - * if j-i == -1: # recursive base case -- empty interval - * return # <<<<<<<<<<<<<< - * if (j-i == 0): # recursive base case -- singleton interval - * isa.arr[self.sa.arr[i]] = i - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":120 - * if j-i == -1: # recursive base case -- empty interval - * return - * if (j-i == 0): # recursive base case -- singleton interval # <<<<<<<<<<<<<< - * isa.arr[self.sa.arr[i]] = i - * self.sa.arr[i] = -1 - */ - __pyx_t_1 = ((__pyx_v_j - __pyx_v_i) == 0); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":121 - * return - * if (j-i == 0): # recursive base case -- singleton interval - * isa.arr[self.sa.arr[i]] = i # <<<<<<<<<<<<<< - * self.sa.arr[i] = -1 - * return - */ - (__pyx_v_isa->arr[(__pyx_v_self->sa->arr[__pyx_v_i])]) = __pyx_v_i; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":122 - * if (j-i == 0): # recursive base case -- singleton interval - * isa.arr[self.sa.arr[i]] = i - * self.sa.arr[i] = -1 # <<<<<<<<<<<<<< - * return - * - */ - (__pyx_v_self->sa->arr[__pyx_v_i]) = -1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":123 - * isa.arr[self.sa.arr[i]] = i - * self.sa.arr[i] = -1 - * return # <<<<<<<<<<<<<< - * - * # NOTE: choosing the first item as a pivot value resulted in - */ - __Pyx_XDECREF(__pyx_r); - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":132 - * # If the method of assigning word_id's is changed, this method - * # may need to be reconsidered as well. - * midpoint = (i+j)/2 # <<<<<<<<<<<<<< - * pval = isa.arr[self.sa.arr[midpoint] + h] - * if i != midpoint: - */ - __pyx_v_midpoint = __Pyx_div_long((__pyx_v_i + __pyx_v_j), 2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":133 - * # may need to be reconsidered as well. - * midpoint = (i+j)/2 - * pval = isa.arr[self.sa.arr[midpoint] + h] # <<<<<<<<<<<<<< - * if i != midpoint: - * tmp = self.sa.arr[midpoint] - */ - __pyx_v_pval = (__pyx_v_isa->arr[((__pyx_v_self->sa->arr[__pyx_v_midpoint]) + __pyx_v_h)]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":134 - * midpoint = (i+j)/2 - * pval = isa.arr[self.sa.arr[midpoint] + h] - * if i != midpoint: # <<<<<<<<<<<<<< - * tmp = self.sa.arr[midpoint] - * self.sa.arr[midpoint] = self.sa.arr[i] - */ - __pyx_t_1 = (__pyx_v_i != __pyx_v_midpoint); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":135 - * pval = isa.arr[self.sa.arr[midpoint] + h] - * if i != midpoint: - * tmp = self.sa.arr[midpoint] # <<<<<<<<<<<<<< - * self.sa.arr[midpoint] = self.sa.arr[i] - * self.sa.arr[i] = tmp - */ - __pyx_v_tmp = (__pyx_v_self->sa->arr[__pyx_v_midpoint]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":136 - * if i != midpoint: - * tmp = self.sa.arr[midpoint] - * self.sa.arr[midpoint] = self.sa.arr[i] # <<<<<<<<<<<<<< - * self.sa.arr[i] = tmp - * phead = i - */ - (__pyx_v_self->sa->arr[__pyx_v_midpoint]) = (__pyx_v_self->sa->arr[__pyx_v_i]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":137 - * tmp = self.sa.arr[midpoint] - * self.sa.arr[midpoint] = self.sa.arr[i] - * self.sa.arr[i] = tmp # <<<<<<<<<<<<<< - * phead = i - * ptail = i - */ - (__pyx_v_self->sa->arr[__pyx_v_i]) = __pyx_v_tmp; - goto __pyx_L6; - } - __pyx_L6:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":138 - * self.sa.arr[midpoint] = self.sa.arr[i] - * self.sa.arr[i] = tmp - * phead = i # <<<<<<<<<<<<<< - * ptail = i - * - */ - __pyx_v_phead = __pyx_v_i; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":139 - * self.sa.arr[i] = tmp - * phead = i - * ptail = i # <<<<<<<<<<<<<< - * - * # find the three partitions. phead marks the first element - */ - __pyx_v_ptail = __pyx_v_i; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":143 - * # find the three partitions. phead marks the first element - * # of the middle partition, and ptail marks the last element - * for k from i+1 <= k < j+1: # <<<<<<<<<<<<<< - * if isa.arr[self.sa.arr[k] + h] < pval: - * if k > ptail+1: - */ - __pyx_t_5 = (__pyx_v_j + 1); - for (__pyx_v_k = (__pyx_v_i + 1); __pyx_v_k < __pyx_t_5; __pyx_v_k++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":144 - * # of the middle partition, and ptail marks the last element - * for k from i+1 <= k < j+1: - * if isa.arr[self.sa.arr[k] + h] < pval: # <<<<<<<<<<<<<< - * if k > ptail+1: - * tmp = self.sa.arr[phead] - */ - __pyx_t_1 = ((__pyx_v_isa->arr[((__pyx_v_self->sa->arr[__pyx_v_k]) + __pyx_v_h)]) < __pyx_v_pval); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":145 - * for k from i+1 <= k < j+1: - * if isa.arr[self.sa.arr[k] + h] < pval: - * if k > ptail+1: # <<<<<<<<<<<<<< - * tmp = self.sa.arr[phead] - * self.sa.arr[phead] = self.sa.arr[k] - */ - __pyx_t_1 = (__pyx_v_k > (__pyx_v_ptail + 1)); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":146 - * if isa.arr[self.sa.arr[k] + h] < pval: - * if k > ptail+1: - * tmp = self.sa.arr[phead] # <<<<<<<<<<<<<< - * self.sa.arr[phead] = self.sa.arr[k] - * self.sa.arr[k] = self.sa.arr[ptail+1] - */ - __pyx_v_tmp = (__pyx_v_self->sa->arr[__pyx_v_phead]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":147 - * if k > ptail+1: - * tmp = self.sa.arr[phead] - * self.sa.arr[phead] = self.sa.arr[k] # <<<<<<<<<<<<<< - * self.sa.arr[k] = self.sa.arr[ptail+1] - * self.sa.arr[ptail+1] = tmp - */ - (__pyx_v_self->sa->arr[__pyx_v_phead]) = (__pyx_v_self->sa->arr[__pyx_v_k]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":148 - * tmp = self.sa.arr[phead] - * self.sa.arr[phead] = self.sa.arr[k] - * self.sa.arr[k] = self.sa.arr[ptail+1] # <<<<<<<<<<<<<< - * self.sa.arr[ptail+1] = tmp - * else: # k == ptail+1 - */ - (__pyx_v_self->sa->arr[__pyx_v_k]) = (__pyx_v_self->sa->arr[(__pyx_v_ptail + 1)]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":149 - * self.sa.arr[phead] = self.sa.arr[k] - * self.sa.arr[k] = self.sa.arr[ptail+1] - * self.sa.arr[ptail+1] = tmp # <<<<<<<<<<<<<< - * else: # k == ptail+1 - * tmp = self.sa.arr[phead] - */ - (__pyx_v_self->sa->arr[(__pyx_v_ptail + 1)]) = __pyx_v_tmp; - goto __pyx_L10; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":151 - * self.sa.arr[ptail+1] = tmp - * else: # k == ptail+1 - * tmp = self.sa.arr[phead] # <<<<<<<<<<<<<< - * self.sa.arr[phead] = self.sa.arr[k] - * self.sa.arr[k] = tmp - */ - __pyx_v_tmp = (__pyx_v_self->sa->arr[__pyx_v_phead]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":152 - * else: # k == ptail+1 - * tmp = self.sa.arr[phead] - * self.sa.arr[phead] = self.sa.arr[k] # <<<<<<<<<<<<<< - * self.sa.arr[k] = tmp - * phead = phead + 1 - */ - (__pyx_v_self->sa->arr[__pyx_v_phead]) = (__pyx_v_self->sa->arr[__pyx_v_k]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":153 - * tmp = self.sa.arr[phead] - * self.sa.arr[phead] = self.sa.arr[k] - * self.sa.arr[k] = tmp # <<<<<<<<<<<<<< - * phead = phead + 1 - * ptail = ptail + 1 - */ - (__pyx_v_self->sa->arr[__pyx_v_k]) = __pyx_v_tmp; - } - __pyx_L10:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":154 - * self.sa.arr[phead] = self.sa.arr[k] - * self.sa.arr[k] = tmp - * phead = phead + 1 # <<<<<<<<<<<<<< - * ptail = ptail + 1 - * else: - */ - __pyx_v_phead = (__pyx_v_phead + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":155 - * self.sa.arr[k] = tmp - * phead = phead + 1 - * ptail = ptail + 1 # <<<<<<<<<<<<<< - * else: - * if isa.arr[self.sa.arr[k] + h] == pval: - */ - __pyx_v_ptail = (__pyx_v_ptail + 1); - goto __pyx_L9; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":157 - * ptail = ptail + 1 - * else: - * if isa.arr[self.sa.arr[k] + h] == pval: # <<<<<<<<<<<<<< - * if k > ptail+1: - * tmp = self.sa.arr[ptail+1] - */ - __pyx_t_1 = ((__pyx_v_isa->arr[((__pyx_v_self->sa->arr[__pyx_v_k]) + __pyx_v_h)]) == __pyx_v_pval); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":158 - * else: - * if isa.arr[self.sa.arr[k] + h] == pval: - * if k > ptail+1: # <<<<<<<<<<<<<< - * tmp = self.sa.arr[ptail+1] - * self.sa.arr[ptail+1] = self.sa.arr[k] - */ - __pyx_t_1 = (__pyx_v_k > (__pyx_v_ptail + 1)); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":159 - * if isa.arr[self.sa.arr[k] + h] == pval: - * if k > ptail+1: - * tmp = self.sa.arr[ptail+1] # <<<<<<<<<<<<<< - * self.sa.arr[ptail+1] = self.sa.arr[k] - * self.sa.arr[k] = tmp - */ - __pyx_v_tmp = (__pyx_v_self->sa->arr[(__pyx_v_ptail + 1)]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":160 - * if k > ptail+1: - * tmp = self.sa.arr[ptail+1] - * self.sa.arr[ptail+1] = self.sa.arr[k] # <<<<<<<<<<<<<< - * self.sa.arr[k] = tmp - * ptail = ptail + 1 - */ - (__pyx_v_self->sa->arr[(__pyx_v_ptail + 1)]) = (__pyx_v_self->sa->arr[__pyx_v_k]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":161 - * tmp = self.sa.arr[ptail+1] - * self.sa.arr[ptail+1] = self.sa.arr[k] - * self.sa.arr[k] = tmp # <<<<<<<<<<<<<< - * ptail = ptail + 1 - * - */ - (__pyx_v_self->sa->arr[__pyx_v_k]) = __pyx_v_tmp; - goto __pyx_L12; - } - __pyx_L12:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":162 - * self.sa.arr[ptail+1] = self.sa.arr[k] - * self.sa.arr[k] = tmp - * ptail = ptail + 1 # <<<<<<<<<<<<<< - * - * # recursively sort smaller suffixes - */ - __pyx_v_ptail = (__pyx_v_ptail + 1); - goto __pyx_L11; - } - __pyx_L11:; - } - __pyx_L9:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":165 - * - * # recursively sort smaller suffixes - * self.q3sort(i, phead-1, h, isa, pad+" ") # <<<<<<<<<<<<<< - * - * # update suffixes with pivot value - */ - __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__q3sort); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyInt_FromLong((__pyx_v_phead - 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyTuple_New(5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_6); - __Pyx_INCREF(((PyObject *)__pyx_v_isa)); - PyTuple_SET_ITEM(__pyx_t_8, 3, ((PyObject *)__pyx_v_isa)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_isa)); - PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - __pyx_t_4 = 0; - __pyx_t_2 = 0; - __pyx_t_6 = 0; - __pyx_t_7 = 0; - __pyx_t_7 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":169 - * # update suffixes with pivot value - * # corresponds to update_group function in Larsson & Sadakane - * for k from phead <= k < ptail+1: # <<<<<<<<<<<<<< - * isa.arr[self.sa.arr[k]] = ptail - * if phead == ptail: - */ - __pyx_t_5 = (__pyx_v_ptail + 1); - for (__pyx_v_k = __pyx_v_phead; __pyx_v_k < __pyx_t_5; __pyx_v_k++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":170 - * # corresponds to update_group function in Larsson & Sadakane - * for k from phead <= k < ptail+1: - * isa.arr[self.sa.arr[k]] = ptail # <<<<<<<<<<<<<< - * if phead == ptail: - * self.sa.arr[phead] = -1 - */ - (__pyx_v_isa->arr[(__pyx_v_self->sa->arr[__pyx_v_k])]) = __pyx_v_ptail; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":171 - * for k from phead <= k < ptail+1: - * isa.arr[self.sa.arr[k]] = ptail - * if phead == ptail: # <<<<<<<<<<<<<< - * self.sa.arr[phead] = -1 - * - */ - __pyx_t_1 = (__pyx_v_phead == __pyx_v_ptail); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":172 - * isa.arr[self.sa.arr[k]] = ptail - * if phead == ptail: - * self.sa.arr[phead] = -1 # <<<<<<<<<<<<<< - * - * # recursively sort larger suffixes - */ - (__pyx_v_self->sa->arr[__pyx_v_phead]) = -1; - goto __pyx_L15; - } - __pyx_L15:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":175 - * - * # recursively sort larger suffixes - * self.q3sort(ptail+1, j, h, isa, pad+" ") # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__q3sort); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyInt_FromLong((__pyx_v_ptail + 1)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_3 = PyInt_FromLong(__pyx_v_j); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyTuple_New(5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_6); - __Pyx_INCREF(((PyObject *)__pyx_v_isa)); - PyTuple_SET_ITEM(__pyx_t_4, 3, ((PyObject *)__pyx_v_isa)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_isa)); - PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_8 = 0; - __pyx_t_3 = 0; - __pyx_t_6 = 0; - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("_cdec_sa.SuffixArray.q3sort", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_15write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_15write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_text (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.SuffixArray.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_14write_text(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":178 - * - * - * def write_text(self, char* filename): # <<<<<<<<<<<<<< - * self.darray.write_text(filename) - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_14write_text(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("write_text", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":179 - * - * def write_text(self, char* filename): - * self.darray.write_text(filename) # <<<<<<<<<<<<<< - * - * def read_binary(self, char* filename): - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->darray), __pyx_n_s__write_text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 179; __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[12]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__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_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - __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_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.SuffixArray.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_17read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_17read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_binary (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.SuffixArray.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_16read_binary(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":181 - * self.darray.write_text(filename) - * - * def read_binary(self, char* filename): # <<<<<<<<<<<<<< - * cdef FILE *f - * f = fopen(filename, "r") - */ - -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_16read_binary(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename) { - FILE *__pyx_v_f; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_binary", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":183 - * def read_binary(self, char* filename): - * cdef FILE *f - * f = fopen(filename, "r") # <<<<<<<<<<<<<< - * self.darray.read_handle(f) - * self.sa.read_handle(f) - */ - __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":184 - * cdef FILE *f - * f = fopen(filename, "r") - * self.darray.read_handle(f) # <<<<<<<<<<<<<< - * self.sa.read_handle(f) - * self.ha.read_handle(f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_DataArray *)__pyx_v_self->darray->__pyx_vtab)->read_handle(__pyx_v_self->darray, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":185 - * f = fopen(filename, "r") - * self.darray.read_handle(f) - * self.sa.read_handle(f) # <<<<<<<<<<<<<< - * self.ha.read_handle(f) - * fclose(f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->sa->__pyx_vtab)->read_handle(__pyx_v_self->sa, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":186 - * self.darray.read_handle(f) - * self.sa.read_handle(f) - * self.ha.read_handle(f) # <<<<<<<<<<<<<< - * fclose(f) - * - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->ha->__pyx_vtab)->read_handle(__pyx_v_self->ha, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":187 - * self.sa.read_handle(f) - * self.ha.read_handle(f) - * fclose(f) # <<<<<<<<<<<<<< - * - * def write_binary(self, char* filename): - */ - fclose(__pyx_v_f); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_19write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_19write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_binary (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.SuffixArray.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_18write_binary(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":189 - * fclose(f) - * - * def write_binary(self, char* filename): # <<<<<<<<<<<<<< - * cdef FILE* f - * f = fopen(filename, "w") - */ - -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_18write_binary(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename) { - FILE *__pyx_v_f; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_binary", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":191 - * def write_binary(self, char* filename): - * cdef FILE* f - * f = fopen(filename, "w") # <<<<<<<<<<<<<< - * self.darray.write_handle(f) - * self.sa.write_handle(f) - */ - __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":192 - * cdef FILE* f - * f = fopen(filename, "w") - * self.darray.write_handle(f) # <<<<<<<<<<<<<< - * self.sa.write_handle(f) - * self.ha.write_handle(f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_DataArray *)__pyx_v_self->darray->__pyx_vtab)->write_handle(__pyx_v_self->darray, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":193 - * f = fopen(filename, "w") - * self.darray.write_handle(f) - * self.sa.write_handle(f) # <<<<<<<<<<<<<< - * self.ha.write_handle(f) - * fclose(f) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->sa->__pyx_vtab)->write_handle(__pyx_v_self->sa, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":194 - * self.darray.write_handle(f) - * self.sa.write_handle(f) - * self.ha.write_handle(f) # <<<<<<<<<<<<<< - * fclose(f) - * - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_self->ha->__pyx_vtab)->write_handle(__pyx_v_self->ha, __pyx_v_f); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":195 - * self.sa.write_handle(f) - * self.ha.write_handle(f) - * fclose(f) # <<<<<<<<<<<<<< - * - * def write_enhanced(self, char* filename): - */ - fclose(__pyx_v_f); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_21write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_21write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("write_enhanced (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.SuffixArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_20write_enhanced(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), ((char *)__pyx_v_filename)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":197 - * fclose(f) - * - * def write_enhanced(self, char* filename): # <<<<<<<<<<<<<< - * with open(filename, "w") as f: - * self.darray.write_enhanced_handle(f) - */ - -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_20write_enhanced(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename) { - PyObject *__pyx_v_f = NULL; - PyObject *__pyx_v_a_i = NULL; - PyObject *__pyx_v_w_i = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - Py_ssize_t __pyx_t_8; - PyObject *(*__pyx_t_9)(PyObject *); - PyObject *__pyx_t_10 = NULL; - int __pyx_t_11; - PyObject *__pyx_t_12 = NULL; - int __pyx_t_13; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("write_enhanced", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":198 - * - * def write_enhanced(self, char* filename): - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * self.darray.write_enhanced_handle(f) - * for a_i in self.sa: - */ - /*with:*/ { - __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /*try:*/ { - { - __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - /*try:*/ { - __Pyx_INCREF(__pyx_t_4); - __pyx_v_f = __pyx_t_4; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":199 - * def write_enhanced(self, char* filename): - * with open(filename, "w") as f: - * self.darray.write_enhanced_handle(f) # <<<<<<<<<<<<<< - * for a_i in self.sa: - * f.write("%d " % a_i) - */ - __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self->darray), __pyx_n_s_24); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_f); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_f); - __Pyx_GIVEREF(__pyx_v_f); - __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":200 - * with open(filename, "w") as f: - * self.darray.write_enhanced_handle(f) - * for a_i in self.sa: # <<<<<<<<<<<<<< - * f.write("%d " % a_i) - * f.write("\n") - */ - if (PyList_CheckExact(((PyObject *)__pyx_v_self->sa)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->sa))) { - __pyx_t_2 = ((PyObject *)__pyx_v_self->sa); __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(((PyObject *)__pyx_v_self->sa)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_9 = Py_TYPE(__pyx_t_2)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_2)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break; - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_2)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; - } else { - __pyx_t_1 = __pyx_t_9(__pyx_t_2); - if (unlikely(!__pyx_t_1)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[12]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XDECREF(__pyx_v_a_i); - __pyx_v_a_i = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":201 - * self.darray.write_enhanced_handle(f) - * for a_i in self.sa: - * f.write("%d " % a_i) # <<<<<<<<<<<<<< - * f.write("\n") - * for w_i in self.ha: - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_a_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_4)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); - __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":202 - * for a_i in self.sa: - * f.write("%d " % a_i) - * f.write("\n") # <<<<<<<<<<<<<< - * for w_i in self.ha: - * f.write("%d " % w_i) - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_94), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":203 - * f.write("%d " % a_i) - * f.write("\n") - * for w_i in self.ha: # <<<<<<<<<<<<<< - * f.write("%d " % w_i) - * f.write("\n") - */ - if (PyList_CheckExact(((PyObject *)__pyx_v_self->ha)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->ha))) { - __pyx_t_4 = ((PyObject *)__pyx_v_self->ha); __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(((PyObject *)__pyx_v_self->ha)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; - } else { - __pyx_t_2 = __pyx_t_9(__pyx_t_4); - if (unlikely(!__pyx_t_2)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[12]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF(__pyx_v_w_i); - __pyx_v_w_i = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":204 - * f.write("\n") - * for w_i in self.ha: - * f.write("%d " % w_i) # <<<<<<<<<<<<<< - * f.write("\n") - * - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_w_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_10)); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_10)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); - __pyx_t_10 = 0; - __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":205 - * for w_i in self.ha: - * f.write("%d " % w_i) - * f.write("\n") # <<<<<<<<<<<<<< - * - * cdef int __search_high(self, int word_id, int offset, int low, int high): - */ - __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_10 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_95), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L14_try_end; - __pyx_L7_error:; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":198 - * - * def write_enhanced(self, char* filename): - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * self.darray.write_enhanced_handle(f) - * for a_i in self.sa: - */ - /*except:*/ { - __Pyx_AddTraceback("_cdec_sa.SuffixArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_10, &__pyx_t_4, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - __Pyx_INCREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_12 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_12); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __pyx_t_13 = (!__pyx_t_11); - if (__pyx_t_13) { - __Pyx_GIVEREF(__pyx_t_10); - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_ErrRestore(__pyx_t_10, __pyx_t_4, __pyx_t_1); - __pyx_t_10 = 0; __pyx_t_4 = 0; __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - goto __pyx_L22; - } - __pyx_L22:; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L8_exception_handled; - } - __pyx_L9_except_error:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - goto __pyx_L1_error; - __pyx_L8_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - __pyx_L14_try_end:; - } - } - /*finally:*/ { - if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_96, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - goto __pyx_L23; - __pyx_L3_error:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L1_error; - __pyx_L23:; - } - - __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_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("_cdec_sa.SuffixArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_f); - __Pyx_XDECREF(__pyx_v_a_i); - __Pyx_XDECREF(__pyx_v_w_i); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":207 - * f.write("\n") - * - * cdef int __search_high(self, int word_id, int offset, int low, int high): # <<<<<<<<<<<<<< - * cdef int midpoint - * - */ - -static int __pyx_f_8_cdec_sa_11SuffixArray___search_high(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, int __pyx_v_word_id, int __pyx_v_offset, int __pyx_v_low, int __pyx_v_high) { - int __pyx_v_midpoint; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("__search_high", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":210 - * cdef int midpoint - * - * if low >= high: # <<<<<<<<<<<<<< - * return high - * midpoint = (high + low) / 2 - */ - __pyx_t_1 = (__pyx_v_low >= __pyx_v_high); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":211 - * - * if low >= high: - * return high # <<<<<<<<<<<<<< - * midpoint = (high + low) / 2 - * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: - */ - __pyx_r = __pyx_v_high; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":212 - * if low >= high: - * return high - * midpoint = (high + low) / 2 # <<<<<<<<<<<<<< - * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: - * return self.__search_high(word_id, offset, midpoint+1, high) - */ - __pyx_v_midpoint = __Pyx_div_long((__pyx_v_high + __pyx_v_low), 2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":213 - * return high - * midpoint = (high + low) / 2 - * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: # <<<<<<<<<<<<<< - * return self.__search_high(word_id, offset, midpoint+1, high) - * else: - */ - __pyx_t_1 = ((__pyx_v_self->darray->data->arr[((__pyx_v_self->sa->arr[__pyx_v_midpoint]) + __pyx_v_offset)]) == __pyx_v_word_id); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":214 - * midpoint = (high + low) / 2 - * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: - * return self.__search_high(word_id, offset, midpoint+1, high) # <<<<<<<<<<<<<< - * else: - * return self.__search_high(word_id, offset, low, midpoint) - */ - __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___search_high(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, (__pyx_v_midpoint + 1), __pyx_v_high); - goto __pyx_L0; - goto __pyx_L4; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":216 - * return self.__search_high(word_id, offset, midpoint+1, high) - * else: - * return self.__search_high(word_id, offset, low, midpoint) # <<<<<<<<<<<<<< - * - * cdef int __search_low(self, int word_id, int offset, int low, int high): - */ - __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___search_high(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, __pyx_v_low, __pyx_v_midpoint); - goto __pyx_L0; - } - __pyx_L4:; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":218 - * return self.__search_high(word_id, offset, low, midpoint) - * - * cdef int __search_low(self, int word_id, int offset, int low, int high): # <<<<<<<<<<<<<< - * cdef int midpoint - * - */ - -static int __pyx_f_8_cdec_sa_11SuffixArray___search_low(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, int __pyx_v_word_id, int __pyx_v_offset, int __pyx_v_low, int __pyx_v_high) { - int __pyx_v_midpoint; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("__search_low", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":221 - * cdef int midpoint - * - * if low >= high: # <<<<<<<<<<<<<< - * return high - * midpoint = (high + low) / 2 - */ - __pyx_t_1 = (__pyx_v_low >= __pyx_v_high); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":222 - * - * if low >= high: - * return high # <<<<<<<<<<<<<< - * midpoint = (high + low) / 2 - * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: - */ - __pyx_r = __pyx_v_high; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":223 - * if low >= high: - * return high - * midpoint = (high + low) / 2 # <<<<<<<<<<<<<< - * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: - * return self.__search_low(word_id, offset, low, midpoint) - */ - __pyx_v_midpoint = __Pyx_div_long((__pyx_v_high + __pyx_v_low), 2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":224 - * return high - * midpoint = (high + low) / 2 - * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: # <<<<<<<<<<<<<< - * return self.__search_low(word_id, offset, low, midpoint) - * else: - */ - __pyx_t_1 = ((__pyx_v_self->darray->data->arr[((__pyx_v_self->sa->arr[__pyx_v_midpoint]) + __pyx_v_offset)]) == __pyx_v_word_id); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":225 - * midpoint = (high + low) / 2 - * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: - * return self.__search_low(word_id, offset, low, midpoint) # <<<<<<<<<<<<<< - * else: - * return self.__search_low(word_id, offset, midpoint+1, high) - */ - __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___search_low(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, __pyx_v_low, __pyx_v_midpoint); - goto __pyx_L0; - goto __pyx_L4; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":227 - * return self.__search_low(word_id, offset, low, midpoint) - * else: - * return self.__search_low(word_id, offset, midpoint+1, high) # <<<<<<<<<<<<<< - * - * cdef __get_range(self, int word_id, int offset, int low, int high, int midpoint): - */ - __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___search_low(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, (__pyx_v_midpoint + 1), __pyx_v_high); - goto __pyx_L0; - } - __pyx_L4:; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":229 - * return self.__search_low(word_id, offset, midpoint+1, high) - * - * cdef __get_range(self, int word_id, int offset, int low, int high, int midpoint): # <<<<<<<<<<<<<< - * return (self.__search_low(word_id, offset, low, midpoint), - * self.__search_high(word_id, offset, midpoint, high)) - */ - -static PyObject *__pyx_f_8_cdec_sa_11SuffixArray___get_range(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, int __pyx_v_word_id, int __pyx_v_offset, int __pyx_v_low, int __pyx_v_high, int __pyx_v_midpoint) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__get_range", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":230 - * - * cdef __get_range(self, int word_id, int offset, int low, int high, int midpoint): - * return (self.__search_low(word_id, offset, low, midpoint), # <<<<<<<<<<<<<< - * self.__search_high(word_id, offset, midpoint, high)) - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___search_low(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, __pyx_v_low, __pyx_v_midpoint)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":231 - * cdef __get_range(self, int word_id, int offset, int low, int high, int midpoint): - * return (self.__search_low(word_id, offset, low, midpoint), - * self.__search_high(word_id, offset, midpoint, high)) # <<<<<<<<<<<<<< - * - * cdef __lookup_helper(self, int word_id, int offset, int low, int high): - */ - __pyx_t_2 = PyInt_FromLong(((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___search_high(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, __pyx_v_midpoint, __pyx_v_high)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_1 = 0; - __pyx_t_2 = 0; - __pyx_r = ((PyObject *)__pyx_t_3); - __pyx_t_3 = 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_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.SuffixArray.__get_range", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":233 - * self.__search_high(word_id, offset, midpoint, high)) - * - * cdef __lookup_helper(self, int word_id, int offset, int low, int high): # <<<<<<<<<<<<<< - * cdef int midpoint - * - */ - -static PyObject *__pyx_f_8_cdec_sa_11SuffixArray___lookup_helper(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, int __pyx_v_word_id, int __pyx_v_offset, int __pyx_v_low, int __pyx_v_high) { - int __pyx_v_midpoint; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__lookup_helper", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":236 - * cdef int midpoint - * - * if offset == 0: # <<<<<<<<<<<<<< - * return (self.ha.arr[word_id], self.ha.arr[word_id+1]) - * if low >= high: - */ - __pyx_t_1 = (__pyx_v_offset == 0); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":237 - * - * if offset == 0: - * return (self.ha.arr[word_id], self.ha.arr[word_id+1]) # <<<<<<<<<<<<<< - * if low >= high: - * return None - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyInt_FromLong((__pyx_v_self->ha->arr[__pyx_v_word_id])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyInt_FromLong((__pyx_v_self->ha->arr[(__pyx_v_word_id + 1)])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_2 = 0; - __pyx_t_3 = 0; - __pyx_r = ((PyObject *)__pyx_t_4); - __pyx_t_4 = 0; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":238 - * if offset == 0: - * return (self.ha.arr[word_id], self.ha.arr[word_id+1]) - * if low >= high: # <<<<<<<<<<<<<< - * return None - * - */ - __pyx_t_1 = (__pyx_v_low >= __pyx_v_high); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":239 - * return (self.ha.arr[word_id], self.ha.arr[word_id+1]) - * if low >= high: - * return None # <<<<<<<<<<<<<< - * - * midpoint = (high + low) / 2 - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(Py_None); - __pyx_r = Py_None; - goto __pyx_L0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":241 - * return None - * - * midpoint = (high + low) / 2 # <<<<<<<<<<<<<< - * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: - * return self.__get_range(word_id, offset, low, high, midpoint) - */ - __pyx_v_midpoint = __Pyx_div_long((__pyx_v_high + __pyx_v_low), 2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":242 - * - * midpoint = (high + low) / 2 - * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: # <<<<<<<<<<<<<< - * return self.__get_range(word_id, offset, low, high, midpoint) - * if self.darray.data.arr[self.sa.arr[midpoint] + offset] > word_id: - */ - __pyx_t_1 = ((__pyx_v_self->darray->data->arr[((__pyx_v_self->sa->arr[__pyx_v_midpoint]) + __pyx_v_offset)]) == __pyx_v_word_id); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":243 - * midpoint = (high + low) / 2 - * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: - * return self.__get_range(word_id, offset, low, high, midpoint) # <<<<<<<<<<<<<< - * if self.darray.data.arr[self.sa.arr[midpoint] + offset] > word_id: - * return self.__lookup_helper(word_id, offset, low, midpoint) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = ((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___get_range(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, __pyx_v_low, __pyx_v_high, __pyx_v_midpoint); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":244 - * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: - * return self.__get_range(word_id, offset, low, high, midpoint) - * if self.darray.data.arr[self.sa.arr[midpoint] + offset] > word_id: # <<<<<<<<<<<<<< - * return self.__lookup_helper(word_id, offset, low, midpoint) - * else: - */ - __pyx_t_1 = ((__pyx_v_self->darray->data->arr[((__pyx_v_self->sa->arr[__pyx_v_midpoint]) + __pyx_v_offset)]) > __pyx_v_word_id); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":245 - * return self.__get_range(word_id, offset, low, high, midpoint) - * if self.darray.data.arr[self.sa.arr[midpoint] + offset] > word_id: - * return self.__lookup_helper(word_id, offset, low, midpoint) # <<<<<<<<<<<<<< - * else: - * return self.__lookup_helper(word_id, offset, midpoint+1, high) - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = ((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___lookup_helper(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, __pyx_v_low, __pyx_v_midpoint); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; - goto __pyx_L6; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":247 - * return self.__lookup_helper(word_id, offset, low, midpoint) - * else: - * return self.__lookup_helper(word_id, offset, midpoint+1, high) # <<<<<<<<<<<<<< - * - * def lookup(self, word, int offset, int low, int high): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = ((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___lookup_helper(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, (__pyx_v_midpoint + 1), __pyx_v_high); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; - } - __pyx_L6:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec_sa.SuffixArray.__lookup_helper", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_23lookup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_11SuffixArray_23lookup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_word = 0; - int __pyx_v_offset; - int __pyx_v_low; - int __pyx_v_high; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__word,&__pyx_n_s__offset,&__pyx_n_s__low,&__pyx_n_s__high,0}; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("lookup (wrapper)", 0); - { - PyObject* values[4] = {0,0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__word); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__offset); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("lookup", 1, 4, 4, 1); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__low); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("lookup", 1, 4, 4, 2); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__high); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("lookup", 1, 4, 4, 3); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "lookup") < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - } - __pyx_v_word = values[0]; - __pyx_v_offset = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_offset == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_low = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_low == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_high = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_high == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("lookup", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.SuffixArray.lookup", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_11SuffixArray_22lookup(((struct __pyx_obj_8_cdec_sa_SuffixArray *)__pyx_v_self), __pyx_v_word, __pyx_v_offset, __pyx_v_low, __pyx_v_high); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":249 - * return self.__lookup_helper(word_id, offset, midpoint+1, high) - * - * def lookup(self, word, int offset, int low, int high): # <<<<<<<<<<<<<< - * cdef int wordid - * if low == -1: - */ - -static PyObject *__pyx_pf_8_cdec_sa_11SuffixArray_22lookup(struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_word, int __pyx_v_offset, int __pyx_v_low, int __pyx_v_high) { - PyObject *__pyx_v_word_id = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - Py_ssize_t __pyx_t_3; - int __pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("lookup", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":251 - * def lookup(self, word, int offset, int low, int high): - * cdef int wordid - * if low == -1: # <<<<<<<<<<<<<< - * low = 0 - * if high == -1: - */ - __pyx_t_1 = (__pyx_v_low == -1); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":252 - * cdef int wordid - * if low == -1: - * low = 0 # <<<<<<<<<<<<<< - * if high == -1: - * high = len(self.sa) - */ - __pyx_v_low = 0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":253 - * if low == -1: - * low = 0 - * if high == -1: # <<<<<<<<<<<<<< - * high = len(self.sa) - * if word in self.darray.word2id: - */ - __pyx_t_1 = (__pyx_v_high == -1); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":254 - * low = 0 - * if high == -1: - * high = len(self.sa) # <<<<<<<<<<<<<< - * if word in self.darray.word2id: - * word_id = self.darray.word2id[word] - */ - __pyx_t_2 = ((PyObject *)__pyx_v_self->sa); - __Pyx_INCREF(__pyx_t_2); - __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_high = __pyx_t_3; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":255 - * if high == -1: - * high = len(self.sa) - * if word in self.darray.word2id: # <<<<<<<<<<<<<< - * word_id = self.darray.word2id[word] - * return self.__lookup_helper(word_id, offset, low, high) - */ - __pyx_t_1 = ((PySequence_Contains(__pyx_v_self->darray->word2id, __pyx_v_word))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":256 - * high = len(self.sa) - * if word in self.darray.word2id: - * word_id = self.darray.word2id[word] # <<<<<<<<<<<<<< - * return self.__lookup_helper(word_id, offset, low, high) - * else: - */ - __pyx_t_2 = PyObject_GetItem(__pyx_v_self->darray->word2id, __pyx_v_word); if (!__pyx_t_2) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_word_id = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":257 - * if word in self.darray.word2id: - * word_id = self.darray.word2id[word] - * return self.__lookup_helper(word_id, offset, low, high) # <<<<<<<<<<<<<< - * else: - * return None - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_word_id); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___lookup_helper(__pyx_v_self, __pyx_t_4, __pyx_v_offset, __pyx_v_low, __pyx_v_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L0; - goto __pyx_L5; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":259 - * return self.__lookup_helper(word_id, offset, low, high) - * else: - * return None # <<<<<<<<<<<<<< - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(Py_None); - __pyx_r = Py_None; - goto __pyx_L0; - } - __pyx_L5:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("_cdec_sa.SuffixArray.lookup", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_word_id); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_8TrieNode_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_8TrieNode_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} - if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; - __pyx_r = __pyx_pf_8_cdec_sa_8TrieNode___cinit__(((struct __pyx_obj_8_cdec_sa_TrieNode *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":21 - * cdef public children - * - * def __cinit__(self): # <<<<<<<<<<<<<< - * self.children = {} - * - */ - -static int __pyx_pf_8_cdec_sa_8TrieNode___cinit__(struct __pyx_obj_8_cdec_sa_TrieNode *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":22 - * - * def __cinit__(self): - * self.children = {} # <<<<<<<<<<<<<< - * - * cdef class ExtendedTrieNode(TrieNode): - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __Pyx_GOTREF(__pyx_v_self->children); - __Pyx_DECREF(__pyx_v_self->children); - __pyx_v_self->children = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec_sa.TrieNode.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_8TrieNode_8children_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_8TrieNode_8children_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_8TrieNode_8children___get__(((struct __pyx_obj_8_cdec_sa_TrieNode *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":19 - * - * cdef class TrieNode: - * cdef public children # <<<<<<<<<<<<<< - * - * def __cinit__(self): - */ - -static PyObject *__pyx_pf_8_cdec_sa_8TrieNode_8children___get__(struct __pyx_obj_8_cdec_sa_TrieNode *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->children); - __pyx_r = __pyx_v_self->children; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_8TrieNode_8children_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_8_cdec_sa_8TrieNode_8children_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_8TrieNode_8children_2__set__(((struct __pyx_obj_8_cdec_sa_TrieNode *)__pyx_v_self), ((PyObject *)__pyx_v_value)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_8TrieNode_8children_2__set__(struct __pyx_obj_8_cdec_sa_TrieNode *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(__pyx_v_self->children); - __Pyx_DECREF(__pyx_v_self->children); - __pyx_v_self->children = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_8TrieNode_8children_5__del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pw_8_cdec_sa_8TrieNode_8children_5__del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_8TrieNode_8children_4__del__(((struct __pyx_obj_8_cdec_sa_TrieNode *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_8TrieNode_8children_4__del__(struct __pyx_obj_8_cdec_sa_TrieNode *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__", 0); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->children); - __Pyx_DECREF(__pyx_v_self->children); - __pyx_v_self->children = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_phrase = 0; - PyObject *__pyx_v_phrase_location = 0; - PyObject *__pyx_v_suffix_link = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__phrase,&__pyx_n_s__phrase_location,&__pyx_n_s__suffix_link,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[3] = {0,0,0}; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":29 - * cdef public suffix_link - * - * def __cinit__(self, phrase=None, phrase_location=None, suffix_link=None): # <<<<<<<<<<<<<< - * self.phrase = phrase - * self.phrase_location = phrase_location - */ - values[0] = ((PyObject *)Py_None); - values[1] = ((PyObject *)Py_None); - values[2] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__phrase); - if (value) { values[0] = value; kw_args--; } - } - case 1: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__phrase_location); - if (value) { values[1] = value; kw_args--; } - } - case 2: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__suffix_link); - if (value) { values[2] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_phrase = values[0]; - __pyx_v_phrase_location = values[1]; - __pyx_v_suffix_link = values[2]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.ExtendedTrieNode.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode___cinit__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self), __pyx_v_phrase, __pyx_v_phrase_location, __pyx_v_suffix_link); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode___cinit__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_phrase, PyObject *__pyx_v_phrase_location, PyObject *__pyx_v_suffix_link) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":30 - * - * def __cinit__(self, phrase=None, phrase_location=None, suffix_link=None): - * self.phrase = phrase # <<<<<<<<<<<<<< - * self.phrase_location = phrase_location - * self.suffix_link = suffix_link - */ - __Pyx_INCREF(__pyx_v_phrase); - __Pyx_GIVEREF(__pyx_v_phrase); - __Pyx_GOTREF(__pyx_v_self->phrase); - __Pyx_DECREF(__pyx_v_self->phrase); - __pyx_v_self->phrase = __pyx_v_phrase; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":31 - * def __cinit__(self, phrase=None, phrase_location=None, suffix_link=None): - * self.phrase = phrase - * self.phrase_location = phrase_location # <<<<<<<<<<<<<< - * self.suffix_link = suffix_link - * - */ - __Pyx_INCREF(__pyx_v_phrase_location); - __Pyx_GIVEREF(__pyx_v_phrase_location); - __Pyx_GOTREF(__pyx_v_self->phrase_location); - __Pyx_DECREF(__pyx_v_self->phrase_location); - __pyx_v_self->phrase_location = __pyx_v_phrase_location; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":32 - * self.phrase = phrase - * self.phrase_location = phrase_location - * self.suffix_link = suffix_link # <<<<<<<<<<<<<< - * - * - */ - __Pyx_INCREF(__pyx_v_suffix_link); - __Pyx_GIVEREF(__pyx_v_suffix_link); - __Pyx_GOTREF(__pyx_v_self->suffix_link); - __Pyx_DECREF(__pyx_v_self->suffix_link); - __pyx_v_self->suffix_link = __pyx_v_suffix_link; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_16ExtendedTrieNode_6phrase_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_16ExtendedTrieNode_6phrase_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode_6phrase___get__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":25 - * - * cdef class ExtendedTrieNode(TrieNode): - * cdef public phrase # <<<<<<<<<<<<<< - * cdef public phrase_location - * cdef public suffix_link - */ - -static PyObject *__pyx_pf_8_cdec_sa_16ExtendedTrieNode_6phrase___get__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->phrase); - __pyx_r = __pyx_v_self->phrase; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_6phrase_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_6phrase_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode_6phrase_2__set__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self), ((PyObject *)__pyx_v_value)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_6phrase_2__set__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(__pyx_v_self->phrase); - __Pyx_DECREF(__pyx_v_self->phrase); - __pyx_v_self->phrase = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_6phrase_5__del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_6phrase_5__del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode_6phrase_4__del__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_6phrase_4__del__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__", 0); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->phrase); - __Pyx_DECREF(__pyx_v_self->phrase); - __pyx_v_self->phrase = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_16ExtendedTrieNode_15phrase_location_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_16ExtendedTrieNode_15phrase_location_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode_15phrase_location___get__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":26 - * cdef class ExtendedTrieNode(TrieNode): - * cdef public phrase - * cdef public phrase_location # <<<<<<<<<<<<<< - * cdef public suffix_link - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_16ExtendedTrieNode_15phrase_location___get__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->phrase_location); - __pyx_r = __pyx_v_self->phrase_location; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_15phrase_location_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_15phrase_location_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode_15phrase_location_2__set__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self), ((PyObject *)__pyx_v_value)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_15phrase_location_2__set__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(__pyx_v_self->phrase_location); - __Pyx_DECREF(__pyx_v_self->phrase_location); - __pyx_v_self->phrase_location = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_15phrase_location_5__del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_15phrase_location_5__del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode_15phrase_location_4__del__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_15phrase_location_4__del__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__", 0); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->phrase_location); - __Pyx_DECREF(__pyx_v_self->phrase_location); - __pyx_v_self->phrase_location = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_16ExtendedTrieNode_11suffix_link_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_16ExtendedTrieNode_11suffix_link_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode_11suffix_link___get__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":27 - * cdef public phrase - * cdef public phrase_location - * cdef public suffix_link # <<<<<<<<<<<<<< - * - * def __cinit__(self, phrase=None, phrase_location=None, suffix_link=None): - */ - -static PyObject *__pyx_pf_8_cdec_sa_16ExtendedTrieNode_11suffix_link___get__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->suffix_link); - __pyx_r = __pyx_v_self->suffix_link; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_11suffix_link_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_11suffix_link_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode_11suffix_link_2__set__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self), ((PyObject *)__pyx_v_value)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_11suffix_link_2__set__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(__pyx_v_self->suffix_link); - __Pyx_DECREF(__pyx_v_self->suffix_link); - __pyx_v_self->suffix_link = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_11suffix_link_5__del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pw_8_cdec_sa_16ExtendedTrieNode_11suffix_link_5__del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_16ExtendedTrieNode_11suffix_link_4__del__(((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_16ExtendedTrieNode_11suffix_link_4__del__(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__", 0); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->suffix_link); - __Pyx_DECREF(__pyx_v_self->suffix_link); - __pyx_v_self->suffix_link = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_9TrieTable_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_9TrieTable_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_extended = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__extended,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[1] = {0}; - values[0] = __pyx_k_97; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_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 (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__extended); - if (value) { values[0] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - 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; - } - } - __pyx_v_extended = values[0]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.TrieTable.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_9TrieTable___cinit__(((struct __pyx_obj_8_cdec_sa_TrieTable *)__pyx_v_self), __pyx_v_extended); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":39 - * cdef public int count - * cdef public root - * def __cinit__(self, extended=False): # <<<<<<<<<<<<<< - * self.count = 0 - * self.extended = extended - */ - -static int __pyx_pf_8_cdec_sa_9TrieTable___cinit__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_extended) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":40 - * cdef public root - * def __cinit__(self, extended=False): - * self.count = 0 # <<<<<<<<<<<<<< - * self.extended = extended - * if extended: - */ - __pyx_v_self->count = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":41 - * def __cinit__(self, extended=False): - * self.count = 0 - * self.extended = extended # <<<<<<<<<<<<<< - * if extended: - * self.root = ExtendedTrieNode() - */ - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_extended); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->extended = __pyx_t_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":42 - * self.count = 0 - * self.extended = extended - * if extended: # <<<<<<<<<<<<<< - * self.root = ExtendedTrieNode() - * else: - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_extended); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":43 - * self.extended = extended - * if extended: - * self.root = ExtendedTrieNode() # <<<<<<<<<<<<<< - * else: - * self.root = TrieNode() - */ - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __Pyx_GOTREF(__pyx_v_self->root); - __Pyx_DECREF(__pyx_v_self->root); - __pyx_v_self->root = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":45 - * self.root = ExtendedTrieNode() - * else: - * self.root = TrieNode() # <<<<<<<<<<<<<< - * - * # linked list structure for storing matches in BaselineRuleFactory - */ - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_TrieNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __Pyx_GOTREF(__pyx_v_self->root); - __Pyx_DECREF(__pyx_v_self->root); - __pyx_v_self->root = __pyx_t_3; - __pyx_t_3 = 0; - } - __pyx_L3:; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.TrieTable.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9TrieTable_8extended_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9TrieTable_8extended_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9TrieTable_8extended___get__(((struct __pyx_obj_8_cdec_sa_TrieTable *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":36 - * - * cdef class TrieTable: - * cdef public int extended # <<<<<<<<<<<<<< - * cdef public int count - * cdef public root - */ - -static PyObject *__pyx_pf_8_cdec_sa_9TrieTable_8extended___get__(struct __pyx_obj_8_cdec_sa_TrieTable *__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("__get__", 0); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->extended); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __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_AddTraceback("_cdec_sa.TrieTable.extended.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_9TrieTable_8extended_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_8_cdec_sa_9TrieTable_8extended_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9TrieTable_8extended_2__set__(((struct __pyx_obj_8_cdec_sa_TrieTable *)__pyx_v_self), ((PyObject *)__pyx_v_value)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_9TrieTable_8extended_2__set__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__set__", 0); - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->extended = __pyx_t_1; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec_sa.TrieTable.extended.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9TrieTable_5count_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9TrieTable_5count_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9TrieTable_5count___get__(((struct __pyx_obj_8_cdec_sa_TrieTable *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":37 - * cdef class TrieTable: - * cdef public int extended - * cdef public int count # <<<<<<<<<<<<<< - * cdef public root - * def __cinit__(self, extended=False): - */ - -static PyObject *__pyx_pf_8_cdec_sa_9TrieTable_5count___get__(struct __pyx_obj_8_cdec_sa_TrieTable *__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("__get__", 0); - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyInt_FromLong(__pyx_v_self->count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __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_AddTraceback("_cdec_sa.TrieTable.count.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_9TrieTable_5count_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_8_cdec_sa_9TrieTable_5count_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9TrieTable_5count_2__set__(((struct __pyx_obj_8_cdec_sa_TrieTable *)__pyx_v_self), ((PyObject *)__pyx_v_value)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_9TrieTable_5count_2__set__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__set__", 0); - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->count = __pyx_t_1; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec_sa.TrieTable.count.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_9TrieTable_4root_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_9TrieTable_4root_1__get__(PyObject *__pyx_v_self) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9TrieTable_4root___get__(((struct __pyx_obj_8_cdec_sa_TrieTable *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":38 - * cdef public int extended - * cdef public int count - * cdef public root # <<<<<<<<<<<<<< - * def __cinit__(self, extended=False): - * self.count = 0 - */ - -static PyObject *__pyx_pf_8_cdec_sa_9TrieTable_4root___get__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self) { - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__get__", 0); - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_self->root); - __pyx_r = __pyx_v_self->root; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_9TrieTable_4root_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_8_cdec_sa_9TrieTable_4root_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9TrieTable_4root_2__set__(((struct __pyx_obj_8_cdec_sa_TrieTable *)__pyx_v_self), ((PyObject *)__pyx_v_value)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_9TrieTable_4root_2__set__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__", 0); - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(__pyx_v_self->root); - __Pyx_DECREF(__pyx_v_self->root); - __pyx_v_self->root = __pyx_v_value; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_9TrieTable_4root_5__del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pw_8_cdec_sa_9TrieTable_4root_5__del__(PyObject *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_9TrieTable_4root_4__del__(((struct __pyx_obj_8_cdec_sa_TrieTable *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static int __pyx_pf_8_cdec_sa_9TrieTable_4root_4__del__(struct __pyx_obj_8_cdec_sa_TrieTable *__pyx_v_self) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__", 0); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->root); - __Pyx_DECREF(__pyx_v_self->root); - __pyx_v_self->root = Py_None; - - __pyx_r = 0; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":65 - * - * # returns true if sent_id is contained - * cdef int contains(self, int sent_id): # <<<<<<<<<<<<<< - * return 1 - * - */ - -static int __pyx_f_8_cdec_sa_14PhraseLocation_contains(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_self, CYTHON_UNUSED int __pyx_v_sent_id) { - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("contains", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":66 - * # returns true if sent_id is contained - * cdef int contains(self, int sent_id): - * return 1 # <<<<<<<<<<<<<< - * - * def __cinit__(self, int sa_low=-1, int sa_high=-1, int arr_low=-1, int arr_high=-1, - */ - __pyx_r = 1; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_14PhraseLocation_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_14PhraseLocation_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_v_sa_low; - int __pyx_v_sa_high; - int __pyx_v_arr_low; - int __pyx_v_arr_high; - PyObject *__pyx_v_arr = 0; - int __pyx_v_num_subpatterns; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sa_low,&__pyx_n_s__sa_high,&__pyx_n_s__arr_low,&__pyx_n_s__arr_high,&__pyx_n_s__arr,&__pyx_n_s__num_subpatterns,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[6] = {0,0,0,0,0,0}; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":69 - * - * def __cinit__(self, int sa_low=-1, int sa_high=-1, int arr_low=-1, int arr_high=-1, - * arr=None, int num_subpatterns=1): # <<<<<<<<<<<<<< - * self.sa_low = sa_low - * self.sa_high = sa_high - */ - values[4] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sa_low); - if (value) { values[0] = value; kw_args--; } - } - case 1: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sa_high); - if (value) { values[1] = value; kw_args--; } - } - case 2: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__arr_low); - if (value) { values[2] = value; kw_args--; } - } - case 3: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__arr_high); - if (value) { values[3] = value; kw_args--; } - } - case 4: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__arr); - if (value) { values[4] = value; kw_args--; } - } - case 5: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__num_subpatterns); - if (value) { values[5] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - if (values[0]) { - } else { - __pyx_v_sa_low = ((int)-1); - } - if (values[1]) { - } else { - __pyx_v_sa_high = ((int)-1); - } - if (values[2]) { - } else { - __pyx_v_arr_low = ((int)-1); - } - if (values[3]) { - } else { - __pyx_v_arr_high = ((int)-1); - } - if (values[5]) { - } else { - __pyx_v_num_subpatterns = ((int)1); - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - } - if (values[0]) { - __pyx_v_sa_low = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_sa_low == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_sa_low = ((int)-1); - } - if (values[1]) { - __pyx_v_sa_high = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_sa_high == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_sa_high = ((int)-1); - } - if (values[2]) { - __pyx_v_arr_low = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_arr_low == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_arr_low = ((int)-1); - } - if (values[3]) { - __pyx_v_arr_high = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_arr_high == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_arr_high = ((int)-1); - } - __pyx_v_arr = values[4]; - if (values[5]) { - __pyx_v_num_subpatterns = __Pyx_PyInt_AsInt(values[5]); if (unlikely((__pyx_v_num_subpatterns == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_num_subpatterns = ((int)1); - } - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.PhraseLocation.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_14PhraseLocation___cinit__(((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_v_self), __pyx_v_sa_low, __pyx_v_sa_high, __pyx_v_arr_low, __pyx_v_arr_high, __pyx_v_arr, __pyx_v_num_subpatterns); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":68 - * return 1 - * - * def __cinit__(self, int sa_low=-1, int sa_high=-1, int arr_low=-1, int arr_high=-1, # <<<<<<<<<<<<<< - * arr=None, int num_subpatterns=1): - * self.sa_low = sa_low - */ - -static int __pyx_pf_8_cdec_sa_14PhraseLocation___cinit__(struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_self, int __pyx_v_sa_low, int __pyx_v_sa_high, int __pyx_v_arr_low, int __pyx_v_arr_high, PyObject *__pyx_v_arr, int __pyx_v_num_subpatterns) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":70 - * def __cinit__(self, int sa_low=-1, int sa_high=-1, int arr_low=-1, int arr_high=-1, - * arr=None, int num_subpatterns=1): - * self.sa_low = sa_low # <<<<<<<<<<<<<< - * self.sa_high = sa_high - * self.arr_low = arr_low - */ - __pyx_v_self->sa_low = __pyx_v_sa_low; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":71 - * arr=None, int num_subpatterns=1): - * self.sa_low = sa_low - * self.sa_high = sa_high # <<<<<<<<<<<<<< - * self.arr_low = arr_low - * self.arr_high = arr_high - */ - __pyx_v_self->sa_high = __pyx_v_sa_high; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":72 - * self.sa_low = sa_low - * self.sa_high = sa_high - * self.arr_low = arr_low # <<<<<<<<<<<<<< - * self.arr_high = arr_high - * self.arr = arr - */ - __pyx_v_self->arr_low = __pyx_v_arr_low; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":73 - * self.sa_high = sa_high - * self.arr_low = arr_low - * self.arr_high = arr_high # <<<<<<<<<<<<<< - * self.arr = arr - * self.num_subpatterns = num_subpatterns - */ - __pyx_v_self->arr_high = __pyx_v_arr_high; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":74 - * self.arr_low = arr_low - * self.arr_high = arr_high - * self.arr = arr # <<<<<<<<<<<<<< - * self.num_subpatterns = num_subpatterns - * - */ - if (!(likely(((__pyx_v_arr) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_arr, __pyx_ptype_8_cdec_sa_IntList))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_INCREF(__pyx_v_arr); - __Pyx_GIVEREF(__pyx_v_arr); - __Pyx_GOTREF(__pyx_v_self->arr); - __Pyx_DECREF(((PyObject *)__pyx_v_self->arr)); - __pyx_v_self->arr = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_v_arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":75 - * self.arr_high = arr_high - * self.arr = arr - * self.num_subpatterns = num_subpatterns # <<<<<<<<<<<<<< - * - * - */ - __pyx_v_self->num_subpatterns = __pyx_v_num_subpatterns; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec_sa.PhraseLocation.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_7Sampler_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_7Sampler_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - int __pyx_v_sample_size; - struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_fsarray = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sample_size,&__pyx_n_s__fsarray,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sample_size); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fsarray); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 2, 2, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_sample_size = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_sample_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_fsarray = ((struct __pyx_obj_8_cdec_sa_SuffixArray *)values[1]); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.Sampler.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fsarray), __pyx_ptype_8_cdec_sa_SuffixArray, 1, "fsarray", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_8_cdec_sa_7Sampler___cinit__(((struct __pyx_obj_8_cdec_sa_Sampler *)__pyx_v_self), __pyx_v_sample_size, __pyx_v_fsarray); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":86 - * cdef IntList sa - * - * def __cinit__(self, int sample_size, SuffixArray fsarray): # <<<<<<<<<<<<<< - * self.sample_size = sample_size - * self.sa = fsarray.sa - */ - -static int __pyx_pf_8_cdec_sa_7Sampler___cinit__(struct __pyx_obj_8_cdec_sa_Sampler *__pyx_v_self, int __pyx_v_sample_size, struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_fsarray) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":87 - * - * def __cinit__(self, int sample_size, SuffixArray fsarray): - * self.sample_size = sample_size # <<<<<<<<<<<<<< - * self.sa = fsarray.sa - * if sample_size > 0: - */ - __pyx_v_self->sample_size = __pyx_v_sample_size; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":88 - * def __cinit__(self, int sample_size, SuffixArray fsarray): - * self.sample_size = sample_size - * self.sa = fsarray.sa # <<<<<<<<<<<<<< - * if sample_size > 0: - * logger.info("Sampling strategy: uniform, max sample size = %d", sample_size) - */ - __Pyx_INCREF(((PyObject *)__pyx_v_fsarray->sa)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_fsarray->sa)); - __Pyx_GOTREF(__pyx_v_self->sa); - __Pyx_DECREF(((PyObject *)__pyx_v_self->sa)); - __pyx_v_self->sa = __pyx_v_fsarray->sa; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":89 - * self.sample_size = sample_size - * self.sa = fsarray.sa - * if sample_size > 0: # <<<<<<<<<<<<<< - * logger.info("Sampling strategy: uniform, max sample size = %d", sample_size) - * else: - */ - __pyx_t_1 = (__pyx_v_sample_size > 0); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":90 - * self.sa = fsarray.sa - * if sample_size > 0: - * logger.info("Sampling strategy: uniform, max sample size = %d", sample_size) # <<<<<<<<<<<<<< - * else: - * logger.info("Sampling strategy: no sampling") - */ - __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__info); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyInt_FromLong(__pyx_v_sample_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_98)); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_s_98)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_98)); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":92 - * logger.info("Sampling strategy: uniform, max sample size = %d", sample_size) - * else: - * logger.info("Sampling strategy: no sampling") # <<<<<<<<<<<<<< - * - * def sample(self, PhraseLocation phrase_location): - */ - __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__info); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_100), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __pyx_L3:; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec_sa.Sampler.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_7Sampler_3sample(PyObject *__pyx_v_self, PyObject *__pyx_v_phrase_location); /*proto*/ -static char __pyx_doc_8_cdec_sa_7Sampler_2sample[] = "Returns a sample of the locations for\n the phrase. If there are less than self.sample_size\n locations, return all of them; otherwise, return\n up to self.sample_size locations. In the latter case,\n we choose to sample UNIFORMLY -- that is, the locations\n are chosen at uniform intervals over the entire set, rather\n than randomly. This makes the algorithm deterministic, which\n is good for things like MERT"; -static PyObject *__pyx_pw_8_cdec_sa_7Sampler_3sample(PyObject *__pyx_v_self, PyObject *__pyx_v_phrase_location) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("sample (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_phrase_location), __pyx_ptype_8_cdec_sa_PhraseLocation, 1, "phrase_location", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_8_cdec_sa_7Sampler_2sample(((struct __pyx_obj_8_cdec_sa_Sampler *)__pyx_v_self), ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_v_phrase_location)); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":94 - * logger.info("Sampling strategy: no sampling") - * - * def sample(self, PhraseLocation phrase_location): # <<<<<<<<<<<<<< - * '''Returns a sample of the locations for - * the phrase. If there are less than self.sample_size - */ - -static PyObject *__pyx_pf_8_cdec_sa_7Sampler_2sample(struct __pyx_obj_8_cdec_sa_Sampler *__pyx_v_self, struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_phrase_location) { - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_sample = 0; - double __pyx_v_i; - double __pyx_v_stepsize; - int __pyx_v_num_locations; - int __pyx_v_val; - int __pyx_v_j; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("sample", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":107 - * cdef int num_locations, val, j - * - * sample = IntList() # <<<<<<<<<<<<<< - * if phrase_location.arr is None: - * num_locations = phrase_location.sa_high - phrase_location.sa_low - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_sample = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":108 - * - * sample = IntList() - * if phrase_location.arr is None: # <<<<<<<<<<<<<< - * num_locations = phrase_location.sa_high - phrase_location.sa_low - * if self.sample_size == -1 or num_locations <= self.sample_size: - */ - __pyx_t_2 = (((PyObject *)__pyx_v_phrase_location->arr) == Py_None); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":109 - * sample = IntList() - * if phrase_location.arr is None: - * num_locations = phrase_location.sa_high - phrase_location.sa_low # <<<<<<<<<<<<<< - * if self.sample_size == -1 or num_locations <= self.sample_size: - * sample._extend_arr(self.sa.arr + phrase_location.sa_low, num_locations) - */ - __pyx_v_num_locations = (__pyx_v_phrase_location->sa_high - __pyx_v_phrase_location->sa_low); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":110 - * if phrase_location.arr is None: - * num_locations = phrase_location.sa_high - phrase_location.sa_low - * if self.sample_size == -1 or num_locations <= self.sample_size: # <<<<<<<<<<<<<< - * sample._extend_arr(self.sa.arr + phrase_location.sa_low, num_locations) - * else: - */ - __pyx_t_2 = (__pyx_v_self->sample_size == -1); - if (!__pyx_t_2) { - __pyx_t_3 = (__pyx_v_num_locations <= __pyx_v_self->sample_size); - __pyx_t_4 = __pyx_t_3; - } else { - __pyx_t_4 = __pyx_t_2; - } - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":111 - * num_locations = phrase_location.sa_high - phrase_location.sa_low - * if self.sample_size == -1 or num_locations <= self.sample_size: - * sample._extend_arr(self.sa.arr + phrase_location.sa_low, num_locations) # <<<<<<<<<<<<<< - * else: - * stepsize = float(num_locations)/float(self.sample_size) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_sample->__pyx_vtab)->_extend_arr(__pyx_v_sample, (__pyx_v_self->sa->arr + __pyx_v_phrase_location->sa_low), __pyx_v_num_locations); - goto __pyx_L4; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":113 - * sample._extend_arr(self.sa.arr + phrase_location.sa_low, num_locations) - * else: - * stepsize = float(num_locations)/float(self.sample_size) # <<<<<<<<<<<<<< - * i = phrase_location.sa_low - * while i < phrase_location.sa_high and sample.len < self.sample_size: - */ - if (unlikely(((double)__pyx_v_self->sample_size) == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_stepsize = (((double)__pyx_v_num_locations) / ((double)__pyx_v_self->sample_size)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":114 - * else: - * stepsize = float(num_locations)/float(self.sample_size) - * i = phrase_location.sa_low # <<<<<<<<<<<<<< - * while i < phrase_location.sa_high and sample.len < self.sample_size: - * '''Note: int(i) not guaranteed to have the desired - */ - __pyx_v_i = __pyx_v_phrase_location->sa_low; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":115 - * stepsize = float(num_locations)/float(self.sample_size) - * i = phrase_location.sa_low - * while i < phrase_location.sa_high and sample.len < self.sample_size: # <<<<<<<<<<<<<< - * '''Note: int(i) not guaranteed to have the desired - * effect, according to the python documentation''' - */ - while (1) { - __pyx_t_4 = (__pyx_v_i < __pyx_v_phrase_location->sa_high); - if (__pyx_t_4) { - __pyx_t_2 = (__pyx_v_sample->len < __pyx_v_self->sample_size); - __pyx_t_3 = __pyx_t_2; - } else { - __pyx_t_3 = __pyx_t_4; - } - if (!__pyx_t_3) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":118 - * '''Note: int(i) not guaranteed to have the desired - * effect, according to the python documentation''' - * if fmod(i,1.0) > 0.5: # <<<<<<<<<<<<<< - * val = int(ceil(i)) - * else: - */ - __pyx_t_3 = (fmod(__pyx_v_i, 1.0) > 0.5); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":119 - * effect, according to the python documentation''' - * if fmod(i,1.0) > 0.5: - * val = int(ceil(i)) # <<<<<<<<<<<<<< - * else: - * val = int(floor(i)) - */ - __pyx_v_val = ((int)ceil(__pyx_v_i)); - goto __pyx_L7; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":121 - * val = int(ceil(i)) - * else: - * val = int(floor(i)) # <<<<<<<<<<<<<< - * sample._append(self.sa.arr[val]) - * i = i + stepsize - */ - __pyx_v_val = ((int)floor(__pyx_v_i)); - } - __pyx_L7:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":122 - * else: - * val = int(floor(i)) - * sample._append(self.sa.arr[val]) # <<<<<<<<<<<<<< - * i = i + stepsize - * else: - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_sample->__pyx_vtab)->_append(__pyx_v_sample, (__pyx_v_self->sa->arr[__pyx_v_val])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":123 - * val = int(floor(i)) - * sample._append(self.sa.arr[val]) - * i = i + stepsize # <<<<<<<<<<<<<< - * else: - * num_locations = (phrase_location.arr_high - phrase_location.arr_low) / phrase_location.num_subpatterns - */ - __pyx_v_i = (__pyx_v_i + __pyx_v_stepsize); - } - } - __pyx_L4:; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":125 - * i = i + stepsize - * else: - * num_locations = (phrase_location.arr_high - phrase_location.arr_low) / phrase_location.num_subpatterns # <<<<<<<<<<<<<< - * if self.sample_size == -1 or num_locations <= self.sample_size: - * sample = phrase_location.arr - */ - __pyx_t_5 = (__pyx_v_phrase_location->arr_high - __pyx_v_phrase_location->arr_low); - if (unlikely(__pyx_v_phrase_location->num_subpatterns == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_phrase_location->num_subpatterns == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_5))) { - PyErr_Format(PyExc_OverflowError, "value too large to perform division"); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_num_locations = __Pyx_div_int(__pyx_t_5, __pyx_v_phrase_location->num_subpatterns); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":126 - * else: - * num_locations = (phrase_location.arr_high - phrase_location.arr_low) / phrase_location.num_subpatterns - * if self.sample_size == -1 or num_locations <= self.sample_size: # <<<<<<<<<<<<<< - * sample = phrase_location.arr - * else: - */ - __pyx_t_3 = (__pyx_v_self->sample_size == -1); - if (!__pyx_t_3) { - __pyx_t_4 = (__pyx_v_num_locations <= __pyx_v_self->sample_size); - __pyx_t_2 = __pyx_t_4; - } else { - __pyx_t_2 = __pyx_t_3; - } - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":127 - * num_locations = (phrase_location.arr_high - phrase_location.arr_low) / phrase_location.num_subpatterns - * if self.sample_size == -1 or num_locations <= self.sample_size: - * sample = phrase_location.arr # <<<<<<<<<<<<<< - * else: - * stepsize = float(num_locations)/float(self.sample_size) - */ - __Pyx_INCREF(((PyObject *)__pyx_v_phrase_location->arr)); - __Pyx_DECREF(((PyObject *)__pyx_v_sample)); - __pyx_v_sample = __pyx_v_phrase_location->arr; - goto __pyx_L8; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":129 - * sample = phrase_location.arr - * else: - * stepsize = float(num_locations)/float(self.sample_size) # <<<<<<<<<<<<<< - * i = phrase_location.arr_low - * while i < num_locations and sample.len < self.sample_size * phrase_location.num_subpatterns: - */ - if (unlikely(((double)__pyx_v_self->sample_size) == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_stepsize = (((double)__pyx_v_num_locations) / ((double)__pyx_v_self->sample_size)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":130 - * else: - * stepsize = float(num_locations)/float(self.sample_size) - * i = phrase_location.arr_low # <<<<<<<<<<<<<< - * while i < num_locations and sample.len < self.sample_size * phrase_location.num_subpatterns: - * '''Note: int(i) not guaranteed to have the desired - */ - __pyx_v_i = __pyx_v_phrase_location->arr_low; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":131 - * stepsize = float(num_locations)/float(self.sample_size) - * i = phrase_location.arr_low - * while i < num_locations and sample.len < self.sample_size * phrase_location.num_subpatterns: # <<<<<<<<<<<<<< - * '''Note: int(i) not guaranteed to have the desired - * effect, according to the python documentation''' - */ - while (1) { - __pyx_t_2 = (__pyx_v_i < __pyx_v_num_locations); - if (__pyx_t_2) { - __pyx_t_3 = (__pyx_v_sample->len < (__pyx_v_self->sample_size * __pyx_v_phrase_location->num_subpatterns)); - __pyx_t_4 = __pyx_t_3; - } else { - __pyx_t_4 = __pyx_t_2; - } - if (!__pyx_t_4) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":134 - * '''Note: int(i) not guaranteed to have the desired - * effect, according to the python documentation''' - * if fmod(i,1.0) > 0.5: # <<<<<<<<<<<<<< - * val = int(ceil(i)) - * else: - */ - __pyx_t_4 = (fmod(__pyx_v_i, 1.0) > 0.5); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":135 - * effect, according to the python documentation''' - * if fmod(i,1.0) > 0.5: - * val = int(ceil(i)) # <<<<<<<<<<<<<< - * else: - * val = int(floor(i)) - */ - __pyx_v_val = ((int)ceil(__pyx_v_i)); - goto __pyx_L11; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":137 - * val = int(ceil(i)) - * else: - * val = int(floor(i)) # <<<<<<<<<<<<<< - * j = phrase_location.arr_low + (val*phrase_location.num_subpatterns) - * sample._extend_arr(phrase_location.arr.arr + j, phrase_location.num_subpatterns) - */ - __pyx_v_val = ((int)floor(__pyx_v_i)); - } - __pyx_L11:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":138 - * else: - * val = int(floor(i)) - * j = phrase_location.arr_low + (val*phrase_location.num_subpatterns) # <<<<<<<<<<<<<< - * sample._extend_arr(phrase_location.arr.arr + j, phrase_location.num_subpatterns) - * i = i + stepsize - */ - __pyx_v_j = (__pyx_v_phrase_location->arr_low + (__pyx_v_val * __pyx_v_phrase_location->num_subpatterns)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":139 - * val = int(floor(i)) - * j = phrase_location.arr_low + (val*phrase_location.num_subpatterns) - * sample._extend_arr(phrase_location.arr.arr + j, phrase_location.num_subpatterns) # <<<<<<<<<<<<<< - * i = i + stepsize - * return sample - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_sample->__pyx_vtab)->_extend_arr(__pyx_v_sample, (__pyx_v_phrase_location->arr->arr + __pyx_v_j), __pyx_v_phrase_location->num_subpatterns); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":140 - * j = phrase_location.arr_low + (val*phrase_location.num_subpatterns) - * sample._extend_arr(phrase_location.arr.arr + j, phrase_location.num_subpatterns) - * i = i + stepsize # <<<<<<<<<<<<<< - * return sample - * - */ - __pyx_v_i = (__pyx_v_i + __pyx_v_stepsize); - } - } - __pyx_L8:; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":141 - * sample._extend_arr(phrase_location.arr.arr + j, phrase_location.num_subpatterns) - * i = i + stepsize - * return sample # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_sample)); - __pyx_r = ((PyObject *)__pyx_v_sample); - 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_sa.Sampler.sample", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_sample); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":153 - * - * - * cdef void assign_matching(Matching* m, int* arr, int start, int step, int* sent_id_arr): # <<<<<<<<<<<<<< - * m.arr = arr - * m.start = start - */ - -static void __pyx_f_8_cdec_sa_assign_matching(struct __pyx_t_8_cdec_sa_Matching *__pyx_v_m, int *__pyx_v_arr, int __pyx_v_start, int __pyx_v_step, int *__pyx_v_sent_id_arr) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("assign_matching", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":154 - * - * cdef void assign_matching(Matching* m, int* arr, int start, int step, int* sent_id_arr): - * m.arr = arr # <<<<<<<<<<<<<< - * m.start = start - * m.end = start + step - */ - __pyx_v_m->arr = __pyx_v_arr; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":155 - * cdef void assign_matching(Matching* m, int* arr, int start, int step, int* sent_id_arr): - * m.arr = arr - * m.start = start # <<<<<<<<<<<<<< - * m.end = start + step - * m.sent_id = sent_id_arr[arr[start]] - */ - __pyx_v_m->start = __pyx_v_start; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":156 - * m.arr = arr - * m.start = start - * m.end = start + step # <<<<<<<<<<<<<< - * m.sent_id = sent_id_arr[arr[start]] - * m.size = step - */ - __pyx_v_m->end = (__pyx_v_start + __pyx_v_step); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":157 - * m.start = start - * m.end = start + step - * m.sent_id = sent_id_arr[arr[start]] # <<<<<<<<<<<<<< - * m.size = step - * - */ - __pyx_v_m->sent_id = (__pyx_v_sent_id_arr[(__pyx_v_arr[__pyx_v_start])]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":158 - * m.end = start + step - * m.sent_id = sent_id_arr[arr[start]] - * m.size = step # <<<<<<<<<<<<<< - * - * - */ - __pyx_v_m->size = __pyx_v_step; - - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":161 - * - * - * cdef int* append_combined_matching(int* arr, Matching* loc1, Matching* loc2, # <<<<<<<<<<<<<< - * int offset_by_one, int num_subpatterns, int* result_len): - * cdef int i, new_len - */ - -static int *__pyx_f_8_cdec_sa_append_combined_matching(int *__pyx_v_arr, struct __pyx_t_8_cdec_sa_Matching *__pyx_v_loc1, struct __pyx_t_8_cdec_sa_Matching *__pyx_v_loc2, CYTHON_UNUSED int __pyx_v_offset_by_one, int __pyx_v_num_subpatterns, int *__pyx_v_result_len) { - int __pyx_v_i; - int __pyx_v_new_len; - int *__pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - __Pyx_RefNannySetupContext("append_combined_matching", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":165 - * cdef int i, new_len - * - * new_len = result_len[0] + num_subpatterns # <<<<<<<<<<<<<< - * arr = realloc(arr, new_len*sizeof(int)) - * - */ - __pyx_v_new_len = ((__pyx_v_result_len[0]) + __pyx_v_num_subpatterns); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":166 - * - * new_len = result_len[0] + num_subpatterns - * arr = realloc(arr, new_len*sizeof(int)) # <<<<<<<<<<<<<< - * - * for i from 0 <= i < loc1.size: - */ - __pyx_v_arr = ((int *)realloc(__pyx_v_arr, (__pyx_v_new_len * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":168 - * arr = realloc(arr, new_len*sizeof(int)) - * - * for i from 0 <= i < loc1.size: # <<<<<<<<<<<<<< - * arr[result_len[0]+i] = loc1.arr[loc1.start+i] - * if num_subpatterns > loc1.size: - */ - __pyx_t_1 = __pyx_v_loc1->size; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":169 - * - * for i from 0 <= i < loc1.size: - * arr[result_len[0]+i] = loc1.arr[loc1.start+i] # <<<<<<<<<<<<<< - * if num_subpatterns > loc1.size: - * arr[new_len-1] = loc2.arr[loc2.end-1] - */ - (__pyx_v_arr[((__pyx_v_result_len[0]) + __pyx_v_i)]) = (__pyx_v_loc1->arr[(__pyx_v_loc1->start + __pyx_v_i)]); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":170 - * for i from 0 <= i < loc1.size: - * arr[result_len[0]+i] = loc1.arr[loc1.start+i] - * if num_subpatterns > loc1.size: # <<<<<<<<<<<<<< - * arr[new_len-1] = loc2.arr[loc2.end-1] - * result_len[0] = new_len - */ - __pyx_t_2 = (__pyx_v_num_subpatterns > __pyx_v_loc1->size); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":171 - * arr[result_len[0]+i] = loc1.arr[loc1.start+i] - * if num_subpatterns > loc1.size: - * arr[new_len-1] = loc2.arr[loc2.end-1] # <<<<<<<<<<<<<< - * result_len[0] = new_len - * return arr - */ - (__pyx_v_arr[(__pyx_v_new_len - 1)]) = (__pyx_v_loc2->arr[(__pyx_v_loc2->end - 1)]); - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":172 - * if num_subpatterns > loc1.size: - * arr[new_len-1] = loc2.arr[loc2.end-1] - * result_len[0] = new_len # <<<<<<<<<<<<<< - * return arr - * - */ - (__pyx_v_result_len[0]) = __pyx_v_new_len; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":173 - * arr[new_len-1] = loc2.arr[loc2.end-1] - * result_len[0] = new_len - * return arr # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = __pyx_v_arr; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":176 - * - * - * cdef int* extend_arr(int* arr, int* arr_len, int* appendix, int appendix_len): # <<<<<<<<<<<<<< - * cdef int new_len - * - */ - -static int *__pyx_f_8_cdec_sa_extend_arr(int *__pyx_v_arr, int *__pyx_v_arr_len, int *__pyx_v_appendix, int __pyx_v_appendix_len) { - int __pyx_v_new_len; - int *__pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("extend_arr", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":179 - * cdef int new_len - * - * new_len = arr_len[0] + appendix_len # <<<<<<<<<<<<<< - * arr = realloc(arr, new_len*sizeof(int)) - * memcpy(arr+arr_len[0], appendix, appendix_len*sizeof(int)) - */ - __pyx_v_new_len = ((__pyx_v_arr_len[0]) + __pyx_v_appendix_len); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":180 - * - * new_len = arr_len[0] + appendix_len - * arr = realloc(arr, new_len*sizeof(int)) # <<<<<<<<<<<<<< - * memcpy(arr+arr_len[0], appendix, appendix_len*sizeof(int)) - * arr_len[0] = new_len - */ - __pyx_v_arr = ((int *)realloc(__pyx_v_arr, (__pyx_v_new_len * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":181 - * new_len = arr_len[0] + appendix_len - * arr = realloc(arr, new_len*sizeof(int)) - * memcpy(arr+arr_len[0], appendix, appendix_len*sizeof(int)) # <<<<<<<<<<<<<< - * arr_len[0] = new_len - * return arr - */ - memcpy((__pyx_v_arr + (__pyx_v_arr_len[0])), __pyx_v_appendix, (__pyx_v_appendix_len * (sizeof(int)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":182 - * arr = realloc(arr, new_len*sizeof(int)) - * memcpy(arr+arr_len[0], appendix, appendix_len*sizeof(int)) - * arr_len[0] = new_len # <<<<<<<<<<<<<< - * return arr - * - */ - (__pyx_v_arr_len[0]) = __pyx_v_new_len; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":183 - * memcpy(arr+arr_len[0], appendix, appendix_len*sizeof(int)) - * arr_len[0] = new_len - * return arr # <<<<<<<<<<<<<< - * - * cdef int median(int low, int high, int step): - */ - __pyx_r = __pyx_v_arr; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":185 - * return arr - * - * cdef int median(int low, int high, int step): # <<<<<<<<<<<<<< - * return low + (((high - low)/step)/2)*step - * - */ - -static int __pyx_f_8_cdec_sa_median(int __pyx_v_low, int __pyx_v_high, int __pyx_v_step) { - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("median", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":186 - * - * cdef int median(int low, int high, int step): - * return low + (((high - low)/step)/2)*step # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_1 = (__pyx_v_high - __pyx_v_low); - if (unlikely(__pyx_v_step == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_step == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_1))) { - PyErr_Format(PyExc_OverflowError, "value too large to perform division"); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_r = (__pyx_v_low + (__Pyx_div_long(__Pyx_div_int(__pyx_t_1, __pyx_v_step), 2) * __pyx_v_step)); - goto __pyx_L0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_WriteUnraisable("_cdec_sa.median", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":189 - * - * - * cdef void find_comparable_matchings(int low, int high, int* arr, int step, int loc, int* loc_minus, int* loc_plus): # <<<<<<<<<<<<<< - * # Returns (minus, plus) indices for the portion of the array - * # in which all matchings have the same first index as the one - */ - -static void __pyx_f_8_cdec_sa_find_comparable_matchings(int __pyx_v_low, int __pyx_v_high, int *__pyx_v_arr, int __pyx_v_step, int __pyx_v_loc, int *__pyx_v_loc_minus, int *__pyx_v_loc_plus) { - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("find_comparable_matchings", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":193 - * # in which all matchings have the same first index as the one - * # starting at loc - * loc_plus[0] = loc + step # <<<<<<<<<<<<<< - * while loc_plus[0] < high and arr[loc_plus[0]] == arr[loc]: - * loc_plus[0] = loc_plus[0] + step - */ - (__pyx_v_loc_plus[0]) = (__pyx_v_loc + __pyx_v_step); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":194 - * # starting at loc - * loc_plus[0] = loc + step - * while loc_plus[0] < high and arr[loc_plus[0]] == arr[loc]: # <<<<<<<<<<<<<< - * loc_plus[0] = loc_plus[0] + step - * loc_minus[0] = loc - */ - while (1) { - __pyx_t_1 = ((__pyx_v_loc_plus[0]) < __pyx_v_high); - if (__pyx_t_1) { - __pyx_t_2 = ((__pyx_v_arr[(__pyx_v_loc_plus[0])]) == (__pyx_v_arr[__pyx_v_loc])); - __pyx_t_3 = __pyx_t_2; - } else { - __pyx_t_3 = __pyx_t_1; - } - if (!__pyx_t_3) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":195 - * loc_plus[0] = loc + step - * while loc_plus[0] < high and arr[loc_plus[0]] == arr[loc]: - * loc_plus[0] = loc_plus[0] + step # <<<<<<<<<<<<<< - * loc_minus[0] = loc - * while loc_minus[0]-step >= low and arr[loc_minus[0]-step] == arr[loc]: - */ - (__pyx_v_loc_plus[0]) = ((__pyx_v_loc_plus[0]) + __pyx_v_step); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":196 - * while loc_plus[0] < high and arr[loc_plus[0]] == arr[loc]: - * loc_plus[0] = loc_plus[0] + step - * loc_minus[0] = loc # <<<<<<<<<<<<<< - * while loc_minus[0]-step >= low and arr[loc_minus[0]-step] == arr[loc]: - * loc_minus[0] = loc_minus[0] - step - */ - (__pyx_v_loc_minus[0]) = __pyx_v_loc; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":197 - * loc_plus[0] = loc_plus[0] + step - * loc_minus[0] = loc - * while loc_minus[0]-step >= low and arr[loc_minus[0]-step] == arr[loc]: # <<<<<<<<<<<<<< - * loc_minus[0] = loc_minus[0] - step - * - */ - while (1) { - __pyx_t_3 = (((__pyx_v_loc_minus[0]) - __pyx_v_step) >= __pyx_v_low); - if (__pyx_t_3) { - __pyx_t_1 = ((__pyx_v_arr[((__pyx_v_loc_minus[0]) - __pyx_v_step)]) == (__pyx_v_arr[__pyx_v_loc])); - __pyx_t_2 = __pyx_t_1; - } else { - __pyx_t_2 = __pyx_t_3; - } - if (!__pyx_t_2) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":198 - * loc_minus[0] = loc - * while loc_minus[0]-step >= low and arr[loc_minus[0]-step] == arr[loc]: - * loc_minus[0] = loc_minus[0] - step # <<<<<<<<<<<<<< - * - * - */ - (__pyx_v_loc_minus[0]) = ((__pyx_v_loc_minus[0]) - __pyx_v_step); - } - - __Pyx_RefNannyFinishContext(); -} - -/* Python wrapper */ -static int __pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_alignment = 0; - float __pyx_v_by_slack_factor; - char *__pyx_v_category; - PyObject *__pyx_v_max_chunks = 0; - unsigned int __pyx_v_max_initial_size; - unsigned int __pyx_v_max_length; - unsigned int __pyx_v_max_nonterminals; - PyObject *__pyx_v_max_target_chunks = 0; - PyObject *__pyx_v_max_target_length = 0; - unsigned int __pyx_v_min_gap_size; - PyObject *__pyx_v_precompute_file = 0; - unsigned int __pyx_v_precompute_secondary_rank; - unsigned int __pyx_v_precompute_rank; - int __pyx_v_require_aligned_terminal; - int __pyx_v_require_aligned_chunks; - unsigned int __pyx_v_train_max_initial_size; - unsigned int __pyx_v_train_min_gap_size; - int __pyx_v_tight_phrases; - int __pyx_v_use_baeza_yates; - int __pyx_v_use_collocations; - int __pyx_v_use_index; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__alignment,&__pyx_n_s__by_slack_factor,&__pyx_n_s__category,&__pyx_n_s__max_chunks,&__pyx_n_s__max_initial_size,&__pyx_n_s__max_length,&__pyx_n_s__max_nonterminals,&__pyx_n_s__max_target_chunks,&__pyx_n_s__max_target_length,&__pyx_n_s__min_gap_size,&__pyx_n_s__precompute_file,&__pyx_n_s_68,&__pyx_n_s__precompute_rank,&__pyx_n_s_101,&__pyx_n_s_102,&__pyx_n_s_69,&__pyx_n_s__train_min_gap_size,&__pyx_n_s__tight_phrases,&__pyx_n_s__use_baeza_yates,&__pyx_n_s__use_collocations,&__pyx_n_s__use_index,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[21] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":257 - * char* category="[X]", - * # maximum number of contiguous chunks of terminal symbols in RHS of a rule. If None, defaults to max_nonterminals+1 - * max_chunks=None, # <<<<<<<<<<<<<< - * # maximum span of a grammar rule in TEST DATA - * unsigned max_initial_size=10, - */ - values[3] = ((PyObject *)Py_None); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":265 - * unsigned max_nonterminals=2, - * # maximum number of contiguous chunks of terminal symbols in target-side RHS of a rule. If None, defaults to max_nonterminals+1 - * max_target_chunks=None, # <<<<<<<<<<<<<< - * # maximum number of target side symbols (both T and NT) allowed in a rule. If None, defaults to max_initial_size - * max_target_length=None, - */ - values[7] = ((PyObject *)Py_None); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":267 - * max_target_chunks=None, - * # maximum number of target side symbols (both T and NT) allowed in a rule. If None, defaults to max_initial_size - * max_target_length=None, # <<<<<<<<<<<<<< - * # minimum span of a nonterminal in the RHS of a rule in TEST DATA - * unsigned min_gap_size=2, - */ - values[8] = ((PyObject *)Py_None); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":271 - * unsigned min_gap_size=2, - * # filename of file containing precomputed collocations - * precompute_file=None, # <<<<<<<<<<<<<< - * # maximum frequency rank of patterns used to compute triples (don't set higher than 20). - * unsigned precompute_secondary_rank=20, - */ - values[10] = ((PyObject *)Py_None); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 21: values[20] = PyTuple_GET_ITEM(__pyx_args, 20); - case 20: values[19] = PyTuple_GET_ITEM(__pyx_args, 19); - case 19: values[18] = PyTuple_GET_ITEM(__pyx_args, 18); - case 18: values[17] = PyTuple_GET_ITEM(__pyx_args, 17); - case 17: values[16] = PyTuple_GET_ITEM(__pyx_args, 16); - case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15); - case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14); - case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13); - case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); - case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); - case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); - case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__alignment); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__by_slack_factor); - if (value) { values[1] = value; kw_args--; } - } - case 2: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__category); - if (value) { values[2] = value; kw_args--; } - } - case 3: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_chunks); - if (value) { values[3] = value; kw_args--; } - } - case 4: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_initial_size); - if (value) { values[4] = value; kw_args--; } - } - case 5: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_length); - if (value) { values[5] = value; kw_args--; } - } - case 6: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_nonterminals); - if (value) { values[6] = value; kw_args--; } - } - case 7: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_target_chunks); - if (value) { values[7] = value; kw_args--; } - } - case 8: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_target_length); - if (value) { values[8] = value; kw_args--; } - } - case 9: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__min_gap_size); - if (value) { values[9] = value; kw_args--; } - } - case 10: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__precompute_file); - if (value) { values[10] = value; kw_args--; } - } - case 11: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_68); - if (value) { values[11] = value; kw_args--; } - } - case 12: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__precompute_rank); - if (value) { values[12] = value; kw_args--; } - } - case 13: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_101); - if (value) { values[13] = value; kw_args--; } - } - case 14: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_102); - if (value) { values[14] = value; kw_args--; } - } - case 15: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_69); - if (value) { values[15] = value; kw_args--; } - } - case 16: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__train_min_gap_size); - if (value) { values[16] = value; kw_args--; } - } - case 17: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tight_phrases); - if (value) { values[17] = value; kw_args--; } - } - case 18: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_baeza_yates); - if (value) { values[18] = value; kw_args--; } - } - case 19: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_collocations); - if (value) { values[19] = value; kw_args--; } - } - case 20: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_index); - if (value) { values[20] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - if (values[1]) { - } else { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":253 - * Alignment alignment, - * # parameter for double-binary search; doesn't seem to matter much - * float by_slack_factor=1.0, # <<<<<<<<<<<<<< - * # name of generic nonterminal used by Hiero - * char* category="[X]", - */ - __pyx_v_by_slack_factor = ((float)1.0); - } - if (values[2]) { - } else { - __pyx_v_category = ((char *)__pyx_k_103); - } - if (values[4]) { - } else { - __pyx_v_max_initial_size = ((unsigned int)10); - } - if (values[5]) { - } else { - __pyx_v_max_length = ((unsigned int)5); - } - if (values[6]) { - } else { - __pyx_v_max_nonterminals = ((unsigned int)2); - } - if (values[9]) { - } else { - __pyx_v_min_gap_size = ((unsigned int)2); - } - if (values[11]) { - } else { - __pyx_v_precompute_secondary_rank = ((unsigned int)20); - } - if (values[12]) { - } else { - __pyx_v_precompute_rank = ((unsigned int)100); - } - if (values[13]) { - } else { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":277 - * unsigned precompute_rank=100, - * # require extracted rules to have at least one aligned word - * bint require_aligned_terminal=True, # <<<<<<<<<<<<<< - * # require each contiguous chunk of extracted rules to have at least one aligned word - * bint require_aligned_chunks=False, - */ - __pyx_v_require_aligned_terminal = ((int)1); - } - if (values[14]) { - } else { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":279 - * bint require_aligned_terminal=True, - * # require each contiguous chunk of extracted rules to have at least one aligned word - * bint require_aligned_chunks=False, # <<<<<<<<<<<<<< - * # maximum span of a grammar rule extracted from TRAINING DATA - * unsigned train_max_initial_size=10, - */ - __pyx_v_require_aligned_chunks = ((int)0); - } - if (values[15]) { - } else { - __pyx_v_train_max_initial_size = ((unsigned int)10); - } - if (values[16]) { - } else { - __pyx_v_train_min_gap_size = ((unsigned int)2); - } - if (values[17]) { - } else { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":285 - * unsigned train_min_gap_size=2, - * # True if phrases should be tight, False otherwise (False == slower but better results) - * bint tight_phrases=False, # <<<<<<<<<<<<<< - * # True to require use of double-binary alg, false otherwise - * bint use_baeza_yates=True, - */ - __pyx_v_tight_phrases = ((int)0); - } - if (values[18]) { - } else { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":287 - * bint tight_phrases=False, - * # True to require use of double-binary alg, false otherwise - * bint use_baeza_yates=True, # <<<<<<<<<<<<<< - * # True to enable used of precomputed collocations - * bint use_collocations=True, - */ - __pyx_v_use_baeza_yates = ((int)1); - } - if (values[19]) { - } else { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":289 - * bint use_baeza_yates=True, - * # True to enable used of precomputed collocations - * bint use_collocations=True, # <<<<<<<<<<<<<< - * # True to enable use of precomputed inverted indices - * bint use_index=True): - */ - __pyx_v_use_collocations = ((int)1); - } - if (values[20]) { - } else { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":291 - * bint use_collocations=True, - * # True to enable use of precomputed inverted indices - * bint use_index=True): # <<<<<<<<<<<<<< - * '''Note: we make a distinction between the min_gap_size - * and max_initial_size used in test and train. The latter - */ - __pyx_v_use_index = ((int)1); - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 21: values[20] = PyTuple_GET_ITEM(__pyx_args, 20); - case 20: values[19] = PyTuple_GET_ITEM(__pyx_args, 19); - case 19: values[18] = PyTuple_GET_ITEM(__pyx_args, 18); - case 18: values[17] = PyTuple_GET_ITEM(__pyx_args, 17); - case 17: values[16] = PyTuple_GET_ITEM(__pyx_args, 16); - case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15); - case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14); - case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13); - case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); - case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); - case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); - case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); - case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); - case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_alignment = ((struct __pyx_obj_8_cdec_sa_Alignment *)values[0]); - if (values[1]) { - __pyx_v_by_slack_factor = __pyx_PyFloat_AsFloat(values[1]); if (unlikely((__pyx_v_by_slack_factor == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":253 - * Alignment alignment, - * # parameter for double-binary search; doesn't seem to matter much - * float by_slack_factor=1.0, # <<<<<<<<<<<<<< - * # name of generic nonterminal used by Hiero - * char* category="[X]", - */ - __pyx_v_by_slack_factor = ((float)1.0); - } - if (values[2]) { - __pyx_v_category = PyBytes_AsString(values[2]); if (unlikely((!__pyx_v_category) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_category = ((char *)__pyx_k_103); - } - __pyx_v_max_chunks = values[3]; - if (values[4]) { - __pyx_v_max_initial_size = __Pyx_PyInt_AsUnsignedInt(values[4]); if (unlikely((__pyx_v_max_initial_size == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_max_initial_size = ((unsigned int)10); - } - if (values[5]) { - __pyx_v_max_length = __Pyx_PyInt_AsUnsignedInt(values[5]); if (unlikely((__pyx_v_max_length == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_max_length = ((unsigned int)5); - } - if (values[6]) { - __pyx_v_max_nonterminals = __Pyx_PyInt_AsUnsignedInt(values[6]); if (unlikely((__pyx_v_max_nonterminals == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_max_nonterminals = ((unsigned int)2); - } - __pyx_v_max_target_chunks = values[7]; - __pyx_v_max_target_length = values[8]; - if (values[9]) { - __pyx_v_min_gap_size = __Pyx_PyInt_AsUnsignedInt(values[9]); if (unlikely((__pyx_v_min_gap_size == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_min_gap_size = ((unsigned int)2); - } - __pyx_v_precompute_file = values[10]; - if (values[11]) { - __pyx_v_precompute_secondary_rank = __Pyx_PyInt_AsUnsignedInt(values[11]); if (unlikely((__pyx_v_precompute_secondary_rank == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_precompute_secondary_rank = ((unsigned int)20); - } - if (values[12]) { - __pyx_v_precompute_rank = __Pyx_PyInt_AsUnsignedInt(values[12]); if (unlikely((__pyx_v_precompute_rank == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_precompute_rank = ((unsigned int)100); - } - if (values[13]) { - __pyx_v_require_aligned_terminal = __Pyx_PyObject_IsTrue(values[13]); if (unlikely((__pyx_v_require_aligned_terminal == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":277 - * unsigned precompute_rank=100, - * # require extracted rules to have at least one aligned word - * bint require_aligned_terminal=True, # <<<<<<<<<<<<<< - * # require each contiguous chunk of extracted rules to have at least one aligned word - * bint require_aligned_chunks=False, - */ - __pyx_v_require_aligned_terminal = ((int)1); - } - if (values[14]) { - __pyx_v_require_aligned_chunks = __Pyx_PyObject_IsTrue(values[14]); if (unlikely((__pyx_v_require_aligned_chunks == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":279 - * bint require_aligned_terminal=True, - * # require each contiguous chunk of extracted rules to have at least one aligned word - * bint require_aligned_chunks=False, # <<<<<<<<<<<<<< - * # maximum span of a grammar rule extracted from TRAINING DATA - * unsigned train_max_initial_size=10, - */ - __pyx_v_require_aligned_chunks = ((int)0); - } - if (values[15]) { - __pyx_v_train_max_initial_size = __Pyx_PyInt_AsUnsignedInt(values[15]); if (unlikely((__pyx_v_train_max_initial_size == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_train_max_initial_size = ((unsigned int)10); - } - if (values[16]) { - __pyx_v_train_min_gap_size = __Pyx_PyInt_AsUnsignedInt(values[16]); if (unlikely((__pyx_v_train_min_gap_size == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_train_min_gap_size = ((unsigned int)2); - } - if (values[17]) { - __pyx_v_tight_phrases = __Pyx_PyObject_IsTrue(values[17]); if (unlikely((__pyx_v_tight_phrases == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":285 - * unsigned train_min_gap_size=2, - * # True if phrases should be tight, False otherwise (False == slower but better results) - * bint tight_phrases=False, # <<<<<<<<<<<<<< - * # True to require use of double-binary alg, false otherwise - * bint use_baeza_yates=True, - */ - __pyx_v_tight_phrases = ((int)0); - } - if (values[18]) { - __pyx_v_use_baeza_yates = __Pyx_PyObject_IsTrue(values[18]); if (unlikely((__pyx_v_use_baeza_yates == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":287 - * bint tight_phrases=False, - * # True to require use of double-binary alg, false otherwise - * bint use_baeza_yates=True, # <<<<<<<<<<<<<< - * # True to enable used of precomputed collocations - * bint use_collocations=True, - */ - __pyx_v_use_baeza_yates = ((int)1); - } - if (values[19]) { - __pyx_v_use_collocations = __Pyx_PyObject_IsTrue(values[19]); if (unlikely((__pyx_v_use_collocations == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":289 - * bint use_baeza_yates=True, - * # True to enable used of precomputed collocations - * bint use_collocations=True, # <<<<<<<<<<<<<< - * # True to enable use of precomputed inverted indices - * bint use_index=True): - */ - __pyx_v_use_collocations = ((int)1); - } - if (values[20]) { - __pyx_v_use_index = __Pyx_PyObject_IsTrue(values[20]); if (unlikely((__pyx_v_use_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":291 - * bint use_collocations=True, - * # True to enable use of precomputed inverted indices - * bint use_index=True): # <<<<<<<<<<<<<< - * '''Note: we make a distinction between the min_gap_size - * and max_initial_size used in test and train. The latter - */ - __pyx_v_use_index = ((int)1); - } - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 21, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_alignment), __pyx_ptype_8_cdec_sa_Alignment, 1, "alignment", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 251; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory___cinit__(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_alignment, __pyx_v_by_slack_factor, __pyx_v_category, __pyx_v_max_chunks, __pyx_v_max_initial_size, __pyx_v_max_length, __pyx_v_max_nonterminals, __pyx_v_max_target_chunks, __pyx_v_max_target_length, __pyx_v_min_gap_size, __pyx_v_precompute_file, __pyx_v_precompute_secondary_rank, __pyx_v_precompute_rank, __pyx_v_require_aligned_terminal, __pyx_v_require_aligned_chunks, __pyx_v_train_max_initial_size, __pyx_v_train_min_gap_size, __pyx_v_tight_phrases, __pyx_v_use_baeza_yates, __pyx_v_use_collocations, __pyx_v_use_index); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":249 - * cdef IntList findexes1 - * - * def __cinit__(self, # <<<<<<<<<<<<<< - * # compiled alignment object (REQUIRED) - * Alignment alignment, - */ - -static int __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory___cinit__(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Alignment *__pyx_v_alignment, float __pyx_v_by_slack_factor, char *__pyx_v_category, PyObject *__pyx_v_max_chunks, unsigned int __pyx_v_max_initial_size, unsigned int __pyx_v_max_length, unsigned int __pyx_v_max_nonterminals, PyObject *__pyx_v_max_target_chunks, PyObject *__pyx_v_max_target_length, unsigned int __pyx_v_min_gap_size, PyObject *__pyx_v_precompute_file, unsigned int __pyx_v_precompute_secondary_rank, unsigned int __pyx_v_precompute_rank, int __pyx_v_require_aligned_terminal, int __pyx_v_require_aligned_chunks, unsigned int __pyx_v_train_max_initial_size, unsigned int __pyx_v_train_min_gap_size, int __pyx_v_tight_phrases, int __pyx_v_use_baeza_yates, int __pyx_v_use_collocations, int __pyx_v_use_index) { - int __pyx_r; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":297 - * respectively. This is because Chiang's model does not require - * them to be the same, therefore we don't either.''' - * self.rules = TrieTable(True) # cache # <<<<<<<<<<<<<< - * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) - * if alignment is None: - */ - __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_TrieTable)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->rules); - __Pyx_DECREF(((PyObject *)__pyx_v_self->rules)); - __pyx_v_self->rules = ((struct __pyx_obj_8_cdec_sa_TrieTable *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":298 - * them to be the same, therefore we don't either.''' - * self.rules = TrieTable(True) # cache - * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) # <<<<<<<<<<<<<< - * if alignment is None: - * raise Exception("Must specify an alignment object") - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_PhraseLocation)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__phrase_location), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 298; __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); - __Pyx_GOTREF(__pyx_v_self->rules->root); - __Pyx_DECREF(__pyx_v_self->rules->root); - __pyx_v_self->rules->root = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":299 - * self.rules = TrieTable(True) # cache - * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) - * if alignment is None: # <<<<<<<<<<<<<< - * raise Exception("Must specify an alignment object") - * self.alignment = alignment - */ - __pyx_t_3 = (((PyObject *)__pyx_v_alignment) == Py_None); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":300 - * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) - * if alignment is None: - * raise Exception("Must specify an alignment object") # <<<<<<<<<<<<<< - * self.alignment = alignment - * - */ - __pyx_t_2 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_k_tuple_105), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":301 - * if alignment is None: - * raise Exception("Must specify an alignment object") - * self.alignment = alignment # <<<<<<<<<<<<<< - * - * # grammar parameters and settings - */ - __Pyx_INCREF(((PyObject *)__pyx_v_alignment)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_alignment)); - __Pyx_GOTREF(__pyx_v_self->alignment); - __Pyx_DECREF(((PyObject *)__pyx_v_self->alignment)); - __pyx_v_self->alignment = __pyx_v_alignment; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":305 - * # grammar parameters and settings - * # NOTE: setting max_nonterminals > 2 is not currently supported in Hiero - * self.max_length = max_length # <<<<<<<<<<<<<< - * self.max_nonterminals = max_nonterminals - * self.max_initial_size = max_initial_size - */ - __pyx_v_self->max_length = __pyx_v_max_length; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":306 - * # NOTE: setting max_nonterminals > 2 is not currently supported in Hiero - * self.max_length = max_length - * self.max_nonterminals = max_nonterminals # <<<<<<<<<<<<<< - * self.max_initial_size = max_initial_size - * self.train_max_initial_size = train_max_initial_size - */ - __pyx_v_self->max_nonterminals = __pyx_v_max_nonterminals; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":307 - * self.max_length = max_length - * self.max_nonterminals = max_nonterminals - * self.max_initial_size = max_initial_size # <<<<<<<<<<<<<< - * self.train_max_initial_size = train_max_initial_size - * self.min_gap_size = min_gap_size - */ - __pyx_v_self->max_initial_size = __pyx_v_max_initial_size; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":308 - * self.max_nonterminals = max_nonterminals - * self.max_initial_size = max_initial_size - * self.train_max_initial_size = train_max_initial_size # <<<<<<<<<<<<<< - * self.min_gap_size = min_gap_size - * self.train_min_gap_size = train_min_gap_size - */ - __pyx_v_self->train_max_initial_size = __pyx_v_train_max_initial_size; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":309 - * self.max_initial_size = max_initial_size - * self.train_max_initial_size = train_max_initial_size - * self.min_gap_size = min_gap_size # <<<<<<<<<<<<<< - * self.train_min_gap_size = train_min_gap_size - * self.category = sym_fromstring(category, False) - */ - __pyx_v_self->min_gap_size = __pyx_v_min_gap_size; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":310 - * self.train_max_initial_size = train_max_initial_size - * self.min_gap_size = min_gap_size - * self.train_min_gap_size = train_min_gap_size # <<<<<<<<<<<<<< - * self.category = sym_fromstring(category, False) - * - */ - __pyx_v_self->train_min_gap_size = __pyx_v_train_min_gap_size; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":311 - * self.min_gap_size = min_gap_size - * self.train_min_gap_size = train_min_gap_size - * self.category = sym_fromstring(category, False) # <<<<<<<<<<<<<< - * - * if max_chunks is None: - */ - __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_fromstring); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyBytes_FromString(__pyx_v_category); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_4 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 311; __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[8]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_1 = 0; - __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_self->category = __pyx_t_6; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":313 - * self.category = sym_fromstring(category, False) - * - * if max_chunks is None: # <<<<<<<<<<<<<< - * self.max_chunks = self.max_nonterminals + 1 - * else: - */ - __pyx_t_3 = (__pyx_v_max_chunks == Py_None); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":314 - * - * if max_chunks is None: - * self.max_chunks = self.max_nonterminals + 1 # <<<<<<<<<<<<<< - * else: - * self.max_chunks = max_chunks - */ - __pyx_v_self->max_chunks = (__pyx_v_self->max_nonterminals + 1); - goto __pyx_L4; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":316 - * self.max_chunks = self.max_nonterminals + 1 - * else: - * self.max_chunks = max_chunks # <<<<<<<<<<<<<< - * - * if max_target_chunks is None: - */ - __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_max_chunks); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->max_chunks = __pyx_t_6; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":318 - * self.max_chunks = max_chunks - * - * if max_target_chunks is None: # <<<<<<<<<<<<<< - * self.max_target_chunks = self.max_nonterminals + 1 - * else: - */ - __pyx_t_3 = (__pyx_v_max_target_chunks == Py_None); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":319 - * - * if max_target_chunks is None: - * self.max_target_chunks = self.max_nonterminals + 1 # <<<<<<<<<<<<<< - * else: - * self.max_target_chunks = max_target_chunks - */ - __pyx_v_self->max_target_chunks = (__pyx_v_self->max_nonterminals + 1); - goto __pyx_L5; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":321 - * self.max_target_chunks = self.max_nonterminals + 1 - * else: - * self.max_target_chunks = max_target_chunks # <<<<<<<<<<<<<< - * - * if max_target_length is None: - */ - __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_max_target_chunks); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->max_target_chunks = __pyx_t_6; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":323 - * self.max_target_chunks = max_target_chunks - * - * if max_target_length is None: # <<<<<<<<<<<<<< - * self.max_target_length = max_initial_size - * else: - */ - __pyx_t_3 = (__pyx_v_max_target_length == Py_None); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":324 - * - * if max_target_length is None: - * self.max_target_length = max_initial_size # <<<<<<<<<<<<<< - * else: - * self.max_target_length = max_target_length - */ - __pyx_v_self->max_target_length = __pyx_v_max_initial_size; - goto __pyx_L6; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":326 - * self.max_target_length = max_initial_size - * else: - * self.max_target_length = max_target_length # <<<<<<<<<<<<<< - * - * # algorithmic parameters and settings - */ - __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_max_target_length); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->max_target_length = __pyx_t_6; - } - __pyx_L6:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":329 - * - * # algorithmic parameters and settings - * self.precomputed_collocations = {} # <<<<<<<<<<<<<< - * self.precomputed_index = {} - * self.use_index = use_index - */ - __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); - __Pyx_GOTREF(__pyx_v_self->precomputed_collocations); - __Pyx_DECREF(__pyx_v_self->precomputed_collocations); - __pyx_v_self->precomputed_collocations = ((PyObject *)__pyx_t_4); - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":330 - * # algorithmic parameters and settings - * self.precomputed_collocations = {} - * self.precomputed_index = {} # <<<<<<<<<<<<<< - * self.use_index = use_index - * self.use_collocations = use_collocations - */ - __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); - __Pyx_GOTREF(__pyx_v_self->precomputed_index); - __Pyx_DECREF(__pyx_v_self->precomputed_index); - __pyx_v_self->precomputed_index = ((PyObject *)__pyx_t_4); - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":331 - * self.precomputed_collocations = {} - * self.precomputed_index = {} - * self.use_index = use_index # <<<<<<<<<<<<<< - * self.use_collocations = use_collocations - * self.max_rank = {} - */ - __pyx_v_self->use_index = __pyx_v_use_index; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":332 - * self.precomputed_index = {} - * self.use_index = use_index - * self.use_collocations = use_collocations # <<<<<<<<<<<<<< - * self.max_rank = {} - * self.precompute_file = precompute_file - */ - __pyx_v_self->use_collocations = __pyx_v_use_collocations; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":333 - * self.use_index = use_index - * self.use_collocations = use_collocations - * self.max_rank = {} # <<<<<<<<<<<<<< - * self.precompute_file = precompute_file - * self.precompute_rank = precompute_rank - */ - __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); - __Pyx_GOTREF(__pyx_v_self->max_rank); - __Pyx_DECREF(__pyx_v_self->max_rank); - __pyx_v_self->max_rank = ((PyObject *)__pyx_t_4); - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":334 - * self.use_collocations = use_collocations - * self.max_rank = {} - * self.precompute_file = precompute_file # <<<<<<<<<<<<<< - * self.precompute_rank = precompute_rank - * self.precompute_secondary_rank = precompute_secondary_rank - */ - __Pyx_INCREF(__pyx_v_precompute_file); - __Pyx_GIVEREF(__pyx_v_precompute_file); - __Pyx_GOTREF(__pyx_v_self->precompute_file); - __Pyx_DECREF(__pyx_v_self->precompute_file); - __pyx_v_self->precompute_file = __pyx_v_precompute_file; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":335 - * self.max_rank = {} - * self.precompute_file = precompute_file - * self.precompute_rank = precompute_rank # <<<<<<<<<<<<<< - * self.precompute_secondary_rank = precompute_secondary_rank - * self.use_baeza_yates = use_baeza_yates - */ - __pyx_v_self->precompute_rank = __pyx_v_precompute_rank; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":336 - * self.precompute_file = precompute_file - * self.precompute_rank = precompute_rank - * self.precompute_secondary_rank = precompute_secondary_rank # <<<<<<<<<<<<<< - * self.use_baeza_yates = use_baeza_yates - * self.by_slack_factor = by_slack_factor - */ - __pyx_v_self->precompute_secondary_rank = __pyx_v_precompute_secondary_rank; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":337 - * self.precompute_rank = precompute_rank - * self.precompute_secondary_rank = precompute_secondary_rank - * self.use_baeza_yates = use_baeza_yates # <<<<<<<<<<<<<< - * self.by_slack_factor = by_slack_factor - * if tight_phrases: - */ - __pyx_v_self->use_baeza_yates = __pyx_v_use_baeza_yates; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":338 - * self.precompute_secondary_rank = precompute_secondary_rank - * self.use_baeza_yates = use_baeza_yates - * self.by_slack_factor = by_slack_factor # <<<<<<<<<<<<<< - * if tight_phrases: - * self.tight_phrases = 1 - */ - __pyx_v_self->by_slack_factor = __pyx_v_by_slack_factor; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":339 - * self.use_baeza_yates = use_baeza_yates - * self.by_slack_factor = by_slack_factor - * if tight_phrases: # <<<<<<<<<<<<<< - * self.tight_phrases = 1 - * else: - */ - if (__pyx_v_tight_phrases) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":340 - * self.by_slack_factor = by_slack_factor - * if tight_phrases: - * self.tight_phrases = 1 # <<<<<<<<<<<<<< - * else: - * self.tight_phrases = 0 - */ - __pyx_v_self->tight_phrases = 1; - goto __pyx_L7; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":342 - * self.tight_phrases = 1 - * else: - * self.tight_phrases = 0 # <<<<<<<<<<<<<< - * - * if require_aligned_chunks: - */ - __pyx_v_self->tight_phrases = 0; - } - __pyx_L7:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":344 - * self.tight_phrases = 0 - * - * if require_aligned_chunks: # <<<<<<<<<<<<<< - * # one condition is a stronger version of the other. - * self.require_aligned_chunks = 1 - */ - if (__pyx_v_require_aligned_chunks) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":346 - * if require_aligned_chunks: - * # one condition is a stronger version of the other. - * self.require_aligned_chunks = 1 # <<<<<<<<<<<<<< - * self.require_aligned_terminal = 1 - * elif require_aligned_terminal: - */ - __pyx_v_self->require_aligned_chunks = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":347 - * # one condition is a stronger version of the other. - * self.require_aligned_chunks = 1 - * self.require_aligned_terminal = 1 # <<<<<<<<<<<<<< - * elif require_aligned_terminal: - * self.require_aligned_chunks = 0 - */ - __pyx_v_self->require_aligned_terminal = 1; - goto __pyx_L8; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":348 - * self.require_aligned_chunks = 1 - * self.require_aligned_terminal = 1 - * elif require_aligned_terminal: # <<<<<<<<<<<<<< - * self.require_aligned_chunks = 0 - * self.require_aligned_terminal = 1 - */ - if (__pyx_v_require_aligned_terminal) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":349 - * self.require_aligned_terminal = 1 - * elif require_aligned_terminal: - * self.require_aligned_chunks = 0 # <<<<<<<<<<<<<< - * self.require_aligned_terminal = 1 - * else: - */ - __pyx_v_self->require_aligned_chunks = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":350 - * elif require_aligned_terminal: - * self.require_aligned_chunks = 0 - * self.require_aligned_terminal = 1 # <<<<<<<<<<<<<< - * else: - * self.require_aligned_chunks = 0 - */ - __pyx_v_self->require_aligned_terminal = 1; - goto __pyx_L8; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":352 - * self.require_aligned_terminal = 1 - * else: - * self.require_aligned_chunks = 0 # <<<<<<<<<<<<<< - * self.require_aligned_terminal = 0 - * - */ - __pyx_v_self->require_aligned_chunks = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":353 - * else: - * self.require_aligned_chunks = 0 - * self.require_aligned_terminal = 0 # <<<<<<<<<<<<<< - * - * - */ - __pyx_v_self->require_aligned_terminal = 0; - } - __pyx_L8:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":357 - * - * # diagnostics - * self.prev_norm_prefix = () # <<<<<<<<<<<<<< - * - * self.findexes = IntList(initial_len=10) - */ - __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); - __Pyx_GIVEREF(((PyObject *)__pyx_empty_tuple)); - __Pyx_GOTREF(__pyx_v_self->prev_norm_prefix); - __Pyx_DECREF(__pyx_v_self->prev_norm_prefix); - __pyx_v_self->prev_norm_prefix = ((PyObject *)__pyx_empty_tuple); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":359 - * self.prev_norm_prefix = () - * - * self.findexes = IntList(initial_len=10) # <<<<<<<<<<<<<< - * self.findexes1 = IntList(initial_len=10) - * - */ - __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__initial_len), __pyx_int_10) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_GIVEREF(__pyx_t_5); - __Pyx_GOTREF(__pyx_v_self->findexes); - __Pyx_DECREF(((PyObject *)__pyx_v_self->findexes)); - __pyx_v_self->findexes = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_5); - __pyx_t_5 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":360 - * - * self.findexes = IntList(initial_len=10) - * self.findexes1 = IntList(initial_len=10) # <<<<<<<<<<<<<< - * - * def configure(self, SuffixArray fsarray, DataArray edarray, Sampler sampler): - */ - __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__initial_len), __pyx_int_10) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_GOTREF(__pyx_v_self->findexes1); - __Pyx_DECREF(((PyObject *)__pyx_v_self->findexes1)); - __pyx_v_self->findexes1 = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_4); - __pyx_t_4 = 0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_3configure(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8_cdec_sa_23HieroCachingRuleFactory_2configure[] = "This gives the RuleFactory access to the Context object.\n Here we also use it to precompute the most expensive intersections\n in the corpus quickly."; -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_3configure(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_fsarray = 0; - struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_edarray = 0; - struct __pyx_obj_8_cdec_sa_Sampler *__pyx_v_sampler = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fsarray,&__pyx_n_s__edarray,&__pyx_n_s__sampler,0}; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("configure (wrapper)", 0); - { - PyObject* values[3] = {0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fsarray); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__edarray); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("configure", 1, 3, 3, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sampler); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("configure", 1, 3, 3, 2); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "configure") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - } - __pyx_v_fsarray = ((struct __pyx_obj_8_cdec_sa_SuffixArray *)values[0]); - __pyx_v_edarray = ((struct __pyx_obj_8_cdec_sa_DataArray *)values[1]); - __pyx_v_sampler = ((struct __pyx_obj_8_cdec_sa_Sampler *)values[2]); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("configure", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.configure", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fsarray), __pyx_ptype_8_cdec_sa_SuffixArray, 1, "fsarray", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_edarray), __pyx_ptype_8_cdec_sa_DataArray, 1, "edarray", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_sampler), __pyx_ptype_8_cdec_sa_Sampler, 1, "sampler", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_2configure(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_fsarray, __pyx_v_edarray, __pyx_v_sampler); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":362 - * self.findexes1 = IntList(initial_len=10) - * - * def configure(self, SuffixArray fsarray, DataArray edarray, Sampler sampler): # <<<<<<<<<<<<<< - * '''This gives the RuleFactory access to the Context object. - * Here we also use it to precompute the most expensive intersections - */ - -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_2configure(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_8_cdec_sa_SuffixArray *__pyx_v_fsarray, struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_edarray, struct __pyx_obj_8_cdec_sa_Sampler *__pyx_v_sampler) { - 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("configure", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":366 - * Here we also use it to precompute the most expensive intersections - * in the corpus quickly.''' - * self.fsa = fsarray # <<<<<<<<<<<<<< - * self.fda = fsarray.darray - * self.eda = edarray - */ - __Pyx_INCREF(((PyObject *)__pyx_v_fsarray)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_fsarray)); - __Pyx_GOTREF(__pyx_v_self->fsa); - __Pyx_DECREF(((PyObject *)__pyx_v_self->fsa)); - __pyx_v_self->fsa = __pyx_v_fsarray; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":367 - * in the corpus quickly.''' - * self.fsa = fsarray - * self.fda = fsarray.darray # <<<<<<<<<<<<<< - * self.eda = edarray - * self.fid2symid = self.set_idmap(self.fda) - */ - __Pyx_INCREF(((PyObject *)__pyx_v_fsarray->darray)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_fsarray->darray)); - __Pyx_GOTREF(__pyx_v_self->fda); - __Pyx_DECREF(((PyObject *)__pyx_v_self->fda)); - __pyx_v_self->fda = __pyx_v_fsarray->darray; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":368 - * self.fsa = fsarray - * self.fda = fsarray.darray - * self.eda = edarray # <<<<<<<<<<<<<< - * self.fid2symid = self.set_idmap(self.fda) - * self.eid2symid = self.set_idmap(self.eda) - */ - __Pyx_INCREF(((PyObject *)__pyx_v_edarray)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_edarray)); - __Pyx_GOTREF(__pyx_v_self->eda); - __Pyx_DECREF(((PyObject *)__pyx_v_self->eda)); - __pyx_v_self->eda = __pyx_v_edarray; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":369 - * self.fda = fsarray.darray - * self.eda = edarray - * self.fid2symid = self.set_idmap(self.fda) # <<<<<<<<<<<<<< - * self.eid2symid = self.set_idmap(self.eda) - * self.precompute() - */ - __pyx_t_1 = ((PyObject *)__pyx_v_self->fda); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->set_idmap(__pyx_v_self, ((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_8_cdec_sa_IntList))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_GOTREF(__pyx_v_self->fid2symid); - __Pyx_DECREF(((PyObject *)__pyx_v_self->fid2symid)); - __pyx_v_self->fid2symid = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":370 - * self.eda = edarray - * self.fid2symid = self.set_idmap(self.fda) - * self.eid2symid = self.set_idmap(self.eda) # <<<<<<<<<<<<<< - * self.precompute() - * self.sampler = sampler - */ - __pyx_t_2 = ((PyObject *)__pyx_v_self->eda); - __Pyx_INCREF(__pyx_t_2); - __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->set_idmap(__pyx_v_self, ((struct __pyx_obj_8_cdec_sa_DataArray *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8_cdec_sa_IntList))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->eid2symid); - __Pyx_DECREF(((PyObject *)__pyx_v_self->eid2symid)); - __pyx_v_self->eid2symid = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":371 - * self.fid2symid = self.set_idmap(self.fda) - * self.eid2symid = self.set_idmap(self.eda) - * self.precompute() # <<<<<<<<<<<<<< - * self.sampler = sampler - * - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__precompute); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":372 - * self.eid2symid = self.set_idmap(self.eda) - * self.precompute() - * self.sampler = sampler # <<<<<<<<<<<<<< - * - * cdef set_idmap(self, DataArray darray): - */ - __Pyx_INCREF(((PyObject *)__pyx_v_sampler)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_sampler)); - __Pyx_GOTREF(__pyx_v_self->sampler); - __Pyx_DECREF(((PyObject *)__pyx_v_self->sampler)); - __pyx_v_self->sampler = __pyx_v_sampler; - - __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_sa.HieroCachingRuleFactory.configure", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":374 - * self.sampler = sampler - * - * cdef set_idmap(self, DataArray darray): # <<<<<<<<<<<<<< - * cdef int word_id, new_word_id, N - * cdef IntList idmap - */ - -static PyObject *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_set_idmap(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_8_cdec_sa_DataArray *__pyx_v_darray) { - int __pyx_v_word_id; - int __pyx_v_new_word_id; - int __pyx_v_N; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_idmap = 0; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - int __pyx_t_7; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("set_idmap", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":378 - * cdef IntList idmap - * - * N = len(darray.id2word) # <<<<<<<<<<<<<< - * idmap = IntList(initial_len=N) - * for word_id from 0 <= word_id < N: - */ - __pyx_t_1 = __pyx_v_darray->id2word; - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_N = __pyx_t_2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":379 - * - * N = len(darray.id2word) - * idmap = IntList(initial_len=N) # <<<<<<<<<<<<<< - * for word_id from 0 <= word_id < N: - * new_word_id = sym_fromstring(darray.id2word[word_id], True) - */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_v_idmap = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":380 - * N = len(darray.id2word) - * idmap = IntList(initial_len=N) - * for word_id from 0 <= word_id < N: # <<<<<<<<<<<<<< - * new_word_id = sym_fromstring(darray.id2word[word_id], True) - * idmap.arr[word_id] = new_word_id - */ - __pyx_t_4 = __pyx_v_N; - for (__pyx_v_word_id = 0; __pyx_v_word_id < __pyx_t_4; __pyx_v_word_id++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":381 - * idmap = IntList(initial_len=N) - * for word_id from 0 <= word_id < N: - * new_word_id = sym_fromstring(darray.id2word[word_id], True) # <<<<<<<<<<<<<< - * idmap.arr[word_id] = new_word_id - * return idmap - */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_fromstring); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_darray->id2word, __pyx_v_word_id, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_1 = 0; - __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __pyx_t_7 = __Pyx_PyInt_AsInt(__pyx_t_5); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_new_word_id = __pyx_t_7; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":382 - * for word_id from 0 <= word_id < N: - * new_word_id = sym_fromstring(darray.id2word[word_id], True) - * idmap.arr[word_id] = new_word_id # <<<<<<<<<<<<<< - * return idmap - * - */ - (__pyx_v_idmap->arr[__pyx_v_word_id]) = __pyx_v_new_word_id; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":383 - * new_word_id = sym_fromstring(darray.id2word[word_id], True) - * idmap.arr[word_id] = new_word_id - * return idmap # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_idmap)); - __pyx_r = ((PyObject *)__pyx_v_idmap); - 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_3); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.set_idmap", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_idmap); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_5pattern2phrase(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_5pattern2phrase(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("pattern2phrase (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_4pattern2phrase(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), ((PyObject *)__pyx_v_pattern)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":386 - * - * - * def pattern2phrase(self, pattern): # <<<<<<<<<<<<<< - * # pattern is a tuple, which we must convert to a hiero Phrase - * result = () - */ - -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_4pattern2phrase(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_pattern) { - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_v_arity = NULL; - PyObject *__pyx_v_word_id = NULL; - PyObject *__pyx_v_new_id = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *(*__pyx_t_3)(PyObject *); - PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("pattern2phrase", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":388 - * def pattern2phrase(self, pattern): - * # pattern is a tuple, which we must convert to a hiero Phrase - * result = () # <<<<<<<<<<<<<< - * arity = 0 - * for word_id in pattern: - */ - __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); - __pyx_v_result = __pyx_empty_tuple; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":389 - * # pattern is a tuple, which we must convert to a hiero Phrase - * result = () - * arity = 0 # <<<<<<<<<<<<<< - * for word_id in pattern: - * if word_id == -1: - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_v_arity = __pyx_int_0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":390 - * result = () - * arity = 0 - * for word_id in pattern: # <<<<<<<<<<<<<< - * if word_id == -1: - * arity = arity + 1 - */ - if (PyList_CheckExact(__pyx_v_pattern) || PyTuple_CheckExact(__pyx_v_pattern)) { - __pyx_t_1 = __pyx_v_pattern; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; - __pyx_t_3 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_pattern); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; - } - for (;;) { - if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; - } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; - } else { - __pyx_t_4 = __pyx_t_3(__pyx_t_1); - if (unlikely(!__pyx_t_4)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XDECREF(__pyx_v_word_id); - __pyx_v_word_id = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":391 - * arity = 0 - * for word_id in pattern: - * if word_id == -1: # <<<<<<<<<<<<<< - * arity = arity + 1 - * new_id = sym_setindex(self.category, arity) - */ - __pyx_t_4 = PyObject_RichCompare(__pyx_v_word_id, __pyx_int_neg_1, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":392 - * for word_id in pattern: - * if word_id == -1: - * arity = arity + 1 # <<<<<<<<<<<<<< - * new_id = sym_setindex(self.category, arity) - * else: - */ - __pyx_t_4 = PyNumber_Add(__pyx_v_arity, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_v_arity); - __pyx_v_arity = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":393 - * if word_id == -1: - * arity = arity + 1 - * new_id = sym_setindex(self.category, arity) # <<<<<<<<<<<<<< - * else: - * new_id = sym_fromstring(self.fda.id2word[word_id], True) - */ - __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_arity); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_t_6)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_v_new_id); - __pyx_v_new_id = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L5; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":395 - * new_id = sym_setindex(self.category, arity) - * else: - * new_id = sym_fromstring(self.fda.id2word[word_id], True) # <<<<<<<<<<<<<< - * result = result + (new_id,) - * return Phrase(result) - */ - __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_fromstring); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = PyObject_GetItem(__pyx_v_self->fda->id2word, __pyx_v_word_id); if (!__pyx_t_7) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - __pyx_t_7 = 0; - __pyx_t_8 = 0; - __pyx_t_8 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; - __Pyx_XDECREF(__pyx_v_new_id); - __pyx_v_new_id = __pyx_t_8; - __pyx_t_8 = 0; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":396 - * else: - * new_id = sym_fromstring(self.fda.id2word[word_id], True) - * result = result + (new_id,) # <<<<<<<<<<<<<< - * return Phrase(result) - * - */ - __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(__pyx_v_new_id); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_new_id); - __Pyx_GIVEREF(__pyx_v_new_id); - __pyx_t_9 = PyNumber_Add(((PyObject *)__pyx_v_result), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_9)); - __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_result)); - __pyx_v_result = __pyx_t_9; - __pyx_t_9 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":397 - * new_id = sym_fromstring(self.fda.id2word[word_id], True) - * result = result + (new_id,) - * return Phrase(result) # <<<<<<<<<<<<<< - * - * def pattern2phrase_plus(self, pattern): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_result)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_result)); - __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_r = __pyx_t_9; - __pyx_t_9 = 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_4); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.pattern2phrase", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XDECREF(__pyx_v_arity); - __Pyx_XDECREF(__pyx_v_word_id); - __Pyx_XDECREF(__pyx_v_new_id); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_7pattern2phrase_plus(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_7pattern2phrase_plus(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("pattern2phrase_plus (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_6pattern2phrase_plus(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), ((PyObject *)__pyx_v_pattern)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":399 - * return Phrase(result) - * - * def pattern2phrase_plus(self, pattern): # <<<<<<<<<<<<<< - * # returns a list containing both the pattern, and pattern - * # suffixed/prefixed with the NT category. - */ - -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_6pattern2phrase_plus(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_pattern) { - PyObject *__pyx_v_patterns = NULL; - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_v_arity = NULL; - PyObject *__pyx_v_word_id = NULL; - PyObject *__pyx_v_new_id = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *(*__pyx_t_3)(PyObject *); - PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - int __pyx_t_10; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("pattern2phrase_plus", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":402 - * # returns a list containing both the pattern, and pattern - * # suffixed/prefixed with the NT category. - * patterns = [] # <<<<<<<<<<<<<< - * result = () - * arity = 0 - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_patterns = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":403 - * # suffixed/prefixed with the NT category. - * patterns = [] - * result = () # <<<<<<<<<<<<<< - * arity = 0 - * for word_id in pattern: - */ - __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); - __pyx_v_result = __pyx_empty_tuple; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":404 - * patterns = [] - * result = () - * arity = 0 # <<<<<<<<<<<<<< - * for word_id in pattern: - * if word_id == -1: - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_v_arity = __pyx_int_0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":405 - * result = () - * arity = 0 - * for word_id in pattern: # <<<<<<<<<<<<<< - * if word_id == -1: - * arity = arity + 1 - */ - if (PyList_CheckExact(__pyx_v_pattern) || PyTuple_CheckExact(__pyx_v_pattern)) { - __pyx_t_1 = __pyx_v_pattern; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; - __pyx_t_3 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_pattern); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; - } - for (;;) { - if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; - } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; - } else { - __pyx_t_4 = __pyx_t_3(__pyx_t_1); - if (unlikely(!__pyx_t_4)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XDECREF(__pyx_v_word_id); - __pyx_v_word_id = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":406 - * arity = 0 - * for word_id in pattern: - * if word_id == -1: # <<<<<<<<<<<<<< - * arity = arity + 1 - * new_id = sym_setindex(self.category, arity) - */ - __pyx_t_4 = PyObject_RichCompare(__pyx_v_word_id, __pyx_int_neg_1, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":407 - * for word_id in pattern: - * if word_id == -1: - * arity = arity + 1 # <<<<<<<<<<<<<< - * new_id = sym_setindex(self.category, arity) - * else: - */ - __pyx_t_4 = PyNumber_Add(__pyx_v_arity, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_v_arity); - __pyx_v_arity = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":408 - * if word_id == -1: - * arity = arity + 1 - * new_id = sym_setindex(self.category, arity) # <<<<<<<<<<<<<< - * else: - * new_id = sym_fromstring(self.fda.id2word[word_id], True) - */ - __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_arity); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_t_6)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_v_new_id); - __pyx_v_new_id = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L5; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":410 - * new_id = sym_setindex(self.category, arity) - * else: - * new_id = sym_fromstring(self.fda.id2word[word_id], True) # <<<<<<<<<<<<<< - * result = result + (new_id,) - * patterns.append(Phrase(result)) - */ - __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_fromstring); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = PyObject_GetItem(__pyx_v_self->fda->id2word, __pyx_v_word_id); if (!__pyx_t_7) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - __pyx_t_7 = 0; - __pyx_t_8 = 0; - __pyx_t_8 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; - __Pyx_XDECREF(__pyx_v_new_id); - __pyx_v_new_id = __pyx_t_8; - __pyx_t_8 = 0; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":411 - * else: - * new_id = sym_fromstring(self.fda.id2word[word_id], True) - * result = result + (new_id,) # <<<<<<<<<<<<<< - * patterns.append(Phrase(result)) - * patterns.append(Phrase(result + (sym_setindex(self.category, 1),))) - */ - __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 411; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(__pyx_v_new_id); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_new_id); - __Pyx_GIVEREF(__pyx_v_new_id); - __pyx_t_9 = PyNumber_Add(((PyObject *)__pyx_v_result), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 411; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_9)); - __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_result)); - __pyx_v_result = __pyx_t_9; - __pyx_t_9 = 0; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":412 - * new_id = sym_fromstring(self.fda.id2word[word_id], True) - * result = result + (new_id,) - * patterns.append(Phrase(result)) # <<<<<<<<<<<<<< - * patterns.append(Phrase(result + (sym_setindex(self.category, 1),))) - * patterns.append(Phrase((sym_setindex(self.category, 1),) + result)) - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_result)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_result)); - __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_10 = PyList_Append(__pyx_v_patterns, __pyx_t_9); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":413 - * result = result + (new_id,) - * patterns.append(Phrase(result)) - * patterns.append(Phrase(result + (sym_setindex(self.category, 1),))) # <<<<<<<<<<<<<< - * patterns.append(Phrase((sym_setindex(self.category, 1),) + result)) - * return patterns - */ - __pyx_t_9 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, 1)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - __pyx_t_9 = 0; - __pyx_t_9 = PyNumber_Add(((PyObject *)__pyx_v_result), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_9)); - __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[8]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_9)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); - __pyx_t_9 = 0; - __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_10 = PyList_Append(__pyx_v_patterns, __pyx_t_9); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":414 - * patterns.append(Phrase(result)) - * patterns.append(Phrase(result + (sym_setindex(self.category, 1),))) - * patterns.append(Phrase((sym_setindex(self.category, 1),) + result)) # <<<<<<<<<<<<<< - * return patterns - * - */ - __pyx_t_9 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, 1)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - __pyx_t_9 = 0; - __pyx_t_9 = PyNumber_Add(((PyObject *)__pyx_t_1), ((PyObject *)__pyx_v_result)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_9)); - __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[8]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_9)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); - __pyx_t_9 = 0; - __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_10 = PyList_Append(__pyx_v_patterns, __pyx_t_9); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":415 - * patterns.append(Phrase(result + (sym_setindex(self.category, 1),))) - * patterns.append(Phrase((sym_setindex(self.category, 1),) + result)) - * return patterns # <<<<<<<<<<<<<< - * - * def precompute(self): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_patterns)); - __pyx_r = ((PyObject *)__pyx_v_patterns); - 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_4); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.pattern2phrase_plus", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_patterns); - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XDECREF(__pyx_v_arity); - __Pyx_XDECREF(__pyx_v_word_id); - __Pyx_XDECREF(__pyx_v_new_id); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_9precompute(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_9precompute(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("precompute (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_8precompute(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":417 - * return patterns - * - * def precompute(self): # <<<<<<<<<<<<<< - * cdef Precomputation pre - * - */ - -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_8precompute(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self) { - struct __pyx_obj_8_cdec_sa_Precomputation *__pyx_v_pre = 0; - PyObject *__pyx_v_start_time = NULL; - PyObject *__pyx_v_pattern = NULL; - PyObject *__pyx_v_arr = NULL; - PyObject *__pyx_v_phrases = NULL; - PyObject *__pyx_v_phrase = NULL; - PyObject *__pyx_v_stop_time = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - Py_ssize_t __pyx_t_6; - PyObject *(*__pyx_t_7)(PyObject *); - PyObject *__pyx_t_8 = NULL; - PyObject *(*__pyx_t_9)(PyObject *); - Py_ssize_t __pyx_t_10; - PyObject *(*__pyx_t_11)(PyObject *); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("precompute", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":420 - * cdef Precomputation pre - * - * if self.precompute_file is not None: # <<<<<<<<<<<<<< - * start_time = monitor_cpu() - * logger.info("Reading precomputed data from file %s... ", self.precompute_file) - */ - __pyx_t_1 = (__pyx_v_self->precompute_file != Py_None); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":421 - * - * if self.precompute_file is not None: - * start_time = monitor_cpu() # <<<<<<<<<<<<<< - * logger.info("Reading precomputed data from file %s... ", self.precompute_file) - * pre = Precomputation(from_binary=self.precompute_file) - */ - __pyx_t_2 = PyFloat_FromDouble(__pyx_f_8_cdec_sa_monitor_cpu()); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 421; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_start_time = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":422 - * if self.precompute_file is not None: - * start_time = monitor_cpu() - * logger.info("Reading precomputed data from file %s... ", self.precompute_file) # <<<<<<<<<<<<<< - * pre = Precomputation(from_binary=self.precompute_file) - * # check parameters of precomputation -- some are critical and some are not - */ - __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__info); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_106)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_106)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_106)); - __Pyx_INCREF(__pyx_v_self->precompute_file); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_self->precompute_file); - __Pyx_GIVEREF(__pyx_v_self->precompute_file); - __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":423 - * start_time = monitor_cpu() - * logger.info("Reading precomputed data from file %s... ", self.precompute_file) - * pre = Precomputation(from_binary=self.precompute_file) # <<<<<<<<<<<<<< - * # check parameters of precomputation -- some are critical and some are not - * if pre.max_nonterminals != self.max_nonterminals: - */ - __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__from_binary), __pyx_v_self->precompute_file) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Precomputation)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __pyx_v_pre = ((struct __pyx_obj_8_cdec_sa_Precomputation *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":425 - * pre = Precomputation(from_binary=self.precompute_file) - * # check parameters of precomputation -- some are critical and some are not - * if pre.max_nonterminals != self.max_nonterminals: # <<<<<<<<<<<<<< - * logger.warn("Precomputation done with max nonterminals %d, decoder uses %d", pre.max_nonterminals, self.max_nonterminals) - * if pre.max_length != self.max_length: - */ - __pyx_t_1 = (__pyx_v_pre->max_nonterminals != __pyx_v_self->max_nonterminals); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":426 - * # check parameters of precomputation -- some are critical and some are not - * if pre.max_nonterminals != self.max_nonterminals: - * logger.warn("Precomputation done with max nonterminals %d, decoder uses %d", pre.max_nonterminals, self.max_nonterminals) # <<<<<<<<<<<<<< - * if pre.max_length != self.max_length: - * logger.warn("Precomputation done with max terminals %d, decoder uses %d", pre.max_length, self.max_length) - */ - __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__warn); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyInt_FromLong(__pyx_v_pre->max_nonterminals); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyInt_FromLong(__pyx_v_self->max_nonterminals); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_107)); - PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_107)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_107)); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_2 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":427 - * if pre.max_nonterminals != self.max_nonterminals: - * logger.warn("Precomputation done with max nonterminals %d, decoder uses %d", pre.max_nonterminals, self.max_nonterminals) - * if pre.max_length != self.max_length: # <<<<<<<<<<<<<< - * logger.warn("Precomputation done with max terminals %d, decoder uses %d", pre.max_length, self.max_length) - * if pre.train_max_initial_size != self.train_max_initial_size: - */ - __pyx_t_1 = (__pyx_v_pre->max_length != __pyx_v_self->max_length); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":428 - * logger.warn("Precomputation done with max nonterminals %d, decoder uses %d", pre.max_nonterminals, self.max_nonterminals) - * if pre.max_length != self.max_length: - * logger.warn("Precomputation done with max terminals %d, decoder uses %d", pre.max_length, self.max_length) # <<<<<<<<<<<<<< - * if pre.train_max_initial_size != self.train_max_initial_size: - * raise Exception("Precomputation done with max initial size %d, decoder uses %d" % (pre.train_max_initial_size, self.train_max_initial_size)) - */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__warn); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyInt_FromLong(__pyx_v_pre->max_length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyInt_FromLong(__pyx_v_self->max_length); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_108)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_108)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_108)); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_3 = 0; - __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":429 - * if pre.max_length != self.max_length: - * logger.warn("Precomputation done with max terminals %d, decoder uses %d", pre.max_length, self.max_length) - * if pre.train_max_initial_size != self.train_max_initial_size: # <<<<<<<<<<<<<< - * raise Exception("Precomputation done with max initial size %d, decoder uses %d" % (pre.train_max_initial_size, self.train_max_initial_size)) - * if pre.train_min_gap_size != self.train_min_gap_size: - */ - __pyx_t_1 = (__pyx_v_pre->train_max_initial_size != __pyx_v_self->train_max_initial_size); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":430 - * logger.warn("Precomputation done with max terminals %d, decoder uses %d", pre.max_length, self.max_length) - * if pre.train_max_initial_size != self.train_max_initial_size: - * raise Exception("Precomputation done with max initial size %d, decoder uses %d" % (pre.train_max_initial_size, self.train_max_initial_size)) # <<<<<<<<<<<<<< - * if pre.train_min_gap_size != self.train_min_gap_size: - * raise Exception("Precomputation done with min gap size %d, decoder uses %d" % (pre.train_min_gap_size, self.train_min_gap_size)) - */ - __pyx_t_4 = PyInt_FromLong(__pyx_v_pre->train_max_initial_size); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyInt_FromLong(__pyx_v_self->train_max_initial_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_4 = 0; - __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_109), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __Pyx_Raise(__pyx_t_2, 0, 0, 0); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L6; - } - __pyx_L6:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":431 - * if pre.train_max_initial_size != self.train_max_initial_size: - * raise Exception("Precomputation done with max initial size %d, decoder uses %d" % (pre.train_max_initial_size, self.train_max_initial_size)) - * if pre.train_min_gap_size != self.train_min_gap_size: # <<<<<<<<<<<<<< - * raise Exception("Precomputation done with min gap size %d, decoder uses %d" % (pre.train_min_gap_size, self.train_min_gap_size)) - * if self.use_index: - */ - __pyx_t_1 = (__pyx_v_pre->train_min_gap_size != __pyx_v_self->train_min_gap_size); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":432 - * raise Exception("Precomputation done with max initial size %d, decoder uses %d" % (pre.train_max_initial_size, self.train_max_initial_size)) - * if pre.train_min_gap_size != self.train_min_gap_size: - * raise Exception("Precomputation done with min gap size %d, decoder uses %d" % (pre.train_min_gap_size, self.train_min_gap_size)) # <<<<<<<<<<<<<< - * if self.use_index: - * logger.info("Converting %d hash keys on precomputed inverted index... ", len(pre.precomputed_index)) - */ - __pyx_t_2 = PyInt_FromLong(__pyx_v_pre->train_min_gap_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PyInt_FromLong(__pyx_v_self->train_min_gap_size); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_2 = 0; - __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_110), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_5)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); - __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_Raise(__pyx_t_5, 0, 0, 0); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L7; - } - __pyx_L7:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":433 - * if pre.train_min_gap_size != self.train_min_gap_size: - * raise Exception("Precomputation done with min gap size %d, decoder uses %d" % (pre.train_min_gap_size, self.train_min_gap_size)) - * if self.use_index: # <<<<<<<<<<<<<< - * logger.info("Converting %d hash keys on precomputed inverted index... ", len(pre.precomputed_index)) - * for pattern, arr in pre.precomputed_index.iteritems(): - */ - if (__pyx_v_self->use_index) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":434 - * raise Exception("Precomputation done with min gap size %d, decoder uses %d" % (pre.train_min_gap_size, self.train_min_gap_size)) - * if self.use_index: - * logger.info("Converting %d hash keys on precomputed inverted index... ", len(pre.precomputed_index)) # <<<<<<<<<<<<<< - * for pattern, arr in pre.precomputed_index.iteritems(): - * phrases = self.pattern2phrase_plus(pattern) - */ - __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__info); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __pyx_v_pre->precomputed_index; - __Pyx_INCREF(__pyx_t_5); - __pyx_t_6 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_111)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_111)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_111)); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":435 - * if self.use_index: - * logger.info("Converting %d hash keys on precomputed inverted index... ", len(pre.precomputed_index)) - * for pattern, arr in pre.precomputed_index.iteritems(): # <<<<<<<<<<<<<< - * phrases = self.pattern2phrase_plus(pattern) - * for phrase in phrases: - */ - __pyx_t_5 = PyObject_GetAttr(__pyx_v_pre->precomputed_index, __pyx_n_s__iteritems); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_5 = __pyx_t_2; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; - __pyx_t_7 = NULL; - } else { - __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_5)) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break; - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; - } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_5)) { - if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break; - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_2); __pyx_t_6++; - } else { - __pyx_t_2 = __pyx_t_7(__pyx_t_5); - if (unlikely(!__pyx_t_2)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { - PyObject* sequence = __pyx_t_2; - if (likely(PyTuple_CheckExact(sequence))) { - 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[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_4 = PyList_GET_ITEM(sequence, 0); - __pyx_t_3 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_8 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; - index = 0; __pyx_t_4 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_4)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_4); - index = 1; __pyx_t_3 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_3)) goto __pyx_L11_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - goto __pyx_L12_unpacking_done; - __pyx_L11_unpacking_failed:; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L12_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_pattern); - __pyx_v_pattern = __pyx_t_4; - __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_v_arr); - __pyx_v_arr = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":436 - * logger.info("Converting %d hash keys on precomputed inverted index... ", len(pre.precomputed_index)) - * for pattern, arr in pre.precomputed_index.iteritems(): - * phrases = self.pattern2phrase_plus(pattern) # <<<<<<<<<<<<<< - * for phrase in phrases: - * self.precomputed_index[phrase] = arr - */ - __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__pattern2phrase_plus); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_pattern); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_pattern); - __Pyx_GIVEREF(__pyx_v_pattern); - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_v_phrases); - __pyx_v_phrases = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":437 - * for pattern, arr in pre.precomputed_index.iteritems(): - * phrases = self.pattern2phrase_plus(pattern) - * for phrase in phrases: # <<<<<<<<<<<<<< - * self.precomputed_index[phrase] = arr - * if self.use_collocations: - */ - if (PyList_CheckExact(__pyx_v_phrases) || PyTuple_CheckExact(__pyx_v_phrases)) { - __pyx_t_4 = __pyx_v_phrases; __Pyx_INCREF(__pyx_t_4); __pyx_t_10 = 0; - __pyx_t_11 = NULL; - } else { - __pyx_t_10 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_phrases); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_11 = Py_TYPE(__pyx_t_4)->tp_iternext; - } - for (;;) { - if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_4)) { - if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_4)) break; - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_10); __Pyx_INCREF(__pyx_t_3); __pyx_t_10++; - } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_4)) { - if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_10); __Pyx_INCREF(__pyx_t_3); __pyx_t_10++; - } else { - __pyx_t_3 = __pyx_t_11(__pyx_t_4); - if (unlikely(!__pyx_t_3)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF(__pyx_v_phrase); - __pyx_v_phrase = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":438 - * phrases = self.pattern2phrase_plus(pattern) - * for phrase in phrases: - * self.precomputed_index[phrase] = arr # <<<<<<<<<<<<<< - * if self.use_collocations: - * logger.info("Converting %d hash keys on precomputed collocations... ", len(pre.precomputed_collocations)) - */ - if (PyObject_SetItem(__pyx_v_self->precomputed_index, __pyx_v_phrase, __pyx_v_arr) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 438; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L8; - } - __pyx_L8:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":439 - * for phrase in phrases: - * self.precomputed_index[phrase] = arr - * if self.use_collocations: # <<<<<<<<<<<<<< - * logger.info("Converting %d hash keys on precomputed collocations... ", len(pre.precomputed_collocations)) - * for pattern, arr in pre.precomputed_collocations.iteritems(): - */ - if (__pyx_v_self->use_collocations) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":440 - * self.precomputed_index[phrase] = arr - * if self.use_collocations: - * logger.info("Converting %d hash keys on precomputed collocations... ", len(pre.precomputed_collocations)) # <<<<<<<<<<<<<< - * for pattern, arr in pre.precomputed_collocations.iteritems(): - * phrase = self.pattern2phrase(pattern) - */ - __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__info); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __pyx_v_pre->precomputed_collocations; - __Pyx_INCREF(__pyx_t_5); - __pyx_t_6 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_112)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_112)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_112)); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":441 - * if self.use_collocations: - * logger.info("Converting %d hash keys on precomputed collocations... ", len(pre.precomputed_collocations)) - * for pattern, arr in pre.precomputed_collocations.iteritems(): # <<<<<<<<<<<<<< - * phrase = self.pattern2phrase(pattern) - * self.precomputed_collocations[phrase] = arr - */ - __pyx_t_5 = PyObject_GetAttr(__pyx_v_pre->precomputed_collocations, __pyx_n_s__iteritems); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_5 = __pyx_t_3; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; - __pyx_t_7 = NULL; - } else { - __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_5)) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break; - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; - } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_5)) { - if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break; - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; - } else { - __pyx_t_3 = __pyx_t_7(__pyx_t_5); - if (unlikely(!__pyx_t_3)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { - PyObject* sequence = __pyx_t_3; - if (likely(PyTuple_CheckExact(sequence))) { - 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[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_4 = PyList_GET_ITEM(sequence, 0); - __pyx_t_2 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_8 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext; - index = 0; __pyx_t_4 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_4)) goto __pyx_L18_unpacking_failed; - __Pyx_GOTREF(__pyx_t_4); - index = 1; __pyx_t_2 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_2)) goto __pyx_L18_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - goto __pyx_L19_unpacking_done; - __pyx_L18_unpacking_failed:; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L19_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_pattern); - __pyx_v_pattern = __pyx_t_4; - __pyx_t_4 = 0; - __Pyx_XDECREF(__pyx_v_arr); - __pyx_v_arr = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":442 - * logger.info("Converting %d hash keys on precomputed collocations... ", len(pre.precomputed_collocations)) - * for pattern, arr in pre.precomputed_collocations.iteritems(): - * phrase = self.pattern2phrase(pattern) # <<<<<<<<<<<<<< - * self.precomputed_collocations[phrase] = arr - * stop_time = monitor_cpu() - */ - __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__pattern2phrase); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_v_pattern); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_pattern); - __Pyx_GIVEREF(__pyx_v_pattern); - __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_v_phrase); - __pyx_v_phrase = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":443 - * for pattern, arr in pre.precomputed_collocations.iteritems(): - * phrase = self.pattern2phrase(pattern) - * self.precomputed_collocations[phrase] = arr # <<<<<<<<<<<<<< - * stop_time = monitor_cpu() - * logger.info("Processing precomputations took %f seconds", stop_time - start_time) - */ - if (PyObject_SetItem(__pyx_v_self->precomputed_collocations, __pyx_v_phrase, __pyx_v_arr) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L15; - } - __pyx_L15:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":444 - * phrase = self.pattern2phrase(pattern) - * self.precomputed_collocations[phrase] = arr - * stop_time = monitor_cpu() # <<<<<<<<<<<<<< - * logger.info("Processing precomputations took %f seconds", stop_time - start_time) - * - */ - __pyx_t_5 = PyFloat_FromDouble(__pyx_f_8_cdec_sa_monitor_cpu()); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_v_stop_time = __pyx_t_5; - __pyx_t_5 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":445 - * self.precomputed_collocations[phrase] = arr - * stop_time = monitor_cpu() - * logger.info("Processing precomputations took %f seconds", stop_time - start_time) # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__info); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Subtract(__pyx_v_stop_time, __pyx_v_start_time); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_113)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_113)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_113)); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L3; - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.precompute", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_pre); - __Pyx_XDECREF(__pyx_v_start_time); - __Pyx_XDECREF(__pyx_v_pattern); - __Pyx_XDECREF(__pyx_v_arr); - __Pyx_XDECREF(__pyx_v_phrases); - __Pyx_XDECREF(__pyx_v_phrase); - __Pyx_XDECREF(__pyx_v_stop_time); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_11get_precomputed_collocation(PyObject *__pyx_v_self, PyObject *__pyx_v_phrase); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_11get_precomputed_collocation(PyObject *__pyx_v_self, PyObject *__pyx_v_phrase) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_precomputed_collocation (wrapper)", 0); - __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_10get_precomputed_collocation(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), ((PyObject *)__pyx_v_phrase)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":448 - * - * - * def get_precomputed_collocation(self, phrase): # <<<<<<<<<<<<<< - * if phrase in self.precomputed_collocations: - * arr = self.precomputed_collocations[phrase] - */ - -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_10get_precomputed_collocation(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_phrase) { - PyObject *__pyx_v_arr = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - Py_ssize_t __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get_precomputed_collocation", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":449 - * - * def get_precomputed_collocation(self, phrase): - * if phrase in self.precomputed_collocations: # <<<<<<<<<<<<<< - * arr = self.precomputed_collocations[phrase] - * return PhraseLocation(arr=arr, arr_low=0, arr_high=len(arr), num_subpatterns=phrase.arity()+1) - */ - __pyx_t_1 = ((PySequence_Contains(__pyx_v_self->precomputed_collocations, __pyx_v_phrase))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":450 - * def get_precomputed_collocation(self, phrase): - * if phrase in self.precomputed_collocations: - * arr = self.precomputed_collocations[phrase] # <<<<<<<<<<<<<< - * return PhraseLocation(arr=arr, arr_low=0, arr_high=len(arr), num_subpatterns=phrase.arity()+1) - * return None - */ - __pyx_t_2 = PyObject_GetItem(__pyx_v_self->precomputed_collocations, __pyx_v_phrase); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_arr = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":451 - * if phrase in self.precomputed_collocations: - * arr = self.precomputed_collocations[phrase] - * return PhraseLocation(arr=arr, arr_low=0, arr_high=len(arr), num_subpatterns=phrase.arity()+1) # <<<<<<<<<<<<<< - * return None - * - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__arr), __pyx_v_arr) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__arr_low), __pyx_int_0) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = PyObject_Length(__pyx_v_arr); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__arr_high), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyObject_GetAttr(__pyx_v_phrase, __pyx_n_s__arity); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_Add(__pyx_t_5, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__num_subpatterns), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_PhraseLocation)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":452 - * arr = self.precomputed_collocations[phrase] - * return PhraseLocation(arr=arr, arr_low=0, arr_high=len(arr), num_subpatterns=phrase.arity()+1) - * return None # <<<<<<<<<<<<<< - * - * - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(Py_None); - __pyx_r = Py_None; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.get_precomputed_collocation", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_arr); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":455 - * - * - * cdef int* baeza_yates_helper(self, int low1, int high1, int* arr1, int step1, # <<<<<<<<<<<<<< - * int low2, int high2, int* arr2, int step2, - * int offset_by_one, int len_last, int num_subpatterns, int* result_len): - */ - -static int *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_baeza_yates_helper(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, int __pyx_v_low1, int __pyx_v_high1, int *__pyx_v_arr1, int __pyx_v_step1, int __pyx_v_low2, int __pyx_v_high2, int *__pyx_v_arr2, int __pyx_v_step2, int __pyx_v_offset_by_one, int __pyx_v_len_last, int __pyx_v_num_subpatterns, int *__pyx_v_result_len) { - int __pyx_v_i1; - int __pyx_v_i2; - int __pyx_v_med1; - int __pyx_v_med2; - int __pyx_v_med1_plus; - int __pyx_v_med1_minus; - int __pyx_v_med2_minus; - int __pyx_v_med2_plus; - int __pyx_v_d_first; - int __pyx_v_qsetsize; - int __pyx_v_dsetsize; - int __pyx_v_tmp; - int __pyx_v_search_low; - int __pyx_v_search_high; - int __pyx_v_med_result_len; - int __pyx_v_low_result_len; - int __pyx_v_high_result_len; - long __pyx_v_comparison; - int *__pyx_v_result; - int *__pyx_v_low_result; - int *__pyx_v_med_result; - int *__pyx_v_high_result; - struct __pyx_t_8_cdec_sa_Matching __pyx_v_loc1; - struct __pyx_t_8_cdec_sa_Matching __pyx_v_loc2; - int *__pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - double __pyx_t_5; - double __pyx_t_6; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("baeza_yates_helper", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":468 - * cdef Matching loc1, loc2 - * - * result = malloc(0*sizeof(int*)) # <<<<<<<<<<<<<< - * - * d_first = 0 - */ - __pyx_v_result = ((int *)malloc((0 * (sizeof(int *))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":470 - * result = malloc(0*sizeof(int*)) - * - * d_first = 0 # <<<<<<<<<<<<<< - * if high1 - low1 > high2 - low2: - * d_first = 1 - */ - __pyx_v_d_first = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":471 - * - * d_first = 0 - * if high1 - low1 > high2 - low2: # <<<<<<<<<<<<<< - * d_first = 1 - * - */ - __pyx_t_1 = ((__pyx_v_high1 - __pyx_v_low1) > (__pyx_v_high2 - __pyx_v_low2)); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":472 - * d_first = 0 - * if high1 - low1 > high2 - low2: - * d_first = 1 # <<<<<<<<<<<<<< - * - * # First, check to see if we are at any of the recursive base cases - */ - __pyx_v_d_first = 1; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":476 - * # First, check to see if we are at any of the recursive base cases - * # Case 1: one of the sets is empty - * if low1 >= high1 or low2 >= high2: # <<<<<<<<<<<<<< - * return result - * - */ - __pyx_t_1 = (__pyx_v_low1 >= __pyx_v_high1); - if (!__pyx_t_1) { - __pyx_t_2 = (__pyx_v_low2 >= __pyx_v_high2); - __pyx_t_3 = __pyx_t_2; - } else { - __pyx_t_3 = __pyx_t_1; - } - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":477 - * # Case 1: one of the sets is empty - * if low1 >= high1 or low2 >= high2: - * return result # <<<<<<<<<<<<<< - * - * # Case 2: sets are non-overlapping - */ - __pyx_r = __pyx_v_result; - goto __pyx_L0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":480 - * - * # Case 2: sets are non-overlapping - * assign_matching(&loc1, arr1, high1-step1, step1, self.fda.sent_id.arr) # <<<<<<<<<<<<<< - * assign_matching(&loc2, arr2, low2, step2, self.fda.sent_id.arr) - * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == -1: - */ - __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc1), __pyx_v_arr1, (__pyx_v_high1 - __pyx_v_step1), __pyx_v_step1, __pyx_v_self->fda->sent_id->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":481 - * # Case 2: sets are non-overlapping - * assign_matching(&loc1, arr1, high1-step1, step1, self.fda.sent_id.arr) - * assign_matching(&loc2, arr2, low2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< - * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == -1: - * return result - */ - __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, __pyx_v_low2, __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":482 - * assign_matching(&loc1, arr1, high1-step1, step1, self.fda.sent_id.arr) - * assign_matching(&loc2, arr2, low2, step2, self.fda.sent_id.arr) - * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == -1: # <<<<<<<<<<<<<< - * return result - * - */ - __pyx_t_3 = (((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last) == -1); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":483 - * assign_matching(&loc2, arr2, low2, step2, self.fda.sent_id.arr) - * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == -1: - * return result # <<<<<<<<<<<<<< - * - * assign_matching(&loc1, arr1, low1, step1, self.fda.sent_id.arr) - */ - __pyx_r = __pyx_v_result; - goto __pyx_L0; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":485 - * return result - * - * assign_matching(&loc1, arr1, low1, step1, self.fda.sent_id.arr) # <<<<<<<<<<<<<< - * assign_matching(&loc2, arr2, high2-step2, step2, self.fda.sent_id.arr) - * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: - */ - __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc1), __pyx_v_arr1, __pyx_v_low1, __pyx_v_step1, __pyx_v_self->fda->sent_id->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":486 - * - * assign_matching(&loc1, arr1, low1, step1, self.fda.sent_id.arr) - * assign_matching(&loc2, arr2, high2-step2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< - * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: - * return result - */ - __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, (__pyx_v_high2 - __pyx_v_step2), __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":487 - * assign_matching(&loc1, arr1, low1, step1, self.fda.sent_id.arr) - * assign_matching(&loc2, arr2, high2-step2, step2, self.fda.sent_id.arr) - * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: # <<<<<<<<<<<<<< - * return result - * - */ - __pyx_t_3 = (((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last) == 1); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":488 - * assign_matching(&loc2, arr2, high2-step2, step2, self.fda.sent_id.arr) - * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: - * return result # <<<<<<<<<<<<<< - * - * # Case 3: query set and data set do not meet size mismatch constraints; - */ - __pyx_r = __pyx_v_result; - goto __pyx_L0; - goto __pyx_L6; - } - __pyx_L6:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":492 - * # Case 3: query set and data set do not meet size mismatch constraints; - * # We use mergesort instead in this case - * qsetsize = (high1-low1) / step1 # <<<<<<<<<<<<<< - * dsetsize = (high2-low2) / step2 - * if d_first: - */ - __pyx_t_4 = (__pyx_v_high1 - __pyx_v_low1); - if (unlikely(__pyx_v_step1 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_step1 == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_4))) { - PyErr_Format(PyExc_OverflowError, "value too large to perform division"); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_qsetsize = __Pyx_div_int(__pyx_t_4, __pyx_v_step1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":493 - * # We use mergesort instead in this case - * qsetsize = (high1-low1) / step1 - * dsetsize = (high2-low2) / step2 # <<<<<<<<<<<<<< - * if d_first: - * tmp = qsetsize - */ - __pyx_t_4 = (__pyx_v_high2 - __pyx_v_low2); - if (unlikely(__pyx_v_step2 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 493; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_step2 == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_4))) { - PyErr_Format(PyExc_OverflowError, "value too large to perform division"); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 493; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_dsetsize = __Pyx_div_int(__pyx_t_4, __pyx_v_step2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":494 - * qsetsize = (high1-low1) / step1 - * dsetsize = (high2-low2) / step2 - * if d_first: # <<<<<<<<<<<<<< - * tmp = qsetsize - * qsetsize = dsetsize - */ - if (__pyx_v_d_first) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":495 - * dsetsize = (high2-low2) / step2 - * if d_first: - * tmp = qsetsize # <<<<<<<<<<<<<< - * qsetsize = dsetsize - * dsetsize = tmp - */ - __pyx_v_tmp = __pyx_v_qsetsize; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":496 - * if d_first: - * tmp = qsetsize - * qsetsize = dsetsize # <<<<<<<<<<<<<< - * dsetsize = tmp - * - */ - __pyx_v_qsetsize = __pyx_v_dsetsize; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":497 - * tmp = qsetsize - * qsetsize = dsetsize - * dsetsize = tmp # <<<<<<<<<<<<<< - * - * if self.by_slack_factor * qsetsize * log(dsetsize) / log(2) > dsetsize: - */ - __pyx_v_dsetsize = __pyx_v_tmp; - goto __pyx_L7; - } - __pyx_L7:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":499 - * dsetsize = tmp - * - * if self.by_slack_factor * qsetsize * log(dsetsize) / log(2) > dsetsize: # <<<<<<<<<<<<<< - * free(result) - * return self.merge_helper(low1, high1, arr1, step1, low2, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, result_len) - */ - __pyx_t_5 = ((__pyx_v_self->by_slack_factor * __pyx_v_qsetsize) * log(__pyx_v_dsetsize)); - __pyx_t_6 = log(2.0); - if (unlikely(__pyx_t_6 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_3 = ((__pyx_t_5 / __pyx_t_6) > __pyx_v_dsetsize); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":500 - * - * if self.by_slack_factor * qsetsize * log(dsetsize) / log(2) > dsetsize: - * free(result) # <<<<<<<<<<<<<< - * return self.merge_helper(low1, high1, arr1, step1, low2, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, result_len) - * - */ - free(__pyx_v_result); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":501 - * if self.by_slack_factor * qsetsize * log(dsetsize) / log(2) > dsetsize: - * free(result) - * return self.merge_helper(low1, high1, arr1, step1, low2, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, result_len) # <<<<<<<<<<<<<< - * - * # binary search. There are two flavors, depending on - */ - __pyx_r = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->merge_helper(__pyx_v_self, __pyx_v_low1, __pyx_v_high1, __pyx_v_arr1, __pyx_v_step1, __pyx_v_low2, __pyx_v_high2, __pyx_v_arr2, __pyx_v_step2, __pyx_v_offset_by_one, __pyx_v_len_last, __pyx_v_num_subpatterns, __pyx_v_result_len); - goto __pyx_L0; - goto __pyx_L8; - } - __pyx_L8:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":505 - * # binary search. There are two flavors, depending on - * # whether the queryset or dataset is first - * if d_first: # <<<<<<<<<<<<<< - * med2 = median(low2, high2, step2) - * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) - */ - if (__pyx_v_d_first) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":506 - * # whether the queryset or dataset is first - * if d_first: - * med2 = median(low2, high2, step2) # <<<<<<<<<<<<<< - * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) - * - */ - __pyx_v_med2 = __pyx_f_8_cdec_sa_median(__pyx_v_low2, __pyx_v_high2, __pyx_v_step2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":507 - * if d_first: - * med2 = median(low2, high2, step2) - * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< - * - * search_low = low1 - */ - __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, __pyx_v_med2, __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":509 - * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) - * - * search_low = low1 # <<<<<<<<<<<<<< - * search_high = high1 - * while search_low < search_high: - */ - __pyx_v_search_low = __pyx_v_low1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":510 - * - * search_low = low1 - * search_high = high1 # <<<<<<<<<<<<<< - * while search_low < search_high: - * med1 = median(search_low, search_high, step1) - */ - __pyx_v_search_high = __pyx_v_high1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":511 - * search_low = low1 - * search_high = high1 - * while search_low < search_high: # <<<<<<<<<<<<<< - * med1 = median(search_low, search_high, step1) - * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) - */ - while (1) { - __pyx_t_3 = (__pyx_v_search_low < __pyx_v_search_high); - if (!__pyx_t_3) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":512 - * search_high = high1 - * while search_low < search_high: - * med1 = median(search_low, search_high, step1) # <<<<<<<<<<<<<< - * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) - * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) - */ - __pyx_v_med1 = __pyx_f_8_cdec_sa_median(__pyx_v_search_low, __pyx_v_search_high, __pyx_v_step1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":513 - * while search_low < search_high: - * med1 = median(search_low, search_high, step1) - * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) # <<<<<<<<<<<<<< - * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) - * if comparison == -1: - */ - __pyx_f_8_cdec_sa_find_comparable_matchings(__pyx_v_low1, __pyx_v_high1, __pyx_v_arr1, __pyx_v_step1, __pyx_v_med1, (&__pyx_v_med1_minus), (&__pyx_v_med1_plus)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":514 - * med1 = median(search_low, search_high, step1) - * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) - * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) # <<<<<<<<<<<<<< - * if comparison == -1: - * search_low = med1_plus - */ - __pyx_v_comparison = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings_set(__pyx_v_self, __pyx_v_med1_minus, __pyx_v_med1_plus, __pyx_v_arr1, __pyx_v_step1, (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":517 - * if comparison == -1: - * search_low = med1_plus - * elif comparison == 1: # <<<<<<<<<<<<<< - * search_high = med1_minus - * else: - */ - switch (__pyx_v_comparison) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":515 - * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) - * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) - * if comparison == -1: # <<<<<<<<<<<<<< - * search_low = med1_plus - * elif comparison == 1: - */ - case -1: - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":516 - * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) - * if comparison == -1: - * search_low = med1_plus # <<<<<<<<<<<<<< - * elif comparison == 1: - * search_high = med1_minus - */ - __pyx_v_search_low = __pyx_v_med1_plus; - break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":517 - * if comparison == -1: - * search_low = med1_plus - * elif comparison == 1: # <<<<<<<<<<<<<< - * search_high = med1_minus - * else: - */ - case 1: - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":518 - * search_low = med1_plus - * elif comparison == 1: - * search_high = med1_minus # <<<<<<<<<<<<<< - * else: - * break - */ - __pyx_v_search_high = __pyx_v_med1_minus; - break; - default: - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":520 - * search_high = med1_minus - * else: - * break # <<<<<<<<<<<<<< - * else: - * med1 = median(low1, high1, step1) - */ - goto __pyx_L11_break; - break; - } - } - __pyx_L11_break:; - goto __pyx_L9; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":522 - * break - * else: - * med1 = median(low1, high1, step1) # <<<<<<<<<<<<<< - * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) - * - */ - __pyx_v_med1 = __pyx_f_8_cdec_sa_median(__pyx_v_low1, __pyx_v_high1, __pyx_v_step1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":523 - * else: - * med1 = median(low1, high1, step1) - * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) # <<<<<<<<<<<<<< - * - * search_low = low2 - */ - __pyx_f_8_cdec_sa_find_comparable_matchings(__pyx_v_low1, __pyx_v_high1, __pyx_v_arr1, __pyx_v_step1, __pyx_v_med1, (&__pyx_v_med1_minus), (&__pyx_v_med1_plus)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":525 - * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) - * - * search_low = low2 # <<<<<<<<<<<<<< - * search_high = high2 - * while search_low < search_high: - */ - __pyx_v_search_low = __pyx_v_low2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":526 - * - * search_low = low2 - * search_high = high2 # <<<<<<<<<<<<<< - * while search_low < search_high: - * med2 = median(search_low, search_high, step2) - */ - __pyx_v_search_high = __pyx_v_high2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":527 - * search_low = low2 - * search_high = high2 - * while search_low < search_high: # <<<<<<<<<<<<<< - * med2 = median(search_low, search_high, step2) - * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) - */ - while (1) { - __pyx_t_3 = (__pyx_v_search_low < __pyx_v_search_high); - if (!__pyx_t_3) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":528 - * search_high = high2 - * while search_low < search_high: - * med2 = median(search_low, search_high, step2) # <<<<<<<<<<<<<< - * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) - * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) - */ - __pyx_v_med2 = __pyx_f_8_cdec_sa_median(__pyx_v_search_low, __pyx_v_search_high, __pyx_v_step2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":529 - * while search_low < search_high: - * med2 = median(search_low, search_high, step2) - * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< - * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) - * if comparison == -1: - */ - __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, __pyx_v_med2, __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":530 - * med2 = median(search_low, search_high, step2) - * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) - * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) # <<<<<<<<<<<<<< - * if comparison == -1: - * search_high = med2 - */ - __pyx_v_comparison = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings_set(__pyx_v_self, __pyx_v_med1_minus, __pyx_v_med1_plus, __pyx_v_arr1, __pyx_v_step1, (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":533 - * if comparison == -1: - * search_high = med2 - * elif comparison == 1: # <<<<<<<<<<<<<< - * search_low = med2 + step2 - * else: - */ - switch (__pyx_v_comparison) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":531 - * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) - * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) - * if comparison == -1: # <<<<<<<<<<<<<< - * search_high = med2 - * elif comparison == 1: - */ - case -1: - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":532 - * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) - * if comparison == -1: - * search_high = med2 # <<<<<<<<<<<<<< - * elif comparison == 1: - * search_low = med2 + step2 - */ - __pyx_v_search_high = __pyx_v_med2; - break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":533 - * if comparison == -1: - * search_high = med2 - * elif comparison == 1: # <<<<<<<<<<<<<< - * search_low = med2 + step2 - * else: - */ - case 1: - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":534 - * search_high = med2 - * elif comparison == 1: - * search_low = med2 + step2 # <<<<<<<<<<<<<< - * else: - * break - */ - __pyx_v_search_low = (__pyx_v_med2 + __pyx_v_step2); - break; - default: - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":536 - * search_low = med2 + step2 - * else: - * break # <<<<<<<<<<<<<< - * - * med_result_len = 0 - */ - goto __pyx_L13_break; - break; - } - } - __pyx_L13_break:; - } - __pyx_L9:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":538 - * break - * - * med_result_len = 0 # <<<<<<<<<<<<<< - * med_result = malloc(0*sizeof(int*)) - * if search_high > search_low: - */ - __pyx_v_med_result_len = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":539 - * - * med_result_len = 0 - * med_result = malloc(0*sizeof(int*)) # <<<<<<<<<<<<<< - * if search_high > search_low: - * # Then there is a match for the median element of Q - */ - __pyx_v_med_result = ((int *)malloc((0 * (sizeof(int *))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":540 - * med_result_len = 0 - * med_result = malloc(0*sizeof(int*)) - * if search_high > search_low: # <<<<<<<<<<<<<< - * # Then there is a match for the median element of Q - * # What we want to find is the group of all bindings in the first set - */ - __pyx_t_3 = (__pyx_v_search_high > __pyx_v_search_low); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":546 - * # want to store the bindings for all of those elements. We can - * # subsequently throw all of them away. - * med2_minus = med2 # <<<<<<<<<<<<<< - * med2_plus = med2 + step2 - * i1 = med1_minus - */ - __pyx_v_med2_minus = __pyx_v_med2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":547 - * # subsequently throw all of them away. - * med2_minus = med2 - * med2_plus = med2 + step2 # <<<<<<<<<<<<<< - * i1 = med1_minus - * while i1 < med1_plus: - */ - __pyx_v_med2_plus = (__pyx_v_med2 + __pyx_v_step2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":548 - * med2_minus = med2 - * med2_plus = med2 + step2 - * i1 = med1_minus # <<<<<<<<<<<<<< - * while i1 < med1_plus: - * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) - */ - __pyx_v_i1 = __pyx_v_med1_minus; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":549 - * med2_plus = med2 + step2 - * i1 = med1_minus - * while i1 < med1_plus: # <<<<<<<<<<<<<< - * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) - * while med2_minus-step2 >= low2: - */ - while (1) { - __pyx_t_3 = (__pyx_v_i1 < __pyx_v_med1_plus); - if (!__pyx_t_3) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":550 - * i1 = med1_minus - * while i1 < med1_plus: - * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) # <<<<<<<<<<<<<< - * while med2_minus-step2 >= low2: - * assign_matching(&loc2, arr2, med2_minus-step2, step2, self.fda.sent_id.arr) - */ - __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc1), __pyx_v_arr1, __pyx_v_i1, __pyx_v_step1, __pyx_v_self->fda->sent_id->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":551 - * while i1 < med1_plus: - * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) - * while med2_minus-step2 >= low2: # <<<<<<<<<<<<<< - * assign_matching(&loc2, arr2, med2_minus-step2, step2, self.fda.sent_id.arr) - * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) < 1: - */ - while (1) { - __pyx_t_3 = ((__pyx_v_med2_minus - __pyx_v_step2) >= __pyx_v_low2); - if (!__pyx_t_3) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":552 - * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) - * while med2_minus-step2 >= low2: - * assign_matching(&loc2, arr2, med2_minus-step2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< - * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) < 1: - * med2_minus = med2_minus - step2 - */ - __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, (__pyx_v_med2_minus - __pyx_v_step2), __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":553 - * while med2_minus-step2 >= low2: - * assign_matching(&loc2, arr2, med2_minus-step2, step2, self.fda.sent_id.arr) - * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) < 1: # <<<<<<<<<<<<<< - * med2_minus = med2_minus - step2 - * else: - */ - __pyx_t_3 = (((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last) < 1); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":554 - * assign_matching(&loc2, arr2, med2_minus-step2, step2, self.fda.sent_id.arr) - * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) < 1: - * med2_minus = med2_minus - step2 # <<<<<<<<<<<<<< - * else: - * break - */ - __pyx_v_med2_minus = (__pyx_v_med2_minus - __pyx_v_step2); - goto __pyx_L19; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":556 - * med2_minus = med2_minus - step2 - * else: - * break # <<<<<<<<<<<<<< - * i2 = med2_minus - * while i2 < high2: - */ - goto __pyx_L18_break; - } - __pyx_L19:; - } - __pyx_L18_break:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":557 - * else: - * break - * i2 = med2_minus # <<<<<<<<<<<<<< - * while i2 < high2: - * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) - */ - __pyx_v_i2 = __pyx_v_med2_minus; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":558 - * break - * i2 = med2_minus - * while i2 < high2: # <<<<<<<<<<<<<< - * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) - * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) - */ - while (1) { - __pyx_t_3 = (__pyx_v_i2 < __pyx_v_high2); - if (!__pyx_t_3) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":559 - * i2 = med2_minus - * while i2 < high2: - * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< - * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) - * if comparison == 0: - */ - __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, __pyx_v_i2, __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":560 - * while i2 < high2: - * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) - * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) # <<<<<<<<<<<<<< - * if comparison == 0: - * pass - */ - __pyx_v_comparison = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":561 - * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) - * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) - * if comparison == 0: # <<<<<<<<<<<<<< - * pass - * med_result = append_combined_matching(med_result, &loc1, &loc2, offset_by_one, num_subpatterns, &med_result_len) - */ - __pyx_t_3 = (__pyx_v_comparison == 0); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":563 - * if comparison == 0: - * pass - * med_result = append_combined_matching(med_result, &loc1, &loc2, offset_by_one, num_subpatterns, &med_result_len) # <<<<<<<<<<<<<< - * if comparison == -1: - * break - */ - __pyx_v_med_result = __pyx_f_8_cdec_sa_append_combined_matching(__pyx_v_med_result, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_num_subpatterns, (&__pyx_v_med_result_len)); - goto __pyx_L22; - } - __pyx_L22:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":564 - * pass - * med_result = append_combined_matching(med_result, &loc1, &loc2, offset_by_one, num_subpatterns, &med_result_len) - * if comparison == -1: # <<<<<<<<<<<<<< - * break - * i2 = i2 + step2 - */ - __pyx_t_3 = (__pyx_v_comparison == -1); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":565 - * med_result = append_combined_matching(med_result, &loc1, &loc2, offset_by_one, num_subpatterns, &med_result_len) - * if comparison == -1: - * break # <<<<<<<<<<<<<< - * i2 = i2 + step2 - * if i2 > med2_plus: - */ - goto __pyx_L21_break; - goto __pyx_L23; - } - __pyx_L23:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":566 - * if comparison == -1: - * break - * i2 = i2 + step2 # <<<<<<<<<<<<<< - * if i2 > med2_plus: - * med2_plus = i2 - */ - __pyx_v_i2 = (__pyx_v_i2 + __pyx_v_step2); - } - __pyx_L21_break:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":567 - * break - * i2 = i2 + step2 - * if i2 > med2_plus: # <<<<<<<<<<<<<< - * med2_plus = i2 - * i1 = i1 + step1 - */ - __pyx_t_3 = (__pyx_v_i2 > __pyx_v_med2_plus); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":568 - * i2 = i2 + step2 - * if i2 > med2_plus: - * med2_plus = i2 # <<<<<<<<<<<<<< - * i1 = i1 + step1 - * - */ - __pyx_v_med2_plus = __pyx_v_i2; - goto __pyx_L24; - } - __pyx_L24:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":569 - * if i2 > med2_plus: - * med2_plus = i2 - * i1 = i1 + step1 # <<<<<<<<<<<<<< - * - * tmp = med1_minus - */ - __pyx_v_i1 = (__pyx_v_i1 + __pyx_v_step1); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":571 - * i1 = i1 + step1 - * - * tmp = med1_minus # <<<<<<<<<<<<<< - * med1_minus = med1_plus - * med1_plus = tmp - */ - __pyx_v_tmp = __pyx_v_med1_minus; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":572 - * - * tmp = med1_minus - * med1_minus = med1_plus # <<<<<<<<<<<<<< - * med1_plus = tmp - * else: - */ - __pyx_v_med1_minus = __pyx_v_med1_plus; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":573 - * tmp = med1_minus - * med1_minus = med1_plus - * med1_plus = tmp # <<<<<<<<<<<<<< - * else: - * # No match; need to figure out the point of division in D and Q - */ - __pyx_v_med1_plus = __pyx_v_tmp; - goto __pyx_L14; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":576 - * else: - * # No match; need to figure out the point of division in D and Q - * med2_minus = med2 # <<<<<<<<<<<<<< - * med2_plus = med2 - * if d_first: - */ - __pyx_v_med2_minus = __pyx_v_med2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":577 - * # No match; need to figure out the point of division in D and Q - * med2_minus = med2 - * med2_plus = med2 # <<<<<<<<<<<<<< - * if d_first: - * med2_minus = med2_minus + step2 - */ - __pyx_v_med2_plus = __pyx_v_med2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":578 - * med2_minus = med2 - * med2_plus = med2 - * if d_first: # <<<<<<<<<<<<<< - * med2_minus = med2_minus + step2 - * if comparison == -1: - */ - if (__pyx_v_d_first) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":579 - * med2_plus = med2 - * if d_first: - * med2_minus = med2_minus + step2 # <<<<<<<<<<<<<< - * if comparison == -1: - * med1_minus = med1_plus - */ - __pyx_v_med2_minus = (__pyx_v_med2_minus + __pyx_v_step2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":580 - * if d_first: - * med2_minus = med2_minus + step2 - * if comparison == -1: # <<<<<<<<<<<<<< - * med1_minus = med1_plus - * if comparison == 1: - */ - __pyx_t_3 = (__pyx_v_comparison == -1); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":581 - * med2_minus = med2_minus + step2 - * if comparison == -1: - * med1_minus = med1_plus # <<<<<<<<<<<<<< - * if comparison == 1: - * med1_plus = med1_minus - */ - __pyx_v_med1_minus = __pyx_v_med1_plus; - goto __pyx_L26; - } - __pyx_L26:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":582 - * if comparison == -1: - * med1_minus = med1_plus - * if comparison == 1: # <<<<<<<<<<<<<< - * med1_plus = med1_minus - * else: - */ - __pyx_t_3 = (__pyx_v_comparison == 1); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":583 - * med1_minus = med1_plus - * if comparison == 1: - * med1_plus = med1_minus # <<<<<<<<<<<<<< - * else: - * tmp = med1_minus - */ - __pyx_v_med1_plus = __pyx_v_med1_minus; - goto __pyx_L27; - } - __pyx_L27:; - goto __pyx_L25; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":585 - * med1_plus = med1_minus - * else: - * tmp = med1_minus # <<<<<<<<<<<<<< - * med1_minus = med1_plus - * med1_plus = tmp - */ - __pyx_v_tmp = __pyx_v_med1_minus; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":586 - * else: - * tmp = med1_minus - * med1_minus = med1_plus # <<<<<<<<<<<<<< - * med1_plus = tmp - * if comparison == 1: - */ - __pyx_v_med1_minus = __pyx_v_med1_plus; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":587 - * tmp = med1_minus - * med1_minus = med1_plus - * med1_plus = tmp # <<<<<<<<<<<<<< - * if comparison == 1: - * med2_minus = med2_minus + step2 - */ - __pyx_v_med1_plus = __pyx_v_tmp; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":588 - * med1_minus = med1_plus - * med1_plus = tmp - * if comparison == 1: # <<<<<<<<<<<<<< - * med2_minus = med2_minus + step2 - * med2_plus = med2_plus + step2 - */ - __pyx_t_3 = (__pyx_v_comparison == 1); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":589 - * med1_plus = tmp - * if comparison == 1: - * med2_minus = med2_minus + step2 # <<<<<<<<<<<<<< - * med2_plus = med2_plus + step2 - * - */ - __pyx_v_med2_minus = (__pyx_v_med2_minus + __pyx_v_step2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":590 - * if comparison == 1: - * med2_minus = med2_minus + step2 - * med2_plus = med2_plus + step2 # <<<<<<<<<<<<<< - * - * low_result_len = 0 - */ - __pyx_v_med2_plus = (__pyx_v_med2_plus + __pyx_v_step2); - goto __pyx_L28; - } - __pyx_L28:; - } - __pyx_L25:; - } - __pyx_L14:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":592 - * med2_plus = med2_plus + step2 - * - * low_result_len = 0 # <<<<<<<<<<<<<< - * low_result = self.baeza_yates_helper(low1, med1_plus, arr1, step1, low2, med2_plus, arr2, step2, offset_by_one, len_last, num_subpatterns, &low_result_len) - * high_result_len = 0 - */ - __pyx_v_low_result_len = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":593 - * - * low_result_len = 0 - * low_result = self.baeza_yates_helper(low1, med1_plus, arr1, step1, low2, med2_plus, arr2, step2, offset_by_one, len_last, num_subpatterns, &low_result_len) # <<<<<<<<<<<<<< - * high_result_len = 0 - * high_result = self.baeza_yates_helper(med1_minus, high1, arr1, step1, med2_minus, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, &high_result_len) - */ - __pyx_v_low_result = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->baeza_yates_helper(__pyx_v_self, __pyx_v_low1, __pyx_v_med1_plus, __pyx_v_arr1, __pyx_v_step1, __pyx_v_low2, __pyx_v_med2_plus, __pyx_v_arr2, __pyx_v_step2, __pyx_v_offset_by_one, __pyx_v_len_last, __pyx_v_num_subpatterns, (&__pyx_v_low_result_len)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":594 - * low_result_len = 0 - * low_result = self.baeza_yates_helper(low1, med1_plus, arr1, step1, low2, med2_plus, arr2, step2, offset_by_one, len_last, num_subpatterns, &low_result_len) - * high_result_len = 0 # <<<<<<<<<<<<<< - * high_result = self.baeza_yates_helper(med1_minus, high1, arr1, step1, med2_minus, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, &high_result_len) - * - */ - __pyx_v_high_result_len = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":595 - * low_result = self.baeza_yates_helper(low1, med1_plus, arr1, step1, low2, med2_plus, arr2, step2, offset_by_one, len_last, num_subpatterns, &low_result_len) - * high_result_len = 0 - * high_result = self.baeza_yates_helper(med1_minus, high1, arr1, step1, med2_minus, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, &high_result_len) # <<<<<<<<<<<<<< - * - * result = extend_arr(result, result_len, low_result, low_result_len) - */ - __pyx_v_high_result = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->baeza_yates_helper(__pyx_v_self, __pyx_v_med1_minus, __pyx_v_high1, __pyx_v_arr1, __pyx_v_step1, __pyx_v_med2_minus, __pyx_v_high2, __pyx_v_arr2, __pyx_v_step2, __pyx_v_offset_by_one, __pyx_v_len_last, __pyx_v_num_subpatterns, (&__pyx_v_high_result_len)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":597 - * high_result = self.baeza_yates_helper(med1_minus, high1, arr1, step1, med2_minus, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, &high_result_len) - * - * result = extend_arr(result, result_len, low_result, low_result_len) # <<<<<<<<<<<<<< - * result = extend_arr(result, result_len, med_result, med_result_len) - * result = extend_arr(result, result_len, high_result, high_result_len) - */ - __pyx_v_result = __pyx_f_8_cdec_sa_extend_arr(__pyx_v_result, __pyx_v_result_len, __pyx_v_low_result, __pyx_v_low_result_len); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":598 - * - * result = extend_arr(result, result_len, low_result, low_result_len) - * result = extend_arr(result, result_len, med_result, med_result_len) # <<<<<<<<<<<<<< - * result = extend_arr(result, result_len, high_result, high_result_len) - * free(low_result) - */ - __pyx_v_result = __pyx_f_8_cdec_sa_extend_arr(__pyx_v_result, __pyx_v_result_len, __pyx_v_med_result, __pyx_v_med_result_len); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":599 - * result = extend_arr(result, result_len, low_result, low_result_len) - * result = extend_arr(result, result_len, med_result, med_result_len) - * result = extend_arr(result, result_len, high_result, high_result_len) # <<<<<<<<<<<<<< - * free(low_result) - * free(med_result) - */ - __pyx_v_result = __pyx_f_8_cdec_sa_extend_arr(__pyx_v_result, __pyx_v_result_len, __pyx_v_high_result, __pyx_v_high_result_len); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":600 - * result = extend_arr(result, result_len, med_result, med_result_len) - * result = extend_arr(result, result_len, high_result, high_result_len) - * free(low_result) # <<<<<<<<<<<<<< - * free(med_result) - * free(high_result) - */ - free(__pyx_v_low_result); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":601 - * result = extend_arr(result, result_len, high_result, high_result_len) - * free(low_result) - * free(med_result) # <<<<<<<<<<<<<< - * free(high_result) - * - */ - free(__pyx_v_med_result); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":602 - * free(low_result) - * free(med_result) - * free(high_result) # <<<<<<<<<<<<<< - * - * return result - */ - free(__pyx_v_high_result); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":604 - * free(high_result) - * - * return result # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = __pyx_v_result; - goto __pyx_L0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_WriteUnraisable("_cdec_sa.HieroCachingRuleFactory.baeza_yates_helper", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":608 - * - * - * cdef long compare_matchings_set(self, int i1_minus, int i1_plus, int* arr1, int step1, # <<<<<<<<<<<<<< - * Matching* loc2, int offset_by_one, int len_last): - * """ - */ - -static long __pyx_f_8_cdec_sa_23HieroCachingRuleFactory_compare_matchings_set(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, int __pyx_v_i1_minus, int __pyx_v_i1_plus, int *__pyx_v_arr1, int __pyx_v_step1, struct __pyx_t_8_cdec_sa_Matching *__pyx_v_loc2, int __pyx_v_offset_by_one, int __pyx_v_len_last) { - int __pyx_v_i1; - int __pyx_v_comparison; - int __pyx_v_prev_comparison; - struct __pyx_t_8_cdec_sa_Matching __pyx_v_l1_stack; - struct __pyx_t_8_cdec_sa_Matching *__pyx_v_loc1; - long __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("compare_matchings_set", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":619 - * cdef Matching* loc1 - * - * loc1 = &l1_stack # <<<<<<<<<<<<<< - * - * i1 = i1_minus - */ - __pyx_v_loc1 = (&__pyx_v_l1_stack); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":621 - * loc1 = &l1_stack - * - * i1 = i1_minus # <<<<<<<<<<<<<< - * while i1 < i1_plus: - * assign_matching(loc1, arr1, i1, step1, self.fda.sent_id.arr) - */ - __pyx_v_i1 = __pyx_v_i1_minus; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":622 - * - * i1 = i1_minus - * while i1 < i1_plus: # <<<<<<<<<<<<<< - * assign_matching(loc1, arr1, i1, step1, self.fda.sent_id.arr) - * comparison = self.compare_matchings(loc1, loc2, offset_by_one, len_last) - */ - while (1) { - __pyx_t_1 = (__pyx_v_i1 < __pyx_v_i1_plus); - if (!__pyx_t_1) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":623 - * i1 = i1_minus - * while i1 < i1_plus: - * assign_matching(loc1, arr1, i1, step1, self.fda.sent_id.arr) # <<<<<<<<<<<<<< - * comparison = self.compare_matchings(loc1, loc2, offset_by_one, len_last) - * if comparison == 0: - */ - __pyx_f_8_cdec_sa_assign_matching(__pyx_v_loc1, __pyx_v_arr1, __pyx_v_i1, __pyx_v_step1, __pyx_v_self->fda->sent_id->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":624 - * while i1 < i1_plus: - * assign_matching(loc1, arr1, i1, step1, self.fda.sent_id.arr) - * comparison = self.compare_matchings(loc1, loc2, offset_by_one, len_last) # <<<<<<<<<<<<<< - * if comparison == 0: - * prev_comparison = 0 - */ - __pyx_v_comparison = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, __pyx_v_loc1, __pyx_v_loc2, __pyx_v_offset_by_one, __pyx_v_len_last); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":625 - * assign_matching(loc1, arr1, i1, step1, self.fda.sent_id.arr) - * comparison = self.compare_matchings(loc1, loc2, offset_by_one, len_last) - * if comparison == 0: # <<<<<<<<<<<<<< - * prev_comparison = 0 - * break - */ - __pyx_t_1 = (__pyx_v_comparison == 0); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":626 - * comparison = self.compare_matchings(loc1, loc2, offset_by_one, len_last) - * if comparison == 0: - * prev_comparison = 0 # <<<<<<<<<<<<<< - * break - * elif i1 == i1_minus: - */ - __pyx_v_prev_comparison = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":627 - * if comparison == 0: - * prev_comparison = 0 - * break # <<<<<<<<<<<<<< - * elif i1 == i1_minus: - * prev_comparison = comparison - */ - goto __pyx_L4_break; - goto __pyx_L5; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":628 - * prev_comparison = 0 - * break - * elif i1 == i1_minus: # <<<<<<<<<<<<<< - * prev_comparison = comparison - * else: - */ - __pyx_t_1 = (__pyx_v_i1 == __pyx_v_i1_minus); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":629 - * break - * elif i1 == i1_minus: - * prev_comparison = comparison # <<<<<<<<<<<<<< - * else: - * if comparison != prev_comparison: - */ - __pyx_v_prev_comparison = __pyx_v_comparison; - goto __pyx_L5; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":631 - * prev_comparison = comparison - * else: - * if comparison != prev_comparison: # <<<<<<<<<<<<<< - * prev_comparison = 0 - * break - */ - __pyx_t_1 = (__pyx_v_comparison != __pyx_v_prev_comparison); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":632 - * else: - * if comparison != prev_comparison: - * prev_comparison = 0 # <<<<<<<<<<<<<< - * break - * i1 = i1 + step1 - */ - __pyx_v_prev_comparison = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":633 - * if comparison != prev_comparison: - * prev_comparison = 0 - * break # <<<<<<<<<<<<<< - * i1 = i1 + step1 - * return prev_comparison - */ - goto __pyx_L4_break; - goto __pyx_L6; - } - __pyx_L6:; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":634 - * prev_comparison = 0 - * break - * i1 = i1 + step1 # <<<<<<<<<<<<<< - * return prev_comparison - * - */ - __pyx_v_i1 = (__pyx_v_i1 + __pyx_v_step1); - } - __pyx_L4_break:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":635 - * break - * i1 = i1 + step1 - * return prev_comparison # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = __pyx_v_prev_comparison; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":638 - * - * - * cdef long compare_matchings(self, Matching* loc1, Matching* loc2, int offset_by_one, int len_last): # <<<<<<<<<<<<<< - * cdef int i - * - */ - -static long __pyx_f_8_cdec_sa_23HieroCachingRuleFactory_compare_matchings(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_t_8_cdec_sa_Matching *__pyx_v_loc1, struct __pyx_t_8_cdec_sa_Matching *__pyx_v_loc2, int __pyx_v_offset_by_one, int __pyx_v_len_last) { - int __pyx_v_i; - long __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - __Pyx_RefNannySetupContext("compare_matchings", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":641 - * cdef int i - * - * if loc1.sent_id > loc2.sent_id: # <<<<<<<<<<<<<< - * return 1 - * if loc2.sent_id > loc1.sent_id: - */ - __pyx_t_1 = (__pyx_v_loc1->sent_id > __pyx_v_loc2->sent_id); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":642 - * - * if loc1.sent_id > loc2.sent_id: - * return 1 # <<<<<<<<<<<<<< - * if loc2.sent_id > loc1.sent_id: - * return -1 - */ - __pyx_r = 1; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":643 - * if loc1.sent_id > loc2.sent_id: - * return 1 - * if loc2.sent_id > loc1.sent_id: # <<<<<<<<<<<<<< - * return -1 - * - */ - __pyx_t_1 = (__pyx_v_loc2->sent_id > __pyx_v_loc1->sent_id); - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":644 - * return 1 - * if loc2.sent_id > loc1.sent_id: - * return -1 # <<<<<<<<<<<<<< - * - * if loc1.size == 1 and loc2.size == 1: - */ - __pyx_r = -1; - goto __pyx_L0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":646 - * return -1 - * - * if loc1.size == 1 and loc2.size == 1: # <<<<<<<<<<<<<< - * if loc2.arr[loc2.start] - loc1.arr[loc1.start] <= self.train_min_gap_size: - * return 1 - */ - __pyx_t_1 = (__pyx_v_loc1->size == 1); - if (__pyx_t_1) { - __pyx_t_2 = (__pyx_v_loc2->size == 1); - __pyx_t_3 = __pyx_t_2; - } else { - __pyx_t_3 = __pyx_t_1; - } - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":647 - * - * if loc1.size == 1 and loc2.size == 1: - * if loc2.arr[loc2.start] - loc1.arr[loc1.start] <= self.train_min_gap_size: # <<<<<<<<<<<<<< - * return 1 - * - */ - __pyx_t_3 = (((__pyx_v_loc2->arr[__pyx_v_loc2->start]) - (__pyx_v_loc1->arr[__pyx_v_loc1->start])) <= __pyx_v_self->train_min_gap_size); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":648 - * if loc1.size == 1 and loc2.size == 1: - * if loc2.arr[loc2.start] - loc1.arr[loc1.start] <= self.train_min_gap_size: - * return 1 # <<<<<<<<<<<<<< - * - * elif offset_by_one: - */ - __pyx_r = 1; - goto __pyx_L0; - goto __pyx_L6; - } - __pyx_L6:; - goto __pyx_L5; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":650 - * return 1 - * - * elif offset_by_one: # <<<<<<<<<<<<<< - * for i from 1 <= i < loc1.size: - * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i-1]: - */ - if (__pyx_v_offset_by_one) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":651 - * - * elif offset_by_one: - * for i from 1 <= i < loc1.size: # <<<<<<<<<<<<<< - * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i-1]: - * return 1 - */ - __pyx_t_4 = __pyx_v_loc1->size; - for (__pyx_v_i = 1; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":652 - * elif offset_by_one: - * for i from 1 <= i < loc1.size: - * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i-1]: # <<<<<<<<<<<<<< - * return 1 - * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i-1]: - */ - __pyx_t_3 = ((__pyx_v_loc1->arr[(__pyx_v_loc1->start + __pyx_v_i)]) > (__pyx_v_loc2->arr[((__pyx_v_loc2->start + __pyx_v_i) - 1)])); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":653 - * for i from 1 <= i < loc1.size: - * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i-1]: - * return 1 # <<<<<<<<<<<<<< - * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i-1]: - * return -1 - */ - __pyx_r = 1; - goto __pyx_L0; - goto __pyx_L9; - } - __pyx_L9:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":654 - * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i-1]: - * return 1 - * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i-1]: # <<<<<<<<<<<<<< - * return -1 - * - */ - __pyx_t_3 = ((__pyx_v_loc1->arr[(__pyx_v_loc1->start + __pyx_v_i)]) < (__pyx_v_loc2->arr[((__pyx_v_loc2->start + __pyx_v_i) - 1)])); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":655 - * return 1 - * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i-1]: - * return -1 # <<<<<<<<<<<<<< - * - * else: - */ - __pyx_r = -1; - goto __pyx_L0; - goto __pyx_L10; - } - __pyx_L10:; - } - goto __pyx_L5; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":658 - * - * else: - * if loc1.arr[loc1.start]+1 > loc2.arr[loc2.start]: # <<<<<<<<<<<<<< - * return 1 - * if loc1.arr[loc1.start]+1 < loc2.arr[loc2.start]: - */ - __pyx_t_3 = (((__pyx_v_loc1->arr[__pyx_v_loc1->start]) + 1) > (__pyx_v_loc2->arr[__pyx_v_loc2->start])); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":659 - * else: - * if loc1.arr[loc1.start]+1 > loc2.arr[loc2.start]: - * return 1 # <<<<<<<<<<<<<< - * if loc1.arr[loc1.start]+1 < loc2.arr[loc2.start]: - * return -1 - */ - __pyx_r = 1; - goto __pyx_L0; - goto __pyx_L11; - } - __pyx_L11:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":660 - * if loc1.arr[loc1.start]+1 > loc2.arr[loc2.start]: - * return 1 - * if loc1.arr[loc1.start]+1 < loc2.arr[loc2.start]: # <<<<<<<<<<<<<< - * return -1 - * - */ - __pyx_t_3 = (((__pyx_v_loc1->arr[__pyx_v_loc1->start]) + 1) < (__pyx_v_loc2->arr[__pyx_v_loc2->start])); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":661 - * return 1 - * if loc1.arr[loc1.start]+1 < loc2.arr[loc2.start]: - * return -1 # <<<<<<<<<<<<<< - * - * for i from 1 <= i < loc1.size: - */ - __pyx_r = -1; - goto __pyx_L0; - goto __pyx_L12; - } - __pyx_L12:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":663 - * return -1 - * - * for i from 1 <= i < loc1.size: # <<<<<<<<<<<<<< - * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i]: - * return 1 - */ - __pyx_t_4 = __pyx_v_loc1->size; - for (__pyx_v_i = 1; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":664 - * - * for i from 1 <= i < loc1.size: - * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i]: # <<<<<<<<<<<<<< - * return 1 - * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i]: - */ - __pyx_t_3 = ((__pyx_v_loc1->arr[(__pyx_v_loc1->start + __pyx_v_i)]) > (__pyx_v_loc2->arr[(__pyx_v_loc2->start + __pyx_v_i)])); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":665 - * for i from 1 <= i < loc1.size: - * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i]: - * return 1 # <<<<<<<<<<<<<< - * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i]: - * return -1 - */ - __pyx_r = 1; - goto __pyx_L0; - goto __pyx_L15; - } - __pyx_L15:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":666 - * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i]: - * return 1 - * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i]: # <<<<<<<<<<<<<< - * return -1 - * - */ - __pyx_t_3 = ((__pyx_v_loc1->arr[(__pyx_v_loc1->start + __pyx_v_i)]) < (__pyx_v_loc2->arr[(__pyx_v_loc2->start + __pyx_v_i)])); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":667 - * return 1 - * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i]: - * return -1 # <<<<<<<<<<<<<< - * - * if loc2.arr[loc2.end-1] + len_last - loc1.arr[loc1.start] > self.train_max_initial_size: - */ - __pyx_r = -1; - goto __pyx_L0; - goto __pyx_L16; - } - __pyx_L16:; - } - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":669 - * return -1 - * - * if loc2.arr[loc2.end-1] + len_last - loc1.arr[loc1.start] > self.train_max_initial_size: # <<<<<<<<<<<<<< - * return -1 - * return 0 - */ - __pyx_t_3 = ((((__pyx_v_loc2->arr[(__pyx_v_loc2->end - 1)]) + __pyx_v_len_last) - (__pyx_v_loc1->arr[__pyx_v_loc1->start])) > __pyx_v_self->train_max_initial_size); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":670 - * - * if loc2.arr[loc2.end-1] + len_last - loc1.arr[loc1.start] > self.train_max_initial_size: - * return -1 # <<<<<<<<<<<<<< - * return 0 - * - */ - __pyx_r = -1; - goto __pyx_L0; - goto __pyx_L17; - } - __pyx_L17:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":671 - * if loc2.arr[loc2.end-1] + len_last - loc1.arr[loc1.start] > self.train_max_initial_size: - * return -1 - * return 0 # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = 0; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":674 - * - * - * cdef int* merge_helper(self, int low1, int high1, int* arr1, int step1, # <<<<<<<<<<<<<< - * int low2, int high2, int* arr2, int step2, - * int offset_by_one, int len_last, int num_subpatterns, int* result_len): - */ - -static int *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_merge_helper(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, int __pyx_v_low1, int __pyx_v_high1, int *__pyx_v_arr1, int __pyx_v_step1, int __pyx_v_low2, int __pyx_v_high2, int *__pyx_v_arr2, int __pyx_v_step2, int __pyx_v_offset_by_one, int __pyx_v_len_last, int __pyx_v_num_subpatterns, int *__pyx_v_result_len) { - int __pyx_v_i1; - int __pyx_v_i2; - int __pyx_v_j1; - int __pyx_v_j2; - long __pyx_v_comparison; - int *__pyx_v_result; - struct __pyx_t_8_cdec_sa_Matching __pyx_v_loc1; - struct __pyx_t_8_cdec_sa_Matching __pyx_v_loc2; - int *__pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - __Pyx_RefNannySetupContext("merge_helper", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":682 - * cdef Matching loc1, loc2 - * - * result_len[0] = 0 # <<<<<<<<<<<<<< - * result = malloc(0*sizeof(int)) - * - */ - (__pyx_v_result_len[0]) = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":683 - * - * result_len[0] = 0 - * result = malloc(0*sizeof(int)) # <<<<<<<<<<<<<< - * - * i1 = low1 - */ - __pyx_v_result = ((int *)malloc((0 * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":685 - * result = malloc(0*sizeof(int)) - * - * i1 = low1 # <<<<<<<<<<<<<< - * i2 = low2 - * while i1 < high1 and i2 < high2: - */ - __pyx_v_i1 = __pyx_v_low1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":686 - * - * i1 = low1 - * i2 = low2 # <<<<<<<<<<<<<< - * while i1 < high1 and i2 < high2: - * - */ - __pyx_v_i2 = __pyx_v_low2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":687 - * i1 = low1 - * i2 = low2 - * while i1 < high1 and i2 < high2: # <<<<<<<<<<<<<< - * - * # First, pop all unneeded loc2's off the stack - */ - while (1) { - __pyx_t_1 = (__pyx_v_i1 < __pyx_v_high1); - if (__pyx_t_1) { - __pyx_t_2 = (__pyx_v_i2 < __pyx_v_high2); - __pyx_t_3 = __pyx_t_2; - } else { - __pyx_t_3 = __pyx_t_1; - } - if (!__pyx_t_3) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":690 - * - * # First, pop all unneeded loc2's off the stack - * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) # <<<<<<<<<<<<<< - * while i2 < high2: - * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) - */ - __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc1), __pyx_v_arr1, __pyx_v_i1, __pyx_v_step1, __pyx_v_self->fda->sent_id->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":691 - * # First, pop all unneeded loc2's off the stack - * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) - * while i2 < high2: # <<<<<<<<<<<<<< - * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) - * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: - */ - while (1) { - __pyx_t_3 = (__pyx_v_i2 < __pyx_v_high2); - if (!__pyx_t_3) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":692 - * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) - * while i2 < high2: - * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< - * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: - * i2 = i2 + step2 - */ - __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, __pyx_v_i2, __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":693 - * while i2 < high2: - * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) - * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: # <<<<<<<<<<<<<< - * i2 = i2 + step2 - * else: - */ - __pyx_t_3 = (((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last) == 1); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":694 - * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) - * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: - * i2 = i2 + step2 # <<<<<<<<<<<<<< - * else: - * break - */ - __pyx_v_i2 = (__pyx_v_i2 + __pyx_v_step2); - goto __pyx_L7; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":696 - * i2 = i2 + step2 - * else: - * break # <<<<<<<<<<<<<< - * - * # Next: process all loc1's with the same starting val - */ - goto __pyx_L6_break; - } - __pyx_L7:; - } - __pyx_L6_break:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":699 - * - * # Next: process all loc1's with the same starting val - * j1 = i1 # <<<<<<<<<<<<<< - * while i1 < high1 and arr1[j1] == arr1[i1]: - * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) - */ - __pyx_v_j1 = __pyx_v_i1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":700 - * # Next: process all loc1's with the same starting val - * j1 = i1 - * while i1 < high1 and arr1[j1] == arr1[i1]: # <<<<<<<<<<<<<< - * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) - * j2 = i2 - */ - while (1) { - __pyx_t_3 = (__pyx_v_i1 < __pyx_v_high1); - if (__pyx_t_3) { - __pyx_t_1 = ((__pyx_v_arr1[__pyx_v_j1]) == (__pyx_v_arr1[__pyx_v_i1])); - __pyx_t_2 = __pyx_t_1; - } else { - __pyx_t_2 = __pyx_t_3; - } - if (!__pyx_t_2) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":701 - * j1 = i1 - * while i1 < high1 and arr1[j1] == arr1[i1]: - * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) # <<<<<<<<<<<<<< - * j2 = i2 - * while j2 < high2: - */ - __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc1), __pyx_v_arr1, __pyx_v_i1, __pyx_v_step1, __pyx_v_self->fda->sent_id->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":702 - * while i1 < high1 and arr1[j1] == arr1[i1]: - * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) - * j2 = i2 # <<<<<<<<<<<<<< - * while j2 < high2: - * assign_matching(&loc2, arr2, j2, step2, self.fda.sent_id.arr) - */ - __pyx_v_j2 = __pyx_v_i2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":703 - * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) - * j2 = i2 - * while j2 < high2: # <<<<<<<<<<<<<< - * assign_matching(&loc2, arr2, j2, step2, self.fda.sent_id.arr) - * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) - */ - while (1) { - __pyx_t_2 = (__pyx_v_j2 < __pyx_v_high2); - if (!__pyx_t_2) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":704 - * j2 = i2 - * while j2 < high2: - * assign_matching(&loc2, arr2, j2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< - * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) - * if comparison == 0: - */ - __pyx_f_8_cdec_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, __pyx_v_j2, __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":705 - * while j2 < high2: - * assign_matching(&loc2, arr2, j2, step2, self.fda.sent_id.arr) - * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) # <<<<<<<<<<<<<< - * if comparison == 0: - * result = append_combined_matching(result, &loc1, &loc2, offset_by_one, num_subpatterns, result_len) - */ - __pyx_v_comparison = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":706 - * assign_matching(&loc2, arr2, j2, step2, self.fda.sent_id.arr) - * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) - * if comparison == 0: # <<<<<<<<<<<<<< - * result = append_combined_matching(result, &loc1, &loc2, offset_by_one, num_subpatterns, result_len) - * if comparison == 1: - */ - __pyx_t_2 = (__pyx_v_comparison == 0); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":707 - * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) - * if comparison == 0: - * result = append_combined_matching(result, &loc1, &loc2, offset_by_one, num_subpatterns, result_len) # <<<<<<<<<<<<<< - * if comparison == 1: - * pass - */ - __pyx_v_result = __pyx_f_8_cdec_sa_append_combined_matching(__pyx_v_result, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_num_subpatterns, __pyx_v_result_len); - goto __pyx_L12; - } - __pyx_L12:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":708 - * if comparison == 0: - * result = append_combined_matching(result, &loc1, &loc2, offset_by_one, num_subpatterns, result_len) - * if comparison == 1: # <<<<<<<<<<<<<< - * pass - * if comparison == -1: - */ - __pyx_t_2 = (__pyx_v_comparison == 1); - if (__pyx_t_2) { - goto __pyx_L13; - } - __pyx_L13:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":710 - * if comparison == 1: - * pass - * if comparison == -1: # <<<<<<<<<<<<<< - * break - * else: - */ - __pyx_t_2 = (__pyx_v_comparison == -1); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":711 - * pass - * if comparison == -1: - * break # <<<<<<<<<<<<<< - * else: - * j2 = j2 + step2 - */ - goto __pyx_L11_break; - goto __pyx_L14; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":713 - * break - * else: - * j2 = j2 + step2 # <<<<<<<<<<<<<< - * i1 = i1 + step1 - * return result - */ - __pyx_v_j2 = (__pyx_v_j2 + __pyx_v_step2); - } - __pyx_L14:; - } - __pyx_L11_break:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":714 - * else: - * j2 = j2 + step2 - * i1 = i1 + step1 # <<<<<<<<<<<<<< - * return result - * - */ - __pyx_v_i1 = (__pyx_v_i1 + __pyx_v_step1); - } - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":715 - * j2 = j2 + step2 - * i1 = i1 + step1 - * return result # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = __pyx_v_result; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":718 - * - * - * cdef void sort_phrase_loc(self, IntList arr, PhraseLocation loc, Phrase phrase): # <<<<<<<<<<<<<< - * cdef int i, j - * cdef VEB veb - */ - -static void __pyx_f_8_cdec_sa_23HieroCachingRuleFactory_sort_phrase_loc(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_arr, struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_loc, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_phrase) { - int __pyx_v_i; - int __pyx_v_j; - struct __pyx_obj_8_cdec_sa_VEB *__pyx_v_veb = 0; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("sort_phrase_loc", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":723 - * cdef IntList result - * - * if phrase in self.precomputed_index: # <<<<<<<<<<<<<< - * loc.arr = self.precomputed_index[phrase] - * else: - */ - __pyx_t_1 = ((PySequence_Contains(__pyx_v_self->precomputed_index, ((PyObject *)__pyx_v_phrase)))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_1) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":724 - * - * if phrase in self.precomputed_index: - * loc.arr = self.precomputed_index[phrase] # <<<<<<<<<<<<<< - * else: - * loc.arr = IntList(initial_len=loc.sa_high-loc.sa_low) - */ - __pyx_t_2 = PyObject_GetItem(__pyx_v_self->precomputed_index, ((PyObject *)__pyx_v_phrase)); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_8_cdec_sa_IntList))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_GOTREF(__pyx_v_loc->arr); - __Pyx_DECREF(((PyObject *)__pyx_v_loc->arr)); - __pyx_v_loc->arr = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_2); - __pyx_t_2 = 0; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":726 - * loc.arr = self.precomputed_index[phrase] - * else: - * loc.arr = IntList(initial_len=loc.sa_high-loc.sa_low) # <<<<<<<<<<<<<< - * veb = VEB(arr.len) - * for i from loc.sa_low <= i < loc.sa_high: - */ - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_t_3 = PyInt_FromLong((__pyx_v_loc->sa_high - __pyx_v_loc->sa_low)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_GIVEREF(__pyx_t_3); - __Pyx_GOTREF(__pyx_v_loc->arr); - __Pyx_DECREF(((PyObject *)__pyx_v_loc->arr)); - __pyx_v_loc->arr = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":727 - * else: - * loc.arr = IntList(initial_len=loc.sa_high-loc.sa_low) - * veb = VEB(arr.len) # <<<<<<<<<<<<<< - * for i from loc.sa_low <= i < loc.sa_high: - * veb._insert(arr.arr[i]) - */ - __pyx_t_3 = PyInt_FromLong(__pyx_v_arr->len); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_VEB)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_v_veb = ((struct __pyx_obj_8_cdec_sa_VEB *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":728 - * loc.arr = IntList(initial_len=loc.sa_high-loc.sa_low) - * veb = VEB(arr.len) - * for i from loc.sa_low <= i < loc.sa_high: # <<<<<<<<<<<<<< - * veb._insert(arr.arr[i]) - * i = veb.veb.min_val - */ - __pyx_t_4 = __pyx_v_loc->sa_high; - for (__pyx_v_i = __pyx_v_loc->sa_low; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":729 - * veb = VEB(arr.len) - * for i from loc.sa_low <= i < loc.sa_high: - * veb._insert(arr.arr[i]) # <<<<<<<<<<<<<< - * i = veb.veb.min_val - * for j from 0 <= j < loc.sa_high-loc.sa_low: - */ - ((struct __pyx_vtabstruct_8_cdec_sa_VEB *)__pyx_v_veb->__pyx_vtab)->_insert(__pyx_v_veb, (__pyx_v_arr->arr[__pyx_v_i])); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":730 - * for i from loc.sa_low <= i < loc.sa_high: - * veb._insert(arr.arr[i]) - * i = veb.veb.min_val # <<<<<<<<<<<<<< - * for j from 0 <= j < loc.sa_high-loc.sa_low: - * loc.arr.arr[j] = i - */ - __pyx_v_i = __pyx_v_veb->veb->min_val; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":731 - * veb._insert(arr.arr[i]) - * i = veb.veb.min_val - * for j from 0 <= j < loc.sa_high-loc.sa_low: # <<<<<<<<<<<<<< - * loc.arr.arr[j] = i - * i = veb._findsucc(i) - */ - __pyx_t_4 = (__pyx_v_loc->sa_high - __pyx_v_loc->sa_low); - for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_4; __pyx_v_j++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":732 - * i = veb.veb.min_val - * for j from 0 <= j < loc.sa_high-loc.sa_low: - * loc.arr.arr[j] = i # <<<<<<<<<<<<<< - * i = veb._findsucc(i) - * loc.arr_low = 0 - */ - (__pyx_v_loc->arr->arr[__pyx_v_j]) = __pyx_v_i; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":733 - * for j from 0 <= j < loc.sa_high-loc.sa_low: - * loc.arr.arr[j] = i - * i = veb._findsucc(i) # <<<<<<<<<<<<<< - * loc.arr_low = 0 - * loc.arr_high = loc.arr.len - */ - __pyx_v_i = ((struct __pyx_vtabstruct_8_cdec_sa_VEB *)__pyx_v_veb->__pyx_vtab)->_findsucc(__pyx_v_veb, __pyx_v_i); - } - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":734 - * loc.arr.arr[j] = i - * i = veb._findsucc(i) - * loc.arr_low = 0 # <<<<<<<<<<<<<< - * loc.arr_high = loc.arr.len - * - */ - __pyx_v_loc->arr_low = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":735 - * i = veb._findsucc(i) - * loc.arr_low = 0 - * loc.arr_high = loc.arr.len # <<<<<<<<<<<<<< - * - * - */ - __pyx_v_loc->arr_high = __pyx_v_loc->arr->len; - - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_WriteUnraisable("_cdec_sa.HieroCachingRuleFactory.sort_phrase_loc", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_veb); - __Pyx_RefNannyFinishContext(); -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":738 - * - * - * cdef intersect_helper(self, Phrase prefix, Phrase suffix, # <<<<<<<<<<<<<< - * PhraseLocation prefix_loc, PhraseLocation suffix_loc, int algorithm): - * - */ - -static PyObject *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_intersect_helper(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_prefix, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_suffix, struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_prefix_loc, struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_suffix_loc, int __pyx_v_algorithm) { - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_arr1 = 0; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_arr2 = 0; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_result = 0; - int __pyx_v_low1; - int __pyx_v_high1; - int __pyx_v_step1; - int __pyx_v_low2; - int __pyx_v_high2; - int __pyx_v_step2; - int __pyx_v_offset_by_one; - int __pyx_v_len_last; - int __pyx_v_num_subpatterns; - int __pyx_v_result_len; - int *__pyx_v_result_ptr; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - Py_ssize_t __pyx_t_5; - int __pyx_t_6; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("intersect_helper", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":745 - * cdef int* result_ptr - * - * result_len = 0 # <<<<<<<<<<<<<< - * - * if sym_isvar(suffix[0]): - */ - __pyx_v_result_len = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":747 - * result_len = 0 - * - * if sym_isvar(suffix[0]): # <<<<<<<<<<<<<< - * offset_by_one = 1 - * else: - */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_isvar); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_suffix), 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":748 - * - * if sym_isvar(suffix[0]): - * offset_by_one = 1 # <<<<<<<<<<<<<< - * else: - * offset_by_one = 0 - */ - __pyx_v_offset_by_one = 1; - goto __pyx_L3; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":750 - * offset_by_one = 1 - * else: - * offset_by_one = 0 # <<<<<<<<<<<<<< - * - * len_last = len(suffix.getchunk(suffix.arity())) - */ - __pyx_v_offset_by_one = 0; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":752 - * offset_by_one = 0 - * - * len_last = len(suffix.getchunk(suffix.arity())) # <<<<<<<<<<<<<< - * - * if prefix_loc.arr is None: - */ - __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_suffix), __pyx_n_s__getchunk); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_suffix), __pyx_n_s__arity); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_5 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_len_last = __pyx_t_5; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":754 - * len_last = len(suffix.getchunk(suffix.arity())) - * - * if prefix_loc.arr is None: # <<<<<<<<<<<<<< - * self.sort_phrase_loc(self.fsa.sa, prefix_loc, prefix) - * arr1 = prefix_loc.arr - */ - __pyx_t_4 = (((PyObject *)__pyx_v_prefix_loc->arr) == Py_None); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":755 - * - * if prefix_loc.arr is None: - * self.sort_phrase_loc(self.fsa.sa, prefix_loc, prefix) # <<<<<<<<<<<<<< - * arr1 = prefix_loc.arr - * low1 = prefix_loc.arr_low - */ - __pyx_t_1 = ((PyObject *)__pyx_v_self->fsa->sa); - __Pyx_INCREF(__pyx_t_1); - ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->sort_phrase_loc(__pyx_v_self, ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1), __pyx_v_prefix_loc, __pyx_v_prefix); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":756 - * if prefix_loc.arr is None: - * self.sort_phrase_loc(self.fsa.sa, prefix_loc, prefix) - * arr1 = prefix_loc.arr # <<<<<<<<<<<<<< - * low1 = prefix_loc.arr_low - * high1 = prefix_loc.arr_high - */ - __Pyx_INCREF(((PyObject *)__pyx_v_prefix_loc->arr)); - __pyx_v_arr1 = __pyx_v_prefix_loc->arr; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":757 - * self.sort_phrase_loc(self.fsa.sa, prefix_loc, prefix) - * arr1 = prefix_loc.arr - * low1 = prefix_loc.arr_low # <<<<<<<<<<<<<< - * high1 = prefix_loc.arr_high - * step1 = prefix_loc.num_subpatterns - */ - __pyx_v_low1 = __pyx_v_prefix_loc->arr_low; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":758 - * arr1 = prefix_loc.arr - * low1 = prefix_loc.arr_low - * high1 = prefix_loc.arr_high # <<<<<<<<<<<<<< - * step1 = prefix_loc.num_subpatterns - * - */ - __pyx_v_high1 = __pyx_v_prefix_loc->arr_high; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":759 - * low1 = prefix_loc.arr_low - * high1 = prefix_loc.arr_high - * step1 = prefix_loc.num_subpatterns # <<<<<<<<<<<<<< - * - * if suffix_loc.arr is None: - */ - __pyx_v_step1 = __pyx_v_prefix_loc->num_subpatterns; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":761 - * step1 = prefix_loc.num_subpatterns - * - * if suffix_loc.arr is None: # <<<<<<<<<<<<<< - * self.sort_phrase_loc(self.fsa.sa, suffix_loc, suffix) - * arr2 = suffix_loc.arr - */ - __pyx_t_4 = (((PyObject *)__pyx_v_suffix_loc->arr) == Py_None); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":762 - * - * if suffix_loc.arr is None: - * self.sort_phrase_loc(self.fsa.sa, suffix_loc, suffix) # <<<<<<<<<<<<<< - * arr2 = suffix_loc.arr - * low2 = suffix_loc.arr_low - */ - __pyx_t_1 = ((PyObject *)__pyx_v_self->fsa->sa); - __Pyx_INCREF(__pyx_t_1); - ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->sort_phrase_loc(__pyx_v_self, ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1), __pyx_v_suffix_loc, __pyx_v_suffix); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":763 - * if suffix_loc.arr is None: - * self.sort_phrase_loc(self.fsa.sa, suffix_loc, suffix) - * arr2 = suffix_loc.arr # <<<<<<<<<<<<<< - * low2 = suffix_loc.arr_low - * high2 = suffix_loc.arr_high - */ - __Pyx_INCREF(((PyObject *)__pyx_v_suffix_loc->arr)); - __pyx_v_arr2 = __pyx_v_suffix_loc->arr; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":764 - * self.sort_phrase_loc(self.fsa.sa, suffix_loc, suffix) - * arr2 = suffix_loc.arr - * low2 = suffix_loc.arr_low # <<<<<<<<<<<<<< - * high2 = suffix_loc.arr_high - * step2 = suffix_loc.num_subpatterns - */ - __pyx_v_low2 = __pyx_v_suffix_loc->arr_low; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":765 - * arr2 = suffix_loc.arr - * low2 = suffix_loc.arr_low - * high2 = suffix_loc.arr_high # <<<<<<<<<<<<<< - * step2 = suffix_loc.num_subpatterns - * - */ - __pyx_v_high2 = __pyx_v_suffix_loc->arr_high; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":766 - * low2 = suffix_loc.arr_low - * high2 = suffix_loc.arr_high - * step2 = suffix_loc.num_subpatterns # <<<<<<<<<<<<<< - * - * num_subpatterns = prefix.arity()+1 - */ - __pyx_v_step2 = __pyx_v_suffix_loc->num_subpatterns; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":768 - * step2 = suffix_loc.num_subpatterns - * - * num_subpatterns = prefix.arity()+1 # <<<<<<<<<<<<<< - * - * if algorithm == MERGE: - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_prefix), __pyx_n_s__arity); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Add(__pyx_t_3, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_num_subpatterns = __pyx_t_6; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":770 - * num_subpatterns = prefix.arity()+1 - * - * if algorithm == MERGE: # <<<<<<<<<<<<<< - * result_ptr = self.merge_helper(low1, high1, arr1.arr, step1, - * low2, high2, arr2.arr, step2, - */ - __pyx_t_4 = (__pyx_v_algorithm == __pyx_v_8_cdec_sa_MERGE); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":773 - * result_ptr = self.merge_helper(low1, high1, arr1.arr, step1, - * low2, high2, arr2.arr, step2, - * offset_by_one, len_last, num_subpatterns, &result_len) # <<<<<<<<<<<<<< - * else: - * result_ptr = self.baeza_yates_helper(low1, high1, arr1.arr, step1, - */ - __pyx_v_result_ptr = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->merge_helper(__pyx_v_self, __pyx_v_low1, __pyx_v_high1, __pyx_v_arr1->arr, __pyx_v_step1, __pyx_v_low2, __pyx_v_high2, __pyx_v_arr2->arr, __pyx_v_step2, __pyx_v_offset_by_one, __pyx_v_len_last, __pyx_v_num_subpatterns, (&__pyx_v_result_len)); - goto __pyx_L6; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":777 - * result_ptr = self.baeza_yates_helper(low1, high1, arr1.arr, step1, - * low2, high2, arr2.arr, step2, - * offset_by_one, len_last, num_subpatterns, &result_len) # <<<<<<<<<<<<<< - * - * if result_len == 0: - */ - __pyx_v_result_ptr = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->baeza_yates_helper(__pyx_v_self, __pyx_v_low1, __pyx_v_high1, __pyx_v_arr1->arr, __pyx_v_step1, __pyx_v_low2, __pyx_v_high2, __pyx_v_arr2->arr, __pyx_v_step2, __pyx_v_offset_by_one, __pyx_v_len_last, __pyx_v_num_subpatterns, (&__pyx_v_result_len)); - } - __pyx_L6:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":779 - * offset_by_one, len_last, num_subpatterns, &result_len) - * - * if result_len == 0: # <<<<<<<<<<<<<< - * free(result_ptr) - * return None - */ - __pyx_t_4 = (__pyx_v_result_len == 0); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":780 - * - * if result_len == 0: - * free(result_ptr) # <<<<<<<<<<<<<< - * return None - * else: - */ - free(__pyx_v_result_ptr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":781 - * if result_len == 0: - * free(result_ptr) - * return None # <<<<<<<<<<<<<< - * else: - * result = IntList() - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(Py_None); - __pyx_r = Py_None; - goto __pyx_L0; - goto __pyx_L7; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":783 - * return None - * else: - * result = IntList() # <<<<<<<<<<<<<< - * free(result.arr) - * result.arr = result_ptr - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_result = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":784 - * else: - * result = IntList() - * free(result.arr) # <<<<<<<<<<<<<< - * result.arr = result_ptr - * result.len = result_len - */ - free(__pyx_v_result->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":785 - * result = IntList() - * free(result.arr) - * result.arr = result_ptr # <<<<<<<<<<<<<< - * result.len = result_len - * result.size = result_len - */ - __pyx_v_result->arr = __pyx_v_result_ptr; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":786 - * free(result.arr) - * result.arr = result_ptr - * result.len = result_len # <<<<<<<<<<<<<< - * result.size = result_len - * return PhraseLocation(arr_low=0, arr_high=result_len, arr=result, num_subpatterns=num_subpatterns) - */ - __pyx_v_result->len = __pyx_v_result_len; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":787 - * result.arr = result_ptr - * result.len = result_len - * result.size = result_len # <<<<<<<<<<<<<< - * return PhraseLocation(arr_low=0, arr_high=result_len, arr=result, num_subpatterns=num_subpatterns) - * - */ - __pyx_v_result->size = __pyx_v_result_len; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":788 - * result.len = result_len - * result.size = result_len - * return PhraseLocation(arr_low=0, arr_high=result_len, arr=result, num_subpatterns=num_subpatterns) # <<<<<<<<<<<<<< - * - * cdef loc2str(self, PhraseLocation loc): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__arr_low), __pyx_int_0) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = PyInt_FromLong(__pyx_v_result_len); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__arr_high), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__arr), ((PyObject *)__pyx_v_result)) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = PyInt_FromLong(__pyx_v_num_subpatterns); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__num_subpatterns), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_PhraseLocation)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - } - __pyx_L7:; - - __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_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.intersect_helper", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_arr1); - __Pyx_XDECREF((PyObject *)__pyx_v_arr2); - __Pyx_XDECREF((PyObject *)__pyx_v_result); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":790 - * return PhraseLocation(arr_low=0, arr_high=result_len, arr=result, num_subpatterns=num_subpatterns) - * - * cdef loc2str(self, PhraseLocation loc): # <<<<<<<<<<<<<< - * cdef int i, j - * result = "{" - */ - -static PyObject *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_loc2str(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_loc) { - int __pyx_v_i; - int __pyx_v_j; - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("loc2str", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":792 - * cdef loc2str(self, PhraseLocation loc): - * cdef int i, j - * result = "{" # <<<<<<<<<<<<<< - * i = 0 - * while i < loc.arr_high: - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_114)); - __pyx_v_result = ((PyObject *)__pyx_kp_s_114); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":793 - * cdef int i, j - * result = "{" - * i = 0 # <<<<<<<<<<<<<< - * while i < loc.arr_high: - * result = result + "(" - */ - __pyx_v_i = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":794 - * result = "{" - * i = 0 - * while i < loc.arr_high: # <<<<<<<<<<<<<< - * result = result + "(" - * for j from i <= j < i + loc.num_subpatterns: - */ - while (1) { - __pyx_t_1 = (__pyx_v_i < __pyx_v_loc->arr_high); - if (!__pyx_t_1) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":795 - * i = 0 - * while i < loc.arr_high: - * result = result + "(" # <<<<<<<<<<<<<< - * for j from i <= j < i + loc.num_subpatterns: - * result = result + ("%d " %loc.arr[j]) - */ - __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_kp_s_115)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_v_result); - __pyx_v_result = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":796 - * while i < loc.arr_high: - * result = result + "(" - * for j from i <= j < i + loc.num_subpatterns: # <<<<<<<<<<<<<< - * result = result + ("%d " %loc.arr[j]) - * result = result + ")" - */ - __pyx_t_3 = (__pyx_v_i + __pyx_v_loc->num_subpatterns); - for (__pyx_v_j = __pyx_v_i; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":797 - * result = result + "(" - * for j from i <= j < i + loc.num_subpatterns: - * result = result + ("%d " %loc.arr[j]) # <<<<<<<<<<<<<< - * result = result + ")" - * i = i + loc.num_subpatterns - */ - __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_loc->arr), __pyx_v_j, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_v_result); - __pyx_v_result = __pyx_t_2; - __pyx_t_2 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":798 - * for j from i <= j < i + loc.num_subpatterns: - * result = result + ("%d " %loc.arr[j]) - * result = result + ")" # <<<<<<<<<<<<<< - * i = i + loc.num_subpatterns - * result = result + "}" - */ - __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_kp_s_56)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_v_result); - __pyx_v_result = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":799 - * result = result + ("%d " %loc.arr[j]) - * result = result + ")" - * i = i + loc.num_subpatterns # <<<<<<<<<<<<<< - * result = result + "}" - * return result - */ - __pyx_v_i = (__pyx_v_i + __pyx_v_loc->num_subpatterns); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":800 - * result = result + ")" - * i = i + loc.num_subpatterns - * result = result + "}" # <<<<<<<<<<<<<< - * return result - * - */ - __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_kp_s_116)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_v_result); - __pyx_v_result = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":801 - * i = i + loc.num_subpatterns - * result = result + "}" - * return result # <<<<<<<<<<<<<< - * - * cdef PhraseLocation intersect(self, prefix_node, suffix_node, Phrase phrase): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_result); - __pyx_r = __pyx_v_result; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.loc2str", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":803 - * return result - * - * cdef PhraseLocation intersect(self, prefix_node, suffix_node, Phrase phrase): # <<<<<<<<<<<<<< - * cdef Phrase prefix, suffix - * cdef PhraseLocation prefix_loc, suffix_loc, result - */ - -static struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_intersect(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_prefix_node, PyObject *__pyx_v_suffix_node, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_phrase) { - struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_prefix = 0; - struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_suffix = 0; - struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_prefix_loc = 0; - struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_suffix_loc = 0; - struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_v_result = 0; - CYTHON_UNUSED PyObject *__pyx_v_intersect_method = NULL; - struct __pyx_obj_8_cdec_sa_PhraseLocation *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("intersect", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":807 - * cdef PhraseLocation prefix_loc, suffix_loc, result - * - * prefix = prefix_node.phrase # <<<<<<<<<<<<<< - * suffix = suffix_node.phrase - * prefix_loc = prefix_node.phrase_location - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_prefix_node, __pyx_n_s__phrase); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 807; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8_cdec_sa_Phrase))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 807; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_prefix = ((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":808 - * - * prefix = prefix_node.phrase - * suffix = suffix_node.phrase # <<<<<<<<<<<<<< - * prefix_loc = prefix_node.phrase_location - * suffix_loc = suffix_node.phrase_location - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_suffix_node, __pyx_n_s__phrase); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8_cdec_sa_Phrase))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_suffix = ((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":809 - * prefix = prefix_node.phrase - * suffix = suffix_node.phrase - * prefix_loc = prefix_node.phrase_location # <<<<<<<<<<<<<< - * suffix_loc = suffix_node.phrase_location - * - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_prefix_node, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 809; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8_cdec_sa_PhraseLocation))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 809; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_prefix_loc = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":810 - * suffix = suffix_node.phrase - * prefix_loc = prefix_node.phrase_location - * suffix_loc = suffix_node.phrase_location # <<<<<<<<<<<<<< - * - * result = self.get_precomputed_collocation(phrase) - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_suffix_node, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 810; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8_cdec_sa_PhraseLocation))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 810; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_suffix_loc = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":812 - * suffix_loc = suffix_node.phrase_location - * - * result = self.get_precomputed_collocation(phrase) # <<<<<<<<<<<<<< - * if result is not None: - * intersect_method = "precomputed" - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s_117); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_v_phrase)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_phrase)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_phrase)); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_8_cdec_sa_PhraseLocation))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_result = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":813 - * - * result = self.get_precomputed_collocation(phrase) - * if result is not None: # <<<<<<<<<<<<<< - * intersect_method = "precomputed" - * - */ - __pyx_t_4 = (((PyObject *)__pyx_v_result) != Py_None); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":814 - * result = self.get_precomputed_collocation(phrase) - * if result is not None: - * intersect_method = "precomputed" # <<<<<<<<<<<<<< - * - * if result is None: - */ - __Pyx_INCREF(((PyObject *)__pyx_n_s__precomputed)); - __pyx_v_intersect_method = ((PyObject *)__pyx_n_s__precomputed); - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":816 - * intersect_method = "precomputed" - * - * if result is None: # <<<<<<<<<<<<<< - * if self.use_baeza_yates: - * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, BAEZA_YATES) - */ - __pyx_t_4 = (((PyObject *)__pyx_v_result) == Py_None); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":817 - * - * if result is None: - * if self.use_baeza_yates: # <<<<<<<<<<<<<< - * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, BAEZA_YATES) - * intersect_method="double binary" - */ - if (__pyx_v_self->use_baeza_yates) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":818 - * if result is None: - * if self.use_baeza_yates: - * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, BAEZA_YATES) # <<<<<<<<<<<<<< - * intersect_method="double binary" - * else: - */ - __pyx_t_3 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->intersect_helper(__pyx_v_self, __pyx_v_prefix, __pyx_v_suffix, __pyx_v_prefix_loc, __pyx_v_suffix_loc, __pyx_v_8_cdec_sa_BAEZA_YATES); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_8_cdec_sa_PhraseLocation))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_v_result)); - __pyx_v_result = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":819 - * if self.use_baeza_yates: - * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, BAEZA_YATES) - * intersect_method="double binary" # <<<<<<<<<<<<<< - * else: - * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, MERGE) - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_118)); - __Pyx_XDECREF(__pyx_v_intersect_method); - __pyx_v_intersect_method = ((PyObject *)__pyx_kp_s_118); - goto __pyx_L5; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":821 - * intersect_method="double binary" - * else: - * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, MERGE) # <<<<<<<<<<<<<< - * intersect_method="merge" - * return result - */ - __pyx_t_3 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->intersect_helper(__pyx_v_self, __pyx_v_prefix, __pyx_v_suffix, __pyx_v_prefix_loc, __pyx_v_suffix_loc, __pyx_v_8_cdec_sa_MERGE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_8_cdec_sa_PhraseLocation))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_v_result)); - __pyx_v_result = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":822 - * else: - * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, MERGE) - * intersect_method="merge" # <<<<<<<<<<<<<< - * return result - * - */ - __Pyx_INCREF(((PyObject *)__pyx_n_s__merge)); - __Pyx_XDECREF(__pyx_v_intersect_method); - __pyx_v_intersect_method = ((PyObject *)__pyx_n_s__merge); - } - __pyx_L5:; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":823 - * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, MERGE) - * intersect_method="merge" - * return result # <<<<<<<<<<<<<< - * - * def advance(self, frontier, res, fwords): - */ - __Pyx_XDECREF(((PyObject *)__pyx_r)); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - __pyx_r = __pyx_v_result; - goto __pyx_L0; - - __pyx_r = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)Py_None); __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.intersect", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_prefix); - __Pyx_XDECREF((PyObject *)__pyx_v_suffix); - __Pyx_XDECREF((PyObject *)__pyx_v_prefix_loc); - __Pyx_XDECREF((PyObject *)__pyx_v_suffix_loc); - __Pyx_XDECREF((PyObject *)__pyx_v_result); - __Pyx_XDECREF(__pyx_v_intersect_method); - __Pyx_XGIVEREF((PyObject *)__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_13advance(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_13advance(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_frontier = 0; - PyObject *__pyx_v_res = 0; - PyObject *__pyx_v_fwords = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__frontier,&__pyx_n_s__res,&__pyx_n_s__fwords,0}; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("advance (wrapper)", 0); - { - PyObject* values[3] = {0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__frontier); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__res); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("advance", 1, 3, 3, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fwords); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("advance", 1, 3, 3, 2); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "advance") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - } - __pyx_v_frontier = values[0]; - __pyx_v_res = values[1]; - __pyx_v_fwords = values[2]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("advance", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.advance", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_12advance(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_frontier, __pyx_v_res, __pyx_v_fwords); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":825 - * return result - * - * def advance(self, frontier, res, fwords): # <<<<<<<<<<<<<< - * cdef unsigned na - * nf = [] - */ - -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_12advance(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_frontier, PyObject *__pyx_v_res, PyObject *__pyx_v_fwords) { - unsigned int __pyx_v_na; - PyObject *__pyx_v_nf = NULL; - PyObject *__pyx_v_toskip = NULL; - PyObject *__pyx_v_i = NULL; - PyObject *__pyx_v_alt = NULL; - PyObject *__pyx_v_pathlen = NULL; - PyObject *__pyx_v_spanlen = NULL; - PyObject *__pyx_v_ni = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *(*__pyx_t_3)(PyObject *); - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *(*__pyx_t_8)(PyObject *); - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - int __pyx_t_12; - Py_ssize_t __pyx_t_13; - int __pyx_t_14; - int __pyx_t_15; - unsigned int __pyx_t_16; - int __pyx_t_17; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("advance", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":827 - * def advance(self, frontier, res, fwords): - * cdef unsigned na - * nf = [] # <<<<<<<<<<<<<< - * for (toskip, (i, alt, pathlen)) in frontier: - * spanlen = fwords[i][alt][2] - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_nf = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":828 - * cdef unsigned na - * nf = [] - * for (toskip, (i, alt, pathlen)) in frontier: # <<<<<<<<<<<<<< - * spanlen = fwords[i][alt][2] - * if (toskip == 0): - */ - if (PyList_CheckExact(__pyx_v_frontier) || PyTuple_CheckExact(__pyx_v_frontier)) { - __pyx_t_1 = __pyx_v_frontier; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; - __pyx_t_3 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_frontier); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; - } - for (;;) { - if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; - } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; - } else { - __pyx_t_4 = __pyx_t_3(__pyx_t_1); - if (unlikely(!__pyx_t_4)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) { - PyObject* sequence = __pyx_t_4; - if (likely(PyTuple_CheckExact(sequence))) { - 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[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_5 = PyList_GET_ITEM(sequence, 0); - __pyx_t_6 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; - index = 0; __pyx_t_5 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_5); - index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed; - __Pyx_GOTREF(__pyx_t_6); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L6_unpacking_done; - __pyx_L5_unpacking_failed:; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L6_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_toskip); - __pyx_v_toskip = __pyx_t_5; - __pyx_t_5 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) { - PyObject* sequence = __pyx_t_6; - if (likely(PyTuple_CheckExact(sequence))) { - if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { - if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); - } else { - if (unlikely(PyList_GET_SIZE(sequence) != 3)) { - if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_7 = PyList_GET_ITEM(sequence, 0); - __pyx_t_9 = PyList_GET_ITEM(sequence, 1); - __pyx_t_10 = PyList_GET_ITEM(sequence, 2); - } - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_11 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_8 = Py_TYPE(__pyx_t_11)->tp_iternext; - index = 0; __pyx_t_7 = __pyx_t_8(__pyx_t_11); if (unlikely(!__pyx_t_7)) goto __pyx_L7_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - index = 1; __pyx_t_9 = __pyx_t_8(__pyx_t_11); if (unlikely(!__pyx_t_9)) goto __pyx_L7_unpacking_failed; - __Pyx_GOTREF(__pyx_t_9); - index = 2; __pyx_t_10 = __pyx_t_8(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L7_unpacking_failed; - __Pyx_GOTREF(__pyx_t_10); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_11), 3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - goto __pyx_L8_unpacking_done; - __pyx_L7_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[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L8_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_i); - __pyx_v_i = __pyx_t_7; - __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_v_alt); - __pyx_v_alt = __pyx_t_9; - __pyx_t_9 = 0; - __Pyx_XDECREF(__pyx_v_pathlen); - __pyx_v_pathlen = __pyx_t_10; - __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":829 - * nf = [] - * for (toskip, (i, alt, pathlen)) in frontier: - * spanlen = fwords[i][alt][2] # <<<<<<<<<<<<<< - * if (toskip == 0): - * res.append((i, alt, pathlen)) - */ - __pyx_t_4 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_i); if (!__pyx_t_4) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = PyObject_GetItem(__pyx_t_4, __pyx_v_alt); if (!__pyx_t_6) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_6, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_v_spanlen); - __pyx_v_spanlen = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":830 - * for (toskip, (i, alt, pathlen)) in frontier: - * spanlen = fwords[i][alt][2] - * if (toskip == 0): # <<<<<<<<<<<<<< - * res.append((i, alt, pathlen)) - * ni = i + spanlen - */ - __pyx_t_4 = PyObject_RichCompare(__pyx_v_toskip, __pyx_int_0, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_12) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":831 - * spanlen = fwords[i][alt][2] - * if (toskip == 0): - * res.append((i, alt, pathlen)) # <<<<<<<<<<<<<< - * ni = i + spanlen - * if (ni < len(fwords) and (pathlen + 1) < self.max_initial_size): - */ - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_i); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_i); - __Pyx_GIVEREF(__pyx_v_i); - __Pyx_INCREF(__pyx_v_alt); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_alt); - __Pyx_GIVEREF(__pyx_v_alt); - __Pyx_INCREF(__pyx_v_pathlen); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_pathlen); - __Pyx_GIVEREF(__pyx_v_pathlen); - __pyx_t_6 = __Pyx_PyObject_Append(__pyx_v_res, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - goto __pyx_L9; - } - __pyx_L9:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":832 - * if (toskip == 0): - * res.append((i, alt, pathlen)) - * ni = i + spanlen # <<<<<<<<<<<<<< - * if (ni < len(fwords) and (pathlen + 1) < self.max_initial_size): - * for na in range(len(fwords[ni])): - */ - __pyx_t_6 = PyNumber_Add(__pyx_v_i, __pyx_v_spanlen); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_v_ni); - __pyx_v_ni = __pyx_t_6; - __pyx_t_6 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":833 - * res.append((i, alt, pathlen)) - * ni = i + spanlen - * if (ni < len(fwords) and (pathlen + 1) < self.max_initial_size): # <<<<<<<<<<<<<< - * for na in range(len(fwords[ni])): - * nf.append((toskip - 1, (ni, na, pathlen + 1))) - */ - __pyx_t_13 = PyObject_Length(__pyx_v_fwords); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_6 = PyInt_FromSsize_t(__pyx_t_13); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_4 = PyObject_RichCompare(__pyx_v_ni, __pyx_t_6, Py_LT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_12) { - __pyx_t_4 = PyNumber_Add(__pyx_v_pathlen, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_6 = PyInt_FromLong(__pyx_v_self->max_initial_size); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_t_6, Py_LT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_15 = __pyx_t_14; - } else { - __pyx_t_15 = __pyx_t_12; - } - if (__pyx_t_15) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":834 - * ni = i + spanlen - * if (ni < len(fwords) and (pathlen + 1) < self.max_initial_size): - * for na in range(len(fwords[ni])): # <<<<<<<<<<<<<< - * nf.append((toskip - 1, (ni, na, pathlen + 1))) - * if (len(nf) > 0): - */ - __pyx_t_5 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ni); if (!__pyx_t_5) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_13 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_13; __pyx_t_16+=1) { - __pyx_v_na = __pyx_t_16; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":835 - * if (ni < len(fwords) and (pathlen + 1) < self.max_initial_size): - * for na in range(len(fwords[ni])): - * nf.append((toskip - 1, (ni, na, pathlen + 1))) # <<<<<<<<<<<<<< - * if (len(nf) > 0): - * return self.advance(nf, res, fwords) - */ - __pyx_t_5 = PyNumber_Subtract(__pyx_v_toskip, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PyLong_FromUnsignedLong(__pyx_v_na); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_4 = PyNumber_Add(__pyx_v_pathlen, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_v_ni); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_ni); - __Pyx_GIVEREF(__pyx_v_ni); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_6 = 0; - __pyx_t_4 = 0; - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_t_10)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); - __pyx_t_5 = 0; - __pyx_t_10 = 0; - __pyx_t_17 = PyList_Append(__pyx_v_nf, ((PyObject *)__pyx_t_4)); if (unlikely(__pyx_t_17 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - } - goto __pyx_L10; - } - __pyx_L10:; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":836 - * for na in range(len(fwords[ni])): - * nf.append((toskip - 1, (ni, na, pathlen + 1))) - * if (len(nf) > 0): # <<<<<<<<<<<<<< - * return self.advance(nf, res, fwords) - * else: - */ - __pyx_t_2 = PyList_GET_SIZE(((PyObject *)__pyx_v_nf)); - __pyx_t_15 = (__pyx_t_2 > 0); - if (__pyx_t_15) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":837 - * nf.append((toskip - 1, (ni, na, pathlen + 1))) - * if (len(nf) > 0): - * return self.advance(nf, res, fwords) # <<<<<<<<<<<<<< - * else: - * return res - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__advance); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(((PyObject *)__pyx_v_nf)); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_nf)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_nf)); - __Pyx_INCREF(__pyx_v_res); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_res); - __Pyx_GIVEREF(__pyx_v_res); - __Pyx_INCREF(__pyx_v_fwords); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_fwords); - __Pyx_GIVEREF(__pyx_v_fwords); - __pyx_t_10 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __pyx_r = __pyx_t_10; - __pyx_t_10 = 0; - goto __pyx_L0; - goto __pyx_L13; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":839 - * return self.advance(nf, res, fwords) - * else: - * return res # <<<<<<<<<<<<<< - * - * def get_all_nodes_isteps_away(self, skip, i, spanlen, pathlen, fwords, next_states, reachable_buffer): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_res); - __pyx_r = __pyx_v_res; - goto __pyx_L0; - } - __pyx_L13:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.advance", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_nf); - __Pyx_XDECREF(__pyx_v_toskip); - __Pyx_XDECREF(__pyx_v_i); - __Pyx_XDECREF(__pyx_v_alt); - __Pyx_XDECREF(__pyx_v_pathlen); - __Pyx_XDECREF(__pyx_v_spanlen); - __Pyx_XDECREF(__pyx_v_ni); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_15get_all_nodes_isteps_away(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_15get_all_nodes_isteps_away(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_skip = 0; - PyObject *__pyx_v_i = 0; - PyObject *__pyx_v_spanlen = 0; - PyObject *__pyx_v_pathlen = 0; - PyObject *__pyx_v_fwords = 0; - PyObject *__pyx_v_next_states = 0; - PyObject *__pyx_v_reachable_buffer = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__skip,&__pyx_n_s__i,&__pyx_n_s__spanlen,&__pyx_n_s__pathlen,&__pyx_n_s__fwords,&__pyx_n_s__next_states,&__pyx_n_s__reachable_buffer,0}; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_all_nodes_isteps_away (wrapper)", 0); - { - PyObject* values[7] = {0,0,0,0,0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__skip); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__i); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__spanlen); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, 2); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 3: - values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pathlen); - if (likely(values[3])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, 3); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 4: - values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fwords); - if (likely(values[4])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, 4); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 5: - values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__next_states); - if (likely(values[5])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, 5); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 6: - values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reachable_buffer); - if (likely(values[6])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, 6); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_all_nodes_isteps_away") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 7) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - values[3] = PyTuple_GET_ITEM(__pyx_args, 3); - values[4] = PyTuple_GET_ITEM(__pyx_args, 4); - values[5] = PyTuple_GET_ITEM(__pyx_args, 5); - values[6] = PyTuple_GET_ITEM(__pyx_args, 6); - } - __pyx_v_skip = values[0]; - __pyx_v_i = values[1]; - __pyx_v_spanlen = values[2]; - __pyx_v_pathlen = values[3]; - __pyx_v_fwords = values[4]; - __pyx_v_next_states = values[5]; - __pyx_v_reachable_buffer = values[6]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.get_all_nodes_isteps_away", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_14get_all_nodes_isteps_away(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_skip, __pyx_v_i, __pyx_v_spanlen, __pyx_v_pathlen, __pyx_v_fwords, __pyx_v_next_states, __pyx_v_reachable_buffer); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":841 - * return res - * - * def get_all_nodes_isteps_away(self, skip, i, spanlen, pathlen, fwords, next_states, reachable_buffer): # <<<<<<<<<<<<<< - * cdef unsigned alt_it - * frontier = [] - */ - -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_14get_all_nodes_isteps_away(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_skip, PyObject *__pyx_v_i, PyObject *__pyx_v_spanlen, PyObject *__pyx_v_pathlen, PyObject *__pyx_v_fwords, PyObject *__pyx_v_next_states, PyObject *__pyx_v_reachable_buffer) { - PyObject *__pyx_v_frontier = NULL; - PyObject *__pyx_v_key = NULL; - PyObject *__pyx_v_reachable = NULL; - PyObject *__pyx_v_nextreachable = NULL; - PyObject *__pyx_v_next_id = NULL; - PyObject *__pyx_v_jump = NULL; - PyObject *__pyx_v_alt_id = NULL; - PyObject *__pyx_v_newel = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - Py_ssize_t __pyx_t_3; - PyObject *__pyx_t_4 = NULL; - int __pyx_t_5; - PyObject *(*__pyx_t_6)(PyObject *); - Py_ssize_t __pyx_t_7; - PyObject *(*__pyx_t_8)(PyObject *); - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - Py_ssize_t __pyx_t_11; - PyObject *(*__pyx_t_12)(PyObject *); - PyObject *__pyx_t_13 = NULL; - int __pyx_t_14; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get_all_nodes_isteps_away", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":843 - * def get_all_nodes_isteps_away(self, skip, i, spanlen, pathlen, fwords, next_states, reachable_buffer): - * cdef unsigned alt_it - * frontier = [] # <<<<<<<<<<<<<< - * if (i+spanlen+skip >= len(next_states)): - * return frontier - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 843; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_frontier = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":844 - * cdef unsigned alt_it - * frontier = [] - * if (i+spanlen+skip >= len(next_states)): # <<<<<<<<<<<<<< - * return frontier - * key = tuple([i,spanlen]) - */ - __pyx_t_1 = PyNumber_Add(__pyx_v_i, __pyx_v_spanlen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_v_skip); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_3 = PyObject_Length(__pyx_v_next_states); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_1, Py_GE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":845 - * frontier = [] - * if (i+spanlen+skip >= len(next_states)): - * return frontier # <<<<<<<<<<<<<< - * key = tuple([i,spanlen]) - * reachable = [] - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_frontier)); - __pyx_r = ((PyObject *)__pyx_v_frontier); - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":846 - * if (i+spanlen+skip >= len(next_states)): - * return frontier - * key = tuple([i,spanlen]) # <<<<<<<<<<<<<< - * reachable = [] - * if (key in reachable_buffer): - */ - __pyx_t_4 = PyList_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_i); - PyList_SET_ITEM(__pyx_t_4, 0, __pyx_v_i); - __Pyx_GIVEREF(__pyx_v_i); - __Pyx_INCREF(__pyx_v_spanlen); - PyList_SET_ITEM(__pyx_t_4, 1, __pyx_v_spanlen); - __Pyx_GIVEREF(__pyx_v_spanlen); - __pyx_t_1 = ((PyObject *)PyList_AsTuple(__pyx_t_4)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __pyx_v_key = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":847 - * return frontier - * key = tuple([i,spanlen]) - * reachable = [] # <<<<<<<<<<<<<< - * if (key in reachable_buffer): - * reachable = reachable_buffer[key] - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 847; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_reachable = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":848 - * key = tuple([i,spanlen]) - * reachable = [] - * if (key in reachable_buffer): # <<<<<<<<<<<<<< - * reachable = reachable_buffer[key] - * else: - */ - __pyx_t_5 = ((PySequence_Contains(__pyx_v_reachable_buffer, ((PyObject *)__pyx_v_key)))); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 848; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":849 - * reachable = [] - * if (key in reachable_buffer): - * reachable = reachable_buffer[key] # <<<<<<<<<<<<<< - * else: - * reachable = self.reachable(fwords, i, spanlen) - */ - __pyx_t_1 = PyObject_GetItem(__pyx_v_reachable_buffer, ((PyObject *)__pyx_v_key)); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_v_reachable); - __pyx_v_reachable = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L4; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":851 - * reachable = reachable_buffer[key] - * else: - * reachable = self.reachable(fwords, i, spanlen) # <<<<<<<<<<<<<< - * reachable_buffer[key] = reachable - * for nextreachable in reachable: - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__reachable); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 851; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 851; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(__pyx_v_fwords); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_fwords); - __Pyx_GIVEREF(__pyx_v_fwords); - __Pyx_INCREF(__pyx_v_i); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_i); - __Pyx_GIVEREF(__pyx_v_i); - __Pyx_INCREF(__pyx_v_spanlen); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_spanlen); - __Pyx_GIVEREF(__pyx_v_spanlen); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 851; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_v_reachable); - __pyx_v_reachable = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":852 - * else: - * reachable = self.reachable(fwords, i, spanlen) - * reachable_buffer[key] = reachable # <<<<<<<<<<<<<< - * for nextreachable in reachable: - * for next_id in next_states[nextreachable]: - */ - if (PyObject_SetItem(__pyx_v_reachable_buffer, ((PyObject *)__pyx_v_key), __pyx_v_reachable) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 852; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":853 - * reachable = self.reachable(fwords, i, spanlen) - * reachable_buffer[key] = reachable - * for nextreachable in reachable: # <<<<<<<<<<<<<< - * for next_id in next_states[nextreachable]: - * jump = self.shortest(fwords,i,next_id) - */ - if (PyList_CheckExact(__pyx_v_reachable) || PyTuple_CheckExact(__pyx_v_reachable)) { - __pyx_t_2 = __pyx_v_reachable; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; - __pyx_t_6 = NULL; - } else { - __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_reachable); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext; - } - for (;;) { - if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_2)) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; - } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_2)) { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; - } else { - __pyx_t_4 = __pyx_t_6(__pyx_t_2); - if (unlikely(!__pyx_t_4)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XDECREF(__pyx_v_nextreachable); - __pyx_v_nextreachable = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":854 - * reachable_buffer[key] = reachable - * for nextreachable in reachable: - * for next_id in next_states[nextreachable]: # <<<<<<<<<<<<<< - * jump = self.shortest(fwords,i,next_id) - * if jump < skip: - */ - __pyx_t_4 = PyObject_GetItem(__pyx_v_next_states, __pyx_v_nextreachable); if (!__pyx_t_4) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - if (PyList_CheckExact(__pyx_t_4) || PyTuple_CheckExact(__pyx_t_4)) { - __pyx_t_1 = __pyx_t_4; __Pyx_INCREF(__pyx_t_1); __pyx_t_7 = 0; - __pyx_t_8 = NULL; - } else { - __pyx_t_7 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = Py_TYPE(__pyx_t_1)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - for (;;) { - if (!__pyx_t_8 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; - } else if (!__pyx_t_8 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; - } else { - __pyx_t_4 = __pyx_t_8(__pyx_t_1); - if (unlikely(!__pyx_t_4)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XDECREF(__pyx_v_next_id); - __pyx_v_next_id = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":855 - * for nextreachable in reachable: - * for next_id in next_states[nextreachable]: - * jump = self.shortest(fwords,i,next_id) # <<<<<<<<<<<<<< - * if jump < skip: - * continue - */ - __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__shortest); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 855; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 855; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_INCREF(__pyx_v_fwords); - PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_fwords); - __Pyx_GIVEREF(__pyx_v_fwords); - __Pyx_INCREF(__pyx_v_i); - PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_i); - __Pyx_GIVEREF(__pyx_v_i); - __Pyx_INCREF(__pyx_v_next_id); - PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_v_next_id); - __Pyx_GIVEREF(__pyx_v_next_id); - __pyx_t_10 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 855; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; - __Pyx_XDECREF(__pyx_v_jump); - __pyx_v_jump = __pyx_t_10; - __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":856 - * for next_id in next_states[nextreachable]: - * jump = self.shortest(fwords,i,next_id) - * if jump < skip: # <<<<<<<<<<<<<< - * continue - * if pathlen+jump <= self.max_initial_size: - */ - __pyx_t_10 = PyObject_RichCompare(__pyx_v_jump, __pyx_v_skip, Py_LT); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 856; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 856; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":857 - * jump = self.shortest(fwords,i,next_id) - * if jump < skip: - * continue # <<<<<<<<<<<<<< - * if pathlen+jump <= self.max_initial_size: - * for alt_id in range(len(fwords[next_id])): - */ - goto __pyx_L7_continue; - goto __pyx_L9; - } - __pyx_L9:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":858 - * if jump < skip: - * continue - * if pathlen+jump <= self.max_initial_size: # <<<<<<<<<<<<<< - * for alt_id in range(len(fwords[next_id])): - * if (fwords[next_id][alt_id][0] != EPSILON): - */ - __pyx_t_10 = PyNumber_Add(__pyx_v_pathlen, __pyx_v_jump); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 858; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_9 = PyInt_FromLong(__pyx_v_self->max_initial_size); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 858; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_4 = PyObject_RichCompare(__pyx_t_10, __pyx_t_9, Py_LE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 858; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 858; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":859 - * continue - * if pathlen+jump <= self.max_initial_size: - * for alt_id in range(len(fwords[next_id])): # <<<<<<<<<<<<<< - * if (fwords[next_id][alt_id][0] != EPSILON): - * newel = (next_id,alt_id,pathlen+jump) - */ - __pyx_t_4 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_next_id); if (!__pyx_t_4) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_11 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_11); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; - if (PyList_CheckExact(__pyx_t_4) || PyTuple_CheckExact(__pyx_t_4)) { - __pyx_t_9 = __pyx_t_4; __Pyx_INCREF(__pyx_t_9); __pyx_t_11 = 0; - __pyx_t_12 = NULL; - } else { - __pyx_t_11 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_12 = Py_TYPE(__pyx_t_9)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - for (;;) { - if (!__pyx_t_12 && PyList_CheckExact(__pyx_t_9)) { - if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_9)) break; - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_11); __Pyx_INCREF(__pyx_t_4); __pyx_t_11++; - } else if (!__pyx_t_12 && PyTuple_CheckExact(__pyx_t_9)) { - if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_9)) break; - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_11); __Pyx_INCREF(__pyx_t_4); __pyx_t_11++; - } else { - __pyx_t_4 = __pyx_t_12(__pyx_t_9); - if (unlikely(!__pyx_t_4)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_4); - } - __Pyx_XDECREF(__pyx_v_alt_id); - __pyx_v_alt_id = __pyx_t_4; - __pyx_t_4 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":860 - * if pathlen+jump <= self.max_initial_size: - * for alt_id in range(len(fwords[next_id])): - * if (fwords[next_id][alt_id][0] != EPSILON): # <<<<<<<<<<<<<< - * newel = (next_id,alt_id,pathlen+jump) - * if newel not in frontier: - */ - __pyx_t_4 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_next_id); if (!__pyx_t_4) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_10 = PyObject_GetItem(__pyx_t_4, __pyx_v_alt_id); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_10, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = PyInt_FromLong(__pyx_v_8_cdec_sa_EPSILON); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_13 = PyObject_RichCompare(__pyx_t_4, __pyx_t_10, Py_NE); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":861 - * for alt_id in range(len(fwords[next_id])): - * if (fwords[next_id][alt_id][0] != EPSILON): - * newel = (next_id,alt_id,pathlen+jump) # <<<<<<<<<<<<<< - * if newel not in frontier: - * frontier.append((next_id,alt_id,pathlen+jump)) - */ - __pyx_t_13 = PyNumber_Add(__pyx_v_pathlen, __pyx_v_jump); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_v_next_id); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_next_id); - __Pyx_GIVEREF(__pyx_v_next_id); - __Pyx_INCREF(__pyx_v_alt_id); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_alt_id); - __Pyx_GIVEREF(__pyx_v_alt_id); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_13); - __Pyx_GIVEREF(__pyx_t_13); - __pyx_t_13 = 0; - __Pyx_XDECREF(((PyObject *)__pyx_v_newel)); - __pyx_v_newel = __pyx_t_10; - __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":862 - * if (fwords[next_id][alt_id][0] != EPSILON): - * newel = (next_id,alt_id,pathlen+jump) - * if newel not in frontier: # <<<<<<<<<<<<<< - * frontier.append((next_id,alt_id,pathlen+jump)) - * return frontier - */ - __pyx_t_5 = (__Pyx_NegateNonNeg(PySequence_Contains(((PyObject *)__pyx_v_frontier), ((PyObject *)__pyx_v_newel)))); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 862; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":863 - * newel = (next_id,alt_id,pathlen+jump) - * if newel not in frontier: - * frontier.append((next_id,alt_id,pathlen+jump)) # <<<<<<<<<<<<<< - * return frontier - * - */ - __pyx_t_10 = PyNumber_Add(__pyx_v_pathlen, __pyx_v_jump); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_13 = PyTuple_New(3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_INCREF(__pyx_v_next_id); - PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_v_next_id); - __Pyx_GIVEREF(__pyx_v_next_id); - __Pyx_INCREF(__pyx_v_alt_id); - PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_v_alt_id); - __Pyx_GIVEREF(__pyx_v_alt_id); - PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_t_10 = 0; - __pyx_t_14 = PyList_Append(__pyx_v_frontier, ((PyObject *)__pyx_t_13)); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; - goto __pyx_L14; - } - __pyx_L14:; - goto __pyx_L13; - } - __pyx_L13:; - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L10; - } - __pyx_L10:; - __pyx_L7_continue:; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":864 - * if newel not in frontier: - * frontier.append((next_id,alt_id,pathlen+jump)) - * return frontier # <<<<<<<<<<<<<< - * - * def reachable(self, fwords, ifrom, dist): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_frontier)); - __pyx_r = ((PyObject *)__pyx_v_frontier); - 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_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_13); - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.get_all_nodes_isteps_away", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_frontier); - __Pyx_XDECREF(__pyx_v_key); - __Pyx_XDECREF(__pyx_v_reachable); - __Pyx_XDECREF(__pyx_v_nextreachable); - __Pyx_XDECREF(__pyx_v_next_id); - __Pyx_XDECREF(__pyx_v_jump); - __Pyx_XDECREF(__pyx_v_alt_id); - __Pyx_XDECREF(__pyx_v_newel); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_17reachable(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_17reachable(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_fwords = 0; - PyObject *__pyx_v_ifrom = 0; - PyObject *__pyx_v_dist = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fwords,&__pyx_n_s__ifrom,&__pyx_n_s__dist,0}; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("reachable (wrapper)", 0); - { - PyObject* values[3] = {0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fwords); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ifrom); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("reachable", 1, 3, 3, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dist); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("reachable", 1, 3, 3, 2); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "reachable") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - } - __pyx_v_fwords = values[0]; - __pyx_v_ifrom = values[1]; - __pyx_v_dist = values[2]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("reachable", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.reachable", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_16reachable(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_fwords, __pyx_v_ifrom, __pyx_v_dist); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":866 - * return frontier - * - * def reachable(self, fwords, ifrom, dist): # <<<<<<<<<<<<<< - * ret = [] - * if (ifrom >= len(fwords)): - */ - -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_16reachable(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_ifrom, PyObject *__pyx_v_dist) { - PyObject *__pyx_v_ret = NULL; - PyObject *__pyx_v_alt_id = NULL; - PyObject *__pyx_v_ifromchild = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - PyObject *(*__pyx_t_5)(PyObject *); - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - int __pyx_t_9; - Py_ssize_t __pyx_t_10; - PyObject *(*__pyx_t_11)(PyObject *); - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("reachable", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":867 - * - * def reachable(self, fwords, ifrom, dist): - * ret = [] # <<<<<<<<<<<<<< - * if (ifrom >= len(fwords)): - * return ret - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_ret = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":868 - * def reachable(self, fwords, ifrom, dist): - * ret = [] - * if (ifrom >= len(fwords)): # <<<<<<<<<<<<<< - * return ret - * for alt_id in range(len(fwords[ifrom])): - */ - __pyx_t_2 = PyObject_Length(__pyx_v_fwords); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_RichCompare(__pyx_v_ifrom, __pyx_t_1, Py_GE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":869 - * ret = [] - * if (ifrom >= len(fwords)): - * return ret # <<<<<<<<<<<<<< - * for alt_id in range(len(fwords[ifrom])): - * if (fwords[ifrom][alt_id][0] == EPSILON): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_ret)); - __pyx_r = ((PyObject *)__pyx_v_ret); - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":870 - * if (ifrom >= len(fwords)): - * return ret - * for alt_id in range(len(fwords[ifrom])): # <<<<<<<<<<<<<< - * if (fwords[ifrom][alt_id][0] == EPSILON): - * ret.extend(self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist)) - */ - __pyx_t_3 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ifrom); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; - __pyx_t_5 = NULL; - } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; - } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; - } else { - __pyx_t_3 = __pyx_t_5(__pyx_t_1); - if (unlikely(!__pyx_t_3)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF(__pyx_v_alt_id); - __pyx_v_alt_id = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":871 - * return ret - * for alt_id in range(len(fwords[ifrom])): - * if (fwords[ifrom][alt_id][0] == EPSILON): # <<<<<<<<<<<<<< - * ret.extend(self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist)) - * else: - */ - __pyx_t_3 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ifrom); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = PyObject_GetItem(__pyx_t_3, __pyx_v_alt_id); if (!__pyx_t_6) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_6, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyInt_FromLong(__pyx_v_8_cdec_sa_EPSILON); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = PyObject_RichCompare(__pyx_t_3, __pyx_t_6, Py_EQ); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":872 - * for alt_id in range(len(fwords[ifrom])): - * if (fwords[ifrom][alt_id][0] == EPSILON): - * ret.extend(self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist)) # <<<<<<<<<<<<<< - * else: - * if (dist==0): - */ - __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_ret), __pyx_n_s__extend); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__reachable); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_3 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ifrom); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_8 = PyObject_GetItem(__pyx_t_3, __pyx_v_alt_id); if (!__pyx_t_8) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_8, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = PyNumber_Add(__pyx_v_ifrom, __pyx_t_3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_fwords); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_fwords); - __Pyx_GIVEREF(__pyx_v_fwords); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - __Pyx_INCREF(__pyx_v_dist); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_dist); - __Pyx_GIVEREF(__pyx_v_dist); - __pyx_t_8 = 0; - __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8); - __Pyx_GIVEREF(__pyx_t_8); - __pyx_t_8 = 0; - __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - goto __pyx_L6; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":874 - * ret.extend(self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist)) - * else: - * if (dist==0): # <<<<<<<<<<<<<< - * if (ifrom not in ret): - * ret.append(ifrom) - */ - __pyx_t_8 = PyObject_RichCompare(__pyx_v_dist, __pyx_int_0, Py_EQ); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":875 - * else: - * if (dist==0): - * if (ifrom not in ret): # <<<<<<<<<<<<<< - * ret.append(ifrom) - * else: - */ - __pyx_t_4 = (__Pyx_NegateNonNeg(PySequence_Contains(((PyObject *)__pyx_v_ret), __pyx_v_ifrom))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":876 - * if (dist==0): - * if (ifrom not in ret): - * ret.append(ifrom) # <<<<<<<<<<<<<< - * else: - * for ifromchild in self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist-1): - */ - __pyx_t_9 = PyList_Append(__pyx_v_ret, __pyx_v_ifrom); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 876; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L8; - } - __pyx_L8:; - goto __pyx_L7; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":878 - * ret.append(ifrom) - * else: - * for ifromchild in self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist-1): # <<<<<<<<<<<<<< - * if (ifromchild not in ret): - * ret.append(ifromchild) - */ - __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__reachable); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_3 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ifrom); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = PyObject_GetItem(__pyx_t_3, __pyx_v_alt_id); if (!__pyx_t_7) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_7, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Add(__pyx_v_ifrom, __pyx_t_3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Subtract(__pyx_v_dist, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_INCREF(__pyx_v_fwords); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_fwords); - __Pyx_GIVEREF(__pyx_v_fwords); - PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_7 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_6 = __pyx_t_3; __Pyx_INCREF(__pyx_t_6); __pyx_t_10 = 0; - __pyx_t_11 = NULL; - } else { - __pyx_t_10 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_11 = Py_TYPE(__pyx_t_6)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_6)) { - if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_6)) break; - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_10); __Pyx_INCREF(__pyx_t_3); __pyx_t_10++; - } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_6)) { - if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_6)) break; - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_10); __Pyx_INCREF(__pyx_t_3); __pyx_t_10++; - } else { - __pyx_t_3 = __pyx_t_11(__pyx_t_6); - if (unlikely(!__pyx_t_3)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF(__pyx_v_ifromchild); - __pyx_v_ifromchild = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":879 - * else: - * for ifromchild in self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist-1): - * if (ifromchild not in ret): # <<<<<<<<<<<<<< - * ret.append(ifromchild) - * - */ - __pyx_t_4 = (__Pyx_NegateNonNeg(PySequence_Contains(((PyObject *)__pyx_v_ret), __pyx_v_ifromchild))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 879; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":880 - * for ifromchild in self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist-1): - * if (ifromchild not in ret): - * ret.append(ifromchild) # <<<<<<<<<<<<<< - * - * return ret - */ - __pyx_t_9 = PyList_Append(__pyx_v_ret, __pyx_v_ifromchild); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 880; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L11; - } - __pyx_L11:; - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __pyx_L7:; - } - __pyx_L6:; - } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":882 - * ret.append(ifromchild) - * - * return ret # <<<<<<<<<<<<<< - * - * def shortest(self, fwords, ifrom, ito): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_ret)); - __pyx_r = ((PyObject *)__pyx_v_ret); - 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_3); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.reachable", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_ret); - __Pyx_XDECREF(__pyx_v_alt_id); - __Pyx_XDECREF(__pyx_v_ifromchild); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_19shortest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_19shortest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_fwords = 0; - PyObject *__pyx_v_ifrom = 0; - PyObject *__pyx_v_ito = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fwords,&__pyx_n_s__ifrom,&__pyx_n_s__ito,0}; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("shortest (wrapper)", 0); - { - PyObject* values[3] = {0,0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fwords); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ifrom); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("shortest", 1, 3, 3, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - case 2: - values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ito); - if (likely(values[2])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("shortest", 1, 3, 3, 2); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "shortest") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - } - __pyx_v_fwords = values[0]; - __pyx_v_ifrom = values[1]; - __pyx_v_ito = values[2]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("shortest", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.shortest", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_18shortest(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_fwords, __pyx_v_ifrom, __pyx_v_ito); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":884 - * return ret - * - * def shortest(self, fwords, ifrom, ito): # <<<<<<<<<<<<<< - * cdef unsigned alt_id - * min = 1000 - */ - -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_18shortest(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_ifrom, PyObject *__pyx_v_ito) { - unsigned int __pyx_v_alt_id; - PyObject *__pyx_v_min = NULL; - PyObject *__pyx_v_currmin = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - Py_ssize_t __pyx_t_3; - unsigned int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("shortest", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":886 - * def shortest(self, fwords, ifrom, ito): - * cdef unsigned alt_id - * min = 1000 # <<<<<<<<<<<<<< - * if (ifrom > ito): - * return min - */ - __Pyx_INCREF(__pyx_int_1000); - __pyx_v_min = __pyx_int_1000; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":887 - * cdef unsigned alt_id - * min = 1000 - * if (ifrom > ito): # <<<<<<<<<<<<<< - * return min - * if (ifrom == ito): - */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_ifrom, __pyx_v_ito, Py_GT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":888 - * min = 1000 - * if (ifrom > ito): - * return min # <<<<<<<<<<<<<< - * if (ifrom == ito): - * return 0 - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_min); - __pyx_r = __pyx_v_min; - goto __pyx_L0; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":889 - * if (ifrom > ito): - * return min - * if (ifrom == ito): # <<<<<<<<<<<<<< - * return 0 - * for alt_id in range(len(fwords[ifrom])): - */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_ifrom, __pyx_v_ito, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":890 - * return min - * if (ifrom == ito): - * return 0 # <<<<<<<<<<<<<< - * for alt_id in range(len(fwords[ifrom])): - * currmin = self.shortest(fwords,ifrom+fwords[ifrom][alt_id][2],ito) - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_int_0); - __pyx_r = __pyx_int_0; - goto __pyx_L0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":891 - * if (ifrom == ito): - * return 0 - * for alt_id in range(len(fwords[ifrom])): # <<<<<<<<<<<<<< - * currmin = self.shortest(fwords,ifrom+fwords[ifrom][alt_id][2],ito) - * if (fwords[ifrom][alt_id][0] != EPSILON): - */ - __pyx_t_1 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ifrom); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 891; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 891; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_alt_id = __pyx_t_4; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":892 - * return 0 - * for alt_id in range(len(fwords[ifrom])): - * currmin = self.shortest(fwords,ifrom+fwords[ifrom][alt_id][2],ito) # <<<<<<<<<<<<<< - * if (fwords[ifrom][alt_id][0] != EPSILON): - * currmin += 1 - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__shortest); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ifrom); if (!__pyx_t_5) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_5, __pyx_v_alt_id, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_6) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_6, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyNumber_Add(__pyx_v_ifrom, __pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(__pyx_v_fwords); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_fwords); - __Pyx_GIVEREF(__pyx_v_fwords); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6); - __Pyx_GIVEREF(__pyx_t_6); - __Pyx_INCREF(__pyx_v_ito); - PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_ito); - __Pyx_GIVEREF(__pyx_v_ito); - __pyx_t_6 = 0; - __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_v_currmin); - __pyx_v_currmin = __pyx_t_6; - __pyx_t_6 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":893 - * for alt_id in range(len(fwords[ifrom])): - * currmin = self.shortest(fwords,ifrom+fwords[ifrom][alt_id][2],ito) - * if (fwords[ifrom][alt_id][0] != EPSILON): # <<<<<<<<<<<<<< - * currmin += 1 - * if (currmin 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__min_dist); - if (value) { values[2] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_next_states") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 899; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v__columns = values[0]; - __pyx_v_curr_idx = values[1]; - __pyx_v_min_dist = values[2]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get_next_states", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 899; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.get_next_states", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_20get_next_states(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v__columns, __pyx_v_curr_idx, __pyx_v_min_dist); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":899 - * return min - * - * def get_next_states(self, _columns, curr_idx, min_dist=2): # <<<<<<<<<<<<<< - * result = [] - * candidate = [[curr_idx,0]] - */ - -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_20get_next_states(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v__columns, PyObject *__pyx_v_curr_idx, PyObject *__pyx_v_min_dist) { - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_v_candidate = NULL; - PyObject *__pyx_v_curr = NULL; - PyObject *__pyx_v_curr_col = NULL; - PyObject *__pyx_v_alt = NULL; - PyObject *__pyx_v_next_id = NULL; - PyObject *__pyx_v_jump = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - Py_ssize_t __pyx_t_3; - int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - int __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - PyObject *(*__pyx_t_9)(PyObject *); - PyObject *__pyx_t_10 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get_next_states", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":900 - * - * def get_next_states(self, _columns, curr_idx, min_dist=2): - * result = [] # <<<<<<<<<<<<<< - * candidate = [[curr_idx,0]] - * - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 900; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_result = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":901 - * def get_next_states(self, _columns, curr_idx, min_dist=2): - * result = [] - * candidate = [[curr_idx,0]] # <<<<<<<<<<<<<< - * - * while len(candidate) > 0: - */ - __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 901; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_curr_idx); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_curr_idx); - __Pyx_GIVEREF(__pyx_v_curr_idx); - __Pyx_INCREF(__pyx_int_0); - PyList_SET_ITEM(__pyx_t_1, 1, __pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 901; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); - __pyx_t_1 = 0; - __pyx_v_candidate = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":903 - * candidate = [[curr_idx,0]] - * - * while len(candidate) > 0: # <<<<<<<<<<<<<< - * curr = candidate.pop() - * if curr[0] >= len(_columns): - */ - while (1) { - __pyx_t_3 = PyList_GET_SIZE(((PyObject *)__pyx_v_candidate)); - __pyx_t_4 = (__pyx_t_3 > 0); - if (!__pyx_t_4) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":904 - * - * while len(candidate) > 0: - * curr = candidate.pop() # <<<<<<<<<<<<<< - * if curr[0] >= len(_columns): - * continue - */ - __pyx_t_2 = __Pyx_PyObject_Pop(((PyObject *)__pyx_v_candidate)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 904; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_v_curr); - __pyx_v_curr = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":905 - * while len(candidate) > 0: - * curr = candidate.pop() - * if curr[0] >= len(_columns): # <<<<<<<<<<<<<< - * continue - * if curr[0] not in result and min_dist <= curr[1] <= self.max_initial_size: - */ - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_curr, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 905; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyObject_Length(__pyx_v__columns); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 905; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 905; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyObject_RichCompare(__pyx_t_2, __pyx_t_1, Py_GE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 905; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 905; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":906 - * curr = candidate.pop() - * if curr[0] >= len(_columns): - * continue # <<<<<<<<<<<<<< - * if curr[0] not in result and min_dist <= curr[1] <= self.max_initial_size: - * result.append(curr[0]); - */ - goto __pyx_L3_continue; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":907 - * if curr[0] >= len(_columns): - * continue - * if curr[0] not in result and min_dist <= curr[1] <= self.max_initial_size: # <<<<<<<<<<<<<< - * result.append(curr[0]); - * curr_col = _columns[curr[0]] - */ - __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_curr, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = (__Pyx_NegateNonNeg(PySequence_Contains(((PyObject *)__pyx_v_result), __pyx_t_5))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (__pyx_t_4) { - __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_curr, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyObject_RichCompare(__pyx_v_min_dist, __pyx_t_5, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_PyObject_IsTrue(__pyx_t_1)) { - __Pyx_DECREF(__pyx_t_1); - __pyx_t_2 = PyInt_FromLong(__pyx_v_self->max_initial_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_RichCompare(__pyx_t_5, __pyx_t_2, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_7 = __pyx_t_6; - } else { - __pyx_t_7 = __pyx_t_4; - } - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":908 - * continue - * if curr[0] not in result and min_dist <= curr[1] <= self.max_initial_size: - * result.append(curr[0]); # <<<<<<<<<<<<<< - * curr_col = _columns[curr[0]] - * for alt in curr_col: - */ - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_curr, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 908; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_8 = PyList_Append(__pyx_v_result, __pyx_t_1); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 908; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L6; - } - __pyx_L6:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":909 - * if curr[0] not in result and min_dist <= curr[1] <= self.max_initial_size: - * result.append(curr[0]); - * curr_col = _columns[curr[0]] # <<<<<<<<<<<<<< - * for alt in curr_col: - * next_id = curr[0]+alt[2] - */ - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_curr, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 909; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyObject_GetItem(__pyx_v__columns, __pyx_t_1); if (!__pyx_t_5) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 909; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_v_curr_col); - __pyx_v_curr_col = __pyx_t_5; - __pyx_t_5 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":910 - * result.append(curr[0]); - * curr_col = _columns[curr[0]] - * for alt in curr_col: # <<<<<<<<<<<<<< - * next_id = curr[0]+alt[2] - * jump = 1 - */ - if (PyList_CheckExact(__pyx_v_curr_col) || PyTuple_CheckExact(__pyx_v_curr_col)) { - __pyx_t_5 = __pyx_v_curr_col; __Pyx_INCREF(__pyx_t_5); __pyx_t_3 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_3 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_curr_col); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 910; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_9 = Py_TYPE(__pyx_t_5)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_5)) { - if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_5)) break; - __pyx_t_1 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_5)) { - if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_5)) break; - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; - } else { - __pyx_t_1 = __pyx_t_9(__pyx_t_5); - if (unlikely(!__pyx_t_1)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 910; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_1); - } - __Pyx_XDECREF(__pyx_v_alt); - __pyx_v_alt = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":911 - * curr_col = _columns[curr[0]] - * for alt in curr_col: - * next_id = curr[0]+alt[2] # <<<<<<<<<<<<<< - * jump = 1 - * if (alt[0] == EPSILON): - */ - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_curr, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 911; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_alt, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 911; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = PyNumber_Add(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 911; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_v_next_id); - __pyx_v_next_id = __pyx_t_10; - __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":912 - * for alt in curr_col: - * next_id = curr[0]+alt[2] - * jump = 1 # <<<<<<<<<<<<<< - * if (alt[0] == EPSILON): - * jump = 0 - */ - __Pyx_INCREF(__pyx_int_1); - __Pyx_XDECREF(__pyx_v_jump); - __pyx_v_jump = __pyx_int_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":913 - * next_id = curr[0]+alt[2] - * jump = 1 - * if (alt[0] == EPSILON): # <<<<<<<<<<<<<< - * jump = 0 - * if next_id not in result and min_dist <= curr[1]+jump <= self.max_initial_size+1: - */ - __pyx_t_10 = __Pyx_GetItemInt(__pyx_v_alt, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 913; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = PyInt_FromLong(__pyx_v_8_cdec_sa_EPSILON); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 913; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_RichCompare(__pyx_t_10, __pyx_t_2, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 913; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 913; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":914 - * jump = 1 - * if (alt[0] == EPSILON): - * jump = 0 # <<<<<<<<<<<<<< - * if next_id not in result and min_dist <= curr[1]+jump <= self.max_initial_size+1: - * candidate.append([next_id,curr[1]+jump]) - */ - __Pyx_INCREF(__pyx_int_0); - __Pyx_DECREF(__pyx_v_jump); - __pyx_v_jump = __pyx_int_0; - goto __pyx_L9; - } - __pyx_L9:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":915 - * if (alt[0] == EPSILON): - * jump = 0 - * if next_id not in result and min_dist <= curr[1]+jump <= self.max_initial_size+1: # <<<<<<<<<<<<<< - * candidate.append([next_id,curr[1]+jump]) - * return sorted(result); - */ - __pyx_t_7 = (__Pyx_NegateNonNeg(PySequence_Contains(((PyObject *)__pyx_v_result), __pyx_v_next_id))); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_7) { - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_curr, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_v_jump); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_v_min_dist, __pyx_t_2, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_PyObject_IsTrue(__pyx_t_1)) { - __Pyx_DECREF(__pyx_t_1); - __pyx_t_10 = PyInt_FromLong((__pyx_v_self->max_initial_size + 1)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_t_10, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = __pyx_t_4; - } else { - __pyx_t_6 = __pyx_t_7; - } - if (__pyx_t_6) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":916 - * jump = 0 - * if next_id not in result and min_dist <= curr[1]+jump <= self.max_initial_size+1: - * candidate.append([next_id,curr[1]+jump]) # <<<<<<<<<<<<<< - * return sorted(result); - * - */ - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_curr, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 916; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_v_jump); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 916; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 916; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_next_id); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_next_id); - __Pyx_GIVEREF(__pyx_v_next_id); - PyList_SET_ITEM(__pyx_t_1, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_8 = PyList_Append(__pyx_v_candidate, ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 916; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - goto __pyx_L10; - } - __pyx_L10:; - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_L3_continue:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":917 - * if next_id not in result and min_dist <= curr[1]+jump <= self.max_initial_size+1: - * candidate.append([next_id,curr[1]+jump]) - * return sorted(result); # <<<<<<<<<<<<<< - * - * def input(self, fwords, models): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 917; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(((PyObject *)__pyx_v_result)); - PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_result)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_result)); - __pyx_t_1 = PyObject_Call(__pyx_builtin_sorted, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 917; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 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_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.get_next_states", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XDECREF(__pyx_v_candidate); - __Pyx_XDECREF(__pyx_v_curr); - __Pyx_XDECREF(__pyx_v_curr_col); - __Pyx_XDECREF(__pyx_v_alt); - __Pyx_XDECREF(__pyx_v_next_id); - __Pyx_XDECREF(__pyx_v_jump); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -static PyObject *__pyx_gb_8_cdec_sa_23HieroCachingRuleFactory_24generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ - -/* Python wrapper */ -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_23input(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_8_cdec_sa_23HieroCachingRuleFactory_22input[] = "When this function is called on the RuleFactory,\n it looks up all of the rules that can be used to translate\n the input sentence"; -static PyObject *__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_23input(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_fwords = 0; - PyObject *__pyx_v_models = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fwords,&__pyx_n_s__models,0}; - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("input (wrapper)", 0); - { - PyObject* values[2] = {0,0}; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args; - const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); - switch (pos_args) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - 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 (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fwords); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__models); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("input", 1, 2, 2, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "input") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - } - __pyx_v_fwords = values[0]; - __pyx_v_models = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("input", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.input", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_22input(((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_fwords, __pyx_v_models); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":919 - * return sorted(result); - * - * def input(self, fwords, models): # <<<<<<<<<<<<<< - * '''When this function is called on the RuleFactory, - * it looks up all of the rules that can be used to translate - */ - -static PyObject *__pyx_pf_8_cdec_sa_23HieroCachingRuleFactory_22input(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_models) { - struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *__pyx_cur_scope; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("input", 0); - __pyx_cur_scope = (struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *)__pyx_ptype_8_cdec_sa___pyx_scope_struct_1_input->tp_new(__pyx_ptype_8_cdec_sa___pyx_scope_struct_1_input, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_v_self = __pyx_v_self; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); - __pyx_cur_scope->__pyx_v_fwords = __pyx_v_fwords; - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fwords); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_fwords); - __pyx_cur_scope->__pyx_v_models = __pyx_v_models; - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_models); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_models); - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_8_cdec_sa_23HieroCachingRuleFactory_24generator1, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.input", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_gb_8_cdec_sa_23HieroCachingRuleFactory_24generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *__pyx_cur_scope = ((struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - Py_ssize_t __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - Py_ssize_t __pyx_t_5; - int __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - int __pyx_t_8; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - int __pyx_t_11; - PyObject *__pyx_t_12 = NULL; - PyObject *__pyx_t_13 = NULL; - PyObject *__pyx_t_14 = NULL; - PyObject *__pyx_t_15 = NULL; - PyObject *__pyx_t_16 = NULL; - PyObject *(*__pyx_t_17)(PyObject *); - int __pyx_t_18; - int __pyx_t_19; - float __pyx_t_20; - Py_ssize_t __pyx_t_21; - PyObject *__pyx_t_22 = NULL; - PyObject *__pyx_t_23 = NULL; - Py_ssize_t __pyx_t_24; - PyObject *(*__pyx_t_25)(PyObject *); - Py_ssize_t __pyx_t_26; - PyObject *(*__pyx_t_27)(PyObject *); - int __pyx_t_28; - int __pyx_t_29; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("None", 0); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L63_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[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":930 - * cdef Phrase hiero_phrase - * - * flen = len(fwords) # <<<<<<<<<<<<<< - * start_time = monitor_cpu() - * self.extract_time = 0.0 - */ - __pyx_t_1 = PyObject_Length(__pyx_cur_scope->__pyx_v_fwords); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 930; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_cur_scope->__pyx_v_flen = __pyx_t_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":931 - * - * flen = len(fwords) - * start_time = monitor_cpu() # <<<<<<<<<<<<<< - * self.extract_time = 0.0 - * nodes_isteps_away_buffer = {} - */ - __pyx_cur_scope->__pyx_v_start_time = __pyx_f_8_cdec_sa_monitor_cpu(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":932 - * flen = len(fwords) - * start_time = monitor_cpu() - * self.extract_time = 0.0 # <<<<<<<<<<<<<< - * nodes_isteps_away_buffer = {} - * hit = 0 - */ - __pyx_cur_scope->__pyx_v_self->extract_time = 0.0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":933 - * start_time = monitor_cpu() - * self.extract_time = 0.0 - * nodes_isteps_away_buffer = {} # <<<<<<<<<<<<<< - * hit = 0 - * reachable_buffer = {} - */ - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 933; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); - __pyx_cur_scope->__pyx_v_nodes_isteps_away_buffer = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":934 - * self.extract_time = 0.0 - * nodes_isteps_away_buffer = {} - * hit = 0 # <<<<<<<<<<<<<< - * reachable_buffer = {} - * - */ - __pyx_cur_scope->__pyx_v_hit = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":935 - * nodes_isteps_away_buffer = {} - * hit = 0 - * reachable_buffer = {} # <<<<<<<<<<<<<< - * - * # Do not cache between sentences - */ - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 935; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); - __pyx_cur_scope->__pyx_v_reachable_buffer = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":938 - * - * # Do not cache between sentences - * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) # <<<<<<<<<<<<<< - * - * frontier = [] - */ - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_PhraseLocation)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__phrase_location), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_GIVEREF(__pyx_t_3); - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->rules->root); - __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->rules->root); - __pyx_cur_scope->__pyx_v_self->rules->root = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":940 - * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) - * - * frontier = [] # <<<<<<<<<<<<<< - * for i in range(len(fwords)): - * for alt in range(0, len(fwords[i])): - */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 940; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); - __pyx_cur_scope->__pyx_v_frontier = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":941 - * - * frontier = [] - * for i in range(len(fwords)): # <<<<<<<<<<<<<< - * for alt in range(0, len(fwords[i])): - * if fwords[i][alt][0] != EPSILON: - */ - __pyx_t_1 = PyObject_Length(__pyx_cur_scope->__pyx_v_fwords); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_1; __pyx_t_4+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_4; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":942 - * frontier = [] - * for i in range(len(fwords)): - * for alt in range(0, len(fwords[i])): # <<<<<<<<<<<<<< - * if fwords[i][alt][0] != EPSILON: - * frontier.append((i, i, alt, 0, self.rules.root, (), False)) - */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_fwords, __pyx_cur_scope->__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 942; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_5 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 942; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_cur_scope->__pyx_v_alt = __pyx_t_6; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":943 - * for i in range(len(fwords)): - * for alt in range(0, len(fwords[i])): - * if fwords[i][alt][0] != EPSILON: # <<<<<<<<<<<<<< - * frontier.append((i, i, alt, 0, self.rules.root, (), False)) - * - */ - __pyx_t_3 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_fwords, __pyx_cur_scope->__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_3, __pyx_cur_scope->__pyx_v_alt, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyInt_FromLong(__pyx_v_8_cdec_sa_EPSILON); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_NE); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":944 - * for alt in range(0, len(fwords[i])): - * if fwords[i][alt][0] != EPSILON: - * frontier.append((i, i, alt, 0, self.rules.root, (), False)) # <<<<<<<<<<<<<< - * - * xroot = None - */ - __pyx_t_7 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_alt); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = PyTuple_New(7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __Pyx_INCREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_self->rules->root); - PyTuple_SET_ITEM(__pyx_t_10, 4, __pyx_cur_scope->__pyx_v_self->rules->root); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_self->rules->root); - __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); - PyTuple_SET_ITEM(__pyx_t_10, 5, ((PyObject *)__pyx_empty_tuple)); - __Pyx_GIVEREF(((PyObject *)__pyx_empty_tuple)); - PyTuple_SET_ITEM(__pyx_t_10, 6, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - __pyx_t_7 = 0; - __pyx_t_2 = 0; - __pyx_t_3 = 0; - __pyx_t_9 = 0; - __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_frontier, ((PyObject *)__pyx_t_10)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - goto __pyx_L8; - } - __pyx_L8:; - } - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":946 - * frontier.append((i, i, alt, 0, self.rules.root, (), False)) - * - * xroot = None # <<<<<<<<<<<<<< - * x1 = sym_setindex(self.category, 1) - * if x1 in self.rules.root.children: - */ - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __pyx_cur_scope->__pyx_v_xroot = Py_None; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":947 - * - * xroot = None - * x1 = sym_setindex(self.category, 1) # <<<<<<<<<<<<<< - * if x1 in self.rules.root.children: - * xroot = self.rules.root.children[x1] - */ - __pyx_cur_scope->__pyx_v_x1 = __pyx_f_8_cdec_sa_sym_setindex(__pyx_cur_scope->__pyx_v_self->category, 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":948 - * xroot = None - * x1 = sym_setindex(self.category, 1) - * if x1 in self.rules.root.children: # <<<<<<<<<<<<<< - * xroot = self.rules.root.children[x1] - * else: - */ - __pyx_t_10 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_x1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_self->rules->root, __pyx_n_s__children); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = ((PySequence_Contains(__pyx_t_9, __pyx_t_10))); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":949 - * x1 = sym_setindex(self.category, 1) - * if x1 in self.rules.root.children: - * xroot = self.rules.root.children[x1] # <<<<<<<<<<<<<< - * else: - * xroot = ExtendedTrieNode(suffix_link=self.rules.root, phrase_location=PhraseLocation()) - */ - __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_self->rules->root, __pyx_n_s__children); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 949; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = __Pyx_GetItemInt(__pyx_t_9, __pyx_cur_scope->__pyx_v_x1, sizeof(int), PyInt_FromLong); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 949; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_xroot); - __Pyx_DECREF(__pyx_cur_scope->__pyx_v_xroot); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_cur_scope->__pyx_v_xroot = __pyx_t_10; - __pyx_t_10 = 0; - goto __pyx_L9; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":951 - * xroot = self.rules.root.children[x1] - * else: - * xroot = ExtendedTrieNode(suffix_link=self.rules.root, phrase_location=PhraseLocation()) # <<<<<<<<<<<<<< - * self.rules.root.children[x1] = xroot - * - */ - __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_10)); - if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__suffix_link), __pyx_cur_scope->__pyx_v_self->rules->root) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_PhraseLocation)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__phrase_location), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_xroot); - __Pyx_DECREF(__pyx_cur_scope->__pyx_v_xroot); - __Pyx_GIVEREF(__pyx_t_9); - __pyx_cur_scope->__pyx_v_xroot = __pyx_t_9; - __pyx_t_9 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":952 - * else: - * xroot = ExtendedTrieNode(suffix_link=self.rules.root, phrase_location=PhraseLocation()) - * self.rules.root.children[x1] = xroot # <<<<<<<<<<<<<< - * - * for i in range(self.min_gap_size, len(fwords)): - */ - __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_self->rules->root, __pyx_n_s__children); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 952; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - if (__Pyx_SetItemInt(__pyx_t_9, __pyx_cur_scope->__pyx_v_x1, __pyx_cur_scope->__pyx_v_xroot, sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 952; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - __pyx_L9:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":954 - * self.rules.root.children[x1] = xroot - * - * for i in range(self.min_gap_size, len(fwords)): # <<<<<<<<<<<<<< - * for alt in range(0, len(fwords[i])): - * if fwords[i][alt][0] != EPSILON: - */ - __pyx_t_1 = PyObject_Length(__pyx_cur_scope->__pyx_v_fwords); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - for (__pyx_t_4 = __pyx_cur_scope->__pyx_v_self->min_gap_size; __pyx_t_4 < __pyx_t_1; __pyx_t_4+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_4; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":955 - * - * for i in range(self.min_gap_size, len(fwords)): - * for alt in range(0, len(fwords[i])): # <<<<<<<<<<<<<< - * if fwords[i][alt][0] != EPSILON: - * frontier.append((i-self.min_gap_size, i, alt, self.min_gap_size, xroot, (x1,), True)) - */ - __pyx_t_9 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_fwords, __pyx_cur_scope->__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 955; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_5 = PyObject_Length(__pyx_t_9); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 955; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_cur_scope->__pyx_v_alt = __pyx_t_6; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":956 - * for i in range(self.min_gap_size, len(fwords)): - * for alt in range(0, len(fwords[i])): - * if fwords[i][alt][0] != EPSILON: # <<<<<<<<<<<<<< - * frontier.append((i-self.min_gap_size, i, alt, self.min_gap_size, xroot, (x1,), True)) - * - */ - __pyx_t_9 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_fwords, __pyx_cur_scope->__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = __Pyx_GetItemInt(__pyx_t_9, __pyx_cur_scope->__pyx_v_alt, sizeof(int), PyInt_FromLong); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_GetItemInt(__pyx_t_10, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = PyInt_FromLong(__pyx_v_8_cdec_sa_EPSILON); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_3 = PyObject_RichCompare(__pyx_t_9, __pyx_t_10, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":957 - * for alt in range(0, len(fwords[i])): - * if fwords[i][alt][0] != EPSILON: - * frontier.append((i-self.min_gap_size, i, alt, self.min_gap_size, xroot, (x1,), True)) # <<<<<<<<<<<<<< - * - * next_states = [] - */ - __pyx_t_3 = PyInt_FromLong((__pyx_cur_scope->__pyx_v_i - __pyx_cur_scope->__pyx_v_self->min_gap_size)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_alt); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_2 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->min_gap_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_x1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - __pyx_t_7 = 0; - __pyx_t_7 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_13 = PyTuple_New(7); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_xroot); - PyTuple_SET_ITEM(__pyx_t_13, 4, __pyx_cur_scope->__pyx_v_xroot); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_xroot); - PyTuple_SET_ITEM(__pyx_t_13, 5, ((PyObject *)__pyx_t_12)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_12)); - PyTuple_SET_ITEM(__pyx_t_13, 6, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - __pyx_t_3 = 0; - __pyx_t_10 = 0; - __pyx_t_9 = 0; - __pyx_t_2 = 0; - __pyx_t_12 = 0; - __pyx_t_7 = 0; - __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_frontier, ((PyObject *)__pyx_t_13)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; - goto __pyx_L14; - } - __pyx_L14:; - } - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":959 - * frontier.append((i-self.min_gap_size, i, alt, self.min_gap_size, xroot, (x1,), True)) - * - * next_states = [] # <<<<<<<<<<<<<< - * for i in range(len(fwords)): - * next_states.append(self.get_next_states(fwords,i,self.min_gap_size)) - */ - __pyx_t_13 = PyList_New(0); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 959; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_GIVEREF(((PyObject *)__pyx_t_13)); - __pyx_cur_scope->__pyx_v_next_states = __pyx_t_13; - __pyx_t_13 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":960 - * - * next_states = [] - * for i in range(len(fwords)): # <<<<<<<<<<<<<< - * next_states.append(self.get_next_states(fwords,i,self.min_gap_size)) - * - */ - __pyx_t_1 = PyObject_Length(__pyx_cur_scope->__pyx_v_fwords); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 960; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_1; __pyx_t_4+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_4; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":961 - * next_states = [] - * for i in range(len(fwords)): - * next_states.append(self.get_next_states(fwords,i,self.min_gap_size)) # <<<<<<<<<<<<<< - * - * while len(frontier) > 0: - */ - __pyx_t_13 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s__get_next_states); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - __pyx_t_7 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_12 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->min_gap_size); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fwords); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_fwords); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_fwords); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_7); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_12); - __Pyx_GIVEREF(__pyx_t_12); - __pyx_t_7 = 0; - __pyx_t_12 = 0; - __pyx_t_12 = PyObject_Call(__pyx_t_13, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_next_states, __pyx_t_12); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":963 - * next_states.append(self.get_next_states(fwords,i,self.min_gap_size)) - * - * while len(frontier) > 0: # <<<<<<<<<<<<<< - * new_frontier = [] - * for k, i, alt, pathlen, node, prefix, is_shadow_path in frontier: - */ - while (1) { - __pyx_t_1 = PyList_GET_SIZE(((PyObject *)__pyx_cur_scope->__pyx_v_frontier)); - __pyx_t_8 = (__pyx_t_1 > 0); - if (!__pyx_t_8) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":964 - * - * while len(frontier) > 0: - * new_frontier = [] # <<<<<<<<<<<<<< - * for k, i, alt, pathlen, node, prefix, is_shadow_path in frontier: - * word_id = fwords[i][alt][0] - */ - __pyx_t_12 = PyList_New(0); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 964; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_new_frontier)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_new_frontier)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_12)); - __pyx_cur_scope->__pyx_v_new_frontier = __pyx_t_12; - __pyx_t_12 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":965 - * while len(frontier) > 0: - * new_frontier = [] - * for k, i, alt, pathlen, node, prefix, is_shadow_path in frontier: # <<<<<<<<<<<<<< - * word_id = fwords[i][alt][0] - * spanlen = fwords[i][alt][2] - */ - __pyx_t_12 = ((PyObject *)__pyx_cur_scope->__pyx_v_frontier); __Pyx_INCREF(__pyx_t_12); __pyx_t_1 = 0; - for (;;) { - if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_12)) break; - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_12, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; - if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { - PyObject* sequence = __pyx_t_2; - if (likely(PyTuple_CheckExact(sequence))) { - if (unlikely(PyTuple_GET_SIZE(sequence) != 7)) { - if (PyTuple_GET_SIZE(sequence) > 7) __Pyx_RaiseTooManyValuesError(7); - else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_13 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_9 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 3); - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 4); - __pyx_t_14 = PyTuple_GET_ITEM(sequence, 5); - __pyx_t_15 = PyTuple_GET_ITEM(sequence, 6); - } else { - if (unlikely(PyList_GET_SIZE(sequence) != 7)) { - if (PyList_GET_SIZE(sequence) > 7) __Pyx_RaiseTooManyValuesError(7); - else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_13 = PyList_GET_ITEM(sequence, 0); - __pyx_t_7 = PyList_GET_ITEM(sequence, 1); - __pyx_t_9 = PyList_GET_ITEM(sequence, 2); - __pyx_t_10 = PyList_GET_ITEM(sequence, 3); - __pyx_t_3 = PyList_GET_ITEM(sequence, 4); - __pyx_t_14 = PyList_GET_ITEM(sequence, 5); - __pyx_t_15 = PyList_GET_ITEM(sequence, 6); - } - __Pyx_INCREF(__pyx_t_13); - __Pyx_INCREF(__pyx_t_7); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_14); - __Pyx_INCREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_16 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_16); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_17 = Py_TYPE(__pyx_t_16)->tp_iternext; - index = 0; __pyx_t_13 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_13)) goto __pyx_L21_unpacking_failed; - __Pyx_GOTREF(__pyx_t_13); - index = 1; __pyx_t_7 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_7)) goto __pyx_L21_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - index = 2; __pyx_t_9 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_9)) goto __pyx_L21_unpacking_failed; - __Pyx_GOTREF(__pyx_t_9); - index = 3; __pyx_t_10 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_10)) goto __pyx_L21_unpacking_failed; - __Pyx_GOTREF(__pyx_t_10); - index = 4; __pyx_t_3 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_3)) goto __pyx_L21_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 5; __pyx_t_14 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_14)) goto __pyx_L21_unpacking_failed; - __Pyx_GOTREF(__pyx_t_14); - index = 6; __pyx_t_15 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_15)) goto __pyx_L21_unpacking_failed; - __Pyx_GOTREF(__pyx_t_15); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_16), 7) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - goto __pyx_L22_unpacking_done; - __pyx_L21_unpacking_failed:; - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L22_unpacking_done:; - } - __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_13); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_t_9); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_cur_scope->__pyx_v_k = __pyx_t_4; - __pyx_cur_scope->__pyx_v_i = __pyx_t_6; - __pyx_cur_scope->__pyx_v_alt = __pyx_t_18; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_pathlen); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_pathlen); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_cur_scope->__pyx_v_pathlen = __pyx_t_10; - __pyx_t_10 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_node); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_node); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_v_node = __pyx_t_3; - __pyx_t_3 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_prefix); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_prefix); - __Pyx_GIVEREF(__pyx_t_14); - __pyx_cur_scope->__pyx_v_prefix = __pyx_t_14; - __pyx_t_14 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_is_shadow_path); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_is_shadow_path); - __Pyx_GIVEREF(__pyx_t_15); - __pyx_cur_scope->__pyx_v_is_shadow_path = __pyx_t_15; - __pyx_t_15 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":966 - * new_frontier = [] - * for k, i, alt, pathlen, node, prefix, is_shadow_path in frontier: - * word_id = fwords[i][alt][0] # <<<<<<<<<<<<<< - * spanlen = fwords[i][alt][2] - * # TODO get rid of k -- pathlen is replacing it - */ - __pyx_t_2 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_fwords, __pyx_cur_scope->__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 966; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_15 = __Pyx_GetItemInt(__pyx_t_2, __pyx_cur_scope->__pyx_v_alt, sizeof(int), PyInt_FromLong); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 966; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_15, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 966; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_word_id); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_word_id); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_cur_scope->__pyx_v_word_id = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":967 - * for k, i, alt, pathlen, node, prefix, is_shadow_path in frontier: - * word_id = fwords[i][alt][0] - * spanlen = fwords[i][alt][2] # <<<<<<<<<<<<<< - * # TODO get rid of k -- pathlen is replacing it - * if word_id == EPSILON: - */ - __pyx_t_2 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_fwords, __pyx_cur_scope->__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_15 = __Pyx_GetItemInt(__pyx_t_2, __pyx_cur_scope->__pyx_v_alt, sizeof(int), PyInt_FromLong); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_15, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_spanlen); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_spanlen); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_cur_scope->__pyx_v_spanlen = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":969 - * spanlen = fwords[i][alt][2] - * # TODO get rid of k -- pathlen is replacing it - * if word_id == EPSILON: # <<<<<<<<<<<<<< - * # skipping because word_id is epsilon - * if i+spanlen >= len(fwords): - */ - __pyx_t_2 = PyInt_FromLong(__pyx_v_8_cdec_sa_EPSILON); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 969; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_15 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_word_id, __pyx_t_2, Py_EQ); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 969; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 969; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":971 - * if word_id == EPSILON: - * # skipping because word_id is epsilon - * if i+spanlen >= len(fwords): # <<<<<<<<<<<<<< - * continue - * for nualt in range(0,len(fwords[i+spanlen])): - */ - __pyx_t_15 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_2 = PyNumber_Add(__pyx_t_15, __pyx_cur_scope->__pyx_v_spanlen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_5 = PyObject_Length(__pyx_cur_scope->__pyx_v_fwords); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_15 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_14 = PyObject_RichCompare(__pyx_t_2, __pyx_t_15, Py_GE); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":972 - * # skipping because word_id is epsilon - * if i+spanlen >= len(fwords): - * continue # <<<<<<<<<<<<<< - * for nualt in range(0,len(fwords[i+spanlen])): - * frontier.append((k, i+spanlen, nualt, pathlen, node, prefix, is_shadow_path)) - */ - goto __pyx_L19_continue; - goto __pyx_L24; - } - __pyx_L24:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":973 - * if i+spanlen >= len(fwords): - * continue - * for nualt in range(0,len(fwords[i+spanlen])): # <<<<<<<<<<<<<< - * frontier.append((k, i+spanlen, nualt, pathlen, node, prefix, is_shadow_path)) - * continue - */ - __pyx_t_14 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_15 = PyNumber_Add(__pyx_t_14, __pyx_cur_scope->__pyx_v_spanlen); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_14 = PyObject_GetItem(__pyx_cur_scope->__pyx_v_fwords, __pyx_t_15); if (!__pyx_t_14) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_5 = PyObject_Length(__pyx_t_14); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_5; __pyx_t_18+=1) { - __pyx_cur_scope->__pyx_v_nualt = __pyx_t_18; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":974 - * continue - * for nualt in range(0,len(fwords[i+spanlen])): - * frontier.append((k, i+spanlen, nualt, pathlen, node, prefix, is_shadow_path)) # <<<<<<<<<<<<<< - * continue - * - */ - __pyx_t_14 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_k); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_15 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_2 = PyNumber_Add(__pyx_t_15, __pyx_cur_scope->__pyx_v_spanlen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_15 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_nualt); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_3 = PyTuple_New(7); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_14); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_15); - __Pyx_GIVEREF(__pyx_t_15); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_pathlen); - PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_cur_scope->__pyx_v_pathlen); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_pathlen); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_node); - PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_cur_scope->__pyx_v_node); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_node); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_prefix); - PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_cur_scope->__pyx_v_prefix); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_prefix); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_is_shadow_path); - PyTuple_SET_ITEM(__pyx_t_3, 6, __pyx_cur_scope->__pyx_v_is_shadow_path); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_is_shadow_path); - __pyx_t_14 = 0; - __pyx_t_2 = 0; - __pyx_t_15 = 0; - __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_frontier, ((PyObject *)__pyx_t_3)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":975 - * for nualt in range(0,len(fwords[i+spanlen])): - * frontier.append((k, i+spanlen, nualt, pathlen, node, prefix, is_shadow_path)) - * continue # <<<<<<<<<<<<<< - * - * phrase = prefix + (word_id,) - */ - goto __pyx_L19_continue; - goto __pyx_L23; - } - __pyx_L23:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":977 - * continue - * - * phrase = prefix + (word_id,) # <<<<<<<<<<<<<< - * str_phrase = map(sym_tostring, phrase) - * hiero_phrase = Phrase(phrase) - */ - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_word_id); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_cur_scope->__pyx_v_word_id); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_word_id); - __pyx_t_15 = PyNumber_Add(__pyx_cur_scope->__pyx_v_prefix, ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_phrase); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_phrase); - __Pyx_GIVEREF(__pyx_t_15); - __pyx_cur_scope->__pyx_v_phrase = __pyx_t_15; - __pyx_t_15 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":978 - * - * phrase = prefix + (word_id,) - * str_phrase = map(sym_tostring, phrase) # <<<<<<<<<<<<<< - * hiero_phrase = Phrase(phrase) - * arity = hiero_phrase.arity() - */ - __pyx_t_15 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_tostring); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_15); - __Pyx_GIVEREF(__pyx_t_15); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_phrase); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_cur_scope->__pyx_v_phrase); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_phrase); - __pyx_t_15 = 0; - __pyx_t_15 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_str_phrase); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_str_phrase); - __Pyx_GIVEREF(__pyx_t_15); - __pyx_cur_scope->__pyx_v_str_phrase = __pyx_t_15; - __pyx_t_15 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":979 - * phrase = prefix + (word_id,) - * str_phrase = map(sym_tostring, phrase) - * hiero_phrase = Phrase(phrase) # <<<<<<<<<<<<<< - * arity = hiero_phrase.arity() - * - */ - __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 979; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_phrase); - PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_cur_scope->__pyx_v_phrase); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_phrase); - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 979; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_hiero_phrase)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_hiero_phrase)); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_v_hiero_phrase = ((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":980 - * str_phrase = map(sym_tostring, phrase) - * hiero_phrase = Phrase(phrase) - * arity = hiero_phrase.arity() # <<<<<<<<<<<<<< - * - * lookup_required = False - */ - __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_hiero_phrase), __pyx_n_s__arity); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 980; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_15 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 980; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_t_15); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 980; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_cur_scope->__pyx_v_arity = __pyx_t_18; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":982 - * arity = hiero_phrase.arity() - * - * lookup_required = False # <<<<<<<<<<<<<< - * if word_id in node.children: - * if node.children[word_id] is None: - */ - __pyx_cur_scope->__pyx_v_lookup_required = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":983 - * - * lookup_required = False - * if word_id in node.children: # <<<<<<<<<<<<<< - * if node.children[word_id] is None: - * # Path dead-ends at this node - */ - __pyx_t_15 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 983; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_8 = ((PySequence_Contains(__pyx_t_15, __pyx_cur_scope->__pyx_v_word_id))); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 983; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":984 - * lookup_required = False - * if word_id in node.children: - * if node.children[word_id] is None: # <<<<<<<<<<<<<< - * # Path dead-ends at this node - * continue - */ - __pyx_t_15 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 984; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_3 = PyObject_GetItem(__pyx_t_15, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 984; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_8 = (__pyx_t_3 == Py_None); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":986 - * if node.children[word_id] is None: - * # Path dead-ends at this node - * continue # <<<<<<<<<<<<<< - * else: - * # Path continues at this node - */ - goto __pyx_L19_continue; - goto __pyx_L28; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":989 - * else: - * # Path continues at this node - * node = node.children[word_id] # <<<<<<<<<<<<<< - * else: - * if node.suffix_link is None: - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 989; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_15 = PyObject_GetItem(__pyx_t_3, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 989; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_node); - __Pyx_DECREF(__pyx_cur_scope->__pyx_v_node); - __Pyx_GIVEREF(__pyx_t_15); - __pyx_cur_scope->__pyx_v_node = __pyx_t_15; - __pyx_t_15 = 0; - } - __pyx_L28:; - goto __pyx_L27; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":991 - * node = node.children[word_id] - * else: - * if node.suffix_link is None: # <<<<<<<<<<<<<< - * # Current node is root; lookup required - * lookup_required = True - */ - __pyx_t_15 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 991; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_8 = (__pyx_t_15 == Py_None); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":993 - * if node.suffix_link is None: - * # Current node is root; lookup required - * lookup_required = True # <<<<<<<<<<<<<< - * else: - * if word_id in node.suffix_link.children: - */ - __pyx_cur_scope->__pyx_v_lookup_required = 1; - goto __pyx_L29; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":995 - * lookup_required = True - * else: - * if word_id in node.suffix_link.children: # <<<<<<<<<<<<<< - * if node.suffix_link.children[word_id] is None: - * # Suffix link reports path is dead end - */ - __pyx_t_15 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_3 = PyObject_GetAttr(__pyx_t_15, __pyx_n_s__children); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_8 = ((PySequence_Contains(__pyx_t_3, __pyx_cur_scope->__pyx_v_word_id))); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":996 - * else: - * if word_id in node.suffix_link.children: - * if node.suffix_link.children[word_id] is None: # <<<<<<<<<<<<<< - * # Suffix link reports path is dead end - * node.children[word_id] = None - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 996; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_15 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__children); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 996; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_GetItem(__pyx_t_15, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 996; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_8 = (__pyx_t_3 == Py_None); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":998 - * if node.suffix_link.children[word_id] is None: - * # Suffix link reports path is dead end - * node.children[word_id] = None # <<<<<<<<<<<<<< - * continue - * else: - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 998; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (PyObject_SetItem(__pyx_t_3, __pyx_cur_scope->__pyx_v_word_id, Py_None) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 998; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":999 - * # Suffix link reports path is dead end - * node.children[word_id] = None - * continue # <<<<<<<<<<<<<< - * else: - * # Suffix link indicates lookup is reqired - */ - goto __pyx_L19_continue; - goto __pyx_L31; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1002 - * else: - * # Suffix link indicates lookup is reqired - * lookup_required = True # <<<<<<<<<<<<<< - * else: - * #ERROR: We never get here - */ - __pyx_cur_scope->__pyx_v_lookup_required = 1; - } - __pyx_L31:; - goto __pyx_L30; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1005 - * else: - * #ERROR: We never get here - * raise Exception("Keyword trie error") # <<<<<<<<<<<<<< - * # checking whether lookup_required - * if lookup_required: - */ - __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_k_tuple_120), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L30:; - } - __pyx_L29:; - } - __pyx_L27:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1007 - * raise Exception("Keyword trie error") - * # checking whether lookup_required - * if lookup_required: # <<<<<<<<<<<<<< - * new_node = None - * if is_shadow_path: - */ - if (__pyx_cur_scope->__pyx_v_lookup_required) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1008 - * # checking whether lookup_required - * if lookup_required: - * new_node = None # <<<<<<<<<<<<<< - * if is_shadow_path: - * # Extending shadow path - */ - __Pyx_INCREF(Py_None); - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_new_node); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_new_node); - __Pyx_GIVEREF(Py_None); - __pyx_cur_scope->__pyx_v_new_node = Py_None; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1009 - * if lookup_required: - * new_node = None - * if is_shadow_path: # <<<<<<<<<<<<<< - * # Extending shadow path - * # on the shadow path we don't do any search, we just use info from suffix link - */ - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_is_shadow_path); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1009; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1012 - * # Extending shadow path - * # on the shadow path we don't do any search, we just use info from suffix link - * new_node = ExtendedTrieNode(phrase_location=node.suffix_link.children[word_id].phrase_location, # <<<<<<<<<<<<<< - * suffix_link=node.suffix_link.children[word_id], - * phrase=hiero_phrase) - */ - __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_15 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_15, __pyx_n_s__children); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_15 = PyObject_GetItem(__pyx_t_2, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_GetAttr(__pyx_t_15, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__phrase_location), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1013 - * # on the shadow path we don't do any search, we just use info from suffix link - * new_node = ExtendedTrieNode(phrase_location=node.suffix_link.children[word_id].phrase_location, - * suffix_link=node.suffix_link.children[word_id], # <<<<<<<<<<<<<< - * phrase=hiero_phrase) - * else: - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1013; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_15 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__children); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1013; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_GetItem(__pyx_t_15, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1013; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__suffix_link), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1014 - * new_node = ExtendedTrieNode(phrase_location=node.suffix_link.children[word_id].phrase_location, - * suffix_link=node.suffix_link.children[word_id], - * phrase=hiero_phrase) # <<<<<<<<<<<<<< - * else: - * if arity > 0: - */ - if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__phrase), ((PyObject *)__pyx_cur_scope->__pyx_v_hiero_phrase)) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_new_node); - __Pyx_DECREF(__pyx_cur_scope->__pyx_v_new_node); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_cur_scope->__pyx_v_new_node = __pyx_t_2; - __pyx_t_2 = 0; - goto __pyx_L33; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1016 - * phrase=hiero_phrase) - * else: - * if arity > 0: # <<<<<<<<<<<<<< - * # Intersecting because of arity > 0 - * phrase_location = self.intersect(node, node.suffix_link.children[word_id], hiero_phrase) - */ - __pyx_t_8 = (__pyx_cur_scope->__pyx_v_arity > 0); - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1018 - * if arity > 0: - * # Intersecting because of arity > 0 - * phrase_location = self.intersect(node, node.suffix_link.children[word_id], hiero_phrase) # <<<<<<<<<<<<<< - * else: - * # Suffix array search - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__children); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_GetItem(__pyx_t_3, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = ((PyObject *)((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_cur_scope->__pyx_v_self->__pyx_vtab)->intersect(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_node, __pyx_t_2, __pyx_cur_scope->__pyx_v_hiero_phrase)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_v_phrase_location = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_t_3); - __pyx_t_3 = 0; - goto __pyx_L34; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1021 - * else: - * # Suffix array search - * phrase_location = node.phrase_location # <<<<<<<<<<<<<< - * sa_range = self.fsa.lookup(str_phrase[-1], len(str_phrase)-1, phrase_location.sa_low, phrase_location.sa_high) - * if sa_range is not None: - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_8_cdec_sa_PhraseLocation))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_v_phrase_location = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1022 - * # Suffix array search - * phrase_location = node.phrase_location - * sa_range = self.fsa.lookup(str_phrase[-1], len(str_phrase)-1, phrase_location.sa_low, phrase_location.sa_high) # <<<<<<<<<<<<<< - * if sa_range is not None: - * phrase_location = PhraseLocation(sa_low=sa_range[0], sa_high=sa_range[1]) - */ - __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self->fsa), __pyx_n_s__lookup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_str_phrase, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = PyObject_Length(__pyx_cur_scope->__pyx_v_str_phrase); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_15 = PyInt_FromSsize_t((__pyx_t_5 - 1)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_14 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_phrase_location->sa_low); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_10 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_phrase_location->sa_high); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_9 = PyTuple_New(4); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_15); - __Pyx_GIVEREF(__pyx_t_15); - PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_14); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_t_2 = 0; - __pyx_t_15 = 0; - __pyx_t_14 = 0; - __pyx_t_10 = 0; - __pyx_t_10 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_sa_range); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_sa_range); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_cur_scope->__pyx_v_sa_range = __pyx_t_10; - __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1023 - * phrase_location = node.phrase_location - * sa_range = self.fsa.lookup(str_phrase[-1], len(str_phrase)-1, phrase_location.sa_low, phrase_location.sa_high) - * if sa_range is not None: # <<<<<<<<<<<<<< - * phrase_location = PhraseLocation(sa_low=sa_range[0], sa_high=sa_range[1]) - * else: - */ - __pyx_t_8 = (__pyx_cur_scope->__pyx_v_sa_range != Py_None); - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1024 - * sa_range = self.fsa.lookup(str_phrase[-1], len(str_phrase)-1, phrase_location.sa_low, phrase_location.sa_high) - * if sa_range is not None: - * phrase_location = PhraseLocation(sa_low=sa_range[0], sa_high=sa_range[1]) # <<<<<<<<<<<<<< - * else: - * phrase_location = None - */ - __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_10)); - __pyx_t_9 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_sa_range, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__sa_low), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_sa_range, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__sa_high), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_PhraseLocation)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_GOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); - __Pyx_DECREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); - __Pyx_GIVEREF(__pyx_t_9); - __pyx_cur_scope->__pyx_v_phrase_location = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_t_9); - __pyx_t_9 = 0; - goto __pyx_L35; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1026 - * phrase_location = PhraseLocation(sa_low=sa_range[0], sa_high=sa_range[1]) - * else: - * phrase_location = None # <<<<<<<<<<<<<< - * - * if phrase_location is None: - */ - __Pyx_INCREF(Py_None); - __Pyx_GOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); - __Pyx_DECREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); - __Pyx_GIVEREF(Py_None); - __pyx_cur_scope->__pyx_v_phrase_location = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)Py_None); - } - __pyx_L35:; - } - __pyx_L34:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1028 - * phrase_location = None - * - * if phrase_location is None: # <<<<<<<<<<<<<< - * node.children[word_id] = None - * # Search failed - */ - __pyx_t_8 = (((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location) == Py_None); - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1029 - * - * if phrase_location is None: - * node.children[word_id] = None # <<<<<<<<<<<<<< - * # Search failed - * continue - */ - __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1029; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - if (PyObject_SetItem(__pyx_t_9, __pyx_cur_scope->__pyx_v_word_id, Py_None) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1029; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1031 - * node.children[word_id] = None - * # Search failed - * continue # <<<<<<<<<<<<<< - * # Search succeeded - * suffix_link = self.rules.root - */ - goto __pyx_L19_continue; - goto __pyx_L36; - } - __pyx_L36:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1033 - * continue - * # Search succeeded - * suffix_link = self.rules.root # <<<<<<<<<<<<<< - * if node.suffix_link is not None: - * suffix_link = node.suffix_link.children[word_id] - */ - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_self->rules->root); - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_suffix_link); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_suffix_link); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_self->rules->root); - __pyx_cur_scope->__pyx_v_suffix_link = __pyx_cur_scope->__pyx_v_self->rules->root; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1034 - * # Search succeeded - * suffix_link = self.rules.root - * if node.suffix_link is not None: # <<<<<<<<<<<<<< - * suffix_link = node.suffix_link.children[word_id] - * new_node = ExtendedTrieNode(phrase_location=phrase_location, - */ - __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1034; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_8 = (__pyx_t_9 != Py_None); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1035 - * suffix_link = self.rules.root - * if node.suffix_link is not None: - * suffix_link = node.suffix_link.children[word_id] # <<<<<<<<<<<<<< - * new_node = ExtendedTrieNode(phrase_location=phrase_location, - * suffix_link=suffix_link, - */ - __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1035; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__children); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1035; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = PyObject_GetItem(__pyx_t_10, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1035; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_suffix_link); - __Pyx_DECREF(__pyx_cur_scope->__pyx_v_suffix_link); - __Pyx_GIVEREF(__pyx_t_9); - __pyx_cur_scope->__pyx_v_suffix_link = __pyx_t_9; - __pyx_t_9 = 0; - goto __pyx_L37; - } - __pyx_L37:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1036 - * if node.suffix_link is not None: - * suffix_link = node.suffix_link.children[word_id] - * new_node = ExtendedTrieNode(phrase_location=phrase_location, # <<<<<<<<<<<<<< - * suffix_link=suffix_link, - * phrase=hiero_phrase) - */ - __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_9)); - if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__phrase_location), ((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1037 - * suffix_link = node.suffix_link.children[word_id] - * new_node = ExtendedTrieNode(phrase_location=phrase_location, - * suffix_link=suffix_link, # <<<<<<<<<<<<<< - * phrase=hiero_phrase) - * node.children[word_id] = new_node - */ - if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__suffix_link), __pyx_cur_scope->__pyx_v_suffix_link) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1038 - * new_node = ExtendedTrieNode(phrase_location=phrase_location, - * suffix_link=suffix_link, - * phrase=hiero_phrase) # <<<<<<<<<<<<<< - * node.children[word_id] = new_node - * node = new_node - */ - if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__phrase), ((PyObject *)__pyx_cur_scope->__pyx_v_hiero_phrase)) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_10 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_9)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1036; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_new_node); - __Pyx_DECREF(__pyx_cur_scope->__pyx_v_new_node); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_cur_scope->__pyx_v_new_node = __pyx_t_10; - __pyx_t_10 = 0; - } - __pyx_L33:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1039 - * suffix_link=suffix_link, - * phrase=hiero_phrase) - * node.children[word_id] = new_node # <<<<<<<<<<<<<< - * node = new_node - * - */ - __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1039; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - if (PyObject_SetItem(__pyx_t_10, __pyx_cur_scope->__pyx_v_word_id, __pyx_cur_scope->__pyx_v_new_node) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1039; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1040 - * phrase=hiero_phrase) - * node.children[word_id] = new_node - * node = new_node # <<<<<<<<<<<<<< - * - * '''Automatically add a trailing X node, if allowed -- - */ - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_new_node); - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_node); - __Pyx_DECREF(__pyx_cur_scope->__pyx_v_node); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_new_node); - __pyx_cur_scope->__pyx_v_node = __pyx_cur_scope->__pyx_v_new_node; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1045 - * This should happen before we get to extraction (so that - * the node will exist if needed)''' - * if arity < self.max_nonterminals: # <<<<<<<<<<<<<< - * xcat_index = arity+1 - * xcat = sym_setindex(self.category, xcat_index) - */ - __pyx_t_8 = (__pyx_cur_scope->__pyx_v_arity < __pyx_cur_scope->__pyx_v_self->max_nonterminals); - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1046 - * the node will exist if needed)''' - * if arity < self.max_nonterminals: - * xcat_index = arity+1 # <<<<<<<<<<<<<< - * xcat = sym_setindex(self.category, xcat_index) - * suffix_link_xcat_index = xcat_index - */ - __pyx_t_10 = PyInt_FromLong((__pyx_cur_scope->__pyx_v_arity + 1)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_xcat_index); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_xcat_index); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_cur_scope->__pyx_v_xcat_index = __pyx_t_10; - __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1047 - * if arity < self.max_nonterminals: - * xcat_index = arity+1 - * xcat = sym_setindex(self.category, xcat_index) # <<<<<<<<<<<<<< - * suffix_link_xcat_index = xcat_index - * if is_shadow_path: - */ - __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_cur_scope->__pyx_v_xcat_index); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_cur_scope->__pyx_v_xcat = __pyx_f_8_cdec_sa_sym_setindex(__pyx_cur_scope->__pyx_v_self->category, __pyx_t_18); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1048 - * xcat_index = arity+1 - * xcat = sym_setindex(self.category, xcat_index) - * suffix_link_xcat_index = xcat_index # <<<<<<<<<<<<<< - * if is_shadow_path: - * suffix_link_xcat_index = xcat_index-1 - */ - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_xcat_index); - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_suffix_link_xcat_index); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_suffix_link_xcat_index); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_xcat_index); - __pyx_cur_scope->__pyx_v_suffix_link_xcat_index = __pyx_cur_scope->__pyx_v_xcat_index; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1049 - * xcat = sym_setindex(self.category, xcat_index) - * suffix_link_xcat_index = xcat_index - * if is_shadow_path: # <<<<<<<<<<<<<< - * suffix_link_xcat_index = xcat_index-1 - * suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) - */ - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_is_shadow_path); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1049; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1050 - * suffix_link_xcat_index = xcat_index - * if is_shadow_path: - * suffix_link_xcat_index = xcat_index-1 # <<<<<<<<<<<<<< - * suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) - * node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, - */ - __pyx_t_10 = PyNumber_Subtract(__pyx_cur_scope->__pyx_v_xcat_index, __pyx_int_1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1050; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_suffix_link_xcat_index); - __Pyx_DECREF(__pyx_cur_scope->__pyx_v_suffix_link_xcat_index); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_cur_scope->__pyx_v_suffix_link_xcat_index = __pyx_t_10; - __pyx_t_10 = 0; - goto __pyx_L39; - } - __pyx_L39:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1051 - * if is_shadow_path: - * suffix_link_xcat_index = xcat_index-1 - * suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) # <<<<<<<<<<<<<< - * node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, - * suffix_link=node.suffix_link.children[suffix_link_xcat], - */ - __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_cur_scope->__pyx_v_suffix_link_xcat_index); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_cur_scope->__pyx_v_suffix_link_xcat = __pyx_f_8_cdec_sa_sym_setindex(__pyx_cur_scope->__pyx_v_self->category, __pyx_t_18); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1052 - * suffix_link_xcat_index = xcat_index-1 - * suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) - * node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, # <<<<<<<<<<<<<< - * suffix_link=node.suffix_link.children[suffix_link_xcat], - * phrase= Phrase(phrase + (xcat,))) - */ - __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_10)); - __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__phrase_location), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1053 - * suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) - * node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, - * suffix_link=node.suffix_link.children[suffix_link_xcat], # <<<<<<<<<<<<<< - * phrase= Phrase(phrase + (xcat,))) - * - */ - __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_3 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__children); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = __Pyx_GetItemInt(__pyx_t_3, __pyx_cur_scope->__pyx_v_suffix_link_xcat, sizeof(int), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__suffix_link), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1054 - * node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, - * suffix_link=node.suffix_link.children[suffix_link_xcat], - * phrase= Phrase(phrase + (xcat,))) # <<<<<<<<<<<<<< - * - * # sample from range - */ - __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_xcat); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - __pyx_t_9 = 0; - __pyx_t_9 = PyNumber_Add(__pyx_cur_scope->__pyx_v_phrase, ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - __pyx_t_9 = 0; - __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__phrase), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1052 - * suffix_link_xcat_index = xcat_index-1 - * suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) - * node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, # <<<<<<<<<<<<<< - * suffix_link=node.suffix_link.children[suffix_link_xcat], - * phrase= Phrase(phrase + (xcat,))) - */ - __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - if (__Pyx_SetItemInt(__pyx_t_10, __pyx_cur_scope->__pyx_v_xcat, __pyx_t_9, sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L38; - } - __pyx_L38:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1057 - * - * # sample from range - * if not is_shadow_path: # <<<<<<<<<<<<<< - * sample = self.sampler.sample(node.phrase_location) - * num_subpatterns = ( node.phrase_location).num_subpatterns - */ - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_is_shadow_path); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1057; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_19 = (!__pyx_t_8); - if (__pyx_t_19) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1058 - * # sample from range - * if not is_shadow_path: - * sample = self.sampler.sample(node.phrase_location) # <<<<<<<<<<<<<< - * num_subpatterns = ( node.phrase_location).num_subpatterns - * chunklen = IntList(initial_len=num_subpatterns) - */ - __pyx_t_9 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self->sampler), __pyx_n_s__sample); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_t_10 = 0; - __pyx_t_10 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - if (!(likely(((__pyx_t_10) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_10, __pyx_ptype_8_cdec_sa_IntList))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_sample)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_sample)); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_cur_scope->__pyx_v_sample = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_10); - __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1059 - * if not is_shadow_path: - * sample = self.sampler.sample(node.phrase_location) - * num_subpatterns = ( node.phrase_location).num_subpatterns # <<<<<<<<<<<<<< - * chunklen = IntList(initial_len=num_subpatterns) - * for j from 0 <= j < num_subpatterns: - */ - __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_cur_scope->__pyx_v_num_subpatterns = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)__pyx_t_10)->num_subpatterns; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1060 - * sample = self.sampler.sample(node.phrase_location) - * num_subpatterns = ( node.phrase_location).num_subpatterns - * chunklen = IntList(initial_len=num_subpatterns) # <<<<<<<<<<<<<< - * for j from 0 <= j < num_subpatterns: - * chunklen.arr[j] = hiero_phrase.chunklen(j) - */ - __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_10)); - __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_num_subpatterns); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_chunklen)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_chunklen)); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_v_chunklen = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1061 - * num_subpatterns = ( node.phrase_location).num_subpatterns - * chunklen = IntList(initial_len=num_subpatterns) - * for j from 0 <= j < num_subpatterns: # <<<<<<<<<<<<<< - * chunklen.arr[j] = hiero_phrase.chunklen(j) - * extracts = [] - */ - __pyx_t_18 = __pyx_cur_scope->__pyx_v_num_subpatterns; - for (__pyx_cur_scope->__pyx_v_j = 0; __pyx_cur_scope->__pyx_v_j < __pyx_t_18; __pyx_cur_scope->__pyx_v_j++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1062 - * chunklen = IntList(initial_len=num_subpatterns) - * for j from 0 <= j < num_subpatterns: - * chunklen.arr[j] = hiero_phrase.chunklen(j) # <<<<<<<<<<<<<< - * extracts = [] - * j = 0 - */ - (__pyx_cur_scope->__pyx_v_chunklen->arr[__pyx_cur_scope->__pyx_v_j]) = ((struct __pyx_vtabstruct_8_cdec_sa_Phrase *)__pyx_cur_scope->__pyx_v_hiero_phrase->__pyx_vtab)->chunklen(__pyx_cur_scope->__pyx_v_hiero_phrase, __pyx_cur_scope->__pyx_v_j); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1063 - * for j from 0 <= j < num_subpatterns: - * chunklen.arr[j] = hiero_phrase.chunklen(j) - * extracts = [] # <<<<<<<<<<<<<< - * j = 0 - * extract_start = monitor_cpu() - */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1063; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_extracts)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_extracts)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); - __pyx_cur_scope->__pyx_v_extracts = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1064 - * chunklen.arr[j] = hiero_phrase.chunklen(j) - * extracts = [] - * j = 0 # <<<<<<<<<<<<<< - * extract_start = monitor_cpu() - * while j < sample.len: - */ - __pyx_cur_scope->__pyx_v_j = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1065 - * extracts = [] - * j = 0 - * extract_start = monitor_cpu() # <<<<<<<<<<<<<< - * while j < sample.len: - * extract = [] - */ - __pyx_t_3 = PyFloat_FromDouble(__pyx_f_8_cdec_sa_monitor_cpu()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_extract_start); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_extract_start); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_v_extract_start = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1066 - * j = 0 - * extract_start = monitor_cpu() - * while j < sample.len: # <<<<<<<<<<<<<< - * extract = [] - * - */ - while (1) { - __pyx_t_19 = (__pyx_cur_scope->__pyx_v_j < __pyx_cur_scope->__pyx_v_sample->len); - if (!__pyx_t_19) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1067 - * extract_start = monitor_cpu() - * while j < sample.len: - * extract = [] # <<<<<<<<<<<<<< - * - * assign_matching(&matching, sample.arr, j, num_subpatterns, self.fda.sent_id.arr) - */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1067; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_extract); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_extract); - __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); - __pyx_cur_scope->__pyx_v_extract = ((PyObject *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1069 - * extract = [] - * - * assign_matching(&matching, sample.arr, j, num_subpatterns, self.fda.sent_id.arr) # <<<<<<<<<<<<<< - * extract = self.extract(hiero_phrase, &matching, chunklen.arr, num_subpatterns) - * extracts.extend(extract) - */ - __pyx_f_8_cdec_sa_assign_matching((&__pyx_cur_scope->__pyx_v_matching), __pyx_cur_scope->__pyx_v_sample->arr, __pyx_cur_scope->__pyx_v_j, __pyx_cur_scope->__pyx_v_num_subpatterns, __pyx_cur_scope->__pyx_v_self->fda->sent_id->arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1070 - * - * assign_matching(&matching, sample.arr, j, num_subpatterns, self.fda.sent_id.arr) - * extract = self.extract(hiero_phrase, &matching, chunklen.arr, num_subpatterns) # <<<<<<<<<<<<<< - * extracts.extend(extract) - * j = j + num_subpatterns - */ - __pyx_t_3 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_cur_scope->__pyx_v_self->__pyx_vtab)->extract(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_hiero_phrase, (&__pyx_cur_scope->__pyx_v_matching), __pyx_cur_scope->__pyx_v_chunklen->arr, __pyx_cur_scope->__pyx_v_num_subpatterns); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_extract); - __Pyx_DECREF(__pyx_cur_scope->__pyx_v_extract); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_v_extract = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1071 - * assign_matching(&matching, sample.arr, j, num_subpatterns, self.fda.sent_id.arr) - * extract = self.extract(hiero_phrase, &matching, chunklen.arr, num_subpatterns) - * extracts.extend(extract) # <<<<<<<<<<<<<< - * j = j + num_subpatterns - * - */ - __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_extracts), __pyx_n_s__extend); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_extract); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_cur_scope->__pyx_v_extract); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_extract); - __pyx_t_9 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1072 - * extract = self.extract(hiero_phrase, &matching, chunklen.arr, num_subpatterns) - * extracts.extend(extract) - * j = j + num_subpatterns # <<<<<<<<<<<<<< - * - * num_samples = sample.len/num_subpatterns - */ - __pyx_cur_scope->__pyx_v_j = (__pyx_cur_scope->__pyx_v_j + __pyx_cur_scope->__pyx_v_num_subpatterns); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1074 - * j = j + num_subpatterns - * - * num_samples = sample.len/num_subpatterns # <<<<<<<<<<<<<< - * extract_stop = monitor_cpu() - * self.extract_time = self.extract_time + extract_stop - extract_start - */ - if (unlikely(__pyx_cur_scope->__pyx_v_num_subpatterns == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1074; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - else if (sizeof(int) == sizeof(long) && unlikely(__pyx_cur_scope->__pyx_v_num_subpatterns == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_cur_scope->__pyx_v_sample->len))) { - PyErr_Format(PyExc_OverflowError, "value too large to perform division"); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1074; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_cur_scope->__pyx_v_num_samples = __Pyx_div_int(__pyx_cur_scope->__pyx_v_sample->len, __pyx_cur_scope->__pyx_v_num_subpatterns); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1075 - * - * num_samples = sample.len/num_subpatterns - * extract_stop = monitor_cpu() # <<<<<<<<<<<<<< - * self.extract_time = self.extract_time + extract_stop - extract_start - * if len(extracts) > 0: - */ - __pyx_t_9 = PyFloat_FromDouble(__pyx_f_8_cdec_sa_monitor_cpu()); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_extract_stop); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_extract_stop); - __Pyx_GIVEREF(__pyx_t_9); - __pyx_cur_scope->__pyx_v_extract_stop = __pyx_t_9; - __pyx_t_9 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1076 - * num_samples = sample.len/num_subpatterns - * extract_stop = monitor_cpu() - * self.extract_time = self.extract_time + extract_stop - extract_start # <<<<<<<<<<<<<< - * if len(extracts) > 0: - * fphrases = {} - */ - __pyx_t_9 = PyFloat_FromDouble(__pyx_cur_scope->__pyx_v_self->extract_time); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = PyNumber_Add(__pyx_t_9, __pyx_cur_scope->__pyx_v_extract_stop); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = PyNumber_Subtract(__pyx_t_10, __pyx_cur_scope->__pyx_v_extract_start); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_20 = __pyx_PyFloat_AsFloat(__pyx_t_9); if (unlikely((__pyx_t_20 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_cur_scope->__pyx_v_self->extract_time = __pyx_t_20; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1077 - * extract_stop = monitor_cpu() - * self.extract_time = self.extract_time + extract_stop - extract_start - * if len(extracts) > 0: # <<<<<<<<<<<<<< - * fphrases = {} - * fals = {} - */ - __pyx_t_5 = PyList_GET_SIZE(((PyObject *)__pyx_cur_scope->__pyx_v_extracts)); - __pyx_t_19 = (__pyx_t_5 > 0); - if (__pyx_t_19) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1078 - * self.extract_time = self.extract_time + extract_stop - extract_start - * if len(extracts) > 0: - * fphrases = {} # <<<<<<<<<<<<<< - * fals = {} - * fcount = {} - */ - __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1078; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_9)); - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); - __pyx_cur_scope->__pyx_v_fphrases = __pyx_t_9; - __pyx_t_9 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1079 - * if len(extracts) > 0: - * fphrases = {} - * fals = {} # <<<<<<<<<<<<<< - * fcount = {} - * for f, e, count, als in extracts: - */ - __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1079; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_9)); - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fals)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fals)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); - __pyx_cur_scope->__pyx_v_fals = __pyx_t_9; - __pyx_t_9 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1080 - * fphrases = {} - * fals = {} - * fcount = {} # <<<<<<<<<<<<<< - * for f, e, count, als in extracts: - * fcount.setdefault(f, 0.0) - */ - __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_9)); - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fcount)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fcount)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); - __pyx_cur_scope->__pyx_v_fcount = __pyx_t_9; - __pyx_t_9 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1081 - * fals = {} - * fcount = {} - * for f, e, count, als in extracts: # <<<<<<<<<<<<<< - * fcount.setdefault(f, 0.0) - * fcount[f] = fcount[f] + count - */ - __pyx_t_9 = ((PyObject *)__pyx_cur_scope->__pyx_v_extracts); __Pyx_INCREF(__pyx_t_9); __pyx_t_5 = 0; - for (;;) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_9)) break; - __pyx_t_10 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_5); __Pyx_INCREF(__pyx_t_10); __pyx_t_5++; - if ((likely(PyTuple_CheckExact(__pyx_t_10))) || (PyList_CheckExact(__pyx_t_10))) { - PyObject* sequence = __pyx_t_10; - if (likely(PyTuple_CheckExact(sequence))) { - if (unlikely(PyTuple_GET_SIZE(sequence) != 4)) { - if (PyTuple_GET_SIZE(sequence) > 4) __Pyx_RaiseTooManyValuesError(4); - else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1081; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_14 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_15 = PyTuple_GET_ITEM(sequence, 2); - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 3); - } else { - if (unlikely(PyList_GET_SIZE(sequence) != 4)) { - if (PyList_GET_SIZE(sequence) > 4) __Pyx_RaiseTooManyValuesError(4); - else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1081; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_3 = PyList_GET_ITEM(sequence, 0); - __pyx_t_14 = PyList_GET_ITEM(sequence, 1); - __pyx_t_15 = PyList_GET_ITEM(sequence, 2); - __pyx_t_2 = PyList_GET_ITEM(sequence, 3); - } - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_14); - __Pyx_INCREF(__pyx_t_15); - __Pyx_INCREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_7 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1081; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_17 = Py_TYPE(__pyx_t_7)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_17(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L48_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 1; __pyx_t_14 = __pyx_t_17(__pyx_t_7); if (unlikely(!__pyx_t_14)) goto __pyx_L48_unpacking_failed; - __Pyx_GOTREF(__pyx_t_14); - index = 2; __pyx_t_15 = __pyx_t_17(__pyx_t_7); if (unlikely(!__pyx_t_15)) goto __pyx_L48_unpacking_failed; - __Pyx_GOTREF(__pyx_t_15); - index = 3; __pyx_t_2 = __pyx_t_17(__pyx_t_7); if (unlikely(!__pyx_t_2)) goto __pyx_L48_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_7), 4) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1081; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L49_unpacking_done; - __pyx_L48_unpacking_failed:; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1081; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L49_unpacking_done:; - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_f); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_f); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_v_f = __pyx_t_3; - __pyx_t_3 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_e); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_e); - __Pyx_GIVEREF(__pyx_t_14); - __pyx_cur_scope->__pyx_v_e = __pyx_t_14; - __pyx_t_14 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_count); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_count); - __Pyx_GIVEREF(__pyx_t_15); - __pyx_cur_scope->__pyx_v_count = __pyx_t_15; - __pyx_t_15 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_als); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_als); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_cur_scope->__pyx_v_als = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1082 - * fcount = {} - * for f, e, count, als in extracts: - * fcount.setdefault(f, 0.0) # <<<<<<<<<<<<<< - * fcount[f] = fcount[f] + count - * fphrases.setdefault(f, {}) - */ - __pyx_t_10 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = __Pyx_PyDict_SetDefault(((PyObject *)__pyx_cur_scope->__pyx_v_fcount), __pyx_cur_scope->__pyx_v_f, __pyx_t_10); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1083 - * for f, e, count, als in extracts: - * fcount.setdefault(f, 0.0) - * fcount[f] = fcount[f] + count # <<<<<<<<<<<<<< - * fphrases.setdefault(f, {}) - * fphrases[f].setdefault(e, {}) - */ - __pyx_t_2 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fcount), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = PyNumber_Add(__pyx_t_2, __pyx_cur_scope->__pyx_v_count); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fcount), __pyx_cur_scope->__pyx_v_f, __pyx_t_10) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1084 - * fcount.setdefault(f, 0.0) - * fcount[f] = fcount[f] + count - * fphrases.setdefault(f, {}) # <<<<<<<<<<<<<< - * fphrases[f].setdefault(e, {}) - * fphrases[f][e].setdefault(als,0.0) - */ - __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_10)); - __pyx_t_2 = __Pyx_PyDict_SetDefault(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases), __pyx_cur_scope->__pyx_v_f, ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1085 - * fcount[f] = fcount[f] + count - * fphrases.setdefault(f, {}) - * fphrases[f].setdefault(e, {}) # <<<<<<<<<<<<<< - * fphrases[f][e].setdefault(als,0.0) - * fphrases[f][e][als] = fphrases[f][e][als] + count - */ - __pyx_t_2 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__setdefault); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_e); - PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_cur_scope->__pyx_v_e); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_e); - PyTuple_SET_ITEM(__pyx_t_15, 1, ((PyObject *)__pyx_t_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1086 - * fphrases.setdefault(f, {}) - * fphrases[f].setdefault(e, {}) - * fphrases[f][e].setdefault(als,0.0) # <<<<<<<<<<<<<< - * fphrases[f][e][als] = fphrases[f][e][als] + count - * for f, elist in fphrases.iteritems(): - */ - __pyx_t_2 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_15 = PyObject_GetItem(__pyx_t_2, __pyx_cur_scope->__pyx_v_e); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_GetAttr(__pyx_t_15, __pyx_n_s__setdefault); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_15 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_als); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_cur_scope->__pyx_v_als); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_als); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_15); - __Pyx_GIVEREF(__pyx_t_15); - __pyx_t_15 = 0; - __pyx_t_15 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1087 - * fphrases[f].setdefault(e, {}) - * fphrases[f][e].setdefault(als,0.0) - * fphrases[f][e][als] = fphrases[f][e][als] + count # <<<<<<<<<<<<<< - * for f, elist in fphrases.iteritems(): - * f_margin = fcount[f] - */ - __pyx_t_15 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_10 = PyObject_GetItem(__pyx_t_15, __pyx_cur_scope->__pyx_v_e); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_15 = PyObject_GetItem(__pyx_t_10, __pyx_cur_scope->__pyx_v_als); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = PyNumber_Add(__pyx_t_15, __pyx_cur_scope->__pyx_v_count); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_15 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_2 = PyObject_GetItem(__pyx_t_15, __pyx_cur_scope->__pyx_v_e); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - if (PyObject_SetItem(__pyx_t_2, __pyx_cur_scope->__pyx_v_als, __pyx_t_10) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1088 - * fphrases[f][e].setdefault(als,0.0) - * fphrases[f][e][als] = fphrases[f][e][als] + count - * for f, elist in fphrases.iteritems(): # <<<<<<<<<<<<<< - * f_margin = fcount[f] - * for e, alslist in elist.iteritems(): - */ - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases)); - __Pyx_XDECREF(__pyx_t_9); - __pyx_t_9 = ((PyObject *)__pyx_cur_scope->__pyx_v_fphrases); - __pyx_t_5 = 0; - __pyx_t_21 = PyDict_Size(__pyx_t_9); - while (1) { - if (unlikely(__pyx_t_21 != PyDict_Size(__pyx_t_9))) { - PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration"); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1088; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - if (!PyDict_Next(__pyx_t_9, (&__pyx_t_5), (&__pyx_t_22), (&__pyx_t_23))) break; - __Pyx_INCREF(((PyObject *)__pyx_t_22)); - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_f); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_f); - __Pyx_GIVEREF(__pyx_t_22); - __pyx_cur_scope->__pyx_v_f = __pyx_t_22; - __Pyx_INCREF(((PyObject *)__pyx_t_23)); - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_elist); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_elist); - __Pyx_GIVEREF(__pyx_t_23); - __pyx_cur_scope->__pyx_v_elist = __pyx_t_23; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1089 - * fphrases[f][e][als] = fphrases[f][e][als] + count - * for f, elist in fphrases.iteritems(): - * f_margin = fcount[f] # <<<<<<<<<<<<<< - * for e, alslist in elist.iteritems(): - * alignment = None - */ - __pyx_t_10 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fcount), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_f_margin); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_f_margin); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_cur_scope->__pyx_v_f_margin = __pyx_t_10; - __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1090 - * for f, elist in fphrases.iteritems(): - * f_margin = fcount[f] - * for e, alslist in elist.iteritems(): # <<<<<<<<<<<<<< - * alignment = None - * count = 0 - */ - __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_elist, __pyx_n_s__iteritems); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) { - __pyx_t_10 = __pyx_t_2; __Pyx_INCREF(__pyx_t_10); __pyx_t_24 = 0; - __pyx_t_25 = NULL; - } else { - __pyx_t_24 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_25 = Py_TYPE(__pyx_t_10)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - for (;;) { - if (!__pyx_t_25 && PyList_CheckExact(__pyx_t_10)) { - if (__pyx_t_24 >= PyList_GET_SIZE(__pyx_t_10)) break; - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_24); __Pyx_INCREF(__pyx_t_2); __pyx_t_24++; - } else if (!__pyx_t_25 && PyTuple_CheckExact(__pyx_t_10)) { - if (__pyx_t_24 >= PyTuple_GET_SIZE(__pyx_t_10)) break; - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_24); __Pyx_INCREF(__pyx_t_2); __pyx_t_24++; - } else { - __pyx_t_2 = __pyx_t_25(__pyx_t_10); - if (unlikely(!__pyx_t_2)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { - PyObject* sequence = __pyx_t_2; - if (likely(PyTuple_CheckExact(sequence))) { - 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[8]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_15 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_14 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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[8]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_15 = PyList_GET_ITEM(sequence, 0); - __pyx_t_14 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_15); - __Pyx_INCREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_17 = Py_TYPE(__pyx_t_3)->tp_iternext; - index = 0; __pyx_t_15 = __pyx_t_17(__pyx_t_3); if (unlikely(!__pyx_t_15)) goto __pyx_L54_unpacking_failed; - __Pyx_GOTREF(__pyx_t_15); - index = 1; __pyx_t_14 = __pyx_t_17(__pyx_t_3); if (unlikely(!__pyx_t_14)) goto __pyx_L54_unpacking_failed; - __Pyx_GOTREF(__pyx_t_14); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_3), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L55_unpacking_done; - __pyx_L54_unpacking_failed:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1090; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L55_unpacking_done:; - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_e); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_e); - __Pyx_GIVEREF(__pyx_t_15); - __pyx_cur_scope->__pyx_v_e = __pyx_t_15; - __pyx_t_15 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_alslist); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_alslist); - __Pyx_GIVEREF(__pyx_t_14); - __pyx_cur_scope->__pyx_v_alslist = __pyx_t_14; - __pyx_t_14 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1091 - * f_margin = fcount[f] - * for e, alslist in elist.iteritems(): - * alignment = None # <<<<<<<<<<<<<< - * count = 0 - * for als, currcount in alslist.iteritems(): - */ - __Pyx_INCREF(Py_None); - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_alignment); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_alignment); - __Pyx_GIVEREF(Py_None); - __pyx_cur_scope->__pyx_v_alignment = Py_None; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1092 - * for e, alslist in elist.iteritems(): - * alignment = None - * count = 0 # <<<<<<<<<<<<<< - * for als, currcount in alslist.iteritems(): - * if currcount > count: - */ - __Pyx_INCREF(__pyx_int_0); - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_count); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_count); - __Pyx_GIVEREF(__pyx_int_0); - __pyx_cur_scope->__pyx_v_count = __pyx_int_0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1093 - * alignment = None - * count = 0 - * for als, currcount in alslist.iteritems(): # <<<<<<<<<<<<<< - * if currcount > count: - * alignment = als - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_alslist, __pyx_n_s__iteritems); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyList_CheckExact(__pyx_t_14) || PyTuple_CheckExact(__pyx_t_14)) { - __pyx_t_2 = __pyx_t_14; __Pyx_INCREF(__pyx_t_2); __pyx_t_26 = 0; - __pyx_t_27 = NULL; - } else { - __pyx_t_26 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_27 = Py_TYPE(__pyx_t_2)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - for (;;) { - if (!__pyx_t_27 && PyList_CheckExact(__pyx_t_2)) { - if (__pyx_t_26 >= PyList_GET_SIZE(__pyx_t_2)) break; - __pyx_t_14 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_26); __Pyx_INCREF(__pyx_t_14); __pyx_t_26++; - } else if (!__pyx_t_27 && PyTuple_CheckExact(__pyx_t_2)) { - if (__pyx_t_26 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - __pyx_t_14 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_26); __Pyx_INCREF(__pyx_t_14); __pyx_t_26++; - } else { - __pyx_t_14 = __pyx_t_27(__pyx_t_2); - if (unlikely(!__pyx_t_14)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_14); - } - if ((likely(PyTuple_CheckExact(__pyx_t_14))) || (PyList_CheckExact(__pyx_t_14))) { - PyObject* sequence = __pyx_t_14; - if (likely(PyTuple_CheckExact(sequence))) { - 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[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_15 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_15 = PyList_GET_ITEM(sequence, 0); - __pyx_t_3 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_15); - __Pyx_INCREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_7 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_17 = Py_TYPE(__pyx_t_7)->tp_iternext; - index = 0; __pyx_t_15 = __pyx_t_17(__pyx_t_7); if (unlikely(!__pyx_t_15)) goto __pyx_L58_unpacking_failed; - __Pyx_GOTREF(__pyx_t_15); - index = 1; __pyx_t_3 = __pyx_t_17(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L58_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L59_unpacking_done; - __pyx_L58_unpacking_failed:; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L59_unpacking_done:; - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_als); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_als); - __Pyx_GIVEREF(__pyx_t_15); - __pyx_cur_scope->__pyx_v_als = __pyx_t_15; - __pyx_t_15 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_currcount); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_currcount); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_v_currcount = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1094 - * count = 0 - * for als, currcount in alslist.iteritems(): - * if currcount > count: # <<<<<<<<<<<<<< - * alignment = als - * count = currcount - */ - __pyx_t_14 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_currcount, __pyx_cur_scope->__pyx_v_count, Py_GT); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1094; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1094; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - if (__pyx_t_19) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1095 - * for als, currcount in alslist.iteritems(): - * if currcount > count: - * alignment = als # <<<<<<<<<<<<<< - * count = currcount - * scores = [] - */ - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_als); - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_alignment); - __Pyx_DECREF(__pyx_cur_scope->__pyx_v_alignment); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_als); - __pyx_cur_scope->__pyx_v_alignment = __pyx_cur_scope->__pyx_v_als; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1096 - * if currcount > count: - * alignment = als - * count = currcount # <<<<<<<<<<<<<< - * scores = [] - * for model in models: - */ - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_currcount); - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_count); - __Pyx_DECREF(__pyx_cur_scope->__pyx_v_count); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_currcount); - __pyx_cur_scope->__pyx_v_count = __pyx_cur_scope->__pyx_v_currcount; - goto __pyx_L60; - } - __pyx_L60:; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1097 - * alignment = als - * count = currcount - * scores = [] # <<<<<<<<<<<<<< - * for model in models: - * scores.append(model(f, e, count, fcount[f], num_samples)) - */ - __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_scores)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_scores)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); - __pyx_cur_scope->__pyx_v_scores = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1098 - * count = currcount - * scores = [] - * for model in models: # <<<<<<<<<<<<<< - * scores.append(model(f, e, count, fcount[f], num_samples)) - * yield Rule(self.category, f, e, - */ - if (PyList_CheckExact(__pyx_cur_scope->__pyx_v_models) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_models)) { - __pyx_t_2 = __pyx_cur_scope->__pyx_v_models; __Pyx_INCREF(__pyx_t_2); __pyx_t_26 = 0; - __pyx_t_27 = NULL; - } else { - __pyx_t_26 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_models); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_27 = Py_TYPE(__pyx_t_2)->tp_iternext; - } - for (;;) { - if (!__pyx_t_27 && PyList_CheckExact(__pyx_t_2)) { - if (__pyx_t_26 >= PyList_GET_SIZE(__pyx_t_2)) break; - __pyx_t_14 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_26); __Pyx_INCREF(__pyx_t_14); __pyx_t_26++; - } else if (!__pyx_t_27 && PyTuple_CheckExact(__pyx_t_2)) { - if (__pyx_t_26 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - __pyx_t_14 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_26); __Pyx_INCREF(__pyx_t_14); __pyx_t_26++; - } else { - __pyx_t_14 = __pyx_t_27(__pyx_t_2); - if (unlikely(!__pyx_t_14)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_14); - } - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_model); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_model); - __Pyx_GIVEREF(__pyx_t_14); - __pyx_cur_scope->__pyx_v_model = __pyx_t_14; - __pyx_t_14 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1099 - * scores = [] - * for model in models: - * scores.append(model(f, e, count, fcount[f], num_samples)) # <<<<<<<<<<<<<< - * yield Rule(self.category, f, e, - * scores=scores, word_alignments=alignment) - */ - __pyx_t_14 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fcount), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_14) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_num_samples); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_15 = PyTuple_New(5); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_f); - PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_cur_scope->__pyx_v_f); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_f); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_e); - PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_cur_scope->__pyx_v_e); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_e); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_count); - PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_cur_scope->__pyx_v_count); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_count); - PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_t_14); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_15, 4, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_14 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_cur_scope->__pyx_v_model, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; - __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_scores, __pyx_t_3); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1100 - * for model in models: - * scores.append(model(f, e, count, fcount[f], num_samples)) - * yield Rule(self.category, f, e, # <<<<<<<<<<<<<< - * scores=scores, word_alignments=alignment) - * - */ - __pyx_t_2 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->category); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_f); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_cur_scope->__pyx_v_f); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_f); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_e); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_cur_scope->__pyx_v_e); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_e); - __pyx_t_2 = 0; - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1101 - * scores.append(model(f, e, count, fcount[f], num_samples)) - * yield Rule(self.category, f, e, - * scores=scores, word_alignments=alignment) # <<<<<<<<<<<<<< - * - * if len(phrase) < self.max_length and i+spanlen < len(fwords) and pathlen+1 <= self.max_initial_size: - */ - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__scores), ((PyObject *)__pyx_cur_scope->__pyx_v_scores)) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__word_alignments), __pyx_cur_scope->__pyx_v_alignment) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_15 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Rule)), ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_r = __pyx_t_15; - __pyx_t_15 = 0; - __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_5; - __Pyx_XGIVEREF(__pyx_t_9); - __pyx_cur_scope->__pyx_t_2 = __pyx_t_9; - __Pyx_XGIVEREF(__pyx_t_10); - __pyx_cur_scope->__pyx_t_3 = __pyx_t_10; - __Pyx_XGIVEREF(__pyx_t_12); - __pyx_cur_scope->__pyx_t_4 = __pyx_t_12; - __pyx_cur_scope->__pyx_t_5 = __pyx_t_21; - __pyx_cur_scope->__pyx_t_6 = __pyx_t_24; - __pyx_cur_scope->__pyx_t_7 = __pyx_t_25; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L63_resume_from_yield:; - __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; - __pyx_t_5 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_9 = __pyx_cur_scope->__pyx_t_2; - __pyx_cur_scope->__pyx_t_2 = 0; - __Pyx_XGOTREF(__pyx_t_9); - __pyx_t_10 = __pyx_cur_scope->__pyx_t_3; - __pyx_cur_scope->__pyx_t_3 = 0; - __Pyx_XGOTREF(__pyx_t_10); - __pyx_t_12 = __pyx_cur_scope->__pyx_t_4; - __pyx_cur_scope->__pyx_t_4 = 0; - __Pyx_XGOTREF(__pyx_t_12); - __pyx_t_21 = __pyx_cur_scope->__pyx_t_5; - __pyx_t_24 = __pyx_cur_scope->__pyx_t_6; - __pyx_t_25 = __pyx_cur_scope->__pyx_t_7; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - goto __pyx_L45; - } - __pyx_L45:; - goto __pyx_L40; - } - __pyx_L40:; - goto __pyx_L32; - } - __pyx_L32:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1103 - * scores=scores, word_alignments=alignment) - * - * if len(phrase) < self.max_length and i+spanlen < len(fwords) and pathlen+1 <= self.max_initial_size: # <<<<<<<<<<<<<< - * for alt_id in range(len(fwords[i+spanlen])): - * new_frontier.append((k, i+spanlen, alt_id, pathlen + 1, node, phrase, is_shadow_path)) - */ - __pyx_t_21 = PyObject_Length(__pyx_cur_scope->__pyx_v_phrase); if (unlikely(__pyx_t_21 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_19 = (__pyx_t_21 < __pyx_cur_scope->__pyx_v_self->max_length); - if (__pyx_t_19) { - __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = PyNumber_Add(__pyx_t_9, __pyx_cur_scope->__pyx_v_spanlen); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_21 = PyObject_Length(__pyx_cur_scope->__pyx_v_fwords); if (unlikely(__pyx_t_21 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_9 = PyInt_FromSsize_t(__pyx_t_21); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_15 = PyObject_RichCompare(__pyx_t_10, __pyx_t_9, Py_LT); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - if (__pyx_t_8) { - __pyx_t_15 = PyNumber_Add(__pyx_cur_scope->__pyx_v_pathlen, __pyx_int_1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->max_initial_size); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_10 = PyObject_RichCompare(__pyx_t_15, __pyx_t_9, Py_LE); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_28 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_28 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_29 = __pyx_t_28; - } else { - __pyx_t_29 = __pyx_t_8; - } - __pyx_t_8 = __pyx_t_29; - } else { - __pyx_t_8 = __pyx_t_19; - } - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1104 - * - * if len(phrase) < self.max_length and i+spanlen < len(fwords) and pathlen+1 <= self.max_initial_size: - * for alt_id in range(len(fwords[i+spanlen])): # <<<<<<<<<<<<<< - * new_frontier.append((k, i+spanlen, alt_id, pathlen + 1, node, phrase, is_shadow_path)) - * num_subpatterns = arity - */ - __pyx_t_10 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_9 = PyNumber_Add(__pyx_t_10, __pyx_cur_scope->__pyx_v_spanlen); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = PyObject_GetItem(__pyx_cur_scope->__pyx_v_fwords, __pyx_t_9); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_21 = PyObject_Length(__pyx_t_10); if (unlikely(__pyx_t_21 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_21; __pyx_t_18+=1) { - __pyx_cur_scope->__pyx_v_alt_id = __pyx_t_18; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1105 - * if len(phrase) < self.max_length and i+spanlen < len(fwords) and pathlen+1 <= self.max_initial_size: - * for alt_id in range(len(fwords[i+spanlen])): - * new_frontier.append((k, i+spanlen, alt_id, pathlen + 1, node, phrase, is_shadow_path)) # <<<<<<<<<<<<<< - * num_subpatterns = arity - * if not is_shadow_path: - */ - __pyx_t_10 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_k); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_15 = PyNumber_Add(__pyx_t_9, __pyx_cur_scope->__pyx_v_spanlen); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_alt_id); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_2 = PyNumber_Add(__pyx_cur_scope->__pyx_v_pathlen, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(7); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_15); - __Pyx_GIVEREF(__pyx_t_15); - PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_node); - PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_cur_scope->__pyx_v_node); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_node); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_phrase); - PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_cur_scope->__pyx_v_phrase); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_phrase); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_is_shadow_path); - PyTuple_SET_ITEM(__pyx_t_3, 6, __pyx_cur_scope->__pyx_v_is_shadow_path); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_is_shadow_path); - __pyx_t_10 = 0; - __pyx_t_15 = 0; - __pyx_t_9 = 0; - __pyx_t_2 = 0; - __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_new_frontier, ((PyObject *)__pyx_t_3)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1106 - * for alt_id in range(len(fwords[i+spanlen])): - * new_frontier.append((k, i+spanlen, alt_id, pathlen + 1, node, phrase, is_shadow_path)) - * num_subpatterns = arity # <<<<<<<<<<<<<< - * if not is_shadow_path: - * num_subpatterns = num_subpatterns + 1 - */ - __pyx_cur_scope->__pyx_v_num_subpatterns = __pyx_cur_scope->__pyx_v_arity; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1107 - * new_frontier.append((k, i+spanlen, alt_id, pathlen + 1, node, phrase, is_shadow_path)) - * num_subpatterns = arity - * if not is_shadow_path: # <<<<<<<<<<<<<< - * num_subpatterns = num_subpatterns + 1 - * if len(phrase)+1 < self.max_length and arity < self.max_nonterminals and num_subpatterns < self.max_chunks: - */ - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_is_shadow_path); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_19 = (!__pyx_t_8); - if (__pyx_t_19) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1108 - * num_subpatterns = arity - * if not is_shadow_path: - * num_subpatterns = num_subpatterns + 1 # <<<<<<<<<<<<<< - * if len(phrase)+1 < self.max_length and arity < self.max_nonterminals and num_subpatterns < self.max_chunks: - * xcat = sym_setindex(self.category, arity+1) - */ - __pyx_cur_scope->__pyx_v_num_subpatterns = (__pyx_cur_scope->__pyx_v_num_subpatterns + 1); - goto __pyx_L67; - } - __pyx_L67:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1109 - * if not is_shadow_path: - * num_subpatterns = num_subpatterns + 1 - * if len(phrase)+1 < self.max_length and arity < self.max_nonterminals and num_subpatterns < self.max_chunks: # <<<<<<<<<<<<<< - * xcat = sym_setindex(self.category, arity+1) - * xnode = node.children[xcat] - */ - __pyx_t_21 = PyObject_Length(__pyx_cur_scope->__pyx_v_phrase); if (unlikely(__pyx_t_21 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_19 = ((__pyx_t_21 + 1) < __pyx_cur_scope->__pyx_v_self->max_length); - if (__pyx_t_19) { - __pyx_t_8 = (__pyx_cur_scope->__pyx_v_arity < __pyx_cur_scope->__pyx_v_self->max_nonterminals); - if (__pyx_t_8) { - __pyx_t_29 = (__pyx_cur_scope->__pyx_v_num_subpatterns < __pyx_cur_scope->__pyx_v_self->max_chunks); - __pyx_t_28 = __pyx_t_29; - } else { - __pyx_t_28 = __pyx_t_8; - } - __pyx_t_8 = __pyx_t_28; - } else { - __pyx_t_8 = __pyx_t_19; - } - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1110 - * num_subpatterns = num_subpatterns + 1 - * if len(phrase)+1 < self.max_length and arity < self.max_nonterminals and num_subpatterns < self.max_chunks: - * xcat = sym_setindex(self.category, arity+1) # <<<<<<<<<<<<<< - * xnode = node.children[xcat] - * # I put spanlen=1 below - */ - __pyx_cur_scope->__pyx_v_xcat = __pyx_f_8_cdec_sa_sym_setindex(__pyx_cur_scope->__pyx_v_self->category, (__pyx_cur_scope->__pyx_v_arity + 1)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1111 - * if len(phrase)+1 < self.max_length and arity < self.max_nonterminals and num_subpatterns < self.max_chunks: - * xcat = sym_setindex(self.category, arity+1) - * xnode = node.children[xcat] # <<<<<<<<<<<<<< - * # I put spanlen=1 below - * key = tuple([self.min_gap_size, i, 1, pathlen]) - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_3, __pyx_cur_scope->__pyx_v_xcat, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_xnode); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_xnode); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_cur_scope->__pyx_v_xnode = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1113 - * xnode = node.children[xcat] - * # I put spanlen=1 below - * key = tuple([self.min_gap_size, i, 1, pathlen]) # <<<<<<<<<<<<<< - * frontier_nodes = [] - * if (key in nodes_isteps_away_buffer): - */ - __pyx_t_2 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->min_gap_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = PyList_New(4); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - PyList_SET_ITEM(__pyx_t_9, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyList_SET_ITEM(__pyx_t_9, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __Pyx_INCREF(__pyx_int_1); - PyList_SET_ITEM(__pyx_t_9, 2, __pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_pathlen); - PyList_SET_ITEM(__pyx_t_9, 3, __pyx_cur_scope->__pyx_v_pathlen); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_pathlen); - __pyx_t_2 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = ((PyObject *)PyList_AsTuple(__pyx_t_9)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_key)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_key)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); - __pyx_cur_scope->__pyx_v_key = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1114 - * # I put spanlen=1 below - * key = tuple([self.min_gap_size, i, 1, pathlen]) - * frontier_nodes = [] # <<<<<<<<<<<<<< - * if (key in nodes_isteps_away_buffer): - * frontier_nodes = nodes_isteps_away_buffer[key] - */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_frontier_nodes); - __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_frontier_nodes); - __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); - __pyx_cur_scope->__pyx_v_frontier_nodes = ((PyObject *)__pyx_t_3); - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1115 - * key = tuple([self.min_gap_size, i, 1, pathlen]) - * frontier_nodes = [] - * if (key in nodes_isteps_away_buffer): # <<<<<<<<<<<<<< - * frontier_nodes = nodes_isteps_away_buffer[key] - * else: - */ - __pyx_t_8 = ((PyDict_Contains(((PyObject *)__pyx_cur_scope->__pyx_v_nodes_isteps_away_buffer), ((PyObject *)__pyx_cur_scope->__pyx_v_key)))); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1116 - * frontier_nodes = [] - * if (key in nodes_isteps_away_buffer): - * frontier_nodes = nodes_isteps_away_buffer[key] # <<<<<<<<<<<<<< - * else: - * frontier_nodes = self.get_all_nodes_isteps_away(self.min_gap_size, i, 1, pathlen, fwords, next_states, reachable_buffer) - */ - __pyx_t_3 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_nodes_isteps_away_buffer), ((PyObject *)__pyx_cur_scope->__pyx_v_key)); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_frontier_nodes); - __Pyx_DECREF(__pyx_cur_scope->__pyx_v_frontier_nodes); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_v_frontier_nodes = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L69; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1118 - * frontier_nodes = nodes_isteps_away_buffer[key] - * else: - * frontier_nodes = self.get_all_nodes_isteps_away(self.min_gap_size, i, 1, pathlen, fwords, next_states, reachable_buffer) # <<<<<<<<<<<<<< - * nodes_isteps_away_buffer[key] = frontier_nodes - * - */ - __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_121); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->min_gap_size); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_2 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_15 = PyTuple_New(7); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_INCREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_int_1); - __Pyx_GIVEREF(__pyx_int_1); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_pathlen); - PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_cur_scope->__pyx_v_pathlen); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_pathlen); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fwords); - PyTuple_SET_ITEM(__pyx_t_15, 4, __pyx_cur_scope->__pyx_v_fwords); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_fwords); - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_next_states)); - PyTuple_SET_ITEM(__pyx_t_15, 5, ((PyObject *)__pyx_cur_scope->__pyx_v_next_states)); - __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_next_states)); - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_reachable_buffer)); - PyTuple_SET_ITEM(__pyx_t_15, 6, ((PyObject *)__pyx_cur_scope->__pyx_v_reachable_buffer)); - __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_reachable_buffer)); - __pyx_t_9 = 0; - __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_frontier_nodes); - __Pyx_DECREF(__pyx_cur_scope->__pyx_v_frontier_nodes); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_cur_scope->__pyx_v_frontier_nodes = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1119 - * else: - * frontier_nodes = self.get_all_nodes_isteps_away(self.min_gap_size, i, 1, pathlen, fwords, next_states, reachable_buffer) - * nodes_isteps_away_buffer[key] = frontier_nodes # <<<<<<<<<<<<<< - * - * for (i, alt, pathlen) in frontier_nodes: - */ - if (PyDict_SetItem(((PyObject *)__pyx_cur_scope->__pyx_v_nodes_isteps_away_buffer), ((PyObject *)__pyx_cur_scope->__pyx_v_key), __pyx_cur_scope->__pyx_v_frontier_nodes) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L69:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1121 - * nodes_isteps_away_buffer[key] = frontier_nodes - * - * for (i, alt, pathlen) in frontier_nodes: # <<<<<<<<<<<<<< - * new_frontier.append((k, i, alt, pathlen, xnode, phrase +(xcat,), is_shadow_path)) - * frontier = new_frontier - */ - if (PyList_CheckExact(__pyx_cur_scope->__pyx_v_frontier_nodes) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_frontier_nodes)) { - __pyx_t_2 = __pyx_cur_scope->__pyx_v_frontier_nodes; __Pyx_INCREF(__pyx_t_2); __pyx_t_21 = 0; - __pyx_t_25 = NULL; - } else { - __pyx_t_21 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_frontier_nodes); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_25 = Py_TYPE(__pyx_t_2)->tp_iternext; - } - for (;;) { - if (!__pyx_t_25 && PyList_CheckExact(__pyx_t_2)) { - if (__pyx_t_21 >= PyList_GET_SIZE(__pyx_t_2)) break; - __pyx_t_15 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_21); __Pyx_INCREF(__pyx_t_15); __pyx_t_21++; - } else if (!__pyx_t_25 && PyTuple_CheckExact(__pyx_t_2)) { - if (__pyx_t_21 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - __pyx_t_15 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_21); __Pyx_INCREF(__pyx_t_15); __pyx_t_21++; - } else { - __pyx_t_15 = __pyx_t_25(__pyx_t_2); - if (unlikely(!__pyx_t_15)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_15); - } - if ((likely(PyTuple_CheckExact(__pyx_t_15))) || (PyList_CheckExact(__pyx_t_15))) { - PyObject* sequence = __pyx_t_15; - if (likely(PyTuple_CheckExact(sequence))) { - if (unlikely(PyTuple_GET_SIZE(sequence) != 3)) { - if (PyTuple_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); - } else { - if (unlikely(PyList_GET_SIZE(sequence) != 3)) { - if (PyList_GET_SIZE(sequence) > 3) __Pyx_RaiseTooManyValuesError(3); - else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_3 = PyList_GET_ITEM(sequence, 0); - __pyx_t_9 = PyList_GET_ITEM(sequence, 1); - __pyx_t_10 = PyList_GET_ITEM(sequence, 2); - } - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_9); - __Pyx_INCREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_14 = PyObject_GetIter(__pyx_t_15); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_17 = Py_TYPE(__pyx_t_14)->tp_iternext; - index = 0; __pyx_t_3 = __pyx_t_17(__pyx_t_14); if (unlikely(!__pyx_t_3)) goto __pyx_L72_unpacking_failed; - __Pyx_GOTREF(__pyx_t_3); - index = 1; __pyx_t_9 = __pyx_t_17(__pyx_t_14); if (unlikely(!__pyx_t_9)) goto __pyx_L72_unpacking_failed; - __Pyx_GOTREF(__pyx_t_9); - index = 2; __pyx_t_10 = __pyx_t_17(__pyx_t_14); if (unlikely(!__pyx_t_10)) goto __pyx_L72_unpacking_failed; - __Pyx_GOTREF(__pyx_t_10); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_14), 3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - goto __pyx_L73_unpacking_done; - __pyx_L72_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[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L73_unpacking_done:; - } - __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_9); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __pyx_cur_scope->__pyx_v_i = __pyx_t_18; - __pyx_cur_scope->__pyx_v_alt = __pyx_t_6; - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_pathlen); - __Pyx_DECREF(__pyx_cur_scope->__pyx_v_pathlen); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_cur_scope->__pyx_v_pathlen = __pyx_t_10; - __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1122 - * - * for (i, alt, pathlen) in frontier_nodes: - * new_frontier.append((k, i, alt, pathlen, xnode, phrase +(xcat,), is_shadow_path)) # <<<<<<<<<<<<<< - * frontier = new_frontier - * - */ - __pyx_t_15 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_k); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_10 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_alt); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_xcat); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Add(__pyx_cur_scope->__pyx_v_phrase, ((PyObject *)__pyx_t_14)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; - __pyx_t_14 = PyTuple_New(7); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_15); - __Pyx_GIVEREF(__pyx_t_15); - PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_9); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_pathlen); - PyTuple_SET_ITEM(__pyx_t_14, 3, __pyx_cur_scope->__pyx_v_pathlen); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_pathlen); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_xnode); - PyTuple_SET_ITEM(__pyx_t_14, 4, __pyx_cur_scope->__pyx_v_xnode); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_xnode); - PyTuple_SET_ITEM(__pyx_t_14, 5, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_is_shadow_path); - PyTuple_SET_ITEM(__pyx_t_14, 6, __pyx_cur_scope->__pyx_v_is_shadow_path); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_is_shadow_path); - __pyx_t_15 = 0; - __pyx_t_10 = 0; - __pyx_t_9 = 0; - __pyx_t_3 = 0; - __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_new_frontier, ((PyObject *)__pyx_t_14)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L68; - } - __pyx_L68:; - goto __pyx_L64; - } - __pyx_L64:; - __pyx_L19_continue:; - } - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1123 - * for (i, alt, pathlen) in frontier_nodes: - * new_frontier.append((k, i, alt, pathlen, xnode, phrase +(xcat,), is_shadow_path)) - * frontier = new_frontier # <<<<<<<<<<<<<< - * - * stop_time = monitor_cpu() - */ - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_new_frontier)); - __Pyx_GOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_frontier)); - __Pyx_DECREF(((PyObject *)__pyx_cur_scope->__pyx_v_frontier)); - __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_new_frontier)); - __pyx_cur_scope->__pyx_v_frontier = __pyx_cur_scope->__pyx_v_new_frontier; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1125 - * frontier = new_frontier - * - * stop_time = monitor_cpu() # <<<<<<<<<<<<<< - * logger.info("Total time for rule lookup, extraction, and scoring = %f seconds", (stop_time - start_time)) - * gc.collect() - */ - __pyx_t_12 = PyFloat_FromDouble(__pyx_f_8_cdec_sa_monitor_cpu()); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_GIVEREF(__pyx_t_12); - __pyx_cur_scope->__pyx_v_stop_time = __pyx_t_12; - __pyx_t_12 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1126 - * - * stop_time = monitor_cpu() - * logger.info("Total time for rule lookup, extraction, and scoring = %f seconds", (stop_time - start_time)) # <<<<<<<<<<<<<< - * gc.collect() - * logger.info(" Extract time = %f seconds", self.extract_time) - */ - __pyx_t_12 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_12, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = PyFloat_FromDouble(__pyx_cur_scope->__pyx_v_start_time); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __pyx_t_14 = PyNumber_Subtract(__pyx_cur_scope->__pyx_v_stop_time, __pyx_t_12); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_122)); - PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)__pyx_kp_s_122)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_122)); - PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_14); - __Pyx_GIVEREF(__pyx_t_14); - __pyx_t_14 = 0; - __pyx_t_14 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1127 - * stop_time = monitor_cpu() - * logger.info("Total time for rule lookup, extraction, and scoring = %f seconds", (stop_time - start_time)) - * gc.collect() # <<<<<<<<<<<<<< - * logger.info(" Extract time = %f seconds", self.extract_time) - * - */ - __pyx_t_14 = __Pyx_GetName(__pyx_m, __pyx_n_s__gc); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_12 = PyObject_GetAttr(__pyx_t_14, __pyx_n_s__collect); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_14 = PyObject_Call(__pyx_t_12, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1128 - * logger.info("Total time for rule lookup, extraction, and scoring = %f seconds", (stop_time - start_time)) - * gc.collect() - * logger.info(" Extract time = %f seconds", self.extract_time) # <<<<<<<<<<<<<< - * - * - */ - __pyx_t_14 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_12 = PyObject_GetAttr(__pyx_t_14, __pyx_n_s__info); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_14 = PyFloat_FromDouble(__pyx_cur_scope->__pyx_v_self->extract_time); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_123)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_123)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_123)); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_14); - __Pyx_GIVEREF(__pyx_t_14); - __pyx_t_14 = 0; - __pyx_t_14 = PyObject_Call(__pyx_t_12, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_XDECREF(__pyx_t_13); - __Pyx_XDECREF(__pyx_t_14); - __Pyx_XDECREF(__pyx_t_15); - __Pyx_XDECREF(__pyx_t_16); - __Pyx_AddTraceback("input", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; - __Pyx_RefNannyFinishContext(); - return NULL; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1131 - * - * - * cdef int find_fixpoint(self, # <<<<<<<<<<<<<< - * int f_low, f_high, - * int* f_links_low, int* f_links_high, - */ - -static int __pyx_f_8_cdec_sa_23HieroCachingRuleFactory_find_fixpoint(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, int __pyx_v_f_low, PyObject *__pyx_v_f_high, int *__pyx_v_f_links_low, int *__pyx_v_f_links_high, int *__pyx_v_e_links_low, int *__pyx_v_e_links_high, int __pyx_v_e_in_low, int __pyx_v_e_in_high, int *__pyx_v_e_low, int *__pyx_v_e_high, int *__pyx_v_f_back_low, int *__pyx_v_f_back_high, int __pyx_v_f_sent_len, int __pyx_v_e_sent_len, int __pyx_v_max_f_len, int __pyx_v_max_e_len, int __pyx_v_min_fx_size, int __pyx_v_min_ex_size, int __pyx_v_max_new_x, int __pyx_v_allow_low_x, int __pyx_v_allow_high_x, int __pyx_v_allow_arbitrary_x, CYTHON_UNUSED int __pyx_v_write_log) { - int __pyx_v_e_low_prev; - int __pyx_v_e_high_prev; - int __pyx_v_f_low_prev; - int __pyx_v_f_high_prev; - int __pyx_v_new_x; - int __pyx_v_new_low_x; - int __pyx_v_new_high_x; - int __pyx_r; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("find_fixpoint", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1146 - * cdef int e_low_prev, e_high_prev, f_low_prev, f_high_prev, new_x, new_low_x, new_high_x - * - * e_low[0] = e_in_low # <<<<<<<<<<<<<< - * e_high[0] = e_in_high - * self.find_projection(f_low, f_high, f_links_low, f_links_high, e_low, e_high) - */ - (__pyx_v_e_low[0]) = __pyx_v_e_in_low; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1147 - * - * e_low[0] = e_in_low - * e_high[0] = e_in_high # <<<<<<<<<<<<<< - * self.find_projection(f_low, f_high, f_links_low, f_links_high, e_low, e_high) - * if e_low[0] == -1: - */ - (__pyx_v_e_high[0]) = __pyx_v_e_in_high; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1148 - * e_low[0] = e_in_low - * e_high[0] = e_in_high - * self.find_projection(f_low, f_high, f_links_low, f_links_high, e_low, e_high) # <<<<<<<<<<<<<< - * if e_low[0] == -1: - * # low-priority corner case: if phrase w is unaligned, - */ - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_f_high); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_projection(__pyx_v_self, __pyx_v_f_low, __pyx_t_1, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_low, __pyx_v_e_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1149 - * e_high[0] = e_in_high - * self.find_projection(f_low, f_high, f_links_low, f_links_high, e_low, e_high) - * if e_low[0] == -1: # <<<<<<<<<<<<<< - * # low-priority corner case: if phrase w is unaligned, - * # but we don't require aligned terminals, then returning - */ - __pyx_t_3 = ((__pyx_v_e_low[0]) == -1); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1155 - * # rule X -> X_1 w X_2 / X_1 X_2. This is probably - * # not worth the bother, though. - * return 0 # <<<<<<<<<<<<<< - * elif e_in_low != -1 and e_low[0] != e_in_low: - * if e_in_low - e_low[0] < min_ex_size: - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L3; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1156 - * # not worth the bother, though. - * return 0 - * elif e_in_low != -1 and e_low[0] != e_in_low: # <<<<<<<<<<<<<< - * if e_in_low - e_low[0] < min_ex_size: - * e_low[0] = e_in_low - min_ex_size - */ - __pyx_t_3 = (__pyx_v_e_in_low != -1); - if (__pyx_t_3) { - __pyx_t_4 = ((__pyx_v_e_low[0]) != __pyx_v_e_in_low); - __pyx_t_5 = __pyx_t_4; - } else { - __pyx_t_5 = __pyx_t_3; - } - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1157 - * return 0 - * elif e_in_low != -1 and e_low[0] != e_in_low: - * if e_in_low - e_low[0] < min_ex_size: # <<<<<<<<<<<<<< - * e_low[0] = e_in_low - min_ex_size - * if e_low[0] < 0: - */ - __pyx_t_5 = ((__pyx_v_e_in_low - (__pyx_v_e_low[0])) < __pyx_v_min_ex_size); - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1158 - * elif e_in_low != -1 and e_low[0] != e_in_low: - * if e_in_low - e_low[0] < min_ex_size: - * e_low[0] = e_in_low - min_ex_size # <<<<<<<<<<<<<< - * if e_low[0] < 0: - * return 0 - */ - (__pyx_v_e_low[0]) = (__pyx_v_e_in_low - __pyx_v_min_ex_size); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1159 - * if e_in_low - e_low[0] < min_ex_size: - * e_low[0] = e_in_low - min_ex_size - * if e_low[0] < 0: # <<<<<<<<<<<<<< - * return 0 - * - */ - __pyx_t_5 = ((__pyx_v_e_low[0]) < 0); - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1160 - * e_low[0] = e_in_low - min_ex_size - * if e_low[0] < 0: - * return 0 # <<<<<<<<<<<<<< - * - * if e_high[0] - e_low[0] > max_e_len: - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L5; - } - __pyx_L5:; - goto __pyx_L4; - } - __pyx_L4:; - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1162 - * return 0 - * - * if e_high[0] - e_low[0] > max_e_len: # <<<<<<<<<<<<<< - * return 0 - * elif e_in_high != -1 and e_high[0] != e_in_high: - */ - __pyx_t_5 = (((__pyx_v_e_high[0]) - (__pyx_v_e_low[0])) > __pyx_v_max_e_len); - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1163 - * - * if e_high[0] - e_low[0] > max_e_len: - * return 0 # <<<<<<<<<<<<<< - * elif e_in_high != -1 and e_high[0] != e_in_high: - * if e_high[0] - e_in_high < min_ex_size: - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L6; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1164 - * if e_high[0] - e_low[0] > max_e_len: - * return 0 - * elif e_in_high != -1 and e_high[0] != e_in_high: # <<<<<<<<<<<<<< - * if e_high[0] - e_in_high < min_ex_size: - * e_high[0] = e_in_high + min_ex_size - */ - __pyx_t_5 = (__pyx_v_e_in_high != -1); - if (__pyx_t_5) { - __pyx_t_3 = ((__pyx_v_e_high[0]) != __pyx_v_e_in_high); - __pyx_t_4 = __pyx_t_3; - } else { - __pyx_t_4 = __pyx_t_5; - } - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1165 - * return 0 - * elif e_in_high != -1 and e_high[0] != e_in_high: - * if e_high[0] - e_in_high < min_ex_size: # <<<<<<<<<<<<<< - * e_high[0] = e_in_high + min_ex_size - * if e_high[0] > e_sent_len: - */ - __pyx_t_4 = (((__pyx_v_e_high[0]) - __pyx_v_e_in_high) < __pyx_v_min_ex_size); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1166 - * elif e_in_high != -1 and e_high[0] != e_in_high: - * if e_high[0] - e_in_high < min_ex_size: - * e_high[0] = e_in_high + min_ex_size # <<<<<<<<<<<<<< - * if e_high[0] > e_sent_len: - * return 0 - */ - (__pyx_v_e_high[0]) = (__pyx_v_e_in_high + __pyx_v_min_ex_size); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1167 - * if e_high[0] - e_in_high < min_ex_size: - * e_high[0] = e_in_high + min_ex_size - * if e_high[0] > e_sent_len: # <<<<<<<<<<<<<< - * return 0 - * - */ - __pyx_t_4 = ((__pyx_v_e_high[0]) > __pyx_v_e_sent_len); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1168 - * e_high[0] = e_in_high + min_ex_size - * if e_high[0] > e_sent_len: - * return 0 # <<<<<<<<<<<<<< - * - * f_back_low[0] = -1 - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L8; - } - __pyx_L8:; - goto __pyx_L7; - } - __pyx_L7:; - goto __pyx_L6; - } - __pyx_L6:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1170 - * return 0 - * - * f_back_low[0] = -1 # <<<<<<<<<<<<<< - * f_back_high[0] = -1 - * f_low_prev = f_low - */ - (__pyx_v_f_back_low[0]) = -1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1171 - * - * f_back_low[0] = -1 - * f_back_high[0] = -1 # <<<<<<<<<<<<<< - * f_low_prev = f_low - * f_high_prev = f_high - */ - (__pyx_v_f_back_high[0]) = -1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1172 - * f_back_low[0] = -1 - * f_back_high[0] = -1 - * f_low_prev = f_low # <<<<<<<<<<<<<< - * f_high_prev = f_high - * new_x = 0 - */ - __pyx_v_f_low_prev = __pyx_v_f_low; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1173 - * f_back_high[0] = -1 - * f_low_prev = f_low - * f_high_prev = f_high # <<<<<<<<<<<<<< - * new_x = 0 - * new_low_x = 0 - */ - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_f_high); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_f_high_prev = __pyx_t_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1174 - * f_low_prev = f_low - * f_high_prev = f_high - * new_x = 0 # <<<<<<<<<<<<<< - * new_low_x = 0 - * new_high_x = 0 - */ - __pyx_v_new_x = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1175 - * f_high_prev = f_high - * new_x = 0 - * new_low_x = 0 # <<<<<<<<<<<<<< - * new_high_x = 0 - * - */ - __pyx_v_new_low_x = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1176 - * new_x = 0 - * new_low_x = 0 - * new_high_x = 0 # <<<<<<<<<<<<<< - * - * while True: - */ - __pyx_v_new_high_x = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1178 - * new_high_x = 0 - * - * while True: # <<<<<<<<<<<<<< - * - * if f_back_low[0] == -1: - */ - while (1) { - if (!1) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1180 - * while True: - * - * if f_back_low[0] == -1: # <<<<<<<<<<<<<< - * self.find_projection(e_low[0], e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) - * else: - */ - __pyx_t_4 = ((__pyx_v_f_back_low[0]) == -1); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1181 - * - * if f_back_low[0] == -1: - * self.find_projection(e_low[0], e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) # <<<<<<<<<<<<<< - * else: - * self.find_projection(e_low[0], e_low_prev, e_links_low, e_links_high, f_back_low, f_back_high) - */ - __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_projection(__pyx_v_self, (__pyx_v_e_low[0]), (__pyx_v_e_high[0]), __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_f_back_low, __pyx_v_f_back_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L11; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1183 - * self.find_projection(e_low[0], e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) - * else: - * self.find_projection(e_low[0], e_low_prev, e_links_low, e_links_high, f_back_low, f_back_high) # <<<<<<<<<<<<<< - * self.find_projection(e_high_prev, e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) - * - */ - __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_projection(__pyx_v_self, (__pyx_v_e_low[0]), __pyx_v_e_low_prev, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_f_back_low, __pyx_v_f_back_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1184 - * else: - * self.find_projection(e_low[0], e_low_prev, e_links_low, e_links_high, f_back_low, f_back_high) - * self.find_projection(e_high_prev, e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) # <<<<<<<<<<<<<< - * - * if f_back_low[0] > f_low: - */ - __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_projection(__pyx_v_self, __pyx_v_e_high_prev, (__pyx_v_e_high[0]), __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_f_back_low, __pyx_v_f_back_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1184; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - } - __pyx_L11:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1186 - * self.find_projection(e_high_prev, e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) - * - * if f_back_low[0] > f_low: # <<<<<<<<<<<<<< - * f_back_low[0] = f_low - * - */ - __pyx_t_4 = ((__pyx_v_f_back_low[0]) > __pyx_v_f_low); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1187 - * - * if f_back_low[0] > f_low: - * f_back_low[0] = f_low # <<<<<<<<<<<<<< - * - * if f_back_high[0] < f_high: - */ - (__pyx_v_f_back_low[0]) = __pyx_v_f_low; - goto __pyx_L12; - } - __pyx_L12:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1189 - * f_back_low[0] = f_low - * - * if f_back_high[0] < f_high: # <<<<<<<<<<<<<< - * f_back_high[0] = f_high - * - */ - __pyx_t_2 = PyInt_FromLong((__pyx_v_f_back_high[0])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1189; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = PyObject_RichCompare(__pyx_t_2, __pyx_v_f_high, Py_LT); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1189; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1189; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1190 - * - * if f_back_high[0] < f_high: - * f_back_high[0] = f_high # <<<<<<<<<<<<<< - * - * if f_back_low[0] == f_low_prev and f_back_high[0] == f_high_prev: - */ - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_f_high); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - (__pyx_v_f_back_high[0]) = __pyx_t_1; - goto __pyx_L13; - } - __pyx_L13:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1192 - * f_back_high[0] = f_high - * - * if f_back_low[0] == f_low_prev and f_back_high[0] == f_high_prev: # <<<<<<<<<<<<<< - * return 1 - * - */ - __pyx_t_4 = ((__pyx_v_f_back_low[0]) == __pyx_v_f_low_prev); - if (__pyx_t_4) { - __pyx_t_5 = ((__pyx_v_f_back_high[0]) == __pyx_v_f_high_prev); - __pyx_t_3 = __pyx_t_5; - } else { - __pyx_t_3 = __pyx_t_4; - } - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1193 - * - * if f_back_low[0] == f_low_prev and f_back_high[0] == f_high_prev: - * return 1 # <<<<<<<<<<<<<< - * - * if allow_low_x == 0 and f_back_low[0] < f_low: - */ - __pyx_r = 1; - goto __pyx_L0; - goto __pyx_L14; - } - __pyx_L14:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1195 - * return 1 - * - * if allow_low_x == 0 and f_back_low[0] < f_low: # <<<<<<<<<<<<<< - * # FAIL: f phrase is not tight - * return 0 - */ - __pyx_t_3 = (__pyx_v_allow_low_x == 0); - if (__pyx_t_3) { - __pyx_t_4 = ((__pyx_v_f_back_low[0]) < __pyx_v_f_low); - __pyx_t_5 = __pyx_t_4; - } else { - __pyx_t_5 = __pyx_t_3; - } - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1197 - * if allow_low_x == 0 and f_back_low[0] < f_low: - * # FAIL: f phrase is not tight - * return 0 # <<<<<<<<<<<<<< - * - * if f_back_high[0] - f_back_low[0] > max_f_len: - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L15; - } - __pyx_L15:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1199 - * return 0 - * - * if f_back_high[0] - f_back_low[0] > max_f_len: # <<<<<<<<<<<<<< - * # FAIL: f back projection is too wide - * return 0 - */ - __pyx_t_5 = (((__pyx_v_f_back_high[0]) - (__pyx_v_f_back_low[0])) > __pyx_v_max_f_len); - if (__pyx_t_5) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1201 - * if f_back_high[0] - f_back_low[0] > max_f_len: - * # FAIL: f back projection is too wide - * return 0 # <<<<<<<<<<<<<< - * - * if allow_high_x == 0 and f_back_high[0] > f_high: - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L16; - } - __pyx_L16:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1203 - * return 0 - * - * if allow_high_x == 0 and f_back_high[0] > f_high: # <<<<<<<<<<<<<< - * # FAIL: extension on high side not allowed - * return 0 - */ - __pyx_t_5 = (__pyx_v_allow_high_x == 0); - if (__pyx_t_5) { - __pyx_t_6 = PyInt_FromLong((__pyx_v_f_back_high[0])); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = PyObject_RichCompare(__pyx_t_6, __pyx_v_f_high, Py_GT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_4 = __pyx_t_3; - } else { - __pyx_t_4 = __pyx_t_5; - } - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1205 - * if allow_high_x == 0 and f_back_high[0] > f_high: - * # FAIL: extension on high side not allowed - * return 0 # <<<<<<<<<<<<<< - * - * if f_low != f_back_low[0]: - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L17; - } - __pyx_L17:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1207 - * return 0 - * - * if f_low != f_back_low[0]: # <<<<<<<<<<<<<< - * if new_low_x == 0: - * if new_x >= max_new_x: - */ - __pyx_t_4 = (__pyx_v_f_low != (__pyx_v_f_back_low[0])); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1208 - * - * if f_low != f_back_low[0]: - * if new_low_x == 0: # <<<<<<<<<<<<<< - * if new_x >= max_new_x: - * # FAIL: extension required on low side violates max # of gaps - */ - __pyx_t_4 = (__pyx_v_new_low_x == 0); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1209 - * if f_low != f_back_low[0]: - * if new_low_x == 0: - * if new_x >= max_new_x: # <<<<<<<<<<<<<< - * # FAIL: extension required on low side violates max # of gaps - * return 0 - */ - __pyx_t_4 = (__pyx_v_new_x >= __pyx_v_max_new_x); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1211 - * if new_x >= max_new_x: - * # FAIL: extension required on low side violates max # of gaps - * return 0 # <<<<<<<<<<<<<< - * else: - * new_x = new_x + 1 - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L20; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1213 - * return 0 - * else: - * new_x = new_x + 1 # <<<<<<<<<<<<<< - * new_low_x = 1 - * if f_low - f_back_low[0] < min_fx_size: - */ - __pyx_v_new_x = (__pyx_v_new_x + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1214 - * else: - * new_x = new_x + 1 - * new_low_x = 1 # <<<<<<<<<<<<<< - * if f_low - f_back_low[0] < min_fx_size: - * f_back_low[0] = f_low - min_fx_size - */ - __pyx_v_new_low_x = 1; - } - __pyx_L20:; - goto __pyx_L19; - } - __pyx_L19:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1215 - * new_x = new_x + 1 - * new_low_x = 1 - * if f_low - f_back_low[0] < min_fx_size: # <<<<<<<<<<<<<< - * f_back_low[0] = f_low - min_fx_size - * if f_back_high[0] - f_back_low[0] > max_f_len: - */ - __pyx_t_4 = ((__pyx_v_f_low - (__pyx_v_f_back_low[0])) < __pyx_v_min_fx_size); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1216 - * new_low_x = 1 - * if f_low - f_back_low[0] < min_fx_size: - * f_back_low[0] = f_low - min_fx_size # <<<<<<<<<<<<<< - * if f_back_high[0] - f_back_low[0] > max_f_len: - * # FAIL: extension required on low side violates max initial length - */ - (__pyx_v_f_back_low[0]) = (__pyx_v_f_low - __pyx_v_min_fx_size); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1217 - * if f_low - f_back_low[0] < min_fx_size: - * f_back_low[0] = f_low - min_fx_size - * if f_back_high[0] - f_back_low[0] > max_f_len: # <<<<<<<<<<<<<< - * # FAIL: extension required on low side violates max initial length - * return 0 - */ - __pyx_t_4 = (((__pyx_v_f_back_high[0]) - (__pyx_v_f_back_low[0])) > __pyx_v_max_f_len); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1219 - * if f_back_high[0] - f_back_low[0] > max_f_len: - * # FAIL: extension required on low side violates max initial length - * return 0 # <<<<<<<<<<<<<< - * if f_back_low[0] < 0: - * # FAIL: extension required on low side violates sentence boundary - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L22; - } - __pyx_L22:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1220 - * # FAIL: extension required on low side violates max initial length - * return 0 - * if f_back_low[0] < 0: # <<<<<<<<<<<<<< - * # FAIL: extension required on low side violates sentence boundary - * return 0 - */ - __pyx_t_4 = ((__pyx_v_f_back_low[0]) < 0); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1222 - * if f_back_low[0] < 0: - * # FAIL: extension required on low side violates sentence boundary - * return 0 # <<<<<<<<<<<<<< - * - * if f_high != f_back_high[0]: - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L23; - } - __pyx_L23:; - goto __pyx_L21; - } - __pyx_L21:; - goto __pyx_L18; - } - __pyx_L18:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1224 - * return 0 - * - * if f_high != f_back_high[0]: # <<<<<<<<<<<<<< - * if new_high_x == 0: - * if new_x >= max_new_x: - */ - __pyx_t_2 = PyInt_FromLong((__pyx_v_f_back_high[0])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = PyObject_RichCompare(__pyx_v_f_high, __pyx_t_2, Py_NE); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1224; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1225 - * - * if f_high != f_back_high[0]: - * if new_high_x == 0: # <<<<<<<<<<<<<< - * if new_x >= max_new_x: - * # FAIL: extension required on high side violates max # of gaps - */ - __pyx_t_4 = (__pyx_v_new_high_x == 0); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1226 - * if f_high != f_back_high[0]: - * if new_high_x == 0: - * if new_x >= max_new_x: # <<<<<<<<<<<<<< - * # FAIL: extension required on high side violates max # of gaps - * return 0 - */ - __pyx_t_4 = (__pyx_v_new_x >= __pyx_v_max_new_x); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1228 - * if new_x >= max_new_x: - * # FAIL: extension required on high side violates max # of gaps - * return 0 # <<<<<<<<<<<<<< - * else: - * new_x = new_x + 1 - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L26; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1230 - * return 0 - * else: - * new_x = new_x + 1 # <<<<<<<<<<<<<< - * new_high_x = 1 - * if f_back_high[0] - f_high < min_fx_size: - */ - __pyx_v_new_x = (__pyx_v_new_x + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1231 - * else: - * new_x = new_x + 1 - * new_high_x = 1 # <<<<<<<<<<<<<< - * if f_back_high[0] - f_high < min_fx_size: - * f_back_high[0] = f_high + min_fx_size - */ - __pyx_v_new_high_x = 1; - } - __pyx_L26:; - goto __pyx_L25; - } - __pyx_L25:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1232 - * new_x = new_x + 1 - * new_high_x = 1 - * if f_back_high[0] - f_high < min_fx_size: # <<<<<<<<<<<<<< - * f_back_high[0] = f_high + min_fx_size - * if f_back_high[0] - f_back_low[0] > max_f_len: - */ - __pyx_t_6 = PyInt_FromLong((__pyx_v_f_back_high[0])); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = PyNumber_Subtract(__pyx_t_6, __pyx_v_f_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = PyInt_FromLong(__pyx_v_min_fx_size); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = PyObject_RichCompare(__pyx_t_2, __pyx_t_6, Py_LT); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1233 - * new_high_x = 1 - * if f_back_high[0] - f_high < min_fx_size: - * f_back_high[0] = f_high + min_fx_size # <<<<<<<<<<<<<< - * if f_back_high[0] - f_back_low[0] > max_f_len: - * # FAIL: extension required on high side violates max initial length - */ - __pyx_t_7 = PyInt_FromLong(__pyx_v_min_fx_size); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1233; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = PyNumber_Add(__pyx_v_f_high, __pyx_t_7); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1233; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1233; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - (__pyx_v_f_back_high[0]) = __pyx_t_1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1234 - * if f_back_high[0] - f_high < min_fx_size: - * f_back_high[0] = f_high + min_fx_size - * if f_back_high[0] - f_back_low[0] > max_f_len: # <<<<<<<<<<<<<< - * # FAIL: extension required on high side violates max initial length - * return 0 - */ - __pyx_t_4 = (((__pyx_v_f_back_high[0]) - (__pyx_v_f_back_low[0])) > __pyx_v_max_f_len); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1236 - * if f_back_high[0] - f_back_low[0] > max_f_len: - * # FAIL: extension required on high side violates max initial length - * return 0 # <<<<<<<<<<<<<< - * if f_back_high[0] > f_sent_len: - * # FAIL: extension required on high side violates sentence boundary - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L28; - } - __pyx_L28:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1237 - * # FAIL: extension required on high side violates max initial length - * return 0 - * if f_back_high[0] > f_sent_len: # <<<<<<<<<<<<<< - * # FAIL: extension required on high side violates sentence boundary - * return 0 - */ - __pyx_t_4 = ((__pyx_v_f_back_high[0]) > __pyx_v_f_sent_len); - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1239 - * if f_back_high[0] > f_sent_len: - * # FAIL: extension required on high side violates sentence boundary - * return 0 # <<<<<<<<<<<<<< - * - * e_low_prev = e_low[0] - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L29; - } - __pyx_L29:; - goto __pyx_L27; - } - __pyx_L27:; - goto __pyx_L24; - } - __pyx_L24:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1241 - * return 0 - * - * e_low_prev = e_low[0] # <<<<<<<<<<<<<< - * e_high_prev = e_high[0] - * - */ - __pyx_v_e_low_prev = (__pyx_v_e_low[0]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1242 - * - * e_low_prev = e_low[0] - * e_high_prev = e_high[0] # <<<<<<<<<<<<<< - * - * self.find_projection(f_back_low[0], f_low_prev, f_links_low, f_links_high, e_low, e_high) - */ - __pyx_v_e_high_prev = (__pyx_v_e_high[0]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1244 - * e_high_prev = e_high[0] - * - * self.find_projection(f_back_low[0], f_low_prev, f_links_low, f_links_high, e_low, e_high) # <<<<<<<<<<<<<< - * self.find_projection(f_high_prev, f_back_high[0], f_links_low, f_links_high, e_low, e_high) - * if e_low[0] == e_low_prev and e_high[0] == e_high_prev: - */ - __pyx_t_6 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_projection(__pyx_v_self, (__pyx_v_f_back_low[0]), __pyx_v_f_low_prev, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_low, __pyx_v_e_high); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1245 - * - * self.find_projection(f_back_low[0], f_low_prev, f_links_low, f_links_high, e_low, e_high) - * self.find_projection(f_high_prev, f_back_high[0], f_links_low, f_links_high, e_low, e_high) # <<<<<<<<<<<<<< - * if e_low[0] == e_low_prev and e_high[0] == e_high_prev: - * return 1 - */ - __pyx_t_6 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_projection(__pyx_v_self, __pyx_v_f_high_prev, (__pyx_v_f_back_high[0]), __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_low, __pyx_v_e_high); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1245; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1246 - * self.find_projection(f_back_low[0], f_low_prev, f_links_low, f_links_high, e_low, e_high) - * self.find_projection(f_high_prev, f_back_high[0], f_links_low, f_links_high, e_low, e_high) - * if e_low[0] == e_low_prev and e_high[0] == e_high_prev: # <<<<<<<<<<<<<< - * return 1 - * if allow_arbitrary_x == 0: - */ - __pyx_t_4 = ((__pyx_v_e_low[0]) == __pyx_v_e_low_prev); - if (__pyx_t_4) { - __pyx_t_5 = ((__pyx_v_e_high[0]) == __pyx_v_e_high_prev); - __pyx_t_3 = __pyx_t_5; - } else { - __pyx_t_3 = __pyx_t_4; - } - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1247 - * self.find_projection(f_high_prev, f_back_high[0], f_links_low, f_links_high, e_low, e_high) - * if e_low[0] == e_low_prev and e_high[0] == e_high_prev: - * return 1 # <<<<<<<<<<<<<< - * if allow_arbitrary_x == 0: - * # FAIL: arbitrary expansion not permitted - */ - __pyx_r = 1; - goto __pyx_L0; - goto __pyx_L30; - } - __pyx_L30:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1248 - * if e_low[0] == e_low_prev and e_high[0] == e_high_prev: - * return 1 - * if allow_arbitrary_x == 0: # <<<<<<<<<<<<<< - * # FAIL: arbitrary expansion not permitted - * return 0 - */ - __pyx_t_3 = (__pyx_v_allow_arbitrary_x == 0); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1250 - * if allow_arbitrary_x == 0: - * # FAIL: arbitrary expansion not permitted - * return 0 # <<<<<<<<<<<<<< - * if e_high[0] - e_low[0] > max_e_len: - * # FAIL: re-projection violates sentence max phrase length - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L31; - } - __pyx_L31:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1251 - * # FAIL: arbitrary expansion not permitted - * return 0 - * if e_high[0] - e_low[0] > max_e_len: # <<<<<<<<<<<<<< - * # FAIL: re-projection violates sentence max phrase length - * return 0 - */ - __pyx_t_3 = (((__pyx_v_e_high[0]) - (__pyx_v_e_low[0])) > __pyx_v_max_e_len); - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1253 - * if e_high[0] - e_low[0] > max_e_len: - * # FAIL: re-projection violates sentence max phrase length - * return 0 # <<<<<<<<<<<<<< - * f_low_prev = f_back_low[0] - * f_high_prev = f_back_high[0] - */ - __pyx_r = 0; - goto __pyx_L0; - goto __pyx_L32; - } - __pyx_L32:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1254 - * # FAIL: re-projection violates sentence max phrase length - * return 0 - * f_low_prev = f_back_low[0] # <<<<<<<<<<<<<< - * f_high_prev = f_back_high[0] - * - */ - __pyx_v_f_low_prev = (__pyx_v_f_back_low[0]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1255 - * return 0 - * f_low_prev = f_back_low[0] - * f_high_prev = f_back_high[0] # <<<<<<<<<<<<<< - * - * - */ - __pyx_v_f_high_prev = (__pyx_v_f_back_high[0]); - } - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_WriteUnraisable("_cdec_sa.HieroCachingRuleFactory.find_fixpoint", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1258 - * - * - * cdef find_projection(self, int in_low, int in_high, int* in_links_low, int* in_links_high, # <<<<<<<<<<<<<< - * int* out_low, int* out_high): - * cdef int i - */ - -static PyObject *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_find_projection(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, int __pyx_v_in_low, int __pyx_v_in_high, int *__pyx_v_in_links_low, int *__pyx_v_in_links_high, int *__pyx_v_out_low, int *__pyx_v_out_high) { - int __pyx_v_i; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_t_1; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - __Pyx_RefNannySetupContext("find_projection", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1261 - * int* out_low, int* out_high): - * cdef int i - * for i from in_low <= i < in_high: # <<<<<<<<<<<<<< - * if in_links_low[i] != -1: - * if out_low[0] == -1 or in_links_low[i] < out_low[0]: - */ - __pyx_t_1 = __pyx_v_in_high; - for (__pyx_v_i = __pyx_v_in_low; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1262 - * cdef int i - * for i from in_low <= i < in_high: - * if in_links_low[i] != -1: # <<<<<<<<<<<<<< - * if out_low[0] == -1 or in_links_low[i] < out_low[0]: - * out_low[0] = in_links_low[i] - */ - __pyx_t_2 = ((__pyx_v_in_links_low[__pyx_v_i]) != -1); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1263 - * for i from in_low <= i < in_high: - * if in_links_low[i] != -1: - * if out_low[0] == -1 or in_links_low[i] < out_low[0]: # <<<<<<<<<<<<<< - * out_low[0] = in_links_low[i] - * if out_high[0] == -1 or in_links_high[i] > out_high[0]: - */ - __pyx_t_2 = ((__pyx_v_out_low[0]) == -1); - if (!__pyx_t_2) { - __pyx_t_3 = ((__pyx_v_in_links_low[__pyx_v_i]) < (__pyx_v_out_low[0])); - __pyx_t_4 = __pyx_t_3; - } else { - __pyx_t_4 = __pyx_t_2; - } - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1264 - * if in_links_low[i] != -1: - * if out_low[0] == -1 or in_links_low[i] < out_low[0]: - * out_low[0] = in_links_low[i] # <<<<<<<<<<<<<< - * if out_high[0] == -1 or in_links_high[i] > out_high[0]: - * out_high[0] = in_links_high[i] - */ - (__pyx_v_out_low[0]) = (__pyx_v_in_links_low[__pyx_v_i]); - goto __pyx_L6; - } - __pyx_L6:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1265 - * if out_low[0] == -1 or in_links_low[i] < out_low[0]: - * out_low[0] = in_links_low[i] - * if out_high[0] == -1 or in_links_high[i] > out_high[0]: # <<<<<<<<<<<<<< - * out_high[0] = in_links_high[i] - * - */ - __pyx_t_4 = ((__pyx_v_out_high[0]) == -1); - if (!__pyx_t_4) { - __pyx_t_2 = ((__pyx_v_in_links_high[__pyx_v_i]) > (__pyx_v_out_high[0])); - __pyx_t_3 = __pyx_t_2; - } else { - __pyx_t_3 = __pyx_t_4; - } - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1266 - * out_low[0] = in_links_low[i] - * if out_high[0] == -1 or in_links_high[i] > out_high[0]: - * out_high[0] = in_links_high[i] # <<<<<<<<<<<<<< - * - * - */ - (__pyx_v_out_high[0]) = (__pyx_v_in_links_high[__pyx_v_i]); - goto __pyx_L7; - } - __pyx_L7:; - goto __pyx_L5; - } - __pyx_L5:; - } - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1269 - * - * - * cdef int* int_arr_extend(self, int* arr, int* arr_len, int* data, int data_len): # <<<<<<<<<<<<<< - * cdef int new_len - * new_len = arr_len[0] + data_len - */ - -static int *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_int_arr_extend(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, int *__pyx_v_arr, int *__pyx_v_arr_len, int *__pyx_v_data, int __pyx_v_data_len) { - int __pyx_v_new_len; - int *__pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("int_arr_extend", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1271 - * cdef int* int_arr_extend(self, int* arr, int* arr_len, int* data, int data_len): - * cdef int new_len - * new_len = arr_len[0] + data_len # <<<<<<<<<<<<<< - * arr = realloc(arr, new_len*sizeof(int)) - * memcpy(arr+arr_len[0], data, data_len*sizeof(int)) - */ - __pyx_v_new_len = ((__pyx_v_arr_len[0]) + __pyx_v_data_len); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1272 - * cdef int new_len - * new_len = arr_len[0] + data_len - * arr = realloc(arr, new_len*sizeof(int)) # <<<<<<<<<<<<<< - * memcpy(arr+arr_len[0], data, data_len*sizeof(int)) - * arr_len[0] = new_len - */ - __pyx_v_arr = ((int *)realloc(__pyx_v_arr, (__pyx_v_new_len * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1273 - * new_len = arr_len[0] + data_len - * arr = realloc(arr, new_len*sizeof(int)) - * memcpy(arr+arr_len[0], data, data_len*sizeof(int)) # <<<<<<<<<<<<<< - * arr_len[0] = new_len - * return arr - */ - memcpy((__pyx_v_arr + (__pyx_v_arr_len[0])), __pyx_v_data, (__pyx_v_data_len * (sizeof(int)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1274 - * arr = realloc(arr, new_len*sizeof(int)) - * memcpy(arr+arr_len[0], data, data_len*sizeof(int)) - * arr_len[0] = new_len # <<<<<<<<<<<<<< - * return arr - * - */ - (__pyx_v_arr_len[0]) = __pyx_v_new_len; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1275 - * memcpy(arr+arr_len[0], data, data_len*sizeof(int)) - * arr_len[0] = new_len - * return arr # <<<<<<<<<<<<<< - * - * - */ - __pyx_r = __pyx_v_arr; - goto __pyx_L0; - - __pyx_r = 0; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1278 - * - * - * cdef extract_phrases(self, int e_low, int e_high, int* e_gap_low, int* e_gap_high, int* e_links_low, int num_gaps, # <<<<<<<<<<<<<< - * int f_low, int f_high, int* f_gap_low, int* f_gap_high, int* f_links_low, - * int sent_id, int e_sent_len, int e_sent_start): - */ - -static PyObject *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_extract_phrases(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, int __pyx_v_e_low, int __pyx_v_e_high, int *__pyx_v_e_gap_low, int *__pyx_v_e_gap_high, int *__pyx_v_e_links_low, int __pyx_v_num_gaps, CYTHON_UNUSED int __pyx_v_f_low, CYTHON_UNUSED int __pyx_v_f_high, CYTHON_UNUSED int *__pyx_v_f_gap_low, CYTHON_UNUSED int *__pyx_v_f_gap_high, CYTHON_UNUSED int *__pyx_v_f_links_low, CYTHON_UNUSED int __pyx_v_sent_id, int __pyx_v_e_sent_len, int __pyx_v_e_sent_start) { - int __pyx_v_i; - int __pyx_v_j; - int __pyx_v_k; - int __pyx_v_m; - int __pyx_v_n; - int *__pyx_v_e_gap_order; - int __pyx_v_e_x_low; - int __pyx_v_e_x_high; - int __pyx_v_e_x_gap_low; - int __pyx_v_e_x_gap_high; - int *__pyx_v_e_gaps1; - int *__pyx_v_e_gaps2; - int __pyx_v_len1; - int __pyx_v_len2; - int __pyx_v_step; - int __pyx_v_num_chunks; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_ephr_arr = 0; - PyObject *__pyx_v_result = 0; - PyObject *__pyx_v_indexes = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - long __pyx_t_9; - int __pyx_t_10; - PyObject *__pyx_t_11 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("extract_phrases", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1286 - * cdef result - * - * result = [] # <<<<<<<<<<<<<< - * len1 = 0 - * e_gaps1 = malloc(0) - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1286; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_result = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1287 - * - * result = [] - * len1 = 0 # <<<<<<<<<<<<<< - * e_gaps1 = malloc(0) - * ephr_arr = IntList() - */ - __pyx_v_len1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1288 - * result = [] - * len1 = 0 - * e_gaps1 = malloc(0) # <<<<<<<<<<<<<< - * ephr_arr = IntList() - * - */ - __pyx_v_e_gaps1 = ((int *)malloc(0)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1289 - * len1 = 0 - * e_gaps1 = malloc(0) - * ephr_arr = IntList() # <<<<<<<<<<<<<< - * - * e_gap_order = malloc(num_gaps*sizeof(int)) - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1289; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_ephr_arr = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1291 - * ephr_arr = IntList() - * - * e_gap_order = malloc(num_gaps*sizeof(int)) # <<<<<<<<<<<<<< - * if num_gaps > 0: - * e_gap_order[0] = 0 - */ - __pyx_v_e_gap_order = ((int *)malloc((__pyx_v_num_gaps * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1292 - * - * e_gap_order = malloc(num_gaps*sizeof(int)) - * if num_gaps > 0: # <<<<<<<<<<<<<< - * e_gap_order[0] = 0 - * for i from 1 <= i < num_gaps: - */ - __pyx_t_2 = (__pyx_v_num_gaps > 0); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1293 - * e_gap_order = malloc(num_gaps*sizeof(int)) - * if num_gaps > 0: - * e_gap_order[0] = 0 # <<<<<<<<<<<<<< - * for i from 1 <= i < num_gaps: - * for j from 0 <= j < i: - */ - (__pyx_v_e_gap_order[0]) = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1294 - * if num_gaps > 0: - * e_gap_order[0] = 0 - * for i from 1 <= i < num_gaps: # <<<<<<<<<<<<<< - * for j from 0 <= j < i: - * if e_gap_low[i] < e_gap_low[j]: - */ - __pyx_t_3 = __pyx_v_num_gaps; - for (__pyx_v_i = 1; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1295 - * e_gap_order[0] = 0 - * for i from 1 <= i < num_gaps: - * for j from 0 <= j < i: # <<<<<<<<<<<<<< - * if e_gap_low[i] < e_gap_low[j]: - * for k from j <= k < i: - */ - __pyx_t_4 = __pyx_v_i; - for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_4; __pyx_v_j++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1296 - * for i from 1 <= i < num_gaps: - * for j from 0 <= j < i: - * if e_gap_low[i] < e_gap_low[j]: # <<<<<<<<<<<<<< - * for k from j <= k < i: - * e_gap_order[k+1] = e_gap_order[k] - */ - __pyx_t_2 = ((__pyx_v_e_gap_low[__pyx_v_i]) < (__pyx_v_e_gap_low[__pyx_v_j])); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1297 - * for j from 0 <= j < i: - * if e_gap_low[i] < e_gap_low[j]: - * for k from j <= k < i: # <<<<<<<<<<<<<< - * e_gap_order[k+1] = e_gap_order[k] - * e_gap_order[j] = i - */ - __pyx_t_5 = __pyx_v_i; - for (__pyx_v_k = __pyx_v_j; __pyx_v_k < __pyx_t_5; __pyx_v_k++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1298 - * if e_gap_low[i] < e_gap_low[j]: - * for k from j <= k < i: - * e_gap_order[k+1] = e_gap_order[k] # <<<<<<<<<<<<<< - * e_gap_order[j] = i - * break - */ - (__pyx_v_e_gap_order[(__pyx_v_k + 1)]) = (__pyx_v_e_gap_order[__pyx_v_k]); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1299 - * for k from j <= k < i: - * e_gap_order[k+1] = e_gap_order[k] - * e_gap_order[j] = i # <<<<<<<<<<<<<< - * break - * else: - */ - (__pyx_v_e_gap_order[__pyx_v_j]) = __pyx_v_i; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1300 - * e_gap_order[k+1] = e_gap_order[k] - * e_gap_order[j] = i - * break # <<<<<<<<<<<<<< - * else: - * e_gap_order[i] = i - */ - goto __pyx_L7_break; - goto __pyx_L8; - } - __pyx_L8:; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1302 - * break - * else: - * e_gap_order[i] = i # <<<<<<<<<<<<<< - * - * e_x_low = e_low - */ - (__pyx_v_e_gap_order[__pyx_v_i]) = __pyx_v_i; - } - __pyx_L7_break:; - } - goto __pyx_L3; - } - __pyx_L3:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1304 - * e_gap_order[i] = i - * - * e_x_low = e_low # <<<<<<<<<<<<<< - * e_x_high = e_high - * if self.tight_phrases == 0: - */ - __pyx_v_e_x_low = __pyx_v_e_low; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1305 - * - * e_x_low = e_low - * e_x_high = e_high # <<<<<<<<<<<<<< - * if self.tight_phrases == 0: - * while e_x_low > 0 and e_high - e_x_low < self.train_max_initial_size and e_links_low[e_x_low-1] == -1: - */ - __pyx_v_e_x_high = __pyx_v_e_high; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1306 - * e_x_low = e_low - * e_x_high = e_high - * if self.tight_phrases == 0: # <<<<<<<<<<<<<< - * while e_x_low > 0 and e_high - e_x_low < self.train_max_initial_size and e_links_low[e_x_low-1] == -1: - * e_x_low = e_x_low - 1 - */ - __pyx_t_2 = (__pyx_v_self->tight_phrases == 0); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1307 - * e_x_high = e_high - * if self.tight_phrases == 0: - * while e_x_low > 0 and e_high - e_x_low < self.train_max_initial_size and e_links_low[e_x_low-1] == -1: # <<<<<<<<<<<<<< - * e_x_low = e_x_low - 1 - * while e_x_high < e_sent_len and e_x_high - e_low < self.train_max_initial_size and e_links_low[e_x_high] == -1: - */ - while (1) { - __pyx_t_2 = (__pyx_v_e_x_low > 0); - if (__pyx_t_2) { - __pyx_t_6 = ((__pyx_v_e_high - __pyx_v_e_x_low) < __pyx_v_self->train_max_initial_size); - if (__pyx_t_6) { - __pyx_t_7 = ((__pyx_v_e_links_low[(__pyx_v_e_x_low - 1)]) == -1); - __pyx_t_8 = __pyx_t_7; - } else { - __pyx_t_8 = __pyx_t_6; - } - __pyx_t_6 = __pyx_t_8; - } else { - __pyx_t_6 = __pyx_t_2; - } - if (!__pyx_t_6) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1308 - * if self.tight_phrases == 0: - * while e_x_low > 0 and e_high - e_x_low < self.train_max_initial_size and e_links_low[e_x_low-1] == -1: - * e_x_low = e_x_low - 1 # <<<<<<<<<<<<<< - * while e_x_high < e_sent_len and e_x_high - e_low < self.train_max_initial_size and e_links_low[e_x_high] == -1: - * e_x_high = e_x_high + 1 - */ - __pyx_v_e_x_low = (__pyx_v_e_x_low - 1); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1309 - * while e_x_low > 0 and e_high - e_x_low < self.train_max_initial_size and e_links_low[e_x_low-1] == -1: - * e_x_low = e_x_low - 1 - * while e_x_high < e_sent_len and e_x_high - e_low < self.train_max_initial_size and e_links_low[e_x_high] == -1: # <<<<<<<<<<<<<< - * e_x_high = e_x_high + 1 - * - */ - while (1) { - __pyx_t_6 = (__pyx_v_e_x_high < __pyx_v_e_sent_len); - if (__pyx_t_6) { - __pyx_t_2 = ((__pyx_v_e_x_high - __pyx_v_e_low) < __pyx_v_self->train_max_initial_size); - if (__pyx_t_2) { - __pyx_t_8 = ((__pyx_v_e_links_low[__pyx_v_e_x_high]) == -1); - __pyx_t_7 = __pyx_t_8; - } else { - __pyx_t_7 = __pyx_t_2; - } - __pyx_t_2 = __pyx_t_7; - } else { - __pyx_t_2 = __pyx_t_6; - } - if (!__pyx_t_2) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1310 - * e_x_low = e_x_low - 1 - * while e_x_high < e_sent_len and e_x_high - e_low < self.train_max_initial_size and e_links_low[e_x_high] == -1: - * e_x_high = e_x_high + 1 # <<<<<<<<<<<<<< - * - * for i from e_x_low <= i <= e_low: - */ - __pyx_v_e_x_high = (__pyx_v_e_x_high + 1); - } - goto __pyx_L11; - } - __pyx_L11:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1312 - * e_x_high = e_x_high + 1 - * - * for i from e_x_low <= i <= e_low: # <<<<<<<<<<<<<< - * e_gaps1 = self.int_arr_extend(e_gaps1, &len1, &i, 1) - * - */ - __pyx_t_3 = __pyx_v_e_low; - for (__pyx_v_i = __pyx_v_e_x_low; __pyx_v_i <= __pyx_t_3; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1313 - * - * for i from e_x_low <= i <= e_low: - * e_gaps1 = self.int_arr_extend(e_gaps1, &len1, &i, 1) # <<<<<<<<<<<<<< - * - * for i from 0 <= i < num_gaps: - */ - __pyx_v_e_gaps1 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->int_arr_extend(__pyx_v_self, __pyx_v_e_gaps1, (&__pyx_v_len1), (&__pyx_v_i), 1); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1315 - * e_gaps1 = self.int_arr_extend(e_gaps1, &len1, &i, 1) - * - * for i from 0 <= i < num_gaps: # <<<<<<<<<<<<<< - * e_gaps2 = malloc(0) - * len2 = 0 - */ - __pyx_t_3 = __pyx_v_num_gaps; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1316 - * - * for i from 0 <= i < num_gaps: - * e_gaps2 = malloc(0) # <<<<<<<<<<<<<< - * len2 = 0 - * - */ - __pyx_v_e_gaps2 = ((int *)malloc(0)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1317 - * for i from 0 <= i < num_gaps: - * e_gaps2 = malloc(0) - * len2 = 0 # <<<<<<<<<<<<<< - * - * j = e_gap_order[i] - */ - __pyx_v_len2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1319 - * len2 = 0 - * - * j = e_gap_order[i] # <<<<<<<<<<<<<< - * e_x_gap_low = e_gap_low[j] - * e_x_gap_high = e_gap_high[j] - */ - __pyx_v_j = (__pyx_v_e_gap_order[__pyx_v_i]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1320 - * - * j = e_gap_order[i] - * e_x_gap_low = e_gap_low[j] # <<<<<<<<<<<<<< - * e_x_gap_high = e_gap_high[j] - * if self.tight_phrases == 0: - */ - __pyx_v_e_x_gap_low = (__pyx_v_e_gap_low[__pyx_v_j]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1321 - * j = e_gap_order[i] - * e_x_gap_low = e_gap_low[j] - * e_x_gap_high = e_gap_high[j] # <<<<<<<<<<<<<< - * if self.tight_phrases == 0: - * while e_x_gap_low > e_x_low and e_links_low[e_x_gap_low-1] == -1: - */ - __pyx_v_e_x_gap_high = (__pyx_v_e_gap_high[__pyx_v_j]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1322 - * e_x_gap_low = e_gap_low[j] - * e_x_gap_high = e_gap_high[j] - * if self.tight_phrases == 0: # <<<<<<<<<<<<<< - * while e_x_gap_low > e_x_low and e_links_low[e_x_gap_low-1] == -1: - * e_x_gap_low = e_x_gap_low - 1 - */ - __pyx_t_2 = (__pyx_v_self->tight_phrases == 0); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1323 - * e_x_gap_high = e_gap_high[j] - * if self.tight_phrases == 0: - * while e_x_gap_low > e_x_low and e_links_low[e_x_gap_low-1] == -1: # <<<<<<<<<<<<<< - * e_x_gap_low = e_x_gap_low - 1 - * while e_x_gap_high < e_x_high and e_links_low[e_x_gap_high] == -1: - */ - while (1) { - __pyx_t_2 = (__pyx_v_e_x_gap_low > __pyx_v_e_x_low); - if (__pyx_t_2) { - __pyx_t_6 = ((__pyx_v_e_links_low[(__pyx_v_e_x_gap_low - 1)]) == -1); - __pyx_t_7 = __pyx_t_6; - } else { - __pyx_t_7 = __pyx_t_2; - } - if (!__pyx_t_7) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1324 - * if self.tight_phrases == 0: - * while e_x_gap_low > e_x_low and e_links_low[e_x_gap_low-1] == -1: - * e_x_gap_low = e_x_gap_low - 1 # <<<<<<<<<<<<<< - * while e_x_gap_high < e_x_high and e_links_low[e_x_gap_high] == -1: - * e_x_gap_high = e_x_gap_high + 1 - */ - __pyx_v_e_x_gap_low = (__pyx_v_e_x_gap_low - 1); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1325 - * while e_x_gap_low > e_x_low and e_links_low[e_x_gap_low-1] == -1: - * e_x_gap_low = e_x_gap_low - 1 - * while e_x_gap_high < e_x_high and e_links_low[e_x_gap_high] == -1: # <<<<<<<<<<<<<< - * e_x_gap_high = e_x_gap_high + 1 - * - */ - while (1) { - __pyx_t_7 = (__pyx_v_e_x_gap_high < __pyx_v_e_x_high); - if (__pyx_t_7) { - __pyx_t_2 = ((__pyx_v_e_links_low[__pyx_v_e_x_gap_high]) == -1); - __pyx_t_6 = __pyx_t_2; - } else { - __pyx_t_6 = __pyx_t_7; - } - if (!__pyx_t_6) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1326 - * e_x_gap_low = e_x_gap_low - 1 - * while e_x_gap_high < e_x_high and e_links_low[e_x_gap_high] == -1: - * e_x_gap_high = e_x_gap_high + 1 # <<<<<<<<<<<<<< - * - * k = 0 - */ - __pyx_v_e_x_gap_high = (__pyx_v_e_x_gap_high + 1); - } - goto __pyx_L20; - } - __pyx_L20:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1328 - * e_x_gap_high = e_x_gap_high + 1 - * - * k = 0 # <<<<<<<<<<<<<< - * step = 1+(i*2) - * while k < len1: - */ - __pyx_v_k = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1329 - * - * k = 0 - * step = 1+(i*2) # <<<<<<<<<<<<<< - * while k < len1: - * for m from e_x_gap_low <= m <= e_gap_low[j]: - */ - __pyx_v_step = (1 + (__pyx_v_i * 2)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1330 - * k = 0 - * step = 1+(i*2) - * while k < len1: # <<<<<<<<<<<<<< - * for m from e_x_gap_low <= m <= e_gap_low[j]: - * if m >= e_gaps1[k+step-1]: - */ - while (1) { - __pyx_t_6 = (__pyx_v_k < __pyx_v_len1); - if (!__pyx_t_6) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1331 - * step = 1+(i*2) - * while k < len1: - * for m from e_x_gap_low <= m <= e_gap_low[j]: # <<<<<<<<<<<<<< - * if m >= e_gaps1[k+step-1]: - * for n from e_gap_high[j] <= n <= e_x_gap_high: - */ - __pyx_t_4 = (__pyx_v_e_gap_low[__pyx_v_j]); - for (__pyx_v_m = __pyx_v_e_x_gap_low; __pyx_v_m <= __pyx_t_4; __pyx_v_m++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1332 - * while k < len1: - * for m from e_x_gap_low <= m <= e_gap_low[j]: - * if m >= e_gaps1[k+step-1]: # <<<<<<<<<<<<<< - * for n from e_gap_high[j] <= n <= e_x_gap_high: - * if n-m >= 1: # extractor.py doesn't restrict target-side gap length - */ - __pyx_t_6 = (__pyx_v_m >= (__pyx_v_e_gaps1[((__pyx_v_k + __pyx_v_step) - 1)])); - if (__pyx_t_6) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1333 - * for m from e_x_gap_low <= m <= e_gap_low[j]: - * if m >= e_gaps1[k+step-1]: - * for n from e_gap_high[j] <= n <= e_x_gap_high: # <<<<<<<<<<<<<< - * if n-m >= 1: # extractor.py doesn't restrict target-side gap length - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+k, step) - */ - __pyx_t_5 = __pyx_v_e_x_gap_high; - for (__pyx_v_n = (__pyx_v_e_gap_high[__pyx_v_j]); __pyx_v_n <= __pyx_t_5; __pyx_v_n++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1334 - * if m >= e_gaps1[k+step-1]: - * for n from e_gap_high[j] <= n <= e_x_gap_high: - * if n-m >= 1: # extractor.py doesn't restrict target-side gap length # <<<<<<<<<<<<<< - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+k, step) - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &m, 1) - */ - __pyx_t_6 = ((__pyx_v_n - __pyx_v_m) >= 1); - if (__pyx_t_6) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1335 - * for n from e_gap_high[j] <= n <= e_x_gap_high: - * if n-m >= 1: # extractor.py doesn't restrict target-side gap length - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+k, step) # <<<<<<<<<<<<<< - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &m, 1) - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &n, 1) - */ - __pyx_v_e_gaps2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->int_arr_extend(__pyx_v_self, __pyx_v_e_gaps2, (&__pyx_v_len2), (__pyx_v_e_gaps1 + __pyx_v_k), __pyx_v_step); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1336 - * if n-m >= 1: # extractor.py doesn't restrict target-side gap length - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+k, step) - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &m, 1) # <<<<<<<<<<<<<< - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &n, 1) - * k = k + step - */ - __pyx_v_e_gaps2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->int_arr_extend(__pyx_v_self, __pyx_v_e_gaps2, (&__pyx_v_len2), (&__pyx_v_m), 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1337 - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+k, step) - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &m, 1) - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &n, 1) # <<<<<<<<<<<<<< - * k = k + step - * free(e_gaps1) - */ - __pyx_v_e_gaps2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->int_arr_extend(__pyx_v_self, __pyx_v_e_gaps2, (&__pyx_v_len2), (&__pyx_v_n), 1); - goto __pyx_L32; - } - __pyx_L32:; - } - goto __pyx_L29; - } - __pyx_L29:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1338 - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &m, 1) - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &n, 1) - * k = k + step # <<<<<<<<<<<<<< - * free(e_gaps1) - * e_gaps1 = e_gaps2 - */ - __pyx_v_k = (__pyx_v_k + __pyx_v_step); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1339 - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &n, 1) - * k = k + step - * free(e_gaps1) # <<<<<<<<<<<<<< - * e_gaps1 = e_gaps2 - * len1 = len2 - */ - free(__pyx_v_e_gaps1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1340 - * k = k + step - * free(e_gaps1) - * e_gaps1 = e_gaps2 # <<<<<<<<<<<<<< - * len1 = len2 - * - */ - __pyx_v_e_gaps1 = __pyx_v_e_gaps2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1341 - * free(e_gaps1) - * e_gaps1 = e_gaps2 - * len1 = len2 # <<<<<<<<<<<<<< - * - * step = 1+(num_gaps*2) - */ - __pyx_v_len1 = __pyx_v_len2; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1343 - * len1 = len2 - * - * step = 1+(num_gaps*2) # <<<<<<<<<<<<<< - * e_gaps2 = malloc(0) - * len2 = 0 - */ - __pyx_v_step = (1 + (__pyx_v_num_gaps * 2)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1344 - * - * step = 1+(num_gaps*2) - * e_gaps2 = malloc(0) # <<<<<<<<<<<<<< - * len2 = 0 - * for i from e_high <= i <= e_x_high: - */ - __pyx_v_e_gaps2 = ((int *)malloc(0)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1345 - * step = 1+(num_gaps*2) - * e_gaps2 = malloc(0) - * len2 = 0 # <<<<<<<<<<<<<< - * for i from e_high <= i <= e_x_high: - * j = 0 - */ - __pyx_v_len2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1346 - * e_gaps2 = malloc(0) - * len2 = 0 - * for i from e_high <= i <= e_x_high: # <<<<<<<<<<<<<< - * j = 0 - * while j < len1: - */ - __pyx_t_3 = __pyx_v_e_x_high; - for (__pyx_v_i = __pyx_v_e_high; __pyx_v_i <= __pyx_t_3; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1347 - * len2 = 0 - * for i from e_high <= i <= e_x_high: - * j = 0 # <<<<<<<<<<<<<< - * while j < len1: - * if i - e_gaps1[j] <= self.train_max_initial_size and i >= e_gaps1[j+step-1]: - */ - __pyx_v_j = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1348 - * for i from e_high <= i <= e_x_high: - * j = 0 - * while j < len1: # <<<<<<<<<<<<<< - * if i - e_gaps1[j] <= self.train_max_initial_size and i >= e_gaps1[j+step-1]: - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+j, step) - */ - while (1) { - __pyx_t_6 = (__pyx_v_j < __pyx_v_len1); - if (!__pyx_t_6) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1349 - * j = 0 - * while j < len1: - * if i - e_gaps1[j] <= self.train_max_initial_size and i >= e_gaps1[j+step-1]: # <<<<<<<<<<<<<< - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+j, step) - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &i, 1) - */ - __pyx_t_6 = ((__pyx_v_i - (__pyx_v_e_gaps1[__pyx_v_j])) <= __pyx_v_self->train_max_initial_size); - if (__pyx_t_6) { - __pyx_t_7 = (__pyx_v_i >= (__pyx_v_e_gaps1[((__pyx_v_j + __pyx_v_step) - 1)])); - __pyx_t_2 = __pyx_t_7; - } else { - __pyx_t_2 = __pyx_t_6; - } - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1350 - * while j < len1: - * if i - e_gaps1[j] <= self.train_max_initial_size and i >= e_gaps1[j+step-1]: - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+j, step) # <<<<<<<<<<<<<< - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &i, 1) - * j = j + step - */ - __pyx_v_e_gaps2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->int_arr_extend(__pyx_v_self, __pyx_v_e_gaps2, (&__pyx_v_len2), (__pyx_v_e_gaps1 + __pyx_v_j), __pyx_v_step); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1351 - * if i - e_gaps1[j] <= self.train_max_initial_size and i >= e_gaps1[j+step-1]: - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+j, step) - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &i, 1) # <<<<<<<<<<<<<< - * j = j + step - * free(e_gaps1) - */ - __pyx_v_e_gaps2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->int_arr_extend(__pyx_v_self, __pyx_v_e_gaps2, (&__pyx_v_len2), (&__pyx_v_i), 1); - goto __pyx_L37; - } - __pyx_L37:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1352 - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+j, step) - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &i, 1) - * j = j + step # <<<<<<<<<<<<<< - * free(e_gaps1) - * e_gaps1 = e_gaps2 - */ - __pyx_v_j = (__pyx_v_j + __pyx_v_step); - } - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1353 - * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &i, 1) - * j = j + step - * free(e_gaps1) # <<<<<<<<<<<<<< - * e_gaps1 = e_gaps2 - * len1 = len2 - */ - free(__pyx_v_e_gaps1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1354 - * j = j + step - * free(e_gaps1) - * e_gaps1 = e_gaps2 # <<<<<<<<<<<<<< - * len1 = len2 - * - */ - __pyx_v_e_gaps1 = __pyx_v_e_gaps2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1355 - * free(e_gaps1) - * e_gaps1 = e_gaps2 - * len1 = len2 # <<<<<<<<<<<<<< - * - * step = (num_gaps+1)*2 - */ - __pyx_v_len1 = __pyx_v_len2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1357 - * len1 = len2 - * - * step = (num_gaps+1)*2 # <<<<<<<<<<<<<< - * i = 0 - * - */ - __pyx_v_step = ((__pyx_v_num_gaps + 1) * 2); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1358 - * - * step = (num_gaps+1)*2 - * i = 0 # <<<<<<<<<<<<<< - * - * while i < len1: - */ - __pyx_v_i = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1360 - * i = 0 - * - * while i < len1: # <<<<<<<<<<<<<< - * ephr_arr._clear() - * num_chunks = 0 - */ - while (1) { - __pyx_t_2 = (__pyx_v_i < __pyx_v_len1); - if (!__pyx_t_2) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1361 - * - * while i < len1: - * ephr_arr._clear() # <<<<<<<<<<<<<< - * num_chunks = 0 - * indexes = [] - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_ephr_arr->__pyx_vtab)->_clear(__pyx_v_ephr_arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1362 - * while i < len1: - * ephr_arr._clear() - * num_chunks = 0 # <<<<<<<<<<<<<< - * indexes = [] - * for j from 0 <= j < num_gaps+1: - */ - __pyx_v_num_chunks = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1363 - * ephr_arr._clear() - * num_chunks = 0 - * indexes = [] # <<<<<<<<<<<<<< - * for j from 0 <= j < num_gaps+1: - * if e_gaps1[i+2*j] < e_gaps1[i+(2*j)+1]: - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1363; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_XDECREF(((PyObject *)__pyx_v_indexes)); - __pyx_v_indexes = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1364 - * num_chunks = 0 - * indexes = [] - * for j from 0 <= j < num_gaps+1: # <<<<<<<<<<<<<< - * if e_gaps1[i+2*j] < e_gaps1[i+(2*j)+1]: - * num_chunks = num_chunks + 1 - */ - __pyx_t_9 = (__pyx_v_num_gaps + 1); - for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_9; __pyx_v_j++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1365 - * indexes = [] - * for j from 0 <= j < num_gaps+1: - * if e_gaps1[i+2*j] < e_gaps1[i+(2*j)+1]: # <<<<<<<<<<<<<< - * num_chunks = num_chunks + 1 - * for k from e_gaps1[i+2*j] <= k < e_gaps1[i+(2*j)+1]: - */ - __pyx_t_2 = ((__pyx_v_e_gaps1[(__pyx_v_i + (2 * __pyx_v_j))]) < (__pyx_v_e_gaps1[((__pyx_v_i + (2 * __pyx_v_j)) + 1)])); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1366 - * for j from 0 <= j < num_gaps+1: - * if e_gaps1[i+2*j] < e_gaps1[i+(2*j)+1]: - * num_chunks = num_chunks + 1 # <<<<<<<<<<<<<< - * for k from e_gaps1[i+2*j] <= k < e_gaps1[i+(2*j)+1]: - * indexes.append(k) - */ - __pyx_v_num_chunks = (__pyx_v_num_chunks + 1); - goto __pyx_L42; - } - __pyx_L42:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1367 - * if e_gaps1[i+2*j] < e_gaps1[i+(2*j)+1]: - * num_chunks = num_chunks + 1 - * for k from e_gaps1[i+2*j] <= k < e_gaps1[i+(2*j)+1]: # <<<<<<<<<<<<<< - * indexes.append(k) - * ephr_arr._append(self.eid2symid[self.eda.data.arr[e_sent_start+k]]) - */ - __pyx_t_3 = (__pyx_v_e_gaps1[((__pyx_v_i + (2 * __pyx_v_j)) + 1)]); - for (__pyx_v_k = (__pyx_v_e_gaps1[(__pyx_v_i + (2 * __pyx_v_j))]); __pyx_v_k < __pyx_t_3; __pyx_v_k++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1368 - * num_chunks = num_chunks + 1 - * for k from e_gaps1[i+2*j] <= k < e_gaps1[i+(2*j)+1]: - * indexes.append(k) # <<<<<<<<<<<<<< - * ephr_arr._append(self.eid2symid[self.eda.data.arr[e_sent_start+k]]) - * if j < num_gaps: - */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_k); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = PyList_Append(__pyx_v_indexes, __pyx_t_1); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1369 - * for k from e_gaps1[i+2*j] <= k < e_gaps1[i+(2*j)+1]: - * indexes.append(k) - * ephr_arr._append(self.eid2symid[self.eda.data.arr[e_sent_start+k]]) # <<<<<<<<<<<<<< - * if j < num_gaps: - * indexes.append(sym_setindex(self.category, e_gap_order[j]+1)) - */ - __pyx_t_4 = (__pyx_v_self->eda->data->arr[(__pyx_v_e_sent_start + __pyx_v_k)]); - __pyx_t_1 = __Pyx_GetItemInt(((PyObject *)__pyx_v_self->eid2symid), __pyx_t_4, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1369; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1369; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_ephr_arr->__pyx_vtab)->_append(__pyx_v_ephr_arr, __pyx_t_4); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1370 - * indexes.append(k) - * ephr_arr._append(self.eid2symid[self.eda.data.arr[e_sent_start+k]]) - * if j < num_gaps: # <<<<<<<<<<<<<< - * indexes.append(sym_setindex(self.category, e_gap_order[j]+1)) - * ephr_arr._append(sym_setindex(self.category, e_gap_order[j]+1)) - */ - __pyx_t_2 = (__pyx_v_j < __pyx_v_num_gaps); - if (__pyx_t_2) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1371 - * ephr_arr._append(self.eid2symid[self.eda.data.arr[e_sent_start+k]]) - * if j < num_gaps: - * indexes.append(sym_setindex(self.category, e_gap_order[j]+1)) # <<<<<<<<<<<<<< - * ephr_arr._append(sym_setindex(self.category, e_gap_order[j]+1)) - * i = i + step - */ - __pyx_t_1 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, ((__pyx_v_e_gap_order[__pyx_v_j]) + 1))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = PyList_Append(__pyx_v_indexes, __pyx_t_1); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1372 - * if j < num_gaps: - * indexes.append(sym_setindex(self.category, e_gap_order[j]+1)) - * ephr_arr._append(sym_setindex(self.category, e_gap_order[j]+1)) # <<<<<<<<<<<<<< - * i = i + step - * if ephr_arr.len <= self.max_target_length and num_chunks <= self.max_target_chunks: - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_ephr_arr->__pyx_vtab)->_append(__pyx_v_ephr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, ((__pyx_v_e_gap_order[__pyx_v_j]) + 1))); - goto __pyx_L45; - } - __pyx_L45:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1373 - * indexes.append(sym_setindex(self.category, e_gap_order[j]+1)) - * ephr_arr._append(sym_setindex(self.category, e_gap_order[j]+1)) - * i = i + step # <<<<<<<<<<<<<< - * if ephr_arr.len <= self.max_target_length and num_chunks <= self.max_target_chunks: - * result.append((Phrase(ephr_arr),indexes)) - */ - __pyx_v_i = (__pyx_v_i + __pyx_v_step); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1374 - * ephr_arr._append(sym_setindex(self.category, e_gap_order[j]+1)) - * i = i + step - * if ephr_arr.len <= self.max_target_length and num_chunks <= self.max_target_chunks: # <<<<<<<<<<<<<< - * result.append((Phrase(ephr_arr),indexes)) - * - */ - __pyx_t_2 = (__pyx_v_ephr_arr->len <= __pyx_v_self->max_target_length); - if (__pyx_t_2) { - __pyx_t_6 = (__pyx_v_num_chunks <= __pyx_v_self->max_target_chunks); - __pyx_t_7 = __pyx_t_6; - } else { - __pyx_t_7 = __pyx_t_2; - } - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1375 - * i = i + step - * if ephr_arr.len <= self.max_target_length and num_chunks <= self.max_target_chunks: - * result.append((Phrase(ephr_arr),indexes)) # <<<<<<<<<<<<<< - * - * free(e_gaps1) - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1375; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_ephr_arr)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_ephr_arr)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_ephr_arr)); - __pyx_t_11 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1375; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1375; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_11); - __Pyx_GIVEREF(__pyx_t_11); - __Pyx_INCREF(((PyObject *)__pyx_v_indexes)); - PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_indexes)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_indexes)); - __pyx_t_11 = 0; - __pyx_t_11 = __Pyx_PyObject_Append(__pyx_v_result, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1375; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - goto __pyx_L46; - } - __pyx_L46:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1377 - * result.append((Phrase(ephr_arr),indexes)) - * - * free(e_gaps1) # <<<<<<<<<<<<<< - * free(e_gap_order) - * return result - */ - free(__pyx_v_e_gaps1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1378 - * - * free(e_gaps1) - * free(e_gap_order) # <<<<<<<<<<<<<< - * return result - * - */ - free(__pyx_v_e_gap_order); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1379 - * free(e_gaps1) - * free(e_gap_order) - * return result # <<<<<<<<<<<<<< - * - * cdef create_alignments(self, int* sent_links, int num_links, findexes, eindexes): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_result); - __pyx_r = __pyx_v_result; - 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_11); - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.extract_phrases", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_ephr_arr); - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XDECREF(__pyx_v_indexes); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1381 - * return result - * - * cdef create_alignments(self, int* sent_links, int num_links, findexes, eindexes): # <<<<<<<<<<<<<< - * cdef unsigned i - * ret = IntList() - */ - -static PyObject *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_create_alignments(CYTHON_UNUSED struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, int *__pyx_v_sent_links, int __pyx_v_num_links, PyObject *__pyx_v_findexes, PyObject *__pyx_v_eindexes) { - unsigned int __pyx_v_i; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_ret = NULL; - PyObject *__pyx_v_s = NULL; - PyObject *__pyx_v_idx = NULL; - PyObject *__pyx_v_j = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - Py_ssize_t __pyx_t_2; - unsigned int __pyx_t_3; - int __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - Py_ssize_t __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("create_alignments", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1383 - * cdef create_alignments(self, int* sent_links, int num_links, findexes, eindexes): - * cdef unsigned i - * ret = IntList() # <<<<<<<<<<<<<< - * for i in range(len(findexes)): - * s = findexes[i] - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_ret = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1384 - * cdef unsigned i - * ret = IntList() - * for i in range(len(findexes)): # <<<<<<<<<<<<<< - * s = findexes[i] - * if (s<0): - */ - __pyx_t_2 = PyObject_Length(__pyx_v_findexes); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1384; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_v_i = __pyx_t_3; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1385 - * ret = IntList() - * for i in range(len(findexes)): - * s = findexes[i] # <<<<<<<<<<<<<< - * if (s<0): - * continue - */ - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_findexes, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1385; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_v_s); - __pyx_v_s = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1386 - * for i in range(len(findexes)): - * s = findexes[i] - * if (s<0): # <<<<<<<<<<<<<< - * continue - * idx = 0 - */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_s, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1387 - * s = findexes[i] - * if (s<0): - * continue # <<<<<<<<<<<<<< - * idx = 0 - * while (idx < num_links*2): - */ - goto __pyx_L3_continue; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1388 - * if (s<0): - * continue - * idx = 0 # <<<<<<<<<<<<<< - * while (idx < num_links*2): - * if (sent_links[idx] == s): - */ - __Pyx_INCREF(__pyx_int_0); - __Pyx_XDECREF(__pyx_v_idx); - __pyx_v_idx = __pyx_int_0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1389 - * continue - * idx = 0 - * while (idx < num_links*2): # <<<<<<<<<<<<<< - * if (sent_links[idx] == s): - * j = eindexes.index(sent_links[idx+1]) - */ - while (1) { - __pyx_t_1 = PyInt_FromLong((__pyx_v_num_links * 2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyObject_RichCompare(__pyx_v_idx, __pyx_t_1, Py_LT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (!__pyx_t_4) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1390 - * idx = 0 - * while (idx < num_links*2): - * if (sent_links[idx] == s): # <<<<<<<<<<<<<< - * j = eindexes.index(sent_links[idx+1]) - * ret.append(i*65536+j) - */ - __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_idx); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_5 = PyInt_FromLong((__pyx_v_sent_links[__pyx_t_6])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyObject_RichCompare(__pyx_t_5, __pyx_v_s, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_4) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1391 - * while (idx < num_links*2): - * if (sent_links[idx] == s): - * j = eindexes.index(sent_links[idx+1]) # <<<<<<<<<<<<<< - * ret.append(i*65536+j) - * idx += 2 - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_eindexes, __pyx_n_s__index); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyNumber_Add(__pyx_v_idx, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_t_5); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyInt_FromLong((__pyx_v_sent_links[__pyx_t_6])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_5); - __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; - __Pyx_XDECREF(__pyx_v_j); - __pyx_v_j = __pyx_t_5; - __pyx_t_5 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1392 - * if (sent_links[idx] == s): - * j = eindexes.index(sent_links[idx+1]) - * ret.append(i*65536+j) # <<<<<<<<<<<<<< - * idx += 2 - * return ret - */ - __pyx_t_5 = PyInt_FromLong((__pyx_v_i * 65536)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = PyNumber_Add(__pyx_t_5, __pyx_v_j); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_ret), __pyx_t_7); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - goto __pyx_L8; - } - __pyx_L8:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1393 - * j = eindexes.index(sent_links[idx+1]) - * ret.append(i*65536+j) - * idx += 2 # <<<<<<<<<<<<<< - * return ret - * - */ - __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_idx, __pyx_int_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_v_idx); - __pyx_v_idx = __pyx_t_5; - __pyx_t_5 = 0; - } - __pyx_L3_continue:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1394 - * ret.append(i*65536+j) - * idx += 2 - * return ret # <<<<<<<<<<<<<< - * - * cdef extract(self, Phrase phrase, Matching* matching, int* chunklen, int num_chunks): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_ret)); - __pyx_r = ((PyObject *)__pyx_v_ret); - 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_5); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.create_alignments", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_ret); - __Pyx_XDECREF(__pyx_v_s); - __Pyx_XDECREF(__pyx_v_idx); - __Pyx_XDECREF(__pyx_v_j); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1396 - * return ret - * - * cdef extract(self, Phrase phrase, Matching* matching, int* chunklen, int num_chunks): # <<<<<<<<<<<<<< - * cdef int* sent_links, *e_links_low, *e_links_high, *f_links_low, *f_links_high - * cdef int *f_gap_low, *f_gap_high, *e_gap_low, *e_gap_high, num_gaps, gap_start - */ - -static PyObject *__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_extract(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_phrase, struct __pyx_t_8_cdec_sa_Matching *__pyx_v_matching, int *__pyx_v_chunklen, int __pyx_v_num_chunks) { - int *__pyx_v_sent_links; - int *__pyx_v_e_links_low; - int *__pyx_v_e_links_high; - int *__pyx_v_f_links_low; - int *__pyx_v_f_links_high; - int *__pyx_v_f_gap_low; - int *__pyx_v_f_gap_high; - int *__pyx_v_e_gap_low; - int *__pyx_v_e_gap_high; - int __pyx_v_num_gaps; - int __pyx_v_gap_start; - int __pyx_v_i; - int __pyx_v_j; - int __pyx_v_e_i; - int __pyx_v_f_i; - int __pyx_v_num_links; - int __pyx_v_num_aligned_chunks; - int __pyx_v_met_constraints; - int __pyx_v_x; - int __pyx_v_f_low; - int __pyx_v_f_high; - int __pyx_v_e_low; - int __pyx_v_e_high; - int __pyx_v_f_back_low; - int __pyx_v_f_back_high; - int __pyx_v_e_sent_start; - int __pyx_v_e_sent_end; - int __pyx_v_f_sent_start; - int __pyx_v_f_sent_end; - int __pyx_v_e_sent_len; - int __pyx_v_f_sent_len; - CYTHON_UNUSED int __pyx_v_e_word_count; - int __pyx_v_f_x_low; - int __pyx_v_f_x_high; - int __pyx_v_e_x_low; - int __pyx_v_e_x_high; - int __pyx_v_phrase_len; - float __pyx_v_pair_count; - PyObject *__pyx_v_extracts = 0; - PyObject *__pyx_v_phrase_list = 0; - struct __pyx_obj_8_cdec_sa_IntList *__pyx_v_fphr_arr = 0; - struct __pyx_obj_8_cdec_sa_Phrase *__pyx_v_fphr = 0; - CYTHON_UNUSED PyObject *__pyx_v_reason_for_failure = 0; - PyObject *__pyx_v_sofar = NULL; - PyObject *__pyx_v_als = NULL; - PyObject *__pyx_v_al = NULL; - long __pyx_v_gap_error; - PyObject *__pyx_v_phrase2 = NULL; - PyObject *__pyx_v_eindexes = NULL; - PyObject *__pyx_v_als1 = NULL; - PyObject *__pyx_v_als2 = NULL; - PyObject *__pyx_v_als3 = NULL; - PyObject *__pyx_v_als4 = NULL; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - int __pyx_t_3; - int __pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; - int __pyx_t_7; - int __pyx_t_8; - int __pyx_t_9; - PyObject *__pyx_t_10 = NULL; - int __pyx_t_11; - long __pyx_t_12; - Py_ssize_t __pyx_t_13; - PyObject *__pyx_t_14 = NULL; - PyObject *__pyx_t_15 = NULL; - PyObject *(*__pyx_t_16)(PyObject *); - PyObject *(*__pyx_t_17)(PyObject *); - int __pyx_t_18; - int __pyx_t_19; - int __pyx_t_20; - int __pyx_t_21; - int __pyx_t_22; - int __pyx_t_23; - int __pyx_t_24; - int __pyx_t_25; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("extract", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1409 - * cdef reason_for_failure - * - * fphr_arr = IntList() # <<<<<<<<<<<<<< - * phrase_len = phrase.n - * extracts = [] - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_fphr_arr = ((struct __pyx_obj_8_cdec_sa_IntList *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1410 - * - * fphr_arr = IntList() - * phrase_len = phrase.n # <<<<<<<<<<<<<< - * extracts = [] - * sent_links = self.alignment._get_sent_links(matching.sent_id, &num_links) - */ - __pyx_v_phrase_len = __pyx_v_phrase->n; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1411 - * fphr_arr = IntList() - * phrase_len = phrase.n - * extracts = [] # <<<<<<<<<<<<<< - * sent_links = self.alignment._get_sent_links(matching.sent_id, &num_links) - * - */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1411; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_extracts = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1412 - * phrase_len = phrase.n - * extracts = [] - * sent_links = self.alignment._get_sent_links(matching.sent_id, &num_links) # <<<<<<<<<<<<<< - * - * e_sent_start = self.eda.sent_index.arr[matching.sent_id] - */ - __pyx_v_sent_links = ((struct __pyx_vtabstruct_8_cdec_sa_Alignment *)__pyx_v_self->alignment->__pyx_vtab)->_get_sent_links(__pyx_v_self->alignment, __pyx_v_matching->sent_id, (&__pyx_v_num_links)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1414 - * sent_links = self.alignment._get_sent_links(matching.sent_id, &num_links) - * - * e_sent_start = self.eda.sent_index.arr[matching.sent_id] # <<<<<<<<<<<<<< - * e_sent_end = self.eda.sent_index.arr[matching.sent_id+1] - * e_sent_len = e_sent_end - e_sent_start - 1 - */ - __pyx_v_e_sent_start = (__pyx_v_self->eda->sent_index->arr[__pyx_v_matching->sent_id]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1415 - * - * e_sent_start = self.eda.sent_index.arr[matching.sent_id] - * e_sent_end = self.eda.sent_index.arr[matching.sent_id+1] # <<<<<<<<<<<<<< - * e_sent_len = e_sent_end - e_sent_start - 1 - * f_sent_start = self.fda.sent_index.arr[matching.sent_id] - */ - __pyx_v_e_sent_end = (__pyx_v_self->eda->sent_index->arr[(__pyx_v_matching->sent_id + 1)]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1416 - * e_sent_start = self.eda.sent_index.arr[matching.sent_id] - * e_sent_end = self.eda.sent_index.arr[matching.sent_id+1] - * e_sent_len = e_sent_end - e_sent_start - 1 # <<<<<<<<<<<<<< - * f_sent_start = self.fda.sent_index.arr[matching.sent_id] - * f_sent_end = self.fda.sent_index.arr[matching.sent_id+1] - */ - __pyx_v_e_sent_len = ((__pyx_v_e_sent_end - __pyx_v_e_sent_start) - 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1417 - * e_sent_end = self.eda.sent_index.arr[matching.sent_id+1] - * e_sent_len = e_sent_end - e_sent_start - 1 - * f_sent_start = self.fda.sent_index.arr[matching.sent_id] # <<<<<<<<<<<<<< - * f_sent_end = self.fda.sent_index.arr[matching.sent_id+1] - * f_sent_len = f_sent_end - f_sent_start - 1 - */ - __pyx_v_f_sent_start = (__pyx_v_self->fda->sent_index->arr[__pyx_v_matching->sent_id]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1418 - * e_sent_len = e_sent_end - e_sent_start - 1 - * f_sent_start = self.fda.sent_index.arr[matching.sent_id] - * f_sent_end = self.fda.sent_index.arr[matching.sent_id+1] # <<<<<<<<<<<<<< - * f_sent_len = f_sent_end - f_sent_start - 1 - * - */ - __pyx_v_f_sent_end = (__pyx_v_self->fda->sent_index->arr[(__pyx_v_matching->sent_id + 1)]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1419 - * f_sent_start = self.fda.sent_index.arr[matching.sent_id] - * f_sent_end = self.fda.sent_index.arr[matching.sent_id+1] - * f_sent_len = f_sent_end - f_sent_start - 1 # <<<<<<<<<<<<<< - * - * self.findexes1.reset() - */ - __pyx_v_f_sent_len = ((__pyx_v_f_sent_end - __pyx_v_f_sent_start) - 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1421 - * f_sent_len = f_sent_end - f_sent_start - 1 - * - * self.findexes1.reset() # <<<<<<<<<<<<<< - * sofar = 0 - * for i in range(num_chunks): - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes1), __pyx_n_s__reset); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1421; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1422 - * - * self.findexes1.reset() - * sofar = 0 # <<<<<<<<<<<<<< - * for i in range(num_chunks): - * for j in range(chunklen[i]): - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_v_sofar = __pyx_int_0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1423 - * self.findexes1.reset() - * sofar = 0 - * for i in range(num_chunks): # <<<<<<<<<<<<<< - * for j in range(chunklen[i]): - * self.findexes1.append(matching.arr[matching.start+i]+j-f_sent_start); - */ - __pyx_t_3 = __pyx_v_num_chunks; - for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_i = __pyx_t_4; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1424 - * sofar = 0 - * for i in range(num_chunks): - * for j in range(chunklen[i]): # <<<<<<<<<<<<<< - * self.findexes1.append(matching.arr[matching.start+i]+j-f_sent_start); - * sofar += 1 - */ - __pyx_t_5 = (__pyx_v_chunklen[__pyx_v_i]); - for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { - __pyx_v_j = __pyx_t_6; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1425 - * for i in range(num_chunks): - * for j in range(chunklen[i]): - * self.findexes1.append(matching.arr[matching.start+i]+j-f_sent_start); # <<<<<<<<<<<<<< - * sofar += 1 - * if (i+1arr[(__pyx_v_matching->start + __pyx_v_i)]) + __pyx_v_j) - __pyx_v_f_sent_start)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1425; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes1), __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1425; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1426 - * for j in range(chunklen[i]): - * self.findexes1.append(matching.arr[matching.start+i]+j-f_sent_start); - * sofar += 1 # <<<<<<<<<<<<<< - * if (i+1findexes1), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1429 - * if (i+1 malloc(e_sent_len*sizeof(int)) # <<<<<<<<<<<<<< - * e_links_high = malloc(e_sent_len*sizeof(int)) - * f_links_low = malloc(f_sent_len*sizeof(int)) - */ - __pyx_v_e_links_low = ((int *)malloc((__pyx_v_e_sent_len * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1433 - * - * e_links_low = malloc(e_sent_len*sizeof(int)) - * e_links_high = malloc(e_sent_len*sizeof(int)) # <<<<<<<<<<<<<< - * f_links_low = malloc(f_sent_len*sizeof(int)) - * f_links_high = malloc(f_sent_len*sizeof(int)) - */ - __pyx_v_e_links_high = ((int *)malloc((__pyx_v_e_sent_len * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1434 - * e_links_low = malloc(e_sent_len*sizeof(int)) - * e_links_high = malloc(e_sent_len*sizeof(int)) - * f_links_low = malloc(f_sent_len*sizeof(int)) # <<<<<<<<<<<<<< - * f_links_high = malloc(f_sent_len*sizeof(int)) - * f_gap_low = malloc((num_chunks+1)*sizeof(int)) - */ - __pyx_v_f_links_low = ((int *)malloc((__pyx_v_f_sent_len * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1435 - * e_links_high = malloc(e_sent_len*sizeof(int)) - * f_links_low = malloc(f_sent_len*sizeof(int)) - * f_links_high = malloc(f_sent_len*sizeof(int)) # <<<<<<<<<<<<<< - * f_gap_low = malloc((num_chunks+1)*sizeof(int)) - * f_gap_high = malloc((num_chunks+1)*sizeof(int)) - */ - __pyx_v_f_links_high = ((int *)malloc((__pyx_v_f_sent_len * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1436 - * f_links_low = malloc(f_sent_len*sizeof(int)) - * f_links_high = malloc(f_sent_len*sizeof(int)) - * f_gap_low = malloc((num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< - * f_gap_high = malloc((num_chunks+1)*sizeof(int)) - * e_gap_low = malloc((num_chunks+1)*sizeof(int)) - */ - __pyx_v_f_gap_low = ((int *)malloc(((__pyx_v_num_chunks + 1) * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1437 - * f_links_high = malloc(f_sent_len*sizeof(int)) - * f_gap_low = malloc((num_chunks+1)*sizeof(int)) - * f_gap_high = malloc((num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< - * e_gap_low = malloc((num_chunks+1)*sizeof(int)) - * e_gap_high = malloc((num_chunks+1)*sizeof(int)) - */ - __pyx_v_f_gap_high = ((int *)malloc(((__pyx_v_num_chunks + 1) * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1438 - * f_gap_low = malloc((num_chunks+1)*sizeof(int)) - * f_gap_high = malloc((num_chunks+1)*sizeof(int)) - * e_gap_low = malloc((num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< - * e_gap_high = malloc((num_chunks+1)*sizeof(int)) - * memset(f_gap_low, 0, (num_chunks+1)*sizeof(int)) - */ - __pyx_v_e_gap_low = ((int *)malloc(((__pyx_v_num_chunks + 1) * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1439 - * f_gap_high = malloc((num_chunks+1)*sizeof(int)) - * e_gap_low = malloc((num_chunks+1)*sizeof(int)) - * e_gap_high = malloc((num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< - * memset(f_gap_low, 0, (num_chunks+1)*sizeof(int)) - * memset(f_gap_high, 0, (num_chunks+1)*sizeof(int)) - */ - __pyx_v_e_gap_high = ((int *)malloc(((__pyx_v_num_chunks + 1) * (sizeof(int))))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1440 - * e_gap_low = malloc((num_chunks+1)*sizeof(int)) - * e_gap_high = malloc((num_chunks+1)*sizeof(int)) - * memset(f_gap_low, 0, (num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< - * memset(f_gap_high, 0, (num_chunks+1)*sizeof(int)) - * memset(e_gap_low, 0, (num_chunks+1)*sizeof(int)) - */ - memset(__pyx_v_f_gap_low, 0, ((__pyx_v_num_chunks + 1) * (sizeof(int)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1441 - * e_gap_high = malloc((num_chunks+1)*sizeof(int)) - * memset(f_gap_low, 0, (num_chunks+1)*sizeof(int)) - * memset(f_gap_high, 0, (num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< - * memset(e_gap_low, 0, (num_chunks+1)*sizeof(int)) - * memset(e_gap_high, 0, (num_chunks+1)*sizeof(int)) - */ - memset(__pyx_v_f_gap_high, 0, ((__pyx_v_num_chunks + 1) * (sizeof(int)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1442 - * memset(f_gap_low, 0, (num_chunks+1)*sizeof(int)) - * memset(f_gap_high, 0, (num_chunks+1)*sizeof(int)) - * memset(e_gap_low, 0, (num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< - * memset(e_gap_high, 0, (num_chunks+1)*sizeof(int)) - * - */ - memset(__pyx_v_e_gap_low, 0, ((__pyx_v_num_chunks + 1) * (sizeof(int)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1443 - * memset(f_gap_high, 0, (num_chunks+1)*sizeof(int)) - * memset(e_gap_low, 0, (num_chunks+1)*sizeof(int)) - * memset(e_gap_high, 0, (num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< - * - * reason_for_failure = "" - */ - memset(__pyx_v_e_gap_high, 0, ((__pyx_v_num_chunks + 1) * (sizeof(int)))); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1445 - * memset(e_gap_high, 0, (num_chunks+1)*sizeof(int)) - * - * reason_for_failure = "" # <<<<<<<<<<<<<< - * - * for i from 0 <= i < e_sent_len: - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_42)); - __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_42); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1447 - * reason_for_failure = "" - * - * for i from 0 <= i < e_sent_len: # <<<<<<<<<<<<<< - * e_links_low[i] = -1 - * e_links_high[i] = -1 - */ - __pyx_t_3 = __pyx_v_e_sent_len; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1448 - * - * for i from 0 <= i < e_sent_len: - * e_links_low[i] = -1 # <<<<<<<<<<<<<< - * e_links_high[i] = -1 - * for i from 0 <= i < f_sent_len: - */ - (__pyx_v_e_links_low[__pyx_v_i]) = -1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1449 - * for i from 0 <= i < e_sent_len: - * e_links_low[i] = -1 - * e_links_high[i] = -1 # <<<<<<<<<<<<<< - * for i from 0 <= i < f_sent_len: - * f_links_low[i] = -1 - */ - (__pyx_v_e_links_high[__pyx_v_i]) = -1; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1450 - * e_links_low[i] = -1 - * e_links_high[i] = -1 - * for i from 0 <= i < f_sent_len: # <<<<<<<<<<<<<< - * f_links_low[i] = -1 - * f_links_high[i] = -1 - */ - __pyx_t_3 = __pyx_v_f_sent_len; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1451 - * e_links_high[i] = -1 - * for i from 0 <= i < f_sent_len: - * f_links_low[i] = -1 # <<<<<<<<<<<<<< - * f_links_high[i] = -1 - * - */ - (__pyx_v_f_links_low[__pyx_v_i]) = -1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1452 - * for i from 0 <= i < f_sent_len: - * f_links_low[i] = -1 - * f_links_high[i] = -1 # <<<<<<<<<<<<<< - * - * # this is really inefficient -- might be good to - */ - (__pyx_v_f_links_high[__pyx_v_i]) = -1; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1458 - * # links that we care about (but then how to look up - * # when we want to check something on the e side?) - * i = 0 # <<<<<<<<<<<<<< - * while i < num_links*2: - * f_i = sent_links[i] - */ - __pyx_v_i = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1459 - * # when we want to check something on the e side?) - * i = 0 - * while i < num_links*2: # <<<<<<<<<<<<<< - * f_i = sent_links[i] - * e_i = sent_links[i+1] - */ - while (1) { - __pyx_t_7 = (__pyx_v_i < (__pyx_v_num_links * 2)); - if (!__pyx_t_7) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1460 - * i = 0 - * while i < num_links*2: - * f_i = sent_links[i] # <<<<<<<<<<<<<< - * e_i = sent_links[i+1] - * if f_links_low[f_i] == -1 or f_links_low[f_i] > e_i: - */ - __pyx_v_f_i = (__pyx_v_sent_links[__pyx_v_i]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1461 - * while i < num_links*2: - * f_i = sent_links[i] - * e_i = sent_links[i+1] # <<<<<<<<<<<<<< - * if f_links_low[f_i] == -1 or f_links_low[f_i] > e_i: - * f_links_low[f_i] = e_i - */ - __pyx_v_e_i = (__pyx_v_sent_links[(__pyx_v_i + 1)]); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1462 - * f_i = sent_links[i] - * e_i = sent_links[i+1] - * if f_links_low[f_i] == -1 or f_links_low[f_i] > e_i: # <<<<<<<<<<<<<< - * f_links_low[f_i] = e_i - * if f_links_high[f_i] == -1 or f_links_high[f_i] < e_i + 1: - */ - __pyx_t_7 = ((__pyx_v_f_links_low[__pyx_v_f_i]) == -1); - if (!__pyx_t_7) { - __pyx_t_8 = ((__pyx_v_f_links_low[__pyx_v_f_i]) > __pyx_v_e_i); - __pyx_t_9 = __pyx_t_8; - } else { - __pyx_t_9 = __pyx_t_7; - } - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1463 - * e_i = sent_links[i+1] - * if f_links_low[f_i] == -1 or f_links_low[f_i] > e_i: - * f_links_low[f_i] = e_i # <<<<<<<<<<<<<< - * if f_links_high[f_i] == -1 or f_links_high[f_i] < e_i + 1: - * f_links_high[f_i] = e_i + 1 - */ - (__pyx_v_f_links_low[__pyx_v_f_i]) = __pyx_v_e_i; - goto __pyx_L14; - } - __pyx_L14:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1464 - * if f_links_low[f_i] == -1 or f_links_low[f_i] > e_i: - * f_links_low[f_i] = e_i - * if f_links_high[f_i] == -1 or f_links_high[f_i] < e_i + 1: # <<<<<<<<<<<<<< - * f_links_high[f_i] = e_i + 1 - * if e_links_low[e_i] == -1 or e_links_low[e_i] > f_i: - */ - __pyx_t_9 = ((__pyx_v_f_links_high[__pyx_v_f_i]) == -1); - if (!__pyx_t_9) { - __pyx_t_7 = ((__pyx_v_f_links_high[__pyx_v_f_i]) < (__pyx_v_e_i + 1)); - __pyx_t_8 = __pyx_t_7; - } else { - __pyx_t_8 = __pyx_t_9; - } - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1465 - * f_links_low[f_i] = e_i - * if f_links_high[f_i] == -1 or f_links_high[f_i] < e_i + 1: - * f_links_high[f_i] = e_i + 1 # <<<<<<<<<<<<<< - * if e_links_low[e_i] == -1 or e_links_low[e_i] > f_i: - * e_links_low[e_i] = f_i - */ - (__pyx_v_f_links_high[__pyx_v_f_i]) = (__pyx_v_e_i + 1); - goto __pyx_L15; - } - __pyx_L15:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1466 - * if f_links_high[f_i] == -1 or f_links_high[f_i] < e_i + 1: - * f_links_high[f_i] = e_i + 1 - * if e_links_low[e_i] == -1 or e_links_low[e_i] > f_i: # <<<<<<<<<<<<<< - * e_links_low[e_i] = f_i - * if e_links_high[e_i] == -1 or e_links_high[e_i] < f_i + 1: - */ - __pyx_t_8 = ((__pyx_v_e_links_low[__pyx_v_e_i]) == -1); - if (!__pyx_t_8) { - __pyx_t_9 = ((__pyx_v_e_links_low[__pyx_v_e_i]) > __pyx_v_f_i); - __pyx_t_7 = __pyx_t_9; - } else { - __pyx_t_7 = __pyx_t_8; - } - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1467 - * f_links_high[f_i] = e_i + 1 - * if e_links_low[e_i] == -1 or e_links_low[e_i] > f_i: - * e_links_low[e_i] = f_i # <<<<<<<<<<<<<< - * if e_links_high[e_i] == -1 or e_links_high[e_i] < f_i + 1: - * e_links_high[e_i] = f_i + 1 - */ - (__pyx_v_e_links_low[__pyx_v_e_i]) = __pyx_v_f_i; - goto __pyx_L16; - } - __pyx_L16:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1468 - * if e_links_low[e_i] == -1 or e_links_low[e_i] > f_i: - * e_links_low[e_i] = f_i - * if e_links_high[e_i] == -1 or e_links_high[e_i] < f_i + 1: # <<<<<<<<<<<<<< - * e_links_high[e_i] = f_i + 1 - * i = i + 2 - */ - __pyx_t_7 = ((__pyx_v_e_links_high[__pyx_v_e_i]) == -1); - if (!__pyx_t_7) { - __pyx_t_8 = ((__pyx_v_e_links_high[__pyx_v_e_i]) < (__pyx_v_f_i + 1)); - __pyx_t_9 = __pyx_t_8; - } else { - __pyx_t_9 = __pyx_t_7; - } - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1469 - * e_links_low[e_i] = f_i - * if e_links_high[e_i] == -1 or e_links_high[e_i] < f_i + 1: - * e_links_high[e_i] = f_i + 1 # <<<<<<<<<<<<<< - * i = i + 2 - * - */ - (__pyx_v_e_links_high[__pyx_v_e_i]) = (__pyx_v_f_i + 1); - goto __pyx_L17; - } - __pyx_L17:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1470 - * if e_links_high[e_i] == -1 or e_links_high[e_i] < f_i + 1: - * e_links_high[e_i] = f_i + 1 - * i = i + 2 # <<<<<<<<<<<<<< - * - * als = [] - */ - __pyx_v_i = (__pyx_v_i + 2); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1472 - * i = i + 2 - * - * als = [] # <<<<<<<<<<<<<< - * for x in range(matching.start,matching.end): - * al = (matching.arr[x]-f_sent_start,f_links_low[matching.arr[x]-f_sent_start]) - */ - __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1472; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_als = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1473 - * - * als = [] - * for x in range(matching.start,matching.end): # <<<<<<<<<<<<<< - * al = (matching.arr[x]-f_sent_start,f_links_low[matching.arr[x]-f_sent_start]) - * als.append(al) - */ - __pyx_t_3 = __pyx_v_matching->end; - for (__pyx_t_4 = __pyx_v_matching->start; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { - __pyx_v_x = __pyx_t_4; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1474 - * als = [] - * for x in range(matching.start,matching.end): - * al = (matching.arr[x]-f_sent_start,f_links_low[matching.arr[x]-f_sent_start]) # <<<<<<<<<<<<<< - * als.append(al) - * # check all source-side alignment constraints - */ - __pyx_t_2 = PyInt_FromLong(((__pyx_v_matching->arr[__pyx_v_x]) - __pyx_v_f_sent_start)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1474; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyInt_FromLong((__pyx_v_f_links_low[((__pyx_v_matching->arr[__pyx_v_x]) - __pyx_v_f_sent_start)])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1474; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1474; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_2 = 0; - __pyx_t_1 = 0; - __Pyx_XDECREF(((PyObject *)__pyx_v_al)); - __pyx_v_al = __pyx_t_10; - __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1475 - * for x in range(matching.start,matching.end): - * al = (matching.arr[x]-f_sent_start,f_links_low[matching.arr[x]-f_sent_start]) - * als.append(al) # <<<<<<<<<<<<<< - * # check all source-side alignment constraints - * met_constraints = 1 - */ - __pyx_t_11 = PyList_Append(__pyx_v_als, ((PyObject *)__pyx_v_al)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1475; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1477 - * als.append(al) - * # check all source-side alignment constraints - * met_constraints = 1 # <<<<<<<<<<<<<< - * if self.require_aligned_terminal: - * num_aligned_chunks = 0 - */ - __pyx_v_met_constraints = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1478 - * # check all source-side alignment constraints - * met_constraints = 1 - * if self.require_aligned_terminal: # <<<<<<<<<<<<<< - * num_aligned_chunks = 0 - * for i from 0 <= i < num_chunks: - */ - if (__pyx_v_self->require_aligned_terminal) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1479 - * met_constraints = 1 - * if self.require_aligned_terminal: - * num_aligned_chunks = 0 # <<<<<<<<<<<<<< - * for i from 0 <= i < num_chunks: - * for j from 0 <= j < chunklen[i]: - */ - __pyx_v_num_aligned_chunks = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1480 - * if self.require_aligned_terminal: - * num_aligned_chunks = 0 - * for i from 0 <= i < num_chunks: # <<<<<<<<<<<<<< - * for j from 0 <= j < chunklen[i]: - * if f_links_low[matching.arr[matching.start+i]+j-f_sent_start] > -1: - */ - __pyx_t_3 = __pyx_v_num_chunks; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1481 - * num_aligned_chunks = 0 - * for i from 0 <= i < num_chunks: - * for j from 0 <= j < chunklen[i]: # <<<<<<<<<<<<<< - * if f_links_low[matching.arr[matching.start+i]+j-f_sent_start] > -1: - * num_aligned_chunks = num_aligned_chunks + 1 - */ - __pyx_t_4 = (__pyx_v_chunklen[__pyx_v_i]); - for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_4; __pyx_v_j++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1482 - * for i from 0 <= i < num_chunks: - * for j from 0 <= j < chunklen[i]: - * if f_links_low[matching.arr[matching.start+i]+j-f_sent_start] > -1: # <<<<<<<<<<<<<< - * num_aligned_chunks = num_aligned_chunks + 1 - * break - */ - __pyx_t_9 = ((__pyx_v_f_links_low[(((__pyx_v_matching->arr[(__pyx_v_matching->start + __pyx_v_i)]) + __pyx_v_j) - __pyx_v_f_sent_start)]) > -1); - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1483 - * for j from 0 <= j < chunklen[i]: - * if f_links_low[matching.arr[matching.start+i]+j-f_sent_start] > -1: - * num_aligned_chunks = num_aligned_chunks + 1 # <<<<<<<<<<<<<< - * break - * if num_aligned_chunks == 0: - */ - __pyx_v_num_aligned_chunks = (__pyx_v_num_aligned_chunks + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1484 - * if f_links_low[matching.arr[matching.start+i]+j-f_sent_start] > -1: - * num_aligned_chunks = num_aligned_chunks + 1 - * break # <<<<<<<<<<<<<< - * if num_aligned_chunks == 0: - * reason_for_failure = "No aligned terminals" - */ - goto __pyx_L24_break; - goto __pyx_L25; - } - __pyx_L25:; - } - __pyx_L24_break:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1485 - * num_aligned_chunks = num_aligned_chunks + 1 - * break - * if num_aligned_chunks == 0: # <<<<<<<<<<<<<< - * reason_for_failure = "No aligned terminals" - * met_constraints = 0 - */ - __pyx_t_9 = (__pyx_v_num_aligned_chunks == 0); - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1486 - * break - * if num_aligned_chunks == 0: - * reason_for_failure = "No aligned terminals" # <<<<<<<<<<<<<< - * met_constraints = 0 - * if self.require_aligned_chunks and num_aligned_chunks < num_chunks: - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_124)); - __Pyx_DECREF(__pyx_v_reason_for_failure); - __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_124); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1487 - * if num_aligned_chunks == 0: - * reason_for_failure = "No aligned terminals" - * met_constraints = 0 # <<<<<<<<<<<<<< - * if self.require_aligned_chunks and num_aligned_chunks < num_chunks: - * reason_for_failure = "Unaligned chunk" - */ - __pyx_v_met_constraints = 0; - goto __pyx_L26; - } - __pyx_L26:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1488 - * reason_for_failure = "No aligned terminals" - * met_constraints = 0 - * if self.require_aligned_chunks and num_aligned_chunks < num_chunks: # <<<<<<<<<<<<<< - * reason_for_failure = "Unaligned chunk" - * met_constraints = 0 - */ - if (__pyx_v_self->require_aligned_chunks) { - __pyx_t_9 = (__pyx_v_num_aligned_chunks < __pyx_v_num_chunks); - __pyx_t_7 = __pyx_t_9; - } else { - __pyx_t_7 = __pyx_v_self->require_aligned_chunks; - } - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1489 - * met_constraints = 0 - * if self.require_aligned_chunks and num_aligned_chunks < num_chunks: - * reason_for_failure = "Unaligned chunk" # <<<<<<<<<<<<<< - * met_constraints = 0 - * - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_125)); - __Pyx_DECREF(__pyx_v_reason_for_failure); - __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_125); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1490 - * if self.require_aligned_chunks and num_aligned_chunks < num_chunks: - * reason_for_failure = "Unaligned chunk" - * met_constraints = 0 # <<<<<<<<<<<<<< - * - * if met_constraints and self.tight_phrases: - */ - __pyx_v_met_constraints = 0; - goto __pyx_L27; - } - __pyx_L27:; - goto __pyx_L20; - } - __pyx_L20:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1492 - * met_constraints = 0 - * - * if met_constraints and self.tight_phrases: # <<<<<<<<<<<<<< - * # outside edge constraints are checked later - * for i from 0 <= i < num_chunks-1: - */ - if (__pyx_v_met_constraints) { - __pyx_t_7 = __pyx_v_self->tight_phrases; - } else { - __pyx_t_7 = __pyx_v_met_constraints; - } - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1494 - * if met_constraints and self.tight_phrases: - * # outside edge constraints are checked later - * for i from 0 <= i < num_chunks-1: # <<<<<<<<<<<<<< - * if f_links_low[matching.arr[matching.start+i]+chunklen[i]-f_sent_start] == -1: - * reason_for_failure = "Gaps are not tight phrases" - */ - __pyx_t_12 = (__pyx_v_num_chunks - 1); - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_12; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1495 - * # outside edge constraints are checked later - * for i from 0 <= i < num_chunks-1: - * if f_links_low[matching.arr[matching.start+i]+chunklen[i]-f_sent_start] == -1: # <<<<<<<<<<<<<< - * reason_for_failure = "Gaps are not tight phrases" - * met_constraints = 0 - */ - __pyx_t_7 = ((__pyx_v_f_links_low[(((__pyx_v_matching->arr[(__pyx_v_matching->start + __pyx_v_i)]) + (__pyx_v_chunklen[__pyx_v_i])) - __pyx_v_f_sent_start)]) == -1); - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1496 - * for i from 0 <= i < num_chunks-1: - * if f_links_low[matching.arr[matching.start+i]+chunklen[i]-f_sent_start] == -1: - * reason_for_failure = "Gaps are not tight phrases" # <<<<<<<<<<<<<< - * met_constraints = 0 - * break - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_126)); - __Pyx_DECREF(__pyx_v_reason_for_failure); - __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_126); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1497 - * if f_links_low[matching.arr[matching.start+i]+chunklen[i]-f_sent_start] == -1: - * reason_for_failure = "Gaps are not tight phrases" - * met_constraints = 0 # <<<<<<<<<<<<<< - * break - * if f_links_low[matching.arr[matching.start+i+1]-1-f_sent_start] == -1: - */ - __pyx_v_met_constraints = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1498 - * reason_for_failure = "Gaps are not tight phrases" - * met_constraints = 0 - * break # <<<<<<<<<<<<<< - * if f_links_low[matching.arr[matching.start+i+1]-1-f_sent_start] == -1: - * reason_for_failure = "Gaps are not tight phrases" - */ - goto __pyx_L30_break; - goto __pyx_L31; - } - __pyx_L31:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1499 - * met_constraints = 0 - * break - * if f_links_low[matching.arr[matching.start+i+1]-1-f_sent_start] == -1: # <<<<<<<<<<<<<< - * reason_for_failure = "Gaps are not tight phrases" - * met_constraints = 0 - */ - __pyx_t_7 = ((__pyx_v_f_links_low[(((__pyx_v_matching->arr[((__pyx_v_matching->start + __pyx_v_i) + 1)]) - 1) - __pyx_v_f_sent_start)]) == -1); - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1500 - * break - * if f_links_low[matching.arr[matching.start+i+1]-1-f_sent_start] == -1: - * reason_for_failure = "Gaps are not tight phrases" # <<<<<<<<<<<<<< - * met_constraints = 0 - * break - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_126)); - __Pyx_DECREF(__pyx_v_reason_for_failure); - __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_126); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1501 - * if f_links_low[matching.arr[matching.start+i+1]-1-f_sent_start] == -1: - * reason_for_failure = "Gaps are not tight phrases" - * met_constraints = 0 # <<<<<<<<<<<<<< - * break - * - */ - __pyx_v_met_constraints = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1502 - * reason_for_failure = "Gaps are not tight phrases" - * met_constraints = 0 - * break # <<<<<<<<<<<<<< - * - * f_low = matching.arr[matching.start] - f_sent_start - */ - goto __pyx_L30_break; - goto __pyx_L32; - } - __pyx_L32:; - } - __pyx_L30_break:; - goto __pyx_L28; - } - __pyx_L28:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1504 - * break - * - * f_low = matching.arr[matching.start] - f_sent_start # <<<<<<<<<<<<<< - * f_high = matching.arr[matching.start + matching.size - 1] + chunklen[num_chunks-1] - f_sent_start - * if met_constraints: - */ - __pyx_v_f_low = ((__pyx_v_matching->arr[__pyx_v_matching->start]) - __pyx_v_f_sent_start); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1505 - * - * f_low = matching.arr[matching.start] - f_sent_start - * f_high = matching.arr[matching.start + matching.size - 1] + chunklen[num_chunks-1] - f_sent_start # <<<<<<<<<<<<<< - * if met_constraints: - * - */ - __pyx_v_f_high = (((__pyx_v_matching->arr[((__pyx_v_matching->start + __pyx_v_matching->size) - 1)]) + (__pyx_v_chunklen[(__pyx_v_num_chunks - 1)])) - __pyx_v_f_sent_start); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1506 - * f_low = matching.arr[matching.start] - f_sent_start - * f_high = matching.arr[matching.start + matching.size - 1] + chunklen[num_chunks-1] - f_sent_start - * if met_constraints: # <<<<<<<<<<<<<< - * - * if self.find_fixpoint(f_low, f_high, f_links_low, f_links_high, e_links_low, e_links_high, - */ - if (__pyx_v_met_constraints) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1508 - * if met_constraints: - * - * if self.find_fixpoint(f_low, f_high, f_links_low, f_links_high, e_links_low, e_links_high, # <<<<<<<<<<<<<< - * -1, -1, &e_low, &e_high, &f_back_low, &f_back_high, f_sent_len, e_sent_len, - * self.train_max_initial_size, self.train_max_initial_size, - */ - __pyx_t_10 = PyInt_FromLong(__pyx_v_f_high); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1508; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1512 - * self.train_max_initial_size, self.train_max_initial_size, - * self.train_min_gap_size, 0, - * self.max_nonterminals - num_chunks + 1, 1, 1, 0, 0): # <<<<<<<<<<<<<< - * gap_error = 0 - * num_gaps = 0 - */ - __pyx_t_3 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_low, __pyx_t_10, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, -1, -1, (&__pyx_v_e_low), (&__pyx_v_e_high), (&__pyx_v_f_back_low), (&__pyx_v_f_back_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_min_gap_size, 0, ((__pyx_v_self->max_nonterminals - __pyx_v_num_chunks) + 1), 1, 1, 0, 0); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1513 - * self.train_min_gap_size, 0, - * self.max_nonterminals - num_chunks + 1, 1, 1, 0, 0): - * gap_error = 0 # <<<<<<<<<<<<<< - * num_gaps = 0 - * - */ - __pyx_v_gap_error = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1514 - * self.max_nonterminals - num_chunks + 1, 1, 1, 0, 0): - * gap_error = 0 - * num_gaps = 0 # <<<<<<<<<<<<<< - * - * if f_back_low < f_low: - */ - __pyx_v_num_gaps = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1516 - * num_gaps = 0 - * - * if f_back_low < f_low: # <<<<<<<<<<<<<< - * f_gap_low[0] = f_back_low - * f_gap_high[0] = f_low - */ - __pyx_t_7 = (__pyx_v_f_back_low < __pyx_v_f_low); - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1517 - * - * if f_back_low < f_low: - * f_gap_low[0] = f_back_low # <<<<<<<<<<<<<< - * f_gap_high[0] = f_low - * num_gaps = 1 - */ - (__pyx_v_f_gap_low[0]) = __pyx_v_f_back_low; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1518 - * if f_back_low < f_low: - * f_gap_low[0] = f_back_low - * f_gap_high[0] = f_low # <<<<<<<<<<<<<< - * num_gaps = 1 - * gap_start = 0 - */ - (__pyx_v_f_gap_high[0]) = __pyx_v_f_low; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1519 - * f_gap_low[0] = f_back_low - * f_gap_high[0] = f_low - * num_gaps = 1 # <<<<<<<<<<<<<< - * gap_start = 0 - * phrase_len = phrase_len+1 - */ - __pyx_v_num_gaps = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1520 - * f_gap_high[0] = f_low - * num_gaps = 1 - * gap_start = 0 # <<<<<<<<<<<<<< - * phrase_len = phrase_len+1 - * if phrase_len > self.max_length: - */ - __pyx_v_gap_start = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1521 - * num_gaps = 1 - * gap_start = 0 - * phrase_len = phrase_len+1 # <<<<<<<<<<<<<< - * if phrase_len > self.max_length: - * gap_error = 1 - */ - __pyx_v_phrase_len = (__pyx_v_phrase_len + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1522 - * gap_start = 0 - * phrase_len = phrase_len+1 - * if phrase_len > self.max_length: # <<<<<<<<<<<<<< - * gap_error = 1 - * if self.tight_phrases: - */ - __pyx_t_7 = (__pyx_v_phrase_len > __pyx_v_self->max_length); - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1523 - * phrase_len = phrase_len+1 - * if phrase_len > self.max_length: - * gap_error = 1 # <<<<<<<<<<<<<< - * if self.tight_phrases: - * if f_links_low[f_back_low] == -1 or f_links_low[f_low-1] == -1: - */ - __pyx_v_gap_error = 1; - goto __pyx_L36; - } - __pyx_L36:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1524 - * if phrase_len > self.max_length: - * gap_error = 1 - * if self.tight_phrases: # <<<<<<<<<<<<<< - * if f_links_low[f_back_low] == -1 or f_links_low[f_low-1] == -1: - * gap_error = 1 - */ - if (__pyx_v_self->tight_phrases) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1525 - * gap_error = 1 - * if self.tight_phrases: - * if f_links_low[f_back_low] == -1 or f_links_low[f_low-1] == -1: # <<<<<<<<<<<<<< - * gap_error = 1 - * reason_for_failure = "Inside edges of preceding subphrase are not tight" - */ - __pyx_t_7 = ((__pyx_v_f_links_low[__pyx_v_f_back_low]) == -1); - if (!__pyx_t_7) { - __pyx_t_9 = ((__pyx_v_f_links_low[(__pyx_v_f_low - 1)]) == -1); - __pyx_t_8 = __pyx_t_9; - } else { - __pyx_t_8 = __pyx_t_7; - } - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1526 - * if self.tight_phrases: - * if f_links_low[f_back_low] == -1 or f_links_low[f_low-1] == -1: - * gap_error = 1 # <<<<<<<<<<<<<< - * reason_for_failure = "Inside edges of preceding subphrase are not tight" - * else: - */ - __pyx_v_gap_error = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1527 - * if f_links_low[f_back_low] == -1 or f_links_low[f_low-1] == -1: - * gap_error = 1 - * reason_for_failure = "Inside edges of preceding subphrase are not tight" # <<<<<<<<<<<<<< - * else: - * gap_start = 1 - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_127)); - __Pyx_DECREF(__pyx_v_reason_for_failure); - __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_127); - goto __pyx_L38; - } - __pyx_L38:; - goto __pyx_L37; - } - __pyx_L37:; - goto __pyx_L35; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1529 - * reason_for_failure = "Inside edges of preceding subphrase are not tight" - * else: - * gap_start = 1 # <<<<<<<<<<<<<< - * if self.tight_phrases and f_links_low[f_low] == -1: - * # this is not a hard error. we can't extract this phrase - */ - __pyx_v_gap_start = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1530 - * else: - * gap_start = 1 - * if self.tight_phrases and f_links_low[f_low] == -1: # <<<<<<<<<<<<<< - * # this is not a hard error. we can't extract this phrase - * # but we still might be able to extract a superphrase - */ - if (__pyx_v_self->tight_phrases) { - __pyx_t_8 = ((__pyx_v_f_links_low[__pyx_v_f_low]) == -1); - __pyx_t_7 = __pyx_t_8; - } else { - __pyx_t_7 = __pyx_v_self->tight_phrases; - } - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1533 - * # this is not a hard error. we can't extract this phrase - * # but we still might be able to extract a superphrase - * met_constraints = 0 # <<<<<<<<<<<<<< - * - * for i from 0 <= i < matching.size - 1: - */ - __pyx_v_met_constraints = 0; - goto __pyx_L39; - } - __pyx_L39:; - } - __pyx_L35:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1535 - * met_constraints = 0 - * - * for i from 0 <= i < matching.size - 1: # <<<<<<<<<<<<<< - * f_gap_low[1+i] = matching.arr[matching.start+i] + chunklen[i] - f_sent_start - * f_gap_high[1+i] = matching.arr[matching.start+i+1] - f_sent_start - */ - __pyx_t_12 = (__pyx_v_matching->size - 1); - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_12; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1536 - * - * for i from 0 <= i < matching.size - 1: - * f_gap_low[1+i] = matching.arr[matching.start+i] + chunklen[i] - f_sent_start # <<<<<<<<<<<<<< - * f_gap_high[1+i] = matching.arr[matching.start+i+1] - f_sent_start - * num_gaps = num_gaps + 1 - */ - (__pyx_v_f_gap_low[(1 + __pyx_v_i)]) = (((__pyx_v_matching->arr[(__pyx_v_matching->start + __pyx_v_i)]) + (__pyx_v_chunklen[__pyx_v_i])) - __pyx_v_f_sent_start); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1537 - * for i from 0 <= i < matching.size - 1: - * f_gap_low[1+i] = matching.arr[matching.start+i] + chunklen[i] - f_sent_start - * f_gap_high[1+i] = matching.arr[matching.start+i+1] - f_sent_start # <<<<<<<<<<<<<< - * num_gaps = num_gaps + 1 - * - */ - (__pyx_v_f_gap_high[(1 + __pyx_v_i)]) = ((__pyx_v_matching->arr[((__pyx_v_matching->start + __pyx_v_i) + 1)]) - __pyx_v_f_sent_start); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1538 - * f_gap_low[1+i] = matching.arr[matching.start+i] + chunklen[i] - f_sent_start - * f_gap_high[1+i] = matching.arr[matching.start+i+1] - f_sent_start - * num_gaps = num_gaps + 1 # <<<<<<<<<<<<<< - * - * if f_high < f_back_high: - */ - __pyx_v_num_gaps = (__pyx_v_num_gaps + 1); - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1540 - * num_gaps = num_gaps + 1 - * - * if f_high < f_back_high: # <<<<<<<<<<<<<< - * f_gap_low[gap_start+num_gaps] = f_high - * f_gap_high[gap_start+num_gaps] = f_back_high - */ - __pyx_t_7 = (__pyx_v_f_high < __pyx_v_f_back_high); - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1541 - * - * if f_high < f_back_high: - * f_gap_low[gap_start+num_gaps] = f_high # <<<<<<<<<<<<<< - * f_gap_high[gap_start+num_gaps] = f_back_high - * num_gaps = num_gaps + 1 - */ - (__pyx_v_f_gap_low[(__pyx_v_gap_start + __pyx_v_num_gaps)]) = __pyx_v_f_high; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1542 - * if f_high < f_back_high: - * f_gap_low[gap_start+num_gaps] = f_high - * f_gap_high[gap_start+num_gaps] = f_back_high # <<<<<<<<<<<<<< - * num_gaps = num_gaps + 1 - * phrase_len = phrase_len+1 - */ - (__pyx_v_f_gap_high[(__pyx_v_gap_start + __pyx_v_num_gaps)]) = __pyx_v_f_back_high; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1543 - * f_gap_low[gap_start+num_gaps] = f_high - * f_gap_high[gap_start+num_gaps] = f_back_high - * num_gaps = num_gaps + 1 # <<<<<<<<<<<<<< - * phrase_len = phrase_len+1 - * if phrase_len > self.max_length: - */ - __pyx_v_num_gaps = (__pyx_v_num_gaps + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1544 - * f_gap_high[gap_start+num_gaps] = f_back_high - * num_gaps = num_gaps + 1 - * phrase_len = phrase_len+1 # <<<<<<<<<<<<<< - * if phrase_len > self.max_length: - * gap_error = 1 - */ - __pyx_v_phrase_len = (__pyx_v_phrase_len + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1545 - * num_gaps = num_gaps + 1 - * phrase_len = phrase_len+1 - * if phrase_len > self.max_length: # <<<<<<<<<<<<<< - * gap_error = 1 - * if self.tight_phrases: - */ - __pyx_t_7 = (__pyx_v_phrase_len > __pyx_v_self->max_length); - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1546 - * phrase_len = phrase_len+1 - * if phrase_len > self.max_length: - * gap_error = 1 # <<<<<<<<<<<<<< - * if self.tight_phrases: - * if f_links_low[f_back_high-1] == -1 or f_links_low[f_high] == -1: - */ - __pyx_v_gap_error = 1; - goto __pyx_L43; - } - __pyx_L43:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1547 - * if phrase_len > self.max_length: - * gap_error = 1 - * if self.tight_phrases: # <<<<<<<<<<<<<< - * if f_links_low[f_back_high-1] == -1 or f_links_low[f_high] == -1: - * gap_error = 1 - */ - if (__pyx_v_self->tight_phrases) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1548 - * gap_error = 1 - * if self.tight_phrases: - * if f_links_low[f_back_high-1] == -1 or f_links_low[f_high] == -1: # <<<<<<<<<<<<<< - * gap_error = 1 - * reason_for_failure = "Inside edges of following subphrase are not tight" - */ - __pyx_t_7 = ((__pyx_v_f_links_low[(__pyx_v_f_back_high - 1)]) == -1); - if (!__pyx_t_7) { - __pyx_t_8 = ((__pyx_v_f_links_low[__pyx_v_f_high]) == -1); - __pyx_t_9 = __pyx_t_8; - } else { - __pyx_t_9 = __pyx_t_7; - } - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1549 - * if self.tight_phrases: - * if f_links_low[f_back_high-1] == -1 or f_links_low[f_high] == -1: - * gap_error = 1 # <<<<<<<<<<<<<< - * reason_for_failure = "Inside edges of following subphrase are not tight" - * else: - */ - __pyx_v_gap_error = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1550 - * if f_links_low[f_back_high-1] == -1 or f_links_low[f_high] == -1: - * gap_error = 1 - * reason_for_failure = "Inside edges of following subphrase are not tight" # <<<<<<<<<<<<<< - * else: - * if self.tight_phrases and f_links_low[f_high-1] == -1: - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_128)); - __Pyx_DECREF(__pyx_v_reason_for_failure); - __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_128); - goto __pyx_L45; - } - __pyx_L45:; - goto __pyx_L44; - } - __pyx_L44:; - goto __pyx_L42; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1552 - * reason_for_failure = "Inside edges of following subphrase are not tight" - * else: - * if self.tight_phrases and f_links_low[f_high-1] == -1: # <<<<<<<<<<<<<< - * met_constraints = 0 - * - */ - if (__pyx_v_self->tight_phrases) { - __pyx_t_9 = ((__pyx_v_f_links_low[(__pyx_v_f_high - 1)]) == -1); - __pyx_t_7 = __pyx_t_9; - } else { - __pyx_t_7 = __pyx_v_self->tight_phrases; - } - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1553 - * else: - * if self.tight_phrases and f_links_low[f_high-1] == -1: - * met_constraints = 0 # <<<<<<<<<<<<<< - * - * if gap_error == 0: - */ - __pyx_v_met_constraints = 0; - goto __pyx_L46; - } - __pyx_L46:; - } - __pyx_L42:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1555 - * met_constraints = 0 - * - * if gap_error == 0: # <<<<<<<<<<<<<< - * e_word_count = e_high - e_low - * for i from 0 <= i < num_gaps: # check integrity of subphrases - */ - __pyx_t_7 = (__pyx_v_gap_error == 0); - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1556 - * - * if gap_error == 0: - * e_word_count = e_high - e_low # <<<<<<<<<<<<<< - * for i from 0 <= i < num_gaps: # check integrity of subphrases - * if self.find_fixpoint(f_gap_low[gap_start+i], f_gap_high[gap_start+i], - */ - __pyx_v_e_word_count = (__pyx_v_e_high - __pyx_v_e_low); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1557 - * if gap_error == 0: - * e_word_count = e_high - e_low - * for i from 0 <= i < num_gaps: # check integrity of subphrases # <<<<<<<<<<<<<< - * if self.find_fixpoint(f_gap_low[gap_start+i], f_gap_high[gap_start+i], - * f_links_low, f_links_high, e_links_low, e_links_high, - */ - __pyx_t_3 = __pyx_v_num_gaps; - for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1558 - * e_word_count = e_high - e_low - * for i from 0 <= i < num_gaps: # check integrity of subphrases - * if self.find_fixpoint(f_gap_low[gap_start+i], f_gap_high[gap_start+i], # <<<<<<<<<<<<<< - * f_links_low, f_links_high, e_links_low, e_links_high, - * -1, -1, e_gap_low+gap_start+i, e_gap_high+gap_start+i, - */ - __pyx_t_10 = PyInt_FromLong((__pyx_v_f_gap_high[(__pyx_v_gap_start + __pyx_v_i)])); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1558; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1563 - * f_gap_low+gap_start+i, f_gap_high+gap_start+i, - * f_sent_len, e_sent_len, - * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< - * 0, 0, 0, 0, 0, 0, 0) == 0: - * gap_error = 1 - */ - __pyx_t_7 = (((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, (__pyx_v_f_gap_low[(__pyx_v_gap_start + __pyx_v_i)]), __pyx_t_10, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, -1, -1, ((__pyx_v_e_gap_low + __pyx_v_gap_start) + __pyx_v_i), ((__pyx_v_e_gap_high + __pyx_v_gap_start) + __pyx_v_i), ((__pyx_v_f_gap_low + __pyx_v_gap_start) + __pyx_v_i), ((__pyx_v_f_gap_high + __pyx_v_gap_start) + __pyx_v_i), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 0, 0, 0, 0, 0, 0, 0) == 0); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1565 - * self.train_max_initial_size, self.train_max_initial_size, - * 0, 0, 0, 0, 0, 0, 0) == 0: - * gap_error = 1 # <<<<<<<<<<<<<< - * reason_for_failure = "Subphrase [%d, %d] failed integrity check" % (f_gap_low[gap_start+i], f_gap_high[gap_start+i]) - * break - */ - __pyx_v_gap_error = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1566 - * 0, 0, 0, 0, 0, 0, 0) == 0: - * gap_error = 1 - * reason_for_failure = "Subphrase [%d, %d] failed integrity check" % (f_gap_low[gap_start+i], f_gap_high[gap_start+i]) # <<<<<<<<<<<<<< - * break - * - */ - __pyx_t_10 = PyInt_FromLong((__pyx_v_f_gap_low[(__pyx_v_gap_start + __pyx_v_i)])); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1566; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_1 = PyInt_FromLong((__pyx_v_f_gap_high[(__pyx_v_gap_start + __pyx_v_i)])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1566; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1566; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_10 = 0; - __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_129), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1566; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_v_reason_for_failure); - __pyx_v_reason_for_failure = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1567 - * gap_error = 1 - * reason_for_failure = "Subphrase [%d, %d] failed integrity check" % (f_gap_low[gap_start+i], f_gap_high[gap_start+i]) - * break # <<<<<<<<<<<<<< - * - * if gap_error == 0: - */ - goto __pyx_L49_break; - goto __pyx_L50; - } - __pyx_L50:; - } - __pyx_L49_break:; - goto __pyx_L47; - } - __pyx_L47:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1569 - * break - * - * if gap_error == 0: # <<<<<<<<<<<<<< - * i = 1 - * self.findexes.reset() - */ - __pyx_t_7 = (__pyx_v_gap_error == 0); - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1570 - * - * if gap_error == 0: - * i = 1 # <<<<<<<<<<<<<< - * self.findexes.reset() - * if f_back_low < f_low: - */ - __pyx_v_i = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1571 - * if gap_error == 0: - * i = 1 - * self.findexes.reset() # <<<<<<<<<<<<<< - * if f_back_low < f_low: - * fphr_arr._append(sym_setindex(self.category, i)) - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__reset); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1571; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1571; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1572 - * i = 1 - * self.findexes.reset() - * if f_back_low < f_low: # <<<<<<<<<<<<<< - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i+1 - */ - __pyx_t_7 = (__pyx_v_f_back_low < __pyx_v_f_low); - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1573 - * self.findexes.reset() - * if f_back_low < f_low: - * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * i = i+1 - * self.findexes.append(sym_setindex(self.category, i)) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1574 - * if f_back_low < f_low: - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i+1 # <<<<<<<<<<<<<< - * self.findexes.append(sym_setindex(self.category, i)) - * self.findexes.extend(self.findexes1) - */ - __pyx_v_i = (__pyx_v_i + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1575 - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i+1 - * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * self.findexes.extend(self.findexes1) - * for j from 0 <= j < phrase.n: - */ - __pyx_t_2 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L52; - } - __pyx_L52:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1576 - * i = i+1 - * self.findexes.append(sym_setindex(self.category, i)) - * self.findexes.extend(self.findexes1) # <<<<<<<<<<<<<< - * for j from 0 <= j < phrase.n: - * if sym_isvar(phrase.syms[j]): - */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__extend); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1576; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1576; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_v_self->findexes1)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self->findexes1)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->findexes1)); - __pyx_t_10 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1576; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1577 - * self.findexes.append(sym_setindex(self.category, i)) - * self.findexes.extend(self.findexes1) - * for j from 0 <= j < phrase.n: # <<<<<<<<<<<<<< - * if sym_isvar(phrase.syms[j]): - * fphr_arr._append(sym_setindex(self.category, i)) - */ - __pyx_t_3 = __pyx_v_phrase->n; - for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1578 - * self.findexes.extend(self.findexes1) - * for j from 0 <= j < phrase.n: - * if sym_isvar(phrase.syms[j]): # <<<<<<<<<<<<<< - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i + 1 - */ - __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_isvar); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1578; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = PyInt_FromLong((__pyx_v_phrase->syms[__pyx_v_j])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1578; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1578; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__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_t_10, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1578; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1578; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1579 - * for j from 0 <= j < phrase.n: - * if sym_isvar(phrase.syms[j]): - * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * i = i + 1 - * else: - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1580 - * if sym_isvar(phrase.syms[j]): - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i + 1 # <<<<<<<<<<<<<< - * else: - * fphr_arr._append(phrase.syms[j]) - */ - __pyx_v_i = (__pyx_v_i + 1); - goto __pyx_L55; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1582 - * i = i + 1 - * else: - * fphr_arr._append(phrase.syms[j]) # <<<<<<<<<<<<<< - * if f_back_high > f_high: - * fphr_arr._append(sym_setindex(self.category, i)) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, (__pyx_v_phrase->syms[__pyx_v_j])); - } - __pyx_L55:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1583 - * else: - * fphr_arr._append(phrase.syms[j]) - * if f_back_high > f_high: # <<<<<<<<<<<<<< - * fphr_arr._append(sym_setindex(self.category, i)) - * self.findexes.append(sym_setindex(self.category, i)) - */ - __pyx_t_7 = (__pyx_v_f_back_high > __pyx_v_f_high); - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1584 - * fphr_arr._append(phrase.syms[j]) - * if f_back_high > f_high: - * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * self.findexes.append(sym_setindex(self.category, i)) - * - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1585 - * if f_back_high > f_high: - * fphr_arr._append(sym_setindex(self.category, i)) - * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * - * fphr = Phrase(fphr_arr) - */ - __pyx_t_2 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1585; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1585; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L56; - } - __pyx_L56:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1587 - * self.findexes.append(sym_setindex(self.category, i)) - * - * fphr = Phrase(fphr_arr) # <<<<<<<<<<<<<< - * if met_constraints: - * phrase_list = self.extract_phrases(e_low, e_high, e_gap_low + gap_start, e_gap_high + gap_start, e_links_low, num_gaps, - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1587; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_v_fphr_arr)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_fphr_arr)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr_arr)); - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1587; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_v_fphr = ((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_t_2); - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1588 - * - * fphr = Phrase(fphr_arr) - * if met_constraints: # <<<<<<<<<<<<<< - * phrase_list = self.extract_phrases(e_low, e_high, e_gap_low + gap_start, e_gap_high + gap_start, e_links_low, num_gaps, - * f_back_low, f_back_high, f_gap_low + gap_start, f_gap_high + gap_start, f_links_low, - */ - if (__pyx_v_met_constraints) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1591 - * phrase_list = self.extract_phrases(e_low, e_high, e_gap_low + gap_start, e_gap_high + gap_start, e_links_low, num_gaps, - * f_back_low, f_back_high, f_gap_low + gap_start, f_gap_high + gap_start, f_links_low, - * matching.sent_id, e_sent_len, e_sent_start) # <<<<<<<<<<<<<< - * if len(phrase_list) > 0: - * pair_count = 1.0 / len(phrase_list) - */ - __pyx_t_2 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->extract_phrases(__pyx_v_self, __pyx_v_e_low, __pyx_v_e_high, (__pyx_v_e_gap_low + __pyx_v_gap_start), (__pyx_v_e_gap_high + __pyx_v_gap_start), __pyx_v_e_links_low, __pyx_v_num_gaps, __pyx_v_f_back_low, __pyx_v_f_back_high, (__pyx_v_f_gap_low + __pyx_v_gap_start), (__pyx_v_f_gap_high + __pyx_v_gap_start), __pyx_v_f_links_low, __pyx_v_matching->sent_id, __pyx_v_e_sent_len, __pyx_v_e_sent_start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1589; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_v_phrase_list = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1592 - * f_back_low, f_back_high, f_gap_low + gap_start, f_gap_high + gap_start, f_links_low, - * matching.sent_id, e_sent_len, e_sent_start) - * if len(phrase_list) > 0: # <<<<<<<<<<<<<< - * pair_count = 1.0 / len(phrase_list) - * else: - */ - __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_7 = (__pyx_t_13 > 0); - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1593 - * matching.sent_id, e_sent_len, e_sent_start) - * if len(phrase_list) > 0: - * pair_count = 1.0 / len(phrase_list) # <<<<<<<<<<<<<< - * else: - * pair_count = 0 - */ - __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1593; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(__pyx_t_13 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1593; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_pair_count = (1.0 / __pyx_t_13); - goto __pyx_L58; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1595 - * pair_count = 1.0 / len(phrase_list) - * else: - * pair_count = 0 # <<<<<<<<<<<<<< - * reason_for_failure = "Didn't extract anything from [%d, %d] -> [%d, %d]" % (f_back_low, f_back_high, e_low, e_high) - * for (phrase2,eindexes) in phrase_list: - */ - __pyx_v_pair_count = 0.0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1596 - * else: - * pair_count = 0 - * reason_for_failure = "Didn't extract anything from [%d, %d] -> [%d, %d]" % (f_back_low, f_back_high, e_low, e_high) # <<<<<<<<<<<<<< - * for (phrase2,eindexes) in phrase_list: - * als1 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) - */ - __pyx_t_2 = PyInt_FromLong(__pyx_v_f_back_low); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyInt_FromLong(__pyx_v_f_back_high); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = PyInt_FromLong(__pyx_v_e_low); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_14 = PyInt_FromLong(__pyx_v_e_high); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_15 = PyTuple_New(4); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_t_14); - __Pyx_GIVEREF(__pyx_t_14); - __pyx_t_2 = 0; - __pyx_t_1 = 0; - __pyx_t_10 = 0; - __pyx_t_14 = 0; - __pyx_t_14 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_130), ((PyObject *)__pyx_t_15)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_14)); - __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_v_reason_for_failure); - __pyx_v_reason_for_failure = ((PyObject *)__pyx_t_14); - __pyx_t_14 = 0; - } - __pyx_L58:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1597 - * pair_count = 0 - * reason_for_failure = "Didn't extract anything from [%d, %d] -> [%d, %d]" % (f_back_low, f_back_high, e_low, e_high) - * for (phrase2,eindexes) in phrase_list: # <<<<<<<<<<<<<< - * als1 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) - * extracts.append((fphr, phrase2, pair_count, tuple(als1))) - */ - if (PyList_CheckExact(__pyx_v_phrase_list) || PyTuple_CheckExact(__pyx_v_phrase_list)) { - __pyx_t_14 = __pyx_v_phrase_list; __Pyx_INCREF(__pyx_t_14); __pyx_t_13 = 0; - __pyx_t_16 = NULL; - } else { - __pyx_t_13 = -1; __pyx_t_14 = PyObject_GetIter(__pyx_v_phrase_list); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_16 = Py_TYPE(__pyx_t_14)->tp_iternext; - } - for (;;) { - if (!__pyx_t_16 && PyList_CheckExact(__pyx_t_14)) { - if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_14)) break; - __pyx_t_15 = PyList_GET_ITEM(__pyx_t_14, __pyx_t_13); __Pyx_INCREF(__pyx_t_15); __pyx_t_13++; - } else if (!__pyx_t_16 && PyTuple_CheckExact(__pyx_t_14)) { - if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_14)) break; - __pyx_t_15 = PyTuple_GET_ITEM(__pyx_t_14, __pyx_t_13); __Pyx_INCREF(__pyx_t_15); __pyx_t_13++; - } else { - __pyx_t_15 = __pyx_t_16(__pyx_t_14); - if (unlikely(!__pyx_t_15)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_15); - } - if ((likely(PyTuple_CheckExact(__pyx_t_15))) || (PyList_CheckExact(__pyx_t_15))) { - PyObject* sequence = __pyx_t_15; - if (likely(PyTuple_CheckExact(sequence))) { - 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[8]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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[8]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_10 = PyList_GET_ITEM(sequence, 0); - __pyx_t_1 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_2 = PyObject_GetIter(__pyx_t_15); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_17 = Py_TYPE(__pyx_t_2)->tp_iternext; - index = 0; __pyx_t_10 = __pyx_t_17(__pyx_t_2); if (unlikely(!__pyx_t_10)) goto __pyx_L61_unpacking_failed; - __Pyx_GOTREF(__pyx_t_10); - index = 1; __pyx_t_1 = __pyx_t_17(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L61_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_2), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L62_unpacking_done; - __pyx_L61_unpacking_failed:; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L62_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_phrase2); - __pyx_v_phrase2 = __pyx_t_10; - __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_v_eindexes); - __pyx_v_eindexes = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1598 - * reason_for_failure = "Didn't extract anything from [%d, %d] -> [%d, %d]" % (f_back_low, f_back_high, e_low, e_high) - * for (phrase2,eindexes) in phrase_list: - * als1 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) # <<<<<<<<<<<<<< - * extracts.append((fphr, phrase2, pair_count, tuple(als1))) - * - */ - __pyx_t_15 = ((PyObject *)__pyx_v_self->findexes); - __Pyx_INCREF(__pyx_t_15); - __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->create_alignments(__pyx_v_self, __pyx_v_sent_links, __pyx_v_num_links, __pyx_t_15, __pyx_v_eindexes); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_XDECREF(__pyx_v_als1); - __pyx_v_als1 = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1599 - * for (phrase2,eindexes) in phrase_list: - * als1 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) - * extracts.append((fphr, phrase2, pair_count, tuple(als1))) # <<<<<<<<<<<<<< - * - * if (num_gaps < self.max_nonterminals and - */ - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_pair_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_INCREF(__pyx_v_als1); - PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_als1); - __Pyx_GIVEREF(__pyx_v_als1); - __pyx_t_10 = PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; - __pyx_t_15 = PyTuple_New(4); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_INCREF(((PyObject *)__pyx_v_fphr)); - PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)__pyx_v_fphr)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr)); - __Pyx_INCREF(__pyx_v_phrase2); - PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_v_phrase2); - __Pyx_GIVEREF(__pyx_v_phrase2); - PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_t_1 = 0; - __pyx_t_10 = 0; - __pyx_t_10 = __Pyx_PyObject_Append(__pyx_v_extracts, ((PyObject *)__pyx_t_15)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1599; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - goto __pyx_L57; - } - __pyx_L57:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1601 - * extracts.append((fphr, phrase2, pair_count, tuple(als1))) - * - * if (num_gaps < self.max_nonterminals and # <<<<<<<<<<<<<< - * phrase_len < self.max_length and - * f_back_high - f_back_low + self.train_min_gap_size <= self.train_max_initial_size): - */ - __pyx_t_7 = (__pyx_v_num_gaps < __pyx_v_self->max_nonterminals); - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1602 - * - * if (num_gaps < self.max_nonterminals and - * phrase_len < self.max_length and # <<<<<<<<<<<<<< - * f_back_high - f_back_low + self.train_min_gap_size <= self.train_max_initial_size): - * if (f_back_low == f_low and - */ - __pyx_t_9 = (__pyx_v_phrase_len < __pyx_v_self->max_length); - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1603 - * if (num_gaps < self.max_nonterminals and - * phrase_len < self.max_length and - * f_back_high - f_back_low + self.train_min_gap_size <= self.train_max_initial_size): # <<<<<<<<<<<<<< - * if (f_back_low == f_low and - * f_low >= self.train_min_gap_size and - */ - __pyx_t_8 = (((__pyx_v_f_back_high - __pyx_v_f_back_low) + __pyx_v_self->train_min_gap_size) <= __pyx_v_self->train_max_initial_size); - __pyx_t_18 = __pyx_t_8; - } else { - __pyx_t_18 = __pyx_t_9; - } - __pyx_t_9 = __pyx_t_18; - } else { - __pyx_t_9 = __pyx_t_7; - } - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1604 - * phrase_len < self.max_length and - * f_back_high - f_back_low + self.train_min_gap_size <= self.train_max_initial_size): - * if (f_back_low == f_low and # <<<<<<<<<<<<<< - * f_low >= self.train_min_gap_size and - * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_back_high-1] != -1))): - */ - __pyx_t_9 = (__pyx_v_f_back_low == __pyx_v_f_low); - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1605 - * f_back_high - f_back_low + self.train_min_gap_size <= self.train_max_initial_size): - * if (f_back_low == f_low and - * f_low >= self.train_min_gap_size and # <<<<<<<<<<<<<< - * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_back_high-1] != -1))): - * f_x_low = f_low-self.train_min_gap_size - */ - __pyx_t_7 = (__pyx_v_f_low >= __pyx_v_self->train_min_gap_size); - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1606 - * if (f_back_low == f_low and - * f_low >= self.train_min_gap_size and - * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_back_high-1] != -1))): # <<<<<<<<<<<<<< - * f_x_low = f_low-self.train_min_gap_size - * met_constraints = 1 - */ - __pyx_t_18 = (!__pyx_v_self->tight_phrases); - if (!__pyx_t_18) { - __pyx_t_8 = ((__pyx_v_f_links_low[(__pyx_v_f_low - 1)]) != -1); - if (__pyx_t_8) { - __pyx_t_19 = ((__pyx_v_f_links_low[(__pyx_v_f_back_high - 1)]) != -1); - __pyx_t_20 = __pyx_t_19; - } else { - __pyx_t_20 = __pyx_t_8; - } - __pyx_t_8 = __pyx_t_20; - } else { - __pyx_t_8 = __pyx_t_18; - } - __pyx_t_18 = __pyx_t_8; - } else { - __pyx_t_18 = __pyx_t_7; - } - __pyx_t_7 = __pyx_t_18; - } else { - __pyx_t_7 = __pyx_t_9; - } - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1607 - * f_low >= self.train_min_gap_size and - * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_back_high-1] != -1))): - * f_x_low = f_low-self.train_min_gap_size # <<<<<<<<<<<<<< - * met_constraints = 1 - * if self.tight_phrases: - */ - __pyx_v_f_x_low = (__pyx_v_f_low - __pyx_v_self->train_min_gap_size); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1608 - * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_back_high-1] != -1))): - * f_x_low = f_low-self.train_min_gap_size - * met_constraints = 1 # <<<<<<<<<<<<<< - * if self.tight_phrases: - * while f_x_low >= 0 and f_links_low[f_x_low] == -1: - */ - __pyx_v_met_constraints = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1609 - * f_x_low = f_low-self.train_min_gap_size - * met_constraints = 1 - * if self.tight_phrases: # <<<<<<<<<<<<<< - * while f_x_low >= 0 and f_links_low[f_x_low] == -1: - * f_x_low = f_x_low - 1 - */ - if (__pyx_v_self->tight_phrases) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1610 - * met_constraints = 1 - * if self.tight_phrases: - * while f_x_low >= 0 and f_links_low[f_x_low] == -1: # <<<<<<<<<<<<<< - * f_x_low = f_x_low - 1 - * if f_x_low < 0 or f_back_high - f_x_low > self.train_max_initial_size: - */ - while (1) { - __pyx_t_7 = (__pyx_v_f_x_low >= 0); - if (__pyx_t_7) { - __pyx_t_9 = ((__pyx_v_f_links_low[__pyx_v_f_x_low]) == -1); - __pyx_t_18 = __pyx_t_9; - } else { - __pyx_t_18 = __pyx_t_7; - } - if (!__pyx_t_18) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1611 - * if self.tight_phrases: - * while f_x_low >= 0 and f_links_low[f_x_low] == -1: - * f_x_low = f_x_low - 1 # <<<<<<<<<<<<<< - * if f_x_low < 0 or f_back_high - f_x_low > self.train_max_initial_size: - * met_constraints = 0 - */ - __pyx_v_f_x_low = (__pyx_v_f_x_low - 1); - } - goto __pyx_L65; - } - __pyx_L65:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1612 - * while f_x_low >= 0 and f_links_low[f_x_low] == -1: - * f_x_low = f_x_low - 1 - * if f_x_low < 0 or f_back_high - f_x_low > self.train_max_initial_size: # <<<<<<<<<<<<<< - * met_constraints = 0 - * - */ - __pyx_t_18 = (__pyx_v_f_x_low < 0); - if (!__pyx_t_18) { - __pyx_t_7 = ((__pyx_v_f_back_high - __pyx_v_f_x_low) > __pyx_v_self->train_max_initial_size); - __pyx_t_9 = __pyx_t_7; - } else { - __pyx_t_9 = __pyx_t_18; - } - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1613 - * f_x_low = f_x_low - 1 - * if f_x_low < 0 or f_back_high - f_x_low > self.train_max_initial_size: - * met_constraints = 0 # <<<<<<<<<<<<<< - * - * if (met_constraints and - */ - __pyx_v_met_constraints = 0; - goto __pyx_L68; - } - __pyx_L68:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1615 - * met_constraints = 0 - * - * if (met_constraints and # <<<<<<<<<<<<<< - * self.find_fixpoint(f_x_low, f_back_high, - * f_links_low, f_links_high, e_links_low, e_links_high, - */ - if (__pyx_v_met_constraints) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1616 - * - * if (met_constraints and - * self.find_fixpoint(f_x_low, f_back_high, # <<<<<<<<<<<<<< - * f_links_low, f_links_high, e_links_low, e_links_high, - * e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, - */ - __pyx_t_14 = PyInt_FromLong(__pyx_v_f_back_high); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1616; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1620 - * e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, - * f_sent_len, e_sent_len, - * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< - * 1, 1, 1, 1, 0, 1, 0) and - * ((not self.tight_phrases) or f_links_low[f_x_low] != -1) and - */ - if (((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_x_low, __pyx_t_14, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_e_low, __pyx_v_e_high, (&__pyx_v_e_x_low), (&__pyx_v_e_x_high), (&__pyx_v_f_x_low), (&__pyx_v_f_x_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 1, 1, 1, 1, 0, 1, 0)) { - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1622 - * self.train_max_initial_size, self.train_max_initial_size, - * 1, 1, 1, 1, 0, 1, 0) and - * ((not self.tight_phrases) or f_links_low[f_x_low] != -1) and # <<<<<<<<<<<<<< - * self.find_fixpoint(f_x_low, f_low, # check integrity of new subphrase - * f_links_low, f_links_high, e_links_low, e_links_high, - */ - __pyx_t_9 = (!__pyx_v_self->tight_phrases); - if (!__pyx_t_9) { - __pyx_t_18 = ((__pyx_v_f_links_low[__pyx_v_f_x_low]) != -1); - __pyx_t_7 = __pyx_t_18; - } else { - __pyx_t_7 = __pyx_t_9; - } - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1623 - * 1, 1, 1, 1, 0, 1, 0) and - * ((not self.tight_phrases) or f_links_low[f_x_low] != -1) and - * self.find_fixpoint(f_x_low, f_low, # check integrity of new subphrase # <<<<<<<<<<<<<< - * f_links_low, f_links_high, e_links_low, e_links_high, - * -1, -1, e_gap_low, e_gap_high, f_gap_low, f_gap_high, - */ - __pyx_t_10 = PyInt_FromLong(__pyx_v_f_low); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1623; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1627 - * -1, -1, e_gap_low, e_gap_high, f_gap_low, f_gap_high, - * f_sent_len, e_sent_len, - * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< - * 0, 0, 0, 0, 0, 0, 0)): - * fphr_arr._clear() - */ - __pyx_t_9 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_x_low, __pyx_t_10, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, -1, -1, __pyx_v_e_gap_low, __pyx_v_e_gap_high, __pyx_v_f_gap_low, __pyx_v_f_gap_high, __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 0, 0, 0, 0, 0, 0, 0); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } else { - __pyx_t_9 = __pyx_t_7; - } - __pyx_t_7 = __pyx_t_9; - } else { - __pyx_t_7 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_x_low, __pyx_t_14, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_e_low, __pyx_v_e_high, (&__pyx_v_e_x_low), (&__pyx_v_e_x_high), (&__pyx_v_f_x_low), (&__pyx_v_f_x_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 1, 1, 1, 1, 0, 1, 0); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - } - __pyx_t_9 = __pyx_t_7; - } else { - __pyx_t_9 = __pyx_v_met_constraints; - } - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1629 - * self.train_max_initial_size, self.train_max_initial_size, - * 0, 0, 0, 0, 0, 0, 0)): - * fphr_arr._clear() # <<<<<<<<<<<<<< - * i = 1 - * self.findexes.reset() - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_clear(__pyx_v_fphr_arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1630 - * 0, 0, 0, 0, 0, 0, 0)): - * fphr_arr._clear() - * i = 1 # <<<<<<<<<<<<<< - * self.findexes.reset() - * self.findexes.append(sym_setindex(self.category, i)) - */ - __pyx_v_i = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1631 - * fphr_arr._clear() - * i = 1 - * self.findexes.reset() # <<<<<<<<<<<<<< - * self.findexes.append(sym_setindex(self.category, i)) - * fphr_arr._append(sym_setindex(self.category, i)) - */ - __pyx_t_14 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__reset); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1631; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_10 = PyObject_Call(__pyx_t_14, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1631; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1632 - * i = 1 - * self.findexes.reset() - * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i+1 - */ - __pyx_t_10 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1632; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_14 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_10); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1632; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1633 - * self.findexes.reset() - * self.findexes.append(sym_setindex(self.category, i)) - * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * i = i+1 - * self.findexes.extend(self.findexes1) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1634 - * self.findexes.append(sym_setindex(self.category, i)) - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i+1 # <<<<<<<<<<<<<< - * self.findexes.extend(self.findexes1) - * for j from 0 <= j < phrase.n: - */ - __pyx_v_i = (__pyx_v_i + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1635 - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i+1 - * self.findexes.extend(self.findexes1) # <<<<<<<<<<<<<< - * for j from 0 <= j < phrase.n: - * if sym_isvar(phrase.syms[j]): - */ - __pyx_t_14 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__extend); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1635; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1635; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(((PyObject *)__pyx_v_self->findexes1)); - PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_v_self->findexes1)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->findexes1)); - __pyx_t_15 = PyObject_Call(__pyx_t_14, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1635; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1636 - * i = i+1 - * self.findexes.extend(self.findexes1) - * for j from 0 <= j < phrase.n: # <<<<<<<<<<<<<< - * if sym_isvar(phrase.syms[j]): - * fphr_arr._append(sym_setindex(self.category, i)) - */ - __pyx_t_3 = __pyx_v_phrase->n; - for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1637 - * self.findexes.extend(self.findexes1) - * for j from 0 <= j < phrase.n: - * if sym_isvar(phrase.syms[j]): # <<<<<<<<<<<<<< - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i + 1 - */ - __pyx_t_15 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_isvar); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_10 = PyInt_FromLong((__pyx_v_phrase->syms[__pyx_v_j])); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_t_10 = 0; - __pyx_t_10 = PyObject_Call(__pyx_t_15, ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; - __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1637; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1638 - * for j from 0 <= j < phrase.n: - * if sym_isvar(phrase.syms[j]): - * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * i = i + 1 - * else: - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1639 - * if sym_isvar(phrase.syms[j]): - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i + 1 # <<<<<<<<<<<<<< - * else: - * fphr_arr._append(phrase.syms[j]) - */ - __pyx_v_i = (__pyx_v_i + 1); - goto __pyx_L72; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1641 - * i = i + 1 - * else: - * fphr_arr._append(phrase.syms[j]) # <<<<<<<<<<<<<< - * if f_back_high > f_high: - * fphr_arr._append(sym_setindex(self.category, i)) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, (__pyx_v_phrase->syms[__pyx_v_j])); - } - __pyx_L72:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1642 - * else: - * fphr_arr._append(phrase.syms[j]) - * if f_back_high > f_high: # <<<<<<<<<<<<<< - * fphr_arr._append(sym_setindex(self.category, i)) - * self.findexes.append(sym_setindex(self.category, i)) - */ - __pyx_t_9 = (__pyx_v_f_back_high > __pyx_v_f_high); - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1643 - * fphr_arr._append(phrase.syms[j]) - * if f_back_high > f_high: - * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * self.findexes.append(sym_setindex(self.category, i)) - * fphr = Phrase(fphr_arr) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1644 - * if f_back_high > f_high: - * fphr_arr._append(sym_setindex(self.category, i)) - * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * fphr = Phrase(fphr_arr) - * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+1, - */ - __pyx_t_10 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1644; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_14 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_10); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1644; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - goto __pyx_L73; - } - __pyx_L73:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1645 - * fphr_arr._append(sym_setindex(self.category, i)) - * self.findexes.append(sym_setindex(self.category, i)) - * fphr = Phrase(fphr_arr) # <<<<<<<<<<<<<< - * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+1, - * f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, matching.sent_id, - */ - __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1645; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_INCREF(((PyObject *)__pyx_v_fphr_arr)); - PyTuple_SET_ITEM(__pyx_t_14, 0, ((PyObject *)__pyx_v_fphr_arr)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr_arr)); - __pyx_t_10 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1645; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_fphr)); - __pyx_v_fphr = ((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_t_10); - __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1648 - * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+1, - * f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, matching.sent_id, - * e_sent_len, e_sent_start) # <<<<<<<<<<<<<< - * if len(phrase_list) > 0: - * pair_count = 1.0 / len(phrase_list) - */ - __pyx_t_10 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->extract_phrases(__pyx_v_self, __pyx_v_e_x_low, __pyx_v_e_x_high, __pyx_v_e_gap_low, __pyx_v_e_gap_high, __pyx_v_e_links_low, (__pyx_v_num_gaps + 1), __pyx_v_f_x_low, __pyx_v_f_x_high, __pyx_v_f_gap_low, __pyx_v_f_gap_high, __pyx_v_f_links_low, __pyx_v_matching->sent_id, __pyx_v_e_sent_len, __pyx_v_e_sent_start); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1646; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_v_phrase_list); - __pyx_v_phrase_list = __pyx_t_10; - __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1649 - * f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, matching.sent_id, - * e_sent_len, e_sent_start) - * if len(phrase_list) > 0: # <<<<<<<<<<<<<< - * pair_count = 1.0 / len(phrase_list) - * else: - */ - __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1649; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_9 = (__pyx_t_13 > 0); - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1650 - * e_sent_len, e_sent_start) - * if len(phrase_list) > 0: - * pair_count = 1.0 / len(phrase_list) # <<<<<<<<<<<<<< - * else: - * pair_count = 0 - */ - __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1650; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(__pyx_t_13 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1650; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_pair_count = (1.0 / __pyx_t_13); - goto __pyx_L74; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1652 - * pair_count = 1.0 / len(phrase_list) - * else: - * pair_count = 0 # <<<<<<<<<<<<<< - * for phrase2,eindexes in phrase_list: - * als2 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) - */ - __pyx_v_pair_count = 0.0; - } - __pyx_L74:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1653 - * else: - * pair_count = 0 - * for phrase2,eindexes in phrase_list: # <<<<<<<<<<<<<< - * als2 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) - * extracts.append((fphr, phrase2, pair_count, tuple(als2))) - */ - if (PyList_CheckExact(__pyx_v_phrase_list) || PyTuple_CheckExact(__pyx_v_phrase_list)) { - __pyx_t_10 = __pyx_v_phrase_list; __Pyx_INCREF(__pyx_t_10); __pyx_t_13 = 0; - __pyx_t_16 = NULL; - } else { - __pyx_t_13 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_v_phrase_list); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_16 = Py_TYPE(__pyx_t_10)->tp_iternext; - } - for (;;) { - if (!__pyx_t_16 && PyList_CheckExact(__pyx_t_10)) { - if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_10)) break; - __pyx_t_14 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_13); __Pyx_INCREF(__pyx_t_14); __pyx_t_13++; - } else if (!__pyx_t_16 && PyTuple_CheckExact(__pyx_t_10)) { - if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_10)) break; - __pyx_t_14 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_13); __Pyx_INCREF(__pyx_t_14); __pyx_t_13++; - } else { - __pyx_t_14 = __pyx_t_16(__pyx_t_10); - if (unlikely(!__pyx_t_14)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_14); - } - if ((likely(PyTuple_CheckExact(__pyx_t_14))) || (PyList_CheckExact(__pyx_t_14))) { - PyObject* sequence = __pyx_t_14; - if (likely(PyTuple_CheckExact(sequence))) { - 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[8]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_15 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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[8]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_15 = PyList_GET_ITEM(sequence, 0); - __pyx_t_1 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_15); - __Pyx_INCREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_2 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_17 = Py_TYPE(__pyx_t_2)->tp_iternext; - index = 0; __pyx_t_15 = __pyx_t_17(__pyx_t_2); if (unlikely(!__pyx_t_15)) goto __pyx_L77_unpacking_failed; - __Pyx_GOTREF(__pyx_t_15); - index = 1; __pyx_t_1 = __pyx_t_17(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L77_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_2), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L78_unpacking_done; - __pyx_L77_unpacking_failed:; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L78_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_phrase2); - __pyx_v_phrase2 = __pyx_t_15; - __pyx_t_15 = 0; - __Pyx_XDECREF(__pyx_v_eindexes); - __pyx_v_eindexes = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1654 - * pair_count = 0 - * for phrase2,eindexes in phrase_list: - * als2 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) # <<<<<<<<<<<<<< - * extracts.append((fphr, phrase2, pair_count, tuple(als2))) - * - */ - __pyx_t_14 = ((PyObject *)__pyx_v_self->findexes); - __Pyx_INCREF(__pyx_t_14); - __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->create_alignments(__pyx_v_self, __pyx_v_sent_links, __pyx_v_num_links, __pyx_t_14, __pyx_v_eindexes); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1654; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_XDECREF(__pyx_v_als2); - __pyx_v_als2 = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1655 - * for phrase2,eindexes in phrase_list: - * als2 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) - * extracts.append((fphr, phrase2, pair_count, tuple(als2))) # <<<<<<<<<<<<<< - * - * if (f_back_high == f_high and - */ - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_pair_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_INCREF(__pyx_v_als2); - PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_v_als2); - __Pyx_GIVEREF(__pyx_v_als2); - __pyx_t_15 = PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; - __pyx_t_14 = PyTuple_New(4); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_INCREF(((PyObject *)__pyx_v_fphr)); - PyTuple_SET_ITEM(__pyx_t_14, 0, ((PyObject *)__pyx_v_fphr)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr)); - __Pyx_INCREF(__pyx_v_phrase2); - PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_v_phrase2); - __Pyx_GIVEREF(__pyx_v_phrase2); - PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_14, 3, __pyx_t_15); - __Pyx_GIVEREF(__pyx_t_15); - __pyx_t_1 = 0; - __pyx_t_15 = 0; - __pyx_t_15 = __Pyx_PyObject_Append(__pyx_v_extracts, ((PyObject *)__pyx_t_14)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1655; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - goto __pyx_L69; - } - __pyx_L69:; - goto __pyx_L64; - } - __pyx_L64:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1657 - * extracts.append((fphr, phrase2, pair_count, tuple(als2))) - * - * if (f_back_high == f_high and # <<<<<<<<<<<<<< - * f_sent_len - f_high >= self.train_min_gap_size and - * ((not self.tight_phrases) or (f_links_low[f_high] != -1 and f_links_low[f_back_low] != -1))): - */ - __pyx_t_9 = (__pyx_v_f_back_high == __pyx_v_f_high); - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1658 - * - * if (f_back_high == f_high and - * f_sent_len - f_high >= self.train_min_gap_size and # <<<<<<<<<<<<<< - * ((not self.tight_phrases) or (f_links_low[f_high] != -1 and f_links_low[f_back_low] != -1))): - * f_x_high = f_high+self.train_min_gap_size - */ - __pyx_t_7 = ((__pyx_v_f_sent_len - __pyx_v_f_high) >= __pyx_v_self->train_min_gap_size); - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1659 - * if (f_back_high == f_high and - * f_sent_len - f_high >= self.train_min_gap_size and - * ((not self.tight_phrases) or (f_links_low[f_high] != -1 and f_links_low[f_back_low] != -1))): # <<<<<<<<<<<<<< - * f_x_high = f_high+self.train_min_gap_size - * met_constraints = 1 - */ - __pyx_t_18 = (!__pyx_v_self->tight_phrases); - if (!__pyx_t_18) { - __pyx_t_8 = ((__pyx_v_f_links_low[__pyx_v_f_high]) != -1); - if (__pyx_t_8) { - __pyx_t_20 = ((__pyx_v_f_links_low[__pyx_v_f_back_low]) != -1); - __pyx_t_19 = __pyx_t_20; - } else { - __pyx_t_19 = __pyx_t_8; - } - __pyx_t_8 = __pyx_t_19; - } else { - __pyx_t_8 = __pyx_t_18; - } - __pyx_t_18 = __pyx_t_8; - } else { - __pyx_t_18 = __pyx_t_7; - } - __pyx_t_7 = __pyx_t_18; - } else { - __pyx_t_7 = __pyx_t_9; - } - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1660 - * f_sent_len - f_high >= self.train_min_gap_size and - * ((not self.tight_phrases) or (f_links_low[f_high] != -1 and f_links_low[f_back_low] != -1))): - * f_x_high = f_high+self.train_min_gap_size # <<<<<<<<<<<<<< - * met_constraints = 1 - * if self.tight_phrases: - */ - __pyx_v_f_x_high = (__pyx_v_f_high + __pyx_v_self->train_min_gap_size); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1661 - * ((not self.tight_phrases) or (f_links_low[f_high] != -1 and f_links_low[f_back_low] != -1))): - * f_x_high = f_high+self.train_min_gap_size - * met_constraints = 1 # <<<<<<<<<<<<<< - * if self.tight_phrases: - * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: - */ - __pyx_v_met_constraints = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1662 - * f_x_high = f_high+self.train_min_gap_size - * met_constraints = 1 - * if self.tight_phrases: # <<<<<<<<<<<<<< - * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: - * f_x_high = f_x_high + 1 - */ - if (__pyx_v_self->tight_phrases) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1663 - * met_constraints = 1 - * if self.tight_phrases: - * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: # <<<<<<<<<<<<<< - * f_x_high = f_x_high + 1 - * if f_x_high > f_sent_len or f_x_high - f_back_low > self.train_max_initial_size: - */ - while (1) { - __pyx_t_7 = (__pyx_v_f_x_high <= __pyx_v_f_sent_len); - if (__pyx_t_7) { - __pyx_t_9 = ((__pyx_v_f_links_low[(__pyx_v_f_x_high - 1)]) == -1); - __pyx_t_18 = __pyx_t_9; - } else { - __pyx_t_18 = __pyx_t_7; - } - if (!__pyx_t_18) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1664 - * if self.tight_phrases: - * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: - * f_x_high = f_x_high + 1 # <<<<<<<<<<<<<< - * if f_x_high > f_sent_len or f_x_high - f_back_low > self.train_max_initial_size: - * met_constraints = 0 - */ - __pyx_v_f_x_high = (__pyx_v_f_x_high + 1); - } - goto __pyx_L80; - } - __pyx_L80:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1665 - * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: - * f_x_high = f_x_high + 1 - * if f_x_high > f_sent_len or f_x_high - f_back_low > self.train_max_initial_size: # <<<<<<<<<<<<<< - * met_constraints = 0 - * - */ - __pyx_t_18 = (__pyx_v_f_x_high > __pyx_v_f_sent_len); - if (!__pyx_t_18) { - __pyx_t_7 = ((__pyx_v_f_x_high - __pyx_v_f_back_low) > __pyx_v_self->train_max_initial_size); - __pyx_t_9 = __pyx_t_7; - } else { - __pyx_t_9 = __pyx_t_18; - } - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1666 - * f_x_high = f_x_high + 1 - * if f_x_high > f_sent_len or f_x_high - f_back_low > self.train_max_initial_size: - * met_constraints = 0 # <<<<<<<<<<<<<< - * - * if (met_constraints and - */ - __pyx_v_met_constraints = 0; - goto __pyx_L83; - } - __pyx_L83:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1668 - * met_constraints = 0 - * - * if (met_constraints and # <<<<<<<<<<<<<< - * self.find_fixpoint(f_back_low, f_x_high, - * f_links_low, f_links_high, e_links_low, e_links_high, - */ - if (__pyx_v_met_constraints) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1669 - * - * if (met_constraints and - * self.find_fixpoint(f_back_low, f_x_high, # <<<<<<<<<<<<<< - * f_links_low, f_links_high, e_links_low, e_links_high, - * e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, - */ - __pyx_t_10 = PyInt_FromLong(__pyx_v_f_x_high); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1669; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1673 - * e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, - * f_sent_len, e_sent_len, - * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< - * 1, 1, 1, 0, 1, 1, 0) and - * ((not self.tight_phrases) or f_links_low[f_x_high-1] != -1) and - */ - if (((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_back_low, __pyx_t_10, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_e_low, __pyx_v_e_high, (&__pyx_v_e_x_low), (&__pyx_v_e_x_high), (&__pyx_v_f_x_low), (&__pyx_v_f_x_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 1, 1, 1, 0, 1, 1, 0)) { - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1675 - * self.train_max_initial_size, self.train_max_initial_size, - * 1, 1, 1, 0, 1, 1, 0) and - * ((not self.tight_phrases) or f_links_low[f_x_high-1] != -1) and # <<<<<<<<<<<<<< - * self.find_fixpoint(f_high, f_x_high, - * f_links_low, f_links_high, e_links_low, e_links_high, - */ - __pyx_t_9 = (!__pyx_v_self->tight_phrases); - if (!__pyx_t_9) { - __pyx_t_18 = ((__pyx_v_f_links_low[(__pyx_v_f_x_high - 1)]) != -1); - __pyx_t_7 = __pyx_t_18; - } else { - __pyx_t_7 = __pyx_t_9; - } - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1676 - * 1, 1, 1, 0, 1, 1, 0) and - * ((not self.tight_phrases) or f_links_low[f_x_high-1] != -1) and - * self.find_fixpoint(f_high, f_x_high, # <<<<<<<<<<<<<< - * f_links_low, f_links_high, e_links_low, e_links_high, - * -1, -1, e_gap_low+gap_start+num_gaps, e_gap_high+gap_start+num_gaps, - */ - __pyx_t_15 = PyInt_FromLong(__pyx_v_f_x_high); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1676; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1681 - * f_gap_low+gap_start+num_gaps, f_gap_high+gap_start+num_gaps, - * f_sent_len, e_sent_len, - * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< - * 0, 0, 0, 0, 0, 0, 0)): - * fphr_arr._clear() - */ - __pyx_t_9 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_high, __pyx_t_15, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, -1, -1, ((__pyx_v_e_gap_low + __pyx_v_gap_start) + __pyx_v_num_gaps), ((__pyx_v_e_gap_high + __pyx_v_gap_start) + __pyx_v_num_gaps), ((__pyx_v_f_gap_low + __pyx_v_gap_start) + __pyx_v_num_gaps), ((__pyx_v_f_gap_high + __pyx_v_gap_start) + __pyx_v_num_gaps), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 0, 0, 0, 0, 0, 0, 0); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - } else { - __pyx_t_9 = __pyx_t_7; - } - __pyx_t_7 = __pyx_t_9; - } else { - __pyx_t_7 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_back_low, __pyx_t_10, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_e_low, __pyx_v_e_high, (&__pyx_v_e_x_low), (&__pyx_v_e_x_high), (&__pyx_v_f_x_low), (&__pyx_v_f_x_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 1, 1, 1, 0, 1, 1, 0); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - __pyx_t_9 = __pyx_t_7; - } else { - __pyx_t_9 = __pyx_v_met_constraints; - } - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1683 - * self.train_max_initial_size, self.train_max_initial_size, - * 0, 0, 0, 0, 0, 0, 0)): - * fphr_arr._clear() # <<<<<<<<<<<<<< - * i = 1 - * self.findexes.reset() - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_clear(__pyx_v_fphr_arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1684 - * 0, 0, 0, 0, 0, 0, 0)): - * fphr_arr._clear() - * i = 1 # <<<<<<<<<<<<<< - * self.findexes.reset() - * if f_back_low < f_low: - */ - __pyx_v_i = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1685 - * fphr_arr._clear() - * i = 1 - * self.findexes.reset() # <<<<<<<<<<<<<< - * if f_back_low < f_low: - * fphr_arr._append(sym_setindex(self.category, i)) - */ - __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__reset); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1685; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_15 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1685; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1686 - * i = 1 - * self.findexes.reset() - * if f_back_low < f_low: # <<<<<<<<<<<<<< - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i+1 - */ - __pyx_t_9 = (__pyx_v_f_back_low < __pyx_v_f_low); - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1687 - * self.findexes.reset() - * if f_back_low < f_low: - * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * i = i+1 - * self.findexes.append(sym_setindex(self.category, i)) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1688 - * if f_back_low < f_low: - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i+1 # <<<<<<<<<<<<<< - * self.findexes.append(sym_setindex(self.category, i)) - * self.findexes.extend(self.findexes1) - */ - __pyx_v_i = (__pyx_v_i + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1689 - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i+1 - * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * self.findexes.extend(self.findexes1) - * for j from 0 <= j < phrase.n: - */ - __pyx_t_15 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1689; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_10 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_15); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1689; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - goto __pyx_L85; - } - __pyx_L85:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1690 - * i = i+1 - * self.findexes.append(sym_setindex(self.category, i)) - * self.findexes.extend(self.findexes1) # <<<<<<<<<<<<<< - * for j from 0 <= j < phrase.n: - * if sym_isvar(phrase.syms[j]): - */ - __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__extend); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1690; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1690; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_INCREF(((PyObject *)__pyx_v_self->findexes1)); - PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)__pyx_v_self->findexes1)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->findexes1)); - __pyx_t_14 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1690; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1691 - * self.findexes.append(sym_setindex(self.category, i)) - * self.findexes.extend(self.findexes1) - * for j from 0 <= j < phrase.n: # <<<<<<<<<<<<<< - * if sym_isvar(phrase.syms[j]): - * fphr_arr._append(sym_setindex(self.category, i)) - */ - __pyx_t_3 = __pyx_v_phrase->n; - for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1692 - * self.findexes.extend(self.findexes1) - * for j from 0 <= j < phrase.n: - * if sym_isvar(phrase.syms[j]): # <<<<<<<<<<<<<< - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i + 1 - */ - __pyx_t_14 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_isvar); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_15 = PyInt_FromLong((__pyx_v_phrase->syms[__pyx_v_j])); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_15); - __Pyx_GIVEREF(__pyx_t_15); - __pyx_t_15 = 0; - __pyx_t_15 = PyObject_Call(__pyx_t_14, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1693 - * for j from 0 <= j < phrase.n: - * if sym_isvar(phrase.syms[j]): - * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * i = i + 1 - * else: - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1694 - * if sym_isvar(phrase.syms[j]): - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i + 1 # <<<<<<<<<<<<<< - * else: - * fphr_arr._append(phrase.syms[j]) - */ - __pyx_v_i = (__pyx_v_i + 1); - goto __pyx_L88; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1696 - * i = i + 1 - * else: - * fphr_arr._append(phrase.syms[j]) # <<<<<<<<<<<<<< - * fphr_arr._append(sym_setindex(self.category, i)) - * self.findexes.append(sym_setindex(self.category, i)) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, (__pyx_v_phrase->syms[__pyx_v_j])); - } - __pyx_L88:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1697 - * else: - * fphr_arr._append(phrase.syms[j]) - * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * self.findexes.append(sym_setindex(self.category, i)) - * fphr = Phrase(fphr_arr) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1698 - * fphr_arr._append(phrase.syms[j]) - * fphr_arr._append(sym_setindex(self.category, i)) - * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * fphr = Phrase(fphr_arr) - * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low+gap_start, e_gap_high+gap_start, e_links_low, num_gaps+1, - */ - __pyx_t_15 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1698; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_10 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_15); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1698; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1699 - * fphr_arr._append(sym_setindex(self.category, i)) - * self.findexes.append(sym_setindex(self.category, i)) - * fphr = Phrase(fphr_arr) # <<<<<<<<<<<<<< - * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low+gap_start, e_gap_high+gap_start, e_links_low, num_gaps+1, - * f_x_low, f_x_high, f_gap_low+gap_start, f_gap_high+gap_start, f_links_low, - */ - __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1699; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(((PyObject *)__pyx_v_fphr_arr)); - PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_v_fphr_arr)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr_arr)); - __pyx_t_15 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1699; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_fphr)); - __pyx_v_fphr = ((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_t_15); - __pyx_t_15 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1702 - * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low+gap_start, e_gap_high+gap_start, e_links_low, num_gaps+1, - * f_x_low, f_x_high, f_gap_low+gap_start, f_gap_high+gap_start, f_links_low, - * matching.sent_id, e_sent_len, e_sent_start) # <<<<<<<<<<<<<< - * if len(phrase_list) > 0: - * pair_count = 1.0 / len(phrase_list) - */ - __pyx_t_15 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->extract_phrases(__pyx_v_self, __pyx_v_e_x_low, __pyx_v_e_x_high, (__pyx_v_e_gap_low + __pyx_v_gap_start), (__pyx_v_e_gap_high + __pyx_v_gap_start), __pyx_v_e_links_low, (__pyx_v_num_gaps + 1), __pyx_v_f_x_low, __pyx_v_f_x_high, (__pyx_v_f_gap_low + __pyx_v_gap_start), (__pyx_v_f_gap_high + __pyx_v_gap_start), __pyx_v_f_links_low, __pyx_v_matching->sent_id, __pyx_v_e_sent_len, __pyx_v_e_sent_start); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_XDECREF(__pyx_v_phrase_list); - __pyx_v_phrase_list = __pyx_t_15; - __pyx_t_15 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1703 - * f_x_low, f_x_high, f_gap_low+gap_start, f_gap_high+gap_start, f_links_low, - * matching.sent_id, e_sent_len, e_sent_start) - * if len(phrase_list) > 0: # <<<<<<<<<<<<<< - * pair_count = 1.0 / len(phrase_list) - * else: - */ - __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1703; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_9 = (__pyx_t_13 > 0); - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1704 - * matching.sent_id, e_sent_len, e_sent_start) - * if len(phrase_list) > 0: - * pair_count = 1.0 / len(phrase_list) # <<<<<<<<<<<<<< - * else: - * pair_count = 0 - */ - __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1704; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(__pyx_t_13 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1704; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_pair_count = (1.0 / __pyx_t_13); - goto __pyx_L89; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1706 - * pair_count = 1.0 / len(phrase_list) - * else: - * pair_count = 0 # <<<<<<<<<<<<<< - * for phrase2, eindexes in phrase_list: - * als3 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) - */ - __pyx_v_pair_count = 0.0; - } - __pyx_L89:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1707 - * else: - * pair_count = 0 - * for phrase2, eindexes in phrase_list: # <<<<<<<<<<<<<< - * als3 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) - * extracts.append((fphr, phrase2, pair_count, tuple(als3))) - */ - if (PyList_CheckExact(__pyx_v_phrase_list) || PyTuple_CheckExact(__pyx_v_phrase_list)) { - __pyx_t_15 = __pyx_v_phrase_list; __Pyx_INCREF(__pyx_t_15); __pyx_t_13 = 0; - __pyx_t_16 = NULL; - } else { - __pyx_t_13 = -1; __pyx_t_15 = PyObject_GetIter(__pyx_v_phrase_list); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_16 = Py_TYPE(__pyx_t_15)->tp_iternext; - } - for (;;) { - if (!__pyx_t_16 && PyList_CheckExact(__pyx_t_15)) { - if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_15)) break; - __pyx_t_10 = PyList_GET_ITEM(__pyx_t_15, __pyx_t_13); __Pyx_INCREF(__pyx_t_10); __pyx_t_13++; - } else if (!__pyx_t_16 && PyTuple_CheckExact(__pyx_t_15)) { - if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_15)) break; - __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_15, __pyx_t_13); __Pyx_INCREF(__pyx_t_10); __pyx_t_13++; - } else { - __pyx_t_10 = __pyx_t_16(__pyx_t_15); - if (unlikely(!__pyx_t_10)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_10); - } - if ((likely(PyTuple_CheckExact(__pyx_t_10))) || (PyList_CheckExact(__pyx_t_10))) { - PyObject* sequence = __pyx_t_10; - if (likely(PyTuple_CheckExact(sequence))) { - 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[8]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_14 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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[8]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_14 = PyList_GET_ITEM(sequence, 0); - __pyx_t_1 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_14); - __Pyx_INCREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_2 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_17 = Py_TYPE(__pyx_t_2)->tp_iternext; - index = 0; __pyx_t_14 = __pyx_t_17(__pyx_t_2); if (unlikely(!__pyx_t_14)) goto __pyx_L92_unpacking_failed; - __Pyx_GOTREF(__pyx_t_14); - index = 1; __pyx_t_1 = __pyx_t_17(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L92_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_2), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L93_unpacking_done; - __pyx_L92_unpacking_failed:; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L93_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_phrase2); - __pyx_v_phrase2 = __pyx_t_14; - __pyx_t_14 = 0; - __Pyx_XDECREF(__pyx_v_eindexes); - __pyx_v_eindexes = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1708 - * pair_count = 0 - * for phrase2, eindexes in phrase_list: - * als3 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) # <<<<<<<<<<<<<< - * extracts.append((fphr, phrase2, pair_count, tuple(als3))) - * if (num_gaps < self.max_nonterminals - 1 and - */ - __pyx_t_10 = ((PyObject *)__pyx_v_self->findexes); - __Pyx_INCREF(__pyx_t_10); - __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->create_alignments(__pyx_v_self, __pyx_v_sent_links, __pyx_v_num_links, __pyx_t_10, __pyx_v_eindexes); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_v_als3); - __pyx_v_als3 = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1709 - * for phrase2, eindexes in phrase_list: - * als3 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) - * extracts.append((fphr, phrase2, pair_count, tuple(als3))) # <<<<<<<<<<<<<< - * if (num_gaps < self.max_nonterminals - 1 and - * phrase_len+1 < self.max_length and - */ - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_pair_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_v_als3); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_als3); - __Pyx_GIVEREF(__pyx_v_als3); - __pyx_t_14 = PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __pyx_t_10 = PyTuple_New(4); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(((PyObject *)__pyx_v_fphr)); - PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_v_fphr)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr)); - __Pyx_INCREF(__pyx_v_phrase2); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_phrase2); - __Pyx_GIVEREF(__pyx_v_phrase2); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_t_14); - __Pyx_GIVEREF(__pyx_t_14); - __pyx_t_1 = 0; - __pyx_t_14 = 0; - __pyx_t_14 = __Pyx_PyObject_Append(__pyx_v_extracts, ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - } - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - goto __pyx_L84; - } - __pyx_L84:; - goto __pyx_L79; - } - __pyx_L79:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1710 - * als3 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) - * extracts.append((fphr, phrase2, pair_count, tuple(als3))) - * if (num_gaps < self.max_nonterminals - 1 and # <<<<<<<<<<<<<< - * phrase_len+1 < self.max_length and - * f_back_high == f_high and - */ - __pyx_t_9 = (__pyx_v_num_gaps < (__pyx_v_self->max_nonterminals - 1)); - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1711 - * extracts.append((fphr, phrase2, pair_count, tuple(als3))) - * if (num_gaps < self.max_nonterminals - 1 and - * phrase_len+1 < self.max_length and # <<<<<<<<<<<<<< - * f_back_high == f_high and - * f_back_low == f_low and - */ - __pyx_t_7 = ((__pyx_v_phrase_len + 1) < __pyx_v_self->max_length); - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1712 - * if (num_gaps < self.max_nonterminals - 1 and - * phrase_len+1 < self.max_length and - * f_back_high == f_high and # <<<<<<<<<<<<<< - * f_back_low == f_low and - * f_back_high - f_back_low + (2*self.train_min_gap_size) <= self.train_max_initial_size and - */ - __pyx_t_18 = (__pyx_v_f_back_high == __pyx_v_f_high); - if (__pyx_t_18) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1713 - * phrase_len+1 < self.max_length and - * f_back_high == f_high and - * f_back_low == f_low and # <<<<<<<<<<<<<< - * f_back_high - f_back_low + (2*self.train_min_gap_size) <= self.train_max_initial_size and - * f_low >= self.train_min_gap_size and - */ - __pyx_t_8 = (__pyx_v_f_back_low == __pyx_v_f_low); - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1714 - * f_back_high == f_high and - * f_back_low == f_low and - * f_back_high - f_back_low + (2*self.train_min_gap_size) <= self.train_max_initial_size and # <<<<<<<<<<<<<< - * f_low >= self.train_min_gap_size and - * f_high <= f_sent_len - self.train_min_gap_size and - */ - __pyx_t_19 = (((__pyx_v_f_back_high - __pyx_v_f_back_low) + (2 * __pyx_v_self->train_min_gap_size)) <= __pyx_v_self->train_max_initial_size); - if (__pyx_t_19) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1715 - * f_back_low == f_low and - * f_back_high - f_back_low + (2*self.train_min_gap_size) <= self.train_max_initial_size and - * f_low >= self.train_min_gap_size and # <<<<<<<<<<<<<< - * f_high <= f_sent_len - self.train_min_gap_size and - * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_high] != -1))): - */ - __pyx_t_20 = (__pyx_v_f_low >= __pyx_v_self->train_min_gap_size); - if (__pyx_t_20) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1716 - * f_back_high - f_back_low + (2*self.train_min_gap_size) <= self.train_max_initial_size and - * f_low >= self.train_min_gap_size and - * f_high <= f_sent_len - self.train_min_gap_size and # <<<<<<<<<<<<<< - * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_high] != -1))): - * - */ - __pyx_t_21 = (__pyx_v_f_high <= (__pyx_v_f_sent_len - __pyx_v_self->train_min_gap_size)); - if (__pyx_t_21) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1717 - * f_low >= self.train_min_gap_size and - * f_high <= f_sent_len - self.train_min_gap_size and - * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_high] != -1))): # <<<<<<<<<<<<<< - * - * met_constraints = 1 - */ - __pyx_t_22 = (!__pyx_v_self->tight_phrases); - if (!__pyx_t_22) { - __pyx_t_23 = ((__pyx_v_f_links_low[(__pyx_v_f_low - 1)]) != -1); - if (__pyx_t_23) { - __pyx_t_24 = ((__pyx_v_f_links_low[__pyx_v_f_high]) != -1); - __pyx_t_25 = __pyx_t_24; - } else { - __pyx_t_25 = __pyx_t_23; - } - __pyx_t_23 = __pyx_t_25; - } else { - __pyx_t_23 = __pyx_t_22; - } - __pyx_t_22 = __pyx_t_23; - } else { - __pyx_t_22 = __pyx_t_21; - } - __pyx_t_21 = __pyx_t_22; - } else { - __pyx_t_21 = __pyx_t_20; - } - __pyx_t_20 = __pyx_t_21; - } else { - __pyx_t_20 = __pyx_t_19; - } - __pyx_t_19 = __pyx_t_20; - } else { - __pyx_t_19 = __pyx_t_8; - } - __pyx_t_8 = __pyx_t_19; - } else { - __pyx_t_8 = __pyx_t_18; - } - __pyx_t_18 = __pyx_t_8; - } else { - __pyx_t_18 = __pyx_t_7; - } - __pyx_t_7 = __pyx_t_18; - } else { - __pyx_t_7 = __pyx_t_9; - } - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1719 - * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_high] != -1))): - * - * met_constraints = 1 # <<<<<<<<<<<<<< - * f_x_low = f_low-self.train_min_gap_size - * if self.tight_phrases: - */ - __pyx_v_met_constraints = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1720 - * - * met_constraints = 1 - * f_x_low = f_low-self.train_min_gap_size # <<<<<<<<<<<<<< - * if self.tight_phrases: - * while f_x_low >= 0 and f_links_low[f_x_low] == -1: - */ - __pyx_v_f_x_low = (__pyx_v_f_low - __pyx_v_self->train_min_gap_size); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1721 - * met_constraints = 1 - * f_x_low = f_low-self.train_min_gap_size - * if self.tight_phrases: # <<<<<<<<<<<<<< - * while f_x_low >= 0 and f_links_low[f_x_low] == -1: - * f_x_low = f_x_low - 1 - */ - if (__pyx_v_self->tight_phrases) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1722 - * f_x_low = f_low-self.train_min_gap_size - * if self.tight_phrases: - * while f_x_low >= 0 and f_links_low[f_x_low] == -1: # <<<<<<<<<<<<<< - * f_x_low = f_x_low - 1 - * if f_x_low < 0: - */ - while (1) { - __pyx_t_7 = (__pyx_v_f_x_low >= 0); - if (__pyx_t_7) { - __pyx_t_9 = ((__pyx_v_f_links_low[__pyx_v_f_x_low]) == -1); - __pyx_t_18 = __pyx_t_9; - } else { - __pyx_t_18 = __pyx_t_7; - } - if (!__pyx_t_18) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1723 - * if self.tight_phrases: - * while f_x_low >= 0 and f_links_low[f_x_low] == -1: - * f_x_low = f_x_low - 1 # <<<<<<<<<<<<<< - * if f_x_low < 0: - * met_constraints = 0 - */ - __pyx_v_f_x_low = (__pyx_v_f_x_low - 1); - } - goto __pyx_L95; - } - __pyx_L95:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1724 - * while f_x_low >= 0 and f_links_low[f_x_low] == -1: - * f_x_low = f_x_low - 1 - * if f_x_low < 0: # <<<<<<<<<<<<<< - * met_constraints = 0 - * - */ - __pyx_t_18 = (__pyx_v_f_x_low < 0); - if (__pyx_t_18) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1725 - * f_x_low = f_x_low - 1 - * if f_x_low < 0: - * met_constraints = 0 # <<<<<<<<<<<<<< - * - * f_x_high = f_high+self.train_min_gap_size - */ - __pyx_v_met_constraints = 0; - goto __pyx_L98; - } - __pyx_L98:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1727 - * met_constraints = 0 - * - * f_x_high = f_high+self.train_min_gap_size # <<<<<<<<<<<<<< - * if self.tight_phrases: - * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: - */ - __pyx_v_f_x_high = (__pyx_v_f_high + __pyx_v_self->train_min_gap_size); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1728 - * - * f_x_high = f_high+self.train_min_gap_size - * if self.tight_phrases: # <<<<<<<<<<<<<< - * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: - * f_x_high = f_x_high + 1 - */ - if (__pyx_v_self->tight_phrases) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1729 - * f_x_high = f_high+self.train_min_gap_size - * if self.tight_phrases: - * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: # <<<<<<<<<<<<<< - * f_x_high = f_x_high + 1 - * if f_x_high > f_sent_len or f_x_high - f_x_low > self.train_max_initial_size: - */ - while (1) { - __pyx_t_18 = (__pyx_v_f_x_high <= __pyx_v_f_sent_len); - if (__pyx_t_18) { - __pyx_t_7 = ((__pyx_v_f_links_low[(__pyx_v_f_x_high - 1)]) == -1); - __pyx_t_9 = __pyx_t_7; - } else { - __pyx_t_9 = __pyx_t_18; - } - if (!__pyx_t_9) break; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1730 - * if self.tight_phrases: - * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: - * f_x_high = f_x_high + 1 # <<<<<<<<<<<<<< - * if f_x_high > f_sent_len or f_x_high - f_x_low > self.train_max_initial_size: - * met_constraints = 0 - */ - __pyx_v_f_x_high = (__pyx_v_f_x_high + 1); - } - goto __pyx_L99; - } - __pyx_L99:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1731 - * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: - * f_x_high = f_x_high + 1 - * if f_x_high > f_sent_len or f_x_high - f_x_low > self.train_max_initial_size: # <<<<<<<<<<<<<< - * met_constraints = 0 - * - */ - __pyx_t_9 = (__pyx_v_f_x_high > __pyx_v_f_sent_len); - if (!__pyx_t_9) { - __pyx_t_18 = ((__pyx_v_f_x_high - __pyx_v_f_x_low) > __pyx_v_self->train_max_initial_size); - __pyx_t_7 = __pyx_t_18; - } else { - __pyx_t_7 = __pyx_t_9; - } - if (__pyx_t_7) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1732 - * f_x_high = f_x_high + 1 - * if f_x_high > f_sent_len or f_x_high - f_x_low > self.train_max_initial_size: - * met_constraints = 0 # <<<<<<<<<<<<<< - * - * if (met_constraints and - */ - __pyx_v_met_constraints = 0; - goto __pyx_L102; - } - __pyx_L102:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1734 - * met_constraints = 0 - * - * if (met_constraints and # <<<<<<<<<<<<<< - * self.find_fixpoint(f_x_low, f_x_high, - * f_links_low, f_links_high, e_links_low, e_links_high, - */ - if (__pyx_v_met_constraints) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1735 - * - * if (met_constraints and - * self.find_fixpoint(f_x_low, f_x_high, # <<<<<<<<<<<<<< - * f_links_low, f_links_high, e_links_low, e_links_high, - * e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, - */ - __pyx_t_15 = PyInt_FromLong(__pyx_v_f_x_high); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1735; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1739 - * e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, - * f_sent_len, e_sent_len, - * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< - * 1, 1, 2, 1, 1, 1, 1) and - * ((not self.tight_phrases) or (f_links_low[f_x_low] != -1 and f_links_low[f_x_high-1] != -1)) and - */ - if (((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_x_low, __pyx_t_15, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_e_low, __pyx_v_e_high, (&__pyx_v_e_x_low), (&__pyx_v_e_x_high), (&__pyx_v_f_x_low), (&__pyx_v_f_x_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 1, 1, 2, 1, 1, 1, 1)) { - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1741 - * self.train_max_initial_size, self.train_max_initial_size, - * 1, 1, 2, 1, 1, 1, 1) and - * ((not self.tight_phrases) or (f_links_low[f_x_low] != -1 and f_links_low[f_x_high-1] != -1)) and # <<<<<<<<<<<<<< - * self.find_fixpoint(f_x_low, f_low, - * f_links_low, f_links_high, e_links_low, e_links_high, - */ - __pyx_t_7 = (!__pyx_v_self->tight_phrases); - if (!__pyx_t_7) { - __pyx_t_9 = ((__pyx_v_f_links_low[__pyx_v_f_x_low]) != -1); - if (__pyx_t_9) { - __pyx_t_18 = ((__pyx_v_f_links_low[(__pyx_v_f_x_high - 1)]) != -1); - __pyx_t_8 = __pyx_t_18; - } else { - __pyx_t_8 = __pyx_t_9; - } - __pyx_t_9 = __pyx_t_8; - } else { - __pyx_t_9 = __pyx_t_7; - } - if (__pyx_t_9) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1742 - * 1, 1, 2, 1, 1, 1, 1) and - * ((not self.tight_phrases) or (f_links_low[f_x_low] != -1 and f_links_low[f_x_high-1] != -1)) and - * self.find_fixpoint(f_x_low, f_low, # <<<<<<<<<<<<<< - * f_links_low, f_links_high, e_links_low, e_links_high, - * -1, -1, e_gap_low, e_gap_high, f_gap_low, f_gap_high, - */ - __pyx_t_14 = PyInt_FromLong(__pyx_v_f_low); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1742; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1746 - * -1, -1, e_gap_low, e_gap_high, f_gap_low, f_gap_high, - * f_sent_len, e_sent_len, - * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< - * 0, 0, 0, 0, 0, 0, 0) and - * self.find_fixpoint(f_high, f_x_high, - */ - __pyx_t_3 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_x_low, __pyx_t_14, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, -1, -1, __pyx_v_e_gap_low, __pyx_v_e_gap_high, __pyx_v_f_gap_low, __pyx_v_f_gap_high, __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 0, 0, 0, 0, 0, 0, 0); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - if (__pyx_t_3) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1748 - * self.train_max_initial_size, self.train_max_initial_size, - * 0, 0, 0, 0, 0, 0, 0) and - * self.find_fixpoint(f_high, f_x_high, # <<<<<<<<<<<<<< - * f_links_low, f_links_high, e_links_low, e_links_high, - * -1, -1, e_gap_low+1+num_gaps, e_gap_high+1+num_gaps, - */ - __pyx_t_14 = PyInt_FromLong(__pyx_v_f_x_high); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1748; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1753 - * f_gap_low+1+num_gaps, f_gap_high+1+num_gaps, - * f_sent_len, e_sent_len, - * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< - * 0, 0, 0, 0, 0, 0, 0)): - * fphr_arr._clear() - */ - __pyx_t_4 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_high, __pyx_t_14, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, -1, -1, ((__pyx_v_e_gap_low + 1) + __pyx_v_num_gaps), ((__pyx_v_e_gap_high + 1) + __pyx_v_num_gaps), ((__pyx_v_f_gap_low + 1) + __pyx_v_num_gaps), ((__pyx_v_f_gap_high + 1) + __pyx_v_num_gaps), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 0, 0, 0, 0, 0, 0, 0); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __pyx_t_7 = __pyx_t_4; - } else { - __pyx_t_7 = __pyx_t_3; - } - __pyx_t_8 = __pyx_t_7; - } else { - __pyx_t_8 = __pyx_t_9; - } - __pyx_t_9 = __pyx_t_8; - } else { - __pyx_t_9 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_x_low, __pyx_t_15, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_e_low, __pyx_v_e_high, (&__pyx_v_e_x_low), (&__pyx_v_e_x_high), (&__pyx_v_f_x_low), (&__pyx_v_f_x_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 1, 1, 2, 1, 1, 1, 1); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - } - __pyx_t_8 = __pyx_t_9; - } else { - __pyx_t_8 = __pyx_v_met_constraints; - } - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1755 - * self.train_max_initial_size, self.train_max_initial_size, - * 0, 0, 0, 0, 0, 0, 0)): - * fphr_arr._clear() # <<<<<<<<<<<<<< - * i = 1 - * self.findexes.reset() - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_clear(__pyx_v_fphr_arr); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1756 - * 0, 0, 0, 0, 0, 0, 0)): - * fphr_arr._clear() - * i = 1 # <<<<<<<<<<<<<< - * self.findexes.reset() - * self.findexes.append(sym_setindex(self.category, i)) - */ - __pyx_v_i = 1; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1757 - * fphr_arr._clear() - * i = 1 - * self.findexes.reset() # <<<<<<<<<<<<<< - * self.findexes.append(sym_setindex(self.category, i)) - * fphr_arr._append(sym_setindex(self.category, i)) - */ - __pyx_t_15 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__reset); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1757; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_14 = PyObject_Call(__pyx_t_15, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1757; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1758 - * i = 1 - * self.findexes.reset() - * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i+1 - */ - __pyx_t_14 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1758; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_15 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_14); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1758; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1759 - * self.findexes.reset() - * self.findexes.append(sym_setindex(self.category, i)) - * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * i = i+1 - * self.findexes.extend(self.findexes1) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1760 - * self.findexes.append(sym_setindex(self.category, i)) - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i+1 # <<<<<<<<<<<<<< - * self.findexes.extend(self.findexes1) - * for j from 0 <= j < phrase.n: - */ - __pyx_v_i = (__pyx_v_i + 1); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1761 - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i+1 - * self.findexes.extend(self.findexes1) # <<<<<<<<<<<<<< - * for j from 0 <= j < phrase.n: - * if sym_isvar(phrase.syms[j]): - */ - __pyx_t_15 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__extend); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1761; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1761; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_INCREF(((PyObject *)__pyx_v_self->findexes1)); - PyTuple_SET_ITEM(__pyx_t_14, 0, ((PyObject *)__pyx_v_self->findexes1)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_self->findexes1)); - __pyx_t_10 = PyObject_Call(__pyx_t_15, ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1761; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1762 - * i = i+1 - * self.findexes.extend(self.findexes1) - * for j from 0 <= j < phrase.n: # <<<<<<<<<<<<<< - * if sym_isvar(phrase.syms[j]): - * fphr_arr._append(sym_setindex(self.category, i)) - */ - __pyx_t_3 = __pyx_v_phrase->n; - for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1763 - * self.findexes.extend(self.findexes1) - * for j from 0 <= j < phrase.n: - * if sym_isvar(phrase.syms[j]): # <<<<<<<<<<<<<< - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i + 1 - */ - __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_isvar); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1763; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_14 = PyInt_FromLong((__pyx_v_phrase->syms[__pyx_v_j])); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1763; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1763; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_14); - __Pyx_GIVEREF(__pyx_t_14); - __pyx_t_14 = 0; - __pyx_t_14 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1763; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; - __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1763; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1764 - * for j from 0 <= j < phrase.n: - * if sym_isvar(phrase.syms[j]): - * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * i = i + 1 - * else: - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1765 - * if sym_isvar(phrase.syms[j]): - * fphr_arr._append(sym_setindex(self.category, i)) - * i = i + 1 # <<<<<<<<<<<<<< - * else: - * fphr_arr._append(phrase.syms[j]) - */ - __pyx_v_i = (__pyx_v_i + 1); - goto __pyx_L106; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1767 - * i = i + 1 - * else: - * fphr_arr._append(phrase.syms[j]) # <<<<<<<<<<<<<< - * fphr_arr._append(sym_setindex(self.category, i)) - * self.findexes.append(sym_setindex(self.category, i)) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, (__pyx_v_phrase->syms[__pyx_v_j])); - } - __pyx_L106:; - } - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1768 - * else: - * fphr_arr._append(phrase.syms[j]) - * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * self.findexes.append(sym_setindex(self.category, i)) - * fphr = Phrase(fphr_arr) - */ - ((struct __pyx_vtabstruct_8_cdec_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1769 - * fphr_arr._append(phrase.syms[j]) - * fphr_arr._append(sym_setindex(self.category, i)) - * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< - * fphr = Phrase(fphr_arr) - * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+2, - */ - __pyx_t_14 = PyInt_FromLong(__pyx_f_8_cdec_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1769; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_15 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_14); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1769; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1770 - * fphr_arr._append(sym_setindex(self.category, i)) - * self.findexes.append(sym_setindex(self.category, i)) - * fphr = Phrase(fphr_arr) # <<<<<<<<<<<<<< - * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+2, - * f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, - */ - __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1770; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_INCREF(((PyObject *)__pyx_v_fphr_arr)); - PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)__pyx_v_fphr_arr)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr_arr)); - __pyx_t_14 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_8_cdec_sa_Phrase)), ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1770; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; - __Pyx_DECREF(((PyObject *)__pyx_v_fphr)); - __pyx_v_fphr = ((struct __pyx_obj_8_cdec_sa_Phrase *)__pyx_t_14); - __pyx_t_14 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1773 - * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+2, - * f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, - * matching.sent_id, e_sent_len, e_sent_start) # <<<<<<<<<<<<<< - * if len(phrase_list) > 0: - * pair_count = 1.0 / len(phrase_list) - */ - __pyx_t_14 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->extract_phrases(__pyx_v_self, __pyx_v_e_x_low, __pyx_v_e_x_high, __pyx_v_e_gap_low, __pyx_v_e_gap_high, __pyx_v_e_links_low, (__pyx_v_num_gaps + 2), __pyx_v_f_x_low, __pyx_v_f_x_high, __pyx_v_f_gap_low, __pyx_v_f_gap_high, __pyx_v_f_links_low, __pyx_v_matching->sent_id, __pyx_v_e_sent_len, __pyx_v_e_sent_start); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1771; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_XDECREF(__pyx_v_phrase_list); - __pyx_v_phrase_list = __pyx_t_14; - __pyx_t_14 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1774 - * f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, - * matching.sent_id, e_sent_len, e_sent_start) - * if len(phrase_list) > 0: # <<<<<<<<<<<<<< - * pair_count = 1.0 / len(phrase_list) - * else: - */ - __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1774; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_8 = (__pyx_t_13 > 0); - if (__pyx_t_8) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1775 - * matching.sent_id, e_sent_len, e_sent_start) - * if len(phrase_list) > 0: - * pair_count = 1.0 / len(phrase_list) # <<<<<<<<<<<<<< - * else: - * pair_count = 0 - */ - __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1775; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(__pyx_t_13 == 0)) { - PyErr_Format(PyExc_ZeroDivisionError, "float division"); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1775; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_pair_count = (1.0 / __pyx_t_13); - goto __pyx_L107; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1777 - * pair_count = 1.0 / len(phrase_list) - * else: - * pair_count = 0 # <<<<<<<<<<<<<< - * for phrase2, eindexes in phrase_list: - * als4 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) - */ - __pyx_v_pair_count = 0.0; - } - __pyx_L107:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1778 - * else: - * pair_count = 0 - * for phrase2, eindexes in phrase_list: # <<<<<<<<<<<<<< - * als4 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) - * extracts.append((fphr, phrase2, pair_count, tuple(als4))) - */ - if (PyList_CheckExact(__pyx_v_phrase_list) || PyTuple_CheckExact(__pyx_v_phrase_list)) { - __pyx_t_14 = __pyx_v_phrase_list; __Pyx_INCREF(__pyx_t_14); __pyx_t_13 = 0; - __pyx_t_16 = NULL; - } else { - __pyx_t_13 = -1; __pyx_t_14 = PyObject_GetIter(__pyx_v_phrase_list); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_16 = Py_TYPE(__pyx_t_14)->tp_iternext; - } - for (;;) { - if (!__pyx_t_16 && PyList_CheckExact(__pyx_t_14)) { - if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_14)) break; - __pyx_t_15 = PyList_GET_ITEM(__pyx_t_14, __pyx_t_13); __Pyx_INCREF(__pyx_t_15); __pyx_t_13++; - } else if (!__pyx_t_16 && PyTuple_CheckExact(__pyx_t_14)) { - if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_14)) break; - __pyx_t_15 = PyTuple_GET_ITEM(__pyx_t_14, __pyx_t_13); __Pyx_INCREF(__pyx_t_15); __pyx_t_13++; - } else { - __pyx_t_15 = __pyx_t_16(__pyx_t_14); - if (unlikely(!__pyx_t_15)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_15); - } - if ((likely(PyTuple_CheckExact(__pyx_t_15))) || (PyList_CheckExact(__pyx_t_15))) { - PyObject* sequence = __pyx_t_15; - if (likely(PyTuple_CheckExact(sequence))) { - 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[8]; __pyx_lineno = 1778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); - } else { - 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[8]; __pyx_lineno = 1778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_t_10 = PyList_GET_ITEM(sequence, 0); - __pyx_t_1 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_10); - __Pyx_INCREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_2 = PyObject_GetIter(__pyx_t_15); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __pyx_t_17 = Py_TYPE(__pyx_t_2)->tp_iternext; - index = 0; __pyx_t_10 = __pyx_t_17(__pyx_t_2); if (unlikely(!__pyx_t_10)) goto __pyx_L110_unpacking_failed; - __Pyx_GOTREF(__pyx_t_10); - index = 1; __pyx_t_1 = __pyx_t_17(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L110_unpacking_failed; - __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_2), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L111_unpacking_done; - __pyx_L110_unpacking_failed:; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_L111_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_phrase2); - __pyx_v_phrase2 = __pyx_t_10; - __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_v_eindexes); - __pyx_v_eindexes = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1779 - * pair_count = 0 - * for phrase2, eindexes in phrase_list: - * als4 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) # <<<<<<<<<<<<<< - * extracts.append((fphr, phrase2, pair_count, tuple(als4))) - * else: - */ - __pyx_t_15 = ((PyObject *)__pyx_v_self->findexes); - __Pyx_INCREF(__pyx_t_15); - __pyx_t_1 = ((struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->create_alignments(__pyx_v_self, __pyx_v_sent_links, __pyx_v_num_links, __pyx_t_15, __pyx_v_eindexes); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1779; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - __Pyx_XDECREF(__pyx_v_als4); - __pyx_v_als4 = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1780 - * for phrase2, eindexes in phrase_list: - * als4 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) - * extracts.append((fphr, phrase2, pair_count, tuple(als4))) # <<<<<<<<<<<<<< - * else: - * reason_for_failure = "Unable to extract basic phrase" - */ - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_pair_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1780; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1780; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_INCREF(__pyx_v_als4); - PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_als4); - __Pyx_GIVEREF(__pyx_v_als4); - __pyx_t_10 = PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1780; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; - __pyx_t_15 = PyTuple_New(4); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1780; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_15); - __Pyx_INCREF(((PyObject *)__pyx_v_fphr)); - PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)__pyx_v_fphr)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr)); - __Pyx_INCREF(__pyx_v_phrase2); - PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_v_phrase2); - __Pyx_GIVEREF(__pyx_v_phrase2); - PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_t_1 = 0; - __pyx_t_10 = 0; - __pyx_t_10 = __Pyx_PyObject_Append(__pyx_v_extracts, ((PyObject *)__pyx_t_15)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1780; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - } - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - goto __pyx_L103; - } - __pyx_L103:; - goto __pyx_L94; - } - __pyx_L94:; - goto __pyx_L63; - } - __pyx_L63:; - goto __pyx_L51; - } - __pyx_L51:; - goto __pyx_L34; - } - /*else*/ { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1782 - * extracts.append((fphr, phrase2, pair_count, tuple(als4))) - * else: - * reason_for_failure = "Unable to extract basic phrase" # <<<<<<<<<<<<<< - * - * free(sent_links) - */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_131)); - __Pyx_DECREF(__pyx_v_reason_for_failure); - __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_131); - } - __pyx_L34:; - goto __pyx_L33; - } - __pyx_L33:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1784 - * reason_for_failure = "Unable to extract basic phrase" - * - * free(sent_links) # <<<<<<<<<<<<<< - * free(f_links_low) - * free(f_links_high) - */ - free(__pyx_v_sent_links); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1785 - * - * free(sent_links) - * free(f_links_low) # <<<<<<<<<<<<<< - * free(f_links_high) - * free(e_links_low) - */ - free(__pyx_v_f_links_low); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1786 - * free(sent_links) - * free(f_links_low) - * free(f_links_high) # <<<<<<<<<<<<<< - * free(e_links_low) - * free(e_links_high) - */ - free(__pyx_v_f_links_high); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1787 - * free(f_links_low) - * free(f_links_high) - * free(e_links_low) # <<<<<<<<<<<<<< - * free(e_links_high) - * free(f_gap_low) - */ - free(__pyx_v_e_links_low); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1788 - * free(f_links_high) - * free(e_links_low) - * free(e_links_high) # <<<<<<<<<<<<<< - * free(f_gap_low) - * free(f_gap_high) - */ - free(__pyx_v_e_links_high); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1789 - * free(e_links_low) - * free(e_links_high) - * free(f_gap_low) # <<<<<<<<<<<<<< - * free(f_gap_high) - * free(e_gap_low) - */ - free(__pyx_v_f_gap_low); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1790 - * free(e_links_high) - * free(f_gap_low) - * free(f_gap_high) # <<<<<<<<<<<<<< - * free(e_gap_low) - * free(e_gap_high) - */ - free(__pyx_v_f_gap_high); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1791 - * free(f_gap_low) - * free(f_gap_high) - * free(e_gap_low) # <<<<<<<<<<<<<< - * free(e_gap_high) - * - */ - free(__pyx_v_e_gap_low); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1792 - * free(f_gap_high) - * free(e_gap_low) - * free(e_gap_high) # <<<<<<<<<<<<<< - * - * return extracts - */ - free(__pyx_v_e_gap_high); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1794 - * free(e_gap_high) - * - * return extracts # <<<<<<<<<<<<<< - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_v_extracts); - __pyx_r = __pyx_v_extracts; - 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_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_14); - __Pyx_XDECREF(__pyx_t_15); - __Pyx_AddTraceback("_cdec_sa.HieroCachingRuleFactory.extract", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = 0; - __pyx_L0:; - __Pyx_XDECREF(__pyx_v_extracts); - __Pyx_XDECREF(__pyx_v_phrase_list); - __Pyx_XDECREF((PyObject *)__pyx_v_fphr_arr); - __Pyx_XDECREF((PyObject *)__pyx_v_fphr); - __Pyx_XDECREF(__pyx_v_reason_for_failure); - __Pyx_XDECREF(__pyx_v_sofar); - __Pyx_XDECREF(__pyx_v_als); - __Pyx_XDECREF(__pyx_v_al); - __Pyx_XDECREF(__pyx_v_phrase2); - __Pyx_XDECREF(__pyx_v_eindexes); - __Pyx_XDECREF(__pyx_v_als1); - __Pyx_XDECREF(__pyx_v_als2); - __Pyx_XDECREF(__pyx_v_als3); - __Pyx_XDECREF(__pyx_v_als4); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} -static struct __pyx_vtabstruct_8_cdec_sa_FloatList __pyx_vtable_8_cdec_sa_FloatList; - -static PyObject *__pyx_tp_new_8_cdec_sa_FloatList(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_FloatList *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_FloatList *)o); - p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_FloatList; - if (__pyx_pw_8_cdec_sa_9FloatList_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_FloatList(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_8_cdec_sa_9FloatList_3__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - (*Py_TYPE(o)->tp_free)(o); -} -static PyObject *__pyx_sq_item_8_cdec_sa_FloatList(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} - -static int __pyx_mp_ass_subscript_8_cdec_sa_FloatList(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_pw_8_cdec_sa_9FloatList_7__setitem__(o, i, v); - } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); - return -1; - } -} - -static PyMethodDef __pyx_methods_8_cdec_sa_FloatList[] = { - {__Pyx_NAMESTR("append"), (PyCFunction)__pyx_pw_8_cdec_sa_9FloatList_11append, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("write"), (PyCFunction)__pyx_pw_8_cdec_sa_9FloatList_13write, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("read"), (PyCFunction)__pyx_pw_8_cdec_sa_9FloatList_15read, METH_O, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_FloatList = { - 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_FloatList = { - __pyx_pw_8_cdec_sa_9FloatList_9__len__, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - __pyx_sq_item_8_cdec_sa_FloatList, /*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_FloatList = { - __pyx_pw_8_cdec_sa_9FloatList_9__len__, /*mp_length*/ - __pyx_pw_8_cdec_sa_9FloatList_5__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_8_cdec_sa_FloatList, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_FloatList = { - #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_8_cdec_sa_FloatList = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.FloatList"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_FloatList), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_FloatList, /*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_FloatList, /*tp_as_number*/ - &__pyx_tp_as_sequence_FloatList, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_FloatList, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_FloatList, /*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*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_FloatList, /*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_8_cdec_sa_FloatList, /*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 struct __pyx_vtabstruct_8_cdec_sa_IntList __pyx_vtable_8_cdec_sa_IntList; - -static PyObject *__pyx_tp_new_8_cdec_sa_IntList(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_IntList *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_IntList *)o); - p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_IntList; - if (__pyx_pw_8_cdec_sa_7IntList_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_IntList(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_8_cdec_sa_7IntList_15__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - (*Py_TYPE(o)->tp_free)(o); -} -static PyObject *__pyx_sq_item_8_cdec_sa_IntList(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} - -static int __pyx_mp_ass_subscript_8_cdec_sa_IntList(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_pw_8_cdec_sa_7IntList_19__setitem__(o, i, v); - } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); - return -1; - } -} - -static PyMethodDef __pyx_methods_8_cdec_sa_IntList[] = { - {__Pyx_NAMESTR("index"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_5index, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("partition"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_7partition, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("_doquicksort"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_9_doquicksort, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("sort"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_11sort, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("reset"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_13reset, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("getSize"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_23getSize, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("append"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_25append, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("extend"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_27extend, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("write"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_29write, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("read"), (PyCFunction)__pyx_pw_8_cdec_sa_7IntList_31read, METH_O, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_IntList = { - 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_IntList = { - __pyx_pw_8_cdec_sa_7IntList_21__len__, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - __pyx_sq_item_8_cdec_sa_IntList, /*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_IntList = { - __pyx_pw_8_cdec_sa_7IntList_21__len__, /*mp_length*/ - __pyx_pw_8_cdec_sa_7IntList_17__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_8_cdec_sa_IntList, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_IntList = { - #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_8_cdec_sa_IntList = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.IntList"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_IntList), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_IntList, /*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_IntList, /*tp_as_number*/ - &__pyx_tp_as_sequence_IntList, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_IntList, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - __pyx_pw_8_cdec_sa_7IntList_3__str__, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_IntList, /*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*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_IntList, /*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_8_cdec_sa_IntList, /*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 struct __pyx_vtabstruct_8_cdec_sa_StringMap __pyx_vtable_8_cdec_sa_StringMap; - -static PyObject *__pyx_tp_new_8_cdec_sa_StringMap(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_StringMap *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_StringMap *)o); - p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_StringMap; - if (__pyx_pw_8_cdec_sa_9StringMap_1__cinit__(o, __pyx_empty_tuple, NULL) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_StringMap(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_8_cdec_sa_9StringMap_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_8_cdec_sa_StringMap[] = { - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_StringMap = { - 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_StringMap = { - 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_StringMap = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_StringMap = { - #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_8_cdec_sa_StringMap = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.StringMap"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_StringMap), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_StringMap, /*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_StringMap, /*tp_as_number*/ - &__pyx_tp_as_sequence_StringMap, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_StringMap, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_StringMap, /*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*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_StringMap, /*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_8_cdec_sa_StringMap, /*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 struct __pyx_vtabstruct_8_cdec_sa_DataArray __pyx_vtable_8_cdec_sa_DataArray; - -static PyObject *__pyx_tp_new_8_cdec_sa_DataArray(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_DataArray *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_DataArray *)o); - p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_DataArray; - p->word2id = Py_None; Py_INCREF(Py_None); - p->id2word = Py_None; Py_INCREF(Py_None); - p->data = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - p->sent_id = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - p->sent_index = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - if (__pyx_pw_8_cdec_sa_9DataArray_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_DataArray(PyObject *o) { - struct __pyx_obj_8_cdec_sa_DataArray *p = (struct __pyx_obj_8_cdec_sa_DataArray *)o; - Py_XDECREF(p->word2id); - Py_XDECREF(p->id2word); - Py_XDECREF(((PyObject *)p->data)); - Py_XDECREF(((PyObject *)p->sent_id)); - Py_XDECREF(((PyObject *)p->sent_index)); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_8_cdec_sa_DataArray(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_8_cdec_sa_DataArray *p = (struct __pyx_obj_8_cdec_sa_DataArray *)o; - if (p->word2id) { - e = (*v)(p->word2id, a); if (e) return e; - } - if (p->id2word) { - e = (*v)(p->id2word, a); if (e) return e; - } - if (p->data) { - e = (*v)(((PyObject*)p->data), a); if (e) return e; - } - if (p->sent_id) { - e = (*v)(((PyObject*)p->sent_id), a); if (e) return e; - } - if (p->sent_index) { - e = (*v)(((PyObject*)p->sent_index), a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_8_cdec_sa_DataArray(PyObject *o) { - struct __pyx_obj_8_cdec_sa_DataArray *p = (struct __pyx_obj_8_cdec_sa_DataArray *)o; - PyObject* tmp; - tmp = ((PyObject*)p->word2id); - p->word2id = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->id2word); - p->id2word = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->data); - p->data = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->sent_id); - p->sent_id = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->sent_index); - p->sent_index = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyMethodDef __pyx_methods_8_cdec_sa_DataArray[] = { - {__Pyx_NAMESTR("getSentId"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_5getSentId, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("getSent"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_7getSent, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("getSentPos"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_9getSentPos, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_id"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_11get_id, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_word"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_13get_word, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("write_text"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_15write_text, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("read_text"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_17read_text, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("read_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_19read_binary, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("write_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_21write_binary, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("write_enhanced_handle"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_23write_enhanced_handle, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("write_enhanced"), (PyCFunction)__pyx_pw_8_cdec_sa_9DataArray_25write_enhanced, METH_O, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_DataArray = { - 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_DataArray = { - __pyx_pw_8_cdec_sa_9DataArray_3__len__, /*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_DataArray = { - __pyx_pw_8_cdec_sa_9DataArray_3__len__, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_DataArray = { - #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_8_cdec_sa_DataArray = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.DataArray"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_DataArray), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_DataArray, /*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_DataArray, /*tp_as_number*/ - &__pyx_tp_as_sequence_DataArray, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_DataArray, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_DataArray, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_8_cdec_sa_DataArray, /*tp_traverse*/ - __pyx_tp_clear_8_cdec_sa_DataArray, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_DataArray, /*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_8_cdec_sa_DataArray, /*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 struct __pyx_vtabstruct_8_cdec_sa_Alignment __pyx_vtable_8_cdec_sa_Alignment; - -static PyObject *__pyx_tp_new_8_cdec_sa_Alignment(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_Alignment *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_Alignment *)o); - p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_Alignment; - p->links = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - p->sent_index = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - if (__pyx_pw_8_cdec_sa_9Alignment_5__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_Alignment(PyObject *o) { - struct __pyx_obj_8_cdec_sa_Alignment *p = (struct __pyx_obj_8_cdec_sa_Alignment *)o; - Py_XDECREF(((PyObject *)p->links)); - Py_XDECREF(((PyObject *)p->sent_index)); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_8_cdec_sa_Alignment(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_8_cdec_sa_Alignment *p = (struct __pyx_obj_8_cdec_sa_Alignment *)o; - if (p->links) { - e = (*v)(((PyObject*)p->links), a); if (e) return e; - } - if (p->sent_index) { - e = (*v)(((PyObject*)p->sent_index), a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_8_cdec_sa_Alignment(PyObject *o) { - struct __pyx_obj_8_cdec_sa_Alignment *p = (struct __pyx_obj_8_cdec_sa_Alignment *)o; - PyObject* tmp; - tmp = ((PyObject*)p->links); - p->links = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->sent_index); - p->sent_index = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyMethodDef __pyx_methods_8_cdec_sa_Alignment[] = { - {__Pyx_NAMESTR("unlink"), (PyCFunction)__pyx_pw_8_cdec_sa_9Alignment_1unlink, METH_O, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_9Alignment_unlink)}, - {__Pyx_NAMESTR("get_sent_links"), (PyCFunction)__pyx_pw_8_cdec_sa_9Alignment_3get_sent_links, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("read_text"), (PyCFunction)__pyx_pw_8_cdec_sa_9Alignment_7read_text, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("read_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_9Alignment_9read_binary, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("write_text"), (PyCFunction)__pyx_pw_8_cdec_sa_9Alignment_11write_text, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("write_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_9Alignment_13write_binary, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("write_enhanced"), (PyCFunction)__pyx_pw_8_cdec_sa_9Alignment_15write_enhanced, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("alignment"), (PyCFunction)__pyx_pw_8_cdec_sa_9Alignment_17alignment, METH_O, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_9Alignment_16alignment)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_Alignment = { - 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_Alignment = { - 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_Alignment = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_Alignment = { - #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_8_cdec_sa_Alignment = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.Alignment"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_Alignment), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_Alignment, /*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_Alignment, /*tp_as_number*/ - &__pyx_tp_as_sequence_Alignment, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Alignment, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Alignment, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_8_cdec_sa_Alignment, /*tp_traverse*/ - __pyx_tp_clear_8_cdec_sa_Alignment, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_Alignment, /*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_8_cdec_sa_Alignment, /*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 struct __pyx_vtabstruct_8_cdec_sa_BiLex __pyx_vtable_8_cdec_sa_BiLex; - -static PyObject *__pyx_tp_new_8_cdec_sa_BiLex(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_BiLex *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_BiLex *)o); - p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_BiLex; - p->col1 = ((struct __pyx_obj_8_cdec_sa_FloatList *)Py_None); Py_INCREF(Py_None); - p->col2 = ((struct __pyx_obj_8_cdec_sa_FloatList *)Py_None); Py_INCREF(Py_None); - p->f_index = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - p->e_index = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - p->id2eword = Py_None; Py_INCREF(Py_None); - p->id2fword = Py_None; Py_INCREF(Py_None); - p->eword2id = Py_None; Py_INCREF(Py_None); - p->fword2id = Py_None; Py_INCREF(Py_None); - if (__pyx_pw_8_cdec_sa_5BiLex_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_BiLex(PyObject *o) { - struct __pyx_obj_8_cdec_sa_BiLex *p = (struct __pyx_obj_8_cdec_sa_BiLex *)o; - Py_XDECREF(((PyObject *)p->col1)); - Py_XDECREF(((PyObject *)p->col2)); - Py_XDECREF(((PyObject *)p->f_index)); - Py_XDECREF(((PyObject *)p->e_index)); - Py_XDECREF(p->id2eword); - Py_XDECREF(p->id2fword); - Py_XDECREF(p->eword2id); - Py_XDECREF(p->fword2id); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_8_cdec_sa_BiLex(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_8_cdec_sa_BiLex *p = (struct __pyx_obj_8_cdec_sa_BiLex *)o; - if (p->col1) { - e = (*v)(((PyObject*)p->col1), a); if (e) return e; - } - if (p->col2) { - e = (*v)(((PyObject*)p->col2), a); if (e) return e; - } - if (p->f_index) { - e = (*v)(((PyObject*)p->f_index), a); if (e) return e; - } - if (p->e_index) { - e = (*v)(((PyObject*)p->e_index), a); if (e) return e; - } - if (p->id2eword) { - e = (*v)(p->id2eword, a); if (e) return e; - } - if (p->id2fword) { - e = (*v)(p->id2fword, a); if (e) return e; - } - if (p->eword2id) { - e = (*v)(p->eword2id, a); if (e) return e; - } - if (p->fword2id) { - e = (*v)(p->fword2id, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_8_cdec_sa_BiLex(PyObject *o) { - struct __pyx_obj_8_cdec_sa_BiLex *p = (struct __pyx_obj_8_cdec_sa_BiLex *)o; - PyObject* tmp; - tmp = ((PyObject*)p->col1); - p->col1 = ((struct __pyx_obj_8_cdec_sa_FloatList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->col2); - p->col2 = ((struct __pyx_obj_8_cdec_sa_FloatList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->f_index); - p->f_index = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->e_index); - p->e_index = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->id2eword); - p->id2eword = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->id2fword); - p->id2fword = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->eword2id); - p->eword2id = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->fword2id); - p->fword2id = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyMethodDef __pyx_methods_8_cdec_sa_BiLex[] = { - {__Pyx_NAMESTR("write_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_5BiLex_3write_binary, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("read_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_5BiLex_5read_binary, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_e_id"), (PyCFunction)__pyx_pw_8_cdec_sa_5BiLex_7get_e_id, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_f_id"), (PyCFunction)__pyx_pw_8_cdec_sa_5BiLex_9get_f_id, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("read_text"), (PyCFunction)__pyx_pw_8_cdec_sa_5BiLex_11read_text, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("write_enhanced"), (PyCFunction)__pyx_pw_8_cdec_sa_5BiLex_13write_enhanced, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_score"), (PyCFunction)__pyx_pw_8_cdec_sa_5BiLex_15get_score, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("write_text"), (PyCFunction)__pyx_pw_8_cdec_sa_5BiLex_17write_text, METH_O, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_5BiLex_16write_text)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_BiLex = { - 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_BiLex = { - 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_BiLex = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_BiLex = { - #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_8_cdec_sa_BiLex = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.BiLex"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_BiLex), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_BiLex, /*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_BiLex, /*tp_as_number*/ - &__pyx_tp_as_sequence_BiLex, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_BiLex, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_BiLex, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_8_cdec_sa_BiLex, /*tp_traverse*/ - __pyx_tp_clear_8_cdec_sa_BiLex, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_BiLex, /*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_8_cdec_sa_BiLex, /*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_8_cdec_sa_BitSetIterator(PyTypeObject *t, PyObject *a, PyObject *k) { - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_BitSetIterator(PyObject *o) { - (*Py_TYPE(o)->tp_free)(o); -} - -static PyMethodDef __pyx_methods_8_cdec_sa_BitSetIterator[] = { - {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_8_cdec_sa_14BitSetIterator_1__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_BitSetIterator = { - 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_BitSetIterator = { - 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_BitSetIterator = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_BitSetIterator = { - #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_8_cdec_sa_BitSetIterator = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.BitSetIterator"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_BitSetIterator), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_BitSetIterator, /*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_BitSetIterator, /*tp_as_number*/ - &__pyx_tp_as_sequence_BitSetIterator, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_BitSetIterator, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_BitSetIterator, /*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*/ - 0, /*tp_iter*/ - __pyx_pw_8_cdec_sa_14BitSetIterator_1__next__, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_BitSetIterator, /*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_8_cdec_sa_BitSetIterator, /*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_8_cdec_sa_BitSet(PyTypeObject *t, PyObject *a, PyObject *k) { - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - if (__pyx_pw_8_cdec_sa_6BitSet_1__cinit__(o, __pyx_empty_tuple, NULL) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_BitSet(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_8_cdec_sa_6BitSet_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_8_cdec_sa_BitSet[] = { - {__Pyx_NAMESTR("insert"), (PyCFunction)__pyx_pw_8_cdec_sa_6BitSet_7insert, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("findsucc"), (PyCFunction)__pyx_pw_8_cdec_sa_6BitSet_9findsucc, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("min"), (PyCFunction)__pyx_pw_8_cdec_sa_6BitSet_13min, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("max"), (PyCFunction)__pyx_pw_8_cdec_sa_6BitSet_15max, METH_NOARGS, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_BitSet = { - 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_BitSet = { - __pyx_pw_8_cdec_sa_6BitSet_17__len__, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - __pyx_pw_8_cdec_sa_6BitSet_19__contains__, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_BitSet = { - __pyx_pw_8_cdec_sa_6BitSet_17__len__, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_BitSet = { - #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_8_cdec_sa_BitSet = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.BitSet"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_BitSet), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_BitSet, /*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_BitSet, /*tp_as_number*/ - &__pyx_tp_as_sequence_BitSet, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_BitSet, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - __pyx_pw_8_cdec_sa_6BitSet_11__str__, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_BitSet, /*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_pw_8_cdec_sa_6BitSet_5__iter__, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_BitSet, /*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_8_cdec_sa_BitSet, /*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_8_cdec_sa_VEBIterator(PyTypeObject *t, PyObject *a, PyObject *k) { - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_VEBIterator(PyObject *o) { - (*Py_TYPE(o)->tp_free)(o); -} - -static PyMethodDef __pyx_methods_8_cdec_sa_VEBIterator[] = { - {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_8_cdec_sa_11VEBIterator_1__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_VEBIterator = { - 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_VEBIterator = { - 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_VEBIterator = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_VEBIterator = { - #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_8_cdec_sa_VEBIterator = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.VEBIterator"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_VEBIterator), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_VEBIterator, /*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_VEBIterator, /*tp_as_number*/ - &__pyx_tp_as_sequence_VEBIterator, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_VEBIterator, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_VEBIterator, /*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*/ - 0, /*tp_iter*/ - __pyx_pw_8_cdec_sa_11VEBIterator_1__next__, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_VEBIterator, /*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_8_cdec_sa_VEBIterator, /*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 struct __pyx_vtabstruct_8_cdec_sa_VEB __pyx_vtable_8_cdec_sa_VEB; - -static PyObject *__pyx_tp_new_8_cdec_sa_VEB(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_VEB *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_VEB *)o); - p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_VEB; - if (__pyx_pw_8_cdec_sa_3VEB_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_VEB(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_8_cdec_sa_3VEB_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_8_cdec_sa_VEB[] = { - {__Pyx_NAMESTR("insert"), (PyCFunction)__pyx_pw_8_cdec_sa_3VEB_7insert, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("findsucc"), (PyCFunction)__pyx_pw_8_cdec_sa_3VEB_9findsucc, METH_O, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_VEB = { - 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_VEB = { - __pyx_pw_8_cdec_sa_3VEB_11__len__, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - __pyx_pw_8_cdec_sa_3VEB_13__contains__, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_VEB = { - __pyx_pw_8_cdec_sa_3VEB_11__len__, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_VEB = { - #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_8_cdec_sa_VEB = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.VEB"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_VEB), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_VEB, /*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_VEB, /*tp_as_number*/ - &__pyx_tp_as_sequence_VEB, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_VEB, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_VEB, /*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_pw_8_cdec_sa_3VEB_5__iter__, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_VEB, /*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_8_cdec_sa_VEB, /*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_8_cdec_sa_LCP(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_LCP *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_LCP *)o); - p->sa = ((struct __pyx_obj_8_cdec_sa_SuffixArray *)Py_None); Py_INCREF(Py_None); - p->lcp = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - if (__pyx_pw_8_cdec_sa_3LCP_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_LCP(PyObject *o) { - struct __pyx_obj_8_cdec_sa_LCP *p = (struct __pyx_obj_8_cdec_sa_LCP *)o; - Py_XDECREF(((PyObject *)p->sa)); - Py_XDECREF(((PyObject *)p->lcp)); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_8_cdec_sa_LCP(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_8_cdec_sa_LCP *p = (struct __pyx_obj_8_cdec_sa_LCP *)o; - if (p->sa) { - e = (*v)(((PyObject*)p->sa), a); if (e) return e; - } - if (p->lcp) { - e = (*v)(((PyObject*)p->lcp), a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_8_cdec_sa_LCP(PyObject *o) { - struct __pyx_obj_8_cdec_sa_LCP *p = (struct __pyx_obj_8_cdec_sa_LCP *)o; - PyObject* tmp; - tmp = ((PyObject*)p->sa); - p->sa = ((struct __pyx_obj_8_cdec_sa_SuffixArray *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->lcp); - p->lcp = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyMethodDef __pyx_methods_8_cdec_sa_LCP[] = { - {__Pyx_NAMESTR("compute_stats"), (PyCFunction)__pyx_pw_8_cdec_sa_3LCP_3compute_stats, METH_O, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_3LCP_2compute_stats)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_LCP = { - 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_LCP = { - 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_LCP = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_LCP = { - #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_8_cdec_sa_LCP = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.LCP"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_LCP), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_LCP, /*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_LCP, /*tp_as_number*/ - &__pyx_tp_as_sequence_LCP, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_LCP, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_LCP, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_8_cdec_sa_LCP, /*tp_traverse*/ - __pyx_tp_clear_8_cdec_sa_LCP, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_LCP, /*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_8_cdec_sa_LCP, /*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 struct __pyx_vtabstruct_8_cdec_sa_Alphabet __pyx_vtable_8_cdec_sa_Alphabet; - -static PyObject *__pyx_tp_new_8_cdec_sa_Alphabet(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_Alphabet *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_Alphabet *)o); - p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_Alphabet; - p->terminals = ((struct __pyx_obj_8_cdec_sa_StringMap *)Py_None); Py_INCREF(Py_None); - p->nonterminals = ((struct __pyx_obj_8_cdec_sa_StringMap *)Py_None); Py_INCREF(Py_None); - p->id2sym = ((PyObject*)Py_None); Py_INCREF(Py_None); - if (__pyx_pw_8_cdec_sa_8Alphabet_1__cinit__(o, __pyx_empty_tuple, NULL) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_Alphabet(PyObject *o) { - struct __pyx_obj_8_cdec_sa_Alphabet *p = (struct __pyx_obj_8_cdec_sa_Alphabet *)o; - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_8_cdec_sa_8Alphabet_3__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - Py_XDECREF(((PyObject *)p->terminals)); - Py_XDECREF(((PyObject *)p->nonterminals)); - Py_XDECREF(((PyObject *)p->id2sym)); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_8_cdec_sa_Alphabet(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_8_cdec_sa_Alphabet *p = (struct __pyx_obj_8_cdec_sa_Alphabet *)o; - if (p->terminals) { - e = (*v)(((PyObject*)p->terminals), a); if (e) return e; - } - if (p->nonterminals) { - e = (*v)(((PyObject*)p->nonterminals), a); if (e) return e; - } - if (p->id2sym) { - e = (*v)(p->id2sym, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_8_cdec_sa_Alphabet(PyObject *o) { - struct __pyx_obj_8_cdec_sa_Alphabet *p = (struct __pyx_obj_8_cdec_sa_Alphabet *)o; - PyObject* tmp; - tmp = ((PyObject*)p->terminals); - p->terminals = ((struct __pyx_obj_8_cdec_sa_StringMap *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->nonterminals); - p->nonterminals = ((struct __pyx_obj_8_cdec_sa_StringMap *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->id2sym); - p->id2sym = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyObject *__pyx_getprop_8_cdec_sa_8Alphabet_terminals(PyObject *o, void *x) { - return __pyx_pw_8_cdec_sa_8Alphabet_9terminals_1__get__(o); -} - -static PyObject *__pyx_getprop_8_cdec_sa_8Alphabet_nonterminals(PyObject *o, void *x) { - return __pyx_pw_8_cdec_sa_8Alphabet_12nonterminals_1__get__(o); -} - -static PyMethodDef __pyx_methods_8_cdec_sa_Alphabet[] = { - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_8_cdec_sa_Alphabet[] = { - {(char *)"terminals", __pyx_getprop_8_cdec_sa_8Alphabet_terminals, 0, 0, 0}, - {(char *)"nonterminals", __pyx_getprop_8_cdec_sa_8Alphabet_nonterminals, 0, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_Alphabet = { - 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_Alphabet = { - 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_Alphabet = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_Alphabet = { - #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_8_cdec_sa_Alphabet = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.Alphabet"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_Alphabet), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_Alphabet, /*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_Alphabet, /*tp_as_number*/ - &__pyx_tp_as_sequence_Alphabet, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Alphabet, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Alphabet, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_8_cdec_sa_Alphabet, /*tp_traverse*/ - __pyx_tp_clear_8_cdec_sa_Alphabet, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_Alphabet, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_8_cdec_sa_Alphabet, /*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_8_cdec_sa_Alphabet, /*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 struct __pyx_vtabstruct_8_cdec_sa_Phrase __pyx_vtable_8_cdec_sa_Phrase; - -static PyObject *__pyx_tp_new_8_cdec_sa_Phrase(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_Phrase *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_Phrase *)o); - p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_Phrase; - if (__pyx_pw_8_cdec_sa_6Phrase_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_Phrase(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_8_cdec_sa_6Phrase_3__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - (*Py_TYPE(o)->tp_free)(o); -} -static PyObject *__pyx_sq_item_8_cdec_sa_Phrase(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} - -static PyMethodDef __pyx_methods_8_cdec_sa_Phrase[] = { - {__Pyx_NAMESTR("handle"), (PyCFunction)__pyx_pw_8_cdec_sa_6Phrase_7handle, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_6Phrase_6handle)}, - {__Pyx_NAMESTR("strhandle"), (PyCFunction)__pyx_pw_8_cdec_sa_6Phrase_9strhandle, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("arity"), (PyCFunction)__pyx_pw_8_cdec_sa_6Phrase_11arity, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("getvarpos"), (PyCFunction)__pyx_pw_8_cdec_sa_6Phrase_13getvarpos, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("getvar"), (PyCFunction)__pyx_pw_8_cdec_sa_6Phrase_15getvar, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("clen"), (PyCFunction)__pyx_pw_8_cdec_sa_6Phrase_17clen, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("getchunk"), (PyCFunction)__pyx_pw_8_cdec_sa_6Phrase_19getchunk, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("subst"), (PyCFunction)__pyx_pw_8_cdec_sa_6Phrase_31subst, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_Phrase = { - 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_Phrase = { - __pyx_pw_8_cdec_sa_6Phrase_25__len__, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - __pyx_sq_item_8_cdec_sa_Phrase, /*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_Phrase = { - __pyx_pw_8_cdec_sa_6Phrase_25__len__, /*mp_length*/ - __pyx_pw_8_cdec_sa_6Phrase_27__getitem__, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_Phrase = { - #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_8_cdec_sa_Phrase = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.Phrase"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_Phrase), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_Phrase, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - __pyx_pw_8_cdec_sa_6Phrase_21__cmp__, /*tp_compare*/ - #else - 0, /*reserved*/ - #endif - 0, /*tp_repr*/ - &__pyx_tp_as_number_Phrase, /*tp_as_number*/ - &__pyx_tp_as_sequence_Phrase, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Phrase, /*tp_as_mapping*/ - __pyx_pw_8_cdec_sa_6Phrase_23__hash__, /*tp_hash*/ - 0, /*tp_call*/ - __pyx_pw_8_cdec_sa_6Phrase_5__str__, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Phrase, /*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_pw_8_cdec_sa_6Phrase_29__iter__, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_Phrase, /*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_8_cdec_sa_Phrase, /*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_8_cdec_sa_Rule(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_Rule *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_Rule *)o); - p->f = ((struct __pyx_obj_8_cdec_sa_Phrase *)Py_None); Py_INCREF(Py_None); - p->e = ((struct __pyx_obj_8_cdec_sa_Phrase *)Py_None); Py_INCREF(Py_None); - p->word_alignments = Py_None; Py_INCREF(Py_None); - if (__pyx_pw_8_cdec_sa_4Rule_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_Rule(PyObject *o) { - struct __pyx_obj_8_cdec_sa_Rule *p = (struct __pyx_obj_8_cdec_sa_Rule *)o; - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_8_cdec_sa_4Rule_3__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - Py_XDECREF(((PyObject *)p->f)); - Py_XDECREF(((PyObject *)p->e)); - Py_XDECREF(p->word_alignments); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_8_cdec_sa_Rule(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_8_cdec_sa_Rule *p = (struct __pyx_obj_8_cdec_sa_Rule *)o; - if (p->f) { - e = (*v)(((PyObject*)p->f), a); if (e) return e; - } - if (p->e) { - e = (*v)(((PyObject*)p->e), a); if (e) return e; - } - if (p->word_alignments) { - e = (*v)(p->word_alignments, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_8_cdec_sa_Rule(PyObject *o) { - struct __pyx_obj_8_cdec_sa_Rule *p = (struct __pyx_obj_8_cdec_sa_Rule *)o; - PyObject* tmp; - tmp = ((PyObject*)p->f); - p->f = ((struct __pyx_obj_8_cdec_sa_Phrase *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->e); - p->e = ((struct __pyx_obj_8_cdec_sa_Phrase *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->word_alignments); - p->word_alignments = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyObject *__pyx_getprop_8_cdec_sa_4Rule_scores(PyObject *o, void *x) { - return __pyx_pw_8_cdec_sa_4Rule_6scores_1__get__(o); -} - -static int __pyx_setprop_8_cdec_sa_4Rule_scores(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_8_cdec_sa_4Rule_6scores_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} - -static PyObject *__pyx_getprop_8_cdec_sa_4Rule_lhs(PyObject *o, void *x) { - return __pyx_pw_8_cdec_sa_4Rule_3lhs_1__get__(o); -} - -static int __pyx_setprop_8_cdec_sa_4Rule_lhs(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_8_cdec_sa_4Rule_3lhs_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} - -static PyObject *__pyx_getprop_8_cdec_sa_4Rule_f(PyObject *o, void *x) { - return __pyx_pw_8_cdec_sa_4Rule_1f_1__get__(o); -} - -static PyObject *__pyx_getprop_8_cdec_sa_4Rule_e(PyObject *o, void *x) { - return __pyx_pw_8_cdec_sa_4Rule_1e_1__get__(o); -} - -static PyObject *__pyx_getprop_8_cdec_sa_4Rule_word_alignments(PyObject *o, void *x) { - return __pyx_pw_8_cdec_sa_4Rule_15word_alignments_1__get__(o); -} - -static int __pyx_setprop_8_cdec_sa_4Rule_word_alignments(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_8_cdec_sa_4Rule_15word_alignments_3__set__(o, v); - } - else { - return __pyx_pw_8_cdec_sa_4Rule_15word_alignments_5__del__(o); - } -} - -static PyMethodDef __pyx_methods_8_cdec_sa_Rule[] = { - {__Pyx_NAMESTR("fmerge"), (PyCFunction)__pyx_pw_8_cdec_sa_4Rule_11fmerge, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("arity"), (PyCFunction)__pyx_pw_8_cdec_sa_4Rule_13arity, METH_NOARGS, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_8_cdec_sa_Rule[] = { - {(char *)"scores", __pyx_getprop_8_cdec_sa_4Rule_scores, __pyx_setprop_8_cdec_sa_4Rule_scores, 0, 0}, - {(char *)"lhs", __pyx_getprop_8_cdec_sa_4Rule_lhs, __pyx_setprop_8_cdec_sa_4Rule_lhs, 0, 0}, - {(char *)"f", __pyx_getprop_8_cdec_sa_4Rule_f, 0, 0, 0}, - {(char *)"e", __pyx_getprop_8_cdec_sa_4Rule_e, 0, 0, 0}, - {(char *)"word_alignments", __pyx_getprop_8_cdec_sa_4Rule_word_alignments, __pyx_setprop_8_cdec_sa_4Rule_word_alignments, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_Rule = { - 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 - __pyx_pw_8_cdec_sa_4Rule_9__iadd__, /*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_Rule = { - 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_Rule = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_Rule = { - #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_8_cdec_sa_Rule = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.Rule"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_Rule), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_Rule, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - #if PY_MAJOR_VERSION < 3 - __pyx_pw_8_cdec_sa_4Rule_7__cmp__, /*tp_compare*/ - #else - 0, /*reserved*/ - #endif - 0, /*tp_repr*/ - &__pyx_tp_as_number_Rule, /*tp_as_number*/ - &__pyx_tp_as_sequence_Rule, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Rule, /*tp_as_mapping*/ - __pyx_pw_8_cdec_sa_4Rule_5__hash__, /*tp_hash*/ - 0, /*tp_call*/ - __pyx_pw_8_cdec_sa_4Rule_15__str__, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Rule, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_8_cdec_sa_Rule, /*tp_traverse*/ - __pyx_tp_clear_8_cdec_sa_Rule, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_Rule, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_8_cdec_sa_Rule, /*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_8_cdec_sa_Rule, /*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 struct __pyx_vtabstruct_8_cdec_sa_TrieMap __pyx_vtable_8_cdec_sa_TrieMap; - -static PyObject *__pyx_tp_new_8_cdec_sa_TrieMap(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_TrieMap *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_TrieMap *)o); - p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_TrieMap; - if (__pyx_pw_8_cdec_sa_7TrieMap_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_TrieMap(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_8_cdec_sa_7TrieMap_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_8_cdec_sa_TrieMap[] = { - {__Pyx_NAMESTR("insert"), (PyCFunction)__pyx_pw_8_cdec_sa_7TrieMap_5insert, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("contains"), (PyCFunction)__pyx_pw_8_cdec_sa_7TrieMap_7contains, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("toMap"), (PyCFunction)__pyx_pw_8_cdec_sa_7TrieMap_9toMap, METH_O, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_TrieMap = { - 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_TrieMap = { - 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_TrieMap = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_TrieMap = { - #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_8_cdec_sa_TrieMap = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.TrieMap"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_TrieMap), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_TrieMap, /*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_TrieMap, /*tp_as_number*/ - &__pyx_tp_as_sequence_TrieMap, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_TrieMap, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_TrieMap, /*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*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_TrieMap, /*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_8_cdec_sa_TrieMap, /*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 struct __pyx_vtabstruct_8_cdec_sa_Precomputation __pyx_vtable_8_cdec_sa_Precomputation; - -static PyObject *__pyx_tp_new_8_cdec_sa_Precomputation(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_Precomputation *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_Precomputation *)o); - p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_Precomputation; - p->precomputed_index = Py_None; Py_INCREF(Py_None); - p->precomputed_collocations = Py_None; Py_INCREF(Py_None); - if (__pyx_pw_8_cdec_sa_14Precomputation_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_Precomputation(PyObject *o) { - struct __pyx_obj_8_cdec_sa_Precomputation *p = (struct __pyx_obj_8_cdec_sa_Precomputation *)o; - Py_XDECREF(p->precomputed_index); - Py_XDECREF(p->precomputed_collocations); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_8_cdec_sa_Precomputation(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_8_cdec_sa_Precomputation *p = (struct __pyx_obj_8_cdec_sa_Precomputation *)o; - if (p->precomputed_index) { - e = (*v)(p->precomputed_index, a); if (e) return e; - } - if (p->precomputed_collocations) { - e = (*v)(p->precomputed_collocations, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_8_cdec_sa_Precomputation(PyObject *o) { - struct __pyx_obj_8_cdec_sa_Precomputation *p = (struct __pyx_obj_8_cdec_sa_Precomputation *)o; - PyObject* tmp; - tmp = ((PyObject*)p->precomputed_index); - p->precomputed_index = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->precomputed_collocations); - p->precomputed_collocations = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyMethodDef __pyx_methods_8_cdec_sa_Precomputation[] = { - {__Pyx_NAMESTR("read_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_14Precomputation_3read_binary, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("write_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_14Precomputation_5write_binary, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("precompute"), (PyCFunction)__pyx_pw_8_cdec_sa_14Precomputation_7precompute, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_Precomputation = { - 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_Precomputation = { - 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_Precomputation = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_Precomputation = { - #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_8_cdec_sa_Precomputation = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.Precomputation"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_Precomputation), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_Precomputation, /*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_Precomputation, /*tp_as_number*/ - &__pyx_tp_as_sequence_Precomputation, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Precomputation, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Precomputation, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_8_cdec_sa_Precomputation, /*tp_traverse*/ - __pyx_tp_clear_8_cdec_sa_Precomputation, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_Precomputation, /*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_8_cdec_sa_Precomputation, /*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 struct __pyx_vtabstruct_8_cdec_sa_SuffixArray __pyx_vtable_8_cdec_sa_SuffixArray; - -static PyObject *__pyx_tp_new_8_cdec_sa_SuffixArray(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_SuffixArray *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_SuffixArray *)o); - p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_SuffixArray; - p->darray = ((struct __pyx_obj_8_cdec_sa_DataArray *)Py_None); Py_INCREF(Py_None); - p->sa = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - p->ha = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - if (__pyx_pw_8_cdec_sa_11SuffixArray_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_SuffixArray(PyObject *o) { - struct __pyx_obj_8_cdec_sa_SuffixArray *p = (struct __pyx_obj_8_cdec_sa_SuffixArray *)o; - Py_XDECREF(((PyObject *)p->darray)); - Py_XDECREF(((PyObject *)p->sa)); - Py_XDECREF(((PyObject *)p->ha)); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_8_cdec_sa_SuffixArray(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_8_cdec_sa_SuffixArray *p = (struct __pyx_obj_8_cdec_sa_SuffixArray *)o; - if (p->darray) { - e = (*v)(((PyObject*)p->darray), a); if (e) return e; - } - if (p->sa) { - e = (*v)(((PyObject*)p->sa), a); if (e) return e; - } - if (p->ha) { - e = (*v)(((PyObject*)p->ha), a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_8_cdec_sa_SuffixArray(PyObject *o) { - struct __pyx_obj_8_cdec_sa_SuffixArray *p = (struct __pyx_obj_8_cdec_sa_SuffixArray *)o; - PyObject* tmp; - tmp = ((PyObject*)p->darray); - p->darray = ((struct __pyx_obj_8_cdec_sa_DataArray *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->sa); - p->sa = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->ha); - p->ha = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} -static PyObject *__pyx_sq_item_8_cdec_sa_SuffixArray(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} - -static PyMethodDef __pyx_methods_8_cdec_sa_SuffixArray[] = { - {__Pyx_NAMESTR("getSentId"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_5getSentId, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("getSent"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_7getSent, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("getSentPos"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_9getSentPos, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("read_text"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_11read_text, METH_O, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_11SuffixArray_10read_text)}, - {__Pyx_NAMESTR("q3sort"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_13q3sort, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_11SuffixArray_12q3sort)}, - {__Pyx_NAMESTR("write_text"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_15write_text, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("read_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_17read_binary, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("write_binary"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_19write_binary, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("write_enhanced"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_21write_enhanced, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("lookup"), (PyCFunction)__pyx_pw_8_cdec_sa_11SuffixArray_23lookup, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_SuffixArray = { - 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_SuffixArray = { - 0, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - __pyx_sq_item_8_cdec_sa_SuffixArray, /*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_SuffixArray = { - 0, /*mp_length*/ - __pyx_pw_8_cdec_sa_11SuffixArray_3__getitem__, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_SuffixArray = { - #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_8_cdec_sa_SuffixArray = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.SuffixArray"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_SuffixArray), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_SuffixArray, /*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_SuffixArray, /*tp_as_number*/ - &__pyx_tp_as_sequence_SuffixArray, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_SuffixArray, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_SuffixArray, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_8_cdec_sa_SuffixArray, /*tp_traverse*/ - __pyx_tp_clear_8_cdec_sa_SuffixArray, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_SuffixArray, /*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_8_cdec_sa_SuffixArray, /*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_8_cdec_sa_TrieNode(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_TrieNode *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_TrieNode *)o); - p->children = Py_None; Py_INCREF(Py_None); - if (__pyx_pw_8_cdec_sa_8TrieNode_1__cinit__(o, __pyx_empty_tuple, NULL) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_TrieNode(PyObject *o) { - struct __pyx_obj_8_cdec_sa_TrieNode *p = (struct __pyx_obj_8_cdec_sa_TrieNode *)o; - Py_XDECREF(p->children); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_8_cdec_sa_TrieNode(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_8_cdec_sa_TrieNode *p = (struct __pyx_obj_8_cdec_sa_TrieNode *)o; - if (p->children) { - e = (*v)(p->children, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_8_cdec_sa_TrieNode(PyObject *o) { - struct __pyx_obj_8_cdec_sa_TrieNode *p = (struct __pyx_obj_8_cdec_sa_TrieNode *)o; - PyObject* tmp; - tmp = ((PyObject*)p->children); - p->children = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyObject *__pyx_getprop_8_cdec_sa_8TrieNode_children(PyObject *o, void *x) { - return __pyx_pw_8_cdec_sa_8TrieNode_8children_1__get__(o); -} - -static int __pyx_setprop_8_cdec_sa_8TrieNode_children(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_8_cdec_sa_8TrieNode_8children_3__set__(o, v); - } - else { - return __pyx_pw_8_cdec_sa_8TrieNode_8children_5__del__(o); - } -} - -static PyMethodDef __pyx_methods_8_cdec_sa_TrieNode[] = { - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_8_cdec_sa_TrieNode[] = { - {(char *)"children", __pyx_getprop_8_cdec_sa_8TrieNode_children, __pyx_setprop_8_cdec_sa_8TrieNode_children, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_TrieNode = { - 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_TrieNode = { - 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_TrieNode = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_TrieNode = { - #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_8_cdec_sa_TrieNode = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.TrieNode"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_TrieNode), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_TrieNode, /*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_TrieNode, /*tp_as_number*/ - &__pyx_tp_as_sequence_TrieNode, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_TrieNode, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_TrieNode, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_8_cdec_sa_TrieNode, /*tp_traverse*/ - __pyx_tp_clear_8_cdec_sa_TrieNode, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_TrieNode, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_8_cdec_sa_TrieNode, /*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_8_cdec_sa_TrieNode, /*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_8_cdec_sa_ExtendedTrieNode(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *p; - PyObject *o = __pyx_tp_new_8_cdec_sa_TrieNode(t, a, k); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)o); - p->phrase = Py_None; Py_INCREF(Py_None); - p->phrase_location = Py_None; Py_INCREF(Py_None); - p->suffix_link = Py_None; Py_INCREF(Py_None); - if (__pyx_pw_8_cdec_sa_16ExtendedTrieNode_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_ExtendedTrieNode(PyObject *o) { - struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *p = (struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)o; - Py_XDECREF(p->phrase); - Py_XDECREF(p->phrase_location); - Py_XDECREF(p->suffix_link); - __pyx_tp_dealloc_8_cdec_sa_TrieNode(o); -} - -static int __pyx_tp_traverse_8_cdec_sa_ExtendedTrieNode(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *p = (struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)o; - e = __pyx_tp_traverse_8_cdec_sa_TrieNode(o, v, a); if (e) return e; - if (p->phrase) { - e = (*v)(p->phrase, a); if (e) return e; - } - if (p->phrase_location) { - e = (*v)(p->phrase_location, a); if (e) return e; - } - if (p->suffix_link) { - e = (*v)(p->suffix_link, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_8_cdec_sa_ExtendedTrieNode(PyObject *o) { - struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *p = (struct __pyx_obj_8_cdec_sa_ExtendedTrieNode *)o; - PyObject* tmp; - __pyx_tp_clear_8_cdec_sa_TrieNode(o); - tmp = ((PyObject*)p->phrase); - p->phrase = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->phrase_location); - p->phrase_location = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->suffix_link); - p->suffix_link = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyObject *__pyx_getprop_8_cdec_sa_16ExtendedTrieNode_phrase(PyObject *o, void *x) { - return __pyx_pw_8_cdec_sa_16ExtendedTrieNode_6phrase_1__get__(o); -} - -static int __pyx_setprop_8_cdec_sa_16ExtendedTrieNode_phrase(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_8_cdec_sa_16ExtendedTrieNode_6phrase_3__set__(o, v); - } - else { - return __pyx_pw_8_cdec_sa_16ExtendedTrieNode_6phrase_5__del__(o); - } -} - -static PyObject *__pyx_getprop_8_cdec_sa_16ExtendedTrieNode_phrase_location(PyObject *o, void *x) { - return __pyx_pw_8_cdec_sa_16ExtendedTrieNode_15phrase_location_1__get__(o); -} - -static int __pyx_setprop_8_cdec_sa_16ExtendedTrieNode_phrase_location(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_8_cdec_sa_16ExtendedTrieNode_15phrase_location_3__set__(o, v); - } - else { - return __pyx_pw_8_cdec_sa_16ExtendedTrieNode_15phrase_location_5__del__(o); - } -} - -static PyObject *__pyx_getprop_8_cdec_sa_16ExtendedTrieNode_suffix_link(PyObject *o, void *x) { - return __pyx_pw_8_cdec_sa_16ExtendedTrieNode_11suffix_link_1__get__(o); -} - -static int __pyx_setprop_8_cdec_sa_16ExtendedTrieNode_suffix_link(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_8_cdec_sa_16ExtendedTrieNode_11suffix_link_3__set__(o, v); - } - else { - return __pyx_pw_8_cdec_sa_16ExtendedTrieNode_11suffix_link_5__del__(o); - } -} - -static PyMethodDef __pyx_methods_8_cdec_sa_ExtendedTrieNode[] = { - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_8_cdec_sa_ExtendedTrieNode[] = { - {(char *)"phrase", __pyx_getprop_8_cdec_sa_16ExtendedTrieNode_phrase, __pyx_setprop_8_cdec_sa_16ExtendedTrieNode_phrase, 0, 0}, - {(char *)"phrase_location", __pyx_getprop_8_cdec_sa_16ExtendedTrieNode_phrase_location, __pyx_setprop_8_cdec_sa_16ExtendedTrieNode_phrase_location, 0, 0}, - {(char *)"suffix_link", __pyx_getprop_8_cdec_sa_16ExtendedTrieNode_suffix_link, __pyx_setprop_8_cdec_sa_16ExtendedTrieNode_suffix_link, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_ExtendedTrieNode = { - 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_ExtendedTrieNode = { - 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_ExtendedTrieNode = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_ExtendedTrieNode = { - #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_8_cdec_sa_ExtendedTrieNode = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.ExtendedTrieNode"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_ExtendedTrieNode), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_ExtendedTrieNode, /*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_ExtendedTrieNode, /*tp_as_number*/ - &__pyx_tp_as_sequence_ExtendedTrieNode, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_ExtendedTrieNode, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_ExtendedTrieNode, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_8_cdec_sa_ExtendedTrieNode, /*tp_traverse*/ - __pyx_tp_clear_8_cdec_sa_ExtendedTrieNode, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_ExtendedTrieNode, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_8_cdec_sa_ExtendedTrieNode, /*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_8_cdec_sa_ExtendedTrieNode, /*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_8_cdec_sa_TrieTable(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_TrieTable *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_TrieTable *)o); - p->root = Py_None; Py_INCREF(Py_None); - if (__pyx_pw_8_cdec_sa_9TrieTable_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_TrieTable(PyObject *o) { - struct __pyx_obj_8_cdec_sa_TrieTable *p = (struct __pyx_obj_8_cdec_sa_TrieTable *)o; - Py_XDECREF(p->root); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_8_cdec_sa_TrieTable(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_8_cdec_sa_TrieTable *p = (struct __pyx_obj_8_cdec_sa_TrieTable *)o; - if (p->root) { - e = (*v)(p->root, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_8_cdec_sa_TrieTable(PyObject *o) { - struct __pyx_obj_8_cdec_sa_TrieTable *p = (struct __pyx_obj_8_cdec_sa_TrieTable *)o; - PyObject* tmp; - tmp = ((PyObject*)p->root); - p->root = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyObject *__pyx_getprop_8_cdec_sa_9TrieTable_extended(PyObject *o, void *x) { - return __pyx_pw_8_cdec_sa_9TrieTable_8extended_1__get__(o); -} - -static int __pyx_setprop_8_cdec_sa_9TrieTable_extended(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_8_cdec_sa_9TrieTable_8extended_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} - -static PyObject *__pyx_getprop_8_cdec_sa_9TrieTable_count(PyObject *o, void *x) { - return __pyx_pw_8_cdec_sa_9TrieTable_5count_1__get__(o); -} - -static int __pyx_setprop_8_cdec_sa_9TrieTable_count(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_8_cdec_sa_9TrieTable_5count_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} - -static PyObject *__pyx_getprop_8_cdec_sa_9TrieTable_root(PyObject *o, void *x) { - return __pyx_pw_8_cdec_sa_9TrieTable_4root_1__get__(o); -} - -static int __pyx_setprop_8_cdec_sa_9TrieTable_root(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_8_cdec_sa_9TrieTable_4root_3__set__(o, v); - } - else { - return __pyx_pw_8_cdec_sa_9TrieTable_4root_5__del__(o); - } -} - -static PyMethodDef __pyx_methods_8_cdec_sa_TrieTable[] = { - {0, 0, 0, 0} -}; - -static struct PyGetSetDef __pyx_getsets_8_cdec_sa_TrieTable[] = { - {(char *)"extended", __pyx_getprop_8_cdec_sa_9TrieTable_extended, __pyx_setprop_8_cdec_sa_9TrieTable_extended, 0, 0}, - {(char *)"count", __pyx_getprop_8_cdec_sa_9TrieTable_count, __pyx_setprop_8_cdec_sa_9TrieTable_count, 0, 0}, - {(char *)"root", __pyx_getprop_8_cdec_sa_9TrieTable_root, __pyx_setprop_8_cdec_sa_9TrieTable_root, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_TrieTable = { - 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_TrieTable = { - 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_TrieTable = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_TrieTable = { - #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_8_cdec_sa_TrieTable = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.TrieTable"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_TrieTable), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_TrieTable, /*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_TrieTable, /*tp_as_number*/ - &__pyx_tp_as_sequence_TrieTable, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_TrieTable, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_TrieTable, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_8_cdec_sa_TrieTable, /*tp_traverse*/ - __pyx_tp_clear_8_cdec_sa_TrieTable, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_TrieTable, /*tp_methods*/ - 0, /*tp_members*/ - __pyx_getsets_8_cdec_sa_TrieTable, /*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_8_cdec_sa_TrieTable, /*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 struct __pyx_vtabstruct_8_cdec_sa_PhraseLocation __pyx_vtable_8_cdec_sa_PhraseLocation; - -static PyObject *__pyx_tp_new_8_cdec_sa_PhraseLocation(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_PhraseLocation *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)o); - p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_PhraseLocation; - p->arr = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - if (__pyx_pw_8_cdec_sa_14PhraseLocation_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_PhraseLocation(PyObject *o) { - struct __pyx_obj_8_cdec_sa_PhraseLocation *p = (struct __pyx_obj_8_cdec_sa_PhraseLocation *)o; - Py_XDECREF(((PyObject *)p->arr)); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_8_cdec_sa_PhraseLocation(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_8_cdec_sa_PhraseLocation *p = (struct __pyx_obj_8_cdec_sa_PhraseLocation *)o; - if (p->arr) { - e = (*v)(((PyObject*)p->arr), a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_8_cdec_sa_PhraseLocation(PyObject *o) { - struct __pyx_obj_8_cdec_sa_PhraseLocation *p = (struct __pyx_obj_8_cdec_sa_PhraseLocation *)o; - PyObject* tmp; - tmp = ((PyObject*)p->arr); - p->arr = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyMethodDef __pyx_methods_8_cdec_sa_PhraseLocation[] = { - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_PhraseLocation = { - 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_PhraseLocation = { - 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_PhraseLocation = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_PhraseLocation = { - #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_8_cdec_sa_PhraseLocation = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.PhraseLocation"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_PhraseLocation), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_PhraseLocation, /*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_PhraseLocation, /*tp_as_number*/ - &__pyx_tp_as_sequence_PhraseLocation, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_PhraseLocation, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_PhraseLocation, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - __pyx_tp_traverse_8_cdec_sa_PhraseLocation, /*tp_traverse*/ - __pyx_tp_clear_8_cdec_sa_PhraseLocation, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_PhraseLocation, /*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_8_cdec_sa_PhraseLocation, /*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_8_cdec_sa_Sampler(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_Sampler *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_Sampler *)o); - p->sa = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - if (__pyx_pw_8_cdec_sa_7Sampler_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_Sampler(PyObject *o) { - struct __pyx_obj_8_cdec_sa_Sampler *p = (struct __pyx_obj_8_cdec_sa_Sampler *)o; - Py_XDECREF(((PyObject *)p->sa)); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_8_cdec_sa_Sampler(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_8_cdec_sa_Sampler *p = (struct __pyx_obj_8_cdec_sa_Sampler *)o; - if (p->sa) { - e = (*v)(((PyObject*)p->sa), a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_8_cdec_sa_Sampler(PyObject *o) { - struct __pyx_obj_8_cdec_sa_Sampler *p = (struct __pyx_obj_8_cdec_sa_Sampler *)o; - PyObject* tmp; - tmp = ((PyObject*)p->sa); - p->sa = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyMethodDef __pyx_methods_8_cdec_sa_Sampler[] = { - {__Pyx_NAMESTR("sample"), (PyCFunction)__pyx_pw_8_cdec_sa_7Sampler_3sample, METH_O, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_7Sampler_2sample)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_Sampler = { - 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_Sampler = { - 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_Sampler = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_Sampler = { - #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_8_cdec_sa_Sampler = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.Sampler"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_Sampler), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_Sampler, /*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_Sampler, /*tp_as_number*/ - &__pyx_tp_as_sequence_Sampler, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Sampler, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Sampler, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - __Pyx_DOCSTR("A Sampler implements a logic for choosing\n samples from a population range"), /*tp_doc*/ - __pyx_tp_traverse_8_cdec_sa_Sampler, /*tp_traverse*/ - __pyx_tp_clear_8_cdec_sa_Sampler, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_Sampler, /*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_8_cdec_sa_Sampler, /*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 struct __pyx_vtabstruct_8_cdec_sa_HieroCachingRuleFactory __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory; - -static PyObject *__pyx_tp_new_8_cdec_sa_HieroCachingRuleFactory(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)o); - p->__pyx_vtab = __pyx_vtabptr_8_cdec_sa_HieroCachingRuleFactory; - p->rules = ((struct __pyx_obj_8_cdec_sa_TrieTable *)Py_None); Py_INCREF(Py_None); - p->sampler = ((struct __pyx_obj_8_cdec_sa_Sampler *)Py_None); Py_INCREF(Py_None); - p->precomputed_index = Py_None; Py_INCREF(Py_None); - p->precomputed_collocations = Py_None; Py_INCREF(Py_None); - p->precompute_file = Py_None; Py_INCREF(Py_None); - p->max_rank = Py_None; Py_INCREF(Py_None); - p->prev_norm_prefix = Py_None; Py_INCREF(Py_None); - p->fsa = ((struct __pyx_obj_8_cdec_sa_SuffixArray *)Py_None); Py_INCREF(Py_None); - p->fda = ((struct __pyx_obj_8_cdec_sa_DataArray *)Py_None); Py_INCREF(Py_None); - p->eda = ((struct __pyx_obj_8_cdec_sa_DataArray *)Py_None); Py_INCREF(Py_None); - p->alignment = ((struct __pyx_obj_8_cdec_sa_Alignment *)Py_None); Py_INCREF(Py_None); - p->eid2symid = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - p->fid2symid = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - p->findexes = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - p->findexes1 = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - if (__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa_HieroCachingRuleFactory(PyObject *o) { - struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *p = (struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)o; - Py_XDECREF(((PyObject *)p->rules)); - Py_XDECREF(((PyObject *)p->sampler)); - Py_XDECREF(p->precomputed_index); - Py_XDECREF(p->precomputed_collocations); - Py_XDECREF(p->precompute_file); - Py_XDECREF(p->max_rank); - Py_XDECREF(p->prev_norm_prefix); - Py_XDECREF(((PyObject *)p->fsa)); - Py_XDECREF(((PyObject *)p->fda)); - Py_XDECREF(((PyObject *)p->eda)); - Py_XDECREF(((PyObject *)p->alignment)); - Py_XDECREF(((PyObject *)p->eid2symid)); - Py_XDECREF(((PyObject *)p->fid2symid)); - Py_XDECREF(((PyObject *)p->findexes)); - Py_XDECREF(((PyObject *)p->findexes1)); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_8_cdec_sa_HieroCachingRuleFactory(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *p = (struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)o; - if (p->rules) { - e = (*v)(((PyObject*)p->rules), a); if (e) return e; - } - if (p->sampler) { - e = (*v)(((PyObject*)p->sampler), a); if (e) return e; - } - if (p->precomputed_index) { - e = (*v)(p->precomputed_index, a); if (e) return e; - } - if (p->precomputed_collocations) { - e = (*v)(p->precomputed_collocations, a); if (e) return e; - } - if (p->precompute_file) { - e = (*v)(p->precompute_file, a); if (e) return e; - } - if (p->max_rank) { - e = (*v)(p->max_rank, a); if (e) return e; - } - if (p->prev_norm_prefix) { - e = (*v)(p->prev_norm_prefix, a); if (e) return e; - } - if (p->fsa) { - e = (*v)(((PyObject*)p->fsa), a); if (e) return e; - } - if (p->fda) { - e = (*v)(((PyObject*)p->fda), a); if (e) return e; - } - if (p->eda) { - e = (*v)(((PyObject*)p->eda), a); if (e) return e; - } - if (p->alignment) { - e = (*v)(((PyObject*)p->alignment), a); if (e) return e; - } - if (p->eid2symid) { - e = (*v)(((PyObject*)p->eid2symid), a); if (e) return e; - } - if (p->fid2symid) { - e = (*v)(((PyObject*)p->fid2symid), a); if (e) return e; - } - if (p->findexes) { - e = (*v)(((PyObject*)p->findexes), a); if (e) return e; - } - if (p->findexes1) { - e = (*v)(((PyObject*)p->findexes1), a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_8_cdec_sa_HieroCachingRuleFactory(PyObject *o) { - struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *p = (struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)o; - PyObject* tmp; - tmp = ((PyObject*)p->rules); - p->rules = ((struct __pyx_obj_8_cdec_sa_TrieTable *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->sampler); - p->sampler = ((struct __pyx_obj_8_cdec_sa_Sampler *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->precomputed_index); - p->precomputed_index = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->precomputed_collocations); - p->precomputed_collocations = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->precompute_file); - p->precompute_file = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->max_rank); - p->max_rank = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->prev_norm_prefix); - p->prev_norm_prefix = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->fsa); - p->fsa = ((struct __pyx_obj_8_cdec_sa_SuffixArray *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->fda); - p->fda = ((struct __pyx_obj_8_cdec_sa_DataArray *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->eda); - p->eda = ((struct __pyx_obj_8_cdec_sa_DataArray *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->alignment); - p->alignment = ((struct __pyx_obj_8_cdec_sa_Alignment *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->eid2symid); - p->eid2symid = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->fid2symid); - p->fid2symid = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->findexes); - p->findexes = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->findexes1); - p->findexes1 = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyMethodDef __pyx_methods_8_cdec_sa_HieroCachingRuleFactory[] = { - {__Pyx_NAMESTR("configure"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_3configure, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_23HieroCachingRuleFactory_2configure)}, - {__Pyx_NAMESTR("pattern2phrase"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_5pattern2phrase, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("pattern2phrase_plus"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_7pattern2phrase_plus, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("precompute"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_9precompute, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_precomputed_collocation"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_11get_precomputed_collocation, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("advance"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_13advance, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_all_nodes_isteps_away"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_15get_all_nodes_isteps_away, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("reachable"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_17reachable, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("shortest"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_19shortest, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_next_states"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_21get_next_states, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("input"), (PyCFunction)__pyx_pw_8_cdec_sa_23HieroCachingRuleFactory_23input, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_8_cdec_sa_23HieroCachingRuleFactory_22input)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_HieroCachingRuleFactory = { - 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_HieroCachingRuleFactory = { - 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_HieroCachingRuleFactory = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_HieroCachingRuleFactory = { - #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_8_cdec_sa_HieroCachingRuleFactory = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.HieroCachingRuleFactory"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa_HieroCachingRuleFactory, /*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_HieroCachingRuleFactory, /*tp_as_number*/ - &__pyx_tp_as_sequence_HieroCachingRuleFactory, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_HieroCachingRuleFactory, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_HieroCachingRuleFactory, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - __Pyx_DOCSTR("This RuleFactory implements a caching \n method using TrieTable, which makes phrase\n generation somewhat speedier -- phrases only\n need to be extracted once (however, it is\n quite possible they need to be scored \n for each input sentence, for contextual models)"), /*tp_doc*/ - __pyx_tp_traverse_8_cdec_sa_HieroCachingRuleFactory, /*tp_traverse*/ - __pyx_tp_clear_8_cdec_sa_HieroCachingRuleFactory, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa_HieroCachingRuleFactory, /*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_8_cdec_sa_HieroCachingRuleFactory, /*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_8_cdec_sa___pyx_scope_struct__compute_stats(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *)o); - p->__pyx_v_ngram = 0; - p->__pyx_v_ngram_start = 0; - p->__pyx_v_ngram_starts = 0; - p->__pyx_v_run_start = 0; - p->__pyx_v_self = 0; - p->__pyx_v_veb = 0; - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa___pyx_scope_struct__compute_stats(PyObject *o) { - struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *p = (struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *)o; - Py_XDECREF(((PyObject *)p->__pyx_v_ngram)); - Py_XDECREF(((PyObject *)p->__pyx_v_ngram_start)); - Py_XDECREF(((PyObject *)p->__pyx_v_ngram_starts)); - Py_XDECREF(((PyObject *)p->__pyx_v_run_start)); - Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(((PyObject *)p->__pyx_v_veb)); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_8_cdec_sa___pyx_scope_struct__compute_stats(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *p = (struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *)o; - if (p->__pyx_v_ngram) { - e = (*v)(p->__pyx_v_ngram, a); if (e) return e; - } - if (p->__pyx_v_ngram_start) { - e = (*v)(((PyObject*)p->__pyx_v_ngram_start), a); if (e) return e; - } - if (p->__pyx_v_ngram_starts) { - e = (*v)(p->__pyx_v_ngram_starts, a); if (e) return e; - } - if (p->__pyx_v_run_start) { - e = (*v)(((PyObject*)p->__pyx_v_run_start), 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_veb) { - e = (*v)(((PyObject*)p->__pyx_v_veb), a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_8_cdec_sa___pyx_scope_struct__compute_stats(PyObject *o) { - struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *p = (struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats *)o; - PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_ngram); - p->__pyx_v_ngram = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_ngram_start); - p->__pyx_v_ngram_start = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_ngram_starts); - p->__pyx_v_ngram_starts = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_run_start); - p->__pyx_v_run_start = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_8_cdec_sa_LCP *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_veb); - p->__pyx_v_veb = ((struct __pyx_obj_8_cdec_sa_VEB *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyMethodDef __pyx_methods_8_cdec_sa___pyx_scope_struct__compute_stats[] = { - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct__compute_stats = { - 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__compute_stats = { - 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__compute_stats = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct__compute_stats = { - #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_8_cdec_sa___pyx_scope_struct__compute_stats = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.__pyx_scope_struct__compute_stats"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa___pyx_scope_struct__compute_stats), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa___pyx_scope_struct__compute_stats, /*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__compute_stats, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct__compute_stats, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct__compute_stats, /*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__compute_stats, /*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_8_cdec_sa___pyx_scope_struct__compute_stats, /*tp_traverse*/ - __pyx_tp_clear_8_cdec_sa___pyx_scope_struct__compute_stats, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa___pyx_scope_struct__compute_stats, /*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_8_cdec_sa___pyx_scope_struct__compute_stats, /*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_8_cdec_sa___pyx_scope_struct_1_input(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *)o); - p->__pyx_v_alignment = 0; - p->__pyx_v_als = 0; - p->__pyx_v_alslist = 0; - p->__pyx_v_chunklen = 0; - p->__pyx_v_count = 0; - p->__pyx_v_currcount = 0; - p->__pyx_v_e = 0; - p->__pyx_v_elist = 0; - p->__pyx_v_extract = 0; - p->__pyx_v_extract_start = 0; - p->__pyx_v_extract_stop = 0; - p->__pyx_v_extracts = 0; - p->__pyx_v_f = 0; - p->__pyx_v_f_margin = 0; - p->__pyx_v_fals = 0; - p->__pyx_v_fcount = 0; - p->__pyx_v_fphrases = 0; - p->__pyx_v_frontier = 0; - p->__pyx_v_frontier_nodes = 0; - p->__pyx_v_fwords = 0; - p->__pyx_v_hiero_phrase = 0; - p->__pyx_v_is_shadow_path = 0; - p->__pyx_v_key = 0; - p->__pyx_v_model = 0; - p->__pyx_v_models = 0; - p->__pyx_v_new_frontier = 0; - p->__pyx_v_new_node = 0; - p->__pyx_v_next_states = 0; - p->__pyx_v_node = 0; - p->__pyx_v_nodes_isteps_away_buffer = 0; - p->__pyx_v_pathlen = 0; - p->__pyx_v_phrase = 0; - p->__pyx_v_phrase_location = 0; - p->__pyx_v_prefix = 0; - p->__pyx_v_reachable_buffer = 0; - p->__pyx_v_sa_range = 0; - p->__pyx_v_sample = 0; - p->__pyx_v_scores = 0; - p->__pyx_v_self = 0; - p->__pyx_v_spanlen = 0; - p->__pyx_v_stop_time = 0; - p->__pyx_v_str_phrase = 0; - p->__pyx_v_suffix_link = 0; - p->__pyx_v_suffix_link_xcat_index = 0; - p->__pyx_v_word_id = 0; - p->__pyx_v_xcat_index = 0; - p->__pyx_v_xnode = 0; - p->__pyx_v_xroot = 0; - p->__pyx_t_2 = 0; - p->__pyx_t_3 = 0; - p->__pyx_t_4 = 0; - return o; -} - -static void __pyx_tp_dealloc_8_cdec_sa___pyx_scope_struct_1_input(PyObject *o) { - struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *p = (struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *)o; - Py_XDECREF(p->__pyx_v_alignment); - Py_XDECREF(p->__pyx_v_als); - Py_XDECREF(p->__pyx_v_alslist); - Py_XDECREF(((PyObject *)p->__pyx_v_chunklen)); - Py_XDECREF(p->__pyx_v_count); - Py_XDECREF(p->__pyx_v_currcount); - Py_XDECREF(p->__pyx_v_e); - Py_XDECREF(p->__pyx_v_elist); - Py_XDECREF(p->__pyx_v_extract); - Py_XDECREF(p->__pyx_v_extract_start); - Py_XDECREF(p->__pyx_v_extract_stop); - Py_XDECREF(((PyObject *)p->__pyx_v_extracts)); - Py_XDECREF(p->__pyx_v_f); - Py_XDECREF(p->__pyx_v_f_margin); - Py_XDECREF(((PyObject *)p->__pyx_v_fals)); - Py_XDECREF(((PyObject *)p->__pyx_v_fcount)); - Py_XDECREF(((PyObject *)p->__pyx_v_fphrases)); - Py_XDECREF(((PyObject *)p->__pyx_v_frontier)); - Py_XDECREF(p->__pyx_v_frontier_nodes); - Py_XDECREF(p->__pyx_v_fwords); - Py_XDECREF(((PyObject *)p->__pyx_v_hiero_phrase)); - Py_XDECREF(p->__pyx_v_is_shadow_path); - Py_XDECREF(((PyObject *)p->__pyx_v_key)); - Py_XDECREF(p->__pyx_v_model); - Py_XDECREF(p->__pyx_v_models); - Py_XDECREF(((PyObject *)p->__pyx_v_new_frontier)); - Py_XDECREF(p->__pyx_v_new_node); - Py_XDECREF(((PyObject *)p->__pyx_v_next_states)); - Py_XDECREF(p->__pyx_v_node); - Py_XDECREF(((PyObject *)p->__pyx_v_nodes_isteps_away_buffer)); - Py_XDECREF(p->__pyx_v_pathlen); - Py_XDECREF(p->__pyx_v_phrase); - Py_XDECREF(((PyObject *)p->__pyx_v_phrase_location)); - Py_XDECREF(p->__pyx_v_prefix); - Py_XDECREF(((PyObject *)p->__pyx_v_reachable_buffer)); - Py_XDECREF(p->__pyx_v_sa_range); - Py_XDECREF(((PyObject *)p->__pyx_v_sample)); - Py_XDECREF(((PyObject *)p->__pyx_v_scores)); - Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(p->__pyx_v_spanlen); - Py_XDECREF(p->__pyx_v_stop_time); - Py_XDECREF(p->__pyx_v_str_phrase); - Py_XDECREF(p->__pyx_v_suffix_link); - Py_XDECREF(p->__pyx_v_suffix_link_xcat_index); - Py_XDECREF(p->__pyx_v_word_id); - Py_XDECREF(p->__pyx_v_xcat_index); - Py_XDECREF(p->__pyx_v_xnode); - Py_XDECREF(p->__pyx_v_xroot); - Py_XDECREF(p->__pyx_t_2); - Py_XDECREF(p->__pyx_t_3); - Py_XDECREF(p->__pyx_t_4); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_8_cdec_sa___pyx_scope_struct_1_input(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *p = (struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *)o; - if (p->__pyx_v_alignment) { - e = (*v)(p->__pyx_v_alignment, a); if (e) return e; - } - if (p->__pyx_v_als) { - e = (*v)(p->__pyx_v_als, a); if (e) return e; - } - if (p->__pyx_v_alslist) { - e = (*v)(p->__pyx_v_alslist, a); if (e) return e; - } - if (p->__pyx_v_chunklen) { - e = (*v)(((PyObject*)p->__pyx_v_chunklen), a); if (e) return e; - } - if (p->__pyx_v_count) { - e = (*v)(p->__pyx_v_count, a); if (e) return e; - } - if (p->__pyx_v_currcount) { - e = (*v)(p->__pyx_v_currcount, a); if (e) return e; - } - if (p->__pyx_v_e) { - e = (*v)(p->__pyx_v_e, a); if (e) return e; - } - if (p->__pyx_v_elist) { - e = (*v)(p->__pyx_v_elist, a); if (e) return e; - } - if (p->__pyx_v_extract) { - e = (*v)(p->__pyx_v_extract, a); if (e) return e; - } - if (p->__pyx_v_extract_start) { - e = (*v)(p->__pyx_v_extract_start, a); if (e) return e; - } - if (p->__pyx_v_extract_stop) { - e = (*v)(p->__pyx_v_extract_stop, a); if (e) return e; - } - if (p->__pyx_v_extracts) { - e = (*v)(p->__pyx_v_extracts, a); if (e) return e; - } - if (p->__pyx_v_f) { - e = (*v)(p->__pyx_v_f, a); if (e) return e; - } - if (p->__pyx_v_f_margin) { - e = (*v)(p->__pyx_v_f_margin, a); if (e) return e; - } - if (p->__pyx_v_fals) { - e = (*v)(p->__pyx_v_fals, a); if (e) return e; - } - if (p->__pyx_v_fcount) { - e = (*v)(p->__pyx_v_fcount, a); if (e) return e; - } - if (p->__pyx_v_fphrases) { - e = (*v)(p->__pyx_v_fphrases, a); if (e) return e; - } - if (p->__pyx_v_frontier) { - e = (*v)(p->__pyx_v_frontier, a); if (e) return e; - } - if (p->__pyx_v_frontier_nodes) { - e = (*v)(p->__pyx_v_frontier_nodes, a); if (e) return e; - } - if (p->__pyx_v_fwords) { - e = (*v)(p->__pyx_v_fwords, a); if (e) return e; - } - if (p->__pyx_v_hiero_phrase) { - e = (*v)(((PyObject*)p->__pyx_v_hiero_phrase), a); if (e) return e; - } - if (p->__pyx_v_is_shadow_path) { - e = (*v)(p->__pyx_v_is_shadow_path, a); if (e) return e; - } - if (p->__pyx_v_key) { - e = (*v)(p->__pyx_v_key, a); if (e) return e; - } - if (p->__pyx_v_model) { - e = (*v)(p->__pyx_v_model, a); if (e) return e; - } - if (p->__pyx_v_models) { - e = (*v)(p->__pyx_v_models, a); if (e) return e; - } - if (p->__pyx_v_new_frontier) { - e = (*v)(p->__pyx_v_new_frontier, a); if (e) return e; - } - if (p->__pyx_v_new_node) { - e = (*v)(p->__pyx_v_new_node, a); if (e) return e; - } - if (p->__pyx_v_next_states) { - e = (*v)(p->__pyx_v_next_states, a); if (e) return e; - } - if (p->__pyx_v_node) { - e = (*v)(p->__pyx_v_node, a); if (e) return e; - } - if (p->__pyx_v_nodes_isteps_away_buffer) { - e = (*v)(p->__pyx_v_nodes_isteps_away_buffer, a); if (e) return e; - } - if (p->__pyx_v_pathlen) { - e = (*v)(p->__pyx_v_pathlen, a); if (e) return e; - } - if (p->__pyx_v_phrase) { - e = (*v)(p->__pyx_v_phrase, a); if (e) return e; - } - if (p->__pyx_v_phrase_location) { - e = (*v)(((PyObject*)p->__pyx_v_phrase_location), a); if (e) return e; - } - if (p->__pyx_v_prefix) { - e = (*v)(p->__pyx_v_prefix, a); if (e) return e; - } - if (p->__pyx_v_reachable_buffer) { - e = (*v)(p->__pyx_v_reachable_buffer, a); if (e) return e; - } - if (p->__pyx_v_sa_range) { - e = (*v)(p->__pyx_v_sa_range, a); if (e) return e; - } - if (p->__pyx_v_sample) { - e = (*v)(((PyObject*)p->__pyx_v_sample), a); if (e) return e; - } - if (p->__pyx_v_scores) { - e = (*v)(p->__pyx_v_scores, 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_spanlen) { - e = (*v)(p->__pyx_v_spanlen, a); if (e) return e; - } - if (p->__pyx_v_stop_time) { - e = (*v)(p->__pyx_v_stop_time, a); if (e) return e; - } - if (p->__pyx_v_str_phrase) { - e = (*v)(p->__pyx_v_str_phrase, a); if (e) return e; - } - if (p->__pyx_v_suffix_link) { - e = (*v)(p->__pyx_v_suffix_link, a); if (e) return e; - } - if (p->__pyx_v_suffix_link_xcat_index) { - e = (*v)(p->__pyx_v_suffix_link_xcat_index, a); if (e) return e; - } - if (p->__pyx_v_word_id) { - e = (*v)(p->__pyx_v_word_id, a); if (e) return e; - } - if (p->__pyx_v_xcat_index) { - e = (*v)(p->__pyx_v_xcat_index, a); if (e) return e; - } - if (p->__pyx_v_xnode) { - e = (*v)(p->__pyx_v_xnode, a); if (e) return e; - } - if (p->__pyx_v_xroot) { - e = (*v)(p->__pyx_v_xroot, a); if (e) return e; - } - if (p->__pyx_t_2) { - e = (*v)(p->__pyx_t_2, a); if (e) return e; - } - if (p->__pyx_t_3) { - e = (*v)(p->__pyx_t_3, a); if (e) return e; - } - if (p->__pyx_t_4) { - e = (*v)(p->__pyx_t_4, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_8_cdec_sa___pyx_scope_struct_1_input(PyObject *o) { - struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *p = (struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input *)o; - PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_alignment); - p->__pyx_v_alignment = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_als); - p->__pyx_v_als = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_alslist); - p->__pyx_v_alslist = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_chunklen); - p->__pyx_v_chunklen = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_count); - p->__pyx_v_count = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_currcount); - p->__pyx_v_currcount = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_e); - p->__pyx_v_e = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_elist); - p->__pyx_v_elist = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_extract); - p->__pyx_v_extract = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_extract_start); - p->__pyx_v_extract_start = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_extract_stop); - p->__pyx_v_extract_stop = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_extracts); - p->__pyx_v_extracts = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_f); - p->__pyx_v_f = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_f_margin); - p->__pyx_v_f_margin = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_fals); - p->__pyx_v_fals = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_fcount); - p->__pyx_v_fcount = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_fphrases); - p->__pyx_v_fphrases = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_frontier); - p->__pyx_v_frontier = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_frontier_nodes); - p->__pyx_v_frontier_nodes = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_fwords); - p->__pyx_v_fwords = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_hiero_phrase); - p->__pyx_v_hiero_phrase = ((struct __pyx_obj_8_cdec_sa_Phrase *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_is_shadow_path); - p->__pyx_v_is_shadow_path = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_key); - p->__pyx_v_key = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_model); - p->__pyx_v_model = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_models); - p->__pyx_v_models = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_new_frontier); - p->__pyx_v_new_frontier = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_new_node); - p->__pyx_v_new_node = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_next_states); - p->__pyx_v_next_states = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_node); - p->__pyx_v_node = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_nodes_isteps_away_buffer); - p->__pyx_v_nodes_isteps_away_buffer = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_pathlen); - p->__pyx_v_pathlen = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_phrase); - p->__pyx_v_phrase = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_phrase_location); - p->__pyx_v_phrase_location = ((struct __pyx_obj_8_cdec_sa_PhraseLocation *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_prefix); - p->__pyx_v_prefix = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_reachable_buffer); - p->__pyx_v_reachable_buffer = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_sa_range); - p->__pyx_v_sa_range = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_sample); - p->__pyx_v_sample = ((struct __pyx_obj_8_cdec_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_scores); - p->__pyx_v_scores = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_spanlen); - p->__pyx_v_spanlen = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_stop_time); - p->__pyx_v_stop_time = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_str_phrase); - p->__pyx_v_str_phrase = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_suffix_link); - p->__pyx_v_suffix_link = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_suffix_link_xcat_index); - p->__pyx_v_suffix_link_xcat_index = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_word_id); - p->__pyx_v_word_id = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_xcat_index); - p->__pyx_v_xcat_index = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_xnode); - p->__pyx_v_xnode = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_xroot); - p->__pyx_v_xroot = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_t_2); - p->__pyx_t_2 = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_t_3); - p->__pyx_t_3 = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_t_4); - p->__pyx_t_4 = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyMethodDef __pyx_methods_8_cdec_sa___pyx_scope_struct_1_input[] = { - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1_input = { - 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_input = { - 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_input = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1_input = { - #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_8_cdec_sa___pyx_scope_struct_1_input = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec_sa.__pyx_scope_struct_1_input"), /*tp_name*/ - sizeof(struct __pyx_obj_8_cdec_sa___pyx_scope_struct_1_input), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_8_cdec_sa___pyx_scope_struct_1_input, /*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_input, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_1_input, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_1_input, /*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_input, /*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_8_cdec_sa___pyx_scope_struct_1_input, /*tp_traverse*/ - __pyx_tp_clear_8_cdec_sa___pyx_scope_struct_1_input, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_8_cdec_sa___pyx_scope_struct_1_input, /*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_8_cdec_sa___pyx_scope_struct_1_input, /*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} -}; - -#if PY_MAJOR_VERSION >= 3 -static struct PyModuleDef __pyx_moduledef = { - PyModuleDef_HEAD_INIT, - __Pyx_NAMESTR("_cdec_sa"), - 0, /* m_doc */ - -1, /* m_size */ - __pyx_methods /* m_methods */, - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL /* m_free */ -}; -#endif - -static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0}, - {&__pyx_n_s_101, __pyx_k_101, sizeof(__pyx_k_101), 0, 0, 1, 1}, - {&__pyx_n_s_102, __pyx_k_102, sizeof(__pyx_k_102), 0, 0, 1, 1}, - {&__pyx_kp_s_104, __pyx_k_104, sizeof(__pyx_k_104), 0, 0, 1, 0}, - {&__pyx_kp_s_106, __pyx_k_106, sizeof(__pyx_k_106), 0, 0, 1, 0}, - {&__pyx_kp_s_107, __pyx_k_107, sizeof(__pyx_k_107), 0, 0, 1, 0}, - {&__pyx_kp_s_108, __pyx_k_108, sizeof(__pyx_k_108), 0, 0, 1, 0}, - {&__pyx_kp_s_109, __pyx_k_109, sizeof(__pyx_k_109), 0, 0, 1, 0}, - {&__pyx_kp_s_110, __pyx_k_110, sizeof(__pyx_k_110), 0, 0, 1, 0}, - {&__pyx_kp_s_111, __pyx_k_111, sizeof(__pyx_k_111), 0, 0, 1, 0}, - {&__pyx_kp_s_112, __pyx_k_112, sizeof(__pyx_k_112), 0, 0, 1, 0}, - {&__pyx_kp_s_113, __pyx_k_113, sizeof(__pyx_k_113), 0, 0, 1, 0}, - {&__pyx_kp_s_114, __pyx_k_114, sizeof(__pyx_k_114), 0, 0, 1, 0}, - {&__pyx_kp_s_115, __pyx_k_115, sizeof(__pyx_k_115), 0, 0, 1, 0}, - {&__pyx_kp_s_116, __pyx_k_116, sizeof(__pyx_k_116), 0, 0, 1, 0}, - {&__pyx_n_s_117, __pyx_k_117, sizeof(__pyx_k_117), 0, 0, 1, 1}, - {&__pyx_kp_s_118, __pyx_k_118, sizeof(__pyx_k_118), 0, 0, 1, 0}, - {&__pyx_kp_s_119, __pyx_k_119, sizeof(__pyx_k_119), 0, 0, 1, 0}, - {&__pyx_n_s_121, __pyx_k_121, sizeof(__pyx_k_121), 0, 0, 1, 1}, - {&__pyx_kp_s_122, __pyx_k_122, sizeof(__pyx_k_122), 0, 0, 1, 0}, - {&__pyx_kp_s_123, __pyx_k_123, sizeof(__pyx_k_123), 0, 0, 1, 0}, - {&__pyx_kp_s_124, __pyx_k_124, sizeof(__pyx_k_124), 0, 0, 1, 0}, - {&__pyx_kp_s_125, __pyx_k_125, sizeof(__pyx_k_125), 0, 0, 1, 0}, - {&__pyx_kp_s_126, __pyx_k_126, sizeof(__pyx_k_126), 0, 0, 1, 0}, - {&__pyx_kp_s_127, __pyx_k_127, sizeof(__pyx_k_127), 0, 0, 1, 0}, - {&__pyx_kp_s_128, __pyx_k_128, sizeof(__pyx_k_128), 0, 0, 1, 0}, - {&__pyx_kp_s_129, __pyx_k_129, sizeof(__pyx_k_129), 0, 0, 1, 0}, - {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0}, - {&__pyx_kp_s_130, __pyx_k_130, sizeof(__pyx_k_130), 0, 0, 1, 0}, - {&__pyx_kp_s_131, __pyx_k_131, sizeof(__pyx_k_131), 0, 0, 1, 0}, - {&__pyx_kp_s_134, __pyx_k_134, sizeof(__pyx_k_134), 0, 0, 1, 0}, - {&__pyx_kp_s_135, __pyx_k_135, sizeof(__pyx_k_135), 0, 0, 1, 0}, - {&__pyx_kp_s_139, __pyx_k_139, sizeof(__pyx_k_139), 0, 0, 1, 0}, - {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0}, - {&__pyx_kp_s_144, __pyx_k_144, sizeof(__pyx_k_144), 0, 0, 1, 0}, - {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0}, - {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0}, - {&__pyx_kp_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 0}, - {&__pyx_n_s_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 1, 1}, - {&__pyx_kp_s_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 0, 1, 0}, - {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0}, - {&__pyx_kp_s_32, __pyx_k_32, sizeof(__pyx_k_32), 0, 0, 1, 0}, - {&__pyx_kp_s_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 1, 0}, - {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0}, - {&__pyx_kp_s_42, __pyx_k_42, sizeof(__pyx_k_42), 0, 0, 1, 0}, - {&__pyx_kp_s_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 1, 0}, - {&__pyx_kp_s_45, __pyx_k_45, sizeof(__pyx_k_45), 0, 0, 1, 0}, - {&__pyx_kp_s_47, __pyx_k_47, sizeof(__pyx_k_47), 0, 0, 1, 0}, - {&__pyx_kp_s_49, __pyx_k_49, sizeof(__pyx_k_49), 0, 0, 1, 0}, - {&__pyx_kp_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 0}, - {&__pyx_kp_s_53, __pyx_k_53, sizeof(__pyx_k_53), 0, 0, 1, 0}, - {&__pyx_kp_s_55, __pyx_k_55, sizeof(__pyx_k_55), 0, 0, 1, 0}, - {&__pyx_kp_s_56, __pyx_k_56, sizeof(__pyx_k_56), 0, 0, 1, 0}, - {&__pyx_kp_s_57, __pyx_k_57, sizeof(__pyx_k_57), 0, 0, 1, 0}, - {&__pyx_kp_s_59, __pyx_k_59, sizeof(__pyx_k_59), 0, 0, 1, 0}, - {&__pyx_kp_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 0}, - {&__pyx_kp_s_61, __pyx_k_61, sizeof(__pyx_k_61), 0, 0, 1, 0}, - {&__pyx_kp_s_62, __pyx_k_62, sizeof(__pyx_k_62), 0, 0, 1, 0}, - {&__pyx_kp_s_63, __pyx_k_63, sizeof(__pyx_k_63), 0, 0, 1, 0}, - {&__pyx_kp_s_64, __pyx_k_64, sizeof(__pyx_k_64), 0, 0, 1, 0}, - {&__pyx_kp_s_65, __pyx_k_65, sizeof(__pyx_k_65), 0, 0, 1, 0}, - {&__pyx_kp_s_66, __pyx_k_66, sizeof(__pyx_k_66), 0, 0, 1, 0}, - {&__pyx_kp_s_67, __pyx_k_67, sizeof(__pyx_k_67), 0, 0, 1, 0}, - {&__pyx_n_s_68, __pyx_k_68, sizeof(__pyx_k_68), 0, 0, 1, 1}, - {&__pyx_n_s_69, __pyx_k_69, sizeof(__pyx_k_69), 0, 0, 1, 1}, - {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0}, - {&__pyx_kp_s_70, __pyx_k_70, sizeof(__pyx_k_70), 0, 0, 1, 0}, - {&__pyx_kp_s_72, __pyx_k_72, sizeof(__pyx_k_72), 0, 0, 1, 0}, - {&__pyx_kp_s_74, __pyx_k_74, sizeof(__pyx_k_74), 0, 0, 1, 0}, - {&__pyx_kp_s_76, __pyx_k_76, sizeof(__pyx_k_76), 0, 0, 1, 0}, - {&__pyx_kp_s_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 1, 0}, - {&__pyx_kp_s_81, __pyx_k_81, sizeof(__pyx_k_81), 0, 0, 1, 0}, - {&__pyx_kp_s_82, __pyx_k_82, sizeof(__pyx_k_82), 0, 0, 1, 0}, - {&__pyx_kp_s_83, __pyx_k_83, sizeof(__pyx_k_83), 0, 0, 1, 0}, - {&__pyx_kp_s_84, __pyx_k_84, sizeof(__pyx_k_84), 0, 0, 1, 0}, - {&__pyx_kp_s_85, __pyx_k_85, sizeof(__pyx_k_85), 0, 0, 1, 0}, - {&__pyx_kp_s_86, __pyx_k_86, sizeof(__pyx_k_86), 0, 0, 1, 0}, - {&__pyx_kp_s_87, __pyx_k_87, sizeof(__pyx_k_87), 0, 0, 1, 0}, - {&__pyx_kp_s_88, __pyx_k_88, sizeof(__pyx_k_88), 0, 0, 1, 0}, - {&__pyx_kp_s_89, __pyx_k_89, sizeof(__pyx_k_89), 0, 0, 1, 0}, - {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0}, - {&__pyx_kp_s_90, __pyx_k_90, sizeof(__pyx_k_90), 0, 0, 1, 0}, - {&__pyx_kp_s_92, __pyx_k_92, sizeof(__pyx_k_92), 0, 0, 1, 0}, - {&__pyx_kp_s_93, __pyx_k_93, sizeof(__pyx_k_93), 0, 0, 1, 0}, - {&__pyx_kp_s_98, __pyx_k_98, sizeof(__pyx_k_98), 0, 0, 1, 0}, - {&__pyx_kp_s_99, __pyx_k_99, sizeof(__pyx_k_99), 0, 0, 1, 0}, - {&__pyx_kp_s__0, __pyx_k__0, sizeof(__pyx_k__0), 0, 0, 1, 0}, - {&__pyx_kp_s__1, __pyx_k__1, sizeof(__pyx_k__1), 0, 0, 1, 0}, - {&__pyx_n_s__END_OF_FILE, __pyx_k__END_OF_FILE, sizeof(__pyx_k__END_OF_FILE), 0, 0, 1, 1}, - {&__pyx_n_s__END_OF_LINE, __pyx_k__END_OF_LINE, sizeof(__pyx_k__END_OF_LINE), 0, 0, 1, 1}, - {&__pyx_n_s__Exception, __pyx_k__Exception, sizeof(__pyx_k__Exception), 0, 0, 1, 1}, - {&__pyx_n_s__GzipFile, __pyx_k__GzipFile, sizeof(__pyx_k__GzipFile), 0, 0, 1, 1}, - {&__pyx_n_s__IndexError, __pyx_k__IndexError, sizeof(__pyx_k__IndexError), 0, 0, 1, 1}, - {&__pyx_n_s__NULL, __pyx_k__NULL, sizeof(__pyx_k__NULL), 0, 0, 1, 1}, - {&__pyx_n_s__RUSAGE_SELF, __pyx_k__RUSAGE_SELF, sizeof(__pyx_k__RUSAGE_SELF), 0, 0, 1, 1}, - {&__pyx_n_s__StopIteration, __pyx_k__StopIteration, sizeof(__pyx_k__StopIteration), 0, 0, 1, 1}, - {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1}, - {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, - {&__pyx_n_s____enter__, __pyx_k____enter__, sizeof(__pyx_k____enter__), 0, 0, 1, 1}, - {&__pyx_n_s____exit__, __pyx_k____exit__, sizeof(__pyx_k____exit__), 0, 0, 1, 1}, - {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, - {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, - {&__pyx_n_s___cdec_sa, __pyx_k___cdec_sa, sizeof(__pyx_k___cdec_sa), 0, 0, 1, 1}, - {&__pyx_n_s___columns, __pyx_k___columns, sizeof(__pyx_k___columns), 0, 0, 1, 1}, - {&__pyx_n_s___doquicksort, __pyx_k___doquicksort, sizeof(__pyx_k___doquicksort), 0, 0, 1, 1}, - {&__pyx_n_s__advance, __pyx_k__advance, sizeof(__pyx_k__advance), 0, 0, 1, 1}, - {&__pyx_n_s__alignment, __pyx_k__alignment, sizeof(__pyx_k__alignment), 0, 0, 1, 1}, - {&__pyx_n_s__alphabet_size, __pyx_k__alphabet_size, sizeof(__pyx_k__alphabet_size), 0, 0, 1, 1}, - {&__pyx_n_s__arity, __pyx_k__arity, sizeof(__pyx_k__arity), 0, 0, 1, 1}, - {&__pyx_n_s__arr, __pyx_k__arr, sizeof(__pyx_k__arr), 0, 0, 1, 1}, - {&__pyx_n_s__arr_high, __pyx_k__arr_high, sizeof(__pyx_k__arr_high), 0, 0, 1, 1}, - {&__pyx_n_s__arr_low, __pyx_k__arr_low, sizeof(__pyx_k__arr_low), 0, 0, 1, 1}, - {&__pyx_n_s__by_slack_factor, __pyx_k__by_slack_factor, sizeof(__pyx_k__by_slack_factor), 0, 0, 1, 1}, - {&__pyx_n_s__category, __pyx_k__category, sizeof(__pyx_k__category), 0, 0, 1, 1}, - {&__pyx_n_s__children, __pyx_k__children, sizeof(__pyx_k__children), 0, 0, 1, 1}, - {&__pyx_n_s__cmp, __pyx_k__cmp, sizeof(__pyx_k__cmp), 0, 0, 1, 1}, - {&__pyx_n_s__col, __pyx_k__col, sizeof(__pyx_k__col), 0, 0, 1, 1}, - {&__pyx_n_s__collect, __pyx_k__collect, sizeof(__pyx_k__collect), 0, 0, 1, 1}, - {&__pyx_n_s__curr_idx, __pyx_k__curr_idx, sizeof(__pyx_k__curr_idx), 0, 0, 1, 1}, - {&__pyx_n_s__debug, __pyx_k__debug, sizeof(__pyx_k__debug), 0, 0, 1, 1}, - {&__pyx_n_s__dist, __pyx_k__dist, sizeof(__pyx_k__dist), 0, 0, 1, 1}, - {&__pyx_n_s__e, __pyx_k__e, sizeof(__pyx_k__e), 0, 0, 1, 1}, - {&__pyx_n_s__earray, __pyx_k__earray, sizeof(__pyx_k__earray), 0, 0, 1, 1}, - {&__pyx_n_s__edarray, __pyx_k__edarray, sizeof(__pyx_k__edarray), 0, 0, 1, 1}, - {&__pyx_n_s__end, __pyx_k__end, sizeof(__pyx_k__end), 0, 0, 1, 1}, - {&__pyx_n_s__enumerate, __pyx_k__enumerate, sizeof(__pyx_k__enumerate), 0, 0, 1, 1}, - {&__pyx_n_s__eword, __pyx_k__eword, sizeof(__pyx_k__eword), 0, 0, 1, 1}, - {&__pyx_n_s__extend, __pyx_k__extend, sizeof(__pyx_k__extend), 0, 0, 1, 1}, - {&__pyx_n_s__extended, __pyx_k__extended, sizeof(__pyx_k__extended), 0, 0, 1, 1}, - {&__pyx_n_s__f, __pyx_k__f, sizeof(__pyx_k__f), 0, 0, 1, 1}, - {&__pyx_n_s__filename, __pyx_k__filename, sizeof(__pyx_k__filename), 0, 0, 1, 1}, - {&__pyx_n_s__from_binary, __pyx_k__from_binary, sizeof(__pyx_k__from_binary), 0, 0, 1, 1}, - {&__pyx_n_s__from_data, __pyx_k__from_data, sizeof(__pyx_k__from_data), 0, 0, 1, 1}, - {&__pyx_n_s__from_stats, __pyx_k__from_stats, sizeof(__pyx_k__from_stats), 0, 0, 1, 1}, - {&__pyx_n_s__from_text, __pyx_k__from_text, sizeof(__pyx_k__from_text), 0, 0, 1, 1}, - {&__pyx_n_s__frontier, __pyx_k__frontier, sizeof(__pyx_k__frontier), 0, 0, 1, 1}, - {&__pyx_n_s__fsarray, __pyx_k__fsarray, sizeof(__pyx_k__fsarray), 0, 0, 1, 1}, - {&__pyx_n_s__fword, __pyx_k__fword, sizeof(__pyx_k__fword), 0, 0, 1, 1}, - {&__pyx_n_s__fwords, __pyx_k__fwords, sizeof(__pyx_k__fwords), 0, 0, 1, 1}, - {&__pyx_n_s__gc, __pyx_k__gc, sizeof(__pyx_k__gc), 0, 0, 1, 1}, - {&__pyx_n_s__getLogger, __pyx_k__getLogger, sizeof(__pyx_k__getLogger), 0, 0, 1, 1}, - {&__pyx_n_s__getSent, __pyx_k__getSent, sizeof(__pyx_k__getSent), 0, 0, 1, 1}, - {&__pyx_n_s__getSentId, __pyx_k__getSentId, sizeof(__pyx_k__getSentId), 0, 0, 1, 1}, - {&__pyx_n_s__getSentPos, __pyx_k__getSentPos, sizeof(__pyx_k__getSentPos), 0, 0, 1, 1}, - {&__pyx_n_s__get_e_id, __pyx_k__get_e_id, sizeof(__pyx_k__get_e_id), 0, 0, 1, 1}, - {&__pyx_n_s__get_f_id, __pyx_k__get_f_id, sizeof(__pyx_k__get_f_id), 0, 0, 1, 1}, - {&__pyx_n_s__get_id, __pyx_k__get_id, sizeof(__pyx_k__get_id), 0, 0, 1, 1}, - {&__pyx_n_s__get_next_states, __pyx_k__get_next_states, sizeof(__pyx_k__get_next_states), 0, 0, 1, 1}, - {&__pyx_n_s__get_word, __pyx_k__get_word, sizeof(__pyx_k__get_word), 0, 0, 1, 1}, - {&__pyx_n_s__getchunk, __pyx_k__getchunk, sizeof(__pyx_k__getchunk), 0, 0, 1, 1}, - {&__pyx_n_s__getrusage, __pyx_k__getrusage, sizeof(__pyx_k__getrusage), 0, 0, 1, 1}, - {&__pyx_n_s__gzip, __pyx_k__gzip, sizeof(__pyx_k__gzip), 0, 0, 1, 1}, - {&__pyx_n_s__gzip_or_text, __pyx_k__gzip_or_text, sizeof(__pyx_k__gzip_or_text), 0, 0, 1, 1}, - {&__pyx_n_s__h, __pyx_k__h, sizeof(__pyx_k__h), 0, 0, 1, 1}, - {&__pyx_n_s__high, __pyx_k__high, sizeof(__pyx_k__high), 0, 0, 1, 1}, - {&__pyx_n_s__i, __pyx_k__i, sizeof(__pyx_k__i), 0, 0, 1, 1}, - {&__pyx_n_s__ifrom, __pyx_k__ifrom, sizeof(__pyx_k__ifrom), 0, 0, 1, 1}, - {&__pyx_n_s__increment, __pyx_k__increment, sizeof(__pyx_k__increment), 0, 0, 1, 1}, - {&__pyx_n_s__index, __pyx_k__index, sizeof(__pyx_k__index), 0, 0, 1, 1}, - {&__pyx_n_s__info, __pyx_k__info, sizeof(__pyx_k__info), 0, 0, 1, 1}, - {&__pyx_n_s__initial_len, __pyx_k__initial_len, sizeof(__pyx_k__initial_len), 0, 0, 1, 1}, - {&__pyx_n_s__insert, __pyx_k__insert, sizeof(__pyx_k__insert), 0, 0, 1, 1}, - {&__pyx_n_s__isa, __pyx_k__isa, sizeof(__pyx_k__isa), 0, 0, 1, 1}, - {&__pyx_n_s__iteritems, __pyx_k__iteritems, sizeof(__pyx_k__iteritems), 0, 0, 1, 1}, - {&__pyx_n_s__ito, __pyx_k__ito, sizeof(__pyx_k__ito), 0, 0, 1, 1}, - {&__pyx_n_s__j, __pyx_k__j, sizeof(__pyx_k__j), 0, 0, 1, 1}, - {&__pyx_n_s__join, __pyx_k__join, sizeof(__pyx_k__join), 0, 0, 1, 1}, - {&__pyx_n_s__lhs, __pyx_k__lhs, sizeof(__pyx_k__lhs), 0, 0, 1, 1}, - {&__pyx_n_s__logger, __pyx_k__logger, sizeof(__pyx_k__logger), 0, 0, 1, 1}, - {&__pyx_n_s__logging, __pyx_k__logging, sizeof(__pyx_k__logging), 0, 0, 1, 1}, - {&__pyx_n_s__lookup, __pyx_k__lookup, sizeof(__pyx_k__lookup), 0, 0, 1, 1}, - {&__pyx_n_s__low, __pyx_k__low, sizeof(__pyx_k__low), 0, 0, 1, 1}, - {&__pyx_n_s__map, __pyx_k__map, sizeof(__pyx_k__map), 0, 0, 1, 1}, - {&__pyx_n_s__max_chunks, __pyx_k__max_chunks, sizeof(__pyx_k__max_chunks), 0, 0, 1, 1}, - {&__pyx_n_s__max_initial_size, __pyx_k__max_initial_size, sizeof(__pyx_k__max_initial_size), 0, 0, 1, 1}, - {&__pyx_n_s__max_length, __pyx_k__max_length, sizeof(__pyx_k__max_length), 0, 0, 1, 1}, - {&__pyx_n_s__max_nonterminals, __pyx_k__max_nonterminals, sizeof(__pyx_k__max_nonterminals), 0, 0, 1, 1}, - {&__pyx_n_s__max_target_chunks, __pyx_k__max_target_chunks, sizeof(__pyx_k__max_target_chunks), 0, 0, 1, 1}, - {&__pyx_n_s__max_target_length, __pyx_k__max_target_length, sizeof(__pyx_k__max_target_length), 0, 0, 1, 1}, - {&__pyx_n_s__merge, __pyx_k__merge, sizeof(__pyx_k__merge), 0, 0, 1, 1}, - {&__pyx_n_s__min_dist, __pyx_k__min_dist, sizeof(__pyx_k__min_dist), 0, 0, 1, 1}, - {&__pyx_n_s__min_gap_size, __pyx_k__min_gap_size, sizeof(__pyx_k__min_gap_size), 0, 0, 1, 1}, - {&__pyx_n_s__models, __pyx_k__models, sizeof(__pyx_k__models), 0, 0, 1, 1}, - {&__pyx_n_s__next_states, __pyx_k__next_states, sizeof(__pyx_k__next_states), 0, 0, 1, 1}, - {&__pyx_n_s__num_subpatterns, __pyx_k__num_subpatterns, sizeof(__pyx_k__num_subpatterns), 0, 0, 1, 1}, - {&__pyx_n_s__offset, __pyx_k__offset, sizeof(__pyx_k__offset), 0, 0, 1, 1}, - {&__pyx_n_s__open, __pyx_k__open, sizeof(__pyx_k__open), 0, 0, 1, 1}, - {&__pyx_n_s__pad, __pyx_k__pad, sizeof(__pyx_k__pad), 0, 0, 1, 1}, - {&__pyx_n_s__partition, __pyx_k__partition, sizeof(__pyx_k__partition), 0, 0, 1, 1}, - {&__pyx_n_s__pathlen, __pyx_k__pathlen, sizeof(__pyx_k__pathlen), 0, 0, 1, 1}, - {&__pyx_n_s__pattern2phrase, __pyx_k__pattern2phrase, sizeof(__pyx_k__pattern2phrase), 0, 0, 1, 1}, - {&__pyx_n_s__pattern2phrase_plus, __pyx_k__pattern2phrase_plus, sizeof(__pyx_k__pattern2phrase_plus), 0, 0, 1, 1}, - {&__pyx_n_s__phrase, __pyx_k__phrase, sizeof(__pyx_k__phrase), 0, 0, 1, 1}, - {&__pyx_n_s__phrase_location, __pyx_k__phrase_location, sizeof(__pyx_k__phrase_location), 0, 0, 1, 1}, - {&__pyx_n_s__precompute, __pyx_k__precompute, sizeof(__pyx_k__precompute), 0, 0, 1, 1}, - {&__pyx_n_s__precompute_file, __pyx_k__precompute_file, sizeof(__pyx_k__precompute_file), 0, 0, 1, 1}, - {&__pyx_n_s__precompute_rank, __pyx_k__precompute_rank, sizeof(__pyx_k__precompute_rank), 0, 0, 1, 1}, - {&__pyx_n_s__precomputed, __pyx_k__precomputed, sizeof(__pyx_k__precomputed), 0, 0, 1, 1}, - {&__pyx_n_s__q3sort, __pyx_k__q3sort, sizeof(__pyx_k__q3sort), 0, 0, 1, 1}, - {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1}, - {&__pyx_n_s__reachable, __pyx_k__reachable, sizeof(__pyx_k__reachable), 0, 0, 1, 1}, - {&__pyx_n_s__reachable_buffer, __pyx_k__reachable_buffer, sizeof(__pyx_k__reachable_buffer), 0, 0, 1, 1}, - {&__pyx_n_s__read_binary, __pyx_k__read_binary, sizeof(__pyx_k__read_binary), 0, 0, 1, 1}, - {&__pyx_n_s__read_text, __pyx_k__read_text, sizeof(__pyx_k__read_text), 0, 0, 1, 1}, - {&__pyx_n_s__res, __pyx_k__res, sizeof(__pyx_k__res), 0, 0, 1, 1}, - {&__pyx_n_s__reset, __pyx_k__reset, sizeof(__pyx_k__reset), 0, 0, 1, 1}, - {&__pyx_n_s__resource, __pyx_k__resource, sizeof(__pyx_k__resource), 0, 0, 1, 1}, - {&__pyx_n_s__ru_stime, __pyx_k__ru_stime, sizeof(__pyx_k__ru_stime), 0, 0, 1, 1}, - {&__pyx_n_s__ru_utime, __pyx_k__ru_utime, sizeof(__pyx_k__ru_utime), 0, 0, 1, 1}, - {&__pyx_n_s__sa, __pyx_k__sa, sizeof(__pyx_k__sa), 0, 0, 1, 1}, - {&__pyx_n_s__sa_high, __pyx_k__sa_high, sizeof(__pyx_k__sa_high), 0, 0, 1, 1}, - {&__pyx_n_s__sa_low, __pyx_k__sa_low, sizeof(__pyx_k__sa_low), 0, 0, 1, 1}, - {&__pyx_n_s__sample, __pyx_k__sample, sizeof(__pyx_k__sample), 0, 0, 1, 1}, - {&__pyx_n_s__sample_size, __pyx_k__sample_size, sizeof(__pyx_k__sample_size), 0, 0, 1, 1}, - {&__pyx_n_s__sampler, __pyx_k__sampler, sizeof(__pyx_k__sampler), 0, 0, 1, 1}, - {&__pyx_n_s__sarray, __pyx_k__sarray, sizeof(__pyx_k__sarray), 0, 0, 1, 1}, - {&__pyx_n_s__scores, __pyx_k__scores, sizeof(__pyx_k__scores), 0, 0, 1, 1}, - {&__pyx_n_s__seek, __pyx_k__seek, sizeof(__pyx_k__seek), 0, 0, 1, 1}, - {&__pyx_n_s__setdefault, __pyx_k__setdefault, sizeof(__pyx_k__setdefault), 0, 0, 1, 1}, - {&__pyx_n_s__shortest, __pyx_k__shortest, sizeof(__pyx_k__shortest), 0, 0, 1, 1}, - {&__pyx_n_s__size, __pyx_k__size, sizeof(__pyx_k__size), 0, 0, 1, 1}, - {&__pyx_n_s__skip, __pyx_k__skip, sizeof(__pyx_k__skip), 0, 0, 1, 1}, - {&__pyx_n_s__sorted, __pyx_k__sorted, sizeof(__pyx_k__sorted), 0, 0, 1, 1}, - {&__pyx_n_s__spanlen, __pyx_k__spanlen, sizeof(__pyx_k__spanlen), 0, 0, 1, 1}, - {&__pyx_n_s__split, __pyx_k__split, sizeof(__pyx_k__split), 0, 0, 1, 1}, - {&__pyx_n_s__start, __pyx_k__start, sizeof(__pyx_k__start), 0, 0, 1, 1}, - {&__pyx_n_s__stats, __pyx_k__stats, sizeof(__pyx_k__stats), 0, 0, 1, 1}, - {&__pyx_n_s__stop, __pyx_k__stop, sizeof(__pyx_k__stop), 0, 0, 1, 1}, - {&__pyx_n_s__string, __pyx_k__string, sizeof(__pyx_k__string), 0, 0, 1, 1}, - {&__pyx_n_s__suffix_link, __pyx_k__suffix_link, sizeof(__pyx_k__suffix_link), 0, 0, 1, 1}, - {&__pyx_n_s__sym, __pyx_k__sym, sizeof(__pyx_k__sym), 0, 0, 1, 1}, - {&__pyx_n_s__sym_fromstring, __pyx_k__sym_fromstring, sizeof(__pyx_k__sym_fromstring), 0, 0, 1, 1}, - {&__pyx_n_s__sym_isvar, __pyx_k__sym_isvar, sizeof(__pyx_k__sym_isvar), 0, 0, 1, 1}, - {&__pyx_n_s__sym_tostring, __pyx_k__sym_tostring, sizeof(__pyx_k__sym_tostring), 0, 0, 1, 1}, - {&__pyx_n_s__terminal, __pyx_k__terminal, sizeof(__pyx_k__terminal), 0, 0, 1, 1}, - {&__pyx_n_s__tight_phrases, __pyx_k__tight_phrases, sizeof(__pyx_k__tight_phrases), 0, 0, 1, 1}, - {&__pyx_n_s__toMap, __pyx_k__toMap, sizeof(__pyx_k__toMap), 0, 0, 1, 1}, - {&__pyx_n_s__train_min_gap_size, __pyx_k__train_min_gap_size, sizeof(__pyx_k__train_min_gap_size), 0, 0, 1, 1}, - {&__pyx_n_s__unlink, __pyx_k__unlink, sizeof(__pyx_k__unlink), 0, 0, 1, 1}, - {&__pyx_n_s__use_baeza_yates, __pyx_k__use_baeza_yates, sizeof(__pyx_k__use_baeza_yates), 0, 0, 1, 1}, - {&__pyx_n_s__use_collocations, __pyx_k__use_collocations, sizeof(__pyx_k__use_collocations), 0, 0, 1, 1}, - {&__pyx_n_s__use_index, __pyx_k__use_index, sizeof(__pyx_k__use_index), 0, 0, 1, 1}, - {&__pyx_n_s__use_sent_id, __pyx_k__use_sent_id, sizeof(__pyx_k__use_sent_id), 0, 0, 1, 1}, - {&__pyx_n_s__w, __pyx_k__w, sizeof(__pyx_k__w), 0, 0, 1, 1}, - {&__pyx_n_s__warn, __pyx_k__warn, sizeof(__pyx_k__warn), 0, 0, 1, 1}, - {&__pyx_n_s__word, __pyx_k__word, sizeof(__pyx_k__word), 0, 0, 1, 1}, - {&__pyx_n_s__word_alignments, __pyx_k__word_alignments, sizeof(__pyx_k__word_alignments), 0, 0, 1, 1}, - {&__pyx_n_s__words, __pyx_k__words, sizeof(__pyx_k__words), 0, 0, 1, 1}, - {&__pyx_n_s__write, __pyx_k__write, sizeof(__pyx_k__write), 0, 0, 1, 1}, - {&__pyx_n_s__write_text, __pyx_k__write_text, sizeof(__pyx_k__write_text), 0, 0, 1, 1}, - {&__pyx_n_s__zip, __pyx_k__zip, sizeof(__pyx_k__zip), 0, 0, 1, 1}, - {0, 0, 0, 0, 0, 0, 0} -}; -static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_open = __Pyx_GetName(__pyx_b, __pyx_n_s__open); if (!__pyx_builtin_open) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __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[2]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_map = __Pyx_GetName(__pyx_b, __pyx_n_s__map); if (!__pyx_builtin_map) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __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[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_zip = __Pyx_GetName(__pyx_b, __pyx_n_s__zip); if (!__pyx_builtin_zip) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_StopIteration = __Pyx_GetName(__pyx_b, __pyx_n_s__StopIteration); if (!__pyx_builtin_StopIteration) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_cmp = __Pyx_GetName(__pyx_b, __pyx_n_s__cmp); if (!__pyx_builtin_cmp) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_sorted = __Pyx_GetName(__pyx_b, __pyx_n_s__sorted); if (!__pyx_builtin_sorted) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 917; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - return 0; - __pyx_L1_error:; - return -1; -} - -static int __Pyx_InitCachedConstants(void) { - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":20 - * self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} - * self.id2word = ["END_OF_FILE", "END_OF_LINE"] - * self.data = IntList(1000,1000) # <<<<<<<<<<<<<< - * self.sent_id = IntList(1000,1000) - * self.sent_index = IntList(1000,1000) - */ - __pyx_k_tuple_10 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_10); - __Pyx_INCREF(__pyx_int_1000); - PyTuple_SET_ITEM(__pyx_k_tuple_10, 0, __pyx_int_1000); - __Pyx_GIVEREF(__pyx_int_1000); - __Pyx_INCREF(__pyx_int_1000); - PyTuple_SET_ITEM(__pyx_k_tuple_10, 1, __pyx_int_1000); - __Pyx_GIVEREF(__pyx_int_1000); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_10)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":21 - * self.id2word = ["END_OF_FILE", "END_OF_LINE"] - * self.data = IntList(1000,1000) - * self.sent_id = IntList(1000,1000) # <<<<<<<<<<<<<< - * self.sent_index = IntList(1000,1000) - * self.use_sent_id = use_sent_id - */ - __pyx_k_tuple_11 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_11); - __Pyx_INCREF(__pyx_int_1000); - PyTuple_SET_ITEM(__pyx_k_tuple_11, 0, __pyx_int_1000); - __Pyx_GIVEREF(__pyx_int_1000); - __Pyx_INCREF(__pyx_int_1000); - PyTuple_SET_ITEM(__pyx_k_tuple_11, 1, __pyx_int_1000); - __Pyx_GIVEREF(__pyx_int_1000); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_11)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":22 - * self.data = IntList(1000,1000) - * self.sent_id = IntList(1000,1000) - * self.sent_index = IntList(1000,1000) # <<<<<<<<<<<<<< - * self.use_sent_id = use_sent_id - * if from_binary: - */ - __pyx_k_tuple_12 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_12); - __Pyx_INCREF(__pyx_int_1000); - PyTuple_SET_ITEM(__pyx_k_tuple_12, 0, __pyx_int_1000); - __Pyx_GIVEREF(__pyx_int_1000); - __Pyx_INCREF(__pyx_int_1000); - PyTuple_SET_ITEM(__pyx_k_tuple_12, 1, __pyx_int_1000); - __Pyx_GIVEREF(__pyx_int_1000); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":62 - * f.write("%s " % self.get_word(w_id)) - * if w_id == 1: - * f.write("\n") # <<<<<<<<<<<<<< - * - * def read_text(self, char* filename): - */ - __pyx_k_tuple_15 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_15)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_15); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_15, 0, ((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_15)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":57 - * - * def write_text(self, char* filename): - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * for w_id in self.data: - * if w_id > 1: - */ - __pyx_k_tuple_16 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_16)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_16); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_16, 0, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_16, 1, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_16, 2, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_16)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":66 - * def read_text(self, char* filename): - * cdef int word_count = 0 - * with gzip_or_text(filename) as fp: # <<<<<<<<<<<<<< - * for line_num, line in enumerate(fp): - * self.sent_index.append(word_count) - */ - __pyx_k_tuple_17 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_17)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_17); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_17, 0, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_17, 1, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_17, 2, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_17)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":133 - * for i in self.data: - * f.write("%d " %i) - * f.write("\n") # <<<<<<<<<<<<<< - * for i in self.sent_index: - * f.write("%d " %i) - */ - __pyx_k_tuple_19 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_19)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_19); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_19, 0, ((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_19)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":136 - * for i in self.sent_index: - * f.write("%d " %i) - * f.write("\n") # <<<<<<<<<<<<<< - * for i in self.sent_id: - * f.write("%d " %i) - */ - __pyx_k_tuple_20 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_20); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_20, 0, ((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":139 - * for i in self.sent_id: - * f.write("%d " %i) - * f.write("\n") # <<<<<<<<<<<<<< - * for word in self.id2word: - * f.write("%s %d " % (word, self.word2id[word])) - */ - __pyx_k_tuple_21 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_21)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_21); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_21, 0, ((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":142 - * for word in self.id2word: - * f.write("%s %d " % (word, self.word2id[word])) - * f.write("\n") # <<<<<<<<<<<<<< - * - * def write_enhanced(self, char* filename): - */ - __pyx_k_tuple_23 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_23)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_23); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_23, 0, ((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_23)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":145 - * - * def write_enhanced(self, char* filename): - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * self.write_enhanced_handle(self, f) - */ - __pyx_k_tuple_25 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_25); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_25, 0, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_25, 1, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_25, 2, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_25)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":46 - * - * def __cinit__(self, from_binary=None, from_text=None): - * self.links = IntList(1000,1000) # <<<<<<<<<<<<<< - * self.sent_index = IntList(1000,1000) - * if from_binary: - */ - __pyx_k_tuple_26 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_26)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_26); - __Pyx_INCREF(__pyx_int_1000); - PyTuple_SET_ITEM(__pyx_k_tuple_26, 0, __pyx_int_1000); - __Pyx_GIVEREF(__pyx_int_1000); - __Pyx_INCREF(__pyx_int_1000); - PyTuple_SET_ITEM(__pyx_k_tuple_26, 1, __pyx_int_1000); - __Pyx_GIVEREF(__pyx_int_1000); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_26)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":47 - * def __cinit__(self, from_binary=None, from_text=None): - * self.links = IntList(1000,1000) - * self.sent_index = IntList(1000,1000) # <<<<<<<<<<<<<< - * if from_binary: - * self.read_binary(from_binary) - */ - __pyx_k_tuple_27 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_27)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_27); - __Pyx_INCREF(__pyx_int_1000); - PyTuple_SET_ITEM(__pyx_k_tuple_27, 0, __pyx_int_1000); - __Pyx_GIVEREF(__pyx_int_1000); - __Pyx_INCREF(__pyx_int_1000); - PyTuple_SET_ITEM(__pyx_k_tuple_27, 1, __pyx_int_1000); - __Pyx_GIVEREF(__pyx_int_1000); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_27)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":59 - * pairs = line.split() - * for pair in pairs: - * (i, j) = map(int, pair.split('-')) # <<<<<<<<<<<<<< - * self.links.append(self.link(i, j)) - * self.sent_index.append(len(self.links)) - */ - __pyx_k_tuple_29 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_29)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_29); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_28)); - PyTuple_SET_ITEM(__pyx_k_tuple_29, 0, ((PyObject *)__pyx_kp_s_28)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_28)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_29)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":54 - * - * def read_text(self, char* filename): - * with gzip_or_text(filename) as f: # <<<<<<<<<<<<<< - * for line in f: - * self.sent_index.append(len(self.links)) - */ - __pyx_k_tuple_30 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_30)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_30); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_30, 0, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_30, 1, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_30, 2, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_30)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":75 - * for i, link in enumerate(self.links): - * while i >= self.sent_index[sent_num]: - * f.write("\n") # <<<<<<<<<<<<<< - * sent_num = sent_num + 1 - * f.write("%d-%d " % self.unlink(link)) - */ - __pyx_k_tuple_31 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_31)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_31); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_31, 0, ((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_31)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":78 - * sent_num = sent_num + 1 - * f.write("%d-%d " % self.unlink(link)) - * f.write("\n") # <<<<<<<<<<<<<< - * - * def write_binary(self, char* filename): - */ - __pyx_k_tuple_33 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_33)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_33); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_33, 0, ((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_33)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":71 - * - * def write_text(self, char* filename): - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * sent_num = 0 - * for i, link in enumerate(self.links): - */ - __pyx_k_tuple_34 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_34)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_34); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_34, 0, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_34, 1, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_34, 2, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_34)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":92 - * for link in self.links: - * f.write("%d " % link) - * f.write("\n") # <<<<<<<<<<<<<< - * for i in self.sent_index: - * f.write("%d " % i) - */ - __pyx_k_tuple_35 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_35)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_35); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_35, 0, ((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_35)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":95 - * for i in self.sent_index: - * f.write("%d " % i) - * f.write("\n") # <<<<<<<<<<<<<< - * - * def alignment(self, i): - */ - __pyx_k_tuple_36 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_36)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_36); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_36, 0, ((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_36)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":88 - * - * def write_enhanced(self, char* filename): - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * sent_num = 1 - * for link in self.links: - */ - __pyx_k_tuple_37 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_37)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_37); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_37, 0, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_37, 1, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_37, 2, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_37)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":302 - * - * # Re-read file, placing words into buckets - * f.seek(0) # <<<<<<<<<<<<<< - * for line in f: - * (fword, eword, score1, score2) = line.split() - */ - __pyx_k_tuple_40 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_40)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_40); - __Pyx_INCREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_k_tuple_40, 0, __pyx_int_0); - __Pyx_GIVEREF(__pyx_int_0); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_40)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":278 - * - * fcount = IntList() - * with gzip_or_text(filename) as f: # <<<<<<<<<<<<<< - * # first loop merely establishes size of array objects - * for line in f: - */ - __pyx_k_tuple_41 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_41)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_41); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_41, 0, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_41, 1, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_41, 2, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_41)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":344 - * - * if i > j: - * raise Exception("Sort error in CLex") # <<<<<<<<<<<<<< - * if i == j: #empty interval - * return - */ - __pyx_k_tuple_44 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_44)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_44); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_43)); - PyTuple_SET_ITEM(__pyx_k_tuple_44, 0, ((PyObject *)__pyx_kp_s_43)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_43)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_44)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":367 - * for i in self.f_index: - * f.write("%d " % i) - * f.write("\n") # <<<<<<<<<<<<<< - * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): - * f.write("%d %f %f " % (i, s1, s2)) - */ - __pyx_k_tuple_46 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_46)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_46); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_46, 0, ((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_46)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":370 - * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): - * f.write("%d %f %f " % (i, s1, s2)) - * f.write("\n") # <<<<<<<<<<<<<< - * for i, w in enumerate(self.id2fword): - * f.write("%d %s " % (i, w)) - */ - __pyx_k_tuple_48 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_48)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_48); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_48, 0, ((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_48)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":373 - * for i, w in enumerate(self.id2fword): - * f.write("%d %s " % (i, w)) - * f.write("\n") # <<<<<<<<<<<<<< - * for i, w in enumerate(self.id2eword): - * f.write("%d %s " % (i, w)) - */ - __pyx_k_tuple_50 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_50)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_50); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_50, 0, ((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_50)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":376 - * for i, w in enumerate(self.id2eword): - * f.write("%d %s " % (i, w)) - * f.write("\n") # <<<<<<<<<<<<<< - * - * - */ - __pyx_k_tuple_51 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_51)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_51); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_51, 0, ((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_51)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":364 - * - * def write_enhanced(self, char* filename): - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * for i in self.f_index: - * f.write("%d " % i) - */ - __pyx_k_tuple_52 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_52); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_52, 0, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_52, 1, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_52, 2, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_52)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":409 - * cdef i, N, e_id, f_id - * - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * N = len(self.e_index) - * f_id = 0 - */ - __pyx_k_tuple_54 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_54)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_54); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_54, 0, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_54, 1, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_54, 2, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_54)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":13 - * cdef IntList rank - * - * logger.info("Constructing LCP array") # <<<<<<<<<<<<<< - * self.sa = sa - * n = self.sa.sa.len - */ - __pyx_k_tuple_58 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_58)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_58); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_57)); - PyTuple_SET_ITEM(__pyx_k_tuple_58, 0, ((PyObject *)__pyx_kp_s_57)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_57)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_58)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":34 - * if h > 0: - * h = h-1 - * logger.info("LCP array completed") # <<<<<<<<<<<<<< - * - * def compute_stats(self, int max_n): - */ - __pyx_k_tuple_60 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_60)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_60); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_59)); - PyTuple_SET_ITEM(__pyx_k_tuple_60, 0, ((PyObject *)__pyx_kp_s_59)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_59)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_60)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":297 - * pattern_rank = {} - * - * logger.info("Precomputing frequent intersections") # <<<<<<<<<<<<<< - * cdef float start_time = monitor_cpu() - * - */ - __pyx_k_tuple_71 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_71)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_71); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_70)); - PyTuple_SET_ITEM(__pyx_k_tuple_71, 0, ((PyObject *)__pyx_kp_s_70)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_70)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_71)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":314 - * queue = IntList(increment=1000) - * - * logger.info(" Computing inverted indexes...") # <<<<<<<<<<<<<< - * N = len(data) - * for i from 0 <= i < N: - */ - __pyx_k_tuple_73 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_73)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_73); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_72)); - PyTuple_SET_ITEM(__pyx_k_tuple_73, 0, ((PyObject *)__pyx_kp_s_72)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_72)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_73)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":329 - * trie_node_data_append(node, i) - * - * logger.info(" Computing collocations...") # <<<<<<<<<<<<<< - * N = len(queue) - * ptr1 = 0 - */ - __pyx_k_tuple_75 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_75)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_75); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_74)); - PyTuple_SET_ITEM(__pyx_k_tuple_75, 0, ((PyObject *)__pyx_kp_s_74)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_74)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_75)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":393 - * for pattern2 in J_set: - * if len(pattern1) + len(pattern2) + 1 < self.max_length: - * combined_pattern = pattern1 + (-1,) + pattern2 # <<<<<<<<<<<<<< - * J2_set.add(combined_pattern) - * - */ - __pyx_k_tuple_77 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_77)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_77); - __Pyx_INCREF(__pyx_int_neg_1); - PyTuple_SET_ITEM(__pyx_k_tuple_77, 0, __pyx_int_neg_1); - __Pyx_GIVEREF(__pyx_int_neg_1); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_77)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":400 - * x = x+1 - * if len(pattern1) + len(pattern2) + 1 <= self.max_length: - * combined_pattern = pattern1 + (-1,) + pattern2 # <<<<<<<<<<<<<< - * IJ_set.add(combined_pattern) - * - */ - __pyx_k_tuple_78 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_78)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_78); - __Pyx_INCREF(__pyx_int_neg_1); - PyTuple_SET_ITEM(__pyx_k_tuple_78, 0, __pyx_int_neg_1); - __Pyx_GIVEREF(__pyx_int_neg_1); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_78)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":407 - * x = x+2 - * if len(pattern1) + len(pattern2) + 1<= self.max_length: - * combined_pattern = pattern1 + (-1,) + pattern2 # <<<<<<<<<<<<<< - * IJ_set.add(combined_pattern) - * combined_pattern = pattern2 + (-1,) + pattern1 - */ - __pyx_k_tuple_79 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_79)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_79); - __Pyx_INCREF(__pyx_int_neg_1); - PyTuple_SET_ITEM(__pyx_k_tuple_79, 0, __pyx_int_neg_1); - __Pyx_GIVEREF(__pyx_int_neg_1); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_79)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":409 - * combined_pattern = pattern1 + (-1,) + pattern2 - * IJ_set.add(combined_pattern) - * combined_pattern = pattern2 + (-1,) + pattern1 # <<<<<<<<<<<<<< - * IJ_set.add(combined_pattern) - * - */ - __pyx_k_tuple_80 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_80)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_80); - __Pyx_INCREF(__pyx_int_neg_1); - PyTuple_SET_ITEM(__pyx_k_tuple_80, 0, __pyx_int_neg_1); - __Pyx_GIVEREF(__pyx_int_neg_1); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_80)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":103 - * - * '''Step 3: read off suffix array from inverse suffix array''' - * logger.info(" Finalizing sort...") # <<<<<<<<<<<<<< - * for i from 0 <= i < N: - * j = isa.arr[i] - */ - __pyx_k_tuple_91 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_91)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_91); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_90)); - PyTuple_SET_ITEM(__pyx_k_tuple_91, 0, ((PyObject *)__pyx_kp_s_90)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_90)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_91)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":202 - * for a_i in self.sa: - * f.write("%d " % a_i) - * f.write("\n") # <<<<<<<<<<<<<< - * for w_i in self.ha: - * f.write("%d " % w_i) - */ - __pyx_k_tuple_94 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_94)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_94); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_94, 0, ((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_94)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":205 - * for w_i in self.ha: - * f.write("%d " % w_i) - * f.write("\n") # <<<<<<<<<<<<<< - * - * cdef int __search_high(self, int word_id, int offset, int low, int high): - */ - __pyx_k_tuple_95 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_95)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_95); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_95, 0, ((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_95)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":198 - * - * def write_enhanced(self, char* filename): - * with open(filename, "w") as f: # <<<<<<<<<<<<<< - * self.darray.write_enhanced_handle(f) - * for a_i in self.sa: - */ - __pyx_k_tuple_96 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_96)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_96); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_96, 0, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_96, 1, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_96, 2, Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_96)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":92 - * logger.info("Sampling strategy: uniform, max sample size = %d", sample_size) - * else: - * logger.info("Sampling strategy: no sampling") # <<<<<<<<<<<<<< - * - * def sample(self, PhraseLocation phrase_location): - */ - __pyx_k_tuple_100 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_100)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_100); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_99)); - PyTuple_SET_ITEM(__pyx_k_tuple_100, 0, ((PyObject *)__pyx_kp_s_99)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_99)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_100)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":300 - * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) - * if alignment is None: - * raise Exception("Must specify an alignment object") # <<<<<<<<<<<<<< - * self.alignment = alignment - * - */ - __pyx_k_tuple_105 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_105)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_105); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_104)); - PyTuple_SET_ITEM(__pyx_k_tuple_105, 0, ((PyObject *)__pyx_kp_s_104)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_104)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_105)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1005 - * else: - * #ERROR: We never get here - * raise Exception("Keyword trie error") # <<<<<<<<<<<<<< - * # checking whether lookup_required - * if lookup_required: - */ - __pyx_k_tuple_120 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_120)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_120); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_119)); - PyTuple_SET_ITEM(__pyx_k_tuple_120, 0, ((PyObject *)__pyx_kp_s_119)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_119)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_120)); - - /* "_cdec_sa.pyx":9 - * resource.getrusage(resource.RUSAGE_SELF).ru_stime) - * - * def gzip_or_text(char* filename): # <<<<<<<<<<<<<< - * if filename.endswith('.gz'): - * return gzip.GzipFile(filename) - */ - __pyx_k_tuple_132 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_132)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_132); - __Pyx_INCREF(((PyObject *)__pyx_n_s__filename)); - PyTuple_SET_ITEM(__pyx_k_tuple_132, 0, ((PyObject *)__pyx_n_s__filename)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__filename)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__filename)); - PyTuple_SET_ITEM(__pyx_k_tuple_132, 1, ((PyObject *)__pyx_n_s__filename)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__filename)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_132)); - __pyx_k_codeobj_133 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_132, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_134, __pyx_n_s__gzip_or_text, 9, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_133)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "_cdec_sa.pyx":15 - * return open(filename) - * - * logger = logging.getLogger('cdec.sa') # <<<<<<<<<<<<<< - * - * include "float_list.pxi" - */ - __pyx_k_tuple_136 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_136)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_136); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_135)); - PyTuple_SET_ITEM(__pyx_k_tuple_136, 0, ((PyObject *)__pyx_kp_s_135)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_135)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_136)); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":91 - * cdef Alphabet ALPHABET = Alphabet() - * - * def sym_tostring(int sym): # <<<<<<<<<<<<<< - * return ALPHABET.tostring(sym) - * - */ - __pyx_k_tuple_137 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_137)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_137); - __Pyx_INCREF(((PyObject *)__pyx_n_s__sym)); - PyTuple_SET_ITEM(__pyx_k_tuple_137, 0, ((PyObject *)__pyx_n_s__sym)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__sym)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__sym)); - PyTuple_SET_ITEM(__pyx_k_tuple_137, 1, ((PyObject *)__pyx_n_s__sym)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__sym)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_137)); - __pyx_k_codeobj_138 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_137, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_139, __pyx_n_s__sym_tostring, 91, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_138)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":94 - * return ALPHABET.tostring(sym) - * - * def sym_fromstring(bytes string, bint terminal): # <<<<<<<<<<<<<< - * return ALPHABET.fromstring(string, terminal) - * - */ - __pyx_k_tuple_140 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_140)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_140); - __Pyx_INCREF(((PyObject *)__pyx_n_s__string)); - PyTuple_SET_ITEM(__pyx_k_tuple_140, 0, ((PyObject *)__pyx_n_s__string)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__string)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__terminal)); - PyTuple_SET_ITEM(__pyx_k_tuple_140, 1, ((PyObject *)__pyx_n_s__terminal)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__terminal)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_140)); - __pyx_k_codeobj_141 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_139, __pyx_n_s__sym_fromstring, 94, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_141)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":97 - * return ALPHABET.fromstring(string, terminal) - * - * def sym_isvar(int sym): # <<<<<<<<<<<<<< - * return ALPHABET.isvar(sym) - * - */ - __pyx_k_tuple_142 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_142)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_142); - __Pyx_INCREF(((PyObject *)__pyx_n_s__sym)); - PyTuple_SET_ITEM(__pyx_k_tuple_142, 0, ((PyObject *)__pyx_n_s__sym)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__sym)); - __Pyx_INCREF(((PyObject *)__pyx_n_s__sym)); - PyTuple_SET_ITEM(__pyx_k_tuple_142, 1, ((PyObject *)__pyx_n_s__sym)); - __Pyx_GIVEREF(((PyObject *)__pyx_n_s__sym)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_142)); - __pyx_k_codeobj_143 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_142, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_139, __pyx_n_s__sym_isvar, 97, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_143)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_RefNannyFinishContext(); - return 0; - __pyx_L1_error:; - __Pyx_RefNannyFinishContext(); - return -1; -} - -static int __Pyx_InitGlobals(void) { - if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_5 = PyInt_FromLong(5); if (unlikely(!__pyx_int_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_10 = PyInt_FromLong(10); if (unlikely(!__pyx_int_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_20 = PyInt_FromLong(20); if (unlikely(!__pyx_int_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_1000 = PyInt_FromLong(1000); if (unlikely(!__pyx_int_1000)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_65536 = PyInt_FromLong(65536); if (unlikely(!__pyx_int_65536)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - return 0; - __pyx_L1_error:; - return -1; -} - -#if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC init_cdec_sa(void); /*proto*/ -PyMODINIT_FUNC init_cdec_sa(void) -#else -PyMODINIT_FUNC PyInit__cdec_sa(void); /*proto*/ -PyMODINIT_FUNC PyInit__cdec_sa(void) -#endif -{ - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - int __pyx_t_4; - __Pyx_RefNannyDeclarations - #if CYTHON_REFNANNY - __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); - if (!__Pyx_RefNanny) { - PyErr_Clear(); - __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); - if (!__Pyx_RefNanny) - Py_FatalError("failed to import 'refnanny' module"); - } - #endif - __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit__cdec_sa(void)", 0); - if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #ifdef __Pyx_CyFunction_USED - if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - #ifdef __Pyx_FusedFunction_USED - if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - #ifdef __Pyx_Generator_USED - if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - /*--- Library function declarations ---*/ - /*--- Threads initialization code ---*/ - #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS - #ifdef WITH_THREAD /* Python build with threading support? */ - PyEval_InitThreads(); - #endif - #endif - /*--- Module creation code ---*/ - #if PY_MAJOR_VERSION < 3 - __pyx_m = Py_InitModule4(__Pyx_NAMESTR("_cdec_sa"), __pyx_methods, 0, 0, PYTHON_API_VERSION); - #else - __pyx_m = PyModule_Create(&__pyx_moduledef); - #endif - if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - #if PY_MAJOR_VERSION < 3 - Py_INCREF(__pyx_m); - #endif - __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); - if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - /*--- Initialize various global constants etc. ---*/ - if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_module_is_main__cdec_sa) { - if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - } - /*--- Builtin init code ---*/ - if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Constants init code ---*/ - if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Global init code ---*/ - __pyx_v_8_cdec_sa_ALPHABET = ((struct __pyx_obj_8_cdec_sa_Alphabet *)Py_None); Py_INCREF(Py_None); - /*--- Variable export code ---*/ - /*--- Function export code ---*/ - /*--- Type init code ---*/ - __pyx_vtabptr_8_cdec_sa_FloatList = &__pyx_vtable_8_cdec_sa_FloatList; - __pyx_vtable_8_cdec_sa_FloatList.set = (void (*)(struct __pyx_obj_8_cdec_sa_FloatList *, int, float))__pyx_f_8_cdec_sa_9FloatList_set; - __pyx_vtable_8_cdec_sa_FloatList.write_handle = (void (*)(struct __pyx_obj_8_cdec_sa_FloatList *, FILE *))__pyx_f_8_cdec_sa_9FloatList_write_handle; - __pyx_vtable_8_cdec_sa_FloatList.read_handle = (void (*)(struct __pyx_obj_8_cdec_sa_FloatList *, FILE *))__pyx_f_8_cdec_sa_9FloatList_read_handle; - if (PyType_Ready(&__pyx_type_8_cdec_sa_FloatList) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_FloatList.tp_dict, __pyx_vtabptr_8_cdec_sa_FloatList) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "FloatList", (PyObject *)&__pyx_type_8_cdec_sa_FloatList) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_FloatList = &__pyx_type_8_cdec_sa_FloatList; - __pyx_vtabptr_8_cdec_sa_IntList = &__pyx_vtable_8_cdec_sa_IntList; - __pyx_vtable_8_cdec_sa_IntList.set = (void (*)(struct __pyx_obj_8_cdec_sa_IntList *, int, int))__pyx_f_8_cdec_sa_7IntList_set; - __pyx_vtable_8_cdec_sa_IntList._append = (void (*)(struct __pyx_obj_8_cdec_sa_IntList *, int))__pyx_f_8_cdec_sa_7IntList__append; - __pyx_vtable_8_cdec_sa_IntList._extend = (void (*)(struct __pyx_obj_8_cdec_sa_IntList *, struct __pyx_obj_8_cdec_sa_IntList *))__pyx_f_8_cdec_sa_7IntList__extend; - __pyx_vtable_8_cdec_sa_IntList._extend_arr = (void (*)(struct __pyx_obj_8_cdec_sa_IntList *, int *, int))__pyx_f_8_cdec_sa_7IntList__extend_arr; - __pyx_vtable_8_cdec_sa_IntList._clear = (void (*)(struct __pyx_obj_8_cdec_sa_IntList *))__pyx_f_8_cdec_sa_7IntList__clear; - __pyx_vtable_8_cdec_sa_IntList.write_handle = (void (*)(struct __pyx_obj_8_cdec_sa_IntList *, FILE *))__pyx_f_8_cdec_sa_7IntList_write_handle; - __pyx_vtable_8_cdec_sa_IntList.read_handle = (void (*)(struct __pyx_obj_8_cdec_sa_IntList *, FILE *))__pyx_f_8_cdec_sa_7IntList_read_handle; - if (PyType_Ready(&__pyx_type_8_cdec_sa_IntList) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_IntList.tp_dict, __pyx_vtabptr_8_cdec_sa_IntList) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "IntList", (PyObject *)&__pyx_type_8_cdec_sa_IntList) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_IntList = &__pyx_type_8_cdec_sa_IntList; - __pyx_vtabptr_8_cdec_sa_StringMap = &__pyx_vtable_8_cdec_sa_StringMap; - __pyx_vtable_8_cdec_sa_StringMap.word = (char *(*)(struct __pyx_obj_8_cdec_sa_StringMap *, int))__pyx_f_8_cdec_sa_9StringMap_word; - __pyx_vtable_8_cdec_sa_StringMap.index = (int (*)(struct __pyx_obj_8_cdec_sa_StringMap *, char *))__pyx_f_8_cdec_sa_9StringMap_index; - if (PyType_Ready(&__pyx_type_8_cdec_sa_StringMap) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_StringMap.tp_dict, __pyx_vtabptr_8_cdec_sa_StringMap) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "StringMap", (PyObject *)&__pyx_type_8_cdec_sa_StringMap) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_StringMap = &__pyx_type_8_cdec_sa_StringMap; - __pyx_vtabptr_8_cdec_sa_DataArray = &__pyx_vtable_8_cdec_sa_DataArray; - __pyx_vtable_8_cdec_sa_DataArray.read_handle = (void (*)(struct __pyx_obj_8_cdec_sa_DataArray *, FILE *))__pyx_f_8_cdec_sa_9DataArray_read_handle; - __pyx_vtable_8_cdec_sa_DataArray.write_handle = (void (*)(struct __pyx_obj_8_cdec_sa_DataArray *, FILE *))__pyx_f_8_cdec_sa_9DataArray_write_handle; - if (PyType_Ready(&__pyx_type_8_cdec_sa_DataArray) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_DataArray.tp_dict, __pyx_vtabptr_8_cdec_sa_DataArray) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "DataArray", (PyObject *)&__pyx_type_8_cdec_sa_DataArray) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_DataArray = &__pyx_type_8_cdec_sa_DataArray; - __pyx_vtabptr_8_cdec_sa_Alignment = &__pyx_vtable_8_cdec_sa_Alignment; - __pyx_vtable_8_cdec_sa_Alignment.link = (int (*)(struct __pyx_obj_8_cdec_sa_Alignment *, int, int))__pyx_f_8_cdec_sa_9Alignment_link; - __pyx_vtable_8_cdec_sa_Alignment._unlink = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_Alignment *, int, int *, int *))__pyx_f_8_cdec_sa_9Alignment__unlink; - __pyx_vtable_8_cdec_sa_Alignment._get_sent_links = (int *(*)(struct __pyx_obj_8_cdec_sa_Alignment *, int, int *))__pyx_f_8_cdec_sa_9Alignment__get_sent_links; - if (PyType_Ready(&__pyx_type_8_cdec_sa_Alignment) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_Alignment.tp_dict, __pyx_vtabptr_8_cdec_sa_Alignment) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Alignment", (PyObject *)&__pyx_type_8_cdec_sa_Alignment) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_Alignment = &__pyx_type_8_cdec_sa_Alignment; - __pyx_vtabptr_8_cdec_sa_BiLex = &__pyx_vtable_8_cdec_sa_BiLex; - __pyx_vtable_8_cdec_sa_BiLex.compute_from_data = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_BiLex *, struct __pyx_obj_8_cdec_sa_SuffixArray *, struct __pyx_obj_8_cdec_sa_DataArray *, struct __pyx_obj_8_cdec_sa_Alignment *))__pyx_f_8_cdec_sa_5BiLex_compute_from_data; - __pyx_vtable_8_cdec_sa_BiLex._add_node = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_BiLex *, struct __pyx_t_8_cdec_sa__node *, int *, float, int *))__pyx_f_8_cdec_sa_5BiLex__add_node; - __pyx_vtable_8_cdec_sa_BiLex.write_wordlist = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_BiLex *, PyObject *, FILE *))__pyx_f_8_cdec_sa_5BiLex_write_wordlist; - __pyx_vtable_8_cdec_sa_BiLex.read_wordlist = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_BiLex *, PyObject *, PyObject *, FILE *))__pyx_f_8_cdec_sa_5BiLex_read_wordlist; - __pyx_vtable_8_cdec_sa_BiLex.swap = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_BiLex *, int, int))__pyx_f_8_cdec_sa_5BiLex_swap; - __pyx_vtable_8_cdec_sa_BiLex.qsort = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_BiLex *, int, int, PyObject *))__pyx_f_8_cdec_sa_5BiLex_qsort; - if (PyType_Ready(&__pyx_type_8_cdec_sa_BiLex) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_BiLex.tp_dict, __pyx_vtabptr_8_cdec_sa_BiLex) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "BiLex", (PyObject *)&__pyx_type_8_cdec_sa_BiLex) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_BiLex = &__pyx_type_8_cdec_sa_BiLex; - if (PyType_Ready(&__pyx_type_8_cdec_sa_BitSetIterator) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "BitSetIterator", (PyObject *)&__pyx_type_8_cdec_sa_BitSetIterator) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_BitSetIterator = &__pyx_type_8_cdec_sa_BitSetIterator; - if (PyType_Ready(&__pyx_type_8_cdec_sa_BitSet) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "BitSet", (PyObject *)&__pyx_type_8_cdec_sa_BitSet) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_BitSet = &__pyx_type_8_cdec_sa_BitSet; - if (PyType_Ready(&__pyx_type_8_cdec_sa_VEBIterator) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "VEBIterator", (PyObject *)&__pyx_type_8_cdec_sa_VEBIterator) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_VEBIterator = &__pyx_type_8_cdec_sa_VEBIterator; - __pyx_vtabptr_8_cdec_sa_VEB = &__pyx_vtable_8_cdec_sa_VEB; - __pyx_vtable_8_cdec_sa_VEB._findsucc = (int (*)(struct __pyx_obj_8_cdec_sa_VEB *, int))__pyx_f_8_cdec_sa_3VEB__findsucc; - __pyx_vtable_8_cdec_sa_VEB._insert = (int (*)(struct __pyx_obj_8_cdec_sa_VEB *, int))__pyx_f_8_cdec_sa_3VEB__insert; - __pyx_vtable_8_cdec_sa_VEB._first = (int (*)(struct __pyx_obj_8_cdec_sa_VEB *))__pyx_f_8_cdec_sa_3VEB__first; - if (PyType_Ready(&__pyx_type_8_cdec_sa_VEB) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_VEB.tp_dict, __pyx_vtabptr_8_cdec_sa_VEB) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "VEB", (PyObject *)&__pyx_type_8_cdec_sa_VEB) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_VEB = &__pyx_type_8_cdec_sa_VEB; - if (PyType_Ready(&__pyx_type_8_cdec_sa_LCP) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "LCP", (PyObject *)&__pyx_type_8_cdec_sa_LCP) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_LCP = &__pyx_type_8_cdec_sa_LCP; - __pyx_vtabptr_8_cdec_sa_Alphabet = &__pyx_vtable_8_cdec_sa_Alphabet; - __pyx_vtable_8_cdec_sa_Alphabet.isvar = (int (*)(struct __pyx_obj_8_cdec_sa_Alphabet *, int))__pyx_f_8_cdec_sa_8Alphabet_isvar; - __pyx_vtable_8_cdec_sa_Alphabet.isword = (int (*)(struct __pyx_obj_8_cdec_sa_Alphabet *, int))__pyx_f_8_cdec_sa_8Alphabet_isword; - __pyx_vtable_8_cdec_sa_Alphabet.getindex = (int (*)(struct __pyx_obj_8_cdec_sa_Alphabet *, int))__pyx_f_8_cdec_sa_8Alphabet_getindex; - __pyx_vtable_8_cdec_sa_Alphabet.setindex = (int (*)(struct __pyx_obj_8_cdec_sa_Alphabet *, int, int))__pyx_f_8_cdec_sa_8Alphabet_setindex; - __pyx_vtable_8_cdec_sa_Alphabet.clearindex = (int (*)(struct __pyx_obj_8_cdec_sa_Alphabet *, int))__pyx_f_8_cdec_sa_8Alphabet_clearindex; - __pyx_vtable_8_cdec_sa_Alphabet.match = (int (*)(struct __pyx_obj_8_cdec_sa_Alphabet *, int, int))__pyx_f_8_cdec_sa_8Alphabet_match; - __pyx_vtable_8_cdec_sa_Alphabet.tocat = (char *(*)(struct __pyx_obj_8_cdec_sa_Alphabet *, int))__pyx_f_8_cdec_sa_8Alphabet_tocat; - __pyx_vtable_8_cdec_sa_Alphabet.fromcat = (int (*)(struct __pyx_obj_8_cdec_sa_Alphabet *, char *))__pyx_f_8_cdec_sa_8Alphabet_fromcat; - __pyx_vtable_8_cdec_sa_Alphabet.tostring = (char *(*)(struct __pyx_obj_8_cdec_sa_Alphabet *, int))__pyx_f_8_cdec_sa_8Alphabet_tostring; - __pyx_vtable_8_cdec_sa_Alphabet.fromstring = (int (*)(struct __pyx_obj_8_cdec_sa_Alphabet *, char *, int))__pyx_f_8_cdec_sa_8Alphabet_fromstring; - if (PyType_Ready(&__pyx_type_8_cdec_sa_Alphabet) < 0) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_Alphabet.tp_dict, __pyx_vtabptr_8_cdec_sa_Alphabet) < 0) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Alphabet", (PyObject *)&__pyx_type_8_cdec_sa_Alphabet) < 0) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_Alphabet = &__pyx_type_8_cdec_sa_Alphabet; - __pyx_vtabptr_8_cdec_sa_Phrase = &__pyx_vtable_8_cdec_sa_Phrase; - __pyx_vtable_8_cdec_sa_Phrase.chunkpos = (int (*)(struct __pyx_obj_8_cdec_sa_Phrase *, int))__pyx_f_8_cdec_sa_6Phrase_chunkpos; - __pyx_vtable_8_cdec_sa_Phrase.chunklen = (int (*)(struct __pyx_obj_8_cdec_sa_Phrase *, int))__pyx_f_8_cdec_sa_6Phrase_chunklen; - if (PyType_Ready(&__pyx_type_8_cdec_sa_Phrase) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_Phrase.tp_dict, __pyx_vtabptr_8_cdec_sa_Phrase) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Phrase", (PyObject *)&__pyx_type_8_cdec_sa_Phrase) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_Phrase = &__pyx_type_8_cdec_sa_Phrase; - if (PyType_Ready(&__pyx_type_8_cdec_sa_Rule) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Rule", (PyObject *)&__pyx_type_8_cdec_sa_Rule) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_Rule = &__pyx_type_8_cdec_sa_Rule; - __pyx_vtabptr_8_cdec_sa_TrieMap = &__pyx_vtable_8_cdec_sa_TrieMap; - __pyx_vtable_8_cdec_sa_TrieMap._insert = (struct __pyx_t_8_cdec_sa__Trie_Node *(*)(struct __pyx_obj_8_cdec_sa_TrieMap *, int *, int))__pyx_f_8_cdec_sa_7TrieMap__insert; - __pyx_vtable_8_cdec_sa_TrieMap._contains = (struct __pyx_t_8_cdec_sa__Trie_Node *(*)(struct __pyx_obj_8_cdec_sa_TrieMap *, int *, int))__pyx_f_8_cdec_sa_7TrieMap__contains; - if (PyType_Ready(&__pyx_type_8_cdec_sa_TrieMap) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_TrieMap.tp_dict, __pyx_vtabptr_8_cdec_sa_TrieMap) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "TrieMap", (PyObject *)&__pyx_type_8_cdec_sa_TrieMap) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_TrieMap = &__pyx_type_8_cdec_sa_TrieMap; - __pyx_vtabptr_8_cdec_sa_Precomputation = &__pyx_vtable_8_cdec_sa_Precomputation; - __pyx_vtable_8_cdec_sa_Precomputation.read_map = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_Precomputation *, FILE *))__pyx_f_8_cdec_sa_14Precomputation_read_map; - __pyx_vtable_8_cdec_sa_Precomputation.write_map = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_Precomputation *, PyObject *, FILE *))__pyx_f_8_cdec_sa_14Precomputation_write_map; - if (PyType_Ready(&__pyx_type_8_cdec_sa_Precomputation) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_Precomputation.tp_dict, __pyx_vtabptr_8_cdec_sa_Precomputation) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Precomputation", (PyObject *)&__pyx_type_8_cdec_sa_Precomputation) < 0) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_Precomputation = &__pyx_type_8_cdec_sa_Precomputation; - __pyx_vtabptr_8_cdec_sa_SuffixArray = &__pyx_vtable_8_cdec_sa_SuffixArray; - __pyx_vtable_8_cdec_sa_SuffixArray.__pyx___search_high = (int (*)(struct __pyx_obj_8_cdec_sa_SuffixArray *, int, int, int, int))__pyx_f_8_cdec_sa_11SuffixArray___search_high; - __pyx_vtable_8_cdec_sa_SuffixArray.__pyx___search_low = (int (*)(struct __pyx_obj_8_cdec_sa_SuffixArray *, int, int, int, int))__pyx_f_8_cdec_sa_11SuffixArray___search_low; - __pyx_vtable_8_cdec_sa_SuffixArray.__pyx___get_range = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_SuffixArray *, int, int, int, int, int))__pyx_f_8_cdec_sa_11SuffixArray___get_range; - __pyx_vtable_8_cdec_sa_SuffixArray.__pyx___lookup_helper = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_SuffixArray *, int, int, int, int))__pyx_f_8_cdec_sa_11SuffixArray___lookup_helper; - if (PyType_Ready(&__pyx_type_8_cdec_sa_SuffixArray) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_SuffixArray.tp_dict, __pyx_vtabptr_8_cdec_sa_SuffixArray) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "SuffixArray", (PyObject *)&__pyx_type_8_cdec_sa_SuffixArray) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_SuffixArray = &__pyx_type_8_cdec_sa_SuffixArray; - if (PyType_Ready(&__pyx_type_8_cdec_sa_TrieNode) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "TrieNode", (PyObject *)&__pyx_type_8_cdec_sa_TrieNode) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_TrieNode = &__pyx_type_8_cdec_sa_TrieNode; - __pyx_type_8_cdec_sa_ExtendedTrieNode.tp_base = __pyx_ptype_8_cdec_sa_TrieNode; - if (PyType_Ready(&__pyx_type_8_cdec_sa_ExtendedTrieNode) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "ExtendedTrieNode", (PyObject *)&__pyx_type_8_cdec_sa_ExtendedTrieNode) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_ExtendedTrieNode = &__pyx_type_8_cdec_sa_ExtendedTrieNode; - if (PyType_Ready(&__pyx_type_8_cdec_sa_TrieTable) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "TrieTable", (PyObject *)&__pyx_type_8_cdec_sa_TrieTable) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_TrieTable = &__pyx_type_8_cdec_sa_TrieTable; - __pyx_vtabptr_8_cdec_sa_PhraseLocation = &__pyx_vtable_8_cdec_sa_PhraseLocation; - __pyx_vtable_8_cdec_sa_PhraseLocation.contains = (int (*)(struct __pyx_obj_8_cdec_sa_PhraseLocation *, int))__pyx_f_8_cdec_sa_14PhraseLocation_contains; - if (PyType_Ready(&__pyx_type_8_cdec_sa_PhraseLocation) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_PhraseLocation.tp_dict, __pyx_vtabptr_8_cdec_sa_PhraseLocation) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "PhraseLocation", (PyObject *)&__pyx_type_8_cdec_sa_PhraseLocation) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_PhraseLocation = &__pyx_type_8_cdec_sa_PhraseLocation; - if (PyType_Ready(&__pyx_type_8_cdec_sa_Sampler) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Sampler", (PyObject *)&__pyx_type_8_cdec_sa_Sampler) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_Sampler = &__pyx_type_8_cdec_sa_Sampler; - __pyx_vtabptr_8_cdec_sa_HieroCachingRuleFactory = &__pyx_vtable_8_cdec_sa_HieroCachingRuleFactory; - __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.set_idmap = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, struct __pyx_obj_8_cdec_sa_DataArray *))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_set_idmap; - __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.baeza_yates_helper = (int *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, int, int, int *, int, int, int, int *, int, int, int, int, int *))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_baeza_yates_helper; - __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.compare_matchings_set = (long (*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, int, int, int *, int, struct __pyx_t_8_cdec_sa_Matching *, int, int))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_compare_matchings_set; - __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.compare_matchings = (long (*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, struct __pyx_t_8_cdec_sa_Matching *, struct __pyx_t_8_cdec_sa_Matching *, int, int))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_compare_matchings; - __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.merge_helper = (int *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, int, int, int *, int, int, int, int *, int, int, int, int, int *))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_merge_helper; - __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.sort_phrase_loc = (void (*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, struct __pyx_obj_8_cdec_sa_IntList *, struct __pyx_obj_8_cdec_sa_PhraseLocation *, struct __pyx_obj_8_cdec_sa_Phrase *))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_sort_phrase_loc; - __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.intersect_helper = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, struct __pyx_obj_8_cdec_sa_Phrase *, struct __pyx_obj_8_cdec_sa_Phrase *, struct __pyx_obj_8_cdec_sa_PhraseLocation *, struct __pyx_obj_8_cdec_sa_PhraseLocation *, int))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_intersect_helper; - __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.loc2str = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, struct __pyx_obj_8_cdec_sa_PhraseLocation *))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_loc2str; - __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.intersect = (struct __pyx_obj_8_cdec_sa_PhraseLocation *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, PyObject *, PyObject *, struct __pyx_obj_8_cdec_sa_Phrase *))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_intersect; - __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.find_fixpoint = (int (*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, int, PyObject *, int *, int *, int *, int *, int, int, int *, int *, int *, int *, int, int, int, int, int, int, int, int, int, int, int))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_find_fixpoint; - __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.find_projection = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, int, int, int *, int *, int *, int *))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_find_projection; - __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.int_arr_extend = (int *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, int *, int *, int *, int))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_int_arr_extend; - __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.extract_phrases = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, int, int, int *, int *, int *, int, int, int, int *, int *, int *, int, int, int))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_extract_phrases; - __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.create_alignments = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, int *, int, PyObject *, PyObject *))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_create_alignments; - __pyx_vtable_8_cdec_sa_HieroCachingRuleFactory.extract = (PyObject *(*)(struct __pyx_obj_8_cdec_sa_HieroCachingRuleFactory *, struct __pyx_obj_8_cdec_sa_Phrase *, struct __pyx_t_8_cdec_sa_Matching *, int *, int))__pyx_f_8_cdec_sa_23HieroCachingRuleFactory_extract; - if (PyType_Ready(&__pyx_type_8_cdec_sa_HieroCachingRuleFactory) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_8_cdec_sa_HieroCachingRuleFactory.tp_dict, __pyx_vtabptr_8_cdec_sa_HieroCachingRuleFactory) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "HieroCachingRuleFactory", (PyObject *)&__pyx_type_8_cdec_sa_HieroCachingRuleFactory) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa_HieroCachingRuleFactory = &__pyx_type_8_cdec_sa_HieroCachingRuleFactory; - if (PyType_Ready(&__pyx_type_8_cdec_sa___pyx_scope_struct__compute_stats) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa___pyx_scope_struct__compute_stats = &__pyx_type_8_cdec_sa___pyx_scope_struct__compute_stats; - if (PyType_Ready(&__pyx_type_8_cdec_sa___pyx_scope_struct_1_input) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_8_cdec_sa___pyx_scope_struct_1_input = &__pyx_type_8_cdec_sa___pyx_scope_struct_1_input; - /*--- Type import code ---*/ - /*--- Variable import code ---*/ - /*--- Function import code ---*/ - /*--- Execution code ---*/ - - /* "_cdec_sa.pyx":1 - * import logging # <<<<<<<<<<<<<< - * import resource - * import gzip - */ - __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__logging), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__logging, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "_cdec_sa.pyx":2 - * import logging - * import resource # <<<<<<<<<<<<<< - * import gzip - * - */ - __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__resource), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__resource, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "_cdec_sa.pyx":3 - * import logging - * import resource - * import gzip # <<<<<<<<<<<<<< - * - * cdef float monitor_cpu(): - */ - __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__gzip), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__gzip, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "_cdec_sa.pyx":9 - * resource.getrusage(resource.RUSAGE_SELF).ru_stime) - * - * def gzip_or_text(char* filename): # <<<<<<<<<<<<<< - * if filename.endswith('.gz'): - * return gzip.GzipFile(filename) - */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8_cdec_sa_1gzip_or_text, NULL, __pyx_n_s___cdec_sa); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__gzip_or_text, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "_cdec_sa.pyx":15 - * return open(filename) - * - * logger = logging.getLogger('cdec.sa') # <<<<<<<<<<<<<< - * - * include "float_list.pxi" - */ - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logging); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__getLogger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_136), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__logger, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":54 - * cdef id2eword, id2fword, eword2id, fword2id - * - * def __cinit__(self, from_text=None, from_data=False, from_binary=None, # <<<<<<<<<<<<<< - * earray=None, fsarray=None, alignment=None): - * self.id2eword = [] - */ - __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_k_38 = __pyx_t_1; - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":17 - * from libc.string cimport memset - * - * cdef int MIN_BOTTOM_SIZE = 32 # <<<<<<<<<<<<<< - * cdef int MIN_BOTTOM_BITS = 5 - * cdef int LOWER_MASK[32] - */ - __pyx_v_8_cdec_sa_MIN_BOTTOM_SIZE = 32; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":18 - * - * cdef int MIN_BOTTOM_SIZE = 32 - * cdef int MIN_BOTTOM_BITS = 5 # <<<<<<<<<<<<<< - * cdef int LOWER_MASK[32] - * - */ - __pyx_v_8_cdec_sa_MIN_BOTTOM_BITS = 5; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":28 - * LOWER_MASK[i] = mask - * - * _init_lower_mask() # <<<<<<<<<<<<<< - * - * cdef struct _BitSet: - */ - __pyx_f_8_cdec_sa__init_lower_mask(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":4 - * from libc.stdlib cimport malloc, realloc, strtol - * - * cdef int INDEX_SHIFT = 3 # <<<<<<<<<<<<<< - * cdef int INDEX_MASK = (1<= 3 - "%s() got multiple values for keyword argument '%U'", func_name, kw_name); - #else - "%s() got multiple values for keyword argument '%s'", func_name, - PyString_AS_STRING(kw_name)); - #endif -} - -static int __Pyx_ParseOptionalKeywords( - PyObject *kwds, - PyObject **argnames[], - PyObject *kwds2, - PyObject *values[], - Py_ssize_t num_pos_args, - const char* function_name) -{ - PyObject *key = 0, *value = 0; - Py_ssize_t pos = 0; - PyObject*** name; - PyObject*** first_kw_arg = argnames + num_pos_args; - while (PyDict_Next(kwds, &pos, &key, &value)) { - name = first_kw_arg; - while (*name && (**name != key)) name++; - if (*name) { - values[name-argnames] = value; - } else { - #if PY_MAJOR_VERSION < 3 - if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) { - #else - if (unlikely(!PyUnicode_Check(key))) { - #endif - goto invalid_keyword_type; - } else { - for (name = first_kw_arg; *name; name++) { - #if PY_MAJOR_VERSION >= 3 - if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && - PyUnicode_Compare(**name, key) == 0) break; - #else - if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && - _PyString_Eq(**name, key)) break; - #endif - } - if (*name) { - values[name-argnames] = value; - } else { - for (name=argnames; name != first_kw_arg; name++) { - if (**name == key) goto arg_passed_twice; - #if PY_MAJOR_VERSION >= 3 - if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && - PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice; - #else - if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && - _PyString_Eq(**name, key)) goto arg_passed_twice; - #endif - } - if (kwds2) { - if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; - } else { - goto invalid_keyword; - } - } - } - } - } - return 0; -arg_passed_twice: - __Pyx_RaiseDoubleKeywordsError(function_name, **name); - goto bad; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%s() keywords must be strings", function_name); - goto bad; -invalid_keyword: - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION < 3 - "%s() got an unexpected keyword argument '%s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); - #endif -bad: - return -1; -} - -static void __Pyx_RaiseArgtupleInvalid( - const char* func_name, - int exact, - Py_ssize_t num_min, - Py_ssize_t num_max, - Py_ssize_t num_found) -{ - Py_ssize_t num_expected; - const char *more_or_less; - if (num_found < num_min) { - num_expected = num_min; - more_or_less = "at least"; - } else { - num_expected = num_max; - more_or_less = "at most"; - } - if (exact) { - more_or_less = "exactly"; - } - PyErr_Format(PyExc_TypeError, - "%s() takes %s %"PY_FORMAT_SIZE_T"d positional argument%s (%"PY_FORMAT_SIZE_T"d given)", - func_name, more_or_less, num_expected, - (num_expected == 1) ? "" : "s", num_found); -} - -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { -#if CYTHON_COMPILING_IN_CPYTHON - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyThreadState *tstate = PyThreadState_GET(); - tmp_type = tstate->curexc_type; - tmp_value = tstate->curexc_value; - tmp_tb = tstate->curexc_traceback; - tstate->curexc_type = type; - tstate->curexc_value = value; - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_type); - Py_XDECREF(tmp_value); - Py_XDECREF(tmp_tb); -#else - PyErr_Restore(type, value, tb); -#endif -} -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { -#if CYTHON_COMPILING_IN_CPYTHON - PyThreadState *tstate = PyThreadState_GET(); - *type = tstate->curexc_type; - *value = tstate->curexc_value; - *tb = tstate->curexc_traceback; - tstate->curexc_type = 0; - tstate->curexc_value = 0; - tstate->curexc_traceback = 0; -#else - PyErr_Fetch(type, value, tb); -#endif -} - -#if PY_MAJOR_VERSION < 3 -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, - CYTHON_UNUSED PyObject *cause) { - Py_XINCREF(type); - Py_XINCREF(value); - Py_XINCREF(tb); - if (tb == Py_None) { - Py_DECREF(tb); - tb = 0; - } - else if (tb != NULL && !PyTraceBack_Check(tb)) { - PyErr_SetString(PyExc_TypeError, - "raise: arg 3 must be a traceback or None"); - goto raise_error; - } - if (value == NULL) { - value = Py_None; - Py_INCREF(value); - } - #if PY_VERSION_HEX < 0x02050000 - if (!PyClass_Check(type)) - #else - if (!PyType_Check(type)) - #endif - { - if (value != Py_None) { - PyErr_SetString(PyExc_TypeError, - "instance exception may not have a separate value"); - goto raise_error; - } - Py_DECREF(value); - value = type; - #if PY_VERSION_HEX < 0x02050000 - if (PyInstance_Check(type)) { - type = (PyObject*) ((PyInstanceObject*)type)->in_class; - Py_INCREF(type); - } - else { - type = 0; - PyErr_SetString(PyExc_TypeError, - "raise: exception must be an old-style class or instance"); - goto raise_error; - } - #else - type = (PyObject*) Py_TYPE(type); - Py_INCREF(type); - if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { - PyErr_SetString(PyExc_TypeError, - "raise: exception class must be a subclass of BaseException"); - goto raise_error; - } - #endif - } - __Pyx_ErrRestore(type, value, tb); - return; -raise_error: - Py_XDECREF(value); - Py_XDECREF(type); - Py_XDECREF(tb); - return; -} -#else /* Python 3+ */ -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { - if (tb == Py_None) { - tb = 0; - } else if (tb && !PyTraceBack_Check(tb)) { - PyErr_SetString(PyExc_TypeError, - "raise: arg 3 must be a traceback or None"); - goto bad; - } - if (value == Py_None) - value = 0; - if (PyExceptionInstance_Check(type)) { - if (value) { - PyErr_SetString(PyExc_TypeError, - "instance exception may not have a separate value"); - goto bad; - } - value = type; - type = (PyObject*) Py_TYPE(value); - } else if (!PyExceptionClass_Check(type)) { - PyErr_SetString(PyExc_TypeError, - "raise: exception class must be a subclass of BaseException"); - goto bad; - } - if (cause) { - PyObject *fixed_cause; - if (PyExceptionClass_Check(cause)) { - fixed_cause = PyObject_CallObject(cause, NULL); - if (fixed_cause == NULL) - goto bad; - } - else if (PyExceptionInstance_Check(cause)) { - fixed_cause = cause; - Py_INCREF(fixed_cause); - } - else { - PyErr_SetString(PyExc_TypeError, - "exception causes must derive from " - "BaseException"); - goto bad; - } - if (!value) { - value = PyObject_CallObject(type, NULL); - } - PyException_SetCause(value, fixed_cause); - } - PyErr_SetObject(type, value); - if (tb) { - PyThreadState *tstate = PyThreadState_GET(); - PyObject* tmp_tb = tstate->curexc_traceback; - if (tb != tmp_tb) { - Py_INCREF(tb); - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_tb); - } - } -bad: - return; -} -#endif - -static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { - if (unlikely(!type)) { - PyErr_Format(PyExc_SystemError, "Missing type object"); - return 0; - } - if (likely(PyObject_TypeCheck(obj, type))) - return 1; - PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", - Py_TYPE(obj)->tp_name, type->tp_name); - return 0; -} - -static CYTHON_INLINE int __Pyx_CheckKeywordStrings( - PyObject *kwdict, - const char* function_name, - int kw_allowed) -{ - PyObject* key = 0; - Py_ssize_t pos = 0; - while (PyDict_Next(kwdict, &pos, &key, 0)) { - #if PY_MAJOR_VERSION < 3 - if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) - #else - if (unlikely(!PyUnicode_Check(key))) - #endif - goto invalid_keyword_type; - } - if ((!kw_allowed) && unlikely(key)) - goto invalid_keyword; - return 1; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%s() keywords must be strings", function_name); - return 0; -invalid_keyword: - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION < 3 - "%s() got an unexpected keyword argument '%s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); - #endif - return 0; -} - - - -static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) { - PyObject *local_type, *local_value, *local_tb; - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyThreadState *tstate = PyThreadState_GET(); - local_type = tstate->curexc_type; - local_value = tstate->curexc_value; - local_tb = tstate->curexc_traceback; - tstate->curexc_type = 0; - tstate->curexc_value = 0; - tstate->curexc_traceback = 0; - PyErr_NormalizeException(&local_type, &local_value, &local_tb); - if (unlikely(tstate->curexc_type)) - goto bad; - #if PY_MAJOR_VERSION >= 3 - if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) - goto bad; - #endif - *type = local_type; - *value = local_value; - *tb = local_tb; - Py_INCREF(local_type); - Py_INCREF(local_value); - Py_INCREF(local_tb); - tmp_type = tstate->exc_type; - tmp_value = tstate->exc_value; - tmp_tb = tstate->exc_traceback; - tstate->exc_type = local_type; - tstate->exc_value = local_value; - tstate->exc_traceback = local_tb; - /* Make sure tstate is in a consistent state when we XDECREF - these objects (XDECREF may run arbitrary code). */ - Py_XDECREF(tmp_type); - Py_XDECREF(tmp_value); - Py_XDECREF(tmp_tb); - return 0; -bad: - *type = 0; - *value = 0; - *tb = 0; - Py_XDECREF(local_type); - Py_XDECREF(local_value); - Py_XDECREF(local_tb); - return -1; -} - -static CYTHON_INLINE long __Pyx_div_long(long a, long b) { - long q = a / b; - long r = a - q*b; - q -= ((r != 0) & ((r ^ b) < 0)); - return q; -} - -static CYTHON_INLINE long __Pyx_mod_long(long a, long b) { - long r = a % b; - r += ((r != 0) & ((r ^ b) < 0)) * b; - return r; -} - -static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { - PyErr_Format(PyExc_ValueError, - "need more than %"PY_FORMAT_SIZE_T"d value%s to unpack", - index, (index == 1) ? "" : "s"); -} - -static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { - PyErr_Format(PyExc_ValueError, - "too many values to unpack (expected %"PY_FORMAT_SIZE_T"d)", expected); -} - -static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { - if (unlikely(retval)) { - Py_DECREF(retval); - __Pyx_RaiseTooManyValuesError(expected); - return -1; - } else if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) { - PyErr_Clear(); - return 0; - } else { - return -1; - } - } - return 0; -} - - - -static double __Pyx__PyObject_AsDouble(PyObject* obj) { - PyObject* float_value; - if (Py_TYPE(obj)->tp_as_number && Py_TYPE(obj)->tp_as_number->nb_float) { - return PyFloat_AsDouble(obj); - } else if (PyUnicode_CheckExact(obj) || PyBytes_CheckExact(obj)) { -#if PY_MAJOR_VERSION >= 3 - float_value = PyFloat_FromString(obj); -#else - float_value = PyFloat_FromString(obj, 0); -#endif - } else { - PyObject* args = PyTuple_New(1); - if (unlikely(!args)) goto bad; - PyTuple_SET_ITEM(args, 0, obj); - float_value = PyObject_Call((PyObject*)&PyFloat_Type, args, 0); - PyTuple_SET_ITEM(args, 0, 0); - Py_DECREF(args); - } - if (likely(float_value)) { - double value = PyFloat_AS_DOUBLE(float_value); - Py_DECREF(float_value); - return value; - } -bad: - return (double)-1; -} - -static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) { - PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname); -} - -static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, - const char *name, int exact) -{ - if (!type) { - PyErr_Format(PyExc_SystemError, "Missing type object"); - return 0; - } - if (none_allowed && obj == Py_None) return 1; - else if (exact) { - if (Py_TYPE(obj) == type) return 1; - } - else { - if (PyObject_TypeCheck(obj, type)) return 1; - } - PyErr_Format(PyExc_TypeError, - "Argument '%s' has incorrect type (expected %s, got %s)", - name, type->tp_name, Py_TYPE(obj)->tp_name); - return 0; -} - -static CYTHON_INLINE void __Pyx_RaiseNoneIndexingError(void) { - PyErr_SetString(PyExc_TypeError, "'NoneType' object is unsubscriptable"); -} - -static CYTHON_INLINE int __Pyx_div_int(int a, int b) { - int q = a / b; - int r = a - q*b; - q -= ((r != 0) & ((r ^ b) < 0)); - return q; -} - -static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) { - PyThreadState *tstate = PyThreadState_GET(); - *type = tstate->exc_type; - *value = tstate->exc_value; - *tb = tstate->exc_traceback; - Py_XINCREF(*type); - Py_XINCREF(*value); - Py_XINCREF(*tb); -} -static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) { - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyThreadState *tstate = PyThreadState_GET(); - tmp_type = tstate->exc_type; - tmp_value = tstate->exc_value; - tmp_tb = tstate->exc_traceback; - tstate->exc_type = type; - tstate->exc_value = value; - tstate->exc_traceback = tb; - Py_XDECREF(tmp_type); - Py_XDECREF(tmp_value); - Py_XDECREF(tmp_tb); -} - -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) { - PyObject *py_import = 0; - PyObject *empty_list = 0; - PyObject *module = 0; - PyObject *global_dict = 0; - PyObject *empty_dict = 0; - PyObject *list; - py_import = __Pyx_GetAttrString(__pyx_b, "__import__"); - if (!py_import) - goto bad; - if (from_list) - list = from_list; - else { - empty_list = PyList_New(0); - if (!empty_list) - goto bad; - list = empty_list; - } - global_dict = PyModule_GetDict(__pyx_m); - if (!global_dict) - goto bad; - empty_dict = PyDict_New(); - if (!empty_dict) - goto bad; - #if PY_VERSION_HEX >= 0x02050000 - { - #if PY_MAJOR_VERSION >= 3 - if (level == -1) { - if (strchr(__Pyx_MODULE_NAME, '.')) { - /* try package relative import first */ - PyObject *py_level = PyInt_FromLong(1); - if (!py_level) - goto bad; - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, py_level, NULL); - Py_DECREF(py_level); - if (!module) { - if (!PyErr_ExceptionMatches(PyExc_ImportError)) - goto bad; - PyErr_Clear(); - } - } - level = 0; /* try absolute import on failure */ - } - #endif - if (!module) { - PyObject *py_level = PyInt_FromLong(level); - if (!py_level) - goto bad; - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, py_level, NULL); - Py_DECREF(py_level); - } - } - #else - if (level>0) { - PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4."); - goto bad; - } - module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, NULL); - #endif -bad: - Py_XDECREF(empty_list); - Py_XDECREF(py_import); - Py_XDECREF(empty_dict); - return module; -} - -static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { - const unsigned char neg_one = (unsigned char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned char" : - "value too large to convert to unsigned char"); - } - return (unsigned char)-1; - } - return (unsigned char)val; - } - return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { - const unsigned short neg_one = (unsigned short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned short" : - "value too large to convert to unsigned short"); - } - return (unsigned short)-1; - } - return (unsigned short)val; - } - return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { - const unsigned int neg_one = (unsigned int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(unsigned int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to unsigned int" : - "value too large to convert to unsigned int"); - } - return (unsigned int)-1; - } - return (unsigned int)val; - } - return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); -} - -static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) { - const char neg_one = (char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to char" : - "value too large to convert to char"); - } - return (char)-1; - } - return (char)val; - } - return (char)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) { - const short neg_one = (short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to short" : - "value too large to convert to short"); - } - return (short)-1; - } - return (short)val; - } - return (short)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) { - const int neg_one = (int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to int" : - "value too large to convert to int"); - } - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { - const signed char neg_one = (signed char)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed char)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed char" : - "value too large to convert to signed char"); - } - return (signed char)-1; - } - return (signed char)val; - } - return (signed char)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { - const signed short neg_one = (signed short)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed short)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed short" : - "value too large to convert to signed short"); - } - return (signed short)-1; - } - return (signed short)val; - } - return (signed short)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { - const signed int neg_one = (signed int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(signed int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to signed int" : - "value too large to convert to signed int"); - } - return (signed int)-1; - } - return (signed int)val; - } - return (signed int)__Pyx_PyInt_AsSignedLong(x); -} - -static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) { - const int neg_one = (int)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (!unlikely(val == -1 && PyErr_Occurred())) { - PyErr_SetString(PyExc_OverflowError, - (is_unsigned && unlikely(val < 0)) ? - "can't convert negative value to int" : - "value too large to convert to int"); - } - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - -static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { - const unsigned long neg_one = (unsigned long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return (unsigned long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return (unsigned long)PyLong_AsUnsignedLong(x); - } else { - return (unsigned long)PyLong_AsLong(x); - } - } else { - unsigned long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned long)-1; - val = __Pyx_PyInt_AsUnsignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { - const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { - return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - unsigned PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsUnsignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { - const long neg_one = (long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to long"); - return (long)-1; - } - return (long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to long"); - return (long)-1; - } - return (long)PyLong_AsUnsignedLong(x); - } else { - return (long)PyLong_AsLong(x); - } - } else { - long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (long)-1; - val = __Pyx_PyInt_AsLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { - const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG)-1; - } - return (PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to PY_LONG_LONG"); - return (PY_LONG_LONG)-1; - } - return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { - return (PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { - const signed long neg_one = (signed long)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed long"); - return (signed long)-1; - } - return (signed long)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed long"); - return (signed long)-1; - } - return (signed long)PyLong_AsUnsignedLong(x); - } else { - return (signed long)PyLong_AsLong(x); - } - } else { - signed long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed long)-1; - val = __Pyx_PyInt_AsSignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { - const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed PY_LONG_LONG"); - return (signed PY_LONG_LONG)-1; - } - return (signed PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to signed PY_LONG_LONG"); - return (signed PY_LONG_LONG)-1; - } - return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); - } else { - return (signed PY_LONG_LONG)PyLong_AsLongLong(x); - } - } else { - signed PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsSignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static void __Pyx_WriteUnraisable(const char *name, int clineno, - int lineno, const char *filename) { - PyObject *old_exc, *old_val, *old_tb; - PyObject *ctx; - __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); - #if PY_MAJOR_VERSION < 3 - ctx = PyString_FromString(name); - #else - ctx = PyUnicode_FromString(name); - #endif - __Pyx_ErrRestore(old_exc, old_val, old_tb); - if (!ctx) { - PyErr_WriteUnraisable(Py_None); - } else { - PyErr_WriteUnraisable(ctx); - Py_DECREF(ctx); - } -} - -static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) { - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyThreadState *tstate = PyThreadState_GET(); - tmp_type = tstate->exc_type; - tmp_value = tstate->exc_value; - tmp_tb = tstate->exc_traceback; - tstate->exc_type = *type; - tstate->exc_value = *value; - tstate->exc_traceback = *tb; - *type = tmp_type; - *value = tmp_value; - *tb = tmp_tb; -} - -static PyObject *__Pyx_Generator_Next(PyObject *self); -static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value); -static PyObject *__Pyx_Generator_Close(PyObject *self); -static PyObject *__Pyx_Generator_Throw(PyObject *gen, PyObject *args); -static CYTHON_INLINE -void __Pyx_Generator_ExceptionClear(__pyx_GeneratorObject *self) -{ - PyObject *exc_type = self->exc_type; - PyObject *exc_value = self->exc_value; - PyObject *exc_traceback = self->exc_traceback; - self->exc_type = NULL; - self->exc_value = NULL; - self->exc_traceback = NULL; - Py_XDECREF(exc_type); - Py_XDECREF(exc_value); - Py_XDECREF(exc_traceback); -} -static CYTHON_INLINE -PyObject *__Pyx_Generator_SendEx(__pyx_GeneratorObject *self, PyObject *value) -{ - PyObject *retval; - if (unlikely(self->is_running)) { - PyErr_SetString(PyExc_ValueError, - "generator already executing"); - return NULL; - } - if (unlikely(self->resume_label == 0)) { - if (unlikely(value && value != Py_None)) { - PyErr_SetString(PyExc_TypeError, - "can't send non-None value to a " - "just-started generator"); - return NULL; - } - } - if (unlikely(self->resume_label == -1)) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - if (value) - __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, &self->exc_traceback); - else - __Pyx_Generator_ExceptionClear(self); - self->is_running = 1; - retval = self->body((PyObject *) self, value); - self->is_running = 0; - if (retval) - __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, &self->exc_traceback); - else - __Pyx_Generator_ExceptionClear(self); - return retval; -} -static PyObject *__Pyx_Generator_Next(PyObject *self) -{ - return __Pyx_Generator_SendEx((__pyx_GeneratorObject *) self, Py_None); -} -static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value) -{ - return __Pyx_Generator_SendEx((__pyx_GeneratorObject *) self, value); -} -static PyObject *__Pyx_Generator_Close(PyObject *self) -{ - __pyx_GeneratorObject *generator = (__pyx_GeneratorObject *) self; - PyObject *retval; -#if PY_VERSION_HEX < 0x02050000 - PyErr_SetNone(PyExc_StopIteration); -#else - PyErr_SetNone(PyExc_GeneratorExit); -#endif - retval = __Pyx_Generator_SendEx(generator, NULL); - if (retval) { - Py_DECREF(retval); - PyErr_SetString(PyExc_RuntimeError, - "generator ignored GeneratorExit"); - return NULL; - } -#if PY_VERSION_HEX < 0x02050000 - if (PyErr_ExceptionMatches(PyExc_StopIteration)) -#else - if (PyErr_ExceptionMatches(PyExc_StopIteration) - || PyErr_ExceptionMatches(PyExc_GeneratorExit)) -#endif - { - PyErr_Clear(); /* ignore these errors */ - Py_INCREF(Py_None); - return Py_None; - } - return NULL; -} -static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args) -{ - __pyx_GeneratorObject *generator = (__pyx_GeneratorObject *) self; - PyObject *typ; - PyObject *tb = NULL; - PyObject *val = NULL; - if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb)) - return NULL; - __Pyx_Raise(typ, val, tb, NULL); - return __Pyx_Generator_SendEx(generator, NULL); -} -static int -__Pyx_Generator_traverse(PyObject *self, visitproc visit, void *arg) -{ - __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; - Py_VISIT(gen->closure); - Py_VISIT(gen->classobj); - Py_VISIT(gen->exc_type); - Py_VISIT(gen->exc_value); - Py_VISIT(gen->exc_traceback); - return 0; -} -static void -__Pyx_Generator_dealloc(PyObject *self) -{ - __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; - PyObject_GC_UnTrack(gen); - if (gen->gi_weakreflist != NULL) - PyObject_ClearWeakRefs(self); - PyObject_GC_Track(self); - if (gen->resume_label > 0) { - Py_TYPE(gen)->tp_del(self); - if (self->ob_refcnt > 0) - return; /* resurrected. :( */ - } - PyObject_GC_UnTrack(self); - Py_CLEAR(gen->closure); - Py_CLEAR(gen->classobj); - Py_CLEAR(gen->exc_type); - Py_CLEAR(gen->exc_value); - Py_CLEAR(gen->exc_traceback); - PyObject_GC_Del(gen); -} -static void -__Pyx_Generator_del(PyObject *self) -{ - PyObject *res; - PyObject *error_type, *error_value, *error_traceback; - __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; - if (gen->resume_label <= 0) - return ; - assert(self->ob_refcnt == 0); - self->ob_refcnt = 1; - __Pyx_ErrFetch(&error_type, &error_value, &error_traceback); - res = __Pyx_Generator_Close(self); - if (res == NULL) - PyErr_WriteUnraisable(self); - else - Py_DECREF(res); - __Pyx_ErrRestore(error_type, error_value, error_traceback); - /* Undo the temporary resurrection; can't use DECREF here, it would - * cause a recursive call. - */ - assert(self->ob_refcnt > 0); - if (--self->ob_refcnt == 0) - return; /* this is the normal path out */ - /* close() resurrected it! Make it look like the original Py_DECREF - * never happened. - */ - { - Py_ssize_t refcnt = self->ob_refcnt; - _Py_NewReference(self); - self->ob_refcnt = refcnt; - } - assert(PyType_IS_GC(self->ob_type) && - _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED); - /* If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so - * we need to undo that. */ - _Py_DEC_REFTOTAL; - /* If Py_TRACE_REFS, _Py_NewReference re-added self to the object - * chain, so no more to do there. - * If COUNT_ALLOCS, the original decref bumped tp_frees, and - * _Py_NewReference bumped tp_allocs: both of those need to be - * undone. - */ -#ifdef COUNT_ALLOCS - --self->ob_type->tp_frees; - --self->ob_type->tp_allocs; -#endif -} -static PyMemberDef __pyx_Generator_memberlist[] = { - {(char *) "gi_running", - T_INT, - offsetof(__pyx_GeneratorObject, is_running), - READONLY, - NULL}, - {0, 0, 0, 0, 0} -}; -static PyMethodDef __pyx_Generator_methods[] = { - {__Pyx_NAMESTR("send"), (PyCFunction) __Pyx_Generator_Send, METH_O, 0}, - {__Pyx_NAMESTR("throw"), (PyCFunction) __Pyx_Generator_Throw, METH_VARARGS, 0}, - {__Pyx_NAMESTR("close"), (PyCFunction) __Pyx_Generator_Close, METH_NOARGS, 0}, - {0, 0, 0, 0} -}; -static PyTypeObject __pyx_GeneratorType = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("generator"), /*tp_name*/ - sizeof(__pyx_GeneratorObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - (destructor) __Pyx_Generator_dealloc,/*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ -#if PY_MAJOR_VERSION < 3 - 0, /*tp_compare*/ -#else - 0, /*reserved*/ -#endif - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - PyObject_GenericGetAttr, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags*/ - 0, /*tp_doc*/ - (traverseproc) __Pyx_Generator_traverse, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - offsetof(__pyx_GeneratorObject, gi_weakreflist), /* tp_weaklistoffse */ - PyObject_SelfIter, /*tp_iter*/ - (iternextfunc) __Pyx_Generator_Next, /*tp_iternext*/ - __pyx_Generator_methods, /*tp_methods*/ - __pyx_Generator_memberlist, /*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*/ - 0, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ - __Pyx_Generator_del, /*tp_del*/ -#if PY_VERSION_HEX >= 0x02060000 - 0, /*tp_version_tag*/ -#endif -}; -static -__pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body, - PyObject *closure) -{ - __pyx_GeneratorObject *gen = - PyObject_GC_New(__pyx_GeneratorObject, &__pyx_GeneratorType); - if (gen == NULL) - return NULL; - gen->body = body; - gen->closure = closure; - Py_XINCREF(closure); - gen->is_running = 0; - gen->resume_label = 0; - gen->classobj = NULL; - gen->exc_type = NULL; - gen->exc_value = NULL; - gen->exc_traceback = NULL; - gen->gi_weakreflist = NULL; - PyObject_GC_Track(gen); - return gen; -} -static int __pyx_Generator_init(void) -{ - return PyType_Ready(&__pyx_GeneratorType); -} - -static int __Pyx_check_binary_version(void) { - char ctversion[4], rtversion[4]; - PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); - PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); - if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { - char message[200]; - PyOS_snprintf(message, sizeof(message), - "compiletime version %s of module '%.100s' " - "does not match runtime version %s", - ctversion, __Pyx_MODULE_NAME, rtversion); - #if PY_VERSION_HEX < 0x02050000 - return PyErr_Warn(NULL, message); - #else - return PyErr_WarnEx(NULL, message, 1); - #endif - } - return 0; -} - -static int __Pyx_SetVtable(PyObject *dict, void *vtable) { -#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) - PyObject *ob = PyCapsule_New(vtable, 0, 0); -#else - PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); -#endif - if (!ob) - goto bad; - if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0) - goto bad; - Py_DECREF(ob); - return 0; -bad: - Py_XDECREF(ob); - return -1; -} - -static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { - int start = 0, mid = 0, end = count - 1; - if (end >= 0 && code_line > entries[end].code_line) { - return count; - } - while (start < end) { - mid = (start + end) / 2; - if (code_line < entries[mid].code_line) { - end = mid; - } else if (code_line > entries[mid].code_line) { - start = mid + 1; - } else { - return mid; - } - } - if (code_line <= entries[mid].code_line) { - return mid; - } else { - return mid + 1; - } -} -static PyCodeObject *__pyx_find_code_object(int code_line) { - PyCodeObject* code_object; - int pos; - if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { - return NULL; - } - pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); - if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { - return NULL; - } - code_object = __pyx_code_cache.entries[pos].code_object; - Py_INCREF(code_object); - return code_object; -} -static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { - int pos, i; - __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; - if (unlikely(!code_line)) { - return; - } - if (unlikely(!entries)) { - entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); - if (likely(entries)) { - __pyx_code_cache.entries = entries; - __pyx_code_cache.max_count = 64; - __pyx_code_cache.count = 1; - entries[0].code_line = code_line; - entries[0].code_object = code_object; - Py_INCREF(code_object); - } - return; - } - pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); - if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { - PyCodeObject* tmp = entries[pos].code_object; - entries[pos].code_object = code_object; - Py_DECREF(tmp); - return; - } - if (__pyx_code_cache.count == __pyx_code_cache.max_count) { - int new_max = __pyx_code_cache.max_count + 64; - entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( - __pyx_code_cache.entries, new_max*sizeof(__Pyx_CodeObjectCacheEntry)); - if (unlikely(!entries)) { - return; - } - __pyx_code_cache.entries = entries; - __pyx_code_cache.max_count = new_max; - } - for (i=__pyx_code_cache.count; i>pos; i--) { - entries[i] = entries[i-1]; - } - entries[pos].code_line = code_line; - entries[pos].code_object = code_object; - __pyx_code_cache.count++; - Py_INCREF(code_object); -} - -#include "compile.h" -#include "frameobject.h" -#include "traceback.h" -static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( - const char *funcname, int c_line, - int py_line, const char *filename) { - PyCodeObject *py_code = 0; - PyObject *py_srcfile = 0; - PyObject *py_funcname = 0; - #if PY_MAJOR_VERSION < 3 - py_srcfile = PyString_FromString(filename); - #else - py_srcfile = PyUnicode_FromString(filename); - #endif - if (!py_srcfile) goto bad; - if (c_line) { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); - #else - py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); - #endif - } - else { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromString(funcname); - #else - py_funcname = PyUnicode_FromString(funcname); - #endif - } - if (!py_funcname) goto bad; - py_code = __Pyx_PyCode_New( - 0, /*int argcount,*/ - 0, /*int kwonlyargcount,*/ - 0, /*int nlocals,*/ - 0, /*int stacksize,*/ - 0, /*int flags,*/ - __pyx_empty_bytes, /*PyObject *code,*/ - __pyx_empty_tuple, /*PyObject *consts,*/ - __pyx_empty_tuple, /*PyObject *names,*/ - __pyx_empty_tuple, /*PyObject *varnames,*/ - __pyx_empty_tuple, /*PyObject *freevars,*/ - __pyx_empty_tuple, /*PyObject *cellvars,*/ - py_srcfile, /*PyObject *filename,*/ - py_funcname, /*PyObject *name,*/ - py_line, /*int firstlineno,*/ - __pyx_empty_bytes /*PyObject *lnotab*/ - ); - Py_DECREF(py_srcfile); - Py_DECREF(py_funcname); - return py_code; -bad: - Py_XDECREF(py_srcfile); - Py_XDECREF(py_funcname); - return NULL; -} -static void __Pyx_AddTraceback(const char *funcname, int c_line, - int py_line, const char *filename) { - PyCodeObject *py_code = 0; - PyObject *py_globals = 0; - PyFrameObject *py_frame = 0; - py_code = __pyx_find_code_object(c_line ? c_line : py_line); - if (!py_code) { - py_code = __Pyx_CreateCodeObjectForTraceback( - funcname, c_line, py_line, filename); - if (!py_code) goto bad; - __pyx_insert_code_object(c_line ? c_line : py_line, py_code); - } - py_globals = PyModule_GetDict(__pyx_m); - if (!py_globals) goto bad; - py_frame = PyFrame_New( - PyThreadState_GET(), /*PyThreadState *tstate,*/ - py_code, /*PyCodeObject *code,*/ - py_globals, /*PyObject *globals,*/ - 0 /*PyObject *locals*/ - ); - if (!py_frame) goto bad; - py_frame->f_lineno = py_line; - PyTraceBack_Here(py_frame); -bad: - Py_XDECREF(py_code); - Py_XDECREF(py_frame); -} - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { - while (t->p) { - #if PY_MAJOR_VERSION < 3 - if (t->is_unicode) { - *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); - } else if (t->intern) { - *t->p = PyString_InternFromString(t->s); - } else { - *t->p = PyString_FromStringAndSize(t->s, t->n - 1); - } - #else /* Python 3+ has unicode identifiers */ - if (t->is_unicode | t->is_str) { - if (t->intern) { - *t->p = PyUnicode_InternFromString(t->s); - } else if (t->encoding) { - *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); - } else { - *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); - } - } else { - *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); - } - #endif - if (!*t->p) - return -1; - ++t; - } - return 0; -} - - -/* Type Conversion Functions */ - -static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { - int is_true = x == Py_True; - if (is_true | (x == Py_False) | (x == Py_None)) return is_true; - else return PyObject_IsTrue(x); -} - -static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { - PyNumberMethods *m; - const char *name = NULL; - PyObject *res = NULL; -#if PY_VERSION_HEX < 0x03000000 - if (PyInt_Check(x) || PyLong_Check(x)) -#else - if (PyLong_Check(x)) -#endif - return Py_INCREF(x), x; - m = Py_TYPE(x)->tp_as_number; -#if PY_VERSION_HEX < 0x03000000 - if (m && m->nb_int) { - name = "int"; - res = PyNumber_Int(x); - } - else if (m && m->nb_long) { - name = "long"; - res = PyNumber_Long(x); - } -#else - if (m && m->nb_int) { - name = "int"; - res = PyNumber_Long(x); - } -#endif - if (res) { -#if PY_VERSION_HEX < 0x03000000 - if (!PyInt_Check(res) && !PyLong_Check(res)) { -#else - if (!PyLong_Check(res)) { -#endif - PyErr_Format(PyExc_TypeError, - "__%s__ returned non-%s (type %.200s)", - name, name, Py_TYPE(res)->tp_name); - Py_DECREF(res); - return NULL; - } - } - else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, - "an integer is required"); - } - return res; -} - -static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { - Py_ssize_t ival; - PyObject* x = PyNumber_Index(b); - if (!x) return -1; - ival = PyInt_AsSsize_t(x); - Py_DECREF(x); - return ival; -} - -static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { -#if PY_VERSION_HEX < 0x02050000 - if (ival <= LONG_MAX) - return PyInt_FromLong((long)ival); - else { - unsigned char *bytes = (unsigned char *) &ival; - int one = 1; int little = (int)*(unsigned char*)&one; - return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); - } -#else - return PyInt_FromSize_t(ival); -#endif -} - -static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { - unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); - if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { - return (size_t)-1; - } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to size_t"); - return (size_t)-1; - } - return (size_t)val; -} - - -#endif /* Py_PYTHON_H */ diff --git a/python/src/sa/_cdec_sa.pyx b/python/src/sa/_cdec_sa.pyx deleted file mode 100644 index 710f8cb4..00000000 --- a/python/src/sa/_cdec_sa.pyx +++ /dev/null @@ -1,29 +0,0 @@ -import logging -import resource -import gzip - -cdef float monitor_cpu(): - return (resource.getrusage(resource.RUSAGE_SELF).ru_utime+ - resource.getrusage(resource.RUSAGE_SELF).ru_stime) - -def gzip_or_text(char* filename): - if filename.endswith('.gz'): - return gzip.GzipFile(filename) - else: - return open(filename) - -logger = logging.getLogger('cdec.sa') - -include "float_list.pxi" -include "int_list.pxi" -include "str_map.pxi" -include "data_array.pxi" -include "alignment.pxi" -include "bilex.pxi" -include "veb.pxi" -include "lcp.pxi" -include "sym.pxi" -include "rule.pxi" -include "precomputation.pxi" -include "suffix_array.pxi" -include "rulefactory.pxi" diff --git a/python/src/sa/_sa.c b/python/src/sa/_sa.c new file mode 100644 index 00000000..34f170bf --- /dev/null +++ b/python/src/sa/_sa.c @@ -0,0 +1,63140 @@ +/* Generated by Cython 0.17.beta1 on Fri Jul 27 22:15:31 2012 */ + +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#ifndef Py_PYTHON_H + #error Python headers needed to compile C extensions, please install development version of Python. +#elif PY_VERSION_HEX < 0x02040000 + #error Cython requires Python 2.4+. +#else +#include /* For offsetof */ +#ifndef offsetof +#define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) +#endif + +#if !defined(WIN32) && !defined(MS_WINDOWS) + #ifndef __stdcall + #define __stdcall + #endif + #ifndef __cdecl + #define __cdecl + #endif + #ifndef __fastcall + #define __fastcall + #endif +#endif + +#ifndef DL_IMPORT + #define DL_IMPORT(t) t +#endif +#ifndef DL_EXPORT + #define DL_EXPORT(t) t +#endif + +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif + +#ifndef Py_HUGE_VAL + #define Py_HUGE_VAL HUGE_VAL +#endif + +#ifdef PYPY_VERSION +#define CYTHON_COMPILING_IN_PYPY 1 +#define CYTHON_COMPILING_IN_CPYTHON 0 +#else +#define CYTHON_COMPILING_IN_PYPY 0 +#define CYTHON_COMPILING_IN_CPYTHON 1 +#endif + +#if PY_VERSION_HEX < 0x02050000 + typedef int Py_ssize_t; + #define PY_SSIZE_T_MAX INT_MAX + #define PY_SSIZE_T_MIN INT_MIN + #define PY_FORMAT_SIZE_T "" + #define PyInt_FromSsize_t(z) PyInt_FromLong(z) + #define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o) + #define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \ + (PyErr_Format(PyExc_TypeError, \ + "expected index value, got %.200s", Py_TYPE(o)->tp_name), \ + (PyObject*)0)) + #define PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && !PyComplex_Check(o)) + #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message) + #define __PYX_BUILD_PY_SSIZE_T "i" +#else + #define __PYX_BUILD_PY_SSIZE_T "n" +#endif + +#if PY_VERSION_HEX < 0x02060000 + #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) + #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) + #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) + #define PyVarObject_HEAD_INIT(type, size) \ + PyObject_HEAD_INIT(type) size, + #define PyType_Modified(t) + + typedef struct { + void *buf; + PyObject *obj; + Py_ssize_t len; + Py_ssize_t itemsize; + int readonly; + int ndim; + char *format; + Py_ssize_t *shape; + Py_ssize_t *strides; + Py_ssize_t *suboffsets; + void *internal; + } Py_buffer; + + #define PyBUF_SIMPLE 0 + #define PyBUF_WRITABLE 0x0001 + #define PyBUF_FORMAT 0x0004 + #define PyBUF_ND 0x0008 + #define PyBUF_STRIDES (0x0010 | PyBUF_ND) + #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) + #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) + #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) + #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) + #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE) + #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE) + + typedef int (*getbufferproc)(PyObject *, Py_buffer *, int); + typedef void (*releasebufferproc)(PyObject *, Py_buffer *); +#endif + +#if PY_MAJOR_VERSION < 3 + #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ + PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else + #define __Pyx_BUILTIN_MODULE_NAME "builtins" + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ + PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#endif + +#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6 + #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict") +#endif + +#if PY_MAJOR_VERSION >= 3 + #define Py_TPFLAGS_CHECKTYPES 0 + #define Py_TPFLAGS_HAVE_INDEX 0 +#endif + +#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) + #define Py_TPFLAGS_HAVE_NEWBUFFER 0 +#endif + + +#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) + #define CYTHON_PEP393_ENABLED 1 + #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ? \ + 0 : _PyUnicode_Ready((PyObject *)(op))) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) + #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) +#else + #define CYTHON_PEP393_ENABLED 0 + #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) + + #define __Pyx_PyUnicode_READ(k, d, i) ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i])) +#endif + +#if PY_MAJOR_VERSION >= 3 + #define PyBaseString_Type PyUnicode_Type + #define PyStringObject PyUnicodeObject + #define PyString_Type PyUnicode_Type + #define PyString_Check PyUnicode_Check + #define PyString_CheckExact PyUnicode_CheckExact +#endif + +#if PY_VERSION_HEX < 0x02060000 + #define PyBytesObject PyStringObject + #define PyBytes_Type PyString_Type + #define PyBytes_Check PyString_Check + #define PyBytes_CheckExact PyString_CheckExact + #define PyBytes_FromString PyString_FromString + #define PyBytes_FromStringAndSize PyString_FromStringAndSize + #define PyBytes_FromFormat PyString_FromFormat + #define PyBytes_DecodeEscape PyString_DecodeEscape + #define PyBytes_AsString PyString_AsString + #define PyBytes_AsStringAndSize PyString_AsStringAndSize + #define PyBytes_Size PyString_Size + #define PyBytes_AS_STRING PyString_AS_STRING + #define PyBytes_GET_SIZE PyString_GET_SIZE + #define PyBytes_Repr PyString_Repr + #define PyBytes_Concat PyString_Concat + #define PyBytes_ConcatAndDel PyString_ConcatAndDel +#endif + +#if PY_VERSION_HEX < 0x02060000 + #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) + #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type) +#endif +#ifndef PySet_CheckExact + #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) +#endif + +#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) + +#if PY_MAJOR_VERSION >= 3 + #define PyIntObject PyLongObject + #define PyInt_Type PyLong_Type + #define PyInt_Check(op) PyLong_Check(op) + #define PyInt_CheckExact(op) PyLong_CheckExact(op) + #define PyInt_FromString PyLong_FromString + #define PyInt_FromUnicode PyLong_FromUnicode + #define PyInt_FromLong PyLong_FromLong + #define PyInt_FromSize_t PyLong_FromSize_t + #define PyInt_FromSsize_t PyLong_FromSsize_t + #define PyInt_AsLong PyLong_AsLong + #define PyInt_AS_LONG PyLong_AS_LONG + #define PyInt_AsSsize_t PyLong_AsSsize_t + #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask + #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask +#endif + +#if PY_MAJOR_VERSION >= 3 + #define PyBoolObject PyLongObject +#endif + +#if PY_VERSION_HEX < 0x03020000 + typedef long Py_hash_t; + #define __Pyx_PyInt_FromHash_t PyInt_FromLong + #define __Pyx_PyInt_AsHash_t PyInt_AsLong +#else + #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t + #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t +#endif + +#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300) + #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b) + #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value) + #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b) +#else + #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \ + (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \ + (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \ + (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0))) + #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \ + (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ + (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \ + (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1))) + #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \ + (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ + (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \ + (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1))) +#endif + +#if PY_MAJOR_VERSION >= 3 + #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) +#endif + +#if PY_VERSION_HEX < 0x02050000 + #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) + #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) + #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) +#else + #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) + #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) + #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) +#endif + +#if PY_VERSION_HEX < 0x02050000 + #define __Pyx_NAMESTR(n) ((char *)(n)) + #define __Pyx_DOCSTR(n) ((char *)(n)) +#else + #define __Pyx_NAMESTR(n) (n) + #define __Pyx_DOCSTR(n) (n) +#endif + +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) +#else + #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) +#endif + +#ifndef __PYX_EXTERN_C + #ifdef __cplusplus + #define __PYX_EXTERN_C extern "C" + #else + #define __PYX_EXTERN_C extern + #endif +#endif + +#if defined(WIN32) || defined(MS_WINDOWS) +#define _USE_MATH_DEFINES +#endif +#include +#define __PYX_HAVE___sa +#define __PYX_HAVE_API___sa +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "strmap.h" +#include "math.h" +#ifdef _OPENMP +#include +#endif /* _OPENMP */ + +#ifdef PYREX_WITHOUT_ASSERTIONS +#define CYTHON_WITHOUT_ASSERTIONS +#endif + + +/* inline attribute */ +#ifndef CYTHON_INLINE + #if defined(__GNUC__) + #define CYTHON_INLINE __inline__ + #elif defined(_MSC_VER) + #define CYTHON_INLINE __inline + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_INLINE inline + #else + #define CYTHON_INLINE + #endif +#endif + +/* unused attribute */ +#ifndef CYTHON_UNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +#endif + +typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ + + +/* Type Conversion Predeclarations */ + +#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s) +#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s)) + +#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None) +#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); +static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); + +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); +static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); + +#if CYTHON_COMPILING_IN_CPYTHON +#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) +#else +#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) +#endif +#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) + +#ifdef __GNUC__ + /* Test for GCC > 2.95 */ + #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) + #define likely(x) __builtin_expect(!!(x), 1) + #define unlikely(x) __builtin_expect(!!(x), 0) + #else /* __GNUC__ > 2 ... */ + #define likely(x) (x) + #define unlikely(x) (x) + #endif /* __GNUC__ > 2 ... */ +#else /* __GNUC__ */ + #define likely(x) (x) + #define unlikely(x) (x) +#endif /* __GNUC__ */ + +static PyObject *__pyx_m; +static PyObject *__pyx_b; +static PyObject *__pyx_empty_tuple; +static PyObject *__pyx_empty_bytes; +static int __pyx_lineno; +static int __pyx_clineno = 0; +static const char * __pyx_cfilenm= __FILE__; +static const char *__pyx_filename; + + +static const char *__pyx_f[] = { + "_sa.pyx", + "float_list.pxi", + "int_list.pxi", + "data_array.pxi", + "alignment.pxi", + "bilex.pxi", + "veb.pxi", + "rule.pxi", + "rulefactory.pxi", + "lcp.pxi", + "sym.pxi", + "_sa.pxd", + "precomputation.pxi", + "suffix_array.pxi", + "str_map.pxi", +}; + +/*--- Type declarations ---*/ +struct __pyx_obj_3_sa_HieroCachingRuleFactory; +struct __pyx_obj_3_sa_IntList; +struct __pyx_obj_3_sa_VEBIterator; +struct __pyx_obj_3_sa_BiLex; +struct __pyx_obj_3_sa_VEB; +struct __pyx_obj_3_sa_LCP; +struct __pyx_obj_3_sa_DataArray; +struct __pyx_obj_3_sa_BitSetIterator; +struct __pyx_obj_3_sa_Precomputation; +struct __pyx_obj_3_sa_SuffixArray; +struct __pyx_obj_3_sa_Alphabet; +struct __pyx_obj_3_sa_Rule; +struct __pyx_obj_3_sa_PhraseLocation; +struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats; +struct __pyx_obj_3_sa___pyx_scope_struct_2_input; +struct __pyx_obj_3_sa_Alignment; +struct __pyx_obj_3_sa_BitSet; +struct __pyx_obj_3_sa_Sampler; +struct __pyx_obj_3_sa_StringMap; +struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__; +struct __pyx_obj_3_sa_TrieNode; +struct __pyx_obj_3_sa_ExtendedTrieNode; +struct __pyx_obj_3_sa_TrieMap; +struct __pyx_obj_3_sa_Phrase; +struct __pyx_obj_3_sa_TrieTable; +struct __pyx_obj_3_sa_FloatList; +struct __pyx_t_3_sa__node; +struct __pyx_t_3_sa__BitSet; +struct __pyx_t_3_sa__VEB; +struct __pyx_t_3_sa__Trie_Edge; +struct __pyx_t_3_sa__Trie_Node; +struct __pyx_t_3_sa_match_node; +struct __pyx_t_3_sa_Matching; + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":9 + * from libc.string cimport memset, strcpy, strlen + * + * cdef struct _node: # <<<<<<<<<<<<<< + * _node* smaller + * _node* bigger + */ +struct __pyx_t_3_sa__node { + struct __pyx_t_3_sa__node *smaller; + struct __pyx_t_3_sa__node *bigger; + int key; + int val; +}; + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":30 + * _init_lower_mask() + * + * cdef struct _BitSet: # <<<<<<<<<<<<<< + * long bitset + * int min_val + */ +struct __pyx_t_3_sa__BitSet { + long bitset; + int min_val; + int max_val; + int size; +}; + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":168 + * return result + * + * cdef struct _VEB: # <<<<<<<<<<<<<< + * int top_universe_size + * int num_bottom_bits + */ +struct __pyx_t_3_sa__VEB { + int top_universe_size; + int num_bottom_bits; + int max_val; + int min_val; + int size; + void *top; + void **bottom; +}; + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":10 + * cdef struct _Trie_Node # forward decl + * + * cdef struct _Trie_Edge: # <<<<<<<<<<<<<< + * int val + * _Trie_Node* node + */ +struct __pyx_t_3_sa__Trie_Edge { + int val; + struct __pyx_t_3_sa__Trie_Node *node; + struct __pyx_t_3_sa__Trie_Edge *bigger; + struct __pyx_t_3_sa__Trie_Edge *smaller; +}; + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":8 + * from libc.string cimport memset, memcpy + * + * cdef struct _Trie_Node # forward decl # <<<<<<<<<<<<<< + * + * cdef struct _Trie_Edge: + */ +struct __pyx_t_3_sa__Trie_Node { + struct __pyx_t_3_sa__Trie_Edge *root; + int *arr; + int arr_len; +}; + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":48 + * + * # linked list structure for storing matches in BaselineRuleFactory + * cdef struct match_node: # <<<<<<<<<<<<<< + * int* match + * match_node* next + */ +struct __pyx_t_3_sa_match_node { + int *match; + struct __pyx_t_3_sa_match_node *next; +}; + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":145 + * + * # struct used to encapsulate a single matching + * cdef struct Matching: # <<<<<<<<<<<<<< + * int* arr + * int start + */ +struct __pyx_t_3_sa_Matching { + int *arr; + int start; + int end; + int sent_id; + int size; +}; + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":201 + * + * + * cdef class HieroCachingRuleFactory: # <<<<<<<<<<<<<< + * '''This RuleFactory implements a caching + * method using TrieTable, which makes phrase + */ +struct __pyx_obj_3_sa_HieroCachingRuleFactory { + PyObject_HEAD + struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *__pyx_vtab; + struct __pyx_obj_3_sa_TrieTable *rules; + struct __pyx_obj_3_sa_Sampler *sampler; + int max_chunks; + int max_target_chunks; + int max_length; + int max_target_length; + int max_nonterminals; + int max_initial_size; + int train_max_initial_size; + int min_gap_size; + int train_min_gap_size; + int category; + PyObject *precomputed_index; + PyObject *precomputed_collocations; + PyObject *precompute_file; + PyObject *max_rank; + int precompute_rank; + int precompute_secondary_rank; + int use_baeza_yates; + int use_index; + int use_collocations; + float by_slack_factor; + PyObject *prev_norm_prefix; + float extract_time; + struct __pyx_obj_3_sa_SuffixArray *fsa; + struct __pyx_obj_3_sa_DataArray *fda; + struct __pyx_obj_3_sa_DataArray *eda; + struct __pyx_obj_3_sa_Alignment *alignment; + struct __pyx_obj_3_sa_IntList *eid2symid; + struct __pyx_obj_3_sa_IntList *fid2symid; + int tight_phrases; + int require_aligned_terminal; + int require_aligned_chunks; + struct __pyx_obj_3_sa_IntList *findexes; + struct __pyx_obj_3_sa_IntList *findexes1; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":9 + * from libc.string cimport memset, memcpy + * + * cdef class IntList: # <<<<<<<<<<<<<< + * cdef int size + * cdef int increment + */ +struct __pyx_obj_3_sa_IntList { + PyObject_HEAD + struct __pyx_vtabstruct_3_sa_IntList *__pyx_vtab; + int size; + int increment; + int len; + int *arr; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":340 + * + * + * cdef class VEBIterator: # <<<<<<<<<<<<<< + * cdef _VEB* v + * cdef int next_val + */ +struct __pyx_obj_3_sa_VEBIterator { + PyObject_HEAD + struct __pyx_t_3_sa__VEB *v; + int next_val; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":47 + * + * + * cdef class BiLex: # <<<<<<<<<<<<<< + * cdef FloatList col1 + * cdef FloatList col2 + */ +struct __pyx_obj_3_sa_BiLex { + PyObject_HEAD + struct __pyx_vtabstruct_3_sa_BiLex *__pyx_vtab; + struct __pyx_obj_3_sa_FloatList *col1; + struct __pyx_obj_3_sa_FloatList *col2; + struct __pyx_obj_3_sa_IntList *f_index; + struct __pyx_obj_3_sa_IntList *e_index; + PyObject *id2eword; + PyObject *id2fword; + PyObject *eword2id; + PyObject *fword2id; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":354 + * + * + * cdef class VEB: # <<<<<<<<<<<<<< + * cdef _VEB* veb + * cdef int _findsucc(self, int i) + */ +struct __pyx_obj_3_sa_VEB { + PyObject_HEAD + struct __pyx_vtabstruct_3_sa_VEB *__pyx_vtab; + struct __pyx_t_3_sa__VEB *veb; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":5 + * as k most frequent n-grams""" + * + * cdef class LCP: # <<<<<<<<<<<<<< + * cdef SuffixArray sa + * cdef IntList lcp + */ +struct __pyx_obj_3_sa_LCP { + PyObject_HEAD + struct __pyx_obj_3_sa_SuffixArray *sa; + struct __pyx_obj_3_sa_IntList *lcp; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":9 + * from libc.string cimport memset, strcpy, strlen + * + * cdef class DataArray: # <<<<<<<<<<<<<< + * cdef word2id + * cdef id2word + */ +struct __pyx_obj_3_sa_DataArray { + PyObject_HEAD + struct __pyx_vtabstruct_3_sa_DataArray *__pyx_vtab; + PyObject *word2id; + PyObject *id2word; + struct __pyx_obj_3_sa_IntList *data; + struct __pyx_obj_3_sa_IntList *sent_id; + struct __pyx_obj_3_sa_IntList *sent_index; + int use_sent_id; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":100 + * + * + * cdef class BitSetIterator: # <<<<<<<<<<<<<< + * cdef _BitSet* b + * cdef int next_val + */ +struct __pyx_obj_3_sa_BitSetIterator { + PyObject_HEAD + struct __pyx_t_3_sa__BitSet *b; + int next_val; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":188 + * + * + * cdef class Precomputation: # <<<<<<<<<<<<<< + * cdef int precompute_rank + * cdef int precompute_secondary_rank + */ +struct __pyx_obj_3_sa_Precomputation { + PyObject_HEAD + struct __pyx_vtabstruct_3_sa_Precomputation *__pyx_vtab; + int precompute_rank; + int precompute_secondary_rank; + int max_length; + int max_nonterminals; + int train_max_initial_size; + int train_min_gap_size; + PyObject *precomputed_index; + PyObject *precomputed_collocations; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":6 + * from libc.stdio cimport FILE, fclose, fopen + * + * cdef class SuffixArray: # <<<<<<<<<<<<<< + * cdef DataArray darray + * cdef IntList sa + */ +struct __pyx_obj_3_sa_SuffixArray { + PyObject_HEAD + struct __pyx_vtabstruct_3_sa_SuffixArray *__pyx_vtab; + struct __pyx_obj_3_sa_DataArray *darray; + struct __pyx_obj_3_sa_IntList *sa; + struct __pyx_obj_3_sa_IntList *ha; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":7 + * cdef int INDEX_MASK = (1<SetupContext((name), __LINE__, __FILE__); \ + PyGILState_Release(__pyx_gilstate_save); \ + } else { \ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \ + } +#else + #define __Pyx_RefNannySetupContext(name, acquire_gil) \ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) +#endif + #define __Pyx_RefNannyFinishContext() \ + __Pyx_RefNanny->FinishContext(&__pyx_refnanny) + #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) + #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) + #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) + #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) +#else + #define __Pyx_RefNannyDeclarations + #define __Pyx_RefNannySetupContext(name, acquire_gil) + #define __Pyx_RefNannyFinishContext() + #define __Pyx_INCREF(r) Py_INCREF(r) + #define __Pyx_DECREF(r) Py_DECREF(r) + #define __Pyx_GOTREF(r) + #define __Pyx_GIVEREF(r) + #define __Pyx_XINCREF(r) Py_XINCREF(r) + #define __Pyx_XDECREF(r) Py_XDECREF(r) + #define __Pyx_XGOTREF(r) + #define __Pyx_XGIVEREF(r) +#endif /* CYTHON_REFNANNY */ +#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) +#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) + +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ + +static int __Pyx_PyBytes_SingleTailmatch(PyObject* self, PyObject* arg, Py_ssize_t start, + Py_ssize_t end, int direction) +{ + const char* self_ptr = PyBytes_AS_STRING(self); + Py_ssize_t self_len = PyBytes_GET_SIZE(self); + const char* sub_ptr; + Py_ssize_t sub_len; + int retval; +#if PY_VERSION_HEX >= 0x02060000 + Py_buffer view; + view.obj = NULL; +#endif + if ( PyBytes_Check(arg) ) { + sub_ptr = PyBytes_AS_STRING(arg); + sub_len = PyBytes_GET_SIZE(arg); + } +#if PY_MAJOR_VERSION < 3 + else if ( PyUnicode_Check(arg) ) { + return PyUnicode_Tailmatch(self, arg, start, end, direction); + } +#endif + else { +#if PY_VERSION_HEX < 0x02060000 + if (unlikely(PyObject_AsCharBuffer(arg, &sub_ptr, &sub_len))) + return -1; +#else + if (unlikely(PyObject_GetBuffer(self, &view, PyBUF_SIMPLE) == -1)) + return -1; + sub_ptr = (const char*) view.buf; + sub_len = view.len; +#endif + } + if (end > self_len) + end = self_len; + else if (end < 0) + end += self_len; + if (end < 0) + end = 0; + if (start < 0) + start += self_len; + if (start < 0) + start = 0; + if (direction > 0) { + if (end-sub_len > start) + start = end - sub_len; + } + if (start + sub_len <= end) + retval = !memcmp(self_ptr+start, sub_ptr, sub_len); + else + retval = 0; +#if PY_VERSION_HEX >= 0x02060000 + if (view.obj) + PyBuffer_Release(&view); +#endif + return retval; +} +static int __Pyx_PyBytes_Tailmatch(PyObject* self, PyObject* substr, Py_ssize_t start, + Py_ssize_t end, int direction) +{ + if (unlikely(PyTuple_Check(substr))) { + int result; + Py_ssize_t i; + for (i = 0; i < PyTuple_GET_SIZE(substr); i++) { + result = __Pyx_PyBytes_SingleTailmatch(self, PyTuple_GET_ITEM(substr, i), + start, end, direction); + if (result) { + return result; + } + } + return 0; + } + return __Pyx_PyBytes_SingleTailmatch(self, substr, start, end, direction); +} + +static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/ + +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ + PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \ + const char* function_name); /*proto*/ + +static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ + +static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ +static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ + +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/ + +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ + +static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); /*proto*/ + +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { + PyObject *r; + if (!j) return NULL; + r = PyObject_GetItem(o, j); + Py_DECREF(j); + return r; +} +#define __Pyx_GetItemInt_List(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ + __Pyx_GetItemInt_List_Fast(o, i) : \ + __Pyx_GetItemInt_Generic(o, to_py_func(i))) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i) { +#if CYTHON_COMPILING_IN_CPYTHON + if (likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { + PyObject *r = PyList_GET_ITEM(o, i); + Py_INCREF(r); + return r; + } + else if ((-PyList_GET_SIZE(o) <= i) & (i < 0)) { + PyObject *r = PyList_GET_ITEM(o, PyList_GET_SIZE(o) + i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +#define __Pyx_GetItemInt_Tuple(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ + __Pyx_GetItemInt_Tuple_Fast(o, i) : \ + __Pyx_GetItemInt_Generic(o, to_py_func(i))) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i) { +#if CYTHON_COMPILING_IN_CPYTHON + if (likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, i); + Py_INCREF(r); + return r; + } + else if ((-PyTuple_GET_SIZE(o) <= i) & (i < 0)) { + PyObject *r = PyTuple_GET_ITEM(o, PyTuple_GET_SIZE(o) + i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +#define __Pyx_GetItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ + __Pyx_GetItemInt_Fast(o, i) : \ + __Pyx_GetItemInt_Generic(o, to_py_func(i))) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i) { +#if CYTHON_COMPILING_IN_CPYTHON + if (PyList_CheckExact(o)) { + Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); + if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) { + PyObject *r = PyList_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } + else if (PyTuple_CheckExact(o)) { + Py_ssize_t n = (likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); + if (likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } else { /* inlined PySequence_GetItem() */ + PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; + if (likely(m && m->sq_item)) { + if (unlikely(i < 0) && likely(m->sq_length)) { + Py_ssize_t l = m->sq_length(o); + if (unlikely(l < 0)) return NULL; + i += l; + } + return m->sq_item(o, i); + } + } +#else + if (PySequence_Check(o)) { + return PySequence_GetItem(o, i); + } +#endif + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} + +static CYTHON_INLINE int __Pyx_NegateNonNeg(int b) { + return unlikely(b < 0) ? b : !b; +} +static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) { + return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b); +} + +static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) { + if (likely(PyList_CheckExact(L))) { + if (unlikely(PyList_Append(L, x) < 0)) return NULL; + Py_INCREF(Py_None); + return Py_None; /* this is just to have an accurate signature */ + } else { + PyObject *r, *m; + m = __Pyx_GetAttrString(L, "append"); + if (!m) return NULL; + r = PyObject_CallFunctionObjArgs(m, x, NULL); + Py_DECREF(m); + return r; + } +} + +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ + +static CYTHON_INLINE long __Pyx_div_long(long, long); /* proto */ + +static CYTHON_INLINE long __Pyx_mod_long(long, long); /* proto */ + +static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); + +static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); + +static CYTHON_INLINE int __Pyx_IterFinish(void); /*proto*/ + +static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/ + +#define __Pyx_SetItemInt(o, i, v, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ + __Pyx_SetItemInt_Fast(o, i, v) : \ + __Pyx_SetItemInt_Generic(o, to_py_func(i), v)) +static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) { + int r; + if (!j) return -1; + r = PyObject_SetItem(o, j, v); + Py_DECREF(j); + return r; +} +static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v) { +#if CYTHON_COMPILING_IN_CPYTHON + if (PyList_CheckExact(o)) { + Py_ssize_t n = (likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); + if (likely((n >= 0) & (n < PyList_GET_SIZE(o)))) { + PyObject* old = PyList_GET_ITEM(o, n); + Py_INCREF(v); + PyList_SET_ITEM(o, n, v); + Py_DECREF(old); + return 1; + } + } else { /* inlined PySequence_SetItem() */ + PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; + if (likely(m && m->sq_ass_item)) { + if (unlikely(i < 0) && likely(m->sq_length)) { + Py_ssize_t l = m->sq_length(o); + if (unlikely(l < 0)) return -1; + i += l; + } + return m->sq_ass_item(o, i, v); + } + } +#else +#if CYTHON_COMPILING_IN_PYPY + if (PySequence_Check(o) && !PyDict_Check(o)) { +#else + if (PySequence_Check(o)) { +#endif + return PySequence_SetItem(o, i, v); + } +#endif + return __Pyx_SetItemInt_Generic(o, PyInt_FromSsize_t(i), v); +} + +static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */ +#if CYTHON_COMPILING_IN_PYPY +#define __Pyx_PyObject_AsDouble(obj) \ +(likely(PyFloat_CheckExact(obj)) ? PyFloat_AS_DOUBLE(obj) : \ + likely(PyInt_CheckExact(obj)) ? \ + PyFloat_AsDouble(obj) : __Pyx__PyObject_AsDouble(obj)) +#else +#define __Pyx_PyObject_AsDouble(obj) \ +((likely(PyFloat_CheckExact(obj))) ? \ + PyFloat_AS_DOUBLE(obj) : __Pyx__PyObject_AsDouble(obj)) +#endif + +static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname); + +static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, + const char *name, int exact); /*proto*/ + +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) { + PyListObject* L = (PyListObject*) list; + Py_ssize_t len = Py_SIZE(list); + if (likely(L->allocated > len)) { + Py_INCREF(x); + PyList_SET_ITEM(list, len, x); + Py_SIZE(list) = len+1; + return 0; + } + return PyList_Append(list, x); +} +#else +#define __Pyx_PyList_Append(L,x) PyList_Append(L,x) +#endif + +static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void); + +static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index); /*proto*/ + +static CYTHON_INLINE int __Pyx_unpack_tuple2(PyObject* tuple, PyObject** value1, PyObject** value2, + int is_tuple, int has_known_size, int decref_tuple); + +static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict, PyObject* method_name, + Py_ssize_t* p_orig_length, int* p_is_dict); +static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t orig_length, Py_ssize_t* ppos, + PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict); + +#if PY_VERSION_HEX < 0x02050000 +#ifndef PyAnySet_CheckExact +#define PyAnySet_CheckExact(ob) \ + ((ob)->ob_type == &PySet_Type || \ + (ob)->ob_type == &PyFrozenSet_Type) +#define PySet_New(iterable) \ + PyObject_CallFunctionObjArgs((PyObject *)&PySet_Type, (iterable), NULL) +#define Pyx_PyFrozenSet_New(iterable) \ + PyObject_CallFunctionObjArgs((PyObject *)&PyFrozenSet_Type, (iterable), NULL) +#define PySet_Size(anyset) \ + PyObject_Size((anyset)) +#define PySet_Contains(anyset, key) \ + PySequence_Contains((anyset), (key)) +#define PySet_Pop(set) \ + PyObject_CallMethod(set, (char *)"pop", NULL) +static CYTHON_INLINE int PySet_Clear(PyObject *set) { + PyObject *ret = PyObject_CallMethod(set, (char *)"clear", NULL); + if (!ret) return -1; + Py_DECREF(ret); return 0; +} +static CYTHON_INLINE int PySet_Discard(PyObject *set, PyObject *key) { + PyObject *ret = PyObject_CallMethod(set, (char *)"discard", (char *)"O", key); + if (!ret) return -1; + Py_DECREF(ret); return 0; +} +static CYTHON_INLINE int PySet_Add(PyObject *set, PyObject *key) { + PyObject *ret = PyObject_CallMethod(set, (char *)"add", (char *)"O", key); + if (!ret) return -1; + Py_DECREF(ret); return 0; +} +#endif /* PyAnySet_CheckExact (<= Py2.4) */ +#endif /* < Py2.5 */ + +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { + PyObject *value; + value = PyDict_GetItemWithError(d, key); + if (unlikely(!value)) { + if (!PyErr_Occurred()) + PyErr_SetObject(PyExc_KeyError, key); + return NULL; + } + Py_INCREF(value); + return value; +} +#else + #define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key) +#endif + +static CYTHON_INLINE int __Pyx_div_int(int, int); /* proto */ + +#define UNARY_NEG_WOULD_OVERFLOW(x) (((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x))) + +static CYTHON_INLINE PyObject* __Pyx_PyObject_Pop(PyObject* L) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02040000 + if (likely(PyList_CheckExact(L)) + && likely(PyList_GET_SIZE(L) > (((PyListObject*)L)->allocated >> 1))) { + Py_SIZE(L) -= 1; + return PyList_GET_ITEM(L, PyList_GET_SIZE(L)); + } +#if PY_VERSION_HEX >= 0x02050000 + else if (Py_TYPE(L) == (&PySet_Type)) { + return PySet_Pop(L); + } +#endif +#endif + return PyObject_CallMethod(L, (char*)"pop", NULL); +} + +static PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value) { + PyObject* value; +#if PY_MAJOR_VERSION >= 3 + value = PyDict_GetItemWithError(d, key); + if (unlikely(!value)) { + if (unlikely(PyErr_Occurred())) + return NULL; + if (unlikely(PyDict_SetItem(d, key, default_value) == -1)) + return NULL; + value = default_value; + } + Py_INCREF(value); +#else + if (PyString_CheckExact(key) || PyUnicode_CheckExact(key) || PyInt_CheckExact(key)) { + value = PyDict_GetItem(d, key); + if (unlikely(!value)) { + if (unlikely(PyDict_SetItem(d, key, default_value) == -1)) + return NULL; + value = default_value; + } + Py_INCREF(value); + } else { + PyObject *m; + m = __Pyx_GetAttrString(d, "setdefault"); + if (!m) return NULL; + value = PyObject_CallFunctionObjArgs(m, key, default_value, NULL); + Py_DECREF(m); + } +#endif + return value; +} + +static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ +static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ + +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/ + +static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); + +static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); + +static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); + +static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); + +static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); + +static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); + +static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); + +static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); + +static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); + +static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); + +static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); + +static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); + +static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); + +static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); + +static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); + +static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); + +static void __Pyx_WriteUnraisable(const char *name, int clineno, + int lineno, const char *filename); /*proto*/ + +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ + +#define __Pyx_Generator_USED +#include +#include +typedef PyObject *(*__pyx_generator_body_t)(PyObject *, PyObject *); +typedef struct { + PyObject_HEAD + __pyx_generator_body_t body; + PyObject *closure; + int is_running; + int resume_label; + PyObject *exc_type; + PyObject *exc_value; + PyObject *exc_traceback; + PyObject *gi_weakreflist; + PyObject *classobj; + PyObject *yieldfrom; +} __pyx_GeneratorObject; +static __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body, + PyObject *closure); +static int __pyx_Generator_init(void); +static int __Pyx_Generator_clear(PyObject* self); +#if 1 || PY_VERSION_HEX < 0x030300B0 +static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue); +#else +#define __Pyx_PyGen_FetchStopIterationValue(pvalue) PyGen_FetchStopIterationValue(pvalue) +#endif + +static int __Pyx_check_binary_version(void); + +static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig); /*proto*/ + +static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ + +typedef struct { + int code_line; + PyCodeObject* code_object; +} __Pyx_CodeObjectCacheEntry; +struct __Pyx_CodeObjectCache { + int count; + int max_count; + __Pyx_CodeObjectCacheEntry* entries; +}; +static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); +static PyCodeObject *__pyx_find_code_object(int code_line); +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); + +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename); /*proto*/ + +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ + + +/* Module declarations from 'libc.stdio' */ + +/* Module declarations from 'libc.stdlib' */ + +/* Module declarations from 'libc.string' */ + +/* Module declarations from 'libc.math' */ + +/* Module declarations from '_sa' */ +static PyTypeObject *__pyx_ptype_3_sa_Phrase = 0; +static PyTypeObject *__pyx_ptype_3_sa_Rule = 0; +static PyTypeObject *__pyx_ptype_3_sa_FloatList = 0; +static PyTypeObject *__pyx_ptype_3_sa_IntList = 0; +static PyTypeObject *__pyx_ptype_3_sa_StringMap = 0; +static PyTypeObject *__pyx_ptype_3_sa_DataArray = 0; +static PyTypeObject *__pyx_ptype_3_sa_Alignment = 0; +static PyTypeObject *__pyx_ptype_3_sa_BiLex = 0; +static PyTypeObject *__pyx_ptype_3_sa_BitSetIterator = 0; +static PyTypeObject *__pyx_ptype_3_sa_BitSet = 0; +static PyTypeObject *__pyx_ptype_3_sa_VEBIterator = 0; +static PyTypeObject *__pyx_ptype_3_sa_VEB = 0; +static PyTypeObject *__pyx_ptype_3_sa_LCP = 0; +static PyTypeObject *__pyx_ptype_3_sa_Alphabet = 0; +static PyTypeObject *__pyx_ptype_3_sa_TrieMap = 0; +static PyTypeObject *__pyx_ptype_3_sa_Precomputation = 0; +static PyTypeObject *__pyx_ptype_3_sa_SuffixArray = 0; +static PyTypeObject *__pyx_ptype_3_sa_TrieNode = 0; +static PyTypeObject *__pyx_ptype_3_sa_ExtendedTrieNode = 0; +static PyTypeObject *__pyx_ptype_3_sa_TrieTable = 0; +static PyTypeObject *__pyx_ptype_3_sa_PhraseLocation = 0; +static PyTypeObject *__pyx_ptype_3_sa_Sampler = 0; +static PyTypeObject *__pyx_ptype_3_sa_HieroCachingRuleFactory = 0; +static PyTypeObject *__pyx_ptype_3_sa___pyx_scope_struct__compute_stats = 0; +static PyTypeObject *__pyx_ptype_3_sa___pyx_scope_struct_1___iter__ = 0; +static PyTypeObject *__pyx_ptype_3_sa___pyx_scope_struct_2_input = 0; +static int __pyx_v_3_sa_MIN_BOTTOM_SIZE; +static int __pyx_v_3_sa_MIN_BOTTOM_BITS; +static int __pyx_v_3_sa_LOWER_MASK[32]; +static int __pyx_v_3_sa_INDEX_SHIFT; +static int __pyx_v_3_sa_INDEX_MASK; +static struct __pyx_obj_3_sa_Alphabet *__pyx_v_3_sa_ALPHABET = 0; +static int __pyx_v_3_sa_PRECOMPUTE; +static int __pyx_v_3_sa_MERGE; +static int __pyx_v_3_sa_BAEZA_YATES; +static int __pyx_v_3_sa_EPSILON; +static char *__pyx_f_3_sa_sym_tostring(int); /*proto*/ +static int __pyx_f_3_sa_sym_isvar(int); /*proto*/ +static int __pyx_f_3_sa_sym_getindex(int); /*proto*/ +static float __pyx_f_3_sa_monitor_cpu(void); /*proto*/ +static struct __pyx_t_3_sa__node *__pyx_f_3_sa_new_node(int); /*proto*/ +static PyObject *__pyx_f_3_sa_del_node(struct __pyx_t_3_sa__node *); /*proto*/ +static int *__pyx_f_3_sa_get_val(struct __pyx_t_3_sa__node *, int); /*proto*/ +static void __pyx_f_3_sa__init_lower_mask(void); /*proto*/ +static struct __pyx_t_3_sa__BitSet *__pyx_f_3_sa_new_BitSet(void); /*proto*/ +static int __pyx_f_3_sa_bitset_findsucc(struct __pyx_t_3_sa__BitSet *, int); /*proto*/ +static int __pyx_f_3_sa_bitset_insert(struct __pyx_t_3_sa__BitSet *, int); /*proto*/ +static int __pyx_f_3_sa_bitset_contains(struct __pyx_t_3_sa__BitSet *, int); /*proto*/ +static PyObject *__pyx_f_3_sa_dec2bin(long); /*proto*/ +static struct __pyx_t_3_sa__VEB *__pyx_f_3_sa_new_VEB(int); /*proto*/ +static int __pyx_f_3_sa_VEB_insert(struct __pyx_t_3_sa__VEB *, int); /*proto*/ +static PyObject *__pyx_f_3_sa_del_VEB(struct __pyx_t_3_sa__VEB *); /*proto*/ +static int __pyx_f_3_sa_VEB_findsucc(struct __pyx_t_3_sa__VEB *, int); /*proto*/ +static int __pyx_f_3_sa_VEB_contains(struct __pyx_t_3_sa__VEB *, int); /*proto*/ +static int __pyx_f_3_sa_sym_setindex(int, int); /*proto*/ +static struct __pyx_t_3_sa__Trie_Node *__pyx_f_3_sa_new_trie_node(void); /*proto*/ +static struct __pyx_t_3_sa__Trie_Edge *__pyx_f_3_sa_new_trie_edge(int); /*proto*/ +static PyObject *__pyx_f_3_sa_free_trie_node(struct __pyx_t_3_sa__Trie_Node *); /*proto*/ +static PyObject *__pyx_f_3_sa_free_trie_edge(struct __pyx_t_3_sa__Trie_Edge *); /*proto*/ +static struct __pyx_t_3_sa__Trie_Node *__pyx_f_3_sa_trie_find(struct __pyx_t_3_sa__Trie_Node *, int); /*proto*/ +static PyObject *__pyx_f_3_sa_trie_node_data_append(struct __pyx_t_3_sa__Trie_Node *, int); /*proto*/ +static struct __pyx_t_3_sa__Trie_Node *__pyx_f_3_sa_trie_insert(struct __pyx_t_3_sa__Trie_Node *, int); /*proto*/ +static PyObject *__pyx_f_3_sa_trie_node_to_map(struct __pyx_t_3_sa__Trie_Node *, PyObject *, PyObject *, int); /*proto*/ +static PyObject *__pyx_f_3_sa_trie_edge_to_map(struct __pyx_t_3_sa__Trie_Edge *, PyObject *, PyObject *, int); /*proto*/ +static void __pyx_f_3_sa_assign_matching(struct __pyx_t_3_sa_Matching *, int *, int, int, int *); /*proto*/ +static int *__pyx_f_3_sa_append_combined_matching(int *, struct __pyx_t_3_sa_Matching *, struct __pyx_t_3_sa_Matching *, int, int, int *); /*proto*/ +static int *__pyx_f_3_sa_extend_arr(int *, int *, int *, int); /*proto*/ +static int __pyx_f_3_sa_median(int, int, int); /*proto*/ +static void __pyx_f_3_sa_find_comparable_matchings(int, int, int *, int, int, int *, int *); /*proto*/ +#define __Pyx_MODULE_NAME "_sa" +int __pyx_module_is_main__sa = 0; + +/* Implementation of '_sa' */ +static PyObject *__pyx_builtin_open; +static PyObject *__pyx_builtin_IndexError; +static PyObject *__pyx_builtin_range; +static PyObject *__pyx_builtin_TypeError; +static PyObject *__pyx_builtin_enumerate; +static PyObject *__pyx_builtin_map; +static PyObject *__pyx_builtin_Exception; +static PyObject *__pyx_builtin_zip; +static PyObject *__pyx_builtin_StopIteration; +static PyObject *__pyx_builtin_cmp; +static PyObject *__pyx_builtin_ValueError; +static PyObject *__pyx_builtin_sorted; +static PyObject *__pyx_pf_3_sa_gzip_or_text(CYTHON_UNUSED PyObject *__pyx_self, char *__pyx_v_filename); /* proto */ +static int __pyx_pf_3_sa_9FloatList___cinit__(struct __pyx_obj_3_sa_FloatList *__pyx_v_self, int __pyx_v_size, int __pyx_v_increment, int __pyx_v_initial_len); /* proto */ +static void __pyx_pf_3_sa_9FloatList_2__dealloc__(struct __pyx_obj_3_sa_FloatList *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_9FloatList_4__getitem__(struct __pyx_obj_3_sa_FloatList *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static int __pyx_pf_3_sa_9FloatList_6__setitem__(struct __pyx_obj_3_sa_FloatList *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val); /* proto */ +static Py_ssize_t __pyx_pf_3_sa_9FloatList_8__len__(struct __pyx_obj_3_sa_FloatList *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_9FloatList_10append(struct __pyx_obj_3_sa_FloatList *__pyx_v_self, float __pyx_v_val); /* proto */ +static PyObject *__pyx_pf_3_sa_9FloatList_12write(struct __pyx_obj_3_sa_FloatList *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_9FloatList_14read(struct __pyx_obj_3_sa_FloatList *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static int __pyx_pf_3_sa_7IntList___cinit__(struct __pyx_obj_3_sa_IntList *__pyx_v_self, int __pyx_v_size, int __pyx_v_increment, int __pyx_v_initial_len); /* proto */ +static PyObject *__pyx_pf_3_sa_7IntList_2__str__(struct __pyx_obj_3_sa_IntList *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_7IntList_4index(struct __pyx_obj_3_sa_IntList *__pyx_v_self, PyObject *__pyx_v_val); /* proto */ +static PyObject *__pyx_pf_3_sa_7IntList_6partition(struct __pyx_obj_3_sa_IntList *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_end); /* proto */ +static PyObject *__pyx_pf_3_sa_7IntList_8_doquicksort(struct __pyx_obj_3_sa_IntList *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_end); /* proto */ +static PyObject *__pyx_pf_3_sa_7IntList_10sort(struct __pyx_obj_3_sa_IntList *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_7IntList_12reset(struct __pyx_obj_3_sa_IntList *__pyx_v_self); /* proto */ +static void __pyx_pf_3_sa_7IntList_14__dealloc__(struct __pyx_obj_3_sa_IntList *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_7IntList_16__getitem__(struct __pyx_obj_3_sa_IntList *__pyx_v_self, PyObject *__pyx_v_index); /* proto */ +static int __pyx_pf_3_sa_7IntList_18__setitem__(struct __pyx_obj_3_sa_IntList *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val); /* proto */ +static Py_ssize_t __pyx_pf_3_sa_7IntList_20__len__(struct __pyx_obj_3_sa_IntList *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_7IntList_22getSize(struct __pyx_obj_3_sa_IntList *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_7IntList_24append(struct __pyx_obj_3_sa_IntList *__pyx_v_self, int __pyx_v_val); /* proto */ +static PyObject *__pyx_pf_3_sa_7IntList_26extend(struct __pyx_obj_3_sa_IntList *__pyx_v_self, PyObject *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_3_sa_7IntList_28write(struct __pyx_obj_3_sa_IntList *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_7IntList_30read(struct __pyx_obj_3_sa_IntList *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static int __pyx_pf_3_sa_9StringMap___cinit__(struct __pyx_obj_3_sa_StringMap *__pyx_v_self); /* proto */ +static void __pyx_pf_3_sa_9StringMap_2__dealloc__(struct __pyx_obj_3_sa_StringMap *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_9DataArray___cinit__(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text, int __pyx_v_use_sent_id); /* proto */ +static Py_ssize_t __pyx_pf_3_sa_9DataArray_2__len__(struct __pyx_obj_3_sa_DataArray *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_9DataArray_4getSentId(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_3_sa_9DataArray_6getSent(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_3_sa_9DataArray_8getSentPos(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_loc); /* proto */ +static PyObject *__pyx_pf_3_sa_9DataArray_10get_id(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_word); /* proto */ +static PyObject *__pyx_pf_3_sa_9DataArray_12get_word(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_id); /* proto */ +static PyObject *__pyx_pf_3_sa_9DataArray_14write_text(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_9DataArray_16read_text(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_9DataArray_18read_binary(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_9DataArray_20write_binary(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_f); /* proto */ +static PyObject *__pyx_pf_3_sa_9DataArray_24write_enhanced(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_9Alignment_unlink(CYTHON_UNUSED struct __pyx_obj_3_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_link); /* proto */ +static PyObject *__pyx_pf_3_sa_9Alignment_2get_sent_links(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, int __pyx_v_sent_id); /* proto */ +static int __pyx_pf_3_sa_9Alignment_4__cinit__(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text); /* proto */ +static PyObject *__pyx_pf_3_sa_9Alignment_6read_text(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_9Alignment_8read_binary(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_9Alignment_10write_text(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_9Alignment_12write_binary(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_9Alignment_14write_enhanced(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_9Alignment_16alignment(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static int __pyx_pf_3_sa_5BiLex___cinit__(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_from_text, PyObject *__pyx_v_from_data, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_earray, PyObject *__pyx_v_fsarray, PyObject *__pyx_v_alignment); /* proto */ +static PyObject *__pyx_pf_3_sa_5BiLex_2write_binary(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_5BiLex_4read_binary(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_5BiLex_6get_e_id(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_eword); /* proto */ +static PyObject *__pyx_pf_3_sa_5BiLex_8get_f_id(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_fword); /* proto */ +static PyObject *__pyx_pf_3_sa_5BiLex_10read_text(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_5BiLex_12write_enhanced(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_5BiLex_14get_score(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_fword, PyObject *__pyx_v_eword, PyObject *__pyx_v_col); /* proto */ +static PyObject *__pyx_pf_3_sa_5BiLex_16write_text(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_14BitSetIterator___next__(struct __pyx_obj_3_sa_BitSetIterator *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_6BitSet___cinit__(struct __pyx_obj_3_sa_BitSet *__pyx_v_self); /* proto */ +static void __pyx_pf_3_sa_6BitSet_2__dealloc__(struct __pyx_obj_3_sa_BitSet *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_6BitSet_4__iter__(struct __pyx_obj_3_sa_BitSet *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_6BitSet_6insert(struct __pyx_obj_3_sa_BitSet *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_3_sa_6BitSet_8findsucc(struct __pyx_obj_3_sa_BitSet *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_3_sa_6BitSet_10__str__(struct __pyx_obj_3_sa_BitSet *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_6BitSet_12min(struct __pyx_obj_3_sa_BitSet *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_6BitSet_14max(struct __pyx_obj_3_sa_BitSet *__pyx_v_self); /* proto */ +static Py_ssize_t __pyx_pf_3_sa_6BitSet_16__len__(struct __pyx_obj_3_sa_BitSet *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_6BitSet_18__contains__(struct __pyx_obj_3_sa_BitSet *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_3_sa_11VEBIterator___next__(struct __pyx_obj_3_sa_VEBIterator *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_3VEB___cinit__(struct __pyx_obj_3_sa_VEB *__pyx_v_self, int __pyx_v_size); /* proto */ +static void __pyx_pf_3_sa_3VEB_2__dealloc__(struct __pyx_obj_3_sa_VEB *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_3VEB_4__iter__(struct __pyx_obj_3_sa_VEB *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_3VEB_6insert(struct __pyx_obj_3_sa_VEB *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_3_sa_3VEB_8findsucc(struct __pyx_obj_3_sa_VEB *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static Py_ssize_t __pyx_pf_3_sa_3VEB_10__len__(struct __pyx_obj_3_sa_VEB *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_3VEB_12__contains__(struct __pyx_obj_3_sa_VEB *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static int __pyx_pf_3_sa_3LCP___cinit__(struct __pyx_obj_3_sa_LCP *__pyx_v_self, struct __pyx_obj_3_sa_SuffixArray *__pyx_v_sa); /* proto */ +static PyObject *__pyx_pf_3_sa_3LCP_2compute_stats(struct __pyx_obj_3_sa_LCP *__pyx_v_self, int __pyx_v_max_n); /* proto */ +static int __pyx_pf_3_sa_8Alphabet___cinit__(struct __pyx_obj_3_sa_Alphabet *__pyx_v_self); /* proto */ +static void __pyx_pf_3_sa_8Alphabet_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_3_sa_Alphabet *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_8Alphabet_9terminals___get__(struct __pyx_obj_3_sa_Alphabet *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_8Alphabet_12nonterminals___get__(struct __pyx_obj_3_sa_Alphabet *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_2sym_fromstring(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_string, int __pyx_v_terminal); /* proto */ +static int __pyx_pf_3_sa_6Phrase___cinit__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_words); /* proto */ +static void __pyx_pf_3_sa_6Phrase_2__dealloc__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_6Phrase_4__str__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_6Phrase_6handle(struct __pyx_obj_3_sa_Phrase *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_6Phrase_8strhandle(struct __pyx_obj_3_sa_Phrase *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_6Phrase_10arity(struct __pyx_obj_3_sa_Phrase *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_6Phrase_12getvarpos(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_3_sa_6Phrase_14getvar(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_3_sa_6Phrase_16clen(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_k); /* proto */ +static PyObject *__pyx_pf_3_sa_6Phrase_18getchunk(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_ci); /* proto */ +#if PY_MAJOR_VERSION < 3 +static int __pyx_pf_3_sa_6Phrase_20__cmp__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_other); /* proto */ +#endif +static Py_hash_t __pyx_pf_3_sa_6Phrase_22__hash__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self); /* proto */ +static Py_ssize_t __pyx_pf_3_sa_6Phrase_24__len__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_6Phrase_26__getitem__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_3_sa_6Phrase_28__iter__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_6Phrase_31subst(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_children); /* proto */ +static PyObject *__pyx_pf_3_sa_6Phrase_5words___get__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_4Rule___cinit__(struct __pyx_obj_3_sa_Rule *__pyx_v_self, int __pyx_v_lhs, struct __pyx_obj_3_sa_Phrase *__pyx_v_f, struct __pyx_obj_3_sa_Phrase *__pyx_v_e, PyObject *__pyx_v_scores, PyObject *__pyx_v_word_alignments); /* proto */ +static void __pyx_pf_3_sa_4Rule_2__dealloc__(struct __pyx_obj_3_sa_Rule *__pyx_v_self); /* proto */ +static Py_hash_t __pyx_pf_3_sa_4Rule_4__hash__(struct __pyx_obj_3_sa_Rule *__pyx_v_self); /* proto */ +#if PY_MAJOR_VERSION < 3 +static int __pyx_pf_3_sa_4Rule_6__cmp__(struct __pyx_obj_3_sa_Rule *__pyx_v_self, struct __pyx_obj_3_sa_Rule *__pyx_v_other); /* proto */ +#endif +static PyObject *__pyx_pf_3_sa_4Rule_8__iadd__(struct __pyx_obj_3_sa_Rule *__pyx_v_self, struct __pyx_obj_3_sa_Rule *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_3_sa_4Rule_10fmerge(struct __pyx_obj_3_sa_Rule *__pyx_v_self, struct __pyx_obj_3_sa_Phrase *__pyx_v_f); /* proto */ +static PyObject *__pyx_pf_3_sa_4Rule_12arity(struct __pyx_obj_3_sa_Rule *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_4Rule_14__str__(struct __pyx_obj_3_sa_Rule *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_4Rule_6scores___get__(struct __pyx_obj_3_sa_Rule *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_4Rule_6scores_2__set__(struct __pyx_obj_3_sa_Rule *__pyx_v_self, PyObject *__pyx_v_s); /* proto */ +static PyObject *__pyx_pf_3_sa_4Rule_3lhs___get__(struct __pyx_obj_3_sa_Rule *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_4Rule_3lhs_2__set__(struct __pyx_obj_3_sa_Rule *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_3_sa_4Rule_1f___get__(struct __pyx_obj_3_sa_Rule *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_4Rule_1e___get__(struct __pyx_obj_3_sa_Rule *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_4Rule_15word_alignments___get__(struct __pyx_obj_3_sa_Rule *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_4Rule_15word_alignments_2__set__(struct __pyx_obj_3_sa_Rule *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_3_sa_4Rule_15word_alignments_4__del__(struct __pyx_obj_3_sa_Rule *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_7TrieMap___cinit__(struct __pyx_obj_3_sa_TrieMap *__pyx_v_self, int __pyx_v_alphabet_size); /* proto */ +static void __pyx_pf_3_sa_7TrieMap_2__dealloc__(struct __pyx_obj_3_sa_TrieMap *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_7TrieMap_4insert(struct __pyx_obj_3_sa_TrieMap *__pyx_v_self, PyObject *__pyx_v_pattern); /* proto */ +static PyObject *__pyx_pf_3_sa_7TrieMap_6contains(struct __pyx_obj_3_sa_TrieMap *__pyx_v_self, PyObject *__pyx_v_pattern); /* proto */ +static PyObject *__pyx_pf_3_sa_7TrieMap_8toMap(struct __pyx_obj_3_sa_TrieMap *__pyx_v_self, PyObject *__pyx_v_flag); /* proto */ +static int __pyx_pf_3_sa_14Precomputation___cinit__(struct __pyx_obj_3_sa_Precomputation *__pyx_v_self, PyObject *__pyx_v_fsarray, PyObject *__pyx_v_from_stats, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_precompute_rank, PyObject *__pyx_v_precompute_secondary_rank, PyObject *__pyx_v_max_length, PyObject *__pyx_v_max_nonterminals, PyObject *__pyx_v_train_max_initial_size, PyObject *__pyx_v_train_min_gap_size); /* proto */ +static PyObject *__pyx_pf_3_sa_14Precomputation_2read_binary(struct __pyx_obj_3_sa_Precomputation *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_14Precomputation_4write_binary(struct __pyx_obj_3_sa_Precomputation *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_sa_Precomputation *__pyx_v_self, PyObject *__pyx_v_stats, struct __pyx_obj_3_sa_SuffixArray *__pyx_v_sarray); /* proto */ +static int __pyx_pf_3_sa_11SuffixArray___cinit__(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text); /* proto */ +static PyObject *__pyx_pf_3_sa_11SuffixArray_2__getitem__(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_3_sa_11SuffixArray_4getSentId(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_3_sa_11SuffixArray_6getSent(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ +static PyObject *__pyx_pf_3_sa_11SuffixArray_8getSentPos(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_loc); /* proto */ +static PyObject *__pyx_pf_3_sa_11SuffixArray_10read_text(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_11SuffixArray_12q3sort(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, int __pyx_v_i, int __pyx_v_j, int __pyx_v_h, struct __pyx_obj_3_sa_IntList *__pyx_v_isa, PyObject *__pyx_v_pad); /* proto */ +static PyObject *__pyx_pf_3_sa_11SuffixArray_14write_text(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_11SuffixArray_16read_binary(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_11SuffixArray_18write_binary(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_11SuffixArray_20write_enhanced(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_11SuffixArray_22lookup(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_word, int __pyx_v_offset, int __pyx_v_low, int __pyx_v_high); /* proto */ +static int __pyx_pf_3_sa_8TrieNode___cinit__(struct __pyx_obj_3_sa_TrieNode *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_8TrieNode_8children___get__(struct __pyx_obj_3_sa_TrieNode *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_8TrieNode_8children_2__set__(struct __pyx_obj_3_sa_TrieNode *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_3_sa_8TrieNode_8children_4__del__(struct __pyx_obj_3_sa_TrieNode *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_16ExtendedTrieNode___cinit__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_phrase, PyObject *__pyx_v_phrase_location, PyObject *__pyx_v_suffix_link); /* proto */ +static PyObject *__pyx_pf_3_sa_16ExtendedTrieNode_6phrase___get__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_16ExtendedTrieNode_6phrase_2__set__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_3_sa_16ExtendedTrieNode_6phrase_4__del__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_16ExtendedTrieNode_15phrase_location___get__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_16ExtendedTrieNode_15phrase_location_2__set__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_3_sa_16ExtendedTrieNode_15phrase_location_4__del__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_16ExtendedTrieNode_11suffix_link___get__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_16ExtendedTrieNode_11suffix_link_2__set__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_3_sa_16ExtendedTrieNode_11suffix_link_4__del__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_9TrieTable___cinit__(struct __pyx_obj_3_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_extended); /* proto */ +static PyObject *__pyx_pf_3_sa_9TrieTable_8extended___get__(struct __pyx_obj_3_sa_TrieTable *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_9TrieTable_8extended_2__set__(struct __pyx_obj_3_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_3_sa_9TrieTable_5count___get__(struct __pyx_obj_3_sa_TrieTable *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_9TrieTable_5count_2__set__(struct __pyx_obj_3_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static PyObject *__pyx_pf_3_sa_9TrieTable_4root___get__(struct __pyx_obj_3_sa_TrieTable *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_9TrieTable_4root_2__set__(struct __pyx_obj_3_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_3_sa_9TrieTable_4root_4__del__(struct __pyx_obj_3_sa_TrieTable *__pyx_v_self); /* proto */ +static int __pyx_pf_3_sa_14PhraseLocation___cinit__(struct __pyx_obj_3_sa_PhraseLocation *__pyx_v_self, int __pyx_v_sa_low, int __pyx_v_sa_high, int __pyx_v_arr_low, int __pyx_v_arr_high, PyObject *__pyx_v_arr, int __pyx_v_num_subpatterns); /* proto */ +static int __pyx_pf_3_sa_7Sampler___cinit__(struct __pyx_obj_3_sa_Sampler *__pyx_v_self, int __pyx_v_sample_size, struct __pyx_obj_3_sa_SuffixArray *__pyx_v_fsarray); /* proto */ +static PyObject *__pyx_pf_3_sa_7Sampler_2sample(struct __pyx_obj_3_sa_Sampler *__pyx_v_self, struct __pyx_obj_3_sa_PhraseLocation *__pyx_v_phrase_location); /* proto */ +static int __pyx_pf_3_sa_23HieroCachingRuleFactory___cinit__(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_3_sa_Alignment *__pyx_v_alignment, float __pyx_v_by_slack_factor, char *__pyx_v_category, PyObject *__pyx_v_max_chunks, unsigned int __pyx_v_max_initial_size, unsigned int __pyx_v_max_length, unsigned int __pyx_v_max_nonterminals, PyObject *__pyx_v_max_target_chunks, PyObject *__pyx_v_max_target_length, unsigned int __pyx_v_min_gap_size, PyObject *__pyx_v_precompute_file, unsigned int __pyx_v_precompute_secondary_rank, unsigned int __pyx_v_precompute_rank, int __pyx_v_require_aligned_terminal, int __pyx_v_require_aligned_chunks, unsigned int __pyx_v_train_max_initial_size, unsigned int __pyx_v_train_min_gap_size, int __pyx_v_tight_phrases, int __pyx_v_use_baeza_yates, int __pyx_v_use_collocations, int __pyx_v_use_index); /* proto */ +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_2configure(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_3_sa_SuffixArray *__pyx_v_fsarray, struct __pyx_obj_3_sa_DataArray *__pyx_v_edarray, struct __pyx_obj_3_sa_Sampler *__pyx_v_sampler); /* proto */ +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_4pattern2phrase(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_pattern); /* proto */ +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_6pattern2phrase_plus(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_pattern); /* proto */ +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_8precompute(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_10get_precomputed_collocation(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_phrase); /* proto */ +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_12advance(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_frontier, PyObject *__pyx_v_res, PyObject *__pyx_v_fwords); /* proto */ +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_14get_all_nodes_isteps_away(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_skip, PyObject *__pyx_v_i, PyObject *__pyx_v_spanlen, PyObject *__pyx_v_pathlen, PyObject *__pyx_v_fwords, PyObject *__pyx_v_next_states, PyObject *__pyx_v_reachable_buffer); /* proto */ +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_16reachable(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_ifrom, PyObject *__pyx_v_dist); /* proto */ +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_18shortest(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_ifrom, PyObject *__pyx_v_ito); /* proto */ +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_20get_next_states(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v__columns, PyObject *__pyx_v_curr_idx, PyObject *__pyx_v_min_dist); /* proto */ +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_22input(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_models); /* proto */ +static char __pyx_k_1[] = ".gz"; +static char __pyx_k_2[] = "Requested index %d of %d-length FloatList"; +static char __pyx_k_3[] = "IntList["; +static char __pyx_k_4[] = ","; +static char __pyx_k_5[] = "]"; +static char __pyx_k_6[] = "len="; +static char __pyx_k_7[] = "Requested index %d of %d-length IntList"; +static char __pyx_k_8[] = "Requested index %d:%d of %d-length IntList"; +static char __pyx_k_9[] = "Illegal key type %s for IntList"; +static char __pyx_k_13[] = "%s "; +static char __pyx_k_14[] = "\n"; +static char __pyx_k_18[] = "%d "; +static char __pyx_k_22[] = "%s %d "; +static char __pyx_k_24[] = "write_enhanced_handle"; +static char __pyx_k_28[] = "-"; +static char __pyx_k_32[] = "%d-%d "; +static char __pyx_k_39[] = "%d-%d out of bounds (I=%d,J=%d) in line %d\n"; +static char __pyx_k_42[] = ""; +static char __pyx_k_43[] = "Sort error in CLex"; +static char __pyx_k_45[] = " "; +static char __pyx_k_47[] = "%d %f %f "; +static char __pyx_k_49[] = "%d %s "; +static char __pyx_k_53[] = "%s %s %.6f %.6f\n"; +static char __pyx_k_55[] = " ("; +static char __pyx_k_56[] = ")"; +static char __pyx_k_57[] = "Constructing LCP array"; +static char __pyx_k_59[] = "LCP array completed"; +static char __pyx_k_61[] = "[%s,%d]"; +static char __pyx_k_62[] = "[%s]"; +static char __pyx_k_63[] = "\\"; +static char __pyx_k_64[] = " "; +static char __pyx_k_65[] = "Invalid LHS symbol: %d"; +static char __pyx_k_66[] = "%d-%d"; +static char __pyx_k_67[] = " ||| "; +static char __pyx_k_68[] = "precompute_secondary_rank"; +static char __pyx_k_69[] = "train_max_initial_size"; +static char __pyx_k_70[] = "Precomputing frequent intersections"; +static char __pyx_k_72[] = " Computing inverted indexes..."; +static char __pyx_k_74[] = " Computing collocations..."; +static char __pyx_k_76[] = " %d sentences"; +static char __pyx_k_81[] = "X "; +static char __pyx_k_82[] = "ERROR: unexpected pattern %s in set of precomputed collocations"; +static char __pyx_k_83[] = "RANK %d\tCOUNT, COST: %d %d\tCUMUL: %d, %d"; +static char __pyx_k_84[] = "Precomputed collocations for %d patterns out of %d possible (upper bound %d)"; +static char __pyx_k_85[] = "Precomputed inverted index for %d patterns "; +static char __pyx_k_86[] = "Precomputation took %f seconds"; +static char __pyx_k_87[] = " Bucket sort took %f seconds"; +static char __pyx_k_88[] = " Refining, sort depth = %d"; +static char __pyx_k_89[] = " Refinement took %f seconds"; +static char __pyx_k_90[] = " Finalizing sort..."; +static char __pyx_k_92[] = "Suffix array construction took %f seconds"; +static char __pyx_k_93[] = "Unexpected condition found in q3sort: sort from %d to %d"; +static char __pyx_k_98[] = "Sampling strategy: uniform, max sample size = %d"; +static char __pyx_k_99[] = "Sampling strategy: no sampling"; +static char __pyx_k__0[] = "0"; +static char __pyx_k__1[] = "1"; +static char __pyx_k__e[] = "e"; +static char __pyx_k__f[] = "f"; +static char __pyx_k__h[] = "h"; +static char __pyx_k__i[] = "i"; +static char __pyx_k__j[] = "j"; +static char __pyx_k__r[] = "r"; +static char __pyx_k__w[] = "w"; +static char __pyx_k_101[] = "require_aligned_terminal"; +static char __pyx_k_102[] = "require_aligned_chunks"; +static char __pyx_k_103[] = "[X]"; +static char __pyx_k_104[] = "Must specify an alignment object"; +static char __pyx_k_106[] = "Reading precomputed data from file %s... "; +static char __pyx_k_107[] = "Precomputation done with max nonterminals %d, decoder uses %d"; +static char __pyx_k_108[] = "Precomputation done with max terminals %d, decoder uses %d"; +static char __pyx_k_109[] = "Precomputation done with max initial size %d, decoder uses %d"; +static char __pyx_k_110[] = "Precomputation done with min gap size %d, decoder uses %d"; +static char __pyx_k_111[] = "Converting %d hash keys on precomputed inverted index... "; +static char __pyx_k_112[] = "Converting %d hash keys on precomputed collocations... "; +static char __pyx_k_113[] = "Processing precomputations took %f seconds"; +static char __pyx_k_114[] = "{"; + static char __pyx_k_115[] = "("; +static char __pyx_k_116[] = "}"; +static char __pyx_k_117[] = "get_precomputed_collocation"; +static char __pyx_k_118[] = "double binary"; +static char __pyx_k_119[] = "Keyword trie error"; +static char __pyx_k_121[] = "get_all_nodes_isteps_away"; +static char __pyx_k_122[] = "Total time for rule lookup, extraction, and scoring = %f seconds"; +static char __pyx_k_123[] = " Extract time = %f seconds"; +static char __pyx_k_124[] = "No aligned terminals"; +static char __pyx_k_125[] = "Unaligned chunk"; +static char __pyx_k_126[] = "Gaps are not tight phrases"; +static char __pyx_k_127[] = "Inside edges of preceding subphrase are not tight"; +static char __pyx_k_128[] = "Inside edges of following subphrase are not tight"; +static char __pyx_k_129[] = "Subphrase [%d, %d] failed integrity check"; +static char __pyx_k_130[] = "Didn't extract anything from [%d, %d] -> [%d, %d]"; +static char __pyx_k_131[] = "Unable to extract basic phrase"; +static char __pyx_k_134[] = "/Users/vchahun/Sandbox/cdec/python/src/sa/_sa.pyx"; +static char __pyx_k_135[] = "cdec.sa"; +static char __pyx_k_139[] = "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi"; +static char __pyx_k_140[] = "*EPS*"; +static char __pyx_k__gc[] = "gc"; +static char __pyx_k__sa[] = "sa"; +static char __pyx_k___sa[] = "_sa"; +static char __pyx_k__arr[] = "arr"; +static char __pyx_k__cmp[] = "cmp"; +static char __pyx_k__col[] = "col"; +static char __pyx_k__end[] = "end"; +static char __pyx_k__isa[] = "isa"; +static char __pyx_k__ito[] = "ito"; +static char __pyx_k__lhs[] = "lhs"; +static char __pyx_k__low[] = "low"; +static char __pyx_k__map[] = "map"; +static char __pyx_k__pad[] = "pad"; +static char __pyx_k__res[] = "res"; +static char __pyx_k__zip[] = "zip"; +static char __pyx_k__NULL[] = "NULL"; +static char __pyx_k__dist[] = "dist"; +static char __pyx_k__gzip[] = "gzip"; +static char __pyx_k__high[] = "high"; +static char __pyx_k__info[] = "info"; +static char __pyx_k__join[] = "join"; +static char __pyx_k__open[] = "open"; +static char __pyx_k__seek[] = "seek"; +static char __pyx_k__size[] = "size"; +static char __pyx_k__skip[] = "skip"; +static char __pyx_k__stop[] = "stop"; +static char __pyx_k__warn[] = "warn"; +static char __pyx_k__word[] = "word"; +static char __pyx_k___SEP_[] = "_SEP_"; +static char __pyx_k__arity[] = "arity"; +static char __pyx_k__debug[] = "debug"; +static char __pyx_k__eword[] = "eword"; +static char __pyx_k__fword[] = "fword"; +static char __pyx_k__ifrom[] = "ifrom"; +static char __pyx_k__index[] = "index"; +static char __pyx_k__merge[] = "merge"; +static char __pyx_k__range[] = "range"; +static char __pyx_k__reset[] = "reset"; +static char __pyx_k__split[] = "split"; +static char __pyx_k__start[] = "start"; +static char __pyx_k__stats[] = "stats"; +static char __pyx_k__toMap[] = "toMap"; +static char __pyx_k__words[] = "words"; +static char __pyx_k__write[] = "write"; +static char __pyx_k__earray[] = "earray"; +static char __pyx_k__extend[] = "extend"; +static char __pyx_k__fwords[] = "fwords"; +static char __pyx_k__get_id[] = "get_id"; +static char __pyx_k__insert[] = "insert"; +static char __pyx_k__logger[] = "logger"; +static char __pyx_k__lookup[] = "lookup"; +static char __pyx_k__models[] = "models"; +static char __pyx_k__offset[] = "offset"; +static char __pyx_k__phrase[] = "phrase"; +static char __pyx_k__q3sort[] = "q3sort"; +static char __pyx_k__sa_low[] = "sa_low"; +static char __pyx_k__sample[] = "sample"; +static char __pyx_k__sarray[] = "sarray"; +static char __pyx_k__scores[] = "scores"; +static char __pyx_k__sorted[] = "sorted"; +static char __pyx_k__string[] = "string"; +static char __pyx_k__unlink[] = "unlink"; +static char __pyx_k__advance[] = "advance"; +static char __pyx_k__arr_low[] = "arr_low"; +static char __pyx_k__collect[] = "collect"; +static char __pyx_k__edarray[] = "edarray"; +static char __pyx_k__fsarray[] = "fsarray"; +static char __pyx_k__getSent[] = "getSent"; +static char __pyx_k__logging[] = "logging"; +static char __pyx_k__pathlen[] = "pathlen"; +static char __pyx_k__sa_high[] = "sa_high"; +static char __pyx_k__sampler[] = "sampler"; +static char __pyx_k__spanlen[] = "spanlen"; +static char __pyx_k__GzipFile[] = "GzipFile"; +static char __pyx_k____exit__[] = "__exit__"; +static char __pyx_k____main__[] = "__main__"; +static char __pyx_k____test__[] = "__test__"; +static char __pyx_k___columns[] = "_columns"; +static char __pyx_k__arr_high[] = "arr_high"; +static char __pyx_k__category[] = "category"; +static char __pyx_k__children[] = "children"; +static char __pyx_k__curr_idx[] = "curr_idx"; +static char __pyx_k__extended[] = "extended"; +static char __pyx_k__filename[] = "filename"; +static char __pyx_k__frontier[] = "frontier"; +static char __pyx_k__get_e_id[] = "get_e_id"; +static char __pyx_k__get_f_id[] = "get_f_id"; +static char __pyx_k__get_word[] = "get_word"; +static char __pyx_k__getchunk[] = "getchunk"; +static char __pyx_k__min_dist[] = "min_dist"; +static char __pyx_k__resource[] = "resource"; +static char __pyx_k__ru_stime[] = "ru_stime"; +static char __pyx_k__ru_utime[] = "ru_utime"; +static char __pyx_k__shortest[] = "shortest"; +static char __pyx_k__terminal[] = "terminal"; +static char __pyx_k__Exception[] = "Exception"; +static char __pyx_k__TypeError[] = "TypeError"; +static char __pyx_k____enter__[] = "__enter__"; +static char __pyx_k__alignment[] = "alignment"; +static char __pyx_k__enumerate[] = "enumerate"; +static char __pyx_k__from_data[] = "from_data"; +static char __pyx_k__from_text[] = "from_text"; +static char __pyx_k__getLogger[] = "getLogger"; +static char __pyx_k__getSentId[] = "getSentId"; +static char __pyx_k__getrusage[] = "getrusage"; +static char __pyx_k__increment[] = "increment"; +static char __pyx_k__iteritems[] = "iteritems"; +static char __pyx_k__partition[] = "partition"; +static char __pyx_k__reachable[] = "reachable"; +static char __pyx_k__read_text[] = "read_text"; +static char __pyx_k__use_index[] = "use_index"; +static char __pyx_k__IndexError[] = "IndexError"; +static char __pyx_k__ValueError[] = "ValueError"; +static char __pyx_k__from_stats[] = "from_stats"; +static char __pyx_k__getSentPos[] = "getSentPos"; +static char __pyx_k__max_chunks[] = "max_chunks"; +static char __pyx_k__max_length[] = "max_length"; +static char __pyx_k__precompute[] = "precompute"; +static char __pyx_k__setdefault[] = "setdefault"; +static char __pyx_k__write_text[] = "write_text"; +static char __pyx_k__END_OF_FILE[] = "END_OF_FILE"; +static char __pyx_k__END_OF_LINE[] = "END_OF_LINE"; +static char __pyx_k__RUSAGE_SELF[] = "RUSAGE_SELF"; +static char __pyx_k__from_binary[] = "from_binary"; +static char __pyx_k__initial_len[] = "initial_len"; +static char __pyx_k__next_states[] = "next_states"; +static char __pyx_k__precomputed[] = "precomputed"; +static char __pyx_k__read_binary[] = "read_binary"; +static char __pyx_k__sample_size[] = "sample_size"; +static char __pyx_k__suffix_link[] = "suffix_link"; +static char __pyx_k__use_sent_id[] = "use_sent_id"; +static char __pyx_k___doquicksort[] = "_doquicksort"; +static char __pyx_k__gzip_or_text[] = "gzip_or_text"; +static char __pyx_k__min_gap_size[] = "min_gap_size"; +static char __pyx_k__StopIteration[] = "StopIteration"; +static char __pyx_k__alphabet_size[] = "alphabet_size"; +static char __pyx_k__tight_phrases[] = "tight_phrases"; +static char __pyx_k__pattern2phrase[] = "pattern2phrase"; +static char __pyx_k__sym_fromstring[] = "sym_fromstring"; +static char __pyx_k__by_slack_factor[] = "by_slack_factor"; +static char __pyx_k__get_next_states[] = "get_next_states"; +static char __pyx_k__num_subpatterns[] = "num_subpatterns"; +static char __pyx_k__phrase_location[] = "phrase_location"; +static char __pyx_k__precompute_file[] = "precompute_file"; +static char __pyx_k__precompute_rank[] = "precompute_rank"; +static char __pyx_k__use_baeza_yates[] = "use_baeza_yates"; +static char __pyx_k__word_alignments[] = "word_alignments"; +static char __pyx_k__max_initial_size[] = "max_initial_size"; +static char __pyx_k__max_nonterminals[] = "max_nonterminals"; +static char __pyx_k__reachable_buffer[] = "reachable_buffer"; +static char __pyx_k__use_collocations[] = "use_collocations"; +static char __pyx_k__max_target_chunks[] = "max_target_chunks"; +static char __pyx_k__max_target_length[] = "max_target_length"; +static char __pyx_k__train_min_gap_size[] = "train_min_gap_size"; +static char __pyx_k__pattern2phrase_plus[] = "pattern2phrase_plus"; +static PyObject *__pyx_kp_s_1; +static PyObject *__pyx_n_s_101; +static PyObject *__pyx_n_s_102; +static PyObject *__pyx_kp_s_104; +static PyObject *__pyx_kp_s_106; +static PyObject *__pyx_kp_s_107; +static PyObject *__pyx_kp_s_108; +static PyObject *__pyx_kp_s_109; +static PyObject *__pyx_kp_s_110; +static PyObject *__pyx_kp_s_111; +static PyObject *__pyx_kp_s_112; +static PyObject *__pyx_kp_s_113; +static PyObject *__pyx_kp_s_114; +static PyObject *__pyx_kp_s_115; +static PyObject *__pyx_kp_s_116; +static PyObject *__pyx_n_s_117; +static PyObject *__pyx_kp_s_118; +static PyObject *__pyx_kp_s_119; +static PyObject *__pyx_n_s_121; +static PyObject *__pyx_kp_s_122; +static PyObject *__pyx_kp_s_123; +static PyObject *__pyx_kp_s_124; +static PyObject *__pyx_kp_s_125; +static PyObject *__pyx_kp_s_126; +static PyObject *__pyx_kp_s_127; +static PyObject *__pyx_kp_s_128; +static PyObject *__pyx_kp_s_129; +static PyObject *__pyx_kp_s_13; +static PyObject *__pyx_kp_s_130; +static PyObject *__pyx_kp_s_131; +static PyObject *__pyx_kp_s_134; +static PyObject *__pyx_kp_s_135; +static PyObject *__pyx_kp_s_139; +static PyObject *__pyx_kp_s_14; +static PyObject *__pyx_kp_s_140; +static PyObject *__pyx_kp_s_18; +static PyObject *__pyx_kp_s_2; +static PyObject *__pyx_kp_s_22; +static PyObject *__pyx_n_s_24; +static PyObject *__pyx_kp_s_28; +static PyObject *__pyx_kp_s_3; +static PyObject *__pyx_kp_s_32; +static PyObject *__pyx_kp_s_39; +static PyObject *__pyx_kp_s_4; +static PyObject *__pyx_kp_s_42; +static PyObject *__pyx_kp_s_43; +static PyObject *__pyx_kp_s_45; +static PyObject *__pyx_kp_s_47; +static PyObject *__pyx_kp_s_49; +static PyObject *__pyx_kp_s_5; +static PyObject *__pyx_kp_s_53; +static PyObject *__pyx_kp_s_55; +static PyObject *__pyx_kp_s_56; +static PyObject *__pyx_kp_s_57; +static PyObject *__pyx_kp_s_59; +static PyObject *__pyx_kp_s_6; +static PyObject *__pyx_kp_s_61; +static PyObject *__pyx_kp_s_62; +static PyObject *__pyx_kp_s_63; +static PyObject *__pyx_kp_s_64; +static PyObject *__pyx_kp_s_65; +static PyObject *__pyx_kp_s_66; +static PyObject *__pyx_kp_s_67; +static PyObject *__pyx_n_s_68; +static PyObject *__pyx_n_s_69; +static PyObject *__pyx_kp_s_7; +static PyObject *__pyx_kp_s_70; +static PyObject *__pyx_kp_s_72; +static PyObject *__pyx_kp_s_74; +static PyObject *__pyx_kp_s_76; +static PyObject *__pyx_kp_s_8; +static PyObject *__pyx_kp_s_81; +static PyObject *__pyx_kp_s_82; +static PyObject *__pyx_kp_s_83; +static PyObject *__pyx_kp_s_84; +static PyObject *__pyx_kp_s_85; +static PyObject *__pyx_kp_s_86; +static PyObject *__pyx_kp_s_87; +static PyObject *__pyx_kp_s_88; +static PyObject *__pyx_kp_s_89; +static PyObject *__pyx_kp_s_9; +static PyObject *__pyx_kp_s_90; +static PyObject *__pyx_kp_s_92; +static PyObject *__pyx_kp_s_93; +static PyObject *__pyx_kp_s_98; +static PyObject *__pyx_kp_s_99; +static PyObject *__pyx_kp_s__0; +static PyObject *__pyx_kp_s__1; +static PyObject *__pyx_n_s__END_OF_FILE; +static PyObject *__pyx_n_s__END_OF_LINE; +static PyObject *__pyx_n_s__Exception; +static PyObject *__pyx_n_s__GzipFile; +static PyObject *__pyx_n_s__IndexError; +static PyObject *__pyx_n_s__NULL; +static PyObject *__pyx_n_s__RUSAGE_SELF; +static PyObject *__pyx_n_s__StopIteration; +static PyObject *__pyx_n_s__TypeError; +static PyObject *__pyx_n_s__ValueError; +static PyObject *__pyx_n_s____enter__; +static PyObject *__pyx_n_s____exit__; +static PyObject *__pyx_n_s____main__; +static PyObject *__pyx_n_s____test__; +static PyObject *__pyx_n_s___columns; +static PyObject *__pyx_n_s___doquicksort; +static PyObject *__pyx_n_s___sa; +static PyObject *__pyx_n_s__advance; +static PyObject *__pyx_n_s__alignment; +static PyObject *__pyx_n_s__alphabet_size; +static PyObject *__pyx_n_s__arity; +static PyObject *__pyx_n_s__arr; +static PyObject *__pyx_n_s__arr_high; +static PyObject *__pyx_n_s__arr_low; +static PyObject *__pyx_n_s__by_slack_factor; +static PyObject *__pyx_n_s__category; +static PyObject *__pyx_n_s__children; +static PyObject *__pyx_n_s__cmp; +static PyObject *__pyx_n_s__col; +static PyObject *__pyx_n_s__collect; +static PyObject *__pyx_n_s__curr_idx; +static PyObject *__pyx_n_s__debug; +static PyObject *__pyx_n_s__dist; +static PyObject *__pyx_n_s__e; +static PyObject *__pyx_n_s__earray; +static PyObject *__pyx_n_s__edarray; +static PyObject *__pyx_n_s__end; +static PyObject *__pyx_n_s__enumerate; +static PyObject *__pyx_n_s__eword; +static PyObject *__pyx_n_s__extend; +static PyObject *__pyx_n_s__extended; +static PyObject *__pyx_n_s__f; +static PyObject *__pyx_n_s__filename; +static PyObject *__pyx_n_s__from_binary; +static PyObject *__pyx_n_s__from_data; +static PyObject *__pyx_n_s__from_stats; +static PyObject *__pyx_n_s__from_text; +static PyObject *__pyx_n_s__frontier; +static PyObject *__pyx_n_s__fsarray; +static PyObject *__pyx_n_s__fword; +static PyObject *__pyx_n_s__fwords; +static PyObject *__pyx_n_s__gc; +static PyObject *__pyx_n_s__getLogger; +static PyObject *__pyx_n_s__getSent; +static PyObject *__pyx_n_s__getSentId; +static PyObject *__pyx_n_s__getSentPos; +static PyObject *__pyx_n_s__get_e_id; +static PyObject *__pyx_n_s__get_f_id; +static PyObject *__pyx_n_s__get_id; +static PyObject *__pyx_n_s__get_next_states; +static PyObject *__pyx_n_s__get_word; +static PyObject *__pyx_n_s__getchunk; +static PyObject *__pyx_n_s__getrusage; +static PyObject *__pyx_n_s__gzip; +static PyObject *__pyx_n_s__gzip_or_text; +static PyObject *__pyx_n_s__h; +static PyObject *__pyx_n_s__high; +static PyObject *__pyx_n_s__i; +static PyObject *__pyx_n_s__ifrom; +static PyObject *__pyx_n_s__increment; +static PyObject *__pyx_n_s__index; +static PyObject *__pyx_n_s__info; +static PyObject *__pyx_n_s__initial_len; +static PyObject *__pyx_n_s__insert; +static PyObject *__pyx_n_s__isa; +static PyObject *__pyx_n_s__iteritems; +static PyObject *__pyx_n_s__ito; +static PyObject *__pyx_n_s__j; +static PyObject *__pyx_n_s__join; +static PyObject *__pyx_n_s__lhs; +static PyObject *__pyx_n_s__logger; +static PyObject *__pyx_n_s__logging; +static PyObject *__pyx_n_s__lookup; +static PyObject *__pyx_n_s__low; +static PyObject *__pyx_n_s__map; +static PyObject *__pyx_n_s__max_chunks; +static PyObject *__pyx_n_s__max_initial_size; +static PyObject *__pyx_n_s__max_length; +static PyObject *__pyx_n_s__max_nonterminals; +static PyObject *__pyx_n_s__max_target_chunks; +static PyObject *__pyx_n_s__max_target_length; +static PyObject *__pyx_n_s__merge; +static PyObject *__pyx_n_s__min_dist; +static PyObject *__pyx_n_s__min_gap_size; +static PyObject *__pyx_n_s__models; +static PyObject *__pyx_n_s__next_states; +static PyObject *__pyx_n_s__num_subpatterns; +static PyObject *__pyx_n_s__offset; +static PyObject *__pyx_n_s__open; +static PyObject *__pyx_n_s__pad; +static PyObject *__pyx_n_s__partition; +static PyObject *__pyx_n_s__pathlen; +static PyObject *__pyx_n_s__pattern2phrase; +static PyObject *__pyx_n_s__pattern2phrase_plus; +static PyObject *__pyx_n_s__phrase; +static PyObject *__pyx_n_s__phrase_location; +static PyObject *__pyx_n_s__precompute; +static PyObject *__pyx_n_s__precompute_file; +static PyObject *__pyx_n_s__precompute_rank; +static PyObject *__pyx_n_s__precomputed; +static PyObject *__pyx_n_s__q3sort; +static PyObject *__pyx_n_s__range; +static PyObject *__pyx_n_s__reachable; +static PyObject *__pyx_n_s__reachable_buffer; +static PyObject *__pyx_n_s__read_binary; +static PyObject *__pyx_n_s__read_text; +static PyObject *__pyx_n_s__res; +static PyObject *__pyx_n_s__reset; +static PyObject *__pyx_n_s__resource; +static PyObject *__pyx_n_s__ru_stime; +static PyObject *__pyx_n_s__ru_utime; +static PyObject *__pyx_n_s__sa; +static PyObject *__pyx_n_s__sa_high; +static PyObject *__pyx_n_s__sa_low; +static PyObject *__pyx_n_s__sample; +static PyObject *__pyx_n_s__sample_size; +static PyObject *__pyx_n_s__sampler; +static PyObject *__pyx_n_s__sarray; +static PyObject *__pyx_n_s__scores; +static PyObject *__pyx_n_s__seek; +static PyObject *__pyx_n_s__setdefault; +static PyObject *__pyx_n_s__shortest; +static PyObject *__pyx_n_s__size; +static PyObject *__pyx_n_s__skip; +static PyObject *__pyx_n_s__sorted; +static PyObject *__pyx_n_s__spanlen; +static PyObject *__pyx_n_s__split; +static PyObject *__pyx_n_s__start; +static PyObject *__pyx_n_s__stats; +static PyObject *__pyx_n_s__stop; +static PyObject *__pyx_n_s__string; +static PyObject *__pyx_n_s__suffix_link; +static PyObject *__pyx_n_s__sym_fromstring; +static PyObject *__pyx_n_s__terminal; +static PyObject *__pyx_n_s__tight_phrases; +static PyObject *__pyx_n_s__toMap; +static PyObject *__pyx_n_s__train_min_gap_size; +static PyObject *__pyx_n_s__unlink; +static PyObject *__pyx_n_s__use_baeza_yates; +static PyObject *__pyx_n_s__use_collocations; +static PyObject *__pyx_n_s__use_index; +static PyObject *__pyx_n_s__use_sent_id; +static PyObject *__pyx_n_s__w; +static PyObject *__pyx_n_s__warn; +static PyObject *__pyx_n_s__word; +static PyObject *__pyx_n_s__word_alignments; +static PyObject *__pyx_n_s__words; +static PyObject *__pyx_n_s__write; +static PyObject *__pyx_n_s__write_text; +static PyObject *__pyx_n_s__zip; +static PyObject *__pyx_int_0; +static PyObject *__pyx_int_1; +static PyObject *__pyx_int_2; +static PyObject *__pyx_int_5; +static PyObject *__pyx_int_neg_1; +static PyObject *__pyx_int_10; +static PyObject *__pyx_int_20; +static PyObject *__pyx_int_1000; +static PyObject *__pyx_int_65536; +static PyObject *__pyx_k_38; +static PyObject *__pyx_k_97; +static PyObject *__pyx_k_tuple_10; +static PyObject *__pyx_k_tuple_11; +static PyObject *__pyx_k_tuple_12; +static PyObject *__pyx_k_tuple_15; +static PyObject *__pyx_k_tuple_16; +static PyObject *__pyx_k_tuple_17; +static PyObject *__pyx_k_tuple_19; +static PyObject *__pyx_k_tuple_20; +static PyObject *__pyx_k_tuple_21; +static PyObject *__pyx_k_tuple_23; +static PyObject *__pyx_k_tuple_25; +static PyObject *__pyx_k_tuple_26; +static PyObject *__pyx_k_tuple_27; +static PyObject *__pyx_k_tuple_29; +static PyObject *__pyx_k_tuple_30; +static PyObject *__pyx_k_tuple_31; +static PyObject *__pyx_k_tuple_33; +static PyObject *__pyx_k_tuple_34; +static PyObject *__pyx_k_tuple_35; +static PyObject *__pyx_k_tuple_36; +static PyObject *__pyx_k_tuple_37; +static PyObject *__pyx_k_tuple_40; +static PyObject *__pyx_k_tuple_41; +static PyObject *__pyx_k_tuple_44; +static PyObject *__pyx_k_tuple_46; +static PyObject *__pyx_k_tuple_48; +static PyObject *__pyx_k_tuple_50; +static PyObject *__pyx_k_tuple_51; +static PyObject *__pyx_k_tuple_52; +static PyObject *__pyx_k_tuple_54; +static PyObject *__pyx_k_tuple_58; +static PyObject *__pyx_k_tuple_60; +static PyObject *__pyx_k_tuple_71; +static PyObject *__pyx_k_tuple_73; +static PyObject *__pyx_k_tuple_75; +static PyObject *__pyx_k_tuple_77; +static PyObject *__pyx_k_tuple_78; +static PyObject *__pyx_k_tuple_79; +static PyObject *__pyx_k_tuple_80; +static PyObject *__pyx_k_tuple_91; +static PyObject *__pyx_k_tuple_94; +static PyObject *__pyx_k_tuple_95; +static PyObject *__pyx_k_tuple_96; +static PyObject *__pyx_k_tuple_100; +static PyObject *__pyx_k_tuple_105; +static PyObject *__pyx_k_tuple_120; +static PyObject *__pyx_k_tuple_132; +static PyObject *__pyx_k_tuple_136; +static PyObject *__pyx_k_tuple_137; +static PyObject *__pyx_k_codeobj_133; +static PyObject *__pyx_k_codeobj_138; + +/* "_sa.pyx":5 + * import gzip + * + * cdef float monitor_cpu(): # <<<<<<<<<<<<<< + * return (resource.getrusage(resource.RUSAGE_SELF).ru_utime+ + * resource.getrusage(resource.RUSAGE_SELF).ru_stime) + */ + +static float __pyx_f_3_sa_monitor_cpu(void) { + float __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + float __pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("monitor_cpu", 0); + + /* "_sa.pyx":6 + * + * cdef float monitor_cpu(): + * return (resource.getrusage(resource.RUSAGE_SELF).ru_utime+ # <<<<<<<<<<<<<< + * resource.getrusage(resource.RUSAGE_SELF).ru_stime) + * + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__resource); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__getrusage); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__resource); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__RUSAGE_SELF); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__ru_utime); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "_sa.pyx":7 + * cdef float monitor_cpu(): + * return (resource.getrusage(resource.RUSAGE_SELF).ru_utime+ + * resource.getrusage(resource.RUSAGE_SELF).ru_stime) # <<<<<<<<<<<<<< + * + * def gzip_or_text(char* filename): + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__resource); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__getrusage); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__resource); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__RUSAGE_SELF); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__ru_stime); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyNumber_Add(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_5 = __pyx_PyFloat_AsFloat(__pyx_t_4); if (unlikely((__pyx_t_5 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_5; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_WriteUnraisable("_sa.monitor_cpu", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_1gzip_or_text(PyObject *__pyx_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyMethodDef __pyx_mdef_3_sa_1gzip_or_text = {__Pyx_NAMESTR("gzip_or_text"), (PyCFunction)__pyx_pw_3_sa_1gzip_or_text, METH_O, __Pyx_DOCSTR(0)}; +static PyObject *__pyx_pw_3_sa_1gzip_or_text(PyObject *__pyx_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("gzip_or_text (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.gzip_or_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_gzip_or_text(__pyx_self, ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_sa.pyx":9 + * resource.getrusage(resource.RUSAGE_SELF).ru_stime) + * + * def gzip_or_text(char* filename): # <<<<<<<<<<<<<< + * if filename.endswith('.gz'): + * return gzip.GzipFile(filename) + */ + +static PyObject *__pyx_pf_3_sa_gzip_or_text(CYTHON_UNUSED PyObject *__pyx_self, char *__pyx_v_filename) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("gzip_or_text", 0); + + /* "_sa.pyx":10 + * + * def gzip_or_text(char* filename): + * if filename.endswith('.gz'): # <<<<<<<<<<<<<< + * return gzip.GzipFile(filename) + * else: + */ + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = __Pyx_PyBytes_Tailmatch(((PyObject *)__pyx_t_1), ((PyObject *)__pyx_kp_s_1), 0, PY_SSIZE_T_MAX, 1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_sa.pyx":11 + * def gzip_or_text(char* filename): + * if filename.endswith('.gz'): + * return gzip.GzipFile(filename) # <<<<<<<<<<<<<< + * else: + * return open(filename) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__gzip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__GzipFile); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "_sa.pyx":13 + * return gzip.GzipFile(filename) + * else: + * return open(filename) # <<<<<<<<<<<<<< + * + * logger = logging.getLogger('cdec.sa') + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_sa.gzip_or_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_9FloatList_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_9FloatList_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_size; + int __pyx_v_increment; + int __pyx_v_initial_len; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__size,&__pyx_n_s__increment,&__pyx_n_s__initial_len,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__increment); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__initial_len); + if (value) { values[2] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + if (values[0]) { + __pyx_v_size = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_size = ((int)0); + } + if (values[1]) { + __pyx_v_increment = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_increment == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_increment = ((int)1); + } + if (values[2]) { + __pyx_v_initial_len = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_initial_len == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_initial_len = ((int)0); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.FloatList.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9FloatList___cinit__(((struct __pyx_obj_3_sa_FloatList *)__pyx_v_self), __pyx_v_size, __pyx_v_increment, __pyx_v_initial_len); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":15 + * cdef float* arr + * + * def __cinit__(self, int size=0, int increment=1, int initial_len=0): # <<<<<<<<<<<<<< + * if initial_len > size: + * size = initial_len + */ + +static int __pyx_pf_3_sa_9FloatList___cinit__(struct __pyx_obj_3_sa_FloatList *__pyx_v_self, int __pyx_v_size, int __pyx_v_increment, int __pyx_v_initial_len) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":16 + * + * def __cinit__(self, int size=0, int increment=1, int initial_len=0): + * if initial_len > size: # <<<<<<<<<<<<<< + * size = initial_len + * self.size = size + */ + __pyx_t_1 = (__pyx_v_initial_len > __pyx_v_size); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":17 + * def __cinit__(self, int size=0, int increment=1, int initial_len=0): + * if initial_len > size: + * size = initial_len # <<<<<<<<<<<<<< + * self.size = size + * self.increment = increment + */ + __pyx_v_size = __pyx_v_initial_len; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":18 + * if initial_len > size: + * size = initial_len + * self.size = size # <<<<<<<<<<<<<< + * self.increment = increment + * self.len = initial_len + */ + __pyx_v_self->size = __pyx_v_size; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":19 + * size = initial_len + * self.size = size + * self.increment = increment # <<<<<<<<<<<<<< + * self.len = initial_len + * self.arr = malloc(size*sizeof(float)) + */ + __pyx_v_self->increment = __pyx_v_increment; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":20 + * self.size = size + * self.increment = increment + * self.len = initial_len # <<<<<<<<<<<<<< + * self.arr = malloc(size*sizeof(float)) + * memset(self.arr, 0, initial_len*sizeof(float)) + */ + __pyx_v_self->len = __pyx_v_initial_len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":21 + * self.increment = increment + * self.len = initial_len + * self.arr = malloc(size*sizeof(float)) # <<<<<<<<<<<<<< + * memset(self.arr, 0, initial_len*sizeof(float)) + * + */ + __pyx_v_self->arr = ((float *)malloc((__pyx_v_size * (sizeof(float))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":22 + * self.len = initial_len + * self.arr = malloc(size*sizeof(float)) + * memset(self.arr, 0, initial_len*sizeof(float)) # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + memset(__pyx_v_self->arr, 0, (__pyx_v_initial_len * (sizeof(float)))); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_3_sa_9FloatList_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_3_sa_9FloatList_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_3_sa_9FloatList_2__dealloc__(((struct __pyx_obj_3_sa_FloatList *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":24 + * memset(self.arr, 0, initial_len*sizeof(float)) + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * free(self.arr) + * + */ + +static void __pyx_pf_3_sa_9FloatList_2__dealloc__(struct __pyx_obj_3_sa_FloatList *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":25 + * + * def __dealloc__(self): + * free(self.arr) # <<<<<<<<<<<<<< + * + * def __getitem__(self, i): + */ + free(__pyx_v_self->arr); + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9FloatList_5__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_3_sa_9FloatList_5__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9FloatList_4__getitem__(((struct __pyx_obj_3_sa_FloatList *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":27 + * free(self.arr) + * + * def __getitem__(self, i): # <<<<<<<<<<<<<< + * j = i + * if i<0: + */ + +static PyObject *__pyx_pf_3_sa_9FloatList_4__getitem__(struct __pyx_obj_3_sa_FloatList *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_v_j = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_t_5; + Py_ssize_t __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__getitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":28 + * + * def __getitem__(self, i): + * j = i # <<<<<<<<<<<<<< + * if i<0: + * j = self.len + i + */ + __Pyx_INCREF(__pyx_v_i); + __pyx_v_j = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":29 + * def __getitem__(self, i): + * j = i + * if i<0: # <<<<<<<<<<<<<< + * j = self.len + i + * if j<0 or j>=self.len: + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_v_i, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":30 + * j = i + * if i<0: + * j = self.len + i # <<<<<<<<<<<<<< + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_v_i); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_v_j); + __pyx_v_j = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":31 + * if i<0: + * j = self.len + i + * if j<0 or j>=self.len: # <<<<<<<<<<<<<< + * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) + * return self.arr[j] + */ + __pyx_t_3 = PyObject_RichCompare(__pyx_v_j, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (!__pyx_t_2) { + __pyx_t_3 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_RichCompare(__pyx_v_j, __pyx_t_3, Py_GE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = __pyx_t_4; + } else { + __pyx_t_5 = __pyx_t_2; + } + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":32 + * j = self.len + i + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) # <<<<<<<<<<<<<< + * return self.arr[j] + * + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":33 + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) + * return self.arr[j] # <<<<<<<<<<<<<< + * + * cdef void set(self, int i, float v): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_j); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyFloat_FromDouble((__pyx_v_self->arr[__pyx_t_6])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_3); + __Pyx_AddTraceback("_sa.FloatList.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_j); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":35 + * return self.arr[j] + * + * cdef void set(self, int i, float v): # <<<<<<<<<<<<<< + * j = i + * if i<0: + */ + +static void __pyx_f_3_sa_9FloatList_set(struct __pyx_obj_3_sa_FloatList *__pyx_v_self, int __pyx_v_i, float __pyx_v_v) { + int __pyx_v_j; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("set", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":36 + * + * cdef void set(self, int i, float v): + * j = i # <<<<<<<<<<<<<< + * if i<0: + * j = self.len + i + */ + __pyx_v_j = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":37 + * cdef void set(self, int i, float v): + * j = i + * if i<0: # <<<<<<<<<<<<<< + * j = self.len + i + * if j<0 or j>=self.len: + */ + __pyx_t_1 = (__pyx_v_i < 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":38 + * j = i + * if i<0: + * j = self.len + i # <<<<<<<<<<<<<< + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) + */ + __pyx_v_j = (__pyx_v_self->len + __pyx_v_i); + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":39 + * if i<0: + * j = self.len + i + * if j<0 or j>=self.len: # <<<<<<<<<<<<<< + * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) + * self.arr[j] = v + */ + __pyx_t_1 = (__pyx_v_j < 0); + if (!__pyx_t_1) { + __pyx_t_2 = (__pyx_v_j >= __pyx_v_self->len); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":40 + * j = self.len + i + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) # <<<<<<<<<<<<<< + * self.arr[j] = v + * + */ + __pyx_t_4 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_2), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":41 + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length FloatList" % (i, self.len)) + * self.arr[j] = v # <<<<<<<<<<<<<< + * + * def __setitem__(self, i, val): + */ + (__pyx_v_self->arr[__pyx_v_j]) = __pyx_v_v; + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_WriteUnraisable("_sa.FloatList.set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_9FloatList_7__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val); /*proto*/ +static int __pyx_pw_3_sa_9FloatList_7__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9FloatList_6__setitem__(((struct __pyx_obj_3_sa_FloatList *)__pyx_v_self), ((PyObject *)__pyx_v_i), ((PyObject *)__pyx_v_val)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":43 + * self.arr[j] = v + * + * def __setitem__(self, i, val): # <<<<<<<<<<<<<< + * self.set(i, val) + * + */ + +static int __pyx_pf_3_sa_9FloatList_6__setitem__(struct __pyx_obj_3_sa_FloatList *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + float __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__setitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":44 + * + * def __setitem__(self, i, val): + * self.set(i, val) # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __pyx_PyFloat_AsFloat(__pyx_v_val); if (unlikely((__pyx_t_2 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + ((struct __pyx_vtabstruct_3_sa_FloatList *)__pyx_v_self->__pyx_vtab)->set(__pyx_v_self, __pyx_t_1, __pyx_t_2); + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_sa.FloatList.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_3_sa_9FloatList_9__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_3_sa_9FloatList_9__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9FloatList_8__len__(((struct __pyx_obj_3_sa_FloatList *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":46 + * self.set(i, val) + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.len + * + */ + +static Py_ssize_t __pyx_pf_3_sa_9FloatList_8__len__(struct __pyx_obj_3_sa_FloatList *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":47 + * + * def __len__(self): + * return self.len # <<<<<<<<<<<<<< + * + * def append(self, float val): + */ + __pyx_r = __pyx_v_self->len; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9FloatList_11append(PyObject *__pyx_v_self, PyObject *__pyx_arg_val); /*proto*/ +static PyObject *__pyx_pw_3_sa_9FloatList_11append(PyObject *__pyx_v_self, PyObject *__pyx_arg_val) { + float __pyx_v_val; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("append (wrapper)", 0); + assert(__pyx_arg_val); { + __pyx_v_val = __pyx_PyFloat_AsFloat(__pyx_arg_val); if (unlikely((__pyx_v_val == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.FloatList.append", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9FloatList_10append(((struct __pyx_obj_3_sa_FloatList *)__pyx_v_self), ((float)__pyx_v_val)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":49 + * return self.len + * + * def append(self, float val): # <<<<<<<<<<<<<< + * if self.len == self.size: + * self.size = self.size + self.increment + */ + +static PyObject *__pyx_pf_3_sa_9FloatList_10append(struct __pyx_obj_3_sa_FloatList *__pyx_v_self, float __pyx_v_val) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("append", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":50 + * + * def append(self, float val): + * if self.len == self.size: # <<<<<<<<<<<<<< + * self.size = self.size + self.increment + * self.arr = realloc(self.arr, self.size*sizeof(float)) + */ + __pyx_t_1 = (__pyx_v_self->len == __pyx_v_self->size); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":51 + * def append(self, float val): + * if self.len == self.size: + * self.size = self.size + self.increment # <<<<<<<<<<<<<< + * self.arr = realloc(self.arr, self.size*sizeof(float)) + * self.arr[self.len] = val + */ + __pyx_v_self->size = (__pyx_v_self->size + __pyx_v_self->increment); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":52 + * if self.len == self.size: + * self.size = self.size + self.increment + * self.arr = realloc(self.arr, self.size*sizeof(float)) # <<<<<<<<<<<<<< + * self.arr[self.len] = val + * self.len = self.len + 1 + */ + __pyx_v_self->arr = ((float *)realloc(__pyx_v_self->arr, (__pyx_v_self->size * (sizeof(float))))); + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":53 + * self.size = self.size + self.increment + * self.arr = realloc(self.arr, self.size*sizeof(float)) + * self.arr[self.len] = val # <<<<<<<<<<<<<< + * self.len = self.len + 1 + * + */ + (__pyx_v_self->arr[__pyx_v_self->len]) = __pyx_v_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":54 + * self.arr = realloc(self.arr, self.size*sizeof(float)) + * self.arr[self.len] = val + * self.len = self.len + 1 # <<<<<<<<<<<<<< + * + * cdef void write_handle(self, FILE* f): + */ + __pyx_v_self->len = (__pyx_v_self->len + 1); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":56 + * self.len = self.len + 1 + * + * cdef void write_handle(self, FILE* f): # <<<<<<<<<<<<<< + * fwrite(&(self.len), sizeof(float), 1, f) + * fwrite(self.arr, sizeof(float), self.len, f) + */ + +static void __pyx_f_3_sa_9FloatList_write_handle(struct __pyx_obj_3_sa_FloatList *__pyx_v_self, FILE *__pyx_v_f) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_handle", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":57 + * + * cdef void write_handle(self, FILE* f): + * fwrite(&(self.len), sizeof(float), 1, f) # <<<<<<<<<<<<<< + * fwrite(self.arr, sizeof(float), self.len, f) + * + */ + fwrite((&__pyx_v_self->len), (sizeof(float)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":58 + * cdef void write_handle(self, FILE* f): + * fwrite(&(self.len), sizeof(float), 1, f) + * fwrite(self.arr, sizeof(float), self.len, f) # <<<<<<<<<<<<<< + * + * def write(self, char* filename): + */ + fwrite(__pyx_v_self->arr, (sizeof(float)), __pyx_v_self->len, __pyx_v_f); + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9FloatList_13write(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_9FloatList_13write(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.FloatList.write", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9FloatList_12write(((struct __pyx_obj_3_sa_FloatList *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":60 + * fwrite(self.arr, sizeof(float), self.len, f) + * + * def write(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "w") + */ + +static PyObject *__pyx_pf_3_sa_9FloatList_12write(struct __pyx_obj_3_sa_FloatList *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":62 + * def write(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "w") # <<<<<<<<<<<<<< + * self.write_handle(f) + * fclose(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":63 + * cdef FILE* f + * f = fopen(filename, "w") + * self.write_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + ((struct __pyx_vtabstruct_3_sa_FloatList *)__pyx_v_self->__pyx_vtab)->write_handle(__pyx_v_self, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":64 + * f = fopen(filename, "w") + * self.write_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + * + * cdef void read_handle(self, FILE* f): + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":66 + * fclose(f) + * + * cdef void read_handle(self, FILE* f): # <<<<<<<<<<<<<< + * free(self.arr) + * fread(&(self.len), sizeof(float), 1, f) + */ + +static void __pyx_f_3_sa_9FloatList_read_handle(struct __pyx_obj_3_sa_FloatList *__pyx_v_self, FILE *__pyx_v_f) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_handle", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":67 + * + * cdef void read_handle(self, FILE* f): + * free(self.arr) # <<<<<<<<<<<<<< + * fread(&(self.len), sizeof(float), 1, f) + * self.arr = malloc(self.len * sizeof(float)) + */ + free(__pyx_v_self->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":68 + * cdef void read_handle(self, FILE* f): + * free(self.arr) + * fread(&(self.len), sizeof(float), 1, f) # <<<<<<<<<<<<<< + * self.arr = malloc(self.len * sizeof(float)) + * self.size = self.len + */ + fread((&__pyx_v_self->len), (sizeof(float)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":69 + * free(self.arr) + * fread(&(self.len), sizeof(float), 1, f) + * self.arr = malloc(self.len * sizeof(float)) # <<<<<<<<<<<<<< + * self.size = self.len + * fread(self.arr, sizeof(float), self.len, f) + */ + __pyx_v_self->arr = ((float *)malloc((__pyx_v_self->len * (sizeof(float))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":70 + * fread(&(self.len), sizeof(float), 1, f) + * self.arr = malloc(self.len * sizeof(float)) + * self.size = self.len # <<<<<<<<<<<<<< + * fread(self.arr, sizeof(float), self.len, f) + * + */ + __pyx_v_self->size = __pyx_v_self->len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":71 + * self.arr = malloc(self.len * sizeof(float)) + * self.size = self.len + * fread(self.arr, sizeof(float), self.len, f) # <<<<<<<<<<<<<< + * + * def read(self, char* filename): + */ + fread(__pyx_v_self->arr, (sizeof(float)), __pyx_v_self->len, __pyx_v_f); + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9FloatList_15read(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_9FloatList_15read(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.FloatList.read", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9FloatList_14read(((struct __pyx_obj_3_sa_FloatList *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":73 + * fread(self.arr, sizeof(float), self.len, f) + * + * def read(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "r") + */ + +static PyObject *__pyx_pf_3_sa_9FloatList_14read(struct __pyx_obj_3_sa_FloatList *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":75 + * def read(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "r") # <<<<<<<<<<<<<< + * self.read_handle(f) + * fclose(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":76 + * cdef FILE* f + * f = fopen(filename, "r") + * self.read_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + */ + ((struct __pyx_vtabstruct_3_sa_FloatList *)__pyx_v_self->__pyx_vtab)->read_handle(__pyx_v_self, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/float_list.pxi":77 + * f = fopen(filename, "r") + * self.read_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_7IntList_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_7IntList_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_size; + int __pyx_v_increment; + int __pyx_v_initial_len; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__size,&__pyx_n_s__increment,&__pyx_n_s__initial_len,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__increment); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__initial_len); + if (value) { values[2] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + if (values[0]) { + __pyx_v_size = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_size = ((int)0); + } + if (values[1]) { + __pyx_v_increment = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_increment == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_increment = ((int)1); + } + if (values[2]) { + __pyx_v_initial_len = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_initial_len == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_initial_len = ((int)0); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.IntList.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_7IntList___cinit__(((struct __pyx_obj_3_sa_IntList *)__pyx_v_self), __pyx_v_size, __pyx_v_increment, __pyx_v_initial_len); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":15 + * cdef int* arr + * + * def __cinit__(self, int size=0, int increment=1, int initial_len=0): # <<<<<<<<<<<<<< + * if initial_len > size: + * size = initial_len + */ + +static int __pyx_pf_3_sa_7IntList___cinit__(struct __pyx_obj_3_sa_IntList *__pyx_v_self, int __pyx_v_size, int __pyx_v_increment, int __pyx_v_initial_len) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":16 + * + * def __cinit__(self, int size=0, int increment=1, int initial_len=0): + * if initial_len > size: # <<<<<<<<<<<<<< + * size = initial_len + * self.size = size + */ + __pyx_t_1 = (__pyx_v_initial_len > __pyx_v_size); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":17 + * def __cinit__(self, int size=0, int increment=1, int initial_len=0): + * if initial_len > size: + * size = initial_len # <<<<<<<<<<<<<< + * self.size = size + * self.increment = increment + */ + __pyx_v_size = __pyx_v_initial_len; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":18 + * if initial_len > size: + * size = initial_len + * self.size = size # <<<<<<<<<<<<<< + * self.increment = increment + * self.len = initial_len + */ + __pyx_v_self->size = __pyx_v_size; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":19 + * size = initial_len + * self.size = size + * self.increment = increment # <<<<<<<<<<<<<< + * self.len = initial_len + * self.arr = malloc(size*sizeof(int)) + */ + __pyx_v_self->increment = __pyx_v_increment; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":20 + * self.size = size + * self.increment = increment + * self.len = initial_len # <<<<<<<<<<<<<< + * self.arr = malloc(size*sizeof(int)) + * memset(self.arr, 0, initial_len*sizeof(int)) + */ + __pyx_v_self->len = __pyx_v_initial_len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":21 + * self.increment = increment + * self.len = initial_len + * self.arr = malloc(size*sizeof(int)) # <<<<<<<<<<<<<< + * memset(self.arr, 0, initial_len*sizeof(int)) + * + */ + __pyx_v_self->arr = ((int *)malloc((__pyx_v_size * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":22 + * self.len = initial_len + * self.arr = malloc(size*sizeof(int)) + * memset(self.arr, 0, initial_len*sizeof(int)) # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + memset(__pyx_v_self->arr, 0, (__pyx_v_initial_len * (sizeof(int)))); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_7IntList_3__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_7IntList_3__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_7IntList_2__str__(((struct __pyx_obj_3_sa_IntList *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":24 + * memset(self.arr, 0, initial_len*sizeof(int)) + * + * def __str__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * ret = "IntList[" + */ + +static PyObject *__pyx_pf_3_sa_7IntList_2__str__(struct __pyx_obj_3_sa_IntList *__pyx_v_self) { + PyObject *__pyx_v_ret = NULL; + int __pyx_v_idx; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__str__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":26 + * def __str__(self): + * cdef unsigned i + * ret = "IntList[" # <<<<<<<<<<<<<< + * for idx in range(self.size): + * if idx>0: + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); + __pyx_v_ret = ((PyObject *)__pyx_kp_s_3); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":27 + * cdef unsigned i + * ret = "IntList[" + * for idx in range(self.size): # <<<<<<<<<<<<<< + * if idx>0: + * ret += "," + */ + __pyx_t_1 = __pyx_v_self->size; + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_v_idx = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":28 + * ret = "IntList[" + * for idx in range(self.size): + * if idx>0: # <<<<<<<<<<<<<< + * ret += "," + * ret += str(self.arr[idx]) + */ + __pyx_t_3 = (__pyx_v_idx > 0); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":29 + * for idx in range(self.size): + * if idx>0: + * ret += "," # <<<<<<<<<<<<<< + * ret += str(self.arr[idx]) + * ret += "]" + */ + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_ret, ((PyObject *)__pyx_kp_s_4)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_v_ret); + __pyx_v_ret = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":30 + * if idx>0: + * ret += "," + * ret += str(self.arr[idx]) # <<<<<<<<<<<<<< + * ret += "]" + * ret += "len=" + */ + __pyx_t_4 = PyInt_FromLong((__pyx_v_self->arr[__pyx_v_idx])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_ret, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_v_ret); + __pyx_v_ret = __pyx_t_5; + __pyx_t_5 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":31 + * ret += "," + * ret += str(self.arr[idx]) + * ret += "]" # <<<<<<<<<<<<<< + * ret += "len=" + * ret += self.len + */ + __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_ret, ((PyObject *)__pyx_kp_s_5)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_v_ret); + __pyx_v_ret = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":32 + * ret += str(self.arr[idx]) + * ret += "]" + * ret += "len=" # <<<<<<<<<<<<<< + * ret += self.len + * return ret + */ + __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_ret, ((PyObject *)__pyx_kp_s_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_v_ret); + __pyx_v_ret = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":33 + * ret += "]" + * ret += "len=" + * ret += self.len # <<<<<<<<<<<<<< + * return ret + * + */ + __pyx_t_5 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_ret, __pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_v_ret); + __pyx_v_ret = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":34 + * ret += "len=" + * ret += self.len + * return ret # <<<<<<<<<<<<<< + * + * def index(self, val): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_ret); + __pyx_r = __pyx_v_ret; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_sa.IntList.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_ret); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_7IntList_5index(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/ +static PyObject *__pyx_pw_3_sa_7IntList_5index(PyObject *__pyx_v_self, PyObject *__pyx_v_val) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("index (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_7IntList_4index(((struct __pyx_obj_3_sa_IntList *)__pyx_v_self), ((PyObject *)__pyx_v_val)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":36 + * return ret + * + * def index(self, val): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(self.len): + */ + +static PyObject *__pyx_pf_3_sa_7IntList_4index(struct __pyx_obj_3_sa_IntList *__pyx_v_self, PyObject *__pyx_v_val) { + unsigned int __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("index", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":38 + * def index(self, val): + * cdef unsigned i + * for i in range(self.len): # <<<<<<<<<<<<<< + * if self.arr[i] == val: + * return i + */ + __pyx_t_1 = __pyx_v_self->len; + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_v_i = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":39 + * cdef unsigned i + * for i in range(self.len): + * if self.arr[i] == val: # <<<<<<<<<<<<<< + * return i + * return IndexError + */ + __pyx_t_3 = PyInt_FromLong((__pyx_v_self->arr[__pyx_v_i])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_v_val, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":40 + * for i in range(self.len): + * if self.arr[i] == val: + * return i # <<<<<<<<<<<<<< + * return IndexError + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = PyLong_FromUnsignedLong(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":41 + * if self.arr[i] == val: + * return i + * return IndexError # <<<<<<<<<<<<<< + * + * def partition(self,start,end): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_builtin_IndexError); + __pyx_r = __pyx_builtin_IndexError; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_sa.IntList.index", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_7IntList_7partition(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_3_sa_7IntList_7partition(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_start = 0; + PyObject *__pyx_v_end = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("partition (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("partition", 1, 2, 2, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "partition") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_start = values[0]; + __pyx_v_end = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("partition", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.IntList.partition", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_7IntList_6partition(((struct __pyx_obj_3_sa_IntList *)__pyx_v_self), __pyx_v_start, __pyx_v_end); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":43 + * return IndexError + * + * def partition(self,start,end): # <<<<<<<<<<<<<< + * pivot = self.arr[end] + * bottom = start-1 + */ + +static PyObject *__pyx_pf_3_sa_7IntList_6partition(struct __pyx_obj_3_sa_IntList *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_end) { + PyObject *__pyx_v_pivot = NULL; + PyObject *__pyx_v_bottom = NULL; + PyObject *__pyx_v_top = NULL; + long __pyx_v_done; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + Py_ssize_t __pyx_t_5; + int __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("partition", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":44 + * + * def partition(self,start,end): + * pivot = self.arr[end] # <<<<<<<<<<<<<< + * bottom = start-1 + * top = end + */ + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_end); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->arr[__pyx_t_1])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_pivot = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":45 + * def partition(self,start,end): + * pivot = self.arr[end] + * bottom = start-1 # <<<<<<<<<<<<<< + * top = end + * done = 0 + */ + __pyx_t_2 = PyNumber_Subtract(__pyx_v_start, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_bottom = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":46 + * pivot = self.arr[end] + * bottom = start-1 + * top = end # <<<<<<<<<<<<<< + * done = 0 + * while not done: + */ + __Pyx_INCREF(__pyx_v_end); + __pyx_v_top = __pyx_v_end; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":47 + * bottom = start-1 + * top = end + * done = 0 # <<<<<<<<<<<<<< + * while not done: + * while not done: + */ + __pyx_v_done = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":48 + * top = end + * done = 0 + * while not done: # <<<<<<<<<<<<<< + * while not done: + * bottom += 1 + */ + while (1) { + __pyx_t_3 = (!__pyx_v_done); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":49 + * done = 0 + * while not done: + * while not done: # <<<<<<<<<<<<<< + * bottom += 1 + * if bottom == top: + */ + while (1) { + __pyx_t_3 = (!__pyx_v_done); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":50 + * while not done: + * while not done: + * bottom += 1 # <<<<<<<<<<<<<< + * if bottom == top: + * done = 1 + */ + __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_v_bottom, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_v_bottom); + __pyx_v_bottom = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":51 + * while not done: + * bottom += 1 + * if bottom == top: # <<<<<<<<<<<<<< + * done = 1 + * break + */ + __pyx_t_2 = PyObject_RichCompare(__pyx_v_bottom, __pyx_v_top, Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":52 + * bottom += 1 + * if bottom == top: + * done = 1 # <<<<<<<<<<<<<< + * break + * if self.arr[bottom] > pivot: + */ + __pyx_v_done = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":53 + * if bottom == top: + * done = 1 + * break # <<<<<<<<<<<<<< + * if self.arr[bottom] > pivot: + * self.arr[top] = self.arr[bottom] + */ + goto __pyx_L6_break; + goto __pyx_L7; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":54 + * done = 1 + * break + * if self.arr[bottom] > pivot: # <<<<<<<<<<<<<< + * self.arr[top] = self.arr[bottom] + * break + */ + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_bottom); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->arr[__pyx_t_1])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_v_pivot, Py_GT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":55 + * break + * if self.arr[bottom] > pivot: + * self.arr[top] = self.arr[bottom] # <<<<<<<<<<<<<< + * break + * while not done: + */ + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_bottom); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_top); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + (__pyx_v_self->arr[__pyx_t_5]) = (__pyx_v_self->arr[__pyx_t_1]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":56 + * if self.arr[bottom] > pivot: + * self.arr[top] = self.arr[bottom] + * break # <<<<<<<<<<<<<< + * while not done: + * top -= 1 + */ + goto __pyx_L6_break; + goto __pyx_L8; + } + __pyx_L8:; + } + __pyx_L6_break:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":57 + * self.arr[top] = self.arr[bottom] + * break + * while not done: # <<<<<<<<<<<<<< + * top -= 1 + * if top == bottom: + */ + while (1) { + __pyx_t_3 = (!__pyx_v_done); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":58 + * break + * while not done: + * top -= 1 # <<<<<<<<<<<<<< + * if top == bottom: + * done = 1 + */ + __pyx_t_4 = PyNumber_InPlaceSubtract(__pyx_v_top, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_v_top); + __pyx_v_top = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":59 + * while not done: + * top -= 1 + * if top == bottom: # <<<<<<<<<<<<<< + * done = 1 + * break + */ + __pyx_t_4 = PyObject_RichCompare(__pyx_v_top, __pyx_v_bottom, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":60 + * top -= 1 + * if top == bottom: + * done = 1 # <<<<<<<<<<<<<< + * break + * if self.arr[top] < pivot: + */ + __pyx_v_done = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":61 + * if top == bottom: + * done = 1 + * break # <<<<<<<<<<<<<< + * if self.arr[top] < pivot: + * self.arr[bottom] = self.arr[top] + */ + goto __pyx_L10_break; + goto __pyx_L11; + } + __pyx_L11:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":62 + * done = 1 + * break + * if self.arr[top] < pivot: # <<<<<<<<<<<<<< + * self.arr[bottom] = self.arr[top] + * break + */ + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_top); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong((__pyx_v_self->arr[__pyx_t_1])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_v_pivot, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":63 + * break + * if self.arr[top] < pivot: + * self.arr[bottom] = self.arr[top] # <<<<<<<<<<<<<< + * break + * self.arr[top] = pivot + */ + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_top); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_bottom); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + (__pyx_v_self->arr[__pyx_t_5]) = (__pyx_v_self->arr[__pyx_t_1]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":64 + * if self.arr[top] < pivot: + * self.arr[bottom] = self.arr[top] + * break # <<<<<<<<<<<<<< + * self.arr[top] = pivot + * return top + */ + goto __pyx_L10_break; + goto __pyx_L12; + } + __pyx_L12:; + } + __pyx_L10_break:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":65 + * self.arr[bottom] = self.arr[top] + * break + * self.arr[top] = pivot # <<<<<<<<<<<<<< + * return top + * + */ + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_pivot); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_top); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + (__pyx_v_self->arr[__pyx_t_1]) = __pyx_t_6; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":66 + * break + * self.arr[top] = pivot + * return top # <<<<<<<<<<<<<< + * + * def _doquicksort(self,start,end): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_top); + __pyx_r = __pyx_v_top; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_sa.IntList.partition", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_pivot); + __Pyx_XDECREF(__pyx_v_bottom); + __Pyx_XDECREF(__pyx_v_top); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_7IntList_9_doquicksort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_3_sa_7IntList_9_doquicksort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_start = 0; + PyObject *__pyx_v_end = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_doquicksort (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_doquicksort", 1, 2, 2, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_doquicksort") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_start = values[0]; + __pyx_v_end = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("_doquicksort", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.IntList._doquicksort", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_7IntList_8_doquicksort(((struct __pyx_obj_3_sa_IntList *)__pyx_v_self), __pyx_v_start, __pyx_v_end); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":68 + * return top + * + * def _doquicksort(self,start,end): # <<<<<<<<<<<<<< + * if start < end: + * split = self.partition(start,end) + */ + +static PyObject *__pyx_pf_3_sa_7IntList_8_doquicksort(struct __pyx_obj_3_sa_IntList *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_end) { + PyObject *__pyx_v_split = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_doquicksort", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":69 + * + * def _doquicksort(self,start,end): + * if start < end: # <<<<<<<<<<<<<< + * split = self.partition(start,end) + * self._doquicksort(start,split-1) + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_v_start, __pyx_v_end, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":70 + * def _doquicksort(self,start,end): + * if start < end: + * split = self.partition(start,end) # <<<<<<<<<<<<<< + * self._doquicksort(start,split-1) + * self._doquicksort(split+1,end) + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__partition); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_start); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_start); + __Pyx_GIVEREF(__pyx_v_start); + __Pyx_INCREF(__pyx_v_end); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_end); + __Pyx_GIVEREF(__pyx_v_end); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_v_split = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":71 + * if start < end: + * split = self.partition(start,end) + * self._doquicksort(start,split-1) # <<<<<<<<<<<<<< + * self._doquicksort(split+1,end) + * else: + */ + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___doquicksort); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyNumber_Subtract(__pyx_v_split, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_start); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_start); + __Pyx_GIVEREF(__pyx_v_start); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":72 + * split = self.partition(start,end) + * self._doquicksort(start,split-1) + * self._doquicksort(split+1,end) # <<<<<<<<<<<<<< + * else: + * return + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___doquicksort); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyNumber_Add(__pyx_v_split, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_end); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_end); + __Pyx_GIVEREF(__pyx_v_end); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":74 + * self._doquicksort(split+1,end) + * else: + * return # <<<<<<<<<<<<<< + * + * def sort(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_sa.IntList._doquicksort", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_split); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_7IntList_11sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_3_sa_7IntList_11sort(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("sort (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_7IntList_10sort(((struct __pyx_obj_3_sa_IntList *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":76 + * return + * + * def sort(self): # <<<<<<<<<<<<<< + * self._doquicksort(0,self.len-1) + * + */ + +static PyObject *__pyx_pf_3_sa_7IntList_10sort(struct __pyx_obj_3_sa_IntList *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("sort", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":77 + * + * def sort(self): + * self._doquicksort(0,self.len-1) # <<<<<<<<<<<<<< + * + * def reset(self): + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s___doquicksort); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->len - 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + __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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.IntList.sort", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_7IntList_13reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_3_sa_7IntList_13reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("reset (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_7IntList_12reset(((struct __pyx_obj_3_sa_IntList *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":79 + * self._doquicksort(0,self.len-1) + * + * def reset(self): # <<<<<<<<<<<<<< + * self.len = 0 + * + */ + +static PyObject *__pyx_pf_3_sa_7IntList_12reset(struct __pyx_obj_3_sa_IntList *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("reset", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":80 + * + * def reset(self): + * self.len = 0 # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->len = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_3_sa_7IntList_15__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_3_sa_7IntList_15__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_3_sa_7IntList_14__dealloc__(((struct __pyx_obj_3_sa_IntList *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":82 + * self.len = 0 + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * free(self.arr) + * + */ + +static void __pyx_pf_3_sa_7IntList_14__dealloc__(struct __pyx_obj_3_sa_IntList *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":83 + * + * def __dealloc__(self): + * free(self.arr) # <<<<<<<<<<<<<< + * + * def __getitem__(self, index): + */ + free(__pyx_v_self->arr); + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_7IntList_17__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index); /*proto*/ +static PyObject *__pyx_pw_3_sa_7IntList_17__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_7IntList_16__getitem__(((struct __pyx_obj_3_sa_IntList *)__pyx_v_self), ((PyObject *)__pyx_v_index)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":85 + * free(self.arr) + * + * def __getitem__(self, index): # <<<<<<<<<<<<<< + * cdef int i, j, k + * if isinstance(index, int): + */ + +static PyObject *__pyx_pf_3_sa_7IntList_16__getitem__(struct __pyx_obj_3_sa_IntList *__pyx_v_self, PyObject *__pyx_v_index) { + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_k; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__getitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":87 + * def __getitem__(self, index): + * cdef int i, j, k + * if isinstance(index, int): # <<<<<<<<<<<<<< + * j = index + * if j < 0: + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyInt_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_index, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":88 + * cdef int i, j, k + * if isinstance(index, int): + * j = index # <<<<<<<<<<<<<< + * if j < 0: + * j = self.len + j + */ + __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_v_index); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_j = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":89 + * if isinstance(index, int): + * j = index + * if j < 0: # <<<<<<<<<<<<<< + * j = self.len + j + * if j<0 or j>=self.len: + */ + __pyx_t_2 = (__pyx_v_j < 0); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":90 + * j = index + * if j < 0: + * j = self.len + j # <<<<<<<<<<<<<< + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length IntList" % (index, self.len)) + */ + __pyx_v_j = (__pyx_v_self->len + __pyx_v_j); + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":91 + * if j < 0: + * j = self.len + j + * if j<0 or j>=self.len: # <<<<<<<<<<<<<< + * raise IndexError("Requested index %d of %d-length IntList" % (index, self.len)) + * return self.arr[j] + */ + __pyx_t_2 = (__pyx_v_j < 0); + if (!__pyx_t_2) { + __pyx_t_4 = (__pyx_v_j >= __pyx_v_self->len); + __pyx_t_5 = __pyx_t_4; + } else { + __pyx_t_5 = __pyx_t_2; + } + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":92 + * j = self.len + j + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length IntList" % (index, self.len)) # <<<<<<<<<<<<<< + * return self.arr[j] + * elif isinstance(index, slice): + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(__pyx_v_index); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_index); + __Pyx_GIVEREF(__pyx_v_index); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_7), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":93 + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length IntList" % (index, self.len)) + * return self.arr[j] # <<<<<<<<<<<<<< + * elif isinstance(index, slice): + * i = index.start + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong((__pyx_v_self->arr[__pyx_v_j])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":94 + * raise IndexError("Requested index %d of %d-length IntList" % (index, self.len)) + * return self.arr[j] + * elif isinstance(index, slice): # <<<<<<<<<<<<<< + * i = index.start + * j = index.stop + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PySlice_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_5 = __Pyx_TypeCheck(__pyx_v_index, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":95 + * return self.arr[j] + * elif isinstance(index, slice): + * i = index.start # <<<<<<<<<<<<<< + * j = index.stop + * if i < 0: + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_i = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":96 + * elif isinstance(index, slice): + * i = index.start + * j = index.stop # <<<<<<<<<<<<<< + * if i < 0: + * i = self.len + i + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__stop); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_j = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":97 + * i = index.start + * j = index.stop + * if i < 0: # <<<<<<<<<<<<<< + * i = self.len + i + * if j < 0: + */ + __pyx_t_5 = (__pyx_v_i < 0); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":98 + * j = index.stop + * if i < 0: + * i = self.len + i # <<<<<<<<<<<<<< + * if j < 0: + * j = self.len + j + */ + __pyx_v_i = (__pyx_v_self->len + __pyx_v_i); + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":99 + * if i < 0: + * i = self.len + i + * if j < 0: # <<<<<<<<<<<<<< + * j = self.len + j + * if i < 0 or i >= self.len or j < 0 or j > self.len: + */ + __pyx_t_5 = (__pyx_v_j < 0); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":100 + * i = self.len + i + * if j < 0: + * j = self.len + j # <<<<<<<<<<<<<< + * if i < 0 or i >= self.len or j < 0 or j > self.len: + * raise IndexError("Requested index %d:%d of %d-length IntList" % (index.start, index.stop, self.len)) + */ + __pyx_v_j = (__pyx_v_self->len + __pyx_v_j); + goto __pyx_L7; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":101 + * if j < 0: + * j = self.len + j + * if i < 0 or i >= self.len or j < 0 or j > self.len: # <<<<<<<<<<<<<< + * raise IndexError("Requested index %d:%d of %d-length IntList" % (index.start, index.stop, self.len)) + * result = () + */ + __pyx_t_5 = (__pyx_v_i < 0); + if (!__pyx_t_5) { + __pyx_t_2 = (__pyx_v_i >= __pyx_v_self->len); + if (!__pyx_t_2) { + __pyx_t_4 = (__pyx_v_j < 0); + if (!__pyx_t_4) { + __pyx_t_7 = (__pyx_v_j > __pyx_v_self->len); + __pyx_t_8 = __pyx_t_7; + } else { + __pyx_t_8 = __pyx_t_4; + } + __pyx_t_4 = __pyx_t_8; + } else { + __pyx_t_4 = __pyx_t_2; + } + __pyx_t_2 = __pyx_t_4; + } else { + __pyx_t_2 = __pyx_t_5; + } + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":102 + * j = self.len + j + * if i < 0 or i >= self.len or j < 0 or j > self.len: + * raise IndexError("Requested index %d:%d of %d-length IntList" % (index.start, index.stop, self.len)) # <<<<<<<<<<<<<< + * result = () + * for k from i <= k < j: + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = PyObject_GetAttr(__pyx_v_index, __pyx_n_s__stop); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_9 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_t_1 = 0; + __pyx_t_6 = 0; + __pyx_t_9 = 0; + __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_8), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_9)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); + __pyx_t_9 = 0; + __pyx_t_9 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L8; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":103 + * if i < 0 or i >= self.len or j < 0 or j > self.len: + * raise IndexError("Requested index %d:%d of %d-length IntList" % (index.start, index.stop, self.len)) + * result = () # <<<<<<<<<<<<<< + * for k from i <= k < j: + * result = result + (self.arr[k],) + */ + __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); + __pyx_v_result = __pyx_empty_tuple; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":104 + * raise IndexError("Requested index %d:%d of %d-length IntList" % (index.start, index.stop, self.len)) + * result = () + * for k from i <= k < j: # <<<<<<<<<<<<<< + * result = result + (self.arr[k],) + * return result + */ + __pyx_t_3 = __pyx_v_j; + for (__pyx_v_k = __pyx_v_i; __pyx_v_k < __pyx_t_3; __pyx_v_k++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":105 + * result = () + * for k from i <= k < j: + * result = result + (self.arr[k],) # <<<<<<<<<<<<<< + * return result + * else: + */ + __pyx_t_9 = PyInt_FromLong((__pyx_v_self->arr[__pyx_v_k])); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_9 = PyNumber_Add(((PyObject *)__pyx_v_result), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_result)); + __pyx_v_result = __pyx_t_9; + __pyx_t_9 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":106 + * for k from i <= k < j: + * result = result + (self.arr[k],) + * return result # <<<<<<<<<<<<<< + * else: + * raise TypeError("Illegal key type %s for IntList" % type(index)) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":108 + * return result + * else: + * raise TypeError("Illegal key type %s for IntList" % type(index)) # <<<<<<<<<<<<<< + * + * cdef void set(self, int i, int val): + */ + __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), ((PyObject *)Py_TYPE(__pyx_v_index))); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_9)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); + __pyx_t_9 = 0; + __pyx_t_9 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("_sa.IntList.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":110 + * raise TypeError("Illegal key type %s for IntList" % type(index)) + * + * cdef void set(self, int i, int val): # <<<<<<<<<<<<<< + * j = i + * if i<0: + */ + +static void __pyx_f_3_sa_7IntList_set(struct __pyx_obj_3_sa_IntList *__pyx_v_self, int __pyx_v_i, int __pyx_v_val) { + int __pyx_v_j; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("set", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":111 + * + * cdef void set(self, int i, int val): + * j = i # <<<<<<<<<<<<<< + * if i<0: + * j = self.len + i + */ + __pyx_v_j = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":112 + * cdef void set(self, int i, int val): + * j = i + * if i<0: # <<<<<<<<<<<<<< + * j = self.len + i + * if j<0 or j>=self.len: + */ + __pyx_t_1 = (__pyx_v_i < 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":113 + * j = i + * if i<0: + * j = self.len + i # <<<<<<<<<<<<<< + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length IntList" % (i, self.len)) + */ + __pyx_v_j = (__pyx_v_self->len + __pyx_v_i); + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":114 + * if i<0: + * j = self.len + i + * if j<0 or j>=self.len: # <<<<<<<<<<<<<< + * raise IndexError("Requested index %d of %d-length IntList" % (i, self.len)) + * self.arr[j] = val + */ + __pyx_t_1 = (__pyx_v_j < 0); + if (!__pyx_t_1) { + __pyx_t_2 = (__pyx_v_j >= __pyx_v_self->len); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":115 + * j = self.len + i + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length IntList" % (i, self.len)) # <<<<<<<<<<<<<< + * self.arr[j] = val + * + */ + __pyx_t_4 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyInt_FromLong(__pyx_v_self->len); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_7), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_builtin_IndexError, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":116 + * if j<0 or j>=self.len: + * raise IndexError("Requested index %d of %d-length IntList" % (i, self.len)) + * self.arr[j] = val # <<<<<<<<<<<<<< + * + * def __setitem__(self, i, val): + */ + (__pyx_v_self->arr[__pyx_v_j]) = __pyx_v_val; + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_WriteUnraisable("_sa.IntList.set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_7IntList_19__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val); /*proto*/ +static int __pyx_pw_3_sa_7IntList_19__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_7IntList_18__setitem__(((struct __pyx_obj_3_sa_IntList *)__pyx_v_self), ((PyObject *)__pyx_v_i), ((PyObject *)__pyx_v_val)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":118 + * self.arr[j] = val + * + * def __setitem__(self, i, val): # <<<<<<<<<<<<<< + * self.set(i, val) + * + */ + +static int __pyx_pf_3_sa_7IntList_18__setitem__(struct __pyx_obj_3_sa_IntList *__pyx_v_self, PyObject *__pyx_v_i, PyObject *__pyx_v_val) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__setitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":119 + * + * def __setitem__(self, i, val): + * self.set(i, val) # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_v_val); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->__pyx_vtab)->set(__pyx_v_self, __pyx_t_1, __pyx_t_2); + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_sa.IntList.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_3_sa_7IntList_21__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_3_sa_7IntList_21__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_7IntList_20__len__(((struct __pyx_obj_3_sa_IntList *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":121 + * self.set(i, val) + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.len + * + */ + +static Py_ssize_t __pyx_pf_3_sa_7IntList_20__len__(struct __pyx_obj_3_sa_IntList *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":122 + * + * def __len__(self): + * return self.len # <<<<<<<<<<<<<< + * + * def getSize(self): + */ + __pyx_r = __pyx_v_self->len; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_7IntList_23getSize(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_3_sa_7IntList_23getSize(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getSize (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_7IntList_22getSize(((struct __pyx_obj_3_sa_IntList *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":124 + * return self.len + * + * def getSize(self): # <<<<<<<<<<<<<< + * return self.size + * + */ + +static PyObject *__pyx_pf_3_sa_7IntList_22getSize(struct __pyx_obj_3_sa_IntList *__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("getSize", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":125 + * + * def getSize(self): + * return self.size # <<<<<<<<<<<<<< + * + * def append(self, int val): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_sa.IntList.getSize", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_7IntList_25append(PyObject *__pyx_v_self, PyObject *__pyx_arg_val); /*proto*/ +static PyObject *__pyx_pw_3_sa_7IntList_25append(PyObject *__pyx_v_self, PyObject *__pyx_arg_val) { + int __pyx_v_val; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("append (wrapper)", 0); + assert(__pyx_arg_val); { + __pyx_v_val = __Pyx_PyInt_AsInt(__pyx_arg_val); if (unlikely((__pyx_v_val == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.IntList.append", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_7IntList_24append(((struct __pyx_obj_3_sa_IntList *)__pyx_v_self), ((int)__pyx_v_val)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":127 + * return self.size + * + * def append(self, int val): # <<<<<<<<<<<<<< + * self._append(val) + * + */ + +static PyObject *__pyx_pf_3_sa_7IntList_24append(struct __pyx_obj_3_sa_IntList *__pyx_v_self, int __pyx_v_val) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("append", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":128 + * + * def append(self, int val): + * self._append(val) # <<<<<<<<<<<<<< + * + * cdef void _append(self, int val): + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->__pyx_vtab)->_append(__pyx_v_self, __pyx_v_val); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":130 + * self._append(val) + * + * cdef void _append(self, int val): # <<<<<<<<<<<<<< + * if self.len == self.size: + * self.size = self.size + self.increment + */ + +static void __pyx_f_3_sa_7IntList__append(struct __pyx_obj_3_sa_IntList *__pyx_v_self, int __pyx_v_val) { + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("_append", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":131 + * + * cdef void _append(self, int val): + * if self.len == self.size: # <<<<<<<<<<<<<< + * self.size = self.size + self.increment + * self.arr = realloc(self.arr, self.size*sizeof(int)) + */ + __pyx_t_1 = (__pyx_v_self->len == __pyx_v_self->size); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":132 + * cdef void _append(self, int val): + * if self.len == self.size: + * self.size = self.size + self.increment # <<<<<<<<<<<<<< + * self.arr = realloc(self.arr, self.size*sizeof(int)) + * self.arr[self.len] = val + */ + __pyx_v_self->size = (__pyx_v_self->size + __pyx_v_self->increment); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":133 + * if self.len == self.size: + * self.size = self.size + self.increment + * self.arr = realloc(self.arr, self.size*sizeof(int)) # <<<<<<<<<<<<<< + * self.arr[self.len] = val + * self.len = self.len + 1 + */ + __pyx_v_self->arr = ((int *)realloc(__pyx_v_self->arr, (__pyx_v_self->size * (sizeof(int))))); + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":134 + * self.size = self.size + self.increment + * self.arr = realloc(self.arr, self.size*sizeof(int)) + * self.arr[self.len] = val # <<<<<<<<<<<<<< + * self.len = self.len + 1 + * + */ + (__pyx_v_self->arr[__pyx_v_self->len]) = __pyx_v_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":135 + * self.arr = realloc(self.arr, self.size*sizeof(int)) + * self.arr[self.len] = val + * self.len = self.len + 1 # <<<<<<<<<<<<<< + * + * def extend(self, other): + */ + __pyx_v_self->len = (__pyx_v_self->len + 1); + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_7IntList_27extend(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_3_sa_7IntList_27extend(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("extend (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_7IntList_26extend(((struct __pyx_obj_3_sa_IntList *)__pyx_v_self), ((PyObject *)__pyx_v_other)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":137 + * self.len = self.len + 1 + * + * def extend(self, other): # <<<<<<<<<<<<<< + * self._extend(other) + * + */ + +static PyObject *__pyx_pf_3_sa_7IntList_26extend(struct __pyx_obj_3_sa_IntList *__pyx_v_self, PyObject *__pyx_v_other) { + 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("extend", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":138 + * + * def extend(self, other): + * self._extend(other) # <<<<<<<<<<<<<< + * + * cdef void _extend(self, IntList other): + */ + if (!(likely(((__pyx_v_other) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_other, __pyx_ptype_3_sa_IntList))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_v_other; + __Pyx_INCREF(__pyx_t_1); + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->__pyx_vtab)->_extend(__pyx_v_self, ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1)); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_sa.IntList.extend", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":140 + * self._extend(other) + * + * cdef void _extend(self, IntList other): # <<<<<<<<<<<<<< + * self._extend_arr(other.arr, other.len) + * + */ + +static void __pyx_f_3_sa_7IntList__extend(struct __pyx_obj_3_sa_IntList *__pyx_v_self, struct __pyx_obj_3_sa_IntList *__pyx_v_other) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_extend", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":141 + * + * cdef void _extend(self, IntList other): + * self._extend_arr(other.arr, other.len) # <<<<<<<<<<<<<< + * + * cdef void _extend_arr(self, int* other, int other_len): + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->__pyx_vtab)->_extend_arr(__pyx_v_self, __pyx_v_other->arr, __pyx_v_other->len); + + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":143 + * self._extend_arr(other.arr, other.len) + * + * cdef void _extend_arr(self, int* other, int other_len): # <<<<<<<<<<<<<< + * if self.size < self.len + other_len: + * self.size = self.len + other_len + */ + +static void __pyx_f_3_sa_7IntList__extend_arr(struct __pyx_obj_3_sa_IntList *__pyx_v_self, int *__pyx_v_other, int __pyx_v_other_len) { + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("_extend_arr", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":144 + * + * cdef void _extend_arr(self, int* other, int other_len): + * if self.size < self.len + other_len: # <<<<<<<<<<<<<< + * self.size = self.len + other_len + * self.arr = realloc(self.arr, self.size*sizeof(int)) + */ + __pyx_t_1 = (__pyx_v_self->size < (__pyx_v_self->len + __pyx_v_other_len)); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":145 + * cdef void _extend_arr(self, int* other, int other_len): + * if self.size < self.len + other_len: + * self.size = self.len + other_len # <<<<<<<<<<<<<< + * self.arr = realloc(self.arr, self.size*sizeof(int)) + * memcpy(self.arr+self.len, other, other_len*sizeof(int)) + */ + __pyx_v_self->size = (__pyx_v_self->len + __pyx_v_other_len); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":146 + * if self.size < self.len + other_len: + * self.size = self.len + other_len + * self.arr = realloc(self.arr, self.size*sizeof(int)) # <<<<<<<<<<<<<< + * memcpy(self.arr+self.len, other, other_len*sizeof(int)) + * self.len = self.len + other_len + */ + __pyx_v_self->arr = ((int *)realloc(__pyx_v_self->arr, (__pyx_v_self->size * (sizeof(int))))); + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":147 + * self.size = self.len + other_len + * self.arr = realloc(self.arr, self.size*sizeof(int)) + * memcpy(self.arr+self.len, other, other_len*sizeof(int)) # <<<<<<<<<<<<<< + * self.len = self.len + other_len + * + */ + memcpy((__pyx_v_self->arr + __pyx_v_self->len), __pyx_v_other, (__pyx_v_other_len * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":148 + * self.arr = realloc(self.arr, self.size*sizeof(int)) + * memcpy(self.arr+self.len, other, other_len*sizeof(int)) + * self.len = self.len + other_len # <<<<<<<<<<<<<< + * + * cdef void _clear(self): + */ + __pyx_v_self->len = (__pyx_v_self->len + __pyx_v_other_len); + + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":150 + * self.len = self.len + other_len + * + * cdef void _clear(self): # <<<<<<<<<<<<<< + * free(self.arr) + * self.len = 0 + */ + +static void __pyx_f_3_sa_7IntList__clear(struct __pyx_obj_3_sa_IntList *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_clear", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":151 + * + * cdef void _clear(self): + * free(self.arr) # <<<<<<<<<<<<<< + * self.len = 0 + * self.size = 0 + */ + free(__pyx_v_self->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":152 + * cdef void _clear(self): + * free(self.arr) + * self.len = 0 # <<<<<<<<<<<<<< + * self.size = 0 + * self.arr = malloc(0) + */ + __pyx_v_self->len = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":153 + * free(self.arr) + * self.len = 0 + * self.size = 0 # <<<<<<<<<<<<<< + * self.arr = malloc(0) + * + */ + __pyx_v_self->size = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":154 + * self.len = 0 + * self.size = 0 + * self.arr = malloc(0) # <<<<<<<<<<<<<< + * + * cdef void write_handle(self, FILE* f): + */ + __pyx_v_self->arr = ((int *)malloc(0)); + + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":156 + * self.arr = malloc(0) + * + * cdef void write_handle(self, FILE* f): # <<<<<<<<<<<<<< + * fwrite(&(self.len), sizeof(int), 1, f) + * fwrite(self.arr, sizeof(int), self.len, f) + */ + +static void __pyx_f_3_sa_7IntList_write_handle(struct __pyx_obj_3_sa_IntList *__pyx_v_self, FILE *__pyx_v_f) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_handle", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":157 + * + * cdef void write_handle(self, FILE* f): + * fwrite(&(self.len), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fwrite(self.arr, sizeof(int), self.len, f) + * + */ + fwrite((&__pyx_v_self->len), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":158 + * cdef void write_handle(self, FILE* f): + * fwrite(&(self.len), sizeof(int), 1, f) + * fwrite(self.arr, sizeof(int), self.len, f) # <<<<<<<<<<<<<< + * + * def write(self, char* filename): + */ + fwrite(__pyx_v_self->arr, (sizeof(int)), __pyx_v_self->len, __pyx_v_f); + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_7IntList_29write(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_7IntList_29write(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.IntList.write", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_7IntList_28write(((struct __pyx_obj_3_sa_IntList *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":160 + * fwrite(self.arr, sizeof(int), self.len, f) + * + * def write(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "w") + */ + +static PyObject *__pyx_pf_3_sa_7IntList_28write(struct __pyx_obj_3_sa_IntList *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":162 + * def write(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "w") # <<<<<<<<<<<<<< + * self.write_handle(f) + * fclose(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":163 + * cdef FILE* f + * f = fopen(filename, "w") + * self.write_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->__pyx_vtab)->write_handle(__pyx_v_self, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":164 + * f = fopen(filename, "w") + * self.write_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + * + * cdef void read_handle(self, FILE* f): + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":166 + * fclose(f) + * + * cdef void read_handle(self, FILE* f): # <<<<<<<<<<<<<< + * (self.arr) + * fread(&(self.len), sizeof(int), 1, f) + */ + +static void __pyx_f_3_sa_7IntList_read_handle(struct __pyx_obj_3_sa_IntList *__pyx_v_self, FILE *__pyx_v_f) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_handle", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":167 + * + * cdef void read_handle(self, FILE* f): + * (self.arr) # <<<<<<<<<<<<<< + * fread(&(self.len), sizeof(int), 1, f) + * self.arr = malloc(self.len * sizeof(int)) + */ + __pyx_v_self->arr; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":168 + * cdef void read_handle(self, FILE* f): + * (self.arr) + * fread(&(self.len), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * self.arr = malloc(self.len * sizeof(int)) + * self.size = self.len + */ + fread((&__pyx_v_self->len), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":169 + * (self.arr) + * fread(&(self.len), sizeof(int), 1, f) + * self.arr = malloc(self.len * sizeof(int)) # <<<<<<<<<<<<<< + * self.size = self.len + * fread(self.arr, sizeof(int), self.len, f) + */ + __pyx_v_self->arr = ((int *)malloc((__pyx_v_self->len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":170 + * fread(&(self.len), sizeof(int), 1, f) + * self.arr = malloc(self.len * sizeof(int)) + * self.size = self.len # <<<<<<<<<<<<<< + * fread(self.arr, sizeof(int), self.len, f) + * + */ + __pyx_v_self->size = __pyx_v_self->len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":171 + * self.arr = malloc(self.len * sizeof(int)) + * self.size = self.len + * fread(self.arr, sizeof(int), self.len, f) # <<<<<<<<<<<<<< + * + * def read(self, char* filename): + */ + fread(__pyx_v_self->arr, (sizeof(int)), __pyx_v_self->len, __pyx_v_f); + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_7IntList_31read(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_7IntList_31read(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.IntList.read", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_7IntList_30read(((struct __pyx_obj_3_sa_IntList *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":173 + * fread(self.arr, sizeof(int), self.len, f) + * + * def read(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "r") + */ + +static PyObject *__pyx_pf_3_sa_7IntList_30read(struct __pyx_obj_3_sa_IntList *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":175 + * def read(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "r") # <<<<<<<<<<<<<< + * self.read_handle(f) + * fclose(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":176 + * cdef FILE* f + * f = fopen(filename, "r") + * self.read_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->__pyx_vtab)->read_handle(__pyx_v_self, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":177 + * f = fopen(filename, "r") + * self.read_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_9StringMap_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_9StringMap_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; + __pyx_r = __pyx_pf_3_sa_9StringMap___cinit__(((struct __pyx_obj_3_sa_StringMap *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":13 + * cdef int index(self, char *s) + * + * def __cinit__(self): # <<<<<<<<<<<<<< + * self.vocab = stringmap_new() + * + */ + +static int __pyx_pf_3_sa_9StringMap___cinit__(struct __pyx_obj_3_sa_StringMap *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":14 + * + * def __cinit__(self): + * self.vocab = stringmap_new() # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->vocab = stringmap_new(); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_3_sa_9StringMap_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_3_sa_9StringMap_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_3_sa_9StringMap_2__dealloc__(((struct __pyx_obj_3_sa_StringMap *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":16 + * self.vocab = stringmap_new() + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * stringmap_delete(self.vocab) + * + */ + +static void __pyx_pf_3_sa_9StringMap_2__dealloc__(struct __pyx_obj_3_sa_StringMap *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":17 + * + * def __dealloc__(self): + * stringmap_delete(self.vocab) # <<<<<<<<<<<<<< + * + * cdef char *word(self, int i): + */ + stringmap_delete(__pyx_v_self->vocab); + + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":19 + * stringmap_delete(self.vocab) + * + * cdef char *word(self, int i): # <<<<<<<<<<<<<< + * return stringmap_word(self.vocab, i) + * + */ + +static char *__pyx_f_3_sa_9StringMap_word(struct __pyx_obj_3_sa_StringMap *__pyx_v_self, int __pyx_v_i) { + char *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("word", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":20 + * + * cdef char *word(self, int i): + * return stringmap_word(self.vocab, i) # <<<<<<<<<<<<<< + * + * cdef int index(self, char *s): + */ + __pyx_r = stringmap_word(__pyx_v_self->vocab, __pyx_v_i); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":22 + * return stringmap_word(self.vocab, i) + * + * cdef int index(self, char *s): # <<<<<<<<<<<<<< + * return stringmap_index(self.vocab, s) + */ + +static int __pyx_f_3_sa_9StringMap_index(struct __pyx_obj_3_sa_StringMap *__pyx_v_self, char *__pyx_v_s) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("index", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/str_map.pxi":23 + * + * cdef int index(self, char *s): + * return stringmap_index(self.vocab, s) # <<<<<<<<<<<<<< + */ + __pyx_r = stringmap_index(__pyx_v_self->vocab, __pyx_v_s); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_9DataArray_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_9DataArray_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_from_binary = 0; + PyObject *__pyx_v_from_text = 0; + int __pyx_v_use_sent_id; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__from_binary,&__pyx_n_s__from_text,&__pyx_n_s__use_sent_id,0}; + PyObject* values[3] = {0,0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":17 + * cdef bint use_sent_id + * + * def __cinit__(self, from_binary=None, from_text=None, bint use_sent_id=False): # <<<<<<<<<<<<<< + * self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} + * self.id2word = ["END_OF_FILE", "END_OF_LINE"] + */ + values[0] = ((PyObject *)Py_None); + values[1] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_binary); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_text); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_sent_id); + if (value) { values[2] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_from_binary = values[0]; + __pyx_v_from_text = values[1]; + if (values[2]) { + __pyx_v_use_sent_id = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_use_sent_id == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_use_sent_id = ((int)0); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.DataArray.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9DataArray___cinit__(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), __pyx_v_from_binary, __pyx_v_from_text, __pyx_v_use_sent_id); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_9DataArray___cinit__(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text, int __pyx_v_use_sent_id) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":18 + * + * def __cinit__(self, from_binary=None, from_text=None, bint use_sent_id=False): + * self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} # <<<<<<<<<<<<<< + * self.id2word = ["END_OF_FILE", "END_OF_LINE"] + * self.data = IntList(1000,1000) + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__END_OF_FILE), __pyx_int_0) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__END_OF_LINE), __pyx_int_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_GOTREF(__pyx_v_self->word2id); + __Pyx_DECREF(__pyx_v_self->word2id); + __pyx_v_self->word2id = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":19 + * def __cinit__(self, from_binary=None, from_text=None, bint use_sent_id=False): + * self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} + * self.id2word = ["END_OF_FILE", "END_OF_LINE"] # <<<<<<<<<<<<<< + * self.data = IntList(1000,1000) + * self.sent_id = IntList(1000,1000) + */ + __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_n_s__END_OF_FILE)); + PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__END_OF_FILE)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__END_OF_FILE)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__END_OF_LINE)); + PyList_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_n_s__END_OF_LINE)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__END_OF_LINE)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_GOTREF(__pyx_v_self->id2word); + __Pyx_DECREF(__pyx_v_self->id2word); + __pyx_v_self->id2word = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":20 + * self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} + * self.id2word = ["END_OF_FILE", "END_OF_LINE"] + * self.data = IntList(1000,1000) # <<<<<<<<<<<<<< + * self.sent_id = IntList(1000,1000) + * self.sent_index = IntList(1000,1000) + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->data); + __Pyx_DECREF(((PyObject *)__pyx_v_self->data)); + __pyx_v_self->data = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":21 + * self.id2word = ["END_OF_FILE", "END_OF_LINE"] + * self.data = IntList(1000,1000) + * self.sent_id = IntList(1000,1000) # <<<<<<<<<<<<<< + * self.sent_index = IntList(1000,1000) + * self.use_sent_id = use_sent_id + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_k_tuple_11), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->sent_id); + __Pyx_DECREF(((PyObject *)__pyx_v_self->sent_id)); + __pyx_v_self->sent_id = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":22 + * self.data = IntList(1000,1000) + * self.sent_id = IntList(1000,1000) + * self.sent_index = IntList(1000,1000) # <<<<<<<<<<<<<< + * self.use_sent_id = use_sent_id + * if from_binary: + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_k_tuple_12), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->sent_index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->sent_index)); + __pyx_v_self->sent_index = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":23 + * self.sent_id = IntList(1000,1000) + * self.sent_index = IntList(1000,1000) + * self.use_sent_id = use_sent_id # <<<<<<<<<<<<<< + * if from_binary: + * self.read_binary(from_binary) + */ + __pyx_v_self->use_sent_id = __pyx_v_use_sent_id; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":24 + * self.sent_index = IntList(1000,1000) + * self.use_sent_id = use_sent_id + * if from_binary: # <<<<<<<<<<<<<< + * self.read_binary(from_binary) + * elif from_text: + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_binary); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":25 + * self.use_sent_id = use_sent_id + * if from_binary: + * self.read_binary(from_binary) # <<<<<<<<<<<<<< + * elif from_text: + * self.read_text(from_text) + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_binary); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_from_binary); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_binary); + __Pyx_GIVEREF(__pyx_v_from_binary); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":26 + * if from_binary: + * self.read_binary(from_binary) + * elif from_text: # <<<<<<<<<<<<<< + * self.read_text(from_text) + * + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_text); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":27 + * self.read_binary(from_binary) + * elif from_text: + * self.read_text(from_text) # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_text); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_from_text); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_text); + __Pyx_GIVEREF(__pyx_v_from_text); + __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_sa.DataArray.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_3_sa_9DataArray_3__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_3_sa_9DataArray_3__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9DataArray_2__len__(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":29 + * self.read_text(from_text) + * + * def __len__(self): # <<<<<<<<<<<<<< + * return len(self.data) + * + */ + +static Py_ssize_t __pyx_pf_3_sa_9DataArray_2__len__(struct __pyx_obj_3_sa_DataArray *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":30 + * + * def __len__(self): + * return len(self.data) # <<<<<<<<<<<<<< + * + * def getSentId(self, i): + */ + __pyx_t_1 = ((PyObject *)__pyx_v_self->data); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_sa.DataArray.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9DataArray_5getSentId(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_3_sa_9DataArray_5getSentId(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getSentId (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9DataArray_4getSentId(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":32 + * return len(self.data) + * + * def getSentId(self, i): # <<<<<<<<<<<<<< + * return self.sent_id.arr[i] + * + */ + +static PyObject *__pyx_pf_3_sa_9DataArray_4getSentId(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("getSentId", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":33 + * + * def getSentId(self, i): + * return self.sent_id.arr[i] # <<<<<<<<<<<<<< + * + * def getSent(self, i): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->sent_id->arr[__pyx_t_1])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_sa.DataArray.getSentId", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9DataArray_7getSent(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_3_sa_9DataArray_7getSent(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getSent (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9DataArray_6getSent(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":35 + * return self.sent_id.arr[i] + * + * def getSent(self, i): # <<<<<<<<<<<<<< + * cdef int j, start, stop + * sent = [] + */ + +static PyObject *__pyx_pf_3_sa_9DataArray_6getSent(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_i) { + int __pyx_v_start; + int __pyx_v_stop; + PyObject *__pyx_v_sent = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("getSent", 0); + __Pyx_INCREF(__pyx_v_i); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":37 + * def getSent(self, i): + * cdef int j, start, stop + * sent = [] # <<<<<<<<<<<<<< + * start = self.sent_index.arr[i] + * stop = self.sent_index.arr[i+1] + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sent = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":38 + * cdef int j, start, stop + * sent = [] + * start = self.sent_index.arr[i] # <<<<<<<<<<<<<< + * stop = self.sent_index.arr[i+1] + * for i from start <= i < stop: + */ + __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_start = (__pyx_v_self->sent_index->arr[__pyx_t_2]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":39 + * sent = [] + * start = self.sent_index.arr[i] + * stop = self.sent_index.arr[i+1] # <<<<<<<<<<<<<< + * for i from start <= i < stop: + * sent.append(self.id2word[self.data.arr[i]]) + */ + __pyx_t_1 = PyNumber_Add(__pyx_v_i, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_stop = (__pyx_v_self->sent_index->arr[__pyx_t_2]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":40 + * start = self.sent_index.arr[i] + * stop = self.sent_index.arr[i+1] + * for i from start <= i < stop: # <<<<<<<<<<<<<< + * sent.append(self.id2word[self.data.arr[i]]) + * return sent + */ + __pyx_t_3 = __pyx_v_stop; + for (__pyx_t_4 = __pyx_v_start; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) { + __pyx_t_1 = PyInt_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":41 + * stop = self.sent_index.arr[i+1] + * for i from start <= i < stop: + * sent.append(self.id2word[self.data.arr[i]]) # <<<<<<<<<<<<<< + * return sent + * + */ + __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_self->id2word, (__pyx_v_self->data->arr[__pyx_t_2]), sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyList_Append(__pyx_v_sent, __pyx_t_1); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":40 + * start = self.sent_index.arr[i] + * stop = self.sent_index.arr[i+1] + * for i from start <= i < stop: # <<<<<<<<<<<<<< + * sent.append(self.id2word[self.data.arr[i]]) + * return sent + */ + __pyx_t_1 = PyInt_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":42 + * for i from start <= i < stop: + * sent.append(self.id2word[self.data.arr[i]]) + * return sent # <<<<<<<<<<<<<< + * + * def getSentPos(self, loc): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_sent)); + __pyx_r = ((PyObject *)__pyx_v_sent); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_sa.DataArray.getSent", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_sent); + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9DataArray_9getSentPos(PyObject *__pyx_v_self, PyObject *__pyx_v_loc); /*proto*/ +static PyObject *__pyx_pw_3_sa_9DataArray_9getSentPos(PyObject *__pyx_v_self, PyObject *__pyx_v_loc) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getSentPos (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9DataArray_8getSentPos(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_loc)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":44 + * return sent + * + * def getSentPos(self, loc): # <<<<<<<<<<<<<< + * return loc - self.sent_index.arr[self.sent_id.arr[loc]] + * + */ + +static PyObject *__pyx_pf_3_sa_9DataArray_8getSentPos(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_loc) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("getSentPos", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":45 + * + * def getSentPos(self, loc): + * return loc - self.sent_index.arr[self.sent_id.arr[loc]] # <<<<<<<<<<<<<< + * + * def get_id(self, word): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_loc); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->sent_index->arr[(__pyx_v_self->sent_id->arr[__pyx_t_1])])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_Subtract(__pyx_v_loc, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.DataArray.getSentPos", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9DataArray_11get_id(PyObject *__pyx_v_self, PyObject *__pyx_v_word); /*proto*/ +static PyObject *__pyx_pw_3_sa_9DataArray_11get_id(PyObject *__pyx_v_self, PyObject *__pyx_v_word) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_id (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9DataArray_10get_id(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_word)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":47 + * return loc - self.sent_index.arr[self.sent_id.arr[loc]] + * + * def get_id(self, word): # <<<<<<<<<<<<<< + * if not word in self.word2id: + * self.word2id[word] = len(self.id2word) + */ + +static PyObject *__pyx_pf_3_sa_9DataArray_10get_id(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_word) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_id", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":48 + * + * def get_id(self, word): + * if not word in self.word2id: # <<<<<<<<<<<<<< + * self.word2id[word] = len(self.id2word) + * self.id2word.append(word) + */ + __pyx_t_1 = ((PySequence_Contains(__pyx_v_self->word2id, __pyx_v_word))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = (!__pyx_t_1); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":49 + * def get_id(self, word): + * if not word in self.word2id: + * self.word2id[word] = len(self.id2word) # <<<<<<<<<<<<<< + * self.id2word.append(word) + * return self.word2id[word] + */ + __pyx_t_3 = __pyx_v_self->id2word; + __Pyx_INCREF(__pyx_t_3); + __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyObject_SetItem(__pyx_v_self->word2id, __pyx_v_word, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":50 + * if not word in self.word2id: + * self.word2id[word] = len(self.id2word) + * self.id2word.append(word) # <<<<<<<<<<<<<< + * return self.word2id[word] + * + */ + __pyx_t_3 = __Pyx_PyObject_Append(__pyx_v_self->id2word, __pyx_v_word); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":51 + * self.word2id[word] = len(self.id2word) + * self.id2word.append(word) + * return self.word2id[word] # <<<<<<<<<<<<<< + * + * def get_word(self, id): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = PyObject_GetItem(__pyx_v_self->word2id, __pyx_v_word); if (!__pyx_t_3) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.DataArray.get_id", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9DataArray_13get_word(PyObject *__pyx_v_self, PyObject *__pyx_v_id); /*proto*/ +static PyObject *__pyx_pw_3_sa_9DataArray_13get_word(PyObject *__pyx_v_self, PyObject *__pyx_v_id) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_word (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9DataArray_12get_word(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_id)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":53 + * return self.word2id[word] + * + * def get_word(self, id): # <<<<<<<<<<<<<< + * return self.id2word[id] + * + */ + +static PyObject *__pyx_pf_3_sa_9DataArray_12get_word(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_id) { + 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("get_word", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":54 + * + * def get_word(self, id): + * return self.id2word[id] # <<<<<<<<<<<<<< + * + * def write_text(self, char* filename): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetItem(__pyx_v_self->id2word, __pyx_v_id); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_sa.DataArray.get_word", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9DataArray_15write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_9DataArray_15write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_text (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.DataArray.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9DataArray_14write_text(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":56 + * return self.id2word[id] + * + * def write_text(self, char* filename): # <<<<<<<<<<<<<< + * with open(filename, "w") as f: + * for w_id in self.data: + */ + +static PyObject *__pyx_pf_3_sa_9DataArray_14write_text(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_v_w_id = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + int __pyx_t_14; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_text", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":57 + * + * def write_text(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * for w_id in self.data: + * if w_id > 1: + */ + /*with:*/ { + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_f = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":58 + * def write_text(self, char* filename): + * with open(filename, "w") as f: + * for w_id in self.data: # <<<<<<<<<<<<<< + * if w_id > 1: + * f.write("%s " % self.get_word(w_id)) + */ + if (PyList_CheckExact(((PyObject *)__pyx_v_self->data)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->data))) { + __pyx_t_4 = ((PyObject *)__pyx_v_self->data); __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(((PyObject *)__pyx_v_self->data)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else { + __pyx_t_1 = __pyx_t_9(__pyx_t_4); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF(__pyx_v_w_id); + __pyx_v_w_id = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":59 + * with open(filename, "w") as f: + * for w_id in self.data: + * if w_id > 1: # <<<<<<<<<<<<<< + * f.write("%s " % self.get_word(w_id)) + * if w_id == 1: + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_v_w_id, __pyx_int_1, Py_GT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":60 + * for w_id in self.data: + * if w_id > 1: + * f.write("%s " % self.get_word(w_id)) # <<<<<<<<<<<<<< + * if w_id == 1: + * f.write("\n") + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_word); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_INCREF(__pyx_v_w_id); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_w_id); + __Pyx_GIVEREF(__pyx_v_w_id); + __pyx_t_12 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; + __pyx_t_11 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_13), __pyx_t_12); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_11)); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)__pyx_t_11)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_11)); + __pyx_t_11 = 0; + __pyx_t_11 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L18; + } + __pyx_L18:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":61 + * if w_id > 1: + * f.write("%s " % self.get_word(w_id)) + * if w_id == 1: # <<<<<<<<<<<<<< + * f.write("\n") + * + */ + __pyx_t_11 = PyObject_RichCompare(__pyx_v_w_id, __pyx_int_1, Py_EQ); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":62 + * f.write("%s " % self.get_word(w_id)) + * if w_id == 1: + * f.write("\n") # <<<<<<<<<<<<<< + * + * def read_text(self, char* filename): + */ + __pyx_t_11 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_12 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_k_tuple_15), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L19; + } + __pyx_L19:; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":57 + * + * def write_text(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * for w_id in self.data: + * if w_id > 1: + */ + /*except:*/ { + __Pyx_AddTraceback("_sa.DataArray.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_12, &__pyx_t_11) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_12); + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_INCREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_11); + __Pyx_GIVEREF(__pyx_t_11); + __pyx_t_13 = PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_13); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_14 = (!__pyx_t_10); + if (__pyx_t_14) { + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_11); + __Pyx_ErrRestore(__pyx_t_4, __pyx_t_12, __pyx_t_11); + __pyx_t_4 = 0; __pyx_t_12 = 0; __pyx_t_11 = 0; + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L22; + } + __pyx_L22:; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_16, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L23; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L23:; + } + + __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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("_sa.DataArray.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_w_id); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9DataArray_17read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_9DataArray_17read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_text (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.DataArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9DataArray_16read_text(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":64 + * f.write("\n") + * + * def read_text(self, char* filename): # <<<<<<<<<<<<<< + * cdef int word_count = 0 + * with gzip_or_text(filename) as fp: + */ + +static PyObject *__pyx_pf_3_sa_9DataArray_16read_text(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { + int __pyx_v_word_count; + PyObject *__pyx_v_fp = NULL; + PyObject *__pyx_v_line_num = NULL; + PyObject *__pyx_v_line = NULL; + PyObject *__pyx_v_word = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + Py_ssize_t __pyx_t_11; + PyObject *(*__pyx_t_12)(PyObject *); + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + int __pyx_t_15; + PyObject *__pyx_t_16 = NULL; + int __pyx_t_17; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_text", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":65 + * + * def read_text(self, char* filename): + * cdef int word_count = 0 # <<<<<<<<<<<<<< + * with gzip_or_text(filename) as fp: + * for line_num, line in enumerate(fp): + */ + __pyx_v_word_count = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":66 + * def read_text(self, char* filename): + * cdef int word_count = 0 + * with gzip_or_text(filename) as fp: # <<<<<<<<<<<<<< + * for line_num, line in enumerate(fp): + * self.sent_index.append(word_count) + */ + /*with:*/ { + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__gzip_or_text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __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[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_1); + __pyx_v_fp = __pyx_t_1; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":67 + * cdef int word_count = 0 + * with gzip_or_text(filename) as fp: + * for line_num, line in enumerate(fp): # <<<<<<<<<<<<<< + * self.sent_index.append(word_count) + * for word in line.split(): + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_1 = __pyx_int_0; + if (PyList_CheckExact(__pyx_v_fp) || PyTuple_CheckExact(__pyx_v_fp)) { + __pyx_t_2 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_3); __pyx_t_8++; + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_3); __pyx_t_8++; + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else { + __pyx_t_3 = __pyx_t_9(__pyx_t_2); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_line); + __pyx_v_line = __pyx_t_3; + __pyx_t_3 = 0; + __Pyx_INCREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_line_num); + __pyx_v_line_num = __pyx_t_1; + __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":68 + * with gzip_or_text(filename) as fp: + * for line_num, line in enumerate(fp): + * self.sent_index.append(word_count) # <<<<<<<<<<<<<< + * for word in line.split(): + * self.data.append(self.get_id(word)) + */ + __pyx_t_3 = PyInt_FromLong(__pyx_v_word_count); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_index), __pyx_t_3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":69 + * for line_num, line in enumerate(fp): + * self.sent_index.append(word_count) + * for word in line.split(): # <<<<<<<<<<<<<< + * self.data.append(self.get_id(word)) + * if self.use_sent_id: + */ + __pyx_t_10 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_3 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_10 = __pyx_t_3; __Pyx_INCREF(__pyx_t_10); __pyx_t_11 = 0; + __pyx_t_12 = NULL; + } else { + __pyx_t_11 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_12 = Py_TYPE(__pyx_t_10)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (!__pyx_t_12 && PyList_CheckExact(__pyx_t_10)) { + if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_10)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_11); __Pyx_INCREF(__pyx_t_3); __pyx_t_11++; + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_10, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else if (!__pyx_t_12 && PyTuple_CheckExact(__pyx_t_10)) { + if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_10)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_11); __Pyx_INCREF(__pyx_t_3); __pyx_t_11++; + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_10, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else { + __pyx_t_3 = __pyx_t_12(__pyx_t_10); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_word); + __pyx_v_word = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":70 + * self.sent_index.append(word_count) + * for word in line.split(): + * self.data.append(self.get_id(word)) # <<<<<<<<<<<<<< + * if self.use_sent_id: + * self.sent_id.append(line_num) + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_id); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_INCREF(__pyx_v_word); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_v_word); + __Pyx_GIVEREF(__pyx_v_word); + __pyx_t_14 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + __pyx_t_13 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->data), __pyx_t_14); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":71 + * for word in line.split(): + * self.data.append(self.get_id(word)) + * if self.use_sent_id: # <<<<<<<<<<<<<< + * self.sent_id.append(line_num) + * word_count = word_count + 1 + */ + if (__pyx_v_self->use_sent_id) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":72 + * self.data.append(self.get_id(word)) + * if self.use_sent_id: + * self.sent_id.append(line_num) # <<<<<<<<<<<<<< + * word_count = word_count + 1 + * self.data.append(1) + */ + __pyx_t_13 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_id), __pyx_v_line_num); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + goto __pyx_L20; + } + __pyx_L20:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":73 + * if self.use_sent_id: + * self.sent_id.append(line_num) + * word_count = word_count + 1 # <<<<<<<<<<<<<< + * self.data.append(1) + * if self.use_sent_id: + */ + __pyx_v_word_count = (__pyx_v_word_count + 1); + } + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":74 + * self.sent_id.append(line_num) + * word_count = word_count + 1 + * self.data.append(1) # <<<<<<<<<<<<<< + * if self.use_sent_id: + * self.sent_id.append(line_num) + */ + __pyx_t_10 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->data), __pyx_int_1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":75 + * word_count = word_count + 1 + * self.data.append(1) + * if self.use_sent_id: # <<<<<<<<<<<<<< + * self.sent_id.append(line_num) + * word_count = word_count + 1 + */ + if (__pyx_v_self->use_sent_id) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":76 + * self.data.append(1) + * if self.use_sent_id: + * self.sent_id.append(line_num) # <<<<<<<<<<<<<< + * word_count = word_count + 1 + * self.data.append(0) + */ + __pyx_t_10 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_id), __pyx_v_line_num); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L21; + } + __pyx_L21:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":77 + * if self.use_sent_id: + * self.sent_id.append(line_num) + * word_count = word_count + 1 # <<<<<<<<<<<<<< + * self.data.append(0) + * self.sent_index.append(word_count) + */ + __pyx_v_word_count = (__pyx_v_word_count + 1); + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":78 + * self.sent_id.append(line_num) + * word_count = word_count + 1 + * self.data.append(0) # <<<<<<<<<<<<<< + * self.sent_index.append(word_count) + * + */ + __pyx_t_1 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->data), __pyx_int_0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":79 + * word_count = word_count + 1 + * self.data.append(0) + * self.sent_index.append(word_count) # <<<<<<<<<<<<<< + * + * def read_binary(self, char* filename): + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_word_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_index), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":66 + * def read_text(self, char* filename): + * cdef int word_count = 0 + * with gzip_or_text(filename) as fp: # <<<<<<<<<<<<<< + * for line_num, line in enumerate(fp): + * self.sent_index.append(word_count) + */ + /*except:*/ { + __Pyx_AddTraceback("_sa.DataArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_1, &__pyx_t_10) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_13 = PyTuple_New(3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_t_16 = PyObject_Call(__pyx_t_4, __pyx_t_13, NULL); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_16); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + if (unlikely(__pyx_t_15 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_17 = (!__pyx_t_15); + if (__pyx_t_17) { + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_10); + __Pyx_ErrRestore(__pyx_t_2, __pyx_t_1, __pyx_t_10); + __pyx_t_2 = 0; __pyx_t_1 = 0; __pyx_t_10 = 0; + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L24; + } + __pyx_L24:; + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_4) { + __pyx_t_7 = PyObject_Call(__pyx_t_4, __pyx_k_tuple_17, NULL); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_17 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L25; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L1_error; + __pyx_L25:; + } + + __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_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_AddTraceback("_sa.DataArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_fp); + __Pyx_XDECREF(__pyx_v_line_num); + __Pyx_XDECREF(__pyx_v_line); + __Pyx_XDECREF(__pyx_v_word); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9DataArray_19read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_9DataArray_19read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.DataArray.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9DataArray_18read_binary(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":81 + * self.sent_index.append(word_count) + * + * def read_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "r") + */ + +static PyObject *__pyx_pf_3_sa_9DataArray_18read_binary(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":83 + * def read_binary(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "r") # <<<<<<<<<<<<<< + * self.read_handle(f) + * fclose(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":84 + * cdef FILE* f + * f = fopen(filename, "r") + * self.read_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + ((struct __pyx_vtabstruct_3_sa_DataArray *)__pyx_v_self->__pyx_vtab)->read_handle(__pyx_v_self, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":85 + * f = fopen(filename, "r") + * self.read_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + * + * cdef void read_handle(self, FILE* f): + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":87 + * fclose(f) + * + * cdef void read_handle(self, FILE* f): # <<<<<<<<<<<<<< + * cdef int num_words, word_len + * cdef unsigned i + */ + +static void __pyx_f_3_sa_9DataArray_read_handle(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, FILE *__pyx_v_f) { + int __pyx_v_num_words; + int __pyx_v_word_len; + CYTHON_UNUSED unsigned int __pyx_v_i; + char *__pyx_v_c_word; + PyObject *__pyx_v_py_word = 0; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + int __pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_handle", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":92 + * cdef char* c_word + * cdef bytes py_word + * self.data.read_handle(f) # <<<<<<<<<<<<<< + * self.sent_index.read_handle(f) + * self.sent_id.read_handle(f) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->data->__pyx_vtab)->read_handle(__pyx_v_self->data, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":93 + * cdef bytes py_word + * self.data.read_handle(f) + * self.sent_index.read_handle(f) # <<<<<<<<<<<<<< + * self.sent_id.read_handle(f) + * fread(&(num_words), sizeof(int), 1, f) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->sent_index->__pyx_vtab)->read_handle(__pyx_v_self->sent_index, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":94 + * self.data.read_handle(f) + * self.sent_index.read_handle(f) + * self.sent_id.read_handle(f) # <<<<<<<<<<<<<< + * fread(&(num_words), sizeof(int), 1, f) + * for i in range(num_words): + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->sent_id->__pyx_vtab)->read_handle(__pyx_v_self->sent_id, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":95 + * self.sent_index.read_handle(f) + * self.sent_id.read_handle(f) + * fread(&(num_words), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * for i in range(num_words): + * fread(&(word_len), sizeof(int), 1, f) + */ + fread((&__pyx_v_num_words), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":96 + * self.sent_id.read_handle(f) + * fread(&(num_words), sizeof(int), 1, f) + * for i in range(num_words): # <<<<<<<<<<<<<< + * fread(&(word_len), sizeof(int), 1, f) + * c_word = malloc (word_len * sizeof(char)) + */ + __pyx_t_1 = __pyx_v_num_words; + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_v_i = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":97 + * fread(&(num_words), sizeof(int), 1, f) + * for i in range(num_words): + * fread(&(word_len), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * c_word = malloc (word_len * sizeof(char)) + * fread(c_word, sizeof(char), word_len, f) + */ + fread((&__pyx_v_word_len), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":98 + * for i in range(num_words): + * fread(&(word_len), sizeof(int), 1, f) + * c_word = malloc (word_len * sizeof(char)) # <<<<<<<<<<<<<< + * fread(c_word, sizeof(char), word_len, f) + * py_word = c_word + */ + __pyx_v_c_word = ((char *)malloc((__pyx_v_word_len * (sizeof(char))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":99 + * fread(&(word_len), sizeof(int), 1, f) + * c_word = malloc (word_len * sizeof(char)) + * fread(c_word, sizeof(char), word_len, f) # <<<<<<<<<<<<<< + * py_word = c_word + * free(c_word) + */ + fread(__pyx_v_c_word, (sizeof(char)), __pyx_v_word_len, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":100 + * c_word = malloc (word_len * sizeof(char)) + * fread(c_word, sizeof(char), word_len, f) + * py_word = c_word # <<<<<<<<<<<<<< + * free(c_word) + * self.word2id[py_word] = len(self.id2word) + */ + __pyx_t_3 = PyBytes_FromString(__pyx_v_c_word); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __Pyx_XDECREF(((PyObject *)__pyx_v_py_word)); + __pyx_v_py_word = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":101 + * fread(c_word, sizeof(char), word_len, f) + * py_word = c_word + * free(c_word) # <<<<<<<<<<<<<< + * self.word2id[py_word] = len(self.id2word) + * self.id2word.append(py_word) + */ + free(__pyx_v_c_word); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":102 + * py_word = c_word + * free(c_word) + * self.word2id[py_word] = len(self.id2word) # <<<<<<<<<<<<<< + * self.id2word.append(py_word) + * if len(self.sent_id) == 0: + */ + __pyx_t_3 = __pyx_v_self->id2word; + __Pyx_INCREF(__pyx_t_3); + __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyObject_SetItem(__pyx_v_self->word2id, ((PyObject *)__pyx_v_py_word), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":103 + * free(c_word) + * self.word2id[py_word] = len(self.id2word) + * self.id2word.append(py_word) # <<<<<<<<<<<<<< + * if len(self.sent_id) == 0: + * self.use_sent_id = False + */ + __pyx_t_3 = __Pyx_PyObject_Append(__pyx_v_self->id2word, ((PyObject *)__pyx_v_py_word)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":104 + * self.word2id[py_word] = len(self.id2word) + * self.id2word.append(py_word) + * if len(self.sent_id) == 0: # <<<<<<<<<<<<<< + * self.use_sent_id = False + * else: + */ + __pyx_t_3 = ((PyObject *)__pyx_v_self->sent_id); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_5 = (__pyx_t_4 == 0); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":105 + * self.id2word.append(py_word) + * if len(self.sent_id) == 0: + * self.use_sent_id = False # <<<<<<<<<<<<<< + * else: + * self.use_sent_id = True + */ + __pyx_v_self->use_sent_id = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":107 + * self.use_sent_id = False + * else: + * self.use_sent_id = True # <<<<<<<<<<<<<< + * + * cdef void write_handle(self, FILE* f): + */ + __pyx_v_self->use_sent_id = 1; + } + __pyx_L5:; + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_WriteUnraisable("_sa.DataArray.read_handle", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_py_word); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":109 + * self.use_sent_id = True + * + * cdef void write_handle(self, FILE* f): # <<<<<<<<<<<<<< + * cdef int word_len + * cdef int num_words + */ + +static void __pyx_f_3_sa_9DataArray_write_handle(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, FILE *__pyx_v_f) { + int __pyx_v_word_len; + int __pyx_v_num_words; + char *__pyx_v_c_word; + PyObject *__pyx_v_word = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *(*__pyx_t_4)(PyObject *); + char *__pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_handle", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":113 + * cdef int num_words + * cdef char* c_word + * self.data.write_handle(f) # <<<<<<<<<<<<<< + * self.sent_index.write_handle(f) + * self.sent_id.write_handle(f) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->data->__pyx_vtab)->write_handle(__pyx_v_self->data, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":114 + * cdef char* c_word + * self.data.write_handle(f) + * self.sent_index.write_handle(f) # <<<<<<<<<<<<<< + * self.sent_id.write_handle(f) + * num_words = len(self.id2word) - 2 + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->sent_index->__pyx_vtab)->write_handle(__pyx_v_self->sent_index, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":115 + * self.data.write_handle(f) + * self.sent_index.write_handle(f) + * self.sent_id.write_handle(f) # <<<<<<<<<<<<<< + * num_words = len(self.id2word) - 2 + * fwrite(&(num_words), sizeof(int), 1, f) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->sent_id->__pyx_vtab)->write_handle(__pyx_v_self->sent_id, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":116 + * self.sent_index.write_handle(f) + * self.sent_id.write_handle(f) + * num_words = len(self.id2word) - 2 # <<<<<<<<<<<<<< + * fwrite(&(num_words), sizeof(int), 1, f) + * for word in self.id2word[2:]: + */ + __pyx_t_1 = __pyx_v_self->id2word; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_num_words = (__pyx_t_2 - 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":117 + * self.sent_id.write_handle(f) + * num_words = len(self.id2word) - 2 + * fwrite(&(num_words), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * for word in self.id2word[2:]: + * c_word = word + */ + fwrite((&__pyx_v_num_words), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":118 + * num_words = len(self.id2word) - 2 + * fwrite(&(num_words), sizeof(int), 1, f) + * for word in self.id2word[2:]: # <<<<<<<<<<<<<< + * c_word = word + * word_len = strlen(c_word) + 1 + */ + __pyx_t_1 = __Pyx_PySequence_GetSlice(__pyx_v_self->id2word, 2, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_1 = __pyx_t_4(__pyx_t_3); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF(__pyx_v_word); + __pyx_v_word = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":119 + * fwrite(&(num_words), sizeof(int), 1, f) + * for word in self.id2word[2:]: + * c_word = word # <<<<<<<<<<<<<< + * word_len = strlen(c_word) + 1 + * fwrite(&(word_len), sizeof(int), 1, f) + */ + __pyx_t_5 = PyBytes_AsString(__pyx_v_word); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_c_word = __pyx_t_5; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":120 + * for word in self.id2word[2:]: + * c_word = word + * word_len = strlen(c_word) + 1 # <<<<<<<<<<<<<< + * fwrite(&(word_len), sizeof(int), 1, f) + * fwrite(c_word, sizeof(char), word_len, f) + */ + __pyx_v_word_len = (strlen(__pyx_v_c_word) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":121 + * c_word = word + * word_len = strlen(c_word) + 1 + * fwrite(&(word_len), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fwrite(c_word, sizeof(char), word_len, f) + * + */ + fwrite((&__pyx_v_word_len), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":122 + * word_len = strlen(c_word) + 1 + * fwrite(&(word_len), sizeof(int), 1, f) + * fwrite(c_word, sizeof(char), word_len, f) # <<<<<<<<<<<<<< + * + * def write_binary(self, char* filename): + */ + fwrite(__pyx_v_c_word, (sizeof(char)), __pyx_v_word_len, __pyx_v_f); + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_WriteUnraisable("_sa.DataArray.write_handle", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_word); + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9DataArray_21write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_9DataArray_21write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.DataArray.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9DataArray_20write_binary(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":124 + * fwrite(c_word, sizeof(char), word_len, f) + * + * def write_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "w") + */ + +static PyObject *__pyx_pf_3_sa_9DataArray_20write_binary(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":126 + * def write_binary(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "w") # <<<<<<<<<<<<<< + * self.write_handle(f) + * fclose(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":127 + * cdef FILE* f + * f = fopen(filename, "w") + * self.write_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + ((struct __pyx_vtabstruct_3_sa_DataArray *)__pyx_v_self->__pyx_vtab)->write_handle(__pyx_v_self, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":128 + * f = fopen(filename, "w") + * self.write_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + * + * def write_enhanced_handle(self, f): + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9DataArray_23write_enhanced_handle(PyObject *__pyx_v_self, PyObject *__pyx_v_f); /*proto*/ +static PyObject *__pyx_pw_3_sa_9DataArray_23write_enhanced_handle(PyObject *__pyx_v_self, PyObject *__pyx_v_f) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_enhanced_handle (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9DataArray_22write_enhanced_handle(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_f)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":130 + * fclose(f) + * + * def write_enhanced_handle(self, f): # <<<<<<<<<<<<<< + * for i in self.data: + * f.write("%d " %i) + */ + +static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_f) { + PyObject *__pyx_v_i = NULL; + PyObject *__pyx_v_word = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_enhanced_handle", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":131 + * + * def write_enhanced_handle(self, f): + * for i in self.data: # <<<<<<<<<<<<<< + * f.write("%d " %i) + * f.write("\n") + */ + if (PyList_CheckExact(((PyObject *)__pyx_v_self->data)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->data))) { + __pyx_t_1 = ((PyObject *)__pyx_v_self->data); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self->data)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":132 + * def write_enhanced_handle(self, f): + * for i in self.data: + * f.write("%d " %i) # <<<<<<<<<<<<<< + * f.write("\n") + * for i in self.sent_index: + */ + __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":133 + * for i in self.data: + * f.write("%d " %i) + * f.write("\n") # <<<<<<<<<<<<<< + * for i in self.sent_index: + * f.write("%d " %i) + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_19), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":134 + * f.write("%d " %i) + * f.write("\n") + * for i in self.sent_index: # <<<<<<<<<<<<<< + * f.write("%d " %i) + * f.write("\n") + */ + if (PyList_CheckExact(((PyObject *)__pyx_v_self->sent_index)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->sent_index))) { + __pyx_t_5 = ((PyObject *)__pyx_v_self->sent_index); __Pyx_INCREF(__pyx_t_5); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_5 = PyObject_GetIter(((PyObject *)__pyx_v_self->sent_index)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = Py_TYPE(__pyx_t_5)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_5)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_5)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_5, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_5)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_5)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_5, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_1 = __pyx_t_3(__pyx_t_5); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":135 + * f.write("\n") + * for i in self.sent_index: + * f.write("%d " %i) # <<<<<<<<<<<<<< + * f.write("\n") + * for i in self.sent_id: + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_6)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_6)); + __pyx_t_6 = 0; + __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":136 + * for i in self.sent_index: + * f.write("%d " %i) + * f.write("\n") # <<<<<<<<<<<<<< + * for i in self.sent_id: + * f.write("%d " %i) + */ + __pyx_t_5 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":137 + * f.write("%d " %i) + * f.write("\n") + * for i in self.sent_id: # <<<<<<<<<<<<<< + * f.write("%d " %i) + * f.write("\n") + */ + if (PyList_CheckExact(((PyObject *)__pyx_v_self->sent_id)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->sent_id))) { + __pyx_t_6 = ((PyObject *)__pyx_v_self->sent_id); __Pyx_INCREF(__pyx_t_6); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_6 = PyObject_GetIter(((PyObject *)__pyx_v_self->sent_id)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = Py_TYPE(__pyx_t_6)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_6)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_6)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_6, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_6)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_6)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_6, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_5 = __pyx_t_3(__pyx_t_6); + if (unlikely(!__pyx_t_5)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_5); + } + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":138 + * f.write("\n") + * for i in self.sent_id: + * f.write("%d " %i) # <<<<<<<<<<<<<< + * f.write("\n") + * for word in self.id2word: + */ + __pyx_t_5 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":139 + * for i in self.sent_id: + * f.write("%d " %i) + * f.write("\n") # <<<<<<<<<<<<<< + * for word in self.id2word: + * f.write("%s %d " % (word, self.word2id[word])) + */ + __pyx_t_6 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_k_tuple_21), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":140 + * f.write("%d " %i) + * f.write("\n") + * for word in self.id2word: # <<<<<<<<<<<<<< + * f.write("%s %d " % (word, self.word2id[word])) + * f.write("\n") + */ + if (PyList_CheckExact(__pyx_v_self->id2word) || PyTuple_CheckExact(__pyx_v_self->id2word)) { + __pyx_t_4 = __pyx_v_self->id2word; __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_self->id2word); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_6); __pyx_t_2++; + #else + __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_6); __pyx_t_2++; + #else + __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_6 = __pyx_t_3(__pyx_t_4); + if (unlikely(!__pyx_t_6)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_6); + } + __Pyx_XDECREF(__pyx_v_word); + __pyx_v_word = __pyx_t_6; + __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":141 + * f.write("\n") + * for word in self.id2word: + * f.write("%s %d " % (word, self.word2id[word])) # <<<<<<<<<<<<<< + * f.write("\n") + * + */ + __pyx_t_6 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_1 = PyObject_GetItem(__pyx_v_self->word2id, __pyx_v_word); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_word); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_word); + __Pyx_GIVEREF(__pyx_v_word); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_22), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":142 + * for word in self.id2word: + * f.write("%s %d " % (word, self.word2id[word])) + * f.write("\n") # <<<<<<<<<<<<<< + * + * def write_enhanced(self, char* filename): + */ + __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_23), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_sa.DataArray.write_enhanced_handle", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_word); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9DataArray_25write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_9DataArray_25write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_enhanced (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.DataArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9DataArray_24write_enhanced(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":144 + * f.write("\n") + * + * def write_enhanced(self, char* filename): # <<<<<<<<<<<<<< + * with open(filename, "w") as f: + * self.write_enhanced_handle(self, f) + */ + +static PyObject *__pyx_pf_3_sa_9DataArray_24write_enhanced(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_enhanced", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":145 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * self.write_enhanced_handle(self, f) + */ + /*with:*/ { + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_f = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":146 + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: + * self.write_enhanced_handle(self, f) # <<<<<<<<<<<<<< + */ + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s_24); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + __Pyx_INCREF(__pyx_v_f); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_f); + __Pyx_GIVEREF(__pyx_v_f); + __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":145 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * self.write_enhanced_handle(self, f) + */ + /*except:*/ { + __Pyx_AddTraceback("_sa.DataArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_1, &__pyx_t_4) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_10 = PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_10); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_11 = (!__pyx_t_9); + if (__pyx_t_11) { + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_ErrRestore(__pyx_t_2, __pyx_t_1, __pyx_t_4); + __pyx_t_2 = 0; __pyx_t_1 = 0; __pyx_t_4 = 0; + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L18; + } + __pyx_L18:; + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_25, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L19; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L19:; + } + + __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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_sa.DataArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":12 + * cdef IntList sent_index + * + * cdef int link(self, int i, int j): # <<<<<<<<<<<<<< + * """Integerizes an alignment link pair""" + * return i*65536 + j + */ + +static int __pyx_f_3_sa_9Alignment_link(CYTHON_UNUSED struct __pyx_obj_3_sa_Alignment *__pyx_v_self, int __pyx_v_i, int __pyx_v_j) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("link", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":14 + * cdef int link(self, int i, int j): + * """Integerizes an alignment link pair""" + * return i*65536 + j # <<<<<<<<<<<<<< + * + * def unlink(self, link): + */ + __pyx_r = ((__pyx_v_i * 65536) + __pyx_v_j); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9Alignment_1unlink(PyObject *__pyx_v_self, PyObject *__pyx_v_link); /*proto*/ +static char __pyx_doc_3_sa_9Alignment_unlink[] = "De-integerizes an alignment link pair"; +static PyObject *__pyx_pw_3_sa_9Alignment_1unlink(PyObject *__pyx_v_self, PyObject *__pyx_v_link) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("unlink (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9Alignment_unlink(((struct __pyx_obj_3_sa_Alignment *)__pyx_v_self), ((PyObject *)__pyx_v_link)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":16 + * return i*65536 + j + * + * def unlink(self, link): # <<<<<<<<<<<<<< + * """De-integerizes an alignment link pair""" + * return (link/65536, link%65536) + */ + +static PyObject *__pyx_pf_3_sa_9Alignment_unlink(CYTHON_UNUSED struct __pyx_obj_3_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_link) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("unlink", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":18 + * def unlink(self, link): + * """De-integerizes an alignment link pair""" + * return (link/65536, link%65536) # <<<<<<<<<<<<<< + * + * cdef _unlink(self, int link, int* f, int* e): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_v_link, __pyx_int_65536); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Remainder(__pyx_v_link, __pyx_int_65536); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_r = ((PyObject *)__pyx_t_3); + __pyx_t_3 = 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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.Alignment.unlink", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":20 + * return (link/65536, link%65536) + * + * cdef _unlink(self, int link, int* f, int* e): # <<<<<<<<<<<<<< + * f[0] = link/65536 + * e[0] = link%65536 + */ + +static PyObject *__pyx_f_3_sa_9Alignment__unlink(CYTHON_UNUSED struct __pyx_obj_3_sa_Alignment *__pyx_v_self, int __pyx_v_link, int *__pyx_v_f, int *__pyx_v_e) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_unlink", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":21 + * + * cdef _unlink(self, int link, int* f, int* e): + * f[0] = link/65536 # <<<<<<<<<<<<<< + * e[0] = link%65536 + * + */ + (__pyx_v_f[0]) = __Pyx_div_long(__pyx_v_link, 65536); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":22 + * cdef _unlink(self, int link, int* f, int* e): + * f[0] = link/65536 + * e[0] = link%65536 # <<<<<<<<<<<<<< + * + * def get_sent_links(self, int sent_id): + */ + (__pyx_v_e[0]) = __Pyx_mod_long(__pyx_v_link, 65536); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9Alignment_3get_sent_links(PyObject *__pyx_v_self, PyObject *__pyx_arg_sent_id); /*proto*/ +static PyObject *__pyx_pw_3_sa_9Alignment_3get_sent_links(PyObject *__pyx_v_self, PyObject *__pyx_arg_sent_id) { + int __pyx_v_sent_id; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_sent_links (wrapper)", 0); + assert(__pyx_arg_sent_id); { + __pyx_v_sent_id = __Pyx_PyInt_AsInt(__pyx_arg_sent_id); if (unlikely((__pyx_v_sent_id == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.Alignment.get_sent_links", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9Alignment_2get_sent_links(((struct __pyx_obj_3_sa_Alignment *)__pyx_v_self), ((int)__pyx_v_sent_id)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":24 + * e[0] = link%65536 + * + * def get_sent_links(self, int sent_id): # <<<<<<<<<<<<<< + * cdef IntList sent_links + * cdef int* arr + */ + +static PyObject *__pyx_pf_3_sa_9Alignment_2get_sent_links(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, int __pyx_v_sent_id) { + struct __pyx_obj_3_sa_IntList *__pyx_v_sent_links = 0; + int *__pyx_v_arr; + int __pyx_v_arr_len; + 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("get_sent_links", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":28 + * cdef int* arr + * cdef int arr_len + * sent_links = IntList() # <<<<<<<<<<<<<< + * arr = self._get_sent_links(sent_id, &arr_len) + * sent_links._extend_arr(arr, arr_len*2) + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sent_links = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":29 + * cdef int arr_len + * sent_links = IntList() + * arr = self._get_sent_links(sent_id, &arr_len) # <<<<<<<<<<<<<< + * sent_links._extend_arr(arr, arr_len*2) + * free(arr) + */ + __pyx_v_arr = ((struct __pyx_vtabstruct_3_sa_Alignment *)__pyx_v_self->__pyx_vtab)->_get_sent_links(__pyx_v_self, __pyx_v_sent_id, (&__pyx_v_arr_len)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":30 + * sent_links = IntList() + * arr = self._get_sent_links(sent_id, &arr_len) + * sent_links._extend_arr(arr, arr_len*2) # <<<<<<<<<<<<<< + * free(arr) + * return sent_links + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_sent_links->__pyx_vtab)->_extend_arr(__pyx_v_sent_links, __pyx_v_arr, (__pyx_v_arr_len * 2)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":31 + * arr = self._get_sent_links(sent_id, &arr_len) + * sent_links._extend_arr(arr, arr_len*2) + * free(arr) # <<<<<<<<<<<<<< + * return sent_links + * + */ + free(__pyx_v_arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":32 + * sent_links._extend_arr(arr, arr_len*2) + * free(arr) + * return sent_links # <<<<<<<<<<<<<< + * + * cdef int* _get_sent_links(self, int sent_id, int* num_links): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_sent_links)); + __pyx_r = ((PyObject *)__pyx_v_sent_links); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_sa.Alignment.get_sent_links", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_sent_links); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":34 + * return sent_links + * + * cdef int* _get_sent_links(self, int sent_id, int* num_links): # <<<<<<<<<<<<<< + * cdef int* sent_links + * cdef int i, start, end + */ + +static int *__pyx_f_3_sa_9Alignment__get_sent_links(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, int __pyx_v_sent_id, int *__pyx_v_num_links) { + int *__pyx_v_sent_links; + int __pyx_v_i; + int __pyx_v_start; + int __pyx_v_end; + int *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_get_sent_links", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":37 + * cdef int* sent_links + * cdef int i, start, end + * start = self.sent_index.arr[sent_id] # <<<<<<<<<<<<<< + * end = self.sent_index.arr[sent_id+1] + * num_links[0] = end - start + */ + __pyx_v_start = (__pyx_v_self->sent_index->arr[__pyx_v_sent_id]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":38 + * cdef int i, start, end + * start = self.sent_index.arr[sent_id] + * end = self.sent_index.arr[sent_id+1] # <<<<<<<<<<<<<< + * num_links[0] = end - start + * sent_links = malloc(2*num_links[0]*sizeof(int)) + */ + __pyx_v_end = (__pyx_v_self->sent_index->arr[(__pyx_v_sent_id + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":39 + * start = self.sent_index.arr[sent_id] + * end = self.sent_index.arr[sent_id+1] + * num_links[0] = end - start # <<<<<<<<<<<<<< + * sent_links = malloc(2*num_links[0]*sizeof(int)) + * for i from 0 <= i < num_links[0]: + */ + (__pyx_v_num_links[0]) = (__pyx_v_end - __pyx_v_start); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":40 + * end = self.sent_index.arr[sent_id+1] + * num_links[0] = end - start + * sent_links = malloc(2*num_links[0]*sizeof(int)) # <<<<<<<<<<<<<< + * for i from 0 <= i < num_links[0]: + * self._unlink(self.links.arr[start + i], sent_links + (2*i), sent_links + (2*i) + 1) + */ + __pyx_v_sent_links = ((int *)malloc(((2 * (__pyx_v_num_links[0])) * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":41 + * num_links[0] = end - start + * sent_links = malloc(2*num_links[0]*sizeof(int)) + * for i from 0 <= i < num_links[0]: # <<<<<<<<<<<<<< + * self._unlink(self.links.arr[start + i], sent_links + (2*i), sent_links + (2*i) + 1) + * return sent_links + */ + __pyx_t_1 = (__pyx_v_num_links[0]); + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":42 + * sent_links = malloc(2*num_links[0]*sizeof(int)) + * for i from 0 <= i < num_links[0]: + * self._unlink(self.links.arr[start + i], sent_links + (2*i), sent_links + (2*i) + 1) # <<<<<<<<<<<<<< + * return sent_links + * + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_Alignment *)__pyx_v_self->__pyx_vtab)->_unlink(__pyx_v_self, (__pyx_v_self->links->arr[(__pyx_v_start + __pyx_v_i)]), (__pyx_v_sent_links + (2 * __pyx_v_i)), ((__pyx_v_sent_links + (2 * __pyx_v_i)) + 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":43 + * for i from 0 <= i < num_links[0]: + * self._unlink(self.links.arr[start + i], sent_links + (2*i), sent_links + (2*i) + 1) + * return sent_links # <<<<<<<<<<<<<< + * + * def __cinit__(self, from_binary=None, from_text=None): + */ + __pyx_r = __pyx_v_sent_links; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_WriteUnraisable("_sa.Alignment._get_sent_links", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_9Alignment_5__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_9Alignment_5__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_from_binary = 0; + PyObject *__pyx_v_from_text = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__from_binary,&__pyx_n_s__from_text,0}; + PyObject* values[2] = {0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":45 + * return sent_links + * + * def __cinit__(self, from_binary=None, from_text=None): # <<<<<<<<<<<<<< + * self.links = IntList(1000,1000) + * self.sent_index = IntList(1000,1000) + */ + values[0] = ((PyObject *)Py_None); + values[1] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_binary); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_text); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_from_binary = values[0]; + __pyx_v_from_text = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.Alignment.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9Alignment_4__cinit__(((struct __pyx_obj_3_sa_Alignment *)__pyx_v_self), __pyx_v_from_binary, __pyx_v_from_text); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_9Alignment_4__cinit__(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":46 + * + * def __cinit__(self, from_binary=None, from_text=None): + * self.links = IntList(1000,1000) # <<<<<<<<<<<<<< + * self.sent_index = IntList(1000,1000) + * if from_binary: + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_k_tuple_26), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->links); + __Pyx_DECREF(((PyObject *)__pyx_v_self->links)); + __pyx_v_self->links = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":47 + * def __cinit__(self, from_binary=None, from_text=None): + * self.links = IntList(1000,1000) + * self.sent_index = IntList(1000,1000) # <<<<<<<<<<<<<< + * if from_binary: + * self.read_binary(from_binary) + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_k_tuple_27), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->sent_index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->sent_index)); + __pyx_v_self->sent_index = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":48 + * self.links = IntList(1000,1000) + * self.sent_index = IntList(1000,1000) + * if from_binary: # <<<<<<<<<<<<<< + * self.read_binary(from_binary) + * elif from_text: + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_binary); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":49 + * self.sent_index = IntList(1000,1000) + * if from_binary: + * self.read_binary(from_binary) # <<<<<<<<<<<<<< + * elif from_text: + * self.read_text(from_text) + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_binary); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_from_binary); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_binary); + __Pyx_GIVEREF(__pyx_v_from_binary); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":50 + * if from_binary: + * self.read_binary(from_binary) + * elif from_text: # <<<<<<<<<<<<<< + * self.read_text(from_text) + * + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_text); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":51 + * self.read_binary(from_binary) + * elif from_text: + * self.read_text(from_text) # <<<<<<<<<<<<<< + * + * def read_text(self, char* filename): + */ + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_text); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_from_text); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_text); + __Pyx_GIVEREF(__pyx_v_from_text); + __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_sa.Alignment.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9Alignment_7read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_9Alignment_7read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_text (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.Alignment.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9Alignment_6read_text(((struct __pyx_obj_3_sa_Alignment *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":53 + * self.read_text(from_text) + * + * def read_text(self, char* filename): # <<<<<<<<<<<<<< + * with gzip_or_text(filename) as f: + * for line in f: + */ + +static PyObject *__pyx_pf_3_sa_9Alignment_6read_text(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_v_line = NULL; + PyObject *__pyx_v_pairs = NULL; + PyObject *__pyx_v_pair = NULL; + PyObject *__pyx_v_i = NULL; + PyObject *__pyx_v_j = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + Py_ssize_t __pyx_t_10; + PyObject *(*__pyx_t_11)(PyObject *); + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + PyObject *(*__pyx_t_15)(PyObject *); + int __pyx_t_16; + int __pyx_t_17; + int __pyx_t_18; + PyObject *__pyx_t_19 = NULL; + int __pyx_t_20; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_text", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":54 + * + * def read_text(self, char* filename): + * with gzip_or_text(filename) as f: # <<<<<<<<<<<<<< + * for line in f: + * self.sent_index.append(len(self.links)) + */ + /*with:*/ { + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__gzip_or_text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __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[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_1); + __pyx_v_f = __pyx_t_1; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":55 + * def read_text(self, char* filename): + * with gzip_or_text(filename) as f: + * for line in f: # <<<<<<<<<<<<<< + * self.sent_index.append(len(self.links)) + * pairs = line.split() + */ + if (PyList_CheckExact(__pyx_v_f) || PyTuple_CheckExact(__pyx_v_f)) { + __pyx_t_1 = __pyx_v_f; __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else { + __pyx_t_2 = __pyx_t_9(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF(__pyx_v_line); + __pyx_v_line = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":56 + * with gzip_or_text(filename) as f: + * for line in f: + * self.sent_index.append(len(self.links)) # <<<<<<<<<<<<<< + * pairs = line.split() + * for pair in pairs: + */ + __pyx_t_2 = ((PyObject *)__pyx_v_self->links); + __Pyx_INCREF(__pyx_t_2); + __pyx_t_10 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_10); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_index), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":57 + * for line in f: + * self.sent_index.append(len(self.links)) + * pairs = line.split() # <<<<<<<<<<<<<< + * for pair in pairs: + * (i, j) = map(int, pair.split('-')) + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_v_pairs); + __pyx_v_pairs = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":58 + * self.sent_index.append(len(self.links)) + * pairs = line.split() + * for pair in pairs: # <<<<<<<<<<<<<< + * (i, j) = map(int, pair.split('-')) + * self.links.append(self.link(i, j)) + */ + if (PyList_CheckExact(__pyx_v_pairs) || PyTuple_CheckExact(__pyx_v_pairs)) { + __pyx_t_2 = __pyx_v_pairs; __Pyx_INCREF(__pyx_t_2); __pyx_t_10 = 0; + __pyx_t_11 = NULL; + } else { + __pyx_t_10 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_pairs); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_11 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_3); __pyx_t_10++; + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_10); __Pyx_INCREF(__pyx_t_3); __pyx_t_10++; + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else { + __pyx_t_3 = __pyx_t_11(__pyx_t_2); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_pair); + __pyx_v_pair = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":59 + * pairs = line.split() + * for pair in pairs: + * (i, j) = map(int, pair.split('-')) # <<<<<<<<<<<<<< + * self.links.append(self.link(i, j)) + * self.sent_index.append(len(self.links)) + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_v_pair, __pyx_n_s__split); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_29), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(((PyObject *)((PyObject*)(&PyInt_Type)))); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)((PyObject*)(&PyInt_Type)))); + __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyInt_Type)))); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_12); + __Pyx_GIVEREF(__pyx_t_12); + __pyx_t_12 = 0; + __pyx_t_12 = PyObject_Call(__pyx_builtin_map, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_12))) || (PyList_CheckExact(__pyx_t_12))) { + PyObject* sequence = __pyx_t_12; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_13 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_13 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_13); + #else + __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_13 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + #endif + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } else + { + Py_ssize_t index = -1; + __pyx_t_14 = PyObject_GetIter(__pyx_t_12); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext; + index = 0; __pyx_t_3 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_3)) goto __pyx_L20_unpacking_failed; + __Pyx_GOTREF(__pyx_t_3); + 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[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_15 = NULL; + __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; + __pyx_t_15 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_L21_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_3; + __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_v_j); + __pyx_v_j = __pyx_t_13; + __pyx_t_13 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":60 + * for pair in pairs: + * (i, j) = map(int, pair.split('-')) + * self.links.append(self.link(i, j)) # <<<<<<<<<<<<<< + * self.sent_index.append(len(self.links)) + * + */ + __pyx_t_16 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_16 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_17 = __Pyx_PyInt_AsInt(__pyx_v_j); if (unlikely((__pyx_t_17 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_12 = PyInt_FromLong(((struct __pyx_vtabstruct_3_sa_Alignment *)__pyx_v_self->__pyx_vtab)->link(__pyx_v_self, __pyx_t_16, __pyx_t_17)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->links), __pyx_t_12); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":61 + * (i, j) = map(int, pair.split('-')) + * self.links.append(self.link(i, j)) + * self.sent_index.append(len(self.links)) # <<<<<<<<<<<<<< + * + * def read_binary(self, char* filename): + */ + __pyx_t_1 = ((PyObject *)__pyx_v_self->links); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_8 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_index), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":54 + * + * def read_text(self, char* filename): + * with gzip_or_text(filename) as f: # <<<<<<<<<<<<<< + * for line in f: + * self.sent_index.append(len(self.links)) + */ + /*except:*/ { + __Pyx_AddTraceback("_sa.Alignment.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_1, &__pyx_t_13) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_12 = PyTuple_New(3); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_13); + PyTuple_SET_ITEM(__pyx_t_12, 2, __pyx_t_13); + __Pyx_GIVEREF(__pyx_t_13); + __pyx_t_19 = PyObject_Call(__pyx_t_4, __pyx_t_12, NULL); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_19); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(__pyx_t_18 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_20 = (!__pyx_t_18); + if (__pyx_t_20) { + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_13); + __Pyx_ErrRestore(__pyx_t_2, __pyx_t_1, __pyx_t_13); + __pyx_t_2 = 0; __pyx_t_1 = 0; __pyx_t_13 = 0; + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L24; + } + __pyx_L24:; + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_4) { + __pyx_t_7 = PyObject_Call(__pyx_t_4, __pyx_k_tuple_30, NULL); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_20 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_20 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L25; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L1_error; + __pyx_L25:; + } + + __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_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_AddTraceback("_sa.Alignment.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_line); + __Pyx_XDECREF(__pyx_v_pairs); + __Pyx_XDECREF(__pyx_v_pair); + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_j); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9Alignment_9read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_9Alignment_9read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.Alignment.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9Alignment_8read_binary(((struct __pyx_obj_3_sa_Alignment *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":63 + * self.sent_index.append(len(self.links)) + * + * def read_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "r") + */ + +static PyObject *__pyx_pf_3_sa_9Alignment_8read_binary(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":65 + * def read_binary(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "r") # <<<<<<<<<<<<<< + * self.links.read_handle(f) + * self.sent_index.read_handle(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":66 + * cdef FILE* f + * f = fopen(filename, "r") + * self.links.read_handle(f) # <<<<<<<<<<<<<< + * self.sent_index.read_handle(f) + * fclose(f) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->links->__pyx_vtab)->read_handle(__pyx_v_self->links, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":67 + * f = fopen(filename, "r") + * self.links.read_handle(f) + * self.sent_index.read_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->sent_index->__pyx_vtab)->read_handle(__pyx_v_self->sent_index, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":68 + * self.links.read_handle(f) + * self.sent_index.read_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + * + * def write_text(self, char* filename): + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9Alignment_11write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_9Alignment_11write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_text (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.Alignment.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9Alignment_10write_text(((struct __pyx_obj_3_sa_Alignment *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":70 + * fclose(f) + * + * def write_text(self, char* filename): # <<<<<<<<<<<<<< + * with open(filename, "w") as f: + * sent_num = 0 + */ + +static PyObject *__pyx_pf_3_sa_9Alignment_10write_text(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_v_sent_num = NULL; + PyObject *__pyx_v_i = NULL; + PyObject *__pyx_v_link = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + int __pyx_t_15; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_text", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":71 + * + * def write_text(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * sent_num = 0 + * for i, link in enumerate(self.links): + */ + /*with:*/ { + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_f = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":72 + * def write_text(self, char* filename): + * with open(filename, "w") as f: + * sent_num = 0 # <<<<<<<<<<<<<< + * for i, link in enumerate(self.links): + * while i >= self.sent_index[sent_num]: + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_sent_num = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":73 + * with open(filename, "w") as f: + * sent_num = 0 + * for i, link in enumerate(self.links): # <<<<<<<<<<<<<< + * while i >= self.sent_index[sent_num]: + * f.write("\n") + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_4 = __pyx_int_0; + if (PyList_CheckExact(((PyObject *)__pyx_v_self->links)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->links))) { + __pyx_t_1 = ((PyObject *)__pyx_v_self->links); __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self->links)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else { + __pyx_t_2 = __pyx_t_9(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF(__pyx_v_link); + __pyx_v_link = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_INCREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_4; + __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); + __pyx_t_4 = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":74 + * sent_num = 0 + * for i, link in enumerate(self.links): + * while i >= self.sent_index[sent_num]: # <<<<<<<<<<<<<< + * f.write("\n") + * sent_num = sent_num + 1 + */ + while (1) { + __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_self->sent_index), __pyx_v_sent_num); if (!__pyx_t_2) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = PyObject_RichCompare(__pyx_v_i, __pyx_t_2, Py_GE); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (!__pyx_t_11) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":75 + * for i, link in enumerate(self.links): + * while i >= self.sent_index[sent_num]: + * f.write("\n") # <<<<<<<<<<<<<< + * sent_num = sent_num + 1 + * f.write("%d-%d " % self.unlink(link)) + */ + __pyx_t_10 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_k_tuple_31), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":76 + * while i >= self.sent_index[sent_num]: + * f.write("\n") + * sent_num = sent_num + 1 # <<<<<<<<<<<<<< + * f.write("%d-%d " % self.unlink(link)) + * f.write("\n") + */ + __pyx_t_2 = PyNumber_Add(__pyx_v_sent_num, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_v_sent_num); + __pyx_v_sent_num = __pyx_t_2; + __pyx_t_2 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":77 + * f.write("\n") + * sent_num = sent_num + 1 + * f.write("%d-%d " % self.unlink(link)) # <<<<<<<<<<<<<< + * f.write("\n") + * + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__unlink); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_INCREF(__pyx_v_link); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_v_link); + __Pyx_GIVEREF(__pyx_v_link); + __pyx_t_13 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __pyx_t_12 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_32), __pyx_t_13); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_12)); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_13); + PyTuple_SET_ITEM(__pyx_t_13, 0, ((PyObject *)__pyx_t_12)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_12)); + __pyx_t_12 = 0; + __pyx_t_12 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":78 + * sent_num = sent_num + 1 + * f.write("%d-%d " % self.unlink(link)) + * f.write("\n") # <<<<<<<<<<<<<< + * + * def write_binary(self, char* filename): + */ + __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_33), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":71 + * + * def write_text(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * sent_num = 0 + * for i, link in enumerate(self.links): + */ + /*except:*/ { + __Pyx_AddTraceback("_sa.Alignment.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_4, &__pyx_t_12) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = PyTuple_New(3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_12); + __Pyx_GIVEREF(__pyx_t_12); + __pyx_t_14 = PyObject_Call(__pyx_t_3, __pyx_t_13, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_14); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_15 = (!__pyx_t_11); + if (__pyx_t_15) { + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_ErrRestore(__pyx_t_1, __pyx_t_4, __pyx_t_12); + __pyx_t_1 = 0; __pyx_t_4 = 0; __pyx_t_12 = 0; + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L22; + } + __pyx_L22:; + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_34, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_15 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L23; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L23:; + } + + __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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_AddTraceback("_sa.Alignment.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_sent_num); + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_link); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9Alignment_13write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_9Alignment_13write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.Alignment.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9Alignment_12write_binary(((struct __pyx_obj_3_sa_Alignment *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":80 + * f.write("\n") + * + * def write_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "w") + */ + +static PyObject *__pyx_pf_3_sa_9Alignment_12write_binary(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":82 + * def write_binary(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "w") # <<<<<<<<<<<<<< + * self.links.write_handle(f) + * self.sent_index.write_handle(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":83 + * cdef FILE* f + * f = fopen(filename, "w") + * self.links.write_handle(f) # <<<<<<<<<<<<<< + * self.sent_index.write_handle(f) + * fclose(f) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->links->__pyx_vtab)->write_handle(__pyx_v_self->links, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":84 + * f = fopen(filename, "w") + * self.links.write_handle(f) + * self.sent_index.write_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->sent_index->__pyx_vtab)->write_handle(__pyx_v_self->sent_index, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":85 + * self.links.write_handle(f) + * self.sent_index.write_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + * + * def write_enhanced(self, char* filename): + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9Alignment_15write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_9Alignment_15write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_enhanced (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.Alignment.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9Alignment_14write_enhanced(((struct __pyx_obj_3_sa_Alignment *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":87 + * fclose(f) + * + * def write_enhanced(self, char* filename): # <<<<<<<<<<<<<< + * with open(filename, "w") as f: + * sent_num = 1 + */ + +static PyObject *__pyx_pf_3_sa_9Alignment_14write_enhanced(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_v_f = NULL; + CYTHON_UNUSED long __pyx_v_sent_num; + PyObject *__pyx_v_link = NULL; + PyObject *__pyx_v_i = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + PyObject *__pyx_t_12 = NULL; + int __pyx_t_13; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_enhanced", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":88 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * sent_num = 1 + * for link in self.links: + */ + /*with:*/ { + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_f = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":89 + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: + * sent_num = 1 # <<<<<<<<<<<<<< + * for link in self.links: + * f.write("%d " % link) + */ + __pyx_v_sent_num = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":90 + * with open(filename, "w") as f: + * sent_num = 1 + * for link in self.links: # <<<<<<<<<<<<<< + * f.write("%d " % link) + * f.write("\n") + */ + if (PyList_CheckExact(((PyObject *)__pyx_v_self->links)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->links))) { + __pyx_t_4 = ((PyObject *)__pyx_v_self->links); __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(((PyObject *)__pyx_v_self->links)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else { + __pyx_t_1 = __pyx_t_9(__pyx_t_4); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF(__pyx_v_link); + __pyx_v_link = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":91 + * sent_num = 1 + * for link in self.links: + * f.write("%d " % link) # <<<<<<<<<<<<<< + * f.write("\n") + * for i in self.sent_index: + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_link); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":92 + * for link in self.links: + * f.write("%d " % link) + * f.write("\n") # <<<<<<<<<<<<<< + * for i in self.sent_index: + * f.write("%d " % i) + */ + __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_35), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":93 + * f.write("%d " % link) + * f.write("\n") + * for i in self.sent_index: # <<<<<<<<<<<<<< + * f.write("%d " % i) + * f.write("\n") + */ + if (PyList_CheckExact(((PyObject *)__pyx_v_self->sent_index)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->sent_index))) { + __pyx_t_2 = ((PyObject *)__pyx_v_self->sent_index); __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(((PyObject *)__pyx_v_self->sent_index)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_4); __pyx_t_8++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_4); __pyx_t_8++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else { + __pyx_t_4 = __pyx_t_9(__pyx_t_2); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":94 + * f.write("\n") + * for i in self.sent_index: + * f.write("%d " % i) # <<<<<<<<<<<<<< + * f.write("\n") + * + */ + __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_10)); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_10)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); + __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":95 + * for i in self.sent_index: + * f.write("%d " % i) + * f.write("\n") # <<<<<<<<<<<<<< + * + * def alignment(self, i): + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_36), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":88 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * sent_num = 1 + * for link in self.links: + */ + /*except:*/ { + __Pyx_AddTraceback("_sa.Alignment.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_10, &__pyx_t_2, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_12 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_13 = (!__pyx_t_11); + if (__pyx_t_13) { + __Pyx_GIVEREF(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_ErrRestore(__pyx_t_10, __pyx_t_2, __pyx_t_1); + __pyx_t_10 = 0; __pyx_t_2 = 0; __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L22; + } + __pyx_L22:; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_37, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L23; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L23:; + } + + __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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("_sa.Alignment.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_link); + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9Alignment_17alignment(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static char __pyx_doc_3_sa_9Alignment_16alignment[] = "Return all (e,f) pairs for sentence i"; +static PyObject *__pyx_pw_3_sa_9Alignment_17alignment(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("alignment (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9Alignment_16alignment(((struct __pyx_obj_3_sa_Alignment *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":97 + * f.write("\n") + * + * def alignment(self, i): # <<<<<<<<<<<<<< + * """Return all (e,f) pairs for sentence i""" + * cdef int j, start, end + */ + +static PyObject *__pyx_pf_3_sa_9Alignment_16alignment(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_i) { + int __pyx_v_j; + int __pyx_v_start; + int __pyx_v_end; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("alignment", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":100 + * """Return all (e,f) pairs for sentence i""" + * cdef int j, start, end + * result = [] # <<<<<<<<<<<<<< + * start = self.sent_index.arr[i] + * end = self.sent_index.arr[i+1] + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":101 + * cdef int j, start, end + * result = [] + * start = self.sent_index.arr[i] # <<<<<<<<<<<<<< + * end = self.sent_index.arr[i+1] + * for j from start <= j < end: + */ + __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_start = (__pyx_v_self->sent_index->arr[__pyx_t_2]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":102 + * result = [] + * start = self.sent_index.arr[i] + * end = self.sent_index.arr[i+1] # <<<<<<<<<<<<<< + * for j from start <= j < end: + * result.append(self.unlink(self.links.arr[j])) + */ + __pyx_t_1 = PyNumber_Add(__pyx_v_i, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_end = (__pyx_v_self->sent_index->arr[__pyx_t_2]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":103 + * start = self.sent_index.arr[i] + * end = self.sent_index.arr[i+1] + * for j from start <= j < end: # <<<<<<<<<<<<<< + * result.append(self.unlink(self.links.arr[j])) + * return result + */ + __pyx_t_3 = __pyx_v_end; + for (__pyx_v_j = __pyx_v_start; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":104 + * end = self.sent_index.arr[i+1] + * for j from start <= j < end: + * result.append(self.unlink(self.links.arr[j])) # <<<<<<<<<<<<<< + * return result + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__unlink); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyInt_FromLong((__pyx_v_self->links->arr[__pyx_v_j])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_6 = PyList_Append(__pyx_v_result, __pyx_t_4); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":105 + * for j from start <= j < end: + * result.append(self.unlink(self.links.arr[j])) + * return result # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + 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_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_sa.Alignment.alignment", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":15 + * int val + * + * cdef _node* new_node(int key): # <<<<<<<<<<<<<< + * cdef _node* n + * n = <_node*> malloc(sizeof(_node)) + */ + +static struct __pyx_t_3_sa__node *__pyx_f_3_sa_new_node(int __pyx_v_key) { + struct __pyx_t_3_sa__node *__pyx_v_n; + struct __pyx_t_3_sa__node *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("new_node", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":17 + * cdef _node* new_node(int key): + * cdef _node* n + * n = <_node*> malloc(sizeof(_node)) # <<<<<<<<<<<<<< + * n.smaller = NULL + * n.bigger = NULL + */ + __pyx_v_n = ((struct __pyx_t_3_sa__node *)malloc((sizeof(struct __pyx_t_3_sa__node)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":18 + * cdef _node* n + * n = <_node*> malloc(sizeof(_node)) + * n.smaller = NULL # <<<<<<<<<<<<<< + * n.bigger = NULL + * n.key = key + */ + __pyx_v_n->smaller = NULL; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":19 + * n = <_node*> malloc(sizeof(_node)) + * n.smaller = NULL + * n.bigger = NULL # <<<<<<<<<<<<<< + * n.key = key + * n.val = 0 + */ + __pyx_v_n->bigger = NULL; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":20 + * n.smaller = NULL + * n.bigger = NULL + * n.key = key # <<<<<<<<<<<<<< + * n.val = 0 + * return n + */ + __pyx_v_n->key = __pyx_v_key; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":21 + * n.bigger = NULL + * n.key = key + * n.val = 0 # <<<<<<<<<<<<<< + * return n + * + */ + __pyx_v_n->val = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":22 + * n.key = key + * n.val = 0 + * return n # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_n; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":25 + * + * + * cdef del_node(_node* n): # <<<<<<<<<<<<<< + * if n.smaller != NULL: + * del_node(n.smaller) + */ + +static PyObject *__pyx_f_3_sa_del_node(struct __pyx_t_3_sa__node *__pyx_v_n) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("del_node", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":26 + * + * cdef del_node(_node* n): + * if n.smaller != NULL: # <<<<<<<<<<<<<< + * del_node(n.smaller) + * if n.bigger != NULL: + */ + __pyx_t_1 = (__pyx_v_n->smaller != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":27 + * cdef del_node(_node* n): + * if n.smaller != NULL: + * del_node(n.smaller) # <<<<<<<<<<<<<< + * if n.bigger != NULL: + * del_node(n.bigger) + */ + __pyx_t_2 = __pyx_f_3_sa_del_node(__pyx_v_n->smaller); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":28 + * if n.smaller != NULL: + * del_node(n.smaller) + * if n.bigger != NULL: # <<<<<<<<<<<<<< + * del_node(n.bigger) + * free(n) + */ + __pyx_t_1 = (__pyx_v_n->bigger != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":29 + * del_node(n.smaller) + * if n.bigger != NULL: + * del_node(n.bigger) # <<<<<<<<<<<<<< + * free(n) + * + */ + __pyx_t_2 = __pyx_f_3_sa_del_node(__pyx_v_n->bigger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":30 + * if n.bigger != NULL: + * del_node(n.bigger) + * free(n) # <<<<<<<<<<<<<< + * + * cdef int* get_val(_node* n, int key): + */ + free(__pyx_v_n); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_sa.del_node", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":32 + * free(n) + * + * cdef int* get_val(_node* n, int key): # <<<<<<<<<<<<<< + * if key == n.key: + * return &n.val + */ + +static int *__pyx_f_3_sa_get_val(struct __pyx_t_3_sa__node *__pyx_v_n, int __pyx_v_key) { + int *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("get_val", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":33 + * + * cdef int* get_val(_node* n, int key): + * if key == n.key: # <<<<<<<<<<<<<< + * return &n.val + * elif key < n.key: + */ + __pyx_t_1 = (__pyx_v_key == __pyx_v_n->key); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":34 + * cdef int* get_val(_node* n, int key): + * if key == n.key: + * return &n.val # <<<<<<<<<<<<<< + * elif key < n.key: + * if n.smaller == NULL: + */ + __pyx_r = (&__pyx_v_n->val); + goto __pyx_L0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":35 + * if key == n.key: + * return &n.val + * elif key < n.key: # <<<<<<<<<<<<<< + * if n.smaller == NULL: + * n.smaller = new_node(key) + */ + __pyx_t_1 = (__pyx_v_key < __pyx_v_n->key); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":36 + * return &n.val + * elif key < n.key: + * if n.smaller == NULL: # <<<<<<<<<<<<<< + * n.smaller = new_node(key) + * return &(n.smaller.val) + */ + __pyx_t_1 = (__pyx_v_n->smaller == NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":37 + * elif key < n.key: + * if n.smaller == NULL: + * n.smaller = new_node(key) # <<<<<<<<<<<<<< + * return &(n.smaller.val) + * return get_val(n.smaller, key) + */ + __pyx_v_n->smaller = __pyx_f_3_sa_new_node(__pyx_v_key); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":38 + * if n.smaller == NULL: + * n.smaller = new_node(key) + * return &(n.smaller.val) # <<<<<<<<<<<<<< + * return get_val(n.smaller, key) + * else: + */ + __pyx_r = (&__pyx_v_n->smaller->val); + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":39 + * n.smaller = new_node(key) + * return &(n.smaller.val) + * return get_val(n.smaller, key) # <<<<<<<<<<<<<< + * else: + * if n.bigger == NULL: + */ + __pyx_r = __pyx_f_3_sa_get_val(__pyx_v_n->smaller, __pyx_v_key); + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":41 + * return get_val(n.smaller, key) + * else: + * if n.bigger == NULL: # <<<<<<<<<<<<<< + * n.bigger = new_node(key) + * return &(n.bigger.val) + */ + __pyx_t_1 = (__pyx_v_n->bigger == NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":42 + * else: + * if n.bigger == NULL: + * n.bigger = new_node(key) # <<<<<<<<<<<<<< + * return &(n.bigger.val) + * return get_val(n.bigger, key) + */ + __pyx_v_n->bigger = __pyx_f_3_sa_new_node(__pyx_v_key); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":43 + * if n.bigger == NULL: + * n.bigger = new_node(key) + * return &(n.bigger.val) # <<<<<<<<<<<<<< + * return get_val(n.bigger, key) + * + */ + __pyx_r = (&__pyx_v_n->bigger->val); + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":44 + * n.bigger = new_node(key) + * return &(n.bigger.val) + * return get_val(n.bigger, key) # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_f_3_sa_get_val(__pyx_v_n->bigger, __pyx_v_key); + goto __pyx_L0; + } + __pyx_L3:; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_5BiLex_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_5BiLex_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_from_text = 0; + PyObject *__pyx_v_from_data = 0; + PyObject *__pyx_v_from_binary = 0; + PyObject *__pyx_v_earray = 0; + PyObject *__pyx_v_fsarray = 0; + PyObject *__pyx_v_alignment = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__from_text,&__pyx_n_s__from_data,&__pyx_n_s__from_binary,&__pyx_n_s__earray,&__pyx_n_s__fsarray,&__pyx_n_s__alignment,0}; + PyObject* values[6] = {0,0,0,0,0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":54 + * cdef id2eword, id2fword, eword2id, fword2id + * + * def __cinit__(self, from_text=None, from_data=False, from_binary=None, # <<<<<<<<<<<<<< + * earray=None, fsarray=None, alignment=None): + * self.id2eword = [] + */ + values[0] = ((PyObject *)Py_None); + values[1] = __pyx_k_38; + values[2] = ((PyObject *)Py_None); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":55 + * + * def __cinit__(self, from_text=None, from_data=False, from_binary=None, + * earray=None, fsarray=None, alignment=None): # <<<<<<<<<<<<<< + * self.id2eword = [] + * self.id2fword = [] + */ + values[3] = ((PyObject *)Py_None); + values[4] = ((PyObject *)Py_None); + values[5] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_text); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_data); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_binary); + if (value) { values[2] = value; kw_args--; } + } + case 3: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__earray); + if (value) { values[3] = value; kw_args--; } + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fsarray); + if (value) { values[4] = value; kw_args--; } + } + case 5: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__alignment); + if (value) { values[5] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_from_text = values[0]; + __pyx_v_from_data = values[1]; + __pyx_v_from_binary = values[2]; + __pyx_v_earray = values[3]; + __pyx_v_fsarray = values[4]; + __pyx_v_alignment = values[5]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.BiLex.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_5BiLex___cinit__(((struct __pyx_obj_3_sa_BiLex *)__pyx_v_self), __pyx_v_from_text, __pyx_v_from_data, __pyx_v_from_binary, __pyx_v_earray, __pyx_v_fsarray, __pyx_v_alignment); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":54 + * cdef id2eword, id2fword, eword2id, fword2id + * + * def __cinit__(self, from_text=None, from_data=False, from_binary=None, # <<<<<<<<<<<<<< + * earray=None, fsarray=None, alignment=None): + * self.id2eword = [] + */ + +static int __pyx_pf_3_sa_5BiLex___cinit__(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_from_text, PyObject *__pyx_v_from_data, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_earray, PyObject *__pyx_v_fsarray, PyObject *__pyx_v_alignment) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":56 + * def __cinit__(self, from_text=None, from_data=False, from_binary=None, + * earray=None, fsarray=None, alignment=None): + * self.id2eword = [] # <<<<<<<<<<<<<< + * self.id2fword = [] + * self.eword2id = {} + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_GOTREF(__pyx_v_self->id2eword); + __Pyx_DECREF(__pyx_v_self->id2eword); + __pyx_v_self->id2eword = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":57 + * earray=None, fsarray=None, alignment=None): + * self.id2eword = [] + * self.id2fword = [] # <<<<<<<<<<<<<< + * self.eword2id = {} + * self.fword2id = {} + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_GOTREF(__pyx_v_self->id2fword); + __Pyx_DECREF(__pyx_v_self->id2fword); + __pyx_v_self->id2fword = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":58 + * self.id2eword = [] + * self.id2fword = [] + * self.eword2id = {} # <<<<<<<<<<<<<< + * self.fword2id = {} + * self.e_index = IntList() + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_GOTREF(__pyx_v_self->eword2id); + __Pyx_DECREF(__pyx_v_self->eword2id); + __pyx_v_self->eword2id = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":59 + * self.id2fword = [] + * self.eword2id = {} + * self.fword2id = {} # <<<<<<<<<<<<<< + * self.e_index = IntList() + * self.f_index = IntList() + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_GOTREF(__pyx_v_self->fword2id); + __Pyx_DECREF(__pyx_v_self->fword2id); + __pyx_v_self->fword2id = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":60 + * self.eword2id = {} + * self.fword2id = {} + * self.e_index = IntList() # <<<<<<<<<<<<<< + * self.f_index = IntList() + * self.col1 = FloatList() + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->e_index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->e_index)); + __pyx_v_self->e_index = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":61 + * self.fword2id = {} + * self.e_index = IntList() + * self.f_index = IntList() # <<<<<<<<<<<<<< + * self.col1 = FloatList() + * self.col2 = FloatList() + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->f_index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->f_index)); + __pyx_v_self->f_index = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":62 + * self.e_index = IntList() + * self.f_index = IntList() + * self.col1 = FloatList() # <<<<<<<<<<<<<< + * self.col2 = FloatList() + * if from_binary: + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_FloatList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->col1); + __Pyx_DECREF(((PyObject *)__pyx_v_self->col1)); + __pyx_v_self->col1 = ((struct __pyx_obj_3_sa_FloatList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":63 + * self.f_index = IntList() + * self.col1 = FloatList() + * self.col2 = FloatList() # <<<<<<<<<<<<<< + * if from_binary: + * self.read_binary(from_binary) + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_FloatList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->col2); + __Pyx_DECREF(((PyObject *)__pyx_v_self->col2)); + __pyx_v_self->col2 = ((struct __pyx_obj_3_sa_FloatList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":64 + * self.col1 = FloatList() + * self.col2 = FloatList() + * if from_binary: # <<<<<<<<<<<<<< + * self.read_binary(from_binary) + * elif from_data: + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_binary); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":65 + * self.col2 = FloatList() + * if from_binary: + * self.read_binary(from_binary) # <<<<<<<<<<<<<< + * elif from_data: + * self.compute_from_data(fsarray, earray, alignment) + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_binary); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_from_binary); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_binary); + __Pyx_GIVEREF(__pyx_v_from_binary); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":66 + * if from_binary: + * self.read_binary(from_binary) + * elif from_data: # <<<<<<<<<<<<<< + * self.compute_from_data(fsarray, earray, alignment) + * else: + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_data); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":67 + * self.read_binary(from_binary) + * elif from_data: + * self.compute_from_data(fsarray, earray, alignment) # <<<<<<<<<<<<<< + * else: + * self.read_text(from_text) + */ + if (!(likely(((__pyx_v_fsarray) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_fsarray, __pyx_ptype_3_sa_SuffixArray))))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __pyx_v_fsarray; + __Pyx_INCREF(__pyx_t_4); + if (!(likely(((__pyx_v_earray) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_earray, __pyx_ptype_3_sa_DataArray))))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_v_earray; + __Pyx_INCREF(__pyx_t_3); + if (!(likely(((__pyx_v_alignment) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_alignment, __pyx_ptype_3_sa_Alignment))))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_v_alignment; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_5 = ((struct __pyx_vtabstruct_3_sa_BiLex *)__pyx_v_self->__pyx_vtab)->compute_from_data(__pyx_v_self, ((struct __pyx_obj_3_sa_SuffixArray *)__pyx_t_4), ((struct __pyx_obj_3_sa_DataArray *)__pyx_t_3), ((struct __pyx_obj_3_sa_Alignment *)__pyx_t_1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":69 + * self.compute_from_data(fsarray, earray, alignment) + * else: + * self.read_text(from_text) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_text); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_from_text); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_from_text); + __Pyx_GIVEREF(__pyx_v_from_text); + __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_sa.BiLex.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":72 + * + * + * cdef compute_from_data(self, SuffixArray fsa, DataArray eda, Alignment aa): # <<<<<<<<<<<<<< + * cdef int sent_id, num_links, l, i, j, f_i, e_j, I, J, V_E, V_F, num_pairs + * cdef int *fsent, *esent, *alignment, *links, *ealigned, *faligned + */ + +static PyObject *__pyx_f_3_sa_5BiLex_compute_from_data(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, struct __pyx_obj_3_sa_SuffixArray *__pyx_v_fsa, struct __pyx_obj_3_sa_DataArray *__pyx_v_eda, struct __pyx_obj_3_sa_Alignment *__pyx_v_aa) { + int __pyx_v_sent_id; + int __pyx_v_num_links; + int __pyx_v_l; + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_f_i; + int __pyx_v_e_j; + int __pyx_v_I; + int __pyx_v_J; + int __pyx_v_V_E; + int __pyx_v_V_F; + int __pyx_v_num_pairs; + int *__pyx_v_fsent; + int *__pyx_v_esent; + int *__pyx_v_links; + int *__pyx_v_ealigned; + int *__pyx_v_faligned; + struct __pyx_t_3_sa__node **__pyx_v_dict; + int *__pyx_v_fmargin; + int *__pyx_v_emargin; + int *__pyx_v_count; + PyObject *__pyx_v_word = 0; + int __pyx_v_null_word; + PyObject *__pyx_v_id = NULL; + PyObject *__pyx_v_num_sents = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + int __pyx_t_9; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("compute_from_data", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":80 + * cdef int null_word + * + * null_word = 0 # <<<<<<<<<<<<<< + * for word in fsa.darray.id2word: # I miss list comprehensions + * self.id2fword.append(word) + */ + __pyx_v_null_word = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":81 + * + * null_word = 0 + * for word in fsa.darray.id2word: # I miss list comprehensions # <<<<<<<<<<<<<< + * self.id2fword.append(word) + * self.id2fword[null_word] = "NULL" + */ + if (PyList_CheckExact(__pyx_v_fsa->darray->id2word) || PyTuple_CheckExact(__pyx_v_fsa->darray->id2word)) { + __pyx_t_1 = __pyx_v_fsa->darray->id2word; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_fsa->darray->id2word); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XDECREF(((PyObject *)__pyx_v_word)); + __pyx_v_word = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":82 + * null_word = 0 + * for word in fsa.darray.id2word: # I miss list comprehensions + * self.id2fword.append(word) # <<<<<<<<<<<<<< + * self.id2fword[null_word] = "NULL" + * for id, word in enumerate(self.id2fword): + */ + __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_self->id2fword, ((PyObject *)__pyx_v_word)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":83 + * for word in fsa.darray.id2word: # I miss list comprehensions + * self.id2fword.append(word) + * self.id2fword[null_word] = "NULL" # <<<<<<<<<<<<<< + * for id, word in enumerate(self.id2fword): + * self.fword2id[word] = id + */ + if (__Pyx_SetItemInt(__pyx_v_self->id2fword, __pyx_v_null_word, ((PyObject *)__pyx_n_s__NULL), sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":84 + * self.id2fword.append(word) + * self.id2fword[null_word] = "NULL" + * for id, word in enumerate(self.id2fword): # <<<<<<<<<<<<<< + * self.fword2id[word] = id + * + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_1 = __pyx_int_0; + if (PyList_CheckExact(__pyx_v_self->id2fword) || PyTuple_CheckExact(__pyx_v_self->id2fword)) { + __pyx_t_4 = __pyx_v_self->id2fword; __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_self->id2fword); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_5 = __pyx_t_3(__pyx_t_4); + if (unlikely(!__pyx_t_5)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_5); + } + if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XDECREF(((PyObject *)__pyx_v_word)); + __pyx_v_word = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; + __Pyx_INCREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_id); + __pyx_v_id = __pyx_t_1; + __pyx_t_5 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); + __pyx_t_1 = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":85 + * self.id2fword[null_word] = "NULL" + * for id, word in enumerate(self.id2fword): + * self.fword2id[word] = id # <<<<<<<<<<<<<< + * + * for word in eda.id2word: + */ + if (PyObject_SetItem(__pyx_v_self->fword2id, ((PyObject *)__pyx_v_word), __pyx_v_id) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":87 + * self.fword2id[word] = id + * + * for word in eda.id2word: # <<<<<<<<<<<<<< + * self.id2eword.append(word) + * self.id2eword[null_word] = "NULL" + */ + if (PyList_CheckExact(__pyx_v_eda->id2word) || PyTuple_CheckExact(__pyx_v_eda->id2word)) { + __pyx_t_1 = __pyx_v_eda->id2word; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_eda->id2word); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_4)->tp_name), 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XDECREF(((PyObject *)__pyx_v_word)); + __pyx_v_word = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":88 + * + * for word in eda.id2word: + * self.id2eword.append(word) # <<<<<<<<<<<<<< + * self.id2eword[null_word] = "NULL" + * for id, word in enumerate(self.id2eword): + */ + __pyx_t_4 = __Pyx_PyObject_Append(__pyx_v_self->id2eword, ((PyObject *)__pyx_v_word)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":89 + * for word in eda.id2word: + * self.id2eword.append(word) + * self.id2eword[null_word] = "NULL" # <<<<<<<<<<<<<< + * for id, word in enumerate(self.id2eword): + * self.eword2id[word] = id + */ + if (__Pyx_SetItemInt(__pyx_v_self->id2eword, __pyx_v_null_word, ((PyObject *)__pyx_n_s__NULL), sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":90 + * self.id2eword.append(word) + * self.id2eword[null_word] = "NULL" + * for id, word in enumerate(self.id2eword): # <<<<<<<<<<<<<< + * self.eword2id[word] = id + * + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_1 = __pyx_int_0; + if (PyList_CheckExact(__pyx_v_self->id2eword) || PyTuple_CheckExact(__pyx_v_self->id2eword)) { + __pyx_t_4 = __pyx_v_self->id2eword; __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_self->id2eword); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_5 = __pyx_t_3(__pyx_t_4); + if (unlikely(!__pyx_t_5)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_5); + } + if (!(likely(PyBytes_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_5)->tp_name), 0))) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XDECREF(((PyObject *)__pyx_v_word)); + __pyx_v_word = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; + __Pyx_INCREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_id); + __pyx_v_id = __pyx_t_1; + __pyx_t_5 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); + __pyx_t_1 = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":91 + * self.id2eword[null_word] = "NULL" + * for id, word in enumerate(self.id2eword): + * self.eword2id[word] = id # <<<<<<<<<<<<<< + * + * num_pairs = 0 + */ + if (PyObject_SetItem(__pyx_v_self->eword2id, ((PyObject *)__pyx_v_word), __pyx_v_id) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":93 + * self.eword2id[word] = id + * + * num_pairs = 0 # <<<<<<<<<<<<<< + * + * V_E = len(eda.id2word) + */ + __pyx_v_num_pairs = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":95 + * num_pairs = 0 + * + * V_E = len(eda.id2word) # <<<<<<<<<<<<<< + * V_F = len(fsa.darray.id2word) + * fmargin = malloc(V_F*sizeof(int)) + */ + __pyx_t_1 = __pyx_v_eda->id2word; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_V_E = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":96 + * + * V_E = len(eda.id2word) + * V_F = len(fsa.darray.id2word) # <<<<<<<<<<<<<< + * fmargin = malloc(V_F*sizeof(int)) + * emargin = malloc(V_E*sizeof(int)) + */ + __pyx_t_1 = __pyx_v_fsa->darray->id2word; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_V_F = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":97 + * V_E = len(eda.id2word) + * V_F = len(fsa.darray.id2word) + * fmargin = malloc(V_F*sizeof(int)) # <<<<<<<<<<<<<< + * emargin = malloc(V_E*sizeof(int)) + * memset(fmargin, 0, V_F*sizeof(int)) + */ + __pyx_v_fmargin = ((int *)malloc((__pyx_v_V_F * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":98 + * V_F = len(fsa.darray.id2word) + * fmargin = malloc(V_F*sizeof(int)) + * emargin = malloc(V_E*sizeof(int)) # <<<<<<<<<<<<<< + * memset(fmargin, 0, V_F*sizeof(int)) + * memset(emargin, 0, V_E*sizeof(int)) + */ + __pyx_v_emargin = ((int *)malloc((__pyx_v_V_E * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":99 + * fmargin = malloc(V_F*sizeof(int)) + * emargin = malloc(V_E*sizeof(int)) + * memset(fmargin, 0, V_F*sizeof(int)) # <<<<<<<<<<<<<< + * memset(emargin, 0, V_E*sizeof(int)) + * + */ + memset(__pyx_v_fmargin, 0, (__pyx_v_V_F * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":100 + * emargin = malloc(V_E*sizeof(int)) + * memset(fmargin, 0, V_F*sizeof(int)) + * memset(emargin, 0, V_E*sizeof(int)) # <<<<<<<<<<<<<< + * + * dict = <_node**> malloc(V_F*sizeof(_node*)) + */ + memset(__pyx_v_emargin, 0, (__pyx_v_V_E * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":102 + * memset(emargin, 0, V_E*sizeof(int)) + * + * dict = <_node**> malloc(V_F*sizeof(_node*)) # <<<<<<<<<<<<<< + * memset(dict, 0, V_F*sizeof(_node*)) + * + */ + __pyx_v_dict = ((struct __pyx_t_3_sa__node **)malloc((__pyx_v_V_F * (sizeof(struct __pyx_t_3_sa__node *))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":103 + * + * dict = <_node**> malloc(V_F*sizeof(_node*)) + * memset(dict, 0, V_F*sizeof(_node*)) # <<<<<<<<<<<<<< + * + * num_sents = len(fsa.darray.sent_index) + */ + memset(__pyx_v_dict, 0, (__pyx_v_V_F * (sizeof(struct __pyx_t_3_sa__node *)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":105 + * memset(dict, 0, V_F*sizeof(_node*)) + * + * num_sents = len(fsa.darray.sent_index) # <<<<<<<<<<<<<< + * for sent_id from 0 <= sent_id < num_sents-1: + * + */ + __pyx_t_1 = ((PyObject *)__pyx_v_fsa->darray->sent_index); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_num_sents = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":106 + * + * num_sents = len(fsa.darray.sent_index) + * for sent_id from 0 <= sent_id < num_sents-1: # <<<<<<<<<<<<<< + * + * fsent = fsa.darray.data.arr + fsa.darray.sent_index.arr[sent_id] + */ + __pyx_t_1 = PyNumber_Subtract(__pyx_v_num_sents, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (__pyx_v_sent_id = 0; __pyx_v_sent_id < __pyx_t_6; __pyx_v_sent_id++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":108 + * for sent_id from 0 <= sent_id < num_sents-1: + * + * fsent = fsa.darray.data.arr + fsa.darray.sent_index.arr[sent_id] # <<<<<<<<<<<<<< + * I = fsa.darray.sent_index.arr[sent_id+1] - fsa.darray.sent_index.arr[sent_id] - 1 + * faligned = malloc(I*sizeof(int)) + */ + __pyx_v_fsent = (__pyx_v_fsa->darray->data->arr + (__pyx_v_fsa->darray->sent_index->arr[__pyx_v_sent_id])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":109 + * + * fsent = fsa.darray.data.arr + fsa.darray.sent_index.arr[sent_id] + * I = fsa.darray.sent_index.arr[sent_id+1] - fsa.darray.sent_index.arr[sent_id] - 1 # <<<<<<<<<<<<<< + * faligned = malloc(I*sizeof(int)) + * memset(faligned, 0, I*sizeof(int)) + */ + __pyx_v_I = (((__pyx_v_fsa->darray->sent_index->arr[(__pyx_v_sent_id + 1)]) - (__pyx_v_fsa->darray->sent_index->arr[__pyx_v_sent_id])) - 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":110 + * fsent = fsa.darray.data.arr + fsa.darray.sent_index.arr[sent_id] + * I = fsa.darray.sent_index.arr[sent_id+1] - fsa.darray.sent_index.arr[sent_id] - 1 + * faligned = malloc(I*sizeof(int)) # <<<<<<<<<<<<<< + * memset(faligned, 0, I*sizeof(int)) + * + */ + __pyx_v_faligned = ((int *)malloc((__pyx_v_I * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":111 + * I = fsa.darray.sent_index.arr[sent_id+1] - fsa.darray.sent_index.arr[sent_id] - 1 + * faligned = malloc(I*sizeof(int)) + * memset(faligned, 0, I*sizeof(int)) # <<<<<<<<<<<<<< + * + * esent = eda.data.arr + eda.sent_index.arr[sent_id] + */ + memset(__pyx_v_faligned, 0, (__pyx_v_I * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":113 + * memset(faligned, 0, I*sizeof(int)) + * + * esent = eda.data.arr + eda.sent_index.arr[sent_id] # <<<<<<<<<<<<<< + * J = eda.sent_index.arr[sent_id+1] - eda.sent_index.arr[sent_id] - 1 + * ealigned = malloc(J*sizeof(int)) + */ + __pyx_v_esent = (__pyx_v_eda->data->arr + (__pyx_v_eda->sent_index->arr[__pyx_v_sent_id])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":114 + * + * esent = eda.data.arr + eda.sent_index.arr[sent_id] + * J = eda.sent_index.arr[sent_id+1] - eda.sent_index.arr[sent_id] - 1 # <<<<<<<<<<<<<< + * ealigned = malloc(J*sizeof(int)) + * memset(ealigned, 0, J*sizeof(int)) + */ + __pyx_v_J = (((__pyx_v_eda->sent_index->arr[(__pyx_v_sent_id + 1)]) - (__pyx_v_eda->sent_index->arr[__pyx_v_sent_id])) - 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":115 + * esent = eda.data.arr + eda.sent_index.arr[sent_id] + * J = eda.sent_index.arr[sent_id+1] - eda.sent_index.arr[sent_id] - 1 + * ealigned = malloc(J*sizeof(int)) # <<<<<<<<<<<<<< + * memset(ealigned, 0, J*sizeof(int)) + * + */ + __pyx_v_ealigned = ((int *)malloc((__pyx_v_J * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":116 + * J = eda.sent_index.arr[sent_id+1] - eda.sent_index.arr[sent_id] - 1 + * ealigned = malloc(J*sizeof(int)) + * memset(ealigned, 0, J*sizeof(int)) # <<<<<<<<<<<<<< + * + * links = aa._get_sent_links(sent_id, &num_links) + */ + memset(__pyx_v_ealigned, 0, (__pyx_v_J * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":118 + * memset(ealigned, 0, J*sizeof(int)) + * + * links = aa._get_sent_links(sent_id, &num_links) # <<<<<<<<<<<<<< + * + * for l from 0 <= l < num_links: + */ + __pyx_v_links = ((struct __pyx_vtabstruct_3_sa_Alignment *)__pyx_v_aa->__pyx_vtab)->_get_sent_links(__pyx_v_aa, __pyx_v_sent_id, (&__pyx_v_num_links)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":120 + * links = aa._get_sent_links(sent_id, &num_links) + * + * for l from 0 <= l < num_links: # <<<<<<<<<<<<<< + * i = links[l*2] + * j = links[l*2+1] + */ + __pyx_t_7 = __pyx_v_num_links; + for (__pyx_v_l = 0; __pyx_v_l < __pyx_t_7; __pyx_v_l++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":121 + * + * for l from 0 <= l < num_links: + * i = links[l*2] # <<<<<<<<<<<<<< + * j = links[l*2+1] + * if i >= I or j >= J: + */ + __pyx_v_i = (__pyx_v_links[(__pyx_v_l * 2)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":122 + * for l from 0 <= l < num_links: + * i = links[l*2] + * j = links[l*2+1] # <<<<<<<<<<<<<< + * if i >= I or j >= J: + * raise Exception("%d-%d out of bounds (I=%d,J=%d) in line %d\n" % (i,j,I,J,sent_id+1)) + */ + __pyx_v_j = (__pyx_v_links[((__pyx_v_l * 2) + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":123 + * i = links[l*2] + * j = links[l*2+1] + * if i >= I or j >= J: # <<<<<<<<<<<<<< + * raise Exception("%d-%d out of bounds (I=%d,J=%d) in line %d\n" % (i,j,I,J,sent_id+1)) + * f_i = fsent[i] + */ + __pyx_t_8 = (__pyx_v_i >= __pyx_v_I); + if (!__pyx_t_8) { + __pyx_t_9 = (__pyx_v_j >= __pyx_v_J); + __pyx_t_10 = __pyx_t_9; + } else { + __pyx_t_10 = __pyx_t_8; + } + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":124 + * j = links[l*2+1] + * if i >= I or j >= J: + * raise Exception("%d-%d out of bounds (I=%d,J=%d) in line %d\n" % (i,j,I,J,sent_id+1)) # <<<<<<<<<<<<<< + * f_i = fsent[i] + * e_j = esent[j] + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyInt_FromLong(__pyx_v_j); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyInt_FromLong(__pyx_v_I); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_11 = PyInt_FromLong(__pyx_v_J); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_12 = PyInt_FromLong((__pyx_v_sent_id + 1)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = PyTuple_New(5); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_t_11); + __Pyx_GIVEREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_13, 4, __pyx_t_12); + __Pyx_GIVEREF(__pyx_t_12); + __pyx_t_1 = 0; + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_t_11 = 0; + __pyx_t_12 = 0; + __pyx_t_12 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_39), ((PyObject *)__pyx_t_13)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_12)); + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + PyTuple_SET_ITEM(__pyx_t_13, 0, ((PyObject *)__pyx_t_12)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_12)); + __pyx_t_12 = 0; + __pyx_t_12 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + __Pyx_Raise(__pyx_t_12, 0, 0, 0); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L15; + } + __pyx_L15:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":125 + * if i >= I or j >= J: + * raise Exception("%d-%d out of bounds (I=%d,J=%d) in line %d\n" % (i,j,I,J,sent_id+1)) + * f_i = fsent[i] # <<<<<<<<<<<<<< + * e_j = esent[j] + * fmargin[f_i] = fmargin[f_i]+1 + */ + __pyx_v_f_i = (__pyx_v_fsent[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":126 + * raise Exception("%d-%d out of bounds (I=%d,J=%d) in line %d\n" % (i,j,I,J,sent_id+1)) + * f_i = fsent[i] + * e_j = esent[j] # <<<<<<<<<<<<<< + * fmargin[f_i] = fmargin[f_i]+1 + * emargin[e_j] = emargin[e_j]+1 + */ + __pyx_v_e_j = (__pyx_v_esent[__pyx_v_j]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":127 + * f_i = fsent[i] + * e_j = esent[j] + * fmargin[f_i] = fmargin[f_i]+1 # <<<<<<<<<<<<<< + * emargin[e_j] = emargin[e_j]+1 + * if dict[f_i] == NULL: + */ + (__pyx_v_fmargin[__pyx_v_f_i]) = ((__pyx_v_fmargin[__pyx_v_f_i]) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":128 + * e_j = esent[j] + * fmargin[f_i] = fmargin[f_i]+1 + * emargin[e_j] = emargin[e_j]+1 # <<<<<<<<<<<<<< + * if dict[f_i] == NULL: + * dict[f_i] = new_node(e_j) + */ + (__pyx_v_emargin[__pyx_v_e_j]) = ((__pyx_v_emargin[__pyx_v_e_j]) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":129 + * fmargin[f_i] = fmargin[f_i]+1 + * emargin[e_j] = emargin[e_j]+1 + * if dict[f_i] == NULL: # <<<<<<<<<<<<<< + * dict[f_i] = new_node(e_j) + * dict[f_i].val = 1 + */ + __pyx_t_10 = ((__pyx_v_dict[__pyx_v_f_i]) == NULL); + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":130 + * emargin[e_j] = emargin[e_j]+1 + * if dict[f_i] == NULL: + * dict[f_i] = new_node(e_j) # <<<<<<<<<<<<<< + * dict[f_i].val = 1 + * num_pairs = num_pairs + 1 + */ + (__pyx_v_dict[__pyx_v_f_i]) = __pyx_f_3_sa_new_node(__pyx_v_e_j); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":131 + * if dict[f_i] == NULL: + * dict[f_i] = new_node(e_j) + * dict[f_i].val = 1 # <<<<<<<<<<<<<< + * num_pairs = num_pairs + 1 + * else: + */ + (__pyx_v_dict[__pyx_v_f_i])->val = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":132 + * dict[f_i] = new_node(e_j) + * dict[f_i].val = 1 + * num_pairs = num_pairs + 1 # <<<<<<<<<<<<<< + * else: + * count = get_val(dict[f_i], e_j) + */ + __pyx_v_num_pairs = (__pyx_v_num_pairs + 1); + goto __pyx_L16; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":134 + * num_pairs = num_pairs + 1 + * else: + * count = get_val(dict[f_i], e_j) # <<<<<<<<<<<<<< + * if count[0] == 0: + * num_pairs = num_pairs + 1 + */ + __pyx_v_count = __pyx_f_3_sa_get_val((__pyx_v_dict[__pyx_v_f_i]), __pyx_v_e_j); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":135 + * else: + * count = get_val(dict[f_i], e_j) + * if count[0] == 0: # <<<<<<<<<<<<<< + * num_pairs = num_pairs + 1 + * count[0] = count[0] + 1 + */ + __pyx_t_10 = ((__pyx_v_count[0]) == 0); + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":136 + * count = get_val(dict[f_i], e_j) + * if count[0] == 0: + * num_pairs = num_pairs + 1 # <<<<<<<<<<<<<< + * count[0] = count[0] + 1 + * # add count + */ + __pyx_v_num_pairs = (__pyx_v_num_pairs + 1); + goto __pyx_L17; + } + __pyx_L17:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":137 + * if count[0] == 0: + * num_pairs = num_pairs + 1 + * count[0] = count[0] + 1 # <<<<<<<<<<<<<< + * # add count + * faligned[i] = 1 + */ + (__pyx_v_count[0]) = ((__pyx_v_count[0]) + 1); + } + __pyx_L16:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":139 + * count[0] = count[0] + 1 + * # add count + * faligned[i] = 1 # <<<<<<<<<<<<<< + * ealigned[j] = 1 + * for i from 0 <= i < I: + */ + (__pyx_v_faligned[__pyx_v_i]) = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":140 + * # add count + * faligned[i] = 1 + * ealigned[j] = 1 # <<<<<<<<<<<<<< + * for i from 0 <= i < I: + * if faligned[i] == 0: + */ + (__pyx_v_ealigned[__pyx_v_j]) = 1; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":141 + * faligned[i] = 1 + * ealigned[j] = 1 + * for i from 0 <= i < I: # <<<<<<<<<<<<<< + * if faligned[i] == 0: + * f_i = fsent[i] + */ + __pyx_t_7 = __pyx_v_I; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_7; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":142 + * ealigned[j] = 1 + * for i from 0 <= i < I: + * if faligned[i] == 0: # <<<<<<<<<<<<<< + * f_i = fsent[i] + * fmargin[f_i] = fmargin[f_i] + 1 + */ + __pyx_t_10 = ((__pyx_v_faligned[__pyx_v_i]) == 0); + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":143 + * for i from 0 <= i < I: + * if faligned[i] == 0: + * f_i = fsent[i] # <<<<<<<<<<<<<< + * fmargin[f_i] = fmargin[f_i] + 1 + * emargin[null_word] = emargin[null_word] + 1 + */ + __pyx_v_f_i = (__pyx_v_fsent[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":144 + * if faligned[i] == 0: + * f_i = fsent[i] + * fmargin[f_i] = fmargin[f_i] + 1 # <<<<<<<<<<<<<< + * emargin[null_word] = emargin[null_word] + 1 + * if dict[f_i] == NULL: + */ + (__pyx_v_fmargin[__pyx_v_f_i]) = ((__pyx_v_fmargin[__pyx_v_f_i]) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":145 + * f_i = fsent[i] + * fmargin[f_i] = fmargin[f_i] + 1 + * emargin[null_word] = emargin[null_word] + 1 # <<<<<<<<<<<<<< + * if dict[f_i] == NULL: + * dict[f_i] = new_node(null_word) + */ + (__pyx_v_emargin[__pyx_v_null_word]) = ((__pyx_v_emargin[__pyx_v_null_word]) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":146 + * fmargin[f_i] = fmargin[f_i] + 1 + * emargin[null_word] = emargin[null_word] + 1 + * if dict[f_i] == NULL: # <<<<<<<<<<<<<< + * dict[f_i] = new_node(null_word) + * dict[f_i].val = 1 + */ + __pyx_t_10 = ((__pyx_v_dict[__pyx_v_f_i]) == NULL); + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":147 + * emargin[null_word] = emargin[null_word] + 1 + * if dict[f_i] == NULL: + * dict[f_i] = new_node(null_word) # <<<<<<<<<<<<<< + * dict[f_i].val = 1 + * num_pairs = num_pairs + 1 + */ + (__pyx_v_dict[__pyx_v_f_i]) = __pyx_f_3_sa_new_node(__pyx_v_null_word); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":148 + * if dict[f_i] == NULL: + * dict[f_i] = new_node(null_word) + * dict[f_i].val = 1 # <<<<<<<<<<<<<< + * num_pairs = num_pairs + 1 + * else: + */ + (__pyx_v_dict[__pyx_v_f_i])->val = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":149 + * dict[f_i] = new_node(null_word) + * dict[f_i].val = 1 + * num_pairs = num_pairs + 1 # <<<<<<<<<<<<<< + * else: + * count = get_val(dict[f_i], null_word) + */ + __pyx_v_num_pairs = (__pyx_v_num_pairs + 1); + goto __pyx_L21; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":151 + * num_pairs = num_pairs + 1 + * else: + * count = get_val(dict[f_i], null_word) # <<<<<<<<<<<<<< + * if count[0] == 0: + * num_pairs = num_pairs + 1 + */ + __pyx_v_count = __pyx_f_3_sa_get_val((__pyx_v_dict[__pyx_v_f_i]), __pyx_v_null_word); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":152 + * else: + * count = get_val(dict[f_i], null_word) + * if count[0] == 0: # <<<<<<<<<<<<<< + * num_pairs = num_pairs + 1 + * count[0] = count[0] + 1 + */ + __pyx_t_10 = ((__pyx_v_count[0]) == 0); + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":153 + * count = get_val(dict[f_i], null_word) + * if count[0] == 0: + * num_pairs = num_pairs + 1 # <<<<<<<<<<<<<< + * count[0] = count[0] + 1 + * for j from 0 <= j < J: + */ + __pyx_v_num_pairs = (__pyx_v_num_pairs + 1); + goto __pyx_L22; + } + __pyx_L22:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":154 + * if count[0] == 0: + * num_pairs = num_pairs + 1 + * count[0] = count[0] + 1 # <<<<<<<<<<<<<< + * for j from 0 <= j < J: + * if ealigned[j] == 0: + */ + (__pyx_v_count[0]) = ((__pyx_v_count[0]) + 1); + } + __pyx_L21:; + goto __pyx_L20; + } + __pyx_L20:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":155 + * num_pairs = num_pairs + 1 + * count[0] = count[0] + 1 + * for j from 0 <= j < J: # <<<<<<<<<<<<<< + * if ealigned[j] == 0: + * e_j = esent[j] + */ + __pyx_t_7 = __pyx_v_J; + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_7; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":156 + * count[0] = count[0] + 1 + * for j from 0 <= j < J: + * if ealigned[j] == 0: # <<<<<<<<<<<<<< + * e_j = esent[j] + * fmargin[null_word] = fmargin[null_word] + 1 + */ + __pyx_t_10 = ((__pyx_v_ealigned[__pyx_v_j]) == 0); + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":157 + * for j from 0 <= j < J: + * if ealigned[j] == 0: + * e_j = esent[j] # <<<<<<<<<<<<<< + * fmargin[null_word] = fmargin[null_word] + 1 + * emargin[e_j] = emargin[e_j] + 1 + */ + __pyx_v_e_j = (__pyx_v_esent[__pyx_v_j]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":158 + * if ealigned[j] == 0: + * e_j = esent[j] + * fmargin[null_word] = fmargin[null_word] + 1 # <<<<<<<<<<<<<< + * emargin[e_j] = emargin[e_j] + 1 + * if dict[null_word] == NULL: + */ + (__pyx_v_fmargin[__pyx_v_null_word]) = ((__pyx_v_fmargin[__pyx_v_null_word]) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":159 + * e_j = esent[j] + * fmargin[null_word] = fmargin[null_word] + 1 + * emargin[e_j] = emargin[e_j] + 1 # <<<<<<<<<<<<<< + * if dict[null_word] == NULL: + * dict[null_word] = new_node(e_j) + */ + (__pyx_v_emargin[__pyx_v_e_j]) = ((__pyx_v_emargin[__pyx_v_e_j]) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":160 + * fmargin[null_word] = fmargin[null_word] + 1 + * emargin[e_j] = emargin[e_j] + 1 + * if dict[null_word] == NULL: # <<<<<<<<<<<<<< + * dict[null_word] = new_node(e_j) + * dict[null_word].val = 1 + */ + __pyx_t_10 = ((__pyx_v_dict[__pyx_v_null_word]) == NULL); + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":161 + * emargin[e_j] = emargin[e_j] + 1 + * if dict[null_word] == NULL: + * dict[null_word] = new_node(e_j) # <<<<<<<<<<<<<< + * dict[null_word].val = 1 + * num_pairs = num_pairs + 1 + */ + (__pyx_v_dict[__pyx_v_null_word]) = __pyx_f_3_sa_new_node(__pyx_v_e_j); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":162 + * if dict[null_word] == NULL: + * dict[null_word] = new_node(e_j) + * dict[null_word].val = 1 # <<<<<<<<<<<<<< + * num_pairs = num_pairs + 1 + * else: + */ + (__pyx_v_dict[__pyx_v_null_word])->val = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":163 + * dict[null_word] = new_node(e_j) + * dict[null_word].val = 1 + * num_pairs = num_pairs + 1 # <<<<<<<<<<<<<< + * else: + * count = get_val(dict[null_word], e_j) + */ + __pyx_v_num_pairs = (__pyx_v_num_pairs + 1); + goto __pyx_L26; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":165 + * num_pairs = num_pairs + 1 + * else: + * count = get_val(dict[null_word], e_j) # <<<<<<<<<<<<<< + * if count[0] == 0: + * num_pairs = num_pairs + 1 + */ + __pyx_v_count = __pyx_f_3_sa_get_val((__pyx_v_dict[__pyx_v_null_word]), __pyx_v_e_j); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":166 + * else: + * count = get_val(dict[null_word], e_j) + * if count[0] == 0: # <<<<<<<<<<<<<< + * num_pairs = num_pairs + 1 + * count[0] = count[0] + 1 + */ + __pyx_t_10 = ((__pyx_v_count[0]) == 0); + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":167 + * count = get_val(dict[null_word], e_j) + * if count[0] == 0: + * num_pairs = num_pairs + 1 # <<<<<<<<<<<<<< + * count[0] = count[0] + 1 + * free(links) + */ + __pyx_v_num_pairs = (__pyx_v_num_pairs + 1); + goto __pyx_L27; + } + __pyx_L27:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":168 + * if count[0] == 0: + * num_pairs = num_pairs + 1 + * count[0] = count[0] + 1 # <<<<<<<<<<<<<< + * free(links) + * free(faligned) + */ + (__pyx_v_count[0]) = ((__pyx_v_count[0]) + 1); + } + __pyx_L26:; + goto __pyx_L25; + } + __pyx_L25:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":169 + * num_pairs = num_pairs + 1 + * count[0] = count[0] + 1 + * free(links) # <<<<<<<<<<<<<< + * free(faligned) + * free(ealigned) + */ + free(__pyx_v_links); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":170 + * count[0] = count[0] + 1 + * free(links) + * free(faligned) # <<<<<<<<<<<<<< + * free(ealigned) + * self.f_index = IntList(initial_len=V_F) + */ + free(__pyx_v_faligned); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":171 + * free(links) + * free(faligned) + * free(ealigned) # <<<<<<<<<<<<<< + * self.f_index = IntList(initial_len=V_F) + * self.e_index = IntList(initial_len=num_pairs) + */ + free(__pyx_v_ealigned); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":172 + * free(faligned) + * free(ealigned) + * self.f_index = IntList(initial_len=V_F) # <<<<<<<<<<<<<< + * self.e_index = IntList(initial_len=num_pairs) + * self.col1 = FloatList(initial_len=num_pairs) + */ + __pyx_t_12 = PyDict_New(); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_12)); + __pyx_t_13 = PyInt_FromLong(__pyx_v_V_F); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + if (PyDict_SetItem(__pyx_t_12, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_13) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_12)); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __Pyx_GIVEREF(__pyx_t_13); + __Pyx_GOTREF(__pyx_v_self->f_index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->f_index)); + __pyx_v_self->f_index = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_13); + __pyx_t_13 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":173 + * free(ealigned) + * self.f_index = IntList(initial_len=V_F) + * self.e_index = IntList(initial_len=num_pairs) # <<<<<<<<<<<<<< + * self.col1 = FloatList(initial_len=num_pairs) + * self.col2 = FloatList(initial_len=num_pairs) + */ + __pyx_t_13 = PyDict_New(); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_13)); + __pyx_t_12 = PyInt_FromLong(__pyx_v_num_pairs); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + if (PyDict_SetItem(__pyx_t_13, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_12) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_13)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_GOTREF(__pyx_v_self->e_index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->e_index)); + __pyx_v_self->e_index = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_12); + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":174 + * self.f_index = IntList(initial_len=V_F) + * self.e_index = IntList(initial_len=num_pairs) + * self.col1 = FloatList(initial_len=num_pairs) # <<<<<<<<<<<<<< + * self.col2 = FloatList(initial_len=num_pairs) + * + */ + __pyx_t_12 = PyDict_New(); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_12)); + __pyx_t_13 = PyInt_FromLong(__pyx_v_num_pairs); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + if (PyDict_SetItem(__pyx_t_12, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_13) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_FloatList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_12)); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __Pyx_GIVEREF(__pyx_t_13); + __Pyx_GOTREF(__pyx_v_self->col1); + __Pyx_DECREF(((PyObject *)__pyx_v_self->col1)); + __pyx_v_self->col1 = ((struct __pyx_obj_3_sa_FloatList *)__pyx_t_13); + __pyx_t_13 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":175 + * self.e_index = IntList(initial_len=num_pairs) + * self.col1 = FloatList(initial_len=num_pairs) + * self.col2 = FloatList(initial_len=num_pairs) # <<<<<<<<<<<<<< + * + * num_pairs = 0 + */ + __pyx_t_13 = PyDict_New(); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_13)); + __pyx_t_12 = PyInt_FromLong(__pyx_v_num_pairs); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + if (PyDict_SetItem(__pyx_t_13, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_12) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_FloatList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_13)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_GOTREF(__pyx_v_self->col2); + __Pyx_DECREF(((PyObject *)__pyx_v_self->col2)); + __pyx_v_self->col2 = ((struct __pyx_obj_3_sa_FloatList *)__pyx_t_12); + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":177 + * self.col2 = FloatList(initial_len=num_pairs) + * + * num_pairs = 0 # <<<<<<<<<<<<<< + * for i from 0 <= i < V_F: + * #self.f_index[i] = num_pairs + */ + __pyx_v_num_pairs = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":178 + * + * num_pairs = 0 + * for i from 0 <= i < V_F: # <<<<<<<<<<<<<< + * #self.f_index[i] = num_pairs + * self.f_index.set(i, num_pairs) + */ + __pyx_t_6 = __pyx_v_V_F; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_6; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":180 + * for i from 0 <= i < V_F: + * #self.f_index[i] = num_pairs + * self.f_index.set(i, num_pairs) # <<<<<<<<<<<<<< + * if dict[i] != NULL: + * self._add_node(dict[i], &num_pairs, float(fmargin[i]), emargin) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->f_index->__pyx_vtab)->set(__pyx_v_self->f_index, __pyx_v_i, __pyx_v_num_pairs); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":181 + * #self.f_index[i] = num_pairs + * self.f_index.set(i, num_pairs) + * if dict[i] != NULL: # <<<<<<<<<<<<<< + * self._add_node(dict[i], &num_pairs, float(fmargin[i]), emargin) + * del_node(dict[i]) + */ + __pyx_t_10 = ((__pyx_v_dict[__pyx_v_i]) != NULL); + if (__pyx_t_10) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":182 + * self.f_index.set(i, num_pairs) + * if dict[i] != NULL: + * self._add_node(dict[i], &num_pairs, float(fmargin[i]), emargin) # <<<<<<<<<<<<<< + * del_node(dict[i]) + * free(fmargin) + */ + __pyx_t_12 = ((struct __pyx_vtabstruct_3_sa_BiLex *)__pyx_v_self->__pyx_vtab)->_add_node(__pyx_v_self, (__pyx_v_dict[__pyx_v_i]), (&__pyx_v_num_pairs), ((double)(__pyx_v_fmargin[__pyx_v_i])), __pyx_v_emargin); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":183 + * if dict[i] != NULL: + * self._add_node(dict[i], &num_pairs, float(fmargin[i]), emargin) + * del_node(dict[i]) # <<<<<<<<<<<<<< + * free(fmargin) + * free(emargin) + */ + __pyx_t_12 = __pyx_f_3_sa_del_node((__pyx_v_dict[__pyx_v_i])); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L30; + } + __pyx_L30:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":184 + * self._add_node(dict[i], &num_pairs, float(fmargin[i]), emargin) + * del_node(dict[i]) + * free(fmargin) # <<<<<<<<<<<<<< + * free(emargin) + * free(dict) + */ + free(__pyx_v_fmargin); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":185 + * del_node(dict[i]) + * free(fmargin) + * free(emargin) # <<<<<<<<<<<<<< + * free(dict) + * return + */ + free(__pyx_v_emargin); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":186 + * free(fmargin) + * free(emargin) + * free(dict) # <<<<<<<<<<<<<< + * return + * + */ + free(__pyx_v_dict); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":187 + * free(emargin) + * free(dict) + * return # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + 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_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_AddTraceback("_sa.BiLex.compute_from_data", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_word); + __Pyx_XDECREF(__pyx_v_id); + __Pyx_XDECREF(__pyx_v_num_sents); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":190 + * + * + * cdef _add_node(self, _node* n, int* num_pairs, float fmargin, int* emargin): # <<<<<<<<<<<<<< + * cdef int loc + * if n.smaller != NULL: + */ + +static PyObject *__pyx_f_3_sa_5BiLex__add_node(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, struct __pyx_t_3_sa__node *__pyx_v_n, int *__pyx_v_num_pairs, float __pyx_v_fmargin, int *__pyx_v_emargin) { + int __pyx_v_loc; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_add_node", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":192 + * cdef _add_node(self, _node* n, int* num_pairs, float fmargin, int* emargin): + * cdef int loc + * if n.smaller != NULL: # <<<<<<<<<<<<<< + * self._add_node(n.smaller, num_pairs, fmargin, emargin) + * loc = num_pairs[0] + */ + __pyx_t_1 = (__pyx_v_n->smaller != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":193 + * cdef int loc + * if n.smaller != NULL: + * self._add_node(n.smaller, num_pairs, fmargin, emargin) # <<<<<<<<<<<<<< + * loc = num_pairs[0] + * self.e_index.set(loc, n.key) + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_BiLex *)__pyx_v_self->__pyx_vtab)->_add_node(__pyx_v_self, __pyx_v_n->smaller, __pyx_v_num_pairs, __pyx_v_fmargin, __pyx_v_emargin); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":194 + * if n.smaller != NULL: + * self._add_node(n.smaller, num_pairs, fmargin, emargin) + * loc = num_pairs[0] # <<<<<<<<<<<<<< + * self.e_index.set(loc, n.key) + * self.col1.set(loc, float(n.val)/fmargin) + */ + __pyx_v_loc = (__pyx_v_num_pairs[0]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":195 + * self._add_node(n.smaller, num_pairs, fmargin, emargin) + * loc = num_pairs[0] + * self.e_index.set(loc, n.key) # <<<<<<<<<<<<<< + * self.col1.set(loc, float(n.val)/fmargin) + * self.col2.set(loc, float(n.val)/float(emargin[n.key])) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->e_index->__pyx_vtab)->set(__pyx_v_self->e_index, __pyx_v_loc, __pyx_v_n->key); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":196 + * loc = num_pairs[0] + * self.e_index.set(loc, n.key) + * self.col1.set(loc, float(n.val)/fmargin) # <<<<<<<<<<<<<< + * self.col2.set(loc, float(n.val)/float(emargin[n.key])) + * num_pairs[0] = loc + 1 + */ + if (unlikely(__pyx_v_fmargin == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + ((struct __pyx_vtabstruct_3_sa_FloatList *)__pyx_v_self->col1->__pyx_vtab)->set(__pyx_v_self->col1, __pyx_v_loc, (((double)__pyx_v_n->val) / __pyx_v_fmargin)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":197 + * self.e_index.set(loc, n.key) + * self.col1.set(loc, float(n.val)/fmargin) + * self.col2.set(loc, float(n.val)/float(emargin[n.key])) # <<<<<<<<<<<<<< + * num_pairs[0] = loc + 1 + * if n.bigger != NULL: + */ + if (unlikely(((double)(__pyx_v_emargin[__pyx_v_n->key])) == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + ((struct __pyx_vtabstruct_3_sa_FloatList *)__pyx_v_self->col2->__pyx_vtab)->set(__pyx_v_self->col2, __pyx_v_loc, (((double)__pyx_v_n->val) / ((double)(__pyx_v_emargin[__pyx_v_n->key])))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":198 + * self.col1.set(loc, float(n.val)/fmargin) + * self.col2.set(loc, float(n.val)/float(emargin[n.key])) + * num_pairs[0] = loc + 1 # <<<<<<<<<<<<<< + * if n.bigger != NULL: + * self._add_node(n.bigger, num_pairs, fmargin, emargin) + */ + (__pyx_v_num_pairs[0]) = (__pyx_v_loc + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":199 + * self.col2.set(loc, float(n.val)/float(emargin[n.key])) + * num_pairs[0] = loc + 1 + * if n.bigger != NULL: # <<<<<<<<<<<<<< + * self._add_node(n.bigger, num_pairs, fmargin, emargin) + * + */ + __pyx_t_1 = (__pyx_v_n->bigger != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":200 + * num_pairs[0] = loc + 1 + * if n.bigger != NULL: + * self._add_node(n.bigger, num_pairs, fmargin, emargin) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_BiLex *)__pyx_v_self->__pyx_vtab)->_add_node(__pyx_v_self, __pyx_v_n->bigger, __pyx_v_num_pairs, __pyx_v_fmargin, __pyx_v_emargin); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L4; + } + __pyx_L4:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_sa.BiLex._add_node", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_5BiLex_3write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_5BiLex_3write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.BiLex.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_5BiLex_2write_binary(((struct __pyx_obj_3_sa_BiLex *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":203 + * + * + * def write_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "w") + */ + +static PyObject *__pyx_pf_3_sa_5BiLex_2write_binary(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + 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("write_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":205 + * def write_binary(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "w") # <<<<<<<<<<<<<< + * self.f_index.write_handle(f) + * self.e_index.write_handle(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":206 + * cdef FILE* f + * f = fopen(filename, "w") + * self.f_index.write_handle(f) # <<<<<<<<<<<<<< + * self.e_index.write_handle(f) + * self.col1.write_handle(f) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->f_index->__pyx_vtab)->write_handle(__pyx_v_self->f_index, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":207 + * f = fopen(filename, "w") + * self.f_index.write_handle(f) + * self.e_index.write_handle(f) # <<<<<<<<<<<<<< + * self.col1.write_handle(f) + * self.col2.write_handle(f) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->e_index->__pyx_vtab)->write_handle(__pyx_v_self->e_index, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":208 + * self.f_index.write_handle(f) + * self.e_index.write_handle(f) + * self.col1.write_handle(f) # <<<<<<<<<<<<<< + * self.col2.write_handle(f) + * self.write_wordlist(self.id2fword, f) + */ + ((struct __pyx_vtabstruct_3_sa_FloatList *)__pyx_v_self->col1->__pyx_vtab)->write_handle(__pyx_v_self->col1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":209 + * self.e_index.write_handle(f) + * self.col1.write_handle(f) + * self.col2.write_handle(f) # <<<<<<<<<<<<<< + * self.write_wordlist(self.id2fword, f) + * self.write_wordlist(self.id2eword, f) + */ + ((struct __pyx_vtabstruct_3_sa_FloatList *)__pyx_v_self->col2->__pyx_vtab)->write_handle(__pyx_v_self->col2, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":210 + * self.col1.write_handle(f) + * self.col2.write_handle(f) + * self.write_wordlist(self.id2fword, f) # <<<<<<<<<<<<<< + * self.write_wordlist(self.id2eword, f) + * fclose(f) + */ + __pyx_t_1 = __pyx_v_self->id2fword; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_BiLex *)__pyx_v_self->__pyx_vtab)->write_wordlist(__pyx_v_self, __pyx_t_1, __pyx_v_f); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":211 + * self.col2.write_handle(f) + * self.write_wordlist(self.id2fword, f) + * self.write_wordlist(self.id2eword, f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + __pyx_t_2 = __pyx_v_self->id2eword; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_1 = ((struct __pyx_vtabstruct_3_sa_BiLex *)__pyx_v_self->__pyx_vtab)->write_wordlist(__pyx_v_self, __pyx_t_2, __pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":212 + * self.write_wordlist(self.id2fword, f) + * self.write_wordlist(self.id2eword, f) + * fclose(f) # <<<<<<<<<<<<<< + * + * + */ + fclose(__pyx_v_f); + + __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("_sa.BiLex.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":215 + * + * + * cdef write_wordlist(self, wordlist, FILE* f): # <<<<<<<<<<<<<< + * cdef int word_len + * cdef int num_words + */ + +static PyObject *__pyx_f_3_sa_5BiLex_write_wordlist(CYTHON_UNUSED struct __pyx_obj_3_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_wordlist, FILE *__pyx_v_f) { + int __pyx_v_word_len; + int __pyx_v_num_words; + char *__pyx_v_c_word; + PyObject *__pyx_v_word = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + char *__pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_wordlist", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":220 + * cdef char* c_word + * + * num_words = len(wordlist) # <<<<<<<<<<<<<< + * fwrite(&(num_words), sizeof(int), 1, f) + * for word in wordlist: + */ + __pyx_t_1 = PyObject_Length(__pyx_v_wordlist); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_num_words = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":221 + * + * num_words = len(wordlist) + * fwrite(&(num_words), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * for word in wordlist: + * c_word = word + */ + fwrite((&__pyx_v_num_words), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":222 + * num_words = len(wordlist) + * fwrite(&(num_words), sizeof(int), 1, f) + * for word in wordlist: # <<<<<<<<<<<<<< + * c_word = word + * word_len = strlen(c_word) + 1 + */ + if (PyList_CheckExact(__pyx_v_wordlist) || PyTuple_CheckExact(__pyx_v_wordlist)) { + __pyx_t_2 = __pyx_v_wordlist; __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_1 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_wordlist); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_1); __Pyx_INCREF(__pyx_t_4); __pyx_t_1++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_1); __Pyx_INCREF(__pyx_t_4); __pyx_t_1++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_2); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_word); + __pyx_v_word = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":223 + * fwrite(&(num_words), sizeof(int), 1, f) + * for word in wordlist: + * c_word = word # <<<<<<<<<<<<<< + * word_len = strlen(c_word) + 1 + * fwrite(&(word_len), sizeof(int), 1, f) + */ + __pyx_t_5 = PyBytes_AsString(__pyx_v_word); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_c_word = __pyx_t_5; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":224 + * for word in wordlist: + * c_word = word + * word_len = strlen(c_word) + 1 # <<<<<<<<<<<<<< + * fwrite(&(word_len), sizeof(int), 1, f) + * fwrite(c_word, sizeof(char), word_len, f) + */ + __pyx_v_word_len = (strlen(__pyx_v_c_word) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":225 + * c_word = word + * word_len = strlen(c_word) + 1 + * fwrite(&(word_len), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fwrite(c_word, sizeof(char), word_len, f) + * + */ + fwrite((&__pyx_v_word_len), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":226 + * word_len = strlen(c_word) + 1 + * fwrite(&(word_len), sizeof(int), 1, f) + * fwrite(c_word, sizeof(char), word_len, f) # <<<<<<<<<<<<<< + * + * + */ + fwrite(__pyx_v_c_word, (sizeof(char)), __pyx_v_word_len, __pyx_v_f); + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_sa.BiLex.write_wordlist", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_word); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":229 + * + * + * cdef read_wordlist(self, word2id, id2word, FILE* f): # <<<<<<<<<<<<<< + * cdef int num_words + * cdef int word_len + */ + +static PyObject *__pyx_f_3_sa_5BiLex_read_wordlist(CYTHON_UNUSED struct __pyx_obj_3_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_word2id, PyObject *__pyx_v_id2word, FILE *__pyx_v_f) { + int __pyx_v_num_words; + int __pyx_v_word_len; + char *__pyx_v_c_word; + PyObject *__pyx_v_py_word = 0; + CYTHON_UNUSED long __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_wordlist", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":235 + * cdef bytes py_word + * + * fread(&(num_words), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * for i from 0 <= i < num_words: + * fread(&(word_len), sizeof(int), 1, f) + */ + fread((&__pyx_v_num_words), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":236 + * + * fread(&(num_words), sizeof(int), 1, f) + * for i from 0 <= i < num_words: # <<<<<<<<<<<<<< + * fread(&(word_len), sizeof(int), 1, f) + * c_word = malloc (word_len * sizeof(char)) + */ + __pyx_t_1 = __pyx_v_num_words; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":237 + * fread(&(num_words), sizeof(int), 1, f) + * for i from 0 <= i < num_words: + * fread(&(word_len), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * c_word = malloc (word_len * sizeof(char)) + * fread(c_word, sizeof(char), word_len, f) + */ + fread((&__pyx_v_word_len), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":238 + * for i from 0 <= i < num_words: + * fread(&(word_len), sizeof(int), 1, f) + * c_word = malloc (word_len * sizeof(char)) # <<<<<<<<<<<<<< + * fread(c_word, sizeof(char), word_len, f) + * py_word = c_word + */ + __pyx_v_c_word = ((char *)malloc((__pyx_v_word_len * (sizeof(char))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":239 + * fread(&(word_len), sizeof(int), 1, f) + * c_word = malloc (word_len * sizeof(char)) + * fread(c_word, sizeof(char), word_len, f) # <<<<<<<<<<<<<< + * py_word = c_word + * free(c_word) + */ + fread(__pyx_v_c_word, (sizeof(char)), __pyx_v_word_len, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":240 + * c_word = malloc (word_len * sizeof(char)) + * fread(c_word, sizeof(char), word_len, f) + * py_word = c_word # <<<<<<<<<<<<<< + * free(c_word) + * word2id[py_word] = len(id2word) + */ + __pyx_t_2 = PyBytes_FromString(__pyx_v_c_word); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 240; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_XDECREF(((PyObject *)__pyx_v_py_word)); + __pyx_v_py_word = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":241 + * fread(c_word, sizeof(char), word_len, f) + * py_word = c_word + * free(c_word) # <<<<<<<<<<<<<< + * word2id[py_word] = len(id2word) + * id2word.append(py_word) + */ + free(__pyx_v_c_word); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":242 + * py_word = c_word + * free(c_word) + * word2id[py_word] = len(id2word) # <<<<<<<<<<<<<< + * id2word.append(py_word) + * + */ + __pyx_t_3 = PyObject_Length(__pyx_v_id2word); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyObject_SetItem(__pyx_v_word2id, ((PyObject *)__pyx_v_py_word), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":243 + * free(c_word) + * word2id[py_word] = len(id2word) + * id2word.append(py_word) # <<<<<<<<<<<<<< + * + * def read_binary(self, char* filename): + */ + __pyx_t_2 = __Pyx_PyObject_Append(__pyx_v_id2word, ((PyObject *)__pyx_v_py_word)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_sa.BiLex.read_wordlist", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_py_word); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_5BiLex_5read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_5BiLex_5read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.BiLex.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_5BiLex_4read_binary(((struct __pyx_obj_3_sa_BiLex *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":245 + * id2word.append(py_word) + * + * def read_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "r") + */ + +static PyObject *__pyx_pf_3_sa_5BiLex_4read_binary(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":247 + * def read_binary(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "r") # <<<<<<<<<<<<<< + * self.f_index.read_handle(f) + * self.e_index.read_handle(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":248 + * cdef FILE* f + * f = fopen(filename, "r") + * self.f_index.read_handle(f) # <<<<<<<<<<<<<< + * self.e_index.read_handle(f) + * self.col1.read_handle(f) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->f_index->__pyx_vtab)->read_handle(__pyx_v_self->f_index, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":249 + * f = fopen(filename, "r") + * self.f_index.read_handle(f) + * self.e_index.read_handle(f) # <<<<<<<<<<<<<< + * self.col1.read_handle(f) + * self.col2.read_handle(f) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->e_index->__pyx_vtab)->read_handle(__pyx_v_self->e_index, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":250 + * self.f_index.read_handle(f) + * self.e_index.read_handle(f) + * self.col1.read_handle(f) # <<<<<<<<<<<<<< + * self.col2.read_handle(f) + * self.read_wordlist(self.fword2id, self.id2fword, f) + */ + ((struct __pyx_vtabstruct_3_sa_FloatList *)__pyx_v_self->col1->__pyx_vtab)->read_handle(__pyx_v_self->col1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":251 + * self.e_index.read_handle(f) + * self.col1.read_handle(f) + * self.col2.read_handle(f) # <<<<<<<<<<<<<< + * self.read_wordlist(self.fword2id, self.id2fword, f) + * self.read_wordlist(self.eword2id, self.id2eword, f) + */ + ((struct __pyx_vtabstruct_3_sa_FloatList *)__pyx_v_self->col2->__pyx_vtab)->read_handle(__pyx_v_self->col2, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":252 + * self.col1.read_handle(f) + * self.col2.read_handle(f) + * self.read_wordlist(self.fword2id, self.id2fword, f) # <<<<<<<<<<<<<< + * self.read_wordlist(self.eword2id, self.id2eword, f) + * fclose(f) + */ + __pyx_t_1 = __pyx_v_self->fword2id; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __pyx_v_self->id2fword; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_3 = ((struct __pyx_vtabstruct_3_sa_BiLex *)__pyx_v_self->__pyx_vtab)->read_wordlist(__pyx_v_self, __pyx_t_1, __pyx_t_2, __pyx_v_f); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":253 + * self.col2.read_handle(f) + * self.read_wordlist(self.fword2id, self.id2fword, f) + * self.read_wordlist(self.eword2id, self.id2eword, f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + __pyx_t_3 = __pyx_v_self->eword2id; + __Pyx_INCREF(__pyx_t_3); + __pyx_t_2 = __pyx_v_self->id2eword; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_1 = ((struct __pyx_vtabstruct_3_sa_BiLex *)__pyx_v_self->__pyx_vtab)->read_wordlist(__pyx_v_self, __pyx_t_3, __pyx_t_2, __pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":254 + * self.read_wordlist(self.fword2id, self.id2fword, f) + * self.read_wordlist(self.eword2id, self.id2eword, f) + * fclose(f) # <<<<<<<<<<<<<< + * + * + */ + fclose(__pyx_v_f); + + __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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.BiLex.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_5BiLex_7get_e_id(PyObject *__pyx_v_self, PyObject *__pyx_v_eword); /*proto*/ +static PyObject *__pyx_pw_3_sa_5BiLex_7get_e_id(PyObject *__pyx_v_self, PyObject *__pyx_v_eword) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_e_id (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_5BiLex_6get_e_id(((struct __pyx_obj_3_sa_BiLex *)__pyx_v_self), ((PyObject *)__pyx_v_eword)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":257 + * + * + * def get_e_id(self, eword): # <<<<<<<<<<<<<< + * if eword not in self.eword2id: + * e_id = len(self.id2eword) + */ + +static PyObject *__pyx_pf_3_sa_5BiLex_6get_e_id(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_eword) { + PyObject *__pyx_v_e_id = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_e_id", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":258 + * + * def get_e_id(self, eword): + * if eword not in self.eword2id: # <<<<<<<<<<<<<< + * e_id = len(self.id2eword) + * self.id2eword.append(eword) + */ + __pyx_t_1 = (__Pyx_NegateNonNeg(PySequence_Contains(__pyx_v_self->eword2id, __pyx_v_eword))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":259 + * def get_e_id(self, eword): + * if eword not in self.eword2id: + * e_id = len(self.id2eword) # <<<<<<<<<<<<<< + * self.id2eword.append(eword) + * self.eword2id[eword] = e_id + */ + __pyx_t_2 = __pyx_v_self->id2eword; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_e_id = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":260 + * if eword not in self.eword2id: + * e_id = len(self.id2eword) + * self.id2eword.append(eword) # <<<<<<<<<<<<<< + * self.eword2id[eword] = e_id + * return self.eword2id[eword] + */ + __pyx_t_2 = __Pyx_PyObject_Append(__pyx_v_self->id2eword, __pyx_v_eword); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":261 + * e_id = len(self.id2eword) + * self.id2eword.append(eword) + * self.eword2id[eword] = e_id # <<<<<<<<<<<<<< + * return self.eword2id[eword] + * + */ + if (PyObject_SetItem(__pyx_v_self->eword2id, __pyx_v_eword, __pyx_v_e_id) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":262 + * self.id2eword.append(eword) + * self.eword2id[eword] = e_id + * return self.eword2id[eword] # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyObject_GetItem(__pyx_v_self->eword2id, __pyx_v_eword); if (!__pyx_t_2) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_sa.BiLex.get_e_id", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_e_id); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_5BiLex_9get_f_id(PyObject *__pyx_v_self, PyObject *__pyx_v_fword); /*proto*/ +static PyObject *__pyx_pw_3_sa_5BiLex_9get_f_id(PyObject *__pyx_v_self, PyObject *__pyx_v_fword) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_f_id (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_5BiLex_8get_f_id(((struct __pyx_obj_3_sa_BiLex *)__pyx_v_self), ((PyObject *)__pyx_v_fword)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":265 + * + * + * def get_f_id(self, fword): # <<<<<<<<<<<<<< + * if fword not in self.fword2id: + * f_id = len(self.id2fword) + */ + +static PyObject *__pyx_pf_3_sa_5BiLex_8get_f_id(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_fword) { + PyObject *__pyx_v_f_id = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_f_id", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":266 + * + * def get_f_id(self, fword): + * if fword not in self.fword2id: # <<<<<<<<<<<<<< + * f_id = len(self.id2fword) + * self.id2fword.append(fword) + */ + __pyx_t_1 = (__Pyx_NegateNonNeg(PySequence_Contains(__pyx_v_self->fword2id, __pyx_v_fword))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 266; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":267 + * def get_f_id(self, fword): + * if fword not in self.fword2id: + * f_id = len(self.id2fword) # <<<<<<<<<<<<<< + * self.id2fword.append(fword) + * self.fword2id[fword] = f_id + */ + __pyx_t_2 = __pyx_v_self->id2fword; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_f_id = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":268 + * if fword not in self.fword2id: + * f_id = len(self.id2fword) + * self.id2fword.append(fword) # <<<<<<<<<<<<<< + * self.fword2id[fword] = f_id + * return self.fword2id[fword] + */ + __pyx_t_2 = __Pyx_PyObject_Append(__pyx_v_self->id2fword, __pyx_v_fword); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":269 + * f_id = len(self.id2fword) + * self.id2fword.append(fword) + * self.fword2id[fword] = f_id # <<<<<<<<<<<<<< + * return self.fword2id[fword] + * + */ + if (PyObject_SetItem(__pyx_v_self->fword2id, __pyx_v_fword, __pyx_v_f_id) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":270 + * self.id2fword.append(fword) + * self.fword2id[fword] = f_id + * return self.fword2id[fword] # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyObject_GetItem(__pyx_v_self->fword2id, __pyx_v_fword); if (!__pyx_t_2) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 270; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_sa.BiLex.get_f_id", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f_id); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_5BiLex_11read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_5BiLex_11read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_text (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.BiLex.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_5BiLex_10read_text(((struct __pyx_obj_3_sa_BiLex *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":273 + * + * + * def read_text(self, char* filename): # <<<<<<<<<<<<<< + * cdef i, j, w, e_id, f_id, n_f, n_e, N + * cdef IntList fcount + */ + +static PyObject *__pyx_pf_3_sa_5BiLex_10read_text(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_v_i = 0; + PyObject *__pyx_v_j = 0; + PyObject *__pyx_v_e_id = 0; + PyObject *__pyx_v_f_id = 0; + PyObject *__pyx_v_n_f = 0; + PyObject *__pyx_v_N = 0; + struct __pyx_obj_3_sa_IntList *__pyx_v_fcount = 0; + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_v_line = NULL; + PyObject *__pyx_v_fword = NULL; + PyObject *__pyx_v_eword = NULL; + PyObject *__pyx_v_score1 = NULL; + PyObject *__pyx_v_score2 = NULL; + PyObject *__pyx_v_index = NULL; + PyObject *__pyx_v_b = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *(*__pyx_t_14)(PyObject *); + Py_ssize_t __pyx_t_15; + int __pyx_t_16; + Py_ssize_t __pyx_t_17; + long __pyx_t_18; + long __pyx_t_19; + int __pyx_t_20; + double __pyx_t_21; + PyObject *__pyx_t_22 = NULL; + int __pyx_t_23; + int __pyx_t_24; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_text", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":277 + * cdef IntList fcount + * + * fcount = IntList() # <<<<<<<<<<<<<< + * with gzip_or_text(filename) as f: + * # first loop merely establishes size of array objects + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_fcount = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":278 + * + * fcount = IntList() + * with gzip_or_text(filename) as f: # <<<<<<<<<<<<<< + * # first loop merely establishes size of array objects + * for line in f: + */ + /*with:*/ { + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__gzip_or_text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __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[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_1); + __pyx_v_f = __pyx_t_1; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":280 + * with gzip_or_text(filename) as f: + * # first loop merely establishes size of array objects + * for line in f: # <<<<<<<<<<<<<< + * (fword, eword, score1, score2) = line.split() + * f_id = self.get_f_id(fword) + */ + if (PyList_CheckExact(__pyx_v_f) || PyTuple_CheckExact(__pyx_v_f)) { + __pyx_t_1 = __pyx_v_f; __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else { + __pyx_t_2 = __pyx_t_9(__pyx_t_1); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF(__pyx_v_line); + __pyx_v_line = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":281 + * # first loop merely establishes size of array objects + * for line in f: + * (fword, eword, score1, score2) = line.split() # <<<<<<<<<<<<<< + * f_id = self.get_f_id(fword) + * e_id = self.get_e_id(eword) + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { + PyObject* sequence = __pyx_t_3; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 4)) { + if (size > 4) __Pyx_RaiseTooManyValuesError(4); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_11 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_12 = PyTuple_GET_ITEM(sequence, 3); + } else { + __pyx_t_2 = PyList_GET_ITEM(sequence, 0); + __pyx_t_10 = PyList_GET_ITEM(sequence, 1); + __pyx_t_11 = PyList_GET_ITEM(sequence, 2); + __pyx_t_12 = PyList_GET_ITEM(sequence, 3); + } + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(__pyx_t_12); + #else + Py_ssize_t i; + PyObject** temps[4] = {&__pyx_t_2,&__pyx_t_10,&__pyx_t_11,&__pyx_t_12}; + for (i=0; i < 4; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + *(temps[i]) = item; + } + #endif + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + { + Py_ssize_t index = -1; + PyObject** temps[4] = {&__pyx_t_2,&__pyx_t_10,&__pyx_t_11,&__pyx_t_12}; + __pyx_t_13 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_14 = Py_TYPE(__pyx_t_13)->tp_iternext; + for (index=0; index < 4; index++) { + PyObject* item = __pyx_t_14(__pyx_t_13); if (unlikely(!item)) goto __pyx_L18_unpacking_failed; + __Pyx_GOTREF(item); + *(temps[index]) = item; + } + if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_13), 4) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_14 = NULL; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + goto __pyx_L19_unpacking_done; + __pyx_L18_unpacking_failed:; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_14 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_L19_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_fword); + __pyx_v_fword = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_v_eword); + __pyx_v_eword = __pyx_t_10; + __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_v_score1); + __pyx_v_score1 = __pyx_t_11; + __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_v_score2); + __pyx_v_score2 = __pyx_t_12; + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":282 + * for line in f: + * (fword, eword, score1, score2) = line.split() + * f_id = self.get_f_id(fword) # <<<<<<<<<<<<<< + * e_id = self.get_e_id(eword) + * while f_id >= len(fcount): + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_f_id); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_INCREF(__pyx_v_fword); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_v_fword); + __Pyx_GIVEREF(__pyx_v_fword); + __pyx_t_11 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_v_f_id); + __pyx_v_f_id = __pyx_t_11; + __pyx_t_11 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":283 + * (fword, eword, score1, score2) = line.split() + * f_id = self.get_f_id(fword) + * e_id = self.get_e_id(eword) # <<<<<<<<<<<<<< + * while f_id >= len(fcount): + * fcount.append(0) + */ + __pyx_t_11 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_e_id); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_INCREF(__pyx_v_eword); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_v_eword); + __Pyx_GIVEREF(__pyx_v_eword); + __pyx_t_3 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_v_e_id); + __pyx_v_e_id = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":284 + * f_id = self.get_f_id(fword) + * e_id = self.get_e_id(eword) + * while f_id >= len(fcount): # <<<<<<<<<<<<<< + * fcount.append(0) + * fcount.arr[f_id] = fcount.arr[f_id] + 1 + */ + while (1) { + __pyx_t_15 = PyObject_Length(((PyObject *)__pyx_v_fcount)); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_15); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_12 = PyObject_RichCompare(__pyx_v_f_id, __pyx_t_3, Py_GE); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 284; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (!__pyx_t_16) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":285 + * e_id = self.get_e_id(eword) + * while f_id >= len(fcount): + * fcount.append(0) # <<<<<<<<<<<<<< + * fcount.arr[f_id] = fcount.arr[f_id] + 1 + * + */ + __pyx_t_12 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_fcount), __pyx_int_0); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":286 + * while f_id >= len(fcount): + * fcount.append(0) + * fcount.arr[f_id] = fcount.arr[f_id] + 1 # <<<<<<<<<<<<<< + * + * # Allocate space for dictionary in arrays + */ + __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + (__pyx_v_fcount->arr[__pyx_t_17]) = ((__pyx_v_fcount->arr[__pyx_t_15]) + 1); + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":289 + * + * # Allocate space for dictionary in arrays + * N = 0 # <<<<<<<<<<<<<< + * n_f = len(fcount) + * self.f_index = IntList(initial_len=n_f+1) + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_N = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":290 + * # Allocate space for dictionary in arrays + * N = 0 + * n_f = len(fcount) # <<<<<<<<<<<<<< + * self.f_index = IntList(initial_len=n_f+1) + * for i from 0 <= i < n_f: + */ + __pyx_t_8 = PyObject_Length(((PyObject *)__pyx_v_fcount)); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_n_f = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":291 + * N = 0 + * n_f = len(fcount) + * self.f_index = IntList(initial_len=n_f+1) # <<<<<<<<<<<<<< + * for i from 0 <= i < n_f: + * self.f_index.arr[i] = N + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_12 = PyNumber_Add(__pyx_v_n_f, __pyx_int_1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_12) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_GOTREF(__pyx_v_self->f_index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->f_index)); + __pyx_v_self->f_index = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_12); + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":292 + * n_f = len(fcount) + * self.f_index = IntList(initial_len=n_f+1) + * for i from 0 <= i < n_f: # <<<<<<<<<<<<<< + * self.f_index.arr[i] = N + * N = N + fcount.arr[i] + */ + __pyx_t_18 = __Pyx_PyInt_AsLong(__pyx_v_n_f); if (unlikely((__pyx_t_18 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_18; __pyx_t_19++) { + __pyx_t_12 = PyInt_FromLong(__pyx_t_19); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_12; + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":293 + * self.f_index = IntList(initial_len=n_f+1) + * for i from 0 <= i < n_f: + * self.f_index.arr[i] = N # <<<<<<<<<<<<<< + * N = N + fcount.arr[i] + * fcount.arr[i] = 0 + */ + __pyx_t_20 = __Pyx_PyInt_AsInt(__pyx_v_N); if (unlikely((__pyx_t_20 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + (__pyx_v_self->f_index->arr[__pyx_t_8]) = __pyx_t_20; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":294 + * for i from 0 <= i < n_f: + * self.f_index.arr[i] = N + * N = N + fcount.arr[i] # <<<<<<<<<<<<<< + * fcount.arr[i] = 0 + * self.f_index.arr[n_f] = N + */ + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_12 = PyInt_FromLong((__pyx_v_fcount->arr[__pyx_t_8])); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_1 = PyNumber_Add(__pyx_v_N, __pyx_t_12); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_v_N); + __pyx_v_N = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":295 + * self.f_index.arr[i] = N + * N = N + fcount.arr[i] + * fcount.arr[i] = 0 # <<<<<<<<<<<<<< + * self.f_index.arr[n_f] = N + * self.e_index = IntList(initial_len=N) + */ + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + (__pyx_v_fcount->arr[__pyx_t_8]) = 0; + __pyx_t_19 = __Pyx_PyInt_AsLong(__pyx_v_i); if (unlikely((__pyx_t_19 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":292 + * n_f = len(fcount) + * self.f_index = IntList(initial_len=n_f+1) + * for i from 0 <= i < n_f: # <<<<<<<<<<<<<< + * self.f_index.arr[i] = N + * N = N + fcount.arr[i] + */ + __pyx_t_1 = PyInt_FromLong(__pyx_t_19); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":296 + * N = N + fcount.arr[i] + * fcount.arr[i] = 0 + * self.f_index.arr[n_f] = N # <<<<<<<<<<<<<< + * self.e_index = IntList(initial_len=N) + * self.col1 = FloatList(initial_len=N) + */ + __pyx_t_20 = __Pyx_PyInt_AsInt(__pyx_v_N); if (unlikely((__pyx_t_20 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_n_f); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + (__pyx_v_self->f_index->arr[__pyx_t_8]) = __pyx_t_20; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":297 + * fcount.arr[i] = 0 + * self.f_index.arr[n_f] = N + * self.e_index = IntList(initial_len=N) # <<<<<<<<<<<<<< + * self.col1 = FloatList(initial_len=N) + * self.col2 = FloatList(initial_len=N) + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_v_N) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_12 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_GOTREF(__pyx_v_self->e_index); + __Pyx_DECREF(((PyObject *)__pyx_v_self->e_index)); + __pyx_v_self->e_index = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_12); + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":298 + * self.f_index.arr[n_f] = N + * self.e_index = IntList(initial_len=N) + * self.col1 = FloatList(initial_len=N) # <<<<<<<<<<<<<< + * self.col2 = FloatList(initial_len=N) + * + */ + __pyx_t_12 = PyDict_New(); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_12)); + if (PyDict_SetItem(__pyx_t_12, ((PyObject *)__pyx_n_s__initial_len), __pyx_v_N) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_FloatList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_12)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->col1); + __Pyx_DECREF(((PyObject *)__pyx_v_self->col1)); + __pyx_v_self->col1 = ((struct __pyx_obj_3_sa_FloatList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":299 + * self.e_index = IntList(initial_len=N) + * self.col1 = FloatList(initial_len=N) + * self.col2 = FloatList(initial_len=N) # <<<<<<<<<<<<<< + * + * # Re-read file, placing words into buckets + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_v_N) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_12 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_FloatList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_GOTREF(__pyx_v_self->col2); + __Pyx_DECREF(((PyObject *)__pyx_v_self->col2)); + __pyx_v_self->col2 = ((struct __pyx_obj_3_sa_FloatList *)__pyx_t_12); + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":302 + * + * # Re-read file, placing words into buckets + * f.seek(0) # <<<<<<<<<<<<<< + * for line in f: + * (fword, eword, score1, score2) = line.split() + */ + __pyx_t_12 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__seek); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_1 = PyObject_Call(__pyx_t_12, ((PyObject *)__pyx_k_tuple_40), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":303 + * # Re-read file, placing words into buckets + * f.seek(0) + * for line in f: # <<<<<<<<<<<<<< + * (fword, eword, score1, score2) = line.split() + * f_id = self.get_f_id(fword) + */ + if (PyList_CheckExact(__pyx_v_f) || PyTuple_CheckExact(__pyx_v_f)) { + __pyx_t_1 = __pyx_v_f; __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_12 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_12); __pyx_t_8++; + #else + __pyx_t_12 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_12 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_12); __pyx_t_8++; + #else + __pyx_t_12 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else { + __pyx_t_12 = __pyx_t_9(__pyx_t_1); + if (unlikely(!__pyx_t_12)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_12); + } + __Pyx_XDECREF(__pyx_v_line); + __pyx_v_line = __pyx_t_12; + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":304 + * f.seek(0) + * for line in f: + * (fword, eword, score1, score2) = line.split() # <<<<<<<<<<<<<< + * f_id = self.get_f_id(fword) + * e_id = self.get_e_id(eword) + */ + __pyx_t_12 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_3 = PyObject_Call(__pyx_t_12, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { + PyObject* sequence = __pyx_t_3; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 4)) { + if (size > 4) __Pyx_RaiseTooManyValuesError(4); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_12 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 3); + } else { + __pyx_t_12 = PyList_GET_ITEM(sequence, 0); + __pyx_t_11 = PyList_GET_ITEM(sequence, 1); + __pyx_t_10 = PyList_GET_ITEM(sequence, 2); + __pyx_t_2 = PyList_GET_ITEM(sequence, 3); + } + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_2); + #else + Py_ssize_t i; + PyObject** temps[4] = {&__pyx_t_12,&__pyx_t_11,&__pyx_t_10,&__pyx_t_2}; + for (i=0; i < 4; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + *(temps[i]) = item; + } + #endif + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + { + Py_ssize_t index = -1; + PyObject** temps[4] = {&__pyx_t_12,&__pyx_t_11,&__pyx_t_10,&__pyx_t_2}; + __pyx_t_13 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_14 = Py_TYPE(__pyx_t_13)->tp_iternext; + for (index=0; index < 4; index++) { + PyObject* item = __pyx_t_14(__pyx_t_13); if (unlikely(!item)) goto __pyx_L26_unpacking_failed; + __Pyx_GOTREF(item); + *(temps[index]) = item; + } + if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_13), 4) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_14 = NULL; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + goto __pyx_L27_unpacking_done; + __pyx_L26_unpacking_failed:; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_14 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_L27_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_fword); + __pyx_v_fword = __pyx_t_12; + __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_v_eword); + __pyx_v_eword = __pyx_t_11; + __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_v_score1); + __pyx_v_score1 = __pyx_t_10; + __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_v_score2); + __pyx_v_score2 = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":305 + * for line in f: + * (fword, eword, score1, score2) = line.split() + * f_id = self.get_f_id(fword) # <<<<<<<<<<<<<< + * e_id = self.get_e_id(eword) + * index = self.f_index.arr[f_id] + fcount.arr[f_id] + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_f_id); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_fword); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_fword); + __Pyx_GIVEREF(__pyx_v_fword); + __pyx_t_10 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_v_f_id); + __pyx_v_f_id = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":306 + * (fword, eword, score1, score2) = line.split() + * f_id = self.get_f_id(fword) + * e_id = self.get_e_id(eword) # <<<<<<<<<<<<<< + * index = self.f_index.arr[f_id] + fcount.arr[f_id] + * fcount.arr[f_id] = fcount.arr[f_id] + 1 + */ + __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_e_id); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_eword); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_eword); + __Pyx_GIVEREF(__pyx_v_eword); + __pyx_t_3 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_v_e_id); + __pyx_v_e_id = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":307 + * f_id = self.get_f_id(fword) + * e_id = self.get_e_id(eword) + * index = self.f_index.arr[f_id] + fcount.arr[f_id] # <<<<<<<<<<<<<< + * fcount.arr[f_id] = fcount.arr[f_id] + 1 + * self.e_index.arr[index] = int(e_id) + */ + __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_3 = PyInt_FromLong(((__pyx_v_self->f_index->arr[__pyx_t_15]) + (__pyx_v_fcount->arr[__pyx_t_17]))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_v_index); + __pyx_v_index = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":308 + * e_id = self.get_e_id(eword) + * index = self.f_index.arr[f_id] + fcount.arr[f_id] + * fcount.arr[f_id] = fcount.arr[f_id] + 1 # <<<<<<<<<<<<<< + * self.e_index.arr[index] = int(e_id) + * self.col1[index] = float(score1) + */ + __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + (__pyx_v_fcount->arr[__pyx_t_15]) = ((__pyx_v_fcount->arr[__pyx_t_17]) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":309 + * index = self.f_index.arr[f_id] + fcount.arr[f_id] + * fcount.arr[f_id] = fcount.arr[f_id] + 1 + * self.e_index.arr[index] = int(e_id) # <<<<<<<<<<<<<< + * self.col1[index] = float(score1) + * self.col2[index] = float(score2) + */ + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_e_id); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_e_id); + __Pyx_GIVEREF(__pyx_v_e_id); + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_20 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_20 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_17 = __Pyx_PyIndex_AsSsize_t(__pyx_v_index); if (unlikely((__pyx_t_17 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + (__pyx_v_self->e_index->arr[__pyx_t_17]) = __pyx_t_20; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":310 + * fcount.arr[f_id] = fcount.arr[f_id] + 1 + * self.e_index.arr[index] = int(e_id) + * self.col1[index] = float(score1) # <<<<<<<<<<<<<< + * self.col2[index] = float(score2) + * + */ + __pyx_t_21 = __Pyx_PyObject_AsDouble(__pyx_v_score1); if (unlikely(__pyx_t_21 == ((double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyFloat_FromDouble(__pyx_t_21); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyObject_SetItem(((PyObject *)__pyx_v_self->col1), __pyx_v_index, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":311 + * self.e_index.arr[index] = int(e_id) + * self.col1[index] = float(score1) + * self.col2[index] = float(score2) # <<<<<<<<<<<<<< + * + * # Sort buckets by eword + */ + __pyx_t_21 = __Pyx_PyObject_AsDouble(__pyx_v_score2); if (unlikely(__pyx_t_21 == ((double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyFloat_FromDouble(__pyx_t_21); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyObject_SetItem(((PyObject *)__pyx_v_self->col2), __pyx_v_index, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":278 + * + * fcount = IntList() + * with gzip_or_text(filename) as f: # <<<<<<<<<<<<<< + * # first loop merely establishes size of array objects + * for line in f: + */ + /*except:*/ { + __Pyx_AddTraceback("_sa.BiLex.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_22 = PyObject_Call(__pyx_t_4, __pyx_t_10, NULL); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_22)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_22); + __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_22); + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_23 = (!__pyx_t_16); + if (__pyx_t_23) { + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_ErrRestore(__pyx_t_1, __pyx_t_2, __pyx_t_3); + __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_3 = 0; + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L30; + } + __pyx_L30:; + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_4) { + __pyx_t_7 = PyObject_Call(__pyx_t_4, __pyx_k_tuple_41, NULL); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_23 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_23 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L31; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L1_error; + __pyx_L31:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":314 + * + * # Sort buckets by eword + * for b from 0 <= b < n_f: # <<<<<<<<<<<<<< + * i = self.f_index.arr[b] + * j = self.f_index.arr[b+1] + */ + if (unlikely(!__pyx_v_n_f)) { __Pyx_RaiseUnboundLocalError("n_f"); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } + __pyx_t_19 = __Pyx_PyInt_AsLong(__pyx_v_n_f); if (unlikely((__pyx_t_19 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_19; __pyx_t_18++) { + __pyx_t_3 = PyInt_FromLong(__pyx_t_18); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_v_b); + __pyx_v_b = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":315 + * # Sort buckets by eword + * for b from 0 <= b < n_f: + * i = self.f_index.arr[b] # <<<<<<<<<<<<<< + * j = self.f_index.arr[b+1] + * self.qsort(i,j, "") + */ + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_b); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromLong((__pyx_v_self->f_index->arr[__pyx_t_8])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":316 + * for b from 0 <= b < n_f: + * i = self.f_index.arr[b] + * j = self.f_index.arr[b+1] # <<<<<<<<<<<<<< + * self.qsort(i,j, "") + * + */ + __pyx_t_3 = PyNumber_Add(__pyx_v_b, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_3); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromLong((__pyx_v_self->f_index->arr[__pyx_t_8])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_v_j); + __pyx_v_j = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":317 + * i = self.f_index.arr[b] + * j = self.f_index.arr[b+1] + * self.qsort(i,j, "") # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_20 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_20 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_24 = __Pyx_PyInt_AsInt(__pyx_v_j); if (unlikely((__pyx_t_24 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = ((PyObject *)__pyx_kp_s_42); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_BiLex *)__pyx_v_self->__pyx_vtab)->qsort(__pyx_v_self, __pyx_t_20, __pyx_t_24, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_18 = __Pyx_PyInt_AsLong(__pyx_v_b); if (unlikely((__pyx_t_18 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":314 + * + * # Sort buckets by eword + * for b from 0 <= b < n_f: # <<<<<<<<<<<<<< + * i = self.f_index.arr[b] + * j = self.f_index.arr[b+1] + */ + __pyx_t_2 = PyInt_FromLong(__pyx_t_18); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_v_b); + __pyx_v_b = __pyx_t_2; + __pyx_t_2 = 0; + + __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_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_AddTraceback("_sa.BiLex.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_j); + __Pyx_XDECREF(__pyx_v_e_id); + __Pyx_XDECREF(__pyx_v_f_id); + __Pyx_XDECREF(__pyx_v_n_f); + __Pyx_XDECREF(__pyx_v_N); + __Pyx_XDECREF((PyObject *)__pyx_v_fcount); + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_line); + __Pyx_XDECREF(__pyx_v_fword); + __Pyx_XDECREF(__pyx_v_eword); + __Pyx_XDECREF(__pyx_v_score1); + __Pyx_XDECREF(__pyx_v_score2); + __Pyx_XDECREF(__pyx_v_index); + __Pyx_XDECREF(__pyx_v_b); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":320 + * + * + * cdef swap(self, int i, int j): # <<<<<<<<<<<<<< + * cdef int itmp + * cdef float ftmp + */ + +static PyObject *__pyx_f_3_sa_5BiLex_swap(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, int __pyx_v_i, int __pyx_v_j) { + int __pyx_v_itmp; + float __pyx_v_ftmp; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("swap", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":324 + * cdef float ftmp + * + * if i == j: # <<<<<<<<<<<<<< + * return + * + */ + __pyx_t_1 = (__pyx_v_i == __pyx_v_j); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":325 + * + * if i == j: + * return # <<<<<<<<<<<<<< + * + * itmp = self.e_index.arr[i] + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":327 + * return + * + * itmp = self.e_index.arr[i] # <<<<<<<<<<<<<< + * self.e_index.arr[i] = self.e_index.arr[j] + * self.e_index.arr[j] = itmp + */ + __pyx_v_itmp = (__pyx_v_self->e_index->arr[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":328 + * + * itmp = self.e_index.arr[i] + * self.e_index.arr[i] = self.e_index.arr[j] # <<<<<<<<<<<<<< + * self.e_index.arr[j] = itmp + * + */ + (__pyx_v_self->e_index->arr[__pyx_v_i]) = (__pyx_v_self->e_index->arr[__pyx_v_j]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":329 + * itmp = self.e_index.arr[i] + * self.e_index.arr[i] = self.e_index.arr[j] + * self.e_index.arr[j] = itmp # <<<<<<<<<<<<<< + * + * ftmp = self.col1.arr[i] + */ + (__pyx_v_self->e_index->arr[__pyx_v_j]) = __pyx_v_itmp; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":331 + * self.e_index.arr[j] = itmp + * + * ftmp = self.col1.arr[i] # <<<<<<<<<<<<<< + * self.col1.arr[i] = self.col1.arr[j] + * self.col1.arr[j] = ftmp + */ + __pyx_v_ftmp = (__pyx_v_self->col1->arr[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":332 + * + * ftmp = self.col1.arr[i] + * self.col1.arr[i] = self.col1.arr[j] # <<<<<<<<<<<<<< + * self.col1.arr[j] = ftmp + * + */ + (__pyx_v_self->col1->arr[__pyx_v_i]) = (__pyx_v_self->col1->arr[__pyx_v_j]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":333 + * ftmp = self.col1.arr[i] + * self.col1.arr[i] = self.col1.arr[j] + * self.col1.arr[j] = ftmp # <<<<<<<<<<<<<< + * + * ftmp = self.col2.arr[i] + */ + (__pyx_v_self->col1->arr[__pyx_v_j]) = __pyx_v_ftmp; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":335 + * self.col1.arr[j] = ftmp + * + * ftmp = self.col2.arr[i] # <<<<<<<<<<<<<< + * self.col2.arr[i] = self.col2.arr[j] + * self.col2.arr[j] = ftmp + */ + __pyx_v_ftmp = (__pyx_v_self->col2->arr[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":336 + * + * ftmp = self.col2.arr[i] + * self.col2.arr[i] = self.col2.arr[j] # <<<<<<<<<<<<<< + * self.col2.arr[j] = ftmp + * + */ + (__pyx_v_self->col2->arr[__pyx_v_i]) = (__pyx_v_self->col2->arr[__pyx_v_j]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":337 + * ftmp = self.col2.arr[i] + * self.col2.arr[i] = self.col2.arr[j] + * self.col2.arr[j] = ftmp # <<<<<<<<<<<<<< + * + * + */ + (__pyx_v_self->col2->arr[__pyx_v_j]) = __pyx_v_ftmp; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":340 + * + * + * cdef qsort(self, int i, int j, pad): # <<<<<<<<<<<<<< + * cdef int pval, p + * + */ + +static PyObject *__pyx_f_3_sa_5BiLex_qsort(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, int __pyx_v_i, int __pyx_v_j, PyObject *__pyx_v_pad) { + int __pyx_v_pval; + int __pyx_v_p; + long __pyx_v_k; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("qsort", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":343 + * cdef int pval, p + * + * if i > j: # <<<<<<<<<<<<<< + * raise Exception("Sort error in CLex") + * if i == j: #empty interval + */ + __pyx_t_1 = (__pyx_v_i > __pyx_v_j); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":344 + * + * if i > j: + * raise Exception("Sort error in CLex") # <<<<<<<<<<<<<< + * if i == j: #empty interval + * return + */ + __pyx_t_2 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_k_tuple_44), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":345 + * if i > j: + * raise Exception("Sort error in CLex") + * if i == j: #empty interval # <<<<<<<<<<<<<< + * return + * if i == j-1: # singleton interval + */ + __pyx_t_1 = (__pyx_v_i == __pyx_v_j); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":346 + * raise Exception("Sort error in CLex") + * if i == j: #empty interval + * return # <<<<<<<<<<<<<< + * if i == j-1: # singleton interval + * return + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":347 + * if i == j: #empty interval + * return + * if i == j-1: # singleton interval # <<<<<<<<<<<<<< + * return + * + */ + __pyx_t_1 = (__pyx_v_i == (__pyx_v_j - 1)); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":348 + * return + * if i == j-1: # singleton interval + * return # <<<<<<<<<<<<<< + * + * p = (i+j)/2 + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":350 + * return + * + * p = (i+j)/2 # <<<<<<<<<<<<<< + * pval = self.e_index.arr[p] + * self.swap(i, p) + */ + __pyx_v_p = __Pyx_div_long((__pyx_v_i + __pyx_v_j), 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":351 + * + * p = (i+j)/2 + * pval = self.e_index.arr[p] # <<<<<<<<<<<<<< + * self.swap(i, p) + * p = i + */ + __pyx_v_pval = (__pyx_v_self->e_index->arr[__pyx_v_p]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":352 + * p = (i+j)/2 + * pval = self.e_index.arr[p] + * self.swap(i, p) # <<<<<<<<<<<<<< + * p = i + * for k from i+1 <= k < j: + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_BiLex *)__pyx_v_self->__pyx_vtab)->swap(__pyx_v_self, __pyx_v_i, __pyx_v_p); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":353 + * pval = self.e_index.arr[p] + * self.swap(i, p) + * p = i # <<<<<<<<<<<<<< + * for k from i+1 <= k < j: + * if pval >= self.e_index.arr[k]: + */ + __pyx_v_p = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":354 + * self.swap(i, p) + * p = i + * for k from i+1 <= k < j: # <<<<<<<<<<<<<< + * if pval >= self.e_index.arr[k]: + * self.swap(p+1, k) + */ + __pyx_t_3 = __pyx_v_j; + for (__pyx_v_k = (__pyx_v_i + 1); __pyx_v_k < __pyx_t_3; __pyx_v_k++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":355 + * p = i + * for k from i+1 <= k < j: + * if pval >= self.e_index.arr[k]: # <<<<<<<<<<<<<< + * self.swap(p+1, k) + * self.swap(p, p+1) + */ + __pyx_t_1 = (__pyx_v_pval >= (__pyx_v_self->e_index->arr[__pyx_v_k])); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":356 + * for k from i+1 <= k < j: + * if pval >= self.e_index.arr[k]: + * self.swap(p+1, k) # <<<<<<<<<<<<<< + * self.swap(p, p+1) + * p = p + 1 + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_BiLex *)__pyx_v_self->__pyx_vtab)->swap(__pyx_v_self, (__pyx_v_p + 1), __pyx_v_k); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":357 + * if pval >= self.e_index.arr[k]: + * self.swap(p+1, k) + * self.swap(p, p+1) # <<<<<<<<<<<<<< + * p = p + 1 + * self.qsort(i,p, pad+" ") + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_BiLex *)__pyx_v_self->__pyx_vtab)->swap(__pyx_v_self, __pyx_v_p, (__pyx_v_p + 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":358 + * self.swap(p+1, k) + * self.swap(p, p+1) + * p = p + 1 # <<<<<<<<<<<<<< + * self.qsort(i,p, pad+" ") + * self.qsort(p+1,j, pad+" ") + */ + __pyx_v_p = (__pyx_v_p + 1); + goto __pyx_L8; + } + __pyx_L8:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":359 + * self.swap(p, p+1) + * p = p + 1 + * self.qsort(i,p, pad+" ") # <<<<<<<<<<<<<< + * self.qsort(p+1,j, pad+" ") + * + */ + __pyx_t_2 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = ((struct __pyx_vtabstruct_3_sa_BiLex *)__pyx_v_self->__pyx_vtab)->qsort(__pyx_v_self, __pyx_v_i, __pyx_v_p, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":360 + * p = p + 1 + * self.qsort(i,p, pad+" ") + * self.qsort(p+1,j, pad+" ") # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_4 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_BiLex *)__pyx_v_self->__pyx_vtab)->qsort(__pyx_v_self, (__pyx_v_p + 1), __pyx_v_j, __pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_sa.BiLex.qsort", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_5BiLex_13write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_5BiLex_13write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_enhanced (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.BiLex.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_5BiLex_12write_enhanced(((struct __pyx_obj_3_sa_BiLex *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":363 + * + * + * def write_enhanced(self, char* filename): # <<<<<<<<<<<<<< + * with open(filename, "w") as f: + * for i in self.f_index: + */ + +static PyObject *__pyx_pf_3_sa_5BiLex_12write_enhanced(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_v_i = NULL; + PyObject *__pyx_v_s1 = NULL; + PyObject *__pyx_v_s2 = NULL; + PyObject *__pyx_v_w = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *(*__pyx_t_13)(PyObject *); + int __pyx_t_14; + PyObject *__pyx_t_15 = NULL; + int __pyx_t_16; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_enhanced", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":364 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * for i in self.f_index: + * f.write("%d " % i) + */ + /*with:*/ { + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_f = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":365 + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: + * for i in self.f_index: # <<<<<<<<<<<<<< + * f.write("%d " % i) + * f.write("\n") + */ + if (PyList_CheckExact(((PyObject *)__pyx_v_self->f_index)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->f_index))) { + __pyx_t_4 = ((PyObject *)__pyx_v_self->f_index); __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(((PyObject *)__pyx_v_self->f_index)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else { + __pyx_t_1 = __pyx_t_9(__pyx_t_4); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":366 + * with open(filename, "w") as f: + * for i in self.f_index: + * f.write("%d " % i) # <<<<<<<<<<<<<< + * f.write("\n") + * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":367 + * for i in self.f_index: + * f.write("%d " % i) + * f.write("\n") # <<<<<<<<<<<<<< + * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): + * f.write("%d %f %f " % (i, s1, s2)) + */ + __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_46), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":368 + * f.write("%d " % i) + * f.write("\n") + * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): # <<<<<<<<<<<<<< + * f.write("%d %f %f " % (i, s1, s2)) + * f.write("\n") + */ + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_v_self->e_index)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self->e_index)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->e_index)); + __Pyx_INCREF(((PyObject *)__pyx_v_self->col1)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_self->col1)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->col1)); + __Pyx_INCREF(((PyObject *)__pyx_v_self->col2)); + PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_self->col2)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->col2)); + __pyx_t_4 = PyObject_Call(__pyx_builtin_zip, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + if (PyList_CheckExact(__pyx_t_4) || PyTuple_CheckExact(__pyx_t_4)) { + __pyx_t_2 = __pyx_t_4; __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_4); __pyx_t_8++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_4); __pyx_t_8++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else { + __pyx_t_4 = __pyx_t_9(__pyx_t_2); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) { + PyObject* sequence = __pyx_t_4; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 3)) { + if (size > 3) __Pyx_RaiseTooManyValuesError(3); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_11 = PyTuple_GET_ITEM(sequence, 2); + } else { + __pyx_t_10 = PyList_GET_ITEM(sequence, 0); + __pyx_t_1 = PyList_GET_ITEM(sequence, 1); + __pyx_t_11 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_11); + #else + __pyx_t_10 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_11 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + #endif + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + { + Py_ssize_t index = -1; + __pyx_t_12 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_13 = Py_TYPE(__pyx_t_12)->tp_iternext; + index = 0; __pyx_t_10 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_10)) goto __pyx_L20_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + index = 1; __pyx_t_1 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_1)) goto __pyx_L20_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 2; __pyx_t_11 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_11)) goto __pyx_L20_unpacking_failed; + __Pyx_GOTREF(__pyx_t_11); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 3) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_13 = NULL; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L21_unpacking_done; + __pyx_L20_unpacking_failed:; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_13 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_L21_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_10; + __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_v_s1); + __pyx_v_s1 = __pyx_t_1; + __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_v_s2); + __pyx_v_s2 = __pyx_t_11; + __pyx_t_11 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":369 + * f.write("\n") + * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): + * f.write("%d %f %f " % (i, s1, s2)) # <<<<<<<<<<<<<< + * f.write("\n") + * for i, w in enumerate(self.id2fword): + */ + __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_INCREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + __Pyx_INCREF(__pyx_v_s1); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_v_s1); + __Pyx_GIVEREF(__pyx_v_s1); + __Pyx_INCREF(__pyx_v_s2); + PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_v_s2); + __Pyx_GIVEREF(__pyx_v_s2); + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_47), ((PyObject *)__pyx_t_11)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; + __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_11, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":370 + * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): + * f.write("%d %f %f " % (i, s1, s2)) + * f.write("\n") # <<<<<<<<<<<<<< + * for i, w in enumerate(self.id2fword): + * f.write("%d %s " % (i, w)) + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_48), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":371 + * f.write("%d %f %f " % (i, s1, s2)) + * f.write("\n") + * for i, w in enumerate(self.id2fword): # <<<<<<<<<<<<<< + * f.write("%d %s " % (i, w)) + * f.write("\n") + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_1 = __pyx_int_0; + if (PyList_CheckExact(__pyx_v_self->id2fword) || PyTuple_CheckExact(__pyx_v_self->id2fword)) { + __pyx_t_2 = __pyx_v_self->id2fword; __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_self->id2fword); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_11 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_11); __pyx_t_8++; + #else + __pyx_t_11 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_11 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_11); __pyx_t_8++; + #else + __pyx_t_11 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else { + __pyx_t_11 = __pyx_t_9(__pyx_t_2); + if (unlikely(!__pyx_t_11)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_11); + } + __Pyx_XDECREF(__pyx_v_w); + __pyx_v_w = __pyx_t_11; + __pyx_t_11 = 0; + __Pyx_INCREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_1; + __pyx_t_11 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_1); + __pyx_t_1 = __pyx_t_11; + __pyx_t_11 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":372 + * f.write("\n") + * for i, w in enumerate(self.id2fword): + * f.write("%d %s " % (i, w)) # <<<<<<<<<<<<<< + * f.write("\n") + * for i, w in enumerate(self.id2eword): + */ + __pyx_t_11 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + __Pyx_INCREF(__pyx_v_w); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_w); + __Pyx_GIVEREF(__pyx_v_w); + __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_49), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_10)); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_10)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); + __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":373 + * for i, w in enumerate(self.id2fword): + * f.write("%d %s " % (i, w)) + * f.write("\n") # <<<<<<<<<<<<<< + * for i, w in enumerate(self.id2eword): + * f.write("%d %s " % (i, w)) + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_50), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":374 + * f.write("%d %s " % (i, w)) + * f.write("\n") + * for i, w in enumerate(self.id2eword): # <<<<<<<<<<<<<< + * f.write("%d %s " % (i, w)) + * f.write("\n") + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_2 = __pyx_int_0; + if (PyList_CheckExact(__pyx_v_self->id2eword) || PyTuple_CheckExact(__pyx_v_self->id2eword)) { + __pyx_t_1 = __pyx_v_self->id2eword; __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_self->id2eword); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_10 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_10); __pyx_t_8++; + #else + __pyx_t_10 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_10); __pyx_t_8++; + #else + __pyx_t_10 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else { + __pyx_t_10 = __pyx_t_9(__pyx_t_1); + if (unlikely(!__pyx_t_10)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[5]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_10); + } + __Pyx_XDECREF(__pyx_v_w); + __pyx_v_w = __pyx_t_10; + __pyx_t_10 = 0; + __Pyx_INCREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_2; + __pyx_t_10 = PyNumber_Add(__pyx_t_2, __pyx_int_1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); + __pyx_t_2 = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":375 + * f.write("\n") + * for i, w in enumerate(self.id2eword): + * f.write("%d %s " % (i, w)) # <<<<<<<<<<<<<< + * f.write("\n") + * + */ + __pyx_t_10 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + __Pyx_INCREF(__pyx_v_w); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_w); + __Pyx_GIVEREF(__pyx_v_w); + __pyx_t_11 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_49), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_11)); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_11)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_11)); + __pyx_t_11 = 0; + __pyx_t_11 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":376 + * for i, w in enumerate(self.id2eword): + * f.write("%d %s " % (i, w)) + * f.write("\n") # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_51), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":364 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * for i in self.f_index: + * f.write("%d " % i) + */ + /*except:*/ { + __Pyx_AddTraceback("_sa.BiLex.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_2, &__pyx_t_11) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_11); + __Pyx_GIVEREF(__pyx_t_11); + __pyx_t_15 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L9_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[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_16 = (!__pyx_t_14); + if (__pyx_t_16) { + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_11); + __Pyx_ErrRestore(__pyx_t_1, __pyx_t_2, __pyx_t_11); + __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_11 = 0; + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L28; + } + __pyx_L28:; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_52, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L29; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L29:; + } + + __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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("_sa.BiLex.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_s1); + __Pyx_XDECREF(__pyx_v_s2); + __Pyx_XDECREF(__pyx_v_w); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_5BiLex_15get_score(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_3_sa_5BiLex_15get_score(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_fword = 0; + PyObject *__pyx_v_eword = 0; + PyObject *__pyx_v_col = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_score (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fword,&__pyx_n_s__eword,&__pyx_n_s__col,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fword)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__eword)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("get_score", 1, 3, 3, 1); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__col)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("get_score", 1, 3, 3, 2); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_score") < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_fword = values[0]; + __pyx_v_eword = values[1]; + __pyx_v_col = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("get_score", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[5]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.BiLex.get_score", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_5BiLex_14get_score(((struct __pyx_obj_3_sa_BiLex *)__pyx_v_self), __pyx_v_fword, __pyx_v_eword, __pyx_v_col); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":379 + * + * + * def get_score(self, fword, eword, col): # <<<<<<<<<<<<<< + * cdef e_id, f_id, low, high, midpoint, val + * + */ + +static PyObject *__pyx_pf_3_sa_5BiLex_14get_score(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, PyObject *__pyx_v_fword, PyObject *__pyx_v_eword, PyObject *__pyx_v_col) { + PyObject *__pyx_v_e_id = 0; + PyObject *__pyx_v_f_id = 0; + PyObject *__pyx_v_low = 0; + PyObject *__pyx_v_high = 0; + PyObject *__pyx_v_midpoint = 0; + PyObject *__pyx_v_val = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_score", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":382 + * cdef e_id, f_id, low, high, midpoint, val + * + * if eword not in self.eword2id: # <<<<<<<<<<<<<< + * return None + * if fword not in self.fword2id: + */ + __pyx_t_1 = (__Pyx_NegateNonNeg(PySequence_Contains(__pyx_v_self->eword2id, __pyx_v_eword))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 382; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":383 + * + * if eword not in self.eword2id: + * return None # <<<<<<<<<<<<<< + * if fword not in self.fword2id: + * return None + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_None); + __pyx_r = Py_None; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":384 + * if eword not in self.eword2id: + * return None + * if fword not in self.fword2id: # <<<<<<<<<<<<<< + * return None + * f_id = self.fword2id[fword] + */ + __pyx_t_1 = (__Pyx_NegateNonNeg(PySequence_Contains(__pyx_v_self->fword2id, __pyx_v_fword))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":385 + * return None + * if fword not in self.fword2id: + * return None # <<<<<<<<<<<<<< + * f_id = self.fword2id[fword] + * e_id = self.eword2id[eword] + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_None); + __pyx_r = Py_None; + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":386 + * if fword not in self.fword2id: + * return None + * f_id = self.fword2id[fword] # <<<<<<<<<<<<<< + * e_id = self.eword2id[eword] + * low = self.f_index.arr[f_id] + */ + __pyx_t_2 = PyObject_GetItem(__pyx_v_self->fword2id, __pyx_v_fword); if (!__pyx_t_2) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_f_id = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":387 + * return None + * f_id = self.fword2id[fword] + * e_id = self.eword2id[eword] # <<<<<<<<<<<<<< + * low = self.f_index.arr[f_id] + * high = self.f_index.arr[f_id+1] + */ + __pyx_t_2 = PyObject_GetItem(__pyx_v_self->eword2id, __pyx_v_eword); if (!__pyx_t_2) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_e_id = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":388 + * f_id = self.fword2id[fword] + * e_id = self.eword2id[eword] + * low = self.f_index.arr[f_id] # <<<<<<<<<<<<<< + * high = self.f_index.arr[f_id+1] + * while high - low > 0: + */ + __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_v_f_id); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 388; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->f_index->arr[__pyx_t_3])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 388; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_low = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":389 + * e_id = self.eword2id[eword] + * low = self.f_index.arr[f_id] + * high = self.f_index.arr[f_id+1] # <<<<<<<<<<<<<< + * while high - low > 0: + * midpoint = (low+high)/2 + */ + __pyx_t_2 = PyNumber_Add(__pyx_v_f_id, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->f_index->arr[__pyx_t_3])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_high = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":390 + * low = self.f_index.arr[f_id] + * high = self.f_index.arr[f_id+1] + * while high - low > 0: # <<<<<<<<<<<<<< + * midpoint = (low+high)/2 + * val = self.e_index.arr[midpoint] + */ + while (1) { + __pyx_t_2 = PyNumber_Subtract(__pyx_v_high, __pyx_v_low); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_GT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (!__pyx_t_1) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":391 + * high = self.f_index.arr[f_id+1] + * while high - low > 0: + * midpoint = (low+high)/2 # <<<<<<<<<<<<<< + * val = self.e_index.arr[midpoint] + * if val == e_id: + */ + __pyx_t_4 = PyNumber_Add(__pyx_v_low, __pyx_v_high); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_int_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_v_midpoint); + __pyx_v_midpoint = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":392 + * while high - low > 0: + * midpoint = (low+high)/2 + * val = self.e_index.arr[midpoint] # <<<<<<<<<<<<<< + * if val == e_id: + * if col == 0: + */ + __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_v_midpoint); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->e_index->arr[__pyx_t_3])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_v_val); + __pyx_v_val = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":393 + * midpoint = (low+high)/2 + * val = self.e_index.arr[midpoint] + * if val == e_id: # <<<<<<<<<<<<<< + * if col == 0: + * return self.col1.arr[midpoint] + */ + __pyx_t_2 = PyObject_RichCompare(__pyx_v_val, __pyx_v_e_id, Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":394 + * val = self.e_index.arr[midpoint] + * if val == e_id: + * if col == 0: # <<<<<<<<<<<<<< + * return self.col1.arr[midpoint] + * if col == 1: + */ + __pyx_t_2 = PyObject_RichCompare(__pyx_v_col, __pyx_int_0, Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 394; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 394; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":395 + * if val == e_id: + * if col == 0: + * return self.col1.arr[midpoint] # <<<<<<<<<<<<<< + * if col == 1: + * return self.col2.arr[midpoint] + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_v_midpoint); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyFloat_FromDouble((__pyx_v_self->col1->arr[__pyx_t_3])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + goto __pyx_L8; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":396 + * if col == 0: + * return self.col1.arr[midpoint] + * if col == 1: # <<<<<<<<<<<<<< + * return self.col2.arr[midpoint] + * if val > e_id: + */ + __pyx_t_2 = PyObject_RichCompare(__pyx_v_col, __pyx_int_1, Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":397 + * return self.col1.arr[midpoint] + * if col == 1: + * return self.col2.arr[midpoint] # <<<<<<<<<<<<<< + * if val > e_id: + * high = midpoint + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_v_midpoint); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyFloat_FromDouble((__pyx_v_self->col2->arr[__pyx_t_3])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + goto __pyx_L9; + } + __pyx_L9:; + goto __pyx_L7; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":398 + * if col == 1: + * return self.col2.arr[midpoint] + * if val > e_id: # <<<<<<<<<<<<<< + * high = midpoint + * if val < e_id: + */ + __pyx_t_2 = PyObject_RichCompare(__pyx_v_val, __pyx_v_e_id, Py_GT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":399 + * return self.col2.arr[midpoint] + * if val > e_id: + * high = midpoint # <<<<<<<<<<<<<< + * if val < e_id: + * low = midpoint + 1 + */ + __Pyx_INCREF(__pyx_v_midpoint); + __Pyx_DECREF(__pyx_v_high); + __pyx_v_high = __pyx_v_midpoint; + goto __pyx_L10; + } + __pyx_L10:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":400 + * if val > e_id: + * high = midpoint + * if val < e_id: # <<<<<<<<<<<<<< + * low = midpoint + 1 + * return None + */ + __pyx_t_2 = PyObject_RichCompare(__pyx_v_val, __pyx_v_e_id, Py_LT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":401 + * high = midpoint + * if val < e_id: + * low = midpoint + 1 # <<<<<<<<<<<<<< + * return None + * + */ + __pyx_t_2 = PyNumber_Add(__pyx_v_midpoint, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_v_low); + __pyx_v_low = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L11; + } + __pyx_L11:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":402 + * if val < e_id: + * low = midpoint + 1 + * return None # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_None); + __pyx_r = Py_None; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_sa.BiLex.get_score", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_e_id); + __Pyx_XDECREF(__pyx_v_f_id); + __Pyx_XDECREF(__pyx_v_low); + __Pyx_XDECREF(__pyx_v_high); + __Pyx_XDECREF(__pyx_v_midpoint); + __Pyx_XDECREF(__pyx_v_val); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_5BiLex_17write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static char __pyx_doc_3_sa_5BiLex_16write_text[] = "Note: does not guarantee writing the dictionary in the original order"; +static PyObject *__pyx_pw_3_sa_5BiLex_17write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_text (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.BiLex.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_5BiLex_16write_text(((struct __pyx_obj_3_sa_BiLex *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":405 + * + * + * def write_text(self, char* filename): # <<<<<<<<<<<<<< + * """Note: does not guarantee writing the dictionary in the original order""" + * cdef i, N, e_id, f_id + */ + +static PyObject *__pyx_pf_3_sa_5BiLex_16write_text(struct __pyx_obj_3_sa_BiLex *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_v_i = 0; + PyObject *__pyx_v_N = 0; + PyObject *__pyx_v_e_id = 0; + PyObject *__pyx_v_f_id = 0; + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_v_score1 = NULL; + PyObject *__pyx_v_score2 = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + long __pyx_t_9; + long __pyx_t_10; + int __pyx_t_11; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + int __pyx_t_14; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_text", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":409 + * cdef i, N, e_id, f_id + * + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * N = len(self.e_index) + * f_id = 0 + */ + /*with:*/ { + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_f = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":410 + * + * with open(filename, "w") as f: + * N = len(self.e_index) # <<<<<<<<<<<<<< + * f_id = 0 + * for i from 0 <= i < N: + */ + __pyx_t_4 = ((PyObject *)__pyx_v_self->e_index); + __Pyx_INCREF(__pyx_t_4); + __pyx_t_8 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_v_N = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":411 + * with open(filename, "w") as f: + * N = len(self.e_index) + * f_id = 0 # <<<<<<<<<<<<<< + * for i from 0 <= i < N: + * while self.f_index.arr[f_id+1] == i: + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_f_id = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":412 + * N = len(self.e_index) + * f_id = 0 + * for i from 0 <= i < N: # <<<<<<<<<<<<<< + * while self.f_index.arr[f_id+1] == i: + * f_id = f_id + 1 + */ + __pyx_t_9 = __Pyx_PyInt_AsLong(__pyx_v_N); if (unlikely((__pyx_t_9 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10++) { + __pyx_t_4 = PyInt_FromLong(__pyx_t_10); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":413 + * f_id = 0 + * for i from 0 <= i < N: + * while self.f_index.arr[f_id+1] == i: # <<<<<<<<<<<<<< + * f_id = f_id + 1 + * e_id = self.e_index.arr[i] + */ + while (1) { + __pyx_t_4 = PyNumber_Add(__pyx_v_f_id, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyInt_FromLong((__pyx_v_self->f_index->arr[__pyx_t_8])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_v_i, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!__pyx_t_11) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":414 + * for i from 0 <= i < N: + * while self.f_index.arr[f_id+1] == i: + * f_id = f_id + 1 # <<<<<<<<<<<<<< + * e_id = self.e_index.arr[i] + * score1 = self.col1.arr[i] + */ + __pyx_t_1 = PyNumber_Add(__pyx_v_f_id, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_v_f_id); + __pyx_v_f_id = __pyx_t_1; + __pyx_t_1 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":415 + * while self.f_index.arr[f_id+1] == i: + * f_id = f_id + 1 + * e_id = self.e_index.arr[i] # <<<<<<<<<<<<<< + * score1 = self.col1.arr[i] + * score2 = self.col2.arr[i] + */ + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyInt_FromLong((__pyx_v_self->e_index->arr[__pyx_t_8])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_e_id); + __pyx_v_e_id = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":416 + * f_id = f_id + 1 + * e_id = self.e_index.arr[i] + * score1 = self.col1.arr[i] # <<<<<<<<<<<<<< + * score2 = self.col2.arr[i] + * f.write("%s %s %.6f %.6f\n" % (self.id2fword[f_id], self.id2eword[e_id], score1, score2)) + */ + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyFloat_FromDouble((__pyx_v_self->col1->arr[__pyx_t_8])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_score1); + __pyx_v_score1 = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":417 + * e_id = self.e_index.arr[i] + * score1 = self.col1.arr[i] + * score2 = self.col2.arr[i] # <<<<<<<<<<<<<< + * f.write("%s %s %.6f %.6f\n" % (self.id2fword[f_id], self.id2eword[e_id], score1, score2)) + */ + __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyFloat_FromDouble((__pyx_v_self->col2->arr[__pyx_t_8])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_score2); + __pyx_v_score2 = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":418 + * score1 = self.col1.arr[i] + * score2 = self.col2.arr[i] + * f.write("%s %s %.6f %.6f\n" % (self.id2fword[f_id], self.id2eword[e_id], score1, score2)) # <<<<<<<<<<<<<< + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyObject_GetItem(__pyx_v_self->id2fword, __pyx_v_f_id); if (!__pyx_t_4) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyObject_GetItem(__pyx_v_self->id2eword, __pyx_v_e_id); if (!__pyx_t_2) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_12 = PyTuple_New(4); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_score1); + PyTuple_SET_ITEM(__pyx_t_12, 2, __pyx_v_score1); + __Pyx_GIVEREF(__pyx_v_score1); + __Pyx_INCREF(__pyx_v_score2); + PyTuple_SET_ITEM(__pyx_t_12, 3, __pyx_v_score2); + __Pyx_GIVEREF(__pyx_v_score2); + __pyx_t_4 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_53), ((PyObject *)__pyx_t_12)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_10 = __Pyx_PyInt_AsLong(__pyx_v_i); if (unlikely((__pyx_t_10 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":412 + * N = len(self.e_index) + * f_id = 0 + * for i from 0 <= i < N: # <<<<<<<<<<<<<< + * while self.f_index.arr[f_id+1] == i: + * f_id = f_id + 1 + */ + __pyx_t_2 = PyInt_FromLong(__pyx_t_10); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_2; + __pyx_t_2 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":409 + * cdef i, N, e_id, f_id + * + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * N = len(self.e_index) + * f_id = 0 + */ + /*except:*/ { + __Pyx_AddTraceback("_sa.BiLex.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_12, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_12); + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_13 = PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_13); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_14 = (!__pyx_t_11); + if (__pyx_t_14) { + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_ErrRestore(__pyx_t_2, __pyx_t_12, __pyx_t_1); + __pyx_t_2 = 0; __pyx_t_12 = 0; __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L22; + } + __pyx_L22:; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_54, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L23; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L23:; + } + + __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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_AddTraceback("_sa.BiLex.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_N); + __Pyx_XDECREF(__pyx_v_e_id); + __Pyx_XDECREF(__pyx_v_f_id); + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_score1); + __Pyx_XDECREF(__pyx_v_score2); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":21 + * cdef int LOWER_MASK[32] + * + * cdef void _init_lower_mask(): # <<<<<<<<<<<<<< + * cdef unsigned i + * cdef int mask = 0 + */ + +static void __pyx_f_3_sa__init_lower_mask(void) { + unsigned int __pyx_v_i; + int __pyx_v_mask; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + unsigned int __pyx_t_2; + __Pyx_RefNannySetupContext("_init_lower_mask", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":23 + * cdef void _init_lower_mask(): + * cdef unsigned i + * cdef int mask = 0 # <<<<<<<<<<<<<< + * for i in range(MIN_BOTTOM_SIZE): + * mask = (mask << 1) + 1 + */ + __pyx_v_mask = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":24 + * cdef unsigned i + * cdef int mask = 0 + * for i in range(MIN_BOTTOM_SIZE): # <<<<<<<<<<<<<< + * mask = (mask << 1) + 1 + * LOWER_MASK[i] = mask + */ + __pyx_t_1 = __pyx_v_3_sa_MIN_BOTTOM_SIZE; + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_v_i = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":25 + * cdef int mask = 0 + * for i in range(MIN_BOTTOM_SIZE): + * mask = (mask << 1) + 1 # <<<<<<<<<<<<<< + * LOWER_MASK[i] = mask + * + */ + __pyx_v_mask = ((__pyx_v_mask << 1) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":26 + * for i in range(MIN_BOTTOM_SIZE): + * mask = (mask << 1) + 1 + * LOWER_MASK[i] = mask # <<<<<<<<<<<<<< + * + * _init_lower_mask() + */ + (__pyx_v_3_sa_LOWER_MASK[__pyx_v_i]) = __pyx_v_mask; + } + + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":37 + * + * + * cdef _BitSet* new_BitSet(): # <<<<<<<<<<<<<< + * cdef _BitSet* b + * + */ + +static struct __pyx_t_3_sa__BitSet *__pyx_f_3_sa_new_BitSet(void) { + struct __pyx_t_3_sa__BitSet *__pyx_v_b; + struct __pyx_t_3_sa__BitSet *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("new_BitSet", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":40 + * cdef _BitSet* b + * + * b = <_BitSet*> malloc(sizeof(_BitSet)) # <<<<<<<<<<<<<< + * b.bitset = 0 + * b.min_val = -1 + */ + __pyx_v_b = ((struct __pyx_t_3_sa__BitSet *)malloc((sizeof(struct __pyx_t_3_sa__BitSet)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":41 + * + * b = <_BitSet*> malloc(sizeof(_BitSet)) + * b.bitset = 0 # <<<<<<<<<<<<<< + * b.min_val = -1 + * b.max_val = -1 + */ + __pyx_v_b->bitset = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":42 + * b = <_BitSet*> malloc(sizeof(_BitSet)) + * b.bitset = 0 + * b.min_val = -1 # <<<<<<<<<<<<<< + * b.max_val = -1 + * b.size = 0 + */ + __pyx_v_b->min_val = -1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":43 + * b.bitset = 0 + * b.min_val = -1 + * b.max_val = -1 # <<<<<<<<<<<<<< + * b.size = 0 + * return b + */ + __pyx_v_b->max_val = -1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":44 + * b.min_val = -1 + * b.max_val = -1 + * b.size = 0 # <<<<<<<<<<<<<< + * return b + * + */ + __pyx_v_b->size = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":45 + * b.max_val = -1 + * b.size = 0 + * return b # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_b; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":48 + * + * + * cdef int bitset_findsucc(_BitSet* b, int i): # <<<<<<<<<<<<<< + * cdef int bitset, mask + * cdef int low, high, mid + */ + +static int __pyx_f_3_sa_bitset_findsucc(struct __pyx_t_3_sa__BitSet *__pyx_v_b, int __pyx_v_i) { + int __pyx_v_bitset; + int __pyx_v_mask; + int __pyx_v_low; + int __pyx_v_high; + int __pyx_v_mid; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("bitset_findsucc", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":52 + * cdef int low, high, mid + * + * if b.max_val == -1 or i >= b.max_val: # <<<<<<<<<<<<<< + * return -1 + * if i < b.min_val: + */ + __pyx_t_1 = (__pyx_v_b->max_val == -1); + if (!__pyx_t_1) { + __pyx_t_2 = (__pyx_v_i >= __pyx_v_b->max_val); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":53 + * + * if b.max_val == -1 or i >= b.max_val: + * return -1 # <<<<<<<<<<<<<< + * if i < b.min_val: + * return b.min_val + */ + __pyx_r = -1; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":54 + * if b.max_val == -1 or i >= b.max_val: + * return -1 + * if i < b.min_val: # <<<<<<<<<<<<<< + * return b.min_val + * + */ + __pyx_t_3 = (__pyx_v_i < __pyx_v_b->min_val); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":55 + * return -1 + * if i < b.min_val: + * return b.min_val # <<<<<<<<<<<<<< + * + * bitset = b.bitset & ~LOWER_MASK[i] + */ + __pyx_r = __pyx_v_b->min_val; + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":57 + * return b.min_val + * + * bitset = b.bitset & ~LOWER_MASK[i] # <<<<<<<<<<<<<< + * low = i+1 + * high = b.max_val+1 + */ + __pyx_v_bitset = (__pyx_v_b->bitset & (~(__pyx_v_3_sa_LOWER_MASK[__pyx_v_i]))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":58 + * + * bitset = b.bitset & ~LOWER_MASK[i] + * low = i+1 # <<<<<<<<<<<<<< + * high = b.max_val+1 + * while low < high-1: + */ + __pyx_v_low = (__pyx_v_i + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":59 + * bitset = b.bitset & ~LOWER_MASK[i] + * low = i+1 + * high = b.max_val+1 # <<<<<<<<<<<<<< + * while low < high-1: + * mid = (high + low)/2 + */ + __pyx_v_high = (__pyx_v_b->max_val + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":60 + * low = i+1 + * high = b.max_val+1 + * while low < high-1: # <<<<<<<<<<<<<< + * mid = (high + low)/2 + * mask = ~(LOWER_MASK[high-1] ^ LOWER_MASK[mid-1]) + */ + while (1) { + __pyx_t_3 = (__pyx_v_low < (__pyx_v_high - 1)); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":61 + * high = b.max_val+1 + * while low < high-1: + * mid = (high + low)/2 # <<<<<<<<<<<<<< + * mask = ~(LOWER_MASK[high-1] ^ LOWER_MASK[mid-1]) + * if bitset & mask == 0: + */ + __pyx_v_mid = __Pyx_div_long((__pyx_v_high + __pyx_v_low), 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":62 + * while low < high-1: + * mid = (high + low)/2 + * mask = ~(LOWER_MASK[high-1] ^ LOWER_MASK[mid-1]) # <<<<<<<<<<<<<< + * if bitset & mask == 0: + * low = mid + */ + __pyx_v_mask = (~((__pyx_v_3_sa_LOWER_MASK[(__pyx_v_high - 1)]) ^ (__pyx_v_3_sa_LOWER_MASK[(__pyx_v_mid - 1)]))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":63 + * mid = (high + low)/2 + * mask = ~(LOWER_MASK[high-1] ^ LOWER_MASK[mid-1]) + * if bitset & mask == 0: # <<<<<<<<<<<<<< + * low = mid + * else: + */ + __pyx_t_3 = ((__pyx_v_bitset & __pyx_v_mask) == 0); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":64 + * mask = ~(LOWER_MASK[high-1] ^ LOWER_MASK[mid-1]) + * if bitset & mask == 0: + * low = mid # <<<<<<<<<<<<<< + * else: + * bitset = bitset & mask + */ + __pyx_v_low = __pyx_v_mid; + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":66 + * low = mid + * else: + * bitset = bitset & mask # <<<<<<<<<<<<<< + * high = mid + * return low + */ + __pyx_v_bitset = (__pyx_v_bitset & __pyx_v_mask); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":67 + * else: + * bitset = bitset & mask + * high = mid # <<<<<<<<<<<<<< + * return low + * + */ + __pyx_v_high = __pyx_v_mid; + } + __pyx_L7:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":68 + * bitset = bitset & mask + * high = mid + * return low # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_low; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":71 + * + * + * cdef int bitset_insert(_BitSet* b, int i): # <<<<<<<<<<<<<< + * cdef int val + * + */ + +static int __pyx_f_3_sa_bitset_insert(struct __pyx_t_3_sa__BitSet *__pyx_v_b, int __pyx_v_i) { + int __pyx_v_val; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("bitset_insert", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":74 + * cdef int val + * + * val = 1 << i # <<<<<<<<<<<<<< + * if b.bitset & val == 0: + * b.bitset = b.bitset | val + */ + __pyx_v_val = (1 << __pyx_v_i); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":75 + * + * val = 1 << i + * if b.bitset & val == 0: # <<<<<<<<<<<<<< + * b.bitset = b.bitset | val + * if b.size == 0: + */ + __pyx_t_1 = ((__pyx_v_b->bitset & __pyx_v_val) == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":76 + * val = 1 << i + * if b.bitset & val == 0: + * b.bitset = b.bitset | val # <<<<<<<<<<<<<< + * if b.size == 0: + * b.min_val = i + */ + __pyx_v_b->bitset = (__pyx_v_b->bitset | __pyx_v_val); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":77 + * if b.bitset & val == 0: + * b.bitset = b.bitset | val + * if b.size == 0: # <<<<<<<<<<<<<< + * b.min_val = i + * b.max_val = i + */ + __pyx_t_1 = (__pyx_v_b->size == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":78 + * b.bitset = b.bitset | val + * if b.size == 0: + * b.min_val = i # <<<<<<<<<<<<<< + * b.max_val = i + * else: + */ + __pyx_v_b->min_val = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":79 + * if b.size == 0: + * b.min_val = i + * b.max_val = i # <<<<<<<<<<<<<< + * else: + * if i < b.min_val: + */ + __pyx_v_b->max_val = __pyx_v_i; + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":81 + * b.max_val = i + * else: + * if i < b.min_val: # <<<<<<<<<<<<<< + * b.min_val = i + * if i > b.max_val: + */ + __pyx_t_1 = (__pyx_v_i < __pyx_v_b->min_val); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":82 + * else: + * if i < b.min_val: + * b.min_val = i # <<<<<<<<<<<<<< + * if i > b.max_val: + * b.max_val = i + */ + __pyx_v_b->min_val = __pyx_v_i; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":83 + * if i < b.min_val: + * b.min_val = i + * if i > b.max_val: # <<<<<<<<<<<<<< + * b.max_val = i + * b.size = b.size + 1 + */ + __pyx_t_1 = (__pyx_v_i > __pyx_v_b->max_val); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":84 + * b.min_val = i + * if i > b.max_val: + * b.max_val = i # <<<<<<<<<<<<<< + * b.size = b.size + 1 + * return 1 + */ + __pyx_v_b->max_val = __pyx_v_i; + goto __pyx_L6; + } + __pyx_L6:; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":85 + * if i > b.max_val: + * b.max_val = i + * b.size = b.size + 1 # <<<<<<<<<<<<<< + * return 1 + * return 0 + */ + __pyx_v_b->size = (__pyx_v_b->size + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":86 + * b.max_val = i + * b.size = b.size + 1 + * return 1 # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":87 + * b.size = b.size + 1 + * return 1 + * return 0 # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = 0; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":90 + * + * + * cdef int bitset_contains(_BitSet* b, int i): # <<<<<<<<<<<<<< + * cdef int val + * + */ + +static int __pyx_f_3_sa_bitset_contains(struct __pyx_t_3_sa__BitSet *__pyx_v_b, int __pyx_v_i) { + int __pyx_v_val; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("bitset_contains", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":93 + * cdef int val + * + * val = 1 << i # <<<<<<<<<<<<<< + * if b.bitset & val == 0: + * return 0 + */ + __pyx_v_val = (1 << __pyx_v_i); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":94 + * + * val = 1 << i + * if b.bitset & val == 0: # <<<<<<<<<<<<<< + * return 0 + * else: + */ + __pyx_t_1 = ((__pyx_v_b->bitset & __pyx_v_val) == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":95 + * val = 1 << i + * if b.bitset & val == 0: + * return 0 # <<<<<<<<<<<<<< + * else: + * return 1 + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":97 + * return 0 + * else: + * return 1 # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = 1; + goto __pyx_L0; + } + __pyx_L3:; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_14BitSetIterator_1__next__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_14BitSetIterator_1__next__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__next__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_14BitSetIterator___next__(((struct __pyx_obj_3_sa_BitSetIterator *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":104 + * cdef int next_val + * + * def __next__(self): # <<<<<<<<<<<<<< + * cdef int ret_val + * + */ + +static PyObject *__pyx_pf_3_sa_14BitSetIterator___next__(struct __pyx_obj_3_sa_BitSetIterator *__pyx_v_self) { + int __pyx_v_ret_val; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__next__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":107 + * cdef int ret_val + * + * if self.next_val == -1: # <<<<<<<<<<<<<< + * raise StopIteration() + * ret_val = self.next_val + */ + __pyx_t_1 = (__pyx_v_self->next_val == -1); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":108 + * + * if self.next_val == -1: + * raise StopIteration() # <<<<<<<<<<<<<< + * ret_val = self.next_val + * self.next_val = bitset_findsucc(self.b, ret_val) + */ + __pyx_t_2 = PyObject_Call(__pyx_builtin_StopIteration, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[6]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":109 + * if self.next_val == -1: + * raise StopIteration() + * ret_val = self.next_val # <<<<<<<<<<<<<< + * self.next_val = bitset_findsucc(self.b, ret_val) + * return ret_val + */ + __pyx_v_ret_val = __pyx_v_self->next_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":110 + * raise StopIteration() + * ret_val = self.next_val + * self.next_val = bitset_findsucc(self.b, ret_val) # <<<<<<<<<<<<<< + * return ret_val + * + */ + __pyx_v_self->next_val = __pyx_f_3_sa_bitset_findsucc(__pyx_v_self->b, __pyx_v_ret_val); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":111 + * ret_val = self.next_val + * self.next_val = bitset_findsucc(self.b, ret_val) + * return ret_val # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyInt_FromLong(__pyx_v_ret_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_sa.BitSetIterator.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_6BitSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_6BitSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; + __pyx_r = __pyx_pf_3_sa_6BitSet___cinit__(((struct __pyx_obj_3_sa_BitSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":122 + * cdef _BitSet* b + * + * def __cinit__(self): # <<<<<<<<<<<<<< + * self.b = new_BitSet() + * + */ + +static int __pyx_pf_3_sa_6BitSet___cinit__(struct __pyx_obj_3_sa_BitSet *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":123 + * + * def __cinit__(self): + * self.b = new_BitSet() # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->b = __pyx_f_3_sa_new_BitSet(); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_3_sa_6BitSet_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_3_sa_6BitSet_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_3_sa_6BitSet_2__dealloc__(((struct __pyx_obj_3_sa_BitSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":125 + * self.b = new_BitSet() + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * free(self.b) + * + */ + +static void __pyx_pf_3_sa_6BitSet_2__dealloc__(struct __pyx_obj_3_sa_BitSet *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":126 + * + * def __dealloc__(self): + * free(self.b) # <<<<<<<<<<<<<< + * + * def __iter__(self): + */ + free(__pyx_v_self->b); + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_6BitSet_5__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_6BitSet_5__iter__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6BitSet_4__iter__(((struct __pyx_obj_3_sa_BitSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":128 + * free(self.b) + * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef BitSetIterator it + * it = BitSetIterator() + */ + +static PyObject *__pyx_pf_3_sa_6BitSet_4__iter__(struct __pyx_obj_3_sa_BitSet *__pyx_v_self) { + struct __pyx_obj_3_sa_BitSetIterator *__pyx_v_it = 0; + 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("__iter__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":130 + * def __iter__(self): + * cdef BitSetIterator it + * it = BitSetIterator() # <<<<<<<<<<<<<< + * it.b = self.b + * it.next_val = self.b.min_val + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_BitSetIterator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_it = ((struct __pyx_obj_3_sa_BitSetIterator *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":131 + * cdef BitSetIterator it + * it = BitSetIterator() + * it.b = self.b # <<<<<<<<<<<<<< + * it.next_val = self.b.min_val + * return it + */ + __pyx_v_it->b = __pyx_v_self->b; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":132 + * it = BitSetIterator() + * it.b = self.b + * it.next_val = self.b.min_val # <<<<<<<<<<<<<< + * return it + * + */ + __pyx_v_it->next_val = __pyx_v_self->b->min_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":133 + * it.b = self.b + * it.next_val = self.b.min_val + * return it # <<<<<<<<<<<<<< + * + * def insert(self, i): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_it)); + __pyx_r = ((PyObject *)__pyx_v_it); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_sa.BitSet.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_it); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_6BitSet_7insert(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_3_sa_6BitSet_7insert(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("insert (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6BitSet_6insert(((struct __pyx_obj_3_sa_BitSet *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":135 + * return it + * + * def insert(self, i): # <<<<<<<<<<<<<< + * return bitset_insert(self.b, i) + * + */ + +static PyObject *__pyx_pf_3_sa_6BitSet_6insert(struct __pyx_obj_3_sa_BitSet *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("insert", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":136 + * + * def insert(self, i): + * return bitset_insert(self.b, i) # <<<<<<<<<<<<<< + * + * def findsucc(self, i): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong(__pyx_f_3_sa_bitset_insert(__pyx_v_self->b, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_sa.BitSet.insert", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_6BitSet_9findsucc(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_3_sa_6BitSet_9findsucc(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("findsucc (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6BitSet_8findsucc(((struct __pyx_obj_3_sa_BitSet *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":138 + * return bitset_insert(self.b, i) + * + * def findsucc(self, i): # <<<<<<<<<<<<<< + * return bitset_findsucc(self.b, i) + * + */ + +static PyObject *__pyx_pf_3_sa_6BitSet_8findsucc(struct __pyx_obj_3_sa_BitSet *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("findsucc", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":139 + * + * def findsucc(self, i): + * return bitset_findsucc(self.b, i) # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong(__pyx_f_3_sa_bitset_findsucc(__pyx_v_self->b, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_sa.BitSet.findsucc", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_6BitSet_11__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_6BitSet_11__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6BitSet_10__str__(((struct __pyx_obj_3_sa_BitSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":141 + * return bitset_findsucc(self.b, i) + * + * def __str__(self): # <<<<<<<<<<<<<< + * return dec2bin(self.b.bitset)+" ("+str(self.b.size)+","+str(self.b.min_val)+","+str(self.b.max_val)+")" + * + */ + +static PyObject *__pyx_pf_3_sa_6BitSet_10__str__(struct __pyx_obj_3_sa_BitSet *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__str__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":142 + * + * def __str__(self): + * return dec2bin(self.b.bitset)+" ("+str(self.b.size)+","+str(self.b.min_val)+","+str(self.b.max_val)+")" # <<<<<<<<<<<<<< + * + * def min(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = ((PyObject *)__pyx_f_3_sa_dec2bin(__pyx_v_self->b->bitset)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Add(__pyx_t_1, ((PyObject *)__pyx_kp_s_55)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->b->size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Add(((PyObject *)__pyx_t_2), __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Add(__pyx_t_3, ((PyObject *)__pyx_kp_s_4)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromLong(__pyx_v_self->b->min_val); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Add(__pyx_t_2, ((PyObject *)__pyx_kp_s_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyInt_FromLong(__pyx_v_self->b->max_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __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 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Add(__pyx_t_1, ((PyObject *)__pyx_kp_s_56)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.BitSet.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_6BitSet_13min(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_3_sa_6BitSet_13min(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("min (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6BitSet_12min(((struct __pyx_obj_3_sa_BitSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":144 + * return dec2bin(self.b.bitset)+" ("+str(self.b.size)+","+str(self.b.min_val)+","+str(self.b.max_val)+")" + * + * def min(self): # <<<<<<<<<<<<<< + * return self.b.min_val + * + */ + +static PyObject *__pyx_pf_3_sa_6BitSet_12min(struct __pyx_obj_3_sa_BitSet *__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("min", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":145 + * + * def min(self): + * return self.b.min_val # <<<<<<<<<<<<<< + * + * def max(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->b->min_val); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_sa.BitSet.min", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_6BitSet_15max(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_3_sa_6BitSet_15max(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("max (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6BitSet_14max(((struct __pyx_obj_3_sa_BitSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":147 + * return self.b.min_val + * + * def max(self): # <<<<<<<<<<<<<< + * return self.b.max_val + * + */ + +static PyObject *__pyx_pf_3_sa_6BitSet_14max(struct __pyx_obj_3_sa_BitSet *__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("max", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":148 + * + * def max(self): + * return self.b.max_val # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->b->max_val); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_sa.BitSet.max", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_3_sa_6BitSet_17__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_3_sa_6BitSet_17__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6BitSet_16__len__(((struct __pyx_obj_3_sa_BitSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":150 + * return self.b.max_val + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.b.size + * + */ + +static Py_ssize_t __pyx_pf_3_sa_6BitSet_16__len__(struct __pyx_obj_3_sa_BitSet *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":151 + * + * def __len__(self): + * return self.b.size # <<<<<<<<<<<<<< + * + * def __contains__(self, i): + */ + __pyx_r = __pyx_v_self->b->size; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_6BitSet_19__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static int __pyx_pw_3_sa_6BitSet_19__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6BitSet_18__contains__(((struct __pyx_obj_3_sa_BitSet *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":153 + * return self.b.size + * + * def __contains__(self, i): # <<<<<<<<<<<<<< + * return bool(bitset_contains(self.b, i)) + * + */ + +static int __pyx_pf_3_sa_6BitSet_18__contains__(struct __pyx_obj_3_sa_BitSet *__pyx_v_self, PyObject *__pyx_v_i) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__contains__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":154 + * + * def __contains__(self, i): + * return bool(bitset_contains(self.b, i)) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong(__pyx_f_3_sa_bitset_contains(__pyx_v_self->b, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = (!(!__pyx_t_3)); + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_sa.BitSet.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":157 + * + * + * cdef str dec2bin(long i): # <<<<<<<<<<<<<< + * cdef str result = "" + * cdef unsigned d + */ + +static PyObject *__pyx_f_3_sa_dec2bin(long __pyx_v_i) { + PyObject *__pyx_v_result = 0; + CYTHON_UNUSED unsigned int __pyx_v_d; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + unsigned int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("dec2bin", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":158 + * + * cdef str dec2bin(long i): + * cdef str result = "" # <<<<<<<<<<<<<< + * cdef unsigned d + * for d in range(MIN_BOTTOM_SIZE): + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_42)); + __pyx_v_result = __pyx_kp_s_42; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":160 + * cdef str result = "" + * cdef unsigned d + * for d in range(MIN_BOTTOM_SIZE): # <<<<<<<<<<<<<< + * if i & LOWER_MASK[0] == 0: + * result = "0"+result + */ + __pyx_t_1 = __pyx_v_3_sa_MIN_BOTTOM_SIZE; + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_v_d = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":161 + * cdef unsigned d + * for d in range(MIN_BOTTOM_SIZE): + * if i & LOWER_MASK[0] == 0: # <<<<<<<<<<<<<< + * result = "0"+result + * else: + */ + __pyx_t_3 = ((__pyx_v_i & (__pyx_v_3_sa_LOWER_MASK[0])) == 0); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":162 + * for d in range(MIN_BOTTOM_SIZE): + * if i & LOWER_MASK[0] == 0: + * result = "0"+result # <<<<<<<<<<<<<< + * else: + * result = "1"+result + */ + __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_kp_s__0), ((PyObject *)__pyx_v_result)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __Pyx_DECREF(((PyObject *)__pyx_v_result)); + __pyx_v_result = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":164 + * result = "0"+result + * else: + * result = "1"+result # <<<<<<<<<<<<<< + * i = i >> 1 + * return result + */ + __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_kp_s__1), ((PyObject *)__pyx_v_result)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __Pyx_DECREF(((PyObject *)__pyx_v_result)); + __pyx_v_result = __pyx_t_4; + __pyx_t_4 = 0; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":165 + * else: + * result = "1"+result + * i = i >> 1 # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_v_i = (__pyx_v_i >> 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":166 + * result = "1"+result + * i = i >> 1 + * return result # <<<<<<<<<<<<<< + * + * cdef struct _VEB: + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = ((PyObject*)Py_None); __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_sa.dec2bin", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":177 + * void** bottom + * + * cdef _VEB* new_VEB(int n): # <<<<<<<<<<<<<< + * cdef _VEB* veb + * cdef int num_bits, num_top_bits, i + */ + +static struct __pyx_t_3_sa__VEB *__pyx_f_3_sa_new_VEB(int __pyx_v_n) { + struct __pyx_t_3_sa__VEB *__pyx_v_veb; + int __pyx_v_num_bits; + struct __pyx_t_3_sa__VEB *__pyx_r; + __Pyx_RefNannyDeclarations + double __pyx_t_1; + double __pyx_t_2; + int __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("new_VEB", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":181 + * cdef int num_bits, num_top_bits, i + * + * veb = <_VEB*> malloc(sizeof(_VEB)) # <<<<<<<<<<<<<< + * + * num_bits = int(ceil(log(n) / log(2))) + */ + __pyx_v_veb = ((struct __pyx_t_3_sa__VEB *)malloc((sizeof(struct __pyx_t_3_sa__VEB)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":183 + * veb = <_VEB*> malloc(sizeof(_VEB)) + * + * num_bits = int(ceil(log(n) / log(2))) # <<<<<<<<<<<<<< + * veb.num_bottom_bits = num_bits/2 + * if veb.num_bottom_bits < MIN_BOTTOM_BITS: + */ + __pyx_t_1 = log(__pyx_v_n); + __pyx_t_2 = log(2.0); + if (unlikely(__pyx_t_2 == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[6]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_num_bits = ((int)ceil((__pyx_t_1 / __pyx_t_2))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":184 + * + * num_bits = int(ceil(log(n) / log(2))) + * veb.num_bottom_bits = num_bits/2 # <<<<<<<<<<<<<< + * if veb.num_bottom_bits < MIN_BOTTOM_BITS: + * veb.num_bottom_bits = MIN_BOTTOM_BITS + */ + __pyx_v_veb->num_bottom_bits = __Pyx_div_long(__pyx_v_num_bits, 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":185 + * num_bits = int(ceil(log(n) / log(2))) + * veb.num_bottom_bits = num_bits/2 + * if veb.num_bottom_bits < MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< + * veb.num_bottom_bits = MIN_BOTTOM_BITS + * veb.top_universe_size = (n >> veb.num_bottom_bits) + 1 + */ + __pyx_t_3 = (__pyx_v_veb->num_bottom_bits < __pyx_v_3_sa_MIN_BOTTOM_BITS); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":186 + * veb.num_bottom_bits = num_bits/2 + * if veb.num_bottom_bits < MIN_BOTTOM_BITS: + * veb.num_bottom_bits = MIN_BOTTOM_BITS # <<<<<<<<<<<<<< + * veb.top_universe_size = (n >> veb.num_bottom_bits) + 1 + * + */ + __pyx_v_veb->num_bottom_bits = __pyx_v_3_sa_MIN_BOTTOM_BITS; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":187 + * if veb.num_bottom_bits < MIN_BOTTOM_BITS: + * veb.num_bottom_bits = MIN_BOTTOM_BITS + * veb.top_universe_size = (n >> veb.num_bottom_bits) + 1 # <<<<<<<<<<<<<< + * + * veb.bottom = malloc(veb.top_universe_size * sizeof(void*)) + */ + __pyx_v_veb->top_universe_size = ((__pyx_v_n >> __pyx_v_veb->num_bottom_bits) + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":189 + * veb.top_universe_size = (n >> veb.num_bottom_bits) + 1 + * + * veb.bottom = malloc(veb.top_universe_size * sizeof(void*)) # <<<<<<<<<<<<<< + * memset(veb.bottom, 0, veb.top_universe_size * sizeof(void*)) + * + */ + __pyx_v_veb->bottom = ((void **)malloc((__pyx_v_veb->top_universe_size * (sizeof(void *))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":190 + * + * veb.bottom = malloc(veb.top_universe_size * sizeof(void*)) + * memset(veb.bottom, 0, veb.top_universe_size * sizeof(void*)) # <<<<<<<<<<<<<< + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + */ + memset(__pyx_v_veb->bottom, 0, (__pyx_v_veb->top_universe_size * (sizeof(void *)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":192 + * memset(veb.bottom, 0, veb.top_universe_size * sizeof(void*)) + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: # <<<<<<<<<<<<<< + * veb.top = new_VEB(veb.top_universe_size) + * else: + */ + __pyx_t_3 = (__pyx_v_veb->top_universe_size > __pyx_v_3_sa_MIN_BOTTOM_SIZE); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":193 + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * veb.top = new_VEB(veb.top_universe_size) # <<<<<<<<<<<<<< + * else: + * veb.top = new_BitSet() + */ + __pyx_v_veb->top = __pyx_f_3_sa_new_VEB(__pyx_v_veb->top_universe_size); + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":195 + * veb.top = new_VEB(veb.top_universe_size) + * else: + * veb.top = new_BitSet() # <<<<<<<<<<<<<< + * + * veb.max_val = -1 + */ + __pyx_v_veb->top = __pyx_f_3_sa_new_BitSet(); + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":197 + * veb.top = new_BitSet() + * + * veb.max_val = -1 # <<<<<<<<<<<<<< + * veb.min_val = -1 + * veb.size = 0 + */ + __pyx_v_veb->max_val = -1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":198 + * + * veb.max_val = -1 + * veb.min_val = -1 # <<<<<<<<<<<<<< + * veb.size = 0 + * return veb + */ + __pyx_v_veb->min_val = -1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":199 + * veb.max_val = -1 + * veb.min_val = -1 + * veb.size = 0 # <<<<<<<<<<<<<< + * return veb + * + */ + __pyx_v_veb->size = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":200 + * veb.min_val = -1 + * veb.size = 0 + * return veb # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_veb; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("_sa.new_VEB", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":203 + * + * + * cdef int VEB_insert(_VEB* veb, int i): # <<<<<<<<<<<<<< + * cdef _VEB* subv + * cdef _BitSet* subb + */ + +static int __pyx_f_3_sa_VEB_insert(struct __pyx_t_3_sa__VEB *__pyx_v_veb, int __pyx_v_i) { + struct __pyx_t_3_sa__VEB *__pyx_v_subv; + struct __pyx_t_3_sa__BitSet *__pyx_v_subb; + int __pyx_v_a; + int __pyx_v_b; + int __pyx_v_tmp; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("VEB_insert", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":208 + * cdef int a, b, tmp + * + * if veb.size == 0: # <<<<<<<<<<<<<< + * veb.min_val = i + * veb.max_val = i + */ + __pyx_t_1 = (__pyx_v_veb->size == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":209 + * + * if veb.size == 0: + * veb.min_val = i # <<<<<<<<<<<<<< + * veb.max_val = i + * elif i == veb.min_val or i == veb.max_val: + */ + __pyx_v_veb->min_val = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":210 + * if veb.size == 0: + * veb.min_val = i + * veb.max_val = i # <<<<<<<<<<<<<< + * elif i == veb.min_val or i == veb.max_val: + * return 0 + */ + __pyx_v_veb->max_val = __pyx_v_i; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":211 + * veb.min_val = i + * veb.max_val = i + * elif i == veb.min_val or i == veb.max_val: # <<<<<<<<<<<<<< + * return 0 + * else: + */ + __pyx_t_1 = (__pyx_v_i == __pyx_v_veb->min_val); + if (!__pyx_t_1) { + __pyx_t_2 = (__pyx_v_i == __pyx_v_veb->max_val); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":212 + * veb.max_val = i + * elif i == veb.min_val or i == veb.max_val: + * return 0 # <<<<<<<<<<<<<< + * else: + * if i < veb.min_val: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":214 + * return 0 + * else: + * if i < veb.min_val: # <<<<<<<<<<<<<< + * tmp = i + * i = veb.min_val + */ + __pyx_t_3 = (__pyx_v_i < __pyx_v_veb->min_val); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":215 + * else: + * if i < veb.min_val: + * tmp = i # <<<<<<<<<<<<<< + * i = veb.min_val + * veb.min_val = tmp + */ + __pyx_v_tmp = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":216 + * if i < veb.min_val: + * tmp = i + * i = veb.min_val # <<<<<<<<<<<<<< + * veb.min_val = tmp + * a = i >> veb.num_bottom_bits + */ + __pyx_v_i = __pyx_v_veb->min_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":217 + * tmp = i + * i = veb.min_val + * veb.min_val = tmp # <<<<<<<<<<<<<< + * a = i >> veb.num_bottom_bits + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + */ + __pyx_v_veb->min_val = __pyx_v_tmp; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":218 + * i = veb.min_val + * veb.min_val = tmp + * a = i >> veb.num_bottom_bits # <<<<<<<<<<<<<< + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + * if veb.bottom[a] == NULL: + */ + __pyx_v_a = (__pyx_v_i >> __pyx_v_veb->num_bottom_bits); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":219 + * veb.min_val = tmp + * a = i >> veb.num_bottom_bits + * b = i & LOWER_MASK[veb.num_bottom_bits-1] # <<<<<<<<<<<<<< + * if veb.bottom[a] == NULL: + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + */ + __pyx_v_b = (__pyx_v_i & (__pyx_v_3_sa_LOWER_MASK[(__pyx_v_veb->num_bottom_bits - 1)])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":220 + * a = i >> veb.num_bottom_bits + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + * if veb.bottom[a] == NULL: # <<<<<<<<<<<<<< + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * subv = <_VEB*> veb.top + */ + __pyx_t_3 = ((__pyx_v_veb->bottom[__pyx_v_a]) == NULL); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":221 + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + * if veb.bottom[a] == NULL: + * if veb.top_universe_size > MIN_BOTTOM_SIZE: # <<<<<<<<<<<<<< + * subv = <_VEB*> veb.top + * VEB_insert(subv, a) + */ + __pyx_t_3 = (__pyx_v_veb->top_universe_size > __pyx_v_3_sa_MIN_BOTTOM_SIZE); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":222 + * if veb.bottom[a] == NULL: + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * subv = <_VEB*> veb.top # <<<<<<<<<<<<<< + * VEB_insert(subv, a) + * else: + */ + __pyx_v_subv = ((struct __pyx_t_3_sa__VEB *)__pyx_v_veb->top); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":223 + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * subv = <_VEB*> veb.top + * VEB_insert(subv, a) # <<<<<<<<<<<<<< + * else: + * subb = <_BitSet*> veb.top + */ + __pyx_f_3_sa_VEB_insert(__pyx_v_subv, __pyx_v_a); + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":225 + * VEB_insert(subv, a) + * else: + * subb = <_BitSet*> veb.top # <<<<<<<<<<<<<< + * bitset_insert(subb, a) + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + */ + __pyx_v_subb = ((struct __pyx_t_3_sa__BitSet *)__pyx_v_veb->top); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":226 + * else: + * subb = <_BitSet*> veb.top + * bitset_insert(subb, a) # <<<<<<<<<<<<<< + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * veb.bottom[a] = new_VEB(1 << veb.num_bottom_bits) + */ + __pyx_f_3_sa_bitset_insert(__pyx_v_subb, __pyx_v_a); + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":227 + * subb = <_BitSet*> veb.top + * bitset_insert(subb, a) + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< + * veb.bottom[a] = new_VEB(1 << veb.num_bottom_bits) + * else: + */ + __pyx_t_3 = (__pyx_v_veb->num_bottom_bits > __pyx_v_3_sa_MIN_BOTTOM_BITS); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":228 + * bitset_insert(subb, a) + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * veb.bottom[a] = new_VEB(1 << veb.num_bottom_bits) # <<<<<<<<<<<<<< + * else: + * veb.bottom[a] = new_BitSet() + */ + (__pyx_v_veb->bottom[__pyx_v_a]) = __pyx_f_3_sa_new_VEB((1 << __pyx_v_veb->num_bottom_bits)); + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":230 + * veb.bottom[a] = new_VEB(1 << veb.num_bottom_bits) + * else: + * veb.bottom[a] = new_BitSet() # <<<<<<<<<<<<<< + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[a] + */ + (__pyx_v_veb->bottom[__pyx_v_a]) = __pyx_f_3_sa_new_BitSet(); + } + __pyx_L7:; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":231 + * else: + * veb.bottom[a] = new_BitSet() + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< + * subv = <_VEB*> veb.bottom[a] + * if VEB_insert(subv, b) == 0: + */ + __pyx_t_3 = (__pyx_v_veb->num_bottom_bits > __pyx_v_3_sa_MIN_BOTTOM_BITS); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":232 + * veb.bottom[a] = new_BitSet() + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[a] # <<<<<<<<<<<<<< + * if VEB_insert(subv, b) == 0: + * return 0 + */ + __pyx_v_subv = ((struct __pyx_t_3_sa__VEB *)(__pyx_v_veb->bottom[__pyx_v_a])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":233 + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[a] + * if VEB_insert(subv, b) == 0: # <<<<<<<<<<<<<< + * return 0 + * else: + */ + __pyx_t_3 = (__pyx_f_3_sa_VEB_insert(__pyx_v_subv, __pyx_v_b) == 0); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":234 + * subv = <_VEB*> veb.bottom[a] + * if VEB_insert(subv, b) == 0: + * return 0 # <<<<<<<<<<<<<< + * else: + * subb = <_BitSet*> veb.bottom[a] + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L9; + } + __pyx_L9:; + goto __pyx_L8; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":236 + * return 0 + * else: + * subb = <_BitSet*> veb.bottom[a] # <<<<<<<<<<<<<< + * if bitset_insert(subb, b) == 0: + * return 0 + */ + __pyx_v_subb = ((struct __pyx_t_3_sa__BitSet *)(__pyx_v_veb->bottom[__pyx_v_a])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":237 + * else: + * subb = <_BitSet*> veb.bottom[a] + * if bitset_insert(subb, b) == 0: # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_t_3 = (__pyx_f_3_sa_bitset_insert(__pyx_v_subb, __pyx_v_b) == 0); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":238 + * subb = <_BitSet*> veb.bottom[a] + * if bitset_insert(subb, b) == 0: + * return 0 # <<<<<<<<<<<<<< + * + * if i > veb.max_val: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L10; + } + __pyx_L10:; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":240 + * return 0 + * + * if i > veb.max_val: # <<<<<<<<<<<<<< + * veb.max_val = i + * veb.size = veb.size + 1 + */ + __pyx_t_3 = (__pyx_v_i > __pyx_v_veb->max_val); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":241 + * + * if i > veb.max_val: + * veb.max_val = i # <<<<<<<<<<<<<< + * veb.size = veb.size + 1 + * return 1 + */ + __pyx_v_veb->max_val = __pyx_v_i; + goto __pyx_L11; + } + __pyx_L11:; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":242 + * if i > veb.max_val: + * veb.max_val = i + * veb.size = veb.size + 1 # <<<<<<<<<<<<<< + * return 1 + * + */ + __pyx_v_veb->size = (__pyx_v_veb->size + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":243 + * veb.max_val = i + * veb.size = veb.size + 1 + * return 1 # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = 1; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":246 + * + * + * cdef del_VEB(_VEB* veb): # <<<<<<<<<<<<<< + * cdef int i + * + */ + +static PyObject *__pyx_f_3_sa_del_VEB(struct __pyx_t_3_sa__VEB *__pyx_v_veb) { + int __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("del_VEB", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":249 + * cdef int i + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: # <<<<<<<<<<<<<< + * i = (<_VEB*> veb.top).min_val + * else: + */ + __pyx_t_1 = (__pyx_v_veb->top_universe_size > __pyx_v_3_sa_MIN_BOTTOM_SIZE); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":250 + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * i = (<_VEB*> veb.top).min_val # <<<<<<<<<<<<<< + * else: + * i = (<_BitSet*> veb.top).min_val + */ + __pyx_v_i = ((struct __pyx_t_3_sa__VEB *)__pyx_v_veb->top)->min_val; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":252 + * i = (<_VEB*> veb.top).min_val + * else: + * i = (<_BitSet*> veb.top).min_val # <<<<<<<<<<<<<< + * + * while i != -1: + */ + __pyx_v_i = ((struct __pyx_t_3_sa__BitSet *)__pyx_v_veb->top)->min_val; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":254 + * i = (<_BitSet*> veb.top).min_val + * + * while i != -1: # <<<<<<<<<<<<<< + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * del_VEB(<_VEB*> veb.bottom[i]) + */ + while (1) { + __pyx_t_1 = (__pyx_v_i != -1); + if (!__pyx_t_1) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":255 + * + * while i != -1: + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< + * del_VEB(<_VEB*> veb.bottom[i]) + * else: + */ + __pyx_t_1 = (__pyx_v_veb->num_bottom_bits > __pyx_v_3_sa_MIN_BOTTOM_BITS); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":256 + * while i != -1: + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * del_VEB(<_VEB*> veb.bottom[i]) # <<<<<<<<<<<<<< + * else: + * free(<_BitSet*> veb.bottom[i]) + */ + __pyx_t_2 = __pyx_f_3_sa_del_VEB(((struct __pyx_t_3_sa__VEB *)(__pyx_v_veb->bottom[__pyx_v_i]))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":258 + * del_VEB(<_VEB*> veb.bottom[i]) + * else: + * free(<_BitSet*> veb.bottom[i]) # <<<<<<<<<<<<<< + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + */ + free(((struct __pyx_t_3_sa__BitSet *)(__pyx_v_veb->bottom[__pyx_v_i]))); + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":260 + * free(<_BitSet*> veb.bottom[i]) + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: # <<<<<<<<<<<<<< + * i = VEB_findsucc(<_VEB*> veb.top, i) + * else: + */ + __pyx_t_1 = (__pyx_v_veb->top_universe_size > __pyx_v_3_sa_MIN_BOTTOM_SIZE); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":261 + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * i = VEB_findsucc(<_VEB*> veb.top, i) # <<<<<<<<<<<<<< + * else: + * i = bitset_findsucc(<_BitSet*> veb.top, i) + */ + __pyx_v_i = __pyx_f_3_sa_VEB_findsucc(((struct __pyx_t_3_sa__VEB *)__pyx_v_veb->top), __pyx_v_i); + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":263 + * i = VEB_findsucc(<_VEB*> veb.top, i) + * else: + * i = bitset_findsucc(<_BitSet*> veb.top, i) # <<<<<<<<<<<<<< + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + */ + __pyx_v_i = __pyx_f_3_sa_bitset_findsucc(((struct __pyx_t_3_sa__BitSet *)__pyx_v_veb->top), __pyx_v_i); + } + __pyx_L7:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":265 + * i = bitset_findsucc(<_BitSet*> veb.top, i) + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: # <<<<<<<<<<<<<< + * del_VEB(<_VEB*> veb.top) + * else: + */ + __pyx_t_1 = (__pyx_v_veb->top_universe_size > __pyx_v_3_sa_MIN_BOTTOM_SIZE); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":266 + * + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * del_VEB(<_VEB*> veb.top) # <<<<<<<<<<<<<< + * else: + * free(<_BitSet*> veb.top) + */ + __pyx_t_2 = __pyx_f_3_sa_del_VEB(((struct __pyx_t_3_sa__VEB *)__pyx_v_veb->top)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 266; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L8; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":268 + * del_VEB(<_VEB*> veb.top) + * else: + * free(<_BitSet*> veb.top) # <<<<<<<<<<<<<< + * free(veb.bottom) + * free(veb) + */ + free(((struct __pyx_t_3_sa__BitSet *)__pyx_v_veb->top)); + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":269 + * else: + * free(<_BitSet*> veb.top) + * free(veb.bottom) # <<<<<<<<<<<<<< + * free(veb) + * + */ + free(__pyx_v_veb->bottom); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":270 + * free(<_BitSet*> veb.top) + * free(veb.bottom) + * free(veb) # <<<<<<<<<<<<<< + * + * + */ + free(__pyx_v_veb); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_sa.del_VEB", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":273 + * + * + * cdef int VEB_findsucc(_VEB* veb, int i): # <<<<<<<<<<<<<< + * cdef _VEB* subv + * cdef _BitSet* subb + */ + +static int __pyx_f_3_sa_VEB_findsucc(struct __pyx_t_3_sa__VEB *__pyx_v_veb, int __pyx_v_i) { + struct __pyx_t_3_sa__VEB *__pyx_v_subv; + struct __pyx_t_3_sa__BitSet *__pyx_v_subb; + int __pyx_v_a; + int __pyx_v_b; + int __pyx_v_j; + int __pyx_v_c; + int __pyx_v_found; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("VEB_findsucc", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":278 + * cdef int a, b, j, c, found + * + * if veb.max_val == -1 or i>=veb.max_val: # <<<<<<<<<<<<<< + * return -1 + * if i < veb.min_val: + */ + __pyx_t_1 = (__pyx_v_veb->max_val == -1); + if (!__pyx_t_1) { + __pyx_t_2 = (__pyx_v_i >= __pyx_v_veb->max_val); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":279 + * + * if veb.max_val == -1 or i>=veb.max_val: + * return -1 # <<<<<<<<<<<<<< + * if i < veb.min_val: + * return veb.min_val + */ + __pyx_r = -1; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":280 + * if veb.max_val == -1 or i>=veb.max_val: + * return -1 + * if i < veb.min_val: # <<<<<<<<<<<<<< + * return veb.min_val + * + */ + __pyx_t_3 = (__pyx_v_i < __pyx_v_veb->min_val); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":281 + * return -1 + * if i < veb.min_val: + * return veb.min_val # <<<<<<<<<<<<<< + * + * a = i >> veb.num_bottom_bits + */ + __pyx_r = __pyx_v_veb->min_val; + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":283 + * return veb.min_val + * + * a = i >> veb.num_bottom_bits # <<<<<<<<<<<<<< + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + * found = 0 + */ + __pyx_v_a = (__pyx_v_i >> __pyx_v_veb->num_bottom_bits); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":284 + * + * a = i >> veb.num_bottom_bits + * b = i & LOWER_MASK[veb.num_bottom_bits-1] # <<<<<<<<<<<<<< + * found = 0 + * if veb.bottom[a] != NULL: + */ + __pyx_v_b = (__pyx_v_i & (__pyx_v_3_sa_LOWER_MASK[(__pyx_v_veb->num_bottom_bits - 1)])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":285 + * a = i >> veb.num_bottom_bits + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + * found = 0 # <<<<<<<<<<<<<< + * if veb.bottom[a] != NULL: + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + */ + __pyx_v_found = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":286 + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + * found = 0 + * if veb.bottom[a] != NULL: # <<<<<<<<<<<<<< + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[a] + */ + __pyx_t_3 = ((__pyx_v_veb->bottom[__pyx_v_a]) != NULL); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":287 + * found = 0 + * if veb.bottom[a] != NULL: + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< + * subv = <_VEB*> veb.bottom[a] + * if subv.max_val > b: + */ + __pyx_t_3 = (__pyx_v_veb->num_bottom_bits > __pyx_v_3_sa_MIN_BOTTOM_BITS); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":288 + * if veb.bottom[a] != NULL: + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[a] # <<<<<<<<<<<<<< + * if subv.max_val > b: + * j = (a << veb.num_bottom_bits) + VEB_findsucc(subv, b) + */ + __pyx_v_subv = ((struct __pyx_t_3_sa__VEB *)(__pyx_v_veb->bottom[__pyx_v_a])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":289 + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[a] + * if subv.max_val > b: # <<<<<<<<<<<<<< + * j = (a << veb.num_bottom_bits) + VEB_findsucc(subv, b) + * found = 1 + */ + __pyx_t_3 = (__pyx_v_subv->max_val > __pyx_v_b); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":290 + * subv = <_VEB*> veb.bottom[a] + * if subv.max_val > b: + * j = (a << veb.num_bottom_bits) + VEB_findsucc(subv, b) # <<<<<<<<<<<<<< + * found = 1 + * else: + */ + __pyx_v_j = ((__pyx_v_a << __pyx_v_veb->num_bottom_bits) + __pyx_f_3_sa_VEB_findsucc(__pyx_v_subv, __pyx_v_b)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":291 + * if subv.max_val > b: + * j = (a << veb.num_bottom_bits) + VEB_findsucc(subv, b) + * found = 1 # <<<<<<<<<<<<<< + * else: + * subb = <_BitSet*> veb.bottom[a] + */ + __pyx_v_found = 1; + goto __pyx_L7; + } + __pyx_L7:; + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":293 + * found = 1 + * else: + * subb = <_BitSet*> veb.bottom[a] # <<<<<<<<<<<<<< + * if subb.max_val > b: + * j = (a << veb.num_bottom_bits) + bitset_findsucc(subb, b) + */ + __pyx_v_subb = ((struct __pyx_t_3_sa__BitSet *)(__pyx_v_veb->bottom[__pyx_v_a])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":294 + * else: + * subb = <_BitSet*> veb.bottom[a] + * if subb.max_val > b: # <<<<<<<<<<<<<< + * j = (a << veb.num_bottom_bits) + bitset_findsucc(subb, b) + * found = 1 + */ + __pyx_t_3 = (__pyx_v_subb->max_val > __pyx_v_b); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":295 + * subb = <_BitSet*> veb.bottom[a] + * if subb.max_val > b: + * j = (a << veb.num_bottom_bits) + bitset_findsucc(subb, b) # <<<<<<<<<<<<<< + * found = 1 + * if found==0: + */ + __pyx_v_j = ((__pyx_v_a << __pyx_v_veb->num_bottom_bits) + __pyx_f_3_sa_bitset_findsucc(__pyx_v_subb, __pyx_v_b)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":296 + * if subb.max_val > b: + * j = (a << veb.num_bottom_bits) + bitset_findsucc(subb, b) + * found = 1 # <<<<<<<<<<<<<< + * if found==0: + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + */ + __pyx_v_found = 1; + goto __pyx_L8; + } + __pyx_L8:; + } + __pyx_L6:; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":297 + * j = (a << veb.num_bottom_bits) + bitset_findsucc(subb, b) + * found = 1 + * if found==0: # <<<<<<<<<<<<<< + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * subv = <_VEB*> veb.top + */ + __pyx_t_3 = (__pyx_v_found == 0); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":298 + * found = 1 + * if found==0: + * if veb.top_universe_size > MIN_BOTTOM_SIZE: # <<<<<<<<<<<<<< + * subv = <_VEB*> veb.top + * c = VEB_findsucc(subv, a) + */ + __pyx_t_3 = (__pyx_v_veb->top_universe_size > __pyx_v_3_sa_MIN_BOTTOM_SIZE); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":299 + * if found==0: + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * subv = <_VEB*> veb.top # <<<<<<<<<<<<<< + * c = VEB_findsucc(subv, a) + * else: + */ + __pyx_v_subv = ((struct __pyx_t_3_sa__VEB *)__pyx_v_veb->top); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":300 + * if veb.top_universe_size > MIN_BOTTOM_SIZE: + * subv = <_VEB*> veb.top + * c = VEB_findsucc(subv, a) # <<<<<<<<<<<<<< + * else: + * subb = <_BitSet*> veb.top + */ + __pyx_v_c = __pyx_f_3_sa_VEB_findsucc(__pyx_v_subv, __pyx_v_a); + goto __pyx_L10; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":302 + * c = VEB_findsucc(subv, a) + * else: + * subb = <_BitSet*> veb.top # <<<<<<<<<<<<<< + * c = bitset_findsucc(subb, a) + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + */ + __pyx_v_subb = ((struct __pyx_t_3_sa__BitSet *)__pyx_v_veb->top); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":303 + * else: + * subb = <_BitSet*> veb.top + * c = bitset_findsucc(subb, a) # <<<<<<<<<<<<<< + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[c] + */ + __pyx_v_c = __pyx_f_3_sa_bitset_findsucc(__pyx_v_subb, __pyx_v_a); + } + __pyx_L10:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":304 + * subb = <_BitSet*> veb.top + * c = bitset_findsucc(subb, a) + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< + * subv = <_VEB*> veb.bottom[c] + * j = (c << veb.num_bottom_bits) + subv.min_val + */ + __pyx_t_3 = (__pyx_v_veb->num_bottom_bits > __pyx_v_3_sa_MIN_BOTTOM_BITS); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":305 + * c = bitset_findsucc(subb, a) + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[c] # <<<<<<<<<<<<<< + * j = (c << veb.num_bottom_bits) + subv.min_val + * else: + */ + __pyx_v_subv = ((struct __pyx_t_3_sa__VEB *)(__pyx_v_veb->bottom[__pyx_v_c])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":306 + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[c] + * j = (c << veb.num_bottom_bits) + subv.min_val # <<<<<<<<<<<<<< + * else: + * subb = <_BitSet*> veb.bottom[c] + */ + __pyx_v_j = ((__pyx_v_c << __pyx_v_veb->num_bottom_bits) + __pyx_v_subv->min_val); + goto __pyx_L11; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":308 + * j = (c << veb.num_bottom_bits) + subv.min_val + * else: + * subb = <_BitSet*> veb.bottom[c] # <<<<<<<<<<<<<< + * j = (c << veb.num_bottom_bits) + subb.min_val + * return j + */ + __pyx_v_subb = ((struct __pyx_t_3_sa__BitSet *)(__pyx_v_veb->bottom[__pyx_v_c])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":309 + * else: + * subb = <_BitSet*> veb.bottom[c] + * j = (c << veb.num_bottom_bits) + subb.min_val # <<<<<<<<<<<<<< + * return j + * + */ + __pyx_v_j = ((__pyx_v_c << __pyx_v_veb->num_bottom_bits) + __pyx_v_subb->min_val); + } + __pyx_L11:; + goto __pyx_L9; + } + __pyx_L9:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":310 + * subb = <_BitSet*> veb.bottom[c] + * j = (c << veb.num_bottom_bits) + subb.min_val + * return j # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_j; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":313 + * + * + * cdef int VEB_contains(_VEB* veb, int i): # <<<<<<<<<<<<<< + * cdef _VEB* subv + * cdef _BitSet* subb + */ + +static int __pyx_f_3_sa_VEB_contains(struct __pyx_t_3_sa__VEB *__pyx_v_veb, int __pyx_v_i) { + struct __pyx_t_3_sa__VEB *__pyx_v_subv; + struct __pyx_t_3_sa__BitSet *__pyx_v_subb; + int __pyx_v_a; + int __pyx_v_b; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + __Pyx_RefNannySetupContext("VEB_contains", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":318 + * cdef int a, b + * + * if veb.size == 0 or i < veb.min_val or i > veb.max_val: # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_t_1 = (__pyx_v_veb->size == 0); + if (!__pyx_t_1) { + __pyx_t_2 = (__pyx_v_i < __pyx_v_veb->min_val); + if (!__pyx_t_2) { + __pyx_t_3 = (__pyx_v_i > __pyx_v_veb->max_val); + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_2; + } + __pyx_t_2 = __pyx_t_4; + } else { + __pyx_t_2 = __pyx_t_1; + } + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":319 + * + * if veb.size == 0 or i < veb.min_val or i > veb.max_val: + * return 0 # <<<<<<<<<<<<<< + * + * if veb.min_val == i: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":321 + * return 0 + * + * if veb.min_val == i: # <<<<<<<<<<<<<< + * return 1 + * else: + */ + __pyx_t_2 = (__pyx_v_veb->min_val == __pyx_v_i); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":322 + * + * if veb.min_val == i: + * return 1 # <<<<<<<<<<<<<< + * else: + * if veb.size == 1: + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":324 + * return 1 + * else: + * if veb.size == 1: # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_t_2 = (__pyx_v_veb->size == 1); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":325 + * else: + * if veb.size == 1: + * return 0 # <<<<<<<<<<<<<< + * + * a = i >> veb.num_bottom_bits + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":327 + * return 0 + * + * a = i >> veb.num_bottom_bits # <<<<<<<<<<<<<< + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + * if veb.bottom[a] == NULL: + */ + __pyx_v_a = (__pyx_v_i >> __pyx_v_veb->num_bottom_bits); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":328 + * + * a = i >> veb.num_bottom_bits + * b = i & LOWER_MASK[veb.num_bottom_bits-1] # <<<<<<<<<<<<<< + * if veb.bottom[a] == NULL: + * return 0 + */ + __pyx_v_b = (__pyx_v_i & (__pyx_v_3_sa_LOWER_MASK[(__pyx_v_veb->num_bottom_bits - 1)])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":329 + * a = i >> veb.num_bottom_bits + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + * if veb.bottom[a] == NULL: # <<<<<<<<<<<<<< + * return 0 + * else: + */ + __pyx_t_2 = ((__pyx_v_veb->bottom[__pyx_v_a]) == NULL); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":330 + * b = i & LOWER_MASK[veb.num_bottom_bits-1] + * if veb.bottom[a] == NULL: + * return 0 # <<<<<<<<<<<<<< + * else: + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":332 + * return 0 + * else: + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: # <<<<<<<<<<<<<< + * subv = <_VEB*> veb.bottom[a] + * return VEB_contains(subv, b) + */ + __pyx_t_2 = (__pyx_v_veb->num_bottom_bits > __pyx_v_3_sa_MIN_BOTTOM_BITS); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":333 + * else: + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[a] # <<<<<<<<<<<<<< + * return VEB_contains(subv, b) + * else: + */ + __pyx_v_subv = ((struct __pyx_t_3_sa__VEB *)(__pyx_v_veb->bottom[__pyx_v_a])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":334 + * if veb.num_bottom_bits > MIN_BOTTOM_BITS: + * subv = <_VEB*> veb.bottom[a] + * return VEB_contains(subv, b) # <<<<<<<<<<<<<< + * else: + * subb = <_BitSet*> veb.bottom[a] + */ + __pyx_r = __pyx_f_3_sa_VEB_contains(__pyx_v_subv, __pyx_v_b); + goto __pyx_L0; + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":336 + * return VEB_contains(subv, b) + * else: + * subb = <_BitSet*> veb.bottom[a] # <<<<<<<<<<<<<< + * return bitset_contains(subb, b) + * + */ + __pyx_v_subb = ((struct __pyx_t_3_sa__BitSet *)(__pyx_v_veb->bottom[__pyx_v_a])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":337 + * else: + * subb = <_BitSet*> veb.bottom[a] + * return bitset_contains(subb, b) # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_f_3_sa_bitset_contains(__pyx_v_subb, __pyx_v_b); + goto __pyx_L0; + } + __pyx_L7:; + } + __pyx_L6:; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_11VEBIterator_1__next__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_11VEBIterator_1__next__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__next__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_11VEBIterator___next__(((struct __pyx_obj_3_sa_VEBIterator *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":344 + * cdef int next_val + * + * def __next__(self): # <<<<<<<<<<<<<< + * cdef int ret_val + * + */ + +static PyObject *__pyx_pf_3_sa_11VEBIterator___next__(struct __pyx_obj_3_sa_VEBIterator *__pyx_v_self) { + int __pyx_v_ret_val; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__next__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":347 + * cdef int ret_val + * + * if self.next_val == -1: # <<<<<<<<<<<<<< + * raise StopIteration() + * ret_val = self.next_val + */ + __pyx_t_1 = (__pyx_v_self->next_val == -1); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":348 + * + * if self.next_val == -1: + * raise StopIteration() # <<<<<<<<<<<<<< + * ret_val = self.next_val + * self.next_val = VEB_findsucc(self.v, ret_val) + */ + __pyx_t_2 = PyObject_Call(__pyx_builtin_StopIteration, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[6]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":349 + * if self.next_val == -1: + * raise StopIteration() + * ret_val = self.next_val # <<<<<<<<<<<<<< + * self.next_val = VEB_findsucc(self.v, ret_val) + * return ret_val + */ + __pyx_v_ret_val = __pyx_v_self->next_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":350 + * raise StopIteration() + * ret_val = self.next_val + * self.next_val = VEB_findsucc(self.v, ret_val) # <<<<<<<<<<<<<< + * return ret_val + * + */ + __pyx_v_self->next_val = __pyx_f_3_sa_VEB_findsucc(__pyx_v_self->v, __pyx_v_ret_val); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":351 + * ret_val = self.next_val + * self.next_val = VEB_findsucc(self.v, ret_val) + * return ret_val # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyInt_FromLong(__pyx_v_ret_val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_sa.VEBIterator.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_3VEB_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_3VEB_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_size; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__size,0}; + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__size)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 360; __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_size = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 360; __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[6]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.VEB.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_3VEB___cinit__(((struct __pyx_obj_3_sa_VEB *)__pyx_v_self), __pyx_v_size); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":360 + * cdef int _first(self) + * + * def __cinit__(self, int size): # <<<<<<<<<<<<<< + * self.veb = new_VEB(size) + * + */ + +static int __pyx_pf_3_sa_3VEB___cinit__(struct __pyx_obj_3_sa_VEB *__pyx_v_self, int __pyx_v_size) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":361 + * + * def __cinit__(self, int size): + * self.veb = new_VEB(size) # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->veb = __pyx_f_3_sa_new_VEB(__pyx_v_size); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_3_sa_3VEB_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_3_sa_3VEB_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_3_sa_3VEB_2__dealloc__(((struct __pyx_obj_3_sa_VEB *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":363 + * self.veb = new_VEB(size) + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del_VEB(self.veb) + * + */ + +static void __pyx_pf_3_sa_3VEB_2__dealloc__(struct __pyx_obj_3_sa_VEB *__pyx_v_self) { + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":364 + * + * def __dealloc__(self): + * del_VEB(self.veb) # <<<<<<<<<<<<<< + * + * def __iter__(self): + */ + __pyx_t_1 = __pyx_f_3_sa_del_VEB(__pyx_v_self->veb); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_sa.VEB.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_3VEB_5__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_3VEB_5__iter__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_3VEB_4__iter__(((struct __pyx_obj_3_sa_VEB *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":366 + * del_VEB(self.veb) + * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef VEBIterator it + * it = VEBIterator() + */ + +static PyObject *__pyx_pf_3_sa_3VEB_4__iter__(struct __pyx_obj_3_sa_VEB *__pyx_v_self) { + struct __pyx_obj_3_sa_VEBIterator *__pyx_v_it = 0; + 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("__iter__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":368 + * def __iter__(self): + * cdef VEBIterator it + * it = VEBIterator() # <<<<<<<<<<<<<< + * it.v = self.veb + * it.next_val = self.veb.min_val + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_VEBIterator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_it = ((struct __pyx_obj_3_sa_VEBIterator *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":369 + * cdef VEBIterator it + * it = VEBIterator() + * it.v = self.veb # <<<<<<<<<<<<<< + * it.next_val = self.veb.min_val + * return it + */ + __pyx_v_it->v = __pyx_v_self->veb; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":370 + * it = VEBIterator() + * it.v = self.veb + * it.next_val = self.veb.min_val # <<<<<<<<<<<<<< + * return it + * + */ + __pyx_v_it->next_val = __pyx_v_self->veb->min_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":371 + * it.v = self.veb + * it.next_val = self.veb.min_val + * return it # <<<<<<<<<<<<<< + * + * def insert(self, i): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_it)); + __pyx_r = ((PyObject *)__pyx_v_it); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_sa.VEB.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_it); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_3VEB_7insert(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_3_sa_3VEB_7insert(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("insert (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_3VEB_6insert(((struct __pyx_obj_3_sa_VEB *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":373 + * return it + * + * def insert(self, i): # <<<<<<<<<<<<<< + * return VEB_insert(self.veb, i) + * + */ + +static PyObject *__pyx_pf_3_sa_3VEB_6insert(struct __pyx_obj_3_sa_VEB *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("insert", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":374 + * + * def insert(self, i): + * return VEB_insert(self.veb, i) # <<<<<<<<<<<<<< + * + * cdef int _insert(self, int i): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong(__pyx_f_3_sa_VEB_insert(__pyx_v_self->veb, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_sa.VEB.insert", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":376 + * return VEB_insert(self.veb, i) + * + * cdef int _insert(self, int i): # <<<<<<<<<<<<<< + * return VEB_insert(self.veb, i) + * + */ + +static int __pyx_f_3_sa_3VEB__insert(struct __pyx_obj_3_sa_VEB *__pyx_v_self, int __pyx_v_i) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_insert", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":377 + * + * cdef int _insert(self, int i): + * return VEB_insert(self.veb, i) # <<<<<<<<<<<<<< + * + * def findsucc(self, i): + */ + __pyx_r = __pyx_f_3_sa_VEB_insert(__pyx_v_self->veb, __pyx_v_i); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_3VEB_9findsucc(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_3_sa_3VEB_9findsucc(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("findsucc (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_3VEB_8findsucc(((struct __pyx_obj_3_sa_VEB *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":379 + * return VEB_insert(self.veb, i) + * + * def findsucc(self, i): # <<<<<<<<<<<<<< + * return VEB_findsucc(self.veb, i) + * + */ + +static PyObject *__pyx_pf_3_sa_3VEB_8findsucc(struct __pyx_obj_3_sa_VEB *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("findsucc", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":380 + * + * def findsucc(self, i): + * return VEB_findsucc(self.veb, i) # <<<<<<<<<<<<<< + * + * cdef int _first(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong(__pyx_f_3_sa_VEB_findsucc(__pyx_v_self->veb, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 380; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_sa.VEB.findsucc", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":382 + * return VEB_findsucc(self.veb, i) + * + * cdef int _first(self): # <<<<<<<<<<<<<< + * return self.veb.min_val + * + */ + +static int __pyx_f_3_sa_3VEB__first(struct __pyx_obj_3_sa_VEB *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_first", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":383 + * + * cdef int _first(self): + * return self.veb.min_val # <<<<<<<<<<<<<< + * + * cdef int _findsucc(self, int i): + */ + __pyx_r = __pyx_v_self->veb->min_val; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":385 + * return self.veb.min_val + * + * cdef int _findsucc(self, int i): # <<<<<<<<<<<<<< + * return VEB_findsucc(self.veb, i) + * + */ + +static int __pyx_f_3_sa_3VEB__findsucc(struct __pyx_obj_3_sa_VEB *__pyx_v_self, int __pyx_v_i) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("_findsucc", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":386 + * + * cdef int _findsucc(self, int i): + * return VEB_findsucc(self.veb, i) # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + __pyx_r = __pyx_f_3_sa_VEB_findsucc(__pyx_v_self->veb, __pyx_v_i); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_3_sa_3VEB_11__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_3_sa_3VEB_11__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_3VEB_10__len__(((struct __pyx_obj_3_sa_VEB *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":388 + * return VEB_findsucc(self.veb, i) + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.veb.size + * + */ + +static Py_ssize_t __pyx_pf_3_sa_3VEB_10__len__(struct __pyx_obj_3_sa_VEB *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":389 + * + * def __len__(self): + * return self.veb.size # <<<<<<<<<<<<<< + * + * def __contains__(self, i): + */ + __pyx_r = __pyx_v_self->veb->size; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_3VEB_13__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static int __pyx_pw_3_sa_3VEB_13__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_3VEB_12__contains__(((struct __pyx_obj_3_sa_VEB *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":391 + * return self.veb.size + * + * def __contains__(self, i): # <<<<<<<<<<<<<< + * return VEB_contains(self.veb, i) + */ + +static int __pyx_pf_3_sa_3VEB_12__contains__(struct __pyx_obj_3_sa_VEB *__pyx_v_self, PyObject *__pyx_v_i) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__contains__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":392 + * + * def __contains__(self, i): + * return VEB_contains(self.veb, i) # <<<<<<<<<<<<<< + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_f_3_sa_VEB_contains(__pyx_v_self->veb, __pyx_t_1); + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_sa.VEB.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_3LCP_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_3LCP_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + struct __pyx_obj_3_sa_SuffixArray *__pyx_v_sa = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sa,0}; + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sa)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 9; __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_sa = ((struct __pyx_obj_3_sa_SuffixArray *)values[0]); + } + 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[9]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.LCP.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_sa), __pyx_ptype_3_sa_SuffixArray, 1, "sa", 0))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_3_sa_3LCP___cinit__(((struct __pyx_obj_3_sa_LCP *)__pyx_v_self), __pyx_v_sa); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":9 + * cdef IntList lcp + * + * def __cinit__(self, SuffixArray sa): # <<<<<<<<<<<<<< + * cdef int i, k, j, h, n + * cdef IntList rank + */ + +static int __pyx_pf_3_sa_3LCP___cinit__(struct __pyx_obj_3_sa_LCP *__pyx_v_self, struct __pyx_obj_3_sa_SuffixArray *__pyx_v_sa) { + int __pyx_v_i; + int __pyx_v_k; + int __pyx_v_j; + int __pyx_v_h; + int __pyx_v_n; + struct __pyx_obj_3_sa_IntList *__pyx_v_rank = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":13 + * cdef IntList rank + * + * logger.info("Constructing LCP array") # <<<<<<<<<<<<<< + * self.sa = sa + * n = self.sa.sa.len + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_58), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":14 + * + * logger.info("Constructing LCP array") + * self.sa = sa # <<<<<<<<<<<<<< + * n = self.sa.sa.len + * self.lcp = IntList(initial_len=n) + */ + __Pyx_INCREF(((PyObject *)__pyx_v_sa)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_sa)); + __Pyx_GOTREF(__pyx_v_self->sa); + __Pyx_DECREF(((PyObject *)__pyx_v_self->sa)); + __pyx_v_self->sa = __pyx_v_sa; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":15 + * logger.info("Constructing LCP array") + * self.sa = sa + * n = self.sa.sa.len # <<<<<<<<<<<<<< + * self.lcp = IntList(initial_len=n) + * + */ + __pyx_v_n = __pyx_v_self->sa->sa->len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":16 + * self.sa = sa + * n = self.sa.sa.len + * self.lcp = IntList(initial_len=n) # <<<<<<<<<<<<<< + * + * rank = IntList(initial_len=n) + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 16; __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); + __Pyx_GOTREF(__pyx_v_self->lcp); + __Pyx_DECREF(((PyObject *)__pyx_v_self->lcp)); + __pyx_v_self->lcp = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":18 + * self.lcp = IntList(initial_len=n) + * + * rank = IntList(initial_len=n) # <<<<<<<<<<<<<< + * for i from 0 <= i < n: + * rank.arr[sa.sa.arr[i]] = i + */ + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_1 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_v_rank = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":19 + * + * rank = IntList(initial_len=n) + * for i from 0 <= i < n: # <<<<<<<<<<<<<< + * rank.arr[sa.sa.arr[i]] = i + * + */ + __pyx_t_3 = __pyx_v_n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":20 + * rank = IntList(initial_len=n) + * for i from 0 <= i < n: + * rank.arr[sa.sa.arr[i]] = i # <<<<<<<<<<<<<< + * + * h = 0 + */ + (__pyx_v_rank->arr[(__pyx_v_sa->sa->arr[__pyx_v_i])]) = __pyx_v_i; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":22 + * rank.arr[sa.sa.arr[i]] = i + * + * h = 0 # <<<<<<<<<<<<<< + * for i from 0 <= i < n: + * k = rank.arr[i] + */ + __pyx_v_h = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":23 + * + * h = 0 + * for i from 0 <= i < n: # <<<<<<<<<<<<<< + * k = rank.arr[i] + * if k == 0: + */ + __pyx_t_3 = __pyx_v_n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":24 + * h = 0 + * for i from 0 <= i < n: + * k = rank.arr[i] # <<<<<<<<<<<<<< + * if k == 0: + * self.lcp.arr[k] = -1 + */ + __pyx_v_k = (__pyx_v_rank->arr[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":25 + * for i from 0 <= i < n: + * k = rank.arr[i] + * if k == 0: # <<<<<<<<<<<<<< + * self.lcp.arr[k] = -1 + * else: + */ + __pyx_t_4 = (__pyx_v_k == 0); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":26 + * k = rank.arr[i] + * if k == 0: + * self.lcp.arr[k] = -1 # <<<<<<<<<<<<<< + * else: + * j = sa.sa.arr[k-1] + */ + (__pyx_v_self->lcp->arr[__pyx_v_k]) = -1; + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":28 + * self.lcp.arr[k] = -1 + * else: + * j = sa.sa.arr[k-1] # <<<<<<<<<<<<<< + * while i+h < n and j+h < n and sa.darray.data.arr[i+h] == sa.darray.data.arr[j+h]: + * h = h+1 + */ + __pyx_v_j = (__pyx_v_sa->sa->arr[(__pyx_v_k - 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":29 + * else: + * j = sa.sa.arr[k-1] + * while i+h < n and j+h < n and sa.darray.data.arr[i+h] == sa.darray.data.arr[j+h]: # <<<<<<<<<<<<<< + * h = h+1 + * self.lcp.arr[k] = h + */ + while (1) { + __pyx_t_4 = ((__pyx_v_i + __pyx_v_h) < __pyx_v_n); + if (__pyx_t_4) { + __pyx_t_5 = ((__pyx_v_j + __pyx_v_h) < __pyx_v_n); + if (__pyx_t_5) { + __pyx_t_6 = ((__pyx_v_sa->darray->data->arr[(__pyx_v_i + __pyx_v_h)]) == (__pyx_v_sa->darray->data->arr[(__pyx_v_j + __pyx_v_h)])); + __pyx_t_7 = __pyx_t_6; + } else { + __pyx_t_7 = __pyx_t_5; + } + __pyx_t_5 = __pyx_t_7; + } else { + __pyx_t_5 = __pyx_t_4; + } + if (!__pyx_t_5) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":30 + * j = sa.sa.arr[k-1] + * while i+h < n and j+h < n and sa.darray.data.arr[i+h] == sa.darray.data.arr[j+h]: + * h = h+1 # <<<<<<<<<<<<<< + * self.lcp.arr[k] = h + * if h > 0: + */ + __pyx_v_h = (__pyx_v_h + 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":31 + * while i+h < n and j+h < n and sa.darray.data.arr[i+h] == sa.darray.data.arr[j+h]: + * h = h+1 + * self.lcp.arr[k] = h # <<<<<<<<<<<<<< + * if h > 0: + * h = h-1 + */ + (__pyx_v_self->lcp->arr[__pyx_v_k]) = __pyx_v_h; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":32 + * h = h+1 + * self.lcp.arr[k] = h + * if h > 0: # <<<<<<<<<<<<<< + * h = h-1 + * logger.info("LCP array completed") + */ + __pyx_t_5 = (__pyx_v_h > 0); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":33 + * self.lcp.arr[k] = h + * if h > 0: + * h = h-1 # <<<<<<<<<<<<<< + * logger.info("LCP array completed") + * + */ + __pyx_v_h = (__pyx_v_h - 1); + goto __pyx_L10; + } + __pyx_L10:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":34 + * if h > 0: + * h = h-1 + * logger.info("LCP array completed") # <<<<<<<<<<<<<< + * + * def compute_stats(self, int max_n): + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_60), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_sa.LCP.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_rank); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_3_sa_3LCP_4generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_3LCP_3compute_stats(PyObject *__pyx_v_self, PyObject *__pyx_arg_max_n); /*proto*/ +static char __pyx_doc_3_sa_3LCP_2compute_stats[] = "Note: the output of this function is not exact. In\n particular, the frequency associated with each word is \n not guaranteed to be correct. This is due to a bit of\n laxness in the design; the function is intended only to\n obtain a list of the most frequent words; for this \n purpose it is perfectly fine"; +static PyObject *__pyx_pw_3_sa_3LCP_3compute_stats(PyObject *__pyx_v_self, PyObject *__pyx_arg_max_n) { + int __pyx_v_max_n; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("compute_stats (wrapper)", 0); + assert(__pyx_arg_max_n); { + __pyx_v_max_n = __Pyx_PyInt_AsInt(__pyx_arg_max_n); if (unlikely((__pyx_v_max_n == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.LCP.compute_stats", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_3LCP_2compute_stats(((struct __pyx_obj_3_sa_LCP *)__pyx_v_self), ((int)__pyx_v_max_n)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":36 + * logger.info("LCP array completed") + * + * def compute_stats(self, int max_n): # <<<<<<<<<<<<<< + * """Note: the output of this function is not exact. In + * particular, the frequency associated with each word is + */ + +static PyObject *__pyx_pf_3_sa_3LCP_2compute_stats(struct __pyx_obj_3_sa_LCP *__pyx_v_self, int __pyx_v_max_n) { + struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("compute_stats", 0); + __pyx_cur_scope = (struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *)__pyx_ptype_3_sa___pyx_scope_struct__compute_stats->tp_new(__pyx_ptype_3_sa___pyx_scope_struct__compute_stats, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __pyx_cur_scope->__pyx_v_max_n = __pyx_v_max_n; + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_3_sa_3LCP_4generator, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_sa.LCP.compute_stats", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_3_sa_3LCP_4generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *__pyx_cur_scope = ((struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + long __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L26_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[9]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":48 + * cdef VEB veb + * + * N = self.sa.sa.len # <<<<<<<<<<<<<< + * + * ngram_starts = [] + */ + __pyx_cur_scope->__pyx_v_N = __pyx_cur_scope->__pyx_v_self->sa->sa->len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":50 + * N = self.sa.sa.len + * + * ngram_starts = [] # <<<<<<<<<<<<<< + * for n from 0 <= n < max_n: + * ngram_starts.append(IntList(initial_len=N)) + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_cur_scope->__pyx_v_ngram_starts = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":51 + * + * ngram_starts = [] + * for n from 0 <= n < max_n: # <<<<<<<<<<<<<< + * ngram_starts.append(IntList(initial_len=N)) + * + */ + __pyx_t_2 = __pyx_cur_scope->__pyx_v_max_n; + for (__pyx_cur_scope->__pyx_v_n = 0; __pyx_cur_scope->__pyx_v_n < __pyx_t_2; __pyx_cur_scope->__pyx_v_n++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":52 + * ngram_starts = [] + * for n from 0 <= n < max_n: + * ngram_starts.append(IntList(initial_len=N)) # <<<<<<<<<<<<<< + * + * run_start = IntList(initial_len=max_n) + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_4 = PyList_Append(__pyx_cur_scope->__pyx_v_ngram_starts, __pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":54 + * ngram_starts.append(IntList(initial_len=N)) + * + * run_start = IntList(initial_len=max_n) # <<<<<<<<<<<<<< + * veb = VEB(N) + * + */ + __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_t_1 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_max_n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_run_start = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":55 + * + * run_start = IntList(initial_len=max_n) + * veb = VEB(N) # <<<<<<<<<<<<<< + * + * for i from 0 <= i < N: + */ + __pyx_t_1 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_VEB)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_veb = ((struct __pyx_obj_3_sa_VEB *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":57 + * veb = VEB(N) + * + * for i from 0 <= i < N: # <<<<<<<<<<<<<< + * h = self.lcp.arr[i] + * if h < 0: + */ + __pyx_t_2 = __pyx_cur_scope->__pyx_v_N; + for (__pyx_cur_scope->__pyx_v_i = 0; __pyx_cur_scope->__pyx_v_i < __pyx_t_2; __pyx_cur_scope->__pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":58 + * + * for i from 0 <= i < N: + * h = self.lcp.arr[i] # <<<<<<<<<<<<<< + * if h < 0: + * h = 0 + */ + __pyx_cur_scope->__pyx_v_h = (__pyx_cur_scope->__pyx_v_self->lcp->arr[__pyx_cur_scope->__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":59 + * for i from 0 <= i < N: + * h = self.lcp.arr[i] + * if h < 0: # <<<<<<<<<<<<<< + * h = 0 + * for n from h <= n < max_n: + */ + __pyx_t_5 = (__pyx_cur_scope->__pyx_v_h < 0); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":60 + * h = self.lcp.arr[i] + * if h < 0: + * h = 0 # <<<<<<<<<<<<<< + * for n from h <= n < max_n: + * rs = run_start.arr[n] + */ + __pyx_cur_scope->__pyx_v_h = 0; + goto __pyx_L8; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":61 + * if h < 0: + * h = 0 + * for n from h <= n < max_n: # <<<<<<<<<<<<<< + * rs = run_start.arr[n] + * run_start.arr[n] = i + */ + __pyx_t_6 = __pyx_cur_scope->__pyx_v_max_n; + for (__pyx_cur_scope->__pyx_v_n = __pyx_cur_scope->__pyx_v_h; __pyx_cur_scope->__pyx_v_n < __pyx_t_6; __pyx_cur_scope->__pyx_v_n++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":62 + * h = 0 + * for n from h <= n < max_n: + * rs = run_start.arr[n] # <<<<<<<<<<<<<< + * run_start.arr[n] = i + * freq = i - rs + */ + __pyx_cur_scope->__pyx_v_rs = (__pyx_cur_scope->__pyx_v_run_start->arr[__pyx_cur_scope->__pyx_v_n]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":63 + * for n from h <= n < max_n: + * rs = run_start.arr[n] + * run_start.arr[n] = i # <<<<<<<<<<<<<< + * freq = i - rs + * if freq > 1000: # arbitrary, but see note below + */ + (__pyx_cur_scope->__pyx_v_run_start->arr[__pyx_cur_scope->__pyx_v_n]) = __pyx_cur_scope->__pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":64 + * rs = run_start.arr[n] + * run_start.arr[n] = i + * freq = i - rs # <<<<<<<<<<<<<< + * if freq > 1000: # arbitrary, but see note below + * veb._insert(freq) + */ + __pyx_cur_scope->__pyx_v_freq = (__pyx_cur_scope->__pyx_v_i - __pyx_cur_scope->__pyx_v_rs); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":65 + * run_start.arr[n] = i + * freq = i - rs + * if freq > 1000: # arbitrary, but see note below # <<<<<<<<<<<<<< + * veb._insert(freq) + * ngram_start = ngram_starts[n] + */ + __pyx_t_5 = (__pyx_cur_scope->__pyx_v_freq > 1000); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":66 + * freq = i - rs + * if freq > 1000: # arbitrary, but see note below + * veb._insert(freq) # <<<<<<<<<<<<<< + * ngram_start = ngram_starts[n] + * while ngram_start.arr[freq] > 0: + */ + ((struct __pyx_vtabstruct_3_sa_VEB *)__pyx_cur_scope->__pyx_v_veb->__pyx_vtab)->_insert(__pyx_cur_scope->__pyx_v_veb, __pyx_cur_scope->__pyx_v_freq); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":67 + * if freq > 1000: # arbitrary, but see note below + * veb._insert(freq) + * ngram_start = ngram_starts[n] # <<<<<<<<<<<<<< + * while ngram_start.arr[freq] > 0: + * freq = freq + 1 # cheating a bit, should be ok for sparse histogram + */ + __pyx_t_1 = __Pyx_GetItemInt_List(((PyObject *)__pyx_cur_scope->__pyx_v_ngram_starts), __pyx_cur_scope->__pyx_v_n, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_3_sa_IntList))))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram_start)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram_start)); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_ngram_start = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":68 + * veb._insert(freq) + * ngram_start = ngram_starts[n] + * while ngram_start.arr[freq] > 0: # <<<<<<<<<<<<<< + * freq = freq + 1 # cheating a bit, should be ok for sparse histogram + * ngram_start.arr[freq] = rs + */ + while (1) { + __pyx_t_5 = ((__pyx_cur_scope->__pyx_v_ngram_start->arr[__pyx_cur_scope->__pyx_v_freq]) > 0); + if (!__pyx_t_5) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":69 + * ngram_start = ngram_starts[n] + * while ngram_start.arr[freq] > 0: + * freq = freq + 1 # cheating a bit, should be ok for sparse histogram # <<<<<<<<<<<<<< + * ngram_start.arr[freq] = rs + * i = veb.veb.min_val + */ + __pyx_cur_scope->__pyx_v_freq = (__pyx_cur_scope->__pyx_v_freq + 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":70 + * while ngram_start.arr[freq] > 0: + * freq = freq + 1 # cheating a bit, should be ok for sparse histogram + * ngram_start.arr[freq] = rs # <<<<<<<<<<<<<< + * i = veb.veb.min_val + * while i != -1: + */ + (__pyx_cur_scope->__pyx_v_ngram_start->arr[__pyx_cur_scope->__pyx_v_freq]) = __pyx_cur_scope->__pyx_v_rs; + goto __pyx_L11; + } + __pyx_L11:; + } + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":71 + * freq = freq + 1 # cheating a bit, should be ok for sparse histogram + * ngram_start.arr[freq] = rs + * i = veb.veb.min_val # <<<<<<<<<<<<<< + * while i != -1: + * ii = veb._findsucc(i) + */ + __pyx_cur_scope->__pyx_v_i = __pyx_cur_scope->__pyx_v_veb->veb->min_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":72 + * ngram_start.arr[freq] = rs + * i = veb.veb.min_val + * while i != -1: # <<<<<<<<<<<<<< + * ii = veb._findsucc(i) + * for n from 0 <= n < max_n: + */ + while (1) { + __pyx_t_5 = (__pyx_cur_scope->__pyx_v_i != -1); + if (!__pyx_t_5) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":73 + * i = veb.veb.min_val + * while i != -1: + * ii = veb._findsucc(i) # <<<<<<<<<<<<<< + * for n from 0 <= n < max_n: + * ngram_start = ngram_starts[n] + */ + __pyx_cur_scope->__pyx_v_ii = ((struct __pyx_vtabstruct_3_sa_VEB *)__pyx_cur_scope->__pyx_v_veb->__pyx_vtab)->_findsucc(__pyx_cur_scope->__pyx_v_veb, __pyx_cur_scope->__pyx_v_i); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":74 + * while i != -1: + * ii = veb._findsucc(i) + * for n from 0 <= n < max_n: # <<<<<<<<<<<<<< + * ngram_start = ngram_starts[n] + * iii = i + */ + __pyx_t_2 = __pyx_cur_scope->__pyx_v_max_n; + for (__pyx_cur_scope->__pyx_v_n = 0; __pyx_cur_scope->__pyx_v_n < __pyx_t_2; __pyx_cur_scope->__pyx_v_n++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":75 + * ii = veb._findsucc(i) + * for n from 0 <= n < max_n: + * ngram_start = ngram_starts[n] # <<<<<<<<<<<<<< + * iii = i + * rs = ngram_start.arr[iii] + */ + __pyx_t_1 = __Pyx_GetItemInt_List(((PyObject *)__pyx_cur_scope->__pyx_v_ngram_starts), __pyx_cur_scope->__pyx_v_n, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_3_sa_IntList))))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram_start)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram_start)); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_ngram_start = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":76 + * for n from 0 <= n < max_n: + * ngram_start = ngram_starts[n] + * iii = i # <<<<<<<<<<<<<< + * rs = ngram_start.arr[iii] + * while (ii==-1 or iii < ii) and rs != 0: + */ + __pyx_cur_scope->__pyx_v_iii = __pyx_cur_scope->__pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":77 + * ngram_start = ngram_starts[n] + * iii = i + * rs = ngram_start.arr[iii] # <<<<<<<<<<<<<< + * while (ii==-1 or iii < ii) and rs != 0: + * j = self.sa.sa.arr[rs] + */ + __pyx_cur_scope->__pyx_v_rs = (__pyx_cur_scope->__pyx_v_ngram_start->arr[__pyx_cur_scope->__pyx_v_iii]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":78 + * iii = i + * rs = ngram_start.arr[iii] + * while (ii==-1 or iii < ii) and rs != 0: # <<<<<<<<<<<<<< + * j = self.sa.sa.arr[rs] + * valid = 1 + */ + while (1) { + __pyx_t_5 = (__pyx_cur_scope->__pyx_v_ii == -1); + if (!__pyx_t_5) { + __pyx_t_7 = (__pyx_cur_scope->__pyx_v_iii < __pyx_cur_scope->__pyx_v_ii); + __pyx_t_8 = __pyx_t_7; + } else { + __pyx_t_8 = __pyx_t_5; + } + if (__pyx_t_8) { + __pyx_t_5 = (__pyx_cur_scope->__pyx_v_rs != 0); + __pyx_t_7 = __pyx_t_5; + } else { + __pyx_t_7 = __pyx_t_8; + } + if (!__pyx_t_7) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":79 + * rs = ngram_start.arr[iii] + * while (ii==-1 or iii < ii) and rs != 0: + * j = self.sa.sa.arr[rs] # <<<<<<<<<<<<<< + * valid = 1 + * for k from 0 <= k < n+1: + */ + __pyx_cur_scope->__pyx_v_j = (__pyx_cur_scope->__pyx_v_self->sa->sa->arr[__pyx_cur_scope->__pyx_v_rs]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":80 + * while (ii==-1 or iii < ii) and rs != 0: + * j = self.sa.sa.arr[rs] + * valid = 1 # <<<<<<<<<<<<<< + * for k from 0 <= k < n+1: + * if self.sa.darray.data.arr[j+k] < 2: + */ + __pyx_cur_scope->__pyx_v_valid = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":81 + * j = self.sa.sa.arr[rs] + * valid = 1 + * for k from 0 <= k < n+1: # <<<<<<<<<<<<<< + * if self.sa.darray.data.arr[j+k] < 2: + * valid = 0 + */ + __pyx_t_9 = (__pyx_cur_scope->__pyx_v_n + 1); + for (__pyx_cur_scope->__pyx_v_k = 0; __pyx_cur_scope->__pyx_v_k < __pyx_t_9; __pyx_cur_scope->__pyx_v_k++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":82 + * valid = 1 + * for k from 0 <= k < n+1: + * if self.sa.darray.data.arr[j+k] < 2: # <<<<<<<<<<<<<< + * valid = 0 + * if valid: + */ + __pyx_t_7 = ((__pyx_cur_scope->__pyx_v_self->sa->darray->data->arr[(__pyx_cur_scope->__pyx_v_j + __pyx_cur_scope->__pyx_v_k)]) < 2); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":83 + * for k from 0 <= k < n+1: + * if self.sa.darray.data.arr[j+k] < 2: + * valid = 0 # <<<<<<<<<<<<<< + * if valid: + * ngram = tuple([self.sa.darray.data.arr[j+k] for k in range(n+1)]) + */ + __pyx_cur_scope->__pyx_v_valid = 0; + goto __pyx_L22; + } + __pyx_L22:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":84 + * if self.sa.darray.data.arr[j+k] < 2: + * valid = 0 + * if valid: # <<<<<<<<<<<<<< + * ngram = tuple([self.sa.darray.data.arr[j+k] for k in range(n+1)]) + * yield i, n+1, ngram + */ + if (__pyx_cur_scope->__pyx_v_valid) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":85 + * valid = 0 + * if valid: + * ngram = tuple([self.sa.darray.data.arr[j+k] for k in range(n+1)]) # <<<<<<<<<<<<<< + * yield i, n+1, ngram + * iii = iii + 1 + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = (__pyx_cur_scope->__pyx_v_n + 1); + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_9; __pyx_t_6+=1) { + __pyx_cur_scope->__pyx_v_k = __pyx_t_6; + __pyx_t_3 = PyInt_FromLong((__pyx_cur_scope->__pyx_v_self->sa->darray->data->arr[(__pyx_cur_scope->__pyx_v_j + __pyx_cur_scope->__pyx_v_k)])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (unlikely(__Pyx_PyList_Append(__pyx_t_1, (PyObject*)__pyx_t_3))) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __pyx_t_3 = ((PyObject *)PyList_AsTuple(__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_cur_scope->__pyx_v_ngram = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":86 + * if valid: + * ngram = tuple([self.sa.darray.data.arr[j+k] for k in range(n+1)]) + * yield i, n+1, ngram # <<<<<<<<<<<<<< + * iii = iii + 1 + * rs = ngram_start.arr[iii] + */ + __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyInt_FromLong((__pyx_cur_scope->__pyx_v_n + 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram)); + PyTuple_SET_ITEM(__pyx_t_10, 2, ((PyObject *)__pyx_cur_scope->__pyx_v_ngram)); + __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_ngram)); + __pyx_t_3 = 0; + __pyx_t_1 = 0; + __pyx_r = ((PyObject *)__pyx_t_10); + __pyx_t_10 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L26_resume_from_yield:; + __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L23; + } + __pyx_L23:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":87 + * ngram = tuple([self.sa.darray.data.arr[j+k] for k in range(n+1)]) + * yield i, n+1, ngram + * iii = iii + 1 # <<<<<<<<<<<<<< + * rs = ngram_start.arr[iii] + * i = ii + */ + __pyx_cur_scope->__pyx_v_iii = (__pyx_cur_scope->__pyx_v_iii + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":88 + * yield i, n+1, ngram + * iii = iii + 1 + * rs = ngram_start.arr[iii] # <<<<<<<<<<<<<< + * i = ii + */ + __pyx_cur_scope->__pyx_v_rs = (__pyx_cur_scope->__pyx_v_ngram_start->arr[__pyx_cur_scope->__pyx_v_iii]); + } + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":89 + * iii = iii + 1 + * rs = ngram_start.arr[iii] + * i = ii # <<<<<<<<<<<<<< + */ + __pyx_cur_scope->__pyx_v_i = __pyx_cur_scope->__pyx_v_ii; + } + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("compute_stats", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_8Alphabet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_8Alphabet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; + __pyx_r = __pyx_pf_3_sa_8Alphabet___cinit__(((struct __pyx_obj_3_sa_Alphabet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":12 + * cdef dict id2sym + * + * def __cinit__(self): # <<<<<<<<<<<<<< + * self.terminals = StringMap() + * self.nonterminals = StringMap() + */ + +static int __pyx_pf_3_sa_8Alphabet___cinit__(struct __pyx_obj_3_sa_Alphabet *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":13 + * + * def __cinit__(self): + * self.terminals = StringMap() # <<<<<<<<<<<<<< + * self.nonterminals = StringMap() + * self.id2sym = {} + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_StringMap)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->terminals); + __Pyx_DECREF(((PyObject *)__pyx_v_self->terminals)); + __pyx_v_self->terminals = ((struct __pyx_obj_3_sa_StringMap *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":14 + * def __cinit__(self): + * self.terminals = StringMap() + * self.nonterminals = StringMap() # <<<<<<<<<<<<<< + * self.id2sym = {} + * self.first_nonterminal = -1 + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_StringMap)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->nonterminals); + __Pyx_DECREF(((PyObject *)__pyx_v_self->nonterminals)); + __pyx_v_self->nonterminals = ((struct __pyx_obj_3_sa_StringMap *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":15 + * self.terminals = StringMap() + * self.nonterminals = StringMap() + * self.id2sym = {} # <<<<<<<<<<<<<< + * self.first_nonterminal = -1 + * + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_GOTREF(__pyx_v_self->id2sym); + __Pyx_DECREF(((PyObject *)__pyx_v_self->id2sym)); + __pyx_v_self->id2sym = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":16 + * self.nonterminals = StringMap() + * self.id2sym = {} + * self.first_nonterminal = -1 # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->first_nonterminal = -1; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_sa.Alphabet.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_3_sa_8Alphabet_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_3_sa_8Alphabet_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_3_sa_8Alphabet_2__dealloc__(((struct __pyx_obj_3_sa_Alphabet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":18 + * self.first_nonterminal = -1 + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * pass + * + */ + +static void __pyx_pf_3_sa_8Alphabet_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_3_sa_Alphabet *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":21 + * pass + * + * cdef int isvar(self, int sym): # <<<<<<<<<<<<<< + * return sym < 0 + * + */ + +static int __pyx_f_3_sa_8Alphabet_isvar(CYTHON_UNUSED struct __pyx_obj_3_sa_Alphabet *__pyx_v_self, int __pyx_v_sym) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("isvar", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":22 + * + * cdef int isvar(self, int sym): + * return sym < 0 # <<<<<<<<<<<<<< + * + * cdef int isword(self, int sym): + */ + __pyx_r = (__pyx_v_sym < 0); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":24 + * return sym < 0 + * + * cdef int isword(self, int sym): # <<<<<<<<<<<<<< + * return sym >= 0 + * + */ + +static int __pyx_f_3_sa_8Alphabet_isword(CYTHON_UNUSED struct __pyx_obj_3_sa_Alphabet *__pyx_v_self, int __pyx_v_sym) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("isword", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":25 + * + * cdef int isword(self, int sym): + * return sym >= 0 # <<<<<<<<<<<<<< + * + * cdef int getindex(self, int sym): + */ + __pyx_r = (__pyx_v_sym >= 0); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":27 + * return sym >= 0 + * + * cdef int getindex(self, int sym): # <<<<<<<<<<<<<< + * return -sym & INDEX_MASK + * + */ + +static int __pyx_f_3_sa_8Alphabet_getindex(CYTHON_UNUSED struct __pyx_obj_3_sa_Alphabet *__pyx_v_self, int __pyx_v_sym) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getindex", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":28 + * + * cdef int getindex(self, int sym): + * return -sym & INDEX_MASK # <<<<<<<<<<<<<< + * + * cdef int setindex(self, int sym, int ind): + */ + __pyx_r = ((-__pyx_v_sym) & __pyx_v_3_sa_INDEX_MASK); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":30 + * return -sym & INDEX_MASK + * + * cdef int setindex(self, int sym, int ind): # <<<<<<<<<<<<<< + * return -(-sym & ~INDEX_MASK | ind) + * + */ + +static int __pyx_f_3_sa_8Alphabet_setindex(CYTHON_UNUSED struct __pyx_obj_3_sa_Alphabet *__pyx_v_self, int __pyx_v_sym, int __pyx_v_ind) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("setindex", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":31 + * + * cdef int setindex(self, int sym, int ind): + * return -(-sym & ~INDEX_MASK | ind) # <<<<<<<<<<<<<< + * + * cdef int clearindex(self, int sym): + */ + __pyx_r = (-(((-__pyx_v_sym) & (~__pyx_v_3_sa_INDEX_MASK)) | __pyx_v_ind)); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":33 + * return -(-sym & ~INDEX_MASK | ind) + * + * cdef int clearindex(self, int sym): # <<<<<<<<<<<<<< + * return -(-sym& ~INDEX_MASK) + * + */ + +static int __pyx_f_3_sa_8Alphabet_clearindex(CYTHON_UNUSED struct __pyx_obj_3_sa_Alphabet *__pyx_v_self, int __pyx_v_sym) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("clearindex", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":34 + * + * cdef int clearindex(self, int sym): + * return -(-sym& ~INDEX_MASK) # <<<<<<<<<<<<<< + * + * cdef int match(self, int sym1, int sym2): + */ + __pyx_r = (-((-__pyx_v_sym) & (~__pyx_v_3_sa_INDEX_MASK))); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":36 + * return -(-sym& ~INDEX_MASK) + * + * cdef int match(self, int sym1, int sym2): # <<<<<<<<<<<<<< + * return self.clearindex(sym1) == self.clearindex(sym2); + * + */ + +static int __pyx_f_3_sa_8Alphabet_match(struct __pyx_obj_3_sa_Alphabet *__pyx_v_self, int __pyx_v_sym1, int __pyx_v_sym2) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("match", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":37 + * + * cdef int match(self, int sym1, int sym2): + * return self.clearindex(sym1) == self.clearindex(sym2); # <<<<<<<<<<<<<< + * + * cdef char* tocat(self, int sym): + */ + __pyx_r = (((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->clearindex(__pyx_v_self, __pyx_v_sym1) == ((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->clearindex(__pyx_v_self, __pyx_v_sym2)); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":39 + * return self.clearindex(sym1) == self.clearindex(sym2); + * + * cdef char* tocat(self, int sym): # <<<<<<<<<<<<<< + * return self.nonterminals.word((-sym >> INDEX_SHIFT)-1) + * + */ + +static char *__pyx_f_3_sa_8Alphabet_tocat(struct __pyx_obj_3_sa_Alphabet *__pyx_v_self, int __pyx_v_sym) { + char *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("tocat", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":40 + * + * cdef char* tocat(self, int sym): + * return self.nonterminals.word((-sym >> INDEX_SHIFT)-1) # <<<<<<<<<<<<<< + * + * cdef int fromcat(self, char *s): + */ + __pyx_r = ((struct __pyx_vtabstruct_3_sa_StringMap *)__pyx_v_self->nonterminals->__pyx_vtab)->word(__pyx_v_self->nonterminals, (((-__pyx_v_sym) >> __pyx_v_3_sa_INDEX_SHIFT) - 1)); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":42 + * return self.nonterminals.word((-sym >> INDEX_SHIFT)-1) + * + * cdef int fromcat(self, char *s): # <<<<<<<<<<<<<< + * cdef int i + * i = self.nonterminals.index(s) + */ + +static int __pyx_f_3_sa_8Alphabet_fromcat(struct __pyx_obj_3_sa_Alphabet *__pyx_v_self, char *__pyx_v_s) { + int __pyx_v_i; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("fromcat", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":44 + * cdef int fromcat(self, char *s): + * cdef int i + * i = self.nonterminals.index(s) # <<<<<<<<<<<<<< + * if self.first_nonterminal == -1: + * self.first_nonterminal = i + */ + __pyx_v_i = ((struct __pyx_vtabstruct_3_sa_StringMap *)__pyx_v_self->nonterminals->__pyx_vtab)->index(__pyx_v_self->nonterminals, __pyx_v_s); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":45 + * cdef int i + * i = self.nonterminals.index(s) + * if self.first_nonterminal == -1: # <<<<<<<<<<<<<< + * self.first_nonterminal = i + * if i > self.last_nonterminal: + */ + __pyx_t_1 = (__pyx_v_self->first_nonterminal == -1); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":46 + * i = self.nonterminals.index(s) + * if self.first_nonterminal == -1: + * self.first_nonterminal = i # <<<<<<<<<<<<<< + * if i > self.last_nonterminal: + * self.last_nonterminal = i + */ + __pyx_v_self->first_nonterminal = __pyx_v_i; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":47 + * if self.first_nonterminal == -1: + * self.first_nonterminal = i + * if i > self.last_nonterminal: # <<<<<<<<<<<<<< + * self.last_nonterminal = i + * return -(i+1 << INDEX_SHIFT) + */ + __pyx_t_1 = (__pyx_v_i > __pyx_v_self->last_nonterminal); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":48 + * self.first_nonterminal = i + * if i > self.last_nonterminal: + * self.last_nonterminal = i # <<<<<<<<<<<<<< + * return -(i+1 << INDEX_SHIFT) + * + */ + __pyx_v_self->last_nonterminal = __pyx_v_i; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":49 + * if i > self.last_nonterminal: + * self.last_nonterminal = i + * return -(i+1 << INDEX_SHIFT) # <<<<<<<<<<<<<< + * + * cdef char* tostring(self, int sym): + */ + __pyx_r = (-((__pyx_v_i + 1) << __pyx_v_3_sa_INDEX_SHIFT)); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":51 + * return -(i+1 << INDEX_SHIFT) + * + * cdef char* tostring(self, int sym): # <<<<<<<<<<<<<< + * cdef int ind + * if self.isvar(sym): + */ + +static char *__pyx_f_3_sa_8Alphabet_tostring(struct __pyx_obj_3_sa_Alphabet *__pyx_v_self, int __pyx_v_sym) { + int __pyx_v_ind; + char *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + char *__pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("tostring", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":53 + * cdef char* tostring(self, int sym): + * cdef int ind + * if self.isvar(sym): # <<<<<<<<<<<<<< + * if sym in self.id2sym: + * return self.id2sym[sym] + */ + __pyx_t_1 = ((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->isvar(__pyx_v_self, __pyx_v_sym); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":54 + * cdef int ind + * if self.isvar(sym): + * if sym in self.id2sym: # <<<<<<<<<<<<<< + * return self.id2sym[sym] + * ind = self.getindex(sym) + */ + __pyx_t_2 = PyInt_FromLong(__pyx_v_sym); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (unlikely(((PyObject *)__pyx_v_self->id2sym) == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); + {__pyx_filename = __pyx_f[10]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_3 = ((PyDict_Contains(((PyObject *)__pyx_v_self->id2sym), __pyx_t_2))); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":55 + * if self.isvar(sym): + * if sym in self.id2sym: + * return self.id2sym[sym] # <<<<<<<<<<<<<< + * ind = self.getindex(sym) + * if ind > 0: + */ + if (unlikely(((PyObject *)__pyx_v_self->id2sym) == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + {__pyx_filename = __pyx_f[10]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_self->id2sym), __pyx_v_sym, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyBytes_AsString(__pyx_t_2); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_4; + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":56 + * if sym in self.id2sym: + * return self.id2sym[sym] + * ind = self.getindex(sym) # <<<<<<<<<<<<<< + * if ind > 0: + * self.id2sym[sym] = "[%s,%d]" % (self.tocat(sym), ind) + */ + __pyx_v_ind = ((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->getindex(__pyx_v_self, __pyx_v_sym); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":57 + * return self.id2sym[sym] + * ind = self.getindex(sym) + * if ind > 0: # <<<<<<<<<<<<<< + * self.id2sym[sym] = "[%s,%d]" % (self.tocat(sym), ind) + * else: + */ + __pyx_t_3 = (__pyx_v_ind > 0); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":58 + * ind = self.getindex(sym) + * if ind > 0: + * self.id2sym[sym] = "[%s,%d]" % (self.tocat(sym), ind) # <<<<<<<<<<<<<< + * else: + * self.id2sym[sym] = "[%s]" % self.tocat(sym) + */ + __pyx_t_2 = PyBytes_FromString(((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->tocat(__pyx_v_self, __pyx_v_sym)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_5 = PyInt_FromLong(__pyx_v_ind); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_2 = 0; + __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_61), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + if (unlikely(((PyObject *)__pyx_v_self->id2sym) == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + {__pyx_filename = __pyx_f[10]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + if (__Pyx_SetItemInt(((PyObject *)__pyx_v_self->id2sym), __pyx_v_sym, ((PyObject *)__pyx_t_5), sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":60 + * self.id2sym[sym] = "[%s,%d]" % (self.tocat(sym), ind) + * else: + * self.id2sym[sym] = "[%s]" % self.tocat(sym) # <<<<<<<<<<<<<< + * return self.id2sym[sym] + * else: + */ + __pyx_t_5 = PyBytes_FromString(((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->tocat(__pyx_v_self, __pyx_v_sym)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_62), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + if (unlikely(((PyObject *)__pyx_v_self->id2sym) == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + {__pyx_filename = __pyx_f[10]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + if (__Pyx_SetItemInt(((PyObject *)__pyx_v_self->id2sym), __pyx_v_sym, ((PyObject *)__pyx_t_6), sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":61 + * else: + * self.id2sym[sym] = "[%s]" % self.tocat(sym) + * return self.id2sym[sym] # <<<<<<<<<<<<<< + * else: + * return self.terminals.word(sym) + */ + if (unlikely(((PyObject *)__pyx_v_self->id2sym) == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + {__pyx_filename = __pyx_f[10]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_6 = __Pyx_GetItemInt(((PyObject *)__pyx_v_self->id2sym), __pyx_v_sym, sizeof(int), PyInt_FromLong); if (!__pyx_t_6) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = PyBytes_AsString(__pyx_t_6); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_r = __pyx_t_4; + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":63 + * return self.id2sym[sym] + * else: + * return self.terminals.word(sym) # <<<<<<<<<<<<<< + * + * cdef int fromstring(self, char *s, bint terminal): + */ + __pyx_r = ((struct __pyx_vtabstruct_3_sa_StringMap *)__pyx_v_self->terminals->__pyx_vtab)->word(__pyx_v_self->terminals, __pyx_v_sym); + goto __pyx_L0; + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_WriteUnraisable("_sa.Alphabet.tostring", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":65 + * return self.terminals.word(sym) + * + * cdef int fromstring(self, char *s, bint terminal): # <<<<<<<<<<<<<< + * """Warning: this method is allowed to alter s.""" + * cdef char *comma + */ + +static int __pyx_f_3_sa_8Alphabet_fromstring(struct __pyx_obj_3_sa_Alphabet *__pyx_v_self, char *__pyx_v_s, int __pyx_v_terminal) { + char *__pyx_v_comma; + int __pyx_v_n; + char *__pyx_v_sep; + PyObject *__pyx_v_s1 = NULL; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + char *__pyx_t_8; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("fromstring", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":69 + * cdef char *comma + * cdef int n + * n = strlen(s) # <<<<<<<<<<<<<< + * cdef char *sep + * sep = strstr(s,"_SEP_") + */ + __pyx_v_n = strlen(__pyx_v_s); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":71 + * n = strlen(s) + * cdef char *sep + * sep = strstr(s,"_SEP_") # <<<<<<<<<<<<<< + * if n >= 3 and s[0] == c'[' and s[n-1] == c']' and sep == NULL: + * if terminal: + */ + __pyx_v_sep = strstr(__pyx_v_s, __pyx_k___SEP_); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":72 + * cdef char *sep + * sep = strstr(s,"_SEP_") + * if n >= 3 and s[0] == c'[' and s[n-1] == c']' and sep == NULL: # <<<<<<<<<<<<<< + * if terminal: + * s1 = "\\"+s + */ + __pyx_t_1 = (__pyx_v_n >= 3); + if (__pyx_t_1) { + __pyx_t_2 = ((__pyx_v_s[0]) == '['); + if (__pyx_t_2) { + __pyx_t_3 = ((__pyx_v_s[(__pyx_v_n - 1)]) == ']'); + if (__pyx_t_3) { + __pyx_t_4 = (__pyx_v_sep == NULL); + __pyx_t_5 = __pyx_t_4; + } else { + __pyx_t_5 = __pyx_t_3; + } + __pyx_t_3 = __pyx_t_5; + } else { + __pyx_t_3 = __pyx_t_2; + } + __pyx_t_2 = __pyx_t_3; + } else { + __pyx_t_2 = __pyx_t_1; + } + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":73 + * sep = strstr(s,"_SEP_") + * if n >= 3 and s[0] == c'[' and s[n-1] == c']' and sep == NULL: + * if terminal: # <<<<<<<<<<<<<< + * s1 = "\\"+s + * return self.terminals.index(s1) + */ + if (__pyx_v_terminal) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":74 + * if n >= 3 and s[0] == c'[' and s[n-1] == c']' and sep == NULL: + * if terminal: + * s1 = "\\"+s # <<<<<<<<<<<<<< + * return self.terminals.index(s1) + * s[n-1] = c'\0' + */ + __pyx_t_6 = PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + __pyx_t_7 = PyNumber_Add(((PyObject *)__pyx_kp_s_63), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __pyx_v_s1 = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":75 + * if terminal: + * s1 = "\\"+s + * return self.terminals.index(s1) # <<<<<<<<<<<<<< + * s[n-1] = c'\0' + * s = s + 1 + */ + __pyx_t_8 = PyBytes_AsString(__pyx_v_s1); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = ((struct __pyx_vtabstruct_3_sa_StringMap *)__pyx_v_self->terminals->__pyx_vtab)->index(__pyx_v_self->terminals, __pyx_t_8); + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":76 + * s1 = "\\"+s + * return self.terminals.index(s1) + * s[n-1] = c'\0' # <<<<<<<<<<<<<< + * s = s + 1 + * comma = strrchr(s, c',') + */ + (__pyx_v_s[(__pyx_v_n - 1)]) = '\x00'; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":77 + * return self.terminals.index(s1) + * s[n-1] = c'\0' + * s = s + 1 # <<<<<<<<<<<<<< + * comma = strrchr(s, c',') + * if comma != NULL: + */ + __pyx_v_s = (__pyx_v_s + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":78 + * s[n-1] = c'\0' + * s = s + 1 + * comma = strrchr(s, c',') # <<<<<<<<<<<<<< + * if comma != NULL: + * comma[0] = c'\0' + */ + __pyx_v_comma = strrchr(__pyx_v_s, ','); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":79 + * s = s + 1 + * comma = strrchr(s, c',') + * if comma != NULL: # <<<<<<<<<<<<<< + * comma[0] = c'\0' + * return self.setindex(self.fromcat(s), strtol(comma+1, NULL, 10)) + */ + __pyx_t_2 = (__pyx_v_comma != NULL); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":80 + * comma = strrchr(s, c',') + * if comma != NULL: + * comma[0] = c'\0' # <<<<<<<<<<<<<< + * return self.setindex(self.fromcat(s), strtol(comma+1, NULL, 10)) + * else: + */ + (__pyx_v_comma[0]) = '\x00'; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":81 + * if comma != NULL: + * comma[0] = c'\0' + * return self.setindex(self.fromcat(s), strtol(comma+1, NULL, 10)) # <<<<<<<<<<<<<< + * else: + * return self.fromcat(s) + */ + __pyx_r = ((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->setindex(__pyx_v_self, ((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->fromcat(__pyx_v_self, __pyx_v_s), strtol((__pyx_v_comma + 1), NULL, 10)); + goto __pyx_L0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":83 + * return self.setindex(self.fromcat(s), strtol(comma+1, NULL, 10)) + * else: + * return self.fromcat(s) # <<<<<<<<<<<<<< + * else: + * return self.terminals.index(s) + */ + __pyx_r = ((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->fromcat(__pyx_v_self, __pyx_v_s); + goto __pyx_L0; + } + __pyx_L5:; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":85 + * return self.fromcat(s) + * else: + * return self.terminals.index(s) # <<<<<<<<<<<<<< + * + * cdef Alphabet ALPHABET = Alphabet() + */ + __pyx_r = ((struct __pyx_vtabstruct_3_sa_StringMap *)__pyx_v_self->terminals->__pyx_vtab)->index(__pyx_v_self->terminals, __pyx_v_s); + goto __pyx_L0; + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_WriteUnraisable("_sa.Alphabet.fromstring", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_s1); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_8Alphabet_9terminals_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_8Alphabet_9terminals_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_8Alphabet_9terminals___get__(((struct __pyx_obj_3_sa_Alphabet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":8 + * + * cdef class Alphabet: + * cdef readonly StringMap terminals, nonterminals # <<<<<<<<<<<<<< + * cdef int first_nonterminal, last_nonterminal + * cdef dict id2sym + */ + +static PyObject *__pyx_pf_3_sa_8Alphabet_9terminals___get__(struct __pyx_obj_3_sa_Alphabet *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->terminals)); + __pyx_r = ((PyObject *)__pyx_v_self->terminals); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_8Alphabet_12nonterminals_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_8Alphabet_12nonterminals_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_8Alphabet_12nonterminals___get__(((struct __pyx_obj_3_sa_Alphabet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_3_sa_8Alphabet_12nonterminals___get__(struct __pyx_obj_3_sa_Alphabet *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->nonterminals)); + __pyx_r = ((PyObject *)__pyx_v_self->nonterminals); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":89 + * cdef Alphabet ALPHABET = Alphabet() + * + * cdef char* sym_tostring(int sym): # <<<<<<<<<<<<<< + * return ALPHABET.tostring(sym) + * + */ + +static char *__pyx_f_3_sa_sym_tostring(int __pyx_v_sym) { + char *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("sym_tostring", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":90 + * + * cdef char* sym_tostring(int sym): + * return ALPHABET.tostring(sym) # <<<<<<<<<<<<<< + * + * cdef char* sym_tocat(int sym): + */ + __pyx_r = ((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_3_sa_ALPHABET->__pyx_vtab)->tostring(__pyx_v_3_sa_ALPHABET, __pyx_v_sym); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":92 + * return ALPHABET.tostring(sym) + * + * cdef char* sym_tocat(int sym): # <<<<<<<<<<<<<< + * return ALPHABET.tocat(sym) + * + */ + +static char *__pyx_f_3_sa_sym_tocat(int __pyx_v_sym) { + char *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("sym_tocat", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":93 + * + * cdef char* sym_tocat(int sym): + * return ALPHABET.tocat(sym) # <<<<<<<<<<<<<< + * + * cdef int sym_isvar(int sym): + */ + __pyx_r = ((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_3_sa_ALPHABET->__pyx_vtab)->tocat(__pyx_v_3_sa_ALPHABET, __pyx_v_sym); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":95 + * return ALPHABET.tocat(sym) + * + * cdef int sym_isvar(int sym): # <<<<<<<<<<<<<< + * return ALPHABET.isvar(sym) + * + */ + +static int __pyx_f_3_sa_sym_isvar(int __pyx_v_sym) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("sym_isvar", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":96 + * + * cdef int sym_isvar(int sym): + * return ALPHABET.isvar(sym) # <<<<<<<<<<<<<< + * + * cdef int sym_getindex(int sym): + */ + __pyx_r = ((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_3_sa_ALPHABET->__pyx_vtab)->isvar(__pyx_v_3_sa_ALPHABET, __pyx_v_sym); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":98 + * return ALPHABET.isvar(sym) + * + * cdef int sym_getindex(int sym): # <<<<<<<<<<<<<< + * return ALPHABET.getindex(sym) + * + */ + +static int __pyx_f_3_sa_sym_getindex(int __pyx_v_sym) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("sym_getindex", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":99 + * + * cdef int sym_getindex(int sym): + * return ALPHABET.getindex(sym) # <<<<<<<<<<<<<< + * + * cdef int sym_setindex(int sym, int id): + */ + __pyx_r = ((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_3_sa_ALPHABET->__pyx_vtab)->getindex(__pyx_v_3_sa_ALPHABET, __pyx_v_sym); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":101 + * return ALPHABET.getindex(sym) + * + * cdef int sym_setindex(int sym, int id): # <<<<<<<<<<<<<< + * return ALPHABET.setindex(sym, id) + * + */ + +static int __pyx_f_3_sa_sym_setindex(int __pyx_v_sym, int __pyx_v_id) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("sym_setindex", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":102 + * + * cdef int sym_setindex(int sym, int id): + * return ALPHABET.setindex(sym, id) # <<<<<<<<<<<<<< + * + * def sym_fromstring(bytes string, bint terminal): + */ + __pyx_r = ((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_3_sa_ALPHABET->__pyx_vtab)->setindex(__pyx_v_3_sa_ALPHABET, __pyx_v_sym, __pyx_v_id); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_3sym_fromstring(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_3_sa_3sym_fromstring = {__Pyx_NAMESTR("sym_fromstring"), (PyCFunction)__pyx_pw_3_sa_3sym_fromstring, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}; +static PyObject *__pyx_pw_3_sa_3sym_fromstring(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_string = 0; + int __pyx_v_terminal; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("sym_fromstring (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__string,&__pyx_n_s__terminal,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__string)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__terminal)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("sym_fromstring", 1, 2, 2, 1); {__pyx_filename = __pyx_f[10]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sym_fromstring") < 0)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_string = ((PyObject*)values[0]); + __pyx_v_terminal = __Pyx_PyObject_IsTrue(values[1]); if (unlikely((__pyx_v_terminal == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("sym_fromstring", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[10]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.sym_fromstring", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_string), (&PyBytes_Type), 1, "string", 1))) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_3_sa_2sym_fromstring(__pyx_self, __pyx_v_string, __pyx_v_terminal); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":104 + * return ALPHABET.setindex(sym, id) + * + * def sym_fromstring(bytes string, bint terminal): # <<<<<<<<<<<<<< + * return ALPHABET.fromstring(string, terminal) + */ + +static PyObject *__pyx_pf_3_sa_2sym_fromstring(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_string, int __pyx_v_terminal) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + char *__pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("sym_fromstring", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":105 + * + * def sym_fromstring(bytes string, bint terminal): + * return ALPHABET.fromstring(string, terminal) # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_AsString(((PyObject *)__pyx_v_string)); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong(((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_3_sa_ALPHABET->__pyx_vtab)->fromstring(__pyx_v_3_sa_ALPHABET, __pyx_t_1, __pyx_v_terminal)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_sa.sym_fromstring", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_6Phrase_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_6Phrase_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_words = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__words,0}; + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__words)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 6; __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_words = values[0]; + } + 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[7]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.Phrase.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_6Phrase___cinit__(((struct __pyx_obj_3_sa_Phrase *)__pyx_v_self), __pyx_v_words); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":6 + * cdef class Phrase: + * + * def __cinit__(self, words): # <<<<<<<<<<<<<< + * cdef int i, j, n, n_vars + * n_vars = 0 + */ + +static int __pyx_pf_3_sa_6Phrase___cinit__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_words) { + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_n; + int __pyx_v_n_vars; + int __pyx_r; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":8 + * def __cinit__(self, words): + * cdef int i, j, n, n_vars + * n_vars = 0 # <<<<<<<<<<<<<< + * n = len(words) + * self.syms = malloc(n*sizeof(int)) + */ + __pyx_v_n_vars = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":9 + * cdef int i, j, n, n_vars + * n_vars = 0 + * n = len(words) # <<<<<<<<<<<<<< + * self.syms = malloc(n*sizeof(int)) + * for i from 0 <= i < n: + */ + __pyx_t_1 = PyObject_Length(__pyx_v_words); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_n = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":10 + * n_vars = 0 + * n = len(words) + * self.syms = malloc(n*sizeof(int)) # <<<<<<<<<<<<<< + * for i from 0 <= i < n: + * self.syms[i] = words[i] + */ + __pyx_v_self->syms = ((int *)malloc((__pyx_v_n * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":11 + * n = len(words) + * self.syms = malloc(n*sizeof(int)) + * for i from 0 <= i < n: # <<<<<<<<<<<<<< + * self.syms[i] = words[i] + * if sym_isvar(self.syms[i]): + */ + __pyx_t_2 = __pyx_v_n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":12 + * self.syms = malloc(n*sizeof(int)) + * for i from 0 <= i < n: + * self.syms[i] = words[i] # <<<<<<<<<<<<<< + * if sym_isvar(self.syms[i]): + * n_vars += 1 + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_words, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + (__pyx_v_self->syms[__pyx_v_i]) = __pyx_t_4; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":13 + * for i from 0 <= i < n: + * self.syms[i] = words[i] + * if sym_isvar(self.syms[i]): # <<<<<<<<<<<<<< + * n_vars += 1 + * self.n = n + */ + __pyx_t_4 = __pyx_f_3_sa_sym_isvar((__pyx_v_self->syms[__pyx_v_i])); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":14 + * self.syms[i] = words[i] + * if sym_isvar(self.syms[i]): + * n_vars += 1 # <<<<<<<<<<<<<< + * self.n = n + * self.n_vars = n_vars + */ + __pyx_v_n_vars = (__pyx_v_n_vars + 1); + goto __pyx_L5; + } + __pyx_L5:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":15 + * if sym_isvar(self.syms[i]): + * n_vars += 1 + * self.n = n # <<<<<<<<<<<<<< + * self.n_vars = n_vars + * self.varpos = malloc(n_vars*sizeof(int)) + */ + __pyx_v_self->n = __pyx_v_n; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":16 + * n_vars += 1 + * self.n = n + * self.n_vars = n_vars # <<<<<<<<<<<<<< + * self.varpos = malloc(n_vars*sizeof(int)) + * j = 0 + */ + __pyx_v_self->n_vars = __pyx_v_n_vars; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":17 + * self.n = n + * self.n_vars = n_vars + * self.varpos = malloc(n_vars*sizeof(int)) # <<<<<<<<<<<<<< + * j = 0 + * for i from 0 <= i < n: + */ + __pyx_v_self->varpos = ((int *)malloc((__pyx_v_n_vars * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":18 + * self.n_vars = n_vars + * self.varpos = malloc(n_vars*sizeof(int)) + * j = 0 # <<<<<<<<<<<<<< + * for i from 0 <= i < n: + * if sym_isvar(self.syms[i]): + */ + __pyx_v_j = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":19 + * self.varpos = malloc(n_vars*sizeof(int)) + * j = 0 + * for i from 0 <= i < n: # <<<<<<<<<<<<<< + * if sym_isvar(self.syms[i]): + * self.varpos[j] = i + */ + __pyx_t_2 = __pyx_v_n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":20 + * j = 0 + * for i from 0 <= i < n: + * if sym_isvar(self.syms[i]): # <<<<<<<<<<<<<< + * self.varpos[j] = i + * j = j + 1 + */ + __pyx_t_4 = __pyx_f_3_sa_sym_isvar((__pyx_v_self->syms[__pyx_v_i])); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":21 + * for i from 0 <= i < n: + * if sym_isvar(self.syms[i]): + * self.varpos[j] = i # <<<<<<<<<<<<<< + * j = j + 1 + * + */ + (__pyx_v_self->varpos[__pyx_v_j]) = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":22 + * if sym_isvar(self.syms[i]): + * self.varpos[j] = i + * j = j + 1 # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_j = (__pyx_v_j + 1); + goto __pyx_L8; + } + __pyx_L8:; + } + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.Phrase.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_3_sa_6Phrase_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_3_sa_6Phrase_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_3_sa_6Phrase_2__dealloc__(((struct __pyx_obj_3_sa_Phrase *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":24 + * j = j + 1 + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * free(self.syms) + * free(self.varpos) + */ + +static void __pyx_pf_3_sa_6Phrase_2__dealloc__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":25 + * + * def __dealloc__(self): + * free(self.syms) # <<<<<<<<<<<<<< + * free(self.varpos) + * + */ + free(__pyx_v_self->syms); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":26 + * def __dealloc__(self): + * free(self.syms) + * free(self.varpos) # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + free(__pyx_v_self->varpos); + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_6Phrase_5__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_6Phrase_5__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6Phrase_4__str__(((struct __pyx_obj_3_sa_Phrase *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":28 + * free(self.varpos) + * + * def __str__(self): # <<<<<<<<<<<<<< + * strs = [] + * cdef int i, s + */ + +static PyObject *__pyx_pf_3_sa_6Phrase_4__str__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self) { + PyObject *__pyx_v_strs = NULL; + int __pyx_v_i; + int __pyx_v_s; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__str__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":29 + * + * def __str__(self): + * strs = [] # <<<<<<<<<<<<<< + * cdef int i, s + * for i from 0 <= i < self.n: + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_strs = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":31 + * strs = [] + * cdef int i, s + * for i from 0 <= i < self.n: # <<<<<<<<<<<<<< + * s = self.syms[i] + * strs.append(sym_tostring(s)) + */ + __pyx_t_2 = __pyx_v_self->n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":32 + * cdef int i, s + * for i from 0 <= i < self.n: + * s = self.syms[i] # <<<<<<<<<<<<<< + * strs.append(sym_tostring(s)) + * return " ".join(strs) + */ + __pyx_v_s = (__pyx_v_self->syms[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":33 + * for i from 0 <= i < self.n: + * s = self.syms[i] + * strs.append(sym_tostring(s)) # <<<<<<<<<<<<<< + * return " ".join(strs) + * + */ + __pyx_t_1 = PyBytes_FromString(__pyx_f_3_sa_sym_tostring(__pyx_v_s)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_3 = PyList_Append(__pyx_v_strs, ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":34 + * s = self.syms[i] + * strs.append(sym_tostring(s)) + * return " ".join(strs) # <<<<<<<<<<<<<< + * + * def handle(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_64), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(((PyObject *)__pyx_v_strs)); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_strs)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_strs)); + __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 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_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_sa.Phrase.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_strs); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_6Phrase_7handle(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_3_sa_6Phrase_6handle[] = "return a hashable representation that normalizes the ordering\n of the nonterminal indices"; +static PyObject *__pyx_pw_3_sa_6Phrase_7handle(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("handle (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6Phrase_6handle(((struct __pyx_obj_3_sa_Phrase *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":36 + * return " ".join(strs) + * + * def handle(self): # <<<<<<<<<<<<<< + * """return a hashable representation that normalizes the ordering + * of the nonterminal indices""" + */ + +static PyObject *__pyx_pf_3_sa_6Phrase_6handle(struct __pyx_obj_3_sa_Phrase *__pyx_v_self) { + PyObject *__pyx_v_norm = NULL; + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_s; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("handle", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":39 + * """return a hashable representation that normalizes the ordering + * of the nonterminal indices""" + * norm = [] # <<<<<<<<<<<<<< + * cdef int i, j, s + * i = 1 + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_norm = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":41 + * norm = [] + * cdef int i, j, s + * i = 1 # <<<<<<<<<<<<<< + * j = 0 + * for j from 0 <= j < self.n: + */ + __pyx_v_i = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":42 + * cdef int i, j, s + * i = 1 + * j = 0 # <<<<<<<<<<<<<< + * for j from 0 <= j < self.n: + * s = self.syms[j] + */ + __pyx_v_j = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":43 + * i = 1 + * j = 0 + * for j from 0 <= j < self.n: # <<<<<<<<<<<<<< + * s = self.syms[j] + * if sym_isvar(s): + */ + __pyx_t_2 = __pyx_v_self->n; + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_2; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":44 + * j = 0 + * for j from 0 <= j < self.n: + * s = self.syms[j] # <<<<<<<<<<<<<< + * if sym_isvar(s): + * s = sym_setindex(s,i) + */ + __pyx_v_s = (__pyx_v_self->syms[__pyx_v_j]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":45 + * for j from 0 <= j < self.n: + * s = self.syms[j] + * if sym_isvar(s): # <<<<<<<<<<<<<< + * s = sym_setindex(s,i) + * i = i + 1 + */ + __pyx_t_3 = __pyx_f_3_sa_sym_isvar(__pyx_v_s); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":46 + * s = self.syms[j] + * if sym_isvar(s): + * s = sym_setindex(s,i) # <<<<<<<<<<<<<< + * i = i + 1 + * norm.append(s) + */ + __pyx_v_s = __pyx_f_3_sa_sym_setindex(__pyx_v_s, __pyx_v_i); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":47 + * if sym_isvar(s): + * s = sym_setindex(s,i) + * i = i + 1 # <<<<<<<<<<<<<< + * norm.append(s) + * return tuple(norm) + */ + __pyx_v_i = (__pyx_v_i + 1); + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":48 + * s = sym_setindex(s,i) + * i = i + 1 + * norm.append(s) # <<<<<<<<<<<<<< + * return tuple(norm) + * + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_s); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyList_Append(__pyx_v_norm, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":49 + * i = i + 1 + * norm.append(s) + * return tuple(norm) # <<<<<<<<<<<<<< + * + * def strhandle(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = ((PyObject *)PyList_AsTuple(__pyx_v_norm)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 49; __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("_sa.Phrase.handle", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_norm); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_6Phrase_9strhandle(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_3_sa_6Phrase_9strhandle(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("strhandle (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6Phrase_8strhandle(((struct __pyx_obj_3_sa_Phrase *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":51 + * return tuple(norm) + * + * def strhandle(self): # <<<<<<<<<<<<<< + * strs = [] + * norm = [] + */ + +static PyObject *__pyx_pf_3_sa_6Phrase_8strhandle(struct __pyx_obj_3_sa_Phrase *__pyx_v_self) { + CYTHON_UNUSED PyObject *__pyx_v_strs = NULL; + PyObject *__pyx_v_norm = NULL; + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_s; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("strhandle", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":52 + * + * def strhandle(self): + * strs = [] # <<<<<<<<<<<<<< + * norm = [] + * cdef int i, j, s + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_strs = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":53 + * def strhandle(self): + * strs = [] + * norm = [] # <<<<<<<<<<<<<< + * cdef int i, j, s + * i = 1 + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_norm = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":55 + * norm = [] + * cdef int i, j, s + * i = 1 # <<<<<<<<<<<<<< + * j = 0 + * for j from 0 <= j < self.n: + */ + __pyx_v_i = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":56 + * cdef int i, j, s + * i = 1 + * j = 0 # <<<<<<<<<<<<<< + * for j from 0 <= j < self.n: + * s = self.syms[j] + */ + __pyx_v_j = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":57 + * i = 1 + * j = 0 + * for j from 0 <= j < self.n: # <<<<<<<<<<<<<< + * s = self.syms[j] + * if sym_isvar(s): + */ + __pyx_t_2 = __pyx_v_self->n; + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_2; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":58 + * j = 0 + * for j from 0 <= j < self.n: + * s = self.syms[j] # <<<<<<<<<<<<<< + * if sym_isvar(s): + * s = sym_setindex(s,i) + */ + __pyx_v_s = (__pyx_v_self->syms[__pyx_v_j]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":59 + * for j from 0 <= j < self.n: + * s = self.syms[j] + * if sym_isvar(s): # <<<<<<<<<<<<<< + * s = sym_setindex(s,i) + * i = i + 1 + */ + __pyx_t_3 = __pyx_f_3_sa_sym_isvar(__pyx_v_s); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":60 + * s = self.syms[j] + * if sym_isvar(s): + * s = sym_setindex(s,i) # <<<<<<<<<<<<<< + * i = i + 1 + * norm.append(sym_tostring(s)) + */ + __pyx_v_s = __pyx_f_3_sa_sym_setindex(__pyx_v_s, __pyx_v_i); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":61 + * if sym_isvar(s): + * s = sym_setindex(s,i) + * i = i + 1 # <<<<<<<<<<<<<< + * norm.append(sym_tostring(s)) + * return " ".join(norm) + */ + __pyx_v_i = (__pyx_v_i + 1); + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":62 + * s = sym_setindex(s,i) + * i = i + 1 + * norm.append(sym_tostring(s)) # <<<<<<<<<<<<<< + * return " ".join(norm) + * + */ + __pyx_t_1 = PyBytes_FromString(__pyx_f_3_sa_sym_tostring(__pyx_v_s)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_4 = PyList_Append(__pyx_v_norm, ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":63 + * i = i + 1 + * norm.append(sym_tostring(s)) + * return " ".join(norm) # <<<<<<<<<<<<<< + * + * def arity(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_64), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(((PyObject *)__pyx_v_norm)); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_norm)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_norm)); + __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_r = __pyx_t_6; + __pyx_t_6 = 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_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_sa.Phrase.strhandle", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_strs); + __Pyx_XDECREF(__pyx_v_norm); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_6Phrase_11arity(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_3_sa_6Phrase_11arity(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("arity (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6Phrase_10arity(((struct __pyx_obj_3_sa_Phrase *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":65 + * return " ".join(norm) + * + * def arity(self): # <<<<<<<<<<<<<< + * return self.n_vars + * + */ + +static PyObject *__pyx_pf_3_sa_6Phrase_10arity(struct __pyx_obj_3_sa_Phrase *__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("arity", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":66 + * + * def arity(self): + * return self.n_vars # <<<<<<<<<<<<<< + * + * def getvarpos(self, i): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->n_vars); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_sa.Phrase.arity", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_6Phrase_13getvarpos(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_3_sa_6Phrase_13getvarpos(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getvarpos (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6Phrase_12getvarpos(((struct __pyx_obj_3_sa_Phrase *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":68 + * return self.n_vars + * + * def getvarpos(self, i): # <<<<<<<<<<<<<< + * if 0 <= i < self.n_vars: + * return self.varpos[i] + */ + +static PyObject *__pyx_pf_3_sa_6Phrase_12getvarpos(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + Py_ssize_t __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("getvarpos", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":69 + * + * def getvarpos(self, i): + * if 0 <= i < self.n_vars: # <<<<<<<<<<<<<< + * return self.varpos[i] + * else: + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_int_0, __pyx_v_i, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_PyObject_IsTrue(__pyx_t_1)) { + __Pyx_DECREF(__pyx_t_1); + __pyx_t_2 = PyInt_FromLong(__pyx_v_self->n_vars); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_RichCompare(__pyx_v_i, __pyx_t_2, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":70 + * def getvarpos(self, i): + * if 0 <= i < self.n_vars: + * return self.varpos[i] # <<<<<<<<<<<<<< + * else: + * raise IndexError + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyInt_FromLong((__pyx_v_self->varpos[__pyx_t_4])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":72 + * return self.varpos[i] + * else: + * raise IndexError # <<<<<<<<<<<<<< + * + * def getvar(self, i): + */ + __Pyx_Raise(__pyx_builtin_IndexError, 0, 0, 0); + {__pyx_filename = __pyx_f[7]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; + + __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("_sa.Phrase.getvarpos", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_6Phrase_15getvar(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_3_sa_6Phrase_15getvar(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getvar (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6Phrase_14getvar(((struct __pyx_obj_3_sa_Phrase *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":74 + * raise IndexError + * + * def getvar(self, i): # <<<<<<<<<<<<<< + * if 0 <= i < self.n_vars: + * return self.syms[self.varpos[i]] + */ + +static PyObject *__pyx_pf_3_sa_6Phrase_14getvar(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + Py_ssize_t __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("getvar", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":75 + * + * def getvar(self, i): + * if 0 <= i < self.n_vars: # <<<<<<<<<<<<<< + * return self.syms[self.varpos[i]] + * else: + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_int_0, __pyx_v_i, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_PyObject_IsTrue(__pyx_t_1)) { + __Pyx_DECREF(__pyx_t_1); + __pyx_t_2 = PyInt_FromLong(__pyx_v_self->n_vars); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_RichCompare(__pyx_v_i, __pyx_t_2, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":76 + * def getvar(self, i): + * if 0 <= i < self.n_vars: + * return self.syms[self.varpos[i]] # <<<<<<<<<<<<<< + * else: + * raise IndexError + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyInt_FromLong((__pyx_v_self->syms[(__pyx_v_self->varpos[__pyx_t_4])])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":78 + * return self.syms[self.varpos[i]] + * else: + * raise IndexError # <<<<<<<<<<<<<< + * + * cdef int chunkpos(self, int k): + */ + __Pyx_Raise(__pyx_builtin_IndexError, 0, 0, 0); + {__pyx_filename = __pyx_f[7]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; + + __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("_sa.Phrase.getvar", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":80 + * raise IndexError + * + * cdef int chunkpos(self, int k): # <<<<<<<<<<<<<< + * if k == 0: + * return 0 + */ + +int __pyx_f_3_sa_6Phrase_chunkpos(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, int __pyx_v_k) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("chunkpos", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":81 + * + * cdef int chunkpos(self, int k): + * if k == 0: # <<<<<<<<<<<<<< + * return 0 + * else: + */ + __pyx_t_1 = (__pyx_v_k == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":82 + * cdef int chunkpos(self, int k): + * if k == 0: + * return 0 # <<<<<<<<<<<<<< + * else: + * return self.varpos[k-1]+1 + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":84 + * return 0 + * else: + * return self.varpos[k-1]+1 # <<<<<<<<<<<<<< + * + * cdef int chunklen(self, int k): + */ + __pyx_r = ((__pyx_v_self->varpos[(__pyx_v_k - 1)]) + 1); + goto __pyx_L0; + } + __pyx_L3:; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":86 + * return self.varpos[k-1]+1 + * + * cdef int chunklen(self, int k): # <<<<<<<<<<<<<< + * if self.n_vars == 0: + * return self.n + */ + +int __pyx_f_3_sa_6Phrase_chunklen(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, int __pyx_v_k) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("chunklen", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":87 + * + * cdef int chunklen(self, int k): + * if self.n_vars == 0: # <<<<<<<<<<<<<< + * return self.n + * elif k == 0: + */ + __pyx_t_1 = (__pyx_v_self->n_vars == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":88 + * cdef int chunklen(self, int k): + * if self.n_vars == 0: + * return self.n # <<<<<<<<<<<<<< + * elif k == 0: + * return self.varpos[0] + */ + __pyx_r = __pyx_v_self->n; + goto __pyx_L0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":89 + * if self.n_vars == 0: + * return self.n + * elif k == 0: # <<<<<<<<<<<<<< + * return self.varpos[0] + * elif k == self.n_vars: + */ + __pyx_t_1 = (__pyx_v_k == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":90 + * return self.n + * elif k == 0: + * return self.varpos[0] # <<<<<<<<<<<<<< + * elif k == self.n_vars: + * return self.n-self.varpos[k-1]-1 + */ + __pyx_r = (__pyx_v_self->varpos[0]); + goto __pyx_L0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":91 + * elif k == 0: + * return self.varpos[0] + * elif k == self.n_vars: # <<<<<<<<<<<<<< + * return self.n-self.varpos[k-1]-1 + * else: + */ + __pyx_t_1 = (__pyx_v_k == __pyx_v_self->n_vars); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":92 + * return self.varpos[0] + * elif k == self.n_vars: + * return self.n-self.varpos[k-1]-1 # <<<<<<<<<<<<<< + * else: + * return self.varpos[k]-self.varpos[k-1]-1 + */ + __pyx_r = ((__pyx_v_self->n - (__pyx_v_self->varpos[(__pyx_v_k - 1)])) - 1); + goto __pyx_L0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":94 + * return self.n-self.varpos[k-1]-1 + * else: + * return self.varpos[k]-self.varpos[k-1]-1 # <<<<<<<<<<<<<< + * + * def clen(self, k): + */ + __pyx_r = (((__pyx_v_self->varpos[__pyx_v_k]) - (__pyx_v_self->varpos[(__pyx_v_k - 1)])) - 1); + goto __pyx_L0; + } + __pyx_L3:; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_6Phrase_17clen(PyObject *__pyx_v_self, PyObject *__pyx_v_k); /*proto*/ +static PyObject *__pyx_pw_3_sa_6Phrase_17clen(PyObject *__pyx_v_self, PyObject *__pyx_v_k) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("clen (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6Phrase_16clen(((struct __pyx_obj_3_sa_Phrase *)__pyx_v_self), ((PyObject *)__pyx_v_k)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":96 + * return self.varpos[k]-self.varpos[k-1]-1 + * + * def clen(self, k): # <<<<<<<<<<<<<< + * return self.chunklen(k) + * + */ + +static PyObject *__pyx_pf_3_sa_6Phrase_16clen(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_k) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("clen", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":97 + * + * def clen(self, k): + * return self.chunklen(k) # <<<<<<<<<<<<<< + * + * def getchunk(self, ci): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_k); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong(((struct __pyx_vtabstruct_3_sa_Phrase *)__pyx_v_self->__pyx_vtab)->chunklen(__pyx_v_self, __pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_sa.Phrase.clen", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_6Phrase_19getchunk(PyObject *__pyx_v_self, PyObject *__pyx_v_ci); /*proto*/ +static PyObject *__pyx_pw_3_sa_6Phrase_19getchunk(PyObject *__pyx_v_self, PyObject *__pyx_v_ci) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getchunk (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6Phrase_18getchunk(((struct __pyx_obj_3_sa_Phrase *)__pyx_v_self), ((PyObject *)__pyx_v_ci)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":99 + * return self.chunklen(k) + * + * def getchunk(self, ci): # <<<<<<<<<<<<<< + * cdef int start, stop + * start = self.chunkpos(ci) + */ + +static PyObject *__pyx_pf_3_sa_6Phrase_18getchunk(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_ci) { + int __pyx_v_start; + int __pyx_v_stop; + PyObject *__pyx_v_chunk = NULL; + int __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("getchunk", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":101 + * def getchunk(self, ci): + * cdef int start, stop + * start = self.chunkpos(ci) # <<<<<<<<<<<<<< + * stop = start+self.chunklen(ci) + * chunk = [] + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_ci); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_start = ((struct __pyx_vtabstruct_3_sa_Phrase *)__pyx_v_self->__pyx_vtab)->chunkpos(__pyx_v_self, __pyx_t_1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":102 + * cdef int start, stop + * start = self.chunkpos(ci) + * stop = start+self.chunklen(ci) # <<<<<<<<<<<<<< + * chunk = [] + * for i from start <= i < stop: + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_ci); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_stop = (__pyx_v_start + ((struct __pyx_vtabstruct_3_sa_Phrase *)__pyx_v_self->__pyx_vtab)->chunklen(__pyx_v_self, __pyx_t_1)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":103 + * start = self.chunkpos(ci) + * stop = start+self.chunklen(ci) + * chunk = [] # <<<<<<<<<<<<<< + * for i from start <= i < stop: + * chunk.append(self.syms[i]) + */ + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_chunk = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":104 + * stop = start+self.chunklen(ci) + * chunk = [] + * for i from start <= i < stop: # <<<<<<<<<<<<<< + * chunk.append(self.syms[i]) + * return chunk + */ + __pyx_t_1 = __pyx_v_stop; + for (__pyx_v_i = __pyx_v_start; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":105 + * chunk = [] + * for i from start <= i < stop: + * chunk.append(self.syms[i]) # <<<<<<<<<<<<<< + * return chunk + * + */ + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->syms[__pyx_v_i])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyList_Append(__pyx_v_chunk, __pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":106 + * for i from start <= i < stop: + * chunk.append(self.syms[i]) + * return chunk # <<<<<<<<<<<<<< + * + * def __cmp__(self, other): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_chunk)); + __pyx_r = ((PyObject *)__pyx_v_chunk); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_sa.Phrase.getchunk", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_chunk); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +#if PY_MAJOR_VERSION < 3 +static int __pyx_pw_3_sa_6Phrase_21__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static int __pyx_pw_3_sa_6Phrase_21__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cmp__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6Phrase_20__cmp__(((struct __pyx_obj_3_sa_Phrase *)__pyx_v_self), ((PyObject *)__pyx_v_other)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +#endif /*!(#if PY_MAJOR_VERSION < 3)*/ + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":108 + * return chunk + * + * def __cmp__(self, other): # <<<<<<<<<<<<<< + * cdef Phrase otherp + * cdef int i + */ + +#if PY_MAJOR_VERSION < 3 +static int __pyx_pf_3_sa_6Phrase_20__cmp__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_other) { + struct __pyx_obj_3_sa_Phrase *__pyx_v_otherp = 0; + int __pyx_v_i; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cmp__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":111 + * cdef Phrase otherp + * cdef int i + * otherp = other # <<<<<<<<<<<<<< + * for i from 0 <= i < min(self.n, otherp.n): + * if self.syms[i] < otherp.syms[i]: + */ + if (!(likely(((__pyx_v_other) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_other, __pyx_ptype_3_sa_Phrase))))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_other); + __pyx_v_otherp = ((struct __pyx_obj_3_sa_Phrase *)__pyx_v_other); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":112 + * cdef int i + * otherp = other + * for i from 0 <= i < min(self.n, otherp.n): # <<<<<<<<<<<<<< + * if self.syms[i] < otherp.syms[i]: + * return -1 + */ + __pyx_t_1 = __pyx_v_otherp->n; + __pyx_t_2 = __pyx_v_self->n; + if ((__pyx_t_1 < __pyx_t_2)) { + __pyx_t_3 = __pyx_t_1; + } else { + __pyx_t_3 = __pyx_t_2; + } + __pyx_t_1 = __pyx_t_3; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":113 + * otherp = other + * for i from 0 <= i < min(self.n, otherp.n): + * if self.syms[i] < otherp.syms[i]: # <<<<<<<<<<<<<< + * return -1 + * elif self.syms[i] > otherp.syms[i]: + */ + __pyx_t_4 = ((__pyx_v_self->syms[__pyx_v_i]) < (__pyx_v_otherp->syms[__pyx_v_i])); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":114 + * for i from 0 <= i < min(self.n, otherp.n): + * if self.syms[i] < otherp.syms[i]: + * return -1 # <<<<<<<<<<<<<< + * elif self.syms[i] > otherp.syms[i]: + * return 1 + */ + __pyx_r = -1; + goto __pyx_L0; + goto __pyx_L5; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":115 + * if self.syms[i] < otherp.syms[i]: + * return -1 + * elif self.syms[i] > otherp.syms[i]: # <<<<<<<<<<<<<< + * return 1 + * if self.n < otherp.n: + */ + __pyx_t_4 = ((__pyx_v_self->syms[__pyx_v_i]) > (__pyx_v_otherp->syms[__pyx_v_i])); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":116 + * return -1 + * elif self.syms[i] > otherp.syms[i]: + * return 1 # <<<<<<<<<<<<<< + * if self.n < otherp.n: + * return -1 + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":117 + * elif self.syms[i] > otherp.syms[i]: + * return 1 + * if self.n < otherp.n: # <<<<<<<<<<<<<< + * return -1 + * elif self.n > otherp.n: + */ + __pyx_t_4 = (__pyx_v_self->n < __pyx_v_otherp->n); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":118 + * return 1 + * if self.n < otherp.n: + * return -1 # <<<<<<<<<<<<<< + * elif self.n > otherp.n: + * return 1 + */ + __pyx_r = -1; + goto __pyx_L0; + goto __pyx_L6; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":119 + * if self.n < otherp.n: + * return -1 + * elif self.n > otherp.n: # <<<<<<<<<<<<<< + * return 1 + * else: + */ + __pyx_t_4 = (__pyx_v_self->n > __pyx_v_otherp->n); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":120 + * return -1 + * elif self.n > otherp.n: + * return 1 # <<<<<<<<<<<<<< + * else: + * return 0 + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":122 + * return 1 + * else: + * return 0 # <<<<<<<<<<<<<< + * + * def __hash__(self): + */ + __pyx_r = 0; + goto __pyx_L0; + } + __pyx_L6:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_sa.Phrase.__cmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_otherp); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +#endif /*!(#if PY_MAJOR_VERSION < 3)*/ + +/* Python wrapper */ +static Py_hash_t __pyx_pw_3_sa_6Phrase_23__hash__(PyObject *__pyx_v_self); /*proto*/ +static Py_hash_t __pyx_pw_3_sa_6Phrase_23__hash__(PyObject *__pyx_v_self) { + Py_hash_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__hash__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6Phrase_22__hash__(((struct __pyx_obj_3_sa_Phrase *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":124 + * return 0 + * + * def __hash__(self): # <<<<<<<<<<<<<< + * cdef int i + * cdef unsigned h + */ + +static Py_hash_t __pyx_pf_3_sa_6Phrase_22__hash__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self) { + int __pyx_v_i; + unsigned int __pyx_v_h; + Py_hash_t __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + __Pyx_RefNannySetupContext("__hash__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":127 + * cdef int i + * cdef unsigned h + * h = 0 # <<<<<<<<<<<<<< + * for i from 0 <= i < self.n: + * if self.syms[i] > 0: + */ + __pyx_v_h = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":128 + * cdef unsigned h + * h = 0 + * for i from 0 <= i < self.n: # <<<<<<<<<<<<<< + * if self.syms[i] > 0: + * h = (h << 1) + self.syms[i] + */ + __pyx_t_1 = __pyx_v_self->n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":129 + * h = 0 + * for i from 0 <= i < self.n: + * if self.syms[i] > 0: # <<<<<<<<<<<<<< + * h = (h << 1) + self.syms[i] + * else: + */ + __pyx_t_2 = ((__pyx_v_self->syms[__pyx_v_i]) > 0); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":130 + * for i from 0 <= i < self.n: + * if self.syms[i] > 0: + * h = (h << 1) + self.syms[i] # <<<<<<<<<<<<<< + * else: + * h = (h << 1) + -self.syms[i] + */ + __pyx_v_h = ((__pyx_v_h << 1) + (__pyx_v_self->syms[__pyx_v_i])); + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":132 + * h = (h << 1) + self.syms[i] + * else: + * h = (h << 1) + -self.syms[i] # <<<<<<<<<<<<<< + * return h + * + */ + __pyx_v_h = ((__pyx_v_h << 1) + (-(__pyx_v_self->syms[__pyx_v_i]))); + } + __pyx_L5:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":133 + * else: + * h = (h << 1) + -self.syms[i] + * return h # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + __pyx_r = __pyx_v_h; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static Py_ssize_t __pyx_pw_3_sa_6Phrase_25__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_3_sa_6Phrase_25__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6Phrase_24__len__(((struct __pyx_obj_3_sa_Phrase *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":135 + * return h + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.n + * + */ + +static Py_ssize_t __pyx_pf_3_sa_6Phrase_24__len__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":136 + * + * def __len__(self): + * return self.n # <<<<<<<<<<<<<< + * + * def __getitem__(self, i): + */ + __pyx_r = __pyx_v_self->n; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_6Phrase_27__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_3_sa_6Phrase_27__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6Phrase_26__getitem__(((struct __pyx_obj_3_sa_Phrase *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":138 + * return self.n + * + * def __getitem__(self, i): # <<<<<<<<<<<<<< + * return self.syms[i] + * + */ + +static PyObject *__pyx_pf_3_sa_6Phrase_26__getitem__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__getitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":139 + * + * def __getitem__(self, i): + * return self.syms[i] # <<<<<<<<<<<<<< + * + * def __iter__(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->syms[__pyx_t_1])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_sa.Phrase.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_3_sa_6Phrase_30generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_6Phrase_29__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_6Phrase_29__iter__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6Phrase_28__iter__(((struct __pyx_obj_3_sa_Phrase *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":141 + * return self.syms[i] + * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef int i + * for i from 0 <= i < self.n: + */ + +static PyObject *__pyx_pf_3_sa_6Phrase_28__iter__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self) { + struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__iter__", 0); + __pyx_cur_scope = (struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *)__pyx_ptype_3_sa___pyx_scope_struct_1___iter__->tp_new(__pyx_ptype_3_sa___pyx_scope_struct_1___iter__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_3_sa_6Phrase_30generator1, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_sa.Phrase.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_3_sa_6Phrase_30generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *__pyx_cur_scope = ((struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[7]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":143 + * def __iter__(self): + * cdef int i + * for i from 0 <= i < self.n: # <<<<<<<<<<<<<< + * yield self.syms[i] + * + */ + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->n; + for (__pyx_cur_scope->__pyx_v_i = 0; __pyx_cur_scope->__pyx_v_i < __pyx_t_1; __pyx_cur_scope->__pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":144 + * cdef int i + * for i from 0 <= i < self.n: + * yield self.syms[i] # <<<<<<<<<<<<<< + * + * def subst(self, start, children): + */ + __pyx_t_2 = PyInt_FromLong((__pyx_cur_scope->__pyx_v_self->syms[__pyx_cur_scope->__pyx_v_i])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_6Phrase_32subst(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_3_sa_6Phrase_32subst(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_start = 0; + PyObject *__pyx_v_children = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("subst (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__children,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__children)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("subst", 1, 2, 2, 1); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "subst") < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_start = values[0]; + __pyx_v_children = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("subst", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.Phrase.subst", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_6Phrase_31subst(((struct __pyx_obj_3_sa_Phrase *)__pyx_v_self), __pyx_v_start, __pyx_v_children); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":146 + * yield self.syms[i] + * + * def subst(self, start, children): # <<<<<<<<<<<<<< + * cdef int i + * for i from 0 <= i < self.n: + */ + +static PyObject *__pyx_pf_3_sa_6Phrase_31subst(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_start, PyObject *__pyx_v_children) { + int __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + long __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("subst", 0); + __Pyx_INCREF(__pyx_v_start); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":148 + * def subst(self, start, children): + * cdef int i + * for i from 0 <= i < self.n: # <<<<<<<<<<<<<< + * if sym_isvar(self.syms[i]): + * start = start + children[sym_getindex(self.syms[i])-1] + */ + __pyx_t_1 = __pyx_v_self->n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":149 + * cdef int i + * for i from 0 <= i < self.n: + * if sym_isvar(self.syms[i]): # <<<<<<<<<<<<<< + * start = start + children[sym_getindex(self.syms[i])-1] + * else: + */ + __pyx_t_2 = __pyx_f_3_sa_sym_isvar((__pyx_v_self->syms[__pyx_v_i])); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":150 + * for i from 0 <= i < self.n: + * if sym_isvar(self.syms[i]): + * start = start + children[sym_getindex(self.syms[i])-1] # <<<<<<<<<<<<<< + * else: + * start = start + (self.syms[i],) + */ + __pyx_t_3 = (__pyx_f_3_sa_sym_getindex((__pyx_v_self->syms[__pyx_v_i])) - 1); + __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_children, __pyx_t_3, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyNumber_Add(__pyx_v_start, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_v_start); + __pyx_v_start = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":152 + * start = start + children[sym_getindex(self.syms[i])-1] + * else: + * start = start + (self.syms[i],) # <<<<<<<<<<<<<< + * return start + * + */ + __pyx_t_5 = PyInt_FromLong((__pyx_v_self->syms[__pyx_v_i])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Add(__pyx_v_start, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_v_start); + __pyx_v_start = __pyx_t_5; + __pyx_t_5 = 0; + } + __pyx_L5:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":153 + * else: + * start = start + (self.syms[i],) + * return start # <<<<<<<<<<<<<< + * + * property words: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_start); + __pyx_r = __pyx_v_start; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_sa.Phrase.subst", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_start); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_6Phrase_5words_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_6Phrase_5words_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_6Phrase_5words___get__(((struct __pyx_obj_3_sa_Phrase *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":156 + * + * property words: + * def __get__(self): # <<<<<<<<<<<<<< + * return [sym_tostring(w) for w in self if not sym_isvar(w)] + * + */ + +static PyObject *__pyx_pf_3_sa_6Phrase_5words___get__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self) { + PyObject *__pyx_v_w = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *(*__pyx_t_4)(PyObject *); + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":157 + * property words: + * def __get__(self): + * return [sym_tostring(w) for w in self if not sym_isvar(w)] # <<<<<<<<<<<<<< + * + * cdef class Rule: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyList_CheckExact(((PyObject *)__pyx_v_self)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self))) { + __pyx_t_2 = ((PyObject *)__pyx_v_self); __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_5 = __pyx_t_4(__pyx_t_2); + if (unlikely(!__pyx_t_5)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[7]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_5); + } + __Pyx_XDECREF(__pyx_v_w); + __pyx_v_w = __pyx_t_5; + __pyx_t_5 = 0; + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_w); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = (!__pyx_f_3_sa_sym_isvar(__pyx_t_6)); + if (__pyx_t_7) { + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_w); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyBytes_FromString(__pyx_f_3_sa_sym_tostring(__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + if (unlikely(__Pyx_PyList_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + goto __pyx_L5; + } + __pyx_L5:; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_INCREF(((PyObject *)__pyx_t_1)); + __pyx_r = ((PyObject *)__pyx_t_1); + __Pyx_DECREF(((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_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_sa.Phrase.words.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_w); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_4Rule_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_4Rule_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_lhs; + struct __pyx_obj_3_sa_Phrase *__pyx_v_f = 0; + struct __pyx_obj_3_sa_Phrase *__pyx_v_e = 0; + PyObject *__pyx_v_scores = 0; + PyObject *__pyx_v_word_alignments = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__lhs,&__pyx_n_s__f,&__pyx_n_s__e,&__pyx_n_s__scores,&__pyx_n_s__word_alignments,0}; + PyObject* values[5] = {0,0,0,0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":162 + * + * def __cinit__(self, int lhs, Phrase f, Phrase e, + * scores=None, word_alignments=None): # <<<<<<<<<<<<<< + * cdef int i, n + * cdef char *rest + */ + values[3] = ((PyObject *)Py_None); + values[4] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__lhs)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__f)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 1); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__e)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 2); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 3: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__scores); + if (value) { values[3] = value; kw_args--; } + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__word_alignments); + if (value) { values[4] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_lhs = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_lhs == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_f = ((struct __pyx_obj_3_sa_Phrase *)values[1]); + __pyx_v_e = ((struct __pyx_obj_3_sa_Phrase *)values[2]); + __pyx_v_scores = values[3]; + __pyx_v_word_alignments = values[4]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[7]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.Rule.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_f), __pyx_ptype_3_sa_Phrase, 1, "f", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_e), __pyx_ptype_3_sa_Phrase, 1, "e", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_3_sa_4Rule___cinit__(((struct __pyx_obj_3_sa_Rule *)__pyx_v_self), __pyx_v_lhs, __pyx_v_f, __pyx_v_e, __pyx_v_scores, __pyx_v_word_alignments); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":161 + * cdef class Rule: + * + * def __cinit__(self, int lhs, Phrase f, Phrase e, # <<<<<<<<<<<<<< + * scores=None, word_alignments=None): + * cdef int i, n + */ + +static int __pyx_pf_3_sa_4Rule___cinit__(struct __pyx_obj_3_sa_Rule *__pyx_v_self, int __pyx_v_lhs, struct __pyx_obj_3_sa_Phrase *__pyx_v_f, struct __pyx_obj_3_sa_Phrase *__pyx_v_e, PyObject *__pyx_v_scores, PyObject *__pyx_v_word_alignments) { + int __pyx_v_i; + int __pyx_v_n; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + Py_ssize_t __pyx_t_4; + int __pyx_t_5; + float __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":166 + * cdef char *rest + * + * if not sym_isvar(lhs): # <<<<<<<<<<<<<< + * raise Exception('Invalid LHS symbol: %d' % lhs) + * + */ + __pyx_t_1 = (!__pyx_f_3_sa_sym_isvar(__pyx_v_lhs)); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":167 + * + * if not sym_isvar(lhs): + * raise Exception('Invalid LHS symbol: %d' % lhs) # <<<<<<<<<<<<<< + * + * self.lhs = lhs + */ + __pyx_t_2 = PyInt_FromLong(__pyx_v_lhs); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_65), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + {__pyx_filename = __pyx_f[7]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":169 + * raise Exception('Invalid LHS symbol: %d' % lhs) + * + * self.lhs = lhs # <<<<<<<<<<<<<< + * self.f = f + * self.e = e + */ + __pyx_v_self->lhs = __pyx_v_lhs; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":170 + * + * self.lhs = lhs + * self.f = f # <<<<<<<<<<<<<< + * self.e = e + * + */ + __Pyx_INCREF(((PyObject *)__pyx_v_f)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_f)); + __Pyx_GOTREF(__pyx_v_self->f); + __Pyx_DECREF(((PyObject *)__pyx_v_self->f)); + __pyx_v_self->f = __pyx_v_f; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":171 + * self.lhs = lhs + * self.f = f + * self.e = e # <<<<<<<<<<<<<< + * + * self.word_alignments = word_alignments + */ + __Pyx_INCREF(((PyObject *)__pyx_v_e)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_e)); + __Pyx_GOTREF(__pyx_v_self->e); + __Pyx_DECREF(((PyObject *)__pyx_v_self->e)); + __pyx_v_self->e = __pyx_v_e; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":173 + * self.e = e + * + * self.word_alignments = word_alignments # <<<<<<<<<<<<<< + * if scores is None: + * self.cscores = NULL + */ + __Pyx_INCREF(__pyx_v_word_alignments); + __Pyx_GIVEREF(__pyx_v_word_alignments); + __Pyx_GOTREF(__pyx_v_self->word_alignments); + __Pyx_DECREF(__pyx_v_self->word_alignments); + __pyx_v_self->word_alignments = __pyx_v_word_alignments; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":174 + * + * self.word_alignments = word_alignments + * if scores is None: # <<<<<<<<<<<<<< + * self.cscores = NULL + * self.n_scores = 0 + */ + __pyx_t_1 = (__pyx_v_scores == Py_None); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":175 + * self.word_alignments = word_alignments + * if scores is None: + * self.cscores = NULL # <<<<<<<<<<<<<< + * self.n_scores = 0 + * else: + */ + __pyx_v_self->cscores = NULL; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":176 + * if scores is None: + * self.cscores = NULL + * self.n_scores = 0 # <<<<<<<<<<<<<< + * else: + * n = len(scores) + */ + __pyx_v_self->n_scores = 0; + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":178 + * self.n_scores = 0 + * else: + * n = len(scores) # <<<<<<<<<<<<<< + * self.cscores = malloc(n*sizeof(float)) + * self.n_scores = n + */ + __pyx_t_4 = PyObject_Length(__pyx_v_scores); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_n = __pyx_t_4; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":179 + * else: + * n = len(scores) + * self.cscores = malloc(n*sizeof(float)) # <<<<<<<<<<<<<< + * self.n_scores = n + * for i from 0 <= i < n: + */ + __pyx_v_self->cscores = ((float *)malloc((__pyx_v_n * (sizeof(float))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":180 + * n = len(scores) + * self.cscores = malloc(n*sizeof(float)) + * self.n_scores = n # <<<<<<<<<<<<<< + * for i from 0 <= i < n: + * self.cscores[i] = scores[i] + */ + __pyx_v_self->n_scores = __pyx_v_n; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":181 + * self.cscores = malloc(n*sizeof(float)) + * self.n_scores = n + * for i from 0 <= i < n: # <<<<<<<<<<<<<< + * self.cscores[i] = scores[i] + * + */ + __pyx_t_5 = __pyx_v_n; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_5; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":182 + * self.n_scores = n + * for i from 0 <= i < n: + * self.cscores[i] = scores[i] # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_scores, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = __pyx_PyFloat_AsFloat(__pyx_t_3); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 182; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + (__pyx_v_self->cscores[__pyx_v_i]) = __pyx_t_6; + } + } + __pyx_L4:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.Rule.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_3_sa_4Rule_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_3_sa_4Rule_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_3_sa_4Rule_2__dealloc__(((struct __pyx_obj_3_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":184 + * self.cscores[i] = scores[i] + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * if self.cscores != NULL: + * free(self.cscores) + */ + +static void __pyx_pf_3_sa_4Rule_2__dealloc__(struct __pyx_obj_3_sa_Rule *__pyx_v_self) { + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":185 + * + * def __dealloc__(self): + * if self.cscores != NULL: # <<<<<<<<<<<<<< + * free(self.cscores) + * + */ + __pyx_t_1 = (__pyx_v_self->cscores != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":186 + * def __dealloc__(self): + * if self.cscores != NULL: + * free(self.cscores) # <<<<<<<<<<<<<< + * + * def __hash__(self): + */ + free(__pyx_v_self->cscores); + goto __pyx_L3; + } + __pyx_L3:; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static Py_hash_t __pyx_pw_3_sa_4Rule_5__hash__(PyObject *__pyx_v_self); /*proto*/ +static Py_hash_t __pyx_pw_3_sa_4Rule_5__hash__(PyObject *__pyx_v_self) { + Py_hash_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__hash__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_4Rule_4__hash__(((struct __pyx_obj_3_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":188 + * free(self.cscores) + * + * def __hash__(self): # <<<<<<<<<<<<<< + * return hash((self.lhs, self.f, self.e)) + * + */ + +static Py_hash_t __pyx_pf_3_sa_4Rule_4__hash__(struct __pyx_obj_3_sa_Rule *__pyx_v_self) { + Py_hash_t __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_hash_t __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__hash__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":189 + * + * def __hash__(self): + * return hash((self.lhs, self.f, self.e)) # <<<<<<<<<<<<<< + * + * def __cmp__(self, Rule other): + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->lhs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_self->f)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_self->f)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->f)); + __Pyx_INCREF(((PyObject *)__pyx_v_self->e)); + PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_self->e)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->e)); + __pyx_t_1 = 0; + __pyx_t_3 = PyObject_Hash(((PyObject *)__pyx_t_2)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_sa.Rule.__hash__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +#if PY_MAJOR_VERSION < 3 +static int __pyx_pw_3_sa_4Rule_7__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static int __pyx_pw_3_sa_4Rule_7__cmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cmp__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_3_sa_Rule, 1, "other", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_3_sa_4Rule_6__cmp__(((struct __pyx_obj_3_sa_Rule *)__pyx_v_self), ((struct __pyx_obj_3_sa_Rule *)__pyx_v_other)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +#endif /*!(#if PY_MAJOR_VERSION < 3)*/ + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":191 + * return hash((self.lhs, self.f, self.e)) + * + * def __cmp__(self, Rule other): # <<<<<<<<<<<<<< + * return cmp((self.lhs, self.f, self.e, self.word_alignments), (other.lhs, other.f, other.e, self.word_alignments)) + * + */ + +#if PY_MAJOR_VERSION < 3 +static int __pyx_pf_3_sa_4Rule_6__cmp__(struct __pyx_obj_3_sa_Rule *__pyx_v_self, struct __pyx_obj_3_sa_Rule *__pyx_v_other) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cmp__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":192 + * + * def __cmp__(self, Rule other): + * return cmp((self.lhs, self.f, self.e, self.word_alignments), (other.lhs, other.f, other.e, self.word_alignments)) # <<<<<<<<<<<<<< + * + * def __iadd__(self, Rule other): + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->lhs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_self->f)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_self->f)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->f)); + __Pyx_INCREF(((PyObject *)__pyx_v_self->e)); + PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_self->e)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->e)); + __Pyx_INCREF(__pyx_v_self->word_alignments); + PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_self->word_alignments); + __Pyx_GIVEREF(__pyx_v_self->word_alignments); + __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromLong(__pyx_v_other->lhs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_other->f)); + PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_other->f)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_other->f)); + __Pyx_INCREF(((PyObject *)__pyx_v_other->e)); + PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_other->e)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_other->e)); + __Pyx_INCREF(__pyx_v_self->word_alignments); + PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_v_self->word_alignments); + __Pyx_GIVEREF(__pyx_v_self->word_alignments); + __pyx_t_1 = 0; + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_t_3)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_cmp, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_4; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.Rule.__cmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +#endif /*!(#if PY_MAJOR_VERSION < 3)*/ + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_4Rule_9__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_3_sa_4Rule_9__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iadd__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_3_sa_Rule, 1, "other", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_3_sa_4Rule_8__iadd__(((struct __pyx_obj_3_sa_Rule *)__pyx_v_self), ((struct __pyx_obj_3_sa_Rule *)__pyx_v_other)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":194 + * return cmp((self.lhs, self.f, self.e, self.word_alignments), (other.lhs, other.f, other.e, self.word_alignments)) + * + * def __iadd__(self, Rule other): # <<<<<<<<<<<<<< + * if self.n_scores != other.n_scores: + * raise ValueError + */ + +static PyObject *__pyx_pf_3_sa_4Rule_8__iadd__(struct __pyx_obj_3_sa_Rule *__pyx_v_self, struct __pyx_obj_3_sa_Rule *__pyx_v_other) { + long __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__iadd__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":195 + * + * def __iadd__(self, Rule other): + * if self.n_scores != other.n_scores: # <<<<<<<<<<<<<< + * raise ValueError + * for i from 0 <= i < self.n_scores: + */ + __pyx_t_1 = (__pyx_v_self->n_scores != __pyx_v_other->n_scores); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":196 + * def __iadd__(self, Rule other): + * if self.n_scores != other.n_scores: + * raise ValueError # <<<<<<<<<<<<<< + * for i from 0 <= i < self.n_scores: + * self.cscores[i] = self.cscores[i] + other.cscores[i] + */ + __Pyx_Raise(__pyx_builtin_ValueError, 0, 0, 0); + {__pyx_filename = __pyx_f[7]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":197 + * if self.n_scores != other.n_scores: + * raise ValueError + * for i from 0 <= i < self.n_scores: # <<<<<<<<<<<<<< + * self.cscores[i] = self.cscores[i] + other.cscores[i] + * return self + */ + __pyx_t_2 = __pyx_v_self->n_scores; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":198 + * raise ValueError + * for i from 0 <= i < self.n_scores: + * self.cscores[i] = self.cscores[i] + other.cscores[i] # <<<<<<<<<<<<<< + * return self + * + */ + (__pyx_v_self->cscores[__pyx_v_i]) = ((__pyx_v_self->cscores[__pyx_v_i]) + (__pyx_v_other->cscores[__pyx_v_i])); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":199 + * for i from 0 <= i < self.n_scores: + * self.cscores[i] = self.cscores[i] + other.cscores[i] + * return self # <<<<<<<<<<<<<< + * + * def fmerge(self, Phrase f): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_sa.Rule.__iadd__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_4Rule_11fmerge(PyObject *__pyx_v_self, PyObject *__pyx_v_f); /*proto*/ +static PyObject *__pyx_pw_3_sa_4Rule_11fmerge(PyObject *__pyx_v_self, PyObject *__pyx_v_f) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("fmerge (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_f), __pyx_ptype_3_sa_Phrase, 1, "f", 0))) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_3_sa_4Rule_10fmerge(((struct __pyx_obj_3_sa_Rule *)__pyx_v_self), ((struct __pyx_obj_3_sa_Phrase *)__pyx_v_f)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":201 + * return self + * + * def fmerge(self, Phrase f): # <<<<<<<<<<<<<< + * if self.f == f: + * self.f = f + */ + +static PyObject *__pyx_pf_3_sa_4Rule_10fmerge(struct __pyx_obj_3_sa_Rule *__pyx_v_self, struct __pyx_obj_3_sa_Phrase *__pyx_v_f) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("fmerge", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":202 + * + * def fmerge(self, Phrase f): + * if self.f == f: # <<<<<<<<<<<<<< + * self.f = f + * + */ + __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_self->f), ((PyObject *)__pyx_v_f), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":203 + * def fmerge(self, Phrase f): + * if self.f == f: + * self.f = f # <<<<<<<<<<<<<< + * + * def arity(self): + */ + __Pyx_INCREF(((PyObject *)__pyx_v_f)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_f)); + __Pyx_GOTREF(__pyx_v_self->f); + __Pyx_DECREF(((PyObject *)__pyx_v_self->f)); + __pyx_v_self->f = __pyx_v_f; + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_sa.Rule.fmerge", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_4Rule_13arity(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_3_sa_4Rule_13arity(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("arity (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_4Rule_12arity(((struct __pyx_obj_3_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":205 + * self.f = f + * + * def arity(self): # <<<<<<<<<<<<<< + * return self.f.arity() + * + */ + +static PyObject *__pyx_pf_3_sa_4Rule_12arity(struct __pyx_obj_3_sa_Rule *__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("arity", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":206 + * + * def arity(self): + * return self.f.arity() # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->f), __pyx_n_s__arity); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 206; __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("_sa.Rule.arity", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_4Rule_15__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_4Rule_15__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_4Rule_14__str__(((struct __pyx_obj_3_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":208 + * return self.f.arity() + * + * def __str__(self): # <<<<<<<<<<<<<< + * scorestrs = [] + * for i from 0 <= i < self.n_scores: + */ + +static PyObject *__pyx_pf_3_sa_4Rule_14__str__(struct __pyx_obj_3_sa_Rule *__pyx_v_self) { + PyObject *__pyx_v_scorestrs = NULL; + long __pyx_v_i; + PyObject *__pyx_v_fields = NULL; + PyObject *__pyx_v_alignstr = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + Py_ssize_t __pyx_t_10; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__str__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":209 + * + * def __str__(self): + * scorestrs = [] # <<<<<<<<<<<<<< + * for i from 0 <= i < self.n_scores: + * scorestrs.append(str(self.cscores[i])) + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_scorestrs = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":210 + * def __str__(self): + * scorestrs = [] + * for i from 0 <= i < self.n_scores: # <<<<<<<<<<<<<< + * scorestrs.append(str(self.cscores[i])) + * fields = [sym_tostring(self.lhs), str(self.f), str(self.e), " ".join(scorestrs)] + */ + __pyx_t_2 = __pyx_v_self->n_scores; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":211 + * scorestrs = [] + * for i from 0 <= i < self.n_scores: + * scorestrs.append(str(self.cscores[i])) # <<<<<<<<<<<<<< + * fields = [sym_tostring(self.lhs), str(self.f), str(self.e), " ".join(scorestrs)] + * if self.word_alignments is not None: + */ + __pyx_t_1 = PyFloat_FromDouble((__pyx_v_self->cscores[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_4 = PyList_Append(__pyx_v_scorestrs, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":212 + * for i from 0 <= i < self.n_scores: + * scorestrs.append(str(self.cscores[i])) + * fields = [sym_tostring(self.lhs), str(self.f), str(self.e), " ".join(scorestrs)] # <<<<<<<<<<<<<< + * if self.word_alignments is not None: + * alignstr = [] + */ + __pyx_t_1 = PyBytes_FromString(__pyx_f_3_sa_sym_tostring(__pyx_v_self->lhs)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(((PyObject *)__pyx_v_self->f)); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->f)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->f)); + __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(((PyObject *)__pyx_v_self->e)); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->e)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->e)); + __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_64), __pyx_n_s__join); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(((PyObject *)__pyx_v_scorestrs)); + PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_scorestrs)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_scorestrs)); + __pyx_t_8 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __pyx_t_7 = PyList_New(4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + PyList_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + PyList_SET_ITEM(__pyx_t_7, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + PyList_SET_ITEM(__pyx_t_7, 2, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + PyList_SET_ITEM(__pyx_t_7, 3, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_1 = 0; + __pyx_t_5 = 0; + __pyx_t_6 = 0; + __pyx_t_8 = 0; + __pyx_v_fields = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":213 + * scorestrs.append(str(self.cscores[i])) + * fields = [sym_tostring(self.lhs), str(self.f), str(self.e), " ".join(scorestrs)] + * if self.word_alignments is not None: # <<<<<<<<<<<<<< + * alignstr = [] + * for i from 0 <= i < len(self.word_alignments): + */ + __pyx_t_9 = (__pyx_v_self->word_alignments != Py_None); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":214 + * fields = [sym_tostring(self.lhs), str(self.f), str(self.e), " ".join(scorestrs)] + * if self.word_alignments is not None: + * alignstr = [] # <<<<<<<<<<<<<< + * for i from 0 <= i < len(self.word_alignments): + * alignstr.append("%d-%d" % (self.word_alignments[i]/65536, self.word_alignments[i]%65536)) + */ + __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_v_alignstr = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":215 + * if self.word_alignments is not None: + * alignstr = [] + * for i from 0 <= i < len(self.word_alignments): # <<<<<<<<<<<<<< + * alignstr.append("%d-%d" % (self.word_alignments[i]/65536, self.word_alignments[i]%65536)) + * #for s,t in self.word_alignments: + */ + __pyx_t_7 = __pyx_v_self->word_alignments; + __Pyx_INCREF(__pyx_t_7); + __pyx_t_10 = PyObject_Length(__pyx_t_7); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_10; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":216 + * alignstr = [] + * for i from 0 <= i < len(self.word_alignments): + * alignstr.append("%d-%d" % (self.word_alignments[i]/65536, self.word_alignments[i]%65536)) # <<<<<<<<<<<<<< + * #for s,t in self.word_alignments: + * #alignstr.append("%d-%d" % (s,t)) + */ + __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_self->word_alignments, __pyx_v_i, sizeof(long), PyInt_FromLong); if (!__pyx_t_7) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyNumber_Divide(__pyx_t_7, __pyx_int_65536); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_self->word_alignments, __pyx_v_i, sizeof(long), PyInt_FromLong); if (!__pyx_t_7) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = PyNumber_Remainder(__pyx_t_7, __pyx_int_65536); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + __pyx_t_8 = 0; + __pyx_t_6 = 0; + __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_66), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __pyx_t_4 = PyList_Append(__pyx_v_alignstr, ((PyObject *)__pyx_t_6)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":219 + * #for s,t in self.word_alignments: + * #alignstr.append("%d-%d" % (s,t)) + * fields.append(" ".join(alignstr)) # <<<<<<<<<<<<<< + * + * return " ||| ".join(fields) + */ + __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_64), __pyx_n_s__join); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(((PyObject *)__pyx_v_alignstr)); + PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_alignstr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_alignstr)); + __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __pyx_t_4 = PyList_Append(__pyx_v_fields, __pyx_t_8); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":221 + * fields.append(" ".join(alignstr)) + * + * return " ||| ".join(fields) # <<<<<<<<<<<<<< + * + * property scores: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_67), __pyx_n_s__join); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(((PyObject *)__pyx_v_fields)); + PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_fields)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fields)); + __pyx_t_6 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __pyx_r = __pyx_t_6; + __pyx_t_6 = 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_3); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_sa.Rule.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_scorestrs); + __Pyx_XDECREF(__pyx_v_fields); + __Pyx_XDECREF(__pyx_v_alignstr); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_4Rule_6scores_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_4Rule_6scores_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_4Rule_6scores___get__(((struct __pyx_obj_3_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":224 + * + * property scores: + * def __get__(self): # <<<<<<<<<<<<<< + * s = [None]*self.n_scores + * for i from 0 <= i < self.n_scores: + */ + +static PyObject *__pyx_pf_3_sa_4Rule_6scores___get__(struct __pyx_obj_3_sa_Rule *__pyx_v_self) { + PyObject *__pyx_v_s = NULL; + long __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":225 + * property scores: + * def __get__(self): + * s = [None]*self.n_scores # <<<<<<<<<<<<<< + * for i from 0 <= i < self.n_scores: + * s[i] = self.cscores[i] + */ + __pyx_t_1 = PyList_New(1 * ((__pyx_v_self->n_scores<0) ? 0:__pyx_v_self->n_scores)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + { Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < __pyx_v_self->n_scores; __pyx_temp++) { + __Pyx_INCREF(Py_None); + PyList_SET_ITEM(__pyx_t_1, __pyx_temp, Py_None); + __Pyx_GIVEREF(Py_None); + } + } + __pyx_v_s = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":226 + * def __get__(self): + * s = [None]*self.n_scores + * for i from 0 <= i < self.n_scores: # <<<<<<<<<<<<<< + * s[i] = self.cscores[i] + * return s + */ + __pyx_t_2 = __pyx_v_self->n_scores; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":227 + * s = [None]*self.n_scores + * for i from 0 <= i < self.n_scores: + * s[i] = self.cscores[i] # <<<<<<<<<<<<<< + * return s + * + */ + __pyx_t_1 = PyFloat_FromDouble((__pyx_v_self->cscores[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_SetItemInt(((PyObject *)__pyx_v_s), __pyx_v_i, __pyx_t_1, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":228 + * for i from 0 <= i < self.n_scores: + * s[i] = self.cscores[i] + * return s # <<<<<<<<<<<<<< + * + * def __set__(self, s): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_s)); + __pyx_r = ((PyObject *)__pyx_v_s); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_sa.Rule.scores.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_s); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_4Rule_6scores_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_s); /*proto*/ +static int __pyx_pw_3_sa_4Rule_6scores_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_s) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_4Rule_6scores_2__set__(((struct __pyx_obj_3_sa_Rule *)__pyx_v_self), ((PyObject *)__pyx_v_s)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":230 + * return s + * + * def __set__(self, s): # <<<<<<<<<<<<<< + * if self.cscores != NULL: + * free(self.cscores) + */ + +static int __pyx_pf_3_sa_4Rule_6scores_2__set__(struct __pyx_obj_3_sa_Rule *__pyx_v_self, PyObject *__pyx_v_s) { + long __pyx_v_i; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + Py_ssize_t __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + float __pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":231 + * + * def __set__(self, s): + * if self.cscores != NULL: # <<<<<<<<<<<<<< + * free(self.cscores) + * self.cscores = malloc(len(s)*sizeof(float)) + */ + __pyx_t_1 = (__pyx_v_self->cscores != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":232 + * def __set__(self, s): + * if self.cscores != NULL: + * free(self.cscores) # <<<<<<<<<<<<<< + * self.cscores = malloc(len(s)*sizeof(float)) + * self.n_scores = len(s) + */ + free(__pyx_v_self->cscores); + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":233 + * if self.cscores != NULL: + * free(self.cscores) + * self.cscores = malloc(len(s)*sizeof(float)) # <<<<<<<<<<<<<< + * self.n_scores = len(s) + * for i from 0 <= i < self.n_scores: + */ + __pyx_t_2 = PyObject_Length(__pyx_v_s); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->cscores = ((float *)malloc((__pyx_t_2 * (sizeof(float))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":234 + * free(self.cscores) + * self.cscores = malloc(len(s)*sizeof(float)) + * self.n_scores = len(s) # <<<<<<<<<<<<<< + * for i from 0 <= i < self.n_scores: + * self.cscores[i] = s[i] + */ + __pyx_t_2 = PyObject_Length(__pyx_v_s); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->n_scores = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":235 + * self.cscores = malloc(len(s)*sizeof(float)) + * self.n_scores = len(s) + * for i from 0 <= i < self.n_scores: # <<<<<<<<<<<<<< + * self.cscores[i] = s[i] + */ + __pyx_t_3 = __pyx_v_self->n_scores; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rule.pxi":236 + * self.n_scores = len(s) + * for i from 0 <= i < self.n_scores: + * self.cscores[i] = s[i] # <<<<<<<<<<<<<< + */ + __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_s, __pyx_v_i, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __pyx_PyFloat_AsFloat(__pyx_t_4); if (unlikely((__pyx_t_5 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + (__pyx_v_self->cscores[__pyx_v_i]) = __pyx_t_5; + } + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_sa.Rule.scores.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_4Rule_3lhs_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_4Rule_3lhs_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_4Rule_3lhs___get__(((struct __pyx_obj_3_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_sa.pxd":8 + * + * cdef class Rule: + * cdef public int lhs # <<<<<<<<<<<<<< + * cdef readonly Phrase f, e + * cdef float *cscores + */ + +static PyObject *__pyx_pf_3_sa_4Rule_3lhs___get__(struct __pyx_obj_3_sa_Rule *__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("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->lhs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_sa.Rule.lhs.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_4Rule_3lhs_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_3_sa_4Rule_3lhs_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_4Rule_3lhs_2__set__(((struct __pyx_obj_3_sa_Rule *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_4Rule_3lhs_2__set__(struct __pyx_obj_3_sa_Rule *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[11]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->lhs = __pyx_t_1; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_sa.Rule.lhs.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_4Rule_1f_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_4Rule_1f_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_4Rule_1f___get__(((struct __pyx_obj_3_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_sa.pxd":9 + * cdef class Rule: + * cdef public int lhs + * cdef readonly Phrase f, e # <<<<<<<<<<<<<< + * cdef float *cscores + * cdef int n_scores + */ + +static PyObject *__pyx_pf_3_sa_4Rule_1f___get__(struct __pyx_obj_3_sa_Rule *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->f)); + __pyx_r = ((PyObject *)__pyx_v_self->f); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_4Rule_1e_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_4Rule_1e_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_4Rule_1e___get__(((struct __pyx_obj_3_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_3_sa_4Rule_1e___get__(struct __pyx_obj_3_sa_Rule *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->e)); + __pyx_r = ((PyObject *)__pyx_v_self->e); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_4Rule_15word_alignments_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_4Rule_15word_alignments_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_4Rule_15word_alignments___get__(((struct __pyx_obj_3_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_sa.pxd":12 + * cdef float *cscores + * cdef int n_scores + * cdef public word_alignments # <<<<<<<<<<<<<< + * + * cdef char* sym_tostring(int sym) + */ + +static PyObject *__pyx_pf_3_sa_4Rule_15word_alignments___get__(struct __pyx_obj_3_sa_Rule *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->word_alignments); + __pyx_r = __pyx_v_self->word_alignments; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_4Rule_15word_alignments_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_3_sa_4Rule_15word_alignments_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_4Rule_15word_alignments_2__set__(((struct __pyx_obj_3_sa_Rule *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_4Rule_15word_alignments_2__set__(struct __pyx_obj_3_sa_Rule *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->word_alignments); + __Pyx_DECREF(__pyx_v_self->word_alignments); + __pyx_v_self->word_alignments = __pyx_v_value; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_4Rule_15word_alignments_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_3_sa_4Rule_15word_alignments_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_4Rule_15word_alignments_4__del__(((struct __pyx_obj_3_sa_Rule *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_4Rule_15word_alignments_4__del__(struct __pyx_obj_3_sa_Rule *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->word_alignments); + __Pyx_DECREF(__pyx_v_self->word_alignments); + __pyx_v_self->word_alignments = Py_None; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":21 + * int arr_len + * + * cdef _Trie_Node* new_trie_node(): # <<<<<<<<<<<<<< + * cdef _Trie_Node* node + * node = <_Trie_Node*> malloc(sizeof(_Trie_Node)) + */ + +static struct __pyx_t_3_sa__Trie_Node *__pyx_f_3_sa_new_trie_node(void) { + struct __pyx_t_3_sa__Trie_Node *__pyx_v_node; + struct __pyx_t_3_sa__Trie_Node *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("new_trie_node", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":23 + * cdef _Trie_Node* new_trie_node(): + * cdef _Trie_Node* node + * node = <_Trie_Node*> malloc(sizeof(_Trie_Node)) # <<<<<<<<<<<<<< + * node.root = NULL + * node.arr_len = 0 + */ + __pyx_v_node = ((struct __pyx_t_3_sa__Trie_Node *)malloc((sizeof(struct __pyx_t_3_sa__Trie_Node)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":24 + * cdef _Trie_Node* node + * node = <_Trie_Node*> malloc(sizeof(_Trie_Node)) + * node.root = NULL # <<<<<<<<<<<<<< + * node.arr_len = 0 + * node.arr = malloc(sizeof(0*sizeof(int))) + */ + __pyx_v_node->root = NULL; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":25 + * node = <_Trie_Node*> malloc(sizeof(_Trie_Node)) + * node.root = NULL + * node.arr_len = 0 # <<<<<<<<<<<<<< + * node.arr = malloc(sizeof(0*sizeof(int))) + * return node + */ + __pyx_v_node->arr_len = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":26 + * node.root = NULL + * node.arr_len = 0 + * node.arr = malloc(sizeof(0*sizeof(int))) # <<<<<<<<<<<<<< + * return node + * + */ + __pyx_v_node->arr = ((int *)malloc((sizeof((0 * (sizeof(int))))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":27 + * node.arr_len = 0 + * node.arr = malloc(sizeof(0*sizeof(int))) + * return node # <<<<<<<<<<<<<< + * + * cdef _Trie_Edge* new_trie_edge(int val): + */ + __pyx_r = __pyx_v_node; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":29 + * return node + * + * cdef _Trie_Edge* new_trie_edge(int val): # <<<<<<<<<<<<<< + * cdef _Trie_Edge* edge + * edge = <_Trie_Edge*> malloc(sizeof(_Trie_Edge)) + */ + +static struct __pyx_t_3_sa__Trie_Edge *__pyx_f_3_sa_new_trie_edge(int __pyx_v_val) { + struct __pyx_t_3_sa__Trie_Edge *__pyx_v_edge; + struct __pyx_t_3_sa__Trie_Edge *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("new_trie_edge", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":31 + * cdef _Trie_Edge* new_trie_edge(int val): + * cdef _Trie_Edge* edge + * edge = <_Trie_Edge*> malloc(sizeof(_Trie_Edge)) # <<<<<<<<<<<<<< + * edge.node = new_trie_node() + * edge.bigger = NULL + */ + __pyx_v_edge = ((struct __pyx_t_3_sa__Trie_Edge *)malloc((sizeof(struct __pyx_t_3_sa__Trie_Edge)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":32 + * cdef _Trie_Edge* edge + * edge = <_Trie_Edge*> malloc(sizeof(_Trie_Edge)) + * edge.node = new_trie_node() # <<<<<<<<<<<<<< + * edge.bigger = NULL + * edge.smaller = NULL + */ + __pyx_v_edge->node = __pyx_f_3_sa_new_trie_node(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":33 + * edge = <_Trie_Edge*> malloc(sizeof(_Trie_Edge)) + * edge.node = new_trie_node() + * edge.bigger = NULL # <<<<<<<<<<<<<< + * edge.smaller = NULL + * edge.val = val + */ + __pyx_v_edge->bigger = NULL; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":34 + * edge.node = new_trie_node() + * edge.bigger = NULL + * edge.smaller = NULL # <<<<<<<<<<<<<< + * edge.val = val + * return edge + */ + __pyx_v_edge->smaller = NULL; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":35 + * edge.bigger = NULL + * edge.smaller = NULL + * edge.val = val # <<<<<<<<<<<<<< + * return edge + * + */ + __pyx_v_edge->val = __pyx_v_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":36 + * edge.smaller = NULL + * edge.val = val + * return edge # <<<<<<<<<<<<<< + * + * cdef free_trie_node(_Trie_Node* node): + */ + __pyx_r = __pyx_v_edge; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":38 + * return edge + * + * cdef free_trie_node(_Trie_Node* node): # <<<<<<<<<<<<<< + * if node != NULL: + * free_trie_edge(node.root) + */ + +static PyObject *__pyx_f_3_sa_free_trie_node(struct __pyx_t_3_sa__Trie_Node *__pyx_v_node) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("free_trie_node", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":39 + * + * cdef free_trie_node(_Trie_Node* node): + * if node != NULL: # <<<<<<<<<<<<<< + * free_trie_edge(node.root) + * free(node.arr) + */ + __pyx_t_1 = (__pyx_v_node != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":40 + * cdef free_trie_node(_Trie_Node* node): + * if node != NULL: + * free_trie_edge(node.root) # <<<<<<<<<<<<<< + * free(node.arr) + * + */ + __pyx_t_2 = __pyx_f_3_sa_free_trie_edge(__pyx_v_node->root); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":41 + * if node != NULL: + * free_trie_edge(node.root) + * free(node.arr) # <<<<<<<<<<<<<< + * + * cdef free_trie_edge(_Trie_Edge* edge): + */ + free(__pyx_v_node->arr); + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_sa.free_trie_node", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":43 + * free(node.arr) + * + * cdef free_trie_edge(_Trie_Edge* edge): # <<<<<<<<<<<<<< + * if edge != NULL: + * free_trie_node(edge.node) + */ + +static PyObject *__pyx_f_3_sa_free_trie_edge(struct __pyx_t_3_sa__Trie_Edge *__pyx_v_edge) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("free_trie_edge", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":44 + * + * cdef free_trie_edge(_Trie_Edge* edge): + * if edge != NULL: # <<<<<<<<<<<<<< + * free_trie_node(edge.node) + * free_trie_edge(edge.bigger) + */ + __pyx_t_1 = (__pyx_v_edge != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":45 + * cdef free_trie_edge(_Trie_Edge* edge): + * if edge != NULL: + * free_trie_node(edge.node) # <<<<<<<<<<<<<< + * free_trie_edge(edge.bigger) + * free_trie_edge(edge.smaller) + */ + __pyx_t_2 = __pyx_f_3_sa_free_trie_node(__pyx_v_edge->node); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":46 + * if edge != NULL: + * free_trie_node(edge.node) + * free_trie_edge(edge.bigger) # <<<<<<<<<<<<<< + * free_trie_edge(edge.smaller) + * + */ + __pyx_t_2 = __pyx_f_3_sa_free_trie_edge(__pyx_v_edge->bigger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":47 + * free_trie_node(edge.node) + * free_trie_edge(edge.bigger) + * free_trie_edge(edge.smaller) # <<<<<<<<<<<<<< + * + * cdef _Trie_Node* trie_find(_Trie_Node* node, int val): + */ + __pyx_t_2 = __pyx_f_3_sa_free_trie_edge(__pyx_v_edge->smaller); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_sa.free_trie_edge", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":49 + * free_trie_edge(edge.smaller) + * + * cdef _Trie_Node* trie_find(_Trie_Node* node, int val): # <<<<<<<<<<<<<< + * cdef _Trie_Edge* cur + * cur = node.root + */ + +static struct __pyx_t_3_sa__Trie_Node *__pyx_f_3_sa_trie_find(struct __pyx_t_3_sa__Trie_Node *__pyx_v_node, int __pyx_v_val) { + struct __pyx_t_3_sa__Trie_Edge *__pyx_v_cur; + struct __pyx_t_3_sa__Trie_Node *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("trie_find", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":51 + * cdef _Trie_Node* trie_find(_Trie_Node* node, int val): + * cdef _Trie_Edge* cur + * cur = node.root # <<<<<<<<<<<<<< + * while cur != NULL and cur.val != val: + * if val > cur.val: + */ + __pyx_v_cur = __pyx_v_node->root; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":52 + * cdef _Trie_Edge* cur + * cur = node.root + * while cur != NULL and cur.val != val: # <<<<<<<<<<<<<< + * if val > cur.val: + * cur = cur.bigger + */ + while (1) { + __pyx_t_1 = (__pyx_v_cur != NULL); + if (__pyx_t_1) { + __pyx_t_2 = (__pyx_v_cur->val != __pyx_v_val); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":53 + * cur = node.root + * while cur != NULL and cur.val != val: + * if val > cur.val: # <<<<<<<<<<<<<< + * cur = cur.bigger + * elif val < cur.val: + */ + __pyx_t_3 = (__pyx_v_val > __pyx_v_cur->val); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":54 + * while cur != NULL and cur.val != val: + * if val > cur.val: + * cur = cur.bigger # <<<<<<<<<<<<<< + * elif val < cur.val: + * cur = cur.smaller + */ + __pyx_v_cur = __pyx_v_cur->bigger; + goto __pyx_L5; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":55 + * if val > cur.val: + * cur = cur.bigger + * elif val < cur.val: # <<<<<<<<<<<<<< + * cur = cur.smaller + * if cur == NULL: + */ + __pyx_t_3 = (__pyx_v_val < __pyx_v_cur->val); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":56 + * cur = cur.bigger + * elif val < cur.val: + * cur = cur.smaller # <<<<<<<<<<<<<< + * if cur == NULL: + * return NULL + */ + __pyx_v_cur = __pyx_v_cur->smaller; + goto __pyx_L5; + } + __pyx_L5:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":57 + * elif val < cur.val: + * cur = cur.smaller + * if cur == NULL: # <<<<<<<<<<<<<< + * return NULL + * else: + */ + __pyx_t_3 = (__pyx_v_cur == NULL); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":58 + * cur = cur.smaller + * if cur == NULL: + * return NULL # <<<<<<<<<<<<<< + * else: + * return cur.node + */ + __pyx_r = NULL; + goto __pyx_L0; + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":60 + * return NULL + * else: + * return cur.node # <<<<<<<<<<<<<< + * + * cdef trie_node_data_append(_Trie_Node* node, int val): + */ + __pyx_r = __pyx_v_cur->node; + goto __pyx_L0; + } + __pyx_L6:; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":62 + * return cur.node + * + * cdef trie_node_data_append(_Trie_Node* node, int val): # <<<<<<<<<<<<<< + * cdef int new_len + * new_len = node.arr_len + 1 + */ + +static PyObject *__pyx_f_3_sa_trie_node_data_append(struct __pyx_t_3_sa__Trie_Node *__pyx_v_node, int __pyx_v_val) { + int __pyx_v_new_len; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("trie_node_data_append", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":64 + * cdef trie_node_data_append(_Trie_Node* node, int val): + * cdef int new_len + * new_len = node.arr_len + 1 # <<<<<<<<<<<<<< + * node.arr = realloc(node.arr, new_len*sizeof(int)) + * node.arr[node.arr_len] = val + */ + __pyx_v_new_len = (__pyx_v_node->arr_len + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":65 + * cdef int new_len + * new_len = node.arr_len + 1 + * node.arr = realloc(node.arr, new_len*sizeof(int)) # <<<<<<<<<<<<<< + * node.arr[node.arr_len] = val + * node.arr_len = new_len + */ + __pyx_v_node->arr = ((int *)realloc(__pyx_v_node->arr, (__pyx_v_new_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":66 + * new_len = node.arr_len + 1 + * node.arr = realloc(node.arr, new_len*sizeof(int)) + * node.arr[node.arr_len] = val # <<<<<<<<<<<<<< + * node.arr_len = new_len + * + */ + (__pyx_v_node->arr[__pyx_v_node->arr_len]) = __pyx_v_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":67 + * node.arr = realloc(node.arr, new_len*sizeof(int)) + * node.arr[node.arr_len] = val + * node.arr_len = new_len # <<<<<<<<<<<<<< + * + * cdef trie_node_data_extend(_Trie_Node* node, int* vals, int num_vals): + */ + __pyx_v_node->arr_len = __pyx_v_new_len; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":69 + * node.arr_len = new_len + * + * cdef trie_node_data_extend(_Trie_Node* node, int* vals, int num_vals): # <<<<<<<<<<<<<< + * cdef int new_len + * new_len = node.arr_len + num_vals + */ + +static PyObject *__pyx_f_3_sa_trie_node_data_extend(struct __pyx_t_3_sa__Trie_Node *__pyx_v_node, int *__pyx_v_vals, int __pyx_v_num_vals) { + int __pyx_v_new_len; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("trie_node_data_extend", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":71 + * cdef trie_node_data_extend(_Trie_Node* node, int* vals, int num_vals): + * cdef int new_len + * new_len = node.arr_len + num_vals # <<<<<<<<<<<<<< + * node.arr = realloc(node.arr, new_len*sizeof(int)) + * memcpy(node.arr + node.arr_len, vals, num_vals*sizeof(int)) + */ + __pyx_v_new_len = (__pyx_v_node->arr_len + __pyx_v_num_vals); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":72 + * cdef int new_len + * new_len = node.arr_len + num_vals + * node.arr = realloc(node.arr, new_len*sizeof(int)) # <<<<<<<<<<<<<< + * memcpy(node.arr + node.arr_len, vals, num_vals*sizeof(int)) + * node.arr_len = new_len + */ + __pyx_v_node->arr = ((int *)realloc(__pyx_v_node->arr, (__pyx_v_new_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":73 + * new_len = node.arr_len + num_vals + * node.arr = realloc(node.arr, new_len*sizeof(int)) + * memcpy(node.arr + node.arr_len, vals, num_vals*sizeof(int)) # <<<<<<<<<<<<<< + * node.arr_len = new_len + * + */ + memcpy((__pyx_v_node->arr + __pyx_v_node->arr_len), __pyx_v_vals, (__pyx_v_num_vals * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":74 + * node.arr = realloc(node.arr, new_len*sizeof(int)) + * memcpy(node.arr + node.arr_len, vals, num_vals*sizeof(int)) + * node.arr_len = new_len # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_node->arr_len = __pyx_v_new_len; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":77 + * + * + * cdef _Trie_Node* trie_insert(_Trie_Node* node, int val): # <<<<<<<<<<<<<< + * cdef _Trie_Edge** cur + * cur = &node.root + */ + +static struct __pyx_t_3_sa__Trie_Node *__pyx_f_3_sa_trie_insert(struct __pyx_t_3_sa__Trie_Node *__pyx_v_node, int __pyx_v_val) { + struct __pyx_t_3_sa__Trie_Edge **__pyx_v_cur; + struct __pyx_t_3_sa__Trie_Node *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("trie_insert", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":79 + * cdef _Trie_Node* trie_insert(_Trie_Node* node, int val): + * cdef _Trie_Edge** cur + * cur = &node.root # <<<<<<<<<<<<<< + * while cur[0] != NULL and cur[0].val != val: + * if val > cur[0].val: + */ + __pyx_v_cur = (&__pyx_v_node->root); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":80 + * cdef _Trie_Edge** cur + * cur = &node.root + * while cur[0] != NULL and cur[0].val != val: # <<<<<<<<<<<<<< + * if val > cur[0].val: + * cur = &cur[0].bigger + */ + while (1) { + __pyx_t_1 = ((__pyx_v_cur[0]) != NULL); + if (__pyx_t_1) { + __pyx_t_2 = ((__pyx_v_cur[0])->val != __pyx_v_val); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":81 + * cur = &node.root + * while cur[0] != NULL and cur[0].val != val: + * if val > cur[0].val: # <<<<<<<<<<<<<< + * cur = &cur[0].bigger + * elif val < cur[0].val: + */ + __pyx_t_3 = (__pyx_v_val > (__pyx_v_cur[0])->val); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":82 + * while cur[0] != NULL and cur[0].val != val: + * if val > cur[0].val: + * cur = &cur[0].bigger # <<<<<<<<<<<<<< + * elif val < cur[0].val: + * cur = &cur[0].smaller + */ + __pyx_v_cur = (&(__pyx_v_cur[0])->bigger); + goto __pyx_L5; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":83 + * if val > cur[0].val: + * cur = &cur[0].bigger + * elif val < cur[0].val: # <<<<<<<<<<<<<< + * cur = &cur[0].smaller + * if cur[0] == NULL: + */ + __pyx_t_3 = (__pyx_v_val < (__pyx_v_cur[0])->val); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":84 + * cur = &cur[0].bigger + * elif val < cur[0].val: + * cur = &cur[0].smaller # <<<<<<<<<<<<<< + * if cur[0] == NULL: + * cur[0] = new_trie_edge(val) + */ + __pyx_v_cur = (&(__pyx_v_cur[0])->smaller); + goto __pyx_L5; + } + __pyx_L5:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":85 + * elif val < cur[0].val: + * cur = &cur[0].smaller + * if cur[0] == NULL: # <<<<<<<<<<<<<< + * cur[0] = new_trie_edge(val) + * return cur[0].node + */ + __pyx_t_3 = ((__pyx_v_cur[0]) == NULL); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":86 + * cur = &cur[0].smaller + * if cur[0] == NULL: + * cur[0] = new_trie_edge(val) # <<<<<<<<<<<<<< + * return cur[0].node + * + */ + (__pyx_v_cur[0]) = __pyx_f_3_sa_new_trie_edge(__pyx_v_val); + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":87 + * if cur[0] == NULL: + * cur[0] = new_trie_edge(val) + * return cur[0].node # <<<<<<<<<<<<<< + * + * cdef trie_node_to_map(_Trie_Node* node, result, prefix, int include_zeros): + */ + __pyx_r = (__pyx_v_cur[0])->node; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":89 + * return cur[0].node + * + * cdef trie_node_to_map(_Trie_Node* node, result, prefix, int include_zeros): # <<<<<<<<<<<<<< + * cdef IntList arr + * + */ + +static PyObject *__pyx_f_3_sa_trie_node_to_map(struct __pyx_t_3_sa__Trie_Node *__pyx_v_node, PyObject *__pyx_v_result, PyObject *__pyx_v_prefix, int __pyx_v_include_zeros) { + struct __pyx_obj_3_sa_IntList *__pyx_v_arr = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("trie_node_to_map", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":92 + * cdef IntList arr + * + * if include_zeros or node.arr_len > 0: # <<<<<<<<<<<<<< + * arr = IntList() + * free(arr.arr) + */ + if (!__pyx_v_include_zeros) { + __pyx_t_1 = (__pyx_v_node->arr_len > 0); + __pyx_t_2 = __pyx_t_1; + } else { + __pyx_t_2 = __pyx_v_include_zeros; + } + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":93 + * + * if include_zeros or node.arr_len > 0: + * arr = IntList() # <<<<<<<<<<<<<< + * free(arr.arr) + * arr.arr = malloc(node.arr_len * sizeof(int)) + */ + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_arr = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":94 + * if include_zeros or node.arr_len > 0: + * arr = IntList() + * free(arr.arr) # <<<<<<<<<<<<<< + * arr.arr = malloc(node.arr_len * sizeof(int)) + * memcpy(arr.arr, node.arr, node.arr_len * sizeof(int)) + */ + free(__pyx_v_arr->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":95 + * arr = IntList() + * free(arr.arr) + * arr.arr = malloc(node.arr_len * sizeof(int)) # <<<<<<<<<<<<<< + * memcpy(arr.arr, node.arr, node.arr_len * sizeof(int)) + * arr.len = node.arr_len + */ + __pyx_v_arr->arr = ((int *)malloc((__pyx_v_node->arr_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":96 + * free(arr.arr) + * arr.arr = malloc(node.arr_len * sizeof(int)) + * memcpy(arr.arr, node.arr, node.arr_len * sizeof(int)) # <<<<<<<<<<<<<< + * arr.len = node.arr_len + * arr.size = node.arr_len + */ + memcpy(__pyx_v_arr->arr, __pyx_v_node->arr, (__pyx_v_node->arr_len * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":97 + * arr.arr = malloc(node.arr_len * sizeof(int)) + * memcpy(arr.arr, node.arr, node.arr_len * sizeof(int)) + * arr.len = node.arr_len # <<<<<<<<<<<<<< + * arr.size = node.arr_len + * result[prefix] = arr + */ + __pyx_v_arr->len = __pyx_v_node->arr_len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":98 + * memcpy(arr.arr, node.arr, node.arr_len * sizeof(int)) + * arr.len = node.arr_len + * arr.size = node.arr_len # <<<<<<<<<<<<<< + * result[prefix] = arr + * trie_edge_to_map(node.root, result, prefix, include_zeros) + */ + __pyx_v_arr->size = __pyx_v_node->arr_len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":99 + * arr.len = node.arr_len + * arr.size = node.arr_len + * result[prefix] = arr # <<<<<<<<<<<<<< + * trie_edge_to_map(node.root, result, prefix, include_zeros) + * + */ + if (PyObject_SetItem(__pyx_v_result, __pyx_v_prefix, ((PyObject *)__pyx_v_arr)) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":100 + * arr.size = node.arr_len + * result[prefix] = arr + * trie_edge_to_map(node.root, result, prefix, include_zeros) # <<<<<<<<<<<<<< + * + * cdef trie_edge_to_map(_Trie_Edge* edge, result, prefix, int include_zeros): + */ + __pyx_t_3 = __pyx_f_3_sa_trie_edge_to_map(__pyx_v_node->root, __pyx_v_result, __pyx_v_prefix, __pyx_v_include_zeros); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.trie_node_to_map", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_arr); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":102 + * trie_edge_to_map(node.root, result, prefix, include_zeros) + * + * cdef trie_edge_to_map(_Trie_Edge* edge, result, prefix, int include_zeros): # <<<<<<<<<<<<<< + * if edge != NULL: + * trie_edge_to_map(edge.smaller, result, prefix, include_zeros) + */ + +static PyObject *__pyx_f_3_sa_trie_edge_to_map(struct __pyx_t_3_sa__Trie_Edge *__pyx_v_edge, PyObject *__pyx_v_result, PyObject *__pyx_v_prefix, int __pyx_v_include_zeros) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("trie_edge_to_map", 0); + __Pyx_INCREF(__pyx_v_prefix); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":103 + * + * cdef trie_edge_to_map(_Trie_Edge* edge, result, prefix, int include_zeros): + * if edge != NULL: # <<<<<<<<<<<<<< + * trie_edge_to_map(edge.smaller, result, prefix, include_zeros) + * trie_edge_to_map(edge.bigger, result, prefix, include_zeros) + */ + __pyx_t_1 = (__pyx_v_edge != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":104 + * cdef trie_edge_to_map(_Trie_Edge* edge, result, prefix, int include_zeros): + * if edge != NULL: + * trie_edge_to_map(edge.smaller, result, prefix, include_zeros) # <<<<<<<<<<<<<< + * trie_edge_to_map(edge.bigger, result, prefix, include_zeros) + * prefix = prefix + (edge.val,) + */ + __pyx_t_2 = __pyx_f_3_sa_trie_edge_to_map(__pyx_v_edge->smaller, __pyx_v_result, __pyx_v_prefix, __pyx_v_include_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":105 + * if edge != NULL: + * trie_edge_to_map(edge.smaller, result, prefix, include_zeros) + * trie_edge_to_map(edge.bigger, result, prefix, include_zeros) # <<<<<<<<<<<<<< + * prefix = prefix + (edge.val,) + * trie_node_to_map(edge.node, result, prefix, include_zeros) + */ + __pyx_t_2 = __pyx_f_3_sa_trie_edge_to_map(__pyx_v_edge->bigger, __pyx_v_result, __pyx_v_prefix, __pyx_v_include_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":106 + * trie_edge_to_map(edge.smaller, result, prefix, include_zeros) + * trie_edge_to_map(edge.bigger, result, prefix, include_zeros) + * prefix = prefix + (edge.val,) # <<<<<<<<<<<<<< + * trie_node_to_map(edge.node, result, prefix, include_zeros) + * + */ + __pyx_t_2 = PyInt_FromLong(__pyx_v_edge->val); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Add(__pyx_v_prefix, ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_v_prefix); + __pyx_v_prefix = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":107 + * trie_edge_to_map(edge.bigger, result, prefix, include_zeros) + * prefix = prefix + (edge.val,) + * trie_node_to_map(edge.node, result, prefix, include_zeros) # <<<<<<<<<<<<<< + * + * cdef class TrieMap: + */ + __pyx_t_2 = __pyx_f_3_sa_trie_node_to_map(__pyx_v_edge->node, __pyx_v_result, __pyx_v_prefix, __pyx_v_include_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.trie_edge_to_map", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_prefix); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_7TrieMap_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_7TrieMap_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_alphabet_size; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__alphabet_size,0}; + PyObject* values[1] = {0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__alphabet_size)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 114; __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_alphabet_size = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_alphabet_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 114; __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[12]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.TrieMap.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_7TrieMap___cinit__(((struct __pyx_obj_3_sa_TrieMap *)__pyx_v_self), __pyx_v_alphabet_size); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":114 + * cdef int V + * + * def __cinit__(self, int alphabet_size): # <<<<<<<<<<<<<< + * self.V = alphabet_size + * self.root = <_Trie_Node**> malloc(self.V * sizeof(_Trie_Node*)) + */ + +static int __pyx_pf_3_sa_7TrieMap___cinit__(struct __pyx_obj_3_sa_TrieMap *__pyx_v_self, int __pyx_v_alphabet_size) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":115 + * + * def __cinit__(self, int alphabet_size): + * self.V = alphabet_size # <<<<<<<<<<<<<< + * self.root = <_Trie_Node**> malloc(self.V * sizeof(_Trie_Node*)) + * memset(self.root, 0, self.V * sizeof(_Trie_Node*)) + */ + __pyx_v_self->V = __pyx_v_alphabet_size; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":116 + * def __cinit__(self, int alphabet_size): + * self.V = alphabet_size + * self.root = <_Trie_Node**> malloc(self.V * sizeof(_Trie_Node*)) # <<<<<<<<<<<<<< + * memset(self.root, 0, self.V * sizeof(_Trie_Node*)) + * + */ + __pyx_v_self->root = ((struct __pyx_t_3_sa__Trie_Node **)malloc((__pyx_v_self->V * (sizeof(struct __pyx_t_3_sa__Trie_Node *))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":117 + * self.V = alphabet_size + * self.root = <_Trie_Node**> malloc(self.V * sizeof(_Trie_Node*)) + * memset(self.root, 0, self.V * sizeof(_Trie_Node*)) # <<<<<<<<<<<<<< + * + * + */ + memset(__pyx_v_self->root, 0, (__pyx_v_self->V * (sizeof(struct __pyx_t_3_sa__Trie_Node *)))); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_3_sa_7TrieMap_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_3_sa_7TrieMap_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_3_sa_7TrieMap_2__dealloc__(((struct __pyx_obj_3_sa_TrieMap *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":120 + * + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * cdef int i + * for i from 0 <= i < self.V: + */ + +static void __pyx_pf_3_sa_7TrieMap_2__dealloc__(struct __pyx_obj_3_sa_TrieMap *__pyx_v_self) { + int __pyx_v_i; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":122 + * def __dealloc__(self): + * cdef int i + * for i from 0 <= i < self.V: # <<<<<<<<<<<<<< + * if self.root[i] != NULL: + * free_trie_node(self.root[i]) + */ + __pyx_t_1 = __pyx_v_self->V; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":123 + * cdef int i + * for i from 0 <= i < self.V: + * if self.root[i] != NULL: # <<<<<<<<<<<<<< + * free_trie_node(self.root[i]) + * free(self.root) + */ + __pyx_t_2 = ((__pyx_v_self->root[__pyx_v_i]) != NULL); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":124 + * for i from 0 <= i < self.V: + * if self.root[i] != NULL: + * free_trie_node(self.root[i]) # <<<<<<<<<<<<<< + * free(self.root) + * + */ + __pyx_t_3 = __pyx_f_3_sa_free_trie_node((__pyx_v_self->root[__pyx_v_i])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L5; + } + __pyx_L5:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":125 + * if self.root[i] != NULL: + * free_trie_node(self.root[i]) + * free(self.root) # <<<<<<<<<<<<<< + * + * + */ + free(__pyx_v_self->root); + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.TrieMap.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_7TrieMap_5insert(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern); /*proto*/ +static PyObject *__pyx_pw_3_sa_7TrieMap_5insert(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("insert (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_7TrieMap_4insert(((struct __pyx_obj_3_sa_TrieMap *)__pyx_v_self), ((PyObject *)__pyx_v_pattern)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":128 + * + * + * def insert(self, pattern): # <<<<<<<<<<<<<< + * cdef int* p + * cdef int i, l + */ + +static PyObject *__pyx_pf_3_sa_7TrieMap_4insert(struct __pyx_obj_3_sa_TrieMap *__pyx_v_self, PyObject *__pyx_v_pattern) { + int *__pyx_v_p; + int __pyx_v_i; + int __pyx_v_l; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("insert", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":131 + * cdef int* p + * cdef int i, l + * l = len(pattern) # <<<<<<<<<<<<<< + * p = malloc(l*sizeof(int)) + * for i from 0 <= i < l: + */ + __pyx_t_1 = PyObject_Length(__pyx_v_pattern); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_l = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":132 + * cdef int i, l + * l = len(pattern) + * p = malloc(l*sizeof(int)) # <<<<<<<<<<<<<< + * for i from 0 <= i < l: + * p[i] = pattern[i] + */ + __pyx_v_p = ((int *)malloc((__pyx_v_l * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":133 + * l = len(pattern) + * p = malloc(l*sizeof(int)) + * for i from 0 <= i < l: # <<<<<<<<<<<<<< + * p[i] = pattern[i] + * self._insert(p,l) + */ + __pyx_t_2 = __pyx_v_l; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":134 + * p = malloc(l*sizeof(int)) + * for i from 0 <= i < l: + * p[i] = pattern[i] # <<<<<<<<<<<<<< + * self._insert(p,l) + * free(p) + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_pattern, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + (__pyx_v_p[__pyx_v_i]) = __pyx_t_4; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":135 + * for i from 0 <= i < l: + * p[i] = pattern[i] + * self._insert(p,l) # <<<<<<<<<<<<<< + * free(p) + * + */ + ((struct __pyx_vtabstruct_3_sa_TrieMap *)__pyx_v_self->__pyx_vtab)->_insert(__pyx_v_self, __pyx_v_p, __pyx_v_l); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":136 + * p[i] = pattern[i] + * self._insert(p,l) + * free(p) # <<<<<<<<<<<<<< + * + * + */ + free(__pyx_v_p); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.TrieMap.insert", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":139 + * + * + * cdef _Trie_Node* _insert(self, int* pattern, int pattern_len): # <<<<<<<<<<<<<< + * cdef int i + * cdef _Trie_Node* node + */ + +static struct __pyx_t_3_sa__Trie_Node *__pyx_f_3_sa_7TrieMap__insert(struct __pyx_obj_3_sa_TrieMap *__pyx_v_self, int *__pyx_v_pattern, int __pyx_v_pattern_len) { + int __pyx_v_i; + struct __pyx_t_3_sa__Trie_Node *__pyx_v_node; + struct __pyx_t_3_sa__Trie_Node *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + __Pyx_RefNannySetupContext("_insert", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":142 + * cdef int i + * cdef _Trie_Node* node + * if self.root[pattern[0]] == NULL: # <<<<<<<<<<<<<< + * self.root[pattern[0]] = new_trie_node() + * node = self.root[pattern[0]] + */ + __pyx_t_1 = ((__pyx_v_self->root[(__pyx_v_pattern[0])]) == NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":143 + * cdef _Trie_Node* node + * if self.root[pattern[0]] == NULL: + * self.root[pattern[0]] = new_trie_node() # <<<<<<<<<<<<<< + * node = self.root[pattern[0]] + * for i from 1 <= i < pattern_len: + */ + (__pyx_v_self->root[(__pyx_v_pattern[0])]) = __pyx_f_3_sa_new_trie_node(); + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":144 + * if self.root[pattern[0]] == NULL: + * self.root[pattern[0]] = new_trie_node() + * node = self.root[pattern[0]] # <<<<<<<<<<<<<< + * for i from 1 <= i < pattern_len: + * node = trie_insert(node, pattern[i]) + */ + __pyx_v_node = (__pyx_v_self->root[(__pyx_v_pattern[0])]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":145 + * self.root[pattern[0]] = new_trie_node() + * node = self.root[pattern[0]] + * for i from 1 <= i < pattern_len: # <<<<<<<<<<<<<< + * node = trie_insert(node, pattern[i]) + * return node + */ + __pyx_t_2 = __pyx_v_pattern_len; + for (__pyx_v_i = 1; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":146 + * node = self.root[pattern[0]] + * for i from 1 <= i < pattern_len: + * node = trie_insert(node, pattern[i]) # <<<<<<<<<<<<<< + * return node + * + */ + __pyx_v_node = __pyx_f_3_sa_trie_insert(__pyx_v_node, (__pyx_v_pattern[__pyx_v_i])); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":147 + * for i from 1 <= i < pattern_len: + * node = trie_insert(node, pattern[i]) + * return node # <<<<<<<<<<<<<< + * + * def contains(self, pattern): + */ + __pyx_r = __pyx_v_node; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_7TrieMap_7contains(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern); /*proto*/ +static PyObject *__pyx_pw_3_sa_7TrieMap_7contains(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("contains (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_7TrieMap_6contains(((struct __pyx_obj_3_sa_TrieMap *)__pyx_v_self), ((PyObject *)__pyx_v_pattern)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":149 + * return node + * + * def contains(self, pattern): # <<<<<<<<<<<<<< + * cdef int* p + * cdef int i, l + */ + +static PyObject *__pyx_pf_3_sa_7TrieMap_6contains(struct __pyx_obj_3_sa_TrieMap *__pyx_v_self, PyObject *__pyx_v_pattern) { + int *__pyx_v_p; + int __pyx_v_i; + int __pyx_v_l; + struct __pyx_t_3_sa__Trie_Node *__pyx_v_node; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("contains", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":153 + * cdef int i, l + * cdef _Trie_Node* node + * l = len(pattern) # <<<<<<<<<<<<<< + * p = malloc(l*sizeof(int)) + * for i from 0 <= i < l: + */ + __pyx_t_1 = PyObject_Length(__pyx_v_pattern); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_l = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":154 + * cdef _Trie_Node* node + * l = len(pattern) + * p = malloc(l*sizeof(int)) # <<<<<<<<<<<<<< + * for i from 0 <= i < l: + * p[i] = pattern[i] + */ + __pyx_v_p = ((int *)malloc((__pyx_v_l * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":155 + * l = len(pattern) + * p = malloc(l*sizeof(int)) + * for i from 0 <= i < l: # <<<<<<<<<<<<<< + * p[i] = pattern[i] + * node = self._contains(p,l) + */ + __pyx_t_2 = __pyx_v_l; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":156 + * p = malloc(l*sizeof(int)) + * for i from 0 <= i < l: + * p[i] = pattern[i] # <<<<<<<<<<<<<< + * node = self._contains(p,l) + * free(p) + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_pattern, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + (__pyx_v_p[__pyx_v_i]) = __pyx_t_4; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":157 + * for i from 0 <= i < l: + * p[i] = pattern[i] + * node = self._contains(p,l) # <<<<<<<<<<<<<< + * free(p) + * if node == NULL: + */ + __pyx_v_node = ((struct __pyx_vtabstruct_3_sa_TrieMap *)__pyx_v_self->__pyx_vtab)->_contains(__pyx_v_self, __pyx_v_p, __pyx_v_l); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":158 + * p[i] = pattern[i] + * node = self._contains(p,l) + * free(p) # <<<<<<<<<<<<<< + * if node == NULL: + * return False + */ + free(__pyx_v_p); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":159 + * node = self._contains(p,l) + * free(p) + * if node == NULL: # <<<<<<<<<<<<<< + * return False + * else: + */ + __pyx_t_5 = (__pyx_v_node == NULL); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":160 + * free(p) + * if node == NULL: + * return False # <<<<<<<<<<<<<< + * else: + * return True + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":162 + * return False + * else: + * return True # <<<<<<<<<<<<<< + * + * cdef _Trie_Node* _contains(self, int* pattern, int pattern_len): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + } + __pyx_L5:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.TrieMap.contains", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":164 + * return True + * + * cdef _Trie_Node* _contains(self, int* pattern, int pattern_len): # <<<<<<<<<<<<<< + * cdef int i + * cdef _Trie_Node* node + */ + +static struct __pyx_t_3_sa__Trie_Node *__pyx_f_3_sa_7TrieMap__contains(struct __pyx_obj_3_sa_TrieMap *__pyx_v_self, int *__pyx_v_pattern, int __pyx_v_pattern_len) { + int __pyx_v_i; + struct __pyx_t_3_sa__Trie_Node *__pyx_v_node; + struct __pyx_t_3_sa__Trie_Node *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("_contains", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":167 + * cdef int i + * cdef _Trie_Node* node + * node = self.root[pattern[0]] # <<<<<<<<<<<<<< + * i = 1 + * while node != NULL and i < pattern_len: + */ + __pyx_v_node = (__pyx_v_self->root[(__pyx_v_pattern[0])]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":168 + * cdef _Trie_Node* node + * node = self.root[pattern[0]] + * i = 1 # <<<<<<<<<<<<<< + * while node != NULL and i < pattern_len: + * node = trie_find(node, pattern[i]) + */ + __pyx_v_i = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":169 + * node = self.root[pattern[0]] + * i = 1 + * while node != NULL and i < pattern_len: # <<<<<<<<<<<<<< + * node = trie_find(node, pattern[i]) + * i = i+1 + */ + while (1) { + __pyx_t_1 = (__pyx_v_node != NULL); + if (__pyx_t_1) { + __pyx_t_2 = (__pyx_v_i < __pyx_v_pattern_len); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":170 + * i = 1 + * while node != NULL and i < pattern_len: + * node = trie_find(node, pattern[i]) # <<<<<<<<<<<<<< + * i = i+1 + * return node + */ + __pyx_v_node = __pyx_f_3_sa_trie_find(__pyx_v_node, (__pyx_v_pattern[__pyx_v_i])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":171 + * while node != NULL and i < pattern_len: + * node = trie_find(node, pattern[i]) + * i = i+1 # <<<<<<<<<<<<<< + * return node + * + */ + __pyx_v_i = (__pyx_v_i + 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":172 + * node = trie_find(node, pattern[i]) + * i = i+1 + * return node # <<<<<<<<<<<<<< + * + * def toMap(self, flag): + */ + __pyx_r = __pyx_v_node; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_7TrieMap_9toMap(PyObject *__pyx_v_self, PyObject *__pyx_v_flag); /*proto*/ +static PyObject *__pyx_pw_3_sa_7TrieMap_9toMap(PyObject *__pyx_v_self, PyObject *__pyx_v_flag) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("toMap (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_7TrieMap_8toMap(((struct __pyx_obj_3_sa_TrieMap *)__pyx_v_self), ((PyObject *)__pyx_v_flag)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":174 + * return node + * + * def toMap(self, flag): # <<<<<<<<<<<<<< + * cdef int i, include_zeros + * + */ + +static PyObject *__pyx_pf_3_sa_7TrieMap_8toMap(struct __pyx_obj_3_sa_TrieMap *__pyx_v_self, PyObject *__pyx_v_flag) { + int __pyx_v_i; + int __pyx_v_include_zeros; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("toMap", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":177 + * cdef int i, include_zeros + * + * if flag: # <<<<<<<<<<<<<< + * include_zeros=1 + * else: + */ + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_flag); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":178 + * + * if flag: + * include_zeros=1 # <<<<<<<<<<<<<< + * else: + * include_zeros=0 + */ + __pyx_v_include_zeros = 1; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":180 + * include_zeros=1 + * else: + * include_zeros=0 # <<<<<<<<<<<<<< + * result = {} + * for i from 0 <= i < self.V: + */ + __pyx_v_include_zeros = 0; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":181 + * else: + * include_zeros=0 + * result = {} # <<<<<<<<<<<<<< + * for i from 0 <= i < self.V: + * if self.root[i] != NULL: + */ + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_v_result = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":182 + * include_zeros=0 + * result = {} + * for i from 0 <= i < self.V: # <<<<<<<<<<<<<< + * if self.root[i] != NULL: + * trie_node_to_map(self.root[i], result, (i,), include_zeros) + */ + __pyx_t_3 = __pyx_v_self->V; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":183 + * result = {} + * for i from 0 <= i < self.V: + * if self.root[i] != NULL: # <<<<<<<<<<<<<< + * trie_node_to_map(self.root[i], result, (i,), include_zeros) + * return result + */ + __pyx_t_1 = ((__pyx_v_self->root[__pyx_v_i]) != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":184 + * for i from 0 <= i < self.V: + * if self.root[i] != NULL: + * trie_node_to_map(self.root[i], result, (i,), include_zeros) # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_t_2 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = __pyx_f_3_sa_trie_node_to_map((__pyx_v_self->root[__pyx_v_i]), ((PyObject *)__pyx_v_result), ((PyObject *)__pyx_t_4), __pyx_v_include_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L6; + } + __pyx_L6:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":185 + * if self.root[i] != NULL: + * trie_node_to_map(self.root[i], result, (i,), include_zeros) + * return result # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_sa.TrieMap.toMap", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_14Precomputation_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_14Precomputation_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_fsarray = 0; + PyObject *__pyx_v_from_stats = 0; + PyObject *__pyx_v_from_binary = 0; + PyObject *__pyx_v_precompute_rank = 0; + PyObject *__pyx_v_precompute_secondary_rank = 0; + PyObject *__pyx_v_max_length = 0; + PyObject *__pyx_v_max_nonterminals = 0; + PyObject *__pyx_v_train_max_initial_size = 0; + PyObject *__pyx_v_train_min_gap_size = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fsarray,&__pyx_n_s__from_stats,&__pyx_n_s__from_binary,&__pyx_n_s__precompute_rank,&__pyx_n_s_68,&__pyx_n_s__max_length,&__pyx_n_s__max_nonterminals,&__pyx_n_s_69,&__pyx_n_s__train_min_gap_size,0}; + PyObject* values[9] = {0,0,0,0,0,0,0,0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":200 + * cdef write_map(self, m, FILE* f) + * + * def __cinit__(self, fsarray=None, from_stats=None, from_binary=None, # <<<<<<<<<<<<<< + * precompute_rank=1000, precompute_secondary_rank=20, + * max_length=5, max_nonterminals=2, + */ + values[0] = ((PyObject *)Py_None); + values[1] = ((PyObject *)Py_None); + values[2] = ((PyObject *)Py_None); + values[3] = ((PyObject *)__pyx_int_1000); + values[4] = ((PyObject *)__pyx_int_20); + values[5] = ((PyObject *)__pyx_int_5); + values[6] = ((PyObject *)__pyx_int_2); + values[7] = ((PyObject *)__pyx_int_10); + values[8] = ((PyObject *)__pyx_int_2); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fsarray); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_stats); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_binary); + if (value) { values[2] = value; kw_args--; } + } + case 3: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__precompute_rank); + if (value) { values[3] = value; kw_args--; } + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_68); + if (value) { values[4] = value; kw_args--; } + } + case 5: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_length); + if (value) { values[5] = value; kw_args--; } + } + case 6: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_nonterminals); + if (value) { values[6] = value; kw_args--; } + } + case 7: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_69); + if (value) { values[7] = value; kw_args--; } + } + case 8: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__train_min_gap_size); + if (value) { values[8] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_fsarray = values[0]; + __pyx_v_from_stats = values[1]; + __pyx_v_from_binary = values[2]; + __pyx_v_precompute_rank = values[3]; + __pyx_v_precompute_secondary_rank = values[4]; + __pyx_v_max_length = values[5]; + __pyx_v_max_nonterminals = values[6]; + __pyx_v_train_max_initial_size = values[7]; + __pyx_v_train_min_gap_size = values[8]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 9, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.Precomputation.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_14Precomputation___cinit__(((struct __pyx_obj_3_sa_Precomputation *)__pyx_v_self), __pyx_v_fsarray, __pyx_v_from_stats, __pyx_v_from_binary, __pyx_v_precompute_rank, __pyx_v_precompute_secondary_rank, __pyx_v_max_length, __pyx_v_max_nonterminals, __pyx_v_train_max_initial_size, __pyx_v_train_min_gap_size); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_14Precomputation___cinit__(struct __pyx_obj_3_sa_Precomputation *__pyx_v_self, PyObject *__pyx_v_fsarray, PyObject *__pyx_v_from_stats, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_precompute_rank, PyObject *__pyx_v_precompute_secondary_rank, PyObject *__pyx_v_max_length, PyObject *__pyx_v_max_nonterminals, PyObject *__pyx_v_train_max_initial_size, PyObject *__pyx_v_train_min_gap_size) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":204 + * max_length=5, max_nonterminals=2, + * train_max_initial_size=10, train_min_gap_size=2): + * self.precompute_rank = precompute_rank # <<<<<<<<<<<<<< + * self.precompute_secondary_rank = precompute_secondary_rank + * self.max_length = max_length + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_precompute_rank); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->precompute_rank = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":205 + * train_max_initial_size=10, train_min_gap_size=2): + * self.precompute_rank = precompute_rank + * self.precompute_secondary_rank = precompute_secondary_rank # <<<<<<<<<<<<<< + * self.max_length = max_length + * self.max_nonterminals = max_nonterminals + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_precompute_secondary_rank); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->precompute_secondary_rank = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":206 + * self.precompute_rank = precompute_rank + * self.precompute_secondary_rank = precompute_secondary_rank + * self.max_length = max_length # <<<<<<<<<<<<<< + * self.max_nonterminals = max_nonterminals + * self.train_max_initial_size = train_max_initial_size + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_max_length); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->max_length = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":207 + * self.precompute_secondary_rank = precompute_secondary_rank + * self.max_length = max_length + * self.max_nonterminals = max_nonterminals # <<<<<<<<<<<<<< + * self.train_max_initial_size = train_max_initial_size + * self.train_min_gap_size = train_min_gap_size + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_max_nonterminals); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->max_nonterminals = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":208 + * self.max_length = max_length + * self.max_nonterminals = max_nonterminals + * self.train_max_initial_size = train_max_initial_size # <<<<<<<<<<<<<< + * self.train_min_gap_size = train_min_gap_size + * if from_binary: + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_train_max_initial_size); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->train_max_initial_size = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":209 + * self.max_nonterminals = max_nonterminals + * self.train_max_initial_size = train_max_initial_size + * self.train_min_gap_size = train_min_gap_size # <<<<<<<<<<<<<< + * if from_binary: + * self.read_binary(from_binary) + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_train_min_gap_size); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->train_min_gap_size = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":210 + * self.train_max_initial_size = train_max_initial_size + * self.train_min_gap_size = train_min_gap_size + * if from_binary: # <<<<<<<<<<<<<< + * self.read_binary(from_binary) + * elif from_stats: + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_binary); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":211 + * self.train_min_gap_size = train_min_gap_size + * if from_binary: + * self.read_binary(from_binary) # <<<<<<<<<<<<<< + * elif from_stats: + * self.precompute(from_stats, fsarray) + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_binary); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_from_binary); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_from_binary); + __Pyx_GIVEREF(__pyx_v_from_binary); + __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":212 + * if from_binary: + * self.read_binary(from_binary) + * elif from_stats: # <<<<<<<<<<<<<< + * self.precompute(from_stats, fsarray) + * + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_stats); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":213 + * self.read_binary(from_binary) + * elif from_stats: + * self.precompute(from_stats, fsarray) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__precompute); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_from_stats); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_from_stats); + __Pyx_GIVEREF(__pyx_v_from_stats); + __Pyx_INCREF(__pyx_v_fsarray); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_fsarray); + __Pyx_GIVEREF(__pyx_v_fsarray); + __pyx_t_3 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_sa.Precomputation.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_14Precomputation_3read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_14Precomputation_3read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.Precomputation.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_14Precomputation_2read_binary(((struct __pyx_obj_3_sa_Precomputation *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":216 + * + * + * def read_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "r") + */ + +static PyObject *__pyx_pf_3_sa_14Precomputation_2read_binary(struct __pyx_obj_3_sa_Precomputation *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + 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("read_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":218 + * def read_binary(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "r") # <<<<<<<<<<<<<< + * fread(&(self.precompute_rank), sizeof(int), 1, f) + * fread(&(self.precompute_secondary_rank), sizeof(int), 1, f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":219 + * cdef FILE* f + * f = fopen(filename, "r") + * fread(&(self.precompute_rank), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fread(&(self.precompute_secondary_rank), sizeof(int), 1, f) + * fread(&(self.max_length), sizeof(int), 1, f) + */ + fread((&__pyx_v_self->precompute_rank), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":220 + * f = fopen(filename, "r") + * fread(&(self.precompute_rank), sizeof(int), 1, f) + * fread(&(self.precompute_secondary_rank), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fread(&(self.max_length), sizeof(int), 1, f) + * fread(&(self.max_nonterminals), sizeof(int), 1, f) + */ + fread((&__pyx_v_self->precompute_secondary_rank), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":221 + * fread(&(self.precompute_rank), sizeof(int), 1, f) + * fread(&(self.precompute_secondary_rank), sizeof(int), 1, f) + * fread(&(self.max_length), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fread(&(self.max_nonterminals), sizeof(int), 1, f) + * fread(&(self.train_max_initial_size), sizeof(int), 1, f) + */ + fread((&__pyx_v_self->max_length), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":222 + * fread(&(self.precompute_secondary_rank), sizeof(int), 1, f) + * fread(&(self.max_length), sizeof(int), 1, f) + * fread(&(self.max_nonterminals), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fread(&(self.train_max_initial_size), sizeof(int), 1, f) + * fread(&(self.train_min_gap_size), sizeof(int), 1, f) + */ + fread((&__pyx_v_self->max_nonterminals), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":223 + * fread(&(self.max_length), sizeof(int), 1, f) + * fread(&(self.max_nonterminals), sizeof(int), 1, f) + * fread(&(self.train_max_initial_size), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fread(&(self.train_min_gap_size), sizeof(int), 1, f) + * self.precomputed_index = self.read_map(f) + */ + fread((&__pyx_v_self->train_max_initial_size), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":224 + * fread(&(self.max_nonterminals), sizeof(int), 1, f) + * fread(&(self.train_max_initial_size), sizeof(int), 1, f) + * fread(&(self.train_min_gap_size), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * self.precomputed_index = self.read_map(f) + * self.precomputed_collocations = self.read_map(f) + */ + fread((&__pyx_v_self->train_min_gap_size), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":225 + * fread(&(self.train_max_initial_size), sizeof(int), 1, f) + * fread(&(self.train_min_gap_size), sizeof(int), 1, f) + * self.precomputed_index = self.read_map(f) # <<<<<<<<<<<<<< + * self.precomputed_collocations = self.read_map(f) + * fclose(f) + */ + __pyx_t_1 = ((struct __pyx_vtabstruct_3_sa_Precomputation *)__pyx_v_self->__pyx_vtab)->read_map(__pyx_v_self, __pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->precomputed_index); + __Pyx_DECREF(__pyx_v_self->precomputed_index); + __pyx_v_self->precomputed_index = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":226 + * fread(&(self.train_min_gap_size), sizeof(int), 1, f) + * self.precomputed_index = self.read_map(f) + * self.precomputed_collocations = self.read_map(f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + __pyx_t_1 = ((struct __pyx_vtabstruct_3_sa_Precomputation *)__pyx_v_self->__pyx_vtab)->read_map(__pyx_v_self, __pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->precomputed_collocations); + __Pyx_DECREF(__pyx_v_self->precomputed_collocations); + __pyx_v_self->precomputed_collocations = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":227 + * self.precomputed_index = self.read_map(f) + * self.precomputed_collocations = self.read_map(f) + * fclose(f) # <<<<<<<<<<<<<< + * + * + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_sa.Precomputation.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_14Precomputation_5write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_14Precomputation_5write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.Precomputation.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_14Precomputation_4write_binary(((struct __pyx_obj_3_sa_Precomputation *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":230 + * + * + * def write_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "w") + */ + +static PyObject *__pyx_pf_3_sa_14Precomputation_4write_binary(struct __pyx_obj_3_sa_Precomputation *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + 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("write_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":232 + * def write_binary(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "w") # <<<<<<<<<<<<<< + * fwrite(&(self.precompute_rank), sizeof(int), 1, f) + * fwrite(&(self.precompute_secondary_rank), sizeof(int), 1, f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":233 + * cdef FILE* f + * f = fopen(filename, "w") + * fwrite(&(self.precompute_rank), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fwrite(&(self.precompute_secondary_rank), sizeof(int), 1, f) + * fwrite(&(self.max_length), sizeof(int), 1, f) + */ + fwrite((&__pyx_v_self->precompute_rank), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":234 + * f = fopen(filename, "w") + * fwrite(&(self.precompute_rank), sizeof(int), 1, f) + * fwrite(&(self.precompute_secondary_rank), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fwrite(&(self.max_length), sizeof(int), 1, f) + * fwrite(&(self.max_nonterminals), sizeof(int), 1, f) + */ + fwrite((&__pyx_v_self->precompute_secondary_rank), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":235 + * fwrite(&(self.precompute_rank), sizeof(int), 1, f) + * fwrite(&(self.precompute_secondary_rank), sizeof(int), 1, f) + * fwrite(&(self.max_length), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fwrite(&(self.max_nonterminals), sizeof(int), 1, f) + * fwrite(&(self.train_max_initial_size), sizeof(int), 1, f) + */ + fwrite((&__pyx_v_self->max_length), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":236 + * fwrite(&(self.precompute_secondary_rank), sizeof(int), 1, f) + * fwrite(&(self.max_length), sizeof(int), 1, f) + * fwrite(&(self.max_nonterminals), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fwrite(&(self.train_max_initial_size), sizeof(int), 1, f) + * fwrite(&(self.train_min_gap_size), sizeof(int), 1, f) + */ + fwrite((&__pyx_v_self->max_nonterminals), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":237 + * fwrite(&(self.max_length), sizeof(int), 1, f) + * fwrite(&(self.max_nonterminals), sizeof(int), 1, f) + * fwrite(&(self.train_max_initial_size), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * fwrite(&(self.train_min_gap_size), sizeof(int), 1, f) + * self.write_map(self.precomputed_index, f) + */ + fwrite((&__pyx_v_self->train_max_initial_size), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":238 + * fwrite(&(self.max_nonterminals), sizeof(int), 1, f) + * fwrite(&(self.train_max_initial_size), sizeof(int), 1, f) + * fwrite(&(self.train_min_gap_size), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * self.write_map(self.precomputed_index, f) + * self.write_map(self.precomputed_collocations, f) + */ + fwrite((&__pyx_v_self->train_min_gap_size), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":239 + * fwrite(&(self.train_max_initial_size), sizeof(int), 1, f) + * fwrite(&(self.train_min_gap_size), sizeof(int), 1, f) + * self.write_map(self.precomputed_index, f) # <<<<<<<<<<<<<< + * self.write_map(self.precomputed_collocations, f) + * fclose(f) + */ + __pyx_t_1 = __pyx_v_self->precomputed_index; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_Precomputation *)__pyx_v_self->__pyx_vtab)->write_map(__pyx_v_self, __pyx_t_1, __pyx_v_f); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":240 + * fwrite(&(self.train_min_gap_size), sizeof(int), 1, f) + * self.write_map(self.precomputed_index, f) + * self.write_map(self.precomputed_collocations, f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + __pyx_t_2 = __pyx_v_self->precomputed_collocations; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_1 = ((struct __pyx_vtabstruct_3_sa_Precomputation *)__pyx_v_self->__pyx_vtab)->write_map(__pyx_v_self, __pyx_t_2, __pyx_v_f); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 240; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":241 + * self.write_map(self.precomputed_index, f) + * self.write_map(self.precomputed_collocations, f) + * fclose(f) # <<<<<<<<<<<<<< + * + * + */ + fclose(__pyx_v_f); + + __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("_sa.Precomputation.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":244 + * + * + * cdef write_map(self, m, FILE* f): # <<<<<<<<<<<<<< + * cdef int i, N + * cdef IntList arr + */ + +static PyObject *__pyx_f_3_sa_14Precomputation_write_map(CYTHON_UNUSED struct __pyx_obj_3_sa_Precomputation *__pyx_v_self, PyObject *__pyx_v_m, FILE *__pyx_v_f) { + int __pyx_v_i; + int __pyx_v_N; + struct __pyx_obj_3_sa_IntList *__pyx_v_arr = 0; + PyObject *__pyx_v_pattern = NULL; + PyObject *__pyx_v_val = NULL; + PyObject *__pyx_v_word_id = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_map", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":248 + * cdef IntList arr + * + * N = len(m) # <<<<<<<<<<<<<< + * fwrite(&(N), sizeof(int), 1, f) + * for pattern, val in m.iteritems(): + */ + __pyx_t_1 = PyObject_Length(__pyx_v_m); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_N = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":249 + * + * N = len(m) + * fwrite(&(N), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * for pattern, val in m.iteritems(): + * N = len(pattern) + */ + fwrite((&__pyx_v_N), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":250 + * N = len(m) + * fwrite(&(N), sizeof(int), 1, f) + * for pattern, val in m.iteritems(): # <<<<<<<<<<<<<< + * N = len(pattern) + * fwrite(&(N), sizeof(int), 1, f) + */ + __pyx_t_1 = 0; + if (unlikely(__pyx_v_m == Py_None)) { + PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "iteritems"); + {__pyx_filename = __pyx_f[12]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_5 = __Pyx_dict_iterator(__pyx_v_m, 0, ((PyObject *)__pyx_n_s__iteritems), (&__pyx_t_3), (&__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_2); + __pyx_t_2 = __pyx_t_5; + __pyx_t_5 = 0; + while (1) { + __pyx_t_7 = __Pyx_dict_iter_next(__pyx_t_2, __pyx_t_3, &__pyx_t_1, &__pyx_t_5, &__pyx_t_6, NULL, __pyx_t_4); + if (unlikely(__pyx_t_7 == 0)) break; + if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_v_pattern); + __pyx_v_pattern = __pyx_t_5; + __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_v_val); + __pyx_v_val = __pyx_t_6; + __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":251 + * fwrite(&(N), sizeof(int), 1, f) + * for pattern, val in m.iteritems(): + * N = len(pattern) # <<<<<<<<<<<<<< + * fwrite(&(N), sizeof(int), 1, f) + * for word_id in pattern: + */ + __pyx_t_8 = PyObject_Length(__pyx_v_pattern); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 251; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_N = __pyx_t_8; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":252 + * for pattern, val in m.iteritems(): + * N = len(pattern) + * fwrite(&(N), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * for word_id in pattern: + * i = word_id + */ + fwrite((&__pyx_v_N), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":253 + * N = len(pattern) + * fwrite(&(N), sizeof(int), 1, f) + * for word_id in pattern: # <<<<<<<<<<<<<< + * i = word_id + * fwrite(&(i), sizeof(int), 1, f) + */ + if (PyList_CheckExact(__pyx_v_pattern) || PyTuple_CheckExact(__pyx_v_pattern)) { + __pyx_t_6 = __pyx_v_pattern; __Pyx_INCREF(__pyx_t_6); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_v_pattern); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_9 = Py_TYPE(__pyx_t_6)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_6)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_6)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_8); __Pyx_INCREF(__pyx_t_5); __pyx_t_8++; + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_6, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_6)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_6)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_8); __Pyx_INCREF(__pyx_t_5); __pyx_t_8++; + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_6, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_5 = __pyx_t_9(__pyx_t_6); + if (unlikely(!__pyx_t_5)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[12]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_5); + } + __Pyx_XDECREF(__pyx_v_word_id); + __pyx_v_word_id = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":254 + * fwrite(&(N), sizeof(int), 1, f) + * for word_id in pattern: + * i = word_id # <<<<<<<<<<<<<< + * fwrite(&(i), sizeof(int), 1, f) + * arr = val + */ + __pyx_t_7 = __Pyx_PyInt_AsInt(__pyx_v_word_id); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_i = __pyx_t_7; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":255 + * for word_id in pattern: + * i = word_id + * fwrite(&(i), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * arr = val + * arr.write_handle(f) + */ + fwrite((&__pyx_v_i), (sizeof(int)), 1, __pyx_v_f); + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":256 + * i = word_id + * fwrite(&(i), sizeof(int), 1, f) + * arr = val # <<<<<<<<<<<<<< + * arr.write_handle(f) + * + */ + if (!(likely(((__pyx_v_val) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_val, __pyx_ptype_3_sa_IntList))))) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_val); + __Pyx_XDECREF(((PyObject *)__pyx_v_arr)); + __pyx_v_arr = ((struct __pyx_obj_3_sa_IntList *)__pyx_v_val); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":257 + * fwrite(&(i), sizeof(int), 1, f) + * arr = val + * arr.write_handle(f) # <<<<<<<<<<<<<< + * + * + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_arr->__pyx_vtab)->write_handle(__pyx_v_arr, __pyx_v_f); + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_sa.Precomputation.write_map", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_arr); + __Pyx_XDECREF(__pyx_v_pattern); + __Pyx_XDECREF(__pyx_v_val); + __Pyx_XDECREF(__pyx_v_word_id); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":260 + * + * + * cdef read_map(self, FILE* f): # <<<<<<<<<<<<<< + * cdef int i, j, k, word_id, N + * cdef IntList arr + */ + +static PyObject *__pyx_f_3_sa_14Precomputation_read_map(CYTHON_UNUSED struct __pyx_obj_3_sa_Precomputation *__pyx_v_self, FILE *__pyx_v_f) { + int __pyx_v_i; + CYTHON_UNUSED int __pyx_v_j; + CYTHON_UNUSED int __pyx_v_k; + int __pyx_v_word_id; + int __pyx_v_N; + struct __pyx_obj_3_sa_IntList *__pyx_v_arr = 0; + PyObject *__pyx_v_m = NULL; + PyObject *__pyx_v_key = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_map", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":264 + * cdef IntList arr + * + * m = {} # <<<<<<<<<<<<<< + * fread(&(N), sizeof(int), 1, f) + * for j from 0 <= j < N: + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 264; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_v_m = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":265 + * + * m = {} + * fread(&(N), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * for j from 0 <= j < N: + * fread(&(i), sizeof(int), 1, f) + */ + fread((&__pyx_v_N), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":266 + * m = {} + * fread(&(N), sizeof(int), 1, f) + * for j from 0 <= j < N: # <<<<<<<<<<<<<< + * fread(&(i), sizeof(int), 1, f) + * key = () + */ + __pyx_t_2 = __pyx_v_N; + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_2; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":267 + * fread(&(N), sizeof(int), 1, f) + * for j from 0 <= j < N: + * fread(&(i), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * key = () + * for k from 0 <= k < i: + */ + fread((&__pyx_v_i), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":268 + * for j from 0 <= j < N: + * fread(&(i), sizeof(int), 1, f) + * key = () # <<<<<<<<<<<<<< + * for k from 0 <= k < i: + * fread(&(word_id), sizeof(int), 1, f) + */ + __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); + __Pyx_XDECREF(((PyObject *)__pyx_v_key)); + __pyx_v_key = __pyx_empty_tuple; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":269 + * fread(&(i), sizeof(int), 1, f) + * key = () + * for k from 0 <= k < i: # <<<<<<<<<<<<<< + * fread(&(word_id), sizeof(int), 1, f) + * key = key + (word_id,) + */ + __pyx_t_3 = __pyx_v_i; + for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_3; __pyx_v_k++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":270 + * key = () + * for k from 0 <= k < i: + * fread(&(word_id), sizeof(int), 1, f) # <<<<<<<<<<<<<< + * key = key + (word_id,) + * arr = IntList() + */ + fread((&__pyx_v_word_id), (sizeof(int)), 1, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":271 + * for k from 0 <= k < i: + * fread(&(word_id), sizeof(int), 1, f) + * key = key + (word_id,) # <<<<<<<<<<<<<< + * arr = IntList() + * arr.read_handle(f) + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_word_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Add(((PyObject *)__pyx_v_key), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_key)); + __pyx_v_key = __pyx_t_1; + __pyx_t_1 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":272 + * fread(&(word_id), sizeof(int), 1, f) + * key = key + (word_id,) + * arr = IntList() # <<<<<<<<<<<<<< + * arr.read_handle(f) + * m[key] = arr + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 272; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF(((PyObject *)__pyx_v_arr)); + __pyx_v_arr = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":273 + * key = key + (word_id,) + * arr = IntList() + * arr.read_handle(f) # <<<<<<<<<<<<<< + * m[key] = arr + * return m + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_arr->__pyx_vtab)->read_handle(__pyx_v_arr, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":274 + * arr = IntList() + * arr.read_handle(f) + * m[key] = arr # <<<<<<<<<<<<<< + * return m + * + */ + if (PyDict_SetItem(((PyObject *)__pyx_v_m), ((PyObject *)__pyx_v_key), ((PyObject *)__pyx_v_arr)) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":275 + * arr.read_handle(f) + * m[key] = arr + * return m # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_m)); + __pyx_r = ((PyObject *)__pyx_v_m); + 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_4); + __Pyx_AddTraceback("_sa.Precomputation.read_map", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_arr); + __Pyx_XDECREF(__pyx_v_m); + __Pyx_XDECREF(__pyx_v_key); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_14Precomputation_7precompute(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_3_sa_14Precomputation_7precompute(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_stats = 0; + struct __pyx_obj_3_sa_SuffixArray *__pyx_v_sarray = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("precompute (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__stats,&__pyx_n_s__sarray,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__stats)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sarray)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("precompute", 1, 2, 2, 1); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "precompute") < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_stats = values[0]; + __pyx_v_sarray = ((struct __pyx_obj_3_sa_SuffixArray *)values[1]); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("precompute", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[12]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.Precomputation.precompute", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_sarray), __pyx_ptype_3_sa_SuffixArray, 1, "sarray", 0))) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_3_sa_14Precomputation_6precompute(((struct __pyx_obj_3_sa_Precomputation *)__pyx_v_self), __pyx_v_stats, __pyx_v_sarray); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":278 + * + * + * def precompute(self, stats, SuffixArray sarray): # <<<<<<<<<<<<<< + * cdef int i, l, N, max_pattern_len, i1, l1, i2, l2, i3, l3, ptr1, ptr2, ptr3, is_super, sent_count, max_rank + * cdef DataArray darray = sarray.darray + */ + +static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_sa_Precomputation *__pyx_v_self, PyObject *__pyx_v_stats, struct __pyx_obj_3_sa_SuffixArray *__pyx_v_sarray) { + int __pyx_v_i; + int __pyx_v_l; + int __pyx_v_N; + int __pyx_v_max_pattern_len; + int __pyx_v_i1; + int __pyx_v_l1; + int __pyx_v_i2; + int __pyx_v_l2; + int __pyx_v_i3; + int __pyx_v_l3; + int __pyx_v_ptr1; + int __pyx_v_ptr2; + int __pyx_v_ptr3; + int __pyx_v_is_super; + int __pyx_v_sent_count; + int __pyx_v_max_rank; + struct __pyx_obj_3_sa_DataArray *__pyx_v_darray = 0; + struct __pyx_obj_3_sa_IntList *__pyx_v_data = 0; + struct __pyx_obj_3_sa_IntList *__pyx_v_queue = 0; + struct __pyx_obj_3_sa_IntList *__pyx_v_cost_by_rank = 0; + struct __pyx_obj_3_sa_IntList *__pyx_v_count_by_rank = 0; + struct __pyx_obj_3_sa_TrieMap *__pyx_v_frequent_patterns = 0; + struct __pyx_obj_3_sa_TrieMap *__pyx_v_super_frequent_patterns = 0; + struct __pyx_obj_3_sa_TrieMap *__pyx_v_collocations = 0; + struct __pyx_t_3_sa__Trie_Node *__pyx_v_node; + PyObject *__pyx_v_I_set = NULL; + PyObject *__pyx_v_J_set = NULL; + PyObject *__pyx_v_J2_set = NULL; + PyObject *__pyx_v_IJ_set = NULL; + PyObject *__pyx_v_pattern_rank = NULL; + float __pyx_v_start_time; + PyObject *__pyx_v_rank = NULL; + CYTHON_UNUSED PyObject *__pyx_v__ = NULL; + PyObject *__pyx_v_phrase = NULL; + int __pyx_v_sa_word_id; + PyObject *__pyx_v_x = NULL; + PyObject *__pyx_v_pattern1 = NULL; + PyObject *__pyx_v_pattern2 = NULL; + PyObject *__pyx_v_combined_pattern = NULL; + PyObject *__pyx_v_pattern = NULL; + PyObject *__pyx_v_arr = NULL; + PyObject *__pyx_v_s = NULL; + PyObject *__pyx_v_word_id = NULL; + PyObject *__pyx_v_chunk = NULL; + PyObject *__pyx_v_arity = NULL; + PyObject *__pyx_v_cumul_cost = NULL; + PyObject *__pyx_v_cumul_count = NULL; + PyObject *__pyx_v_num_found_patterns = NULL; + float __pyx_v_stop_time; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *(*__pyx_t_4)(PyObject *); + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *(*__pyx_t_10)(PyObject *); + int __pyx_t_11; + Py_ssize_t __pyx_t_12; + int __pyx_t_13; + Py_ssize_t __pyx_t_14; + int __pyx_t_15; + int __pyx_t_16; + int __pyx_t_17; + int __pyx_t_18; + int __pyx_t_19; + PyObject *(*__pyx_t_20)(PyObject *); + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("precompute", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":280 + * def precompute(self, stats, SuffixArray sarray): + * cdef int i, l, N, max_pattern_len, i1, l1, i2, l2, i3, l3, ptr1, ptr2, ptr3, is_super, sent_count, max_rank + * cdef DataArray darray = sarray.darray # <<<<<<<<<<<<<< + * cdef IntList data, queue, cost_by_rank, count_by_rank + * cdef TrieMap frequent_patterns, super_frequent_patterns, collocations + */ + __Pyx_INCREF(((PyObject *)__pyx_v_sarray->darray)); + __pyx_v_darray = __pyx_v_sarray->darray; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":285 + * cdef _Trie_Node* node + * + * data = darray.data # <<<<<<<<<<<<<< + * + * frequent_patterns = TrieMap(len(darray.id2word)) + */ + __Pyx_INCREF(((PyObject *)__pyx_v_darray->data)); + __pyx_v_data = __pyx_v_darray->data; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":287 + * data = darray.data + * + * frequent_patterns = TrieMap(len(darray.id2word)) # <<<<<<<<<<<<<< + * super_frequent_patterns = TrieMap(len(darray.id2word)) + * collocations = TrieMap(len(darray.id2word)) + */ + __pyx_t_1 = __pyx_v_darray->id2word; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_TrieMap)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_v_frequent_patterns = ((struct __pyx_obj_3_sa_TrieMap *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":288 + * + * frequent_patterns = TrieMap(len(darray.id2word)) + * super_frequent_patterns = TrieMap(len(darray.id2word)) # <<<<<<<<<<<<<< + * collocations = TrieMap(len(darray.id2word)) + * + */ + __pyx_t_1 = __pyx_v_darray->id2word; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_TrieMap)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_v_super_frequent_patterns = ((struct __pyx_obj_3_sa_TrieMap *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":289 + * frequent_patterns = TrieMap(len(darray.id2word)) + * super_frequent_patterns = TrieMap(len(darray.id2word)) + * collocations = TrieMap(len(darray.id2word)) # <<<<<<<<<<<<<< + * + * I_set = set() + */ + __pyx_t_1 = __pyx_v_darray->id2word; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_TrieMap)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_v_collocations = ((struct __pyx_obj_3_sa_TrieMap *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":291 + * collocations = TrieMap(len(darray.id2word)) + * + * I_set = set() # <<<<<<<<<<<<<< + * J_set = set() + * J2_set = set() + */ + __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_v_I_set = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":292 + * + * I_set = set() + * J_set = set() # <<<<<<<<<<<<<< + * J2_set = set() + * IJ_set = set() + */ + __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_v_J_set = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":293 + * I_set = set() + * J_set = set() + * J2_set = set() # <<<<<<<<<<<<<< + * IJ_set = set() + * pattern_rank = {} + */ + __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_v_J2_set = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":294 + * J_set = set() + * J2_set = set() + * IJ_set = set() # <<<<<<<<<<<<<< + * pattern_rank = {} + * + */ + __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_v_IJ_set = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":295 + * J2_set = set() + * IJ_set = set() + * pattern_rank = {} # <<<<<<<<<<<<<< + * + * logger.info("Precomputing frequent intersections") + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_v_pattern_rank = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":297 + * pattern_rank = {} + * + * logger.info("Precomputing frequent intersections") # <<<<<<<<<<<<<< + * cdef float start_time = monitor_cpu() + * + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__info); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_71), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":298 + * + * logger.info("Precomputing frequent intersections") + * cdef float start_time = monitor_cpu() # <<<<<<<<<<<<<< + * + * max_pattern_len = 0 + */ + __pyx_v_start_time = __pyx_f_3_sa_monitor_cpu(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":300 + * cdef float start_time = monitor_cpu() + * + * max_pattern_len = 0 # <<<<<<<<<<<<<< + * for rank, (_, _, phrase) in enumerate(stats): + * if rank >= self.precompute_rank: + */ + __pyx_v_max_pattern_len = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":301 + * + * max_pattern_len = 0 + * for rank, (_, _, phrase) in enumerate(stats): # <<<<<<<<<<<<<< + * if rank >= self.precompute_rank: + * break + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_1 = __pyx_int_0; + if (PyList_CheckExact(__pyx_v_stats) || PyTuple_CheckExact(__pyx_v_stats)) { + __pyx_t_3 = __pyx_v_stats; __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_stats); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; + } + for (;;) { + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_5 = __pyx_t_4(__pyx_t_3); + if (unlikely(!__pyx_t_5)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[12]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_5); + } + if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) { + PyObject* sequence = __pyx_t_5; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 3)) { + if (size > 3) __Pyx_RaiseTooManyValuesError(3); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[12]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_8 = PyTuple_GET_ITEM(sequence, 2); + } else { + __pyx_t_6 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + __pyx_t_8 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + #else + __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } else + { + Py_ssize_t index = -1; + __pyx_t_9 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; + index = 0; __pyx_t_6 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + index = 1; __pyx_t_7 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_7)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + index = 2; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_8); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 3) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_10 = NULL; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L6_unpacking_done; + __pyx_L5_unpacking_failed:; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_10 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[12]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L6_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v__); + __pyx_v__ = __pyx_t_6; + __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_v__); + __pyx_v__ = __pyx_t_7; + __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_v_phrase); + __pyx_v_phrase = __pyx_t_8; + __pyx_t_8 = 0; + __Pyx_INCREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_rank); + __pyx_v_rank = __pyx_t_1; + __pyx_t_5 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); + __pyx_t_1 = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":302 + * max_pattern_len = 0 + * for rank, (_, _, phrase) in enumerate(stats): + * if rank >= self.precompute_rank: # <<<<<<<<<<<<<< + * break + * max_pattern_len = max(max_pattern_len, len(phrase)) + */ + __pyx_t_5 = PyInt_FromLong(__pyx_v_self->precompute_rank); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = PyObject_RichCompare(__pyx_v_rank, __pyx_t_5, Py_GE); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":303 + * for rank, (_, _, phrase) in enumerate(stats): + * if rank >= self.precompute_rank: + * break # <<<<<<<<<<<<<< + * max_pattern_len = max(max_pattern_len, len(phrase)) + * frequent_patterns.insert(phrase) + */ + goto __pyx_L4_break; + goto __pyx_L7; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":304 + * if rank >= self.precompute_rank: + * break + * max_pattern_len = max(max_pattern_len, len(phrase)) # <<<<<<<<<<<<<< + * frequent_patterns.insert(phrase) + * I_set.add(phrase) + */ + __pyx_t_12 = PyObject_Length(__pyx_v_phrase); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_13 = __pyx_v_max_pattern_len; + if ((__pyx_t_12 > __pyx_t_13)) { + __pyx_t_14 = __pyx_t_12; + } else { + __pyx_t_14 = __pyx_t_13; + } + __pyx_v_max_pattern_len = __pyx_t_14; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":305 + * break + * max_pattern_len = max(max_pattern_len, len(phrase)) + * frequent_patterns.insert(phrase) # <<<<<<<<<<<<<< + * I_set.add(phrase) + * pattern_rank[phrase] = rank + */ + __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_v_frequent_patterns), __pyx_n_s__insert); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_phrase); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_phrase); + __Pyx_GIVEREF(__pyx_v_phrase); + __pyx_t_7 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 305; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":306 + * max_pattern_len = max(max_pattern_len, len(phrase)) + * frequent_patterns.insert(phrase) + * I_set.add(phrase) # <<<<<<<<<<<<<< + * pattern_rank[phrase] = rank + * if rank < self.precompute_secondary_rank: + */ + __pyx_t_15 = PySet_Add(__pyx_v_I_set, __pyx_v_phrase); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":307 + * frequent_patterns.insert(phrase) + * I_set.add(phrase) + * pattern_rank[phrase] = rank # <<<<<<<<<<<<<< + * if rank < self.precompute_secondary_rank: + * super_frequent_patterns.insert(phrase) + */ + if (PyDict_SetItem(((PyObject *)__pyx_v_pattern_rank), __pyx_v_phrase, __pyx_v_rank) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 307; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":308 + * I_set.add(phrase) + * pattern_rank[phrase] = rank + * if rank < self.precompute_secondary_rank: # <<<<<<<<<<<<<< + * super_frequent_patterns.insert(phrase) + * J_set.add(phrase) + */ + __pyx_t_7 = PyInt_FromLong(__pyx_v_self->precompute_secondary_rank); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_rank, __pyx_t_7, Py_LT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":309 + * pattern_rank[phrase] = rank + * if rank < self.precompute_secondary_rank: + * super_frequent_patterns.insert(phrase) # <<<<<<<<<<<<<< + * J_set.add(phrase) + * + */ + __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_super_frequent_patterns), __pyx_n_s__insert); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_v_phrase); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_phrase); + __Pyx_GIVEREF(__pyx_v_phrase); + __pyx_t_8 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 309; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":310 + * if rank < self.precompute_secondary_rank: + * super_frequent_patterns.insert(phrase) + * J_set.add(phrase) # <<<<<<<<<<<<<< + * + * queue = IntList(increment=1000) + */ + __pyx_t_15 = PySet_Add(__pyx_v_J_set, __pyx_v_phrase); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L8; + } + __pyx_L8:; + } + __pyx_L4_break:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":312 + * J_set.add(phrase) + * + * queue = IntList(increment=1000) # <<<<<<<<<<<<<< + * + * logger.info(" Computing inverted indexes...") + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 312; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__increment), __pyx_int_1000) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 312; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 312; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_v_queue = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":314 + * queue = IntList(increment=1000) + * + * logger.info(" Computing inverted indexes...") # <<<<<<<<<<<<<< + * N = len(data) + * for i from 0 <= i < N: + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_73), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":315 + * + * logger.info(" Computing inverted indexes...") + * N = len(data) # <<<<<<<<<<<<<< + * for i from 0 <= i < N: + * sa_word_id = data.arr[i] + */ + __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_data)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 315; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_N = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":316 + * logger.info(" Computing inverted indexes...") + * N = len(data) + * for i from 0 <= i < N: # <<<<<<<<<<<<<< + * sa_word_id = data.arr[i] + * if sa_word_id == 1: + */ + __pyx_t_13 = __pyx_v_N; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_13; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":317 + * N = len(data) + * for i from 0 <= i < N: + * sa_word_id = data.arr[i] # <<<<<<<<<<<<<< + * if sa_word_id == 1: + * queue._append(-1) + */ + __pyx_v_sa_word_id = (__pyx_v_data->arr[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":318 + * for i from 0 <= i < N: + * sa_word_id = data.arr[i] + * if sa_word_id == 1: # <<<<<<<<<<<<<< + * queue._append(-1) + * else: + */ + __pyx_t_11 = (__pyx_v_sa_word_id == 1); + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":319 + * sa_word_id = data.arr[i] + * if sa_word_id == 1: + * queue._append(-1) # <<<<<<<<<<<<<< + * else: + * for l from 1 <= l <= max_pattern_len: + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_queue->__pyx_vtab)->_append(__pyx_v_queue, -1); + goto __pyx_L11; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":321 + * queue._append(-1) + * else: + * for l from 1 <= l <= max_pattern_len: # <<<<<<<<<<<<<< + * node = frequent_patterns._contains(data.arr+i, l) + * if node == NULL: + */ + __pyx_t_16 = __pyx_v_max_pattern_len; + for (__pyx_v_l = 1; __pyx_v_l <= __pyx_t_16; __pyx_v_l++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":322 + * else: + * for l from 1 <= l <= max_pattern_len: + * node = frequent_patterns._contains(data.arr+i, l) # <<<<<<<<<<<<<< + * if node == NULL: + * break + */ + __pyx_v_node = ((struct __pyx_vtabstruct_3_sa_TrieMap *)__pyx_v_frequent_patterns->__pyx_vtab)->_contains(__pyx_v_frequent_patterns, (__pyx_v_data->arr + __pyx_v_i), __pyx_v_l); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":323 + * for l from 1 <= l <= max_pattern_len: + * node = frequent_patterns._contains(data.arr+i, l) + * if node == NULL: # <<<<<<<<<<<<<< + * break + * queue._append(i) + */ + __pyx_t_11 = (__pyx_v_node == NULL); + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":324 + * node = frequent_patterns._contains(data.arr+i, l) + * if node == NULL: + * break # <<<<<<<<<<<<<< + * queue._append(i) + * queue._append(l) + */ + goto __pyx_L13_break; + goto __pyx_L14; + } + __pyx_L14:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":325 + * if node == NULL: + * break + * queue._append(i) # <<<<<<<<<<<<<< + * queue._append(l) + * trie_node_data_append(node, i) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_queue->__pyx_vtab)->_append(__pyx_v_queue, __pyx_v_i); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":326 + * break + * queue._append(i) + * queue._append(l) # <<<<<<<<<<<<<< + * trie_node_data_append(node, i) + * + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_queue->__pyx_vtab)->_append(__pyx_v_queue, __pyx_v_l); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":327 + * queue._append(i) + * queue._append(l) + * trie_node_data_append(node, i) # <<<<<<<<<<<<<< + * + * logger.info(" Computing collocations...") + */ + __pyx_t_3 = __pyx_f_3_sa_trie_node_data_append(__pyx_v_node, __pyx_v_i); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __pyx_L13_break:; + } + __pyx_L11:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":329 + * trie_node_data_append(node, i) + * + * logger.info(" Computing collocations...") # <<<<<<<<<<<<<< + * N = len(queue) + * ptr1 = 0 + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_75), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":330 + * + * logger.info(" Computing collocations...") + * N = len(queue) # <<<<<<<<<<<<<< + * ptr1 = 0 + * sent_count = 0 + */ + __pyx_t_2 = PyObject_Length(((PyObject *)__pyx_v_queue)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_N = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":331 + * logger.info(" Computing collocations...") + * N = len(queue) + * ptr1 = 0 # <<<<<<<<<<<<<< + * sent_count = 0 + * while ptr1 < N: # main loop + */ + __pyx_v_ptr1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":332 + * N = len(queue) + * ptr1 = 0 + * sent_count = 0 # <<<<<<<<<<<<<< + * while ptr1 < N: # main loop + * i1 = queue.arr[ptr1] + */ + __pyx_v_sent_count = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":333 + * ptr1 = 0 + * sent_count = 0 + * while ptr1 < N: # main loop # <<<<<<<<<<<<<< + * i1 = queue.arr[ptr1] + * if i1 > -1: + */ + while (1) { + __pyx_t_11 = (__pyx_v_ptr1 < __pyx_v_N); + if (!__pyx_t_11) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":334 + * sent_count = 0 + * while ptr1 < N: # main loop + * i1 = queue.arr[ptr1] # <<<<<<<<<<<<<< + * if i1 > -1: + * l1 = queue.arr[ptr1+1] + */ + __pyx_v_i1 = (__pyx_v_queue->arr[__pyx_v_ptr1]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":335 + * while ptr1 < N: # main loop + * i1 = queue.arr[ptr1] + * if i1 > -1: # <<<<<<<<<<<<<< + * l1 = queue.arr[ptr1+1] + * ptr2 = ptr1 + 2 + */ + __pyx_t_11 = (__pyx_v_i1 > -1); + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":336 + * i1 = queue.arr[ptr1] + * if i1 > -1: + * l1 = queue.arr[ptr1+1] # <<<<<<<<<<<<<< + * ptr2 = ptr1 + 2 + * while ptr2 < N: + */ + __pyx_v_l1 = (__pyx_v_queue->arr[(__pyx_v_ptr1 + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":337 + * if i1 > -1: + * l1 = queue.arr[ptr1+1] + * ptr2 = ptr1 + 2 # <<<<<<<<<<<<<< + * while ptr2 < N: + * i2 = queue.arr[ptr2] + */ + __pyx_v_ptr2 = (__pyx_v_ptr1 + 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":338 + * l1 = queue.arr[ptr1+1] + * ptr2 = ptr1 + 2 + * while ptr2 < N: # <<<<<<<<<<<<<< + * i2 = queue.arr[ptr2] + * if i2 == -1 or i2 - i1 >= self.train_max_initial_size: + */ + while (1) { + __pyx_t_11 = (__pyx_v_ptr2 < __pyx_v_N); + if (!__pyx_t_11) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":339 + * ptr2 = ptr1 + 2 + * while ptr2 < N: + * i2 = queue.arr[ptr2] # <<<<<<<<<<<<<< + * if i2 == -1 or i2 - i1 >= self.train_max_initial_size: + * break + */ + __pyx_v_i2 = (__pyx_v_queue->arr[__pyx_v_ptr2]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":340 + * while ptr2 < N: + * i2 = queue.arr[ptr2] + * if i2 == -1 or i2 - i1 >= self.train_max_initial_size: # <<<<<<<<<<<<<< + * break + * l2 = queue.arr[ptr2+1] + */ + __pyx_t_11 = (__pyx_v_i2 == -1); + if (!__pyx_t_11) { + __pyx_t_17 = ((__pyx_v_i2 - __pyx_v_i1) >= __pyx_v_self->train_max_initial_size); + __pyx_t_18 = __pyx_t_17; + } else { + __pyx_t_18 = __pyx_t_11; + } + if (__pyx_t_18) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":341 + * i2 = queue.arr[ptr2] + * if i2 == -1 or i2 - i1 >= self.train_max_initial_size: + * break # <<<<<<<<<<<<<< + * l2 = queue.arr[ptr2+1] + * if (i2 - i1 - l1 >= self.train_min_gap_size and + */ + goto __pyx_L19_break; + goto __pyx_L20; + } + __pyx_L20:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":342 + * if i2 == -1 or i2 - i1 >= self.train_max_initial_size: + * break + * l2 = queue.arr[ptr2+1] # <<<<<<<<<<<<<< + * if (i2 - i1 - l1 >= self.train_min_gap_size and + * i2 + l2 - i1 <= self.train_max_initial_size and + */ + __pyx_v_l2 = (__pyx_v_queue->arr[(__pyx_v_ptr2 + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":343 + * break + * l2 = queue.arr[ptr2+1] + * if (i2 - i1 - l1 >= self.train_min_gap_size and # <<<<<<<<<<<<<< + * i2 + l2 - i1 <= self.train_max_initial_size and + * l1+l2+1 <= self.max_length): + */ + __pyx_t_18 = (((__pyx_v_i2 - __pyx_v_i1) - __pyx_v_l1) >= __pyx_v_self->train_min_gap_size); + if (__pyx_t_18) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":344 + * l2 = queue.arr[ptr2+1] + * if (i2 - i1 - l1 >= self.train_min_gap_size and + * i2 + l2 - i1 <= self.train_max_initial_size and # <<<<<<<<<<<<<< + * l1+l2+1 <= self.max_length): + * node = collocations._insert(data.arr+i1, l1) + */ + __pyx_t_11 = (((__pyx_v_i2 + __pyx_v_l2) - __pyx_v_i1) <= __pyx_v_self->train_max_initial_size); + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":345 + * if (i2 - i1 - l1 >= self.train_min_gap_size and + * i2 + l2 - i1 <= self.train_max_initial_size and + * l1+l2+1 <= self.max_length): # <<<<<<<<<<<<<< + * node = collocations._insert(data.arr+i1, l1) + * node = trie_insert(node, -1) + */ + __pyx_t_17 = (((__pyx_v_l1 + __pyx_v_l2) + 1) <= __pyx_v_self->max_length); + __pyx_t_19 = __pyx_t_17; + } else { + __pyx_t_19 = __pyx_t_11; + } + __pyx_t_11 = __pyx_t_19; + } else { + __pyx_t_11 = __pyx_t_18; + } + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":346 + * i2 + l2 - i1 <= self.train_max_initial_size and + * l1+l2+1 <= self.max_length): + * node = collocations._insert(data.arr+i1, l1) # <<<<<<<<<<<<<< + * node = trie_insert(node, -1) + * for i from i2 <= i < i2+l2: + */ + __pyx_v_node = ((struct __pyx_vtabstruct_3_sa_TrieMap *)__pyx_v_collocations->__pyx_vtab)->_insert(__pyx_v_collocations, (__pyx_v_data->arr + __pyx_v_i1), __pyx_v_l1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":347 + * l1+l2+1 <= self.max_length): + * node = collocations._insert(data.arr+i1, l1) + * node = trie_insert(node, -1) # <<<<<<<<<<<<<< + * for i from i2 <= i < i2+l2: + * node = trie_insert(node, data.arr[i]) + */ + __pyx_v_node = __pyx_f_3_sa_trie_insert(__pyx_v_node, -1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":348 + * node = collocations._insert(data.arr+i1, l1) + * node = trie_insert(node, -1) + * for i from i2 <= i < i2+l2: # <<<<<<<<<<<<<< + * node = trie_insert(node, data.arr[i]) + * trie_node_data_append(node, i1) + */ + __pyx_t_13 = (__pyx_v_i2 + __pyx_v_l2); + for (__pyx_v_i = __pyx_v_i2; __pyx_v_i < __pyx_t_13; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":349 + * node = trie_insert(node, -1) + * for i from i2 <= i < i2+l2: + * node = trie_insert(node, data.arr[i]) # <<<<<<<<<<<<<< + * trie_node_data_append(node, i1) + * trie_node_data_append(node, i2) + */ + __pyx_v_node = __pyx_f_3_sa_trie_insert(__pyx_v_node, (__pyx_v_data->arr[__pyx_v_i])); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":350 + * for i from i2 <= i < i2+l2: + * node = trie_insert(node, data.arr[i]) + * trie_node_data_append(node, i1) # <<<<<<<<<<<<<< + * trie_node_data_append(node, i2) + * if super_frequent_patterns._contains(data.arr+i2, l2) != NULL: + */ + __pyx_t_3 = __pyx_f_3_sa_trie_node_data_append(__pyx_v_node, __pyx_v_i1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":351 + * node = trie_insert(node, data.arr[i]) + * trie_node_data_append(node, i1) + * trie_node_data_append(node, i2) # <<<<<<<<<<<<<< + * if super_frequent_patterns._contains(data.arr+i2, l2) != NULL: + * if super_frequent_patterns._contains(data.arr+i1, l1) != NULL: + */ + __pyx_t_3 = __pyx_f_3_sa_trie_node_data_append(__pyx_v_node, __pyx_v_i2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 351; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":352 + * trie_node_data_append(node, i1) + * trie_node_data_append(node, i2) + * if super_frequent_patterns._contains(data.arr+i2, l2) != NULL: # <<<<<<<<<<<<<< + * if super_frequent_patterns._contains(data.arr+i1, l1) != NULL: + * is_super = 1 + */ + __pyx_t_11 = (((struct __pyx_vtabstruct_3_sa_TrieMap *)__pyx_v_super_frequent_patterns->__pyx_vtab)->_contains(__pyx_v_super_frequent_patterns, (__pyx_v_data->arr + __pyx_v_i2), __pyx_v_l2) != NULL); + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":353 + * trie_node_data_append(node, i2) + * if super_frequent_patterns._contains(data.arr+i2, l2) != NULL: + * if super_frequent_patterns._contains(data.arr+i1, l1) != NULL: # <<<<<<<<<<<<<< + * is_super = 1 + * else: + */ + __pyx_t_11 = (((struct __pyx_vtabstruct_3_sa_TrieMap *)__pyx_v_super_frequent_patterns->__pyx_vtab)->_contains(__pyx_v_super_frequent_patterns, (__pyx_v_data->arr + __pyx_v_i1), __pyx_v_l1) != NULL); + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":354 + * if super_frequent_patterns._contains(data.arr+i2, l2) != NULL: + * if super_frequent_patterns._contains(data.arr+i1, l1) != NULL: + * is_super = 1 # <<<<<<<<<<<<<< + * else: + * is_super = 0 + */ + __pyx_v_is_super = 1; + goto __pyx_L25; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":356 + * is_super = 1 + * else: + * is_super = 0 # <<<<<<<<<<<<<< + * ptr3 = ptr2 + 2 + * while ptr3 < N: + */ + __pyx_v_is_super = 0; + } + __pyx_L25:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":357 + * else: + * is_super = 0 + * ptr3 = ptr2 + 2 # <<<<<<<<<<<<<< + * while ptr3 < N: + * i3 = queue.arr[ptr3] + */ + __pyx_v_ptr3 = (__pyx_v_ptr2 + 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":358 + * is_super = 0 + * ptr3 = ptr2 + 2 + * while ptr3 < N: # <<<<<<<<<<<<<< + * i3 = queue.arr[ptr3] + * if i3 == -1 or i3 - i1 >= self.train_max_initial_size: + */ + while (1) { + __pyx_t_11 = (__pyx_v_ptr3 < __pyx_v_N); + if (!__pyx_t_11) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":359 + * ptr3 = ptr2 + 2 + * while ptr3 < N: + * i3 = queue.arr[ptr3] # <<<<<<<<<<<<<< + * if i3 == -1 or i3 - i1 >= self.train_max_initial_size: + * break + */ + __pyx_v_i3 = (__pyx_v_queue->arr[__pyx_v_ptr3]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":360 + * while ptr3 < N: + * i3 = queue.arr[ptr3] + * if i3 == -1 or i3 - i1 >= self.train_max_initial_size: # <<<<<<<<<<<<<< + * break + * l3 = queue.arr[ptr3+1] + */ + __pyx_t_11 = (__pyx_v_i3 == -1); + if (!__pyx_t_11) { + __pyx_t_18 = ((__pyx_v_i3 - __pyx_v_i1) >= __pyx_v_self->train_max_initial_size); + __pyx_t_19 = __pyx_t_18; + } else { + __pyx_t_19 = __pyx_t_11; + } + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":361 + * i3 = queue.arr[ptr3] + * if i3 == -1 or i3 - i1 >= self.train_max_initial_size: + * break # <<<<<<<<<<<<<< + * l3 = queue.arr[ptr3+1] + * if (i3 - i2 - l2 >= self.train_min_gap_size and + */ + goto __pyx_L27_break; + goto __pyx_L28; + } + __pyx_L28:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":362 + * if i3 == -1 or i3 - i1 >= self.train_max_initial_size: + * break + * l3 = queue.arr[ptr3+1] # <<<<<<<<<<<<<< + * if (i3 - i2 - l2 >= self.train_min_gap_size and + * i3 + l3 - i1 <= self.train_max_initial_size and + */ + __pyx_v_l3 = (__pyx_v_queue->arr[(__pyx_v_ptr3 + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":363 + * break + * l3 = queue.arr[ptr3+1] + * if (i3 - i2 - l2 >= self.train_min_gap_size and # <<<<<<<<<<<<<< + * i3 + l3 - i1 <= self.train_max_initial_size and + * l1+l2+l3+2 <= self.max_length): + */ + __pyx_t_19 = (((__pyx_v_i3 - __pyx_v_i2) - __pyx_v_l2) >= __pyx_v_self->train_min_gap_size); + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":364 + * l3 = queue.arr[ptr3+1] + * if (i3 - i2 - l2 >= self.train_min_gap_size and + * i3 + l3 - i1 <= self.train_max_initial_size and # <<<<<<<<<<<<<< + * l1+l2+l3+2 <= self.max_length): + * if is_super or super_frequent_patterns._contains(data.arr+i3, l3) != NULL: + */ + __pyx_t_11 = (((__pyx_v_i3 + __pyx_v_l3) - __pyx_v_i1) <= __pyx_v_self->train_max_initial_size); + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":365 + * if (i3 - i2 - l2 >= self.train_min_gap_size and + * i3 + l3 - i1 <= self.train_max_initial_size and + * l1+l2+l3+2 <= self.max_length): # <<<<<<<<<<<<<< + * if is_super or super_frequent_patterns._contains(data.arr+i3, l3) != NULL: + * node = collocations._insert(data.arr+i1, l1) + */ + __pyx_t_18 = ((((__pyx_v_l1 + __pyx_v_l2) + __pyx_v_l3) + 2) <= __pyx_v_self->max_length); + __pyx_t_17 = __pyx_t_18; + } else { + __pyx_t_17 = __pyx_t_11; + } + __pyx_t_11 = __pyx_t_17; + } else { + __pyx_t_11 = __pyx_t_19; + } + if (__pyx_t_11) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":366 + * i3 + l3 - i1 <= self.train_max_initial_size and + * l1+l2+l3+2 <= self.max_length): + * if is_super or super_frequent_patterns._contains(data.arr+i3, l3) != NULL: # <<<<<<<<<<<<<< + * node = collocations._insert(data.arr+i1, l1) + * node = trie_insert(node, -1) + */ + if (!__pyx_v_is_super) { + __pyx_t_11 = (((struct __pyx_vtabstruct_3_sa_TrieMap *)__pyx_v_super_frequent_patterns->__pyx_vtab)->_contains(__pyx_v_super_frequent_patterns, (__pyx_v_data->arr + __pyx_v_i3), __pyx_v_l3) != NULL); + __pyx_t_19 = __pyx_t_11; + } else { + __pyx_t_19 = __pyx_v_is_super; + } + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":367 + * l1+l2+l3+2 <= self.max_length): + * if is_super or super_frequent_patterns._contains(data.arr+i3, l3) != NULL: + * node = collocations._insert(data.arr+i1, l1) # <<<<<<<<<<<<<< + * node = trie_insert(node, -1) + * for i from i2 <= i < i2+l2: + */ + __pyx_v_node = ((struct __pyx_vtabstruct_3_sa_TrieMap *)__pyx_v_collocations->__pyx_vtab)->_insert(__pyx_v_collocations, (__pyx_v_data->arr + __pyx_v_i1), __pyx_v_l1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":368 + * if is_super or super_frequent_patterns._contains(data.arr+i3, l3) != NULL: + * node = collocations._insert(data.arr+i1, l1) + * node = trie_insert(node, -1) # <<<<<<<<<<<<<< + * for i from i2 <= i < i2+l2: + * node = trie_insert(node, data.arr[i]) + */ + __pyx_v_node = __pyx_f_3_sa_trie_insert(__pyx_v_node, -1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":369 + * node = collocations._insert(data.arr+i1, l1) + * node = trie_insert(node, -1) + * for i from i2 <= i < i2+l2: # <<<<<<<<<<<<<< + * node = trie_insert(node, data.arr[i]) + * node = trie_insert(node, -1) + */ + __pyx_t_13 = (__pyx_v_i2 + __pyx_v_l2); + for (__pyx_v_i = __pyx_v_i2; __pyx_v_i < __pyx_t_13; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":370 + * node = trie_insert(node, -1) + * for i from i2 <= i < i2+l2: + * node = trie_insert(node, data.arr[i]) # <<<<<<<<<<<<<< + * node = trie_insert(node, -1) + * for i from i3 <= i < i3+l3: + */ + __pyx_v_node = __pyx_f_3_sa_trie_insert(__pyx_v_node, (__pyx_v_data->arr[__pyx_v_i])); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":371 + * for i from i2 <= i < i2+l2: + * node = trie_insert(node, data.arr[i]) + * node = trie_insert(node, -1) # <<<<<<<<<<<<<< + * for i from i3 <= i < i3+l3: + * node = trie_insert(node, data.arr[i]) + */ + __pyx_v_node = __pyx_f_3_sa_trie_insert(__pyx_v_node, -1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":372 + * node = trie_insert(node, data.arr[i]) + * node = trie_insert(node, -1) + * for i from i3 <= i < i3+l3: # <<<<<<<<<<<<<< + * node = trie_insert(node, data.arr[i]) + * trie_node_data_append(node, i1) + */ + __pyx_t_13 = (__pyx_v_i3 + __pyx_v_l3); + for (__pyx_v_i = __pyx_v_i3; __pyx_v_i < __pyx_t_13; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":373 + * node = trie_insert(node, -1) + * for i from i3 <= i < i3+l3: + * node = trie_insert(node, data.arr[i]) # <<<<<<<<<<<<<< + * trie_node_data_append(node, i1) + * trie_node_data_append(node, i2) + */ + __pyx_v_node = __pyx_f_3_sa_trie_insert(__pyx_v_node, (__pyx_v_data->arr[__pyx_v_i])); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":374 + * for i from i3 <= i < i3+l3: + * node = trie_insert(node, data.arr[i]) + * trie_node_data_append(node, i1) # <<<<<<<<<<<<<< + * trie_node_data_append(node, i2) + * trie_node_data_append(node, i3) + */ + __pyx_t_3 = __pyx_f_3_sa_trie_node_data_append(__pyx_v_node, __pyx_v_i1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":375 + * node = trie_insert(node, data.arr[i]) + * trie_node_data_append(node, i1) + * trie_node_data_append(node, i2) # <<<<<<<<<<<<<< + * trie_node_data_append(node, i3) + * ptr3 = ptr3 + 2 + */ + __pyx_t_3 = __pyx_f_3_sa_trie_node_data_append(__pyx_v_node, __pyx_v_i2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":376 + * trie_node_data_append(node, i1) + * trie_node_data_append(node, i2) + * trie_node_data_append(node, i3) # <<<<<<<<<<<<<< + * ptr3 = ptr3 + 2 + * ptr2 = ptr2 + 2 + */ + __pyx_t_3 = __pyx_f_3_sa_trie_node_data_append(__pyx_v_node, __pyx_v_i3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L30; + } + __pyx_L30:; + goto __pyx_L29; + } + __pyx_L29:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":377 + * trie_node_data_append(node, i2) + * trie_node_data_append(node, i3) + * ptr3 = ptr3 + 2 # <<<<<<<<<<<<<< + * ptr2 = ptr2 + 2 + * ptr1 = ptr1 + 2 + */ + __pyx_v_ptr3 = (__pyx_v_ptr3 + 2); + } + __pyx_L27_break:; + goto __pyx_L24; + } + __pyx_L24:; + goto __pyx_L21; + } + __pyx_L21:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":378 + * trie_node_data_append(node, i3) + * ptr3 = ptr3 + 2 + * ptr2 = ptr2 + 2 # <<<<<<<<<<<<<< + * ptr1 = ptr1 + 2 + * else: + */ + __pyx_v_ptr2 = (__pyx_v_ptr2 + 2); + } + __pyx_L19_break:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":379 + * ptr3 = ptr3 + 2 + * ptr2 = ptr2 + 2 + * ptr1 = ptr1 + 2 # <<<<<<<<<<<<<< + * else: + * sent_count = sent_count + 1 + */ + __pyx_v_ptr1 = (__pyx_v_ptr1 + 2); + goto __pyx_L17; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":381 + * ptr1 = ptr1 + 2 + * else: + * sent_count = sent_count + 1 # <<<<<<<<<<<<<< + * if sent_count % 10000 == 0: + * logger.debug(" %d sentences", sent_count) + */ + __pyx_v_sent_count = (__pyx_v_sent_count + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":382 + * else: + * sent_count = sent_count + 1 + * if sent_count % 10000 == 0: # <<<<<<<<<<<<<< + * logger.debug(" %d sentences", sent_count) + * ptr1 = ptr1 + 1 + */ + __pyx_t_19 = (__Pyx_mod_long(__pyx_v_sent_count, 10000) == 0); + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":383 + * sent_count = sent_count + 1 + * if sent_count % 10000 == 0: + * logger.debug(" %d sentences", sent_count) # <<<<<<<<<<<<<< + * ptr1 = ptr1 + 1 + * + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__debug); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromLong(__pyx_v_sent_count); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_76)); + PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_kp_s_76)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_76)); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L35; + } + __pyx_L35:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":384 + * if sent_count % 10000 == 0: + * logger.debug(" %d sentences", sent_count) + * ptr1 = ptr1 + 1 # <<<<<<<<<<<<<< + * + * self.precomputed_collocations = collocations.toMap(False) + */ + __pyx_v_ptr1 = (__pyx_v_ptr1 + 1); + } + __pyx_L17:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":386 + * ptr1 = ptr1 + 1 + * + * self.precomputed_collocations = collocations.toMap(False) # <<<<<<<<<<<<<< + * self.precomputed_index = frequent_patterns.toMap(True) + * + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_collocations), __pyx_n_s__toMap); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_8 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_GIVEREF(__pyx_t_8); + __Pyx_GOTREF(__pyx_v_self->precomputed_collocations); + __Pyx_DECREF(__pyx_v_self->precomputed_collocations); + __pyx_v_self->precomputed_collocations = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":387 + * + * self.precomputed_collocations = collocations.toMap(False) + * self.precomputed_index = frequent_patterns.toMap(True) # <<<<<<<<<<<<<< + * + * x = 0 + */ + __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_v_frequent_patterns), __pyx_n_s__toMap); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->precomputed_index); + __Pyx_DECREF(__pyx_v_self->precomputed_index); + __pyx_v_self->precomputed_index = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":389 + * self.precomputed_index = frequent_patterns.toMap(True) + * + * x = 0 # <<<<<<<<<<<<<< + * for pattern1 in J_set: + * for pattern2 in J_set: + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_x = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":390 + * + * x = 0 + * for pattern1 in J_set: # <<<<<<<<<<<<<< + * for pattern2 in J_set: + * if len(pattern1) + len(pattern2) + 1 < self.max_length: + */ + __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_J_set)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; + for (;;) { + { + __pyx_t_3 = __pyx_t_4(__pyx_t_1); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[12]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_pattern1); + __pyx_v_pattern1 = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":391 + * x = 0 + * for pattern1 in J_set: + * for pattern2 in J_set: # <<<<<<<<<<<<<< + * if len(pattern1) + len(pattern2) + 1 < self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 + */ + __pyx_t_3 = PyObject_GetIter(((PyObject *)__pyx_v_J_set)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_20 = Py_TYPE(__pyx_t_3)->tp_iternext; + for (;;) { + { + __pyx_t_8 = __pyx_t_20(__pyx_t_3); + if (unlikely(!__pyx_t_8)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[12]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_8); + } + __Pyx_XDECREF(__pyx_v_pattern2); + __pyx_v_pattern2 = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":392 + * for pattern1 in J_set: + * for pattern2 in J_set: + * if len(pattern1) + len(pattern2) + 1 < self.max_length: # <<<<<<<<<<<<<< + * combined_pattern = pattern1 + (-1,) + pattern2 + * J2_set.add(combined_pattern) + */ + __pyx_t_2 = PyObject_Length(__pyx_v_pattern1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_14 = PyObject_Length(__pyx_v_pattern2); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_19 = (((__pyx_t_2 + __pyx_t_14) + 1) < __pyx_v_self->max_length); + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":393 + * for pattern2 in J_set: + * if len(pattern1) + len(pattern2) + 1 < self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 # <<<<<<<<<<<<<< + * J2_set.add(combined_pattern) + * + */ + __pyx_t_8 = PyNumber_Add(__pyx_v_pattern1, ((PyObject *)__pyx_k_tuple_77)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = PyNumber_Add(__pyx_t_8, __pyx_v_pattern2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_v_combined_pattern); + __pyx_v_combined_pattern = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":394 + * if len(pattern1) + len(pattern2) + 1 < self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 + * J2_set.add(combined_pattern) # <<<<<<<<<<<<<< + * + * for pattern1 in I_set: + */ + __pyx_t_15 = PySet_Add(__pyx_v_J2_set, __pyx_v_combined_pattern); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 394; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L40; + } + __pyx_L40:; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":396 + * J2_set.add(combined_pattern) + * + * for pattern1 in I_set: # <<<<<<<<<<<<<< + * for pattern2 in I_set: + * x = x+1 + */ + __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_I_set)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; + for (;;) { + { + __pyx_t_3 = __pyx_t_4(__pyx_t_1); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[12]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_pattern1); + __pyx_v_pattern1 = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":397 + * + * for pattern1 in I_set: + * for pattern2 in I_set: # <<<<<<<<<<<<<< + * x = x+1 + * if len(pattern1) + len(pattern2) + 1 <= self.max_length: + */ + __pyx_t_3 = PyObject_GetIter(((PyObject *)__pyx_v_I_set)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_20 = Py_TYPE(__pyx_t_3)->tp_iternext; + for (;;) { + { + __pyx_t_7 = __pyx_t_20(__pyx_t_3); + if (unlikely(!__pyx_t_7)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[12]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_7); + } + __Pyx_XDECREF(__pyx_v_pattern2); + __pyx_v_pattern2 = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":398 + * for pattern1 in I_set: + * for pattern2 in I_set: + * x = x+1 # <<<<<<<<<<<<<< + * if len(pattern1) + len(pattern2) + 1 <= self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 + */ + __pyx_t_7 = PyNumber_Add(__pyx_v_x, __pyx_int_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_v_x); + __pyx_v_x = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":399 + * for pattern2 in I_set: + * x = x+1 + * if len(pattern1) + len(pattern2) + 1 <= self.max_length: # <<<<<<<<<<<<<< + * combined_pattern = pattern1 + (-1,) + pattern2 + * IJ_set.add(combined_pattern) + */ + __pyx_t_14 = PyObject_Length(__pyx_v_pattern1); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Length(__pyx_v_pattern2); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_19 = (((__pyx_t_14 + __pyx_t_2) + 1) <= __pyx_v_self->max_length); + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":400 + * x = x+1 + * if len(pattern1) + len(pattern2) + 1 <= self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 # <<<<<<<<<<<<<< + * IJ_set.add(combined_pattern) + * + */ + __pyx_t_7 = PyNumber_Add(__pyx_v_pattern1, ((PyObject *)__pyx_k_tuple_78)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyNumber_Add(__pyx_t_7, __pyx_v_pattern2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_v_combined_pattern); + __pyx_v_combined_pattern = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":401 + * if len(pattern1) + len(pattern2) + 1 <= self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 + * IJ_set.add(combined_pattern) # <<<<<<<<<<<<<< + * + * for pattern1 in I_set: + */ + __pyx_t_15 = PySet_Add(__pyx_v_IJ_set, __pyx_v_combined_pattern); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L45; + } + __pyx_L45:; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":403 + * IJ_set.add(combined_pattern) + * + * for pattern1 in I_set: # <<<<<<<<<<<<<< + * for pattern2 in J2_set: + * x = x+2 + */ + __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_I_set)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; + for (;;) { + { + __pyx_t_3 = __pyx_t_4(__pyx_t_1); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[12]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_pattern1); + __pyx_v_pattern1 = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":404 + * + * for pattern1 in I_set: + * for pattern2 in J2_set: # <<<<<<<<<<<<<< + * x = x+2 + * if len(pattern1) + len(pattern2) + 1<= self.max_length: + */ + __pyx_t_3 = PyObject_GetIter(((PyObject *)__pyx_v_J2_set)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_20 = Py_TYPE(__pyx_t_3)->tp_iternext; + for (;;) { + { + __pyx_t_8 = __pyx_t_20(__pyx_t_3); + if (unlikely(!__pyx_t_8)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[12]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_8); + } + __Pyx_XDECREF(__pyx_v_pattern2); + __pyx_v_pattern2 = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":405 + * for pattern1 in I_set: + * for pattern2 in J2_set: + * x = x+2 # <<<<<<<<<<<<<< + * if len(pattern1) + len(pattern2) + 1<= self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 + */ + __pyx_t_8 = PyNumber_Add(__pyx_v_x, __pyx_int_2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_v_x); + __pyx_v_x = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":406 + * for pattern2 in J2_set: + * x = x+2 + * if len(pattern1) + len(pattern2) + 1<= self.max_length: # <<<<<<<<<<<<<< + * combined_pattern = pattern1 + (-1,) + pattern2 + * IJ_set.add(combined_pattern) + */ + __pyx_t_2 = PyObject_Length(__pyx_v_pattern1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_14 = PyObject_Length(__pyx_v_pattern2); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_19 = (((__pyx_t_2 + __pyx_t_14) + 1) <= __pyx_v_self->max_length); + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":407 + * x = x+2 + * if len(pattern1) + len(pattern2) + 1<= self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 # <<<<<<<<<<<<<< + * IJ_set.add(combined_pattern) + * combined_pattern = pattern2 + (-1,) + pattern1 + */ + __pyx_t_8 = PyNumber_Add(__pyx_v_pattern1, ((PyObject *)__pyx_k_tuple_79)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = PyNumber_Add(__pyx_t_8, __pyx_v_pattern2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_v_combined_pattern); + __pyx_v_combined_pattern = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":408 + * if len(pattern1) + len(pattern2) + 1<= self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 + * IJ_set.add(combined_pattern) # <<<<<<<<<<<<<< + * combined_pattern = pattern2 + (-1,) + pattern1 + * IJ_set.add(combined_pattern) + */ + __pyx_t_15 = PySet_Add(__pyx_v_IJ_set, __pyx_v_combined_pattern); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":409 + * combined_pattern = pattern1 + (-1,) + pattern2 + * IJ_set.add(combined_pattern) + * combined_pattern = pattern2 + (-1,) + pattern1 # <<<<<<<<<<<<<< + * IJ_set.add(combined_pattern) + * + */ + __pyx_t_7 = PyNumber_Add(__pyx_v_pattern2, ((PyObject *)__pyx_k_tuple_80)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyNumber_Add(__pyx_t_7, __pyx_v_pattern1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_v_combined_pattern); + __pyx_v_combined_pattern = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":410 + * IJ_set.add(combined_pattern) + * combined_pattern = pattern2 + (-1,) + pattern1 + * IJ_set.add(combined_pattern) # <<<<<<<<<<<<<< + * + * N = len(pattern_rank) + */ + __pyx_t_15 = PySet_Add(__pyx_v_IJ_set, __pyx_v_combined_pattern); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L50; + } + __pyx_L50:; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":412 + * IJ_set.add(combined_pattern) + * + * N = len(pattern_rank) # <<<<<<<<<<<<<< + * cost_by_rank = IntList(initial_len=N) + * count_by_rank = IntList(initial_len=N) + */ + __pyx_t_14 = PyDict_Size(((PyObject *)__pyx_v_pattern_rank)); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_N = __pyx_t_14; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":413 + * + * N = len(pattern_rank) + * cost_by_rank = IntList(initial_len=N) # <<<<<<<<<<<<<< + * count_by_rank = IntList(initial_len=N) + * for pattern, arr in self.precomputed_collocations.iteritems(): + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_v_cost_by_rank = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":414 + * N = len(pattern_rank) + * cost_by_rank = IntList(initial_len=N) + * count_by_rank = IntList(initial_len=N) # <<<<<<<<<<<<<< + * for pattern, arr in self.precomputed_collocations.iteritems(): + * if pattern not in IJ_set: + */ + __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_v_count_by_rank = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":415 + * cost_by_rank = IntList(initial_len=N) + * count_by_rank = IntList(initial_len=N) + * for pattern, arr in self.precomputed_collocations.iteritems(): # <<<<<<<<<<<<<< + * if pattern not in IJ_set: + * s = "" + */ + __pyx_t_14 = 0; + if (unlikely(__pyx_v_self->precomputed_collocations == Py_None)) { + PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "iteritems"); + {__pyx_filename = __pyx_f[12]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_3 = __Pyx_dict_iterator(__pyx_v_self->precomputed_collocations, 0, ((PyObject *)__pyx_n_s__iteritems), (&__pyx_t_2), (&__pyx_t_13)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_1); + __pyx_t_1 = __pyx_t_3; + __pyx_t_3 = 0; + while (1) { + __pyx_t_16 = __Pyx_dict_iter_next(__pyx_t_1, __pyx_t_2, &__pyx_t_14, &__pyx_t_3, &__pyx_t_8, NULL, __pyx_t_13); + if (unlikely(__pyx_t_16 == 0)) break; + if (unlikely(__pyx_t_16 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_v_pattern); + __pyx_v_pattern = __pyx_t_3; + __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_v_arr); + __pyx_v_arr = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":416 + * count_by_rank = IntList(initial_len=N) + * for pattern, arr in self.precomputed_collocations.iteritems(): + * if pattern not in IJ_set: # <<<<<<<<<<<<<< + * s = "" + * for word_id in pattern: + */ + __pyx_t_19 = (__Pyx_NegateNonNeg(PySequence_Contains(((PyObject *)__pyx_v_IJ_set), __pyx_v_pattern))); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":417 + * for pattern, arr in self.precomputed_collocations.iteritems(): + * if pattern not in IJ_set: + * s = "" # <<<<<<<<<<<<<< + * for word_id in pattern: + * if word_id == -1: + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_42)); + __Pyx_XDECREF(__pyx_v_s); + __pyx_v_s = ((PyObject *)__pyx_kp_s_42); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":418 + * if pattern not in IJ_set: + * s = "" + * for word_id in pattern: # <<<<<<<<<<<<<< + * if word_id == -1: + * s = s + "X " + */ + if (PyList_CheckExact(__pyx_v_pattern) || PyTuple_CheckExact(__pyx_v_pattern)) { + __pyx_t_8 = __pyx_v_pattern; __Pyx_INCREF(__pyx_t_8); __pyx_t_12 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_12 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_pattern); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_4 = Py_TYPE(__pyx_t_8)->tp_iternext; + } + for (;;) { + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_8)) { + if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_8)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_12); __Pyx_INCREF(__pyx_t_3); __pyx_t_12++; + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_8, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_8)) { + if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_8)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_12); __Pyx_INCREF(__pyx_t_3); __pyx_t_12++; + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_8, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_3 = __pyx_t_4(__pyx_t_8); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[12]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_word_id); + __pyx_v_word_id = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":419 + * s = "" + * for word_id in pattern: + * if word_id == -1: # <<<<<<<<<<<<<< + * s = s + "X " + * else: + */ + __pyx_t_3 = PyObject_RichCompare(__pyx_v_word_id, __pyx_int_neg_1, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 419; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 419; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":420 + * for word_id in pattern: + * if word_id == -1: + * s = s + "X " # <<<<<<<<<<<<<< + * else: + * s = s + darray.id2word[word_id] + " " + */ + __pyx_t_3 = PyNumber_Add(__pyx_v_s, ((PyObject *)__pyx_kp_s_81)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_v_s); + __pyx_v_s = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L56; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":422 + * s = s + "X " + * else: + * s = s + darray.id2word[word_id] + " " # <<<<<<<<<<<<<< + * logger.warn("ERROR: unexpected pattern %s in set of precomputed collocations", s) + * else: + */ + __pyx_t_3 = PyObject_GetItem(__pyx_v_darray->id2word, __pyx_v_word_id); if (!__pyx_t_3) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = PyNumber_Add(__pyx_v_s, __pyx_t_3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Add(__pyx_t_7, ((PyObject *)__pyx_kp_s_64)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_v_s); + __pyx_v_s = __pyx_t_3; + __pyx_t_3 = 0; + } + __pyx_L56:; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":423 + * else: + * s = s + darray.id2word[word_id] + " " + * logger.warn("ERROR: unexpected pattern %s in set of precomputed collocations", s) # <<<<<<<<<<<<<< + * else: + * chunk = () + */ + __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__warn); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_82)); + PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_kp_s_82)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_82)); + __Pyx_INCREF(__pyx_v_s); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_s); + __Pyx_GIVEREF(__pyx_v_s); + __pyx_t_7 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L53; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":425 + * logger.warn("ERROR: unexpected pattern %s in set of precomputed collocations", s) + * else: + * chunk = () # <<<<<<<<<<<<<< + * max_rank = 0 + * arity = 0 + */ + __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); + __Pyx_XDECREF(((PyObject *)__pyx_v_chunk)); + __pyx_v_chunk = __pyx_empty_tuple; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":426 + * else: + * chunk = () + * max_rank = 0 # <<<<<<<<<<<<<< + * arity = 0 + * for word_id in pattern: + */ + __pyx_v_max_rank = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":427 + * chunk = () + * max_rank = 0 + * arity = 0 # <<<<<<<<<<<<<< + * for word_id in pattern: + * if word_id == -1: + */ + __Pyx_INCREF(__pyx_int_0); + __Pyx_XDECREF(__pyx_v_arity); + __pyx_v_arity = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":428 + * max_rank = 0 + * arity = 0 + * for word_id in pattern: # <<<<<<<<<<<<<< + * if word_id == -1: + * max_rank = max(max_rank, pattern_rank[chunk]) + */ + if (PyList_CheckExact(__pyx_v_pattern) || PyTuple_CheckExact(__pyx_v_pattern)) { + __pyx_t_7 = __pyx_v_pattern; __Pyx_INCREF(__pyx_t_7); __pyx_t_12 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_12 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_v_pattern); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_4 = Py_TYPE(__pyx_t_7)->tp_iternext; + } + for (;;) { + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_7)) { + if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_7)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_8 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_12); __Pyx_INCREF(__pyx_t_8); __pyx_t_12++; + #else + __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_7)) { + if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_7)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_12); __Pyx_INCREF(__pyx_t_8); __pyx_t_12++; + #else + __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_8 = __pyx_t_4(__pyx_t_7); + if (unlikely(!__pyx_t_8)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[12]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_8); + } + __Pyx_XDECREF(__pyx_v_word_id); + __pyx_v_word_id = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":429 + * arity = 0 + * for word_id in pattern: + * if word_id == -1: # <<<<<<<<<<<<<< + * max_rank = max(max_rank, pattern_rank[chunk]) + * arity = arity + 1 + */ + __pyx_t_8 = PyObject_RichCompare(__pyx_v_word_id, __pyx_int_neg_1, Py_EQ); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 429; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":430 + * for word_id in pattern: + * if word_id == -1: + * max_rank = max(max_rank, pattern_rank[chunk]) # <<<<<<<<<<<<<< + * arity = arity + 1 + * chunk = () + */ + __pyx_t_8 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_pattern_rank), ((PyObject *)__pyx_v_chunk)); if (!__pyx_t_8) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_16 = __pyx_v_max_rank; + __pyx_t_5 = PyInt_FromLong(__pyx_t_16); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyObject_RichCompare(__pyx_t_8, __pyx_t_5, Py_GT); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_19) { + __Pyx_INCREF(__pyx_t_8); + __pyx_t_3 = __pyx_t_8; + } else { + __pyx_t_6 = PyInt_FromLong(__pyx_t_16); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = __pyx_t_6; + __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_16 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_16 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_max_rank = __pyx_t_16; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":431 + * if word_id == -1: + * max_rank = max(max_rank, pattern_rank[chunk]) + * arity = arity + 1 # <<<<<<<<<<<<<< + * chunk = () + * else: + */ + __pyx_t_3 = PyNumber_Add(__pyx_v_arity, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_v_arity); + __pyx_v_arity = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":432 + * max_rank = max(max_rank, pattern_rank[chunk]) + * arity = arity + 1 + * chunk = () # <<<<<<<<<<<<<< + * else: + * chunk = chunk + (word_id,) + */ + __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); + __Pyx_DECREF(((PyObject *)__pyx_v_chunk)); + __pyx_v_chunk = __pyx_empty_tuple; + goto __pyx_L59; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":434 + * chunk = () + * else: + * chunk = chunk + (word_id,) # <<<<<<<<<<<<<< + * max_rank = max(max_rank, pattern_rank[chunk]) + * cost_by_rank.arr[max_rank] = cost_by_rank.arr[max_rank] + (4*len(arr)) + */ + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_word_id); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_word_id); + __Pyx_GIVEREF(__pyx_v_word_id); + __pyx_t_8 = PyNumber_Add(((PyObject *)__pyx_v_chunk), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_8)); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_chunk)); + __pyx_v_chunk = __pyx_t_8; + __pyx_t_8 = 0; + } + __pyx_L59:; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":435 + * else: + * chunk = chunk + (word_id,) + * max_rank = max(max_rank, pattern_rank[chunk]) # <<<<<<<<<<<<<< + * cost_by_rank.arr[max_rank] = cost_by_rank.arr[max_rank] + (4*len(arr)) + * count_by_rank.arr[max_rank] = count_by_rank.arr[max_rank] + (len(arr)/(arity+1)) + */ + __pyx_t_7 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_pattern_rank), ((PyObject *)__pyx_v_chunk)); if (!__pyx_t_7) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_16 = __pyx_v_max_rank; + __pyx_t_3 = PyInt_FromLong(__pyx_t_16); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PyObject_RichCompare(__pyx_t_7, __pyx_t_3, Py_GT); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_19) { + __Pyx_INCREF(__pyx_t_7); + __pyx_t_8 = __pyx_t_7; + } else { + __pyx_t_6 = PyInt_FromLong(__pyx_t_16); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = __pyx_t_6; + __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_16 = __Pyx_PyInt_AsInt(__pyx_t_8); if (unlikely((__pyx_t_16 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_v_max_rank = __pyx_t_16; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":436 + * chunk = chunk + (word_id,) + * max_rank = max(max_rank, pattern_rank[chunk]) + * cost_by_rank.arr[max_rank] = cost_by_rank.arr[max_rank] + (4*len(arr)) # <<<<<<<<<<<<<< + * count_by_rank.arr[max_rank] = count_by_rank.arr[max_rank] + (len(arr)/(arity+1)) + * + */ + __pyx_t_12 = PyObject_Length(__pyx_v_arr); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + (__pyx_v_cost_by_rank->arr[__pyx_v_max_rank]) = ((__pyx_v_cost_by_rank->arr[__pyx_v_max_rank]) + (4 * __pyx_t_12)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":437 + * max_rank = max(max_rank, pattern_rank[chunk]) + * cost_by_rank.arr[max_rank] = cost_by_rank.arr[max_rank] + (4*len(arr)) + * count_by_rank.arr[max_rank] = count_by_rank.arr[max_rank] + (len(arr)/(arity+1)) # <<<<<<<<<<<<<< + * + * cumul_cost = 0 + */ + __pyx_t_8 = PyInt_FromLong((__pyx_v_count_by_rank->arr[__pyx_v_max_rank])); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_12 = PyObject_Length(__pyx_v_arr); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_12); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = PyNumber_Add(__pyx_v_arity, __pyx_int_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = PyNumber_Add(__pyx_t_8, __pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_16 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_16 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + (__pyx_v_count_by_rank->arr[__pyx_v_max_rank]) = __pyx_t_16; + } + __pyx_L53:; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":439 + * count_by_rank.arr[max_rank] = count_by_rank.arr[max_rank] + (len(arr)/(arity+1)) + * + * cumul_cost = 0 # <<<<<<<<<<<<<< + * cumul_count = 0 + * for i from 0 <= i < N: + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_cumul_cost = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":440 + * + * cumul_cost = 0 + * cumul_count = 0 # <<<<<<<<<<<<<< + * for i from 0 <= i < N: + * cumul_cost = cumul_cost + cost_by_rank.arr[i] + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_cumul_count = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":441 + * cumul_cost = 0 + * cumul_count = 0 + * for i from 0 <= i < N: # <<<<<<<<<<<<<< + * cumul_cost = cumul_cost + cost_by_rank.arr[i] + * cumul_count = cumul_count + count_by_rank.arr[i] + */ + __pyx_t_13 = __pyx_v_N; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_13; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":442 + * cumul_count = 0 + * for i from 0 <= i < N: + * cumul_cost = cumul_cost + cost_by_rank.arr[i] # <<<<<<<<<<<<<< + * cumul_count = cumul_count + count_by_rank.arr[i] + * logger.debug("RANK %d\tCOUNT, COST: %d %d\tCUMUL: %d, %d", i, count_by_rank.arr[i], cost_by_rank.arr[i], cumul_count, cumul_cost) + */ + __pyx_t_1 = PyInt_FromLong((__pyx_v_cost_by_rank->arr[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = PyNumber_Add(__pyx_v_cumul_cost, __pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_v_cumul_cost); + __pyx_v_cumul_cost = __pyx_t_6; + __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":443 + * for i from 0 <= i < N: + * cumul_cost = cumul_cost + cost_by_rank.arr[i] + * cumul_count = cumul_count + count_by_rank.arr[i] # <<<<<<<<<<<<<< + * logger.debug("RANK %d\tCOUNT, COST: %d %d\tCUMUL: %d, %d", i, count_by_rank.arr[i], cost_by_rank.arr[i], cumul_count, cumul_cost) + * + */ + __pyx_t_6 = PyInt_FromLong((__pyx_v_count_by_rank->arr[__pyx_v_i])); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_1 = PyNumber_Add(__pyx_v_cumul_count, __pyx_t_6); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_v_cumul_count); + __pyx_v_cumul_count = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":444 + * cumul_cost = cumul_cost + cost_by_rank.arr[i] + * cumul_count = cumul_count + count_by_rank.arr[i] + * logger.debug("RANK %d\tCOUNT, COST: %d %d\tCUMUL: %d, %d", i, count_by_rank.arr[i], cost_by_rank.arr[i], cumul_count, cumul_cost) # <<<<<<<<<<<<<< + * + * num_found_patterns = len(self.precomputed_collocations) + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__debug); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyInt_FromLong((__pyx_v_count_by_rank->arr[__pyx_v_i])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = PyInt_FromLong((__pyx_v_cost_by_rank->arr[__pyx_v_i])); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = PyTuple_New(6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_83)); + PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_kp_s_83)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_83)); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_7, 3, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __Pyx_INCREF(__pyx_v_cumul_count); + PyTuple_SET_ITEM(__pyx_t_7, 4, __pyx_v_cumul_count); + __Pyx_GIVEREF(__pyx_v_cumul_count); + __Pyx_INCREF(__pyx_v_cumul_cost); + PyTuple_SET_ITEM(__pyx_t_7, 5, __pyx_v_cumul_cost); + __Pyx_GIVEREF(__pyx_v_cumul_cost); + __pyx_t_1 = 0; + __pyx_t_3 = 0; + __pyx_t_8 = 0; + __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":446 + * logger.debug("RANK %d\tCOUNT, COST: %d %d\tCUMUL: %d, %d", i, count_by_rank.arr[i], cost_by_rank.arr[i], cumul_count, cumul_cost) + * + * num_found_patterns = len(self.precomputed_collocations) # <<<<<<<<<<<<<< + * for pattern in IJ_set: + * if pattern not in self.precomputed_collocations: + */ + __pyx_t_8 = __pyx_v_self->precomputed_collocations; + __Pyx_INCREF(__pyx_t_8); + __pyx_t_2 = PyObject_Length(__pyx_t_8); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 446; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_v_num_found_patterns = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":447 + * + * num_found_patterns = len(self.precomputed_collocations) + * for pattern in IJ_set: # <<<<<<<<<<<<<< + * if pattern not in self.precomputed_collocations: + * self.precomputed_collocations[pattern] = IntList() + */ + __pyx_t_8 = PyObject_GetIter(((PyObject *)__pyx_v_IJ_set)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_4 = Py_TYPE(__pyx_t_8)->tp_iternext; + for (;;) { + { + __pyx_t_7 = __pyx_t_4(__pyx_t_8); + if (unlikely(!__pyx_t_7)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[12]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_7); + } + __Pyx_XDECREF(__pyx_v_pattern); + __pyx_v_pattern = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":448 + * num_found_patterns = len(self.precomputed_collocations) + * for pattern in IJ_set: + * if pattern not in self.precomputed_collocations: # <<<<<<<<<<<<<< + * self.precomputed_collocations[pattern] = IntList() + * + */ + __pyx_t_19 = (__Pyx_NegateNonNeg(PySequence_Contains(__pyx_v_self->precomputed_collocations, __pyx_v_pattern))); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":449 + * for pattern in IJ_set: + * if pattern not in self.precomputed_collocations: + * self.precomputed_collocations[pattern] = IntList() # <<<<<<<<<<<<<< + * + * cdef float stop_time = monitor_cpu() + */ + __pyx_t_7 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + if (PyObject_SetItem(__pyx_v_self->precomputed_collocations, __pyx_v_pattern, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L64; + } + __pyx_L64:; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":451 + * self.precomputed_collocations[pattern] = IntList() + * + * cdef float stop_time = monitor_cpu() # <<<<<<<<<<<<<< + * logger.info("Precomputed collocations for %d patterns out of %d possible (upper bound %d)", num_found_patterns, len(self.precomputed_collocations), x) + * logger.info("Precomputed inverted index for %d patterns ", len(self.precomputed_index)) + */ + __pyx_v_stop_time = __pyx_f_3_sa_monitor_cpu(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":452 + * + * cdef float stop_time = monitor_cpu() + * logger.info("Precomputed collocations for %d patterns out of %d possible (upper bound %d)", num_found_patterns, len(self.precomputed_collocations), x) # <<<<<<<<<<<<<< + * logger.info("Precomputed inverted index for %d patterns ", len(self.precomputed_index)) + * logger.info("Precomputation took %f seconds", (stop_time - start_time)) + */ + __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__info); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __pyx_v_self->precomputed_collocations; + __Pyx_INCREF(__pyx_t_8); + __pyx_t_2 = PyObject_Length(__pyx_t_8); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_6 = PyTuple_New(4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_84)); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_kp_s_84)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_84)); + __Pyx_INCREF(__pyx_v_num_found_patterns); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_num_found_patterns); + __Pyx_GIVEREF(__pyx_v_num_found_patterns); + PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __Pyx_INCREF(__pyx_v_x); + PyTuple_SET_ITEM(__pyx_t_6, 3, __pyx_v_x); + __Pyx_GIVEREF(__pyx_v_x); + __pyx_t_8 = 0; + __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":453 + * cdef float stop_time = monitor_cpu() + * logger.info("Precomputed collocations for %d patterns out of %d possible (upper bound %d)", num_found_patterns, len(self.precomputed_collocations), x) + * logger.info("Precomputed inverted index for %d patterns ", len(self.precomputed_index)) # <<<<<<<<<<<<<< + * logger.info("Precomputation took %f seconds", (stop_time - start_time)) + */ + __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_6 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__info); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __pyx_v_self->precomputed_index; + __Pyx_INCREF(__pyx_t_8); + __pyx_t_2 = PyObject_Length(__pyx_t_8); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_85)); + PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_kp_s_85)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_85)); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":454 + * logger.info("Precomputed collocations for %d patterns out of %d possible (upper bound %d)", num_found_patterns, len(self.precomputed_collocations), x) + * logger.info("Precomputed inverted index for %d patterns ", len(self.precomputed_index)) + * logger.info("Precomputation took %f seconds", (stop_time - start_time)) # <<<<<<<<<<<<<< + */ + __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__info); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = PyFloat_FromDouble((__pyx_v_stop_time - __pyx_v_start_time)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_86)); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_kp_s_86)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_86)); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("_sa.Precomputation.precompute", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_darray); + __Pyx_XDECREF((PyObject *)__pyx_v_data); + __Pyx_XDECREF((PyObject *)__pyx_v_queue); + __Pyx_XDECREF((PyObject *)__pyx_v_cost_by_rank); + __Pyx_XDECREF((PyObject *)__pyx_v_count_by_rank); + __Pyx_XDECREF((PyObject *)__pyx_v_frequent_patterns); + __Pyx_XDECREF((PyObject *)__pyx_v_super_frequent_patterns); + __Pyx_XDECREF((PyObject *)__pyx_v_collocations); + __Pyx_XDECREF(__pyx_v_I_set); + __Pyx_XDECREF(__pyx_v_J_set); + __Pyx_XDECREF(__pyx_v_J2_set); + __Pyx_XDECREF(__pyx_v_IJ_set); + __Pyx_XDECREF(__pyx_v_pattern_rank); + __Pyx_XDECREF(__pyx_v_rank); + __Pyx_XDECREF(__pyx_v__); + __Pyx_XDECREF(__pyx_v_phrase); + __Pyx_XDECREF(__pyx_v_x); + __Pyx_XDECREF(__pyx_v_pattern1); + __Pyx_XDECREF(__pyx_v_pattern2); + __Pyx_XDECREF(__pyx_v_combined_pattern); + __Pyx_XDECREF(__pyx_v_pattern); + __Pyx_XDECREF(__pyx_v_arr); + __Pyx_XDECREF(__pyx_v_s); + __Pyx_XDECREF(__pyx_v_word_id); + __Pyx_XDECREF(__pyx_v_chunk); + __Pyx_XDECREF(__pyx_v_arity); + __Pyx_XDECREF(__pyx_v_cumul_cost); + __Pyx_XDECREF(__pyx_v_cumul_count); + __Pyx_XDECREF(__pyx_v_num_found_patterns); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_11SuffixArray_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_11SuffixArray_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_from_binary = 0; + PyObject *__pyx_v_from_text = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__from_binary,&__pyx_n_s__from_text,0}; + PyObject* values[2] = {0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":11 + * cdef IntList ha + * + * def __cinit__(self, from_binary=None, from_text=None): # <<<<<<<<<<<<<< + * self.darray = DataArray() + * self.sa = IntList() + */ + values[0] = ((PyObject *)Py_None); + values[1] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_binary); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_text); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_from_binary = values[0]; + __pyx_v_from_text = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[13]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.SuffixArray.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_11SuffixArray___cinit__(((struct __pyx_obj_3_sa_SuffixArray *)__pyx_v_self), __pyx_v_from_binary, __pyx_v_from_text); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_11SuffixArray___cinit__(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":12 + * + * def __cinit__(self, from_binary=None, from_text=None): + * self.darray = DataArray() # <<<<<<<<<<<<<< + * self.sa = IntList() + * self.ha = IntList() + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_DataArray)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->darray); + __Pyx_DECREF(((PyObject *)__pyx_v_self->darray)); + __pyx_v_self->darray = ((struct __pyx_obj_3_sa_DataArray *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":13 + * def __cinit__(self, from_binary=None, from_text=None): + * self.darray = DataArray() + * self.sa = IntList() # <<<<<<<<<<<<<< + * self.ha = IntList() + * if from_binary: + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->sa); + __Pyx_DECREF(((PyObject *)__pyx_v_self->sa)); + __pyx_v_self->sa = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":14 + * self.darray = DataArray() + * self.sa = IntList() + * self.ha = IntList() # <<<<<<<<<<<<<< + * if from_binary: + * self.read_binary(from_binary) + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->ha); + __Pyx_DECREF(((PyObject *)__pyx_v_self->ha)); + __pyx_v_self->ha = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":15 + * self.sa = IntList() + * self.ha = IntList() + * if from_binary: # <<<<<<<<<<<<<< + * self.read_binary(from_binary) + * elif from_text: + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_binary); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":16 + * self.ha = IntList() + * if from_binary: + * self.read_binary(from_binary) # <<<<<<<<<<<<<< + * elif from_text: + * self.read_text(from_text) + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_binary); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_from_binary); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_binary); + __Pyx_GIVEREF(__pyx_v_from_binary); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":17 + * if from_binary: + * self.read_binary(from_binary) + * elif from_text: # <<<<<<<<<<<<<< + * self.read_text(from_text) + * + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_text); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":18 + * self.read_binary(from_binary) + * elif from_text: + * self.read_text(from_text) # <<<<<<<<<<<<<< + * + * def __getitem__(self, i): + */ + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_text); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_from_text); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_text); + __Pyx_GIVEREF(__pyx_v_from_text); + __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_sa.SuffixArray.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_11SuffixArray_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_3_sa_11SuffixArray_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_11SuffixArray_2__getitem__(((struct __pyx_obj_3_sa_SuffixArray *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":20 + * self.read_text(from_text) + * + * def __getitem__(self, i): # <<<<<<<<<<<<<< + * return self.sa.arr[i] + * + */ + +static PyObject *__pyx_pf_3_sa_11SuffixArray_2__getitem__(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__getitem__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":21 + * + * def __getitem__(self, i): + * return self.sa.arr[i] # <<<<<<<<<<<<<< + * + * def getSentId(self, i): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->sa->arr[__pyx_t_1])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __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_2); + __Pyx_AddTraceback("_sa.SuffixArray.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_11SuffixArray_5getSentId(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_3_sa_11SuffixArray_5getSentId(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getSentId (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_11SuffixArray_4getSentId(((struct __pyx_obj_3_sa_SuffixArray *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":23 + * return self.sa.arr[i] + * + * def getSentId(self, i): # <<<<<<<<<<<<<< + * return self.darray.getSentId(i) + * + */ + +static PyObject *__pyx_pf_3_sa_11SuffixArray_4getSentId(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("getSentId", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":24 + * + * def getSentId(self, i): + * return self.darray.getSentId(i) # <<<<<<<<<<<<<< + * + * def getSent(self, i): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->darray), __pyx_n_s__getSentId); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.SuffixArray.getSentId", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_11SuffixArray_7getSent(PyObject *__pyx_v_self, PyObject *__pyx_v_i); /*proto*/ +static PyObject *__pyx_pw_3_sa_11SuffixArray_7getSent(PyObject *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getSent (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_11SuffixArray_6getSent(((struct __pyx_obj_3_sa_SuffixArray *)__pyx_v_self), ((PyObject *)__pyx_v_i)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":26 + * return self.darray.getSentId(i) + * + * def getSent(self, i): # <<<<<<<<<<<<<< + * return self.darray.getSent(i) + * + */ + +static PyObject *__pyx_pf_3_sa_11SuffixArray_6getSent(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("getSent", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":27 + * + * def getSent(self, i): + * return self.darray.getSent(i) # <<<<<<<<<<<<<< + * + * def getSentPos(self, loc): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->darray), __pyx_n_s__getSent); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.SuffixArray.getSent", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_11SuffixArray_9getSentPos(PyObject *__pyx_v_self, PyObject *__pyx_v_loc); /*proto*/ +static PyObject *__pyx_pw_3_sa_11SuffixArray_9getSentPos(PyObject *__pyx_v_self, PyObject *__pyx_v_loc) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("getSentPos (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_11SuffixArray_8getSentPos(((struct __pyx_obj_3_sa_SuffixArray *)__pyx_v_self), ((PyObject *)__pyx_v_loc)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":29 + * return self.darray.getSent(i) + * + * def getSentPos(self, loc): # <<<<<<<<<<<<<< + * return self.darray.getSentPos(loc) + * + */ + +static PyObject *__pyx_pf_3_sa_11SuffixArray_8getSentPos(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_loc) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("getSentPos", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":30 + * + * def getSentPos(self, loc): + * return self.darray.getSentPos(loc) # <<<<<<<<<<<<<< + * + * def read_text(self, char* filename): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->darray), __pyx_n_s__getSentPos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_loc); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_loc); + __Pyx_GIVEREF(__pyx_v_loc); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.SuffixArray.getSentPos", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_11SuffixArray_11read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static char __pyx_doc_3_sa_11SuffixArray_10read_text[] = "Constructs suffix array using the algorithm\n of Larsson & Sadahkane (1999)"; +static PyObject *__pyx_pw_3_sa_11SuffixArray_11read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_text (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.SuffixArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_11SuffixArray_10read_text(((struct __pyx_obj_3_sa_SuffixArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":32 + * return self.darray.getSentPos(loc) + * + * def read_text(self, char* filename): # <<<<<<<<<<<<<< + * '''Constructs suffix array using the algorithm + * of Larsson & Sadahkane (1999)''' + */ + +static PyObject *__pyx_pf_3_sa_11SuffixArray_10read_text(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename) { + int __pyx_v_V; + int __pyx_v_N; + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_h; + int __pyx_v_a_i; + int __pyx_v_n; + int __pyx_v_current_run; + int __pyx_v_skip; + struct __pyx_obj_3_sa_IntList *__pyx_v_isa = 0; + struct __pyx_obj_3_sa_IntList *__pyx_v_word_count = 0; + float __pyx_v_sort_start_time; + float __pyx_v_start_time; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + long __pyx_t_5; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_text", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":38 + * cdef IntList isa, word_count + * + * self.darray = DataArray(from_text=filename, use_sent_id=True) # <<<<<<<<<<<<<< + * N = len(self.darray) + * V = len(self.darray.id2word) + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__from_text), ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__use_sent_id), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_DataArray)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 38; __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); + __Pyx_GOTREF(__pyx_v_self->darray); + __Pyx_DECREF(((PyObject *)__pyx_v_self->darray)); + __pyx_v_self->darray = ((struct __pyx_obj_3_sa_DataArray *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":39 + * + * self.darray = DataArray(from_text=filename, use_sent_id=True) + * N = len(self.darray) # <<<<<<<<<<<<<< + * V = len(self.darray.id2word) + * + */ + __pyx_t_2 = ((PyObject *)__pyx_v_self->darray); + __Pyx_INCREF(__pyx_t_2); + __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_N = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":40 + * self.darray = DataArray(from_text=filename, use_sent_id=True) + * N = len(self.darray) + * V = len(self.darray.id2word) # <<<<<<<<<<<<<< + * + * self.sa = IntList(initial_len=N) + */ + __pyx_t_2 = __pyx_v_self->darray->id2word; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_V = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":42 + * V = len(self.darray.id2word) + * + * self.sa = IntList(initial_len=N) # <<<<<<<<<<<<<< + * self.ha = IntList(initial_len=V+1) + * + */ + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->sa); + __Pyx_DECREF(((PyObject *)__pyx_v_self->sa)); + __pyx_v_self->sa = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":43 + * + * self.sa = IntList(initial_len=N) + * self.ha = IntList(initial_len=V+1) # <<<<<<<<<<<<<< + * + * isa = IntList(initial_len=N) + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyInt_FromLong((__pyx_v_V + 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 43; __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); + __Pyx_GOTREF(__pyx_v_self->ha); + __Pyx_DECREF(((PyObject *)__pyx_v_self->ha)); + __pyx_v_self->ha = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":45 + * self.ha = IntList(initial_len=V+1) + * + * isa = IntList(initial_len=N) # <<<<<<<<<<<<<< + * word_count = IntList(initial_len=V+1) + * + */ + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_1 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_v_isa = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":46 + * + * isa = IntList(initial_len=N) + * word_count = IntList(initial_len=V+1) # <<<<<<<<<<<<<< + * + * '''Step 1: bucket sort data''' + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyInt_FromLong((__pyx_v_V + 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_v_word_count = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":49 + * + * '''Step 1: bucket sort data''' + * cdef float sort_start_time = monitor_cpu() # <<<<<<<<<<<<<< + * cdef float start_time = sort_start_time + * for i from 0 <= i < N: + */ + __pyx_v_sort_start_time = __pyx_f_3_sa_monitor_cpu(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":50 + * '''Step 1: bucket sort data''' + * cdef float sort_start_time = monitor_cpu() + * cdef float start_time = sort_start_time # <<<<<<<<<<<<<< + * for i from 0 <= i < N: + * a_i = self.darray.data.arr[i] + */ + __pyx_v_start_time = __pyx_v_sort_start_time; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":51 + * cdef float sort_start_time = monitor_cpu() + * cdef float start_time = sort_start_time + * for i from 0 <= i < N: # <<<<<<<<<<<<<< + * a_i = self.darray.data.arr[i] + * word_count.arr[a_i] = word_count.arr[a_i] + 1 + */ + __pyx_t_4 = __pyx_v_N; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":52 + * cdef float start_time = sort_start_time + * for i from 0 <= i < N: + * a_i = self.darray.data.arr[i] # <<<<<<<<<<<<<< + * word_count.arr[a_i] = word_count.arr[a_i] + 1 + * + */ + __pyx_v_a_i = (__pyx_v_self->darray->data->arr[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":53 + * for i from 0 <= i < N: + * a_i = self.darray.data.arr[i] + * word_count.arr[a_i] = word_count.arr[a_i] + 1 # <<<<<<<<<<<<<< + * + * n = 0 + */ + (__pyx_v_word_count->arr[__pyx_v_a_i]) = ((__pyx_v_word_count->arr[__pyx_v_a_i]) + 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":55 + * word_count.arr[a_i] = word_count.arr[a_i] + 1 + * + * n = 0 # <<<<<<<<<<<<<< + * for i from 0 <= i < V+1: + * self.ha.arr[i] = n + */ + __pyx_v_n = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":56 + * + * n = 0 + * for i from 0 <= i < V+1: # <<<<<<<<<<<<<< + * self.ha.arr[i] = n + * n = n + word_count.arr[i] + */ + __pyx_t_5 = (__pyx_v_V + 1); + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_5; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":57 + * n = 0 + * for i from 0 <= i < V+1: + * self.ha.arr[i] = n # <<<<<<<<<<<<<< + * n = n + word_count.arr[i] + * word_count.arr[i] = 0 + */ + (__pyx_v_self->ha->arr[__pyx_v_i]) = __pyx_v_n; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":58 + * for i from 0 <= i < V+1: + * self.ha.arr[i] = n + * n = n + word_count.arr[i] # <<<<<<<<<<<<<< + * word_count.arr[i] = 0 + * + */ + __pyx_v_n = (__pyx_v_n + (__pyx_v_word_count->arr[__pyx_v_i])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":59 + * self.ha.arr[i] = n + * n = n + word_count.arr[i] + * word_count.arr[i] = 0 # <<<<<<<<<<<<<< + * + * for i from 0 <= i < N: + */ + (__pyx_v_word_count->arr[__pyx_v_i]) = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":61 + * word_count.arr[i] = 0 + * + * for i from 0 <= i < N: # <<<<<<<<<<<<<< + * a_i = self.darray.data.arr[i] + * self.sa.arr[self.ha.arr[a_i] + word_count.arr[a_i]] = i + */ + __pyx_t_4 = __pyx_v_N; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":62 + * + * for i from 0 <= i < N: + * a_i = self.darray.data.arr[i] # <<<<<<<<<<<<<< + * self.sa.arr[self.ha.arr[a_i] + word_count.arr[a_i]] = i + * isa.arr[i] = self.ha.arr[a_i + 1] - 1 # bucket pointer is last index in bucket + */ + __pyx_v_a_i = (__pyx_v_self->darray->data->arr[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":63 + * for i from 0 <= i < N: + * a_i = self.darray.data.arr[i] + * self.sa.arr[self.ha.arr[a_i] + word_count.arr[a_i]] = i # <<<<<<<<<<<<<< + * isa.arr[i] = self.ha.arr[a_i + 1] - 1 # bucket pointer is last index in bucket + * word_count.arr[a_i] = word_count.arr[a_i] + 1 + */ + (__pyx_v_self->sa->arr[((__pyx_v_self->ha->arr[__pyx_v_a_i]) + (__pyx_v_word_count->arr[__pyx_v_a_i]))]) = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":64 + * a_i = self.darray.data.arr[i] + * self.sa.arr[self.ha.arr[a_i] + word_count.arr[a_i]] = i + * isa.arr[i] = self.ha.arr[a_i + 1] - 1 # bucket pointer is last index in bucket # <<<<<<<<<<<<<< + * word_count.arr[a_i] = word_count.arr[a_i] + 1 + * + */ + (__pyx_v_isa->arr[__pyx_v_i]) = ((__pyx_v_self->ha->arr[(__pyx_v_a_i + 1)]) - 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":65 + * self.sa.arr[self.ha.arr[a_i] + word_count.arr[a_i]] = i + * isa.arr[i] = self.ha.arr[a_i + 1] - 1 # bucket pointer is last index in bucket + * word_count.arr[a_i] = word_count.arr[a_i] + 1 # <<<<<<<<<<<<<< + * + * '''Determine size of initial runs''' + */ + (__pyx_v_word_count->arr[__pyx_v_a_i]) = ((__pyx_v_word_count->arr[__pyx_v_a_i]) + 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":68 + * + * '''Determine size of initial runs''' + * current_run = 0 # <<<<<<<<<<<<<< + * for i from 0 <= i < V+1: + * if i < V and self.ha.arr[i+1] - self.ha.arr[i] == 1: + */ + __pyx_v_current_run = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":69 + * '''Determine size of initial runs''' + * current_run = 0 + * for i from 0 <= i < V+1: # <<<<<<<<<<<<<< + * if i < V and self.ha.arr[i+1] - self.ha.arr[i] == 1: + * current_run = current_run + 1 + */ + __pyx_t_5 = (__pyx_v_V + 1); + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_5; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":70 + * current_run = 0 + * for i from 0 <= i < V+1: + * if i < V and self.ha.arr[i+1] - self.ha.arr[i] == 1: # <<<<<<<<<<<<<< + * current_run = current_run + 1 + * else: + */ + __pyx_t_6 = (__pyx_v_i < __pyx_v_V); + if (__pyx_t_6) { + __pyx_t_7 = (((__pyx_v_self->ha->arr[(__pyx_v_i + 1)]) - (__pyx_v_self->ha->arr[__pyx_v_i])) == 1); + __pyx_t_8 = __pyx_t_7; + } else { + __pyx_t_8 = __pyx_t_6; + } + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":71 + * for i from 0 <= i < V+1: + * if i < V and self.ha.arr[i+1] - self.ha.arr[i] == 1: + * current_run = current_run + 1 # <<<<<<<<<<<<<< + * else: + * if current_run > 0: + */ + __pyx_v_current_run = (__pyx_v_current_run + 1); + goto __pyx_L11; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":73 + * current_run = current_run + 1 + * else: + * if current_run > 0: # <<<<<<<<<<<<<< + * self.sa.arr[self.ha.arr[i] - current_run] = -current_run + * current_run = 0 + */ + __pyx_t_8 = (__pyx_v_current_run > 0); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":74 + * else: + * if current_run > 0: + * self.sa.arr[self.ha.arr[i] - current_run] = -current_run # <<<<<<<<<<<<<< + * current_run = 0 + * + */ + (__pyx_v_self->sa->arr[((__pyx_v_self->ha->arr[__pyx_v_i]) - __pyx_v_current_run)]) = (-__pyx_v_current_run); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":75 + * if current_run > 0: + * self.sa.arr[self.ha.arr[i] - current_run] = -current_run + * current_run = 0 # <<<<<<<<<<<<<< + * + * logger.info(" Bucket sort took %f seconds", (monitor_cpu() - sort_start_time)) + */ + __pyx_v_current_run = 0; + goto __pyx_L12; + } + __pyx_L12:; + } + __pyx_L11:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":77 + * current_run = 0 + * + * logger.info(" Bucket sort took %f seconds", (monitor_cpu() - sort_start_time)) # <<<<<<<<<<<<<< + * + * '''Step 2: prefix-doubling sort''' + */ + __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__info); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyFloat_FromDouble((__pyx_f_3_sa_monitor_cpu() - __pyx_v_sort_start_time)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_87)); + PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_kp_s_87)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_87)); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":80 + * + * '''Step 2: prefix-doubling sort''' + * h = 1 # <<<<<<<<<<<<<< + * while self.sa.arr[0] != -N: + * sort_start_time = monitor_cpu() + */ + __pyx_v_h = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":81 + * '''Step 2: prefix-doubling sort''' + * h = 1 + * while self.sa.arr[0] != -N: # <<<<<<<<<<<<<< + * sort_start_time = monitor_cpu() + * logger.debug(" Refining, sort depth = %d", h) + */ + while (1) { + __pyx_t_8 = ((__pyx_v_self->sa->arr[0]) != (-__pyx_v_N)); + if (!__pyx_t_8) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":82 + * h = 1 + * while self.sa.arr[0] != -N: + * sort_start_time = monitor_cpu() # <<<<<<<<<<<<<< + * logger.debug(" Refining, sort depth = %d", h) + * i = 0 + */ + __pyx_v_sort_start_time = __pyx_f_3_sa_monitor_cpu(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":83 + * while self.sa.arr[0] != -N: + * sort_start_time = monitor_cpu() + * logger.debug(" Refining, sort depth = %d", h) # <<<<<<<<<<<<<< + * i = 0 + * skip = 0 + */ + __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__debug); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_88)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_88)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_88)); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":84 + * sort_start_time = monitor_cpu() + * logger.debug(" Refining, sort depth = %d", h) + * i = 0 # <<<<<<<<<<<<<< + * skip = 0 + * while i < N: + */ + __pyx_v_i = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":85 + * logger.debug(" Refining, sort depth = %d", h) + * i = 0 + * skip = 0 # <<<<<<<<<<<<<< + * while i < N: + * if self.sa.arr[i] < 0: + */ + __pyx_v_skip = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":86 + * i = 0 + * skip = 0 + * while i < N: # <<<<<<<<<<<<<< + * if self.sa.arr[i] < 0: + * skip = skip + self.sa.arr[i] + */ + while (1) { + __pyx_t_8 = (__pyx_v_i < __pyx_v_N); + if (!__pyx_t_8) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":87 + * skip = 0 + * while i < N: + * if self.sa.arr[i] < 0: # <<<<<<<<<<<<<< + * skip = skip + self.sa.arr[i] + * i = i - self.sa.arr[i] + */ + __pyx_t_8 = ((__pyx_v_self->sa->arr[__pyx_v_i]) < 0); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":88 + * while i < N: + * if self.sa.arr[i] < 0: + * skip = skip + self.sa.arr[i] # <<<<<<<<<<<<<< + * i = i - self.sa.arr[i] + * else: + */ + __pyx_v_skip = (__pyx_v_skip + (__pyx_v_self->sa->arr[__pyx_v_i])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":89 + * if self.sa.arr[i] < 0: + * skip = skip + self.sa.arr[i] + * i = i - self.sa.arr[i] # <<<<<<<<<<<<<< + * else: + * if skip < 0: + */ + __pyx_v_i = (__pyx_v_i - (__pyx_v_self->sa->arr[__pyx_v_i])); + goto __pyx_L17; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":91 + * i = i - self.sa.arr[i] + * else: + * if skip < 0: # <<<<<<<<<<<<<< + * self.sa.arr[i+skip] = skip + * skip = 0 + */ + __pyx_t_8 = (__pyx_v_skip < 0); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":92 + * else: + * if skip < 0: + * self.sa.arr[i+skip] = skip # <<<<<<<<<<<<<< + * skip = 0 + * j = isa.arr[self.sa.arr[i]] + */ + (__pyx_v_self->sa->arr[(__pyx_v_i + __pyx_v_skip)]) = __pyx_v_skip; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":93 + * if skip < 0: + * self.sa.arr[i+skip] = skip + * skip = 0 # <<<<<<<<<<<<<< + * j = isa.arr[self.sa.arr[i]] + * self.q3sort(i, j, h, isa) + */ + __pyx_v_skip = 0; + goto __pyx_L18; + } + __pyx_L18:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":94 + * self.sa.arr[i+skip] = skip + * skip = 0 + * j = isa.arr[self.sa.arr[i]] # <<<<<<<<<<<<<< + * self.q3sort(i, j, h, isa) + * i = j+1 + */ + __pyx_v_j = (__pyx_v_isa->arr[(__pyx_v_self->sa->arr[__pyx_v_i])]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":95 + * skip = 0 + * j = isa.arr[self.sa.arr[i]] + * self.q3sort(i, j, h, isa) # <<<<<<<<<<<<<< + * i = j+1 + * if skip < 0: + */ + __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__q3sort); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = PyInt_FromLong(__pyx_v_j); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_11 = PyTuple_New(4); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_11); + PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __Pyx_INCREF(((PyObject *)__pyx_v_isa)); + PyTuple_SET_ITEM(__pyx_t_11, 3, ((PyObject *)__pyx_v_isa)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_isa)); + __pyx_t_1 = 0; + __pyx_t_9 = 0; + __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":96 + * j = isa.arr[self.sa.arr[i]] + * self.q3sort(i, j, h, isa) + * i = j+1 # <<<<<<<<<<<<<< + * if skip < 0: + * self.sa.arr[i+skip] = skip + */ + __pyx_v_i = (__pyx_v_j + 1); + } + __pyx_L17:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":97 + * self.q3sort(i, j, h, isa) + * i = j+1 + * if skip < 0: # <<<<<<<<<<<<<< + * self.sa.arr[i+skip] = skip + * h = h * 2 + */ + __pyx_t_8 = (__pyx_v_skip < 0); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":98 + * i = j+1 + * if skip < 0: + * self.sa.arr[i+skip] = skip # <<<<<<<<<<<<<< + * h = h * 2 + * logger.debug(" Refinement took %f seconds", (monitor_cpu() - sort_start_time)) + */ + (__pyx_v_self->sa->arr[(__pyx_v_i + __pyx_v_skip)]) = __pyx_v_skip; + goto __pyx_L19; + } + __pyx_L19:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":99 + * if skip < 0: + * self.sa.arr[i+skip] = skip + * h = h * 2 # <<<<<<<<<<<<<< + * logger.debug(" Refinement took %f seconds", (monitor_cpu() - sort_start_time)) + * + */ + __pyx_v_h = (__pyx_v_h * 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":100 + * self.sa.arr[i+skip] = skip + * h = h * 2 + * logger.debug(" Refinement took %f seconds", (monitor_cpu() - sort_start_time)) # <<<<<<<<<<<<<< + * + * '''Step 3: read off suffix array from inverse suffix array''' + */ + __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_11 = PyObject_GetAttr(__pyx_t_10, __pyx_n_s__debug); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = PyFloat_FromDouble((__pyx_f_3_sa_monitor_cpu() - __pyx_v_sort_start_time)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_89)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_89)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_89)); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":103 + * + * '''Step 3: read off suffix array from inverse suffix array''' + * logger.info(" Finalizing sort...") # <<<<<<<<<<<<<< + * for i from 0 <= i < N: + * j = isa.arr[i] + */ + __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_10, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_91), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":104 + * '''Step 3: read off suffix array from inverse suffix array''' + * logger.info(" Finalizing sort...") + * for i from 0 <= i < N: # <<<<<<<<<<<<<< + * j = isa.arr[i] + * self.sa.arr[j] = i + */ + __pyx_t_4 = __pyx_v_N; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":105 + * logger.info(" Finalizing sort...") + * for i from 0 <= i < N: + * j = isa.arr[i] # <<<<<<<<<<<<<< + * self.sa.arr[j] = i + * logger.info("Suffix array construction took %f seconds", (monitor_cpu() - start_time)) + */ + __pyx_v_j = (__pyx_v_isa->arr[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":106 + * for i from 0 <= i < N: + * j = isa.arr[i] + * self.sa.arr[j] = i # <<<<<<<<<<<<<< + * logger.info("Suffix array construction took %f seconds", (monitor_cpu() - start_time)) + * + */ + (__pyx_v_self->sa->arr[__pyx_v_j]) = __pyx_v_i; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":107 + * j = isa.arr[i] + * self.sa.arr[j] = i + * logger.info("Suffix array construction took %f seconds", (monitor_cpu() - start_time)) # <<<<<<<<<<<<<< + * + * def q3sort(self, int i, int j, int h, IntList isa, pad=""): + */ + __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_10, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = PyFloat_FromDouble((__pyx_f_3_sa_monitor_cpu() - __pyx_v_start_time)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_92)); + PyTuple_SET_ITEM(__pyx_t_11, 0, ((PyObject *)__pyx_kp_s_92)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_92)); + PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + __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_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("_sa.SuffixArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_isa); + __Pyx_XDECREF((PyObject *)__pyx_v_word_count); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_11SuffixArray_13q3sort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_3_sa_11SuffixArray_12q3sort[] = "This is a ternary quicksort. It divides the array into\n three partitions: items less than the pivot, items equal\n to pivot, and items greater than pivot. The first and last\n of these partitions are then recursively sorted"; +static PyObject *__pyx_pw_3_sa_11SuffixArray_13q3sort(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_h; + struct __pyx_obj_3_sa_IntList *__pyx_v_isa = 0; + PyObject *__pyx_v_pad = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("q3sort (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__i,&__pyx_n_s__j,&__pyx_n_s__h,&__pyx_n_s__isa,&__pyx_n_s__pad,0}; + PyObject* values[5] = {0,0,0,0,0}; + values[4] = ((PyObject *)__pyx_kp_s_42); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__i)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__j)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("q3sort", 0, 4, 5, 1); {__pyx_filename = __pyx_f[13]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__h)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("q3sort", 0, 4, 5, 2); {__pyx_filename = __pyx_f[13]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 3: + if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__isa)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("q3sort", 0, 4, 5, 3); {__pyx_filename = __pyx_f[13]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pad); + if (value) { values[4] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "q3sort") < 0)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_i = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_i == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_j = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_j == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_h = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_h == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_isa = ((struct __pyx_obj_3_sa_IntList *)values[3]); + __pyx_v_pad = values[4]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("q3sort", 0, 4, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[13]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.SuffixArray.q3sort", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_isa), __pyx_ptype_3_sa_IntList, 1, "isa", 0))) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_3_sa_11SuffixArray_12q3sort(((struct __pyx_obj_3_sa_SuffixArray *)__pyx_v_self), __pyx_v_i, __pyx_v_j, __pyx_v_h, __pyx_v_isa, __pyx_v_pad); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":109 + * logger.info("Suffix array construction took %f seconds", (monitor_cpu() - start_time)) + * + * def q3sort(self, int i, int j, int h, IntList isa, pad=""): # <<<<<<<<<<<<<< + * '''This is a ternary quicksort. It divides the array into + * three partitions: items less than the pivot, items equal + */ + +static PyObject *__pyx_pf_3_sa_11SuffixArray_12q3sort(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, int __pyx_v_i, int __pyx_v_j, int __pyx_v_h, struct __pyx_obj_3_sa_IntList *__pyx_v_isa, PyObject *__pyx_v_pad) { + int __pyx_v_k; + int __pyx_v_midpoint; + int __pyx_v_pval; + int __pyx_v_phead; + int __pyx_v_ptail; + int __pyx_v_tmp; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + long __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("q3sort", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":116 + * cdef int k, midpoint, pval, phead, ptail, tmp + * + * if j-i < -1: # <<<<<<<<<<<<<< + * raise Exception("Unexpected condition found in q3sort: sort from %d to %d" % (i,j)) + * if j-i == -1: # recursive base case -- empty interval + */ + __pyx_t_1 = ((__pyx_v_j - __pyx_v_i) < -1); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":117 + * + * if j-i < -1: + * raise Exception("Unexpected condition found in q3sort: sort from %d to %d" % (i,j)) # <<<<<<<<<<<<<< + * if j-i == -1: # recursive base case -- empty interval + * return + */ + __pyx_t_2 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyInt_FromLong(__pyx_v_j); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_93), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_3)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__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[13]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":118 + * if j-i < -1: + * raise Exception("Unexpected condition found in q3sort: sort from %d to %d" % (i,j)) + * if j-i == -1: # recursive base case -- empty interval # <<<<<<<<<<<<<< + * return + * if (j-i == 0): # recursive base case -- singleton interval + */ + __pyx_t_1 = ((__pyx_v_j - __pyx_v_i) == -1); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":119 + * raise Exception("Unexpected condition found in q3sort: sort from %d to %d" % (i,j)) + * if j-i == -1: # recursive base case -- empty interval + * return # <<<<<<<<<<<<<< + * if (j-i == 0): # recursive base case -- singleton interval + * isa.arr[self.sa.arr[i]] = i + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":120 + * if j-i == -1: # recursive base case -- empty interval + * return + * if (j-i == 0): # recursive base case -- singleton interval # <<<<<<<<<<<<<< + * isa.arr[self.sa.arr[i]] = i + * self.sa.arr[i] = -1 + */ + __pyx_t_1 = ((__pyx_v_j - __pyx_v_i) == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":121 + * return + * if (j-i == 0): # recursive base case -- singleton interval + * isa.arr[self.sa.arr[i]] = i # <<<<<<<<<<<<<< + * self.sa.arr[i] = -1 + * return + */ + (__pyx_v_isa->arr[(__pyx_v_self->sa->arr[__pyx_v_i])]) = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":122 + * if (j-i == 0): # recursive base case -- singleton interval + * isa.arr[self.sa.arr[i]] = i + * self.sa.arr[i] = -1 # <<<<<<<<<<<<<< + * return + * + */ + (__pyx_v_self->sa->arr[__pyx_v_i]) = -1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":123 + * isa.arr[self.sa.arr[i]] = i + * self.sa.arr[i] = -1 + * return # <<<<<<<<<<<<<< + * + * # NOTE: choosing the first item as a pivot value resulted in + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":132 + * # If the method of assigning word_id's is changed, this method + * # may need to be reconsidered as well. + * midpoint = (i+j)/2 # <<<<<<<<<<<<<< + * pval = isa.arr[self.sa.arr[midpoint] + h] + * if i != midpoint: + */ + __pyx_v_midpoint = __Pyx_div_long((__pyx_v_i + __pyx_v_j), 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":133 + * # may need to be reconsidered as well. + * midpoint = (i+j)/2 + * pval = isa.arr[self.sa.arr[midpoint] + h] # <<<<<<<<<<<<<< + * if i != midpoint: + * tmp = self.sa.arr[midpoint] + */ + __pyx_v_pval = (__pyx_v_isa->arr[((__pyx_v_self->sa->arr[__pyx_v_midpoint]) + __pyx_v_h)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":134 + * midpoint = (i+j)/2 + * pval = isa.arr[self.sa.arr[midpoint] + h] + * if i != midpoint: # <<<<<<<<<<<<<< + * tmp = self.sa.arr[midpoint] + * self.sa.arr[midpoint] = self.sa.arr[i] + */ + __pyx_t_1 = (__pyx_v_i != __pyx_v_midpoint); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":135 + * pval = isa.arr[self.sa.arr[midpoint] + h] + * if i != midpoint: + * tmp = self.sa.arr[midpoint] # <<<<<<<<<<<<<< + * self.sa.arr[midpoint] = self.sa.arr[i] + * self.sa.arr[i] = tmp + */ + __pyx_v_tmp = (__pyx_v_self->sa->arr[__pyx_v_midpoint]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":136 + * if i != midpoint: + * tmp = self.sa.arr[midpoint] + * self.sa.arr[midpoint] = self.sa.arr[i] # <<<<<<<<<<<<<< + * self.sa.arr[i] = tmp + * phead = i + */ + (__pyx_v_self->sa->arr[__pyx_v_midpoint]) = (__pyx_v_self->sa->arr[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":137 + * tmp = self.sa.arr[midpoint] + * self.sa.arr[midpoint] = self.sa.arr[i] + * self.sa.arr[i] = tmp # <<<<<<<<<<<<<< + * phead = i + * ptail = i + */ + (__pyx_v_self->sa->arr[__pyx_v_i]) = __pyx_v_tmp; + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":138 + * self.sa.arr[midpoint] = self.sa.arr[i] + * self.sa.arr[i] = tmp + * phead = i # <<<<<<<<<<<<<< + * ptail = i + * + */ + __pyx_v_phead = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":139 + * self.sa.arr[i] = tmp + * phead = i + * ptail = i # <<<<<<<<<<<<<< + * + * # find the three partitions. phead marks the first element + */ + __pyx_v_ptail = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":143 + * # find the three partitions. phead marks the first element + * # of the middle partition, and ptail marks the last element + * for k from i+1 <= k < j+1: # <<<<<<<<<<<<<< + * if isa.arr[self.sa.arr[k] + h] < pval: + * if k > ptail+1: + */ + __pyx_t_5 = (__pyx_v_j + 1); + for (__pyx_v_k = (__pyx_v_i + 1); __pyx_v_k < __pyx_t_5; __pyx_v_k++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":144 + * # of the middle partition, and ptail marks the last element + * for k from i+1 <= k < j+1: + * if isa.arr[self.sa.arr[k] + h] < pval: # <<<<<<<<<<<<<< + * if k > ptail+1: + * tmp = self.sa.arr[phead] + */ + __pyx_t_1 = ((__pyx_v_isa->arr[((__pyx_v_self->sa->arr[__pyx_v_k]) + __pyx_v_h)]) < __pyx_v_pval); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":145 + * for k from i+1 <= k < j+1: + * if isa.arr[self.sa.arr[k] + h] < pval: + * if k > ptail+1: # <<<<<<<<<<<<<< + * tmp = self.sa.arr[phead] + * self.sa.arr[phead] = self.sa.arr[k] + */ + __pyx_t_1 = (__pyx_v_k > (__pyx_v_ptail + 1)); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":146 + * if isa.arr[self.sa.arr[k] + h] < pval: + * if k > ptail+1: + * tmp = self.sa.arr[phead] # <<<<<<<<<<<<<< + * self.sa.arr[phead] = self.sa.arr[k] + * self.sa.arr[k] = self.sa.arr[ptail+1] + */ + __pyx_v_tmp = (__pyx_v_self->sa->arr[__pyx_v_phead]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":147 + * if k > ptail+1: + * tmp = self.sa.arr[phead] + * self.sa.arr[phead] = self.sa.arr[k] # <<<<<<<<<<<<<< + * self.sa.arr[k] = self.sa.arr[ptail+1] + * self.sa.arr[ptail+1] = tmp + */ + (__pyx_v_self->sa->arr[__pyx_v_phead]) = (__pyx_v_self->sa->arr[__pyx_v_k]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":148 + * tmp = self.sa.arr[phead] + * self.sa.arr[phead] = self.sa.arr[k] + * self.sa.arr[k] = self.sa.arr[ptail+1] # <<<<<<<<<<<<<< + * self.sa.arr[ptail+1] = tmp + * else: # k == ptail+1 + */ + (__pyx_v_self->sa->arr[__pyx_v_k]) = (__pyx_v_self->sa->arr[(__pyx_v_ptail + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":149 + * self.sa.arr[phead] = self.sa.arr[k] + * self.sa.arr[k] = self.sa.arr[ptail+1] + * self.sa.arr[ptail+1] = tmp # <<<<<<<<<<<<<< + * else: # k == ptail+1 + * tmp = self.sa.arr[phead] + */ + (__pyx_v_self->sa->arr[(__pyx_v_ptail + 1)]) = __pyx_v_tmp; + goto __pyx_L10; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":151 + * self.sa.arr[ptail+1] = tmp + * else: # k == ptail+1 + * tmp = self.sa.arr[phead] # <<<<<<<<<<<<<< + * self.sa.arr[phead] = self.sa.arr[k] + * self.sa.arr[k] = tmp + */ + __pyx_v_tmp = (__pyx_v_self->sa->arr[__pyx_v_phead]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":152 + * else: # k == ptail+1 + * tmp = self.sa.arr[phead] + * self.sa.arr[phead] = self.sa.arr[k] # <<<<<<<<<<<<<< + * self.sa.arr[k] = tmp + * phead = phead + 1 + */ + (__pyx_v_self->sa->arr[__pyx_v_phead]) = (__pyx_v_self->sa->arr[__pyx_v_k]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":153 + * tmp = self.sa.arr[phead] + * self.sa.arr[phead] = self.sa.arr[k] + * self.sa.arr[k] = tmp # <<<<<<<<<<<<<< + * phead = phead + 1 + * ptail = ptail + 1 + */ + (__pyx_v_self->sa->arr[__pyx_v_k]) = __pyx_v_tmp; + } + __pyx_L10:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":154 + * self.sa.arr[phead] = self.sa.arr[k] + * self.sa.arr[k] = tmp + * phead = phead + 1 # <<<<<<<<<<<<<< + * ptail = ptail + 1 + * else: + */ + __pyx_v_phead = (__pyx_v_phead + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":155 + * self.sa.arr[k] = tmp + * phead = phead + 1 + * ptail = ptail + 1 # <<<<<<<<<<<<<< + * else: + * if isa.arr[self.sa.arr[k] + h] == pval: + */ + __pyx_v_ptail = (__pyx_v_ptail + 1); + goto __pyx_L9; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":157 + * ptail = ptail + 1 + * else: + * if isa.arr[self.sa.arr[k] + h] == pval: # <<<<<<<<<<<<<< + * if k > ptail+1: + * tmp = self.sa.arr[ptail+1] + */ + __pyx_t_1 = ((__pyx_v_isa->arr[((__pyx_v_self->sa->arr[__pyx_v_k]) + __pyx_v_h)]) == __pyx_v_pval); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":158 + * else: + * if isa.arr[self.sa.arr[k] + h] == pval: + * if k > ptail+1: # <<<<<<<<<<<<<< + * tmp = self.sa.arr[ptail+1] + * self.sa.arr[ptail+1] = self.sa.arr[k] + */ + __pyx_t_1 = (__pyx_v_k > (__pyx_v_ptail + 1)); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":159 + * if isa.arr[self.sa.arr[k] + h] == pval: + * if k > ptail+1: + * tmp = self.sa.arr[ptail+1] # <<<<<<<<<<<<<< + * self.sa.arr[ptail+1] = self.sa.arr[k] + * self.sa.arr[k] = tmp + */ + __pyx_v_tmp = (__pyx_v_self->sa->arr[(__pyx_v_ptail + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":160 + * if k > ptail+1: + * tmp = self.sa.arr[ptail+1] + * self.sa.arr[ptail+1] = self.sa.arr[k] # <<<<<<<<<<<<<< + * self.sa.arr[k] = tmp + * ptail = ptail + 1 + */ + (__pyx_v_self->sa->arr[(__pyx_v_ptail + 1)]) = (__pyx_v_self->sa->arr[__pyx_v_k]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":161 + * tmp = self.sa.arr[ptail+1] + * self.sa.arr[ptail+1] = self.sa.arr[k] + * self.sa.arr[k] = tmp # <<<<<<<<<<<<<< + * ptail = ptail + 1 + * + */ + (__pyx_v_self->sa->arr[__pyx_v_k]) = __pyx_v_tmp; + goto __pyx_L12; + } + __pyx_L12:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":162 + * self.sa.arr[ptail+1] = self.sa.arr[k] + * self.sa.arr[k] = tmp + * ptail = ptail + 1 # <<<<<<<<<<<<<< + * + * # recursively sort smaller suffixes + */ + __pyx_v_ptail = (__pyx_v_ptail + 1); + goto __pyx_L11; + } + __pyx_L11:; + } + __pyx_L9:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":165 + * + * # recursively sort smaller suffixes + * self.q3sort(i, phead-1, h, isa, pad+" ") # <<<<<<<<<<<<<< + * + * # update suffixes with pivot value + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__q3sort); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyInt_FromLong((__pyx_v_phead - 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyTuple_New(5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + __Pyx_INCREF(((PyObject *)__pyx_v_isa)); + PyTuple_SET_ITEM(__pyx_t_8, 3, ((PyObject *)__pyx_v_isa)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_isa)); + PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + __pyx_t_4 = 0; + __pyx_t_2 = 0; + __pyx_t_6 = 0; + __pyx_t_7 = 0; + __pyx_t_7 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":169 + * # update suffixes with pivot value + * # corresponds to update_group function in Larsson & Sadakane + * for k from phead <= k < ptail+1: # <<<<<<<<<<<<<< + * isa.arr[self.sa.arr[k]] = ptail + * if phead == ptail: + */ + __pyx_t_5 = (__pyx_v_ptail + 1); + for (__pyx_v_k = __pyx_v_phead; __pyx_v_k < __pyx_t_5; __pyx_v_k++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":170 + * # corresponds to update_group function in Larsson & Sadakane + * for k from phead <= k < ptail+1: + * isa.arr[self.sa.arr[k]] = ptail # <<<<<<<<<<<<<< + * if phead == ptail: + * self.sa.arr[phead] = -1 + */ + (__pyx_v_isa->arr[(__pyx_v_self->sa->arr[__pyx_v_k])]) = __pyx_v_ptail; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":171 + * for k from phead <= k < ptail+1: + * isa.arr[self.sa.arr[k]] = ptail + * if phead == ptail: # <<<<<<<<<<<<<< + * self.sa.arr[phead] = -1 + * + */ + __pyx_t_1 = (__pyx_v_phead == __pyx_v_ptail); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":172 + * isa.arr[self.sa.arr[k]] = ptail + * if phead == ptail: + * self.sa.arr[phead] = -1 # <<<<<<<<<<<<<< + * + * # recursively sort larger suffixes + */ + (__pyx_v_self->sa->arr[__pyx_v_phead]) = -1; + goto __pyx_L15; + } + __pyx_L15:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":175 + * + * # recursively sort larger suffixes + * self.q3sort(ptail+1, j, h, isa, pad+" ") # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__q3sort); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyInt_FromLong((__pyx_v_ptail + 1)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = PyInt_FromLong(__pyx_v_j); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_2 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + __Pyx_INCREF(((PyObject *)__pyx_v_isa)); + PyTuple_SET_ITEM(__pyx_t_4, 3, ((PyObject *)__pyx_v_isa)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_isa)); + PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_8 = 0; + __pyx_t_3 = 0; + __pyx_t_6 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_sa.SuffixArray.q3sort", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_11SuffixArray_15write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_11SuffixArray_15write_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_text (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.SuffixArray.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_11SuffixArray_14write_text(((struct __pyx_obj_3_sa_SuffixArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":178 + * + * + * def write_text(self, char* filename): # <<<<<<<<<<<<<< + * self.darray.write_text(filename) + * + */ + +static PyObject *__pyx_pf_3_sa_11SuffixArray_14write_text(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_text", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":179 + * + * def write_text(self, char* filename): + * self.darray.write_text(filename) # <<<<<<<<<<<<<< + * + * def read_binary(self, char* filename): + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->darray), __pyx_n_s__write_text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 179; __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[13]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + __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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.SuffixArray.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_11SuffixArray_17read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_11SuffixArray_17read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.SuffixArray.read_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_11SuffixArray_16read_binary(((struct __pyx_obj_3_sa_SuffixArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":181 + * self.darray.write_text(filename) + * + * def read_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE *f + * f = fopen(filename, "r") + */ + +static PyObject *__pyx_pf_3_sa_11SuffixArray_16read_binary(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":183 + * def read_binary(self, char* filename): + * cdef FILE *f + * f = fopen(filename, "r") # <<<<<<<<<<<<<< + * self.darray.read_handle(f) + * self.sa.read_handle(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":184 + * cdef FILE *f + * f = fopen(filename, "r") + * self.darray.read_handle(f) # <<<<<<<<<<<<<< + * self.sa.read_handle(f) + * self.ha.read_handle(f) + */ + ((struct __pyx_vtabstruct_3_sa_DataArray *)__pyx_v_self->darray->__pyx_vtab)->read_handle(__pyx_v_self->darray, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":185 + * f = fopen(filename, "r") + * self.darray.read_handle(f) + * self.sa.read_handle(f) # <<<<<<<<<<<<<< + * self.ha.read_handle(f) + * fclose(f) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->sa->__pyx_vtab)->read_handle(__pyx_v_self->sa, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":186 + * self.darray.read_handle(f) + * self.sa.read_handle(f) + * self.ha.read_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->ha->__pyx_vtab)->read_handle(__pyx_v_self->ha, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":187 + * self.sa.read_handle(f) + * self.ha.read_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + * + * def write_binary(self, char* filename): + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_11SuffixArray_19write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_11SuffixArray_19write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_binary (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.SuffixArray.write_binary", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_11SuffixArray_18write_binary(((struct __pyx_obj_3_sa_SuffixArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":189 + * fclose(f) + * + * def write_binary(self, char* filename): # <<<<<<<<<<<<<< + * cdef FILE* f + * f = fopen(filename, "w") + */ + +static PyObject *__pyx_pf_3_sa_11SuffixArray_18write_binary(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename) { + FILE *__pyx_v_f; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_binary", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":191 + * def write_binary(self, char* filename): + * cdef FILE* f + * f = fopen(filename, "w") # <<<<<<<<<<<<<< + * self.darray.write_handle(f) + * self.sa.write_handle(f) + */ + __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":192 + * cdef FILE* f + * f = fopen(filename, "w") + * self.darray.write_handle(f) # <<<<<<<<<<<<<< + * self.sa.write_handle(f) + * self.ha.write_handle(f) + */ + ((struct __pyx_vtabstruct_3_sa_DataArray *)__pyx_v_self->darray->__pyx_vtab)->write_handle(__pyx_v_self->darray, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":193 + * f = fopen(filename, "w") + * self.darray.write_handle(f) + * self.sa.write_handle(f) # <<<<<<<<<<<<<< + * self.ha.write_handle(f) + * fclose(f) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->sa->__pyx_vtab)->write_handle(__pyx_v_self->sa, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":194 + * self.darray.write_handle(f) + * self.sa.write_handle(f) + * self.ha.write_handle(f) # <<<<<<<<<<<<<< + * fclose(f) + * + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->ha->__pyx_vtab)->write_handle(__pyx_v_self->ha, __pyx_v_f); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":195 + * self.sa.write_handle(f) + * self.ha.write_handle(f) + * fclose(f) # <<<<<<<<<<<<<< + * + * def write_enhanced(self, char* filename): + */ + fclose(__pyx_v_f); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_11SuffixArray_21write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_11SuffixArray_21write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { + char *__pyx_v_filename; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("write_enhanced (wrapper)", 0); + assert(__pyx_arg_filename); { + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.SuffixArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_11SuffixArray_20write_enhanced(((struct __pyx_obj_3_sa_SuffixArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":197 + * fclose(f) + * + * def write_enhanced(self, char* filename): # <<<<<<<<<<<<<< + * with open(filename, "w") as f: + * self.darray.write_enhanced_handle(f) + */ + +static PyObject *__pyx_pf_3_sa_11SuffixArray_20write_enhanced(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename) { + PyObject *__pyx_v_f = NULL; + PyObject *__pyx_v_a_i = NULL; + PyObject *__pyx_v_w_i = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + PyObject *__pyx_t_12 = NULL; + int __pyx_t_13; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("write_enhanced", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":198 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * self.darray.write_enhanced_handle(f) + * for a_i in self.sa: + */ + /*with:*/ { + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__w)); + PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_f = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":199 + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: + * self.darray.write_enhanced_handle(f) # <<<<<<<<<<<<<< + * for a_i in self.sa: + * f.write("%d " % a_i) + */ + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self->darray), __pyx_n_s_24); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_f); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_f); + __Pyx_GIVEREF(__pyx_v_f); + __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":200 + * with open(filename, "w") as f: + * self.darray.write_enhanced_handle(f) + * for a_i in self.sa: # <<<<<<<<<<<<<< + * f.write("%d " % a_i) + * f.write("\n") + */ + if (PyList_CheckExact(((PyObject *)__pyx_v_self->sa)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->sa))) { + __pyx_t_2 = ((PyObject *)__pyx_v_self->sa); __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(((PyObject *)__pyx_v_self->sa)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else { + __pyx_t_1 = __pyx_t_9(__pyx_t_2); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[13]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF(__pyx_v_a_i); + __pyx_v_a_i = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":201 + * self.darray.write_enhanced_handle(f) + * for a_i in self.sa: + * f.write("%d " % a_i) # <<<<<<<<<<<<<< + * f.write("\n") + * for w_i in self.ha: + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_a_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":202 + * for a_i in self.sa: + * f.write("%d " % a_i) + * f.write("\n") # <<<<<<<<<<<<<< + * for w_i in self.ha: + * f.write("%d " % w_i) + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_94), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":203 + * f.write("%d " % a_i) + * f.write("\n") + * for w_i in self.ha: # <<<<<<<<<<<<<< + * f.write("%d " % w_i) + * f.write("\n") + */ + if (PyList_CheckExact(((PyObject *)__pyx_v_self->ha)) || PyTuple_CheckExact(((PyObject *)__pyx_v_self->ha))) { + __pyx_t_4 = ((PyObject *)__pyx_v_self->ha); __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(((PyObject *)__pyx_v_self->ha)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + #endif + } else { + __pyx_t_2 = __pyx_t_9(__pyx_t_4); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[13]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF(__pyx_v_w_i); + __pyx_v_w_i = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":204 + * f.write("\n") + * for w_i in self.ha: + * f.write("%d " % w_i) # <<<<<<<<<<<<<< + * f.write("\n") + * + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_w_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_10)); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_10)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); + __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":205 + * for w_i in self.ha: + * f.write("%d " % w_i) + * f.write("\n") # <<<<<<<<<<<<<< + * + * cdef int __search_high(self, int word_id, int offset, int low, int high): + */ + __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_10 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_95), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":198 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * self.darray.write_enhanced_handle(f) + * for a_i in self.sa: + */ + /*except:*/ { + __Pyx_AddTraceback("_sa.SuffixArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_10, &__pyx_t_4, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_12 = PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_13 = (!__pyx_t_11); + if (__pyx_t_13) { + __Pyx_GIVEREF(__pyx_t_10); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_ErrRestore(__pyx_t_10, __pyx_t_4, __pyx_t_1); + __pyx_t_10 = 0; __pyx_t_4 = 0; __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[13]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L22; + } + __pyx_L22:; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_96, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L23; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L23:; + } + + __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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("_sa.SuffixArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_f); + __Pyx_XDECREF(__pyx_v_a_i); + __Pyx_XDECREF(__pyx_v_w_i); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":207 + * f.write("\n") + * + * cdef int __search_high(self, int word_id, int offset, int low, int high): # <<<<<<<<<<<<<< + * cdef int midpoint + * + */ + +static int __pyx_f_3_sa_11SuffixArray___search_high(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, int __pyx_v_word_id, int __pyx_v_offset, int __pyx_v_low, int __pyx_v_high) { + int __pyx_v_midpoint; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__search_high", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":210 + * cdef int midpoint + * + * if low >= high: # <<<<<<<<<<<<<< + * return high + * midpoint = (high + low) / 2 + */ + __pyx_t_1 = (__pyx_v_low >= __pyx_v_high); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":211 + * + * if low >= high: + * return high # <<<<<<<<<<<<<< + * midpoint = (high + low) / 2 + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + */ + __pyx_r = __pyx_v_high; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":212 + * if low >= high: + * return high + * midpoint = (high + low) / 2 # <<<<<<<<<<<<<< + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + * return self.__search_high(word_id, offset, midpoint+1, high) + */ + __pyx_v_midpoint = __Pyx_div_long((__pyx_v_high + __pyx_v_low), 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":213 + * return high + * midpoint = (high + low) / 2 + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: # <<<<<<<<<<<<<< + * return self.__search_high(word_id, offset, midpoint+1, high) + * else: + */ + __pyx_t_1 = ((__pyx_v_self->darray->data->arr[((__pyx_v_self->sa->arr[__pyx_v_midpoint]) + __pyx_v_offset)]) == __pyx_v_word_id); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":214 + * midpoint = (high + low) / 2 + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + * return self.__search_high(word_id, offset, midpoint+1, high) # <<<<<<<<<<<<<< + * else: + * return self.__search_high(word_id, offset, low, midpoint) + */ + __pyx_r = ((struct __pyx_vtabstruct_3_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___search_high(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, (__pyx_v_midpoint + 1), __pyx_v_high); + goto __pyx_L0; + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":216 + * return self.__search_high(word_id, offset, midpoint+1, high) + * else: + * return self.__search_high(word_id, offset, low, midpoint) # <<<<<<<<<<<<<< + * + * cdef int __search_low(self, int word_id, int offset, int low, int high): + */ + __pyx_r = ((struct __pyx_vtabstruct_3_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___search_high(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, __pyx_v_low, __pyx_v_midpoint); + goto __pyx_L0; + } + __pyx_L4:; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":218 + * return self.__search_high(word_id, offset, low, midpoint) + * + * cdef int __search_low(self, int word_id, int offset, int low, int high): # <<<<<<<<<<<<<< + * cdef int midpoint + * + */ + +static int __pyx_f_3_sa_11SuffixArray___search_low(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, int __pyx_v_word_id, int __pyx_v_offset, int __pyx_v_low, int __pyx_v_high) { + int __pyx_v_midpoint; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__search_low", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":221 + * cdef int midpoint + * + * if low >= high: # <<<<<<<<<<<<<< + * return high + * midpoint = (high + low) / 2 + */ + __pyx_t_1 = (__pyx_v_low >= __pyx_v_high); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":222 + * + * if low >= high: + * return high # <<<<<<<<<<<<<< + * midpoint = (high + low) / 2 + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + */ + __pyx_r = __pyx_v_high; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":223 + * if low >= high: + * return high + * midpoint = (high + low) / 2 # <<<<<<<<<<<<<< + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + * return self.__search_low(word_id, offset, low, midpoint) + */ + __pyx_v_midpoint = __Pyx_div_long((__pyx_v_high + __pyx_v_low), 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":224 + * return high + * midpoint = (high + low) / 2 + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: # <<<<<<<<<<<<<< + * return self.__search_low(word_id, offset, low, midpoint) + * else: + */ + __pyx_t_1 = ((__pyx_v_self->darray->data->arr[((__pyx_v_self->sa->arr[__pyx_v_midpoint]) + __pyx_v_offset)]) == __pyx_v_word_id); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":225 + * midpoint = (high + low) / 2 + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + * return self.__search_low(word_id, offset, low, midpoint) # <<<<<<<<<<<<<< + * else: + * return self.__search_low(word_id, offset, midpoint+1, high) + */ + __pyx_r = ((struct __pyx_vtabstruct_3_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___search_low(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, __pyx_v_low, __pyx_v_midpoint); + goto __pyx_L0; + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":227 + * return self.__search_low(word_id, offset, low, midpoint) + * else: + * return self.__search_low(word_id, offset, midpoint+1, high) # <<<<<<<<<<<<<< + * + * cdef __get_range(self, int word_id, int offset, int low, int high, int midpoint): + */ + __pyx_r = ((struct __pyx_vtabstruct_3_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___search_low(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, (__pyx_v_midpoint + 1), __pyx_v_high); + goto __pyx_L0; + } + __pyx_L4:; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":229 + * return self.__search_low(word_id, offset, midpoint+1, high) + * + * cdef __get_range(self, int word_id, int offset, int low, int high, int midpoint): # <<<<<<<<<<<<<< + * return (self.__search_low(word_id, offset, low, midpoint), + * self.__search_high(word_id, offset, midpoint, high)) + */ + +static PyObject *__pyx_f_3_sa_11SuffixArray___get_range(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, int __pyx_v_word_id, int __pyx_v_offset, int __pyx_v_low, int __pyx_v_high, int __pyx_v_midpoint) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get_range", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":230 + * + * cdef __get_range(self, int word_id, int offset, int low, int high, int midpoint): + * return (self.__search_low(word_id, offset, low, midpoint), # <<<<<<<<<<<<<< + * self.__search_high(word_id, offset, midpoint, high)) + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong(((struct __pyx_vtabstruct_3_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___search_low(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, __pyx_v_low, __pyx_v_midpoint)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":231 + * cdef __get_range(self, int word_id, int offset, int low, int high, int midpoint): + * return (self.__search_low(word_id, offset, low, midpoint), + * self.__search_high(word_id, offset, midpoint, high)) # <<<<<<<<<<<<<< + * + * cdef __lookup_helper(self, int word_id, int offset, int low, int high): + */ + __pyx_t_2 = PyInt_FromLong(((struct __pyx_vtabstruct_3_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___search_high(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, __pyx_v_midpoint, __pyx_v_high)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_r = ((PyObject *)__pyx_t_3); + __pyx_t_3 = 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_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.SuffixArray.__get_range", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":233 + * self.__search_high(word_id, offset, midpoint, high)) + * + * cdef __lookup_helper(self, int word_id, int offset, int low, int high): # <<<<<<<<<<<<<< + * cdef int midpoint + * + */ + +static PyObject *__pyx_f_3_sa_11SuffixArray___lookup_helper(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, int __pyx_v_word_id, int __pyx_v_offset, int __pyx_v_low, int __pyx_v_high) { + int __pyx_v_midpoint; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__lookup_helper", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":236 + * cdef int midpoint + * + * if offset == 0: # <<<<<<<<<<<<<< + * return (self.ha.arr[word_id], self.ha.arr[word_id+1]) + * if low >= high: + */ + __pyx_t_1 = (__pyx_v_offset == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":237 + * + * if offset == 0: + * return (self.ha.arr[word_id], self.ha.arr[word_id+1]) # <<<<<<<<<<<<<< + * if low >= high: + * return None + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->ha->arr[__pyx_v_word_id])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyInt_FromLong((__pyx_v_self->ha->arr[(__pyx_v_word_id + 1)])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_r = ((PyObject *)__pyx_t_4); + __pyx_t_4 = 0; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":238 + * if offset == 0: + * return (self.ha.arr[word_id], self.ha.arr[word_id+1]) + * if low >= high: # <<<<<<<<<<<<<< + * return None + * + */ + __pyx_t_1 = (__pyx_v_low >= __pyx_v_high); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":239 + * return (self.ha.arr[word_id], self.ha.arr[word_id+1]) + * if low >= high: + * return None # <<<<<<<<<<<<<< + * + * midpoint = (high + low) / 2 + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_None); + __pyx_r = Py_None; + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":241 + * return None + * + * midpoint = (high + low) / 2 # <<<<<<<<<<<<<< + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + * return self.__get_range(word_id, offset, low, high, midpoint) + */ + __pyx_v_midpoint = __Pyx_div_long((__pyx_v_high + __pyx_v_low), 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":242 + * + * midpoint = (high + low) / 2 + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: # <<<<<<<<<<<<<< + * return self.__get_range(word_id, offset, low, high, midpoint) + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] > word_id: + */ + __pyx_t_1 = ((__pyx_v_self->darray->data->arr[((__pyx_v_self->sa->arr[__pyx_v_midpoint]) + __pyx_v_offset)]) == __pyx_v_word_id); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":243 + * midpoint = (high + low) / 2 + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + * return self.__get_range(word_id, offset, low, high, midpoint) # <<<<<<<<<<<<<< + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] > word_id: + * return self.__lookup_helper(word_id, offset, low, midpoint) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = ((struct __pyx_vtabstruct_3_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___get_range(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, __pyx_v_low, __pyx_v_high, __pyx_v_midpoint); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":244 + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] == word_id: + * return self.__get_range(word_id, offset, low, high, midpoint) + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] > word_id: # <<<<<<<<<<<<<< + * return self.__lookup_helper(word_id, offset, low, midpoint) + * else: + */ + __pyx_t_1 = ((__pyx_v_self->darray->data->arr[((__pyx_v_self->sa->arr[__pyx_v_midpoint]) + __pyx_v_offset)]) > __pyx_v_word_id); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":245 + * return self.__get_range(word_id, offset, low, high, midpoint) + * if self.darray.data.arr[self.sa.arr[midpoint] + offset] > word_id: + * return self.__lookup_helper(word_id, offset, low, midpoint) # <<<<<<<<<<<<<< + * else: + * return self.__lookup_helper(word_id, offset, midpoint+1, high) + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = ((struct __pyx_vtabstruct_3_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___lookup_helper(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, __pyx_v_low, __pyx_v_midpoint); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":247 + * return self.__lookup_helper(word_id, offset, low, midpoint) + * else: + * return self.__lookup_helper(word_id, offset, midpoint+1, high) # <<<<<<<<<<<<<< + * + * def lookup(self, word, int offset, int low, int high): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = ((struct __pyx_vtabstruct_3_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___lookup_helper(__pyx_v_self, __pyx_v_word_id, __pyx_v_offset, (__pyx_v_midpoint + 1), __pyx_v_high); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + } + __pyx_L6:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_sa.SuffixArray.__lookup_helper", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_11SuffixArray_23lookup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_3_sa_11SuffixArray_23lookup(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_word = 0; + int __pyx_v_offset; + int __pyx_v_low; + int __pyx_v_high; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("lookup (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__word,&__pyx_n_s__offset,&__pyx_n_s__low,&__pyx_n_s__high,0}; + PyObject* values[4] = {0,0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__word)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__offset)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("lookup", 1, 4, 4, 1); {__pyx_filename = __pyx_f[13]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__low)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("lookup", 1, 4, 4, 2); {__pyx_filename = __pyx_f[13]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 3: + if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__high)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("lookup", 1, 4, 4, 3); {__pyx_filename = __pyx_f[13]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "lookup") < 0)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + } + __pyx_v_word = values[0]; + __pyx_v_offset = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_offset == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_low = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_low == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_high = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_high == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("lookup", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[13]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.SuffixArray.lookup", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_11SuffixArray_22lookup(((struct __pyx_obj_3_sa_SuffixArray *)__pyx_v_self), __pyx_v_word, __pyx_v_offset, __pyx_v_low, __pyx_v_high); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":249 + * return self.__lookup_helper(word_id, offset, midpoint+1, high) + * + * def lookup(self, word, int offset, int low, int high): # <<<<<<<<<<<<<< + * cdef int wordid + * if low == -1: + */ + +static PyObject *__pyx_pf_3_sa_11SuffixArray_22lookup(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_word, int __pyx_v_offset, int __pyx_v_low, int __pyx_v_high) { + PyObject *__pyx_v_word_id = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("lookup", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":251 + * def lookup(self, word, int offset, int low, int high): + * cdef int wordid + * if low == -1: # <<<<<<<<<<<<<< + * low = 0 + * if high == -1: + */ + __pyx_t_1 = (__pyx_v_low == -1); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":252 + * cdef int wordid + * if low == -1: + * low = 0 # <<<<<<<<<<<<<< + * if high == -1: + * high = len(self.sa) + */ + __pyx_v_low = 0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":253 + * if low == -1: + * low = 0 + * if high == -1: # <<<<<<<<<<<<<< + * high = len(self.sa) + * if word in self.darray.word2id: + */ + __pyx_t_1 = (__pyx_v_high == -1); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":254 + * low = 0 + * if high == -1: + * high = len(self.sa) # <<<<<<<<<<<<<< + * if word in self.darray.word2id: + * word_id = self.darray.word2id[word] + */ + __pyx_t_2 = ((PyObject *)__pyx_v_self->sa); + __Pyx_INCREF(__pyx_t_2); + __pyx_t_3 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 254; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_high = __pyx_t_3; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":255 + * if high == -1: + * high = len(self.sa) + * if word in self.darray.word2id: # <<<<<<<<<<<<<< + * word_id = self.darray.word2id[word] + * return self.__lookup_helper(word_id, offset, low, high) + */ + __pyx_t_1 = ((PySequence_Contains(__pyx_v_self->darray->word2id, __pyx_v_word))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":256 + * high = len(self.sa) + * if word in self.darray.word2id: + * word_id = self.darray.word2id[word] # <<<<<<<<<<<<<< + * return self.__lookup_helper(word_id, offset, low, high) + * else: + */ + __pyx_t_2 = PyObject_GetItem(__pyx_v_self->darray->word2id, __pyx_v_word); if (!__pyx_t_2) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_word_id = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":257 + * if word in self.darray.word2id: + * word_id = self.darray.word2id[word] + * return self.__lookup_helper(word_id, offset, low, high) # <<<<<<<<<<<<<< + * else: + * return None + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_word_id); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_SuffixArray *)__pyx_v_self->__pyx_vtab)->__pyx___lookup_helper(__pyx_v_self, __pyx_t_4, __pyx_v_offset, __pyx_v_low, __pyx_v_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":259 + * return self.__lookup_helper(word_id, offset, low, high) + * else: + * return None # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_None); + __pyx_r = Py_None; + goto __pyx_L0; + } + __pyx_L5:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_sa.SuffixArray.lookup", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_word_id); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_8TrieNode_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_8TrieNode_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; + __pyx_r = __pyx_pf_3_sa_8TrieNode___cinit__(((struct __pyx_obj_3_sa_TrieNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":21 + * cdef public children + * + * def __cinit__(self): # <<<<<<<<<<<<<< + * self.children = {} + * + */ + +static int __pyx_pf_3_sa_8TrieNode___cinit__(struct __pyx_obj_3_sa_TrieNode *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":22 + * + * def __cinit__(self): + * self.children = {} # <<<<<<<<<<<<<< + * + * cdef class ExtendedTrieNode(TrieNode): + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_GOTREF(__pyx_v_self->children); + __Pyx_DECREF(__pyx_v_self->children); + __pyx_v_self->children = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_sa.TrieNode.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_8TrieNode_8children_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_8TrieNode_8children_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_8TrieNode_8children___get__(((struct __pyx_obj_3_sa_TrieNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":19 + * + * cdef class TrieNode: + * cdef public children # <<<<<<<<<<<<<< + * + * def __cinit__(self): + */ + +static PyObject *__pyx_pf_3_sa_8TrieNode_8children___get__(struct __pyx_obj_3_sa_TrieNode *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->children); + __pyx_r = __pyx_v_self->children; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_8TrieNode_8children_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_3_sa_8TrieNode_8children_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_8TrieNode_8children_2__set__(((struct __pyx_obj_3_sa_TrieNode *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_8TrieNode_8children_2__set__(struct __pyx_obj_3_sa_TrieNode *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->children); + __Pyx_DECREF(__pyx_v_self->children); + __pyx_v_self->children = __pyx_v_value; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_8TrieNode_8children_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_3_sa_8TrieNode_8children_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_8TrieNode_8children_4__del__(((struct __pyx_obj_3_sa_TrieNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_8TrieNode_8children_4__del__(struct __pyx_obj_3_sa_TrieNode *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->children); + __Pyx_DECREF(__pyx_v_self->children); + __pyx_v_self->children = Py_None; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_16ExtendedTrieNode_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_16ExtendedTrieNode_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_phrase = 0; + PyObject *__pyx_v_phrase_location = 0; + PyObject *__pyx_v_suffix_link = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__phrase,&__pyx_n_s__phrase_location,&__pyx_n_s__suffix_link,0}; + PyObject* values[3] = {0,0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":29 + * cdef public suffix_link + * + * def __cinit__(self, phrase=None, phrase_location=None, suffix_link=None): # <<<<<<<<<<<<<< + * self.phrase = phrase + * self.phrase_location = phrase_location + */ + values[0] = ((PyObject *)Py_None); + values[1] = ((PyObject *)Py_None); + values[2] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__phrase); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__phrase_location); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__suffix_link); + if (value) { values[2] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_phrase = values[0]; + __pyx_v_phrase_location = values[1]; + __pyx_v_suffix_link = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.ExtendedTrieNode.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_16ExtendedTrieNode___cinit__(((struct __pyx_obj_3_sa_ExtendedTrieNode *)__pyx_v_self), __pyx_v_phrase, __pyx_v_phrase_location, __pyx_v_suffix_link); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_16ExtendedTrieNode___cinit__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_phrase, PyObject *__pyx_v_phrase_location, PyObject *__pyx_v_suffix_link) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":30 + * + * def __cinit__(self, phrase=None, phrase_location=None, suffix_link=None): + * self.phrase = phrase # <<<<<<<<<<<<<< + * self.phrase_location = phrase_location + * self.suffix_link = suffix_link + */ + __Pyx_INCREF(__pyx_v_phrase); + __Pyx_GIVEREF(__pyx_v_phrase); + __Pyx_GOTREF(__pyx_v_self->phrase); + __Pyx_DECREF(__pyx_v_self->phrase); + __pyx_v_self->phrase = __pyx_v_phrase; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":31 + * def __cinit__(self, phrase=None, phrase_location=None, suffix_link=None): + * self.phrase = phrase + * self.phrase_location = phrase_location # <<<<<<<<<<<<<< + * self.suffix_link = suffix_link + * + */ + __Pyx_INCREF(__pyx_v_phrase_location); + __Pyx_GIVEREF(__pyx_v_phrase_location); + __Pyx_GOTREF(__pyx_v_self->phrase_location); + __Pyx_DECREF(__pyx_v_self->phrase_location); + __pyx_v_self->phrase_location = __pyx_v_phrase_location; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":32 + * self.phrase = phrase + * self.phrase_location = phrase_location + * self.suffix_link = suffix_link # <<<<<<<<<<<<<< + * + * + */ + __Pyx_INCREF(__pyx_v_suffix_link); + __Pyx_GIVEREF(__pyx_v_suffix_link); + __Pyx_GOTREF(__pyx_v_self->suffix_link); + __Pyx_DECREF(__pyx_v_self->suffix_link); + __pyx_v_self->suffix_link = __pyx_v_suffix_link; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_16ExtendedTrieNode_6phrase_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_16ExtendedTrieNode_6phrase_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_16ExtendedTrieNode_6phrase___get__(((struct __pyx_obj_3_sa_ExtendedTrieNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":25 + * + * cdef class ExtendedTrieNode(TrieNode): + * cdef public phrase # <<<<<<<<<<<<<< + * cdef public phrase_location + * cdef public suffix_link + */ + +static PyObject *__pyx_pf_3_sa_16ExtendedTrieNode_6phrase___get__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->phrase); + __pyx_r = __pyx_v_self->phrase; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_16ExtendedTrieNode_6phrase_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_3_sa_16ExtendedTrieNode_6phrase_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_16ExtendedTrieNode_6phrase_2__set__(((struct __pyx_obj_3_sa_ExtendedTrieNode *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_16ExtendedTrieNode_6phrase_2__set__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->phrase); + __Pyx_DECREF(__pyx_v_self->phrase); + __pyx_v_self->phrase = __pyx_v_value; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_16ExtendedTrieNode_6phrase_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_3_sa_16ExtendedTrieNode_6phrase_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_16ExtendedTrieNode_6phrase_4__del__(((struct __pyx_obj_3_sa_ExtendedTrieNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_16ExtendedTrieNode_6phrase_4__del__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->phrase); + __Pyx_DECREF(__pyx_v_self->phrase); + __pyx_v_self->phrase = Py_None; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_16ExtendedTrieNode_15phrase_location_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_16ExtendedTrieNode_15phrase_location_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_16ExtendedTrieNode_15phrase_location___get__(((struct __pyx_obj_3_sa_ExtendedTrieNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":26 + * cdef class ExtendedTrieNode(TrieNode): + * cdef public phrase + * cdef public phrase_location # <<<<<<<<<<<<<< + * cdef public suffix_link + * + */ + +static PyObject *__pyx_pf_3_sa_16ExtendedTrieNode_15phrase_location___get__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->phrase_location); + __pyx_r = __pyx_v_self->phrase_location; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_16ExtendedTrieNode_15phrase_location_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_3_sa_16ExtendedTrieNode_15phrase_location_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_16ExtendedTrieNode_15phrase_location_2__set__(((struct __pyx_obj_3_sa_ExtendedTrieNode *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_16ExtendedTrieNode_15phrase_location_2__set__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->phrase_location); + __Pyx_DECREF(__pyx_v_self->phrase_location); + __pyx_v_self->phrase_location = __pyx_v_value; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_16ExtendedTrieNode_15phrase_location_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_3_sa_16ExtendedTrieNode_15phrase_location_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_16ExtendedTrieNode_15phrase_location_4__del__(((struct __pyx_obj_3_sa_ExtendedTrieNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_16ExtendedTrieNode_15phrase_location_4__del__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->phrase_location); + __Pyx_DECREF(__pyx_v_self->phrase_location); + __pyx_v_self->phrase_location = Py_None; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_16ExtendedTrieNode_11suffix_link_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_16ExtendedTrieNode_11suffix_link_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_16ExtendedTrieNode_11suffix_link___get__(((struct __pyx_obj_3_sa_ExtendedTrieNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":27 + * cdef public phrase + * cdef public phrase_location + * cdef public suffix_link # <<<<<<<<<<<<<< + * + * def __cinit__(self, phrase=None, phrase_location=None, suffix_link=None): + */ + +static PyObject *__pyx_pf_3_sa_16ExtendedTrieNode_11suffix_link___get__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->suffix_link); + __pyx_r = __pyx_v_self->suffix_link; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_16ExtendedTrieNode_11suffix_link_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_3_sa_16ExtendedTrieNode_11suffix_link_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_16ExtendedTrieNode_11suffix_link_2__set__(((struct __pyx_obj_3_sa_ExtendedTrieNode *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_16ExtendedTrieNode_11suffix_link_2__set__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->suffix_link); + __Pyx_DECREF(__pyx_v_self->suffix_link); + __pyx_v_self->suffix_link = __pyx_v_value; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_16ExtendedTrieNode_11suffix_link_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_3_sa_16ExtendedTrieNode_11suffix_link_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_16ExtendedTrieNode_11suffix_link_4__del__(((struct __pyx_obj_3_sa_ExtendedTrieNode *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_16ExtendedTrieNode_11suffix_link_4__del__(struct __pyx_obj_3_sa_ExtendedTrieNode *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->suffix_link); + __Pyx_DECREF(__pyx_v_self->suffix_link); + __pyx_v_self->suffix_link = Py_None; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_9TrieTable_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_9TrieTable_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_extended = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__extended,0}; + PyObject* values[1] = {0}; + values[0] = __pyx_k_97; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__extended); + if (value) { values[0] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + 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; + } + } + __pyx_v_extended = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.TrieTable.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9TrieTable___cinit__(((struct __pyx_obj_3_sa_TrieTable *)__pyx_v_self), __pyx_v_extended); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":39 + * cdef public int count + * cdef public root + * def __cinit__(self, extended=False): # <<<<<<<<<<<<<< + * self.count = 0 + * self.extended = extended + */ + +static int __pyx_pf_3_sa_9TrieTable___cinit__(struct __pyx_obj_3_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_extended) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":40 + * cdef public root + * def __cinit__(self, extended=False): + * self.count = 0 # <<<<<<<<<<<<<< + * self.extended = extended + * if extended: + */ + __pyx_v_self->count = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":41 + * def __cinit__(self, extended=False): + * self.count = 0 + * self.extended = extended # <<<<<<<<<<<<<< + * if extended: + * self.root = ExtendedTrieNode() + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_extended); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->extended = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":42 + * self.count = 0 + * self.extended = extended + * if extended: # <<<<<<<<<<<<<< + * self.root = ExtendedTrieNode() + * else: + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_extended); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":43 + * self.extended = extended + * if extended: + * self.root = ExtendedTrieNode() # <<<<<<<<<<<<<< + * else: + * self.root = TrieNode() + */ + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->root); + __Pyx_DECREF(__pyx_v_self->root); + __pyx_v_self->root = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":45 + * self.root = ExtendedTrieNode() + * else: + * self.root = TrieNode() # <<<<<<<<<<<<<< + * + * # linked list structure for storing matches in BaselineRuleFactory + */ + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_TrieNode)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_self->root); + __Pyx_DECREF(__pyx_v_self->root); + __pyx_v_self->root = __pyx_t_3; + __pyx_t_3 = 0; + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.TrieTable.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9TrieTable_8extended_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_9TrieTable_8extended_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9TrieTable_8extended___get__(((struct __pyx_obj_3_sa_TrieTable *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":36 + * + * cdef class TrieTable: + * cdef public int extended # <<<<<<<<<<<<<< + * cdef public int count + * cdef public root + */ + +static PyObject *__pyx_pf_3_sa_9TrieTable_8extended___get__(struct __pyx_obj_3_sa_TrieTable *__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("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->extended); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_sa.TrieTable.extended.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_9TrieTable_8extended_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_3_sa_9TrieTable_8extended_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9TrieTable_8extended_2__set__(((struct __pyx_obj_3_sa_TrieTable *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_9TrieTable_8extended_2__set__(struct __pyx_obj_3_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->extended = __pyx_t_1; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_sa.TrieTable.extended.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9TrieTable_5count_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_9TrieTable_5count_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9TrieTable_5count___get__(((struct __pyx_obj_3_sa_TrieTable *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":37 + * cdef class TrieTable: + * cdef public int extended + * cdef public int count # <<<<<<<<<<<<<< + * cdef public root + * def __cinit__(self, extended=False): + */ + +static PyObject *__pyx_pf_3_sa_9TrieTable_5count___get__(struct __pyx_obj_3_sa_TrieTable *__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("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyInt_FromLong(__pyx_v_self->count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_AddTraceback("_sa.TrieTable.count.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_9TrieTable_5count_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_3_sa_9TrieTable_5count_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9TrieTable_5count_2__set__(((struct __pyx_obj_3_sa_TrieTable *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_9TrieTable_5count_2__set__(struct __pyx_obj_3_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->count = __pyx_t_1; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_sa.TrieTable.count.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9TrieTable_4root_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_3_sa_9TrieTable_4root_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9TrieTable_4root___get__(((struct __pyx_obj_3_sa_TrieTable *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":38 + * cdef public int extended + * cdef public int count + * cdef public root # <<<<<<<<<<<<<< + * def __cinit__(self, extended=False): + * self.count = 0 + */ + +static PyObject *__pyx_pf_3_sa_9TrieTable_4root___get__(struct __pyx_obj_3_sa_TrieTable *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->root); + __pyx_r = __pyx_v_self->root; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_9TrieTable_4root_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_3_sa_9TrieTable_4root_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9TrieTable_4root_2__set__(((struct __pyx_obj_3_sa_TrieTable *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_9TrieTable_4root_2__set__(struct __pyx_obj_3_sa_TrieTable *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__", 0); + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->root); + __Pyx_DECREF(__pyx_v_self->root); + __pyx_v_self->root = __pyx_v_value; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_9TrieTable_4root_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_3_sa_9TrieTable_4root_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9TrieTable_4root_4__del__(((struct __pyx_obj_3_sa_TrieTable *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_3_sa_9TrieTable_4root_4__del__(struct __pyx_obj_3_sa_TrieTable *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->root); + __Pyx_DECREF(__pyx_v_self->root); + __pyx_v_self->root = Py_None; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":65 + * + * # returns true if sent_id is contained + * cdef int contains(self, int sent_id): # <<<<<<<<<<<<<< + * return 1 + * + */ + +static int __pyx_f_3_sa_14PhraseLocation_contains(CYTHON_UNUSED struct __pyx_obj_3_sa_PhraseLocation *__pyx_v_self, CYTHON_UNUSED int __pyx_v_sent_id) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("contains", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":66 + * # returns true if sent_id is contained + * cdef int contains(self, int sent_id): + * return 1 # <<<<<<<<<<<<<< + * + * def __cinit__(self, int sa_low=-1, int sa_high=-1, int arr_low=-1, int arr_high=-1, + */ + __pyx_r = 1; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_14PhraseLocation_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_14PhraseLocation_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_sa_low; + int __pyx_v_sa_high; + int __pyx_v_arr_low; + int __pyx_v_arr_high; + PyObject *__pyx_v_arr = 0; + int __pyx_v_num_subpatterns; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sa_low,&__pyx_n_s__sa_high,&__pyx_n_s__arr_low,&__pyx_n_s__arr_high,&__pyx_n_s__arr,&__pyx_n_s__num_subpatterns,0}; + PyObject* values[6] = {0,0,0,0,0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":69 + * + * def __cinit__(self, int sa_low=-1, int sa_high=-1, int arr_low=-1, int arr_high=-1, + * arr=None, int num_subpatterns=1): # <<<<<<<<<<<<<< + * self.sa_low = sa_low + * self.sa_high = sa_high + */ + values[4] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sa_low); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sa_high); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__arr_low); + if (value) { values[2] = value; kw_args--; } + } + case 3: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__arr_high); + if (value) { values[3] = value; kw_args--; } + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__arr); + if (value) { values[4] = value; kw_args--; } + } + case 5: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__num_subpatterns); + if (value) { values[5] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + if (values[0]) { + __pyx_v_sa_low = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_sa_low == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_sa_low = ((int)-1); + } + if (values[1]) { + __pyx_v_sa_high = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_sa_high == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_sa_high = ((int)-1); + } + if (values[2]) { + __pyx_v_arr_low = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_arr_low == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_arr_low = ((int)-1); + } + if (values[3]) { + __pyx_v_arr_high = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_arr_high == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_arr_high = ((int)-1); + } + __pyx_v_arr = values[4]; + if (values[5]) { + __pyx_v_num_subpatterns = __Pyx_PyInt_AsInt(values[5]); if (unlikely((__pyx_v_num_subpatterns == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_num_subpatterns = ((int)1); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.PhraseLocation.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_14PhraseLocation___cinit__(((struct __pyx_obj_3_sa_PhraseLocation *)__pyx_v_self), __pyx_v_sa_low, __pyx_v_sa_high, __pyx_v_arr_low, __pyx_v_arr_high, __pyx_v_arr, __pyx_v_num_subpatterns); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":68 + * return 1 + * + * def __cinit__(self, int sa_low=-1, int sa_high=-1, int arr_low=-1, int arr_high=-1, # <<<<<<<<<<<<<< + * arr=None, int num_subpatterns=1): + * self.sa_low = sa_low + */ + +static int __pyx_pf_3_sa_14PhraseLocation___cinit__(struct __pyx_obj_3_sa_PhraseLocation *__pyx_v_self, int __pyx_v_sa_low, int __pyx_v_sa_high, int __pyx_v_arr_low, int __pyx_v_arr_high, PyObject *__pyx_v_arr, int __pyx_v_num_subpatterns) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":70 + * def __cinit__(self, int sa_low=-1, int sa_high=-1, int arr_low=-1, int arr_high=-1, + * arr=None, int num_subpatterns=1): + * self.sa_low = sa_low # <<<<<<<<<<<<<< + * self.sa_high = sa_high + * self.arr_low = arr_low + */ + __pyx_v_self->sa_low = __pyx_v_sa_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":71 + * arr=None, int num_subpatterns=1): + * self.sa_low = sa_low + * self.sa_high = sa_high # <<<<<<<<<<<<<< + * self.arr_low = arr_low + * self.arr_high = arr_high + */ + __pyx_v_self->sa_high = __pyx_v_sa_high; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":72 + * self.sa_low = sa_low + * self.sa_high = sa_high + * self.arr_low = arr_low # <<<<<<<<<<<<<< + * self.arr_high = arr_high + * self.arr = arr + */ + __pyx_v_self->arr_low = __pyx_v_arr_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":73 + * self.sa_high = sa_high + * self.arr_low = arr_low + * self.arr_high = arr_high # <<<<<<<<<<<<<< + * self.arr = arr + * self.num_subpatterns = num_subpatterns + */ + __pyx_v_self->arr_high = __pyx_v_arr_high; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":74 + * self.arr_low = arr_low + * self.arr_high = arr_high + * self.arr = arr # <<<<<<<<<<<<<< + * self.num_subpatterns = num_subpatterns + * + */ + if (!(likely(((__pyx_v_arr) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_arr, __pyx_ptype_3_sa_IntList))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_arr); + __Pyx_GIVEREF(__pyx_v_arr); + __Pyx_GOTREF(__pyx_v_self->arr); + __Pyx_DECREF(((PyObject *)__pyx_v_self->arr)); + __pyx_v_self->arr = ((struct __pyx_obj_3_sa_IntList *)__pyx_v_arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":75 + * self.arr_high = arr_high + * self.arr = arr + * self.num_subpatterns = num_subpatterns # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_self->num_subpatterns = __pyx_v_num_subpatterns; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_sa.PhraseLocation.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_7Sampler_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_7Sampler_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_sample_size; + struct __pyx_obj_3_sa_SuffixArray *__pyx_v_fsarray = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sample_size,&__pyx_n_s__fsarray,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sample_size)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fsarray)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 2, 2, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_sample_size = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_sample_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_fsarray = ((struct __pyx_obj_3_sa_SuffixArray *)values[1]); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.Sampler.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fsarray), __pyx_ptype_3_sa_SuffixArray, 1, "fsarray", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_3_sa_7Sampler___cinit__(((struct __pyx_obj_3_sa_Sampler *)__pyx_v_self), __pyx_v_sample_size, __pyx_v_fsarray); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":86 + * cdef IntList sa + * + * def __cinit__(self, int sample_size, SuffixArray fsarray): # <<<<<<<<<<<<<< + * self.sample_size = sample_size + * self.sa = fsarray.sa + */ + +static int __pyx_pf_3_sa_7Sampler___cinit__(struct __pyx_obj_3_sa_Sampler *__pyx_v_self, int __pyx_v_sample_size, struct __pyx_obj_3_sa_SuffixArray *__pyx_v_fsarray) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":87 + * + * def __cinit__(self, int sample_size, SuffixArray fsarray): + * self.sample_size = sample_size # <<<<<<<<<<<<<< + * self.sa = fsarray.sa + * if sample_size > 0: + */ + __pyx_v_self->sample_size = __pyx_v_sample_size; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":88 + * def __cinit__(self, int sample_size, SuffixArray fsarray): + * self.sample_size = sample_size + * self.sa = fsarray.sa # <<<<<<<<<<<<<< + * if sample_size > 0: + * logger.info("Sampling strategy: uniform, max sample size = %d", sample_size) + */ + __Pyx_INCREF(((PyObject *)__pyx_v_fsarray->sa)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fsarray->sa)); + __Pyx_GOTREF(__pyx_v_self->sa); + __Pyx_DECREF(((PyObject *)__pyx_v_self->sa)); + __pyx_v_self->sa = __pyx_v_fsarray->sa; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":89 + * self.sample_size = sample_size + * self.sa = fsarray.sa + * if sample_size > 0: # <<<<<<<<<<<<<< + * logger.info("Sampling strategy: uniform, max sample size = %d", sample_size) + * else: + */ + __pyx_t_1 = (__pyx_v_sample_size > 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":90 + * self.sa = fsarray.sa + * if sample_size > 0: + * logger.info("Sampling strategy: uniform, max sample size = %d", sample_size) # <<<<<<<<<<<<<< + * else: + * logger.info("Sampling strategy: no sampling") + */ + __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__info); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyInt_FromLong(__pyx_v_sample_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_98)); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_s_98)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_98)); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":92 + * logger.info("Sampling strategy: uniform, max sample size = %d", sample_size) + * else: + * logger.info("Sampling strategy: no sampling") # <<<<<<<<<<<<<< + * + * def sample(self, PhraseLocation phrase_location): + */ + __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__info); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_100), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __pyx_L3:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_sa.Sampler.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_7Sampler_3sample(PyObject *__pyx_v_self, PyObject *__pyx_v_phrase_location); /*proto*/ +static char __pyx_doc_3_sa_7Sampler_2sample[] = "Returns a sample of the locations for\n the phrase. If there are less than self.sample_size\n locations, return all of them; otherwise, return\n up to self.sample_size locations. In the latter case,\n we choose to sample UNIFORMLY -- that is, the locations\n are chosen at uniform intervals over the entire set, rather\n than randomly. This makes the algorithm deterministic, which\n is good for things like MERT"; +static PyObject *__pyx_pw_3_sa_7Sampler_3sample(PyObject *__pyx_v_self, PyObject *__pyx_v_phrase_location) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("sample (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_phrase_location), __pyx_ptype_3_sa_PhraseLocation, 1, "phrase_location", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_3_sa_7Sampler_2sample(((struct __pyx_obj_3_sa_Sampler *)__pyx_v_self), ((struct __pyx_obj_3_sa_PhraseLocation *)__pyx_v_phrase_location)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":94 + * logger.info("Sampling strategy: no sampling") + * + * def sample(self, PhraseLocation phrase_location): # <<<<<<<<<<<<<< + * '''Returns a sample of the locations for + * the phrase. If there are less than self.sample_size + */ + +static PyObject *__pyx_pf_3_sa_7Sampler_2sample(struct __pyx_obj_3_sa_Sampler *__pyx_v_self, struct __pyx_obj_3_sa_PhraseLocation *__pyx_v_phrase_location) { + struct __pyx_obj_3_sa_IntList *__pyx_v_sample = 0; + double __pyx_v_i; + double __pyx_v_stepsize; + int __pyx_v_num_locations; + int __pyx_v_val; + int __pyx_v_j; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("sample", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":107 + * cdef int num_locations, val, j + * + * sample = IntList() # <<<<<<<<<<<<<< + * if phrase_location.arr is None: + * num_locations = phrase_location.sa_high - phrase_location.sa_low + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sample = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":108 + * + * sample = IntList() + * if phrase_location.arr is None: # <<<<<<<<<<<<<< + * num_locations = phrase_location.sa_high - phrase_location.sa_low + * if self.sample_size == -1 or num_locations <= self.sample_size: + */ + __pyx_t_2 = (((PyObject *)__pyx_v_phrase_location->arr) == Py_None); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":109 + * sample = IntList() + * if phrase_location.arr is None: + * num_locations = phrase_location.sa_high - phrase_location.sa_low # <<<<<<<<<<<<<< + * if self.sample_size == -1 or num_locations <= self.sample_size: + * sample._extend_arr(self.sa.arr + phrase_location.sa_low, num_locations) + */ + __pyx_v_num_locations = (__pyx_v_phrase_location->sa_high - __pyx_v_phrase_location->sa_low); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":110 + * if phrase_location.arr is None: + * num_locations = phrase_location.sa_high - phrase_location.sa_low + * if self.sample_size == -1 or num_locations <= self.sample_size: # <<<<<<<<<<<<<< + * sample._extend_arr(self.sa.arr + phrase_location.sa_low, num_locations) + * else: + */ + __pyx_t_2 = (__pyx_v_self->sample_size == -1); + if (!__pyx_t_2) { + __pyx_t_3 = (__pyx_v_num_locations <= __pyx_v_self->sample_size); + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_2; + } + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":111 + * num_locations = phrase_location.sa_high - phrase_location.sa_low + * if self.sample_size == -1 or num_locations <= self.sample_size: + * sample._extend_arr(self.sa.arr + phrase_location.sa_low, num_locations) # <<<<<<<<<<<<<< + * else: + * stepsize = float(num_locations)/float(self.sample_size) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_sample->__pyx_vtab)->_extend_arr(__pyx_v_sample, (__pyx_v_self->sa->arr + __pyx_v_phrase_location->sa_low), __pyx_v_num_locations); + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":113 + * sample._extend_arr(self.sa.arr + phrase_location.sa_low, num_locations) + * else: + * stepsize = float(num_locations)/float(self.sample_size) # <<<<<<<<<<<<<< + * i = phrase_location.sa_low + * while i < phrase_location.sa_high and sample.len < self.sample_size: + */ + if (unlikely(((double)__pyx_v_self->sample_size) == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_stepsize = (((double)__pyx_v_num_locations) / ((double)__pyx_v_self->sample_size)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":114 + * else: + * stepsize = float(num_locations)/float(self.sample_size) + * i = phrase_location.sa_low # <<<<<<<<<<<<<< + * while i < phrase_location.sa_high and sample.len < self.sample_size: + * '''Note: int(i) not guaranteed to have the desired + */ + __pyx_v_i = __pyx_v_phrase_location->sa_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":115 + * stepsize = float(num_locations)/float(self.sample_size) + * i = phrase_location.sa_low + * while i < phrase_location.sa_high and sample.len < self.sample_size: # <<<<<<<<<<<<<< + * '''Note: int(i) not guaranteed to have the desired + * effect, according to the python documentation''' + */ + while (1) { + __pyx_t_4 = (__pyx_v_i < __pyx_v_phrase_location->sa_high); + if (__pyx_t_4) { + __pyx_t_2 = (__pyx_v_sample->len < __pyx_v_self->sample_size); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_4; + } + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":118 + * '''Note: int(i) not guaranteed to have the desired + * effect, according to the python documentation''' + * if fmod(i,1.0) > 0.5: # <<<<<<<<<<<<<< + * val = int(ceil(i)) + * else: + */ + __pyx_t_3 = (fmod(__pyx_v_i, 1.0) > 0.5); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":119 + * effect, according to the python documentation''' + * if fmod(i,1.0) > 0.5: + * val = int(ceil(i)) # <<<<<<<<<<<<<< + * else: + * val = int(floor(i)) + */ + __pyx_v_val = ((int)ceil(__pyx_v_i)); + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":121 + * val = int(ceil(i)) + * else: + * val = int(floor(i)) # <<<<<<<<<<<<<< + * sample._append(self.sa.arr[val]) + * i = i + stepsize + */ + __pyx_v_val = ((int)floor(__pyx_v_i)); + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":122 + * else: + * val = int(floor(i)) + * sample._append(self.sa.arr[val]) # <<<<<<<<<<<<<< + * i = i + stepsize + * else: + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_sample->__pyx_vtab)->_append(__pyx_v_sample, (__pyx_v_self->sa->arr[__pyx_v_val])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":123 + * val = int(floor(i)) + * sample._append(self.sa.arr[val]) + * i = i + stepsize # <<<<<<<<<<<<<< + * else: + * num_locations = (phrase_location.arr_high - phrase_location.arr_low) / phrase_location.num_subpatterns + */ + __pyx_v_i = (__pyx_v_i + __pyx_v_stepsize); + } + } + __pyx_L4:; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":125 + * i = i + stepsize + * else: + * num_locations = (phrase_location.arr_high - phrase_location.arr_low) / phrase_location.num_subpatterns # <<<<<<<<<<<<<< + * if self.sample_size == -1 or num_locations <= self.sample_size: + * sample = phrase_location.arr + */ + __pyx_t_5 = (__pyx_v_phrase_location->arr_high - __pyx_v_phrase_location->arr_low); + if (unlikely(__pyx_v_phrase_location->num_subpatterns == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_phrase_location->num_subpatterns == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_5))) { + PyErr_Format(PyExc_OverflowError, "value too large to perform division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_num_locations = __Pyx_div_int(__pyx_t_5, __pyx_v_phrase_location->num_subpatterns); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":126 + * else: + * num_locations = (phrase_location.arr_high - phrase_location.arr_low) / phrase_location.num_subpatterns + * if self.sample_size == -1 or num_locations <= self.sample_size: # <<<<<<<<<<<<<< + * sample = phrase_location.arr + * else: + */ + __pyx_t_3 = (__pyx_v_self->sample_size == -1); + if (!__pyx_t_3) { + __pyx_t_4 = (__pyx_v_num_locations <= __pyx_v_self->sample_size); + __pyx_t_2 = __pyx_t_4; + } else { + __pyx_t_2 = __pyx_t_3; + } + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":127 + * num_locations = (phrase_location.arr_high - phrase_location.arr_low) / phrase_location.num_subpatterns + * if self.sample_size == -1 or num_locations <= self.sample_size: + * sample = phrase_location.arr # <<<<<<<<<<<<<< + * else: + * stepsize = float(num_locations)/float(self.sample_size) + */ + __Pyx_INCREF(((PyObject *)__pyx_v_phrase_location->arr)); + __Pyx_DECREF(((PyObject *)__pyx_v_sample)); + __pyx_v_sample = __pyx_v_phrase_location->arr; + goto __pyx_L8; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":129 + * sample = phrase_location.arr + * else: + * stepsize = float(num_locations)/float(self.sample_size) # <<<<<<<<<<<<<< + * i = phrase_location.arr_low + * while i < num_locations and sample.len < self.sample_size * phrase_location.num_subpatterns: + */ + if (unlikely(((double)__pyx_v_self->sample_size) == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_stepsize = (((double)__pyx_v_num_locations) / ((double)__pyx_v_self->sample_size)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":130 + * else: + * stepsize = float(num_locations)/float(self.sample_size) + * i = phrase_location.arr_low # <<<<<<<<<<<<<< + * while i < num_locations and sample.len < self.sample_size * phrase_location.num_subpatterns: + * '''Note: int(i) not guaranteed to have the desired + */ + __pyx_v_i = __pyx_v_phrase_location->arr_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":131 + * stepsize = float(num_locations)/float(self.sample_size) + * i = phrase_location.arr_low + * while i < num_locations and sample.len < self.sample_size * phrase_location.num_subpatterns: # <<<<<<<<<<<<<< + * '''Note: int(i) not guaranteed to have the desired + * effect, according to the python documentation''' + */ + while (1) { + __pyx_t_2 = (__pyx_v_i < __pyx_v_num_locations); + if (__pyx_t_2) { + __pyx_t_3 = (__pyx_v_sample->len < (__pyx_v_self->sample_size * __pyx_v_phrase_location->num_subpatterns)); + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_2; + } + if (!__pyx_t_4) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":134 + * '''Note: int(i) not guaranteed to have the desired + * effect, according to the python documentation''' + * if fmod(i,1.0) > 0.5: # <<<<<<<<<<<<<< + * val = int(ceil(i)) + * else: + */ + __pyx_t_4 = (fmod(__pyx_v_i, 1.0) > 0.5); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":135 + * effect, according to the python documentation''' + * if fmod(i,1.0) > 0.5: + * val = int(ceil(i)) # <<<<<<<<<<<<<< + * else: + * val = int(floor(i)) + */ + __pyx_v_val = ((int)ceil(__pyx_v_i)); + goto __pyx_L11; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":137 + * val = int(ceil(i)) + * else: + * val = int(floor(i)) # <<<<<<<<<<<<<< + * j = phrase_location.arr_low + (val*phrase_location.num_subpatterns) + * sample._extend_arr(phrase_location.arr.arr + j, phrase_location.num_subpatterns) + */ + __pyx_v_val = ((int)floor(__pyx_v_i)); + } + __pyx_L11:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":138 + * else: + * val = int(floor(i)) + * j = phrase_location.arr_low + (val*phrase_location.num_subpatterns) # <<<<<<<<<<<<<< + * sample._extend_arr(phrase_location.arr.arr + j, phrase_location.num_subpatterns) + * i = i + stepsize + */ + __pyx_v_j = (__pyx_v_phrase_location->arr_low + (__pyx_v_val * __pyx_v_phrase_location->num_subpatterns)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":139 + * val = int(floor(i)) + * j = phrase_location.arr_low + (val*phrase_location.num_subpatterns) + * sample._extend_arr(phrase_location.arr.arr + j, phrase_location.num_subpatterns) # <<<<<<<<<<<<<< + * i = i + stepsize + * return sample + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_sample->__pyx_vtab)->_extend_arr(__pyx_v_sample, (__pyx_v_phrase_location->arr->arr + __pyx_v_j), __pyx_v_phrase_location->num_subpatterns); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":140 + * j = phrase_location.arr_low + (val*phrase_location.num_subpatterns) + * sample._extend_arr(phrase_location.arr.arr + j, phrase_location.num_subpatterns) + * i = i + stepsize # <<<<<<<<<<<<<< + * return sample + * + */ + __pyx_v_i = (__pyx_v_i + __pyx_v_stepsize); + } + } + __pyx_L8:; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":141 + * sample._extend_arr(phrase_location.arr.arr + j, phrase_location.num_subpatterns) + * i = i + stepsize + * return sample # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_sample)); + __pyx_r = ((PyObject *)__pyx_v_sample); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_sa.Sampler.sample", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_sample); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":153 + * + * + * cdef void assign_matching(Matching* m, int* arr, int start, int step, int* sent_id_arr): # <<<<<<<<<<<<<< + * m.arr = arr + * m.start = start + */ + +static void __pyx_f_3_sa_assign_matching(struct __pyx_t_3_sa_Matching *__pyx_v_m, int *__pyx_v_arr, int __pyx_v_start, int __pyx_v_step, int *__pyx_v_sent_id_arr) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("assign_matching", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":154 + * + * cdef void assign_matching(Matching* m, int* arr, int start, int step, int* sent_id_arr): + * m.arr = arr # <<<<<<<<<<<<<< + * m.start = start + * m.end = start + step + */ + __pyx_v_m->arr = __pyx_v_arr; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":155 + * cdef void assign_matching(Matching* m, int* arr, int start, int step, int* sent_id_arr): + * m.arr = arr + * m.start = start # <<<<<<<<<<<<<< + * m.end = start + step + * m.sent_id = sent_id_arr[arr[start]] + */ + __pyx_v_m->start = __pyx_v_start; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":156 + * m.arr = arr + * m.start = start + * m.end = start + step # <<<<<<<<<<<<<< + * m.sent_id = sent_id_arr[arr[start]] + * m.size = step + */ + __pyx_v_m->end = (__pyx_v_start + __pyx_v_step); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":157 + * m.start = start + * m.end = start + step + * m.sent_id = sent_id_arr[arr[start]] # <<<<<<<<<<<<<< + * m.size = step + * + */ + __pyx_v_m->sent_id = (__pyx_v_sent_id_arr[(__pyx_v_arr[__pyx_v_start])]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":158 + * m.end = start + step + * m.sent_id = sent_id_arr[arr[start]] + * m.size = step # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_m->size = __pyx_v_step; + + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":161 + * + * + * cdef int* append_combined_matching(int* arr, Matching* loc1, Matching* loc2, # <<<<<<<<<<<<<< + * int offset_by_one, int num_subpatterns, int* result_len): + * cdef int i, new_len + */ + +static int *__pyx_f_3_sa_append_combined_matching(int *__pyx_v_arr, struct __pyx_t_3_sa_Matching *__pyx_v_loc1, struct __pyx_t_3_sa_Matching *__pyx_v_loc2, CYTHON_UNUSED int __pyx_v_offset_by_one, int __pyx_v_num_subpatterns, int *__pyx_v_result_len) { + int __pyx_v_i; + int __pyx_v_new_len; + int *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + __Pyx_RefNannySetupContext("append_combined_matching", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":165 + * cdef int i, new_len + * + * new_len = result_len[0] + num_subpatterns # <<<<<<<<<<<<<< + * arr = realloc(arr, new_len*sizeof(int)) + * + */ + __pyx_v_new_len = ((__pyx_v_result_len[0]) + __pyx_v_num_subpatterns); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":166 + * + * new_len = result_len[0] + num_subpatterns + * arr = realloc(arr, new_len*sizeof(int)) # <<<<<<<<<<<<<< + * + * for i from 0 <= i < loc1.size: + */ + __pyx_v_arr = ((int *)realloc(__pyx_v_arr, (__pyx_v_new_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":168 + * arr = realloc(arr, new_len*sizeof(int)) + * + * for i from 0 <= i < loc1.size: # <<<<<<<<<<<<<< + * arr[result_len[0]+i] = loc1.arr[loc1.start+i] + * if num_subpatterns > loc1.size: + */ + __pyx_t_1 = __pyx_v_loc1->size; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":169 + * + * for i from 0 <= i < loc1.size: + * arr[result_len[0]+i] = loc1.arr[loc1.start+i] # <<<<<<<<<<<<<< + * if num_subpatterns > loc1.size: + * arr[new_len-1] = loc2.arr[loc2.end-1] + */ + (__pyx_v_arr[((__pyx_v_result_len[0]) + __pyx_v_i)]) = (__pyx_v_loc1->arr[(__pyx_v_loc1->start + __pyx_v_i)]); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":170 + * for i from 0 <= i < loc1.size: + * arr[result_len[0]+i] = loc1.arr[loc1.start+i] + * if num_subpatterns > loc1.size: # <<<<<<<<<<<<<< + * arr[new_len-1] = loc2.arr[loc2.end-1] + * result_len[0] = new_len + */ + __pyx_t_2 = (__pyx_v_num_subpatterns > __pyx_v_loc1->size); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":171 + * arr[result_len[0]+i] = loc1.arr[loc1.start+i] + * if num_subpatterns > loc1.size: + * arr[new_len-1] = loc2.arr[loc2.end-1] # <<<<<<<<<<<<<< + * result_len[0] = new_len + * return arr + */ + (__pyx_v_arr[(__pyx_v_new_len - 1)]) = (__pyx_v_loc2->arr[(__pyx_v_loc2->end - 1)]); + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":172 + * if num_subpatterns > loc1.size: + * arr[new_len-1] = loc2.arr[loc2.end-1] + * result_len[0] = new_len # <<<<<<<<<<<<<< + * return arr + * + */ + (__pyx_v_result_len[0]) = __pyx_v_new_len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":173 + * arr[new_len-1] = loc2.arr[loc2.end-1] + * result_len[0] = new_len + * return arr # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_arr; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":176 + * + * + * cdef int* extend_arr(int* arr, int* arr_len, int* appendix, int appendix_len): # <<<<<<<<<<<<<< + * cdef int new_len + * + */ + +static int *__pyx_f_3_sa_extend_arr(int *__pyx_v_arr, int *__pyx_v_arr_len, int *__pyx_v_appendix, int __pyx_v_appendix_len) { + int __pyx_v_new_len; + int *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("extend_arr", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":179 + * cdef int new_len + * + * new_len = arr_len[0] + appendix_len # <<<<<<<<<<<<<< + * arr = realloc(arr, new_len*sizeof(int)) + * memcpy(arr+arr_len[0], appendix, appendix_len*sizeof(int)) + */ + __pyx_v_new_len = ((__pyx_v_arr_len[0]) + __pyx_v_appendix_len); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":180 + * + * new_len = arr_len[0] + appendix_len + * arr = realloc(arr, new_len*sizeof(int)) # <<<<<<<<<<<<<< + * memcpy(arr+arr_len[0], appendix, appendix_len*sizeof(int)) + * arr_len[0] = new_len + */ + __pyx_v_arr = ((int *)realloc(__pyx_v_arr, (__pyx_v_new_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":181 + * new_len = arr_len[0] + appendix_len + * arr = realloc(arr, new_len*sizeof(int)) + * memcpy(arr+arr_len[0], appendix, appendix_len*sizeof(int)) # <<<<<<<<<<<<<< + * arr_len[0] = new_len + * return arr + */ + memcpy((__pyx_v_arr + (__pyx_v_arr_len[0])), __pyx_v_appendix, (__pyx_v_appendix_len * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":182 + * arr = realloc(arr, new_len*sizeof(int)) + * memcpy(arr+arr_len[0], appendix, appendix_len*sizeof(int)) + * arr_len[0] = new_len # <<<<<<<<<<<<<< + * return arr + * + */ + (__pyx_v_arr_len[0]) = __pyx_v_new_len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":183 + * memcpy(arr+arr_len[0], appendix, appendix_len*sizeof(int)) + * arr_len[0] = new_len + * return arr # <<<<<<<<<<<<<< + * + * cdef int median(int low, int high, int step): + */ + __pyx_r = __pyx_v_arr; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":185 + * return arr + * + * cdef int median(int low, int high, int step): # <<<<<<<<<<<<<< + * return low + (((high - low)/step)/2)*step + * + */ + +static int __pyx_f_3_sa_median(int __pyx_v_low, int __pyx_v_high, int __pyx_v_step) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("median", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":186 + * + * cdef int median(int low, int high, int step): + * return low + (((high - low)/step)/2)*step # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_1 = (__pyx_v_high - __pyx_v_low); + if (unlikely(__pyx_v_step == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_step == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_1))) { + PyErr_Format(PyExc_OverflowError, "value too large to perform division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_r = (__pyx_v_low + (__Pyx_div_long(__Pyx_div_int(__pyx_t_1, __pyx_v_step), 2) * __pyx_v_step)); + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("_sa.median", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":189 + * + * + * cdef void find_comparable_matchings(int low, int high, int* arr, int step, int loc, int* loc_minus, int* loc_plus): # <<<<<<<<<<<<<< + * # Returns (minus, plus) indices for the portion of the array + * # in which all matchings have the same first index as the one + */ + +static void __pyx_f_3_sa_find_comparable_matchings(int __pyx_v_low, int __pyx_v_high, int *__pyx_v_arr, int __pyx_v_step, int __pyx_v_loc, int *__pyx_v_loc_minus, int *__pyx_v_loc_plus) { + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("find_comparable_matchings", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":193 + * # in which all matchings have the same first index as the one + * # starting at loc + * loc_plus[0] = loc + step # <<<<<<<<<<<<<< + * while loc_plus[0] < high and arr[loc_plus[0]] == arr[loc]: + * loc_plus[0] = loc_plus[0] + step + */ + (__pyx_v_loc_plus[0]) = (__pyx_v_loc + __pyx_v_step); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":194 + * # starting at loc + * loc_plus[0] = loc + step + * while loc_plus[0] < high and arr[loc_plus[0]] == arr[loc]: # <<<<<<<<<<<<<< + * loc_plus[0] = loc_plus[0] + step + * loc_minus[0] = loc + */ + while (1) { + __pyx_t_1 = ((__pyx_v_loc_plus[0]) < __pyx_v_high); + if (__pyx_t_1) { + __pyx_t_2 = ((__pyx_v_arr[(__pyx_v_loc_plus[0])]) == (__pyx_v_arr[__pyx_v_loc])); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":195 + * loc_plus[0] = loc + step + * while loc_plus[0] < high and arr[loc_plus[0]] == arr[loc]: + * loc_plus[0] = loc_plus[0] + step # <<<<<<<<<<<<<< + * loc_minus[0] = loc + * while loc_minus[0]-step >= low and arr[loc_minus[0]-step] == arr[loc]: + */ + (__pyx_v_loc_plus[0]) = ((__pyx_v_loc_plus[0]) + __pyx_v_step); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":196 + * while loc_plus[0] < high and arr[loc_plus[0]] == arr[loc]: + * loc_plus[0] = loc_plus[0] + step + * loc_minus[0] = loc # <<<<<<<<<<<<<< + * while loc_minus[0]-step >= low and arr[loc_minus[0]-step] == arr[loc]: + * loc_minus[0] = loc_minus[0] - step + */ + (__pyx_v_loc_minus[0]) = __pyx_v_loc; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":197 + * loc_plus[0] = loc_plus[0] + step + * loc_minus[0] = loc + * while loc_minus[0]-step >= low and arr[loc_minus[0]-step] == arr[loc]: # <<<<<<<<<<<<<< + * loc_minus[0] = loc_minus[0] - step + * + */ + while (1) { + __pyx_t_3 = (((__pyx_v_loc_minus[0]) - __pyx_v_step) >= __pyx_v_low); + if (__pyx_t_3) { + __pyx_t_1 = ((__pyx_v_arr[((__pyx_v_loc_minus[0]) - __pyx_v_step)]) == (__pyx_v_arr[__pyx_v_loc])); + __pyx_t_2 = __pyx_t_1; + } else { + __pyx_t_2 = __pyx_t_3; + } + if (!__pyx_t_2) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":198 + * loc_minus[0] = loc + * while loc_minus[0]-step >= low and arr[loc_minus[0]-step] == arr[loc]: + * loc_minus[0] = loc_minus[0] - step # <<<<<<<<<<<<<< + * + * + */ + (__pyx_v_loc_minus[0]) = ((__pyx_v_loc_minus[0]) - __pyx_v_step); + } + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static int __pyx_pw_3_sa_23HieroCachingRuleFactory_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_3_sa_23HieroCachingRuleFactory_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + struct __pyx_obj_3_sa_Alignment *__pyx_v_alignment = 0; + float __pyx_v_by_slack_factor; + char *__pyx_v_category; + PyObject *__pyx_v_max_chunks = 0; + unsigned int __pyx_v_max_initial_size; + unsigned int __pyx_v_max_length; + unsigned int __pyx_v_max_nonterminals; + PyObject *__pyx_v_max_target_chunks = 0; + PyObject *__pyx_v_max_target_length = 0; + unsigned int __pyx_v_min_gap_size; + PyObject *__pyx_v_precompute_file = 0; + unsigned int __pyx_v_precompute_secondary_rank; + unsigned int __pyx_v_precompute_rank; + int __pyx_v_require_aligned_terminal; + int __pyx_v_require_aligned_chunks; + unsigned int __pyx_v_train_max_initial_size; + unsigned int __pyx_v_train_min_gap_size; + int __pyx_v_tight_phrases; + int __pyx_v_use_baeza_yates; + int __pyx_v_use_collocations; + int __pyx_v_use_index; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__alignment,&__pyx_n_s__by_slack_factor,&__pyx_n_s__category,&__pyx_n_s__max_chunks,&__pyx_n_s__max_initial_size,&__pyx_n_s__max_length,&__pyx_n_s__max_nonterminals,&__pyx_n_s__max_target_chunks,&__pyx_n_s__max_target_length,&__pyx_n_s__min_gap_size,&__pyx_n_s__precompute_file,&__pyx_n_s_68,&__pyx_n_s__precompute_rank,&__pyx_n_s_101,&__pyx_n_s_102,&__pyx_n_s_69,&__pyx_n_s__train_min_gap_size,&__pyx_n_s__tight_phrases,&__pyx_n_s__use_baeza_yates,&__pyx_n_s__use_collocations,&__pyx_n_s__use_index,0}; + PyObject* values[21] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":257 + * char* category="[X]", + * # maximum number of contiguous chunks of terminal symbols in RHS of a rule. If None, defaults to max_nonterminals+1 + * max_chunks=None, # <<<<<<<<<<<<<< + * # maximum span of a grammar rule in TEST DATA + * unsigned max_initial_size=10, + */ + values[3] = ((PyObject *)Py_None); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":265 + * unsigned max_nonterminals=2, + * # maximum number of contiguous chunks of terminal symbols in target-side RHS of a rule. If None, defaults to max_nonterminals+1 + * max_target_chunks=None, # <<<<<<<<<<<<<< + * # maximum number of target side symbols (both T and NT) allowed in a rule. If None, defaults to max_initial_size + * max_target_length=None, + */ + values[7] = ((PyObject *)Py_None); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":267 + * max_target_chunks=None, + * # maximum number of target side symbols (both T and NT) allowed in a rule. If None, defaults to max_initial_size + * max_target_length=None, # <<<<<<<<<<<<<< + * # minimum span of a nonterminal in the RHS of a rule in TEST DATA + * unsigned min_gap_size=2, + */ + values[8] = ((PyObject *)Py_None); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":271 + * unsigned min_gap_size=2, + * # filename of file containing precomputed collocations + * precompute_file=None, # <<<<<<<<<<<<<< + * # maximum frequency rank of patterns used to compute triples (don't set higher than 20). + * unsigned precompute_secondary_rank=20, + */ + values[10] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 21: values[20] = PyTuple_GET_ITEM(__pyx_args, 20); + case 20: values[19] = PyTuple_GET_ITEM(__pyx_args, 19); + case 19: values[18] = PyTuple_GET_ITEM(__pyx_args, 18); + case 18: values[17] = PyTuple_GET_ITEM(__pyx_args, 17); + case 17: values[16] = PyTuple_GET_ITEM(__pyx_args, 16); + case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15); + case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14); + case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13); + case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); + case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); + case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); + case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__alignment)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__by_slack_factor); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__category); + if (value) { values[2] = value; kw_args--; } + } + case 3: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_chunks); + if (value) { values[3] = value; kw_args--; } + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_initial_size); + if (value) { values[4] = value; kw_args--; } + } + case 5: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_length); + if (value) { values[5] = value; kw_args--; } + } + case 6: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_nonterminals); + if (value) { values[6] = value; kw_args--; } + } + case 7: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_target_chunks); + if (value) { values[7] = value; kw_args--; } + } + case 8: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__max_target_length); + if (value) { values[8] = value; kw_args--; } + } + case 9: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__min_gap_size); + if (value) { values[9] = value; kw_args--; } + } + case 10: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__precompute_file); + if (value) { values[10] = value; kw_args--; } + } + case 11: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_68); + if (value) { values[11] = value; kw_args--; } + } + case 12: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__precompute_rank); + if (value) { values[12] = value; kw_args--; } + } + case 13: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_101); + if (value) { values[13] = value; kw_args--; } + } + case 14: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_102); + if (value) { values[14] = value; kw_args--; } + } + case 15: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_69); + if (value) { values[15] = value; kw_args--; } + } + case 16: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__train_min_gap_size); + if (value) { values[16] = value; kw_args--; } + } + case 17: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__tight_phrases); + if (value) { values[17] = value; kw_args--; } + } + case 18: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_baeza_yates); + if (value) { values[18] = value; kw_args--; } + } + case 19: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_collocations); + if (value) { values[19] = value; kw_args--; } + } + case 20: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_index); + if (value) { values[20] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 21: values[20] = PyTuple_GET_ITEM(__pyx_args, 20); + case 20: values[19] = PyTuple_GET_ITEM(__pyx_args, 19); + case 19: values[18] = PyTuple_GET_ITEM(__pyx_args, 18); + case 18: values[17] = PyTuple_GET_ITEM(__pyx_args, 17); + case 17: values[16] = PyTuple_GET_ITEM(__pyx_args, 16); + case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15); + case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14); + case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13); + case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); + case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); + case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); + case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); + case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); + case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_alignment = ((struct __pyx_obj_3_sa_Alignment *)values[0]); + if (values[1]) { + __pyx_v_by_slack_factor = __pyx_PyFloat_AsFloat(values[1]); if (unlikely((__pyx_v_by_slack_factor == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":253 + * Alignment alignment, + * # parameter for double-binary search; doesn't seem to matter much + * float by_slack_factor=1.0, # <<<<<<<<<<<<<< + * # name of generic nonterminal used by Hiero + * char* category="[X]", + */ + __pyx_v_by_slack_factor = ((float)1.0); + } + if (values[2]) { + __pyx_v_category = PyBytes_AsString(values[2]); if (unlikely((!__pyx_v_category) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_category = ((char *)__pyx_k_103); + } + __pyx_v_max_chunks = values[3]; + if (values[4]) { + __pyx_v_max_initial_size = __Pyx_PyInt_AsUnsignedInt(values[4]); if (unlikely((__pyx_v_max_initial_size == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_max_initial_size = ((unsigned int)10); + } + if (values[5]) { + __pyx_v_max_length = __Pyx_PyInt_AsUnsignedInt(values[5]); if (unlikely((__pyx_v_max_length == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_max_length = ((unsigned int)5); + } + if (values[6]) { + __pyx_v_max_nonterminals = __Pyx_PyInt_AsUnsignedInt(values[6]); if (unlikely((__pyx_v_max_nonterminals == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_max_nonterminals = ((unsigned int)2); + } + __pyx_v_max_target_chunks = values[7]; + __pyx_v_max_target_length = values[8]; + if (values[9]) { + __pyx_v_min_gap_size = __Pyx_PyInt_AsUnsignedInt(values[9]); if (unlikely((__pyx_v_min_gap_size == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_min_gap_size = ((unsigned int)2); + } + __pyx_v_precompute_file = values[10]; + if (values[11]) { + __pyx_v_precompute_secondary_rank = __Pyx_PyInt_AsUnsignedInt(values[11]); if (unlikely((__pyx_v_precompute_secondary_rank == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_precompute_secondary_rank = ((unsigned int)20); + } + if (values[12]) { + __pyx_v_precompute_rank = __Pyx_PyInt_AsUnsignedInt(values[12]); if (unlikely((__pyx_v_precompute_rank == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_precompute_rank = ((unsigned int)100); + } + if (values[13]) { + __pyx_v_require_aligned_terminal = __Pyx_PyObject_IsTrue(values[13]); if (unlikely((__pyx_v_require_aligned_terminal == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":277 + * unsigned precompute_rank=100, + * # require extracted rules to have at least one aligned word + * bint require_aligned_terminal=True, # <<<<<<<<<<<<<< + * # require each contiguous chunk of extracted rules to have at least one aligned word + * bint require_aligned_chunks=False, + */ + __pyx_v_require_aligned_terminal = ((int)1); + } + if (values[14]) { + __pyx_v_require_aligned_chunks = __Pyx_PyObject_IsTrue(values[14]); if (unlikely((__pyx_v_require_aligned_chunks == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":279 + * bint require_aligned_terminal=True, + * # require each contiguous chunk of extracted rules to have at least one aligned word + * bint require_aligned_chunks=False, # <<<<<<<<<<<<<< + * # maximum span of a grammar rule extracted from TRAINING DATA + * unsigned train_max_initial_size=10, + */ + __pyx_v_require_aligned_chunks = ((int)0); + } + if (values[15]) { + __pyx_v_train_max_initial_size = __Pyx_PyInt_AsUnsignedInt(values[15]); if (unlikely((__pyx_v_train_max_initial_size == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_train_max_initial_size = ((unsigned int)10); + } + if (values[16]) { + __pyx_v_train_min_gap_size = __Pyx_PyInt_AsUnsignedInt(values[16]); if (unlikely((__pyx_v_train_min_gap_size == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_train_min_gap_size = ((unsigned int)2); + } + if (values[17]) { + __pyx_v_tight_phrases = __Pyx_PyObject_IsTrue(values[17]); if (unlikely((__pyx_v_tight_phrases == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":285 + * unsigned train_min_gap_size=2, + * # True if phrases should be tight, False otherwise (False == slower but better results) + * bint tight_phrases=False, # <<<<<<<<<<<<<< + * # True to require use of double-binary alg, false otherwise + * bint use_baeza_yates=True, + */ + __pyx_v_tight_phrases = ((int)0); + } + if (values[18]) { + __pyx_v_use_baeza_yates = __Pyx_PyObject_IsTrue(values[18]); if (unlikely((__pyx_v_use_baeza_yates == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":287 + * bint tight_phrases=False, + * # True to require use of double-binary alg, false otherwise + * bint use_baeza_yates=True, # <<<<<<<<<<<<<< + * # True to enable used of precomputed collocations + * bint use_collocations=True, + */ + __pyx_v_use_baeza_yates = ((int)1); + } + if (values[19]) { + __pyx_v_use_collocations = __Pyx_PyObject_IsTrue(values[19]); if (unlikely((__pyx_v_use_collocations == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":289 + * bint use_baeza_yates=True, + * # True to enable used of precomputed collocations + * bint use_collocations=True, # <<<<<<<<<<<<<< + * # True to enable use of precomputed inverted indices + * bint use_index=True): + */ + __pyx_v_use_collocations = ((int)1); + } + if (values[20]) { + __pyx_v_use_index = __Pyx_PyObject_IsTrue(values[20]); if (unlikely((__pyx_v_use_index == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":291 + * bint use_collocations=True, + * # True to enable use of precomputed inverted indices + * bint use_index=True): # <<<<<<<<<<<<<< + * '''Note: we make a distinction between the min_gap_size + * and max_initial_size used in test and train. The latter + */ + __pyx_v_use_index = ((int)1); + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 21, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_alignment), __pyx_ptype_3_sa_Alignment, 1, "alignment", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 251; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_3_sa_23HieroCachingRuleFactory___cinit__(((struct __pyx_obj_3_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_alignment, __pyx_v_by_slack_factor, __pyx_v_category, __pyx_v_max_chunks, __pyx_v_max_initial_size, __pyx_v_max_length, __pyx_v_max_nonterminals, __pyx_v_max_target_chunks, __pyx_v_max_target_length, __pyx_v_min_gap_size, __pyx_v_precompute_file, __pyx_v_precompute_secondary_rank, __pyx_v_precompute_rank, __pyx_v_require_aligned_terminal, __pyx_v_require_aligned_chunks, __pyx_v_train_max_initial_size, __pyx_v_train_min_gap_size, __pyx_v_tight_phrases, __pyx_v_use_baeza_yates, __pyx_v_use_collocations, __pyx_v_use_index); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":249 + * cdef IntList findexes1 + * + * def __cinit__(self, # <<<<<<<<<<<<<< + * # compiled alignment object (REQUIRED) + * Alignment alignment, + */ + +static int __pyx_pf_3_sa_23HieroCachingRuleFactory___cinit__(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_3_sa_Alignment *__pyx_v_alignment, float __pyx_v_by_slack_factor, char *__pyx_v_category, PyObject *__pyx_v_max_chunks, unsigned int __pyx_v_max_initial_size, unsigned int __pyx_v_max_length, unsigned int __pyx_v_max_nonterminals, PyObject *__pyx_v_max_target_chunks, PyObject *__pyx_v_max_target_length, unsigned int __pyx_v_min_gap_size, PyObject *__pyx_v_precompute_file, unsigned int __pyx_v_precompute_secondary_rank, unsigned int __pyx_v_precompute_rank, int __pyx_v_require_aligned_terminal, int __pyx_v_require_aligned_chunks, unsigned int __pyx_v_train_max_initial_size, unsigned int __pyx_v_train_min_gap_size, int __pyx_v_tight_phrases, int __pyx_v_use_baeza_yates, int __pyx_v_use_collocations, int __pyx_v_use_index) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":297 + * respectively. This is because Chiang's model does not require + * them to be the same, therefore we don't either.''' + * self.rules = TrieTable(True) # cache # <<<<<<<<<<<<<< + * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) + * if alignment is None: + */ + __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_TrieTable)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->rules); + __Pyx_DECREF(((PyObject *)__pyx_v_self->rules)); + __pyx_v_self->rules = ((struct __pyx_obj_3_sa_TrieTable *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":298 + * them to be the same, therefore we don't either.''' + * self.rules = TrieTable(True) # cache + * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) # <<<<<<<<<<<<<< + * if alignment is None: + * raise Exception("Must specify an alignment object") + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_PhraseLocation)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__phrase_location), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 298; __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); + __Pyx_GOTREF(__pyx_v_self->rules->root); + __Pyx_DECREF(__pyx_v_self->rules->root); + __pyx_v_self->rules->root = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":299 + * self.rules = TrieTable(True) # cache + * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) + * if alignment is None: # <<<<<<<<<<<<<< + * raise Exception("Must specify an alignment object") + * self.alignment = alignment + */ + __pyx_t_3 = (((PyObject *)__pyx_v_alignment) == Py_None); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":300 + * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) + * if alignment is None: + * raise Exception("Must specify an alignment object") # <<<<<<<<<<<<<< + * self.alignment = alignment + * + */ + __pyx_t_2 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_k_tuple_105), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":301 + * if alignment is None: + * raise Exception("Must specify an alignment object") + * self.alignment = alignment # <<<<<<<<<<<<<< + * + * # grammar parameters and settings + */ + __Pyx_INCREF(((PyObject *)__pyx_v_alignment)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_alignment)); + __Pyx_GOTREF(__pyx_v_self->alignment); + __Pyx_DECREF(((PyObject *)__pyx_v_self->alignment)); + __pyx_v_self->alignment = __pyx_v_alignment; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":305 + * # grammar parameters and settings + * # NOTE: setting max_nonterminals > 2 is not currently supported in Hiero + * self.max_length = max_length # <<<<<<<<<<<<<< + * self.max_nonterminals = max_nonterminals + * self.max_initial_size = max_initial_size + */ + __pyx_v_self->max_length = __pyx_v_max_length; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":306 + * # NOTE: setting max_nonterminals > 2 is not currently supported in Hiero + * self.max_length = max_length + * self.max_nonterminals = max_nonterminals # <<<<<<<<<<<<<< + * self.max_initial_size = max_initial_size + * self.train_max_initial_size = train_max_initial_size + */ + __pyx_v_self->max_nonterminals = __pyx_v_max_nonterminals; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":307 + * self.max_length = max_length + * self.max_nonterminals = max_nonterminals + * self.max_initial_size = max_initial_size # <<<<<<<<<<<<<< + * self.train_max_initial_size = train_max_initial_size + * self.min_gap_size = min_gap_size + */ + __pyx_v_self->max_initial_size = __pyx_v_max_initial_size; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":308 + * self.max_nonterminals = max_nonterminals + * self.max_initial_size = max_initial_size + * self.train_max_initial_size = train_max_initial_size # <<<<<<<<<<<<<< + * self.min_gap_size = min_gap_size + * self.train_min_gap_size = train_min_gap_size + */ + __pyx_v_self->train_max_initial_size = __pyx_v_train_max_initial_size; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":309 + * self.max_initial_size = max_initial_size + * self.train_max_initial_size = train_max_initial_size + * self.min_gap_size = min_gap_size # <<<<<<<<<<<<<< + * self.train_min_gap_size = train_min_gap_size + * self.category = sym_fromstring(category, False) + */ + __pyx_v_self->min_gap_size = __pyx_v_min_gap_size; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":310 + * self.train_max_initial_size = train_max_initial_size + * self.min_gap_size = min_gap_size + * self.train_min_gap_size = train_min_gap_size # <<<<<<<<<<<<<< + * self.category = sym_fromstring(category, False) + * + */ + __pyx_v_self->train_min_gap_size = __pyx_v_train_min_gap_size; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":311 + * self.min_gap_size = min_gap_size + * self.train_min_gap_size = train_min_gap_size + * self.category = sym_fromstring(category, False) # <<<<<<<<<<<<<< + * + * if max_chunks is None: + */ + __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_fromstring); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyBytes_FromString(__pyx_v_category); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_4 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 311; __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[8]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_1 = 0; + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_self->category = __pyx_t_6; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":313 + * self.category = sym_fromstring(category, False) + * + * if max_chunks is None: # <<<<<<<<<<<<<< + * self.max_chunks = self.max_nonterminals + 1 + * else: + */ + __pyx_t_3 = (__pyx_v_max_chunks == Py_None); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":314 + * + * if max_chunks is None: + * self.max_chunks = self.max_nonterminals + 1 # <<<<<<<<<<<<<< + * else: + * self.max_chunks = max_chunks + */ + __pyx_v_self->max_chunks = (__pyx_v_self->max_nonterminals + 1); + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":316 + * self.max_chunks = self.max_nonterminals + 1 + * else: + * self.max_chunks = max_chunks # <<<<<<<<<<<<<< + * + * if max_target_chunks is None: + */ + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_max_chunks); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 316; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->max_chunks = __pyx_t_6; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":318 + * self.max_chunks = max_chunks + * + * if max_target_chunks is None: # <<<<<<<<<<<<<< + * self.max_target_chunks = self.max_nonterminals + 1 + * else: + */ + __pyx_t_3 = (__pyx_v_max_target_chunks == Py_None); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":319 + * + * if max_target_chunks is None: + * self.max_target_chunks = self.max_nonterminals + 1 # <<<<<<<<<<<<<< + * else: + * self.max_target_chunks = max_target_chunks + */ + __pyx_v_self->max_target_chunks = (__pyx_v_self->max_nonterminals + 1); + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":321 + * self.max_target_chunks = self.max_nonterminals + 1 + * else: + * self.max_target_chunks = max_target_chunks # <<<<<<<<<<<<<< + * + * if max_target_length is None: + */ + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_max_target_chunks); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->max_target_chunks = __pyx_t_6; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":323 + * self.max_target_chunks = max_target_chunks + * + * if max_target_length is None: # <<<<<<<<<<<<<< + * self.max_target_length = max_initial_size + * else: + */ + __pyx_t_3 = (__pyx_v_max_target_length == Py_None); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":324 + * + * if max_target_length is None: + * self.max_target_length = max_initial_size # <<<<<<<<<<<<<< + * else: + * self.max_target_length = max_target_length + */ + __pyx_v_self->max_target_length = __pyx_v_max_initial_size; + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":326 + * self.max_target_length = max_initial_size + * else: + * self.max_target_length = max_target_length # <<<<<<<<<<<<<< + * + * # algorithmic parameters and settings + */ + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_max_target_length); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->max_target_length = __pyx_t_6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":329 + * + * # algorithmic parameters and settings + * self.precomputed_collocations = {} # <<<<<<<<<<<<<< + * self.precomputed_index = {} + * self.use_index = use_index + */ + __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __Pyx_GOTREF(__pyx_v_self->precomputed_collocations); + __Pyx_DECREF(__pyx_v_self->precomputed_collocations); + __pyx_v_self->precomputed_collocations = ((PyObject *)__pyx_t_4); + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":330 + * # algorithmic parameters and settings + * self.precomputed_collocations = {} + * self.precomputed_index = {} # <<<<<<<<<<<<<< + * self.use_index = use_index + * self.use_collocations = use_collocations + */ + __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 330; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __Pyx_GOTREF(__pyx_v_self->precomputed_index); + __Pyx_DECREF(__pyx_v_self->precomputed_index); + __pyx_v_self->precomputed_index = ((PyObject *)__pyx_t_4); + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":331 + * self.precomputed_collocations = {} + * self.precomputed_index = {} + * self.use_index = use_index # <<<<<<<<<<<<<< + * self.use_collocations = use_collocations + * self.max_rank = {} + */ + __pyx_v_self->use_index = __pyx_v_use_index; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":332 + * self.precomputed_index = {} + * self.use_index = use_index + * self.use_collocations = use_collocations # <<<<<<<<<<<<<< + * self.max_rank = {} + * self.precompute_file = precompute_file + */ + __pyx_v_self->use_collocations = __pyx_v_use_collocations; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":333 + * self.use_index = use_index + * self.use_collocations = use_collocations + * self.max_rank = {} # <<<<<<<<<<<<<< + * self.precompute_file = precompute_file + * self.precompute_rank = precompute_rank + */ + __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __Pyx_GOTREF(__pyx_v_self->max_rank); + __Pyx_DECREF(__pyx_v_self->max_rank); + __pyx_v_self->max_rank = ((PyObject *)__pyx_t_4); + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":334 + * self.use_collocations = use_collocations + * self.max_rank = {} + * self.precompute_file = precompute_file # <<<<<<<<<<<<<< + * self.precompute_rank = precompute_rank + * self.precompute_secondary_rank = precompute_secondary_rank + */ + __Pyx_INCREF(__pyx_v_precompute_file); + __Pyx_GIVEREF(__pyx_v_precompute_file); + __Pyx_GOTREF(__pyx_v_self->precompute_file); + __Pyx_DECREF(__pyx_v_self->precompute_file); + __pyx_v_self->precompute_file = __pyx_v_precompute_file; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":335 + * self.max_rank = {} + * self.precompute_file = precompute_file + * self.precompute_rank = precompute_rank # <<<<<<<<<<<<<< + * self.precompute_secondary_rank = precompute_secondary_rank + * self.use_baeza_yates = use_baeza_yates + */ + __pyx_v_self->precompute_rank = __pyx_v_precompute_rank; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":336 + * self.precompute_file = precompute_file + * self.precompute_rank = precompute_rank + * self.precompute_secondary_rank = precompute_secondary_rank # <<<<<<<<<<<<<< + * self.use_baeza_yates = use_baeza_yates + * self.by_slack_factor = by_slack_factor + */ + __pyx_v_self->precompute_secondary_rank = __pyx_v_precompute_secondary_rank; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":337 + * self.precompute_rank = precompute_rank + * self.precompute_secondary_rank = precompute_secondary_rank + * self.use_baeza_yates = use_baeza_yates # <<<<<<<<<<<<<< + * self.by_slack_factor = by_slack_factor + * if tight_phrases: + */ + __pyx_v_self->use_baeza_yates = __pyx_v_use_baeza_yates; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":338 + * self.precompute_secondary_rank = precompute_secondary_rank + * self.use_baeza_yates = use_baeza_yates + * self.by_slack_factor = by_slack_factor # <<<<<<<<<<<<<< + * if tight_phrases: + * self.tight_phrases = 1 + */ + __pyx_v_self->by_slack_factor = __pyx_v_by_slack_factor; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":339 + * self.use_baeza_yates = use_baeza_yates + * self.by_slack_factor = by_slack_factor + * if tight_phrases: # <<<<<<<<<<<<<< + * self.tight_phrases = 1 + * else: + */ + if (__pyx_v_tight_phrases) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":340 + * self.by_slack_factor = by_slack_factor + * if tight_phrases: + * self.tight_phrases = 1 # <<<<<<<<<<<<<< + * else: + * self.tight_phrases = 0 + */ + __pyx_v_self->tight_phrases = 1; + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":342 + * self.tight_phrases = 1 + * else: + * self.tight_phrases = 0 # <<<<<<<<<<<<<< + * + * if require_aligned_chunks: + */ + __pyx_v_self->tight_phrases = 0; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":344 + * self.tight_phrases = 0 + * + * if require_aligned_chunks: # <<<<<<<<<<<<<< + * # one condition is a stronger version of the other. + * self.require_aligned_chunks = 1 + */ + if (__pyx_v_require_aligned_chunks) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":346 + * if require_aligned_chunks: + * # one condition is a stronger version of the other. + * self.require_aligned_chunks = 1 # <<<<<<<<<<<<<< + * self.require_aligned_terminal = 1 + * elif require_aligned_terminal: + */ + __pyx_v_self->require_aligned_chunks = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":347 + * # one condition is a stronger version of the other. + * self.require_aligned_chunks = 1 + * self.require_aligned_terminal = 1 # <<<<<<<<<<<<<< + * elif require_aligned_terminal: + * self.require_aligned_chunks = 0 + */ + __pyx_v_self->require_aligned_terminal = 1; + goto __pyx_L8; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":348 + * self.require_aligned_chunks = 1 + * self.require_aligned_terminal = 1 + * elif require_aligned_terminal: # <<<<<<<<<<<<<< + * self.require_aligned_chunks = 0 + * self.require_aligned_terminal = 1 + */ + if (__pyx_v_require_aligned_terminal) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":349 + * self.require_aligned_terminal = 1 + * elif require_aligned_terminal: + * self.require_aligned_chunks = 0 # <<<<<<<<<<<<<< + * self.require_aligned_terminal = 1 + * else: + */ + __pyx_v_self->require_aligned_chunks = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":350 + * elif require_aligned_terminal: + * self.require_aligned_chunks = 0 + * self.require_aligned_terminal = 1 # <<<<<<<<<<<<<< + * else: + * self.require_aligned_chunks = 0 + */ + __pyx_v_self->require_aligned_terminal = 1; + goto __pyx_L8; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":352 + * self.require_aligned_terminal = 1 + * else: + * self.require_aligned_chunks = 0 # <<<<<<<<<<<<<< + * self.require_aligned_terminal = 0 + * + */ + __pyx_v_self->require_aligned_chunks = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":353 + * else: + * self.require_aligned_chunks = 0 + * self.require_aligned_terminal = 0 # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_self->require_aligned_terminal = 0; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":357 + * + * # diagnostics + * self.prev_norm_prefix = () # <<<<<<<<<<<<<< + * + * self.findexes = IntList(initial_len=10) + */ + __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); + __Pyx_GIVEREF(((PyObject *)__pyx_empty_tuple)); + __Pyx_GOTREF(__pyx_v_self->prev_norm_prefix); + __Pyx_DECREF(__pyx_v_self->prev_norm_prefix); + __pyx_v_self->prev_norm_prefix = ((PyObject *)__pyx_empty_tuple); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":359 + * self.prev_norm_prefix = () + * + * self.findexes = IntList(initial_len=10) # <<<<<<<<<<<<<< + * self.findexes1 = IntList(initial_len=10) + * + */ + __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__initial_len), __pyx_int_10) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_GIVEREF(__pyx_t_5); + __Pyx_GOTREF(__pyx_v_self->findexes); + __Pyx_DECREF(((PyObject *)__pyx_v_self->findexes)); + __pyx_v_self->findexes = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_5); + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":360 + * + * self.findexes = IntList(initial_len=10) + * self.findexes1 = IntList(initial_len=10) # <<<<<<<<<<<<<< + * + * def configure(self, SuffixArray fsarray, DataArray edarray, Sampler sampler): + */ + __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__initial_len), __pyx_int_10) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_v_self->findexes1); + __Pyx_DECREF(((PyObject *)__pyx_v_self->findexes1)); + __pyx_v_self->findexes1 = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_4); + __pyx_t_4 = 0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_3configure(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_3_sa_23HieroCachingRuleFactory_2configure[] = "This gives the RuleFactory access to the Context object.\n Here we also use it to precompute the most expensive intersections\n in the corpus quickly."; +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_3configure(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + struct __pyx_obj_3_sa_SuffixArray *__pyx_v_fsarray = 0; + struct __pyx_obj_3_sa_DataArray *__pyx_v_edarray = 0; + struct __pyx_obj_3_sa_Sampler *__pyx_v_sampler = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("configure (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fsarray,&__pyx_n_s__edarray,&__pyx_n_s__sampler,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fsarray)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__edarray)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("configure", 1, 3, 3, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sampler)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("configure", 1, 3, 3, 2); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "configure") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_fsarray = ((struct __pyx_obj_3_sa_SuffixArray *)values[0]); + __pyx_v_edarray = ((struct __pyx_obj_3_sa_DataArray *)values[1]); + __pyx_v_sampler = ((struct __pyx_obj_3_sa_Sampler *)values[2]); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("configure", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.configure", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fsarray), __pyx_ptype_3_sa_SuffixArray, 1, "fsarray", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_edarray), __pyx_ptype_3_sa_DataArray, 1, "edarray", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_sampler), __pyx_ptype_3_sa_Sampler, 1, "sampler", 0))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_3_sa_23HieroCachingRuleFactory_2configure(((struct __pyx_obj_3_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_fsarray, __pyx_v_edarray, __pyx_v_sampler); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":362 + * self.findexes1 = IntList(initial_len=10) + * + * def configure(self, SuffixArray fsarray, DataArray edarray, Sampler sampler): # <<<<<<<<<<<<<< + * '''This gives the RuleFactory access to the Context object. + * Here we also use it to precompute the most expensive intersections + */ + +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_2configure(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_3_sa_SuffixArray *__pyx_v_fsarray, struct __pyx_obj_3_sa_DataArray *__pyx_v_edarray, struct __pyx_obj_3_sa_Sampler *__pyx_v_sampler) { + 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("configure", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":366 + * Here we also use it to precompute the most expensive intersections + * in the corpus quickly.''' + * self.fsa = fsarray # <<<<<<<<<<<<<< + * self.fda = fsarray.darray + * self.eda = edarray + */ + __Pyx_INCREF(((PyObject *)__pyx_v_fsarray)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fsarray)); + __Pyx_GOTREF(__pyx_v_self->fsa); + __Pyx_DECREF(((PyObject *)__pyx_v_self->fsa)); + __pyx_v_self->fsa = __pyx_v_fsarray; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":367 + * in the corpus quickly.''' + * self.fsa = fsarray + * self.fda = fsarray.darray # <<<<<<<<<<<<<< + * self.eda = edarray + * self.fid2symid = self.set_idmap(self.fda) + */ + __Pyx_INCREF(((PyObject *)__pyx_v_fsarray->darray)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fsarray->darray)); + __Pyx_GOTREF(__pyx_v_self->fda); + __Pyx_DECREF(((PyObject *)__pyx_v_self->fda)); + __pyx_v_self->fda = __pyx_v_fsarray->darray; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":368 + * self.fsa = fsarray + * self.fda = fsarray.darray + * self.eda = edarray # <<<<<<<<<<<<<< + * self.fid2symid = self.set_idmap(self.fda) + * self.eid2symid = self.set_idmap(self.eda) + */ + __Pyx_INCREF(((PyObject *)__pyx_v_edarray)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_edarray)); + __Pyx_GOTREF(__pyx_v_self->eda); + __Pyx_DECREF(((PyObject *)__pyx_v_self->eda)); + __pyx_v_self->eda = __pyx_v_edarray; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":369 + * self.fda = fsarray.darray + * self.eda = edarray + * self.fid2symid = self.set_idmap(self.fda) # <<<<<<<<<<<<<< + * self.eid2symid = self.set_idmap(self.eda) + * self.precompute() + */ + __pyx_t_1 = ((PyObject *)__pyx_v_self->fda); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->set_idmap(__pyx_v_self, ((struct __pyx_obj_3_sa_DataArray *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_3_sa_IntList))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_v_self->fid2symid); + __Pyx_DECREF(((PyObject *)__pyx_v_self->fid2symid)); + __pyx_v_self->fid2symid = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":370 + * self.eda = edarray + * self.fid2symid = self.set_idmap(self.fda) + * self.eid2symid = self.set_idmap(self.eda) # <<<<<<<<<<<<<< + * self.precompute() + * self.sampler = sampler + */ + __pyx_t_2 = ((PyObject *)__pyx_v_self->eda); + __Pyx_INCREF(__pyx_t_2); + __pyx_t_1 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->set_idmap(__pyx_v_self, ((struct __pyx_obj_3_sa_DataArray *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_3_sa_IntList))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->eid2symid); + __Pyx_DECREF(((PyObject *)__pyx_v_self->eid2symid)); + __pyx_v_self->eid2symid = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":371 + * self.fid2symid = self.set_idmap(self.fda) + * self.eid2symid = self.set_idmap(self.eda) + * self.precompute() # <<<<<<<<<<<<<< + * self.sampler = sampler + * + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__precompute); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":372 + * self.eid2symid = self.set_idmap(self.eda) + * self.precompute() + * self.sampler = sampler # <<<<<<<<<<<<<< + * + * cdef set_idmap(self, DataArray darray): + */ + __Pyx_INCREF(((PyObject *)__pyx_v_sampler)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_sampler)); + __Pyx_GOTREF(__pyx_v_self->sampler); + __Pyx_DECREF(((PyObject *)__pyx_v_self->sampler)); + __pyx_v_self->sampler = __pyx_v_sampler; + + __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("_sa.HieroCachingRuleFactory.configure", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":374 + * self.sampler = sampler + * + * cdef set_idmap(self, DataArray darray): # <<<<<<<<<<<<<< + * cdef int word_id, new_word_id, N + * cdef IntList idmap + */ + +static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_set_idmap(CYTHON_UNUSED struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_3_sa_DataArray *__pyx_v_darray) { + int __pyx_v_word_id; + int __pyx_v_new_word_id; + int __pyx_v_N; + struct __pyx_obj_3_sa_IntList *__pyx_v_idmap = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("set_idmap", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":378 + * cdef IntList idmap + * + * N = len(darray.id2word) # <<<<<<<<<<<<<< + * idmap = IntList(initial_len=N) + * for word_id from 0 <= word_id < N: + */ + __pyx_t_1 = __pyx_v_darray->id2word; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_N = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":379 + * + * N = len(darray.id2word) + * idmap = IntList(initial_len=N) # <<<<<<<<<<<<<< + * for word_id from 0 <= word_id < N: + * new_word_id = sym_fromstring(darray.id2word[word_id], True) + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_3 = PyInt_FromLong(__pyx_v_N); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_v_idmap = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":380 + * N = len(darray.id2word) + * idmap = IntList(initial_len=N) + * for word_id from 0 <= word_id < N: # <<<<<<<<<<<<<< + * new_word_id = sym_fromstring(darray.id2word[word_id], True) + * idmap.arr[word_id] = new_word_id + */ + __pyx_t_4 = __pyx_v_N; + for (__pyx_v_word_id = 0; __pyx_v_word_id < __pyx_t_4; __pyx_v_word_id++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":381 + * idmap = IntList(initial_len=N) + * for word_id from 0 <= word_id < N: + * new_word_id = sym_fromstring(darray.id2word[word_id], True) # <<<<<<<<<<<<<< + * idmap.arr[word_id] = new_word_id + * return idmap + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_fromstring); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_darray->id2word, __pyx_v_word_id, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_1 = 0; + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __pyx_t_7 = __Pyx_PyInt_AsInt(__pyx_t_5); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 381; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_new_word_id = __pyx_t_7; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":382 + * for word_id from 0 <= word_id < N: + * new_word_id = sym_fromstring(darray.id2word[word_id], True) + * idmap.arr[word_id] = new_word_id # <<<<<<<<<<<<<< + * return idmap + * + */ + (__pyx_v_idmap->arr[__pyx_v_word_id]) = __pyx_v_new_word_id; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":383 + * new_word_id = sym_fromstring(darray.id2word[word_id], True) + * idmap.arr[word_id] = new_word_id + * return idmap # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_idmap)); + __pyx_r = ((PyObject *)__pyx_v_idmap); + 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_3); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.set_idmap", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_idmap); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_5pattern2phrase(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern); /*proto*/ +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_5pattern2phrase(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("pattern2phrase (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_23HieroCachingRuleFactory_4pattern2phrase(((struct __pyx_obj_3_sa_HieroCachingRuleFactory *)__pyx_v_self), ((PyObject *)__pyx_v_pattern)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":386 + * + * + * def pattern2phrase(self, pattern): # <<<<<<<<<<<<<< + * # pattern is a tuple, which we must convert to a hiero Phrase + * result = () + */ + +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_4pattern2phrase(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_pattern) { + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_v_arity = NULL; + PyObject *__pyx_v_word_id = NULL; + PyObject *__pyx_v_new_id = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("pattern2phrase", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":388 + * def pattern2phrase(self, pattern): + * # pattern is a tuple, which we must convert to a hiero Phrase + * result = () # <<<<<<<<<<<<<< + * arity = 0 + * for word_id in pattern: + */ + __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); + __pyx_v_result = __pyx_empty_tuple; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":389 + * # pattern is a tuple, which we must convert to a hiero Phrase + * result = () + * arity = 0 # <<<<<<<<<<<<<< + * for word_id in pattern: + * if word_id == -1: + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_arity = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":390 + * result = () + * arity = 0 + * for word_id in pattern: # <<<<<<<<<<<<<< + * if word_id == -1: + * arity = arity + 1 + */ + if (PyList_CheckExact(__pyx_v_pattern) || PyTuple_CheckExact(__pyx_v_pattern)) { + __pyx_t_1 = __pyx_v_pattern; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_pattern); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_word_id); + __pyx_v_word_id = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":391 + * arity = 0 + * for word_id in pattern: + * if word_id == -1: # <<<<<<<<<<<<<< + * arity = arity + 1 + * new_id = sym_setindex(self.category, arity) + */ + __pyx_t_4 = PyObject_RichCompare(__pyx_v_word_id, __pyx_int_neg_1, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":392 + * for word_id in pattern: + * if word_id == -1: + * arity = arity + 1 # <<<<<<<<<<<<<< + * new_id = sym_setindex(self.category, arity) + * else: + */ + __pyx_t_4 = PyNumber_Add(__pyx_v_arity, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_v_arity); + __pyx_v_arity = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":393 + * if word_id == -1: + * arity = arity + 1 + * new_id = sym_setindex(self.category, arity) # <<<<<<<<<<<<<< + * else: + * new_id = sym_fromstring(self.fda.id2word[word_id], True) + */ + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_arity); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(__pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_t_6)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_v_new_id); + __pyx_v_new_id = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":395 + * new_id = sym_setindex(self.category, arity) + * else: + * new_id = sym_fromstring(self.fda.id2word[word_id], True) # <<<<<<<<<<<<<< + * result = result + (new_id,) + * return Phrase(result) + */ + __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_fromstring); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = PyObject_GetItem(__pyx_v_self->fda->id2word, __pyx_v_word_id); if (!__pyx_t_7) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_7 = 0; + __pyx_t_8 = 0; + __pyx_t_8 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_v_new_id); + __pyx_v_new_id = __pyx_t_8; + __pyx_t_8 = 0; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":396 + * else: + * new_id = sym_fromstring(self.fda.id2word[word_id], True) + * result = result + (new_id,) # <<<<<<<<<<<<<< + * return Phrase(result) + * + */ + __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(__pyx_v_new_id); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_new_id); + __Pyx_GIVEREF(__pyx_v_new_id); + __pyx_t_9 = PyNumber_Add(((PyObject *)__pyx_v_result), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_result)); + __pyx_v_result = __pyx_t_9; + __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":397 + * new_id = sym_fromstring(self.fda.id2word[word_id], True) + * result = result + (new_id,) + * return Phrase(result) # <<<<<<<<<<<<<< + * + * def pattern2phrase_plus(self, pattern): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_result)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_result)); + __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_Phrase)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_r = __pyx_t_9; + __pyx_t_9 = 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_4); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.pattern2phrase", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_arity); + __Pyx_XDECREF(__pyx_v_word_id); + __Pyx_XDECREF(__pyx_v_new_id); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_7pattern2phrase_plus(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern); /*proto*/ +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_7pattern2phrase_plus(PyObject *__pyx_v_self, PyObject *__pyx_v_pattern) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("pattern2phrase_plus (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_23HieroCachingRuleFactory_6pattern2phrase_plus(((struct __pyx_obj_3_sa_HieroCachingRuleFactory *)__pyx_v_self), ((PyObject *)__pyx_v_pattern)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":399 + * return Phrase(result) + * + * def pattern2phrase_plus(self, pattern): # <<<<<<<<<<<<<< + * # returns a list containing both the pattern, and pattern + * # suffixed/prefixed with the NT category. + */ + +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_6pattern2phrase_plus(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_pattern) { + PyObject *__pyx_v_patterns = NULL; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_v_arity = NULL; + PyObject *__pyx_v_word_id = NULL; + PyObject *__pyx_v_new_id = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + int __pyx_t_10; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("pattern2phrase_plus", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":402 + * # returns a list containing both the pattern, and pattern + * # suffixed/prefixed with the NT category. + * patterns = [] # <<<<<<<<<<<<<< + * result = () + * arity = 0 + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_patterns = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":403 + * # suffixed/prefixed with the NT category. + * patterns = [] + * result = () # <<<<<<<<<<<<<< + * arity = 0 + * for word_id in pattern: + */ + __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); + __pyx_v_result = __pyx_empty_tuple; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":404 + * patterns = [] + * result = () + * arity = 0 # <<<<<<<<<<<<<< + * for word_id in pattern: + * if word_id == -1: + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_arity = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":405 + * result = () + * arity = 0 + * for word_id in pattern: # <<<<<<<<<<<<<< + * if word_id == -1: + * arity = arity + 1 + */ + if (PyList_CheckExact(__pyx_v_pattern) || PyTuple_CheckExact(__pyx_v_pattern)) { + __pyx_t_1 = __pyx_v_pattern; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_pattern); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_word_id); + __pyx_v_word_id = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":406 + * arity = 0 + * for word_id in pattern: + * if word_id == -1: # <<<<<<<<<<<<<< + * arity = arity + 1 + * new_id = sym_setindex(self.category, arity) + */ + __pyx_t_4 = PyObject_RichCompare(__pyx_v_word_id, __pyx_int_neg_1, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":407 + * for word_id in pattern: + * if word_id == -1: + * arity = arity + 1 # <<<<<<<<<<<<<< + * new_id = sym_setindex(self.category, arity) + * else: + */ + __pyx_t_4 = PyNumber_Add(__pyx_v_arity, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_v_arity); + __pyx_v_arity = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":408 + * if word_id == -1: + * arity = arity + 1 + * new_id = sym_setindex(self.category, arity) # <<<<<<<<<<<<<< + * else: + * new_id = sym_fromstring(self.fda.id2word[word_id], True) + */ + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_v_arity); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(__pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_t_6)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_v_new_id); + __pyx_v_new_id = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":410 + * new_id = sym_setindex(self.category, arity) + * else: + * new_id = sym_fromstring(self.fda.id2word[word_id], True) # <<<<<<<<<<<<<< + * result = result + (new_id,) + * patterns.append(Phrase(result)) + */ + __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__sym_fromstring); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = PyObject_GetItem(__pyx_v_self->fda->id2word, __pyx_v_word_id); if (!__pyx_t_7) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_7 = 0; + __pyx_t_8 = 0; + __pyx_t_8 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_v_new_id); + __pyx_v_new_id = __pyx_t_8; + __pyx_t_8 = 0; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":411 + * else: + * new_id = sym_fromstring(self.fda.id2word[word_id], True) + * result = result + (new_id,) # <<<<<<<<<<<<<< + * patterns.append(Phrase(result)) + * patterns.append(Phrase(result + (sym_setindex(self.category, 1),))) + */ + __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 411; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(__pyx_v_new_id); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_new_id); + __Pyx_GIVEREF(__pyx_v_new_id); + __pyx_t_9 = PyNumber_Add(((PyObject *)__pyx_v_result), ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 411; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_result)); + __pyx_v_result = __pyx_t_9; + __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":412 + * new_id = sym_fromstring(self.fda.id2word[word_id], True) + * result = result + (new_id,) + * patterns.append(Phrase(result)) # <<<<<<<<<<<<<< + * patterns.append(Phrase(result + (sym_setindex(self.category, 1),))) + * patterns.append(Phrase((sym_setindex(self.category, 1),) + result)) + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_result)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_result)); + __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_Phrase)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_10 = PyList_Append(__pyx_v_patterns, __pyx_t_9); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":413 + * result = result + (new_id,) + * patterns.append(Phrase(result)) + * patterns.append(Phrase(result + (sym_setindex(self.category, 1),))) # <<<<<<<<<<<<<< + * patterns.append(Phrase((sym_setindex(self.category, 1),) + result)) + * return patterns + */ + __pyx_t_9 = PyInt_FromLong(__pyx_f_3_sa_sym_setindex(__pyx_v_self->category, 1)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_9 = PyNumber_Add(((PyObject *)__pyx_v_result), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __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[8]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_9)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); + __pyx_t_9 = 0; + __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_Phrase)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_10 = PyList_Append(__pyx_v_patterns, __pyx_t_9); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 413; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":414 + * patterns.append(Phrase(result)) + * patterns.append(Phrase(result + (sym_setindex(self.category, 1),))) + * patterns.append(Phrase((sym_setindex(self.category, 1),) + result)) # <<<<<<<<<<<<<< + * return patterns + * + */ + __pyx_t_9 = PyInt_FromLong(__pyx_f_3_sa_sym_setindex(__pyx_v_self->category, 1)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_9 = PyNumber_Add(((PyObject *)__pyx_t_1), ((PyObject *)__pyx_v_result)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __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[8]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_9)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); + __pyx_t_9 = 0; + __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_Phrase)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_10 = PyList_Append(__pyx_v_patterns, __pyx_t_9); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":415 + * patterns.append(Phrase(result + (sym_setindex(self.category, 1),))) + * patterns.append(Phrase((sym_setindex(self.category, 1),) + result)) + * return patterns # <<<<<<<<<<<<<< + * + * def precompute(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_patterns)); + __pyx_r = ((PyObject *)__pyx_v_patterns); + 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_4); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.pattern2phrase_plus", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_patterns); + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_arity); + __Pyx_XDECREF(__pyx_v_word_id); + __Pyx_XDECREF(__pyx_v_new_id); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_9precompute(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_9precompute(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("precompute (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_23HieroCachingRuleFactory_8precompute(((struct __pyx_obj_3_sa_HieroCachingRuleFactory *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":417 + * return patterns + * + * def precompute(self): # <<<<<<<<<<<<<< + * cdef Precomputation pre + * + */ + +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_8precompute(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self) { + struct __pyx_obj_3_sa_Precomputation *__pyx_v_pre = 0; + PyObject *__pyx_v_start_time = NULL; + PyObject *__pyx_v_pattern = NULL; + PyObject *__pyx_v_arr = NULL; + PyObject *__pyx_v_phrases = NULL; + PyObject *__pyx_v_phrase = NULL; + PyObject *__pyx_v_stop_time = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + Py_ssize_t __pyx_t_6; + Py_ssize_t __pyx_t_7; + int __pyx_t_8; + int __pyx_t_9; + Py_ssize_t __pyx_t_10; + PyObject *(*__pyx_t_11)(PyObject *); + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("precompute", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":420 + * cdef Precomputation pre + * + * if self.precompute_file is not None: # <<<<<<<<<<<<<< + * start_time = monitor_cpu() + * logger.info("Reading precomputed data from file %s... ", self.precompute_file) + */ + __pyx_t_1 = (__pyx_v_self->precompute_file != Py_None); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":421 + * + * if self.precompute_file is not None: + * start_time = monitor_cpu() # <<<<<<<<<<<<<< + * logger.info("Reading precomputed data from file %s... ", self.precompute_file) + * pre = Precomputation(from_binary=self.precompute_file) + */ + __pyx_t_2 = PyFloat_FromDouble(__pyx_f_3_sa_monitor_cpu()); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 421; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_start_time = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":422 + * if self.precompute_file is not None: + * start_time = monitor_cpu() + * logger.info("Reading precomputed data from file %s... ", self.precompute_file) # <<<<<<<<<<<<<< + * pre = Precomputation(from_binary=self.precompute_file) + * # check parameters of precomputation -- some are critical and some are not + */ + __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__info); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_106)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_106)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_106)); + __Pyx_INCREF(__pyx_v_self->precompute_file); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_self->precompute_file); + __Pyx_GIVEREF(__pyx_v_self->precompute_file); + __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":423 + * start_time = monitor_cpu() + * logger.info("Reading precomputed data from file %s... ", self.precompute_file) + * pre = Precomputation(from_binary=self.precompute_file) # <<<<<<<<<<<<<< + * # check parameters of precomputation -- some are critical and some are not + * if pre.max_nonterminals != self.max_nonterminals: + */ + __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__from_binary), __pyx_v_self->precompute_file) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_Precomputation)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_v_pre = ((struct __pyx_obj_3_sa_Precomputation *)__pyx_t_2); + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":425 + * pre = Precomputation(from_binary=self.precompute_file) + * # check parameters of precomputation -- some are critical and some are not + * if pre.max_nonterminals != self.max_nonterminals: # <<<<<<<<<<<<<< + * logger.warn("Precomputation done with max nonterminals %d, decoder uses %d", pre.max_nonterminals, self.max_nonterminals) + * if pre.max_length != self.max_length: + */ + __pyx_t_1 = (__pyx_v_pre->max_nonterminals != __pyx_v_self->max_nonterminals); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":426 + * # check parameters of precomputation -- some are critical and some are not + * if pre.max_nonterminals != self.max_nonterminals: + * logger.warn("Precomputation done with max nonterminals %d, decoder uses %d", pre.max_nonterminals, self.max_nonterminals) # <<<<<<<<<<<<<< + * if pre.max_length != self.max_length: + * logger.warn("Precomputation done with max terminals %d, decoder uses %d", pre.max_length, self.max_length) + */ + __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__warn); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyInt_FromLong(__pyx_v_pre->max_nonterminals); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyInt_FromLong(__pyx_v_self->max_nonterminals); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_107)); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_107)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_107)); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":427 + * if pre.max_nonterminals != self.max_nonterminals: + * logger.warn("Precomputation done with max nonterminals %d, decoder uses %d", pre.max_nonterminals, self.max_nonterminals) + * if pre.max_length != self.max_length: # <<<<<<<<<<<<<< + * logger.warn("Precomputation done with max terminals %d, decoder uses %d", pre.max_length, self.max_length) + * if pre.train_max_initial_size != self.train_max_initial_size: + */ + __pyx_t_1 = (__pyx_v_pre->max_length != __pyx_v_self->max_length); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":428 + * logger.warn("Precomputation done with max nonterminals %d, decoder uses %d", pre.max_nonterminals, self.max_nonterminals) + * if pre.max_length != self.max_length: + * logger.warn("Precomputation done with max terminals %d, decoder uses %d", pre.max_length, self.max_length) # <<<<<<<<<<<<<< + * if pre.train_max_initial_size != self.train_max_initial_size: + * raise Exception("Precomputation done with max initial size %d, decoder uses %d" % (pre.train_max_initial_size, self.train_max_initial_size)) + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__warn); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromLong(__pyx_v_pre->max_length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyInt_FromLong(__pyx_v_self->max_length); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_108)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_108)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_108)); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_3 = 0; + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":429 + * if pre.max_length != self.max_length: + * logger.warn("Precomputation done with max terminals %d, decoder uses %d", pre.max_length, self.max_length) + * if pre.train_max_initial_size != self.train_max_initial_size: # <<<<<<<<<<<<<< + * raise Exception("Precomputation done with max initial size %d, decoder uses %d" % (pre.train_max_initial_size, self.train_max_initial_size)) + * if pre.train_min_gap_size != self.train_min_gap_size: + */ + __pyx_t_1 = (__pyx_v_pre->train_max_initial_size != __pyx_v_self->train_max_initial_size); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":430 + * logger.warn("Precomputation done with max terminals %d, decoder uses %d", pre.max_length, self.max_length) + * if pre.train_max_initial_size != self.train_max_initial_size: + * raise Exception("Precomputation done with max initial size %d, decoder uses %d" % (pre.train_max_initial_size, self.train_max_initial_size)) # <<<<<<<<<<<<<< + * if pre.train_min_gap_size != self.train_min_gap_size: + * raise Exception("Precomputation done with min gap size %d, decoder uses %d" % (pre.train_min_gap_size, self.train_min_gap_size)) + */ + __pyx_t_4 = PyInt_FromLong(__pyx_v_pre->train_max_initial_size); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyInt_FromLong(__pyx_v_self->train_max_initial_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_4 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_109), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":431 + * if pre.train_max_initial_size != self.train_max_initial_size: + * raise Exception("Precomputation done with max initial size %d, decoder uses %d" % (pre.train_max_initial_size, self.train_max_initial_size)) + * if pre.train_min_gap_size != self.train_min_gap_size: # <<<<<<<<<<<<<< + * raise Exception("Precomputation done with min gap size %d, decoder uses %d" % (pre.train_min_gap_size, self.train_min_gap_size)) + * if self.use_index: + */ + __pyx_t_1 = (__pyx_v_pre->train_min_gap_size != __pyx_v_self->train_min_gap_size); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":432 + * raise Exception("Precomputation done with max initial size %d, decoder uses %d" % (pre.train_max_initial_size, self.train_max_initial_size)) + * if pre.train_min_gap_size != self.train_min_gap_size: + * raise Exception("Precomputation done with min gap size %d, decoder uses %d" % (pre.train_min_gap_size, self.train_min_gap_size)) # <<<<<<<<<<<<<< + * if self.use_index: + * logger.info("Converting %d hash keys on precomputed inverted index... ", len(pre.precomputed_index)) + */ + __pyx_t_2 = PyInt_FromLong(__pyx_v_pre->train_min_gap_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = PyInt_FromLong(__pyx_v_self->train_min_gap_size); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_2 = 0; + __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_110), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_5)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_5, 0, 0, 0); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L7; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":433 + * if pre.train_min_gap_size != self.train_min_gap_size: + * raise Exception("Precomputation done with min gap size %d, decoder uses %d" % (pre.train_min_gap_size, self.train_min_gap_size)) + * if self.use_index: # <<<<<<<<<<<<<< + * logger.info("Converting %d hash keys on precomputed inverted index... ", len(pre.precomputed_index)) + * for pattern, arr in pre.precomputed_index.iteritems(): + */ + if (__pyx_v_self->use_index) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":434 + * raise Exception("Precomputation done with min gap size %d, decoder uses %d" % (pre.train_min_gap_size, self.train_min_gap_size)) + * if self.use_index: + * logger.info("Converting %d hash keys on precomputed inverted index... ", len(pre.precomputed_index)) # <<<<<<<<<<<<<< + * for pattern, arr in pre.precomputed_index.iteritems(): + * phrases = self.pattern2phrase_plus(pattern) + */ + __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__info); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __pyx_v_pre->precomputed_index; + __Pyx_INCREF(__pyx_t_5); + __pyx_t_6 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_111)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_111)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_111)); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":435 + * if self.use_index: + * logger.info("Converting %d hash keys on precomputed inverted index... ", len(pre.precomputed_index)) + * for pattern, arr in pre.precomputed_index.iteritems(): # <<<<<<<<<<<<<< + * phrases = self.pattern2phrase_plus(pattern) + * for phrase in phrases: + */ + __pyx_t_6 = 0; + if (unlikely(__pyx_v_pre->precomputed_index == Py_None)) { + PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "iteritems"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_2 = __Pyx_dict_iterator(__pyx_v_pre->precomputed_index, 0, ((PyObject *)__pyx_n_s__iteritems), (&__pyx_t_7), (&__pyx_t_8)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_5); + __pyx_t_5 = __pyx_t_2; + __pyx_t_2 = 0; + while (1) { + __pyx_t_9 = __Pyx_dict_iter_next(__pyx_t_5, __pyx_t_7, &__pyx_t_6, &__pyx_t_2, &__pyx_t_4, NULL, __pyx_t_8); + if (unlikely(__pyx_t_9 == 0)) break; + if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_v_pattern); + __pyx_v_pattern = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_v_arr); + __pyx_v_arr = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":436 + * logger.info("Converting %d hash keys on precomputed inverted index... ", len(pre.precomputed_index)) + * for pattern, arr in pre.precomputed_index.iteritems(): + * phrases = self.pattern2phrase_plus(pattern) # <<<<<<<<<<<<<< + * for phrase in phrases: + * self.precomputed_index[phrase] = arr + */ + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__pattern2phrase_plus); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_pattern); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_pattern); + __Pyx_GIVEREF(__pyx_v_pattern); + __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 436; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_v_phrases); + __pyx_v_phrases = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":437 + * for pattern, arr in pre.precomputed_index.iteritems(): + * phrases = self.pattern2phrase_plus(pattern) + * for phrase in phrases: # <<<<<<<<<<<<<< + * self.precomputed_index[phrase] = arr + * if self.use_collocations: + */ + if (PyList_CheckExact(__pyx_v_phrases) || PyTuple_CheckExact(__pyx_v_phrases)) { + __pyx_t_3 = __pyx_v_phrases; __Pyx_INCREF(__pyx_t_3); __pyx_t_10 = 0; + __pyx_t_11 = NULL; + } else { + __pyx_t_10 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_phrases); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_11 = Py_TYPE(__pyx_t_3)->tp_iternext; + } + for (;;) { + if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_3)) { + if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_10); __Pyx_INCREF(__pyx_t_2); __pyx_t_10++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_3)) { + if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_10); __Pyx_INCREF(__pyx_t_2); __pyx_t_10++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_2 = __pyx_t_11(__pyx_t_3); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF(__pyx_v_phrase); + __pyx_v_phrase = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":438 + * phrases = self.pattern2phrase_plus(pattern) + * for phrase in phrases: + * self.precomputed_index[phrase] = arr # <<<<<<<<<<<<<< + * if self.use_collocations: + * logger.info("Converting %d hash keys on precomputed collocations... ", len(pre.precomputed_collocations)) + */ + if (PyObject_SetItem(__pyx_v_self->precomputed_index, __pyx_v_phrase, __pyx_v_arr) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 438; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L8; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":439 + * for phrase in phrases: + * self.precomputed_index[phrase] = arr + * if self.use_collocations: # <<<<<<<<<<<<<< + * logger.info("Converting %d hash keys on precomputed collocations... ", len(pre.precomputed_collocations)) + * for pattern, arr in pre.precomputed_collocations.iteritems(): + */ + if (__pyx_v_self->use_collocations) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":440 + * self.precomputed_index[phrase] = arr + * if self.use_collocations: + * logger.info("Converting %d hash keys on precomputed collocations... ", len(pre.precomputed_collocations)) # <<<<<<<<<<<<<< + * for pattern, arr in pre.precomputed_collocations.iteritems(): + * phrase = self.pattern2phrase(pattern) + */ + __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__info); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __pyx_v_pre->precomputed_collocations; + __Pyx_INCREF(__pyx_t_5); + __pyx_t_7 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_7); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_112)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_112)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_112)); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":441 + * if self.use_collocations: + * logger.info("Converting %d hash keys on precomputed collocations... ", len(pre.precomputed_collocations)) + * for pattern, arr in pre.precomputed_collocations.iteritems(): # <<<<<<<<<<<<<< + * phrase = self.pattern2phrase(pattern) + * self.precomputed_collocations[phrase] = arr + */ + __pyx_t_7 = 0; + if (unlikely(__pyx_v_pre->precomputed_collocations == Py_None)) { + PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "iteritems"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_2 = __Pyx_dict_iterator(__pyx_v_pre->precomputed_collocations, 0, ((PyObject *)__pyx_n_s__iteritems), (&__pyx_t_6), (&__pyx_t_8)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_5); + __pyx_t_5 = __pyx_t_2; + __pyx_t_2 = 0; + while (1) { + __pyx_t_9 = __Pyx_dict_iter_next(__pyx_t_5, __pyx_t_6, &__pyx_t_7, &__pyx_t_2, &__pyx_t_3, NULL, __pyx_t_8); + if (unlikely(__pyx_t_9 == 0)) break; + if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 441; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_v_pattern); + __pyx_v_pattern = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_v_arr); + __pyx_v_arr = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":442 + * logger.info("Converting %d hash keys on precomputed collocations... ", len(pre.precomputed_collocations)) + * for pattern, arr in pre.precomputed_collocations.iteritems(): + * phrase = self.pattern2phrase(pattern) # <<<<<<<<<<<<<< + * self.precomputed_collocations[phrase] = arr + * stop_time = monitor_cpu() + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__pattern2phrase); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_pattern); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_pattern); + __Pyx_GIVEREF(__pyx_v_pattern); + __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 442; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_v_phrase); + __pyx_v_phrase = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":443 + * for pattern, arr in pre.precomputed_collocations.iteritems(): + * phrase = self.pattern2phrase(pattern) + * self.precomputed_collocations[phrase] = arr # <<<<<<<<<<<<<< + * stop_time = monitor_cpu() + * logger.info("Processing precomputations took %f seconds", stop_time - start_time) + */ + if (PyObject_SetItem(__pyx_v_self->precomputed_collocations, __pyx_v_phrase, __pyx_v_arr) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 443; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L13; + } + __pyx_L13:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":444 + * phrase = self.pattern2phrase(pattern) + * self.precomputed_collocations[phrase] = arr + * stop_time = monitor_cpu() # <<<<<<<<<<<<<< + * logger.info("Processing precomputations took %f seconds", stop_time - start_time) + * + */ + __pyx_t_5 = PyFloat_FromDouble(__pyx_f_3_sa_monitor_cpu()); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_v_stop_time = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":445 + * self.precomputed_collocations[phrase] = arr + * stop_time = monitor_cpu() + * logger.info("Processing precomputations took %f seconds", stop_time - start_time) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__info); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Subtract(__pyx_v_stop_time, __pyx_v_start_time); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_113)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_113)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_113)); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.precompute", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_pre); + __Pyx_XDECREF(__pyx_v_start_time); + __Pyx_XDECREF(__pyx_v_pattern); + __Pyx_XDECREF(__pyx_v_arr); + __Pyx_XDECREF(__pyx_v_phrases); + __Pyx_XDECREF(__pyx_v_phrase); + __Pyx_XDECREF(__pyx_v_stop_time); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_11get_precomputed_collocation(PyObject *__pyx_v_self, PyObject *__pyx_v_phrase); /*proto*/ +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_11get_precomputed_collocation(PyObject *__pyx_v_self, PyObject *__pyx_v_phrase) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_precomputed_collocation (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_23HieroCachingRuleFactory_10get_precomputed_collocation(((struct __pyx_obj_3_sa_HieroCachingRuleFactory *)__pyx_v_self), ((PyObject *)__pyx_v_phrase)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":448 + * + * + * def get_precomputed_collocation(self, phrase): # <<<<<<<<<<<<<< + * if phrase in self.precomputed_collocations: + * arr = self.precomputed_collocations[phrase] + */ + +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_10get_precomputed_collocation(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_phrase) { + PyObject *__pyx_v_arr = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_precomputed_collocation", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":449 + * + * def get_precomputed_collocation(self, phrase): + * if phrase in self.precomputed_collocations: # <<<<<<<<<<<<<< + * arr = self.precomputed_collocations[phrase] + * return PhraseLocation(arr=arr, arr_low=0, arr_high=len(arr), num_subpatterns=phrase.arity()+1) + */ + __pyx_t_1 = ((PySequence_Contains(__pyx_v_self->precomputed_collocations, __pyx_v_phrase))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":450 + * def get_precomputed_collocation(self, phrase): + * if phrase in self.precomputed_collocations: + * arr = self.precomputed_collocations[phrase] # <<<<<<<<<<<<<< + * return PhraseLocation(arr=arr, arr_low=0, arr_high=len(arr), num_subpatterns=phrase.arity()+1) + * return None + */ + __pyx_t_2 = PyObject_GetItem(__pyx_v_self->precomputed_collocations, __pyx_v_phrase); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_arr = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":451 + * if phrase in self.precomputed_collocations: + * arr = self.precomputed_collocations[phrase] + * return PhraseLocation(arr=arr, arr_low=0, arr_high=len(arr), num_subpatterns=phrase.arity()+1) # <<<<<<<<<<<<<< + * return None + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__arr), __pyx_v_arr) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__arr_low), __pyx_int_0) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Length(__pyx_v_arr); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__arr_high), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyObject_GetAttr(__pyx_v_phrase, __pyx_n_s__arity); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyNumber_Add(__pyx_t_5, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__num_subpatterns), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_PhraseLocation)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 451; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":452 + * arr = self.precomputed_collocations[phrase] + * return PhraseLocation(arr=arr, arr_low=0, arr_high=len(arr), num_subpatterns=phrase.arity()+1) + * return None # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_None); + __pyx_r = Py_None; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.get_precomputed_collocation", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_arr); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":455 + * + * + * cdef int* baeza_yates_helper(self, int low1, int high1, int* arr1, int step1, # <<<<<<<<<<<<<< + * int low2, int high2, int* arr2, int step2, + * int offset_by_one, int len_last, int num_subpatterns, int* result_len): + */ + +static int *__pyx_f_3_sa_23HieroCachingRuleFactory_baeza_yates_helper(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, int __pyx_v_low1, int __pyx_v_high1, int *__pyx_v_arr1, int __pyx_v_step1, int __pyx_v_low2, int __pyx_v_high2, int *__pyx_v_arr2, int __pyx_v_step2, int __pyx_v_offset_by_one, int __pyx_v_len_last, int __pyx_v_num_subpatterns, int *__pyx_v_result_len) { + int __pyx_v_i1; + int __pyx_v_i2; + int __pyx_v_med1; + int __pyx_v_med2; + int __pyx_v_med1_plus; + int __pyx_v_med1_minus; + int __pyx_v_med2_minus; + int __pyx_v_med2_plus; + int __pyx_v_d_first; + int __pyx_v_qsetsize; + int __pyx_v_dsetsize; + int __pyx_v_tmp; + int __pyx_v_search_low; + int __pyx_v_search_high; + int __pyx_v_med_result_len; + int __pyx_v_low_result_len; + int __pyx_v_high_result_len; + long __pyx_v_comparison; + int *__pyx_v_result; + int *__pyx_v_low_result; + int *__pyx_v_med_result; + int *__pyx_v_high_result; + struct __pyx_t_3_sa_Matching __pyx_v_loc1; + struct __pyx_t_3_sa_Matching __pyx_v_loc2; + int *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + double __pyx_t_5; + double __pyx_t_6; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("baeza_yates_helper", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":468 + * cdef Matching loc1, loc2 + * + * result = malloc(0*sizeof(int*)) # <<<<<<<<<<<<<< + * + * d_first = 0 + */ + __pyx_v_result = ((int *)malloc((0 * (sizeof(int *))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":470 + * result = malloc(0*sizeof(int*)) + * + * d_first = 0 # <<<<<<<<<<<<<< + * if high1 - low1 > high2 - low2: + * d_first = 1 + */ + __pyx_v_d_first = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":471 + * + * d_first = 0 + * if high1 - low1 > high2 - low2: # <<<<<<<<<<<<<< + * d_first = 1 + * + */ + __pyx_t_1 = ((__pyx_v_high1 - __pyx_v_low1) > (__pyx_v_high2 - __pyx_v_low2)); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":472 + * d_first = 0 + * if high1 - low1 > high2 - low2: + * d_first = 1 # <<<<<<<<<<<<<< + * + * # First, check to see if we are at any of the recursive base cases + */ + __pyx_v_d_first = 1; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":476 + * # First, check to see if we are at any of the recursive base cases + * # Case 1: one of the sets is empty + * if low1 >= high1 or low2 >= high2: # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_t_1 = (__pyx_v_low1 >= __pyx_v_high1); + if (!__pyx_t_1) { + __pyx_t_2 = (__pyx_v_low2 >= __pyx_v_high2); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":477 + * # Case 1: one of the sets is empty + * if low1 >= high1 or low2 >= high2: + * return result # <<<<<<<<<<<<<< + * + * # Case 2: sets are non-overlapping + */ + __pyx_r = __pyx_v_result; + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":480 + * + * # Case 2: sets are non-overlapping + * assign_matching(&loc1, arr1, high1-step1, step1, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * assign_matching(&loc2, arr2, low2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == -1: + */ + __pyx_f_3_sa_assign_matching((&__pyx_v_loc1), __pyx_v_arr1, (__pyx_v_high1 - __pyx_v_step1), __pyx_v_step1, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":481 + * # Case 2: sets are non-overlapping + * assign_matching(&loc1, arr1, high1-step1, step1, self.fda.sent_id.arr) + * assign_matching(&loc2, arr2, low2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == -1: + * return result + */ + __pyx_f_3_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, __pyx_v_low2, __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":482 + * assign_matching(&loc1, arr1, high1-step1, step1, self.fda.sent_id.arr) + * assign_matching(&loc2, arr2, low2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == -1: # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_t_3 = (((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last) == -1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":483 + * assign_matching(&loc2, arr2, low2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == -1: + * return result # <<<<<<<<<<<<<< + * + * assign_matching(&loc1, arr1, low1, step1, self.fda.sent_id.arr) + */ + __pyx_r = __pyx_v_result; + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":485 + * return result + * + * assign_matching(&loc1, arr1, low1, step1, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * assign_matching(&loc2, arr2, high2-step2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: + */ + __pyx_f_3_sa_assign_matching((&__pyx_v_loc1), __pyx_v_arr1, __pyx_v_low1, __pyx_v_step1, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":486 + * + * assign_matching(&loc1, arr1, low1, step1, self.fda.sent_id.arr) + * assign_matching(&loc2, arr2, high2-step2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: + * return result + */ + __pyx_f_3_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, (__pyx_v_high2 - __pyx_v_step2), __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":487 + * assign_matching(&loc1, arr1, low1, step1, self.fda.sent_id.arr) + * assign_matching(&loc2, arr2, high2-step2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_t_3 = (((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last) == 1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":488 + * assign_matching(&loc2, arr2, high2-step2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: + * return result # <<<<<<<<<<<<<< + * + * # Case 3: query set and data set do not meet size mismatch constraints; + */ + __pyx_r = __pyx_v_result; + goto __pyx_L0; + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":492 + * # Case 3: query set and data set do not meet size mismatch constraints; + * # We use mergesort instead in this case + * qsetsize = (high1-low1) / step1 # <<<<<<<<<<<<<< + * dsetsize = (high2-low2) / step2 + * if d_first: + */ + __pyx_t_4 = (__pyx_v_high1 - __pyx_v_low1); + if (unlikely(__pyx_v_step1 == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_step1 == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_4))) { + PyErr_Format(PyExc_OverflowError, "value too large to perform division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_qsetsize = __Pyx_div_int(__pyx_t_4, __pyx_v_step1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":493 + * # We use mergesort instead in this case + * qsetsize = (high1-low1) / step1 + * dsetsize = (high2-low2) / step2 # <<<<<<<<<<<<<< + * if d_first: + * tmp = qsetsize + */ + __pyx_t_4 = (__pyx_v_high2 - __pyx_v_low2); + if (unlikely(__pyx_v_step2 == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 493; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_step2 == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_4))) { + PyErr_Format(PyExc_OverflowError, "value too large to perform division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 493; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_dsetsize = __Pyx_div_int(__pyx_t_4, __pyx_v_step2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":494 + * qsetsize = (high1-low1) / step1 + * dsetsize = (high2-low2) / step2 + * if d_first: # <<<<<<<<<<<<<< + * tmp = qsetsize + * qsetsize = dsetsize + */ + if (__pyx_v_d_first) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":495 + * dsetsize = (high2-low2) / step2 + * if d_first: + * tmp = qsetsize # <<<<<<<<<<<<<< + * qsetsize = dsetsize + * dsetsize = tmp + */ + __pyx_v_tmp = __pyx_v_qsetsize; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":496 + * if d_first: + * tmp = qsetsize + * qsetsize = dsetsize # <<<<<<<<<<<<<< + * dsetsize = tmp + * + */ + __pyx_v_qsetsize = __pyx_v_dsetsize; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":497 + * tmp = qsetsize + * qsetsize = dsetsize + * dsetsize = tmp # <<<<<<<<<<<<<< + * + * if self.by_slack_factor * qsetsize * log(dsetsize) / log(2) > dsetsize: + */ + __pyx_v_dsetsize = __pyx_v_tmp; + goto __pyx_L7; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":499 + * dsetsize = tmp + * + * if self.by_slack_factor * qsetsize * log(dsetsize) / log(2) > dsetsize: # <<<<<<<<<<<<<< + * free(result) + * return self.merge_helper(low1, high1, arr1, step1, low2, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, result_len) + */ + __pyx_t_5 = ((__pyx_v_self->by_slack_factor * __pyx_v_qsetsize) * log(__pyx_v_dsetsize)); + __pyx_t_6 = log(2.0); + if (unlikely(__pyx_t_6 == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_3 = ((__pyx_t_5 / __pyx_t_6) > __pyx_v_dsetsize); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":500 + * + * if self.by_slack_factor * qsetsize * log(dsetsize) / log(2) > dsetsize: + * free(result) # <<<<<<<<<<<<<< + * return self.merge_helper(low1, high1, arr1, step1, low2, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, result_len) + * + */ + free(__pyx_v_result); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":501 + * if self.by_slack_factor * qsetsize * log(dsetsize) / log(2) > dsetsize: + * free(result) + * return self.merge_helper(low1, high1, arr1, step1, low2, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, result_len) # <<<<<<<<<<<<<< + * + * # binary search. There are two flavors, depending on + */ + __pyx_r = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->merge_helper(__pyx_v_self, __pyx_v_low1, __pyx_v_high1, __pyx_v_arr1, __pyx_v_step1, __pyx_v_low2, __pyx_v_high2, __pyx_v_arr2, __pyx_v_step2, __pyx_v_offset_by_one, __pyx_v_len_last, __pyx_v_num_subpatterns, __pyx_v_result_len); + goto __pyx_L0; + goto __pyx_L8; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":505 + * # binary search. There are two flavors, depending on + * # whether the queryset or dataset is first + * if d_first: # <<<<<<<<<<<<<< + * med2 = median(low2, high2, step2) + * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) + */ + if (__pyx_v_d_first) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":506 + * # whether the queryset or dataset is first + * if d_first: + * med2 = median(low2, high2, step2) # <<<<<<<<<<<<<< + * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) + * + */ + __pyx_v_med2 = __pyx_f_3_sa_median(__pyx_v_low2, __pyx_v_high2, __pyx_v_step2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":507 + * if d_first: + * med2 = median(low2, high2, step2) + * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * + * search_low = low1 + */ + __pyx_f_3_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, __pyx_v_med2, __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":509 + * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) + * + * search_low = low1 # <<<<<<<<<<<<<< + * search_high = high1 + * while search_low < search_high: + */ + __pyx_v_search_low = __pyx_v_low1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":510 + * + * search_low = low1 + * search_high = high1 # <<<<<<<<<<<<<< + * while search_low < search_high: + * med1 = median(search_low, search_high, step1) + */ + __pyx_v_search_high = __pyx_v_high1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":511 + * search_low = low1 + * search_high = high1 + * while search_low < search_high: # <<<<<<<<<<<<<< + * med1 = median(search_low, search_high, step1) + * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) + */ + while (1) { + __pyx_t_3 = (__pyx_v_search_low < __pyx_v_search_high); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":512 + * search_high = high1 + * while search_low < search_high: + * med1 = median(search_low, search_high, step1) # <<<<<<<<<<<<<< + * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) + */ + __pyx_v_med1 = __pyx_f_3_sa_median(__pyx_v_search_low, __pyx_v_search_high, __pyx_v_step1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":513 + * while search_low < search_high: + * med1 = median(search_low, search_high, step1) + * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) # <<<<<<<<<<<<<< + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) + * if comparison == -1: + */ + __pyx_f_3_sa_find_comparable_matchings(__pyx_v_low1, __pyx_v_high1, __pyx_v_arr1, __pyx_v_step1, __pyx_v_med1, (&__pyx_v_med1_minus), (&__pyx_v_med1_plus)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":514 + * med1 = median(search_low, search_high, step1) + * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) # <<<<<<<<<<<<<< + * if comparison == -1: + * search_low = med1_plus + */ + __pyx_v_comparison = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings_set(__pyx_v_self, __pyx_v_med1_minus, __pyx_v_med1_plus, __pyx_v_arr1, __pyx_v_step1, (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":517 + * if comparison == -1: + * search_low = med1_plus + * elif comparison == 1: # <<<<<<<<<<<<<< + * search_high = med1_minus + * else: + */ + switch (__pyx_v_comparison) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":515 + * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) + * if comparison == -1: # <<<<<<<<<<<<<< + * search_low = med1_plus + * elif comparison == 1: + */ + case -1: + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":516 + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) + * if comparison == -1: + * search_low = med1_plus # <<<<<<<<<<<<<< + * elif comparison == 1: + * search_high = med1_minus + */ + __pyx_v_search_low = __pyx_v_med1_plus; + break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":517 + * if comparison == -1: + * search_low = med1_plus + * elif comparison == 1: # <<<<<<<<<<<<<< + * search_high = med1_minus + * else: + */ + case 1: + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":518 + * search_low = med1_plus + * elif comparison == 1: + * search_high = med1_minus # <<<<<<<<<<<<<< + * else: + * break + */ + __pyx_v_search_high = __pyx_v_med1_minus; + break; + default: + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":520 + * search_high = med1_minus + * else: + * break # <<<<<<<<<<<<<< + * else: + * med1 = median(low1, high1, step1) + */ + goto __pyx_L11_break; + break; + } + } + __pyx_L11_break:; + goto __pyx_L9; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":522 + * break + * else: + * med1 = median(low1, high1, step1) # <<<<<<<<<<<<<< + * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) + * + */ + __pyx_v_med1 = __pyx_f_3_sa_median(__pyx_v_low1, __pyx_v_high1, __pyx_v_step1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":523 + * else: + * med1 = median(low1, high1, step1) + * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) # <<<<<<<<<<<<<< + * + * search_low = low2 + */ + __pyx_f_3_sa_find_comparable_matchings(__pyx_v_low1, __pyx_v_high1, __pyx_v_arr1, __pyx_v_step1, __pyx_v_med1, (&__pyx_v_med1_minus), (&__pyx_v_med1_plus)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":525 + * find_comparable_matchings(low1, high1, arr1, step1, med1, &med1_minus, &med1_plus) + * + * search_low = low2 # <<<<<<<<<<<<<< + * search_high = high2 + * while search_low < search_high: + */ + __pyx_v_search_low = __pyx_v_low2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":526 + * + * search_low = low2 + * search_high = high2 # <<<<<<<<<<<<<< + * while search_low < search_high: + * med2 = median(search_low, search_high, step2) + */ + __pyx_v_search_high = __pyx_v_high2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":527 + * search_low = low2 + * search_high = high2 + * while search_low < search_high: # <<<<<<<<<<<<<< + * med2 = median(search_low, search_high, step2) + * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) + */ + while (1) { + __pyx_t_3 = (__pyx_v_search_low < __pyx_v_search_high); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":528 + * search_high = high2 + * while search_low < search_high: + * med2 = median(search_low, search_high, step2) # <<<<<<<<<<<<<< + * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) + */ + __pyx_v_med2 = __pyx_f_3_sa_median(__pyx_v_search_low, __pyx_v_search_high, __pyx_v_step2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":529 + * while search_low < search_high: + * med2 = median(search_low, search_high, step2) + * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) + * if comparison == -1: + */ + __pyx_f_3_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, __pyx_v_med2, __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":530 + * med2 = median(search_low, search_high, step2) + * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) # <<<<<<<<<<<<<< + * if comparison == -1: + * search_high = med2 + */ + __pyx_v_comparison = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings_set(__pyx_v_self, __pyx_v_med1_minus, __pyx_v_med1_plus, __pyx_v_arr1, __pyx_v_step1, (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":533 + * if comparison == -1: + * search_high = med2 + * elif comparison == 1: # <<<<<<<<<<<<<< + * search_low = med2 + step2 + * else: + */ + switch (__pyx_v_comparison) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":531 + * assign_matching(&loc2, arr2, med2, step2, self.fda.sent_id.arr) + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) + * if comparison == -1: # <<<<<<<<<<<<<< + * search_high = med2 + * elif comparison == 1: + */ + case -1: + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":532 + * comparison = self.compare_matchings_set(med1_minus, med1_plus, arr1, step1, &loc2, offset_by_one, len_last) + * if comparison == -1: + * search_high = med2 # <<<<<<<<<<<<<< + * elif comparison == 1: + * search_low = med2 + step2 + */ + __pyx_v_search_high = __pyx_v_med2; + break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":533 + * if comparison == -1: + * search_high = med2 + * elif comparison == 1: # <<<<<<<<<<<<<< + * search_low = med2 + step2 + * else: + */ + case 1: + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":534 + * search_high = med2 + * elif comparison == 1: + * search_low = med2 + step2 # <<<<<<<<<<<<<< + * else: + * break + */ + __pyx_v_search_low = (__pyx_v_med2 + __pyx_v_step2); + break; + default: + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":536 + * search_low = med2 + step2 + * else: + * break # <<<<<<<<<<<<<< + * + * med_result_len = 0 + */ + goto __pyx_L13_break; + break; + } + } + __pyx_L13_break:; + } + __pyx_L9:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":538 + * break + * + * med_result_len = 0 # <<<<<<<<<<<<<< + * med_result = malloc(0*sizeof(int*)) + * if search_high > search_low: + */ + __pyx_v_med_result_len = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":539 + * + * med_result_len = 0 + * med_result = malloc(0*sizeof(int*)) # <<<<<<<<<<<<<< + * if search_high > search_low: + * # Then there is a match for the median element of Q + */ + __pyx_v_med_result = ((int *)malloc((0 * (sizeof(int *))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":540 + * med_result_len = 0 + * med_result = malloc(0*sizeof(int*)) + * if search_high > search_low: # <<<<<<<<<<<<<< + * # Then there is a match for the median element of Q + * # What we want to find is the group of all bindings in the first set + */ + __pyx_t_3 = (__pyx_v_search_high > __pyx_v_search_low); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":546 + * # want to store the bindings for all of those elements. We can + * # subsequently throw all of them away. + * med2_minus = med2 # <<<<<<<<<<<<<< + * med2_plus = med2 + step2 + * i1 = med1_minus + */ + __pyx_v_med2_minus = __pyx_v_med2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":547 + * # subsequently throw all of them away. + * med2_minus = med2 + * med2_plus = med2 + step2 # <<<<<<<<<<<<<< + * i1 = med1_minus + * while i1 < med1_plus: + */ + __pyx_v_med2_plus = (__pyx_v_med2 + __pyx_v_step2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":548 + * med2_minus = med2 + * med2_plus = med2 + step2 + * i1 = med1_minus # <<<<<<<<<<<<<< + * while i1 < med1_plus: + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + */ + __pyx_v_i1 = __pyx_v_med1_minus; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":549 + * med2_plus = med2 + step2 + * i1 = med1_minus + * while i1 < med1_plus: # <<<<<<<<<<<<<< + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + * while med2_minus-step2 >= low2: + */ + while (1) { + __pyx_t_3 = (__pyx_v_i1 < __pyx_v_med1_plus); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":550 + * i1 = med1_minus + * while i1 < med1_plus: + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * while med2_minus-step2 >= low2: + * assign_matching(&loc2, arr2, med2_minus-step2, step2, self.fda.sent_id.arr) + */ + __pyx_f_3_sa_assign_matching((&__pyx_v_loc1), __pyx_v_arr1, __pyx_v_i1, __pyx_v_step1, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":551 + * while i1 < med1_plus: + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + * while med2_minus-step2 >= low2: # <<<<<<<<<<<<<< + * assign_matching(&loc2, arr2, med2_minus-step2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) < 1: + */ + while (1) { + __pyx_t_3 = ((__pyx_v_med2_minus - __pyx_v_step2) >= __pyx_v_low2); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":552 + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + * while med2_minus-step2 >= low2: + * assign_matching(&loc2, arr2, med2_minus-step2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) < 1: + * med2_minus = med2_minus - step2 + */ + __pyx_f_3_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, (__pyx_v_med2_minus - __pyx_v_step2), __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":553 + * while med2_minus-step2 >= low2: + * assign_matching(&loc2, arr2, med2_minus-step2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) < 1: # <<<<<<<<<<<<<< + * med2_minus = med2_minus - step2 + * else: + */ + __pyx_t_3 = (((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last) < 1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":554 + * assign_matching(&loc2, arr2, med2_minus-step2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) < 1: + * med2_minus = med2_minus - step2 # <<<<<<<<<<<<<< + * else: + * break + */ + __pyx_v_med2_minus = (__pyx_v_med2_minus - __pyx_v_step2); + goto __pyx_L19; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":556 + * med2_minus = med2_minus - step2 + * else: + * break # <<<<<<<<<<<<<< + * i2 = med2_minus + * while i2 < high2: + */ + goto __pyx_L18_break; + } + __pyx_L19:; + } + __pyx_L18_break:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":557 + * else: + * break + * i2 = med2_minus # <<<<<<<<<<<<<< + * while i2 < high2: + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) + */ + __pyx_v_i2 = __pyx_v_med2_minus; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":558 + * break + * i2 = med2_minus + * while i2 < high2: # <<<<<<<<<<<<<< + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) + * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) + */ + while (1) { + __pyx_t_3 = (__pyx_v_i2 < __pyx_v_high2); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":559 + * i2 = med2_minus + * while i2 < high2: + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) + * if comparison == 0: + */ + __pyx_f_3_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, __pyx_v_i2, __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":560 + * while i2 < high2: + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) + * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) # <<<<<<<<<<<<<< + * if comparison == 0: + * pass + */ + __pyx_v_comparison = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":561 + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) + * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) + * if comparison == 0: # <<<<<<<<<<<<<< + * pass + * med_result = append_combined_matching(med_result, &loc1, &loc2, offset_by_one, num_subpatterns, &med_result_len) + */ + __pyx_t_3 = (__pyx_v_comparison == 0); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":563 + * if comparison == 0: + * pass + * med_result = append_combined_matching(med_result, &loc1, &loc2, offset_by_one, num_subpatterns, &med_result_len) # <<<<<<<<<<<<<< + * if comparison == -1: + * break + */ + __pyx_v_med_result = __pyx_f_3_sa_append_combined_matching(__pyx_v_med_result, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_num_subpatterns, (&__pyx_v_med_result_len)); + goto __pyx_L22; + } + __pyx_L22:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":564 + * pass + * med_result = append_combined_matching(med_result, &loc1, &loc2, offset_by_one, num_subpatterns, &med_result_len) + * if comparison == -1: # <<<<<<<<<<<<<< + * break + * i2 = i2 + step2 + */ + __pyx_t_3 = (__pyx_v_comparison == -1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":565 + * med_result = append_combined_matching(med_result, &loc1, &loc2, offset_by_one, num_subpatterns, &med_result_len) + * if comparison == -1: + * break # <<<<<<<<<<<<<< + * i2 = i2 + step2 + * if i2 > med2_plus: + */ + goto __pyx_L21_break; + goto __pyx_L23; + } + __pyx_L23:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":566 + * if comparison == -1: + * break + * i2 = i2 + step2 # <<<<<<<<<<<<<< + * if i2 > med2_plus: + * med2_plus = i2 + */ + __pyx_v_i2 = (__pyx_v_i2 + __pyx_v_step2); + } + __pyx_L21_break:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":567 + * break + * i2 = i2 + step2 + * if i2 > med2_plus: # <<<<<<<<<<<<<< + * med2_plus = i2 + * i1 = i1 + step1 + */ + __pyx_t_3 = (__pyx_v_i2 > __pyx_v_med2_plus); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":568 + * i2 = i2 + step2 + * if i2 > med2_plus: + * med2_plus = i2 # <<<<<<<<<<<<<< + * i1 = i1 + step1 + * + */ + __pyx_v_med2_plus = __pyx_v_i2; + goto __pyx_L24; + } + __pyx_L24:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":569 + * if i2 > med2_plus: + * med2_plus = i2 + * i1 = i1 + step1 # <<<<<<<<<<<<<< + * + * tmp = med1_minus + */ + __pyx_v_i1 = (__pyx_v_i1 + __pyx_v_step1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":571 + * i1 = i1 + step1 + * + * tmp = med1_minus # <<<<<<<<<<<<<< + * med1_minus = med1_plus + * med1_plus = tmp + */ + __pyx_v_tmp = __pyx_v_med1_minus; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":572 + * + * tmp = med1_minus + * med1_minus = med1_plus # <<<<<<<<<<<<<< + * med1_plus = tmp + * else: + */ + __pyx_v_med1_minus = __pyx_v_med1_plus; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":573 + * tmp = med1_minus + * med1_minus = med1_plus + * med1_plus = tmp # <<<<<<<<<<<<<< + * else: + * # No match; need to figure out the point of division in D and Q + */ + __pyx_v_med1_plus = __pyx_v_tmp; + goto __pyx_L14; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":576 + * else: + * # No match; need to figure out the point of division in D and Q + * med2_minus = med2 # <<<<<<<<<<<<<< + * med2_plus = med2 + * if d_first: + */ + __pyx_v_med2_minus = __pyx_v_med2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":577 + * # No match; need to figure out the point of division in D and Q + * med2_minus = med2 + * med2_plus = med2 # <<<<<<<<<<<<<< + * if d_first: + * med2_minus = med2_minus + step2 + */ + __pyx_v_med2_plus = __pyx_v_med2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":578 + * med2_minus = med2 + * med2_plus = med2 + * if d_first: # <<<<<<<<<<<<<< + * med2_minus = med2_minus + step2 + * if comparison == -1: + */ + if (__pyx_v_d_first) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":579 + * med2_plus = med2 + * if d_first: + * med2_minus = med2_minus + step2 # <<<<<<<<<<<<<< + * if comparison == -1: + * med1_minus = med1_plus + */ + __pyx_v_med2_minus = (__pyx_v_med2_minus + __pyx_v_step2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":580 + * if d_first: + * med2_minus = med2_minus + step2 + * if comparison == -1: # <<<<<<<<<<<<<< + * med1_minus = med1_plus + * if comparison == 1: + */ + __pyx_t_3 = (__pyx_v_comparison == -1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":581 + * med2_minus = med2_minus + step2 + * if comparison == -1: + * med1_minus = med1_plus # <<<<<<<<<<<<<< + * if comparison == 1: + * med1_plus = med1_minus + */ + __pyx_v_med1_minus = __pyx_v_med1_plus; + goto __pyx_L26; + } + __pyx_L26:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":582 + * if comparison == -1: + * med1_minus = med1_plus + * if comparison == 1: # <<<<<<<<<<<<<< + * med1_plus = med1_minus + * else: + */ + __pyx_t_3 = (__pyx_v_comparison == 1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":583 + * med1_minus = med1_plus + * if comparison == 1: + * med1_plus = med1_minus # <<<<<<<<<<<<<< + * else: + * tmp = med1_minus + */ + __pyx_v_med1_plus = __pyx_v_med1_minus; + goto __pyx_L27; + } + __pyx_L27:; + goto __pyx_L25; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":585 + * med1_plus = med1_minus + * else: + * tmp = med1_minus # <<<<<<<<<<<<<< + * med1_minus = med1_plus + * med1_plus = tmp + */ + __pyx_v_tmp = __pyx_v_med1_minus; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":586 + * else: + * tmp = med1_minus + * med1_minus = med1_plus # <<<<<<<<<<<<<< + * med1_plus = tmp + * if comparison == 1: + */ + __pyx_v_med1_minus = __pyx_v_med1_plus; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":587 + * tmp = med1_minus + * med1_minus = med1_plus + * med1_plus = tmp # <<<<<<<<<<<<<< + * if comparison == 1: + * med2_minus = med2_minus + step2 + */ + __pyx_v_med1_plus = __pyx_v_tmp; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":588 + * med1_minus = med1_plus + * med1_plus = tmp + * if comparison == 1: # <<<<<<<<<<<<<< + * med2_minus = med2_minus + step2 + * med2_plus = med2_plus + step2 + */ + __pyx_t_3 = (__pyx_v_comparison == 1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":589 + * med1_plus = tmp + * if comparison == 1: + * med2_minus = med2_minus + step2 # <<<<<<<<<<<<<< + * med2_plus = med2_plus + step2 + * + */ + __pyx_v_med2_minus = (__pyx_v_med2_minus + __pyx_v_step2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":590 + * if comparison == 1: + * med2_minus = med2_minus + step2 + * med2_plus = med2_plus + step2 # <<<<<<<<<<<<<< + * + * low_result_len = 0 + */ + __pyx_v_med2_plus = (__pyx_v_med2_plus + __pyx_v_step2); + goto __pyx_L28; + } + __pyx_L28:; + } + __pyx_L25:; + } + __pyx_L14:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":592 + * med2_plus = med2_plus + step2 + * + * low_result_len = 0 # <<<<<<<<<<<<<< + * low_result = self.baeza_yates_helper(low1, med1_plus, arr1, step1, low2, med2_plus, arr2, step2, offset_by_one, len_last, num_subpatterns, &low_result_len) + * high_result_len = 0 + */ + __pyx_v_low_result_len = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":593 + * + * low_result_len = 0 + * low_result = self.baeza_yates_helper(low1, med1_plus, arr1, step1, low2, med2_plus, arr2, step2, offset_by_one, len_last, num_subpatterns, &low_result_len) # <<<<<<<<<<<<<< + * high_result_len = 0 + * high_result = self.baeza_yates_helper(med1_minus, high1, arr1, step1, med2_minus, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, &high_result_len) + */ + __pyx_v_low_result = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->baeza_yates_helper(__pyx_v_self, __pyx_v_low1, __pyx_v_med1_plus, __pyx_v_arr1, __pyx_v_step1, __pyx_v_low2, __pyx_v_med2_plus, __pyx_v_arr2, __pyx_v_step2, __pyx_v_offset_by_one, __pyx_v_len_last, __pyx_v_num_subpatterns, (&__pyx_v_low_result_len)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":594 + * low_result_len = 0 + * low_result = self.baeza_yates_helper(low1, med1_plus, arr1, step1, low2, med2_plus, arr2, step2, offset_by_one, len_last, num_subpatterns, &low_result_len) + * high_result_len = 0 # <<<<<<<<<<<<<< + * high_result = self.baeza_yates_helper(med1_minus, high1, arr1, step1, med2_minus, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, &high_result_len) + * + */ + __pyx_v_high_result_len = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":595 + * low_result = self.baeza_yates_helper(low1, med1_plus, arr1, step1, low2, med2_plus, arr2, step2, offset_by_one, len_last, num_subpatterns, &low_result_len) + * high_result_len = 0 + * high_result = self.baeza_yates_helper(med1_minus, high1, arr1, step1, med2_minus, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, &high_result_len) # <<<<<<<<<<<<<< + * + * result = extend_arr(result, result_len, low_result, low_result_len) + */ + __pyx_v_high_result = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->baeza_yates_helper(__pyx_v_self, __pyx_v_med1_minus, __pyx_v_high1, __pyx_v_arr1, __pyx_v_step1, __pyx_v_med2_minus, __pyx_v_high2, __pyx_v_arr2, __pyx_v_step2, __pyx_v_offset_by_one, __pyx_v_len_last, __pyx_v_num_subpatterns, (&__pyx_v_high_result_len)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":597 + * high_result = self.baeza_yates_helper(med1_minus, high1, arr1, step1, med2_minus, high2, arr2, step2, offset_by_one, len_last, num_subpatterns, &high_result_len) + * + * result = extend_arr(result, result_len, low_result, low_result_len) # <<<<<<<<<<<<<< + * result = extend_arr(result, result_len, med_result, med_result_len) + * result = extend_arr(result, result_len, high_result, high_result_len) + */ + __pyx_v_result = __pyx_f_3_sa_extend_arr(__pyx_v_result, __pyx_v_result_len, __pyx_v_low_result, __pyx_v_low_result_len); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":598 + * + * result = extend_arr(result, result_len, low_result, low_result_len) + * result = extend_arr(result, result_len, med_result, med_result_len) # <<<<<<<<<<<<<< + * result = extend_arr(result, result_len, high_result, high_result_len) + * free(low_result) + */ + __pyx_v_result = __pyx_f_3_sa_extend_arr(__pyx_v_result, __pyx_v_result_len, __pyx_v_med_result, __pyx_v_med_result_len); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":599 + * result = extend_arr(result, result_len, low_result, low_result_len) + * result = extend_arr(result, result_len, med_result, med_result_len) + * result = extend_arr(result, result_len, high_result, high_result_len) # <<<<<<<<<<<<<< + * free(low_result) + * free(med_result) + */ + __pyx_v_result = __pyx_f_3_sa_extend_arr(__pyx_v_result, __pyx_v_result_len, __pyx_v_high_result, __pyx_v_high_result_len); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":600 + * result = extend_arr(result, result_len, med_result, med_result_len) + * result = extend_arr(result, result_len, high_result, high_result_len) + * free(low_result) # <<<<<<<<<<<<<< + * free(med_result) + * free(high_result) + */ + free(__pyx_v_low_result); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":601 + * result = extend_arr(result, result_len, high_result, high_result_len) + * free(low_result) + * free(med_result) # <<<<<<<<<<<<<< + * free(high_result) + * + */ + free(__pyx_v_med_result); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":602 + * free(low_result) + * free(med_result) + * free(high_result) # <<<<<<<<<<<<<< + * + * return result + */ + free(__pyx_v_high_result); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":604 + * free(high_result) + * + * return result # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_WriteUnraisable("_sa.HieroCachingRuleFactory.baeza_yates_helper", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":608 + * + * + * cdef long compare_matchings_set(self, int i1_minus, int i1_plus, int* arr1, int step1, # <<<<<<<<<<<<<< + * Matching* loc2, int offset_by_one, int len_last): + * """ + */ + +static long __pyx_f_3_sa_23HieroCachingRuleFactory_compare_matchings_set(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, int __pyx_v_i1_minus, int __pyx_v_i1_plus, int *__pyx_v_arr1, int __pyx_v_step1, struct __pyx_t_3_sa_Matching *__pyx_v_loc2, int __pyx_v_offset_by_one, int __pyx_v_len_last) { + int __pyx_v_i1; + int __pyx_v_comparison; + int __pyx_v_prev_comparison; + struct __pyx_t_3_sa_Matching __pyx_v_l1_stack; + struct __pyx_t_3_sa_Matching *__pyx_v_loc1; + long __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("compare_matchings_set", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":619 + * cdef Matching* loc1 + * + * loc1 = &l1_stack # <<<<<<<<<<<<<< + * + * i1 = i1_minus + */ + __pyx_v_loc1 = (&__pyx_v_l1_stack); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":621 + * loc1 = &l1_stack + * + * i1 = i1_minus # <<<<<<<<<<<<<< + * while i1 < i1_plus: + * assign_matching(loc1, arr1, i1, step1, self.fda.sent_id.arr) + */ + __pyx_v_i1 = __pyx_v_i1_minus; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":622 + * + * i1 = i1_minus + * while i1 < i1_plus: # <<<<<<<<<<<<<< + * assign_matching(loc1, arr1, i1, step1, self.fda.sent_id.arr) + * comparison = self.compare_matchings(loc1, loc2, offset_by_one, len_last) + */ + while (1) { + __pyx_t_1 = (__pyx_v_i1 < __pyx_v_i1_plus); + if (!__pyx_t_1) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":623 + * i1 = i1_minus + * while i1 < i1_plus: + * assign_matching(loc1, arr1, i1, step1, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * comparison = self.compare_matchings(loc1, loc2, offset_by_one, len_last) + * if comparison == 0: + */ + __pyx_f_3_sa_assign_matching(__pyx_v_loc1, __pyx_v_arr1, __pyx_v_i1, __pyx_v_step1, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":624 + * while i1 < i1_plus: + * assign_matching(loc1, arr1, i1, step1, self.fda.sent_id.arr) + * comparison = self.compare_matchings(loc1, loc2, offset_by_one, len_last) # <<<<<<<<<<<<<< + * if comparison == 0: + * prev_comparison = 0 + */ + __pyx_v_comparison = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, __pyx_v_loc1, __pyx_v_loc2, __pyx_v_offset_by_one, __pyx_v_len_last); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":625 + * assign_matching(loc1, arr1, i1, step1, self.fda.sent_id.arr) + * comparison = self.compare_matchings(loc1, loc2, offset_by_one, len_last) + * if comparison == 0: # <<<<<<<<<<<<<< + * prev_comparison = 0 + * break + */ + __pyx_t_1 = (__pyx_v_comparison == 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":626 + * comparison = self.compare_matchings(loc1, loc2, offset_by_one, len_last) + * if comparison == 0: + * prev_comparison = 0 # <<<<<<<<<<<<<< + * break + * elif i1 == i1_minus: + */ + __pyx_v_prev_comparison = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":627 + * if comparison == 0: + * prev_comparison = 0 + * break # <<<<<<<<<<<<<< + * elif i1 == i1_minus: + * prev_comparison = comparison + */ + goto __pyx_L4_break; + goto __pyx_L5; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":628 + * prev_comparison = 0 + * break + * elif i1 == i1_minus: # <<<<<<<<<<<<<< + * prev_comparison = comparison + * else: + */ + __pyx_t_1 = (__pyx_v_i1 == __pyx_v_i1_minus); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":629 + * break + * elif i1 == i1_minus: + * prev_comparison = comparison # <<<<<<<<<<<<<< + * else: + * if comparison != prev_comparison: + */ + __pyx_v_prev_comparison = __pyx_v_comparison; + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":631 + * prev_comparison = comparison + * else: + * if comparison != prev_comparison: # <<<<<<<<<<<<<< + * prev_comparison = 0 + * break + */ + __pyx_t_1 = (__pyx_v_comparison != __pyx_v_prev_comparison); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":632 + * else: + * if comparison != prev_comparison: + * prev_comparison = 0 # <<<<<<<<<<<<<< + * break + * i1 = i1 + step1 + */ + __pyx_v_prev_comparison = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":633 + * if comparison != prev_comparison: + * prev_comparison = 0 + * break # <<<<<<<<<<<<<< + * i1 = i1 + step1 + * return prev_comparison + */ + goto __pyx_L4_break; + goto __pyx_L6; + } + __pyx_L6:; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":634 + * prev_comparison = 0 + * break + * i1 = i1 + step1 # <<<<<<<<<<<<<< + * return prev_comparison + * + */ + __pyx_v_i1 = (__pyx_v_i1 + __pyx_v_step1); + } + __pyx_L4_break:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":635 + * break + * i1 = i1 + step1 + * return prev_comparison # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_prev_comparison; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":638 + * + * + * cdef long compare_matchings(self, Matching* loc1, Matching* loc2, int offset_by_one, int len_last): # <<<<<<<<<<<<<< + * cdef int i + * + */ + +static long __pyx_f_3_sa_23HieroCachingRuleFactory_compare_matchings(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_t_3_sa_Matching *__pyx_v_loc1, struct __pyx_t_3_sa_Matching *__pyx_v_loc2, int __pyx_v_offset_by_one, int __pyx_v_len_last) { + int __pyx_v_i; + long __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + __Pyx_RefNannySetupContext("compare_matchings", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":641 + * cdef int i + * + * if loc1.sent_id > loc2.sent_id: # <<<<<<<<<<<<<< + * return 1 + * if loc2.sent_id > loc1.sent_id: + */ + __pyx_t_1 = (__pyx_v_loc1->sent_id > __pyx_v_loc2->sent_id); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":642 + * + * if loc1.sent_id > loc2.sent_id: + * return 1 # <<<<<<<<<<<<<< + * if loc2.sent_id > loc1.sent_id: + * return -1 + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":643 + * if loc1.sent_id > loc2.sent_id: + * return 1 + * if loc2.sent_id > loc1.sent_id: # <<<<<<<<<<<<<< + * return -1 + * + */ + __pyx_t_1 = (__pyx_v_loc2->sent_id > __pyx_v_loc1->sent_id); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":644 + * return 1 + * if loc2.sent_id > loc1.sent_id: + * return -1 # <<<<<<<<<<<<<< + * + * if loc1.size == 1 and loc2.size == 1: + */ + __pyx_r = -1; + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":646 + * return -1 + * + * if loc1.size == 1 and loc2.size == 1: # <<<<<<<<<<<<<< + * if loc2.arr[loc2.start] - loc1.arr[loc1.start] <= self.train_min_gap_size: + * return 1 + */ + __pyx_t_1 = (__pyx_v_loc1->size == 1); + if (__pyx_t_1) { + __pyx_t_2 = (__pyx_v_loc2->size == 1); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":647 + * + * if loc1.size == 1 and loc2.size == 1: + * if loc2.arr[loc2.start] - loc1.arr[loc1.start] <= self.train_min_gap_size: # <<<<<<<<<<<<<< + * return 1 + * + */ + __pyx_t_3 = (((__pyx_v_loc2->arr[__pyx_v_loc2->start]) - (__pyx_v_loc1->arr[__pyx_v_loc1->start])) <= __pyx_v_self->train_min_gap_size); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":648 + * if loc1.size == 1 and loc2.size == 1: + * if loc2.arr[loc2.start] - loc1.arr[loc1.start] <= self.train_min_gap_size: + * return 1 # <<<<<<<<<<<<<< + * + * elif offset_by_one: + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L6; + } + __pyx_L6:; + goto __pyx_L5; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":650 + * return 1 + * + * elif offset_by_one: # <<<<<<<<<<<<<< + * for i from 1 <= i < loc1.size: + * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i-1]: + */ + if (__pyx_v_offset_by_one) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":651 + * + * elif offset_by_one: + * for i from 1 <= i < loc1.size: # <<<<<<<<<<<<<< + * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i-1]: + * return 1 + */ + __pyx_t_4 = __pyx_v_loc1->size; + for (__pyx_v_i = 1; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":652 + * elif offset_by_one: + * for i from 1 <= i < loc1.size: + * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i-1]: # <<<<<<<<<<<<<< + * return 1 + * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i-1]: + */ + __pyx_t_3 = ((__pyx_v_loc1->arr[(__pyx_v_loc1->start + __pyx_v_i)]) > (__pyx_v_loc2->arr[((__pyx_v_loc2->start + __pyx_v_i) - 1)])); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":653 + * for i from 1 <= i < loc1.size: + * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i-1]: + * return 1 # <<<<<<<<<<<<<< + * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i-1]: + * return -1 + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L9; + } + __pyx_L9:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":654 + * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i-1]: + * return 1 + * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i-1]: # <<<<<<<<<<<<<< + * return -1 + * + */ + __pyx_t_3 = ((__pyx_v_loc1->arr[(__pyx_v_loc1->start + __pyx_v_i)]) < (__pyx_v_loc2->arr[((__pyx_v_loc2->start + __pyx_v_i) - 1)])); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":655 + * return 1 + * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i-1]: + * return -1 # <<<<<<<<<<<<<< + * + * else: + */ + __pyx_r = -1; + goto __pyx_L0; + goto __pyx_L10; + } + __pyx_L10:; + } + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":658 + * + * else: + * if loc1.arr[loc1.start]+1 > loc2.arr[loc2.start]: # <<<<<<<<<<<<<< + * return 1 + * if loc1.arr[loc1.start]+1 < loc2.arr[loc2.start]: + */ + __pyx_t_3 = (((__pyx_v_loc1->arr[__pyx_v_loc1->start]) + 1) > (__pyx_v_loc2->arr[__pyx_v_loc2->start])); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":659 + * else: + * if loc1.arr[loc1.start]+1 > loc2.arr[loc2.start]: + * return 1 # <<<<<<<<<<<<<< + * if loc1.arr[loc1.start]+1 < loc2.arr[loc2.start]: + * return -1 + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L11; + } + __pyx_L11:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":660 + * if loc1.arr[loc1.start]+1 > loc2.arr[loc2.start]: + * return 1 + * if loc1.arr[loc1.start]+1 < loc2.arr[loc2.start]: # <<<<<<<<<<<<<< + * return -1 + * + */ + __pyx_t_3 = (((__pyx_v_loc1->arr[__pyx_v_loc1->start]) + 1) < (__pyx_v_loc2->arr[__pyx_v_loc2->start])); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":661 + * return 1 + * if loc1.arr[loc1.start]+1 < loc2.arr[loc2.start]: + * return -1 # <<<<<<<<<<<<<< + * + * for i from 1 <= i < loc1.size: + */ + __pyx_r = -1; + goto __pyx_L0; + goto __pyx_L12; + } + __pyx_L12:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":663 + * return -1 + * + * for i from 1 <= i < loc1.size: # <<<<<<<<<<<<<< + * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i]: + * return 1 + */ + __pyx_t_4 = __pyx_v_loc1->size; + for (__pyx_v_i = 1; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":664 + * + * for i from 1 <= i < loc1.size: + * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i]: # <<<<<<<<<<<<<< + * return 1 + * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i]: + */ + __pyx_t_3 = ((__pyx_v_loc1->arr[(__pyx_v_loc1->start + __pyx_v_i)]) > (__pyx_v_loc2->arr[(__pyx_v_loc2->start + __pyx_v_i)])); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":665 + * for i from 1 <= i < loc1.size: + * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i]: + * return 1 # <<<<<<<<<<<<<< + * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i]: + * return -1 + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L15; + } + __pyx_L15:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":666 + * if loc1.arr[loc1.start+i] > loc2.arr[loc2.start+i]: + * return 1 + * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i]: # <<<<<<<<<<<<<< + * return -1 + * + */ + __pyx_t_3 = ((__pyx_v_loc1->arr[(__pyx_v_loc1->start + __pyx_v_i)]) < (__pyx_v_loc2->arr[(__pyx_v_loc2->start + __pyx_v_i)])); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":667 + * return 1 + * if loc1.arr[loc1.start+i] < loc2.arr[loc2.start+i]: + * return -1 # <<<<<<<<<<<<<< + * + * if loc2.arr[loc2.end-1] + len_last - loc1.arr[loc1.start] > self.train_max_initial_size: + */ + __pyx_r = -1; + goto __pyx_L0; + goto __pyx_L16; + } + __pyx_L16:; + } + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":669 + * return -1 + * + * if loc2.arr[loc2.end-1] + len_last - loc1.arr[loc1.start] > self.train_max_initial_size: # <<<<<<<<<<<<<< + * return -1 + * return 0 + */ + __pyx_t_3 = ((((__pyx_v_loc2->arr[(__pyx_v_loc2->end - 1)]) + __pyx_v_len_last) - (__pyx_v_loc1->arr[__pyx_v_loc1->start])) > __pyx_v_self->train_max_initial_size); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":670 + * + * if loc2.arr[loc2.end-1] + len_last - loc1.arr[loc1.start] > self.train_max_initial_size: + * return -1 # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_r = -1; + goto __pyx_L0; + goto __pyx_L17; + } + __pyx_L17:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":671 + * if loc2.arr[loc2.end-1] + len_last - loc1.arr[loc1.start] > self.train_max_initial_size: + * return -1 + * return 0 # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = 0; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":674 + * + * + * cdef int* merge_helper(self, int low1, int high1, int* arr1, int step1, # <<<<<<<<<<<<<< + * int low2, int high2, int* arr2, int step2, + * int offset_by_one, int len_last, int num_subpatterns, int* result_len): + */ + +static int *__pyx_f_3_sa_23HieroCachingRuleFactory_merge_helper(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, int __pyx_v_low1, int __pyx_v_high1, int *__pyx_v_arr1, int __pyx_v_step1, int __pyx_v_low2, int __pyx_v_high2, int *__pyx_v_arr2, int __pyx_v_step2, int __pyx_v_offset_by_one, int __pyx_v_len_last, int __pyx_v_num_subpatterns, int *__pyx_v_result_len) { + int __pyx_v_i1; + int __pyx_v_i2; + int __pyx_v_j1; + int __pyx_v_j2; + long __pyx_v_comparison; + int *__pyx_v_result; + struct __pyx_t_3_sa_Matching __pyx_v_loc1; + struct __pyx_t_3_sa_Matching __pyx_v_loc2; + int *__pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + __Pyx_RefNannySetupContext("merge_helper", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":682 + * cdef Matching loc1, loc2 + * + * result_len[0] = 0 # <<<<<<<<<<<<<< + * result = malloc(0*sizeof(int)) + * + */ + (__pyx_v_result_len[0]) = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":683 + * + * result_len[0] = 0 + * result = malloc(0*sizeof(int)) # <<<<<<<<<<<<<< + * + * i1 = low1 + */ + __pyx_v_result = ((int *)malloc((0 * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":685 + * result = malloc(0*sizeof(int)) + * + * i1 = low1 # <<<<<<<<<<<<<< + * i2 = low2 + * while i1 < high1 and i2 < high2: + */ + __pyx_v_i1 = __pyx_v_low1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":686 + * + * i1 = low1 + * i2 = low2 # <<<<<<<<<<<<<< + * while i1 < high1 and i2 < high2: + * + */ + __pyx_v_i2 = __pyx_v_low2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":687 + * i1 = low1 + * i2 = low2 + * while i1 < high1 and i2 < high2: # <<<<<<<<<<<<<< + * + * # First, pop all unneeded loc2's off the stack + */ + while (1) { + __pyx_t_1 = (__pyx_v_i1 < __pyx_v_high1); + if (__pyx_t_1) { + __pyx_t_2 = (__pyx_v_i2 < __pyx_v_high2); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_1; + } + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":690 + * + * # First, pop all unneeded loc2's off the stack + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * while i2 < high2: + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) + */ + __pyx_f_3_sa_assign_matching((&__pyx_v_loc1), __pyx_v_arr1, __pyx_v_i1, __pyx_v_step1, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":691 + * # First, pop all unneeded loc2's off the stack + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + * while i2 < high2: # <<<<<<<<<<<<<< + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: + */ + while (1) { + __pyx_t_3 = (__pyx_v_i2 < __pyx_v_high2); + if (!__pyx_t_3) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":692 + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + * while i2 < high2: + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: + * i2 = i2 + step2 + */ + __pyx_f_3_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, __pyx_v_i2, __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":693 + * while i2 < high2: + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: # <<<<<<<<<<<<<< + * i2 = i2 + step2 + * else: + */ + __pyx_t_3 = (((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last) == 1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":694 + * assign_matching(&loc2, arr2, i2, step2, self.fda.sent_id.arr) + * if self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) == 1: + * i2 = i2 + step2 # <<<<<<<<<<<<<< + * else: + * break + */ + __pyx_v_i2 = (__pyx_v_i2 + __pyx_v_step2); + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":696 + * i2 = i2 + step2 + * else: + * break # <<<<<<<<<<<<<< + * + * # Next: process all loc1's with the same starting val + */ + goto __pyx_L6_break; + } + __pyx_L7:; + } + __pyx_L6_break:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":699 + * + * # Next: process all loc1's with the same starting val + * j1 = i1 # <<<<<<<<<<<<<< + * while i1 < high1 and arr1[j1] == arr1[i1]: + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + */ + __pyx_v_j1 = __pyx_v_i1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":700 + * # Next: process all loc1's with the same starting val + * j1 = i1 + * while i1 < high1 and arr1[j1] == arr1[i1]: # <<<<<<<<<<<<<< + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + * j2 = i2 + */ + while (1) { + __pyx_t_3 = (__pyx_v_i1 < __pyx_v_high1); + if (__pyx_t_3) { + __pyx_t_1 = ((__pyx_v_arr1[__pyx_v_j1]) == (__pyx_v_arr1[__pyx_v_i1])); + __pyx_t_2 = __pyx_t_1; + } else { + __pyx_t_2 = __pyx_t_3; + } + if (!__pyx_t_2) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":701 + * j1 = i1 + * while i1 < high1 and arr1[j1] == arr1[i1]: + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * j2 = i2 + * while j2 < high2: + */ + __pyx_f_3_sa_assign_matching((&__pyx_v_loc1), __pyx_v_arr1, __pyx_v_i1, __pyx_v_step1, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":702 + * while i1 < high1 and arr1[j1] == arr1[i1]: + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + * j2 = i2 # <<<<<<<<<<<<<< + * while j2 < high2: + * assign_matching(&loc2, arr2, j2, step2, self.fda.sent_id.arr) + */ + __pyx_v_j2 = __pyx_v_i2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":703 + * assign_matching(&loc1, arr1, i1, step1, self.fda.sent_id.arr) + * j2 = i2 + * while j2 < high2: # <<<<<<<<<<<<<< + * assign_matching(&loc2, arr2, j2, step2, self.fda.sent_id.arr) + * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) + */ + while (1) { + __pyx_t_2 = (__pyx_v_j2 < __pyx_v_high2); + if (!__pyx_t_2) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":704 + * j2 = i2 + * while j2 < high2: + * assign_matching(&loc2, arr2, j2, step2, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) + * if comparison == 0: + */ + __pyx_f_3_sa_assign_matching((&__pyx_v_loc2), __pyx_v_arr2, __pyx_v_j2, __pyx_v_step2, __pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":705 + * while j2 < high2: + * assign_matching(&loc2, arr2, j2, step2, self.fda.sent_id.arr) + * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) # <<<<<<<<<<<<<< + * if comparison == 0: + * result = append_combined_matching(result, &loc1, &loc2, offset_by_one, num_subpatterns, result_len) + */ + __pyx_v_comparison = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->compare_matchings(__pyx_v_self, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_len_last); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":706 + * assign_matching(&loc2, arr2, j2, step2, self.fda.sent_id.arr) + * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) + * if comparison == 0: # <<<<<<<<<<<<<< + * result = append_combined_matching(result, &loc1, &loc2, offset_by_one, num_subpatterns, result_len) + * if comparison == 1: + */ + __pyx_t_2 = (__pyx_v_comparison == 0); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":707 + * comparison = self.compare_matchings(&loc1, &loc2, offset_by_one, len_last) + * if comparison == 0: + * result = append_combined_matching(result, &loc1, &loc2, offset_by_one, num_subpatterns, result_len) # <<<<<<<<<<<<<< + * if comparison == 1: + * pass + */ + __pyx_v_result = __pyx_f_3_sa_append_combined_matching(__pyx_v_result, (&__pyx_v_loc1), (&__pyx_v_loc2), __pyx_v_offset_by_one, __pyx_v_num_subpatterns, __pyx_v_result_len); + goto __pyx_L12; + } + __pyx_L12:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":708 + * if comparison == 0: + * result = append_combined_matching(result, &loc1, &loc2, offset_by_one, num_subpatterns, result_len) + * if comparison == 1: # <<<<<<<<<<<<<< + * pass + * if comparison == -1: + */ + __pyx_t_2 = (__pyx_v_comparison == 1); + if (__pyx_t_2) { + goto __pyx_L13; + } + __pyx_L13:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":710 + * if comparison == 1: + * pass + * if comparison == -1: # <<<<<<<<<<<<<< + * break + * else: + */ + __pyx_t_2 = (__pyx_v_comparison == -1); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":711 + * pass + * if comparison == -1: + * break # <<<<<<<<<<<<<< + * else: + * j2 = j2 + step2 + */ + goto __pyx_L11_break; + goto __pyx_L14; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":713 + * break + * else: + * j2 = j2 + step2 # <<<<<<<<<<<<<< + * i1 = i1 + step1 + * return result + */ + __pyx_v_j2 = (__pyx_v_j2 + __pyx_v_step2); + } + __pyx_L14:; + } + __pyx_L11_break:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":714 + * else: + * j2 = j2 + step2 + * i1 = i1 + step1 # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_v_i1 = (__pyx_v_i1 + __pyx_v_step1); + } + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":715 + * j2 = j2 + step2 + * i1 = i1 + step1 + * return result # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":718 + * + * + * cdef void sort_phrase_loc(self, IntList arr, PhraseLocation loc, Phrase phrase): # <<<<<<<<<<<<<< + * cdef int i, j + * cdef VEB veb + */ + +static void __pyx_f_3_sa_23HieroCachingRuleFactory_sort_phrase_loc(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_3_sa_IntList *__pyx_v_arr, struct __pyx_obj_3_sa_PhraseLocation *__pyx_v_loc, struct __pyx_obj_3_sa_Phrase *__pyx_v_phrase) { + int __pyx_v_i; + int __pyx_v_j; + struct __pyx_obj_3_sa_VEB *__pyx_v_veb = 0; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("sort_phrase_loc", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":723 + * cdef IntList result + * + * if phrase in self.precomputed_index: # <<<<<<<<<<<<<< + * loc.arr = self.precomputed_index[phrase] + * else: + */ + __pyx_t_1 = ((PySequence_Contains(__pyx_v_self->precomputed_index, ((PyObject *)__pyx_v_phrase)))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":724 + * + * if phrase in self.precomputed_index: + * loc.arr = self.precomputed_index[phrase] # <<<<<<<<<<<<<< + * else: + * loc.arr = IntList(initial_len=loc.sa_high-loc.sa_low) + */ + __pyx_t_2 = PyObject_GetItem(__pyx_v_self->precomputed_index, ((PyObject *)__pyx_v_phrase)); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_3_sa_IntList))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_v_loc->arr); + __Pyx_DECREF(((PyObject *)__pyx_v_loc->arr)); + __pyx_v_loc->arr = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_2); + __pyx_t_2 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":726 + * loc.arr = self.precomputed_index[phrase] + * else: + * loc.arr = IntList(initial_len=loc.sa_high-loc.sa_low) # <<<<<<<<<<<<<< + * veb = VEB(arr.len) + * for i from loc.sa_low <= i < loc.sa_high: + */ + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_3 = PyInt_FromLong((__pyx_v_loc->sa_high - __pyx_v_loc->sa_low)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 726; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_v_loc->arr); + __Pyx_DECREF(((PyObject *)__pyx_v_loc->arr)); + __pyx_v_loc->arr = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":727 + * else: + * loc.arr = IntList(initial_len=loc.sa_high-loc.sa_low) + * veb = VEB(arr.len) # <<<<<<<<<<<<<< + * for i from loc.sa_low <= i < loc.sa_high: + * veb._insert(arr.arr[i]) + */ + __pyx_t_3 = PyInt_FromLong(__pyx_v_arr->len); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_VEB)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_v_veb = ((struct __pyx_obj_3_sa_VEB *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":728 + * loc.arr = IntList(initial_len=loc.sa_high-loc.sa_low) + * veb = VEB(arr.len) + * for i from loc.sa_low <= i < loc.sa_high: # <<<<<<<<<<<<<< + * veb._insert(arr.arr[i]) + * i = veb.veb.min_val + */ + __pyx_t_4 = __pyx_v_loc->sa_high; + for (__pyx_v_i = __pyx_v_loc->sa_low; __pyx_v_i < __pyx_t_4; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":729 + * veb = VEB(arr.len) + * for i from loc.sa_low <= i < loc.sa_high: + * veb._insert(arr.arr[i]) # <<<<<<<<<<<<<< + * i = veb.veb.min_val + * for j from 0 <= j < loc.sa_high-loc.sa_low: + */ + ((struct __pyx_vtabstruct_3_sa_VEB *)__pyx_v_veb->__pyx_vtab)->_insert(__pyx_v_veb, (__pyx_v_arr->arr[__pyx_v_i])); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":730 + * for i from loc.sa_low <= i < loc.sa_high: + * veb._insert(arr.arr[i]) + * i = veb.veb.min_val # <<<<<<<<<<<<<< + * for j from 0 <= j < loc.sa_high-loc.sa_low: + * loc.arr.arr[j] = i + */ + __pyx_v_i = __pyx_v_veb->veb->min_val; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":731 + * veb._insert(arr.arr[i]) + * i = veb.veb.min_val + * for j from 0 <= j < loc.sa_high-loc.sa_low: # <<<<<<<<<<<<<< + * loc.arr.arr[j] = i + * i = veb._findsucc(i) + */ + __pyx_t_4 = (__pyx_v_loc->sa_high - __pyx_v_loc->sa_low); + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_4; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":732 + * i = veb.veb.min_val + * for j from 0 <= j < loc.sa_high-loc.sa_low: + * loc.arr.arr[j] = i # <<<<<<<<<<<<<< + * i = veb._findsucc(i) + * loc.arr_low = 0 + */ + (__pyx_v_loc->arr->arr[__pyx_v_j]) = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":733 + * for j from 0 <= j < loc.sa_high-loc.sa_low: + * loc.arr.arr[j] = i + * i = veb._findsucc(i) # <<<<<<<<<<<<<< + * loc.arr_low = 0 + * loc.arr_high = loc.arr.len + */ + __pyx_v_i = ((struct __pyx_vtabstruct_3_sa_VEB *)__pyx_v_veb->__pyx_vtab)->_findsucc(__pyx_v_veb, __pyx_v_i); + } + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":734 + * loc.arr.arr[j] = i + * i = veb._findsucc(i) + * loc.arr_low = 0 # <<<<<<<<<<<<<< + * loc.arr_high = loc.arr.len + * + */ + __pyx_v_loc->arr_low = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":735 + * i = veb._findsucc(i) + * loc.arr_low = 0 + * loc.arr_high = loc.arr.len # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_loc->arr_high = __pyx_v_loc->arr->len; + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_WriteUnraisable("_sa.HieroCachingRuleFactory.sort_phrase_loc", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_veb); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":738 + * + * + * cdef intersect_helper(self, Phrase prefix, Phrase suffix, # <<<<<<<<<<<<<< + * PhraseLocation prefix_loc, PhraseLocation suffix_loc, int algorithm): + * + */ + +static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_intersect_helper(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_3_sa_Phrase *__pyx_v_prefix, struct __pyx_obj_3_sa_Phrase *__pyx_v_suffix, struct __pyx_obj_3_sa_PhraseLocation *__pyx_v_prefix_loc, struct __pyx_obj_3_sa_PhraseLocation *__pyx_v_suffix_loc, int __pyx_v_algorithm) { + struct __pyx_obj_3_sa_IntList *__pyx_v_arr1 = 0; + struct __pyx_obj_3_sa_IntList *__pyx_v_arr2 = 0; + struct __pyx_obj_3_sa_IntList *__pyx_v_result = 0; + int __pyx_v_low1; + int __pyx_v_high1; + int __pyx_v_step1; + int __pyx_v_low2; + int __pyx_v_high2; + int __pyx_v_step2; + int __pyx_v_offset_by_one; + int __pyx_v_len_last; + int __pyx_v_num_subpatterns; + int __pyx_v_result_len; + int *__pyx_v_result_ptr; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + Py_ssize_t __pyx_t_6; + int __pyx_t_7; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("intersect_helper", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":745 + * cdef int* result_ptr + * + * result_len = 0 # <<<<<<<<<<<<<< + * + * if sym_isvar(suffix[0]): + */ + __pyx_v_result_len = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":747 + * result_len = 0 + * + * if sym_isvar(suffix[0]): # <<<<<<<<<<<<<< + * offset_by_one = 1 + * else: + */ + __pyx_t_1 = __Pyx_GetItemInt(((PyObject *)__pyx_v_suffix), 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = __pyx_f_3_sa_sym_isvar(__pyx_t_2); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":748 + * + * if sym_isvar(suffix[0]): + * offset_by_one = 1 # <<<<<<<<<<<<<< + * else: + * offset_by_one = 0 + */ + __pyx_v_offset_by_one = 1; + goto __pyx_L3; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":750 + * offset_by_one = 1 + * else: + * offset_by_one = 0 # <<<<<<<<<<<<<< + * + * len_last = len(suffix.getchunk(suffix.arity())) + */ + __pyx_v_offset_by_one = 0; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":752 + * offset_by_one = 0 + * + * len_last = len(suffix.getchunk(suffix.arity())) # <<<<<<<<<<<<<< + * + * if prefix_loc.arr is None: + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_suffix), __pyx_n_s__getchunk); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_suffix), __pyx_n_s__arity); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_t_6 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 752; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_len_last = __pyx_t_6; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":754 + * len_last = len(suffix.getchunk(suffix.arity())) + * + * if prefix_loc.arr is None: # <<<<<<<<<<<<<< + * self.sort_phrase_loc(self.fsa.sa, prefix_loc, prefix) + * arr1 = prefix_loc.arr + */ + __pyx_t_7 = (((PyObject *)__pyx_v_prefix_loc->arr) == Py_None); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":755 + * + * if prefix_loc.arr is None: + * self.sort_phrase_loc(self.fsa.sa, prefix_loc, prefix) # <<<<<<<<<<<<<< + * arr1 = prefix_loc.arr + * low1 = prefix_loc.arr_low + */ + __pyx_t_5 = ((PyObject *)__pyx_v_self->fsa->sa); + __Pyx_INCREF(__pyx_t_5); + ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->sort_phrase_loc(__pyx_v_self, ((struct __pyx_obj_3_sa_IntList *)__pyx_t_5), __pyx_v_prefix_loc, __pyx_v_prefix); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":756 + * if prefix_loc.arr is None: + * self.sort_phrase_loc(self.fsa.sa, prefix_loc, prefix) + * arr1 = prefix_loc.arr # <<<<<<<<<<<<<< + * low1 = prefix_loc.arr_low + * high1 = prefix_loc.arr_high + */ + __Pyx_INCREF(((PyObject *)__pyx_v_prefix_loc->arr)); + __pyx_v_arr1 = __pyx_v_prefix_loc->arr; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":757 + * self.sort_phrase_loc(self.fsa.sa, prefix_loc, prefix) + * arr1 = prefix_loc.arr + * low1 = prefix_loc.arr_low # <<<<<<<<<<<<<< + * high1 = prefix_loc.arr_high + * step1 = prefix_loc.num_subpatterns + */ + __pyx_v_low1 = __pyx_v_prefix_loc->arr_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":758 + * arr1 = prefix_loc.arr + * low1 = prefix_loc.arr_low + * high1 = prefix_loc.arr_high # <<<<<<<<<<<<<< + * step1 = prefix_loc.num_subpatterns + * + */ + __pyx_v_high1 = __pyx_v_prefix_loc->arr_high; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":759 + * low1 = prefix_loc.arr_low + * high1 = prefix_loc.arr_high + * step1 = prefix_loc.num_subpatterns # <<<<<<<<<<<<<< + * + * if suffix_loc.arr is None: + */ + __pyx_v_step1 = __pyx_v_prefix_loc->num_subpatterns; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":761 + * step1 = prefix_loc.num_subpatterns + * + * if suffix_loc.arr is None: # <<<<<<<<<<<<<< + * self.sort_phrase_loc(self.fsa.sa, suffix_loc, suffix) + * arr2 = suffix_loc.arr + */ + __pyx_t_7 = (((PyObject *)__pyx_v_suffix_loc->arr) == Py_None); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":762 + * + * if suffix_loc.arr is None: + * self.sort_phrase_loc(self.fsa.sa, suffix_loc, suffix) # <<<<<<<<<<<<<< + * arr2 = suffix_loc.arr + * low2 = suffix_loc.arr_low + */ + __pyx_t_5 = ((PyObject *)__pyx_v_self->fsa->sa); + __Pyx_INCREF(__pyx_t_5); + ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->sort_phrase_loc(__pyx_v_self, ((struct __pyx_obj_3_sa_IntList *)__pyx_t_5), __pyx_v_suffix_loc, __pyx_v_suffix); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":763 + * if suffix_loc.arr is None: + * self.sort_phrase_loc(self.fsa.sa, suffix_loc, suffix) + * arr2 = suffix_loc.arr # <<<<<<<<<<<<<< + * low2 = suffix_loc.arr_low + * high2 = suffix_loc.arr_high + */ + __Pyx_INCREF(((PyObject *)__pyx_v_suffix_loc->arr)); + __pyx_v_arr2 = __pyx_v_suffix_loc->arr; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":764 + * self.sort_phrase_loc(self.fsa.sa, suffix_loc, suffix) + * arr2 = suffix_loc.arr + * low2 = suffix_loc.arr_low # <<<<<<<<<<<<<< + * high2 = suffix_loc.arr_high + * step2 = suffix_loc.num_subpatterns + */ + __pyx_v_low2 = __pyx_v_suffix_loc->arr_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":765 + * arr2 = suffix_loc.arr + * low2 = suffix_loc.arr_low + * high2 = suffix_loc.arr_high # <<<<<<<<<<<<<< + * step2 = suffix_loc.num_subpatterns + * + */ + __pyx_v_high2 = __pyx_v_suffix_loc->arr_high; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":766 + * low2 = suffix_loc.arr_low + * high2 = suffix_loc.arr_high + * step2 = suffix_loc.num_subpatterns # <<<<<<<<<<<<<< + * + * num_subpatterns = prefix.arity()+1 + */ + __pyx_v_step2 = __pyx_v_suffix_loc->num_subpatterns; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":768 + * step2 = suffix_loc.num_subpatterns + * + * num_subpatterns = prefix.arity()+1 # <<<<<<<<<<<<<< + * + * if algorithm == MERGE: + */ + __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_prefix), __pyx_n_s__arity); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyNumber_Add(__pyx_t_4, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_num_subpatterns = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":770 + * num_subpatterns = prefix.arity()+1 + * + * if algorithm == MERGE: # <<<<<<<<<<<<<< + * result_ptr = self.merge_helper(low1, high1, arr1.arr, step1, + * low2, high2, arr2.arr, step2, + */ + __pyx_t_7 = (__pyx_v_algorithm == __pyx_v_3_sa_MERGE); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":773 + * result_ptr = self.merge_helper(low1, high1, arr1.arr, step1, + * low2, high2, arr2.arr, step2, + * offset_by_one, len_last, num_subpatterns, &result_len) # <<<<<<<<<<<<<< + * else: + * result_ptr = self.baeza_yates_helper(low1, high1, arr1.arr, step1, + */ + __pyx_v_result_ptr = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->merge_helper(__pyx_v_self, __pyx_v_low1, __pyx_v_high1, __pyx_v_arr1->arr, __pyx_v_step1, __pyx_v_low2, __pyx_v_high2, __pyx_v_arr2->arr, __pyx_v_step2, __pyx_v_offset_by_one, __pyx_v_len_last, __pyx_v_num_subpatterns, (&__pyx_v_result_len)); + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":777 + * result_ptr = self.baeza_yates_helper(low1, high1, arr1.arr, step1, + * low2, high2, arr2.arr, step2, + * offset_by_one, len_last, num_subpatterns, &result_len) # <<<<<<<<<<<<<< + * + * if result_len == 0: + */ + __pyx_v_result_ptr = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->baeza_yates_helper(__pyx_v_self, __pyx_v_low1, __pyx_v_high1, __pyx_v_arr1->arr, __pyx_v_step1, __pyx_v_low2, __pyx_v_high2, __pyx_v_arr2->arr, __pyx_v_step2, __pyx_v_offset_by_one, __pyx_v_len_last, __pyx_v_num_subpatterns, (&__pyx_v_result_len)); + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":779 + * offset_by_one, len_last, num_subpatterns, &result_len) + * + * if result_len == 0: # <<<<<<<<<<<<<< + * free(result_ptr) + * return None + */ + __pyx_t_7 = (__pyx_v_result_len == 0); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":780 + * + * if result_len == 0: + * free(result_ptr) # <<<<<<<<<<<<<< + * return None + * else: + */ + free(__pyx_v_result_ptr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":781 + * if result_len == 0: + * free(result_ptr) + * return None # <<<<<<<<<<<<<< + * else: + * result = IntList() + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_None); + __pyx_r = Py_None; + goto __pyx_L0; + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":783 + * return None + * else: + * result = IntList() # <<<<<<<<<<<<<< + * free(result.arr) + * result.arr = result_ptr + */ + __pyx_t_5 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_v_result = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_5); + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":784 + * else: + * result = IntList() + * free(result.arr) # <<<<<<<<<<<<<< + * result.arr = result_ptr + * result.len = result_len + */ + free(__pyx_v_result->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":785 + * result = IntList() + * free(result.arr) + * result.arr = result_ptr # <<<<<<<<<<<<<< + * result.len = result_len + * result.size = result_len + */ + __pyx_v_result->arr = __pyx_v_result_ptr; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":786 + * free(result.arr) + * result.arr = result_ptr + * result.len = result_len # <<<<<<<<<<<<<< + * result.size = result_len + * return PhraseLocation(arr_low=0, arr_high=result_len, arr=result, num_subpatterns=num_subpatterns) + */ + __pyx_v_result->len = __pyx_v_result_len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":787 + * result.arr = result_ptr + * result.len = result_len + * result.size = result_len # <<<<<<<<<<<<<< + * return PhraseLocation(arr_low=0, arr_high=result_len, arr=result, num_subpatterns=num_subpatterns) + * + */ + __pyx_v_result->size = __pyx_v_result_len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":788 + * result.len = result_len + * result.size = result_len + * return PhraseLocation(arr_low=0, arr_high=result_len, arr=result, num_subpatterns=num_subpatterns) # <<<<<<<<<<<<<< + * + * cdef loc2str(self, PhraseLocation loc): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_5)); + if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__arr_low), __pyx_int_0) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(__pyx_v_result_len); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__arr_high), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__arr), ((PyObject *)__pyx_v_result)) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyInt_FromLong(__pyx_v_num_subpatterns); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__num_subpatterns), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_PhraseLocation)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + } + __pyx_L7:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.intersect_helper", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_arr1); + __Pyx_XDECREF((PyObject *)__pyx_v_arr2); + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":790 + * return PhraseLocation(arr_low=0, arr_high=result_len, arr=result, num_subpatterns=num_subpatterns) + * + * cdef loc2str(self, PhraseLocation loc): # <<<<<<<<<<<<<< + * cdef int i, j + * result = "{" + */ + +static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_loc2str(CYTHON_UNUSED struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_3_sa_PhraseLocation *__pyx_v_loc) { + int __pyx_v_i; + int __pyx_v_j; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("loc2str", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":792 + * cdef loc2str(self, PhraseLocation loc): + * cdef int i, j + * result = "{" # <<<<<<<<<<<<<< + * i = 0 + * while i < loc.arr_high: + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_114)); + __pyx_v_result = ((PyObject *)__pyx_kp_s_114); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":793 + * cdef int i, j + * result = "{" + * i = 0 # <<<<<<<<<<<<<< + * while i < loc.arr_high: + * result = result + "(" + */ + __pyx_v_i = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":794 + * result = "{" + * i = 0 + * while i < loc.arr_high: # <<<<<<<<<<<<<< + * result = result + "(" + * for j from i <= j < i + loc.num_subpatterns: + */ + while (1) { + __pyx_t_1 = (__pyx_v_i < __pyx_v_loc->arr_high); + if (!__pyx_t_1) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":795 + * i = 0 + * while i < loc.arr_high: + * result = result + "(" # <<<<<<<<<<<<<< + * for j from i <= j < i + loc.num_subpatterns: + * result = result + ("%d " %loc.arr[j]) + */ + __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_kp_s_115)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":796 + * while i < loc.arr_high: + * result = result + "(" + * for j from i <= j < i + loc.num_subpatterns: # <<<<<<<<<<<<<< + * result = result + ("%d " %loc.arr[j]) + * result = result + ")" + */ + __pyx_t_3 = (__pyx_v_i + __pyx_v_loc->num_subpatterns); + for (__pyx_v_j = __pyx_v_i; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":797 + * result = result + "(" + * for j from i <= j < i + loc.num_subpatterns: + * result = result + ("%d " %loc.arr[j]) # <<<<<<<<<<<<<< + * result = result + ")" + * i = i + loc.num_subpatterns + */ + __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_loc->arr), __pyx_v_j, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_t_2; + __pyx_t_2 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":798 + * for j from i <= j < i + loc.num_subpatterns: + * result = result + ("%d " %loc.arr[j]) + * result = result + ")" # <<<<<<<<<<<<<< + * i = i + loc.num_subpatterns + * result = result + "}" + */ + __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_kp_s_56)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":799 + * result = result + ("%d " %loc.arr[j]) + * result = result + ")" + * i = i + loc.num_subpatterns # <<<<<<<<<<<<<< + * result = result + "}" + * return result + */ + __pyx_v_i = (__pyx_v_i + __pyx_v_loc->num_subpatterns); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":800 + * result = result + ")" + * i = i + loc.num_subpatterns + * result = result + "}" # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_kp_s_116)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":801 + * i = i + loc.num_subpatterns + * result = result + "}" + * return result # <<<<<<<<<<<<<< + * + * cdef PhraseLocation intersect(self, prefix_node, suffix_node, Phrase phrase): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.loc2str", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":803 + * return result + * + * cdef PhraseLocation intersect(self, prefix_node, suffix_node, Phrase phrase): # <<<<<<<<<<<<<< + * cdef Phrase prefix, suffix + * cdef PhraseLocation prefix_loc, suffix_loc, result + */ + +static struct __pyx_obj_3_sa_PhraseLocation *__pyx_f_3_sa_23HieroCachingRuleFactory_intersect(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_prefix_node, PyObject *__pyx_v_suffix_node, struct __pyx_obj_3_sa_Phrase *__pyx_v_phrase) { + struct __pyx_obj_3_sa_Phrase *__pyx_v_prefix = 0; + struct __pyx_obj_3_sa_Phrase *__pyx_v_suffix = 0; + struct __pyx_obj_3_sa_PhraseLocation *__pyx_v_prefix_loc = 0; + struct __pyx_obj_3_sa_PhraseLocation *__pyx_v_suffix_loc = 0; + struct __pyx_obj_3_sa_PhraseLocation *__pyx_v_result = 0; + CYTHON_UNUSED PyObject *__pyx_v_intersect_method = NULL; + struct __pyx_obj_3_sa_PhraseLocation *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("intersect", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":807 + * cdef PhraseLocation prefix_loc, suffix_loc, result + * + * prefix = prefix_node.phrase # <<<<<<<<<<<<<< + * suffix = suffix_node.phrase + * prefix_loc = prefix_node.phrase_location + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_prefix_node, __pyx_n_s__phrase); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 807; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_3_sa_Phrase))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 807; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_prefix = ((struct __pyx_obj_3_sa_Phrase *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":808 + * + * prefix = prefix_node.phrase + * suffix = suffix_node.phrase # <<<<<<<<<<<<<< + * prefix_loc = prefix_node.phrase_location + * suffix_loc = suffix_node.phrase_location + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_suffix_node, __pyx_n_s__phrase); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_3_sa_Phrase))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 808; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_suffix = ((struct __pyx_obj_3_sa_Phrase *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":809 + * prefix = prefix_node.phrase + * suffix = suffix_node.phrase + * prefix_loc = prefix_node.phrase_location # <<<<<<<<<<<<<< + * suffix_loc = suffix_node.phrase_location + * + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_prefix_node, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 809; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_3_sa_PhraseLocation))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 809; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_prefix_loc = ((struct __pyx_obj_3_sa_PhraseLocation *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":810 + * suffix = suffix_node.phrase + * prefix_loc = prefix_node.phrase_location + * suffix_loc = suffix_node.phrase_location # <<<<<<<<<<<<<< + * + * result = self.get_precomputed_collocation(phrase) + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_suffix_node, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 810; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_3_sa_PhraseLocation))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 810; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_suffix_loc = ((struct __pyx_obj_3_sa_PhraseLocation *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":812 + * suffix_loc = suffix_node.phrase_location + * + * result = self.get_precomputed_collocation(phrase) # <<<<<<<<<<<<<< + * if result is not None: + * intersect_method = "precomputed" + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s_117); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_v_phrase)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_phrase)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_phrase)); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_3_sa_PhraseLocation))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_result = ((struct __pyx_obj_3_sa_PhraseLocation *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":813 + * + * result = self.get_precomputed_collocation(phrase) + * if result is not None: # <<<<<<<<<<<<<< + * intersect_method = "precomputed" + * + */ + __pyx_t_4 = (((PyObject *)__pyx_v_result) != Py_None); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":814 + * result = self.get_precomputed_collocation(phrase) + * if result is not None: + * intersect_method = "precomputed" # <<<<<<<<<<<<<< + * + * if result is None: + */ + __Pyx_INCREF(((PyObject *)__pyx_n_s__precomputed)); + __pyx_v_intersect_method = ((PyObject *)__pyx_n_s__precomputed); + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":816 + * intersect_method = "precomputed" + * + * if result is None: # <<<<<<<<<<<<<< + * if self.use_baeza_yates: + * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, BAEZA_YATES) + */ + __pyx_t_4 = (((PyObject *)__pyx_v_result) == Py_None); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":817 + * + * if result is None: + * if self.use_baeza_yates: # <<<<<<<<<<<<<< + * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, BAEZA_YATES) + * intersect_method="double binary" + */ + if (__pyx_v_self->use_baeza_yates) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":818 + * if result is None: + * if self.use_baeza_yates: + * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, BAEZA_YATES) # <<<<<<<<<<<<<< + * intersect_method="double binary" + * else: + */ + __pyx_t_3 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->intersect_helper(__pyx_v_self, __pyx_v_prefix, __pyx_v_suffix, __pyx_v_prefix_loc, __pyx_v_suffix_loc, __pyx_v_3_sa_BAEZA_YATES); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_3_sa_PhraseLocation))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_v_result)); + __pyx_v_result = ((struct __pyx_obj_3_sa_PhraseLocation *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":819 + * if self.use_baeza_yates: + * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, BAEZA_YATES) + * intersect_method="double binary" # <<<<<<<<<<<<<< + * else: + * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, MERGE) + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_118)); + __Pyx_XDECREF(__pyx_v_intersect_method); + __pyx_v_intersect_method = ((PyObject *)__pyx_kp_s_118); + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":821 + * intersect_method="double binary" + * else: + * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, MERGE) # <<<<<<<<<<<<<< + * intersect_method="merge" + * return result + */ + __pyx_t_3 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->intersect_helper(__pyx_v_self, __pyx_v_prefix, __pyx_v_suffix, __pyx_v_prefix_loc, __pyx_v_suffix_loc, __pyx_v_3_sa_MERGE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_3_sa_PhraseLocation))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_v_result)); + __pyx_v_result = ((struct __pyx_obj_3_sa_PhraseLocation *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":822 + * else: + * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, MERGE) + * intersect_method="merge" # <<<<<<<<<<<<<< + * return result + * + */ + __Pyx_INCREF(((PyObject *)__pyx_n_s__merge)); + __Pyx_XDECREF(__pyx_v_intersect_method); + __pyx_v_intersect_method = ((PyObject *)__pyx_n_s__merge); + } + __pyx_L5:; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":823 + * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, MERGE) + * intersect_method="merge" + * return result # <<<<<<<<<<<<<< + * + * def advance(self, frontier, res, fwords): + */ + __Pyx_XDECREF(((PyObject *)__pyx_r)); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = ((struct __pyx_obj_3_sa_PhraseLocation *)Py_None); __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.intersect", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_prefix); + __Pyx_XDECREF((PyObject *)__pyx_v_suffix); + __Pyx_XDECREF((PyObject *)__pyx_v_prefix_loc); + __Pyx_XDECREF((PyObject *)__pyx_v_suffix_loc); + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XDECREF(__pyx_v_intersect_method); + __Pyx_XGIVEREF((PyObject *)__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_13advance(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_13advance(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_frontier = 0; + PyObject *__pyx_v_res = 0; + PyObject *__pyx_v_fwords = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("advance (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__frontier,&__pyx_n_s__res,&__pyx_n_s__fwords,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__frontier)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__res)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("advance", 1, 3, 3, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fwords)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("advance", 1, 3, 3, 2); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "advance") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_frontier = values[0]; + __pyx_v_res = values[1]; + __pyx_v_fwords = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("advance", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 825; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.advance", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_23HieroCachingRuleFactory_12advance(((struct __pyx_obj_3_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_frontier, __pyx_v_res, __pyx_v_fwords); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":825 + * return result + * + * def advance(self, frontier, res, fwords): # <<<<<<<<<<<<<< + * cdef unsigned na + * nf = [] + */ + +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_12advance(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_frontier, PyObject *__pyx_v_res, PyObject *__pyx_v_fwords) { + unsigned int __pyx_v_na; + PyObject *__pyx_v_nf = NULL; + PyObject *__pyx_v_toskip = NULL; + PyObject *__pyx_v_i = NULL; + PyObject *__pyx_v_alt = NULL; + PyObject *__pyx_v_pathlen = NULL; + PyObject *__pyx_v_spanlen = NULL; + PyObject *__pyx_v_ni = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *(*__pyx_t_8)(PyObject *); + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + int __pyx_t_12; + Py_ssize_t __pyx_t_13; + int __pyx_t_14; + int __pyx_t_15; + unsigned int __pyx_t_16; + int __pyx_t_17; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("advance", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":827 + * def advance(self, frontier, res, fwords): + * cdef unsigned na + * nf = [] # <<<<<<<<<<<<<< + * for (toskip, (i, alt, pathlen)) in frontier: + * spanlen = fwords[i][alt][2] + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_nf = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":828 + * cdef unsigned na + * nf = [] + * for (toskip, (i, alt, pathlen)) in frontier: # <<<<<<<<<<<<<< + * spanlen = fwords[i][alt][2] + * if (toskip == 0): + */ + if (PyList_CheckExact(__pyx_v_frontier) || PyTuple_CheckExact(__pyx_v_frontier)) { + __pyx_t_1 = __pyx_v_frontier; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_frontier); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) { + PyObject* sequence = __pyx_t_4; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_5 = PyList_GET_ITEM(sequence, 0); + __pyx_t_6 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); + #else + __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } else + { + Py_ssize_t index = -1; + __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext; + index = 0; __pyx_t_5 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_5); + index = 1; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed; + __Pyx_GOTREF(__pyx_t_6); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L6_unpacking_done; + __pyx_L5_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L6_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_toskip); + __pyx_v_toskip = __pyx_t_5; + __pyx_t_5 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) { + PyObject* sequence = __pyx_t_6; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 3)) { + if (size > 3) __Pyx_RaiseTooManyValuesError(3); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 2); + } else { + __pyx_t_7 = PyList_GET_ITEM(sequence, 0); + __pyx_t_9 = PyList_GET_ITEM(sequence, 1); + __pyx_t_10 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + #else + __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_10 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } else + { + Py_ssize_t index = -1; + __pyx_t_11 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_8 = Py_TYPE(__pyx_t_11)->tp_iternext; + index = 0; __pyx_t_7 = __pyx_t_8(__pyx_t_11); if (unlikely(!__pyx_t_7)) goto __pyx_L7_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + index = 1; __pyx_t_9 = __pyx_t_8(__pyx_t_11); if (unlikely(!__pyx_t_9)) goto __pyx_L7_unpacking_failed; + __Pyx_GOTREF(__pyx_t_9); + index = 2; __pyx_t_10 = __pyx_t_8(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L7_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_11), 3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = NULL; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L8_unpacking_done; + __pyx_L7_unpacking_failed:; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_8 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L8_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_i); + __pyx_v_i = __pyx_t_7; + __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_v_alt); + __pyx_v_alt = __pyx_t_9; + __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_v_pathlen); + __pyx_v_pathlen = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":829 + * nf = [] + * for (toskip, (i, alt, pathlen)) in frontier: + * spanlen = fwords[i][alt][2] # <<<<<<<<<<<<<< + * if (toskip == 0): + * res.append((i, alt, pathlen)) + */ + __pyx_t_4 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_i); if (!__pyx_t_4) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = PyObject_GetItem(__pyx_t_4, __pyx_v_alt); if (!__pyx_t_6) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_6, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_v_spanlen); + __pyx_v_spanlen = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":830 + * for (toskip, (i, alt, pathlen)) in frontier: + * spanlen = fwords[i][alt][2] + * if (toskip == 0): # <<<<<<<<<<<<<< + * res.append((i, alt, pathlen)) + * ni = i + spanlen + */ + __pyx_t_4 = PyObject_RichCompare(__pyx_v_toskip, __pyx_int_0, Py_EQ); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_12) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":831 + * spanlen = fwords[i][alt][2] + * if (toskip == 0): + * res.append((i, alt, pathlen)) # <<<<<<<<<<<<<< + * ni = i + spanlen + * if (ni < len(fwords) and (pathlen + 1) < self.max_initial_size): + */ + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + __Pyx_INCREF(__pyx_v_alt); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_alt); + __Pyx_GIVEREF(__pyx_v_alt); + __Pyx_INCREF(__pyx_v_pathlen); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_pathlen); + __Pyx_GIVEREF(__pyx_v_pathlen); + __pyx_t_6 = __Pyx_PyObject_Append(__pyx_v_res, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L9; + } + __pyx_L9:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":832 + * if (toskip == 0): + * res.append((i, alt, pathlen)) + * ni = i + spanlen # <<<<<<<<<<<<<< + * if (ni < len(fwords) and (pathlen + 1) < self.max_initial_size): + * for na in range(len(fwords[ni])): + */ + __pyx_t_6 = PyNumber_Add(__pyx_v_i, __pyx_v_spanlen); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_v_ni); + __pyx_v_ni = __pyx_t_6; + __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":833 + * res.append((i, alt, pathlen)) + * ni = i + spanlen + * if (ni < len(fwords) and (pathlen + 1) < self.max_initial_size): # <<<<<<<<<<<<<< + * for na in range(len(fwords[ni])): + * nf.append((toskip - 1, (ni, na, pathlen + 1))) + */ + __pyx_t_13 = PyObject_Length(__pyx_v_fwords); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyInt_FromSsize_t(__pyx_t_13); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = PyObject_RichCompare(__pyx_v_ni, __pyx_t_6, Py_LT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_12) { + __pyx_t_4 = PyNumber_Add(__pyx_v_pathlen, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = PyInt_FromLong(__pyx_v_self->max_initial_size); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_t_6, Py_LT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_15 = __pyx_t_14; + } else { + __pyx_t_15 = __pyx_t_12; + } + if (__pyx_t_15) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":834 + * ni = i + spanlen + * if (ni < len(fwords) and (pathlen + 1) < self.max_initial_size): + * for na in range(len(fwords[ni])): # <<<<<<<<<<<<<< + * nf.append((toskip - 1, (ni, na, pathlen + 1))) + * if (len(nf) > 0): + */ + __pyx_t_5 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ni); if (!__pyx_t_5) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_13 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_13; __pyx_t_16+=1) { + __pyx_v_na = __pyx_t_16; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":835 + * if (ni < len(fwords) and (pathlen + 1) < self.max_initial_size): + * for na in range(len(fwords[ni])): + * nf.append((toskip - 1, (ni, na, pathlen + 1))) # <<<<<<<<<<<<<< + * if (len(nf) > 0): + * return self.advance(nf, res, fwords) + */ + __pyx_t_5 = PyNumber_Subtract(__pyx_v_toskip, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyLong_FromUnsignedLong(__pyx_v_na); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_4 = PyNumber_Add(__pyx_v_pathlen, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_v_ni); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_ni); + __Pyx_GIVEREF(__pyx_v_ni); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_6 = 0; + __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_t_10)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); + __pyx_t_5 = 0; + __pyx_t_10 = 0; + __pyx_t_17 = PyList_Append(__pyx_v_nf, ((PyObject *)__pyx_t_4)); if (unlikely(__pyx_t_17 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + } + goto __pyx_L10; + } + __pyx_L10:; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":836 + * for na in range(len(fwords[ni])): + * nf.append((toskip - 1, (ni, na, pathlen + 1))) + * if (len(nf) > 0): # <<<<<<<<<<<<<< + * return self.advance(nf, res, fwords) + * else: + */ + __pyx_t_2 = PyList_GET_SIZE(((PyObject *)__pyx_v_nf)); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_15 = (__pyx_t_2 > 0); + if (__pyx_t_15) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":837 + * nf.append((toskip - 1, (ni, na, pathlen + 1))) + * if (len(nf) > 0): + * return self.advance(nf, res, fwords) # <<<<<<<<<<<<<< + * else: + * return res + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__advance); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(((PyObject *)__pyx_v_nf)); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_nf)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_nf)); + __Pyx_INCREF(__pyx_v_res); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_res); + __Pyx_GIVEREF(__pyx_v_res); + __Pyx_INCREF(__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_fwords); + __Pyx_GIVEREF(__pyx_v_fwords); + __pyx_t_10 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_r = __pyx_t_10; + __pyx_t_10 = 0; + goto __pyx_L0; + goto __pyx_L13; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":839 + * return self.advance(nf, res, fwords) + * else: + * return res # <<<<<<<<<<<<<< + * + * def get_all_nodes_isteps_away(self, skip, i, spanlen, pathlen, fwords, next_states, reachable_buffer): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_res); + __pyx_r = __pyx_v_res; + goto __pyx_L0; + } + __pyx_L13:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.advance", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_nf); + __Pyx_XDECREF(__pyx_v_toskip); + __Pyx_XDECREF(__pyx_v_i); + __Pyx_XDECREF(__pyx_v_alt); + __Pyx_XDECREF(__pyx_v_pathlen); + __Pyx_XDECREF(__pyx_v_spanlen); + __Pyx_XDECREF(__pyx_v_ni); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_15get_all_nodes_isteps_away(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_15get_all_nodes_isteps_away(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_skip = 0; + PyObject *__pyx_v_i = 0; + PyObject *__pyx_v_spanlen = 0; + PyObject *__pyx_v_pathlen = 0; + PyObject *__pyx_v_fwords = 0; + PyObject *__pyx_v_next_states = 0; + PyObject *__pyx_v_reachable_buffer = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("get_all_nodes_isteps_away (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__skip,&__pyx_n_s__i,&__pyx_n_s__spanlen,&__pyx_n_s__pathlen,&__pyx_n_s__fwords,&__pyx_n_s__next_states,&__pyx_n_s__reachable_buffer,0}; + PyObject* values[7] = {0,0,0,0,0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__skip)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__i)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__spanlen)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, 2); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 3: + if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pathlen)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, 3); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 4: + if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fwords)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, 4); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 5: + if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__next_states)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, 5); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 6: + if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__reachable_buffer)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, 6); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_all_nodes_isteps_away") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 7) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + } + __pyx_v_skip = values[0]; + __pyx_v_i = values[1]; + __pyx_v_spanlen = values[2]; + __pyx_v_pathlen = values[3]; + __pyx_v_fwords = values[4]; + __pyx_v_next_states = values[5]; + __pyx_v_reachable_buffer = values[6]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("get_all_nodes_isteps_away", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.get_all_nodes_isteps_away", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_23HieroCachingRuleFactory_14get_all_nodes_isteps_away(((struct __pyx_obj_3_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_skip, __pyx_v_i, __pyx_v_spanlen, __pyx_v_pathlen, __pyx_v_fwords, __pyx_v_next_states, __pyx_v_reachable_buffer); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":841 + * return res + * + * def get_all_nodes_isteps_away(self, skip, i, spanlen, pathlen, fwords, next_states, reachable_buffer): # <<<<<<<<<<<<<< + * cdef unsigned alt_it + * frontier = [] + */ + +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_14get_all_nodes_isteps_away(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_skip, PyObject *__pyx_v_i, PyObject *__pyx_v_spanlen, PyObject *__pyx_v_pathlen, PyObject *__pyx_v_fwords, PyObject *__pyx_v_next_states, PyObject *__pyx_v_reachable_buffer) { + PyObject *__pyx_v_frontier = NULL; + PyObject *__pyx_v_key = NULL; + PyObject *__pyx_v_reachable = NULL; + PyObject *__pyx_v_nextreachable = NULL; + PyObject *__pyx_v_next_id = NULL; + PyObject *__pyx_v_jump = NULL; + PyObject *__pyx_v_alt_id = NULL; + PyObject *__pyx_v_newel = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + PyObject *(*__pyx_t_6)(PyObject *); + Py_ssize_t __pyx_t_7; + PyObject *(*__pyx_t_8)(PyObject *); + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + Py_ssize_t __pyx_t_11; + PyObject *(*__pyx_t_12)(PyObject *); + PyObject *__pyx_t_13 = NULL; + int __pyx_t_14; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_all_nodes_isteps_away", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":843 + * def get_all_nodes_isteps_away(self, skip, i, spanlen, pathlen, fwords, next_states, reachable_buffer): + * cdef unsigned alt_it + * frontier = [] # <<<<<<<<<<<<<< + * if (i+spanlen+skip >= len(next_states)): + * return frontier + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 843; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_frontier = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":844 + * cdef unsigned alt_it + * frontier = [] + * if (i+spanlen+skip >= len(next_states)): # <<<<<<<<<<<<<< + * return frontier + * key = tuple([i,spanlen]) + */ + __pyx_t_1 = PyNumber_Add(__pyx_v_i, __pyx_v_spanlen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_v_skip); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = PyObject_Length(__pyx_v_next_states); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_1, Py_GE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":845 + * frontier = [] + * if (i+spanlen+skip >= len(next_states)): + * return frontier # <<<<<<<<<<<<<< + * key = tuple([i,spanlen]) + * reachable = [] + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_frontier)); + __pyx_r = ((PyObject *)__pyx_v_frontier); + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":846 + * if (i+spanlen+skip >= len(next_states)): + * return frontier + * key = tuple([i,spanlen]) # <<<<<<<<<<<<<< + * reachable = [] + * if (key in reachable_buffer): + */ + __pyx_t_4 = PyList_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_i); + PyList_SET_ITEM(__pyx_t_4, 0, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + __Pyx_INCREF(__pyx_v_spanlen); + PyList_SET_ITEM(__pyx_t_4, 1, __pyx_v_spanlen); + __Pyx_GIVEREF(__pyx_v_spanlen); + __pyx_t_1 = ((PyObject *)PyList_AsTuple(__pyx_t_4)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __pyx_v_key = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":847 + * return frontier + * key = tuple([i,spanlen]) + * reachable = [] # <<<<<<<<<<<<<< + * if (key in reachable_buffer): + * reachable = reachable_buffer[key] + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 847; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_reachable = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":848 + * key = tuple([i,spanlen]) + * reachable = [] + * if (key in reachable_buffer): # <<<<<<<<<<<<<< + * reachable = reachable_buffer[key] + * else: + */ + __pyx_t_5 = ((PySequence_Contains(__pyx_v_reachable_buffer, ((PyObject *)__pyx_v_key)))); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 848; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":849 + * reachable = [] + * if (key in reachable_buffer): + * reachable = reachable_buffer[key] # <<<<<<<<<<<<<< + * else: + * reachable = self.reachable(fwords, i, spanlen) + */ + __pyx_t_1 = PyObject_GetItem(__pyx_v_reachable_buffer, ((PyObject *)__pyx_v_key)); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_v_reachable); + __pyx_v_reachable = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":851 + * reachable = reachable_buffer[key] + * else: + * reachable = self.reachable(fwords, i, spanlen) # <<<<<<<<<<<<<< + * reachable_buffer[key] = reachable + * for nextreachable in reachable: + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__reachable); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 851; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 851; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_fwords); + __Pyx_GIVEREF(__pyx_v_fwords); + __Pyx_INCREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + __Pyx_INCREF(__pyx_v_spanlen); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_spanlen); + __Pyx_GIVEREF(__pyx_v_spanlen); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 851; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_v_reachable); + __pyx_v_reachable = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":852 + * else: + * reachable = self.reachable(fwords, i, spanlen) + * reachable_buffer[key] = reachable # <<<<<<<<<<<<<< + * for nextreachable in reachable: + * for next_id in next_states[nextreachable]: + */ + if (PyObject_SetItem(__pyx_v_reachable_buffer, ((PyObject *)__pyx_v_key), __pyx_v_reachable) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 852; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":853 + * reachable = self.reachable(fwords, i, spanlen) + * reachable_buffer[key] = reachable + * for nextreachable in reachable: # <<<<<<<<<<<<<< + * for next_id in next_states[nextreachable]: + * jump = self.shortest(fwords,i,next_id) + */ + if (PyList_CheckExact(__pyx_v_reachable) || PyTuple_CheckExact(__pyx_v_reachable)) { + __pyx_t_2 = __pyx_v_reachable; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; + __pyx_t_6 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_reachable); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_4 = __pyx_t_6(__pyx_t_2); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 853; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_nextreachable); + __pyx_v_nextreachable = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":854 + * reachable_buffer[key] = reachable + * for nextreachable in reachable: + * for next_id in next_states[nextreachable]: # <<<<<<<<<<<<<< + * jump = self.shortest(fwords,i,next_id) + * if jump < skip: + */ + __pyx_t_4 = PyObject_GetItem(__pyx_v_next_states, __pyx_v_nextreachable); if (!__pyx_t_4) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + if (PyList_CheckExact(__pyx_t_4) || PyTuple_CheckExact(__pyx_t_4)) { + __pyx_t_1 = __pyx_t_4; __Pyx_INCREF(__pyx_t_1); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + } else { + __pyx_t_7 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + for (;;) { + if (!__pyx_t_8 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_8 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_4 = __pyx_t_8(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 854; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_next_id); + __pyx_v_next_id = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":855 + * for nextreachable in reachable: + * for next_id in next_states[nextreachable]: + * jump = self.shortest(fwords,i,next_id) # <<<<<<<<<<<<<< + * if jump < skip: + * continue + */ + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__shortest); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 855; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 855; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_INCREF(__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_fwords); + __Pyx_GIVEREF(__pyx_v_fwords); + __Pyx_INCREF(__pyx_v_i); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_i); + __Pyx_GIVEREF(__pyx_v_i); + __Pyx_INCREF(__pyx_v_next_id); + PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_v_next_id); + __Pyx_GIVEREF(__pyx_v_next_id); + __pyx_t_10 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 855; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_v_jump); + __pyx_v_jump = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":856 + * for next_id in next_states[nextreachable]: + * jump = self.shortest(fwords,i,next_id) + * if jump < skip: # <<<<<<<<<<<<<< + * continue + * if pathlen+jump <= self.max_initial_size: + */ + __pyx_t_10 = PyObject_RichCompare(__pyx_v_jump, __pyx_v_skip, Py_LT); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 856; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 856; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":857 + * jump = self.shortest(fwords,i,next_id) + * if jump < skip: + * continue # <<<<<<<<<<<<<< + * if pathlen+jump <= self.max_initial_size: + * for alt_id in range(len(fwords[next_id])): + */ + goto __pyx_L7_continue; + goto __pyx_L9; + } + __pyx_L9:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":858 + * if jump < skip: + * continue + * if pathlen+jump <= self.max_initial_size: # <<<<<<<<<<<<<< + * for alt_id in range(len(fwords[next_id])): + * if (fwords[next_id][alt_id][0] != EPSILON): + */ + __pyx_t_10 = PyNumber_Add(__pyx_v_pathlen, __pyx_v_jump); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 858; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyInt_FromLong(__pyx_v_self->max_initial_size); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 858; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_10, __pyx_t_9, Py_LE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 858; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 858; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":859 + * continue + * if pathlen+jump <= self.max_initial_size: + * for alt_id in range(len(fwords[next_id])): # <<<<<<<<<<<<<< + * if (fwords[next_id][alt_id][0] != EPSILON): + * newel = (next_id,alt_id,pathlen+jump) + */ + __pyx_t_4 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_next_id); if (!__pyx_t_4) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_11 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_11); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + if (PyList_CheckExact(__pyx_t_4) || PyTuple_CheckExact(__pyx_t_4)) { + __pyx_t_9 = __pyx_t_4; __Pyx_INCREF(__pyx_t_9); __pyx_t_11 = 0; + __pyx_t_12 = NULL; + } else { + __pyx_t_11 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_12 = Py_TYPE(__pyx_t_9)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + for (;;) { + if (!__pyx_t_12 && PyList_CheckExact(__pyx_t_9)) { + if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_9)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_11); __Pyx_INCREF(__pyx_t_4); __pyx_t_11++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_9, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_12 && PyTuple_CheckExact(__pyx_t_9)) { + if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_9)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_11); __Pyx_INCREF(__pyx_t_4); __pyx_t_11++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_9, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_4 = __pyx_t_12(__pyx_t_9); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_alt_id); + __pyx_v_alt_id = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":860 + * if pathlen+jump <= self.max_initial_size: + * for alt_id in range(len(fwords[next_id])): + * if (fwords[next_id][alt_id][0] != EPSILON): # <<<<<<<<<<<<<< + * newel = (next_id,alt_id,pathlen+jump) + * if newel not in frontier: + */ + __pyx_t_4 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_next_id); if (!__pyx_t_4) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_10 = PyObject_GetItem(__pyx_t_4, __pyx_v_alt_id); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_10, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = PyInt_FromLong(__pyx_v_3_sa_EPSILON); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_13 = PyObject_RichCompare(__pyx_t_4, __pyx_t_10, Py_NE); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_13); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":861 + * for alt_id in range(len(fwords[next_id])): + * if (fwords[next_id][alt_id][0] != EPSILON): + * newel = (next_id,alt_id,pathlen+jump) # <<<<<<<<<<<<<< + * if newel not in frontier: + * frontier.append((next_id,alt_id,pathlen+jump)) + */ + __pyx_t_13 = PyNumber_Add(__pyx_v_pathlen, __pyx_v_jump); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_v_next_id); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_next_id); + __Pyx_GIVEREF(__pyx_v_next_id); + __Pyx_INCREF(__pyx_v_alt_id); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_alt_id); + __Pyx_GIVEREF(__pyx_v_alt_id); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_13); + __Pyx_GIVEREF(__pyx_t_13); + __pyx_t_13 = 0; + __Pyx_XDECREF(((PyObject *)__pyx_v_newel)); + __pyx_v_newel = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":862 + * if (fwords[next_id][alt_id][0] != EPSILON): + * newel = (next_id,alt_id,pathlen+jump) + * if newel not in frontier: # <<<<<<<<<<<<<< + * frontier.append((next_id,alt_id,pathlen+jump)) + * return frontier + */ + __pyx_t_5 = (__Pyx_NegateNonNeg(PySequence_Contains(((PyObject *)__pyx_v_frontier), ((PyObject *)__pyx_v_newel)))); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 862; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":863 + * newel = (next_id,alt_id,pathlen+jump) + * if newel not in frontier: + * frontier.append((next_id,alt_id,pathlen+jump)) # <<<<<<<<<<<<<< + * return frontier + * + */ + __pyx_t_10 = PyNumber_Add(__pyx_v_pathlen, __pyx_v_jump); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_13 = PyTuple_New(3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_INCREF(__pyx_v_next_id); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_v_next_id); + __Pyx_GIVEREF(__pyx_v_next_id); + __Pyx_INCREF(__pyx_v_alt_id); + PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_v_alt_id); + __Pyx_GIVEREF(__pyx_v_alt_id); + PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_t_10 = 0; + __pyx_t_14 = PyList_Append(__pyx_v_frontier, ((PyObject *)__pyx_t_13)); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + goto __pyx_L14; + } + __pyx_L14:; + goto __pyx_L13; + } + __pyx_L13:; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L10; + } + __pyx_L10:; + __pyx_L7_continue:; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":864 + * if newel not in frontier: + * frontier.append((next_id,alt_id,pathlen+jump)) + * return frontier # <<<<<<<<<<<<<< + * + * def reachable(self, fwords, ifrom, dist): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_frontier)); + __pyx_r = ((PyObject *)__pyx_v_frontier); + 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_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.get_all_nodes_isteps_away", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_frontier); + __Pyx_XDECREF(__pyx_v_key); + __Pyx_XDECREF(__pyx_v_reachable); + __Pyx_XDECREF(__pyx_v_nextreachable); + __Pyx_XDECREF(__pyx_v_next_id); + __Pyx_XDECREF(__pyx_v_jump); + __Pyx_XDECREF(__pyx_v_alt_id); + __Pyx_XDECREF(__pyx_v_newel); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_17reachable(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_17reachable(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_fwords = 0; + PyObject *__pyx_v_ifrom = 0; + PyObject *__pyx_v_dist = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("reachable (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fwords,&__pyx_n_s__ifrom,&__pyx_n_s__dist,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fwords)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ifrom)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("reachable", 1, 3, 3, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dist)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("reachable", 1, 3, 3, 2); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "reachable") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_fwords = values[0]; + __pyx_v_ifrom = values[1]; + __pyx_v_dist = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("reachable", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 866; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.reachable", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_23HieroCachingRuleFactory_16reachable(((struct __pyx_obj_3_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_fwords, __pyx_v_ifrom, __pyx_v_dist); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":866 + * return frontier + * + * def reachable(self, fwords, ifrom, dist): # <<<<<<<<<<<<<< + * ret = [] + * if (ifrom >= len(fwords)): + */ + +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_16reachable(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_ifrom, PyObject *__pyx_v_dist) { + PyObject *__pyx_v_ret = NULL; + PyObject *__pyx_v_alt_id = NULL; + PyObject *__pyx_v_ifromchild = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + Py_ssize_t __pyx_t_10; + PyObject *(*__pyx_t_11)(PyObject *); + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("reachable", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":867 + * + * def reachable(self, fwords, ifrom, dist): + * ret = [] # <<<<<<<<<<<<<< + * if (ifrom >= len(fwords)): + * return ret + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 867; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_ret = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":868 + * def reachable(self, fwords, ifrom, dist): + * ret = [] + * if (ifrom >= len(fwords)): # <<<<<<<<<<<<<< + * return ret + * for alt_id in range(len(fwords[ifrom])): + */ + __pyx_t_2 = PyObject_Length(__pyx_v_fwords); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_RichCompare(__pyx_v_ifrom, __pyx_t_1, Py_GE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 868; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":869 + * ret = [] + * if (ifrom >= len(fwords)): + * return ret # <<<<<<<<<<<<<< + * for alt_id in range(len(fwords[ifrom])): + * if (fwords[ifrom][alt_id][0] == EPSILON): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_ret)); + __pyx_r = ((PyObject *)__pyx_v_ret); + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":870 + * if (ifrom >= len(fwords)): + * return ret + * for alt_id in range(len(fwords[ifrom])): # <<<<<<<<<<<<<< + * if (fwords[ifrom][alt_id][0] == EPSILON): + * ret.extend(self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist)) + */ + __pyx_t_3 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ifrom); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_5 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_3 = __pyx_t_5(__pyx_t_1); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_alt_id); + __pyx_v_alt_id = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":871 + * return ret + * for alt_id in range(len(fwords[ifrom])): + * if (fwords[ifrom][alt_id][0] == EPSILON): # <<<<<<<<<<<<<< + * ret.extend(self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist)) + * else: + */ + __pyx_t_3 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ifrom); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PyObject_GetItem(__pyx_t_3, __pyx_v_alt_id); if (!__pyx_t_6) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_6, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = PyInt_FromLong(__pyx_v_3_sa_EPSILON); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PyObject_RichCompare(__pyx_t_3, __pyx_t_6, Py_EQ); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":872 + * for alt_id in range(len(fwords[ifrom])): + * if (fwords[ifrom][alt_id][0] == EPSILON): + * ret.extend(self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist)) # <<<<<<<<<<<<<< + * else: + * if (dist==0): + */ + __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_ret), __pyx_n_s__extend); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__reachable); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_3 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ifrom); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = PyObject_GetItem(__pyx_t_3, __pyx_v_alt_id); if (!__pyx_t_8) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_8, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = PyNumber_Add(__pyx_v_ifrom, __pyx_t_3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_fwords); + __Pyx_GIVEREF(__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __Pyx_INCREF(__pyx_v_dist); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_dist); + __Pyx_GIVEREF(__pyx_v_dist); + __pyx_t_8 = 0; + __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L6; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":874 + * ret.extend(self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist)) + * else: + * if (dist==0): # <<<<<<<<<<<<<< + * if (ifrom not in ret): + * ret.append(ifrom) + */ + __pyx_t_8 = PyObject_RichCompare(__pyx_v_dist, __pyx_int_0, Py_EQ); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":875 + * else: + * if (dist==0): + * if (ifrom not in ret): # <<<<<<<<<<<<<< + * ret.append(ifrom) + * else: + */ + __pyx_t_4 = (__Pyx_NegateNonNeg(PySequence_Contains(((PyObject *)__pyx_v_ret), __pyx_v_ifrom))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 875; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":876 + * if (dist==0): + * if (ifrom not in ret): + * ret.append(ifrom) # <<<<<<<<<<<<<< + * else: + * for ifromchild in self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist-1): + */ + __pyx_t_9 = PyList_Append(__pyx_v_ret, __pyx_v_ifrom); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 876; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L8; + } + __pyx_L8:; + goto __pyx_L7; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":878 + * ret.append(ifrom) + * else: + * for ifromchild in self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist-1): # <<<<<<<<<<<<<< + * if (ifromchild not in ret): + * ret.append(ifromchild) + */ + __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__reachable); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ifrom); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_7 = PyObject_GetItem(__pyx_t_3, __pyx_v_alt_id); if (!__pyx_t_7) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_7, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = PyNumber_Add(__pyx_v_ifrom, __pyx_t_3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyNumber_Subtract(__pyx_v_dist, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_fwords); + __Pyx_GIVEREF(__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_7 = 0; + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { + __pyx_t_6 = __pyx_t_3; __Pyx_INCREF(__pyx_t_6); __pyx_t_10 = 0; + __pyx_t_11 = NULL; + } else { + __pyx_t_10 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_11 = Py_TYPE(__pyx_t_6)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (;;) { + if (!__pyx_t_11 && PyList_CheckExact(__pyx_t_6)) { + if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_6)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_10); __Pyx_INCREF(__pyx_t_3); __pyx_t_10++; + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_6, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_11 && PyTuple_CheckExact(__pyx_t_6)) { + if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_6)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_10); __Pyx_INCREF(__pyx_t_3); __pyx_t_10++; + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_6, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_3 = __pyx_t_11(__pyx_t_6); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 878; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + __Pyx_XDECREF(__pyx_v_ifromchild); + __pyx_v_ifromchild = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":879 + * else: + * for ifromchild in self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist-1): + * if (ifromchild not in ret): # <<<<<<<<<<<<<< + * ret.append(ifromchild) + * + */ + __pyx_t_4 = (__Pyx_NegateNonNeg(PySequence_Contains(((PyObject *)__pyx_v_ret), __pyx_v_ifromchild))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 879; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":880 + * for ifromchild in self.reachable(fwords,ifrom+fwords[ifrom][alt_id][2],dist-1): + * if (ifromchild not in ret): + * ret.append(ifromchild) # <<<<<<<<<<<<<< + * + * return ret + */ + __pyx_t_9 = PyList_Append(__pyx_v_ret, __pyx_v_ifromchild); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 880; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L11; + } + __pyx_L11:; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __pyx_L7:; + } + __pyx_L6:; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":882 + * ret.append(ifromchild) + * + * return ret # <<<<<<<<<<<<<< + * + * def shortest(self, fwords, ifrom, ito): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_ret)); + __pyx_r = ((PyObject *)__pyx_v_ret); + 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_3); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.reachable", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_ret); + __Pyx_XDECREF(__pyx_v_alt_id); + __Pyx_XDECREF(__pyx_v_ifromchild); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_19shortest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_19shortest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_fwords = 0; + PyObject *__pyx_v_ifrom = 0; + PyObject *__pyx_v_ito = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("shortest (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fwords,&__pyx_n_s__ifrom,&__pyx_n_s__ito,0}; + PyObject* values[3] = {0,0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fwords)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ifrom)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("shortest", 1, 3, 3, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__ito)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("shortest", 1, 3, 3, 2); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "shortest") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + } + __pyx_v_fwords = values[0]; + __pyx_v_ifrom = values[1]; + __pyx_v_ito = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("shortest", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 884; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.shortest", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_23HieroCachingRuleFactory_18shortest(((struct __pyx_obj_3_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_fwords, __pyx_v_ifrom, __pyx_v_ito); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":884 + * return ret + * + * def shortest(self, fwords, ifrom, ito): # <<<<<<<<<<<<<< + * cdef unsigned alt_id + * min = 1000 + */ + +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_18shortest(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_ifrom, PyObject *__pyx_v_ito) { + unsigned int __pyx_v_alt_id; + PyObject *__pyx_v_min = NULL; + PyObject *__pyx_v_currmin = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + Py_ssize_t __pyx_t_3; + unsigned int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("shortest", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":886 + * def shortest(self, fwords, ifrom, ito): + * cdef unsigned alt_id + * min = 1000 # <<<<<<<<<<<<<< + * if (ifrom > ito): + * return min + */ + __Pyx_INCREF(__pyx_int_1000); + __pyx_v_min = __pyx_int_1000; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":887 + * cdef unsigned alt_id + * min = 1000 + * if (ifrom > ito): # <<<<<<<<<<<<<< + * return min + * if (ifrom == ito): + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_v_ifrom, __pyx_v_ito, Py_GT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":888 + * min = 1000 + * if (ifrom > ito): + * return min # <<<<<<<<<<<<<< + * if (ifrom == ito): + * return 0 + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_min); + __pyx_r = __pyx_v_min; + goto __pyx_L0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":889 + * if (ifrom > ito): + * return min + * if (ifrom == ito): # <<<<<<<<<<<<<< + * return 0 + * for alt_id in range(len(fwords[ifrom])): + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_v_ifrom, __pyx_v_ito, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":890 + * return min + * if (ifrom == ito): + * return 0 # <<<<<<<<<<<<<< + * for alt_id in range(len(fwords[ifrom])): + * currmin = self.shortest(fwords,ifrom+fwords[ifrom][alt_id][2],ito) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_int_0); + __pyx_r = __pyx_int_0; + goto __pyx_L0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":891 + * if (ifrom == ito): + * return 0 + * for alt_id in range(len(fwords[ifrom])): # <<<<<<<<<<<<<< + * currmin = self.shortest(fwords,ifrom+fwords[ifrom][alt_id][2],ito) + * if (fwords[ifrom][alt_id][0] != EPSILON): + */ + __pyx_t_1 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ifrom); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 891; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 891; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_alt_id = __pyx_t_4; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":892 + * return 0 + * for alt_id in range(len(fwords[ifrom])): + * currmin = self.shortest(fwords,ifrom+fwords[ifrom][alt_id][2],ito) # <<<<<<<<<<<<<< + * if (fwords[ifrom][alt_id][0] != EPSILON): + * currmin += 1 + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__shortest); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyObject_GetItem(__pyx_v_fwords, __pyx_v_ifrom); if (!__pyx_t_5) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_5, __pyx_v_alt_id, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_6) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_6, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = PyNumber_Add(__pyx_v_ifrom, __pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_fwords); + __Pyx_GIVEREF(__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + __Pyx_INCREF(__pyx_v_ito); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_ito); + __Pyx_GIVEREF(__pyx_v_ito); + __pyx_t_6 = 0; + __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_v_currmin); + __pyx_v_currmin = __pyx_t_6; + __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":893 + * for alt_id in range(len(fwords[ifrom])): + * currmin = self.shortest(fwords,ifrom+fwords[ifrom][alt_id][2],ito) + * if (fwords[ifrom][alt_id][0] != EPSILON): # <<<<<<<<<<<<<< + * currmin += 1 + * if (currmin 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__min_dist); + if (value) { values[2] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_next_states") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 899; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v__columns = values[0]; + __pyx_v_curr_idx = values[1]; + __pyx_v_min_dist = values[2]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("get_next_states", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 899; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.get_next_states", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_23HieroCachingRuleFactory_20get_next_states(((struct __pyx_obj_3_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v__columns, __pyx_v_curr_idx, __pyx_v_min_dist); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":899 + * return min + * + * def get_next_states(self, _columns, curr_idx, min_dist=2): # <<<<<<<<<<<<<< + * result = [] + * candidate = [[curr_idx,0]] + */ + +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_20get_next_states(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v__columns, PyObject *__pyx_v_curr_idx, PyObject *__pyx_v_min_dist) { + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_v_candidate = NULL; + PyObject *__pyx_v_curr = NULL; + PyObject *__pyx_v_curr_col = NULL; + PyObject *__pyx_v_alt = NULL; + PyObject *__pyx_v_next_id = NULL; + PyObject *__pyx_v_jump = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_next_states", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":900 + * + * def get_next_states(self, _columns, curr_idx, min_dist=2): + * result = [] # <<<<<<<<<<<<<< + * candidate = [[curr_idx,0]] + * + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 900; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":901 + * def get_next_states(self, _columns, curr_idx, min_dist=2): + * result = [] + * candidate = [[curr_idx,0]] # <<<<<<<<<<<<<< + * + * while len(candidate) > 0: + */ + __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 901; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_curr_idx); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_curr_idx); + __Pyx_GIVEREF(__pyx_v_curr_idx); + __Pyx_INCREF(__pyx_int_0); + PyList_SET_ITEM(__pyx_t_1, 1, __pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 901; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_v_candidate = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":903 + * candidate = [[curr_idx,0]] + * + * while len(candidate) > 0: # <<<<<<<<<<<<<< + * curr = candidate.pop() + * if curr[0] >= len(_columns): + */ + while (1) { + __pyx_t_3 = PyList_GET_SIZE(((PyObject *)__pyx_v_candidate)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 903; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = (__pyx_t_3 > 0); + if (!__pyx_t_4) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":904 + * + * while len(candidate) > 0: + * curr = candidate.pop() # <<<<<<<<<<<<<< + * if curr[0] >= len(_columns): + * continue + */ + __pyx_t_2 = __Pyx_PyObject_Pop(((PyObject *)__pyx_v_candidate)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 904; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_v_curr); + __pyx_v_curr = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":905 + * while len(candidate) > 0: + * curr = candidate.pop() + * if curr[0] >= len(_columns): # <<<<<<<<<<<<<< + * continue + * if curr[0] not in result and min_dist <= curr[1] <= self.max_initial_size: + */ + __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_curr, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 905; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyObject_Length(__pyx_v__columns); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 905; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 905; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyObject_RichCompare(__pyx_t_2, __pyx_t_1, Py_GE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 905; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 905; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":906 + * curr = candidate.pop() + * if curr[0] >= len(_columns): + * continue # <<<<<<<<<<<<<< + * if curr[0] not in result and min_dist <= curr[1] <= self.max_initial_size: + * result.append(curr[0]); + */ + goto __pyx_L3_continue; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":907 + * if curr[0] >= len(_columns): + * continue + * if curr[0] not in result and min_dist <= curr[1] <= self.max_initial_size: # <<<<<<<<<<<<<< + * result.append(curr[0]); + * curr_col = _columns[curr[0]] + */ + __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_curr, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = (__Pyx_NegateNonNeg(PySequence_Contains(((PyObject *)__pyx_v_result), __pyx_t_5))); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (__pyx_t_4) { + __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_curr, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyObject_RichCompare(__pyx_v_min_dist, __pyx_t_5, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_PyObject_IsTrue(__pyx_t_1)) { + __Pyx_DECREF(__pyx_t_1); + __pyx_t_2 = PyInt_FromLong(__pyx_v_self->max_initial_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_RichCompare(__pyx_t_5, __pyx_t_2, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 907; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_7 = __pyx_t_6; + } else { + __pyx_t_7 = __pyx_t_4; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":908 + * continue + * if curr[0] not in result and min_dist <= curr[1] <= self.max_initial_size: + * result.append(curr[0]); # <<<<<<<<<<<<<< + * curr_col = _columns[curr[0]] + * for alt in curr_col: + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_curr, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 908; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = PyList_Append(__pyx_v_result, __pyx_t_1); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 908; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":909 + * if curr[0] not in result and min_dist <= curr[1] <= self.max_initial_size: + * result.append(curr[0]); + * curr_col = _columns[curr[0]] # <<<<<<<<<<<<<< + * for alt in curr_col: + * next_id = curr[0]+alt[2] + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_curr, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 909; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyObject_GetItem(__pyx_v__columns, __pyx_t_1); if (!__pyx_t_5) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 909; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_v_curr_col); + __pyx_v_curr_col = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":910 + * result.append(curr[0]); + * curr_col = _columns[curr[0]] + * for alt in curr_col: # <<<<<<<<<<<<<< + * next_id = curr[0]+alt[2] + * jump = 1 + */ + if (PyList_CheckExact(__pyx_v_curr_col) || PyTuple_CheckExact(__pyx_v_curr_col)) { + __pyx_t_5 = __pyx_v_curr_col; __Pyx_INCREF(__pyx_t_5); __pyx_t_3 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_curr_col); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 910; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_9 = Py_TYPE(__pyx_t_5)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_5)) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_5)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_5, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 910; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_5)) { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_5)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_5, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 910; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_1 = __pyx_t_9(__pyx_t_5); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 910; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __Pyx_XDECREF(__pyx_v_alt); + __pyx_v_alt = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":911 + * curr_col = _columns[curr[0]] + * for alt in curr_col: + * next_id = curr[0]+alt[2] # <<<<<<<<<<<<<< + * jump = 1 + * if (alt[0] == EPSILON): + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_curr, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 911; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_alt, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 911; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = PyNumber_Add(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 911; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_v_next_id); + __pyx_v_next_id = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":912 + * for alt in curr_col: + * next_id = curr[0]+alt[2] + * jump = 1 # <<<<<<<<<<<<<< + * if (alt[0] == EPSILON): + * jump = 0 + */ + __Pyx_INCREF(__pyx_int_1); + __Pyx_XDECREF(__pyx_v_jump); + __pyx_v_jump = __pyx_int_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":913 + * next_id = curr[0]+alt[2] + * jump = 1 + * if (alt[0] == EPSILON): # <<<<<<<<<<<<<< + * jump = 0 + * if next_id not in result and min_dist <= curr[1]+jump <= self.max_initial_size+1: + */ + __pyx_t_10 = __Pyx_GetItemInt(__pyx_v_alt, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 913; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = PyInt_FromLong(__pyx_v_3_sa_EPSILON); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 913; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_RichCompare(__pyx_t_10, __pyx_t_2, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 913; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 913; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":914 + * jump = 1 + * if (alt[0] == EPSILON): + * jump = 0 # <<<<<<<<<<<<<< + * if next_id not in result and min_dist <= curr[1]+jump <= self.max_initial_size+1: + * candidate.append([next_id,curr[1]+jump]) + */ + __Pyx_INCREF(__pyx_int_0); + __Pyx_DECREF(__pyx_v_jump); + __pyx_v_jump = __pyx_int_0; + goto __pyx_L9; + } + __pyx_L9:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":915 + * if (alt[0] == EPSILON): + * jump = 0 + * if next_id not in result and min_dist <= curr[1]+jump <= self.max_initial_size+1: # <<<<<<<<<<<<<< + * candidate.append([next_id,curr[1]+jump]) + * return sorted(result); + */ + __pyx_t_7 = (__Pyx_NegateNonNeg(PySequence_Contains(((PyObject *)__pyx_v_result), __pyx_v_next_id))); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_7) { + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_curr, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_v_jump); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_RichCompare(__pyx_v_min_dist, __pyx_t_2, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_PyObject_IsTrue(__pyx_t_1)) { + __Pyx_DECREF(__pyx_t_1); + __pyx_t_10 = PyInt_FromLong((__pyx_v_self->max_initial_size + 1)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_t_10, Py_LE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_6 = __pyx_t_4; + } else { + __pyx_t_6 = __pyx_t_7; + } + if (__pyx_t_6) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":916 + * jump = 0 + * if next_id not in result and min_dist <= curr[1]+jump <= self.max_initial_size+1: + * candidate.append([next_id,curr[1]+jump]) # <<<<<<<<<<<<<< + * return sorted(result); + * + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_curr, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 916; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_v_jump); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 916; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 916; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_next_id); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_next_id); + __Pyx_GIVEREF(__pyx_v_next_id); + PyList_SET_ITEM(__pyx_t_1, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_8 = PyList_Append(__pyx_v_candidate, ((PyObject *)__pyx_t_1)); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 916; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + goto __pyx_L10; + } + __pyx_L10:; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_L3_continue:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":917 + * if next_id not in result and min_dist <= curr[1]+jump <= self.max_initial_size+1: + * candidate.append([next_id,curr[1]+jump]) + * return sorted(result); # <<<<<<<<<<<<<< + * + * def input(self, fwords, models): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 917; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_result)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_result)); + __pyx_t_1 = PyObject_Call(__pyx_builtin_sorted, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 917; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 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_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.get_next_states", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_candidate); + __Pyx_XDECREF(__pyx_v_curr); + __Pyx_XDECREF(__pyx_v_curr_col); + __Pyx_XDECREF(__pyx_v_alt); + __Pyx_XDECREF(__pyx_v_next_id); + __Pyx_XDECREF(__pyx_v_jump); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_3_sa_23HieroCachingRuleFactory_24generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_23input(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_3_sa_23HieroCachingRuleFactory_22input[] = "When this function is called on the RuleFactory,\n it looks up all of the rules that can be used to translate\n the input sentence"; +static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_23input(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_fwords = 0; + PyObject *__pyx_v_models = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("input (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fwords,&__pyx_n_s__models,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fwords)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__models)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("input", 1, 2, 2, 1); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "input") < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_fwords = values[0]; + __pyx_v_models = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("input", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.input", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_23HieroCachingRuleFactory_22input(((struct __pyx_obj_3_sa_HieroCachingRuleFactory *)__pyx_v_self), __pyx_v_fwords, __pyx_v_models); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":919 + * return sorted(result); + * + * def input(self, fwords, models): # <<<<<<<<<<<<<< + * '''When this function is called on the RuleFactory, + * it looks up all of the rules that can be used to translate + */ + +static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_22input(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_models) { + struct __pyx_obj_3_sa___pyx_scope_struct_2_input *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("input", 0); + __pyx_cur_scope = (struct __pyx_obj_3_sa___pyx_scope_struct_2_input *)__pyx_ptype_3_sa___pyx_scope_struct_2_input->tp_new(__pyx_ptype_3_sa___pyx_scope_struct_2_input, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); + __pyx_cur_scope->__pyx_v_fwords = __pyx_v_fwords; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fwords); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_fwords); + __pyx_cur_scope->__pyx_v_models = __pyx_v_models; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_models); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_models); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_3_sa_23HieroCachingRuleFactory_24generator2, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.input", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_3_sa_23HieroCachingRuleFactory_24generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_3_sa___pyx_scope_struct_2_input *__pyx_cur_scope = ((struct __pyx_obj_3_sa___pyx_scope_struct_2_input *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + Py_ssize_t __pyx_t_5; + int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + PyObject *__pyx_t_16 = NULL; + PyObject *(*__pyx_t_17)(PyObject *); + int __pyx_t_18; + int __pyx_t_19; + float __pyx_t_20; + Py_ssize_t __pyx_t_21; + Py_ssize_t __pyx_t_22; + Py_ssize_t __pyx_t_23; + Py_ssize_t __pyx_t_24; + Py_ssize_t __pyx_t_25; + int __pyx_t_26; + PyObject *(*__pyx_t_27)(PyObject *); + int __pyx_t_28; + int __pyx_t_29; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L59_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[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":930 + * cdef Phrase hiero_phrase + * + * flen = len(fwords) # <<<<<<<<<<<<<< + * start_time = monitor_cpu() + * self.extract_time = 0.0 + */ + __pyx_t_1 = PyObject_Length(__pyx_cur_scope->__pyx_v_fwords); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 930; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_flen = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":931 + * + * flen = len(fwords) + * start_time = monitor_cpu() # <<<<<<<<<<<<<< + * self.extract_time = 0.0 + * nodes_isteps_away_buffer = {} + */ + __pyx_cur_scope->__pyx_v_start_time = __pyx_f_3_sa_monitor_cpu(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":932 + * flen = len(fwords) + * start_time = monitor_cpu() + * self.extract_time = 0.0 # <<<<<<<<<<<<<< + * nodes_isteps_away_buffer = {} + * hit = 0 + */ + __pyx_cur_scope->__pyx_v_self->extract_time = 0.0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":933 + * start_time = monitor_cpu() + * self.extract_time = 0.0 + * nodes_isteps_away_buffer = {} # <<<<<<<<<<<<<< + * hit = 0 + * reachable_buffer = {} + */ + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 933; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_cur_scope->__pyx_v_nodes_isteps_away_buffer = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":934 + * self.extract_time = 0.0 + * nodes_isteps_away_buffer = {} + * hit = 0 # <<<<<<<<<<<<<< + * reachable_buffer = {} + * + */ + __pyx_cur_scope->__pyx_v_hit = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":935 + * nodes_isteps_away_buffer = {} + * hit = 0 + * reachable_buffer = {} # <<<<<<<<<<<<<< + * + * # Do not cache between sentences + */ + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 935; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_cur_scope->__pyx_v_reachable_buffer = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":938 + * + * # Do not cache between sentences + * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) # <<<<<<<<<<<<<< + * + * frontier = [] + */ + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_PhraseLocation)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__phrase_location), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 938; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_self->rules->root); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_self->rules->root); + __pyx_cur_scope->__pyx_v_self->rules->root = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":940 + * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) + * + * frontier = [] # <<<<<<<<<<<<<< + * for i in range(len(fwords)): + * for alt in range(0, len(fwords[i])): + */ + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 940; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_cur_scope->__pyx_v_frontier = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":941 + * + * frontier = [] + * for i in range(len(fwords)): # <<<<<<<<<<<<<< + * for alt in range(0, len(fwords[i])): + * if fwords[i][alt][0] != EPSILON: + */ + __pyx_t_1 = PyObject_Length(__pyx_cur_scope->__pyx_v_fwords); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_1; __pyx_t_4+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_4; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":942 + * frontier = [] + * for i in range(len(fwords)): + * for alt in range(0, len(fwords[i])): # <<<<<<<<<<<<<< + * if fwords[i][alt][0] != EPSILON: + * frontier.append((i, i, alt, 0, self.rules.root, (), False)) + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_fwords, __pyx_cur_scope->__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 942; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 942; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_cur_scope->__pyx_v_alt = __pyx_t_6; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":943 + * for i in range(len(fwords)): + * for alt in range(0, len(fwords[i])): + * if fwords[i][alt][0] != EPSILON: # <<<<<<<<<<<<<< + * frontier.append((i, i, alt, 0, self.rules.root, (), False)) + * + */ + __pyx_t_3 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_fwords, __pyx_cur_scope->__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_3, __pyx_cur_scope->__pyx_v_alt, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyInt_FromLong(__pyx_v_3_sa_EPSILON); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_NE); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 943; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":944 + * for alt in range(0, len(fwords[i])): + * if fwords[i][alt][0] != EPSILON: + * frontier.append((i, i, alt, 0, self.rules.root, (), False)) # <<<<<<<<<<<<<< + * + * xroot = None + */ + __pyx_t_7 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_2 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_alt); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_9 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyTuple_New(7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_INCREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_self->rules->root); + PyTuple_SET_ITEM(__pyx_t_10, 4, __pyx_cur_scope->__pyx_v_self->rules->root); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_self->rules->root); + __Pyx_INCREF(((PyObject *)__pyx_empty_tuple)); + PyTuple_SET_ITEM(__pyx_t_10, 5, ((PyObject *)__pyx_empty_tuple)); + __Pyx_GIVEREF(((PyObject *)__pyx_empty_tuple)); + PyTuple_SET_ITEM(__pyx_t_10, 6, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_t_7 = 0; + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_9 = 0; + __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_frontier, ((PyObject *)__pyx_t_10)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 944; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + goto __pyx_L8; + } + __pyx_L8:; + } + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":946 + * frontier.append((i, i, alt, 0, self.rules.root, (), False)) + * + * xroot = None # <<<<<<<<<<<<<< + * x1 = sym_setindex(self.category, 1) + * if x1 in self.rules.root.children: + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __pyx_cur_scope->__pyx_v_xroot = Py_None; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":947 + * + * xroot = None + * x1 = sym_setindex(self.category, 1) # <<<<<<<<<<<<<< + * if x1 in self.rules.root.children: + * xroot = self.rules.root.children[x1] + */ + __pyx_cur_scope->__pyx_v_x1 = __pyx_f_3_sa_sym_setindex(__pyx_cur_scope->__pyx_v_self->category, 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":948 + * xroot = None + * x1 = sym_setindex(self.category, 1) + * if x1 in self.rules.root.children: # <<<<<<<<<<<<<< + * xroot = self.rules.root.children[x1] + * else: + */ + __pyx_t_10 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_x1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_self->rules->root, __pyx_n_s__children); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = ((PySequence_Contains(__pyx_t_9, __pyx_t_10))); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":949 + * x1 = sym_setindex(self.category, 1) + * if x1 in self.rules.root.children: + * xroot = self.rules.root.children[x1] # <<<<<<<<<<<<<< + * else: + * xroot = ExtendedTrieNode(suffix_link=self.rules.root, phrase_location=PhraseLocation()) + */ + __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_self->rules->root, __pyx_n_s__children); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 949; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = __Pyx_GetItemInt(__pyx_t_9, __pyx_cur_scope->__pyx_v_x1, sizeof(int), PyInt_FromLong); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 949; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_xroot); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_xroot); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_xroot = __pyx_t_10; + __pyx_t_10 = 0; + goto __pyx_L9; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":951 + * xroot = self.rules.root.children[x1] + * else: + * xroot = ExtendedTrieNode(suffix_link=self.rules.root, phrase_location=PhraseLocation()) # <<<<<<<<<<<<<< + * self.rules.root.children[x1] = xroot + * + */ + __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_10)); + if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__suffix_link), __pyx_cur_scope->__pyx_v_self->rules->root) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_PhraseLocation)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__phrase_location), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_xroot); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_xroot); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_v_xroot = __pyx_t_9; + __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":952 + * else: + * xroot = ExtendedTrieNode(suffix_link=self.rules.root, phrase_location=PhraseLocation()) + * self.rules.root.children[x1] = xroot # <<<<<<<<<<<<<< + * + * for i in range(self.min_gap_size, len(fwords)): + */ + __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_self->rules->root, __pyx_n_s__children); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 952; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + if (__Pyx_SetItemInt(__pyx_t_9, __pyx_cur_scope->__pyx_v_x1, __pyx_cur_scope->__pyx_v_xroot, sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 952; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __pyx_L9:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":954 + * self.rules.root.children[x1] = xroot + * + * for i in range(self.min_gap_size, len(fwords)): # <<<<<<<<<<<<<< + * for alt in range(0, len(fwords[i])): + * if fwords[i][alt][0] != EPSILON: + */ + __pyx_t_1 = PyObject_Length(__pyx_cur_scope->__pyx_v_fwords); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 954; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_4 = __pyx_cur_scope->__pyx_v_self->min_gap_size; __pyx_t_4 < __pyx_t_1; __pyx_t_4+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_4; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":955 + * + * for i in range(self.min_gap_size, len(fwords)): + * for alt in range(0, len(fwords[i])): # <<<<<<<<<<<<<< + * if fwords[i][alt][0] != EPSILON: + * frontier.append((i-self.min_gap_size, i, alt, self.min_gap_size, xroot, (x1,), True)) + */ + __pyx_t_9 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_fwords, __pyx_cur_scope->__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 955; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_5 = PyObject_Length(__pyx_t_9); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 955; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_cur_scope->__pyx_v_alt = __pyx_t_6; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":956 + * for i in range(self.min_gap_size, len(fwords)): + * for alt in range(0, len(fwords[i])): + * if fwords[i][alt][0] != EPSILON: # <<<<<<<<<<<<<< + * frontier.append((i-self.min_gap_size, i, alt, self.min_gap_size, xroot, (x1,), True)) + * + */ + __pyx_t_9 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_fwords, __pyx_cur_scope->__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = __Pyx_GetItemInt(__pyx_t_9, __pyx_cur_scope->__pyx_v_alt, sizeof(int), PyInt_FromLong); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_GetItemInt(__pyx_t_10, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = PyInt_FromLong(__pyx_v_3_sa_EPSILON); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_3 = PyObject_RichCompare(__pyx_t_9, __pyx_t_10, Py_NE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":957 + * for alt in range(0, len(fwords[i])): + * if fwords[i][alt][0] != EPSILON: + * frontier.append((i-self.min_gap_size, i, alt, self.min_gap_size, xroot, (x1,), True)) # <<<<<<<<<<<<<< + * + * next_states = [] + */ + __pyx_t_3 = PyInt_FromLong((__pyx_cur_scope->__pyx_v_i - __pyx_cur_scope->__pyx_v_self->min_gap_size)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_alt); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_2 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->min_gap_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_x1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_13 = PyTuple_New(7); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_xroot); + PyTuple_SET_ITEM(__pyx_t_13, 4, __pyx_cur_scope->__pyx_v_xroot); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_xroot); + PyTuple_SET_ITEM(__pyx_t_13, 5, ((PyObject *)__pyx_t_12)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_12)); + PyTuple_SET_ITEM(__pyx_t_13, 6, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + __pyx_t_3 = 0; + __pyx_t_10 = 0; + __pyx_t_9 = 0; + __pyx_t_2 = 0; + __pyx_t_12 = 0; + __pyx_t_7 = 0; + __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_frontier, ((PyObject *)__pyx_t_13)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + goto __pyx_L14; + } + __pyx_L14:; + } + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":959 + * frontier.append((i-self.min_gap_size, i, alt, self.min_gap_size, xroot, (x1,), True)) + * + * next_states = [] # <<<<<<<<<<<<<< + * for i in range(len(fwords)): + * next_states.append(self.get_next_states(fwords,i,self.min_gap_size)) + */ + __pyx_t_13 = PyList_New(0); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 959; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_GIVEREF(((PyObject *)__pyx_t_13)); + __pyx_cur_scope->__pyx_v_next_states = __pyx_t_13; + __pyx_t_13 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":960 + * + * next_states = [] + * for i in range(len(fwords)): # <<<<<<<<<<<<<< + * next_states.append(self.get_next_states(fwords,i,self.min_gap_size)) + * + */ + __pyx_t_1 = PyObject_Length(__pyx_cur_scope->__pyx_v_fwords); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 960; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_1; __pyx_t_4+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_4; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":961 + * next_states = [] + * for i in range(len(fwords)): + * next_states.append(self.get_next_states(fwords,i,self.min_gap_size)) # <<<<<<<<<<<<<< + * + * while len(frontier) > 0: + */ + __pyx_t_13 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s__get_next_states); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_7 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_12 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->min_gap_size); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_fwords); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_7); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_12); + __Pyx_GIVEREF(__pyx_t_12); + __pyx_t_7 = 0; + __pyx_t_12 = 0; + __pyx_t_12 = PyObject_Call(__pyx_t_13, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_next_states, __pyx_t_12); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 961; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":963 + * next_states.append(self.get_next_states(fwords,i,self.min_gap_size)) + * + * while len(frontier) > 0: # <<<<<<<<<<<<<< + * new_frontier = [] + * for k, i, alt, pathlen, node, prefix, is_shadow_path in frontier: + */ + while (1) { + __pyx_t_1 = PyList_GET_SIZE(((PyObject *)__pyx_cur_scope->__pyx_v_frontier)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 963; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = (__pyx_t_1 > 0); + if (!__pyx_t_8) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":964 + * + * while len(frontier) > 0: + * new_frontier = [] # <<<<<<<<<<<<<< + * for k, i, alt, pathlen, node, prefix, is_shadow_path in frontier: + * word_id = fwords[i][alt][0] + */ + __pyx_t_12 = PyList_New(0); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 964; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_new_frontier)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_new_frontier)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_12)); + __pyx_cur_scope->__pyx_v_new_frontier = __pyx_t_12; + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":965 + * while len(frontier) > 0: + * new_frontier = [] + * for k, i, alt, pathlen, node, prefix, is_shadow_path in frontier: # <<<<<<<<<<<<<< + * word_id = fwords[i][alt][0] + * spanlen = fwords[i][alt][2] + */ + __pyx_t_12 = ((PyObject *)__pyx_cur_scope->__pyx_v_frontier); __Pyx_INCREF(__pyx_t_12); __pyx_t_1 = 0; + for (;;) { + if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_12)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_12, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; + #else + __pyx_t_2 = PySequence_ITEM(__pyx_t_12, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 7)) { + if (size > 7) __Pyx_RaiseTooManyValuesError(7); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_13 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_9 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 3); + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 4); + __pyx_t_14 = PyTuple_GET_ITEM(sequence, 5); + __pyx_t_15 = PyTuple_GET_ITEM(sequence, 6); + } else { + __pyx_t_13 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + __pyx_t_9 = PyList_GET_ITEM(sequence, 2); + __pyx_t_10 = PyList_GET_ITEM(sequence, 3); + __pyx_t_3 = PyList_GET_ITEM(sequence, 4); + __pyx_t_14 = PyList_GET_ITEM(sequence, 5); + __pyx_t_15 = PyList_GET_ITEM(sequence, 6); + } + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(__pyx_t_15); + #else + Py_ssize_t i; + PyObject** temps[7] = {&__pyx_t_13,&__pyx_t_7,&__pyx_t_9,&__pyx_t_10,&__pyx_t_3,&__pyx_t_14,&__pyx_t_15}; + for (i=0; i < 7; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + *(temps[i]) = item; + } + #endif + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else + { + Py_ssize_t index = -1; + PyObject** temps[7] = {&__pyx_t_13,&__pyx_t_7,&__pyx_t_9,&__pyx_t_10,&__pyx_t_3,&__pyx_t_14,&__pyx_t_15}; + __pyx_t_16 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_17 = Py_TYPE(__pyx_t_16)->tp_iternext; + for (index=0; index < 7; index++) { + PyObject* item = __pyx_t_17(__pyx_t_16); if (unlikely(!item)) goto __pyx_L21_unpacking_failed; + __Pyx_GOTREF(item); + *(temps[index]) = item; + } + if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_16), 7) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_17 = NULL; + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + goto __pyx_L22_unpacking_done; + __pyx_L21_unpacking_failed:; + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __pyx_t_17 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L22_unpacking_done:; + } + __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_13); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_7); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_t_9); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_cur_scope->__pyx_v_k = __pyx_t_4; + __pyx_cur_scope->__pyx_v_i = __pyx_t_6; + __pyx_cur_scope->__pyx_v_alt = __pyx_t_18; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_pathlen); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_pathlen); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_pathlen = __pyx_t_10; + __pyx_t_10 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_node); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_node); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_node = __pyx_t_3; + __pyx_t_3 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_prefix); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_prefix); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_cur_scope->__pyx_v_prefix = __pyx_t_14; + __pyx_t_14 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_is_shadow_path); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_is_shadow_path); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_cur_scope->__pyx_v_is_shadow_path = __pyx_t_15; + __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":966 + * new_frontier = [] + * for k, i, alt, pathlen, node, prefix, is_shadow_path in frontier: + * word_id = fwords[i][alt][0] # <<<<<<<<<<<<<< + * spanlen = fwords[i][alt][2] + * # TODO get rid of k -- pathlen is replacing it + */ + __pyx_t_2 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_fwords, __pyx_cur_scope->__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 966; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = __Pyx_GetItemInt(__pyx_t_2, __pyx_cur_scope->__pyx_v_alt, sizeof(int), PyInt_FromLong); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 966; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_15, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 966; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_word_id); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_word_id); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_v_word_id = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":967 + * for k, i, alt, pathlen, node, prefix, is_shadow_path in frontier: + * word_id = fwords[i][alt][0] + * spanlen = fwords[i][alt][2] # <<<<<<<<<<<<<< + * # TODO get rid of k -- pathlen is replacing it + * if word_id == EPSILON: + */ + __pyx_t_2 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_fwords, __pyx_cur_scope->__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = __Pyx_GetItemInt(__pyx_t_2, __pyx_cur_scope->__pyx_v_alt, sizeof(int), PyInt_FromLong); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_15, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 967; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_spanlen); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_spanlen); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_v_spanlen = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":969 + * spanlen = fwords[i][alt][2] + * # TODO get rid of k -- pathlen is replacing it + * if word_id == EPSILON: # <<<<<<<<<<<<<< + * # skipping because word_id is epsilon + * if i+spanlen >= len(fwords): + */ + __pyx_t_2 = PyInt_FromLong(__pyx_v_3_sa_EPSILON); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 969; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_word_id, __pyx_t_2, Py_EQ); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 969; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 969; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":971 + * if word_id == EPSILON: + * # skipping because word_id is epsilon + * if i+spanlen >= len(fwords): # <<<<<<<<<<<<<< + * continue + * for nualt in range(0,len(fwords[i+spanlen])): + */ + __pyx_t_15 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_2 = PyNumber_Add(__pyx_t_15, __pyx_cur_scope->__pyx_v_spanlen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_5 = PyObject_Length(__pyx_cur_scope->__pyx_v_fwords); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_15 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_14 = PyObject_RichCompare(__pyx_t_2, __pyx_t_15, Py_GE); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 971; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":972 + * # skipping because word_id is epsilon + * if i+spanlen >= len(fwords): + * continue # <<<<<<<<<<<<<< + * for nualt in range(0,len(fwords[i+spanlen])): + * frontier.append((k, i+spanlen, nualt, pathlen, node, prefix, is_shadow_path)) + */ + goto __pyx_L19_continue; + goto __pyx_L24; + } + __pyx_L24:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":973 + * if i+spanlen >= len(fwords): + * continue + * for nualt in range(0,len(fwords[i+spanlen])): # <<<<<<<<<<<<<< + * frontier.append((k, i+spanlen, nualt, pathlen, node, prefix, is_shadow_path)) + * continue + */ + __pyx_t_14 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = PyNumber_Add(__pyx_t_14, __pyx_cur_scope->__pyx_v_spanlen); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = PyObject_GetItem(__pyx_cur_scope->__pyx_v_fwords, __pyx_t_15); if (!__pyx_t_14) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_5 = PyObject_Length(__pyx_t_14); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 973; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_5; __pyx_t_18+=1) { + __pyx_cur_scope->__pyx_v_nualt = __pyx_t_18; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":974 + * continue + * for nualt in range(0,len(fwords[i+spanlen])): + * frontier.append((k, i+spanlen, nualt, pathlen, node, prefix, is_shadow_path)) # <<<<<<<<<<<<<< + * continue + * + */ + __pyx_t_14 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_k); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_2 = PyNumber_Add(__pyx_t_15, __pyx_cur_scope->__pyx_v_spanlen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_nualt); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = PyTuple_New(7); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_15); + __Pyx_GIVEREF(__pyx_t_15); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_pathlen); + PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_cur_scope->__pyx_v_pathlen); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_pathlen); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_node); + PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_cur_scope->__pyx_v_node); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_node); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_prefix); + PyTuple_SET_ITEM(__pyx_t_3, 5, __pyx_cur_scope->__pyx_v_prefix); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_prefix); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_is_shadow_path); + PyTuple_SET_ITEM(__pyx_t_3, 6, __pyx_cur_scope->__pyx_v_is_shadow_path); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_is_shadow_path); + __pyx_t_14 = 0; + __pyx_t_2 = 0; + __pyx_t_15 = 0; + __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_frontier, ((PyObject *)__pyx_t_3)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 974; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":975 + * for nualt in range(0,len(fwords[i+spanlen])): + * frontier.append((k, i+spanlen, nualt, pathlen, node, prefix, is_shadow_path)) + * continue # <<<<<<<<<<<<<< + * + * phrase = prefix + (word_id,) + */ + goto __pyx_L19_continue; + goto __pyx_L23; + } + __pyx_L23:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":977 + * continue + * + * phrase = prefix + (word_id,) # <<<<<<<<<<<<<< + * hiero_phrase = Phrase(phrase) + * arity = hiero_phrase.arity() + */ + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_word_id); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_cur_scope->__pyx_v_word_id); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_word_id); + __pyx_t_15 = PyNumber_Add(__pyx_cur_scope->__pyx_v_prefix, ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_phrase); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_phrase); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_cur_scope->__pyx_v_phrase = __pyx_t_15; + __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":978 + * + * phrase = prefix + (word_id,) + * hiero_phrase = Phrase(phrase) # <<<<<<<<<<<<<< + * arity = hiero_phrase.arity() + * + */ + __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_phrase); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_cur_scope->__pyx_v_phrase); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_phrase); + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_Phrase)), ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_hiero_phrase)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_hiero_phrase)); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_hiero_phrase = ((struct __pyx_obj_3_sa_Phrase *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":979 + * phrase = prefix + (word_id,) + * hiero_phrase = Phrase(phrase) + * arity = hiero_phrase.arity() # <<<<<<<<<<<<<< + * + * lookup_required = False + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_hiero_phrase), __pyx_n_s__arity); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 979; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_15 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 979; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_t_15); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 979; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_cur_scope->__pyx_v_arity = __pyx_t_18; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":981 + * arity = hiero_phrase.arity() + * + * lookup_required = False # <<<<<<<<<<<<<< + * if word_id in node.children: + * if node.children[word_id] is None: + */ + __pyx_cur_scope->__pyx_v_lookup_required = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":982 + * + * lookup_required = False + * if word_id in node.children: # <<<<<<<<<<<<<< + * if node.children[word_id] is None: + * # Path dead-ends at this node + */ + __pyx_t_15 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 982; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_8 = ((PySequence_Contains(__pyx_t_15, __pyx_cur_scope->__pyx_v_word_id))); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 982; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":983 + * lookup_required = False + * if word_id in node.children: + * if node.children[word_id] is None: # <<<<<<<<<<<<<< + * # Path dead-ends at this node + * continue + */ + __pyx_t_15 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 983; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = PyObject_GetItem(__pyx_t_15, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 983; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_8 = (__pyx_t_3 == Py_None); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":985 + * if node.children[word_id] is None: + * # Path dead-ends at this node + * continue # <<<<<<<<<<<<<< + * else: + * # Path continues at this node + */ + goto __pyx_L19_continue; + goto __pyx_L28; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":988 + * else: + * # Path continues at this node + * node = node.children[word_id] # <<<<<<<<<<<<<< + * else: + * if node.suffix_link is None: + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 988; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_15 = PyObject_GetItem(__pyx_t_3, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 988; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_node); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_node); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_cur_scope->__pyx_v_node = __pyx_t_15; + __pyx_t_15 = 0; + } + __pyx_L28:; + goto __pyx_L27; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":990 + * node = node.children[word_id] + * else: + * if node.suffix_link is None: # <<<<<<<<<<<<<< + * # Current node is root; lookup required + * lookup_required = True + */ + __pyx_t_15 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 990; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_8 = (__pyx_t_15 == Py_None); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":992 + * if node.suffix_link is None: + * # Current node is root; lookup required + * lookup_required = True # <<<<<<<<<<<<<< + * else: + * if word_id in node.suffix_link.children: + */ + __pyx_cur_scope->__pyx_v_lookup_required = 1; + goto __pyx_L29; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":994 + * lookup_required = True + * else: + * if word_id in node.suffix_link.children: # <<<<<<<<<<<<<< + * if node.suffix_link.children[word_id] is None: + * # Suffix link reports path is dead end + */ + __pyx_t_15 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 994; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_15, __pyx_n_s__children); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 994; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_8 = ((PySequence_Contains(__pyx_t_3, __pyx_cur_scope->__pyx_v_word_id))); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 994; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":995 + * else: + * if word_id in node.suffix_link.children: + * if node.suffix_link.children[word_id] is None: # <<<<<<<<<<<<<< + * # Suffix link reports path is dead end + * node.children[word_id] = None + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_15 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__children); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_GetItem(__pyx_t_15, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_3) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_8 = (__pyx_t_3 == Py_None); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":997 + * if node.suffix_link.children[word_id] is None: + * # Suffix link reports path is dead end + * node.children[word_id] = None # <<<<<<<<<<<<<< + * continue + * else: + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 997; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyObject_SetItem(__pyx_t_3, __pyx_cur_scope->__pyx_v_word_id, Py_None) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 997; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":998 + * # Suffix link reports path is dead end + * node.children[word_id] = None + * continue # <<<<<<<<<<<<<< + * else: + * # Suffix link indicates lookup is reqired + */ + goto __pyx_L19_continue; + goto __pyx_L31; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1001 + * else: + * # Suffix link indicates lookup is reqired + * lookup_required = True # <<<<<<<<<<<<<< + * else: + * #ERROR: We never get here + */ + __pyx_cur_scope->__pyx_v_lookup_required = 1; + } + __pyx_L31:; + goto __pyx_L30; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1004 + * else: + * #ERROR: We never get here + * raise Exception("Keyword trie error") # <<<<<<<<<<<<<< + * # checking whether lookup_required + * if lookup_required: + */ + __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_k_tuple_120), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1004; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1004; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L30:; + } + __pyx_L29:; + } + __pyx_L27:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1006 + * raise Exception("Keyword trie error") + * # checking whether lookup_required + * if lookup_required: # <<<<<<<<<<<<<< + * new_node = None + * if is_shadow_path: + */ + if (__pyx_cur_scope->__pyx_v_lookup_required) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1007 + * # checking whether lookup_required + * if lookup_required: + * new_node = None # <<<<<<<<<<<<<< + * if is_shadow_path: + * # Extending shadow path + */ + __Pyx_INCREF(Py_None); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_new_node); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_new_node); + __Pyx_GIVEREF(Py_None); + __pyx_cur_scope->__pyx_v_new_node = Py_None; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1008 + * if lookup_required: + * new_node = None + * if is_shadow_path: # <<<<<<<<<<<<<< + * # Extending shadow path + * # on the shadow path we don't do any search, we just use info from suffix link + */ + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_is_shadow_path); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1008; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1011 + * # Extending shadow path + * # on the shadow path we don't do any search, we just use info from suffix link + * new_node = ExtendedTrieNode(phrase_location=node.suffix_link.children[word_id].phrase_location, # <<<<<<<<<<<<<< + * suffix_link=node.suffix_link.children[word_id], + * phrase=hiero_phrase) + */ + __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_t_15 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_15, __pyx_n_s__children); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = PyObject_GetItem(__pyx_t_2, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_GetAttr(__pyx_t_15, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__phrase_location), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1012 + * # on the shadow path we don't do any search, we just use info from suffix link + * new_node = ExtendedTrieNode(phrase_location=node.suffix_link.children[word_id].phrase_location, + * suffix_link=node.suffix_link.children[word_id], # <<<<<<<<<<<<<< + * phrase=hiero_phrase) + * else: + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__children); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_GetItem(__pyx_t_15, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__suffix_link), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1013 + * new_node = ExtendedTrieNode(phrase_location=node.suffix_link.children[word_id].phrase_location, + * suffix_link=node.suffix_link.children[word_id], + * phrase=hiero_phrase) # <<<<<<<<<<<<<< + * else: + * if arity > 0: + */ + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__phrase), ((PyObject *)__pyx_cur_scope->__pyx_v_hiero_phrase)) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_new_node); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_new_node); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_v_new_node = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L33; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1015 + * phrase=hiero_phrase) + * else: + * if arity > 0: # <<<<<<<<<<<<<< + * # Intersecting because of arity > 0 + * phrase_location = self.intersect(node, node.suffix_link.children[word_id], hiero_phrase) + */ + __pyx_t_8 = (__pyx_cur_scope->__pyx_v_arity > 0); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1017 + * if arity > 0: + * # Intersecting because of arity > 0 + * phrase_location = self.intersect(node, node.suffix_link.children[word_id], hiero_phrase) # <<<<<<<<<<<<<< + * else: + * # Suffix array search + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1017; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__children); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1017; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_GetItem(__pyx_t_3, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1017; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = ((PyObject *)((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_cur_scope->__pyx_v_self->__pyx_vtab)->intersect(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_node, __pyx_t_2, __pyx_cur_scope->__pyx_v_hiero_phrase)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1017; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_phrase_location = ((struct __pyx_obj_3_sa_PhraseLocation *)__pyx_t_3); + __pyx_t_3 = 0; + goto __pyx_L34; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1020 + * else: + * # Suffix array search + * phrase_location = node.phrase_location # <<<<<<<<<<<<<< + * sa_range = self.fsa.lookup(sym_tostring(phrase[-1]), len(phrase)-1, phrase_location.sa_low, phrase_location.sa_high) + * if sa_range is not None: + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1020; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_3_sa_PhraseLocation))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1020; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_phrase_location = ((struct __pyx_obj_3_sa_PhraseLocation *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1021 + * # Suffix array search + * phrase_location = node.phrase_location + * sa_range = self.fsa.lookup(sym_tostring(phrase[-1]), len(phrase)-1, phrase_location.sa_low, phrase_location.sa_high) # <<<<<<<<<<<<<< + * if sa_range is not None: + * phrase_location = PhraseLocation(sa_low=sa_range[0], sa_high=sa_range[1]) + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self->fsa), __pyx_n_s__lookup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_phrase, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyBytes_FromString(__pyx_f_3_sa_sym_tostring(__pyx_t_18)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_5 = PyObject_Length(__pyx_cur_scope->__pyx_v_phrase); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_15 = PyInt_FromSsize_t((__pyx_t_5 - 1)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_14 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_phrase_location->sa_low); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_10 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_phrase_location->sa_high); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyTuple_New(4); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_15); + __Pyx_GIVEREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_t_2 = 0; + __pyx_t_15 = 0; + __pyx_t_14 = 0; + __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_sa_range); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_sa_range); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_sa_range = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1022 + * phrase_location = node.phrase_location + * sa_range = self.fsa.lookup(sym_tostring(phrase[-1]), len(phrase)-1, phrase_location.sa_low, phrase_location.sa_high) + * if sa_range is not None: # <<<<<<<<<<<<<< + * phrase_location = PhraseLocation(sa_low=sa_range[0], sa_high=sa_range[1]) + * else: + */ + __pyx_t_8 = (__pyx_cur_scope->__pyx_v_sa_range != Py_None); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1023 + * sa_range = self.fsa.lookup(sym_tostring(phrase[-1]), len(phrase)-1, phrase_location.sa_low, phrase_location.sa_high) + * if sa_range is not None: + * phrase_location = PhraseLocation(sa_low=sa_range[0], sa_high=sa_range[1]) # <<<<<<<<<<<<<< + * else: + * phrase_location = None + */ + __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1023; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_10)); + __pyx_t_9 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_sa_range, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1023; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__sa_low), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1023; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_sa_range, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1023; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__sa_high), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1023; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_PhraseLocation)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1023; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_GOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_v_phrase_location = ((struct __pyx_obj_3_sa_PhraseLocation *)__pyx_t_9); + __pyx_t_9 = 0; + goto __pyx_L35; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1025 + * phrase_location = PhraseLocation(sa_low=sa_range[0], sa_high=sa_range[1]) + * else: + * phrase_location = None # <<<<<<<<<<<<<< + * + * if phrase_location is None: + */ + __Pyx_INCREF(Py_None); + __Pyx_GOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)); + __Pyx_GIVEREF(Py_None); + __pyx_cur_scope->__pyx_v_phrase_location = ((struct __pyx_obj_3_sa_PhraseLocation *)Py_None); + } + __pyx_L35:; + } + __pyx_L34:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1027 + * phrase_location = None + * + * if phrase_location is None: # <<<<<<<<<<<<<< + * node.children[word_id] = None + * # Search failed + */ + __pyx_t_8 = (((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location) == Py_None); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1028 + * + * if phrase_location is None: + * node.children[word_id] = None # <<<<<<<<<<<<<< + * # Search failed + * continue + */ + __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1028; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + if (PyObject_SetItem(__pyx_t_9, __pyx_cur_scope->__pyx_v_word_id, Py_None) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1028; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1030 + * node.children[word_id] = None + * # Search failed + * continue # <<<<<<<<<<<<<< + * # Search succeeded + * suffix_link = self.rules.root + */ + goto __pyx_L19_continue; + goto __pyx_L36; + } + __pyx_L36:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1032 + * continue + * # Search succeeded + * suffix_link = self.rules.root # <<<<<<<<<<<<<< + * if node.suffix_link is not None: + * suffix_link = node.suffix_link.children[word_id] + */ + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_self->rules->root); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_suffix_link); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_suffix_link); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_self->rules->root); + __pyx_cur_scope->__pyx_v_suffix_link = __pyx_cur_scope->__pyx_v_self->rules->root; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1033 + * # Search succeeded + * suffix_link = self.rules.root + * if node.suffix_link is not None: # <<<<<<<<<<<<<< + * suffix_link = node.suffix_link.children[word_id] + * new_node = ExtendedTrieNode(phrase_location=phrase_location, + */ + __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1033; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = (__pyx_t_9 != Py_None); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1034 + * suffix_link = self.rules.root + * if node.suffix_link is not None: + * suffix_link = node.suffix_link.children[word_id] # <<<<<<<<<<<<<< + * new_node = ExtendedTrieNode(phrase_location=phrase_location, + * suffix_link=suffix_link, + */ + __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1034; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__children); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1034; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = PyObject_GetItem(__pyx_t_10, __pyx_cur_scope->__pyx_v_word_id); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1034; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_suffix_link); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_suffix_link); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_v_suffix_link = __pyx_t_9; + __pyx_t_9 = 0; + goto __pyx_L37; + } + __pyx_L37:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1035 + * if node.suffix_link is not None: + * suffix_link = node.suffix_link.children[word_id] + * new_node = ExtendedTrieNode(phrase_location=phrase_location, # <<<<<<<<<<<<<< + * suffix_link=suffix_link, + * phrase=hiero_phrase) + */ + __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1035; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__phrase_location), ((PyObject *)__pyx_cur_scope->__pyx_v_phrase_location)) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1035; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1036 + * suffix_link = node.suffix_link.children[word_id] + * new_node = ExtendedTrieNode(phrase_location=phrase_location, + * suffix_link=suffix_link, # <<<<<<<<<<<<<< + * phrase=hiero_phrase) + * node.children[word_id] = new_node + */ + if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__suffix_link), __pyx_cur_scope->__pyx_v_suffix_link) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1035; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1037 + * new_node = ExtendedTrieNode(phrase_location=phrase_location, + * suffix_link=suffix_link, + * phrase=hiero_phrase) # <<<<<<<<<<<<<< + * node.children[word_id] = new_node + * node = new_node + */ + if (PyDict_SetItem(__pyx_t_9, ((PyObject *)__pyx_n_s__phrase), ((PyObject *)__pyx_cur_scope->__pyx_v_hiero_phrase)) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1035; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_10 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_9)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1035; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_new_node); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_new_node); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_new_node = __pyx_t_10; + __pyx_t_10 = 0; + } + __pyx_L33:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1038 + * suffix_link=suffix_link, + * phrase=hiero_phrase) + * node.children[word_id] = new_node # <<<<<<<<<<<<<< + * node = new_node + * + */ + __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1038; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + if (PyObject_SetItem(__pyx_t_10, __pyx_cur_scope->__pyx_v_word_id, __pyx_cur_scope->__pyx_v_new_node) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1038; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1039 + * phrase=hiero_phrase) + * node.children[word_id] = new_node + * node = new_node # <<<<<<<<<<<<<< + * + * '''Automatically add a trailing X node, if allowed -- + */ + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_new_node); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_node); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_node); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_new_node); + __pyx_cur_scope->__pyx_v_node = __pyx_cur_scope->__pyx_v_new_node; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1044 + * This should happen before we get to extraction (so that + * the node will exist if needed)''' + * if arity < self.max_nonterminals: # <<<<<<<<<<<<<< + * xcat_index = arity+1 + * xcat = sym_setindex(self.category, xcat_index) + */ + __pyx_t_8 = (__pyx_cur_scope->__pyx_v_arity < __pyx_cur_scope->__pyx_v_self->max_nonterminals); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1045 + * the node will exist if needed)''' + * if arity < self.max_nonterminals: + * xcat_index = arity+1 # <<<<<<<<<<<<<< + * xcat = sym_setindex(self.category, xcat_index) + * suffix_link_xcat_index = xcat_index + */ + __pyx_t_10 = PyInt_FromLong((__pyx_cur_scope->__pyx_v_arity + 1)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1045; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_xcat_index); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_xcat_index); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_xcat_index = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1046 + * if arity < self.max_nonterminals: + * xcat_index = arity+1 + * xcat = sym_setindex(self.category, xcat_index) # <<<<<<<<<<<<<< + * suffix_link_xcat_index = xcat_index + * if is_shadow_path: + */ + __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_cur_scope->__pyx_v_xcat_index); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_xcat = __pyx_f_3_sa_sym_setindex(__pyx_cur_scope->__pyx_v_self->category, __pyx_t_18); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1047 + * xcat_index = arity+1 + * xcat = sym_setindex(self.category, xcat_index) + * suffix_link_xcat_index = xcat_index # <<<<<<<<<<<<<< + * if is_shadow_path: + * suffix_link_xcat_index = xcat_index-1 + */ + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_xcat_index); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_suffix_link_xcat_index); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_suffix_link_xcat_index); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_xcat_index); + __pyx_cur_scope->__pyx_v_suffix_link_xcat_index = __pyx_cur_scope->__pyx_v_xcat_index; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1048 + * xcat = sym_setindex(self.category, xcat_index) + * suffix_link_xcat_index = xcat_index + * if is_shadow_path: # <<<<<<<<<<<<<< + * suffix_link_xcat_index = xcat_index-1 + * suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) + */ + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_is_shadow_path); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1048; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1049 + * suffix_link_xcat_index = xcat_index + * if is_shadow_path: + * suffix_link_xcat_index = xcat_index-1 # <<<<<<<<<<<<<< + * suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) + * node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, + */ + __pyx_t_10 = PyNumber_Subtract(__pyx_cur_scope->__pyx_v_xcat_index, __pyx_int_1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1049; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_suffix_link_xcat_index); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_suffix_link_xcat_index); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_suffix_link_xcat_index = __pyx_t_10; + __pyx_t_10 = 0; + goto __pyx_L39; + } + __pyx_L39:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1050 + * if is_shadow_path: + * suffix_link_xcat_index = xcat_index-1 + * suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) # <<<<<<<<<<<<<< + * node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, + * suffix_link=node.suffix_link.children[suffix_link_xcat], + */ + __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_cur_scope->__pyx_v_suffix_link_xcat_index); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1050; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_suffix_link_xcat = __pyx_f_3_sa_sym_setindex(__pyx_cur_scope->__pyx_v_self->category, __pyx_t_18); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1051 + * suffix_link_xcat_index = xcat_index-1 + * suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) + * node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, # <<<<<<<<<<<<<< + * suffix_link=node.suffix_link.children[suffix_link_xcat], + * phrase= Phrase(phrase + (xcat,))) + */ + __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_10)); + __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__phrase_location), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1052 + * suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) + * node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, + * suffix_link=node.suffix_link.children[suffix_link_xcat], # <<<<<<<<<<<<<< + * phrase= Phrase(phrase + (xcat,))) + * + */ + __pyx_t_9 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__suffix_link); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__children); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_GetItemInt(__pyx_t_3, __pyx_cur_scope->__pyx_v_suffix_link_xcat, sizeof(int), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__suffix_link), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1053 + * node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, + * suffix_link=node.suffix_link.children[suffix_link_xcat], + * phrase= Phrase(phrase + (xcat,))) # <<<<<<<<<<<<<< + * + * # sample from range + */ + __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_xcat); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_9 = PyNumber_Add(__pyx_cur_scope->__pyx_v_phrase, ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_t_9 = 0; + __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_Phrase)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__phrase), __pyx_t_9) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_ExtendedTrieNode)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1051 + * suffix_link_xcat_index = xcat_index-1 + * suffix_link_xcat = sym_setindex(self.category, suffix_link_xcat_index) + * node.children[xcat] = ExtendedTrieNode(phrase_location=node.phrase_location, # <<<<<<<<<<<<<< + * suffix_link=node.suffix_link.children[suffix_link_xcat], + * phrase= Phrase(phrase + (xcat,))) + */ + __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + if (__Pyx_SetItemInt(__pyx_t_10, __pyx_cur_scope->__pyx_v_xcat, __pyx_t_9, sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L38; + } + __pyx_L38:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1056 + * + * # sample from range + * if not is_shadow_path: # <<<<<<<<<<<<<< + * sample = self.sampler.sample(node.phrase_location) + * num_subpatterns = ( node.phrase_location).num_subpatterns + */ + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_is_shadow_path); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1056; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_19 = (!__pyx_t_8); + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1057 + * # sample from range + * if not is_shadow_path: + * sample = self.sampler.sample(node.phrase_location) # <<<<<<<<<<<<<< + * num_subpatterns = ( node.phrase_location).num_subpatterns + * chunklen = IntList(initial_len=num_subpatterns) + */ + __pyx_t_9 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self->sampler), __pyx_n_s__sample); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1057; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1057; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1057; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1057; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + if (!(likely(((__pyx_t_10) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_10, __pyx_ptype_3_sa_IntList))))) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1057; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_sample)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_sample)); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_sample = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_10); + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1058 + * if not is_shadow_path: + * sample = self.sampler.sample(node.phrase_location) + * num_subpatterns = ( node.phrase_location).num_subpatterns # <<<<<<<<<<<<<< + * chunklen = IntList(initial_len=num_subpatterns) + * for j from 0 <= j < num_subpatterns: + */ + __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__phrase_location); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_num_subpatterns = ((struct __pyx_obj_3_sa_PhraseLocation *)__pyx_t_10)->num_subpatterns; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1059 + * sample = self.sampler.sample(node.phrase_location) + * num_subpatterns = ( node.phrase_location).num_subpatterns + * chunklen = IntList(initial_len=num_subpatterns) # <<<<<<<<<<<<<< + * for j from 0 <= j < num_subpatterns: + * chunklen.arr[j] = hiero_phrase.chunklen(j) + */ + __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_10)); + __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_num_subpatterns); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_t_10, ((PyObject *)__pyx_n_s__initial_len), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_chunklen)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_chunklen)); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_chunklen = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1060 + * num_subpatterns = ( node.phrase_location).num_subpatterns + * chunklen = IntList(initial_len=num_subpatterns) + * for j from 0 <= j < num_subpatterns: # <<<<<<<<<<<<<< + * chunklen.arr[j] = hiero_phrase.chunklen(j) + * extracts = [] + */ + __pyx_t_18 = __pyx_cur_scope->__pyx_v_num_subpatterns; + for (__pyx_cur_scope->__pyx_v_j = 0; __pyx_cur_scope->__pyx_v_j < __pyx_t_18; __pyx_cur_scope->__pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1061 + * chunklen = IntList(initial_len=num_subpatterns) + * for j from 0 <= j < num_subpatterns: + * chunklen.arr[j] = hiero_phrase.chunklen(j) # <<<<<<<<<<<<<< + * extracts = [] + * j = 0 + */ + (__pyx_cur_scope->__pyx_v_chunklen->arr[__pyx_cur_scope->__pyx_v_j]) = ((struct __pyx_vtabstruct_3_sa_Phrase *)__pyx_cur_scope->__pyx_v_hiero_phrase->__pyx_vtab)->chunklen(__pyx_cur_scope->__pyx_v_hiero_phrase, __pyx_cur_scope->__pyx_v_j); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1062 + * for j from 0 <= j < num_subpatterns: + * chunklen.arr[j] = hiero_phrase.chunklen(j) + * extracts = [] # <<<<<<<<<<<<<< + * j = 0 + * extract_start = monitor_cpu() + */ + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1062; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_extracts)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_extracts)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_cur_scope->__pyx_v_extracts = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1063 + * chunklen.arr[j] = hiero_phrase.chunklen(j) + * extracts = [] + * j = 0 # <<<<<<<<<<<<<< + * extract_start = monitor_cpu() + * while j < sample.len: + */ + __pyx_cur_scope->__pyx_v_j = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1064 + * extracts = [] + * j = 0 + * extract_start = monitor_cpu() # <<<<<<<<<<<<<< + * while j < sample.len: + * extract = [] + */ + __pyx_t_3 = PyFloat_FromDouble(__pyx_f_3_sa_monitor_cpu()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_extract_start); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_extract_start); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_extract_start = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1065 + * j = 0 + * extract_start = monitor_cpu() + * while j < sample.len: # <<<<<<<<<<<<<< + * extract = [] + * + */ + while (1) { + __pyx_t_19 = (__pyx_cur_scope->__pyx_v_j < __pyx_cur_scope->__pyx_v_sample->len); + if (!__pyx_t_19) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1066 + * extract_start = monitor_cpu() + * while j < sample.len: + * extract = [] # <<<<<<<<<<<<<< + * + * assign_matching(&matching, sample.arr, j, num_subpatterns, self.fda.sent_id.arr) + */ + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1066; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_extract); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_extract); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_cur_scope->__pyx_v_extract = ((PyObject *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1068 + * extract = [] + * + * assign_matching(&matching, sample.arr, j, num_subpatterns, self.fda.sent_id.arr) # <<<<<<<<<<<<<< + * extract = self.extract(hiero_phrase, &matching, chunklen.arr, num_subpatterns) + * extracts.extend(extract) + */ + __pyx_f_3_sa_assign_matching((&__pyx_cur_scope->__pyx_v_matching), __pyx_cur_scope->__pyx_v_sample->arr, __pyx_cur_scope->__pyx_v_j, __pyx_cur_scope->__pyx_v_num_subpatterns, __pyx_cur_scope->__pyx_v_self->fda->sent_id->arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1069 + * + * assign_matching(&matching, sample.arr, j, num_subpatterns, self.fda.sent_id.arr) + * extract = self.extract(hiero_phrase, &matching, chunklen.arr, num_subpatterns) # <<<<<<<<<<<<<< + * extracts.extend(extract) + * j = j + num_subpatterns + */ + __pyx_t_3 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_cur_scope->__pyx_v_self->__pyx_vtab)->extract(__pyx_cur_scope->__pyx_v_self, __pyx_cur_scope->__pyx_v_hiero_phrase, (&__pyx_cur_scope->__pyx_v_matching), __pyx_cur_scope->__pyx_v_chunklen->arr, __pyx_cur_scope->__pyx_v_num_subpatterns); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1069; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_extract); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_extract); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_extract = __pyx_t_3; + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1070 + * assign_matching(&matching, sample.arr, j, num_subpatterns, self.fda.sent_id.arr) + * extract = self.extract(hiero_phrase, &matching, chunklen.arr, num_subpatterns) + * extracts.extend(extract) # <<<<<<<<<<<<<< + * j = j + num_subpatterns + * + */ + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_extracts), __pyx_n_s__extend); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_extract); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_cur_scope->__pyx_v_extract); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_extract); + __pyx_t_9 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1070; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1071 + * extract = self.extract(hiero_phrase, &matching, chunklen.arr, num_subpatterns) + * extracts.extend(extract) + * j = j + num_subpatterns # <<<<<<<<<<<<<< + * + * num_samples = sample.len/num_subpatterns + */ + __pyx_cur_scope->__pyx_v_j = (__pyx_cur_scope->__pyx_v_j + __pyx_cur_scope->__pyx_v_num_subpatterns); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1073 + * j = j + num_subpatterns + * + * num_samples = sample.len/num_subpatterns # <<<<<<<<<<<<<< + * extract_stop = monitor_cpu() + * self.extract_time = self.extract_time + extract_stop - extract_start + */ + if (unlikely(__pyx_cur_scope->__pyx_v_num_subpatterns == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1073; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + else if (sizeof(int) == sizeof(long) && unlikely(__pyx_cur_scope->__pyx_v_num_subpatterns == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_cur_scope->__pyx_v_sample->len))) { + PyErr_Format(PyExc_OverflowError, "value too large to perform division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1073; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_cur_scope->__pyx_v_num_samples = __Pyx_div_int(__pyx_cur_scope->__pyx_v_sample->len, __pyx_cur_scope->__pyx_v_num_subpatterns); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1074 + * + * num_samples = sample.len/num_subpatterns + * extract_stop = monitor_cpu() # <<<<<<<<<<<<<< + * self.extract_time = self.extract_time + extract_stop - extract_start + * if len(extracts) > 0: + */ + __pyx_t_9 = PyFloat_FromDouble(__pyx_f_3_sa_monitor_cpu()); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1074; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_extract_stop); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_extract_stop); + __Pyx_GIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_v_extract_stop = __pyx_t_9; + __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1075 + * num_samples = sample.len/num_subpatterns + * extract_stop = monitor_cpu() + * self.extract_time = self.extract_time + extract_stop - extract_start # <<<<<<<<<<<<<< + * if len(extracts) > 0: + * fphrases = {} + */ + __pyx_t_9 = PyFloat_FromDouble(__pyx_cur_scope->__pyx_v_self->extract_time); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyNumber_Add(__pyx_t_9, __pyx_cur_scope->__pyx_v_extract_stop); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = PyNumber_Subtract(__pyx_t_10, __pyx_cur_scope->__pyx_v_extract_start); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_20 = __pyx_PyFloat_AsFloat(__pyx_t_9); if (unlikely((__pyx_t_20 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_cur_scope->__pyx_v_self->extract_time = __pyx_t_20; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1076 + * extract_stop = monitor_cpu() + * self.extract_time = self.extract_time + extract_stop - extract_start + * if len(extracts) > 0: # <<<<<<<<<<<<<< + * fphrases = {} + * fals = {} + */ + __pyx_t_5 = PyList_GET_SIZE(((PyObject *)__pyx_cur_scope->__pyx_v_extracts)); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1076; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_19 = (__pyx_t_5 > 0); + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1077 + * self.extract_time = self.extract_time + extract_stop - extract_start + * if len(extracts) > 0: + * fphrases = {} # <<<<<<<<<<<<<< + * fals = {} + * fcount = {} + */ + __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1077; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); + __pyx_cur_scope->__pyx_v_fphrases = __pyx_t_9; + __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1078 + * if len(extracts) > 0: + * fphrases = {} + * fals = {} # <<<<<<<<<<<<<< + * fcount = {} + * for f, e, count, als in extracts: + */ + __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1078; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fals)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fals)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); + __pyx_cur_scope->__pyx_v_fals = __pyx_t_9; + __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1079 + * fphrases = {} + * fals = {} + * fcount = {} # <<<<<<<<<<<<<< + * for f, e, count, als in extracts: + * fcount.setdefault(f, 0.0) + */ + __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1079; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fcount)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fcount)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); + __pyx_cur_scope->__pyx_v_fcount = __pyx_t_9; + __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1080 + * fals = {} + * fcount = {} + * for f, e, count, als in extracts: # <<<<<<<<<<<<<< + * fcount.setdefault(f, 0.0) + * fcount[f] = fcount[f] + count + */ + __pyx_t_9 = ((PyObject *)__pyx_cur_scope->__pyx_v_extracts); __Pyx_INCREF(__pyx_t_9); __pyx_t_5 = 0; + for (;;) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_9)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_10 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_5); __Pyx_INCREF(__pyx_t_10); __pyx_t_5++; + #else + __pyx_t_10 = PySequence_ITEM(__pyx_t_9, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + if ((likely(PyTuple_CheckExact(__pyx_t_10))) || (PyList_CheckExact(__pyx_t_10))) { + PyObject* sequence = __pyx_t_10; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 4)) { + if (size > 4) __Pyx_RaiseTooManyValuesError(4); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_14 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_15 = PyTuple_GET_ITEM(sequence, 2); + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 3); + } else { + __pyx_t_3 = PyList_GET_ITEM(sequence, 0); + __pyx_t_14 = PyList_GET_ITEM(sequence, 1); + __pyx_t_15 = PyList_GET_ITEM(sequence, 2); + __pyx_t_2 = PyList_GET_ITEM(sequence, 3); + } + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(__pyx_t_15); + __Pyx_INCREF(__pyx_t_2); + #else + Py_ssize_t i; + PyObject** temps[4] = {&__pyx_t_3,&__pyx_t_14,&__pyx_t_15,&__pyx_t_2}; + for (i=0; i < 4; i++) { + PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + *(temps[i]) = item; + } + #endif + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } else + { + Py_ssize_t index = -1; + PyObject** temps[4] = {&__pyx_t_3,&__pyx_t_14,&__pyx_t_15,&__pyx_t_2}; + __pyx_t_7 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_17 = Py_TYPE(__pyx_t_7)->tp_iternext; + for (index=0; index < 4; index++) { + PyObject* item = __pyx_t_17(__pyx_t_7); if (unlikely(!item)) goto __pyx_L48_unpacking_failed; + __Pyx_GOTREF(item); + *(temps[index]) = item; + } + if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_7), 4) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_17 = NULL; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L49_unpacking_done; + __pyx_L48_unpacking_failed:; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_17 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1080; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L49_unpacking_done:; + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_f); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_f); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_f = __pyx_t_3; + __pyx_t_3 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_e); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_e); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_cur_scope->__pyx_v_e = __pyx_t_14; + __pyx_t_14 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_count); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_count); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_cur_scope->__pyx_v_count = __pyx_t_15; + __pyx_t_15 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_als); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_als); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_v_als = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1081 + * fcount = {} + * for f, e, count, als in extracts: + * fcount.setdefault(f, 0.0) # <<<<<<<<<<<<<< + * fcount[f] = fcount[f] + count + * fphrases.setdefault(f, {}) + */ + __pyx_t_10 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1081; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = __Pyx_PyDict_SetDefault(((PyObject *)__pyx_cur_scope->__pyx_v_fcount), __pyx_cur_scope->__pyx_v_f, __pyx_t_10); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1081; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1082 + * for f, e, count, als in extracts: + * fcount.setdefault(f, 0.0) + * fcount[f] = fcount[f] + count # <<<<<<<<<<<<<< + * fphrases.setdefault(f, {}) + * fphrases[f].setdefault(e, {}) + */ + __pyx_t_2 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fcount), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = PyNumber_Add(__pyx_t_2, __pyx_cur_scope->__pyx_v_count); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fcount), __pyx_cur_scope->__pyx_v_f, __pyx_t_10) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1083 + * fcount.setdefault(f, 0.0) + * fcount[f] = fcount[f] + count + * fphrases.setdefault(f, {}) # <<<<<<<<<<<<<< + * fphrases[f].setdefault(e, {}) + * fphrases[f][e].setdefault(als,0.0) + */ + __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_10)); + __pyx_t_2 = __Pyx_PyDict_SetDefault(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases), __pyx_cur_scope->__pyx_v_f, ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1084 + * fcount[f] = fcount[f] + count + * fphrases.setdefault(f, {}) + * fphrases[f].setdefault(e, {}) # <<<<<<<<<<<<<< + * fphrases[f][e].setdefault(als,0.0) + * fphrases[f][e][als] = fphrases[f][e][als] + count + */ + __pyx_t_2 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__setdefault); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_e); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_cur_scope->__pyx_v_e); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_e); + PyTuple_SET_ITEM(__pyx_t_15, 1, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1084; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1085 + * fphrases.setdefault(f, {}) + * fphrases[f].setdefault(e, {}) + * fphrases[f][e].setdefault(als,0.0) # <<<<<<<<<<<<<< + * fphrases[f][e][als] = fphrases[f][e][als] + count + * for f, elist in fphrases.iteritems(): + */ + __pyx_t_2 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = PyObject_GetItem(__pyx_t_2, __pyx_cur_scope->__pyx_v_e); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_GetAttr(__pyx_t_15, __pyx_n_s__setdefault); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_als); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_cur_scope->__pyx_v_als); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_als); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_15); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_t_15 = 0; + __pyx_t_15 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1085; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1086 + * fphrases[f].setdefault(e, {}) + * fphrases[f][e].setdefault(als,0.0) + * fphrases[f][e][als] = fphrases[f][e][als] + count # <<<<<<<<<<<<<< + * for f, elist in fphrases.iteritems(): + * f_margin = fcount[f] + */ + __pyx_t_15 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_10 = PyObject_GetItem(__pyx_t_15, __pyx_cur_scope->__pyx_v_e); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = PyObject_GetItem(__pyx_t_10, __pyx_cur_scope->__pyx_v_als); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_10 = PyNumber_Add(__pyx_t_15, __pyx_cur_scope->__pyx_v_count); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_2 = PyObject_GetItem(__pyx_t_15, __pyx_cur_scope->__pyx_v_e); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (PyObject_SetItem(__pyx_t_2, __pyx_cur_scope->__pyx_v_als, __pyx_t_10) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1086; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1087 + * fphrases[f][e].setdefault(als,0.0) + * fphrases[f][e][als] = fphrases[f][e][als] + count + * for f, elist in fphrases.iteritems(): # <<<<<<<<<<<<<< + * f_margin = fcount[f] + * for e, alslist in elist.iteritems(): + */ + __pyx_t_5 = 0; + __pyx_t_10 = __Pyx_dict_iterator(((PyObject *)__pyx_cur_scope->__pyx_v_fphrases), 1, ((PyObject *)__pyx_n_s__iteritems), (&__pyx_t_21), (&__pyx_t_18)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_9); + __pyx_t_9 = __pyx_t_10; + __pyx_t_10 = 0; + while (1) { + __pyx_t_6 = __Pyx_dict_iter_next(__pyx_t_9, __pyx_t_21, &__pyx_t_5, &__pyx_t_10, &__pyx_t_2, NULL, __pyx_t_18); + if (unlikely(__pyx_t_6 == 0)) break; + if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_f); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_f); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_f = __pyx_t_10; + __pyx_t_10 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_elist); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_elist); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_v_elist = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1088 + * fphrases[f][e][als] = fphrases[f][e][als] + count + * for f, elist in fphrases.iteritems(): + * f_margin = fcount[f] # <<<<<<<<<<<<<< + * for e, alslist in elist.iteritems(): + * alignment = None + */ + __pyx_t_2 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fcount), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1088; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_f_margin); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_f_margin); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_v_f_margin = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1089 + * for f, elist in fphrases.iteritems(): + * f_margin = fcount[f] + * for e, alslist in elist.iteritems(): # <<<<<<<<<<<<<< + * alignment = None + * count = 0 + */ + __pyx_t_22 = 0; + if (unlikely(__pyx_cur_scope->__pyx_v_elist == Py_None)) { + PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "iteritems"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_10 = __Pyx_dict_iterator(__pyx_cur_scope->__pyx_v_elist, 0, ((PyObject *)__pyx_n_s__iteritems), (&__pyx_t_23), (&__pyx_t_6)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_2); + __pyx_t_2 = __pyx_t_10; + __pyx_t_10 = 0; + while (1) { + __pyx_t_4 = __Pyx_dict_iter_next(__pyx_t_2, __pyx_t_23, &__pyx_t_22, &__pyx_t_10, &__pyx_t_15, NULL, __pyx_t_6); + if (unlikely(__pyx_t_4 == 0)) break; + if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1089; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GOTREF(__pyx_t_15); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_e); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_e); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_e = __pyx_t_10; + __pyx_t_10 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_alslist); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_alslist); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_cur_scope->__pyx_v_alslist = __pyx_t_15; + __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1090 + * f_margin = fcount[f] + * for e, alslist in elist.iteritems(): + * alignment = None # <<<<<<<<<<<<<< + * count = 0 + * for als, currcount in alslist.iteritems(): + */ + __Pyx_INCREF(Py_None); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_alignment); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_alignment); + __Pyx_GIVEREF(Py_None); + __pyx_cur_scope->__pyx_v_alignment = Py_None; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1091 + * for e, alslist in elist.iteritems(): + * alignment = None + * count = 0 # <<<<<<<<<<<<<< + * for als, currcount in alslist.iteritems(): + * if currcount > count: + */ + __Pyx_INCREF(__pyx_int_0); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_count); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_count); + __Pyx_GIVEREF(__pyx_int_0); + __pyx_cur_scope->__pyx_v_count = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1092 + * alignment = None + * count = 0 + * for als, currcount in alslist.iteritems(): # <<<<<<<<<<<<<< + * if currcount > count: + * alignment = als + */ + __pyx_t_24 = 0; + if (unlikely(__pyx_cur_scope->__pyx_v_alslist == Py_None)) { + PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "iteritems"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1092; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_10 = __Pyx_dict_iterator(__pyx_cur_scope->__pyx_v_alslist, 0, ((PyObject *)__pyx_n_s__iteritems), (&__pyx_t_25), (&__pyx_t_4)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1092; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_15); + __pyx_t_15 = __pyx_t_10; + __pyx_t_10 = 0; + while (1) { + __pyx_t_26 = __Pyx_dict_iter_next(__pyx_t_15, __pyx_t_25, &__pyx_t_24, &__pyx_t_10, &__pyx_t_14, NULL, __pyx_t_4); + if (unlikely(__pyx_t_26 == 0)) break; + if (unlikely(__pyx_t_26 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1092; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GOTREF(__pyx_t_14); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_als); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_als); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_als = __pyx_t_10; + __pyx_t_10 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_currcount); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_currcount); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_cur_scope->__pyx_v_currcount = __pyx_t_14; + __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1093 + * count = 0 + * for als, currcount in alslist.iteritems(): + * if currcount > count: # <<<<<<<<<<<<<< + * alignment = als + * count = currcount + */ + __pyx_t_14 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_currcount, __pyx_cur_scope->__pyx_v_count, Py_GT); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_14); if (unlikely(__pyx_t_19 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1093; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1094 + * for als, currcount in alslist.iteritems(): + * if currcount > count: + * alignment = als # <<<<<<<<<<<<<< + * count = currcount + * scores = [] + */ + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_als); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_alignment); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_alignment); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_als); + __pyx_cur_scope->__pyx_v_alignment = __pyx_cur_scope->__pyx_v_als; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1095 + * if currcount > count: + * alignment = als + * count = currcount # <<<<<<<<<<<<<< + * scores = [] + * for model in models: + */ + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_currcount); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_count); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_count); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_currcount); + __pyx_cur_scope->__pyx_v_count = __pyx_cur_scope->__pyx_v_currcount; + goto __pyx_L56; + } + __pyx_L56:; + } + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1096 + * alignment = als + * count = currcount + * scores = [] # <<<<<<<<<<<<<< + * for model in models: + * scores.append(model(f, e, count, fcount[f], num_samples)) + */ + __pyx_t_15 = PyList_New(0); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_scores)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_scores)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_15)); + __pyx_cur_scope->__pyx_v_scores = __pyx_t_15; + __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1097 + * count = currcount + * scores = [] + * for model in models: # <<<<<<<<<<<<<< + * scores.append(model(f, e, count, fcount[f], num_samples)) + * yield Rule(self.category, f, e, + */ + if (PyList_CheckExact(__pyx_cur_scope->__pyx_v_models) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_models)) { + __pyx_t_15 = __pyx_cur_scope->__pyx_v_models; __Pyx_INCREF(__pyx_t_15); __pyx_t_25 = 0; + __pyx_t_27 = NULL; + } else { + __pyx_t_25 = -1; __pyx_t_15 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_models); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_27 = Py_TYPE(__pyx_t_15)->tp_iternext; + } + for (;;) { + if (!__pyx_t_27 && PyList_CheckExact(__pyx_t_15)) { + if (__pyx_t_25 >= PyList_GET_SIZE(__pyx_t_15)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_14 = PyList_GET_ITEM(__pyx_t_15, __pyx_t_25); __Pyx_INCREF(__pyx_t_14); __pyx_t_25++; + #else + __pyx_t_14 = PySequence_ITEM(__pyx_t_15, __pyx_t_25); __pyx_t_25++; if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_27 && PyTuple_CheckExact(__pyx_t_15)) { + if (__pyx_t_25 >= PyTuple_GET_SIZE(__pyx_t_15)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_14 = PyTuple_GET_ITEM(__pyx_t_15, __pyx_t_25); __Pyx_INCREF(__pyx_t_14); __pyx_t_25++; + #else + __pyx_t_14 = PySequence_ITEM(__pyx_t_15, __pyx_t_25); __pyx_t_25++; if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_14 = __pyx_t_27(__pyx_t_15); + if (unlikely(!__pyx_t_14)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_14); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_model); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_model); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_cur_scope->__pyx_v_model = __pyx_t_14; + __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1098 + * scores = [] + * for model in models: + * scores.append(model(f, e, count, fcount[f], num_samples)) # <<<<<<<<<<<<<< + * yield Rule(self.category, f, e, + * scores=scores, word_alignments=alignment) + */ + __pyx_t_14 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_fcount), __pyx_cur_scope->__pyx_v_f); if (!__pyx_t_14) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_10 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_num_samples); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_3 = PyTuple_New(5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_f); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_cur_scope->__pyx_v_f); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_f); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_e); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_cur_scope->__pyx_v_e); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_e); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_count); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_cur_scope->__pyx_v_count); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_count); + PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_t_14 = 0; + __pyx_t_10 = 0; + __pyx_t_10 = PyObject_Call(__pyx_cur_scope->__pyx_v_model, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_scores, __pyx_t_10); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1099 + * for model in models: + * scores.append(model(f, e, count, fcount[f], num_samples)) + * yield Rule(self.category, f, e, # <<<<<<<<<<<<<< + * scores=scores, word_alignments=alignment) + * + */ + __pyx_t_15 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->category); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_15); + __Pyx_GIVEREF(__pyx_t_15); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_f); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_cur_scope->__pyx_v_f); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_f); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_e); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_cur_scope->__pyx_v_e); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_e); + __pyx_t_15 = 0; + __pyx_t_15 = PyDict_New(); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_15)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1100 + * scores.append(model(f, e, count, fcount[f], num_samples)) + * yield Rule(self.category, f, e, + * scores=scores, word_alignments=alignment) # <<<<<<<<<<<<<< + * + * if len(phrase) < self.max_length and i+spanlen < len(fwords) and pathlen+1 <= self.max_initial_size: + */ + if (PyDict_SetItem(__pyx_t_15, ((PyObject *)__pyx_n_s__scores), ((PyObject *)__pyx_cur_scope->__pyx_v_scores)) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_15, ((PyObject *)__pyx_n_s__word_alignments), __pyx_cur_scope->__pyx_v_alignment) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_Rule)), ((PyObject *)__pyx_t_10), ((PyObject *)__pyx_t_15)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __Pyx_XGIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_5; + __pyx_cur_scope->__pyx_t_3 = __pyx_t_6; + __Pyx_XGIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_t_4 = __pyx_t_9; + __Pyx_XGIVEREF(__pyx_t_12); + __pyx_cur_scope->__pyx_t_5 = __pyx_t_12; + __pyx_cur_scope->__pyx_t_6 = __pyx_t_18; + __pyx_cur_scope->__pyx_t_7 = __pyx_t_21; + __pyx_cur_scope->__pyx_t_8 = __pyx_t_22; + __pyx_cur_scope->__pyx_t_9 = __pyx_t_23; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L59_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_t_2); + __pyx_t_5 = __pyx_cur_scope->__pyx_t_2; + __pyx_t_6 = __pyx_cur_scope->__pyx_t_3; + __pyx_t_9 = __pyx_cur_scope->__pyx_t_4; + __pyx_cur_scope->__pyx_t_4 = 0; + __Pyx_XGOTREF(__pyx_t_9); + __pyx_t_12 = __pyx_cur_scope->__pyx_t_5; + __pyx_cur_scope->__pyx_t_5 = 0; + __Pyx_XGOTREF(__pyx_t_12); + __pyx_t_18 = __pyx_cur_scope->__pyx_t_6; + __pyx_t_21 = __pyx_cur_scope->__pyx_t_7; + __pyx_t_22 = __pyx_cur_scope->__pyx_t_8; + __pyx_t_23 = __pyx_cur_scope->__pyx_t_9; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L45; + } + __pyx_L45:; + goto __pyx_L40; + } + __pyx_L40:; + goto __pyx_L32; + } + __pyx_L32:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1102 + * scores=scores, word_alignments=alignment) + * + * if len(phrase) < self.max_length and i+spanlen < len(fwords) and pathlen+1 <= self.max_initial_size: # <<<<<<<<<<<<<< + * for alt_id in range(len(fwords[i+spanlen])): + * new_frontier.append((k, i+spanlen, alt_id, pathlen + 1, node, phrase, is_shadow_path)) + */ + __pyx_t_21 = PyObject_Length(__pyx_cur_scope->__pyx_v_phrase); if (unlikely(__pyx_t_21 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_19 = (__pyx_t_21 < __pyx_cur_scope->__pyx_v_self->max_length); + if (__pyx_t_19) { + __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_2 = PyNumber_Add(__pyx_t_9, __pyx_cur_scope->__pyx_v_spanlen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_21 = PyObject_Length(__pyx_cur_scope->__pyx_v_fwords); if (unlikely(__pyx_t_21 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = PyInt_FromSsize_t(__pyx_t_21); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_3 = PyObject_RichCompare(__pyx_t_2, __pyx_t_9, Py_LT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_8) { + __pyx_t_3 = PyNumber_Add(__pyx_cur_scope->__pyx_v_pathlen, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->max_initial_size); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_t_9, Py_LE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_28 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_28 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_29 = __pyx_t_28; + } else { + __pyx_t_29 = __pyx_t_8; + } + __pyx_t_8 = __pyx_t_29; + } else { + __pyx_t_8 = __pyx_t_19; + } + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1103 + * + * if len(phrase) < self.max_length and i+spanlen < len(fwords) and pathlen+1 <= self.max_initial_size: + * for alt_id in range(len(fwords[i+spanlen])): # <<<<<<<<<<<<<< + * new_frontier.append((k, i+spanlen, alt_id, pathlen + 1, node, phrase, is_shadow_path)) + * num_subpatterns = arity + */ + __pyx_t_2 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = PyNumber_Add(__pyx_t_2, __pyx_cur_scope->__pyx_v_spanlen); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyObject_GetItem(__pyx_cur_scope->__pyx_v_fwords, __pyx_t_9); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_21 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_21 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_21; __pyx_t_18+=1) { + __pyx_cur_scope->__pyx_v_alt_id = __pyx_t_18; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1104 + * if len(phrase) < self.max_length and i+spanlen < len(fwords) and pathlen+1 <= self.max_initial_size: + * for alt_id in range(len(fwords[i+spanlen])): + * new_frontier.append((k, i+spanlen, alt_id, pathlen + 1, node, phrase, is_shadow_path)) # <<<<<<<<<<<<<< + * num_subpatterns = arity + * if not is_shadow_path: + */ + __pyx_t_2 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_k); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_3 = PyNumber_Add(__pyx_t_9, __pyx_cur_scope->__pyx_v_spanlen); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_alt_id); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_15 = PyNumber_Add(__pyx_cur_scope->__pyx_v_pathlen, __pyx_int_1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_10 = PyTuple_New(7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_t_15); + __Pyx_GIVEREF(__pyx_t_15); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_node); + PyTuple_SET_ITEM(__pyx_t_10, 4, __pyx_cur_scope->__pyx_v_node); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_node); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_phrase); + PyTuple_SET_ITEM(__pyx_t_10, 5, __pyx_cur_scope->__pyx_v_phrase); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_phrase); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_is_shadow_path); + PyTuple_SET_ITEM(__pyx_t_10, 6, __pyx_cur_scope->__pyx_v_is_shadow_path); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_is_shadow_path); + __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_9 = 0; + __pyx_t_15 = 0; + __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_new_frontier, ((PyObject *)__pyx_t_10)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1105 + * for alt_id in range(len(fwords[i+spanlen])): + * new_frontier.append((k, i+spanlen, alt_id, pathlen + 1, node, phrase, is_shadow_path)) + * num_subpatterns = arity # <<<<<<<<<<<<<< + * if not is_shadow_path: + * num_subpatterns = num_subpatterns + 1 + */ + __pyx_cur_scope->__pyx_v_num_subpatterns = __pyx_cur_scope->__pyx_v_arity; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1106 + * new_frontier.append((k, i+spanlen, alt_id, pathlen + 1, node, phrase, is_shadow_path)) + * num_subpatterns = arity + * if not is_shadow_path: # <<<<<<<<<<<<<< + * num_subpatterns = num_subpatterns + 1 + * if len(phrase)+1 < self.max_length and arity < self.max_nonterminals and num_subpatterns < self.max_chunks: + */ + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_is_shadow_path); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_19 = (!__pyx_t_8); + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1107 + * num_subpatterns = arity + * if not is_shadow_path: + * num_subpatterns = num_subpatterns + 1 # <<<<<<<<<<<<<< + * if len(phrase)+1 < self.max_length and arity < self.max_nonterminals and num_subpatterns < self.max_chunks: + * xcat = sym_setindex(self.category, arity+1) + */ + __pyx_cur_scope->__pyx_v_num_subpatterns = (__pyx_cur_scope->__pyx_v_num_subpatterns + 1); + goto __pyx_L63; + } + __pyx_L63:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1108 + * if not is_shadow_path: + * num_subpatterns = num_subpatterns + 1 + * if len(phrase)+1 < self.max_length and arity < self.max_nonterminals and num_subpatterns < self.max_chunks: # <<<<<<<<<<<<<< + * xcat = sym_setindex(self.category, arity+1) + * xnode = node.children[xcat] + */ + __pyx_t_21 = PyObject_Length(__pyx_cur_scope->__pyx_v_phrase); if (unlikely(__pyx_t_21 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_19 = ((__pyx_t_21 + 1) < __pyx_cur_scope->__pyx_v_self->max_length); + if (__pyx_t_19) { + __pyx_t_8 = (__pyx_cur_scope->__pyx_v_arity < __pyx_cur_scope->__pyx_v_self->max_nonterminals); + if (__pyx_t_8) { + __pyx_t_29 = (__pyx_cur_scope->__pyx_v_num_subpatterns < __pyx_cur_scope->__pyx_v_self->max_chunks); + __pyx_t_28 = __pyx_t_29; + } else { + __pyx_t_28 = __pyx_t_8; + } + __pyx_t_8 = __pyx_t_28; + } else { + __pyx_t_8 = __pyx_t_19; + } + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1109 + * num_subpatterns = num_subpatterns + 1 + * if len(phrase)+1 < self.max_length and arity < self.max_nonterminals and num_subpatterns < self.max_chunks: + * xcat = sym_setindex(self.category, arity+1) # <<<<<<<<<<<<<< + * xnode = node.children[xcat] + * # I put spanlen=1 below + */ + __pyx_cur_scope->__pyx_v_xcat = __pyx_f_3_sa_sym_setindex(__pyx_cur_scope->__pyx_v_self->category, (__pyx_cur_scope->__pyx_v_arity + 1)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1110 + * if len(phrase)+1 < self.max_length and arity < self.max_nonterminals and num_subpatterns < self.max_chunks: + * xcat = sym_setindex(self.category, arity+1) + * xnode = node.children[xcat] # <<<<<<<<<<<<<< + * # I put spanlen=1 below + * key = tuple([self.min_gap_size, i, 1, pathlen]) + */ + __pyx_t_10 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_node, __pyx_n_s__children); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_15 = __Pyx_GetItemInt(__pyx_t_10, __pyx_cur_scope->__pyx_v_xcat, sizeof(int), PyInt_FromLong); if (!__pyx_t_15) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_xnode); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_xnode); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_cur_scope->__pyx_v_xnode = __pyx_t_15; + __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1112 + * xnode = node.children[xcat] + * # I put spanlen=1 below + * key = tuple([self.min_gap_size, i, 1, pathlen]) # <<<<<<<<<<<<<< + * frontier_nodes = [] + * if (key in nodes_isteps_away_buffer): + */ + __pyx_t_15 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->min_gap_size); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_10 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyList_New(4); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + PyList_SET_ITEM(__pyx_t_9, 0, __pyx_t_15); + __Pyx_GIVEREF(__pyx_t_15); + PyList_SET_ITEM(__pyx_t_9, 1, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __Pyx_INCREF(__pyx_int_1); + PyList_SET_ITEM(__pyx_t_9, 2, __pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_pathlen); + PyList_SET_ITEM(__pyx_t_9, 3, __pyx_cur_scope->__pyx_v_pathlen); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_pathlen); + __pyx_t_15 = 0; + __pyx_t_10 = 0; + __pyx_t_10 = ((PyObject *)PyList_AsTuple(__pyx_t_9)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_10)); + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_key)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_key)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); + __pyx_cur_scope->__pyx_v_key = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1113 + * # I put spanlen=1 below + * key = tuple([self.min_gap_size, i, 1, pathlen]) + * frontier_nodes = [] # <<<<<<<<<<<<<< + * if (key in nodes_isteps_away_buffer): + * frontier_nodes = nodes_isteps_away_buffer[key] + */ + __pyx_t_10 = PyList_New(0); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_frontier_nodes); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_frontier_nodes); + __Pyx_GIVEREF(((PyObject *)__pyx_t_10)); + __pyx_cur_scope->__pyx_v_frontier_nodes = ((PyObject *)__pyx_t_10); + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1114 + * key = tuple([self.min_gap_size, i, 1, pathlen]) + * frontier_nodes = [] + * if (key in nodes_isteps_away_buffer): # <<<<<<<<<<<<<< + * frontier_nodes = nodes_isteps_away_buffer[key] + * else: + */ + __pyx_t_8 = ((PyDict_Contains(((PyObject *)__pyx_cur_scope->__pyx_v_nodes_isteps_away_buffer), ((PyObject *)__pyx_cur_scope->__pyx_v_key)))); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1115 + * frontier_nodes = [] + * if (key in nodes_isteps_away_buffer): + * frontier_nodes = nodes_isteps_away_buffer[key] # <<<<<<<<<<<<<< + * else: + * frontier_nodes = self.get_all_nodes_isteps_away(self.min_gap_size, i, 1, pathlen, fwords, next_states, reachable_buffer) + */ + __pyx_t_10 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_nodes_isteps_away_buffer), ((PyObject *)__pyx_cur_scope->__pyx_v_key)); if (!__pyx_t_10) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_frontier_nodes); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_frontier_nodes); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_v_frontier_nodes = __pyx_t_10; + __pyx_t_10 = 0; + goto __pyx_L65; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1117 + * frontier_nodes = nodes_isteps_away_buffer[key] + * else: + * frontier_nodes = self.get_all_nodes_isteps_away(self.min_gap_size, i, 1, pathlen, fwords, next_states, reachable_buffer) # <<<<<<<<<<<<<< + * nodes_isteps_away_buffer[key] = frontier_nodes + * + */ + __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_121); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->min_gap_size); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_15 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_3 = PyTuple_New(7); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_15); + __Pyx_GIVEREF(__pyx_t_15); + __Pyx_INCREF(__pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_int_1); + __Pyx_GIVEREF(__pyx_int_1); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_pathlen); + PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_cur_scope->__pyx_v_pathlen); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_pathlen); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fwords); + PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_cur_scope->__pyx_v_fwords); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_fwords); + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_next_states)); + PyTuple_SET_ITEM(__pyx_t_3, 5, ((PyObject *)__pyx_cur_scope->__pyx_v_next_states)); + __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_next_states)); + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_reachable_buffer)); + PyTuple_SET_ITEM(__pyx_t_3, 6, ((PyObject *)__pyx_cur_scope->__pyx_v_reachable_buffer)); + __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_reachable_buffer)); + __pyx_t_9 = 0; + __pyx_t_15 = 0; + __pyx_t_15 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_frontier_nodes); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_frontier_nodes); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_cur_scope->__pyx_v_frontier_nodes = __pyx_t_15; + __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1118 + * else: + * frontier_nodes = self.get_all_nodes_isteps_away(self.min_gap_size, i, 1, pathlen, fwords, next_states, reachable_buffer) + * nodes_isteps_away_buffer[key] = frontier_nodes # <<<<<<<<<<<<<< + * + * for (i, alt, pathlen) in frontier_nodes: + */ + if (PyDict_SetItem(((PyObject *)__pyx_cur_scope->__pyx_v_nodes_isteps_away_buffer), ((PyObject *)__pyx_cur_scope->__pyx_v_key), __pyx_cur_scope->__pyx_v_frontier_nodes) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L65:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1120 + * nodes_isteps_away_buffer[key] = frontier_nodes + * + * for (i, alt, pathlen) in frontier_nodes: # <<<<<<<<<<<<<< + * new_frontier.append((k, i, alt, pathlen, xnode, phrase +(xcat,), is_shadow_path)) + * frontier = new_frontier + */ + if (PyList_CheckExact(__pyx_cur_scope->__pyx_v_frontier_nodes) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_frontier_nodes)) { + __pyx_t_15 = __pyx_cur_scope->__pyx_v_frontier_nodes; __Pyx_INCREF(__pyx_t_15); __pyx_t_21 = 0; + __pyx_t_27 = NULL; + } else { + __pyx_t_21 = -1; __pyx_t_15 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_frontier_nodes); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_27 = Py_TYPE(__pyx_t_15)->tp_iternext; + } + for (;;) { + if (!__pyx_t_27 && PyList_CheckExact(__pyx_t_15)) { + if (__pyx_t_21 >= PyList_GET_SIZE(__pyx_t_15)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_3 = PyList_GET_ITEM(__pyx_t_15, __pyx_t_21); __Pyx_INCREF(__pyx_t_3); __pyx_t_21++; + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_15, __pyx_t_21); __pyx_t_21++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_27 && PyTuple_CheckExact(__pyx_t_15)) { + if (__pyx_t_21 >= PyTuple_GET_SIZE(__pyx_t_15)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_15, __pyx_t_21); __Pyx_INCREF(__pyx_t_3); __pyx_t_21++; + #else + __pyx_t_3 = PySequence_ITEM(__pyx_t_15, __pyx_t_21); __pyx_t_21++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_3 = __pyx_t_27(__pyx_t_15); + if (unlikely(!__pyx_t_3)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_3); + } + if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { + PyObject* sequence = __pyx_t_3; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 3)) { + if (size > 3) __Pyx_RaiseTooManyValuesError(3); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 2); + } else { + __pyx_t_10 = PyList_GET_ITEM(sequence, 0); + __pyx_t_9 = PyList_GET_ITEM(sequence, 1); + __pyx_t_2 = PyList_GET_ITEM(sequence, 2); + } + __Pyx_INCREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(__pyx_t_2); + #else + __pyx_t_10 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + { + Py_ssize_t index = -1; + __pyx_t_14 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_17 = Py_TYPE(__pyx_t_14)->tp_iternext; + index = 0; __pyx_t_10 = __pyx_t_17(__pyx_t_14); if (unlikely(!__pyx_t_10)) goto __pyx_L68_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + index = 1; __pyx_t_9 = __pyx_t_17(__pyx_t_14); if (unlikely(!__pyx_t_9)) goto __pyx_L68_unpacking_failed; + __Pyx_GOTREF(__pyx_t_9); + index = 2; __pyx_t_2 = __pyx_t_17(__pyx_t_14); if (unlikely(!__pyx_t_2)) goto __pyx_L68_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_14), 3) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_17 = NULL; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + goto __pyx_L69_unpacking_done; + __pyx_L68_unpacking_failed:; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_17 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L69_unpacking_done:; + } + __pyx_t_18 = __Pyx_PyInt_AsInt(__pyx_t_10); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_6 = __Pyx_PyInt_AsInt(__pyx_t_9); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_cur_scope->__pyx_v_i = __pyx_t_18; + __pyx_cur_scope->__pyx_v_alt = __pyx_t_6; + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_pathlen); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_pathlen); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_v_pathlen = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1121 + * + * for (i, alt, pathlen) in frontier_nodes: + * new_frontier.append((k, i, alt, pathlen, xnode, phrase +(xcat,), is_shadow_path)) # <<<<<<<<<<<<<< + * frontier = new_frontier + * + */ + __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_k); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_alt); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_xcat); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __pyx_t_10 = 0; + __pyx_t_10 = PyNumber_Add(__pyx_cur_scope->__pyx_v_phrase, ((PyObject *)__pyx_t_14)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; + __pyx_t_14 = PyTuple_New(7); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_pathlen); + PyTuple_SET_ITEM(__pyx_t_14, 3, __pyx_cur_scope->__pyx_v_pathlen); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_pathlen); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_xnode); + PyTuple_SET_ITEM(__pyx_t_14, 4, __pyx_cur_scope->__pyx_v_xnode); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_xnode); + PyTuple_SET_ITEM(__pyx_t_14, 5, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_is_shadow_path); + PyTuple_SET_ITEM(__pyx_t_14, 6, __pyx_cur_scope->__pyx_v_is_shadow_path); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_is_shadow_path); + __pyx_t_3 = 0; + __pyx_t_2 = 0; + __pyx_t_9 = 0; + __pyx_t_10 = 0; + __pyx_t_11 = PyList_Append(__pyx_cur_scope->__pyx_v_new_frontier, ((PyObject *)__pyx_t_14)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; + } + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + goto __pyx_L64; + } + __pyx_L64:; + goto __pyx_L60; + } + __pyx_L60:; + __pyx_L19_continue:; + } + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1122 + * for (i, alt, pathlen) in frontier_nodes: + * new_frontier.append((k, i, alt, pathlen, xnode, phrase +(xcat,), is_shadow_path)) + * frontier = new_frontier # <<<<<<<<<<<<<< + * + * stop_time = monitor_cpu() + */ + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_new_frontier)); + __Pyx_GOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_frontier)); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope->__pyx_v_frontier)); + __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_new_frontier)); + __pyx_cur_scope->__pyx_v_frontier = __pyx_cur_scope->__pyx_v_new_frontier; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1124 + * frontier = new_frontier + * + * stop_time = monitor_cpu() # <<<<<<<<<<<<<< + * logger.info("Total time for rule lookup, extraction, and scoring = %f seconds", (stop_time - start_time)) + * gc.collect() + */ + __pyx_t_12 = PyFloat_FromDouble(__pyx_f_3_sa_monitor_cpu()); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_GIVEREF(__pyx_t_12); + __pyx_cur_scope->__pyx_v_stop_time = __pyx_t_12; + __pyx_t_12 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1125 + * + * stop_time = monitor_cpu() + * logger.info("Total time for rule lookup, extraction, and scoring = %f seconds", (stop_time - start_time)) # <<<<<<<<<<<<<< + * gc.collect() + * logger.info(" Extract time = %f seconds", self.extract_time) + */ + __pyx_t_12 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_15 = PyObject_GetAttr(__pyx_t_12, __pyx_n_s__info); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = PyFloat_FromDouble(__pyx_cur_scope->__pyx_v_start_time); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_14 = PyNumber_Subtract(__pyx_cur_scope->__pyx_v_stop_time, __pyx_t_12); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_122)); + PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)__pyx_kp_s_122)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_122)); + PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_t_14 = 0; + __pyx_t_14 = PyObject_Call(__pyx_t_15, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1126 + * stop_time = monitor_cpu() + * logger.info("Total time for rule lookup, extraction, and scoring = %f seconds", (stop_time - start_time)) + * gc.collect() # <<<<<<<<<<<<<< + * logger.info(" Extract time = %f seconds", self.extract_time) + * + */ + __pyx_t_14 = __Pyx_GetName(__pyx_m, __pyx_n_s__gc); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_12 = PyObject_GetAttr(__pyx_t_14, __pyx_n_s__collect); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = PyObject_Call(__pyx_t_12, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1127 + * logger.info("Total time for rule lookup, extraction, and scoring = %f seconds", (stop_time - start_time)) + * gc.collect() + * logger.info(" Extract time = %f seconds", self.extract_time) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_14 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_12 = PyObject_GetAttr(__pyx_t_14, __pyx_n_s__info); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = PyFloat_FromDouble(__pyx_cur_scope->__pyx_v_self->extract_time); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_123)); + PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)__pyx_kp_s_123)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_123)); + PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_t_14 = 0; + __pyx_t_14 = PyObject_Call(__pyx_t_12, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_XDECREF(__pyx_t_15); + __Pyx_XDECREF(__pyx_t_16); + __Pyx_AddTraceback("input", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1130 + * + * + * cdef int find_fixpoint(self, # <<<<<<<<<<<<<< + * int f_low, f_high, + * int* f_links_low, int* f_links_high, + */ + +static int __pyx_f_3_sa_23HieroCachingRuleFactory_find_fixpoint(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, int __pyx_v_f_low, PyObject *__pyx_v_f_high, int *__pyx_v_f_links_low, int *__pyx_v_f_links_high, int *__pyx_v_e_links_low, int *__pyx_v_e_links_high, int __pyx_v_e_in_low, int __pyx_v_e_in_high, int *__pyx_v_e_low, int *__pyx_v_e_high, int *__pyx_v_f_back_low, int *__pyx_v_f_back_high, int __pyx_v_f_sent_len, int __pyx_v_e_sent_len, int __pyx_v_max_f_len, int __pyx_v_max_e_len, int __pyx_v_min_fx_size, int __pyx_v_min_ex_size, int __pyx_v_max_new_x, int __pyx_v_allow_low_x, int __pyx_v_allow_high_x, int __pyx_v_allow_arbitrary_x, CYTHON_UNUSED int __pyx_v_write_log) { + int __pyx_v_e_low_prev; + int __pyx_v_e_high_prev; + int __pyx_v_f_low_prev; + int __pyx_v_f_high_prev; + int __pyx_v_new_x; + int __pyx_v_new_low_x; + int __pyx_v_new_high_x; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("find_fixpoint", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1145 + * cdef int e_low_prev, e_high_prev, f_low_prev, f_high_prev, new_x, new_low_x, new_high_x + * + * e_low[0] = e_in_low # <<<<<<<<<<<<<< + * e_high[0] = e_in_high + * self.find_projection(f_low, f_high, f_links_low, f_links_high, e_low, e_high) + */ + (__pyx_v_e_low[0]) = __pyx_v_e_in_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1146 + * + * e_low[0] = e_in_low + * e_high[0] = e_in_high # <<<<<<<<<<<<<< + * self.find_projection(f_low, f_high, f_links_low, f_links_high, e_low, e_high) + * if e_low[0] == -1: + */ + (__pyx_v_e_high[0]) = __pyx_v_e_in_high; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1147 + * e_low[0] = e_in_low + * e_high[0] = e_in_high + * self.find_projection(f_low, f_high, f_links_low, f_links_high, e_low, e_high) # <<<<<<<<<<<<<< + * if e_low[0] == -1: + * # low-priority corner case: if phrase w is unaligned, + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_f_high); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_projection(__pyx_v_self, __pyx_v_f_low, __pyx_t_1, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_low, __pyx_v_e_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1148 + * e_high[0] = e_in_high + * self.find_projection(f_low, f_high, f_links_low, f_links_high, e_low, e_high) + * if e_low[0] == -1: # <<<<<<<<<<<<<< + * # low-priority corner case: if phrase w is unaligned, + * # but we don't require aligned terminals, then returning + */ + __pyx_t_3 = ((__pyx_v_e_low[0]) == -1); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1154 + * # rule X -> X_1 w X_2 / X_1 X_2. This is probably + * # not worth the bother, though. + * return 0 # <<<<<<<<<<<<<< + * elif e_in_low != -1 and e_low[0] != e_in_low: + * if e_in_low - e_low[0] < min_ex_size: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L3; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1155 + * # not worth the bother, though. + * return 0 + * elif e_in_low != -1 and e_low[0] != e_in_low: # <<<<<<<<<<<<<< + * if e_in_low - e_low[0] < min_ex_size: + * e_low[0] = e_in_low - min_ex_size + */ + __pyx_t_3 = (__pyx_v_e_in_low != -1); + if (__pyx_t_3) { + __pyx_t_4 = ((__pyx_v_e_low[0]) != __pyx_v_e_in_low); + __pyx_t_5 = __pyx_t_4; + } else { + __pyx_t_5 = __pyx_t_3; + } + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1156 + * return 0 + * elif e_in_low != -1 and e_low[0] != e_in_low: + * if e_in_low - e_low[0] < min_ex_size: # <<<<<<<<<<<<<< + * e_low[0] = e_in_low - min_ex_size + * if e_low[0] < 0: + */ + __pyx_t_5 = ((__pyx_v_e_in_low - (__pyx_v_e_low[0])) < __pyx_v_min_ex_size); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1157 + * elif e_in_low != -1 and e_low[0] != e_in_low: + * if e_in_low - e_low[0] < min_ex_size: + * e_low[0] = e_in_low - min_ex_size # <<<<<<<<<<<<<< + * if e_low[0] < 0: + * return 0 + */ + (__pyx_v_e_low[0]) = (__pyx_v_e_in_low - __pyx_v_min_ex_size); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1158 + * if e_in_low - e_low[0] < min_ex_size: + * e_low[0] = e_in_low - min_ex_size + * if e_low[0] < 0: # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_t_5 = ((__pyx_v_e_low[0]) < 0); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1159 + * e_low[0] = e_in_low - min_ex_size + * if e_low[0] < 0: + * return 0 # <<<<<<<<<<<<<< + * + * if e_high[0] - e_low[0] > max_e_len: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L5; + } + __pyx_L5:; + goto __pyx_L4; + } + __pyx_L4:; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1161 + * return 0 + * + * if e_high[0] - e_low[0] > max_e_len: # <<<<<<<<<<<<<< + * return 0 + * elif e_in_high != -1 and e_high[0] != e_in_high: + */ + __pyx_t_5 = (((__pyx_v_e_high[0]) - (__pyx_v_e_low[0])) > __pyx_v_max_e_len); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1162 + * + * if e_high[0] - e_low[0] > max_e_len: + * return 0 # <<<<<<<<<<<<<< + * elif e_in_high != -1 and e_high[0] != e_in_high: + * if e_high[0] - e_in_high < min_ex_size: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L6; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1163 + * if e_high[0] - e_low[0] > max_e_len: + * return 0 + * elif e_in_high != -1 and e_high[0] != e_in_high: # <<<<<<<<<<<<<< + * if e_high[0] - e_in_high < min_ex_size: + * e_high[0] = e_in_high + min_ex_size + */ + __pyx_t_5 = (__pyx_v_e_in_high != -1); + if (__pyx_t_5) { + __pyx_t_3 = ((__pyx_v_e_high[0]) != __pyx_v_e_in_high); + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_5; + } + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1164 + * return 0 + * elif e_in_high != -1 and e_high[0] != e_in_high: + * if e_high[0] - e_in_high < min_ex_size: # <<<<<<<<<<<<<< + * e_high[0] = e_in_high + min_ex_size + * if e_high[0] > e_sent_len: + */ + __pyx_t_4 = (((__pyx_v_e_high[0]) - __pyx_v_e_in_high) < __pyx_v_min_ex_size); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1165 + * elif e_in_high != -1 and e_high[0] != e_in_high: + * if e_high[0] - e_in_high < min_ex_size: + * e_high[0] = e_in_high + min_ex_size # <<<<<<<<<<<<<< + * if e_high[0] > e_sent_len: + * return 0 + */ + (__pyx_v_e_high[0]) = (__pyx_v_e_in_high + __pyx_v_min_ex_size); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1166 + * if e_high[0] - e_in_high < min_ex_size: + * e_high[0] = e_in_high + min_ex_size + * if e_high[0] > e_sent_len: # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_t_4 = ((__pyx_v_e_high[0]) > __pyx_v_e_sent_len); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1167 + * e_high[0] = e_in_high + min_ex_size + * if e_high[0] > e_sent_len: + * return 0 # <<<<<<<<<<<<<< + * + * f_back_low[0] = -1 + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L8; + } + __pyx_L8:; + goto __pyx_L7; + } + __pyx_L7:; + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1169 + * return 0 + * + * f_back_low[0] = -1 # <<<<<<<<<<<<<< + * f_back_high[0] = -1 + * f_low_prev = f_low + */ + (__pyx_v_f_back_low[0]) = -1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1170 + * + * f_back_low[0] = -1 + * f_back_high[0] = -1 # <<<<<<<<<<<<<< + * f_low_prev = f_low + * f_high_prev = f_high + */ + (__pyx_v_f_back_high[0]) = -1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1171 + * f_back_low[0] = -1 + * f_back_high[0] = -1 + * f_low_prev = f_low # <<<<<<<<<<<<<< + * f_high_prev = f_high + * new_x = 0 + */ + __pyx_v_f_low_prev = __pyx_v_f_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1172 + * f_back_high[0] = -1 + * f_low_prev = f_low + * f_high_prev = f_high # <<<<<<<<<<<<<< + * new_x = 0 + * new_low_x = 0 + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_f_high); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_f_high_prev = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1173 + * f_low_prev = f_low + * f_high_prev = f_high + * new_x = 0 # <<<<<<<<<<<<<< + * new_low_x = 0 + * new_high_x = 0 + */ + __pyx_v_new_x = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1174 + * f_high_prev = f_high + * new_x = 0 + * new_low_x = 0 # <<<<<<<<<<<<<< + * new_high_x = 0 + * + */ + __pyx_v_new_low_x = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1175 + * new_x = 0 + * new_low_x = 0 + * new_high_x = 0 # <<<<<<<<<<<<<< + * + * while True: + */ + __pyx_v_new_high_x = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1177 + * new_high_x = 0 + * + * while True: # <<<<<<<<<<<<<< + * + * if f_back_low[0] == -1: + */ + while (1) { + if (!1) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1179 + * while True: + * + * if f_back_low[0] == -1: # <<<<<<<<<<<<<< + * self.find_projection(e_low[0], e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) + * else: + */ + __pyx_t_4 = ((__pyx_v_f_back_low[0]) == -1); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1180 + * + * if f_back_low[0] == -1: + * self.find_projection(e_low[0], e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) # <<<<<<<<<<<<<< + * else: + * self.find_projection(e_low[0], e_low_prev, e_links_low, e_links_high, f_back_low, f_back_high) + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_projection(__pyx_v_self, (__pyx_v_e_low[0]), (__pyx_v_e_high[0]), __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_f_back_low, __pyx_v_f_back_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1180; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L11; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1182 + * self.find_projection(e_low[0], e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) + * else: + * self.find_projection(e_low[0], e_low_prev, e_links_low, e_links_high, f_back_low, f_back_high) # <<<<<<<<<<<<<< + * self.find_projection(e_high_prev, e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) + * + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_projection(__pyx_v_self, (__pyx_v_e_low[0]), __pyx_v_e_low_prev, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_f_back_low, __pyx_v_f_back_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1182; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1183 + * else: + * self.find_projection(e_low[0], e_low_prev, e_links_low, e_links_high, f_back_low, f_back_high) + * self.find_projection(e_high_prev, e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) # <<<<<<<<<<<<<< + * + * if f_back_low[0] > f_low: + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_projection(__pyx_v_self, __pyx_v_e_high_prev, (__pyx_v_e_high[0]), __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_f_back_low, __pyx_v_f_back_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __pyx_L11:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1185 + * self.find_projection(e_high_prev, e_high[0], e_links_low, e_links_high, f_back_low, f_back_high) + * + * if f_back_low[0] > f_low: # <<<<<<<<<<<<<< + * f_back_low[0] = f_low + * + */ + __pyx_t_4 = ((__pyx_v_f_back_low[0]) > __pyx_v_f_low); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1186 + * + * if f_back_low[0] > f_low: + * f_back_low[0] = f_low # <<<<<<<<<<<<<< + * + * if f_back_high[0] < f_high: + */ + (__pyx_v_f_back_low[0]) = __pyx_v_f_low; + goto __pyx_L12; + } + __pyx_L12:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1188 + * f_back_low[0] = f_low + * + * if f_back_high[0] < f_high: # <<<<<<<<<<<<<< + * f_back_high[0] = f_high + * + */ + __pyx_t_2 = PyInt_FromLong((__pyx_v_f_back_high[0])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = PyObject_RichCompare(__pyx_t_2, __pyx_v_f_high, Py_LT); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1189 + * + * if f_back_high[0] < f_high: + * f_back_high[0] = f_high # <<<<<<<<<<<<<< + * + * if f_back_low[0] == f_low_prev and f_back_high[0] == f_high_prev: + */ + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_v_f_high); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1189; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + (__pyx_v_f_back_high[0]) = __pyx_t_1; + goto __pyx_L13; + } + __pyx_L13:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1191 + * f_back_high[0] = f_high + * + * if f_back_low[0] == f_low_prev and f_back_high[0] == f_high_prev: # <<<<<<<<<<<<<< + * return 1 + * + */ + __pyx_t_4 = ((__pyx_v_f_back_low[0]) == __pyx_v_f_low_prev); + if (__pyx_t_4) { + __pyx_t_5 = ((__pyx_v_f_back_high[0]) == __pyx_v_f_high_prev); + __pyx_t_3 = __pyx_t_5; + } else { + __pyx_t_3 = __pyx_t_4; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1192 + * + * if f_back_low[0] == f_low_prev and f_back_high[0] == f_high_prev: + * return 1 # <<<<<<<<<<<<<< + * + * if allow_low_x == 0 and f_back_low[0] < f_low: + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L14; + } + __pyx_L14:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1194 + * return 1 + * + * if allow_low_x == 0 and f_back_low[0] < f_low: # <<<<<<<<<<<<<< + * # FAIL: f phrase is not tight + * return 0 + */ + __pyx_t_3 = (__pyx_v_allow_low_x == 0); + if (__pyx_t_3) { + __pyx_t_4 = ((__pyx_v_f_back_low[0]) < __pyx_v_f_low); + __pyx_t_5 = __pyx_t_4; + } else { + __pyx_t_5 = __pyx_t_3; + } + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1196 + * if allow_low_x == 0 and f_back_low[0] < f_low: + * # FAIL: f phrase is not tight + * return 0 # <<<<<<<<<<<<<< + * + * if f_back_high[0] - f_back_low[0] > max_f_len: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L15; + } + __pyx_L15:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1198 + * return 0 + * + * if f_back_high[0] - f_back_low[0] > max_f_len: # <<<<<<<<<<<<<< + * # FAIL: f back projection is too wide + * return 0 + */ + __pyx_t_5 = (((__pyx_v_f_back_high[0]) - (__pyx_v_f_back_low[0])) > __pyx_v_max_f_len); + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1200 + * if f_back_high[0] - f_back_low[0] > max_f_len: + * # FAIL: f back projection is too wide + * return 0 # <<<<<<<<<<<<<< + * + * if allow_high_x == 0 and f_back_high[0] > f_high: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L16; + } + __pyx_L16:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1202 + * return 0 + * + * if allow_high_x == 0 and f_back_high[0] > f_high: # <<<<<<<<<<<<<< + * # FAIL: extension on high side not allowed + * return 0 + */ + __pyx_t_5 = (__pyx_v_allow_high_x == 0); + if (__pyx_t_5) { + __pyx_t_6 = PyInt_FromLong((__pyx_v_f_back_high[0])); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_2 = PyObject_RichCompare(__pyx_t_6, __pyx_v_f_high, Py_GT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_5; + } + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1204 + * if allow_high_x == 0 and f_back_high[0] > f_high: + * # FAIL: extension on high side not allowed + * return 0 # <<<<<<<<<<<<<< + * + * if f_low != f_back_low[0]: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L17; + } + __pyx_L17:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1206 + * return 0 + * + * if f_low != f_back_low[0]: # <<<<<<<<<<<<<< + * if new_low_x == 0: + * if new_x >= max_new_x: + */ + __pyx_t_4 = (__pyx_v_f_low != (__pyx_v_f_back_low[0])); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1207 + * + * if f_low != f_back_low[0]: + * if new_low_x == 0: # <<<<<<<<<<<<<< + * if new_x >= max_new_x: + * # FAIL: extension required on low side violates max # of gaps + */ + __pyx_t_4 = (__pyx_v_new_low_x == 0); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1208 + * if f_low != f_back_low[0]: + * if new_low_x == 0: + * if new_x >= max_new_x: # <<<<<<<<<<<<<< + * # FAIL: extension required on low side violates max # of gaps + * return 0 + */ + __pyx_t_4 = (__pyx_v_new_x >= __pyx_v_max_new_x); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1210 + * if new_x >= max_new_x: + * # FAIL: extension required on low side violates max # of gaps + * return 0 # <<<<<<<<<<<<<< + * else: + * new_x = new_x + 1 + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L20; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1212 + * return 0 + * else: + * new_x = new_x + 1 # <<<<<<<<<<<<<< + * new_low_x = 1 + * if f_low - f_back_low[0] < min_fx_size: + */ + __pyx_v_new_x = (__pyx_v_new_x + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1213 + * else: + * new_x = new_x + 1 + * new_low_x = 1 # <<<<<<<<<<<<<< + * if f_low - f_back_low[0] < min_fx_size: + * f_back_low[0] = f_low - min_fx_size + */ + __pyx_v_new_low_x = 1; + } + __pyx_L20:; + goto __pyx_L19; + } + __pyx_L19:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1214 + * new_x = new_x + 1 + * new_low_x = 1 + * if f_low - f_back_low[0] < min_fx_size: # <<<<<<<<<<<<<< + * f_back_low[0] = f_low - min_fx_size + * if f_back_high[0] - f_back_low[0] > max_f_len: + */ + __pyx_t_4 = ((__pyx_v_f_low - (__pyx_v_f_back_low[0])) < __pyx_v_min_fx_size); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1215 + * new_low_x = 1 + * if f_low - f_back_low[0] < min_fx_size: + * f_back_low[0] = f_low - min_fx_size # <<<<<<<<<<<<<< + * if f_back_high[0] - f_back_low[0] > max_f_len: + * # FAIL: extension required on low side violates max initial length + */ + (__pyx_v_f_back_low[0]) = (__pyx_v_f_low - __pyx_v_min_fx_size); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1216 + * if f_low - f_back_low[0] < min_fx_size: + * f_back_low[0] = f_low - min_fx_size + * if f_back_high[0] - f_back_low[0] > max_f_len: # <<<<<<<<<<<<<< + * # FAIL: extension required on low side violates max initial length + * return 0 + */ + __pyx_t_4 = (((__pyx_v_f_back_high[0]) - (__pyx_v_f_back_low[0])) > __pyx_v_max_f_len); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1218 + * if f_back_high[0] - f_back_low[0] > max_f_len: + * # FAIL: extension required on low side violates max initial length + * return 0 # <<<<<<<<<<<<<< + * if f_back_low[0] < 0: + * # FAIL: extension required on low side violates sentence boundary + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L22; + } + __pyx_L22:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1219 + * # FAIL: extension required on low side violates max initial length + * return 0 + * if f_back_low[0] < 0: # <<<<<<<<<<<<<< + * # FAIL: extension required on low side violates sentence boundary + * return 0 + */ + __pyx_t_4 = ((__pyx_v_f_back_low[0]) < 0); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1221 + * if f_back_low[0] < 0: + * # FAIL: extension required on low side violates sentence boundary + * return 0 # <<<<<<<<<<<<<< + * + * if f_high != f_back_high[0]: + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L23; + } + __pyx_L23:; + goto __pyx_L21; + } + __pyx_L21:; + goto __pyx_L18; + } + __pyx_L18:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1223 + * return 0 + * + * if f_high != f_back_high[0]: # <<<<<<<<<<<<<< + * if new_high_x == 0: + * if new_x >= max_new_x: + */ + __pyx_t_2 = PyInt_FromLong((__pyx_v_f_back_high[0])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1223; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = PyObject_RichCompare(__pyx_v_f_high, __pyx_t_2, Py_NE); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1223; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1223; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1224 + * + * if f_high != f_back_high[0]: + * if new_high_x == 0: # <<<<<<<<<<<<<< + * if new_x >= max_new_x: + * # FAIL: extension required on high side violates max # of gaps + */ + __pyx_t_4 = (__pyx_v_new_high_x == 0); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1225 + * if f_high != f_back_high[0]: + * if new_high_x == 0: + * if new_x >= max_new_x: # <<<<<<<<<<<<<< + * # FAIL: extension required on high side violates max # of gaps + * return 0 + */ + __pyx_t_4 = (__pyx_v_new_x >= __pyx_v_max_new_x); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1227 + * if new_x >= max_new_x: + * # FAIL: extension required on high side violates max # of gaps + * return 0 # <<<<<<<<<<<<<< + * else: + * new_x = new_x + 1 + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L26; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1229 + * return 0 + * else: + * new_x = new_x + 1 # <<<<<<<<<<<<<< + * new_high_x = 1 + * if f_back_high[0] - f_high < min_fx_size: + */ + __pyx_v_new_x = (__pyx_v_new_x + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1230 + * else: + * new_x = new_x + 1 + * new_high_x = 1 # <<<<<<<<<<<<<< + * if f_back_high[0] - f_high < min_fx_size: + * f_back_high[0] = f_high + min_fx_size + */ + __pyx_v_new_high_x = 1; + } + __pyx_L26:; + goto __pyx_L25; + } + __pyx_L25:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1231 + * new_x = new_x + 1 + * new_high_x = 1 + * if f_back_high[0] - f_high < min_fx_size: # <<<<<<<<<<<<<< + * f_back_high[0] = f_high + min_fx_size + * if f_back_high[0] - f_back_low[0] > max_f_len: + */ + __pyx_t_6 = PyInt_FromLong((__pyx_v_f_back_high[0])); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1231; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_2 = PyNumber_Subtract(__pyx_t_6, __pyx_v_f_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1231; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = PyInt_FromLong(__pyx_v_min_fx_size); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1231; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PyObject_RichCompare(__pyx_t_2, __pyx_t_6, Py_LT); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1231; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1231; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1232 + * new_high_x = 1 + * if f_back_high[0] - f_high < min_fx_size: + * f_back_high[0] = f_high + min_fx_size # <<<<<<<<<<<<<< + * if f_back_high[0] - f_back_low[0] > max_f_len: + * # FAIL: extension required on high side violates max initial length + */ + __pyx_t_7 = PyInt_FromLong(__pyx_v_min_fx_size); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = PyNumber_Add(__pyx_v_f_high, __pyx_t_7); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_1 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1232; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + (__pyx_v_f_back_high[0]) = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1233 + * if f_back_high[0] - f_high < min_fx_size: + * f_back_high[0] = f_high + min_fx_size + * if f_back_high[0] - f_back_low[0] > max_f_len: # <<<<<<<<<<<<<< + * # FAIL: extension required on high side violates max initial length + * return 0 + */ + __pyx_t_4 = (((__pyx_v_f_back_high[0]) - (__pyx_v_f_back_low[0])) > __pyx_v_max_f_len); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1235 + * if f_back_high[0] - f_back_low[0] > max_f_len: + * # FAIL: extension required on high side violates max initial length + * return 0 # <<<<<<<<<<<<<< + * if f_back_high[0] > f_sent_len: + * # FAIL: extension required on high side violates sentence boundary + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L28; + } + __pyx_L28:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1236 + * # FAIL: extension required on high side violates max initial length + * return 0 + * if f_back_high[0] > f_sent_len: # <<<<<<<<<<<<<< + * # FAIL: extension required on high side violates sentence boundary + * return 0 + */ + __pyx_t_4 = ((__pyx_v_f_back_high[0]) > __pyx_v_f_sent_len); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1238 + * if f_back_high[0] > f_sent_len: + * # FAIL: extension required on high side violates sentence boundary + * return 0 # <<<<<<<<<<<<<< + * + * e_low_prev = e_low[0] + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L29; + } + __pyx_L29:; + goto __pyx_L27; + } + __pyx_L27:; + goto __pyx_L24; + } + __pyx_L24:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1240 + * return 0 + * + * e_low_prev = e_low[0] # <<<<<<<<<<<<<< + * e_high_prev = e_high[0] + * + */ + __pyx_v_e_low_prev = (__pyx_v_e_low[0]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1241 + * + * e_low_prev = e_low[0] + * e_high_prev = e_high[0] # <<<<<<<<<<<<<< + * + * self.find_projection(f_back_low[0], f_low_prev, f_links_low, f_links_high, e_low, e_high) + */ + __pyx_v_e_high_prev = (__pyx_v_e_high[0]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1243 + * e_high_prev = e_high[0] + * + * self.find_projection(f_back_low[0], f_low_prev, f_links_low, f_links_high, e_low, e_high) # <<<<<<<<<<<<<< + * self.find_projection(f_high_prev, f_back_high[0], f_links_low, f_links_high, e_low, e_high) + * if e_low[0] == e_low_prev and e_high[0] == e_high_prev: + */ + __pyx_t_6 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_projection(__pyx_v_self, (__pyx_v_f_back_low[0]), __pyx_v_f_low_prev, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_low, __pyx_v_e_high); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1243; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1244 + * + * self.find_projection(f_back_low[0], f_low_prev, f_links_low, f_links_high, e_low, e_high) + * self.find_projection(f_high_prev, f_back_high[0], f_links_low, f_links_high, e_low, e_high) # <<<<<<<<<<<<<< + * if e_low[0] == e_low_prev and e_high[0] == e_high_prev: + * return 1 + */ + __pyx_t_6 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_projection(__pyx_v_self, __pyx_v_f_high_prev, (__pyx_v_f_back_high[0]), __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_low, __pyx_v_e_high); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1244; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1245 + * self.find_projection(f_back_low[0], f_low_prev, f_links_low, f_links_high, e_low, e_high) + * self.find_projection(f_high_prev, f_back_high[0], f_links_low, f_links_high, e_low, e_high) + * if e_low[0] == e_low_prev and e_high[0] == e_high_prev: # <<<<<<<<<<<<<< + * return 1 + * if allow_arbitrary_x == 0: + */ + __pyx_t_4 = ((__pyx_v_e_low[0]) == __pyx_v_e_low_prev); + if (__pyx_t_4) { + __pyx_t_5 = ((__pyx_v_e_high[0]) == __pyx_v_e_high_prev); + __pyx_t_3 = __pyx_t_5; + } else { + __pyx_t_3 = __pyx_t_4; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1246 + * self.find_projection(f_high_prev, f_back_high[0], f_links_low, f_links_high, e_low, e_high) + * if e_low[0] == e_low_prev and e_high[0] == e_high_prev: + * return 1 # <<<<<<<<<<<<<< + * if allow_arbitrary_x == 0: + * # FAIL: arbitrary expansion not permitted + */ + __pyx_r = 1; + goto __pyx_L0; + goto __pyx_L30; + } + __pyx_L30:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1247 + * if e_low[0] == e_low_prev and e_high[0] == e_high_prev: + * return 1 + * if allow_arbitrary_x == 0: # <<<<<<<<<<<<<< + * # FAIL: arbitrary expansion not permitted + * return 0 + */ + __pyx_t_3 = (__pyx_v_allow_arbitrary_x == 0); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1249 + * if allow_arbitrary_x == 0: + * # FAIL: arbitrary expansion not permitted + * return 0 # <<<<<<<<<<<<<< + * if e_high[0] - e_low[0] > max_e_len: + * # FAIL: re-projection violates sentence max phrase length + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L31; + } + __pyx_L31:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1250 + * # FAIL: arbitrary expansion not permitted + * return 0 + * if e_high[0] - e_low[0] > max_e_len: # <<<<<<<<<<<<<< + * # FAIL: re-projection violates sentence max phrase length + * return 0 + */ + __pyx_t_3 = (((__pyx_v_e_high[0]) - (__pyx_v_e_low[0])) > __pyx_v_max_e_len); + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1252 + * if e_high[0] - e_low[0] > max_e_len: + * # FAIL: re-projection violates sentence max phrase length + * return 0 # <<<<<<<<<<<<<< + * f_low_prev = f_back_low[0] + * f_high_prev = f_back_high[0] + */ + __pyx_r = 0; + goto __pyx_L0; + goto __pyx_L32; + } + __pyx_L32:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1253 + * # FAIL: re-projection violates sentence max phrase length + * return 0 + * f_low_prev = f_back_low[0] # <<<<<<<<<<<<<< + * f_high_prev = f_back_high[0] + * + */ + __pyx_v_f_low_prev = (__pyx_v_f_back_low[0]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1254 + * return 0 + * f_low_prev = f_back_low[0] + * f_high_prev = f_back_high[0] # <<<<<<<<<<<<<< + * + * + */ + __pyx_v_f_high_prev = (__pyx_v_f_back_high[0]); + } + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_WriteUnraisable("_sa.HieroCachingRuleFactory.find_fixpoint", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1257 + * + * + * cdef find_projection(self, int in_low, int in_high, int* in_links_low, int* in_links_high, # <<<<<<<<<<<<<< + * int* out_low, int* out_high): + * cdef int i + */ + +static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_find_projection(CYTHON_UNUSED struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, int __pyx_v_in_low, int __pyx_v_in_high, int *__pyx_v_in_links_low, int *__pyx_v_in_links_high, int *__pyx_v_out_low, int *__pyx_v_out_high) { + int __pyx_v_i; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + __Pyx_RefNannySetupContext("find_projection", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1260 + * int* out_low, int* out_high): + * cdef int i + * for i from in_low <= i < in_high: # <<<<<<<<<<<<<< + * if in_links_low[i] != -1: + * if out_low[0] == -1 or in_links_low[i] < out_low[0]: + */ + __pyx_t_1 = __pyx_v_in_high; + for (__pyx_v_i = __pyx_v_in_low; __pyx_v_i < __pyx_t_1; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1261 + * cdef int i + * for i from in_low <= i < in_high: + * if in_links_low[i] != -1: # <<<<<<<<<<<<<< + * if out_low[0] == -1 or in_links_low[i] < out_low[0]: + * out_low[0] = in_links_low[i] + */ + __pyx_t_2 = ((__pyx_v_in_links_low[__pyx_v_i]) != -1); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1262 + * for i from in_low <= i < in_high: + * if in_links_low[i] != -1: + * if out_low[0] == -1 or in_links_low[i] < out_low[0]: # <<<<<<<<<<<<<< + * out_low[0] = in_links_low[i] + * if out_high[0] == -1 or in_links_high[i] > out_high[0]: + */ + __pyx_t_2 = ((__pyx_v_out_low[0]) == -1); + if (!__pyx_t_2) { + __pyx_t_3 = ((__pyx_v_in_links_low[__pyx_v_i]) < (__pyx_v_out_low[0])); + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_2; + } + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1263 + * if in_links_low[i] != -1: + * if out_low[0] == -1 or in_links_low[i] < out_low[0]: + * out_low[0] = in_links_low[i] # <<<<<<<<<<<<<< + * if out_high[0] == -1 or in_links_high[i] > out_high[0]: + * out_high[0] = in_links_high[i] + */ + (__pyx_v_out_low[0]) = (__pyx_v_in_links_low[__pyx_v_i]); + goto __pyx_L6; + } + __pyx_L6:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1264 + * if out_low[0] == -1 or in_links_low[i] < out_low[0]: + * out_low[0] = in_links_low[i] + * if out_high[0] == -1 or in_links_high[i] > out_high[0]: # <<<<<<<<<<<<<< + * out_high[0] = in_links_high[i] + * + */ + __pyx_t_4 = ((__pyx_v_out_high[0]) == -1); + if (!__pyx_t_4) { + __pyx_t_2 = ((__pyx_v_in_links_high[__pyx_v_i]) > (__pyx_v_out_high[0])); + __pyx_t_3 = __pyx_t_2; + } else { + __pyx_t_3 = __pyx_t_4; + } + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1265 + * out_low[0] = in_links_low[i] + * if out_high[0] == -1 or in_links_high[i] > out_high[0]: + * out_high[0] = in_links_high[i] # <<<<<<<<<<<<<< + * + * + */ + (__pyx_v_out_high[0]) = (__pyx_v_in_links_high[__pyx_v_i]); + goto __pyx_L7; + } + __pyx_L7:; + goto __pyx_L5; + } + __pyx_L5:; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1268 + * + * + * cdef int* int_arr_extend(self, int* arr, int* arr_len, int* data, int data_len): # <<<<<<<<<<<<<< + * cdef int new_len + * new_len = arr_len[0] + data_len + */ + +static int *__pyx_f_3_sa_23HieroCachingRuleFactory_int_arr_extend(CYTHON_UNUSED struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, int *__pyx_v_arr, int *__pyx_v_arr_len, int *__pyx_v_data, int __pyx_v_data_len) { + int __pyx_v_new_len; + int *__pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("int_arr_extend", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1270 + * cdef int* int_arr_extend(self, int* arr, int* arr_len, int* data, int data_len): + * cdef int new_len + * new_len = arr_len[0] + data_len # <<<<<<<<<<<<<< + * arr = realloc(arr, new_len*sizeof(int)) + * memcpy(arr+arr_len[0], data, data_len*sizeof(int)) + */ + __pyx_v_new_len = ((__pyx_v_arr_len[0]) + __pyx_v_data_len); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1271 + * cdef int new_len + * new_len = arr_len[0] + data_len + * arr = realloc(arr, new_len*sizeof(int)) # <<<<<<<<<<<<<< + * memcpy(arr+arr_len[0], data, data_len*sizeof(int)) + * arr_len[0] = new_len + */ + __pyx_v_arr = ((int *)realloc(__pyx_v_arr, (__pyx_v_new_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1272 + * new_len = arr_len[0] + data_len + * arr = realloc(arr, new_len*sizeof(int)) + * memcpy(arr+arr_len[0], data, data_len*sizeof(int)) # <<<<<<<<<<<<<< + * arr_len[0] = new_len + * return arr + */ + memcpy((__pyx_v_arr + (__pyx_v_arr_len[0])), __pyx_v_data, (__pyx_v_data_len * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1273 + * arr = realloc(arr, new_len*sizeof(int)) + * memcpy(arr+arr_len[0], data, data_len*sizeof(int)) + * arr_len[0] = new_len # <<<<<<<<<<<<<< + * return arr + * + */ + (__pyx_v_arr_len[0]) = __pyx_v_new_len; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1274 + * memcpy(arr+arr_len[0], data, data_len*sizeof(int)) + * arr_len[0] = new_len + * return arr # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = __pyx_v_arr; + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1277 + * + * + * cdef extract_phrases(self, int e_low, int e_high, int* e_gap_low, int* e_gap_high, int* e_links_low, int num_gaps, # <<<<<<<<<<<<<< + * int f_low, int f_high, int* f_gap_low, int* f_gap_high, int* f_links_low, + * int sent_id, int e_sent_len, int e_sent_start): + */ + +static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_extract_phrases(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, int __pyx_v_e_low, int __pyx_v_e_high, int *__pyx_v_e_gap_low, int *__pyx_v_e_gap_high, int *__pyx_v_e_links_low, int __pyx_v_num_gaps, CYTHON_UNUSED int __pyx_v_f_low, CYTHON_UNUSED int __pyx_v_f_high, CYTHON_UNUSED int *__pyx_v_f_gap_low, CYTHON_UNUSED int *__pyx_v_f_gap_high, CYTHON_UNUSED int *__pyx_v_f_links_low, CYTHON_UNUSED int __pyx_v_sent_id, int __pyx_v_e_sent_len, int __pyx_v_e_sent_start) { + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_k; + int __pyx_v_m; + int __pyx_v_n; + int *__pyx_v_e_gap_order; + int __pyx_v_e_x_low; + int __pyx_v_e_x_high; + int __pyx_v_e_x_gap_low; + int __pyx_v_e_x_gap_high; + int *__pyx_v_e_gaps1; + int *__pyx_v_e_gaps2; + int __pyx_v_len1; + int __pyx_v_len2; + int __pyx_v_step; + int __pyx_v_num_chunks; + struct __pyx_obj_3_sa_IntList *__pyx_v_ephr_arr = 0; + PyObject *__pyx_v_result = 0; + PyObject *__pyx_v_indexes = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + long __pyx_t_9; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("extract_phrases", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1285 + * cdef result + * + * result = [] # <<<<<<<<<<<<<< + * len1 = 0 + * e_gaps1 = malloc(0) + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1285; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1286 + * + * result = [] + * len1 = 0 # <<<<<<<<<<<<<< + * e_gaps1 = malloc(0) + * ephr_arr = IntList() + */ + __pyx_v_len1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1287 + * result = [] + * len1 = 0 + * e_gaps1 = malloc(0) # <<<<<<<<<<<<<< + * ephr_arr = IntList() + * + */ + __pyx_v_e_gaps1 = ((int *)malloc(0)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1288 + * len1 = 0 + * e_gaps1 = malloc(0) + * ephr_arr = IntList() # <<<<<<<<<<<<<< + * + * e_gap_order = malloc(num_gaps*sizeof(int)) + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1288; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_ephr_arr = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1290 + * ephr_arr = IntList() + * + * e_gap_order = malloc(num_gaps*sizeof(int)) # <<<<<<<<<<<<<< + * if num_gaps > 0: + * e_gap_order[0] = 0 + */ + __pyx_v_e_gap_order = ((int *)malloc((__pyx_v_num_gaps * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1291 + * + * e_gap_order = malloc(num_gaps*sizeof(int)) + * if num_gaps > 0: # <<<<<<<<<<<<<< + * e_gap_order[0] = 0 + * for i from 1 <= i < num_gaps: + */ + __pyx_t_2 = (__pyx_v_num_gaps > 0); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1292 + * e_gap_order = malloc(num_gaps*sizeof(int)) + * if num_gaps > 0: + * e_gap_order[0] = 0 # <<<<<<<<<<<<<< + * for i from 1 <= i < num_gaps: + * for j from 0 <= j < i: + */ + (__pyx_v_e_gap_order[0]) = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1293 + * if num_gaps > 0: + * e_gap_order[0] = 0 + * for i from 1 <= i < num_gaps: # <<<<<<<<<<<<<< + * for j from 0 <= j < i: + * if e_gap_low[i] < e_gap_low[j]: + */ + __pyx_t_3 = __pyx_v_num_gaps; + for (__pyx_v_i = 1; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1294 + * e_gap_order[0] = 0 + * for i from 1 <= i < num_gaps: + * for j from 0 <= j < i: # <<<<<<<<<<<<<< + * if e_gap_low[i] < e_gap_low[j]: + * for k from j <= k < i: + */ + __pyx_t_4 = __pyx_v_i; + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_4; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1295 + * for i from 1 <= i < num_gaps: + * for j from 0 <= j < i: + * if e_gap_low[i] < e_gap_low[j]: # <<<<<<<<<<<<<< + * for k from j <= k < i: + * e_gap_order[k+1] = e_gap_order[k] + */ + __pyx_t_2 = ((__pyx_v_e_gap_low[__pyx_v_i]) < (__pyx_v_e_gap_low[__pyx_v_j])); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1296 + * for j from 0 <= j < i: + * if e_gap_low[i] < e_gap_low[j]: + * for k from j <= k < i: # <<<<<<<<<<<<<< + * e_gap_order[k+1] = e_gap_order[k] + * e_gap_order[j] = i + */ + __pyx_t_5 = __pyx_v_i; + for (__pyx_v_k = __pyx_v_j; __pyx_v_k < __pyx_t_5; __pyx_v_k++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1297 + * if e_gap_low[i] < e_gap_low[j]: + * for k from j <= k < i: + * e_gap_order[k+1] = e_gap_order[k] # <<<<<<<<<<<<<< + * e_gap_order[j] = i + * break + */ + (__pyx_v_e_gap_order[(__pyx_v_k + 1)]) = (__pyx_v_e_gap_order[__pyx_v_k]); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1298 + * for k from j <= k < i: + * e_gap_order[k+1] = e_gap_order[k] + * e_gap_order[j] = i # <<<<<<<<<<<<<< + * break + * else: + */ + (__pyx_v_e_gap_order[__pyx_v_j]) = __pyx_v_i; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1299 + * e_gap_order[k+1] = e_gap_order[k] + * e_gap_order[j] = i + * break # <<<<<<<<<<<<<< + * else: + * e_gap_order[i] = i + */ + goto __pyx_L7_break; + goto __pyx_L8; + } + __pyx_L8:; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1301 + * break + * else: + * e_gap_order[i] = i # <<<<<<<<<<<<<< + * + * e_x_low = e_low + */ + (__pyx_v_e_gap_order[__pyx_v_i]) = __pyx_v_i; + } + __pyx_L7_break:; + } + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1303 + * e_gap_order[i] = i + * + * e_x_low = e_low # <<<<<<<<<<<<<< + * e_x_high = e_high + * if self.tight_phrases == 0: + */ + __pyx_v_e_x_low = __pyx_v_e_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1304 + * + * e_x_low = e_low + * e_x_high = e_high # <<<<<<<<<<<<<< + * if self.tight_phrases == 0: + * while e_x_low > 0 and e_high - e_x_low < self.train_max_initial_size and e_links_low[e_x_low-1] == -1: + */ + __pyx_v_e_x_high = __pyx_v_e_high; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1305 + * e_x_low = e_low + * e_x_high = e_high + * if self.tight_phrases == 0: # <<<<<<<<<<<<<< + * while e_x_low > 0 and e_high - e_x_low < self.train_max_initial_size and e_links_low[e_x_low-1] == -1: + * e_x_low = e_x_low - 1 + */ + __pyx_t_2 = (__pyx_v_self->tight_phrases == 0); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1306 + * e_x_high = e_high + * if self.tight_phrases == 0: + * while e_x_low > 0 and e_high - e_x_low < self.train_max_initial_size and e_links_low[e_x_low-1] == -1: # <<<<<<<<<<<<<< + * e_x_low = e_x_low - 1 + * while e_x_high < e_sent_len and e_x_high - e_low < self.train_max_initial_size and e_links_low[e_x_high] == -1: + */ + while (1) { + __pyx_t_2 = (__pyx_v_e_x_low > 0); + if (__pyx_t_2) { + __pyx_t_6 = ((__pyx_v_e_high - __pyx_v_e_x_low) < __pyx_v_self->train_max_initial_size); + if (__pyx_t_6) { + __pyx_t_7 = ((__pyx_v_e_links_low[(__pyx_v_e_x_low - 1)]) == -1); + __pyx_t_8 = __pyx_t_7; + } else { + __pyx_t_8 = __pyx_t_6; + } + __pyx_t_6 = __pyx_t_8; + } else { + __pyx_t_6 = __pyx_t_2; + } + if (!__pyx_t_6) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1307 + * if self.tight_phrases == 0: + * while e_x_low > 0 and e_high - e_x_low < self.train_max_initial_size and e_links_low[e_x_low-1] == -1: + * e_x_low = e_x_low - 1 # <<<<<<<<<<<<<< + * while e_x_high < e_sent_len and e_x_high - e_low < self.train_max_initial_size and e_links_low[e_x_high] == -1: + * e_x_high = e_x_high + 1 + */ + __pyx_v_e_x_low = (__pyx_v_e_x_low - 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1308 + * while e_x_low > 0 and e_high - e_x_low < self.train_max_initial_size and e_links_low[e_x_low-1] == -1: + * e_x_low = e_x_low - 1 + * while e_x_high < e_sent_len and e_x_high - e_low < self.train_max_initial_size and e_links_low[e_x_high] == -1: # <<<<<<<<<<<<<< + * e_x_high = e_x_high + 1 + * + */ + while (1) { + __pyx_t_6 = (__pyx_v_e_x_high < __pyx_v_e_sent_len); + if (__pyx_t_6) { + __pyx_t_2 = ((__pyx_v_e_x_high - __pyx_v_e_low) < __pyx_v_self->train_max_initial_size); + if (__pyx_t_2) { + __pyx_t_8 = ((__pyx_v_e_links_low[__pyx_v_e_x_high]) == -1); + __pyx_t_7 = __pyx_t_8; + } else { + __pyx_t_7 = __pyx_t_2; + } + __pyx_t_2 = __pyx_t_7; + } else { + __pyx_t_2 = __pyx_t_6; + } + if (!__pyx_t_2) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1309 + * e_x_low = e_x_low - 1 + * while e_x_high < e_sent_len and e_x_high - e_low < self.train_max_initial_size and e_links_low[e_x_high] == -1: + * e_x_high = e_x_high + 1 # <<<<<<<<<<<<<< + * + * for i from e_x_low <= i <= e_low: + */ + __pyx_v_e_x_high = (__pyx_v_e_x_high + 1); + } + goto __pyx_L11; + } + __pyx_L11:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1311 + * e_x_high = e_x_high + 1 + * + * for i from e_x_low <= i <= e_low: # <<<<<<<<<<<<<< + * e_gaps1 = self.int_arr_extend(e_gaps1, &len1, &i, 1) + * + */ + __pyx_t_3 = __pyx_v_e_low; + for (__pyx_v_i = __pyx_v_e_x_low; __pyx_v_i <= __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1312 + * + * for i from e_x_low <= i <= e_low: + * e_gaps1 = self.int_arr_extend(e_gaps1, &len1, &i, 1) # <<<<<<<<<<<<<< + * + * for i from 0 <= i < num_gaps: + */ + __pyx_v_e_gaps1 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->int_arr_extend(__pyx_v_self, __pyx_v_e_gaps1, (&__pyx_v_len1), (&__pyx_v_i), 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1314 + * e_gaps1 = self.int_arr_extend(e_gaps1, &len1, &i, 1) + * + * for i from 0 <= i < num_gaps: # <<<<<<<<<<<<<< + * e_gaps2 = malloc(0) + * len2 = 0 + */ + __pyx_t_3 = __pyx_v_num_gaps; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1315 + * + * for i from 0 <= i < num_gaps: + * e_gaps2 = malloc(0) # <<<<<<<<<<<<<< + * len2 = 0 + * + */ + __pyx_v_e_gaps2 = ((int *)malloc(0)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1316 + * for i from 0 <= i < num_gaps: + * e_gaps2 = malloc(0) + * len2 = 0 # <<<<<<<<<<<<<< + * + * j = e_gap_order[i] + */ + __pyx_v_len2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1318 + * len2 = 0 + * + * j = e_gap_order[i] # <<<<<<<<<<<<<< + * e_x_gap_low = e_gap_low[j] + * e_x_gap_high = e_gap_high[j] + */ + __pyx_v_j = (__pyx_v_e_gap_order[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1319 + * + * j = e_gap_order[i] + * e_x_gap_low = e_gap_low[j] # <<<<<<<<<<<<<< + * e_x_gap_high = e_gap_high[j] + * if self.tight_phrases == 0: + */ + __pyx_v_e_x_gap_low = (__pyx_v_e_gap_low[__pyx_v_j]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1320 + * j = e_gap_order[i] + * e_x_gap_low = e_gap_low[j] + * e_x_gap_high = e_gap_high[j] # <<<<<<<<<<<<<< + * if self.tight_phrases == 0: + * while e_x_gap_low > e_x_low and e_links_low[e_x_gap_low-1] == -1: + */ + __pyx_v_e_x_gap_high = (__pyx_v_e_gap_high[__pyx_v_j]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1321 + * e_x_gap_low = e_gap_low[j] + * e_x_gap_high = e_gap_high[j] + * if self.tight_phrases == 0: # <<<<<<<<<<<<<< + * while e_x_gap_low > e_x_low and e_links_low[e_x_gap_low-1] == -1: + * e_x_gap_low = e_x_gap_low - 1 + */ + __pyx_t_2 = (__pyx_v_self->tight_phrases == 0); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1322 + * e_x_gap_high = e_gap_high[j] + * if self.tight_phrases == 0: + * while e_x_gap_low > e_x_low and e_links_low[e_x_gap_low-1] == -1: # <<<<<<<<<<<<<< + * e_x_gap_low = e_x_gap_low - 1 + * while e_x_gap_high < e_x_high and e_links_low[e_x_gap_high] == -1: + */ + while (1) { + __pyx_t_2 = (__pyx_v_e_x_gap_low > __pyx_v_e_x_low); + if (__pyx_t_2) { + __pyx_t_6 = ((__pyx_v_e_links_low[(__pyx_v_e_x_gap_low - 1)]) == -1); + __pyx_t_7 = __pyx_t_6; + } else { + __pyx_t_7 = __pyx_t_2; + } + if (!__pyx_t_7) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1323 + * if self.tight_phrases == 0: + * while e_x_gap_low > e_x_low and e_links_low[e_x_gap_low-1] == -1: + * e_x_gap_low = e_x_gap_low - 1 # <<<<<<<<<<<<<< + * while e_x_gap_high < e_x_high and e_links_low[e_x_gap_high] == -1: + * e_x_gap_high = e_x_gap_high + 1 + */ + __pyx_v_e_x_gap_low = (__pyx_v_e_x_gap_low - 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1324 + * while e_x_gap_low > e_x_low and e_links_low[e_x_gap_low-1] == -1: + * e_x_gap_low = e_x_gap_low - 1 + * while e_x_gap_high < e_x_high and e_links_low[e_x_gap_high] == -1: # <<<<<<<<<<<<<< + * e_x_gap_high = e_x_gap_high + 1 + * + */ + while (1) { + __pyx_t_7 = (__pyx_v_e_x_gap_high < __pyx_v_e_x_high); + if (__pyx_t_7) { + __pyx_t_2 = ((__pyx_v_e_links_low[__pyx_v_e_x_gap_high]) == -1); + __pyx_t_6 = __pyx_t_2; + } else { + __pyx_t_6 = __pyx_t_7; + } + if (!__pyx_t_6) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1325 + * e_x_gap_low = e_x_gap_low - 1 + * while e_x_gap_high < e_x_high and e_links_low[e_x_gap_high] == -1: + * e_x_gap_high = e_x_gap_high + 1 # <<<<<<<<<<<<<< + * + * k = 0 + */ + __pyx_v_e_x_gap_high = (__pyx_v_e_x_gap_high + 1); + } + goto __pyx_L20; + } + __pyx_L20:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1327 + * e_x_gap_high = e_x_gap_high + 1 + * + * k = 0 # <<<<<<<<<<<<<< + * step = 1+(i*2) + * while k < len1: + */ + __pyx_v_k = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1328 + * + * k = 0 + * step = 1+(i*2) # <<<<<<<<<<<<<< + * while k < len1: + * for m from e_x_gap_low <= m <= e_gap_low[j]: + */ + __pyx_v_step = (1 + (__pyx_v_i * 2)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1329 + * k = 0 + * step = 1+(i*2) + * while k < len1: # <<<<<<<<<<<<<< + * for m from e_x_gap_low <= m <= e_gap_low[j]: + * if m >= e_gaps1[k+step-1]: + */ + while (1) { + __pyx_t_6 = (__pyx_v_k < __pyx_v_len1); + if (!__pyx_t_6) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1330 + * step = 1+(i*2) + * while k < len1: + * for m from e_x_gap_low <= m <= e_gap_low[j]: # <<<<<<<<<<<<<< + * if m >= e_gaps1[k+step-1]: + * for n from e_gap_high[j] <= n <= e_x_gap_high: + */ + __pyx_t_4 = (__pyx_v_e_gap_low[__pyx_v_j]); + for (__pyx_v_m = __pyx_v_e_x_gap_low; __pyx_v_m <= __pyx_t_4; __pyx_v_m++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1331 + * while k < len1: + * for m from e_x_gap_low <= m <= e_gap_low[j]: + * if m >= e_gaps1[k+step-1]: # <<<<<<<<<<<<<< + * for n from e_gap_high[j] <= n <= e_x_gap_high: + * if n-m >= 1: # extractor.py doesn't restrict target-side gap length + */ + __pyx_t_6 = (__pyx_v_m >= (__pyx_v_e_gaps1[((__pyx_v_k + __pyx_v_step) - 1)])); + if (__pyx_t_6) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1332 + * for m from e_x_gap_low <= m <= e_gap_low[j]: + * if m >= e_gaps1[k+step-1]: + * for n from e_gap_high[j] <= n <= e_x_gap_high: # <<<<<<<<<<<<<< + * if n-m >= 1: # extractor.py doesn't restrict target-side gap length + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+k, step) + */ + __pyx_t_5 = __pyx_v_e_x_gap_high; + for (__pyx_v_n = (__pyx_v_e_gap_high[__pyx_v_j]); __pyx_v_n <= __pyx_t_5; __pyx_v_n++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1333 + * if m >= e_gaps1[k+step-1]: + * for n from e_gap_high[j] <= n <= e_x_gap_high: + * if n-m >= 1: # extractor.py doesn't restrict target-side gap length # <<<<<<<<<<<<<< + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+k, step) + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &m, 1) + */ + __pyx_t_6 = ((__pyx_v_n - __pyx_v_m) >= 1); + if (__pyx_t_6) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1334 + * for n from e_gap_high[j] <= n <= e_x_gap_high: + * if n-m >= 1: # extractor.py doesn't restrict target-side gap length + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+k, step) # <<<<<<<<<<<<<< + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &m, 1) + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &n, 1) + */ + __pyx_v_e_gaps2 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->int_arr_extend(__pyx_v_self, __pyx_v_e_gaps2, (&__pyx_v_len2), (__pyx_v_e_gaps1 + __pyx_v_k), __pyx_v_step); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1335 + * if n-m >= 1: # extractor.py doesn't restrict target-side gap length + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+k, step) + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &m, 1) # <<<<<<<<<<<<<< + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &n, 1) + * k = k + step + */ + __pyx_v_e_gaps2 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->int_arr_extend(__pyx_v_self, __pyx_v_e_gaps2, (&__pyx_v_len2), (&__pyx_v_m), 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1336 + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+k, step) + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &m, 1) + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &n, 1) # <<<<<<<<<<<<<< + * k = k + step + * free(e_gaps1) + */ + __pyx_v_e_gaps2 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->int_arr_extend(__pyx_v_self, __pyx_v_e_gaps2, (&__pyx_v_len2), (&__pyx_v_n), 1); + goto __pyx_L32; + } + __pyx_L32:; + } + goto __pyx_L29; + } + __pyx_L29:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1337 + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &m, 1) + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &n, 1) + * k = k + step # <<<<<<<<<<<<<< + * free(e_gaps1) + * e_gaps1 = e_gaps2 + */ + __pyx_v_k = (__pyx_v_k + __pyx_v_step); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1338 + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &n, 1) + * k = k + step + * free(e_gaps1) # <<<<<<<<<<<<<< + * e_gaps1 = e_gaps2 + * len1 = len2 + */ + free(__pyx_v_e_gaps1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1339 + * k = k + step + * free(e_gaps1) + * e_gaps1 = e_gaps2 # <<<<<<<<<<<<<< + * len1 = len2 + * + */ + __pyx_v_e_gaps1 = __pyx_v_e_gaps2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1340 + * free(e_gaps1) + * e_gaps1 = e_gaps2 + * len1 = len2 # <<<<<<<<<<<<<< + * + * step = 1+(num_gaps*2) + */ + __pyx_v_len1 = __pyx_v_len2; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1342 + * len1 = len2 + * + * step = 1+(num_gaps*2) # <<<<<<<<<<<<<< + * e_gaps2 = malloc(0) + * len2 = 0 + */ + __pyx_v_step = (1 + (__pyx_v_num_gaps * 2)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1343 + * + * step = 1+(num_gaps*2) + * e_gaps2 = malloc(0) # <<<<<<<<<<<<<< + * len2 = 0 + * for i from e_high <= i <= e_x_high: + */ + __pyx_v_e_gaps2 = ((int *)malloc(0)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1344 + * step = 1+(num_gaps*2) + * e_gaps2 = malloc(0) + * len2 = 0 # <<<<<<<<<<<<<< + * for i from e_high <= i <= e_x_high: + * j = 0 + */ + __pyx_v_len2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1345 + * e_gaps2 = malloc(0) + * len2 = 0 + * for i from e_high <= i <= e_x_high: # <<<<<<<<<<<<<< + * j = 0 + * while j < len1: + */ + __pyx_t_3 = __pyx_v_e_x_high; + for (__pyx_v_i = __pyx_v_e_high; __pyx_v_i <= __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1346 + * len2 = 0 + * for i from e_high <= i <= e_x_high: + * j = 0 # <<<<<<<<<<<<<< + * while j < len1: + * if i - e_gaps1[j] <= self.train_max_initial_size and i >= e_gaps1[j+step-1]: + */ + __pyx_v_j = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1347 + * for i from e_high <= i <= e_x_high: + * j = 0 + * while j < len1: # <<<<<<<<<<<<<< + * if i - e_gaps1[j] <= self.train_max_initial_size and i >= e_gaps1[j+step-1]: + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+j, step) + */ + while (1) { + __pyx_t_6 = (__pyx_v_j < __pyx_v_len1); + if (!__pyx_t_6) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1348 + * j = 0 + * while j < len1: + * if i - e_gaps1[j] <= self.train_max_initial_size and i >= e_gaps1[j+step-1]: # <<<<<<<<<<<<<< + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+j, step) + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &i, 1) + */ + __pyx_t_6 = ((__pyx_v_i - (__pyx_v_e_gaps1[__pyx_v_j])) <= __pyx_v_self->train_max_initial_size); + if (__pyx_t_6) { + __pyx_t_7 = (__pyx_v_i >= (__pyx_v_e_gaps1[((__pyx_v_j + __pyx_v_step) - 1)])); + __pyx_t_2 = __pyx_t_7; + } else { + __pyx_t_2 = __pyx_t_6; + } + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1349 + * while j < len1: + * if i - e_gaps1[j] <= self.train_max_initial_size and i >= e_gaps1[j+step-1]: + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+j, step) # <<<<<<<<<<<<<< + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &i, 1) + * j = j + step + */ + __pyx_v_e_gaps2 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->int_arr_extend(__pyx_v_self, __pyx_v_e_gaps2, (&__pyx_v_len2), (__pyx_v_e_gaps1 + __pyx_v_j), __pyx_v_step); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1350 + * if i - e_gaps1[j] <= self.train_max_initial_size and i >= e_gaps1[j+step-1]: + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+j, step) + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &i, 1) # <<<<<<<<<<<<<< + * j = j + step + * free(e_gaps1) + */ + __pyx_v_e_gaps2 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->int_arr_extend(__pyx_v_self, __pyx_v_e_gaps2, (&__pyx_v_len2), (&__pyx_v_i), 1); + goto __pyx_L37; + } + __pyx_L37:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1351 + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, e_gaps1+j, step) + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &i, 1) + * j = j + step # <<<<<<<<<<<<<< + * free(e_gaps1) + * e_gaps1 = e_gaps2 + */ + __pyx_v_j = (__pyx_v_j + __pyx_v_step); + } + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1352 + * e_gaps2 = self.int_arr_extend(e_gaps2, &len2, &i, 1) + * j = j + step + * free(e_gaps1) # <<<<<<<<<<<<<< + * e_gaps1 = e_gaps2 + * len1 = len2 + */ + free(__pyx_v_e_gaps1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1353 + * j = j + step + * free(e_gaps1) + * e_gaps1 = e_gaps2 # <<<<<<<<<<<<<< + * len1 = len2 + * + */ + __pyx_v_e_gaps1 = __pyx_v_e_gaps2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1354 + * free(e_gaps1) + * e_gaps1 = e_gaps2 + * len1 = len2 # <<<<<<<<<<<<<< + * + * step = (num_gaps+1)*2 + */ + __pyx_v_len1 = __pyx_v_len2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1356 + * len1 = len2 + * + * step = (num_gaps+1)*2 # <<<<<<<<<<<<<< + * i = 0 + * + */ + __pyx_v_step = ((__pyx_v_num_gaps + 1) * 2); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1357 + * + * step = (num_gaps+1)*2 + * i = 0 # <<<<<<<<<<<<<< + * + * while i < len1: + */ + __pyx_v_i = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1359 + * i = 0 + * + * while i < len1: # <<<<<<<<<<<<<< + * ephr_arr._clear() + * num_chunks = 0 + */ + while (1) { + __pyx_t_2 = (__pyx_v_i < __pyx_v_len1); + if (!__pyx_t_2) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1360 + * + * while i < len1: + * ephr_arr._clear() # <<<<<<<<<<<<<< + * num_chunks = 0 + * indexes = [] + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_ephr_arr->__pyx_vtab)->_clear(__pyx_v_ephr_arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1361 + * while i < len1: + * ephr_arr._clear() + * num_chunks = 0 # <<<<<<<<<<<<<< + * indexes = [] + * for j from 0 <= j < num_gaps+1: + */ + __pyx_v_num_chunks = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1362 + * ephr_arr._clear() + * num_chunks = 0 + * indexes = [] # <<<<<<<<<<<<<< + * for j from 0 <= j < num_gaps+1: + * if e_gaps1[i+2*j] < e_gaps1[i+(2*j)+1]: + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF(((PyObject *)__pyx_v_indexes)); + __pyx_v_indexes = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1363 + * num_chunks = 0 + * indexes = [] + * for j from 0 <= j < num_gaps+1: # <<<<<<<<<<<<<< + * if e_gaps1[i+2*j] < e_gaps1[i+(2*j)+1]: + * num_chunks = num_chunks + 1 + */ + __pyx_t_9 = (__pyx_v_num_gaps + 1); + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_9; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1364 + * indexes = [] + * for j from 0 <= j < num_gaps+1: + * if e_gaps1[i+2*j] < e_gaps1[i+(2*j)+1]: # <<<<<<<<<<<<<< + * num_chunks = num_chunks + 1 + * for k from e_gaps1[i+2*j] <= k < e_gaps1[i+(2*j)+1]: + */ + __pyx_t_2 = ((__pyx_v_e_gaps1[(__pyx_v_i + (2 * __pyx_v_j))]) < (__pyx_v_e_gaps1[((__pyx_v_i + (2 * __pyx_v_j)) + 1)])); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1365 + * for j from 0 <= j < num_gaps+1: + * if e_gaps1[i+2*j] < e_gaps1[i+(2*j)+1]: + * num_chunks = num_chunks + 1 # <<<<<<<<<<<<<< + * for k from e_gaps1[i+2*j] <= k < e_gaps1[i+(2*j)+1]: + * indexes.append(k) + */ + __pyx_v_num_chunks = (__pyx_v_num_chunks + 1); + goto __pyx_L42; + } + __pyx_L42:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1366 + * if e_gaps1[i+2*j] < e_gaps1[i+(2*j)+1]: + * num_chunks = num_chunks + 1 + * for k from e_gaps1[i+2*j] <= k < e_gaps1[i+(2*j)+1]: # <<<<<<<<<<<<<< + * indexes.append(k) + * ephr_arr._append(self.eid2symid[self.eda.data.arr[e_sent_start+k]]) + */ + __pyx_t_3 = (__pyx_v_e_gaps1[((__pyx_v_i + (2 * __pyx_v_j)) + 1)]); + for (__pyx_v_k = (__pyx_v_e_gaps1[(__pyx_v_i + (2 * __pyx_v_j))]); __pyx_v_k < __pyx_t_3; __pyx_v_k++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1367 + * num_chunks = num_chunks + 1 + * for k from e_gaps1[i+2*j] <= k < e_gaps1[i+(2*j)+1]: + * indexes.append(k) # <<<<<<<<<<<<<< + * ephr_arr._append(self.eid2symid[self.eda.data.arr[e_sent_start+k]]) + * if j < num_gaps: + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_k); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1367; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = PyList_Append(__pyx_v_indexes, __pyx_t_1); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1367; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1368 + * for k from e_gaps1[i+2*j] <= k < e_gaps1[i+(2*j)+1]: + * indexes.append(k) + * ephr_arr._append(self.eid2symid[self.eda.data.arr[e_sent_start+k]]) # <<<<<<<<<<<<<< + * if j < num_gaps: + * indexes.append(sym_setindex(self.category, e_gap_order[j]+1)) + */ + __pyx_t_4 = (__pyx_v_self->eda->data->arr[(__pyx_v_e_sent_start + __pyx_v_k)]); + __pyx_t_1 = __Pyx_GetItemInt(((PyObject *)__pyx_v_self->eid2symid), __pyx_t_4, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_ephr_arr->__pyx_vtab)->_append(__pyx_v_ephr_arr, __pyx_t_4); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1369 + * indexes.append(k) + * ephr_arr._append(self.eid2symid[self.eda.data.arr[e_sent_start+k]]) + * if j < num_gaps: # <<<<<<<<<<<<<< + * indexes.append(sym_setindex(self.category, e_gap_order[j]+1)) + * ephr_arr._append(sym_setindex(self.category, e_gap_order[j]+1)) + */ + __pyx_t_2 = (__pyx_v_j < __pyx_v_num_gaps); + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1370 + * ephr_arr._append(self.eid2symid[self.eda.data.arr[e_sent_start+k]]) + * if j < num_gaps: + * indexes.append(sym_setindex(self.category, e_gap_order[j]+1)) # <<<<<<<<<<<<<< + * ephr_arr._append(sym_setindex(self.category, e_gap_order[j]+1)) + * i = i + step + */ + __pyx_t_1 = PyInt_FromLong(__pyx_f_3_sa_sym_setindex(__pyx_v_self->category, ((__pyx_v_e_gap_order[__pyx_v_j]) + 1))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1370; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = PyList_Append(__pyx_v_indexes, __pyx_t_1); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1370; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1371 + * if j < num_gaps: + * indexes.append(sym_setindex(self.category, e_gap_order[j]+1)) + * ephr_arr._append(sym_setindex(self.category, e_gap_order[j]+1)) # <<<<<<<<<<<<<< + * i = i + step + * if ephr_arr.len <= self.max_target_length and num_chunks <= self.max_target_chunks: + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_ephr_arr->__pyx_vtab)->_append(__pyx_v_ephr_arr, __pyx_f_3_sa_sym_setindex(__pyx_v_self->category, ((__pyx_v_e_gap_order[__pyx_v_j]) + 1))); + goto __pyx_L45; + } + __pyx_L45:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1372 + * indexes.append(sym_setindex(self.category, e_gap_order[j]+1)) + * ephr_arr._append(sym_setindex(self.category, e_gap_order[j]+1)) + * i = i + step # <<<<<<<<<<<<<< + * if ephr_arr.len <= self.max_target_length and num_chunks <= self.max_target_chunks: + * result.append((Phrase(ephr_arr),indexes)) + */ + __pyx_v_i = (__pyx_v_i + __pyx_v_step); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1373 + * ephr_arr._append(sym_setindex(self.category, e_gap_order[j]+1)) + * i = i + step + * if ephr_arr.len <= self.max_target_length and num_chunks <= self.max_target_chunks: # <<<<<<<<<<<<<< + * result.append((Phrase(ephr_arr),indexes)) + * + */ + __pyx_t_2 = (__pyx_v_ephr_arr->len <= __pyx_v_self->max_target_length); + if (__pyx_t_2) { + __pyx_t_6 = (__pyx_v_num_chunks <= __pyx_v_self->max_target_chunks); + __pyx_t_7 = __pyx_t_6; + } else { + __pyx_t_7 = __pyx_t_2; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1374 + * i = i + step + * if ephr_arr.len <= self.max_target_length and num_chunks <= self.max_target_chunks: + * result.append((Phrase(ephr_arr),indexes)) # <<<<<<<<<<<<<< + * + * free(e_gaps1) + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1374; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_ephr_arr)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_ephr_arr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_ephr_arr)); + __pyx_t_11 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_Phrase)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1374; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1374; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_11); + __Pyx_GIVEREF(__pyx_t_11); + __Pyx_INCREF(((PyObject *)__pyx_v_indexes)); + PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_indexes)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_indexes)); + __pyx_t_11 = 0; + __pyx_t_11 = __Pyx_PyObject_Append(__pyx_v_result, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1374; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L46; + } + __pyx_L46:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1376 + * result.append((Phrase(ephr_arr),indexes)) + * + * free(e_gaps1) # <<<<<<<<<<<<<< + * free(e_gap_order) + * return result + */ + free(__pyx_v_e_gaps1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1377 + * + * free(e_gaps1) + * free(e_gap_order) # <<<<<<<<<<<<<< + * return result + * + */ + free(__pyx_v_e_gap_order); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1378 + * free(e_gaps1) + * free(e_gap_order) + * return result # <<<<<<<<<<<<<< + * + * cdef create_alignments(self, int* sent_links, int num_links, findexes, eindexes): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + 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_11); + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.extract_phrases", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_ephr_arr); + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_indexes); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1380 + * return result + * + * cdef create_alignments(self, int* sent_links, int num_links, findexes, eindexes): # <<<<<<<<<<<<<< + * cdef unsigned i + * ret = IntList() + */ + +static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_create_alignments(CYTHON_UNUSED struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, int *__pyx_v_sent_links, int __pyx_v_num_links, PyObject *__pyx_v_findexes, PyObject *__pyx_v_eindexes) { + unsigned int __pyx_v_i; + struct __pyx_obj_3_sa_IntList *__pyx_v_ret = NULL; + PyObject *__pyx_v_s = NULL; + PyObject *__pyx_v_idx = NULL; + PyObject *__pyx_v_j = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + unsigned int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + Py_ssize_t __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("create_alignments", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1382 + * cdef create_alignments(self, int* sent_links, int num_links, findexes, eindexes): + * cdef unsigned i + * ret = IntList() # <<<<<<<<<<<<<< + * for i in range(len(findexes)): + * s = findexes[i] + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1382; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_ret = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1383 + * cdef unsigned i + * ret = IntList() + * for i in range(len(findexes)): # <<<<<<<<<<<<<< + * s = findexes[i] + * if (s<0): + */ + __pyx_t_2 = PyObject_Length(__pyx_v_findexes); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_v_i = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1384 + * ret = IntList() + * for i in range(len(findexes)): + * s = findexes[i] # <<<<<<<<<<<<<< + * if (s<0): + * continue + */ + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_findexes, __pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1384; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_s); + __pyx_v_s = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1385 + * for i in range(len(findexes)): + * s = findexes[i] + * if (s<0): # <<<<<<<<<<<<<< + * continue + * idx = 0 + */ + __pyx_t_1 = PyObject_RichCompare(__pyx_v_s, __pyx_int_0, Py_LT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1385; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1385; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1386 + * s = findexes[i] + * if (s<0): + * continue # <<<<<<<<<<<<<< + * idx = 0 + * while (idx < num_links*2): + */ + goto __pyx_L3_continue; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1387 + * if (s<0): + * continue + * idx = 0 # <<<<<<<<<<<<<< + * while (idx < num_links*2): + * if (sent_links[idx] == s): + */ + __Pyx_INCREF(__pyx_int_0); + __Pyx_XDECREF(__pyx_v_idx); + __pyx_v_idx = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1388 + * continue + * idx = 0 + * while (idx < num_links*2): # <<<<<<<<<<<<<< + * if (sent_links[idx] == s): + * j = eindexes.index(sent_links[idx+1]) + */ + while (1) { + __pyx_t_1 = PyInt_FromLong((__pyx_v_num_links * 2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1388; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyObject_RichCompare(__pyx_v_idx, __pyx_t_1, Py_LT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1388; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1388; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (!__pyx_t_4) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1389 + * idx = 0 + * while (idx < num_links*2): + * if (sent_links[idx] == s): # <<<<<<<<<<<<<< + * j = eindexes.index(sent_links[idx+1]) + * ret.append(i*65536+j) + */ + __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_idx); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyInt_FromLong((__pyx_v_sent_links[__pyx_t_6])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyObject_RichCompare(__pyx_t_5, __pyx_v_s, Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1389; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1390 + * while (idx < num_links*2): + * if (sent_links[idx] == s): + * j = eindexes.index(sent_links[idx+1]) # <<<<<<<<<<<<<< + * ret.append(i*65536+j) + * idx += 2 + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_eindexes, __pyx_n_s__index); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_5 = PyNumber_Add(__pyx_v_idx, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_t_5); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyInt_FromLong((__pyx_v_sent_links[__pyx_t_6])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_5 = 0; + __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1390; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_v_j); + __pyx_v_j = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1391 + * if (sent_links[idx] == s): + * j = eindexes.index(sent_links[idx+1]) + * ret.append(i*65536+j) # <<<<<<<<<<<<<< + * idx += 2 + * return ret + */ + __pyx_t_5 = PyInt_FromLong((__pyx_v_i * 65536)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = PyNumber_Add(__pyx_t_5, __pyx_v_j); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_ret), __pyx_t_7); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L8; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1392 + * j = eindexes.index(sent_links[idx+1]) + * ret.append(i*65536+j) + * idx += 2 # <<<<<<<<<<<<<< + * return ret + * + */ + __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_v_idx, __pyx_int_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1392; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_v_idx); + __pyx_v_idx = __pyx_t_5; + __pyx_t_5 = 0; + } + __pyx_L3_continue:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1393 + * ret.append(i*65536+j) + * idx += 2 + * return ret # <<<<<<<<<<<<<< + * + * cdef extract(self, Phrase phrase, Matching* matching, int* chunklen, int num_chunks): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_ret)); + __pyx_r = ((PyObject *)__pyx_v_ret); + 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_5); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.create_alignments", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_ret); + __Pyx_XDECREF(__pyx_v_s); + __Pyx_XDECREF(__pyx_v_idx); + __Pyx_XDECREF(__pyx_v_j); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1395 + * return ret + * + * cdef extract(self, Phrase phrase, Matching* matching, int* chunklen, int num_chunks): # <<<<<<<<<<<<<< + * cdef int* sent_links, *e_links_low, *e_links_high, *f_links_low, *f_links_high + * cdef int *f_gap_low, *f_gap_high, *e_gap_low, *e_gap_high, num_gaps, gap_start + */ + +static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_extract(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, struct __pyx_obj_3_sa_Phrase *__pyx_v_phrase, struct __pyx_t_3_sa_Matching *__pyx_v_matching, int *__pyx_v_chunklen, int __pyx_v_num_chunks) { + int *__pyx_v_sent_links; + int *__pyx_v_e_links_low; + int *__pyx_v_e_links_high; + int *__pyx_v_f_links_low; + int *__pyx_v_f_links_high; + int *__pyx_v_f_gap_low; + int *__pyx_v_f_gap_high; + int *__pyx_v_e_gap_low; + int *__pyx_v_e_gap_high; + int __pyx_v_num_gaps; + int __pyx_v_gap_start; + int __pyx_v_i; + int __pyx_v_j; + int __pyx_v_e_i; + int __pyx_v_f_i; + int __pyx_v_num_links; + int __pyx_v_num_aligned_chunks; + int __pyx_v_met_constraints; + int __pyx_v_x; + int __pyx_v_f_low; + int __pyx_v_f_high; + int __pyx_v_e_low; + int __pyx_v_e_high; + int __pyx_v_f_back_low; + int __pyx_v_f_back_high; + int __pyx_v_e_sent_start; + int __pyx_v_e_sent_end; + int __pyx_v_f_sent_start; + int __pyx_v_f_sent_end; + int __pyx_v_e_sent_len; + int __pyx_v_f_sent_len; + CYTHON_UNUSED int __pyx_v_e_word_count; + int __pyx_v_f_x_low; + int __pyx_v_f_x_high; + int __pyx_v_e_x_low; + int __pyx_v_e_x_high; + int __pyx_v_phrase_len; + float __pyx_v_pair_count; + PyObject *__pyx_v_extracts = 0; + PyObject *__pyx_v_phrase_list = 0; + struct __pyx_obj_3_sa_IntList *__pyx_v_fphr_arr = 0; + struct __pyx_obj_3_sa_Phrase *__pyx_v_fphr = 0; + CYTHON_UNUSED PyObject *__pyx_v_reason_for_failure = 0; + PyObject *__pyx_v_sofar = NULL; + PyObject *__pyx_v_als = NULL; + PyObject *__pyx_v_al = NULL; + long __pyx_v_gap_error; + PyObject *__pyx_v_phrase2 = NULL; + PyObject *__pyx_v_eindexes = NULL; + PyObject *__pyx_v_als1 = NULL; + PyObject *__pyx_v_als2 = NULL; + PyObject *__pyx_v_als3 = NULL; + PyObject *__pyx_v_als4 = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_t_5; + int __pyx_t_6; + int __pyx_t_7; + int __pyx_t_8; + int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + long __pyx_t_12; + Py_ssize_t __pyx_t_13; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + PyObject *(*__pyx_t_16)(PyObject *); + PyObject *(*__pyx_t_17)(PyObject *); + int __pyx_t_18; + int __pyx_t_19; + int __pyx_t_20; + int __pyx_t_21; + int __pyx_t_22; + int __pyx_t_23; + int __pyx_t_24; + int __pyx_t_25; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("extract", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1408 + * cdef reason_for_failure + * + * fphr_arr = IntList() # <<<<<<<<<<<<<< + * phrase_len = phrase.n + * extracts = [] + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1408; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_fphr_arr = ((struct __pyx_obj_3_sa_IntList *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1409 + * + * fphr_arr = IntList() + * phrase_len = phrase.n # <<<<<<<<<<<<<< + * extracts = [] + * sent_links = self.alignment._get_sent_links(matching.sent_id, &num_links) + */ + __pyx_v_phrase_len = __pyx_v_phrase->n; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1410 + * fphr_arr = IntList() + * phrase_len = phrase.n + * extracts = [] # <<<<<<<<<<<<<< + * sent_links = self.alignment._get_sent_links(matching.sent_id, &num_links) + * + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_extracts = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1411 + * phrase_len = phrase.n + * extracts = [] + * sent_links = self.alignment._get_sent_links(matching.sent_id, &num_links) # <<<<<<<<<<<<<< + * + * e_sent_start = self.eda.sent_index.arr[matching.sent_id] + */ + __pyx_v_sent_links = ((struct __pyx_vtabstruct_3_sa_Alignment *)__pyx_v_self->alignment->__pyx_vtab)->_get_sent_links(__pyx_v_self->alignment, __pyx_v_matching->sent_id, (&__pyx_v_num_links)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1413 + * sent_links = self.alignment._get_sent_links(matching.sent_id, &num_links) + * + * e_sent_start = self.eda.sent_index.arr[matching.sent_id] # <<<<<<<<<<<<<< + * e_sent_end = self.eda.sent_index.arr[matching.sent_id+1] + * e_sent_len = e_sent_end - e_sent_start - 1 + */ + __pyx_v_e_sent_start = (__pyx_v_self->eda->sent_index->arr[__pyx_v_matching->sent_id]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1414 + * + * e_sent_start = self.eda.sent_index.arr[matching.sent_id] + * e_sent_end = self.eda.sent_index.arr[matching.sent_id+1] # <<<<<<<<<<<<<< + * e_sent_len = e_sent_end - e_sent_start - 1 + * f_sent_start = self.fda.sent_index.arr[matching.sent_id] + */ + __pyx_v_e_sent_end = (__pyx_v_self->eda->sent_index->arr[(__pyx_v_matching->sent_id + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1415 + * e_sent_start = self.eda.sent_index.arr[matching.sent_id] + * e_sent_end = self.eda.sent_index.arr[matching.sent_id+1] + * e_sent_len = e_sent_end - e_sent_start - 1 # <<<<<<<<<<<<<< + * f_sent_start = self.fda.sent_index.arr[matching.sent_id] + * f_sent_end = self.fda.sent_index.arr[matching.sent_id+1] + */ + __pyx_v_e_sent_len = ((__pyx_v_e_sent_end - __pyx_v_e_sent_start) - 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1416 + * e_sent_end = self.eda.sent_index.arr[matching.sent_id+1] + * e_sent_len = e_sent_end - e_sent_start - 1 + * f_sent_start = self.fda.sent_index.arr[matching.sent_id] # <<<<<<<<<<<<<< + * f_sent_end = self.fda.sent_index.arr[matching.sent_id+1] + * f_sent_len = f_sent_end - f_sent_start - 1 + */ + __pyx_v_f_sent_start = (__pyx_v_self->fda->sent_index->arr[__pyx_v_matching->sent_id]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1417 + * e_sent_len = e_sent_end - e_sent_start - 1 + * f_sent_start = self.fda.sent_index.arr[matching.sent_id] + * f_sent_end = self.fda.sent_index.arr[matching.sent_id+1] # <<<<<<<<<<<<<< + * f_sent_len = f_sent_end - f_sent_start - 1 + * + */ + __pyx_v_f_sent_end = (__pyx_v_self->fda->sent_index->arr[(__pyx_v_matching->sent_id + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1418 + * f_sent_start = self.fda.sent_index.arr[matching.sent_id] + * f_sent_end = self.fda.sent_index.arr[matching.sent_id+1] + * f_sent_len = f_sent_end - f_sent_start - 1 # <<<<<<<<<<<<<< + * + * self.findexes1.reset() + */ + __pyx_v_f_sent_len = ((__pyx_v_f_sent_end - __pyx_v_f_sent_start) - 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1420 + * f_sent_len = f_sent_end - f_sent_start - 1 + * + * self.findexes1.reset() # <<<<<<<<<<<<<< + * sofar = 0 + * for i in range(num_chunks): + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes1), __pyx_n_s__reset); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1420; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1420; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1421 + * + * self.findexes1.reset() + * sofar = 0 # <<<<<<<<<<<<<< + * for i in range(num_chunks): + * for j in range(chunklen[i]): + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_v_sofar = __pyx_int_0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1422 + * self.findexes1.reset() + * sofar = 0 + * for i in range(num_chunks): # <<<<<<<<<<<<<< + * for j in range(chunklen[i]): + * self.findexes1.append(matching.arr[matching.start+i]+j-f_sent_start); + */ + __pyx_t_3 = __pyx_v_num_chunks; + for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_i = __pyx_t_4; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1423 + * sofar = 0 + * for i in range(num_chunks): + * for j in range(chunklen[i]): # <<<<<<<<<<<<<< + * self.findexes1.append(matching.arr[matching.start+i]+j-f_sent_start); + * sofar += 1 + */ + __pyx_t_5 = (__pyx_v_chunklen[__pyx_v_i]); + for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { + __pyx_v_j = __pyx_t_6; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1424 + * for i in range(num_chunks): + * for j in range(chunklen[i]): + * self.findexes1.append(matching.arr[matching.start+i]+j-f_sent_start); # <<<<<<<<<<<<<< + * sofar += 1 + * if (i+1arr[(__pyx_v_matching->start + __pyx_v_i)]) + __pyx_v_j) - __pyx_v_f_sent_start)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1424; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes1), __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1424; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1425 + * for j in range(chunklen[i]): + * self.findexes1.append(matching.arr[matching.start+i]+j-f_sent_start); + * sofar += 1 # <<<<<<<<<<<<<< + * if (i+1findexes1), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1427; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1428 + * if (i+1 malloc(e_sent_len*sizeof(int)) # <<<<<<<<<<<<<< + * e_links_high = malloc(e_sent_len*sizeof(int)) + * f_links_low = malloc(f_sent_len*sizeof(int)) + */ + __pyx_v_e_links_low = ((int *)malloc((__pyx_v_e_sent_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1432 + * + * e_links_low = malloc(e_sent_len*sizeof(int)) + * e_links_high = malloc(e_sent_len*sizeof(int)) # <<<<<<<<<<<<<< + * f_links_low = malloc(f_sent_len*sizeof(int)) + * f_links_high = malloc(f_sent_len*sizeof(int)) + */ + __pyx_v_e_links_high = ((int *)malloc((__pyx_v_e_sent_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1433 + * e_links_low = malloc(e_sent_len*sizeof(int)) + * e_links_high = malloc(e_sent_len*sizeof(int)) + * f_links_low = malloc(f_sent_len*sizeof(int)) # <<<<<<<<<<<<<< + * f_links_high = malloc(f_sent_len*sizeof(int)) + * f_gap_low = malloc((num_chunks+1)*sizeof(int)) + */ + __pyx_v_f_links_low = ((int *)malloc((__pyx_v_f_sent_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1434 + * e_links_high = malloc(e_sent_len*sizeof(int)) + * f_links_low = malloc(f_sent_len*sizeof(int)) + * f_links_high = malloc(f_sent_len*sizeof(int)) # <<<<<<<<<<<<<< + * f_gap_low = malloc((num_chunks+1)*sizeof(int)) + * f_gap_high = malloc((num_chunks+1)*sizeof(int)) + */ + __pyx_v_f_links_high = ((int *)malloc((__pyx_v_f_sent_len * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1435 + * f_links_low = malloc(f_sent_len*sizeof(int)) + * f_links_high = malloc(f_sent_len*sizeof(int)) + * f_gap_low = malloc((num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< + * f_gap_high = malloc((num_chunks+1)*sizeof(int)) + * e_gap_low = malloc((num_chunks+1)*sizeof(int)) + */ + __pyx_v_f_gap_low = ((int *)malloc(((__pyx_v_num_chunks + 1) * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1436 + * f_links_high = malloc(f_sent_len*sizeof(int)) + * f_gap_low = malloc((num_chunks+1)*sizeof(int)) + * f_gap_high = malloc((num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< + * e_gap_low = malloc((num_chunks+1)*sizeof(int)) + * e_gap_high = malloc((num_chunks+1)*sizeof(int)) + */ + __pyx_v_f_gap_high = ((int *)malloc(((__pyx_v_num_chunks + 1) * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1437 + * f_gap_low = malloc((num_chunks+1)*sizeof(int)) + * f_gap_high = malloc((num_chunks+1)*sizeof(int)) + * e_gap_low = malloc((num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< + * e_gap_high = malloc((num_chunks+1)*sizeof(int)) + * memset(f_gap_low, 0, (num_chunks+1)*sizeof(int)) + */ + __pyx_v_e_gap_low = ((int *)malloc(((__pyx_v_num_chunks + 1) * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1438 + * f_gap_high = malloc((num_chunks+1)*sizeof(int)) + * e_gap_low = malloc((num_chunks+1)*sizeof(int)) + * e_gap_high = malloc((num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< + * memset(f_gap_low, 0, (num_chunks+1)*sizeof(int)) + * memset(f_gap_high, 0, (num_chunks+1)*sizeof(int)) + */ + __pyx_v_e_gap_high = ((int *)malloc(((__pyx_v_num_chunks + 1) * (sizeof(int))))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1439 + * e_gap_low = malloc((num_chunks+1)*sizeof(int)) + * e_gap_high = malloc((num_chunks+1)*sizeof(int)) + * memset(f_gap_low, 0, (num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< + * memset(f_gap_high, 0, (num_chunks+1)*sizeof(int)) + * memset(e_gap_low, 0, (num_chunks+1)*sizeof(int)) + */ + memset(__pyx_v_f_gap_low, 0, ((__pyx_v_num_chunks + 1) * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1440 + * e_gap_high = malloc((num_chunks+1)*sizeof(int)) + * memset(f_gap_low, 0, (num_chunks+1)*sizeof(int)) + * memset(f_gap_high, 0, (num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< + * memset(e_gap_low, 0, (num_chunks+1)*sizeof(int)) + * memset(e_gap_high, 0, (num_chunks+1)*sizeof(int)) + */ + memset(__pyx_v_f_gap_high, 0, ((__pyx_v_num_chunks + 1) * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1441 + * memset(f_gap_low, 0, (num_chunks+1)*sizeof(int)) + * memset(f_gap_high, 0, (num_chunks+1)*sizeof(int)) + * memset(e_gap_low, 0, (num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< + * memset(e_gap_high, 0, (num_chunks+1)*sizeof(int)) + * + */ + memset(__pyx_v_e_gap_low, 0, ((__pyx_v_num_chunks + 1) * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1442 + * memset(f_gap_high, 0, (num_chunks+1)*sizeof(int)) + * memset(e_gap_low, 0, (num_chunks+1)*sizeof(int)) + * memset(e_gap_high, 0, (num_chunks+1)*sizeof(int)) # <<<<<<<<<<<<<< + * + * reason_for_failure = "" + */ + memset(__pyx_v_e_gap_high, 0, ((__pyx_v_num_chunks + 1) * (sizeof(int)))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1444 + * memset(e_gap_high, 0, (num_chunks+1)*sizeof(int)) + * + * reason_for_failure = "" # <<<<<<<<<<<<<< + * + * for i from 0 <= i < e_sent_len: + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_42)); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_42); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1446 + * reason_for_failure = "" + * + * for i from 0 <= i < e_sent_len: # <<<<<<<<<<<<<< + * e_links_low[i] = -1 + * e_links_high[i] = -1 + */ + __pyx_t_3 = __pyx_v_e_sent_len; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1447 + * + * for i from 0 <= i < e_sent_len: + * e_links_low[i] = -1 # <<<<<<<<<<<<<< + * e_links_high[i] = -1 + * for i from 0 <= i < f_sent_len: + */ + (__pyx_v_e_links_low[__pyx_v_i]) = -1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1448 + * for i from 0 <= i < e_sent_len: + * e_links_low[i] = -1 + * e_links_high[i] = -1 # <<<<<<<<<<<<<< + * for i from 0 <= i < f_sent_len: + * f_links_low[i] = -1 + */ + (__pyx_v_e_links_high[__pyx_v_i]) = -1; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1449 + * e_links_low[i] = -1 + * e_links_high[i] = -1 + * for i from 0 <= i < f_sent_len: # <<<<<<<<<<<<<< + * f_links_low[i] = -1 + * f_links_high[i] = -1 + */ + __pyx_t_3 = __pyx_v_f_sent_len; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1450 + * e_links_high[i] = -1 + * for i from 0 <= i < f_sent_len: + * f_links_low[i] = -1 # <<<<<<<<<<<<<< + * f_links_high[i] = -1 + * + */ + (__pyx_v_f_links_low[__pyx_v_i]) = -1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1451 + * for i from 0 <= i < f_sent_len: + * f_links_low[i] = -1 + * f_links_high[i] = -1 # <<<<<<<<<<<<<< + * + * # this is really inefficient -- might be good to + */ + (__pyx_v_f_links_high[__pyx_v_i]) = -1; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1457 + * # links that we care about (but then how to look up + * # when we want to check something on the e side?) + * i = 0 # <<<<<<<<<<<<<< + * while i < num_links*2: + * f_i = sent_links[i] + */ + __pyx_v_i = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1458 + * # when we want to check something on the e side?) + * i = 0 + * while i < num_links*2: # <<<<<<<<<<<<<< + * f_i = sent_links[i] + * e_i = sent_links[i+1] + */ + while (1) { + __pyx_t_7 = (__pyx_v_i < (__pyx_v_num_links * 2)); + if (!__pyx_t_7) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1459 + * i = 0 + * while i < num_links*2: + * f_i = sent_links[i] # <<<<<<<<<<<<<< + * e_i = sent_links[i+1] + * if f_links_low[f_i] == -1 or f_links_low[f_i] > e_i: + */ + __pyx_v_f_i = (__pyx_v_sent_links[__pyx_v_i]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1460 + * while i < num_links*2: + * f_i = sent_links[i] + * e_i = sent_links[i+1] # <<<<<<<<<<<<<< + * if f_links_low[f_i] == -1 or f_links_low[f_i] > e_i: + * f_links_low[f_i] = e_i + */ + __pyx_v_e_i = (__pyx_v_sent_links[(__pyx_v_i + 1)]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1461 + * f_i = sent_links[i] + * e_i = sent_links[i+1] + * if f_links_low[f_i] == -1 or f_links_low[f_i] > e_i: # <<<<<<<<<<<<<< + * f_links_low[f_i] = e_i + * if f_links_high[f_i] == -1 or f_links_high[f_i] < e_i + 1: + */ + __pyx_t_7 = ((__pyx_v_f_links_low[__pyx_v_f_i]) == -1); + if (!__pyx_t_7) { + __pyx_t_8 = ((__pyx_v_f_links_low[__pyx_v_f_i]) > __pyx_v_e_i); + __pyx_t_9 = __pyx_t_8; + } else { + __pyx_t_9 = __pyx_t_7; + } + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1462 + * e_i = sent_links[i+1] + * if f_links_low[f_i] == -1 or f_links_low[f_i] > e_i: + * f_links_low[f_i] = e_i # <<<<<<<<<<<<<< + * if f_links_high[f_i] == -1 or f_links_high[f_i] < e_i + 1: + * f_links_high[f_i] = e_i + 1 + */ + (__pyx_v_f_links_low[__pyx_v_f_i]) = __pyx_v_e_i; + goto __pyx_L14; + } + __pyx_L14:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1463 + * if f_links_low[f_i] == -1 or f_links_low[f_i] > e_i: + * f_links_low[f_i] = e_i + * if f_links_high[f_i] == -1 or f_links_high[f_i] < e_i + 1: # <<<<<<<<<<<<<< + * f_links_high[f_i] = e_i + 1 + * if e_links_low[e_i] == -1 or e_links_low[e_i] > f_i: + */ + __pyx_t_9 = ((__pyx_v_f_links_high[__pyx_v_f_i]) == -1); + if (!__pyx_t_9) { + __pyx_t_7 = ((__pyx_v_f_links_high[__pyx_v_f_i]) < (__pyx_v_e_i + 1)); + __pyx_t_8 = __pyx_t_7; + } else { + __pyx_t_8 = __pyx_t_9; + } + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1464 + * f_links_low[f_i] = e_i + * if f_links_high[f_i] == -1 or f_links_high[f_i] < e_i + 1: + * f_links_high[f_i] = e_i + 1 # <<<<<<<<<<<<<< + * if e_links_low[e_i] == -1 or e_links_low[e_i] > f_i: + * e_links_low[e_i] = f_i + */ + (__pyx_v_f_links_high[__pyx_v_f_i]) = (__pyx_v_e_i + 1); + goto __pyx_L15; + } + __pyx_L15:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1465 + * if f_links_high[f_i] == -1 or f_links_high[f_i] < e_i + 1: + * f_links_high[f_i] = e_i + 1 + * if e_links_low[e_i] == -1 or e_links_low[e_i] > f_i: # <<<<<<<<<<<<<< + * e_links_low[e_i] = f_i + * if e_links_high[e_i] == -1 or e_links_high[e_i] < f_i + 1: + */ + __pyx_t_8 = ((__pyx_v_e_links_low[__pyx_v_e_i]) == -1); + if (!__pyx_t_8) { + __pyx_t_9 = ((__pyx_v_e_links_low[__pyx_v_e_i]) > __pyx_v_f_i); + __pyx_t_7 = __pyx_t_9; + } else { + __pyx_t_7 = __pyx_t_8; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1466 + * f_links_high[f_i] = e_i + 1 + * if e_links_low[e_i] == -1 or e_links_low[e_i] > f_i: + * e_links_low[e_i] = f_i # <<<<<<<<<<<<<< + * if e_links_high[e_i] == -1 or e_links_high[e_i] < f_i + 1: + * e_links_high[e_i] = f_i + 1 + */ + (__pyx_v_e_links_low[__pyx_v_e_i]) = __pyx_v_f_i; + goto __pyx_L16; + } + __pyx_L16:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1467 + * if e_links_low[e_i] == -1 or e_links_low[e_i] > f_i: + * e_links_low[e_i] = f_i + * if e_links_high[e_i] == -1 or e_links_high[e_i] < f_i + 1: # <<<<<<<<<<<<<< + * e_links_high[e_i] = f_i + 1 + * i = i + 2 + */ + __pyx_t_7 = ((__pyx_v_e_links_high[__pyx_v_e_i]) == -1); + if (!__pyx_t_7) { + __pyx_t_8 = ((__pyx_v_e_links_high[__pyx_v_e_i]) < (__pyx_v_f_i + 1)); + __pyx_t_9 = __pyx_t_8; + } else { + __pyx_t_9 = __pyx_t_7; + } + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1468 + * e_links_low[e_i] = f_i + * if e_links_high[e_i] == -1 or e_links_high[e_i] < f_i + 1: + * e_links_high[e_i] = f_i + 1 # <<<<<<<<<<<<<< + * i = i + 2 + * + */ + (__pyx_v_e_links_high[__pyx_v_e_i]) = (__pyx_v_f_i + 1); + goto __pyx_L17; + } + __pyx_L17:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1469 + * if e_links_high[e_i] == -1 or e_links_high[e_i] < f_i + 1: + * e_links_high[e_i] = f_i + 1 + * i = i + 2 # <<<<<<<<<<<<<< + * + * als = [] + */ + __pyx_v_i = (__pyx_v_i + 2); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1471 + * i = i + 2 + * + * als = [] # <<<<<<<<<<<<<< + * for x in range(matching.start,matching.end): + * al = (matching.arr[x]-f_sent_start,f_links_low[matching.arr[x]-f_sent_start]) + */ + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1471; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_v_als = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1472 + * + * als = [] + * for x in range(matching.start,matching.end): # <<<<<<<<<<<<<< + * al = (matching.arr[x]-f_sent_start,f_links_low[matching.arr[x]-f_sent_start]) + * als.append(al) + */ + __pyx_t_3 = __pyx_v_matching->end; + for (__pyx_t_4 = __pyx_v_matching->start; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) { + __pyx_v_x = __pyx_t_4; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1473 + * als = [] + * for x in range(matching.start,matching.end): + * al = (matching.arr[x]-f_sent_start,f_links_low[matching.arr[x]-f_sent_start]) # <<<<<<<<<<<<<< + * als.append(al) + * # check all source-side alignment constraints + */ + __pyx_t_2 = PyInt_FromLong(((__pyx_v_matching->arr[__pyx_v_x]) - __pyx_v_f_sent_start)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1473; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyInt_FromLong((__pyx_v_f_links_low[((__pyx_v_matching->arr[__pyx_v_x]) - __pyx_v_f_sent_start)])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1473; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1473; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __Pyx_XDECREF(((PyObject *)__pyx_v_al)); + __pyx_v_al = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1474 + * for x in range(matching.start,matching.end): + * al = (matching.arr[x]-f_sent_start,f_links_low[matching.arr[x]-f_sent_start]) + * als.append(al) # <<<<<<<<<<<<<< + * # check all source-side alignment constraints + * met_constraints = 1 + */ + __pyx_t_11 = PyList_Append(__pyx_v_als, ((PyObject *)__pyx_v_al)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1474; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1476 + * als.append(al) + * # check all source-side alignment constraints + * met_constraints = 1 # <<<<<<<<<<<<<< + * if self.require_aligned_terminal: + * num_aligned_chunks = 0 + */ + __pyx_v_met_constraints = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1477 + * # check all source-side alignment constraints + * met_constraints = 1 + * if self.require_aligned_terminal: # <<<<<<<<<<<<<< + * num_aligned_chunks = 0 + * for i from 0 <= i < num_chunks: + */ + if (__pyx_v_self->require_aligned_terminal) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1478 + * met_constraints = 1 + * if self.require_aligned_terminal: + * num_aligned_chunks = 0 # <<<<<<<<<<<<<< + * for i from 0 <= i < num_chunks: + * for j from 0 <= j < chunklen[i]: + */ + __pyx_v_num_aligned_chunks = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1479 + * if self.require_aligned_terminal: + * num_aligned_chunks = 0 + * for i from 0 <= i < num_chunks: # <<<<<<<<<<<<<< + * for j from 0 <= j < chunklen[i]: + * if f_links_low[matching.arr[matching.start+i]+j-f_sent_start] > -1: + */ + __pyx_t_3 = __pyx_v_num_chunks; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1480 + * num_aligned_chunks = 0 + * for i from 0 <= i < num_chunks: + * for j from 0 <= j < chunklen[i]: # <<<<<<<<<<<<<< + * if f_links_low[matching.arr[matching.start+i]+j-f_sent_start] > -1: + * num_aligned_chunks = num_aligned_chunks + 1 + */ + __pyx_t_4 = (__pyx_v_chunklen[__pyx_v_i]); + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_4; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1481 + * for i from 0 <= i < num_chunks: + * for j from 0 <= j < chunklen[i]: + * if f_links_low[matching.arr[matching.start+i]+j-f_sent_start] > -1: # <<<<<<<<<<<<<< + * num_aligned_chunks = num_aligned_chunks + 1 + * break + */ + __pyx_t_9 = ((__pyx_v_f_links_low[(((__pyx_v_matching->arr[(__pyx_v_matching->start + __pyx_v_i)]) + __pyx_v_j) - __pyx_v_f_sent_start)]) > -1); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1482 + * for j from 0 <= j < chunklen[i]: + * if f_links_low[matching.arr[matching.start+i]+j-f_sent_start] > -1: + * num_aligned_chunks = num_aligned_chunks + 1 # <<<<<<<<<<<<<< + * break + * if num_aligned_chunks == 0: + */ + __pyx_v_num_aligned_chunks = (__pyx_v_num_aligned_chunks + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1483 + * if f_links_low[matching.arr[matching.start+i]+j-f_sent_start] > -1: + * num_aligned_chunks = num_aligned_chunks + 1 + * break # <<<<<<<<<<<<<< + * if num_aligned_chunks == 0: + * reason_for_failure = "No aligned terminals" + */ + goto __pyx_L24_break; + goto __pyx_L25; + } + __pyx_L25:; + } + __pyx_L24_break:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1484 + * num_aligned_chunks = num_aligned_chunks + 1 + * break + * if num_aligned_chunks == 0: # <<<<<<<<<<<<<< + * reason_for_failure = "No aligned terminals" + * met_constraints = 0 + */ + __pyx_t_9 = (__pyx_v_num_aligned_chunks == 0); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1485 + * break + * if num_aligned_chunks == 0: + * reason_for_failure = "No aligned terminals" # <<<<<<<<<<<<<< + * met_constraints = 0 + * if self.require_aligned_chunks and num_aligned_chunks < num_chunks: + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_124)); + __Pyx_DECREF(__pyx_v_reason_for_failure); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_124); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1486 + * if num_aligned_chunks == 0: + * reason_for_failure = "No aligned terminals" + * met_constraints = 0 # <<<<<<<<<<<<<< + * if self.require_aligned_chunks and num_aligned_chunks < num_chunks: + * reason_for_failure = "Unaligned chunk" + */ + __pyx_v_met_constraints = 0; + goto __pyx_L26; + } + __pyx_L26:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1487 + * reason_for_failure = "No aligned terminals" + * met_constraints = 0 + * if self.require_aligned_chunks and num_aligned_chunks < num_chunks: # <<<<<<<<<<<<<< + * reason_for_failure = "Unaligned chunk" + * met_constraints = 0 + */ + if (__pyx_v_self->require_aligned_chunks) { + __pyx_t_9 = (__pyx_v_num_aligned_chunks < __pyx_v_num_chunks); + __pyx_t_7 = __pyx_t_9; + } else { + __pyx_t_7 = __pyx_v_self->require_aligned_chunks; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1488 + * met_constraints = 0 + * if self.require_aligned_chunks and num_aligned_chunks < num_chunks: + * reason_for_failure = "Unaligned chunk" # <<<<<<<<<<<<<< + * met_constraints = 0 + * + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_125)); + __Pyx_DECREF(__pyx_v_reason_for_failure); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_125); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1489 + * if self.require_aligned_chunks and num_aligned_chunks < num_chunks: + * reason_for_failure = "Unaligned chunk" + * met_constraints = 0 # <<<<<<<<<<<<<< + * + * if met_constraints and self.tight_phrases: + */ + __pyx_v_met_constraints = 0; + goto __pyx_L27; + } + __pyx_L27:; + goto __pyx_L20; + } + __pyx_L20:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1491 + * met_constraints = 0 + * + * if met_constraints and self.tight_phrases: # <<<<<<<<<<<<<< + * # outside edge constraints are checked later + * for i from 0 <= i < num_chunks-1: + */ + if (__pyx_v_met_constraints) { + __pyx_t_7 = __pyx_v_self->tight_phrases; + } else { + __pyx_t_7 = __pyx_v_met_constraints; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1493 + * if met_constraints and self.tight_phrases: + * # outside edge constraints are checked later + * for i from 0 <= i < num_chunks-1: # <<<<<<<<<<<<<< + * if f_links_low[matching.arr[matching.start+i]+chunklen[i]-f_sent_start] == -1: + * reason_for_failure = "Gaps are not tight phrases" + */ + __pyx_t_12 = (__pyx_v_num_chunks - 1); + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_12; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1494 + * # outside edge constraints are checked later + * for i from 0 <= i < num_chunks-1: + * if f_links_low[matching.arr[matching.start+i]+chunklen[i]-f_sent_start] == -1: # <<<<<<<<<<<<<< + * reason_for_failure = "Gaps are not tight phrases" + * met_constraints = 0 + */ + __pyx_t_7 = ((__pyx_v_f_links_low[(((__pyx_v_matching->arr[(__pyx_v_matching->start + __pyx_v_i)]) + (__pyx_v_chunklen[__pyx_v_i])) - __pyx_v_f_sent_start)]) == -1); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1495 + * for i from 0 <= i < num_chunks-1: + * if f_links_low[matching.arr[matching.start+i]+chunklen[i]-f_sent_start] == -1: + * reason_for_failure = "Gaps are not tight phrases" # <<<<<<<<<<<<<< + * met_constraints = 0 + * break + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_126)); + __Pyx_DECREF(__pyx_v_reason_for_failure); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_126); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1496 + * if f_links_low[matching.arr[matching.start+i]+chunklen[i]-f_sent_start] == -1: + * reason_for_failure = "Gaps are not tight phrases" + * met_constraints = 0 # <<<<<<<<<<<<<< + * break + * if f_links_low[matching.arr[matching.start+i+1]-1-f_sent_start] == -1: + */ + __pyx_v_met_constraints = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1497 + * reason_for_failure = "Gaps are not tight phrases" + * met_constraints = 0 + * break # <<<<<<<<<<<<<< + * if f_links_low[matching.arr[matching.start+i+1]-1-f_sent_start] == -1: + * reason_for_failure = "Gaps are not tight phrases" + */ + goto __pyx_L30_break; + goto __pyx_L31; + } + __pyx_L31:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1498 + * met_constraints = 0 + * break + * if f_links_low[matching.arr[matching.start+i+1]-1-f_sent_start] == -1: # <<<<<<<<<<<<<< + * reason_for_failure = "Gaps are not tight phrases" + * met_constraints = 0 + */ + __pyx_t_7 = ((__pyx_v_f_links_low[(((__pyx_v_matching->arr[((__pyx_v_matching->start + __pyx_v_i) + 1)]) - 1) - __pyx_v_f_sent_start)]) == -1); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1499 + * break + * if f_links_low[matching.arr[matching.start+i+1]-1-f_sent_start] == -1: + * reason_for_failure = "Gaps are not tight phrases" # <<<<<<<<<<<<<< + * met_constraints = 0 + * break + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_126)); + __Pyx_DECREF(__pyx_v_reason_for_failure); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_126); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1500 + * if f_links_low[matching.arr[matching.start+i+1]-1-f_sent_start] == -1: + * reason_for_failure = "Gaps are not tight phrases" + * met_constraints = 0 # <<<<<<<<<<<<<< + * break + * + */ + __pyx_v_met_constraints = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1501 + * reason_for_failure = "Gaps are not tight phrases" + * met_constraints = 0 + * break # <<<<<<<<<<<<<< + * + * f_low = matching.arr[matching.start] - f_sent_start + */ + goto __pyx_L30_break; + goto __pyx_L32; + } + __pyx_L32:; + } + __pyx_L30_break:; + goto __pyx_L28; + } + __pyx_L28:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1503 + * break + * + * f_low = matching.arr[matching.start] - f_sent_start # <<<<<<<<<<<<<< + * f_high = matching.arr[matching.start + matching.size - 1] + chunklen[num_chunks-1] - f_sent_start + * if met_constraints: + */ + __pyx_v_f_low = ((__pyx_v_matching->arr[__pyx_v_matching->start]) - __pyx_v_f_sent_start); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1504 + * + * f_low = matching.arr[matching.start] - f_sent_start + * f_high = matching.arr[matching.start + matching.size - 1] + chunklen[num_chunks-1] - f_sent_start # <<<<<<<<<<<<<< + * if met_constraints: + * + */ + __pyx_v_f_high = (((__pyx_v_matching->arr[((__pyx_v_matching->start + __pyx_v_matching->size) - 1)]) + (__pyx_v_chunklen[(__pyx_v_num_chunks - 1)])) - __pyx_v_f_sent_start); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1505 + * f_low = matching.arr[matching.start] - f_sent_start + * f_high = matching.arr[matching.start + matching.size - 1] + chunklen[num_chunks-1] - f_sent_start + * if met_constraints: # <<<<<<<<<<<<<< + * + * if self.find_fixpoint(f_low, f_high, f_links_low, f_links_high, e_links_low, e_links_high, + */ + if (__pyx_v_met_constraints) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1507 + * if met_constraints: + * + * if self.find_fixpoint(f_low, f_high, f_links_low, f_links_high, e_links_low, e_links_high, # <<<<<<<<<<<<<< + * -1, -1, &e_low, &e_high, &f_back_low, &f_back_high, f_sent_len, e_sent_len, + * self.train_max_initial_size, self.train_max_initial_size, + */ + __pyx_t_10 = PyInt_FromLong(__pyx_v_f_high); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1507; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1511 + * self.train_max_initial_size, self.train_max_initial_size, + * self.train_min_gap_size, 0, + * self.max_nonterminals - num_chunks + 1, 1, 1, 0, 0): # <<<<<<<<<<<<<< + * gap_error = 0 + * num_gaps = 0 + */ + __pyx_t_3 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_low, __pyx_t_10, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, -1, -1, (&__pyx_v_e_low), (&__pyx_v_e_high), (&__pyx_v_f_back_low), (&__pyx_v_f_back_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_min_gap_size, 0, ((__pyx_v_self->max_nonterminals - __pyx_v_num_chunks) + 1), 1, 1, 0, 0); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1512 + * self.train_min_gap_size, 0, + * self.max_nonterminals - num_chunks + 1, 1, 1, 0, 0): + * gap_error = 0 # <<<<<<<<<<<<<< + * num_gaps = 0 + * + */ + __pyx_v_gap_error = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1513 + * self.max_nonterminals - num_chunks + 1, 1, 1, 0, 0): + * gap_error = 0 + * num_gaps = 0 # <<<<<<<<<<<<<< + * + * if f_back_low < f_low: + */ + __pyx_v_num_gaps = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1515 + * num_gaps = 0 + * + * if f_back_low < f_low: # <<<<<<<<<<<<<< + * f_gap_low[0] = f_back_low + * f_gap_high[0] = f_low + */ + __pyx_t_7 = (__pyx_v_f_back_low < __pyx_v_f_low); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1516 + * + * if f_back_low < f_low: + * f_gap_low[0] = f_back_low # <<<<<<<<<<<<<< + * f_gap_high[0] = f_low + * num_gaps = 1 + */ + (__pyx_v_f_gap_low[0]) = __pyx_v_f_back_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1517 + * if f_back_low < f_low: + * f_gap_low[0] = f_back_low + * f_gap_high[0] = f_low # <<<<<<<<<<<<<< + * num_gaps = 1 + * gap_start = 0 + */ + (__pyx_v_f_gap_high[0]) = __pyx_v_f_low; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1518 + * f_gap_low[0] = f_back_low + * f_gap_high[0] = f_low + * num_gaps = 1 # <<<<<<<<<<<<<< + * gap_start = 0 + * phrase_len = phrase_len+1 + */ + __pyx_v_num_gaps = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1519 + * f_gap_high[0] = f_low + * num_gaps = 1 + * gap_start = 0 # <<<<<<<<<<<<<< + * phrase_len = phrase_len+1 + * if phrase_len > self.max_length: + */ + __pyx_v_gap_start = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1520 + * num_gaps = 1 + * gap_start = 0 + * phrase_len = phrase_len+1 # <<<<<<<<<<<<<< + * if phrase_len > self.max_length: + * gap_error = 1 + */ + __pyx_v_phrase_len = (__pyx_v_phrase_len + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1521 + * gap_start = 0 + * phrase_len = phrase_len+1 + * if phrase_len > self.max_length: # <<<<<<<<<<<<<< + * gap_error = 1 + * if self.tight_phrases: + */ + __pyx_t_7 = (__pyx_v_phrase_len > __pyx_v_self->max_length); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1522 + * phrase_len = phrase_len+1 + * if phrase_len > self.max_length: + * gap_error = 1 # <<<<<<<<<<<<<< + * if self.tight_phrases: + * if f_links_low[f_back_low] == -1 or f_links_low[f_low-1] == -1: + */ + __pyx_v_gap_error = 1; + goto __pyx_L36; + } + __pyx_L36:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1523 + * if phrase_len > self.max_length: + * gap_error = 1 + * if self.tight_phrases: # <<<<<<<<<<<<<< + * if f_links_low[f_back_low] == -1 or f_links_low[f_low-1] == -1: + * gap_error = 1 + */ + if (__pyx_v_self->tight_phrases) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1524 + * gap_error = 1 + * if self.tight_phrases: + * if f_links_low[f_back_low] == -1 or f_links_low[f_low-1] == -1: # <<<<<<<<<<<<<< + * gap_error = 1 + * reason_for_failure = "Inside edges of preceding subphrase are not tight" + */ + __pyx_t_7 = ((__pyx_v_f_links_low[__pyx_v_f_back_low]) == -1); + if (!__pyx_t_7) { + __pyx_t_9 = ((__pyx_v_f_links_low[(__pyx_v_f_low - 1)]) == -1); + __pyx_t_8 = __pyx_t_9; + } else { + __pyx_t_8 = __pyx_t_7; + } + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1525 + * if self.tight_phrases: + * if f_links_low[f_back_low] == -1 or f_links_low[f_low-1] == -1: + * gap_error = 1 # <<<<<<<<<<<<<< + * reason_for_failure = "Inside edges of preceding subphrase are not tight" + * else: + */ + __pyx_v_gap_error = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1526 + * if f_links_low[f_back_low] == -1 or f_links_low[f_low-1] == -1: + * gap_error = 1 + * reason_for_failure = "Inside edges of preceding subphrase are not tight" # <<<<<<<<<<<<<< + * else: + * gap_start = 1 + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_127)); + __Pyx_DECREF(__pyx_v_reason_for_failure); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_127); + goto __pyx_L38; + } + __pyx_L38:; + goto __pyx_L37; + } + __pyx_L37:; + goto __pyx_L35; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1528 + * reason_for_failure = "Inside edges of preceding subphrase are not tight" + * else: + * gap_start = 1 # <<<<<<<<<<<<<< + * if self.tight_phrases and f_links_low[f_low] == -1: + * # this is not a hard error. we can't extract this phrase + */ + __pyx_v_gap_start = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1529 + * else: + * gap_start = 1 + * if self.tight_phrases and f_links_low[f_low] == -1: # <<<<<<<<<<<<<< + * # this is not a hard error. we can't extract this phrase + * # but we still might be able to extract a superphrase + */ + if (__pyx_v_self->tight_phrases) { + __pyx_t_8 = ((__pyx_v_f_links_low[__pyx_v_f_low]) == -1); + __pyx_t_7 = __pyx_t_8; + } else { + __pyx_t_7 = __pyx_v_self->tight_phrases; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1532 + * # this is not a hard error. we can't extract this phrase + * # but we still might be able to extract a superphrase + * met_constraints = 0 # <<<<<<<<<<<<<< + * + * for i from 0 <= i < matching.size - 1: + */ + __pyx_v_met_constraints = 0; + goto __pyx_L39; + } + __pyx_L39:; + } + __pyx_L35:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1534 + * met_constraints = 0 + * + * for i from 0 <= i < matching.size - 1: # <<<<<<<<<<<<<< + * f_gap_low[1+i] = matching.arr[matching.start+i] + chunklen[i] - f_sent_start + * f_gap_high[1+i] = matching.arr[matching.start+i+1] - f_sent_start + */ + __pyx_t_12 = (__pyx_v_matching->size - 1); + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_12; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1535 + * + * for i from 0 <= i < matching.size - 1: + * f_gap_low[1+i] = matching.arr[matching.start+i] + chunklen[i] - f_sent_start # <<<<<<<<<<<<<< + * f_gap_high[1+i] = matching.arr[matching.start+i+1] - f_sent_start + * num_gaps = num_gaps + 1 + */ + (__pyx_v_f_gap_low[(1 + __pyx_v_i)]) = (((__pyx_v_matching->arr[(__pyx_v_matching->start + __pyx_v_i)]) + (__pyx_v_chunklen[__pyx_v_i])) - __pyx_v_f_sent_start); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1536 + * for i from 0 <= i < matching.size - 1: + * f_gap_low[1+i] = matching.arr[matching.start+i] + chunklen[i] - f_sent_start + * f_gap_high[1+i] = matching.arr[matching.start+i+1] - f_sent_start # <<<<<<<<<<<<<< + * num_gaps = num_gaps + 1 + * + */ + (__pyx_v_f_gap_high[(1 + __pyx_v_i)]) = ((__pyx_v_matching->arr[((__pyx_v_matching->start + __pyx_v_i) + 1)]) - __pyx_v_f_sent_start); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1537 + * f_gap_low[1+i] = matching.arr[matching.start+i] + chunklen[i] - f_sent_start + * f_gap_high[1+i] = matching.arr[matching.start+i+1] - f_sent_start + * num_gaps = num_gaps + 1 # <<<<<<<<<<<<<< + * + * if f_high < f_back_high: + */ + __pyx_v_num_gaps = (__pyx_v_num_gaps + 1); + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1539 + * num_gaps = num_gaps + 1 + * + * if f_high < f_back_high: # <<<<<<<<<<<<<< + * f_gap_low[gap_start+num_gaps] = f_high + * f_gap_high[gap_start+num_gaps] = f_back_high + */ + __pyx_t_7 = (__pyx_v_f_high < __pyx_v_f_back_high); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1540 + * + * if f_high < f_back_high: + * f_gap_low[gap_start+num_gaps] = f_high # <<<<<<<<<<<<<< + * f_gap_high[gap_start+num_gaps] = f_back_high + * num_gaps = num_gaps + 1 + */ + (__pyx_v_f_gap_low[(__pyx_v_gap_start + __pyx_v_num_gaps)]) = __pyx_v_f_high; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1541 + * if f_high < f_back_high: + * f_gap_low[gap_start+num_gaps] = f_high + * f_gap_high[gap_start+num_gaps] = f_back_high # <<<<<<<<<<<<<< + * num_gaps = num_gaps + 1 + * phrase_len = phrase_len+1 + */ + (__pyx_v_f_gap_high[(__pyx_v_gap_start + __pyx_v_num_gaps)]) = __pyx_v_f_back_high; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1542 + * f_gap_low[gap_start+num_gaps] = f_high + * f_gap_high[gap_start+num_gaps] = f_back_high + * num_gaps = num_gaps + 1 # <<<<<<<<<<<<<< + * phrase_len = phrase_len+1 + * if phrase_len > self.max_length: + */ + __pyx_v_num_gaps = (__pyx_v_num_gaps + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1543 + * f_gap_high[gap_start+num_gaps] = f_back_high + * num_gaps = num_gaps + 1 + * phrase_len = phrase_len+1 # <<<<<<<<<<<<<< + * if phrase_len > self.max_length: + * gap_error = 1 + */ + __pyx_v_phrase_len = (__pyx_v_phrase_len + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1544 + * num_gaps = num_gaps + 1 + * phrase_len = phrase_len+1 + * if phrase_len > self.max_length: # <<<<<<<<<<<<<< + * gap_error = 1 + * if self.tight_phrases: + */ + __pyx_t_7 = (__pyx_v_phrase_len > __pyx_v_self->max_length); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1545 + * phrase_len = phrase_len+1 + * if phrase_len > self.max_length: + * gap_error = 1 # <<<<<<<<<<<<<< + * if self.tight_phrases: + * if f_links_low[f_back_high-1] == -1 or f_links_low[f_high] == -1: + */ + __pyx_v_gap_error = 1; + goto __pyx_L43; + } + __pyx_L43:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1546 + * if phrase_len > self.max_length: + * gap_error = 1 + * if self.tight_phrases: # <<<<<<<<<<<<<< + * if f_links_low[f_back_high-1] == -1 or f_links_low[f_high] == -1: + * gap_error = 1 + */ + if (__pyx_v_self->tight_phrases) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1547 + * gap_error = 1 + * if self.tight_phrases: + * if f_links_low[f_back_high-1] == -1 or f_links_low[f_high] == -1: # <<<<<<<<<<<<<< + * gap_error = 1 + * reason_for_failure = "Inside edges of following subphrase are not tight" + */ + __pyx_t_7 = ((__pyx_v_f_links_low[(__pyx_v_f_back_high - 1)]) == -1); + if (!__pyx_t_7) { + __pyx_t_8 = ((__pyx_v_f_links_low[__pyx_v_f_high]) == -1); + __pyx_t_9 = __pyx_t_8; + } else { + __pyx_t_9 = __pyx_t_7; + } + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1548 + * if self.tight_phrases: + * if f_links_low[f_back_high-1] == -1 or f_links_low[f_high] == -1: + * gap_error = 1 # <<<<<<<<<<<<<< + * reason_for_failure = "Inside edges of following subphrase are not tight" + * else: + */ + __pyx_v_gap_error = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1549 + * if f_links_low[f_back_high-1] == -1 or f_links_low[f_high] == -1: + * gap_error = 1 + * reason_for_failure = "Inside edges of following subphrase are not tight" # <<<<<<<<<<<<<< + * else: + * if self.tight_phrases and f_links_low[f_high-1] == -1: + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_128)); + __Pyx_DECREF(__pyx_v_reason_for_failure); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_128); + goto __pyx_L45; + } + __pyx_L45:; + goto __pyx_L44; + } + __pyx_L44:; + goto __pyx_L42; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1551 + * reason_for_failure = "Inside edges of following subphrase are not tight" + * else: + * if self.tight_phrases and f_links_low[f_high-1] == -1: # <<<<<<<<<<<<<< + * met_constraints = 0 + * + */ + if (__pyx_v_self->tight_phrases) { + __pyx_t_9 = ((__pyx_v_f_links_low[(__pyx_v_f_high - 1)]) == -1); + __pyx_t_7 = __pyx_t_9; + } else { + __pyx_t_7 = __pyx_v_self->tight_phrases; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1552 + * else: + * if self.tight_phrases and f_links_low[f_high-1] == -1: + * met_constraints = 0 # <<<<<<<<<<<<<< + * + * if gap_error == 0: + */ + __pyx_v_met_constraints = 0; + goto __pyx_L46; + } + __pyx_L46:; + } + __pyx_L42:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1554 + * met_constraints = 0 + * + * if gap_error == 0: # <<<<<<<<<<<<<< + * e_word_count = e_high - e_low + * for i from 0 <= i < num_gaps: # check integrity of subphrases + */ + __pyx_t_7 = (__pyx_v_gap_error == 0); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1555 + * + * if gap_error == 0: + * e_word_count = e_high - e_low # <<<<<<<<<<<<<< + * for i from 0 <= i < num_gaps: # check integrity of subphrases + * if self.find_fixpoint(f_gap_low[gap_start+i], f_gap_high[gap_start+i], + */ + __pyx_v_e_word_count = (__pyx_v_e_high - __pyx_v_e_low); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1556 + * if gap_error == 0: + * e_word_count = e_high - e_low + * for i from 0 <= i < num_gaps: # check integrity of subphrases # <<<<<<<<<<<<<< + * if self.find_fixpoint(f_gap_low[gap_start+i], f_gap_high[gap_start+i], + * f_links_low, f_links_high, e_links_low, e_links_high, + */ + __pyx_t_3 = __pyx_v_num_gaps; + for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_3; __pyx_v_i++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1557 + * e_word_count = e_high - e_low + * for i from 0 <= i < num_gaps: # check integrity of subphrases + * if self.find_fixpoint(f_gap_low[gap_start+i], f_gap_high[gap_start+i], # <<<<<<<<<<<<<< + * f_links_low, f_links_high, e_links_low, e_links_high, + * -1, -1, e_gap_low+gap_start+i, e_gap_high+gap_start+i, + */ + __pyx_t_10 = PyInt_FromLong((__pyx_v_f_gap_high[(__pyx_v_gap_start + __pyx_v_i)])); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1557; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1562 + * f_gap_low+gap_start+i, f_gap_high+gap_start+i, + * f_sent_len, e_sent_len, + * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< + * 0, 0, 0, 0, 0, 0, 0) == 0: + * gap_error = 1 + */ + __pyx_t_7 = (((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, (__pyx_v_f_gap_low[(__pyx_v_gap_start + __pyx_v_i)]), __pyx_t_10, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, -1, -1, ((__pyx_v_e_gap_low + __pyx_v_gap_start) + __pyx_v_i), ((__pyx_v_e_gap_high + __pyx_v_gap_start) + __pyx_v_i), ((__pyx_v_f_gap_low + __pyx_v_gap_start) + __pyx_v_i), ((__pyx_v_f_gap_high + __pyx_v_gap_start) + __pyx_v_i), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 0, 0, 0, 0, 0, 0, 0) == 0); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1564 + * self.train_max_initial_size, self.train_max_initial_size, + * 0, 0, 0, 0, 0, 0, 0) == 0: + * gap_error = 1 # <<<<<<<<<<<<<< + * reason_for_failure = "Subphrase [%d, %d] failed integrity check" % (f_gap_low[gap_start+i], f_gap_high[gap_start+i]) + * break + */ + __pyx_v_gap_error = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1565 + * 0, 0, 0, 0, 0, 0, 0) == 0: + * gap_error = 1 + * reason_for_failure = "Subphrase [%d, %d] failed integrity check" % (f_gap_low[gap_start+i], f_gap_high[gap_start+i]) # <<<<<<<<<<<<<< + * break + * + */ + __pyx_t_10 = PyInt_FromLong((__pyx_v_f_gap_low[(__pyx_v_gap_start + __pyx_v_i)])); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1565; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_1 = PyInt_FromLong((__pyx_v_f_gap_high[(__pyx_v_gap_start + __pyx_v_i)])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1565; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1565; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_10 = 0; + __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_129), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1565; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_v_reason_for_failure); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1566 + * gap_error = 1 + * reason_for_failure = "Subphrase [%d, %d] failed integrity check" % (f_gap_low[gap_start+i], f_gap_high[gap_start+i]) + * break # <<<<<<<<<<<<<< + * + * if gap_error == 0: + */ + goto __pyx_L49_break; + goto __pyx_L50; + } + __pyx_L50:; + } + __pyx_L49_break:; + goto __pyx_L47; + } + __pyx_L47:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1568 + * break + * + * if gap_error == 0: # <<<<<<<<<<<<<< + * i = 1 + * self.findexes.reset() + */ + __pyx_t_7 = (__pyx_v_gap_error == 0); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1569 + * + * if gap_error == 0: + * i = 1 # <<<<<<<<<<<<<< + * self.findexes.reset() + * if f_back_low < f_low: + */ + __pyx_v_i = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1570 + * if gap_error == 0: + * i = 1 + * self.findexes.reset() # <<<<<<<<<<<<<< + * if f_back_low < f_low: + * fphr_arr._append(sym_setindex(self.category, i)) + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__reset); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1570; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1570; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1571 + * i = 1 + * self.findexes.reset() + * if f_back_low < f_low: # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 + */ + __pyx_t_7 = (__pyx_v_f_back_low < __pyx_v_f_low); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1572 + * self.findexes.reset() + * if f_back_low < f_low: + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * i = i+1 + * self.findexes.append(sym_setindex(self.category, i)) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1573 + * if f_back_low < f_low: + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 # <<<<<<<<<<<<<< + * self.findexes.append(sym_setindex(self.category, i)) + * self.findexes.extend(self.findexes1) + */ + __pyx_v_i = (__pyx_v_i + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1574 + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 + * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: + */ + __pyx_t_2 = PyInt_FromLong(__pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1574; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1574; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L52; + } + __pyx_L52:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1575 + * i = i+1 + * self.findexes.append(sym_setindex(self.category, i)) + * self.findexes.extend(self.findexes1) # <<<<<<<<<<<<<< + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__extend); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_v_self->findexes1)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self->findexes1)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->findexes1)); + __pyx_t_10 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1575; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1576 + * self.findexes.append(sym_setindex(self.category, i)) + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: # <<<<<<<<<<<<<< + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) + */ + __pyx_t_3 = __pyx_v_phrase->n; + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1577 + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i + 1 + */ + __pyx_t_4 = __pyx_f_3_sa_sym_isvar((__pyx_v_phrase->syms[__pyx_v_j])); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1578 + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * i = i + 1 + * else: + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1579 + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i + 1 # <<<<<<<<<<<<<< + * else: + * fphr_arr._append(phrase.syms[j]) + */ + __pyx_v_i = (__pyx_v_i + 1); + goto __pyx_L55; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1581 + * i = i + 1 + * else: + * fphr_arr._append(phrase.syms[j]) # <<<<<<<<<<<<<< + * if f_back_high > f_high: + * fphr_arr._append(sym_setindex(self.category, i)) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, (__pyx_v_phrase->syms[__pyx_v_j])); + } + __pyx_L55:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1582 + * else: + * fphr_arr._append(phrase.syms[j]) + * if f_back_high > f_high: # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) + */ + __pyx_t_7 = (__pyx_v_f_back_high > __pyx_v_f_high); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1583 + * fphr_arr._append(phrase.syms[j]) + * if f_back_high > f_high: + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * self.findexes.append(sym_setindex(self.category, i)) + * + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1584 + * if f_back_high > f_high: + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * + * fphr = Phrase(fphr_arr) + */ + __pyx_t_10 = PyInt_FromLong(__pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1584; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_10); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1584; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L56; + } + __pyx_L56:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1586 + * self.findexes.append(sym_setindex(self.category, i)) + * + * fphr = Phrase(fphr_arr) # <<<<<<<<<<<<<< + * if met_constraints: + * phrase_list = self.extract_phrases(e_low, e_high, e_gap_low + gap_start, e_gap_high + gap_start, e_links_low, num_gaps, + */ + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1586; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_v_fphr_arr)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_fphr_arr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr_arr)); + __pyx_t_10 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_Phrase)), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1586; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_v_fphr = ((struct __pyx_obj_3_sa_Phrase *)__pyx_t_10); + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1587 + * + * fphr = Phrase(fphr_arr) + * if met_constraints: # <<<<<<<<<<<<<< + * phrase_list = self.extract_phrases(e_low, e_high, e_gap_low + gap_start, e_gap_high + gap_start, e_links_low, num_gaps, + * f_back_low, f_back_high, f_gap_low + gap_start, f_gap_high + gap_start, f_links_low, + */ + if (__pyx_v_met_constraints) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1590 + * phrase_list = self.extract_phrases(e_low, e_high, e_gap_low + gap_start, e_gap_high + gap_start, e_links_low, num_gaps, + * f_back_low, f_back_high, f_gap_low + gap_start, f_gap_high + gap_start, f_links_low, + * matching.sent_id, e_sent_len, e_sent_start) # <<<<<<<<<<<<<< + * if len(phrase_list) > 0: + * pair_count = 1.0 / len(phrase_list) + */ + __pyx_t_10 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->extract_phrases(__pyx_v_self, __pyx_v_e_low, __pyx_v_e_high, (__pyx_v_e_gap_low + __pyx_v_gap_start), (__pyx_v_e_gap_high + __pyx_v_gap_start), __pyx_v_e_links_low, __pyx_v_num_gaps, __pyx_v_f_back_low, __pyx_v_f_back_high, (__pyx_v_f_gap_low + __pyx_v_gap_start), (__pyx_v_f_gap_high + __pyx_v_gap_start), __pyx_v_f_links_low, __pyx_v_matching->sent_id, __pyx_v_e_sent_len, __pyx_v_e_sent_start); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1588; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_v_phrase_list = __pyx_t_10; + __pyx_t_10 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1591 + * f_back_low, f_back_high, f_gap_low + gap_start, f_gap_high + gap_start, f_links_low, + * matching.sent_id, e_sent_len, e_sent_start) + * if len(phrase_list) > 0: # <<<<<<<<<<<<<< + * pair_count = 1.0 / len(phrase_list) + * else: + */ + __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1591; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = (__pyx_t_13 > 0); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1592 + * matching.sent_id, e_sent_len, e_sent_start) + * if len(phrase_list) > 0: + * pair_count = 1.0 / len(phrase_list) # <<<<<<<<<<<<<< + * else: + * pair_count = 0 + */ + __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__pyx_t_13 == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_pair_count = (1.0 / __pyx_t_13); + goto __pyx_L58; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1594 + * pair_count = 1.0 / len(phrase_list) + * else: + * pair_count = 0 # <<<<<<<<<<<<<< + * reason_for_failure = "Didn't extract anything from [%d, %d] -> [%d, %d]" % (f_back_low, f_back_high, e_low, e_high) + * for (phrase2,eindexes) in phrase_list: + */ + __pyx_v_pair_count = 0.0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1595 + * else: + * pair_count = 0 + * reason_for_failure = "Didn't extract anything from [%d, %d] -> [%d, %d]" % (f_back_low, f_back_high, e_low, e_high) # <<<<<<<<<<<<<< + * for (phrase2,eindexes) in phrase_list: + * als1 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + */ + __pyx_t_10 = PyInt_FromLong(__pyx_v_f_back_low); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1595; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = PyInt_FromLong(__pyx_v_f_back_high); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1595; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyInt_FromLong(__pyx_v_e_low); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1595; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_14 = PyInt_FromLong(__pyx_v_e_high); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1595; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = PyTuple_New(4); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1595; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_10); + __Pyx_GIVEREF(__pyx_t_10); + PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_t_10 = 0; + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __pyx_t_14 = 0; + __pyx_t_14 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_130), ((PyObject *)__pyx_t_15)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1595; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_14)); + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_v_reason_for_failure); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_t_14); + __pyx_t_14 = 0; + } + __pyx_L58:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1596 + * pair_count = 0 + * reason_for_failure = "Didn't extract anything from [%d, %d] -> [%d, %d]" % (f_back_low, f_back_high, e_low, e_high) + * for (phrase2,eindexes) in phrase_list: # <<<<<<<<<<<<<< + * als1 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + * extracts.append((fphr, phrase2, pair_count, tuple(als1))) + */ + if (PyList_CheckExact(__pyx_v_phrase_list) || PyTuple_CheckExact(__pyx_v_phrase_list)) { + __pyx_t_14 = __pyx_v_phrase_list; __Pyx_INCREF(__pyx_t_14); __pyx_t_13 = 0; + __pyx_t_16 = NULL; + } else { + __pyx_t_13 = -1; __pyx_t_14 = PyObject_GetIter(__pyx_v_phrase_list); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_16 = Py_TYPE(__pyx_t_14)->tp_iternext; + } + for (;;) { + if (!__pyx_t_16 && PyList_CheckExact(__pyx_t_14)) { + if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_14)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_15 = PyList_GET_ITEM(__pyx_t_14, __pyx_t_13); __Pyx_INCREF(__pyx_t_15); __pyx_t_13++; + #else + __pyx_t_15 = PySequence_ITEM(__pyx_t_14, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_16 && PyTuple_CheckExact(__pyx_t_14)) { + if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_14)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_15 = PyTuple_GET_ITEM(__pyx_t_14, __pyx_t_13); __Pyx_INCREF(__pyx_t_15); __pyx_t_13++; + #else + __pyx_t_15 = PySequence_ITEM(__pyx_t_14, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_15 = __pyx_t_16(__pyx_t_14); + if (unlikely(!__pyx_t_15)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_15); + } + if ((likely(PyTuple_CheckExact(__pyx_t_15))) || (PyList_CheckExact(__pyx_t_15))) { + PyObject* sequence = __pyx_t_15; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_2 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_2); + #else + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } else + { + Py_ssize_t index = -1; + __pyx_t_10 = PyObject_GetIter(__pyx_t_15); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_17 = Py_TYPE(__pyx_t_10)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_17(__pyx_t_10); if (unlikely(!__pyx_t_1)) goto __pyx_L61_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_2 = __pyx_t_17(__pyx_t_10); if (unlikely(!__pyx_t_2)) goto __pyx_L61_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_10), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_17 = NULL; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L62_unpacking_done; + __pyx_L61_unpacking_failed:; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_17 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L62_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_phrase2); + __pyx_v_phrase2 = __pyx_t_1; + __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_v_eindexes); + __pyx_v_eindexes = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1597 + * reason_for_failure = "Didn't extract anything from [%d, %d] -> [%d, %d]" % (f_back_low, f_back_high, e_low, e_high) + * for (phrase2,eindexes) in phrase_list: + * als1 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) # <<<<<<<<<<<<<< + * extracts.append((fphr, phrase2, pair_count, tuple(als1))) + * + */ + __pyx_t_15 = ((PyObject *)__pyx_v_self->findexes); + __Pyx_INCREF(__pyx_t_15); + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->create_alignments(__pyx_v_self, __pyx_v_sent_links, __pyx_v_num_links, __pyx_t_15, __pyx_v_eindexes); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_v_als1); + __pyx_v_als1 = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1598 + * for (phrase2,eindexes) in phrase_list: + * als1 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + * extracts.append((fphr, phrase2, pair_count, tuple(als1))) # <<<<<<<<<<<<<< + * + * if (num_gaps < self.max_nonterminals and + */ + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_pair_count); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(__pyx_v_als1); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_als1); + __Pyx_GIVEREF(__pyx_v_als1); + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __pyx_t_15 = PyTuple_New(4); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(((PyObject *)__pyx_v_fphr)); + PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)__pyx_v_fphr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr)); + __Pyx_INCREF(__pyx_v_phrase2); + PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_v_phrase2); + __Pyx_GIVEREF(__pyx_v_phrase2); + PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Append(__pyx_v_extracts, ((PyObject *)__pyx_t_15)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + goto __pyx_L57; + } + __pyx_L57:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1600 + * extracts.append((fphr, phrase2, pair_count, tuple(als1))) + * + * if (num_gaps < self.max_nonterminals and # <<<<<<<<<<<<<< + * phrase_len < self.max_length and + * f_back_high - f_back_low + self.train_min_gap_size <= self.train_max_initial_size): + */ + __pyx_t_7 = (__pyx_v_num_gaps < __pyx_v_self->max_nonterminals); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1601 + * + * if (num_gaps < self.max_nonterminals and + * phrase_len < self.max_length and # <<<<<<<<<<<<<< + * f_back_high - f_back_low + self.train_min_gap_size <= self.train_max_initial_size): + * if (f_back_low == f_low and + */ + __pyx_t_9 = (__pyx_v_phrase_len < __pyx_v_self->max_length); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1602 + * if (num_gaps < self.max_nonterminals and + * phrase_len < self.max_length and + * f_back_high - f_back_low + self.train_min_gap_size <= self.train_max_initial_size): # <<<<<<<<<<<<<< + * if (f_back_low == f_low and + * f_low >= self.train_min_gap_size and + */ + __pyx_t_8 = (((__pyx_v_f_back_high - __pyx_v_f_back_low) + __pyx_v_self->train_min_gap_size) <= __pyx_v_self->train_max_initial_size); + __pyx_t_18 = __pyx_t_8; + } else { + __pyx_t_18 = __pyx_t_9; + } + __pyx_t_9 = __pyx_t_18; + } else { + __pyx_t_9 = __pyx_t_7; + } + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1603 + * phrase_len < self.max_length and + * f_back_high - f_back_low + self.train_min_gap_size <= self.train_max_initial_size): + * if (f_back_low == f_low and # <<<<<<<<<<<<<< + * f_low >= self.train_min_gap_size and + * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_back_high-1] != -1))): + */ + __pyx_t_9 = (__pyx_v_f_back_low == __pyx_v_f_low); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1604 + * f_back_high - f_back_low + self.train_min_gap_size <= self.train_max_initial_size): + * if (f_back_low == f_low and + * f_low >= self.train_min_gap_size and # <<<<<<<<<<<<<< + * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_back_high-1] != -1))): + * f_x_low = f_low-self.train_min_gap_size + */ + __pyx_t_7 = (__pyx_v_f_low >= __pyx_v_self->train_min_gap_size); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1605 + * if (f_back_low == f_low and + * f_low >= self.train_min_gap_size and + * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_back_high-1] != -1))): # <<<<<<<<<<<<<< + * f_x_low = f_low-self.train_min_gap_size + * met_constraints = 1 + */ + __pyx_t_18 = (!__pyx_v_self->tight_phrases); + if (!__pyx_t_18) { + __pyx_t_8 = ((__pyx_v_f_links_low[(__pyx_v_f_low - 1)]) != -1); + if (__pyx_t_8) { + __pyx_t_19 = ((__pyx_v_f_links_low[(__pyx_v_f_back_high - 1)]) != -1); + __pyx_t_20 = __pyx_t_19; + } else { + __pyx_t_20 = __pyx_t_8; + } + __pyx_t_8 = __pyx_t_20; + } else { + __pyx_t_8 = __pyx_t_18; + } + __pyx_t_18 = __pyx_t_8; + } else { + __pyx_t_18 = __pyx_t_7; + } + __pyx_t_7 = __pyx_t_18; + } else { + __pyx_t_7 = __pyx_t_9; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1606 + * f_low >= self.train_min_gap_size and + * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_back_high-1] != -1))): + * f_x_low = f_low-self.train_min_gap_size # <<<<<<<<<<<<<< + * met_constraints = 1 + * if self.tight_phrases: + */ + __pyx_v_f_x_low = (__pyx_v_f_low - __pyx_v_self->train_min_gap_size); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1607 + * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_back_high-1] != -1))): + * f_x_low = f_low-self.train_min_gap_size + * met_constraints = 1 # <<<<<<<<<<<<<< + * if self.tight_phrases: + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: + */ + __pyx_v_met_constraints = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1608 + * f_x_low = f_low-self.train_min_gap_size + * met_constraints = 1 + * if self.tight_phrases: # <<<<<<<<<<<<<< + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: + * f_x_low = f_x_low - 1 + */ + if (__pyx_v_self->tight_phrases) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1609 + * met_constraints = 1 + * if self.tight_phrases: + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: # <<<<<<<<<<<<<< + * f_x_low = f_x_low - 1 + * if f_x_low < 0 or f_back_high - f_x_low > self.train_max_initial_size: + */ + while (1) { + __pyx_t_7 = (__pyx_v_f_x_low >= 0); + if (__pyx_t_7) { + __pyx_t_9 = ((__pyx_v_f_links_low[__pyx_v_f_x_low]) == -1); + __pyx_t_18 = __pyx_t_9; + } else { + __pyx_t_18 = __pyx_t_7; + } + if (!__pyx_t_18) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1610 + * if self.tight_phrases: + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: + * f_x_low = f_x_low - 1 # <<<<<<<<<<<<<< + * if f_x_low < 0 or f_back_high - f_x_low > self.train_max_initial_size: + * met_constraints = 0 + */ + __pyx_v_f_x_low = (__pyx_v_f_x_low - 1); + } + goto __pyx_L65; + } + __pyx_L65:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1611 + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: + * f_x_low = f_x_low - 1 + * if f_x_low < 0 or f_back_high - f_x_low > self.train_max_initial_size: # <<<<<<<<<<<<<< + * met_constraints = 0 + * + */ + __pyx_t_18 = (__pyx_v_f_x_low < 0); + if (!__pyx_t_18) { + __pyx_t_7 = ((__pyx_v_f_back_high - __pyx_v_f_x_low) > __pyx_v_self->train_max_initial_size); + __pyx_t_9 = __pyx_t_7; + } else { + __pyx_t_9 = __pyx_t_18; + } + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1612 + * f_x_low = f_x_low - 1 + * if f_x_low < 0 or f_back_high - f_x_low > self.train_max_initial_size: + * met_constraints = 0 # <<<<<<<<<<<<<< + * + * if (met_constraints and + */ + __pyx_v_met_constraints = 0; + goto __pyx_L68; + } + __pyx_L68:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1614 + * met_constraints = 0 + * + * if (met_constraints and # <<<<<<<<<<<<<< + * self.find_fixpoint(f_x_low, f_back_high, + * f_links_low, f_links_high, e_links_low, e_links_high, + */ + if (__pyx_v_met_constraints) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1615 + * + * if (met_constraints and + * self.find_fixpoint(f_x_low, f_back_high, # <<<<<<<<<<<<<< + * f_links_low, f_links_high, e_links_low, e_links_high, + * e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, + */ + __pyx_t_14 = PyInt_FromLong(__pyx_v_f_back_high); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1615; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1619 + * e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, + * f_sent_len, e_sent_len, + * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< + * 1, 1, 1, 1, 0, 1, 0) and + * ((not self.tight_phrases) or f_links_low[f_x_low] != -1) and + */ + if (((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_x_low, __pyx_t_14, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_e_low, __pyx_v_e_high, (&__pyx_v_e_x_low), (&__pyx_v_e_x_high), (&__pyx_v_f_x_low), (&__pyx_v_f_x_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 1, 1, 1, 1, 0, 1, 0)) { + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1621 + * self.train_max_initial_size, self.train_max_initial_size, + * 1, 1, 1, 1, 0, 1, 0) and + * ((not self.tight_phrases) or f_links_low[f_x_low] != -1) and # <<<<<<<<<<<<<< + * self.find_fixpoint(f_x_low, f_low, # check integrity of new subphrase + * f_links_low, f_links_high, e_links_low, e_links_high, + */ + __pyx_t_9 = (!__pyx_v_self->tight_phrases); + if (!__pyx_t_9) { + __pyx_t_18 = ((__pyx_v_f_links_low[__pyx_v_f_x_low]) != -1); + __pyx_t_7 = __pyx_t_18; + } else { + __pyx_t_7 = __pyx_t_9; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1622 + * 1, 1, 1, 1, 0, 1, 0) and + * ((not self.tight_phrases) or f_links_low[f_x_low] != -1) and + * self.find_fixpoint(f_x_low, f_low, # check integrity of new subphrase # <<<<<<<<<<<<<< + * f_links_low, f_links_high, e_links_low, e_links_high, + * -1, -1, e_gap_low, e_gap_high, f_gap_low, f_gap_high, + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_f_low); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1622; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1626 + * -1, -1, e_gap_low, e_gap_high, f_gap_low, f_gap_high, + * f_sent_len, e_sent_len, + * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< + * 0, 0, 0, 0, 0, 0, 0)): + * fphr_arr._clear() + */ + __pyx_t_9 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_x_low, __pyx_t_1, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, -1, -1, __pyx_v_e_gap_low, __pyx_v_e_gap_high, __pyx_v_f_gap_low, __pyx_v_f_gap_high, __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 0, 0, 0, 0, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + __pyx_t_9 = __pyx_t_7; + } + __pyx_t_7 = __pyx_t_9; + } else { + __pyx_t_7 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_x_low, __pyx_t_14, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_e_low, __pyx_v_e_high, (&__pyx_v_e_x_low), (&__pyx_v_e_x_high), (&__pyx_v_f_x_low), (&__pyx_v_f_x_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 1, 1, 1, 1, 0, 1, 0); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } + __pyx_t_9 = __pyx_t_7; + } else { + __pyx_t_9 = __pyx_v_met_constraints; + } + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1628 + * self.train_max_initial_size, self.train_max_initial_size, + * 0, 0, 0, 0, 0, 0, 0)): + * fphr_arr._clear() # <<<<<<<<<<<<<< + * i = 1 + * self.findexes.reset() + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_clear(__pyx_v_fphr_arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1629 + * 0, 0, 0, 0, 0, 0, 0)): + * fphr_arr._clear() + * i = 1 # <<<<<<<<<<<<<< + * self.findexes.reset() + * self.findexes.append(sym_setindex(self.category, i)) + */ + __pyx_v_i = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1630 + * fphr_arr._clear() + * i = 1 + * self.findexes.reset() # <<<<<<<<<<<<<< + * self.findexes.append(sym_setindex(self.category, i)) + * fphr_arr._append(sym_setindex(self.category, i)) + */ + __pyx_t_14 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__reset); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1630; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_1 = PyObject_Call(__pyx_t_14, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1630; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1631 + * i = 1 + * self.findexes.reset() + * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 + */ + __pyx_t_1 = PyInt_FromLong(__pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1631; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_14 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1631; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1632 + * self.findexes.reset() + * self.findexes.append(sym_setindex(self.category, i)) + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * i = i+1 + * self.findexes.extend(self.findexes1) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1633 + * self.findexes.append(sym_setindex(self.category, i)) + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 # <<<<<<<<<<<<<< + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: + */ + __pyx_v_i = (__pyx_v_i + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1634 + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 + * self.findexes.extend(self.findexes1) # <<<<<<<<<<<<<< + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): + */ + __pyx_t_14 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__extend); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1634; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1634; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_self->findexes1)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self->findexes1)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->findexes1)); + __pyx_t_15 = PyObject_Call(__pyx_t_14, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1634; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1635 + * i = i+1 + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: # <<<<<<<<<<<<<< + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) + */ + __pyx_t_3 = __pyx_v_phrase->n; + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1636 + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i + 1 + */ + __pyx_t_4 = __pyx_f_3_sa_sym_isvar((__pyx_v_phrase->syms[__pyx_v_j])); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1637 + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * i = i + 1 + * else: + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1638 + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i + 1 # <<<<<<<<<<<<<< + * else: + * fphr_arr._append(phrase.syms[j]) + */ + __pyx_v_i = (__pyx_v_i + 1); + goto __pyx_L72; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1640 + * i = i + 1 + * else: + * fphr_arr._append(phrase.syms[j]) # <<<<<<<<<<<<<< + * if f_back_high > f_high: + * fphr_arr._append(sym_setindex(self.category, i)) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, (__pyx_v_phrase->syms[__pyx_v_j])); + } + __pyx_L72:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1641 + * else: + * fphr_arr._append(phrase.syms[j]) + * if f_back_high > f_high: # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) + */ + __pyx_t_9 = (__pyx_v_f_back_high > __pyx_v_f_high); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1642 + * fphr_arr._append(phrase.syms[j]) + * if f_back_high > f_high: + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * self.findexes.append(sym_setindex(self.category, i)) + * fphr = Phrase(fphr_arr) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1643 + * if f_back_high > f_high: + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * fphr = Phrase(fphr_arr) + * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+1, + */ + __pyx_t_15 = PyInt_FromLong(__pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1643; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_1 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_15); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1643; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L73; + } + __pyx_L73:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1644 + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) + * fphr = Phrase(fphr_arr) # <<<<<<<<<<<<<< + * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+1, + * f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, matching.sent_id, + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1644; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_fphr_arr)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_fphr_arr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr_arr)); + __pyx_t_15 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_Phrase)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1644; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_fphr)); + __pyx_v_fphr = ((struct __pyx_obj_3_sa_Phrase *)__pyx_t_15); + __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1647 + * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+1, + * f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, matching.sent_id, + * e_sent_len, e_sent_start) # <<<<<<<<<<<<<< + * if len(phrase_list) > 0: + * pair_count = 1.0 / len(phrase_list) + */ + __pyx_t_15 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->extract_phrases(__pyx_v_self, __pyx_v_e_x_low, __pyx_v_e_x_high, __pyx_v_e_gap_low, __pyx_v_e_gap_high, __pyx_v_e_links_low, (__pyx_v_num_gaps + 1), __pyx_v_f_x_low, __pyx_v_f_x_high, __pyx_v_f_gap_low, __pyx_v_f_gap_high, __pyx_v_f_links_low, __pyx_v_matching->sent_id, __pyx_v_e_sent_len, __pyx_v_e_sent_start); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1645; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_XDECREF(__pyx_v_phrase_list); + __pyx_v_phrase_list = __pyx_t_15; + __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1648 + * f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, matching.sent_id, + * e_sent_len, e_sent_start) + * if len(phrase_list) > 0: # <<<<<<<<<<<<<< + * pair_count = 1.0 / len(phrase_list) + * else: + */ + __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1648; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = (__pyx_t_13 > 0); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1649 + * e_sent_len, e_sent_start) + * if len(phrase_list) > 0: + * pair_count = 1.0 / len(phrase_list) # <<<<<<<<<<<<<< + * else: + * pair_count = 0 + */ + __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1649; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__pyx_t_13 == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1649; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_pair_count = (1.0 / __pyx_t_13); + goto __pyx_L74; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1651 + * pair_count = 1.0 / len(phrase_list) + * else: + * pair_count = 0 # <<<<<<<<<<<<<< + * for phrase2,eindexes in phrase_list: + * als2 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + */ + __pyx_v_pair_count = 0.0; + } + __pyx_L74:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1652 + * else: + * pair_count = 0 + * for phrase2,eindexes in phrase_list: # <<<<<<<<<<<<<< + * als2 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + * extracts.append((fphr, phrase2, pair_count, tuple(als2))) + */ + if (PyList_CheckExact(__pyx_v_phrase_list) || PyTuple_CheckExact(__pyx_v_phrase_list)) { + __pyx_t_15 = __pyx_v_phrase_list; __Pyx_INCREF(__pyx_t_15); __pyx_t_13 = 0; + __pyx_t_16 = NULL; + } else { + __pyx_t_13 = -1; __pyx_t_15 = PyObject_GetIter(__pyx_v_phrase_list); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_16 = Py_TYPE(__pyx_t_15)->tp_iternext; + } + for (;;) { + if (!__pyx_t_16 && PyList_CheckExact(__pyx_t_15)) { + if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_15)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_15, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_15, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_16 && PyTuple_CheckExact(__pyx_t_15)) { + if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_15)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_15, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_15, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1652; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_1 = __pyx_t_16(__pyx_t_15); + if (unlikely(!__pyx_t_1)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { + PyObject* sequence = __pyx_t_1; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_14 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_14 = PyList_GET_ITEM(sequence, 0); + __pyx_t_2 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(__pyx_t_2); + #else + __pyx_t_14 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else + { + Py_ssize_t index = -1; + __pyx_t_10 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_17 = Py_TYPE(__pyx_t_10)->tp_iternext; + index = 0; __pyx_t_14 = __pyx_t_17(__pyx_t_10); if (unlikely(!__pyx_t_14)) goto __pyx_L77_unpacking_failed; + __Pyx_GOTREF(__pyx_t_14); + index = 1; __pyx_t_2 = __pyx_t_17(__pyx_t_10); if (unlikely(!__pyx_t_2)) goto __pyx_L77_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_10), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_17 = NULL; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L78_unpacking_done; + __pyx_L77_unpacking_failed:; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_17 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1652; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L78_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_phrase2); + __pyx_v_phrase2 = __pyx_t_14; + __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_v_eindexes); + __pyx_v_eindexes = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1653 + * pair_count = 0 + * for phrase2,eindexes in phrase_list: + * als2 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) # <<<<<<<<<<<<<< + * extracts.append((fphr, phrase2, pair_count, tuple(als2))) + * + */ + __pyx_t_1 = ((PyObject *)__pyx_v_self->findexes); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->create_alignments(__pyx_v_self, __pyx_v_sent_links, __pyx_v_num_links, __pyx_t_1, __pyx_v_eindexes); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_v_als2); + __pyx_v_als2 = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1654 + * for phrase2,eindexes in phrase_list: + * als2 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + * extracts.append((fphr, phrase2, pair_count, tuple(als2))) # <<<<<<<<<<<<<< + * + * if (f_back_high == f_high and + */ + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_pair_count); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1654; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1654; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_als2); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_als2); + __Pyx_GIVEREF(__pyx_v_als2); + __pyx_t_14 = PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1654; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1654; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_fphr)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_fphr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr)); + __Pyx_INCREF(__pyx_v_phrase2); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_phrase2); + __Pyx_GIVEREF(__pyx_v_phrase2); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_t_2 = 0; + __pyx_t_14 = 0; + __pyx_t_14 = __Pyx_PyObject_Append(__pyx_v_extracts, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1654; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + goto __pyx_L69; + } + __pyx_L69:; + goto __pyx_L64; + } + __pyx_L64:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1656 + * extracts.append((fphr, phrase2, pair_count, tuple(als2))) + * + * if (f_back_high == f_high and # <<<<<<<<<<<<<< + * f_sent_len - f_high >= self.train_min_gap_size and + * ((not self.tight_phrases) or (f_links_low[f_high] != -1 and f_links_low[f_back_low] != -1))): + */ + __pyx_t_9 = (__pyx_v_f_back_high == __pyx_v_f_high); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1657 + * + * if (f_back_high == f_high and + * f_sent_len - f_high >= self.train_min_gap_size and # <<<<<<<<<<<<<< + * ((not self.tight_phrases) or (f_links_low[f_high] != -1 and f_links_low[f_back_low] != -1))): + * f_x_high = f_high+self.train_min_gap_size + */ + __pyx_t_7 = ((__pyx_v_f_sent_len - __pyx_v_f_high) >= __pyx_v_self->train_min_gap_size); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1658 + * if (f_back_high == f_high and + * f_sent_len - f_high >= self.train_min_gap_size and + * ((not self.tight_phrases) or (f_links_low[f_high] != -1 and f_links_low[f_back_low] != -1))): # <<<<<<<<<<<<<< + * f_x_high = f_high+self.train_min_gap_size + * met_constraints = 1 + */ + __pyx_t_18 = (!__pyx_v_self->tight_phrases); + if (!__pyx_t_18) { + __pyx_t_8 = ((__pyx_v_f_links_low[__pyx_v_f_high]) != -1); + if (__pyx_t_8) { + __pyx_t_20 = ((__pyx_v_f_links_low[__pyx_v_f_back_low]) != -1); + __pyx_t_19 = __pyx_t_20; + } else { + __pyx_t_19 = __pyx_t_8; + } + __pyx_t_8 = __pyx_t_19; + } else { + __pyx_t_8 = __pyx_t_18; + } + __pyx_t_18 = __pyx_t_8; + } else { + __pyx_t_18 = __pyx_t_7; + } + __pyx_t_7 = __pyx_t_18; + } else { + __pyx_t_7 = __pyx_t_9; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1659 + * f_sent_len - f_high >= self.train_min_gap_size and + * ((not self.tight_phrases) or (f_links_low[f_high] != -1 and f_links_low[f_back_low] != -1))): + * f_x_high = f_high+self.train_min_gap_size # <<<<<<<<<<<<<< + * met_constraints = 1 + * if self.tight_phrases: + */ + __pyx_v_f_x_high = (__pyx_v_f_high + __pyx_v_self->train_min_gap_size); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1660 + * ((not self.tight_phrases) or (f_links_low[f_high] != -1 and f_links_low[f_back_low] != -1))): + * f_x_high = f_high+self.train_min_gap_size + * met_constraints = 1 # <<<<<<<<<<<<<< + * if self.tight_phrases: + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: + */ + __pyx_v_met_constraints = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1661 + * f_x_high = f_high+self.train_min_gap_size + * met_constraints = 1 + * if self.tight_phrases: # <<<<<<<<<<<<<< + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: + * f_x_high = f_x_high + 1 + */ + if (__pyx_v_self->tight_phrases) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1662 + * met_constraints = 1 + * if self.tight_phrases: + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: # <<<<<<<<<<<<<< + * f_x_high = f_x_high + 1 + * if f_x_high > f_sent_len or f_x_high - f_back_low > self.train_max_initial_size: + */ + while (1) { + __pyx_t_7 = (__pyx_v_f_x_high <= __pyx_v_f_sent_len); + if (__pyx_t_7) { + __pyx_t_9 = ((__pyx_v_f_links_low[(__pyx_v_f_x_high - 1)]) == -1); + __pyx_t_18 = __pyx_t_9; + } else { + __pyx_t_18 = __pyx_t_7; + } + if (!__pyx_t_18) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1663 + * if self.tight_phrases: + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: + * f_x_high = f_x_high + 1 # <<<<<<<<<<<<<< + * if f_x_high > f_sent_len or f_x_high - f_back_low > self.train_max_initial_size: + * met_constraints = 0 + */ + __pyx_v_f_x_high = (__pyx_v_f_x_high + 1); + } + goto __pyx_L80; + } + __pyx_L80:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1664 + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: + * f_x_high = f_x_high + 1 + * if f_x_high > f_sent_len or f_x_high - f_back_low > self.train_max_initial_size: # <<<<<<<<<<<<<< + * met_constraints = 0 + * + */ + __pyx_t_18 = (__pyx_v_f_x_high > __pyx_v_f_sent_len); + if (!__pyx_t_18) { + __pyx_t_7 = ((__pyx_v_f_x_high - __pyx_v_f_back_low) > __pyx_v_self->train_max_initial_size); + __pyx_t_9 = __pyx_t_7; + } else { + __pyx_t_9 = __pyx_t_18; + } + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1665 + * f_x_high = f_x_high + 1 + * if f_x_high > f_sent_len or f_x_high - f_back_low > self.train_max_initial_size: + * met_constraints = 0 # <<<<<<<<<<<<<< + * + * if (met_constraints and + */ + __pyx_v_met_constraints = 0; + goto __pyx_L83; + } + __pyx_L83:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1667 + * met_constraints = 0 + * + * if (met_constraints and # <<<<<<<<<<<<<< + * self.find_fixpoint(f_back_low, f_x_high, + * f_links_low, f_links_high, e_links_low, e_links_high, + */ + if (__pyx_v_met_constraints) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1668 + * + * if (met_constraints and + * self.find_fixpoint(f_back_low, f_x_high, # <<<<<<<<<<<<<< + * f_links_low, f_links_high, e_links_low, e_links_high, + * e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, + */ + __pyx_t_15 = PyInt_FromLong(__pyx_v_f_x_high); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1668; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1672 + * e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, + * f_sent_len, e_sent_len, + * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< + * 1, 1, 1, 0, 1, 1, 0) and + * ((not self.tight_phrases) or f_links_low[f_x_high-1] != -1) and + */ + if (((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_back_low, __pyx_t_15, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_e_low, __pyx_v_e_high, (&__pyx_v_e_x_low), (&__pyx_v_e_x_high), (&__pyx_v_f_x_low), (&__pyx_v_f_x_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 1, 1, 1, 0, 1, 1, 0)) { + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1674 + * self.train_max_initial_size, self.train_max_initial_size, + * 1, 1, 1, 0, 1, 1, 0) and + * ((not self.tight_phrases) or f_links_low[f_x_high-1] != -1) and # <<<<<<<<<<<<<< + * self.find_fixpoint(f_high, f_x_high, + * f_links_low, f_links_high, e_links_low, e_links_high, + */ + __pyx_t_9 = (!__pyx_v_self->tight_phrases); + if (!__pyx_t_9) { + __pyx_t_18 = ((__pyx_v_f_links_low[(__pyx_v_f_x_high - 1)]) != -1); + __pyx_t_7 = __pyx_t_18; + } else { + __pyx_t_7 = __pyx_t_9; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1675 + * 1, 1, 1, 0, 1, 1, 0) and + * ((not self.tight_phrases) or f_links_low[f_x_high-1] != -1) and + * self.find_fixpoint(f_high, f_x_high, # <<<<<<<<<<<<<< + * f_links_low, f_links_high, e_links_low, e_links_high, + * -1, -1, e_gap_low+gap_start+num_gaps, e_gap_high+gap_start+num_gaps, + */ + __pyx_t_14 = PyInt_FromLong(__pyx_v_f_x_high); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1675; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1680 + * f_gap_low+gap_start+num_gaps, f_gap_high+gap_start+num_gaps, + * f_sent_len, e_sent_len, + * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< + * 0, 0, 0, 0, 0, 0, 0)): + * fphr_arr._clear() + */ + __pyx_t_9 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_high, __pyx_t_14, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, -1, -1, ((__pyx_v_e_gap_low + __pyx_v_gap_start) + __pyx_v_num_gaps), ((__pyx_v_e_gap_high + __pyx_v_gap_start) + __pyx_v_num_gaps), ((__pyx_v_f_gap_low + __pyx_v_gap_start) + __pyx_v_num_gaps), ((__pyx_v_f_gap_high + __pyx_v_gap_start) + __pyx_v_num_gaps), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 0, 0, 0, 0, 0, 0, 0); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } else { + __pyx_t_9 = __pyx_t_7; + } + __pyx_t_7 = __pyx_t_9; + } else { + __pyx_t_7 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_back_low, __pyx_t_15, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_e_low, __pyx_v_e_high, (&__pyx_v_e_x_low), (&__pyx_v_e_x_high), (&__pyx_v_f_x_low), (&__pyx_v_f_x_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 1, 1, 1, 0, 1, 1, 0); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } + __pyx_t_9 = __pyx_t_7; + } else { + __pyx_t_9 = __pyx_v_met_constraints; + } + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1682 + * self.train_max_initial_size, self.train_max_initial_size, + * 0, 0, 0, 0, 0, 0, 0)): + * fphr_arr._clear() # <<<<<<<<<<<<<< + * i = 1 + * self.findexes.reset() + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_clear(__pyx_v_fphr_arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1683 + * 0, 0, 0, 0, 0, 0, 0)): + * fphr_arr._clear() + * i = 1 # <<<<<<<<<<<<<< + * self.findexes.reset() + * if f_back_low < f_low: + */ + __pyx_v_i = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1684 + * fphr_arr._clear() + * i = 1 + * self.findexes.reset() # <<<<<<<<<<<<<< + * if f_back_low < f_low: + * fphr_arr._append(sym_setindex(self.category, i)) + */ + __pyx_t_15 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__reset); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1684; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_14 = PyObject_Call(__pyx_t_15, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1684; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1685 + * i = 1 + * self.findexes.reset() + * if f_back_low < f_low: # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 + */ + __pyx_t_9 = (__pyx_v_f_back_low < __pyx_v_f_low); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1686 + * self.findexes.reset() + * if f_back_low < f_low: + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * i = i+1 + * self.findexes.append(sym_setindex(self.category, i)) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1687 + * if f_back_low < f_low: + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 # <<<<<<<<<<<<<< + * self.findexes.append(sym_setindex(self.category, i)) + * self.findexes.extend(self.findexes1) + */ + __pyx_v_i = (__pyx_v_i + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1688 + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 + * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: + */ + __pyx_t_14 = PyInt_FromLong(__pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1688; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_14); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1688; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + goto __pyx_L85; + } + __pyx_L85:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1689 + * i = i+1 + * self.findexes.append(sym_setindex(self.category, i)) + * self.findexes.extend(self.findexes1) # <<<<<<<<<<<<<< + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): + */ + __pyx_t_15 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__extend); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1689; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1689; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_INCREF(((PyObject *)__pyx_v_self->findexes1)); + PyTuple_SET_ITEM(__pyx_t_14, 0, ((PyObject *)__pyx_v_self->findexes1)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->findexes1)); + __pyx_t_1 = PyObject_Call(__pyx_t_15, ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1689; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1690 + * self.findexes.append(sym_setindex(self.category, i)) + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: # <<<<<<<<<<<<<< + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) + */ + __pyx_t_3 = __pyx_v_phrase->n; + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1691 + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i + 1 + */ + __pyx_t_4 = __pyx_f_3_sa_sym_isvar((__pyx_v_phrase->syms[__pyx_v_j])); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1692 + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * i = i + 1 + * else: + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1693 + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i + 1 # <<<<<<<<<<<<<< + * else: + * fphr_arr._append(phrase.syms[j]) + */ + __pyx_v_i = (__pyx_v_i + 1); + goto __pyx_L88; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1695 + * i = i + 1 + * else: + * fphr_arr._append(phrase.syms[j]) # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, (__pyx_v_phrase->syms[__pyx_v_j])); + } + __pyx_L88:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1696 + * else: + * fphr_arr._append(phrase.syms[j]) + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * self.findexes.append(sym_setindex(self.category, i)) + * fphr = Phrase(fphr_arr) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1697 + * fphr_arr._append(phrase.syms[j]) + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * fphr = Phrase(fphr_arr) + * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low+gap_start, e_gap_high+gap_start, e_links_low, num_gaps+1, + */ + __pyx_t_1 = PyInt_FromLong(__pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1697; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_14 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1697; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1698 + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) + * fphr = Phrase(fphr_arr) # <<<<<<<<<<<<<< + * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low+gap_start, e_gap_high+gap_start, e_links_low, num_gaps+1, + * f_x_low, f_x_high, f_gap_low+gap_start, f_gap_high+gap_start, f_links_low, + */ + __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1698; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_INCREF(((PyObject *)__pyx_v_fphr_arr)); + PyTuple_SET_ITEM(__pyx_t_14, 0, ((PyObject *)__pyx_v_fphr_arr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr_arr)); + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_Phrase)), ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1698; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_fphr)); + __pyx_v_fphr = ((struct __pyx_obj_3_sa_Phrase *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1701 + * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low+gap_start, e_gap_high+gap_start, e_links_low, num_gaps+1, + * f_x_low, f_x_high, f_gap_low+gap_start, f_gap_high+gap_start, f_links_low, + * matching.sent_id, e_sent_len, e_sent_start) # <<<<<<<<<<<<<< + * if len(phrase_list) > 0: + * pair_count = 1.0 / len(phrase_list) + */ + __pyx_t_1 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->extract_phrases(__pyx_v_self, __pyx_v_e_x_low, __pyx_v_e_x_high, (__pyx_v_e_gap_low + __pyx_v_gap_start), (__pyx_v_e_gap_high + __pyx_v_gap_start), __pyx_v_e_links_low, (__pyx_v_num_gaps + 1), __pyx_v_f_x_low, __pyx_v_f_x_high, (__pyx_v_f_gap_low + __pyx_v_gap_start), (__pyx_v_f_gap_high + __pyx_v_gap_start), __pyx_v_f_links_low, __pyx_v_matching->sent_id, __pyx_v_e_sent_len, __pyx_v_e_sent_start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1699; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_phrase_list); + __pyx_v_phrase_list = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1702 + * f_x_low, f_x_high, f_gap_low+gap_start, f_gap_high+gap_start, f_links_low, + * matching.sent_id, e_sent_len, e_sent_start) + * if len(phrase_list) > 0: # <<<<<<<<<<<<<< + * pair_count = 1.0 / len(phrase_list) + * else: + */ + __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1702; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = (__pyx_t_13 > 0); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1703 + * matching.sent_id, e_sent_len, e_sent_start) + * if len(phrase_list) > 0: + * pair_count = 1.0 / len(phrase_list) # <<<<<<<<<<<<<< + * else: + * pair_count = 0 + */ + __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1703; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__pyx_t_13 == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1703; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_pair_count = (1.0 / __pyx_t_13); + goto __pyx_L89; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1705 + * pair_count = 1.0 / len(phrase_list) + * else: + * pair_count = 0 # <<<<<<<<<<<<<< + * for phrase2, eindexes in phrase_list: + * als3 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + */ + __pyx_v_pair_count = 0.0; + } + __pyx_L89:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1706 + * else: + * pair_count = 0 + * for phrase2, eindexes in phrase_list: # <<<<<<<<<<<<<< + * als3 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + * extracts.append((fphr, phrase2, pair_count, tuple(als3))) + */ + if (PyList_CheckExact(__pyx_v_phrase_list) || PyTuple_CheckExact(__pyx_v_phrase_list)) { + __pyx_t_1 = __pyx_v_phrase_list; __Pyx_INCREF(__pyx_t_1); __pyx_t_13 = 0; + __pyx_t_16 = NULL; + } else { + __pyx_t_13 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_phrase_list); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1706; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_16 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_16 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_14 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_13); __Pyx_INCREF(__pyx_t_14); __pyx_t_13++; + #else + __pyx_t_14 = PySequence_ITEM(__pyx_t_1, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1706; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_16 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_14 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_13); __Pyx_INCREF(__pyx_t_14); __pyx_t_13++; + #else + __pyx_t_14 = PySequence_ITEM(__pyx_t_1, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1706; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_14 = __pyx_t_16(__pyx_t_1); + if (unlikely(!__pyx_t_14)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1706; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_14); + } + if ((likely(PyTuple_CheckExact(__pyx_t_14))) || (PyList_CheckExact(__pyx_t_14))) { + PyObject* sequence = __pyx_t_14; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1706; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_15 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_15 = PyList_GET_ITEM(sequence, 0); + __pyx_t_2 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_15); + __Pyx_INCREF(__pyx_t_2); + #else + __pyx_t_15 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1706; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1706; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } else + { + Py_ssize_t index = -1; + __pyx_t_10 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1706; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_17 = Py_TYPE(__pyx_t_10)->tp_iternext; + index = 0; __pyx_t_15 = __pyx_t_17(__pyx_t_10); if (unlikely(!__pyx_t_15)) goto __pyx_L92_unpacking_failed; + __Pyx_GOTREF(__pyx_t_15); + index = 1; __pyx_t_2 = __pyx_t_17(__pyx_t_10); if (unlikely(!__pyx_t_2)) goto __pyx_L92_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_10), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1706; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_17 = NULL; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L93_unpacking_done; + __pyx_L92_unpacking_failed:; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_17 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1706; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L93_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_phrase2); + __pyx_v_phrase2 = __pyx_t_15; + __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_v_eindexes); + __pyx_v_eindexes = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1707 + * pair_count = 0 + * for phrase2, eindexes in phrase_list: + * als3 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) # <<<<<<<<<<<<<< + * extracts.append((fphr, phrase2, pair_count, tuple(als3))) + * if (num_gaps < self.max_nonterminals - 1 and + */ + __pyx_t_14 = ((PyObject *)__pyx_v_self->findexes); + __Pyx_INCREF(__pyx_t_14); + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->create_alignments(__pyx_v_self, __pyx_v_sent_links, __pyx_v_num_links, __pyx_t_14, __pyx_v_eindexes); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1707; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_v_als3); + __pyx_v_als3 = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1708 + * for phrase2, eindexes in phrase_list: + * als3 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + * extracts.append((fphr, phrase2, pair_count, tuple(als3))) # <<<<<<<<<<<<<< + * if (num_gaps < self.max_nonterminals - 1 and + * phrase_len+1 < self.max_length and + */ + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_pair_count); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_INCREF(__pyx_v_als3); + PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_v_als3); + __Pyx_GIVEREF(__pyx_v_als3); + __pyx_t_15 = PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), ((PyObject *)__pyx_t_14), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; + __pyx_t_14 = PyTuple_New(4); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_INCREF(((PyObject *)__pyx_v_fphr)); + PyTuple_SET_ITEM(__pyx_t_14, 0, ((PyObject *)__pyx_v_fphr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr)); + __Pyx_INCREF(__pyx_v_phrase2); + PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_v_phrase2); + __Pyx_GIVEREF(__pyx_v_phrase2); + PyTuple_SET_ITEM(__pyx_t_14, 2, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_14, 3, __pyx_t_15); + __Pyx_GIVEREF(__pyx_t_15); + __pyx_t_2 = 0; + __pyx_t_15 = 0; + __pyx_t_15 = __Pyx_PyObject_Append(__pyx_v_extracts, ((PyObject *)__pyx_t_14)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(((PyObject *)__pyx_t_14)); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L84; + } + __pyx_L84:; + goto __pyx_L79; + } + __pyx_L79:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1709 + * als3 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + * extracts.append((fphr, phrase2, pair_count, tuple(als3))) + * if (num_gaps < self.max_nonterminals - 1 and # <<<<<<<<<<<<<< + * phrase_len+1 < self.max_length and + * f_back_high == f_high and + */ + __pyx_t_9 = (__pyx_v_num_gaps < (__pyx_v_self->max_nonterminals - 1)); + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1710 + * extracts.append((fphr, phrase2, pair_count, tuple(als3))) + * if (num_gaps < self.max_nonterminals - 1 and + * phrase_len+1 < self.max_length and # <<<<<<<<<<<<<< + * f_back_high == f_high and + * f_back_low == f_low and + */ + __pyx_t_7 = ((__pyx_v_phrase_len + 1) < __pyx_v_self->max_length); + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1711 + * if (num_gaps < self.max_nonterminals - 1 and + * phrase_len+1 < self.max_length and + * f_back_high == f_high and # <<<<<<<<<<<<<< + * f_back_low == f_low and + * f_back_high - f_back_low + (2*self.train_min_gap_size) <= self.train_max_initial_size and + */ + __pyx_t_18 = (__pyx_v_f_back_high == __pyx_v_f_high); + if (__pyx_t_18) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1712 + * phrase_len+1 < self.max_length and + * f_back_high == f_high and + * f_back_low == f_low and # <<<<<<<<<<<<<< + * f_back_high - f_back_low + (2*self.train_min_gap_size) <= self.train_max_initial_size and + * f_low >= self.train_min_gap_size and + */ + __pyx_t_8 = (__pyx_v_f_back_low == __pyx_v_f_low); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1713 + * f_back_high == f_high and + * f_back_low == f_low and + * f_back_high - f_back_low + (2*self.train_min_gap_size) <= self.train_max_initial_size and # <<<<<<<<<<<<<< + * f_low >= self.train_min_gap_size and + * f_high <= f_sent_len - self.train_min_gap_size and + */ + __pyx_t_19 = (((__pyx_v_f_back_high - __pyx_v_f_back_low) + (2 * __pyx_v_self->train_min_gap_size)) <= __pyx_v_self->train_max_initial_size); + if (__pyx_t_19) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1714 + * f_back_low == f_low and + * f_back_high - f_back_low + (2*self.train_min_gap_size) <= self.train_max_initial_size and + * f_low >= self.train_min_gap_size and # <<<<<<<<<<<<<< + * f_high <= f_sent_len - self.train_min_gap_size and + * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_high] != -1))): + */ + __pyx_t_20 = (__pyx_v_f_low >= __pyx_v_self->train_min_gap_size); + if (__pyx_t_20) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1715 + * f_back_high - f_back_low + (2*self.train_min_gap_size) <= self.train_max_initial_size and + * f_low >= self.train_min_gap_size and + * f_high <= f_sent_len - self.train_min_gap_size and # <<<<<<<<<<<<<< + * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_high] != -1))): + * + */ + __pyx_t_21 = (__pyx_v_f_high <= (__pyx_v_f_sent_len - __pyx_v_self->train_min_gap_size)); + if (__pyx_t_21) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1716 + * f_low >= self.train_min_gap_size and + * f_high <= f_sent_len - self.train_min_gap_size and + * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_high] != -1))): # <<<<<<<<<<<<<< + * + * met_constraints = 1 + */ + __pyx_t_22 = (!__pyx_v_self->tight_phrases); + if (!__pyx_t_22) { + __pyx_t_23 = ((__pyx_v_f_links_low[(__pyx_v_f_low - 1)]) != -1); + if (__pyx_t_23) { + __pyx_t_24 = ((__pyx_v_f_links_low[__pyx_v_f_high]) != -1); + __pyx_t_25 = __pyx_t_24; + } else { + __pyx_t_25 = __pyx_t_23; + } + __pyx_t_23 = __pyx_t_25; + } else { + __pyx_t_23 = __pyx_t_22; + } + __pyx_t_22 = __pyx_t_23; + } else { + __pyx_t_22 = __pyx_t_21; + } + __pyx_t_21 = __pyx_t_22; + } else { + __pyx_t_21 = __pyx_t_20; + } + __pyx_t_20 = __pyx_t_21; + } else { + __pyx_t_20 = __pyx_t_19; + } + __pyx_t_19 = __pyx_t_20; + } else { + __pyx_t_19 = __pyx_t_8; + } + __pyx_t_8 = __pyx_t_19; + } else { + __pyx_t_8 = __pyx_t_18; + } + __pyx_t_18 = __pyx_t_8; + } else { + __pyx_t_18 = __pyx_t_7; + } + __pyx_t_7 = __pyx_t_18; + } else { + __pyx_t_7 = __pyx_t_9; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1718 + * ((not self.tight_phrases) or (f_links_low[f_low-1] != -1 and f_links_low[f_high] != -1))): + * + * met_constraints = 1 # <<<<<<<<<<<<<< + * f_x_low = f_low-self.train_min_gap_size + * if self.tight_phrases: + */ + __pyx_v_met_constraints = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1719 + * + * met_constraints = 1 + * f_x_low = f_low-self.train_min_gap_size # <<<<<<<<<<<<<< + * if self.tight_phrases: + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: + */ + __pyx_v_f_x_low = (__pyx_v_f_low - __pyx_v_self->train_min_gap_size); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1720 + * met_constraints = 1 + * f_x_low = f_low-self.train_min_gap_size + * if self.tight_phrases: # <<<<<<<<<<<<<< + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: + * f_x_low = f_x_low - 1 + */ + if (__pyx_v_self->tight_phrases) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1721 + * f_x_low = f_low-self.train_min_gap_size + * if self.tight_phrases: + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: # <<<<<<<<<<<<<< + * f_x_low = f_x_low - 1 + * if f_x_low < 0: + */ + while (1) { + __pyx_t_7 = (__pyx_v_f_x_low >= 0); + if (__pyx_t_7) { + __pyx_t_9 = ((__pyx_v_f_links_low[__pyx_v_f_x_low]) == -1); + __pyx_t_18 = __pyx_t_9; + } else { + __pyx_t_18 = __pyx_t_7; + } + if (!__pyx_t_18) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1722 + * if self.tight_phrases: + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: + * f_x_low = f_x_low - 1 # <<<<<<<<<<<<<< + * if f_x_low < 0: + * met_constraints = 0 + */ + __pyx_v_f_x_low = (__pyx_v_f_x_low - 1); + } + goto __pyx_L95; + } + __pyx_L95:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1723 + * while f_x_low >= 0 and f_links_low[f_x_low] == -1: + * f_x_low = f_x_low - 1 + * if f_x_low < 0: # <<<<<<<<<<<<<< + * met_constraints = 0 + * + */ + __pyx_t_18 = (__pyx_v_f_x_low < 0); + if (__pyx_t_18) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1724 + * f_x_low = f_x_low - 1 + * if f_x_low < 0: + * met_constraints = 0 # <<<<<<<<<<<<<< + * + * f_x_high = f_high+self.train_min_gap_size + */ + __pyx_v_met_constraints = 0; + goto __pyx_L98; + } + __pyx_L98:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1726 + * met_constraints = 0 + * + * f_x_high = f_high+self.train_min_gap_size # <<<<<<<<<<<<<< + * if self.tight_phrases: + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: + */ + __pyx_v_f_x_high = (__pyx_v_f_high + __pyx_v_self->train_min_gap_size); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1727 + * + * f_x_high = f_high+self.train_min_gap_size + * if self.tight_phrases: # <<<<<<<<<<<<<< + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: + * f_x_high = f_x_high + 1 + */ + if (__pyx_v_self->tight_phrases) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1728 + * f_x_high = f_high+self.train_min_gap_size + * if self.tight_phrases: + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: # <<<<<<<<<<<<<< + * f_x_high = f_x_high + 1 + * if f_x_high > f_sent_len or f_x_high - f_x_low > self.train_max_initial_size: + */ + while (1) { + __pyx_t_18 = (__pyx_v_f_x_high <= __pyx_v_f_sent_len); + if (__pyx_t_18) { + __pyx_t_7 = ((__pyx_v_f_links_low[(__pyx_v_f_x_high - 1)]) == -1); + __pyx_t_9 = __pyx_t_7; + } else { + __pyx_t_9 = __pyx_t_18; + } + if (!__pyx_t_9) break; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1729 + * if self.tight_phrases: + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: + * f_x_high = f_x_high + 1 # <<<<<<<<<<<<<< + * if f_x_high > f_sent_len or f_x_high - f_x_low > self.train_max_initial_size: + * met_constraints = 0 + */ + __pyx_v_f_x_high = (__pyx_v_f_x_high + 1); + } + goto __pyx_L99; + } + __pyx_L99:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1730 + * while f_x_high <= f_sent_len and f_links_low[f_x_high-1] == -1: + * f_x_high = f_x_high + 1 + * if f_x_high > f_sent_len or f_x_high - f_x_low > self.train_max_initial_size: # <<<<<<<<<<<<<< + * met_constraints = 0 + * + */ + __pyx_t_9 = (__pyx_v_f_x_high > __pyx_v_f_sent_len); + if (!__pyx_t_9) { + __pyx_t_18 = ((__pyx_v_f_x_high - __pyx_v_f_x_low) > __pyx_v_self->train_max_initial_size); + __pyx_t_7 = __pyx_t_18; + } else { + __pyx_t_7 = __pyx_t_9; + } + if (__pyx_t_7) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1731 + * f_x_high = f_x_high + 1 + * if f_x_high > f_sent_len or f_x_high - f_x_low > self.train_max_initial_size: + * met_constraints = 0 # <<<<<<<<<<<<<< + * + * if (met_constraints and + */ + __pyx_v_met_constraints = 0; + goto __pyx_L102; + } + __pyx_L102:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1733 + * met_constraints = 0 + * + * if (met_constraints and # <<<<<<<<<<<<<< + * self.find_fixpoint(f_x_low, f_x_high, + * f_links_low, f_links_high, e_links_low, e_links_high, + */ + if (__pyx_v_met_constraints) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1734 + * + * if (met_constraints and + * self.find_fixpoint(f_x_low, f_x_high, # <<<<<<<<<<<<<< + * f_links_low, f_links_high, e_links_low, e_links_high, + * e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_f_x_high); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1734; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1738 + * e_low, e_high, &e_x_low, &e_x_high, &f_x_low, &f_x_high, + * f_sent_len, e_sent_len, + * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< + * 1, 1, 2, 1, 1, 1, 1) and + * ((not self.tight_phrases) or (f_links_low[f_x_low] != -1 and f_links_low[f_x_high-1] != -1)) and + */ + if (((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_x_low, __pyx_t_1, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_e_low, __pyx_v_e_high, (&__pyx_v_e_x_low), (&__pyx_v_e_x_high), (&__pyx_v_f_x_low), (&__pyx_v_f_x_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 1, 1, 2, 1, 1, 1, 1)) { + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1740 + * self.train_max_initial_size, self.train_max_initial_size, + * 1, 1, 2, 1, 1, 1, 1) and + * ((not self.tight_phrases) or (f_links_low[f_x_low] != -1 and f_links_low[f_x_high-1] != -1)) and # <<<<<<<<<<<<<< + * self.find_fixpoint(f_x_low, f_low, + * f_links_low, f_links_high, e_links_low, e_links_high, + */ + __pyx_t_7 = (!__pyx_v_self->tight_phrases); + if (!__pyx_t_7) { + __pyx_t_9 = ((__pyx_v_f_links_low[__pyx_v_f_x_low]) != -1); + if (__pyx_t_9) { + __pyx_t_18 = ((__pyx_v_f_links_low[(__pyx_v_f_x_high - 1)]) != -1); + __pyx_t_8 = __pyx_t_18; + } else { + __pyx_t_8 = __pyx_t_9; + } + __pyx_t_9 = __pyx_t_8; + } else { + __pyx_t_9 = __pyx_t_7; + } + if (__pyx_t_9) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1741 + * 1, 1, 2, 1, 1, 1, 1) and + * ((not self.tight_phrases) or (f_links_low[f_x_low] != -1 and f_links_low[f_x_high-1] != -1)) and + * self.find_fixpoint(f_x_low, f_low, # <<<<<<<<<<<<<< + * f_links_low, f_links_high, e_links_low, e_links_high, + * -1, -1, e_gap_low, e_gap_high, f_gap_low, f_gap_high, + */ + __pyx_t_15 = PyInt_FromLong(__pyx_v_f_low); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1741; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1745 + * -1, -1, e_gap_low, e_gap_high, f_gap_low, f_gap_high, + * f_sent_len, e_sent_len, + * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< + * 0, 0, 0, 0, 0, 0, 0) and + * self.find_fixpoint(f_high, f_x_high, + */ + __pyx_t_3 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_x_low, __pyx_t_15, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, -1, -1, __pyx_v_e_gap_low, __pyx_v_e_gap_high, __pyx_v_f_gap_low, __pyx_v_f_gap_high, __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 0, 0, 0, 0, 0, 0, 0); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (__pyx_t_3) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1747 + * self.train_max_initial_size, self.train_max_initial_size, + * 0, 0, 0, 0, 0, 0, 0) and + * self.find_fixpoint(f_high, f_x_high, # <<<<<<<<<<<<<< + * f_links_low, f_links_high, e_links_low, e_links_high, + * -1, -1, e_gap_low+1+num_gaps, e_gap_high+1+num_gaps, + */ + __pyx_t_15 = PyInt_FromLong(__pyx_v_f_x_high); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1747; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1752 + * f_gap_low+1+num_gaps, f_gap_high+1+num_gaps, + * f_sent_len, e_sent_len, + * self.train_max_initial_size, self.train_max_initial_size, # <<<<<<<<<<<<<< + * 0, 0, 0, 0, 0, 0, 0)): + * fphr_arr._clear() + */ + __pyx_t_4 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_high, __pyx_t_15, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, -1, -1, ((__pyx_v_e_gap_low + 1) + __pyx_v_num_gaps), ((__pyx_v_e_gap_high + 1) + __pyx_v_num_gaps), ((__pyx_v_f_gap_low + 1) + __pyx_v_num_gaps), ((__pyx_v_f_gap_high + 1) + __pyx_v_num_gaps), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 0, 0, 0, 0, 0, 0, 0); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_7 = __pyx_t_4; + } else { + __pyx_t_7 = __pyx_t_3; + } + __pyx_t_8 = __pyx_t_7; + } else { + __pyx_t_8 = __pyx_t_9; + } + __pyx_t_9 = __pyx_t_8; + } else { + __pyx_t_9 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->find_fixpoint(__pyx_v_self, __pyx_v_f_x_low, __pyx_t_1, __pyx_v_f_links_low, __pyx_v_f_links_high, __pyx_v_e_links_low, __pyx_v_e_links_high, __pyx_v_e_low, __pyx_v_e_high, (&__pyx_v_e_x_low), (&__pyx_v_e_x_high), (&__pyx_v_f_x_low), (&__pyx_v_f_x_high), __pyx_v_f_sent_len, __pyx_v_e_sent_len, __pyx_v_self->train_max_initial_size, __pyx_v_self->train_max_initial_size, 1, 1, 2, 1, 1, 1, 1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __pyx_t_8 = __pyx_t_9; + } else { + __pyx_t_8 = __pyx_v_met_constraints; + } + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1754 + * self.train_max_initial_size, self.train_max_initial_size, + * 0, 0, 0, 0, 0, 0, 0)): + * fphr_arr._clear() # <<<<<<<<<<<<<< + * i = 1 + * self.findexes.reset() + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_clear(__pyx_v_fphr_arr); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1755 + * 0, 0, 0, 0, 0, 0, 0)): + * fphr_arr._clear() + * i = 1 # <<<<<<<<<<<<<< + * self.findexes.reset() + * self.findexes.append(sym_setindex(self.category, i)) + */ + __pyx_v_i = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1756 + * fphr_arr._clear() + * i = 1 + * self.findexes.reset() # <<<<<<<<<<<<<< + * self.findexes.append(sym_setindex(self.category, i)) + * fphr_arr._append(sym_setindex(self.category, i)) + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__reset); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1756; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_15 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1756; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1757 + * i = 1 + * self.findexes.reset() + * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 + */ + __pyx_t_15 = PyInt_FromLong(__pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1757; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_1 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_15); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1757; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1758 + * self.findexes.reset() + * self.findexes.append(sym_setindex(self.category, i)) + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * i = i+1 + * self.findexes.extend(self.findexes1) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1759 + * self.findexes.append(sym_setindex(self.category, i)) + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 # <<<<<<<<<<<<<< + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: + */ + __pyx_v_i = (__pyx_v_i + 1); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1760 + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i+1 + * self.findexes.extend(self.findexes1) # <<<<<<<<<<<<<< + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): + */ + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->findexes), __pyx_n_s__extend); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1760; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1760; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(((PyObject *)__pyx_v_self->findexes1)); + PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)__pyx_v_self->findexes1)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->findexes1)); + __pyx_t_14 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1760; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1761 + * i = i+1 + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: # <<<<<<<<<<<<<< + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) + */ + __pyx_t_3 = __pyx_v_phrase->n; + for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_3; __pyx_v_j++) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1762 + * self.findexes.extend(self.findexes1) + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i + 1 + */ + __pyx_t_4 = __pyx_f_3_sa_sym_isvar((__pyx_v_phrase->syms[__pyx_v_j])); + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1763 + * for j from 0 <= j < phrase.n: + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * i = i + 1 + * else: + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1764 + * if sym_isvar(phrase.syms[j]): + * fphr_arr._append(sym_setindex(self.category, i)) + * i = i + 1 # <<<<<<<<<<<<<< + * else: + * fphr_arr._append(phrase.syms[j]) + */ + __pyx_v_i = (__pyx_v_i + 1); + goto __pyx_L106; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1766 + * i = i + 1 + * else: + * fphr_arr._append(phrase.syms[j]) # <<<<<<<<<<<<<< + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, (__pyx_v_phrase->syms[__pyx_v_j])); + } + __pyx_L106:; + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1767 + * else: + * fphr_arr._append(phrase.syms[j]) + * fphr_arr._append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * self.findexes.append(sym_setindex(self.category, i)) + * fphr = Phrase(fphr_arr) + */ + ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_fphr_arr->__pyx_vtab)->_append(__pyx_v_fphr_arr, __pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1768 + * fphr_arr._append(phrase.syms[j]) + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) # <<<<<<<<<<<<<< + * fphr = Phrase(fphr_arr) + * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+2, + */ + __pyx_t_14 = PyInt_FromLong(__pyx_f_3_sa_sym_setindex(__pyx_v_self->category, __pyx_v_i)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1768; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->findexes), __pyx_t_14); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1768; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1769 + * fphr_arr._append(sym_setindex(self.category, i)) + * self.findexes.append(sym_setindex(self.category, i)) + * fphr = Phrase(fphr_arr) # <<<<<<<<<<<<<< + * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+2, + * f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, + */ + __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1769; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(((PyObject *)__pyx_v_fphr_arr)); + PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)__pyx_v_fphr_arr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr_arr)); + __pyx_t_14 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_Phrase)), ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1769; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __Pyx_DECREF(((PyObject *)__pyx_v_fphr)); + __pyx_v_fphr = ((struct __pyx_obj_3_sa_Phrase *)__pyx_t_14); + __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1772 + * phrase_list = self.extract_phrases(e_x_low, e_x_high, e_gap_low, e_gap_high, e_links_low, num_gaps+2, + * f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, + * matching.sent_id, e_sent_len, e_sent_start) # <<<<<<<<<<<<<< + * if len(phrase_list) > 0: + * pair_count = 1.0 / len(phrase_list) + */ + __pyx_t_14 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->extract_phrases(__pyx_v_self, __pyx_v_e_x_low, __pyx_v_e_x_high, __pyx_v_e_gap_low, __pyx_v_e_gap_high, __pyx_v_e_links_low, (__pyx_v_num_gaps + 2), __pyx_v_f_x_low, __pyx_v_f_x_high, __pyx_v_f_gap_low, __pyx_v_f_gap_high, __pyx_v_f_links_low, __pyx_v_matching->sent_id, __pyx_v_e_sent_len, __pyx_v_e_sent_start); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1770; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __Pyx_XDECREF(__pyx_v_phrase_list); + __pyx_v_phrase_list = __pyx_t_14; + __pyx_t_14 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1773 + * f_x_low, f_x_high, f_gap_low, f_gap_high, f_links_low, + * matching.sent_id, e_sent_len, e_sent_start) + * if len(phrase_list) > 0: # <<<<<<<<<<<<<< + * pair_count = 1.0 / len(phrase_list) + * else: + */ + __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1773; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = (__pyx_t_13 > 0); + if (__pyx_t_8) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1774 + * matching.sent_id, e_sent_len, e_sent_start) + * if len(phrase_list) > 0: + * pair_count = 1.0 / len(phrase_list) # <<<<<<<<<<<<<< + * else: + * pair_count = 0 + */ + __pyx_t_13 = PyObject_Length(__pyx_v_phrase_list); if (unlikely(__pyx_t_13 == -1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1774; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__pyx_t_13 == 0)) { + PyErr_Format(PyExc_ZeroDivisionError, "float division"); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1774; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_pair_count = (1.0 / __pyx_t_13); + goto __pyx_L107; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1776 + * pair_count = 1.0 / len(phrase_list) + * else: + * pair_count = 0 # <<<<<<<<<<<<<< + * for phrase2, eindexes in phrase_list: + * als4 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + */ + __pyx_v_pair_count = 0.0; + } + __pyx_L107:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1777 + * else: + * pair_count = 0 + * for phrase2, eindexes in phrase_list: # <<<<<<<<<<<<<< + * als4 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + * extracts.append((fphr, phrase2, pair_count, tuple(als4))) + */ + if (PyList_CheckExact(__pyx_v_phrase_list) || PyTuple_CheckExact(__pyx_v_phrase_list)) { + __pyx_t_14 = __pyx_v_phrase_list; __Pyx_INCREF(__pyx_t_14); __pyx_t_13 = 0; + __pyx_t_16 = NULL; + } else { + __pyx_t_13 = -1; __pyx_t_14 = PyObject_GetIter(__pyx_v_phrase_list); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_16 = Py_TYPE(__pyx_t_14)->tp_iternext; + } + for (;;) { + if (!__pyx_t_16 && PyList_CheckExact(__pyx_t_14)) { + if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_14)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_15 = PyList_GET_ITEM(__pyx_t_14, __pyx_t_13); __Pyx_INCREF(__pyx_t_15); __pyx_t_13++; + #else + __pyx_t_15 = PySequence_ITEM(__pyx_t_14, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_16 && PyTuple_CheckExact(__pyx_t_14)) { + if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_14)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_15 = PyTuple_GET_ITEM(__pyx_t_14, __pyx_t_13); __Pyx_INCREF(__pyx_t_15); __pyx_t_13++; + #else + __pyx_t_15 = PySequence_ITEM(__pyx_t_14, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_15 = __pyx_t_16(__pyx_t_14); + if (unlikely(!__pyx_t_15)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_15); + } + if ((likely(PyTuple_CheckExact(__pyx_t_15))) || (PyList_CheckExact(__pyx_t_15))) { + PyObject* sequence = __pyx_t_15; + #if CYTHON_COMPILING_IN_CPYTHON + Py_ssize_t size = Py_SIZE(sequence); + #else + Py_ssize_t size = PySequence_Size(sequence); + #endif + if (unlikely(size != 2)) { + if (size > 2) __Pyx_RaiseTooManyValuesError(2); + else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + #if CYTHON_COMPILING_IN_CPYTHON + if (likely(PyTuple_CheckExact(sequence))) { + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); + } else { + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_2 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_2); + #else + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } else + { + Py_ssize_t index = -1; + __pyx_t_10 = PyObject_GetIter(__pyx_t_15); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_17 = Py_TYPE(__pyx_t_10)->tp_iternext; + index = 0; __pyx_t_1 = __pyx_t_17(__pyx_t_10); if (unlikely(!__pyx_t_1)) goto __pyx_L110_unpacking_failed; + __Pyx_GOTREF(__pyx_t_1); + index = 1; __pyx_t_2 = __pyx_t_17(__pyx_t_10); if (unlikely(!__pyx_t_2)) goto __pyx_L110_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_10), 2) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_17 = NULL; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L111_unpacking_done; + __pyx_L110_unpacking_failed:; + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __pyx_t_17 = NULL; + if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L111_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_phrase2); + __pyx_v_phrase2 = __pyx_t_1; + __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_v_eindexes); + __pyx_v_eindexes = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1778 + * pair_count = 0 + * for phrase2, eindexes in phrase_list: + * als4 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) # <<<<<<<<<<<<<< + * extracts.append((fphr, phrase2, pair_count, tuple(als4))) + * else: + */ + __pyx_t_15 = ((PyObject *)__pyx_v_self->findexes); + __Pyx_INCREF(__pyx_t_15); + __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory *)__pyx_v_self->__pyx_vtab)->create_alignments(__pyx_v_self, __pyx_v_sent_links, __pyx_v_num_links, __pyx_t_15, __pyx_v_eindexes); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1778; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_v_als4); + __pyx_v_als4 = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1779 + * for phrase2, eindexes in phrase_list: + * als4 = self.create_alignments(sent_links,num_links,self.findexes,eindexes) + * extracts.append((fphr, phrase2, pair_count, tuple(als4))) # <<<<<<<<<<<<<< + * else: + * reason_for_failure = "Unable to extract basic phrase" + */ + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_pair_count); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1779; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1779; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(__pyx_v_als4); + PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_als4); + __Pyx_GIVEREF(__pyx_v_als4); + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyTuple_Type))), ((PyObject *)__pyx_t_15), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1779; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __pyx_t_15 = PyTuple_New(4); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1779; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_15); + __Pyx_INCREF(((PyObject *)__pyx_v_fphr)); + PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)__pyx_v_fphr)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_fphr)); + __Pyx_INCREF(__pyx_v_phrase2); + PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_v_phrase2); + __Pyx_GIVEREF(__pyx_v_phrase2); + PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_15, 3, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_2 = 0; + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Append(__pyx_v_extracts, ((PyObject *)__pyx_t_15)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1779; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + goto __pyx_L103; + } + __pyx_L103:; + goto __pyx_L94; + } + __pyx_L94:; + goto __pyx_L63; + } + __pyx_L63:; + goto __pyx_L51; + } + __pyx_L51:; + goto __pyx_L34; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1781 + * extracts.append((fphr, phrase2, pair_count, tuple(als4))) + * else: + * reason_for_failure = "Unable to extract basic phrase" # <<<<<<<<<<<<<< + * + * free(sent_links) + */ + __Pyx_INCREF(((PyObject *)__pyx_kp_s_131)); + __Pyx_DECREF(__pyx_v_reason_for_failure); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_131); + } + __pyx_L34:; + goto __pyx_L33; + } + __pyx_L33:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1783 + * reason_for_failure = "Unable to extract basic phrase" + * + * free(sent_links) # <<<<<<<<<<<<<< + * free(f_links_low) + * free(f_links_high) + */ + free(__pyx_v_sent_links); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1784 + * + * free(sent_links) + * free(f_links_low) # <<<<<<<<<<<<<< + * free(f_links_high) + * free(e_links_low) + */ + free(__pyx_v_f_links_low); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1785 + * free(sent_links) + * free(f_links_low) + * free(f_links_high) # <<<<<<<<<<<<<< + * free(e_links_low) + * free(e_links_high) + */ + free(__pyx_v_f_links_high); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1786 + * free(f_links_low) + * free(f_links_high) + * free(e_links_low) # <<<<<<<<<<<<<< + * free(e_links_high) + * free(f_gap_low) + */ + free(__pyx_v_e_links_low); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1787 + * free(f_links_high) + * free(e_links_low) + * free(e_links_high) # <<<<<<<<<<<<<< + * free(f_gap_low) + * free(f_gap_high) + */ + free(__pyx_v_e_links_high); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1788 + * free(e_links_low) + * free(e_links_high) + * free(f_gap_low) # <<<<<<<<<<<<<< + * free(f_gap_high) + * free(e_gap_low) + */ + free(__pyx_v_f_gap_low); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1789 + * free(e_links_high) + * free(f_gap_low) + * free(f_gap_high) # <<<<<<<<<<<<<< + * free(e_gap_low) + * free(e_gap_high) + */ + free(__pyx_v_f_gap_high); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1790 + * free(f_gap_low) + * free(f_gap_high) + * free(e_gap_low) # <<<<<<<<<<<<<< + * free(e_gap_high) + * + */ + free(__pyx_v_e_gap_low); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1791 + * free(f_gap_high) + * free(e_gap_low) + * free(e_gap_high) # <<<<<<<<<<<<<< + * + * return extracts + */ + free(__pyx_v_e_gap_high); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1793 + * free(e_gap_high) + * + * return extracts # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_extracts); + __pyx_r = __pyx_v_extracts; + 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_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_XDECREF(__pyx_t_15); + __Pyx_AddTraceback("_sa.HieroCachingRuleFactory.extract", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_extracts); + __Pyx_XDECREF(__pyx_v_phrase_list); + __Pyx_XDECREF((PyObject *)__pyx_v_fphr_arr); + __Pyx_XDECREF((PyObject *)__pyx_v_fphr); + __Pyx_XDECREF(__pyx_v_reason_for_failure); + __Pyx_XDECREF(__pyx_v_sofar); + __Pyx_XDECREF(__pyx_v_als); + __Pyx_XDECREF(__pyx_v_al); + __Pyx_XDECREF(__pyx_v_phrase2); + __Pyx_XDECREF(__pyx_v_eindexes); + __Pyx_XDECREF(__pyx_v_als1); + __Pyx_XDECREF(__pyx_v_als2); + __Pyx_XDECREF(__pyx_v_als3); + __Pyx_XDECREF(__pyx_v_als4); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static struct __pyx_vtabstruct_3_sa_Phrase __pyx_vtable_3_sa_Phrase; + +static PyObject *__pyx_tp_new_3_sa_Phrase(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_3_sa_Phrase *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_Phrase *)o); + p->__pyx_vtab = __pyx_vtabptr_3_sa_Phrase; + if (__pyx_pw_3_sa_6Phrase_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_Phrase(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_3_sa_6Phrase_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_3_sa_Phrase(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static PyObject *__pyx_getprop_3_sa_6Phrase_words(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_3_sa_6Phrase_5words_1__get__(o); +} + +static PyMethodDef __pyx_methods_3_sa_Phrase[] = { + {__Pyx_NAMESTR("handle"), (PyCFunction)__pyx_pw_3_sa_6Phrase_7handle, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_3_sa_6Phrase_6handle)}, + {__Pyx_NAMESTR("strhandle"), (PyCFunction)__pyx_pw_3_sa_6Phrase_9strhandle, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("arity"), (PyCFunction)__pyx_pw_3_sa_6Phrase_11arity, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("getvarpos"), (PyCFunction)__pyx_pw_3_sa_6Phrase_13getvarpos, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("getvar"), (PyCFunction)__pyx_pw_3_sa_6Phrase_15getvar, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("clen"), (PyCFunction)__pyx_pw_3_sa_6Phrase_17clen, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("getchunk"), (PyCFunction)__pyx_pw_3_sa_6Phrase_19getchunk, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("subst"), (PyCFunction)__pyx_pw_3_sa_6Phrase_32subst, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_3_sa_Phrase[] = { + {(char *)"words", __pyx_getprop_3_sa_6Phrase_words, 0, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Phrase = { + 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_Phrase = { + __pyx_pw_3_sa_6Phrase_25__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_3_sa_Phrase, /*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_Phrase = { + __pyx_pw_3_sa_6Phrase_25__len__, /*mp_length*/ + __pyx_pw_3_sa_6Phrase_27__getitem__, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Phrase = { + #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_3_sa_Phrase = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.Phrase"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_Phrase), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_Phrase, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + __pyx_pw_3_sa_6Phrase_21__cmp__, /*tp_compare*/ + #else + 0, /*reserved*/ + #endif + 0, /*tp_repr*/ + &__pyx_tp_as_number_Phrase, /*tp_as_number*/ + &__pyx_tp_as_sequence_Phrase, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Phrase, /*tp_as_mapping*/ + __pyx_pw_3_sa_6Phrase_23__hash__, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_3_sa_6Phrase_5__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Phrase, /*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_pw_3_sa_6Phrase_29__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_Phrase, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_3_sa_Phrase, /*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_3_sa_Phrase, /*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_3_sa_Rule(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_3_sa_Rule *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_Rule *)o); + p->f = ((struct __pyx_obj_3_sa_Phrase *)Py_None); Py_INCREF(Py_None); + p->e = ((struct __pyx_obj_3_sa_Phrase *)Py_None); Py_INCREF(Py_None); + p->word_alignments = Py_None; Py_INCREF(Py_None); + if (__pyx_pw_3_sa_4Rule_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_Rule(PyObject *o) { + struct __pyx_obj_3_sa_Rule *p = (struct __pyx_obj_3_sa_Rule *)o; + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_3_sa_4Rule_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + Py_XDECREF(((PyObject *)p->f)); + Py_XDECREF(((PyObject *)p->e)); + Py_XDECREF(p->word_alignments); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_3_sa_Rule(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa_Rule *p = (struct __pyx_obj_3_sa_Rule *)o; + if (p->f) { + e = (*v)(((PyObject*)p->f), a); if (e) return e; + } + if (p->e) { + e = (*v)(((PyObject*)p->e), a); if (e) return e; + } + if (p->word_alignments) { + e = (*v)(p->word_alignments, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa_Rule(PyObject *o) { + struct __pyx_obj_3_sa_Rule *p = (struct __pyx_obj_3_sa_Rule *)o; + PyObject* tmp; + tmp = ((PyObject*)p->f); + p->f = ((struct __pyx_obj_3_sa_Phrase *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->e); + p->e = ((struct __pyx_obj_3_sa_Phrase *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->word_alignments); + p->word_alignments = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_3_sa_4Rule_scores(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_3_sa_4Rule_6scores_1__get__(o); +} + +static int __pyx_setprop_3_sa_4Rule_scores(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_3_sa_4Rule_6scores_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_3_sa_4Rule_lhs(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_3_sa_4Rule_3lhs_1__get__(o); +} + +static int __pyx_setprop_3_sa_4Rule_lhs(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_3_sa_4Rule_3lhs_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_3_sa_4Rule_f(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_3_sa_4Rule_1f_1__get__(o); +} + +static PyObject *__pyx_getprop_3_sa_4Rule_e(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_3_sa_4Rule_1e_1__get__(o); +} + +static PyObject *__pyx_getprop_3_sa_4Rule_word_alignments(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_3_sa_4Rule_15word_alignments_1__get__(o); +} + +static int __pyx_setprop_3_sa_4Rule_word_alignments(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_3_sa_4Rule_15word_alignments_3__set__(o, v); + } + else { + return __pyx_pw_3_sa_4Rule_15word_alignments_5__del__(o); + } +} + +static PyMethodDef __pyx_methods_3_sa_Rule[] = { + {__Pyx_NAMESTR("fmerge"), (PyCFunction)__pyx_pw_3_sa_4Rule_11fmerge, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("arity"), (PyCFunction)__pyx_pw_3_sa_4Rule_13arity, METH_NOARGS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_3_sa_Rule[] = { + {(char *)"scores", __pyx_getprop_3_sa_4Rule_scores, __pyx_setprop_3_sa_4Rule_scores, 0, 0}, + {(char *)"lhs", __pyx_getprop_3_sa_4Rule_lhs, __pyx_setprop_3_sa_4Rule_lhs, 0, 0}, + {(char *)"f", __pyx_getprop_3_sa_4Rule_f, 0, 0, 0}, + {(char *)"e", __pyx_getprop_3_sa_4Rule_e, 0, 0, 0}, + {(char *)"word_alignments", __pyx_getprop_3_sa_4Rule_word_alignments, __pyx_setprop_3_sa_4Rule_word_alignments, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Rule = { + 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 + __pyx_pw_3_sa_4Rule_9__iadd__, /*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_Rule = { + 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_Rule = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Rule = { + #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_3_sa_Rule = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.Rule"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_Rule), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_Rule, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + __pyx_pw_3_sa_4Rule_7__cmp__, /*tp_compare*/ + #else + 0, /*reserved*/ + #endif + 0, /*tp_repr*/ + &__pyx_tp_as_number_Rule, /*tp_as_number*/ + &__pyx_tp_as_sequence_Rule, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Rule, /*tp_as_mapping*/ + __pyx_pw_3_sa_4Rule_5__hash__, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_3_sa_4Rule_15__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Rule, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_3_sa_Rule, /*tp_traverse*/ + __pyx_tp_clear_3_sa_Rule, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_Rule, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_3_sa_Rule, /*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_3_sa_Rule, /*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 struct __pyx_vtabstruct_3_sa_FloatList __pyx_vtable_3_sa_FloatList; + +static PyObject *__pyx_tp_new_3_sa_FloatList(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_3_sa_FloatList *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_FloatList *)o); + p->__pyx_vtab = __pyx_vtabptr_3_sa_FloatList; + if (__pyx_pw_3_sa_9FloatList_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_FloatList(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_3_sa_9FloatList_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_3_sa_FloatList(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_3_sa_FloatList(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_3_sa_9FloatList_7__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_3_sa_FloatList[] = { + {__Pyx_NAMESTR("append"), (PyCFunction)__pyx_pw_3_sa_9FloatList_11append, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write"), (PyCFunction)__pyx_pw_3_sa_9FloatList_13write, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read"), (PyCFunction)__pyx_pw_3_sa_9FloatList_15read, METH_O, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_FloatList = { + 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_FloatList = { + __pyx_pw_3_sa_9FloatList_9__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_3_sa_FloatList, /*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_FloatList = { + __pyx_pw_3_sa_9FloatList_9__len__, /*mp_length*/ + __pyx_pw_3_sa_9FloatList_5__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_3_sa_FloatList, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_FloatList = { + #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_3_sa_FloatList = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.FloatList"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_FloatList), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_FloatList, /*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_FloatList, /*tp_as_number*/ + &__pyx_tp_as_sequence_FloatList, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_FloatList, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_FloatList, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_FloatList, /*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_3_sa_FloatList, /*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 struct __pyx_vtabstruct_3_sa_IntList __pyx_vtable_3_sa_IntList; + +static PyObject *__pyx_tp_new_3_sa_IntList(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_3_sa_IntList *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_IntList *)o); + p->__pyx_vtab = __pyx_vtabptr_3_sa_IntList; + if (__pyx_pw_3_sa_7IntList_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_IntList(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_3_sa_7IntList_15__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_3_sa_IntList(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_3_sa_IntList(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_3_sa_7IntList_19__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_3_sa_IntList[] = { + {__Pyx_NAMESTR("index"), (PyCFunction)__pyx_pw_3_sa_7IntList_5index, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("partition"), (PyCFunction)__pyx_pw_3_sa_7IntList_7partition, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("_doquicksort"), (PyCFunction)__pyx_pw_3_sa_7IntList_9_doquicksort, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("sort"), (PyCFunction)__pyx_pw_3_sa_7IntList_11sort, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("reset"), (PyCFunction)__pyx_pw_3_sa_7IntList_13reset, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("getSize"), (PyCFunction)__pyx_pw_3_sa_7IntList_23getSize, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("append"), (PyCFunction)__pyx_pw_3_sa_7IntList_25append, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("extend"), (PyCFunction)__pyx_pw_3_sa_7IntList_27extend, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write"), (PyCFunction)__pyx_pw_3_sa_7IntList_29write, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read"), (PyCFunction)__pyx_pw_3_sa_7IntList_31read, METH_O, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_IntList = { + 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_IntList = { + __pyx_pw_3_sa_7IntList_21__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_3_sa_IntList, /*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_IntList = { + __pyx_pw_3_sa_7IntList_21__len__, /*mp_length*/ + __pyx_pw_3_sa_7IntList_17__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_3_sa_IntList, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_IntList = { + #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_3_sa_IntList = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.IntList"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_IntList), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_IntList, /*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_IntList, /*tp_as_number*/ + &__pyx_tp_as_sequence_IntList, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_IntList, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_3_sa_7IntList_3__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_IntList, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_IntList, /*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_3_sa_IntList, /*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 struct __pyx_vtabstruct_3_sa_StringMap __pyx_vtable_3_sa_StringMap; + +static PyObject *__pyx_tp_new_3_sa_StringMap(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_3_sa_StringMap *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_StringMap *)o); + p->__pyx_vtab = __pyx_vtabptr_3_sa_StringMap; + if (__pyx_pw_3_sa_9StringMap_1__cinit__(o, __pyx_empty_tuple, NULL) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_StringMap(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_3_sa_9StringMap_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_3_sa_StringMap[] = { + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_StringMap = { + 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_StringMap = { + 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_StringMap = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_StringMap = { + #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_3_sa_StringMap = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.StringMap"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_StringMap), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_StringMap, /*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_StringMap, /*tp_as_number*/ + &__pyx_tp_as_sequence_StringMap, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_StringMap, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_StringMap, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_StringMap, /*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_3_sa_StringMap, /*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 struct __pyx_vtabstruct_3_sa_DataArray __pyx_vtable_3_sa_DataArray; + +static PyObject *__pyx_tp_new_3_sa_DataArray(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_3_sa_DataArray *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_DataArray *)o); + p->__pyx_vtab = __pyx_vtabptr_3_sa_DataArray; + p->word2id = Py_None; Py_INCREF(Py_None); + p->id2word = Py_None; Py_INCREF(Py_None); + p->data = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->sent_id = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->sent_index = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_3_sa_9DataArray_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_DataArray(PyObject *o) { + struct __pyx_obj_3_sa_DataArray *p = (struct __pyx_obj_3_sa_DataArray *)o; + Py_XDECREF(p->word2id); + Py_XDECREF(p->id2word); + Py_XDECREF(((PyObject *)p->data)); + Py_XDECREF(((PyObject *)p->sent_id)); + Py_XDECREF(((PyObject *)p->sent_index)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_3_sa_DataArray(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa_DataArray *p = (struct __pyx_obj_3_sa_DataArray *)o; + if (p->word2id) { + e = (*v)(p->word2id, a); if (e) return e; + } + if (p->id2word) { + e = (*v)(p->id2word, a); if (e) return e; + } + if (p->data) { + e = (*v)(((PyObject*)p->data), a); if (e) return e; + } + if (p->sent_id) { + e = (*v)(((PyObject*)p->sent_id), a); if (e) return e; + } + if (p->sent_index) { + e = (*v)(((PyObject*)p->sent_index), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa_DataArray(PyObject *o) { + struct __pyx_obj_3_sa_DataArray *p = (struct __pyx_obj_3_sa_DataArray *)o; + PyObject* tmp; + tmp = ((PyObject*)p->word2id); + p->word2id = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->id2word); + p->id2word = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->data); + p->data = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->sent_id); + p->sent_id = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->sent_index); + p->sent_index = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_3_sa_DataArray[] = { + {__Pyx_NAMESTR("getSentId"), (PyCFunction)__pyx_pw_3_sa_9DataArray_5getSentId, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("getSent"), (PyCFunction)__pyx_pw_3_sa_9DataArray_7getSent, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("getSentPos"), (PyCFunction)__pyx_pw_3_sa_9DataArray_9getSentPos, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_id"), (PyCFunction)__pyx_pw_3_sa_9DataArray_11get_id, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_word"), (PyCFunction)__pyx_pw_3_sa_9DataArray_13get_word, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_text"), (PyCFunction)__pyx_pw_3_sa_9DataArray_15write_text, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_text"), (PyCFunction)__pyx_pw_3_sa_9DataArray_17read_text, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_binary"), (PyCFunction)__pyx_pw_3_sa_9DataArray_19read_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_binary"), (PyCFunction)__pyx_pw_3_sa_9DataArray_21write_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_enhanced_handle"), (PyCFunction)__pyx_pw_3_sa_9DataArray_23write_enhanced_handle, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_enhanced"), (PyCFunction)__pyx_pw_3_sa_9DataArray_25write_enhanced, METH_O, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_DataArray = { + 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_DataArray = { + __pyx_pw_3_sa_9DataArray_3__len__, /*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_DataArray = { + __pyx_pw_3_sa_9DataArray_3__len__, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_DataArray = { + #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_3_sa_DataArray = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.DataArray"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_DataArray), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_DataArray, /*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_DataArray, /*tp_as_number*/ + &__pyx_tp_as_sequence_DataArray, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_DataArray, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_DataArray, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_3_sa_DataArray, /*tp_traverse*/ + __pyx_tp_clear_3_sa_DataArray, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_DataArray, /*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_3_sa_DataArray, /*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 struct __pyx_vtabstruct_3_sa_Alignment __pyx_vtable_3_sa_Alignment; + +static PyObject *__pyx_tp_new_3_sa_Alignment(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_3_sa_Alignment *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_Alignment *)o); + p->__pyx_vtab = __pyx_vtabptr_3_sa_Alignment; + p->links = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->sent_index = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_3_sa_9Alignment_5__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_Alignment(PyObject *o) { + struct __pyx_obj_3_sa_Alignment *p = (struct __pyx_obj_3_sa_Alignment *)o; + Py_XDECREF(((PyObject *)p->links)); + Py_XDECREF(((PyObject *)p->sent_index)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_3_sa_Alignment(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa_Alignment *p = (struct __pyx_obj_3_sa_Alignment *)o; + if (p->links) { + e = (*v)(((PyObject*)p->links), a); if (e) return e; + } + if (p->sent_index) { + e = (*v)(((PyObject*)p->sent_index), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa_Alignment(PyObject *o) { + struct __pyx_obj_3_sa_Alignment *p = (struct __pyx_obj_3_sa_Alignment *)o; + PyObject* tmp; + tmp = ((PyObject*)p->links); + p->links = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->sent_index); + p->sent_index = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_3_sa_Alignment[] = { + {__Pyx_NAMESTR("unlink"), (PyCFunction)__pyx_pw_3_sa_9Alignment_1unlink, METH_O, __Pyx_DOCSTR(__pyx_doc_3_sa_9Alignment_unlink)}, + {__Pyx_NAMESTR("get_sent_links"), (PyCFunction)__pyx_pw_3_sa_9Alignment_3get_sent_links, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_text"), (PyCFunction)__pyx_pw_3_sa_9Alignment_7read_text, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_binary"), (PyCFunction)__pyx_pw_3_sa_9Alignment_9read_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_text"), (PyCFunction)__pyx_pw_3_sa_9Alignment_11write_text, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_binary"), (PyCFunction)__pyx_pw_3_sa_9Alignment_13write_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_enhanced"), (PyCFunction)__pyx_pw_3_sa_9Alignment_15write_enhanced, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("alignment"), (PyCFunction)__pyx_pw_3_sa_9Alignment_17alignment, METH_O, __Pyx_DOCSTR(__pyx_doc_3_sa_9Alignment_16alignment)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Alignment = { + 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_Alignment = { + 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_Alignment = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Alignment = { + #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_3_sa_Alignment = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.Alignment"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_Alignment), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_Alignment, /*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_Alignment, /*tp_as_number*/ + &__pyx_tp_as_sequence_Alignment, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Alignment, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Alignment, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_3_sa_Alignment, /*tp_traverse*/ + __pyx_tp_clear_3_sa_Alignment, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_Alignment, /*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_3_sa_Alignment, /*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 struct __pyx_vtabstruct_3_sa_BiLex __pyx_vtable_3_sa_BiLex; + +static PyObject *__pyx_tp_new_3_sa_BiLex(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_3_sa_BiLex *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_BiLex *)o); + p->__pyx_vtab = __pyx_vtabptr_3_sa_BiLex; + p->col1 = ((struct __pyx_obj_3_sa_FloatList *)Py_None); Py_INCREF(Py_None); + p->col2 = ((struct __pyx_obj_3_sa_FloatList *)Py_None); Py_INCREF(Py_None); + p->f_index = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->e_index = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->id2eword = Py_None; Py_INCREF(Py_None); + p->id2fword = Py_None; Py_INCREF(Py_None); + p->eword2id = Py_None; Py_INCREF(Py_None); + p->fword2id = Py_None; Py_INCREF(Py_None); + if (__pyx_pw_3_sa_5BiLex_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_BiLex(PyObject *o) { + struct __pyx_obj_3_sa_BiLex *p = (struct __pyx_obj_3_sa_BiLex *)o; + Py_XDECREF(((PyObject *)p->col1)); + Py_XDECREF(((PyObject *)p->col2)); + Py_XDECREF(((PyObject *)p->f_index)); + Py_XDECREF(((PyObject *)p->e_index)); + Py_XDECREF(p->id2eword); + Py_XDECREF(p->id2fword); + Py_XDECREF(p->eword2id); + Py_XDECREF(p->fword2id); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_3_sa_BiLex(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa_BiLex *p = (struct __pyx_obj_3_sa_BiLex *)o; + if (p->col1) { + e = (*v)(((PyObject*)p->col1), a); if (e) return e; + } + if (p->col2) { + e = (*v)(((PyObject*)p->col2), a); if (e) return e; + } + if (p->f_index) { + e = (*v)(((PyObject*)p->f_index), a); if (e) return e; + } + if (p->e_index) { + e = (*v)(((PyObject*)p->e_index), a); if (e) return e; + } + if (p->id2eword) { + e = (*v)(p->id2eword, a); if (e) return e; + } + if (p->id2fword) { + e = (*v)(p->id2fword, a); if (e) return e; + } + if (p->eword2id) { + e = (*v)(p->eword2id, a); if (e) return e; + } + if (p->fword2id) { + e = (*v)(p->fword2id, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa_BiLex(PyObject *o) { + struct __pyx_obj_3_sa_BiLex *p = (struct __pyx_obj_3_sa_BiLex *)o; + PyObject* tmp; + tmp = ((PyObject*)p->col1); + p->col1 = ((struct __pyx_obj_3_sa_FloatList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->col2); + p->col2 = ((struct __pyx_obj_3_sa_FloatList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->f_index); + p->f_index = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->e_index); + p->e_index = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->id2eword); + p->id2eword = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->id2fword); + p->id2fword = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->eword2id); + p->eword2id = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->fword2id); + p->fword2id = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_3_sa_BiLex[] = { + {__Pyx_NAMESTR("write_binary"), (PyCFunction)__pyx_pw_3_sa_5BiLex_3write_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_binary"), (PyCFunction)__pyx_pw_3_sa_5BiLex_5read_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_e_id"), (PyCFunction)__pyx_pw_3_sa_5BiLex_7get_e_id, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_f_id"), (PyCFunction)__pyx_pw_3_sa_5BiLex_9get_f_id, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_text"), (PyCFunction)__pyx_pw_3_sa_5BiLex_11read_text, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_enhanced"), (PyCFunction)__pyx_pw_3_sa_5BiLex_13write_enhanced, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_score"), (PyCFunction)__pyx_pw_3_sa_5BiLex_15get_score, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_text"), (PyCFunction)__pyx_pw_3_sa_5BiLex_17write_text, METH_O, __Pyx_DOCSTR(__pyx_doc_3_sa_5BiLex_16write_text)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_BiLex = { + 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_BiLex = { + 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_BiLex = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_BiLex = { + #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_3_sa_BiLex = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.BiLex"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_BiLex), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_BiLex, /*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_BiLex, /*tp_as_number*/ + &__pyx_tp_as_sequence_BiLex, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_BiLex, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_BiLex, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_3_sa_BiLex, /*tp_traverse*/ + __pyx_tp_clear_3_sa_BiLex, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_BiLex, /*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_3_sa_BiLex, /*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_3_sa_BitSetIterator(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + return o; +} + +static void __pyx_tp_dealloc_3_sa_BitSetIterator(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} + +static PyMethodDef __pyx_methods_3_sa_BitSetIterator[] = { + {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_3_sa_14BitSetIterator_1__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_BitSetIterator = { + 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_BitSetIterator = { + 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_BitSetIterator = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_BitSetIterator = { + #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_3_sa_BitSetIterator = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.BitSetIterator"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_BitSetIterator), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_BitSetIterator, /*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_BitSetIterator, /*tp_as_number*/ + &__pyx_tp_as_sequence_BitSetIterator, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_BitSetIterator, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_BitSetIterator, /*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*/ + 0, /*tp_iter*/ + __pyx_pw_3_sa_14BitSetIterator_1__next__, /*tp_iternext*/ + __pyx_methods_3_sa_BitSetIterator, /*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_3_sa_BitSetIterator, /*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_3_sa_BitSet(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + if (__pyx_pw_3_sa_6BitSet_1__cinit__(o, __pyx_empty_tuple, NULL) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_BitSet(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_3_sa_6BitSet_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_3_sa_BitSet[] = { + {__Pyx_NAMESTR("insert"), (PyCFunction)__pyx_pw_3_sa_6BitSet_7insert, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("findsucc"), (PyCFunction)__pyx_pw_3_sa_6BitSet_9findsucc, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("min"), (PyCFunction)__pyx_pw_3_sa_6BitSet_13min, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("max"), (PyCFunction)__pyx_pw_3_sa_6BitSet_15max, METH_NOARGS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_BitSet = { + 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_BitSet = { + __pyx_pw_3_sa_6BitSet_17__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + 0, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + __pyx_pw_3_sa_6BitSet_19__contains__, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_BitSet = { + __pyx_pw_3_sa_6BitSet_17__len__, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_BitSet = { + #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_3_sa_BitSet = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.BitSet"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_BitSet), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_BitSet, /*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_BitSet, /*tp_as_number*/ + &__pyx_tp_as_sequence_BitSet, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_BitSet, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_3_sa_6BitSet_11__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_BitSet, /*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_pw_3_sa_6BitSet_5__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_BitSet, /*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_3_sa_BitSet, /*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_3_sa_VEBIterator(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + return o; +} + +static void __pyx_tp_dealloc_3_sa_VEBIterator(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} + +static PyMethodDef __pyx_methods_3_sa_VEBIterator[] = { + {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pw_3_sa_11VEBIterator_1__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_VEBIterator = { + 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_VEBIterator = { + 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_VEBIterator = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_VEBIterator = { + #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_3_sa_VEBIterator = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.VEBIterator"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_VEBIterator), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_VEBIterator, /*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_VEBIterator, /*tp_as_number*/ + &__pyx_tp_as_sequence_VEBIterator, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_VEBIterator, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_VEBIterator, /*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*/ + 0, /*tp_iter*/ + __pyx_pw_3_sa_11VEBIterator_1__next__, /*tp_iternext*/ + __pyx_methods_3_sa_VEBIterator, /*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_3_sa_VEBIterator, /*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 struct __pyx_vtabstruct_3_sa_VEB __pyx_vtable_3_sa_VEB; + +static PyObject *__pyx_tp_new_3_sa_VEB(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_3_sa_VEB *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_VEB *)o); + p->__pyx_vtab = __pyx_vtabptr_3_sa_VEB; + if (__pyx_pw_3_sa_3VEB_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_VEB(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_3_sa_3VEB_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_3_sa_VEB[] = { + {__Pyx_NAMESTR("insert"), (PyCFunction)__pyx_pw_3_sa_3VEB_7insert, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("findsucc"), (PyCFunction)__pyx_pw_3_sa_3VEB_9findsucc, METH_O, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_VEB = { + 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_VEB = { + __pyx_pw_3_sa_3VEB_11__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + 0, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + __pyx_pw_3_sa_3VEB_13__contains__, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_VEB = { + __pyx_pw_3_sa_3VEB_11__len__, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_VEB = { + #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_3_sa_VEB = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.VEB"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_VEB), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_VEB, /*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_VEB, /*tp_as_number*/ + &__pyx_tp_as_sequence_VEB, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_VEB, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_VEB, /*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_pw_3_sa_3VEB_5__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_VEB, /*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_3_sa_VEB, /*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_3_sa_LCP(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_3_sa_LCP *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_LCP *)o); + p->sa = ((struct __pyx_obj_3_sa_SuffixArray *)Py_None); Py_INCREF(Py_None); + p->lcp = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_3_sa_3LCP_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_LCP(PyObject *o) { + struct __pyx_obj_3_sa_LCP *p = (struct __pyx_obj_3_sa_LCP *)o; + Py_XDECREF(((PyObject *)p->sa)); + Py_XDECREF(((PyObject *)p->lcp)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_3_sa_LCP(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa_LCP *p = (struct __pyx_obj_3_sa_LCP *)o; + if (p->sa) { + e = (*v)(((PyObject*)p->sa), a); if (e) return e; + } + if (p->lcp) { + e = (*v)(((PyObject*)p->lcp), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa_LCP(PyObject *o) { + struct __pyx_obj_3_sa_LCP *p = (struct __pyx_obj_3_sa_LCP *)o; + PyObject* tmp; + tmp = ((PyObject*)p->sa); + p->sa = ((struct __pyx_obj_3_sa_SuffixArray *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->lcp); + p->lcp = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_3_sa_LCP[] = { + {__Pyx_NAMESTR("compute_stats"), (PyCFunction)__pyx_pw_3_sa_3LCP_3compute_stats, METH_O, __Pyx_DOCSTR(__pyx_doc_3_sa_3LCP_2compute_stats)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_LCP = { + 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_LCP = { + 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_LCP = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_LCP = { + #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_3_sa_LCP = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.LCP"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_LCP), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_LCP, /*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_LCP, /*tp_as_number*/ + &__pyx_tp_as_sequence_LCP, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_LCP, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_LCP, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_3_sa_LCP, /*tp_traverse*/ + __pyx_tp_clear_3_sa_LCP, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_LCP, /*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_3_sa_LCP, /*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 struct __pyx_vtabstruct_3_sa_Alphabet __pyx_vtable_3_sa_Alphabet; + +static PyObject *__pyx_tp_new_3_sa_Alphabet(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_3_sa_Alphabet *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_Alphabet *)o); + p->__pyx_vtab = __pyx_vtabptr_3_sa_Alphabet; + p->terminals = ((struct __pyx_obj_3_sa_StringMap *)Py_None); Py_INCREF(Py_None); + p->nonterminals = ((struct __pyx_obj_3_sa_StringMap *)Py_None); Py_INCREF(Py_None); + p->id2sym = ((PyObject*)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_3_sa_8Alphabet_1__cinit__(o, __pyx_empty_tuple, NULL) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_Alphabet(PyObject *o) { + struct __pyx_obj_3_sa_Alphabet *p = (struct __pyx_obj_3_sa_Alphabet *)o; + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_3_sa_8Alphabet_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + Py_XDECREF(((PyObject *)p->terminals)); + Py_XDECREF(((PyObject *)p->nonterminals)); + Py_XDECREF(((PyObject *)p->id2sym)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_3_sa_Alphabet(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa_Alphabet *p = (struct __pyx_obj_3_sa_Alphabet *)o; + if (p->terminals) { + e = (*v)(((PyObject*)p->terminals), a); if (e) return e; + } + if (p->nonterminals) { + e = (*v)(((PyObject*)p->nonterminals), a); if (e) return e; + } + if (p->id2sym) { + e = (*v)(p->id2sym, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa_Alphabet(PyObject *o) { + struct __pyx_obj_3_sa_Alphabet *p = (struct __pyx_obj_3_sa_Alphabet *)o; + PyObject* tmp; + tmp = ((PyObject*)p->terminals); + p->terminals = ((struct __pyx_obj_3_sa_StringMap *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->nonterminals); + p->nonterminals = ((struct __pyx_obj_3_sa_StringMap *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->id2sym); + p->id2sym = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_3_sa_8Alphabet_terminals(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_3_sa_8Alphabet_9terminals_1__get__(o); +} + +static PyObject *__pyx_getprop_3_sa_8Alphabet_nonterminals(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_3_sa_8Alphabet_12nonterminals_1__get__(o); +} + +static PyMethodDef __pyx_methods_3_sa_Alphabet[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_3_sa_Alphabet[] = { + {(char *)"terminals", __pyx_getprop_3_sa_8Alphabet_terminals, 0, 0, 0}, + {(char *)"nonterminals", __pyx_getprop_3_sa_8Alphabet_nonterminals, 0, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Alphabet = { + 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_Alphabet = { + 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_Alphabet = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Alphabet = { + #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_3_sa_Alphabet = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.Alphabet"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_Alphabet), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_Alphabet, /*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_Alphabet, /*tp_as_number*/ + &__pyx_tp_as_sequence_Alphabet, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Alphabet, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Alphabet, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_3_sa_Alphabet, /*tp_traverse*/ + __pyx_tp_clear_3_sa_Alphabet, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_Alphabet, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_3_sa_Alphabet, /*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_3_sa_Alphabet, /*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 struct __pyx_vtabstruct_3_sa_TrieMap __pyx_vtable_3_sa_TrieMap; + +static PyObject *__pyx_tp_new_3_sa_TrieMap(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_3_sa_TrieMap *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_TrieMap *)o); + p->__pyx_vtab = __pyx_vtabptr_3_sa_TrieMap; + if (__pyx_pw_3_sa_7TrieMap_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_TrieMap(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_3_sa_7TrieMap_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_3_sa_TrieMap[] = { + {__Pyx_NAMESTR("insert"), (PyCFunction)__pyx_pw_3_sa_7TrieMap_5insert, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("contains"), (PyCFunction)__pyx_pw_3_sa_7TrieMap_7contains, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("toMap"), (PyCFunction)__pyx_pw_3_sa_7TrieMap_9toMap, METH_O, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_TrieMap = { + 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_TrieMap = { + 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_TrieMap = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_TrieMap = { + #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_3_sa_TrieMap = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.TrieMap"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_TrieMap), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_TrieMap, /*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_TrieMap, /*tp_as_number*/ + &__pyx_tp_as_sequence_TrieMap, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_TrieMap, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_TrieMap, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_TrieMap, /*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_3_sa_TrieMap, /*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 struct __pyx_vtabstruct_3_sa_Precomputation __pyx_vtable_3_sa_Precomputation; + +static PyObject *__pyx_tp_new_3_sa_Precomputation(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_3_sa_Precomputation *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_Precomputation *)o); + p->__pyx_vtab = __pyx_vtabptr_3_sa_Precomputation; + p->precomputed_index = Py_None; Py_INCREF(Py_None); + p->precomputed_collocations = Py_None; Py_INCREF(Py_None); + if (__pyx_pw_3_sa_14Precomputation_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_Precomputation(PyObject *o) { + struct __pyx_obj_3_sa_Precomputation *p = (struct __pyx_obj_3_sa_Precomputation *)o; + Py_XDECREF(p->precomputed_index); + Py_XDECREF(p->precomputed_collocations); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_3_sa_Precomputation(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa_Precomputation *p = (struct __pyx_obj_3_sa_Precomputation *)o; + if (p->precomputed_index) { + e = (*v)(p->precomputed_index, a); if (e) return e; + } + if (p->precomputed_collocations) { + e = (*v)(p->precomputed_collocations, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa_Precomputation(PyObject *o) { + struct __pyx_obj_3_sa_Precomputation *p = (struct __pyx_obj_3_sa_Precomputation *)o; + PyObject* tmp; + tmp = ((PyObject*)p->precomputed_index); + p->precomputed_index = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->precomputed_collocations); + p->precomputed_collocations = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_3_sa_Precomputation[] = { + {__Pyx_NAMESTR("read_binary"), (PyCFunction)__pyx_pw_3_sa_14Precomputation_3read_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_binary"), (PyCFunction)__pyx_pw_3_sa_14Precomputation_5write_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("precompute"), (PyCFunction)__pyx_pw_3_sa_14Precomputation_7precompute, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Precomputation = { + 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_Precomputation = { + 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_Precomputation = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Precomputation = { + #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_3_sa_Precomputation = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.Precomputation"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_Precomputation), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_Precomputation, /*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_Precomputation, /*tp_as_number*/ + &__pyx_tp_as_sequence_Precomputation, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Precomputation, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Precomputation, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_3_sa_Precomputation, /*tp_traverse*/ + __pyx_tp_clear_3_sa_Precomputation, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_Precomputation, /*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_3_sa_Precomputation, /*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 struct __pyx_vtabstruct_3_sa_SuffixArray __pyx_vtable_3_sa_SuffixArray; + +static PyObject *__pyx_tp_new_3_sa_SuffixArray(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_3_sa_SuffixArray *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_SuffixArray *)o); + p->__pyx_vtab = __pyx_vtabptr_3_sa_SuffixArray; + p->darray = ((struct __pyx_obj_3_sa_DataArray *)Py_None); Py_INCREF(Py_None); + p->sa = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->ha = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_3_sa_11SuffixArray_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_SuffixArray(PyObject *o) { + struct __pyx_obj_3_sa_SuffixArray *p = (struct __pyx_obj_3_sa_SuffixArray *)o; + Py_XDECREF(((PyObject *)p->darray)); + Py_XDECREF(((PyObject *)p->sa)); + Py_XDECREF(((PyObject *)p->ha)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_3_sa_SuffixArray(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa_SuffixArray *p = (struct __pyx_obj_3_sa_SuffixArray *)o; + if (p->darray) { + e = (*v)(((PyObject*)p->darray), a); if (e) return e; + } + if (p->sa) { + e = (*v)(((PyObject*)p->sa), a); if (e) return e; + } + if (p->ha) { + e = (*v)(((PyObject*)p->ha), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa_SuffixArray(PyObject *o) { + struct __pyx_obj_3_sa_SuffixArray *p = (struct __pyx_obj_3_sa_SuffixArray *)o; + PyObject* tmp; + tmp = ((PyObject*)p->darray); + p->darray = ((struct __pyx_obj_3_sa_DataArray *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->sa); + p->sa = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->ha); + p->ha = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} +static PyObject *__pyx_sq_item_3_sa_SuffixArray(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static PyMethodDef __pyx_methods_3_sa_SuffixArray[] = { + {__Pyx_NAMESTR("getSentId"), (PyCFunction)__pyx_pw_3_sa_11SuffixArray_5getSentId, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("getSent"), (PyCFunction)__pyx_pw_3_sa_11SuffixArray_7getSent, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("getSentPos"), (PyCFunction)__pyx_pw_3_sa_11SuffixArray_9getSentPos, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_text"), (PyCFunction)__pyx_pw_3_sa_11SuffixArray_11read_text, METH_O, __Pyx_DOCSTR(__pyx_doc_3_sa_11SuffixArray_10read_text)}, + {__Pyx_NAMESTR("q3sort"), (PyCFunction)__pyx_pw_3_sa_11SuffixArray_13q3sort, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_3_sa_11SuffixArray_12q3sort)}, + {__Pyx_NAMESTR("write_text"), (PyCFunction)__pyx_pw_3_sa_11SuffixArray_15write_text, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_binary"), (PyCFunction)__pyx_pw_3_sa_11SuffixArray_17read_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_binary"), (PyCFunction)__pyx_pw_3_sa_11SuffixArray_19write_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_enhanced"), (PyCFunction)__pyx_pw_3_sa_11SuffixArray_21write_enhanced, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("lookup"), (PyCFunction)__pyx_pw_3_sa_11SuffixArray_23lookup, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_SuffixArray = { + 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_SuffixArray = { + 0, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_3_sa_SuffixArray, /*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_SuffixArray = { + 0, /*mp_length*/ + __pyx_pw_3_sa_11SuffixArray_3__getitem__, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_SuffixArray = { + #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_3_sa_SuffixArray = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.SuffixArray"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_SuffixArray), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_SuffixArray, /*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_SuffixArray, /*tp_as_number*/ + &__pyx_tp_as_sequence_SuffixArray, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_SuffixArray, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_SuffixArray, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_3_sa_SuffixArray, /*tp_traverse*/ + __pyx_tp_clear_3_sa_SuffixArray, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_SuffixArray, /*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_3_sa_SuffixArray, /*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_3_sa_TrieNode(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_3_sa_TrieNode *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_TrieNode *)o); + p->children = Py_None; Py_INCREF(Py_None); + if (__pyx_pw_3_sa_8TrieNode_1__cinit__(o, __pyx_empty_tuple, NULL) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_TrieNode(PyObject *o) { + struct __pyx_obj_3_sa_TrieNode *p = (struct __pyx_obj_3_sa_TrieNode *)o; + Py_XDECREF(p->children); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_3_sa_TrieNode(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa_TrieNode *p = (struct __pyx_obj_3_sa_TrieNode *)o; + if (p->children) { + e = (*v)(p->children, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa_TrieNode(PyObject *o) { + struct __pyx_obj_3_sa_TrieNode *p = (struct __pyx_obj_3_sa_TrieNode *)o; + PyObject* tmp; + tmp = ((PyObject*)p->children); + p->children = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_3_sa_8TrieNode_children(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_3_sa_8TrieNode_8children_1__get__(o); +} + +static int __pyx_setprop_3_sa_8TrieNode_children(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_3_sa_8TrieNode_8children_3__set__(o, v); + } + else { + return __pyx_pw_3_sa_8TrieNode_8children_5__del__(o); + } +} + +static PyMethodDef __pyx_methods_3_sa_TrieNode[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_3_sa_TrieNode[] = { + {(char *)"children", __pyx_getprop_3_sa_8TrieNode_children, __pyx_setprop_3_sa_8TrieNode_children, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_TrieNode = { + 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_TrieNode = { + 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_TrieNode = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_TrieNode = { + #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_3_sa_TrieNode = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.TrieNode"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_TrieNode), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_TrieNode, /*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_TrieNode, /*tp_as_number*/ + &__pyx_tp_as_sequence_TrieNode, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_TrieNode, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_TrieNode, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_3_sa_TrieNode, /*tp_traverse*/ + __pyx_tp_clear_3_sa_TrieNode, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_TrieNode, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_3_sa_TrieNode, /*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_3_sa_TrieNode, /*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_3_sa_ExtendedTrieNode(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_3_sa_ExtendedTrieNode *p; + PyObject *o = __pyx_tp_new_3_sa_TrieNode(t, a, k); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_ExtendedTrieNode *)o); + p->phrase = Py_None; Py_INCREF(Py_None); + p->phrase_location = Py_None; Py_INCREF(Py_None); + p->suffix_link = Py_None; Py_INCREF(Py_None); + if (__pyx_pw_3_sa_16ExtendedTrieNode_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_ExtendedTrieNode(PyObject *o) { + struct __pyx_obj_3_sa_ExtendedTrieNode *p = (struct __pyx_obj_3_sa_ExtendedTrieNode *)o; + Py_XDECREF(p->phrase); + Py_XDECREF(p->phrase_location); + Py_XDECREF(p->suffix_link); + __pyx_tp_dealloc_3_sa_TrieNode(o); +} + +static int __pyx_tp_traverse_3_sa_ExtendedTrieNode(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa_ExtendedTrieNode *p = (struct __pyx_obj_3_sa_ExtendedTrieNode *)o; + e = __pyx_tp_traverse_3_sa_TrieNode(o, v, a); if (e) return e; + if (p->phrase) { + e = (*v)(p->phrase, a); if (e) return e; + } + if (p->phrase_location) { + e = (*v)(p->phrase_location, a); if (e) return e; + } + if (p->suffix_link) { + e = (*v)(p->suffix_link, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa_ExtendedTrieNode(PyObject *o) { + struct __pyx_obj_3_sa_ExtendedTrieNode *p = (struct __pyx_obj_3_sa_ExtendedTrieNode *)o; + PyObject* tmp; + __pyx_tp_clear_3_sa_TrieNode(o); + tmp = ((PyObject*)p->phrase); + p->phrase = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->phrase_location); + p->phrase_location = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->suffix_link); + p->suffix_link = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_3_sa_16ExtendedTrieNode_phrase(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_3_sa_16ExtendedTrieNode_6phrase_1__get__(o); +} + +static int __pyx_setprop_3_sa_16ExtendedTrieNode_phrase(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_3_sa_16ExtendedTrieNode_6phrase_3__set__(o, v); + } + else { + return __pyx_pw_3_sa_16ExtendedTrieNode_6phrase_5__del__(o); + } +} + +static PyObject *__pyx_getprop_3_sa_16ExtendedTrieNode_phrase_location(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_3_sa_16ExtendedTrieNode_15phrase_location_1__get__(o); +} + +static int __pyx_setprop_3_sa_16ExtendedTrieNode_phrase_location(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_3_sa_16ExtendedTrieNode_15phrase_location_3__set__(o, v); + } + else { + return __pyx_pw_3_sa_16ExtendedTrieNode_15phrase_location_5__del__(o); + } +} + +static PyObject *__pyx_getprop_3_sa_16ExtendedTrieNode_suffix_link(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_3_sa_16ExtendedTrieNode_11suffix_link_1__get__(o); +} + +static int __pyx_setprop_3_sa_16ExtendedTrieNode_suffix_link(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_3_sa_16ExtendedTrieNode_11suffix_link_3__set__(o, v); + } + else { + return __pyx_pw_3_sa_16ExtendedTrieNode_11suffix_link_5__del__(o); + } +} + +static PyMethodDef __pyx_methods_3_sa_ExtendedTrieNode[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_3_sa_ExtendedTrieNode[] = { + {(char *)"phrase", __pyx_getprop_3_sa_16ExtendedTrieNode_phrase, __pyx_setprop_3_sa_16ExtendedTrieNode_phrase, 0, 0}, + {(char *)"phrase_location", __pyx_getprop_3_sa_16ExtendedTrieNode_phrase_location, __pyx_setprop_3_sa_16ExtendedTrieNode_phrase_location, 0, 0}, + {(char *)"suffix_link", __pyx_getprop_3_sa_16ExtendedTrieNode_suffix_link, __pyx_setprop_3_sa_16ExtendedTrieNode_suffix_link, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_ExtendedTrieNode = { + 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_ExtendedTrieNode = { + 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_ExtendedTrieNode = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_ExtendedTrieNode = { + #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_3_sa_ExtendedTrieNode = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.ExtendedTrieNode"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_ExtendedTrieNode), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_ExtendedTrieNode, /*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_ExtendedTrieNode, /*tp_as_number*/ + &__pyx_tp_as_sequence_ExtendedTrieNode, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_ExtendedTrieNode, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_ExtendedTrieNode, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_3_sa_ExtendedTrieNode, /*tp_traverse*/ + __pyx_tp_clear_3_sa_ExtendedTrieNode, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_ExtendedTrieNode, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_3_sa_ExtendedTrieNode, /*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_3_sa_ExtendedTrieNode, /*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_3_sa_TrieTable(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_3_sa_TrieTable *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_TrieTable *)o); + p->root = Py_None; Py_INCREF(Py_None); + if (__pyx_pw_3_sa_9TrieTable_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_TrieTable(PyObject *o) { + struct __pyx_obj_3_sa_TrieTable *p = (struct __pyx_obj_3_sa_TrieTable *)o; + Py_XDECREF(p->root); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_3_sa_TrieTable(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa_TrieTable *p = (struct __pyx_obj_3_sa_TrieTable *)o; + if (p->root) { + e = (*v)(p->root, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa_TrieTable(PyObject *o) { + struct __pyx_obj_3_sa_TrieTable *p = (struct __pyx_obj_3_sa_TrieTable *)o; + PyObject* tmp; + tmp = ((PyObject*)p->root); + p->root = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_3_sa_9TrieTable_extended(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_3_sa_9TrieTable_8extended_1__get__(o); +} + +static int __pyx_setprop_3_sa_9TrieTable_extended(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_3_sa_9TrieTable_8extended_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_3_sa_9TrieTable_count(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_3_sa_9TrieTable_5count_1__get__(o); +} + +static int __pyx_setprop_3_sa_9TrieTable_count(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_3_sa_9TrieTable_5count_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyObject *__pyx_getprop_3_sa_9TrieTable_root(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_3_sa_9TrieTable_4root_1__get__(o); +} + +static int __pyx_setprop_3_sa_9TrieTable_root(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_3_sa_9TrieTable_4root_3__set__(o, v); + } + else { + return __pyx_pw_3_sa_9TrieTable_4root_5__del__(o); + } +} + +static PyMethodDef __pyx_methods_3_sa_TrieTable[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_3_sa_TrieTable[] = { + {(char *)"extended", __pyx_getprop_3_sa_9TrieTable_extended, __pyx_setprop_3_sa_9TrieTable_extended, 0, 0}, + {(char *)"count", __pyx_getprop_3_sa_9TrieTable_count, __pyx_setprop_3_sa_9TrieTable_count, 0, 0}, + {(char *)"root", __pyx_getprop_3_sa_9TrieTable_root, __pyx_setprop_3_sa_9TrieTable_root, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_TrieTable = { + 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_TrieTable = { + 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_TrieTable = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_TrieTable = { + #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_3_sa_TrieTable = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.TrieTable"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_TrieTable), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_TrieTable, /*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_TrieTable, /*tp_as_number*/ + &__pyx_tp_as_sequence_TrieTable, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_TrieTable, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_TrieTable, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_3_sa_TrieTable, /*tp_traverse*/ + __pyx_tp_clear_3_sa_TrieTable, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_TrieTable, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_3_sa_TrieTable, /*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_3_sa_TrieTable, /*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 struct __pyx_vtabstruct_3_sa_PhraseLocation __pyx_vtable_3_sa_PhraseLocation; + +static PyObject *__pyx_tp_new_3_sa_PhraseLocation(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_3_sa_PhraseLocation *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_PhraseLocation *)o); + p->__pyx_vtab = __pyx_vtabptr_3_sa_PhraseLocation; + p->arr = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_3_sa_14PhraseLocation_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_PhraseLocation(PyObject *o) { + struct __pyx_obj_3_sa_PhraseLocation *p = (struct __pyx_obj_3_sa_PhraseLocation *)o; + Py_XDECREF(((PyObject *)p->arr)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_3_sa_PhraseLocation(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa_PhraseLocation *p = (struct __pyx_obj_3_sa_PhraseLocation *)o; + if (p->arr) { + e = (*v)(((PyObject*)p->arr), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa_PhraseLocation(PyObject *o) { + struct __pyx_obj_3_sa_PhraseLocation *p = (struct __pyx_obj_3_sa_PhraseLocation *)o; + PyObject* tmp; + tmp = ((PyObject*)p->arr); + p->arr = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_3_sa_PhraseLocation[] = { + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_PhraseLocation = { + 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_PhraseLocation = { + 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_PhraseLocation = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_PhraseLocation = { + #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_3_sa_PhraseLocation = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.PhraseLocation"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_PhraseLocation), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_PhraseLocation, /*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_PhraseLocation, /*tp_as_number*/ + &__pyx_tp_as_sequence_PhraseLocation, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_PhraseLocation, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_PhraseLocation, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_3_sa_PhraseLocation, /*tp_traverse*/ + __pyx_tp_clear_3_sa_PhraseLocation, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_PhraseLocation, /*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_3_sa_PhraseLocation, /*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_3_sa_Sampler(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_3_sa_Sampler *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_Sampler *)o); + p->sa = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_3_sa_7Sampler_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_Sampler(PyObject *o) { + struct __pyx_obj_3_sa_Sampler *p = (struct __pyx_obj_3_sa_Sampler *)o; + Py_XDECREF(((PyObject *)p->sa)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_3_sa_Sampler(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa_Sampler *p = (struct __pyx_obj_3_sa_Sampler *)o; + if (p->sa) { + e = (*v)(((PyObject*)p->sa), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa_Sampler(PyObject *o) { + struct __pyx_obj_3_sa_Sampler *p = (struct __pyx_obj_3_sa_Sampler *)o; + PyObject* tmp; + tmp = ((PyObject*)p->sa); + p->sa = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_3_sa_Sampler[] = { + {__Pyx_NAMESTR("sample"), (PyCFunction)__pyx_pw_3_sa_7Sampler_3sample, METH_O, __Pyx_DOCSTR(__pyx_doc_3_sa_7Sampler_2sample)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Sampler = { + 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_Sampler = { + 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_Sampler = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Sampler = { + #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_3_sa_Sampler = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.Sampler"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_Sampler), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_Sampler, /*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_Sampler, /*tp_as_number*/ + &__pyx_tp_as_sequence_Sampler, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Sampler, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Sampler, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + __Pyx_DOCSTR("A Sampler implements a logic for choosing\n samples from a population range"), /*tp_doc*/ + __pyx_tp_traverse_3_sa_Sampler, /*tp_traverse*/ + __pyx_tp_clear_3_sa_Sampler, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_Sampler, /*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_3_sa_Sampler, /*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 struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory __pyx_vtable_3_sa_HieroCachingRuleFactory; + +static PyObject *__pyx_tp_new_3_sa_HieroCachingRuleFactory(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_3_sa_HieroCachingRuleFactory *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_HieroCachingRuleFactory *)o); + p->__pyx_vtab = __pyx_vtabptr_3_sa_HieroCachingRuleFactory; + p->rules = ((struct __pyx_obj_3_sa_TrieTable *)Py_None); Py_INCREF(Py_None); + p->sampler = ((struct __pyx_obj_3_sa_Sampler *)Py_None); Py_INCREF(Py_None); + p->precomputed_index = Py_None; Py_INCREF(Py_None); + p->precomputed_collocations = Py_None; Py_INCREF(Py_None); + p->precompute_file = Py_None; Py_INCREF(Py_None); + p->max_rank = Py_None; Py_INCREF(Py_None); + p->prev_norm_prefix = Py_None; Py_INCREF(Py_None); + p->fsa = ((struct __pyx_obj_3_sa_SuffixArray *)Py_None); Py_INCREF(Py_None); + p->fda = ((struct __pyx_obj_3_sa_DataArray *)Py_None); Py_INCREF(Py_None); + p->eda = ((struct __pyx_obj_3_sa_DataArray *)Py_None); Py_INCREF(Py_None); + p->alignment = ((struct __pyx_obj_3_sa_Alignment *)Py_None); Py_INCREF(Py_None); + p->eid2symid = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->fid2symid = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->findexes = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->findexes1 = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_3_sa_23HieroCachingRuleFactory_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_HieroCachingRuleFactory(PyObject *o) { + struct __pyx_obj_3_sa_HieroCachingRuleFactory *p = (struct __pyx_obj_3_sa_HieroCachingRuleFactory *)o; + Py_XDECREF(((PyObject *)p->rules)); + Py_XDECREF(((PyObject *)p->sampler)); + Py_XDECREF(p->precomputed_index); + Py_XDECREF(p->precomputed_collocations); + Py_XDECREF(p->precompute_file); + Py_XDECREF(p->max_rank); + Py_XDECREF(p->prev_norm_prefix); + Py_XDECREF(((PyObject *)p->fsa)); + Py_XDECREF(((PyObject *)p->fda)); + Py_XDECREF(((PyObject *)p->eda)); + Py_XDECREF(((PyObject *)p->alignment)); + Py_XDECREF(((PyObject *)p->eid2symid)); + Py_XDECREF(((PyObject *)p->fid2symid)); + Py_XDECREF(((PyObject *)p->findexes)); + Py_XDECREF(((PyObject *)p->findexes1)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_3_sa_HieroCachingRuleFactory(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa_HieroCachingRuleFactory *p = (struct __pyx_obj_3_sa_HieroCachingRuleFactory *)o; + if (p->rules) { + e = (*v)(((PyObject*)p->rules), a); if (e) return e; + } + if (p->sampler) { + e = (*v)(((PyObject*)p->sampler), a); if (e) return e; + } + if (p->precomputed_index) { + e = (*v)(p->precomputed_index, a); if (e) return e; + } + if (p->precomputed_collocations) { + e = (*v)(p->precomputed_collocations, a); if (e) return e; + } + if (p->precompute_file) { + e = (*v)(p->precompute_file, a); if (e) return e; + } + if (p->max_rank) { + e = (*v)(p->max_rank, a); if (e) return e; + } + if (p->prev_norm_prefix) { + e = (*v)(p->prev_norm_prefix, a); if (e) return e; + } + if (p->fsa) { + e = (*v)(((PyObject*)p->fsa), a); if (e) return e; + } + if (p->fda) { + e = (*v)(((PyObject*)p->fda), a); if (e) return e; + } + if (p->eda) { + e = (*v)(((PyObject*)p->eda), a); if (e) return e; + } + if (p->alignment) { + e = (*v)(((PyObject*)p->alignment), a); if (e) return e; + } + if (p->eid2symid) { + e = (*v)(((PyObject*)p->eid2symid), a); if (e) return e; + } + if (p->fid2symid) { + e = (*v)(((PyObject*)p->fid2symid), a); if (e) return e; + } + if (p->findexes) { + e = (*v)(((PyObject*)p->findexes), a); if (e) return e; + } + if (p->findexes1) { + e = (*v)(((PyObject*)p->findexes1), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa_HieroCachingRuleFactory(PyObject *o) { + struct __pyx_obj_3_sa_HieroCachingRuleFactory *p = (struct __pyx_obj_3_sa_HieroCachingRuleFactory *)o; + PyObject* tmp; + tmp = ((PyObject*)p->rules); + p->rules = ((struct __pyx_obj_3_sa_TrieTable *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->sampler); + p->sampler = ((struct __pyx_obj_3_sa_Sampler *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->precomputed_index); + p->precomputed_index = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->precomputed_collocations); + p->precomputed_collocations = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->precompute_file); + p->precompute_file = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->max_rank); + p->max_rank = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->prev_norm_prefix); + p->prev_norm_prefix = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->fsa); + p->fsa = ((struct __pyx_obj_3_sa_SuffixArray *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->fda); + p->fda = ((struct __pyx_obj_3_sa_DataArray *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->eda); + p->eda = ((struct __pyx_obj_3_sa_DataArray *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->alignment); + p->alignment = ((struct __pyx_obj_3_sa_Alignment *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->eid2symid); + p->eid2symid = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->fid2symid); + p->fid2symid = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->findexes); + p->findexes = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->findexes1); + p->findexes1 = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_3_sa_HieroCachingRuleFactory[] = { + {__Pyx_NAMESTR("configure"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_3configure, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_3_sa_23HieroCachingRuleFactory_2configure)}, + {__Pyx_NAMESTR("pattern2phrase"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_5pattern2phrase, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("pattern2phrase_plus"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_7pattern2phrase_plus, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("precompute"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_9precompute, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_precomputed_collocation"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_11get_precomputed_collocation, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("advance"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_13advance, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_all_nodes_isteps_away"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_15get_all_nodes_isteps_away, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("reachable"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_17reachable, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("shortest"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_19shortest, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_next_states"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_21get_next_states, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("input"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_23input, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_3_sa_23HieroCachingRuleFactory_22input)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_HieroCachingRuleFactory = { + 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_HieroCachingRuleFactory = { + 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_HieroCachingRuleFactory = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_HieroCachingRuleFactory = { + #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_3_sa_HieroCachingRuleFactory = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.HieroCachingRuleFactory"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_HieroCachingRuleFactory), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_HieroCachingRuleFactory, /*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_HieroCachingRuleFactory, /*tp_as_number*/ + &__pyx_tp_as_sequence_HieroCachingRuleFactory, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_HieroCachingRuleFactory, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_HieroCachingRuleFactory, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + __Pyx_DOCSTR("This RuleFactory implements a caching \n method using TrieTable, which makes phrase\n generation somewhat speedier -- phrases only\n need to be extracted once (however, it is\n quite possible they need to be scored \n for each input sentence, for contextual models)"), /*tp_doc*/ + __pyx_tp_traverse_3_sa_HieroCachingRuleFactory, /*tp_traverse*/ + __pyx_tp_clear_3_sa_HieroCachingRuleFactory, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_HieroCachingRuleFactory, /*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_3_sa_HieroCachingRuleFactory, /*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_3_sa___pyx_scope_struct__compute_stats(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *)o); + p->__pyx_v_ngram = 0; + p->__pyx_v_ngram_start = 0; + p->__pyx_v_ngram_starts = 0; + p->__pyx_v_run_start = 0; + p->__pyx_v_self = 0; + p->__pyx_v_veb = 0; + return o; +} + +static void __pyx_tp_dealloc_3_sa___pyx_scope_struct__compute_stats(PyObject *o) { + struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *p = (struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_ngram)); + Py_XDECREF(((PyObject *)p->__pyx_v_ngram_start)); + Py_XDECREF(((PyObject *)p->__pyx_v_ngram_starts)); + Py_XDECREF(((PyObject *)p->__pyx_v_run_start)); + Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(((PyObject *)p->__pyx_v_veb)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_3_sa___pyx_scope_struct__compute_stats(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *p = (struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *)o; + if (p->__pyx_v_ngram) { + e = (*v)(p->__pyx_v_ngram, a); if (e) return e; + } + if (p->__pyx_v_ngram_start) { + e = (*v)(((PyObject*)p->__pyx_v_ngram_start), a); if (e) return e; + } + if (p->__pyx_v_ngram_starts) { + e = (*v)(p->__pyx_v_ngram_starts, a); if (e) return e; + } + if (p->__pyx_v_run_start) { + e = (*v)(((PyObject*)p->__pyx_v_run_start), 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_veb) { + e = (*v)(((PyObject*)p->__pyx_v_veb), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa___pyx_scope_struct__compute_stats(PyObject *o) { + struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *p = (struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_ngram); + p->__pyx_v_ngram = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_ngram_start); + p->__pyx_v_ngram_start = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_ngram_starts); + p->__pyx_v_ngram_starts = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_run_start); + p->__pyx_v_run_start = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_3_sa_LCP *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_veb); + p->__pyx_v_veb = ((struct __pyx_obj_3_sa_VEB *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_3_sa___pyx_scope_struct__compute_stats[] = { + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct__compute_stats = { + 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__compute_stats = { + 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__compute_stats = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct__compute_stats = { + #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_3_sa___pyx_scope_struct__compute_stats = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.__pyx_scope_struct__compute_stats"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa___pyx_scope_struct__compute_stats, /*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__compute_stats, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct__compute_stats, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct__compute_stats, /*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__compute_stats, /*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_3_sa___pyx_scope_struct__compute_stats, /*tp_traverse*/ + __pyx_tp_clear_3_sa___pyx_scope_struct__compute_stats, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa___pyx_scope_struct__compute_stats, /*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_3_sa___pyx_scope_struct__compute_stats, /*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_3_sa___pyx_scope_struct_1___iter__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *)o); + p->__pyx_v_self = 0; + return o; +} + +static void __pyx_tp_dealloc_3_sa___pyx_scope_struct_1___iter__(PyObject *o) { + struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_3_sa___pyx_scope_struct_1___iter__(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa___pyx_scope_struct_1___iter__(PyObject *o) { + struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_3_sa_Phrase *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_3_sa___pyx_scope_struct_1___iter__[] = { + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { + 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___iter__ = { + 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___iter__ = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { + #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_3_sa___pyx_scope_struct_1___iter__ = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.__pyx_scope_struct_1___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa___pyx_scope_struct_1___iter__, /*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___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_1___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_1___iter__, /*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___iter__, /*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_3_sa___pyx_scope_struct_1___iter__, /*tp_traverse*/ + __pyx_tp_clear_3_sa___pyx_scope_struct_1___iter__, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa___pyx_scope_struct_1___iter__, /*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_3_sa___pyx_scope_struct_1___iter__, /*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_3_sa___pyx_scope_struct_2_input(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_3_sa___pyx_scope_struct_2_input *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa___pyx_scope_struct_2_input *)o); + p->__pyx_v_alignment = 0; + p->__pyx_v_als = 0; + p->__pyx_v_alslist = 0; + p->__pyx_v_chunklen = 0; + p->__pyx_v_count = 0; + p->__pyx_v_currcount = 0; + p->__pyx_v_e = 0; + p->__pyx_v_elist = 0; + p->__pyx_v_extract = 0; + p->__pyx_v_extract_start = 0; + p->__pyx_v_extract_stop = 0; + p->__pyx_v_extracts = 0; + p->__pyx_v_f = 0; + p->__pyx_v_f_margin = 0; + p->__pyx_v_fals = 0; + p->__pyx_v_fcount = 0; + p->__pyx_v_fphrases = 0; + p->__pyx_v_frontier = 0; + p->__pyx_v_frontier_nodes = 0; + p->__pyx_v_fwords = 0; + p->__pyx_v_hiero_phrase = 0; + p->__pyx_v_is_shadow_path = 0; + p->__pyx_v_key = 0; + p->__pyx_v_model = 0; + p->__pyx_v_models = 0; + p->__pyx_v_new_frontier = 0; + p->__pyx_v_new_node = 0; + p->__pyx_v_next_states = 0; + p->__pyx_v_node = 0; + p->__pyx_v_nodes_isteps_away_buffer = 0; + p->__pyx_v_pathlen = 0; + p->__pyx_v_phrase = 0; + p->__pyx_v_phrase_location = 0; + p->__pyx_v_prefix = 0; + p->__pyx_v_reachable_buffer = 0; + p->__pyx_v_sa_range = 0; + p->__pyx_v_sample = 0; + p->__pyx_v_scores = 0; + p->__pyx_v_self = 0; + p->__pyx_v_spanlen = 0; + p->__pyx_v_stop_time = 0; + p->__pyx_v_suffix_link = 0; + p->__pyx_v_suffix_link_xcat_index = 0; + p->__pyx_v_word_id = 0; + p->__pyx_v_xcat_index = 0; + p->__pyx_v_xnode = 0; + p->__pyx_v_xroot = 0; + p->__pyx_t_1 = 0; + p->__pyx_t_4 = 0; + p->__pyx_t_5 = 0; + return o; +} + +static void __pyx_tp_dealloc_3_sa___pyx_scope_struct_2_input(PyObject *o) { + struct __pyx_obj_3_sa___pyx_scope_struct_2_input *p = (struct __pyx_obj_3_sa___pyx_scope_struct_2_input *)o; + Py_XDECREF(p->__pyx_v_alignment); + Py_XDECREF(p->__pyx_v_als); + Py_XDECREF(p->__pyx_v_alslist); + Py_XDECREF(((PyObject *)p->__pyx_v_chunklen)); + Py_XDECREF(p->__pyx_v_count); + Py_XDECREF(p->__pyx_v_currcount); + Py_XDECREF(p->__pyx_v_e); + Py_XDECREF(p->__pyx_v_elist); + Py_XDECREF(p->__pyx_v_extract); + Py_XDECREF(p->__pyx_v_extract_start); + Py_XDECREF(p->__pyx_v_extract_stop); + Py_XDECREF(((PyObject *)p->__pyx_v_extracts)); + Py_XDECREF(p->__pyx_v_f); + Py_XDECREF(p->__pyx_v_f_margin); + Py_XDECREF(((PyObject *)p->__pyx_v_fals)); + Py_XDECREF(((PyObject *)p->__pyx_v_fcount)); + Py_XDECREF(((PyObject *)p->__pyx_v_fphrases)); + Py_XDECREF(((PyObject *)p->__pyx_v_frontier)); + Py_XDECREF(p->__pyx_v_frontier_nodes); + Py_XDECREF(p->__pyx_v_fwords); + Py_XDECREF(((PyObject *)p->__pyx_v_hiero_phrase)); + Py_XDECREF(p->__pyx_v_is_shadow_path); + Py_XDECREF(((PyObject *)p->__pyx_v_key)); + Py_XDECREF(p->__pyx_v_model); + Py_XDECREF(p->__pyx_v_models); + Py_XDECREF(((PyObject *)p->__pyx_v_new_frontier)); + Py_XDECREF(p->__pyx_v_new_node); + Py_XDECREF(((PyObject *)p->__pyx_v_next_states)); + Py_XDECREF(p->__pyx_v_node); + Py_XDECREF(((PyObject *)p->__pyx_v_nodes_isteps_away_buffer)); + Py_XDECREF(p->__pyx_v_pathlen); + Py_XDECREF(p->__pyx_v_phrase); + Py_XDECREF(((PyObject *)p->__pyx_v_phrase_location)); + Py_XDECREF(p->__pyx_v_prefix); + Py_XDECREF(((PyObject *)p->__pyx_v_reachable_buffer)); + Py_XDECREF(p->__pyx_v_sa_range); + Py_XDECREF(((PyObject *)p->__pyx_v_sample)); + Py_XDECREF(((PyObject *)p->__pyx_v_scores)); + Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(p->__pyx_v_spanlen); + Py_XDECREF(p->__pyx_v_stop_time); + Py_XDECREF(p->__pyx_v_suffix_link); + Py_XDECREF(p->__pyx_v_suffix_link_xcat_index); + Py_XDECREF(p->__pyx_v_word_id); + Py_XDECREF(p->__pyx_v_xcat_index); + Py_XDECREF(p->__pyx_v_xnode); + Py_XDECREF(p->__pyx_v_xroot); + Py_XDECREF(p->__pyx_t_1); + Py_XDECREF(p->__pyx_t_4); + Py_XDECREF(p->__pyx_t_5); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_3_sa___pyx_scope_struct_2_input(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa___pyx_scope_struct_2_input *p = (struct __pyx_obj_3_sa___pyx_scope_struct_2_input *)o; + if (p->__pyx_v_alignment) { + e = (*v)(p->__pyx_v_alignment, a); if (e) return e; + } + if (p->__pyx_v_als) { + e = (*v)(p->__pyx_v_als, a); if (e) return e; + } + if (p->__pyx_v_alslist) { + e = (*v)(p->__pyx_v_alslist, a); if (e) return e; + } + if (p->__pyx_v_chunklen) { + e = (*v)(((PyObject*)p->__pyx_v_chunklen), a); if (e) return e; + } + if (p->__pyx_v_count) { + e = (*v)(p->__pyx_v_count, a); if (e) return e; + } + if (p->__pyx_v_currcount) { + e = (*v)(p->__pyx_v_currcount, a); if (e) return e; + } + if (p->__pyx_v_e) { + e = (*v)(p->__pyx_v_e, a); if (e) return e; + } + if (p->__pyx_v_elist) { + e = (*v)(p->__pyx_v_elist, a); if (e) return e; + } + if (p->__pyx_v_extract) { + e = (*v)(p->__pyx_v_extract, a); if (e) return e; + } + if (p->__pyx_v_extract_start) { + e = (*v)(p->__pyx_v_extract_start, a); if (e) return e; + } + if (p->__pyx_v_extract_stop) { + e = (*v)(p->__pyx_v_extract_stop, a); if (e) return e; + } + if (p->__pyx_v_extracts) { + e = (*v)(p->__pyx_v_extracts, a); if (e) return e; + } + if (p->__pyx_v_f) { + e = (*v)(p->__pyx_v_f, a); if (e) return e; + } + if (p->__pyx_v_f_margin) { + e = (*v)(p->__pyx_v_f_margin, a); if (e) return e; + } + if (p->__pyx_v_fals) { + e = (*v)(p->__pyx_v_fals, a); if (e) return e; + } + if (p->__pyx_v_fcount) { + e = (*v)(p->__pyx_v_fcount, a); if (e) return e; + } + if (p->__pyx_v_fphrases) { + e = (*v)(p->__pyx_v_fphrases, a); if (e) return e; + } + if (p->__pyx_v_frontier) { + e = (*v)(p->__pyx_v_frontier, a); if (e) return e; + } + if (p->__pyx_v_frontier_nodes) { + e = (*v)(p->__pyx_v_frontier_nodes, a); if (e) return e; + } + if (p->__pyx_v_fwords) { + e = (*v)(p->__pyx_v_fwords, a); if (e) return e; + } + if (p->__pyx_v_hiero_phrase) { + e = (*v)(((PyObject*)p->__pyx_v_hiero_phrase), a); if (e) return e; + } + if (p->__pyx_v_is_shadow_path) { + e = (*v)(p->__pyx_v_is_shadow_path, a); if (e) return e; + } + if (p->__pyx_v_key) { + e = (*v)(p->__pyx_v_key, a); if (e) return e; + } + if (p->__pyx_v_model) { + e = (*v)(p->__pyx_v_model, a); if (e) return e; + } + if (p->__pyx_v_models) { + e = (*v)(p->__pyx_v_models, a); if (e) return e; + } + if (p->__pyx_v_new_frontier) { + e = (*v)(p->__pyx_v_new_frontier, a); if (e) return e; + } + if (p->__pyx_v_new_node) { + e = (*v)(p->__pyx_v_new_node, a); if (e) return e; + } + if (p->__pyx_v_next_states) { + e = (*v)(p->__pyx_v_next_states, a); if (e) return e; + } + if (p->__pyx_v_node) { + e = (*v)(p->__pyx_v_node, a); if (e) return e; + } + if (p->__pyx_v_nodes_isteps_away_buffer) { + e = (*v)(p->__pyx_v_nodes_isteps_away_buffer, a); if (e) return e; + } + if (p->__pyx_v_pathlen) { + e = (*v)(p->__pyx_v_pathlen, a); if (e) return e; + } + if (p->__pyx_v_phrase) { + e = (*v)(p->__pyx_v_phrase, a); if (e) return e; + } + if (p->__pyx_v_phrase_location) { + e = (*v)(((PyObject*)p->__pyx_v_phrase_location), a); if (e) return e; + } + if (p->__pyx_v_prefix) { + e = (*v)(p->__pyx_v_prefix, a); if (e) return e; + } + if (p->__pyx_v_reachable_buffer) { + e = (*v)(p->__pyx_v_reachable_buffer, a); if (e) return e; + } + if (p->__pyx_v_sa_range) { + e = (*v)(p->__pyx_v_sa_range, a); if (e) return e; + } + if (p->__pyx_v_sample) { + e = (*v)(((PyObject*)p->__pyx_v_sample), a); if (e) return e; + } + if (p->__pyx_v_scores) { + e = (*v)(p->__pyx_v_scores, 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_spanlen) { + e = (*v)(p->__pyx_v_spanlen, a); if (e) return e; + } + if (p->__pyx_v_stop_time) { + e = (*v)(p->__pyx_v_stop_time, a); if (e) return e; + } + if (p->__pyx_v_suffix_link) { + e = (*v)(p->__pyx_v_suffix_link, a); if (e) return e; + } + if (p->__pyx_v_suffix_link_xcat_index) { + e = (*v)(p->__pyx_v_suffix_link_xcat_index, a); if (e) return e; + } + if (p->__pyx_v_word_id) { + e = (*v)(p->__pyx_v_word_id, a); if (e) return e; + } + if (p->__pyx_v_xcat_index) { + e = (*v)(p->__pyx_v_xcat_index, a); if (e) return e; + } + if (p->__pyx_v_xnode) { + e = (*v)(p->__pyx_v_xnode, a); if (e) return e; + } + if (p->__pyx_v_xroot) { + e = (*v)(p->__pyx_v_xroot, a); if (e) return e; + } + if (p->__pyx_t_1) { + e = (*v)(p->__pyx_t_1, a); if (e) return e; + } + if (p->__pyx_t_4) { + e = (*v)(p->__pyx_t_4, a); if (e) return e; + } + if (p->__pyx_t_5) { + e = (*v)(p->__pyx_t_5, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa___pyx_scope_struct_2_input(PyObject *o) { + struct __pyx_obj_3_sa___pyx_scope_struct_2_input *p = (struct __pyx_obj_3_sa___pyx_scope_struct_2_input *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_alignment); + p->__pyx_v_alignment = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_als); + p->__pyx_v_als = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_alslist); + p->__pyx_v_alslist = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_chunklen); + p->__pyx_v_chunklen = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_count); + p->__pyx_v_count = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_currcount); + p->__pyx_v_currcount = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_e); + p->__pyx_v_e = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_elist); + p->__pyx_v_elist = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_extract); + p->__pyx_v_extract = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_extract_start); + p->__pyx_v_extract_start = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_extract_stop); + p->__pyx_v_extract_stop = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_extracts); + p->__pyx_v_extracts = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_f); + p->__pyx_v_f = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_f_margin); + p->__pyx_v_f_margin = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_fals); + p->__pyx_v_fals = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_fcount); + p->__pyx_v_fcount = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_fphrases); + p->__pyx_v_fphrases = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_frontier); + p->__pyx_v_frontier = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_frontier_nodes); + p->__pyx_v_frontier_nodes = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_fwords); + p->__pyx_v_fwords = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_hiero_phrase); + p->__pyx_v_hiero_phrase = ((struct __pyx_obj_3_sa_Phrase *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_is_shadow_path); + p->__pyx_v_is_shadow_path = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_key); + p->__pyx_v_key = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_model); + p->__pyx_v_model = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_models); + p->__pyx_v_models = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_new_frontier); + p->__pyx_v_new_frontier = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_new_node); + p->__pyx_v_new_node = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_next_states); + p->__pyx_v_next_states = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_node); + p->__pyx_v_node = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_nodes_isteps_away_buffer); + p->__pyx_v_nodes_isteps_away_buffer = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_pathlen); + p->__pyx_v_pathlen = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_phrase); + p->__pyx_v_phrase = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_phrase_location); + p->__pyx_v_phrase_location = ((struct __pyx_obj_3_sa_PhraseLocation *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_prefix); + p->__pyx_v_prefix = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_reachable_buffer); + p->__pyx_v_reachable_buffer = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_sa_range); + p->__pyx_v_sa_range = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_sample); + p->__pyx_v_sample = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_scores); + p->__pyx_v_scores = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_3_sa_HieroCachingRuleFactory *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_spanlen); + p->__pyx_v_spanlen = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_stop_time); + p->__pyx_v_stop_time = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_suffix_link); + p->__pyx_v_suffix_link = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_suffix_link_xcat_index); + p->__pyx_v_suffix_link_xcat_index = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_word_id); + p->__pyx_v_word_id = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_xcat_index); + p->__pyx_v_xcat_index = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_xnode); + p->__pyx_v_xnode = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_xroot); + p->__pyx_v_xroot = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_1); + p->__pyx_t_1 = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_4); + p->__pyx_t_4 = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_5); + p->__pyx_t_5 = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_3_sa___pyx_scope_struct_2_input[] = { + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_input = { + 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_input = { + 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_input = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_input = { + #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_3_sa___pyx_scope_struct_2_input = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.__pyx_scope_struct_2_input"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa___pyx_scope_struct_2_input), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa___pyx_scope_struct_2_input, /*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_input, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_2_input, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_2_input, /*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_input, /*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_3_sa___pyx_scope_struct_2_input, /*tp_traverse*/ + __pyx_tp_clear_3_sa___pyx_scope_struct_2_input, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa___pyx_scope_struct_2_input, /*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_3_sa___pyx_scope_struct_2_input, /*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} +}; + +#if PY_MAJOR_VERSION >= 3 +static struct PyModuleDef __pyx_moduledef = { + PyModuleDef_HEAD_INIT, + __Pyx_NAMESTR("_sa"), + 0, /* m_doc */ + -1, /* m_size */ + __pyx_methods /* m_methods */, + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ +}; +#endif + +static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0}, + {&__pyx_n_s_101, __pyx_k_101, sizeof(__pyx_k_101), 0, 0, 1, 1}, + {&__pyx_n_s_102, __pyx_k_102, sizeof(__pyx_k_102), 0, 0, 1, 1}, + {&__pyx_kp_s_104, __pyx_k_104, sizeof(__pyx_k_104), 0, 0, 1, 0}, + {&__pyx_kp_s_106, __pyx_k_106, sizeof(__pyx_k_106), 0, 0, 1, 0}, + {&__pyx_kp_s_107, __pyx_k_107, sizeof(__pyx_k_107), 0, 0, 1, 0}, + {&__pyx_kp_s_108, __pyx_k_108, sizeof(__pyx_k_108), 0, 0, 1, 0}, + {&__pyx_kp_s_109, __pyx_k_109, sizeof(__pyx_k_109), 0, 0, 1, 0}, + {&__pyx_kp_s_110, __pyx_k_110, sizeof(__pyx_k_110), 0, 0, 1, 0}, + {&__pyx_kp_s_111, __pyx_k_111, sizeof(__pyx_k_111), 0, 0, 1, 0}, + {&__pyx_kp_s_112, __pyx_k_112, sizeof(__pyx_k_112), 0, 0, 1, 0}, + {&__pyx_kp_s_113, __pyx_k_113, sizeof(__pyx_k_113), 0, 0, 1, 0}, + {&__pyx_kp_s_114, __pyx_k_114, sizeof(__pyx_k_114), 0, 0, 1, 0}, + {&__pyx_kp_s_115, __pyx_k_115, sizeof(__pyx_k_115), 0, 0, 1, 0}, + {&__pyx_kp_s_116, __pyx_k_116, sizeof(__pyx_k_116), 0, 0, 1, 0}, + {&__pyx_n_s_117, __pyx_k_117, sizeof(__pyx_k_117), 0, 0, 1, 1}, + {&__pyx_kp_s_118, __pyx_k_118, sizeof(__pyx_k_118), 0, 0, 1, 0}, + {&__pyx_kp_s_119, __pyx_k_119, sizeof(__pyx_k_119), 0, 0, 1, 0}, + {&__pyx_n_s_121, __pyx_k_121, sizeof(__pyx_k_121), 0, 0, 1, 1}, + {&__pyx_kp_s_122, __pyx_k_122, sizeof(__pyx_k_122), 0, 0, 1, 0}, + {&__pyx_kp_s_123, __pyx_k_123, sizeof(__pyx_k_123), 0, 0, 1, 0}, + {&__pyx_kp_s_124, __pyx_k_124, sizeof(__pyx_k_124), 0, 0, 1, 0}, + {&__pyx_kp_s_125, __pyx_k_125, sizeof(__pyx_k_125), 0, 0, 1, 0}, + {&__pyx_kp_s_126, __pyx_k_126, sizeof(__pyx_k_126), 0, 0, 1, 0}, + {&__pyx_kp_s_127, __pyx_k_127, sizeof(__pyx_k_127), 0, 0, 1, 0}, + {&__pyx_kp_s_128, __pyx_k_128, sizeof(__pyx_k_128), 0, 0, 1, 0}, + {&__pyx_kp_s_129, __pyx_k_129, sizeof(__pyx_k_129), 0, 0, 1, 0}, + {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0}, + {&__pyx_kp_s_130, __pyx_k_130, sizeof(__pyx_k_130), 0, 0, 1, 0}, + {&__pyx_kp_s_131, __pyx_k_131, sizeof(__pyx_k_131), 0, 0, 1, 0}, + {&__pyx_kp_s_134, __pyx_k_134, sizeof(__pyx_k_134), 0, 0, 1, 0}, + {&__pyx_kp_s_135, __pyx_k_135, sizeof(__pyx_k_135), 0, 0, 1, 0}, + {&__pyx_kp_s_139, __pyx_k_139, sizeof(__pyx_k_139), 0, 0, 1, 0}, + {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0}, + {&__pyx_kp_s_140, __pyx_k_140, sizeof(__pyx_k_140), 0, 0, 1, 0}, + {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0}, + {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0}, + {&__pyx_kp_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 0}, + {&__pyx_n_s_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 1, 1}, + {&__pyx_kp_s_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 0, 1, 0}, + {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0}, + {&__pyx_kp_s_32, __pyx_k_32, sizeof(__pyx_k_32), 0, 0, 1, 0}, + {&__pyx_kp_s_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 1, 0}, + {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0}, + {&__pyx_kp_s_42, __pyx_k_42, sizeof(__pyx_k_42), 0, 0, 1, 0}, + {&__pyx_kp_s_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 1, 0}, + {&__pyx_kp_s_45, __pyx_k_45, sizeof(__pyx_k_45), 0, 0, 1, 0}, + {&__pyx_kp_s_47, __pyx_k_47, sizeof(__pyx_k_47), 0, 0, 1, 0}, + {&__pyx_kp_s_49, __pyx_k_49, sizeof(__pyx_k_49), 0, 0, 1, 0}, + {&__pyx_kp_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 0}, + {&__pyx_kp_s_53, __pyx_k_53, sizeof(__pyx_k_53), 0, 0, 1, 0}, + {&__pyx_kp_s_55, __pyx_k_55, sizeof(__pyx_k_55), 0, 0, 1, 0}, + {&__pyx_kp_s_56, __pyx_k_56, sizeof(__pyx_k_56), 0, 0, 1, 0}, + {&__pyx_kp_s_57, __pyx_k_57, sizeof(__pyx_k_57), 0, 0, 1, 0}, + {&__pyx_kp_s_59, __pyx_k_59, sizeof(__pyx_k_59), 0, 0, 1, 0}, + {&__pyx_kp_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 0}, + {&__pyx_kp_s_61, __pyx_k_61, sizeof(__pyx_k_61), 0, 0, 1, 0}, + {&__pyx_kp_s_62, __pyx_k_62, sizeof(__pyx_k_62), 0, 0, 1, 0}, + {&__pyx_kp_s_63, __pyx_k_63, sizeof(__pyx_k_63), 0, 0, 1, 0}, + {&__pyx_kp_s_64, __pyx_k_64, sizeof(__pyx_k_64), 0, 0, 1, 0}, + {&__pyx_kp_s_65, __pyx_k_65, sizeof(__pyx_k_65), 0, 0, 1, 0}, + {&__pyx_kp_s_66, __pyx_k_66, sizeof(__pyx_k_66), 0, 0, 1, 0}, + {&__pyx_kp_s_67, __pyx_k_67, sizeof(__pyx_k_67), 0, 0, 1, 0}, + {&__pyx_n_s_68, __pyx_k_68, sizeof(__pyx_k_68), 0, 0, 1, 1}, + {&__pyx_n_s_69, __pyx_k_69, sizeof(__pyx_k_69), 0, 0, 1, 1}, + {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0}, + {&__pyx_kp_s_70, __pyx_k_70, sizeof(__pyx_k_70), 0, 0, 1, 0}, + {&__pyx_kp_s_72, __pyx_k_72, sizeof(__pyx_k_72), 0, 0, 1, 0}, + {&__pyx_kp_s_74, __pyx_k_74, sizeof(__pyx_k_74), 0, 0, 1, 0}, + {&__pyx_kp_s_76, __pyx_k_76, sizeof(__pyx_k_76), 0, 0, 1, 0}, + {&__pyx_kp_s_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 1, 0}, + {&__pyx_kp_s_81, __pyx_k_81, sizeof(__pyx_k_81), 0, 0, 1, 0}, + {&__pyx_kp_s_82, __pyx_k_82, sizeof(__pyx_k_82), 0, 0, 1, 0}, + {&__pyx_kp_s_83, __pyx_k_83, sizeof(__pyx_k_83), 0, 0, 1, 0}, + {&__pyx_kp_s_84, __pyx_k_84, sizeof(__pyx_k_84), 0, 0, 1, 0}, + {&__pyx_kp_s_85, __pyx_k_85, sizeof(__pyx_k_85), 0, 0, 1, 0}, + {&__pyx_kp_s_86, __pyx_k_86, sizeof(__pyx_k_86), 0, 0, 1, 0}, + {&__pyx_kp_s_87, __pyx_k_87, sizeof(__pyx_k_87), 0, 0, 1, 0}, + {&__pyx_kp_s_88, __pyx_k_88, sizeof(__pyx_k_88), 0, 0, 1, 0}, + {&__pyx_kp_s_89, __pyx_k_89, sizeof(__pyx_k_89), 0, 0, 1, 0}, + {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0}, + {&__pyx_kp_s_90, __pyx_k_90, sizeof(__pyx_k_90), 0, 0, 1, 0}, + {&__pyx_kp_s_92, __pyx_k_92, sizeof(__pyx_k_92), 0, 0, 1, 0}, + {&__pyx_kp_s_93, __pyx_k_93, sizeof(__pyx_k_93), 0, 0, 1, 0}, + {&__pyx_kp_s_98, __pyx_k_98, sizeof(__pyx_k_98), 0, 0, 1, 0}, + {&__pyx_kp_s_99, __pyx_k_99, sizeof(__pyx_k_99), 0, 0, 1, 0}, + {&__pyx_kp_s__0, __pyx_k__0, sizeof(__pyx_k__0), 0, 0, 1, 0}, + {&__pyx_kp_s__1, __pyx_k__1, sizeof(__pyx_k__1), 0, 0, 1, 0}, + {&__pyx_n_s__END_OF_FILE, __pyx_k__END_OF_FILE, sizeof(__pyx_k__END_OF_FILE), 0, 0, 1, 1}, + {&__pyx_n_s__END_OF_LINE, __pyx_k__END_OF_LINE, sizeof(__pyx_k__END_OF_LINE), 0, 0, 1, 1}, + {&__pyx_n_s__Exception, __pyx_k__Exception, sizeof(__pyx_k__Exception), 0, 0, 1, 1}, + {&__pyx_n_s__GzipFile, __pyx_k__GzipFile, sizeof(__pyx_k__GzipFile), 0, 0, 1, 1}, + {&__pyx_n_s__IndexError, __pyx_k__IndexError, sizeof(__pyx_k__IndexError), 0, 0, 1, 1}, + {&__pyx_n_s__NULL, __pyx_k__NULL, sizeof(__pyx_k__NULL), 0, 0, 1, 1}, + {&__pyx_n_s__RUSAGE_SELF, __pyx_k__RUSAGE_SELF, sizeof(__pyx_k__RUSAGE_SELF), 0, 0, 1, 1}, + {&__pyx_n_s__StopIteration, __pyx_k__StopIteration, sizeof(__pyx_k__StopIteration), 0, 0, 1, 1}, + {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1}, + {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, + {&__pyx_n_s____enter__, __pyx_k____enter__, sizeof(__pyx_k____enter__), 0, 0, 1, 1}, + {&__pyx_n_s____exit__, __pyx_k____exit__, sizeof(__pyx_k____exit__), 0, 0, 1, 1}, + {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, + {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, + {&__pyx_n_s___columns, __pyx_k___columns, sizeof(__pyx_k___columns), 0, 0, 1, 1}, + {&__pyx_n_s___doquicksort, __pyx_k___doquicksort, sizeof(__pyx_k___doquicksort), 0, 0, 1, 1}, + {&__pyx_n_s___sa, __pyx_k___sa, sizeof(__pyx_k___sa), 0, 0, 1, 1}, + {&__pyx_n_s__advance, __pyx_k__advance, sizeof(__pyx_k__advance), 0, 0, 1, 1}, + {&__pyx_n_s__alignment, __pyx_k__alignment, sizeof(__pyx_k__alignment), 0, 0, 1, 1}, + {&__pyx_n_s__alphabet_size, __pyx_k__alphabet_size, sizeof(__pyx_k__alphabet_size), 0, 0, 1, 1}, + {&__pyx_n_s__arity, __pyx_k__arity, sizeof(__pyx_k__arity), 0, 0, 1, 1}, + {&__pyx_n_s__arr, __pyx_k__arr, sizeof(__pyx_k__arr), 0, 0, 1, 1}, + {&__pyx_n_s__arr_high, __pyx_k__arr_high, sizeof(__pyx_k__arr_high), 0, 0, 1, 1}, + {&__pyx_n_s__arr_low, __pyx_k__arr_low, sizeof(__pyx_k__arr_low), 0, 0, 1, 1}, + {&__pyx_n_s__by_slack_factor, __pyx_k__by_slack_factor, sizeof(__pyx_k__by_slack_factor), 0, 0, 1, 1}, + {&__pyx_n_s__category, __pyx_k__category, sizeof(__pyx_k__category), 0, 0, 1, 1}, + {&__pyx_n_s__children, __pyx_k__children, sizeof(__pyx_k__children), 0, 0, 1, 1}, + {&__pyx_n_s__cmp, __pyx_k__cmp, sizeof(__pyx_k__cmp), 0, 0, 1, 1}, + {&__pyx_n_s__col, __pyx_k__col, sizeof(__pyx_k__col), 0, 0, 1, 1}, + {&__pyx_n_s__collect, __pyx_k__collect, sizeof(__pyx_k__collect), 0, 0, 1, 1}, + {&__pyx_n_s__curr_idx, __pyx_k__curr_idx, sizeof(__pyx_k__curr_idx), 0, 0, 1, 1}, + {&__pyx_n_s__debug, __pyx_k__debug, sizeof(__pyx_k__debug), 0, 0, 1, 1}, + {&__pyx_n_s__dist, __pyx_k__dist, sizeof(__pyx_k__dist), 0, 0, 1, 1}, + {&__pyx_n_s__e, __pyx_k__e, sizeof(__pyx_k__e), 0, 0, 1, 1}, + {&__pyx_n_s__earray, __pyx_k__earray, sizeof(__pyx_k__earray), 0, 0, 1, 1}, + {&__pyx_n_s__edarray, __pyx_k__edarray, sizeof(__pyx_k__edarray), 0, 0, 1, 1}, + {&__pyx_n_s__end, __pyx_k__end, sizeof(__pyx_k__end), 0, 0, 1, 1}, + {&__pyx_n_s__enumerate, __pyx_k__enumerate, sizeof(__pyx_k__enumerate), 0, 0, 1, 1}, + {&__pyx_n_s__eword, __pyx_k__eword, sizeof(__pyx_k__eword), 0, 0, 1, 1}, + {&__pyx_n_s__extend, __pyx_k__extend, sizeof(__pyx_k__extend), 0, 0, 1, 1}, + {&__pyx_n_s__extended, __pyx_k__extended, sizeof(__pyx_k__extended), 0, 0, 1, 1}, + {&__pyx_n_s__f, __pyx_k__f, sizeof(__pyx_k__f), 0, 0, 1, 1}, + {&__pyx_n_s__filename, __pyx_k__filename, sizeof(__pyx_k__filename), 0, 0, 1, 1}, + {&__pyx_n_s__from_binary, __pyx_k__from_binary, sizeof(__pyx_k__from_binary), 0, 0, 1, 1}, + {&__pyx_n_s__from_data, __pyx_k__from_data, sizeof(__pyx_k__from_data), 0, 0, 1, 1}, + {&__pyx_n_s__from_stats, __pyx_k__from_stats, sizeof(__pyx_k__from_stats), 0, 0, 1, 1}, + {&__pyx_n_s__from_text, __pyx_k__from_text, sizeof(__pyx_k__from_text), 0, 0, 1, 1}, + {&__pyx_n_s__frontier, __pyx_k__frontier, sizeof(__pyx_k__frontier), 0, 0, 1, 1}, + {&__pyx_n_s__fsarray, __pyx_k__fsarray, sizeof(__pyx_k__fsarray), 0, 0, 1, 1}, + {&__pyx_n_s__fword, __pyx_k__fword, sizeof(__pyx_k__fword), 0, 0, 1, 1}, + {&__pyx_n_s__fwords, __pyx_k__fwords, sizeof(__pyx_k__fwords), 0, 0, 1, 1}, + {&__pyx_n_s__gc, __pyx_k__gc, sizeof(__pyx_k__gc), 0, 0, 1, 1}, + {&__pyx_n_s__getLogger, __pyx_k__getLogger, sizeof(__pyx_k__getLogger), 0, 0, 1, 1}, + {&__pyx_n_s__getSent, __pyx_k__getSent, sizeof(__pyx_k__getSent), 0, 0, 1, 1}, + {&__pyx_n_s__getSentId, __pyx_k__getSentId, sizeof(__pyx_k__getSentId), 0, 0, 1, 1}, + {&__pyx_n_s__getSentPos, __pyx_k__getSentPos, sizeof(__pyx_k__getSentPos), 0, 0, 1, 1}, + {&__pyx_n_s__get_e_id, __pyx_k__get_e_id, sizeof(__pyx_k__get_e_id), 0, 0, 1, 1}, + {&__pyx_n_s__get_f_id, __pyx_k__get_f_id, sizeof(__pyx_k__get_f_id), 0, 0, 1, 1}, + {&__pyx_n_s__get_id, __pyx_k__get_id, sizeof(__pyx_k__get_id), 0, 0, 1, 1}, + {&__pyx_n_s__get_next_states, __pyx_k__get_next_states, sizeof(__pyx_k__get_next_states), 0, 0, 1, 1}, + {&__pyx_n_s__get_word, __pyx_k__get_word, sizeof(__pyx_k__get_word), 0, 0, 1, 1}, + {&__pyx_n_s__getchunk, __pyx_k__getchunk, sizeof(__pyx_k__getchunk), 0, 0, 1, 1}, + {&__pyx_n_s__getrusage, __pyx_k__getrusage, sizeof(__pyx_k__getrusage), 0, 0, 1, 1}, + {&__pyx_n_s__gzip, __pyx_k__gzip, sizeof(__pyx_k__gzip), 0, 0, 1, 1}, + {&__pyx_n_s__gzip_or_text, __pyx_k__gzip_or_text, sizeof(__pyx_k__gzip_or_text), 0, 0, 1, 1}, + {&__pyx_n_s__h, __pyx_k__h, sizeof(__pyx_k__h), 0, 0, 1, 1}, + {&__pyx_n_s__high, __pyx_k__high, sizeof(__pyx_k__high), 0, 0, 1, 1}, + {&__pyx_n_s__i, __pyx_k__i, sizeof(__pyx_k__i), 0, 0, 1, 1}, + {&__pyx_n_s__ifrom, __pyx_k__ifrom, sizeof(__pyx_k__ifrom), 0, 0, 1, 1}, + {&__pyx_n_s__increment, __pyx_k__increment, sizeof(__pyx_k__increment), 0, 0, 1, 1}, + {&__pyx_n_s__index, __pyx_k__index, sizeof(__pyx_k__index), 0, 0, 1, 1}, + {&__pyx_n_s__info, __pyx_k__info, sizeof(__pyx_k__info), 0, 0, 1, 1}, + {&__pyx_n_s__initial_len, __pyx_k__initial_len, sizeof(__pyx_k__initial_len), 0, 0, 1, 1}, + {&__pyx_n_s__insert, __pyx_k__insert, sizeof(__pyx_k__insert), 0, 0, 1, 1}, + {&__pyx_n_s__isa, __pyx_k__isa, sizeof(__pyx_k__isa), 0, 0, 1, 1}, + {&__pyx_n_s__iteritems, __pyx_k__iteritems, sizeof(__pyx_k__iteritems), 0, 0, 1, 1}, + {&__pyx_n_s__ito, __pyx_k__ito, sizeof(__pyx_k__ito), 0, 0, 1, 1}, + {&__pyx_n_s__j, __pyx_k__j, sizeof(__pyx_k__j), 0, 0, 1, 1}, + {&__pyx_n_s__join, __pyx_k__join, sizeof(__pyx_k__join), 0, 0, 1, 1}, + {&__pyx_n_s__lhs, __pyx_k__lhs, sizeof(__pyx_k__lhs), 0, 0, 1, 1}, + {&__pyx_n_s__logger, __pyx_k__logger, sizeof(__pyx_k__logger), 0, 0, 1, 1}, + {&__pyx_n_s__logging, __pyx_k__logging, sizeof(__pyx_k__logging), 0, 0, 1, 1}, + {&__pyx_n_s__lookup, __pyx_k__lookup, sizeof(__pyx_k__lookup), 0, 0, 1, 1}, + {&__pyx_n_s__low, __pyx_k__low, sizeof(__pyx_k__low), 0, 0, 1, 1}, + {&__pyx_n_s__map, __pyx_k__map, sizeof(__pyx_k__map), 0, 0, 1, 1}, + {&__pyx_n_s__max_chunks, __pyx_k__max_chunks, sizeof(__pyx_k__max_chunks), 0, 0, 1, 1}, + {&__pyx_n_s__max_initial_size, __pyx_k__max_initial_size, sizeof(__pyx_k__max_initial_size), 0, 0, 1, 1}, + {&__pyx_n_s__max_length, __pyx_k__max_length, sizeof(__pyx_k__max_length), 0, 0, 1, 1}, + {&__pyx_n_s__max_nonterminals, __pyx_k__max_nonterminals, sizeof(__pyx_k__max_nonterminals), 0, 0, 1, 1}, + {&__pyx_n_s__max_target_chunks, __pyx_k__max_target_chunks, sizeof(__pyx_k__max_target_chunks), 0, 0, 1, 1}, + {&__pyx_n_s__max_target_length, __pyx_k__max_target_length, sizeof(__pyx_k__max_target_length), 0, 0, 1, 1}, + {&__pyx_n_s__merge, __pyx_k__merge, sizeof(__pyx_k__merge), 0, 0, 1, 1}, + {&__pyx_n_s__min_dist, __pyx_k__min_dist, sizeof(__pyx_k__min_dist), 0, 0, 1, 1}, + {&__pyx_n_s__min_gap_size, __pyx_k__min_gap_size, sizeof(__pyx_k__min_gap_size), 0, 0, 1, 1}, + {&__pyx_n_s__models, __pyx_k__models, sizeof(__pyx_k__models), 0, 0, 1, 1}, + {&__pyx_n_s__next_states, __pyx_k__next_states, sizeof(__pyx_k__next_states), 0, 0, 1, 1}, + {&__pyx_n_s__num_subpatterns, __pyx_k__num_subpatterns, sizeof(__pyx_k__num_subpatterns), 0, 0, 1, 1}, + {&__pyx_n_s__offset, __pyx_k__offset, sizeof(__pyx_k__offset), 0, 0, 1, 1}, + {&__pyx_n_s__open, __pyx_k__open, sizeof(__pyx_k__open), 0, 0, 1, 1}, + {&__pyx_n_s__pad, __pyx_k__pad, sizeof(__pyx_k__pad), 0, 0, 1, 1}, + {&__pyx_n_s__partition, __pyx_k__partition, sizeof(__pyx_k__partition), 0, 0, 1, 1}, + {&__pyx_n_s__pathlen, __pyx_k__pathlen, sizeof(__pyx_k__pathlen), 0, 0, 1, 1}, + {&__pyx_n_s__pattern2phrase, __pyx_k__pattern2phrase, sizeof(__pyx_k__pattern2phrase), 0, 0, 1, 1}, + {&__pyx_n_s__pattern2phrase_plus, __pyx_k__pattern2phrase_plus, sizeof(__pyx_k__pattern2phrase_plus), 0, 0, 1, 1}, + {&__pyx_n_s__phrase, __pyx_k__phrase, sizeof(__pyx_k__phrase), 0, 0, 1, 1}, + {&__pyx_n_s__phrase_location, __pyx_k__phrase_location, sizeof(__pyx_k__phrase_location), 0, 0, 1, 1}, + {&__pyx_n_s__precompute, __pyx_k__precompute, sizeof(__pyx_k__precompute), 0, 0, 1, 1}, + {&__pyx_n_s__precompute_file, __pyx_k__precompute_file, sizeof(__pyx_k__precompute_file), 0, 0, 1, 1}, + {&__pyx_n_s__precompute_rank, __pyx_k__precompute_rank, sizeof(__pyx_k__precompute_rank), 0, 0, 1, 1}, + {&__pyx_n_s__precomputed, __pyx_k__precomputed, sizeof(__pyx_k__precomputed), 0, 0, 1, 1}, + {&__pyx_n_s__q3sort, __pyx_k__q3sort, sizeof(__pyx_k__q3sort), 0, 0, 1, 1}, + {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1}, + {&__pyx_n_s__reachable, __pyx_k__reachable, sizeof(__pyx_k__reachable), 0, 0, 1, 1}, + {&__pyx_n_s__reachable_buffer, __pyx_k__reachable_buffer, sizeof(__pyx_k__reachable_buffer), 0, 0, 1, 1}, + {&__pyx_n_s__read_binary, __pyx_k__read_binary, sizeof(__pyx_k__read_binary), 0, 0, 1, 1}, + {&__pyx_n_s__read_text, __pyx_k__read_text, sizeof(__pyx_k__read_text), 0, 0, 1, 1}, + {&__pyx_n_s__res, __pyx_k__res, sizeof(__pyx_k__res), 0, 0, 1, 1}, + {&__pyx_n_s__reset, __pyx_k__reset, sizeof(__pyx_k__reset), 0, 0, 1, 1}, + {&__pyx_n_s__resource, __pyx_k__resource, sizeof(__pyx_k__resource), 0, 0, 1, 1}, + {&__pyx_n_s__ru_stime, __pyx_k__ru_stime, sizeof(__pyx_k__ru_stime), 0, 0, 1, 1}, + {&__pyx_n_s__ru_utime, __pyx_k__ru_utime, sizeof(__pyx_k__ru_utime), 0, 0, 1, 1}, + {&__pyx_n_s__sa, __pyx_k__sa, sizeof(__pyx_k__sa), 0, 0, 1, 1}, + {&__pyx_n_s__sa_high, __pyx_k__sa_high, sizeof(__pyx_k__sa_high), 0, 0, 1, 1}, + {&__pyx_n_s__sa_low, __pyx_k__sa_low, sizeof(__pyx_k__sa_low), 0, 0, 1, 1}, + {&__pyx_n_s__sample, __pyx_k__sample, sizeof(__pyx_k__sample), 0, 0, 1, 1}, + {&__pyx_n_s__sample_size, __pyx_k__sample_size, sizeof(__pyx_k__sample_size), 0, 0, 1, 1}, + {&__pyx_n_s__sampler, __pyx_k__sampler, sizeof(__pyx_k__sampler), 0, 0, 1, 1}, + {&__pyx_n_s__sarray, __pyx_k__sarray, sizeof(__pyx_k__sarray), 0, 0, 1, 1}, + {&__pyx_n_s__scores, __pyx_k__scores, sizeof(__pyx_k__scores), 0, 0, 1, 1}, + {&__pyx_n_s__seek, __pyx_k__seek, sizeof(__pyx_k__seek), 0, 0, 1, 1}, + {&__pyx_n_s__setdefault, __pyx_k__setdefault, sizeof(__pyx_k__setdefault), 0, 0, 1, 1}, + {&__pyx_n_s__shortest, __pyx_k__shortest, sizeof(__pyx_k__shortest), 0, 0, 1, 1}, + {&__pyx_n_s__size, __pyx_k__size, sizeof(__pyx_k__size), 0, 0, 1, 1}, + {&__pyx_n_s__skip, __pyx_k__skip, sizeof(__pyx_k__skip), 0, 0, 1, 1}, + {&__pyx_n_s__sorted, __pyx_k__sorted, sizeof(__pyx_k__sorted), 0, 0, 1, 1}, + {&__pyx_n_s__spanlen, __pyx_k__spanlen, sizeof(__pyx_k__spanlen), 0, 0, 1, 1}, + {&__pyx_n_s__split, __pyx_k__split, sizeof(__pyx_k__split), 0, 0, 1, 1}, + {&__pyx_n_s__start, __pyx_k__start, sizeof(__pyx_k__start), 0, 0, 1, 1}, + {&__pyx_n_s__stats, __pyx_k__stats, sizeof(__pyx_k__stats), 0, 0, 1, 1}, + {&__pyx_n_s__stop, __pyx_k__stop, sizeof(__pyx_k__stop), 0, 0, 1, 1}, + {&__pyx_n_s__string, __pyx_k__string, sizeof(__pyx_k__string), 0, 0, 1, 1}, + {&__pyx_n_s__suffix_link, __pyx_k__suffix_link, sizeof(__pyx_k__suffix_link), 0, 0, 1, 1}, + {&__pyx_n_s__sym_fromstring, __pyx_k__sym_fromstring, sizeof(__pyx_k__sym_fromstring), 0, 0, 1, 1}, + {&__pyx_n_s__terminal, __pyx_k__terminal, sizeof(__pyx_k__terminal), 0, 0, 1, 1}, + {&__pyx_n_s__tight_phrases, __pyx_k__tight_phrases, sizeof(__pyx_k__tight_phrases), 0, 0, 1, 1}, + {&__pyx_n_s__toMap, __pyx_k__toMap, sizeof(__pyx_k__toMap), 0, 0, 1, 1}, + {&__pyx_n_s__train_min_gap_size, __pyx_k__train_min_gap_size, sizeof(__pyx_k__train_min_gap_size), 0, 0, 1, 1}, + {&__pyx_n_s__unlink, __pyx_k__unlink, sizeof(__pyx_k__unlink), 0, 0, 1, 1}, + {&__pyx_n_s__use_baeza_yates, __pyx_k__use_baeza_yates, sizeof(__pyx_k__use_baeza_yates), 0, 0, 1, 1}, + {&__pyx_n_s__use_collocations, __pyx_k__use_collocations, sizeof(__pyx_k__use_collocations), 0, 0, 1, 1}, + {&__pyx_n_s__use_index, __pyx_k__use_index, sizeof(__pyx_k__use_index), 0, 0, 1, 1}, + {&__pyx_n_s__use_sent_id, __pyx_k__use_sent_id, sizeof(__pyx_k__use_sent_id), 0, 0, 1, 1}, + {&__pyx_n_s__w, __pyx_k__w, sizeof(__pyx_k__w), 0, 0, 1, 1}, + {&__pyx_n_s__warn, __pyx_k__warn, sizeof(__pyx_k__warn), 0, 0, 1, 1}, + {&__pyx_n_s__word, __pyx_k__word, sizeof(__pyx_k__word), 0, 0, 1, 1}, + {&__pyx_n_s__word_alignments, __pyx_k__word_alignments, sizeof(__pyx_k__word_alignments), 0, 0, 1, 1}, + {&__pyx_n_s__words, __pyx_k__words, sizeof(__pyx_k__words), 0, 0, 1, 1}, + {&__pyx_n_s__write, __pyx_k__write, sizeof(__pyx_k__write), 0, 0, 1, 1}, + {&__pyx_n_s__write_text, __pyx_k__write_text, sizeof(__pyx_k__write_text), 0, 0, 1, 1}, + {&__pyx_n_s__zip, __pyx_k__zip, sizeof(__pyx_k__zip), 0, 0, 1, 1}, + {0, 0, 0, 0, 0, 0, 0} +}; +static int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_open = __Pyx_GetName(__pyx_b, __pyx_n_s__open); if (!__pyx_builtin_open) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __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[2]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_map = __Pyx_GetName(__pyx_b, __pyx_n_s__map); if (!__pyx_builtin_map) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __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[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_zip = __Pyx_GetName(__pyx_b, __pyx_n_s__zip); if (!__pyx_builtin_zip) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_StopIteration = __Pyx_GetName(__pyx_b, __pyx_n_s__StopIteration); if (!__pyx_builtin_StopIteration) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_cmp = __Pyx_GetName(__pyx_b, __pyx_n_s__cmp); if (!__pyx_builtin_cmp) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_sorted = __Pyx_GetName(__pyx_b, __pyx_n_s__sorted); if (!__pyx_builtin_sorted) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 917; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + return 0; + __pyx_L1_error:; + return -1; +} + +static int __Pyx_InitCachedConstants(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":20 + * self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} + * self.id2word = ["END_OF_FILE", "END_OF_LINE"] + * self.data = IntList(1000,1000) # <<<<<<<<<<<<<< + * self.sent_id = IntList(1000,1000) + * self.sent_index = IntList(1000,1000) + */ + __pyx_k_tuple_10 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_10); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_10, 0, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_10, 1, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_10)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":21 + * self.id2word = ["END_OF_FILE", "END_OF_LINE"] + * self.data = IntList(1000,1000) + * self.sent_id = IntList(1000,1000) # <<<<<<<<<<<<<< + * self.sent_index = IntList(1000,1000) + * self.use_sent_id = use_sent_id + */ + __pyx_k_tuple_11 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_11); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_11, 0, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_11, 1, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_11)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":22 + * self.data = IntList(1000,1000) + * self.sent_id = IntList(1000,1000) + * self.sent_index = IntList(1000,1000) # <<<<<<<<<<<<<< + * self.use_sent_id = use_sent_id + * if from_binary: + */ + __pyx_k_tuple_12 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_12); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_12, 0, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_12, 1, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":62 + * f.write("%s " % self.get_word(w_id)) + * if w_id == 1: + * f.write("\n") # <<<<<<<<<<<<<< + * + * def read_text(self, char* filename): + */ + __pyx_k_tuple_15 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_15)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_15); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_15, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_15)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":57 + * + * def write_text(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * for w_id in self.data: + * if w_id > 1: + */ + __pyx_k_tuple_16 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_16)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_16); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_16, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_16, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_16, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_16)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":66 + * def read_text(self, char* filename): + * cdef int word_count = 0 + * with gzip_or_text(filename) as fp: # <<<<<<<<<<<<<< + * for line_num, line in enumerate(fp): + * self.sent_index.append(word_count) + */ + __pyx_k_tuple_17 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_17)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_17); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_17, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_17, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_17, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_17)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":133 + * for i in self.data: + * f.write("%d " %i) + * f.write("\n") # <<<<<<<<<<<<<< + * for i in self.sent_index: + * f.write("%d " %i) + */ + __pyx_k_tuple_19 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_19)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_19); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_19, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_19)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":136 + * for i in self.sent_index: + * f.write("%d " %i) + * f.write("\n") # <<<<<<<<<<<<<< + * for i in self.sent_id: + * f.write("%d " %i) + */ + __pyx_k_tuple_20 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_20); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_20, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":139 + * for i in self.sent_id: + * f.write("%d " %i) + * f.write("\n") # <<<<<<<<<<<<<< + * for word in self.id2word: + * f.write("%s %d " % (word, self.word2id[word])) + */ + __pyx_k_tuple_21 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_21)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_21); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_21, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":142 + * for word in self.id2word: + * f.write("%s %d " % (word, self.word2id[word])) + * f.write("\n") # <<<<<<<<<<<<<< + * + * def write_enhanced(self, char* filename): + */ + __pyx_k_tuple_23 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_23)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_23); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_23, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_23)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":145 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * self.write_enhanced_handle(self, f) + */ + __pyx_k_tuple_25 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_25); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_25, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_25, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_25, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_25)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":46 + * + * def __cinit__(self, from_binary=None, from_text=None): + * self.links = IntList(1000,1000) # <<<<<<<<<<<<<< + * self.sent_index = IntList(1000,1000) + * if from_binary: + */ + __pyx_k_tuple_26 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_26)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_26); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_26, 0, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_26, 1, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_26)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":47 + * def __cinit__(self, from_binary=None, from_text=None): + * self.links = IntList(1000,1000) + * self.sent_index = IntList(1000,1000) # <<<<<<<<<<<<<< + * if from_binary: + * self.read_binary(from_binary) + */ + __pyx_k_tuple_27 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_27)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_27); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_27, 0, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_INCREF(__pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_27, 1, __pyx_int_1000); + __Pyx_GIVEREF(__pyx_int_1000); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_27)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":59 + * pairs = line.split() + * for pair in pairs: + * (i, j) = map(int, pair.split('-')) # <<<<<<<<<<<<<< + * self.links.append(self.link(i, j)) + * self.sent_index.append(len(self.links)) + */ + __pyx_k_tuple_29 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_29)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_29); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_28)); + PyTuple_SET_ITEM(__pyx_k_tuple_29, 0, ((PyObject *)__pyx_kp_s_28)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_28)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_29)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":54 + * + * def read_text(self, char* filename): + * with gzip_or_text(filename) as f: # <<<<<<<<<<<<<< + * for line in f: + * self.sent_index.append(len(self.links)) + */ + __pyx_k_tuple_30 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_30)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_30); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_30, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_30, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_30, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_30)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":75 + * for i, link in enumerate(self.links): + * while i >= self.sent_index[sent_num]: + * f.write("\n") # <<<<<<<<<<<<<< + * sent_num = sent_num + 1 + * f.write("%d-%d " % self.unlink(link)) + */ + __pyx_k_tuple_31 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_31)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_31); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_31, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_31)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":78 + * sent_num = sent_num + 1 + * f.write("%d-%d " % self.unlink(link)) + * f.write("\n") # <<<<<<<<<<<<<< + * + * def write_binary(self, char* filename): + */ + __pyx_k_tuple_33 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_33)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_33); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_33, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_33)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":71 + * + * def write_text(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * sent_num = 0 + * for i, link in enumerate(self.links): + */ + __pyx_k_tuple_34 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_34)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_34); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_34, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_34, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_34, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_34)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":92 + * for link in self.links: + * f.write("%d " % link) + * f.write("\n") # <<<<<<<<<<<<<< + * for i in self.sent_index: + * f.write("%d " % i) + */ + __pyx_k_tuple_35 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_35)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_35); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_35, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_35)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":95 + * for i in self.sent_index: + * f.write("%d " % i) + * f.write("\n") # <<<<<<<<<<<<<< + * + * def alignment(self, i): + */ + __pyx_k_tuple_36 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_36)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_36); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_36, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_36)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":88 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * sent_num = 1 + * for link in self.links: + */ + __pyx_k_tuple_37 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_37)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_37); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_37, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_37, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_37, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_37)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":302 + * + * # Re-read file, placing words into buckets + * f.seek(0) # <<<<<<<<<<<<<< + * for line in f: + * (fword, eword, score1, score2) = line.split() + */ + __pyx_k_tuple_40 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_40)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_40); + __Pyx_INCREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_k_tuple_40, 0, __pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_40)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":278 + * + * fcount = IntList() + * with gzip_or_text(filename) as f: # <<<<<<<<<<<<<< + * # first loop merely establishes size of array objects + * for line in f: + */ + __pyx_k_tuple_41 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_41)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_41); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_41, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_41, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_41, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_41)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":344 + * + * if i > j: + * raise Exception("Sort error in CLex") # <<<<<<<<<<<<<< + * if i == j: #empty interval + * return + */ + __pyx_k_tuple_44 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_44)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_44); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_43)); + PyTuple_SET_ITEM(__pyx_k_tuple_44, 0, ((PyObject *)__pyx_kp_s_43)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_43)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_44)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":367 + * for i in self.f_index: + * f.write("%d " % i) + * f.write("\n") # <<<<<<<<<<<<<< + * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): + * f.write("%d %f %f " % (i, s1, s2)) + */ + __pyx_k_tuple_46 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_46)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_46); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_46, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_46)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":370 + * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): + * f.write("%d %f %f " % (i, s1, s2)) + * f.write("\n") # <<<<<<<<<<<<<< + * for i, w in enumerate(self.id2fword): + * f.write("%d %s " % (i, w)) + */ + __pyx_k_tuple_48 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_48)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_48); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_48, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_48)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":373 + * for i, w in enumerate(self.id2fword): + * f.write("%d %s " % (i, w)) + * f.write("\n") # <<<<<<<<<<<<<< + * for i, w in enumerate(self.id2eword): + * f.write("%d %s " % (i, w)) + */ + __pyx_k_tuple_50 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_50)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_50); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_50, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_50)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":376 + * for i, w in enumerate(self.id2eword): + * f.write("%d %s " % (i, w)) + * f.write("\n") # <<<<<<<<<<<<<< + * + * + */ + __pyx_k_tuple_51 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_51)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_51); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_51, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_51)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":364 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * for i in self.f_index: + * f.write("%d " % i) + */ + __pyx_k_tuple_52 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_52); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_52, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_52, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_52, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_52)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":409 + * cdef i, N, e_id, f_id + * + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * N = len(self.e_index) + * f_id = 0 + */ + __pyx_k_tuple_54 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_54)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_54); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_54, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_54, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_54, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_54)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":13 + * cdef IntList rank + * + * logger.info("Constructing LCP array") # <<<<<<<<<<<<<< + * self.sa = sa + * n = self.sa.sa.len + */ + __pyx_k_tuple_58 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_58)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_58); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_57)); + PyTuple_SET_ITEM(__pyx_k_tuple_58, 0, ((PyObject *)__pyx_kp_s_57)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_57)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_58)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":34 + * if h > 0: + * h = h-1 + * logger.info("LCP array completed") # <<<<<<<<<<<<<< + * + * def compute_stats(self, int max_n): + */ + __pyx_k_tuple_60 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_60)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_60); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_59)); + PyTuple_SET_ITEM(__pyx_k_tuple_60, 0, ((PyObject *)__pyx_kp_s_59)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_59)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_60)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":297 + * pattern_rank = {} + * + * logger.info("Precomputing frequent intersections") # <<<<<<<<<<<<<< + * cdef float start_time = monitor_cpu() + * + */ + __pyx_k_tuple_71 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_71)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_71); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_70)); + PyTuple_SET_ITEM(__pyx_k_tuple_71, 0, ((PyObject *)__pyx_kp_s_70)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_70)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_71)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":314 + * queue = IntList(increment=1000) + * + * logger.info(" Computing inverted indexes...") # <<<<<<<<<<<<<< + * N = len(data) + * for i from 0 <= i < N: + */ + __pyx_k_tuple_73 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_73)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_73); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_72)); + PyTuple_SET_ITEM(__pyx_k_tuple_73, 0, ((PyObject *)__pyx_kp_s_72)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_72)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_73)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":329 + * trie_node_data_append(node, i) + * + * logger.info(" Computing collocations...") # <<<<<<<<<<<<<< + * N = len(queue) + * ptr1 = 0 + */ + __pyx_k_tuple_75 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_75)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_75); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_74)); + PyTuple_SET_ITEM(__pyx_k_tuple_75, 0, ((PyObject *)__pyx_kp_s_74)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_74)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_75)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":393 + * for pattern2 in J_set: + * if len(pattern1) + len(pattern2) + 1 < self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 # <<<<<<<<<<<<<< + * J2_set.add(combined_pattern) + * + */ + __pyx_k_tuple_77 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_77)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_77); + __Pyx_INCREF(__pyx_int_neg_1); + PyTuple_SET_ITEM(__pyx_k_tuple_77, 0, __pyx_int_neg_1); + __Pyx_GIVEREF(__pyx_int_neg_1); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_77)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":400 + * x = x+1 + * if len(pattern1) + len(pattern2) + 1 <= self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 # <<<<<<<<<<<<<< + * IJ_set.add(combined_pattern) + * + */ + __pyx_k_tuple_78 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_78)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_78); + __Pyx_INCREF(__pyx_int_neg_1); + PyTuple_SET_ITEM(__pyx_k_tuple_78, 0, __pyx_int_neg_1); + __Pyx_GIVEREF(__pyx_int_neg_1); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_78)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":407 + * x = x+2 + * if len(pattern1) + len(pattern2) + 1<= self.max_length: + * combined_pattern = pattern1 + (-1,) + pattern2 # <<<<<<<<<<<<<< + * IJ_set.add(combined_pattern) + * combined_pattern = pattern2 + (-1,) + pattern1 + */ + __pyx_k_tuple_79 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_79)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_79); + __Pyx_INCREF(__pyx_int_neg_1); + PyTuple_SET_ITEM(__pyx_k_tuple_79, 0, __pyx_int_neg_1); + __Pyx_GIVEREF(__pyx_int_neg_1); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_79)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":409 + * combined_pattern = pattern1 + (-1,) + pattern2 + * IJ_set.add(combined_pattern) + * combined_pattern = pattern2 + (-1,) + pattern1 # <<<<<<<<<<<<<< + * IJ_set.add(combined_pattern) + * + */ + __pyx_k_tuple_80 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_80)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_80); + __Pyx_INCREF(__pyx_int_neg_1); + PyTuple_SET_ITEM(__pyx_k_tuple_80, 0, __pyx_int_neg_1); + __Pyx_GIVEREF(__pyx_int_neg_1); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_80)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":103 + * + * '''Step 3: read off suffix array from inverse suffix array''' + * logger.info(" Finalizing sort...") # <<<<<<<<<<<<<< + * for i from 0 <= i < N: + * j = isa.arr[i] + */ + __pyx_k_tuple_91 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_91)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_91); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_90)); + PyTuple_SET_ITEM(__pyx_k_tuple_91, 0, ((PyObject *)__pyx_kp_s_90)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_90)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_91)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":202 + * for a_i in self.sa: + * f.write("%d " % a_i) + * f.write("\n") # <<<<<<<<<<<<<< + * for w_i in self.ha: + * f.write("%d " % w_i) + */ + __pyx_k_tuple_94 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_94)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_94); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_94, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_94)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":205 + * for w_i in self.ha: + * f.write("%d " % w_i) + * f.write("\n") # <<<<<<<<<<<<<< + * + * cdef int __search_high(self, int word_id, int offset, int low, int high): + */ + __pyx_k_tuple_95 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_95)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_95); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_95, 0, ((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_95)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":198 + * + * def write_enhanced(self, char* filename): + * with open(filename, "w") as f: # <<<<<<<<<<<<<< + * self.darray.write_enhanced_handle(f) + * for a_i in self.sa: + */ + __pyx_k_tuple_96 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_96)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_96); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_96, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_96, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_96, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_96)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":92 + * logger.info("Sampling strategy: uniform, max sample size = %d", sample_size) + * else: + * logger.info("Sampling strategy: no sampling") # <<<<<<<<<<<<<< + * + * def sample(self, PhraseLocation phrase_location): + */ + __pyx_k_tuple_100 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_100)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_100); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_99)); + PyTuple_SET_ITEM(__pyx_k_tuple_100, 0, ((PyObject *)__pyx_kp_s_99)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_99)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_100)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":300 + * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) + * if alignment is None: + * raise Exception("Must specify an alignment object") # <<<<<<<<<<<<<< + * self.alignment = alignment + * + */ + __pyx_k_tuple_105 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_105)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_105); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_104)); + PyTuple_SET_ITEM(__pyx_k_tuple_105, 0, ((PyObject *)__pyx_kp_s_104)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_104)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_105)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1004 + * else: + * #ERROR: We never get here + * raise Exception("Keyword trie error") # <<<<<<<<<<<<<< + * # checking whether lookup_required + * if lookup_required: + */ + __pyx_k_tuple_120 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_120)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1004; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_120); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_119)); + PyTuple_SET_ITEM(__pyx_k_tuple_120, 0, ((PyObject *)__pyx_kp_s_119)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_119)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_120)); + + /* "_sa.pyx":9 + * resource.getrusage(resource.RUSAGE_SELF).ru_stime) + * + * def gzip_or_text(char* filename): # <<<<<<<<<<<<<< + * if filename.endswith('.gz'): + * return gzip.GzipFile(filename) + */ + __pyx_k_tuple_132 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_132)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_132); + __Pyx_INCREF(((PyObject *)__pyx_n_s__filename)); + PyTuple_SET_ITEM(__pyx_k_tuple_132, 0, ((PyObject *)__pyx_n_s__filename)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__filename)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__filename)); + PyTuple_SET_ITEM(__pyx_k_tuple_132, 1, ((PyObject *)__pyx_n_s__filename)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__filename)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_132)); + __pyx_k_codeobj_133 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_132, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_134, __pyx_n_s__gzip_or_text, 9, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_133)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "_sa.pyx":15 + * return open(filename) + * + * logger = logging.getLogger('cdec.sa') # <<<<<<<<<<<<<< + * + * include "float_list.pxi" + */ + __pyx_k_tuple_136 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_136)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_136); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_135)); + PyTuple_SET_ITEM(__pyx_k_tuple_136, 0, ((PyObject *)__pyx_kp_s_135)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_135)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_136)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":104 + * return ALPHABET.setindex(sym, id) + * + * def sym_fromstring(bytes string, bint terminal): # <<<<<<<<<<<<<< + * return ALPHABET.fromstring(string, terminal) + */ + __pyx_k_tuple_137 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_137)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_137); + __Pyx_INCREF(((PyObject *)__pyx_n_s__string)); + PyTuple_SET_ITEM(__pyx_k_tuple_137, 0, ((PyObject *)__pyx_n_s__string)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__string)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__terminal)); + PyTuple_SET_ITEM(__pyx_k_tuple_137, 1, ((PyObject *)__pyx_n_s__terminal)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__terminal)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_137)); + __pyx_k_codeobj_138 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_137, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_139, __pyx_n_s__sym_fromstring, 104, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_138)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static int __Pyx_InitGlobals(void) { + if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_5 = PyInt_FromLong(5); if (unlikely(!__pyx_int_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_10 = PyInt_FromLong(10); if (unlikely(!__pyx_int_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_20 = PyInt_FromLong(20); if (unlikely(!__pyx_int_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_1000 = PyInt_FromLong(1000); if (unlikely(!__pyx_int_1000)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_int_65536 = PyInt_FromLong(65536); if (unlikely(!__pyx_int_65536)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + return 0; + __pyx_L1_error:; + return -1; +} + +#if PY_MAJOR_VERSION < 3 +PyMODINIT_FUNC init_sa(void); /*proto*/ +PyMODINIT_FUNC init_sa(void) +#else +PyMODINIT_FUNC PyInit__sa(void); /*proto*/ +PyMODINIT_FUNC PyInit__sa(void) +#endif +{ + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + __Pyx_RefNannyDeclarations + #if CYTHON_REFNANNY + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); + if (!__Pyx_RefNanny) { + PyErr_Clear(); + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); + if (!__Pyx_RefNanny) + Py_FatalError("failed to import 'refnanny' module"); + } + #endif + __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit__sa(void)", 0); + if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #ifdef __Pyx_CyFunction_USED + if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif + #ifdef __Pyx_FusedFunction_USED + if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif + #ifdef __Pyx_Generator_USED + if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif + /*--- Library function declarations ---*/ + /*--- Threads initialization code ---*/ + #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS + #ifdef WITH_THREAD /* Python build with threading support? */ + PyEval_InitThreads(); + #endif + #endif + /*--- Module creation code ---*/ + #if PY_MAJOR_VERSION < 3 + __pyx_m = Py_InitModule4(__Pyx_NAMESTR("_sa"), __pyx_methods, 0, 0, PYTHON_API_VERSION); + #else + __pyx_m = PyModule_Create(&__pyx_moduledef); + #endif + if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #if PY_MAJOR_VERSION < 3 + Py_INCREF(__pyx_m); + #endif + __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); + if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #if CYTHON_COMPILING_IN_PYPY + Py_INCREF(__pyx_b); + #endif + if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + /*--- Initialize various global constants etc. ---*/ + if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_module_is_main__sa) { + if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + } + /*--- Builtin init code ---*/ + if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /*--- Constants init code ---*/ + if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /*--- Global init code ---*/ + __pyx_v_3_sa_ALPHABET = ((struct __pyx_obj_3_sa_Alphabet *)Py_None); Py_INCREF(Py_None); + /*--- Variable export code ---*/ + /*--- Function export code ---*/ + if (__Pyx_ExportFunction("sym_tostring", (void (*)(void))__pyx_f_3_sa_sym_tostring, "char *(int)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_ExportFunction("sym_tocat", (void (*)(void))__pyx_f_3_sa_sym_tocat, "char *(int)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_ExportFunction("sym_isvar", (void (*)(void))__pyx_f_3_sa_sym_isvar, "int (int)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_ExportFunction("sym_getindex", (void (*)(void))__pyx_f_3_sa_sym_getindex, "int (int)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /*--- Type init code ---*/ + __pyx_vtabptr_3_sa_Phrase = &__pyx_vtable_3_sa_Phrase; + __pyx_vtable_3_sa_Phrase.chunkpos = (int (*)(struct __pyx_obj_3_sa_Phrase *, int))__pyx_f_3_sa_6Phrase_chunkpos; + __pyx_vtable_3_sa_Phrase.chunklen = (int (*)(struct __pyx_obj_3_sa_Phrase *, int))__pyx_f_3_sa_6Phrase_chunklen; + if (PyType_Ready(&__pyx_type_3_sa_Phrase) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_3_sa_Phrase.tp_dict, __pyx_vtabptr_3_sa_Phrase) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Phrase", (PyObject *)&__pyx_type_3_sa_Phrase) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_Phrase = &__pyx_type_3_sa_Phrase; + if (PyType_Ready(&__pyx_type_3_sa_Rule) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Rule", (PyObject *)&__pyx_type_3_sa_Rule) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_Rule = &__pyx_type_3_sa_Rule; + __pyx_vtabptr_3_sa_FloatList = &__pyx_vtable_3_sa_FloatList; + __pyx_vtable_3_sa_FloatList.set = (void (*)(struct __pyx_obj_3_sa_FloatList *, int, float))__pyx_f_3_sa_9FloatList_set; + __pyx_vtable_3_sa_FloatList.write_handle = (void (*)(struct __pyx_obj_3_sa_FloatList *, FILE *))__pyx_f_3_sa_9FloatList_write_handle; + __pyx_vtable_3_sa_FloatList.read_handle = (void (*)(struct __pyx_obj_3_sa_FloatList *, FILE *))__pyx_f_3_sa_9FloatList_read_handle; + if (PyType_Ready(&__pyx_type_3_sa_FloatList) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_3_sa_FloatList.tp_dict, __pyx_vtabptr_3_sa_FloatList) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "FloatList", (PyObject *)&__pyx_type_3_sa_FloatList) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_FloatList = &__pyx_type_3_sa_FloatList; + __pyx_vtabptr_3_sa_IntList = &__pyx_vtable_3_sa_IntList; + __pyx_vtable_3_sa_IntList.set = (void (*)(struct __pyx_obj_3_sa_IntList *, int, int))__pyx_f_3_sa_7IntList_set; + __pyx_vtable_3_sa_IntList._append = (void (*)(struct __pyx_obj_3_sa_IntList *, int))__pyx_f_3_sa_7IntList__append; + __pyx_vtable_3_sa_IntList._extend = (void (*)(struct __pyx_obj_3_sa_IntList *, struct __pyx_obj_3_sa_IntList *))__pyx_f_3_sa_7IntList__extend; + __pyx_vtable_3_sa_IntList._extend_arr = (void (*)(struct __pyx_obj_3_sa_IntList *, int *, int))__pyx_f_3_sa_7IntList__extend_arr; + __pyx_vtable_3_sa_IntList._clear = (void (*)(struct __pyx_obj_3_sa_IntList *))__pyx_f_3_sa_7IntList__clear; + __pyx_vtable_3_sa_IntList.write_handle = (void (*)(struct __pyx_obj_3_sa_IntList *, FILE *))__pyx_f_3_sa_7IntList_write_handle; + __pyx_vtable_3_sa_IntList.read_handle = (void (*)(struct __pyx_obj_3_sa_IntList *, FILE *))__pyx_f_3_sa_7IntList_read_handle; + if (PyType_Ready(&__pyx_type_3_sa_IntList) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_3_sa_IntList.tp_dict, __pyx_vtabptr_3_sa_IntList) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "IntList", (PyObject *)&__pyx_type_3_sa_IntList) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_IntList = &__pyx_type_3_sa_IntList; + __pyx_vtabptr_3_sa_StringMap = &__pyx_vtable_3_sa_StringMap; + __pyx_vtable_3_sa_StringMap.word = (char *(*)(struct __pyx_obj_3_sa_StringMap *, int))__pyx_f_3_sa_9StringMap_word; + __pyx_vtable_3_sa_StringMap.index = (int (*)(struct __pyx_obj_3_sa_StringMap *, char *))__pyx_f_3_sa_9StringMap_index; + if (PyType_Ready(&__pyx_type_3_sa_StringMap) < 0) {__pyx_filename = __pyx_f[14]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_3_sa_StringMap.tp_dict, __pyx_vtabptr_3_sa_StringMap) < 0) {__pyx_filename = __pyx_f[14]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "StringMap", (PyObject *)&__pyx_type_3_sa_StringMap) < 0) {__pyx_filename = __pyx_f[14]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_StringMap = &__pyx_type_3_sa_StringMap; + __pyx_vtabptr_3_sa_DataArray = &__pyx_vtable_3_sa_DataArray; + __pyx_vtable_3_sa_DataArray.read_handle = (void (*)(struct __pyx_obj_3_sa_DataArray *, FILE *))__pyx_f_3_sa_9DataArray_read_handle; + __pyx_vtable_3_sa_DataArray.write_handle = (void (*)(struct __pyx_obj_3_sa_DataArray *, FILE *))__pyx_f_3_sa_9DataArray_write_handle; + if (PyType_Ready(&__pyx_type_3_sa_DataArray) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_3_sa_DataArray.tp_dict, __pyx_vtabptr_3_sa_DataArray) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "DataArray", (PyObject *)&__pyx_type_3_sa_DataArray) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_DataArray = &__pyx_type_3_sa_DataArray; + __pyx_vtabptr_3_sa_Alignment = &__pyx_vtable_3_sa_Alignment; + __pyx_vtable_3_sa_Alignment.link = (int (*)(struct __pyx_obj_3_sa_Alignment *, int, int))__pyx_f_3_sa_9Alignment_link; + __pyx_vtable_3_sa_Alignment._unlink = (PyObject *(*)(struct __pyx_obj_3_sa_Alignment *, int, int *, int *))__pyx_f_3_sa_9Alignment__unlink; + __pyx_vtable_3_sa_Alignment._get_sent_links = (int *(*)(struct __pyx_obj_3_sa_Alignment *, int, int *))__pyx_f_3_sa_9Alignment__get_sent_links; + if (PyType_Ready(&__pyx_type_3_sa_Alignment) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_3_sa_Alignment.tp_dict, __pyx_vtabptr_3_sa_Alignment) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Alignment", (PyObject *)&__pyx_type_3_sa_Alignment) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_Alignment = &__pyx_type_3_sa_Alignment; + __pyx_vtabptr_3_sa_BiLex = &__pyx_vtable_3_sa_BiLex; + __pyx_vtable_3_sa_BiLex.compute_from_data = (PyObject *(*)(struct __pyx_obj_3_sa_BiLex *, struct __pyx_obj_3_sa_SuffixArray *, struct __pyx_obj_3_sa_DataArray *, struct __pyx_obj_3_sa_Alignment *))__pyx_f_3_sa_5BiLex_compute_from_data; + __pyx_vtable_3_sa_BiLex._add_node = (PyObject *(*)(struct __pyx_obj_3_sa_BiLex *, struct __pyx_t_3_sa__node *, int *, float, int *))__pyx_f_3_sa_5BiLex__add_node; + __pyx_vtable_3_sa_BiLex.write_wordlist = (PyObject *(*)(struct __pyx_obj_3_sa_BiLex *, PyObject *, FILE *))__pyx_f_3_sa_5BiLex_write_wordlist; + __pyx_vtable_3_sa_BiLex.read_wordlist = (PyObject *(*)(struct __pyx_obj_3_sa_BiLex *, PyObject *, PyObject *, FILE *))__pyx_f_3_sa_5BiLex_read_wordlist; + __pyx_vtable_3_sa_BiLex.swap = (PyObject *(*)(struct __pyx_obj_3_sa_BiLex *, int, int))__pyx_f_3_sa_5BiLex_swap; + __pyx_vtable_3_sa_BiLex.qsort = (PyObject *(*)(struct __pyx_obj_3_sa_BiLex *, int, int, PyObject *))__pyx_f_3_sa_5BiLex_qsort; + if (PyType_Ready(&__pyx_type_3_sa_BiLex) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_3_sa_BiLex.tp_dict, __pyx_vtabptr_3_sa_BiLex) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "BiLex", (PyObject *)&__pyx_type_3_sa_BiLex) < 0) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_BiLex = &__pyx_type_3_sa_BiLex; + if (PyType_Ready(&__pyx_type_3_sa_BitSetIterator) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "BitSetIterator", (PyObject *)&__pyx_type_3_sa_BitSetIterator) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_BitSetIterator = &__pyx_type_3_sa_BitSetIterator; + if (PyType_Ready(&__pyx_type_3_sa_BitSet) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "BitSet", (PyObject *)&__pyx_type_3_sa_BitSet) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_BitSet = &__pyx_type_3_sa_BitSet; + if (PyType_Ready(&__pyx_type_3_sa_VEBIterator) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "VEBIterator", (PyObject *)&__pyx_type_3_sa_VEBIterator) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 340; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_VEBIterator = &__pyx_type_3_sa_VEBIterator; + __pyx_vtabptr_3_sa_VEB = &__pyx_vtable_3_sa_VEB; + __pyx_vtable_3_sa_VEB._findsucc = (int (*)(struct __pyx_obj_3_sa_VEB *, int))__pyx_f_3_sa_3VEB__findsucc; + __pyx_vtable_3_sa_VEB._insert = (int (*)(struct __pyx_obj_3_sa_VEB *, int))__pyx_f_3_sa_3VEB__insert; + __pyx_vtable_3_sa_VEB._first = (int (*)(struct __pyx_obj_3_sa_VEB *))__pyx_f_3_sa_3VEB__first; + if (PyType_Ready(&__pyx_type_3_sa_VEB) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_3_sa_VEB.tp_dict, __pyx_vtabptr_3_sa_VEB) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "VEB", (PyObject *)&__pyx_type_3_sa_VEB) < 0) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_VEB = &__pyx_type_3_sa_VEB; + if (PyType_Ready(&__pyx_type_3_sa_LCP) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "LCP", (PyObject *)&__pyx_type_3_sa_LCP) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_LCP = &__pyx_type_3_sa_LCP; + __pyx_vtabptr_3_sa_Alphabet = &__pyx_vtable_3_sa_Alphabet; + __pyx_vtable_3_sa_Alphabet.isvar = (int (*)(struct __pyx_obj_3_sa_Alphabet *, int))__pyx_f_3_sa_8Alphabet_isvar; + __pyx_vtable_3_sa_Alphabet.isword = (int (*)(struct __pyx_obj_3_sa_Alphabet *, int))__pyx_f_3_sa_8Alphabet_isword; + __pyx_vtable_3_sa_Alphabet.getindex = (int (*)(struct __pyx_obj_3_sa_Alphabet *, int))__pyx_f_3_sa_8Alphabet_getindex; + __pyx_vtable_3_sa_Alphabet.setindex = (int (*)(struct __pyx_obj_3_sa_Alphabet *, int, int))__pyx_f_3_sa_8Alphabet_setindex; + __pyx_vtable_3_sa_Alphabet.clearindex = (int (*)(struct __pyx_obj_3_sa_Alphabet *, int))__pyx_f_3_sa_8Alphabet_clearindex; + __pyx_vtable_3_sa_Alphabet.match = (int (*)(struct __pyx_obj_3_sa_Alphabet *, int, int))__pyx_f_3_sa_8Alphabet_match; + __pyx_vtable_3_sa_Alphabet.tocat = (char *(*)(struct __pyx_obj_3_sa_Alphabet *, int))__pyx_f_3_sa_8Alphabet_tocat; + __pyx_vtable_3_sa_Alphabet.fromcat = (int (*)(struct __pyx_obj_3_sa_Alphabet *, char *))__pyx_f_3_sa_8Alphabet_fromcat; + __pyx_vtable_3_sa_Alphabet.tostring = (char *(*)(struct __pyx_obj_3_sa_Alphabet *, int))__pyx_f_3_sa_8Alphabet_tostring; + __pyx_vtable_3_sa_Alphabet.fromstring = (int (*)(struct __pyx_obj_3_sa_Alphabet *, char *, int))__pyx_f_3_sa_8Alphabet_fromstring; + if (PyType_Ready(&__pyx_type_3_sa_Alphabet) < 0) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_3_sa_Alphabet.tp_dict, __pyx_vtabptr_3_sa_Alphabet) < 0) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Alphabet", (PyObject *)&__pyx_type_3_sa_Alphabet) < 0) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_Alphabet = &__pyx_type_3_sa_Alphabet; + __pyx_vtabptr_3_sa_TrieMap = &__pyx_vtable_3_sa_TrieMap; + __pyx_vtable_3_sa_TrieMap._insert = (struct __pyx_t_3_sa__Trie_Node *(*)(struct __pyx_obj_3_sa_TrieMap *, int *, int))__pyx_f_3_sa_7TrieMap__insert; + __pyx_vtable_3_sa_TrieMap._contains = (struct __pyx_t_3_sa__Trie_Node *(*)(struct __pyx_obj_3_sa_TrieMap *, int *, int))__pyx_f_3_sa_7TrieMap__contains; + if (PyType_Ready(&__pyx_type_3_sa_TrieMap) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_3_sa_TrieMap.tp_dict, __pyx_vtabptr_3_sa_TrieMap) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "TrieMap", (PyObject *)&__pyx_type_3_sa_TrieMap) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_TrieMap = &__pyx_type_3_sa_TrieMap; + __pyx_vtabptr_3_sa_Precomputation = &__pyx_vtable_3_sa_Precomputation; + __pyx_vtable_3_sa_Precomputation.read_map = (PyObject *(*)(struct __pyx_obj_3_sa_Precomputation *, FILE *))__pyx_f_3_sa_14Precomputation_read_map; + __pyx_vtable_3_sa_Precomputation.write_map = (PyObject *(*)(struct __pyx_obj_3_sa_Precomputation *, PyObject *, FILE *))__pyx_f_3_sa_14Precomputation_write_map; + if (PyType_Ready(&__pyx_type_3_sa_Precomputation) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_3_sa_Precomputation.tp_dict, __pyx_vtabptr_3_sa_Precomputation) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Precomputation", (PyObject *)&__pyx_type_3_sa_Precomputation) < 0) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_Precomputation = &__pyx_type_3_sa_Precomputation; + __pyx_vtabptr_3_sa_SuffixArray = &__pyx_vtable_3_sa_SuffixArray; + __pyx_vtable_3_sa_SuffixArray.__pyx___search_high = (int (*)(struct __pyx_obj_3_sa_SuffixArray *, int, int, int, int))__pyx_f_3_sa_11SuffixArray___search_high; + __pyx_vtable_3_sa_SuffixArray.__pyx___search_low = (int (*)(struct __pyx_obj_3_sa_SuffixArray *, int, int, int, int))__pyx_f_3_sa_11SuffixArray___search_low; + __pyx_vtable_3_sa_SuffixArray.__pyx___get_range = (PyObject *(*)(struct __pyx_obj_3_sa_SuffixArray *, int, int, int, int, int))__pyx_f_3_sa_11SuffixArray___get_range; + __pyx_vtable_3_sa_SuffixArray.__pyx___lookup_helper = (PyObject *(*)(struct __pyx_obj_3_sa_SuffixArray *, int, int, int, int))__pyx_f_3_sa_11SuffixArray___lookup_helper; + if (PyType_Ready(&__pyx_type_3_sa_SuffixArray) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_3_sa_SuffixArray.tp_dict, __pyx_vtabptr_3_sa_SuffixArray) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "SuffixArray", (PyObject *)&__pyx_type_3_sa_SuffixArray) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_SuffixArray = &__pyx_type_3_sa_SuffixArray; + if (PyType_Ready(&__pyx_type_3_sa_TrieNode) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "TrieNode", (PyObject *)&__pyx_type_3_sa_TrieNode) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_TrieNode = &__pyx_type_3_sa_TrieNode; + __pyx_type_3_sa_ExtendedTrieNode.tp_base = __pyx_ptype_3_sa_TrieNode; + if (PyType_Ready(&__pyx_type_3_sa_ExtendedTrieNode) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "ExtendedTrieNode", (PyObject *)&__pyx_type_3_sa_ExtendedTrieNode) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_ExtendedTrieNode = &__pyx_type_3_sa_ExtendedTrieNode; + if (PyType_Ready(&__pyx_type_3_sa_TrieTable) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "TrieTable", (PyObject *)&__pyx_type_3_sa_TrieTable) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_TrieTable = &__pyx_type_3_sa_TrieTable; + __pyx_vtabptr_3_sa_PhraseLocation = &__pyx_vtable_3_sa_PhraseLocation; + __pyx_vtable_3_sa_PhraseLocation.contains = (int (*)(struct __pyx_obj_3_sa_PhraseLocation *, int))__pyx_f_3_sa_14PhraseLocation_contains; + if (PyType_Ready(&__pyx_type_3_sa_PhraseLocation) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_3_sa_PhraseLocation.tp_dict, __pyx_vtabptr_3_sa_PhraseLocation) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "PhraseLocation", (PyObject *)&__pyx_type_3_sa_PhraseLocation) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_PhraseLocation = &__pyx_type_3_sa_PhraseLocation; + if (PyType_Ready(&__pyx_type_3_sa_Sampler) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Sampler", (PyObject *)&__pyx_type_3_sa_Sampler) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_Sampler = &__pyx_type_3_sa_Sampler; + __pyx_vtabptr_3_sa_HieroCachingRuleFactory = &__pyx_vtable_3_sa_HieroCachingRuleFactory; + __pyx_vtable_3_sa_HieroCachingRuleFactory.set_idmap = (PyObject *(*)(struct __pyx_obj_3_sa_HieroCachingRuleFactory *, struct __pyx_obj_3_sa_DataArray *))__pyx_f_3_sa_23HieroCachingRuleFactory_set_idmap; + __pyx_vtable_3_sa_HieroCachingRuleFactory.baeza_yates_helper = (int *(*)(struct __pyx_obj_3_sa_HieroCachingRuleFactory *, int, int, int *, int, int, int, int *, int, int, int, int, int *))__pyx_f_3_sa_23HieroCachingRuleFactory_baeza_yates_helper; + __pyx_vtable_3_sa_HieroCachingRuleFactory.compare_matchings_set = (long (*)(struct __pyx_obj_3_sa_HieroCachingRuleFactory *, int, int, int *, int, struct __pyx_t_3_sa_Matching *, int, int))__pyx_f_3_sa_23HieroCachingRuleFactory_compare_matchings_set; + __pyx_vtable_3_sa_HieroCachingRuleFactory.compare_matchings = (long (*)(struct __pyx_obj_3_sa_HieroCachingRuleFactory *, struct __pyx_t_3_sa_Matching *, struct __pyx_t_3_sa_Matching *, int, int))__pyx_f_3_sa_23HieroCachingRuleFactory_compare_matchings; + __pyx_vtable_3_sa_HieroCachingRuleFactory.merge_helper = (int *(*)(struct __pyx_obj_3_sa_HieroCachingRuleFactory *, int, int, int *, int, int, int, int *, int, int, int, int, int *))__pyx_f_3_sa_23HieroCachingRuleFactory_merge_helper; + __pyx_vtable_3_sa_HieroCachingRuleFactory.sort_phrase_loc = (void (*)(struct __pyx_obj_3_sa_HieroCachingRuleFactory *, struct __pyx_obj_3_sa_IntList *, struct __pyx_obj_3_sa_PhraseLocation *, struct __pyx_obj_3_sa_Phrase *))__pyx_f_3_sa_23HieroCachingRuleFactory_sort_phrase_loc; + __pyx_vtable_3_sa_HieroCachingRuleFactory.intersect_helper = (PyObject *(*)(struct __pyx_obj_3_sa_HieroCachingRuleFactory *, struct __pyx_obj_3_sa_Phrase *, struct __pyx_obj_3_sa_Phrase *, struct __pyx_obj_3_sa_PhraseLocation *, struct __pyx_obj_3_sa_PhraseLocation *, int))__pyx_f_3_sa_23HieroCachingRuleFactory_intersect_helper; + __pyx_vtable_3_sa_HieroCachingRuleFactory.loc2str = (PyObject *(*)(struct __pyx_obj_3_sa_HieroCachingRuleFactory *, struct __pyx_obj_3_sa_PhraseLocation *))__pyx_f_3_sa_23HieroCachingRuleFactory_loc2str; + __pyx_vtable_3_sa_HieroCachingRuleFactory.intersect = (struct __pyx_obj_3_sa_PhraseLocation *(*)(struct __pyx_obj_3_sa_HieroCachingRuleFactory *, PyObject *, PyObject *, struct __pyx_obj_3_sa_Phrase *))__pyx_f_3_sa_23HieroCachingRuleFactory_intersect; + __pyx_vtable_3_sa_HieroCachingRuleFactory.find_fixpoint = (int (*)(struct __pyx_obj_3_sa_HieroCachingRuleFactory *, int, PyObject *, int *, int *, int *, int *, int, int, int *, int *, int *, int *, int, int, int, int, int, int, int, int, int, int, int))__pyx_f_3_sa_23HieroCachingRuleFactory_find_fixpoint; + __pyx_vtable_3_sa_HieroCachingRuleFactory.find_projection = (PyObject *(*)(struct __pyx_obj_3_sa_HieroCachingRuleFactory *, int, int, int *, int *, int *, int *))__pyx_f_3_sa_23HieroCachingRuleFactory_find_projection; + __pyx_vtable_3_sa_HieroCachingRuleFactory.int_arr_extend = (int *(*)(struct __pyx_obj_3_sa_HieroCachingRuleFactory *, int *, int *, int *, int))__pyx_f_3_sa_23HieroCachingRuleFactory_int_arr_extend; + __pyx_vtable_3_sa_HieroCachingRuleFactory.extract_phrases = (PyObject *(*)(struct __pyx_obj_3_sa_HieroCachingRuleFactory *, int, int, int *, int *, int *, int, int, int, int *, int *, int *, int, int, int))__pyx_f_3_sa_23HieroCachingRuleFactory_extract_phrases; + __pyx_vtable_3_sa_HieroCachingRuleFactory.create_alignments = (PyObject *(*)(struct __pyx_obj_3_sa_HieroCachingRuleFactory *, int *, int, PyObject *, PyObject *))__pyx_f_3_sa_23HieroCachingRuleFactory_create_alignments; + __pyx_vtable_3_sa_HieroCachingRuleFactory.extract = (PyObject *(*)(struct __pyx_obj_3_sa_HieroCachingRuleFactory *, struct __pyx_obj_3_sa_Phrase *, struct __pyx_t_3_sa_Matching *, int *, int))__pyx_f_3_sa_23HieroCachingRuleFactory_extract; + if (PyType_Ready(&__pyx_type_3_sa_HieroCachingRuleFactory) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_3_sa_HieroCachingRuleFactory.tp_dict, __pyx_vtabptr_3_sa_HieroCachingRuleFactory) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "HieroCachingRuleFactory", (PyObject *)&__pyx_type_3_sa_HieroCachingRuleFactory) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa_HieroCachingRuleFactory = &__pyx_type_3_sa_HieroCachingRuleFactory; + if (PyType_Ready(&__pyx_type_3_sa___pyx_scope_struct__compute_stats) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa___pyx_scope_struct__compute_stats = &__pyx_type_3_sa___pyx_scope_struct__compute_stats; + if (PyType_Ready(&__pyx_type_3_sa___pyx_scope_struct_1___iter__) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa___pyx_scope_struct_1___iter__ = &__pyx_type_3_sa___pyx_scope_struct_1___iter__; + if (PyType_Ready(&__pyx_type_3_sa___pyx_scope_struct_2_input) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa___pyx_scope_struct_2_input = &__pyx_type_3_sa___pyx_scope_struct_2_input; + /*--- Type import code ---*/ + /*--- Variable import code ---*/ + /*--- Function import code ---*/ + /*--- Execution code ---*/ + + /* "_sa.pyx":1 + * import logging # <<<<<<<<<<<<<< + * import resource + * import gzip + */ + __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__logging), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__logging, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_sa.pyx":2 + * import logging + * import resource # <<<<<<<<<<<<<< + * import gzip + * + */ + __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__resource), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__resource, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_sa.pyx":3 + * import logging + * import resource + * import gzip # <<<<<<<<<<<<<< + * + * cdef float monitor_cpu(): + */ + __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__gzip), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__gzip, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_sa.pyx":9 + * resource.getrusage(resource.RUSAGE_SELF).ru_stime) + * + * def gzip_or_text(char* filename): # <<<<<<<<<<<<<< + * if filename.endswith('.gz'): + * return gzip.GzipFile(filename) + */ + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_3_sa_1gzip_or_text, NULL, __pyx_n_s___sa); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__gzip_or_text, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_sa.pyx":15 + * return open(filename) + * + * logger = logging.getLogger('cdec.sa') # <<<<<<<<<<<<<< + * + * include "float_list.pxi" + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logging); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__getLogger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_136), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__logger, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":54 + * cdef id2eword, id2fword, eword2id, fword2id + * + * def __cinit__(self, from_text=None, from_data=False, from_binary=None, # <<<<<<<<<<<<<< + * earray=None, fsarray=None, alignment=None): + * self.id2eword = [] + */ + __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_k_38 = __pyx_t_1; + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":17 + * from libc.string cimport memset + * + * cdef int MIN_BOTTOM_SIZE = 32 # <<<<<<<<<<<<<< + * cdef int MIN_BOTTOM_BITS = 5 + * cdef int LOWER_MASK[32] + */ + __pyx_v_3_sa_MIN_BOTTOM_SIZE = 32; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":18 + * + * cdef int MIN_BOTTOM_SIZE = 32 + * cdef int MIN_BOTTOM_BITS = 5 # <<<<<<<<<<<<<< + * cdef int LOWER_MASK[32] + * + */ + __pyx_v_3_sa_MIN_BOTTOM_BITS = 5; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":28 + * LOWER_MASK[i] = mask + * + * _init_lower_mask() # <<<<<<<<<<<<<< + * + * cdef struct _BitSet: + */ + __pyx_f_3_sa__init_lower_mask(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":4 + * from libc.stdlib cimport malloc, realloc, strtol + * + * cdef int INDEX_SHIFT = 3 # <<<<<<<<<<<<<< + * cdef int INDEX_MASK = (1<= 3 + "%s() got multiple values for keyword argument '%U'", func_name, kw_name); + #else + "%s() got multiple values for keyword argument '%s'", func_name, + PyString_AS_STRING(kw_name)); + #endif +} + +static int __Pyx_ParseOptionalKeywords( + PyObject *kwds, + PyObject **argnames[], + PyObject *kwds2, + PyObject *values[], + Py_ssize_t num_pos_args, + const char* function_name) +{ + PyObject *key = 0, *value = 0; + Py_ssize_t pos = 0; + PyObject*** name; + PyObject*** first_kw_arg = argnames + num_pos_args; + while (PyDict_Next(kwds, &pos, &key, &value)) { + name = first_kw_arg; + while (*name && (**name != key)) name++; + if (*name) { + values[name-argnames] = value; + } else { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) { + #else + if (unlikely(!PyUnicode_Check(key))) { + #endif + goto invalid_keyword_type; + } else { + for (name = first_kw_arg; *name; name++) { + #if PY_MAJOR_VERSION >= 3 + if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && + PyUnicode_Compare(**name, key) == 0) break; + #else + if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && + _PyString_Eq(**name, key)) break; + #endif + } + if (*name) { + values[name-argnames] = value; + } else { + for (name=argnames; name != first_kw_arg; name++) { + if (**name == key) goto arg_passed_twice; + #if PY_MAJOR_VERSION >= 3 + if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && + PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice; + #else + if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && + _PyString_Eq(**name, key)) goto arg_passed_twice; + #endif + } + if (kwds2) { + if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; + } else { + goto invalid_keyword; + } + } + } + } + } + return 0; +arg_passed_twice: + __Pyx_RaiseDoubleKeywordsError(function_name, **name); + goto bad; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%s() keywords must be strings", function_name); + goto bad; +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%s() got an unexpected keyword argument '%s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif +bad: + return -1; +} + +static void __Pyx_RaiseArgtupleInvalid( + const char* func_name, + int exact, + Py_ssize_t num_min, + Py_ssize_t num_max, + Py_ssize_t num_found) +{ + Py_ssize_t num_expected; + const char *more_or_less; + if (num_found < num_min) { + num_expected = num_min; + more_or_less = "at least"; + } else { + num_expected = num_max; + more_or_less = "at most"; + } + if (exact) { + more_or_less = "exactly"; + } + PyErr_Format(PyExc_TypeError, + "%s() takes %s %" PY_FORMAT_SIZE_T "d positional argument%s (%" PY_FORMAT_SIZE_T "d given)", + func_name, more_or_less, num_expected, + (num_expected == 1) ? "" : "s", num_found); +} + +static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { +#if CYTHON_COMPILING_IN_CPYTHON + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyThreadState *tstate = PyThreadState_GET(); + tmp_type = tstate->curexc_type; + tmp_value = tstate->curexc_value; + tmp_tb = tstate->curexc_traceback; + tstate->curexc_type = type; + tstate->curexc_value = value; + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#else + PyErr_Restore(type, value, tb); +#endif +} +static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { +#if CYTHON_COMPILING_IN_CPYTHON + PyThreadState *tstate = PyThreadState_GET(); + *type = tstate->curexc_type; + *value = tstate->curexc_value; + *tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +#else + PyErr_Fetch(type, value, tb); +#endif +} + +#if PY_MAJOR_VERSION < 3 +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, + CYTHON_UNUSED PyObject *cause) { + Py_XINCREF(type); + Py_XINCREF(value); + Py_XINCREF(tb); + if (tb == Py_None) { + Py_DECREF(tb); + tb = 0; + } + else if (tb != NULL && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto raise_error; + } + if (value == NULL) { + value = Py_None; + Py_INCREF(value); + } + #if PY_VERSION_HEX < 0x02050000 + if (!PyClass_Check(type)) + #else + if (!PyType_Check(type)) + #endif + { + if (value != Py_None) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto raise_error; + } + Py_DECREF(value); + value = type; + #if PY_VERSION_HEX < 0x02050000 + if (PyInstance_Check(type)) { + type = (PyObject*) ((PyInstanceObject*)type)->in_class; + Py_INCREF(type); + } + else { + type = 0; + PyErr_SetString(PyExc_TypeError, + "raise: exception must be an old-style class or instance"); + goto raise_error; + } + #else + type = (PyObject*) Py_TYPE(type); + Py_INCREF(type); + if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto raise_error; + } + #endif + } + __Pyx_ErrRestore(type, value, tb); + return; +raise_error: + Py_XDECREF(value); + Py_XDECREF(type); + Py_XDECREF(tb); + return; +} +#else /* Python 3+ */ +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + if (tb == Py_None) { + tb = 0; + } else if (tb && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto bad; + } + if (value == Py_None) + value = 0; + if (PyExceptionInstance_Check(type)) { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto bad; + } + value = type; + type = (PyObject*) Py_TYPE(value); + } else if (!PyExceptionClass_Check(type)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto bad; + } + if (cause) { + PyObject *fixed_cause; + if (PyExceptionClass_Check(cause)) { + fixed_cause = PyObject_CallObject(cause, NULL); + if (fixed_cause == NULL) + goto bad; + } + else if (PyExceptionInstance_Check(cause)) { + fixed_cause = cause; + Py_INCREF(fixed_cause); + } + else { + PyErr_SetString(PyExc_TypeError, + "exception causes must derive from " + "BaseException"); + goto bad; + } + if (!value) { + value = PyObject_CallObject(type, NULL); + } + PyException_SetCause(value, fixed_cause); + } + PyErr_SetObject(type, value); + if (tb) { + PyThreadState *tstate = PyThreadState_GET(); + PyObject* tmp_tb = tstate->curexc_traceback; + if (tb != tmp_tb) { + Py_INCREF(tb); + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_tb); + } + } +bad: + return; +} +#endif + +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { + if (unlikely(!type)) { + PyErr_Format(PyExc_SystemError, "Missing type object"); + return 0; + } + if (likely(PyObject_TypeCheck(obj, type))) + return 1; + PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", + Py_TYPE(obj)->tp_name, type->tp_name); + return 0; +} + +static CYTHON_INLINE int __Pyx_CheckKeywordStrings( + PyObject *kwdict, + const char* function_name, + int kw_allowed) +{ + PyObject* key = 0; + Py_ssize_t pos = 0; +#if CPYTHON_COMPILING_IN_PYPY + if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0)) + goto invalid_keyword; + return 1; +#else + while (PyDict_Next(kwdict, &pos, &key, 0)) { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) + #else + if (unlikely(!PyUnicode_Check(key))) + #endif + goto invalid_keyword_type; + } + if ((!kw_allowed) && unlikely(key)) + goto invalid_keyword; + return 1; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%s() keywords must be strings", function_name); + return 0; +#endif +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%s() got an unexpected keyword argument '%s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif + return 0; +} + +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) { + PyObject *local_type, *local_value, *local_tb; +#if CYTHON_COMPILING_IN_CPYTHON + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyThreadState *tstate = PyThreadState_GET(); + local_type = tstate->curexc_type; + local_value = tstate->curexc_value; + local_tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +#else + PyErr_Fetch(&local_type, &local_value, &local_tb); +#endif + PyErr_NormalizeException(&local_type, &local_value, &local_tb); +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(tstate->curexc_type)) +#else + if (unlikely(PyErr_Occurred())) +#endif + goto bad; + #if PY_MAJOR_VERSION >= 3 + if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) + goto bad; + #endif + Py_INCREF(local_type); + Py_INCREF(local_value); + Py_INCREF(local_tb); + *type = local_type; + *value = local_value; + *tb = local_tb; +#if CYTHON_COMPILING_IN_CPYTHON + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = local_type; + tstate->exc_value = local_value; + tstate->exc_traceback = local_tb; + /* Make sure tstate is in a consistent state when we XDECREF + these objects (DECREF may run arbitrary code). */ + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#else + PyErr_SetExcInfo(local_type, local_value, local_tb); +#endif + return 0; +bad: + *type = 0; + *value = 0; + *tb = 0; + Py_XDECREF(local_type); + Py_XDECREF(local_value); + Py_XDECREF(local_tb); + return -1; +} + +static CYTHON_INLINE long __Pyx_div_long(long a, long b) { + long q = a / b; + long r = a - q*b; + q -= ((r != 0) & ((r ^ b) < 0)); + return q; +} + +static CYTHON_INLINE long __Pyx_mod_long(long a, long b) { + long r = a % b; + r += ((r != 0) & ((r ^ b) < 0)) * b; + return r; +} + +static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { + PyErr_Format(PyExc_ValueError, + "too many values to unpack (expected %" PY_FORMAT_SIZE_T "d)", expected); +} + +static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { + PyErr_Format(PyExc_ValueError, + "need more than %" PY_FORMAT_SIZE_T "d value%s to unpack", + index, (index == 1) ? "" : "s"); +} + +static CYTHON_INLINE int __Pyx_IterFinish(void) { +#if CYTHON_COMPILING_IN_CPYTHON + PyThreadState *tstate = PyThreadState_GET(); + PyObject* exc_type = tstate->curexc_type; + if (unlikely(exc_type)) { + if (likely(exc_type == PyExc_StopIteration) || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)) { + PyObject *exc_value, *exc_tb; + exc_value = tstate->curexc_value; + exc_tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; + Py_DECREF(exc_type); + Py_XDECREF(exc_value); + Py_XDECREF(exc_tb); + return 0; + } else { + return -1; + } + } + return 0; +#else + if (unlikely(PyErr_Occurred())) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) { + PyErr_Clear(); + return 0; + } else { + return -1; + } + } + return 0; +#endif +} + +static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { + if (unlikely(retval)) { + Py_DECREF(retval); + __Pyx_RaiseTooManyValuesError(expected); + return -1; + } else { + return __Pyx_IterFinish(); + } + return 0; +} + +static double __Pyx__PyObject_AsDouble(PyObject* obj) { + PyObject* float_value; +#if CYTHON_COMPILING_IN_PYPY + float_value = PyNumber_Float(obj); +#else + if (Py_TYPE(obj)->tp_as_number && Py_TYPE(obj)->tp_as_number->nb_float) { + return PyFloat_AsDouble(obj); + } else if (PyUnicode_CheckExact(obj) || PyBytes_CheckExact(obj)) { +#if PY_MAJOR_VERSION >= 3 + float_value = PyFloat_FromString(obj); +#else + float_value = PyFloat_FromString(obj, 0); +#endif + } else { + PyObject* args = PyTuple_New(1); + if (unlikely(!args)) goto bad; + PyTuple_SET_ITEM(args, 0, obj); + float_value = PyObject_Call((PyObject*)&PyFloat_Type, args, 0); + PyTuple_SET_ITEM(args, 0, 0); + Py_DECREF(args); + } +#endif + if (likely(float_value)) { + double value = PyFloat_AS_DOUBLE(float_value); + Py_DECREF(float_value); + return value; + } +bad: + return (double)-1; +} + +static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) { + PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname); +} + +static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, + const char *name, int exact) +{ + if (!type) { + PyErr_Format(PyExc_SystemError, "Missing type object"); + return 0; + } + if (none_allowed && obj == Py_None) return 1; + else if (exact) { + if (Py_TYPE(obj) == type) return 1; + } + else { + if (PyObject_TypeCheck(obj, type)) return 1; + } + PyErr_Format(PyExc_TypeError, + "Argument '%s' has incorrect type (expected %s, got %s)", + name, type->tp_name, Py_TYPE(obj)->tp_name); + return 0; +} + +static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); +} + +static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) { + if (t == Py_None) { + __Pyx_RaiseNoneNotIterableError(); + } else if (PyTuple_GET_SIZE(t) < index) { + __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t)); + } else { + __Pyx_RaiseTooManyValuesError(index); + } +} + +static CYTHON_INLINE int __Pyx_unpack_tuple2(PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, + int is_tuple, int has_known_size, int decref_tuple) { + Py_ssize_t index; + PyObject *value1 = NULL, *value2 = NULL, *iter = NULL; + if (!is_tuple && unlikely(!PyTuple_Check(tuple))) { + iternextfunc iternext; + iter = PyObject_GetIter(tuple); + if (unlikely(!iter)) goto bad; + if (decref_tuple) { Py_DECREF(tuple); tuple = NULL; } + iternext = Py_TYPE(iter)->tp_iternext; + value1 = iternext(iter); if (unlikely(!value1)) { index = 0; goto unpacking_failed; } + value2 = iternext(iter); if (unlikely(!value2)) { index = 1; goto unpacking_failed; } + if (!has_known_size && unlikely(__Pyx_IternextUnpackEndCheck(iternext(iter), 2))) goto bad; + Py_DECREF(iter); + } else { + if (!has_known_size && unlikely(PyTuple_GET_SIZE(tuple) != 2)) { + __Pyx_UnpackTupleError(tuple, 2); + goto bad; + } +#if CYTHON_COMPILING_IN_PYPY + value1 = PySequence_ITEM(tuple, 0); + if (unlikely(!value1)) goto bad; + value2 = PySequence_ITEM(tuple, 1); + if (unlikely(!value2)) goto bad; +#else + value1 = PyTuple_GET_ITEM(tuple, 0); + value2 = PyTuple_GET_ITEM(tuple, 1); + Py_INCREF(value1); + Py_INCREF(value2); +#endif + if (decref_tuple) { Py_DECREF(tuple); } + } + *pvalue1 = value1; + *pvalue2 = value2; + return 0; +unpacking_failed: + if (!has_known_size && __Pyx_IterFinish() == 0) + __Pyx_RaiseNeedMoreValuesError(index); +bad: + Py_XDECREF(iter); + Py_XDECREF(value1); + Py_XDECREF(value2); + if (decref_tuple) { Py_XDECREF(tuple); } + return -1; +} + +static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name, + Py_ssize_t* p_orig_length, int* p_source_is_dict) { + is_dict = is_dict || likely(PyDict_CheckExact(iterable)); + *p_source_is_dict = is_dict; +#if !CYTHON_COMPILING_IN_PYPY + if (is_dict) { + *p_orig_length = PyDict_Size(iterable); + Py_INCREF(iterable); + return iterable; + } +#endif + *p_orig_length = 0; + if (method_name) { + PyObject* iter; + iterable = PyObject_CallMethodObjArgs(iterable, method_name, NULL); + if (!iterable) + return NULL; +#if !CYTHON_COMPILING_IN_PYPY + if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable)) + return iterable; +#endif + iter = PyObject_GetIter(iterable); + Py_DECREF(iterable); + return iter; + } + return PyObject_GetIter(iterable); +} +static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* iter_obj, Py_ssize_t orig_length, Py_ssize_t* ppos, + PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) { + PyObject* next_item; +#if !CYTHON_COMPILING_IN_PYPY + if (source_is_dict) { + PyObject *key, *value; + if (unlikely(orig_length != PyDict_Size(iter_obj))) { + PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration"); + return -1; + } + if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) { + return 0; + } + if (pitem) { + PyObject* tuple = PyTuple_New(2); + if (unlikely(!tuple)) { + return -1; + } + Py_INCREF(key); + Py_INCREF(value); + PyTuple_SET_ITEM(tuple, 0, key); + PyTuple_SET_ITEM(tuple, 1, value); + *pitem = tuple; + } else { + if (pkey) { + Py_INCREF(key); + *pkey = key; + } + if (pvalue) { + Py_INCREF(value); + *pvalue = value; + } + } + return 1; + } else if (PyTuple_CheckExact(iter_obj)) { + Py_ssize_t pos = *ppos; + if (unlikely(pos >= PyTuple_GET_SIZE(iter_obj))) return 0; + *ppos = pos + 1; + next_item = PyTuple_GET_ITEM(iter_obj, pos); + Py_INCREF(next_item); + } else if (PyList_CheckExact(iter_obj)) { + Py_ssize_t pos = *ppos; + if (unlikely(pos >= PyList_GET_SIZE(iter_obj))) return 0; + *ppos = pos + 1; + next_item = PyList_GET_ITEM(iter_obj, pos); + Py_INCREF(next_item); + } else +#endif + { + next_item = PyIter_Next(iter_obj); + if (unlikely(!next_item)) { + return __Pyx_IterFinish(); + } + } + if (pitem) { + *pitem = next_item; + } else if (pkey && pvalue) { + if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1)) + return -1; + } else if (pkey) { + *pkey = next_item; + } else { + *pvalue = next_item; + } + return 1; +} + +static CYTHON_INLINE int __Pyx_div_int(int a, int b) { + int q = a / b; + int r = a - q*b; + q -= ((r != 0) & ((r ^ b) < 0)); + return q; +} + +static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) { +#if CYTHON_COMPILING_IN_CPYTHON + PyThreadState *tstate = PyThreadState_GET(); + *type = tstate->exc_type; + *value = tstate->exc_value; + *tb = tstate->exc_traceback; + Py_XINCREF(*type); + Py_XINCREF(*value); + Py_XINCREF(*tb); +#else + PyErr_GetExcInfo(type, value, tb); +#endif +} +static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) { +#if CYTHON_COMPILING_IN_CPYTHON + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyThreadState *tstate = PyThreadState_GET(); + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = type; + tstate->exc_value = value; + tstate->exc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#else + PyErr_SetExcInfo(type, value, tb); +#endif +} + +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) { + PyObject *py_import = 0; + PyObject *empty_list = 0; + PyObject *module = 0; + PyObject *global_dict = 0; + PyObject *empty_dict = 0; + PyObject *list; + py_import = __Pyx_GetAttrString(__pyx_b, "__import__"); + if (!py_import) + goto bad; + if (from_list) + list = from_list; + else { + empty_list = PyList_New(0); + if (!empty_list) + goto bad; + list = empty_list; + } + global_dict = PyModule_GetDict(__pyx_m); + if (!global_dict) + goto bad; + empty_dict = PyDict_New(); + if (!empty_dict) + goto bad; + #if PY_VERSION_HEX >= 0x02050000 + { + #if PY_MAJOR_VERSION >= 3 + if (level == -1) { + if (strchr(__Pyx_MODULE_NAME, '.')) { + /* try package relative import first */ + PyObject *py_level = PyInt_FromLong(1); + if (!py_level) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, py_level, NULL); + Py_DECREF(py_level); + if (!module) { + if (!PyErr_ExceptionMatches(PyExc_ImportError)) + goto bad; + PyErr_Clear(); + } + } + level = 0; /* try absolute import on failure */ + } + #endif + if (!module) { + PyObject *py_level = PyInt_FromLong(level); + if (!py_level) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, py_level, NULL); + Py_DECREF(py_level); + } + } + #else + if (level>0) { + PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4."); + goto bad; + } + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, NULL); + #endif +bad: + Py_XDECREF(empty_list); + Py_XDECREF(py_import); + Py_XDECREF(empty_dict); + return module; +} + +static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { + const unsigned char neg_one = (unsigned char)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(unsigned char) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(unsigned char)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to unsigned char" : + "value too large to convert to unsigned char"); + } + return (unsigned char)-1; + } + return (unsigned char)val; + } + return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); +} + +static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { + const unsigned short neg_one = (unsigned short)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(unsigned short) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(unsigned short)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to unsigned short" : + "value too large to convert to unsigned short"); + } + return (unsigned short)-1; + } + return (unsigned short)val; + } + return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); +} + +static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { + const unsigned int neg_one = (unsigned int)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(unsigned int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(unsigned int)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to unsigned int" : + "value too large to convert to unsigned int"); + } + return (unsigned int)-1; + } + return (unsigned int)val; + } + return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); +} + +static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) { + const char neg_one = (char)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(char) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(char)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to char" : + "value too large to convert to char"); + } + return (char)-1; + } + return (char)val; + } + return (char)__Pyx_PyInt_AsLong(x); +} + +static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) { + const short neg_one = (short)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(short) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(short)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to short" : + "value too large to convert to short"); + } + return (short)-1; + } + return (short)val; + } + return (short)__Pyx_PyInt_AsLong(x); +} + +static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) { + const int neg_one = (int)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(int)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to int" : + "value too large to convert to int"); + } + return (int)-1; + } + return (int)val; + } + return (int)__Pyx_PyInt_AsLong(x); +} + +static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { + const signed char neg_one = (signed char)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(signed char) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(signed char)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to signed char" : + "value too large to convert to signed char"); + } + return (signed char)-1; + } + return (signed char)val; + } + return (signed char)__Pyx_PyInt_AsSignedLong(x); +} + +static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { + const signed short neg_one = (signed short)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(signed short) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(signed short)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to signed short" : + "value too large to convert to signed short"); + } + return (signed short)-1; + } + return (signed short)val; + } + return (signed short)__Pyx_PyInt_AsSignedLong(x); +} + +static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { + const signed int neg_one = (signed int)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(signed int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(signed int)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to signed int" : + "value too large to convert to signed int"); + } + return (signed int)-1; + } + return (signed int)val; + } + return (signed int)__Pyx_PyInt_AsSignedLong(x); +} + +static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) { + const int neg_one = (int)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(int)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to int" : + "value too large to convert to int"); + } + return (int)-1; + } + return (int)val; + } + return (int)__Pyx_PyInt_AsLong(x); +} + +static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { + const unsigned long neg_one = (unsigned long)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned long"); + return (unsigned long)-1; + } + return (unsigned long)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned long"); + return (unsigned long)-1; + } + return (unsigned long)PyLong_AsUnsignedLong(x); + } else { + return (unsigned long)PyLong_AsLong(x); + } + } else { + unsigned long val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (unsigned long)-1; + val = __Pyx_PyInt_AsUnsignedLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { + const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned PY_LONG_LONG"); + return (unsigned PY_LONG_LONG)-1; + } + return (unsigned PY_LONG_LONG)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned PY_LONG_LONG"); + return (unsigned PY_LONG_LONG)-1; + } + return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); + } else { + return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x); + } + } else { + unsigned PY_LONG_LONG val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (unsigned PY_LONG_LONG)-1; + val = __Pyx_PyInt_AsUnsignedLongLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { + const long neg_one = (long)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long)-1; + } + return (long)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long)-1; + } + return (long)PyLong_AsUnsignedLong(x); + } else { + return (long)PyLong_AsLong(x); + } + } else { + long val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (long)-1; + val = __Pyx_PyInt_AsLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { + const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to PY_LONG_LONG"); + return (PY_LONG_LONG)-1; + } + return (PY_LONG_LONG)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to PY_LONG_LONG"); + return (PY_LONG_LONG)-1; + } + return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); + } else { + return (PY_LONG_LONG)PyLong_AsLongLong(x); + } + } else { + PY_LONG_LONG val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (PY_LONG_LONG)-1; + val = __Pyx_PyInt_AsLongLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { + const signed long neg_one = (signed long)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to signed long"); + return (signed long)-1; + } + return (signed long)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to signed long"); + return (signed long)-1; + } + return (signed long)PyLong_AsUnsignedLong(x); + } else { + return (signed long)PyLong_AsLong(x); + } + } else { + signed long val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (signed long)-1; + val = __Pyx_PyInt_AsSignedLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { + const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to signed PY_LONG_LONG"); + return (signed PY_LONG_LONG)-1; + } + return (signed PY_LONG_LONG)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to signed PY_LONG_LONG"); + return (signed PY_LONG_LONG)-1; + } + return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); + } else { + return (signed PY_LONG_LONG)PyLong_AsLongLong(x); + } + } else { + signed PY_LONG_LONG val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (signed PY_LONG_LONG)-1; + val = __Pyx_PyInt_AsSignedLongLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, + CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename) { + PyObject *old_exc, *old_val, *old_tb; + PyObject *ctx; + __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); + #if PY_MAJOR_VERSION < 3 + ctx = PyString_FromString(name); + #else + ctx = PyUnicode_FromString(name); + #endif + __Pyx_ErrRestore(old_exc, old_val, old_tb); + if (!ctx) { + PyErr_WriteUnraisable(Py_None); + } else { + PyErr_WriteUnraisable(ctx); + Py_DECREF(ctx); + } +} + +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; +#if CYTHON_COMPILING_IN_CPYTHON + PyThreadState *tstate = PyThreadState_GET(); + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = *type; + tstate->exc_value = *value; + tstate->exc_traceback = *tb; +#else + PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb); + PyErr_SetExcInfo(*type, *value, *tb); +#endif + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} + +static PyObject *__Pyx_Generator_Next(PyObject *self); +static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value); +static PyObject *__Pyx_Generator_Close(PyObject *self); +static PyObject *__Pyx_Generator_Throw(PyObject *gen, PyObject *args); +static PyTypeObject *__pyx_GeneratorType = 0; +#define __Pyx_Generator_CheckExact(obj) (Py_TYPE(obj) == __pyx_GeneratorType) +#define __Pyx_Generator_Undelegate(gen) Py_CLEAR((gen)->yieldfrom) +#if 1 || PY_VERSION_HEX < 0x030300B0 +static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue) { + PyObject *et, *ev, *tb; + PyObject *value = NULL; + __Pyx_ErrFetch(&et, &ev, &tb); + if (!et) { + Py_XDECREF(tb); + Py_XDECREF(ev); + Py_INCREF(Py_None); + *pvalue = Py_None; + return 0; + } + if (unlikely(et != PyExc_StopIteration) && + unlikely(!PyErr_GivenExceptionMatches(et, PyExc_StopIteration))) { + __Pyx_ErrRestore(et, ev, tb); + return -1; + } + if (likely(et == PyExc_StopIteration)) { + if (likely(!ev) || !PyObject_IsInstance(ev, PyExc_StopIteration)) { + if (!ev) { + Py_INCREF(Py_None); + ev = Py_None; + } + Py_XDECREF(tb); + Py_DECREF(et); + *pvalue = ev; + return 0; + } + } + PyErr_NormalizeException(&et, &ev, &tb); + if (unlikely(!PyObject_IsInstance(ev, PyExc_StopIteration))) { + __Pyx_ErrRestore(et, ev, tb); + return -1; + } + Py_XDECREF(tb); + Py_DECREF(et); +#if PY_VERSION_HEX >= 0x030300A0 + value = ((PyStopIterationObject *)ev)->value; + Py_INCREF(value); + Py_DECREF(ev); +#else + { + PyObject* args = PyObject_GetAttrString(ev, "args"); + Py_DECREF(ev); + if (likely(args)) { + value = PyObject_GetItem(args, 0); + Py_DECREF(args); + } + if (unlikely(!value)) { + __Pyx_ErrRestore(NULL, NULL, NULL); + Py_INCREF(Py_None); + value = Py_None; + } + } +#endif + *pvalue = value; + return 0; +} +#endif +static CYTHON_INLINE +void __Pyx_Generator_ExceptionClear(__pyx_GeneratorObject *self) { + PyObject *exc_type = self->exc_type; + PyObject *exc_value = self->exc_value; + PyObject *exc_traceback = self->exc_traceback; + self->exc_type = NULL; + self->exc_value = NULL; + self->exc_traceback = NULL; + Py_XDECREF(exc_type); + Py_XDECREF(exc_value); + Py_XDECREF(exc_traceback); +} +static CYTHON_INLINE +int __Pyx_Generator_CheckRunning(__pyx_GeneratorObject *gen) { + if (unlikely(gen->is_running)) { + PyErr_SetString(PyExc_ValueError, + "generator already executing"); + return 1; + } + return 0; +} +static CYTHON_INLINE +PyObject *__Pyx_Generator_SendEx(__pyx_GeneratorObject *self, PyObject *value) { + PyObject *retval; + assert(!self->is_running); + if (unlikely(self->resume_label == 0)) { + if (unlikely(value && value != Py_None)) { + PyErr_SetString(PyExc_TypeError, + "can't send non-None value to a " + "just-started generator"); + return NULL; + } + } + if (unlikely(self->resume_label == -1)) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + if (value) { +#if CYTHON_COMPILING_IN_PYPY +#else + /* Generators always return to their most recent caller, not + * necessarily their creator. */ + if (self->exc_traceback) { + PyThreadState *tstate = PyThreadState_GET(); + PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback; + PyFrameObject *f = tb->tb_frame; + Py_XINCREF(tstate->frame); + assert(f->f_back == NULL); + f->f_back = tstate->frame; + } +#endif + __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, + &self->exc_traceback); + } else { + __Pyx_Generator_ExceptionClear(self); + } + self->is_running = 1; + retval = self->body((PyObject *) self, value); + self->is_running = 0; + if (retval) { + __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value, + &self->exc_traceback); +#if CYTHON_COMPILING_IN_PYPY +#else + /* Don't keep the reference to f_back any longer than necessary. It + * may keep a chain of frames alive or it could create a reference + * cycle. */ + if (self->exc_traceback) { + PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback; + PyFrameObject *f = tb->tb_frame; + Py_CLEAR(f->f_back); + } +#endif + } else { + __Pyx_Generator_ExceptionClear(self); + } + return retval; +} +static CYTHON_INLINE +PyObject *__Pyx_Generator_FinishDelegation(__pyx_GeneratorObject *gen) { + PyObject *ret; + PyObject *val = NULL; + __Pyx_Generator_Undelegate(gen); + __Pyx_PyGen_FetchStopIterationValue(&val); + ret = __Pyx_Generator_SendEx(gen, val); + Py_XDECREF(val); + return ret; +} +static PyObject *__Pyx_Generator_Next(PyObject *self) { + __pyx_GeneratorObject *gen = (__pyx_GeneratorObject*) self; + PyObject *yf = gen->yieldfrom; + if (unlikely(__Pyx_Generator_CheckRunning(gen))) + return NULL; + if (yf) { + PyObject *ret; + gen->is_running = 1; + ret = Py_TYPE(yf)->tp_iternext(yf); + gen->is_running = 0; + if (likely(ret)) { + return ret; + } + return __Pyx_Generator_FinishDelegation(gen); + } + return __Pyx_Generator_SendEx(gen, Py_None); +} +static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value) { + __pyx_GeneratorObject *gen = (__pyx_GeneratorObject*) self; + PyObject *yf = gen->yieldfrom; + if (unlikely(__Pyx_Generator_CheckRunning(gen))) + return NULL; + if (yf) { + PyObject *ret; + gen->is_running = 1; + if (__Pyx_Generator_CheckExact(yf)) { + ret = __Pyx_Generator_Send(yf, value); + } else { + if (value == Py_None) + ret = PyIter_Next(yf); + else + ret = PyObject_CallMethod(yf, (char*)"send", (char*)"O", value); + } + gen->is_running = 0; + if (likely(ret)) { + return ret; + } + return __Pyx_Generator_FinishDelegation(gen); + } + return __Pyx_Generator_SendEx(gen, value); +} +static int __Pyx_Generator_CloseIter(__pyx_GeneratorObject *gen, PyObject *yf) { + PyObject *retval = NULL; + int err = 0; + if (__Pyx_Generator_CheckExact(yf)) { + retval = __Pyx_Generator_Close(yf); + if (!retval) + return -1; + } else { + PyObject *meth; + gen->is_running = 1; + meth = PyObject_GetAttrString(yf, "close"); + if (unlikely(!meth)) { + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_WriteUnraisable(yf); + } + PyErr_Clear(); + } else { + retval = PyObject_CallFunction(meth, NULL); + Py_DECREF(meth); + if (!retval) + err = -1; + } + gen->is_running = 0; + } + Py_XDECREF(retval); + return err; +} +static PyObject *__Pyx_Generator_Close(PyObject *self) { + __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; + PyObject *retval, *raised_exception; + PyObject *yf = gen->yieldfrom; + int err = 0; + if (unlikely(__Pyx_Generator_CheckRunning(gen))) + return NULL; + if (yf) { + Py_INCREF(yf); + err = __Pyx_Generator_CloseIter(gen, yf); + __Pyx_Generator_Undelegate(gen); + Py_DECREF(yf); + } + if (err == 0) +#if PY_VERSION_HEX < 0x02050000 + PyErr_SetNone(PyExc_StopIteration); +#else + PyErr_SetNone(PyExc_GeneratorExit); +#endif + retval = __Pyx_Generator_SendEx(gen, NULL); + if (retval) { + Py_DECREF(retval); + PyErr_SetString(PyExc_RuntimeError, + "generator ignored GeneratorExit"); + return NULL; + } + raised_exception = PyErr_Occurred(); + if (!raised_exception + || raised_exception == PyExc_StopIteration +#if PY_VERSION_HEX >= 0x02050000 + || raised_exception == PyExc_GeneratorExit + || PyErr_GivenExceptionMatches(raised_exception, PyExc_GeneratorExit) +#endif + || PyErr_GivenExceptionMatches(raised_exception, PyExc_StopIteration)) + { + if (raised_exception) PyErr_Clear(); /* ignore these errors */ + Py_INCREF(Py_None); + return Py_None; + } + return NULL; +} +static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args) { + __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; + PyObject *typ; + PyObject *tb = NULL; + PyObject *val = NULL; + PyObject *yf = gen->yieldfrom; + if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb)) + return NULL; + if (unlikely(__Pyx_Generator_CheckRunning(gen))) + return NULL; + if (yf) { + PyObject *ret; + Py_INCREF(yf); +#if PY_VERSION_HEX >= 0x02050000 + if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit)) { + int err = __Pyx_Generator_CloseIter(gen, yf); + Py_DECREF(yf); + __Pyx_Generator_Undelegate(gen); + if (err < 0) + return __Pyx_Generator_SendEx(gen, NULL); + goto throw_here; + } +#endif + gen->is_running = 1; + if (__Pyx_Generator_CheckExact(yf)) { + ret = __Pyx_Generator_Throw(yf, args); + } else { + PyObject *meth = PyObject_GetAttrString(yf, "throw"); + if (unlikely(!meth)) { + Py_DECREF(yf); + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { + gen->is_running = 0; + return NULL; + } + PyErr_Clear(); + __Pyx_Generator_Undelegate(gen); + gen->is_running = 0; + goto throw_here; + } + ret = PyObject_CallObject(meth, args); + Py_DECREF(meth); + } + gen->is_running = 0; + Py_DECREF(yf); + if (!ret) { + ret = __Pyx_Generator_FinishDelegation(gen); + } + return ret; + } +throw_here: + __Pyx_Raise(typ, val, tb, NULL); + return __Pyx_Generator_SendEx(gen, NULL); +} +static int __Pyx_Generator_traverse(PyObject *self, visitproc visit, void *arg) { + __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; + Py_VISIT(gen->closure); + Py_VISIT(gen->classobj); + Py_VISIT(gen->yieldfrom); + Py_VISIT(gen->exc_type); + Py_VISIT(gen->exc_value); + Py_VISIT(gen->exc_traceback); + return 0; +} +static int __Pyx_Generator_clear(PyObject *self) { + __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; + Py_CLEAR(gen->closure); + Py_CLEAR(gen->classobj); + Py_CLEAR(gen->yieldfrom); + Py_CLEAR(gen->exc_type); + Py_CLEAR(gen->exc_value); + Py_CLEAR(gen->exc_traceback); + return 0; +} +static void __Pyx_Generator_dealloc(PyObject *self) { + __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; + PyObject_GC_UnTrack(gen); + if (gen->gi_weakreflist != NULL) + PyObject_ClearWeakRefs(self); + PyObject_GC_Track(self); + if (gen->resume_label > 0) { + Py_TYPE(gen)->tp_del(self); + if (self->ob_refcnt > 0) + return; /* resurrected. :( */ + } + PyObject_GC_UnTrack(self); + __Pyx_Generator_clear(self); + PyObject_GC_Del(gen); +} +static void __Pyx_Generator_del(PyObject *self) { + PyObject *res; + PyObject *error_type, *error_value, *error_traceback; + __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self; + if (gen->resume_label <= 0) + return ; + assert(self->ob_refcnt == 0); + self->ob_refcnt = 1; + __Pyx_ErrFetch(&error_type, &error_value, &error_traceback); + res = __Pyx_Generator_Close(self); + if (res == NULL) + PyErr_WriteUnraisable(self); + else + Py_DECREF(res); + __Pyx_ErrRestore(error_type, error_value, error_traceback); + /* Undo the temporary resurrection; can't use DECREF here, it would + * cause a recursive call. + */ + assert(self->ob_refcnt > 0); + if (--self->ob_refcnt == 0) + return; /* this is the normal path out */ + /* close() resurrected it! Make it look like the original Py_DECREF + * never happened. + */ + { + Py_ssize_t refcnt = self->ob_refcnt; + _Py_NewReference(self); + self->ob_refcnt = refcnt; + } +#if CYTHON_COMPILING_FOR_CPYTHON + assert(PyType_IS_GC(self->ob_type) && + _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED); + /* If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so + * we need to undo that. */ + _Py_DEC_REFTOTAL; +#endif + /* If Py_TRACE_REFS, _Py_NewReference re-added self to the object + * chain, so no more to do there. + * If COUNT_ALLOCS, the original decref bumped tp_frees, and + * _Py_NewReference bumped tp_allocs: both of those need to be + * undone. + */ +#ifdef COUNT_ALLOCS + --Py_TYPE(self)->tp_frees; + --Py_TYPE(self)->tp_allocs; +#endif +} +static PyMemberDef __pyx_Generator_memberlist[] = { + {(char *) "gi_running", +#if PY_VERSION_HEX >= 0x02060000 + T_BOOL, +#else + T_INT, +#endif + offsetof(__pyx_GeneratorObject, is_running), + READONLY, + NULL}, + {0, 0, 0, 0, 0} +}; +static PyMethodDef __pyx_Generator_methods[] = { + {__Pyx_NAMESTR("send"), (PyCFunction) __Pyx_Generator_Send, METH_O, 0}, + {__Pyx_NAMESTR("throw"), (PyCFunction) __Pyx_Generator_Throw, METH_VARARGS, 0}, + {__Pyx_NAMESTR("close"), (PyCFunction) __Pyx_Generator_Close, METH_NOARGS, 0}, + {0, 0, 0, 0} +}; +static PyTypeObject __pyx_GeneratorType_type = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("generator"), /*tp_name*/ + sizeof(__pyx_GeneratorObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + (destructor) __Pyx_Generator_dealloc,/*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ +#if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ +#else + 0, /*reserved*/ +#endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags*/ + 0, /*tp_doc*/ + (traverseproc) __Pyx_Generator_traverse, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + offsetof(__pyx_GeneratorObject, gi_weakreflist), /* tp_weaklistoffse */ + 0, /*tp_iter*/ + (iternextfunc) __Pyx_Generator_Next, /*tp_iternext*/ + __pyx_Generator_methods, /*tp_methods*/ + __pyx_Generator_memberlist, /*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*/ + 0, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + __Pyx_Generator_del, /*tp_del*/ +#if PY_VERSION_HEX >= 0x02060000 + 0, /*tp_version_tag*/ +#endif +}; +static __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body, + PyObject *closure) { + __pyx_GeneratorObject *gen = + PyObject_GC_New(__pyx_GeneratorObject, &__pyx_GeneratorType_type); + if (gen == NULL) + return NULL; + gen->body = body; + gen->closure = closure; + Py_XINCREF(closure); + gen->is_running = 0; + gen->resume_label = 0; + gen->classobj = NULL; + gen->yieldfrom = NULL; + gen->exc_type = NULL; + gen->exc_value = NULL; + gen->exc_traceback = NULL; + gen->gi_weakreflist = NULL; + PyObject_GC_Track(gen); + return gen; +} +static int __pyx_Generator_init(void) { + __pyx_GeneratorType_type.tp_getattro = PyObject_GenericGetAttr; + __pyx_GeneratorType_type.tp_iter = PyObject_SelfIter; + if (PyType_Ready(&__pyx_GeneratorType_type)) { + return -1; + } + __pyx_GeneratorType = &__pyx_GeneratorType_type; + return 0; +} + +static int __Pyx_check_binary_version(void) { + char ctversion[4], rtversion[4]; + PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); + PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); + if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { + char message[200]; + PyOS_snprintf(message, sizeof(message), + "compiletime version %s of module '%.100s' " + "does not match runtime version %s", + ctversion, __Pyx_MODULE_NAME, rtversion); + #if PY_VERSION_HEX < 0x02050000 + return PyErr_Warn(NULL, message); + #else + return PyErr_WarnEx(NULL, message, 1); + #endif + } + return 0; +} + +static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig) { + PyObject *d = 0; + PyObject *cobj = 0; + union { + void (*fp)(void); + void *p; + } tmp; + d = PyObject_GetAttrString(__pyx_m, (char *)"__pyx_capi__"); + if (!d) { + PyErr_Clear(); + d = PyDict_New(); + if (!d) + goto bad; + Py_INCREF(d); + if (PyModule_AddObject(__pyx_m, (char *)"__pyx_capi__", d) < 0) + goto bad; + } + tmp.fp = f; +#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) + cobj = PyCapsule_New(tmp.p, sig, 0); +#else + cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0); +#endif + if (!cobj) + goto bad; + if (PyDict_SetItemString(d, name, cobj) < 0) + goto bad; + Py_DECREF(cobj); + Py_DECREF(d); + return 0; +bad: + Py_XDECREF(cobj); + Py_XDECREF(d); + return -1; +} + +static int __Pyx_SetVtable(PyObject *dict, void *vtable) { +#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) + PyObject *ob = PyCapsule_New(vtable, 0, 0); +#else + PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); +#endif + if (!ob) + goto bad; + if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0) + goto bad; + Py_DECREF(ob); + return 0; +bad: + Py_XDECREF(ob); + return -1; +} + +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { + int start = 0, mid = 0, end = count - 1; + if (end >= 0 && code_line > entries[end].code_line) { + return count; + } + while (start < end) { + mid = (start + end) / 2; + if (code_line < entries[mid].code_line) { + end = mid; + } else if (code_line > entries[mid].code_line) { + start = mid + 1; + } else { + return mid; + } + } + if (code_line <= entries[mid].code_line) { + return mid; + } else { + return mid + 1; + } +} +static PyCodeObject *__pyx_find_code_object(int code_line) { + PyCodeObject* code_object; + int pos; + if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { + return NULL; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { + return NULL; + } + code_object = __pyx_code_cache.entries[pos].code_object; + Py_INCREF(code_object); + return code_object; +} +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { + int pos, i; + __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; + if (unlikely(!code_line)) { + return; + } + if (unlikely(!entries)) { + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); + if (likely(entries)) { + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = 64; + __pyx_code_cache.count = 1; + entries[0].code_line = code_line; + entries[0].code_object = code_object; + Py_INCREF(code_object); + } + return; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { + PyCodeObject* tmp = entries[pos].code_object; + entries[pos].code_object = code_object; + Py_DECREF(tmp); + return; + } + if (__pyx_code_cache.count == __pyx_code_cache.max_count) { + int new_max = __pyx_code_cache.max_count + 64; + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( + __pyx_code_cache.entries, new_max*sizeof(__Pyx_CodeObjectCacheEntry)); + if (unlikely(!entries)) { + return; + } + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = new_max; + } + for (i=__pyx_code_cache.count; i>pos; i--) { + entries[i] = entries[i-1]; + } + entries[pos].code_line = code_line; + entries[pos].code_object = code_object; + __pyx_code_cache.count++; + Py_INCREF(code_object); +} + +#include "compile.h" +#include "frameobject.h" +#include "traceback.h" +static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( + const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyObject *py_srcfile = 0; + PyObject *py_funcname = 0; + #if PY_MAJOR_VERSION < 3 + py_srcfile = PyString_FromString(filename); + #else + py_srcfile = PyUnicode_FromString(filename); + #endif + if (!py_srcfile) goto bad; + if (c_line) { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + #else + py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + #endif + } + else { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromString(funcname); + #else + py_funcname = PyUnicode_FromString(funcname); + #endif + } + if (!py_funcname) goto bad; + py_code = __Pyx_PyCode_New( + 0, /*int argcount,*/ + 0, /*int kwonlyargcount,*/ + 0, /*int nlocals,*/ + 0, /*int stacksize,*/ + 0, /*int flags,*/ + __pyx_empty_bytes, /*PyObject *code,*/ + __pyx_empty_tuple, /*PyObject *consts,*/ + __pyx_empty_tuple, /*PyObject *names,*/ + __pyx_empty_tuple, /*PyObject *varnames,*/ + __pyx_empty_tuple, /*PyObject *freevars,*/ + __pyx_empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + py_line, /*int firstlineno,*/ + __pyx_empty_bytes /*PyObject *lnotab*/ + ); + Py_DECREF(py_srcfile); + Py_DECREF(py_funcname); + return py_code; +bad: + Py_XDECREF(py_srcfile); + Py_XDECREF(py_funcname); + return NULL; +} +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyObject *py_globals = 0; + PyFrameObject *py_frame = 0; + py_code = __pyx_find_code_object(c_line ? c_line : py_line); + if (!py_code) { + py_code = __Pyx_CreateCodeObjectForTraceback( + funcname, c_line, py_line, filename); + if (!py_code) goto bad; + __pyx_insert_code_object(c_line ? c_line : py_line, py_code); + } + py_globals = PyModule_GetDict(__pyx_m); + if (!py_globals) goto bad; + py_frame = PyFrame_New( + PyThreadState_GET(), /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + py_globals, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + py_frame->f_lineno = py_line; + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} + +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + while (t->p) { + #if PY_MAJOR_VERSION < 3 + if (t->is_unicode) { + *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); + } else if (t->intern) { + *t->p = PyString_InternFromString(t->s); + } else { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + } + #else /* Python 3+ has unicode identifiers */ + if (t->is_unicode | t->is_str) { + if (t->intern) { + *t->p = PyUnicode_InternFromString(t->s); + } else if (t->encoding) { + *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); + } else { + *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); + } + } else { + *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); + } + #endif + if (!*t->p) + return -1; + ++t; + } + return 0; +} + + +/* Type Conversion Functions */ + +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { + int is_true = x == Py_True; + if (is_true | (x == Py_False) | (x == Py_None)) return is_true; + else return PyObject_IsTrue(x); +} + +static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { + PyNumberMethods *m; + const char *name = NULL; + PyObject *res = NULL; +#if PY_VERSION_HEX < 0x03000000 + if (PyInt_Check(x) || PyLong_Check(x)) +#else + if (PyLong_Check(x)) +#endif + return Py_INCREF(x), x; + m = Py_TYPE(x)->tp_as_number; +#if PY_VERSION_HEX < 0x03000000 + if (m && m->nb_int) { + name = "int"; + res = PyNumber_Int(x); + } + else if (m && m->nb_long) { + name = "long"; + res = PyNumber_Long(x); + } +#else + if (m && m->nb_int) { + name = "int"; + res = PyNumber_Long(x); + } +#endif + if (res) { +#if PY_VERSION_HEX < 0x03000000 + if (!PyInt_Check(res) && !PyLong_Check(res)) { +#else + if (!PyLong_Check(res)) { +#endif + PyErr_Format(PyExc_TypeError, + "__%s__ returned non-%s (type %.200s)", + name, name, Py_TYPE(res)->tp_name); + Py_DECREF(res); + return NULL; + } + } + else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, + "an integer is required"); + } + return res; +} + +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { + Py_ssize_t ival; + PyObject* x = PyNumber_Index(b); + if (!x) return -1; + ival = PyInt_AsSsize_t(x); + Py_DECREF(x); + return ival; +} + +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { +#if PY_VERSION_HEX < 0x02050000 + if (ival <= LONG_MAX) + return PyInt_FromLong((long)ival); + else { + unsigned char *bytes = (unsigned char *) &ival; + int one = 1; int little = (int)*(unsigned char*)&one; + return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); + } +#else + return PyInt_FromSize_t(ival); +#endif +} + +static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { + unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); + if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { + return (size_t)-1; + } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to size_t"); + return (size_t)-1; + } + return (size_t)val; +} + + +#endif /* Py_PYTHON_H */ diff --git a/python/src/sa/_sa.pxd b/python/src/sa/_sa.pxd new file mode 100644 index 00000000..d390bfc5 --- /dev/null +++ b/python/src/sa/_sa.pxd @@ -0,0 +1,17 @@ +cdef class Phrase: + cdef int *syms + cdef int n, *varpos, n_vars + cdef public int chunkpos(self, int k) + cdef public int chunklen(self, int k) + +cdef class Rule: + cdef public int lhs + cdef readonly Phrase f, e + cdef float *cscores + cdef int n_scores + cdef public word_alignments + +cdef char* sym_tostring(int sym) +cdef char* sym_tocat(int sym) +cdef int sym_isvar(int sym) +cdef int sym_getindex(int sym) diff --git a/python/src/sa/_sa.pyx b/python/src/sa/_sa.pyx new file mode 100644 index 00000000..710f8cb4 --- /dev/null +++ b/python/src/sa/_sa.pyx @@ -0,0 +1,29 @@ +import logging +import resource +import gzip + +cdef float monitor_cpu(): + return (resource.getrusage(resource.RUSAGE_SELF).ru_utime+ + resource.getrusage(resource.RUSAGE_SELF).ru_stime) + +def gzip_or_text(char* filename): + if filename.endswith('.gz'): + return gzip.GzipFile(filename) + else: + return open(filename) + +logger = logging.getLogger('cdec.sa') + +include "float_list.pxi" +include "int_list.pxi" +include "str_map.pxi" +include "data_array.pxi" +include "alignment.pxi" +include "bilex.pxi" +include "veb.pxi" +include "lcp.pxi" +include "sym.pxi" +include "rule.pxi" +include "precomputation.pxi" +include "suffix_array.pxi" +include "rulefactory.pxi" diff --git a/python/src/sa/rule.pxi b/python/src/sa/rule.pxi index 9c34f66d..bf1a83c6 100644 --- a/python/src/sa/rule.pxi +++ b/python/src/sa/rule.pxi @@ -2,8 +2,6 @@ from libc.stdlib cimport malloc, calloc, realloc, free, strtof, strtol from libc.string cimport strsep, strcpy, strlen cdef class Phrase: - cdef int *syms - cdef int n, *varpos, n_vars def __cinit__(self, words): cdef int i, j, n, n_vars @@ -12,14 +10,14 @@ cdef class Phrase: self.syms = malloc(n*sizeof(int)) for i from 0 <= i < n: self.syms[i] = words[i] - if ALPHABET.isvar(self.syms[i]): + if sym_isvar(self.syms[i]): n_vars += 1 self.n = n self.n_vars = n_vars self.varpos = malloc(n_vars*sizeof(int)) j = 0 for i from 0 <= i < n: - if ALPHABET.isvar(self.syms[i]): + if sym_isvar(self.syms[i]): self.varpos[j] = i j = j + 1 @@ -32,7 +30,7 @@ cdef class Phrase: cdef int i, s for i from 0 <= i < self.n: s = self.syms[i] - strs.append(ALPHABET.tostring(s)) + strs.append(sym_tostring(s)) return " ".join(strs) def handle(self): @@ -44,8 +42,8 @@ cdef class Phrase: j = 0 for j from 0 <= j < self.n: s = self.syms[j] - if ALPHABET.isvar(s): - s = ALPHABET.setindex(s,i) + if sym_isvar(s): + s = sym_setindex(s,i) i = i + 1 norm.append(s) return tuple(norm) @@ -58,10 +56,10 @@ cdef class Phrase: j = 0 for j from 0 <= j < self.n: s = self.syms[j] - if ALPHABET.isvar(s): - s = ALPHABET.setindex(s,i) + if sym_isvar(s): + s = sym_setindex(s,i) i = i + 1 - norm.append(ALPHABET.tostring(s)) + norm.append(sym_tostring(s)) return " ".join(norm) def arity(self): @@ -142,33 +140,30 @@ cdef class Phrase: def __iter__(self): cdef int i - l = [] for i from 0 <= i < self.n: - l.append(self.syms[i]) - return iter(l) + yield self.syms[i] def subst(self, start, children): cdef int i for i from 0 <= i < self.n: - if ALPHABET.isvar(self.syms[i]): - start = start + children[ALPHABET.getindex(self.syms[i])-1] + if sym_isvar(self.syms[i]): + start = start + children[sym_getindex(self.syms[i])-1] else: start = start + (self.syms[i],) return start + + property words: + def __get__(self): + return [sym_tostring(w) for w in self if not sym_isvar(w)] cdef class Rule: - cdef public int lhs - cdef readonly Phrase f, e - cdef float *cscores - cdef int n_scores - cdef public word_alignments def __cinit__(self, int lhs, Phrase f, Phrase e, scores=None, word_alignments=None): cdef int i, n cdef char *rest - if not ALPHABET.isvar(lhs): + if not sym_isvar(lhs): raise Exception('Invalid LHS symbol: %d' % lhs) self.lhs = lhs @@ -214,7 +209,7 @@ cdef class Rule: scorestrs = [] for i from 0 <= i < self.n_scores: scorestrs.append(str(self.cscores[i])) - fields = [ALPHABET.tostring(self.lhs), str(self.f), str(self.e), " ".join(scorestrs)] + fields = [sym_tostring(self.lhs), str(self.f), str(self.e), " ".join(scorestrs)] if self.word_alignments is not None: alignstr = [] for i from 0 <= i < len(self.word_alignments): diff --git a/python/src/sa/rulefactory.pxi b/python/src/sa/rulefactory.pxi index 24bb680f..1c8d25a4 100644 --- a/python/src/sa/rulefactory.pxi +++ b/python/src/sa/rulefactory.pxi @@ -975,7 +975,6 @@ cdef class HieroCachingRuleFactory: continue phrase = prefix + (word_id,) - str_phrase = map(sym_tostring, phrase) hiero_phrase = Phrase(phrase) arity = hiero_phrase.arity() @@ -1019,7 +1018,7 @@ cdef class HieroCachingRuleFactory: else: # Suffix array search phrase_location = node.phrase_location - sa_range = self.fsa.lookup(str_phrase[-1], len(str_phrase)-1, phrase_location.sa_low, phrase_location.sa_high) + sa_range = self.fsa.lookup(sym_tostring(phrase[-1]), len(phrase)-1, phrase_location.sa_low, phrase_location.sa_high) if sa_range is not None: phrase_location = PhraseLocation(sa_low=sa_range[0], sa_high=sa_range[1]) else: diff --git a/python/src/sa/sym.pxi b/python/src/sa/sym.pxi index 3fd6c5a7..4b41886f 100644 --- a/python/src/sa/sym.pxi +++ b/python/src/sa/sym.pxi @@ -53,14 +53,12 @@ cdef class Alphabet: if self.isvar(sym): if sym in self.id2sym: return self.id2sym[sym] - ind = self.getindex(sym) if ind > 0: self.id2sym[sym] = "[%s,%d]" % (self.tocat(sym), ind) else: self.id2sym[sym] = "[%s]" % self.tocat(sym) return self.id2sym[sym] - else: return self.terminals.word(sym) @@ -88,14 +86,20 @@ cdef class Alphabet: cdef Alphabet ALPHABET = Alphabet() -def sym_tostring(int sym): +cdef char* sym_tostring(int sym): return ALPHABET.tostring(sym) -def sym_fromstring(bytes string, bint terminal): - return ALPHABET.fromstring(string, terminal) +cdef char* sym_tocat(int sym): + return ALPHABET.tocat(sym) -def sym_isvar(int sym): +cdef int sym_isvar(int sym): return ALPHABET.isvar(sym) +cdef int sym_getindex(int sym): + return ALPHABET.getindex(sym) + cdef int sym_setindex(int sym, int id): return ALPHABET.setindex(sym, id) + +def sym_fromstring(bytes string, bint terminal): + return ALPHABET.fromstring(string, terminal) diff --git a/python/src/utils.pxd b/python/src/utils.pxd index f4da686b..a1a4799b 100644 --- a/python/src/utils.pxd +++ b/python/src/utils.pxd @@ -17,7 +17,9 @@ cdef extern from "utils/logval.h": cdef cppclass LogVal[T]: double as_float() - double log(LogVal[double]&) + ctypedef LogVal[double] prob_t + + double log(prob_t&) cdef extern from "utils/wordid.h": ctypedef int WordID @@ -33,7 +35,6 @@ cdef extern from "utils/sparse_vector.h": const_iterator(FastSparseVector[T]&, bint is_end) pair[unsigned, T]* ptr "operator->" () const_iterator& operator++() - bint operator==(const_iterator&) bint operator!=(const_iterator&) FastSparseVector() FastSparseVector(FastSparseVector[T]&) diff --git a/python/src/vectors.pxi b/python/src/vectors.pxi index cd1c2598..989a6a7c 100644 --- a/python/src/vectors.pxi +++ b/python/src/vectors.pxi @@ -1,7 +1,16 @@ from cython.operator cimport preincrement as pinc cdef class DenseVector: - cdef vector[weight_t]* vector # Not owned by DenseVector + cdef vector[weight_t]* vector + cdef bint owned # if True, do not manage memory + + def __init__(self): + self.vector = new vector[weight_t]() + self.owned = False + + def __dealloc__(self): + if not self.owned: + del self.vector def __len__(self): return self.vector.size() @@ -28,7 +37,7 @@ cdef class DenseVector: return other.dot(self) def tosparse(self): - cdef SparseVector sparse = SparseVector() + cdef SparseVector sparse = SparseVector.__new__(SparseVector) sparse.vector = new FastSparseVector[weight_t]() InitSparseVector(self.vector[0], sparse.vector) return sparse @@ -36,6 +45,9 @@ cdef class DenseVector: cdef class SparseVector: cdef FastSparseVector[weight_t]* vector + def __init__(self): + self.vector = new FastSparseVector[weight_t]() + def __dealloc__(self): del self.vector @@ -83,7 +95,7 @@ cdef class SparseVector: return self.vector.nonzero(FDConvert(fname)) def __neg__(self): - cdef SparseVector result = SparseVector() + cdef SparseVector result = SparseVector.__new__(SparseVector) result.vector = new FastSparseVector[weight_t](self.vector[0]) result.vector[0] *= -1.0 return result @@ -105,12 +117,12 @@ cdef class SparseVector: return self def __add__(SparseVector x, SparseVector y): - cdef SparseVector result = SparseVector() + cdef SparseVector result = SparseVector.__new__(SparseVector) result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) return result def __sub__(SparseVector x, SparseVector y): - cdef SparseVector result = SparseVector() + cdef SparseVector result = SparseVector.__new__(SparseVector) result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) return result @@ -119,7 +131,7 @@ cdef class SparseVector: cdef float scalar if isinstance(x, SparseVector): vector, scalar = x, y else: vector, scalar = y, x - cdef SparseVector result = SparseVector() + cdef SparseVector result = SparseVector.__new__(SparseVector) result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) return result @@ -128,6 +140,6 @@ cdef class SparseVector: cdef float scalar if isinstance(x, SparseVector): vector, scalar = x, y else: vector, scalar = y, x - cdef SparseVector result = SparseVector() + cdef SparseVector result = SparseVector.__new__(SparseVector) result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) return result -- cgit v1.2.3 From ee5e376e263d9aeabdeee6968b4457f53d3fc772 Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Fri, 27 Jul 2012 23:33:45 -0400 Subject: [python] Move python files to avoid pythonpath conflicts --- python/cdec/__init__.py | 1 - python/cdec/configobj.py | 2468 --------------------------------------- python/cdec/sa/__init__.py | 4 - python/cdec/sa/compile.py | 94 -- python/cdec/sa/extract.py | 31 - python/cdec/sa/extractor.py | 78 -- python/cdec/sa/features.py | 57 - python/cdec/score.py | 1 - python/pkg/cdec/__init__.py | 1 + python/pkg/cdec/configobj.py | 2468 +++++++++++++++++++++++++++++++++++++++ python/pkg/cdec/sa/__init__.py | 4 + python/pkg/cdec/sa/compile.py | 94 ++ python/pkg/cdec/sa/extract.py | 31 + python/pkg/cdec/sa/extractor.py | 78 ++ python/pkg/cdec/sa/features.py | 57 + python/pkg/cdec/score.py | 1 + python/setup.py | 3 +- python/src/sa/_sa.c | 39 +- python/src/sa/sym.pxi | 2 +- 19 files changed, 2753 insertions(+), 2759 deletions(-) delete mode 100644 python/cdec/__init__.py delete mode 100644 python/cdec/configobj.py delete mode 100644 python/cdec/sa/__init__.py delete mode 100644 python/cdec/sa/compile.py delete mode 100644 python/cdec/sa/extract.py delete mode 100644 python/cdec/sa/extractor.py delete mode 100644 python/cdec/sa/features.py delete mode 100644 python/cdec/score.py create mode 100644 python/pkg/cdec/__init__.py create mode 100644 python/pkg/cdec/configobj.py create mode 100644 python/pkg/cdec/sa/__init__.py create mode 100644 python/pkg/cdec/sa/compile.py create mode 100644 python/pkg/cdec/sa/extract.py create mode 100644 python/pkg/cdec/sa/extractor.py create mode 100644 python/pkg/cdec/sa/features.py create mode 100644 python/pkg/cdec/score.py (limited to 'python/src') diff --git a/python/cdec/__init__.py b/python/cdec/__init__.py deleted file mode 100644 index 19058493..00000000 --- a/python/cdec/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from _cdec import Decoder, Lattice, TRule, NT, NTRef, ParseFailed, InvalidConfig diff --git a/python/cdec/configobj.py b/python/cdec/configobj.py deleted file mode 100644 index c1f6e6df..00000000 --- a/python/cdec/configobj.py +++ /dev/null @@ -1,2468 +0,0 @@ -# configobj.py -# A config file reader/writer that supports nested sections in config files. -# Copyright (C) 2005-2010 Michael Foord, Nicola Larosa -# E-mail: fuzzyman AT voidspace DOT org DOT uk -# nico AT tekNico DOT net - -# ConfigObj 4 -# http://www.voidspace.org.uk/python/configobj.html - -# Released subject to the BSD License -# Please see http://www.voidspace.org.uk/python/license.shtml - -# Scripts maintained at http://www.voidspace.org.uk/python/index.shtml -# For information about bugfixes, updates and support, please join the -# ConfigObj mailing list: -# http://lists.sourceforge.net/lists/listinfo/configobj-develop -# Comments, suggestions and bug reports welcome. - -from __future__ import generators - -import os -import re -import sys - -from codecs import BOM_UTF8, BOM_UTF16, BOM_UTF16_BE, BOM_UTF16_LE - - -# imported lazily to avoid startup performance hit if it isn't used -compiler = None - -# A dictionary mapping BOM to -# the encoding to decode with, and what to set the -# encoding attribute to. -BOMS = { - BOM_UTF8: ('utf_8', None), - BOM_UTF16_BE: ('utf16_be', 'utf_16'), - BOM_UTF16_LE: ('utf16_le', 'utf_16'), - BOM_UTF16: ('utf_16', 'utf_16'), - } -# All legal variants of the BOM codecs. -# TODO: the list of aliases is not meant to be exhaustive, is there a -# better way ? -BOM_LIST = { - 'utf_16': 'utf_16', - 'u16': 'utf_16', - 'utf16': 'utf_16', - 'utf-16': 'utf_16', - 'utf16_be': 'utf16_be', - 'utf_16_be': 'utf16_be', - 'utf-16be': 'utf16_be', - 'utf16_le': 'utf16_le', - 'utf_16_le': 'utf16_le', - 'utf-16le': 'utf16_le', - 'utf_8': 'utf_8', - 'u8': 'utf_8', - 'utf': 'utf_8', - 'utf8': 'utf_8', - 'utf-8': 'utf_8', - } - -# Map of encodings to the BOM to write. -BOM_SET = { - 'utf_8': BOM_UTF8, - 'utf_16': BOM_UTF16, - 'utf16_be': BOM_UTF16_BE, - 'utf16_le': BOM_UTF16_LE, - None: BOM_UTF8 - } - - -def match_utf8(encoding): - return BOM_LIST.get(encoding.lower()) == 'utf_8' - - -# Quote strings used for writing values -squot = "'%s'" -dquot = '"%s"' -noquot = "%s" -wspace_plus = ' \r\n\v\t\'"' -tsquot = '"""%s"""' -tdquot = "'''%s'''" - -# Sentinel for use in getattr calls to replace hasattr -MISSING = object() - -__version__ = '4.7.2' - -try: - any -except NameError: - def any(iterable): - for entry in iterable: - if entry: - return True - return False - - -__all__ = ( - '__version__', - 'DEFAULT_INDENT_TYPE', - 'DEFAULT_INTERPOLATION', - 'ConfigObjError', - 'NestingError', - 'ParseError', - 'DuplicateError', - 'ConfigspecError', - 'ConfigObj', - 'SimpleVal', - 'InterpolationError', - 'InterpolationLoopError', - 'MissingInterpolationOption', - 'RepeatSectionError', - 'ReloadError', - 'UnreprError', - 'UnknownType', - 'flatten_errors', - 'get_extra_values' -) - -DEFAULT_INTERPOLATION = 'configparser' -DEFAULT_INDENT_TYPE = ' ' -MAX_INTERPOL_DEPTH = 10 - -OPTION_DEFAULTS = { - 'interpolation': True, - 'raise_errors': False, - 'list_values': True, - 'create_empty': False, - 'file_error': False, - 'configspec': None, - 'stringify': True, - # option may be set to one of ('', ' ', '\t') - 'indent_type': None, - 'encoding': None, - 'default_encoding': None, - 'unrepr': False, - 'write_empty_values': False, -} - - - -def getObj(s): - global compiler - if compiler is None: - import compiler - s = "a=" + s - p = compiler.parse(s) - return p.getChildren()[1].getChildren()[0].getChildren()[1] - - -class UnknownType(Exception): - pass - - -class Builder(object): - - def build(self, o): - m = getattr(self, 'build_' + o.__class__.__name__, None) - if m is None: - raise UnknownType(o.__class__.__name__) - return m(o) - - def build_List(self, o): - return map(self.build, o.getChildren()) - - def build_Const(self, o): - return o.value - - def build_Dict(self, o): - d = {} - i = iter(map(self.build, o.getChildren())) - for el in i: - d[el] = i.next() - return d - - def build_Tuple(self, o): - return tuple(self.build_List(o)) - - def build_Name(self, o): - if o.name == 'None': - return None - if o.name == 'True': - return True - if o.name == 'False': - return False - - # An undefined Name - raise UnknownType('Undefined Name') - - def build_Add(self, o): - real, imag = map(self.build_Const, o.getChildren()) - try: - real = float(real) - except TypeError: - raise UnknownType('Add') - if not isinstance(imag, complex) or imag.real != 0.0: - raise UnknownType('Add') - return real+imag - - def build_Getattr(self, o): - parent = self.build(o.expr) - return getattr(parent, o.attrname) - - def build_UnarySub(self, o): - return -self.build_Const(o.getChildren()[0]) - - def build_UnaryAdd(self, o): - return self.build_Const(o.getChildren()[0]) - - -_builder = Builder() - - -def unrepr(s): - if not s: - return s - return _builder.build(getObj(s)) - - - -class ConfigObjError(SyntaxError): - """ - This is the base class for all errors that ConfigObj raises. - It is a subclass of SyntaxError. - """ - def __init__(self, message='', line_number=None, line=''): - self.line = line - self.line_number = line_number - SyntaxError.__init__(self, message) - - -class NestingError(ConfigObjError): - """ - This error indicates a level of nesting that doesn't match. - """ - - -class ParseError(ConfigObjError): - """ - This error indicates that a line is badly written. - It is neither a valid ``key = value`` line, - nor a valid section marker line. - """ - - -class ReloadError(IOError): - """ - A 'reload' operation failed. - This exception is a subclass of ``IOError``. - """ - def __init__(self): - IOError.__init__(self, 'reload failed, filename is not set.') - - -class DuplicateError(ConfigObjError): - """ - The keyword or section specified already exists. - """ - - -class ConfigspecError(ConfigObjError): - """ - An error occured whilst parsing a configspec. - """ - - -class InterpolationError(ConfigObjError): - """Base class for the two interpolation errors.""" - - -class InterpolationLoopError(InterpolationError): - """Maximum interpolation depth exceeded in string interpolation.""" - - def __init__(self, option): - InterpolationError.__init__( - self, - 'interpolation loop detected in value "%s".' % option) - - -class RepeatSectionError(ConfigObjError): - """ - This error indicates additional sections in a section with a - ``__many__`` (repeated) section. - """ - - -class MissingInterpolationOption(InterpolationError): - """A value specified for interpolation was missing.""" - def __init__(self, option): - msg = 'missing option "%s" in interpolation.' % option - InterpolationError.__init__(self, msg) - - -class UnreprError(ConfigObjError): - """An error parsing in unrepr mode.""" - - - -class InterpolationEngine(object): - """ - A helper class to help perform string interpolation. - - This class is an abstract base class; its descendants perform - the actual work. - """ - - # compiled regexp to use in self.interpolate() - _KEYCRE = re.compile(r"%\(([^)]*)\)s") - _cookie = '%' - - def __init__(self, section): - # the Section instance that "owns" this engine - self.section = section - - - def interpolate(self, key, value): - # short-cut - if not self._cookie in value: - return value - - def recursive_interpolate(key, value, section, backtrail): - """The function that does the actual work. - - ``value``: the string we're trying to interpolate. - ``section``: the section in which that string was found - ``backtrail``: a dict to keep track of where we've been, - to detect and prevent infinite recursion loops - - This is similar to a depth-first-search algorithm. - """ - # Have we been here already? - if (key, section.name) in backtrail: - # Yes - infinite loop detected - raise InterpolationLoopError(key) - # Place a marker on our backtrail so we won't come back here again - backtrail[(key, section.name)] = 1 - - # Now start the actual work - match = self._KEYCRE.search(value) - while match: - # The actual parsing of the match is implementation-dependent, - # so delegate to our helper function - k, v, s = self._parse_match(match) - if k is None: - # That's the signal that no further interpolation is needed - replacement = v - else: - # Further interpolation may be needed to obtain final value - replacement = recursive_interpolate(k, v, s, backtrail) - # Replace the matched string with its final value - start, end = match.span() - value = ''.join((value[:start], replacement, value[end:])) - new_search_start = start + len(replacement) - # Pick up the next interpolation key, if any, for next time - # through the while loop - match = self._KEYCRE.search(value, new_search_start) - - # Now safe to come back here again; remove marker from backtrail - del backtrail[(key, section.name)] - - return value - - # Back in interpolate(), all we have to do is kick off the recursive - # function with appropriate starting values - value = recursive_interpolate(key, value, self.section, {}) - return value - - - def _fetch(self, key): - """Helper function to fetch values from owning section. - - Returns a 2-tuple: the value, and the section where it was found. - """ - # switch off interpolation before we try and fetch anything ! - save_interp = self.section.main.interpolation - self.section.main.interpolation = False - - # Start at section that "owns" this InterpolationEngine - current_section = self.section - while True: - # try the current section first - val = current_section.get(key) - if val is not None and not isinstance(val, Section): - break - # try "DEFAULT" next - val = current_section.get('DEFAULT', {}).get(key) - if val is not None and not isinstance(val, Section): - break - # move up to parent and try again - # top-level's parent is itself - if current_section.parent is current_section: - # reached top level, time to give up - break - current_section = current_section.parent - - # restore interpolation to previous value before returning - self.section.main.interpolation = save_interp - if val is None: - raise MissingInterpolationOption(key) - return val, current_section - - - def _parse_match(self, match): - """Implementation-dependent helper function. - - Will be passed a match object corresponding to the interpolation - key we just found (e.g., "%(foo)s" or "$foo"). Should look up that - key in the appropriate config file section (using the ``_fetch()`` - helper function) and return a 3-tuple: (key, value, section) - - ``key`` is the name of the key we're looking for - ``value`` is the value found for that key - ``section`` is a reference to the section where it was found - - ``key`` and ``section`` should be None if no further - interpolation should be performed on the resulting value - (e.g., if we interpolated "$$" and returned "$"). - """ - raise NotImplementedError() - - - -class ConfigParserInterpolation(InterpolationEngine): - """Behaves like ConfigParser.""" - _cookie = '%' - _KEYCRE = re.compile(r"%\(([^)]*)\)s") - - def _parse_match(self, match): - key = match.group(1) - value, section = self._fetch(key) - return key, value, section - - - -class TemplateInterpolation(InterpolationEngine): - """Behaves like string.Template.""" - _cookie = '$' - _delimiter = '$' - _KEYCRE = re.compile(r""" - \$(?: - (?P\$) | # Two $ signs - (?P[_a-z][_a-z0-9]*) | # $name format - {(?P[^}]*)} # ${name} format - ) - """, re.IGNORECASE | re.VERBOSE) - - def _parse_match(self, match): - # Valid name (in or out of braces): fetch value from section - key = match.group('named') or match.group('braced') - if key is not None: - value, section = self._fetch(key) - return key, value, section - # Escaped delimiter (e.g., $$): return single delimiter - if match.group('escaped') is not None: - # Return None for key and section to indicate it's time to stop - return None, self._delimiter, None - # Anything else: ignore completely, just return it unchanged - return None, match.group(), None - - -interpolation_engines = { - 'configparser': ConfigParserInterpolation, - 'template': TemplateInterpolation, -} - - -def __newobj__(cls, *args): - # Hack for pickle - return cls.__new__(cls, *args) - -class Section(dict): - """ - A dictionary-like object that represents a section in a config file. - - It does string interpolation if the 'interpolation' attribute - of the 'main' object is set to True. - - Interpolation is tried first from this object, then from the 'DEFAULT' - section of this object, next from the parent and its 'DEFAULT' section, - and so on until the main object is reached. - - A Section will behave like an ordered dictionary - following the - order of the ``scalars`` and ``sections`` attributes. - You can use this to change the order of members. - - Iteration follows the order: scalars, then sections. - """ - - - def __setstate__(self, state): - dict.update(self, state[0]) - self.__dict__.update(state[1]) - - def __reduce__(self): - state = (dict(self), self.__dict__) - return (__newobj__, (self.__class__,), state) - - - def __init__(self, parent, depth, main, indict=None, name=None): - """ - * parent is the section above - * depth is the depth level of this section - * main is the main ConfigObj - * indict is a dictionary to initialise the section with - """ - if indict is None: - indict = {} - dict.__init__(self) - # used for nesting level *and* interpolation - self.parent = parent - # used for the interpolation attribute - self.main = main - # level of nesting depth of this Section - self.depth = depth - # purely for information - self.name = name - # - self._initialise() - # we do this explicitly so that __setitem__ is used properly - # (rather than just passing to ``dict.__init__``) - for entry, value in indict.iteritems(): - self[entry] = value - - - def _initialise(self): - # the sequence of scalar values in this Section - self.scalars = [] - # the sequence of sections in this Section - self.sections = [] - # for comments :-) - self.comments = {} - self.inline_comments = {} - # the configspec - self.configspec = None - # for defaults - self.defaults = [] - self.default_values = {} - self.extra_values = [] - self._created = False - - - def _interpolate(self, key, value): - try: - # do we already have an interpolation engine? - engine = self._interpolation_engine - except AttributeError: - # not yet: first time running _interpolate(), so pick the engine - name = self.main.interpolation - if name == True: # note that "if name:" would be incorrect here - # backwards-compatibility: interpolation=True means use default - name = DEFAULT_INTERPOLATION - name = name.lower() # so that "Template", "template", etc. all work - class_ = interpolation_engines.get(name, None) - if class_ is None: - # invalid value for self.main.interpolation - self.main.interpolation = False - return value - else: - # save reference to engine so we don't have to do this again - engine = self._interpolation_engine = class_(self) - # let the engine do the actual work - return engine.interpolate(key, value) - - - def __getitem__(self, key): - """Fetch the item and do string interpolation.""" - val = dict.__getitem__(self, key) - if self.main.interpolation: - if isinstance(val, basestring): - return self._interpolate(key, val) - if isinstance(val, list): - def _check(entry): - if isinstance(entry, basestring): - return self._interpolate(key, entry) - return entry - new = [_check(entry) for entry in val] - if new != val: - return new - return val - - - def __setitem__(self, key, value, unrepr=False): - """ - Correctly set a value. - - Making dictionary values Section instances. - (We have to special case 'Section' instances - which are also dicts) - - Keys must be strings. - Values need only be strings (or lists of strings) if - ``main.stringify`` is set. - - ``unrepr`` must be set when setting a value to a dictionary, without - creating a new sub-section. - """ - if not isinstance(key, basestring): - raise ValueError('The key "%s" is not a string.' % key) - - # add the comment - if key not in self.comments: - self.comments[key] = [] - self.inline_comments[key] = '' - # remove the entry from defaults - if key in self.defaults: - self.defaults.remove(key) - # - if isinstance(value, Section): - if key not in self: - self.sections.append(key) - dict.__setitem__(self, key, value) - elif isinstance(value, dict) and not unrepr: - # First create the new depth level, - # then create the section - if key not in self: - self.sections.append(key) - new_depth = self.depth + 1 - dict.__setitem__( - self, - key, - Section( - self, - new_depth, - self.main, - indict=value, - name=key)) - else: - if key not in self: - self.scalars.append(key) - if not self.main.stringify: - if isinstance(value, basestring): - pass - elif isinstance(value, (list, tuple)): - for entry in value: - if not isinstance(entry, basestring): - raise TypeError('Value is not a string "%s".' % entry) - else: - raise TypeError('Value is not a string "%s".' % value) - dict.__setitem__(self, key, value) - - - def __delitem__(self, key): - """Remove items from the sequence when deleting.""" - dict. __delitem__(self, key) - if key in self.scalars: - self.scalars.remove(key) - else: - self.sections.remove(key) - del self.comments[key] - del self.inline_comments[key] - - - def get(self, key, default=None): - """A version of ``get`` that doesn't bypass string interpolation.""" - try: - return self[key] - except KeyError: - return default - - - def update(self, indict): - """ - A version of update that uses our ``__setitem__``. - """ - for entry in indict: - self[entry] = indict[entry] - - - def pop(self, key, default=MISSING): - """ - 'D.pop(k[,d]) -> v, remove specified key and return the corresponding value. - If key is not found, d is returned if given, otherwise KeyError is raised' - """ - try: - val = self[key] - except KeyError: - if default is MISSING: - raise - val = default - else: - del self[key] - return val - - - def popitem(self): - """Pops the first (key,val)""" - sequence = (self.scalars + self.sections) - if not sequence: - raise KeyError(": 'popitem(): dictionary is empty'") - key = sequence[0] - val = self[key] - del self[key] - return key, val - - - def clear(self): - """ - A version of clear that also affects scalars/sections - Also clears comments and configspec. - - Leaves other attributes alone : - depth/main/parent are not affected - """ - dict.clear(self) - self.scalars = [] - self.sections = [] - self.comments = {} - self.inline_comments = {} - self.configspec = None - self.defaults = [] - self.extra_values = [] - - - def setdefault(self, key, default=None): - """A version of setdefault that sets sequence if appropriate.""" - try: - return self[key] - except KeyError: - self[key] = default - return self[key] - - - def items(self): - """D.items() -> list of D's (key, value) pairs, as 2-tuples""" - return zip((self.scalars + self.sections), self.values()) - - - def keys(self): - """D.keys() -> list of D's keys""" - return (self.scalars + self.sections) - - - def values(self): - """D.values() -> list of D's values""" - return [self[key] for key in (self.scalars + self.sections)] - - - def iteritems(self): - """D.iteritems() -> an iterator over the (key, value) items of D""" - return iter(self.items()) - - - def iterkeys(self): - """D.iterkeys() -> an iterator over the keys of D""" - return iter((self.scalars + self.sections)) - - __iter__ = iterkeys - - - def itervalues(self): - """D.itervalues() -> an iterator over the values of D""" - return iter(self.values()) - - - def __repr__(self): - """x.__repr__() <==> repr(x)""" - def _getval(key): - try: - return self[key] - except MissingInterpolationOption: - return dict.__getitem__(self, key) - return '{%s}' % ', '.join([('%s: %s' % (repr(key), repr(_getval(key)))) - for key in (self.scalars + self.sections)]) - - __str__ = __repr__ - __str__.__doc__ = "x.__str__() <==> str(x)" - - - # Extra methods - not in a normal dictionary - - def dict(self): - """ - Return a deepcopy of self as a dictionary. - - All members that are ``Section`` instances are recursively turned to - ordinary dictionaries - by calling their ``dict`` method. - - >>> n = a.dict() - >>> n == a - 1 - >>> n is a - 0 - """ - newdict = {} - for entry in self: - this_entry = self[entry] - if isinstance(this_entry, Section): - this_entry = this_entry.dict() - elif isinstance(this_entry, list): - # create a copy rather than a reference - this_entry = list(this_entry) - elif isinstance(this_entry, tuple): - # create a copy rather than a reference - this_entry = tuple(this_entry) - newdict[entry] = this_entry - return newdict - - - def merge(self, indict): - """ - A recursive update - useful for merging config files. - - >>> a = '''[section1] - ... option1 = True - ... [[subsection]] - ... more_options = False - ... # end of file'''.splitlines() - >>> b = '''# File is user.ini - ... [section1] - ... option1 = False - ... # end of file'''.splitlines() - >>> c1 = ConfigObj(b) - >>> c2 = ConfigObj(a) - >>> c2.merge(c1) - >>> c2 - ConfigObj({'section1': {'option1': 'False', 'subsection': {'more_options': 'False'}}}) - """ - for key, val in indict.items(): - if (key in self and isinstance(self[key], dict) and - isinstance(val, dict)): - self[key].merge(val) - else: - self[key] = val - - - def rename(self, oldkey, newkey): - """ - Change a keyname to another, without changing position in sequence. - - Implemented so that transformations can be made on keys, - as well as on values. (used by encode and decode) - - Also renames comments. - """ - if oldkey in self.scalars: - the_list = self.scalars - elif oldkey in self.sections: - the_list = self.sections - else: - raise KeyError('Key "%s" not found.' % oldkey) - pos = the_list.index(oldkey) - # - val = self[oldkey] - dict.__delitem__(self, oldkey) - dict.__setitem__(self, newkey, val) - the_list.remove(oldkey) - the_list.insert(pos, newkey) - comm = self.comments[oldkey] - inline_comment = self.inline_comments[oldkey] - del self.comments[oldkey] - del self.inline_comments[oldkey] - self.comments[newkey] = comm - self.inline_comments[newkey] = inline_comment - - - def walk(self, function, raise_errors=True, - call_on_sections=False, **keywargs): - """ - Walk every member and call a function on the keyword and value. - - Return a dictionary of the return values - - If the function raises an exception, raise the errror - unless ``raise_errors=False``, in which case set the return value to - ``False``. - - Any unrecognised keyword arguments you pass to walk, will be pased on - to the function you pass in. - - Note: if ``call_on_sections`` is ``True`` then - on encountering a - subsection, *first* the function is called for the *whole* subsection, - and then recurses into it's members. This means your function must be - able to handle strings, dictionaries and lists. This allows you - to change the key of subsections as well as for ordinary members. The - return value when called on the whole subsection has to be discarded. - - See the encode and decode methods for examples, including functions. - - .. admonition:: caution - - You can use ``walk`` to transform the names of members of a section - but you mustn't add or delete members. - - >>> config = '''[XXXXsection] - ... XXXXkey = XXXXvalue'''.splitlines() - >>> cfg = ConfigObj(config) - >>> cfg - ConfigObj({'XXXXsection': {'XXXXkey': 'XXXXvalue'}}) - >>> def transform(section, key): - ... val = section[key] - ... newkey = key.replace('XXXX', 'CLIENT1') - ... section.rename(key, newkey) - ... if isinstance(val, (tuple, list, dict)): - ... pass - ... else: - ... val = val.replace('XXXX', 'CLIENT1') - ... section[newkey] = val - >>> cfg.walk(transform, call_on_sections=True) - {'CLIENT1section': {'CLIENT1key': None}} - >>> cfg - ConfigObj({'CLIENT1section': {'CLIENT1key': 'CLIENT1value'}}) - """ - out = {} - # scalars first - for i in range(len(self.scalars)): - entry = self.scalars[i] - try: - val = function(self, entry, **keywargs) - # bound again in case name has changed - entry = self.scalars[i] - out[entry] = val - except Exception: - if raise_errors: - raise - else: - entry = self.scalars[i] - out[entry] = False - # then sections - for i in range(len(self.sections)): - entry = self.sections[i] - if call_on_sections: - try: - function(self, entry, **keywargs) - except Exception: - if raise_errors: - raise - else: - entry = self.sections[i] - out[entry] = False - # bound again in case name has changed - entry = self.sections[i] - # previous result is discarded - out[entry] = self[entry].walk( - function, - raise_errors=raise_errors, - call_on_sections=call_on_sections, - **keywargs) - return out - - - def as_bool(self, key): - """ - Accepts a key as input. The corresponding value must be a string or - the objects (``True`` or 1) or (``False`` or 0). We allow 0 and 1 to - retain compatibility with Python 2.2. - - If the string is one of ``True``, ``On``, ``Yes``, or ``1`` it returns - ``True``. - - If the string is one of ``False``, ``Off``, ``No``, or ``0`` it returns - ``False``. - - ``as_bool`` is not case sensitive. - - Any other input will raise a ``ValueError``. - - >>> a = ConfigObj() - >>> a['a'] = 'fish' - >>> a.as_bool('a') - Traceback (most recent call last): - ValueError: Value "fish" is neither True nor False - >>> a['b'] = 'True' - >>> a.as_bool('b') - 1 - >>> a['b'] = 'off' - >>> a.as_bool('b') - 0 - """ - val = self[key] - if val == True: - return True - elif val == False: - return False - else: - try: - if not isinstance(val, basestring): - # TODO: Why do we raise a KeyError here? - raise KeyError() - else: - return self.main._bools[val.lower()] - except KeyError: - raise ValueError('Value "%s" is neither True nor False' % val) - - - def as_int(self, key): - """ - A convenience method which coerces the specified value to an integer. - - If the value is an invalid literal for ``int``, a ``ValueError`` will - be raised. - - >>> a = ConfigObj() - >>> a['a'] = 'fish' - >>> a.as_int('a') - Traceback (most recent call last): - ValueError: invalid literal for int() with base 10: 'fish' - >>> a['b'] = '1' - >>> a.as_int('b') - 1 - >>> a['b'] = '3.2' - >>> a.as_int('b') - Traceback (most recent call last): - ValueError: invalid literal for int() with base 10: '3.2' - """ - return int(self[key]) - - - def as_float(self, key): - """ - A convenience method which coerces the specified value to a float. - - If the value is an invalid literal for ``float``, a ``ValueError`` will - be raised. - - >>> a = ConfigObj() - >>> a['a'] = 'fish' - >>> a.as_float('a') - Traceback (most recent call last): - ValueError: invalid literal for float(): fish - >>> a['b'] = '1' - >>> a.as_float('b') - 1.0 - >>> a['b'] = '3.2' - >>> a.as_float('b') - 3.2000000000000002 - """ - return float(self[key]) - - - def as_list(self, key): - """ - A convenience method which fetches the specified value, guaranteeing - that it is a list. - - >>> a = ConfigObj() - >>> a['a'] = 1 - >>> a.as_list('a') - [1] - >>> a['a'] = (1,) - >>> a.as_list('a') - [1] - >>> a['a'] = [1] - >>> a.as_list('a') - [1] - """ - result = self[key] - if isinstance(result, (tuple, list)): - return list(result) - return [result] - - - def restore_default(self, key): - """ - Restore (and return) default value for the specified key. - - This method will only work for a ConfigObj that was created - with a configspec and has been validated. - - If there is no default value for this key, ``KeyError`` is raised. - """ - default = self.default_values[key] - dict.__setitem__(self, key, default) - if key not in self.defaults: - self.defaults.append(key) - return default - - - def restore_defaults(self): - """ - Recursively restore default values to all members - that have them. - - This method will only work for a ConfigObj that was created - with a configspec and has been validated. - - It doesn't delete or modify entries without default values. - """ - for key in self.default_values: - self.restore_default(key) - - for section in self.sections: - self[section].restore_defaults() - - -class ConfigObj(Section): - """An object to read, create, and write config files.""" - - _keyword = re.compile(r'''^ # line start - (\s*) # indentation - ( # keyword - (?:".*?")| # double quotes - (?:'.*?')| # single quotes - (?:[^'"=].*?) # no quotes - ) - \s*=\s* # divider - (.*) # value (including list values and comments) - $ # line end - ''', - re.VERBOSE) - - _sectionmarker = re.compile(r'''^ - (\s*) # 1: indentation - ((?:\[\s*)+) # 2: section marker open - ( # 3: section name open - (?:"\s*\S.*?\s*")| # at least one non-space with double quotes - (?:'\s*\S.*?\s*')| # at least one non-space with single quotes - (?:[^'"\s].*?) # at least one non-space unquoted - ) # section name close - ((?:\s*\])+) # 4: section marker close - \s*(\#.*)? # 5: optional comment - $''', - re.VERBOSE) - - # this regexp pulls list values out as a single string - # or single values and comments - # FIXME: this regex adds a '' to the end of comma terminated lists - # workaround in ``_handle_value`` - _valueexp = re.compile(r'''^ - (?: - (?: - ( - (?: - (?: - (?:".*?")| # double quotes - (?:'.*?')| # single quotes - (?:[^'",\#][^,\#]*?) # unquoted - ) - \s*,\s* # comma - )* # match all list items ending in a comma (if any) - ) - ( - (?:".*?")| # double quotes - (?:'.*?')| # single quotes - (?:[^'",\#\s][^,]*?)| # unquoted - (?:(? 1: - msg = "Parsing failed with several errors.\nFirst error %s" % info - error = ConfigObjError(msg) - else: - error = self._errors[0] - # set the errors attribute; it's a list of tuples: - # (error_type, message, line_number) - error.errors = self._errors - # set the config attribute - error.config = self - raise error - # delete private attributes - del self._errors - - if configspec is None: - self.configspec = None - else: - self._handle_configspec(configspec) - - - def _initialise(self, options=None): - if options is None: - options = OPTION_DEFAULTS - - # initialise a few variables - self.filename = None - self._errors = [] - self.raise_errors = options['raise_errors'] - self.interpolation = options['interpolation'] - self.list_values = options['list_values'] - self.create_empty = options['create_empty'] - self.file_error = options['file_error'] - self.stringify = options['stringify'] - self.indent_type = options['indent_type'] - self.encoding = options['encoding'] - self.default_encoding = options['default_encoding'] - self.BOM = False - self.newlines = None - self.write_empty_values = options['write_empty_values'] - self.unrepr = options['unrepr'] - - self.initial_comment = [] - self.final_comment = [] - self.configspec = None - - if self._inspec: - self.list_values = False - - # Clear section attributes as well - Section._initialise(self) - - - def __repr__(self): - def _getval(key): - try: - return self[key] - except MissingInterpolationOption: - return dict.__getitem__(self, key) - return ('ConfigObj({%s})' % - ', '.join([('%s: %s' % (repr(key), repr(_getval(key)))) - for key in (self.scalars + self.sections)])) - - - def _handle_bom(self, infile): - """ - Handle any BOM, and decode if necessary. - - If an encoding is specified, that *must* be used - but the BOM should - still be removed (and the BOM attribute set). - - (If the encoding is wrongly specified, then a BOM for an alternative - encoding won't be discovered or removed.) - - If an encoding is not specified, UTF8 or UTF16 BOM will be detected and - removed. The BOM attribute will be set. UTF16 will be decoded to - unicode. - - NOTE: This method must not be called with an empty ``infile``. - - Specifying the *wrong* encoding is likely to cause a - ``UnicodeDecodeError``. - - ``infile`` must always be returned as a list of lines, but may be - passed in as a single string. - """ - if ((self.encoding is not None) and - (self.encoding.lower() not in BOM_LIST)): - # No need to check for a BOM - # the encoding specified doesn't have one - # just decode - return self._decode(infile, self.encoding) - - if isinstance(infile, (list, tuple)): - line = infile[0] - else: - line = infile - if self.encoding is not None: - # encoding explicitly supplied - # And it could have an associated BOM - # TODO: if encoding is just UTF16 - we ought to check for both - # TODO: big endian and little endian versions. - enc = BOM_LIST[self.encoding.lower()] - if enc == 'utf_16': - # For UTF16 we try big endian and little endian - for BOM, (encoding, final_encoding) in BOMS.items(): - if not final_encoding: - # skip UTF8 - continue - if infile.startswith(BOM): - ### BOM discovered - ##self.BOM = True - # Don't need to remove BOM - return self._decode(infile, encoding) - - # If we get this far, will *probably* raise a DecodeError - # As it doesn't appear to start with a BOM - return self._decode(infile, self.encoding) - - # Must be UTF8 - BOM = BOM_SET[enc] - if not line.startswith(BOM): - return self._decode(infile, self.encoding) - - newline = line[len(BOM):] - - # BOM removed - if isinstance(infile, (list, tuple)): - infile[0] = newline - else: - infile = newline - self.BOM = True - return self._decode(infile, self.encoding) - - # No encoding specified - so we need to check for UTF8/UTF16 - for BOM, (encoding, final_encoding) in BOMS.items(): - if not line.startswith(BOM): - continue - else: - # BOM discovered - self.encoding = final_encoding - if not final_encoding: - self.BOM = True - # UTF8 - # remove BOM - newline = line[len(BOM):] - if isinstance(infile, (list, tuple)): - infile[0] = newline - else: - infile = newline - # UTF8 - don't decode - if isinstance(infile, basestring): - return infile.splitlines(True) - else: - return infile - # UTF16 - have to decode - return self._decode(infile, encoding) - - # No BOM discovered and no encoding specified, just return - if isinstance(infile, basestring): - # infile read from a file will be a single string - return infile.splitlines(True) - return infile - - - def _a_to_u(self, aString): - """Decode ASCII strings to unicode if a self.encoding is specified.""" - if self.encoding: - return aString.decode('ascii') - else: - return aString - - - def _decode(self, infile, encoding): - """ - Decode infile to unicode. Using the specified encoding. - - if is a string, it also needs converting to a list. - """ - if isinstance(infile, basestring): - # can't be unicode - # NOTE: Could raise a ``UnicodeDecodeError`` - return infile.decode(encoding).splitlines(True) - for i, line in enumerate(infile): - if not isinstance(line, unicode): - # NOTE: The isinstance test here handles mixed lists of unicode/string - # NOTE: But the decode will break on any non-string values - # NOTE: Or could raise a ``UnicodeDecodeError`` - infile[i] = line.decode(encoding) - return infile - - - def _decode_element(self, line): - """Decode element to unicode if necessary.""" - if not self.encoding: - return line - if isinstance(line, str) and self.default_encoding: - return line.decode(self.default_encoding) - return line - - - def _str(self, value): - """ - Used by ``stringify`` within validate, to turn non-string values - into strings. - """ - if not isinstance(value, basestring): - return str(value) - else: - return value - - - def _parse(self, infile): - """Actually parse the config file.""" - temp_list_values = self.list_values - if self.unrepr: - self.list_values = False - - comment_list = [] - done_start = False - this_section = self - maxline = len(infile) - 1 - cur_index = -1 - reset_comment = False - - while cur_index < maxline: - if reset_comment: - comment_list = [] - cur_index += 1 - line = infile[cur_index] - sline = line.strip() - # do we have anything on the line ? - if not sline or sline.startswith('#'): - reset_comment = False - comment_list.append(line) - continue - - if not done_start: - # preserve initial comment - self.initial_comment = comment_list - comment_list = [] - done_start = True - - reset_comment = True - # first we check if it's a section marker - mat = self._sectionmarker.match(line) - if mat is not None: - # is a section line - (indent, sect_open, sect_name, sect_close, comment) = mat.groups() - if indent and (self.indent_type is None): - self.indent_type = indent - cur_depth = sect_open.count('[') - if cur_depth != sect_close.count(']'): - self._handle_error("Cannot compute the section depth at line %s.", - NestingError, infile, cur_index) - continue - - if cur_depth < this_section.depth: - # the new section is dropping back to a previous level - try: - parent = self._match_depth(this_section, - cur_depth).parent - except SyntaxError: - self._handle_error("Cannot compute nesting level at line %s.", - NestingError, infile, cur_index) - continue - elif cur_depth == this_section.depth: - # the new section is a sibling of the current section - parent = this_section.parent - elif cur_depth == this_section.depth + 1: - # the new section is a child the current section - parent = this_section - else: - self._handle_error("Section too nested at line %s.", - NestingError, infile, cur_index) - - sect_name = self._unquote(sect_name) - if sect_name in parent: - self._handle_error('Duplicate section name at line %s.', - DuplicateError, infile, cur_index) - continue - - # create the new section - this_section = Section( - parent, - cur_depth, - self, - name=sect_name) - parent[sect_name] = this_section - parent.inline_comments[sect_name] = comment - parent.comments[sect_name] = comment_list - continue - # - # it's not a section marker, - # so it should be a valid ``key = value`` line - mat = self._keyword.match(line) - if mat is None: - # it neither matched as a keyword - # or a section marker - self._handle_error( - 'Invalid line at line "%s".', - ParseError, infile, cur_index) - else: - # is a keyword value - # value will include any inline comment - (indent, key, value) = mat.groups() - if indent and (self.indent_type is None): - self.indent_type = indent - # check for a multiline value - if value[:3] in ['"""', "'''"]: - try: - value, comment, cur_index = self._multiline( - value, infile, cur_index, maxline) - except SyntaxError: - self._handle_error( - 'Parse error in value at line %s.', - ParseError, infile, cur_index) - continue - else: - if self.unrepr: - comment = '' - try: - value = unrepr(value) - except Exception, e: - if type(e) == UnknownType: - msg = 'Unknown name or type in value at line %s.' - else: - msg = 'Parse error in value at line %s.' - self._handle_error(msg, UnreprError, infile, - cur_index) - continue - else: - if self.unrepr: - comment = '' - try: - value = unrepr(value) - except Exception, e: - if isinstance(e, UnknownType): - msg = 'Unknown name or type in value at line %s.' - else: - msg = 'Parse error in value at line %s.' - self._handle_error(msg, UnreprError, infile, - cur_index) - continue - else: - # extract comment and lists - try: - (value, comment) = self._handle_value(value) - except SyntaxError: - self._handle_error( - 'Parse error in value at line %s.', - ParseError, infile, cur_index) - continue - # - key = self._unquote(key) - if key in this_section: - self._handle_error( - 'Duplicate keyword name at line %s.', - DuplicateError, infile, cur_index) - continue - # add the key. - # we set unrepr because if we have got this far we will never - # be creating a new section - this_section.__setitem__(key, value, unrepr=True) - this_section.inline_comments[key] = comment - this_section.comments[key] = comment_list - continue - # - if self.indent_type is None: - # no indentation used, set the type accordingly - self.indent_type = '' - - # preserve the final comment - if not self and not self.initial_comment: - self.initial_comment = comment_list - elif not reset_comment: - self.final_comment = comment_list - self.list_values = temp_list_values - - - def _match_depth(self, sect, depth): - """ - Given a section and a depth level, walk back through the sections - parents to see if the depth level matches a previous section. - - Return a reference to the right section, - or raise a SyntaxError. - """ - while depth < sect.depth: - if sect is sect.parent: - # we've reached the top level already - raise SyntaxError() - sect = sect.parent - if sect.depth == depth: - return sect - # shouldn't get here - raise SyntaxError() - - - def _handle_error(self, text, ErrorClass, infile, cur_index): - """ - Handle an error according to the error settings. - - Either raise the error or store it. - The error will have occured at ``cur_index`` - """ - line = infile[cur_index] - cur_index += 1 - message = text % cur_index - error = ErrorClass(message, cur_index, line) - if self.raise_errors: - # raise the error - parsing stops here - raise error - # store the error - # reraise when parsing has finished - self._errors.append(error) - - - def _unquote(self, value): - """Return an unquoted version of a value""" - if not value: - # should only happen during parsing of lists - raise SyntaxError - if (value[0] == value[-1]) and (value[0] in ('"', "'")): - value = value[1:-1] - return value - - - def _quote(self, value, multiline=True): - """ - Return a safely quoted version of a value. - - Raise a ConfigObjError if the value cannot be safely quoted. - If multiline is ``True`` (default) then use triple quotes - if necessary. - - * Don't quote values that don't need it. - * Recursively quote members of a list and return a comma joined list. - * Multiline is ``False`` for lists. - * Obey list syntax for empty and single member lists. - - If ``list_values=False`` then the value is only quoted if it contains - a ``\\n`` (is multiline) or '#'. - - If ``write_empty_values`` is set, and the value is an empty string, it - won't be quoted. - """ - if multiline and self.write_empty_values and value == '': - # Only if multiline is set, so that it is used for values not - # keys, and not values that are part of a list - return '' - - if multiline and isinstance(value, (list, tuple)): - if not value: - return ',' - elif len(value) == 1: - return self._quote(value[0], multiline=False) + ',' - return ', '.join([self._quote(val, multiline=False) - for val in value]) - if not isinstance(value, basestring): - if self.stringify: - value = str(value) - else: - raise TypeError('Value "%s" is not a string.' % value) - - if not value: - return '""' - - no_lists_no_quotes = not self.list_values and '\n' not in value and '#' not in value - need_triple = multiline and ((("'" in value) and ('"' in value)) or ('\n' in value )) - hash_triple_quote = multiline and not need_triple and ("'" in value) and ('"' in value) and ('#' in value) - check_for_single = (no_lists_no_quotes or not need_triple) and not hash_triple_quote - - if check_for_single: - if not self.list_values: - # we don't quote if ``list_values=False`` - quot = noquot - # for normal values either single or double quotes will do - elif '\n' in value: - # will only happen if multiline is off - e.g. '\n' in key - raise ConfigObjError('Value "%s" cannot be safely quoted.' % value) - elif ((value[0] not in wspace_plus) and - (value[-1] not in wspace_plus) and - (',' not in value)): - quot = noquot - else: - quot = self._get_single_quote(value) - else: - # if value has '\n' or "'" *and* '"', it will need triple quotes - quot = self._get_triple_quote(value) - - if quot == noquot and '#' in value and self.list_values: - quot = self._get_single_quote(value) - - return quot % value - - - def _get_single_quote(self, value): - if ("'" in value) and ('"' in value): - raise ConfigObjError('Value "%s" cannot be safely quoted.' % value) - elif '"' in value: - quot = squot - else: - quot = dquot - return quot - - - def _get_triple_quote(self, value): - if (value.find('"""') != -1) and (value.find("'''") != -1): - raise ConfigObjError('Value "%s" cannot be safely quoted.' % value) - if value.find('"""') == -1: - quot = tdquot - else: - quot = tsquot - return quot - - - def _handle_value(self, value): - """ - Given a value string, unquote, remove comment, - handle lists. (including empty and single member lists) - """ - if self._inspec: - # Parsing a configspec so don't handle comments - return (value, '') - # do we look for lists in values ? - if not self.list_values: - mat = self._nolistvalue.match(value) - if mat is None: - raise SyntaxError() - # NOTE: we don't unquote here - return mat.groups() - # - mat = self._valueexp.match(value) - if mat is None: - # the value is badly constructed, probably badly quoted, - # or an invalid list - raise SyntaxError() - (list_values, single, empty_list, comment) = mat.groups() - if (list_values == '') and (single is None): - # change this if you want to accept empty values - raise SyntaxError() - # NOTE: note there is no error handling from here if the regex - # is wrong: then incorrect values will slip through - if empty_list is not None: - # the single comma - meaning an empty list - return ([], comment) - if single is not None: - # handle empty values - if list_values and not single: - # FIXME: the '' is a workaround because our regex now matches - # '' at the end of a list if it has a trailing comma - single = None - else: - single = single or '""' - single = self._unquote(single) - if list_values == '': - # not a list value - return (single, comment) - the_list = self._listvalueexp.findall(list_values) - the_list = [self._unquote(val) for val in the_list] - if single is not None: - the_list += [single] - return (the_list, comment) - - - def _multiline(self, value, infile, cur_index, maxline): - """Extract the value, where we are in a multiline situation.""" - quot = value[:3] - newvalue = value[3:] - single_line = self._triple_quote[quot][0] - multi_line = self._triple_quote[quot][1] - mat = single_line.match(value) - if mat is not None: - retval = list(mat.groups()) - retval.append(cur_index) - return retval - elif newvalue.find(quot) != -1: - # somehow the triple quote is missing - raise SyntaxError() - # - while cur_index < maxline: - cur_index += 1 - newvalue += '\n' - line = infile[cur_index] - if line.find(quot) == -1: - newvalue += line - else: - # end of multiline, process it - break - else: - # we've got to the end of the config, oops... - raise SyntaxError() - mat = multi_line.match(line) - if mat is None: - # a badly formed line - raise SyntaxError() - (value, comment) = mat.groups() - return (newvalue + value, comment, cur_index) - - - def _handle_configspec(self, configspec): - """Parse the configspec.""" - # FIXME: Should we check that the configspec was created with the - # correct settings ? (i.e. ``list_values=False``) - if not isinstance(configspec, ConfigObj): - try: - configspec = ConfigObj(configspec, - raise_errors=True, - file_error=True, - _inspec=True) - except ConfigObjError, e: - # FIXME: Should these errors have a reference - # to the already parsed ConfigObj ? - raise ConfigspecError('Parsing configspec failed: %s' % e) - except IOError, e: - raise IOError('Reading configspec failed: %s' % e) - - self.configspec = configspec - - - - def _set_configspec(self, section, copy): - """ - Called by validate. Handles setting the configspec on subsections - including sections to be validated by __many__ - """ - configspec = section.configspec - many = configspec.get('__many__') - if isinstance(many, dict): - for entry in section.sections: - if entry not in configspec: - section[entry].configspec = many - - for entry in configspec.sections: - if entry == '__many__': - continue - if entry not in section: - section[entry] = {} - section[entry]._created = True - if copy: - # copy comments - section.comments[entry] = configspec.comments.get(entry, []) - section.inline_comments[entry] = configspec.inline_comments.get(entry, '') - - # Could be a scalar when we expect a section - if isinstance(section[entry], Section): - section[entry].configspec = configspec[entry] - - - def _write_line(self, indent_string, entry, this_entry, comment): - """Write an individual line, for the write method""" - # NOTE: the calls to self._quote here handles non-StringType values. - if not self.unrepr: - val = self._decode_element(self._quote(this_entry)) - else: - val = repr(this_entry) - return '%s%s%s%s%s' % (indent_string, - self._decode_element(self._quote(entry, multiline=False)), - self._a_to_u(' = '), - val, - self._decode_element(comment)) - - - def _write_marker(self, indent_string, depth, entry, comment): - """Write a section marker line""" - return '%s%s%s%s%s' % (indent_string, - self._a_to_u('[' * depth), - self._quote(self._decode_element(entry), multiline=False), - self._a_to_u(']' * depth), - self._decode_element(comment)) - - - def _handle_comment(self, comment): - """Deal with a comment.""" - if not comment: - return '' - start = self.indent_type - if not comment.startswith('#'): - start += self._a_to_u(' # ') - return (start + comment) - - - # Public methods - - def write(self, outfile=None, section=None): - """ - Write the current ConfigObj as a file - - tekNico: FIXME: use StringIO instead of real files - - >>> filename = a.filename - >>> a.filename = 'test.ini' - >>> a.write() - >>> a.filename = filename - >>> a == ConfigObj('test.ini', raise_errors=True) - 1 - >>> import os - >>> os.remove('test.ini') - """ - if self.indent_type is None: - # this can be true if initialised from a dictionary - self.indent_type = DEFAULT_INDENT_TYPE - - out = [] - cs = self._a_to_u('#') - csp = self._a_to_u('# ') - if section is None: - int_val = self.interpolation - self.interpolation = False - section = self - for line in self.initial_comment: - line = self._decode_element(line) - stripped_line = line.strip() - if stripped_line and not stripped_line.startswith(cs): - line = csp + line - out.append(line) - - indent_string = self.indent_type * section.depth - for entry in (section.scalars + section.sections): - if entry in section.defaults: - # don't write out default values - continue - for comment_line in section.comments[entry]: - comment_line = self._decode_element(comment_line.lstrip()) - if comment_line and not comment_line.startswith(cs): - comment_line = csp + comment_line - out.append(indent_string + comment_line) - this_entry = section[entry] - comment = self._handle_comment(section.inline_comments[entry]) - - if isinstance(this_entry, dict): - # a section - out.append(self._write_marker( - indent_string, - this_entry.depth, - entry, - comment)) - out.extend(self.write(section=this_entry)) - else: - out.append(self._write_line( - indent_string, - entry, - this_entry, - comment)) - - if section is self: - for line in self.final_comment: - line = self._decode_element(line) - stripped_line = line.strip() - if stripped_line and not stripped_line.startswith(cs): - line = csp + line - out.append(line) - self.interpolation = int_val - - if section is not self: - return out - - if (self.filename is None) and (outfile is None): - # output a list of lines - # might need to encode - # NOTE: This will *screw* UTF16, each line will start with the BOM - if self.encoding: - out = [l.encode(self.encoding) for l in out] - if (self.BOM and ((self.encoding is None) or - (BOM_LIST.get(self.encoding.lower()) == 'utf_8'))): - # Add the UTF8 BOM - if not out: - out.append('') - out[0] = BOM_UTF8 + out[0] - return out - - # Turn the list to a string, joined with correct newlines - newline = self.newlines or os.linesep - if (getattr(outfile, 'mode', None) is not None and outfile.mode == 'w' - and sys.platform == 'win32' and newline == '\r\n'): - # Windows specific hack to avoid writing '\r\r\n' - newline = '\n' - output = self._a_to_u(newline).join(out) - if self.encoding: - output = output.encode(self.encoding) - if self.BOM and ((self.encoding is None) or match_utf8(self.encoding)): - # Add the UTF8 BOM - output = BOM_UTF8 + output - - if not output.endswith(newline): - output += newline - if outfile is not None: - outfile.write(output) - else: - h = open(self.filename, 'wb') - h.write(output) - h.close() - - - def validate(self, validator, preserve_errors=False, copy=False, - section=None): - """ - Test the ConfigObj against a configspec. - - It uses the ``validator`` object from *validate.py*. - - To run ``validate`` on the current ConfigObj, call: :: - - test = config.validate(validator) - - (Normally having previously passed in the configspec when the ConfigObj - was created - you can dynamically assign a dictionary of checks to the - ``configspec`` attribute of a section though). - - It returns ``True`` if everything passes, or a dictionary of - pass/fails (True/False). If every member of a subsection passes, it - will just have the value ``True``. (It also returns ``False`` if all - members fail). - - In addition, it converts the values from strings to their native - types if their checks pass (and ``stringify`` is set). - - If ``preserve_errors`` is ``True`` (``False`` is default) then instead - of a marking a fail with a ``False``, it will preserve the actual - exception object. This can contain info about the reason for failure. - For example the ``VdtValueTooSmallError`` indicates that the value - supplied was too small. If a value (or section) is missing it will - still be marked as ``False``. - - You must have the validate module to use ``preserve_errors=True``. - - You can then use the ``flatten_errors`` function to turn your nested - results dictionary into a flattened list of failures - useful for - displaying meaningful error messages. - """ - if section is None: - if self.configspec is None: - raise ValueError('No configspec supplied.') - if preserve_errors: - # We do this once to remove a top level dependency on the validate module - # Which makes importing configobj faster - from validate import VdtMissingValue - self._vdtMissingValue = VdtMissingValue - - section = self - - if copy: - section.initial_comment = section.configspec.initial_comment - section.final_comment = section.configspec.final_comment - section.encoding = section.configspec.encoding - section.BOM = section.configspec.BOM - section.newlines = section.configspec.newlines - section.indent_type = section.configspec.indent_type - - # - # section.default_values.clear() #?? - configspec = section.configspec - self._set_configspec(section, copy) - - - def validate_entry(entry, spec, val, missing, ret_true, ret_false): - section.default_values.pop(entry, None) - - try: - section.default_values[entry] = validator.get_default_value(configspec[entry]) - except (KeyError, AttributeError, validator.baseErrorClass): - # No default, bad default or validator has no 'get_default_value' - # (e.g. SimpleVal) - pass - - try: - check = validator.check(spec, - val, - missing=missing - ) - except validator.baseErrorClass, e: - if not preserve_errors or isinstance(e, self._vdtMissingValue): - out[entry] = False - else: - # preserve the error - out[entry] = e - ret_false = False - ret_true = False - else: - ret_false = False - out[entry] = True - if self.stringify or missing: - # if we are doing type conversion - # or the value is a supplied default - if not self.stringify: - if isinstance(check, (list, tuple)): - # preserve lists - check = [self._str(item) for item in check] - elif missing and check is None: - # convert the None from a default to a '' - check = '' - else: - check = self._str(check) - if (check != val) or missing: - section[entry] = check - if not copy and missing and entry not in section.defaults: - section.defaults.append(entry) - return ret_true, ret_false - - # - out = {} - ret_true = True - ret_false = True - - unvalidated = [k for k in section.scalars if k not in configspec] - incorrect_sections = [k for k in configspec.sections if k in section.scalars] - incorrect_scalars = [k for k in configspec.scalars if k in section.sections] - - for entry in configspec.scalars: - if entry in ('__many__', '___many___'): - # reserved names - continue - if (not entry in section.scalars) or (entry in section.defaults): - # missing entries - # or entries from defaults - missing = True - val = None - if copy and entry not in section.scalars: - # copy comments - section.comments[entry] = ( - configspec.comments.get(entry, [])) - section.inline_comments[entry] = ( - configspec.inline_comments.get(entry, '')) - # - else: - missing = False - val = section[entry] - - ret_true, ret_false = validate_entry(entry, configspec[entry], val, - missing, ret_true, ret_false) - - many = None - if '__many__' in configspec.scalars: - many = configspec['__many__'] - elif '___many___' in configspec.scalars: - many = configspec['___many___'] - - if many is not None: - for entry in unvalidated: - val = section[entry] - ret_true, ret_false = validate_entry(entry, many, val, False, - ret_true, ret_false) - unvalidated = [] - - for entry in incorrect_scalars: - ret_true = False - if not preserve_errors: - out[entry] = False - else: - ret_false = False - msg = 'Value %r was provided as a section' % entry - out[entry] = validator.baseErrorClass(msg) - for entry in incorrect_sections: - ret_true = False - if not preserve_errors: - out[entry] = False - else: - ret_false = False - msg = 'Section %r was provided as a single value' % entry - out[entry] = validator.baseErrorClass(msg) - - # Missing sections will have been created as empty ones when the - # configspec was read. - for entry in section.sections: - # FIXME: this means DEFAULT is not copied in copy mode - if section is self and entry == 'DEFAULT': - continue - if section[entry].configspec is None: - unvalidated.append(entry) - continue - if copy: - section.comments[entry] = configspec.comments.get(entry, []) - section.inline_comments[entry] = configspec.inline_comments.get(entry, '') - check = self.validate(validator, preserve_errors=preserve_errors, copy=copy, section=section[entry]) - out[entry] = check - if check == False: - ret_true = False - elif check == True: - ret_false = False - else: - ret_true = False - - section.extra_values = unvalidated - if preserve_errors and not section._created: - # If the section wasn't created (i.e. it wasn't missing) - # then we can't return False, we need to preserve errors - ret_false = False - # - if ret_false and preserve_errors and out: - # If we are preserving errors, but all - # the failures are from missing sections / values - # then we can return False. Otherwise there is a - # real failure that we need to preserve. - ret_false = not any(out.values()) - if ret_true: - return True - elif ret_false: - return False - return out - - - def reset(self): - """Clear ConfigObj instance and restore to 'freshly created' state.""" - self.clear() - self._initialise() - # FIXME: Should be done by '_initialise', but ConfigObj constructor (and reload) - # requires an empty dictionary - self.configspec = None - # Just to be sure ;-) - self._original_configspec = None - - - def reload(self): - """ - Reload a ConfigObj from file. - - This method raises a ``ReloadError`` if the ConfigObj doesn't have - a filename attribute pointing to a file. - """ - if not isinstance(self.filename, basestring): - raise ReloadError() - - filename = self.filename - current_options = {} - for entry in OPTION_DEFAULTS: - if entry == 'configspec': - continue - current_options[entry] = getattr(self, entry) - - configspec = self._original_configspec - current_options['configspec'] = configspec - - self.clear() - self._initialise(current_options) - self._load(filename, configspec) - - - -class SimpleVal(object): - """ - A simple validator. - Can be used to check that all members expected are present. - - To use it, provide a configspec with all your members in (the value given - will be ignored). Pass an instance of ``SimpleVal`` to the ``validate`` - method of your ``ConfigObj``. ``validate`` will return ``True`` if all - members are present, or a dictionary with True/False meaning - present/missing. (Whole missing sections will be replaced with ``False``) - """ - - def __init__(self): - self.baseErrorClass = ConfigObjError - - def check(self, check, member, missing=False): - """A dummy check method, always returns the value unchanged.""" - if missing: - raise self.baseErrorClass() - return member - - -def flatten_errors(cfg, res, levels=None, results=None): - """ - An example function that will turn a nested dictionary of results - (as returned by ``ConfigObj.validate``) into a flat list. - - ``cfg`` is the ConfigObj instance being checked, ``res`` is the results - dictionary returned by ``validate``. - - (This is a recursive function, so you shouldn't use the ``levels`` or - ``results`` arguments - they are used by the function.) - - Returns a list of keys that failed. Each member of the list is a tuple:: - - ([list of sections...], key, result) - - If ``validate`` was called with ``preserve_errors=False`` (the default) - then ``result`` will always be ``False``. - - *list of sections* is a flattened list of sections that the key was found - in. - - If the section was missing (or a section was expected and a scalar provided - - or vice-versa) then key will be ``None``. - - If the value (or section) was missing then ``result`` will be ``False``. - - If ``validate`` was called with ``preserve_errors=True`` and a value - was present, but failed the check, then ``result`` will be the exception - object returned. You can use this as a string that describes the failure. - - For example *The value "3" is of the wrong type*. - """ - if levels is None: - # first time called - levels = [] - results = [] - if res == True: - return results - if res == False or isinstance(res, Exception): - results.append((levels[:], None, res)) - if levels: - levels.pop() - return results - for (key, val) in res.items(): - if val == True: - continue - if isinstance(cfg.get(key), dict): - # Go down one level - levels.append(key) - flatten_errors(cfg[key], val, levels, results) - continue - results.append((levels[:], key, val)) - # - # Go up one level - if levels: - levels.pop() - # - return results - - -def get_extra_values(conf, _prepend=()): - """ - Find all the values and sections not in the configspec from a validated - ConfigObj. - - ``get_extra_values`` returns a list of tuples where each tuple represents - either an extra section, or an extra value. - - The tuples contain two values, a tuple representing the section the value - is in and the name of the extra values. For extra values in the top level - section the first member will be an empty tuple. For values in the 'foo' - section the first member will be ``('foo',)``. For members in the 'bar' - subsection of the 'foo' section the first member will be ``('foo', 'bar')``. - - NOTE: If you call ``get_extra_values`` on a ConfigObj instance that hasn't - been validated it will return an empty list. - """ - out = [] - - out.extend([(_prepend, name) for name in conf.extra_values]) - for name in conf.sections: - if name not in conf.extra_values: - out.extend(get_extra_values(conf[name], _prepend + (name,))) - return out - - -"""*A programming language is a medium of expression.* - Paul Graham""" diff --git a/python/cdec/sa/__init__.py b/python/cdec/sa/__init__.py deleted file mode 100644 index 8645e837..00000000 --- a/python/cdec/sa/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from _sa import sym_fromstring,\ - SuffixArray, DataArray, LCP, Precomputation, Alignment, BiLex,\ - HieroCachingRuleFactory, Sampler -from extractor import GrammarExtractor diff --git a/python/cdec/sa/compile.py b/python/cdec/sa/compile.py deleted file mode 100644 index 30e605a6..00000000 --- a/python/cdec/sa/compile.py +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env python -import argparse -import os -import logging -import cdec.configobj -import cdec.sa - -MAX_PHRASE_LENGTH = 4 -def precompute(f_sa, max_len, max_nt, max_size, min_gap, rank1, rank2): - lcp = cdec.sa.LCP(f_sa) - stats = sorted(lcp.compute_stats(MAX_PHRASE_LENGTH), reverse=True) - precomp = cdec.sa.Precomputation(from_stats=stats, - fsarray=f_sa, - precompute_rank=rank1, - precompute_secondary_rank=rank2, - max_length=max_len, - max_nonterminals=max_nt, - train_max_initial_size=max_size, - train_min_gap_size=min_gap) - return precomp - -def main(): - logging.basicConfig(level=logging.INFO) - logger = logging.getLogger('cdec.sa.compile') - parser = argparse.ArgumentParser(description='Compile a corpus into a suffix array.') - parser.add_argument('--maxnt', '-n', type=int, default=2, - help='Maximum number of non-terminal symbols') - parser.add_argument('--maxlen', '-l', type=int, default=5, - help='Maximum number of terminals') - parser.add_argument('--maxsize', '-s', type=int, default=15, - help='Maximum rule span') - parser.add_argument('--mingap', '-g', type=int, default=1, - help='Minimum gap size') - parser.add_argument('--rank1', '-r1', type=int, default=100, - help='Number of pre-computed frequent patterns') - parser.add_argument('--rank2', '-r2', type=int, default=10, - help='Number of pre-computed super-frequent patterns)') - parser.add_argument('-c', '--config', default='/dev/stdout', - help='Output configuration') - parser.add_argument('-o', '--output', required=True, - help='Output path') - parser.add_argument('-f', '--source', required=True, - help='Source language corpus') - parser.add_argument('-e', '--target', required=True, - help='Target language corpus') - parser.add_argument('-a', '--alignment', required=True, - help='Bitext word alignment') - args = parser.parse_args() - - param_names = ("max_len", "max_nt", "max_size", "min_gap", "rank1", "rank2") - params = (args.maxlen, args.maxnt, args.maxsize, args.mingap, args.rank1, args.rank2) - - if not os.path.exists(args.output): - os.mkdir(args.output) - - f_sa_bin = os.path.join(args.output, 'f.sa.bin') - e_bin = os.path.join(args.output, 'e.bin') - precomp_file = 'precomp.{0}.{1}.{2}.{3}.{4}.{5}.bin'.format(*params) - precomp_bin = os.path.join(args.output, precomp_file) - a_bin = os.path.join(args.output, 'a.bin') - lex_bin = os.path.join(args.output, 'lex.bin') - - logger.info('Compiling source suffix array') - f_sa = cdec.sa.SuffixArray(from_text=args.source) - f_sa.write_binary(f_sa_bin) - - logger.info('Compiling target data array') - e = cdec.sa.DataArray(from_text=args.target) - e.write_binary(e_bin) - - logger.info('Precomputing frequent phrases') - precompute(f_sa, *params).write_binary(precomp_bin) - - logger.info('Compiling alignment') - a = cdec.sa.Alignment(from_text=args.alignment) - a.write_binary(a_bin) - - logger.info('Compiling bilexical dictionary') - lex = cdec.sa.BiLex(from_data=True, alignment=a, earray=e, fsarray=f_sa) - lex.write_binary(lex_bin) - - # Write configuration - config = cdec.configobj.ConfigObj(args.config, unrepr=True) - config['f_sa_file'] = f_sa_bin - config['e_file'] = e_bin - config['a_file'] = a_bin - config['lex_file'] = lex_bin - config['precompute_file'] = precomp_bin - for name, value in zip(param_names, params): - config[name] = value - config.write() - -if __name__ == '__main__': - main() diff --git a/python/cdec/sa/extract.py b/python/cdec/sa/extract.py deleted file mode 100644 index 918aa3bb..00000000 --- a/python/cdec/sa/extract.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env python -import sys -import os -import argparse -import logging -import cdec.sa - -def main(): - logging.basicConfig(level=logging.INFO) - parser = argparse.ArgumentParser(description='Extract grammars from a compiled corpus.') - parser.add_argument('-c', '--config', required=True, - help='Extractor configuration') - parser.add_argument('-g', '--grammars', required=True, - help='Grammar output path') - args = parser.parse_args() - - if not os.path.exists(args.grammars): - os.mkdir(args.grammars) - - extractor = cdec.sa.GrammarExtractor(args.config) - for i, sentence in enumerate(sys.stdin): - sentence = sentence[:-1] - grammar_file = os.path.join(args.grammars, 'grammar.{0}'.format(i)) - with open(grammar_file, 'w') as output: - for rule in extractor.grammar(sentence): - output.write(str(rule)+'\n') - grammar_file = os.path.abspath(grammar_file) - print('{1}'.format(grammar_file, sentence)) - -if __name__ == '__main__': - main() diff --git a/python/cdec/sa/extractor.py b/python/cdec/sa/extractor.py deleted file mode 100644 index bb912e16..00000000 --- a/python/cdec/sa/extractor.py +++ /dev/null @@ -1,78 +0,0 @@ -from itertools import chain -import os -import cdec.configobj -from cdec.sa.features import EgivenFCoherent, SampleCountF, CountEF,\ - MaxLexEgivenF, MaxLexFgivenE, IsSingletonF, IsSingletonFE -import cdec.sa - -# maximum span of a grammar rule in TEST DATA -MAX_INITIAL_SIZE = 15 - -class GrammarExtractor: - def __init__(self, config): - if isinstance(config, str) or isinstance(config, unicode): - if not os.path.exists(config): - raise IOError('cannot read configuration from {0}'.format(config)) - config = cdec.configobj.ConfigObj(config, unrepr=True) - alignment = cdec.sa.Alignment(from_binary=config['a_file']) - self.factory = cdec.sa.HieroCachingRuleFactory( - # compiled alignment object (REQUIRED) - alignment, - # name of generic nonterminal used by Hiero - category="[X]", - # maximum number of contiguous chunks of terminal symbols in RHS of a rule - max_chunks=config['max_nt']+1, - # maximum span of a grammar rule in TEST DATA - max_initial_size=MAX_INITIAL_SIZE, - # maximum number of symbols (both T and NT) allowed in a rule - max_length=config['max_len'], - # maximum number of nonterminals allowed in a rule (set >2 at your own risk) - max_nonterminals=config['max_nt'], - # maximum number of contiguous chunks of terminal symbols - # in target-side RHS of a rule. - max_target_chunks=config['max_nt']+1, - # maximum number of target side symbols (both T and NT) allowed in a rule. - max_target_length=MAX_INITIAL_SIZE, - # minimum span of a nonterminal in the RHS of a rule in TEST DATA - min_gap_size=1, - # filename of file containing precomputed collocations - precompute_file=config['precompute_file'], - # maximum frequency rank of patterns used to compute triples (< 20) - precompute_secondary_rank=config['rank2'], - # maximum frequency rank of patterns used to compute collocations (< 300) - precompute_rank=config['rank1'], - # require extracted rules to have at least one aligned word - require_aligned_terminal=True, - # require each contiguous chunk of extracted rules - # to have at least one aligned word - require_aligned_chunks=False, - # maximum span of a grammar rule extracted from TRAINING DATA - train_max_initial_size=config['max_size'], - # minimum span of an RHS nonterminal in a rule extracted from TRAINING DATA - train_min_gap_size=config['min_gap'], - # True if phrases should be tight, False otherwise (better but slower) - tight_phrases=True, - ) - - # lexical weighting tables - tt = cdec.sa.BiLex(from_binary=config['lex_file']) - - self.models = (EgivenFCoherent, SampleCountF, CountEF, - MaxLexFgivenE(tt), MaxLexEgivenF(tt), IsSingletonF, IsSingletonFE) - - fsarray = cdec.sa.SuffixArray(from_binary=config['f_sa_file']) - edarray = cdec.sa.DataArray(from_binary=config['e_file']) - - # lower=faster, higher=better; improvements level off above 200-300 range, - # -1 = don't sample, use all data (VERY SLOW!) - sampler = cdec.sa.Sampler(300, fsarray) - - self.factory.configure(fsarray, edarray, sampler) - - def grammar(self, sentence): - if isinstance(sentence, unicode): - sentence = sentence.encode('utf8') - cnet = chain(('',), sentence.split(), ('',)) - cnet = (cdec.sa.sym_fromstring(word, terminal=True) for word in cnet) - cnet = tuple(((word, None, 1), ) for word in cnet) - return self.factory.input(cnet, self.models) diff --git a/python/cdec/sa/features.py b/python/cdec/sa/features.py deleted file mode 100644 index 325b9e13..00000000 --- a/python/cdec/sa/features.py +++ /dev/null @@ -1,57 +0,0 @@ -from __future__ import division -import math - -MAXSCORE = 99 - -def EgivenF(fphrase, ephrase, paircount, fcount, fsample_count): # p(e|f) - return -math.log10(paircount/fcount) - -def CountEF(fphrase, ephrase, paircount, fcount, fsample_count): - return math.log10(1 + paircount) - -def SampleCountF(fphrase, ephrase, paircount, fcount, fsample_count): - return math.log10(1 + fsample_count) - -def EgivenFCoherent(fphrase, ephrase, paircount, fcount, fsample_count): - prob = paircount/fsample_count - return -math.log10(prob) if prob > 0 else MAXSCORE - -def CoherenceProb(fphrase, ephrase, paircount, fcount, fsample_count): - return -math.log10(fcount/fsample_count) - -def MaxLexEgivenF(ttable): - def feature(fphrase, ephrase, paircount, fcount, fsample_count): - fwords = fphrase.words - fwords.append('NULL') - def score(): - for e in ephrase.words: - maxScore = max(ttable.get_score(f, e, 0) for f in fwords) - yield -math.log10(maxScore) if maxScore > 0 else MAXSCORE - return sum(score()) - return feature - -def MaxLexFgivenE(ttable): - def feature(fphrase, ephrase, paircount, fcount, fsample_count): - ewords = ephrase.words - ewords.append('NULL') - def score(): - for f in fphrase.words: - maxScore = max(ttable.get_score(f, e, 1) for e in ewords) - yield -math.log10(maxScore) if maxScore > 0 else MAXSCORE - return sum(score()) - return feature - -def IsSingletonF(fphrase, ephrase, paircount, fcount, fsample_count): - return (fcount == 1) - -def IsSingletonFE(fphrase, ephrase, paircount, fcount, fsample_count): - return (paircount == 1) - -def IsNotSingletonF(fphrase, ephrase, paircount, fcount, fsample_count): - return (fcount > 1) - -def IsNotSingletonFE(fphrase, ephrase, paircount, fcount, fsample_count): - return (paircount > 1) - -def IsFEGreaterThanZero(fphrase, ephrase, paircount, fcount, fsample_count): - return (paircount > 0.01) diff --git a/python/cdec/score.py b/python/cdec/score.py deleted file mode 100644 index 22257774..00000000 --- a/python/cdec/score.py +++ /dev/null @@ -1 +0,0 @@ -from _cdec import BLEU, TER, CER, Metric diff --git a/python/pkg/cdec/__init__.py b/python/pkg/cdec/__init__.py new file mode 100644 index 00000000..503ac787 --- /dev/null +++ b/python/pkg/cdec/__init__.py @@ -0,0 +1 @@ +from cdec._cdec import Decoder, Lattice, TRule, NT, NTRef, ParseFailed, InvalidConfig diff --git a/python/pkg/cdec/configobj.py b/python/pkg/cdec/configobj.py new file mode 100644 index 00000000..c1f6e6df --- /dev/null +++ b/python/pkg/cdec/configobj.py @@ -0,0 +1,2468 @@ +# configobj.py +# A config file reader/writer that supports nested sections in config files. +# Copyright (C) 2005-2010 Michael Foord, Nicola Larosa +# E-mail: fuzzyman AT voidspace DOT org DOT uk +# nico AT tekNico DOT net + +# ConfigObj 4 +# http://www.voidspace.org.uk/python/configobj.html + +# Released subject to the BSD License +# Please see http://www.voidspace.org.uk/python/license.shtml + +# Scripts maintained at http://www.voidspace.org.uk/python/index.shtml +# For information about bugfixes, updates and support, please join the +# ConfigObj mailing list: +# http://lists.sourceforge.net/lists/listinfo/configobj-develop +# Comments, suggestions and bug reports welcome. + +from __future__ import generators + +import os +import re +import sys + +from codecs import BOM_UTF8, BOM_UTF16, BOM_UTF16_BE, BOM_UTF16_LE + + +# imported lazily to avoid startup performance hit if it isn't used +compiler = None + +# A dictionary mapping BOM to +# the encoding to decode with, and what to set the +# encoding attribute to. +BOMS = { + BOM_UTF8: ('utf_8', None), + BOM_UTF16_BE: ('utf16_be', 'utf_16'), + BOM_UTF16_LE: ('utf16_le', 'utf_16'), + BOM_UTF16: ('utf_16', 'utf_16'), + } +# All legal variants of the BOM codecs. +# TODO: the list of aliases is not meant to be exhaustive, is there a +# better way ? +BOM_LIST = { + 'utf_16': 'utf_16', + 'u16': 'utf_16', + 'utf16': 'utf_16', + 'utf-16': 'utf_16', + 'utf16_be': 'utf16_be', + 'utf_16_be': 'utf16_be', + 'utf-16be': 'utf16_be', + 'utf16_le': 'utf16_le', + 'utf_16_le': 'utf16_le', + 'utf-16le': 'utf16_le', + 'utf_8': 'utf_8', + 'u8': 'utf_8', + 'utf': 'utf_8', + 'utf8': 'utf_8', + 'utf-8': 'utf_8', + } + +# Map of encodings to the BOM to write. +BOM_SET = { + 'utf_8': BOM_UTF8, + 'utf_16': BOM_UTF16, + 'utf16_be': BOM_UTF16_BE, + 'utf16_le': BOM_UTF16_LE, + None: BOM_UTF8 + } + + +def match_utf8(encoding): + return BOM_LIST.get(encoding.lower()) == 'utf_8' + + +# Quote strings used for writing values +squot = "'%s'" +dquot = '"%s"' +noquot = "%s" +wspace_plus = ' \r\n\v\t\'"' +tsquot = '"""%s"""' +tdquot = "'''%s'''" + +# Sentinel for use in getattr calls to replace hasattr +MISSING = object() + +__version__ = '4.7.2' + +try: + any +except NameError: + def any(iterable): + for entry in iterable: + if entry: + return True + return False + + +__all__ = ( + '__version__', + 'DEFAULT_INDENT_TYPE', + 'DEFAULT_INTERPOLATION', + 'ConfigObjError', + 'NestingError', + 'ParseError', + 'DuplicateError', + 'ConfigspecError', + 'ConfigObj', + 'SimpleVal', + 'InterpolationError', + 'InterpolationLoopError', + 'MissingInterpolationOption', + 'RepeatSectionError', + 'ReloadError', + 'UnreprError', + 'UnknownType', + 'flatten_errors', + 'get_extra_values' +) + +DEFAULT_INTERPOLATION = 'configparser' +DEFAULT_INDENT_TYPE = ' ' +MAX_INTERPOL_DEPTH = 10 + +OPTION_DEFAULTS = { + 'interpolation': True, + 'raise_errors': False, + 'list_values': True, + 'create_empty': False, + 'file_error': False, + 'configspec': None, + 'stringify': True, + # option may be set to one of ('', ' ', '\t') + 'indent_type': None, + 'encoding': None, + 'default_encoding': None, + 'unrepr': False, + 'write_empty_values': False, +} + + + +def getObj(s): + global compiler + if compiler is None: + import compiler + s = "a=" + s + p = compiler.parse(s) + return p.getChildren()[1].getChildren()[0].getChildren()[1] + + +class UnknownType(Exception): + pass + + +class Builder(object): + + def build(self, o): + m = getattr(self, 'build_' + o.__class__.__name__, None) + if m is None: + raise UnknownType(o.__class__.__name__) + return m(o) + + def build_List(self, o): + return map(self.build, o.getChildren()) + + def build_Const(self, o): + return o.value + + def build_Dict(self, o): + d = {} + i = iter(map(self.build, o.getChildren())) + for el in i: + d[el] = i.next() + return d + + def build_Tuple(self, o): + return tuple(self.build_List(o)) + + def build_Name(self, o): + if o.name == 'None': + return None + if o.name == 'True': + return True + if o.name == 'False': + return False + + # An undefined Name + raise UnknownType('Undefined Name') + + def build_Add(self, o): + real, imag = map(self.build_Const, o.getChildren()) + try: + real = float(real) + except TypeError: + raise UnknownType('Add') + if not isinstance(imag, complex) or imag.real != 0.0: + raise UnknownType('Add') + return real+imag + + def build_Getattr(self, o): + parent = self.build(o.expr) + return getattr(parent, o.attrname) + + def build_UnarySub(self, o): + return -self.build_Const(o.getChildren()[0]) + + def build_UnaryAdd(self, o): + return self.build_Const(o.getChildren()[0]) + + +_builder = Builder() + + +def unrepr(s): + if not s: + return s + return _builder.build(getObj(s)) + + + +class ConfigObjError(SyntaxError): + """ + This is the base class for all errors that ConfigObj raises. + It is a subclass of SyntaxError. + """ + def __init__(self, message='', line_number=None, line=''): + self.line = line + self.line_number = line_number + SyntaxError.__init__(self, message) + + +class NestingError(ConfigObjError): + """ + This error indicates a level of nesting that doesn't match. + """ + + +class ParseError(ConfigObjError): + """ + This error indicates that a line is badly written. + It is neither a valid ``key = value`` line, + nor a valid section marker line. + """ + + +class ReloadError(IOError): + """ + A 'reload' operation failed. + This exception is a subclass of ``IOError``. + """ + def __init__(self): + IOError.__init__(self, 'reload failed, filename is not set.') + + +class DuplicateError(ConfigObjError): + """ + The keyword or section specified already exists. + """ + + +class ConfigspecError(ConfigObjError): + """ + An error occured whilst parsing a configspec. + """ + + +class InterpolationError(ConfigObjError): + """Base class for the two interpolation errors.""" + + +class InterpolationLoopError(InterpolationError): + """Maximum interpolation depth exceeded in string interpolation.""" + + def __init__(self, option): + InterpolationError.__init__( + self, + 'interpolation loop detected in value "%s".' % option) + + +class RepeatSectionError(ConfigObjError): + """ + This error indicates additional sections in a section with a + ``__many__`` (repeated) section. + """ + + +class MissingInterpolationOption(InterpolationError): + """A value specified for interpolation was missing.""" + def __init__(self, option): + msg = 'missing option "%s" in interpolation.' % option + InterpolationError.__init__(self, msg) + + +class UnreprError(ConfigObjError): + """An error parsing in unrepr mode.""" + + + +class InterpolationEngine(object): + """ + A helper class to help perform string interpolation. + + This class is an abstract base class; its descendants perform + the actual work. + """ + + # compiled regexp to use in self.interpolate() + _KEYCRE = re.compile(r"%\(([^)]*)\)s") + _cookie = '%' + + def __init__(self, section): + # the Section instance that "owns" this engine + self.section = section + + + def interpolate(self, key, value): + # short-cut + if not self._cookie in value: + return value + + def recursive_interpolate(key, value, section, backtrail): + """The function that does the actual work. + + ``value``: the string we're trying to interpolate. + ``section``: the section in which that string was found + ``backtrail``: a dict to keep track of where we've been, + to detect and prevent infinite recursion loops + + This is similar to a depth-first-search algorithm. + """ + # Have we been here already? + if (key, section.name) in backtrail: + # Yes - infinite loop detected + raise InterpolationLoopError(key) + # Place a marker on our backtrail so we won't come back here again + backtrail[(key, section.name)] = 1 + + # Now start the actual work + match = self._KEYCRE.search(value) + while match: + # The actual parsing of the match is implementation-dependent, + # so delegate to our helper function + k, v, s = self._parse_match(match) + if k is None: + # That's the signal that no further interpolation is needed + replacement = v + else: + # Further interpolation may be needed to obtain final value + replacement = recursive_interpolate(k, v, s, backtrail) + # Replace the matched string with its final value + start, end = match.span() + value = ''.join((value[:start], replacement, value[end:])) + new_search_start = start + len(replacement) + # Pick up the next interpolation key, if any, for next time + # through the while loop + match = self._KEYCRE.search(value, new_search_start) + + # Now safe to come back here again; remove marker from backtrail + del backtrail[(key, section.name)] + + return value + + # Back in interpolate(), all we have to do is kick off the recursive + # function with appropriate starting values + value = recursive_interpolate(key, value, self.section, {}) + return value + + + def _fetch(self, key): + """Helper function to fetch values from owning section. + + Returns a 2-tuple: the value, and the section where it was found. + """ + # switch off interpolation before we try and fetch anything ! + save_interp = self.section.main.interpolation + self.section.main.interpolation = False + + # Start at section that "owns" this InterpolationEngine + current_section = self.section + while True: + # try the current section first + val = current_section.get(key) + if val is not None and not isinstance(val, Section): + break + # try "DEFAULT" next + val = current_section.get('DEFAULT', {}).get(key) + if val is not None and not isinstance(val, Section): + break + # move up to parent and try again + # top-level's parent is itself + if current_section.parent is current_section: + # reached top level, time to give up + break + current_section = current_section.parent + + # restore interpolation to previous value before returning + self.section.main.interpolation = save_interp + if val is None: + raise MissingInterpolationOption(key) + return val, current_section + + + def _parse_match(self, match): + """Implementation-dependent helper function. + + Will be passed a match object corresponding to the interpolation + key we just found (e.g., "%(foo)s" or "$foo"). Should look up that + key in the appropriate config file section (using the ``_fetch()`` + helper function) and return a 3-tuple: (key, value, section) + + ``key`` is the name of the key we're looking for + ``value`` is the value found for that key + ``section`` is a reference to the section where it was found + + ``key`` and ``section`` should be None if no further + interpolation should be performed on the resulting value + (e.g., if we interpolated "$$" and returned "$"). + """ + raise NotImplementedError() + + + +class ConfigParserInterpolation(InterpolationEngine): + """Behaves like ConfigParser.""" + _cookie = '%' + _KEYCRE = re.compile(r"%\(([^)]*)\)s") + + def _parse_match(self, match): + key = match.group(1) + value, section = self._fetch(key) + return key, value, section + + + +class TemplateInterpolation(InterpolationEngine): + """Behaves like string.Template.""" + _cookie = '$' + _delimiter = '$' + _KEYCRE = re.compile(r""" + \$(?: + (?P\$) | # Two $ signs + (?P[_a-z][_a-z0-9]*) | # $name format + {(?P[^}]*)} # ${name} format + ) + """, re.IGNORECASE | re.VERBOSE) + + def _parse_match(self, match): + # Valid name (in or out of braces): fetch value from section + key = match.group('named') or match.group('braced') + if key is not None: + value, section = self._fetch(key) + return key, value, section + # Escaped delimiter (e.g., $$): return single delimiter + if match.group('escaped') is not None: + # Return None for key and section to indicate it's time to stop + return None, self._delimiter, None + # Anything else: ignore completely, just return it unchanged + return None, match.group(), None + + +interpolation_engines = { + 'configparser': ConfigParserInterpolation, + 'template': TemplateInterpolation, +} + + +def __newobj__(cls, *args): + # Hack for pickle + return cls.__new__(cls, *args) + +class Section(dict): + """ + A dictionary-like object that represents a section in a config file. + + It does string interpolation if the 'interpolation' attribute + of the 'main' object is set to True. + + Interpolation is tried first from this object, then from the 'DEFAULT' + section of this object, next from the parent and its 'DEFAULT' section, + and so on until the main object is reached. + + A Section will behave like an ordered dictionary - following the + order of the ``scalars`` and ``sections`` attributes. + You can use this to change the order of members. + + Iteration follows the order: scalars, then sections. + """ + + + def __setstate__(self, state): + dict.update(self, state[0]) + self.__dict__.update(state[1]) + + def __reduce__(self): + state = (dict(self), self.__dict__) + return (__newobj__, (self.__class__,), state) + + + def __init__(self, parent, depth, main, indict=None, name=None): + """ + * parent is the section above + * depth is the depth level of this section + * main is the main ConfigObj + * indict is a dictionary to initialise the section with + """ + if indict is None: + indict = {} + dict.__init__(self) + # used for nesting level *and* interpolation + self.parent = parent + # used for the interpolation attribute + self.main = main + # level of nesting depth of this Section + self.depth = depth + # purely for information + self.name = name + # + self._initialise() + # we do this explicitly so that __setitem__ is used properly + # (rather than just passing to ``dict.__init__``) + for entry, value in indict.iteritems(): + self[entry] = value + + + def _initialise(self): + # the sequence of scalar values in this Section + self.scalars = [] + # the sequence of sections in this Section + self.sections = [] + # for comments :-) + self.comments = {} + self.inline_comments = {} + # the configspec + self.configspec = None + # for defaults + self.defaults = [] + self.default_values = {} + self.extra_values = [] + self._created = False + + + def _interpolate(self, key, value): + try: + # do we already have an interpolation engine? + engine = self._interpolation_engine + except AttributeError: + # not yet: first time running _interpolate(), so pick the engine + name = self.main.interpolation + if name == True: # note that "if name:" would be incorrect here + # backwards-compatibility: interpolation=True means use default + name = DEFAULT_INTERPOLATION + name = name.lower() # so that "Template", "template", etc. all work + class_ = interpolation_engines.get(name, None) + if class_ is None: + # invalid value for self.main.interpolation + self.main.interpolation = False + return value + else: + # save reference to engine so we don't have to do this again + engine = self._interpolation_engine = class_(self) + # let the engine do the actual work + return engine.interpolate(key, value) + + + def __getitem__(self, key): + """Fetch the item and do string interpolation.""" + val = dict.__getitem__(self, key) + if self.main.interpolation: + if isinstance(val, basestring): + return self._interpolate(key, val) + if isinstance(val, list): + def _check(entry): + if isinstance(entry, basestring): + return self._interpolate(key, entry) + return entry + new = [_check(entry) for entry in val] + if new != val: + return new + return val + + + def __setitem__(self, key, value, unrepr=False): + """ + Correctly set a value. + + Making dictionary values Section instances. + (We have to special case 'Section' instances - which are also dicts) + + Keys must be strings. + Values need only be strings (or lists of strings) if + ``main.stringify`` is set. + + ``unrepr`` must be set when setting a value to a dictionary, without + creating a new sub-section. + """ + if not isinstance(key, basestring): + raise ValueError('The key "%s" is not a string.' % key) + + # add the comment + if key not in self.comments: + self.comments[key] = [] + self.inline_comments[key] = '' + # remove the entry from defaults + if key in self.defaults: + self.defaults.remove(key) + # + if isinstance(value, Section): + if key not in self: + self.sections.append(key) + dict.__setitem__(self, key, value) + elif isinstance(value, dict) and not unrepr: + # First create the new depth level, + # then create the section + if key not in self: + self.sections.append(key) + new_depth = self.depth + 1 + dict.__setitem__( + self, + key, + Section( + self, + new_depth, + self.main, + indict=value, + name=key)) + else: + if key not in self: + self.scalars.append(key) + if not self.main.stringify: + if isinstance(value, basestring): + pass + elif isinstance(value, (list, tuple)): + for entry in value: + if not isinstance(entry, basestring): + raise TypeError('Value is not a string "%s".' % entry) + else: + raise TypeError('Value is not a string "%s".' % value) + dict.__setitem__(self, key, value) + + + def __delitem__(self, key): + """Remove items from the sequence when deleting.""" + dict. __delitem__(self, key) + if key in self.scalars: + self.scalars.remove(key) + else: + self.sections.remove(key) + del self.comments[key] + del self.inline_comments[key] + + + def get(self, key, default=None): + """A version of ``get`` that doesn't bypass string interpolation.""" + try: + return self[key] + except KeyError: + return default + + + def update(self, indict): + """ + A version of update that uses our ``__setitem__``. + """ + for entry in indict: + self[entry] = indict[entry] + + + def pop(self, key, default=MISSING): + """ + 'D.pop(k[,d]) -> v, remove specified key and return the corresponding value. + If key is not found, d is returned if given, otherwise KeyError is raised' + """ + try: + val = self[key] + except KeyError: + if default is MISSING: + raise + val = default + else: + del self[key] + return val + + + def popitem(self): + """Pops the first (key,val)""" + sequence = (self.scalars + self.sections) + if not sequence: + raise KeyError(": 'popitem(): dictionary is empty'") + key = sequence[0] + val = self[key] + del self[key] + return key, val + + + def clear(self): + """ + A version of clear that also affects scalars/sections + Also clears comments and configspec. + + Leaves other attributes alone : + depth/main/parent are not affected + """ + dict.clear(self) + self.scalars = [] + self.sections = [] + self.comments = {} + self.inline_comments = {} + self.configspec = None + self.defaults = [] + self.extra_values = [] + + + def setdefault(self, key, default=None): + """A version of setdefault that sets sequence if appropriate.""" + try: + return self[key] + except KeyError: + self[key] = default + return self[key] + + + def items(self): + """D.items() -> list of D's (key, value) pairs, as 2-tuples""" + return zip((self.scalars + self.sections), self.values()) + + + def keys(self): + """D.keys() -> list of D's keys""" + return (self.scalars + self.sections) + + + def values(self): + """D.values() -> list of D's values""" + return [self[key] for key in (self.scalars + self.sections)] + + + def iteritems(self): + """D.iteritems() -> an iterator over the (key, value) items of D""" + return iter(self.items()) + + + def iterkeys(self): + """D.iterkeys() -> an iterator over the keys of D""" + return iter((self.scalars + self.sections)) + + __iter__ = iterkeys + + + def itervalues(self): + """D.itervalues() -> an iterator over the values of D""" + return iter(self.values()) + + + def __repr__(self): + """x.__repr__() <==> repr(x)""" + def _getval(key): + try: + return self[key] + except MissingInterpolationOption: + return dict.__getitem__(self, key) + return '{%s}' % ', '.join([('%s: %s' % (repr(key), repr(_getval(key)))) + for key in (self.scalars + self.sections)]) + + __str__ = __repr__ + __str__.__doc__ = "x.__str__() <==> str(x)" + + + # Extra methods - not in a normal dictionary + + def dict(self): + """ + Return a deepcopy of self as a dictionary. + + All members that are ``Section`` instances are recursively turned to + ordinary dictionaries - by calling their ``dict`` method. + + >>> n = a.dict() + >>> n == a + 1 + >>> n is a + 0 + """ + newdict = {} + for entry in self: + this_entry = self[entry] + if isinstance(this_entry, Section): + this_entry = this_entry.dict() + elif isinstance(this_entry, list): + # create a copy rather than a reference + this_entry = list(this_entry) + elif isinstance(this_entry, tuple): + # create a copy rather than a reference + this_entry = tuple(this_entry) + newdict[entry] = this_entry + return newdict + + + def merge(self, indict): + """ + A recursive update - useful for merging config files. + + >>> a = '''[section1] + ... option1 = True + ... [[subsection]] + ... more_options = False + ... # end of file'''.splitlines() + >>> b = '''# File is user.ini + ... [section1] + ... option1 = False + ... # end of file'''.splitlines() + >>> c1 = ConfigObj(b) + >>> c2 = ConfigObj(a) + >>> c2.merge(c1) + >>> c2 + ConfigObj({'section1': {'option1': 'False', 'subsection': {'more_options': 'False'}}}) + """ + for key, val in indict.items(): + if (key in self and isinstance(self[key], dict) and + isinstance(val, dict)): + self[key].merge(val) + else: + self[key] = val + + + def rename(self, oldkey, newkey): + """ + Change a keyname to another, without changing position in sequence. + + Implemented so that transformations can be made on keys, + as well as on values. (used by encode and decode) + + Also renames comments. + """ + if oldkey in self.scalars: + the_list = self.scalars + elif oldkey in self.sections: + the_list = self.sections + else: + raise KeyError('Key "%s" not found.' % oldkey) + pos = the_list.index(oldkey) + # + val = self[oldkey] + dict.__delitem__(self, oldkey) + dict.__setitem__(self, newkey, val) + the_list.remove(oldkey) + the_list.insert(pos, newkey) + comm = self.comments[oldkey] + inline_comment = self.inline_comments[oldkey] + del self.comments[oldkey] + del self.inline_comments[oldkey] + self.comments[newkey] = comm + self.inline_comments[newkey] = inline_comment + + + def walk(self, function, raise_errors=True, + call_on_sections=False, **keywargs): + """ + Walk every member and call a function on the keyword and value. + + Return a dictionary of the return values + + If the function raises an exception, raise the errror + unless ``raise_errors=False``, in which case set the return value to + ``False``. + + Any unrecognised keyword arguments you pass to walk, will be pased on + to the function you pass in. + + Note: if ``call_on_sections`` is ``True`` then - on encountering a + subsection, *first* the function is called for the *whole* subsection, + and then recurses into it's members. This means your function must be + able to handle strings, dictionaries and lists. This allows you + to change the key of subsections as well as for ordinary members. The + return value when called on the whole subsection has to be discarded. + + See the encode and decode methods for examples, including functions. + + .. admonition:: caution + + You can use ``walk`` to transform the names of members of a section + but you mustn't add or delete members. + + >>> config = '''[XXXXsection] + ... XXXXkey = XXXXvalue'''.splitlines() + >>> cfg = ConfigObj(config) + >>> cfg + ConfigObj({'XXXXsection': {'XXXXkey': 'XXXXvalue'}}) + >>> def transform(section, key): + ... val = section[key] + ... newkey = key.replace('XXXX', 'CLIENT1') + ... section.rename(key, newkey) + ... if isinstance(val, (tuple, list, dict)): + ... pass + ... else: + ... val = val.replace('XXXX', 'CLIENT1') + ... section[newkey] = val + >>> cfg.walk(transform, call_on_sections=True) + {'CLIENT1section': {'CLIENT1key': None}} + >>> cfg + ConfigObj({'CLIENT1section': {'CLIENT1key': 'CLIENT1value'}}) + """ + out = {} + # scalars first + for i in range(len(self.scalars)): + entry = self.scalars[i] + try: + val = function(self, entry, **keywargs) + # bound again in case name has changed + entry = self.scalars[i] + out[entry] = val + except Exception: + if raise_errors: + raise + else: + entry = self.scalars[i] + out[entry] = False + # then sections + for i in range(len(self.sections)): + entry = self.sections[i] + if call_on_sections: + try: + function(self, entry, **keywargs) + except Exception: + if raise_errors: + raise + else: + entry = self.sections[i] + out[entry] = False + # bound again in case name has changed + entry = self.sections[i] + # previous result is discarded + out[entry] = self[entry].walk( + function, + raise_errors=raise_errors, + call_on_sections=call_on_sections, + **keywargs) + return out + + + def as_bool(self, key): + """ + Accepts a key as input. The corresponding value must be a string or + the objects (``True`` or 1) or (``False`` or 0). We allow 0 and 1 to + retain compatibility with Python 2.2. + + If the string is one of ``True``, ``On``, ``Yes``, or ``1`` it returns + ``True``. + + If the string is one of ``False``, ``Off``, ``No``, or ``0`` it returns + ``False``. + + ``as_bool`` is not case sensitive. + + Any other input will raise a ``ValueError``. + + >>> a = ConfigObj() + >>> a['a'] = 'fish' + >>> a.as_bool('a') + Traceback (most recent call last): + ValueError: Value "fish" is neither True nor False + >>> a['b'] = 'True' + >>> a.as_bool('b') + 1 + >>> a['b'] = 'off' + >>> a.as_bool('b') + 0 + """ + val = self[key] + if val == True: + return True + elif val == False: + return False + else: + try: + if not isinstance(val, basestring): + # TODO: Why do we raise a KeyError here? + raise KeyError() + else: + return self.main._bools[val.lower()] + except KeyError: + raise ValueError('Value "%s" is neither True nor False' % val) + + + def as_int(self, key): + """ + A convenience method which coerces the specified value to an integer. + + If the value is an invalid literal for ``int``, a ``ValueError`` will + be raised. + + >>> a = ConfigObj() + >>> a['a'] = 'fish' + >>> a.as_int('a') + Traceback (most recent call last): + ValueError: invalid literal for int() with base 10: 'fish' + >>> a['b'] = '1' + >>> a.as_int('b') + 1 + >>> a['b'] = '3.2' + >>> a.as_int('b') + Traceback (most recent call last): + ValueError: invalid literal for int() with base 10: '3.2' + """ + return int(self[key]) + + + def as_float(self, key): + """ + A convenience method which coerces the specified value to a float. + + If the value is an invalid literal for ``float``, a ``ValueError`` will + be raised. + + >>> a = ConfigObj() + >>> a['a'] = 'fish' + >>> a.as_float('a') + Traceback (most recent call last): + ValueError: invalid literal for float(): fish + >>> a['b'] = '1' + >>> a.as_float('b') + 1.0 + >>> a['b'] = '3.2' + >>> a.as_float('b') + 3.2000000000000002 + """ + return float(self[key]) + + + def as_list(self, key): + """ + A convenience method which fetches the specified value, guaranteeing + that it is a list. + + >>> a = ConfigObj() + >>> a['a'] = 1 + >>> a.as_list('a') + [1] + >>> a['a'] = (1,) + >>> a.as_list('a') + [1] + >>> a['a'] = [1] + >>> a.as_list('a') + [1] + """ + result = self[key] + if isinstance(result, (tuple, list)): + return list(result) + return [result] + + + def restore_default(self, key): + """ + Restore (and return) default value for the specified key. + + This method will only work for a ConfigObj that was created + with a configspec and has been validated. + + If there is no default value for this key, ``KeyError`` is raised. + """ + default = self.default_values[key] + dict.__setitem__(self, key, default) + if key not in self.defaults: + self.defaults.append(key) + return default + + + def restore_defaults(self): + """ + Recursively restore default values to all members + that have them. + + This method will only work for a ConfigObj that was created + with a configspec and has been validated. + + It doesn't delete or modify entries without default values. + """ + for key in self.default_values: + self.restore_default(key) + + for section in self.sections: + self[section].restore_defaults() + + +class ConfigObj(Section): + """An object to read, create, and write config files.""" + + _keyword = re.compile(r'''^ # line start + (\s*) # indentation + ( # keyword + (?:".*?")| # double quotes + (?:'.*?')| # single quotes + (?:[^'"=].*?) # no quotes + ) + \s*=\s* # divider + (.*) # value (including list values and comments) + $ # line end + ''', + re.VERBOSE) + + _sectionmarker = re.compile(r'''^ + (\s*) # 1: indentation + ((?:\[\s*)+) # 2: section marker open + ( # 3: section name open + (?:"\s*\S.*?\s*")| # at least one non-space with double quotes + (?:'\s*\S.*?\s*')| # at least one non-space with single quotes + (?:[^'"\s].*?) # at least one non-space unquoted + ) # section name close + ((?:\s*\])+) # 4: section marker close + \s*(\#.*)? # 5: optional comment + $''', + re.VERBOSE) + + # this regexp pulls list values out as a single string + # or single values and comments + # FIXME: this regex adds a '' to the end of comma terminated lists + # workaround in ``_handle_value`` + _valueexp = re.compile(r'''^ + (?: + (?: + ( + (?: + (?: + (?:".*?")| # double quotes + (?:'.*?')| # single quotes + (?:[^'",\#][^,\#]*?) # unquoted + ) + \s*,\s* # comma + )* # match all list items ending in a comma (if any) + ) + ( + (?:".*?")| # double quotes + (?:'.*?')| # single quotes + (?:[^'",\#\s][^,]*?)| # unquoted + (?:(? 1: + msg = "Parsing failed with several errors.\nFirst error %s" % info + error = ConfigObjError(msg) + else: + error = self._errors[0] + # set the errors attribute; it's a list of tuples: + # (error_type, message, line_number) + error.errors = self._errors + # set the config attribute + error.config = self + raise error + # delete private attributes + del self._errors + + if configspec is None: + self.configspec = None + else: + self._handle_configspec(configspec) + + + def _initialise(self, options=None): + if options is None: + options = OPTION_DEFAULTS + + # initialise a few variables + self.filename = None + self._errors = [] + self.raise_errors = options['raise_errors'] + self.interpolation = options['interpolation'] + self.list_values = options['list_values'] + self.create_empty = options['create_empty'] + self.file_error = options['file_error'] + self.stringify = options['stringify'] + self.indent_type = options['indent_type'] + self.encoding = options['encoding'] + self.default_encoding = options['default_encoding'] + self.BOM = False + self.newlines = None + self.write_empty_values = options['write_empty_values'] + self.unrepr = options['unrepr'] + + self.initial_comment = [] + self.final_comment = [] + self.configspec = None + + if self._inspec: + self.list_values = False + + # Clear section attributes as well + Section._initialise(self) + + + def __repr__(self): + def _getval(key): + try: + return self[key] + except MissingInterpolationOption: + return dict.__getitem__(self, key) + return ('ConfigObj({%s})' % + ', '.join([('%s: %s' % (repr(key), repr(_getval(key)))) + for key in (self.scalars + self.sections)])) + + + def _handle_bom(self, infile): + """ + Handle any BOM, and decode if necessary. + + If an encoding is specified, that *must* be used - but the BOM should + still be removed (and the BOM attribute set). + + (If the encoding is wrongly specified, then a BOM for an alternative + encoding won't be discovered or removed.) + + If an encoding is not specified, UTF8 or UTF16 BOM will be detected and + removed. The BOM attribute will be set. UTF16 will be decoded to + unicode. + + NOTE: This method must not be called with an empty ``infile``. + + Specifying the *wrong* encoding is likely to cause a + ``UnicodeDecodeError``. + + ``infile`` must always be returned as a list of lines, but may be + passed in as a single string. + """ + if ((self.encoding is not None) and + (self.encoding.lower() not in BOM_LIST)): + # No need to check for a BOM + # the encoding specified doesn't have one + # just decode + return self._decode(infile, self.encoding) + + if isinstance(infile, (list, tuple)): + line = infile[0] + else: + line = infile + if self.encoding is not None: + # encoding explicitly supplied + # And it could have an associated BOM + # TODO: if encoding is just UTF16 - we ought to check for both + # TODO: big endian and little endian versions. + enc = BOM_LIST[self.encoding.lower()] + if enc == 'utf_16': + # For UTF16 we try big endian and little endian + for BOM, (encoding, final_encoding) in BOMS.items(): + if not final_encoding: + # skip UTF8 + continue + if infile.startswith(BOM): + ### BOM discovered + ##self.BOM = True + # Don't need to remove BOM + return self._decode(infile, encoding) + + # If we get this far, will *probably* raise a DecodeError + # As it doesn't appear to start with a BOM + return self._decode(infile, self.encoding) + + # Must be UTF8 + BOM = BOM_SET[enc] + if not line.startswith(BOM): + return self._decode(infile, self.encoding) + + newline = line[len(BOM):] + + # BOM removed + if isinstance(infile, (list, tuple)): + infile[0] = newline + else: + infile = newline + self.BOM = True + return self._decode(infile, self.encoding) + + # No encoding specified - so we need to check for UTF8/UTF16 + for BOM, (encoding, final_encoding) in BOMS.items(): + if not line.startswith(BOM): + continue + else: + # BOM discovered + self.encoding = final_encoding + if not final_encoding: + self.BOM = True + # UTF8 + # remove BOM + newline = line[len(BOM):] + if isinstance(infile, (list, tuple)): + infile[0] = newline + else: + infile = newline + # UTF8 - don't decode + if isinstance(infile, basestring): + return infile.splitlines(True) + else: + return infile + # UTF16 - have to decode + return self._decode(infile, encoding) + + # No BOM discovered and no encoding specified, just return + if isinstance(infile, basestring): + # infile read from a file will be a single string + return infile.splitlines(True) + return infile + + + def _a_to_u(self, aString): + """Decode ASCII strings to unicode if a self.encoding is specified.""" + if self.encoding: + return aString.decode('ascii') + else: + return aString + + + def _decode(self, infile, encoding): + """ + Decode infile to unicode. Using the specified encoding. + + if is a string, it also needs converting to a list. + """ + if isinstance(infile, basestring): + # can't be unicode + # NOTE: Could raise a ``UnicodeDecodeError`` + return infile.decode(encoding).splitlines(True) + for i, line in enumerate(infile): + if not isinstance(line, unicode): + # NOTE: The isinstance test here handles mixed lists of unicode/string + # NOTE: But the decode will break on any non-string values + # NOTE: Or could raise a ``UnicodeDecodeError`` + infile[i] = line.decode(encoding) + return infile + + + def _decode_element(self, line): + """Decode element to unicode if necessary.""" + if not self.encoding: + return line + if isinstance(line, str) and self.default_encoding: + return line.decode(self.default_encoding) + return line + + + def _str(self, value): + """ + Used by ``stringify`` within validate, to turn non-string values + into strings. + """ + if not isinstance(value, basestring): + return str(value) + else: + return value + + + def _parse(self, infile): + """Actually parse the config file.""" + temp_list_values = self.list_values + if self.unrepr: + self.list_values = False + + comment_list = [] + done_start = False + this_section = self + maxline = len(infile) - 1 + cur_index = -1 + reset_comment = False + + while cur_index < maxline: + if reset_comment: + comment_list = [] + cur_index += 1 + line = infile[cur_index] + sline = line.strip() + # do we have anything on the line ? + if not sline or sline.startswith('#'): + reset_comment = False + comment_list.append(line) + continue + + if not done_start: + # preserve initial comment + self.initial_comment = comment_list + comment_list = [] + done_start = True + + reset_comment = True + # first we check if it's a section marker + mat = self._sectionmarker.match(line) + if mat is not None: + # is a section line + (indent, sect_open, sect_name, sect_close, comment) = mat.groups() + if indent and (self.indent_type is None): + self.indent_type = indent + cur_depth = sect_open.count('[') + if cur_depth != sect_close.count(']'): + self._handle_error("Cannot compute the section depth at line %s.", + NestingError, infile, cur_index) + continue + + if cur_depth < this_section.depth: + # the new section is dropping back to a previous level + try: + parent = self._match_depth(this_section, + cur_depth).parent + except SyntaxError: + self._handle_error("Cannot compute nesting level at line %s.", + NestingError, infile, cur_index) + continue + elif cur_depth == this_section.depth: + # the new section is a sibling of the current section + parent = this_section.parent + elif cur_depth == this_section.depth + 1: + # the new section is a child the current section + parent = this_section + else: + self._handle_error("Section too nested at line %s.", + NestingError, infile, cur_index) + + sect_name = self._unquote(sect_name) + if sect_name in parent: + self._handle_error('Duplicate section name at line %s.', + DuplicateError, infile, cur_index) + continue + + # create the new section + this_section = Section( + parent, + cur_depth, + self, + name=sect_name) + parent[sect_name] = this_section + parent.inline_comments[sect_name] = comment + parent.comments[sect_name] = comment_list + continue + # + # it's not a section marker, + # so it should be a valid ``key = value`` line + mat = self._keyword.match(line) + if mat is None: + # it neither matched as a keyword + # or a section marker + self._handle_error( + 'Invalid line at line "%s".', + ParseError, infile, cur_index) + else: + # is a keyword value + # value will include any inline comment + (indent, key, value) = mat.groups() + if indent and (self.indent_type is None): + self.indent_type = indent + # check for a multiline value + if value[:3] in ['"""', "'''"]: + try: + value, comment, cur_index = self._multiline( + value, infile, cur_index, maxline) + except SyntaxError: + self._handle_error( + 'Parse error in value at line %s.', + ParseError, infile, cur_index) + continue + else: + if self.unrepr: + comment = '' + try: + value = unrepr(value) + except Exception, e: + if type(e) == UnknownType: + msg = 'Unknown name or type in value at line %s.' + else: + msg = 'Parse error in value at line %s.' + self._handle_error(msg, UnreprError, infile, + cur_index) + continue + else: + if self.unrepr: + comment = '' + try: + value = unrepr(value) + except Exception, e: + if isinstance(e, UnknownType): + msg = 'Unknown name or type in value at line %s.' + else: + msg = 'Parse error in value at line %s.' + self._handle_error(msg, UnreprError, infile, + cur_index) + continue + else: + # extract comment and lists + try: + (value, comment) = self._handle_value(value) + except SyntaxError: + self._handle_error( + 'Parse error in value at line %s.', + ParseError, infile, cur_index) + continue + # + key = self._unquote(key) + if key in this_section: + self._handle_error( + 'Duplicate keyword name at line %s.', + DuplicateError, infile, cur_index) + continue + # add the key. + # we set unrepr because if we have got this far we will never + # be creating a new section + this_section.__setitem__(key, value, unrepr=True) + this_section.inline_comments[key] = comment + this_section.comments[key] = comment_list + continue + # + if self.indent_type is None: + # no indentation used, set the type accordingly + self.indent_type = '' + + # preserve the final comment + if not self and not self.initial_comment: + self.initial_comment = comment_list + elif not reset_comment: + self.final_comment = comment_list + self.list_values = temp_list_values + + + def _match_depth(self, sect, depth): + """ + Given a section and a depth level, walk back through the sections + parents to see if the depth level matches a previous section. + + Return a reference to the right section, + or raise a SyntaxError. + """ + while depth < sect.depth: + if sect is sect.parent: + # we've reached the top level already + raise SyntaxError() + sect = sect.parent + if sect.depth == depth: + return sect + # shouldn't get here + raise SyntaxError() + + + def _handle_error(self, text, ErrorClass, infile, cur_index): + """ + Handle an error according to the error settings. + + Either raise the error or store it. + The error will have occured at ``cur_index`` + """ + line = infile[cur_index] + cur_index += 1 + message = text % cur_index + error = ErrorClass(message, cur_index, line) + if self.raise_errors: + # raise the error - parsing stops here + raise error + # store the error + # reraise when parsing has finished + self._errors.append(error) + + + def _unquote(self, value): + """Return an unquoted version of a value""" + if not value: + # should only happen during parsing of lists + raise SyntaxError + if (value[0] == value[-1]) and (value[0] in ('"', "'")): + value = value[1:-1] + return value + + + def _quote(self, value, multiline=True): + """ + Return a safely quoted version of a value. + + Raise a ConfigObjError if the value cannot be safely quoted. + If multiline is ``True`` (default) then use triple quotes + if necessary. + + * Don't quote values that don't need it. + * Recursively quote members of a list and return a comma joined list. + * Multiline is ``False`` for lists. + * Obey list syntax for empty and single member lists. + + If ``list_values=False`` then the value is only quoted if it contains + a ``\\n`` (is multiline) or '#'. + + If ``write_empty_values`` is set, and the value is an empty string, it + won't be quoted. + """ + if multiline and self.write_empty_values and value == '': + # Only if multiline is set, so that it is used for values not + # keys, and not values that are part of a list + return '' + + if multiline and isinstance(value, (list, tuple)): + if not value: + return ',' + elif len(value) == 1: + return self._quote(value[0], multiline=False) + ',' + return ', '.join([self._quote(val, multiline=False) + for val in value]) + if not isinstance(value, basestring): + if self.stringify: + value = str(value) + else: + raise TypeError('Value "%s" is not a string.' % value) + + if not value: + return '""' + + no_lists_no_quotes = not self.list_values and '\n' not in value and '#' not in value + need_triple = multiline and ((("'" in value) and ('"' in value)) or ('\n' in value )) + hash_triple_quote = multiline and not need_triple and ("'" in value) and ('"' in value) and ('#' in value) + check_for_single = (no_lists_no_quotes or not need_triple) and not hash_triple_quote + + if check_for_single: + if not self.list_values: + # we don't quote if ``list_values=False`` + quot = noquot + # for normal values either single or double quotes will do + elif '\n' in value: + # will only happen if multiline is off - e.g. '\n' in key + raise ConfigObjError('Value "%s" cannot be safely quoted.' % value) + elif ((value[0] not in wspace_plus) and + (value[-1] not in wspace_plus) and + (',' not in value)): + quot = noquot + else: + quot = self._get_single_quote(value) + else: + # if value has '\n' or "'" *and* '"', it will need triple quotes + quot = self._get_triple_quote(value) + + if quot == noquot and '#' in value and self.list_values: + quot = self._get_single_quote(value) + + return quot % value + + + def _get_single_quote(self, value): + if ("'" in value) and ('"' in value): + raise ConfigObjError('Value "%s" cannot be safely quoted.' % value) + elif '"' in value: + quot = squot + else: + quot = dquot + return quot + + + def _get_triple_quote(self, value): + if (value.find('"""') != -1) and (value.find("'''") != -1): + raise ConfigObjError('Value "%s" cannot be safely quoted.' % value) + if value.find('"""') == -1: + quot = tdquot + else: + quot = tsquot + return quot + + + def _handle_value(self, value): + """ + Given a value string, unquote, remove comment, + handle lists. (including empty and single member lists) + """ + if self._inspec: + # Parsing a configspec so don't handle comments + return (value, '') + # do we look for lists in values ? + if not self.list_values: + mat = self._nolistvalue.match(value) + if mat is None: + raise SyntaxError() + # NOTE: we don't unquote here + return mat.groups() + # + mat = self._valueexp.match(value) + if mat is None: + # the value is badly constructed, probably badly quoted, + # or an invalid list + raise SyntaxError() + (list_values, single, empty_list, comment) = mat.groups() + if (list_values == '') and (single is None): + # change this if you want to accept empty values + raise SyntaxError() + # NOTE: note there is no error handling from here if the regex + # is wrong: then incorrect values will slip through + if empty_list is not None: + # the single comma - meaning an empty list + return ([], comment) + if single is not None: + # handle empty values + if list_values and not single: + # FIXME: the '' is a workaround because our regex now matches + # '' at the end of a list if it has a trailing comma + single = None + else: + single = single or '""' + single = self._unquote(single) + if list_values == '': + # not a list value + return (single, comment) + the_list = self._listvalueexp.findall(list_values) + the_list = [self._unquote(val) for val in the_list] + if single is not None: + the_list += [single] + return (the_list, comment) + + + def _multiline(self, value, infile, cur_index, maxline): + """Extract the value, where we are in a multiline situation.""" + quot = value[:3] + newvalue = value[3:] + single_line = self._triple_quote[quot][0] + multi_line = self._triple_quote[quot][1] + mat = single_line.match(value) + if mat is not None: + retval = list(mat.groups()) + retval.append(cur_index) + return retval + elif newvalue.find(quot) != -1: + # somehow the triple quote is missing + raise SyntaxError() + # + while cur_index < maxline: + cur_index += 1 + newvalue += '\n' + line = infile[cur_index] + if line.find(quot) == -1: + newvalue += line + else: + # end of multiline, process it + break + else: + # we've got to the end of the config, oops... + raise SyntaxError() + mat = multi_line.match(line) + if mat is None: + # a badly formed line + raise SyntaxError() + (value, comment) = mat.groups() + return (newvalue + value, comment, cur_index) + + + def _handle_configspec(self, configspec): + """Parse the configspec.""" + # FIXME: Should we check that the configspec was created with the + # correct settings ? (i.e. ``list_values=False``) + if not isinstance(configspec, ConfigObj): + try: + configspec = ConfigObj(configspec, + raise_errors=True, + file_error=True, + _inspec=True) + except ConfigObjError, e: + # FIXME: Should these errors have a reference + # to the already parsed ConfigObj ? + raise ConfigspecError('Parsing configspec failed: %s' % e) + except IOError, e: + raise IOError('Reading configspec failed: %s' % e) + + self.configspec = configspec + + + + def _set_configspec(self, section, copy): + """ + Called by validate. Handles setting the configspec on subsections + including sections to be validated by __many__ + """ + configspec = section.configspec + many = configspec.get('__many__') + if isinstance(many, dict): + for entry in section.sections: + if entry not in configspec: + section[entry].configspec = many + + for entry in configspec.sections: + if entry == '__many__': + continue + if entry not in section: + section[entry] = {} + section[entry]._created = True + if copy: + # copy comments + section.comments[entry] = configspec.comments.get(entry, []) + section.inline_comments[entry] = configspec.inline_comments.get(entry, '') + + # Could be a scalar when we expect a section + if isinstance(section[entry], Section): + section[entry].configspec = configspec[entry] + + + def _write_line(self, indent_string, entry, this_entry, comment): + """Write an individual line, for the write method""" + # NOTE: the calls to self._quote here handles non-StringType values. + if not self.unrepr: + val = self._decode_element(self._quote(this_entry)) + else: + val = repr(this_entry) + return '%s%s%s%s%s' % (indent_string, + self._decode_element(self._quote(entry, multiline=False)), + self._a_to_u(' = '), + val, + self._decode_element(comment)) + + + def _write_marker(self, indent_string, depth, entry, comment): + """Write a section marker line""" + return '%s%s%s%s%s' % (indent_string, + self._a_to_u('[' * depth), + self._quote(self._decode_element(entry), multiline=False), + self._a_to_u(']' * depth), + self._decode_element(comment)) + + + def _handle_comment(self, comment): + """Deal with a comment.""" + if not comment: + return '' + start = self.indent_type + if not comment.startswith('#'): + start += self._a_to_u(' # ') + return (start + comment) + + + # Public methods + + def write(self, outfile=None, section=None): + """ + Write the current ConfigObj as a file + + tekNico: FIXME: use StringIO instead of real files + + >>> filename = a.filename + >>> a.filename = 'test.ini' + >>> a.write() + >>> a.filename = filename + >>> a == ConfigObj('test.ini', raise_errors=True) + 1 + >>> import os + >>> os.remove('test.ini') + """ + if self.indent_type is None: + # this can be true if initialised from a dictionary + self.indent_type = DEFAULT_INDENT_TYPE + + out = [] + cs = self._a_to_u('#') + csp = self._a_to_u('# ') + if section is None: + int_val = self.interpolation + self.interpolation = False + section = self + for line in self.initial_comment: + line = self._decode_element(line) + stripped_line = line.strip() + if stripped_line and not stripped_line.startswith(cs): + line = csp + line + out.append(line) + + indent_string = self.indent_type * section.depth + for entry in (section.scalars + section.sections): + if entry in section.defaults: + # don't write out default values + continue + for comment_line in section.comments[entry]: + comment_line = self._decode_element(comment_line.lstrip()) + if comment_line and not comment_line.startswith(cs): + comment_line = csp + comment_line + out.append(indent_string + comment_line) + this_entry = section[entry] + comment = self._handle_comment(section.inline_comments[entry]) + + if isinstance(this_entry, dict): + # a section + out.append(self._write_marker( + indent_string, + this_entry.depth, + entry, + comment)) + out.extend(self.write(section=this_entry)) + else: + out.append(self._write_line( + indent_string, + entry, + this_entry, + comment)) + + if section is self: + for line in self.final_comment: + line = self._decode_element(line) + stripped_line = line.strip() + if stripped_line and not stripped_line.startswith(cs): + line = csp + line + out.append(line) + self.interpolation = int_val + + if section is not self: + return out + + if (self.filename is None) and (outfile is None): + # output a list of lines + # might need to encode + # NOTE: This will *screw* UTF16, each line will start with the BOM + if self.encoding: + out = [l.encode(self.encoding) for l in out] + if (self.BOM and ((self.encoding is None) or + (BOM_LIST.get(self.encoding.lower()) == 'utf_8'))): + # Add the UTF8 BOM + if not out: + out.append('') + out[0] = BOM_UTF8 + out[0] + return out + + # Turn the list to a string, joined with correct newlines + newline = self.newlines or os.linesep + if (getattr(outfile, 'mode', None) is not None and outfile.mode == 'w' + and sys.platform == 'win32' and newline == '\r\n'): + # Windows specific hack to avoid writing '\r\r\n' + newline = '\n' + output = self._a_to_u(newline).join(out) + if self.encoding: + output = output.encode(self.encoding) + if self.BOM and ((self.encoding is None) or match_utf8(self.encoding)): + # Add the UTF8 BOM + output = BOM_UTF8 + output + + if not output.endswith(newline): + output += newline + if outfile is not None: + outfile.write(output) + else: + h = open(self.filename, 'wb') + h.write(output) + h.close() + + + def validate(self, validator, preserve_errors=False, copy=False, + section=None): + """ + Test the ConfigObj against a configspec. + + It uses the ``validator`` object from *validate.py*. + + To run ``validate`` on the current ConfigObj, call: :: + + test = config.validate(validator) + + (Normally having previously passed in the configspec when the ConfigObj + was created - you can dynamically assign a dictionary of checks to the + ``configspec`` attribute of a section though). + + It returns ``True`` if everything passes, or a dictionary of + pass/fails (True/False). If every member of a subsection passes, it + will just have the value ``True``. (It also returns ``False`` if all + members fail). + + In addition, it converts the values from strings to their native + types if their checks pass (and ``stringify`` is set). + + If ``preserve_errors`` is ``True`` (``False`` is default) then instead + of a marking a fail with a ``False``, it will preserve the actual + exception object. This can contain info about the reason for failure. + For example the ``VdtValueTooSmallError`` indicates that the value + supplied was too small. If a value (or section) is missing it will + still be marked as ``False``. + + You must have the validate module to use ``preserve_errors=True``. + + You can then use the ``flatten_errors`` function to turn your nested + results dictionary into a flattened list of failures - useful for + displaying meaningful error messages. + """ + if section is None: + if self.configspec is None: + raise ValueError('No configspec supplied.') + if preserve_errors: + # We do this once to remove a top level dependency on the validate module + # Which makes importing configobj faster + from validate import VdtMissingValue + self._vdtMissingValue = VdtMissingValue + + section = self + + if copy: + section.initial_comment = section.configspec.initial_comment + section.final_comment = section.configspec.final_comment + section.encoding = section.configspec.encoding + section.BOM = section.configspec.BOM + section.newlines = section.configspec.newlines + section.indent_type = section.configspec.indent_type + + # + # section.default_values.clear() #?? + configspec = section.configspec + self._set_configspec(section, copy) + + + def validate_entry(entry, spec, val, missing, ret_true, ret_false): + section.default_values.pop(entry, None) + + try: + section.default_values[entry] = validator.get_default_value(configspec[entry]) + except (KeyError, AttributeError, validator.baseErrorClass): + # No default, bad default or validator has no 'get_default_value' + # (e.g. SimpleVal) + pass + + try: + check = validator.check(spec, + val, + missing=missing + ) + except validator.baseErrorClass, e: + if not preserve_errors or isinstance(e, self._vdtMissingValue): + out[entry] = False + else: + # preserve the error + out[entry] = e + ret_false = False + ret_true = False + else: + ret_false = False + out[entry] = True + if self.stringify or missing: + # if we are doing type conversion + # or the value is a supplied default + if not self.stringify: + if isinstance(check, (list, tuple)): + # preserve lists + check = [self._str(item) for item in check] + elif missing and check is None: + # convert the None from a default to a '' + check = '' + else: + check = self._str(check) + if (check != val) or missing: + section[entry] = check + if not copy and missing and entry not in section.defaults: + section.defaults.append(entry) + return ret_true, ret_false + + # + out = {} + ret_true = True + ret_false = True + + unvalidated = [k for k in section.scalars if k not in configspec] + incorrect_sections = [k for k in configspec.sections if k in section.scalars] + incorrect_scalars = [k for k in configspec.scalars if k in section.sections] + + for entry in configspec.scalars: + if entry in ('__many__', '___many___'): + # reserved names + continue + if (not entry in section.scalars) or (entry in section.defaults): + # missing entries + # or entries from defaults + missing = True + val = None + if copy and entry not in section.scalars: + # copy comments + section.comments[entry] = ( + configspec.comments.get(entry, [])) + section.inline_comments[entry] = ( + configspec.inline_comments.get(entry, '')) + # + else: + missing = False + val = section[entry] + + ret_true, ret_false = validate_entry(entry, configspec[entry], val, + missing, ret_true, ret_false) + + many = None + if '__many__' in configspec.scalars: + many = configspec['__many__'] + elif '___many___' in configspec.scalars: + many = configspec['___many___'] + + if many is not None: + for entry in unvalidated: + val = section[entry] + ret_true, ret_false = validate_entry(entry, many, val, False, + ret_true, ret_false) + unvalidated = [] + + for entry in incorrect_scalars: + ret_true = False + if not preserve_errors: + out[entry] = False + else: + ret_false = False + msg = 'Value %r was provided as a section' % entry + out[entry] = validator.baseErrorClass(msg) + for entry in incorrect_sections: + ret_true = False + if not preserve_errors: + out[entry] = False + else: + ret_false = False + msg = 'Section %r was provided as a single value' % entry + out[entry] = validator.baseErrorClass(msg) + + # Missing sections will have been created as empty ones when the + # configspec was read. + for entry in section.sections: + # FIXME: this means DEFAULT is not copied in copy mode + if section is self and entry == 'DEFAULT': + continue + if section[entry].configspec is None: + unvalidated.append(entry) + continue + if copy: + section.comments[entry] = configspec.comments.get(entry, []) + section.inline_comments[entry] = configspec.inline_comments.get(entry, '') + check = self.validate(validator, preserve_errors=preserve_errors, copy=copy, section=section[entry]) + out[entry] = check + if check == False: + ret_true = False + elif check == True: + ret_false = False + else: + ret_true = False + + section.extra_values = unvalidated + if preserve_errors and not section._created: + # If the section wasn't created (i.e. it wasn't missing) + # then we can't return False, we need to preserve errors + ret_false = False + # + if ret_false and preserve_errors and out: + # If we are preserving errors, but all + # the failures are from missing sections / values + # then we can return False. Otherwise there is a + # real failure that we need to preserve. + ret_false = not any(out.values()) + if ret_true: + return True + elif ret_false: + return False + return out + + + def reset(self): + """Clear ConfigObj instance and restore to 'freshly created' state.""" + self.clear() + self._initialise() + # FIXME: Should be done by '_initialise', but ConfigObj constructor (and reload) + # requires an empty dictionary + self.configspec = None + # Just to be sure ;-) + self._original_configspec = None + + + def reload(self): + """ + Reload a ConfigObj from file. + + This method raises a ``ReloadError`` if the ConfigObj doesn't have + a filename attribute pointing to a file. + """ + if not isinstance(self.filename, basestring): + raise ReloadError() + + filename = self.filename + current_options = {} + for entry in OPTION_DEFAULTS: + if entry == 'configspec': + continue + current_options[entry] = getattr(self, entry) + + configspec = self._original_configspec + current_options['configspec'] = configspec + + self.clear() + self._initialise(current_options) + self._load(filename, configspec) + + + +class SimpleVal(object): + """ + A simple validator. + Can be used to check that all members expected are present. + + To use it, provide a configspec with all your members in (the value given + will be ignored). Pass an instance of ``SimpleVal`` to the ``validate`` + method of your ``ConfigObj``. ``validate`` will return ``True`` if all + members are present, or a dictionary with True/False meaning + present/missing. (Whole missing sections will be replaced with ``False``) + """ + + def __init__(self): + self.baseErrorClass = ConfigObjError + + def check(self, check, member, missing=False): + """A dummy check method, always returns the value unchanged.""" + if missing: + raise self.baseErrorClass() + return member + + +def flatten_errors(cfg, res, levels=None, results=None): + """ + An example function that will turn a nested dictionary of results + (as returned by ``ConfigObj.validate``) into a flat list. + + ``cfg`` is the ConfigObj instance being checked, ``res`` is the results + dictionary returned by ``validate``. + + (This is a recursive function, so you shouldn't use the ``levels`` or + ``results`` arguments - they are used by the function.) + + Returns a list of keys that failed. Each member of the list is a tuple:: + + ([list of sections...], key, result) + + If ``validate`` was called with ``preserve_errors=False`` (the default) + then ``result`` will always be ``False``. + + *list of sections* is a flattened list of sections that the key was found + in. + + If the section was missing (or a section was expected and a scalar provided + - or vice-versa) then key will be ``None``. + + If the value (or section) was missing then ``result`` will be ``False``. + + If ``validate`` was called with ``preserve_errors=True`` and a value + was present, but failed the check, then ``result`` will be the exception + object returned. You can use this as a string that describes the failure. + + For example *The value "3" is of the wrong type*. + """ + if levels is None: + # first time called + levels = [] + results = [] + if res == True: + return results + if res == False or isinstance(res, Exception): + results.append((levels[:], None, res)) + if levels: + levels.pop() + return results + for (key, val) in res.items(): + if val == True: + continue + if isinstance(cfg.get(key), dict): + # Go down one level + levels.append(key) + flatten_errors(cfg[key], val, levels, results) + continue + results.append((levels[:], key, val)) + # + # Go up one level + if levels: + levels.pop() + # + return results + + +def get_extra_values(conf, _prepend=()): + """ + Find all the values and sections not in the configspec from a validated + ConfigObj. + + ``get_extra_values`` returns a list of tuples where each tuple represents + either an extra section, or an extra value. + + The tuples contain two values, a tuple representing the section the value + is in and the name of the extra values. For extra values in the top level + section the first member will be an empty tuple. For values in the 'foo' + section the first member will be ``('foo',)``. For members in the 'bar' + subsection of the 'foo' section the first member will be ``('foo', 'bar')``. + + NOTE: If you call ``get_extra_values`` on a ConfigObj instance that hasn't + been validated it will return an empty list. + """ + out = [] + + out.extend([(_prepend, name) for name in conf.extra_values]) + for name in conf.sections: + if name not in conf.extra_values: + out.extend(get_extra_values(conf[name], _prepend + (name,))) + return out + + +"""*A programming language is a medium of expression.* - Paul Graham""" diff --git a/python/pkg/cdec/sa/__init__.py b/python/pkg/cdec/sa/__init__.py new file mode 100644 index 00000000..fd4a4148 --- /dev/null +++ b/python/pkg/cdec/sa/__init__.py @@ -0,0 +1,4 @@ +from cdec.sa._sa import sym_fromstring,\ + SuffixArray, DataArray, LCP, Precomputation, Alignment, BiLex,\ + HieroCachingRuleFactory, Sampler +from cdec.sa.extractor import GrammarExtractor diff --git a/python/pkg/cdec/sa/compile.py b/python/pkg/cdec/sa/compile.py new file mode 100644 index 00000000..30e605a6 --- /dev/null +++ b/python/pkg/cdec/sa/compile.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python +import argparse +import os +import logging +import cdec.configobj +import cdec.sa + +MAX_PHRASE_LENGTH = 4 +def precompute(f_sa, max_len, max_nt, max_size, min_gap, rank1, rank2): + lcp = cdec.sa.LCP(f_sa) + stats = sorted(lcp.compute_stats(MAX_PHRASE_LENGTH), reverse=True) + precomp = cdec.sa.Precomputation(from_stats=stats, + fsarray=f_sa, + precompute_rank=rank1, + precompute_secondary_rank=rank2, + max_length=max_len, + max_nonterminals=max_nt, + train_max_initial_size=max_size, + train_min_gap_size=min_gap) + return precomp + +def main(): + logging.basicConfig(level=logging.INFO) + logger = logging.getLogger('cdec.sa.compile') + parser = argparse.ArgumentParser(description='Compile a corpus into a suffix array.') + parser.add_argument('--maxnt', '-n', type=int, default=2, + help='Maximum number of non-terminal symbols') + parser.add_argument('--maxlen', '-l', type=int, default=5, + help='Maximum number of terminals') + parser.add_argument('--maxsize', '-s', type=int, default=15, + help='Maximum rule span') + parser.add_argument('--mingap', '-g', type=int, default=1, + help='Minimum gap size') + parser.add_argument('--rank1', '-r1', type=int, default=100, + help='Number of pre-computed frequent patterns') + parser.add_argument('--rank2', '-r2', type=int, default=10, + help='Number of pre-computed super-frequent patterns)') + parser.add_argument('-c', '--config', default='/dev/stdout', + help='Output configuration') + parser.add_argument('-o', '--output', required=True, + help='Output path') + parser.add_argument('-f', '--source', required=True, + help='Source language corpus') + parser.add_argument('-e', '--target', required=True, + help='Target language corpus') + parser.add_argument('-a', '--alignment', required=True, + help='Bitext word alignment') + args = parser.parse_args() + + param_names = ("max_len", "max_nt", "max_size", "min_gap", "rank1", "rank2") + params = (args.maxlen, args.maxnt, args.maxsize, args.mingap, args.rank1, args.rank2) + + if not os.path.exists(args.output): + os.mkdir(args.output) + + f_sa_bin = os.path.join(args.output, 'f.sa.bin') + e_bin = os.path.join(args.output, 'e.bin') + precomp_file = 'precomp.{0}.{1}.{2}.{3}.{4}.{5}.bin'.format(*params) + precomp_bin = os.path.join(args.output, precomp_file) + a_bin = os.path.join(args.output, 'a.bin') + lex_bin = os.path.join(args.output, 'lex.bin') + + logger.info('Compiling source suffix array') + f_sa = cdec.sa.SuffixArray(from_text=args.source) + f_sa.write_binary(f_sa_bin) + + logger.info('Compiling target data array') + e = cdec.sa.DataArray(from_text=args.target) + e.write_binary(e_bin) + + logger.info('Precomputing frequent phrases') + precompute(f_sa, *params).write_binary(precomp_bin) + + logger.info('Compiling alignment') + a = cdec.sa.Alignment(from_text=args.alignment) + a.write_binary(a_bin) + + logger.info('Compiling bilexical dictionary') + lex = cdec.sa.BiLex(from_data=True, alignment=a, earray=e, fsarray=f_sa) + lex.write_binary(lex_bin) + + # Write configuration + config = cdec.configobj.ConfigObj(args.config, unrepr=True) + config['f_sa_file'] = f_sa_bin + config['e_file'] = e_bin + config['a_file'] = a_bin + config['lex_file'] = lex_bin + config['precompute_file'] = precomp_bin + for name, value in zip(param_names, params): + config[name] = value + config.write() + +if __name__ == '__main__': + main() diff --git a/python/pkg/cdec/sa/extract.py b/python/pkg/cdec/sa/extract.py new file mode 100644 index 00000000..918aa3bb --- /dev/null +++ b/python/pkg/cdec/sa/extract.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +import sys +import os +import argparse +import logging +import cdec.sa + +def main(): + logging.basicConfig(level=logging.INFO) + parser = argparse.ArgumentParser(description='Extract grammars from a compiled corpus.') + parser.add_argument('-c', '--config', required=True, + help='Extractor configuration') + parser.add_argument('-g', '--grammars', required=True, + help='Grammar output path') + args = parser.parse_args() + + if not os.path.exists(args.grammars): + os.mkdir(args.grammars) + + extractor = cdec.sa.GrammarExtractor(args.config) + for i, sentence in enumerate(sys.stdin): + sentence = sentence[:-1] + grammar_file = os.path.join(args.grammars, 'grammar.{0}'.format(i)) + with open(grammar_file, 'w') as output: + for rule in extractor.grammar(sentence): + output.write(str(rule)+'\n') + grammar_file = os.path.abspath(grammar_file) + print('{1}'.format(grammar_file, sentence)) + +if __name__ == '__main__': + main() diff --git a/python/pkg/cdec/sa/extractor.py b/python/pkg/cdec/sa/extractor.py new file mode 100644 index 00000000..bb912e16 --- /dev/null +++ b/python/pkg/cdec/sa/extractor.py @@ -0,0 +1,78 @@ +from itertools import chain +import os +import cdec.configobj +from cdec.sa.features import EgivenFCoherent, SampleCountF, CountEF,\ + MaxLexEgivenF, MaxLexFgivenE, IsSingletonF, IsSingletonFE +import cdec.sa + +# maximum span of a grammar rule in TEST DATA +MAX_INITIAL_SIZE = 15 + +class GrammarExtractor: + def __init__(self, config): + if isinstance(config, str) or isinstance(config, unicode): + if not os.path.exists(config): + raise IOError('cannot read configuration from {0}'.format(config)) + config = cdec.configobj.ConfigObj(config, unrepr=True) + alignment = cdec.sa.Alignment(from_binary=config['a_file']) + self.factory = cdec.sa.HieroCachingRuleFactory( + # compiled alignment object (REQUIRED) + alignment, + # name of generic nonterminal used by Hiero + category="[X]", + # maximum number of contiguous chunks of terminal symbols in RHS of a rule + max_chunks=config['max_nt']+1, + # maximum span of a grammar rule in TEST DATA + max_initial_size=MAX_INITIAL_SIZE, + # maximum number of symbols (both T and NT) allowed in a rule + max_length=config['max_len'], + # maximum number of nonterminals allowed in a rule (set >2 at your own risk) + max_nonterminals=config['max_nt'], + # maximum number of contiguous chunks of terminal symbols + # in target-side RHS of a rule. + max_target_chunks=config['max_nt']+1, + # maximum number of target side symbols (both T and NT) allowed in a rule. + max_target_length=MAX_INITIAL_SIZE, + # minimum span of a nonterminal in the RHS of a rule in TEST DATA + min_gap_size=1, + # filename of file containing precomputed collocations + precompute_file=config['precompute_file'], + # maximum frequency rank of patterns used to compute triples (< 20) + precompute_secondary_rank=config['rank2'], + # maximum frequency rank of patterns used to compute collocations (< 300) + precompute_rank=config['rank1'], + # require extracted rules to have at least one aligned word + require_aligned_terminal=True, + # require each contiguous chunk of extracted rules + # to have at least one aligned word + require_aligned_chunks=False, + # maximum span of a grammar rule extracted from TRAINING DATA + train_max_initial_size=config['max_size'], + # minimum span of an RHS nonterminal in a rule extracted from TRAINING DATA + train_min_gap_size=config['min_gap'], + # True if phrases should be tight, False otherwise (better but slower) + tight_phrases=True, + ) + + # lexical weighting tables + tt = cdec.sa.BiLex(from_binary=config['lex_file']) + + self.models = (EgivenFCoherent, SampleCountF, CountEF, + MaxLexFgivenE(tt), MaxLexEgivenF(tt), IsSingletonF, IsSingletonFE) + + fsarray = cdec.sa.SuffixArray(from_binary=config['f_sa_file']) + edarray = cdec.sa.DataArray(from_binary=config['e_file']) + + # lower=faster, higher=better; improvements level off above 200-300 range, + # -1 = don't sample, use all data (VERY SLOW!) + sampler = cdec.sa.Sampler(300, fsarray) + + self.factory.configure(fsarray, edarray, sampler) + + def grammar(self, sentence): + if isinstance(sentence, unicode): + sentence = sentence.encode('utf8') + cnet = chain(('',), sentence.split(), ('',)) + cnet = (cdec.sa.sym_fromstring(word, terminal=True) for word in cnet) + cnet = tuple(((word, None, 1), ) for word in cnet) + return self.factory.input(cnet, self.models) diff --git a/python/pkg/cdec/sa/features.py b/python/pkg/cdec/sa/features.py new file mode 100644 index 00000000..325b9e13 --- /dev/null +++ b/python/pkg/cdec/sa/features.py @@ -0,0 +1,57 @@ +from __future__ import division +import math + +MAXSCORE = 99 + +def EgivenF(fphrase, ephrase, paircount, fcount, fsample_count): # p(e|f) + return -math.log10(paircount/fcount) + +def CountEF(fphrase, ephrase, paircount, fcount, fsample_count): + return math.log10(1 + paircount) + +def SampleCountF(fphrase, ephrase, paircount, fcount, fsample_count): + return math.log10(1 + fsample_count) + +def EgivenFCoherent(fphrase, ephrase, paircount, fcount, fsample_count): + prob = paircount/fsample_count + return -math.log10(prob) if prob > 0 else MAXSCORE + +def CoherenceProb(fphrase, ephrase, paircount, fcount, fsample_count): + return -math.log10(fcount/fsample_count) + +def MaxLexEgivenF(ttable): + def feature(fphrase, ephrase, paircount, fcount, fsample_count): + fwords = fphrase.words + fwords.append('NULL') + def score(): + for e in ephrase.words: + maxScore = max(ttable.get_score(f, e, 0) for f in fwords) + yield -math.log10(maxScore) if maxScore > 0 else MAXSCORE + return sum(score()) + return feature + +def MaxLexFgivenE(ttable): + def feature(fphrase, ephrase, paircount, fcount, fsample_count): + ewords = ephrase.words + ewords.append('NULL') + def score(): + for f in fphrase.words: + maxScore = max(ttable.get_score(f, e, 1) for e in ewords) + yield -math.log10(maxScore) if maxScore > 0 else MAXSCORE + return sum(score()) + return feature + +def IsSingletonF(fphrase, ephrase, paircount, fcount, fsample_count): + return (fcount == 1) + +def IsSingletonFE(fphrase, ephrase, paircount, fcount, fsample_count): + return (paircount == 1) + +def IsNotSingletonF(fphrase, ephrase, paircount, fcount, fsample_count): + return (fcount > 1) + +def IsNotSingletonFE(fphrase, ephrase, paircount, fcount, fsample_count): + return (paircount > 1) + +def IsFEGreaterThanZero(fphrase, ephrase, paircount, fcount, fsample_count): + return (paircount > 0.01) diff --git a/python/pkg/cdec/score.py b/python/pkg/cdec/score.py new file mode 100644 index 00000000..22257774 --- /dev/null +++ b/python/pkg/cdec/score.py @@ -0,0 +1 @@ +from _cdec import BLEU, TER, CER, Metric diff --git a/python/setup.py b/python/setup.py index 1d1d7e45..7be976e8 100644 --- a/python/setup.py +++ b/python/setup.py @@ -48,5 +48,6 @@ setup( name='cdec', ext_modules=ext_modules, requires=['configobj'], - packages=['cdec', 'cdec.sa'] + packages=['cdec', 'cdec.sa'], + package_dir={'': 'pkg'} ) diff --git a/python/src/sa/_sa.c b/python/src/sa/_sa.c index 34f170bf..b7f3627a 100644 --- a/python/src/sa/_sa.c +++ b/python/src/sa/_sa.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.17.beta1 on Fri Jul 27 22:15:31 2012 */ +/* Generated by Cython 0.17.beta1 on Fri Jul 27 23:31:04 2012 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -2013,7 +2013,7 @@ static int __pyx_pf_3_sa_8Alphabet___cinit__(struct __pyx_obj_3_sa_Alphabet *__p static void __pyx_pf_3_sa_8Alphabet_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_3_sa_Alphabet *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_3_sa_8Alphabet_9terminals___get__(struct __pyx_obj_3_sa_Alphabet *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_3_sa_8Alphabet_12nonterminals___get__(struct __pyx_obj_3_sa_Alphabet *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_3_sa_2sym_fromstring(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_string, int __pyx_v_terminal); /* proto */ +static PyObject *__pyx_pf_3_sa_2sym_fromstring(CYTHON_UNUSED PyObject *__pyx_self, char *__pyx_v_string, int __pyx_v_terminal); /* proto */ static int __pyx_pf_3_sa_6Phrase___cinit__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self, PyObject *__pyx_v_words); /* proto */ static void __pyx_pf_3_sa_6Phrase_2__dealloc__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_3_sa_6Phrase_4__str__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self); /* proto */ @@ -21750,7 +21750,7 @@ static int __pyx_f_3_sa_sym_setindex(int __pyx_v_sym, int __pyx_v_id) { * cdef int sym_setindex(int sym, int id): * return ALPHABET.setindex(sym, id) # <<<<<<<<<<<<<< * - * def sym_fromstring(bytes string, bint terminal): + * def sym_fromstring(char* string, bint terminal): */ __pyx_r = ((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_3_sa_ALPHABET->__pyx_vtab)->setindex(__pyx_v_3_sa_ALPHABET, __pyx_v_sym, __pyx_v_id); goto __pyx_L0; @@ -21765,7 +21765,7 @@ static int __pyx_f_3_sa_sym_setindex(int __pyx_v_sym, int __pyx_v_id) { static PyObject *__pyx_pw_3_sa_3sym_fromstring(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_3_sa_3sym_fromstring = {__Pyx_NAMESTR("sym_fromstring"), (PyCFunction)__pyx_pw_3_sa_3sym_fromstring, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}; static PyObject *__pyx_pw_3_sa_3sym_fromstring(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_string = 0; + char *__pyx_v_string; int __pyx_v_terminal; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations @@ -21802,7 +21802,7 @@ static PyObject *__pyx_pw_3_sa_3sym_fromstring(PyObject *__pyx_self, PyObject *_ values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } - __pyx_v_string = ((PyObject*)values[0]); + __pyx_v_string = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_string) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_terminal = __Pyx_PyObject_IsTrue(values[1]); if (unlikely((__pyx_v_terminal == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; @@ -21813,12 +21813,7 @@ static PyObject *__pyx_pw_3_sa_3sym_fromstring(PyObject *__pyx_self, PyObject *_ __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_string), (&PyBytes_Type), 1, "string", 1))) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = __pyx_pf_3_sa_2sym_fromstring(__pyx_self, __pyx_v_string, __pyx_v_terminal); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } @@ -21826,15 +21821,14 @@ static PyObject *__pyx_pw_3_sa_3sym_fromstring(PyObject *__pyx_self, PyObject *_ /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":104 * return ALPHABET.setindex(sym, id) * - * def sym_fromstring(bytes string, bint terminal): # <<<<<<<<<<<<<< + * def sym_fromstring(char* string, bint terminal): # <<<<<<<<<<<<<< * return ALPHABET.fromstring(string, terminal) */ -static PyObject *__pyx_pf_3_sa_2sym_fromstring(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_string, int __pyx_v_terminal) { +static PyObject *__pyx_pf_3_sa_2sym_fromstring(CYTHON_UNUSED PyObject *__pyx_self, char *__pyx_v_string, int __pyx_v_terminal) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - char *__pyx_t_1; - PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -21842,21 +21836,20 @@ static PyObject *__pyx_pf_3_sa_2sym_fromstring(CYTHON_UNUSED PyObject *__pyx_sel /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":105 * - * def sym_fromstring(bytes string, bint terminal): + * def sym_fromstring(char* string, bint terminal): * return ALPHABET.fromstring(string, terminal) # <<<<<<<<<<<<<< */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_AsString(((PyObject *)__pyx_v_string)); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromLong(((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_3_sa_ALPHABET->__pyx_vtab)->fromstring(__pyx_v_3_sa_ALPHABET, __pyx_t_1, __pyx_v_terminal)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_t_1 = PyInt_FromLong(((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_3_sa_ALPHABET->__pyx_vtab)->fromstring(__pyx_v_3_sa_ALPHABET, __pyx_v_string, __pyx_v_terminal)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_2); + __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("_sa.sym_fromstring", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -60511,7 +60504,7 @@ static int __Pyx_InitCachedConstants(void) { /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":104 * return ALPHABET.setindex(sym, id) * - * def sym_fromstring(bytes string, bint terminal): # <<<<<<<<<<<<<< + * def sym_fromstring(char* string, bint terminal): # <<<<<<<<<<<<<< * return ALPHABET.fromstring(string, terminal) */ __pyx_k_tuple_137 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_137)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -60933,7 +60926,7 @@ PyMODINIT_FUNC PyInit__sa(void) /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":104 * return ALPHABET.setindex(sym, id) * - * def sym_fromstring(bytes string, bint terminal): # <<<<<<<<<<<<<< + * def sym_fromstring(char* string, bint terminal): # <<<<<<<<<<<<<< * return ALPHABET.fromstring(string, terminal) */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_3_sa_3sym_fromstring, NULL, __pyx_n_s___sa); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} diff --git a/python/src/sa/sym.pxi b/python/src/sa/sym.pxi index 4b41886f..132925f6 100644 --- a/python/src/sa/sym.pxi +++ b/python/src/sa/sym.pxi @@ -101,5 +101,5 @@ cdef int sym_getindex(int sym): cdef int sym_setindex(int sym, int id): return ALPHABET.setindex(sym, id) -def sym_fromstring(bytes string, bint terminal): +def sym_fromstring(char* string, bint terminal): return ALPHABET.fromstring(string, terminal) -- cgit v1.2.3 From 0b0616c6f7400ce52d07350f7a7054a2513d9813 Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Sat, 28 Jul 2012 17:12:40 -0400 Subject: [python] Suffix array compiler can read bitext (-b) --- python/pkg/cdec/sa/compile.py | 24 +- python/src/cdec.sa._sa.pxd | 1 + python/src/sa/_sa.c | 4291 +++++++++++++++++++++++++--------------- python/src/sa/data_array.pxi | 38 +- python/src/sa/suffix_array.pxi | 8 +- 5 files changed, 2780 insertions(+), 1582 deletions(-) create mode 120000 python/src/cdec.sa._sa.pxd (limited to 'python/src') diff --git a/python/pkg/cdec/sa/compile.py b/python/pkg/cdec/sa/compile.py index 30e605a6..2a89243b 100644 --- a/python/pkg/cdec/sa/compile.py +++ b/python/pkg/cdec/sa/compile.py @@ -37,16 +37,22 @@ def main(): help='Number of pre-computed super-frequent patterns)') parser.add_argument('-c', '--config', default='/dev/stdout', help='Output configuration') - parser.add_argument('-o', '--output', required=True, - help='Output path') - parser.add_argument('-f', '--source', required=True, + parser.add_argument('-f', '--source', help='Source language corpus') - parser.add_argument('-e', '--target', required=True, + parser.add_argument('-e', '--target', help='Target language corpus') + parser.add_argument('-b', '--bitext', + help='Parallel text (source ||| target)') parser.add_argument('-a', '--alignment', required=True, help='Bitext word alignment') + parser.add_argument('-o', '--output', required=True, + help='Output path') args = parser.parse_args() + if not ((args.source and args.target) or args.bitext): + parser.error('a parallel corpus is required\n' + '\tuse -f (source) with -e (target) or -b (bitext)') + param_names = ("max_len", "max_nt", "max_size", "min_gap", "rank1", "rank2") params = (args.maxlen, args.maxnt, args.maxsize, args.mingap, args.rank1, args.rank2) @@ -61,11 +67,17 @@ def main(): lex_bin = os.path.join(args.output, 'lex.bin') logger.info('Compiling source suffix array') - f_sa = cdec.sa.SuffixArray(from_text=args.source) + if args.bitext: + f_sa = cdec.sa.SuffixArray(from_text=args.bitext, side='source') + else: + f_sa = cdec.sa.SuffixArray(from_text=args.source) f_sa.write_binary(f_sa_bin) logger.info('Compiling target data array') - e = cdec.sa.DataArray(from_text=args.target) + if args.bitext: + e = cdec.sa.DataArray(from_text=args.bitext, side='target') + else: + e = cdec.sa.DataArray(from_text=args.target) e.write_binary(e_bin) logger.info('Precomputing frequent phrases') diff --git a/python/src/cdec.sa._sa.pxd b/python/src/cdec.sa._sa.pxd new file mode 120000 index 00000000..3613f643 --- /dev/null +++ b/python/src/cdec.sa._sa.pxd @@ -0,0 +1 @@ +sa/_sa.pxd \ No newline at end of file diff --git a/python/src/sa/_sa.c b/python/src/sa/_sa.c index b7f3627a..0f9b0d22 100644 --- a/python/src/sa/_sa.c +++ b/python/src/sa/_sa.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.17.beta1 on Fri Jul 27 23:31:04 2012 */ +/* Generated by Cython 0.17.beta1 on Sat Jul 28 17:07:03 2012 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -383,6 +383,7 @@ static const char *__pyx_f[] = { /*--- Type declarations ---*/ struct __pyx_obj_3_sa_HieroCachingRuleFactory; +struct __pyx_obj_3_sa___pyx_scope_struct_2_compute_stats; struct __pyx_obj_3_sa_IntList; struct __pyx_obj_3_sa_VEBIterator; struct __pyx_obj_3_sa_BiLex; @@ -390,23 +391,24 @@ struct __pyx_obj_3_sa_VEB; struct __pyx_obj_3_sa_LCP; struct __pyx_obj_3_sa_DataArray; struct __pyx_obj_3_sa_BitSetIterator; +struct __pyx_obj_3_sa___pyx_scope_struct__read_bitext; struct __pyx_obj_3_sa_Precomputation; struct __pyx_obj_3_sa_SuffixArray; +struct __pyx_obj_3_sa___pyx_scope_struct_4_input; struct __pyx_obj_3_sa_Alphabet; struct __pyx_obj_3_sa_Rule; struct __pyx_obj_3_sa_PhraseLocation; -struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats; -struct __pyx_obj_3_sa___pyx_scope_struct_2_input; +struct __pyx_obj_3_sa___pyx_scope_struct_3___iter__; struct __pyx_obj_3_sa_Alignment; struct __pyx_obj_3_sa_BitSet; struct __pyx_obj_3_sa_Sampler; struct __pyx_obj_3_sa_StringMap; -struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__; struct __pyx_obj_3_sa_TrieNode; struct __pyx_obj_3_sa_ExtendedTrieNode; struct __pyx_obj_3_sa_TrieMap; struct __pyx_obj_3_sa_Phrase; struct __pyx_obj_3_sa_TrieTable; +struct __pyx_obj_3_sa___pyx_scope_struct_1_genexpr; struct __pyx_obj_3_sa_FloatList; struct __pyx_t_3_sa__node; struct __pyx_t_3_sa__BitSet; @@ -563,6 +565,37 @@ struct __pyx_obj_3_sa_HieroCachingRuleFactory { }; +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":36 + * logger.info("LCP array completed") + * + * def compute_stats(self, int max_n): # <<<<<<<<<<<<<< + * """Note: the output of this function is not exact. In + * particular, the frequency associated with each word is + */ +struct __pyx_obj_3_sa___pyx_scope_struct_2_compute_stats { + PyObject_HEAD + int __pyx_v_N; + int __pyx_v_freq; + int __pyx_v_h; + int __pyx_v_i; + int __pyx_v_ii; + int __pyx_v_iii; + int __pyx_v_j; + int __pyx_v_k; + int __pyx_v_max_n; + int __pyx_v_n; + PyObject *__pyx_v_ngram; + struct __pyx_obj_3_sa_IntList *__pyx_v_ngram_start; + PyObject *__pyx_v_ngram_starts; + int __pyx_v_rs; + struct __pyx_obj_3_sa_IntList *__pyx_v_run_start; + struct __pyx_obj_3_sa_LCP *__pyx_v_self; + int __pyx_v_valid; + struct __pyx_obj_3_sa_VEB *__pyx_v_veb; + int __pyx_t_0; +}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/int_list.pxi":9 * from libc.string cimport memset, memcpy * @@ -676,6 +709,20 @@ struct __pyx_obj_3_sa_BitSetIterator { }; +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":71 + * self.read_text_data(fp) + * + * def read_bitext(self, char* filename, int side): # <<<<<<<<<<<<<< + * with gzip_or_text(filename) as fp: + * data = (line.split(' ||| ')[side] for line in fp) + */ +struct __pyx_obj_3_sa___pyx_scope_struct__read_bitext { + PyObject_HEAD + PyObject *__pyx_v_fp; + int __pyx_v_side; +}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":188 * * @@ -713,84 +760,6 @@ struct __pyx_obj_3_sa_SuffixArray { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":7 - * cdef int INDEX_MASK = (1< + +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); /*proto*/ + +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); /*proto*/ + +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals +#else +#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals +#endif + static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); @@ -1868,9 +1915,11 @@ static PyTypeObject *__pyx_ptype_3_sa_TrieTable = 0; static PyTypeObject *__pyx_ptype_3_sa_PhraseLocation = 0; static PyTypeObject *__pyx_ptype_3_sa_Sampler = 0; static PyTypeObject *__pyx_ptype_3_sa_HieroCachingRuleFactory = 0; -static PyTypeObject *__pyx_ptype_3_sa___pyx_scope_struct__compute_stats = 0; -static PyTypeObject *__pyx_ptype_3_sa___pyx_scope_struct_1___iter__ = 0; -static PyTypeObject *__pyx_ptype_3_sa___pyx_scope_struct_2_input = 0; +static PyTypeObject *__pyx_ptype_3_sa___pyx_scope_struct__read_bitext = 0; +static PyTypeObject *__pyx_ptype_3_sa___pyx_scope_struct_1_genexpr = 0; +static PyTypeObject *__pyx_ptype_3_sa___pyx_scope_struct_2_compute_stats = 0; +static PyTypeObject *__pyx_ptype_3_sa___pyx_scope_struct_3___iter__ = 0; +static PyTypeObject *__pyx_ptype_3_sa___pyx_scope_struct_4_input = 0; static int __pyx_v_3_sa_MIN_BOTTOM_SIZE; static int __pyx_v_3_sa_MIN_BOTTOM_BITS; static int __pyx_v_3_sa_LOWER_MASK[32]; @@ -1957,7 +2006,7 @@ static PyObject *__pyx_pf_3_sa_7IntList_28write(struct __pyx_obj_3_sa_IntList *_ static PyObject *__pyx_pf_3_sa_7IntList_30read(struct __pyx_obj_3_sa_IntList *__pyx_v_self, char *__pyx_v_filename); /* proto */ static int __pyx_pf_3_sa_9StringMap___cinit__(struct __pyx_obj_3_sa_StringMap *__pyx_v_self); /* proto */ static void __pyx_pf_3_sa_9StringMap_2__dealloc__(struct __pyx_obj_3_sa_StringMap *__pyx_v_self); /* proto */ -static int __pyx_pf_3_sa_9DataArray___cinit__(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text, int __pyx_v_use_sent_id); /* proto */ +static int __pyx_pf_3_sa_9DataArray___cinit__(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text, PyObject *__pyx_v_side, int __pyx_v_use_sent_id); /* proto */ static Py_ssize_t __pyx_pf_3_sa_9DataArray_2__len__(struct __pyx_obj_3_sa_DataArray *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_3_sa_9DataArray_4getSentId(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ static PyObject *__pyx_pf_3_sa_9DataArray_6getSent(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ @@ -1966,10 +2015,13 @@ static PyObject *__pyx_pf_3_sa_9DataArray_10get_id(struct __pyx_obj_3_sa_DataArr static PyObject *__pyx_pf_3_sa_9DataArray_12get_word(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_id); /* proto */ static PyObject *__pyx_pf_3_sa_9DataArray_14write_text(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ static PyObject *__pyx_pf_3_sa_9DataArray_16read_text(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_3_sa_9DataArray_18read_binary(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_3_sa_9DataArray_20write_binary(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ -static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_f); /* proto */ -static PyObject *__pyx_pf_3_sa_9DataArray_24write_enhanced(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_9DataArray_11read_bitext_genexpr(PyObject *__pyx_self); /* proto */ +static PyObject *__pyx_pf_3_sa_9DataArray_18read_bitext(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename, int __pyx_v_side); /* proto */ +static PyObject *__pyx_pf_3_sa_9DataArray_20read_text_data(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_data); /* proto */ +static PyObject *__pyx_pf_3_sa_9DataArray_22read_binary(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_9DataArray_24write_binary(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_9DataArray_26write_enhanced_handle(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_f); /* proto */ +static PyObject *__pyx_pf_3_sa_9DataArray_28write_enhanced(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ static PyObject *__pyx_pf_3_sa_9Alignment_unlink(CYTHON_UNUSED struct __pyx_obj_3_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_link); /* proto */ static PyObject *__pyx_pf_3_sa_9Alignment_2get_sent_links(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, int __pyx_v_sent_id); /* proto */ static int __pyx_pf_3_sa_9Alignment_4__cinit__(struct __pyx_obj_3_sa_Alignment *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text); /* proto */ @@ -2061,12 +2113,12 @@ static int __pyx_pf_3_sa_14Precomputation___cinit__(struct __pyx_obj_3_sa_Precom static PyObject *__pyx_pf_3_sa_14Precomputation_2read_binary(struct __pyx_obj_3_sa_Precomputation *__pyx_v_self, char *__pyx_v_filename); /* proto */ static PyObject *__pyx_pf_3_sa_14Precomputation_4write_binary(struct __pyx_obj_3_sa_Precomputation *__pyx_v_self, char *__pyx_v_filename); /* proto */ static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_sa_Precomputation *__pyx_v_self, PyObject *__pyx_v_stats, struct __pyx_obj_3_sa_SuffixArray *__pyx_v_sarray); /* proto */ -static int __pyx_pf_3_sa_11SuffixArray___cinit__(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text); /* proto */ +static int __pyx_pf_3_sa_11SuffixArray___cinit__(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text, PyObject *__pyx_v_side); /* proto */ static PyObject *__pyx_pf_3_sa_11SuffixArray_2__getitem__(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ static PyObject *__pyx_pf_3_sa_11SuffixArray_4getSentId(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ static PyObject *__pyx_pf_3_sa_11SuffixArray_6getSent(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_i); /* proto */ static PyObject *__pyx_pf_3_sa_11SuffixArray_8getSentPos(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_loc); /* proto */ -static PyObject *__pyx_pf_3_sa_11SuffixArray_10read_text(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ +static PyObject *__pyx_pf_3_sa_11SuffixArray_10read_text(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_side); /* proto */ static PyObject *__pyx_pf_3_sa_11SuffixArray_12q3sort(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, int __pyx_v_i, int __pyx_v_j, int __pyx_v_h, struct __pyx_obj_3_sa_IntList *__pyx_v_isa, PyObject *__pyx_v_pad); /* proto */ static PyObject *__pyx_pf_3_sa_11SuffixArray_14write_text(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ static PyObject *__pyx_pf_3_sa_11SuffixArray_16read_binary(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename); /* proto */ @@ -2121,49 +2173,47 @@ static char __pyx_k_8[] = "Requested index %d:%d of %d-length IntList"; static char __pyx_k_9[] = "Illegal key type %s for IntList"; static char __pyx_k_13[] = "%s "; static char __pyx_k_14[] = "\n"; -static char __pyx_k_18[] = "%d "; -static char __pyx_k_22[] = "%s %d "; -static char __pyx_k_24[] = "write_enhanced_handle"; -static char __pyx_k_28[] = "-"; -static char __pyx_k_32[] = "%d-%d "; -static char __pyx_k_39[] = "%d-%d out of bounds (I=%d,J=%d) in line %d\n"; -static char __pyx_k_42[] = ""; -static char __pyx_k_43[] = "Sort error in CLex"; -static char __pyx_k_45[] = " "; -static char __pyx_k_47[] = "%d %f %f "; -static char __pyx_k_49[] = "%d %s "; -static char __pyx_k_53[] = "%s %s %.6f %.6f\n"; -static char __pyx_k_55[] = " ("; -static char __pyx_k_56[] = ")"; -static char __pyx_k_57[] = "Constructing LCP array"; -static char __pyx_k_59[] = "LCP array completed"; -static char __pyx_k_61[] = "[%s,%d]"; -static char __pyx_k_62[] = "[%s]"; -static char __pyx_k_63[] = "\\"; -static char __pyx_k_64[] = " "; -static char __pyx_k_65[] = "Invalid LHS symbol: %d"; -static char __pyx_k_66[] = "%d-%d"; -static char __pyx_k_67[] = " ||| "; -static char __pyx_k_68[] = "precompute_secondary_rank"; -static char __pyx_k_69[] = "train_max_initial_size"; -static char __pyx_k_70[] = "Precomputing frequent intersections"; -static char __pyx_k_72[] = " Computing inverted indexes..."; -static char __pyx_k_74[] = " Computing collocations..."; -static char __pyx_k_76[] = " %d sentences"; -static char __pyx_k_81[] = "X "; -static char __pyx_k_82[] = "ERROR: unexpected pattern %s in set of precomputed collocations"; -static char __pyx_k_83[] = "RANK %d\tCOUNT, COST: %d %d\tCUMUL: %d, %d"; -static char __pyx_k_84[] = "Precomputed collocations for %d patterns out of %d possible (upper bound %d)"; -static char __pyx_k_85[] = "Precomputed inverted index for %d patterns "; -static char __pyx_k_86[] = "Precomputation took %f seconds"; -static char __pyx_k_87[] = " Bucket sort took %f seconds"; -static char __pyx_k_88[] = " Refining, sort depth = %d"; -static char __pyx_k_89[] = " Refinement took %f seconds"; -static char __pyx_k_90[] = " Finalizing sort..."; -static char __pyx_k_92[] = "Suffix array construction took %f seconds"; -static char __pyx_k_93[] = "Unexpected condition found in q3sort: sort from %d to %d"; -static char __pyx_k_98[] = "Sampling strategy: uniform, max sample size = %d"; -static char __pyx_k_99[] = "Sampling strategy: no sampling"; +static char __pyx_k_18[] = " ||| "; +static char __pyx_k_21[] = "%d "; +static char __pyx_k_25[] = "%s %d "; +static char __pyx_k_27[] = "write_enhanced_handle"; +static char __pyx_k_31[] = "-"; +static char __pyx_k_35[] = "%d-%d "; +static char __pyx_k_42[] = "%d-%d out of bounds (I=%d,J=%d) in line %d\n"; +static char __pyx_k_45[] = ""; +static char __pyx_k_46[] = "Sort error in CLex"; +static char __pyx_k_48[] = " "; +static char __pyx_k_50[] = "%d %f %f "; +static char __pyx_k_52[] = "%d %s "; +static char __pyx_k_56[] = "%s %s %.6f %.6f\n"; +static char __pyx_k_58[] = " ("; +static char __pyx_k_59[] = ")"; +static char __pyx_k_60[] = "Constructing LCP array"; +static char __pyx_k_62[] = "LCP array completed"; +static char __pyx_k_64[] = "[%s,%d]"; +static char __pyx_k_65[] = "[%s]"; +static char __pyx_k_66[] = "\\"; +static char __pyx_k_67[] = " "; +static char __pyx_k_68[] = "Invalid LHS symbol: %d"; +static char __pyx_k_69[] = "%d-%d"; +static char __pyx_k_70[] = "precompute_secondary_rank"; +static char __pyx_k_71[] = "train_max_initial_size"; +static char __pyx_k_72[] = "Precomputing frequent intersections"; +static char __pyx_k_74[] = " Computing inverted indexes..."; +static char __pyx_k_76[] = " Computing collocations..."; +static char __pyx_k_78[] = " %d sentences"; +static char __pyx_k_83[] = "X "; +static char __pyx_k_84[] = "ERROR: unexpected pattern %s in set of precomputed collocations"; +static char __pyx_k_85[] = "RANK %d\tCOUNT, COST: %d %d\tCUMUL: %d, %d"; +static char __pyx_k_86[] = "Precomputed collocations for %d patterns out of %d possible (upper bound %d)"; +static char __pyx_k_87[] = "Precomputed inverted index for %d patterns "; +static char __pyx_k_88[] = "Precomputation took %f seconds"; +static char __pyx_k_89[] = " Bucket sort took %f seconds"; +static char __pyx_k_90[] = " Refining, sort depth = %d"; +static char __pyx_k_91[] = " Refinement took %f seconds"; +static char __pyx_k_92[] = " Finalizing sort..."; +static char __pyx_k_94[] = "Suffix array construction took %f seconds"; +static char __pyx_k_95[] = "Unexpected condition found in q3sort: sort from %d to %d"; static char __pyx_k__0[] = "0"; static char __pyx_k__1[] = "1"; static char __pyx_k__e[] = "e"; @@ -2173,39 +2223,41 @@ static char __pyx_k__i[] = "i"; static char __pyx_k__j[] = "j"; static char __pyx_k__r[] = "r"; static char __pyx_k__w[] = "w"; -static char __pyx_k_101[] = "require_aligned_terminal"; -static char __pyx_k_102[] = "require_aligned_chunks"; -static char __pyx_k_103[] = "[X]"; -static char __pyx_k_104[] = "Must specify an alignment object"; -static char __pyx_k_106[] = "Reading precomputed data from file %s... "; -static char __pyx_k_107[] = "Precomputation done with max nonterminals %d, decoder uses %d"; -static char __pyx_k_108[] = "Precomputation done with max terminals %d, decoder uses %d"; -static char __pyx_k_109[] = "Precomputation done with max initial size %d, decoder uses %d"; -static char __pyx_k_110[] = "Precomputation done with min gap size %d, decoder uses %d"; -static char __pyx_k_111[] = "Converting %d hash keys on precomputed inverted index... "; -static char __pyx_k_112[] = "Converting %d hash keys on precomputed collocations... "; -static char __pyx_k_113[] = "Processing precomputations took %f seconds"; -static char __pyx_k_114[] = "{"; - static char __pyx_k_115[] = "("; -static char __pyx_k_116[] = "}"; -static char __pyx_k_117[] = "get_precomputed_collocation"; -static char __pyx_k_118[] = "double binary"; -static char __pyx_k_119[] = "Keyword trie error"; -static char __pyx_k_121[] = "get_all_nodes_isteps_away"; -static char __pyx_k_122[] = "Total time for rule lookup, extraction, and scoring = %f seconds"; -static char __pyx_k_123[] = " Extract time = %f seconds"; -static char __pyx_k_124[] = "No aligned terminals"; -static char __pyx_k_125[] = "Unaligned chunk"; -static char __pyx_k_126[] = "Gaps are not tight phrases"; -static char __pyx_k_127[] = "Inside edges of preceding subphrase are not tight"; -static char __pyx_k_128[] = "Inside edges of following subphrase are not tight"; -static char __pyx_k_129[] = "Subphrase [%d, %d] failed integrity check"; -static char __pyx_k_130[] = "Didn't extract anything from [%d, %d] -> [%d, %d]"; -static char __pyx_k_131[] = "Unable to extract basic phrase"; -static char __pyx_k_134[] = "/Users/vchahun/Sandbox/cdec/python/src/sa/_sa.pyx"; -static char __pyx_k_135[] = "cdec.sa"; -static char __pyx_k_139[] = "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi"; -static char __pyx_k_140[] = "*EPS*"; +static char __pyx_k_100[] = "Sampling strategy: uniform, max sample size = %d"; +static char __pyx_k_101[] = "Sampling strategy: no sampling"; +static char __pyx_k_103[] = "require_aligned_terminal"; +static char __pyx_k_104[] = "require_aligned_chunks"; +static char __pyx_k_105[] = "[X]"; +static char __pyx_k_106[] = "Must specify an alignment object"; +static char __pyx_k_108[] = "Reading precomputed data from file %s... "; +static char __pyx_k_109[] = "Precomputation done with max nonterminals %d, decoder uses %d"; +static char __pyx_k_110[] = "Precomputation done with max terminals %d, decoder uses %d"; +static char __pyx_k_111[] = "Precomputation done with max initial size %d, decoder uses %d"; +static char __pyx_k_112[] = "Precomputation done with min gap size %d, decoder uses %d"; +static char __pyx_k_113[] = "Converting %d hash keys on precomputed inverted index... "; +static char __pyx_k_114[] = "Converting %d hash keys on precomputed collocations... "; +static char __pyx_k_115[] = "Processing precomputations took %f seconds"; +static char __pyx_k_116[] = "{"; + static char __pyx_k_117[] = "("; +static char __pyx_k_118[] = "}"; +static char __pyx_k_119[] = "get_precomputed_collocation"; +static char __pyx_k_120[] = "double binary"; +static char __pyx_k_121[] = "Keyword trie error"; +static char __pyx_k_123[] = "get_all_nodes_isteps_away"; +static char __pyx_k_124[] = "Total time for rule lookup, extraction, and scoring = %f seconds"; +static char __pyx_k_125[] = " Extract time = %f seconds"; +static char __pyx_k_126[] = "No aligned terminals"; +static char __pyx_k_127[] = "Unaligned chunk"; +static char __pyx_k_128[] = "Gaps are not tight phrases"; +static char __pyx_k_129[] = "Inside edges of preceding subphrase are not tight"; +static char __pyx_k_130[] = "Inside edges of following subphrase are not tight"; +static char __pyx_k_131[] = "Subphrase [%d, %d] failed integrity check"; +static char __pyx_k_132[] = "Didn't extract anything from [%d, %d] -> [%d, %d]"; +static char __pyx_k_133[] = "Unable to extract basic phrase"; +static char __pyx_k_136[] = "/Users/vchahun/Sandbox/cdec/python/src/sa/_sa.pyx"; +static char __pyx_k_137[] = "cdec.sa"; +static char __pyx_k_141[] = "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi"; +static char __pyx_k_142[] = "*EPS*"; static char __pyx_k__gc[] = "gc"; static char __pyx_k__sa[] = "sa"; static char __pyx_k___sa[] = "_sa"; @@ -2229,6 +2281,7 @@ static char __pyx_k__info[] = "info"; static char __pyx_k__join[] = "join"; static char __pyx_k__open[] = "open"; static char __pyx_k__seek[] = "seek"; +static char __pyx_k__side[] = "side"; static char __pyx_k__size[] = "size"; static char __pyx_k__skip[] = "skip"; static char __pyx_k__stop[] = "stop"; @@ -2266,6 +2319,7 @@ static char __pyx_k__sample[] = "sample"; static char __pyx_k__sarray[] = "sarray"; static char __pyx_k__scores[] = "scores"; static char __pyx_k__sorted[] = "sorted"; +static char __pyx_k__source[] = "source"; static char __pyx_k__string[] = "string"; static char __pyx_k__unlink[] = "unlink"; static char __pyx_k__advance[] = "advance"; @@ -2334,6 +2388,7 @@ static char __pyx_k__initial_len[] = "initial_len"; static char __pyx_k__next_states[] = "next_states"; static char __pyx_k__precomputed[] = "precomputed"; static char __pyx_k__read_binary[] = "read_binary"; +static char __pyx_k__read_bitext[] = "read_bitext"; static char __pyx_k__sample_size[] = "sample_size"; static char __pyx_k__suffix_link[] = "suffix_link"; static char __pyx_k__use_sent_id[] = "use_sent_id"; @@ -2344,6 +2399,7 @@ static char __pyx_k__StopIteration[] = "StopIteration"; static char __pyx_k__alphabet_size[] = "alphabet_size"; static char __pyx_k__tight_phrases[] = "tight_phrases"; static char __pyx_k__pattern2phrase[] = "pattern2phrase"; +static char __pyx_k__read_text_data[] = "read_text_data"; static char __pyx_k__sym_fromstring[] = "sym_fromstring"; static char __pyx_k__by_slack_factor[] = "by_slack_factor"; static char __pyx_k__get_next_states[] = "get_next_states"; @@ -2362,11 +2418,11 @@ static char __pyx_k__max_target_length[] = "max_target_length"; static char __pyx_k__train_min_gap_size[] = "train_min_gap_size"; static char __pyx_k__pattern2phrase_plus[] = "pattern2phrase_plus"; static PyObject *__pyx_kp_s_1; -static PyObject *__pyx_n_s_101; -static PyObject *__pyx_n_s_102; -static PyObject *__pyx_kp_s_104; +static PyObject *__pyx_kp_s_100; +static PyObject *__pyx_kp_s_101; +static PyObject *__pyx_n_s_103; +static PyObject *__pyx_n_s_104; static PyObject *__pyx_kp_s_106; -static PyObject *__pyx_kp_s_107; static PyObject *__pyx_kp_s_108; static PyObject *__pyx_kp_s_109; static PyObject *__pyx_kp_s_110; @@ -2376,12 +2432,12 @@ static PyObject *__pyx_kp_s_113; static PyObject *__pyx_kp_s_114; static PyObject *__pyx_kp_s_115; static PyObject *__pyx_kp_s_116; -static PyObject *__pyx_n_s_117; +static PyObject *__pyx_kp_s_117; static PyObject *__pyx_kp_s_118; -static PyObject *__pyx_kp_s_119; -static PyObject *__pyx_n_s_121; -static PyObject *__pyx_kp_s_122; -static PyObject *__pyx_kp_s_123; +static PyObject *__pyx_n_s_119; +static PyObject *__pyx_kp_s_120; +static PyObject *__pyx_kp_s_121; +static PyObject *__pyx_n_s_123; static PyObject *__pyx_kp_s_124; static PyObject *__pyx_kp_s_125; static PyObject *__pyx_kp_s_126; @@ -2391,49 +2447,49 @@ static PyObject *__pyx_kp_s_129; static PyObject *__pyx_kp_s_13; static PyObject *__pyx_kp_s_130; static PyObject *__pyx_kp_s_131; -static PyObject *__pyx_kp_s_134; -static PyObject *__pyx_kp_s_135; -static PyObject *__pyx_kp_s_139; +static PyObject *__pyx_kp_s_132; +static PyObject *__pyx_kp_s_133; +static PyObject *__pyx_kp_s_136; +static PyObject *__pyx_kp_s_137; static PyObject *__pyx_kp_s_14; -static PyObject *__pyx_kp_s_140; +static PyObject *__pyx_kp_s_141; +static PyObject *__pyx_kp_s_142; static PyObject *__pyx_kp_s_18; static PyObject *__pyx_kp_s_2; -static PyObject *__pyx_kp_s_22; -static PyObject *__pyx_n_s_24; -static PyObject *__pyx_kp_s_28; +static PyObject *__pyx_kp_s_21; +static PyObject *__pyx_kp_s_25; +static PyObject *__pyx_n_s_27; static PyObject *__pyx_kp_s_3; -static PyObject *__pyx_kp_s_32; -static PyObject *__pyx_kp_s_39; +static PyObject *__pyx_kp_s_31; +static PyObject *__pyx_kp_s_35; static PyObject *__pyx_kp_s_4; static PyObject *__pyx_kp_s_42; -static PyObject *__pyx_kp_s_43; static PyObject *__pyx_kp_s_45; -static PyObject *__pyx_kp_s_47; -static PyObject *__pyx_kp_s_49; +static PyObject *__pyx_kp_s_46; +static PyObject *__pyx_kp_s_48; static PyObject *__pyx_kp_s_5; -static PyObject *__pyx_kp_s_53; -static PyObject *__pyx_kp_s_55; +static PyObject *__pyx_kp_s_50; +static PyObject *__pyx_kp_s_52; static PyObject *__pyx_kp_s_56; -static PyObject *__pyx_kp_s_57; +static PyObject *__pyx_kp_s_58; static PyObject *__pyx_kp_s_59; static PyObject *__pyx_kp_s_6; -static PyObject *__pyx_kp_s_61; +static PyObject *__pyx_kp_s_60; static PyObject *__pyx_kp_s_62; -static PyObject *__pyx_kp_s_63; static PyObject *__pyx_kp_s_64; static PyObject *__pyx_kp_s_65; static PyObject *__pyx_kp_s_66; static PyObject *__pyx_kp_s_67; -static PyObject *__pyx_n_s_68; -static PyObject *__pyx_n_s_69; +static PyObject *__pyx_kp_s_68; +static PyObject *__pyx_kp_s_69; static PyObject *__pyx_kp_s_7; -static PyObject *__pyx_kp_s_70; +static PyObject *__pyx_n_s_70; +static PyObject *__pyx_n_s_71; static PyObject *__pyx_kp_s_72; static PyObject *__pyx_kp_s_74; static PyObject *__pyx_kp_s_76; +static PyObject *__pyx_kp_s_78; static PyObject *__pyx_kp_s_8; -static PyObject *__pyx_kp_s_81; -static PyObject *__pyx_kp_s_82; static PyObject *__pyx_kp_s_83; static PyObject *__pyx_kp_s_84; static PyObject *__pyx_kp_s_85; @@ -2443,10 +2499,10 @@ static PyObject *__pyx_kp_s_88; static PyObject *__pyx_kp_s_89; static PyObject *__pyx_kp_s_9; static PyObject *__pyx_kp_s_90; +static PyObject *__pyx_kp_s_91; static PyObject *__pyx_kp_s_92; -static PyObject *__pyx_kp_s_93; -static PyObject *__pyx_kp_s_98; -static PyObject *__pyx_kp_s_99; +static PyObject *__pyx_kp_s_94; +static PyObject *__pyx_kp_s_95; static PyObject *__pyx_kp_s__0; static PyObject *__pyx_kp_s__1; static PyObject *__pyx_n_s__END_OF_FILE; @@ -2564,7 +2620,9 @@ static PyObject *__pyx_n_s__range; static PyObject *__pyx_n_s__reachable; static PyObject *__pyx_n_s__reachable_buffer; static PyObject *__pyx_n_s__read_binary; +static PyObject *__pyx_n_s__read_bitext; static PyObject *__pyx_n_s__read_text; +static PyObject *__pyx_n_s__read_text_data; static PyObject *__pyx_n_s__res; static PyObject *__pyx_n_s__reset; static PyObject *__pyx_n_s__resource; @@ -2581,9 +2639,11 @@ static PyObject *__pyx_n_s__scores; static PyObject *__pyx_n_s__seek; static PyObject *__pyx_n_s__setdefault; static PyObject *__pyx_n_s__shortest; +static PyObject *__pyx_n_s__side; static PyObject *__pyx_n_s__size; static PyObject *__pyx_n_s__skip; static PyObject *__pyx_n_s__sorted; +static PyObject *__pyx_n_s__source; static PyObject *__pyx_n_s__spanlen; static PyObject *__pyx_n_s__split; static PyObject *__pyx_n_s__start; @@ -2618,8 +2678,8 @@ static PyObject *__pyx_int_10; static PyObject *__pyx_int_20; static PyObject *__pyx_int_1000; static PyObject *__pyx_int_65536; -static PyObject *__pyx_k_38; -static PyObject *__pyx_k_97; +static PyObject *__pyx_k_41; +static PyObject *__pyx_k_99; static PyObject *__pyx_k_tuple_10; static PyObject *__pyx_k_tuple_11; static PyObject *__pyx_k_tuple_12; @@ -2628,49 +2688,51 @@ static PyObject *__pyx_k_tuple_16; static PyObject *__pyx_k_tuple_17; static PyObject *__pyx_k_tuple_19; static PyObject *__pyx_k_tuple_20; -static PyObject *__pyx_k_tuple_21; +static PyObject *__pyx_k_tuple_22; static PyObject *__pyx_k_tuple_23; -static PyObject *__pyx_k_tuple_25; +static PyObject *__pyx_k_tuple_24; static PyObject *__pyx_k_tuple_26; -static PyObject *__pyx_k_tuple_27; +static PyObject *__pyx_k_tuple_28; static PyObject *__pyx_k_tuple_29; static PyObject *__pyx_k_tuple_30; -static PyObject *__pyx_k_tuple_31; +static PyObject *__pyx_k_tuple_32; static PyObject *__pyx_k_tuple_33; static PyObject *__pyx_k_tuple_34; -static PyObject *__pyx_k_tuple_35; static PyObject *__pyx_k_tuple_36; static PyObject *__pyx_k_tuple_37; +static PyObject *__pyx_k_tuple_38; +static PyObject *__pyx_k_tuple_39; static PyObject *__pyx_k_tuple_40; -static PyObject *__pyx_k_tuple_41; +static PyObject *__pyx_k_tuple_43; static PyObject *__pyx_k_tuple_44; -static PyObject *__pyx_k_tuple_46; -static PyObject *__pyx_k_tuple_48; -static PyObject *__pyx_k_tuple_50; +static PyObject *__pyx_k_tuple_47; +static PyObject *__pyx_k_tuple_49; static PyObject *__pyx_k_tuple_51; -static PyObject *__pyx_k_tuple_52; +static PyObject *__pyx_k_tuple_53; static PyObject *__pyx_k_tuple_54; -static PyObject *__pyx_k_tuple_58; -static PyObject *__pyx_k_tuple_60; -static PyObject *__pyx_k_tuple_71; +static PyObject *__pyx_k_tuple_55; +static PyObject *__pyx_k_tuple_57; +static PyObject *__pyx_k_tuple_61; +static PyObject *__pyx_k_tuple_63; static PyObject *__pyx_k_tuple_73; static PyObject *__pyx_k_tuple_75; static PyObject *__pyx_k_tuple_77; -static PyObject *__pyx_k_tuple_78; static PyObject *__pyx_k_tuple_79; static PyObject *__pyx_k_tuple_80; -static PyObject *__pyx_k_tuple_91; -static PyObject *__pyx_k_tuple_94; -static PyObject *__pyx_k_tuple_95; +static PyObject *__pyx_k_tuple_81; +static PyObject *__pyx_k_tuple_82; +static PyObject *__pyx_k_tuple_93; static PyObject *__pyx_k_tuple_96; -static PyObject *__pyx_k_tuple_100; -static PyObject *__pyx_k_tuple_105; -static PyObject *__pyx_k_tuple_120; -static PyObject *__pyx_k_tuple_132; -static PyObject *__pyx_k_tuple_136; -static PyObject *__pyx_k_tuple_137; -static PyObject *__pyx_k_codeobj_133; -static PyObject *__pyx_k_codeobj_138; +static PyObject *__pyx_k_tuple_97; +static PyObject *__pyx_k_tuple_98; +static PyObject *__pyx_k_tuple_102; +static PyObject *__pyx_k_tuple_107; +static PyObject *__pyx_k_tuple_122; +static PyObject *__pyx_k_tuple_134; +static PyObject *__pyx_k_tuple_138; +static PyObject *__pyx_k_tuple_139; +static PyObject *__pyx_k_codeobj_135; +static PyObject *__pyx_k_codeobj_140; /* "_sa.pyx":5 * import gzip @@ -6290,27 +6352,30 @@ static int __pyx_pw_3_sa_9DataArray_1__cinit__(PyObject *__pyx_v_self, PyObject static int __pyx_pw_3_sa_9DataArray_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_from_binary = 0; PyObject *__pyx_v_from_text = 0; + PyObject *__pyx_v_side = 0; int __pyx_v_use_sent_id; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__from_binary,&__pyx_n_s__from_text,&__pyx_n_s__use_sent_id,0}; - PyObject* values[3] = {0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__from_binary,&__pyx_n_s__from_text,&__pyx_n_s__side,&__pyx_n_s__use_sent_id,0}; + PyObject* values[4] = {0,0,0,0}; /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":17 * cdef bint use_sent_id * - * def __cinit__(self, from_binary=None, from_text=None, bint use_sent_id=False): # <<<<<<<<<<<<<< + * def __cinit__(self, from_binary=None, from_text=None, side=None, bint use_sent_id=False): # <<<<<<<<<<<<<< * self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} * self.id2word = ["END_OF_FILE", "END_OF_LINE"] */ values[0] = ((PyObject *)Py_None); values[1] = ((PyObject *)Py_None); + values[2] = ((PyObject *)Py_None); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -6331,15 +6396,21 @@ static int __pyx_pw_3_sa_9DataArray_1__cinit__(PyObject *__pyx_v_self, PyObject } case 2: if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_sent_id); + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__side); if (value) { values[2] = value; kw_args--; } } + case 3: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_sent_id); + if (value) { values[3] = value; kw_args--; } + } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -6349,32 +6420,34 @@ static int __pyx_pw_3_sa_9DataArray_1__cinit__(PyObject *__pyx_v_self, PyObject } __pyx_v_from_binary = values[0]; __pyx_v_from_text = values[1]; - if (values[2]) { - __pyx_v_use_sent_id = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_use_sent_id == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_side = values[2]; + if (values[3]) { + __pyx_v_use_sent_id = __Pyx_PyObject_IsTrue(values[3]); if (unlikely((__pyx_v_use_sent_id == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { __pyx_v_use_sent_id = ((int)0); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_sa.DataArray.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_3_sa_9DataArray___cinit__(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), __pyx_v_from_binary, __pyx_v_from_text, __pyx_v_use_sent_id); + __pyx_r = __pyx_pf_3_sa_9DataArray___cinit__(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), __pyx_v_from_binary, __pyx_v_from_text, __pyx_v_side, __pyx_v_use_sent_id); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_3_sa_9DataArray___cinit__(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text, int __pyx_v_use_sent_id) { +static int __pyx_pf_3_sa_9DataArray___cinit__(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text, PyObject *__pyx_v_side, int __pyx_v_use_sent_id) { int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; int __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; + long __pyx_t_5; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -6382,7 +6455,7 @@ static int __pyx_pf_3_sa_9DataArray___cinit__(struct __pyx_obj_3_sa_DataArray *_ /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":18 * - * def __cinit__(self, from_binary=None, from_text=None, bint use_sent_id=False): + * def __cinit__(self, from_binary=None, from_text=None, side=None, bint use_sent_id=False): * self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} # <<<<<<<<<<<<<< * self.id2word = ["END_OF_FILE", "END_OF_LINE"] * self.data = IntList(1000,1000) @@ -6398,7 +6471,7 @@ static int __pyx_pf_3_sa_9DataArray___cinit__(struct __pyx_obj_3_sa_DataArray *_ __pyx_t_1 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":19 - * def __cinit__(self, from_binary=None, from_text=None, bint use_sent_id=False): + * def __cinit__(self, from_binary=None, from_text=None, side=None, bint use_sent_id=False): * self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} * self.id2word = ["END_OF_FILE", "END_OF_LINE"] # <<<<<<<<<<<<<< * self.data = IntList(1000,1000) @@ -6487,7 +6560,7 @@ static int __pyx_pf_3_sa_9DataArray___cinit__(struct __pyx_obj_3_sa_DataArray *_ * if from_binary: * self.read_binary(from_binary) # <<<<<<<<<<<<<< * elif from_text: - * self.read_text(from_text) + * if side: */ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_binary); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); @@ -6508,8 +6581,8 @@ static int __pyx_pf_3_sa_9DataArray___cinit__(struct __pyx_obj_3_sa_DataArray *_ * if from_binary: * self.read_binary(from_binary) * elif from_text: # <<<<<<<<<<<<<< - * self.read_text(from_text) - * + * if side: + * self.read_bitext(from_text, (0 if side == 'source' else 1)) */ __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_text); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_2) { @@ -6517,22 +6590,68 @@ static int __pyx_pf_3_sa_9DataArray___cinit__(struct __pyx_obj_3_sa_DataArray *_ /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":27 * self.read_binary(from_binary) * elif from_text: - * self.read_text(from_text) # <<<<<<<<<<<<<< + * if side: # <<<<<<<<<<<<<< + * self.read_bitext(from_text, (0 if side == 'source' else 1)) + * else: + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_side); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":28 + * elif from_text: + * if side: + * self.read_bitext(from_text, (0 if side == 'source' else 1)) # <<<<<<<<<<<<<< + * else: + * self.read_text(from_text) + */ + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_bitext); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = __Pyx_PyString_Equals(__pyx_v_side, ((PyObject *)__pyx_n_s__source), Py_EQ); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + __pyx_t_5 = 0; + } else { + __pyx_t_5 = 1; + } + __pyx_t_3 = PyInt_FromLong(__pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_from_text); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_from_text); + __Pyx_GIVEREF(__pyx_v_from_text); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L4; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":30 + * self.read_bitext(from_text, (0 if side == 'source' else 1)) + * else: + * self.read_text(from_text) # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_text); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_from_text); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_text); - __Pyx_GIVEREF(__pyx_v_from_text); - __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_text); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_from_text); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_from_text); + __Pyx_GIVEREF(__pyx_v_from_text); + __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __pyx_L4:; goto __pyx_L3; } __pyx_L3:; @@ -6561,8 +6680,8 @@ static Py_ssize_t __pyx_pw_3_sa_9DataArray_3__len__(PyObject *__pyx_v_self) { return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":29 - * self.read_text(from_text) +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":32 + * self.read_text(from_text) * * def __len__(self): # <<<<<<<<<<<<<< * return len(self.data) @@ -6579,7 +6698,7 @@ static Py_ssize_t __pyx_pf_3_sa_9DataArray_2__len__(struct __pyx_obj_3_sa_DataAr int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__len__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":30 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":33 * * def __len__(self): * return len(self.data) # <<<<<<<<<<<<<< @@ -6588,7 +6707,7 @@ static Py_ssize_t __pyx_pf_3_sa_9DataArray_2__len__(struct __pyx_obj_3_sa_DataAr */ __pyx_t_1 = ((PyObject *)__pyx_v_self->data); __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; goto __pyx_L0; @@ -6615,7 +6734,7 @@ static PyObject *__pyx_pw_3_sa_9DataArray_5getSentId(PyObject *__pyx_v_self, PyO return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":32 +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":35 * return len(self.data) * * def getSentId(self, i): # <<<<<<<<<<<<<< @@ -6633,7 +6752,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_4getSentId(struct __pyx_obj_3_sa_DataA int __pyx_clineno = 0; __Pyx_RefNannySetupContext("getSentId", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":33 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":36 * * def getSentId(self, i): * return self.sent_id.arr[i] # <<<<<<<<<<<<<< @@ -6641,8 +6760,8 @@ static PyObject *__pyx_pf_3_sa_9DataArray_4getSentId(struct __pyx_obj_3_sa_DataA * def getSent(self, i): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromLong((__pyx_v_self->sent_id->arr[__pyx_t_1])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->sent_id->arr[__pyx_t_1])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; @@ -6671,7 +6790,7 @@ static PyObject *__pyx_pw_3_sa_9DataArray_7getSent(PyObject *__pyx_v_self, PyObj return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":35 +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":38 * return self.sent_id.arr[i] * * def getSent(self, i): # <<<<<<<<<<<<<< @@ -6696,42 +6815,42 @@ static PyObject *__pyx_pf_3_sa_9DataArray_6getSent(struct __pyx_obj_3_sa_DataArr __Pyx_RefNannySetupContext("getSent", 0); __Pyx_INCREF(__pyx_v_i); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":37 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":40 * def getSent(self, i): * cdef int j, start, stop * sent = [] # <<<<<<<<<<<<<< * start = self.sent_index.arr[i] * stop = self.sent_index.arr[i+1] */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_sent = __pyx_t_1; __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":38 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":41 * cdef int j, start, stop * sent = [] * start = self.sent_index.arr[i] # <<<<<<<<<<<<<< * stop = self.sent_index.arr[i+1] * for i from start <= i < stop: */ - __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_start = (__pyx_v_self->sent_index->arr[__pyx_t_2]); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":39 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":42 * sent = [] * start = self.sent_index.arr[i] * stop = self.sent_index.arr[i+1] # <<<<<<<<<<<<<< * for i from start <= i < stop: * sent.append(self.id2word[self.data.arr[i]]) */ - __pyx_t_1 = PyNumber_Add(__pyx_v_i, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyNumber_Add(__pyx_v_i, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_stop = (__pyx_v_self->sent_index->arr[__pyx_t_2]); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":40 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":43 * start = self.sent_index.arr[i] * stop = self.sent_index.arr[i+1] * for i from start <= i < stop: # <<<<<<<<<<<<<< @@ -6740,41 +6859,41 @@ static PyObject *__pyx_pf_3_sa_9DataArray_6getSent(struct __pyx_obj_3_sa_DataArr */ __pyx_t_3 = __pyx_v_stop; for (__pyx_t_4 = __pyx_v_start; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) { - __pyx_t_1 = PyInt_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyInt_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_v_i); __pyx_v_i = __pyx_t_1; __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":41 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":44 * stop = self.sent_index.arr[i+1] * for i from start <= i < stop: * sent.append(self.id2word[self.data.arr[i]]) # <<<<<<<<<<<<<< * return sent * */ - __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_self->id2word, (__pyx_v_self->data->arr[__pyx_t_2]), sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_v_i); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_self->id2word, (__pyx_v_self->data->arr[__pyx_t_2]), sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyList_Append(__pyx_v_sent, __pyx_t_1); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyList_Append(__pyx_v_sent, __pyx_t_1); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":40 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":43 * start = self.sent_index.arr[i] * stop = self.sent_index.arr[i+1] * for i from start <= i < stop: # <<<<<<<<<<<<<< * sent.append(self.id2word[self.data.arr[i]]) * return sent */ - __pyx_t_1 = PyInt_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyInt_FromLong(__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_v_i); __pyx_v_i = __pyx_t_1; __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":42 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":45 * for i from start <= i < stop: * sent.append(self.id2word[self.data.arr[i]]) * return sent # <<<<<<<<<<<<<< @@ -6811,7 +6930,7 @@ static PyObject *__pyx_pw_3_sa_9DataArray_9getSentPos(PyObject *__pyx_v_self, Py return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":44 +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":47 * return sent * * def getSentPos(self, loc): # <<<<<<<<<<<<<< @@ -6830,7 +6949,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_8getSentPos(struct __pyx_obj_3_sa_Data int __pyx_clineno = 0; __Pyx_RefNannySetupContext("getSentPos", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":45 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":48 * * def getSentPos(self, loc): * return loc - self.sent_index.arr[self.sent_id.arr[loc]] # <<<<<<<<<<<<<< @@ -6838,10 +6957,10 @@ static PyObject *__pyx_pf_3_sa_9DataArray_8getSentPos(struct __pyx_obj_3_sa_Data * def get_id(self, word): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_loc); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = PyInt_FromLong((__pyx_v_self->sent_index->arr[(__pyx_v_self->sent_id->arr[__pyx_t_1])])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_loc); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromLong((__pyx_v_self->sent_index->arr[(__pyx_v_self->sent_id->arr[__pyx_t_1])])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_Subtract(__pyx_v_loc, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyNumber_Subtract(__pyx_v_loc, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; @@ -6872,7 +6991,7 @@ static PyObject *__pyx_pw_3_sa_9DataArray_11get_id(PyObject *__pyx_v_self, PyObj return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":47 +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":50 * return loc - self.sent_index.arr[self.sent_id.arr[loc]] * * def get_id(self, word): # <<<<<<<<<<<<<< @@ -6892,18 +7011,18 @@ static PyObject *__pyx_pf_3_sa_9DataArray_10get_id(struct __pyx_obj_3_sa_DataArr int __pyx_clineno = 0; __Pyx_RefNannySetupContext("get_id", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":48 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":51 * * def get_id(self, word): * if not word in self.word2id: # <<<<<<<<<<<<<< * self.word2id[word] = len(self.id2word) * self.id2word.append(word) */ - __pyx_t_1 = ((PySequence_Contains(__pyx_v_self->word2id, __pyx_v_word))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = ((PySequence_Contains(__pyx_v_self->word2id, __pyx_v_word))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_2 = (!__pyx_t_1); if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":49 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":52 * def get_id(self, word): * if not word in self.word2id: * self.word2id[word] = len(self.id2word) # <<<<<<<<<<<<<< @@ -6912,28 +7031,28 @@ static PyObject *__pyx_pf_3_sa_9DataArray_10get_id(struct __pyx_obj_3_sa_DataArr */ __pyx_t_3 = __pyx_v_self->id2word; __Pyx_INCREF(__pyx_t_3); - __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - if (PyObject_SetItem(__pyx_v_self->word2id, __pyx_v_word, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetItem(__pyx_v_self->word2id, __pyx_v_word, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":50 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":53 * if not word in self.word2id: * self.word2id[word] = len(self.id2word) * self.id2word.append(word) # <<<<<<<<<<<<<< * return self.word2id[word] * */ - __pyx_t_3 = __Pyx_PyObject_Append(__pyx_v_self->id2word, __pyx_v_word); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyObject_Append(__pyx_v_self->id2word, __pyx_v_word); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":51 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":54 * self.word2id[word] = len(self.id2word) * self.id2word.append(word) * return self.word2id[word] # <<<<<<<<<<<<<< @@ -6941,7 +7060,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_10get_id(struct __pyx_obj_3_sa_DataArr * def get_word(self, id): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyObject_GetItem(__pyx_v_self->word2id, __pyx_v_word); if (!__pyx_t_3) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetItem(__pyx_v_self->word2id, __pyx_v_word); if (!__pyx_t_3) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; @@ -6970,7 +7089,7 @@ static PyObject *__pyx_pw_3_sa_9DataArray_13get_word(PyObject *__pyx_v_self, PyO return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":53 +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":56 * return self.word2id[word] * * def get_word(self, id): # <<<<<<<<<<<<<< @@ -6987,7 +7106,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_12get_word(struct __pyx_obj_3_sa_DataA int __pyx_clineno = 0; __Pyx_RefNannySetupContext("get_word", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":54 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":57 * * def get_word(self, id): * return self.id2word[id] # <<<<<<<<<<<<<< @@ -6995,7 +7114,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_12get_word(struct __pyx_obj_3_sa_DataA * def write_text(self, char* filename): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetItem(__pyx_v_self->id2word, __pyx_v_id); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetItem(__pyx_v_self->id2word, __pyx_v_id); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -7021,7 +7140,7 @@ static PyObject *__pyx_pw_3_sa_9DataArray_15write_text(PyObject *__pyx_v_self, P __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write_text (wrapper)", 0); assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -7034,7 +7153,7 @@ static PyObject *__pyx_pw_3_sa_9DataArray_15write_text(PyObject *__pyx_v_self, P return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":56 +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":59 * return self.id2word[id] * * def write_text(self, char* filename): # <<<<<<<<<<<<<< @@ -7066,7 +7185,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_14write_text(struct __pyx_obj_3_sa_Dat int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write_text", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":57 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":60 * * def write_text(self, char* filename): * with open(filename, "w") as f: # <<<<<<<<<<<<<< @@ -7074,9 +7193,9 @@ static PyObject *__pyx_pf_3_sa_9DataArray_14write_text(struct __pyx_obj_3_sa_Dat * if w_id > 1: */ /*with:*/ { - __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); @@ -7084,14 +7203,14 @@ static PyObject *__pyx_pf_3_sa_9DataArray_14write_text(struct __pyx_obj_3_sa_Dat PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -7106,7 +7225,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_14write_text(struct __pyx_obj_3_sa_Dat __pyx_v_f = __pyx_t_4; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":58 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":61 * def write_text(self, char* filename): * with open(filename, "w") as f: * for w_id in self.data: # <<<<<<<<<<<<<< @@ -7117,7 +7236,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_14write_text(struct __pyx_obj_3_sa_Dat __pyx_t_4 = ((PyObject *)__pyx_v_self->data); __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; __pyx_t_9 = NULL; } else { - __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(((PyObject *)__pyx_v_self->data)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(((PyObject *)__pyx_v_self->data)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; } @@ -7127,21 +7246,21 @@ static PyObject *__pyx_pf_3_sa_9DataArray_14write_text(struct __pyx_obj_3_sa_Dat #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; #endif } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; + __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; #endif } else { __pyx_t_1 = __pyx_t_9(__pyx_t_4); if (unlikely(!__pyx_t_1)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} } break; } @@ -7151,48 +7270,48 @@ static PyObject *__pyx_pf_3_sa_9DataArray_14write_text(struct __pyx_obj_3_sa_Dat __pyx_v_w_id = __pyx_t_1; __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":59 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":62 * with open(filename, "w") as f: * for w_id in self.data: * if w_id > 1: # <<<<<<<<<<<<<< * f.write("%s " % self.get_word(w_id)) * if w_id == 1: */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_w_id, __pyx_int_1, Py_GT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyObject_RichCompare(__pyx_v_w_id, __pyx_int_1, Py_GT); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_10) { - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":60 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":63 * for w_id in self.data: * if w_id > 1: * f.write("%s " % self.get_word(w_id)) # <<<<<<<<<<<<<< * if w_id == 1: * f.write("\n") */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_word); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_word); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_11); __Pyx_INCREF(__pyx_v_w_id); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_v_w_id); __Pyx_GIVEREF(__pyx_v_w_id); - __pyx_t_12 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_12 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; - __pyx_t_11 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_13), __pyx_t_12); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_11 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_13), __pyx_t_12); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_11)); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)__pyx_t_11)); __Pyx_GIVEREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; - __pyx_t_11 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_11 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_12), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_11); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; @@ -7201,29 +7320,29 @@ static PyObject *__pyx_pf_3_sa_9DataArray_14write_text(struct __pyx_obj_3_sa_Dat } __pyx_L18:; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":61 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":64 * if w_id > 1: * f.write("%s " % self.get_word(w_id)) * if w_id == 1: # <<<<<<<<<<<<<< * f.write("\n") * */ - __pyx_t_11 = PyObject_RichCompare(__pyx_v_w_id, __pyx_int_1, Py_EQ); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_11 = PyObject_RichCompare(__pyx_v_w_id, __pyx_int_1, Py_EQ); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_11); - __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; if (__pyx_t_10) { - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":62 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":65 * f.write("%s " % self.get_word(w_id)) * if w_id == 1: * f.write("\n") # <<<<<<<<<<<<<< * * def read_text(self, char* filename): */ - __pyx_t_11 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_11 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_11); - __pyx_t_12 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_k_tuple_15), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_12 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_k_tuple_15), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; @@ -7244,7 +7363,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_14write_text(struct __pyx_obj_3_sa_Dat __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":57 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":60 * * def write_text(self, char* filename): * with open(filename, "w") as f: # <<<<<<<<<<<<<< @@ -7253,11 +7372,11 @@ static PyObject *__pyx_pf_3_sa_9DataArray_14write_text(struct __pyx_obj_3_sa_Dat */ /*except:*/ { __Pyx_AddTraceback("_sa.DataArray.write_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_12, &__pyx_t_11) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_12, &__pyx_t_11) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_GOTREF(__pyx_t_12); __Pyx_GOTREF(__pyx_t_11); - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); @@ -7270,11 +7389,11 @@ static PyObject *__pyx_pf_3_sa_9DataArray_14write_text(struct __pyx_obj_3_sa_Dat __Pyx_GIVEREF(__pyx_t_11); __pyx_t_13 = PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} __Pyx_GOTREF(__pyx_t_13); __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_13); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} __pyx_t_14 = (!__pyx_t_10); if (__pyx_t_14) { __Pyx_GIVEREF(__pyx_t_4); @@ -7282,7 +7401,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_14write_text(struct __pyx_obj_3_sa_Dat __Pyx_GIVEREF(__pyx_t_11); __Pyx_ErrRestore(__pyx_t_4, __pyx_t_12, __pyx_t_11); __pyx_t_4 = 0; __pyx_t_12 = 0; __pyx_t_11 = 0; - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} goto __pyx_L22; } __pyx_L22:; @@ -7310,11 +7429,11 @@ static PyObject *__pyx_pf_3_sa_9DataArray_14write_text(struct __pyx_obj_3_sa_Dat if (__pyx_t_3) { __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_16, NULL); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_7); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } } goto __pyx_L23; @@ -7350,7 +7469,7 @@ static PyObject *__pyx_pw_3_sa_9DataArray_17read_text(PyObject *__pyx_v_self, Py __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_text (wrapper)", 0); assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -7363,20 +7482,16 @@ static PyObject *__pyx_pw_3_sa_9DataArray_17read_text(PyObject *__pyx_v_self, Py return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":64 +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":67 * f.write("\n") * * def read_text(self, char* filename): # <<<<<<<<<<<<<< - * cdef int word_count = 0 * with gzip_or_text(filename) as fp: + * self.read_text_data(fp) */ static PyObject *__pyx_pf_3_sa_9DataArray_16read_text(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { - int __pyx_v_word_count; PyObject *__pyx_v_fp = NULL; - PyObject *__pyx_v_line_num = NULL; - PyObject *__pyx_v_line = NULL; - PyObject *__pyx_v_word = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -7386,56 +7501,446 @@ static PyObject *__pyx_pf_3_sa_9DataArray_16read_text(struct __pyx_obj_3_sa_Data PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; PyObject *__pyx_t_7 = NULL; - Py_ssize_t __pyx_t_8; - PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; PyObject *__pyx_t_10 = NULL; - Py_ssize_t __pyx_t_11; - PyObject *(*__pyx_t_12)(PyObject *); - PyObject *__pyx_t_13 = NULL; - PyObject *__pyx_t_14 = NULL; - int __pyx_t_15; - PyObject *__pyx_t_16 = NULL; - int __pyx_t_17; + int __pyx_t_11; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_text", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":65 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":68 * * def read_text(self, char* filename): - * cdef int word_count = 0 # <<<<<<<<<<<<<< + * with gzip_or_text(filename) as fp: # <<<<<<<<<<<<<< + * self.read_text_data(fp) + * + */ + /*with:*/ { + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__gzip_or_text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __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[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__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_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_1); + __pyx_v_fp = __pyx_t_1; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":69 + * def read_text(self, char* filename): * with gzip_or_text(filename) as fp: - * for line_num, line in enumerate(fp): + * self.read_text_data(fp) # <<<<<<<<<<<<<< + * + * def read_bitext(self, char* filename, int side): */ - __pyx_v_word_count = 0; + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_text_data); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_fp); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_fp); + __Pyx_GIVEREF(__pyx_v_fp); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":66 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":68 + * * def read_text(self, char* filename): - * cdef int word_count = 0 * with gzip_or_text(filename) as fp: # <<<<<<<<<<<<<< - * for line_num, line in enumerate(fp): - * self.sent_index.append(word_count) + * self.read_text_data(fp) + * + */ + /*except:*/ { + __Pyx_AddTraceback("_sa.DataArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_2, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_10 = PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_10); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_11 = (!__pyx_t_9); + if (__pyx_t_11) { + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_ErrRestore(__pyx_t_3, __pyx_t_2, __pyx_t_1); + __pyx_t_3 = 0; __pyx_t_2 = 0; __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L18; + } + __pyx_L18:; + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_4) { + __pyx_t_7 = PyObject_Call(__pyx_t_4, __pyx_k_tuple_17, NULL); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L19; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L1_error; + __pyx_L19:; + } + + __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_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_sa.DataArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_fp); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9DataArray_19read_bitext(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_3_sa_9DataArray_19read_bitext(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + char *__pyx_v_filename; + int __pyx_v_side; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_bitext (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__filename,&__pyx_n_s__side,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__filename)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__side)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("read_bitext", 1, 2, 2, 1); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "read_bitext") < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_filename = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_side = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_side == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("read_bitext", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_sa.DataArray.read_bitext", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_3_sa_9DataArray_18read_bitext(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), __pyx_v_filename, __pyx_v_side); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_3_sa_9DataArray_11read_bitext_2generator3(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":73 + * def read_bitext(self, char* filename, int side): + * with gzip_or_text(filename) as fp: + * data = (line.split(' ||| ')[side] for line in fp) # <<<<<<<<<<<<<< + * self.read_text_data(data) + * + */ + +static PyObject *__pyx_pf_3_sa_9DataArray_11read_bitext_genexpr(PyObject *__pyx_self) { + struct __pyx_obj_3_sa___pyx_scope_struct_1_genexpr *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("genexpr", 0); + __pyx_cur_scope = (struct __pyx_obj_3_sa___pyx_scope_struct_1_genexpr *)__pyx_ptype_3_sa___pyx_scope_struct_1_genexpr->tp_new(__pyx_ptype_3_sa___pyx_scope_struct_1_genexpr, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_3_sa___pyx_scope_struct__read_bitext *) __pyx_self; + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_3_sa_9DataArray_11read_bitext_2generator3, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_sa.DataArray.read_bitext.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_3_sa_9DataArray_11read_bitext_2generator3(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_3_sa___pyx_scope_struct_1_genexpr *__pyx_cur_scope = ((struct __pyx_obj_3_sa___pyx_scope_struct_1_genexpr *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_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[3]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_fp)) { __Pyx_RaiseClosureNameError("fp"); {__pyx_filename = __pyx_f[3]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } + if (PyList_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_fp) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_fp)) { + __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_fp; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_fp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_line); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_line); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_cur_scope->__pyx_v_line = __pyx_t_4; + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_19), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_5, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_side, sizeof(int), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L6_resume_from_yield:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":71 + * self.read_text_data(fp) + * + * def read_bitext(self, char* filename, int side): # <<<<<<<<<<<<<< + * with gzip_or_text(filename) as fp: + * data = (line.split(' ||| ')[side] for line in fp) + */ + +static PyObject *__pyx_pf_3_sa_9DataArray_18read_bitext(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename, int __pyx_v_side) { + struct __pyx_obj_3_sa___pyx_scope_struct__read_bitext *__pyx_cur_scope; + PyObject *__pyx_v_data = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_bitext", 0); + __pyx_cur_scope = (struct __pyx_obj_3_sa___pyx_scope_struct__read_bitext *)__pyx_ptype_3_sa___pyx_scope_struct__read_bitext->tp_new(__pyx_ptype_3_sa___pyx_scope_struct__read_bitext, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_side = __pyx_v_side; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":72 + * + * def read_bitext(self, char* filename, int side): + * with gzip_or_text(filename) as fp: # <<<<<<<<<<<<<< + * data = (line.split(' ||| ')[side] for line in fp) + * self.read_text_data(data) */ /*with:*/ { - __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__gzip_or_text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__gzip_or_text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __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[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__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_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; @@ -7447,315 +7952,97 @@ static PyObject *__pyx_pf_3_sa_9DataArray_16read_text(struct __pyx_obj_3_sa_Data __Pyx_XGOTREF(__pyx_t_7); /*try:*/ { __Pyx_INCREF(__pyx_t_1); - __pyx_v_fp = __pyx_t_1; + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_fp = __pyx_t_1; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":67 - * cdef int word_count = 0 - * with gzip_or_text(filename) as fp: - * for line_num, line in enumerate(fp): # <<<<<<<<<<<<<< - * self.sent_index.append(word_count) - * for word in line.split(): - */ - __Pyx_INCREF(__pyx_int_0); - __pyx_t_1 = __pyx_int_0; - if (PyList_CheckExact(__pyx_v_fp) || PyTuple_CheckExact(__pyx_v_fp)) { - __pyx_t_2 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_9 = Py_TYPE(__pyx_t_2)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_2)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_COMPILING_IN_CPYTHON - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_3); __pyx_t_8++; - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; - #endif - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_2)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_2)) break; - #if CYTHON_COMPILING_IN_CPYTHON - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_8); __Pyx_INCREF(__pyx_t_3); __pyx_t_8++; - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; - #endif - } else { - __pyx_t_3 = __pyx_t_9(__pyx_t_2); - if (unlikely(!__pyx_t_3)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF(__pyx_v_line); - __pyx_v_line = __pyx_t_3; - __pyx_t_3 = 0; - __Pyx_INCREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_v_line_num); - __pyx_v_line_num = __pyx_t_1; - __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); - __pyx_t_1 = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":68 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":73 + * def read_bitext(self, char* filename, int side): * with gzip_or_text(filename) as fp: - * for line_num, line in enumerate(fp): - * self.sent_index.append(word_count) # <<<<<<<<<<<<<< - * for word in line.split(): - * self.data.append(self.get_id(word)) - */ - __pyx_t_3 = PyInt_FromLong(__pyx_v_word_count); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_10 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_index), __pyx_t_3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":69 - * for line_num, line in enumerate(fp): - * self.sent_index.append(word_count) - * for word in line.split(): # <<<<<<<<<<<<<< - * self.data.append(self.get_id(word)) - * if self.use_sent_id: - */ - __pyx_t_10 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_3 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) { - __pyx_t_10 = __pyx_t_3; __Pyx_INCREF(__pyx_t_10); __pyx_t_11 = 0; - __pyx_t_12 = NULL; - } else { - __pyx_t_11 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_12 = Py_TYPE(__pyx_t_10)->tp_iternext; - } - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - for (;;) { - if (!__pyx_t_12 && PyList_CheckExact(__pyx_t_10)) { - if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_10)) break; - #if CYTHON_COMPILING_IN_CPYTHON - __pyx_t_3 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_11); __Pyx_INCREF(__pyx_t_3); __pyx_t_11++; - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_10, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; - #endif - } else if (!__pyx_t_12 && PyTuple_CheckExact(__pyx_t_10)) { - if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_10)) break; - #if CYTHON_COMPILING_IN_CPYTHON - __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_11); __Pyx_INCREF(__pyx_t_3); __pyx_t_11++; - #else - __pyx_t_3 = PySequence_ITEM(__pyx_t_10, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;}; - #endif - } else { - __pyx_t_3 = __pyx_t_12(__pyx_t_10); - if (unlikely(!__pyx_t_3)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_3); - } - __Pyx_XDECREF(__pyx_v_word); - __pyx_v_word = __pyx_t_3; - __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":70 - * self.sent_index.append(word_count) - * for word in line.split(): - * self.data.append(self.get_id(word)) # <<<<<<<<<<<<<< - * if self.use_sent_id: - * self.sent_id.append(line_num) - */ - __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_id); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_INCREF(__pyx_v_word); - PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_v_word); - __Pyx_GIVEREF(__pyx_v_word); - __pyx_t_14 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_13), NULL); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; - __pyx_t_13 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->data), __pyx_t_14); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":71 - * for word in line.split(): - * self.data.append(self.get_id(word)) - * if self.use_sent_id: # <<<<<<<<<<<<<< - * self.sent_id.append(line_num) - * word_count = word_count + 1 - */ - if (__pyx_v_self->use_sent_id) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":72 - * self.data.append(self.get_id(word)) - * if self.use_sent_id: - * self.sent_id.append(line_num) # <<<<<<<<<<<<<< - * word_count = word_count + 1 - * self.data.append(1) - */ - __pyx_t_13 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_id), __pyx_v_line_num); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - goto __pyx_L20; - } - __pyx_L20:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":73 - * if self.use_sent_id: - * self.sent_id.append(line_num) - * word_count = word_count + 1 # <<<<<<<<<<<<<< - * self.data.append(1) - * if self.use_sent_id: - */ - __pyx_v_word_count = (__pyx_v_word_count + 1); - } - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":74 - * self.sent_id.append(line_num) - * word_count = word_count + 1 - * self.data.append(1) # <<<<<<<<<<<<<< - * if self.use_sent_id: - * self.sent_id.append(line_num) - */ - __pyx_t_10 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->data), __pyx_int_1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":75 - * word_count = word_count + 1 - * self.data.append(1) - * if self.use_sent_id: # <<<<<<<<<<<<<< - * self.sent_id.append(line_num) - * word_count = word_count + 1 - */ - if (__pyx_v_self->use_sent_id) { - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":76 - * self.data.append(1) - * if self.use_sent_id: - * self.sent_id.append(line_num) # <<<<<<<<<<<<<< - * word_count = word_count + 1 - * self.data.append(0) - */ - __pyx_t_10 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_id), __pyx_v_line_num); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - goto __pyx_L21; - } - __pyx_L21:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":77 - * if self.use_sent_id: - * self.sent_id.append(line_num) - * word_count = word_count + 1 # <<<<<<<<<<<<<< - * self.data.append(0) - * self.sent_index.append(word_count) - */ - __pyx_v_word_count = (__pyx_v_word_count + 1); - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":78 - * self.sent_id.append(line_num) - * word_count = word_count + 1 - * self.data.append(0) # <<<<<<<<<<<<<< - * self.sent_index.append(word_count) + * data = (line.split(' ||| ')[side] for line in fp) # <<<<<<<<<<<<<< + * self.read_text_data(data) * */ - __pyx_t_1 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->data), __pyx_int_0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = __pyx_pf_3_sa_9DataArray_11read_bitext_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_data = __pyx_t_1; + __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":79 - * word_count = word_count + 1 - * self.data.append(0) - * self.sent_index.append(word_count) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":74 + * with gzip_or_text(filename) as fp: + * data = (line.split(' ||| ')[side] for line in fp) + * self.read_text_data(data) # <<<<<<<<<<<<<< * - * def read_binary(self, char* filename): + * def read_text_data(self, data): */ - __pyx_t_1 = PyInt_FromLong(__pyx_v_word_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_text_data); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_index), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_data); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_data); + __Pyx_GIVEREF(__pyx_v_data); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; goto __pyx_L14_try_end; __pyx_L7_error:; - __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; - __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":66 - * def read_text(self, char* filename): - * cdef int word_count = 0 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":72 + * + * def read_bitext(self, char* filename, int side): * with gzip_or_text(filename) as fp: # <<<<<<<<<<<<<< - * for line_num, line in enumerate(fp): - * self.sent_index.append(word_count) + * data = (line.split(' ||| ')[side] for line in fp) + * self.read_text_data(data) */ /*except:*/ { - __Pyx_AddTraceback("_sa.DataArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_1, &__pyx_t_10) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_AddTraceback("_sa.DataArray.read_bitext", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_2, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_3); __Pyx_GOTREF(__pyx_t_2); __Pyx_GOTREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_13 = PyTuple_New(3); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_13); + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_INCREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); __Pyx_INCREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_10); - __pyx_t_16 = PyObject_Call(__pyx_t_4, __pyx_t_13, NULL); + __pyx_t_10 = PyObject_Call(__pyx_t_4, __pyx_t_8, NULL); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_16); - __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_16); - __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; - if (unlikely(__pyx_t_15 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __pyx_t_17 = (!__pyx_t_15); - if (__pyx_t_17) { + if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_10); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_11 = (!__pyx_t_9); + if (__pyx_t_11) { + __Pyx_GIVEREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_10); - __Pyx_ErrRestore(__pyx_t_2, __pyx_t_1, __pyx_t_10); - __pyx_t_2 = 0; __pyx_t_1 = 0; __pyx_t_10 = 0; - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - goto __pyx_L24; + __Pyx_ErrRestore(__pyx_t_3, __pyx_t_2, __pyx_t_1); + __pyx_t_3 = 0; __pyx_t_2 = 0; __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L18; } - __pyx_L24:; - __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; + __pyx_L18:; + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; goto __pyx_L8_exception_handled; } __pyx_L9_except_error:; @@ -7774,20 +8061,20 @@ static PyObject *__pyx_pf_3_sa_9DataArray_16read_text(struct __pyx_obj_3_sa_Data } /*finally:*/ { if (__pyx_t_4) { - __pyx_t_7 = PyObject_Call(__pyx_t_4, __pyx_k_tuple_17, NULL); + __pyx_t_7 = PyObject_Call(__pyx_t_4, __pyx_k_tuple_20, NULL); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); - __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_7); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_17 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } } - goto __pyx_L25; + goto __pyx_L19; __pyx_L3_error:; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L1_error; - __pyx_L25:; + __pyx_L19:; } __pyx_r = Py_None; __Pyx_INCREF(Py_None); @@ -7796,13 +8083,327 @@ static PyObject *__pyx_pf_3_sa_9DataArray_16read_text(struct __pyx_obj_3_sa_Data __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_sa.DataArray.read_bitext", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_data); + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_3_sa_9DataArray_21read_text_data(PyObject *__pyx_v_self, PyObject *__pyx_v_data); /*proto*/ +static PyObject *__pyx_pw_3_sa_9DataArray_21read_text_data(PyObject *__pyx_v_self, PyObject *__pyx_v_data) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_text_data (wrapper)", 0); + __pyx_r = __pyx_pf_3_sa_9DataArray_20read_text_data(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_data)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":76 + * self.read_text_data(data) + * + * def read_text_data(self, data): # <<<<<<<<<<<<<< + * cdef int word_count = 0 + * for line_num, line in enumerate(data): + */ + +static PyObject *__pyx_pf_3_sa_9DataArray_20read_text_data(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_data) { + int __pyx_v_word_count; + PyObject *__pyx_v_line_num = NULL; + PyObject *__pyx_v_line = NULL; + PyObject *__pyx_v_word = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_3; + PyObject *(*__pyx_t_4)(PyObject *); + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + Py_ssize_t __pyx_t_7; + PyObject *(*__pyx_t_8)(PyObject *); + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_text_data", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":77 + * + * def read_text_data(self, data): + * cdef int word_count = 0 # <<<<<<<<<<<<<< + * for line_num, line in enumerate(data): + * self.sent_index.append(word_count) + */ + __pyx_v_word_count = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":78 + * def read_text_data(self, data): + * cdef int word_count = 0 + * for line_num, line in enumerate(data): # <<<<<<<<<<<<<< + * self.sent_index.append(word_count) + * for word in line.split(): + */ + __Pyx_INCREF(__pyx_int_0); + __pyx_t_1 = __pyx_int_0; + if (PyList_CheckExact(__pyx_v_data) || PyTuple_CheckExact(__pyx_v_data)) { + __pyx_t_2 = __pyx_v_data; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_data); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; + } + for (;;) { + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_2)) { + if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_2)) { + if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_5 = __pyx_t_4(__pyx_t_2); + if (unlikely(!__pyx_t_5)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_5); + } + __Pyx_XDECREF(__pyx_v_line); + __pyx_v_line = __pyx_t_5; + __pyx_t_5 = 0; + __Pyx_INCREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_v_line_num); + __pyx_v_line_num = __pyx_t_1; + __pyx_t_5 = PyNumber_Add(__pyx_t_1, __pyx_int_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); + __pyx_t_1 = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":79 + * cdef int word_count = 0 + * for line_num, line in enumerate(data): + * self.sent_index.append(word_count) # <<<<<<<<<<<<<< + * for word in line.split(): + * self.data.append(self.get_id(word)) + */ + __pyx_t_5 = PyInt_FromLong(__pyx_v_word_count); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_index), __pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":80 + * for line_num, line in enumerate(data): + * self.sent_index.append(word_count) + * for word in line.split(): # <<<<<<<<<<<<<< + * self.data.append(self.get_id(word)) + * if self.use_sent_id: + */ + __pyx_t_6 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (PyList_CheckExact(__pyx_t_5) || PyTuple_CheckExact(__pyx_t_5)) { + __pyx_t_6 = __pyx_t_5; __Pyx_INCREF(__pyx_t_6); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + } else { + __pyx_t_7 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_8 = Py_TYPE(__pyx_t_6)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + for (;;) { + if (!__pyx_t_8 && PyList_CheckExact(__pyx_t_6)) { + if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_6)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_7); __Pyx_INCREF(__pyx_t_5); __pyx_t_7++; + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_6, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_8 && PyTuple_CheckExact(__pyx_t_6)) { + if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_6)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_7); __Pyx_INCREF(__pyx_t_5); __pyx_t_7++; + #else + __pyx_t_5 = PySequence_ITEM(__pyx_t_6, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_5 = __pyx_t_8(__pyx_t_6); + if (unlikely(!__pyx_t_5)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_5); + } + __Pyx_XDECREF(__pyx_v_word); + __pyx_v_word = __pyx_t_5; + __pyx_t_5 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":81 + * self.sent_index.append(word_count) + * for word in line.split(): + * self.data.append(self.get_id(word)) # <<<<<<<<<<<<<< + * if self.use_sent_id: + * self.sent_id.append(line_num) + */ + __pyx_t_5 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__get_id); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_INCREF(__pyx_v_word); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_word); + __Pyx_GIVEREF(__pyx_v_word); + __pyx_t_10 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + __pyx_t_9 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->data), __pyx_t_10); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":82 + * for word in line.split(): + * self.data.append(self.get_id(word)) + * if self.use_sent_id: # <<<<<<<<<<<<<< + * self.sent_id.append(line_num) + * word_count = word_count + 1 + */ + if (__pyx_v_self->use_sent_id) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":83 + * self.data.append(self.get_id(word)) + * if self.use_sent_id: + * self.sent_id.append(line_num) # <<<<<<<<<<<<<< + * word_count = word_count + 1 + * self.data.append(1) + */ + __pyx_t_9 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_id), __pyx_v_line_num); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L7; + } + __pyx_L7:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":84 + * if self.use_sent_id: + * self.sent_id.append(line_num) + * word_count = word_count + 1 # <<<<<<<<<<<<<< + * self.data.append(1) + * if self.use_sent_id: + */ + __pyx_v_word_count = (__pyx_v_word_count + 1); + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":85 + * self.sent_id.append(line_num) + * word_count = word_count + 1 + * self.data.append(1) # <<<<<<<<<<<<<< + * if self.use_sent_id: + * self.sent_id.append(line_num) + */ + __pyx_t_6 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->data), __pyx_int_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":86 + * word_count = word_count + 1 + * self.data.append(1) + * if self.use_sent_id: # <<<<<<<<<<<<<< + * self.sent_id.append(line_num) + * word_count = word_count + 1 + */ + if (__pyx_v_self->use_sent_id) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":87 + * self.data.append(1) + * if self.use_sent_id: + * self.sent_id.append(line_num) # <<<<<<<<<<<<<< + * word_count = word_count + 1 + * self.data.append(0) + */ + __pyx_t_6 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_id), __pyx_v_line_num); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L8; + } + __pyx_L8:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":88 + * if self.use_sent_id: + * self.sent_id.append(line_num) + * word_count = word_count + 1 # <<<<<<<<<<<<<< + * self.data.append(0) + * self.sent_index.append(word_count) + */ + __pyx_v_word_count = (__pyx_v_word_count + 1); + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":89 + * self.sent_id.append(line_num) + * word_count = word_count + 1 + * self.data.append(0) # <<<<<<<<<<<<<< + * self.sent_index.append(word_count) + * + */ + __pyx_t_1 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->data), __pyx_int_0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":90 + * word_count = word_count + 1 + * self.data.append(0) + * self.sent_index.append(word_count) # <<<<<<<<<<<<<< + * + * + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_word_count); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_Append(((PyObject *)__pyx_v_self->sent_index), __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + __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_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_9); __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_13); - __Pyx_XDECREF(__pyx_t_14); - __Pyx_AddTraceback("_sa.DataArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_sa.DataArray.read_text_data", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_fp); __Pyx_XDECREF(__pyx_v_line_num); __Pyx_XDECREF(__pyx_v_line); __Pyx_XDECREF(__pyx_v_word); @@ -7812,14 +8413,14 @@ static PyObject *__pyx_pf_3_sa_9DataArray_16read_text(struct __pyx_obj_3_sa_Data } /* Python wrapper */ -static PyObject *__pyx_pw_3_sa_9DataArray_19read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_3_sa_9DataArray_19read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { +static PyObject *__pyx_pw_3_sa_9DataArray_23read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_9DataArray_23read_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { char *__pyx_v_filename; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_binary (wrapper)", 0); assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -7827,26 +8428,26 @@ static PyObject *__pyx_pw_3_sa_9DataArray_19read_binary(PyObject *__pyx_v_self, __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_3_sa_9DataArray_18read_binary(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __pyx_r = __pyx_pf_3_sa_9DataArray_22read_binary(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":81 - * self.sent_index.append(word_count) +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":93 + * * * def read_binary(self, char* filename): # <<<<<<<<<<<<<< * cdef FILE* f * f = fopen(filename, "r") */ -static PyObject *__pyx_pf_3_sa_9DataArray_18read_binary(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { +static PyObject *__pyx_pf_3_sa_9DataArray_22read_binary(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { FILE *__pyx_v_f; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_binary", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":83 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":95 * def read_binary(self, char* filename): * cdef FILE* f * f = fopen(filename, "r") # <<<<<<<<<<<<<< @@ -7855,7 +8456,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_18read_binary(struct __pyx_obj_3_sa_Da */ __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__r); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":84 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":96 * cdef FILE* f * f = fopen(filename, "r") * self.read_handle(f) # <<<<<<<<<<<<<< @@ -7864,7 +8465,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_18read_binary(struct __pyx_obj_3_sa_Da */ ((struct __pyx_vtabstruct_3_sa_DataArray *)__pyx_v_self->__pyx_vtab)->read_handle(__pyx_v_self, __pyx_v_f); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":85 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":97 * f = fopen(filename, "r") * self.read_handle(f) * fclose(f) # <<<<<<<<<<<<<< @@ -7879,7 +8480,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_18read_binary(struct __pyx_obj_3_sa_Da return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":87 +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":99 * fclose(f) * * cdef void read_handle(self, FILE* f): # <<<<<<<<<<<<<< @@ -7904,7 +8505,7 @@ static void __pyx_f_3_sa_9DataArray_read_handle(struct __pyx_obj_3_sa_DataArray int __pyx_clineno = 0; __Pyx_RefNannySetupContext("read_handle", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":92 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":104 * cdef char* c_word * cdef bytes py_word * self.data.read_handle(f) # <<<<<<<<<<<<<< @@ -7913,7 +8514,7 @@ static void __pyx_f_3_sa_9DataArray_read_handle(struct __pyx_obj_3_sa_DataArray */ ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->data->__pyx_vtab)->read_handle(__pyx_v_self->data, __pyx_v_f); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":93 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":105 * cdef bytes py_word * self.data.read_handle(f) * self.sent_index.read_handle(f) # <<<<<<<<<<<<<< @@ -7922,7 +8523,7 @@ static void __pyx_f_3_sa_9DataArray_read_handle(struct __pyx_obj_3_sa_DataArray */ ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->sent_index->__pyx_vtab)->read_handle(__pyx_v_self->sent_index, __pyx_v_f); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":94 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":106 * self.data.read_handle(f) * self.sent_index.read_handle(f) * self.sent_id.read_handle(f) # <<<<<<<<<<<<<< @@ -7931,7 +8532,7 @@ static void __pyx_f_3_sa_9DataArray_read_handle(struct __pyx_obj_3_sa_DataArray */ ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->sent_id->__pyx_vtab)->read_handle(__pyx_v_self->sent_id, __pyx_v_f); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":95 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":107 * self.sent_index.read_handle(f) * self.sent_id.read_handle(f) * fread(&(num_words), sizeof(int), 1, f) # <<<<<<<<<<<<<< @@ -7940,7 +8541,7 @@ static void __pyx_f_3_sa_9DataArray_read_handle(struct __pyx_obj_3_sa_DataArray */ fread((&__pyx_v_num_words), (sizeof(int)), 1, __pyx_v_f); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":96 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":108 * self.sent_id.read_handle(f) * fread(&(num_words), sizeof(int), 1, f) * for i in range(num_words): # <<<<<<<<<<<<<< @@ -7951,7 +8552,7 @@ static void __pyx_f_3_sa_9DataArray_read_handle(struct __pyx_obj_3_sa_DataArray for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":97 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":109 * fread(&(num_words), sizeof(int), 1, f) * for i in range(num_words): * fread(&(word_len), sizeof(int), 1, f) # <<<<<<<<<<<<<< @@ -7960,7 +8561,7 @@ static void __pyx_f_3_sa_9DataArray_read_handle(struct __pyx_obj_3_sa_DataArray */ fread((&__pyx_v_word_len), (sizeof(int)), 1, __pyx_v_f); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":98 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":110 * for i in range(num_words): * fread(&(word_len), sizeof(int), 1, f) * c_word = malloc (word_len * sizeof(char)) # <<<<<<<<<<<<<< @@ -7969,7 +8570,7 @@ static void __pyx_f_3_sa_9DataArray_read_handle(struct __pyx_obj_3_sa_DataArray */ __pyx_v_c_word = ((char *)malloc((__pyx_v_word_len * (sizeof(char))))); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":99 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":111 * fread(&(word_len), sizeof(int), 1, f) * c_word = malloc (word_len * sizeof(char)) * fread(c_word, sizeof(char), word_len, f) # <<<<<<<<<<<<<< @@ -7978,20 +8579,20 @@ static void __pyx_f_3_sa_9DataArray_read_handle(struct __pyx_obj_3_sa_DataArray */ fread(__pyx_v_c_word, (sizeof(char)), __pyx_v_word_len, __pyx_v_f); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":100 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":112 * c_word = malloc (word_len * sizeof(char)) * fread(c_word, sizeof(char), word_len, f) * py_word = c_word # <<<<<<<<<<<<<< * free(c_word) * self.word2id[py_word] = len(self.id2word) */ - __pyx_t_3 = PyBytes_FromString(__pyx_v_c_word); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyBytes_FromString(__pyx_v_c_word); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_XDECREF(((PyObject *)__pyx_v_py_word)); __pyx_v_py_word = __pyx_t_3; __pyx_t_3 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":101 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":113 * fread(c_word, sizeof(char), word_len, f) * py_word = c_word * free(c_word) # <<<<<<<<<<<<<< @@ -8000,7 +8601,7 @@ static void __pyx_f_3_sa_9DataArray_read_handle(struct __pyx_obj_3_sa_DataArray */ free(__pyx_v_c_word); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":102 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":114 * py_word = c_word * free(c_word) * self.word2id[py_word] = len(self.id2word) # <<<<<<<<<<<<<< @@ -8009,26 +8610,26 @@ static void __pyx_f_3_sa_9DataArray_read_handle(struct __pyx_obj_3_sa_DataArray */ __pyx_t_3 = __pyx_v_self->id2word; __Pyx_INCREF(__pyx_t_3); - __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - if (PyObject_SetItem(__pyx_v_self->word2id, ((PyObject *)__pyx_v_py_word), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetItem(__pyx_v_self->word2id, ((PyObject *)__pyx_v_py_word), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":103 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":115 * free(c_word) * self.word2id[py_word] = len(self.id2word) * self.id2word.append(py_word) # <<<<<<<<<<<<<< * if len(self.sent_id) == 0: * self.use_sent_id = False */ - __pyx_t_3 = __Pyx_PyObject_Append(__pyx_v_self->id2word, ((PyObject *)__pyx_v_py_word)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyObject_Append(__pyx_v_self->id2word, ((PyObject *)__pyx_v_py_word)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":104 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":116 * self.word2id[py_word] = len(self.id2word) * self.id2word.append(py_word) * if len(self.sent_id) == 0: # <<<<<<<<<<<<<< @@ -8037,12 +8638,12 @@ static void __pyx_f_3_sa_9DataArray_read_handle(struct __pyx_obj_3_sa_DataArray */ __pyx_t_3 = ((PyObject *)__pyx_v_self->sent_id); __Pyx_INCREF(__pyx_t_3); - __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_5 = (__pyx_t_4 == 0); if (__pyx_t_5) { - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":105 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":117 * self.id2word.append(py_word) * if len(self.sent_id) == 0: * self.use_sent_id = False # <<<<<<<<<<<<<< @@ -8054,7 +8655,7 @@ static void __pyx_f_3_sa_9DataArray_read_handle(struct __pyx_obj_3_sa_DataArray } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":107 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":119 * self.use_sent_id = False * else: * self.use_sent_id = True # <<<<<<<<<<<<<< @@ -8074,7 +8675,7 @@ static void __pyx_f_3_sa_9DataArray_read_handle(struct __pyx_obj_3_sa_DataArray __Pyx_RefNannyFinishContext(); } -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":109 +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":121 * self.use_sent_id = True * * cdef void write_handle(self, FILE* f): # <<<<<<<<<<<<<< @@ -8098,7 +8699,7 @@ static void __pyx_f_3_sa_9DataArray_write_handle(struct __pyx_obj_3_sa_DataArray int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write_handle", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":113 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":125 * cdef int num_words * cdef char* c_word * self.data.write_handle(f) # <<<<<<<<<<<<<< @@ -8107,7 +8708,7 @@ static void __pyx_f_3_sa_9DataArray_write_handle(struct __pyx_obj_3_sa_DataArray */ ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->data->__pyx_vtab)->write_handle(__pyx_v_self->data, __pyx_v_f); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":114 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":126 * cdef char* c_word * self.data.write_handle(f) * self.sent_index.write_handle(f) # <<<<<<<<<<<<<< @@ -8116,7 +8717,7 @@ static void __pyx_f_3_sa_9DataArray_write_handle(struct __pyx_obj_3_sa_DataArray */ ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->sent_index->__pyx_vtab)->write_handle(__pyx_v_self->sent_index, __pyx_v_f); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":115 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":127 * self.data.write_handle(f) * self.sent_index.write_handle(f) * self.sent_id.write_handle(f) # <<<<<<<<<<<<<< @@ -8125,7 +8726,7 @@ static void __pyx_f_3_sa_9DataArray_write_handle(struct __pyx_obj_3_sa_DataArray */ ((struct __pyx_vtabstruct_3_sa_IntList *)__pyx_v_self->sent_id->__pyx_vtab)->write_handle(__pyx_v_self->sent_id, __pyx_v_f); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":116 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":128 * self.sent_index.write_handle(f) * self.sent_id.write_handle(f) * num_words = len(self.id2word) - 2 # <<<<<<<<<<<<<< @@ -8134,11 +8735,11 @@ static void __pyx_f_3_sa_9DataArray_write_handle(struct __pyx_obj_3_sa_DataArray */ __pyx_t_1 = __pyx_v_self->id2word; __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_num_words = (__pyx_t_2 - 2); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":117 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":129 * self.sent_id.write_handle(f) * num_words = len(self.id2word) - 2 * fwrite(&(num_words), sizeof(int), 1, f) # <<<<<<<<<<<<<< @@ -8147,20 +8748,20 @@ static void __pyx_f_3_sa_9DataArray_write_handle(struct __pyx_obj_3_sa_DataArray */ fwrite((&__pyx_v_num_words), (sizeof(int)), 1, __pyx_v_f); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":118 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":130 * num_words = len(self.id2word) - 2 * fwrite(&(num_words), sizeof(int), 1, f) * for word in self.id2word[2:]: # <<<<<<<<<<<<<< * c_word = word * word_len = strlen(c_word) + 1 */ - __pyx_t_1 = __Pyx_PySequence_GetSlice(__pyx_v_self->id2word, 2, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PySequence_GetSlice(__pyx_v_self->id2word, 2, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = 0; __pyx_t_4 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; } @@ -8171,21 +8772,21 @@ static void __pyx_f_3_sa_9DataArray_write_handle(struct __pyx_obj_3_sa_DataArray #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; #endif } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; #endif } else { __pyx_t_1 = __pyx_t_4(__pyx_t_3); if (unlikely(!__pyx_t_1)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } @@ -8195,17 +8796,17 @@ static void __pyx_f_3_sa_9DataArray_write_handle(struct __pyx_obj_3_sa_DataArray __pyx_v_word = __pyx_t_1; __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":119 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":131 * fwrite(&(num_words), sizeof(int), 1, f) * for word in self.id2word[2:]: * c_word = word # <<<<<<<<<<<<<< * word_len = strlen(c_word) + 1 * fwrite(&(word_len), sizeof(int), 1, f) */ - __pyx_t_5 = PyBytes_AsString(__pyx_v_word); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 119; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyBytes_AsString(__pyx_v_word); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_c_word = __pyx_t_5; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":120 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":132 * for word in self.id2word[2:]: * c_word = word * word_len = strlen(c_word) + 1 # <<<<<<<<<<<<<< @@ -8214,7 +8815,7 @@ static void __pyx_f_3_sa_9DataArray_write_handle(struct __pyx_obj_3_sa_DataArray */ __pyx_v_word_len = (strlen(__pyx_v_c_word) + 1); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":121 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":133 * c_word = word * word_len = strlen(c_word) + 1 * fwrite(&(word_len), sizeof(int), 1, f) # <<<<<<<<<<<<<< @@ -8223,7 +8824,7 @@ static void __pyx_f_3_sa_9DataArray_write_handle(struct __pyx_obj_3_sa_DataArray */ fwrite((&__pyx_v_word_len), (sizeof(int)), 1, __pyx_v_f); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":122 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":134 * word_len = strlen(c_word) + 1 * fwrite(&(word_len), sizeof(int), 1, f) * fwrite(c_word, sizeof(char), word_len, f) # <<<<<<<<<<<<<< @@ -8245,14 +8846,14 @@ static void __pyx_f_3_sa_9DataArray_write_handle(struct __pyx_obj_3_sa_DataArray } /* Python wrapper */ -static PyObject *__pyx_pw_3_sa_9DataArray_21write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_3_sa_9DataArray_21write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { +static PyObject *__pyx_pw_3_sa_9DataArray_25write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_9DataArray_25write_binary(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { char *__pyx_v_filename; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write_binary (wrapper)", 0); assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -8260,12 +8861,12 @@ static PyObject *__pyx_pw_3_sa_9DataArray_21write_binary(PyObject *__pyx_v_self, __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_3_sa_9DataArray_20write_binary(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __pyx_r = __pyx_pf_3_sa_9DataArray_24write_binary(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":124 +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":136 * fwrite(c_word, sizeof(char), word_len, f) * * def write_binary(self, char* filename): # <<<<<<<<<<<<<< @@ -8273,13 +8874,13 @@ static PyObject *__pyx_pw_3_sa_9DataArray_21write_binary(PyObject *__pyx_v_self, * f = fopen(filename, "w") */ -static PyObject *__pyx_pf_3_sa_9DataArray_20write_binary(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { +static PyObject *__pyx_pf_3_sa_9DataArray_24write_binary(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { FILE *__pyx_v_f; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write_binary", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":126 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":138 * def write_binary(self, char* filename): * cdef FILE* f * f = fopen(filename, "w") # <<<<<<<<<<<<<< @@ -8288,7 +8889,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_20write_binary(struct __pyx_obj_3_sa_D */ __pyx_v_f = fopen(__pyx_v_filename, __pyx_k__w); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":127 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":139 * cdef FILE* f * f = fopen(filename, "w") * self.write_handle(f) # <<<<<<<<<<<<<< @@ -8297,7 +8898,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_20write_binary(struct __pyx_obj_3_sa_D */ ((struct __pyx_vtabstruct_3_sa_DataArray *)__pyx_v_self->__pyx_vtab)->write_handle(__pyx_v_self, __pyx_v_f); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":128 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":140 * f = fopen(filename, "w") * self.write_handle(f) * fclose(f) # <<<<<<<<<<<<<< @@ -8313,17 +8914,17 @@ static PyObject *__pyx_pf_3_sa_9DataArray_20write_binary(struct __pyx_obj_3_sa_D } /* Python wrapper */ -static PyObject *__pyx_pw_3_sa_9DataArray_23write_enhanced_handle(PyObject *__pyx_v_self, PyObject *__pyx_v_f); /*proto*/ -static PyObject *__pyx_pw_3_sa_9DataArray_23write_enhanced_handle(PyObject *__pyx_v_self, PyObject *__pyx_v_f) { +static PyObject *__pyx_pw_3_sa_9DataArray_27write_enhanced_handle(PyObject *__pyx_v_self, PyObject *__pyx_v_f); /*proto*/ +static PyObject *__pyx_pw_3_sa_9DataArray_27write_enhanced_handle(PyObject *__pyx_v_self, PyObject *__pyx_v_f) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write_enhanced_handle (wrapper)", 0); - __pyx_r = __pyx_pf_3_sa_9DataArray_22write_enhanced_handle(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_f)); + __pyx_r = __pyx_pf_3_sa_9DataArray_26write_enhanced_handle(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((PyObject *)__pyx_v_f)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":130 +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":142 * fclose(f) * * def write_enhanced_handle(self, f): # <<<<<<<<<<<<<< @@ -8331,7 +8932,7 @@ static PyObject *__pyx_pw_3_sa_9DataArray_23write_enhanced_handle(PyObject *__py * f.write("%d " %i) */ -static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_f) { +static PyObject *__pyx_pf_3_sa_9DataArray_26write_enhanced_handle(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, PyObject *__pyx_v_f) { PyObject *__pyx_v_i = NULL; PyObject *__pyx_v_word = NULL; PyObject *__pyx_r = NULL; @@ -8347,7 +8948,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write_enhanced_handle", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":131 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":143 * * def write_enhanced_handle(self, f): * for i in self.data: # <<<<<<<<<<<<<< @@ -8358,7 +8959,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o __pyx_t_1 = ((PyObject *)__pyx_v_self->data); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; __pyx_t_3 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self->data)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_self->data)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; } @@ -8368,21 +8969,21 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; #endif } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; #endif } else { __pyx_t_4 = __pyx_t_3(__pyx_t_1); if (unlikely(!__pyx_t_4)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } @@ -8392,23 +8993,23 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o __pyx_v_i = __pyx_t_4; __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":132 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":144 * def write_enhanced_handle(self, f): * for i in self.data: * f.write("%d " %i) # <<<<<<<<<<<<<< * f.write("\n") * for i in self.sent_index: */ - __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_21), __pyx_v_i); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_t_5)); __Pyx_GIVEREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; @@ -8416,21 +9017,21 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":133 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":145 * for i in self.data: * f.write("%d " %i) * f.write("\n") # <<<<<<<<<<<<<< * for i in self.sent_index: * f.write("%d " %i) */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_19), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_22), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":134 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":146 * f.write("%d " %i) * f.write("\n") * for i in self.sent_index: # <<<<<<<<<<<<<< @@ -8441,7 +9042,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o __pyx_t_5 = ((PyObject *)__pyx_v_self->sent_index); __Pyx_INCREF(__pyx_t_5); __pyx_t_2 = 0; __pyx_t_3 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_5 = PyObject_GetIter(((PyObject *)__pyx_v_self->sent_index)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = -1; __pyx_t_5 = PyObject_GetIter(((PyObject *)__pyx_v_self->sent_index)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = Py_TYPE(__pyx_t_5)->tp_iternext; } @@ -8451,21 +9052,21 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_1 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_5, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_t_1 = PySequence_ITEM(__pyx_t_5, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; #endif } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_5)) { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_5)) break; #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_2); __Pyx_INCREF(__pyx_t_1); __pyx_t_2++; #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_5, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_t_1 = PySequence_ITEM(__pyx_t_5, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; #endif } else { __pyx_t_1 = __pyx_t_3(__pyx_t_5); if (unlikely(!__pyx_t_1)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } @@ -8475,23 +9076,23 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o __pyx_v_i = __pyx_t_1; __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":135 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":147 * f.write("\n") * for i in self.sent_index: * f.write("%d " %i) # <<<<<<<<<<<<<< * f.write("\n") * for i in self.sent_id: */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_21), __pyx_v_i); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_6)); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_6)); __Pyx_GIVEREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; @@ -8499,21 +9100,21 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":136 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":148 * for i in self.sent_index: * f.write("%d " %i) * f.write("\n") # <<<<<<<<<<<<<< * for i in self.sent_id: * f.write("%d " %i) */ - __pyx_t_5 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_6 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_23), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":137 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":149 * f.write("%d " %i) * f.write("\n") * for i in self.sent_id: # <<<<<<<<<<<<<< @@ -8524,7 +9125,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o __pyx_t_6 = ((PyObject *)__pyx_v_self->sent_id); __Pyx_INCREF(__pyx_t_6); __pyx_t_2 = 0; __pyx_t_3 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_6 = PyObject_GetIter(((PyObject *)__pyx_v_self->sent_id)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = -1; __pyx_t_6 = PyObject_GetIter(((PyObject *)__pyx_v_self->sent_id)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __pyx_t_3 = Py_TYPE(__pyx_t_6)->tp_iternext; } @@ -8534,21 +9135,21 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_5 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_6, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_t_5 = PySequence_ITEM(__pyx_t_6, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; #endif } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_6)) { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_6)) break; #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_2); __Pyx_INCREF(__pyx_t_5); __pyx_t_2++; #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_6, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_t_5 = PySequence_ITEM(__pyx_t_6, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; #endif } else { __pyx_t_5 = __pyx_t_3(__pyx_t_6); if (unlikely(!__pyx_t_5)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } @@ -8558,23 +9159,23 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o __pyx_v_i = __pyx_t_5; __pyx_t_5 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":138 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":150 * f.write("\n") * for i in self.sent_id: * f.write("%d " %i) # <<<<<<<<<<<<<< * f.write("\n") * for word in self.id2word: */ - __pyx_t_5 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_21), __pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4)); __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; @@ -8582,21 +9183,21 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o } __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":139 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":151 * for i in self.sent_id: * f.write("%d " %i) * f.write("\n") # <<<<<<<<<<<<<< * for word in self.id2word: * f.write("%s %d " % (word, self.word2id[word])) */ - __pyx_t_6 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - __pyx_t_4 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_k_tuple_21), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":140 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":152 * f.write("%d " %i) * f.write("\n") * for word in self.id2word: # <<<<<<<<<<<<<< @@ -8607,7 +9208,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o __pyx_t_4 = __pyx_v_self->id2word; __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = 0; __pyx_t_3 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_self->id2word); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_self->id2word); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = Py_TYPE(__pyx_t_4)->tp_iternext; } @@ -8617,21 +9218,21 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_6); __pyx_t_2++; #else - __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; #endif } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_4)) { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_4)) break; #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_2); __Pyx_INCREF(__pyx_t_6); __pyx_t_2++; #else - __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; #endif } else { __pyx_t_6 = __pyx_t_3(__pyx_t_4); if (unlikely(!__pyx_t_6)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[3]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } @@ -8641,18 +9242,18 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o __pyx_v_word = __pyx_t_6; __pyx_t_6 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":141 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":153 * f.write("\n") * for word in self.id2word: * f.write("%s %d " % (word, self.word2id[word])) # <<<<<<<<<<<<<< * f.write("\n") * */ - __pyx_t_6 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - __pyx_t_1 = PyObject_GetItem(__pyx_v_self->word2id, __pyx_v_word); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetItem(__pyx_v_self->word2id, __pyx_v_word); if (!__pyx_t_1) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF(__pyx_v_word); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_word); @@ -8660,15 +9261,15 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_22), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_25), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; @@ -8676,16 +9277,16 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":142 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":154 * for word in self.id2word: * f.write("%s %d " % (word, self.word2id[word])) * f.write("\n") # <<<<<<<<<<<<<< * * def write_enhanced(self, char* filename): */ - __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_23), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_26), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -8708,14 +9309,14 @@ static PyObject *__pyx_pf_3_sa_9DataArray_22write_enhanced_handle(struct __pyx_o } /* Python wrapper */ -static PyObject *__pyx_pw_3_sa_9DataArray_25write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ -static PyObject *__pyx_pw_3_sa_9DataArray_25write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { +static PyObject *__pyx_pw_3_sa_9DataArray_29write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_9DataArray_29write_enhanced(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { char *__pyx_v_filename; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("write_enhanced (wrapper)", 0); assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -8723,12 +9324,12 @@ static PyObject *__pyx_pw_3_sa_9DataArray_25write_enhanced(PyObject *__pyx_v_sel __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_3_sa_9DataArray_24write_enhanced(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __pyx_r = __pyx_pf_3_sa_9DataArray_28write_enhanced(((struct __pyx_obj_3_sa_DataArray *)__pyx_v_self), ((char *)__pyx_v_filename)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":144 +/* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":156 * f.write("\n") * * def write_enhanced(self, char* filename): # <<<<<<<<<<<<<< @@ -8736,7 +9337,7 @@ static PyObject *__pyx_pw_3_sa_9DataArray_25write_enhanced(PyObject *__pyx_v_sel * self.write_enhanced_handle(self, f) */ -static PyObject *__pyx_pf_3_sa_9DataArray_24write_enhanced(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { +static PyObject *__pyx_pf_3_sa_9DataArray_28write_enhanced(struct __pyx_obj_3_sa_DataArray *__pyx_v_self, char *__pyx_v_filename) { PyObject *__pyx_v_f = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -8756,16 +9357,16 @@ static PyObject *__pyx_pf_3_sa_9DataArray_24write_enhanced(struct __pyx_obj_3_sa int __pyx_clineno = 0; __Pyx_RefNannySetupContext("write_enhanced", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":145 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":157 * * def write_enhanced(self, char* filename): * with open(filename, "w") as f: # <<<<<<<<<<<<<< * self.write_enhanced_handle(self, f) */ /*with:*/ { - __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); @@ -8773,14 +9374,14 @@ static PyObject *__pyx_pf_3_sa_9DataArray_24write_enhanced(struct __pyx_obj_3_sa PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_n_s__w)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__w)); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s____enter__); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -8795,14 +9396,14 @@ static PyObject *__pyx_pf_3_sa_9DataArray_24write_enhanced(struct __pyx_obj_3_sa __pyx_v_f = __pyx_t_4; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":146 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":158 * def write_enhanced(self, char* filename): * with open(filename, "w") as f: * self.write_enhanced_handle(self, f) # <<<<<<<<<<<<<< */ - __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s_24); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s_27); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); @@ -8810,7 +9411,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_24write_enhanced(struct __pyx_obj_3_sa __Pyx_INCREF(__pyx_v_f); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_f); __Pyx_GIVEREF(__pyx_v_f); - __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; @@ -8825,7 +9426,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_24write_enhanced(struct __pyx_obj_3_sa __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":145 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":157 * * def write_enhanced(self, char* filename): * with open(filename, "w") as f: # <<<<<<<<<<<<<< @@ -8833,11 +9434,11 @@ static PyObject *__pyx_pf_3_sa_9DataArray_24write_enhanced(struct __pyx_obj_3_sa */ /*except:*/ { __Pyx_AddTraceback("_sa.DataArray.write_enhanced", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_1, &__pyx_t_4) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_1, &__pyx_t_4) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_GOTREF(__pyx_t_1); __Pyx_GOTREF(__pyx_t_4); - __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_INCREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2); @@ -8850,11 +9451,11 @@ static PyObject *__pyx_pf_3_sa_9DataArray_24write_enhanced(struct __pyx_obj_3_sa __Pyx_GIVEREF(__pyx_t_4); __pyx_t_10 = PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} __Pyx_GOTREF(__pyx_t_10); __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_10); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} __pyx_t_11 = (!__pyx_t_9); if (__pyx_t_11) { __Pyx_GIVEREF(__pyx_t_2); @@ -8862,7 +9463,7 @@ static PyObject *__pyx_pf_3_sa_9DataArray_24write_enhanced(struct __pyx_obj_3_sa __Pyx_GIVEREF(__pyx_t_4); __Pyx_ErrRestore(__pyx_t_2, __pyx_t_1, __pyx_t_4); __pyx_t_2 = 0; __pyx_t_1 = 0; __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + {__pyx_filename = __pyx_f[3]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} goto __pyx_L18; } __pyx_L18:; @@ -8888,13 +9489,13 @@ static PyObject *__pyx_pf_3_sa_9DataArray_24write_enhanced(struct __pyx_obj_3_sa } /*finally:*/ { if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_25, NULL); + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_28, NULL); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_7); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } } goto __pyx_L19; @@ -9350,7 +9951,7 @@ static int __pyx_pf_3_sa_9Alignment_4__cinit__(struct __pyx_obj_3_sa_Alignment * * self.sent_index = IntList(1000,1000) * if from_binary: */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_k_tuple_26), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_k_tuple_29), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->links); @@ -9365,7 +9966,7 @@ static int __pyx_pf_3_sa_9Alignment_4__cinit__(struct __pyx_obj_3_sa_Alignment * * if from_binary: * self.read_binary(from_binary) */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_k_tuple_27), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_3_sa_IntList)), ((PyObject *)__pyx_k_tuple_30), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->sent_index); @@ -9687,7 +10288,7 @@ static PyObject *__pyx_pf_3_sa_9Alignment_6read_text(struct __pyx_obj_3_sa_Align */ __pyx_t_3 = PyObject_GetAttr(__pyx_v_pair, __pyx_n_s__split); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_12 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_29), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_12 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_32), NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L7_error;} @@ -9871,7 +10472,7 @@ static PyObject *__pyx_pf_3_sa_9Alignment_6read_text(struct __pyx_obj_3_sa_Align } /*finally:*/ { if (__pyx_t_4) { - __pyx_t_7 = PyObject_Call(__pyx_t_4, __pyx_k_tuple_30, NULL); + __pyx_t_7 = PyObject_Call(__pyx_t_4, __pyx_k_tuple_33, NULL); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); @@ -10174,7 +10775,7 @@ static PyObject *__pyx_pf_3_sa_9Alignment_10write_text(struct __pyx_obj_3_sa_Ali */ __pyx_t_10 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_k_tuple_31), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_k_tuple_34), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; @@ -10213,7 +10814,7 @@ static PyObject *__pyx_pf_3_sa_9Alignment_10write_text(struct __pyx_obj_3_sa_Ali __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; - __pyx_t_12 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_32), __pyx_t_13); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_12 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_35), __pyx_t_13); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_12)); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L7_error;} @@ -10239,7 +10840,7 @@ static PyObject *__pyx_pf_3_sa_9Alignment_10write_text(struct __pyx_obj_3_sa_Ali */ __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_33), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_36), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -10320,7 +10921,7 @@ static PyObject *__pyx_pf_3_sa_9Alignment_10write_text(struct __pyx_obj_3_sa_Ali } /*finally:*/ { if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_34, NULL); + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_37, NULL); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); @@ -10591,7 +11192,7 @@ static PyObject *__pyx_pf_3_sa_9Alignment_14write_enhanced(struct __pyx_obj_3_sa */ __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_link); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_21), __pyx_v_link); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_10); @@ -10615,7 +11216,7 @@ static PyObject *__pyx_pf_3_sa_9Alignment_14write_enhanced(struct __pyx_obj_3_sa */ __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_35), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_38), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; @@ -10674,7 +11275,7 @@ static PyObject *__pyx_pf_3_sa_9Alignment_14write_enhanced(struct __pyx_obj_3_sa */ __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_21), __pyx_v_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_10)); __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); @@ -10698,7 +11299,7 @@ static PyObject *__pyx_pf_3_sa_9Alignment_14write_enhanced(struct __pyx_obj_3_sa */ __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_36), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_39), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; @@ -10777,7 +11378,7 @@ static PyObject *__pyx_pf_3_sa_9Alignment_14write_enhanced(struct __pyx_obj_3_sa } /*finally:*/ { if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_37, NULL); + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_40, NULL); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); @@ -11269,7 +11870,7 @@ static int __pyx_pw_3_sa_5BiLex_1__cinit__(PyObject *__pyx_v_self, PyObject *__p * self.id2eword = [] */ values[0] = ((PyObject *)Py_None); - values[1] = __pyx_k_38; + values[1] = __pyx_k_41; values[2] = ((PyObject *)Py_None); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":55 @@ -12220,7 +12821,7 @@ static PyObject *__pyx_f_3_sa_5BiLex_compute_from_data(struct __pyx_obj_3_sa_BiL __pyx_t_5 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; - __pyx_t_12 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_39), ((PyObject *)__pyx_t_13)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_12 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_42), ((PyObject *)__pyx_t_13)); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_12)); __Pyx_DECREF(((PyObject *)__pyx_t_13)); __pyx_t_13 = 0; __pyx_t_13 = PyTuple_New(1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -14311,7 +14912,7 @@ static PyObject *__pyx_pf_3_sa_5BiLex_10read_text(struct __pyx_obj_3_sa_BiLex *_ */ __pyx_t_12 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__seek); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_12); - __pyx_t_1 = PyObject_Call(__pyx_t_12, ((PyObject *)__pyx_k_tuple_40), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_12, ((PyObject *)__pyx_k_tuple_43), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -14642,7 +15243,7 @@ static PyObject *__pyx_pf_3_sa_5BiLex_10read_text(struct __pyx_obj_3_sa_BiLex *_ } /*finally:*/ { if (__pyx_t_4) { - __pyx_t_7 = PyObject_Call(__pyx_t_4, __pyx_k_tuple_41, NULL); + __pyx_t_7 = PyObject_Call(__pyx_t_4, __pyx_k_tuple_44, NULL); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); @@ -14714,7 +15315,7 @@ static PyObject *__pyx_pf_3_sa_5BiLex_10read_text(struct __pyx_obj_3_sa_BiLex *_ */ __pyx_t_20 = __Pyx_PyInt_AsInt(__pyx_v_i); if (unlikely((__pyx_t_20 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_24 = __Pyx_PyInt_AsInt(__pyx_v_j); if (unlikely((__pyx_t_24 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = ((PyObject *)__pyx_kp_s_42); + __pyx_t_3 = ((PyObject *)__pyx_kp_s_45); __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_BiLex *)__pyx_v_self->__pyx_vtab)->qsort(__pyx_v_self, __pyx_t_20, __pyx_t_24, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); @@ -14937,7 +15538,7 @@ static PyObject *__pyx_f_3_sa_5BiLex_qsort(struct __pyx_obj_3_sa_BiLex *__pyx_v_ * if i == j: #empty interval * return */ - __pyx_t_2 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_k_tuple_44), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_k_tuple_47), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; @@ -15094,7 +15695,7 @@ static PyObject *__pyx_f_3_sa_5BiLex_qsort(struct __pyx_obj_3_sa_BiLex *__pyx_v_ * self.qsort(p+1,j, pad+" ") * */ - __pyx_t_2 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_48)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = ((struct __pyx_vtabstruct_3_sa_BiLex *)__pyx_v_self->__pyx_vtab)->qsort(__pyx_v_self, __pyx_v_i, __pyx_v_p, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); @@ -15108,7 +15709,7 @@ static PyObject *__pyx_f_3_sa_5BiLex_qsort(struct __pyx_obj_3_sa_BiLex *__pyx_v_ * * */ - __pyx_t_4 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_48)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = ((struct __pyx_vtabstruct_3_sa_BiLex *)__pyx_v_self->__pyx_vtab)->qsort(__pyx_v_self, (__pyx_v_p + 1), __pyx_v_j, __pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); @@ -15280,7 +15881,7 @@ static PyObject *__pyx_pf_3_sa_5BiLex_12write_enhanced(struct __pyx_obj_3_sa_BiL */ __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_21), __pyx_v_i); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_10); @@ -15304,7 +15905,7 @@ static PyObject *__pyx_pf_3_sa_5BiLex_12write_enhanced(struct __pyx_obj_3_sa_BiL */ __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_46), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_49), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; @@ -15450,7 +16051,7 @@ static PyObject *__pyx_pf_3_sa_5BiLex_12write_enhanced(struct __pyx_obj_3_sa_BiL __Pyx_INCREF(__pyx_v_s2); PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_v_s2); __Pyx_GIVEREF(__pyx_v_s2); - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_47), ((PyObject *)__pyx_t_11)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_50), ((PyObject *)__pyx_t_11)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0; __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L7_error;} @@ -15475,7 +16076,7 @@ static PyObject *__pyx_pf_3_sa_5BiLex_12write_enhanced(struct __pyx_obj_3_sa_BiL */ __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_48), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_51), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -15552,7 +16153,7 @@ static PyObject *__pyx_pf_3_sa_5BiLex_12write_enhanced(struct __pyx_obj_3_sa_BiL __Pyx_INCREF(__pyx_v_w); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_w); __Pyx_GIVEREF(__pyx_v_w); - __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_49), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_52), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_10)); __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L7_error;} @@ -15578,7 +16179,7 @@ static PyObject *__pyx_pf_3_sa_5BiLex_12write_enhanced(struct __pyx_obj_3_sa_BiL */ __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_50), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_53), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; @@ -15655,7 +16256,7 @@ static PyObject *__pyx_pf_3_sa_5BiLex_12write_enhanced(struct __pyx_obj_3_sa_BiL __Pyx_INCREF(__pyx_v_w); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_w); __Pyx_GIVEREF(__pyx_v_w); - __pyx_t_11 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_49), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_11 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_52), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_11)); __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 375; __pyx_clineno = __LINE__; goto __pyx_L7_error;} @@ -15681,7 +16282,7 @@ static PyObject *__pyx_pf_3_sa_5BiLex_12write_enhanced(struct __pyx_obj_3_sa_BiL */ __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_51), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_54), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -15762,7 +16363,7 @@ static PyObject *__pyx_pf_3_sa_5BiLex_12write_enhanced(struct __pyx_obj_3_sa_BiL } /*finally:*/ { if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_52, NULL); + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_55, NULL); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); @@ -16448,7 +17049,7 @@ static PyObject *__pyx_pf_3_sa_5BiLex_16write_text(struct __pyx_obj_3_sa_BiLex * __Pyx_GIVEREF(__pyx_v_score2); __pyx_t_4 = 0; __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_53), ((PyObject *)__pyx_t_12)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_56), ((PyObject *)__pyx_t_12)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_DECREF(((PyObject *)__pyx_t_12)); __pyx_t_12 = 0; __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 418; __pyx_clineno = __LINE__; goto __pyx_L7_error;} @@ -16551,7 +17152,7 @@ static PyObject *__pyx_pf_3_sa_5BiLex_16write_text(struct __pyx_obj_3_sa_BiLex * } /*finally:*/ { if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_54, NULL); + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_57, NULL); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); @@ -17543,7 +18144,7 @@ static PyObject *__pyx_pf_3_sa_6BitSet_10__str__(struct __pyx_obj_3_sa_BitSet *_ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = ((PyObject *)__pyx_f_3_sa_dec2bin(__pyx_v_self->b->bitset)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyNumber_Add(__pyx_t_1, ((PyObject *)__pyx_kp_s_55)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyNumber_Add(__pyx_t_1, ((PyObject *)__pyx_kp_s_58)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyInt_FromLong(__pyx_v_self->b->size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -17594,7 +18195,7 @@ static PyObject *__pyx_pf_3_sa_6BitSet_10__str__(struct __pyx_obj_3_sa_BitSet *_ __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Add(__pyx_t_1, ((PyObject *)__pyx_kp_s_56)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyNumber_Add(__pyx_t_1, ((PyObject *)__pyx_kp_s_59)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 142; __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; @@ -17848,8 +18449,8 @@ static PyObject *__pyx_f_3_sa_dec2bin(long __pyx_v_i) { * cdef unsigned d * for d in range(MIN_BOTTOM_SIZE): */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_42)); - __pyx_v_result = __pyx_kp_s_42; + __Pyx_INCREF(((PyObject *)__pyx_kp_s_45)); + __pyx_v_result = __pyx_kp_s_45; /* "/Users/vchahun/Sandbox/cdec/python/src/sa/veb.pxi":160 * cdef str result = "" @@ -19908,7 +20509,7 @@ static int __pyx_pf_3_sa_3LCP___cinit__(struct __pyx_obj_3_sa_LCP *__pyx_v_self, __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_58), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_61), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -20134,7 +20735,7 @@ static int __pyx_pf_3_sa_3LCP___cinit__(struct __pyx_obj_3_sa_LCP *__pyx_v_self, __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_60), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_63), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -20184,14 +20785,14 @@ static PyObject *__pyx_pw_3_sa_3LCP_3compute_stats(PyObject *__pyx_v_self, PyObj */ static PyObject *__pyx_pf_3_sa_3LCP_2compute_stats(struct __pyx_obj_3_sa_LCP *__pyx_v_self, int __pyx_v_max_n) { - struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *__pyx_cur_scope; + struct __pyx_obj_3_sa___pyx_scope_struct_2_compute_stats *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("compute_stats", 0); - __pyx_cur_scope = (struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *)__pyx_ptype_3_sa___pyx_scope_struct__compute_stats->tp_new(__pyx_ptype_3_sa___pyx_scope_struct__compute_stats, __pyx_empty_tuple, NULL); + __pyx_cur_scope = (struct __pyx_obj_3_sa___pyx_scope_struct_2_compute_stats *)__pyx_ptype_3_sa___pyx_scope_struct_2_compute_stats->tp_new(__pyx_ptype_3_sa___pyx_scope_struct_2_compute_stats, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -20222,7 +20823,7 @@ static PyObject *__pyx_pf_3_sa_3LCP_2compute_stats(struct __pyx_obj_3_sa_LCP *__ static PyObject *__pyx_gb_3_sa_3LCP_4generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *__pyx_cur_scope = ((struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *)__pyx_generator->closure); + struct __pyx_obj_3_sa___pyx_scope_struct_2_compute_stats *__pyx_cur_scope = ((struct __pyx_obj_3_sa___pyx_scope_struct_2_compute_stats *)__pyx_generator->closure); PyObject *__pyx_r = NULL; PyObject *__pyx_t_1 = NULL; int __pyx_t_2; @@ -21263,7 +21864,7 @@ static char *__pyx_f_3_sa_8Alphabet_tostring(struct __pyx_obj_3_sa_Alphabet *__p __Pyx_GIVEREF(__pyx_t_5); __pyx_t_2 = 0; __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_61), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_64), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; if (unlikely(((PyObject *)__pyx_v_self->id2sym) == Py_None)) { @@ -21285,7 +21886,7 @@ static char *__pyx_f_3_sa_8Alphabet_tostring(struct __pyx_obj_3_sa_Alphabet *__p */ __pyx_t_5 = PyBytes_FromString(((struct __pyx_vtabstruct_3_sa_Alphabet *)__pyx_v_self->__pyx_vtab)->tocat(__pyx_v_self, __pyx_v_sym)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); - __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_62), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_65), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_6)); __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; if (unlikely(((PyObject *)__pyx_v_self->id2sym) == Py_None)) { @@ -21435,7 +22036,7 @@ static int __pyx_f_3_sa_8Alphabet_fromstring(struct __pyx_obj_3_sa_Alphabet *__p */ __pyx_t_6 = PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_6)); - __pyx_t_7 = PyNumber_Add(((PyObject *)__pyx_kp_s_63), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PyNumber_Add(((PyObject *)__pyx_kp_s_66), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; __pyx_v_s1 = __pyx_t_7; @@ -22221,7 +22822,7 @@ static PyObject *__pyx_pf_3_sa_6Phrase_4__str__(struct __pyx_obj_3_sa_Phrase *__ * def handle(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_64), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_67), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); @@ -22558,7 +23159,7 @@ static PyObject *__pyx_pf_3_sa_6Phrase_8strhandle(struct __pyx_obj_3_sa_Phrase * * def arity(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_64), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_67), __pyx_n_s__join); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); @@ -23551,14 +24152,14 @@ static PyObject *__pyx_pw_3_sa_6Phrase_29__iter__(PyObject *__pyx_v_self) { */ static PyObject *__pyx_pf_3_sa_6Phrase_28__iter__(struct __pyx_obj_3_sa_Phrase *__pyx_v_self) { - struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *__pyx_cur_scope; + struct __pyx_obj_3_sa___pyx_scope_struct_3___iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__iter__", 0); - __pyx_cur_scope = (struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *)__pyx_ptype_3_sa___pyx_scope_struct_1___iter__->tp_new(__pyx_ptype_3_sa___pyx_scope_struct_1___iter__, __pyx_empty_tuple, NULL); + __pyx_cur_scope = (struct __pyx_obj_3_sa___pyx_scope_struct_3___iter__ *)__pyx_ptype_3_sa___pyx_scope_struct_3___iter__->tp_new(__pyx_ptype_3_sa___pyx_scope_struct_3___iter__, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -23588,7 +24189,7 @@ static PyObject *__pyx_pf_3_sa_6Phrase_28__iter__(struct __pyx_obj_3_sa_Phrase * static PyObject *__pyx_gb_3_sa_6Phrase_30generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *__pyx_cur_scope = ((struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *)__pyx_generator->closure); + struct __pyx_obj_3_sa___pyx_scope_struct_3___iter__ *__pyx_cur_scope = ((struct __pyx_obj_3_sa___pyx_scope_struct_3___iter__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; int __pyx_t_1; PyObject *__pyx_t_2 = NULL; @@ -24076,7 +24677,7 @@ static int __pyx_pf_3_sa_4Rule___cinit__(struct __pyx_obj_3_sa_Rule *__pyx_v_sel */ __pyx_t_2 = PyInt_FromLong(__pyx_v_lhs); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_65), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_68), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -24806,7 +25407,7 @@ static PyObject *__pyx_pf_3_sa_4Rule_14__str__(struct __pyx_obj_3_sa_Rule *__pyx __pyx_t_6 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_64), __pyx_n_s__join); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_67), __pyx_n_s__join); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); @@ -24894,7 +25495,7 @@ static PyObject *__pyx_pf_3_sa_4Rule_14__str__(struct __pyx_obj_3_sa_Rule *__pyx __Pyx_GIVEREF(__pyx_t_6); __pyx_t_8 = 0; __pyx_t_6 = 0; - __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_66), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_69), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_6)); __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; __pyx_t_4 = PyList_Append(__pyx_v_alignstr, ((PyObject *)__pyx_t_6)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -24908,7 +25509,7 @@ static PyObject *__pyx_pf_3_sa_4Rule_14__str__(struct __pyx_obj_3_sa_Rule *__pyx * * return " ||| ".join(fields) */ - __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_64), __pyx_n_s__join); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_67), __pyx_n_s__join); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); @@ -24933,7 +25534,7 @@ static PyObject *__pyx_pf_3_sa_4Rule_14__str__(struct __pyx_obj_3_sa_Rule *__pyx * property scores: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_67), __pyx_n_s__join); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_18), __pyx_n_s__join); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); @@ -27041,7 +27642,7 @@ static int __pyx_pw_3_sa_14Precomputation_1__cinit__(PyObject *__pyx_v_self, PyO __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fsarray,&__pyx_n_s__from_stats,&__pyx_n_s__from_binary,&__pyx_n_s__precompute_rank,&__pyx_n_s_68,&__pyx_n_s__max_length,&__pyx_n_s__max_nonterminals,&__pyx_n_s_69,&__pyx_n_s__train_min_gap_size,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__fsarray,&__pyx_n_s__from_stats,&__pyx_n_s__from_binary,&__pyx_n_s__precompute_rank,&__pyx_n_s_70,&__pyx_n_s__max_length,&__pyx_n_s__max_nonterminals,&__pyx_n_s_71,&__pyx_n_s__train_min_gap_size,0}; PyObject* values[9] = {0,0,0,0,0,0,0,0,0}; /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":200 @@ -27100,7 +27701,7 @@ static int __pyx_pw_3_sa_14Precomputation_1__cinit__(PyObject *__pyx_v_self, PyO } case 4: if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_68); + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_70); if (value) { values[4] = value; kw_args--; } } case 5: @@ -27115,7 +27716,7 @@ static int __pyx_pw_3_sa_14Precomputation_1__cinit__(PyObject *__pyx_v_self, PyO } case 7: if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_69); + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_71); if (value) { values[7] = value; kw_args--; } } case 8: @@ -28321,7 +28922,7 @@ static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_s __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__info); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_71), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_73), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -28622,7 +29223,7 @@ static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_s __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_73), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_75), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -28765,7 +29366,7 @@ static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_s __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_75), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_77), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -29344,9 +29945,9 @@ static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_s __Pyx_GOTREF(__pyx_t_3); __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_76)); - PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_kp_s_76)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_76)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_78)); + PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_kp_s_78)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_78)); PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; @@ -29504,7 +30105,7 @@ static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_s * J2_set.add(combined_pattern) * */ - __pyx_t_8 = PyNumber_Add(__pyx_v_pattern1, ((PyObject *)__pyx_k_tuple_77)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyNumber_Add(__pyx_v_pattern1, ((PyObject *)__pyx_k_tuple_79)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __pyx_t_7 = PyNumber_Add(__pyx_t_8, __pyx_v_pattern2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); @@ -29613,7 +30214,7 @@ static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_s * IJ_set.add(combined_pattern) * */ - __pyx_t_7 = PyNumber_Add(__pyx_v_pattern1, ((PyObject *)__pyx_k_tuple_78)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PyNumber_Add(__pyx_v_pattern1, ((PyObject *)__pyx_k_tuple_80)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = PyNumber_Add(__pyx_t_7, __pyx_v_pattern2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); @@ -29722,7 +30323,7 @@ static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_s * IJ_set.add(combined_pattern) * combined_pattern = pattern2 + (-1,) + pattern1 */ - __pyx_t_8 = PyNumber_Add(__pyx_v_pattern1, ((PyObject *)__pyx_k_tuple_79)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyNumber_Add(__pyx_v_pattern1, ((PyObject *)__pyx_k_tuple_81)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __pyx_t_7 = PyNumber_Add(__pyx_t_8, __pyx_v_pattern2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); @@ -29747,7 +30348,7 @@ static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_s * IJ_set.add(combined_pattern) * */ - __pyx_t_7 = PyNumber_Add(__pyx_v_pattern2, ((PyObject *)__pyx_k_tuple_80)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PyNumber_Add(__pyx_v_pattern2, ((PyObject *)__pyx_k_tuple_82)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = PyNumber_Add(__pyx_t_7, __pyx_v_pattern1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); @@ -29867,9 +30468,9 @@ static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_s * for word_id in pattern: * if word_id == -1: */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_42)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_45)); __Pyx_XDECREF(__pyx_v_s); - __pyx_v_s = ((PyObject *)__pyx_kp_s_42); + __pyx_v_s = ((PyObject *)__pyx_kp_s_45); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":418 * if pattern not in IJ_set: @@ -29936,7 +30537,7 @@ static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_s * else: * s = s + darray.id2word[word_id] + " " */ - __pyx_t_3 = PyNumber_Add(__pyx_v_s, ((PyObject *)__pyx_kp_s_81)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyNumber_Add(__pyx_v_s, ((PyObject *)__pyx_kp_s_83)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_v_s); __pyx_v_s = __pyx_t_3; @@ -29957,7 +30558,7 @@ static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_s __pyx_t_7 = PyNumber_Add(__pyx_v_s, __pyx_t_3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Add(__pyx_t_7, ((PyObject *)__pyx_kp_s_64)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyNumber_Add(__pyx_t_7, ((PyObject *)__pyx_kp_s_67)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_v_s); @@ -29982,9 +30583,9 @@ static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_s __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 423; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_82)); - PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_kp_s_82)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_82)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_84)); + PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_kp_s_84)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_84)); __Pyx_INCREF(__pyx_v_s); PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_s); __Pyx_GIVEREF(__pyx_v_s); @@ -30320,9 +30921,9 @@ static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_s __Pyx_GOTREF(__pyx_t_8); __pyx_t_7 = PyTuple_New(6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 444; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_83)); - PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_kp_s_83)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_83)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_85)); + PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_kp_s_85)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_85)); PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_3); @@ -30443,9 +31044,9 @@ static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_s __Pyx_GOTREF(__pyx_t_8); __pyx_t_6 = PyTuple_New(4); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 452; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_84)); - PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_kp_s_84)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_84)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_86)); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_kp_s_86)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_86)); __Pyx_INCREF(__pyx_v_num_found_patterns); PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_num_found_patterns); __Pyx_GIVEREF(__pyx_v_num_found_patterns); @@ -30480,9 +31081,9 @@ static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_s __Pyx_GOTREF(__pyx_t_8); __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 453; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_85)); - PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_kp_s_85)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_85)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_87)); + PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_kp_s_87)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_87)); PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); __pyx_t_8 = 0; @@ -30506,9 +31107,9 @@ static PyObject *__pyx_pf_3_sa_14Precomputation_6precompute(struct __pyx_obj_3_s __Pyx_GOTREF(__pyx_t_8); __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_86)); - PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_kp_s_86)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_86)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_88)); + PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_kp_s_88)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_88)); PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); __pyx_t_8 = 0; @@ -30570,26 +31171,29 @@ static int __pyx_pw_3_sa_11SuffixArray_1__cinit__(PyObject *__pyx_v_self, PyObje static int __pyx_pw_3_sa_11SuffixArray_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_from_binary = 0; PyObject *__pyx_v_from_text = 0; + PyObject *__pyx_v_side = 0; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__from_binary,&__pyx_n_s__from_text,0}; - PyObject* values[2] = {0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__from_binary,&__pyx_n_s__from_text,&__pyx_n_s__side,0}; + PyObject* values[3] = {0,0,0}; /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":11 * cdef IntList ha * - * def __cinit__(self, from_binary=None, from_text=None): # <<<<<<<<<<<<<< + * def __cinit__(self, from_binary=None, from_text=None, side=None): # <<<<<<<<<<<<<< * self.darray = DataArray() * self.sa = IntList() */ values[0] = ((PyObject *)Py_None); values[1] = ((PyObject *)Py_None); + values[2] = ((PyObject *)Py_None); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; @@ -30607,12 +31211,18 @@ static int __pyx_pw_3_sa_11SuffixArray_1__cinit__(PyObject *__pyx_v_self, PyObje PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__from_text); if (value) { values[1] = value; kw_args--; } } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__side); + if (value) { values[2] = value; kw_args--; } + } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; @@ -30621,21 +31231,22 @@ static int __pyx_pw_3_sa_11SuffixArray_1__cinit__(PyObject *__pyx_v_self, PyObje } __pyx_v_from_binary = values[0]; __pyx_v_from_text = values[1]; + __pyx_v_side = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[13]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[13]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_sa.SuffixArray.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_3_sa_11SuffixArray___cinit__(((struct __pyx_obj_3_sa_SuffixArray *)__pyx_v_self), __pyx_v_from_binary, __pyx_v_from_text); + __pyx_r = __pyx_pf_3_sa_11SuffixArray___cinit__(((struct __pyx_obj_3_sa_SuffixArray *)__pyx_v_self), __pyx_v_from_binary, __pyx_v_from_text, __pyx_v_side); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_3_sa_11SuffixArray___cinit__(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text) { +static int __pyx_pf_3_sa_11SuffixArray___cinit__(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_from_binary, PyObject *__pyx_v_from_text, PyObject *__pyx_v_side) { int __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -30649,7 +31260,7 @@ static int __pyx_pf_3_sa_11SuffixArray___cinit__(struct __pyx_obj_3_sa_SuffixArr /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":12 * - * def __cinit__(self, from_binary=None, from_text=None): + * def __cinit__(self, from_binary=None, from_text=None, side=None): * self.darray = DataArray() # <<<<<<<<<<<<<< * self.sa = IntList() * self.ha = IntList() @@ -30663,7 +31274,7 @@ static int __pyx_pf_3_sa_11SuffixArray___cinit__(struct __pyx_obj_3_sa_SuffixArr __pyx_t_1 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":13 - * def __cinit__(self, from_binary=None, from_text=None): + * def __cinit__(self, from_binary=None, from_text=None, side=None): * self.darray = DataArray() * self.sa = IntList() # <<<<<<<<<<<<<< * self.ha = IntList() @@ -30707,7 +31318,7 @@ static int __pyx_pf_3_sa_11SuffixArray___cinit__(struct __pyx_obj_3_sa_SuffixArr * if from_binary: * self.read_binary(from_binary) # <<<<<<<<<<<<<< * elif from_text: - * self.read_text(from_text) + * self.read_text(from_text, side) */ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_binary); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); @@ -30728,7 +31339,7 @@ static int __pyx_pf_3_sa_11SuffixArray___cinit__(struct __pyx_obj_3_sa_SuffixArr * if from_binary: * self.read_binary(from_binary) * elif from_text: # <<<<<<<<<<<<<< - * self.read_text(from_text) + * self.read_text(from_text, side) * */ __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_from_text); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -30737,17 +31348,20 @@ static int __pyx_pf_3_sa_11SuffixArray___cinit__(struct __pyx_obj_3_sa_SuffixArr /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":18 * self.read_binary(from_binary) * elif from_text: - * self.read_text(from_text) # <<<<<<<<<<<<<< + * self.read_text(from_text, side) # <<<<<<<<<<<<<< * * def __getitem__(self, i): */ __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__read_text); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_from_text); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_from_text); __Pyx_GIVEREF(__pyx_v_from_text); + __Pyx_INCREF(__pyx_v_side); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_side); + __Pyx_GIVEREF(__pyx_v_side); __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -30782,7 +31396,7 @@ static PyObject *__pyx_pw_3_sa_11SuffixArray_3__getitem__(PyObject *__pyx_v_self } /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":20 - * self.read_text(from_text) + * self.read_text(from_text, side) * * def __getitem__(self, i): # <<<<<<<<<<<<<< * return self.sa.arr[i] @@ -30995,7 +31609,7 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_8getSentPos(struct __pyx_obj_3_sa_S * def getSentPos(self, loc): * return self.darray.getSentPos(loc) # <<<<<<<<<<<<<< * - * def read_text(self, char* filename): + * def read_text(self, filename, side): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self->darray), __pyx_n_s__getSentPos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -31028,23 +31642,58 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_8getSentPos(struct __pyx_obj_3_sa_S } /* Python wrapper */ -static PyObject *__pyx_pw_3_sa_11SuffixArray_11read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename); /*proto*/ +static PyObject *__pyx_pw_3_sa_11SuffixArray_11read_text(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_3_sa_11SuffixArray_10read_text[] = "Constructs suffix array using the algorithm\n of Larsson & Sadahkane (1999)"; -static PyObject *__pyx_pw_3_sa_11SuffixArray_11read_text(PyObject *__pyx_v_self, PyObject *__pyx_arg_filename) { - char *__pyx_v_filename; +static PyObject *__pyx_pw_3_sa_11SuffixArray_11read_text(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_filename = 0; + PyObject *__pyx_v_side = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("read_text (wrapper)", 0); - assert(__pyx_arg_filename); { - __pyx_v_filename = PyBytes_AsString(__pyx_arg_filename); if (unlikely((!__pyx_v_filename) && PyErr_Occurred())) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__filename,&__pyx_n_s__side,0}; + PyObject* values[2] = {0,0}; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__filename)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__side)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("read_text", 1, 2, 2, 1); {__pyx_filename = __pyx_f[13]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "read_text") < 0)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + } + __pyx_v_filename = values[0]; + __pyx_v_side = values[1]; } goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("read_text", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[13]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_sa.SuffixArray.read_text", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_3_sa_11SuffixArray_10read_text(((struct __pyx_obj_3_sa_SuffixArray *)__pyx_v_self), ((char *)__pyx_v_filename)); + __pyx_r = __pyx_pf_3_sa_11SuffixArray_10read_text(((struct __pyx_obj_3_sa_SuffixArray *)__pyx_v_self), __pyx_v_filename, __pyx_v_side); __Pyx_RefNannyFinishContext(); return __pyx_r; } @@ -31052,12 +31701,12 @@ static PyObject *__pyx_pw_3_sa_11SuffixArray_11read_text(PyObject *__pyx_v_self, /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":32 * return self.darray.getSentPos(loc) * - * def read_text(self, char* filename): # <<<<<<<<<<<<<< + * def read_text(self, filename, side): # <<<<<<<<<<<<<< * '''Constructs suffix array using the algorithm * of Larsson & Sadahkane (1999)''' */ -static PyObject *__pyx_pf_3_sa_11SuffixArray_10read_text(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, char *__pyx_v_filename) { +static PyObject *__pyx_pf_3_sa_11SuffixArray_10read_text(struct __pyx_obj_3_sa_SuffixArray *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_side) { int __pyx_v_V; int __pyx_v_N; int __pyx_v_i; @@ -31092,16 +31741,14 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_10read_text(struct __pyx_obj_3_sa_S /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":38 * cdef IntList isa, word_count * - * self.darray = DataArray(from_text=filename, use_sent_id=True) # <<<<<<<<<<<<<< + * self.darray = DataArray(from_text=filename, side=side, use_sent_id=True) # <<<<<<<<<<<<<< * N = len(self.darray) * V = len(self.darray.id2word) */ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyBytes_FromString(__pyx_v_filename); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__from_text), ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__from_text), __pyx_v_filename) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__side), __pyx_v_side) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__use_sent_id), __pyx_t_2) < 0) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -31117,7 +31764,7 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_10read_text(struct __pyx_obj_3_sa_S /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":39 * - * self.darray = DataArray(from_text=filename, use_sent_id=True) + * self.darray = DataArray(from_text=filename, side=side, use_sent_id=True) * N = len(self.darray) # <<<<<<<<<<<<<< * V = len(self.darray.id2word) * @@ -31129,7 +31776,7 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_10read_text(struct __pyx_obj_3_sa_S __pyx_v_N = __pyx_t_3; /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":40 - * self.darray = DataArray(from_text=filename, use_sent_id=True) + * self.darray = DataArray(from_text=filename, side=side, use_sent_id=True) * N = len(self.darray) * V = len(self.darray.id2word) # <<<<<<<<<<<<<< * @@ -31461,9 +32108,9 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_10read_text(struct __pyx_obj_3_sa_S __Pyx_GOTREF(__pyx_t_2); __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_87)); - PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_kp_s_87)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_87)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_89)); + PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_kp_s_89)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_89)); PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; @@ -31518,9 +32165,9 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_10read_text(struct __pyx_obj_3_sa_S __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_88)); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_88)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_88)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_90)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_kp_s_90)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_90)); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; @@ -31724,9 +32371,9 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_10read_text(struct __pyx_obj_3_sa_S __Pyx_GOTREF(__pyx_t_10); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_89)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_89)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_89)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_91)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_91)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_91)); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_10); __Pyx_GIVEREF(__pyx_t_10); __pyx_t_10 = 0; @@ -31749,7 +32396,7 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_10read_text(struct __pyx_obj_3_sa_S __pyx_t_2 = PyObject_GetAttr(__pyx_t_10, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_91), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_10 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_93), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; @@ -31799,9 +32446,9 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_10read_text(struct __pyx_obj_3_sa_S __Pyx_GOTREF(__pyx_t_10); __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_11); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_92)); - PyTuple_SET_ITEM(__pyx_t_11, 0, ((PyObject *)__pyx_kp_s_92)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_92)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_94)); + PyTuple_SET_ITEM(__pyx_t_11, 0, ((PyObject *)__pyx_kp_s_94)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_94)); PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_10); __Pyx_GIVEREF(__pyx_t_10); __pyx_t_10 = 0; @@ -31844,7 +32491,7 @@ static PyObject *__pyx_pw_3_sa_11SuffixArray_13q3sort(PyObject *__pyx_v_self, Py { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__i,&__pyx_n_s__j,&__pyx_n_s__h,&__pyx_n_s__isa,&__pyx_n_s__pad,0}; PyObject* values[5] = {0,0,0,0,0}; - values[4] = ((PyObject *)__pyx_kp_s_42); + values[4] = ((PyObject *)__pyx_kp_s_45); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); @@ -31980,7 +32627,7 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_12q3sort(struct __pyx_obj_3_sa_Suff __Pyx_GIVEREF(__pyx_t_3); __pyx_t_2 = 0; __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_93), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_95), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -32339,7 +32986,7 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_12q3sort(struct __pyx_obj_3_sa_Suff __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - __pyx_t_7 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_48)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = PyTuple_New(5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); @@ -32421,7 +33068,7 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_12q3sort(struct __pyx_obj_3_sa_Suff __Pyx_GOTREF(__pyx_t_3); __pyx_t_6 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_45)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyNumber_Add(__pyx_v_pad, ((PyObject *)__pyx_kp_s_48)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = PyTuple_New(5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); @@ -32811,7 +33458,7 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_20write_enhanced(struct __pyx_obj_3 * for a_i in self.sa: * f.write("%d " % a_i) */ - __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self->darray), __pyx_n_s_24); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_self->darray), __pyx_n_s_27); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 199; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); @@ -32878,7 +33525,7 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_20write_enhanced(struct __pyx_obj_3 */ __pyx_t_1 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_a_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_21), __pyx_v_a_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_10); @@ -32902,7 +33549,7 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_20write_enhanced(struct __pyx_obj_3 */ __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_94), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_96), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -32961,7 +33608,7 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_20write_enhanced(struct __pyx_obj_3 */ __pyx_t_2 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_v_w_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_21), __pyx_v_w_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_10)); __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_1); @@ -32985,7 +33632,7 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_20write_enhanced(struct __pyx_obj_3 */ __pyx_t_4 = PyObject_GetAttr(__pyx_v_f, __pyx_n_s__write); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_10 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_95), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_10 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_97), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L7_error;} __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; @@ -33064,7 +33711,7 @@ static PyObject *__pyx_pf_3_sa_11SuffixArray_20write_enhanced(struct __pyx_obj_3 } /*finally:*/ { if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_96, NULL); + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_98, NULL); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); @@ -34267,7 +34914,7 @@ static int __pyx_pw_3_sa_9TrieTable_1__cinit__(PyObject *__pyx_v_self, PyObject { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__extended,0}; PyObject* values[1] = {0}; - values[0] = __pyx_k_97; + values[0] = __pyx_k_99; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); @@ -35014,9 +35661,9 @@ static int __pyx_pf_3_sa_7Sampler___cinit__(struct __pyx_obj_3_sa_Sampler *__pyx __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_98)); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_s_98)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_98)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_100)); + PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_kp_s_100)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_100)); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; @@ -35041,7 +35688,7 @@ static int __pyx_pf_3_sa_7Sampler___cinit__(struct __pyx_obj_3_sa_Sampler *__pyx __pyx_t_4 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__info); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_100), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_102), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; @@ -35829,7 +36476,7 @@ static int __pyx_pw_3_sa_23HieroCachingRuleFactory_1__cinit__(PyObject *__pyx_v_ __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__alignment,&__pyx_n_s__by_slack_factor,&__pyx_n_s__category,&__pyx_n_s__max_chunks,&__pyx_n_s__max_initial_size,&__pyx_n_s__max_length,&__pyx_n_s__max_nonterminals,&__pyx_n_s__max_target_chunks,&__pyx_n_s__max_target_length,&__pyx_n_s__min_gap_size,&__pyx_n_s__precompute_file,&__pyx_n_s_68,&__pyx_n_s__precompute_rank,&__pyx_n_s_101,&__pyx_n_s_102,&__pyx_n_s_69,&__pyx_n_s__train_min_gap_size,&__pyx_n_s__tight_phrases,&__pyx_n_s__use_baeza_yates,&__pyx_n_s__use_collocations,&__pyx_n_s__use_index,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__alignment,&__pyx_n_s__by_slack_factor,&__pyx_n_s__category,&__pyx_n_s__max_chunks,&__pyx_n_s__max_initial_size,&__pyx_n_s__max_length,&__pyx_n_s__max_nonterminals,&__pyx_n_s__max_target_chunks,&__pyx_n_s__max_target_length,&__pyx_n_s__min_gap_size,&__pyx_n_s__precompute_file,&__pyx_n_s_70,&__pyx_n_s__precompute_rank,&__pyx_n_s_103,&__pyx_n_s_104,&__pyx_n_s_71,&__pyx_n_s__train_min_gap_size,&__pyx_n_s__tight_phrases,&__pyx_n_s__use_baeza_yates,&__pyx_n_s__use_collocations,&__pyx_n_s__use_index,0}; PyObject* values[21] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":257 @@ -35952,7 +36599,7 @@ static int __pyx_pw_3_sa_23HieroCachingRuleFactory_1__cinit__(PyObject *__pyx_v_ } case 11: if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_68); + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_70); if (value) { values[11] = value; kw_args--; } } case 12: @@ -35962,17 +36609,17 @@ static int __pyx_pw_3_sa_23HieroCachingRuleFactory_1__cinit__(PyObject *__pyx_v_ } case 13: if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_101); + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_103); if (value) { values[13] = value; kw_args--; } } case 14: if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_102); + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_104); if (value) { values[14] = value; kw_args--; } } case 15: if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_69); + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_71); if (value) { values[15] = value; kw_args--; } } case 16: @@ -36048,7 +36695,7 @@ static int __pyx_pw_3_sa_23HieroCachingRuleFactory_1__cinit__(PyObject *__pyx_v_ if (values[2]) { __pyx_v_category = PyBytes_AsString(values[2]); if (unlikely((!__pyx_v_category) && PyErr_Occurred())) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 255; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { - __pyx_v_category = ((char *)__pyx_k_103); + __pyx_v_category = ((char *)__pyx_k_105); } __pyx_v_max_chunks = values[3]; if (values[4]) { @@ -36275,7 +36922,7 @@ static int __pyx_pf_3_sa_23HieroCachingRuleFactory___cinit__(struct __pyx_obj_3_ * self.alignment = alignment * */ - __pyx_t_2 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_k_tuple_105), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_k_tuple_107), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; @@ -37756,9 +38403,9 @@ static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_8precompute(struct __py __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 422; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_106)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_106)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_106)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_108)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_108)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_108)); __Pyx_INCREF(__pyx_v_self->precompute_file); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_self->precompute_file); __Pyx_GIVEREF(__pyx_v_self->precompute_file); @@ -37812,9 +38459,9 @@ static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_8precompute(struct __py __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_107)); - PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_107)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_107)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_109)); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_kp_s_109)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_109)); PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3); @@ -37858,9 +38505,9 @@ static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_8precompute(struct __py __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 428; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_108)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_108)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_108)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_110)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_110)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_110)); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_4); @@ -37905,7 +38552,7 @@ static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_8precompute(struct __py __Pyx_GIVEREF(__pyx_t_2); __pyx_t_4 = 0; __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_109), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_111), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 430; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -37952,7 +38599,7 @@ static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_8precompute(struct __py __Pyx_GIVEREF(__pyx_t_5); __pyx_t_2 = 0; __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_110), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_112), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_5)); __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 432; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -37999,9 +38646,9 @@ static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_8precompute(struct __py __Pyx_GOTREF(__pyx_t_5); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 434; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_111)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_111)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_111)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_113)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_113)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_113)); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = 0; @@ -38153,9 +38800,9 @@ static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_8precompute(struct __py __Pyx_GOTREF(__pyx_t_5); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_112)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_112)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_112)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_114)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_114)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_114)); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = 0; @@ -38259,9 +38906,9 @@ static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_8precompute(struct __py __Pyx_GOTREF(__pyx_t_5); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 445; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_113)); - PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_113)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_113)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_115)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_kp_s_115)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_115)); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = 0; @@ -40981,8 +41628,8 @@ static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_loc2str(CYTHON_UNUSED st * i = 0 * while i < loc.arr_high: */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_114)); - __pyx_v_result = ((PyObject *)__pyx_kp_s_114); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_116)); + __pyx_v_result = ((PyObject *)__pyx_kp_s_116); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":793 * cdef int i, j @@ -41011,7 +41658,7 @@ static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_loc2str(CYTHON_UNUSED st * for j from i <= j < i + loc.num_subpatterns: * result = result + ("%d " %loc.arr[j]) */ - __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_kp_s_115)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_kp_s_117)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_v_result); __pyx_v_result = __pyx_t_2; @@ -41036,7 +41683,7 @@ static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_loc2str(CYTHON_UNUSED st */ __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_loc->arr), __pyx_v_j, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_18), __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_21), __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 797; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -41054,7 +41701,7 @@ static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_loc2str(CYTHON_UNUSED st * i = i + loc.num_subpatterns * result = result + "}" */ - __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_kp_s_56)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_kp_s_59)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_v_result); __pyx_v_result = __pyx_t_2; @@ -41077,7 +41724,7 @@ static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_loc2str(CYTHON_UNUSED st * return result * */ - __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_kp_s_116)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyNumber_Add(__pyx_v_result, ((PyObject *)__pyx_kp_s_118)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 800; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_v_result); __pyx_v_result = __pyx_t_2; @@ -41194,7 +41841,7 @@ static struct __pyx_obj_3_sa_PhraseLocation *__pyx_f_3_sa_23HieroCachingRuleFact * if result is not None: * intersect_method = "precomputed" */ - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s_117); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s_119); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); @@ -41272,9 +41919,9 @@ static struct __pyx_obj_3_sa_PhraseLocation *__pyx_f_3_sa_23HieroCachingRuleFact * else: * result = self.intersect_helper(prefix, suffix, prefix_loc, suffix_loc, MERGE) */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_118)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_120)); __Pyx_XDECREF(__pyx_v_intersect_method); - __pyx_v_intersect_method = ((PyObject *)__pyx_kp_s_118); + __pyx_v_intersect_method = ((PyObject *)__pyx_kp_s_120); goto __pyx_L5; } /*else*/ { @@ -43798,14 +44445,14 @@ static PyObject *__pyx_pw_3_sa_23HieroCachingRuleFactory_23input(PyObject *__pyx */ static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_22input(struct __pyx_obj_3_sa_HieroCachingRuleFactory *__pyx_v_self, PyObject *__pyx_v_fwords, PyObject *__pyx_v_models) { - struct __pyx_obj_3_sa___pyx_scope_struct_2_input *__pyx_cur_scope; + struct __pyx_obj_3_sa___pyx_scope_struct_4_input *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("input", 0); - __pyx_cur_scope = (struct __pyx_obj_3_sa___pyx_scope_struct_2_input *)__pyx_ptype_3_sa___pyx_scope_struct_2_input->tp_new(__pyx_ptype_3_sa___pyx_scope_struct_2_input, __pyx_empty_tuple, NULL); + __pyx_cur_scope = (struct __pyx_obj_3_sa___pyx_scope_struct_4_input *)__pyx_ptype_3_sa___pyx_scope_struct_4_input->tp_new(__pyx_ptype_3_sa___pyx_scope_struct_4_input, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -43841,7 +44488,7 @@ static PyObject *__pyx_pf_3_sa_23HieroCachingRuleFactory_22input(struct __pyx_ob static PyObject *__pyx_gb_3_sa_23HieroCachingRuleFactory_24generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_3_sa___pyx_scope_struct_2_input *__pyx_cur_scope = ((struct __pyx_obj_3_sa___pyx_scope_struct_2_input *)__pyx_generator->closure); + struct __pyx_obj_3_sa___pyx_scope_struct_4_input *__pyx_cur_scope = ((struct __pyx_obj_3_sa___pyx_scope_struct_4_input *)__pyx_generator->closure); PyObject *__pyx_r = NULL; Py_ssize_t __pyx_t_1; PyObject *__pyx_t_2 = NULL; @@ -44879,7 +45526,7 @@ static PyObject *__pyx_gb_3_sa_23HieroCachingRuleFactory_24generator2(__pyx_Gene * # checking whether lookup_required * if lookup_required: */ - __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_k_tuple_120), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1004; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_builtin_Exception, ((PyObject *)__pyx_k_tuple_122), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1004; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -46643,7 +47290,7 @@ static PyObject *__pyx_gb_3_sa_23HieroCachingRuleFactory_24generator2(__pyx_Gene * nodes_isteps_away_buffer[key] = frontier_nodes * */ - __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_121); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_n_s_123); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_10); __pyx_t_9 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_self->min_gap_size); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); @@ -46907,9 +47554,9 @@ static PyObject *__pyx_gb_3_sa_23HieroCachingRuleFactory_24generator2(__pyx_Gene __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_12); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_122)); - PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)__pyx_kp_s_122)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_122)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_124)); + PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)__pyx_kp_s_124)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_124)); PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_14); __Pyx_GIVEREF(__pyx_t_14); __pyx_t_14 = 0; @@ -46952,9 +47599,9 @@ static PyObject *__pyx_gb_3_sa_23HieroCachingRuleFactory_24generator2(__pyx_Gene __Pyx_GOTREF(__pyx_t_14); __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_15); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_123)); - PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)__pyx_kp_s_123)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_123)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_125)); + PyTuple_SET_ITEM(__pyx_t_15, 0, ((PyObject *)__pyx_kp_s_125)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_125)); PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_14); __Pyx_GIVEREF(__pyx_t_14); __pyx_t_14 = 0; @@ -49754,8 +50401,8 @@ static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_extract(struct __pyx_obj * * for i from 0 <= i < e_sent_len: */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_42)); - __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_42); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_45)); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_45); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1446 * reason_for_failure = "" @@ -50129,9 +50776,9 @@ static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_extract(struct __pyx_obj * met_constraints = 0 * if self.require_aligned_chunks and num_aligned_chunks < num_chunks: */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_124)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_126)); __Pyx_DECREF(__pyx_v_reason_for_failure); - __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_124); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_126); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1486 * if num_aligned_chunks == 0: @@ -50167,9 +50814,9 @@ static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_extract(struct __pyx_obj * met_constraints = 0 * */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_125)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_127)); __Pyx_DECREF(__pyx_v_reason_for_failure); - __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_125); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_127); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1489 * if self.require_aligned_chunks and num_aligned_chunks < num_chunks: @@ -50227,9 +50874,9 @@ static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_extract(struct __pyx_obj * met_constraints = 0 * break */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_126)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_128)); __Pyx_DECREF(__pyx_v_reason_for_failure); - __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_126); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_128); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1496 * if f_links_low[matching.arr[matching.start+i]+chunklen[i]-f_sent_start] == -1: @@ -50269,9 +50916,9 @@ static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_extract(struct __pyx_obj * met_constraints = 0 * break */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_126)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_128)); __Pyx_DECREF(__pyx_v_reason_for_failure); - __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_126); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_128); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1500 * if f_links_low[matching.arr[matching.start+i+1]-1-f_sent_start] == -1: @@ -50483,9 +51130,9 @@ static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_extract(struct __pyx_obj * else: * gap_start = 1 */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_127)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_129)); __Pyx_DECREF(__pyx_v_reason_for_failure); - __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_127); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_129); goto __pyx_L38; } __pyx_L38:; @@ -50681,9 +51328,9 @@ static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_extract(struct __pyx_obj * else: * if self.tight_phrases and f_links_low[f_high-1] == -1: */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_128)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_130)); __Pyx_DECREF(__pyx_v_reason_for_failure); - __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_128); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_130); goto __pyx_L45; } __pyx_L45:; @@ -50801,7 +51448,7 @@ static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_extract(struct __pyx_obj __Pyx_GIVEREF(__pyx_t_1); __pyx_t_10 = 0; __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_129), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1565; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_131), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1565; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_v_reason_for_failure); @@ -51117,7 +51764,7 @@ static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_extract(struct __pyx_obj __pyx_t_2 = 0; __pyx_t_1 = 0; __pyx_t_14 = 0; - __pyx_t_14 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_130), ((PyObject *)__pyx_t_15)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1595; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_14 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_132), ((PyObject *)__pyx_t_15)); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1595; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_14)); __Pyx_DECREF(((PyObject *)__pyx_t_15)); __pyx_t_15 = 0; __Pyx_DECREF(__pyx_v_reason_for_failure); @@ -53335,9 +53982,9 @@ static PyObject *__pyx_f_3_sa_23HieroCachingRuleFactory_extract(struct __pyx_obj * * free(sent_links) */ - __Pyx_INCREF(((PyObject *)__pyx_kp_s_131)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_133)); __Pyx_DECREF(__pyx_v_reason_for_failure); - __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_131); + __pyx_v_reason_for_failure = ((PyObject *)__pyx_kp_s_133); } __pyx_L34:; goto __pyx_L33; @@ -54631,10 +55278,12 @@ static PyMethodDef __pyx_methods_3_sa_DataArray[] = { {__Pyx_NAMESTR("get_word"), (PyCFunction)__pyx_pw_3_sa_9DataArray_13get_word, METH_O, __Pyx_DOCSTR(0)}, {__Pyx_NAMESTR("write_text"), (PyCFunction)__pyx_pw_3_sa_9DataArray_15write_text, METH_O, __Pyx_DOCSTR(0)}, {__Pyx_NAMESTR("read_text"), (PyCFunction)__pyx_pw_3_sa_9DataArray_17read_text, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("read_binary"), (PyCFunction)__pyx_pw_3_sa_9DataArray_19read_binary, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("write_binary"), (PyCFunction)__pyx_pw_3_sa_9DataArray_21write_binary, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("write_enhanced_handle"), (PyCFunction)__pyx_pw_3_sa_9DataArray_23write_enhanced_handle, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("write_enhanced"), (PyCFunction)__pyx_pw_3_sa_9DataArray_25write_enhanced, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_bitext"), (PyCFunction)__pyx_pw_3_sa_9DataArray_19read_bitext, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_text_data"), (PyCFunction)__pyx_pw_3_sa_9DataArray_21read_text_data, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("read_binary"), (PyCFunction)__pyx_pw_3_sa_9DataArray_23read_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_binary"), (PyCFunction)__pyx_pw_3_sa_9DataArray_25write_binary, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_enhanced_handle"), (PyCFunction)__pyx_pw_3_sa_9DataArray_27write_enhanced_handle, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("write_enhanced"), (PyCFunction)__pyx_pw_3_sa_9DataArray_29write_enhanced, METH_O, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; @@ -56869,7 +57518,7 @@ static PyMethodDef __pyx_methods_3_sa_SuffixArray[] = { {__Pyx_NAMESTR("getSentId"), (PyCFunction)__pyx_pw_3_sa_11SuffixArray_5getSentId, METH_O, __Pyx_DOCSTR(0)}, {__Pyx_NAMESTR("getSent"), (PyCFunction)__pyx_pw_3_sa_11SuffixArray_7getSent, METH_O, __Pyx_DOCSTR(0)}, {__Pyx_NAMESTR("getSentPos"), (PyCFunction)__pyx_pw_3_sa_11SuffixArray_9getSentPos, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("read_text"), (PyCFunction)__pyx_pw_3_sa_11SuffixArray_11read_text, METH_O, __Pyx_DOCSTR(__pyx_doc_3_sa_11SuffixArray_10read_text)}, + {__Pyx_NAMESTR("read_text"), (PyCFunction)__pyx_pw_3_sa_11SuffixArray_11read_text, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_3_sa_11SuffixArray_10read_text)}, {__Pyx_NAMESTR("q3sort"), (PyCFunction)__pyx_pw_3_sa_11SuffixArray_13q3sort, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_3_sa_11SuffixArray_12q3sort)}, {__Pyx_NAMESTR("write_text"), (PyCFunction)__pyx_pw_3_sa_11SuffixArray_15write_text, METH_O, __Pyx_DOCSTR(0)}, {__Pyx_NAMESTR("read_binary"), (PyCFunction)__pyx_pw_3_sa_11SuffixArray_17read_binary, METH_O, __Pyx_DOCSTR(0)}, @@ -58040,7 +58689,517 @@ static PyNumberMethods __pyx_tp_as_number_Sampler = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Sampler = { +static PySequenceMethods __pyx_tp_as_sequence_Sampler = { + 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_Sampler = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Sampler = { + #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_3_sa_Sampler = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.Sampler"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_Sampler), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_Sampler, /*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_Sampler, /*tp_as_number*/ + &__pyx_tp_as_sequence_Sampler, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Sampler, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Sampler, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + __Pyx_DOCSTR("A Sampler implements a logic for choosing\n samples from a population range"), /*tp_doc*/ + __pyx_tp_traverse_3_sa_Sampler, /*tp_traverse*/ + __pyx_tp_clear_3_sa_Sampler, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_Sampler, /*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_3_sa_Sampler, /*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 struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory __pyx_vtable_3_sa_HieroCachingRuleFactory; + +static PyObject *__pyx_tp_new_3_sa_HieroCachingRuleFactory(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_3_sa_HieroCachingRuleFactory *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa_HieroCachingRuleFactory *)o); + p->__pyx_vtab = __pyx_vtabptr_3_sa_HieroCachingRuleFactory; + p->rules = ((struct __pyx_obj_3_sa_TrieTable *)Py_None); Py_INCREF(Py_None); + p->sampler = ((struct __pyx_obj_3_sa_Sampler *)Py_None); Py_INCREF(Py_None); + p->precomputed_index = Py_None; Py_INCREF(Py_None); + p->precomputed_collocations = Py_None; Py_INCREF(Py_None); + p->precompute_file = Py_None; Py_INCREF(Py_None); + p->max_rank = Py_None; Py_INCREF(Py_None); + p->prev_norm_prefix = Py_None; Py_INCREF(Py_None); + p->fsa = ((struct __pyx_obj_3_sa_SuffixArray *)Py_None); Py_INCREF(Py_None); + p->fda = ((struct __pyx_obj_3_sa_DataArray *)Py_None); Py_INCREF(Py_None); + p->eda = ((struct __pyx_obj_3_sa_DataArray *)Py_None); Py_INCREF(Py_None); + p->alignment = ((struct __pyx_obj_3_sa_Alignment *)Py_None); Py_INCREF(Py_None); + p->eid2symid = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->fid2symid = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->findexes = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + p->findexes1 = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_3_sa_23HieroCachingRuleFactory_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_3_sa_HieroCachingRuleFactory(PyObject *o) { + struct __pyx_obj_3_sa_HieroCachingRuleFactory *p = (struct __pyx_obj_3_sa_HieroCachingRuleFactory *)o; + Py_XDECREF(((PyObject *)p->rules)); + Py_XDECREF(((PyObject *)p->sampler)); + Py_XDECREF(p->precomputed_index); + Py_XDECREF(p->precomputed_collocations); + Py_XDECREF(p->precompute_file); + Py_XDECREF(p->max_rank); + Py_XDECREF(p->prev_norm_prefix); + Py_XDECREF(((PyObject *)p->fsa)); + Py_XDECREF(((PyObject *)p->fda)); + Py_XDECREF(((PyObject *)p->eda)); + Py_XDECREF(((PyObject *)p->alignment)); + Py_XDECREF(((PyObject *)p->eid2symid)); + Py_XDECREF(((PyObject *)p->fid2symid)); + Py_XDECREF(((PyObject *)p->findexes)); + Py_XDECREF(((PyObject *)p->findexes1)); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_3_sa_HieroCachingRuleFactory(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa_HieroCachingRuleFactory *p = (struct __pyx_obj_3_sa_HieroCachingRuleFactory *)o; + if (p->rules) { + e = (*v)(((PyObject*)p->rules), a); if (e) return e; + } + if (p->sampler) { + e = (*v)(((PyObject*)p->sampler), a); if (e) return e; + } + if (p->precomputed_index) { + e = (*v)(p->precomputed_index, a); if (e) return e; + } + if (p->precomputed_collocations) { + e = (*v)(p->precomputed_collocations, a); if (e) return e; + } + if (p->precompute_file) { + e = (*v)(p->precompute_file, a); if (e) return e; + } + if (p->max_rank) { + e = (*v)(p->max_rank, a); if (e) return e; + } + if (p->prev_norm_prefix) { + e = (*v)(p->prev_norm_prefix, a); if (e) return e; + } + if (p->fsa) { + e = (*v)(((PyObject*)p->fsa), a); if (e) return e; + } + if (p->fda) { + e = (*v)(((PyObject*)p->fda), a); if (e) return e; + } + if (p->eda) { + e = (*v)(((PyObject*)p->eda), a); if (e) return e; + } + if (p->alignment) { + e = (*v)(((PyObject*)p->alignment), a); if (e) return e; + } + if (p->eid2symid) { + e = (*v)(((PyObject*)p->eid2symid), a); if (e) return e; + } + if (p->fid2symid) { + e = (*v)(((PyObject*)p->fid2symid), a); if (e) return e; + } + if (p->findexes) { + e = (*v)(((PyObject*)p->findexes), a); if (e) return e; + } + if (p->findexes1) { + e = (*v)(((PyObject*)p->findexes1), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa_HieroCachingRuleFactory(PyObject *o) { + struct __pyx_obj_3_sa_HieroCachingRuleFactory *p = (struct __pyx_obj_3_sa_HieroCachingRuleFactory *)o; + PyObject* tmp; + tmp = ((PyObject*)p->rules); + p->rules = ((struct __pyx_obj_3_sa_TrieTable *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->sampler); + p->sampler = ((struct __pyx_obj_3_sa_Sampler *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->precomputed_index); + p->precomputed_index = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->precomputed_collocations); + p->precomputed_collocations = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->precompute_file); + p->precompute_file = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->max_rank); + p->max_rank = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->prev_norm_prefix); + p->prev_norm_prefix = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->fsa); + p->fsa = ((struct __pyx_obj_3_sa_SuffixArray *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->fda); + p->fda = ((struct __pyx_obj_3_sa_DataArray *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->eda); + p->eda = ((struct __pyx_obj_3_sa_DataArray *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->alignment); + p->alignment = ((struct __pyx_obj_3_sa_Alignment *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->eid2symid); + p->eid2symid = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->fid2symid); + p->fid2symid = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->findexes); + p->findexes = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->findexes1); + p->findexes1 = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_3_sa_HieroCachingRuleFactory[] = { + {__Pyx_NAMESTR("configure"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_3configure, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_3_sa_23HieroCachingRuleFactory_2configure)}, + {__Pyx_NAMESTR("pattern2phrase"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_5pattern2phrase, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("pattern2phrase_plus"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_7pattern2phrase_plus, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("precompute"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_9precompute, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_precomputed_collocation"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_11get_precomputed_collocation, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("advance"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_13advance, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_all_nodes_isteps_away"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_15get_all_nodes_isteps_away, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("reachable"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_17reachable, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("shortest"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_19shortest, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("get_next_states"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_21get_next_states, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("input"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_23input, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_3_sa_23HieroCachingRuleFactory_22input)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_HieroCachingRuleFactory = { + 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_HieroCachingRuleFactory = { + 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_HieroCachingRuleFactory = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_HieroCachingRuleFactory = { + #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_3_sa_HieroCachingRuleFactory = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_sa.HieroCachingRuleFactory"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa_HieroCachingRuleFactory), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_3_sa_HieroCachingRuleFactory, /*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_HieroCachingRuleFactory, /*tp_as_number*/ + &__pyx_tp_as_sequence_HieroCachingRuleFactory, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_HieroCachingRuleFactory, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_HieroCachingRuleFactory, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + __Pyx_DOCSTR("This RuleFactory implements a caching \n method using TrieTable, which makes phrase\n generation somewhat speedier -- phrases only\n need to be extracted once (however, it is\n quite possible they need to be scored \n for each input sentence, for contextual models)"), /*tp_doc*/ + __pyx_tp_traverse_3_sa_HieroCachingRuleFactory, /*tp_traverse*/ + __pyx_tp_clear_3_sa_HieroCachingRuleFactory, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_3_sa_HieroCachingRuleFactory, /*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_3_sa_HieroCachingRuleFactory, /*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_3_sa___pyx_scope_struct__read_bitext(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_3_sa___pyx_scope_struct__read_bitext *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_3_sa___pyx_scope_struct__read_bitext *)o); + p->__pyx_v_fp = 0; + return o; +} + +static void __pyx_tp_dealloc_3_sa___pyx_scope_struct__read_bitext(PyObject *o) { + struct __pyx_obj_3_sa___pyx_scope_struct__read_bitext *p = (struct __pyx_obj_3_sa___pyx_scope_struct__read_bitext *)o; + Py_XDECREF(p->__pyx_v_fp); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_3_sa___pyx_scope_struct__read_bitext(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_3_sa___pyx_scope_struct__read_bitext *p = (struct __pyx_obj_3_sa___pyx_scope_struct__read_bitext *)o; + if (p->__pyx_v_fp) { + e = (*v)(p->__pyx_v_fp, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_3_sa___pyx_scope_struct__read_bitext(PyObject *o) { + struct __pyx_obj_3_sa___pyx_scope_struct__read_bitext *p = (struct __pyx_obj_3_sa___pyx_scope_struct__read_bitext *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_fp); + p->__pyx_v_fp = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_3_sa___pyx_scope_struct__read_bitext[] = { + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct__read_bitext = { + 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__read_bitext = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -58053,13 +59212,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Sampler = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Sampler = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct__read_bitext = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Sampler = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct__read_bitext = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -58080,12 +59239,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Sampler = { #endif }; -static PyTypeObject __pyx_type_3_sa_Sampler = { +static PyTypeObject __pyx_type_3_sa___pyx_scope_struct__read_bitext = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_sa.Sampler"), /*tp_name*/ - sizeof(struct __pyx_obj_3_sa_Sampler), /*tp_basicsize*/ + __Pyx_NAMESTR("_sa.__pyx_scope_struct__read_bitext"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa___pyx_scope_struct__read_bitext), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_3_sa_Sampler, /*tp_dealloc*/ + __pyx_tp_dealloc_3_sa___pyx_scope_struct__read_bitext, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -58095,24 +59254,24 @@ static PyTypeObject __pyx_type_3_sa_Sampler = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Sampler, /*tp_as_number*/ - &__pyx_tp_as_sequence_Sampler, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Sampler, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct__read_bitext, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct__read_bitext, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct__read_bitext, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Sampler, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - __Pyx_DOCSTR("A Sampler implements a logic for choosing\n samples from a population range"), /*tp_doc*/ - __pyx_tp_traverse_3_sa_Sampler, /*tp_traverse*/ - __pyx_tp_clear_3_sa_Sampler, /*tp_clear*/ + &__pyx_tp_as_buffer___pyx_scope_struct__read_bitext, /*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_3_sa___pyx_scope_struct__read_bitext, /*tp_traverse*/ + __pyx_tp_clear_3_sa___pyx_scope_struct__read_bitext, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_3_sa_Sampler, /*tp_methods*/ + __pyx_methods_3_sa___pyx_scope_struct__read_bitext, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -58122,7 +59281,7 @@ static PyTypeObject __pyx_type_3_sa_Sampler = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_3_sa_Sampler, /*tp_new*/ + __pyx_tp_new_3_sa___pyx_scope_struct__read_bitext, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -58135,173 +59294,61 @@ static PyTypeObject __pyx_type_3_sa_Sampler = { 0, /*tp_version_tag*/ #endif }; -static struct __pyx_vtabstruct_3_sa_HieroCachingRuleFactory __pyx_vtable_3_sa_HieroCachingRuleFactory; -static PyObject *__pyx_tp_new_3_sa_HieroCachingRuleFactory(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_3_sa_HieroCachingRuleFactory *p; +static PyObject *__pyx_tp_new_3_sa___pyx_scope_struct_1_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_3_sa___pyx_scope_struct_1_genexpr *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_3_sa_HieroCachingRuleFactory *)o); - p->__pyx_vtab = __pyx_vtabptr_3_sa_HieroCachingRuleFactory; - p->rules = ((struct __pyx_obj_3_sa_TrieTable *)Py_None); Py_INCREF(Py_None); - p->sampler = ((struct __pyx_obj_3_sa_Sampler *)Py_None); Py_INCREF(Py_None); - p->precomputed_index = Py_None; Py_INCREF(Py_None); - p->precomputed_collocations = Py_None; Py_INCREF(Py_None); - p->precompute_file = Py_None; Py_INCREF(Py_None); - p->max_rank = Py_None; Py_INCREF(Py_None); - p->prev_norm_prefix = Py_None; Py_INCREF(Py_None); - p->fsa = ((struct __pyx_obj_3_sa_SuffixArray *)Py_None); Py_INCREF(Py_None); - p->fda = ((struct __pyx_obj_3_sa_DataArray *)Py_None); Py_INCREF(Py_None); - p->eda = ((struct __pyx_obj_3_sa_DataArray *)Py_None); Py_INCREF(Py_None); - p->alignment = ((struct __pyx_obj_3_sa_Alignment *)Py_None); Py_INCREF(Py_None); - p->eid2symid = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); - p->fid2symid = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); - p->findexes = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); - p->findexes1 = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); - if (__pyx_pw_3_sa_23HieroCachingRuleFactory_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } + p = ((struct __pyx_obj_3_sa___pyx_scope_struct_1_genexpr *)o); + p->__pyx_outer_scope = 0; + p->__pyx_v_line = 0; + p->__pyx_t_0 = 0; return o; } -static void __pyx_tp_dealloc_3_sa_HieroCachingRuleFactory(PyObject *o) { - struct __pyx_obj_3_sa_HieroCachingRuleFactory *p = (struct __pyx_obj_3_sa_HieroCachingRuleFactory *)o; - Py_XDECREF(((PyObject *)p->rules)); - Py_XDECREF(((PyObject *)p->sampler)); - Py_XDECREF(p->precomputed_index); - Py_XDECREF(p->precomputed_collocations); - Py_XDECREF(p->precompute_file); - Py_XDECREF(p->max_rank); - Py_XDECREF(p->prev_norm_prefix); - Py_XDECREF(((PyObject *)p->fsa)); - Py_XDECREF(((PyObject *)p->fda)); - Py_XDECREF(((PyObject *)p->eda)); - Py_XDECREF(((PyObject *)p->alignment)); - Py_XDECREF(((PyObject *)p->eid2symid)); - Py_XDECREF(((PyObject *)p->fid2symid)); - Py_XDECREF(((PyObject *)p->findexes)); - Py_XDECREF(((PyObject *)p->findexes1)); +static void __pyx_tp_dealloc_3_sa___pyx_scope_struct_1_genexpr(PyObject *o) { + struct __pyx_obj_3_sa___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_3_sa___pyx_scope_struct_1_genexpr *)o; + Py_XDECREF(((PyObject *)p->__pyx_outer_scope)); + Py_XDECREF(p->__pyx_v_line); + Py_XDECREF(p->__pyx_t_0); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_3_sa_HieroCachingRuleFactory(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_3_sa___pyx_scope_struct_1_genexpr(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_3_sa_HieroCachingRuleFactory *p = (struct __pyx_obj_3_sa_HieroCachingRuleFactory *)o; - if (p->rules) { - e = (*v)(((PyObject*)p->rules), a); if (e) return e; - } - if (p->sampler) { - e = (*v)(((PyObject*)p->sampler), a); if (e) return e; - } - if (p->precomputed_index) { - e = (*v)(p->precomputed_index, a); if (e) return e; - } - if (p->precomputed_collocations) { - e = (*v)(p->precomputed_collocations, a); if (e) return e; - } - if (p->precompute_file) { - e = (*v)(p->precompute_file, a); if (e) return e; - } - if (p->max_rank) { - e = (*v)(p->max_rank, a); if (e) return e; - } - if (p->prev_norm_prefix) { - e = (*v)(p->prev_norm_prefix, a); if (e) return e; - } - if (p->fsa) { - e = (*v)(((PyObject*)p->fsa), a); if (e) return e; - } - if (p->fda) { - e = (*v)(((PyObject*)p->fda), a); if (e) return e; - } - if (p->eda) { - e = (*v)(((PyObject*)p->eda), a); if (e) return e; - } - if (p->alignment) { - e = (*v)(((PyObject*)p->alignment), a); if (e) return e; - } - if (p->eid2symid) { - e = (*v)(((PyObject*)p->eid2symid), a); if (e) return e; + struct __pyx_obj_3_sa___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_3_sa___pyx_scope_struct_1_genexpr *)o; + if (p->__pyx_outer_scope) { + e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e; } - if (p->fid2symid) { - e = (*v)(((PyObject*)p->fid2symid), a); if (e) return e; + if (p->__pyx_v_line) { + e = (*v)(p->__pyx_v_line, a); if (e) return e; } - if (p->findexes) { - e = (*v)(((PyObject*)p->findexes), a); if (e) return e; - } - if (p->findexes1) { - e = (*v)(((PyObject*)p->findexes1), a); if (e) return e; + if (p->__pyx_t_0) { + e = (*v)(p->__pyx_t_0, a); if (e) return e; } return 0; } -static int __pyx_tp_clear_3_sa_HieroCachingRuleFactory(PyObject *o) { - struct __pyx_obj_3_sa_HieroCachingRuleFactory *p = (struct __pyx_obj_3_sa_HieroCachingRuleFactory *)o; +static int __pyx_tp_clear_3_sa___pyx_scope_struct_1_genexpr(PyObject *o) { + struct __pyx_obj_3_sa___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_3_sa___pyx_scope_struct_1_genexpr *)o; PyObject* tmp; - tmp = ((PyObject*)p->rules); - p->rules = ((struct __pyx_obj_3_sa_TrieTable *)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_outer_scope); + p->__pyx_outer_scope = ((struct __pyx_obj_3_sa___pyx_scope_struct__read_bitext *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); - tmp = ((PyObject*)p->sampler); - p->sampler = ((struct __pyx_obj_3_sa_Sampler *)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_line); + p->__pyx_v_line = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); - tmp = ((PyObject*)p->precomputed_index); - p->precomputed_index = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->precomputed_collocations); - p->precomputed_collocations = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->precompute_file); - p->precompute_file = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->max_rank); - p->max_rank = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->prev_norm_prefix); - p->prev_norm_prefix = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->fsa); - p->fsa = ((struct __pyx_obj_3_sa_SuffixArray *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->fda); - p->fda = ((struct __pyx_obj_3_sa_DataArray *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->eda); - p->eda = ((struct __pyx_obj_3_sa_DataArray *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->alignment); - p->alignment = ((struct __pyx_obj_3_sa_Alignment *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->eid2symid); - p->eid2symid = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->fid2symid); - p->fid2symid = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->findexes); - p->findexes = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->findexes1); - p->findexes1 = ((struct __pyx_obj_3_sa_IntList *)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_t_0); + p->__pyx_t_0 = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_3_sa_HieroCachingRuleFactory[] = { - {__Pyx_NAMESTR("configure"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_3configure, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_3_sa_23HieroCachingRuleFactory_2configure)}, - {__Pyx_NAMESTR("pattern2phrase"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_5pattern2phrase, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("pattern2phrase_plus"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_7pattern2phrase_plus, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("precompute"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_9precompute, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_precomputed_collocation"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_11get_precomputed_collocation, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("advance"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_13advance, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_all_nodes_isteps_away"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_15get_all_nodes_isteps_away, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("reachable"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_17reachable, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("shortest"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_19shortest, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_next_states"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_21get_next_states, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("input"), (PyCFunction)__pyx_pw_3_sa_23HieroCachingRuleFactory_23input, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_3_sa_23HieroCachingRuleFactory_22input)}, +static PyMethodDef __pyx_methods_3_sa___pyx_scope_struct_1_genexpr[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_HieroCachingRuleFactory = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1_genexpr = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -58359,7 +59406,7 @@ static PyNumberMethods __pyx_tp_as_number_HieroCachingRuleFactory = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_HieroCachingRuleFactory = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1_genexpr = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -58372,13 +59419,13 @@ static PySequenceMethods __pyx_tp_as_sequence_HieroCachingRuleFactory = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_HieroCachingRuleFactory = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1_genexpr = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_HieroCachingRuleFactory = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1_genexpr = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -58399,12 +59446,12 @@ static PyBufferProcs __pyx_tp_as_buffer_HieroCachingRuleFactory = { #endif }; -static PyTypeObject __pyx_type_3_sa_HieroCachingRuleFactory = { +static PyTypeObject __pyx_type_3_sa___pyx_scope_struct_1_genexpr = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_sa.HieroCachingRuleFactory"), /*tp_name*/ - sizeof(struct __pyx_obj_3_sa_HieroCachingRuleFactory), /*tp_basicsize*/ + __Pyx_NAMESTR("_sa.__pyx_scope_struct_1_genexpr"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa___pyx_scope_struct_1_genexpr), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_3_sa_HieroCachingRuleFactory, /*tp_dealloc*/ + __pyx_tp_dealloc_3_sa___pyx_scope_struct_1_genexpr, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -58414,24 +59461,24 @@ static PyTypeObject __pyx_type_3_sa_HieroCachingRuleFactory = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_HieroCachingRuleFactory, /*tp_as_number*/ - &__pyx_tp_as_sequence_HieroCachingRuleFactory, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_HieroCachingRuleFactory, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_1_genexpr, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_1_genexpr, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_1_genexpr, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_HieroCachingRuleFactory, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - __Pyx_DOCSTR("This RuleFactory implements a caching \n method using TrieTable, which makes phrase\n generation somewhat speedier -- phrases only\n need to be extracted once (however, it is\n quite possible they need to be scored \n for each input sentence, for contextual models)"), /*tp_doc*/ - __pyx_tp_traverse_3_sa_HieroCachingRuleFactory, /*tp_traverse*/ - __pyx_tp_clear_3_sa_HieroCachingRuleFactory, /*tp_clear*/ + &__pyx_tp_as_buffer___pyx_scope_struct_1_genexpr, /*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_3_sa___pyx_scope_struct_1_genexpr, /*tp_traverse*/ + __pyx_tp_clear_3_sa___pyx_scope_struct_1_genexpr, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_3_sa_HieroCachingRuleFactory, /*tp_methods*/ + __pyx_methods_3_sa___pyx_scope_struct_1_genexpr, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -58441,7 +59488,7 @@ static PyTypeObject __pyx_type_3_sa_HieroCachingRuleFactory = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_3_sa_HieroCachingRuleFactory, /*tp_new*/ + __pyx_tp_new_3_sa___pyx_scope_struct_1_genexpr, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -58455,11 +59502,11 @@ static PyTypeObject __pyx_type_3_sa_HieroCachingRuleFactory = { #endif }; -static PyObject *__pyx_tp_new_3_sa___pyx_scope_struct__compute_stats(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { - struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *p; +static PyObject *__pyx_tp_new_3_sa___pyx_scope_struct_2_compute_stats(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_3_sa___pyx_scope_struct_2_compute_stats *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *)o); + p = ((struct __pyx_obj_3_sa___pyx_scope_struct_2_compute_stats *)o); p->__pyx_v_ngram = 0; p->__pyx_v_ngram_start = 0; p->__pyx_v_ngram_starts = 0; @@ -58469,8 +59516,8 @@ static PyObject *__pyx_tp_new_3_sa___pyx_scope_struct__compute_stats(PyTypeObjec return o; } -static void __pyx_tp_dealloc_3_sa___pyx_scope_struct__compute_stats(PyObject *o) { - struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *p = (struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *)o; +static void __pyx_tp_dealloc_3_sa___pyx_scope_struct_2_compute_stats(PyObject *o) { + struct __pyx_obj_3_sa___pyx_scope_struct_2_compute_stats *p = (struct __pyx_obj_3_sa___pyx_scope_struct_2_compute_stats *)o; Py_XDECREF(((PyObject *)p->__pyx_v_ngram)); Py_XDECREF(((PyObject *)p->__pyx_v_ngram_start)); Py_XDECREF(((PyObject *)p->__pyx_v_ngram_starts)); @@ -58480,9 +59527,9 @@ static void __pyx_tp_dealloc_3_sa___pyx_scope_struct__compute_stats(PyObject *o) (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_3_sa___pyx_scope_struct__compute_stats(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_3_sa___pyx_scope_struct_2_compute_stats(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *p = (struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *)o; + struct __pyx_obj_3_sa___pyx_scope_struct_2_compute_stats *p = (struct __pyx_obj_3_sa___pyx_scope_struct_2_compute_stats *)o; if (p->__pyx_v_ngram) { e = (*v)(p->__pyx_v_ngram, a); if (e) return e; } @@ -58504,8 +59551,8 @@ static int __pyx_tp_traverse_3_sa___pyx_scope_struct__compute_stats(PyObject *o, return 0; } -static int __pyx_tp_clear_3_sa___pyx_scope_struct__compute_stats(PyObject *o) { - struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *p = (struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats *)o; +static int __pyx_tp_clear_3_sa___pyx_scope_struct_2_compute_stats(PyObject *o) { + struct __pyx_obj_3_sa___pyx_scope_struct_2_compute_stats *p = (struct __pyx_obj_3_sa___pyx_scope_struct_2_compute_stats *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_ngram); p->__pyx_v_ngram = ((PyObject*)Py_None); Py_INCREF(Py_None); @@ -58528,11 +59575,11 @@ static int __pyx_tp_clear_3_sa___pyx_scope_struct__compute_stats(PyObject *o) { return 0; } -static PyMethodDef __pyx_methods_3_sa___pyx_scope_struct__compute_stats[] = { +static PyMethodDef __pyx_methods_3_sa___pyx_scope_struct_2_compute_stats[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct__compute_stats = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_compute_stats = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -58590,7 +59637,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct__compute_stats = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct__compute_stats = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_compute_stats = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -58603,13 +59650,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct__compute_stats 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct__compute_stats = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_2_compute_stats = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct__compute_stats = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_compute_stats = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -58630,12 +59677,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct__compute_stats = { #endif }; -static PyTypeObject __pyx_type_3_sa___pyx_scope_struct__compute_stats = { +static PyTypeObject __pyx_type_3_sa___pyx_scope_struct_2_compute_stats = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_sa.__pyx_scope_struct__compute_stats"), /*tp_name*/ - sizeof(struct __pyx_obj_3_sa___pyx_scope_struct__compute_stats), /*tp_basicsize*/ + __Pyx_NAMESTR("_sa.__pyx_scope_struct_2_compute_stats"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa___pyx_scope_struct_2_compute_stats), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_3_sa___pyx_scope_struct__compute_stats, /*tp_dealloc*/ + __pyx_tp_dealloc_3_sa___pyx_scope_struct_2_compute_stats, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -58645,24 +59692,24 @@ static PyTypeObject __pyx_type_3_sa___pyx_scope_struct__compute_stats = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct__compute_stats, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct__compute_stats, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct__compute_stats, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_2_compute_stats, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_2_compute_stats, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_2_compute_stats, /*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__compute_stats, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_2_compute_stats, /*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_3_sa___pyx_scope_struct__compute_stats, /*tp_traverse*/ - __pyx_tp_clear_3_sa___pyx_scope_struct__compute_stats, /*tp_clear*/ + __pyx_tp_traverse_3_sa___pyx_scope_struct_2_compute_stats, /*tp_traverse*/ + __pyx_tp_clear_3_sa___pyx_scope_struct_2_compute_stats, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_3_sa___pyx_scope_struct__compute_stats, /*tp_methods*/ + __pyx_methods_3_sa___pyx_scope_struct_2_compute_stats, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -58672,7 +59719,7 @@ static PyTypeObject __pyx_type_3_sa___pyx_scope_struct__compute_stats = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_3_sa___pyx_scope_struct__compute_stats, /*tp_new*/ + __pyx_tp_new_3_sa___pyx_scope_struct_2_compute_stats, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -58686,32 +59733,32 @@ static PyTypeObject __pyx_type_3_sa___pyx_scope_struct__compute_stats = { #endif }; -static PyObject *__pyx_tp_new_3_sa___pyx_scope_struct_1___iter__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { - struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *p; +static PyObject *__pyx_tp_new_3_sa___pyx_scope_struct_3___iter__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_3_sa___pyx_scope_struct_3___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *)o); + p = ((struct __pyx_obj_3_sa___pyx_scope_struct_3___iter__ *)o); p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_3_sa___pyx_scope_struct_1___iter__(PyObject *o) { - struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *)o; +static void __pyx_tp_dealloc_3_sa___pyx_scope_struct_3___iter__(PyObject *o) { + struct __pyx_obj_3_sa___pyx_scope_struct_3___iter__ *p = (struct __pyx_obj_3_sa___pyx_scope_struct_3___iter__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_3_sa___pyx_scope_struct_1___iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_3_sa___pyx_scope_struct_3___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *)o; + struct __pyx_obj_3_sa___pyx_scope_struct_3___iter__ *p = (struct __pyx_obj_3_sa___pyx_scope_struct_3___iter__ *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_3_sa___pyx_scope_struct_1___iter__(PyObject *o) { - struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__ *)o; +static int __pyx_tp_clear_3_sa___pyx_scope_struct_3___iter__(PyObject *o) { + struct __pyx_obj_3_sa___pyx_scope_struct_3___iter__ *p = (struct __pyx_obj_3_sa___pyx_scope_struct_3___iter__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); p->__pyx_v_self = ((struct __pyx_obj_3_sa_Phrase *)Py_None); Py_INCREF(Py_None); @@ -58719,11 +59766,11 @@ static int __pyx_tp_clear_3_sa___pyx_scope_struct_1___iter__(PyObject *o) { return 0; } -static PyMethodDef __pyx_methods_3_sa___pyx_scope_struct_1___iter__[] = { +static PyMethodDef __pyx_methods_3_sa___pyx_scope_struct_3___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -58781,7 +59828,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1___iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -58794,13 +59841,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1___iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1___iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_3___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -58821,12 +59868,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { #endif }; -static PyTypeObject __pyx_type_3_sa___pyx_scope_struct_1___iter__ = { +static PyTypeObject __pyx_type_3_sa___pyx_scope_struct_3___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_sa.__pyx_scope_struct_1___iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_3_sa___pyx_scope_struct_1___iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_sa.__pyx_scope_struct_3___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa___pyx_scope_struct_3___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_3_sa___pyx_scope_struct_1___iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_3_sa___pyx_scope_struct_3___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -58836,24 +59883,24 @@ static PyTypeObject __pyx_type_3_sa___pyx_scope_struct_1___iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_1___iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_1___iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_1___iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_3___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_3___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_3___iter__, /*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___iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_3___iter__, /*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_3_sa___pyx_scope_struct_1___iter__, /*tp_traverse*/ - __pyx_tp_clear_3_sa___pyx_scope_struct_1___iter__, /*tp_clear*/ + __pyx_tp_traverse_3_sa___pyx_scope_struct_3___iter__, /*tp_traverse*/ + __pyx_tp_clear_3_sa___pyx_scope_struct_3___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_3_sa___pyx_scope_struct_1___iter__, /*tp_methods*/ + __pyx_methods_3_sa___pyx_scope_struct_3___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -58863,7 +59910,7 @@ static PyTypeObject __pyx_type_3_sa___pyx_scope_struct_1___iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_3_sa___pyx_scope_struct_1___iter__, /*tp_new*/ + __pyx_tp_new_3_sa___pyx_scope_struct_3___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -58877,11 +59924,11 @@ static PyTypeObject __pyx_type_3_sa___pyx_scope_struct_1___iter__ = { #endif }; -static PyObject *__pyx_tp_new_3_sa___pyx_scope_struct_2_input(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { - struct __pyx_obj_3_sa___pyx_scope_struct_2_input *p; +static PyObject *__pyx_tp_new_3_sa___pyx_scope_struct_4_input(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_3_sa___pyx_scope_struct_4_input *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_3_sa___pyx_scope_struct_2_input *)o); + p = ((struct __pyx_obj_3_sa___pyx_scope_struct_4_input *)o); p->__pyx_v_alignment = 0; p->__pyx_v_als = 0; p->__pyx_v_alslist = 0; @@ -58935,8 +59982,8 @@ static PyObject *__pyx_tp_new_3_sa___pyx_scope_struct_2_input(PyTypeObject *t, C return o; } -static void __pyx_tp_dealloc_3_sa___pyx_scope_struct_2_input(PyObject *o) { - struct __pyx_obj_3_sa___pyx_scope_struct_2_input *p = (struct __pyx_obj_3_sa___pyx_scope_struct_2_input *)o; +static void __pyx_tp_dealloc_3_sa___pyx_scope_struct_4_input(PyObject *o) { + struct __pyx_obj_3_sa___pyx_scope_struct_4_input *p = (struct __pyx_obj_3_sa___pyx_scope_struct_4_input *)o; Py_XDECREF(p->__pyx_v_alignment); Py_XDECREF(p->__pyx_v_als); Py_XDECREF(p->__pyx_v_alslist); @@ -58990,9 +60037,9 @@ static void __pyx_tp_dealloc_3_sa___pyx_scope_struct_2_input(PyObject *o) { (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_3_sa___pyx_scope_struct_2_input(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_3_sa___pyx_scope_struct_4_input(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_3_sa___pyx_scope_struct_2_input *p = (struct __pyx_obj_3_sa___pyx_scope_struct_2_input *)o; + struct __pyx_obj_3_sa___pyx_scope_struct_4_input *p = (struct __pyx_obj_3_sa___pyx_scope_struct_4_input *)o; if (p->__pyx_v_alignment) { e = (*v)(p->__pyx_v_alignment, a); if (e) return e; } @@ -59146,8 +60193,8 @@ static int __pyx_tp_traverse_3_sa___pyx_scope_struct_2_input(PyObject *o, visitp return 0; } -static int __pyx_tp_clear_3_sa___pyx_scope_struct_2_input(PyObject *o) { - struct __pyx_obj_3_sa___pyx_scope_struct_2_input *p = (struct __pyx_obj_3_sa___pyx_scope_struct_2_input *)o; +static int __pyx_tp_clear_3_sa___pyx_scope_struct_4_input(PyObject *o) { + struct __pyx_obj_3_sa___pyx_scope_struct_4_input *p = (struct __pyx_obj_3_sa___pyx_scope_struct_4_input *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_alignment); p->__pyx_v_alignment = Py_None; Py_INCREF(Py_None); @@ -59302,11 +60349,11 @@ static int __pyx_tp_clear_3_sa___pyx_scope_struct_2_input(PyObject *o) { return 0; } -static PyMethodDef __pyx_methods_3_sa___pyx_scope_struct_2_input[] = { +static PyMethodDef __pyx_methods_3_sa___pyx_scope_struct_4_input[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_input = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4_input = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -59364,7 +60411,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_input = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_input = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4_input = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -59377,13 +60424,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_input = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_2_input = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_4_input = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_input = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4_input = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -59404,12 +60451,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_input = { #endif }; -static PyTypeObject __pyx_type_3_sa___pyx_scope_struct_2_input = { +static PyTypeObject __pyx_type_3_sa___pyx_scope_struct_4_input = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_sa.__pyx_scope_struct_2_input"), /*tp_name*/ - sizeof(struct __pyx_obj_3_sa___pyx_scope_struct_2_input), /*tp_basicsize*/ + __Pyx_NAMESTR("_sa.__pyx_scope_struct_4_input"), /*tp_name*/ + sizeof(struct __pyx_obj_3_sa___pyx_scope_struct_4_input), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_3_sa___pyx_scope_struct_2_input, /*tp_dealloc*/ + __pyx_tp_dealloc_3_sa___pyx_scope_struct_4_input, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -59419,24 +60466,24 @@ static PyTypeObject __pyx_type_3_sa___pyx_scope_struct_2_input = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_2_input, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_2_input, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_2_input, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_4_input, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_4_input, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_4_input, /*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_input, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_4_input, /*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_3_sa___pyx_scope_struct_2_input, /*tp_traverse*/ - __pyx_tp_clear_3_sa___pyx_scope_struct_2_input, /*tp_clear*/ + __pyx_tp_traverse_3_sa___pyx_scope_struct_4_input, /*tp_traverse*/ + __pyx_tp_clear_3_sa___pyx_scope_struct_4_input, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_3_sa___pyx_scope_struct_2_input, /*tp_methods*/ + __pyx_methods_3_sa___pyx_scope_struct_4_input, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -59446,7 +60493,7 @@ static PyTypeObject __pyx_type_3_sa___pyx_scope_struct_2_input = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_3_sa___pyx_scope_struct_2_input, /*tp_new*/ + __pyx_tp_new_3_sa___pyx_scope_struct_4_input, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -59480,11 +60527,11 @@ static struct PyModuleDef __pyx_moduledef = { static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0}, - {&__pyx_n_s_101, __pyx_k_101, sizeof(__pyx_k_101), 0, 0, 1, 1}, - {&__pyx_n_s_102, __pyx_k_102, sizeof(__pyx_k_102), 0, 0, 1, 1}, - {&__pyx_kp_s_104, __pyx_k_104, sizeof(__pyx_k_104), 0, 0, 1, 0}, + {&__pyx_kp_s_100, __pyx_k_100, sizeof(__pyx_k_100), 0, 0, 1, 0}, + {&__pyx_kp_s_101, __pyx_k_101, sizeof(__pyx_k_101), 0, 0, 1, 0}, + {&__pyx_n_s_103, __pyx_k_103, sizeof(__pyx_k_103), 0, 0, 1, 1}, + {&__pyx_n_s_104, __pyx_k_104, sizeof(__pyx_k_104), 0, 0, 1, 1}, {&__pyx_kp_s_106, __pyx_k_106, sizeof(__pyx_k_106), 0, 0, 1, 0}, - {&__pyx_kp_s_107, __pyx_k_107, sizeof(__pyx_k_107), 0, 0, 1, 0}, {&__pyx_kp_s_108, __pyx_k_108, sizeof(__pyx_k_108), 0, 0, 1, 0}, {&__pyx_kp_s_109, __pyx_k_109, sizeof(__pyx_k_109), 0, 0, 1, 0}, {&__pyx_kp_s_110, __pyx_k_110, sizeof(__pyx_k_110), 0, 0, 1, 0}, @@ -59494,12 +60541,12 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_114, __pyx_k_114, sizeof(__pyx_k_114), 0, 0, 1, 0}, {&__pyx_kp_s_115, __pyx_k_115, sizeof(__pyx_k_115), 0, 0, 1, 0}, {&__pyx_kp_s_116, __pyx_k_116, sizeof(__pyx_k_116), 0, 0, 1, 0}, - {&__pyx_n_s_117, __pyx_k_117, sizeof(__pyx_k_117), 0, 0, 1, 1}, + {&__pyx_kp_s_117, __pyx_k_117, sizeof(__pyx_k_117), 0, 0, 1, 0}, {&__pyx_kp_s_118, __pyx_k_118, sizeof(__pyx_k_118), 0, 0, 1, 0}, - {&__pyx_kp_s_119, __pyx_k_119, sizeof(__pyx_k_119), 0, 0, 1, 0}, - {&__pyx_n_s_121, __pyx_k_121, sizeof(__pyx_k_121), 0, 0, 1, 1}, - {&__pyx_kp_s_122, __pyx_k_122, sizeof(__pyx_k_122), 0, 0, 1, 0}, - {&__pyx_kp_s_123, __pyx_k_123, sizeof(__pyx_k_123), 0, 0, 1, 0}, + {&__pyx_n_s_119, __pyx_k_119, sizeof(__pyx_k_119), 0, 0, 1, 1}, + {&__pyx_kp_s_120, __pyx_k_120, sizeof(__pyx_k_120), 0, 0, 1, 0}, + {&__pyx_kp_s_121, __pyx_k_121, sizeof(__pyx_k_121), 0, 0, 1, 0}, + {&__pyx_n_s_123, __pyx_k_123, sizeof(__pyx_k_123), 0, 0, 1, 1}, {&__pyx_kp_s_124, __pyx_k_124, sizeof(__pyx_k_124), 0, 0, 1, 0}, {&__pyx_kp_s_125, __pyx_k_125, sizeof(__pyx_k_125), 0, 0, 1, 0}, {&__pyx_kp_s_126, __pyx_k_126, sizeof(__pyx_k_126), 0, 0, 1, 0}, @@ -59509,49 +60556,49 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0}, {&__pyx_kp_s_130, __pyx_k_130, sizeof(__pyx_k_130), 0, 0, 1, 0}, {&__pyx_kp_s_131, __pyx_k_131, sizeof(__pyx_k_131), 0, 0, 1, 0}, - {&__pyx_kp_s_134, __pyx_k_134, sizeof(__pyx_k_134), 0, 0, 1, 0}, - {&__pyx_kp_s_135, __pyx_k_135, sizeof(__pyx_k_135), 0, 0, 1, 0}, - {&__pyx_kp_s_139, __pyx_k_139, sizeof(__pyx_k_139), 0, 0, 1, 0}, + {&__pyx_kp_s_132, __pyx_k_132, sizeof(__pyx_k_132), 0, 0, 1, 0}, + {&__pyx_kp_s_133, __pyx_k_133, sizeof(__pyx_k_133), 0, 0, 1, 0}, + {&__pyx_kp_s_136, __pyx_k_136, sizeof(__pyx_k_136), 0, 0, 1, 0}, + {&__pyx_kp_s_137, __pyx_k_137, sizeof(__pyx_k_137), 0, 0, 1, 0}, {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0}, - {&__pyx_kp_s_140, __pyx_k_140, sizeof(__pyx_k_140), 0, 0, 1, 0}, + {&__pyx_kp_s_141, __pyx_k_141, sizeof(__pyx_k_141), 0, 0, 1, 0}, + {&__pyx_kp_s_142, __pyx_k_142, sizeof(__pyx_k_142), 0, 0, 1, 0}, {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0}, {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0}, - {&__pyx_kp_s_22, __pyx_k_22, sizeof(__pyx_k_22), 0, 0, 1, 0}, - {&__pyx_n_s_24, __pyx_k_24, sizeof(__pyx_k_24), 0, 0, 1, 1}, - {&__pyx_kp_s_28, __pyx_k_28, sizeof(__pyx_k_28), 0, 0, 1, 0}, + {&__pyx_kp_s_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 1, 0}, + {&__pyx_kp_s_25, __pyx_k_25, sizeof(__pyx_k_25), 0, 0, 1, 0}, + {&__pyx_n_s_27, __pyx_k_27, sizeof(__pyx_k_27), 0, 0, 1, 1}, {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0}, - {&__pyx_kp_s_32, __pyx_k_32, sizeof(__pyx_k_32), 0, 0, 1, 0}, - {&__pyx_kp_s_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 1, 0}, + {&__pyx_kp_s_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 0, 1, 0}, + {&__pyx_kp_s_35, __pyx_k_35, sizeof(__pyx_k_35), 0, 0, 1, 0}, {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0}, {&__pyx_kp_s_42, __pyx_k_42, sizeof(__pyx_k_42), 0, 0, 1, 0}, - {&__pyx_kp_s_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 1, 0}, {&__pyx_kp_s_45, __pyx_k_45, sizeof(__pyx_k_45), 0, 0, 1, 0}, - {&__pyx_kp_s_47, __pyx_k_47, sizeof(__pyx_k_47), 0, 0, 1, 0}, - {&__pyx_kp_s_49, __pyx_k_49, sizeof(__pyx_k_49), 0, 0, 1, 0}, + {&__pyx_kp_s_46, __pyx_k_46, sizeof(__pyx_k_46), 0, 0, 1, 0}, + {&__pyx_kp_s_48, __pyx_k_48, sizeof(__pyx_k_48), 0, 0, 1, 0}, {&__pyx_kp_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 0}, - {&__pyx_kp_s_53, __pyx_k_53, sizeof(__pyx_k_53), 0, 0, 1, 0}, - {&__pyx_kp_s_55, __pyx_k_55, sizeof(__pyx_k_55), 0, 0, 1, 0}, + {&__pyx_kp_s_50, __pyx_k_50, sizeof(__pyx_k_50), 0, 0, 1, 0}, + {&__pyx_kp_s_52, __pyx_k_52, sizeof(__pyx_k_52), 0, 0, 1, 0}, {&__pyx_kp_s_56, __pyx_k_56, sizeof(__pyx_k_56), 0, 0, 1, 0}, - {&__pyx_kp_s_57, __pyx_k_57, sizeof(__pyx_k_57), 0, 0, 1, 0}, + {&__pyx_kp_s_58, __pyx_k_58, sizeof(__pyx_k_58), 0, 0, 1, 0}, {&__pyx_kp_s_59, __pyx_k_59, sizeof(__pyx_k_59), 0, 0, 1, 0}, {&__pyx_kp_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 0}, - {&__pyx_kp_s_61, __pyx_k_61, sizeof(__pyx_k_61), 0, 0, 1, 0}, + {&__pyx_kp_s_60, __pyx_k_60, sizeof(__pyx_k_60), 0, 0, 1, 0}, {&__pyx_kp_s_62, __pyx_k_62, sizeof(__pyx_k_62), 0, 0, 1, 0}, - {&__pyx_kp_s_63, __pyx_k_63, sizeof(__pyx_k_63), 0, 0, 1, 0}, {&__pyx_kp_s_64, __pyx_k_64, sizeof(__pyx_k_64), 0, 0, 1, 0}, {&__pyx_kp_s_65, __pyx_k_65, sizeof(__pyx_k_65), 0, 0, 1, 0}, {&__pyx_kp_s_66, __pyx_k_66, sizeof(__pyx_k_66), 0, 0, 1, 0}, {&__pyx_kp_s_67, __pyx_k_67, sizeof(__pyx_k_67), 0, 0, 1, 0}, - {&__pyx_n_s_68, __pyx_k_68, sizeof(__pyx_k_68), 0, 0, 1, 1}, - {&__pyx_n_s_69, __pyx_k_69, sizeof(__pyx_k_69), 0, 0, 1, 1}, + {&__pyx_kp_s_68, __pyx_k_68, sizeof(__pyx_k_68), 0, 0, 1, 0}, + {&__pyx_kp_s_69, __pyx_k_69, sizeof(__pyx_k_69), 0, 0, 1, 0}, {&__pyx_kp_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 0}, - {&__pyx_kp_s_70, __pyx_k_70, sizeof(__pyx_k_70), 0, 0, 1, 0}, + {&__pyx_n_s_70, __pyx_k_70, sizeof(__pyx_k_70), 0, 0, 1, 1}, + {&__pyx_n_s_71, __pyx_k_71, sizeof(__pyx_k_71), 0, 0, 1, 1}, {&__pyx_kp_s_72, __pyx_k_72, sizeof(__pyx_k_72), 0, 0, 1, 0}, {&__pyx_kp_s_74, __pyx_k_74, sizeof(__pyx_k_74), 0, 0, 1, 0}, {&__pyx_kp_s_76, __pyx_k_76, sizeof(__pyx_k_76), 0, 0, 1, 0}, + {&__pyx_kp_s_78, __pyx_k_78, sizeof(__pyx_k_78), 0, 0, 1, 0}, {&__pyx_kp_s_8, __pyx_k_8, sizeof(__pyx_k_8), 0, 0, 1, 0}, - {&__pyx_kp_s_81, __pyx_k_81, sizeof(__pyx_k_81), 0, 0, 1, 0}, - {&__pyx_kp_s_82, __pyx_k_82, sizeof(__pyx_k_82), 0, 0, 1, 0}, {&__pyx_kp_s_83, __pyx_k_83, sizeof(__pyx_k_83), 0, 0, 1, 0}, {&__pyx_kp_s_84, __pyx_k_84, sizeof(__pyx_k_84), 0, 0, 1, 0}, {&__pyx_kp_s_85, __pyx_k_85, sizeof(__pyx_k_85), 0, 0, 1, 0}, @@ -59561,10 +60608,10 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_89, __pyx_k_89, sizeof(__pyx_k_89), 0, 0, 1, 0}, {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0}, {&__pyx_kp_s_90, __pyx_k_90, sizeof(__pyx_k_90), 0, 0, 1, 0}, + {&__pyx_kp_s_91, __pyx_k_91, sizeof(__pyx_k_91), 0, 0, 1, 0}, {&__pyx_kp_s_92, __pyx_k_92, sizeof(__pyx_k_92), 0, 0, 1, 0}, - {&__pyx_kp_s_93, __pyx_k_93, sizeof(__pyx_k_93), 0, 0, 1, 0}, - {&__pyx_kp_s_98, __pyx_k_98, sizeof(__pyx_k_98), 0, 0, 1, 0}, - {&__pyx_kp_s_99, __pyx_k_99, sizeof(__pyx_k_99), 0, 0, 1, 0}, + {&__pyx_kp_s_94, __pyx_k_94, sizeof(__pyx_k_94), 0, 0, 1, 0}, + {&__pyx_kp_s_95, __pyx_k_95, sizeof(__pyx_k_95), 0, 0, 1, 0}, {&__pyx_kp_s__0, __pyx_k__0, sizeof(__pyx_k__0), 0, 0, 1, 0}, {&__pyx_kp_s__1, __pyx_k__1, sizeof(__pyx_k__1), 0, 0, 1, 0}, {&__pyx_n_s__END_OF_FILE, __pyx_k__END_OF_FILE, sizeof(__pyx_k__END_OF_FILE), 0, 0, 1, 1}, @@ -59682,7 +60729,9 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__reachable, __pyx_k__reachable, sizeof(__pyx_k__reachable), 0, 0, 1, 1}, {&__pyx_n_s__reachable_buffer, __pyx_k__reachable_buffer, sizeof(__pyx_k__reachable_buffer), 0, 0, 1, 1}, {&__pyx_n_s__read_binary, __pyx_k__read_binary, sizeof(__pyx_k__read_binary), 0, 0, 1, 1}, + {&__pyx_n_s__read_bitext, __pyx_k__read_bitext, sizeof(__pyx_k__read_bitext), 0, 0, 1, 1}, {&__pyx_n_s__read_text, __pyx_k__read_text, sizeof(__pyx_k__read_text), 0, 0, 1, 1}, + {&__pyx_n_s__read_text_data, __pyx_k__read_text_data, sizeof(__pyx_k__read_text_data), 0, 0, 1, 1}, {&__pyx_n_s__res, __pyx_k__res, sizeof(__pyx_k__res), 0, 0, 1, 1}, {&__pyx_n_s__reset, __pyx_k__reset, sizeof(__pyx_k__reset), 0, 0, 1, 1}, {&__pyx_n_s__resource, __pyx_k__resource, sizeof(__pyx_k__resource), 0, 0, 1, 1}, @@ -59699,9 +60748,11 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__seek, __pyx_k__seek, sizeof(__pyx_k__seek), 0, 0, 1, 1}, {&__pyx_n_s__setdefault, __pyx_k__setdefault, sizeof(__pyx_k__setdefault), 0, 0, 1, 1}, {&__pyx_n_s__shortest, __pyx_k__shortest, sizeof(__pyx_k__shortest), 0, 0, 1, 1}, + {&__pyx_n_s__side, __pyx_k__side, sizeof(__pyx_k__side), 0, 0, 1, 1}, {&__pyx_n_s__size, __pyx_k__size, sizeof(__pyx_k__size), 0, 0, 1, 1}, {&__pyx_n_s__skip, __pyx_k__skip, sizeof(__pyx_k__skip), 0, 0, 1, 1}, {&__pyx_n_s__sorted, __pyx_k__sorted, sizeof(__pyx_k__sorted), 0, 0, 1, 1}, + {&__pyx_n_s__source, __pyx_k__source, sizeof(__pyx_k__source), 0, 0, 1, 1}, {&__pyx_n_s__spanlen, __pyx_k__spanlen, sizeof(__pyx_k__spanlen), 0, 0, 1, 1}, {&__pyx_n_s__split, __pyx_k__split, sizeof(__pyx_k__split), 0, 0, 1, 1}, {&__pyx_n_s__start, __pyx_k__start, sizeof(__pyx_k__start), 0, 0, 1, 1}, @@ -59734,7 +60785,7 @@ static int __Pyx_InitCachedBuiltins(void) { __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __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[2]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_map = __Pyx_GetName(__pyx_b, __pyx_n_s__map); if (!__pyx_builtin_map) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __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[5]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_zip = __Pyx_GetName(__pyx_b, __pyx_n_s__zip); if (!__pyx_builtin_zip) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -59802,28 +60853,28 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(__pyx_int_1000); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12)); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":62 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":65 * f.write("%s " % self.get_word(w_id)) * if w_id == 1: * f.write("\n") # <<<<<<<<<<<<<< * * def read_text(self, char* filename): */ - __pyx_k_tuple_15 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_15)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_15 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_15)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_15); __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); PyTuple_SET_ITEM(__pyx_k_tuple_15, 0, ((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_15)); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":57 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":60 * * def write_text(self, char* filename): * with open(filename, "w") as f: # <<<<<<<<<<<<<< * for w_id in self.data: * if w_id > 1: */ - __pyx_k_tuple_16 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_16)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_16 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_16)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_16); __Pyx_INCREF(Py_None); PyTuple_SET_ITEM(__pyx_k_tuple_16, 0, Py_None); @@ -59836,14 +60887,14 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(Py_None); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_16)); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":66 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":68 + * * def read_text(self, char* filename): - * cdef int word_count = 0 * with gzip_or_text(filename) as fp: # <<<<<<<<<<<<<< - * for line_num, line in enumerate(fp): - * self.sent_index.append(word_count) + * self.read_text_data(fp) + * */ - __pyx_k_tuple_17 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_17)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_17 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_17)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_17); __Pyx_INCREF(Py_None); PyTuple_SET_ITEM(__pyx_k_tuple_17, 0, Py_None); @@ -59856,80 +60907,114 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(Py_None); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_17)); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":133 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":73 + * def read_bitext(self, char* filename, int side): + * with gzip_or_text(filename) as fp: + * data = (line.split(' ||| ')[side] for line in fp) # <<<<<<<<<<<<<< + * self.read_text_data(data) + * + */ + __pyx_k_tuple_19 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_19)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_19); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_18)); + PyTuple_SET_ITEM(__pyx_k_tuple_19, 0, ((PyObject *)__pyx_kp_s_18)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_18)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_19)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":72 + * + * def read_bitext(self, char* filename, int side): + * with gzip_or_text(filename) as fp: # <<<<<<<<<<<<<< + * data = (line.split(' ||| ')[side] for line in fp) + * self.read_text_data(data) + */ + __pyx_k_tuple_20 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_20); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_20, 0, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_20, 1, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_INCREF(Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_20, 2, Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":145 * for i in self.data: * f.write("%d " %i) * f.write("\n") # <<<<<<<<<<<<<< * for i in self.sent_index: * f.write("%d " %i) */ - __pyx_k_tuple_19 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_19)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_19); + __pyx_k_tuple_22 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_22)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_22); __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_19, 0, ((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_22, 0, ((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_19)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22)); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":136 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":148 * for i in self.sent_index: * f.write("%d " %i) * f.write("\n") # <<<<<<<<<<<<<< * for i in self.sent_id: * f.write("%d " %i) */ - __pyx_k_tuple_20 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_20); + __pyx_k_tuple_23 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_23)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_23); __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_20, 0, ((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_23, 0, ((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_23)); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":139 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":151 * for i in self.sent_id: * f.write("%d " %i) * f.write("\n") # <<<<<<<<<<<<<< * for word in self.id2word: * f.write("%s %d " % (word, self.word2id[word])) */ - __pyx_k_tuple_21 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_21)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_21); + __pyx_k_tuple_24 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_24); __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_21, 0, ((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_24, 0, ((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_24)); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":142 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":154 * for word in self.id2word: * f.write("%s %d " % (word, self.word2id[word])) * f.write("\n") # <<<<<<<<<<<<<< * * def write_enhanced(self, char* filename): */ - __pyx_k_tuple_23 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_23)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_23); + __pyx_k_tuple_26 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_26)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_26); __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_23, 0, ((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_26, 0, ((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_23)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_26)); - /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":145 + /* "/Users/vchahun/Sandbox/cdec/python/src/sa/data_array.pxi":157 * * def write_enhanced(self, char* filename): * with open(filename, "w") as f: # <<<<<<<<<<<<<< * self.write_enhanced_handle(self, f) */ - __pyx_k_tuple_25 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_25); + __pyx_k_tuple_28 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_28)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_28); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_25, 0, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_28, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_25, 1, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_28, 1, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_25, 2, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_28, 2, Py_None); __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_25)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_28)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":46 * @@ -59938,15 +61023,15 @@ static int __Pyx_InitCachedConstants(void) { * self.sent_index = IntList(1000,1000) * if from_binary: */ - __pyx_k_tuple_26 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_26)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_26); + __pyx_k_tuple_29 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_29)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_29); __Pyx_INCREF(__pyx_int_1000); - PyTuple_SET_ITEM(__pyx_k_tuple_26, 0, __pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_29, 0, __pyx_int_1000); __Pyx_GIVEREF(__pyx_int_1000); __Pyx_INCREF(__pyx_int_1000); - PyTuple_SET_ITEM(__pyx_k_tuple_26, 1, __pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_29, 1, __pyx_int_1000); __Pyx_GIVEREF(__pyx_int_1000); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_26)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_29)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":47 * def __cinit__(self, from_binary=None, from_text=None): @@ -59955,15 +61040,15 @@ static int __Pyx_InitCachedConstants(void) { * if from_binary: * self.read_binary(from_binary) */ - __pyx_k_tuple_27 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_27)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_27); + __pyx_k_tuple_30 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_30)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_30); __Pyx_INCREF(__pyx_int_1000); - PyTuple_SET_ITEM(__pyx_k_tuple_27, 0, __pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_30, 0, __pyx_int_1000); __Pyx_GIVEREF(__pyx_int_1000); __Pyx_INCREF(__pyx_int_1000); - PyTuple_SET_ITEM(__pyx_k_tuple_27, 1, __pyx_int_1000); + PyTuple_SET_ITEM(__pyx_k_tuple_30, 1, __pyx_int_1000); __Pyx_GIVEREF(__pyx_int_1000); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_27)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_30)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":59 * pairs = line.split() @@ -59972,12 +61057,12 @@ static int __Pyx_InitCachedConstants(void) { * self.links.append(self.link(i, j)) * self.sent_index.append(len(self.links)) */ - __pyx_k_tuple_29 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_29)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_29); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_28)); - PyTuple_SET_ITEM(__pyx_k_tuple_29, 0, ((PyObject *)__pyx_kp_s_28)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_28)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_29)); + __pyx_k_tuple_32 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_32)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_32); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_31)); + PyTuple_SET_ITEM(__pyx_k_tuple_32, 0, ((PyObject *)__pyx_kp_s_31)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_31)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_32)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":54 * @@ -59986,18 +61071,18 @@ static int __Pyx_InitCachedConstants(void) { * for line in f: * self.sent_index.append(len(self.links)) */ - __pyx_k_tuple_30 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_30)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_30); + __pyx_k_tuple_33 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_33)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_33); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_30, 0, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_33, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_30, 1, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_33, 1, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_30, 2, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_33, 2, Py_None); __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_30)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_33)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":75 * for i, link in enumerate(self.links): @@ -60006,12 +61091,12 @@ static int __Pyx_InitCachedConstants(void) { * sent_num = sent_num + 1 * f.write("%d-%d " % self.unlink(link)) */ - __pyx_k_tuple_31 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_31)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_31); + __pyx_k_tuple_34 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_34)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_34); __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_31, 0, ((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_34, 0, ((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_31)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_34)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":78 * sent_num = sent_num + 1 @@ -60020,12 +61105,12 @@ static int __Pyx_InitCachedConstants(void) { * * def write_binary(self, char* filename): */ - __pyx_k_tuple_33 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_33)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_33); + __pyx_k_tuple_36 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_36)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_36); __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_33, 0, ((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_36, 0, ((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_33)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_36)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":71 * @@ -60034,18 +61119,18 @@ static int __Pyx_InitCachedConstants(void) { * sent_num = 0 * for i, link in enumerate(self.links): */ - __pyx_k_tuple_34 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_34)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_34); + __pyx_k_tuple_37 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_37)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_37); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_34, 0, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_37, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_34, 1, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_37, 1, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_34, 2, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_37, 2, Py_None); __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_34)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_37)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":92 * for link in self.links: @@ -60054,12 +61139,12 @@ static int __Pyx_InitCachedConstants(void) { * for i in self.sent_index: * f.write("%d " % i) */ - __pyx_k_tuple_35 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_35)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_35); + __pyx_k_tuple_38 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_38)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_38); __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_35, 0, ((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_38, 0, ((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_35)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_38)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":95 * for i in self.sent_index: @@ -60068,12 +61153,12 @@ static int __Pyx_InitCachedConstants(void) { * * def alignment(self, i): */ - __pyx_k_tuple_36 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_36)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_36); + __pyx_k_tuple_39 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_39)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_39); __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_36, 0, ((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_39, 0, ((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_36)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_39)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/alignment.pxi":88 * @@ -60082,18 +61167,18 @@ static int __Pyx_InitCachedConstants(void) { * sent_num = 1 * for link in self.links: */ - __pyx_k_tuple_37 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_37)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_37); + __pyx_k_tuple_40 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_40)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_40); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_37, 0, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_40, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_37, 1, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_40, 1, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_37, 2, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_40, 2, Py_None); __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_37)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_40)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":302 * @@ -60102,12 +61187,12 @@ static int __Pyx_InitCachedConstants(void) { * for line in f: * (fword, eword, score1, score2) = line.split() */ - __pyx_k_tuple_40 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_40)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_40); + __pyx_k_tuple_43 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_43)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_43); __Pyx_INCREF(__pyx_int_0); - PyTuple_SET_ITEM(__pyx_k_tuple_40, 0, __pyx_int_0); + PyTuple_SET_ITEM(__pyx_k_tuple_43, 0, __pyx_int_0); __Pyx_GIVEREF(__pyx_int_0); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_40)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_43)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":278 * @@ -60116,18 +61201,18 @@ static int __Pyx_InitCachedConstants(void) { * # first loop merely establishes size of array objects * for line in f: */ - __pyx_k_tuple_41 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_41)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_41); + __pyx_k_tuple_44 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_44)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_44); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_41, 0, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_44, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_41, 1, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_44, 1, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_41, 2, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_44, 2, Py_None); __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_41)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_44)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":344 * @@ -60136,12 +61221,12 @@ static int __Pyx_InitCachedConstants(void) { * if i == j: #empty interval * return */ - __pyx_k_tuple_44 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_44)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_44); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_43)); - PyTuple_SET_ITEM(__pyx_k_tuple_44, 0, ((PyObject *)__pyx_kp_s_43)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_43)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_44)); + __pyx_k_tuple_47 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_47)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_47); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_46)); + PyTuple_SET_ITEM(__pyx_k_tuple_47, 0, ((PyObject *)__pyx_kp_s_46)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_46)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_47)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":367 * for i in self.f_index: @@ -60150,12 +61235,12 @@ static int __Pyx_InitCachedConstants(void) { * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): * f.write("%d %f %f " % (i, s1, s2)) */ - __pyx_k_tuple_46 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_46)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_46); + __pyx_k_tuple_49 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_49)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_49); __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_46, 0, ((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_49, 0, ((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_46)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_49)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":370 * for i, s1, s2 in zip(self.e_index, self.col1, self.col2): @@ -60164,12 +61249,12 @@ static int __Pyx_InitCachedConstants(void) { * for i, w in enumerate(self.id2fword): * f.write("%d %s " % (i, w)) */ - __pyx_k_tuple_48 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_48)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_48); + __pyx_k_tuple_51 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_51)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 370; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_51); __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_48, 0, ((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_51, 0, ((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_48)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_51)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":373 * for i, w in enumerate(self.id2fword): @@ -60178,12 +61263,12 @@ static int __Pyx_InitCachedConstants(void) { * for i, w in enumerate(self.id2eword): * f.write("%d %s " % (i, w)) */ - __pyx_k_tuple_50 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_50)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_50); + __pyx_k_tuple_53 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_53)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_53); __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_50, 0, ((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_53, 0, ((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_50)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_53)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":376 * for i, w in enumerate(self.id2eword): @@ -60192,12 +61277,12 @@ static int __Pyx_InitCachedConstants(void) { * * */ - __pyx_k_tuple_51 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_51)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_51); + __pyx_k_tuple_54 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_54)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 376; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_54); __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_51, 0, ((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_54, 0, ((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_51)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_54)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":364 * @@ -60206,18 +61291,18 @@ static int __Pyx_InitCachedConstants(void) { * for i in self.f_index: * f.write("%d " % i) */ - __pyx_k_tuple_52 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_52); + __pyx_k_tuple_55 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_55)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_55); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_52, 0, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_55, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_52, 1, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_55, 1, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_52, 2, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_55, 2, Py_None); __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_52)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_55)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/bilex.pxi":409 * cdef i, N, e_id, f_id @@ -60226,18 +61311,18 @@ static int __Pyx_InitCachedConstants(void) { * N = len(self.e_index) * f_id = 0 */ - __pyx_k_tuple_54 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_54)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_54); + __pyx_k_tuple_57 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_57)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_57); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_54, 0, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_57, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_54, 1, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_57, 1, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_54, 2, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_57, 2, Py_None); __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_54)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_57)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":13 * cdef IntList rank @@ -60246,12 +61331,12 @@ static int __Pyx_InitCachedConstants(void) { * self.sa = sa * n = self.sa.sa.len */ - __pyx_k_tuple_58 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_58)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_58); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_57)); - PyTuple_SET_ITEM(__pyx_k_tuple_58, 0, ((PyObject *)__pyx_kp_s_57)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_57)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_58)); + __pyx_k_tuple_61 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_61)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_61); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_60)); + PyTuple_SET_ITEM(__pyx_k_tuple_61, 0, ((PyObject *)__pyx_kp_s_60)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_60)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_61)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/lcp.pxi":34 * if h > 0: @@ -60260,12 +61345,12 @@ static int __Pyx_InitCachedConstants(void) { * * def compute_stats(self, int max_n): */ - __pyx_k_tuple_60 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_60)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_60); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_59)); - PyTuple_SET_ITEM(__pyx_k_tuple_60, 0, ((PyObject *)__pyx_kp_s_59)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_59)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_60)); + __pyx_k_tuple_63 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_63)) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_63); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_62)); + PyTuple_SET_ITEM(__pyx_k_tuple_63, 0, ((PyObject *)__pyx_kp_s_62)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_62)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_63)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":297 * pattern_rank = {} @@ -60274,12 +61359,12 @@ static int __Pyx_InitCachedConstants(void) { * cdef float start_time = monitor_cpu() * */ - __pyx_k_tuple_71 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_71)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_71); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_70)); - PyTuple_SET_ITEM(__pyx_k_tuple_71, 0, ((PyObject *)__pyx_kp_s_70)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_70)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_71)); + __pyx_k_tuple_73 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_73)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_73); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_72)); + PyTuple_SET_ITEM(__pyx_k_tuple_73, 0, ((PyObject *)__pyx_kp_s_72)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_72)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_73)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":314 * queue = IntList(increment=1000) @@ -60288,12 +61373,12 @@ static int __Pyx_InitCachedConstants(void) { * N = len(data) * for i from 0 <= i < N: */ - __pyx_k_tuple_73 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_73)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_73); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_72)); - PyTuple_SET_ITEM(__pyx_k_tuple_73, 0, ((PyObject *)__pyx_kp_s_72)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_72)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_73)); + __pyx_k_tuple_75 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_75)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 314; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_75); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_74)); + PyTuple_SET_ITEM(__pyx_k_tuple_75, 0, ((PyObject *)__pyx_kp_s_74)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_74)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_75)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":329 * trie_node_data_append(node, i) @@ -60302,12 +61387,12 @@ static int __Pyx_InitCachedConstants(void) { * N = len(queue) * ptr1 = 0 */ - __pyx_k_tuple_75 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_75)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_75); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_74)); - PyTuple_SET_ITEM(__pyx_k_tuple_75, 0, ((PyObject *)__pyx_kp_s_74)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_74)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_75)); + __pyx_k_tuple_77 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_77)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_77); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_76)); + PyTuple_SET_ITEM(__pyx_k_tuple_77, 0, ((PyObject *)__pyx_kp_s_76)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_76)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_77)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":393 * for pattern2 in J_set: @@ -60316,12 +61401,12 @@ static int __Pyx_InitCachedConstants(void) { * J2_set.add(combined_pattern) * */ - __pyx_k_tuple_77 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_77)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_77); + __pyx_k_tuple_79 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_79)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_79); __Pyx_INCREF(__pyx_int_neg_1); - PyTuple_SET_ITEM(__pyx_k_tuple_77, 0, __pyx_int_neg_1); + PyTuple_SET_ITEM(__pyx_k_tuple_79, 0, __pyx_int_neg_1); __Pyx_GIVEREF(__pyx_int_neg_1); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_77)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_79)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":400 * x = x+1 @@ -60330,12 +61415,12 @@ static int __Pyx_InitCachedConstants(void) { * IJ_set.add(combined_pattern) * */ - __pyx_k_tuple_78 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_78)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_78); + __pyx_k_tuple_80 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_80)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_80); __Pyx_INCREF(__pyx_int_neg_1); - PyTuple_SET_ITEM(__pyx_k_tuple_78, 0, __pyx_int_neg_1); + PyTuple_SET_ITEM(__pyx_k_tuple_80, 0, __pyx_int_neg_1); __Pyx_GIVEREF(__pyx_int_neg_1); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_78)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_80)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":407 * x = x+2 @@ -60344,12 +61429,12 @@ static int __Pyx_InitCachedConstants(void) { * IJ_set.add(combined_pattern) * combined_pattern = pattern2 + (-1,) + pattern1 */ - __pyx_k_tuple_79 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_79)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_79); + __pyx_k_tuple_81 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_81)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_81); __Pyx_INCREF(__pyx_int_neg_1); - PyTuple_SET_ITEM(__pyx_k_tuple_79, 0, __pyx_int_neg_1); + PyTuple_SET_ITEM(__pyx_k_tuple_81, 0, __pyx_int_neg_1); __Pyx_GIVEREF(__pyx_int_neg_1); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_79)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_81)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/precomputation.pxi":409 * combined_pattern = pattern1 + (-1,) + pattern2 @@ -60358,12 +61443,12 @@ static int __Pyx_InitCachedConstants(void) { * IJ_set.add(combined_pattern) * */ - __pyx_k_tuple_80 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_80)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_80); + __pyx_k_tuple_82 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_82)) {__pyx_filename = __pyx_f[12]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_82); __Pyx_INCREF(__pyx_int_neg_1); - PyTuple_SET_ITEM(__pyx_k_tuple_80, 0, __pyx_int_neg_1); + PyTuple_SET_ITEM(__pyx_k_tuple_82, 0, __pyx_int_neg_1); __Pyx_GIVEREF(__pyx_int_neg_1); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_80)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_82)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":103 * @@ -60372,12 +61457,12 @@ static int __Pyx_InitCachedConstants(void) { * for i from 0 <= i < N: * j = isa.arr[i] */ - __pyx_k_tuple_91 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_91)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_91); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_90)); - PyTuple_SET_ITEM(__pyx_k_tuple_91, 0, ((PyObject *)__pyx_kp_s_90)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_90)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_91)); + __pyx_k_tuple_93 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_93)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_93); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_92)); + PyTuple_SET_ITEM(__pyx_k_tuple_93, 0, ((PyObject *)__pyx_kp_s_92)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_92)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_93)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":202 * for a_i in self.sa: @@ -60386,12 +61471,12 @@ static int __Pyx_InitCachedConstants(void) { * for w_i in self.ha: * f.write("%d " % w_i) */ - __pyx_k_tuple_94 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_94)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_94); + __pyx_k_tuple_96 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_96)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_96); __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_94, 0, ((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_96, 0, ((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_94)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_96)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":205 * for w_i in self.ha: @@ -60400,12 +61485,12 @@ static int __Pyx_InitCachedConstants(void) { * * cdef int __search_high(self, int word_id, int offset, int low, int high): */ - __pyx_k_tuple_95 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_95)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_95); + __pyx_k_tuple_97 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_97)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_97); __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); - PyTuple_SET_ITEM(__pyx_k_tuple_95, 0, ((PyObject *)__pyx_kp_s_14)); + PyTuple_SET_ITEM(__pyx_k_tuple_97, 0, ((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_95)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_97)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/suffix_array.pxi":198 * @@ -60414,18 +61499,18 @@ static int __Pyx_InitCachedConstants(void) { * self.darray.write_enhanced_handle(f) * for a_i in self.sa: */ - __pyx_k_tuple_96 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_96)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_96); + __pyx_k_tuple_98 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_98)) {__pyx_filename = __pyx_f[13]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_98); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_96, 0, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_98, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_96, 1, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_98, 1, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_96, 2, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_98, 2, Py_None); __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_96)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_98)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":92 * logger.info("Sampling strategy: uniform, max sample size = %d", sample_size) @@ -60434,12 +61519,12 @@ static int __Pyx_InitCachedConstants(void) { * * def sample(self, PhraseLocation phrase_location): */ - __pyx_k_tuple_100 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_100)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_100); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_99)); - PyTuple_SET_ITEM(__pyx_k_tuple_100, 0, ((PyObject *)__pyx_kp_s_99)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_99)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_100)); + __pyx_k_tuple_102 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_102)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_102); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_101)); + PyTuple_SET_ITEM(__pyx_k_tuple_102, 0, ((PyObject *)__pyx_kp_s_101)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_101)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_102)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":300 * self.rules.root = ExtendedTrieNode(phrase_location=PhraseLocation()) @@ -60448,12 +61533,12 @@ static int __Pyx_InitCachedConstants(void) { * self.alignment = alignment * */ - __pyx_k_tuple_105 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_105)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_105); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_104)); - PyTuple_SET_ITEM(__pyx_k_tuple_105, 0, ((PyObject *)__pyx_kp_s_104)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_104)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_105)); + __pyx_k_tuple_107 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_107)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_107); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_106)); + PyTuple_SET_ITEM(__pyx_k_tuple_107, 0, ((PyObject *)__pyx_kp_s_106)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_106)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_107)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/rulefactory.pxi":1004 * else: @@ -60462,12 +61547,12 @@ static int __Pyx_InitCachedConstants(void) { * # checking whether lookup_required * if lookup_required: */ - __pyx_k_tuple_120 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_120)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1004; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_120); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_119)); - PyTuple_SET_ITEM(__pyx_k_tuple_120, 0, ((PyObject *)__pyx_kp_s_119)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_119)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_120)); + __pyx_k_tuple_122 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_122)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 1004; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_122); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_121)); + PyTuple_SET_ITEM(__pyx_k_tuple_122, 0, ((PyObject *)__pyx_kp_s_121)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_121)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_122)); /* "_sa.pyx":9 * resource.getrusage(resource.RUSAGE_SELF).ru_stime) @@ -60476,16 +61561,16 @@ static int __Pyx_InitCachedConstants(void) { * if filename.endswith('.gz'): * return gzip.GzipFile(filename) */ - __pyx_k_tuple_132 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_132)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_132); + __pyx_k_tuple_134 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_134)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_134); __Pyx_INCREF(((PyObject *)__pyx_n_s__filename)); - PyTuple_SET_ITEM(__pyx_k_tuple_132, 0, ((PyObject *)__pyx_n_s__filename)); + PyTuple_SET_ITEM(__pyx_k_tuple_134, 0, ((PyObject *)__pyx_n_s__filename)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__filename)); __Pyx_INCREF(((PyObject *)__pyx_n_s__filename)); - PyTuple_SET_ITEM(__pyx_k_tuple_132, 1, ((PyObject *)__pyx_n_s__filename)); + PyTuple_SET_ITEM(__pyx_k_tuple_134, 1, ((PyObject *)__pyx_n_s__filename)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__filename)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_132)); - __pyx_k_codeobj_133 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_132, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_134, __pyx_n_s__gzip_or_text, 9, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_133)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_134)); + __pyx_k_codeobj_135 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_134, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_136, __pyx_n_s__gzip_or_text, 9, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_135)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "_sa.pyx":15 * return open(filename) @@ -60494,12 +61579,12 @@ static int __Pyx_InitCachedConstants(void) { * * include "float_list.pxi" */ - __pyx_k_tuple_136 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_136)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_136); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_135)); - PyTuple_SET_ITEM(__pyx_k_tuple_136, 0, ((PyObject *)__pyx_kp_s_135)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_135)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_136)); + __pyx_k_tuple_138 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_138)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_138); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_137)); + PyTuple_SET_ITEM(__pyx_k_tuple_138, 0, ((PyObject *)__pyx_kp_s_137)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_137)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_138)); /* "/Users/vchahun/Sandbox/cdec/python/src/sa/sym.pxi":104 * return ALPHABET.setindex(sym, id) @@ -60507,16 +61592,16 @@ static int __Pyx_InitCachedConstants(void) { * def sym_fromstring(char* string, bint terminal): # <<<<<<<<<<<<<< * return ALPHABET.fromstring(string, terminal) */ - __pyx_k_tuple_137 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_137)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_137); + __pyx_k_tuple_139 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_139)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_139); __Pyx_INCREF(((PyObject *)__pyx_n_s__string)); - PyTuple_SET_ITEM(__pyx_k_tuple_137, 0, ((PyObject *)__pyx_n_s__string)); + PyTuple_SET_ITEM(__pyx_k_tuple_139, 0, ((PyObject *)__pyx_n_s__string)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__string)); __Pyx_INCREF(((PyObject *)__pyx_n_s__terminal)); - PyTuple_SET_ITEM(__pyx_k_tuple_137, 1, ((PyObject *)__pyx_n_s__terminal)); + PyTuple_SET_ITEM(__pyx_k_tuple_139, 1, ((PyObject *)__pyx_n_s__terminal)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__terminal)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_137)); - __pyx_k_codeobj_138 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_137, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_139, __pyx_n_s__sym_fromstring, 104, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_138)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_139)); + __pyx_k_codeobj_140 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_139, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_141, __pyx_n_s__sym_fromstring, 104, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_140)) {__pyx_filename = __pyx_f[10]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -60776,12 +61861,16 @@ PyMODINIT_FUNC PyInit__sa(void) if (__Pyx_SetVtable(__pyx_type_3_sa_HieroCachingRuleFactory.tp_dict, __pyx_vtabptr_3_sa_HieroCachingRuleFactory) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "HieroCachingRuleFactory", (PyObject *)&__pyx_type_3_sa_HieroCachingRuleFactory) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 201; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_3_sa_HieroCachingRuleFactory = &__pyx_type_3_sa_HieroCachingRuleFactory; - if (PyType_Ready(&__pyx_type_3_sa___pyx_scope_struct__compute_stats) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_3_sa___pyx_scope_struct__compute_stats = &__pyx_type_3_sa___pyx_scope_struct__compute_stats; - if (PyType_Ready(&__pyx_type_3_sa___pyx_scope_struct_1___iter__) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_3_sa___pyx_scope_struct_1___iter__ = &__pyx_type_3_sa___pyx_scope_struct_1___iter__; - if (PyType_Ready(&__pyx_type_3_sa___pyx_scope_struct_2_input) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_3_sa___pyx_scope_struct_2_input = &__pyx_type_3_sa___pyx_scope_struct_2_input; + if (PyType_Ready(&__pyx_type_3_sa___pyx_scope_struct__read_bitext) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa___pyx_scope_struct__read_bitext = &__pyx_type_3_sa___pyx_scope_struct__read_bitext; + if (PyType_Ready(&__pyx_type_3_sa___pyx_scope_struct_1_genexpr) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa___pyx_scope_struct_1_genexpr = &__pyx_type_3_sa___pyx_scope_struct_1_genexpr; + if (PyType_Ready(&__pyx_type_3_sa___pyx_scope_struct_2_compute_stats) < 0) {__pyx_filename = __pyx_f[9]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa___pyx_scope_struct_2_compute_stats = &__pyx_type_3_sa___pyx_scope_struct_2_compute_stats; + if (PyType_Ready(&__pyx_type_3_sa___pyx_scope_struct_3___iter__) < 0) {__pyx_filename = __pyx_f[7]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa___pyx_scope_struct_3___iter__ = &__pyx_type_3_sa___pyx_scope_struct_3___iter__; + if (PyType_Ready(&__pyx_type_3_sa___pyx_scope_struct_4_input) < 0) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_3_sa___pyx_scope_struct_4_input = &__pyx_type_3_sa___pyx_scope_struct_4_input; /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ @@ -60844,7 +61933,7 @@ PyMODINIT_FUNC PyInit__sa(void) __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__getLogger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_136), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_138), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (PyObject_SetAttr(__pyx_m, __pyx_n_s__logger, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -60859,7 +61948,7 @@ PyMODINIT_FUNC PyInit__sa(void) */ __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_k_38 = __pyx_t_1; + __pyx_k_41 = __pyx_t_1; __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; @@ -60986,9 +62075,9 @@ PyMODINIT_FUNC PyInit__sa(void) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(((PyObject *)__pyx_kp_s_140)); - PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_140)); - __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_140)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_142)); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_kp_s_142)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_142)); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; @@ -61009,7 +62098,7 @@ PyMODINIT_FUNC PyInit__sa(void) */ __pyx_t_2 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[8]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_k_97 = __pyx_t_2; + __pyx_k_99 = __pyx_t_2; __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; @@ -61451,6 +62540,10 @@ bad: return -1; } +static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) { + PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname); +} + static CYTHON_INLINE long __Pyx_div_long(long a, long b) { long q = a / b; long r = a - q*b; @@ -61836,6 +62929,86 @@ bad: return module; } +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else + if (s1 == s2) { + return (equals == Py_EQ); + } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { + if (PyBytes_GET_SIZE(s1) != PyBytes_GET_SIZE(s2)) { + return (equals == Py_NE); + } else if (PyBytes_GET_SIZE(s1) == 1) { + if (equals == Py_EQ) + return (PyBytes_AS_STRING(s1)[0] == PyBytes_AS_STRING(s2)[0]); + else + return (PyBytes_AS_STRING(s1)[0] != PyBytes_AS_STRING(s2)[0]); + } else { + int result = memcmp(PyBytes_AS_STRING(s1), PyBytes_AS_STRING(s2), (size_t)PyBytes_GET_SIZE(s1)); + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { + return (equals == Py_NE); + } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { + return (equals == Py_NE); + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +#endif +} + +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY + return PyObject_RichCompareBool(s1, s2, equals); +#else + if (s1 == s2) { + return (equals == Py_EQ); + } else if (PyUnicode_CheckExact(s1) & PyUnicode_CheckExact(s2)) { + #if CYTHON_PEP393_ENABLED + if ((PyUnicode_READY(s1) < 0) || (PyUnicode_READY(s2) < 0)) + return -1; + if (PyUnicode_GET_LENGTH(s1) != PyUnicode_GET_LENGTH(s2)) { + return (equals == Py_NE); + } else if (PyUnicode_GET_LENGTH(s1) == 1) { + Py_UCS4 ch1 = PyUnicode_READ_CHAR(s1, 0); + Py_UCS4 ch2 = PyUnicode_READ_CHAR(s2, 0); + return (equals == Py_EQ) ? (ch1 == ch2) : (ch1 != ch2); + #else + if (PyUnicode_GET_SIZE(s1) != PyUnicode_GET_SIZE(s2)) { + return (equals == Py_NE); + } else if (PyUnicode_GET_SIZE(s1) == 1) { + Py_UNICODE ch1 = PyUnicode_AS_UNICODE(s1)[0]; + Py_UNICODE ch2 = PyUnicode_AS_UNICODE(s2)[0]; + return (equals == Py_EQ) ? (ch1 == ch2) : (ch1 != ch2); + #endif + } else { + int result = PyUnicode_Compare(s1, s2); + if ((result == -1) && unlikely(PyErr_Occurred())) + return -1; + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & PyUnicode_CheckExact(s2)) { + return (equals == Py_NE); + } else if ((s2 == Py_None) & PyUnicode_CheckExact(s1)) { + return (equals == Py_NE); + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +#endif +} + static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { const unsigned char neg_one = (unsigned char)-1, const_zero = 0; const int is_unsigned = neg_one > const_zero; diff --git a/python/src/sa/data_array.pxi b/python/src/sa/data_array.pxi index 1c044694..7a102a7e 100644 --- a/python/src/sa/data_array.pxi +++ b/python/src/sa/data_array.pxi @@ -14,7 +14,7 @@ cdef class DataArray: cdef IntList sent_index cdef bint use_sent_id - def __cinit__(self, from_binary=None, from_text=None, bint use_sent_id=False): + def __cinit__(self, from_binary=None, from_text=None, side=None, bint use_sent_id=False): self.word2id = {"END_OF_FILE":0, "END_OF_LINE":1} self.id2word = ["END_OF_FILE", "END_OF_LINE"] self.data = IntList(1000,1000) @@ -24,7 +24,10 @@ cdef class DataArray: if from_binary: self.read_binary(from_binary) elif from_text: - self.read_text(from_text) + if side: + self.read_bitext(from_text, (0 if side == 'source' else 1)) + else: + self.read_text(from_text) def __len__(self): return len(self.data) @@ -62,21 +65,30 @@ cdef class DataArray: f.write("\n") def read_text(self, char* filename): - cdef int word_count = 0 with gzip_or_text(filename) as fp: - for line_num, line in enumerate(fp): - self.sent_index.append(word_count) - for word in line.split(): - self.data.append(self.get_id(word)) - if self.use_sent_id: - self.sent_id.append(line_num) - word_count = word_count + 1 - self.data.append(1) + self.read_text_data(fp) + + def read_bitext(self, char* filename, int side): + with gzip_or_text(filename) as fp: + data = (line.split(' ||| ')[side] for line in fp) + self.read_text_data(data) + + def read_text_data(self, data): + cdef int word_count = 0 + for line_num, line in enumerate(data): + self.sent_index.append(word_count) + for word in line.split(): + self.data.append(self.get_id(word)) if self.use_sent_id: self.sent_id.append(line_num) word_count = word_count + 1 - self.data.append(0) - self.sent_index.append(word_count) + self.data.append(1) + if self.use_sent_id: + self.sent_id.append(line_num) + word_count = word_count + 1 + self.data.append(0) + self.sent_index.append(word_count) + def read_binary(self, char* filename): cdef FILE* f diff --git a/python/src/sa/suffix_array.pxi b/python/src/sa/suffix_array.pxi index 20e6261d..d86e8ea6 100644 --- a/python/src/sa/suffix_array.pxi +++ b/python/src/sa/suffix_array.pxi @@ -8,14 +8,14 @@ cdef class SuffixArray: cdef IntList sa cdef IntList ha - def __cinit__(self, from_binary=None, from_text=None): + def __cinit__(self, from_binary=None, from_text=None, side=None): self.darray = DataArray() self.sa = IntList() self.ha = IntList() if from_binary: self.read_binary(from_binary) elif from_text: - self.read_text(from_text) + self.read_text(from_text, side) def __getitem__(self, i): return self.sa.arr[i] @@ -29,13 +29,13 @@ cdef class SuffixArray: def getSentPos(self, loc): return self.darray.getSentPos(loc) - def read_text(self, char* filename): + def read_text(self, filename, side): '''Constructs suffix array using the algorithm of Larsson & Sadahkane (1999)''' cdef int V, N, i, j, h, a_i, n, current_run, skip cdef IntList isa, word_count - self.darray = DataArray(from_text=filename, use_sent_id=True) + self.darray = DataArray(from_text=filename, side=side, use_sent_id=True) N = len(self.darray) V = len(self.darray.id2word) -- cgit v1.2.3 From fd5e2c6858c7522917d6498bdb074b6d03cbacf2 Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Sat, 28 Jul 2012 20:11:56 -0400 Subject: [python] Fix grammar non-terminal memory bug --- python/src/_cdec.cpp | 205 ++++++++++++++++++++++++++++--------------------- python/src/grammar.pxi | 6 +- 2 files changed, 121 insertions(+), 90 deletions(-) (limited to 'python/src') diff --git a/python/src/_cdec.cpp b/python/src/_cdec.cpp index 20b86169..88c03520 100644 --- a/python/src/_cdec.cpp +++ b/python/src/_cdec.cpp @@ -1,4 +1,4 @@ -/* Generated by Cython 0.17.beta1 on Fri Jul 27 22:15:28 2012 */ +/* Generated by Cython 0.17.beta1 on Sat Jul 28 20:10:21 2012 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -482,7 +482,7 @@ struct __pyx_obj_5_cdec_Scorer { * * cdef class NTRef: # <<<<<<<<<<<<<< * cdef public unsigned ref - * def __init__(self, ref): + * def __init__(self, unsigned ref): */ struct __pyx_obj_5_cdec_NTRef { PyObject_HEAD @@ -718,12 +718,12 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_6_genexpr { * return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) * * cdef class NT: # <<<<<<<<<<<<<< - * cdef public char* cat + * cdef public bytes cat * cdef public unsigned ref */ struct __pyx_obj_5_cdec_NT { PyObject_HEAD - char *cat; + PyObject *cat; unsigned int ref; }; @@ -1784,13 +1784,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_37__div__(PyObject *__pyx_v_x, P #endif static PyObject *__pyx_pf_5_cdec_7_phrase_genexpr(PyObject *__pyx_self); /* proto */ static PyObject *__pyx_pf_5_cdec__phrase(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_phrase); /* proto */ -static int __pyx_pf_5_cdec_2NT___init__(struct __pyx_obj_5_cdec_NT *__pyx_v_self, PyObject *__pyx_v_cat, PyObject *__pyx_v_ref); /* proto */ +static int __pyx_pf_5_cdec_2NT___init__(struct __pyx_obj_5_cdec_NT *__pyx_v_self, char *__pyx_v_cat, unsigned int __pyx_v_ref); /* proto */ static PyObject *__pyx_pf_5_cdec_2NT_2__str__(struct __pyx_obj_5_cdec_NT *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_2NT_3cat___get__(struct __pyx_obj_5_cdec_NT *__pyx_v_self); /* proto */ static int __pyx_pf_5_cdec_2NT_3cat_2__set__(struct __pyx_obj_5_cdec_NT *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static int __pyx_pf_5_cdec_2NT_3cat_4__del__(struct __pyx_obj_5_cdec_NT *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_2NT_3ref___get__(struct __pyx_obj_5_cdec_NT *__pyx_v_self); /* proto */ static int __pyx_pf_5_cdec_2NT_3ref_2__set__(struct __pyx_obj_5_cdec_NT *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ -static int __pyx_pf_5_cdec_5NTRef___init__(struct __pyx_obj_5_cdec_NTRef *__pyx_v_self, PyObject *__pyx_v_ref); /* proto */ +static int __pyx_pf_5_cdec_5NTRef___init__(struct __pyx_obj_5_cdec_NTRef *__pyx_v_self, unsigned int __pyx_v_ref); /* proto */ static PyObject *__pyx_pf_5_cdec_5NTRef_2__str__(struct __pyx_obj_5_cdec_NTRef *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_5NTRef_3ref___get__(struct __pyx_obj_5_cdec_NTRef *__pyx_v_self); /* proto */ static int __pyx_pf_5_cdec_5NTRef_3ref_2__set__(struct __pyx_obj_5_cdec_NTRef *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ @@ -4832,15 +4833,14 @@ static PyObject *__pyx_pf_5_cdec__phrase(CYTHON_UNUSED PyObject *__pyx_self, PyO /* Python wrapper */ static int __pyx_pw_5_cdec_2NT_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_5_cdec_2NT_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_cat = 0; - PyObject *__pyx_v_ref = 0; + char *__pyx_v_cat; + unsigned int __pyx_v_ref; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__cat,&__pyx_n_s__ref,0}; PyObject* values[2] = {0,0}; - values[1] = ((PyObject *)__pyx_int_0); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); @@ -4872,8 +4872,12 @@ static int __pyx_pw_5_cdec_2NT_1__init__(PyObject *__pyx_v_self, PyObject *__pyx default: goto __pyx_L5_argtuple_error; } } - __pyx_v_cat = values[0]; - __pyx_v_ref = values[1]; + __pyx_v_cat = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_cat) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (values[1]) { + __pyx_v_ref = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_ref == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_ref = ((unsigned int)0); + } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; @@ -4889,18 +4893,17 @@ static int __pyx_pw_5_cdec_2NT_1__init__(PyObject *__pyx_v_self, PyObject *__pyx } /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":11 - * cdef public char* cat + * cdef public bytes cat * cdef public unsigned ref - * def __init__(self, cat, ref=0): # <<<<<<<<<<<<<< + * def __init__(self, char* cat, unsigned ref=0): # <<<<<<<<<<<<<< * self.cat = cat * self.ref = ref */ -static int __pyx_pf_5_cdec_2NT___init__(struct __pyx_obj_5_cdec_NT *__pyx_v_self, PyObject *__pyx_v_cat, PyObject *__pyx_v_ref) { +static int __pyx_pf_5_cdec_2NT___init__(struct __pyx_obj_5_cdec_NT *__pyx_v_self, char *__pyx_v_cat, unsigned int __pyx_v_ref) { int __pyx_r; __Pyx_RefNannyDeclarations - char *__pyx_t_1; - unsigned int __pyx_t_2; + PyObject *__pyx_t_1 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -4908,27 +4911,32 @@ static int __pyx_pf_5_cdec_2NT___init__(struct __pyx_obj_5_cdec_NT *__pyx_v_self /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":12 * cdef public unsigned ref - * def __init__(self, cat, ref=0): + * def __init__(self, char* cat, unsigned ref=0): * self.cat = cat # <<<<<<<<<<<<<< * self.ref = ref * */ - __pyx_t_1 = PyBytes_AsString(__pyx_v_cat); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(__pyx_v_cat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __Pyx_GOTREF(__pyx_v_self->cat); + __Pyx_DECREF(((PyObject *)__pyx_v_self->cat)); __pyx_v_self->cat = __pyx_t_1; + __pyx_t_1 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":13 - * def __init__(self, cat, ref=0): + * def __init__(self, char* cat, unsigned ref=0): * self.cat = cat * self.ref = ref # <<<<<<<<<<<<<< * * def __str__(self): */ - __pyx_t_2 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_ref); if (unlikely((__pyx_t_2 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->ref = __pyx_t_2; + __pyx_v_self->ref = __pyx_v_ref; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("_cdec.NT.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; @@ -4961,7 +4969,6 @@ static PyObject *__pyx_pf_5_cdec_2NT_2__str__(struct __pyx_obj_5_cdec_NT *__pyx_ int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -4985,23 +4992,21 @@ static PyObject *__pyx_pf_5_cdec_2NT_2__str__(struct __pyx_obj_5_cdec_NT *__pyx_ * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyBytes_FromString(__pyx_v_self->cat); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_t_3 = PyLong_FromUnsignedLong(__pyx_v_self->ref); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyLong_FromUnsignedLong(__pyx_v_self->ref); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_2)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); + __Pyx_INCREF(((PyObject *)__pyx_v_self->cat)); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->cat)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self->cat)); + PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_8), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_r = ((PyObject *)__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_8), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __pyx_r = ((PyObject *)__pyx_t_3); - __pyx_t_3 = 0; goto __pyx_L0; goto __pyx_L3; } @@ -5015,13 +5020,10 @@ static PyObject *__pyx_pf_5_cdec_2NT_2__str__(struct __pyx_obj_5_cdec_NT *__pyx_ * cdef class NTRef: */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = PyBytes_FromString(__pyx_v_self->cat); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_r = ((PyObject *)__pyx_t_4); - __pyx_t_4 = 0; + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_9), ((PyObject *)__pyx_v_self->cat)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_r = ((PyObject *)__pyx_t_2); + __pyx_t_2 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); @@ -5029,7 +5031,6 @@ static PyObject *__pyx_pf_5_cdec_2NT_2__str__(struct __pyx_obj_5_cdec_NT *__pyx_ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("_cdec.NT.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -5052,32 +5053,21 @@ static PyObject *__pyx_pw_5_cdec_2NT_3cat_1__get__(PyObject *__pyx_v_self) { /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":9 * * cdef class NT: - * cdef public char* cat # <<<<<<<<<<<<<< + * cdef public bytes cat # <<<<<<<<<<<<<< * cdef public unsigned ref - * def __init__(self, cat, ref=0): + * def __init__(self, char* cat, unsigned ref=0): */ static PyObject *__pyx_pf_5_cdec_2NT_3cat___get__(struct __pyx_obj_5_cdec_NT *__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("__get__", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(__pyx_v_self->cat); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_r = ((PyObject *)__pyx_t_1); - __pyx_t_1 = 0; + __Pyx_INCREF(((PyObject *)__pyx_v_self->cat)); + __pyx_r = ((PyObject *)__pyx_v_self->cat); 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.NT.cat.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); @@ -5098,13 +5088,16 @@ static int __pyx_pw_5_cdec_2NT_3cat_3__set__(PyObject *__pyx_v_self, PyObject *_ static int __pyx_pf_5_cdec_2NT_3cat_2__set__(struct __pyx_obj_5_cdec_NT *__pyx_v_self, PyObject *__pyx_v_value) { int __pyx_r; __Pyx_RefNannyDeclarations - char *__pyx_t_1; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - __pyx_t_1 = PyBytes_AsString(__pyx_v_value); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->cat = __pyx_t_1; + if (!(likely(PyBytes_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_value)->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->cat); + __Pyx_DECREF(((PyObject *)__pyx_v_self->cat)); + __pyx_v_self->cat = ((PyObject*)__pyx_v_value); __pyx_r = 0; goto __pyx_L0; @@ -5116,6 +5109,32 @@ static int __pyx_pf_5_cdec_2NT_3cat_2__set__(struct __pyx_obj_5_cdec_NT *__pyx_v return __pyx_r; } +/* Python wrapper */ +static int __pyx_pw_5_cdec_2NT_3cat_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_5_cdec_2NT_3cat_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_2NT_3cat_4__del__(((struct __pyx_obj_5_cdec_NT *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5_cdec_2NT_3cat_4__del__(struct __pyx_obj_5_cdec_NT *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->cat); + __Pyx_DECREF(((PyObject *)__pyx_v_self->cat)); + __pyx_v_self->cat = ((PyObject*)Py_None); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + /* Python wrapper */ static PyObject *__pyx_pw_5_cdec_2NT_3ref_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_5_cdec_2NT_3ref_1__get__(PyObject *__pyx_v_self) { @@ -5129,9 +5148,9 @@ static PyObject *__pyx_pw_5_cdec_2NT_3ref_1__get__(PyObject *__pyx_v_self) { /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":10 * cdef class NT: - * cdef public char* cat + * cdef public bytes cat * cdef public unsigned ref # <<<<<<<<<<<<<< - * def __init__(self, cat, ref=0): + * def __init__(self, char* cat, unsigned ref=0): * self.cat = cat */ @@ -5197,7 +5216,7 @@ static int __pyx_pf_5_cdec_2NT_3ref_2__set__(struct __pyx_obj_5_cdec_NT *__pyx_v /* Python wrapper */ static int __pyx_pw_5_cdec_5NTRef_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_5_cdec_5NTRef_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_ref = 0; + unsigned int __pyx_v_ref; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); @@ -5226,7 +5245,7 @@ static int __pyx_pw_5_cdec_5NTRef_1__init__(PyObject *__pyx_v_self, PyObject *__ } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); } - __pyx_v_ref = values[0]; + __pyx_v_ref = __Pyx_PyInt_AsUnsignedInt(values[0]); if (unlikely((__pyx_v_ref == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; @@ -5244,36 +5263,26 @@ static int __pyx_pw_5_cdec_5NTRef_1__init__(PyObject *__pyx_v_self, PyObject *__ /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":22 * cdef class NTRef: * cdef public unsigned ref - * def __init__(self, ref): # <<<<<<<<<<<<<< + * def __init__(self, unsigned ref): # <<<<<<<<<<<<<< * self.ref = ref * */ -static int __pyx_pf_5_cdec_5NTRef___init__(struct __pyx_obj_5_cdec_NTRef *__pyx_v_self, PyObject *__pyx_v_ref) { +static int __pyx_pf_5_cdec_5NTRef___init__(struct __pyx_obj_5_cdec_NTRef *__pyx_v_self, unsigned int __pyx_v_ref) { int __pyx_r; __Pyx_RefNannyDeclarations - unsigned int __pyx_t_1; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__init__", 0); /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":23 * cdef public unsigned ref - * def __init__(self, ref): + * def __init__(self, unsigned ref): * self.ref = ref # <<<<<<<<<<<<<< * * def __str__(self): */ - __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_v_ref); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->ref = __pyx_t_1; + __pyx_v_self->ref = __pyx_v_ref; __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.NTRef.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; - __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } @@ -5352,7 +5361,7 @@ static PyObject *__pyx_pw_5_cdec_5NTRef_3ref_1__get__(PyObject *__pyx_v_self) { * * cdef class NTRef: * cdef public unsigned ref # <<<<<<<<<<<<<< - * def __init__(self, ref): + * def __init__(self, unsigned ref): * self.ref = ref */ @@ -18748,15 +18757,38 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { }; static PyObject *__pyx_tp_new_5_cdec_NT(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_5_cdec_NT *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + p = ((struct __pyx_obj_5_cdec_NT *)o); + p->cat = ((PyObject*)Py_None); Py_INCREF(Py_None); return o; } static void __pyx_tp_dealloc_5_cdec_NT(PyObject *o) { + struct __pyx_obj_5_cdec_NT *p = (struct __pyx_obj_5_cdec_NT *)o; + Py_XDECREF(((PyObject *)p->cat)); (*Py_TYPE(o)->tp_free)(o); } +static int __pyx_tp_traverse_5_cdec_NT(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec_NT *p = (struct __pyx_obj_5_cdec_NT *)o; + if (p->cat) { + e = (*v)(p->cat, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5_cdec_NT(PyObject *o) { + struct __pyx_obj_5_cdec_NT *p = (struct __pyx_obj_5_cdec_NT *)o; + PyObject* tmp; + tmp = ((PyObject*)p->cat); + p->cat = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + static PyObject *__pyx_getprop_5_cdec_2NT_cat(PyObject *o, CYTHON_UNUSED void *x) { return __pyx_pw_5_cdec_2NT_3cat_1__get__(o); } @@ -18766,8 +18798,7 @@ static int __pyx_setprop_5_cdec_2NT_cat(PyObject *o, PyObject *v, CYTHON_UNUSED return __pyx_pw_5_cdec_2NT_3cat_3__set__(o, v); } else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; + return __pyx_pw_5_cdec_2NT_3cat_5__del__(o); } } @@ -18917,10 +18948,10 @@ static PyTypeObject __pyx_type_5_cdec_NT = { 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_NT, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec_NT, /*tp_traverse*/ + __pyx_tp_clear_5_cdec_NT, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ diff --git a/python/src/grammar.pxi b/python/src/grammar.pxi index 5ec21422..59266238 100644 --- a/python/src/grammar.pxi +++ b/python/src/grammar.pxi @@ -6,9 +6,9 @@ def _phrase(phrase): return ' '.join(w.encode('utf8') if isinstance(w, unicode) else str(w) for w in phrase) cdef class NT: - cdef public char* cat + cdef public bytes cat cdef public unsigned ref - def __init__(self, cat, ref=0): + def __init__(self, char* cat, unsigned ref=0): self.cat = cat self.ref = ref @@ -19,7 +19,7 @@ cdef class NT: cdef class NTRef: cdef public unsigned ref - def __init__(self, ref): + def __init__(self, unsigned ref): self.ref = ref def __str__(self): -- cgit v1.2.3 From 3325742971681642adadfac180f8e0e27014bd57 Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Mon, 30 Jul 2012 00:04:02 -0400 Subject: [python] monolingual grammars --- python/pkg/cdec/__init__.py | 2 +- python/src/_cdec.cpp | 588 ++++++++++++++++++++++++++++++++++++++++---- python/src/grammar.pxi | 12 + 3 files changed, 549 insertions(+), 53 deletions(-) (limited to 'python/src') diff --git a/python/pkg/cdec/__init__.py b/python/pkg/cdec/__init__.py index 503ac787..531fea49 100644 --- a/python/pkg/cdec/__init__.py +++ b/python/pkg/cdec/__init__.py @@ -1 +1 @@ -from cdec._cdec import Decoder, Lattice, TRule, NT, NTRef, ParseFailed, InvalidConfig +from cdec._cdec import Decoder, Lattice, TRule, MRule, NT, NTRef, ParseFailed, InvalidConfig diff --git a/python/src/_cdec.cpp b/python/src/_cdec.cpp index 88c03520..dcd33448 100644 --- a/python/src/_cdec.cpp +++ b/python/src/_cdec.cpp @@ -1,4 +1,4 @@ -/* Generated by Cython 0.17.beta1 on Sat Jul 28 20:10:21 2012 */ +/* Generated by Cython 0.17.beta1 on Sun Jul 29 23:00:27 2012 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -417,6 +417,7 @@ struct __pyx_obj_5_cdec_CandidateSet; struct __pyx_obj_5_cdec___pyx_scope_struct_14___get__; struct __pyx_obj_5_cdec_TRule; struct __pyx_obj_4cdec_2sa_3_sa_Rule; +struct __pyx_obj_5_cdec_MRule; struct __pyx_obj_5_cdec_SegmentEvaluator; struct __pyx_obj_5_cdec___pyx_scope_struct_20___iter__; struct __pyx_obj_5_cdec_Candidate; @@ -535,8 +536,8 @@ struct __pyx_obj_4cdec_2sa_3_sa_Phrase { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":169 - * _phrase(self.f), _phrase(self.e), scores) +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":181 + * super(MRule, self).__init__(lhs, rhs, e, scores, a) * * cdef class Grammar: # <<<<<<<<<<<<<< * cdef shared_ptr[grammar.Grammar]* grammar @@ -652,6 +653,18 @@ struct __pyx_obj_4cdec_2sa_3_sa_Rule { }; +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":169 + * _phrase(self.f), _phrase(self.e), scores) + * + * cdef class MRule(TRule): # <<<<<<<<<<<<<< + * def __init__(self, lhs, rhs, scores, a=None): + * cdef unsigned i = 1 + */ +struct __pyx_obj_5_cdec_MRule { + struct __pyx_obj_5_cdec_TRule __pyx_base; +}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":98 * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) * @@ -898,7 +911,7 @@ struct __pyx_obj_5_cdec_DenseVector { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":175 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":187 * del self.grammar * * def __iter__(self): # <<<<<<<<<<<<<< @@ -1136,7 +1149,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_22__make_config { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":192 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":204 * self.grammar.get().SetGrammarName(string(name)) * * cdef class TextGrammar(Grammar): # <<<<<<<<<<<<<< @@ -1693,6 +1706,7 @@ static PyTypeObject *__pyx_ptype_5_cdec_SparseVector = 0; static PyTypeObject *__pyx_ptype_5_cdec_NT = 0; static PyTypeObject *__pyx_ptype_5_cdec_NTRef = 0; static PyTypeObject *__pyx_ptype_5_cdec_TRule = 0; +static PyTypeObject *__pyx_ptype_5_cdec_MRule = 0; static PyTypeObject *__pyx_ptype_5_cdec_Grammar = 0; static PyTypeObject *__pyx_ptype_5_cdec_TextGrammar = 0; static PyTypeObject *__pyx_ptype_5_cdec_Hypergraph = 0; @@ -1746,6 +1760,7 @@ static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_KeyError; static PyObject *__pyx_builtin_range; static PyObject *__pyx_builtin_NotImplemented; +static PyObject *__pyx_builtin_super; static PyObject *__pyx_builtin_ValueError; static PyObject *__pyx_builtin_eval; static PyObject *__pyx_builtin_enumerate; @@ -1810,6 +1825,7 @@ static PyObject *__pyx_pf_5_cdec_5TRule_3lhs___get__(struct __pyx_obj_5_cdec_TRu static int __pyx_pf_5_cdec_5TRule_3lhs_2__set__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self, PyObject *__pyx_v_lhs); /* proto */ static PyObject *__pyx_pf_5_cdec_5TRule_7__str___genexpr(PyObject *__pyx_self); /* proto */ static PyObject *__pyx_pf_5_cdec_5TRule_4__str__(struct __pyx_obj_5_cdec_TRule *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_5MRule___init__(struct __pyx_obj_5_cdec_MRule *__pyx_v_self, PyObject *__pyx_v_lhs, PyObject *__pyx_v_rhs, PyObject *__pyx_v_scores, PyObject *__pyx_v_a); /* proto */ static void __pyx_pf_5_cdec_7Grammar___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Grammar *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_7Grammar_2__iter__(struct __pyx_obj_5_cdec_Grammar *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_7Grammar_4name___get__(struct __pyx_obj_5_cdec_Grammar *__pyx_v_self); /* proto */ @@ -1952,6 +1968,7 @@ static char __pyx_k__key[] = "key"; static char __pyx_k__lhs[] = "lhs"; static char __pyx_k__plf[] = "plf"; static char __pyx_k__ref[] = "ref"; +static char __pyx_k__rhs[] = "rhs"; static char __pyx_k__BLEU[] = "BLEU"; static char __pyx_k__eval[] = "eval"; static char __pyx_k__info[] = "info"; @@ -1973,6 +1990,7 @@ static char __pyx_k__rules[] = "rules"; static char __pyx_k__score[] = "score"; static char __pyx_k__split[] = "split"; static char __pyx_k__strip[] = "strip"; +static char __pyx_k__super[] = "super"; static char __pyx_k__value[] = "value"; static char __pyx_k__config[] = "config"; static char __pyx_k__csplit[] = "csplit"; @@ -1990,6 +2008,7 @@ static char __pyx_k__replace[] = "replace"; static char __pyx_k__IBM_BLEU[] = "IBM_BLEU"; static char __pyx_k__KeyError[] = "KeyError"; static char __pyx_k____exit__[] = "__exit__"; +static char __pyx_k____init__[] = "__init__"; static char __pyx_k____main__[] = "__main__"; static char __pyx_k____name__[] = "__name__"; static char __pyx_k____test__[] = "__test__"; @@ -2070,6 +2089,7 @@ static PyObject *__pyx_n_s__ValueError; static PyObject *__pyx_n_s____class__; static PyObject *__pyx_n_s____enter__; static PyObject *__pyx_n_s____exit__; +static PyObject *__pyx_n_s____init__; static PyObject *__pyx_n_s____main__; static PyObject *__pyx_n_s____name__; static PyObject *__pyx_n_s____test__; @@ -2124,6 +2144,7 @@ static PyObject *__pyx_n_s__range; static PyObject *__pyx_n_s__ref; static PyObject *__pyx_n_s__refs; static PyObject *__pyx_n_s__replace; +static PyObject *__pyx_n_s__rhs; static PyObject *__pyx_n_s__rules; static PyObject *__pyx_n_s__scfg; static PyObject *__pyx_n_s__score; @@ -2134,6 +2155,7 @@ static PyObject *__pyx_n_s__span; static PyObject *__pyx_n_s__split; static PyObject *__pyx_n_s__startswith; static PyObject *__pyx_n_s__strip; +static PyObject *__pyx_n_s__super; static PyObject *__pyx_n_s__tagger; static PyObject *__pyx_n_s__utf8; static PyObject *__pyx_n_s__value; @@ -7706,7 +7728,7 @@ static PyObject *__pyx_pf_5_cdec_5TRule_4__str__(struct __pyx_obj_5_cdec_TRule * * return '%s ||| %s ||| %s ||| %s' % (self.lhs, * _phrase(self.f), _phrase(self.e), scores) # <<<<<<<<<<<<<< * - * cdef class Grammar: + * cdef class MRule(TRule): */ __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s___phrase); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); @@ -7773,6 +7795,292 @@ static PyObject *__pyx_pf_5_cdec_5TRule_4__str__(struct __pyx_obj_5_cdec_TRule * return __pyx_r; } +/* Python wrapper */ +static int __pyx_pw_5_cdec_5MRule_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_5MRule_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_lhs = 0; + PyObject *__pyx_v_rhs = 0; + PyObject *__pyx_v_scores = 0; + PyObject *__pyx_v_a = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__lhs,&__pyx_n_s__rhs,&__pyx_n_s__scores,&__pyx_n_s__a,0}; + PyObject* values[4] = {0,0,0,0}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":170 + * + * cdef class MRule(TRule): + * def __init__(self, lhs, rhs, scores, a=None): # <<<<<<<<<<<<<< + * cdef unsigned i = 1 + * e = [] + */ + values[3] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + 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 (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__lhs)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__rhs)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__init__", 0, 3, 4, 1); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__scores)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("__init__", 0, 3, 4, 2); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 3: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__a); + if (value) { values[3] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_lhs = values[0]; + __pyx_v_rhs = values[1]; + __pyx_v_scores = values[2]; + __pyx_v_a = values[3]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.MRule.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_5MRule___init__(((struct __pyx_obj_5_cdec_MRule *)__pyx_v_self), __pyx_v_lhs, __pyx_v_rhs, __pyx_v_scores, __pyx_v_a); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5_cdec_5MRule___init__(struct __pyx_obj_5_cdec_MRule *__pyx_v_self, PyObject *__pyx_v_lhs, PyObject *__pyx_v_rhs, PyObject *__pyx_v_scores, PyObject *__pyx_v_a) { + unsigned int __pyx_v_i; + PyObject *__pyx_v_e = NULL; + PyObject *__pyx_v_s = NULL; + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + PyObject *(*__pyx_t_3)(PyObject *); + PyObject *__pyx_t_4 = NULL; + int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + int __pyx_t_7; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__init__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":171 + * cdef class MRule(TRule): + * def __init__(self, lhs, rhs, scores, a=None): + * cdef unsigned i = 1 # <<<<<<<<<<<<<< + * e = [] + * for s in rhs: + */ + __pyx_v_i = 1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":172 + * def __init__(self, lhs, rhs, scores, a=None): + * cdef unsigned i = 1 + * e = [] # <<<<<<<<<<<<<< + * for s in rhs: + * if isinstance(s, NT): + */ + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_e = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":173 + * cdef unsigned i = 1 + * e = [] + * for s in rhs: # <<<<<<<<<<<<<< + * if isinstance(s, NT): + * e.append(NTRef(i)) + */ + if (PyList_CheckExact(__pyx_v_rhs) || PyTuple_CheckExact(__pyx_v_rhs)) { + __pyx_t_1 = __pyx_v_rhs; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; + __pyx_t_3 = NULL; + } else { + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_rhs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #endif + } else { + __pyx_t_4 = __pyx_t_3(__pyx_t_1); + if (unlikely(!__pyx_t_4)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_4); + } + __Pyx_XDECREF(__pyx_v_s); + __pyx_v_s = __pyx_t_4; + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":174 + * e = [] + * for s in rhs: + * if isinstance(s, NT): # <<<<<<<<<<<<<< + * e.append(NTRef(i)) + * i += 1 + */ + __pyx_t_4 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NT)); + __Pyx_INCREF(__pyx_t_4); + __pyx_t_5 = __Pyx_TypeCheck(__pyx_v_s, __pyx_t_4); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_5) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":175 + * for s in rhs: + * if isinstance(s, NT): + * e.append(NTRef(i)) # <<<<<<<<<<<<<< + * i += 1 + * else: + */ + __pyx_t_4 = PyLong_FromUnsignedLong(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_NTRef)), ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __pyx_t_7 = PyList_Append(__pyx_v_e, __pyx_t_4); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":176 + * if isinstance(s, NT): + * e.append(NTRef(i)) + * i += 1 # <<<<<<<<<<<<<< + * else: + * e.append(s) + */ + __pyx_v_i = (__pyx_v_i + 1); + goto __pyx_L5; + } + /*else*/ { + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":178 + * i += 1 + * else: + * e.append(s) # <<<<<<<<<<<<<< + * super(MRule, self).__init__(lhs, rhs, e, scores, a) + * + */ + __pyx_t_7 = PyList_Append(__pyx_v_e, __pyx_v_s); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L5:; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":179 + * else: + * e.append(s) + * super(MRule, self).__init__(lhs, rhs, e, scores, a) # <<<<<<<<<<<<<< + * + * cdef class Grammar: + */ + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_MRule))); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_MRule))); + __Pyx_GIVEREF(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_MRule))); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + __pyx_t_4 = PyObject_Call(__pyx_builtin_super, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s____init__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_lhs); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_lhs); + __Pyx_GIVEREF(__pyx_v_lhs); + __Pyx_INCREF(__pyx_v_rhs); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_rhs); + __Pyx_GIVEREF(__pyx_v_rhs); + __Pyx_INCREF(((PyObject *)__pyx_v_e)); + PyTuple_SET_ITEM(__pyx_t_4, 2, ((PyObject *)__pyx_v_e)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_e)); + __Pyx_INCREF(__pyx_v_scores); + PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_v_scores); + __Pyx_GIVEREF(__pyx_v_scores); + __Pyx_INCREF(__pyx_v_a); + PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_v_a); + __Pyx_GIVEREF(__pyx_v_a); + __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("_cdec.MRule.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_e); + __Pyx_XDECREF(__pyx_v_s); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + /* Python wrapper */ static void __pyx_pw_5_cdec_7Grammar_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ static void __pyx_pw_5_cdec_7Grammar_1__dealloc__(PyObject *__pyx_v_self) { @@ -7782,7 +8090,7 @@ static void __pyx_pw_5_cdec_7Grammar_1__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyFinishContext(); } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":172 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":184 * cdef shared_ptr[grammar.Grammar]* grammar * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -7794,7 +8102,7 @@ static void __pyx_pf_5_cdec_7Grammar___dealloc__(CYTHON_UNUSED struct __pyx_obj_ __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":173 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":185 * * def __dealloc__(self): * del self.grammar # <<<<<<<<<<<<<< @@ -7818,7 +8126,7 @@ static PyObject *__pyx_pw_5_cdec_7Grammar_3__iter__(PyObject *__pyx_v_self) { return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":175 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":187 * del self.grammar * * def __iter__(self): # <<<<<<<<<<<<<< @@ -7844,7 +8152,7 @@ static PyObject *__pyx_pf_5_cdec_7Grammar_2__iter__(struct __pyx_obj_5_cdec_Gram __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Grammar_4generator3, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Grammar_4generator3, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -7879,9 +8187,9 @@ static PyObject *__pyx_gb_5_cdec_7Grammar_4generator3(__pyx_GeneratorObject *__p return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":176 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":188 * * def __iter__(self): * cdef grammar.const_GrammarIter* root = self.grammar.get().GetRoot() # <<<<<<<<<<<<<< @@ -7890,7 +8198,7 @@ static PyObject *__pyx_gb_5_cdec_7Grammar_4generator3(__pyx_GeneratorObject *__p */ __pyx_cur_scope->__pyx_v_root = __pyx_cur_scope->__pyx_v_self->grammar->get()->GetRoot(); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":177 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":189 * def __iter__(self): * cdef grammar.const_GrammarIter* root = self.grammar.get().GetRoot() * cdef grammar.const_RuleBin* rbin = root.GetRules() # <<<<<<<<<<<<<< @@ -7899,7 +8207,7 @@ static PyObject *__pyx_gb_5_cdec_7Grammar_4generator3(__pyx_GeneratorObject *__p */ __pyx_cur_scope->__pyx_v_rbin = __pyx_cur_scope->__pyx_v_root->GetRules(); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":180 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":192 * cdef TRule trule * cdef unsigned i * for i in range(rbin.GetNumRules()): # <<<<<<<<<<<<<< @@ -7910,23 +8218,23 @@ static PyObject *__pyx_gb_5_cdec_7Grammar_4generator3(__pyx_GeneratorObject *__p for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":181 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":193 * cdef unsigned i * for i in range(rbin.GetNumRules()): * trule = TRule.__new__(TRule) # <<<<<<<<<<<<<< * trule.rule = new shared_ptr[grammar.TRule](rbin.GetIthRule(i)) * yield trule */ - __pyx_t_3 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5_cdec_TRule)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_tp_new(((PyObject*)__pyx_ptype_5_cdec_TRule)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - if (!(likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5_cdec_TRule)))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5_cdec_TRule)))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_trule)); __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_trule)); __Pyx_GIVEREF(__pyx_t_3); __pyx_cur_scope->__pyx_v_trule = ((struct __pyx_obj_5_cdec_TRule *)__pyx_t_3); __pyx_t_3 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":182 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":194 * for i in range(rbin.GetNumRules()): * trule = TRule.__new__(TRule) * trule.rule = new shared_ptr[grammar.TRule](rbin.GetIthRule(i)) # <<<<<<<<<<<<<< @@ -7935,7 +8243,7 @@ static PyObject *__pyx_gb_5_cdec_7Grammar_4generator3(__pyx_GeneratorObject *__p */ __pyx_cur_scope->__pyx_v_trule->rule = new boost::shared_ptr(__pyx_cur_scope->__pyx_v_rbin->GetIthRule(__pyx_cur_scope->__pyx_v_i)); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":183 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":195 * trule = TRule.__new__(TRule) * trule.rule = new shared_ptr[grammar.TRule](rbin.GetIthRule(i)) * yield trule # <<<<<<<<<<<<<< @@ -7954,7 +8262,7 @@ static PyObject *__pyx_gb_5_cdec_7Grammar_4generator3(__pyx_GeneratorObject *__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[2]; __pyx_lineno = 183; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; @@ -7980,7 +8288,7 @@ static PyObject *__pyx_pw_5_cdec_7Grammar_4name_1__get__(PyObject *__pyx_v_self) return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":186 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":198 * * property name: * def __get__(self): # <<<<<<<<<<<<<< @@ -7993,7 +8301,7 @@ static PyObject *__pyx_pf_5_cdec_7Grammar_4name___get__(struct __pyx_obj_5_cdec_ __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":187 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":199 * property name: * def __get__(self): * self.grammar.get().GetGrammarName().c_str() # <<<<<<<<<<<<<< @@ -8019,7 +8327,7 @@ static int __pyx_pw_5_cdec_7Grammar_4name_3__set__(PyObject *__pyx_v_self, PyObj return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":189 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":201 * self.grammar.get().GetGrammarName().c_str() * * def __set__(self, name): # <<<<<<<<<<<<<< @@ -8036,14 +8344,14 @@ static int __pyx_pf_5_cdec_7Grammar_4name_2__set__(struct __pyx_obj_5_cdec_Gramm int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__set__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":190 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":202 * * def __set__(self, name): * self.grammar.get().SetGrammarName(string(name)) # <<<<<<<<<<<<<< * * cdef class TextGrammar(Grammar): */ - __pyx_t_1 = PyBytes_AsString(__pyx_v_name); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_AsString(__pyx_v_name); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->grammar->get()->SetGrammarName(std::string(((char *)__pyx_t_1))); __pyx_r = 0; @@ -8081,7 +8389,7 @@ static int __pyx_pw_5_cdec_11TextGrammar_1__cinit__(PyObject *__pyx_v_self, PyOb else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; @@ -8092,7 +8400,7 @@ static int __pyx_pw_5_cdec_11TextGrammar_1__cinit__(PyObject *__pyx_v_self, PyOb } 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[2]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.TextGrammar.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -8103,7 +8411,7 @@ static int __pyx_pw_5_cdec_11TextGrammar_1__cinit__(PyObject *__pyx_v_self, PyOb return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":193 +/* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":205 * * cdef class TextGrammar(Grammar): * def __cinit__(self, rules): # <<<<<<<<<<<<<< @@ -8128,7 +8436,7 @@ static int __pyx_pf_5_cdec_11TextGrammar___cinit__(struct __pyx_obj_5_cdec_TextG int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":194 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":206 * cdef class TextGrammar(Grammar): * def __cinit__(self, rules): * self.grammar = new shared_ptr[grammar.Grammar](new grammar.TextGrammar()) # <<<<<<<<<<<<<< @@ -8137,7 +8445,7 @@ static int __pyx_pf_5_cdec_11TextGrammar___cinit__(struct __pyx_obj_5_cdec_TextG */ __pyx_v_self->__pyx_base.grammar = new boost::shared_ptr(new TextGrammar()); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":195 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":207 * def __cinit__(self, rules): * self.grammar = new shared_ptr[grammar.Grammar](new grammar.TextGrammar()) * cdef grammar.TextGrammar* _g = self.grammar.get() # <<<<<<<<<<<<<< @@ -8146,7 +8454,7 @@ static int __pyx_pf_5_cdec_11TextGrammar___cinit__(struct __pyx_obj_5_cdec_TextG */ __pyx_v__g = ((TextGrammar *)__pyx_v_self->__pyx_base.grammar->get()); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":196 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":208 * self.grammar = new shared_ptr[grammar.Grammar](new grammar.TextGrammar()) * cdef grammar.TextGrammar* _g = self.grammar.get() * for trule in rules: # <<<<<<<<<<<<<< @@ -8157,7 +8465,7 @@ static int __pyx_pf_5_cdec_11TextGrammar___cinit__(struct __pyx_obj_5_cdec_TextG __pyx_t_1 = __pyx_v_rules; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; __pyx_t_3 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_rules); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_rules); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; } @@ -8167,21 +8475,21 @@ static int __pyx_pf_5_cdec_11TextGrammar___cinit__(struct __pyx_obj_5_cdec_TextG #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; #endif } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_COMPILING_IN_CPYTHON __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; #endif } else { __pyx_t_4 = __pyx_t_3(__pyx_t_1); if (unlikely(!__pyx_t_4)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 196; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } @@ -8191,7 +8499,7 @@ static int __pyx_pf_5_cdec_11TextGrammar___cinit__(struct __pyx_obj_5_cdec_TextG __pyx_v_trule = __pyx_t_4; __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":197 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":209 * cdef grammar.TextGrammar* _g = self.grammar.get() * for trule in rules: * if isinstance(trule, _sa.Rule): # <<<<<<<<<<<<<< @@ -8204,17 +8512,17 @@ static int __pyx_pf_5_cdec_11TextGrammar___cinit__(struct __pyx_obj_5_cdec_TextG __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_5) { - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":198 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":210 * for trule in rules: * if isinstance(trule, _sa.Rule): * trule = convert_rule(trule) # <<<<<<<<<<<<<< * elif not isinstance(trule, TRule): * raise ValueError('the grammar should contain TRule objects') */ - if (!(likely(((__pyx_v_trule) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_trule, __pyx_ptype_4cdec_2sa_3_sa_Rule))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_trule) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_trule, __pyx_ptype_4cdec_2sa_3_sa_Rule))))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_4 = __pyx_v_trule; __Pyx_INCREF(__pyx_t_4); - __pyx_t_6 = ((PyObject *)__pyx_f_5_cdec_convert_rule(((struct __pyx_obj_4cdec_2sa_3_sa_Rule *)__pyx_t_4))); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = ((PyObject *)__pyx_f_5_cdec_convert_rule(((struct __pyx_obj_4cdec_2sa_3_sa_Rule *)__pyx_t_4))); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_v_trule); @@ -8223,7 +8531,7 @@ static int __pyx_pf_5_cdec_11TextGrammar___cinit__(struct __pyx_obj_5_cdec_TextG goto __pyx_L5; } - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":199 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":211 * if isinstance(trule, _sa.Rule): * trule = convert_rule(trule) * elif not isinstance(trule, TRule): # <<<<<<<<<<<<<< @@ -8237,22 +8545,22 @@ static int __pyx_pf_5_cdec_11TextGrammar___cinit__(struct __pyx_obj_5_cdec_TextG __pyx_t_7 = (!__pyx_t_5); if (__pyx_t_7) { - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":200 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":212 * trule = convert_rule(trule) * elif not isinstance(trule, TRule): * raise ValueError('the grammar should contain TRule objects') # <<<<<<<<<<<<<< * _g.AddRule(( trule).rule[0]) */ - __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_14), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_14), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_Raise(__pyx_t_6, 0, 0, 0); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L5; } __pyx_L5:; - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":201 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":213 * elif not isinstance(trule, TRule): * raise ValueError('the grammar should contain TRule objects') * _g.AddRule(( trule).rule[0]) # <<<<<<<<<<<<<< @@ -19428,6 +19736,174 @@ static PyTypeObject __pyx_type_5_cdec_TRule = { #endif }; +static PyObject *__pyx_tp_new_5_cdec_MRule(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = __pyx_tp_new_5_cdec_TRule(t, a, k); + if (!o) return 0; + return o; +} + +static PyMethodDef __pyx_methods_5_cdec_MRule[] = { + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_MRule = { + 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_MRule = { + 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_MRule = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_MRule = { + #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_MRule = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.MRule"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_MRule), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_TRule, /*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_MRule, /*tp_as_number*/ + &__pyx_tp_as_sequence_MRule, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_MRule, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + #if CYTHON_COMPILING_IN_PYPY + __pyx_pw_5_cdec_5TRule_5__str__, /*tp_str*/ + #else + 0, /*tp_str*/ + #endif + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_MRule, /*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*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_MRule, /*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_pw_5_cdec_5MRule_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5_cdec_MRule, /*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_Grammar(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -27070,6 +27546,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s____class__, __pyx_k____class__, sizeof(__pyx_k____class__), 0, 0, 1, 1}, {&__pyx_n_s____enter__, __pyx_k____enter__, sizeof(__pyx_k____enter__), 0, 0, 1, 1}, {&__pyx_n_s____exit__, __pyx_k____exit__, sizeof(__pyx_k____exit__), 0, 0, 1, 1}, + {&__pyx_n_s____init__, __pyx_k____init__, sizeof(__pyx_k____init__), 0, 0, 1, 1}, {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, {&__pyx_n_s____name__, __pyx_k____name__, sizeof(__pyx_k____name__), 0, 0, 1, 1}, {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, @@ -27124,6 +27601,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__ref, __pyx_k__ref, sizeof(__pyx_k__ref), 0, 0, 1, 1}, {&__pyx_n_s__refs, __pyx_k__refs, sizeof(__pyx_k__refs), 0, 0, 1, 1}, {&__pyx_n_s__replace, __pyx_k__replace, sizeof(__pyx_k__replace), 0, 0, 1, 1}, + {&__pyx_n_s__rhs, __pyx_k__rhs, sizeof(__pyx_k__rhs), 0, 0, 1, 1}, {&__pyx_n_s__rules, __pyx_k__rules, sizeof(__pyx_k__rules), 0, 0, 1, 1}, {&__pyx_n_s__scfg, __pyx_k__scfg, sizeof(__pyx_k__scfg), 0, 0, 1, 1}, {&__pyx_n_s__score, __pyx_k__score, sizeof(__pyx_k__score), 0, 0, 1, 1}, @@ -27134,6 +27612,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__split, __pyx_k__split, sizeof(__pyx_k__split), 0, 0, 1, 1}, {&__pyx_n_s__startswith, __pyx_k__startswith, sizeof(__pyx_k__startswith), 0, 0, 1, 1}, {&__pyx_n_s__strip, __pyx_k__strip, sizeof(__pyx_k__strip), 0, 0, 1, 1}, + {&__pyx_n_s__super, __pyx_k__super, sizeof(__pyx_k__super), 0, 0, 1, 1}, {&__pyx_n_s__tagger, __pyx_k__tagger, sizeof(__pyx_k__tagger), 0, 0, 1, 1}, {&__pyx_n_s__utf8, __pyx_k__utf8, sizeof(__pyx_k__utf8), 0, 0, 1, 1}, {&__pyx_n_s__value, __pyx_k__value, sizeof(__pyx_k__value), 0, 0, 1, 1}, @@ -27146,7 +27625,8 @@ static int __Pyx_InitCachedBuiltins(void) { __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[1]; __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[1]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_NotImplemented = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplemented); if (!__pyx_builtin_NotImplemented) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_super = __Pyx_GetName(__pyx_b, __pyx_n_s__super); if (!__pyx_builtin_super) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 212; __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[3]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -27202,13 +27682,13 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_6)); - /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":200 + /* "/Users/vchahun/Sandbox/cdec/python/src/grammar.pxi":212 * trule = convert_rule(trule) * elif not isinstance(trule, TRule): * raise ValueError('the grammar should contain TRule objects') # <<<<<<<<<<<<<< * _g.AddRule(( trule).rule[0]) */ - __pyx_k_tuple_14 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_14)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_14 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_14)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_14); __Pyx_INCREF(((PyObject *)__pyx_kp_s_13)); PyTuple_SET_ITEM(__pyx_k_tuple_14, 0, ((PyObject *)__pyx_kp_s_13)); @@ -27618,12 +28098,16 @@ PyMODINIT_FUNC PyInit__cdec(void) if (PyType_Ready(&__pyx_type_5_cdec_TRule) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "TRule", (PyObject *)&__pyx_type_5_cdec_TRule) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_TRule = &__pyx_type_5_cdec_TRule; - if (PyType_Ready(&__pyx_type_5_cdec_Grammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Grammar", (PyObject *)&__pyx_type_5_cdec_Grammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_type_5_cdec_MRule.tp_base = __pyx_ptype_5_cdec_TRule; + if (PyType_Ready(&__pyx_type_5_cdec_MRule) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "MRule", (PyObject *)&__pyx_type_5_cdec_MRule) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_MRule = &__pyx_type_5_cdec_MRule; + if (PyType_Ready(&__pyx_type_5_cdec_Grammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Grammar", (PyObject *)&__pyx_type_5_cdec_Grammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Grammar = &__pyx_type_5_cdec_Grammar; __pyx_type_5_cdec_TextGrammar.tp_base = __pyx_ptype_5_cdec_Grammar; - if (PyType_Ready(&__pyx_type_5_cdec_TextGrammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "TextGrammar", (PyObject *)&__pyx_type_5_cdec_TextGrammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_TextGrammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "TextGrammar", (PyObject *)&__pyx_type_5_cdec_TextGrammar) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_TextGrammar = &__pyx_type_5_cdec_TextGrammar; if (PyType_Ready(&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Hypergraph", (PyObject *)&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -27678,7 +28162,7 @@ PyMODINIT_FUNC PyInit__cdec(void) __pyx_ptype_5_cdec___pyx_scope_struct_5___str__ = &__pyx_type_5_cdec___pyx_scope_struct_5___str__; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_6_genexpr) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_6_genexpr = &__pyx_type_5_cdec___pyx_scope_struct_6_genexpr; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_7___iter__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_7___iter__) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_7___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_7___iter__; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_8_kbest) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_8_kbest = &__pyx_type_5_cdec___pyx_scope_struct_8_kbest; diff --git a/python/src/grammar.pxi b/python/src/grammar.pxi index 59266238..a9a5ea14 100644 --- a/python/src/grammar.pxi +++ b/python/src/grammar.pxi @@ -166,6 +166,18 @@ cdef class TRule: return '%s ||| %s ||| %s ||| %s' % (self.lhs, _phrase(self.f), _phrase(self.e), scores) +cdef class MRule(TRule): + def __init__(self, lhs, rhs, scores, a=None): + cdef unsigned i = 1 + e = [] + for s in rhs: + if isinstance(s, NT): + e.append(NTRef(i)) + i += 1 + else: + e.append(s) + super(MRule, self).__init__(lhs, rhs, e, scores, a) + cdef class Grammar: cdef shared_ptr[grammar.Grammar]* grammar -- cgit v1.2.3